@xeokit/xeokit-sdk 2.6.112 → 2.6.113

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.112
3
- * Commit: 2ce58020bcf3e4af1f68e47009f413c448a8a2a4
4
- * Built: 2026-06-25T15:10:14.505Z
2
+ * xeokit-sdk v2.6.113
3
+ * Commit: 35015312cd61fbe9a764d8874667ca89dadefeb0
4
+ * Built: 2026-08-20T08:04:04.016Z
5
5
  */
6
6
 
7
- "undefined"!=typeof window&&(window.__XEOKIT__={version:"2.6.112",commit:"2ce58020bcf3e4af1f68e47009f413c448a8a2a4",built:"2026-06-25T15:10:14.505Z"}),Object.defineProperty(exports,"__esModule",{value:!0});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 s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class i{constructor(){this.items=[]}}class r{constructor(e,t,s,i,r){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=i,this.getShown=r,this.itemElement=null,this.subMenu=null,this.enabled=!0}}function n(e,t,s=2){const i=t&&t.length,r=i?t[0]*s:e.length;let n=A(e,0,r,s,!0);const o=[];if(!n||n.next===n.prev)return o;let l,c,h;if(i&&(n=function(e,t,s,i){const r=[];for(let s=0,n=t.length;s<n;s++){const o=A(e,t[s]*i,s<n-1?t[s+1]*i:e.length,i,!1);o===o.next&&(o.steiner=!0),r.push(m(o))}r.sort(d);for(let e=0;e<r.length;e++)s=p(r[e],s);return s}(e,t,n,s)),e.length>80*s){l=1/0,c=1/0;let t=-1/0,i=-1/0;for(let n=s;n<r;n+=s){const s=e[n],r=e[n+1];s<l&&(l=s),r<c&&(c=r),s>t&&(t=s),r>i&&(i=r)}h=Math.max(t-l,i-c),h=0!==h?32767/h:0}return a(n,o,s,l,c,h,0),o}function A(e,t,s,i,r){let n;if(r===function(e,t,s,i){let r=0;for(let n=t,A=s-i;n<s;n+=i)r+=(e[A]-e[n])*(e[n+1]+e[A+1]),A=n;return r}(e,t,s,i)>0)for(let r=t;r<s;r+=i)n=x(r/i|0,e[r],e[r+1],n);else for(let r=s-i;r>=t;r-=i)n=x(r/i|0,e[r],e[r+1],n);return n&&w(n,n.next)&&(U(n),n=n.next),n}function o(e,t){if(!e)return e;t||(t=e);let s,i=e;do{if(s=!1,i.steiner||!w(i,i.next)&&0!==B(i.prev,i,i.next))i=i.next;else{if(U(i),i=t=i.prev,i===i.next)break;s=!0}}while(s||i!==t);return t}function a(e,t,s,i,r,n,A){if(!e)return;!A&&n&&function(e,t,s,i){let r=e;do{0===r.z&&(r.z=g(r.x,r.y,t,s,i)),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,s=1;do{let i,r=e;e=null;let n=null;for(t=0;r;){t++;let A=r,o=0;for(let e=0;e<s&&(o++,A=A.nextZ,A);e++);let a=s;for(;o>0||a>0&&A;)0!==o&&(0===a||!A||r.z<=A.z)?(i=r,r=r.nextZ,o--):(i=A,A=A.nextZ,a--),n?n.nextZ=i:e=i,i.prevZ=n,n=i;r=A}n.nextZ=null,s*=2}while(t>1)}(r)}(e,i,r,n);let d=e;for(;e.prev!==e.next;){const p=e.prev,f=e.next;if(n?c(e,i,r,n):l(e))t.push(p.i,e.i,f.i),U(e),e=f.next,d=f.next;else if((e=f)===d){A?1===A?a(e=h(o(e),t),t,s,i,r,n,2):2===A&&u(e,t,s,i,r,n):a(o(e),t,s,i,r,n,1);break}}}function l(e){const t=e.prev,s=e,i=e.next;if(B(t,s,i)>=0)return!1;const r=t.x,n=s.x,A=i.x,o=t.y,a=s.y,l=i.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 p=i.next;for(;p!==t;){if(p.x>=c&&p.x<=u&&p.y>=h&&p.y<=d&&b(r,o,n,a,A,l,p.x,p.y)&&B(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function c(e,t,s,i){const r=e.prev,n=e,A=e.next;if(B(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),p=Math.min(c,h,u),f=Math.max(o,a,l),m=Math.max(c,h,u),_=g(d,p,t,s,i),y=g(f,m,t,s,i);let w=e.prevZ,v=e.nextZ;for(;w&&w.z>=_&&v&&v.z<=y;){if(w.x>=d&&w.x<=f&&w.y>=p&&w.y<=m&&w!==r&&w!==A&&b(o,c,a,h,l,u,w.x,w.y)&&B(w.prev,w,w.next)>=0)return!1;if(w=w.prevZ,v.x>=d&&v.x<=f&&v.y>=p&&v.y<=m&&v!==r&&v!==A&&b(o,c,a,h,l,u,v.x,v.y)&&B(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;w&&w.z>=_;){if(w.x>=d&&w.x<=f&&w.y>=p&&w.y<=m&&w!==r&&w!==A&&b(o,c,a,h,l,u,w.x,w.y)&&B(w.prev,w,w.next)>=0)return!1;w=w.prevZ}for(;v&&v.z<=y;){if(v.x>=d&&v.x<=f&&v.y>=p&&v.y<=m&&v!==r&&v!==A&&b(o,c,a,h,l,u,v.x,v.y)&&B(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function h(e,t){let s=e;do{const i=s.prev,r=s.next.next;!w(i,r)&&v(i,s,s.next,r)&&E(i,r)&&E(r,i)&&(t.push(i.i,s.i,r.i),U(s),U(s.next),s=e=r),s=s.next}while(s!==e);return o(s)}function u(e,t,s,i,r,n){let A=e;do{let e=A.next.next;for(;e!==A.prev;){if(A.i!==e.i&&y(A,e)){let l=F(A,e);return A=o(A,A.next),l=o(l,l.next),a(A,t,s,i,r,n,0),void a(l,t,s,i,r,n,0)}e=e.next}A=A.next}while(A!==e)}function d(e,t){let s=e.x-t.x;if(0===s&&(s=e.y-t.y,0===s)){s=(e.next.y-e.y)/(e.next.x-e.x)-(t.next.y-t.y)/(t.next.x-t.x)}return s}function p(e,t){const s=function(e,t){let s=t;const i=e.x,r=e.y;let n,A=-1/0;if(w(e,s))return s;do{if(w(e,s.next))return s.next;if(r<=s.y&&r>=s.next.y&&s.next.y!==s.y){const e=s.x+(r-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(e<=i&&e>A&&(A=e,n=s.x<s.next.x?s:s.next,e===i))return n}s=s.next}while(s!==t);if(!n)return null;const o=n,a=n.x,l=n.y;let c=1/0;s=n;do{if(i>=s.x&&s.x>=a&&i!==s.x&&_(r<l?i:A,r,a,l,r<l?A:i,r,s.x,s.y)){const t=Math.abs(r-s.y)/(i-s.x);E(s,e)&&(t<c||t===c&&(s.x>n.x||s.x===n.x&&f(n,s)))&&(n=s,c=t)}s=s.next}while(s!==o);return n}(e,t);if(!s)return t;const i=F(s,e);return o(i,i.next),o(s,s.next)}function f(e,t){return B(e.prev,e,t.prev)<0&&B(t.next,e,e.next)<0}function g(e,t,s,i,r){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-s)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-i)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function m(e){let t=e,s=e;do{(t.x<s.x||t.x===s.x&&t.y<s.y)&&(s=t),t=t.next}while(t!==e);return s}function _(e,t,s,i,r,n,A,o){return(r-A)*(t-o)>=(e-A)*(n-o)&&(e-A)*(i-o)>=(s-A)*(t-o)&&(s-A)*(n-o)>=(r-A)*(i-o)}function b(e,t,s,i,r,n,A,o){return!(e===A&&t===o)&&_(e,t,s,i,r,n,A,o)}function y(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){let s=e;do{if(s.i!==e.i&&s.next.i!==e.i&&s.i!==t.i&&s.next.i!==t.i&&v(s,s.next,e,t))return!0;s=s.next}while(s!==e);return!1}(e,t)&&(E(e,t)&&E(t,e)&&function(e,t){let s=e,i=!1;const r=(e.x+t.x)/2,n=(e.y+t.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==e);return i}(e,t)&&(B(e.prev,e,t.prev)||B(e,t.prev,t))||w(e,t)&&B(e.prev,e,e.next)>0&&B(t.prev,t,t.next)>0)}function B(e,t,s){return(t.y-e.y)*(s.x-t.x)-(t.x-e.x)*(s.y-t.y)}function w(e,t){return e.x===t.x&&e.y===t.y}function v(e,t,s,i){const r=M(B(e,t,s)),n=M(B(e,t,i)),A=M(B(s,i,e)),o=M(B(s,i,t));return r!==n&&A!==o||(!(0!==r||!C(e,s,t))||(!(0!==n||!C(e,i,t))||(!(0!==A||!C(s,e,i))||!(0!==o||!C(s,t,i)))))}function C(e,t,s){return t.x<=Math.max(e.x,s.x)&&t.x>=Math.min(e.x,s.x)&&t.y<=Math.max(e.y,s.y)&&t.y>=Math.min(e.y,s.y)}function M(e){return e>0?1:e<0?-1:0}function E(e,t){return B(e.prev,e,e.next)<0?B(e,t,e.next)>=0&&B(e,e.prev,t)>=0:B(e,t,e.prev)<0||B(e,e.next,t)<0}function F(e,t){const s=I(e.i,e.x,e.y),i=I(t.i,t.x,t.y),r=e.next,n=t.prev;return e.next=t,t.prev=e,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function x(e,t,s,i){const r=I(e,t,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function U(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 I(e,t,s){return{i:e,x:t,y:s,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}let T=!0,P=T?Float64Array:Float32Array;const S=new P(3),D=new P(16),k=new P(16),Q=new P(4),R={setDoublePrecisionEnabled(e){T=e,P=T?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>T,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new P(e||2),vec3:e=>new P(e||3),vec4:e=>new P(e||4),mat3:e=>new P(e||9),mat3ToMat4:(e,t=new P(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 P(e||16),mat4ToMat3:(e,t=new P(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,s){const i=new P(2);for(let r=0,n=e.length;r<n;r++)R.splitDouble(e[r],i),t[r]=i[0],s[r]=i[1]},splitDouble(e,t){const s=P.from([e])[0],i=e-s;t[0]=s,t[1]=i},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,s=4294967295*Math.random()|0,i=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&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&i|128]}${e[i>>8&255]}-${e[i>>16&255]}${e[i>>24&255]}${e[255&r]}${e[r>>8&255]}${e[r>>16&255]}${e[r>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,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},compareVec2:(e,t)=>e[0]===t[0]&&e[1]===t[1],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,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new P(e[0]);for(let s=1;s<e.length;s++)t[0]+=e[s][0],t[1]+=e[s][1];return t[0]/=e.length,t[1]/=e.length,t},subVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s),mulVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],i=e[1],r=e[2],n=t[0],A=t[1],o=t[2];return[i*o-r*A,r*n-s*o,s*A-i*n,0]},cross3Vec3(e,t,s){s||(s=e);const i=e[0],r=e[1],n=e[2],A=t[0],o=t[1],a=t[2];return s[0]=r*a-n*o,s[1]=n*A-i*a,s[2]=i*o-r*A,s},sqLenVec4:e=>R.dotVec4(e,e),lenVec4:e=>Math.sqrt(R.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=>R.dotVec3(e,e),sqLenVec2:e=>R.dotVec2(e,e),lenVec3:e=>Math.sqrt(R.sqLenVec3(e)),distVec3:(()=>{const e=new P(3);return(t,s)=>R.lenVec3(R.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(R.sqLenVec2(e)),distVec2:(()=>{const e=new P(2);return(t,s)=>R.lenVec2(R.subVec2(t,s,e))})(),rcpVec3:(e,t)=>R.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/R.lenVec4(e);return R.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/R.lenVec3(e);return R.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/R.lenVec2(e);return R.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=R.dotVec3(e,t)/Math.sqrt(R.sqLenVec3(e)*R.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new P(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=R.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=R.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=R.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,i=(t=Array.prototype.slice.call(t)).length;s<i;s++)t[s]=e(t[s]);return t}})(),xyzArrayToObject:e=>({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||R.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:()=>R.m4s(0),setMat4ToOnes:()=>R.m4s(1),diagonalMat4v:e=>new P([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,i)=>R.diagonalMat4v([e,t,s,i]),diagonalMat4s:e=>R.diagonalMat4c(e,e,e,e),identityMat4:(e=new P(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 P(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,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>R.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const i=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],p=e[11],f=e[12],g=e[13],m=e[14],_=e[15],b=t[0],y=t[1],B=t[2],w=t[3],v=t[4],C=t[5],M=t[6],E=t[7],F=t[8],x=t[9],U=t[10],I=t[11],T=t[12],P=t[13],S=t[14],D=t[15];return s[0]=b*i+y*o+B*h+w*f,s[1]=b*r+y*a+B*u+w*g,s[2]=b*n+y*l+B*d+w*m,s[3]=b*A+y*c+B*p+w*_,s[4]=v*i+C*o+M*h+E*f,s[5]=v*r+C*a+M*u+E*g,s[6]=v*n+C*l+M*d+E*m,s[7]=v*A+C*c+M*p+E*_,s[8]=F*i+x*o+U*h+I*f,s[9]=F*r+x*a+U*u+I*g,s[10]=F*n+x*l+U*d+I*m,s[11]=F*A+x*c+U*p+I*_,s[12]=T*i+P*o+S*h+D*f,s[13]=T*r+P*a+S*u+D*g,s[14]=T*n+P*l+S*d+D*m,s[15]=T*A+P*c+S*p+D*_,s},mulMat3(e,t,s){s||(s=new P(9));const i=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],p=t[6],f=t[1],g=t[4],m=t[7],_=t[2],b=t[5],y=t[8];return s[0]=i*u+r*f+n*_,s[3]=i*d+r*g+n*b,s[6]=i*p+r*m+n*y,s[1]=A*u+o*f+a*_,s[4]=A*d+o*g+a*b,s[7]=A*p+o*m+a*y,s[2]=l*u+c*f+h*_,s[5]=l*d+c*g+h*b,s[8]=l*p+c*m+h*y,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=R.vec4()){const i=t[0],r=t[1],n=t[2],A=t[3];return s[0]=e[0]*i+e[4]*r+e[8]*n+e[12]*A,s[1]=e[1]*i+e[5]*r+e[9]*n+e[13]*A,s[2]=e[2]*i+e[6]*r+e[10]*n+e[14]*A,s[3]=e[3]*i+e[7]*r+e[11]*n+e[15]*A,s},transposeMat4(e,t){const s=e[4],i=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]=s,e[2]=r,e[3]=A,e[4]=t,e[6]=o,e[7]=n,e[8]=a,e[9]=c,e[11]=i,e[12]=l,e[13]=h,e[14]=u,e}return t[0]=e[0],t[1]=s,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]=i,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],i=e[2],r=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=i,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],s=e[1],i=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],p=e[13],f=e[14],g=e[15];return d*c*o*r-l*p*o*r-d*A*h*r+n*p*h*r+l*A*f*r-n*c*f*r-d*c*i*a+l*p*i*a+d*s*h*a-t*p*h*a-l*s*f*a+t*c*f*a+d*A*i*u-n*p*i*u-d*s*o*u+t*p*o*u+n*s*f*u-t*A*f*u-l*A*i*g+n*c*i*g+l*s*o*g-t*c*o*g-n*s*h*g+t*A*h*g},inverseMat4(e,t){t||(t=e);const s=e[0],i=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],p=e[12],f=e[13],g=e[14],m=e[15],_=s*o-i*A,b=s*a-r*A,y=s*l-n*A,B=i*a-r*o,w=i*l-n*o,v=r*l-n*a,C=c*f-h*p,M=c*g-u*p,E=c*m-d*p,F=h*g-u*f,x=h*m-d*f,U=u*m-d*g,I=1/(_*U-b*x+y*F+B*E-w*M+v*C);return t[0]=(o*U-a*x+l*F)*I,t[1]=(-i*U+r*x-n*F)*I,t[2]=(f*v-g*w+m*B)*I,t[3]=(-h*v+u*w-d*B)*I,t[4]=(-A*U+a*E-l*M)*I,t[5]=(s*U-r*E+n*M)*I,t[6]=(-p*v+g*y-m*b)*I,t[7]=(c*v-u*y+d*b)*I,t[8]=(A*x-o*E+l*C)*I,t[9]=(-s*x+i*E-n*C)*I,t[10]=(p*w-f*y+m*_)*I,t[11]=(-c*w+h*y-d*_)*I,t[12]=(-A*F+o*M-a*C)*I,t[13]=(s*F-i*M+r*C)*I,t[14]=(-p*B+f*b-g*_)*I,t[15]=(c*B-h*b+u*_)*I,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||R.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||R.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new P(3);return(t,s,i,r)=>(e[0]=t,e[1]=s,e[2]=i,R.translationMat4v(e,r))})(),translationMat4s:(e,t)=>R.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>R.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,i){const r=i[3];i[0]+=r*e,i[1]+=r*t,i[2]+=r*s;const n=i[7];i[4]+=n*e,i[5]+=n*t,i[6]+=n*s;const A=i[11];i[8]+=A*e,i[9]+=A*t,i[10]+=A*s;const o=i[15];return i[12]+=o*e,i[13]+=o*t,i[14]+=o*s,i},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const i=R.normalizeVec4([t[0],t[1],t[2],0],[]),r=Math.sin(e),n=Math.cos(e),A=1-n,o=i[0],a=i[1],l=i[2];let c,h,u,d,p,f;return c=o*a,h=a*l,u=l*o,d=o*r,p=a*r,f=l*r,(s=s||R.mat4())[0]=A*o*o+n,s[1]=A*c+f,s[2]=A*u-p,s[3]=0,s[4]=A*c-f,s[5]=A*a*a+n,s[6]=A*h+d,s[7]=0,s[8]=A*u+p,s[9]=A*h-d,s[10]=A*l*l+n,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,i,r)=>R.rotationMat4v(e,[t,s,i],r),scalingMat4v:(e,t=R.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=R.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new P(3);return(t,s,i,r)=>(e[0]=t,e[1]=s,e[2]=i,R.scalingMat4v(e,r))})(),scaleMat4c:(e,t,s,i)=>(i[0]*=e,i[4]*=t,i[8]*=s,i[1]*=e,i[5]*=t,i[9]*=s,i[2]*=e,i[6]*=t,i[10]*=s,i[3]*=e,i[7]*=t,i[11]*=s,i),scaleMat4v(e,t){const s=e[0],i=e[1],r=e[2];return t[0]*=s,t[4]*=i,t[8]*=r,t[1]*=s,t[5]*=i,t[9]*=r,t[2]*=s,t[6]*=i,t[10]*=r,t[3]*=s,t[7]*=i,t[11]*=r,t},scalingMat4s:e=>R.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=R.mat4()){const i=e[0],r=e[1],n=e[2],A=e[3],o=i+i,a=r+r,l=n+n,c=i*o,h=i*a,u=i*l,d=r*a,p=r*l,f=n*l,g=A*o,m=A*a,_=A*l;return s[0]=1-(d+f),s[1]=h+_,s[2]=u-m,s[3]=0,s[4]=h-_,s[5]=1-(c+f),s[6]=p+g,s[7]=0,s[8]=u+m,s[9]=p-g,s[10]=1-(c+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=R.vec4()){const i=R.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?(s[1]=Math.asin(i(A,-1,1)),Math.abs(A)<.99999?(s[0]=Math.atan2(-l,u),s[2]=Math.atan2(-n,r)):(s[0]=Math.atan2(h,a),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-i(l,-1,1)),Math.abs(l)<.99999?(s[1]=Math.atan2(A,u),s[2]=Math.atan2(o,a)):(s[1]=Math.atan2(-c,r),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(i(h,-1,1)),Math.abs(h)<.99999?(s[1]=Math.atan2(-c,u),s[2]=Math.atan2(-n,a)):(s[1]=0,s[2]=Math.atan2(o,r))):"ZYX"===t?(s[1]=Math.asin(-i(c,-1,1)),Math.abs(c)<.99999?(s[0]=Math.atan2(h,u),s[2]=Math.atan2(o,r)):(s[0]=0,s[2]=Math.atan2(-n,a))):"YZX"===t?(s[2]=Math.asin(i(o,-1,1)),Math.abs(o)<.99999?(s[0]=Math.atan2(-l,a),s[1]=Math.atan2(-c,r)):(s[0]=0,s[1]=Math.atan2(A,u))):"XZY"===t&&(s[2]=Math.asin(-i(n,-1,1)),Math.abs(n)<.99999?(s[0]=Math.atan2(h,a),s[1]=Math.atan2(A,r)):(s[0]=Math.atan2(-l,u),s[1]=0)),s[0]*=R.RADTODEG,s[1]*=R.RADTODEG,s[2]*=R.RADTODEG,s},composeMat4:(e,t,s,i=R.mat4())=>(R.quaternionToRotationMat4(t,i),R.scaleMat4v(s,i),R.translateMat4v(e,i),i),decomposeMat4:(()=>{const e=new P(3),t=new P(16);return function(s,i,r,n){e[0]=s[0],e[1]=s[1],e[2]=s[2];let A=R.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const o=R.lenVec3(e);e[0]=s[8],e[1]=s[9],e[2]=s[10];const a=R.lenVec3(e);R.determinantMat4(s)<0&&(A=-A),i[0]=s[12],i[1]=s[13],i[2]=s[14],t.set(s);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,R.mat4ToQuaternion(t,r),n[0]=A,n[1]=o,n[2]=a,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,i){i||(i=R.mat4());const r=e[0],n=e[1],A=e[2],o=s[0],a=s[1],l=s[2],c=t[0],h=t[1],u=t[2];if(r===c&&n===h&&A===u)return R.identityMat4();let d,p,f,g,m,_,b,y,B,w;return d=r-c,p=n-h,f=A-u,w=1/Math.sqrt(d*d+p*p+f*f),d*=w,p*=w,f*=w,g=a*f-l*p,m=l*d-o*f,_=o*p-a*d,w=Math.sqrt(g*g+m*m+_*_),w?(w=1/w,g*=w,m*=w,_*=w):(g=0,m=0,_=0),b=p*_-f*m,y=f*g-d*_,B=d*m-p*g,w=Math.sqrt(b*b+y*y+B*B),w?(w=1/w,b*=w,y*=w,B*=w):(b=0,y=0,B=0),i[0]=g,i[1]=b,i[2]=d,i[3]=0,i[4]=m,i[5]=y,i[6]=p,i[7]=0,i[8]=_,i[9]=B,i[10]=f,i[11]=0,i[12]=-(g*r+m*n+_*A),i[13]=-(b*r+y*n+B*A),i[14]=-(d*r+p*n+f*A),i[15]=1,i},lookAtMat4c:(e,t,s,i,r,n,A,o,a)=>R.lookAtMat4v([e,t,s],[i,r,n],[A,o,a],[]),orthoMat4c(e,t,s,i,r,n,A){A||(A=R.mat4());const o=t-e,a=i-s,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]=-(i+s)/a,A[14]=-(n+r)/l,A[15]=1,A},frustumMat4v(e,t,s){s||(s=R.mat4());const i=[e[0],e[1],e[2],0],r=[t[0],t[1],t[2],0];R.addVec4(r,i,D),R.subVec4(r,i,k);const n=2*i[2],A=k[0],o=k[1],a=k[2];return s[0]=n/A,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=n/o,s[6]=0,s[7]=0,s[8]=D[0]/A,s[9]=D[1]/o,s[10]=-D[2]/a,s[11]=-1,s[12]=0,s[13]=0,s[14]=-n*r[2]/a,s[15]=0,s},frustumMat4(e,t,s,i,r,n,A){A||(A=R.mat4());const o=t-e,a=i-s,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]=(i+s)/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,s,i,r){const n=[],A=[];return n[2]=s,A[2]=i,A[1]=n[2]*Math.tan(e/2),n[1]=-A[1],A[0]=A[1]*t,n[0]=-A[0],R.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,s=R.vec3()){const i=t[0],r=t[1],n=t[2];return s[0]=e[0]*i+e[4]*r+e[8]*n+e[12],s[1]=e[1]*i+e[5]*r+e[9]*n+e[13],s[2]=e[2]*i+e[6]*r+e[10]*n+e[14],s},transformPoint4:(e,t,s=R.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const i=s||[],r=t.length;let n,A,o,a;const l=e[0],c=e[1],h=e[2],u=e[3],d=e[4],p=e[5],f=e[6],g=e[7],m=e[8],_=e[9],b=e[10],y=e[11],B=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=i[e]||(i[e]=[0,0,0]),M[0]=l*n+d*A+m*o+B,M[1]=c*n+p*A+_*o+w,M[2]=h*n+f*A+b*o+v,M[3]=u*n+g*A+y*o+C;return i.length=r,i},transformPositions3(e,t,s=t){let i;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 p=e[8],f=e[9],g=e[10];e[11];const m=e[12],_=e[13],b=e[14];for(e[15],i=0;i<r;i+=3)n=t[i+0],A=t[i+1],o=t[i+2],s[i+0]=a*n+h*A+p*o+m,s[i+1]=l*n+u*A+f*o+_,s[i+2]=c*n+d*A+g*o+b;return s},transformPositions4(e,t,s=t){let i;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],p=e[6],f=e[7],g=e[8],m=e[9],_=e[10],b=e[11],y=e[12],B=e[13],w=e[14],v=e[15];for(i=0;i<r;i+=4)n=t[i+0],A=t[i+1],o=t[i+2],s[i+0]=a*n+u*A+g*o+y,s[i+1]=l*n+d*A+m*o+B,s[i+2]=c*n+p*A+_*o+w,s[i+3]=h*n+f*A+b*o+v;return s},transformVec3(e,t,s){const i=t[0],r=t[1],n=t[2];return(s=s||this.vec3())[0]=e[0]*i+e[4]*r+e[8]*n,s[1]=e[1]*i+e[5]*r+e[9]*n,s[2]=e[2]*i+e[6]*r+e[10]*n,s},transformVec4(e,t,s){const i=t[0],r=t[1],n=t[2],A=t[3];return(s=s||R.vec4())[0]=e[0]*i+e[4]*r+e[8]*n+e[12]*A,s[1]=e[1]*i+e[5]*r+e[9]*n+e[13]*A,s[2]=e[2]*i+e[6]*r+e[10]*n+e[14]*A,s[3]=e[3]*i+e[7]*r+e[11]*n+e[15]*A,s},rotateVec2(e,t,s,i=e){const r=Math.cos(s),n=Math.sin(s),A=e[0]-t[0],o=e[1]-t[1];return i[0]=A*r-o*n+t[0],i[1]=A*n+o*r+t[1],e},rotateVec3X(e,t,s,i){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(s)-r[2]*Math.sin(s),n[2]=r[1]*Math.sin(s)+r[2]*Math.cos(s),i[0]=n[0]+t[0],i[1]=n[1]+t[1],i[2]=n[2]+t[2],i},rotateVec3Y(e,t,s,i){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(s)+r[0]*Math.cos(s),n[1]=r[1],n[2]=r[2]*Math.cos(s)-r[0]*Math.sin(s),i[0]=n[0]+t[0],i[1]=n[1]+t[1],i[2]=n[2]+t[2],i},rotateVec3Z(e,t,s,i){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(s)-r[1]*Math.sin(s),n[1]=r[0]*Math.sin(s)+r[1]*Math.cos(s),n[2]=r[2],i[0]=n[0]+t[0],i[1]=n[1]+t[1],i[2]=n[2]+t[2],i},projectVec4(e,t){const s=1/e[3];return(t=t||R.vec2())[0]=e[0]*s,t[1]=e[1]*s,t},unprojectVec3:(()=>{const e=new P(16),t=new P(16),s=new P(16);return function(i,r,n,A){return this.transformVec3(this.mulMat4(this.inverseMat4(r,e),this.inverseMat4(n,t),s),i,A)}})(),lerpVec3(e,t,s,i,r,n){const A=n||R.vec3(),o=(e-t)/(s-t);return A[0]=i[0]+o*(r[0]-i[0]),A[1]=i[1]+o*(r[1]-i[1]),A[2]=i[2]+o*(r[2]-i[2]),A},lerpMat4(e,t,s,i,r,n){const A=n||R.mat4(),o=(e-t)/(s-t);return A[0]=i[0]+o*(r[0]-i[0]),A[1]=i[1]+o*(r[1]-i[1]),A[2]=i[2]+o*(r[2]-i[2]),A[3]=i[3]+o*(r[3]-i[3]),A[4]=i[4]+o*(r[4]-i[4]),A[5]=i[5]+o*(r[5]-i[5]),A[6]=i[6]+o*(r[6]-i[6]),A[7]=i[7]+o*(r[7]-i[7]),A[8]=i[8]+o*(r[8]-i[8]),A[9]=i[9]+o*(r[9]-i[9]),A[10]=i[10]+o*(r[10]-i[10]),A[11]=i[11]+o*(r[11]-i[11]),A[12]=i[12]+o*(r[12]-i[12]),A[13]=i[13]+o*(r[13]-i[13]),A[14]=i[14]+o*(r[14]-i[14]),A[15]=i[15]+o*(r[15]-i[15]),A},flatten(e){const t=[];let s,i,r,n,A;for(s=0,i=e.length;s<i;s++)for(A=e[s],r=0,n=A.length;r<n;r++)t.push(A[r]);return t},identityQuaternion:(e=R.vec4())=>(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=R.vec4()){const i=e[0]*R.DEGTORAD/2,r=e[1]*R.DEGTORAD/2,n=e[2]*R.DEGTORAD/2,A=Math.cos(i),o=Math.cos(r),a=Math.cos(n),l=Math.sin(i),c=Math.sin(r),h=Math.sin(n);return"XYZ"===t?(s[0]=l*o*a+A*c*h,s[1]=A*c*a-l*o*h,s[2]=A*o*h+l*c*a,s[3]=A*o*a-l*c*h):"YXZ"===t?(s[0]=l*o*a+A*c*h,s[1]=A*c*a-l*o*h,s[2]=A*o*h-l*c*a,s[3]=A*o*a+l*c*h):"ZXY"===t?(s[0]=l*o*a-A*c*h,s[1]=A*c*a+l*o*h,s[2]=A*o*h+l*c*a,s[3]=A*o*a-l*c*h):"ZYX"===t?(s[0]=l*o*a-A*c*h,s[1]=A*c*a+l*o*h,s[2]=A*o*h-l*c*a,s[3]=A*o*a+l*c*h):"YZX"===t?(s[0]=l*o*a+A*c*h,s[1]=A*c*a+l*o*h,s[2]=A*o*h-l*c*a,s[3]=A*o*a-l*c*h):"XZY"===t&&(s[0]=l*o*a-A*c*h,s[1]=A*c*a-l*o*h,s[2]=A*o*h+l*c*a,s[3]=A*o*a+l*c*h),s},mat4ToQuaternion(e,t=R.vec4()){const s=e[0],i=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=s+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-i)*h):s>A&&s>c?(h=2*Math.sqrt(1+s-A-c),t[3]=(l-o)/h,t[0]=.25*h,t[1]=(i+n)/h,t[2]=(r+a)/h):A>c?(h=2*Math.sqrt(1+A-s-c),t[3]=(r-a)/h,t[0]=(i+n)/h,t[1]=.25*h,t[2]=(o+l)/h):(h=2*Math.sqrt(1+c-s-A),t[3]=(n-i)/h,t[0]=(r+a)/h,t[1]=(o+l)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,s=R.vec4()){const i=Math.sqrt(R.dotVec3(e,e)*R.dotVec3(t,t));let r=i+R.dotVec3(e,t);return r<1e-8*i?(r=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):R.cross3Vec3(e,t,s),s[3]=r,R.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=R.vec4()){const s=e[3]/2,i=Math.sin(s);return t[0]=i*e[0],t[1]=i*e[1],t[2]=i*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new P(16);return(t,s,i)=>(i=i||R.vec3(),R.quaternionToRotationMat4(t,e),R.mat4ToEuler(e,s,i),i)})(),mulQuaternions(e,t,s=R.vec4()){const i=e[0],r=e[1],n=e[2],A=e[3],o=t[0],a=t[1],l=t[2],c=t[3];return s[0]=A*o+i*c+r*l-n*a,s[1]=A*a+r*c+n*o-i*l,s[2]=A*l+n*c+i*a-r*o,s[3]=A*c-i*o-r*a-n*l,s},vec3ApplyQuaternion(e,t,s=R.vec3()){const i=t[0],r=t[1],n=t[2],A=e[0],o=e[1],a=e[2],l=e[3],c=l*i+o*n-a*r,h=l*r+a*i-A*n,u=l*n+A*r-o*i,d=-A*i-o*r-a*n;return s[0]=c*l+d*-A+h*-a-u*-o,s[1]=h*l+d*-o+u*-A-c*-a,s[2]=u*l+d*-a+c*-o-h*-A,s},quaternionToMat4(e,t){t=R.identityMat4(t);const s=e[0],i=e[1],r=e[2],n=e[3],A=2*s,o=2*i,a=2*r,l=A*n,c=o*n,h=a*n,u=A*s,d=o*s,p=a*s,f=o*i,g=a*i,m=a*r;return t[0]=1-(f+m),t[1]=d+h,t[2]=p-c,t[4]=d-h,t[5]=1-(u+m),t[6]=g+l,t[8]=p+c,t[9]=g-l,t[10]=1-(u+f),t},quaternionToRotationMat4(e,t){const s=e[0],i=e[1],r=e[2],n=e[3],A=s+s,o=i+i,a=r+r,l=s*A,c=s*o,h=s*a,u=i*o,d=i*a,p=r*a,f=n*A,g=n*o,m=n*a;return t[0]=1-(u+p),t[4]=c-m,t[8]=h+g,t[1]=c+m,t[5]=1-(l+p),t[9]=d-f,t[2]=h-g,t[6]=d+f,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 s=R.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,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)=>R.normalizeQuaternion(R.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=R.vec4()){const s=(e=R.normalizeQuaternion(e,Q))[3],i=2*Math.acos(s),r=Math.sqrt(1-s*s);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]=i,t},AABB3:e=>new P(e||6),AABB2:e=>new P(e||4),OBB3:e=>new P(e||32),OBB2:e=>new P(e||16),Sphere3:(e,t,s,i)=>new P([e,t,s,i]),transformOBB3(e,t,s=t){let i;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],p=e[6],f=e[7],g=e[8],m=e[9],_=e[10],b=e[11],y=e[12],B=e[13],w=e[14],v=e[15];for(i=0;i<r;i+=4)n=t[i+0],A=t[i+1],o=t[i+2],s[i+0]=a*n+u*A+g*o+y,s[i+1]=l*n+d*A+m*o+B,s[i+2]=c*n+p*A+_*o+w,s[i+3]=h*n+f*A+b*o+v;return s},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 P(3),t=new P(3),s=new P(3);return i=>(e[0]=i[0],e[1]=i[1],e[2]=i[2],t[0]=i[3],t[1]=i[4],t[2]=i[5],R.subVec3(t,e,s),Math.abs(R.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new P(3),t=new P(3),s=new P(3);return(i,r)=>{e[0]=i[0],e[1]=i[1],e[2]=i[2],t[0]=i[3],t[1]=i[4],t[2]=i[5];const n=R.subVec3(t,e,s),A=r[0]-i[0],o=i[3]-r[0],a=r[1]-i[1],l=i[4]-r[1],c=r[2]-i[2],h=i[5]-r[2];return n[0]+=A>o?A:o,n[1]+=a>l?a:l,n[2]+=c>h?c:h,Math.abs(R.lenVec3(n))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||R.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||R.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=R.AABB3())=>(e[0]=R.MAX_DOUBLE,e[1]=R.MAX_DOUBLE,e[2]=R.MAX_DOUBLE,e[3]=R.MIN_DOUBLE,e[4]=R.MIN_DOUBLE,e[5]=R.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=R.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 P(3);return(t,s,i)=>{s=s||R.AABB3();let r,n,A,o=R.MAX_DOUBLE,a=R.MAX_DOUBLE,l=R.MAX_DOUBLE,c=R.MIN_DOUBLE,h=R.MIN_DOUBLE,u=R.MIN_DOUBLE;for(let s=0,d=t.length;s<d;s+=3)i?(e[0]=t[s+0],e[1]=t[s+1],e[2]=t[s+2],R.decompressPosition(e,i,e),r=e[0],n=e[1],A=e[2]):(r=t[s+0],n=t[s+1],A=t[s+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 s[0]=o,s[1]=a,s[2]=l,s[3]=c,s[4]=h,s[5]=u,s}})(),OBB3ToAABB3(e,t=R.AABB3()){let s,i,r,n=R.MAX_DOUBLE,A=R.MAX_DOUBLE,o=R.MAX_DOUBLE,a=R.MIN_DOUBLE,l=R.MIN_DOUBLE,c=R.MIN_DOUBLE;for(let t=0,h=e.length;t<h;t+=4)s=e[t+0],i=e[t+1],r=e[t+2],s<n&&(n=s),i<A&&(A=i),r<o&&(o=r),s>a&&(a=s),i>l&&(l=i),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=R.AABB3()){let s,i,r,n=R.MAX_DOUBLE,A=R.MAX_DOUBLE,o=R.MAX_DOUBLE,a=R.MIN_DOUBLE,l=R.MIN_DOUBLE,c=R.MIN_DOUBLE;for(let t=0,h=e.length;t<h;t++)s=e[t][0],i=e[t][1],r=e[t][2],s<n&&(n=s),i<A&&(A=i),r<o&&(o=r),s>a&&(a=s),i>l&&(l=i),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 P(3);return(t,s)=>{s=s||R.vec4();let i,r=0,n=0,A=0;const o=t.length;for(i=0;i<o;i++)r+=t[i][0],n+=t[i][1],A+=t[i][2];s[0]=r/o,s[1]=n/o,s[2]=A/o;let a,l=0;for(i=0;i<o;i++)a=Math.abs(R.lenVec3(R.subVec3(t[i],s,e))),a>l&&(l=a);return s[3]=l,s}})(),positions3ToSphere3:(()=>{const e=new P(3),t=new P(3);return(s,i)=>{i=i||R.vec4();let r,n=0,A=0,o=0;const a=s.length;let l=0;for(r=0;r<a;r+=3)n+=s[r],A+=s[r+1],o+=s[r+2];const c=a/3;let h;for(i[0]=n/c,i[1]=A/c,i[2]=o/c,r=0;r<a;r+=3)e[0]=s[r],e[1]=s[r+1],e[2]=s[r+2],h=Math.abs(R.lenVec3(R.subVec3(e,i,t))),h>l&&(l=h);return i[3]=l,i}})(),OBB3ToSphere3:(()=>{const e=new P(3),t=new P(3);return(s,i)=>{i=i||R.vec4();let r,n=0,A=0,o=0;const a=s.length,l=a/4;for(r=0;r<a;r+=4)n+=s[r+0],A+=s[r+1],o+=s[r+2];i[0]=n/l,i[1]=A/l,i[2]=o/l;let c,h=0;for(r=0;r<a;r+=4)e[0]=s[r+0],e[1]=s[r+1],e[2]=s[r+2],c=Math.abs(R.lenVec3(R.subVec3(e,i,t))),c>h&&(h=c);return i[3]=h,i}})(),getSphere3Center:(e,t=R.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=R.vec3()){let s=0,i=0,r=0;for(var n=0,A=e.length;n<A;n+=3)s+=e[n+0],i+=e[n+1],r+=e[n+2];const o=e.length/3;return t[0]=s/o,t[1]=i/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 s,i,r,n=0,A=t.length;n<A;n+=3)s=t[n],i=t[n+1],r=t[n+2],e[0]>s&&(e[0]=s),e[1]>i&&(e[1]=i),e[2]>r&&(e[2]=r),e[3]<s&&(e[3]=s),e[4]<i&&(e[4]=i),e[5]<r&&(e[5]=r);return e},collapseAABB2:(e=R.AABB2())=>(e[0]=R.MAX_DOUBLE,e[1]=R.MAX_DOUBLE,e[2]=R.MIN_DOUBLE,e[3]=R.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,s){let i,r;e[0]>0?(i=e[0]*s[0],r=e[0]*s[3]):(i=e[0]*s[3],r=e[0]*s[0]),e[1]>0?(i+=e[1]*s[1],r+=e[1]*s[4]):(i+=e[1]*s[4],r+=e[1]*s[1]),e[2]>0?(i+=e[2]*s[2],r+=e[2]*s[5]):(i+=e[2]*s[5],r+=e[2]*s[2]);if(i<=-t&&r<=-t)return-1;return i>=-t&&r>=-t?1:0},OBB3ToAABB2(e,t=R.AABB2()){let s,i,r,n,A=R.MAX_DOUBLE,o=R.MAX_DOUBLE,a=R.MIN_DOUBLE,l=R.MIN_DOUBLE;for(let t=0,c=e.length;t<c;t+=4)s=e[t+0],i=e[t+1],r=e[t+3]||1,n=1/r,s*=n,i*=n,s<A&&(A=s),i<o&&(o=i),s>a&&(a=s),i>l&&(l=i);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,s,i=e){const r=.5*(e[0]+1),n=.5*(e[1]+1),A=.5*(e[2]+1),o=.5*(e[3]+1);return i[0]=Math.floor(r*t),i[1]=s-Math.floor(o*s),i[2]=Math.floor(A*t),i[3]=s-Math.floor(n*s),i},tangentQuadraticBezier:(e,t,s,i)=>2*(1-e)*(s-t)+2*e*(i-s),tangentQuadraticBezier3:(e,t,s,i,r)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*i*(1-e)-3*e*e*i+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,s,i,r){const n=.5*(s-e),A=.5*(i-t),o=r*r;return(2*t-2*s+n+A)*(r*o)+(-3*t+3*s-2*n-A)*o+n*r+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,i){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,i)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,i,r){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,i)+this.b3p3(e,r)},triangleNormal(e,t,s,i=R.vec3()){const r=t[0]-e[0],n=t[1]-e[1],A=t[2]-e[2],o=s[0]-e[0],a=s[1]-e[1],l=s[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?(i[0]=0,i[1]=0,i[2]=0):(i[0]=c/d,i[1]=h/d,i[2]=u/d),i},rayTriangleIntersect:(()=>{const e=new P(3),t=new P(3),s=new P(3),i=new P(3),r=new P(3);return(n,A,o,a,l,c)=>{c=c||R.vec3();const h=R.subVec3(a,o,e),u=R.subVec3(l,o,t),d=R.cross3Vec3(A,u,s),p=R.dotVec3(h,d);if(p<1e-6)return null;const f=R.subVec3(n,o,i),g=R.dotVec3(f,d);if(g<0||g>p)return null;const m=R.cross3Vec3(f,h,r),_=R.dotVec3(A,m);if(_<0||g+_>p)return null;const b=R.dotVec3(u,m)/p;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 P(3),t=new P(3),s=new P(3),i=new P(3);return(r,n,A,o,a,l)=>{l=l||R.vec3(),n=R.normalizeVec3(n,e);const c=R.subVec3(o,A,t),h=R.subVec3(a,A,s),u=R.cross3Vec3(c,h,i);R.normalizeVec3(u,u);const d=-R.dotVec3(A,u),p=-(R.dotVec3(r,u)+d)/R.dotVec3(n,u);return l[0]=r[0]+p*n[0],l[1]=r[1]+p*n[1],l[2]=r[2]+p*n[2],l}})(),cartesianToBarycentric:(()=>{const e=new P(3),t=new P(3),s=new P(3);return(i,r,n,A,o)=>{const a=R.subVec3(A,r,e),l=R.subVec3(n,r,t),c=R.subVec3(i,r,s),h=R.dotVec3(a,a),u=R.dotVec3(a,l),d=R.dotVec3(a,c),p=R.dotVec3(l,l),f=R.dotVec3(l,c),g=h*p-u*u;if(0===g)return null;const m=1/g,_=(p*d-u*f)*m,b=(h*f-u*d)*m;return o[0]=1-_-b,o[1]=b,o[2]=_,o}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,i,r=R.vec3()){const n=e[0],A=e[1],o=e[2];return r[0]=t[0]*n+s[0]*A+i[0]*o,r[1]=t[1]*n+s[1]*A+i[1]*o,r[2]=t[2]*n+s[2]*A+i[2]*o,r},mergeVertices(e,t,s,i){const r={},n=[],A=[],o=t?[]:null,a=s?[]:null,l=[];let c,h,u,d;const p=1e4;let f,g,m=0;for(f=0,g=e.length;f<g;f+=3)c=e[f],h=e[f+1],u=e[f+2],d=`${Math.round(c*p)}_${Math.round(h*p)}_${Math.round(u*p)}`,void 0===r[d]&&(r[d]=A.length/3,A.push(c),A.push(h),A.push(u),t&&(o.push(t[f]),o.push(t[f+1]),o.push(t[f+2])),s&&(a.push(s[m]),a.push(s[m+1]))),n[f/3]=r[d],m+=2;for(f=0,g=i.length;f<g;f++)l[f]=n[i[f]];const _={positions:A,indices:l};return o&&(_.normals=o),a&&(_.uv=a),_},buildNormals:(()=>{const e=new P(3),t=new P(3),s=new P(3),i=new P(3),r=new P(3),n=new P(3);return(A,o,a)=>{let l,c;const h=new Array(A.length/3);let u,d,p,f,g,m,_;for(l=0,c=o.length;l<c;l+=3){u=o[l],d=o[l+1],p=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],s[0]=A[3*p],s[1]=A[3*p+1],s[2]=A[3*p+2],R.subVec3(t,e,i),R.subVec3(s,e,r);const a=R.vec3();R.normalizeVec3(R.cross3Vec3(i,r,n),a),h[u]||(h[u]=[]),h[d]||(h[d]=[]),h[p]||(h[p]=[]),h[u].push(a),h[d].push(a),h[p].push(a)}for(a=a&&a.length===A.length?a:new Float32Array(A.length),l=0,c=h.length;l<c;l++){f=h[l].length,g=0,m=0,_=0;for(let e=0;e<f;e++)g+=h[l][e][0],m+=h[l][e][1],_+=h[l][e][2];a[3*l]=g/f,a[3*l+1]=m/f,a[3*l+2]=_/f}return a}})(),buildTangents:(()=>{const e=new P(3),t=new P(3),s=new P(3),i=new P(3),r=new P(3),n=new P(3),A=new P(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),p=l.subarray(2*u,2*u+2);u=a[h+1];const f=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=R.subVec3(f,d,e),y=R.subVec3(m,d,t),B=R.subVec2(g,p,s),w=R.subVec2(_,p,i),v=1/(B[0]*w[1]-B[1]*w[0]),C=R.mulVec3Scalar(R.subVec3(R.mulVec3Scalar(b,w[1],r),R.mulVec3Scalar(y,B[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,s){const i=t.length,r=s?new Uint16Array(9*i):new Float32Array(9*i),n=new Uint8Array(12*i);let A,o,a,l,c,h,u=0,d=0,p=0;for(let s=0;s<i;s+=3)h=u>>24&255,c=u>>16&255,l=u>>8&255,a=255&u,o=t[s],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[p++]=a,n[p++]=l,n[p++]=c,n[p++]=h,o=t[s+1],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[p++]=a,n[p++]=l,n[p++]=c,n[p++]=h,o=t[s+2],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[p++]=a,n[p++]=l,n[p++]=c,n[p++]=h,u++;return{positions:r,colors:n}},faceToVertexNormals(e,t,s={}){const i=s.smoothNormalsAngleThreshold||20,r={},n=[],A={};let o,a,l,c,h;const u=1e4;let d,p,f,g,m,_;for(p=0,g=e.length;p<g;p+=3){d=p/3,a=e[p],l=e[p+1],c=e[p+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 s=R.normalizeVec3([t[p],t[p+1],t[p+2]]);n[d]=s,o=R.vec4([s[0],s[1],s[2],1]),A[d]=o}for(h in r)if(r.hasOwnProperty(h)){const e=r[h],t=e.length;for(p=0;p<t;p++){const s=e[p];for(o=A[s],f=0;f<t;f++){if(p===f)continue;const t=e[f];m=n[s],_=n[t];Math.abs(R.angleVec3(m,_)/R.DEGTORAD)<i&&(o[0]+=_[0],o[1]+=_[1],o[2]+=_[2],o[3]+=1)}}}for(p=0,g=t.length;p<g;p+=3)o=A[p/3],t[p+0]=o[0]/o[3],t[p+1]=o[1]/o[3],t[p+2]=o[2]/o[3]},transformRay:(()=>{const e=new P(4),t=new P(4);return(s,i,r,n,A)=>{e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=1,R.transformVec4(s,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],R.transformVec3(s,e,t),R.normalizeVec3(t),A[0]=t[0],A[1]=t[1],A[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new P(16),t=new P(4),s=new P(4),i=(t,s,i,r,n)=>{n[0]=t,n[1]=s,n[2]=i,n[3]=1,R.transformVec4(e,n,n),r||R.mulVec4Scalar(n,1/n[3])};return(r,n,A,o,a,l,c)=>{const h="ortho"===o;R.mulMat4(A,n,e),R.inverseMat4(e,e);const u=2*a[0]/r.clientWidth-1,d=1-2*a[1]/r.clientHeight;i(u,d,-1,h,t),i(u,d,1,h,s),l[0]=t[0],l[1]=t[1],l[2]=t[2],R.subVec3(s,t,c),R.normalizeVec3(c)}})(),canvasPosToLocalRay:(()=>{const e=new P(3),t=new P(3);return(s,i,r,n,A,o,a,l)=>{R.canvasPosToWorldRay(s,i,r,n,o,e,t),R.worldRayToLocalRay(A,e,t,a,l)}})(),worldRayToLocalRay:(()=>{const e=new P(16),t=new P(4),s=new P(4);return(i,r,n,A,o)=>{const a=R.inverseMat4(i,e);t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,R.transformVec4(a,t,s),A[0]=s[0],A[1]=s[1],A[2]=s[2],R.transformVec3(a,n,o)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,i,r,n){const A=new P(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=s.length;a<l;++a){var c=3*s[a];for(let e=0;e<3;++e){const t=3*i[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(s.length<20||n>10)return o.triangles=s,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(s.length);let p=0;const f=new Array(s.length);let g=0;for(a=0,l=s.length;a<l;++a){const e=i[c=3*s[a]],t=3*i[c+1],n=3*i[c+2];r[3*e+h]<=u||r[t+h]<=u||r[n+h]<=u?d[p++]=s[a]:f[g++]=s[a]}return d.length=p,f.length=g,o.left=t(d,i,r,n+1),o.right=t(f,i,r,n+1),o}return(e,s)=>{const i=e.length/3,r=new Array(i);for(let e=0;e<i;++e)r[e]=e;return t(r,e,s,0)}})(),decompressPosition(e,t,s){(s=s||e)[0]=e[0]*t[0]+t[12],s[1]=e[1]*t[5]+t[13],s[2]=e[2]*t[10]+t[14]},decompressPositions(e,t,s=new Float32Array(e.length)){for(let i=0,r=e.length;i<r;i+=3)s[i+0]=e[i+0]*t[0]+t[12],s[i+1]=e[i+1]*t[5]+t[13],s[i+2]=e[i+2]*t[10]+t[14];return s},decompressUV(e,t,s){s[0]=e[0]*t[0]+t[6],s[1]=e[1]*t[4]+t[7]},decompressUVs(e,t,s=new Float32Array(e.length)){for(let i=0,r=e.length;i<r;i+=3)s[i+0]=e[i+0]*t[0]+t[6],s[i+1]=e[i+1]*t[4]+t[7];return s},octDecodeVec2(e,t){let s=e[0],i=e[1];s=(2*s+1)/255,i=(2*i+1)/255;const r=1-Math.abs(s)-Math.abs(i);r<0&&(s=(1-Math.abs(i))*(s>=0?1:-1),i=(1-Math.abs(s))*(i>=0?1:-1));const n=Math.sqrt(s*s+i*i+r*r);return t[0]=s/n,t[1]=i/n,t[2]=r/n,t},octDecodeVec2s(e,t){for(let s=0,i=0,r=e.length;s<r;s+=2){let r=e[s+0],n=e[s+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[i+0]=r/o,t[i+1]=n/o,t[i+2]=A/o,i+=3}return t}};R.buildEdgeIndices=function(){const e=[],t=[],s=[],i=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=R.vec3(),c=R.vec3(),h=R.vec3(),u=R.vec3(),d=R.vec3(),p=R.vec3(),f=R.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,p=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]=p/3,e[p++]=o,e[p++]=a,e[p++]=l),t[u/3]=A[c];for(u=0,d=n.length;u<d;u++)i[u]=t[n[u]],s[i[u]]=n[u]}(g,m),function(t,s){n=0;for(let g=0,m=t;g<m;g+=3){const t=3*i[g],m=3*i[g+1],_=3*i[g+2];s?(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],R.decompressPosition(A,s,l),R.decompressPosition(o,s,c),R.decompressPosition(a,s,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]),R.subVec3(h,c,u),R.subVec3(l,c,d),R.cross3Vec3(u,d,p),R.normalizeVec3(p,f);const b=r[n]||(r[n]={normal:R.vec3()});b.normal[0]=f[0],b.normal[1]=f[1],b.normal[2]=f[2],n++}}(m.length,_);const y=[],B=Math.cos(R.DEGTORAD*b),w={};let v,C,M,E,F,x,U,I,T,P,S,D=!1;for(let e=0,t=m.length;e<t;e+=3){const t=e/3;for(let s=0;s<3;s++)v=i[e+s],C=i[e+(s+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)x=w[F],void 0!==x.face2&&(U=r[x.face1].normal,I=r[x.face2].normal,T=R.dotVec3(U,I),T>B)||(P=s[x.index1],S=s[x.index2],(!D&&P>65535||S>65535)&&(D=!0),y.push(P),y.push(S));return D?new Uint32Array(y):new Uint16Array(y)}}(),R.planeClipsPositions3=function(e,t,s,i=3){for(let r=0,n=s.length;r<n;r+=i){if(S[0]=s[r+0]-e[0],S[1]=s[r+1]-e[1],S[2]=s[r+2]-e[2],S[0]*t[0]+S[1]*t[1]+S[2]*t[2]<0)return!0}return!1},R.planeIntersectsAABB3=(e,t)=>{const s=[t[0],t[1],t[2]],i=[t[3],t[4],t[5]],r=[[s[0],s[1],s[2]],[i[0],s[1],s[2]],[s[0],i[1],s[2]],[i[0],i[1],s[2]],[s[0],s[1],i[2]],[i[0],s[1],i[2]],[s[0],i[1],i[2]],[i[0],i[1],i[2]]];let n=!1,A=!1;for(const t of r){const s=e.dist+R.dotVec3(e.dir,t);if(s>0&&(n=!0),s<0&&(A=!0),n&&A)return!0}return!1},R.makeSectionPlaneSlicer=function(){const e=R.vec2(),t=R.vec2(),s=R.vec2(),i=R.vec2(),r=R.vec3(),A=R.vec3(),o=R.vec3();R.vec3();const a=[R.vec3(),R.vec3(),R.vec3()],l=[null,null,null],c=[null,null,null],h=[null,null,null],u=[1,0,0],d=[0,1,0],p=[0,0,1],f=function(){const e=R.vec3();return(t,s)=>R.sqLenVec3(R.subVec3(t,s,e))}(),g=e=>{const t=[];for(let s=0;s<e;++s)t.push(s);return t},m=(e,t,s)=>(s[1]-e[1])*(t[0]-e[0])>(t[1]-e[1])*(s[0]-e[0]);return function(_){const b=R.vec3ApplyQuaternion(_.quaternion,u,R.vec3()),y=R.vec3ApplyQuaternion(_.quaternion,d,R.vec3()),B=R.vec3ApplyQuaternion(_.quaternion,p,R.vec3());return function(u,d={}){const p=R.subVec3(u.origin,_.pos,R.vec3()),w=R.dotVec3(B,p),v=[],C=[null],M=(e,t)=>{const s=C.length,i=new Float64Array(5);return i.set(e),t&&(R.addVec3(p,e,r),i[3]=-R.dotVec3(b,r),i[4]=R.dotVec3(y,r)),C.push(i),s},E=(e,t)=>{const s=C[e];return t[0]=s[3],t[1]=s[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],s),n=E(l[t],i);if(m(A,r,n)!==m(h,r,n)&&m(A,h,r)!==m(A,h,n))return!1;const[a,d]=r,[p,f]=n,g=o-a,_=c-d,b=p-a,y=f-d,B=(0!==b||0!==y)&&Math.abs(b*_-y*g)<1e-10?g*b+_*y:-1;if(B>=0&&B<=Math.pow(b,2)+Math.pow(y,2))return!1;d>c!=f>c&&g<_*b/y&&(u=!u)}if(!u)return!1}return!0},x={indices:[],normals:[]},U=!d.onlyPosSliceWithUV&&{indices:[],normals:[]},I=(e,t,s)=>{if(e){const i=C[t[0]];s||=R.normalizeVec3(R.cross3Vec3(R.subVec3(C[t[1]],i,r),R.subVec3(C[t[2]],i,A),r),r);for(let i=0;i<3;++i)e.indices.push(t[i]),e.normals.push(s[0],s[1],s[2])}},T=(e,t)=>{const s=3*u.indices[e];return t[0]=u.positions[s+0],t[1]=u.positions[s+1],t[2]=u.positions[s+2],t};for(let e=0;e<u.indices.length;e+=3){const t=T(e+0,a[0]),s=T(e+1,a[1]),i=T(e+2,a[2]);if(R.compareVec3(t,s)||R.compareVec3(s,i)||R.compareVec3(i,t))continue;const n=w+R.dotVec3(B,t),A=w+R.dotVec3(B,s),o=w+R.dotVec3(B,i);if(0!==n||0!==A||0!==o){const e=n*A<=0&&M(R.lerpVec3(n/(n-A),0,1,t,s,r),!0),a=A*o<=0&&M(R.lerpVec3(A/(A-o),0,1,s,i,r),!0),u=o*n<=0&&M(R.lerpVec3(o/(o-n),0,1,i,t,r),!0),p=!d.onlyPosSliceWithUV&&c;if(p&&(p[0]=M(t),p[1]=M(s),p[2]=M(i)),e?a||u:a&&u){if(v.push(e?[e,a||u]:[a,u]),p)if(0===n&&0===A)I(o>0?x:U,p);else if(0===n&&0===o)I(A>0?x:U,p);else if(0===A&&0===o)I(n>0?x:U,p);else{const t=(e?n:A)>0,s=t?x:U,i=t?U:x,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(s,[p[o[0]],r[o[0]],p[o[2]]]),I(s,[r[o[0]],r[o[1]],p[o[2]]]),I(i,[r[o[0]],p[o[1]],r[o[1]]])):(I(s,[p[o[0]],r[o[0]],r[o[2]]]),I(i,[r[o[0]],p[o[1]],p[o[2]]]),I(i,[r[o[0]],p[o[2]],r[o[2]]]))}}else p&&(n>=0&&A>=0&&o>=0?I(x,p):n<=0&&A<=0&&o<=0&&I(U,p))}}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]],s={distSq:f(C[e[0]],t),idx:-1,side:-1};if(v.forEach(((e,i)=>{const r=f(C[e[0]],t),n=f(C[e[1]],t),A=Math.min(r,n);s.distSq>A&&(s.distSq=A,s.idx=i,s.side=n<r?1:0)})),!(s.distSq<1e-20)){P.pop();break}{const i=s.idx>=0&&v[s.idx];if(C[i?i[s.side]:e[0]]=t,!i)break;{v.splice(s.idx,1);const t=i[1-s.side];if(!(f(C[t],C[e[0]])>1e-20))break;e.push(t)}}}}const S=P.filter((e=>e.length>2)).map(((s,i)=>{let r=0;const n=R.collapseAABB2(R.AABB2());for(let i=0;i<s.length;i++)E(s[i],e),R.expandAABB2Point2(n,e),E(s[(i+1)%s.length],t),r+=e[0]*t[1]-t[0]*e[1];return{boundingBox:n,doubleArea:Math.abs(r),endPoints:s}})).sort(((e,t)=>t.doubleArea-e.doubleArea));for(;S.length>0;){const t=[],s=[],i=i=>i.endPoints.forEach((i=>{E(i,e),t.push(e[0],e[1]),s.push(i)})),r=S.shift();i(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,i(e),a.push(e),S.splice(c,1)):++c}const h=n(t,a.map((e=>e.index)));for(let e=0;e<h.length;e+=3){const t=l;t[0]=s[h[e+0]],t[1]=s[h[e+1]],t[2]=s[h[e+2]];const i=C[t[0]];R.subVec3(C[t[1]],i,A),R.subVec3(C[t[2]],i,o),R.normalizeVec3(R.cross3Vec3(A,o,o),o);const r=R.dotVec3(o,B)<=0;I(r?x:U,t,o);const n=t[0];t[0]=t[2],t[2]=n,I(r?U:x,t,R.negateVec3(o,o))}}const D=e=>e&&e.indices.length>0&&function(){const t=[],s=d.onlyPosSliceWithUV&&[];return e.indices.forEach((e=>{const i=C[e];t.push(i[0],i[1],i[2]),s&&s.push(i[3],i[4])})),{indices:g(e.indices.length),positions:t,normals:e.normals,uv:s}}();return{pos:D(x),neg:D(U)}}}}();const O=new Float32Array(3);class V{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 L={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 H=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),i=s+e[1],r=s;r<i;++r)t.push(r);return String.fromCharCode.apply(null,t)})).join("");function N(e,t){return(t&&4!==t?[0,6]:[0,6,12,18]).map((function(t){return H.substr(parseInt(e/(1<<t))%64,1)})).reverse().join("")}const G=function(){for(var e={},t=window.location.search.substring(1).split("&"),s=0;s<t.length;s++){var i=t[s].split("=");if(void 0===e[i[0]])e[i[0]]=decodeURIComponent(i[1]);else if("string"==typeof e[i[0]]){var r=[e[i[0]],decodeURIComponent(i[1])];e[i[0]]=r}else e[i[0]].push(decodeURIComponent(i[1]))}return e}();const j={xmlToJson:function e(t,s){if(t.nodeType===t.TEXT_NODE){var i=t.nodeValue;if(null===i.match(/^\s+$/))return i}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[s[A.nodeName]||A.nodeName]=A.nodeValue}for(var o=0;o<t.childNodes.length;o++){(n=e(t.childNodes[o],s))&&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 N(t[0],2)+[1,4,7,10,13].map((function(e){return N((t[e]<<16)+(t[e+1]<<8)+t[e+2])})).join("")},findNodeOfType:function(e,t){var s=[],i=function(e){e.type===t&&s.push(e),(e.children||[]).forEach((function(e){i(e)}))};return i(e),s},timeout:function(e){return new Promise((function(t,s){setTimeout(t,e)}))},httpRequest:function(e){return new Promise((function(t,s){var i=new XMLHttpRequest;i.open(e.method||"GET",e.url,!0),i.onload=function(e){4===i.readyState&&(200===i.status?t(i.responseXML):s(i.statusText))},i.send(null)}))},loadJSON:function(e,t,s){var i=e=>{};t=t||i,s=s||i;var r=new XMLHttpRequest;r.overrideMimeType("application/json"),r.open("GET",e,!0),r.addEventListener("load",(function(e){var i=e.target.response;if(200===this.status){var r;try{r=JSON.parse(i)}catch(e){s(`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(i))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),r.addEventListener("error",(function(e){s(e)}),!1),r.send(null)},loadArraybuffer:function(e,t,s){var i=e=>{};t=t||i,s=s||i;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),s=new Uint8Array(e);for(var A=0;A<n.length;A++)s[A]=n.charCodeAt(A);q.scheduleTask((()=>{t(e)}))}catch(e){q.scheduleTask((()=>{s(e)}))}}else{const i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onreadystatechange=function(){4===i.readyState&&(200===i.status?t(i.response):s("loadArrayBuffer error : "+i.response))},i.send(null)}},queryString:G,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 j.isString(e)||j.isNumeric(e)},isSameComponent:function(e,t){return!(!e||!t)&&(j.isNumeric(e)||j.isString(e)?`${e}`:e.id)===(j.isNumeric(t)||j.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 j.apply(e,{})},apply:function(e,t){for(const s in e)e.hasOwnProperty(s)&&(t[s]=e[s]);return t},apply2:function(e,t){for(const s in e)e.hasOwnProperty(s)&&void 0!==e[s]&&null!==e[s]&&(t[s]=e[s]);return t},applyIf:function(e,t){for(const s in e)e.hasOwnProperty(s)&&(void 0!==t[s]&&null!==t[s]||(t[s]=e[s]));return t},isEmptyObject:function(e){for(const t in e)if(e.hasOwnProperty(t))return!1;return!0},inQuotes:function(e){return j.isNumeric(e)?`${e}`:`'${e}'`},concat:function(e,t){const s=new e.constructor(e.length+t.length);return s.set(e),s.set(t,e.length),s},flattenParentChildHierarchy:function(e){var t=[];return function e(s){s.id=s.uuid,delete s.oid,t.push(s);var i=s.children;if(i)for(var r=0,n=i.length;r<n;r++){i[r].parent=s.id,e(i[r])}s.children=[]}(e),t}},z={},W=new e,X=new V,K={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},Z=[];let J,Y=0,$=0;const q=new function(){this.version="1.0.0",this.scenes={},this._superTypes={},this._addScene=function(e){if(e.id){if(q.scenes[e.id])return void console.error(`[ERROR] Scene ${j.inQuotes(e.id)} already exists`)}else e.id=W.addItem({});q.scenes[e.id]=e;const t=e.ticksPerOcclusionTest,s=e.ticksPerRender;z[e.id]={ticksPerOcclusionTest:t,ticksPerRender:s,renderCountdown:s},L.components.scenes++,e.once("destroyed",(()=>{W.removeItem(e.id),delete q.scenes[e.id],delete z[e.id],L.components.scenes--}))},this.clear=function(){let e;for(const t in q.scenes)q.scenes.hasOwnProperty(t)&&(e=q.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete q.scenes[e.id]))},this.scheduleTask=function(e,t=null){X.push(e),X.push(t)},this.runTasks=function(e=-1){let t,s,i=(new Date).getTime(),r=0;for(;X.length>0&&(e<0||i<e);)t=X.shift(),s=X.shift(),s?t.call(s):t(),i=(new Date).getTime(),r++;return r},this.getNumTasks=function(){return X.length}},ee=function(){let e=Date.now();if(J=e-Y,Y>0&&J>0){var t=1e3/J;$+=t,Z.push(t),Z.length>=30&&($-=Z.shift()),L.frame.fps=Math.round($/Z.length)}for(let e in q.scenes)q.scenes[e].compile();se(e),Y=e};!function(e,t){let s=Date.now()+t;(function i(){const r=Date.now()-s;e(),s+=t,setTimeout(i,Math.max(0,t-r))})()}((()=>{ee()}),100);const te=function(){let e=Date.now();if(J=e-Y,Y>0&&J>0){var t=1e3/J;$+=t,Z.push(t),Z.length>=30&&($-=Z.shift()),L.frame.fps=Math.round($/Z.length)}se(e),function(e){for(var t in K.time=e,q.scenes)if(q.scenes.hasOwnProperty(t)){var s=q.scenes[t];K.sceneId=t,K.startTime=s.startTime,K.deltaTime=null!=K.prevTime?K.time-K.prevTime:0,s.fire("tick",K,!0)}K.prevTime=e}(e),function(){const e=q.scenes,t=!1;let s,i,r,n,A;for(A in e)e.hasOwnProperty(A)&&(s=e[A],i=z[A],i||(i=z[A]={}),r=s.ticksPerOcclusionTest,i.ticksPerOcclusionTest!==r&&(i.ticksPerOcclusionTest=r,i.renderCountdown=r),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=r),n=s.ticksPerRender,i.ticksPerRender!==n&&(i.ticksPerRender=n,i.renderCountdown=n),0==--i.renderCountdown&&(s.render(t),i.renderCountdown=n))}(),void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(ee):requestAnimationFrame(te)};function se(e){const t=q.runTasks(e+10),s=q.getNumTasks();L.frame.tasksRun=t,L.frame.tasksScheduled=s,L.frame.tasksBudget=10}te();class ie{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 ie))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,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const i=this._eventSubs[e];let r;if(i)for(const s in i)i.hasOwnProperty(s)&&(r=i[s],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,s,i){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:s,scope:i||this},this._subIdEvents[n]=t;const A=this._events[t];return void 0!==A&&s.call(i||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 s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const i=this,r=this.on(e,(function(e){i.off(r),t.call(s||this,e)}),s)}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+" "+j.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 s=e.component;const i=e.sceneDefault,r=e.sceneSingleton,n=e.type,A=e.on,o=!1!==e.recompiles;if(s&&(j.isNumeric(s)||j.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+j.inQuotes(e))}if(!s)if(!0===r){const e=this.scene.types[n];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===i&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+j.inQuotes(s.id));if(n&&!s.isType(n))return void this.error("Expected a "+n+" type or subtype: "+s.type+" "+j.inQuotes(s.id))}this._attachments||(this._attachments={});const a=this._attached[t];let l,c,h;if(a){if(s&&a.id===s.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 i=e.params.onDetached;i&&(j.isFunction(i)?i(a):i.scope?i.callback.call(i.scope,a):i.callback(a)),e.managingLifecycle&&a.destroy()}if(s){const i={params:e,component:s,subs:[],managingLifecycle:false};i.subs.push(s.once("destroyed",(function(){i.params.component=null,this._attach(i.params)}),this)),o&&i.subs.push(s.on("dirty",(function(){this.fire("dirty",this)}),this)),this._attached[t]=s,this._attachments[s.id]=i;const r=e.onAttached;if(r&&(j.isFunction(r)?r(s):r.scope?r.callback.call(r.scope,s):r.callback(s)),A){let e,t,r,n;for(e in A)if(A.hasOwnProperty(e)){if(t=A[e],j.isFunction(t)?(r=t,n=null):(r=t.callback,n=t.scope),!r)continue;i.subs.push(s.on(e,r,n))}}}return o&&this.fire("dirty",this),this.fire(t,s),s}_checkComponent(e,t){if(!t.isComponent){if(!j.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(!j.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 s=0,i=e.length;s<i;s++)if(e[s]===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():q.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}scheduleTask(e){q.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,s,i,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],s=t.component,i=t.subs,r=0,n=i.length;r<n;r++)s.off(i[r]);t.managingLifecycle&&s.destroy()}if(this._ownedComponents)for(e in this._ownedComponents)this._ownedComponents.hasOwnProperty(e)&&(s=this._ownedComponents[e],s.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 re=R.vec3(),ne=R.vec3(),Ae=R.mat4();class oe{constructor(){this.normal=R.vec3(),this.offset=0,this.testVertex=R.vec3()}set(e,t,s,i){const r=1/Math.sqrt(e*e+t*t+s*s);this.normal[0]=e*r,this.normal[1]=t*r,this.normal[2]=s*r,this.offset=i*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 ae{constructor(){this.planes=[new oe,new oe,new oe,new oe,new oe,new oe]}}function le(e,t,s){const i=R.mulMat4(s,t,Ae),r=i[0],n=i[1],A=i[2],o=i[3],a=i[4],l=i[5],c=i[6],h=i[7],u=i[8],d=i[9],p=i[10],f=i[11],g=i[12],m=i[13],_=i[14],b=i[15];e.planes[0].set(o-r,h-a,f-u,b-g),e.planes[1].set(o+r,h+a,f+u,b+g),e.planes[2].set(o-n,h-l,f-d,b-m),e.planes[3].set(o+n,h+l,f+d,b+m),e.planes[4].set(o-A,h-c,f-p,b-_),e.planes[5].set(o+A,h+c,f+p,b+_)}function ce(e,t){let s=ae.INSIDE;const i=re,r=ne;i[0]=t[0],i[1]=t[1],i[2]=t[2],r[0]=t[3],r[1]=t[4],r[2]=t[5];const n=[i,r];for(let t=0;t<6;++t){const i=e.planes[t];if(i.normal[0]*n[i.testVertex[0]][0]+i.normal[1]*n[i.testVertex[1]][1]+i.normal[2]*n[i.testVertex[2]][2]+i.offset<0)return ae.OUTSIDE;i.normal[0]*n[1-i.testVertex[0]][0]+i.normal[1]*n[1-i.testVertex[1]][1]+i.normal[2]*n[1-i.testVertex[2]][2]+i.offset<0&&(s=ae.INTERSECT)}return s}ae.INSIDE=0,ae.INTERSECT=1,ae.OUTSIDE=2;class he extends ie{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=R.vec2(),this._canvasMarqueeCorner2=R.vec2(),this._canvasMarquee=R.AABB2(),this._marqueeFrustum=new ae,this._marqueeFrustumProjMat=R.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!==he.PICK_MODE_INSIDE&&e!==he.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===he.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=(s,i=ae.INTERSECT)=>{if(i===ae.INTERSECT&&(i=ce(this._marqueeFrustum,s.aabb)),i!==ae.OUTSIDE){if(s.entities){const t=s.entities;for(let s=0,i=t.length;s<i;s++){const i=t[s];if(!i.visible)continue;const r=i.aabb;if(this._pickMode===he.PICK_MODE_INSIDE){ce(this._marqueeFrustum,r)===ae.INSIDE&&e.push(i.id)}else{ce(this._marqueeFrustum,r)!==ae.OUTSIDE&&e.push(i.id)}}}s.left&&t(s.left,i),s.right&&t(s.right,i)}};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,s=e.clientHeight,i=e.clientLeft,r=e.clientTop,n=2/t,A=2/s,o=e.clientHeight/e.clientWidth,a=(this._canvasMarquee[0]-i)*n-1,l=(this._canvasMarquee[2]-i)*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);R.frustumMat4(a,l,c*o,h*o,u,1e4,this._marqueeFrustumProjMat),le(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)}}he.PICK_MODE_INTERSECTS=0,he.PICK_MODE_INSIDE=1;class ue{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 s;const i=e=>{if(!this._running)return;s||(s=e);const r=e-s,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(i)};this._running=!0,requestAnimationFrame(i),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 de{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 s=this._messages[this._locale];if(!s)return null;const i=pe(e,s);return i?t?fe(i,t):i:null}translatePlurals(e,t,s){const i=this._messages[this._locale];if(!i)return null;let r=pe(e,i);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=fe(r,[t]),s&&(r=fe(r,s)),r):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const i=this._eventSubs[e];if(i)for(const e in i)if(i.hasOwnProperty(e)){i[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let i=this._eventSubs[t];i||(i={},this._eventSubs[t]=i);const r=this._eventSubIDMap.addItem();i[r]={callback:s},this._eventSubEvents[r]=t;const n=this._events[t];return void 0!==n&&s(n),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function pe(e,t){if(t[e])return t[e];const s=e.split(".");let i=t;for(let e=0,t=s.length;i&&e<t;e++){i=i[s[e]]}return i}function fe(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,s){return"{{"===e?"{":"}}"===e?"}":t[s]}))}class ge extends ie{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 s=e-t,i=e+t;s<0&&(s=0),i>1&&(i=1);var r=this.getPoint(s),n=this.getPoint(i),A=R.subVec3(n,r,[]);return R.normalizeVec3(A,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_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,s,i=[],r=this.getPoint(0),n=0;for(i.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),n+=R.lenVec3(R.subVec3(t,r,[])),i.push(n),r=t;return this.cacheArcLengths=i,i}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,i=this._getLengths(),r=0,n=i.length;s=t||e*i[n-1];for(var A,o=0,a=n-1;o<=a;)if((A=i[r=Math.floor(o+(a-o)/2)]-s)<0)o=r+1;else{if(!(A>0)){a=r;break}a=r-1}if(i[r=a]===s)return r/(n-1);var l=i[r];return(r+(s-l)/(i[r+1]-l))/(n-1)}}class me extends ge{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 s=(t.length-1)*e,i=Math.floor(s),r=s-i,n=t[0===i?i:i-1],A=t[i],o=t[i>t.length-2?t.length-1:i+1],a=t[i>t.length-3?t.length-1:i+2],l=R.vec3();return l[0]=R.catmullRomInterpolate(n[0],A[0],o[0],a[0],r),l[1]=R.catmullRomInterpolate(n[1],A[1],o[1],a[1],r),l[2]=R.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 _e=R.vec3();const be=R.vec3(),ye=R.vec3(),Be=R.vec3(),we=R.vec3(),ve=R.vec3();class Ce extends ie{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=R.vec3(),this._eye1=R.vec3(),this._up1=R.vec3(),this._look2=R.vec3(),this._eye2=R.vec3(),this._up2=R.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,s){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=s;const i=this.scene.camera,r=!!e.projection&&e.projection!==i.projection;let n,A,o,a,l;if(this._eye1[0]=i.eye[0],this._eye1[1]=i.eye[1],this._eye1[2]=i.eye[2],this._look1[0]=i.look[0],this._look1[1]=i.look[1],this._look1[2]=i.look[2],this._up1[0]=i.up[0],this._up1[1]=i.up[1],this._up1[2]=i.up[2],this._orthoScale1=i.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 i=e;if((j.isNumeric(i)||j.isString(i))&&(l=i,i=this.scene.components[l],!i))return this.error("Component not found: "+j.inQuotes(l)),void(t&&(s?t.call(s):t()));r||(n=i.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=R.getAABB3Center(n);this._look2=c||t;const s=R.subVec3(this._eye1,this._look1,be),i=R.normalizeVec3(s),r=c?R.getAABB3DiagPoint(n,c):R.getAABB3Diag(n),A=e.fitFOV||this._fitFOV,o=Math.abs(r/Math.tan(A*R.DEGTORAD));this._orthoScale2=1.1*r,this._eye2[0]=this._look2[0]+i[0]*o,this._eye2[1]=this._look2[1]+i[1]*o,this._eye2[2]=this._look2[2]+i[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"!==i.projection&&(this._projection2="ortho",this._projMatrix1=i.projMatrix.slice(),this._projMatrix2=i.ortho.matrix.slice(),i.projection="customProjection"),"perspective"===e.projection&&"perspective"!==i.projection&&(this._projection2="perspective",this._projMatrix1=i.projMatrix.slice(),this._projMatrix2=i.perspective.matrix.slice(),i.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,q.scheduleTask(this._update,this)}jumpTo(e){this._jumpTo(e)}_jumpTo(e){this._flying&&this.stop();const t=this.scene.camera;var s,i,r,n,A;if(e.aabb)s=e.aabb;else if(6===e.length)s=e;else if(e.eye||e.look||e.up)r=e.eye,n=e.look,A=e.up;else{let t=e;if((j.isNumeric(t)||j.isString(t))&&(i=t,t=this.scene.components[i],!t))return void this.error("Component not found: "+j.inQuotes(i));s=t.aabb||this.scene.aabb}const o=e.poi;if(s){if(s[3]<=s[0]||s[4]<=s[1]||s[5]<=s[2])return;var a=o?R.getAABB3DiagPoint(s,o):R.getAABB3Diag(s);let i;n=o||R.getAABB3Center(s,n),this._trail?R.subVec3(t.look,n,ve):R.subVec3(t.eye,t.look,ve),R.normalizeVec3(ve);i=(void 0!==e.fit?e.fit:this._fit)?Math.abs(a/Math.tan((e.fitFOV||this._fitFOV)*R.DEGTORAD)):R.lenVec3(R.subVec3(t.eye,t.look,be)),R.mulVec3Scalar(ve,i),t.eye=R.addVec3(n,ve,be),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 s=this.easing?Ce._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(R.subVec3(i.eye,i.look,ve),i.eye=R.lerpVec3(s,0,1,this._eye1,this._eye2,Be),i.look=R.subVec3(Be,ve,ye)):this._flyingLook&&(i.look=R.lerpVec3(s,0,1,this._look1,this._look2,ye),i.up=R.lerpVec3(s,0,1,this._up1,this._up2,we)):this._flyingEyeLookUp&&(i.eye=R.lerpVec3(s,0,1,this._eye1,this._eye2,Be),i.look=R.lerpVec3(s,0,1,this._look1,this._look2,ye),i.up=R.lerpVec3(s,0,1,this._up1,this._up2,we)),this._projection2){const t="ortho"===this._projection2?Ce._easeOutExpo(e,0,1,1):Ce._easeInCubic(e,0,1,1);i.customProjection.matrix=R.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();q.scheduleTask(this._update,this)}static _ease(e,t,s,i){return-s*(e/=i)*(e-2)+t}static _easeInCubic(e,t,s,i){return s*(e/=i)*e*e+t}static _easeOutExpo(e,t,s,i){return s*(1-Math.pow(2,-10*e/i))+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 Me extends ie{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Ce(this),this._t=0,this.state=Me.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,s;const i=performance.now(),r=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==r)switch(this.state){case Me.SCRUBBING:return;case Me.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=Me.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Me.PLAYING_TO:s=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=Me.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,i){return-s*(e/=i)*(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=Me.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=Me.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const i=s.frames[e];i?(this.state=Me.SCRUBBING,this._cameraFlightAnimation.flyTo(i,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=Me.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Me.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Me.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Me.STOPPED=0,Me.SCRUBBING=1,Me.PLAYING=2,Me.PLAYING_TO=3;class Ee extends ie{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),L.memory.meshes++}destroy(){super.destroy(),L.memory.meshes--}}const Fe=new e({});class xe{constructor(e){this.id=Fe.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Fe.removeItem(this.id)}}class Ue{constructor(e,t,s,i,r,n,A,o,a){switch(this._gl=e,this.type=t,this.allocated=!1,s.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=i,this.numItems=0,this.itemSize=r,this.normalized=!!A,this.stride=o||0,this.offset=a||0,this._allocate(s)}_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 Ie=function(){const e=[],t=[],s=[],i=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=R.vec3(),c=R.vec3(),h=R.vec3(),u=R.vec3(),d=R.vec3(),p=R.vec3(),f=R.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,p=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]=p/3,e[p++]=o,e[p++]=a,e[p++]=l),t[u/3]=A[c];for(u=0,d=n.length;u<d;u++)i[u]=t[n[u]],s[i[u]]=n[u]}(g,m),function(t,s){n=0;for(let g=0,m=t;g<m;g+=3){const t=3*i[g],m=3*i[g+1],_=3*i[g+2];s?(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],R.decompressPosition(A,s,l),R.decompressPosition(o,s,c),R.decompressPosition(a,s,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]),R.subVec3(h,c,u),R.subVec3(l,c,d),R.cross3Vec3(u,d,p),R.normalizeVec3(p,f);const b=r[n]||(r[n]={normal:R.vec3()});b.normal[0]=f[0],b.normal[1]=f[1],b.normal[2]=f[2],n++}}(m.length,_);const y=[],B=Math.cos(R.DEGTORAD*b),w={};let v,C,M,E,F,x,U,I,T,P,S,D=!1;for(let e=0,t=m.length;e<t;e+=3){const t=e/3;for(let s=0;s<3;s++)v=i[e+s],C=i[e+(s+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)x=w[F],void 0!==x.face2&&(U=r[x.face1].normal,I=r[x.face2].normal,T=R.dotVec3(U,I),T>B)||(P=s[x.index1],S=s[x.index2],(!D&&P>65535||S>65535)&&(D=!0),y.push(P),y.push(S));return D?new Uint32Array(y):new Uint16Array(y)}}();const Te=function(){const e=R.mat4(),t=R.mat4();return function(s,i){i=i||R.mat4();const r=s[0],n=s[1],A=s[2],o=s[3]-r||1,a=s[4]-n||1,l=s[5]-A||1,c=65535;return R.identityMat4(e),R.translationMat4v(s,e),R.identityMat4(t),R.scalingMat4v([o/c,a/c,l/c],t),R.mulMat4(e,t,i),i}}();var Pe=function(){const e=R.mat4(),t=R.mat4();return function(s,i,r){const n=new Uint16Array(s.length),A=new Float32Array([r[0]!==i[0]?65535/(r[0]-i[0]):0,r[1]!==i[1]?65535/(r[1]-i[1]):0,r[2]!==i[2]?65535/(r[2]-i[2]):0]);let o;for(o=0;o<s.length;o+=3)n[o+0]=Math.max(0,Math.min(65535,Math.floor((s[o+0]-i[0])*A[0]))),n[o+1]=Math.max(0,Math.min(65535,Math.floor((s[o+1]-i[1])*A[1]))),n[o+2]=Math.max(0,Math.min(65535,Math.floor((s[o+2]-i[2])*A[2])));R.identityMat4(e),R.translationMat4v(i,e),R.identityMat4(t),R.scalingMat4v([(r[0]-i[0])/65535,(r[1]-i[1])/65535,(r[2]-i[2])/65535],t);return{quantized:n,decodeMatrix:R.mulMat4(e,t,R.identityMat4())}}}();var Se=function(){const e=R.mat3(),t=R.mat3();return function(s,i,r){const n=new Uint16Array(s.length),A=new Float32Array([65535/(r[0]-i[0]),65535/(r[1]-i[1])]);let o;for(o=0;o<s.length;o+=2)n[o+0]=Math.max(0,Math.min(65535,Math.floor((s[o+0]-i[0])*A[0]))),n[o+1]=Math.max(0,Math.min(65535,Math.floor((s[o+1]-i[1])*A[1])));R.identityMat3(e),R.translationMat3v(i,e),R.identityMat3(t),R.scalingMat3v([(r[0]-i[0])/65535,(r[1]-i[1])/65535],t);return{quantized:n,decodeMatrix:R.mulMat3(e,t,R.identityMat3())}}}();function De(e,t,s,i){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[s](127.5*r+(r<0?-1:0)),Math[i](127.5*n+(n<0?-1:0))])}function ke(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const i=1-Math.abs(t)-Math.abs(s);i<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const r=Math.sqrt(t*t+s*s+i*i);return[t/r,s/r,i/r]}function Qe(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const Re={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let i,r;for(i=0;i<3;i++)t[i]=Number.MAX_VALUE,s[i]=-Number.MAX_VALUE;for(i=0;i<e.length;i+=3)for(r=0;r<3;r++)t[r]=Math.min(t[r],e[i+r]),s[r]=Math.max(s[r],e[i+r]);return{min:t,max:s}},createPositionsDecodeMatrix:Te,compressPositions:Pe,compressPosition:function(e,t,s){const i=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]);s[0]=Math.max(0,Math.min(65535,Math.floor((e[0]-t[0])*i[0]))),s[1]=Math.max(0,Math.min(65535,Math.floor((e[1]-t[1])*i[1]))),s[2]=Math.max(0,Math.min(65535,Math.floor((e[2]-t[2])*i[2])))},decompressPositions:function(e,t,s=new Float32Array(e.length)){for(let i=0,r=e.length;i<r;i+=3)s[i+0]=e[i+0]*t[0]+t[12],s[i+1]=e[i+1]*t[5]+t[13],s[i+2]=e[i+2]*t[10]+t[14];return s},decompressPosition:function(e,t,s){return s[0]=e[0]*t[0]+t[12],s[1]=e[1]*t[5]+t[13],s[2]=e[2]*t[10]+t[14],s},decompressAABB:function(e,t,s=e){return s[0]=e[0]*t[0]+t[12],s[1]=e[1]*t[5]+t[13],s[2]=e[2]*t[10]+t[14],s[3]=e[3]*t[0]+t[12],s[4]=e[4]*t[5]+t[13],s[5]=e[5]*t[10]+t[14],s},getUVBounds:function(e){const t=new Float32Array(2),s=new Float32Array(2);let i,r;for(i=0;i<2;i++)t[i]=Number.MAX_VALUE,s[i]=-Number.MAX_VALUE;for(i=0;i<e.length;i+=2)for(r=0;r<2;r++)t[r]=Math.min(t[r],e[i+r]),s[r]=Math.max(s[r],e[i+r]);return{min:t,max:s}},compressUVs:Se,decompressUVs:function(e,t,s=new Float32Array(e.length)){for(let i=0,r=e.length;i<r;i+=3)s[i+0]=e[i+0]*t[0]+t[6],s[i+1]=e[i+1]*t[4]+t[7];return s},decompressUV:function(e,t,s){s[0]=e[0]*t[0]+t[6],s[1]=e[1]*t[4]+t[7]},compressNormals:function(e){const t=new Int8Array(e.length);let s,i,r,n,A;for(let o=0;o<e.length;o+=3)r=s=De(e,o,"floor","floor"),i=ke(s),n=A=Qe(e,o,i),s=De(e,o,"ceil","floor"),i=ke(s),n=Qe(e,o,i),n>A&&(r=s,A=n),s=De(e,o,"floor","ceil"),i=ke(s),n=Qe(e,o,i),n>A&&(r=s,A=n),s=De(e,o,"ceil","ceil"),i=ke(s),n=Qe(e,o,i),n>A&&(r=s,A=n),t[o]=r[0],t[o+1]=r[1];return t},decompressNormals:function(e,t){for(let s=0,i=0,r=e.length;s<r;s+=2){let r=e[s+0],n=e[s+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[i+0]=r/o,t[i+1]=n/o,t[i+2]=A/o,i+=3}return t},decompressNormal:function(e,t){let s=e[0],i=e[1];s=(2*s+1)/255,i=(2*i+1)/255;const r=1-Math.abs(s)-Math.abs(i);r<0&&(s=(1-Math.abs(i))*(s>=0?1:-1),i=(1-Math.abs(s))*(i>=0?1:-1));const n=Math.sqrt(s*s+i*i+r*r);return t[0]=s/n,t[1]=i/n,t[2]=r/n,t}},Oe=L.memory,Ve=R.AABB3();class Le extends Ee{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new xe({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 s=this._state,i=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=i.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=i.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=i.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=i.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=i.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=i.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=i.TRIANGLE_FAN,s.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'."),s.primitive=i.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=Re.getPositionsBounds(t.positions),i=Re.compressPositions(t.positions,e.min,e.max);s.positions=i.quantized,s.positionsDecodeMatrix=i.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=Re.getUVBounds(t.uv),i=Re.compressUVs(t.uv,e.min,e.max);s.uv=i.quantized,s.uvDecodeMatrix=i.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);if(t.normals&&(this._state.compressGeometry?s.normals=Re.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.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(),Oe.meshes++,s.indices&&(s.indicesBuf=new Ue(i,i.ELEMENT_ARRAY_BUFFER,s.indices,s.indices.length,1,i.STATIC_DRAW),Oe.indices+=s.indicesBuf.numItems),s.positions&&(s.positionsBuf=new Ue(i,i.ARRAY_BUFFER,s.positions,s.positions.length,3,i.STATIC_DRAW),Oe.positions+=s.positionsBuf.numItems),s.normals){let e=s.compressGeometry;s.normalsBuf=new Ue(i,i.ARRAY_BUFFER,s.normals,s.normals.length,3,i.STATIC_DRAW,e),Oe.normals+=s.normalsBuf.numItems}s.colors&&(s.colorsBuf=new Ue(i,i.ARRAY_BUFFER,s.colors,s.colors.length,4,i.STATIC_DRAW),Oe.colors+=s.colorsBuf.numItems),s.uv&&(s.uvBuf=new Ue(i,i.ARRAY_BUFFER,s.uv,s.uv.length,2,i.STATIC_DRAW),Oe.uvs+=s.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,s=Ie(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new Ue(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),Oe.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=R.buildPickTriangles(e.positions,e.indices,e.compressGeometry),i=s.positions,r=s.colors;this._pickTrianglePositionsBuf=new Ue(t,t.ARRAY_BUFFER,i,i.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new Ue(t,t.ARRAY_BUFFER,r,r.length,4,t.STATIC_DRAW,!0),Oe.positions+=this._pickTrianglePositionsBuf.numItems,Oe.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),Re.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=Re.getPositionsBounds(e),i=Re.compressPositions(e,s.min,s.max);e=i.quantized,t.positionsDecodeMatrix=i.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),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),Re.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,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),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),Re.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,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),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,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),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=R.AABB3()),R.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=R.OBB3()),R.positions3ToAABB3(this._state.positions,Ve,this._state.positionsDecodeMatrix),R.AABB3ToOBB3(Ve,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,s=(s,i)=>{const r=3*e[s];for(let e=0;e<3;++e)i[e]=t[r+e];return i},i=[R.vec3(),R.vec3(),R.vec3(),R.vec3()];let r=0;const n=R.vec3([0,0,0]);for(let t=0;t<e.length;t+=3){const e=s(t,i[0]),A=s(t+1,i[1]),o=s(t+2,i[2]);R.addVec3(e,A,i[3]),R.addVec3(o,i[3],i[3]);const a=R.lenVec3(R.cross3Vec3(R.subVec3(A,e,i[1]),R.subVec3(o,e,i[2]),i[0]))/2;r+=a,R.mulVec3Scalar(i[3],a,i[3]),R.addVec3(n,i[3],n)}this._metrics={surfaceArea:r,centroid:R.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(),Oe.meshes--}}const He=L.memory,Ne=R.AABB3();class Ge extends Ee{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new xe({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=R.OBB3();const s=this._state,i=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=i.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=i.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=i.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=i.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=i.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=i.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=i.TRIANGLE_FAN,s.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'."),s.primitive=i.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var r;if(t.positionsDecodeMatrix);else{const e=Re.getPositionsBounds(t.positions),n=Re.compressPositions(t.positions,e.min,e.max);r=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix,s.positionsBuf=new Ue(i,i.ARRAY_BUFFER,r,r.length,3,i.STATIC_DRAW),He.positions+=s.positionsBuf.numItems,R.positions3ToAABB3(t.positions,this._aabb),R.positions3ToAABB3(r,Ne,s.positionsDecodeMatrix),R.AABB3ToOBB3(Ne,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new Ue(i,i.ARRAY_BUFFER,e,e.length,4,i.STATIC_DRAW),He.colors+=s.colorsBuf.numItems}if(t.uv){const e=Re.getUVBounds(t.uv),r=Re.compressUVs(t.uv,e.min,e.max),n=r.quantized;s.uvDecodeMatrix=r.decodeMatrix,s.uvBuf=new Ue(i,i.ARRAY_BUFFER,n,n.length,2,i.STATIC_DRAW),He.uvs+=s.uvBuf.numItems}if(t.normals){const e=Re.compressNormals(t.normals);let r=s.compressGeometry;s.normalsBuf=new Ue(i,i.ARRAY_BUFFER,e,e.length,3,i.STATIC_DRAW,r),He.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new Ue(i,i.ELEMENT_ARRAY_BUFFER,e,e.length,1,i.STATIC_DRAW),He.indices+=s.indicesBuf.numItems;const n=Ie(r,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new Ue(i,i.ELEMENT_ARRAY_BUFFER,n,n.length,1,i.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),He.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(),He.meshes--}}var je={};function ze(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let i=e.zSize||1;i<0&&(console.error("negative zSize not allowed - will invert"),i*=-1);const r=e.center,n=r?r[0]:0,A=r?r[1]:0,o=r?r[2]:0,a=-t+n,l=-s+A,c=-i+o,h=t+n,u=s+A,d=i+o;return j.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 We(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let i=e.zSize||1;i<0&&(console.error("negative zSize not allowed - will invert"),i*=-1);const r=e.center,n=r?r[0]:0,A=r?r[1]:0,o=r?r[2]:0,a=-t+n,l=-s+A,c=-i+o,h=t+n,u=s+A,d=i+o;return j.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 Xe(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let i=e.height||1;i<0&&(console.error("negative height not allowed - will invert"),i*=-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=i/2,u=i/n,d=2*Math.PI/r,p=1/r,f=(t-s)/n,g=[],m=[],_=[],b=[];let y,B,w,v,C,M,E,F,x,U,I;const T=(90-180*Math.atan(i/(s-t))/Math.PI)/90;for(y=0;y<=n;y++)for(C=t-y*f,M=h-y*u,B=0;B<=r;B++)w=Math.sin(B*d),v=Math.cos(B*d),m.push(C*w),m.push(T),m.push(C*v),_.push(B*p),_.push(1*y/n),g.push(C*w+a),g.push(M+l),g.push(C*v+c);for(y=0;y<n;y++)for(B=0;B<=r;B++)E=y*(r+1)+B,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(x=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),B=0;B<=r;B++)w=Math.sin(B*d),v=Math.cos(B*d),U=.5*Math.sin(B*d)+.5,I=.5*Math.cos(B*d)+.5,m.push(t*w),m.push(1),m.push(t*v),_.push(U),_.push(I),g.push(t*w+a),g.push(h+l),g.push(t*v+c);for(B=0;B<r;B++)o=x,E=x+1+B,b.push(E),b.push(E+1),b.push(o)}if(!A&&s>0){for(x=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),B=0;B<=r;B++)w=Math.sin(B*d),v=Math.cos(B*d),U=.5*Math.sin(B*d)+.5,I=.5*Math.cos(B*d)+.5,m.push(s*w),m.push(-1),m.push(s*v),_.push(U),_.push(I),g.push(s*w+a),g.push(0-h+l),g.push(s*v+c);for(B=0;B<r;B++)o=x,E=x+1+B,b.push(o),b.push(E+1),b.push(E)}return j.apply(e,{positions:g,normals:m,uv:_,indices:b})}function Ke(e={}){let t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);let s=e.divisions||1;s<0&&(console.error("negative divisions not allowed - will invert"),s*=-1),s<1&&(s=1),t=t||10,s=s||10;const i=t/s,r=t/2,n=[],A=[];let o=0;for(let e=0,t=-r;e<=s;e++,t+=i)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 j.apply(e,{primitive:"lines",positions:n,indices:A})}function Ze(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);let i=e.xSegments||1;i<0&&(console.error("negative xSegments not allowed - will invert"),i*=-1),i<1&&(i=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=s/2,h=Math.floor(i)||1,u=Math.floor(r)||1,d=h+1,p=u+1,f=t/h,g=s/u,m=new Float32Array(d*p*3),_=new Float32Array(d*p*3),b=new Float32Array(d*p*2);let y,B,w,v,C,M,E,F=0,x=0;for(y=0;y<p;y++){const e=y*g-c;for(B=0;B<d;B++)w=B*f-l,m[F]=w+A,m[F+1]=o,m[F+2]=-e+a,_[F+1]=1,b[x]=B/h,b[x+1]=(u-y)/u,F+=3,x+=2}F=0;const U=new(m.length/3>65535?Uint32Array:Uint16Array)(h*u*6);for(y=0;y<u;y++)for(B=0;B<h;B++)v=B+d*y,C=B+d*(y+1),M=B+1+d*(y+1),E=B+1+d*y,U[F]=E,U[F+1]=C,U[F+2]=v,U[F+3]=E,U[F+4]=M,U[F+5]=C,F+=6;return j.apply(e,{positions:m,normals:_,uv:b,indices:U})}function Je(e={}){const t=e.lod||1,s=e.center?e.center[0]:0,i=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,p,f,g,m,_,b,y,B,w,v,C,M,E;for(u=0;u<=A;u++)for(p=u*Math.PI/A,f=Math.sin(p),g=Math.cos(p),d=0;d<=o;d++)m=2*d*Math.PI/o,_=Math.sin(m),b=Math.cos(m),y=b*f,B=g,w=_*f,v=1-d/o,C=u/A,l.push(y),l.push(B),l.push(w),c.push(v),c.push(C),a.push(s+n*y),a.push(i+n*B),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 j.apply(e,{positions:a,normals:l,uv:c,indices:h})}function Ye(e={}){let t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;let s=e.tube||.3;s<0&&(console.error("negative tube not allowed - will invert"),s*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<4&&(i=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 p,f,g,m,_,b,y,B,w,v,C,M;for(B=0;B<=r;B++)for(y=0;y<=i;y++)p=y/i*n,f=.785398+B/r*Math.PI*2,o=t*Math.cos(p),a=t*Math.sin(p),g=(t+s*Math.cos(f))*Math.cos(p),m=(t+s*Math.cos(f))*Math.sin(p),_=s*Math.sin(f),c.push(g+o),c.push(m+a),c.push(_+l),u.push(1-y/i),u.push(B/r),b=R.normalizeVec3(R.subVec3([g,m,_],[o,a,l],[]),[]),h.push(b[0]),h.push(b[1]),h.push(b[2]);for(B=1;B<=r;B++)for(y=1;y<=i;y++)w=(i+1)*B+y-1,v=(i+1)*(B-1)+y-1,C=(i+1)*(B-1)+y,M=(i+1)*B+y,d.push(w),d.push(v),d.push(C),d.push(C),d.push(M),d.push(w);return j.apply(e,{positions:c,normals:h,uv:u,indices:d})}je.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},je.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(je.parse._buffToStr(e));window.location.href=s},je.clone=function(e){return JSON.parse(JSON.stringify(e))},je.bin={},je.bin.f=new Float32Array(1),je.bin.fb=new Uint8Array(je.bin.f.buffer),je.bin.rf=function(e,t){for(var s=je.bin.f,i=je.bin.fb,r=0;r<4;r++)i[r]=e[t+r];return s[0]},je.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},je.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},je.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},je.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},je.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},je.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},je.parse={},je.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",i=0;i<t.length;i++)s=s.concat(String.fromCharCode(t[i]));return s},je.parse._strToBuff=function(e){for(var t=new ArrayBuffer(e.length),s=new Uint8Array(t),i=0;i<e.length;i++)s[i]=e.charCodeAt(i);return t},je.parse._readLine=function(e,t){for(var s="";10!=e[t];)s+=String.fromCharCode(e[t++]);return s},je.parse.fromJSON=function(e){return JSON.parse(je.parse._buffToStr(e))},je.parse.toJSON=function(e){var t=JSON.stringify(e);return je.parse._strToBuff(t)},je.parse.fromOBJ=function(e){for(var t={groups:{},c_verts:[],c_uvt:[],c_norms:[],i_verts:[],i_uvt:[],i_norms:[]},s={from:0,to:0},i=0,r=new Uint8Array(e);i<r.length;){var n=je.parse._readLine(r,i);i+=n.length+1;var A=(n=(n=n.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==A[0]&&(s.to=t.i_verts.length,null==t.groups[A[1]]&&(t.groups[A[1]]={from:t.i_verts.length,to:0}),s=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,p=parseInt(h[0])-1,f=parseInt(u[0])-1,g=parseInt(c[1])-1,m=parseInt(h[1])-1,_=parseInt(u[1])-1,b=parseInt(c[2])-1,y=parseInt(h[2])-1,B=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),p<0&&(p=w+p+1),f<0&&(f=w+f+1),g<0&&(g=v+g+1),m<0&&(m=v+m+1),_<0&&(_=v+_+1),b<0&&(b=C+b+1),y<0&&(y=C+y+1),B<0&&(B=C+B+1),t.i_verts.push(d,p,f),t.i_uvt.push(g,m,_),t.i_norms.push(b,y,B),5==A.length){var M=A[4].split("/"),E=parseInt(M[0])-1,F=parseInt(M[1])-1,x=parseInt(M[2])-1;E<0&&(E=w+E+1),F<0&&(F=v+F+1),x<0&&(x=C+x+1),t.i_verts.push(d,f,E),t.i_uvt.push(g,_,F),t.i_norms.push(b,B,x)}}}return s.to=t.i_verts.length,t},je.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},s={};s.ident=je.bin.ril(e,0),s.version=je.bin.ril(e,4),s.skinwidth=je.bin.ril(e,8),s.skinheight=je.bin.ril(e,12),s.framesize=je.bin.ril(e,16),s.num_skins=je.bin.ril(e,20),s.num_vertices=je.bin.ril(e,24),s.num_st=je.bin.ril(e,28),s.num_tris=je.bin.ril(e,32),s.num_glcmds=je.bin.ril(e,36),s.num_frames=je.bin.ril(e,40),s.offset_skins=je.bin.ril(e,44),s.offset_st=je.bin.ril(e,48),s.offset_tris=je.bin.ril(e,52),s.offset_frames=je.bin.ril(e,56),s.offset_glcmds=je.bin.ril(e,60),s.offset_end=je.bin.ril(e,64);var i=s.offset_st;t.c_uvt=[];for(var r=0;r<s.num_st;r++){var n=je.bin.rsl(e,i)/s.skinwidth,A=je.bin.rsl(e,i+2)/s.skinheight;t.c_uvt.push(n,A),i+=4}i=s.offset_tris;var o=[],a=[];t.i_verts=o,t.i_uvt=a;for(r=0;r<s.num_tris;r++)o.push(je.bin.rsl(e,i),je.bin.rsl(e,i+2),je.bin.rsl(e,i+4)),a.push(je.bin.rsl(e,i+6),je.bin.rsl(e,i+8),je.bin.rsl(e,i+10)),i+=12;i=s.offset_skins;t.skins=[];for(r=0;r<s.num_skins;r++)t.skins.push(je.bin.rASCII0(e,i)),i+=64;i=s.offset_frames;t.frames=[];var l=je.parse.fromMD2._normals;for(r=0;r<s.num_frames;r++){var c={},h=je.bin.rf(e,i),u=je.bin.rf(e,i+4),d=je.bin.rf(e,i+8);i+=12;var p=je.bin.rf(e,i),f=je.bin.rf(e,i+4),g=je.bin.rf(e,i+8);i+=12,c.name=je.bin.rASCII0(e,i),i+=16,c.verts=[],c.norms=[];for(var m=0;m<s.num_vertices;m++)c.verts.push(e[i]*h+p,e[i+1]*u+f,e[i+2]*d+g),c.norms.push(l[3*e[i+3]],l[3*e[i+3]+1],l[3*e[i+3]+2]),i+=4;t.frames.push(c)}return t},je.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],je.parse.fromCollada=function(e){var t=je.parse._buffToStr(e),s=(new DOMParser).parseFromString(t,"text/xml"),i={},r=(s=s.childNodes[0]).getElementsByTagName("asset")[0],n=s.getElementsByTagName("library_geometries")[0],A=s.getElementsByTagName("library_images")[0],o=s.getElementsByTagName("library_materials")[0],a=s.getElementsByTagName("library_effects")[0];return r&&(i.asset=je.parse.fromCollada._asset(r)),n&&(i.geometries=je.parse.fromCollada._libGeometries(n)),A&&(i.images=je.parse.fromCollada._libImages(A)),o&&(i.materials=je.parse.fromCollada._libMaterials(o)),a&&(i.effects=je.parse.fromCollada._libEffects(a)),i},je.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}},je.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],s=0;s<e.length;s++){var i=e[s],r=je.parse.fromCollada._getMesh(i.getElementsByTagName("mesh")[0]);t.push(r)}return t},je.parse.fromCollada._getMesh=function(e){for(var t={},s=e.getElementsByTagName("source"),i=t.sources={},r=0;r<s.length;r++){for(var n=s[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]);i[s[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 p=u[a];o=[];d[parseInt(p.getAttribute("offset"))]=o;var f=p.getAttribute("semantic");c["s_"+f]="VERTEX"==f?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):p.getAttribute("source").substring(1),c["i_"+f]=o,i[c["s_"+f]]}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},je.parse.fromCollada._libImages=function(e){e=e.getElementsByTagName("image");for(var t={},s=0;s<e.length;s++)t[e[s].getAttribute("id")]=e[s].getElementsByTagName("init_from")[0].textContent;return t},je.parse.fromCollada._libMaterials=function(e){e=e.getElementsByTagName("material");for(var t={},s=0;s<e.length;s++)t[e[s].getAttribute("name")]=e[s].getElementsByTagName("instance_effect")[0].getAttribute("url").substring(1);return t},je.parse.fromCollada._libEffects=function(e){e=e.getElementsByTagName("effect");for(var t={},s=0;s<e.length;s++){for(var i={},r=e[s].getElementsByTagName("newparam"),n=0;n<r.length;n++){var A=r[n].getElementsByTagName("surface")[0];A&&(i.surface=A.getElementsByTagName("init_from")[0].textContent)}t[e[s].getAttribute("id")]=i}return t},je.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=je.bin.rsl(e,0))return null;for(var s=je.bin.ril(e,2),i=6;i<s;){var r=je.bin.rsl(e,i),n=je.bin.ril(e,i+2);15677==r&&(t.edit=je.parse.from3DS._edit3ds(e,i,n)),45056==r&&(t.keyf=je.parse.from3DS._keyf3ds(e,i,n)),i+=n}return t},je.parse.from3DS._edit3ds=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);16384==n&&(null==i.objects&&(i.objects=[]),i.objects.push(je.parse.from3DS._edit_object(e,r,A))),r+=A}return i},je.parse.from3DS._keyf3ds=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);45058==n&&(null==i.desc&&(i.desc=[]),i.desc.push(je.parse.from3DS._keyf_objdes(e,r,A))),r+=A}return i},je.parse.from3DS._keyf_objdes=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);45072==n&&(i.hierarchy=je.parse.from3DS._keyf_objhierarch(e,r,A)),45073==n&&(i.dummy_name=je.bin.rASCII0(e,r+6)),r+=A}return i},je.parse.from3DS._keyf_objhierarch=function(e,t,s){var i={},r=t+6;return i.name=je.bin.rASCII0(e,r),r+=i.name.length+1,i.hierarchy=je.bin.rsl(e,r+4),i},je.parse.from3DS._edit_object=function(e,t,s){var i={},r=t+6;for(i.name=je.bin.rASCII0(e,r),r+=i.name.length+1;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);16640==n&&(i.mesh=je.parse.from3DS._obj_trimesh(e,r,A)),r+=A}return i},je.parse.from3DS._obj_trimesh=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);16656==n&&(i.vertices=je.parse.from3DS._tri_vertexl(e,r,A)),16672==n&&(i.indices=je.parse.from3DS._tri_facel1(e,r,A)),16704==n&&(i.uvt=je.parse.from3DS._tri_mappingcoors(e,r,A)),16736==n&&(i.local=je.parse.from3DS._tri_local(e,r,A)),r+=A}return i},je.parse.from3DS._tri_vertexl=function(e,t,s){var i=[],r=t+6,n=je.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(je.bin.rf(e,r)),i.push(je.bin.rf(e,r+4)),i.push(je.bin.rf(e,r+8)),r+=12;return i},je.parse.from3DS._tri_facel1=function(e,t,s){var i=[],r=t+6,n=je.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(je.bin.rsl(e,r)),i.push(je.bin.rsl(e,r+2)),i.push(je.bin.rsl(e,r+4)),r+=8;return i},je.parse.from3DS._tri_mappingcoors=function(e,t,s){var i=[],r=t+6,n=je.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(je.bin.rf(e,r)),i.push(1-je.bin.rf(e,r+4)),r+=8;return i},je.parse.from3DS._tri_local=function(e,t,s){var i={},r=t+6;return i.X=[je.bin.rf(e,r),je.bin.rf(e,r+4),je.bin.rf(e,r+8)],r+=12,i.Y=[je.bin.rf(e,r),je.bin.rf(e,r+4),je.bin.rf(e,r+8)],r+=12,i.Z=[je.bin.rf(e,r),je.bin.rf(e,r+4),je.bin.rf(e,r+8)],r+=12,i.C=[je.bin.rf(e,r),je.bin.rf(e,r+4),je.bin.rf(e,r+8)],r+=12,i},je.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},s={};return s.id=je.bin.ril(e,0),s.verS=je.bin.ril(e,4),s.texS=je.bin.ril(e,8),s.indS=je.bin.ril(e,12),s.verO=je.bin.ril(e,16),s.verL=je.bin.ril(e,20),s.texO=je.bin.ril(e,24),s.texL=je.bin.ril(e,28),s.indO=je.bin.ril(e,32),s.indL=je.bin.ril(e,36),0!=s.verO&&(t.vertices=je.parse.fromBIV._readFloats(e,s.verO,s.verL)),0!=s.texO&&(t.uvt=je.parse.fromBIV._readFloats(e,s.texO,s.texL)),0!=s.indO&&(t.indices=je.parse.fromBIV._readInts(e,s.indO,s.indL,s.indS)),t},je.parse.toBIV=function(e){for(var t=0,s=0;s<e.indices.length;s++)t=Math.max(t,e.indices[s]);var i=32;t<=65535&&(i=16);var r=40;e.vertices&&(r+=4*e.vertices.length),e.uvt&&(r+=4*e.uvt.length),e.indices&&(r+=e.indices.length*i/8);var n=new Uint8Array(r);je.bin.wil(n,0,1769365870),je.bin.wil(n,4,32),je.bin.wil(n,8,32),je.bin.wil(n,12,i);var A=40;return e.vertices&&(je.bin.wil(n,16,A),je.bin.wil(n,20,4*e.vertices.length),je.parse.fromBIV._writeFloats(n,A,e.vertices),A+=4*e.vertices.length),e.uvt&&(je.bin.wil(n,24,A),je.bin.wil(n,28,4*e.uvt.length),je.parse.fromBIV._writeFloats(n,A,e.uvt),A+=4*e.uvt.length),e.indices&&(je.bin.wil(n,32,A),je.bin.wil(n,36,4*e.indices.length),je.parse.fromBIV._writeInts(n,A,e.indices,i)),n.buffer},je.parse.fromBIV._readFloats=function(e,t,s){for(var i=[],r=0;r<s/4;r++)i.push(je.bin.rf(e,t+4*r));return i},je.parse.fromBIV._writeFloats=function(e,t,s){for(var i=0;i<s.length;i++)je.bin.wf(e,t+4*i,s[i])},je.parse.fromBIV._readInts=function(e,t,s,i){for(var r=[],n=0;n<s/4;n++)16==i&&r.push(je.bin.rsl(e,t+2*n)),32==i&&r.push(je.bin.ril(e,t+4*n));return r},je.parse.fromBIV._writeInts=function(e,t,s,i){for(var r=0;r<s.length;r++)16==i&&je.bin.wsl(e,t+2*r,s[r]),32==i&&je.bin.wil(e,t+4*r,s[r])},je.gen={},je.gen.Plane=function(e,t,s,i){s||(s=1),i||(i=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(s*a/e,i*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},je.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]}},je.gen.Sphere=function(e,t){for(var s={verts:[],inds:[],uvt:[]},i=e+1,r=t+1,n=0;n<r;n++)for(var A=0;A<i;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);s.verts.push(l,c,h),s.uvt.push(A/e,n/t),n<t&&A<e&&s.inds.push(i*n+A,i*n+A+1,i*(n+1)+A,i*n+A+1,i*(n+1)+A,i*(n+1)+A+1)}return s},je.mat={},je.mat.scale=function(e,t,s){return[e,0,0,0,0,t,0,0,0,0,s,0,0,0,0,1]},je.mat.translate=function(e,t,s){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,s,1]},je.mat.rotateDeg=function(e,t,s){var i=Math.PI/180;return je.mat.rotate(e*i,t*i,s*i)},je.mat.rotate=function(e,t,s){var i=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],r=e,n=t,A=s,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 i[0]=a*l,i[1]=-a*u,i[2]=h,i[4]=o*u+c*h*l,i[5]=o*l-c*h*u,i[6]=-c*a,i[8]=c*u-o*h*l,i[9]=c*l+o*h*u,i[10]=o*a,i},je.edit={},je.edit.interpolate=function(e,t,s,i){for(var r=0;r<e.length;r++)s[r]=e[r]+i*(t[r]-e[r])},je.edit.transform=function(e,t){for(var s=0;s<e.length;s+=3){var i=e[s],r=e[s+1],n=e[s+2];e[s+0]=t[0]*i+t[4]*r+t[8]*n+t[12],e[s+1]=t[1]*i+t[5]*r+t[9]*n+t[13],e[s+2]=t[2]*i+t[6]*r+t[10]*n+t[14]}},je.edit.unwrap=function(e,t,s){for(var i=new Array(Math.floor(e.length/3)*s),r=0;r<e.length;r++)for(var n=0;n<s;n++)i[r*s+n]=t[e[r]*s+n];return i},je.edit.remap=function(e,t,s,i){for(var r=new Array(s.length),n=0;n<e.length;n++)for(var A=0;A<i;A++)r[t[n]*i+A]=s[e[n]*i+A];return r},je.utils={},je.utils.getAABB=function(e){var t,s,i,r,n,A;r=n=A=-(t=s=i=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<s&&(s=l),l>n&&(n=l),c<i&&(i=c),l>A&&(A=c)}return{min:{x:t,y:s,z:i},max:{x:r,y:n,z:A}}};const $e={" ":{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 qe(e={}){var t=e.origin||[0,0,0],s=t[0],i=t[1],r=t[2],n=e.size||1,A=[],o=[],a=e.text;j.isNumeric(a)&&(a=""+a);for(var l,c,h,u,d,p,f,g,m,_=(a||"").split("\n"),b=0,y=0,B=.04,w=0;w<_.length;w++){l=0,h=(c=_[w]).length;for(var v=0;v<h;v++)if(u=$e[c.charAt(v)]){d=1,p=-1,f=-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*B+s),A.push(y+m[1]*n*B+i),A.push(0+r),-1===p?p=b:(-1===f||(p=f),f=b),b++,d?d=!1:(o.push(p),o.push(f))):d=1;l+=u.width*B*n}y-=35*B*n}return j.apply(e,{primitive:"lines",positions:A,indices:o})}function et(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 s=[];for(let e=0;e<t-1;e++)s.push(e),s.push(e+1);return j.apply(e,{primitive:"lines",positions:e.points,indices:s})}const tt=R.vec4(4),st=R.vec4(),it=R.vec4(),rt=R.vec3([1,0,0]),nt=R.vec3([0,1,0]),At=R.vec3([0,0,1]),ot=R.vec3(3),at=R.vec3(3),lt=R.identityMat4();class ct extends ie{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=R.vec3(),this._quaternion=R.identityQuaternion(),this._rotation=R.vec3(),this._position=R.vec3(),this._offset=R.vec3(),this._localMatrix=R.identityMat4(),this._worldMatrix=R.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 s=0,i=e.length;s<i;s++)this.addChild(e[s],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=R.vec3()),this._origin.set(e)):this._origin&&(this._origin=null);for(let t=0,s=this._children.length;t<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;t++)this._children[t].edges=e}get edges(){return this._edges}set culled(e){e=!!e,this._culled=e;for(let t=0,s=this._children.length;t<s;t++)this._children[t].culled=e}get culled(){return this._culled}set clippable(e){e=!1!==e,this._clippable=e;for(let t=0,s=this._children.length;t<s;t++)this._children[t].clippable=e}get clippable(){return this._clippable}set collidable(e){e=!1!==e,this._collidable=e;for(let t=0,s=this._children.length;t<s;t++)this._children[t].collidable=e}get collidable(){return this._collidable}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._children.length;t<s;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,s=this._children.length;e<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;t++)this._children[t].castsShadow=e}get castsShadow(){return this._castsShadow}set receivesShadow(e){e=!!e,this._receivesShadow=e;for(let t=0,s=this._children.length;t<s;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)R.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(let t=0,s=e.length;t<s;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_setSubtreeAABBsDirty(e){if(e._aabbDirty=!0,e._children)for(let t=0,s=e._children.length;t<s;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=R.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{let e;R.collapseAABB3(this._aabb);for(let t=0,s=this._children.length;t<s;t++)e=this._children[t],e.collidable&&R.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}addChild(e,t){if(j.isNumeric(e)||j.isString(e)){const t=e;if(!(e=this.scene.component[t]))return void this.warn("Component not found: "+j.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,s=this._children.length;t<s;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,s=this._children.length;t<s;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(j.isNumeric(e)||j.isString(e)){const t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+j.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]),R.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]),R.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=R.identityMat4()),this._localMatrix.set(e||lt),R.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=R.identityMat4()),R.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 tt[0]=e[0],tt[1]=e[1],tt[2]=e[2],tt[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(tt,st),R.mulQuaternions(this.quaternion,st,it),this.quaternion=it,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return tt[0]=e[0],tt[1]=e[1],tt[2]=e[2],tt[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(tt,st),R.mulQuaternions(st,this.quaternion,st),this}rotateX(e){return this.rotate(rt,e)}rotateY(e){return this.rotate(nt,e)}rotateZ(e){return this.rotate(At,e)}translate(e,t){return R.vec3ApplyQuaternion(this.quaternion,e,ot),R.mulVec3Scalar(ot,t,at),R.addVec3(this.position,at,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(rt,e)}translateY(e){return this.translate(nt,e)}translateZ(e){return this.translate(At,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 s=0,i=e.length;s<i;s++)t=e[s],t.destroy()}this._children=[],this._setAABBDirty(),this.scene._aabbDirty=!0}}const ht=R.vec3(),ut=function(){const e=new Float64Array(16),t=new Float64Array(4),s=new Float64Array(4);return function(i,r,n){return n=n||e,t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,R.transformVec4(i,t,s),R.setMat4Translation(i,s,n),n.slice()}}();function dt(e,t,s){const i=Float32Array.from([e[0]])[0],r=e[0]-i,n=Float32Array.from([e[1]])[0],A=e[1]-n,o=Float32Array.from([e[2]])[0],a=e[2]-o;t[0]=i,t[1]=n,t[2]=o,s[0]=r,s[1]=A,s[2]=a}function pt(e,t,s,i=1e3){const r=R.getPositionsCenter(e,ht),n=Math.round(r[0]/i)*i,A=Math.round(r[1]/i)*i,o=Math.round(r[2]/i)*i;s[0]=n,s[1]=A,s[2]=o;const a=0!==s[0]||0!==s[1]||0!==s[2];if(a)for(let s=0,i=e.length;s<i;s+=3)t[s+0]=e[s+0]-n,t[s+1]=e[s+1]-A,t[s+2]=e[s+2]-o;return a}const ft=new e({}),gt=R.vec3(),mt=R.vec4(),_t={3001:"sRGBToLinear"},bt=function(){const e=[],t=[],s=[],i=[],r=[],n=[],A=[],o=(t,s)=>{let i=!1;return e.push((e=>i&&s(t,e))),{toString:()=>(i=!0,t)}},a={createAttribute:function(t,s){let i=!1;e.push((e=>i&&e.push(`in ${t} ${s};`)));const A={toString:()=>(i=!0,s)};return r.push((e=>{const t=i&&e(s);return t&&n.push(t.attributeHash),A.setInputValue=t,null})),A},createFragmentDefinition:(e,t)=>{let s=!1;return i.push((i=>s&&t(e,i))),{toString:()=>(s=!0,e)}},createOutput:(e,t,i)=>{let r=!1;return s.push((s=>r&&s.push(`layout(location = ${i||0}) out ${e} ${t};`))),{toString:()=>(r=!0,t)}},createUniform:(t,i,r)=>{let n=!1;const o=e=>n&&e.push(`uniform ${t} ${i};`);e.push(o),s.push(o);const a={toString:()=>(n=!0,i)};return A.push((e=>{const t=n&&e(i);return r?t&&(e=>r(t,e)):(a.setInputValue=t,null)})),a},createUniformArray:(t,i,r)=>{let n=!1;const o=e=>n&&e.push(`uniform ${t} ${i}[${r}];`);e.push(o),s.push(o);const a={toString:()=>(n=!0,i)};return A.push((e=>(a.setInputValue=n&&e(i),null))),a},createUniformBlock:(t,i,r)=>{let n=!1;const o=Object.keys(i),a=e=>{n&&(e.push(`uniform ${t} {`),o.forEach((t=>e.push(` ${i[t]} ${t};`))),e.push("};"))};e.push(a),s.push(a);const l={};return o.forEach((e=>l[e]={toString:()=>(n=!0,e)})),A.push((e=>{const s=n&&e(t);return r?s&&(e=>r(s,e)):(l.setInputValue=s,null)})),l},createVarying:(i,r,n,A)=>{let o=!1;const a=A?A+" ":"";return e.push((e=>o&&e.push(`${a}out ${i} ${r};`))),t.push((e=>o&&e.push(`${r} = ${n()};`))),s.push((e=>o&&e.push(`${a}in ${i} ${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:s=>{e.setInputValue(s.pickClipPos),t.setInputValue(s.pickClipPosInv)},transformedClipPos:()=>`vec4((${u}.xy / ${u}.w - ${e}) * ${t} * ${u}.w, ${u}.zw)`}}(),p=d?d.transformedClipPos():u,f=[],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?f.push(`gl_FragDepth = ${c.testPerspectiveForGl_FragDepth?`${g} == 0.0 ? gl_FragCoord.z : `:""}log2(${h(_)}) * ${m} * 0.5;`):c.cleanerEdges&&f.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("}")})),y=c.sectionPlanesState,B=y&&function(){const e=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t}(y.getNumAllocatedSectionPlanes()).map((e=>{const t=(t,s,i)=>a.createUniform(t,`sectionPlane${s}${e}`,((t,s)=>{const r=y.sectionPlanes,n=r.length,A=(s.mesh.layerIndex||0)*n,o=e<n&&s.mesh.renderFlags.sectionPlanesActivePerLayer[A+e];return i(t,o,r[e],s.mesh.origin)}));return{act:t("bool","Active",((e,t)=>e(t?1:0))),dir:t("vec3","Dir",((e,t,s)=>t&&e(s.dir))),pos:t("vec3","Pos",((e,t,s,i)=>t&&e(i?R.mulVec3Scalar(R.normalizeVec3(s.dir,gt),-(R.dotVec3(s.dir,i)+s.dist),gt):s.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=B?function(){const e=a.createUniform("vec4","sliceColor",(e=>e(w.sliceColor))),t=s=>(t.needed=!0,`(sliced ? ${e} : ${s})`);return t}():e=>e,C=c.getGammaFactor,M=a.createUniform("float","gammaFactor",(e=>e(C())));c.appendFragmentOutputs(f,C&&(e=>`${b}(${e}, ${M})`),"gl_FragCoord",v);const E=function(){const e=[],t=a.createUniform("float","sliceThickness",(e=>e(w.sliceThickness)));if(B){v.needed&&e.push(" bool sliced = false;"),e.push(` if (${c.clippableTest()}) {`);const s=a.createVarying("highp vec3","vHighpWorldPosition",(()=>`${c.worldPositionAttribute}.xyz`));if(e.push(` float dist = ${B(s)};`),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 i.forEach((t=>t(e))),e}(),x=[...function(){const e=[];return s.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,...f,"}"],U=[`gl_Position = ${p};`,...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,...U,"}"],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(x),k=(e,t)=>{const s=t.join("\n"),i=o.createShader(e);return o.shaderSource(i,s),o.compileShader(i),o.getShaderParameter(i,o.COMPILE_STATUS)?[i]:[null,["Failed to compile",o.getShaderInfoLog(i),s.split("\n").map(((e,t)=>t+1+": "+e+"\n")).join("")]]},[Q,O]=k(o.VERTEX_SHADER,S),[V,L]=k(o.FRAGMENT_SHADER,D),H=e=>(console.error(e.join("\n")),[null,e]);if(O)return H(["Vertex shader error"].concat(O));if(L)return H(["Fragment shader error"].concat(L));{const e=o.createProgram();if(e){if(o.attachShader(e,Q),o.attachShader(e,V),o.linkProgram(e),o.getProgramParameter(e,o.LINK_STATUS)){const t=wt(o,e);r.forEach((e=>e(t)));const s=A.map((e=>e(t))).filter((e=>e)),i=ft.addItem({});return[{id:i,bind:()=>o.useProgram(e),inputSetters:{attributesHash:n.sort().join(", "),setUniforms:(e,t)=>{d&&d.setClipPosInputValue(e),s.forEach((e=>e(t)))}},destroy:()=>{ft.removeItem(i),o.deleteProgram(e),o.deleteShader(Q),o.deleteShader(V)}}]}return H(["",o.getProgramInfoLog(this.program),"","Vertex shader:","",...S,"","Fragment shader:","",...D])}return H(["Failed to allocate program"])}}}},yt=function(e,t){const s=e.createUniform("vec4","lightAmbient",(e=>e(t.getAmbientColorAndIntensity()))),i=t.lights,r=i.map(((t,s)=>{const r={color:e.createUniform("vec4",`lightColor${s}`,(e=>{const t=i[s];mt[0]=t.color[0],mt[1]=t.color[1],mt[2]=t.color[2],mt[3]=t.intensity,e(mt)})),position:e.createUniform("vec3",`lightPos${s}`,(e=>e(i[s].pos))),direction:e.createUniform("vec3",`lightDir${s}`,(e=>e(i[s].dir))),shadowProjMatrix:e.createUniform("mat4",`shadowProjMatrix${s}`,(e=>e(i[s].getShadowViewMatrix()))),shadowViewMatrix:e.createUniform("mat4",`shadowViewMatrix${s}`,(e=>e(i[s].getShadowViewMatrix()))),shadowMap:e.createUniform("sampler2D",`shadowMap${s}`,(e=>e(i[s].getShadowRenderBuf().colorTextures[0])))},n=e=>({glslLight:{isViewSpace:"view"===t.space,getColor:()=>`${r.color}.rgb * ${r.color}.a`,getDirection:(t,s)=>`normalize(${e(t,s)})`,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,s)=>{const i=()=>{const e=s();return e.length>0&&e[0]},r=i();return r&&Bt(e,"samplerCube",t,r.encoding,(e=>{const t=i();t&&e(t.texture)}))},A=n("light",(()=>t.lightMaps)),o=n("reflection",(()=>t.reflectionMaps));return{getHash:()=>t.getHash(),getAmbientColor:()=>`${s}.rgb * ${s}.a`,directionalLights:r.map((e=>e.glslLight)),getIrradiance:A&&(e=>`${A(e)}.rgb`),getReflection:o&&((e,t)=>`${o(e,t)}.rgb`)}},Bt=(e,t,s,i,r)=>{const n=e.createUniform(t,s+"Map",r);return(e,t)=>{const s=t?`texture(${n}, ${e}, ${t})`:`texture(${n}, ${e})`;return 3e3!==i?`${_t[i]}(${s})`:s}},wt=function(e,t){const s={},i=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let r=0;r<i;++r){const n=e.getActiveAttrib(t,r),A=e.getAttribLocation(t,n.name);s[n.name]=function(t){t.bindAtLocation(A),e.enableVertexAttribArray(A);const s=t.attributeDivisor;s&&e.vertexAttribDivisor(A,s)},s[n.name].attributeHash=`${A.toString().padStart(1+Math.floor(Math.log10(i)),"0")}:${n.name}`}const r=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS);for(let i=0;i<r;++i){const r=e.getActiveUniformBlockName(t,i),n=e.getUniformBlockIndex(t,r),A=i;e.uniformBlockBinding(t,n,A);const o=e.createBuffer();s[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 i=0;i<n;++i){const r=e.getActiveUniform(t,i);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++;s[n]=function(s){const i=s.bind(t);return i&&e.uniform1i(o,t),i}}else s[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=s[e];if(!t)throw`Missing input "${e}"`;return t}},vt=R.vec4(),Ct=R.vec4();class Mt{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 Et=R.OBB3(),Ft=R.vec4(),xt=R.vec4(),Ut=R.vec4(),It=R.vec3([1,0,0]),Tt=R.vec3([0,1,0]),Pt=R.vec3([0,0,1]),St=R.vec3(3),Dt=R.vec3(3),kt=R.identityMat4(),Qt=new e({}),Rt={};class Ot extends ie{constructor(e,t={}){super(e,t),this.renderOrder=t.renderOrder||0,this.originalSystemId=t.originalSystemId||this.id,this.renderFlags=new Mt,this._state=new xe({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:R.vec3(),origin:null,originHash:null,isUI:t.isUI});const s=t.material?this._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],t.material):this.scene.material,i=this,r=e=>{let t=null;const s=()=>{if(!t){const s=bt(),r=s.programVariables.createAttribute,n=i._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(s.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,i.scene.canvas.canvas.id,i.scene._sectionPlanesState.getHash(),i._geometry._state.hash].concat(h.getHash()).join(";");if(!(u in Rt)){const e=Lt(i,A,{decodedUv:c,worldNormal:a,viewNormal:l},h,s);if(e.errors)return void console.log(e.errors.join("\n"));const t=Qt.addItem({});Rt[u]={drawMesh:e.drawMesh,id:t,useCount:0,delete:()=>{Qt.removeItem(t),e.destroy(),delete Rt[u],L.memory.programs--}},L.memory.programs++}t=Rt[u],t.useCount++}};return{get:s,getId:()=>t.id,put:()=>{t&&(0==--t.useCount&&t.delete(),t=null)},drawMesh:(e,i,r)=>{s(),t&&t.drawMesh(e,i,r)}}},n=i.scene,A=e=>(t,s)=>function(e,t,s,i,r){const n=r&&yt(t,i._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=s.attributes,t=r&&[n.getAmbientColor()].concat(e.normal?n.directionalLights.map((t=>`(max(dot(${e.normal.view}, ${t.getDirection(s.viewMatrix,e.position.view)}), 0.0) * ${t.getColor()})`)):[]);return`vec4(${A}${t?` * (${t.join(" + ")})`:""}, ${o})`})),l=t.createOutput("vec4","outColor");return{getHash:()=>[e,i.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};`)}}(i._state.hash,t,s,n,e);this._renderers={_drawRenderer:r(((e,t)=>"LambertMaterial"===s.type?function(e,t,s,i,r){const n=yt(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=s.attributes,t=[n.getAmbientColor()].concat(e.normal?n.directionalLights.map((t=>`(max(dot(${e.normal.view}, ${t.getDirection(s.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(),i._state.hash],programName:"Lambert",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:(e,t)=>e.push(`${h} = ${t?t(c):c};`)}}(i._state.drawHash,e,t,s,n):function(e,t,s,i,r){const n=i._state,A="PhongMaterial"===n.type,o="MetallicMaterial"===n.type,a="SpecularMaterial"===n.type,l=s.attributes,c=yt(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,s,r)=>{const n=(s,i,n)=>t.createUniform(s,e+"Fresnel"+i,((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(i)&&((e,t)=>`mix(${l+s}, ${c+s}, ${u}(${e}, ${t}, ${A}, ${o}, ${a}))`)},p=d("diffuse","",(e=>e._diffuseFresnel)),f=d("specular","",(e=>e._specularFresnel)),g=d("emissive","",(e=>e._emissiveFresnel)),m=d("alpha",".r",(e=>e._alphaFresnel)),_=(e,s)=>{const r=l.uv&&s(i),n=r&&Bt(t,"sampler2D",e,r.encoding,((e,t)=>e(s(t.material)._state.texture)));return n&&function(){const i=r._state.matrix&&t.createUniform("mat4",e+"MapMatrix",((e,t)=>e(s(t.material)._state.matrix))),A=i?e=>`(${i} * ${e}).st`:e=>`${e}.st`,o=(e,t)=>n(A(e));return o.getTexCoordExpression=A,o}()},b=_("ambient",(e=>e._ambientMap)),y=_("baseColor",(e=>e._baseColorMap)),B=_("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)),x=_("specular",(e=>e._specularMap)),U=_("glossiness",(e=>e._glossinessMap)),I=_("specularGlossiness",(e=>e._specularGlossinessMap)),T=_("normal",(e=>e._normalMap)),P=(e,s,r)=>{const n=r(i);return("float"===s?null!=n:n)&&t.createUniform(s,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?(vt[0]=t,vt[1]=1===e.alphaMode?1:0,vt[2]=e.alphaCutoff,vt):null})),j=t.createVarying("vec3","vViewPosition",(()=>`${l.position.view}.xyz`)),z=t.createVarying("vec4","texturePos",(()=>`vec4(${l.uv}, 1.0, 1.0)`)),W=l.color&&t.createVarying("vec4","vColor",(()=>l.color)),X=t.createVarying("vec3","vViewNormal",(()=>l.normal.view)),K=c.directionalLights.map(((e,i)=>({vViewLightReverseDir:t.createVarying("vec3",`vViewLightReverseDir${i}`,(()=>e.getDirection(s.viewMatrix,null))),vShadowPosFromLight:t.createVarying("vec3",`vShadowPosFromLight${i}`,(()=>`(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(),i._state.hash],programName:"Draw",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:(e,t,i)=>{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(z)}.r;`),W&&(e.push(`diffuseColor *= ${W}.rgb;`),e.push(`alpha *= ${W}.a;`)),o&&y&&(e.push("vec4 baseColorTexel = "+y(z)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(A||a)&&B&&(e.push("vec4 diffuseTexel = "+B(z)+";"),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(z)}.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(z)}.r`:"1.0"};`),o&&M&&e.push(`metallic *= ${M(z)}.r;`),o&&E&&e.push(`roughness *= ${E(z)}.r;`),o&&F&&(e.push("vec4 metalRoughTexel = "+F(z)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(A||a)&&x&&e.push(`specular *= ${x(z)}.rgb;`),a&&U&&e.push(`glossiness *= ${U(z)}.r;`),a&&I&&(e.push("vec4 specGlossTexel = "+I(z)+";"),e.push("specular *= specGlossTexel.rgb;"),e.push("glossiness *= specGlossTexel.a;"));const t=`normalize(${X})`,i=(A||o||a)&&T?`${ee}(${j}, ${t}, ${T.getTexCoordExpression(z)}, ${T(z)})`:t;if(e.push(`vec3 viewNormal = ${i};`),e.push(`vec3 viewEyeDir = normalize(-${j});`),p&&e.push(`diffuseColor *= ${p("viewEyeDir","viewNormal")};`),f&&e.push(`specular *= ${f("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)",i=A?`0.2 * PI * ${c.getReflection(t)}`:function(){const e=`${q}(viewNormal, viewEyeDir, specular, roughness)`,i=`normalize((vec4(${t}, 0.0) * ${s.viewMatrix}).xyz)`;return`${e} * ${c.getReflection(i,"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 += ${i};`)}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,s)=>{if(t.shadowParameters){const i="0.007";e.push(`fragmentDepth = ${K[s].vShadowPosFromLight}.z - ${i};`),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[s].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${s} = ${t.getColor()}${t.shadowParameters?" * shadow":""};`),e.push(`vec3 lightDirection${s} = ${t.isViewSpace?t.getDirection(null,j):K[s].vViewLightReverseDir};`);const i=`${Y}(dot(viewNormal, lightDirection${s}))`;e.push(`vec3 irradiance${s} = ${i} * lightColor${s};`),e.push(`reflDiff += irradiance${s};`);const r=A?`lightColor${s} * specular * pow(max(dot(reflect(-lightDirection${s}, -viewNormal), viewEyeDir), 0.0), shininess)`:`irradiance${s} * PI * ${$}(lightDirection${s}, 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(z)}.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"};`)}}}(i._state.drawHash,e,t,s,n))),_shadowRenderer:r((e=>function(e,t){const s=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("}")})),i=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"Shadow",setsLineWidth:!0,useShadowView:!0,dontGetLogDepth:!0,appendFragmentOutputs:(e,t,r)=>e.push(`${i} = ${s}(${r}.z);`)}}(i._state.hash,e))),_emphasisEdgesRenderer:r(A(!1)),_emphasisFillRenderer:r(A(!0)),_pickMeshRenderer:r((e=>function(e,t){const s=t.createUniform("vec4","pickColor",((e,t)=>{var s=t.meshPickID;Ct[0]=255&s,Ct[1]=s>>8&255,Ct[2]=s>>16&255,Ct[3]=s>>24&255,R.mulVec4Scalar(Ct,1/255,Ct),e(Ct)})),i=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"PickMesh",isPick:!0,appendFragmentOutputs:e=>e.push(`${i} = ${s};`)}}(i._state.hash,e))),_pickTriangleRenderer:r(((e,t)=>function(e,t,s){const i=t.createVarying("vec4","vColor",(()=>s.attributes.pickColor)),r=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"PickTriangle",isPick:!0,trianglePick:!0,appendFragmentOutputs:e=>e.push(`${r} = ${i};`)}}(i._state.hash,e,t))),_occlusionRenderer:r((e=>function(e,t){const s=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"Occlusion",skipIfTransparent:!0,appendFragmentOutputs:e=>e.push(`${s} = vec4(0.0, 0.0, 1.0, 1.0);`)}}(i._state.pickOcclusionHash,e)))},this._geometry=t.geometry?this._checkComponent2(["ReadableGeometry","VBOGeometry"],t.geometry):this.scene.geometry,this._material=s,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=R.vec3(),this._quaternion=R.identityQuaternion(),this._rotation=R.vec3(),this._position=R.vec3(),this._worldMatrix=R.identityMat4(),this._worldNormalMatrix=R.identityMat4(),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0;const o=t.origin||t.rtcCenter;if(o&&(this._state.origin=R.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]),R.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]),R.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=R.identityMat4()),R.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix}set matrix(e){this.__localMatrix||(this.__localMatrix=R.identityMat4()),this.__localMatrix.set(e||kt),R.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=R.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 s=!!e;this.scene._objectColorizeUpdated(this,s),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 s=null!=e;t[3]=s?e:1,this.scene._objectOpacityUpdated(this,s),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,s=[e.canvas.canvas.id,e._sectionPlanesState.getHash()];t.stationary&&s.push("/s"),"none"===t.billboard?s.push("/n"):"spherical"===t.billboard?s.push("/s"):"cylindrical"===t.billboard&&s.push("/c"),s.push(";");const i=s.concat([e.gammaOutput?"go":"",e._lightsState.getHash(),t.receivesShadow?"/rs":""]).join("");this._state.drawHash!==i&&(this._state.drawHash=i,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=s.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)R.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(let t=0,s=e.length;t<s;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_buildWorldNormalMatrix(){this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldNormalMatrix||(this._worldNormalMatrix=R.mat4()),R.transposeMat4(this._worldMatrix,this._worldNormalMatrix),R.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=R.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}_buildAABB(e,t){R.transformOBB3(e,this._geometry.obb,Et),R.OBB3ToAABB3(Et,t);const s=this._state.offset;if(t[0]+=s[0],t[1]+=s[1],t[2]+=s[2],t[3]+=s[0],t[4]+=s[1],t[5]+=s[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 Ft[0]=e[0],Ft[1]=e[1],Ft[2]=e[2],Ft[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(Ft,xt),R.mulQuaternions(this.quaternion,xt,Ut),this.quaternion=Ut,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return Ft[0]=e[0],Ft[1]=e[1],Ft[2]=e[2],Ft[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(Ft,xt),R.mulQuaternions(xt,this.quaternion,xt),this}rotateX(e){return this.rotate(It,e)}rotateY(e){return this.rotate(Tt,e)}rotateZ(e){return this.rotate(Pt,e)}translate(e,t){return R.vec3ApplyQuaternion(this.quaternion,e,St),R.mulVec3Scalar(St,t,Dt),R.addVec3(this.position,Dt,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(It,e)}translateY(e){return this.translate(Tt,e)}translateZ(e){return this.translate(Pt,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 s=0;s<t;s++){const t=e[s],i=this.renderFlags;if(t.active)if(this._state.origin){const e=R.planeAABB3Intersect(t.dir,t.dist,this.aabb);if(-1===e)return!1;const r=0===e;i.sectionPlanesActivePerLayer[s]=r}else i.sectionPlanesActivePerLayer[s]=!0;else i.sectionPlanesActivePerLayer[s]=!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,s,i){Vt(this,e,t,s,i)}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 Vt=function(){const e=R.vec3(),t=R.vec3(),s=R.vec3(),i=R.vec3(),r=R.vec3(),n=R.vec3(),A=R.vec4(),o=R.vec3(),a=R.vec3(),l=R.vec3(),c=R.vec3(),h=R.vec3(),u=R.vec3(),d=R.vec3(),p=R.vec3(),f=R.vec3(),g=R.vec4(),m=R.vec4(),_=R.vec4(),b=R.vec3(),y=R.vec3(),B=R.vec3(),w=R.vec3(),v=R.vec3(),C=R.vec3(),M=R.vec3(),E=R.vec3(),F=R.vec3(),x=R.vec3(),U=R.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,z=L.positions;let W,X,K;if(j){var Q=j[H+0],O=j[H+1],V=j[H+2];n[0]=Q,n[1]=O,n[2]=V,D.indices=n,W=3*Q,X=3*O,K=3*V}else W=3*H,X=W+3,K=X+3;if(s[0]=z[W+0],s[1]=z[W+1],s[2]=z[W+2],i[0]=z[X+0],i[1]=z[X+1],i[2]=z[X+2],r[0]=z[K+0],r[1]=z[K+1],r[2]=z[K+2],L.compressGeometry){const e=L.positionsDecodeMatrix;e&&(Re.decompressPosition(s,e,s),Re.decompressPosition(i,e,i),Re.decompressPosition(r,e,r))}D.canvasPos?R.canvasPosToLocalRay(G.canvas,I.origin?ut(T,I.origin):T,P,S,I.worldMatrix,D.canvasPos,e,t):D.origin&&D.direction&&R.worldRayToLocalRay(I.worldMatrix,D.origin,D.direction,e,t),R.normalizeVec3(t),R.rayPlaneIntersect(e,t,s,i,r,A),D.localPos=A,D.position=A,g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=1,R.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,R.transformVec4(N.matrix,m,_),a[0]=_[0],a[1]=_[1],a[2]=_[2],D.viewPos=a,R.cartesianToBarycentric(A,s,i,r,l),D.bary=l;const Z=L.normals;if(Z){if(L.compressGeometry){const e=3*Q,t=3*O,s=3*V;Re.decompressNormal(Z.subarray(e,e+2),c),Re.decompressNormal(Z.subarray(t,t+2),h),Re.decompressNormal(Z.subarray(s,s+2),u)}else c[0]=Z[W],c[1]=Z[W+1],c[2]=Z[W+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=R.addVec3(R.addVec3(R.mulVec3Scalar(c,l[0],b),R.mulVec3Scalar(h,l[1],y),B),R.mulVec3Scalar(u,l[2],w),v);D.worldNormal=R.normalizeVec3(R.transformVec3(I.worldNormalMatrix,e,C))}const J=L.uv;if(J){if(d[0]=J[2*Q],d[1]=J[2*Q+1],p[0]=J[2*O],p[1]=J[2*O+1],f[0]=J[2*V],f[1]=J[2*V+1],L.compressGeometry){const e=L.uvDecodeMatrix;e&&(Re.decompressUV(d,e,d),Re.decompressUV(p,e,p),Re.decompressUV(f,e,f))}D.uv=R.addVec3(R.addVec3(R.mulVec2Scalar(d,l[0],M),R.mulVec2Scalar(p,l[1],E),F),R.mulVec2Scalar(f,l[2],x),U)}}}}}(),Lt=(e,t,s,i,r)=>{const n=r.programVariables,A=s.decodedUv,o=s.worldNormal,a=s.viewNormal,l=e.scene,c=l.canvas.gl,h=e._state.background,u=e._geometry._state,d=u.compressGeometry,p="points"===u.primitiveName,f=n.createUniform("float","pointSize"),g=n.createUniform("mat4","modelMatrix"),m=n.createUniform("mat4","modelNormalMatrix"),_=n.createUniform("vec3","offset"),b=n.createUniform("vec3","scale"),y=n.createUniform("mat4","positionsDecodeMatrix"),B=n.createUniform("mat3","uvDecodeMatrix"),w=n.createUniform("mat4","viewMatrix"),v=n.createUniform("mat4","viewNormalMatrix"),C=n.createUniform("mat4","projMatrix"),M=e.billboard,E="spherical"===M||"cylindrical"===M,F=e.stationary,x=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)))),U=function(){const e=x&&n.createVertexDefinition("billboard",x);return t=>e?`${e}(${t})`:t}(),I=function(){const e=x&&n.createFragmentDefinition("billboard",x);return t=>e?`${e}(${t})`:t}(),T=[];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,i.programName,{appendFragmentOutputs:(e,t,s,r)=>{T.forEach((t=>e.push(t))),i.appendFragmentOutputs(e,t,s,r)},clippableTest:()=>S,clippingCaps:i.clippingCaps,clipPos:h?"clipPos.xyww":P,crossSections:l.crossSections,discardPoints:p&&i.discardPoints,getGammaFactor:l.gammaOutput&&(()=>l.gammaFactor),getLogDepth:!i.dontGetLogDepth&&l.logarithmicDepthBufferEnabled&&(e=>e),getPointSize:i.setupPointSize&&p&&(()=>f),getVertexData:function(){const e=a&&a.needed&&`vec3 ${a} = normalize((${U(v)} * vec4(${o}, 0.0)).xyz);`,s=[];if(s.push(`vec4 localPosition = vec4(${t.position}, 1.0);`),d&&s.push(`localPosition = ${y} * localPosition;`),s.push(`vec4 worldPosition = ${U(g)} * localPosition;`),s.push(`worldPosition.xyz = worldPosition.xyz + ${_};`),s.push(`mat4 viewMatrix1 = ${w};`),F?s.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):h&&s.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),s.push(`mat4 viewMatrix2 = ${U("viewMatrix1")};`),s.push(`vec4 viewPosition = ${E?`${U(`viewMatrix1 * ${g}`)} * localPosition`:"viewMatrix2 * worldPosition"};`),A&&A.needed&&s.push(`vec2 ${A} = ${d?`(${B} * vec3(${t.uv}, 1.0)).xy`:t.uv};`),o&&o.needed){const e=d?`${n.commonLibrary.octDecode}(${t.normal}.xy)`:t.normal;s.push(`vec3 ${o} = (${U(m)} * vec4(${e}, 0.0)).xyz;`)}return e&&s.push(e),s.push(`vec4 clipPos = ${C} * viewPosition;`),s},projMatrix:C,sectionPlanesState:l._sectionPlanesState,testPerspectiveForGl_FragDepth:!0,usePickClipPos:i.isPick,worldPositionAttribute:"worldPosition"});if(k)return{errors:k};{const e=D.inputSetters;let s=null,r=null;return{destroy:()=>D.destroy(),drawMesh:(n,A,o)=>{if(i.skipIfTransparent&&o.alpha<1)return;const a=o._state,l=A._state,u=A._geometry,d=u._state,p=n.viewParams,M=i.canActAsBackground&&h;n.lastProgramId!==D.id&&(n.lastProgramId=D.id,D.bind(),n.useProgram++,s=null,r=null,M&&c.depthFunc(c.LEQUAL)),a.id!==s&&(n.backfaces!==a.backfaces&&(a.backfaces?c.disable(c.CULL_FACE):c.enable(c.CULL_FACE),n.backfaces=a.backfaces),i.dontSetFrontFace||n.frontface===a.frontface||(c.frontFace(a.frontface?c.CCW:c.CW),n.frontface=a.frontface),i.drawEdges&&n.lineWidth!==a.edgeWidth&&(c.lineWidth(a.edgeWidth),n.lineWidth=a.edgeWidth),i.setsLineWidth&&n.lineWidth!==a.lineWidth&&(c.lineWidth(a.lineWidth),n.lineWidth=a.lineWidth),s=a.id);const E=!i.useShadowView&&A.origin;((t,s)=>{const i=(e,t)=>e.setInputValue&&e.setInputValue(t);i(f,o.pointSize),i(g,A.worldMatrix),i(m,A.worldNormalMatrix),i(_,A.offset),i(b,A.scale),i(y,d.positionsDecodeMatrix),i(B,d.uvDecodeMatrix),i(w,s),i(v,p.viewNormalMatrix),i(C,t),i(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:p.far}})})(p.projMatrix,E?n.getRTCViewMatrix(l.originHash,E):p.viewMatrix);const F=e=>{const s=(e,t)=>{e&&e.setInputValue&&t&&(e.setInputValue(t),n.bindArray++)};s(t.position,(e||d).positionsBuf),s(t.color,d.colorsBuf),s(t.pickColor,e&&e.pickColorsBuf),s(t.uv,d.uvBuf),s(t.normal,d.normalsBuf)};if(i.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(i.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 Ht extends ie{get type(){return"Material"}constructor(e,t={}){super(e,t),L.memory.materials++}destroy(){super.destroy(),L.memory.materials--}}const Nt={opaque:0,mask:1,blend:2},Gt=["opaque","mask","blend"];class jt extends Ht{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new xe({type:"PhongMaterial",ambient:R.vec3([1,1,1]),diffuse:R.vec3([1,1,1]),specular:R.vec3([1,1,1]),emissive:R.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=Nt[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 Gt[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 zt(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];let s;switch(t){case"WEBGL_depth_texture":s=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=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":s=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":s=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=e.getExtension(t)}return e._cachedExtensions[t]=s,s}function Wt(e,t,s=null){let i;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===s){const t=zt(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(i=zt(e,"WEBGL_compressed_texture_s3tc"),null===i)return null;if(33776===r)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===r)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===r)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===r)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===r||35841===r||35842===r||35843===r){const t=zt(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=zt(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){const t=zt(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===r)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===r)return 3001===s?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=zt(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===r){const t=zt(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===r)return 3001===s?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 Xt=new Uint8Array([0,0,0,1]);class Kt{constructor({gl:e,target:t,format:s,type:i,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=s||1023,this.type=i||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?(Xt[0]=Math.floor(255*e[0]),Xt[1]=Math.floor(255*e[1]),Xt[2]=Math.floor(255*e[2]),Xt[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(Xt[0]=0,Xt[1]=0,Xt[2]=0,Xt[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 s=0,i=e.length;s<i;s++)t.texImage2D(e[s],0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,Xt)}else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,Xt);t.bindTexture(this.target,null)}setTarget(e){this.target=e||this.gl.TEXTURE_2D}setImage(e,t={}){const s=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),this.maxAnisotropy=t.maxAnisotropy,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 i=!1;s.bindTexture(this.target,this.texture);const r=s.getParameter(s.UNPACK_FLIP_Y_WEBGL);s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY);const n=s.getParameter(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL);s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);const A=s.getParameter(s.UNPACK_ALIGNMENT);s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment);const o=s.getParameter(s.UNPACK_COLORSPACE_CONVERSION_WEBGL);s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=this.maxAnisotropy&&zt(s,"EXT_texture_filter_anisotropic");if(a){const e=s.getParameter(a.MAX_TEXTURE_MAX_ANISOTROPY_EXT);s.texParameterf(s.TEXTURE_2D,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e,this.maxAnisotropy))}const l=Wt(s,this.minFilter);s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,l),l!==s.NEAREST_MIPMAP_NEAREST&&l!==s.LINEAR_MIPMAP_NEAREST&&l!==s.NEAREST_MIPMAP_LINEAR&&l!==s.LINEAR_MIPMAP_LINEAR||(i=!0);const c=Wt(s,this.magFilter);c&&s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,c);const h=Wt(s,this.wrapS);h&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,h);const u=Wt(s,this.wrapT);u&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,u);const d=Wt(s,this.format,this.encoding),p=Wt(s,this.type),f=Zt(s,this.internalFormat,d,p,this.encoding,!1);if(this.target===s.TEXTURE_CUBE_MAP){if(j.isArray(e)){const t=e,i=[s.TEXTURE_CUBE_MAP_POSITIVE_X,s.TEXTURE_CUBE_MAP_NEGATIVE_X,s.TEXTURE_CUBE_MAP_POSITIVE_Y,s.TEXTURE_CUBE_MAP_NEGATIVE_Y,s.TEXTURE_CUBE_MAP_POSITIVE_Z,s.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let e=0,r=i.length;e<r;e++)s.texImage2D(i[e],0,f,d,p,t[e])}}else s.texImage2D(s.TEXTURE_2D,0,f,d,p,e);i&&s.generateMipmap(this.target),s.bindTexture(this.target,null),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,r),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n),s.pixelStorei(s.UNPACK_ALIGNMENT,A),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,o)}setCompressedData({mipmaps:e,props:t={}}){const s=this.gl,i=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),s.activeTexture(s.TEXTURE0+0),s.bindTexture(this.target,this.texture);let r=e.length>1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const n=Wt(s,this.wrapS);n&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,n);const A=Wt(s,this.wrapT);if(A&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,A),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=Wt(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}r?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Jt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Jt(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Wt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Wt(s,this.magFilter)));const o=Wt(s,this.format,this.encoding),a=Wt(s,this.type),l=Zt(s,this.internalFormat,o,a,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,i,l,e[0].width,e[0].height);for(let t=0,i=e.length;t<i;t++){const i=e[t];1023!==this.format?null!==o?s.compressedTexSubImage2D(s.TEXTURE_2D,t,0,0,i.width,i.height,o,i.data):console.warn("Attempt to load unsupported compressed texture format in .setCompressedData()"):s.texSubImage2D(s.TEXTURE_2D,t,0,0,i.width,i.height,o,a,i.data)}s.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 s=Wt(t,e.minFilter);s&&(this.minFilter=e.minFilter,t.texParameteri(this.target,t.TEXTURE_MIN_FILTER,s),s!==t.NEAREST_MIPMAP_NEAREST&&s!==t.LINEAR_MIPMAP_NEAREST&&s!==t.NEAREST_MIPMAP_LINEAR&&s!==t.LINEAR_MIPMAP_LINEAR||t.generateMipmap(this.target))}if(void 0!==e.magFilter){const s=Wt(t,e.magFilter);s&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,s))}if(void 0!==e.wrapS){const s=Wt(t,e.wrapS);s&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,s))}if(void 0!==e.wrapT){const s=Wt(t,e.wrapT);s&&(this.wrapT=e.wrapT,t.texParameteri(this.target,t.TEXTURE_WRAP_T,s))}}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 Zt(e,t,s,i,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=s;return s===e.RED&&(i===e.FLOAT&&(A=e.R32F),i===e.HALF_FLOAT&&(A=e.R16F),i===e.UNSIGNED_BYTE&&(A=e.R8)),s===e.RG&&(i===e.FLOAT&&(A=e.RG32F),i===e.HALF_FLOAT&&(A=e.RG16F),i===e.UNSIGNED_BYTE&&(A=e.RG8)),s===e.RGBA&&(i===e.FLOAT&&(A=e.RGBA32F),i===e.HALF_FLOAT&&(A=e.RGBA16F),i===e.UNSIGNED_BYTE&&(A=3001===r&&!1===n?e.SRGB8_ALPHA8:e.RGBA8),i===e.UNSIGNED_SHORT_4_4_4_4&&(A=e.RGBA4),i===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||zt(e,"EXT_color_buffer_float"),A}function Jt(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function Yt(e){if(!$t(e.width)||!$t(e.height)){const t=document.createElement("canvas");t.width=qt(e.width),t.height=qt(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function $t(e){return 0==(e&e-1)}function qt(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class es extends ie{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new xe({texture:new Kt({gl:this.scene.canvas.gl}),matrix:R.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),maxAnisotropy:t.maxAnisotropy,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=R.vec2([0,0]),this._scale=R.vec2([1,1]),this._rotate=R.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),L.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,s;0===this._translate[0]&&0===this._translate[1]||(t=R.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=R.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?R.mulMat4(t,s):s),0!==this._rotate&&(s=R.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?R.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=Yt(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 s=new Image;s.onload=function(){s=Yt(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.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(),L.memory.textures--}}const ts=R.vec3(),ss=R.vec3();R.vec3();const is=R.vec3([0,-1,0]),rs=R.vec4([0,0,0,1]);class ns extends Ht{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new xe({type:"LambertMaterial",ambient:R.vec3([1,1,1]),color:R.vec3([1,1,1]),emissive:R.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 As={opaque:0,mask:1,blend:2},os=["opaque","mask","blend"];class as extends Ht{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new xe({type:"MetallicMaterial",baseColor:R.vec4([1,1,1]),emissive:R.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=As[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 os[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 ls={opaque:0,mask:1,blend:2},cs=["opaque","mask","blend"];class hs extends Ht{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new xe({type:"SpecularMaterial",diffuse:R.vec3([1,1,1]),emissive:R.vec3([0,0,0]),specular:R.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=ls[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 cs[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 us={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 ds extends Ht{get type(){return"EmphasisMaterial"}get presets(){return us}constructor(e,t={}){super(e,t),this._state=new xe({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=us[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(us).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 ps={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 fs extends Ht{get type(){return"EdgeMaterial"}get presets(){return ps}constructor(e,t={}){super(e,t),this._state=new xe({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=ps[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(ps).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class gs extends ie{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=R.vec3(t.pos||[0,0,0]),this._up=R.vec3(t.up||[0,1,0]),this._normal=R.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=R.vec3(),this._rtcPos=R.vec3(),this._imageSize=R.vec2(),this._texture=new es(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 ct(this,{matrix:R.inverseMat4(R.lookAtMat4v(this._pos,R.subVec3(this._pos,this._normal,R.mat4()),this._up,R.mat4())),children:[this._bitmapMesh=new Ot(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new Le(this,Ze({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new jt(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 ms=(e,t)=>{const s=[];let i=[];function r(e,s){let i,r;for(let n=0;n<3;n++)if(i=t[3*e+n],r=t[3*s+n],i!==r)return r-i;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]),s[n[e]]=A;for(let t=0,r=e.length;t<r;t+=3){const r=s[e[t]],n=s[e[t+1]],A=s[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)),i[t+0]=[o,a],i[t+1]=[a,l],o>l){const e=l;l=o,o=e}i[t+2]=[l,o]}function o(e,t){let s,i;for(let r=0;r<2;r++)if(s=e[r],i=t[r],i!==s)return i-s;return 0}i=i.slice(0,e.length),i.sort(o);let a=0;for(let e=0;e<i.length;e++)if(0===e||0!==o(i[e],i[e-1])){if(0!==e&&2!==a)return!1;a=1}else a++;return!(i.length>0&&2!==a)},_s=R.vec3(),bs=R.vec3(),ys=R.vec3();class Bs{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&&!ms(t,e))return-1;let s=0;for(let i=0;i<this.lenIndices;i+=3){const r=3*t[i],n=3*t[i+1],A=3*t[i+2];_s[0]=e[r],_s[1]=e[r+1],_s[2]=e[r+2],bs[0]=e[n],bs[1]=e[n+1],bs[2]=e[n+2],ys[0]=e[A],ys[1]=e[A+1],ys[2]=e[A+2],R.cross3Vec3(_s,bs,_s),s+=R.dotVec3(_s,ys)}return s/6}}const ws=new Bs,vs=R.vec3(),Cs=R.vec3(),Ms=R.vec3(),Es=R.vec3(),Fs=R.vec3(),xs=R.vec3();class Us{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 s=0;for(let i=0;i<this.lenIndices;i+=3){const r=3*t[i],n=3*t[i+1],A=3*t[i+2];vs[0]=e[r],vs[1]=e[r+1],vs[2]=e[r+2],Cs[0]=e[n],Cs[1]=e[n+1],Cs[2]=e[n+2],Ms[0]=e[A],Ms[1]=e[A+1],Ms[2]=e[A+2],R.subVec3(vs,Cs,Es),R.subVec3(Ms,Cs,Fs),s+=.5*R.lenVec3(R.cross3Vec3(Es,Fs,xs))}return s}}const Is=new Us,Ts=R.OBB3(),Ps=R.OBB3(),Ss=R.OBB3();class Ds{constructor(e,t,s,i,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=R.AABB3(),this._aabbWorldDirty=!1,this.layer=A,this.portionId=o,this._color=new Uint8Array([s[0],s[1],s[2],i]),this._colorize=new Uint8Array([s[0],s[1],s[2],i]),this._colorizing=!1,this._transparent=i<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 s=e<255,i=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),i&&this.layer.setTransparent(this.portionId,t,s)}_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,s,i){return this.layer.precisionRayPickSurface(this.portionId,e,t,s,i)}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":ws.reset(),ws.setPrimitive(this.layer.primitive),this.getEachVertex((e=>{ws.addVertex(e)})),this.getEachIndex((e=>{ws.addIndex(e)})),this._volume=ws.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":Is.reset(),this.getEachVertex((e=>{Is.addVertex(e)})),this.getEachIndex((e=>{Is.addIndex(e)})),this._surfaceArea=Is.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&&(R.AABB3ToOBB3(this._aabbLocal,Ts),this.transform?(R.transformOBB3(this.transform.worldMatrix,Ts,Ps),R.transformOBB3(this.model.worldMatrix,Ps,Ss),R.OBB3ToAABB3(Ss,this._aabbWorld)):(R.transformOBB3(this.model.worldMatrix,Ts,Ps),R.OBB3ToAABB3(Ps,this._aabbWorld)),this._aabbWorldDirty=!1),this._aabbWorld}_destroy(){this.model.scene._renderer.putPickID(this.pickId),this.layer=null}}const ks=1,Qs=4,Rs=8,Os=16,Vs=32,Ls=256,Hs=512,Ns=1024,Gs=2048,js=function(e,t,s,i){const r=i&&e.createUniform("vec4","edgeColor",((e,t)=>e(t.legacyFrameCtx.programColor))),n=t.attributes.color,A=!i&&e.createVarying("vec4","vColor",(()=>`vec4(${n}.rgb * 0.5, ${n}.a)`)),o=e.createOutput("vec4","outColor");return{programName:i?"Edges":"EdgesColor",getLogDepth:s&&(e=>e),renderPassFlag:2,appendFragmentOutputs:e=>e.push(`${o} = ${r||A};`)}},zs=function(e,t){const s=e.createOutput("vec4","outColor");return{programName:"Occlusion",getLogDepth:!1,renderPassFlag:0,appendFragmentOutputs:e=>e.push(`${s} = vec4(0.0, 0.0, 1.0, 1.0);`)}},Ws=function(e,t,s,i){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:s&&(e=>e),renderPassFlag:1,appendFragmentOutputs:(e,t,s,o)=>{e.push(`${A} = ${i?r:o(`vec4(${r}.rgb, min(${r}.a, ${n}))`)};`)}}},Xs=R.vec2(),Ks=R.vec3(),Zs=R.vec4(),Js=R.mat4(),Ys=R.vec3([0,0,0]),$s=0,qs=1,ei=2,ti=3,si=4,ii=5,ri=6,ni=7,Ai=8,oi=9,ai=10,li=11,ci=e=>[R.safeInv(e[0]),R.safeInv(e[1]),R.safeInv(e[2])],hi=(e,t,s,i,r)=>{const n=!!(e&ks),A=!!(e&Ls),o=!!(e&Hs),a=!!(e&Ns),l=!!(e&Gs),c=!!(e&Rs),h=!!(e&Qs);let u,d;u=!n||h||A||o&&!i.highlightMaterial.glowThrough||a&&!i.selectedMaterial.glowThrough?$s:t?ei:qs,d=!n||h?$s:a?si:o?ti:A?ii:$s;let p=0;p=s&&n&&!h?a?oi:o?Ai:A?ai:l?t?ni:ri:$s:$s;const f=n&&!h&&c?li:$s;r[0]=u,r[1]=d,r[2]=p,r[3]=f},ui=function(){const e={};return function(t,s,i,r,n,A,o,a){const l=[s,"points"===i||"lines"===i?i:"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=bt(),o=A.programVariables,l=a(o,n);return r(o,l.geometryParameters,(function(r,a){const c=t.pointsMaterial,h="points"===i&&!n,u=()=>[t._sectionPlanesState.getHash()].concat(h?[c.hash]:[]).concat(r.getHash?r.getHash():[]).join(";"),d=u(),p=()=>d===u(),f=l.geometryParameters,g=r.incrementDrawState,m=r.isShadowProgram,_=f.attributes,b=_.position.world,y="clipPos",[B,w]=A.buildProgram(e,s+" "+i+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:y,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 s=o.createUniform("float","nearPlaneHeight",((e,t)=>e(t.legacyFrameCtx.nearPlaneHeight))),i=`${Math.floor(c.minPerspectivePointSize)}.0`,r=`${Math.floor(c.maxPerspectivePointSize)}.0`;e.push(`clamp((${s} * ${t}) / gl_Position.w, ${i}, ${r})`)}else e.push(t)}else n&&n.vertices&&e.push("1.0");return r.incPointSizeBy10&&"points"===i&&e.push("10.0"),e.length>0&&(()=>e.join(" + "))}(),getVertexData:()=>{const e=_.color,t=_.flags[r.renderPassFlag],s=o.createUniform("int","renderPass",((e,t)=>e(t.renderPass))),n=[`if (${m?`(${t} <= 0) || (${e}.a < 1.0)`:`${t} != ${s}`}) {`,` 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"===i&&c.filterIntensity?function(){const t=o.createUniform("vec2","intensityRange",(e=>{Xs[0]=c.minIntensity,Xs[1]=c.maxIntensity,e(Xs)}));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=f.attributes.position.view;return A.push(`vec4 ${a} = ${f.viewMatrix} * ${b};`),A.push(`vec4 clipPos = ${f.projMatrix} * ${a};`),A},projMatrix:f.projMatrix,sectionPlanesState:t._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==i&&"lines"!==i||n,usePickClipPos:a,worldPositionAttribute:b});return w?(console.error(w),{getValid:p,destroy:()=>{},drawLayer:(e,t,s)=>{}}):{getValid:p,destroy:()=>B.destroy(),drawLayer:(e,t,s)=>{e.lastProgramId!==B.id&&(e.lastProgramId=B.id,B.bind());const i=t.origin,r=t.model,A=e.viewParams,o=Ks;R.transformPoint3(r.matrix,i,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:s,view:{eye:A.eye,far:A.far,projMatrix:c,viewMatrix:R.compareVec3(o,Ys)?a:ut(a,o,Js),viewNormalMatrix:A.viewNormalMatrix}};B.inputSetters.setUniforms(e,h),t.drawCalls[n?n.vertices?"drawVertices":"drawEdges":"drawSurface"](B.inputSetters.attributesHash,l.layerTypeInputs,{projMatrix:c,viewMatrix:R.compareVec3(o,Ys)?a:ut(a,o,Js),viewNormalMatrix:A.viewNormalMatrix,eye:A.eye}),g&&e.drawElements++}}}))};let l=A&&o();return{drawLayer:(e,t,s)=>{l||(l=o()),l.drawLayer(e,t,s)},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),p=(e,s,r,n)=>function(e,t,s,i,r,n){const A=e.createVarying("vec4","vColor",(()=>{const e=t.attributes,s="points"===n?`vec4(${e.color}.rgb, 1.0)`:`${e.color}`;return i?`vec4(${[i.getAmbientColor()].concat(i.directionalLights.map((s=>`max(dot(${e.normal.view}, ${s.getDirection(t.viewMatrix,e.position.view)}), 0.0) * ${s.getColor()}`))).join(" + ")}, 1) * ${s}`:s})),o=e.createOutput("vec4","outColor");return{programName:"Color",getHash:()=>[i?i.getHash():"-",r?"sao":"nosao"],cleanerEdges:!0,getLogDepth:s&&(e=>"points"!==n&&"lines"!==n?`${e} + length(vec2(dFdx(${e}), dFdy(${e})))`:e),renderPassFlag:0,appendFragmentOutputs:(e,t,s,i)=>{"points"===n||"lines"===n?e.push(`${o} = ${A};`):(e.push(`vec4 fragColor = ${i(A)};`),e.push(`${o} = ${r?`vec4(fragColor.rgb * ${r.getAmbient(s)}, fragColor.a)`:"fragColor"};`))},filterIntensityRange:!0,incrementDrawState:!0}}(e,s,t.logarithmicDepthBufferEnabled,r,n,i),f=(e,s,i)=>i(function(e,t,s){const i=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:s&&(e=>e),renderPassFlag:3,incPointSizeBy10:!0,appendFragmentOutputs:e=>{e.push(`float zNormalizedDepth = abs((${r} + ${n}.z) / (${i} - ${r}));`),e.push(`${A} = ${o}(zNormalizedDepth);`)}}}(e,s,t.logarithmicDepthBufferEnabled),!0),g=(e,s,i)=>i(function(e,t,s){const i=e.createVarying("vec4","vPickColor",(()=>`${t.attributes.pickColor} / 255.0`)),r=e.createOutput("vec4","outPickColor");return{programName:"PickMesh",getLogDepth:s&&(e=>e),renderPassFlag:3,incPointSizeBy10:!0,dontCullOnAlphaZero:!0,appendFragmentOutputs:e=>e.push(`${r} = ${i};`)}}(e,s,t.logarithmicDepthBufferEnabled),!0),m=(e,s,i,r)=>i(function(e,t,s,i){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:i?"PickNormalsFlat":"PickNormals",getLogDepth:s&&(e=>e),renderPassFlag:3,appendFragmentOutputs:e=>{const t=i?`normalize(cross(dFdx(${r}), dFdy(${r})))`:n;e.push(`${A} = ivec4(${t} * float(${R.MAX_INT}), 1.0);`)}}}(e,s,t.logarithmicDepthBufferEnabled,r),!0),_=(e,t,s,i,r)=>s(function(e,t,s,i){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:s?"SnapInit":"Snap",getLogDepth:e=>s?`${e} + length(vec2(dFdx(${e}), dFdy(${e})))`:e,renderPassFlag:3,vertexCullX:!s&&"2.0",dontCullOnAlphaZero:!s,appendFragmentOutputs:e=>{e.push(`${a} = ivec4(${A} * ${n}.xyz, ${s?"-":""}${r});`),s&&(e.push(`${l} = ${i?"ivec4(1.0)":`ivec4(normalize(cross(dFdx(${A}), dFdy(${A}))) * float(${R.MAX_INT}), 1.0)`};`),e.push(`${c} = uvec4(${o});`))}}}(e,t,i,r),!0);c[h]="points"===i?{colorRenderers:{"sao-":{vertex:d(((e,t,s)=>s(p(e,t,null,null))))}},occlusionRenderer:d(((e,s,i)=>i(zs(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:d(f),pickMeshRenderer:d(g),silhouetteRenderer:d(((e,s,i)=>i(Ws(e,s,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:d(((e,t,s)=>_(e,t,s,!0,!0))),snapVertexRenderer:d(((e,t,s)=>_(e,t,s,!1,!0)),{vertices:!0})}:"lines"===i?{colorRenderers:{"sao-":{vertex:d(((e,t,s)=>s(p(e,t,null,null))))}},silhouetteRenderer:d(((e,s,i)=>i(Ws(e,s,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:d(((e,t,s)=>_(e,t,s,!0,!1))),snapEdgeRenderer:d(((e,t,s)=>_(e,t,s,!1,!1)),{vertices:!1}),snapVertexRenderer:d(((e,t,s)=>_(e,t,s,!1,!1)),{vertices:!0})}:{colorRenderers:function(){const e=e=>yt(e,t._lightsState),s=e=>{const t=e.createUniform("vec4","uSAOParams",((e,t)=>e(t.legacyFrameCtx.saoParams))),s=Bt(e,"sampler2D","uOcclusionTexture",3e3,((e,t)=>e(t.legacyFrameCtx.occlusionTexture)));return{getAmbient:e=>{const i=`${t}.w`;return`(smoothstep(${`${t}.z`}, 1.0, dot(${s(`${e}.xy / ${t}.xy`)}, (255. / 256.) / vec4(256. * 256. * 256., 256. * 256., 256., 1.))) * ${i})`}}},i=function(i){const r=(r,n,A)=>function(e,t,s,i,r,n,A){const o=Bt(e,"sampler2D","uColorMap",3001,((e,t)=>{const s=t.layerTextureSet.colorTexture;s&&e(s.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:()=>[i.getHash(),r?"sao":"nosao",!!A,n?"alphaCutoffYes":"alphaCutoffNo"],getLogDepth:s.logarithmicDepthBufferEnabled&&(e=>e),renderPassFlag:0,appendFragmentOutputs:(e,s,n,A)=>{e.push(`vec3 viewNormal = normalize(cross(dFdx(${c}), dFdy(${c})));`),e.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.directionalLights.forEach((s=>{e.push(`reflectedColor += max(dot(viewNormal, ${s.getDirection(t.viewMatrix,c)}), 0.0) * ${s.getColor()};`)})),e.push(`vec4 color = vec4(${i.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);`),s&&e.push(`${d} = ${s(d)};`)},incrementDrawState:!0}}(r,n,t,e(r),i&&s(r),A,t.gammaOutput);return{PBR:n&&d(((r,n,A)=>A(function(e,t,s,i,r){const n=(t,s,i)=>Bt(e,"sampler2D",t,s?3001:3e3,((e,t)=>{const s=i(t.layerTextureSet);s&&e(s.texture)})),A=t.attributes,o=i.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`)),p=e.createVarying("vec3","vViewNormal",(()=>A.normal.view)),f=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"),y=e.createFragmentDefinition("saturate",((e,t)=>t.push(`float ${e}(const in float a) { return clamp(a, 0.0, 1.0); }`))),B=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 = ${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("}")})),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 = ${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("}")})),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:()=>[i.getHash(),r?"sao":"nosao",!!s.gammaOutput],getLogDepth:s.logarithmicDepthBufferEnabled&&(e=>e),renderPassFlag:0,clippingCaps:s._sectionPlanesState.clippingCaps&&b,incrementDrawState:!0,appendFragmentOutputs:(e,s,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 = ${f}.rgb;`),e.push(`float opacity = ${f}.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(${p}), ${g}, ${h(g)});`),e.push(`vec3 viewEyeDir = normalize(${d});`),o&&e.push(`reflDiff += ${o(`normalize(${_})`)};`),i.getReflection){const s=`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=i.getReflection(s,n),o=`${w}(viewNormal, viewEyeDir, specularColor, specularRoughness)`;e.push(`reflSpec += ${A} * ${o};`)}i.directionalLights.forEach(((s,i)=>{e.push(`vec3 lightDirection${i} = -${s.getDirection(t.viewMatrix,d)};`);const r=`${y}(dot(viewNormal, lightDirection${i}))`;e.push(`vec3 irradiance${i} = ${r} * ${s.getColor()};`),e.push(`reflDiff += irradiance${i};`),e.push(`reflSpec += irradiance${i} * PI * ${B}(lightDirection${i}, viewNormal, viewEyeDir, specularColor, specularRoughness);`)})),e.push(`vec3 emissiveColor = ${c(g)}.rgb;`),e.push(`float aoFactor = ${u(g)}.r;`);const A=`${i.getAmbientColor()} * baseColor * opacity * rgb`;e.push(`vec3 outgoingLight = emissiveColor + reflDiff * diffuseColor + reflSpec + ${A};`),e.push(`${b} = vec4(outgoingLight * aoFactor${r?` * ${r.getAmbient(n)}`:""}, opacity);`),s&&e.push(`${b} = ${s(b)};`)}}}(r,n,t,e(r),i&&s(r))))),texture:A&&{"alphaCutoff-":d(((e,t,s)=>s(r(e,t,!1)))),"alphaCutoff+":d(((e,t,s)=>s(r(e,t,!0))))},vertex:d(o?(t,r,n)=>n(p(t,r,e(t),i&&s(t))):(r,n,A)=>A(function(e,t,s,i,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:()=>[i.getHash(),r?"sao":"nosao"],cleanerEdges:!0,getLogDepth:s&&(e=>e),renderPassFlag:0,appendFragmentOutputs:(e,s,n,l)=>{e.push(`vec3 viewNormal = normalize(cross(dFdx(${A}), dFdy(${A})));`);const c=[i.getAmbientColor()].concat(i.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),i&&s(r))))}};return{"sao-":i(!1),"sao+":r&&i(!0)}}(),depthRenderer:d(((e,s,i)=>i(function(e,t,s){const i=e.createVarying("highp vec2","vHighPrecisionZW",(()=>`${t.attributes.position.clip}.zw`)),r=e.createOutput("vec4","outColor");return{programName:"Depth",getLogDepth:s&&(e=>e),renderPassFlag:0,appendFragmentOutputs:e=>e.push(`${r} = vec4(vec3((1.0 - ${i}[0] / ${i}[1]) / 2.0), 1.0);`)}}(e,s,t.logarithmicDepthBufferEnabled)))),edgesRenderers:{uniform:d(((e,s,i)=>i(js(e,s,t.logarithmicDepthBufferEnabled,!0))),{vertices:!1}),vertex:d(((e,s,i)=>i(js(e,s,t.logarithmicDepthBufferEnabled,!1))),{vertices:!1})},occlusionRenderer:d(((e,s,i)=>i(zs(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:u(f),pickMeshRenderer:u(g),pickNormalsFlatRenderer:u(((e,t,s)=>m(e,t,s,!0))),pickNormalsRenderer:u(((e,t,s)=>m(e,t,s,!1))),shadowRenderer:d(((e,s,i)=>i(function(e,t){const s=e.createOutput("vec4","outColor"),i=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(`${s} = ${i}(${r}.z);`)}}(e,t)))),silhouetteRenderer:u(((e,s,i)=>i(Ws(e,s,t.logarithmicDepthBufferEnabled,!1)))),snapInitRenderer:u(((e,t,s)=>_(e,t,s,!0,!1))),snapEdgeRenderer:u(((e,t,s)=>_(e,t,s,!1,!1)),{vertices:!1}),snapVertexRenderer:u(((e,t,s)=>_(e,t,s,!1,!1)),{vertices:!0})};const b=e=>{!function t(s){s.revalidate?s.revalidate(e):Object.values(s).forEach((e=>e&&t(e)))}(c[h])},y=()=>b(!1);y(),t.on("compile",y),t.on("destroyed",(()=>{delete c[h]}))}return c[h]}}();class di{constructor(e,t,s){this.model=e,this.primitive=t,this.origin=s,this._meshes=[],this._aabb=R.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 s={count:0,fromFlags:(i,r)=>{i&e?(s.count++,this.model[t]++):r||(s.count--,this.model[t]--)}};this._countsByFlag[e]=s};e(ks,"numVisibleLayerPortions"),e(Qs,"numCulledLayerPortions"),e(Rs,"numPickableLayerPortions"),e(Os,"numClippableLayerPortions"),e(Ls,"numXRayedLayerPortions"),e(Hs,"numHighlightedLayerPortions"),e(Ns,"numSelectedLayerPortions"),this._renderers.edgesRenderers&&e(Gs,"numEdgesLayerPortions"),this._countsByFlagArr=Object.values(this._countsByFlag),this._numTransparentLayerPortions=0}}aabbChanged(){this._aabbDirty=!0}getAABB(){return this._aabbDirty&&(R.collapseAABB3(this._aabb),this._meshes.forEach((e=>R.expandAABB3(this._aabb,e.aabb))),this._aabbDirty=!1),this._aabb}__drawLayer(e,t,s,i){if(this._countsByFlag[Qs].count<this._portions.length&&this._countsByFlag[ks].count>0){const e="points"!==this.primitive&&"lines"!==this.primitive&&[qs,ei,li,ti,si,ii];if(e&&e.includes(i)){const e=!0;if(t.backfaces!==e){const s=this.model.scene.canvas.gl;s.disable(s.CULL_FACE),t.backfaces=e}}t.textureUnit=0,s.drawLayer(t,this,i)}}__setVec4FromMaterialColorAlpha(e,t,s){return s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=t,s}__drawColor(e,t,s){if((s?this._numTransparentLayerPortions<this._portions.length:this._numTransparentLayerPortions>0)&&this._countsByFlag[Ls].count<this._portions.length){const i=s&&t.withSAO&&this._renderers.colorRenderers["sao+"]||this._renderers.colorRenderers["sao-"],r=t.pbrEnabled&&i.PBR?i.PBR:t.colorTextureEnabled&&i.texture?i.texture[this.layerTextureSet&&"number"==typeof this.layerTextureSet.alphaCutoff?"alphaCutoff+":"alphaCutoff-"]:i.vertex,n=s?qs:ei;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 s=this._renderers.depthRenderer;s&&this._numTransparentLayerPortions<this._portions.length&&this._countsByFlag[Ls].count<this._portions.length&&this.__drawLayer(e,t,s,qs)}__drawSilhouette(e,t,s,i){t.programColor=this.__setVec4FromMaterialColorAlpha(s.fillColor,s.fillAlpha,Zs),this.__drawLayer(e,t,this._renderers.silhouetteRenderer,i)}drawSilhouetteXRayed(e,t){this._countsByFlag[Ls].count>0&&this.__drawSilhouette(e,t,this.model.scene.xrayMaterial,ii)}drawSilhouetteHighlighted(e,t){this._countsByFlag[Hs].count>0&&this.__drawSilhouette(e,t,this.model.scene.highlightMaterial,ti)}drawSilhouetteSelected(e,t){this._countsByFlag[Ns].count>0&&this.__drawSilhouette(e,t,this.model.scene.selectedMaterial,si)}__drawVertexEdges(e,t,s){const i=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.vertex;i&&this._countsByFlag[Gs].count>0&&this.__drawLayer(e,t,i,s)}drawEdgesColorOpaque(e,t){this.__drawVertexEdges(e,t,ri)}drawEdgesColorTransparent(e,t){this._numTransparentLayerPortions>0&&this.__drawVertexEdges(e,t,ni)}__drawUniformEdges(e,t,s,i){const r=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.uniform;r&&(t.programColor=this.__setVec4FromMaterialColorAlpha(s.edgeColor,s.edgeAlpha,Zs),this.__drawLayer(e,t,r,i))}drawEdgesHighlighted(e,t){this._countsByFlag[Hs].count>0&&this.__drawUniformEdges(e,t,this.model.scene.highlightMaterial,Ai)}drawEdgesSelected(e,t){this._countsByFlag[Ns].count>0&&this.__drawUniformEdges(e,t,this.model.scene.selectedMaterial,oi)}drawEdgesXRayed(e,t){this._countsByFlag[Ls].count>0&&this.__drawUniformEdges(e,t,this.model.scene.xrayMaterial,ai)}__drawPick(e,t,s){s&&this.__drawLayer(e,t,s,li)}drawPickMesh(e,t){this.__drawPick(e,t,this._renderers.pickMeshRenderer)}drawPickDepths(e,t){this.__drawPick(e,t,this._renderers.pickDepthRenderer)}drawPickNormals(e,t){const s=this._renderers.pickNormalsFlatRenderer;this.__drawPick(e,t,s)}drawSnap(e,t,s){t.snapPickOrigin=[0,0,0];const i=this.getAABB();t.snapPickCoordinateScale=R.mulVec3Scalar(ci([i[3]-i[0],i[4]-i[1],i[5]-i[2]]),R.MAX_INT);const r=s?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:ci(t.snapPickCoordinateScale)})}drawOcclusion(e,t){const s=this._renderers.occlusionRenderer;s&&this.__drawLayer(e,t,s,qs)}drawShadow(e,t){const s=this._renderers.shadowRenderer;s&&this.__drawLayer(e,t,s,qs)}initFlags(e,t,s){this._countsByFlagArr.forEach((e=>e.fromFlags(t,!0))),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);const i="points"!==this.primitive;this._setFlags(e,t,s,i),this._compiledPortions.setFlags2(e,t,i)}flushInitFlags(){this._compiledPortions.setDeferredFlags()}setVisible(e,t,s){this._countsByFlag[ks].fromFlags(t),this._setFlags(e,t,s)}setCulled(e,t,s){this._countsByFlag[Qs].fromFlags(t),this._setFlags(e,t,s)}setPickable(e,t,s){this._countsByFlag[Rs].fromFlags(t),this._setFlags(e,t,s)}setClippable(e,t){this._countsByFlag[Os].fromFlags(t),this._compiledPortions.setClippableFlags(e,t)}setCollidable(e,t){}setXRayed(e,t,s){this._countsByFlag[Ls].fromFlags(t),this._setFlags(e,t,s)}setHighlighted(e,t,s){this._countsByFlag[Hs].fromFlags(t),this._setFlags(e,t,s)}setSelected(e,t,s){this._countsByFlag[Ns].fromFlags(t),this._setFlags(e,t,s)}setEdges(e,t,s){this._countsByFlag[Gs]&&(this._countsByFlag[Gs].fromFlags(t),this._setFlags(e,t,s))}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}destroy(){this._compiledPortions&&this._compiledPortions.destroy()}}let pi=65536,fi=5e6;class gi{constructor(){}set doublePrecisionEnabled(e){R.setDoublePrecisionEnabled(e)}get doublePrecisionEnabled(){return R.getDoublePrecisionEnabled()}set maxDataTextureHeight(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),pi=e}get maxDataTextureHeight(){return pi}set maxGeometryBatchSize(e){e<1e5?e=1e5:e>5e6&&(e=5e6),fi=e}get maxGeometryBatchSize(){return fi}}const mi=e=>{const t=[];for(let s=0;s<e;++s)t.push(s);return t},_i={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(_i,null,4));let e=0;Object.keys(_i).forEach((t=>{t.startsWith("size")&&(e+=_i[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/_i.totalPolygons).toFixed(2)}`);let t={};Object.keys(_i).forEach((s=>{s.startsWith("size")&&(t[s]=`${(_i[s]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};const bi=new gi,yi=bi.maxDataTextureHeight,Bi=R.vec3(),wi=R.vec3(),vi=R.vec4();R.vec4();const Ci=new Float32Array(16),Mi=new Uint8Array(4),Ei=R.identityMat4();class Fi extends di{constructor(e,t,s){super(e,t,s),_i.numberOfLayers++,this._sortId=`TriDTX-${_i.numberOfLayers}`;const i=e.scene.canvas.gl,r=(e,t)=>{const s=[];let r=0;const A=[];let o=0;const a=[];let l=0;const c=[];let h=0;return{len:()=>o,accumulateIndices:(i,u)=>{const d=i&&i.length>0&&function(){const t=r/3;r+=i.length,s.push(i);const a=i.length/3;return s=>{const i=o;o+=3*a,n.perObjectIndexBaseOffsets.push(i/3-t);for(let e=0;e<a;e+=8)A.push(s);_i[e]+=a,_i.totalPolygons+=a}}(),p=u&&function(){const e=l/2;l+=u.length,a.push(u);const s=u.length/2;return i=>{const r=h;h+=2*s,n.perObjectEdgeIndexBaseOffsets.push(r/2-e);for(let e=0;e<s;e+=8)c.push(i);_i[t]+=s,_i.totalEdges+=s}}();return _i.numberOfGeometries++,{numTriangles:i?i.length/3:0,accumulateSubPortionId:e=>{d&&d(e),p&&p(e)}}},createDrawers:(e,t)=>{const n=function(t,s){return t.length>0?e([t],t.length,1,i.UNSIGNED_SHORT,"sizeDataTexturePortionIds"):s},u=n(A,{texture:null}),d=r>0&&e(s,r,3,t,"sizeDataTextureIndices"),p=n(c),f=l>0&&e(a,l,2,t,"sizeDataTextureEdgeIndices");return{indices:function(e,t){o>0&&(e.perPrimIndices.setInputValue(d),e.perPrimIdPorIds.setInputValue(u),i.drawArrays(t,0,o))},edges:function(e,t){h>0&&(e.perPrimIndices.setInputValue(f),e.perPrimIdPorIds.setInputValue(p),i.drawArrays(t,0,h))}}},_clearToOptimizeGC:()=>{s.length=a.length=0}}},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&&_i.cannotCreatePortion.because10BitsObjectId++;let s=this._portions.length+t<=65536;const i=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#0`:`${e.id}#0`;if(!this._bucketGeometries[i]){const t=this._buffer,i=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*yi||i+n>4096*yi)&&_i.cannotCreatePortion.becauseTextureSize++,s&&=this._numVertices+r<=4096*yi&&i+n<=4096*yi}return s}createPortion(e,t){const s=this._buffer,i=t.buckets.map(((e,i)=>{const r=(t.geometryId??t.id)+"#"+i;if(!(r in this._bucketGeometries)){const t=(e,t,s)=>{if(e){const i=8*Math.ceil(e.length/t/8)*t,r=new Uint32Array(i);return r.set(e),_i[s]+=2*(r.length-e.length),r}return e};e.indices=t(e.indices,3,"overheadSizeAlignementIndices"),e.edgeIndices=t(e.edgeIndices,2,"overheadSizeAlignementEdgeIndices");const i=e.positionsCompressed;s.positionsCompressed.push(i);const n=i.length/3;this._numVertices+=n;const A=s.lenPositionsCompressed/3;s.lenPositionsCompressed+=i.length,this._bucketGeometries[r]={vertexBase:A,geometryData:function(){const t=e.indices,i=e.edgeIndices;return n<=256?s.geometry8Bits.accumulateIndices(t,i):n<=65536?s.geometry16Bits.accumulateIndices(t,i):s.geometry32Bits.accumulateIndices(t,i)}()}}const n=this._bucketGeometries[r];s.perObjectPositionsDecodeMatrices.push(t.positionsDecodeMatrix),s.perObjectInstancePositioningMatrices.push(t.meshMatrix||Ei),s.perObjectSolid.push(!!t.solid),s.perObjectPickColors.push(t.pickColor),s.perObjectVertexBases.push(n.vertexBase);const A=t.colors,o=t.color;s.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}),_i.numberOfPortions++,a})),r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(i),this.model.numPortions++,this._meshes.push(e),r}compilePortions(){const e=this._buffer,t=this.model,s=this._portions.length,i=this.origin,r=this._portionToSubPortionsMap,n=this._primitive,A=this._sortId,o=this._subPortionReadableGeometries,a=t.scene,l=a.canvas.gl,c=xi(l,s,32,l.UNSIGNED_BYTE,512,(t=>{const i=e=>[e>>24&255,e>>16&255,e>>8&255,255&e];for(let r=0;r<s;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(i(e.perObjectVertexBases[r]),32*r+16),t.set(i(e.perObjectIndexBaseOffsets[r]),32*r+20),t.set(i(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,s,i,r,n,A){return xi(l,t,s,i,r,(t=>{for(let s=0,i=0,r=e.length;s<r;s++){const r=e[s];t.set(r,i),i+=r.length}}),n,A)},d=function(e,t,s){const i=e.length;if(0===i)throw"num "+t+" matrices===0";return u(e,i,16,l.FLOAT,512,t,s)},p=d(e.perObjectInstancePositioningMatrices,"sizeDataInstancesMatrices",!0),f=p.textureData,g=d(e.perObjectPositionsDecodeMatrices,"sizeDataPositionDecodeMatrices",!1),m=function(e,t,s,i,r){return u(e,t/s,s,i,4096,r,!1)},_=m(e.positionsCompressed,e.lenPositionsCompressed,3,l.UNSIGNED_SHORT,"sizeDataTexturePositions"),b=e.geometry8Bits.createDrawers(m,l.UNSIGNED_BYTE),y=e.geometry16Bits.createDrawers(m,l.UNSIGNED_SHORT),B=e.geometry32Bits.createDrawers(m,l.UNSIGNED_INT);this._bucketGeometries=null,this._buffer.geometry8Bits._clearToOptimizeGC(),this._buffer.geometry16Bits._clearToOptimizeGC(),this._buffer.geometry32Bits._clearToOptimizeGC(),Object.keys(this._buffer).forEach((e=>this._buffer[e]=null)),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})),x=(e,s)=>{const i=r[e];if(i)for(let e=0,t=i.length;e<t;e++)s(i[e]);else t.error("portion not found: "+e)},U=(e,t,s,i)=>{const r=w||i;r?v=!0:++M>=10&&E(),h.setData(s,e,t,!r)},I=(e,t,s=!1)=>{Mi.set([t&Os?255:0,0,1,2]),x(e,(e=>U(e,3,Mi,s)))};return{sortId:A,setClippableFlags:I,setFlags:(e,t,s,i=!1)=>{hi(t,s,!0,a,Mi),x(e,(e=>U(e,2,Mi,i)))},setFlags2:I,setDeferredFlags:()=>{},setColor:(e,t)=>{Mi.set(t),x(e,(e=>U(e,0,Mi,!1)))},setMatrix:(e,t)=>{x(e,(e=>{const s=w;s?v=!0:++M>=10&&E(),Ci.set(t),f.setData(Ci,e,0,!s)}))},setOffset:(e,t)=>{},getEachIndex:(e,t)=>{o&&x(e,(e=>o[e].indices.forEach((e=>t(e)))))},getEachVertex:(e,s)=>{o&&x(e,(e=>{const r=o[e],n=r.positionsCompressed,A=r.positionsDecodeMatrix,a=vi;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,R.decompressPosition(a,A),R.mulMat4v4(t.worldMatrix,a,a),R.addVec3(i,a,a),s(a)}))},precisionRayPickSurface:(e,t,s,i,r)=>!1,renderers:ui(a,"dtx",n,t.saoEnabled,!1,!1,!0,((e,t)=>Ui(e,!t))),drawCalls:function(){const e=function(e){const s=(e,t)=>e.setInputValue&&e.setInputValue(t);return(r,n,A)=>{s(n.worldMatrix,t.rotationMatrix),s(n.viewMatrix,A.viewMatrix),s(n.projMatrix,A.projMatrix);const o=R.transformPoint3(t.matrix,i,Bi);s(n.uCameraEyeRtc,R.subVec3(A.eye,o,wi)),s(n.perObjPosDecode,g),s(n.perVertIdCoords,_),s(n.perObjColsFlags,c),s(n.perObjectMatrix,p),e(n)}},s=function(t){return e((e=>{b.edges(e,t),y.edges(e,t),B.edges(e,t)}))};return{drawVertices:s(l.POINTS),drawEdges:s(l.LINES),drawSurface:e((e=>{const t=l.TRIANGLES;b.indices(e,t),y.indices(e,t),B.indices(e,t)}))}}(),destroy:()=>{C||(a.off(F),C=!0)}}}}const xi=function(e,t,s,i,r,n,A,o){if(s>4&&s%4>0)throw"Unhandled data size "+s;const a=Math.ceil(s/4),l=s/a,[c,h,u]=function(){switch(i){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 "+i}}(),d=r*a,p=Math.ceil(t/r);if(0===p)throw"texture height===0";let f=new c(d*p*l);_i[A]+=f.byteLength,_i.numberOfTextures++,n(f);const g=e.createTexture();return e.bindTexture(e.TEXTURE_2D,g),e.texStorage2D(e.TEXTURE_2D,1,h,d,p),e.texSubImage2D(e.TEXTURE_2D,0,0,0,d,p,u,i,f),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),o||(f=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(f.set(t,n*s+A*l),o){e.bindTexture(e.TEXTURE_2D,g);const s=n%r*a+A,o=Math.floor(n/r),c=t.length/l;e.texSubImage2D(e.TEXTURE_2D,0,s,o,c,1,u,i,t)}},reloadData(){e.bindTexture(e.TEXTURE_2D,g),e.texSubImage2D(e.TEXTURE_2D,0,0,0,d,p,u,i,f)}}}},Ui=function(e,t){const s=(t,s)=>{const i=e.createUniform(t,s),r=e=>`texelFetch(${i}, ${e}, 0)`;return r.map=i,r},i=s("highp usampler2D","perPrimIndices"),r=s("mediump usampler2D","perPrimIdPorIds"),n=s("highp sampler2D","perObjPosDecode"),A=s("mediump usampler2D","perVertIdCoords"),o=s("lowp usampler2D","perObjColsFlags"),a=s("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},p=d("colorA"),f=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:p,flags:mi(4).map((e=>`int(flags[${e}])`)),metallicRoughness:null,normal:{view:m,world:g},pickColor:f,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)};`),p.needed&&e.push(`vec4 ${p} = vec4(${_(0)}) / 255.0;`)},appendVertexData:e=>{const s=e=>a(`ivec2(objectIndexCoords.x*4+${e}, objectIndexCoords.y)`);e.push(`mat4 objectInstanceMatrix = mat4(${s(0)}, ${s(1)}, ${s(2)}, ${s(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(${i("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;f.needed&&e.push(`vec4 pickColor = vec4(${_(1)});`),e.push(`vec4 worldPosition = ${l} * (objectDecodeAndInstanceMatrix * vec4(position, 1.0));`)},layerTypeInputs:{perPrimIndices:i.map,perPrimIdPorIds:r.map,perObjPosDecode:n.map,perVertIdCoords:A.map,perObjColsFlags:o.map,perObjectMatrix:a.map,worldMatrix:l,viewMatrix:c,projMatrix:h,uCameraEyeRtc:u}}},Ii=R.mat4(),Ti=R.mat4();function Pi(e,t,s){const i=e.length,r=new Uint16Array(i),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,p=h/c,f=e=>e>=0?e:0;for(let t=0;t<i;t+=3)r[t+0]=Math.floor(f(e[t+0]-n)*u),r[t+1]=Math.floor(f(e[t+1]-A)*d),r[t+2]=Math.floor(f(e[t+2]-o)*p);return R.identityMat4(Ii),R.translationMat4v(t,Ii),R.identityMat4(Ti),R.scalingMat4v([a/h,l/h,c/h],Ti),R.mulMat4(Ii,Ti,s),r}function Si(e,t){const s=e[0],i=e[1],r=e[2],n=e[3]-s||1,A=e[4]-i||1,o=e[5]-r||1,a=65525;return R.identityMat4(Ii),R.translationMat4v(e,Ii),R.identityMat4(Ti),R.scalingMat4v([n/a,A/a,o/a],Ti),R.mulMat4(Ii,Ti,t),t}function Di(e,t,s){let i=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=i,t=r;e=(1-Math.abs(r))*(i>=0?1:-1),t=(1-Math.abs(i))*(r>=0?1:-1),i=e,r=t}return new Int8Array([Math[t](127.5*i+(i<0?-1:0)),Math[s](127.5*r+(r<0?-1:0))])}function ki(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const i=1-Math.abs(t)-Math.abs(s);i<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const r=Math.sqrt(t*t+s*s+i*i);return[t/r,s/r,i/r]}const Qi=new Float32Array(1),Ri=new Float32Array(4),Oi=new Float32Array(3),Vi=R.mat4(),Li=R.vec4([0,0,0,1]),Hi=R.vec4(),Ni=R.vec3(),Gi=R.vec3(),ji=R.vec3(),zi=R.vec3(),Wi=R.vec3(),Xi=R.vec3(),Ki=R.vec3(),Zi=new Uint8Array(4),Ji=new Float32Array(96),Yi=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t},$i=function(e,t){e.set(t);let s=t.length;const i=e.length;for(;s<i;){const t=Math.min(s,i-s);e.set(e.subarray(0,t),s),s+=t}},qi=function(){let e=0;const t=new Map;return{acquire:()=>e++,release:()=>{e--,0===e&&t.clear()},getTypeArray:function(e,s){t.has(e)||t.set(e,{});const i=t.get(e);return s in i||(i[s]=new e(s)),i[s]}}}();class er extends di{constructor(e,t,s,i){super(e,t,s);const r=!!i.geometry;this._maxVerts=i.maxGeometryBatchSize;const n=r?i.geometry.positionsDecodeMatrix:i.positionsDecodeMatrix;this._positionsDecodeMatrix=n&&R.mat4(n),this._cfgUvDecodeMatrix=i.uvDecodeMatrix&&R.mat3(i.uvDecodeMatrix),this._instancedGeometry=i.geometry,this._textureSet=i.textureSet,this._modelAABB=!r&&R.collapseAABB3(),this._portions=[];const A=function(){let e=0;const t=[];return{length:()=>e,append:function(s,i=1,r=1,n=0){e+=i*s.length,t.push({data:s,times:i,denormalizeScale:r,increment:n})},compileBuffer:function(e){let s=0;t.forEach((e=>{s+=e.times*e.data.length}));const i=new e(s);let r=0;return t.forEach((e=>{const t=e.data,s=e.denormalizeScale,n=e.increment,A=i.subarray(r);if(1===s&&0===n)A.set(t);else for(let e=0;e<t.length;++e)A[e]=n+t[e]*s;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})),i},_clearToOptimizeGC:()=>{t.length=0}}};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 s=this._buffer,i=this._instancedGeometry,r=this.model,n=this._portions.length,A=this.primitive,o=!!this._positionsDecodeMatrix,a=r.scene,l=t.meshMatrix,c=(i,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:i,portionSize:o,retainedGeometry:a.readableGeometryEnabled&&"points"!==A&&"lines"!==A&&{indices:l,quantizedPositions:c,offset:a.entityOffsetsEnabled&&R.vec3(),matrix:h&&h.slice(),inverseMatrix:null,normalMatrix:null}};return"points"!==A&&"lines"!==A&&s.metallicRoughness.append([t.metallic??0,t.roughness??255],o),"lines"!==A&&s.pickColors.append(t.pickColor.slice(0,4),o),this._portions.push(d),r.numPortions++,this._meshes.push(e),n};if(i){if(s.modelMatrixCol.forEach(((e,t)=>e.append([l[t+0],l[t+4],l[t+8],l[t+12]]))),"points"!==A){const e=t.color;s.colors.append([e[0],e[1],e[2],t.opacity??255])}if("points"!==A&&"lines"!==A&&i.normals){const e=R.inverseMat4(R.transposeMat4(l,R.mat4()));s.modelNormalMatrixCol.forEach(((t,s)=>t.append([e[s+0],e[s+4],e[s+8],e[s+12]])))}return c(n,1,i.indices,i.positionsCompressed,l)}{const e=s.positions.length()/3,i=o?t.positionsCompressed:t.positions;if(!i)throw(o?"positionsCompressed":"positions")+" expected";s.positions.append(i);const r=i.length/3,n=t.indices;n&&s.indices.append(n,1,1,e);const a=t.normalsCompressed,h=t.normals;if(a&&a.length>0)s.normals.append(a);else if(h&&h.length>0){const e=Vi;l?(R.transposeMat4(l,e),R.inverseMat4(e,e)):R.identityMat4(e);const t=[];!function(e,t,s,i,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<s;h+=3)u[0]=t[h],u[1]=t[h+1],u[2]=t[h+2],R.transformVec3(e,u,d),R.normalizeVec3(d,d),a=A=Di(d,"floor","floor"),o=ki(A),l=c=n(d,o),A=Di(d,"ceil","floor"),o=ki(A),l=n(d,o),l>c&&(a=A,c=l),A=Di(d,"floor","ceil"),o=ki(A),l=n(d,o),l>c&&(a=A,c=l),A=Di(d,"ceil","ceil"),o=ki(A),l=n(d,o),l>c&&(a=A,c=l),i[r+h+0]=a[0],i[r+h+1]=a[1],i[r+h+2]=0}(e,h,h.length,t,0),s.normals.append(t)}const u=t.colors,d=t.colorsCompressed,p=t.color;if(u)if("points"===A)s.colors.append(u,1,255);else{const e=[];for(let t=0,s=u.length;t<s;t+=3)e.push(255*u[t]),e.push(255*u[t+1]),e.push(255*u[t+2]),e.push(255);s.colors.append(e)}else if(d)if("points"===A)s.colors.append(d);else{const e=[];for(let t=0,s=d.length;t<s;t+=3)e.push(d[t]),e.push(d[t+1]),e.push(d[t+2]),e.push(255);s.colors.append(e)}else p&&s.colors.append([p[0],p[1],p[2],"points"===A?1:t.opacity],r);const f=e=>e&&e.length>0&&e,g=f(t.uv)||f(t.uvCompressed);g&&s.uv.append(g);const m=t.edgeIndices;return m&&s.edgeIndices.append(m,1,1,e),R.expandAABB3(this._modelAABB,t.aabb),c(e,r,n)}}compilePortions(){const e=this._buffer,t=this._instancedGeometry,s=this.model,i=this._modelAABB,r=this.origin,n=this._portions,A=this.primitive,o=this._textureSet;let a=this._positionsDecodeMatrix;const l=this._cfgUvDecodeMatrix,c=s.scene,h=c.canvas.gl,u=!!t,d=[],p=(e,t,s,i)=>{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,i)};l(t);const c=t.BYTES_PER_ELEMENT,u=t.length/s;return{bindBuffer:a,getData:(t=0,i=u-t)=>{a();const A=new r(i*s);return h.getBufferSubData(e,t*n*s,A,0,i*s),A},numItems:u,setData:l,setSubData:(t,s)=>{a(),h.bufferSubData(e,s*c,t)},type:A}}return null},f=(e,t,s,i=!1,r=!1)=>{const n=p(h.ARRAY_BUFFER,e,t,s);return n&&{getData:n.getData,numItems:n.numItems,setData:n.setData,setSubData:n.setSubData,attributeDivisor:i&&1,bindAtLocation:e=>{n.bindBuffer(),h.vertexAttribPointer(e,t,n.type,!!r,0,0)}}},g=e=>{const t=p(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),_=f(new Float32Array(m),1,h.DYNAMIC_DRAW,u),b=(e,t)=>f(e,4,t,u&&"points"!==A,!0),y=u&&t.colorsCompressed?b(new Uint8Array(t.colorsCompressed),h.STATIC_DRAW):b(e.colors.compileBuffer(Uint8Array),h.DYNAMIC_DRAW),B=c.entityOffsetsEnabled&&f(new Float32Array(3*m),3,h.DYNAMIC_DRAW,u),w=f(e.metallicRoughness.compileBuffer(Uint8Array),2,h.STATIC_DRAW,u),v=f(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):Pi(e.positions.compileBuffer(Float64Array),i,a=R.mat4()),x=F&&f(F,3,h.STATIC_DRAW);if(!u)for(let e=0;e<n.length;++e){const t=n[e];if(t.retainedGeometry){const e=3*t.portionBase;t.retainedGeometry.quantizedPositions=F.subarray(e,e+3*t.portionSize)}}const U=u&&e.modelMatrixCol.map((e=>f(e.compileBuffer(Float32Array),4,h.STATIC_DRAW,!0))),I=!u&&e.normals.compileBuffer(Int8Array),T=I&&f(I,3,h.STATIC_DRAW,!1,!0),P=U&&T&&e.modelNormalMatrixCol.map((e=>f(e.compileBuffer(Float32Array),4,h.STATIC_DRAW,!0))),S=u?"points"!==A&&"lines"!==A&&t.uvCompressed&&{buf:f(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:f(t,2,h.STATIC_DRAW),mat:l};{const e=Re.getUVBounds(t),s=Re.compressUVs(t,e.min,e.max);return{buf:f(s.quantized,2,h.STATIC_DRAW),mat:R.mat3(s.decodeMatrix)}}}();Object.values(this._buffer).forEach((e=>e._clearToOptimizeGC?e._clearToOptimizeGC():e.forEach((e=>e._clearToOptimizeGC())))),this._buffer=null,qi.acquire(),d.push((()=>qi.release()));let D=null;const k=(e,s,i,r=!1)=>{hi(s,i,"points"!==A&&"lines"!==A,c,Zi);const o=s&Os?1:0;let a=0;a|=Zi[0],a|=Zi[1]<<4,a|=Zi[2]<<8,a|=Zi[3]<<12,a|=o<<16,Qi[0]=a;const l=n[e],h=l.portionBase,u=l.portionSize;if(r&&!t)D||(D=new Float32Array(m)),$i(D.subarray(h,h+u),Qi);else if(_){const e=qi.getTypeArray(Float32Array,u);$i(e,Qi),_.setSubData(e,h)}},Q="solid"===A;return{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,s)=>{},setDeferredFlags:()=>{D&&(_.setData(D),D=null)},setColor:(e,t)=>{if(y){const s=n[e],i=qi.getTypeArray(Uint8Array,4*s.portionSize);$i(i,t.slice(0,4)),y.setSubData(i,4*s.portionBase)}},setMatrix:(e,t)=>{U&&U.forEach(((s,i)=>{Ri[0]=t[i+0],Ri[1]=t[i+4],Ri[2]=t[i+8],Ri[3]=t[i+12],s.setSubData(Ri,4*e)}))},setOffset:(e,t)=>{if(c.entityOffsetsEnabled){const s=n[e];if(B){Oi.set(t);const e=qi.getTypeArray(Float32Array,3*s.portionSize);$i(e,Oi),B.setSubData(e,3*s.portionBase)}s.retainedGeometry&&s.retainedGeometry.offset.set(t)}else s.error("Entity#offset not enabled for this Viewer")},getEachIndex:(e,t)=>{const s=n[e].retainedGeometry;s&&s.indices.forEach((e=>t(e)))},getEachVertex:(e,t)=>{const i=n[e].retainedGeometry;if(i){const e=Hi;r?e.set(r,0):e[0]=e[1]=e[2]=0,e[3]=1;const n=s.matrix,A=i.quantizedPositions,o=Li;for(let s=0,r=A.length;s<r;s+=3)o[0]=A[s],o[1]=A[s+1],o[2]=A[s+2],R.decompressPosition(o,a),i.matrix&&R.transformPoint3(i.matrix,o,o),o[3]=1,R.addVec3(e,o,o),R.mulMat4v4(n,o,o),t(o)}},readGeometryData:"points"!==A&&"lines"!==A&&(e=>{const t=!u&&n[e],i=t?E.getData(t.indicesBaseIndex,t.numIndices).map((e=>e-t.portionBase)):E.getData(),A=s.matrix,o=R.vec4();o.set(r,0),o[3]=1,R.mulMat4v4(A,o,o);const l=U&&R.mat4();if(l){const t=U[0].getData(e,1),s=U[1].getData(e,1),i=U[2].getData(e,1);l.set([t[0],s[0],i[0],0,t[1],s[1],i[1],0,t[2],s[2],i[2],0,t[3],s[3],i[3],1])}const c=R.mat4();R.mulMat4(A,l?R.mulMat4(l,a,c):a,c),c[12]+=o[0],c[13]+=o[1],c[14]+=o[2];const h=t?x.getData(t.portionBase,t.portionSize):x.getData();return{indices:i,positions:R.transformPositions3(c,h,new Float64Array(h.length))}}),precisionRayPickSurface:(e,t,i,A,o)=>{const l=n[e].retainedGeometry;if(l){l.matrix&&!l.inverseMatrix&&(l.inverseMatrix=R.inverseMat4(l.matrix,R.mat4())),o&&l.inverseMatrix&&!l.normalMatrix&&(l.normalMatrix=R.transposeMat4(l.inverseMatrix,R.mat4()));const e=l.quantizedPositions,n=l.indices,c=l.offset,h=Ni,u=Gi;h.set(r?R.subVec3(t,r,ji):t),u.set(i),c&&R.subVec3(h,c),R.transformRay(s.worldNormalMatrix,h,u,h,u),l.inverseMatrix&&R.transformRay(l.inverseMatrix,h,u,h,u);const d=zi,p=Wi,f=Xi;let g=!1,m=0;const _=Ki;for(let i=0,b=n.length;i<b;i+=3){const b=3*n[i],y=3*n[i+1],B=3*n[i+2];if(d[0]=e[b],d[1]=e[b+1],d[2]=e[b+2],p[0]=e[y],p[1]=e[y+1],p[2]=e[y+2],f[0]=e[B],f[1]=e[B+1],f[2]=e[B+2],R.decompressPosition(d,a),R.decompressPosition(p,a),R.decompressPosition(f,a),R.rayTriangleIntersect(h,u,d,p,f,_)){l.matrix&&R.transformPoint3(l.matrix,_,_),R.transformPoint3(s.worldMatrix,_,_),c&&R.addVec3(_,c),r&&R.addVec3(_,r);const e=Math.abs(R.lenVec3(R.subVec3(_,t,[])));(!g||e>m)&&(m=e,A.set(_),o&&R.triangleNormal(d,p,f,o),g=!0)}}return g&&o&&(l.normalMatrix&&R.transformVec3(l.normalMatrix,o,o),R.transformVec3(s.worldNormalMatrix,o,o),R.normalizeVec3(o)),g}return!1},layerTextureSet:o,renderers:ui(c,u?"instancing":"batching",A,s.saoEnabled,s.pbrEnabled&&S&&o&&o.colorTexture&&T&&w&&o.metallicRoughnessTexture,s.colorTextureEnabled&&S&&o&&o.colorTexture,!!T,(e=>sr(e,u&&{hasModelNormalMat:!!P},c.entityOffsetsEnabled))),drawCalls:function(){const e={},t=t=>(i,r,o)=>{let l=0;Ji.set(s.rotationMatrix,0),Ji.set(o.viewMatrix,l+=16),Ji.set(o.projMatrix,l+=16),Ji.set(a,l+=16),r.needNormal()&&(Ji.set(s.worldNormalMatrix,l+=16),Ji.set(o.viewNormalMatrix,l+=16)),r.matrices.setInputValue(Ji),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(S.mat),i in e||(e[i]=[null,null,null]);const c=e[i],p=t?t.vertices?0:1:2;if(!c[p]){const e=h.createVertexArray();h.bindVertexArray(e);const s=(e,t)=>{e&&e.setInputValue&&t&&e.setInputValue(t)},i=r.attributes;s(i.position,x),s(i.normal,T),s(i.color,y),s(i.pickColor,v),s(i.uV,S&&S.buf),s(i.metallicRoughness,w),s(i.flags,_),s(i.offset,B),i.modelMatrixCol&&i.modelMatrixCol.forEach(((e,t)=>s(e,U[t]))),i.modelNormalMatrixCol&&i.modelNormalMatrixCol.forEach(((e,t)=>s(e,P[t])));const o=function(){const e=()=>{u?h.drawArraysInstanced(h.POINTS,0,x.numItems,n.length):h.drawArrays(h.POINTS,0,x.numItems)},s=(e,t)=>{t.bindIndicesBuffer();const s=t.indicesCount,i=t.indicesType;return()=>{u?h.drawElementsInstanced(e,s,i,0,n.length):h.drawElements(e,s,i,0)}};return"points"===A?e:"lines"===A?t&&t.vertices?e:s(h.LINES,E):t&&t.vertices?e:t?C?s(h.LINES,C):()=>{}:s(h.TRIANGLES,E)}();h.bindVertexArray(null),d.push((()=>h.deleteVertexArray(e))),c[p]=()=>{h.bindVertexArray(e),o(),h.bindVertexArray(null)}}c[p]()};return{drawVertices:t({vertices:!0}),drawEdges:t({}),drawSurface:t(null)}}(),destroy:()=>{d.forEach((e=>e())),d.length=0}}}}const tr=function(e){const t={toString:()=>(t.needed=!0,e)};return t},sr=function(e,t,s){const i=e.createAttribute,r={position:i("vec3","positionA"),normal:i("vec3","normalA"),color:i("vec4","colorA"),pickColor:i("vec4","pickColor"),uV:i("vec2","uvApremul"),metallicRoughness:i("vec2","metallicRoughness"),flags:i("float","flagsA"),offset:s&&i("vec3","offset"),modelMatrixCol:t&&Yi(3).map((e=>i("vec4","modelMatrixCol"+e))),modelNormalMatrixCol:t&&t.hasModelNormalMat&&Yi(3).map((e=>i("vec4","modelNormalMatrixCol"+e)))},n=tr("aUv"),A=tr("viewNormal"),o=tr("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:Yi(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 s=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)${s?" * "+s:""});`),r.offset&&t.push(`worldPosition.xyz = worldPosition.xyz + ${r.offset};`),l()){const s=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)${s||""};`),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 ir{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 rr{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const nr={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 Ar{constructor(e,t,s){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=s}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,s=this.handlers.length;t<s;t+=2){const s=this.handlers[t],i=this.handlers[t+1];if(s.global&&(s.lastIndex=0),s.test(e))return i}return null}}const or=new Ar;class ar{constructor(e){this.manager=void 0!==e?e:or,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(e,t){const s=this;return new Promise((function(i,r){s.load(e,i,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 lr={};class cr extends ar{constructor(e){super(e)}load(e,t,s,i){void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);const r=nr.get(e);if(void 0!==r)return this.manager.itemStart(e),q.scheduleTask((()=>{t&&t(r),this.manager.itemEnd(e)}),0),r;if(void 0!==lr[e])return void lr[e].push({onLoad:t,onProgress:s,onError:i});lr[e]=[],lr[e].push({onLoad:t,onProgress:s,onError:i});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 s=lr[e],i=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(){i.read().then((({done:i,value:r})=>{if(i)e.close();else{o+=r.byteLength;const i=new ProgressEvent("progress",{lengthComputable:A,loaded:o,total:n});for(let e=0,t=s.length;e<t;e++){const t=s[e];t.onProgress&&t.onProgress(i)}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),s=t&&t[1]?t[1].toLowerCase():void 0,i=new TextDecoder(s);return e.arrayBuffer().then((e=>i.decode(e)))}}})).then((t=>{nr.add(e,t);const s=lr[e];delete lr[e];for(let e=0,i=s.length;e<i;e++){const i=s[e];i.onLoad&&i.onLoad(t)}})).catch((t=>{const s=lr[e];if(void 0===s)throw this.manager.itemError(e),t;delete lr[e];for(let e=0,i=s.length;e<i;e++){const i=s[e];i.onError&&i.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 hr{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 s=this.workersResolve[e];if(s&&s(t),this.queue.length){const{resolve:t,msg:s,transfer:i}=this.queue.shift();this.workersResolve[e]=t,this.workers[e].postMessage(s,i)}else this.workerStatus^=1<<e}setWorkerCreator(e){this.workerCreator=e}setWorkerLimit(e){this.pool=e}postMessage(e,t){return new Promise((s=>{const i=this._getIdleWorker();-1!==i?(this._initWorker(i),this.workerStatus|=1<<i,this.workersResolve[i]=s,this.workers[i].postMessage(e,t)):this.queue.push({resolve:s,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 ur=0;class dr{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new hr,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const i=e.capabilities;this._workerConfig={astcSupported:i.astcSupported,etc1Supported:i.etc1Supported,etc2Supported:i.etc2Supported,dxtSupported:i.dxtSupported,bptcSupported:i.bptcSupported,pvrtcSupported:i.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new cr;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new cr;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const i=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,i]).then((([e,t])=>{const s=dr.BasisWorker.toString(),i=["/* constants */","let _EngineFormat = "+JSON.stringify(dr.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(dr.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(dr.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([i])),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}))})),ur>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),ur++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((i,r)=>{const n=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:n},e))).then((e=>{const s=e.data,{mipmaps:n,width:A,height:o,format:a,type:l,error:c,dfdTransferFn:h,dfdFlags:u}=s;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)}}),i()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),ur--}}dr.BasisFormat={ETC1S:0,UASTC_4x4:1},dr.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},dr.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},dr.BasisWorker=function(){let e,t,s;const i=_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=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.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:p,dfdFlags:f}=function(t){const A=new s.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(),p=A.getLevels(),f=A.getHasAlpha(),g=A.getDFDTransferFunc(),m=A.getDFDFlags(),{transcoderFormat:_,engineFormat:b}=function(t,s,A,c){let h,u;const d=t===n.ETC1S?o:a;for(let i=0;i<d.length;i++){const r=d[i];if(e[r.if]&&(r.basisFormat.includes(t)&&!(c&&r.transcoderFormat.length<2)&&(!r.needsPowerOfTwo||l(s)&&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=i.RGBAFormat,{transcoderFormat:h,engineFormat:u}}(h,u,d,f);if(!u||!d||!p)throw c(),new Error("KTX2TextureTranscoder: Invalid texture");if(!A.startTranscoding())throw c(),new Error("KTX2TextureTranscoder: .startTranscoding failed");const y=[];for(let e=0;e<p;e++){const t=A.getImageLevelInfo(e,0,0),s=t.origWidth,i=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.");y.push({data:r,width:s,height:i})}return c(),{width:u,height:d,hasAlpha:f,mipmaps:y,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:p,dfdFlags:f},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:[i.RGBA_ASTC_4x4_Format,i.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:[i.RGBA_BPTC_Format,i.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.BC1,r.BC3],engineFormat:[i.RGB_S3TC_DXT1_Format,i.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.ETC1,r.ETC2],engineFormat:[i.RGB_ETC2_Format,i.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.ETC1],engineFormat:[i.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:[i.RGB_PVRTC_4BPPV1_Format,i.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 pr={};function fr(e){const t=e.scene.id;let s=pr[t];return s||(s=new dr({viewer:e}),pr[t]=s,e.scene.on("destroyed",(()=>{delete pr[t],s.destroy()}))),s}
7
+ "undefined"!=typeof window&&(window.__XEOKIT__={version:"2.6.113",commit:"35015312cd61fbe9a764d8874667ca89dadefeb0",built:"2026-08-20T08:04:04.016Z"}),Object.defineProperty(exports,"__esModule",{value:!0});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 s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class i{constructor(){this.items=[]}}class r{constructor(e,t,s,i,r){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=i,this.getShown=r,this.itemElement=null,this.subMenu=null,this.enabled=!0}}function n(e,t,s=2){const i=t&&t.length,r=i?t[0]*s:e.length;let n=A(e,0,r,s,!0);const o=[];if(!n||n.next===n.prev)return o;let l,c,h;if(i&&(n=function(e,t,s,i){const r=[];for(let s=0,n=t.length;s<n;s++){const o=A(e,t[s]*i,s<n-1?t[s+1]*i:e.length,i,!1);o===o.next&&(o.steiner=!0),r.push(m(o))}r.sort(d);for(let e=0;e<r.length;e++)s=p(r[e],s);return s}(e,t,n,s)),e.length>80*s){l=1/0,c=1/0;let t=-1/0,i=-1/0;for(let n=s;n<r;n+=s){const s=e[n],r=e[n+1];s<l&&(l=s),r<c&&(c=r),s>t&&(t=s),r>i&&(i=r)}h=Math.max(t-l,i-c),h=0!==h?32767/h:0}return a(n,o,s,l,c,h,0),o}function A(e,t,s,i,r){let n;if(r===function(e,t,s,i){let r=0;for(let n=t,A=s-i;n<s;n+=i)r+=(e[A]-e[n])*(e[n+1]+e[A+1]),A=n;return r}(e,t,s,i)>0)for(let r=t;r<s;r+=i)n=x(r/i|0,e[r],e[r+1],n);else for(let r=s-i;r>=t;r-=i)n=x(r/i|0,e[r],e[r+1],n);return n&&w(n,n.next)&&(U(n),n=n.next),n}function o(e,t){if(!e)return e;t||(t=e);let s,i=e;do{if(s=!1,i.steiner||!w(i,i.next)&&0!==B(i.prev,i,i.next))i=i.next;else{if(U(i),i=t=i.prev,i===i.next)break;s=!0}}while(s||i!==t);return t}function a(e,t,s,i,r,n,A){if(!e)return;!A&&n&&function(e,t,s,i){let r=e;do{0===r.z&&(r.z=g(r.x,r.y,t,s,i)),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,s=1;do{let i,r=e;e=null;let n=null;for(t=0;r;){t++;let A=r,o=0;for(let e=0;e<s&&(o++,A=A.nextZ,A);e++);let a=s;for(;o>0||a>0&&A;)0!==o&&(0===a||!A||r.z<=A.z)?(i=r,r=r.nextZ,o--):(i=A,A=A.nextZ,a--),n?n.nextZ=i:e=i,i.prevZ=n,n=i;r=A}n.nextZ=null,s*=2}while(t>1)}(r)}(e,i,r,n);let d=e;for(;e.prev!==e.next;){const p=e.prev,f=e.next;if(n?c(e,i,r,n):l(e))t.push(p.i,e.i,f.i),U(e),e=f.next,d=f.next;else if((e=f)===d){A?1===A?a(e=h(o(e),t),t,s,i,r,n,2):2===A&&u(e,t,s,i,r,n):a(o(e),t,s,i,r,n,1);break}}}function l(e){const t=e.prev,s=e,i=e.next;if(B(t,s,i)>=0)return!1;const r=t.x,n=s.x,A=i.x,o=t.y,a=s.y,l=i.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 p=i.next;for(;p!==t;){if(p.x>=c&&p.x<=u&&p.y>=h&&p.y<=d&&b(r,o,n,a,A,l,p.x,p.y)&&B(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function c(e,t,s,i){const r=e.prev,n=e,A=e.next;if(B(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),p=Math.min(c,h,u),f=Math.max(o,a,l),m=Math.max(c,h,u),_=g(d,p,t,s,i),y=g(f,m,t,s,i);let w=e.prevZ,v=e.nextZ;for(;w&&w.z>=_&&v&&v.z<=y;){if(w.x>=d&&w.x<=f&&w.y>=p&&w.y<=m&&w!==r&&w!==A&&b(o,c,a,h,l,u,w.x,w.y)&&B(w.prev,w,w.next)>=0)return!1;if(w=w.prevZ,v.x>=d&&v.x<=f&&v.y>=p&&v.y<=m&&v!==r&&v!==A&&b(o,c,a,h,l,u,v.x,v.y)&&B(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;w&&w.z>=_;){if(w.x>=d&&w.x<=f&&w.y>=p&&w.y<=m&&w!==r&&w!==A&&b(o,c,a,h,l,u,w.x,w.y)&&B(w.prev,w,w.next)>=0)return!1;w=w.prevZ}for(;v&&v.z<=y;){if(v.x>=d&&v.x<=f&&v.y>=p&&v.y<=m&&v!==r&&v!==A&&b(o,c,a,h,l,u,v.x,v.y)&&B(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function h(e,t){let s=e;do{const i=s.prev,r=s.next.next;!w(i,r)&&v(i,s,s.next,r)&&E(i,r)&&E(r,i)&&(t.push(i.i,s.i,r.i),U(s),U(s.next),s=e=r),s=s.next}while(s!==e);return o(s)}function u(e,t,s,i,r,n){let A=e;do{let e=A.next.next;for(;e!==A.prev;){if(A.i!==e.i&&y(A,e)){let l=F(A,e);return A=o(A,A.next),l=o(l,l.next),a(A,t,s,i,r,n,0),void a(l,t,s,i,r,n,0)}e=e.next}A=A.next}while(A!==e)}function d(e,t){let s=e.x-t.x;if(0===s&&(s=e.y-t.y,0===s)){s=(e.next.y-e.y)/(e.next.x-e.x)-(t.next.y-t.y)/(t.next.x-t.x)}return s}function p(e,t){const s=function(e,t){let s=t;const i=e.x,r=e.y;let n,A=-1/0;if(w(e,s))return s;do{if(w(e,s.next))return s.next;if(r<=s.y&&r>=s.next.y&&s.next.y!==s.y){const e=s.x+(r-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(e<=i&&e>A&&(A=e,n=s.x<s.next.x?s:s.next,e===i))return n}s=s.next}while(s!==t);if(!n)return null;const o=n,a=n.x,l=n.y;let c=1/0;s=n;do{if(i>=s.x&&s.x>=a&&i!==s.x&&_(r<l?i:A,r,a,l,r<l?A:i,r,s.x,s.y)){const t=Math.abs(r-s.y)/(i-s.x);E(s,e)&&(t<c||t===c&&(s.x>n.x||s.x===n.x&&f(n,s)))&&(n=s,c=t)}s=s.next}while(s!==o);return n}(e,t);if(!s)return t;const i=F(s,e);return o(i,i.next),o(s,s.next)}function f(e,t){return B(e.prev,e,t.prev)<0&&B(t.next,e,e.next)<0}function g(e,t,s,i,r){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-s)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-i)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function m(e){let t=e,s=e;do{(t.x<s.x||t.x===s.x&&t.y<s.y)&&(s=t),t=t.next}while(t!==e);return s}function _(e,t,s,i,r,n,A,o){return(r-A)*(t-o)>=(e-A)*(n-o)&&(e-A)*(i-o)>=(s-A)*(t-o)&&(s-A)*(n-o)>=(r-A)*(i-o)}function b(e,t,s,i,r,n,A,o){return!(e===A&&t===o)&&_(e,t,s,i,r,n,A,o)}function y(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){let s=e;do{if(s.i!==e.i&&s.next.i!==e.i&&s.i!==t.i&&s.next.i!==t.i&&v(s,s.next,e,t))return!0;s=s.next}while(s!==e);return!1}(e,t)&&(E(e,t)&&E(t,e)&&function(e,t){let s=e,i=!1;const r=(e.x+t.x)/2,n=(e.y+t.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==e);return i}(e,t)&&(B(e.prev,e,t.prev)||B(e,t.prev,t))||w(e,t)&&B(e.prev,e,e.next)>0&&B(t.prev,t,t.next)>0)}function B(e,t,s){return(t.y-e.y)*(s.x-t.x)-(t.x-e.x)*(s.y-t.y)}function w(e,t){return e.x===t.x&&e.y===t.y}function v(e,t,s,i){const r=M(B(e,t,s)),n=M(B(e,t,i)),A=M(B(s,i,e)),o=M(B(s,i,t));return r!==n&&A!==o||(!(0!==r||!C(e,s,t))||(!(0!==n||!C(e,i,t))||(!(0!==A||!C(s,e,i))||!(0!==o||!C(s,t,i)))))}function C(e,t,s){return t.x<=Math.max(e.x,s.x)&&t.x>=Math.min(e.x,s.x)&&t.y<=Math.max(e.y,s.y)&&t.y>=Math.min(e.y,s.y)}function M(e){return e>0?1:e<0?-1:0}function E(e,t){return B(e.prev,e,e.next)<0?B(e,t,e.next)>=0&&B(e,e.prev,t)>=0:B(e,t,e.prev)<0||B(e,e.next,t)<0}function F(e,t){const s=I(e.i,e.x,e.y),i=I(t.i,t.x,t.y),r=e.next,n=t.prev;return e.next=t,t.prev=e,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function x(e,t,s,i){const r=I(e,t,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function U(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 I(e,t,s){return{i:e,x:t,y:s,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}let T=!0,P=T?Float64Array:Float32Array;const S=new P(3),D=new P(16),k=new P(16),Q=new P(4),R={setDoublePrecisionEnabled(e){T=e,P=T?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>T,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new P(e||2),vec3:e=>new P(e||3),vec4:e=>new P(e||4),mat3:e=>new P(e||9),mat3ToMat4:(e,t=new P(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 P(e||16),mat4ToMat3:(e,t=new P(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,s){const i=new P(2);for(let r=0,n=e.length;r<n;r++)R.splitDouble(e[r],i),t[r]=i[0],s[r]=i[1]},splitDouble(e,t){const s=P.from([e])[0],i=e-s;t[0]=s,t[1]=i},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,s=4294967295*Math.random()|0,i=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&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&i|128]}${e[i>>8&255]}-${e[i>>16&255]}${e[i>>24&255]}${e[255&r]}${e[r>>8&255]}${e[r>>16&255]}${e[r>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,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},compareVec2:(e,t)=>e[0]===t[0]&&e[1]===t[1],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,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new P(e[0]);for(let s=1;s<e.length;s++)t[0]+=e[s][0],t[1]+=e[s][1];return t[0]/=e.length,t[1]/=e.length,t},subVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s),mulVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],i=e[1],r=e[2],n=t[0],A=t[1],o=t[2];return[i*o-r*A,r*n-s*o,s*A-i*n,0]},cross3Vec3(e,t,s){s||(s=e);const i=e[0],r=e[1],n=e[2],A=t[0],o=t[1],a=t[2];return s[0]=r*a-n*o,s[1]=n*A-i*a,s[2]=i*o-r*A,s},sqLenVec4:e=>R.dotVec4(e,e),lenVec4:e=>Math.sqrt(R.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=>R.dotVec3(e,e),sqLenVec2:e=>R.dotVec2(e,e),lenVec3:e=>Math.sqrt(R.sqLenVec3(e)),distVec3:(()=>{const e=new P(3);return(t,s)=>R.lenVec3(R.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(R.sqLenVec2(e)),distVec2:(()=>{const e=new P(2);return(t,s)=>R.lenVec2(R.subVec2(t,s,e))})(),rcpVec3:(e,t)=>R.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/R.lenVec4(e);return R.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/R.lenVec3(e);return R.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/R.lenVec2(e);return R.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=R.dotVec3(e,t)/Math.sqrt(R.sqLenVec3(e)*R.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new P(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=R.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=R.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=R.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,i=(t=Array.prototype.slice.call(t)).length;s<i;s++)t[s]=e(t[s]);return t}})(),xyzArrayToObject:e=>({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||R.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:()=>R.m4s(0),setMat4ToOnes:()=>R.m4s(1),diagonalMat4v:e=>new P([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,i)=>R.diagonalMat4v([e,t,s,i]),diagonalMat4s:e=>R.diagonalMat4c(e,e,e,e),identityMat4:(e=new P(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 P(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,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>R.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const i=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],p=e[11],f=e[12],g=e[13],m=e[14],_=e[15],b=t[0],y=t[1],B=t[2],w=t[3],v=t[4],C=t[5],M=t[6],E=t[7],F=t[8],x=t[9],U=t[10],I=t[11],T=t[12],P=t[13],S=t[14],D=t[15];return s[0]=b*i+y*o+B*h+w*f,s[1]=b*r+y*a+B*u+w*g,s[2]=b*n+y*l+B*d+w*m,s[3]=b*A+y*c+B*p+w*_,s[4]=v*i+C*o+M*h+E*f,s[5]=v*r+C*a+M*u+E*g,s[6]=v*n+C*l+M*d+E*m,s[7]=v*A+C*c+M*p+E*_,s[8]=F*i+x*o+U*h+I*f,s[9]=F*r+x*a+U*u+I*g,s[10]=F*n+x*l+U*d+I*m,s[11]=F*A+x*c+U*p+I*_,s[12]=T*i+P*o+S*h+D*f,s[13]=T*r+P*a+S*u+D*g,s[14]=T*n+P*l+S*d+D*m,s[15]=T*A+P*c+S*p+D*_,s},mulMat3(e,t,s){s||(s=new P(9));const i=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],p=t[6],f=t[1],g=t[4],m=t[7],_=t[2],b=t[5],y=t[8];return s[0]=i*u+r*f+n*_,s[3]=i*d+r*g+n*b,s[6]=i*p+r*m+n*y,s[1]=A*u+o*f+a*_,s[4]=A*d+o*g+a*b,s[7]=A*p+o*m+a*y,s[2]=l*u+c*f+h*_,s[5]=l*d+c*g+h*b,s[8]=l*p+c*m+h*y,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=R.vec4()){const i=t[0],r=t[1],n=t[2],A=t[3];return s[0]=e[0]*i+e[4]*r+e[8]*n+e[12]*A,s[1]=e[1]*i+e[5]*r+e[9]*n+e[13]*A,s[2]=e[2]*i+e[6]*r+e[10]*n+e[14]*A,s[3]=e[3]*i+e[7]*r+e[11]*n+e[15]*A,s},transposeMat4(e,t){const s=e[4],i=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]=s,e[2]=r,e[3]=A,e[4]=t,e[6]=o,e[7]=n,e[8]=a,e[9]=c,e[11]=i,e[12]=l,e[13]=h,e[14]=u,e}return t[0]=e[0],t[1]=s,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]=i,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],i=e[2],r=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=i,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],s=e[1],i=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],p=e[13],f=e[14],g=e[15];return d*c*o*r-l*p*o*r-d*A*h*r+n*p*h*r+l*A*f*r-n*c*f*r-d*c*i*a+l*p*i*a+d*s*h*a-t*p*h*a-l*s*f*a+t*c*f*a+d*A*i*u-n*p*i*u-d*s*o*u+t*p*o*u+n*s*f*u-t*A*f*u-l*A*i*g+n*c*i*g+l*s*o*g-t*c*o*g-n*s*h*g+t*A*h*g},inverseMat4(e,t){t||(t=e);const s=e[0],i=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],p=e[12],f=e[13],g=e[14],m=e[15],_=s*o-i*A,b=s*a-r*A,y=s*l-n*A,B=i*a-r*o,w=i*l-n*o,v=r*l-n*a,C=c*f-h*p,M=c*g-u*p,E=c*m-d*p,F=h*g-u*f,x=h*m-d*f,U=u*m-d*g,I=1/(_*U-b*x+y*F+B*E-w*M+v*C);return t[0]=(o*U-a*x+l*F)*I,t[1]=(-i*U+r*x-n*F)*I,t[2]=(f*v-g*w+m*B)*I,t[3]=(-h*v+u*w-d*B)*I,t[4]=(-A*U+a*E-l*M)*I,t[5]=(s*U-r*E+n*M)*I,t[6]=(-p*v+g*y-m*b)*I,t[7]=(c*v-u*y+d*b)*I,t[8]=(A*x-o*E+l*C)*I,t[9]=(-s*x+i*E-n*C)*I,t[10]=(p*w-f*y+m*_)*I,t[11]=(-c*w+h*y-d*_)*I,t[12]=(-A*F+o*M-a*C)*I,t[13]=(s*F-i*M+r*C)*I,t[14]=(-p*B+f*b-g*_)*I,t[15]=(c*B-h*b+u*_)*I,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||R.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||R.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new P(3);return(t,s,i,r)=>(e[0]=t,e[1]=s,e[2]=i,R.translationMat4v(e,r))})(),translationMat4s:(e,t)=>R.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>R.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,i){const r=i[3];i[0]+=r*e,i[1]+=r*t,i[2]+=r*s;const n=i[7];i[4]+=n*e,i[5]+=n*t,i[6]+=n*s;const A=i[11];i[8]+=A*e,i[9]+=A*t,i[10]+=A*s;const o=i[15];return i[12]+=o*e,i[13]+=o*t,i[14]+=o*s,i},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const i=R.normalizeVec4([t[0],t[1],t[2],0],[]),r=Math.sin(e),n=Math.cos(e),A=1-n,o=i[0],a=i[1],l=i[2];let c,h,u,d,p,f;return c=o*a,h=a*l,u=l*o,d=o*r,p=a*r,f=l*r,(s=s||R.mat4())[0]=A*o*o+n,s[1]=A*c+f,s[2]=A*u-p,s[3]=0,s[4]=A*c-f,s[5]=A*a*a+n,s[6]=A*h+d,s[7]=0,s[8]=A*u+p,s[9]=A*h-d,s[10]=A*l*l+n,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,i,r)=>R.rotationMat4v(e,[t,s,i],r),scalingMat4v:(e,t=R.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=R.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new P(3);return(t,s,i,r)=>(e[0]=t,e[1]=s,e[2]=i,R.scalingMat4v(e,r))})(),scaleMat4c:(e,t,s,i)=>(i[0]*=e,i[4]*=t,i[8]*=s,i[1]*=e,i[5]*=t,i[9]*=s,i[2]*=e,i[6]*=t,i[10]*=s,i[3]*=e,i[7]*=t,i[11]*=s,i),scaleMat4v(e,t){const s=e[0],i=e[1],r=e[2];return t[0]*=s,t[4]*=i,t[8]*=r,t[1]*=s,t[5]*=i,t[9]*=r,t[2]*=s,t[6]*=i,t[10]*=r,t[3]*=s,t[7]*=i,t[11]*=r,t},scalingMat4s:e=>R.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=R.mat4()){const i=e[0],r=e[1],n=e[2],A=e[3],o=i+i,a=r+r,l=n+n,c=i*o,h=i*a,u=i*l,d=r*a,p=r*l,f=n*l,g=A*o,m=A*a,_=A*l;return s[0]=1-(d+f),s[1]=h+_,s[2]=u-m,s[3]=0,s[4]=h-_,s[5]=1-(c+f),s[6]=p+g,s[7]=0,s[8]=u+m,s[9]=p-g,s[10]=1-(c+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=R.vec4()){const i=R.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?(s[1]=Math.asin(i(A,-1,1)),Math.abs(A)<.99999?(s[0]=Math.atan2(-l,u),s[2]=Math.atan2(-n,r)):(s[0]=Math.atan2(h,a),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-i(l,-1,1)),Math.abs(l)<.99999?(s[1]=Math.atan2(A,u),s[2]=Math.atan2(o,a)):(s[1]=Math.atan2(-c,r),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(i(h,-1,1)),Math.abs(h)<.99999?(s[1]=Math.atan2(-c,u),s[2]=Math.atan2(-n,a)):(s[1]=0,s[2]=Math.atan2(o,r))):"ZYX"===t?(s[1]=Math.asin(-i(c,-1,1)),Math.abs(c)<.99999?(s[0]=Math.atan2(h,u),s[2]=Math.atan2(o,r)):(s[0]=0,s[2]=Math.atan2(-n,a))):"YZX"===t?(s[2]=Math.asin(i(o,-1,1)),Math.abs(o)<.99999?(s[0]=Math.atan2(-l,a),s[1]=Math.atan2(-c,r)):(s[0]=0,s[1]=Math.atan2(A,u))):"XZY"===t&&(s[2]=Math.asin(-i(n,-1,1)),Math.abs(n)<.99999?(s[0]=Math.atan2(h,a),s[1]=Math.atan2(A,r)):(s[0]=Math.atan2(-l,u),s[1]=0)),s[0]*=R.RADTODEG,s[1]*=R.RADTODEG,s[2]*=R.RADTODEG,s},composeMat4:(e,t,s,i=R.mat4())=>(R.quaternionToRotationMat4(t,i),R.scaleMat4v(s,i),R.translateMat4v(e,i),i),decomposeMat4:(()=>{const e=new P(3),t=new P(16);return function(s,i,r,n){e[0]=s[0],e[1]=s[1],e[2]=s[2];let A=R.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const o=R.lenVec3(e);e[0]=s[8],e[1]=s[9],e[2]=s[10];const a=R.lenVec3(e);R.determinantMat4(s)<0&&(A=-A),i[0]=s[12],i[1]=s[13],i[2]=s[14],t.set(s);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,R.mat4ToQuaternion(t,r),n[0]=A,n[1]=o,n[2]=a,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,i){i||(i=R.mat4());const r=e[0],n=e[1],A=e[2],o=s[0],a=s[1],l=s[2],c=t[0],h=t[1],u=t[2];if(r===c&&n===h&&A===u)return R.identityMat4();let d,p,f,g,m,_,b,y,B,w;return d=r-c,p=n-h,f=A-u,w=1/Math.sqrt(d*d+p*p+f*f),d*=w,p*=w,f*=w,g=a*f-l*p,m=l*d-o*f,_=o*p-a*d,w=Math.sqrt(g*g+m*m+_*_),w?(w=1/w,g*=w,m*=w,_*=w):(g=0,m=0,_=0),b=p*_-f*m,y=f*g-d*_,B=d*m-p*g,w=Math.sqrt(b*b+y*y+B*B),w?(w=1/w,b*=w,y*=w,B*=w):(b=0,y=0,B=0),i[0]=g,i[1]=b,i[2]=d,i[3]=0,i[4]=m,i[5]=y,i[6]=p,i[7]=0,i[8]=_,i[9]=B,i[10]=f,i[11]=0,i[12]=-(g*r+m*n+_*A),i[13]=-(b*r+y*n+B*A),i[14]=-(d*r+p*n+f*A),i[15]=1,i},lookAtMat4c:(e,t,s,i,r,n,A,o,a)=>R.lookAtMat4v([e,t,s],[i,r,n],[A,o,a],[]),orthoMat4c(e,t,s,i,r,n,A){A||(A=R.mat4());const o=t-e,a=i-s,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]=-(i+s)/a,A[14]=-(n+r)/l,A[15]=1,A},frustumMat4v(e,t,s){s||(s=R.mat4());const i=[e[0],e[1],e[2],0],r=[t[0],t[1],t[2],0];R.addVec4(r,i,D),R.subVec4(r,i,k);const n=2*i[2],A=k[0],o=k[1],a=k[2];return s[0]=n/A,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=n/o,s[6]=0,s[7]=0,s[8]=D[0]/A,s[9]=D[1]/o,s[10]=-D[2]/a,s[11]=-1,s[12]=0,s[13]=0,s[14]=-n*r[2]/a,s[15]=0,s},frustumMat4(e,t,s,i,r,n,A){A||(A=R.mat4());const o=t-e,a=i-s,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]=(i+s)/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,s,i,r){const n=[],A=[];return n[2]=s,A[2]=i,A[1]=n[2]*Math.tan(e/2),n[1]=-A[1],A[0]=A[1]*t,n[0]=-A[0],R.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,s=R.vec3()){const i=t[0],r=t[1],n=t[2];return s[0]=e[0]*i+e[4]*r+e[8]*n+e[12],s[1]=e[1]*i+e[5]*r+e[9]*n+e[13],s[2]=e[2]*i+e[6]*r+e[10]*n+e[14],s},transformPoint4:(e,t,s=R.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const i=s||[],r=t.length;let n,A,o,a;const l=e[0],c=e[1],h=e[2],u=e[3],d=e[4],p=e[5],f=e[6],g=e[7],m=e[8],_=e[9],b=e[10],y=e[11],B=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=i[e]||(i[e]=[0,0,0]),M[0]=l*n+d*A+m*o+B,M[1]=c*n+p*A+_*o+w,M[2]=h*n+f*A+b*o+v,M[3]=u*n+g*A+y*o+C;return i.length=r,i},transformPositions3(e,t,s=t){let i;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 p=e[8],f=e[9],g=e[10];e[11];const m=e[12],_=e[13],b=e[14];for(e[15],i=0;i<r;i+=3)n=t[i+0],A=t[i+1],o=t[i+2],s[i+0]=a*n+h*A+p*o+m,s[i+1]=l*n+u*A+f*o+_,s[i+2]=c*n+d*A+g*o+b;return s},transformPositions4(e,t,s=t){let i;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],p=e[6],f=e[7],g=e[8],m=e[9],_=e[10],b=e[11],y=e[12],B=e[13],w=e[14],v=e[15];for(i=0;i<r;i+=4)n=t[i+0],A=t[i+1],o=t[i+2],s[i+0]=a*n+u*A+g*o+y,s[i+1]=l*n+d*A+m*o+B,s[i+2]=c*n+p*A+_*o+w,s[i+3]=h*n+f*A+b*o+v;return s},transformVec3(e,t,s){const i=t[0],r=t[1],n=t[2];return(s=s||this.vec3())[0]=e[0]*i+e[4]*r+e[8]*n,s[1]=e[1]*i+e[5]*r+e[9]*n,s[2]=e[2]*i+e[6]*r+e[10]*n,s},transformVec4(e,t,s){const i=t[0],r=t[1],n=t[2],A=t[3];return(s=s||R.vec4())[0]=e[0]*i+e[4]*r+e[8]*n+e[12]*A,s[1]=e[1]*i+e[5]*r+e[9]*n+e[13]*A,s[2]=e[2]*i+e[6]*r+e[10]*n+e[14]*A,s[3]=e[3]*i+e[7]*r+e[11]*n+e[15]*A,s},rotateVec2(e,t,s,i=e){const r=Math.cos(s),n=Math.sin(s),A=e[0]-t[0],o=e[1]-t[1];return i[0]=A*r-o*n+t[0],i[1]=A*n+o*r+t[1],e},rotateVec3X(e,t,s,i){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(s)-r[2]*Math.sin(s),n[2]=r[1]*Math.sin(s)+r[2]*Math.cos(s),i[0]=n[0]+t[0],i[1]=n[1]+t[1],i[2]=n[2]+t[2],i},rotateVec3Y(e,t,s,i){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(s)+r[0]*Math.cos(s),n[1]=r[1],n[2]=r[2]*Math.cos(s)-r[0]*Math.sin(s),i[0]=n[0]+t[0],i[1]=n[1]+t[1],i[2]=n[2]+t[2],i},rotateVec3Z(e,t,s,i){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(s)-r[1]*Math.sin(s),n[1]=r[0]*Math.sin(s)+r[1]*Math.cos(s),n[2]=r[2],i[0]=n[0]+t[0],i[1]=n[1]+t[1],i[2]=n[2]+t[2],i},projectVec4(e,t){const s=1/e[3];return(t=t||R.vec2())[0]=e[0]*s,t[1]=e[1]*s,t},unprojectVec3:(()=>{const e=new P(16),t=new P(16),s=new P(16);return function(i,r,n,A){return this.transformVec3(this.mulMat4(this.inverseMat4(r,e),this.inverseMat4(n,t),s),i,A)}})(),lerpVec3(e,t,s,i,r,n){const A=n||R.vec3(),o=(e-t)/(s-t);return A[0]=i[0]+o*(r[0]-i[0]),A[1]=i[1]+o*(r[1]-i[1]),A[2]=i[2]+o*(r[2]-i[2]),A},lerpMat4(e,t,s,i,r,n){const A=n||R.mat4(),o=(e-t)/(s-t);return A[0]=i[0]+o*(r[0]-i[0]),A[1]=i[1]+o*(r[1]-i[1]),A[2]=i[2]+o*(r[2]-i[2]),A[3]=i[3]+o*(r[3]-i[3]),A[4]=i[4]+o*(r[4]-i[4]),A[5]=i[5]+o*(r[5]-i[5]),A[6]=i[6]+o*(r[6]-i[6]),A[7]=i[7]+o*(r[7]-i[7]),A[8]=i[8]+o*(r[8]-i[8]),A[9]=i[9]+o*(r[9]-i[9]),A[10]=i[10]+o*(r[10]-i[10]),A[11]=i[11]+o*(r[11]-i[11]),A[12]=i[12]+o*(r[12]-i[12]),A[13]=i[13]+o*(r[13]-i[13]),A[14]=i[14]+o*(r[14]-i[14]),A[15]=i[15]+o*(r[15]-i[15]),A},flatten(e){const t=[];let s,i,r,n,A;for(s=0,i=e.length;s<i;s++)for(A=e[s],r=0,n=A.length;r<n;r++)t.push(A[r]);return t},identityQuaternion:(e=R.vec4())=>(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=R.vec4()){const i=e[0]*R.DEGTORAD/2,r=e[1]*R.DEGTORAD/2,n=e[2]*R.DEGTORAD/2,A=Math.cos(i),o=Math.cos(r),a=Math.cos(n),l=Math.sin(i),c=Math.sin(r),h=Math.sin(n);return"XYZ"===t?(s[0]=l*o*a+A*c*h,s[1]=A*c*a-l*o*h,s[2]=A*o*h+l*c*a,s[3]=A*o*a-l*c*h):"YXZ"===t?(s[0]=l*o*a+A*c*h,s[1]=A*c*a-l*o*h,s[2]=A*o*h-l*c*a,s[3]=A*o*a+l*c*h):"ZXY"===t?(s[0]=l*o*a-A*c*h,s[1]=A*c*a+l*o*h,s[2]=A*o*h+l*c*a,s[3]=A*o*a-l*c*h):"ZYX"===t?(s[0]=l*o*a-A*c*h,s[1]=A*c*a+l*o*h,s[2]=A*o*h-l*c*a,s[3]=A*o*a+l*c*h):"YZX"===t?(s[0]=l*o*a+A*c*h,s[1]=A*c*a+l*o*h,s[2]=A*o*h-l*c*a,s[3]=A*o*a-l*c*h):"XZY"===t&&(s[0]=l*o*a-A*c*h,s[1]=A*c*a-l*o*h,s[2]=A*o*h+l*c*a,s[3]=A*o*a+l*c*h),s},mat4ToQuaternion(e,t=R.vec4()){const s=e[0],i=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=s+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-i)*h):s>A&&s>c?(h=2*Math.sqrt(1+s-A-c),t[3]=(l-o)/h,t[0]=.25*h,t[1]=(i+n)/h,t[2]=(r+a)/h):A>c?(h=2*Math.sqrt(1+A-s-c),t[3]=(r-a)/h,t[0]=(i+n)/h,t[1]=.25*h,t[2]=(o+l)/h):(h=2*Math.sqrt(1+c-s-A),t[3]=(n-i)/h,t[0]=(r+a)/h,t[1]=(o+l)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,s=R.vec4()){const i=Math.sqrt(R.dotVec3(e,e)*R.dotVec3(t,t));let r=i+R.dotVec3(e,t);return r<1e-8*i?(r=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):R.cross3Vec3(e,t,s),s[3]=r,R.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=R.vec4()){const s=e[3]/2,i=Math.sin(s);return t[0]=i*e[0],t[1]=i*e[1],t[2]=i*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new P(16);return(t,s,i)=>(i=i||R.vec3(),R.quaternionToRotationMat4(t,e),R.mat4ToEuler(e,s,i),i)})(),mulQuaternions(e,t,s=R.vec4()){const i=e[0],r=e[1],n=e[2],A=e[3],o=t[0],a=t[1],l=t[2],c=t[3];return s[0]=A*o+i*c+r*l-n*a,s[1]=A*a+r*c+n*o-i*l,s[2]=A*l+n*c+i*a-r*o,s[3]=A*c-i*o-r*a-n*l,s},vec3ApplyQuaternion(e,t,s=R.vec3()){const i=t[0],r=t[1],n=t[2],A=e[0],o=e[1],a=e[2],l=e[3],c=l*i+o*n-a*r,h=l*r+a*i-A*n,u=l*n+A*r-o*i,d=-A*i-o*r-a*n;return s[0]=c*l+d*-A+h*-a-u*-o,s[1]=h*l+d*-o+u*-A-c*-a,s[2]=u*l+d*-a+c*-o-h*-A,s},quaternionToMat4(e,t){t=R.identityMat4(t);const s=e[0],i=e[1],r=e[2],n=e[3],A=2*s,o=2*i,a=2*r,l=A*n,c=o*n,h=a*n,u=A*s,d=o*s,p=a*s,f=o*i,g=a*i,m=a*r;return t[0]=1-(f+m),t[1]=d+h,t[2]=p-c,t[4]=d-h,t[5]=1-(u+m),t[6]=g+l,t[8]=p+c,t[9]=g-l,t[10]=1-(u+f),t},quaternionToRotationMat4(e,t){const s=e[0],i=e[1],r=e[2],n=e[3],A=s+s,o=i+i,a=r+r,l=s*A,c=s*o,h=s*a,u=i*o,d=i*a,p=r*a,f=n*A,g=n*o,m=n*a;return t[0]=1-(u+p),t[4]=c-m,t[8]=h+g,t[1]=c+m,t[5]=1-(l+p),t[9]=d-f,t[2]=h-g,t[6]=d+f,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 s=R.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,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)=>R.normalizeQuaternion(R.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=R.vec4()){const s=(e=R.normalizeQuaternion(e,Q))[3],i=2*Math.acos(s),r=Math.sqrt(1-s*s);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]=i,t},AABB3:e=>new P(e||6),AABB2:e=>new P(e||4),OBB3:e=>new P(e||32),OBB2:e=>new P(e||16),Sphere3:(e,t,s,i)=>new P([e,t,s,i]),transformOBB3(e,t,s=t){let i;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],p=e[6],f=e[7],g=e[8],m=e[9],_=e[10],b=e[11],y=e[12],B=e[13],w=e[14],v=e[15];for(i=0;i<r;i+=4)n=t[i+0],A=t[i+1],o=t[i+2],s[i+0]=a*n+u*A+g*o+y,s[i+1]=l*n+d*A+m*o+B,s[i+2]=c*n+p*A+_*o+w,s[i+3]=h*n+f*A+b*o+v;return s},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 P(3),t=new P(3),s=new P(3);return i=>(e[0]=i[0],e[1]=i[1],e[2]=i[2],t[0]=i[3],t[1]=i[4],t[2]=i[5],R.subVec3(t,e,s),Math.abs(R.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new P(3),t=new P(3),s=new P(3);return(i,r)=>{e[0]=i[0],e[1]=i[1],e[2]=i[2],t[0]=i[3],t[1]=i[4],t[2]=i[5];const n=R.subVec3(t,e,s),A=r[0]-i[0],o=i[3]-r[0],a=r[1]-i[1],l=i[4]-r[1],c=r[2]-i[2],h=i[5]-r[2];return n[0]+=A>o?A:o,n[1]+=a>l?a:l,n[2]+=c>h?c:h,Math.abs(R.lenVec3(n))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||R.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||R.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=R.AABB3())=>(e[0]=R.MAX_DOUBLE,e[1]=R.MAX_DOUBLE,e[2]=R.MAX_DOUBLE,e[3]=R.MIN_DOUBLE,e[4]=R.MIN_DOUBLE,e[5]=R.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=R.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 P(3);return(t,s,i)=>{s=s||R.AABB3();let r,n,A,o=R.MAX_DOUBLE,a=R.MAX_DOUBLE,l=R.MAX_DOUBLE,c=R.MIN_DOUBLE,h=R.MIN_DOUBLE,u=R.MIN_DOUBLE;for(let s=0,d=t.length;s<d;s+=3)i?(e[0]=t[s+0],e[1]=t[s+1],e[2]=t[s+2],R.decompressPosition(e,i,e),r=e[0],n=e[1],A=e[2]):(r=t[s+0],n=t[s+1],A=t[s+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 s[0]=o,s[1]=a,s[2]=l,s[3]=c,s[4]=h,s[5]=u,s}})(),OBB3ToAABB3(e,t=R.AABB3()){let s,i,r,n=R.MAX_DOUBLE,A=R.MAX_DOUBLE,o=R.MAX_DOUBLE,a=R.MIN_DOUBLE,l=R.MIN_DOUBLE,c=R.MIN_DOUBLE;for(let t=0,h=e.length;t<h;t+=4)s=e[t+0],i=e[t+1],r=e[t+2],s<n&&(n=s),i<A&&(A=i),r<o&&(o=r),s>a&&(a=s),i>l&&(l=i),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=R.AABB3()){let s,i,r,n=R.MAX_DOUBLE,A=R.MAX_DOUBLE,o=R.MAX_DOUBLE,a=R.MIN_DOUBLE,l=R.MIN_DOUBLE,c=R.MIN_DOUBLE;for(let t=0,h=e.length;t<h;t++)s=e[t][0],i=e[t][1],r=e[t][2],s<n&&(n=s),i<A&&(A=i),r<o&&(o=r),s>a&&(a=s),i>l&&(l=i),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 P(3);return(t,s)=>{s=s||R.vec4();let i,r=0,n=0,A=0;const o=t.length;for(i=0;i<o;i++)r+=t[i][0],n+=t[i][1],A+=t[i][2];s[0]=r/o,s[1]=n/o,s[2]=A/o;let a,l=0;for(i=0;i<o;i++)a=Math.abs(R.lenVec3(R.subVec3(t[i],s,e))),a>l&&(l=a);return s[3]=l,s}})(),positions3ToSphere3:(()=>{const e=new P(3),t=new P(3);return(s,i)=>{i=i||R.vec4();let r,n=0,A=0,o=0;const a=s.length;let l=0;for(r=0;r<a;r+=3)n+=s[r],A+=s[r+1],o+=s[r+2];const c=a/3;let h;for(i[0]=n/c,i[1]=A/c,i[2]=o/c,r=0;r<a;r+=3)e[0]=s[r],e[1]=s[r+1],e[2]=s[r+2],h=Math.abs(R.lenVec3(R.subVec3(e,i,t))),h>l&&(l=h);return i[3]=l,i}})(),OBB3ToSphere3:(()=>{const e=new P(3),t=new P(3);return(s,i)=>{i=i||R.vec4();let r,n=0,A=0,o=0;const a=s.length,l=a/4;for(r=0;r<a;r+=4)n+=s[r+0],A+=s[r+1],o+=s[r+2];i[0]=n/l,i[1]=A/l,i[2]=o/l;let c,h=0;for(r=0;r<a;r+=4)e[0]=s[r+0],e[1]=s[r+1],e[2]=s[r+2],c=Math.abs(R.lenVec3(R.subVec3(e,i,t))),c>h&&(h=c);return i[3]=h,i}})(),getSphere3Center:(e,t=R.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=R.vec3()){let s=0,i=0,r=0;for(var n=0,A=e.length;n<A;n+=3)s+=e[n+0],i+=e[n+1],r+=e[n+2];const o=e.length/3;return t[0]=s/o,t[1]=i/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 s,i,r,n=0,A=t.length;n<A;n+=3)s=t[n],i=t[n+1],r=t[n+2],e[0]>s&&(e[0]=s),e[1]>i&&(e[1]=i),e[2]>r&&(e[2]=r),e[3]<s&&(e[3]=s),e[4]<i&&(e[4]=i),e[5]<r&&(e[5]=r);return e},collapseAABB2:(e=R.AABB2())=>(e[0]=R.MAX_DOUBLE,e[1]=R.MAX_DOUBLE,e[2]=R.MIN_DOUBLE,e[3]=R.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,s){let i,r;e[0]>0?(i=e[0]*s[0],r=e[0]*s[3]):(i=e[0]*s[3],r=e[0]*s[0]),e[1]>0?(i+=e[1]*s[1],r+=e[1]*s[4]):(i+=e[1]*s[4],r+=e[1]*s[1]),e[2]>0?(i+=e[2]*s[2],r+=e[2]*s[5]):(i+=e[2]*s[5],r+=e[2]*s[2]);if(i<=-t&&r<=-t)return-1;return i>=-t&&r>=-t?1:0},OBB3ToAABB2(e,t=R.AABB2()){let s,i,r,n,A=R.MAX_DOUBLE,o=R.MAX_DOUBLE,a=R.MIN_DOUBLE,l=R.MIN_DOUBLE;for(let t=0,c=e.length;t<c;t+=4)s=e[t+0],i=e[t+1],r=e[t+3]||1,n=1/r,s*=n,i*=n,s<A&&(A=s),i<o&&(o=i),s>a&&(a=s),i>l&&(l=i);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,s,i=e){const r=.5*(e[0]+1),n=.5*(e[1]+1),A=.5*(e[2]+1),o=.5*(e[3]+1);return i[0]=Math.floor(r*t),i[1]=s-Math.floor(o*s),i[2]=Math.floor(A*t),i[3]=s-Math.floor(n*s),i},tangentQuadraticBezier:(e,t,s,i)=>2*(1-e)*(s-t)+2*e*(i-s),tangentQuadraticBezier3:(e,t,s,i,r)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*i*(1-e)-3*e*e*i+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,s,i,r){const n=.5*(s-e),A=.5*(i-t),o=r*r;return(2*t-2*s+n+A)*(r*o)+(-3*t+3*s-2*n-A)*o+n*r+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,i){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,i)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,i,r){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,i)+this.b3p3(e,r)},triangleNormal(e,t,s,i=R.vec3()){const r=t[0]-e[0],n=t[1]-e[1],A=t[2]-e[2],o=s[0]-e[0],a=s[1]-e[1],l=s[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?(i[0]=0,i[1]=0,i[2]=0):(i[0]=c/d,i[1]=h/d,i[2]=u/d),i},rayTriangleIntersect:(()=>{const e=new P(3),t=new P(3),s=new P(3),i=new P(3),r=new P(3);return(n,A,o,a,l,c)=>{c=c||R.vec3();const h=R.subVec3(a,o,e),u=R.subVec3(l,o,t),d=R.cross3Vec3(A,u,s),p=R.dotVec3(h,d);if(p<1e-6)return null;const f=R.subVec3(n,o,i),g=R.dotVec3(f,d);if(g<0||g>p)return null;const m=R.cross3Vec3(f,h,r),_=R.dotVec3(A,m);if(_<0||g+_>p)return null;const b=R.dotVec3(u,m)/p;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 P(3),t=new P(3),s=new P(3),i=new P(3);return(r,n,A,o,a,l)=>{l=l||R.vec3(),n=R.normalizeVec3(n,e);const c=R.subVec3(o,A,t),h=R.subVec3(a,A,s),u=R.cross3Vec3(c,h,i);R.normalizeVec3(u,u);const d=-R.dotVec3(A,u),p=-(R.dotVec3(r,u)+d)/R.dotVec3(n,u);return l[0]=r[0]+p*n[0],l[1]=r[1]+p*n[1],l[2]=r[2]+p*n[2],l}})(),cartesianToBarycentric:(()=>{const e=new P(3),t=new P(3),s=new P(3);return(i,r,n,A,o)=>{const a=R.subVec3(A,r,e),l=R.subVec3(n,r,t),c=R.subVec3(i,r,s),h=R.dotVec3(a,a),u=R.dotVec3(a,l),d=R.dotVec3(a,c),p=R.dotVec3(l,l),f=R.dotVec3(l,c),g=h*p-u*u;if(0===g)return null;const m=1/g,_=(p*d-u*f)*m,b=(h*f-u*d)*m;return o[0]=1-_-b,o[1]=b,o[2]=_,o}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,i,r=R.vec3()){const n=e[0],A=e[1],o=e[2];return r[0]=t[0]*n+s[0]*A+i[0]*o,r[1]=t[1]*n+s[1]*A+i[1]*o,r[2]=t[2]*n+s[2]*A+i[2]*o,r},mergeVertices(e,t,s,i){const r={},n=[],A=[],o=t?[]:null,a=s?[]:null,l=[];let c,h,u,d;const p=1e4;let f,g,m=0;for(f=0,g=e.length;f<g;f+=3)c=e[f],h=e[f+1],u=e[f+2],d=`${Math.round(c*p)}_${Math.round(h*p)}_${Math.round(u*p)}`,void 0===r[d]&&(r[d]=A.length/3,A.push(c),A.push(h),A.push(u),t&&(o.push(t[f]),o.push(t[f+1]),o.push(t[f+2])),s&&(a.push(s[m]),a.push(s[m+1]))),n[f/3]=r[d],m+=2;for(f=0,g=i.length;f<g;f++)l[f]=n[i[f]];const _={positions:A,indices:l};return o&&(_.normals=o),a&&(_.uv=a),_},buildNormals:(()=>{const e=new P(3),t=new P(3),s=new P(3),i=new P(3),r=new P(3),n=new P(3);return(A,o,a)=>{let l,c;const h=new Array(A.length/3);let u,d,p,f,g,m,_;for(l=0,c=o.length;l<c;l+=3){u=o[l],d=o[l+1],p=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],s[0]=A[3*p],s[1]=A[3*p+1],s[2]=A[3*p+2],R.subVec3(t,e,i),R.subVec3(s,e,r);const a=R.vec3();R.normalizeVec3(R.cross3Vec3(i,r,n),a),h[u]||(h[u]=[]),h[d]||(h[d]=[]),h[p]||(h[p]=[]),h[u].push(a),h[d].push(a),h[p].push(a)}for(a=a&&a.length===A.length?a:new Float32Array(A.length),l=0,c=h.length;l<c;l++){f=h[l].length,g=0,m=0,_=0;for(let e=0;e<f;e++)g+=h[l][e][0],m+=h[l][e][1],_+=h[l][e][2];a[3*l]=g/f,a[3*l+1]=m/f,a[3*l+2]=_/f}return a}})(),buildTangents:(()=>{const e=new P(3),t=new P(3),s=new P(3),i=new P(3),r=new P(3),n=new P(3),A=new P(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),p=l.subarray(2*u,2*u+2);u=a[h+1];const f=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=R.subVec3(f,d,e),y=R.subVec3(m,d,t),B=R.subVec2(g,p,s),w=R.subVec2(_,p,i),v=1/(B[0]*w[1]-B[1]*w[0]),C=R.mulVec3Scalar(R.subVec3(R.mulVec3Scalar(b,w[1],r),R.mulVec3Scalar(y,B[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,s){const i=t.length,r=s?new Uint16Array(9*i):new Float32Array(9*i),n=new Uint8Array(12*i);let A,o,a,l,c,h,u=0,d=0,p=0;for(let s=0;s<i;s+=3)h=u>>24&255,c=u>>16&255,l=u>>8&255,a=255&u,o=t[s],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[p++]=a,n[p++]=l,n[p++]=c,n[p++]=h,o=t[s+1],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[p++]=a,n[p++]=l,n[p++]=c,n[p++]=h,o=t[s+2],A=3*o,r[d++]=e[A],r[d++]=e[A+1],r[d++]=e[A+2],n[p++]=a,n[p++]=l,n[p++]=c,n[p++]=h,u++;return{positions:r,colors:n}},faceToVertexNormals(e,t,s={}){const i=s.smoothNormalsAngleThreshold||20,r={},n=[],A={};let o,a,l,c,h;const u=1e4;let d,p,f,g,m,_;for(p=0,g=e.length;p<g;p+=3){d=p/3,a=e[p],l=e[p+1],c=e[p+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 s=R.normalizeVec3([t[p],t[p+1],t[p+2]]);n[d]=s,o=R.vec4([s[0],s[1],s[2],1]),A[d]=o}for(h in r)if(r.hasOwnProperty(h)){const e=r[h],t=e.length;for(p=0;p<t;p++){const s=e[p];for(o=A[s],f=0;f<t;f++){if(p===f)continue;const t=e[f];m=n[s],_=n[t];Math.abs(R.angleVec3(m,_)/R.DEGTORAD)<i&&(o[0]+=_[0],o[1]+=_[1],o[2]+=_[2],o[3]+=1)}}}for(p=0,g=t.length;p<g;p+=3)o=A[p/3],t[p+0]=o[0]/o[3],t[p+1]=o[1]/o[3],t[p+2]=o[2]/o[3]},transformRay:(()=>{const e=new P(4),t=new P(4);return(s,i,r,n,A)=>{e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=1,R.transformVec4(s,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],R.transformVec3(s,e,t),R.normalizeVec3(t),A[0]=t[0],A[1]=t[1],A[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new P(16),t=new P(4),s=new P(4),i=(t,s,i,r,n)=>{n[0]=t,n[1]=s,n[2]=i,n[3]=1,R.transformVec4(e,n,n),r||R.mulVec4Scalar(n,1/n[3])};return(r,n,A,o,a,l,c)=>{const h="ortho"===o;R.mulMat4(A,n,e),R.inverseMat4(e,e);const u=2*a[0]/r.clientWidth-1,d=1-2*a[1]/r.clientHeight;i(u,d,-1,h,t),i(u,d,1,h,s),l[0]=t[0],l[1]=t[1],l[2]=t[2],R.subVec3(s,t,c),R.normalizeVec3(c)}})(),canvasPosToLocalRay:(()=>{const e=new P(3),t=new P(3);return(s,i,r,n,A,o,a,l)=>{R.canvasPosToWorldRay(s,i,r,n,o,e,t),R.worldRayToLocalRay(A,e,t,a,l)}})(),worldRayToLocalRay:(()=>{const e=new P(16),t=new P(4),s=new P(4);return(i,r,n,A,o)=>{const a=R.inverseMat4(i,e);t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,R.transformVec4(a,t,s),A[0]=s[0],A[1]=s[1],A[2]=s[2],R.transformVec3(a,n,o)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,i,r,n){const A=new P(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=s.length;a<l;++a){var c=3*s[a];for(let e=0;e<3;++e){const t=3*i[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(s.length<20||n>10)return o.triangles=s,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(s.length);let p=0;const f=new Array(s.length);let g=0;for(a=0,l=s.length;a<l;++a){const e=i[c=3*s[a]],t=3*i[c+1],n=3*i[c+2];r[3*e+h]<=u||r[t+h]<=u||r[n+h]<=u?d[p++]=s[a]:f[g++]=s[a]}return d.length=p,f.length=g,o.left=t(d,i,r,n+1),o.right=t(f,i,r,n+1),o}return(e,s)=>{const i=e.length/3,r=new Array(i);for(let e=0;e<i;++e)r[e]=e;return t(r,e,s,0)}})(),decompressPosition(e,t,s){(s=s||e)[0]=e[0]*t[0]+t[12],s[1]=e[1]*t[5]+t[13],s[2]=e[2]*t[10]+t[14]},decompressPositions(e,t,s=new Float32Array(e.length)){for(let i=0,r=e.length;i<r;i+=3)s[i+0]=e[i+0]*t[0]+t[12],s[i+1]=e[i+1]*t[5]+t[13],s[i+2]=e[i+2]*t[10]+t[14];return s},decompressUV(e,t,s){s[0]=e[0]*t[0]+t[6],s[1]=e[1]*t[4]+t[7]},decompressUVs(e,t,s=new Float32Array(e.length)){for(let i=0,r=e.length;i<r;i+=3)s[i+0]=e[i+0]*t[0]+t[6],s[i+1]=e[i+1]*t[4]+t[7];return s},octDecodeVec2(e,t){let s=e[0],i=e[1];s=(2*s+1)/255,i=(2*i+1)/255;const r=1-Math.abs(s)-Math.abs(i);r<0&&(s=(1-Math.abs(i))*(s>=0?1:-1),i=(1-Math.abs(s))*(i>=0?1:-1));const n=Math.sqrt(s*s+i*i+r*r);return t[0]=s/n,t[1]=i/n,t[2]=r/n,t},octDecodeVec2s(e,t){for(let s=0,i=0,r=e.length;s<r;s+=2){let r=e[s+0],n=e[s+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[i+0]=r/o,t[i+1]=n/o,t[i+2]=A/o,i+=3}return t}};R.buildEdgeIndices=function(){const e=[],t=[],s=[],i=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=R.vec3(),c=R.vec3(),h=R.vec3(),u=R.vec3(),d=R.vec3(),p=R.vec3(),f=R.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,p=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]=p/3,e[p++]=o,e[p++]=a,e[p++]=l),t[u/3]=A[c];for(u=0,d=n.length;u<d;u++)i[u]=t[n[u]],s[i[u]]=n[u]}(g,m),function(t,s){n=0;for(let g=0,m=t;g<m;g+=3){const t=3*i[g],m=3*i[g+1],_=3*i[g+2];s?(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],R.decompressPosition(A,s,l),R.decompressPosition(o,s,c),R.decompressPosition(a,s,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]),R.subVec3(h,c,u),R.subVec3(l,c,d),R.cross3Vec3(u,d,p),R.normalizeVec3(p,f);const b=r[n]||(r[n]={normal:R.vec3()});b.normal[0]=f[0],b.normal[1]=f[1],b.normal[2]=f[2],n++}}(m.length,_);const y=[],B=Math.cos(R.DEGTORAD*b),w={};let v,C,M,E,F,x,U,I,T,P,S,D=!1;for(let e=0,t=m.length;e<t;e+=3){const t=e/3;for(let s=0;s<3;s++)v=i[e+s],C=i[e+(s+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)x=w[F],void 0!==x.face2&&(U=r[x.face1].normal,I=r[x.face2].normal,T=R.dotVec3(U,I),T>B)||(P=s[x.index1],S=s[x.index2],(!D&&P>65535||S>65535)&&(D=!0),y.push(P),y.push(S));return D?new Uint32Array(y):new Uint16Array(y)}}(),R.planeClipsPositions3=function(e,t,s,i=3){for(let r=0,n=s.length;r<n;r+=i){if(S[0]=s[r+0]-e[0],S[1]=s[r+1]-e[1],S[2]=s[r+2]-e[2],S[0]*t[0]+S[1]*t[1]+S[2]*t[2]<0)return!0}return!1},R.planeIntersectsAABB3=(e,t)=>{const s=[t[0],t[1],t[2]],i=[t[3],t[4],t[5]],r=[[s[0],s[1],s[2]],[i[0],s[1],s[2]],[s[0],i[1],s[2]],[i[0],i[1],s[2]],[s[0],s[1],i[2]],[i[0],s[1],i[2]],[s[0],i[1],i[2]],[i[0],i[1],i[2]]];let n=!1,A=!1;for(const t of r){const s=e.dist+R.dotVec3(e.dir,t);if(s>0&&(n=!0),s<0&&(A=!0),n&&A)return!0}return!1},R.makeSectionPlaneSlicer=function(){const e=R.vec2(),t=R.vec2(),s=R.vec2(),i=R.vec2(),r=R.vec3(),A=R.vec3(),o=R.vec3();R.vec3();const a=[R.vec3(),R.vec3(),R.vec3()],l=[null,null,null],c=[null,null,null],h=[null,null,null],u=[1,0,0],d=[0,1,0],p=[0,0,1],f=function(){const e=R.vec3();return(t,s)=>R.sqLenVec3(R.subVec3(t,s,e))}(),g=e=>{const t=[];for(let s=0;s<e;++s)t.push(s);return t},m=(e,t,s)=>(s[1]-e[1])*(t[0]-e[0])>(t[1]-e[1])*(s[0]-e[0]);return function(_){const b=R.vec3ApplyQuaternion(_.quaternion,u,R.vec3()),y=R.vec3ApplyQuaternion(_.quaternion,d,R.vec3()),B=R.vec3ApplyQuaternion(_.quaternion,p,R.vec3());return function(u,d={}){const p=R.subVec3(u.origin,_.pos,R.vec3()),w=R.dotVec3(B,p),v=[],C=[null],M=(e,t)=>{const s=C.length,i=new Float64Array(5);return i.set(e),t&&(R.addVec3(p,e,r),i[3]=-R.dotVec3(b,r),i[4]=R.dotVec3(y,r)),C.push(i),s},E=(e,t)=>{const s=C[e];return t[0]=s[3],t[1]=s[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],s),n=E(l[t],i);if(m(A,r,n)!==m(h,r,n)&&m(A,h,r)!==m(A,h,n))return!1;const[a,d]=r,[p,f]=n,g=o-a,_=c-d,b=p-a,y=f-d,B=(0!==b||0!==y)&&Math.abs(b*_-y*g)<1e-10?g*b+_*y:-1;if(B>=0&&B<=Math.pow(b,2)+Math.pow(y,2))return!1;d>c!=f>c&&g<_*b/y&&(u=!u)}if(!u)return!1}return!0},x={indices:[],normals:[]},U=!d.onlyPosSliceWithUV&&{indices:[],normals:[]},I=(e,t,s)=>{if(e){const i=C[t[0]];s||=R.normalizeVec3(R.cross3Vec3(R.subVec3(C[t[1]],i,r),R.subVec3(C[t[2]],i,A),r),r);for(let i=0;i<3;++i)e.indices.push(t[i]),e.normals.push(s[0],s[1],s[2])}},T=(e,t)=>{const s=3*u.indices[e];return t[0]=u.positions[s+0],t[1]=u.positions[s+1],t[2]=u.positions[s+2],t};for(let e=0;e<u.indices.length;e+=3){const t=T(e+0,a[0]),s=T(e+1,a[1]),i=T(e+2,a[2]);if(R.compareVec3(t,s)||R.compareVec3(s,i)||R.compareVec3(i,t))continue;const n=w+R.dotVec3(B,t),A=w+R.dotVec3(B,s),o=w+R.dotVec3(B,i);if(0!==n||0!==A||0!==o){const e=n*A<=0&&M(R.lerpVec3(n/(n-A),0,1,t,s,r),!0),a=A*o<=0&&M(R.lerpVec3(A/(A-o),0,1,s,i,r),!0),u=o*n<=0&&M(R.lerpVec3(o/(o-n),0,1,i,t,r),!0),p=!d.onlyPosSliceWithUV&&c;if(p&&(p[0]=M(t),p[1]=M(s),p[2]=M(i)),e?a||u:a&&u){if(v.push(e?[e,a||u]:[a,u]),p)if(0===n&&0===A)I(o>0?x:U,p);else if(0===n&&0===o)I(A>0?x:U,p);else if(0===A&&0===o)I(n>0?x:U,p);else{const t=(e?n:A)>0,s=t?x:U,i=t?U:x,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(s,[p[o[0]],r[o[0]],p[o[2]]]),I(s,[r[o[0]],r[o[1]],p[o[2]]]),I(i,[r[o[0]],p[o[1]],r[o[1]]])):(I(s,[p[o[0]],r[o[0]],r[o[2]]]),I(i,[r[o[0]],p[o[1]],p[o[2]]]),I(i,[r[o[0]],p[o[2]],r[o[2]]]))}}else p&&(n>=0&&A>=0&&o>=0?I(x,p):n<=0&&A<=0&&o<=0&&I(U,p))}}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]],s={distSq:f(C[e[0]],t),idx:-1,side:-1};if(v.forEach(((e,i)=>{const r=f(C[e[0]],t),n=f(C[e[1]],t),A=Math.min(r,n);s.distSq>A&&(s.distSq=A,s.idx=i,s.side=n<r?1:0)})),!(s.distSq<1e-20)){P.pop();break}{const i=s.idx>=0&&v[s.idx];if(C[i?i[s.side]:e[0]]=t,!i)break;{v.splice(s.idx,1);const t=i[1-s.side];if(!(f(C[t],C[e[0]])>1e-20))break;e.push(t)}}}}const S=P.filter((e=>e.length>2)).map(((s,i)=>{let r=0;const n=R.collapseAABB2(R.AABB2());for(let i=0;i<s.length;i++)E(s[i],e),R.expandAABB2Point2(n,e),E(s[(i+1)%s.length],t),r+=e[0]*t[1]-t[0]*e[1];return{boundingBox:n,doubleArea:Math.abs(r),endPoints:s}})).sort(((e,t)=>t.doubleArea-e.doubleArea));for(;S.length>0;){const t=[],s=[],i=i=>i.endPoints.forEach((i=>{E(i,e),t.push(e[0],e[1]),s.push(i)})),r=S.shift();i(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,i(e),a.push(e),S.splice(c,1)):++c}const h=n(t,a.map((e=>e.index)));for(let e=0;e<h.length;e+=3){const t=l;t[0]=s[h[e+0]],t[1]=s[h[e+1]],t[2]=s[h[e+2]];const i=C[t[0]];R.subVec3(C[t[1]],i,A),R.subVec3(C[t[2]],i,o),R.normalizeVec3(R.cross3Vec3(A,o,o),o);const r=R.dotVec3(o,B)<=0;I(r?x:U,t,o);const n=t[0];t[0]=t[2],t[2]=n,I(r?U:x,t,R.negateVec3(o,o))}}const D=e=>e&&e.indices.length>0&&function(){const t=[],s=d.onlyPosSliceWithUV&&[];return e.indices.forEach((e=>{const i=C[e];t.push(i[0],i[1],i[2]),s&&s.push(i[3],i[4])})),{indices:g(e.indices.length),positions:t,normals:e.normals,uv:s}}();return{pos:D(x),neg:D(U)}}}}();const O=new Float32Array(3);class V{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 L={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 H=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),i=s+e[1],r=s;r<i;++r)t.push(r);return String.fromCharCode.apply(null,t)})).join("");function N(e,t){return(t&&4!==t?[0,6]:[0,6,12,18]).map((function(t){return H.substr(parseInt(e/(1<<t))%64,1)})).reverse().join("")}const G=function(){for(var e={},t=window.location.search.substring(1).split("&"),s=0;s<t.length;s++){var i=t[s].split("=");if(void 0===e[i[0]])e[i[0]]=decodeURIComponent(i[1]);else if("string"==typeof e[i[0]]){var r=[e[i[0]],decodeURIComponent(i[1])];e[i[0]]=r}else e[i[0]].push(decodeURIComponent(i[1]))}return e}();const j={xmlToJson:function e(t,s){if(t.nodeType===t.TEXT_NODE){var i=t.nodeValue;if(null===i.match(/^\s+$/))return i}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[s[A.nodeName]||A.nodeName]=A.nodeValue}for(var o=0;o<t.childNodes.length;o++){(n=e(t.childNodes[o],s))&&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 N(t[0],2)+[1,4,7,10,13].map((function(e){return N((t[e]<<16)+(t[e+1]<<8)+t[e+2])})).join("")},findNodeOfType:function(e,t){var s=[],i=function(e){e.type===t&&s.push(e),(e.children||[]).forEach((function(e){i(e)}))};return i(e),s},timeout:function(e){return new Promise((function(t,s){setTimeout(t,e)}))},httpRequest:function(e){return new Promise((function(t,s){var i=new XMLHttpRequest;i.open(e.method||"GET",e.url,!0),i.onload=function(e){4===i.readyState&&(200===i.status?t(i.responseXML):s(i.statusText))},i.send(null)}))},loadJSON:function(e,t,s){var i=e=>{};t=t||i,s=s||i;var r=new XMLHttpRequest;r.overrideMimeType("application/json"),r.open("GET",e,!0),r.addEventListener("load",(function(e){var i=e.target.response;if(200===this.status){var r;try{r=JSON.parse(i)}catch(e){s(`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(i))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),r.addEventListener("error",(function(e){s(e)}),!1),r.send(null)},loadArraybuffer:function(e,t,s){var i=e=>{};t=t||i,s=s||i;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),s=new Uint8Array(e);for(var A=0;A<n.length;A++)s[A]=n.charCodeAt(A);q.scheduleTask((()=>{t(e)}))}catch(e){q.scheduleTask((()=>{s(e)}))}}else{const i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onreadystatechange=function(){4===i.readyState&&(200===i.status?t(i.response):s("loadArrayBuffer error : "+i.response))},i.send(null)}},queryString:G,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 j.isString(e)||j.isNumeric(e)},isSameComponent:function(e,t){return!(!e||!t)&&(j.isNumeric(e)||j.isString(e)?`${e}`:e.id)===(j.isNumeric(t)||j.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 j.apply(e,{})},apply:function(e,t){for(const s in e)e.hasOwnProperty(s)&&(t[s]=e[s]);return t},apply2:function(e,t){for(const s in e)e.hasOwnProperty(s)&&void 0!==e[s]&&null!==e[s]&&(t[s]=e[s]);return t},applyIf:function(e,t){for(const s in e)e.hasOwnProperty(s)&&(void 0!==t[s]&&null!==t[s]||(t[s]=e[s]));return t},isEmptyObject:function(e){for(const t in e)if(e.hasOwnProperty(t))return!1;return!0},inQuotes:function(e){return j.isNumeric(e)?`${e}`:`'${e}'`},concat:function(e,t){const s=new e.constructor(e.length+t.length);return s.set(e),s.set(t,e.length),s},flattenParentChildHierarchy:function(e){var t=[];return function e(s){s.id=s.uuid,delete s.oid,t.push(s);var i=s.children;if(i)for(var r=0,n=i.length;r<n;r++){i[r].parent=s.id,e(i[r])}s.children=[]}(e),t}},z={},W=new e,X=new V,K={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},Z=[];let J,Y=0,$=0;const q=new function(){this.version="1.0.0",this.scenes={},this._superTypes={},this._addScene=function(e){if(e.id){if(q.scenes[e.id])return void console.error(`[ERROR] Scene ${j.inQuotes(e.id)} already exists`)}else e.id=W.addItem({});q.scenes[e.id]=e;const t=e.ticksPerOcclusionTest,s=e.ticksPerRender;z[e.id]={ticksPerOcclusionTest:t,ticksPerRender:s,renderCountdown:s},L.components.scenes++,e.once("destroyed",(()=>{W.removeItem(e.id),delete q.scenes[e.id],delete z[e.id],L.components.scenes--}))},this.clear=function(){let e;for(const t in q.scenes)q.scenes.hasOwnProperty(t)&&(e=q.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete q.scenes[e.id]))},this.scheduleTask=function(e,t=null){X.push(e),X.push(t)},this.runTasks=function(e=-1){let t,s,i=(new Date).getTime(),r=0;for(;X.length>0&&(e<0||i<e);)t=X.shift(),s=X.shift(),s?t.call(s):t(),i=(new Date).getTime(),r++;return r},this.getNumTasks=function(){return X.length}},ee=function(){let e=Date.now();if(J=e-Y,Y>0&&J>0){var t=1e3/J;$+=t,Z.push(t),Z.length>=30&&($-=Z.shift()),L.frame.fps=Math.round($/Z.length)}for(let e in q.scenes)q.scenes[e].compile();se(e),Y=e};!function(e,t){let s=Date.now()+t;(function i(){const r=Date.now()-s;e(),s+=t,setTimeout(i,Math.max(0,t-r))})()}((()=>{ee()}),100);const te=function(){let e=Date.now();if(J=e-Y,Y>0&&J>0){var t=1e3/J;$+=t,Z.push(t),Z.length>=30&&($-=Z.shift()),L.frame.fps=Math.round($/Z.length)}se(e),function(e){for(var t in K.time=e,q.scenes)if(q.scenes.hasOwnProperty(t)){var s=q.scenes[t];K.sceneId=t,K.startTime=s.startTime,K.deltaTime=null!=K.prevTime?K.time-K.prevTime:0,s.fire("tick",K,!0)}K.prevTime=e}(e),function(){const e=q.scenes,t=!1;let s,i,r,n,A;for(A in e)e.hasOwnProperty(A)&&(s=e[A],i=z[A],i||(i=z[A]={}),r=s.ticksPerOcclusionTest,i.ticksPerOcclusionTest!==r&&(i.ticksPerOcclusionTest=r,i.renderCountdown=r),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=r),n=s.ticksPerRender,i.ticksPerRender!==n&&(i.ticksPerRender=n,i.renderCountdown=n),0==--i.renderCountdown&&(s.render(t),i.renderCountdown=n))}(),void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(ee):requestAnimationFrame(te)};function se(e){const t=q.runTasks(e+10),s=q.getNumTasks();L.frame.tasksRun=t,L.frame.tasksScheduled=s,L.frame.tasksBudget=10}te();class ie{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 ie))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,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const i=this._eventSubs[e];let r;if(i)for(const s in i)i.hasOwnProperty(s)&&(r=i[s],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,s,i){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:s,scope:i||this},this._subIdEvents[n]=t;const A=this._events[t];return void 0!==A&&s.call(i||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 s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const i=this,r=this.on(e,(function(e){i.off(r),t.call(s||this,e)}),s)}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+" "+j.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 s=e.component;const i=e.sceneDefault,r=e.sceneSingleton,n=e.type,A=e.on,o=!1!==e.recompiles;if(s&&(j.isNumeric(s)||j.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+j.inQuotes(e))}if(!s)if(!0===r){const e=this.scene.types[n];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===i&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+j.inQuotes(s.id));if(n&&!s.isType(n))return void this.error("Expected a "+n+" type or subtype: "+s.type+" "+j.inQuotes(s.id))}this._attachments||(this._attachments={});const a=this._attached[t];let l,c,h;if(a){if(s&&a.id===s.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 i=e.params.onDetached;i&&(j.isFunction(i)?i(a):i.scope?i.callback.call(i.scope,a):i.callback(a)),e.managingLifecycle&&a.destroy()}if(s){const i={params:e,component:s,subs:[],managingLifecycle:false};i.subs.push(s.once("destroyed",(function(){i.params.component=null,this._attach(i.params)}),this)),o&&i.subs.push(s.on("dirty",(function(){this.fire("dirty",this)}),this)),this._attached[t]=s,this._attachments[s.id]=i;const r=e.onAttached;if(r&&(j.isFunction(r)?r(s):r.scope?r.callback.call(r.scope,s):r.callback(s)),A){let e,t,r,n;for(e in A)if(A.hasOwnProperty(e)){if(t=A[e],j.isFunction(t)?(r=t,n=null):(r=t.callback,n=t.scope),!r)continue;i.subs.push(s.on(e,r,n))}}}return o&&this.fire("dirty",this),this.fire(t,s),s}_checkComponent(e,t){if(!t.isComponent){if(!j.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(!j.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 s=0,i=e.length;s<i;s++)if(e[s]===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():q.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}scheduleTask(e){q.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,s,i,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],s=t.component,i=t.subs,r=0,n=i.length;r<n;r++)s.off(i[r]);t.managingLifecycle&&s.destroy()}if(this._ownedComponents)for(e in this._ownedComponents)this._ownedComponents.hasOwnProperty(e)&&(s=this._ownedComponents[e],s.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 re=R.vec3(),ne=R.vec3(),Ae=R.mat4();class oe{constructor(){this.normal=R.vec3(),this.offset=0,this.testVertex=R.vec3()}set(e,t,s,i){const r=1/Math.sqrt(e*e+t*t+s*s);this.normal[0]=e*r,this.normal[1]=t*r,this.normal[2]=s*r,this.offset=i*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 ae{constructor(){this.planes=[new oe,new oe,new oe,new oe,new oe,new oe]}}function le(e,t,s){const i=R.mulMat4(s,t,Ae),r=i[0],n=i[1],A=i[2],o=i[3],a=i[4],l=i[5],c=i[6],h=i[7],u=i[8],d=i[9],p=i[10],f=i[11],g=i[12],m=i[13],_=i[14],b=i[15];e.planes[0].set(o-r,h-a,f-u,b-g),e.planes[1].set(o+r,h+a,f+u,b+g),e.planes[2].set(o-n,h-l,f-d,b-m),e.planes[3].set(o+n,h+l,f+d,b+m),e.planes[4].set(o-A,h-c,f-p,b-_),e.planes[5].set(o+A,h+c,f+p,b+_)}function ce(e,t){let s=ae.INSIDE;const i=re,r=ne;i[0]=t[0],i[1]=t[1],i[2]=t[2],r[0]=t[3],r[1]=t[4],r[2]=t[5];const n=[i,r];for(let t=0;t<6;++t){const i=e.planes[t];if(i.normal[0]*n[i.testVertex[0]][0]+i.normal[1]*n[i.testVertex[1]][1]+i.normal[2]*n[i.testVertex[2]][2]+i.offset<0)return ae.OUTSIDE;i.normal[0]*n[1-i.testVertex[0]][0]+i.normal[1]*n[1-i.testVertex[1]][1]+i.normal[2]*n[1-i.testVertex[2]][2]+i.offset<0&&(s=ae.INTERSECT)}return s}ae.INSIDE=0,ae.INTERSECT=1,ae.OUTSIDE=2;class he extends ie{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=R.vec2(),this._canvasMarqueeCorner2=R.vec2(),this._canvasMarquee=R.AABB2(),this._marqueeFrustum=new ae,this._marqueeFrustumProjMat=R.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!==he.PICK_MODE_INSIDE&&e!==he.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===he.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=(s,i=ae.INTERSECT)=>{if(i===ae.INTERSECT&&(i=ce(this._marqueeFrustum,s.aabb)),i!==ae.OUTSIDE){if(s.entities){const t=s.entities;for(let s=0,i=t.length;s<i;s++){const i=t[s];if(!i.visible)continue;const r=i.aabb;if(this._pickMode===he.PICK_MODE_INSIDE){ce(this._marqueeFrustum,r)===ae.INSIDE&&e.push(i.id)}else{ce(this._marqueeFrustum,r)!==ae.OUTSIDE&&e.push(i.id)}}}s.left&&t(s.left,i),s.right&&t(s.right,i)}};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,s=e.clientHeight,i=e.clientLeft,r=e.clientTop,n=2/t,A=2/s,o=e.clientHeight/e.clientWidth,a=(this._canvasMarquee[0]-i)*n-1,l=(this._canvasMarquee[2]-i)*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);R.frustumMat4(a,l,c*o,h*o,u,1e4,this._marqueeFrustumProjMat),le(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)}}he.PICK_MODE_INTERSECTS=0,he.PICK_MODE_INSIDE=1;class ue{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 s;const i=e=>{if(!this._running)return;s||(s=e);const r=e-s,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(i)};this._running=!0,requestAnimationFrame(i),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 de{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 s=this._messages[this._locale];if(!s)return null;const i=pe(e,s);return i?t?fe(i,t):i:null}translatePlurals(e,t,s){const i=this._messages[this._locale];if(!i)return null;let r=pe(e,i);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=fe(r,[t]),s&&(r=fe(r,s)),r):null}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={}),!0!==s&&(this._events[e]=t||!0);const i=this._eventSubs[e];if(i)for(const e in i)if(i.hasOwnProperty(e)){i[e].callback(t)}}on(t,s){this._events||(this._events={}),this._eventSubIDMap||(this._eventSubIDMap=new e),this._eventSubEvents||(this._eventSubEvents={}),this._eventSubs||(this._eventSubs={});let i=this._eventSubs[t];i||(i={},this._eventSubs[t]=i);const r=this._eventSubIDMap.addItem();i[r]={callback:s},this._eventSubEvents[r]=t;const n=this._events[t];return void 0!==n&&s(n),r}off(e){if(null==e)return;if(!this._eventSubEvents)return;const t=this._eventSubEvents[e];if(t){delete this._eventSubEvents[e];const s=this._eventSubs[t];s&&delete s[e],this._eventSubIDMap.removeItem(e)}}}function pe(e,t){if(t[e])return t[e];const s=e.split(".");let i=t;for(let e=0,t=s.length;i&&e<t;e++){i=i[s[e]]}return i}function fe(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,s){return"{{"===e?"{":"}}"===e?"}":t[s]}))}class ge extends ie{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 s=e-t,i=e+t;s<0&&(s=0),i>1&&(i=1);var r=this.getPoint(s),n=this.getPoint(i),A=R.subVec3(n,r,[]);return R.normalizeVec3(A,[])}getPointAt(e){var t=this.getUToTMapping(e);return this.getPoint(t)}getPoints(e){e||(e=5);var t,s=[];for(t=0;t<=e;t++)s.push(this.getPoint(t/e));return s}_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,s,i=[],r=this.getPoint(0),n=0;for(i.push(0),s=1;s<=e;s++)t=this.getPoint(s/e),n+=R.lenVec3(R.subVec3(t,r,[])),i.push(n),r=t;return this.cacheArcLengths=i,i}_updateArcLengths(){this.needsUpdate=!0,this._getLengths()}getUToTMapping(e,t){var s,i=this._getLengths(),r=0,n=i.length;s=t||e*i[n-1];for(var A,o=0,a=n-1;o<=a;)if((A=i[r=Math.floor(o+(a-o)/2)]-s)<0)o=r+1;else{if(!(A>0)){a=r;break}a=r-1}if(i[r=a]===s)return r/(n-1);var l=i[r];return(r+(s-l)/(i[r+1]-l))/(n-1)}}class me extends ge{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 s=(t.length-1)*e,i=Math.floor(s),r=s-i,n=t[0===i?i:i-1],A=t[i],o=t[i>t.length-2?t.length-1:i+1],a=t[i>t.length-3?t.length-1:i+2],l=R.vec3();return l[0]=R.catmullRomInterpolate(n[0],A[0],o[0],a[0],r),l[1]=R.catmullRomInterpolate(n[1],A[1],o[1],a[1],r),l[2]=R.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 _e=R.vec3();const be=R.vec3(),ye=R.vec3(),Be=R.vec3(),we=R.vec3(),ve=R.vec3();class Ce extends ie{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=R.vec3(),this._eye1=R.vec3(),this._up1=R.vec3(),this._look2=R.vec3(),this._eye2=R.vec3(),this._up2=R.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,s){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=s;const i=this.scene.camera,r=!!e.projection&&e.projection!==i.projection;let n,A,o,a,l;if(this._eye1[0]=i.eye[0],this._eye1[1]=i.eye[1],this._eye1[2]=i.eye[2],this._look1[0]=i.look[0],this._look1[1]=i.look[1],this._look1[2]=i.look[2],this._up1[0]=i.up[0],this._up1[1]=i.up[1],this._up1[2]=i.up[2],this._orthoScale1=i.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 i=e;if((j.isNumeric(i)||j.isString(i))&&(l=i,i=this.scene.components[l],!i))return this.error("Component not found: "+j.inQuotes(l)),void(t&&(s?t.call(s):t()));r||(n=i.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=R.getAABB3Center(n);this._look2=c||t;const s=R.subVec3(this._eye1,this._look1,be),i=R.normalizeVec3(s),r=c?R.getAABB3DiagPoint(n,c):R.getAABB3Diag(n),A=e.fitFOV||this._fitFOV,o=Math.abs(r/Math.tan(A*R.DEGTORAD));this._orthoScale2=1.1*r,this._eye2[0]=this._look2[0]+i[0]*o,this._eye2[1]=this._look2[1]+i[1]*o,this._eye2[2]=this._look2[2]+i[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"!==i.projection&&(this._projection2="ortho",this._projMatrix1=i.projMatrix.slice(),this._projMatrix2=i.ortho.matrix.slice(),i.projection="customProjection"),"perspective"===e.projection&&"perspective"!==i.projection&&(this._projection2="perspective",this._projMatrix1=i.projMatrix.slice(),this._projMatrix2=i.perspective.matrix.slice(),i.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,q.scheduleTask(this._update,this)}jumpTo(e){this._jumpTo(e)}_jumpTo(e){this._flying&&this.stop();const t=this.scene.camera;var s,i,r,n,A;if(e.aabb)s=e.aabb;else if(6===e.length)s=e;else if(e.eye||e.look||e.up)r=e.eye,n=e.look,A=e.up;else{let t=e;if((j.isNumeric(t)||j.isString(t))&&(i=t,t=this.scene.components[i],!t))return void this.error("Component not found: "+j.inQuotes(i));s=t.aabb||this.scene.aabb}const o=e.poi;if(s){if(s[3]<=s[0]||s[4]<=s[1]||s[5]<=s[2])return;var a=o?R.getAABB3DiagPoint(s,o):R.getAABB3Diag(s);let i;n=o||R.getAABB3Center(s,n),this._trail?R.subVec3(t.look,n,ve):R.subVec3(t.eye,t.look,ve),R.normalizeVec3(ve);i=(void 0!==e.fit?e.fit:this._fit)?Math.abs(a/Math.tan((e.fitFOV||this._fitFOV)*R.DEGTORAD)):R.lenVec3(R.subVec3(t.eye,t.look,be)),R.mulVec3Scalar(ve,i),t.eye=R.addVec3(n,ve,be),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 s=this.easing?Ce._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(R.subVec3(i.eye,i.look,ve),i.eye=R.lerpVec3(s,0,1,this._eye1,this._eye2,Be),i.look=R.subVec3(Be,ve,ye)):this._flyingLook&&(i.look=R.lerpVec3(s,0,1,this._look1,this._look2,ye),i.up=R.lerpVec3(s,0,1,this._up1,this._up2,we)):this._flyingEyeLookUp&&(i.eye=R.lerpVec3(s,0,1,this._eye1,this._eye2,Be),i.look=R.lerpVec3(s,0,1,this._look1,this._look2,ye),i.up=R.lerpVec3(s,0,1,this._up1,this._up2,we)),this._projection2){const t="ortho"===this._projection2?Ce._easeOutExpo(e,0,1,1):Ce._easeInCubic(e,0,1,1);i.customProjection.matrix=R.lerpMat4(t,0,1,this._projMatrix1,this._projMatrix2)}else i.ortho.scale=this._orthoScale1+e*(this._orthoScale2-this._orthoScale1);if(t)return i.ortho.scale=this._orthoScale2,void this.stop();q.scheduleTask(this._update,this)}static _ease(e,t,s,i){return-s*(e/=i)*(e-2)+t}static _easeInCubic(e,t,s,i){return s*(e/=i)*e*e+t}static _easeOutExpo(e,t,s,i){return s*(1-Math.pow(2,-10*e/i))+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 Me extends ie{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new Ce(this),this._t=0,this.state=Me.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,s;const i=performance.now(),r=this._lastTime?.001*(i-this._lastTime):0;if(this._lastTime=i,0!==r)switch(this.state){case Me.SCRUBBING:return;case Me.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=Me.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case Me.PLAYING_TO:s=this._t+this._playingRate*r*this._playingDir,(this._playingDir<0&&s<=this._playingToT||this._playingDir>0&&s>=this._playingToT)&&(s=this._playingToT,this.state=Me.SCRUBBING,this.fire("stopped")),this._t=s,e.loadFrame(this._t)}}_ease(e,t,s,i){return-s*(e/=i)*(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=Me.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=Me.PLAYING_TO)}playToFrame(e){const t=this._cameraPath;if(!t)return;const s=t.frames[e];s?this.playToT(s.t):this.error("playToFrame - frame index out of range: "+e)}flyToFrame(e,t){const s=this._cameraPath;if(!s)return;const i=s.frames[e];i?(this.state=Me.SCRUBBING,this._cameraFlightAnimation.flyTo(i,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=Me.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=Me.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=Me.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}Me.STOPPED=0,Me.SCRUBBING=1,Me.PLAYING=2,Me.PLAYING_TO=3;class Ee extends ie{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),L.memory.meshes++}destroy(){super.destroy(),L.memory.meshes--}}const Fe=new e({});class xe{constructor(e){this.id=Fe.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Fe.removeItem(this.id)}}class Ue{constructor(e,t,s,i,r,n,A,o,a){switch(this._gl=e,this.type=t,this.allocated=!1,s.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=i,this.numItems=0,this.itemSize=r,this.normalized=!!A,this.stride=o||0,this.offset=a||0,this._allocate(s)}_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 Ie=function(){const e=[],t=[],s=[],i=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=R.vec3(),c=R.vec3(),h=R.vec3(),u=R.vec3(),d=R.vec3(),p=R.vec3(),f=R.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,p=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]=p/3,e[p++]=o,e[p++]=a,e[p++]=l),t[u/3]=A[c];for(u=0,d=n.length;u<d;u++)i[u]=t[n[u]],s[i[u]]=n[u]}(g,m),function(t,s){n=0;for(let g=0,m=t;g<m;g+=3){const t=3*i[g],m=3*i[g+1],_=3*i[g+2];s?(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],R.decompressPosition(A,s,l),R.decompressPosition(o,s,c),R.decompressPosition(a,s,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]),R.subVec3(h,c,u),R.subVec3(l,c,d),R.cross3Vec3(u,d,p),R.normalizeVec3(p,f);const b=r[n]||(r[n]={normal:R.vec3()});b.normal[0]=f[0],b.normal[1]=f[1],b.normal[2]=f[2],n++}}(m.length,_);const y=[],B=Math.cos(R.DEGTORAD*b),w={};let v,C,M,E,F,x,U,I,T,P,S,D=!1;for(let e=0,t=m.length;e<t;e+=3){const t=e/3;for(let s=0;s<3;s++)v=i[e+s],C=i[e+(s+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)x=w[F],void 0!==x.face2&&(U=r[x.face1].normal,I=r[x.face2].normal,T=R.dotVec3(U,I),T>B)||(P=s[x.index1],S=s[x.index2],(!D&&P>65535||S>65535)&&(D=!0),y.push(P),y.push(S));return D?new Uint32Array(y):new Uint16Array(y)}}();const Te=function(){const e=R.mat4(),t=R.mat4();return function(s,i){i=i||R.mat4();const r=s[0],n=s[1],A=s[2],o=s[3]-r||1,a=s[4]-n||1,l=s[5]-A||1,c=65535;return R.identityMat4(e),R.translationMat4v(s,e),R.identityMat4(t),R.scalingMat4v([o/c,a/c,l/c],t),R.mulMat4(e,t,i),i}}();var Pe=function(){const e=R.mat4(),t=R.mat4();return function(s,i,r){const n=new Uint16Array(s.length),A=new Float32Array([r[0]!==i[0]?65535/(r[0]-i[0]):0,r[1]!==i[1]?65535/(r[1]-i[1]):0,r[2]!==i[2]?65535/(r[2]-i[2]):0]);let o;for(o=0;o<s.length;o+=3)n[o+0]=Math.max(0,Math.min(65535,Math.floor((s[o+0]-i[0])*A[0]))),n[o+1]=Math.max(0,Math.min(65535,Math.floor((s[o+1]-i[1])*A[1]))),n[o+2]=Math.max(0,Math.min(65535,Math.floor((s[o+2]-i[2])*A[2])));R.identityMat4(e),R.translationMat4v(i,e),R.identityMat4(t),R.scalingMat4v([(r[0]-i[0])/65535,(r[1]-i[1])/65535,(r[2]-i[2])/65535],t);return{quantized:n,decodeMatrix:R.mulMat4(e,t,R.identityMat4())}}}();var Se=function(){const e=R.mat3(),t=R.mat3();return function(s,i,r){const n=new Uint16Array(s.length),A=new Float32Array([65535/(r[0]-i[0]),65535/(r[1]-i[1])]);let o;for(o=0;o<s.length;o+=2)n[o+0]=Math.max(0,Math.min(65535,Math.floor((s[o+0]-i[0])*A[0]))),n[o+1]=Math.max(0,Math.min(65535,Math.floor((s[o+1]-i[1])*A[1])));R.identityMat3(e),R.translationMat3v(i,e),R.identityMat3(t),R.scalingMat3v([(r[0]-i[0])/65535,(r[1]-i[1])/65535],t);return{quantized:n,decodeMatrix:R.mulMat3(e,t,R.identityMat3())}}}();function De(e,t,s,i){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[s](127.5*r+(r<0?-1:0)),Math[i](127.5*n+(n<0?-1:0))])}function ke(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const i=1-Math.abs(t)-Math.abs(s);i<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const r=Math.sqrt(t*t+s*s+i*i);return[t/r,s/r,i/r]}function Qe(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const Re={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let i,r;for(i=0;i<3;i++)t[i]=Number.MAX_VALUE,s[i]=-Number.MAX_VALUE;for(i=0;i<e.length;i+=3)for(r=0;r<3;r++)t[r]=Math.min(t[r],e[i+r]),s[r]=Math.max(s[r],e[i+r]);return{min:t,max:s}},createPositionsDecodeMatrix:Te,compressPositions:Pe,compressPosition:function(e,t,s){const i=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]);s[0]=Math.max(0,Math.min(65535,Math.floor((e[0]-t[0])*i[0]))),s[1]=Math.max(0,Math.min(65535,Math.floor((e[1]-t[1])*i[1]))),s[2]=Math.max(0,Math.min(65535,Math.floor((e[2]-t[2])*i[2])))},decompressPositions:function(e,t,s=new Float32Array(e.length)){for(let i=0,r=e.length;i<r;i+=3)s[i+0]=e[i+0]*t[0]+t[12],s[i+1]=e[i+1]*t[5]+t[13],s[i+2]=e[i+2]*t[10]+t[14];return s},decompressPosition:function(e,t,s){return s[0]=e[0]*t[0]+t[12],s[1]=e[1]*t[5]+t[13],s[2]=e[2]*t[10]+t[14],s},decompressAABB:function(e,t,s=e){return s[0]=e[0]*t[0]+t[12],s[1]=e[1]*t[5]+t[13],s[2]=e[2]*t[10]+t[14],s[3]=e[3]*t[0]+t[12],s[4]=e[4]*t[5]+t[13],s[5]=e[5]*t[10]+t[14],s},getUVBounds:function(e){const t=new Float32Array(2),s=new Float32Array(2);let i,r;for(i=0;i<2;i++)t[i]=Number.MAX_VALUE,s[i]=-Number.MAX_VALUE;for(i=0;i<e.length;i+=2)for(r=0;r<2;r++)t[r]=Math.min(t[r],e[i+r]),s[r]=Math.max(s[r],e[i+r]);return{min:t,max:s}},compressUVs:Se,decompressUVs:function(e,t,s=new Float32Array(e.length)){for(let i=0,r=e.length;i<r;i+=3)s[i+0]=e[i+0]*t[0]+t[6],s[i+1]=e[i+1]*t[4]+t[7];return s},decompressUV:function(e,t,s){s[0]=e[0]*t[0]+t[6],s[1]=e[1]*t[4]+t[7]},compressNormals:function(e){const t=new Int8Array(e.length);let s,i,r,n,A;for(let o=0;o<e.length;o+=3)r=s=De(e,o,"floor","floor"),i=ke(s),n=A=Qe(e,o,i),s=De(e,o,"ceil","floor"),i=ke(s),n=Qe(e,o,i),n>A&&(r=s,A=n),s=De(e,o,"floor","ceil"),i=ke(s),n=Qe(e,o,i),n>A&&(r=s,A=n),s=De(e,o,"ceil","ceil"),i=ke(s),n=Qe(e,o,i),n>A&&(r=s,A=n),t[o]=r[0],t[o+1]=r[1];return t},decompressNormals:function(e,t){for(let s=0,i=0,r=e.length;s<r;s+=2){let r=e[s+0],n=e[s+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[i+0]=r/o,t[i+1]=n/o,t[i+2]=A/o,i+=3}return t},decompressNormal:function(e,t){let s=e[0],i=e[1];s=(2*s+1)/255,i=(2*i+1)/255;const r=1-Math.abs(s)-Math.abs(i);r<0&&(s=(1-Math.abs(i))*(s>=0?1:-1),i=(1-Math.abs(s))*(i>=0?1:-1));const n=Math.sqrt(s*s+i*i+r*r);return t[0]=s/n,t[1]=i/n,t[2]=r/n,t}},Oe=L.memory,Ve=R.AABB3();class Le extends Ee{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new xe({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 s=this._state,i=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=i.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=i.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=i.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=i.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=i.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=i.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=i.TRIANGLE_FAN,s.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'."),s.primitive=i.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=Re.getPositionsBounds(t.positions),i=Re.compressPositions(t.positions,e.min,e.max);s.positions=i.quantized,s.positionsDecodeMatrix=i.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=Re.getUVBounds(t.uv),i=Re.compressUVs(t.uv,e.min,e.max);s.uv=i.quantized,s.uvDecodeMatrix=i.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);if(t.normals&&(this._state.compressGeometry?s.normals=Re.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.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(),Oe.meshes++,s.indices&&(s.indicesBuf=new Ue(i,i.ELEMENT_ARRAY_BUFFER,s.indices,s.indices.length,1,i.STATIC_DRAW),Oe.indices+=s.indicesBuf.numItems),s.positions&&(s.positionsBuf=new Ue(i,i.ARRAY_BUFFER,s.positions,s.positions.length,3,i.STATIC_DRAW),Oe.positions+=s.positionsBuf.numItems),s.normals){let e=s.compressGeometry;s.normalsBuf=new Ue(i,i.ARRAY_BUFFER,s.normals,s.normals.length,3,i.STATIC_DRAW,e),Oe.normals+=s.normalsBuf.numItems}s.colors&&(s.colorsBuf=new Ue(i,i.ARRAY_BUFFER,s.colors,s.colors.length,4,i.STATIC_DRAW),Oe.colors+=s.colorsBuf.numItems),s.uv&&(s.uvBuf=new Ue(i,i.ARRAY_BUFFER,s.uv,s.uv.length,2,i.STATIC_DRAW),Oe.uvs+=s.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,s=Ie(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new Ue(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),Oe.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=R.buildPickTriangles(e.positions,e.indices,e.compressGeometry),i=s.positions,r=s.colors;this._pickTrianglePositionsBuf=new Ue(t,t.ARRAY_BUFFER,i,i.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new Ue(t,t.ARRAY_BUFFER,r,r.length,4,t.STATIC_DRAW,!0),Oe.positions+=this._pickTrianglePositionsBuf.numItems,Oe.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),Re.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=Re.getPositionsBounds(e),i=Re.compressPositions(e,s.min,s.max);e=i.quantized,t.positionsDecodeMatrix=i.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),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),Re.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,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),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),Re.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,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),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,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),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=R.AABB3()),R.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=R.OBB3()),R.positions3ToAABB3(this._state.positions,Ve,this._state.positionsDecodeMatrix),R.AABB3ToOBB3(Ve,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,s=(s,i)=>{const r=3*e[s];for(let e=0;e<3;++e)i[e]=t[r+e];return i},i=[R.vec3(),R.vec3(),R.vec3(),R.vec3()];let r=0;const n=R.vec3([0,0,0]);for(let t=0;t<e.length;t+=3){const e=s(t,i[0]),A=s(t+1,i[1]),o=s(t+2,i[2]);R.addVec3(e,A,i[3]),R.addVec3(o,i[3],i[3]);const a=R.lenVec3(R.cross3Vec3(R.subVec3(A,e,i[1]),R.subVec3(o,e,i[2]),i[0]))/2;r+=a,R.mulVec3Scalar(i[3],a,i[3]),R.addVec3(n,i[3],n)}this._metrics={surfaceArea:r,centroid:R.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(),Oe.meshes--}}const He=L.memory,Ne=R.AABB3();class Ge extends Ee{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new xe({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=R.OBB3();const s=this._state,i=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=i.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=i.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=i.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=i.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=i.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=i.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=i.TRIANGLE_FAN,s.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'."),s.primitive=i.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(t.indices){var r;if(t.positionsDecodeMatrix);else{const e=Re.getPositionsBounds(t.positions),n=Re.compressPositions(t.positions,e.min,e.max);r=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix,s.positionsBuf=new Ue(i,i.ARRAY_BUFFER,r,r.length,3,i.STATIC_DRAW),He.positions+=s.positionsBuf.numItems,R.positions3ToAABB3(t.positions,this._aabb),R.positions3ToAABB3(r,Ne,s.positionsDecodeMatrix),R.AABB3ToOBB3(Ne,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new Ue(i,i.ARRAY_BUFFER,e,e.length,4,i.STATIC_DRAW),He.colors+=s.colorsBuf.numItems}if(t.uv){const e=Re.getUVBounds(t.uv),r=Re.compressUVs(t.uv,e.min,e.max),n=r.quantized;s.uvDecodeMatrix=r.decodeMatrix,s.uvBuf=new Ue(i,i.ARRAY_BUFFER,n,n.length,2,i.STATIC_DRAW),He.uvs+=s.uvBuf.numItems}if(t.normals){const e=Re.compressNormals(t.normals);let r=s.compressGeometry;s.normalsBuf=new Ue(i,i.ARRAY_BUFFER,e,e.length,3,i.STATIC_DRAW,r),He.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new Ue(i,i.ELEMENT_ARRAY_BUFFER,e,e.length,1,i.STATIC_DRAW),He.indices+=s.indicesBuf.numItems;const n=Ie(r,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new Ue(i,i.ELEMENT_ARRAY_BUFFER,n,n.length,1,i.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),He.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(),He.meshes--}}var je={};function ze(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let i=e.zSize||1;i<0&&(console.error("negative zSize not allowed - will invert"),i*=-1);const r=e.center,n=r?r[0]:0,A=r?r[1]:0,o=r?r[2]:0,a=-t+n,l=-s+A,c=-i+o,h=t+n,u=s+A,d=i+o;return j.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 We(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let i=e.zSize||1;i<0&&(console.error("negative zSize not allowed - will invert"),i*=-1);const r=e.center,n=r?r[0]:0,A=r?r[1]:0,o=r?r[2]:0,a=-t+n,l=-s+A,c=-i+o,h=t+n,u=s+A,d=i+o;return j.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 Xe(e={}){let t=e.radiusTop||1;t<0&&(console.error("negative radiusTop not allowed - will invert"),t*=-1);let s=e.radiusBottom||1;s<0&&(console.error("negative radiusBottom not allowed - will invert"),s*=-1);let i=e.height||1;i<0&&(console.error("negative height not allowed - will invert"),i*=-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=i/2,u=i/n,d=2*Math.PI/r,p=1/r,f=(t-s)/n,g=[],m=[],_=[],b=[];let y,B,w,v,C,M,E,F,x,U,I;const T=(90-180*Math.atan(i/(s-t))/Math.PI)/90;for(y=0;y<=n;y++)for(C=t-y*f,M=h-y*u,B=0;B<=r;B++)w=Math.sin(B*d),v=Math.cos(B*d),m.push(C*w),m.push(T),m.push(C*v),_.push(B*p),_.push(1*y/n),g.push(C*w+a),g.push(M+l),g.push(C*v+c);for(y=0;y<n;y++)for(B=0;B<=r;B++)E=y*(r+1)+B,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(x=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),B=0;B<=r;B++)w=Math.sin(B*d),v=Math.cos(B*d),U=.5*Math.sin(B*d)+.5,I=.5*Math.cos(B*d)+.5,m.push(t*w),m.push(1),m.push(t*v),_.push(U),_.push(I),g.push(t*w+a),g.push(h+l),g.push(t*v+c);for(B=0;B<r;B++)o=x,E=x+1+B,b.push(E),b.push(E+1),b.push(o)}if(!A&&s>0){for(x=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),B=0;B<=r;B++)w=Math.sin(B*d),v=Math.cos(B*d),U=.5*Math.sin(B*d)+.5,I=.5*Math.cos(B*d)+.5,m.push(s*w),m.push(-1),m.push(s*v),_.push(U),_.push(I),g.push(s*w+a),g.push(0-h+l),g.push(s*v+c);for(B=0;B<r;B++)o=x,E=x+1+B,b.push(o),b.push(E+1),b.push(E)}return j.apply(e,{positions:g,normals:m,uv:_,indices:b})}function Ke(e={}){let t=e.size||1;t<0&&(console.error("negative size not allowed - will invert"),t*=-1);let s=e.divisions||1;s<0&&(console.error("negative divisions not allowed - will invert"),s*=-1),s<1&&(s=1),t=t||10,s=s||10;const i=t/s,r=t/2,n=[],A=[];let o=0;for(let e=0,t=-r;e<=s;e++,t+=i)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 j.apply(e,{primitive:"lines",positions:n,indices:A})}function Ze(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.zSize||1;s<0&&(console.error("negative zSize not allowed - will invert"),s*=-1);let i=e.xSegments||1;i<0&&(console.error("negative xSegments not allowed - will invert"),i*=-1),i<1&&(i=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=s/2,h=Math.floor(i)||1,u=Math.floor(r)||1,d=h+1,p=u+1,f=t/h,g=s/u,m=new Float32Array(d*p*3),_=new Float32Array(d*p*3),b=new Float32Array(d*p*2);let y,B,w,v,C,M,E,F=0,x=0;for(y=0;y<p;y++){const e=y*g-c;for(B=0;B<d;B++)w=B*f-l,m[F]=w+A,m[F+1]=o,m[F+2]=-e+a,_[F+1]=1,b[x]=B/h,b[x+1]=(u-y)/u,F+=3,x+=2}F=0;const U=new(m.length/3>65535?Uint32Array:Uint16Array)(h*u*6);for(y=0;y<u;y++)for(B=0;B<h;B++)v=B+d*y,C=B+d*(y+1),M=B+1+d*(y+1),E=B+1+d*y,U[F]=E,U[F+1]=C,U[F+2]=v,U[F+3]=E,U[F+4]=M,U[F+5]=C,F+=6;return j.apply(e,{positions:m,normals:_,uv:b,indices:U})}function Je(e={}){const t=e.lod||1,s=e.center?e.center[0]:0,i=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,p,f,g,m,_,b,y,B,w,v,C,M,E;for(u=0;u<=A;u++)for(p=u*Math.PI/A,f=Math.sin(p),g=Math.cos(p),d=0;d<=o;d++)m=2*d*Math.PI/o,_=Math.sin(m),b=Math.cos(m),y=b*f,B=g,w=_*f,v=1-d/o,C=u/A,l.push(y),l.push(B),l.push(w),c.push(v),c.push(C),a.push(s+n*y),a.push(i+n*B),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 j.apply(e,{positions:a,normals:l,uv:c,indices:h})}function Ye(e={}){let t=e.radius||1;t<0&&(console.error("negative radius not allowed - will invert"),t*=-1),t*=.5;let s=e.tube||.3;s<0&&(console.error("negative tube not allowed - will invert"),s*=-1);let i=e.radialSegments||32;i<0&&(console.error("negative radialSegments not allowed - will invert"),i*=-1),i<4&&(i=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 p,f,g,m,_,b,y,B,w,v,C,M;for(B=0;B<=r;B++)for(y=0;y<=i;y++)p=y/i*n,f=.785398+B/r*Math.PI*2,o=t*Math.cos(p),a=t*Math.sin(p),g=(t+s*Math.cos(f))*Math.cos(p),m=(t+s*Math.cos(f))*Math.sin(p),_=s*Math.sin(f),c.push(g+o),c.push(m+a),c.push(_+l),u.push(1-y/i),u.push(B/r),b=R.normalizeVec3(R.subVec3([g,m,_],[o,a,l],[]),[]),h.push(b[0]),h.push(b[1]),h.push(b[2]);for(B=1;B<=r;B++)for(y=1;y<=i;y++)w=(i+1)*B+y-1,v=(i+1)*(B-1)+y-1,C=(i+1)*(B-1)+y,M=(i+1)*B+y,d.push(w),d.push(v),d.push(C),d.push(C),d.push(M),d.push(w);return j.apply(e,{positions:c,normals:h,uv:u,indices:d})}je.load=function(e,t){var s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=function(e){t(e.target.response)},s.send()},je.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(je.parse._buffToStr(e));window.location.href=s},je.clone=function(e){return JSON.parse(JSON.stringify(e))},je.bin={},je.bin.f=new Float32Array(1),je.bin.fb=new Uint8Array(je.bin.f.buffer),je.bin.rf=function(e,t){for(var s=je.bin.f,i=je.bin.fb,r=0;r<4;r++)i[r]=e[t+r];return s[0]},je.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},je.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},je.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},je.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},je.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},je.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},je.parse={},je.parse._buffToStr=function(e){for(var t=new Uint8Array(e),s="",i=0;i<t.length;i++)s=s.concat(String.fromCharCode(t[i]));return s},je.parse._strToBuff=function(e){for(var t=new ArrayBuffer(e.length),s=new Uint8Array(t),i=0;i<e.length;i++)s[i]=e.charCodeAt(i);return t},je.parse._readLine=function(e,t){for(var s="";10!=e[t];)s+=String.fromCharCode(e[t++]);return s},je.parse.fromJSON=function(e){return JSON.parse(je.parse._buffToStr(e))},je.parse.toJSON=function(e){var t=JSON.stringify(e);return je.parse._strToBuff(t)},je.parse.fromOBJ=function(e){for(var t={groups:{},c_verts:[],c_uvt:[],c_norms:[],i_verts:[],i_uvt:[],i_norms:[]},s={from:0,to:0},i=0,r=new Uint8Array(e);i<r.length;){var n=je.parse._readLine(r,i);i+=n.length+1;var A=(n=(n=n.replace(/ +(?= )/g,"")).replace(/(^\s+|\s+$)/g,"")).split(" ");if("g"==A[0]&&(s.to=t.i_verts.length,null==t.groups[A[1]]&&(t.groups[A[1]]={from:t.i_verts.length,to:0}),s=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,p=parseInt(h[0])-1,f=parseInt(u[0])-1,g=parseInt(c[1])-1,m=parseInt(h[1])-1,_=parseInt(u[1])-1,b=parseInt(c[2])-1,y=parseInt(h[2])-1,B=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),p<0&&(p=w+p+1),f<0&&(f=w+f+1),g<0&&(g=v+g+1),m<0&&(m=v+m+1),_<0&&(_=v+_+1),b<0&&(b=C+b+1),y<0&&(y=C+y+1),B<0&&(B=C+B+1),t.i_verts.push(d,p,f),t.i_uvt.push(g,m,_),t.i_norms.push(b,y,B),5==A.length){var M=A[4].split("/"),E=parseInt(M[0])-1,F=parseInt(M[1])-1,x=parseInt(M[2])-1;E<0&&(E=w+E+1),F<0&&(F=v+F+1),x<0&&(x=C+x+1),t.i_verts.push(d,f,E),t.i_uvt.push(g,_,F),t.i_norms.push(b,B,x)}}}return s.to=t.i_verts.length,t},je.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},s={};s.ident=je.bin.ril(e,0),s.version=je.bin.ril(e,4),s.skinwidth=je.bin.ril(e,8),s.skinheight=je.bin.ril(e,12),s.framesize=je.bin.ril(e,16),s.num_skins=je.bin.ril(e,20),s.num_vertices=je.bin.ril(e,24),s.num_st=je.bin.ril(e,28),s.num_tris=je.bin.ril(e,32),s.num_glcmds=je.bin.ril(e,36),s.num_frames=je.bin.ril(e,40),s.offset_skins=je.bin.ril(e,44),s.offset_st=je.bin.ril(e,48),s.offset_tris=je.bin.ril(e,52),s.offset_frames=je.bin.ril(e,56),s.offset_glcmds=je.bin.ril(e,60),s.offset_end=je.bin.ril(e,64);var i=s.offset_st;t.c_uvt=[];for(var r=0;r<s.num_st;r++){var n=je.bin.rsl(e,i)/s.skinwidth,A=je.bin.rsl(e,i+2)/s.skinheight;t.c_uvt.push(n,A),i+=4}i=s.offset_tris;var o=[],a=[];t.i_verts=o,t.i_uvt=a;for(r=0;r<s.num_tris;r++)o.push(je.bin.rsl(e,i),je.bin.rsl(e,i+2),je.bin.rsl(e,i+4)),a.push(je.bin.rsl(e,i+6),je.bin.rsl(e,i+8),je.bin.rsl(e,i+10)),i+=12;i=s.offset_skins;t.skins=[];for(r=0;r<s.num_skins;r++)t.skins.push(je.bin.rASCII0(e,i)),i+=64;i=s.offset_frames;t.frames=[];var l=je.parse.fromMD2._normals;for(r=0;r<s.num_frames;r++){var c={},h=je.bin.rf(e,i),u=je.bin.rf(e,i+4),d=je.bin.rf(e,i+8);i+=12;var p=je.bin.rf(e,i),f=je.bin.rf(e,i+4),g=je.bin.rf(e,i+8);i+=12,c.name=je.bin.rASCII0(e,i),i+=16,c.verts=[],c.norms=[];for(var m=0;m<s.num_vertices;m++)c.verts.push(e[i]*h+p,e[i+1]*u+f,e[i+2]*d+g),c.norms.push(l[3*e[i+3]],l[3*e[i+3]+1],l[3*e[i+3]+2]),i+=4;t.frames.push(c)}return t},je.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],je.parse.fromCollada=function(e){var t=je.parse._buffToStr(e),s=(new DOMParser).parseFromString(t,"text/xml"),i={},r=(s=s.childNodes[0]).getElementsByTagName("asset")[0],n=s.getElementsByTagName("library_geometries")[0],A=s.getElementsByTagName("library_images")[0],o=s.getElementsByTagName("library_materials")[0],a=s.getElementsByTagName("library_effects")[0];return r&&(i.asset=je.parse.fromCollada._asset(r)),n&&(i.geometries=je.parse.fromCollada._libGeometries(n)),A&&(i.images=je.parse.fromCollada._libImages(A)),o&&(i.materials=je.parse.fromCollada._libMaterials(o)),a&&(i.effects=je.parse.fromCollada._libEffects(a)),i},je.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}},je.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],s=0;s<e.length;s++){var i=e[s],r=je.parse.fromCollada._getMesh(i.getElementsByTagName("mesh")[0]);t.push(r)}return t},je.parse.fromCollada._getMesh=function(e){for(var t={},s=e.getElementsByTagName("source"),i=t.sources={},r=0;r<s.length;r++){for(var n=s[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]);i[s[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 p=u[a];o=[];d[parseInt(p.getAttribute("offset"))]=o;var f=p.getAttribute("semantic");c["s_"+f]="VERTEX"==f?e.getElementsByTagName("vertices")[0].getElementsByTagName("input")[0].getAttribute("source").substring(1):p.getAttribute("source").substring(1),c["i_"+f]=o,i[c["s_"+f]]}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},je.parse.fromCollada._libImages=function(e){e=e.getElementsByTagName("image");for(var t={},s=0;s<e.length;s++)t[e[s].getAttribute("id")]=e[s].getElementsByTagName("init_from")[0].textContent;return t},je.parse.fromCollada._libMaterials=function(e){e=e.getElementsByTagName("material");for(var t={},s=0;s<e.length;s++)t[e[s].getAttribute("name")]=e[s].getElementsByTagName("instance_effect")[0].getAttribute("url").substring(1);return t},je.parse.fromCollada._libEffects=function(e){e=e.getElementsByTagName("effect");for(var t={},s=0;s<e.length;s++){for(var i={},r=e[s].getElementsByTagName("newparam"),n=0;n<r.length;n++){var A=r[n].getElementsByTagName("surface")[0];A&&(i.surface=A.getElementsByTagName("init_from")[0].textContent)}t[e[s].getAttribute("id")]=i}return t},je.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=je.bin.rsl(e,0))return null;for(var s=je.bin.ril(e,2),i=6;i<s;){var r=je.bin.rsl(e,i),n=je.bin.ril(e,i+2);15677==r&&(t.edit=je.parse.from3DS._edit3ds(e,i,n)),45056==r&&(t.keyf=je.parse.from3DS._keyf3ds(e,i,n)),i+=n}return t},je.parse.from3DS._edit3ds=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);16384==n&&(null==i.objects&&(i.objects=[]),i.objects.push(je.parse.from3DS._edit_object(e,r,A))),r+=A}return i},je.parse.from3DS._keyf3ds=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);45058==n&&(null==i.desc&&(i.desc=[]),i.desc.push(je.parse.from3DS._keyf_objdes(e,r,A))),r+=A}return i},je.parse.from3DS._keyf_objdes=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);45072==n&&(i.hierarchy=je.parse.from3DS._keyf_objhierarch(e,r,A)),45073==n&&(i.dummy_name=je.bin.rASCII0(e,r+6)),r+=A}return i},je.parse.from3DS._keyf_objhierarch=function(e,t,s){var i={},r=t+6;return i.name=je.bin.rASCII0(e,r),r+=i.name.length+1,i.hierarchy=je.bin.rsl(e,r+4),i},je.parse.from3DS._edit_object=function(e,t,s){var i={},r=t+6;for(i.name=je.bin.rASCII0(e,r),r+=i.name.length+1;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);16640==n&&(i.mesh=je.parse.from3DS._obj_trimesh(e,r,A)),r+=A}return i},je.parse.from3DS._obj_trimesh=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=je.bin.rsl(e,r),A=je.bin.ril(e,r+2);16656==n&&(i.vertices=je.parse.from3DS._tri_vertexl(e,r,A)),16672==n&&(i.indices=je.parse.from3DS._tri_facel1(e,r,A)),16704==n&&(i.uvt=je.parse.from3DS._tri_mappingcoors(e,r,A)),16736==n&&(i.local=je.parse.from3DS._tri_local(e,r,A)),r+=A}return i},je.parse.from3DS._tri_vertexl=function(e,t,s){var i=[],r=t+6,n=je.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(je.bin.rf(e,r)),i.push(je.bin.rf(e,r+4)),i.push(je.bin.rf(e,r+8)),r+=12;return i},je.parse.from3DS._tri_facel1=function(e,t,s){var i=[],r=t+6,n=je.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(je.bin.rsl(e,r)),i.push(je.bin.rsl(e,r+2)),i.push(je.bin.rsl(e,r+4)),r+=8;return i},je.parse.from3DS._tri_mappingcoors=function(e,t,s){var i=[],r=t+6,n=je.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(je.bin.rf(e,r)),i.push(1-je.bin.rf(e,r+4)),r+=8;return i},je.parse.from3DS._tri_local=function(e,t,s){var i={},r=t+6;return i.X=[je.bin.rf(e,r),je.bin.rf(e,r+4),je.bin.rf(e,r+8)],r+=12,i.Y=[je.bin.rf(e,r),je.bin.rf(e,r+4),je.bin.rf(e,r+8)],r+=12,i.Z=[je.bin.rf(e,r),je.bin.rf(e,r+4),je.bin.rf(e,r+8)],r+=12,i.C=[je.bin.rf(e,r),je.bin.rf(e,r+4),je.bin.rf(e,r+8)],r+=12,i},je.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},s={};return s.id=je.bin.ril(e,0),s.verS=je.bin.ril(e,4),s.texS=je.bin.ril(e,8),s.indS=je.bin.ril(e,12),s.verO=je.bin.ril(e,16),s.verL=je.bin.ril(e,20),s.texO=je.bin.ril(e,24),s.texL=je.bin.ril(e,28),s.indO=je.bin.ril(e,32),s.indL=je.bin.ril(e,36),0!=s.verO&&(t.vertices=je.parse.fromBIV._readFloats(e,s.verO,s.verL)),0!=s.texO&&(t.uvt=je.parse.fromBIV._readFloats(e,s.texO,s.texL)),0!=s.indO&&(t.indices=je.parse.fromBIV._readInts(e,s.indO,s.indL,s.indS)),t},je.parse.toBIV=function(e){for(var t=0,s=0;s<e.indices.length;s++)t=Math.max(t,e.indices[s]);var i=32;t<=65535&&(i=16);var r=40;e.vertices&&(r+=4*e.vertices.length),e.uvt&&(r+=4*e.uvt.length),e.indices&&(r+=e.indices.length*i/8);var n=new Uint8Array(r);je.bin.wil(n,0,1769365870),je.bin.wil(n,4,32),je.bin.wil(n,8,32),je.bin.wil(n,12,i);var A=40;return e.vertices&&(je.bin.wil(n,16,A),je.bin.wil(n,20,4*e.vertices.length),je.parse.fromBIV._writeFloats(n,A,e.vertices),A+=4*e.vertices.length),e.uvt&&(je.bin.wil(n,24,A),je.bin.wil(n,28,4*e.uvt.length),je.parse.fromBIV._writeFloats(n,A,e.uvt),A+=4*e.uvt.length),e.indices&&(je.bin.wil(n,32,A),je.bin.wil(n,36,4*e.indices.length),je.parse.fromBIV._writeInts(n,A,e.indices,i)),n.buffer},je.parse.fromBIV._readFloats=function(e,t,s){for(var i=[],r=0;r<s/4;r++)i.push(je.bin.rf(e,t+4*r));return i},je.parse.fromBIV._writeFloats=function(e,t,s){for(var i=0;i<s.length;i++)je.bin.wf(e,t+4*i,s[i])},je.parse.fromBIV._readInts=function(e,t,s,i){for(var r=[],n=0;n<s/4;n++)16==i&&r.push(je.bin.rsl(e,t+2*n)),32==i&&r.push(je.bin.ril(e,t+4*n));return r},je.parse.fromBIV._writeInts=function(e,t,s,i){for(var r=0;r<s.length;r++)16==i&&je.bin.wsl(e,t+2*r,s[r]),32==i&&je.bin.wil(e,t+4*r,s[r])},je.gen={},je.gen.Plane=function(e,t,s,i){s||(s=1),i||(i=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(s*a/e,i*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},je.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]}},je.gen.Sphere=function(e,t){for(var s={verts:[],inds:[],uvt:[]},i=e+1,r=t+1,n=0;n<r;n++)for(var A=0;A<i;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);s.verts.push(l,c,h),s.uvt.push(A/e,n/t),n<t&&A<e&&s.inds.push(i*n+A,i*n+A+1,i*(n+1)+A,i*n+A+1,i*(n+1)+A,i*(n+1)+A+1)}return s},je.mat={},je.mat.scale=function(e,t,s){return[e,0,0,0,0,t,0,0,0,0,s,0,0,0,0,1]},je.mat.translate=function(e,t,s){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,s,1]},je.mat.rotateDeg=function(e,t,s){var i=Math.PI/180;return je.mat.rotate(e*i,t*i,s*i)},je.mat.rotate=function(e,t,s){var i=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],r=e,n=t,A=s,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 i[0]=a*l,i[1]=-a*u,i[2]=h,i[4]=o*u+c*h*l,i[5]=o*l-c*h*u,i[6]=-c*a,i[8]=c*u-o*h*l,i[9]=c*l+o*h*u,i[10]=o*a,i},je.edit={},je.edit.interpolate=function(e,t,s,i){for(var r=0;r<e.length;r++)s[r]=e[r]+i*(t[r]-e[r])},je.edit.transform=function(e,t){for(var s=0;s<e.length;s+=3){var i=e[s],r=e[s+1],n=e[s+2];e[s+0]=t[0]*i+t[4]*r+t[8]*n+t[12],e[s+1]=t[1]*i+t[5]*r+t[9]*n+t[13],e[s+2]=t[2]*i+t[6]*r+t[10]*n+t[14]}},je.edit.unwrap=function(e,t,s){for(var i=new Array(Math.floor(e.length/3)*s),r=0;r<e.length;r++)for(var n=0;n<s;n++)i[r*s+n]=t[e[r]*s+n];return i},je.edit.remap=function(e,t,s,i){for(var r=new Array(s.length),n=0;n<e.length;n++)for(var A=0;A<i;A++)r[t[n]*i+A]=s[e[n]*i+A];return r},je.utils={},je.utils.getAABB=function(e){var t,s,i,r,n,A;r=n=A=-(t=s=i=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<s&&(s=l),l>n&&(n=l),c<i&&(i=c),l>A&&(A=c)}return{min:{x:t,y:s,z:i},max:{x:r,y:n,z:A}}};const $e={" ":{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 qe(e={}){var t=e.origin||[0,0,0],s=t[0],i=t[1],r=t[2],n=e.size||1,A=[],o=[],a=e.text;j.isNumeric(a)&&(a=""+a);for(var l,c,h,u,d,p,f,g,m,_=(a||"").split("\n"),b=0,y=0,B=.04,w=0;w<_.length;w++){l=0,h=(c=_[w]).length;for(var v=0;v<h;v++)if(u=$e[c.charAt(v)]){d=1,p=-1,f=-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*B+s),A.push(y+m[1]*n*B+i),A.push(0+r),-1===p?p=b:(-1===f||(p=f),f=b),b++,d?d=!1:(o.push(p),o.push(f))):d=1;l+=u.width*B*n}y-=35*B*n}return j.apply(e,{primitive:"lines",positions:A,indices:o})}function et(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 s=[];for(let e=0;e<t-1;e++)s.push(e),s.push(e+1);return j.apply(e,{primitive:"lines",positions:e.points,indices:s})}const tt=R.vec4(4),st=R.vec4(),it=R.vec4(),rt=R.vec3([1,0,0]),nt=R.vec3([0,1,0]),At=R.vec3([0,0,1]),ot=R.vec3(3),at=R.vec3(3),lt=R.identityMat4();class ct extends ie{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=R.vec3(),this._quaternion=R.identityQuaternion(),this._rotation=R.vec3(),this._position=R.vec3(),this._offset=R.vec3(),this._localMatrix=R.identityMat4(),this._worldMatrix=R.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 s=0,i=e.length;s<i;s++)this.addChild(e[s],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=R.vec3()),this._origin.set(e)):this._origin&&(this._origin=null);for(let t=0,s=this._children.length;t<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;t++)this._children[t].edges=e}get edges(){return this._edges}set culled(e){e=!!e,this._culled=e;for(let t=0,s=this._children.length;t<s;t++)this._children[t].culled=e}get culled(){return this._culled}set clippable(e){e=!1!==e,this._clippable=e;for(let t=0,s=this._children.length;t<s;t++)this._children[t].clippable=e}get clippable(){return this._clippable}set collidable(e){e=!1!==e,this._collidable=e;for(let t=0,s=this._children.length;t<s;t++)this._children[t].collidable=e}get collidable(){return this._collidable}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._children.length;t<s;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,s=this._children.length;e<s;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,s=this._children.length;t<s;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,s=this._children.length;t<s;t++)this._children[t].castsShadow=e}get castsShadow(){return this._castsShadow}set receivesShadow(e){e=!!e,this._receivesShadow=e;for(let t=0,s=this._children.length;t<s;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)R.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(let t=0,s=e.length;t<s;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_setSubtreeAABBsDirty(e){if(e._aabbDirty=!0,e._children)for(let t=0,s=e._children.length;t<s;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=R.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{let e;R.collapseAABB3(this._aabb);for(let t=0,s=this._children.length;t<s;t++)e=this._children[t],e.collidable&&R.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}addChild(e,t){if(j.isNumeric(e)||j.isString(e)){const t=e;if(!(e=this.scene.component[t]))return void this.warn("Component not found: "+j.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,s=this._children.length;t<s;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,s=this._children.length;t<s;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(j.isNumeric(e)||j.isString(e)){const t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+j.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]),R.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]),R.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=R.identityMat4()),this._localMatrix.set(e||lt),R.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=R.identityMat4()),R.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 tt[0]=e[0],tt[1]=e[1],tt[2]=e[2],tt[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(tt,st),R.mulQuaternions(this.quaternion,st,it),this.quaternion=it,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return tt[0]=e[0],tt[1]=e[1],tt[2]=e[2],tt[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(tt,st),R.mulQuaternions(st,this.quaternion,st),this}rotateX(e){return this.rotate(rt,e)}rotateY(e){return this.rotate(nt,e)}rotateZ(e){return this.rotate(At,e)}translate(e,t){return R.vec3ApplyQuaternion(this.quaternion,e,ot),R.mulVec3Scalar(ot,t,at),R.addVec3(this.position,at,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(rt,e)}translateY(e){return this.translate(nt,e)}translateZ(e){return this.translate(At,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 s=0,i=e.length;s<i;s++)t=e[s],t.destroy()}this._children=[],this._setAABBDirty(),this.scene._aabbDirty=!0}}const ht=R.vec3(),ut=function(){const e=new Float64Array(16),t=new Float64Array(4),s=new Float64Array(4);return function(i,r,n){return n=n||e,t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,R.transformVec4(i,t,s),R.setMat4Translation(i,s,n),n.slice()}}();function dt(e,t,s){const i=Float32Array.from([e[0]])[0],r=e[0]-i,n=Float32Array.from([e[1]])[0],A=e[1]-n,o=Float32Array.from([e[2]])[0],a=e[2]-o;t[0]=i,t[1]=n,t[2]=o,s[0]=r,s[1]=A,s[2]=a}function pt(e,t,s,i=1e3){const r=R.getPositionsCenter(e,ht),n=Math.round(r[0]/i)*i,A=Math.round(r[1]/i)*i,o=Math.round(r[2]/i)*i;s[0]=n,s[1]=A,s[2]=o;const a=0!==s[0]||0!==s[1]||0!==s[2];if(a)for(let s=0,i=e.length;s<i;s+=3)t[s+0]=e[s+0]-n,t[s+1]=e[s+1]-A,t[s+2]=e[s+2]-o;return a}const ft=new e({}),gt=R.vec3(),mt=R.vec4(),_t={3001:"sRGBToLinear"},bt=function(){const e=[],t=[],s=[],i=[],r=[],n=[],A=[],o=(t,s)=>{let i=!1;return e.push((e=>i&&s(t,e))),{toString:()=>(i=!0,t)}},a={createAttribute:function(t,s){let i=!1;e.push((e=>i&&e.push(`in ${t} ${s};`)));const A={toString:()=>(i=!0,s)};return r.push((e=>{const t=i&&e(s);return t&&n.push(t.attributeHash),A.setInputValue=t,null})),A},createFragmentDefinition:(e,t)=>{let s=!1;return i.push((i=>s&&t(e,i))),{toString:()=>(s=!0,e)}},createOutput:(e,t,i)=>{let r=!1;return s.push((s=>r&&s.push(`layout(location = ${i||0}) out ${e} ${t};`))),{toString:()=>(r=!0,t)}},createUniform:(t,i,r)=>{let n=!1;const o=e=>n&&e.push(`uniform ${t} ${i};`);e.push(o),s.push(o);const a={toString:()=>(n=!0,i)};return A.push((e=>{const t=n&&e(i);return r?t&&(e=>r(t,e)):(a.setInputValue=t,null)})),a},createUniformArray:(t,i,r)=>{let n=!1;const o=e=>n&&e.push(`uniform ${t} ${i}[${r}];`);e.push(o),s.push(o);const a={toString:()=>(n=!0,i)};return A.push((e=>(a.setInputValue=n&&e(i),null))),a},createUniformBlock:(t,i,r)=>{let n=!1;const o=Object.keys(i),a=e=>{n&&(e.push(`uniform ${t} {`),o.forEach((t=>e.push(` ${i[t]} ${t};`))),e.push("};"))};e.push(a),s.push(a);const l={};return o.forEach((e=>l[e]={toString:()=>(n=!0,e)})),A.push((e=>{const s=n&&e(t);return r?s&&(e=>r(s,e)):(l.setInputValue=s,null)})),l},createVarying:(i,r,n,A)=>{let o=!1;const a=A?A+" ":"";return e.push((e=>o&&e.push(`${a}out ${i} ${r};`))),t.push((e=>o&&e.push(`${r} = ${n()};`))),s.push((e=>o&&e.push(`${a}in ${i} ${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:s=>{e.setInputValue(s.pickClipPos),t.setInputValue(s.pickClipPosInv)},transformedClipPos:()=>`vec4((${u}.xy / ${u}.w - ${e}) * ${t} * ${u}.w, ${u}.zw)`}}(),p=d?d.transformedClipPos():u,f=[],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?f.push(`gl_FragDepth = ${c.testPerspectiveForGl_FragDepth?`${g} == 0.0 ? gl_FragCoord.z : `:""}log2(${h(_)}) * ${m} * 0.5;`):c.cleanerEdges&&f.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("}")})),y=c.sectionPlanesState,B=y&&function(){const e=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t}(y.getNumAllocatedSectionPlanes()).map((e=>{const t=(t,s,i)=>a.createUniform(t,`sectionPlane${s}${e}`,((t,s)=>{const r=y.sectionPlanes,n=r.length,A=(s.mesh.layerIndex||0)*n,o=e<n&&s.mesh.renderFlags.sectionPlanesActivePerLayer[A+e];return i(t,o,r[e],s.mesh.origin)}));return{act:t("bool","Active",((e,t)=>e(t?1:0))),dir:t("vec3","Dir",((e,t,s)=>t&&e(s.dir))),pos:t("vec3","Pos",((e,t,s,i)=>t&&e(i?R.mulVec3Scalar(R.normalizeVec3(s.dir,gt),-(R.dotVec3(s.dir,i)+s.dist),gt):s.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=B?function(){const e=a.createUniform("vec4","sliceColor",(e=>e(w.sliceColor))),t=s=>(t.needed=!0,`(sliced ? ${e} : ${s})`);return t}():e=>e,C=c.getGammaFactor,M=a.createUniform("float","gammaFactor",(e=>e(C())));c.appendFragmentOutputs(f,C&&(e=>`${b}(${e}, ${M})`),"gl_FragCoord",v);const E=function(){const e=[],t=a.createUniform("float","sliceThickness",(e=>e(w.sliceThickness)));if(B){v.needed&&e.push(" bool sliced = false;"),e.push(` if (${c.clippableTest()}) {`);const s=a.createVarying("highp vec3","vHighpWorldPosition",(()=>`${c.worldPositionAttribute}.xyz`));if(e.push(` float dist = ${B(s)};`),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 i.forEach((t=>t(e))),e}(),x=[...function(){const e=[];return s.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,...f,"}"],U=[`gl_Position = ${p};`,...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,...U,"}"],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(x),k=(e,t)=>{const s=t.join("\n"),i=o.createShader(e);return o.shaderSource(i,s),o.compileShader(i),o.getShaderParameter(i,o.COMPILE_STATUS)?[i]:[null,["Failed to compile",o.getShaderInfoLog(i),s.split("\n").map(((e,t)=>t+1+": "+e+"\n")).join("")]]},[Q,O]=k(o.VERTEX_SHADER,S),[V,L]=k(o.FRAGMENT_SHADER,D),H=e=>(console.error(e.join("\n")),[null,e]);if(O)return H(["Vertex shader error"].concat(O));if(L)return H(["Fragment shader error"].concat(L));{const e=o.createProgram();if(e){if(o.attachShader(e,Q),o.attachShader(e,V),o.linkProgram(e),o.getProgramParameter(e,o.LINK_STATUS)){const t=wt(o,e);r.forEach((e=>e(t)));const s=A.map((e=>e(t))).filter((e=>e)),i=ft.addItem({});return[{id:i,bind:()=>o.useProgram(e),inputSetters:{attributesHash:n.sort().join(", "),setUniforms:(e,t)=>{d&&d.setClipPosInputValue(e),s.forEach((e=>e(t)))}},destroy:()=>{ft.removeItem(i),o.deleteProgram(e),o.deleteShader(Q),o.deleteShader(V)}}]}return H(["",o.getProgramInfoLog(this.program),"","Vertex shader:","",...S,"","Fragment shader:","",...D])}return H(["Failed to allocate program"])}}}},yt=function(e,t){const s=e.createUniform("vec4","lightAmbient",(e=>e(t.getAmbientColorAndIntensity()))),i=t.lights,r=i.map(((t,s)=>{const r={color:e.createUniform("vec4",`lightColor${s}`,(e=>{const t=i[s];mt[0]=t.color[0],mt[1]=t.color[1],mt[2]=t.color[2],mt[3]=t.intensity,e(mt)})),position:e.createUniform("vec3",`lightPos${s}`,(e=>e(i[s].pos))),direction:e.createUniform("vec3",`lightDir${s}`,(e=>e(i[s].dir))),shadowProjMatrix:e.createUniform("mat4",`shadowProjMatrix${s}`,(e=>e(i[s].getShadowViewMatrix()))),shadowViewMatrix:e.createUniform("mat4",`shadowViewMatrix${s}`,(e=>e(i[s].getShadowViewMatrix()))),shadowMap:e.createUniform("sampler2D",`shadowMap${s}`,(e=>e(i[s].getShadowRenderBuf().colorTextures[0])))},n=e=>({glslLight:{isViewSpace:"view"===t.space,getColor:()=>`${r.color}.rgb * ${r.color}.a`,getDirection:(t,s)=>`normalize(${e(t,s)})`,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,s)=>{const i=()=>{const e=s();return e.length>0&&e[0]},r=i();return r&&Bt(e,"samplerCube",t,r.encoding,(e=>{const t=i();t&&e(t.texture)}))},A=n("light",(()=>t.lightMaps)),o=n("reflection",(()=>t.reflectionMaps));return{getHash:()=>t.getHash(),getAmbientColor:()=>`${s}.rgb * ${s}.a`,directionalLights:r.map((e=>e.glslLight)),getIrradiance:A&&(e=>`${A(e)}.rgb`),getReflection:o&&((e,t)=>`${o(e,t)}.rgb`)}},Bt=(e,t,s,i,r)=>{const n=e.createUniform(t,s+"Map",r);return(e,t)=>{const s=t?`texture(${n}, ${e}, ${t})`:`texture(${n}, ${e})`;return 3e3!==i?`${_t[i]}(${s})`:s}},wt=function(e,t){const s={},i=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let r=0;r<i;++r){const n=e.getActiveAttrib(t,r),A=e.getAttribLocation(t,n.name);s[n.name]=function(t){t.bindAtLocation(A),e.enableVertexAttribArray(A);const s=t.attributeDivisor;s&&e.vertexAttribDivisor(A,s)},s[n.name].attributeHash=`${A.toString().padStart(1+Math.floor(Math.log10(i)),"0")}:${n.name}`}const r=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS);for(let i=0;i<r;++i){const r=e.getActiveUniformBlockName(t,i),n=e.getUniformBlockIndex(t,r),A=i;e.uniformBlockBinding(t,n,A);const o=e.createBuffer();s[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 i=0;i<n;++i){const r=e.getActiveUniform(t,i);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++;s[n]=function(s){const i=s.bind(t);return i&&e.uniform1i(o,t),i}}else s[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=s[e];if(!t)throw`Missing input "${e}"`;return t}},vt=R.vec4(),Ct=R.vec4();class Mt{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 Et=R.OBB3(),Ft=R.vec4(),xt=R.vec4(),Ut=R.vec4(),It=R.vec3([1,0,0]),Tt=R.vec3([0,1,0]),Pt=R.vec3([0,0,1]),St=R.vec3(3),Dt=R.vec3(3),kt=R.identityMat4(),Qt=new e({}),Rt={};class Ot extends ie{constructor(e,t={}){super(e,t),this.renderOrder=t.renderOrder||0,this.originalSystemId=t.originalSystemId||this.id,this.renderFlags=new Mt,this._state=new xe({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:R.vec3(),origin:null,originHash:null,isUI:t.isUI});const s=t.material?this._checkComponent2(["PhongMaterial","MetallicMaterial","SpecularMaterial","LambertMaterial"],t.material):this.scene.material,i=this,r=e=>{let t=null;const s=()=>{if(!t){const s=bt(),r=s.programVariables.createAttribute,n=i._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(s.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,i.scene.canvas.canvas.id,i.scene._sectionPlanesState.getHash(),i._geometry._state.hash].concat(h.getHash()).join(";");if(!(u in Rt)){const e=Lt(i,A,{decodedUv:c,worldNormal:a,viewNormal:l},h,s);if(e.errors)return void console.log(e.errors.join("\n"));const t=Qt.addItem({});Rt[u]={drawMesh:e.drawMesh,id:t,useCount:0,delete:()=>{Qt.removeItem(t),e.destroy(),delete Rt[u],L.memory.programs--}},L.memory.programs++}t=Rt[u],t.useCount++}};return{get:s,getId:()=>t.id,put:()=>{t&&(0==--t.useCount&&t.delete(),t=null)},drawMesh:(e,i,r)=>{s(),t&&t.drawMesh(e,i,r)}}},n=i.scene,A=e=>(t,s)=>function(e,t,s,i,r){const n=r&&yt(t,i._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=s.attributes,t=r&&[n.getAmbientColor()].concat(e.normal?n.directionalLights.map((t=>`(max(dot(${e.normal.view}, ${t.getDirection(s.viewMatrix,e.position.view)}), 0.0) * ${t.getColor()})`)):[]);return`vec4(${A}${t?` * (${t.join(" + ")})`:""}, ${o})`})),l=t.createOutput("vec4","outColor");return{getHash:()=>[e,i.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};`)}}(i._state.hash,t,s,n,e);this._renderers={_drawRenderer:r(((e,t)=>"LambertMaterial"===s.type?function(e,t,s,i,r){const n=yt(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=s.attributes,t=[n.getAmbientColor()].concat(e.normal?n.directionalLights.map((t=>`(max(dot(${e.normal.view}, ${t.getDirection(s.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(),i._state.hash],programName:"Lambert",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:(e,t)=>e.push(`${h} = ${t?t(c):c};`)}}(i._state.drawHash,e,t,s,n):function(e,t,s,i,r){const n=i._state,A="PhongMaterial"===n.type,o="MetallicMaterial"===n.type,a="SpecularMaterial"===n.type,l=s.attributes,c=yt(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,s,r)=>{const n=(s,i,n)=>t.createUniform(s,e+"Fresnel"+i,((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(i)&&((e,t)=>`mix(${l+s}, ${c+s}, ${u}(${e}, ${t}, ${A}, ${o}, ${a}))`)},p=d("diffuse","",(e=>e._diffuseFresnel)),f=d("specular","",(e=>e._specularFresnel)),g=d("emissive","",(e=>e._emissiveFresnel)),m=d("alpha",".r",(e=>e._alphaFresnel)),_=(e,s)=>{const r=l.uv&&s(i),n=r&&Bt(t,"sampler2D",e,r.encoding,((e,t)=>e(s(t.material)._state.texture)));return n&&function(){const i=r._state.matrix&&t.createUniform("mat4",e+"MapMatrix",((e,t)=>e(s(t.material)._state.matrix))),A=i?e=>`(${i} * ${e}).st`:e=>`${e}.st`,o=(e,t)=>n(A(e));return o.getTexCoordExpression=A,o}()},b=_("ambient",(e=>e._ambientMap)),y=_("baseColor",(e=>e._baseColorMap)),B=_("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)),x=_("specular",(e=>e._specularMap)),U=_("glossiness",(e=>e._glossinessMap)),I=_("specularGlossiness",(e=>e._specularGlossinessMap)),T=_("normal",(e=>e._normalMap)),P=(e,s,r)=>{const n=r(i);return("float"===s?null!=n:n)&&t.createUniform(s,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?(vt[0]=t,vt[1]=1===e.alphaMode?1:0,vt[2]=e.alphaCutoff,vt):null})),j=t.createVarying("vec3","vViewPosition",(()=>`${l.position.view}.xyz`)),z=t.createVarying("vec4","texturePos",(()=>`vec4(${l.uv}, 1.0, 1.0)`)),W=l.color&&t.createVarying("vec4","vColor",(()=>l.color)),X=t.createVarying("vec3","vViewNormal",(()=>l.normal.view)),K=c.directionalLights.map(((e,i)=>({vViewLightReverseDir:t.createVarying("vec3",`vViewLightReverseDir${i}`,(()=>e.getDirection(s.viewMatrix,null))),vShadowPosFromLight:t.createVarying("vec3",`vShadowPosFromLight${i}`,(()=>`(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(),i._state.hash],programName:"Draw",canActAsBackground:!0,discardPoints:!0,setupPointSize:!0,setsLineWidth:!0,appendFragmentOutputs:(e,t,i)=>{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(z)}.r;`),W&&(e.push(`diffuseColor *= ${W}.rgb;`),e.push(`alpha *= ${W}.a;`)),o&&y&&(e.push("vec4 baseColorTexel = "+y(z)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(A||a)&&B&&(e.push("vec4 diffuseTexel = "+B(z)+";"),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(z)}.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(z)}.r`:"1.0"};`),o&&M&&e.push(`metallic *= ${M(z)}.r;`),o&&E&&e.push(`roughness *= ${E(z)}.r;`),o&&F&&(e.push("vec4 metalRoughTexel = "+F(z)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(A||a)&&x&&e.push(`specular *= ${x(z)}.rgb;`),a&&U&&e.push(`glossiness *= ${U(z)}.r;`),a&&I&&(e.push("vec4 specGlossTexel = "+I(z)+";"),e.push("specular *= specGlossTexel.rgb;"),e.push("glossiness *= specGlossTexel.a;"));const t=`normalize(${X})`,i=(A||o||a)&&T?`${ee}(${j}, ${t}, ${T.getTexCoordExpression(z)}, ${T(z)})`:t;if(e.push(`vec3 viewNormal = ${i};`),e.push(`vec3 viewEyeDir = normalize(-${j});`),p&&e.push(`diffuseColor *= ${p("viewEyeDir","viewNormal")};`),f&&e.push(`specular *= ${f("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)",i=A?`0.2 * PI * ${c.getReflection(t)}`:function(){const e=`${q}(viewNormal, viewEyeDir, specular, roughness)`,i=`normalize((vec4(${t}, 0.0) * ${s.viewMatrix}).xyz)`;return`${e} * ${c.getReflection(i,"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 += ${i};`)}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,s)=>{if(t.shadowParameters){const i="0.007";e.push(`fragmentDepth = ${K[s].vShadowPosFromLight}.z - ${i};`),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[s].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${s} = ${t.getColor()}${t.shadowParameters?" * shadow":""};`),e.push(`vec3 lightDirection${s} = ${t.isViewSpace?t.getDirection(null,j):K[s].vViewLightReverseDir};`);const i=`${Y}(dot(viewNormal, lightDirection${s}))`;e.push(`vec3 irradiance${s} = ${i} * lightColor${s};`),e.push(`reflDiff += irradiance${s};`);const r=A?`lightColor${s} * specular * pow(max(dot(reflect(-lightDirection${s}, -viewNormal), viewEyeDir), 0.0), shininess)`:`irradiance${s} * PI * ${$}(lightDirection${s}, 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(z)}.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"};`)}}}(i._state.drawHash,e,t,s,n))),_shadowRenderer:r((e=>function(e,t){const s=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("}")})),i=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"Shadow",setsLineWidth:!0,useShadowView:!0,dontGetLogDepth:!0,appendFragmentOutputs:(e,t,r)=>e.push(`${i} = ${s}(${r}.z);`)}}(i._state.hash,e))),_emphasisEdgesRenderer:r(A(!1)),_emphasisFillRenderer:r(A(!0)),_pickMeshRenderer:r((e=>function(e,t){const s=t.createUniform("vec4","pickColor",((e,t)=>{var s=t.meshPickID;Ct[0]=255&s,Ct[1]=s>>8&255,Ct[2]=s>>16&255,Ct[3]=s>>24&255,R.mulVec4Scalar(Ct,1/255,Ct),e(Ct)})),i=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"PickMesh",isPick:!0,appendFragmentOutputs:e=>e.push(`${i} = ${s};`)}}(i._state.hash,e))),_pickTriangleRenderer:r(((e,t)=>function(e,t,s){const i=t.createVarying("vec4","vColor",(()=>s.attributes.pickColor)),r=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"PickTriangle",isPick:!0,trianglePick:!0,appendFragmentOutputs:e=>e.push(`${r} = ${i};`)}}(i._state.hash,e,t))),_occlusionRenderer:r((e=>function(e,t){const s=t.createOutput("vec4","outColor");return{getHash:()=>[e],programName:"Occlusion",skipIfTransparent:!0,appendFragmentOutputs:e=>e.push(`${s} = vec4(0.0, 0.0, 1.0, 1.0);`)}}(i._state.pickOcclusionHash,e)))},this._geometry=t.geometry?this._checkComponent2(["ReadableGeometry","VBOGeometry"],t.geometry):this.scene.geometry,this._material=s,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=R.vec3(),this._quaternion=R.identityQuaternion(),this._rotation=R.vec3(),this._position=R.vec3(),this._worldMatrix=R.identityMat4(),this._worldNormalMatrix=R.identityMat4(),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0;const o=t.origin||t.rtcCenter;if(o&&(this._state.origin=R.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]),R.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]),R.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=R.identityMat4()),R.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix}set matrix(e){this.__localMatrix||(this.__localMatrix=R.identityMat4()),this.__localMatrix.set(e||kt),R.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=R.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 s=!!e;this.scene._objectColorizeUpdated(this,s),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 s=null!=e;t[3]=s?e:1,this.scene._objectOpacityUpdated(this,s),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,s=[e.canvas.canvas.id,e._sectionPlanesState.getHash()];t.stationary&&s.push("/s"),"none"===t.billboard?s.push("/n"):"spherical"===t.billboard?s.push("/s"):"cylindrical"===t.billboard&&s.push("/c"),s.push(";");const i=s.concat([e.gammaOutput?"go":"",e._lightsState.getHash(),t.receivesShadow?"/rs":""]).join("");this._state.drawHash!==i&&(this._state.drawHash=i,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=s.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)R.mulMat4(this._parentNode.worldMatrix,e,this._worldMatrix);else for(let t=0,s=e.length;t<s;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_buildWorldNormalMatrix(){this._worldMatrixDirty&&this._buildWorldMatrix(),this._worldNormalMatrix||(this._worldNormalMatrix=R.mat4()),R.transposeMat4(this._worldMatrix,this._worldNormalMatrix),R.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=R.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}_buildAABB(e,t){R.transformOBB3(e,this._geometry.obb,Et),R.OBB3ToAABB3(Et,t);const s=this._state.offset;if(t[0]+=s[0],t[1]+=s[1],t[2]+=s[2],t[3]+=s[0],t[4]+=s[1],t[5]+=s[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 Ft[0]=e[0],Ft[1]=e[1],Ft[2]=e[2],Ft[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(Ft,xt),R.mulQuaternions(this.quaternion,xt,Ut),this.quaternion=Ut,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return Ft[0]=e[0],Ft[1]=e[1],Ft[2]=e[2],Ft[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(Ft,xt),R.mulQuaternions(xt,this.quaternion,xt),this}rotateX(e){return this.rotate(It,e)}rotateY(e){return this.rotate(Tt,e)}rotateZ(e){return this.rotate(Pt,e)}translate(e,t){return R.vec3ApplyQuaternion(this.quaternion,e,St),R.mulVec3Scalar(St,t,Dt),R.addVec3(this.position,Dt,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(It,e)}translateY(e){return this.translate(Tt,e)}translateZ(e){return this.translate(Pt,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 s=0;s<t;s++){const t=e[s],i=this.renderFlags;if(t.active)if(this._state.origin){const e=R.planeAABB3Intersect(t.dir,t.dist,this.aabb);if(-1===e)return!1;const r=0===e;i.sectionPlanesActivePerLayer[s]=r}else i.sectionPlanesActivePerLayer[s]=!0;else i.sectionPlanesActivePerLayer[s]=!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,s,i){Vt(this,e,t,s,i)}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 Vt=function(){const e=R.vec3(),t=R.vec3(),s=R.vec3(),i=R.vec3(),r=R.vec3(),n=R.vec3(),A=R.vec4(),o=R.vec3(),a=R.vec3(),l=R.vec3(),c=R.vec3(),h=R.vec3(),u=R.vec3(),d=R.vec3(),p=R.vec3(),f=R.vec3(),g=R.vec4(),m=R.vec4(),_=R.vec4(),b=R.vec3(),y=R.vec3(),B=R.vec3(),w=R.vec3(),v=R.vec3(),C=R.vec3(),M=R.vec3(),E=R.vec3(),F=R.vec3(),x=R.vec3(),U=R.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,z=L.positions;let W,X,K;if(j){var Q=j[H+0],O=j[H+1],V=j[H+2];n[0]=Q,n[1]=O,n[2]=V,D.indices=n,W=3*Q,X=3*O,K=3*V}else W=3*H,X=W+3,K=X+3;if(s[0]=z[W+0],s[1]=z[W+1],s[2]=z[W+2],i[0]=z[X+0],i[1]=z[X+1],i[2]=z[X+2],r[0]=z[K+0],r[1]=z[K+1],r[2]=z[K+2],L.compressGeometry){const e=L.positionsDecodeMatrix;e&&(Re.decompressPosition(s,e,s),Re.decompressPosition(i,e,i),Re.decompressPosition(r,e,r))}D.canvasPos?R.canvasPosToLocalRay(G.canvas,I.origin?ut(T,I.origin):T,P,S,I.worldMatrix,D.canvasPos,e,t):D.origin&&D.direction&&R.worldRayToLocalRay(I.worldMatrix,D.origin,D.direction,e,t),R.normalizeVec3(t),R.rayPlaneIntersect(e,t,s,i,r,A),D.localPos=A,D.position=A,g[0]=A[0],g[1]=A[1],g[2]=A[2],g[3]=1,R.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,R.transformVec4(N.matrix,m,_),a[0]=_[0],a[1]=_[1],a[2]=_[2],D.viewPos=a,R.cartesianToBarycentric(A,s,i,r,l),D.bary=l;const Z=L.normals;if(Z){if(L.compressGeometry){const e=3*Q,t=3*O,s=3*V;Re.decompressNormal(Z.subarray(e,e+2),c),Re.decompressNormal(Z.subarray(t,t+2),h),Re.decompressNormal(Z.subarray(s,s+2),u)}else c[0]=Z[W],c[1]=Z[W+1],c[2]=Z[W+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=R.addVec3(R.addVec3(R.mulVec3Scalar(c,l[0],b),R.mulVec3Scalar(h,l[1],y),B),R.mulVec3Scalar(u,l[2],w),v);D.worldNormal=R.normalizeVec3(R.transformVec3(I.worldNormalMatrix,e,C))}const J=L.uv;if(J){if(d[0]=J[2*Q],d[1]=J[2*Q+1],p[0]=J[2*O],p[1]=J[2*O+1],f[0]=J[2*V],f[1]=J[2*V+1],L.compressGeometry){const e=L.uvDecodeMatrix;e&&(Re.decompressUV(d,e,d),Re.decompressUV(p,e,p),Re.decompressUV(f,e,f))}D.uv=R.addVec3(R.addVec3(R.mulVec2Scalar(d,l[0],M),R.mulVec2Scalar(p,l[1],E),F),R.mulVec2Scalar(f,l[2],x),U)}}}}}(),Lt=(e,t,s,i,r)=>{const n=r.programVariables,A=s.decodedUv,o=s.worldNormal,a=s.viewNormal,l=e.scene,c=l.canvas.gl,h=e._state.background,u=e._geometry._state,d=u.compressGeometry,p="points"===u.primitiveName,f=n.createUniform("float","pointSize"),g=n.createUniform("mat4","modelMatrix"),m=n.createUniform("mat4","modelNormalMatrix"),_=n.createUniform("vec3","offset"),b=n.createUniform("vec3","scale"),y=n.createUniform("mat4","positionsDecodeMatrix"),B=n.createUniform("mat3","uvDecodeMatrix"),w=n.createUniform("mat4","viewMatrix"),v=n.createUniform("mat4","viewNormalMatrix"),C=n.createUniform("mat4","projMatrix"),M=e.billboard,E="spherical"===M||"cylindrical"===M,F=e.stationary,x=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)))),U=function(){const e=x&&n.createVertexDefinition("billboard",x);return t=>e?`${e}(${t})`:t}(),I=function(){const e=x&&n.createFragmentDefinition("billboard",x);return t=>e?`${e}(${t})`:t}(),T=[];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,i.programName,{appendFragmentOutputs:(e,t,s,r)=>{T.forEach((t=>e.push(t))),i.appendFragmentOutputs(e,t,s,r)},clippableTest:()=>S,clippingCaps:i.clippingCaps,clipPos:h?"clipPos.xyww":P,crossSections:l.crossSections,discardPoints:p&&i.discardPoints,getGammaFactor:l.gammaOutput&&(()=>l.gammaFactor),getLogDepth:!i.dontGetLogDepth&&l.logarithmicDepthBufferEnabled&&(e=>e),getPointSize:i.setupPointSize&&p&&(()=>f),getVertexData:function(){const e=a&&a.needed&&`vec3 ${a} = normalize((${U(v)} * vec4(${o}, 0.0)).xyz);`,s=[];if(s.push(`vec4 localPosition = vec4(${t.position}, 1.0);`),d&&s.push(`localPosition = ${y} * localPosition;`),s.push(`vec4 worldPosition = ${U(g)} * localPosition;`),s.push(`worldPosition.xyz = worldPosition.xyz + ${_};`),s.push(`mat4 viewMatrix1 = ${w};`),F?s.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):h&&s.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),s.push(`mat4 viewMatrix2 = ${U("viewMatrix1")};`),s.push(`vec4 viewPosition = ${E?`${U(`viewMatrix1 * ${g}`)} * localPosition`:"viewMatrix2 * worldPosition"};`),A&&A.needed&&s.push(`vec2 ${A} = ${d?`(${B} * vec3(${t.uv}, 1.0)).xy`:t.uv};`),o&&o.needed){const e=d?`${n.commonLibrary.octDecode}(${t.normal}.xy)`:t.normal;s.push(`vec3 ${o} = (${U(m)} * vec4(${e}, 0.0)).xyz;`)}return e&&s.push(e),s.push(`vec4 clipPos = ${C} * viewPosition;`),s},projMatrix:C,sectionPlanesState:l._sectionPlanesState,testPerspectiveForGl_FragDepth:!0,usePickClipPos:i.isPick,worldPositionAttribute:"worldPosition"});if(k)return{errors:k};{const e=D.inputSetters;let s=null,r=null;return{destroy:()=>D.destroy(),drawMesh:(n,A,o)=>{if(i.skipIfTransparent&&o.alpha<1)return;const a=o._state,l=A._state,u=A._geometry,d=u._state,p=n.viewParams,M=i.canActAsBackground&&h;n.lastProgramId!==D.id&&(n.lastProgramId=D.id,D.bind(),n.useProgram++,s=null,r=null,M&&c.depthFunc(c.LEQUAL)),a.id!==s&&(n.backfaces!==a.backfaces&&(a.backfaces?c.disable(c.CULL_FACE):c.enable(c.CULL_FACE),n.backfaces=a.backfaces),i.dontSetFrontFace||n.frontface===a.frontface||(c.frontFace(a.frontface?c.CCW:c.CW),n.frontface=a.frontface),i.drawEdges&&n.lineWidth!==a.edgeWidth&&(c.lineWidth(a.edgeWidth),n.lineWidth=a.edgeWidth),i.setsLineWidth&&n.lineWidth!==a.lineWidth&&(c.lineWidth(a.lineWidth),n.lineWidth=a.lineWidth),s=a.id);const E=!i.useShadowView&&A.origin;((t,s)=>{const i=(e,t)=>e.setInputValue&&e.setInputValue(t);i(f,o.pointSize),i(g,A.worldMatrix),i(m,A.worldNormalMatrix),i(_,A.offset),i(b,A.scale),i(y,d.positionsDecodeMatrix),i(B,d.uvDecodeMatrix),i(w,s),i(v,p.viewNormalMatrix),i(C,t),i(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:p.far}})})(p.projMatrix,E?n.getRTCViewMatrix(l.originHash,E):p.viewMatrix);const F=e=>{const s=(e,t)=>{e&&e.setInputValue&&t&&(e.setInputValue(t),n.bindArray++)};s(t.position,(e||d).positionsBuf),s(t.color,d.colorsBuf),s(t.pickColor,e&&e.pickColorsBuf),s(t.uv,d.uvBuf),s(t.normal,d.normalsBuf)};if(i.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(i.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 Ht extends ie{get type(){return"Material"}constructor(e,t={}){super(e,t),L.memory.materials++}destroy(){super.destroy(),L.memory.materials--}}const Nt={opaque:0,mask:1,blend:2},Gt=["opaque","mask","blend"];class jt extends Ht{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new xe({type:"PhongMaterial",ambient:R.vec3([1,1,1]),diffuse:R.vec3([1,1,1]),specular:R.vec3([1,1,1]),emissive:R.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=Nt[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 Gt[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 zt(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];let s;switch(t){case"WEBGL_depth_texture":s=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=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":s=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":s=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=e.getExtension(t)}return e._cachedExtensions[t]=s,s}function Wt(e,t,s=null){let i;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===s){const t=zt(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(i=zt(e,"WEBGL_compressed_texture_s3tc"),null===i)return null;if(33776===r)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===r)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===r)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===r)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===r||35841===r||35842===r||35843===r){const t=zt(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=zt(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){const t=zt(e,"WEBGL_compressed_texture_etc");if(null===t)return null;if(37492===r)return 3001===s?t.COMPRESSED_SRGB8_ETC2:t.COMPRESSED_RGB8_ETC2;if(37496===r)return 3001===s?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=zt(e,"WEBGL_compressed_texture_astc");if(null===t)return null;if(37808===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:t.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:t.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:t.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:t.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:t.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:t.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:t.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:t.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:t.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:t.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:t.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:t.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:t.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===r)return 3001===s?t.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:t.COMPRESSED_RGBA_ASTC_12x12_KHR}if(36492===r){const t=zt(e,"EXT_texture_compression_bptc");if(null===t)return null;if(36492===r)return 3001===s?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 Xt=new Uint8Array([0,0,0,1]);class Kt{constructor({gl:e,target:t,format:s,type:i,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=s||1023,this.type=i||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?(Xt[0]=Math.floor(255*e[0]),Xt[1]=Math.floor(255*e[1]),Xt[2]=Math.floor(255*e[2]),Xt[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(Xt[0]=0,Xt[1]=0,Xt[2]=0,Xt[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 s=0,i=e.length;s<i;s++)t.texImage2D(e[s],0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,Xt)}else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,Xt);t.bindTexture(this.target,null)}setTarget(e){this.target=e||this.gl.TEXTURE_2D}setImage(e,t={}){const s=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),this.maxAnisotropy=t.maxAnisotropy,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 i=!1;s.bindTexture(this.target,this.texture);const r=s.getParameter(s.UNPACK_FLIP_Y_WEBGL);s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY);const n=s.getParameter(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL);s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha);const A=s.getParameter(s.UNPACK_ALIGNMENT);s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment);const o=s.getParameter(s.UNPACK_COLORSPACE_CONVERSION_WEBGL);s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const a=this.maxAnisotropy&&zt(s,"EXT_texture_filter_anisotropic");if(a){const e=s.getParameter(a.MAX_TEXTURE_MAX_ANISOTROPY_EXT);s.texParameterf(s.TEXTURE_2D,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e,this.maxAnisotropy))}const l=Wt(s,this.minFilter);s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,l),l!==s.NEAREST_MIPMAP_NEAREST&&l!==s.LINEAR_MIPMAP_NEAREST&&l!==s.NEAREST_MIPMAP_LINEAR&&l!==s.LINEAR_MIPMAP_LINEAR||(i=!0);const c=Wt(s,this.magFilter);c&&s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,c);const h=Wt(s,this.wrapS);h&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,h);const u=Wt(s,this.wrapT);u&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,u);const d=Wt(s,this.format,this.encoding),p=Wt(s,this.type),f=Zt(s,this.internalFormat,d,p,this.encoding,!1);if(this.target===s.TEXTURE_CUBE_MAP){if(j.isArray(e)){const t=e,i=[s.TEXTURE_CUBE_MAP_POSITIVE_X,s.TEXTURE_CUBE_MAP_NEGATIVE_X,s.TEXTURE_CUBE_MAP_POSITIVE_Y,s.TEXTURE_CUBE_MAP_NEGATIVE_Y,s.TEXTURE_CUBE_MAP_POSITIVE_Z,s.TEXTURE_CUBE_MAP_NEGATIVE_Z];for(let e=0,r=i.length;e<r;e++)s.texImage2D(i[e],0,f,d,p,t[e])}}else s.texImage2D(s.TEXTURE_2D,0,f,d,p,e);i&&s.generateMipmap(this.target),s.bindTexture(this.target,null),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,r),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n),s.pixelStorei(s.UNPACK_ALIGNMENT,A),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,o)}setCompressedData({mipmaps:e,props:t={}}){const s=this.gl,i=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),s.activeTexture(s.TEXTURE0+0),s.bindTexture(this.target,this.texture);let r=e.length>1;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,this.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,this.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE);const n=Wt(s,this.wrapS);n&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,n);const A=Wt(s,this.wrapT);if(A&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,A),this.type===s.TEXTURE_3D||this.type===s.TEXTURE_2D_ARRAY){const e=Wt(s,this.wrapR);e&&s.texParameteri(this.target,s.TEXTURE_WRAP_R,e),s.texParameteri(this.type,s.TEXTURE_WRAP_R,e)}r?(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Jt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Jt(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,Wt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Wt(s,this.magFilter)));const o=Wt(s,this.format,this.encoding),a=Wt(s,this.type),l=Zt(s,this.internalFormat,o,a,this.encoding,!1);s.texStorage2D(s.TEXTURE_2D,i,l,e[0].width,e[0].height);for(let t=0,i=e.length;t<i;t++){const i=e[t];1023!==this.format?null!==o?s.compressedTexSubImage2D(s.TEXTURE_2D,t,0,0,i.width,i.height,o,i.data):console.warn("Attempt to load unsupported compressed texture format in .setCompressedData()"):s.texSubImage2D(s.TEXTURE_2D,t,0,0,i.width,i.height,o,a,i.data)}s.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 s=Wt(t,e.minFilter);s&&(this.minFilter=e.minFilter,t.texParameteri(this.target,t.TEXTURE_MIN_FILTER,s),s!==t.NEAREST_MIPMAP_NEAREST&&s!==t.LINEAR_MIPMAP_NEAREST&&s!==t.NEAREST_MIPMAP_LINEAR&&s!==t.LINEAR_MIPMAP_LINEAR||t.generateMipmap(this.target))}if(void 0!==e.magFilter){const s=Wt(t,e.magFilter);s&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,s))}if(void 0!==e.wrapS){const s=Wt(t,e.wrapS);s&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,s))}if(void 0!==e.wrapT){const s=Wt(t,e.wrapT);s&&(this.wrapT=e.wrapT,t.texParameteri(this.target,t.TEXTURE_WRAP_T,s))}}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 Zt(e,t,s,i,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=s;return s===e.RED&&(i===e.FLOAT&&(A=e.R32F),i===e.HALF_FLOAT&&(A=e.R16F),i===e.UNSIGNED_BYTE&&(A=e.R8)),s===e.RG&&(i===e.FLOAT&&(A=e.RG32F),i===e.HALF_FLOAT&&(A=e.RG16F),i===e.UNSIGNED_BYTE&&(A=e.RG8)),s===e.RGBA&&(i===e.FLOAT&&(A=e.RGBA32F),i===e.HALF_FLOAT&&(A=e.RGBA16F),i===e.UNSIGNED_BYTE&&(A=3001===r&&!1===n?e.SRGB8_ALPHA8:e.RGBA8),i===e.UNSIGNED_SHORT_4_4_4_4&&(A=e.RGBA4),i===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||zt(e,"EXT_color_buffer_float"),A}function Jt(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function Yt(e){if(!$t(e.width)||!$t(e.height)){const t=document.createElement("canvas");t.width=qt(e.width),t.height=qt(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function $t(e){return 0==(e&e-1)}function qt(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class es extends ie{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new xe({texture:new Kt({gl:this.scene.canvas.gl}),matrix:R.identityMat4(),hasMatrix:t.translate&&(0!==t.translate[0]||0!==t.translate[1])||!!t.rotate||t.scale&&(0!==t.scale[0]||0!==t.scale[1]),maxAnisotropy:t.maxAnisotropy,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=R.vec2([0,0]),this._scale=R.vec2([1,1]),this._rotate=R.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),L.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,s;0===this._translate[0]&&0===this._translate[1]||(t=R.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=R.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?R.mulMat4(t,s):s),0!==this._rotate&&(s=R.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?R.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=Yt(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 s=new Image;s.onload=function(){s=Yt(s),t._state.texture.setImage(s,t._state),t.scene.loading--,t.glRedraw(),t.scene.canvas.spinner.processes--},s.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(),L.memory.textures--}}const ts=R.vec3(),ss=R.vec3();R.vec3();const is=R.vec3([0,-1,0]),rs=R.vec4([0,0,0,1]);class ns extends Ht{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new xe({type:"LambertMaterial",ambient:R.vec3([1,1,1]),color:R.vec3([1,1,1]),emissive:R.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 As={opaque:0,mask:1,blend:2},os=["opaque","mask","blend"];class as extends Ht{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new xe({type:"MetallicMaterial",baseColor:R.vec4([1,1,1]),emissive:R.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=As[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 os[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 ls={opaque:0,mask:1,blend:2},cs=["opaque","mask","blend"];class hs extends Ht{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new xe({type:"SpecularMaterial",diffuse:R.vec3([1,1,1]),emissive:R.vec3([0,0,0]),specular:R.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=ls[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 cs[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 us={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 ds extends Ht{get type(){return"EmphasisMaterial"}get presets(){return us}constructor(e,t={}){super(e,t),this._state=new xe({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=us[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(us).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 ps={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 fs extends Ht{get type(){return"EdgeMaterial"}get presets(){return ps}constructor(e,t={}){super(e,t),this._state=new xe({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=ps[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(ps).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class gs extends ie{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=R.vec3(t.pos||[0,0,0]),this._up=R.vec3(t.up||[0,1,0]),this._normal=R.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=R.vec3(),this._rtcPos=R.vec3(),this._imageSize=R.vec2(),this._texture=new es(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 ct(this,{matrix:R.inverseMat4(R.lookAtMat4v(this._pos,R.subVec3(this._pos,this._normal,R.mat4()),this._up,R.mat4())),children:[this._bitmapMesh=new Ot(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new Le(this,Ze({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new jt(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 ms=(e,t)=>{const s=[];let i=[];function r(e,s){let i,r;for(let n=0;n<3;n++)if(i=t[3*e+n],r=t[3*s+n],i!==r)return r-i;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]),s[n[e]]=A;for(let t=0,r=e.length;t<r;t+=3){const r=s[e[t]],n=s[e[t+1]],A=s[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)),i[t+0]=[o,a],i[t+1]=[a,l],o>l){const e=l;l=o,o=e}i[t+2]=[l,o]}function o(e,t){let s,i;for(let r=0;r<2;r++)if(s=e[r],i=t[r],i!==s)return i-s;return 0}i=i.slice(0,e.length),i.sort(o);let a=0;for(let e=0;e<i.length;e++)if(0===e||0!==o(i[e],i[e-1])){if(0!==e&&2!==a)return!1;a=1}else a++;return!(i.length>0&&2!==a)},_s=R.vec3(),bs=R.vec3(),ys=R.vec3();class Bs{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&&!ms(t,e))return-1;let s=0;for(let i=0;i<this.lenIndices;i+=3){const r=3*t[i],n=3*t[i+1],A=3*t[i+2];_s[0]=e[r],_s[1]=e[r+1],_s[2]=e[r+2],bs[0]=e[n],bs[1]=e[n+1],bs[2]=e[n+2],ys[0]=e[A],ys[1]=e[A+1],ys[2]=e[A+2],R.cross3Vec3(_s,bs,_s),s+=R.dotVec3(_s,ys)}return s/6}}const ws=new Bs,vs=R.vec3(),Cs=R.vec3(),Ms=R.vec3(),Es=R.vec3(),Fs=R.vec3(),xs=R.vec3();class Us{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 s=0;for(let i=0;i<this.lenIndices;i+=3){const r=3*t[i],n=3*t[i+1],A=3*t[i+2];vs[0]=e[r],vs[1]=e[r+1],vs[2]=e[r+2],Cs[0]=e[n],Cs[1]=e[n+1],Cs[2]=e[n+2],Ms[0]=e[A],Ms[1]=e[A+1],Ms[2]=e[A+2],R.subVec3(vs,Cs,Es),R.subVec3(Ms,Cs,Fs),s+=.5*R.lenVec3(R.cross3Vec3(Es,Fs,xs))}return s}}const Is=new Us,Ts=R.OBB3(),Ps=R.OBB3(),Ss=R.OBB3();class Ds{constructor(e,t,s,i,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=R.AABB3(),this._aabbWorldDirty=!1,this.layer=A,this.portionId=o,this._color=new Uint8Array([s[0],s[1],s[2],i]),this._colorize=new Uint8Array([s[0],s[1],s[2],i]),this._colorizing=!1,this._transparent=i<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 s=e<255,i=this._transparent!==s;this._color[3]=e,this._colorize[3]=e,this._transparent=s,this._colorizing?this.layer.setColor(this.portionId,this._colorize):this.layer.setColor(this.portionId,this._color),i&&this.layer.setTransparent(this.portionId,t,s)}_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,s,i){return this.layer.precisionRayPickSurface(this.portionId,e,t,s,i)}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":ws.reset(),ws.setPrimitive(this.layer.primitive),this.getEachVertex((e=>{ws.addVertex(e)})),this.getEachIndex((e=>{ws.addIndex(e)})),this._volume=ws.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":Is.reset(),this.getEachVertex((e=>{Is.addVertex(e)})),this.getEachIndex((e=>{Is.addIndex(e)})),this._surfaceArea=Is.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&&(R.AABB3ToOBB3(this._aabbLocal,Ts),this.transform?(R.transformOBB3(this.transform.worldMatrix,Ts,Ps),R.transformOBB3(this.model.worldMatrix,Ps,Ss),R.OBB3ToAABB3(Ss,this._aabbWorld)):(R.transformOBB3(this.model.worldMatrix,Ts,Ps),R.OBB3ToAABB3(Ps,this._aabbWorld)),this._aabbWorldDirty=!1),this._aabbWorld}_destroy(){this.model.scene._renderer.putPickID(this.pickId),this.layer=null}}const ks=1,Qs=4,Rs=8,Os=16,Vs=32,Ls=256,Hs=512,Ns=1024,Gs=2048,js=function(e,t,s,i){const r=i&&e.createUniform("vec4","edgeColor",((e,t)=>e(t.legacyFrameCtx.programColor))),n=t.attributes.color,A=!i&&e.createVarying("vec4","vColor",(()=>`vec4(${n}.rgb * 0.5, ${n}.a)`)),o=e.createOutput("vec4","outColor");return{programName:i?"Edges":"EdgesColor",getLogDepth:s&&(e=>e),renderPassFlag:2,appendFragmentOutputs:e=>e.push(`${o} = ${r||A};`)}},zs=function(e){const t=e.createOutput("vec4","outColor");return{programName:"Occlusion",renderPassFlag:0,appendFragmentOutputs:e=>e.push(`${t} = vec4(0.0, 0.0, 1.0, 1.0);`)}},Ws=function(e,t,s,i){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:s&&(e=>e),renderPassFlag:1,appendFragmentOutputs:(e,t,s,o)=>{e.push(`${A} = ${i?r:o(`vec4(${r}.rgb, min(${r}.a, ${n}))`)};`)}}},Xs=R.vec2(),Ks=R.vec3(),Zs=R.vec4(),Js=R.mat4(),Ys=R.vec3([0,0,0]),$s=0,qs=1,ei=2,ti=3,si=4,ii=5,ri=6,ni=7,Ai=8,oi=9,ai=10,li=11,ci=e=>[R.safeInv(e[0]),R.safeInv(e[1]),R.safeInv(e[2])],hi=(e,t,s,i,r)=>{const n=!!(e&ks),A=!!(e&Ls),o=!!(e&Hs),a=!!(e&Ns),l=!!(e&Gs),c=!!(e&Rs),h=!!(e&Qs);let u,d;u=!n||h||A||o&&!i.highlightMaterial.glowThrough||a&&!i.selectedMaterial.glowThrough?$s:t?ei:qs,d=!n||h?$s:a?si:o?ti:A?ii:$s;let p=0;p=s&&n&&!h?a?oi:o?Ai:A?ai:l?t?ni:ri:$s:$s;const f=n&&!h&&c?li:$s;r[0]=u,r[1]=d,r[2]=p,r[3]=f},ui=function(){const e={};return function(t,s,i,r,n,A,o,a){const l=[s,"points"===i||"lines"===i?i:"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=bt(),o=A.programVariables,l=a(o,n);return r(o,l.geometryParameters,(function(r,a){const c=t.pointsMaterial,h="points"===i&&!n,u=()=>[t._sectionPlanesState.getHash()].concat(h?[c.hash]:[]).concat(r.getHash?r.getHash():[]).join(";"),d=u(),p=()=>d===u(),f=l.geometryParameters,g=r.incrementDrawState,m=r.isShadowProgram,_=f.attributes,b=_.position.world,y="clipPos",[B,w]=A.buildProgram(e,s+" "+i+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:y,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 s=o.createUniform("float","nearPlaneHeight",((e,t)=>e(t.legacyFrameCtx.nearPlaneHeight))),i=`${Math.floor(c.minPerspectivePointSize)}.0`,r=`${Math.floor(c.maxPerspectivePointSize)}.0`;e.push(`clamp((${s} * ${t}) / gl_Position.w, ${i}, ${r})`)}else e.push(t)}else n&&n.vertices&&e.push("1.0");return r.incPointSizeBy10&&"points"===i&&e.push("10.0"),e.length>0&&(()=>e.join(" + "))}(),getVertexData:()=>{const e=_.color,t=_.flags[r.renderPassFlag],s=o.createUniform("int","renderPass",((e,t)=>e(t.renderPass))),n=[`if (${m?`(${t} <= 0) || (${e}.a < 1.0)`:`${t} != ${s}`}) {`,` 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"===i&&c.filterIntensity?function(){const t=o.createUniform("vec2","intensityRange",(e=>{Xs[0]=c.minIntensity,Xs[1]=c.maxIntensity,e(Xs)}));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=f.attributes.position.view;return A.push(`vec4 ${a} = ${f.viewMatrix} * ${b};`),A.push(`vec4 clipPos = ${f.projMatrix} * ${a};`),A},projMatrix:f.projMatrix,sectionPlanesState:t._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==i&&"lines"!==i||n,usePickClipPos:a,worldPositionAttribute:b});return w?(console.error(w),{getValid:p,destroy:()=>{},drawLayer:(e,t,s)=>{}}):{getValid:p,destroy:()=>B.destroy(),drawLayer:(e,t,s)=>{e.lastProgramId!==B.id&&(e.lastProgramId=B.id,B.bind());const i=t.origin,r=t.model,A=e.viewParams,o=Ks;R.transformPoint3(r.matrix,i,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:s,view:{eye:A.eye,far:A.far,projMatrix:c,viewMatrix:R.compareVec3(o,Ys)?a:ut(a,o,Js),viewNormalMatrix:A.viewNormalMatrix}};B.inputSetters.setUniforms(e,h),t.drawCalls[n?n.vertices?"drawVertices":"drawEdges":"drawSurface"](B.inputSetters.attributesHash,l.layerTypeInputs,{projMatrix:c,viewMatrix:R.compareVec3(o,Ys)?a:ut(a,o,Js),viewNormalMatrix:A.viewNormalMatrix,eye:A.eye}),g&&e.drawElements++}}}))};let l=A&&o();return{drawLayer:(e,t,s)=>{l||(l=o()),l.drawLayer(e,t,s)},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),p=(e,s,r,n)=>function(e,t,s,i,r,n){const A=e.createVarying("vec4","vColor",(()=>{const e=t.attributes,s="points"===n?`vec4(${e.color}.rgb, 1.0)`:`${e.color}`;return i?`vec4(${[i.getAmbientColor()].concat(i.directionalLights.map((s=>`max(dot(${e.normal.view}, ${s.getDirection(t.viewMatrix,e.position.view)}), 0.0) * ${s.getColor()}`))).join(" + ")}, 1) * ${s}`:s})),o=e.createOutput("vec4","outColor");return{programName:"Color",getHash:()=>[i?i.getHash():"-",r?"sao":"nosao"],cleanerEdges:!0,getLogDepth:s&&(e=>"points"!==n&&"lines"!==n?`${e} + length(vec2(dFdx(${e}), dFdy(${e})))`:e),renderPassFlag:0,appendFragmentOutputs:(e,t,s,i)=>{"points"===n||"lines"===n?e.push(`${o} = ${A};`):(e.push(`vec4 fragColor = ${i(A)};`),e.push(`${o} = ${r?`vec4(fragColor.rgb * ${r.getAmbient(s)}, fragColor.a)`:"fragColor"};`))},filterIntensityRange:!0,incrementDrawState:!0}}(e,s,t.logarithmicDepthBufferEnabled,r,n,i),f=(e,s,i)=>i(function(e,t,s){const i=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:s&&(e=>e),renderPassFlag:3,incPointSizeBy10:!0,appendFragmentOutputs:e=>{e.push(`float zNormalizedDepth = abs((${r} + ${n}.z) / (${i} - ${r}));`),e.push(`${A} = ${o}(zNormalizedDepth);`)}}}(e,s,t.logarithmicDepthBufferEnabled),!0),g=(e,s,i)=>i(function(e,t,s){const i=e.createVarying("vec4","vPickColor",(()=>`${t.attributes.pickColor} / 255.0`)),r=e.createOutput("vec4","outPickColor");return{programName:"PickMesh",getLogDepth:s&&(e=>e),renderPassFlag:3,incPointSizeBy10:!0,dontCullOnAlphaZero:!0,appendFragmentOutputs:e=>e.push(`${r} = ${i};`)}}(e,s,t.logarithmicDepthBufferEnabled),!0),m=(e,s,i,r)=>i(function(e,t,s,i){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:i?"PickNormalsFlat":"PickNormals",getLogDepth:s&&(e=>e),renderPassFlag:3,appendFragmentOutputs:e=>{const t=i?`normalize(cross(dFdx(${r}), dFdy(${r})))`:n;e.push(`${A} = ivec4(${t} * float(${R.MAX_INT}), 1.0);`)}}}(e,s,t.logarithmicDepthBufferEnabled,r),!0),_=(e,t,s,i,r)=>s(function(e,t,s,i){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:s?"SnapInit":"Snap",getLogDepth:e=>s?`${e} + length(vec2(dFdx(${e}), dFdy(${e})))`:e,renderPassFlag:3,vertexCullX:!s&&"2.0",dontCullOnAlphaZero:!s,appendFragmentOutputs:e=>{e.push(`${a} = ivec4(${A} * ${n}.xyz, ${s?"-":""}${r});`),s&&(e.push(`${l} = ${i?"ivec4(1.0)":`ivec4(normalize(cross(dFdx(${A}), dFdy(${A}))) * float(${R.MAX_INT}), 1.0)`};`),e.push(`${c} = uvec4(${o});`))}}}(e,t,i,r),!0);c[h]="points"===i?{colorRenderers:{"sao-":{vertex:d(((e,t,s)=>s(p(e,t,null,null))))}},occlusionRenderer:d(((e,t,s)=>s(zs(e)))),pickDepthRenderer:d(f),pickMeshRenderer:d(g),silhouetteRenderer:d(((e,s,i)=>i(Ws(e,s,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:d(((e,t,s)=>_(e,t,s,!0,!0))),snapVertexRenderer:d(((e,t,s)=>_(e,t,s,!1,!0)),{vertices:!0})}:"lines"===i?{colorRenderers:{"sao-":{vertex:d(((e,t,s)=>s(p(e,t,null,null))))}},silhouetteRenderer:d(((e,s,i)=>i(Ws(e,s,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:d(((e,t,s)=>_(e,t,s,!0,!1))),snapEdgeRenderer:d(((e,t,s)=>_(e,t,s,!1,!1)),{vertices:!1}),snapVertexRenderer:d(((e,t,s)=>_(e,t,s,!1,!1)),{vertices:!0})}:{colorRenderers:function(){const e=e=>yt(e,t._lightsState),s=e=>{const t=e.createUniform("vec4","uSAOParams",((e,t)=>e(t.legacyFrameCtx.saoParams))),s=Bt(e,"sampler2D","uOcclusionTexture",3e3,((e,t)=>e(t.legacyFrameCtx.occlusionTexture)));return{getAmbient:e=>{const i=`${t}.w`;return`(smoothstep(${`${t}.z`}, 1.0, dot(${s(`${e}.xy / ${t}.xy`)}, (255. / 256.) / vec4(256. * 256. * 256., 256. * 256., 256., 1.))) * ${i})`}}},i=function(i){const r=(r,n,A)=>function(e,t,s,i,r,n,A){const o=Bt(e,"sampler2D","uColorMap",3001,((e,t)=>{const s=t.layerTextureSet.colorTexture;s&&e(s.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:()=>[i.getHash(),r?"sao":"nosao",!!A,n?"alphaCutoffYes":"alphaCutoffNo"],getLogDepth:s.logarithmicDepthBufferEnabled&&(e=>e),renderPassFlag:0,appendFragmentOutputs:(e,s,n,A)=>{e.push(`vec3 viewNormal = normalize(cross(dFdx(${c}), dFdy(${c})));`),e.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);"),i.directionalLights.forEach((s=>{e.push(`reflectedColor += max(dot(viewNormal, ${s.getDirection(t.viewMatrix,c)}), 0.0) * ${s.getColor()};`)})),e.push(`vec4 color = vec4(${i.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);`),s&&e.push(`${d} = ${s(d)};`)},incrementDrawState:!0}}(r,n,t,e(r),i&&s(r),A,t.gammaOutput);return{PBR:n&&d(((r,n,A)=>A(function(e,t,s,i,r){const n=(t,s,i)=>Bt(e,"sampler2D",t,s?3001:3e3,((e,t)=>{const s=i(t.layerTextureSet);s&&e(s.texture)})),A=t.attributes,o=i.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`)),p=e.createVarying("vec3","vViewNormal",(()=>A.normal.view)),f=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"),y=e.createFragmentDefinition("saturate",((e,t)=>t.push(`float ${e}(const in float a) { return clamp(a, 0.0, 1.0); }`))),B=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 = ${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("}")})),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 = ${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("}")})),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:()=>[i.getHash(),r?"sao":"nosao",!!s.gammaOutput],getLogDepth:s.logarithmicDepthBufferEnabled&&(e=>e),renderPassFlag:0,clippingCaps:s._sectionPlanesState.clippingCaps&&b,incrementDrawState:!0,appendFragmentOutputs:(e,s,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 = ${f}.rgb;`),e.push(`float opacity = ${f}.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(${p}), ${g}, ${h(g)});`),e.push(`vec3 viewEyeDir = normalize(${d});`),o&&e.push(`reflDiff += ${o(`normalize(${_})`)};`),i.getReflection){const s=`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=i.getReflection(s,n),o=`${w}(viewNormal, viewEyeDir, specularColor, specularRoughness)`;e.push(`reflSpec += ${A} * ${o};`)}i.directionalLights.forEach(((s,i)=>{e.push(`vec3 lightDirection${i} = -${s.getDirection(t.viewMatrix,d)};`);const r=`${y}(dot(viewNormal, lightDirection${i}))`;e.push(`vec3 irradiance${i} = ${r} * ${s.getColor()};`),e.push(`reflDiff += irradiance${i};`),e.push(`reflSpec += irradiance${i} * PI * ${B}(lightDirection${i}, viewNormal, viewEyeDir, specularColor, specularRoughness);`)})),e.push(`vec3 emissiveColor = ${c(g)}.rgb;`),e.push(`float aoFactor = ${u(g)}.r;`);const A=`${i.getAmbientColor()} * baseColor * opacity * rgb`;e.push(`vec3 outgoingLight = emissiveColor + reflDiff * diffuseColor + reflSpec + ${A};`),e.push(`${b} = vec4(outgoingLight * aoFactor${r?` * ${r.getAmbient(n)}`:""}, opacity);`),s&&e.push(`${b} = ${s(b)};`)}}}(r,n,t,e(r),i&&s(r))))),texture:A&&{"alphaCutoff-":d(((e,t,s)=>s(r(e,t,!1)))),"alphaCutoff+":d(((e,t,s)=>s(r(e,t,!0))))},vertex:d(o?(t,r,n)=>n(p(t,r,e(t),i&&s(t))):(r,n,A)=>A(function(e,t,s,i,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:()=>[i.getHash(),r?"sao":"nosao"],cleanerEdges:!0,getLogDepth:s&&(e=>e),renderPassFlag:0,appendFragmentOutputs:(e,s,n,l)=>{e.push(`vec3 viewNormal = normalize(cross(dFdx(${A}), dFdy(${A})));`);const c=[i.getAmbientColor()].concat(i.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),i&&s(r))))}};return{"sao-":i(!1),"sao+":r&&i(!0)}}(),depthRenderer:d(((e,s,i)=>i(function(e,t,s){const i=e.createVarying("highp vec2","vHighPrecisionZW",(()=>`${t.attributes.position.clip}.zw`)),r=e.createOutput("vec4","outColor");return{programName:"Depth",getLogDepth:s&&(e=>e),renderPassFlag:0,appendFragmentOutputs:e=>e.push(`${r} = vec4(vec3((1.0 - ${i}[0] / ${i}[1]) / 2.0), 1.0);`)}}(e,s,t.logarithmicDepthBufferEnabled)))),edgesRenderers:{uniform:d(((e,s,i)=>i(js(e,s,t.logarithmicDepthBufferEnabled,!0))),{vertices:!1}),vertex:d(((e,s,i)=>i(js(e,s,t.logarithmicDepthBufferEnabled,!1))),{vertices:!1})},occlusionRenderer:d(((e,t,s)=>s(zs(e)))),pickDepthRenderer:u(f),pickMeshRenderer:u(g),pickNormalsFlatRenderer:u(((e,t,s)=>m(e,t,s,!0))),pickNormalsRenderer:u(((e,t,s)=>m(e,t,s,!1))),shadowRenderer:d(((e,s,i)=>i(function(e,t){const s=e.createOutput("vec4","outColor"),i=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(`${s} = ${i}(${r}.z);`)}}(e,t)))),silhouetteRenderer:u(((e,s,i)=>i(Ws(e,s,t.logarithmicDepthBufferEnabled,!1)))),snapInitRenderer:u(((e,t,s)=>_(e,t,s,!0,!1))),snapEdgeRenderer:u(((e,t,s)=>_(e,t,s,!1,!1)),{vertices:!1}),snapVertexRenderer:u(((e,t,s)=>_(e,t,s,!1,!1)),{vertices:!0})};const b=e=>{!function t(s){s.revalidate?s.revalidate(e):Object.values(s).forEach((e=>e&&t(e)))}(c[h])},y=()=>b(!1);y(),t.on("compile",y),t.on("destroyed",(()=>{delete c[h]}))}return c[h]}}();class di{constructor(e,t,s){this.model=e,this.primitive=t,this.origin=s,this._meshes=[],this._aabb=R.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 s={count:0,fromFlags:(i,r)=>{i&e?(s.count++,this.model[t]++):r||(s.count--,this.model[t]--)}};this._countsByFlag[e]=s};e(ks,"numVisibleLayerPortions"),e(Qs,"numCulledLayerPortions"),e(Rs,"numPickableLayerPortions"),e(Os,"numClippableLayerPortions"),e(Ls,"numXRayedLayerPortions"),e(Hs,"numHighlightedLayerPortions"),e(Ns,"numSelectedLayerPortions"),this._renderers.edgesRenderers&&e(Gs,"numEdgesLayerPortions"),this._countsByFlagArr=Object.values(this._countsByFlag),this._numTransparentLayerPortions=0}}aabbChanged(){this._aabbDirty=!0}getAABB(){return this._aabbDirty&&(R.collapseAABB3(this._aabb),this._meshes.forEach((e=>R.expandAABB3(this._aabb,e.aabb))),this._aabbDirty=!1),this._aabb}__drawLayer(e,t,s,i){if(this._countsByFlag[Qs].count<this._portions.length&&this._countsByFlag[ks].count>0){const e="points"!==this.primitive&&"lines"!==this.primitive&&[qs,ei,li,ti,si,ii];if(e&&e.includes(i)){const e=!0;if(t.backfaces!==e){const s=this.model.scene.canvas.gl;s.disable(s.CULL_FACE),t.backfaces=e}}t.textureUnit=0,s.drawLayer(t,this,i)}}__setVec4FromMaterialColorAlpha(e,t,s){return s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=t,s}__drawColor(e,t,s){if((s?this._numTransparentLayerPortions<this._portions.length:this._numTransparentLayerPortions>0)&&this._countsByFlag[Ls].count<this._portions.length){const i=s&&t.withSAO&&this._renderers.colorRenderers["sao+"]||this._renderers.colorRenderers["sao-"],r=t.pbrEnabled&&i.PBR?i.PBR:t.colorTextureEnabled&&i.texture?i.texture[this.layerTextureSet&&"number"==typeof this.layerTextureSet.alphaCutoff?"alphaCutoff+":"alphaCutoff-"]:i.vertex,n=s?qs:ei;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 s=this._renderers.depthRenderer;s&&this._numTransparentLayerPortions<this._portions.length&&this._countsByFlag[Ls].count<this._portions.length&&this.__drawLayer(e,t,s,qs)}__drawSilhouette(e,t,s,i){t.programColor=this.__setVec4FromMaterialColorAlpha(s.fillColor,s.fillAlpha,Zs),this.__drawLayer(e,t,this._renderers.silhouetteRenderer,i)}drawSilhouetteXRayed(e,t){this._countsByFlag[Ls].count>0&&this.__drawSilhouette(e,t,this.model.scene.xrayMaterial,ii)}drawSilhouetteHighlighted(e,t){this._countsByFlag[Hs].count>0&&this.__drawSilhouette(e,t,this.model.scene.highlightMaterial,ti)}drawSilhouetteSelected(e,t){this._countsByFlag[Ns].count>0&&this.__drawSilhouette(e,t,this.model.scene.selectedMaterial,si)}__drawVertexEdges(e,t,s){const i=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.vertex;i&&this._countsByFlag[Gs].count>0&&this.__drawLayer(e,t,i,s)}drawEdgesColorOpaque(e,t){this.__drawVertexEdges(e,t,ri)}drawEdgesColorTransparent(e,t){this._numTransparentLayerPortions>0&&this.__drawVertexEdges(e,t,ni)}__drawUniformEdges(e,t,s,i){const r=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.uniform;r&&(t.programColor=this.__setVec4FromMaterialColorAlpha(s.edgeColor,s.edgeAlpha,Zs),this.__drawLayer(e,t,r,i))}drawEdgesHighlighted(e,t){this._countsByFlag[Hs].count>0&&this.__drawUniformEdges(e,t,this.model.scene.highlightMaterial,Ai)}drawEdgesSelected(e,t){this._countsByFlag[Ns].count>0&&this.__drawUniformEdges(e,t,this.model.scene.selectedMaterial,oi)}drawEdgesXRayed(e,t){this._countsByFlag[Ls].count>0&&this.__drawUniformEdges(e,t,this.model.scene.xrayMaterial,ai)}__drawPick(e,t,s){s&&this.__drawLayer(e,t,s,li)}drawPickMesh(e,t){this.__drawPick(e,t,this._renderers.pickMeshRenderer)}drawPickDepths(e,t){this.__drawPick(e,t,this._renderers.pickDepthRenderer)}drawPickNormals(e,t){const s=this._renderers.pickNormalsFlatRenderer;this.__drawPick(e,t,s)}drawSnap(e,t,s){t.snapPickOrigin=[0,0,0];const i=this.getAABB();t.snapPickCoordinateScale=R.mulVec3Scalar(ci([i[3]-i[0],i[4]-i[1],i[5]-i[2]]),R.MAX_INT);const r=s?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:ci(t.snapPickCoordinateScale)})}drawOcclusion(e,t){const s=this._renderers.occlusionRenderer;s&&this.__drawLayer(e,t,s,qs)}drawShadow(e,t){const s=this._renderers.shadowRenderer;s&&this.__drawLayer(e,t,s,qs)}initFlags(e,t,s){this._countsByFlagArr.forEach((e=>e.fromFlags(t,!0))),s&&(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++);const i="points"!==this.primitive;this._setFlags(e,t,s,i),this._compiledPortions.setFlags2(e,t,i)}flushInitFlags(){this._compiledPortions.setDeferredFlags()}setVisible(e,t,s){this._countsByFlag[ks].fromFlags(t),this._setFlags(e,t,s)}setCulled(e,t,s){this._countsByFlag[Qs].fromFlags(t),this._setFlags(e,t,s)}setPickable(e,t,s){this._countsByFlag[Rs].fromFlags(t),this._setFlags(e,t,s)}setClippable(e,t){this._countsByFlag[Os].fromFlags(t),this._compiledPortions.setClippableFlags(e,t)}setCollidable(e,t){}setXRayed(e,t,s){this._countsByFlag[Ls].fromFlags(t),this._setFlags(e,t,s)}setHighlighted(e,t,s){this._countsByFlag[Hs].fromFlags(t),this._setFlags(e,t,s)}setSelected(e,t,s){this._countsByFlag[Ns].fromFlags(t),this._setFlags(e,t,s)}setEdges(e,t,s){this._countsByFlag[Gs]&&(this._countsByFlag[Gs].fromFlags(t),this._setFlags(e,t,s))}setTransparent(e,t,s){s?(this._numTransparentLayerPortions++,this.model.numTransparentLayerPortions++):(this._numTransparentLayerPortions--,this.model.numTransparentLayerPortions--),this._setFlags(e,t,s)}destroy(){this._compiledPortions&&this._compiledPortions.destroy()}}let pi=65536,fi=5e6;class gi{constructor(){}set doublePrecisionEnabled(e){R.setDoublePrecisionEnabled(e)}get doublePrecisionEnabled(){return R.getDoublePrecisionEnabled()}set maxDataTextureHeight(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),pi=e}get maxDataTextureHeight(){return pi}set maxGeometryBatchSize(e){e<1e5?e=1e5:e>5e6&&(e=5e6),fi=e}get maxGeometryBatchSize(){return fi}}const mi=e=>{const t=[];for(let s=0;s<e;++s)t.push(s);return t},_i={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(_i,null,4));let e=0;Object.keys(_i).forEach((t=>{t.startsWith("size")&&(e+=_i[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/_i.totalPolygons).toFixed(2)}`);let t={};Object.keys(_i).forEach((s=>{s.startsWith("size")&&(t[s]=`${(_i[s]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};const bi=new gi,yi=bi.maxDataTextureHeight,Bi=R.vec3(),wi=R.vec3(),vi=R.vec4();R.vec4();const Ci=new Float32Array(16),Mi=new Uint8Array(4),Ei=R.identityMat4();class Fi extends di{constructor(e,t,s){super(e,t,s),_i.numberOfLayers++,this._sortId=`TriDTX-${_i.numberOfLayers}`;const i=e.scene.canvas.gl,r=(e,t)=>{const s=[];let r=0;const A=[];let o=0;const a=[];let l=0;const c=[];let h=0;return{len:()=>o,accumulateIndices:(i,u)=>{const d=i&&i.length>0&&function(){const t=r/3;r+=i.length,s.push(i);const a=i.length/3;return s=>{const i=o;o+=3*a,n.perObjectIndexBaseOffsets.push(i/3-t);for(let e=0;e<a;e+=8)A.push(s);_i[e]+=a,_i.totalPolygons+=a}}(),p=u&&function(){const e=l/2;l+=u.length,a.push(u);const s=u.length/2;return i=>{const r=h;h+=2*s,n.perObjectEdgeIndexBaseOffsets.push(r/2-e);for(let e=0;e<s;e+=8)c.push(i);_i[t]+=s,_i.totalEdges+=s}}();return _i.numberOfGeometries++,{numTriangles:i?i.length/3:0,accumulateSubPortionId:e=>{d&&d(e),p&&p(e)}}},createDrawers:(e,t)=>{const n=function(t,s){return t.length>0?e([t],t.length,1,i.UNSIGNED_SHORT,"sizeDataTexturePortionIds"):s},u=n(A,{texture:null}),d=r>0&&e(s,r,3,t,"sizeDataTextureIndices"),p=n(c),f=l>0&&e(a,l,2,t,"sizeDataTextureEdgeIndices");return{indices:function(e,t){o>0&&(e.perPrimIndices.setInputValue(d),e.perPrimIdPorIds.setInputValue(u),i.drawArrays(t,0,o))},edges:function(e,t){h>0&&(e.perPrimIndices.setInputValue(f),e.perPrimIdPorIds.setInputValue(p),i.drawArrays(t,0,h))}}},_clearToOptimizeGC:()=>{s.length=a.length=0}}},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&&_i.cannotCreatePortion.because10BitsObjectId++;let s=this._portions.length+t<=65536;const i=void 0!==e.geometryId&&null!==e.geometryId?`${e.geometryId}#0`:`${e.id}#0`;if(!this._bucketGeometries[i]){const t=this._buffer,i=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*yi||i+n>4096*yi)&&_i.cannotCreatePortion.becauseTextureSize++,s&&=this._numVertices+r<=4096*yi&&i+n<=4096*yi}return s}createPortion(e,t){const s=this._buffer,i=t.buckets.map(((e,i)=>{const r=(t.geometryId??t.id)+"#"+i;if(!(r in this._bucketGeometries)){const t=(e,t,s)=>{if(e){const i=8*Math.ceil(e.length/t/8)*t,r=new Uint32Array(i);return r.set(e),_i[s]+=2*(r.length-e.length),r}return e};e.indices=t(e.indices,3,"overheadSizeAlignementIndices"),e.edgeIndices=t(e.edgeIndices,2,"overheadSizeAlignementEdgeIndices");const i=e.positionsCompressed;s.positionsCompressed.push(i);const n=i.length/3;this._numVertices+=n;const A=s.lenPositionsCompressed/3;s.lenPositionsCompressed+=i.length,this._bucketGeometries[r]={vertexBase:A,geometryData:function(){const t=e.indices,i=e.edgeIndices;return n<=256?s.geometry8Bits.accumulateIndices(t,i):n<=65536?s.geometry16Bits.accumulateIndices(t,i):s.geometry32Bits.accumulateIndices(t,i)}()}}const n=this._bucketGeometries[r];s.perObjectPositionsDecodeMatrices.push(t.positionsDecodeMatrix),s.perObjectInstancePositioningMatrices.push(t.meshMatrix||Ei),s.perObjectSolid.push(!!t.solid),s.perObjectPickColors.push(t.pickColor),s.perObjectVertexBases.push(n.vertexBase);const A=t.colors,o=t.color;s.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}),_i.numberOfPortions++,a})),r=this._portionToSubPortionsMap.length;return this._portionToSubPortionsMap.push(i),this.model.numPortions++,this._meshes.push(e),r}compilePortions(){const e=this._buffer,t=this.model,s=this._portions.length,i=this.origin,r=this._portionToSubPortionsMap,n=this._primitive,A=this._sortId,o=this._subPortionReadableGeometries,a=t.scene,l=a.canvas.gl,c=xi(l,s,32,l.UNSIGNED_BYTE,512,(t=>{const i=e=>[e>>24&255,e>>16&255,e>>8&255,255&e];for(let r=0;r<s;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(i(e.perObjectVertexBases[r]),32*r+16),t.set(i(e.perObjectIndexBaseOffsets[r]),32*r+20),t.set(i(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,s,i,r,n,A){return xi(l,t,s,i,r,(t=>{for(let s=0,i=0,r=e.length;s<r;s++){const r=e[s];t.set(r,i),i+=r.length}}),n,A)},d=function(e,t,s){const i=e.length;if(0===i)throw"num "+t+" matrices===0";return u(e,i,16,l.FLOAT,512,t,s)},p=d(e.perObjectInstancePositioningMatrices,"sizeDataInstancesMatrices",!0),f=p.textureData,g=d(e.perObjectPositionsDecodeMatrices,"sizeDataPositionDecodeMatrices",!1),m=function(e,t,s,i,r){return u(e,t/s,s,i,4096,r,!1)},_=m(e.positionsCompressed,e.lenPositionsCompressed,3,l.UNSIGNED_SHORT,"sizeDataTexturePositions"),b=e.geometry8Bits.createDrawers(m,l.UNSIGNED_BYTE),y=e.geometry16Bits.createDrawers(m,l.UNSIGNED_SHORT),B=e.geometry32Bits.createDrawers(m,l.UNSIGNED_INT);this._bucketGeometries=null,this._buffer.geometry8Bits._clearToOptimizeGC(),this._buffer.geometry16Bits._clearToOptimizeGC(),this._buffer.geometry32Bits._clearToOptimizeGC(),Object.keys(this._buffer).forEach((e=>this._buffer[e]=null)),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})),x=(e,s)=>{const i=r[e];if(i)for(let e=0,t=i.length;e<t;e++)s(i[e]);else t.error("portion not found: "+e)},U=(e,t,s,i)=>{const r=w||i;r?v=!0:++M>=10&&E(),h.setData(s,e,t,!r)},I=(e,t,s=!1)=>{Mi.set([t&Os?255:0,0,1,2]),x(e,(e=>U(e,3,Mi,s)))};return{sortId:A,setClippableFlags:I,setFlags:(e,t,s,i=!1)=>{hi(t,s,!0,a,Mi),x(e,(e=>U(e,2,Mi,i)))},setFlags2:I,setDeferredFlags:()=>{},setColor:(e,t)=>{Mi.set(t),x(e,(e=>U(e,0,Mi,!1)))},setMatrix:(e,t)=>{x(e,(e=>{const s=w;s?v=!0:++M>=10&&E(),Ci.set(t),f.setData(Ci,e,0,!s)}))},setOffset:(e,t)=>{},getEachIndex:(e,t)=>{o&&x(e,(e=>o[e].indices.forEach((e=>t(e)))))},getEachVertex:(e,s)=>{o&&x(e,(e=>{const r=o[e],n=r.positionsCompressed,A=r.positionsDecodeMatrix,a=vi;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,R.decompressPosition(a,A),R.mulMat4v4(t.worldMatrix,a,a),R.addVec3(i,a,a),s(a)}))},precisionRayPickSurface:(e,t,s,i,r)=>!1,renderers:ui(a,"dtx",n,t.saoEnabled,!1,!1,!0,((e,t)=>Ui(e,!t))),drawCalls:function(){const e=function(e){const s=(e,t)=>e.setInputValue&&e.setInputValue(t);return(r,n,A)=>{s(n.worldMatrix,t.rotationMatrix),s(n.viewMatrix,A.viewMatrix),s(n.projMatrix,A.projMatrix);const o=R.transformPoint3(t.matrix,i,Bi);s(n.uCameraEyeRtc,R.subVec3(A.eye,o,wi)),s(n.perObjPosDecode,g),s(n.perVertIdCoords,_),s(n.perObjColsFlags,c),s(n.perObjectMatrix,p),e(n)}},s=function(t){return e((e=>{b.edges(e,t),y.edges(e,t),B.edges(e,t)}))};return{drawVertices:s(l.POINTS),drawEdges:s(l.LINES),drawSurface:e((e=>{const t=l.TRIANGLES;b.indices(e,t),y.indices(e,t),B.indices(e,t)}))}}(),destroy:()=>{C||(a.off(F),C=!0)}}}}const xi=function(e,t,s,i,r,n,A,o){if(s>4&&s%4>0)throw"Unhandled data size "+s;const a=Math.ceil(s/4),l=s/a,[c,h,u]=function(){switch(i){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 "+i}}(),d=r*a,p=Math.ceil(t/r);if(0===p)throw"texture height===0";let f=new c(d*p*l);_i[A]+=f.byteLength,_i.numberOfTextures++,n(f);const g=e.createTexture();return e.bindTexture(e.TEXTURE_2D,g),e.texStorage2D(e.TEXTURE_2D,1,h,d,p),e.texSubImage2D(e.TEXTURE_2D,0,0,0,d,p,u,i,f),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),o||(f=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(f.set(t,n*s+A*l),o){e.bindTexture(e.TEXTURE_2D,g);const s=n%r*a+A,o=Math.floor(n/r),c=t.length/l;e.texSubImage2D(e.TEXTURE_2D,0,s,o,c,1,u,i,t)}},reloadData(){e.bindTexture(e.TEXTURE_2D,g),e.texSubImage2D(e.TEXTURE_2D,0,0,0,d,p,u,i,f)}}}},Ui=function(e,t){const s=(t,s)=>{const i=e.createUniform(t,s),r=e=>`texelFetch(${i}, ${e}, 0)`;return r.map=i,r},i=s("highp usampler2D","perPrimIndices"),r=s("mediump usampler2D","perPrimIdPorIds"),n=s("highp sampler2D","perObjPosDecode"),A=s("mediump usampler2D","perVertIdCoords"),o=s("lowp usampler2D","perObjColsFlags"),a=s("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},p=d("colorA"),f=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:p,flags:mi(4).map((e=>`int(flags[${e}])`)),metallicRoughness:null,normal:{view:m,world:g},pickColor:f,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)};`),p.needed&&e.push(`vec4 ${p} = vec4(${_(0)}) / 255.0;`)},appendVertexData:e=>{const s=e=>a(`ivec2(objectIndexCoords.x*4+${e}, objectIndexCoords.y)`);e.push(`mat4 objectInstanceMatrix = mat4(${s(0)}, ${s(1)}, ${s(2)}, ${s(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(${i("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;f.needed&&e.push(`vec4 pickColor = vec4(${_(1)});`),e.push(`vec4 worldPosition = ${l} * (objectDecodeAndInstanceMatrix * vec4(position, 1.0));`)},layerTypeInputs:{perPrimIndices:i.map,perPrimIdPorIds:r.map,perObjPosDecode:n.map,perVertIdCoords:A.map,perObjColsFlags:o.map,perObjectMatrix:a.map,worldMatrix:l,viewMatrix:c,projMatrix:h,uCameraEyeRtc:u}}},Ii=R.mat4(),Ti=R.mat4();function Pi(e,t,s){const i=e.length,r=new Uint16Array(i),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,p=h/c,f=e=>e>=0?e:0;for(let t=0;t<i;t+=3)r[t+0]=Math.floor(f(e[t+0]-n)*u),r[t+1]=Math.floor(f(e[t+1]-A)*d),r[t+2]=Math.floor(f(e[t+2]-o)*p);return R.identityMat4(Ii),R.translationMat4v(t,Ii),R.identityMat4(Ti),R.scalingMat4v([a/h,l/h,c/h],Ti),R.mulMat4(Ii,Ti,s),r}function Si(e,t){const s=e[0],i=e[1],r=e[2],n=e[3]-s||1,A=e[4]-i||1,o=e[5]-r||1,a=65525;return R.identityMat4(Ii),R.translationMat4v(e,Ii),R.identityMat4(Ti),R.scalingMat4v([n/a,A/a,o/a],Ti),R.mulMat4(Ii,Ti,t),t}function Di(e,t,s){let i=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=i,t=r;e=(1-Math.abs(r))*(i>=0?1:-1),t=(1-Math.abs(i))*(r>=0?1:-1),i=e,r=t}return new Int8Array([Math[t](127.5*i+(i<0?-1:0)),Math[s](127.5*r+(r<0?-1:0))])}function ki(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const i=1-Math.abs(t)-Math.abs(s);i<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const r=Math.sqrt(t*t+s*s+i*i);return[t/r,s/r,i/r]}const Qi=new Float32Array(1),Ri=new Float32Array(4),Oi=new Float32Array(3),Vi=R.mat4(),Li=R.vec4([0,0,0,1]),Hi=R.vec4(),Ni=R.vec3(),Gi=R.vec3(),ji=R.vec3(),zi=R.vec3(),Wi=R.vec3(),Xi=R.vec3(),Ki=R.vec3(),Zi=new Uint8Array(4),Ji=new Float32Array(96),Yi=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t},$i=function(e,t){e.set(t);let s=t.length;const i=e.length;for(;s<i;){const t=Math.min(s,i-s);e.set(e.subarray(0,t),s),s+=t}},qi=function(){let e=0;const t=new Map;return{acquire:()=>e++,release:()=>{e--,0===e&&t.clear()},getTypeArray:function(e,s){t.has(e)||t.set(e,{});const i=t.get(e);return s in i||(i[s]=new e(s)),i[s]}}}();class er extends di{constructor(e,t,s,i){super(e,t,s);const r=!!i.geometry;this._maxVerts=i.maxGeometryBatchSize;const n=r?i.geometry.positionsDecodeMatrix:i.positionsDecodeMatrix;this._positionsDecodeMatrix=n&&R.mat4(n),this._cfgUvDecodeMatrix=i.uvDecodeMatrix&&R.mat3(i.uvDecodeMatrix),this._instancedGeometry=i.geometry,this._textureSet=i.textureSet,this._modelAABB=!r&&R.collapseAABB3(),this._portions=[];const A=function(){let e=0;const t=[];return{length:()=>e,append:function(s,i=1,r=1,n=0){e+=i*s.length,t.push({data:s,times:i,denormalizeScale:r,increment:n})},compileBuffer:function(e){let s=0;t.forEach((e=>{s+=e.times*e.data.length}));const i=new e(s);let r=0;return t.forEach((e=>{const t=e.data,s=e.denormalizeScale,n=e.increment,A=i.subarray(r);if(1===s&&0===n)A.set(t);else for(let e=0;e<t.length;++e)A[e]=n+t[e]*s;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})),i},_clearToOptimizeGC:()=>{t.length=0}}};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 s=this._buffer,i=this._instancedGeometry,r=this.model,n=this._portions.length,A=this.primitive,o=!!this._positionsDecodeMatrix,a=r.scene,l=t.meshMatrix,c=(i,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:i,portionSize:o,retainedGeometry:a.readableGeometryEnabled&&"points"!==A&&"lines"!==A&&{indices:l,quantizedPositions:c,offset:a.entityOffsetsEnabled&&R.vec3(),matrix:h&&h.slice(),inverseMatrix:null,normalMatrix:null}};return"points"!==A&&"lines"!==A&&s.metallicRoughness.append([t.metallic??0,t.roughness??255],o),"lines"!==A&&s.pickColors.append(t.pickColor.slice(0,4),o),this._portions.push(d),r.numPortions++,this._meshes.push(e),n};if(i){if(s.modelMatrixCol.forEach(((e,t)=>e.append([l[t+0],l[t+4],l[t+8],l[t+12]]))),"points"!==A){const e=t.color;s.colors.append([e[0],e[1],e[2],t.opacity??255])}if("points"!==A&&"lines"!==A&&i.normals){const e=R.inverseMat4(R.transposeMat4(l,R.mat4()));s.modelNormalMatrixCol.forEach(((t,s)=>t.append([e[s+0],e[s+4],e[s+8],e[s+12]])))}return c(n,1,i.indices,i.positionsCompressed,l)}{const e=s.positions.length()/3,i=o?t.positionsCompressed:t.positions;if(!i)throw(o?"positionsCompressed":"positions")+" expected";s.positions.append(i);const r=i.length/3,n=t.indices;n&&s.indices.append(n,1,1,e);const a=t.normalsCompressed,h=t.normals;if(a&&a.length>0)s.normals.append(a);else if(h&&h.length>0){const e=Vi;l?(R.transposeMat4(l,e),R.inverseMat4(e,e)):R.identityMat4(e);const t=[];!function(e,t,s,i,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<s;h+=3)u[0]=t[h],u[1]=t[h+1],u[2]=t[h+2],R.transformVec3(e,u,d),R.normalizeVec3(d,d),a=A=Di(d,"floor","floor"),o=ki(A),l=c=n(d,o),A=Di(d,"ceil","floor"),o=ki(A),l=n(d,o),l>c&&(a=A,c=l),A=Di(d,"floor","ceil"),o=ki(A),l=n(d,o),l>c&&(a=A,c=l),A=Di(d,"ceil","ceil"),o=ki(A),l=n(d,o),l>c&&(a=A,c=l),i[r+h+0]=a[0],i[r+h+1]=a[1],i[r+h+2]=0}(e,h,h.length,t,0),s.normals.append(t)}const u=t.colors,d=t.colorsCompressed,p=t.color;if(u)if("points"===A)s.colors.append(u,1,255);else{const e=[];for(let t=0,s=u.length;t<s;t+=3)e.push(255*u[t]),e.push(255*u[t+1]),e.push(255*u[t+2]),e.push(255);s.colors.append(e)}else if(d)if("points"===A)s.colors.append(d);else{const e=[];for(let t=0,s=d.length;t<s;t+=3)e.push(d[t]),e.push(d[t+1]),e.push(d[t+2]),e.push(255);s.colors.append(e)}else p&&s.colors.append([p[0],p[1],p[2],"points"===A?1:t.opacity],r);const f=e=>e&&e.length>0&&e,g=f(t.uv)||f(t.uvCompressed);g&&s.uv.append(g);const m=t.edgeIndices;return m&&s.edgeIndices.append(m,1,1,e),R.expandAABB3(this._modelAABB,t.aabb),c(e,r,n)}}compilePortions(){const e=this._buffer,t=this._instancedGeometry,s=this.model,i=this._modelAABB,r=this.origin,n=this._portions,A=this.primitive,o=this._textureSet;let a=this._positionsDecodeMatrix;const l=this._cfgUvDecodeMatrix,c=s.scene,h=c.canvas.gl,u=!!t,d=[],p=(e,t,s,i)=>{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,i)};l(t);const c=t.BYTES_PER_ELEMENT,u=t.length/s;return{bindBuffer:a,getData:(t=0,i=u-t)=>{a();const A=new r(i*s);return h.getBufferSubData(e,t*n*s,A,0,i*s),A},numItems:u,setData:l,setSubData:(t,s)=>{a(),h.bufferSubData(e,s*c,t)},type:A}}return null},f=(e,t,s,i=!1,r=!1)=>{const n=p(h.ARRAY_BUFFER,e,t,s);return n&&{getData:n.getData,numItems:n.numItems,setData:n.setData,setSubData:n.setSubData,attributeDivisor:i&&1,bindAtLocation:e=>{n.bindBuffer(),h.vertexAttribPointer(e,t,n.type,!!r,0,0)}}},g=e=>{const t=p(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),_=f(new Float32Array(m),1,h.DYNAMIC_DRAW,u),b=(e,t)=>f(e,4,t,u&&"points"!==A,!0),y=u&&t.colorsCompressed?b(new Uint8Array(t.colorsCompressed),h.STATIC_DRAW):b(e.colors.compileBuffer(Uint8Array),h.DYNAMIC_DRAW),B=c.entityOffsetsEnabled&&f(new Float32Array(3*m),3,h.DYNAMIC_DRAW,u),w=f(e.metallicRoughness.compileBuffer(Uint8Array),2,h.STATIC_DRAW,u),v=f(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):Pi(e.positions.compileBuffer(Float64Array),i,a=R.mat4()),x=F&&f(F,3,h.STATIC_DRAW);if(!u)for(let e=0;e<n.length;++e){const t=n[e];if(t.retainedGeometry){const e=3*t.portionBase;t.retainedGeometry.quantizedPositions=F.subarray(e,e+3*t.portionSize)}}const U=u&&e.modelMatrixCol.map((e=>f(e.compileBuffer(Float32Array),4,h.STATIC_DRAW,!0))),I=!u&&e.normals.compileBuffer(Int8Array),T=I&&f(I,3,h.STATIC_DRAW,!1,!0),P=U&&T&&e.modelNormalMatrixCol.map((e=>f(e.compileBuffer(Float32Array),4,h.STATIC_DRAW,!0))),S=u?"points"!==A&&"lines"!==A&&t.uvCompressed&&{buf:f(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:f(t,2,h.STATIC_DRAW),mat:l};{const e=Re.getUVBounds(t),s=Re.compressUVs(t,e.min,e.max);return{buf:f(s.quantized,2,h.STATIC_DRAW),mat:R.mat3(s.decodeMatrix)}}}();Object.values(this._buffer).forEach((e=>e._clearToOptimizeGC?e._clearToOptimizeGC():e.forEach((e=>e._clearToOptimizeGC())))),this._buffer=null,qi.acquire(),d.push((()=>qi.release()));let D=null;const k=(e,s,i,r=!1)=>{hi(s,i,"points"!==A&&"lines"!==A,c,Zi);const o=s&Os?1:0;let a=0;a|=Zi[0],a|=Zi[1]<<4,a|=Zi[2]<<8,a|=Zi[3]<<12,a|=o<<16,Qi[0]=a;const l=n[e],h=l.portionBase,u=l.portionSize;if(r&&!t)D||(D=new Float32Array(m)),$i(D.subarray(h,h+u),Qi);else if(_){const e=qi.getTypeArray(Float32Array,u);$i(e,Qi),_.setSubData(e,h)}},Q="solid"===A;return{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,s)=>{},setDeferredFlags:()=>{D&&(_.setData(D),D=null)},setColor:(e,t)=>{if(y){const s=n[e],i=qi.getTypeArray(Uint8Array,4*s.portionSize);$i(i,t.slice(0,4)),y.setSubData(i,4*s.portionBase)}},setMatrix:(e,t)=>{U&&U.forEach(((s,i)=>{Ri[0]=t[i+0],Ri[1]=t[i+4],Ri[2]=t[i+8],Ri[3]=t[i+12],s.setSubData(Ri,4*e)}))},setOffset:(e,t)=>{if(c.entityOffsetsEnabled){const s=n[e];if(B){Oi.set(t);const e=qi.getTypeArray(Float32Array,3*s.portionSize);$i(e,Oi),B.setSubData(e,3*s.portionBase)}s.retainedGeometry&&s.retainedGeometry.offset.set(t)}else s.error("Entity#offset not enabled for this Viewer")},getEachIndex:(e,t)=>{const s=n[e].retainedGeometry;s&&s.indices.forEach((e=>t(e)))},getEachVertex:(e,t)=>{const i=n[e].retainedGeometry;if(i){const e=Hi;r?e.set(r,0):e[0]=e[1]=e[2]=0,e[3]=1;const n=s.matrix,A=i.quantizedPositions,o=Li;for(let s=0,r=A.length;s<r;s+=3)o[0]=A[s],o[1]=A[s+1],o[2]=A[s+2],R.decompressPosition(o,a),i.matrix&&R.transformPoint3(i.matrix,o,o),o[3]=1,R.addVec3(e,o,o),R.mulMat4v4(n,o,o),t(o)}},readGeometryData:"points"!==A&&"lines"!==A&&(e=>{const t=!u&&n[e],i=t?E.getData(t.indicesBaseIndex,t.numIndices).map((e=>e-t.portionBase)):E.getData(),A=s.matrix,o=R.vec4();o.set(r,0),o[3]=1,R.mulMat4v4(A,o,o);const l=U&&R.mat4();if(l){const t=U[0].getData(e,1),s=U[1].getData(e,1),i=U[2].getData(e,1);l.set([t[0],s[0],i[0],0,t[1],s[1],i[1],0,t[2],s[2],i[2],0,t[3],s[3],i[3],1])}const c=R.mat4();R.mulMat4(A,l?R.mulMat4(l,a,c):a,c),c[12]+=o[0],c[13]+=o[1],c[14]+=o[2];const h=t?x.getData(t.portionBase,t.portionSize):x.getData();return{indices:i,positions:R.transformPositions3(c,h,new Float64Array(h.length))}}),precisionRayPickSurface:(e,t,i,A,o)=>{const l=n[e].retainedGeometry;if(l){l.matrix&&!l.inverseMatrix&&(l.inverseMatrix=R.inverseMat4(l.matrix,R.mat4())),o&&l.inverseMatrix&&!l.normalMatrix&&(l.normalMatrix=R.transposeMat4(l.inverseMatrix,R.mat4()));const e=l.quantizedPositions,n=l.indices,c=l.offset,h=Ni,u=Gi;h.set(r?R.subVec3(t,r,ji):t),u.set(i),c&&R.subVec3(h,c),R.transformRay(s.worldNormalMatrix,h,u,h,u),l.inverseMatrix&&R.transformRay(l.inverseMatrix,h,u,h,u);const d=zi,p=Wi,f=Xi;let g=!1,m=0;const _=Ki;for(let i=0,b=n.length;i<b;i+=3){const b=3*n[i],y=3*n[i+1],B=3*n[i+2];if(d[0]=e[b],d[1]=e[b+1],d[2]=e[b+2],p[0]=e[y],p[1]=e[y+1],p[2]=e[y+2],f[0]=e[B],f[1]=e[B+1],f[2]=e[B+2],R.decompressPosition(d,a),R.decompressPosition(p,a),R.decompressPosition(f,a),R.rayTriangleIntersect(h,u,d,p,f,_)){l.matrix&&R.transformPoint3(l.matrix,_,_),R.transformPoint3(s.worldMatrix,_,_),c&&R.addVec3(_,c),r&&R.addVec3(_,r);const e=Math.abs(R.lenVec3(R.subVec3(_,t,[])));(!g||e>m)&&(m=e,A.set(_),o&&R.triangleNormal(d,p,f,o),g=!0)}}return g&&o&&(l.normalMatrix&&R.transformVec3(l.normalMatrix,o,o),R.transformVec3(s.worldNormalMatrix,o,o),R.normalizeVec3(o)),g}return!1},layerTextureSet:o,renderers:ui(c,u?"instancing":"batching",A,s.saoEnabled,s.pbrEnabled&&S&&o&&o.colorTexture&&T&&w&&o.metallicRoughnessTexture,s.colorTextureEnabled&&S&&o&&o.colorTexture,!!T,(e=>sr(e,u&&{hasModelNormalMat:!!P},c.entityOffsetsEnabled))),drawCalls:function(){const e={},t=t=>(i,r,o)=>{let l=0;Ji.set(s.rotationMatrix,0),Ji.set(o.viewMatrix,l+=16),Ji.set(o.projMatrix,l+=16),Ji.set(a,l+=16),r.needNormal()&&(Ji.set(s.worldNormalMatrix,l+=16),Ji.set(o.viewNormalMatrix,l+=16)),r.matrices.setInputValue(Ji),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(S.mat),i in e||(e[i]=[null,null,null]);const c=e[i],p=t?t.vertices?0:1:2;if(!c[p]){const e=h.createVertexArray();h.bindVertexArray(e);const s=(e,t)=>{e&&e.setInputValue&&t&&e.setInputValue(t)},i=r.attributes;s(i.position,x),s(i.normal,T),s(i.color,y),s(i.pickColor,v),s(i.uV,S&&S.buf),s(i.metallicRoughness,w),s(i.flags,_),s(i.offset,B),i.modelMatrixCol&&i.modelMatrixCol.forEach(((e,t)=>s(e,U[t]))),i.modelNormalMatrixCol&&i.modelNormalMatrixCol.forEach(((e,t)=>s(e,P[t])));const o=function(){const e=()=>{u?h.drawArraysInstanced(h.POINTS,0,x.numItems,n.length):h.drawArrays(h.POINTS,0,x.numItems)},s=(e,t)=>{t.bindIndicesBuffer();const s=t.indicesCount,i=t.indicesType;return()=>{u?h.drawElementsInstanced(e,s,i,0,n.length):h.drawElements(e,s,i,0)}};return"points"===A?e:"lines"===A?t&&t.vertices?e:s(h.LINES,E):t&&t.vertices?e:t?C?s(h.LINES,C):()=>{}:s(h.TRIANGLES,E)}();h.bindVertexArray(null),d.push((()=>h.deleteVertexArray(e))),c[p]=()=>{h.bindVertexArray(e),o(),h.bindVertexArray(null)}}c[p]()};return{drawVertices:t({vertices:!0}),drawEdges:t({}),drawSurface:t(null)}}(),destroy:()=>{d.forEach((e=>e())),d.length=0}}}}const tr=function(e){const t={toString:()=>(t.needed=!0,e)};return t},sr=function(e,t,s){const i=e.createAttribute,r={position:i("vec3","positionA"),normal:i("vec3","normalA"),color:i("vec4","colorA"),pickColor:i("vec4","pickColor"),uV:i("vec2","uvApremul"),metallicRoughness:i("vec2","metallicRoughness"),flags:i("float","flagsA"),offset:s&&i("vec3","offset"),modelMatrixCol:t&&Yi(3).map((e=>i("vec4","modelMatrixCol"+e))),modelNormalMatrixCol:t&&t.hasModelNormalMat&&Yi(3).map((e=>i("vec4","modelNormalMatrixCol"+e)))},n=tr("aUv"),A=tr("viewNormal"),o=tr("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:Yi(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 s=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)${s?" * "+s:""});`),r.offset&&t.push(`worldPosition.xyz = worldPosition.xyz + ${r.offset};`),l()){const s=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)${s||""};`),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 ir{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 rr{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const nr={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 Ar{constructor(e,t,s){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=s}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,s=this.handlers.length;t<s;t+=2){const s=this.handlers[t],i=this.handlers[t+1];if(s.global&&(s.lastIndex=0),s.test(e))return i}return null}}const or=new Ar;class ar{constructor(e){this.manager=void 0!==e?e:or,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(e,t){const s=this;return new Promise((function(i,r){s.load(e,i,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 lr={};class cr extends ar{constructor(e){super(e)}load(e,t,s,i){void 0===e&&(e=""),void 0!==this.path&&(e=this.path+e),e=this.manager.resolveURL(e);const r=nr.get(e);if(void 0!==r)return this.manager.itemStart(e),q.scheduleTask((()=>{t&&t(r),this.manager.itemEnd(e)}),0),r;if(void 0!==lr[e])return void lr[e].push({onLoad:t,onProgress:s,onError:i});lr[e]=[],lr[e].push({onLoad:t,onProgress:s,onError:i});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 s=lr[e],i=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(){i.read().then((({done:i,value:r})=>{if(i)e.close();else{o+=r.byteLength;const i=new ProgressEvent("progress",{lengthComputable:A,loaded:o,total:n});for(let e=0,t=s.length;e<t;e++){const t=s[e];t.onProgress&&t.onProgress(i)}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),s=t&&t[1]?t[1].toLowerCase():void 0,i=new TextDecoder(s);return e.arrayBuffer().then((e=>i.decode(e)))}}})).then((t=>{nr.add(e,t);const s=lr[e];delete lr[e];for(let e=0,i=s.length;e<i;e++){const i=s[e];i.onLoad&&i.onLoad(t)}})).catch((t=>{const s=lr[e];if(void 0===s)throw this.manager.itemError(e),t;delete lr[e];for(let e=0,i=s.length;e<i;e++){const i=s[e];i.onError&&i.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 hr{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 s=this.workersResolve[e];if(s&&s(t),this.queue.length){const{resolve:t,msg:s,transfer:i}=this.queue.shift();this.workersResolve[e]=t,this.workers[e].postMessage(s,i)}else this.workerStatus^=1<<e}setWorkerCreator(e){this.workerCreator=e}setWorkerLimit(e){this.pool=e}postMessage(e,t){return new Promise((s=>{const i=this._getIdleWorker();-1!==i?(this._initWorker(i),this.workerStatus|=1<<i,this.workersResolve[i]=s,this.workers[i].postMessage(e,t)):this.queue.push({resolve:s,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 ur=0;class dr{constructor({viewer:e,transcoderPath:t,workerLimit:s}){this._transcoderPath=t||"https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/basis/",this._transcoderBinary=null,this._transcoderPending=null,this._workerPool=new hr,this._workerSourceURL="",s&&this._workerPool.setWorkerLimit(s);const i=e.capabilities;this._workerConfig={astcSupported:i.astcSupported,etc1Supported:i.etc1Supported,etc2Supported:i.etc2Supported,dxtSupported:i.dxtSupported,bptcSupported:i.bptcSupported,pvrtcSupported:i.pvrtcSupported},this._supportedFileTypes=["xkt2"]}_init(){if(!this._transcoderPending){const e=new cr;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new cr;s.setPath(this._transcoderPath),s.setResponseType("arraybuffer"),s.setWithCredentials(this.withCredentials);const i=s.loadAsync("basis_transcoder.wasm");this._transcoderPending=Promise.all([t,i]).then((([e,t])=>{const s=dr.BasisWorker.toString(),i=["/* constants */","let _EngineFormat = "+JSON.stringify(dr.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(dr.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(dr.BasisFormat),"/* basis_transcoder.js */",e,"/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join("\n");this._workerSourceURL=URL.createObjectURL(new Blob([i])),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}))})),ur>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),ur++}return this._transcoderPending}transcode(e,t,s={}){return new Promise(((i,r)=>{const n=s;this._init().then((()=>this._workerPool.postMessage({type:"transcode",buffers:e,taskConfig:n},e))).then((e=>{const s=e.data,{mipmaps:n,width:A,height:o,format:a,type:l,error:c,dfdTransferFn:h,dfdFlags:u}=s;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)}}),i()}))}))}destroy(){URL.revokeObjectURL(this._workerSourceURL),this._workerPool.destroy(),ur--}}dr.BasisFormat={ETC1S:0,UASTC_4x4:1},dr.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},dr.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},dr.BasisWorker=function(){let e,t,s;const i=_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=>{s={wasmBinary:h,onRuntimeInitialized:e},BASIS(s)})).then((()=>{s.initializeBasis(),void 0===s.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:p,dfdFlags:f}=function(t){const A=new s.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(),p=A.getLevels(),f=A.getHasAlpha(),g=A.getDFDTransferFunc(),m=A.getDFDFlags(),{transcoderFormat:_,engineFormat:b}=function(t,s,A,c){let h,u;const d=t===n.ETC1S?o:a;for(let i=0;i<d.length;i++){const r=d[i];if(e[r.if]&&(r.basisFormat.includes(t)&&!(c&&r.transcoderFormat.length<2)&&(!r.needsPowerOfTwo||l(s)&&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=i.RGBAFormat,{transcoderFormat:h,engineFormat:u}}(h,u,d,f);if(!u||!d||!p)throw c(),new Error("KTX2TextureTranscoder: Invalid texture");if(!A.startTranscoding())throw c(),new Error("KTX2TextureTranscoder: .startTranscoding failed");const y=[];for(let e=0;e<p;e++){const t=A.getImageLevelInfo(e,0,0),s=t.origWidth,i=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.");y.push({data:r,width:s,height:i})}return c(),{width:u,height:d,hasAlpha:f,mipmaps:y,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:p,dfdFlags:f},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:[i.RGBA_ASTC_4x4_Format,i.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:[i.RGBA_BPTC_Format,i.RGBA_BPTC_Format],priorityETC1S:3,priorityUASTC:2,needsPowerOfTwo:!1},{if:"dxtSupported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.BC1,r.BC3],engineFormat:[i.RGB_S3TC_DXT1_Format,i.RGBA_S3TC_DXT5_Format],priorityETC1S:4,priorityUASTC:5,needsPowerOfTwo:!1},{if:"etc2Supported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.ETC1,r.ETC2],engineFormat:[i.RGB_ETC2_Format,i.RGBA_ETC2_EAC_Format],priorityETC1S:1,priorityUASTC:3,needsPowerOfTwo:!1},{if:"etc1Supported",basisFormat:[n.ETC1S,n.UASTC_4x4],transcoderFormat:[r.ETC1],engineFormat:[i.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:[i.RGB_PVRTC_4BPPV1_Format,i.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 pr={};function fr(e){const t=e.scene.id;let s=pr[t];return s||(s=new dr({viewer:e}),pr[t]=s,e.scene.on("destroyed",(()=>{delete pr[t],s.destroy()}))),s}
8
8
  /**
9
9
  * @author https://github.com/tmarti, with support from https://tribia.com/
10
10
  * @license MIT
@@ -20,7 +20,7 @@
20
20
  /**
21
21
  * @author https://github.com/tmarti, with support from https://tribia.com/
22
22
  * @license MIT
23
- **/let yr=null;function Br(e,t){const s=3*e,i=3*t;let r,n,A,o,a,l;const c=Math.min(r=yr[s],n=yr[s+1],A=yr[s+2]),h=Math.min(o=yr[i],a=yr[i+1],l=yr[i+2]);if(c!==h)return c-h;const u=Math.max(r,n,A),d=Math.max(o,a,l);return u!==d?u-d:0}let wr=null;function vr(e,t){let s=wr[2*e]-wr[2*t];return 0!==s?s:wr[2*e+1]-wr[2*t+1]}function Cr(e,t,s=!1){const i=e.positionsCompressed||[],r=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e<t;e++)s[e]=e;yr=new Int32Array(e.length);for(let s=0,i=e.length;s<i;s++)yr[s]=e[s]>>t;s.sort(Br);const i=new Int32Array(e.length);for(let t=0,r=s.length;t<r;t++)i[3*t+0]=e[3*s[t]+0],i[3*t+1]=e[3*s[t]+1],i[3*t+2]=e[3*s[t]+2];return i}(e.indices||[],t),n=function(e){if(0===(e||[]).length)return[];let t=new Int32Array(e.length/2);for(let e=0,s=t.length;e<s;e++)t[e]=e;for(let t=0,s=e.length;t<s;t+=2)if(e[t]>e[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}wr=new Int32Array(e),t.sort(vr);const s=new Int32Array(e.length);for(let i=0,r=t.length;i<r;i++)s[2*i+0]=e[2*t[i]+0],s[2*i+1]=e[2*t[i]+1];return s}(e.edgeIndices||[]);function A(e,t){if(e>t){let s=e;e=t,t=s}function s(s,i){return s!==e?e-s:i!==t?t-i:0}let i=0,r=(n.length>>1)-1;for(;i<=r;){const e=r+i>>1,t=s(n[2*e],n[2*e+1]);if(t>0)i=e+1;else{if(!(t<0))return e;r=e-1}}return-i-1}const o=new Int32Array(n.length/2);o.fill(0);const a=i.length/3;if(a>8*(1<<t))return[e];const l=new Int32Array(a);l.fill(-1);const c=[];function h(){l.fill(-1);const e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:c.length};return c.push(e),e}let u=h();for(let t=0,s=r.length;t<s;t+=3){let s=0;const a=r[t],c=r[t+1],d=r[t+2];if(-1===l[a]&&s++,-1===l[c]&&s++,-1===l[d]&&s++,s+u.numPositions>u.maxNumPositions&&(u=h()),u.bucketNumber>8)return[e];let p;-1===l[a]&&(l[a]=u.numPositions++,u.positionsCompressed.push(i[3*a]),u.positionsCompressed.push(i[3*a+1]),u.positionsCompressed.push(i[3*a+2])),-1===l[c]&&(l[c]=u.numPositions++,u.positionsCompressed.push(i[3*c]),u.positionsCompressed.push(i[3*c+1]),u.positionsCompressed.push(i[3*c+2])),-1===l[d]&&(l[d]=u.numPositions++,u.positionsCompressed.push(i[3*d]),u.positionsCompressed.push(i[3*d+1]),u.positionsCompressed.push(i[3*d+2])),u.indices.push(l[a]),u.indices.push(l[c]),u.indices.push(l[d]),(p=A(a,c))>=0&&0===o[p]&&(o[p]=1,u.edgeIndices.push(l[n[2*p]]),u.edgeIndices.push(l[n[2*p+1]])),(p=A(a,d))>=0&&0===o[p]&&(o[p]=1,u.edgeIndices.push(l[n[2*p]]),u.edgeIndices.push(l[n[2*p+1]])),(p=A(c,d))>=0&&0===o[p]&&(o[p]=1,u.edgeIndices.push(l[n[2*p]]),u.edgeIndices.push(l[n[2*p+1]]))}const d=t/8*2,p=t/8,f=2*i.length+(r.length+n.length)*d;let g=0,m=-i.length/3;return c.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(s&&function(e,t){const s={},i={};let r=0;e.forEach((e=>{const t=e.indices,n=e.edgeIndices,A=e.positionsCompressed;for(let e=0,i=t.length;e<i;e+=3){const i=A[3*t[e]]+"_"+A[3*t[e]+1]+"_"+A[3*t[e]+2]+"/"+A[3*t[e+1]]+"_"+A[3*t[e+1]+1]+"_"+A[3*t[e+1]+2]+"/"+A[3*t[e+2]]+"_"+A[3*t[e+2]+1]+"_"+A[3*t[e+2]+2];s[i]=!0}r+=e.edgeIndices.length/2;for(let e=0,t=n.length;e<t;e+=2){const t=A[3*n[e]]+"_"+A[3*n[e]+1]+"_"+A[3*n[e]+2]+"/"+A[3*n[e+1]]+"_"+A[3*n[e+1]+1]+"_"+A[3*n[e+1]+2]+"/";i[t]=!0}}));{const e=t.indices;t.edgeIndices;const i=t.positionsCompressed;for(let t=0,r=e.length;t<r;t+=3){const r=i[3*e[t]]+"_"+i[3*e[t]+1]+"_"+i[3*e[t]+2]+"/"+i[3*e[t+1]]+"_"+i[3*e[t+1]+1]+"_"+i[3*e[t+1]+2]+"/"+i[3*e[t+2]]+"_"+i[3*e[t+2]+1]+"_"+i[3*e[t+2]+2];if(!(r in s))throw console.log("Not found "+r),"Ohhhh!"}}}(c,e),c)}const Mr=new Float32Array([0,0,0]),Er=new Uint16Array([0,0,0]);R.OBB3();class Fr{constructor(e,t,s,i,r,n){this._isObject=t,this.scene=e.scene,this.model=e,this.isSceneModelEntity=!0,this.meshes=i,this._numPrimitives=0,this._capMaterial=null;for(let e=0,t=this.meshes.length;e<t;e++){const t=this.meshes[e];t.parent=this,t.entity=this,this._numPrimitives+=t.numPrimitives}this.id=s,this.originalSystemId=R.unglobalizeObjectId(e.id,s),this._flags=r,this._aabb=R.AABB3(),this._aabbDirty=!0,this._offset=R.vec3(),this._colorizeUpdated=!1,this._opacityUpdated=!1,this._lodCullable=!!n,this._culled=!1,this._culledVFC=!1,this._culledLOD=!1,this._isObject&&e.scene._registerObject(this)}_transformDirty(){this._aabbDirty=!0,this.model._transformDirty()}_sceneModelDirty(){this._aabbDirty=!0;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._sceneModelDirty()}get aabb(){if(this._aabbDirty){R.collapseAABB3(this._aabb);for(let e=0,t=this.meshes.length;e<t;e++)R.expandAABB3(this._aabb,this.meshes[e].aabb);this._aabbDirty=!1}return this._aabb}get isEntity(){return!0}get isModel(){return!1}get isObject(){return this._isObject}get numPrimitives(){return this._numPrimitives}get numTriangles(){return this._numPrimitives}get visible(){return this._getFlag(ks)}set visible(e){if(!!(this._flags&ks)!==e){this._flags=e?this._flags|ks:this._flags&~ks;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setVisible(this._flags);this._isObject&&this.model.scene._objectVisibilityUpdated(this),this.model.glRedraw()}}get highlighted(){return this._getFlag(Hs)}set highlighted(e){if(!!(this._flags&Hs)!==e){this._flags=e?this._flags|Hs:this._flags&~Hs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setHighlighted(this._flags);this._isObject&&this.model.scene._objectHighlightedUpdated(this),this.model.glRedraw()}}get xrayed(){return this._getFlag(Ls)}set xrayed(e){if(!!(this._flags&Ls)!==e){this._flags=e?this._flags|Ls:this._flags&~Ls;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setXRayed(this._flags);this._isObject&&this.model.scene._objectXRayedUpdated(this),this.model.glRedraw()}}get selected(){return this._getFlag(Ns)}set selected(e){if(!!(this._flags&Ns)!==e){this._flags=e?this._flags|Ns:this._flags&~Ns;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setSelected(this._flags);this._isObject&&this.model.scene._objectSelectedUpdated(this),this.model.glRedraw()}}get edges(){return this._getFlag(Gs)}set edges(e){if(!!(this._flags&Gs)!==e){this._flags=e?this._flags|Gs:this._flags&~Gs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setEdges(this._flags);this.model.glRedraw()}}get culledVFC(){return!!this._culledVFC}set culledVFC(e){this._culledVFC=e,this._setCulled()}get culledLOD(){return!!this._culledLOD}set culledLOD(e){this._culledLOD=e,this._setCulled()}get culled(){return!!this._culled}set culled(e){this._culled=e,this._setCulled()}_setCulled(){let e=!!this._culled||!(!this._culledLOD||!this._lodCullable)||!!this._culledVFC;if(!!(this._flags&Qs)!==e){this._flags=e?this._flags|Qs:this._flags&~Qs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setCulled(this._flags);this.model.glRedraw()}}get clippable(){return this._getFlag(Os)}set clippable(e){if(!!(this._flags&Os)!==e){this._flags=e?this._flags|Os:this._flags&~Os;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setClippable(this._flags);this.model.glRedraw()}}get collidable(){return this._getFlag(Vs)}set collidable(e){if(!!(this._flags&Vs)!==e){this._flags=e?this._flags|Vs:this._flags&~Vs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setCollidable(this._flags)}}get pickable(){return this._getFlag(Rs)}set pickable(e){if(!!(this._flags&Rs)!==e){this._flags=e?this._flags|Rs:this._flags&~Rs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setPickable(this._flags)}}get colorize(){if(0===this.meshes.length)return null;const e=this.meshes[0]._colorize;return Mr[0]=e[0]/255,Mr[1]=e[1]/255,Mr[2]=e[2]/255,Mr}set colorize(e){if(e){Er[0]=Math.floor(255*e[0]),Er[1]=Math.floor(255*e[1]),Er[2]=Math.floor(255*e[2]);for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setColorize(Er)}else for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setColorize(null);if(this._isObject){const t=!!e;this.scene._objectColorizeUpdated(this,t),this._colorizeUpdated=t}this.model.glRedraw()}get opacity(){return this.meshes.length>0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let i=255;if(t){if(e<0?e=0:e>1&&(e=1),i=Math.floor(255*e),s===i)return}else if(i=255,s===i)return;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setOpacity(i,this._flags);this._isObject&&(this.scene._objectOpacityUpdated(this,t),this._opacityUpdated=t),this.model.glRedraw()}get offset(){return this._offset}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.meshes.length;e<t;e++)this.meshes[e]._setOffset(this._offset);this._aabbDirty=!0,this.model._aabbDirty=!0,this.scene._aabbDirty=!0,this.scene._objectOffsetUpdated(this,e),this.model.glRedraw()}get saoEnabled(){return this.model.saoEnabled}set capMaterial(e){if(!this.scene.readableGeometryEnabled)throw"The `capMaterial` assignment requires `Viewer::readableGeometryEnabled` to be `true`";this._capMaterial=e,this.scene._sectionCaps._onCapMaterialUpdated(this)}get capMaterial(){return this._capMaterial}getEachVertex(e){for(let t=0,s=this.meshes.length;t<s;t++)this.meshes[t].getEachVertex(e)}getEachIndex(e){for(let t=0,s=this.meshes.length;t<s;t++)this.meshes[t].getEachIndex(e)}getGeometryData(){let e=0;const t=[],s=[];for(let i=0,r=this.meshes.length;i<r;i++){const r=this.meshes[i];if(r.layer.readGeometryData){const i=r.layer.readGeometryData(r.portionId);for(let t=0,r=i.indices.length;t<r;t++)s.push(i.indices[t]+e);for(let e=0,s=i.positions.length;e<s;e++)t.push(i.positions[e]);e+=i.positions.length/3}}return{indices:s,positions:t}}get volume(){let e=0;for(let t=0,s=this.meshes.length;t<s;t++){const s=this.meshes[t].volume;if(s<0)return-1;e+=s}return e}get surfaceArea(){let e=0;for(let t=0,s=this.meshes.length;t<s;t++){const s=this.meshes[t].surfaceArea;s>=0&&(e+=s)}return e>0?e:-1}_getFlag(e){return!!(this._flags&e)}_finalize(){const e=this.model.scene;this._isObject&&(this.visible&&e._objectVisibilityUpdated(this),this.highlighted&&e._objectHighlightedUpdated(this),this.xrayed&&e._objectXRayedUpdated(this),this.selected&&e._objectSelectedUpdated(this));for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._finalize(this._flags)}_finalize2(){for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._finalize2()}_destroy(){const e=this.model.scene;this._isObject&&(e._deregisterObject(this),this.visible&&e._deRegisterVisibleObject(this),this.xrayed&&e._deRegisterXRayedObject(this),this.selected&&e._deRegisterSelectedObject(this),this.highlighted&&e._deRegisterHighlightedObject(this),this._colorizeUpdated&&this.scene._deRegisterColorizedObject(this),this._opacityUpdated&&this.scene._deRegisterOpacityObject(this),!this._offset||0===this._offset[0]&&0===this._offset[1]&&0===this._offset[2]||this.scene._deRegisterOffsetObject(this));for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._destroy();e._aabbDirty=!0}}const xr=R.vec4(4),Ur=R.vec4(),Ir=R.vec4(),Tr=R.vec3([1,0,0]),Pr=R.vec3([0,1,0]),Sr=R.vec3([0,0,1]);R.vec3(3),R.vec3(3);const Dr=R.identityMat4();class kr{constructor(e){this._model=e.model,this.id=e.id,this._parentTransform=e.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=R.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=R.identityMat4(new Float32Array(16)),this._worldMatrix=R.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,e.matrix?this.matrix=e.matrix:(this.scale=e.scale,this.position=e.position,e.quaternion||(this.rotation=e.rotation)),e.parent&&e.parent._addChildTransform(this)}_addChildTransform(e){this._childTransforms.push(e),e._parentTransform=this,e._transformDirty(),e._setSubtreeAABBsDirty(this)}_addMesh(e){this._meshes.push(e),e.transform=this}get parentTransform(){return this._parentTransform}get meshes(){return this._meshes}set position(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),R.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._model.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),R.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._model.glRedraw()}get quaternion(){return this._quaternion}set scale(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.glRedraw()}get scale(){return this._scale}set matrix(e){this._localMatrix||(this._localMatrix=R.identityMat4()),this._localMatrix.set(e||Dr),R.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}get matrix(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=R.identityMat4()),R.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 xr[0]=e[0],xr[1]=e[1],xr[2]=e[2],xr[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(xr,Ur),R.mulQuaternions(this.quaternion,Ur,Ir),this.quaternion=Ir,this._setLocalMatrixDirty(),this._model.glRedraw(),this}rotateOnWorldAxis(e,t){return xr[0]=e[0],xr[1]=e[1],xr[2]=e[2],xr[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(xr,Ur),R.mulQuaternions(Ur,this.quaternion,Ur),this}rotateX(e){return this.rotate(Tr,e)}rotateY(e){return this.rotate(Pr,e)}rotateZ(e){return this.rotate(Sr,e)}translate(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateX(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateY(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateZ(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}_setLocalMatrixDirty(){this._localMatrixDirty=!0,this._transformDirty()}_transformDirty(){this._worldMatrixDirty=!0;for(let e=0,t=this._childTransforms.length;e<t;e++){const t=this._childTransforms[e];if(t._transformDirty(),t._meshes&&t._meshes.length>0){const e=t._meshes;for(let t=0,s=e.length;t<s;t++)e[t]._transformDirty()}}if(this._meshes&&this._meshes.length>0){const e=this._meshes;for(let t=0,s=e.length;t<s;t++)e[t]._transformDirty()}}_buildWorldMatrix(){const e=this.matrix;if(this._parentTransform)R.mulMat4(this._parentTransform.worldMatrix,e,this._worldMatrix);else for(let t=0,s=e.length;t<s;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_setSubtreeAABBsDirty(e){if(e._aabbDirty=!0,e._childTransforms)for(let t=0,s=e._childTransforms.length;t<s;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}const Qr=R.vec3(),Rr=R.OBB3(),Or=R.vec4(),Vr=R.vec3([1,1,1]),Lr=R.vec3([0,0,0]);R.vec3([0,0,0]);const Hr=R.identityQuaternion(),Nr=R.identityMat4(),Gr=new Uint8Array([255,255,255]);class jr extends ie{constructor(e,t={}){super(e,t),this.renderOrder=t.renderOrder||0,this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!1,this._textureTranscoder=t.textureTranscoder||fr(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize??5e6,this._aabb=R.collapseAABB3(),this._aabbDirty=!0,this._quantizationRanges={},this._vboLayers={},this._dtxLayers={},this._meshList=[],this.layerList=[],this._layersToFinalize=[],this._entityList=[],this._entitiesToFinalize=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._transforms={},this._meshes={},this._unusedMeshes={},this._entities={},this.renderFlags=new Mt,this.numGeometries=0,this.numPortions=0,this.numVisibleLayerPortions=0,this.numTransparentLayerPortions=0,this.numXRayedLayerPortions=0,this.numHighlightedLayerPortions=0,this.numSelectedLayerPortions=0,this.numEdgesLayerPortions=0,this.numPickableLayerPortions=0,this.numClippableLayerPortions=0,this.numCulledLayerPortions=0,this.numEntities=0,this._numTriangles=0,this._numLines=0,this._numPoints=0,this._layersFinalized=!1,this._edgeThreshold=t.edgeThreshold||10,this._origin=R.vec3(t.origin||[0,0,0]),this._position=R.vec3(t.position||[0,0,0]),this._rotation=R.vec3(t.rotation||[0,0,0]),this._quaternion=R.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=R.vec4(t.quaternion||[0,0,0,1]),t.rotation&&R.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=R.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=R.mat4(),this._worldRotationMatrixConjugate=R.mat4(),this._matrix=R.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=R.mat4(),R.inverseMat4(this._matrix,this._worldNormalMatrix),R.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=R.mat4(),this._viewNormalMatrix=R.mat4(),this._viewMatrixDirty=!0,this._matrixNonIdentity=!0),this._opacity=1,this._colorize=[1,1,1],this._saoEnabled=!1!==t.saoEnabled,this._pbrEnabled=!1!==t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()}));const s=(e,t)=>this._textures[e]=new rr({id:e,texture:new Kt({gl:this.scene.canvas.gl,preloadColor:t})});this._textureSets.defaultTextureSet=new ir({id:"defaultTextureSet",colorTexture:s("defaultColorTexture",[1,1,1,1]),metallicRoughnessTexture:s("defaultMetalRoughTexture",[0,1,1,1]),normalsTexture:s("defaultNormalsTexture",[0,0,0,0]),emissiveTexture:s("defaultEmissiveTexture",[0,0,0,1]),occlusionTexture:s("defaultOcclusionTexture",[1,1,1,1])}),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.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),R.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),R.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||Nr),R.decomposeMat4(this._matrix,this._position,this._quaternion,this._scale),R.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(R.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),R.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),R.quaternionToRotationMat4(this._conjugateQuaternion,this._worldRotationMatrixConjugate),R.scaleMat4v(this._scale,this._worldRotationMatrix),R.scaleMat4v(this._scale,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),R.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._viewMatrixDirty=!0)}get rotationMatrixConjugate(){return this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._sceneModelDirty()}get worldMatrix(){return this.matrix}get worldNormalMatrix(){return this._worldNormalMatrix}_rebuildViewMatrices(){this._rebuildMatrices(),this._viewMatrixDirty&&(R.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),R.inverseMat4(this._viewMatrix,this._viewNormalMatrix),R.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1)}get viewMatrix(){return this._viewMatrix?(this._rebuildViewMatrices(),this._viewMatrix):this.scene.camera.viewMatrix}get viewNormalMatrix(){return this._viewNormalMatrix?(this._rebuildViewMatrices(),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}get backfaces(){return this._backfaces}set backfaces(e){e=!!e,this._backfaces=e,this.glRedraw()}get entityList(){return this._entityList}get isEntity(){return!0}get isModel(){return this._isModel}get isObject(){return!1}get aabb(){if(this._aabbDirty){R.collapseAABB3(this._aabb);for(let e=0,t=this._entityList.length;e<t;e++)R.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}get numTriangles(){return this._numTriangles}get numLines(){return this._numLines}get numPoints(){return this._numPoints}get visible(){return this.numVisibleLayerPortions>0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].visible=e;this.glRedraw()}get xrayed(){return this.numXRayedLayerPortions>0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].xrayed=e;this.glRedraw()}get highlighted(){return this.numHighlightedLayerPortions>0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].highlighted=e;this.glRedraw()}get selected(){return this.numSelectedLayerPortions>0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].selected=e;this.glRedraw()}get edges(){return this.numEdgesLayerPortions>0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].edges=e;this.glRedraw()}get culled(){return this._culled}set culled(e){e=!!e,this._culled=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].culled=e;this.glRedraw()}get clippable(){return this._clippable}set clippable(e){e=!1!==e,this._clippable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].clippable=e;this.glRedraw()}get collidable(){return this._collidable}set collidable(e){e=!1!==e,this._collidable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].collidable=e}get pickable(){return this.numPickableLayerPortions>0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].pickable=e}get colorize(){return this._colorize}set colorize(e){this._colorize=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].colorize=e}get opacity(){return this._opacity}set opacity(e){this._opacity=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].opacity=e}get castsShadow(){return this._castsShadow}set castsShadow(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}get receivesShadow(){return this._receivesShadow}set receivesShadow(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}get saoEnabled(){return this._saoEnabled}get pbrEnabled(){return this._pbrEnabled}get colorTextureEnabled(){return this._colorTextureEnabled}get isDrawable(){return!0}get isStateSortable(){return!1}get xrayMaterial(){return this.scene.xrayMaterial}get highlightMaterial(){return this.scene.highlightMaterial}get selectedMaterial(){return this.scene.selectedMaterial}get edgeMaterial(){return this.scene.edgeMaterial}getPickViewMatrix(e){return this._viewMatrix?this._viewMatrix:e}createQuantizationRange(e){void 0!==e.id&&null!==e.id?e.aabb?this.error("[createQuantizationRange] Config missing: aabb"):this._quantizationRanges[e.id]?this.error("[createQuantizationRange] QuantizationRange already created: "+e.id):this._quantizationRanges[e.id]={id:e.id,aabb:e.aabb,matrix:Si(e.aabb,R.mat4())}:this.error("[createQuantizationRange] Config missing: id")}_createDefaultIndices(e){const t=[];for(let s=0;s<e;s++)t.push(s);return t}createGeometry(e){if(void 0!==e.id&&null!==e.id)if(this._geometries[e.id])this.error("[createGeometry] Geometry already created: "+e.id);else if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"===e.primitive||"lines"===e.primitive||"triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive){if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.positionsDecodeMatrix&&e.positionsDecodeBoundary)return this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')"),null;if(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.indices=this._createDefaultIndices((e.positions||e.positionsCompressed).length/3)),!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`[createGeometry] Param expected: indices (required for '${e.primitive}' primitive type)`),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Si(e.positionsDecodeBoundary,R.mat4())),e.positions){const t=R.collapseAABB3();e.positionsDecodeMatrix=R.mat4(),R.expandAABB3Points3(t,e.positions),e.positionsCompressed=Pi(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=R.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),R.expandAABB3Points3(t,e.positionsCompressed),Re.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}else if(e.buckets){const t=R.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(let s=0,i=e.buckets.length;s<i;s++){const i=e.buckets[s];i.positions?R.expandAABB3Points3(t,i.positions):i.positionsCompressed&&R.expandAABB3Points3(t,i.positionsCompressed)}e.positionsDecodeMatrix&&Re.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,i=t.length;e<i;e++)s[e]=255*t[e];e.colorsCompressed=s}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Ie(e.positions,e.indices,null,5):e.edgeIndices=Ie(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){const t=Re.getUVBounds(e.uv),s=Re.compressUVs(e.uv,t.min,t.max);e.uvCompressed=s.quantized,e.uvDecodeMatrix=s.decodeMatrix}else e.uvCompressed&&(e.uvCompressed=new Uint16Array(e.uvCompressed),e.uvDecodeMatrix=new Float64Array(e.uvDecodeMatrix));e.normals&&(e.normals=null),this._geometries[e.id]=e,this._numTriangles+=e.indices?Math.round(e.indices.length/3):0,this.numGeometries++}else this.error(`[createGeometry] Unsupported value for 'primitive': '${e.primitive}' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'.`);else this.error("[createGeometry] Config missing: id")}createTexture(e){const t=e.id;if(null==t)return void this.error("[createTexture] Config missing: id");if(this._textures[t])return void this.error("[createTexture] Texture already created: "+t);if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;let s=e.minFilter||1008;1006!==s&&1007!==s&&1008!==s&&1005!==s&&1004!==s&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),s=1008);let i=e.magFilter||1006;1006!==i&&1003!==i&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),i=1006);let r=e.wrapS||1e3;1001!==r&&1002!==r&&1e3!==r&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),r=1e3);let n=e.wrapT||1e3;1001!==n&&1002!==n&&1e3!==n&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),n=1e3);let A=e.wrapR||1e3;1001!==A&&1002!==A&&1e3!==A&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),A=1e3);let o=e.encoding||3e3;3e3!==o&&3001!==o&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),o=3e3);const a=new Kt({gl:this.scene.canvas.gl,minFilter:s,magFilter:i,wrapS:r,wrapT:n,wrapR:A,encoding:o});if(e.preloadColor&&a.setPreloadColor(e.preloadColor),e.image){const t=e.image;if(t.crossOrigin="Anonymous",t.compressed){const e=t.data;a.setCompressedData({mipmaps:e,props:{format:e[0].format,minFilter:s,magFilter:i}})}else a.setImage(t,{minFilter:s,magFilter:i,wrapS:r,wrapT:n,wrapR:A,flipY:e.flipY,encoding:o})}else if(e.src){const t=e.src.split(".").pop();switch(t){case"jpeg":case"jpg":case"png":case"gif":const l=new Image;l.onload=()=>{a.setImage(l,{minFilter:s,magFilter:i,wrapS:r,wrapT:n,wrapR:A,flipY:e.flipY,encoding:o}),this.glRedraw()},l.src=e.src;break;default:this._textureTranscoder?j.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],a).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,a).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new rr({id:t,texture:a})}createTextureSet(e){const t=e.id;if(null==t)return this.error("[createTextureSet] Config missing: id"),!1;if(this._textureSets[t])return this.error(`[createTextureSet] Texture set already created: ${t}`),!1;const s=(e,t)=>{const s=e??t;if(s in this._textures)return this._textures[s];throw e};try{const i=new ir({id:t,model:this,alphaCutoff:e.alphaCutoff,colorTexture:s(e.colorTextureId,"defaultColorTexture"),metallicRoughnessTexture:s(e.metallicRoughnessTextureId,"defaultMetalRoughTexture"),normalsTexture:s(e.normalsTextureId,"defaultNormalsTexture"),emissiveTexture:s(e.emissiveTextureId,"defaultEmissiveTexture"),occlusionTexture:s(e.occlusionTextureId,"defaultOcclusionTexture")});return this._textureSets[t]=i,i}catch(e){return this.error(`[createTextureSet] Texture not found: ${e} - ensure that you create it first with createTexture()`),!1}}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const s=new kr({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[s.id]=s,s}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;const t=e.geometryId,s=void 0!==t;if(s){if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)"),!1;if(e.geometry=this._geometries[t],!e.geometry)return this.error(`[createMesh] Geometry not found: ${t} - ensure that you create it first with createGeometry()`),!1}else e.primitive??="triangles";const i=s?e.geometry.primitive:e.primitive,r="triangles"===i||"solid"===i||"surface"===i,n=e.textureSetId,A=this._dtxEnabled&&r&&!n;if(e.origin=e.origin?R.addVec3(this._origin,e.origin,R.vec3()):this._origin,s){e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.aabb=R.AABB3(e.geometry.aabb);const t=e.transformId;if(t){if(e.transform=this._transforms[t],!e.transform)return this.error(`[createMesh] Transform not found: ${t} - ensure that you create it first with createTransform()`),!1}else if(e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){const t=e.scale||Vr,s=e.position||Lr,i=e.rotation?R.eulerToQuaternion(e.rotation,"XYZ",Or):e.quaternion||Hr;e.meshMatrix=R.composeMat4(s,i,t,R.mat4())}}else{if("points"!==i&&"lines"!==i&&"triangles"!==i&&"solid"!==i&&"surface"!==i)return this.error(`Unsupported value for 'primitive': '${i}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!e.buckets&&!e.indices)if(r)e.indices=this._createDefaultIndices((e.positions||e.positionsCompressed).length/3);else if("lines"===i)return this.error(`Param expected: indices (required for '${i}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;if(e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){const t=e.scale||Vr,s=e.position||Lr,i=e.rotation?R.eulerToQuaternion(e.rotation,"XYZ",Or):e.quaternion||Hr;e.meshMatrix=R.composeMat4(s,i,t,R.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Si(e.positionsDecodeBoundary,R.mat4())),e.positions){const t=[];pt(e.positions,t,Qr)&&(e.positions=t,e.origin=R.addVec3(e.origin,Qr,R.vec3()));const s=R.collapseAABB3();A?(e.positionsDecodeMatrix=R.mat4(),R.expandAABB3Points3(s,e.positions),e.positionsCompressed=Pi(e.positions,s,e.positionsDecodeMatrix)):(e.meshMatrix&&(R.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),R.expandAABB3Points3(s,e.positions)),e.aabb=s}else if(e.positionsCompressed){const t=R.collapseAABB3();R.expandAABB3Points3(t,e.positionsCompressed),Re.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(A&&e.buckets){const t=R.collapseAABB3();e.buckets.forEach((e=>{const s=e.positions||e.positionsCompressed;s&&R.expandAABB3Points3(t,s)})),e.positionsDecodeMatrix&&Re.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}r&&!e.buckets&&(e.edgeIndices||=Ie(e.positions||e.positionsCompressed,e.indices,e.positions?null:e.positionsDecodeMatrix,2))}if(e.meshMatrix&&(R.AABB3ToOBB3(e.aabb,Rr),R.transformOBB3(e.meshMatrix,Rr,Rr),R.OBB3ToAABB3(Rr,e.aabb)),e.color=e.color?new Uint8Array(e.color.slice(0,3).map((e=>Math.floor(255*e)))):Gr,e.opacity=Math.floor(255*(e.opacity??1)),A)e.type=2,s&&(e.buckets=this._dtxBuckets[t]),e.buckets||(e.buckets=function(e,t,s){let i,r,n,A;t||s?[i,r,n]=br({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}):(i=e.positionsCompressed,r=e.indices,n=e.edgeIndices);if(s){A=Cr({positionsCompressed:i,indices:r,edgeIndices:n},i.length/3>65536?16:8)}else A=[{positionsCompressed:i,indices:r,edgeIndices:n}];return A}(s?e.geometry:e,this._enableVertexWelding,this._enableIndexBucketing),s&&(this._dtxBuckets[t]=e.buckets));else if(e.type=s?0:1,e.metallic=Math.floor(255*(e.metallic??0)),e.roughness=Math.floor(255*(e.roughness??1)),n&&(e.textureSet=this._textureSets[n],!s&&!e.textureSet))return this.error(`[createMesh] Texture set not found: ${n} - ensure that you create it first with createTextureSet()`),!1;e.numPrimitives=this._getNumPrimitives(e);const o=new Ds(this,e.id,e.color,e.opacity,e.transform,e.textureSet),a=this.scene._renderer.getPickID(o);return o.pickId=a,o.origin=R.vec3(e.origin),o.layer=2===e.type?this._getDTXLayer(e):this._getVBOLayer(0===e.type,e),o.aabb=e.aabb,e.pickColor=new Uint8Array([255&a,a>>8&255,a>>16&255,a>>24&255]),e.solid="solid"===e.primitive,e.meshMatrix=e.transform?e.transform.worldMatrix:e.meshMatrix,o.portionId=o.layer.createPortion(o,e),o.numPrimitives=e.numPrimitives,this._meshes[e.id]=o,this._unusedMeshes[e.id]=o,this._meshList.push(o),o}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let s=0,i=e.buckets.length;s<i;s++)t+=e.buckets[s].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/3);case"points":switch(e.type){case 2:for(let s=0,i=e.buckets.length;s<i;s++)t+=e.buckets[s].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:const s=e.geometry;t+=s.positions?s.positions.length:s.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(let s=0,i=e.buckets.length;s<i;s++)t+=e.buckets[s].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}_getDTXLayer(e){const t=e.origin,s=e.geometry?e.geometry.primitive:e.primitive,i=`.${s}.${Math.round(t[0])}.${Math.round(t[1])}.${Math.round(t[2])}`;let r=this._dtxLayers[i];if(r){if(r.canCreatePortion(e))return r;delete this._dtxLayers[i],r=null}switch(s){case"triangles":case"solid":case"surface":r=new Fi(this,s,t);break;default:return}return this._dtxLayers[i]=r,this.layerList.push(r),this._layersToFinalize.push(r),r}_getVBOLayer(e,t){const s=e&&t.geometry,i=e?s.primitive:t.primitive,r=t.origin,n=!e&&(t.positionsDecodeMatrix||t.positionsDecodeBoundary),A=n?this._createHashStringFromMatrix(n):"-",o=t.textureSetId||"-",a=e?t.geometryId:"-",l=(e?"instancing":"batching")+`.${Math.round(r[0])}.${Math.round(r[1])}.${Math.round(r[2])}.${i}.${A}.${o}.${a}.${(t.normalsCompressed||t.normals||[]).length>0?"n":"-"}`;if(!e&&l in this._vboLayers){const e=this._vboLayers[l],s=t.positionsCompressed?t.positionsCompressed.length:t.positions.length;e.canCreatePortion(s,"points"===i?0:t.indices.length)||(e.finalize(),delete this._vboLayers[l])}if(!(l in this._vboLayers)){const n=new er(this,i,r,{textureSet:t.textureSet,...e?{geometry:s}:{maxGeometryBatchSize:this._maxGeometryBatchSize,positionsDecodeMatrix:t.positionsDecodeMatrix,uvDecodeMatrix:t.uvDecodeMatrix}});this.layerList.push(n),this._layersToFinalize.push(n),this._vboLayers[l]=n}return this._vboLayers[l]}_createHashStringFromMatrix(e){const t=e.join(";");let s=0;for(let e=0;e<t.length;e++){s=(s<<5)-s+t.charCodeAt(e),s|=0}return(s>>>0).toString(16)}createEntity(e){if(void 0===e.id?e.id=R.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=R.createUUID()),void 0===e.meshIds)return this.error("Config missing: meshIds"),null;const t=e=>!1!==e;let s=0;s|=this._visible&&t(e.visible)&&ks,s|=this._pickable&&t(e.pickable)&&Rs,s|=this._culled&&t(e.culled)&&Qs,s|=this._clippable&&t(e.clippable)&&Os,s|=this._collidable&&t(e.collidable)&&Vs,s|=this._xrayed&&t(e.xrayed)&&Ls,s|=this._highlighted&&t(e.highlighted)&&Hs,s|=this._selected&&t(e.selected)&&Ns,s|=this._edges&&t(e.edges)&&Gs,e.flags=s;let i=[];for(let t=0,s=e.meshIds.length;t<s;t++){const s=e.meshIds[t];let r=this._meshes[s];r?r.parent?this.error(`Mesh with ID "${s}" already belongs to object with ID "${r.parent.id}" - ignoring this mesh`):(i.push(r),delete this._unusedMeshes[s]):this.error(`Mesh with this ID not found: "${s}" - ignoring this mesh`)}const r=new Fr(this,e.isObject,e.id,i,e.flags,!0);return this._entityList.push(r),this._entities[e.id]=r,this._entitiesToFinalize.push(r),this.numEntities++,r}preFinalize(){if(this.destroyed)return!1;if(0===this._layersToFinalize.length)return!1;this._createDummyEntityForUnusedMeshes();for(let e=0,t=this._layersToFinalize.length;e<t;e++){this._layersToFinalize[e].finalize()}this._vboLayers={},this._dtxLayers={},this._layersToFinalize=[];for(let e=0,t=this._entitiesToFinalize.length;e<t;e++){this._entitiesToFinalize[e]._finalize()}for(let e=0,t=this._entitiesToFinalize.length;e<t;e++){this._entitiesToFinalize[e]._finalize2()}this._entitiesToFinalize=[],this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position,this.layerList.sort(((e,t)=>e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0));for(let e=0,t=this.layerList.length;e<t;e++){this.layerList[e].layerIndex=e}this.glRedraw(),this._layersFinalized=!0}finalize(){this.destroyed||(this.preFinalize(),this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={})}stateSortCompare(e,t){}rebuildRenderFlags(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,s=this.layerList.length;t<s;t++){const s=this.layerList[t];this._getActiveSectionPlanesForLayer(s)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}_createDummyEntityForUnusedMeshes(){const e=Object.keys(this._unusedMeshes);if(e.length>0){const t=`${this.id}-${R.createUUID()}`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,s=this.scene._sectionPlanesState.sectionPlanes,i=s.length,r=e.layerIndex*i;if(i>0)for(let e=0;e<i;e++){s[e].active?(t.sectionPlanesActivePerLayer[r+e]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[r+e]=!1}return!0}_updateRenderFlags(){if(0===this.numVisibleLayerPortions)return;if(this.numCulledLayerPortions===this.numPortions)return;const e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}_withEachVisibleLayer(e,t,s){if(t&&0===this.numVisibleLayerPortions)return;const i=this.scene._sectionPlanesState.sectionPlanes.filter((e=>e.active)),r=e.testAABB,n=this.renderFlags;for(let e=0,t=n.visibleLayers.length;e<t;e++){const t=this.layerList[n.visibleLayers[e]],A=t.getAABB();r&&!r(A)||!i.every((e=>R.planeAABB3Intersect(e.dir,e.dist,A)>=0))||s(t)}}drawColorOpaque(e){this._withEachVisibleLayer(e,!1,(t=>t.drawColorOpaque(this.renderFlags,e)))}drawColorTransparent(e){this._withEachVisibleLayer(e,!1,(t=>t.drawColorTransparent(this.renderFlags,e)))}drawDepth(e){this._withEachVisibleLayer(e,!1,(t=>t.drawDepth(this.renderFlags,e)))}drawSilhouetteXRayed(e){this._withEachVisibleLayer(e,!1,(t=>t.drawSilhouetteXRayed(this.renderFlags,e)))}drawSilhouetteHighlighted(e){this._withEachVisibleLayer(e,!1,(t=>t.drawSilhouetteHighlighted(this.renderFlags,e)))}drawSilhouetteSelected(e){this._withEachVisibleLayer(e,!1,(t=>t.drawSilhouetteSelected(this.renderFlags,e)))}drawEdgesColorOpaque(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesColorOpaque(this.renderFlags,e)))}drawEdgesColorTransparent(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesColorTransparent(this.renderFlags,e)))}drawEdgesXRayed(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesXRayed(this.renderFlags,e)))}drawEdgesHighlighted(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesHighlighted(this.renderFlags,e)))}drawEdgesSelected(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesSelected(this.renderFlags,e)))}drawOcclusion(e){this._withEachVisibleLayer(e,!0,(t=>t.drawOcclusion(this.renderFlags,e)))}drawShadow(e){this._withEachVisibleLayer(e,!0,(t=>t.drawShadow(this.renderFlags,e)))}drawPickMesh(e){this._withEachVisibleLayer(e,!0,(t=>t.drawPickMesh(this.renderFlags,e)))}drawPickDepths(e){this._withEachVisibleLayer(e,!0,(t=>t.drawPickDepths(this.renderFlags,e)))}drawPickNormals(e){this._withEachVisibleLayer(e,!0,(t=>t.drawPickNormals(this.renderFlags,e)))}_drawSnap(e,t){this._withEachVisibleLayer(e,!0,(s=>s.drawSnap(this.renderFlags,e,t)))}drawSnapInit(e){this._drawSnap(e,!0)}drawSnap(e){this._drawSnap(e,!1)}destroy(){Object.values(this._vboLayers).forEach((e=>e.destroy())),this._vboLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(let e=0,t=this.layerList.length;e<t;e++)this.layerList[e].destroy();this.layerList=[];for(let e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._destroy();this._layersToFinalize=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),super.destroy()}}class zr extends ie{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e<t;e+=2)this._indices.push(e),this._indices.push(e+1)}this._color=t.color||[1,1,1],this._opacity=t.opacity||1,this._sceneModel=new jr(this,{isModel:!1}),this._sceneModel.createMesh({id:"linesMesh",primitive:"lines",positions:this._positions,indices:this._indices,color:this._color,opacity:this._opacity}),this._sceneModel.createEntity({meshIds:["linesMesh"],visible:t.visible,clippable:t.clippable,collidable:t.collidable}),this._sceneModel.finalize(),this.scene._lineSetCreated(this)}set visible(e){this._sceneModel.visible=e}get visible(){return this._sceneModel.visible}get positions(){return this._positions}get indices(){return this._indices}destroy(){super.destroy(),this.scene._lineSetDestroyed(this)}}class Wr extends ie{get type(){return"Light"}get isLight(){return!0}constructor(e,t={}){super(e,t)}}class Xr extends Wr{get type(){return"AmbientLight"}constructor(e,t={}){super(e,t),this._state={type:"ambient",color:R.vec3([.7,.7,.7]),intensity:1},this.color=t.color,this.intensity=t.intensity,this.scene._lightCreated(this)}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}get intensity(){return this._state.intensity}destroy(){super.destroy(),this.scene._lightDestroyed(this)}}class Kr{constructor(e,t,s){this.gl=e,this.allocated=!1,this.buffer=null,this.bound=!1,this._colorFormats=t,this._hasDepthTexture=s}setSize(e){this.size=e}bind(){const e=this.size[0],t=this.size[1];if(!this.buffer||this.buffer.width===e&&this.buffer.height===t||(this.buffer.cleanup(),this.buffer=null),this.buffer||(this._allocateBuffer(e,t),this.bound=!1),!this.bound){const e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}_allocateBuffer(e,t){const s=this._colorFormats||[],i=this.gl,r=()=>{const e=i.createTexture();return i.bindTexture(i.TEXTURE_2D,e),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),e},n=(s.length>0?s:[null]).map((s=>{const n=r();return s?i.texStorage2D(i.TEXTURE_2D,1,s,e,t):i.texImage2D(i.TEXTURE_2D,0,i.RGBA,e,t,0,i.RGBA,i.UNSIGNED_BYTE,null),n})),A=i.createRenderbuffer();i.bindRenderbuffer(i.RENDERBUFFER,A),i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_COMPONENT32F,e,t);const o=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,o);for(let e=0;e<n.length;e++)i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+e,i.TEXTURE_2D,n[e],0);s.length>0&&i.drawBuffers(n.map(((e,t)=>i.COLOR_ATTACHMENT0+t)));const a=this._hasDepthTexture&&r();if(a?(i.texImage2D(i.TEXTURE_2D,0,i.DEPTH_COMPONENT32F,e,t,0,i.DEPTH_COMPONENT,i.FLOAT,null),i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,a,0)):i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,A),i.bindTexture(i.TEXTURE_2D,null),i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,o),!i.isFramebuffer(o))throw"Invalid framebuffer";i.bindFramebuffer(i.FRAMEBUFFER,null);const l=i.checkFramebufferStatus(i.FRAMEBUFFER);switch(l){case i.FRAMEBUFFER_COMPLETE:break;case i.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case i.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case i.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case i.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+l}this.buffer={cleanup:()=>{n.forEach((e=>i.deleteTexture(e))),a&&i.deleteTexture(a),i.deleteFramebuffer(o),i.deleteRenderbuffer(A)},framebuf:o,width:e,height:t},this.colorTextures=n.map((e=>({bind:function(t){return i.activeTexture(i["TEXTURE"+t]),i.bindTexture(i.TEXTURE_2D,e),!0}}))),this.depthTexture=a&&{bind:function(e){return i.activeTexture(i["TEXTURE"+e]),i.bindTexture(i.TEXTURE_2D,a),!0}}}read(e,t,s=null,i=null,r=Uint8Array,n=4,A=0){const o=new r(n),a=this.gl;return a.readBuffer(a.COLOR_ATTACHMENT0+A),a.readPixels(e,this.buffer.height-t-1,1,1,s||a.RGBA,i||a.UNSIGNED_BYTE,o,0),o}unbind(){const e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}destroy(){this.allocated&&(this.buffer.cleanup(),this.allocated=!1,this.buffer=null,this.bound=!1),this.colorTextures=null,this.depthTexture=null}}class Zr extends Wr{get type(){return"DirLight"}constructor(e,t={}){super(e,t),this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,i=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=i.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new xe({type:"dir",dir:R.vec3([1,1,1]),color:R.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=R.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,i=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],r=[0,1,0];R.lookAtMat4v(i,s,r,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=R.identityMat4()),R.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new Kr(this.scene.canvas.gl),this._shadowRenderBuf.setSize([1024,1024])),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function Jr(e){if(!Yr(e.width)||!Yr(e.height)){const t=document.createElement("canvas");t.width=$r(e.width),t.height=$r(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Yr(e){return 0==(e&e-1)}function $r(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class qr extends ie{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new xe({texture:new Kt({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),L.memory.textures++}_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}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let i=!1,r=0;for(let n=0;n<e.length;n++){const A=new Image;A.onload=function(){let e=A;const o=n;return function(){if(!i&&(e=Jr(e),t._images[o]=e,r++,6===r)){let e=t._state.texture;e||(e=new Kt({gl:s,target:s.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}}(),A.onerror=function(){i=!0},A.src=e[n]}}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),L.memory.textures--,this._state.destroy()}}const en=R.vec4(),tn=R.vec4();class sn extends ie{constructor(e,t){super(e,t),this._entity=null,this._visible=null,this._worldPos=R.vec3(),this._origin=R.vec3(),this._rtcPos=R.vec3(),this._viewPos=R.vec3(),this._canvasPos=R.vec2(),this._occludable=!1,this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(R.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){en.set(this._viewPos),en[3]=1,R.transformPoint4(this.scene.camera.projMatrix,en,tn);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+tn[0]/tn[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-tn[1]/tn[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){this._entity!==e&&(this._cleanupDestroyedHandlers(),this._entity=e,this._entity&&(this._entity.isSceneModelEntity?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0))}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e,this._occludable&&this._renderer.markerWorldPosUpdated(this))}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),dt(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._cleanupDestroyedHandlers(),this._renderer.removeMarker(this),super.destroy()}_cleanupDestroyedHandlers(){this._entity&&(null!==this._onEntityDestroyed&&(this._entity.model?this._entity.model.off(this._onEntityDestroyed):this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model&&this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null))}}class rn{constructor(e){this._eye=R.vec3(),this._look=R.vec3(),this._up=R.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,s=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,i=this._projection;function r(){switch(i.type){case"perspective":s.perspective.fov=i.fov,s.perspective.fovAxis=i.fovAxis,s.perspective.near=i.near,s.perspective.far=i.far;break;case"ortho":s.ortho.scale=i.scale,s.ortho.near=i.near,s.ortho.far=i.far;break;case"frustum":s.frustum.left=i.left,s.frustum.right=i.right,s.frustum.top=i.top,s.frustum.bottom=i.bottom,s.frustum.near=i.near,s.frustum.far=i.far;break;case"custom":s.customProjection.matrix=i.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:i.scale,projection:i.projection},(()=>{r(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,r(),s.projection=i.projection)}}const nn=R.vec3();const An=R.vec3();class on{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?j.apply(t,{}):null;const s=e.objects,i=!t||t.visible,r=!t||t.edges,n=!t||t.xrayed,A=!t||t.highlighted,o=!t||t.selected,a=!t||t.clippable,l=!t||t.pickable,c=!t||t.colorize,h=!t||t.opacity;for(let e in s)if(s.hasOwnProperty(e)){const t=s[e],u=this.numObjects;if(i&&(this.objectsVisible[u]=t.visible),r&&(this.objectsEdges[u]=t.edges),n&&(this.objectsXrayed[u]=t.xrayed),A&&(this.objectsHighlighted[u]=t.highlighted),o&&(this.objectsSelected[u]=t.selected),a&&(this.objectsClippable[u]=t.clippable),l&&(this.objectsPickable[u]=t.pickable),c){const e=t.colorize;e?(this.objectsColorize[3*u+0]=e[0],this.objectsColorize[3*u+1]=e[1],this.objectsColorize[3*u+2]=e[2],this.objectsHasColorize[u]=!0):this.objectsHasColorize[u]=!1}h&&(this.objectsOpacity[u]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,s=!t||t.visible,i=!t||t.edges,r=!t||t.xrayed,n=!t||t.highlighted,A=!t||t.selected,o=!t||t.clippable,a=!t||t.pickable,l=!t||t.colorize,c=!t||t.opacity;var h=0;const u=e.objects;for(let e in u)if(u.hasOwnProperty(e)){const t=u[e];s&&(t.visible=this.objectsVisible[h]),i&&(t.edges=this.objectsEdges[h]),r&&(t.xrayed=this.objectsXrayed[h]),n&&(t.highlighted=this.objectsHighlighted[h]),A&&(t.selected=this.objectsSelected[h]),o&&(t.clippable=this.objectsClippable[h]),a&&(t.pickable=this.objectsPickable[h]),l&&(this.objectsHasColorize[h]?(An[0]=this.objectsColorize[3*h+0],An[1]=this.objectsColorize[3*h+1],An[2]=this.objectsColorize[3*h+2],t.colorize=An):t.colorize=null),c&&(t.opacity=this.objectsOpacity[h]),h++}}}const an=R.vec3(),ln=R.vec3(),cn=R.vec4(),hn=R.vec3([0,0,-1]),un=R.vec3([0,0,1]),dn=R.vec3([0,1,0]);class pn extends ie{get type(){return"SectionPlane"}constructor(e,t={}){super(e,t),this._state=new xe({active:!0,pos:R.vec3(),quaternion:R.vec4(),roll:0,dir:R.vec3(),dist:0}),this.active=t.active,this.pos=t.pos,this.dir=t.dir,this.scene._sectionPlaneCreated(this)}set active(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active),this.scene.fire("sectionPlaneUpdated",this)}get active(){return this._state.active}set pos(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-R.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos),this.scene.fire("sectionPlaneUpdated",this)}get pos(){return this._state.pos}set quaternion(e){this._state.quaternion.set(e||[0,0,0,-1]),R.vec3ApplyQuaternion(this._state.quaternion,un,this._state.dir);const t=R.vec3ApplyQuaternion(this._state.quaternion,dn,an),s=R.vec3PairToQuaternion(un,this._state.dir,cn),i=R.vec3ApplyQuaternion(s,dn,ln),r=Math.acos(Math.min(1,R.dotVec3(t,i))),n=Math.sign(R.dotVec3(this._state.dir,R.cross3Vec3(t,i,ln)));this._state.roll=n*r,this._onDirUpdated()}get quaternion(){return this._state.quaternion}set roll(e){this._state.roll=e||0,this._onDirRollUpdated()}get roll(){return this._state.roll}set dir(e){this._state.dir.set(e||hn),this._onDirRollUpdated()}_onDirRollUpdated(){R.vec3PairToQuaternion(un,this._state.dir,this._state.quaternion),cn[0]=0,cn[1]=0,cn[2]=-1,cn[3]=this._state.roll,R.angleAxisToQuaternion(cn,cn),R.mulQuaternions(this._state.quaternion,cn,this._state.quaternion),this._onDirUpdated()}_onDirUpdated(){this._state.dist=-R.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir),this.scene.fire("sectionPlaneUpdated",this)}get dir(){return this._state.dir}get dist(){return this._state.dist}flipDir(){R.mulVec3Scalar(this._state.dir,-1,this._state.dir),this.dir=this._state.dir}destroy(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),super.destroy()}}class fn{constructor(){this.entity=null,this.primitive=null,this.primIndex=-1,this.pickSurfacePrecision=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1,this._origin=new Float64Array([0,0,0]),this._direction=new Float64Array([0,0,0]),this._indices=new Int32Array(3),this._localPos=new Float64Array([0,0,0]),this._worldPos=new Float64Array([0,0,0]),this._viewPos=new Float64Array([0,0,0]),this._canvasPos=new Int16Array([0,0]),this._snappedCanvasPos=new Int16Array([0,0]),this._bary=new Float64Array([0,0,0]),this._worldNormal=new Float64Array([0,0,0]),this._uv=new Float64Array([0,0]),this.reset()}get canvasPos(){return this._gotCanvasPos?this._canvasPos:null}set canvasPos(e){e?(this._canvasPos[0]=e[0],this._canvasPos[1]=e[1],this._gotCanvasPos=!0):this._gotCanvasPos=!1}get origin(){return this._gotOrigin?this._origin:null}set origin(e){e?(this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this._gotOrigin=!0):this._gotOrigin=!1}get direction(){return this._gotDirection?this._direction:null}set direction(e){e?(this._direction[0]=e[0],this._direction[1]=e[1],this._direction[2]=e[2],this._gotDirection=!0):this._gotDirection=!1}get indices(){return this.entity&&this._gotIndices?this._indices:null}set indices(e){e?(this._indices[0]=e[0],this._indices[1]=e[1],this._indices[2]=e[2],this._gotIndices=!0):this._gotIndices=!1}get localPos(){return this.entity&&this._gotLocalPos?this._localPos:null}set localPos(e){e?(this._localPos[0]=e[0],this._localPos[1]=e[1],this._localPos[2]=e[2],this._gotLocalPos=!0):this._gotLocalPos=!1}get snappedCanvasPos(){return this._gotSnappedCanvasPos?this._snappedCanvasPos:null}set snappedCanvasPos(e){e?(this._snappedCanvasPos[0]=e[0],this._snappedCanvasPos[1]=e[1],this._gotSnappedCanvasPos=!0):this._gotSnappedCanvasPos=!1}get worldPos(){return this._gotWorldPos?this._worldPos:null}set worldPos(e){e?(this._worldPos[0]=e[0],this._worldPos[1]=e[1],this._worldPos[2]=e[2],this._gotWorldPos=!0):this._gotWorldPos=!1}get viewPos(){return this.entity&&this._gotViewPos?this._viewPos:null}set viewPos(e){e?(this._viewPos[0]=e[0],this._viewPos[1]=e[1],this._viewPos[2]=e[2],this._gotViewPos=!0):this._gotViewPos=!1}get bary(){return this.entity&&this._gotBary?this._bary:null}set bary(e){e?(this._bary[0]=e[0],this._bary[1]=e[1],this._bary[2]=e[2],this._gotBary=!0):this._gotBary=!1}get worldNormal(){return this.entity&&this._gotWorldNormal?this._worldNormal:null}set worldNormal(e){e?(this._worldNormal[0]=e[0],this._worldNormal[1]=e[1],this._worldNormal[2]=e[2],this._gotWorldNormal=!0):this._gotWorldNormal=!1}get uv(){return this.entity&&this._gotUV?this._uv:null}set uv(e){e?(this._uv[0]=e[0],this._uv[1]=e[1],this._gotUV=!0):this._gotUV=!1}get snapped(){return this.snappedToEdge||this.snappedToVertex}reset(){this.entity=null,this.primIndex=-1,this.primitive=null,this.pickSurfacePrecision=!1,this._gotCanvasPos=!1,this._gotSnappedCanvasPos=!1,this._gotOrigin=!1,this._gotDirection=!1,this._gotIndices=!1,this._gotLocalPos=!1,this._gotWorldPos=!1,this._gotViewPos=!1,this._gotBary=!1,this._gotWorldNormal=!1,this._gotUV=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1}}const gn={isIphoneSafari(){const e=window.navigator.userAgent,t=/iPhone/i.test(e),s=/Safari/i.test(e)&&!/Chrome/i.test(e);return t&&s},isIphoneOrIpadSafari(){const e=window.navigator.userAgent,t=/iPhone|iPad/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>2,s=/Safari/i.test(e)&&!/Chrome/i.test(e);return t&&s},isTouchDevice:()=>"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.mxMaxTouchPoints>0};class mn{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}scheduleTask(e){q.scheduleTask(e,null)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const i=this._eventSubs[e];let r;if(i)for(const s in i)i.hasOwnProperty(s)&&(r=i[s],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,s,i){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:s,scope:i||this},this._subIdEvents[n]=t;const A=this._events[t];return void 0!==A&&s.call(i||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 s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const i=this,r=this.on(e,(function(e){i.off(r),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}class _n extends ie{get type(){return"Spinner"}constructor(e,t={}){super(e,t),this._canvas=t.canvas,this._element=null,this._isCustom=!1,t.elementId&&(this._element=document.getElementById(t.elementId),this._element?this._adjustPosition():this.error("Can't find given Spinner HTML element: '"+t.elementId+"' - will automatically create default element")),this._element||this._createDefaultSpinner(),this.processes=0}_createDefaultSpinner(){this._injectDefaultCSS();const e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='<div class="sk-fading-circle"> <div class="sk-circle1 sk-circle"></div> <div class="sk-circle2 sk-circle"></div> <div class="sk-circle3 sk-circle"></div> <div class="sk-circle4 sk-circle"></div> <div class="sk-circle5 sk-circle"></div> <div class="sk-circle6 sk-circle"></div> <div class="sk-circle7 sk-circle"></div> <div class="sk-circle8 sk-circle"></div> <div class="sk-circle9 sk-circle"></div> <div class="sk-circle10 sk-circle"></div> <div class="sk-circle11 sk-circle"></div> <div class="sk-circle12 sk-circle"></div> </div>',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const bn=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class yn extends ie{constructor(e,t={}){super(e,t),this._backgroundColor=R.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;let i=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(i=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{i&&(i=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new _n(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+R.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),i=s.style;i.height="100%",i.width="100%",i.padding="0",i.margin="0",i.background="rgba(0,0,0,0);",i.float="left",i.left="0",i.top="0",i.position="absolute",i.opacity="1.0",i["z-index"]="-10000",s.innerHTML+='<canvas id="'+e+'" style="width: 100%; height: 100%; float: left; margin: 0; padding: 0;"></canvas>',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e<bn.length;e++)try{this.gl=this.canvas.getContext(bn[e],this.contextAttr)}catch(e){}this.gl||(this.error("Failed to get a WebGL context"),this.fire("webglContextFailed",!0,!0));{const e=this.gl;let t="__",s=e.activeTexture;e.activeTexture=function(e){t!==e&&(t=e,s.call(this,e))};let i={},r=e.bindTexture;e.bindTexture=function(e,s){i[t]!==s&&(i[t]=s,r.call(this,e,s))}}this.gl&&this.webgl2&&(this.gl.hint(this.gl.FRAGMENT_SHADER_DERIVATIVE_HINT,this.gl.FASTEST),this.gl,WebGL2RenderingContext)}getSnapshot(e){throw"Canvas#getSnapshot() has been replaced by Viewer#getSnapshot() - use that method instead."}readPixels(e,t,s){return this.scene._renderer.snapshot.readPixels(e,t,s)}loseWebGLContext(){this.canvas.loseContext&&this.canvas.loseContext()}destroy(){this.scene.off(this._tick),this._spinner._destroy(),this.gl=null,super.destroy()}}class Bn{constructor(e){this._matPool=[],this.reset()}reset(){this._matPoolNextFreeIndex=0,this._rtcViewMats={},this.lastProgramId=null,this.pbrEnabled=!1,this.colorTextureEnabled=!1,this.withSAO=!1,this.backfaces=!1,this.frontface=!0,this.textureUnit=0,this.drawElements=0,this.drawArrays=0,this.useProgram=0,this.bindTexture=0,this.bindArray=0,this.pass=0,this.viewParams={},this.viewParams.viewMatrix=null,this.viewParams.projMatrix=null,this.viewParams.near=.01,this.viewParams.far=5e3,this.pickInvisible=!1,this.lineWidth=1,this.snapPickLayerParams=[],this.snapPickCoordinateScale=R.vec3(),this.snapPickOrigin=R.vec3()}getRTCViewMatrix(e,t){let s=this._rtcViewMats[e];return s||(s=this._getNewMat(),ut(this.viewParams.viewMatrix,t,s),this._rtcViewMats[e]=s),s}_getNewMat(){let e=this._matPool[this._matPoolNextFreeIndex];return e||(e=R.mat4(),this._matPool[this._matPoolNextFreeIndex]=e),this._matPoolNextFreeIndex++,e}}const wn={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},vn=document.createElement("canvas");if(vn){const e=vn.getContext("webgl",{antialias:!0})||vn.getContext("experimental-webgl",{antialias:!0});wn.WEBGL=!!e,wn.WEBGL&&(wn.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?wn.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?wn.FS_MAX_FLOAT_PRECISION="mediump":wn.FS_MAX_FLOAT_PRECISION="lowp":wn.FS_MAX_FLOAT_PRECISION="mediump",wn.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),wn.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),wn.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),wn.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),wn.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),wn.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),wn.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),wn.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),wn.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),wn.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){wn.SUPPORTED_EXTENSIONS[e]=!0})))}class Cn{constructor(e){this.aabb=R.AABB3(),this.origin=R.vec3(e),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(e,t){if(this.markerListDirty){for(var s in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(s)&&(this.markerList[this.numMarkers]=this.markers[s],this.markerIndices[s]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0}if(this.positionsDirty){let t=0;for(let e=0;e<this.numMarkers;e++)if(this.markerList[e]){const s=this.markerList[e].rtcPos;this.positions[t++]=s[0],this.positions[t++]=s[1],this.positions[t++]=s[2],this.indices[e]=e}this.positions.length=3*this.numMarkers,this.indices.length=this.numMarkers,this.positionsDirty=!1;const s=this.aabb;R.collapseAABB3(s),R.expandAABB3Points3(s,this.positions);const i=this.origin;s[0]+=i[0],s[1]+=i[1],s[2]+=i[2],s[3]+=i[0],s[4]+=i[1],s[5]+=i[2],this.positionsBuf&&this.lenPositionsBuf!==this.positions.length&&(this.positionsBuf.destroy(),this.positionsBuf=null,this.indicesBuf.destroy(),this.indicesBuf=null);const r=new Float32Array(this.positions);this.positionsBuf?this.positionsBuf.setData(r):(this.positionsBuf=new Ue(e,e.ARRAY_BUFFER,r,r.length,3,e.STATIC_DRAW),this.indicesBuf=new Ue(e,e.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indices),this.indices.length,1,e.STATIC_DRAW),this.lenPositionsBuf=this.positions.length)}if(this.occlusionTestListDirty){let e=0;this.lenOcclusionTestList=0;for(let s=0;s<this.numMarkers;s++){const i=this.markerList[s];i.entity&&!i.entity.visible||!t(i)?i._setVisible(!1):i.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=i,this.pixels[e++]=i.canvasPos[0],this.pixels[e++]=i.canvasPos[1]):i._setVisible(!0)}}}destroy(){this.markers={},this.markerList.length=0,this.positionsBuf&&this.positionsBuf.destroy(),this.indicesBuf&&this.indicesBuf.destroy()}}const Mn=R.vec3([255,0,0]);R.vec3();class En{constructor(e){this._scene=e,this._occlusionLayers={},this._occlusionLayersList=[],this._occlusionLayersListDirty=!1,this._drawable=null,this._markersToOcclusionLayersMap={};const t=e.camera,s=()=>{this._occlusionTestListDirty=!0};this._onCameraViewMatrix=t.on("viewMatrix",s),this._onCameraProjMatrix=t.on("projMatrix",s),this._onCanvasBoundary=e.canvas.on("boundary",s)}_addMarker(e,t){this._occlusionLayers[t]||(this._occlusionLayers[t]=new Cn(e.origin),this._occlusionLayersListDirty=!0);const s=this._occlusionLayers[t];s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s}_removeMarker(e,t){1===e.numMarkers?(e.destroy(),delete this._occlusionLayers[e.originHash],this._occlusionLayersListDirty=!0):e.removeMarker(t),delete this._markersToOcclusionLayersMap[t.id]}addMarker(e){const t=e.origin.join();this._addMarker(e,t),this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(t){const s=e.origin.join();s!==t.originHash?(this._removeMarker(t,e),this._addMarker(e,s)):t.markerWorldPosUpdated(e)}}removeMarker(e){const t=e.origin.join(),s=this._occlusionLayers[t];s&&this._removeMarker(s,e)}get needOcclusionTest(){return this._occlusionTestListDirty}drawMarkers(){const e=this._scene,t=e.canvas,s=t.gl,i=e._sectionPlanesState,r=[t.canvas.id,i.getHash()].join(";");if(!this._drawable||r!==this._drawable.shaderSourceHash){this._drawable&&this._drawable.destroy();const n=bt(),A=n.programVariables,o=A.createUniform("mat4","viewMatrix"),a=A.createUniform("mat4","projMatrix"),l=A.createAttribute("vec3","position"),c=A.createOutput("vec4","outColor"),h="clipPos",[u,d]=n.buildProgram(s,"OcclusionTester",{sectionPlanesState:i,getLogDepth:e.logarithmicDepthBufferEnabled&&(e=>e),clippableTest:()=>"true",getVertexData:()=>{const t=[];return t.push(`vec4 worldPosition = vec4(${l}, 1.0);`),t.push(`vec4 ${h} = ${a} * ${o} * worldPosition;`),!e.logarithmicDepthBufferEnabled&&e.markerZOffset<0&&t.push(`${h}.z += ${e.markerZOffset};`),t},worldPositionAttribute:"worldPosition",getPointSize:()=>"20.0",clipPos:h,appendFragmentOutputs:e=>e.push(`${c} = vec4(1.0, 0.0, 0.0, 1.0);`)});if(d)throw console.error(d.join("\n")),d.join("\n");this._occlusionTestListDirty=!0,this._drawable={shaderSourceHash:r,destroy:()=>u.destroy(),drawCall:()=>{const r=e.camera,n=r.project;u.bind(),a.setInputValue(n.matrix);const A=t.boundary,c=A[2],h=A[3],d=r.perspective.near,p=e=>{const t=e.viewPos,s=e.canvasPos,i=s[0],r=s[1];return t[2]<=-d&&i>=-10&&r>=-10&&i<=c+10&&r<=h+10};this._occlusionLayersList.forEach((e=>{e.update(s,p);const t=i.sectionPlanes.some(((t,s)=>{const i=t.active?R.planeAABB3Intersect(t.dir,t.dist,e.aabb):1,r=-1===i;return e.sectionPlanesActive[s]=0===i,r}));if(!t){const t=e.origin;o.setInputValue(ut(r.viewMatrix,t)),u.inputSetters.setUniforms(null,{view:{far:n.far},mesh:{origin:t,renderFlags:{sectionPlanesActivePerLayer:e.sectionPlanesActive}}}),l.setInputValue(e.positionsBuf);const i=e.indicesBuf;i.bind(),s.drawElements(s.POINTS,i.numItems,i.itemType,0)}}))}}}if(this._occlusionLayersListDirty){let e=0;for(let t in this._occlusionLayers)this._occlusionLayers.hasOwnProperty(t)&&(this._occlusionLayersList[e++]=this._occlusionLayers[t]);this._occlusionLayersList.length=e,this._occlusionLayersListDirty=!1}if(this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e<t;e++){this._occlusionLayersList[e].occlusionTestListDirty=!0}this._occlusionTestListDirty=!1}this._drawable.drawCall()}doOcclusionTest(e){this._occlusionLayersList.forEach((t=>{for(let s=0;s<t.lenOcclusionTestList;s++){const i=2*s,r=e(t.pixels[i],t.pixels[i+1]);t.occlusionTestList[s]._setVisible(R.compareVec3(Mn,r))}}))}destroy(){this.destroyed||(this._occlusionLayersList.forEach((e=>e.destroy())),this._drawable&&this._drawable.destroy(),this._scene.camera.off(this._onCameraViewMatrix),this._scene.camera.off(this._onCameraProjMatrix),this._scene.canvas.off(this._onCanvasBoundary),this.destroyed=!0)}}const Fn=R.vec3([0,0,0]),xn=e=>{const t=[];for(let s=0;s<e;++s)t.push(s);return t},Un=xn(6).map((()=>R.vec4())),In=R.vec4(),Tn=R.vec4([1/4294967296,1/16777216,1/65536,1/256]),Pn=e=>e[0]+(e[1]<<8)+(e[2]<<16)+(e[3]<<24),Sn=e=>R.normalizeVec3(R.divVec3Scalar(e,R.MAX_INT,R.vec3())),Dn=(e,t,s)=>R.vec3([e[0]*s[0]+t[0],e[1]*s[1]+t[1],e[2]*s[2]+t[2]]),kn=(e,t)=>s=>{let i=-1/0,r=1/0;for(let n=0;n<3;n++){const A=e[n],o=t[n],a=s[n],l=s[n+3];if(Math.abs(o)<1e-8){if(A<a||A>l)return!1}else{const e=(a-A)/o,t=(l-A)/o;if(i=Math.max(i,Math.min(e,t)),r=Math.min(r,Math.max(e,t)),i>r)return!1}}return r>=0},Qn=function(t,s){s=s||{};const i=new Bn,r=t.canvas.canvas,n=t.canvas.gl,A=!!s.transparent,o=s.alphaDepthMask,a=new e({});let l={},c={},h=[],u=[],d=[],p=!0,f=!0,g=!0,m=!0,_=!0,b=!0,y=!0,B=!0;const w=function(){const e={},s={};return{getRenderBuffer:(i,r,A)=>{const o=1===t.canvas.resolutionScale?e:s;return o[i]||(o[i]=new Kr(n,r,A)),o[i]},destroy:()=>{Object.values(e).forEach((e=>e.destroy())),Object.values(s).forEach((e=>e.destroy()))}}}(),v=(e,t,s,i)=>{const r=s.programVariables,n=r.createUniform("vec2","uViewportInv"),A=r.createUniform("float","uCameraNear"),o=r.createUniform("float","uCameraFar"),a=r.createUniform("sampler2D","uDepthTexture"),l=r.createAttribute("vec2","uv"),c=r.createVarying("vec2","vUV",(()=>l)),h=r.createOutput("vec4","outColor"),u=r.createFragmentDefinition("getOutColor",((e,t)=>{const s="getDepth";t.push(`\n float getDepth(const in vec2 uv) {\n return texture(${a}, uv).r;\n }\n `),t.push(i(e,c,n,A,o,s))})),[d,p]=s.buildProgram(e,t,{clipPos:`vec4(2.0 * ${l} - 1.0, 0.0, 1.0)`,appendFragmentOutputs:e=>e.push(`${h} = ${u}();`)});if(p)throw console.error(p.join("\n")),p;{const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Ue(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),i=new Uint32Array([0,1,2,0,2,3]),r=new Ue(e,e.ELEMENT_ARRAY_BUFFER,i,i.length,1,e.STATIC_DRAW);return{destroy:d.destroy,bind:(e,t,i)=>{d.bind(),n.setInputValue([1/e[0],1/e[1]]),A.setInputValue(t.near),o.setInputValue(t.far),a.setInputValue(i),l.setInputValue(s)},draw:()=>{r.bind(),e.drawElements(e.TRIANGLES,r.numItems,r.itemType,0)}}}},C=function(){let e=null,t=null;return{destroy:()=>e&&e.destroy(),render:(s,i,r,A)=>{const o=Math.floor(r.numSamples);if(t!==o){e&&e.destroy();const s=bt(),i=s.programVariables,r=i.createUniform("mat4","uProjectMatrix"),A=i.createUniform("mat4","uInvProjMatrix"),a=i.createUniform("bool","uPerspective"),l=i.createUniform("float","uScale"),c=i.createUniform("float","uIntensity"),h=i.createUniform("float","uBias"),u=i.createUniform("float","uKernelRadius"),d=i.createUniform("float","uMinResolution"),p=i.createUniform("float","uRandomSeed"),f=v(n,"SAOOcclusionRenderer",s,((e,t,s,i,n,f)=>`\n #define EPSILON 1e-6\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define NUM_SAMPLES ${o}\n #define NUM_RINGS 4\n\n const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.);\n\n vec4 packFloatToRGBA(const in float v) {\n vec4 r = vec4(fract(v * packFactors), v);\n r.yzw -= r.xyz / 256.;\n return r * 256. / 255.;\n }\n\n highp float rand(const in vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n return fract(sin(mod(dot(uv, vec2(a, b)), PI)) * c);\n }\n\n vec3 getViewPos(const in vec2 screenPos, const in float depth) {\n float near = ${i};\n float far = ${n};\n float viewZ = (${a}\n ? ((near * far) / ((far - near) * depth - far))\n : (depth * (near - far) - near));\n float clipW = ${r}[2][3] * viewZ + ${r}[3][3];\n return (${A} * (clipW * vec4((vec3(screenPos, depth) - 0.5) * 2.0, 1.0))).xyz;\n }\n\n vec4 ${e}() {\n float centerDepth = ${f}(${t});\n if (centerDepth >= (1.0 - EPSILON)) {\n discard;\n }\n\n vec3 centerViewPosition = getViewPos(${t}, centerDepth);\n float scaleDividedByCameraFar = ${l} / ${n};\n float minResolutionMultipliedByCameraFar = ${d} * ${n};\n vec3 centerViewNormal = normalize(cross(dFdx(centerViewPosition), dFdy(centerViewPosition)));\n\n vec2 radiusStep = ${u} * ${s} / float(NUM_SAMPLES);\n vec2 radius = radiusStep;\n const float angleStep = PI2 * float(NUM_RINGS) / float(NUM_SAMPLES);\n float angle = PI2 * rand(${t} + ${p});\n\n float occlusionSum = 0.0;\n float weightSum = 0.0;\n\n for (int i = 0; i < NUM_SAMPLES; i++) {\n vec2 sampleUv = ${t} + vec2(cos(angle), sin(angle)) * radius;\n radius += radiusStep;\n angle += angleStep;\n\n float sampleDepth = ${f}(sampleUv);\n if (sampleDepth >= (1.0 - EPSILON)) {\n continue;\n }\n\n vec3 sampleViewPosition = getViewPos(sampleUv, sampleDepth);\n vec3 viewDelta = sampleViewPosition - centerViewPosition;\n float scaledScreenDistance = scaleDividedByCameraFar * length(viewDelta);\n occlusionSum += max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - ${h}) / (1.0 + scaledScreenDistance * scaledScreenDistance );\n weightSum += 1.0;\n }\n\n return packFloatToRGBA(1.0 - occlusionSum * ${c} / weightSum);\n }`));e={destroy:f.destroy,render:(e,t,s,i)=>{f.bind(e,t,i),r.setInputValue(t.matrix),A.setInputValue(t.inverseMatrix),a.setInputValue("Perspective"===t.type),l.setInputValue(s.scale*t.far/5),c.setInputValue(s.intensity),h.setInputValue(s.bias),u.setInputValue(s.kernelRadius),d.setInputValue(s.minResolution),p.setInputValue(Math.random()),f.draw()}},t=o}e.render(s,i,r,A)}}}(),M=function(){const e=e=>{const t=[];for(let s=0;s<=17;s++)t.push(e[0]*s),t.push(e[1]*s);return new Float32Array(t)},t=e([0,1]),s=e([1,0]),i=new Float32Array(xn(17).map((e=>((e,t)=>Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t))(e,4)))),r=bt(),A=r.programVariables,o=A.createUniform("float","uDepthCutoff"),a=A.createUniformArray("vec2","uSampleOffsets",17),l=A.createUniformArray("float","uSampleWeights",17),c=A.createUniform("sampler2D","uOcclusionTex"),h=v(n,"SAODepthLimitedBlurRenderer",r,((e,t,s,i,r,n)=>`\n #define EPSILON 1e-6\n\n const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.);\n\n vec4 packFloatToRGBA(const in float v) {\n vec4 r = vec4(fract(v * packFactors), v);\n r.yzw -= r.xyz / 256.;\n return r * 256. / 255.;\n }\n\n float getOcclusion(const in vec2 uv) {\n vec4 v = texture(${c}, uv);\n return dot(floor(v * 255.0 + 0.5) / 255.0, 255. / 256. / vec4(packFactors, 1.)); // unpackRGBAToFloat\n }\n\n float getViewZ(const in float depth) {\n return (${i} * ${r}) / ((${r} - ${i}) * depth - ${r});\n }\n\n vec4 ${e}() {\n float centerDepth = ${n}(${t});\n if (centerDepth >= (1.0 - EPSILON)) {\n discard;\n }\n\n float centerViewZ = getViewZ(centerDepth);\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = ${l}[0];\n float occlusionSum = getOcclusion(${t}) * weightSum;\n\n for (int i = 1; i <= 16; i++) {\n float sampleWeight = ${l}[i];\n vec2 sampleUVOffset = ${a}[i] * ${s};\n\n if (! rBreak) {\n vec2 rSampleUV = ${t} + sampleUVOffset;\n if (abs(centerViewZ - getViewZ(${n}(rSampleUV))) > ${o}) {\n rBreak = true;\n } else {\n occlusionSum += getOcclusion(rSampleUV) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n if (! lBreak) {\n vec2 lSampleUV = ${t} - sampleUVOffset;\n if (abs(centerViewZ - getViewZ(${n}(lSampleUV))) > ${o}) {\n lBreak = true;\n } else {\n occlusionSum += getOcclusion(lSampleUV) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n }\n\n return packFloatToRGBA(occlusionSum / weightSum);\n }`));return{destroy:h.destroy,render:(e,r,n,A,u)=>{h.bind(e,r,A),o.setInputValue(.01),a.setInputValue(0===n?s:t),l.setInputValue(i),c.setInputValue(u),h.draw()}}}(),E=function(){let e=null;return function(){if(!e){const s=t.camera;e={get eye(){return s.eye},get far(){return s.project.far},get projMatrix(){return s.projMatrix},get viewMatrix(){return s.viewMatrix},get viewNormalMatrix(){return s.viewNormalMatrix}}}return e}}(),F=(e,t)=>"ortho"===e.projection?1:t/(2*Math.tan(.5*e.perspective.fov*Math.PI/180));function x(){if(p&&(Object.values(l).forEach((e=>{const t=e.drawableListPreCull;let s=0;Object.values(e.drawableMap).forEach((e=>{t[s++]=e})),t.length=s})),p=!1,f=!0),f){let e=0;Object.values(l).forEach((t=>{t.drawableListPreCull.forEach((t=>{h[e++]=t}))})),h.length=e,h.sort(((e,t)=>e.renderOrder-t.renderOrder)),f=!1,g=!0}if(g){let e=0,t=0;h.forEach((s=>{s.rebuildRenderFlags(),s.renderFlags.culled||(s.isUI?d[t++]=s:u[e++]=s)})),u.length=e,d.length=t}}this.scene=t,this._occlusionTester=null,this.capabilities={astcSupported:!!zt(n,"WEBGL_compressed_texture_astc"),etc1Supported:!0,etc2Supported:!!zt(n,"WEBGL_compressed_texture_etc"),dxtSupported:!!zt(n,"WEBGL_compressed_texture_s3tc"),bptcSupported:!!zt(n,"EXT_texture_compression_bptc"),pvrtcSupported:!(!zt(n,"WEBGL_compressed_texture_pvrtc")&&!zt(n,"WEBKIT_WEBGL_compressed_texture_pvrtc"))},this.setTransparentEnabled=function(e){m=e,g=!0},this.setEdgesEnabled=function(e){_=e,g=!0},this.setSAOEnabled=function(e){b=e,g=!0},this.setPBREnabled=function(e){y=e,g=!0},this.setColorTextureEnabled=function(e){B=e,g=!0},this.needStateSort=function(){f=!0},this.shadowsDirty=function(){},this.imageDirty=function(){g=!0},this.addDrawable=function(e,t){const s=t.type;if(!s)return void console.error("Renderer#addDrawable() : drawable with ID "+e+" has no 'type' - ignoring");let i=l[s];i||(i={type:t.type,count:0,isStateSortable:t.isStateSortable,stateSortCompare:t.stateSortCompare,drawableMap:{},drawableListPreCull:[],drawableList:[]},l[s]=i),i.count++,i.drawableMap[e]=t,c[e]=t,p=!0},this.removeDrawable=function(e){const t=c[e];if(!t)return void console.error("Renderer#removeDrawable() : drawable not found with ID "+e+" - ignoring");const s=t.type,i=l[s];--i.count<=0?delete l[s]:delete i.drawableMap[e],delete c[e],p=!0},this.getPickID=function(e){return a.addItem(e)},this.putPickID=function(e){a.removeItem(e)},this.clear=function(e){if(n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),A)n.clearColor(1,1,1,1);else{const e=t.canvas.backgroundColorFromAmbientLight?this.lights.getAmbientColorAndIntensity():t.canvas.backgroundColor;n.clearColor(e[0],e[1],e[2],1)}n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT)},this.needsRender=function(){return g||p||f},this.render=function(e,s){x(),g&&(!function(e,s){const r=t.sao,a=b&&r.possible&&r.numSamples>=1&&function(e){const s=t.sao,r=[n.drawingBufferWidth,n.drawingBufferHeight],A=w.getRenderBuffer("saoDepth",[],!0);A.setSize(r),A.bind(),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.reset(),i.pass=e,i.viewParams=E(),i.nearPlaneHeight=F(t.camera,n.drawingBufferHeight),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),n.clearColor(0,0,0,0),n.enable(n.DEPTH_TEST),n.frontFace(n.CCW),n.enable(n.CULL_FACE),n.depthMask(!0),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),u.forEach((e=>{!e.culled&&e.visible&&e.drawDepth&&e.saoEnabled&&e.renderFlags.colorOpaque&&e.drawDepth(i)})),A.unbind();const o=A.depthTexture,a=w.getRenderBuffer("saoOcclusion");if(a.setSize(r),a.bind(),n.viewport(0,0,r[0],r[1]),n.clearColor(0,0,0,1),n.disable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT),C.render(r,t.camera.project,s,o),a.unbind(),s.blur){const e=w.getRenderBuffer("saoOcclusion2");e.setSize(r);const s=(e,s,i)=>{s.bind(),n.viewport(0,0,r[0],r[1]),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT);const A=t.camera.project;M.render(r,A,i,o,e.colorTextures[0]),s.unbind()};s(a,e,0),s(e,a,1)}return a.colorTextures[0]}(e);t._lightsState.lights.forEach((e=>{if(e.castsShadow){const s=e.getShadowRenderBuf();s.bind(),i.reset(),i.backfaces=!0,i.frontface=!0,i.viewParams.viewMatrix=e.getShadowViewMatrix(),i.viewParams.projMatrix=e.getShadowProjMatrix(),i.nearPlaneHeight=F(t.camera,n.drawingBufferHeight),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),Object.values(l).forEach((e=>{e.drawableList.forEach((e=>{!1!==e.visible&&e.castsShadow&&e.drawShadow&&e.renderFlags.colorOpaque&&e.drawShadow(i)}))})),s.unbind()}})),function(e,s,r){const a=[],l=[],c=[],h=[],p=[],f=[],g=[],b=[],w=[],v=[],C=[],M=[],x=[],U=[],I=[],T=[],P=t._lightsState.getAmbientColorAndIntensity();if(i.reset(),i.pass=e,i.withSAO=!1,i.pbrEnabled=y&&!!t.pbrEnabled,i.colorTextureEnabled=B&&!!t.colorTextureEnabled,i.viewParams=E(),i.nearPlaneHeight=F(t.camera,n.drawingBufferHeight),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),A)n.clearColor(0,0,0,0);else{const e=t.canvas.backgroundColorFromAmbientLight?P:t.canvas.backgroundColor;n.clearColor(e[0],e[1],e[2],1)}let S,D;n.enable(n.DEPTH_TEST),n.frontFace(n.CCW),n.enable(n.CULL_FACE),n.depthMask(!0),n.lineWidth(1),i.lineWidth=1,t.sao,i.saoParams=[n.drawingBufferWidth,n.drawingBufferHeight,t.sao.blendCutoff,t.sao.blendFactor],i.occlusionTexture=r;const k=Date.now();s&&n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT);i.testAABB=function(e){const t=R.mat4();R.mulMat4(e.projMatrix,e.viewMatrix,t);for(let e=0;e<3;++e)Un[2*e+0][0]=t[3]+t[e],Un[2*e+0][1]=t[7]+t[e+4],Un[2*e+0][2]=t[11]+t[e+8],Un[2*e+0][3]=t[15]+t[e+12],Un[2*e+1][0]=t[3]-t[e],Un[2*e+1][1]=t[7]-t[e+4],Un[2*e+1][2]=t[11]-t[e+8],Un[2*e+1][3]=t[15]-t[e+12];return Un.forEach((e=>R.divVec4Scalar(e,R.lenVec3(e),e))),e=>Un.every((t=>(In[0]=e[t[0]>=0?3:0],In[1]=e[t[1]>=0?4:1],In[2]=e[t[2]>=0?5:2],In[3]=1,R.dotVec4(t,In)>=0)))}(t.camera);const Q=function(e){let s=0,u=0,d=0,y=0,B=0,E=0,F=0,P=0,k=0,Q=0,O=0,V=0,L=0,H=0,N=0,G=0;for(let t=0,n=e.length;t<n;t++){if(D=e[t],!0===D.culled||!1===D.visible)continue;const n=D.renderFlags;n.colorOpaque&&(D.saoEnabled&&r?a[s++]=D:D.drawColorOpaque(i)),m&&n.colorTransparent&&(c[d++]=D),n.xrayedSilhouetteTransparent&&(g[F++]=D),n.xrayedSilhouetteOpaque&&(p[B++]=D),n.highlightedSilhouetteTransparent&&(C[O++]=D),n.highlightedSilhouetteOpaque&&(w[k++]=D),n.selectedSilhouetteTransparent&&(I[N++]=D),n.selectedSilhouetteOpaque&&(x[L++]=D),D.edges&&_&&(n.edgesOpaque&&(l[u++]=D),n.edgesTransparent&&(h[y++]=D),n.selectedEdgesTransparent&&(T[G++]=D),n.selectedEdgesOpaque&&(U[H++]=D),n.xrayedEdgesTransparent&&(b[P++]=D),n.xrayedEdgesOpaque&&(f[E++]=D),n.highlightedEdgesTransparent&&(M[V++]=D),n.highlightedEdgesOpaque&&(v[Q++]=D))}if(s>0)for(i.withSAO=!0,S=0;S<s;S++)a[S].drawColorOpaque(i);if(u>0)for(S=0;S<u;S++)l[S].drawEdgesColorOpaque(i);if(B>0)for(S=0;S<B;S++)p[S].drawSilhouetteXRayed(i);if(E>0)for(S=0;S<E;S++)f[S].drawEdgesXRayed(i);if(F>0||P>0||d>0||y>0){if(n.enable(n.CULL_FACE),n.enable(n.BLEND),A?(n.blendEquation(n.FUNC_ADD),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)):(n.blendEquation(n.FUNC_ADD),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA)),i.backfaces=!1,o||n.depthMask(!1),(d>0||y>0)&&n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),y>0)for(S=0;S<y;S++)D=h[S],D.drawEdgesColorTransparent(i);if(d>0){const e=i.viewParams.eye;c.length=d;const t=c.map((t=>({drawable:t,distSq:R.distVec3(t.origin||Fn,e)})));for(t.sort(((e,t)=>t.distSq-e.distSq)),S=0;S<d;S++)t[S].drawable.drawColorTransparent(i)}if(P>0)for(S=0;S<P;S++)b[S].drawEdgesXRayed(i);if(F>0)for(S=0;S<F;S++)g[S].drawSilhouetteXRayed(i);n.disable(n.BLEND),o||n.depthMask(!0)}if(k>0||Q>0){if(i.lastProgramId=null,t.highlightMaterial.glowThrough&&n.clear(n.DEPTH_BUFFER_BIT),Q>0)for(S=0;S<Q;S++)v[S].drawEdgesHighlighted(i);if(k>0)for(S=0;S<k;S++)w[S].drawSilhouetteHighlighted(i)}if(O>0||V>0||k>0){if(i.lastProgramId=null,t.selectedMaterial.glowThrough&&n.clear(n.DEPTH_BUFFER_BIT),n.enable(n.BLEND),A?(n.blendEquation(n.FUNC_ADD),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)):n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),n.enable(n.CULL_FACE),V>0)for(S=0;S<V;S++)M[S].drawEdgesHighlighted(i);if(O>0)for(S=0;S<O;S++)C[S].drawSilhouetteHighlighted(i);n.disable(n.BLEND)}if(L>0||H>0){if(i.lastProgramId=null,t.selectedMaterial.glowThrough&&n.clear(n.DEPTH_BUFFER_BIT),H>0)for(S=0;S<H;S++)U[S].drawEdgesSelected(i);if(L>0)for(S=0;S<L;S++)x[S].drawSilhouetteSelected(i)}if(N>0||G>0){if(i.lastProgramId=null,t.selectedMaterial.glowThrough&&n.clear(n.DEPTH_BUFFER_BIT),n.enable(n.CULL_FACE),n.enable(n.BLEND),A?(n.blendEquation(n.FUNC_ADD),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)):n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),G>0)for(S=0;S<G;S++)T[S].drawEdgesSelected(i);if(N>0)for(S=0;S<N;S++)I[S].drawSilhouetteSelected(i);n.disable(n.BLEND)}};Q(u),d.length>0&&(n.clear(n.DEPTH_BUFFER_BIT),Q(d));i.testAABB=null;const O=Date.now(),V=L.frame;V.renderTime=(O-k)/1e3,V.drawElements=i.drawElements,V.drawArrays=i.drawArrays,V.useProgram=i.useProgram,V.bindTexture=i.bindTexture,V.bindArray=i.bindArray;const H=wn.MAX_TEXTURE_IMAGE_UNITS;for(let e=0;e<H;e++)n.activeTexture(n.TEXTURE0+e);n.bindTexture(n.TEXTURE_CUBE_MAP,null),n.bindTexture(n.TEXTURE_2D,null);const N=wn.MAX_VERTEX_ATTRIBS;for(let e=0;e<N;e++)n.disableVertexAttribArray(e)}(e,s,a)}(e,s),L.frame.frameCount++,g=!1)};const U=(e,s,i,r,A,o,a)=>{a.reset(),a.backfaces=!0,a.frontface=!0,a.viewParams.eye=r,a.viewParams.projMatrix=A,a.viewParams.viewMatrix=o,a.nearPlaneHeight=F(i,n.drawingBufferHeight);const l=t.canvas.resolutionScale;a.pickClipPos=[e?2*e[0]*l/n.drawingBufferWidth-1:0,e?1-2*e[1]*l/n.drawingBufferHeight:0],a.pickClipPosInv=[n.drawingBufferWidth/s,n.drawingBufferHeight/s]};this.pick=function(){const e=R.vec3(),s=R.vec3(),A=R.vec4(),o=R.vec4(),l=R.vec4(),c=R.vec4(),h=R.vec4(),p=R.mat4(),f=R.mat4(),g=R.mat4(),m=R.mat4(),_=R.vec3([0,1,0]),b=new fn,y=R.vec2(),B=R.vec3(),w=R.vec3(),v=R.vec3();R.vec3(),R.vec3();const C=new Kr(n);C.setSize([1,1]);const M=new Kr(n,[n.RGBA32I]);return M.setSize([3,3]),function(E,F=b){F.reset(),x();let I=null,T=null,P=null;const S=t.camera;if(F.pickSurface=E.pickSurface,E.canvasPos)B[0]=E.canvasPos[0],B[1]=E.canvasPos[1],I=S.viewMatrix,T=S.projMatrix,P=S.projection,y[0]=S.project.near,y[1]=S.project.far,F.canvasPos=E.canvasPos,R.canvasPosToWorldRay(r,I,T,P,B,e,s),i.testAABB=kn(e,s);else if(B[0]=.5*r.clientWidth,B[1]=.5*r.clientHeight,E.matrix)I=E.matrix,T=S.projMatrix,P=S.projection,y[0]=S.project.near,y[1]=S.project.far,R.canvasPosToWorldRay(r,I,T,P,B,e,s),i.testAABB=kn(e,s);else{w.set(E.origin||[0,0,0]),v.set(E.direction||[0,0,1]);const t=R.addVec3(w,v,e),r=s;Math.abs(R.dotVec3(v,_))>.999999?(r[0]=0,r[1]=0,r[2]=Math.sign(v[1])):(R.cross3Vec3(v,_,r),R.cross3Vec3(r,v,r),R.normalizeVec3(r,r)),I=R.lookAtMat4v(w,t,r,f),T=S.ortho.matrix,P="ortho",y[0]=S.ortho.near,y[1]=S.ortho.far,F.origin=w,F.direction=v,i.testAABB=kn(F.origin,F.direction)}C.bind();const D=e=>U(B,e,S,F.origin||S.eye,T||S.projMatrix,I||S.viewMatrix,i);D(1),i.pickInvisible=!!E.pickInvisible,n.viewport(0,0,1,1),n.depthMask(!0),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT);const k=E.includeEntityIds,Q=E.excludeEntityIds,O=function(e){e.forEach((e=>{e.culled||!e.visible||!e.pickable||!e.drawPickMesh||k&&!k[e.id]||Q&&Q[e.id]||e.drawPickMesh(i)}))};O(u),d.length>0&&(n.clear(n.DEPTH_BUFFER_BIT),O(d)),i.testAABB=null;const V=Pn(C.read(0,0)),L=V>=0&&a.items[V];if(!L)return C.unbind(),null;const H=L.delegatePickedEntity?L.delegatePickedEntity():L;if(!H)return C.unbind(),null;if(E.pickSurface)if(L.canPickTriangle&&L.canPickTriangle())L.drawPickTriangles&&(D(1),n.viewport(0,0,1,1),n.clearColor(0,0,0,0),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),L.drawPickTriangles(i),F.primIndex=3*Pn(C.read(0,0))),L.pickTriangleSurface(I,T,P,F),F.pickSurfacePrecision=!1;else if(L.canPickWorldPos&&L.canPickWorldPos()){D(1),i.viewParams.near=y[0],i.viewParams.far=y[1],n.viewport(0,0,1,1),n.clearColor(0,0,0,0),n.depthMask(!0),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),L.drawPickDepths(i);const e=R.dotVec4(C.read(0,0),Tn),t=(B[0]-r.clientWidth/2)/(r.clientWidth/2),s=-(B[1]-r.clientHeight/2)/(r.clientHeight/2),a=L.origin,u=R.inverseMat4(R.mulMat4(T,a?ut(I,a,p):I,g),m),d=(e,i)=>(i[0]=t,i[1]=s,i[2]=e,i[3]=1,R.transformVec4(u,i,i),R.mulVec4Scalar(i,1/i[3])),f=d(-1,A),_=d(1,o),b=R.subVec3(_,f,l),w=R.addVec3(f,R.mulVec4Scalar(b,e,c),h);if(a&&R.addVec3(w,a),F.worldPos=w,!1!==E.pickSurfaceNormal){D(3),M.bind(),n.viewport(0,0,M.size[0],M.size[1]),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.DEPTH_BUFFER_BIT),n.clearBufferiv(n.COLOR,0,new Int32Array([0,0,0,0])),L.drawPickNormals(i);const e=M.read(1,1,n.RGBA_INTEGER,n.INT,Int32Array,4);M.unbind(),F.worldNormal=Sn(e)}F.pickSurfacePrecision=!1}return C.unbind(),F.entity=H,F}}(),this.snapPick=function(){const e=new fn,s=function(){const e={};return t=>{if(!(t in e)){const s=new Kr(n,[n.RGBA32I,n.RGBA32I,n.RGBA8UI],!0);s.setSize([2*t+1,2*t+1]),e[t]=s}return e[t]}}();return function(r,A=e){const{canvasPos:o,origin:l,direction:c,snapRadius:h,snapToVertex:d,snapToEdge:p}=r;if(!d&&!p)return this.pick({canvasPos:o,pickSurface:!0});const f=t.camera,g=h||30,m=o?f.viewMatrix:R.lookAtMat4v(l,R.addVec3(l,c,R.vec3()),R.vec3([0,1,0]),R.mat4());U(o,2*g,f,f.eye,f.projMatrix,m,i);const _=s(g);_.bind(),n.viewport(0,0,_.size[0],_.size[1]),n.enable(n.DEPTH_TEST),n.frontFace(n.CCW),n.disable(n.CULL_FACE),n.depthMask(!0),n.disable(n.BLEND),n.depthFunc(n.LEQUAL),n.clear(n.DEPTH_BUFFER_BIT),n.clearBufferiv(n.COLOR,0,new Int32Array([0,0,0,0])),n.clearBufferiv(n.COLOR,1,new Int32Array([0,0,0,0])),n.clearBufferuiv(n.COLOR,2,new Uint32Array([0,0,0,0])),n.drawBuffers([n.COLOR_ATTACHMENT0,n.COLOR_ATTACHMENT1,n.COLOR_ATTACHMENT2]),i.snapPickLayerParams=[],i.snapPickLayerParams.push(null),u.forEach((e=>{!e.culled&&e.visible&&e.pickable&&e.drawSnapInit&&e.drawSnapInit(i)}));const b=i.snapPickLayerParams;i.snapPickLayerParams=[],n.depthMask(!1),n.drawBuffers([n.COLOR_ATTACHMENT0]);const y=e=>{i.snapMode=e,i.snapPickLayerParams.push(null),u.forEach((e=>{!e.culled&&e.visible&&e.pickable&&e.drawSnap&&e.drawSnap(i)}))};p&&y("edge"),d&&y("vertex"),n.depthMask(!0);const B=i.snapPickLayerParams,w=(e,t,s)=>{const i=_.buffer.width,r=_.buffer.height,A=new t(4*i*r);return n.readBuffer(e),n.readPixels(0,0,i,r,n.RGBA_INTEGER,s,A,0),A},v=w(n.COLOR_ATTACHMENT0,Int32Array,n.INT),C=w(n.COLOR_ATTACHMENT1,Int32Array,n.INT),M=w(n.COLOR_ATTACHMENT2,Uint32Array,n.UNSIGNED_INT);_.unbind();let E=null,F=null,x=null;const I=4*g+g*_.size[0]*4,T=v.slice(I,I+4),P=C.slice(I,I+4),S=M.slice(I,I+4);if(0!==T[3]){const e=b[Math.abs(T[3])%b.length];E=Dn(T,e.origin,e.coordinateScale),F=Sn(P),x=a.items[Pn(S)]}const D=[];for(let e=0;e<v.length;e+=4){const t=v[e+3];if(t>0){const s=Math.floor(e/4),i=_.size[0],r=s%i-Math.floor(i/2),n=Math.floor(s/i)-Math.floor(i/2);D.push({dist:R.lenVec2([r,n]),isVertex:d&&p?t>B.length/2:d,result:v.subarray(e,e+4),normal:C.subarray(e,e+4),id:M.subarray(e,e+4)})}}const k=e=>e&&e.delegatePickedEntity?e.delegatePickedEntity():e;if(D.length>0){const e=D.reduce(((e,t)=>(e.isVertex-t.isVertex||t.dist-e.dist)>0?e:t)),t=e.result,s=B[t[3]],i=Dn(t,s.origin,s.coordinateScale),r=f.projectWorldPos(i);return A.reset(),A.snappedToEdge=!e.isVertex,A.snappedToVertex=e.isVertex,A.worldPos=i,A.worldNormal=Sn(e.normal),A.entity=k(a.items[Pn(e.id)]),A.canvasPos=o||E&&f.projectWorldPos(E)||r,A.snappedCanvasPos=r,A}return E?(A.reset(),A.snappedToEdge=!1,A.snappedToVertex=!1,A.worldPos=E,A.worldNormal=F,A.entity=k(x),A.canvasPos=o||f.projectWorldPos(E),A.snappedCanvasPos=o,A):null}}(),this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new En(t),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){x();const e=w.getRenderBuffer("occlusionReadPix");if(e&&(e.setSize([n.drawingBufferWidth,n.drawingBufferHeight]),e.bind()),i.reset(),i.backfaces=!0,i.frontface=!0,i.viewParams=E(),i.nearPlaneHeight=F(t.camera,n.drawingBufferHeight),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),n.clearColor(0,0,0,0),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),u.forEach((e=>{!e.culled&&e.visible&&e.pickable&&e.drawOcclusion&&e.drawOcclusion(i)})),this._occlusionTester.drawMarkers(),e){const s=t.canvas.resolutionScale;this._occlusionTester.doOcclusionTest(((t,i)=>e.read(Math.round(s*t),Math.round(s*i)))),e.unbind()}}},this.snapshot=(()=>{let e=!1;const t=new Kr(n);let s=null;return{readPixels:(e,s,i)=>{t.bind(),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),g=!0,this.render();for(let r=0;r<i;r++){const i=2*r,n=4*r,A=t.read(e[i],e[i+1]);s[n]=A[0],s[n+1]=A[1],s[n+2]=A[2],s[n+3]=A[3]}t.unbind(),g=!0},beginSnapshot:()=>{t.setSize([n.drawingBufferWidth,n.drawingBufferHeight]),t.bind(),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),e=!0},renderSnapshotToCanvas:()=>{const i=t.buffer.width,r=t.buffer.height;return s&&s.width===i&&s.height===r||(s=function(){const e=document.createElement("canvas"),t=e.getContext("2d");e.width=i,e.height=r;const s=new Uint8Array(i*r*4),A=t.createImageData(i,r);return{width:i,height:r,getUpdatedCanvas:()=>{n.readPixels(0,0,i,r,n.RGBA,n.UNSIGNED_BYTE,s);const o=Math.floor(r/2),a=4*i,l=new Uint8Array(a);for(let e=0;e<o;++e){const t=e*a,i=(r-e-1)*a;l.set(s.subarray(t,t+a)),s.copyWithin(t,i,i+a),s.set(l,i)}return A.data.set(s),t.resetTransform(),t.putImageData(A,0,0),e}}}()),e&&(n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),g=!0,this.render(),g=!0),s.getUpdatedCanvas()},endSnapshot:()=>{e&&(t.unbind(),e=!1),g=!0,this.render()}}})(),this.destroy=function(){l={},c={},w.destroy(),C.destroy(),M.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}};class Rn extends ie{constructor(e,t={}){super(e,t),this.KEY_BACKSPACE=8,this.KEY_TAB=9,this.KEY_ENTER=13,this.KEY_SHIFT=16,this.KEY_CTRL=17,this.KEY_ALT=18,this.KEY_PAUSE_BREAK=19,this.KEY_CAPS_LOCK=20,this.KEY_ESCAPE=27,this.KEY_PAGE_UP=33,this.KEY_PAGE_DOWN=34,this.KEY_END=35,this.KEY_HOME=36,this.KEY_LEFT_ARROW=37,this.KEY_UP_ARROW=38,this.KEY_RIGHT_ARROW=39,this.KEY_DOWN_ARROW=40,this.KEY_INSERT=45,this.KEY_DELETE=46,this.KEY_NUM_0=48,this.KEY_NUM_1=49,this.KEY_NUM_2=50,this.KEY_NUM_3=51,this.KEY_NUM_4=52,this.KEY_NUM_5=53,this.KEY_NUM_6=54,this.KEY_NUM_7=55,this.KEY_NUM_8=56,this.KEY_NUM_9=57,this.KEY_A=65,this.KEY_B=66,this.KEY_C=67,this.KEY_D=68,this.KEY_E=69,this.KEY_F=70,this.KEY_G=71,this.KEY_H=72,this.KEY_I=73,this.KEY_J=74,this.KEY_K=75,this.KEY_L=76,this.KEY_M=77,this.KEY_N=78,this.KEY_O=79,this.KEY_P=80,this.KEY_Q=81,this.KEY_R=82,this.KEY_S=83,this.KEY_T=84,this.KEY_U=85,this.KEY_V=86,this.KEY_W=87,this.KEY_X=88,this.KEY_Y=89,this.KEY_Z=90,this.KEY_LEFT_WINDOW=91,this.KEY_RIGHT_WINDOW=92,this.KEY_SELECT_KEY=93,this.KEY_NUMPAD_0=96,this.KEY_NUMPAD_1=97,this.KEY_NUMPAD_2=98,this.KEY_NUMPAD_3=99,this.KEY_NUMPAD_4=100,this.KEY_NUMPAD_5=101,this.KEY_NUMPAD_6=102,this.KEY_NUMPAD_7=103,this.KEY_NUMPAD_8=104,this.KEY_NUMPAD_9=105,this.KEY_MULTIPLY=106,this.KEY_ADD=107,this.KEY_SUBTRACT=109,this.KEY_DECIMAL_POINT=110,this.KEY_DIVIDE=111,this.KEY_F1=112,this.KEY_F2=113,this.KEY_F3=114,this.KEY_F4=115,this.KEY_F5=116,this.KEY_F6=117,this.KEY_F7=118,this.KEY_F8=119,this.KEY_F9=120,this.KEY_F10=121,this.KEY_F11=122,this.KEY_F12=123,this.KEY_NUM_LOCK=144,this.KEY_SCROLL_LOCK=145,this.KEY_SEMI_COLON=186,this.KEY_EQUAL_SIGN=187,this.KEY_COMMA=188,this.KEY_DASH=189,this.KEY_PERIOD=190,this.KEY_FORWARD_SLASH=191,this.KEY_GRAVE_ACCENT=192,this.KEY_OPEN_BRACKET=219,this.KEY_BACK_SLASH=220,this.KEY_CLOSE_BRACKET=221,this.KEY_SINGLE_QUOTE=222,this.KEY_SPACE=32,this.MOUSE_LEFT_BUTTON=260,this.MOUSE_MIDDLE_BUTTON=261,this.MOUSE_RIGHT_BUTTON=262,this.element=t.element,this.altDown=!1,this.ctrlDown=!1,this.mouseDownLeft=!1,this.mouseDownMiddle=!1,this.mouseDownRight=!1,this.keyDown=[],this.enabled=!0,this.keyboardEnabled=!0,this.mouseover=!1,this.mouseCanvasPos=R.vec2(),this._keyboardEventsElement=t.keyboardEventsElement||document,this._bindEvents()}_bindEvents(){if(this._eventsBound)return;this._keyboardEventsElement.addEventListener("keydown",this._keyDownListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}});const e=this.scene.tickify((()=>this.fire("mousemove",this.mouseCanvasPos,!0)));this.element.addEventListener("mousemove",this._mouseMoveListener=t=>{this.enabled&&(this._getMouseCanvasPos(t),e(),this.mouseover&&t.preventDefault())}),this.element.addEventListener("contextmenu",this._contextmenuListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("contextmenu",this.mouseCanvasPos,!0))});const t=this.scene.tickify((e=>{this.fire("mousewheel",e,!0)}));this.element.addEventListener("wheel",this._mouseWheelListener=(e,s)=>{if(!this.enabled)return;const i=Math.max(-1,Math.min(1,40*-e.deltaY));t(i)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(i=>{e>=i[0]-s&&e<=i[0]+s&&t>=i[1]-s&&t<=i[1]+s&&this.fire("mouseclicked",i,!0)}))}this.element.addEventListener("touchstart",this._touchstartListener=e=>{this.enabled&&[...e.changedTouches].forEach((e=>{this.fire("touchstart",[e.identifier,this._getTouchCanvasPos(e)],!0)}))}),this.element.addEventListener("touchend",this._touchendListener=e=>{this.enabled&&[...e.changedTouches].forEach((e=>{this.fire("touchend",[e.identifier,this._getTouchCanvasPos(e)],!0)}))}),this._eventsBound=!0}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("contextmenu",this._contextmenuListener),this.element.removeEventListener("wheel",this._mouseWheelListener),this.element.removeEventListener("touchstart",this._touchstartListener),this.element.removeEventListener("touchend",this._touchendListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getTouchCanvasPos(e){let t=e.target,s=0,i=0;for(;t.offsetParent;)s+=t.offsetLeft,i+=t.offsetTop,t=t.offsetParent;return[e.pageX-s,e.pageY-i]}_getMouseCanvasPos(e){if(e){const t=e.target.getBoundingClientRect();this.mouseCanvasPos[0]=e.clientX-t.left,this.mouseCanvasPos[1]=e.clientY-t.top}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}class On extends ie{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new xe({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class Vn extends ie{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new xe({matrix:R.mat4(),inverseMatrix:R.mat4(),transposedMatrix:R.mat4(),near:.1,far:1e4}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.canvas.boundary,t=e[2]/e[3],s=this._fovAxis;let i=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(i/=t),i=Math.min(i,120),R.perspectiveMat4(i*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:1e4;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(R.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(R.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,i,r){const n=this.scene.canvas.canvas,A=n.offsetWidth/2,o=n.offsetHeight/2;return s[0]=(e[0]-A)/A,s[1]=(e[1]-o)/o,s[2]=t,s[3]=1,R.mulMat4v4(this.inverseMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1,R.mulMat4v4(this.camera.inverseViewMatrix,i,r),r}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class Ln extends ie{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new xe({matrix:R.mat4(),inverseMatrix:R.mat4(),transposedMatrix:R.mat4(),near:.1,far:1e4}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.canvas.boundary,i=s[2],r=s[3],n=i/r;let A,o,a,l;i>r?(A=-t,o=t,a=t/n,l=-t/n):(A=-t*n,o=t*n,a=t,l=-t),R.orthoMat4c(A,o,l,a,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:1e4;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(R.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(R.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,i,r){const n=this.scene.canvas.canvas,A=n.offsetWidth/2,o=n.offsetHeight/2;return s[0]=(e[0]-A)/A,s[1]=(e[1]-o)/o,s[2]=t,s[3]=1,R.mulMat4v4(this.inverseMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1,R.mulMat4v4(this.camera.inverseViewMatrix,i,r),r}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class Hn extends ie{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new xe({matrix:R.mat4(),inverseMatrix:R.mat4(),transposedMatrix:R.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){R.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(R.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(R.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,i,r){const n=this.scene.canvas.canvas,A=n.offsetWidth/2,o=n.offsetHeight/2;return s[0]=(e[0]-A)/A,s[1]=(e[1]-o)/o,s[2]=t,s[3]=1,R.mulMat4v4(this.inverseMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1,R.mulMat4v4(this.camera.inverseViewMatrix,i,r),r}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class Nn extends ie{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new xe({matrix:R.mat4(),inverseMatrix:R.mat4(),transposedMatrix:R.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(R.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(R.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,i,r){const n=this.scene.canvas.canvas,A=n.offsetWidth/2,o=n.offsetHeight/2;return s[0]=(e[0]-A)/A,s[1]=(e[1]-o)/o,s[2]=t,s[3]=1,R.mulMat4v4(this.inverseMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1,R.mulMat4v4(this.camera.inverseViewMatrix,i,r),r}destroy(){super.destroy(),this._state.destroy()}}const Gn=R.vec3(),jn=R.vec3(),zn=R.vec3(),Wn=R.vec3(),Xn=R.vec3(),Kn=R.vec3(),Zn=R.vec4(),Jn=R.vec4(),Yn=R.vec4(),$n=R.mat4(),qn=R.mat4(),eA=R.vec3(),tA=R.vec3(),sA=R.vec3(),iA=R.vec3();class rA extends ie{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new xe({offsetEyeFromLook:!0,deviceMatrix:R.mat4(),hasDeviceMatrix:!1,matrix:R.mat4(),normalMatrix:R.mat4(),inverseMatrix:R.mat4()}),this._perspective=new Vn(this),this._ortho=new Ln(this),this._frustum=new Hn(this),this._customProjection=new Nn(this),this._project=this._perspective,this._eye=R.vec3([0,0,10]),this._look=R.vec3([0,0,0]),this._up=R.vec3([0,1,0]),this._worldUp=R.vec3([0,1,0]),this._worldRight=R.vec3([1,0,0]),this._worldForward=R.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection&&this._state.offsetEyeFromLook?(R.subVec3(this._eye,this._look,eA),R.normalizeVec3(eA,tA),R.mulVec3Scalar(tA,1e3,sA),R.addVec3(this._look,sA,iA),t=iA):t=this._eye,e.hasDeviceMatrix?(R.lookAtMat4v(t,this._look,this._up,qn),R.mulMat4(e.deviceMatrix,qn,e.matrix)):R.lookAtMat4v(t,this._look,this._up,e.matrix),R.inverseMat4(this._state.matrix,this._state.inverseMatrix),R.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=R.subVec3(this._eye,this._look,Gn);R.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,$n),t=R.transformPoint3($n,t,jn),this.eye=R.addVec3(this._look,t,zn),this.up=R.transformPoint3($n,this._up,Wn)}orbitPitch(e){if(this._constrainPitch&&(e=R.dotVec3(this._up,this._worldUp)/R.DEGTORAD)<1)return;let t=R.subVec3(this._eye,this._look,Gn);const s=R.cross3Vec3(R.normalizeVec3(t,jn),R.normalizeVec3(this._up,zn));R.rotationMat4v(.0174532925*e,s,$n),t=R.transformPoint3($n,t,Wn),this.up=R.transformPoint3($n,this._up,Xn),this.eye=R.addVec3(t,this._look,Kn)}yaw(e){let t=R.subVec3(this._look,this._eye,Gn);R.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,$n),t=R.transformPoint3($n,t,jn),this.look=R.addVec3(t,this._eye,zn),this._gimbalLock&&(this.up=R.transformPoint3($n,this._up,Wn))}pitch(e){if(this._constrainPitch&&(e=R.dotVec3(this._up,this._worldUp)/R.DEGTORAD)<1)return;let t=R.subVec3(this._look,this._eye,Gn);const s=R.cross3Vec3(R.normalizeVec3(t,jn),R.normalizeVec3(this._up,zn));R.rotationMat4v(.0174532925*e,s,$n),this.up=R.transformPoint3($n,this._up,Kn),t=R.transformPoint3($n,t,Wn),this.look=R.addVec3(t,this._eye,Xn)}pan(e){const t=R.subVec3(this._eye,this._look,Gn),s=[0,0,0];let i;if(0!==e[0]){const r=R.cross3Vec3(R.normalizeVec3(t,[]),R.normalizeVec3(this._up,jn));i=R.mulVec3Scalar(r,e[0]),s[0]+=i[0],s[1]+=i[1],s[2]+=i[2]}0!==e[1]&&(i=R.mulVec3Scalar(R.normalizeVec3(this._up,zn),e[1]),s[0]+=i[0],s[1]+=i[1],s[2]+=i[2]),0!==e[2]&&(i=R.mulVec3Scalar(R.normalizeVec3(t,Wn),e[2]),s[0]+=i[0],s[1]+=i[1],s[2]+=i[2]),this.eye=R.addVec3(this._eye,s,Xn),this.look=R.addVec3(this._look,s,Kn)}zoom(e){const t=R.subVec3(this._eye,this._look,Gn),s=Math.abs(R.lenVec3(t,jn)),i=Math.abs(s+e);if(i<.5)return;const r=R.normalizeVec3(t,zn);this.eye=R.addVec3(this._look,R.mulVec3Scalar(r,i),Wn)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=R.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return R.lenVec3(R.subVec3(this._look,this._eye,Gn))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}get offsetEyeFromLook(){return this._state.offsetEyeFromLook}set offsetEyeFromLook(e){this._state.offsetEyeFromLook=e,this._needUpdate(0)}projectWorldPos(e){const t=Zn,s=Jn,i=Yn;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,R.mulMat4v4(this.viewMatrix,t,s),R.mulMat4v4(this.projMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1;const r=this.scene.canvas.canvas,n=r.offsetWidth/2,A=r.offsetHeight/2;return[i[0]*n+n,i[1]*A+A]}destroy(){super.destroy(),this._state.destroy()}}const nA={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class AA extends ie{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=R.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return nA}set units(e){e||(e="meters");nA[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=R.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=R.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class oA extends ie{constructor(e,t={}){super(e,t),this._supported=wn.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}class aA extends ie{constructor(e,t={}){super(e,t),this.sliceColor=t.sliceColor,this.sliceThickness=t.sliceThickness}set sliceThickness(e){null==e&&(e=0),this._sliceThickness!==e&&(this._sliceThickness=e,this.glRedraw())}get sliceThickness(){return this._sliceThickness}set sliceColor(e){null==e&&(e=[0,0,0,1]),this._sliceColor!==e&&(this._sliceColor=e,this.glRedraw())}get sliceColor(){return this._sliceColor}destroy(){super.destroy()}}const lA={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class cA extends Ht{get type(){return"PointsMaterial"}get presets(){return lA}constructor(e,t={}){super(e,t),this._state=new xe({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=lA[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(lA).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const hA={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class uA extends Ht{get type(){return"LinesMaterial"}get presets(){return hA}constructor(e,t={}){super(e,t),this._state=new xe({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=hA[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(hA).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}const dA=R.vec3();class pA{constructor(e){let t=null;const s={},i=[];this.destroy=()=>t&&t();let r=null;const n=()=>{clearTimeout(r),r=setTimeout((()=>{const t=Object.values(e.models).filter((e=>e.id in s&&e.visible));i.forEach((i=>{if(i.active){const r=R.makeSectionPlaneSlicer(i);t.forEach((t=>{const n=t.aabb;if(R.planeIntersectsAABB3(i,n)){const A=R.getAABB3Center(n,R.vec3());s[t.id].entityCaches.forEach(((s,n)=>{const o=t.objects[n];s.generateCaps&&o.capMaterial&&R.planeIntersectsAABB3(i,o.aabb)&&(s.meshCaches||=o.meshes.filter((e=>e.isSolid())).map((e=>{const t=[],s=[];return e.getEachIndex((e=>t.push(e))),e.getEachVertex((e=>s.push(...R.subVec3(e,A,dA)))),{mesh:e,meshIndices:t,meshVertices:s}})),s.meshCaches.filter((e=>R.planeIntersectsAABB3(i,e.mesh.aabb))).forEach(((t,a)=>{const l=r({origin:A,indices:t.meshIndices,positions:t.meshVertices},{onlyPosSliceWithUV:!0}).pos;l&&s.capMeshes.push(new Ot(e,{isObject:!0,id:`${i.id}-${n}-${a}`,material:o.capMaterial,origin:R.addVec3(A,R.mulVec3Scalar(i.dir,.001,dA),dA),geometry:new Le(e,{primitive:"triangles",indices:l.indices,positions:l.positions,normals:l.normals,uv:l.uv})}))})))}))}}))}})),t.forEach((e=>s[e.id].entityCaches.forEach((e=>e.generateCaps=!1))))}),100)};this._onCapMaterialUpdated=A=>{if(!t){r=null;const A=e=>{const t=()=>{Object.values(s).forEach((e=>e.entityCaches.forEach((e=>{e.destroyCaps(),e.generateCaps=!0})))),n()};i.push(e),e.on("pos",t),e.on("dir",t),e.on("active",t),e.once("destroyed",(()=>{const s=i.indexOf(e);s>=0&&(i.splice(s,1),t())}))};for(const t in e.sectionPlanes)A(e.sectionPlanes[t]);const o=e.on("sectionPlaneCreated",A),a=e.on("tick",(()=>{let t=!1;for(const i in s){const r=e.models[i];if(r){if(s[i].modelVisible!=r.visible){const e=s[i];e.modelVisible=!!r.visible,e.entityCaches.forEach((e=>{e.destroyCaps(),e.generateCaps=!0})),t=!0}}else s[i].entityCaches.forEach((e=>e.destroyCaps())),delete s[i],t=!0}t&&n()}));t=()=>{for(const e in s)s[e].entityCaches.forEach((e=>e.destroyCaps()));e.off(o),e.off(a)}}const o=A.model,a=o.id;s[a]||={modelVisible:o.visible,entityCaches:new Map};const l=s[a].entityCaches,c=A.id;if(!l.has(c)){const e={capMeshes:[],meshCaches:null,generateCaps:!1,destroyCaps:()=>{e.capMeshes.forEach((e=>e.destroy())),e.capMeshes.length=0}};l.set(c,e)}const h=l.get(c);h.destroyCaps(),h.generateCaps=!0,n()}}}function fA(e,t){const s={};let i,r;for(let n=0,A=t.length;n<A;n++)i=t[n],r=e.components[i],r?r.isEntity?s[i]=!0:e.warn("pick(): Component is not an Entity: "+i):e.warn("pick(): Component not found: "+i);return s}class gA extends ie{get type(){return"Scene"}constructor(e,t={}){super(null,t);const s=t.canvasElement||document.querySelector(`#${t.canvasId}`);if(!(s instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";this._tickifiedFunctions={};const i=!!t.transparent,r=!!t.alphaDepthMask;this._aabbDirty=!0,this._readableGeometry=!!t.readableGeometryEnabled,this.viewer=e,this.occlusionTestCountdown=0,this.loading=0,this.startTime=(new Date).getTime(),this.models={},this.objects={},this._numObjects=0,this.visibleObjects={},this._numVisibleObjects=0,this.xrayedObjects={},this._numXRayedObjects=0,this.highlightedObjects={},this._numHighlightedObjects=0,this.selectedObjects={},this._numSelectedObjects=0,this.colorizedObjects={},this._numColorizedObjects=0,this.opacityObjects={},this._numOpacityObjects=0,this.offsetObjects={},this._numOffsetObjects=0,this._modelIds=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this._opacityObjectIds=null,this._offsetObjectIds=null,this._collidables={},this._compilables={},this._needRecompile=!1,this.types={},this.components={},this.sectionPlanes={},this.lights={},this.lightMaps={},this.reflectionMaps={},this.bitmaps={},this.lineSets={},this.realWorldOffset=t.realWorldOffset||new Float64Array([0,0,0]),this.canvas=new yn(this,{dontClear:!0,canvas:s,spinnerElementId:t.spinnerElementId,transparent:i,webgl2:!1!==t.webgl2,contextAttr:t.contextAttr||{},backgroundColor:t.backgroundColor,backgroundColorFromAmbientLight:t.backgroundColorFromAmbientLight,premultipliedAlpha:t.premultipliedAlpha});const n=e=>this.viewer.destroy();s.addEventListener("webglcontextlost",n,!1),this._removeWebglcontextlostListener=()=>s.removeEventListener("webglcontextlost",n,!1),this.canvas.on("boundary",(()=>{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new Qn(this,{transparent:i,alphaDepthMask:r}),this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1,this._numCachedSectionPlanes=0;let e=null;this.getHash=function(){if(e)return e;const t=this.getNumAllocatedSectionPlanes();if(this.sectionPlanes,0===t)return this.hash=";";const s=[];for(let e=0,i=t;e<i;e++)s.push("cp");return s.push(";"),e=s.join(""),e},this.addSectionPlane=function(t){this.sectionPlanes.push(t),e=null},this.removeSectionPlane=function(t){for(let s=0,i=this.sectionPlanes.length;s<i;s++)if(this.sectionPlanes[s].id===t.id)return this.sectionPlanes.splice(s,1),void(e=null)},this.setNumCachedSectionPlanes=function(t){this._numCachedSectionPlanes=t,e=null},this.getNumCachedSectionPlanes=function(){return this._numCachedSectionPlanes},this.getNumAllocatedSectionPlanes=function(){const e=this.sectionPlanes.length;return e>this._numCachedSectionPlanes?e:this._numCachedSectionPlanes}},this._sectionPlanesState.setNumCachedSectionPlanes(t.numCachedSectionPlanes||0),this._lightsState=new function(){const e=R.vec4([0,0,0,0]),t=R.vec4();this.lights=[],this.reflectionMaps=[],this.lightMaps=[];let s=null,i=null;this.getHash=function(){if(s)return s;const e=[],t=this.lights;let i;for(let s=0,r=t.length;s<r;s++)i=t[s],e.push("/"),e.push(i.type),e.push("world"===i.space?"w":"v"),i.castsShadow&&e.push("sh");return this.lightMaps.length>0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),i=null,s=null},this.removeLight=function(e){for(let t=0,r=this.lights.length;t<r;t++){if(this.lights[t].id===e.id)return this.lights.splice(t,1),i&&i.id===e.id&&(i=null),void(s=null)}},this.addReflectionMap=function(e){this.reflectionMaps.push(e),s=null},this.removeReflectionMap=function(e){for(let t=0,i=this.reflectionMaps.length;t<i;t++)if(this.reflectionMaps[t].id===e.id)return this.reflectionMaps.splice(t,1),void(s=null)},this.addLightMap=function(e){this.lightMaps.push(e),s=null},this.removeLightMap=function(e){for(let t=0,i=this.lightMaps.length;t<i;t++)if(this.lightMaps[t].id===e.id)return this.lightMaps.splice(t,1),void(s=null)},this.getAmbientColorAndIntensity=function(){if(!i)for(let e=0,t=this.lights.length;e<t;e++){const t=this.lights[e];if("ambient"===t.type){i=t;break}}if(i){const e=i.color,s=i.intensity;return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=s,t}return e}},this.input=new Rn(this,{dontClear:!0,element:this.canvas.canvas,keyboardEventsElement:t.keyboardEventsElement}),this.metrics=new AA(this,{units:t.units,scale:t.scale,origin:t.origin}),this.sao=new oA(this,{enabled:t.saoEnabled}),this.crossSections=new aA(this,{}),this.ticksPerRender=t.ticksPerRender,this.ticksPerOcclusionTest=t.ticksPerOcclusionTest,this.passes=t.passes,this.clearEachPass=t.clearEachPass,this.gammaInput=t.gammaInput,this.gammaOutput=t.gammaOutput,this.gammaFactor=t.gammaFactor,this._entityOffsetsEnabled=!!t.entityOffsetsEnabled,this._logarithmicDepthBufferEnabled=!!t.logarithmicDepthBufferEnabled,this._dtxEnabled=!1!==t.dtxEnabled,this._pbrEnabled=!!t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._dtxEnabled=!!t.dtxEnabled,this._markerZOffset=t.markerZOffset,q._addScene(this),this._initDefaults(),this._viewport=new On(this,{id:"default.viewport",autoBoundary:!0,dontClear:!0}),this._camera=new rA(this,{id:"default.camera",dontClear:!0}),this._sectionCaps=new pA(this),new Xr(this,{color:[1,1,1],intensity:.7}),new Zr(this,{dir:[.8,-.5,-.5],color:[.67,.67,1],intensity:.7,space:"world"}),new Zr(this,{dir:[-.8,-1,.5],color:[1,1,.9],intensity:.9,space:"world"}),this._camera.on("dirty",(()=>{this._renderer.imageDirty()}))}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+j.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=R.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const i=this.types[s];i&&(delete i[t],j.isEmptyObject(i)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_deRegisterVisibleObject(e){delete this.visibleObjects[e.id],this._numVisibleObjects--,this._visibleObjectIds=null}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_deRegisterXRayedObject(e){delete this.xrayedObjects[e.id],this._numXRayedObjects--,this._xrayedObjectIds=null}_objectHighlightedUpdated(e){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null}_deRegisterHighlightedObject(e){delete this.highlightedObjects[e.id],this._numHighlightedObjects--,this._highlightedObjectIds=null}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_deRegisterSelectedObject(e){delete this.selectedObjects[e.id],this._numSelectedObjects--,this._selectedObjectIds=null}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_deRegisterColorizedObject(e){delete this.colorizedObjects[e.id],this._numColorizedObjects--,this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_deRegisterOpacityObject(e){delete this.opacityObjects[e.id],this._numOpacityObjects--,this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_deRegisterOffsetObject(e){delete this.offsetObjects[e.id],this._numOffsetObjects--,this._offsetObjectIds=null}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get readableGeometryEnabled(){return this._readableGeometry}get pickSurfacePrecisionEnabled(){return this._readableGeometry}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set numCachedSectionPlanes(e){e=e||0,this._sectionPlanesState.getNumCachedSectionPlanes()!==e&&(this._sectionPlanesState.setNumCachedSectionPlanes(e),this._needRecompile=!0,this.glRedraw())}get numCachedSectionPlanes(){return this._sectionPlanesState.getNumCachedSectionPlanes()}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}get markerZOffset(){return null==this._markerZOffset?-.001:this._markerZOffset}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&q.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;for(let s=0;s<this._passes;s++)t.pass=s,this.fire("rendering",t,!0),e&&this._renderer.imageDirty(),this._renderer.render(s,this._clearEachPass||0===s),this.fire("rendered",t,!0);this._saveAmbientColor()}}compile(){this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1)}_recompile(){for(const e in this._compilables)this._compilables.hasOwnProperty(e)&&this._compilables[e].compile();this._renderer.shadowsDirty(),this.fire("compile",this,!0)}_saveAmbientColor(){const e=this.canvas;if(e.transparent||e.backgroundImage||e.backgroundColor)this._lastAmbientColor=null;else{const t=this._lightsState.getAmbientColorAndIntensity();this._lastAmbientColor&&this._lastAmbientColor[0]===t[0]&&this._lastAmbientColor[1]===t[1]&&this._lastAmbientColor[2]===t[2]&&this._lastAmbientColor[3]===t[3]||(e.backgroundColor=t,this._lastAmbientColor||(this._lastAmbientColor=R.vec4([0,0,0,1])),this._lastAmbientColor.set(t))}}get modelIds(){return this._modelIds||(this._modelIds=Object.keys(this.models)),this._modelIds}get numObjects(){return this._numObjects}get objectIds(){return this._objectIds||(this._objectIds=Object.keys(this.objects)),this._objectIds}get numVisibleObjects(){return this._numVisibleObjects}get visibleObjectIds(){return this._visibleObjectIds||(this._visibleObjectIds=Object.keys(this.visibleObjects)),this._visibleObjectIds}get numXRayedObjects(){return this._numXRayedObjects}get xrayedObjectIds(){return this._xrayedObjectIds||(this._xrayedObjectIds=Object.keys(this.xrayedObjects)),this._xrayedObjectIds}get numHighlightedObjects(){return this._numHighlightedObjects}get highlightedObjectIds(){return this._highlightedObjectIds||(this._highlightedObjectIds=Object.keys(this.highlightedObjects)),this._highlightedObjectIds}get numSelectedObjects(){return this._numSelectedObjects}get selectedObjectIds(){return this._selectedObjectIds||(this._selectedObjectIds=Object.keys(this.selectedObjects)),this._selectedObjectIds}get numColorizedObjects(){return this._numColorizedObjects}get colorizedObjectIds(){return this._colorizedObjectIds||(this._colorizedObjectIds=Object.keys(this.colorizedObjects)),this._colorizedObjectIds}get opacityObjectIds(){return this._opacityObjectIds||(this._opacityObjectIds=Object.keys(this.opacityObjects)),this._opacityObjectIds}get offsetObjectIds(){return this._offsetObjectIds||(this._offsetObjectIds=Object.keys(this.offsetObjects)),this._offsetObjectIds}set ticksPerRender(e){null==e?e=1:(!j.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerRender': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._ticksPerRender&&(this._ticksPerRender=e)}get ticksPerRender(){return this._ticksPerRender}set ticksPerOcclusionTest(e){null==e?e=20:(!j.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerOcclusionTest': '"+e+"' - should be an integer greater than zero."),e=20),e!==this._ticksPerOcclusionTest&&(this._ticksPerOcclusionTest=e)}get ticksPerOcclusionTest(){return this._ticksPerOcclusionTest}set passes(e){null==e?e=1:(!j.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'passes': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._passes&&(this._passes=e,this.glRedraw())}get passes(){return this._passes}set clearEachPass(e){(e=!!e)!==this._clearEachPass&&(this._clearEachPass=e,this.glRedraw())}get clearEachPass(){return this._clearEachPass}set gammaInput(e){(e=!1!==e)!==this._renderer.gammaInput&&(this._renderer.gammaInput=e,this._needRecompile=!0,this.glRedraw())}get gammaInput(){return this._renderer.gammaInput}set gammaOutput(e){(e=!!e)!==this._renderer.gammaOutput&&(this._renderer.gammaOutput=e,this._needRecompile=!0,this.glRedraw())}get gammaOutput(){return this._renderer.gammaOutput}set gammaFactor(e){(e=null==e?2.2:e)!==this._renderer.gammaFactor&&(this._renderer.gammaFactor=e,this.glRedraw())}get gammaFactor(){return this._renderer.gammaFactor}get geometry(){return this.components["default.geometry"]||ze(Le)}get material(){return this.components["default.material"]||new jt(this,{id:"default.material",emissive:[.4,.4,.4],dontClear:!0})}get xrayMaterial(){return this.components["default.xrayMaterial"]||new ds(this,{id:"default.xrayMaterial",fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1,dontClear:!0})}get highlightMaterial(){return this.components["default.highlightMaterial"]||new ds(this,{id:"default.highlightMaterial",fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1,dontClear:!0})}get selectedMaterial(){return this.components["default.selectedMaterial"]||new ds(this,{id:"default.selectedMaterial",fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1,dontClear:!0})}get edgeMaterial(){return this.components["default.edgeMaterial"]||new fs(this,{id:"default.edgeMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1,dontClear:!0})}get pointsMaterial(){return this.components["default.pointsMaterial"]||new cA(this,{id:"default.pointsMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1,dontClear:!0})}get linesMaterial(){return this.components["default.linesMaterial"]||new uA(this,{id:"default.linesMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1,dontClear:!0})}get viewport(){return this._viewport}get camera(){return this._camera}get center(){if(this._aabbDirty||!this._center){const e=this.aabb;this._center||(this._center=R.vec3()),this._center[0]=(e[0]+e[3])/2,this._center[1]=(e[1]+e[4])/2,this._center[2]=(e[2]+e[5])/2}return this._center}get aabb(){if(this._aabbDirty){this._aabb||(this._aabb=R.AABB3());let e,t=R.MAX_DOUBLE,s=R.MAX_DOUBLE,i=R.MAX_DOUBLE,r=R.MIN_DOUBLE,n=R.MIN_DOUBLE,A=R.MIN_DOUBLE;const o=this._collidables;let a,l=!1;for(const c in o)if(o.hasOwnProperty(c)){if(a=o[c],!1===a.collidable)continue;e=a.aabb,e[0]<t&&(t=e[0]),e[1]<s&&(s=e[1]),e[2]<i&&(i=e[2]),e[3]>r&&(r=e[3]),e[4]>n&&(n=e[4]),e[5]>A&&(A=e[5]),l=!0}l||(t=-100,s=-100,i=-100,r=100,n=100,A=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=i,this._aabb[3]=r,this._aabb[4]=n,this._aabb[5]=A,this._aabbDirty=!1,this._center=null}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(!this.canvas)return this.error("Picking not allowed on a destroyed Scene"),null;if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=fA(this,s));const i=e.excludeEntities||e.exclude;return i&&(e.excludeEntityIds=fA(this,i)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=e.snapToEdge||e.snapToVertex?this._renderer.snapPick(e,t):this._renderer.pick(e,t))&&t.entity&&t.entity.fire&&t.entity.fire("picked",t),t}snapPick(e){return this.canvas?(void 0===this._warnSnapPickDeprecated&&(this._warnSnapPickDeprecated=!0,this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead")),e.canvasPos?this._renderer.snapPick(e):void this.error("Scene.snapPick() canvasPos parameter expected")):(this.error("Picking not allowed on a destroyed Scene"),null)}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t<s;t++)this.lights[e[t]].destroy()}clearSectionPlanes(){const e=Object.keys(this.sectionPlanes);for(let t=0,s=e.length;t<s;t++)this.sectionPlanes[e[t]].destroy()}clearBitmaps(){const e=Object.keys(this.bitmaps);for(let t=0,s=e.length;t<s;t++)this.bitmaps[e[t]].destroy()}clearLines(){const e=Object.keys(this.lineSets);for(let t=0,s=e.length;t<s;t++)this.lineSets[e[t]].destroy()}getAABB(e){if(void 0===e)return this.aabb;if(j.isString(e)){const t=this.objects[e];if(t&&t.aabb)return t.aabb;e=[e]}if(0===e.length)return this.aabb;let t,s=R.MAX_DOUBLE,i=R.MAX_DOUBLE,r=R.MAX_DOUBLE,n=R.MIN_DOUBLE,A=R.MIN_DOUBLE,o=R.MIN_DOUBLE;if(this.withObjects(e,(e=>{if(e.collidable){const a=e.aabb;a[0]<s&&(s=a[0]),a[1]<i&&(i=a[1]),a[2]<r&&(r=a[2]),a[3]>n&&(n=a[3]),a[4]>A&&(A=a[4]),a[5]>o&&(o=a[5]),t=!0}})),t){const e=R.AABB3();return e[0]=s,e[1]=i,e[2]=r,e[3]=n,e[4]=A,e[5]=o,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){j.isString(e)&&(e=[e]);let s=!1;for(let i=0,r=e.length;i<r;i++){const r=e[i];let n=this.objects[r];if(n)s=t(n)||s;else{const e=this.modelIds;for(let i=0,A=e.length;i<A;i++){const A=e[i],o=R.globalizeObjectId(A,r);n=this.objects[o],n&&(s=t(n)||s)}}}return s}tickify(e){const t=e.toString();if(t in this._tickifiedFunctions)return this._tickifiedFunctions[t].wrapperFunc;let s,i=0,r=0;const n=function(...e){s=e,r++},A=this.on("tick",(()=>{r>i&&(i=r,e(...s))}));return this._tickifiedFunctions[t]={tickSubId:A,wrapperFunc:n},n}destroy(){super.destroy(),this._removeWebglcontextlostListener();for(const e in this.components)this.components.hasOwnProperty(e)&&this.components[e].destroy();this._sectionCaps.destroy(),this.canvas.gl=null,this.components=null,this.models=null,this.objects=null,this.visibleObjects=null,this.xrayedObjects=null,this.highlightedObjects=null,this.selectedObjects=null,this.colorizedObjects=null,this.opacityObjects=null,this.sectionPlanes=null,this.lights=null,this.lightMaps=null,this.reflectionMaps=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this._sectionCaps=null,this.types=null,this.components=null,this.canvas=null,this._renderer=null,this.input=null,this._viewport=null,this._camera=null}}const mA=R.vec4(),_A=R.vec4(),bA=R.vec3(),yA=R.vec3(),BA=R.vec3(),wA=R.vec4(),vA=R.vec4(),CA=R.vec4();class MA{constructor(e){this._scene=e}dollyToCanvasPos(e,t,s){let i=!1;const r=this._scene.camera;if(e){const t=R.subVec3(e,r.eye,bA);i=R.lenVec3(t)<s}if("perspective"===r.projection){r.ortho.scale=r.ortho.scale-s;const i=this._unproject(t,wA),n=R.subVec3(i,r.eye,CA),A=R.mulVec3Scalar(R.normalizeVec3(n),-s,[]);if(r.eye=[r.eye[0]-A[0],r.eye[1]-A[1],r.eye[2]-A[2]],r.look=[r.look[0]-A[0],r.look[1]-A[1],r.look[2]-A[2]],e){const t=R.subVec3(e,r.eye,bA),s=R.lenVec3(t),i=R.mulVec3Scalar(R.normalizeVec3(R.subVec3(r.look,r.eye,yA)),s);r.look=[r.eye[0]+i[0],r.eye[1]+i[1],r.eye[2]+i[2]]}}else if("ortho"===r.projection){const e=this._unproject(t,wA);r.ortho.scale=r.ortho.scale-s,r.ortho._update();const i=this._unproject(t,vA),n=R.subVec3(i,e,CA),A=R.mulVec3Scalar(R.normalizeVec3(R.subVec3(r.look,r.eye,bA)),-s,yA),o=R.addVec3(n,A,BA);r.eye=[r.eye[0]-o[0],r.eye[1]-o[1],r.eye[2]-o[2]],r.look=[r.look[0]-o[0],r.look[1]-o[1],r.look[2]-o[2]]}return i}_unproject(e,t){const s=this._scene.camera,i=s.project.transposedMatrix,r=i.subarray(8,12),n=i.subarray(12),A=[0,0,-1,1],o=R.dotVec4(A,r)/R.dotVec4(A,n);return s.project.unproject(e,o,mA,_A,t),t}destroy(){}}const EA=R.vec3(),FA=R.vec3(),xA=R.vec3(),UA=R.vec4(),IA=R.vec4(),TA=R.vec4(),PA=Math.PI-.001;class SA{constructor(e,t){this._scene=e,this._configs=t,this._pivotWorldPos=R.vec3(),this._cameraOffset=R.vec3(),this._azimuth=0,this._polar=0,this._radius=0,this._pivotPosSet=!1,this._pivoting=!1,this._shown=!1,this._pivotSphereEnabled=!1,this._pivotSphere=null,this._pivotSphereSize=1,this._pivotSphereGeometry=null,this._pivotSphereMaterial=null,this._rtcCenter=R.vec3(),this._rtcPos=R.vec3(),this._pivotViewPos=R.vec4(),this._pivotProjPos=R.vec4(),this._pivotCanvasPos=R.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(()=>{this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=R.vec3();R.decomposeMat4(R.inverseMat4(this._scene.viewer.camera.viewMatrix,R.mat4()),t,R.vec4(),R.vec3());const s=R.distVec3(t,e);let i=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(i/=this._scene.camera.ortho.scale/2),dt(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Ge(this._scene,Je({radius:i})),this._pivotSphere=new Ot(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){R.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,R.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,i=s[2],r=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*i/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let n=t._lastBoundingClientRect;if(!n||t._canvasSizeChanged){const e=t.canvas;n=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(n.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(n.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(dt(this.getPivotPos(),this._rtcCenter,this._rtcPos),R.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new jt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){const e=this._scene.camera;let t=R.lookAtMat4v(e.eye,e.look,e.up);R.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=R.distVec3(e.eye,s),t=R.inverseMat4(t);const i=R.transformVec3(t,this._cameraOffset),r=R.vec3();if(R.subVec3(e.eye,s,r),R.addVec3(r,i),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=R.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=R.normalizeVec3(R.subVec3(e.look,e.eye,EA)),s=R.cross3Vec3(t,e.worldUp,FA);return R.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(R.distVec3(this._scene.center,t.eye)),i=t.project.transposedMatrix,r=i.subarray(8,12),n=i.subarray(12),A=[0,0,-1,1],o=R.dotVec4(A,r)/R.dotVec4(A,n),a=UA;t.project.unproject(e,o,IA,TA,a);const l=R.normalizeVec3(R.subVec3(a,t.eye,EA)),c=R.addVec3(t.eye,R.mulVec3Scalar(l,s,FA),xA);this.setPivotPos(c)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var i=-e;const r=-t;1===s.worldUp[2]&&(i=-i),this._azimuth+=.01*-i;const n=r<0,A=r>0,o=Math.abs(this._polar-.001)<.005,a=Math.abs(this._polar-PA)<.005;let l=this._polar+.01*r;l=o&&n?.001:a&&A?PA:R.clamp(l,.001,PA),this._polar=l;const c=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===s.worldUp[2]){const e=c[1];c[1]=c[2],c[2]=e}const h=R.lenVec3(R.subVec3(s.look,s.eye,R.vec3())),u=this.getPivotPos();R.addVec3(c,u);let d=R.lookAtMat4v(c,u,s.worldUp);d=R.inverseMat4(d);const p=R.transformVec3(d,this._cameraOffset);d[12]-=p[0],d[13]-=p[1],d[14]-=p[2];const f=[d[8],d[9],d[10]];s.eye=[d[12],d[13],d[14]],R.subVec3(s.eye,R.mulVec3Scalar(f,h),s.look),s.up=[d[4],d[5],d[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class DA{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=R.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new fn;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const kA=R.vec2(),QA=function(e,t,s){if(e){const i=t.getBoundingClientRect();s[0]=e.clientX-i.left,s[1]=e.clientY-i.top}else e=window.event,s[0]=e.x,s[1]=e.y;return s};class RA{constructor(e,t,s,i,r){this._scene=e;const n=t.pickController,A=t.cameraControl;let o,a,l,c=0,h=0,u=0,d=0,p=!1;const f=R.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function b(e=!0){c=i.pointerCanvasPos[0],h=i.pointerCanvasPos[1],u=i.pointerCanvasPos[0],d=i.pointerCanvasPos[1],e&&(n.pickCursorPos=i.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.picked&&n.pickedSurface&&n.pickResult&&n.pickResult.worldPos?(p=!0,f.set(n.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const i=t.keyCode;_[i]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const i=t.keyCode;_[i]=!1}),document.addEventListener("visibilitychange",this._onVisibilityChange=()=>{_.splice(0)}),window.addEventListener("blur",this._onBlur=()=>{_.splice(0)}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||s.planView?(o=!0,_[e.input.MOUSE_LEFT_BUTTON]=!0,b()):(o=!0,_[e.input.MOUSE_LEFT_BUTTON]=!0,b(!1));break;case 2:a=!0,_[e.input.MOUSE_MIDDLE_BUTTON]=!0,b();break;case 3:l=!0,_[e.input.MOUSE_RIGHT_BUTTON]=!0,s.panRightClick&&b()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(!o&&!a&&!l)return;const n=e.canvas.boundary,u=n[2],d=n[3],g=i.pointerCanvasPos[0],m=i.pointerCanvasPos[1],b=s.planView||A._isKeyDownForAction(A.MOUSE_PAN,_),y=A._isKeyDownForAction(A.MOUSE_ROTATE,_),B=document.pointerLockElement?t.movementX:g-c,w=document.pointerLockElement?t.movementY:m-h;if(b){const t=e.camera;if("perspective"===t.projection){const s=Math.abs(p?R.lenVec3(R.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*B*s/d,r.panDeltaY+=1.5*w*s/d}else r.panDeltaX+=.5*t.ortho.scale*(B/d),r.panDeltaY+=.5*t.ortho.scale*(w/d)}else y&&(s.planView||(s.firstPerson?(r.rotateDeltaY-=B/u*s.dragRotationRate/2,r.rotateDeltaX+=w/d*(s.dragRotationRate/4)):(r.rotateDeltaY-=B/u*(1.5*s.dragRotationRate),r.rotateDeltaX+=w/d*(1.5*s.dragRotationRate))));c=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&i.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:case 2:case 3:o=!1,a=!1,l=!1,_[e.input.MOUSE_LEFT_BUTTON]=!1,_[e.input.MOUSE_MIDDLE_BUTTON]=!1,_[e.input.MOUSE_RIGHT_BUTTON]=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){QA(e,m,kA);const s=kA[0],i=kA[1];Math.abs(s-u)<3&&Math.abs(i-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:kA,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const y=1/60;let B=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!(s.active&&s.pointerEnabled&&s.zoomOnMouseWheel&&A._isKeyDownForAction(A.MOUSE_DOLLY,_)))return;const t=performance.now()/1e3;var n=null!==B?t-B:0;B=t,n>.05&&(n=.05),n<y&&(n=y);const o=Math.max(-1,Math.min(1,40*-e.deltaY));if(0===o)return;const a=o/Math.abs(o);r.dollyDelta+=-a*n*s.mouseWheelDollyRate,g&&(0===i.pointerCanvasPos[0]&&0===i.pointerCanvasPos[1]&&QA(e,m,i.pointerCanvasPos),i.followPointerDirty=!0,g=!1)},{passive:!0})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler),document.removeEventListener("keyup",this._documentKeyUpHandler),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("blur",this._onBlur),e.removeEventListener("mousedown",this._mouseDownHandler),document.removeEventListener("mousemove",this._documentMouseMoveHandler),e.removeEventListener("mousemove",this._canvasMouseMoveHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("wheel",this._mouseWheelHandler)}}const OA=R.vec3(),VA=R.vec3(),LA=R.vec3(),HA=R.vec3(),NA=R.vec3(),GA={eye:R.vec3(),look:R.vec3(),up:R.vec3()};class jA{constructor(e,t,s,i){this._scene=e;const r=t.cameraControl,n=e.camera;this._onSceneKeyDown=e.input.on("keydown",(()=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(s.keyboardEnabledOnlyIfMouseover&&!i.mouseover)return;const A=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),o=r._isKeyDownForAction(r.AXIS_VIEW_BACK),a=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),l=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),c=r._isKeyDownForAction(r.AXIS_VIEW_TOP),h=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(A||o||a||l||c||h))return;const u=e.aabb,d=R.getAABB3Diag(u);R.getAABB3Center(u,OA);const p=Math.abs(d/Math.tan(t.cameraFlight.fitFOV*R.DEGTORAD)),f=1.1*d;GA.orthoScale=f,A?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldRight,p,VA),NA)),GA.look.set(OA),GA.up.set(n.worldUp)):o?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldForward,p,VA),NA)),GA.look.set(OA),GA.up.set(n.worldUp)):a?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldRight,-p,VA),NA)),GA.look.set(OA),GA.up.set(n.worldUp)):l?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldForward,-p,VA),NA)),GA.look.set(OA),GA.up.set(n.worldUp)):c?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldUp,p,VA),NA)),GA.look.set(OA),GA.up.set(R.normalizeVec3(R.mulVec3Scalar(n.worldForward,1,LA),HA))):h&&(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldUp,-p,VA),NA)),GA.look.set(OA),GA.up.set(R.normalizeVec3(R.mulVec3Scalar(n.worldForward,-1,LA)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(OA),t.cameraFlight.duration>0?t.cameraFlight.flyTo(GA,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(GA),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class zA{constructor(e,t,s,i,r){this._scene=e;const n=t.pickController,A=t.pivotController,o=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null,this._lastClickedWorldPos=null;let a=!1,l=!1;const c=this._scene.canvas.canvas,h=s=>{let i;s&&s.worldPos&&(i=s.worldPos);const r=s&&s.entity?s.entity.aabb:e.aabb;if(i){const s=e.camera;R.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},u=e.tickify(this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(a||l)return;if(o.hasSubs("rayMove")){const t=R.vec3(),s=R.vec3();R.canvasPosToWorldRay(e.canvas.canvas,e.camera.viewMatrix,e.camera.projMatrix,e.camera.projection,i.pointerCanvasPos,t,s),o.fire("rayMove",{canvasPos:i.pointerCanvasPos,ray:{origin:t,direction:s,canvasPos:i.pointerCanvasPos}},!0)}const r=o.hasSubs("hover"),A=o.hasSubs("hoverEnter"),c=o.hasSubs("hoverOut"),h=o.hasSubs("hoverOff"),u=o.hasSubs("hoverSurface"),d=o.hasSubs("hoverSnapOrSurface");if(r||A||c||h||u||d)if(n.pickCursorPos=i.pointerCanvasPos,n.schedulePickEntity=!0,n.schedulePickSurface=u,n.scheduleSnapOrPick=d,n.update(),n.pickResult){if(n.pickResult.entity){const t=n.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),o.fire("hoverEnter",n.pickResult,!0),this._lastPickedEntityId=t)}o.fire("hover",n.pickResult,!0),(n.pickResult.worldPos||n.pickResult.snappedWorldPos)&&o.fire("hoverSurface",n.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),o.fire("hoverOff",{canvasPos:n.pickCursorPos},!0)});c.addEventListener("mousemove",u),c.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(a=!0),3===t.which&&(l=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(i.mouseDownClientX=t.clientX,i.mouseDownClientY=t.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(n.pickCursorPos=i.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),1===t.which))){const t=n.pickResult;t&&t.worldPos?(A.setPivotPos(t.worldPos),A.startPivot(),this._lastClickedWorldPos=t.worldPos.slice()):(s.smartPivot?A.setCanvasPivotPos(i.pointerCanvasPos):this._lastClickedWorldPos?A.setPivotPos(this._lastClickedWorldPos):A.setPivotPos(e.camera.look),A.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(a=!1),3===e.which&&(l=!1),A.getPivoting()&&A.endPivot()}),c.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!s.active||!s.pointerEnabled)return;if(!(1===r.which))return;if(A.hidePivot(),Math.abs(r.clientX-i.mouseDownClientX)>3||Math.abs(r.clientY-i.mouseDownClientY)>3)return;const a=o.hasSubs("picked"),l=o.hasSubs("pickedNothing"),c=o.hasSubs("pickedSurface"),u=o.hasSubs("doublePicked"),d=o.hasSubs("doublePickedSurface"),p=o.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||u||d||p))return(a||l||c)&&(n.pickCursorPos=i.pointerCanvasPos,n.schedulePickEntity=!0,n.schedulePickSurface=c,n.update(),n.pickResult?(o.fire("picked",n.pickResult,!0),n.pickedSurface&&o.fire("pickedSurface",n.pickResult,!0)):o.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){n.pickCursorPos=i.pointerCanvasPos,n.schedulePickEntity=s.doublePickFlyTo,n.schedulePickSurface=c,n.update();const e=n.pickResult,r=n.pickedSurface;this._timeout=setTimeout((()=>{e?(o.fire("picked",e,!0),r&&(o.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):o.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),n.pickCursorPos=i.pointerCanvasPos,n.schedulePickEntity=s.doublePickFlyTo||u||d,n.schedulePickSurface=n.schedulePickEntity&&d,n.update(),n.pickResult){if(o.fire("doublePicked",n.pickResult,!0),n.pickedSurface&&o.fire("doublePickedSurface",n.pickResult,!0),s.doublePickFlyTo&&(h(n.pickResult),!s.firstPerson&&s.followPointer)){const e=n.pickResult.entity.aabb,s=R.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(o.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),s.doublePickFlyTo&&(h(),!s.firstPerson&&s.followPointer)){const s=e.aabb,i=R.getAABB3Center(s);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class WA{constructor(e,t,s,i,r){this._scene=e;const n=e.input,A=[];e.canvas.canvas;let o=!0;this._onSceneMouseMove=n.on("mousemove",(()=>{o=!0})),this._onSceneKeyDown=n.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(s.keyboardEnabledOnlyIfMouseover&&!i.mouseover||(A[t]=!0))})),this._onSceneKeyUp=n.on("keyup",(i=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(A[i]=!1,t.pivotController.getPivoting()&&t.pivotController.endPivot())})),document.addEventListener("visibilitychange",this._onVisibilityChange=()=>{A.splice(0)}),window.addEventListener("blur",this._onBlur=()=>{A.splice(0)}),this._onTick=e.on("tick",(a=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(s.keyboardEnabledOnlyIfMouseover&&!i.mouseover)return;const l=t.cameraControl,c=a.deltaTime/1e3;if(!s.planView){const e=l._isKeyDownForAction(l.ROTATE_Y_POS,A),i=l._isKeyDownForAction(l.ROTATE_Y_NEG,A),n=l._isKeyDownForAction(l.ROTATE_X_POS,A),o=l._isKeyDownForAction(l.ROTATE_X_NEG,A),a=c*s.keyboardRotationRate;(e||i||n||o)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=a:i&&(r.rotateDeltaY-=a),n?r.rotateDeltaX+=a:o&&(r.rotateDeltaX-=a),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!A[n.KEY_CTRL]&&!A[n.KEY_ALT]){const e=l._isKeyDownForAction(l.DOLLY_BACKWARDS,A),n=l._isKeyDownForAction(l.DOLLY_FORWARDS,A);if(e||n){const A=c*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),n?r.dollyDelta-=A:e&&(r.dollyDelta+=A),o&&(i.followPointerDirty=!0,o=!1)}}const h=l._isKeyDownForAction(l.PAN_FORWARDS,A),u=l._isKeyDownForAction(l.PAN_BACKWARDS,A),d=l._isKeyDownForAction(l.PAN_LEFT,A),p=l._isKeyDownForAction(l.PAN_RIGHT,A),f=l._isKeyDownForAction(l.PAN_UP,A),g=l._isKeyDownForAction(l.PAN_DOWN,A),m=(A[n.KEY_ALT]?.3:1)*c*s.keyboardPanRate;(h||u||d||p||f||g)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:h&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("blur",this._onBlur),this._scene.input.off(this._onSceneKeyUp)}}const XA=R.vec3();class KA{constructor(e,t,s,i,r){this._scene=e;const n=e.camera,A=t.pickController,o=t.pivotController,a=t.panController,l=t.cameraControl;let c=1,h=1,u=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),s.followPointer){if(--c<=0&&(c=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&s.followPointer&&i.followPointerDirty&&(A.pickCursorPos=i.pointerCanvasPos,A.schedulePickSurface=!0,A.update(),A.pickResult&&A.pickResult.worldPos?u=A.pickResult.worldPos:(h=1,u=null),i.followPointerDirty=!1),u){const t=Math.abs(R.lenVec3(R.subVec3(u,e.camera.eye,XA)));h=t/s.dollyProximityThreshold}h<s.dollyMinSpeed&&(h=s.dollyMinSpeed)}}else h=1,u=null;const d=r.dollyDelta*h;if(0===r.rotateDeltaY&&0===r.rotateDeltaX||(s.firstPerson?(0!==r.rotateDeltaX&&n.pitch(-r.rotateDeltaX),0!==r.rotateDeltaY&&n.yaw(r.rotateDeltaY)):s.followPointer&&o.getPivoting()&&(o.continuePivot(r.rotateDeltaY,r.rotateDeltaX),o.showPivot()),r.rotateDeltaX*=s.rotationInertia,r.rotateDeltaY*=s.rotationInertia,t=l._cursors.rotate),Math.abs(r.panDeltaX)<.001&&(r.panDeltaX=0),Math.abs(r.panDeltaY)<.001&&(r.panDeltaY=0),Math.abs(r.panDeltaZ)<.001&&(r.panDeltaZ=0),0!==r.panDeltaX||0!==r.panDeltaY||0!==r.panDeltaZ){const e=R.vec3();let i,A;if(e[0]=r.panDeltaX,e[1]=r.panDeltaY,e[2]=r.panDeltaZ,s.constrainVertical){n.xUp?(i=n.eye[0],A=n.look[0]):n.yUp?(i=n.eye[1],A=n.look[1]):n.zUp&&(i=n.eye[2],A=n.look[2]),n.pan(e);const t=n.eye,s=n.look;n.xUp?(t[0]=i,s[0]=A):n.yUp?(t[1]=i,s[1]=A):n.zUp&&(t[2]=i,s[2]=A),n.eye=t,n.look=s}else n.pan(e);t=l._cursors.pan}if(r.panDeltaX*=s.panInertia,r.panDeltaY*=s.panInertia,r.panDeltaZ*=s.panInertia,0!==d){if(t=d<0?l._cursors.dollyForward:l._cursors.dollyBackward,s.firstPerson){let e,t;if(s.constrainVertical&&(n.xUp?(e=n.eye[0],t=n.look[0]):n.yUp?(e=n.eye[1],t=n.look[1]):n.zUp&&(e=n.eye[2],t=n.look[2])),s.followPointer){a.dollyToCanvasPos(u,i.pointerCanvasPos,-d)&&(i.followPointerDirty=!0)}else n.pan([0,0,d]),n.ortho.scale=n.ortho.scale-d;if(s.constrainVertical){const s=n.eye,i=n.look;n.xUp?(s[0]=e,i[0]=t):n.yUp?(s[1]=e,i[1]=t):n.zUp&&(s[2]=e,i[2]=t),n.eye=s,n.look=i}}else if(s.planView)if(s.followPointer){a.dollyToCanvasPos(u,i.pointerCanvasPos,-d)&&(i.followPointerDirty=!0)}else n.ortho.scale=n.ortho.scale+d,n.zoom(d);else if(s.followPointer){a.dollyToCanvasPos(u,i.pointerCanvasPos,-d)&&(i.followPointerDirty=!0)}else n.ortho.scale=n.ortho.scale+d,n.zoom(d);r.dollyDelta*=s.dollyInertia}A.fireEvents(),document.body.style.cursor=t}))}destroy(){this._scene.off(this._onTick)}}class ZA{constructor(e,t,s,i,r){this._scene=e;const n=this._scene.canvas.canvas;n.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.mouseover=!0}),n.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{i.mouseover=!1,n.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{JA(e,n,i.pointerCanvasPos),i.mouseover=!0}),n.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(JA(e,n,i.pointerCanvasPos),i.mouseover=!0)}),n.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function JA(e,t,s){if(e){const{left:i,top:r}=t.getBoundingClientRect();s[0]=e.clientX-i,s[1]=e.clientY-r}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const YA=function(e,t,s){if(e){const i=t.getBoundingClientRect();s[0]=e.clientX-i.left,s[1]=e.clientY-i.top}else e=window.event,s[0]=e.x,s[1]=e.y;return s};class $A{constructor(e,t,s,i,r){this._scene=e;const n=t.pickController,A=t.pivotController,o=R.vec2(),a=R.vec2(),l=R.vec2(),c=R.vec2(),h=[],u=this._scene.canvas.canvas;let d=0,p=!1;this._onTick=e.on("tick",(()=>{p=!1})),u.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const r=t.touches,a=t.changedTouches;for(i.touchStartTime=Date.now(),1===r.length&&1===a.length&&(YA(r[0],u,o),s.followPointer&&(n.pickCursorPos=o,n.schedulePickSurface=!0,n.update(),s.planView||(n.picked&&n.pickedSurface&&n.pickResult&&n.pickResult.worldPos?(A.setPivotPos(n.pickResult.worldPos),!s.firstPerson&&A.startPivot()&&A.showPivot()):(s.smartPivot?A.setCanvasPivotPos(i.pointerCanvasPos):A.setPivotPos(e.camera.look),!s.firstPerson&&A.startPivot()&&A.showPivot()))));h.length<r.length;)h.push(R.vec2());for(let e=0,t=r.length;e<t;++e)YA(r[e],u,h[e]);d=r.length}),u.addEventListener("touchend",this._canvasTouchEndHandler=()=>{A.getPivoting()&&(A.endPivot(),A.hidePivot())}),u.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),p)return;p=!0;const A=e.canvas.boundary,o=A[2],f=A[3],g=t.touches;if(t.touches.length===d){if(1===d){YA(g[0],u,a),R.subVec2(a,h[0],c);const t=c[0],n=c[1];if(null!==i.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(n)>s.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),s.planView){const i=e.camera;if("perspective"===i.projection){const A=Math.abs(e.camera.eyeLookDist)*Math.tan(i.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*A/f*s.touchPanRate,r.panDeltaY+=n*A/f*s.touchPanRate}else r.panDeltaX+=.5*i.ortho.scale*(t/f)*s.touchPanRate,r.panDeltaY+=.5*i.ortho.scale*(n/f)*s.touchPanRate}else r.rotateDeltaY-=t/o*(1*s.dragRotationRate),r.rotateDeltaX+=n/f*(1.5*s.dragRotationRate)}else if(2===d){const t=g[0],A=g[1];YA(t,u,a),YA(A,u,l);const o=R.geometricMeanVec2(h[0],h[1]),c=R.geometricMeanVec2(a,l),d=R.vec2();R.subVec2(o,c,d);const p=d[0],m=d[1],_=e.camera,b=R.distVec2([t.pageX,t.pageY],[A.pageX,A.pageY]),y=(R.distVec2(h[0],h[1])-b)*s.touchDollyRate;if(r.dollyDelta=y,i.followPointerDirty=!0,Math.abs(y)<1)if("perspective"===_.projection){const t=n.pickResult?n.pickResult.worldPos:e.center,i=Math.abs(R.lenVec3(R.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=p*i/f*s.touchPanRate,r.panDeltaY-=m*i/f*s.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(p/f)*s.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/f)*s.touchPanRate;i.pointerCanvasPos=c}for(let e=0;e<d;++e)YA(g[e],u,h[e])}})}reset(){}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler),e.removeEventListener("touchmove",this._canvasTouchMoveHandler),this._scene.off(this._onTick)}}const qA=function(e,t){if(e){let s=e.target,i=0,r=0;for(;s.offsetParent;)i+=s.offsetLeft,r+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-i,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class eo{constructor(e,t,s,i,r){this._scene=e;const n=t.pickController,A=t.cameraControl;let o;const a=[],l=new Float32Array(2);let c=-1,h=-1;const u=this._scene.canvas.canvas,d=s=>{let i;s&&s.worldPos&&(i=s.worldPos);const r=s?s.entity.aabb:e.aabb;if(i){const s=e.camera;R.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};u.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null);const r=e.touches,n=e.changedTouches;if(o=Date.now(),1===r.length&&1===n.length){c=o,qA(r[0],l);const n=l[0],A=l[1],a=r[0].pageX,h=r[0].pageY;i.longTouchTimeout=setTimeout((()=>{s.active&&s.pointerEnabled&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(a),Math.round(h)],canvasPos:[Math.round(n),Math.round(A)],event:e},!0),i.longTouchTimeout=null}),s.longTapTimeout)}else c=-1;for(;a.length<r.length;)a.push(new Float32Array(2));for(let e=0,t=r.length;e<t;++e)qA(r[e],a[e]);a.length=r.length},{passive:!0}),u.addEventListener("touchend",this._canvasTouchEndHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),r=e.touches,o=e.changedTouches,u=A.hasSubs("pickedSurface");null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),0===r.length&&1===o.length&&c>-1&&t-c<150&&(h>-1&&c-h<325?(qA(o[0],n.pickCursorPos),n.schedulePickEntity=!0,n.schedulePickSurface=u,n.update(),n.pickResult?(n.pickResult.touchInput=!0,A.fire("doublePicked",n.pickResult),n.pickedSurface&&A.fire("doublePickedSurface",n.pickResult),s.doublePickFlyTo&&d(n.pickResult)):(A.fire("doublePickedNothing"),s.doublePickFlyTo&&d()),h=-1):R.distVec2(a[0],l)<4&&(qA(o[0],n.pickCursorPos),n.schedulePickEntity=!0,n.schedulePickSurface=u,n.update(),n.pickResult?(n.pickResult.touchInput=!0,A.fire("picked",n.pickResult),n.pickedSurface&&A.fire("pickedSurface",n.pickResult)):A.fire("pickedNothing"),h=t),c=-1),a.length=r.length;for(let e=0,t=r.length;e<t;++e)a[e][0]=r[e].pageX,a[e][1]=r[e].pageY},{passive:!0})}reset(){}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}class to extends ie{constructor(e,t={}){super(e,t),this.PAN_LEFT=0,this.PAN_RIGHT=1,this.PAN_UP=2,this.PAN_DOWN=3,this.PAN_FORWARDS=4,this.PAN_BACKWARDS=5,this.ROTATE_X_POS=6,this.ROTATE_X_NEG=7,this.ROTATE_Y_POS=8,this.ROTATE_Y_NEG=9,this.DOLLY_FORWARDS=10,this.DOLLY_BACKWARDS=11,this.AXIS_VIEW_RIGHT=12,this.AXIS_VIEW_BACK=13,this.AXIS_VIEW_LEFT=14,this.AXIS_VIEW_FRONT=15,this.AXIS_VIEW_TOP=16,this.AXIS_VIEW_BOTTOM=17,this.MOUSE_PAN=18,this.MOUSE_ROTATE=19,this.MOUSE_DOLLY=20,this._keyMap={},this.scene.canvas.canvas.oncontextmenu=e=>{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,zoomOnMouseWheel:!0,snapToVertex:true,snapToEdge:true,snapRadius:30,keyboardEnabledOnlyIfMouseover:!0,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:R.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:R.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new DA(this,this._configs),pivotController:new SA(s,this._configs),panController:new MA(s),cameraFlight:new Ce(this,{duration:.5})},this._handlers=[new ZA(this.scene,this._controllers,this._configs,this._states,this._updates),new $A(this.scene,this._controllers,this._configs,this._states,this._updates),new RA(this.scene,this._controllers,this._configs,this._states,this._updates),new jA(this.scene,this._controllers,this._configs,this._states,this._updates),new zA(this.scene,this._controllers,this._configs,this._states,this._updates),new eo(this.scene,this._controllers,this._configs,this._states,this._updates),new WA(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cursors={dollyForward:"zoom-in",dollyBackward:"zoom-out",rotate:"grabbing",pan:"move"},this._cameraUpdater=new KA(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",j.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6],s[this.MOUSE_PAN]=[[t.MOUSE_LEFT_BUTTON,t.KEY_SHIFT],this._configs.panRightClick?t.MOUSE_RIGHT_BUTTON:t.MOUSE_MIDDLE_BUTTON],s[this.MOUSE_ROTATE]=[t.MOUSE_LEFT_BUTTON],s[this.MOUSE_DOLLY]=[];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6],s[this.MOUSE_PAN]=[[t.MOUSE_LEFT_BUTTON,t.KEY_SHIFT],this._configs.panRightClick?t.MOUSE_RIGHT_BUTTON:t.MOUSE_MIDDLE_BUTTON],s[this.MOUSE_ROTATE]=[t.MOUSE_LEFT_BUTTON],s[this.MOUSE_DOLLY]=[]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_areAllKeysDown(e,t){if(!t||t.length<=0)return!0;if(!e)return!1;for(let s=0,i=t.length;s<i;s++){if(!e[t[s]])return!1}return!0}_isAnyOtherKeyDown(e,t){for(let s=0,i=e.length;s<i;s++)if(e[s])if(Array.isArray(t)){if(t.indexOf(s)<0)return!0}else if(s!==t)return!0;return!1}_isMouseAction(e){switch(e){case this.MOUSE_ROTATE:case this.MOUSE_DOLLY:case this.MOUSE_PAN:return!0;default:return!1}}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;if(0===s.length&&this._isMouseAction(e))return!0;t||(t=this.scene.input.keyDown);for(let e=0,i=s.length;e<i;e++){const i=s[e];if(Array.isArray(i)){if(this._areAllKeysDown(t,i)&&!this._isAnyOtherKeyDown(t,i))return!0}else if(t[i]&&!this._isAnyOtherKeyDown(t,i))return!0}return!1}set pivotElement(e){this._controllers.pivotController.setPivotElement(e)}set active(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}get active(){return this._configs.active}set snapToVertex(e){this._configs.snapToVertex=!!e}get snapToVertex(){return this._configs.snapToVertex}set snapToEdge(e){this._configs.snapToEdge=!!e}get snapToEdge(){return this._configs.snapToEdge}set snapRadius(e){e=e||30,this._configs.snapRadius=e}get snapRadius(){return this._configs.snapRadius}set keyboardEnabledOnlyIfMouseover(e){this._configs.keyboardEnabledOnlyIfMouseover=!!e}get keyboardEnabledOnlyIfMouseover(){return this._configs.keyboardEnabledOnlyIfMouseover}set navMode(e){"firstPerson"!==(e=e||"orbit")&&"orbit"!==e&&"planView"!==e&&(this.error("Unsupported value for navMode: "+e+" - supported values are 'orbit', 'firstPerson' and 'planView' - defaulting to 'orbit'"),e="orbit"),this._configs.firstPerson="firstPerson"===e,this._configs.planView="planView"===e,(this._configs.firstPerson||this._configs.planView)&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this._configs.navMode=e}get navMode(){return this._configs.navMode}set pointerEnabled(e){this._reset(),this._configs.pointerEnabled=!!e}setCursorStyle(e,t){Object.prototype.hasOwnProperty.call(this._cursors,e)?this._cursors={...this._cursors,[e]:t}:console.warn(`Action '${e}' is not valid for cursor styles.`)}getCursorStyle(e){return this._cursors[e]||null}_reset(){for(let e=0,t=this._handlers.length;e<t;e++){const t=this._handlers[e];t.reset&&t.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}get pointerEnabled(){return this._configs.pointerEnabled}set followPointer(e){this._configs.followPointer=!1!==e}get followPointer(){return this._configs.followPointer}set pivotPos(e){this._controllers.pivotController.setPivotPos(e)}get pivotPos(){return this._controllers.pivotController.getPivotPos()}set dollyToPointer(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}get dollyToPointer(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer}set panToPointer(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}get panToPointer(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1}set planView(e){this._configs.planView=!!e,this._configs.firstPerson=!1,this._configs.planView&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this.warn("planView property is deprecated - replaced with navMode")}get planView(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView}set firstPerson(e){this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson=!!e,this._configs.planView=!1,this._configs.firstPerson&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot())}get firstPerson(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson}set constrainVertical(e){this._configs.constrainVertical=!!e}get constrainVertical(){return this._configs.constrainVertical}set doublePickFlyTo(e){this._configs.doublePickFlyTo=!1!==e}get doublePickFlyTo(){return this._configs.doublePickFlyTo}set panRightClick(e){this._configs.panRightClick=!1!==e;const t=this._keyMap[this.MOUSE_PAN];if(t&&t.length>0){const e=this.scene.input;for(let s=0,i=t.length;s<i;s++)this._configs.panRightClick&&t[s]===e.MOUSE_MIDDLE_BUTTON?this._keyMap[this.MOUSE_PAN][s]=e.MOUSE_RIGHT_BUTTON:this._configs.panRightClick||t[s]!==e.MOUSE_RIGHT_BUTTON||(this._keyMap[this.MOUSE_PAN][s]=e.MOUSE_MIDDLE_BUTTON)}}get panRightClick(){return this._configs.panRightClick}set rotationInertia(e){this._configs.rotationInertia=null!=e?e:0}get rotationInertia(){return this._configs.rotationInertia}set keyboardPanRate(e){this._configs.keyboardPanRate=null!=e?e:5}set touchPanRate(e){this._configs.touchPanRate=null!=e?e:1}get touchPanRate(){return this._configs.touchPanRate}get keyboardPanRate(){return this._configs.keyboardPanRate}set keyboardRotationRate(e){this._configs.keyboardRotationRate=null!=e?e:90}get keyboardRotationRate(){return this._configs.keyboardRotationRate}set dragRotationRate(e){this._configs.dragRotationRate=null!=e?e:360}get dragRotationRate(){return this._configs.dragRotationRate}set keyboardDollyRate(e){this._configs.keyboardDollyRate=null!=e?e:15}get keyboardDollyRate(){return this._configs.keyboardDollyRate}set touchDollyRate(e){this._configs.touchDollyRate=null!=e?e:.2}get touchDollyRate(){return this._configs.touchDollyRate}set mouseWheelDollyRate(e){this._configs.mouseWheelDollyRate=null!=e?e:100}get mouseWheelDollyRate(){return this._configs.mouseWheelDollyRate}set dollyInertia(e){this._configs.dollyInertia=null!=e?e:0}get dollyInertia(){return this._configs.dollyInertia}set dollyProximityThreshold(e){this._configs.dollyProximityThreshold=null!=e?e:35}get dollyProximityThreshold(){return this._configs.dollyProximityThreshold}set dollyMinSpeed(e){this._configs.dollyMinSpeed=null!=e?e:.04}get dollyMinSpeed(){return this._configs.dollyMinSpeed}set panInertia(e){this._configs.panInertia=null!=e?e:.5}get panInertia(){return this._configs.panInertia}set keyboardLayout(e){"qwerty"!==(e=e||"qwerty")&&"azerty"!==e&&(this.error("Unsupported value for keyboardLayout - defaulting to 'qwerty'"),e="qwerty"),this._configs.keyboardLayout=e,this.keyMap=this._configs.keyboardLayout}get keyboardLayout(){return this._configs.keyboardLayout}enablePivotSphere(e={}){this._controllers.pivotController.enablePivotSphere(e)}disablePivotSphere(){this._controllers.pivotController.disablePivotSphere()}set smartPivot(e){this._configs.smartPivot=!1!==e}get smartPivot(){return this._configs.smartPivot}set doubleClickTimeFrame(e){this._configs.doubleClickTimeFrame=null!=e?e:250}get doubleClickTimeFrame(){return this._configs.doubleClickTimeFrame}set zoomOnMouseWheel(e){this._configs.zoomOnMouseWheel=!!e}get zoomOnMouseWheel(){return this._configs.zoomOnMouseWheel}destroy(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),super.destroy()}_destroyHandlers(){for(let e=0,t=this._handlers.length;e<t;e++){const t=this._handlers[e];t.destroy&&t.destroy()}}_destroyControllers(){for(let e=0,t=this._controllers.length;e<t;e++){const t=this._controllers[e];t.destroy&&t.destroy()}}}class so{constructor(e,t,s,i,r){this.name=e,this.type=s,this.value=t,this.valueType=i,this.description=r}}class io{constructor(e){if(this.id=e.id,this.originalSystemId=e.originalSystemId,this.metaModels=[],this.name=e.name,this.type=e.type,this.properties=[],e.properties){const t=e.properties;for(let e=0,s=t.length;e<s;e++){const s=t[e];Number.isInteger(s)?this.properties.push(s):this.properties.push(new so(s.name,s.value,s.type,s.valueType,s.description))}}}}class ro{constructor(e){this.metaModels=[],this.id=e.id,this.parentId=e.parentId,this.parent=null,this.originalSystemId=e.originalSystemId,this.name=e.name,this.type=e.type,this.propertySetIds=e.propertySetIds,this.propertySets=[],this.attributes=e.attributes||{},void 0!==e.external&&null!==e.external&&(this.external=e.external)}get metaModel(){return 1==this.metaModels.length?this.metaModels[0]:null}getObjectIDsInSubtree(){const e=[];return function t(s){if(!s)return;e.push(s.id);const i=s.children;if(i)for(var r=0,n=i.length;r<n;r++)t(i[r])}(this),e}withMetaObjectsInSubtree(e){!function t(s){if(!s)return;e(s);const i=s.children;if(i)for(var r=0,n=i.length;r<n;r++)t(i[r])}(this)}getObjectIDsInSubtreeByType(e){const t={};for(var s=0,i=e.length;s<i;s++)t[e[s]]=e[s];const r=[];return function e(s){if(!s)return;t[s.type]&&r.push(s.id);const i=s.children;if(i)for(var n=0,A=i.length;n<A;n++)e(i[n])}(this),r}getJSON(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}class no{constructor(e){this.id=e.id,this.projectId=e.projectId,this.revisionId=e.revisionId,this.author=e.author,this.createdAt=e.createdAt,this.creatingApplication=e.creatingApplication,this.schema=e.schema,this.metaScene=e.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects={},this.graph=e.graph||{},this.metaScene.metaModels[this.id]=this,this._propertyLookup=[],this.finalized=!1}get rootMetaObject(){return 1===this.rootMetaObjects.length?this.rootMetaObjects[0]:null}loadData(e,t={}){if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);const s=this.metaScene,i=e.properties;if(i)for(let e=0,t=i.length;e<t;e++)this._propertyLookup.push(i[e]);if(e.propertySets)for(let t=0,i=e.propertySets.length;t<i;t++){const i=e.propertySets[t];i.properties||(i.properties=[]);let r=s.propertySets[i.id];r||(r=new io({id:i.id,originalSystemId:i.originalSystemId||i.id,type:i.type,name:i.name,properties:i.properties}),s.propertySets[r.id]=r),r.metaModels.push(this),this.propertySets.push(r)}if(e.metaObjects)for(let t=0,i=e.metaObjects.length;t<i;t++){const i=e.metaObjects[t],r=i.id;let n=s.metaObjects[r];if(!n){const e=i.type,t=i.originalSystemId,s=i.propertySets||i.propertySetIds;n=new ro({id:r,originalSystemId:t,parentId:i.parent,type:e,name:i.name,attributes:i.attributes,propertySetIds:s,external:i.external}),this.metaScene.metaObjects[r]=n,n.metaModels=[]}this.metaObjects[r]=n,i.parent||(this.rootMetaObjects.push(n),s.rootMetaObjects[r]=n),n.metaModels.push(this)}}_decompressProperties(e,t){const s=[];for(let i=0,r=t.length;i<r;i++){const r=t[i];if(Number.isInteger(r)){const n=e[r];n?t[i]=n:s.push(r)}}s.length>0&&console.error(`[MetaModel._decompressProperties] Properties not found: ${s}`)}finalize(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";const e=this.metaScene;for(let t in e.metaObjects){const s=e.metaObjects[t];if(s.children&&(s.children=[]),s.propertySets&&(s.propertySets=[]),s.propertySetIds)for(let t=0,i=s.propertySetIds.length;t<i;t++){const i=s.propertySetIds[t],r=e.propertySets[i];s.propertySets.push(r)}}for(let t in e.metaObjects){const s=e.metaObjects[t];if(s.parentId){const t=e.metaObjects[s.parentId];t&&(s.parent=t,(t.children||(t.children=[])).push(s))}}for(let t in e.metaObjects){e.metaObjects[t].metaModels=[]}for(let t in e.metaModels){const s=e.metaModels[t];for(let e in s.metaObjects){s.metaObjects[e].metaModels.push(s)}}e.metaObjectsByType={};for(let t in e.metaObjects){const s=e.metaObjects[t],i=s.type;(e.metaObjectsByType[i]||(e.metaObjectsByType[i]={}))[t]=s}if(this.propertySets)for(let e=0,t=this.propertySets.length;e<t;e++){const t=this.propertySets[e];this._decompressProperties(this._propertyLookup,t.properties)}this._propertyLookup=[],this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}getJSON(){const e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]},t=Object.values(this.metaObjects);for(let s=0,i=t.length;s<i;s++){const i=t[s],r={id:i.id,originalSystemId:i.originalSystemId,extId:i.extId,type:i.type,name:i.name};i.parent&&(r.parent=i.parent.id),i.attributes&&(r.attributes=i.attributes),i.propertySetIds&&(r.propertySetIds=i.propertySetIds),e.metaObjects.push(r)}for(let t=0,s=this.propertySets.length;t<s;t++){const s=this.propertySets[t],i={id:s.id,originalSystemId:s.originalSystemId,extId:s.extId,type:s.type,name:s.name,propertyies:[]};for(let e=0,t=s.properties.length;e<t;e++){const t=s.properties[e],r={id:t.id,description:t.description,type:t.type,name:t.name,value:t.value,valueType:t.valueType};i.properties.push(r)}e.propertySets.push(i)}return e}_globalizeIDs(e,t){const s=!!t.globalizeObjectIds;if(e.metaObjects)for(let t=0,i=e.metaObjects.length;t<i;t++){const i=e.metaObjects[t];if(i.originalSystemId=i.id,i.parent&&(i.originalParentSystemId=i.parent),s&&(i.id=R.globalizeObjectId(this.id,i.id),i.parent&&(i.parent=R.globalizeObjectId(this.id,i.parent))),s){const e=i.propertySetIds;if(e){const t=[];for(let s=0,i=e.length;s<i;s++)t.push(R.globalizeObjectId(this.id,e[s]));i.propertySetIds=t,i.originalSystemPropertySetIds=e}}else i.originalSystemPropertySetIds=i.propertySetIds}if(e.propertySets)for(let t=0,i=e.propertySets.length;t<i;t++){const i=e.propertySets[t];i.originalSystemId=i.id,s&&(i.id=R.globalizeObjectId(this.id,i.id))}}}class Ao{constructor(e,t){this.viewer=e,this.scene=t,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,i=s.length;e<i;e++)s[e](t)}off(e){}createMetaModel(e,t,s={}){const i=new no({metaScene:this,id:e,projectId:t.projectId||"none",revisionId:t.revisionId||"none",author:t.author||"none",createdAt:t.createdAt||"none",creatingApplication:t.creatingApplication||"none",schema:t.schema||"none",propertySets:[]});return i.loadData(t),i.finalize(),i}_destroy(){this.viewer=null,this.scene=null,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}destroyMetaModel(e){const t=this.metaModels[e];if(t){if(t.propertySets)for(let s=0,i=t.propertySets.length;s<i;s++){const i=t.propertySets[s];if(1===i.metaModels.length&&i.metaModels[0].id===e)delete this.propertySets[i.id];else{const t=[];for(let s=0,r=i.metaModels.length;s<r;s++)i.metaModels[s].id!==e&&t.push(i.metaModels[s]);i.metaModels=t}}if(t.metaObjects)for(let s in t.metaObjects){const i=t.metaObjects[s];1===i.metaModels.length&&i.metaModels[0].id===e?(delete this.metaObjects[s],i.parent||delete this.rootMetaObjects[s]):i.metaModels=i.metaModels.filter((t=>t.id!==e))}for(let e in this.metaObjects){const t=this.metaObjects[e];if(t.children&&(t.children=[]),t.propertySets&&(t.propertySets=[]),t.propertySetIds)for(let e=0,s=t.propertySetIds.length;e<s;e++){const s=t.propertySetIds[e],i=this.propertySets[s];t.propertySets.push(i)}}this.metaObjectsByType={};for(let e in this.metaObjects){const t=this.metaObjects[e],s=t.type;t.children&&(t.children=null),(this.metaObjectsByType[s]||(this.metaObjectsByType[s]={}))[e]=t}for(let e in this.metaObjects){const t=this.metaObjects[e];if(t.parentId){const e=this.metaObjects[t.parentId];e&&(t.parent=e,(e.children||(e.children=[])).push(t))}}delete this.metaModels[e];for(let e in this.metaObjects){this.metaObjects[e].metaModels=[]}for(let e in this.metaModels){const t=this.metaModels[e];for(let e in t.metaObjects){t.metaObjects[e].metaModels.push(t)}}this.fire("metaModelDestroyed",e)}}getObjectIDsByType(e){const t=this.metaObjectsByType[e];return t?Object.keys(t):[]}getObjectIDsInSubtree(e,t,s){const i=[],r=this.metaObjects[e],n=t&&t.length>0?oo(t):null,A=s&&s.length>0?oo(s):null,o=e=>{if(!e)return;var t=!0;(A&&A[e.type]||n&&!n[e.type])&&(t=!1),t&&i.push(e.id);const s=e.children;if(s)for(var r=0,a=s.length;r<a;r++)o(s[r])};return o(r),i}withMetaObjectsInSubtree(e,t){const s=this.metaObjects[e];s&&s.withMetaObjectsInSubtree(t)}}function oo(e){const t={};for(var s=0,i=e.length;s<i;s++)t[e[s]]=!0;return t}async function ao(e,t,s,i){return i._parse(e,t,s,i)}function lo(e,t){if(!e)throw new Error(t||"loader assertion failed.")}const co=Boolean("object"!=typeof process||"[object process]"!==String(process)||process.browser),ho="undefined"!=typeof process&&process.version&&/v([0-9]*)/.exec(process.version);ho&&parseFloat(ho[1]);const uo=globalThis,po=globalThis.process||{};function fo(){return!("object"==typeof process&&"[object process]"===String(process)&&!process?.browser)||function(e){if("undefined"!=typeof window&&"renderer"===window.process?.type)return!0;if("undefined"!=typeof process&&Boolean(process.versions?.electron))return!0;const t="undefined"!=typeof navigator&&navigator.userAgent,s=e||t;return Boolean(s&&s.indexOf("Electron")>=0)}()}class go{constructor(e,t,s="sessionStorage"){this.storage=function(e){try{const t=window[e],s="__storage_test__";return t.setItem(s,s),t.removeItem(s),t}catch(e){return null}}(s),this.id=e,this.config=t,this._loadConfiguration()}getConfiguration(){return this.config}setConfiguration(e){if(Object.assign(this.config,e),this.storage){const e=JSON.stringify(this.config);this.storage.setItem(this.id,e)}}_loadConfiguration(){let e={};if(this.storage){const t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}}var mo;!function(e){e[e.BLACK=30]="BLACK",e[e.RED=31]="RED",e[e.GREEN=32]="GREEN",e[e.YELLOW=33]="YELLOW",e[e.BLUE=34]="BLUE",e[e.MAGENTA=35]="MAGENTA",e[e.CYAN=36]="CYAN",e[e.WHITE=37]="WHITE",e[e.BRIGHT_BLACK=90]="BRIGHT_BLACK",e[e.BRIGHT_RED=91]="BRIGHT_RED",e[e.BRIGHT_GREEN=92]="BRIGHT_GREEN",e[e.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",e[e.BRIGHT_BLUE=94]="BRIGHT_BLUE",e[e.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",e[e.BRIGHT_CYAN=96]="BRIGHT_CYAN",e[e.BRIGHT_WHITE=97]="BRIGHT_WHITE"}(mo||(mo={}));function _o(e){return"string"!=typeof e?e:(e=e.toUpperCase(),mo[e]||mo.WHITE)}function bo(e,t){if(!e)throw new Error(t||"Assertion failed")}function yo(){let e;if(fo()&&uo.performance)e=uo?.performance?.now?.();else if("hrtime"in po){const t=po?.hrtime?.();e=1e3*t[0]+t[1]/1e6}else e=Date.now();return e}const Bo={debug:fo()&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},wo={enabled:!0,level:0};function vo(){}const Co={},Mo={once:!0};class Eo{constructor({id:e}={id:""}){this.VERSION="4.1.0",this._startTs=yo(),this._deltaTs=yo(),this.userData={},this.LOG_THROTTLE_TIMEOUT=0,this.id=e,this.userData={},this._storage=new go(`__probe-${this.id}__`,wo),this.timeStamp(`${this.id} started`),function(e,t=["constructor"]){const s=Object.getPrototypeOf(e),i=Object.getOwnPropertyNames(s),r=e;for(const s of i){const i=r[s];"function"==typeof i&&(t.find((e=>s===e))||(r[s]=i.bind(e)))}}(this),Object.seal(this)}set level(e){this.setLevel(e)}get level(){return this.getLevel()}isEnabled(){return this._storage.config.enabled}getLevel(){return this._storage.config.level}getTotal(){return Number((yo()-this._startTs).toPrecision(10))}getDelta(){return Number((yo()-this._deltaTs).toPrecision(10))}set priority(e){this.level=e}get priority(){return this.level}getPriority(){return this.level}enable(e=!0){return this._storage.setConfiguration({enabled:e}),this}setLevel(e){return this._storage.setConfiguration({level:e}),this}get(e){return this._storage.config[e]}set(e,t){this._storage.setConfiguration({[e]:t})}settings(){console.table?console.table(this._storage.config):console.log(this._storage.config)}assert(e,t){if(!e)throw new Error(t||"Assertion failed")}warn(e){return this._getLogFunction(0,e,Bo.warn,arguments,Mo)}error(e){return this._getLogFunction(0,e,Bo.error,arguments)}deprecated(e,t){return this.warn(`\`${e}\` is deprecated and will be removed in a later version. Use \`${t}\` instead`)}removed(e,t){return this.error(`\`${e}\` has been removed. Use \`${t}\` instead`)}probe(e,t){return this._getLogFunction(e,t,Bo.log,arguments,{time:!0,once:!0})}log(e,t){return this._getLogFunction(e,t,Bo.debug,arguments)}info(e,t){return this._getLogFunction(e,t,console.info,arguments)}once(e,t){return this._getLogFunction(e,t,Bo.debug||Bo.info,arguments,Mo)}table(e,t,s){return t?this._getLogFunction(e,t,console.table||vo,s&&[s],{tag:Uo(t)}):vo}time(e,t){return this._getLogFunction(e,t,console.time?console.time:console.info)}timeEnd(e,t){return this._getLogFunction(e,t,console.timeEnd?console.timeEnd:console.info)}timeStamp(e,t){return this._getLogFunction(e,t,console.timeStamp||vo)}group(e,t,s={collapsed:!1}){const i=xo({logLevel:e,message:t,opts:s}),{collapsed:r}=s;return i.method=(r?console.groupCollapsed:console.group)||console.info,this._getLogFunction(i)}groupCollapsed(e,t,s={}){return this.group(e,t,Object.assign({},s,{collapsed:!0}))}groupEnd(e){return this._getLogFunction(e,"",console.groupEnd||vo)}withGroup(e,t,s){this.group(e,t)();try{s()}finally{this.groupEnd(e)()}}trace(){console.trace&&console.trace()}_shouldLog(e){return this.isEnabled()&&this.getLevel()>=Fo(e)}_getLogFunction(e,t,s,i,r){if(this._shouldLog(e)){r=xo({logLevel:e,message:t,args:i,opts:r}),bo(s=s||r.method),r.total=this.getTotal(),r.delta=this.getDelta(),this._deltaTs=yo();const n=r.tag||r.message;if(r.once&&n){if(Co[n])return vo;Co[n]=yo()}return t=function(e,t,s){if("string"==typeof t){const i=s.time?function(e,t=8){const s=Math.max(t-e.length,0);return`${" ".repeat(s)}${e}`}(function(e){let t;return t=e<10?`${e.toFixed(2)}ms`:e<100?`${e.toFixed(1)}ms`:e<1e3?`${e.toFixed(0)}ms`:`${(e/1e3).toFixed(2)}s`,t}(s.total)):"";t=s.time?`${e}: ${i} ${t}`:`${e}: ${t}`,t=function(e,t,s){fo||"string"!=typeof e||(t&&(e=`[${_o(t)}m${e}`),s&&(e=`[${_o(s)+10}m${e}`));return e}(t,s.color,s.background)}return t}(this.id,r.message,r),s.bind(console,t,...r.args)}return vo}}function Fo(e){if(!e)return 0;let t;switch(typeof e){case"number":t=e;break;case"object":t=e.logLevel||e.priority||0;break;default:return 0}return bo(Number.isFinite(t)&&t>=0),t}function xo(e){const{logLevel:t,message:s}=e;e.logLevel=Fo(t);const i=e.args?Array.from(e.args):[];for(;i.length&&i.shift()!==s;);switch(typeof t){case"string":case"function":void 0!==s&&i.unshift(s),e.message=t;break;case"object":Object.assign(e,t)}"function"==typeof e.message&&(e.message=e.message());const r=typeof e.message;return bo("string"===r||"object"===r),Object.assign(e,{args:i},e.opts)}function Uo(e){for(const t in e)for(const s in e[t])return s||"untitled";return"empty"}Eo.VERSION="4.1.0";const Io="4.3.3"[0]>="0"&&"4.3.3"[0]<="9"?"v4.3.3":"";const To=function(){const e=new Eo({id:"loaders.gl"});return globalThis.loaders=globalThis.loaders||{},globalThis.loaders.log=e,globalThis.loaders.version=Io,globalThis.probe=globalThis.probe||{},globalThis.probe.loaders=e,e}();function Po(e,t){return So(e||{},t)}function So(e,t,s=0){if(s>3)return t;const i={...e};for(const[e,r]of Object.entries(t))r&&"object"==typeof r&&!Array.isArray(r)?i[e]=So(i[e]||{},t[e],s+1):i[e]=t[e];return i}const Do=(globalThis._loadersgl_?.version||(globalThis._loadersgl_=globalThis._loadersgl_||{},globalThis._loadersgl_.version="4.3.3"),globalThis._loadersgl_.version);function ko(e,t){if(!e)throw new Error(t||"loaders.gl assertion failed.")}const Qo="object"!=typeof process||"[object process]"!==String(process)||process.browser,Ro="function"==typeof importScripts,Oo="undefined"!=typeof window&&void 0!==window.orientation,Vo="undefined"!=typeof process&&process.version&&/v([0-9]*)/.exec(process.version);Vo&&parseFloat(Vo[1]);class Lo{name;workerThread;isRunning=!0;result;_resolve=()=>{};_reject=()=>{};constructor(e,t){this.name=e,this.workerThread=t,this.result=new Promise(((e,t)=>{this._resolve=e,this._reject=t}))}postMessage(e,t){this.workerThread.postMessage({source:"loaders.gl",type:e,payload:t})}done(e){ko(this.isRunning),this.isRunning=!1,this._resolve(e)}error(e){ko(this.isRunning),this.isRunning=!1,this._reject(e)}}class Ho{terminate(){}}const No=new Map;function Go(e){ko(e.source&&!e.url||!e.source&&e.url);let t=No.get(e.source||e.url);return t||(e.url&&(t=function(e){if(!e.startsWith("http"))return e;return jo((t=e,`try {\n importScripts('${t}');\n} catch (error) {\n console.error(error);\n throw error;\n}`));var t}(e.url),No.set(e.url,t)),e.source&&(t=jo(e.source),No.set(e.source,t))),ko(t),t}function jo(e){const t=new Blob([e],{type:"application/javascript"});return URL.createObjectURL(t)}function zo(e,t=!0,s){const i=s||new Set;if(e){if(Wo(e))i.add(e);else if(Wo(e.buffer))i.add(e.buffer);else if(ArrayBuffer.isView(e));else if(t&&"object"==typeof e)for(const s in e)zo(e[s],t,i)}else;return void 0===s?Array.from(i):[]}function Wo(e){return!!e&&(e instanceof ArrayBuffer||("undefined"!=typeof MessagePort&&e instanceof MessagePort||("undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)))}const Xo=()=>{};class Ko{name;source;url;terminated=!1;worker;onMessage;onError;_loadableURL="";static isSupported(){return"undefined"!=typeof Worker&&Qo||void 0!==Ho&&!Qo}constructor(e){const{name:t,source:s,url:i}=e;ko(s||i),this.name=t,this.source=s,this.url=i,this.onMessage=Xo,this.onError=e=>console.log(e),this.worker=Qo?this._createBrowserWorker():this._createNodeWorker()}destroy(){this.onMessage=Xo,this.onError=Xo,this.worker.terminate(),this.terminated=!0}get isRunning(){return Boolean(this.onMessage)}postMessage(e,t){t=t||zo(e),this.worker.postMessage(e,t)}_getErrorFromErrorEvent(e){let t="Failed to load ";return t+=`worker ${this.name} from ${this.url}. `,e.message&&(t+=`${e.message} in `),e.lineno&&(t+=`:${e.lineno}:${e.colno}`),new Error(t)}_createBrowserWorker(){this._loadableURL=Go({source:this.source,url:this.url});const e=new Worker(this._loadableURL,{name:this.name});return e.onmessage=e=>{e.data?this.onMessage(e.data):this.onError(new Error("No data received"))},e.onerror=e=>{this.onError(this._getErrorFromErrorEvent(e)),this.terminated=!0},e.onmessageerror=e=>console.error(e),e}_createNodeWorker(){let e;if(this.url){const t=this.url.includes(":/")||this.url.startsWith("/")?this.url:`./${this.url}`;e=new Ho(t,{eval:!1})}else{if(!this.source)throw new Error("no worker");e=new Ho(this.source,{eval:!0})}return e.on("message",(e=>{this.onMessage(e)})),e.on("error",(e=>{this.onError(e)})),e.on("exit",(e=>{})),e}}class Zo{name="unnamed";source;url;maxConcurrency=1;maxMobileConcurrency=1;onDebug=()=>{};reuseWorkers=!0;props={};jobQueue=[];idleQueue=[];count=0;isDestroyed=!1;static isSupported(){return Ko.isSupported()}constructor(e){this.source=e.source,this.url=e.url,this.setProps(e)}destroy(){this.idleQueue.forEach((e=>e.destroy())),this.isDestroyed=!0}setProps(e){this.props={...this.props,...e},void 0!==e.name&&(this.name=e.name),void 0!==e.maxConcurrency&&(this.maxConcurrency=e.maxConcurrency),void 0!==e.maxMobileConcurrency&&(this.maxMobileConcurrency=e.maxMobileConcurrency),void 0!==e.reuseWorkers&&(this.reuseWorkers=e.reuseWorkers),void 0!==e.onDebug&&(this.onDebug=e.onDebug)}async startJob(e,t=((e,t,s)=>e.done(s)),s=((e,t)=>e.error(t))){const i=new Promise((i=>(this.jobQueue.push({name:e,onMessage:t,onError:s,onStart:i}),this)));return this._startQueuedJob(),await i}async _startQueuedJob(){if(!this.jobQueue.length)return;const e=this._getAvailableWorker();if(!e)return;const t=this.jobQueue.shift();if(t){this.onDebug({message:"Starting job",name:t.name,workerThread:e,backlog:this.jobQueue.length});const s=new Lo(t.name,e);e.onMessage=e=>t.onMessage(s,e.type,e.payload),e.onError=e=>t.onError(s,e),t.onStart(s);try{await s.result}catch(e){console.error(`Worker exception: ${e}`)}finally{this.returnWorkerToQueue(e)}}}returnWorkerToQueue(e){!Qo||this.isDestroyed||!this.reuseWorkers||this.count>this._getMaxConcurrency()?(e.destroy(),this.count--):this.idleQueue.push(e),this.isDestroyed||this._startQueuedJob()}_getAvailableWorker(){if(this.idleQueue.length>0)return this.idleQueue.shift()||null;if(this.count<this._getMaxConcurrency()){this.count++;const e=`${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;return new Ko({name:e,source:this.source,url:this.url})}return null}_getMaxConcurrency(){return Oo?this.maxMobileConcurrency:this.maxConcurrency}}const Jo={maxConcurrency:3,maxMobileConcurrency:1,reuseWorkers:!0,onDebug:()=>{}};class Yo{props;workerPools=new Map;static _workerFarm;static isSupported(){return Ko.isSupported()}static getWorkerFarm(e={}){return Yo._workerFarm=Yo._workerFarm||new Yo({}),Yo._workerFarm.setProps(e),Yo._workerFarm}constructor(e){this.props={...Jo},this.setProps(e),this.workerPools=new Map}destroy(){for(const e of this.workerPools.values())e.destroy();this.workerPools=new Map}setProps(e){this.props={...this.props,...e};for(const e of this.workerPools.values())e.setProps(this._getWorkerPoolProps())}getWorkerPool(e){const{name:t,source:s,url:i}=e;let r=this.workerPools.get(t);return r||(r=new Zo({name:t,source:s,url:i}),r.setProps(this._getWorkerPoolProps()),this.workerPools.set(t,r)),r}_getWorkerPoolProps(){return{maxConcurrency:this.props.maxConcurrency,maxMobileConcurrency:this.props.maxMobileConcurrency,reuseWorkers:this.props.reuseWorkers,onDebug:this.props.onDebug}}}const $o={};async function qo(e,t=null,s={},i=null){return t&&(e=function(e,t,s={},i=null){if(!s.useLocalLibraries&&e.startsWith("http"))return e;i=i||e;const r=s.modules||{};if(r[i])return r[i];if(!Qo)return`modules/${t}/dist/libs/${i}`;if(s.CDN)return ko(s.CDN.startsWith("http")),`${s.CDN}/${t}@${Do}/dist/libs/${i}`;if(Ro)return`../src/libs/${i}`;return`modules/${t}/src/libs/${i}`}(e,t,s,i)),$o[e]=$o[e]||async function(e){if(e.endsWith("wasm"))return await async function(e){const{readFileAsArrayBuffer:t}=globalThis.loaders||{};if(Qo||!t||e.startsWith("http")){const t=await fetch(e);return await t.arrayBuffer()}return await t(e)}(e);if(!Qo)try{const{requireFromFile:t}=globalThis.loaders||{};return await(t?.(e))}catch(e){return console.error(e),null}if(Ro)return importScripts(e);return function(e,t){if(!Qo){const{requireFromString:s}=globalThis.loaders||{};return s?.(e,t)}if(Ro)return eval.call(globalThis,e),null;const s=document.createElement("script");s.id=t;try{s.appendChild(document.createTextNode(e))}catch(t){s.text=e}return document.body.appendChild(s),null}(await async function(e){const{readFileAsText:t}=globalThis.loaders||{};if(Qo||!t||e.startsWith("http")){const t=await fetch(e);return await t.text()}return await t(e)}(e),e)}(e),await $o[e]}async function ea(e,t,s,i,r){const n=e.id,A=function(e,t={}){const s=t[e.id]||{},i=Qo?`${e.id}-worker.js`:`${e.id}-worker-node.js`;let r=s.workerUrl;if(r||"compression"!==e.id||(r=t.workerUrl),"test"===t._workerType&&(r=Qo?`modules/${e.module}/dist/${i}`:`modules/${e.module}/src/workers/${e.id}-worker-node.ts`),!r){let t=e.version;"latest"===t&&(t="latest");const s=t?`@${t}`:"";r=`https://unpkg.com/@loaders.gl/${e.module}${s}/dist/${i}`}return ko(r),r}(e,s),o=Yo.getWorkerFarm(s).getWorkerPool({name:n,url:A});s=JSON.parse(JSON.stringify(s)),i=JSON.parse(JSON.stringify(i||{}));const a=await o.startJob("process-on-worker",ta.bind(null,r));a.postMessage("process",{input:t,options:s,context:i});const l=await a.result;return await l.result}async function ta(e,t,s,i){switch(s){case"done":t.done(i);break;case"error":t.error(new Error(i.error));break;case"process":const{id:r,input:n,options:A}=i;try{const s=await e(n,A);t.postMessage("done",{id:r,result:s})}catch(e){const s=e instanceof Error?e.message:"unknown error";t.postMessage("error",{id:r,error:s})}break;default:console.warn(`parse-with-worker unknown message ${s}`)}}function sa(e,t,s){if(e.byteLength<=t+s)return"";const i=new DataView(e);let r="";for(let e=0;e<s;e++)r+=String.fromCharCode(i.getUint8(t+e));return r}function ia(e){try{return JSON.parse(e)}catch(t){throw new Error(`Failed to parse JSON from data starting with "${function(e,t=5){if("string"==typeof e)return e.slice(0,t);if(ArrayBuffer.isView(e))return sa(e.buffer,e.byteOffset,t);if(e instanceof ArrayBuffer)return sa(e,0,t);return""}(e)}"`)}}function ra(...e){return function(e){const t=e.map((e=>e instanceof ArrayBuffer?new Uint8Array(e):e)),s=t.reduce(((e,t)=>e+t.byteLength),0),i=new Uint8Array(s);let r=0;for(const e of t)i.set(e,r),r+=e.byteLength;return i.buffer}(e)}function na(e,t,s){const i=void 0!==s?new Uint8Array(e).subarray(t,t+s):new Uint8Array(e).subarray(t);return new Uint8Array(i).buffer}function Aa(e,t){return lo(e>=0),lo(t>0),e+(t-1)&~(t-1)}function oa(e,t,s){let i;if(e instanceof ArrayBuffer)i=new Uint8Array(e);else{const t=e.byteOffset,s=e.byteLength;i=new Uint8Array(e.buffer||e.arrayBuffer,t,s)}return t.set(i,s),s+Aa(i.byteLength,4)}const aa={};function la(e){if((t=e)&&"object"==typeof t&&t.isBuffer)return e;var t;if(e instanceof ArrayBuffer)return e;if(ArrayBuffer.isView(e))return 0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);if("string"==typeof e){const t=e;return(new TextEncoder).encode(t).buffer}if(e&&"object"==typeof e&&e._toArrayBuffer)return e._toArrayBuffer();throw new Error("toArrayBuffer")}function ca(e){const t=e?e.lastIndexOf("/"):-1;return t>=0?e.substr(t+1):""}const ha=e=>"function"==typeof e,ua=e=>null!==e&&"object"==typeof e,da=e=>ua(e)&&e.constructor==={}.constructor,pa=e=>"undefined"!=typeof Response&&e instanceof Response||e&&e.arrayBuffer&&e.text&&e.json,fa=e=>"undefined"!=typeof Blob&&e instanceof Blob,ga=e=>(e=>"undefined"!=typeof ReadableStream&&e instanceof ReadableStream||ua(e)&&ha(e.tee)&&ha(e.cancel)&&ha(e.getReader))(e)||(e=>ua(e)&&ha(e.read)&&ha(e.pipe)&&(e=>"boolean"==typeof e)(e.readable))(e);class ma extends Error{constructor(e,t){super(e),this.reason=t.reason,this.url=t.url,this.response=t.response}reason;url;response}const _a=/^data:([-\w.]+\/[-\w.+]+)(;|,)/,ba=/^([-\w.]+\/[-\w.+]+)/;function ya(e,t){return e.toLowerCase()===t.toLowerCase()}function Ba(e){const t=_a.exec(e);return t?t[1]:""}const wa=/\?.*/;function va(e){return e.replace(wa,"")}function Ca(e){if(pa(e)){return e.url}if(fa(e)){return e.name||""}return"string"==typeof e?e:""}function Ma(e){if(pa(e)){const t=e,s=t.headers.get("content-type")||"",i=va(t.url);return function(e){const t=ba.exec(e);return t?t[1]:e}(s)||Ba(i)}if(fa(e)){return e.type||""}return"string"==typeof e?Ba(e):""}async function Ea(e){if(pa(e))return e;const t={},s=function(e){if(pa(e))return e.headers["content-length"]||-1;if(fa(e))return e.size;return"string"==typeof e?e.length:e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e.byteLength:-1}(e);s>=0&&(t["content-length"]=String(s));const i=Ca(e),r=Ma(e);r&&(t["content-type"]=r);const n=await async function(e){const t=5;if("string"==typeof e)return`data:,${e.slice(0,t)}`;if(e instanceof Blob){const t=e.slice(0,5);return await new Promise((e=>{const s=new FileReader;s.onload=t=>e(t?.target?.result),s.readAsDataURL(t)}))}if(e instanceof ArrayBuffer){const s=function(e){let t="";const s=new Uint8Array(e);for(let e=0;e<s.byteLength;e++)t+=String.fromCharCode(s[e]);return btoa(t)}(e.slice(0,t));return`data:base64,${s}`}return null}(e);n&&(t["x-first-bytes"]=n),"string"==typeof e&&(e=(new TextEncoder).encode(e));const A=new Response(e,{headers:t});return Object.defineProperty(A,"url",{value:i}),A}async function Fa(e){if(!e.ok){const t=await async function(e){const t=function(e){if(e.length<50)return e;const t=e.slice(e.length-15);return`${e.substr(0,32)}...${t}`}(e.url);let s=`Failed to fetch resource (${e.status}) ${e.statusText}: ${t}`;s=s.length>100?`${s.slice(0,100)}...`:s;const i={reason:e.statusText,url:e.url,response:e};try{const t=e.headers.get("Content-Type");i.reason=!e.bodyUsed&&t?.includes("application/json")?await e.json():await e.text()}catch(e){}return new ma(s,i)}(e);throw t}}async function xa(e,t){if("string"==typeof e){const s=function(e){for(const t in aa)if(e.startsWith(t)){const s=aa[t];e=e.replace(t,s)}return e.startsWith("http://")||e.startsWith("https://")||(e=`${e}`),e}(e);return function(e){return!function(e){return e.startsWith("http:")||e.startsWith("https:")}(e)&&!function(e){return e.startsWith("data:")}(e)}(s)&&globalThis.loaders?.fetchNode?globalThis.loaders?.fetchNode(s,t):await fetch(s,t)}return await Ea(e)}const Ua=new Eo({id:"loaders.gl"});class Ia{log(){return()=>{}}info(){return()=>{}}warn(){return()=>{}}error(){return()=>{}}}const Ta={fetch:null,mimeType:void 0,nothrow:!1,log:new class{console;constructor(){this.console=console}log(...e){return this.console.log.bind(this.console,...e)}info(...e){return this.console.info.bind(this.console,...e)}warn(...e){return this.console.warn.bind(this.console,...e)}error(...e){return this.console.error.bind(this.console,...e)}},useLocalLibraries:!1,CDN:"https://unpkg.com/@loaders.gl",worker:!0,maxConcurrency:3,maxMobileConcurrency:1,reuseWorkers:co,_nodeWorkers:!1,_workerType:"",limit:0,_limitMB:0,batchSize:"auto",batchDebounceMs:0,metadata:!1,transforms:[]},Pa={throws:"nothrow",dataType:"(no longer used)",uri:"baseUri",method:"fetch.method",headers:"fetch.headers",body:"fetch.body",mode:"fetch.mode",credentials:"fetch.credentials",cache:"fetch.cache",redirect:"fetch.redirect",referrer:"fetch.referrer",referrerPolicy:"fetch.referrerPolicy",integrity:"fetch.integrity",keepalive:"fetch.keepalive",signal:"fetch.signal"};function Sa(){globalThis.loaders=globalThis.loaders||{};const{loaders:e}=globalThis;return e._state||(e._state={}),e._state}function Da(){const e=Sa();return e.globalOptions=e.globalOptions||{...Ta},e.globalOptions}function ka(e,t,s,i){return s=s||[],function(e,t){Qa(e,null,Ta,Pa,t);for(const s of t){const i=e&&e[s.id]||{},r=s.options&&s.options[s.id]||{},n=s.deprecatedOptions&&s.deprecatedOptions[s.id]||{};Qa(i,s.id,r,n,t)}}(e,s=Array.isArray(s)?s:[s]),function(e,t,s){const i={...e.options||{}};(function(e,t){t&&!("baseUri"in e)&&(e.baseUri=t)})(i,s),null===i.log&&(i.log=new Ia);return Oa(i,Da()),Oa(i,t),i}(t,e,i)}function Qa(e,t,s,i,r){const n=t||"Top level",A=t?`${t}.`:"";for(const o in e){const a=!t&&ua(e[o]),l="baseUri"===o&&!t,c="workerUrl"===o&&t;if(!(o in s)&&!l&&!c)if(o in i)Ua.warn(`${n} loader option '${A}${o}' no longer supported, use '${i[o]}'`)();else if(!a){const e=Ra(o,r);Ua.warn(`${n} loader option '${A}${o}' not recognized. ${e}`)()}}}function Ra(e,t){const s=e.toLowerCase();let i="";for(const r of t)for(const t in r.options){if(e===t)return`Did you mean '${r.id}.${t}'?`;const n=t.toLowerCase();(s.startsWith(n)||n.startsWith(s))&&(i=i||`Did you mean '${r.id}.${t}'?`)}return i}function Oa(e,t){for(const s in t)if(s in t){const i=t[s];da(i)&&da(e[s])?e[s]={...e[s],...t[s]}:e[s]=t[s]}}function Va(e){if(!e)return!1;Array.isArray(e)&&(e=e[0]);return Array.isArray(e?.extensions)}function La(e){let t;return lo(e,"null loader"),lo(Va(e),"invalid loader"),Array.isArray(e)&&(t=e[1],e=e[0],e={...e,options:{...e.options,...t}}),(e?.parseTextSync||e?.parseText)&&(e.text=!0),e.text||(e.binary=!0),e}function Ha(){return(()=>{const e=Sa();return e.loaderRegistry=e.loaderRegistry||[],e.loaderRegistry})()}const Na=/\.([^.]+)$/;function Ga(e,t=[],s,i){if(!ja(e))return null;if(t&&!Array.isArray(t))return La(t);let r=[];t&&(r=r.concat(t)),s?.ignoreRegisteredLoaders||r.push(...Ha()),function(e){for(const t of e)La(t)}(r);const n=function(e,t,s,i){const r=Ca(e),n=Ma(e),A=va(r)||i?.url;let o=null,a="";s?.mimeType&&(o=Wa(t,s?.mimeType),a=`match forced by supplied MIME type ${s?.mimeType}`);o=o||function(e,t){const s=t&&Na.exec(t),i=s&&s[1];return i?function(e,t){t=t.toLowerCase();for(const s of e)for(const e of s.extensions)if(e.toLowerCase()===t)return s;return null}(e,i):null}(t,A),a=a||(o?`matched url ${A}`:""),o=o||Wa(t,n),a=a||(o?`matched MIME type ${n}`:""),o=o||function(e,t){if(!t)return null;for(const s of e)if("string"==typeof t){if(Xa(t,s))return s}else if(ArrayBuffer.isView(t)){if(Ka(t.buffer,t.byteOffset,s))return s}else if(t instanceof ArrayBuffer){if(Ka(t,0,s))return s}return null}(t,e),a=a||(o?`matched initial data ${Za(e)}`:""),s?.fallbackMimeType&&(o=o||Wa(t,s?.fallbackMimeType),a=a||(o?`matched fallback MIME type ${n}`:""));a&&To.log(1,`selectLoader selected ${o?.name}: ${a}.`);return o}(e,r,s,i);if(!n&&!s?.nothrow)throw new Error(za(e));return n}function ja(e){return!(e instanceof Response&&204===e.status)}function za(e){const t=Ca(e),s=Ma(e);let i="No valid loader found (";i+=t?`${ca(t)}, `:"no url provided, ",i+=`MIME type: ${s?`"${s}"`:"not provided"}, `;const r=e?Za(e):"";return i+=r?` first bytes: "${r}"`:"first bytes: not available",i+=")",i}function Wa(e,t){for(const s of e){if(s.mimeTypes?.some((e=>ya(t,e))))return s;if(ya(t,`application/x.${s.id}`))return s}return null}function Xa(e,t){if(t.testText)return t.testText(e);return(Array.isArray(t.tests)?t.tests:[t.tests]).some((t=>e.startsWith(t)))}function Ka(e,t,s){return(Array.isArray(s.tests)?s.tests:[s.tests]).some((s=>function(e,t,s,i){if(i instanceof ArrayBuffer)return function(e,t,s){if(s=s||e.byteLength,e.byteLength<s||t.byteLength<s)return!1;const i=new Uint8Array(e),r=new Uint8Array(t);for(let e=0;e<i.length;++e)if(i[e]!==r[e])return!1;return!0}(i,e,i.byteLength);switch(typeof i){case"function":return i(e);case"string":return i===Ja(e,t,i.length);default:return!1}}(e,t,0,s)))}function Za(e,t=5){if("string"==typeof e)return e.slice(0,t);if(ArrayBuffer.isView(e))return Ja(e.buffer,e.byteOffset,t);if(e instanceof ArrayBuffer){return Ja(e,0,t)}return""}function Ja(e,t,s){if(e.byteLength<t+s)return"";const i=new DataView(e);let r="";for(let e=0;e<s;e++)r+=String.fromCharCode(i.getUint8(t+e));return r}const Ya=262144;function $a(e,t){return co?async function*(e,t){const s=e.getReader();let i;try{for(;;){const e=i||s.read();t?._streamReadAhead&&(i=s.read());const{done:r,value:n}=await e;if(r)return;yield la(n)}}catch(e){s.releaseLock()}}(e,t):async function*(e,t){for await(const t of e)yield la(t)}(e)}function qa(e,t){if("string"==typeof e)return function*(e,t){const s=t?.chunkSize||262144;let i=0;const r=new TextEncoder;for(;i<e.length;){const t=Math.min(e.length-i,s),n=e.slice(i,i+t);i+=t,yield r.encode(n)}}(e,t);if(e instanceof ArrayBuffer)return function*(e,t={}){const{chunkSize:s=Ya}=t;let i=0;for(;i<e.byteLength;){const t=Math.min(e.byteLength-i,s),r=new ArrayBuffer(t),n=new Uint8Array(e,i,t);new Uint8Array(r).set(n),i+=t,yield r}}(e,t);if(fa(e))return async function*(e,t){const s=t?.chunkSize||1048576;let i=0;for(;i<e.size;){const t=i+s,r=await e.slice(i,t).arrayBuffer();i=t,yield r}}(e,t);if(ga(e))return $a(e,t);if(pa(e)){return $a(e.body,t)}throw new Error("makeIterator")}const el="Cannot convert supplied data type";async function tl(e,t,s){const i=e instanceof ArrayBuffer||ArrayBuffer.isView(e);if("string"==typeof e||i)return function(e,t,s){if(t.text&&"string"==typeof e)return e;var i;if((i=e)&&"object"==typeof i&&i.isBuffer&&(e=e.buffer),e instanceof ArrayBuffer){const s=e;return t.text&&!t.binary?new TextDecoder("utf8").decode(s):s}if(ArrayBuffer.isView(e)){if(t.text&&!t.binary)return new TextDecoder("utf8").decode(e);let s=e.buffer;const i=e.byteLength||e.length;return 0===e.byteOffset&&i===s.byteLength||(s=s.slice(e.byteOffset,e.byteOffset+i)),s}throw new Error(el)}(e,t);if(fa(e)&&(e=await Ea(e)),pa(e)){const s=e;return await Fa(s),t.binary?await s.arrayBuffer():await s.text()}if(ga(e)&&(e=qa(e,s)),r=e,Boolean(r)&&"function"==typeof r[Symbol.iterator]||(e=>e&&"function"==typeof e[Symbol.asyncIterator])(e))return async function(e){const t=[];for await(const s of e)t.push(s);return ra(...t)}(e);var r;throw new Error(el)}function sl(e,t){const s=Da(),i=e||s;return"function"==typeof i.fetch?i.fetch:ua(i.fetch)?e=>xa(e,i.fetch):t?.fetch?t?.fetch:xa}function il(e,t,s){if(s)return s;const i={fetch:sl(t,e),...e};if(i.url){const e=va(i.url);i.baseUrl=e,i.queryString=function(e){const t=e.match(wa);return t&&t[0]}(i.url),i.filename=ca(e),i.baseUrl=function(e){const t=e?e.lastIndexOf("/"):-1;return t>=0?e.substr(0,t):""}(e)}return Array.isArray(i.loaders)||(i.loaders=null),i}async function rl(e,t,s,i){!t||Array.isArray(t)||Va(t)||(i=void 0,s=t,t=void 0),s=s||{};const r=Ca(e=await e),n=function(e,t){if(e&&!Array.isArray(e))return e;let s;if(e&&(s=Array.isArray(e)?e:[e]),t&&t.loaders){const e=Array.isArray(t.loaders)?t.loaders:[t.loaders];s=s?[...s,...e]:e}return s&&s.length?s:void 0}(t,i),A=await async function(e,t=[],s,i){if(!ja(e))return null;let r=Ga(e,t,{...s,nothrow:!0},i);if(r)return r;if(fa(e)&&(r=Ga(e=await e.slice(0,10).arrayBuffer(),t,s,i)),!r&&!s?.nothrow)throw new Error(za(e));return r}(e,n,s);return A?(i=il({url:r,_parse:rl,loaders:n},s=ka(s,A,n,r),i||null),await async function(e,t,s,i){if(function(e,t=Do){ko(e,"no worker provided");const s=e.version}(e),s=Po(e.options,s),pa(t)){const e=t,{ok:s,redirected:r,status:n,statusText:A,type:o,url:a}=e,l=Object.fromEntries(e.headers.entries());i.response={headers:l,ok:s,redirected:r,status:n,statusText:A,type:o,url:a}}t=await tl(t,e,s);const r=e;if(r.parseTextSync&&"string"==typeof t)return r.parseTextSync(t,s,i);if(function(e,t){return!!Yo.isSupported()&&!(!Qo&&!t?._nodeWorkers)&&e.worker&&t?.worker}(e,s))return await ea(e,t,s,i,rl);if(r.parseText&&"string"==typeof t)return await r.parseText(t,s,i);if(r.parse)return await r.parse(t,s,i);throw ko(!r.parseSync),new Error(`${e.id} loader - no parser found and worker is disabled`)}(A,e,s,i)):null}function nl(e){let t=1/0,s=1/0,i=1/0,r=-1/0,n=-1/0,A=-1/0;const o=e.POSITION?e.POSITION.value:[],a=o&&o.length;for(let e=0;e<a;e+=3){const a=o[e],l=o[e+1],c=o[e+2];t=a<t?a:t,s=l<s?l:s,i=c<i?c:i,r=a>r?a:r,n=l>n?l:n,A=c>A?c:A}return[[t,s,i],[r,n,A]]}function Al(e,t={}){const s=function(e){const t=[];for(const s in e){const i=e[s];t.push(ol(s,i))}return t}(e);return{fields:s,metadata:t}}function ol(e,t,s){const i=function(e){switch(e.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}(t.value),r=s||function(e){const t={};"byteOffset"in e&&(t.byteOffset=e.byteOffset.toString(10));"byteStride"in e&&(t.byteStride=e.byteStride.toString(10));"normalized"in e&&(t.normalized=e.normalized.toString());return t}(t);return{name:e,type:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:i}]},nullable:!1,metadata:r}}const al=globalThis.loaders?.parseImageNode,ll="undefined"!=typeof Image,cl="undefined"!=typeof ImageBitmap,hl=Boolean(al),ul=!!co||hl;function dl(e){const t=function(e){if("undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap)return"imagebitmap";if("undefined"!=typeof Image&&e instanceof Image)return"image";if(e&&"object"==typeof e&&e.data&&e.width&&e.height)return"data";return null}(e);if(!t)throw new Error("Not an image");return t}function pl(e){switch(dl(e)){case"data":return e;case"image":case"imagebitmap":const t=document.createElement("canvas"),s=t.getContext("2d");if(!s)throw new Error("getImageData");return t.width=e.width,t.height=e.height,s.drawImage(e,0,0),s.getImageData(0,0,e.width,e.height);default:throw new Error("getImageData")}}const fl=/^data:image\/svg\+xml/,gl=/\.svg((\?|#).*)?$/;function ml(e){return e&&(fl.test(e)||gl.test(e))}function _l(e,t){if(ml(t))throw new Error("SVG cannot be parsed directly to imagebitmap");return new Blob([new Uint8Array(e)])}async function bl(e,t,s){const i=function(e,t){if(ml(t)){let t=(new TextDecoder).decode(e);try{"function"==typeof unescape&&"function"==typeof encodeURIComponent&&(t=unescape(encodeURIComponent(t)))}catch(e){throw new Error(e.message)}return`data:image/svg+xml;base64,${btoa(t)}`}return _l(e,t)}(e,s),r=self.URL||self.webkitURL,n="string"!=typeof i&&r.createObjectURL(i);try{return await async function(e,t){const s=new Image;if(s.src=e,t.image&&t.image.decode&&s.decode)return await s.decode(),s;return await new Promise(((e,t)=>{try{s.onload=()=>e(s),s.onerror=e=>{const s=e instanceof Error?e.message:"error";t(new Error(s))}}catch(e){t(e)}}))}(n||i,t)}finally{n&&r.revokeObjectURL(n)}}const yl={};let Bl=!0;async function wl(e,t,s){let i;if(ml(s)){i=await bl(e,t,s)}else i=_l(e,s);const r=t&&t.imagebitmap;return await async function(e,t=null){!function(e){for(const t in e||yl)return!1;return!0}(t)&&Bl||(t=null);if(t)try{return await createImageBitmap(e,t)}catch(e){console.warn(e),Bl=!1}return await createImageBitmap(e)}(i,r)}function vl(e){return function(e,t,s=0){const i=(r=t,[...r].map((e=>e.charCodeAt(0))));var r;for(let t=0;t<i.length;++t)if(i[t]!==e[t+s])return!1;return!0}(e,"ftyp",4)?0==(96&e[8])?null:function(e){switch((t=e,s=8,i=12,String.fromCharCode(...t.slice(s,i))).replace("\0"," ").trim()){case"avif":case"avis":return{extension:"avif",mimeType:"image/avif"};default:return null}var t,s,i}(e):null}function Cl(e){const t=Ml(e);return function(e){const t=Ml(e);if(!(t.byteLength>=24&&2303741511===t.getUint32(0,false)))return null;return{mimeType:"image/png",width:t.getUint32(16,false),height:t.getUint32(20,false)}}(t)||function(e){const t=Ml(e);if(!(t.byteLength>=3&&65496===t.getUint16(0,false)&&255===t.getUint8(2)))return null;const{tableMarkers:s,sofMarkers:i}=function(){const e=new Set([65499,65476,65484,65501,65534]);for(let t=65504;t<65520;++t)e.add(t);const t=new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502]);return{tableMarkers:e,sofMarkers:t}}();let r=2;for(;r+9<t.byteLength;){const e=t.getUint16(r,false);if(i.has(e))return{mimeType:"image/jpeg",height:t.getUint16(r+5,false),width:t.getUint16(r+7,false)};if(!s.has(e))return null;r+=2,r+=t.getUint16(r,false)}return null}(t)||function(e){const t=Ml(e);if(!(t.byteLength>=10&&1195984440===t.getUint32(0,false)))return null;return{mimeType:"image/gif",width:t.getUint16(6,true),height:t.getUint16(8,true)}}(t)||function(e){const t=Ml(e);if(!(t.byteLength>=14&&16973===t.getUint16(0,false)&&t.getUint32(2,true)===t.byteLength))return null;return{mimeType:"image/bmp",width:t.getUint32(18,true),height:t.getUint32(22,true)}}(t)||function(e){const t=vl(new Uint8Array(e instanceof DataView?e.buffer:e));if(!t)return null;return{mimeType:t.mimeType,width:0,height:0}}(t)}function Ml(e){if(e instanceof DataView)return e;if(ArrayBuffer.isView(e))return new DataView(e.buffer);if(e instanceof ArrayBuffer)return new DataView(e);throw new Error("toDataView")}const El={dataType:null,batchType:null,id:"image",module:"images",name:"Images",version:"4.3.3",mimeTypes:["image/png","image/jpeg","image/gif","image/webp","image/avif","image/bmp","image/vnd.microsoft.icon","image/svg+xml"],extensions:["png","jpg","jpeg","gif","webp","bmp","ico","svg","avif"],parse:async function(e,t,s){const i=((t=t||{}).image||{}).type||"auto",{url:r}=s||{};let n;switch(function(e){switch(e){case"auto":case"data":return function(){if(cl)return"imagebitmap";if(ll)return"image";if(ul)return"data";throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js")}();default:return function(e){switch(e){case"auto":return cl||ll||ul;case"imagebitmap":return cl;case"image":return ll;case"data":return ul;default:throw new Error(`@loaders.gl/images: image ${e} not supported in this environment`)}}(e),e}}(i)){case"imagebitmap":n=await wl(e,t,r);break;case"image":n=await bl(e,t,r);break;case"data":n=await async function(e,t){const{mimeType:s}=Cl(e)||{},i=globalThis.loaders?.parseImageNode;return lo(i),await i(e,s)}(e);break;default:lo(!1)}return"data"===i&&(n=pl(n)),n},tests:[e=>Boolean(Cl(new DataView(e)))],options:{image:{type:"auto",decode:!0}}},Fl={};function xl(e){if(void 0===Fl[e]){const t=co?function(e){switch(e){case"image/avif":case"image/webp":return function(e){try{const t=document.createElement("canvas");return 0===t.toDataURL(e).indexOf(`data:${e}`)}catch{return!1}}(e);default:return!0}}(e):function(e){const t=["image/png","image/jpeg","image/gif"],s=globalThis.loaders?.imageFormatsNode||t,i=globalThis.loaders?.parseImageNode;return Boolean(i)&&s.includes(e)}(e);Fl[e]=t}return Fl[e]}function Ul(e,t){if(!e)throw new Error(t||"assert failed: gltf")}const Il={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Tl={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Pl=["SCALAR","VEC2","VEC3","VEC4"],Sl=[[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126],[Float64Array,5130]],Dl=new Map(Sl),kl={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ql={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Rl={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function Ol(e){return Pl[e-1]||Pl[0]}function Vl(e){const t=Dl.get(e.constructor);if(!t)throw new Error("Illegal typed array");return t}function Ll(e,t){const s=Rl[e.componentType],i=kl[e.type],r=Ql[e.componentType],n=e.count*i,A=e.count*i*r;Ul(A>=0&&A<=t.byteLength);return{ArrayType:s,length:n,byteLength:A,componentByteSize:Tl[e.componentType],numberOfComponentsInElement:Il[e.type]}}class Hl{gltf;sourceBuffers;byteLength;constructor(e){this.gltf={json:e?.json||{asset:{version:"2.0",generator:"loaders.gl"},buffers:[],extensions:{},extensionsRequired:[],extensionsUsed:[]},buffers:e?.buffers||[],images:e?.images||[]},this.sourceBuffers=[],this.byteLength=0,this.gltf.buffers&&this.gltf.buffers[0]&&(this.byteLength=this.gltf.buffers[0].byteLength,this.sourceBuffers=[this.gltf.buffers[0]])}get json(){return this.gltf.json}getApplicationData(e){return this.json[e]}getExtraData(e){return(this.json.extras||{})[e]}hasExtension(e){const t=this.getUsedExtensions().find((t=>t===e)),s=this.getRequiredExtensions().find((t=>t===e));return"string"==typeof t||"string"==typeof s}getExtension(e){const t=this.getUsedExtensions().find((t=>t===e)),s=this.json.extensions||{};return t?s[e]:null}getRequiredExtension(e){const t=this.getRequiredExtensions().find((t=>t===e));return t?this.getExtension(e):null}getRequiredExtensions(){return this.json.extensionsRequired||[]}getUsedExtensions(){return this.json.extensionsUsed||[]}getRemovedExtensions(){return this.json.extensionsRemoved||[]}getObjectExtension(e,t){return(e.extensions||{})[t]}getScene(e){return this.getObject("scenes",e)}getNode(e){return this.getObject("nodes",e)}getSkin(e){return this.getObject("skins",e)}getMesh(e){return this.getObject("meshes",e)}getMaterial(e){return this.getObject("materials",e)}getAccessor(e){return this.getObject("accessors",e)}getTexture(e){return this.getObject("textures",e)}getSampler(e){return this.getObject("samplers",e)}getImage(e){return this.getObject("images",e)}getBufferView(e){return this.getObject("bufferViews",e)}getBuffer(e){return this.getObject("buffers",e)}getObject(e,t){if("object"==typeof t)return t;const s=this.json[e]&&this.json[e][t];if(!s)throw new Error(`glTF file error: Could not find ${e}[${t}]`);return s}getTypedArrayForBufferView(e){const t=(e=this.getBufferView(e)).buffer,s=this.gltf.buffers[t];Ul(s);const i=(e.byteOffset||0)+s.byteOffset;return new Uint8Array(s.arrayBuffer,i,e.byteLength)}getTypedArrayForAccessor(e){const t=this.getAccessor(e);return function(e,t,s){const i="number"==typeof s?e.accessors?.[s]:s;if(!i)throw new Error(`No gltf accessor ${JSON.stringify(s)}`);const r=e.bufferViews?.[i.bufferView||0];if(!r)throw new Error(`No gltf buffer view for accessor ${r}`);const{arrayBuffer:n,byteOffset:A}=t[r.buffer],o=(A||0)+(i.byteOffset||0)+(r.byteOffset||0),{ArrayType:a,length:l,componentByteSize:c,numberOfComponentsInElement:h}=Ll(i,r),u=c*h,d=r.byteStride||u;if(void 0===r.byteStride||r.byteStride===u)return new a(n,o,l);const p=new a(l);for(let e=0;e<i.count;e++){const t=new a(n,o+e*d,h);p.set(t,e*h)}return p}(this.gltf.json,this.gltf.buffers,t)}getTypedArrayForImageData(e){e=this.getAccessor(e);const t=this.getBufferView(e.bufferView),s=this.getBuffer(t.buffer).data,i=t.byteOffset||0;return new Uint8Array(s,i,t.byteLength)}addApplicationData(e,t){return this.json[e]=t,this}addExtraData(e,t){return this.json.extras=this.json.extras||{},this.json.extras[e]=t,this}addObjectExtension(e,t,s){return e.extensions=e.extensions||{},e.extensions[t]=s,this.registerUsedExtension(t),this}setObjectExtension(e,t,s){(e.extensions||{})[t]=s}removeObjectExtension(e,t){const s=e?.extensions||{};if(s[t]){this.json.extensionsRemoved=this.json.extensionsRemoved||[];const e=this.json.extensionsRemoved;e.includes(t)||e.push(t)}delete s[t]}addExtension(e,t={}){return Ul(t),this.json.extensions=this.json.extensions||{},this.json.extensions[e]=t,this.registerUsedExtension(e),t}addRequiredExtension(e,t={}){return Ul(t),this.addExtension(e,t),this.registerRequiredExtension(e),t}registerUsedExtension(e){this.json.extensionsUsed=this.json.extensionsUsed||[],this.json.extensionsUsed.find((t=>t===e))||this.json.extensionsUsed.push(e)}registerRequiredExtension(e){this.registerUsedExtension(e),this.json.extensionsRequired=this.json.extensionsRequired||[],this.json.extensionsRequired.find((t=>t===e))||this.json.extensionsRequired.push(e)}removeExtension(e){if(this.json.extensions?.[e]){this.json.extensionsRemoved=this.json.extensionsRemoved||[];const t=this.json.extensionsRemoved;t.includes(e)||t.push(e)}this.json.extensions&&delete this.json.extensions[e],this.json.extensionsRequired&&this._removeStringFromArray(this.json.extensionsRequired,e),this.json.extensionsUsed&&this._removeStringFromArray(this.json.extensionsUsed,e)}setDefaultScene(e){this.json.scene=e}addScene(e){const{nodeIndices:t}=e;return this.json.scenes=this.json.scenes||[],this.json.scenes.push({nodes:t}),this.json.scenes.length-1}addNode(e){const{meshIndex:t,matrix:s}=e;this.json.nodes=this.json.nodes||[];const i={mesh:t};return s&&(i.matrix=s),this.json.nodes.push(i),this.json.nodes.length-1}addMesh(e){const{attributes:t,indices:s,material:i,mode:r=4}=e,n={primitives:[{attributes:this._addAttributes(t),mode:r}]};if(s){const e=this._addIndices(s);n.primitives[0].indices=e}return Number.isFinite(i)&&(n.primitives[0].material=i),this.json.meshes=this.json.meshes||[],this.json.meshes.push(n),this.json.meshes.length-1}addPointCloud(e){const t={primitives:[{attributes:this._addAttributes(e),mode:0}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(t),this.json.meshes.length-1}addImage(e,t){const s=Cl(e),i=t||s?.mimeType,r={bufferView:this.addBufferView(e),mimeType:i};return this.json.images=this.json.images||[],this.json.images.push(r),this.json.images.length-1}addBufferView(e,t=0,s=this.byteLength){const i=e.byteLength;Ul(Number.isFinite(i)),this.sourceBuffers=this.sourceBuffers||[],this.sourceBuffers.push(e);const r={buffer:t,byteOffset:s,byteLength:i};return this.byteLength+=Aa(i,4),this.json.bufferViews=this.json.bufferViews||[],this.json.bufferViews.push(r),this.json.bufferViews.length-1}addAccessor(e,t){const s={bufferView:e,type:Ol(t.size),componentType:t.componentType,count:t.count,max:t.max,min:t.min};return this.json.accessors=this.json.accessors||[],this.json.accessors.push(s),this.json.accessors.length-1}addBinaryBuffer(e,t={size:3}){const s=this.addBufferView(e);let i={min:t.min,max:t.max};i.min&&i.max||(i=this._getAccessorMinMax(e,t.size));const r={size:t.size,componentType:Vl(e),count:Math.round(e.length/t.size),min:i.min,max:i.max};return this.addAccessor(s,Object.assign(r,t))}addTexture(e){const{imageIndex:t}=e,s={source:t};return this.json.textures=this.json.textures||[],this.json.textures.push(s),this.json.textures.length-1}addMaterial(e){return this.json.materials=this.json.materials||[],this.json.materials.push(e),this.json.materials.length-1}createBinaryChunk(){const e=this.byteLength,t=new ArrayBuffer(e),s=new Uint8Array(t);let i=0;for(const e of this.sourceBuffers||[])i=oa(e,s,i);this.json?.buffers?.[0]?this.json.buffers[0].byteLength=e:this.json.buffers=[{byteLength:e}],this.gltf.binary=t,this.sourceBuffers=[t],this.gltf.buffers=[{arrayBuffer:t,byteOffset:0,byteLength:t.byteLength}]}_removeStringFromArray(e,t){let s=!0;for(;s;){const i=e.indexOf(t);i>-1?e.splice(i,1):s=!1}}_addAttributes(e={}){const t={};for(const s in e){const i=e[s],r=this._getGltfAttributeName(s),n=this.addBinaryBuffer(i.value,i);t[r]=n}return t}_addIndices(e){return this.addBinaryBuffer(e,{size:1})}_getGltfAttributeName(e){switch(e.toLowerCase()){case"position":case"positions":case"vertices":return"POSITION";case"normal":case"normals":return"NORMAL";case"color":case"colors":return"COLOR_0";case"texcoord":case"texcoords":return"TEXCOORD_0";default:return e}}_getAccessorMinMax(e,t){const s={min:null,max:null};if(e.length<t)return s;s.min=[],s.max=[];const i=e.subarray(0,t);for(const e of i)s.min.push(e),s.max.push(e);for(let i=t;i<e.length;i+=t)for(let r=0;r<t;r++)s.min[0+r]=Math.min(s.min[0+r],e[i+r]),s.max[0+r]=Math.max(s.max[0+r],e[i+r]);return s}}function Nl(e){return(e%1+1)%1}const Gl={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16,BOOLEAN:1,STRING:1,ENUM:1},jl={INT8:Int8Array,UINT8:Uint8Array,INT16:Int16Array,UINT16:Uint16Array,INT32:Int32Array,UINT32:Uint32Array,INT64:BigInt64Array,UINT64:BigUint64Array,FLOAT32:Float32Array,FLOAT64:Float64Array},zl={INT8:1,UINT8:1,INT16:2,UINT16:2,INT32:4,UINT32:4,INT64:8,UINT64:8,FLOAT32:4,FLOAT64:8};function Wl(e,t){return zl[t]*Gl[e]}function Xl(e,t,s,i){if("UINT8"!==s&&"UINT16"!==s&&"UINT32"!==s&&"UINT64"!==s)return null;const r=Kl(e.getTypedArrayForBufferView(t),"SCALAR",s,i+1);return r instanceof BigInt64Array||r instanceof BigUint64Array?null:r}function Kl(e,t,s,i=1){const r=jl[s],n=zl[s],A=i*Gl[t],o=A*n;let a=e.buffer,l=e.byteOffset;if(l%n!=0){a=new Uint8Array(a).slice(l,l+o).buffer,l=0}return new r(a,l,A)}function Zl(e,t,s){const i=`TEXCOORD_${t.texCoord||0}`,r=s.attributes[i],n=e.getTypedArrayForAccessor(r),A=e.gltf.json,o=t.index,a=A.textures?.[o]?.source;if(void 0!==a){const s=A.images?.[a]?.mimeType,i=e.gltf.images?.[a];if(i&&void 0!==i.width){const e=[];for(let r=0;r<n.length;r+=2){const A=Yl(i,s,n,r,t.channels);e.push(A)}return e}}return[]}function Jl(e,t,s,i,r){if(!s?.length)return;const n=[];for(const e of s){let t=i.findIndex((t=>t===e));-1===t&&(t=i.push(e)-1),n.push(t)}const A=new Uint32Array(n),o=e.gltf.buffers.push({arrayBuffer:A.buffer,byteOffset:A.byteOffset,byteLength:A.byteLength})-1,a=e.addBufferView(A,o,0),l=e.addAccessor(a,{size:1,componentType:Vl(A),count:A.length});r.attributes[t]=l}function Yl(e,t,s,i,r=[0]){const n={r:{offset:0,shift:0},g:{offset:1,shift:8},b:{offset:2,shift:16},a:{offset:3,shift:24}},A=s[i],o=s[i+1];let a=1;!t||-1===t.indexOf("image/jpeg")&&-1===t.indexOf("image/png")||(a=4);const l=function(e,t,s,i=1){const r=s.width,n=Nl(e)*(r-1),A=Math.round(n),o=s.height,a=Nl(t)*(o-1),l=Math.round(a),c=s.components?s.components:i;return(l*r+A)*c}(A,o,e,a);let c=0;for(const t of r){const s="number"==typeof t?Object.values(n)[t]:n[t],i=l+s.offset,r=pl(e);if(r.data.length<=i)throw new Error(`${r.data.length} <= ${i}`);c|=r.data[i]<<s.shift}return c}function $l(e,t,s,i,r){const n=[];for(let A=0;A<t;A++){const t=s[A],o=s[A+1]-s[A];if(o+t>i)break;const a=t/r,l=o/r;n.push(e.slice(a,a+l))}return n}function ql(e,t,s){const i=[];for(let r=0;r<t;r++){const t=r*s;i.push(e.slice(t,t+s))}return i}function ec(e,t,s,i){if(s)throw new Error("Not implemented - arrayOffsets for strings is specified");if(i){const s=[],r=new TextDecoder("utf8");let n=0;for(let A=0;A<e;A++){const e=i[A+1]-i[A];if(e+n<=t.length){const i=t.subarray(n,e+n),A=r.decode(i);s.push(A),n+=e}}return s}return[]}function tc(e,t,s){if(!s?.gltf?.loadBuffers)return;const i=t.extensions?.EXT_mesh_features,r=i?.featureIds;if(r)for(const i of r){let r;if(void 0!==i.attribute){const s=`_FEATURE_ID_${i.attribute}`,n=t.attributes[s];r=e.getTypedArrayForAccessor(n)}else r=void 0!==i.texture&&s?.gltf?.loadImages?Zl(e,i.texture,t):[];i.data=r}}function sc(e,t){const s=t.extensions?.EXT_mesh_features;if(!s)return;const i=s.featureIds;i.forEach(((s,r)=>{if(s.data){const{accessorKey:n,index:A}=function(e){const t="_FEATURE_ID_",s=Object.keys(e).filter((e=>0===e.indexOf(t)));let i=-1;for(const e of s){const s=Number(e.substring(t.length));s>i&&(i=s)}i++;return{accessorKey:`${t}${i}`,index:i}}(t.attributes),o=new Uint32Array(s.data);i[r]={featureCount:o.length,propertyTable:s.propertyTable,attribute:A},e.gltf.buffers.push({arrayBuffer:o.buffer,byteOffset:o.byteOffset,byteLength:o.byteLength});const a=e.addBufferView(o),l=e.addAccessor(a,{size:1,componentType:Vl(o),count:o.length});t.attributes[n]=l}}))}var ic=Object.freeze({__proto__:null,name:"EXT_mesh_features",decode:async function(e,t){!function(e,t){const s=e.gltf.json;if(!s.meshes)return;for(const i of s.meshes)for(const s of i.primitives)tc(e,s,t)}(new Hl(e),t)},encode:function(e,t){const s=new Hl(e);return function(e,t){const s=e.gltf.json.meshes;if(!s)return;for(const t of s)for(const s of t.primitives)sc(e,s)}(s),s.createBinaryChunk(),s.gltf},createExtMeshFeatures:function(e,t,s,i){t.extensions||(t.extensions={});let r=t.extensions.EXT_mesh_features;r||(r={featureIds:[]},t.extensions.EXT_mesh_features=r);const{featureIds:n}=r,A={featureCount:s.length,propertyTable:i,data:s};n.push(A),e.addObjectExtension(t,"EXT_mesh_features",r)}});function rc(e,t){for(const s of e)if(s.class===t)return s;return null}function nc(e,t,s,i){if(!t)return;const r=s.extensions?.EXT_structural_metadata,n=r?.propertyTextures;if(n)for(const r of n){Ac(e,t[r],s,i)}}function Ac(e,t,s,i){if(!t.properties)return;i.dataAttributeNames||(i.dataAttributeNames=[]);const r=t.class;for(const n in t.properties){const A=`${r}_${n}`,o=t.properties?.[n];if(!o)continue;o.data||(o.data=[]);const a=o.data,l=Zl(e,o,s);null!==l&&(Jl(e,A,l,a,s),o.data=a,i.dataAttributeNames.push(A))}}function oc(e,t,s){const i=t.classes?.[s.class];if(!i)throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${s.class}`);const r=s.count;for(const n in i.properties){const A=i.properties[n],o=s.properties?.[n];if(o){const s=ac(e,t,A,r,o);o.data=s}}}function ac(e,t,s,i,r){let n=[];const A=r.values,o=e.getTypedArrayForBufferView(A),a=function(e,t,s,i){if(t.array&&void 0===t.count&&void 0!==s.arrayOffsets)return Xl(e,s.arrayOffsets,s.arrayOffsetType||"UINT32",i);return null}(e,s,r,i),l=function(e,t,s){if(void 0!==t.stringOffsets)return Xl(e,t.stringOffsets,t.stringOffsetType||"UINT32",s);return null}(e,r,i);switch(s.type){case"SCALAR":case"VEC2":case"VEC3":case"VEC4":case"MAT2":case"MAT3":case"MAT4":n=function(e,t,s,i){const r=e.array,n=e.count,A=Wl(e.type,e.componentType),o=s.byteLength/A;let a;a=e.componentType?Kl(s,e.type,e.componentType,o):s;if(r)return i?$l(a,t,i,s.length,A):n?ql(a,t,n):[];return a}(s,i,o,a);break;case"BOOLEAN":throw new Error(`Not implemented - classProperty.type=${s.type}`);case"STRING":n=ec(i,o,a,l);break;case"ENUM":n=function(e,t,s,i,r){const n=t.enumType;if(!n)throw new Error("Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM");const A=e.enums?.[n];if(!A)throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${n}`);const o=A.valueType||"UINT16",a=Wl(t.type,o),l=i.byteLength/a;let c=Kl(i,t.type,o,l);c||(c=i);if(t.array){if(r)return function(e){const{valuesData:t,numberOfElements:s,arrayOffsets:i,valuesDataBytesLength:r,elementSize:n,enumEntry:A}=e,o=[];for(let e=0;e<s;e++){const s=i[e],a=i[e+1]-i[e];if(a+s>r)break;const l=lc(t,s/n,a/n,A);o.push(l)}return o}({valuesData:c,numberOfElements:s,arrayOffsets:r,valuesDataBytesLength:i.length,elementSize:a,enumEntry:A});const e=t.count;return e?function(e,t,s,i){const r=[];for(let n=0;n<t;n++){const t=lc(e,s*n,s,i);r.push(t)}return r}(c,s,e,A):[]}return lc(c,0,s,A)}(t,s,i,o,a);break;default:throw new Error(`Unknown classProperty type ${s.type}`)}return n}function lc(e,t,s,i){const r=[];for(let n=0;n<s;n++)if(e instanceof BigInt64Array||e instanceof BigUint64Array)r.push("");else{const s=cc(i,e[t+n]);s?r.push(s.name):r.push("")}return r}function cc(e,t){for(const s of e.values)if(s.value===t)return s;return null}function hc(e,t,s){for(const i in e.properties){const r=e.properties[i].data;if(r){const n=t.properties[i];if(n){const t=uc(r,n,s);e.properties[i]=t}}}}function uc(e,t,s){const i={values:0};if("STRING"===t.type){const{stringData:t,stringOffsets:r}=function(e){const t=new TextEncoder,s=[];let i=0;for(const r of e){const e=t.encode(r);i+=e.length,s.push(e)}const r=new Uint8Array(i),n=[];let A=0;for(const e of s)r.set(e,A),n.push(A),A+=e.length;n.push(A);const o=new Uint32Array(n);return{stringData:r,stringOffsets:o}}(e);i.stringOffsets=pc(r,s),i.values=pc(t,s)}else if("SCALAR"===t.type&&t.componentType){const r=function(e,t){const s=[];for(const t of e)s.push(Number(t));const i=dc[t];if(!i)throw new Error("Illegal component type");return new i(s)}(e,t.componentType);i.values=pc(r,s)}return i}const dc={INT8:Int8Array,UINT8:Uint8Array,INT16:Int16Array,UINT16:Uint16Array,INT32:Int32Array,UINT32:Uint32Array,INT64:Int32Array,UINT64:Uint32Array,FLOAT32:Float32Array,FLOAT64:Float64Array};function pc(e,t){return t.gltf.buffers.push({arrayBuffer:e.buffer,byteOffset:e.byteOffset,byteLength:e.byteLength}),t.addBufferView(e)}var fc=Object.freeze({__proto__:null,name:"EXT_structural_metadata",decode:async function(e,t){!function(e,t){if(!t.gltf?.loadBuffers)return;const s=e.getExtension("EXT_structural_metadata");if(!s)return;t.gltf?.loadImages&&function(e,t){const s=t.propertyTextures,i=e.gltf.json;if(s&&i.meshes)for(const r of i.meshes)for(const i of r.primitives)nc(e,s,i,t)}(e,s);!function(e,t){const s=t.schema;if(!s)return;const i=s.classes,r=t.propertyTables;if(i&&r)for(const t in i){const i=rc(r,t);i&&oc(e,s,i)}}(e,s)}(new Hl(e),t)},encode:function(e,t){const s=new Hl(e);return function(e,t){const s=e.getExtension("EXT_structural_metadata");if(!s)return;if(s.propertyTables)for(const t of s.propertyTables){const i=t.class,r=s.schema?.classes?.[i];t.properties&&r&&hc(t,r,e)}}(s),s.createBinaryChunk(),s.gltf},createExtStructuralMetadata:function(e,t,s="schemaClassId"){let i=e.getExtension("EXT_structural_metadata");i||(i=e.addExtension("EXT_structural_metadata")),i.schema=function(e,t,s){const i=s??{id:"schema_id"},r={properties:{}};for(const t of e){const e={type:t.elementType,componentType:t.componentType};r.properties[t.name]=e}return i.classes={},i.classes[t]=r,i}(t,s,i.schema);const r=function(e,t,s){const i={class:t,count:0};let r=0;const n=s.classes?.[t];for(const t of e){if(0===r&&(r=t.values.length),r!==t.values.length&&t.values.length)throw new Error("Illegal values in attributes");const e=n?.properties[t.name];e&&(i.properties||(i.properties={}),i.properties[t.name]={values:0,data:t.values})}return i.count=r,i}(t,s,i.schema);return i.propertyTables||(i.propertyTables=[]),i.propertyTables.push(r)-1}});function gc(e,t){for(const s in e){const i=e[s];if(i.class===t)return i}return null}function mc(e,t){for(const s in e){const i=e[s];if(i.class===t)return i}return null}function _c(e,t,s){if(!s.class)return;const i=t.classes?.[s.class];if(!i)throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${s.class}`);const r=s.count;for(const n in i.properties){const A=i.properties[n],o=s.properties?.[n];if(o){const s=yc(e,t,A,r,o);o.data=s}}}function bc(e,t,s){const i=t.class;for(const r in s.properties){const s=t?.properties?.[r];if(s){const t=Bc(e,s,i);s.data=t}}}function yc(e,t,s,i,r){let n=[];const A=r.bufferView,o=e.getTypedArrayForBufferView(A),a=function(e,t,s,i){if("ARRAY"===t.type&&void 0===t.componentCount&&void 0!==s.arrayOffsetBufferView)return Xl(e,s.arrayOffsetBufferView,s.offsetType||"UINT32",i);return null}(e,s,r,i),l=function(e,t,s,i){if(void 0!==s.stringOffsetBufferView)return Xl(e,s.stringOffsetBufferView,s.offsetType||"UINT32",i);return null}(e,0,r,i);return"STRING"===s.type||"STRING"===s.componentType?n=ec(i,o,a,l):function(e){const t=["UINT8","INT16","UINT16","INT32","UINT32","INT64","UINT64","FLOAT32","FLOAT64"];return t.includes(e.type)||void 0!==e.componentType&&t.includes(e.componentType)}(s)&&(n=function(e,t,s,i){const r="ARRAY"===e.type,n=e.componentCount,A="SCALAR",o=e.componentType||e.type,a=Wl(A,o),l=s.byteLength/a,c=Kl(s,A,o,l);if(r)return i?$l(c,t,i,s.length,a):n?ql(c,t,n):[];return c}(s,i,o,a)),n}function Bc(e,t,s){const i=e.gltf.json;if(!i.meshes)return[];const r=[];for(const n of i.meshes)for(const i of n.primitives)wc(e,s,t,r,i);return r}function wc(e,t,s,i,r){const n=Zl(e,{channels:s.channels,...s.texture},r);n&&Jl(e,t,n,i,r)}var vc=Object.freeze({__proto__:null,name:"EXT_feature_metadata",decode:async function(e,t){!function(e,t){if(!t.gltf?.loadBuffers)return;const s=e.getExtension("EXT_feature_metadata");if(!s)return;t.gltf?.loadImages&&function(e,t){const s=t.schema;if(!s)return;const i=s.classes,{featureTextures:r}=t;if(i&&r)for(const t in i){const s=i[t],n=mc(r,t);n&&bc(e,n,s)}}(e,s);!function(e,t){const s=t.schema;if(!s)return;const i=s.classes,r=t.featureTables;if(i&&r)for(const t in i){const i=gc(r,t);i&&_c(e,s,i)}}(e,s)}(new Hl(e),t)}});const Cc="basis_transcoder.js",Mc="basis_transcoder.wasm",Ec="basis_encoder.js",Fc="basis_encoder.wasm";let xc,Uc;async function Ic(e){var t;t=e.modules,globalThis.loaders||={},globalThis.loaders.modules||={},Object.assign(globalThis.loaders.modules,t);const s=function(e){const t=globalThis.loaders?.modules?.[e];return t||null}("basis");return s||(xc||=async function(e){let t=null,s=null;return[t,s]=await Promise.all([await qo(Cc,"textures",e),await qo(Mc,"textures",e)]),t=t||globalThis.BASIS,await function(e,t){const s={};t&&(s.wasmBinary=t);return new Promise((t=>{e(s).then((e=>{const{BasisFile:s,initializeBasis:i}=e;i(),t({BasisFile:s})}))}))}(t,s)}(e),await xc)}async function Tc(e){const t=e.modules||{};return t.basisEncoder?t.basisEncoder:(Uc=Uc||async function(e){let t=null,s=null;return[t,s]=await Promise.all([await qo(Ec,"textures",e),await qo(Fc,"textures",e)]),t=t||globalThis.BASIS,await function(e,t){const s={};t&&(s.wasmBinary=t);return new Promise((t=>{e(s).then((e=>{const{BasisFile:s,KTX2File:i,initializeBasis:r,BasisEncoder:n}=e;r(),t({BasisFile:s,KTX2File:i,BasisEncoder:n})}))}))}(t,s)}(e),await Uc)}const Pc=["","WEBKIT_","MOZ_"],Sc={WEBGL_compressed_texture_s3tc:"dxt",WEBGL_compressed_texture_s3tc_srgb:"dxt-srgb",WEBGL_compressed_texture_etc1:"etc1",WEBGL_compressed_texture_etc:"etc2",WEBGL_compressed_texture_pvrtc:"pvrtc",WEBGL_compressed_texture_atc:"atc",WEBGL_compressed_texture_astc:"astc",EXT_texture_compression_rgtc:"rgtc"};let Dc=null;function kc(e){if(!Dc){e=e||function(){try{return document.createElement("canvas").getContext("webgl")}catch(e){return null}}()||void 0,Dc=new Set;for(const t of Pc)for(const s in Sc)if(e&&e.getExtension(`${t}${s}`)){const e=Sc[s];Dc.add(e)}}return Dc}const Qc=[171,75,84,88,32,50,48,187,13,10,26,10];const Rc={etc1:{basisFormat:0,compressed:!0,format:36196},etc2:{basisFormat:1,compressed:!0},bc1:{basisFormat:2,compressed:!0,format:33776},bc3:{basisFormat:3,compressed:!0,format:33779},bc4:{basisFormat:4,compressed:!0},bc5:{basisFormat:5,compressed:!0},"bc7-m6-opaque-only":{basisFormat:6,compressed:!0},"bc7-m5":{basisFormat:7,compressed:!0},"pvrtc1-4-rgb":{basisFormat:8,compressed:!0,format:35840},"pvrtc1-4-rgba":{basisFormat:9,compressed:!0,format:35842},"astc-4x4":{basisFormat:10,compressed:!0,format:37808},"atc-rgb":{basisFormat:11,compressed:!0},"atc-rgba-interpolated-alpha":{basisFormat:12,compressed:!0},rgba32:{basisFormat:13,compressed:!1},rgb565:{basisFormat:14,compressed:!1},bgr565:{basisFormat:15,compressed:!1},rgba4444:{basisFormat:16,compressed:!1}};function Oc(e,t,s){const i=new e(new Uint8Array(t));try{if(!i.startTranscoding())throw new Error("Failed to start basis transcoding");const e=i.getNumImages(),t=[];for(let r=0;r<e;r++){const e=i.getNumLevels(r),n=[];for(let t=0;t<e;t++)n.push(Vc(i,r,t,s));t.push(n)}return t}finally{i.close(),i.delete()}}function Vc(e,t,s,i){const r=e.getImageWidth(t,s),n=e.getImageHeight(t,s),A=e.getHasAlpha(),{compressed:o,format:a,basisFormat:l}=Nc(i,A),c=e.getImageTranscodedSizeInBytes(t,s,l),h=new Uint8Array(c);if(!e.transcodeImage(h,t,s,l,0,0))throw new Error("failed to start Basis transcoding");return{width:r,height:n,data:h,compressed:o,format:a,hasAlpha:A}}function Lc(e,t,s){const i=new e(new Uint8Array(t));try{if(!i.startTranscoding())throw new Error("failed to start KTX2 transcoding");const e=i.getLevels(),t=[];for(let r=0;r<e;r++)t.push(Hc(i,r,s));return[t]}finally{i.close(),i.delete()}}function Hc(e,t,s){const{alphaFlag:i,height:r,width:n}=e.getImageLevelInfo(t,0,0),{compressed:A,format:o,basisFormat:a}=Nc(s,i),l=e.getImageTranscodedSizeInBytes(t,0,0,a),c=new Uint8Array(l);if(!e.transcodeImage(c,t,0,0,a,0,-1,-1))throw new Error("Failed to transcode KTX2 image");return{width:n,height:r,data:c,compressed:A,levelSize:l,hasAlpha:i,format:o}}function Nc(e,t){let s=e&&e.basis&&e.basis.format;return"auto"===s&&(s=Gc()),"object"==typeof s&&(s=t?s.alpha:s.noAlpha),s=s.toLowerCase(),Rc[s]}function Gc(){const e=kc();return e.has("astc")?"astc-4x4":e.has("dxt")?{alpha:"bc3",noAlpha:"bc1"}:e.has("pvrtc")?{alpha:"pvrtc1-4-rgba",noAlpha:"pvrtc1-4-rgb"}:e.has("etc1")?"etc1":e.has("etc2")?"etc2":"rgb565"}const jc={...{dataType:null,batchType:null,name:"Basis",id:"basis",module:"textures",version:"4.3.3",worker:!0,extensions:["basis","ktx2"],mimeTypes:["application/octet-stream","image/ktx2"],tests:["sB"],binary:!0,options:{basis:{format:"auto",libraryPath:"libs/",containerFormat:"auto",module:"transcoder"}}},parse:async function(e,t){if("auto"===t.basis.containerFormat){if(function(e){const t=new Uint8Array(e);return!(t.byteLength<Qc.length||t[0]!==Qc[0]||t[1]!==Qc[1]||t[2]!==Qc[2]||t[3]!==Qc[3]||t[4]!==Qc[4]||t[5]!==Qc[5]||t[6]!==Qc[6]||t[7]!==Qc[7]||t[8]!==Qc[8]||t[9]!==Qc[9]||t[10]!==Qc[10]||t[11]!==Qc[11])}(e)){return Lc((await Tc(t)).KTX2File,e,t)}const{BasisFile:s}=await Ic(t);return Oc(s,e,t)}if("encoder"===t.basis.module){const s=await Tc(t);return"ktx2"===t.basis.containerFormat?Lc(s.KTX2File,e,t):Oc(s.BasisFile,e,t)}{const{BasisFile:s}=await Ic(t);return Oc(s,e,t)}}},zc=1735152710;function Wc(e,t,s=0,i={}){const r=new DataView(t),n=function(e,t=0){return`${String.fromCharCode(e.getUint8(t+0))}${String.fromCharCode(e.getUint8(t+1))}${String.fromCharCode(e.getUint8(t+2))}${String.fromCharCode(e.getUint8(t+3))}`}(r,s+0),A=r.getUint32(s+4,true),o=r.getUint32(s+8,true);switch(Object.assign(e,{header:{byteOffset:s,byteLength:o,hasBinChunk:!1},type:n,version:A,json:{},binChunks:[]}),s+=12,e.version){case 1:return function(e,t,s){lo(e.header.byteLength>20);const i=t.getUint32(s+0,true),r=t.getUint32(s+4,true);return s+=8,lo(0===r),Xc(e,t,s,i),s+=i,s+=Kc(e,t,s,e.header.byteLength)}(e,r,s);case 2:return function(e,t,s,i){return lo(e.header.byteLength>20),function(e,t,s,i){for(;s+8<=e.header.byteLength;){const r=t.getUint32(s+0,true),n=t.getUint32(s+4,true);switch(s+=8,n){case 1313821514:Xc(e,t,s,r);break;case 5130562:Kc(e,t,s,r);break;case 0:i.strict||Xc(e,t,s,r);break;case 1:i.strict||Kc(e,t,s,r)}s+=Aa(r,4)}}(e,t,s,i),s+e.header.byteLength}(e,r,s,{});default:throw new Error(`Invalid GLB version ${e.version}. Only supports version 1 and 2.`)}}function Xc(e,t,s,i){const r=new Uint8Array(t.buffer,s,i),n=new TextDecoder("utf8").decode(r);return e.json=JSON.parse(n),Aa(i,4)}function Kc(e,t,s,i){return e.header.hasBinChunk=!0,e.binChunks.push({byteOffset:s,byteLength:i,arrayBuffer:t.buffer}),Aa(i,4)}function Zc(e,t){if(e.startsWith("data:")||e.startsWith("http:")||e.startsWith("https:"))return e;const s=t.baseUri||t.uri;if(!s)throw new Error(`'baseUri' must be provided to resolve relative url ${e}`);return s.substr(0,s.lastIndexOf("/")+1)+e}const Jc="B9h9z9tFBBBF8fL9gBB9gLaaaaaFa9gEaaaB9gFaFa9gEaaaFaEMcBFFFGGGEIIILF9wFFFLEFBFKNFaFCx/IFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBF8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBGy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBEn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBIi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBKI9z9iqlBOc+x8ycGBM/qQFTa8jUUUUBCU/EBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAGTkUUUBRNCUoBAG9uC/wgBZHKCUGAKCUG9JyRVAECFJRICBRcGXEXAcAF9PQFAVAFAclAcAVJAF9JyRMGXGXAG9FQBAMCbJHKC9wZRSAKCIrCEJCGrRQANCUGJRfCBRbAIRTEXGXAOATlAQ9PQBCBRISEMATAQJRIGXAS9FQBCBRtCBREEXGXAOAIlCi9PQBCBRISLMANCU/CBJAEJRKGXGXGXGXGXATAECKrJ2BBAtCKZrCEZfIBFGEBMAKhB83EBAKCNJhB83EBSEMAKAI2BIAI2BBHmCKrHYAYCE6HYy86BBAKCFJAICIJAYJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCGJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCEJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCIJAYAmJHY2BBAI2BFHmCKrHPAPCE6HPy86BBAKCLJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCKJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCOJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCNJAYAmJHY2BBAI2BGHmCKrHPAPCE6HPy86BBAKCVJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCcJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCMJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCSJAYAmJHm2BBAI2BEHICKrHYAYCE6HYy86BBAKCQJAmAYJHm2BBAICIrCEZHYAYCE6HYy86BBAKCfJAmAYJHm2BBAICGrCEZHYAYCE6HYy86BBAKCbJAmAYJHK2BBAICEZHIAICE6HIy86BBAKAIJRISGMAKAI2BNAI2BBHmCIrHYAYCb6HYy86BBAKCFJAICNJAYJHY2BBAmCbZHmAmCb6Hmy86BBAKCGJAYAmJHm2BBAI2BFHYCIrHPAPCb6HPy86BBAKCEJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCIJAmAYJHm2BBAI2BGHYCIrHPAPCb6HPy86BBAKCLJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCKJAmAYJHm2BBAI2BEHYCIrHPAPCb6HPy86BBAKCOJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCNJAmAYJHm2BBAI2BIHYCIrHPAPCb6HPy86BBAKCVJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCcJAmAYJHm2BBAI2BLHYCIrHPAPCb6HPy86BBAKCMJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCSJAmAYJHm2BBAI2BKHYCIrHPAPCb6HPy86BBAKCQJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCfJAmAYJHm2BBAI2BOHICIrHYAYCb6HYy86BBAKCbJAmAYJHK2BBAICbZHIAICb6HIy86BBAKAIJRISFMAKAI8pBB83BBAKCNJAICNJ8pBB83BBAICTJRIMAtCGJRtAECTJHEAS9JQBMMGXAIQBCBRISEMGXAM9FQBANAbJ2BBRtCBRKAfREEXAEANCU/CBJAKJ2BBHTCFrCBATCFZl9zAtJHt86BBAEAGJREAKCFJHKAM9HQBMMAfCFJRfAIRTAbCFJHbAG9HQBMMABAcAG9sJANCUGJAMAG9sTkUUUBpANANCUGJAMCaJAG9sJAGTkUUUBpMAMCBAIyAcJRcAIQBMC9+RKSFMCBC99AOAIlAGCAAGCA9Ly6yRKMALCU/EBJ8kUUUUBAKM+OmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUFT+JUUUBpALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM+lLKFaF99GaG99FaG99GXGXAGCI9HQBAF9FQFEXGXGX9DBBB8/9DBBB+/ABCGJHG1BB+yAB1BBHE+yHI+L+TABCFJHL1BBHK+yHO+L+THN9DBBBB9gHVyAN9DBB/+hANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE86BBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG86BBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG86BBABCIJRBAFCaJHFQBSGMMAF9FQBEXGXGX9DBBB8/9DBBB+/ABCIJHG8uFB+yAB8uFBHE+yHI+L+TABCGJHL8uFBHK+yHO+L+THN9DBBBB9gHVyAN9DB/+g6ANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE87FBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG87FBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG87FBABCNJRBAFCaJHFQBMMM/SEIEaE99EaF99GXAF9FQBCBREABRIEXGXGX9D/zI818/AICKJ8uFBHLCEq+y+VHKAI8uFB+y+UHO9DB/+g6+U9DBBB8/9DBBB+/AO9DBBBB9gy+SHN+L9DBBB9P9d9FQBAN+oRVSFMCUUUU94RVMAICIJ8uFBRcAICGJ8uFBRMABALCFJCEZAEqCFWJAV87FBGXGXAKAM+y+UHN9DB/+g6+U9DBBB8/9DBBB+/AN9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRMSFMCUUUU94RMMABALCGJCEZAEqCFWJAM87FBGXGXAKAc+y+UHK9DB/+g6+U9DBBB8/9DBBB+/AK9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRcSFMCUUUU94RcMABALCaJCEZAEqCFWJAc87FBGXGX9DBBU8/AOAO+U+TANAN+U+TAKAK+U+THO9DBBBBAO9DBBBB9gy+R9DB/+g6+U9DBBB8/+SHO+L9DBBB9P9d9FQBAO+oRcSFMCUUUU94RcMABALCEZAEqCFWJAc87FBAICNJRIAECIJREAFCaJHFQBMMM9JBGXAGCGrAF9sHF9FQBEXABAB8oGBHGCNWCN91+yAGCi91CnWCUUU/8EJ+++U84GBABCIJRBAFCaJHFQBMMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEM/lFFFaGXGXAFABqCEZ9FQBABRESFMGXGXAGCT9PQBABRESFMABREEXAEAF8oGBjGBAECIJAFCIJ8oGBjGBAECNJAFCNJ8oGBjGBAECSJAFCSJ8oGBjGBAECTJREAFCTJRFAGC9wJHGCb9LQBMMAGCI9JQBEXAEAF8oGBjGBAFCIJRFAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF2BB86BBAECFJREAFCFJRFAGCaJHGQBMMABMoFFGaGXGXABCEZ9FQBABRESFMAFCgFZC+BwsN9sRIGXGXAGCT9PQBABRESFMABREEXAEAIjGBAECSJAIjGBAECNJAIjGBAECIJAIjGBAECTJREAGC9wJHGCb9LQBMMAGCI9JQBEXAEAIjGBAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF86BBAECFJREAGCaJHGQBMMABMMMFBCUNMIT9kBB",Yc="B9h9z9tFBBBF8dL9gBB9gLaaaaaFa9gEaaaB9gGaaB9gFaFaEQSBBFBFFGEGEGIILF9wFFFLEFBFKNFaFCx/aFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBG8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBIy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBKi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBNn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBcI9z9iqlBMc/j9JSIBTEM9+FLa8jUUUUBCTlRBCBRFEXCBRGCBREEXABCNJAGJAECUaAFAGrCFZHIy86BBAEAIJREAGCFJHGCN9HQBMAFCx+YUUBJAE86BBAFCEWCxkUUBJAB8pEN83EBAFCFJHFCUG9HQBMMkRIbaG97FaK978jUUUUBCU/KBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAG/8cBBCUoBAG9uC/wgBZHKCUGAKCUG9JyRNAECFJRKCBRVGXEXAVAF9PQFANAFAVlAVANJAF9JyRcGXGXAG9FQBAcCbJHIC9wZHMCE9sRSAMCFWRQAICIrCEJCGrRfCBRbEXAKRTCBRtGXEXGXAOATlAf9PQBCBRKSLMALCU/CBJAtAM9sJRmATAfJRKCBREGXAMCoB9JQBAOAKlC/gB9JQBCBRIEXAmAIJREGXGXGXGXGXATAICKrJ2BBHYCEZfIBFGEBMAECBDtDMIBSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMIBAKCTJRKMGXGXGXGXGXAYCGrCEZfIBFGEBMAECBDtDMITSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMITAKCTJRKMGXGXGXGXGXAYCIrCEZfIBFGEBMAECBDtDMIASEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMIAAKCTJRKMGXGXGXGXGXAYCKrfIBFGEBMAECBDtDMI8wSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCIJAnDeBJAYCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCNJAnDeBJAYCx+YUUBJ2BBJRKSFMAEAKDBBBDMI8wAKCTJRKMAICoBJREAICUFJAM9LQFAERIAOAKlC/fB9LQBMMGXAEAM9PQBAECErRIEXGXAOAKlCi9PQBCBRKSOMAmAEJRYGXGXGXGXGXATAECKrJ2BBAICKZrCEZfIBFGEBMAYCBDtDMIBSEMAYAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAYAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAYAKDBBBDMIBAKCTJRKMAICGJRIAECTJHEAM9JQBMMGXAK9FQBAKRTAtCFJHtCI6QGSFMMCBRKSEMGXAM9FQBALCUGJAbJREALAbJDBGBRnCBRYEXAEALCU/CBJAYJHIDBIBHdCFD9tAdCFDbHPD9OD9hD9RHdAIAMJDBIBHiCFD9tAiAPD9OD9hD9RHiDQBTFtGmEYIPLdKeOnH8ZAIAQJDBIBHpCFD9tApAPD9OD9hD9RHpAIASJDBIBHyCFD9tAyAPD9OD9hD9RHyDQBTFtGmEYIPLdKeOnH8cDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGEAnD9uHnDyBjGBAEAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnA8ZA8cDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnAdAiDQNiV8ZcpMyS8cQ8df8eb8fHdApAyDQNiV8ZcpMyS8cQ8df8eb8fHiDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnAdAiDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJREAYCTJHYAM9JQBMMAbCIJHbAG9JQBMMABAVAG9sJALCUGJAcAG9s/8cBBALALCUGJAcCaJAG9sJAG/8cBBMAcCBAKyAVJRVAKQBMC9+RKSFMCBC99AOAKlAGCAAGCA9Ly6yRKMALCU/KBJ8kUUUUBAKMNBT+BUUUBM+KmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUF/8MBALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM/xLGEaK978jUUUUBCAlHE8kUUUUBGXGXAGCI9HQBGXAFC98ZHI9FQBABRGCBRLEXAGAGDBBBHKCiD+rFCiD+sFD/6FHOAKCND+rFCiD+sFD/6FAOD/gFAKCTD+rFCiD+sFD/6FHND/gFD/kFD/lFHVCBDtD+2FHcAOCUUUU94DtHMD9OD9RD/kFHO9DBB/+hDYAOAOD/mFAVAVD/mFANAcANAMD9OD9RD/kFHOAOD/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHcD/kFCgFDtD9OAKCUUU94DtD9OD9QAOAND/mFAcD/kFCND+rFCU/+EDtD9OD9QAVAND/mFAcD/kFCTD+rFCUU/8ODtD9OD9QDMBBAGCTJRGALCIJHLAI9JQBMMAIAF9PQFAEAFCEZHLCGWHGqCBCTAGl/8MBAEABAICGWJHIAG/8cBBGXAL9FQBAEAEDBIBHKCiD+rFCiD+sFD/6FHOAKCND+rFCiD+sFD/6FAOD/gFAKCTD+rFCiD+sFD/6FHND/gFD/kFD/lFHVCBDtD+2FHcAOCUUUU94DtHMD9OD9RD/kFHO9DBB/+hDYAOAOD/mFAVAVD/mFANAcANAMD9OD9RD/kFHOAOD/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHcD/kFCgFDtD9OAKCUUU94DtD9OD9QAOAND/mFAcD/kFCND+rFCU/+EDtD9OD9QAVAND/mFAcD/kFCTD+rFCUU/8ODtD9OD9QDMIBMAIAEAG/8cBBSFMABAFC98ZHGT+HUUUBAGAF9PQBAEAFCEZHICEWHLJCBCAALl/8MBAEABAGCEWJHGAL/8cBBAEAIT+HUUUBAGAEAL/8cBBMAECAJ8kUUUUBM+yEGGaO97GXAF9FQBCBRGEXABCTJHEAEDBBBHICBDtHLCUU98D8cFCUU98D8cEHKD9OABDBBBHOAIDQILKOSQfbPden8c8d8e8fCggFDtD9OD/6FAOAIDQBFGENVcMTtmYi8ZpyHICTD+sFD/6FHND/gFAICTD+rFCTD+sFD/6FHVD/gFD/kFD/lFHI9DB/+g6DYAVAIALD+2FHLAVCUUUU94DtHcD9OD9RD/kFHVAVD/mFAIAID/mFANALANAcD9OD9RD/kFHIAID/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHLD/kFCTD+rFAVAND/mFALD/kFCggEDtD9OD9QHVAIAND/mFALD/kFCaDbCBDnGCBDnECBDnKCBDnOCBDncCBDnMCBDnfCBDnbD9OHIDQNVi8ZcMpySQ8c8dfb8e8fD9QDMBBABAOAKD9OAVAIDQBFTtGEmYILPdKOenD9QDMBBABCAJRBAGCIJHGAF9JQBMMM94FEa8jUUUUBCAlHE8kUUUUBABAFC98ZHIT+JUUUBGXAIAF9PQBAEAFCEZHLCEWHFJCBCAAFl/8MBAEABAICEWJHBAF/8cBBAEALT+JUUUBABAEAF/8cBBMAECAJ8kUUUUBM/hEIGaF97FaL978jUUUUBCTlRGGXAF9FQBCBREEXAGABDBBBHIABCTJHLDBBBHKDQILKOSQfbPden8c8d8e8fHOCTD+sFHNCID+rFDMIBAB9DBBU8/DY9D/zI818/DYANCEDtD9QD/6FD/nFHNAIAKDQBFGENVcMTtmYi8ZpyHICTD+rFCTD+sFD/6FD/mFHKAKD/mFANAICTD+sFD/6FD/mFHVAVD/mFANAOCTD+rFCTD+sFD/6FD/mFHOAOD/mFD/kFD/kFD/lFCBDtD+4FD/jF9DB/+g6DYHND/mF9DBBX9LDYHID/kFCggEDtHcD9OAVAND/mFAID/kFCTD+rFD9QHVAOAND/mFAID/kFCTD+rFAKAND/mFAID/kFAcD9OD9QHNDQBFTtGEmYILPdKOenHID8dBAGDBIBDyB+t+J83EBABCNJAID8dFAGDBIBDyF+t+J83EBALAVANDQNVi8ZcMpySQ8c8dfb8e8fHND8dBAGDBIBDyG+t+J83EBABCiJAND8dFAGDBIBDyE+t+J83EBABCAJRBAECIJHEAF9JQBMMM/3FGEaF978jUUUUBCoBlREGXAGCGrAF9sHIC98ZHL9FQBCBRGABRFEXAFAFDBBBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMBBAFCTJRFAGCIJHGAL9JQBMMGXALAI9PQBAEAICEZHGCGWHFqCBCoBAFl/8MBAEABALCGWJHLAF/8cBBGXAG9FQBAEAEDBIBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMIBMALAEAF/8cBBMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEMMMFBCUNMIT9tBB",$c=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]),qc=new Uint8Array([32,0,65,253,3,1,2,34,4,106,6,5,11,8,7,20,13,33,12,16,128,9,116,64,19,113,127,15,10,21,22,14,255,66,24,54,136,107,18,23,192,26,114,118,132,17,77,101,130,144,27,87,131,44,45,74,156,154,70,167]),eh={0:"",1:"meshopt_decodeFilterOct",2:"meshopt_decodeFilterQuat",3:"meshopt_decodeFilterExp",NONE:"",OCTAHEDRAL:"meshopt_decodeFilterOct",QUATERNION:"meshopt_decodeFilterQuat",EXPONENTIAL:"meshopt_decodeFilterExp"},th={0:"meshopt_decodeVertexBuffer",1:"meshopt_decodeIndexBuffer",2:"meshopt_decodeIndexSequence",ATTRIBUTES:"meshopt_decodeVertexBuffer",TRIANGLES:"meshopt_decodeIndexBuffer",INDICES:"meshopt_decodeIndexSequence"};async function sh(e,t,s,i,r,n="NONE"){const A=await async function(){ih||(ih=async function(){let e=Jc;WebAssembly.validate($c)&&(e=Yc,console.log("Warning: meshopt_decoder is using experimental SIMD support"));const t=await WebAssembly.instantiate(function(e){const t=new Uint8Array(e.length);for(let s=0;s<e.length;++s){const i=e.charCodeAt(s);t[s]=i>96?i-71:i>64?i-65:i>47?i+4:i>46?63:62}let s=0;for(let i=0;i<e.length;++i)t[s++]=t[i]<60?qc[t[i]]:64*(t[i]-60)+t[++i];return t.buffer.slice(0,s)}(e),{});return await t.instance.exports.__wasm_call_ctors(),t.instance}());return ih}();!function(e,t,s,i,r,n,A){const o=e.exports.sbrk,a=i+3&-4,l=o(a*r),c=o(n.length),h=new Uint8Array(e.exports.memory.buffer);h.set(n,c);const u=t(l,i,r,c,n.length);0===u&&A&&A(l,a,r);if(s.set(h.subarray(l,l+i*r)),o(l-o(0)),0!==u)throw new Error(`Malformed buffer data: ${u}`)}(A,A.exports[th[r]],e,t,s,i,A.exports[eh[n||"NONE"]])}let ih;async function rh(e,t){const s=e.getObjectExtension(t,"EXT_meshopt_compression");if(s){const{byteOffset:i=0,byteLength:r=0,byteStride:n,count:A,mode:o,filter:a="NONE",buffer:l}=s,c=e.gltf.buffers[l],h=new Uint8Array(c.arrayBuffer,c.byteOffset+i,r),u=new Uint8Array(e.gltf.buffers[t.buffer].arrayBuffer,t.byteOffset,t.byteLength);await sh(u,A,n,h,o,a),e.removeObjectExtension(t,"EXT_meshopt_compression")}}var nh=Object.freeze({__proto__:null,name:"EXT_meshopt_compression",decode:async function(e,t){const s=new Hl(e);if(!t?.gltf?.decompressMeshes||!t.gltf?.loadBuffers)return;const i=[];for(const t of e.json.bufferViews||[])i.push(rh(s,t));await Promise.all(i),s.removeExtension("EXT_meshopt_compression")}});var Ah=Object.freeze({__proto__:null,name:"EXT_texture_webp",preprocess:function(e,t){const s=new Hl(e);if(!xl("image/webp")){if(s.getRequiredExtensions().includes("EXT_texture_webp"))throw new Error("gltf: Required extension EXT_texture_webp not supported by browser");return}const{json:i}=s;for(const e of i.textures||[]){const t=s.getObjectExtension(e,"EXT_texture_webp");t&&(e.source=t.source),s.removeObjectExtension(e,"EXT_texture_webp")}s.removeExtension("EXT_texture_webp")}});var oh=Object.freeze({__proto__:null,name:"KHR_texture_basisu",preprocess:function(e,t){const s=new Hl(e),{json:i}=s;for(const e of i.textures||[]){const t=s.getObjectExtension(e,"KHR_texture_basisu");t&&(e.source=t.source,s.removeObjectExtension(e,"KHR_texture_basisu"))}s.removeExtension("KHR_texture_basisu")}});const ah={dataType:null,batchType:null,name:"Draco",id:"draco",module:"draco",version:"4.3.3",worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:{draco:{decoderType:"object"==typeof WebAssembly?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}}};function lh(e,t,s){return ol(e,t,s?ch(s.metadata):void 0)}function ch(e){const t={};for(const s in e)t[`${s}.string`]=JSON.stringify(e[s]);return t}const hh={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},uh={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array};class dh{draco;decoder;metadataQuerier;constructor(e){this.draco=e,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}destroy(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}parseSync(e,t={}){const s=new this.draco.DecoderBuffer;s.Init(new Int8Array(e),e.byteLength),this._disableAttributeTransforms(t);const i=this.decoder.GetEncodedGeometryType(s),r=i===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let e;switch(i){case this.draco.TRIANGULAR_MESH:e=this.decoder.DecodeBufferToMesh(s,r);break;case this.draco.POINT_CLOUD:e=this.decoder.DecodeBufferToPointCloud(s,r);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!e.ok()||!r.ptr){const t=`DRACO decompression failed: ${e.error_msg()}`;throw new Error(t)}const n=this._getDracoLoaderData(r,i,t),A=this._getMeshData(r,n,t),o=nl(A.attributes),a=function(e,t,s){const i=ch(t.metadata),r=[],n=function(e){const t={};for(const s in e){const i=e[s];t[i.name||"undefined"]=i}return t}(t.attributes);for(const t in e){const s=lh(t,e[t],n[t]);r.push(s)}if(s){const e=lh("indices",s);r.push(e)}return{fields:r,metadata:i}}(A.attributes,n,A.indices);return{loader:"draco",loaderData:n,header:{vertexCount:r.num_points(),boundingBox:o},...A,schema:a}}finally{this.draco.destroy(s),r&&this.draco.destroy(r)}}_getDracoLoaderData(e,t,s){const i=this._getTopLevelMetadata(e),r=this._getDracoAttributes(e,s);return{geometry_type:t,num_attributes:e.num_attributes(),num_points:e.num_points(),num_faces:e instanceof this.draco.Mesh?e.num_faces():0,metadata:i,attributes:r}}_getDracoAttributes(e,t){const s={};for(let i=0;i<e.num_attributes();i++){const r=this.decoder.GetAttribute(e,i),n=this._getAttributeMetadata(e,i);s[r.unique_id()]={unique_id:r.unique_id(),attribute_type:r.attribute_type(),data_type:r.data_type(),num_components:r.num_components(),byte_offset:r.byte_offset(),byte_stride:r.byte_stride(),normalized:r.normalized(),attribute_index:i,metadata:n};const A=this._getQuantizationTransform(r,t);A&&(s[r.unique_id()].quantization_transform=A);const o=this._getOctahedronTransform(r,t);o&&(s[r.unique_id()].octahedron_transform=o)}return s}_getMeshData(e,t,s){const i=this._getMeshAttributes(t,e,s);if(!i.POSITION)throw new Error("DRACO: No position attribute found.");return e instanceof this.draco.Mesh?"triangle-strip"===s.topology?{topology:"triangle-strip",mode:4,attributes:i,indices:{value:this._getTriangleStripIndices(e),size:1}}:{topology:"triangle-list",mode:5,attributes:i,indices:{value:this._getTriangleListIndices(e),size:1}}:{topology:"point-list",mode:0,attributes:i}}_getMeshAttributes(e,t,s){const i={};for(const r of Object.values(e.attributes)){const e=this._deduceAttributeName(r,s);r.name=e;const n=this._getAttributeValues(t,r);if(n){const{value:t,size:s}=n;i[e]={value:t,size:s,byteOffset:r.byte_offset,byteStride:r.byte_stride,normalized:r.normalized}}}return i}_getTriangleListIndices(e){const t=3*e.num_faces(),s=4*t,i=this.draco._malloc(s);try{return this.decoder.GetTrianglesUInt32Array(e,s,i),new Uint32Array(this.draco.HEAPF32.buffer,i,t).slice()}finally{this.draco._free(i)}}_getTriangleStripIndices(e){const t=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(e,t),function(e){const t=e.size(),s=new Int32Array(t);for(let i=0;i<t;i++)s[i]=e.GetValue(i);return s}(t)}finally{this.draco.destroy(t)}}_getAttributeValues(e,t){const s=uh[t.data_type];if(!s)return console.warn(`DRACO: Unsupported attribute type ${t.data_type}`),null;const i=t.num_components,r=e.num_points()*i,n=r*s.BYTES_PER_ELEMENT,A=function(e,t){switch(t){case Float32Array:return e.DT_FLOAT32;case Int8Array:return e.DT_INT8;case Int16Array:return e.DT_INT16;case Int32Array:return e.DT_INT32;case Uint8Array:return e.DT_UINT8;case Uint16Array:return e.DT_UINT16;case Uint32Array:return e.DT_UINT32;default:return e.DT_INVALID}}(this.draco,s);let o;const a=this.draco._malloc(n);try{const i=this.decoder.GetAttribute(e,t.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(e,i,A,n,a),o=new s(this.draco.HEAPF32.buffer,a,r).slice()}finally{this.draco._free(a)}return{value:o,size:i}}_deduceAttributeName(e,t){const s=e.unique_id;for(const[e,i]of Object.entries(t.extraAttributes||{}))if(i===s)return e;const i=e.attribute_type;for(const e in hh){if(this.draco[e]===i)return hh[e]}const r=t.attributeNameEntry||"name";return e.metadata[r]?e.metadata[r].string:`CUSTOM_ATTRIBUTE_${s}`}_getTopLevelMetadata(e){const t=this.decoder.GetMetadata(e);return this._getDracoMetadata(t)}_getAttributeMetadata(e,t){const s=this.decoder.GetAttributeMetadata(e,t);return this._getDracoMetadata(s)}_getDracoMetadata(e){if(!e||!e.ptr)return{};const t={},s=this.metadataQuerier.NumEntries(e);for(let i=0;i<s;i++){const s=this.metadataQuerier.GetEntryName(e,i);t[s]=this._getDracoMetadataField(e,s)}return t}_getDracoMetadataField(e,t){const s=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(e,t,s);const i=function(e){const t=e.size(),s=new Int32Array(t);for(let i=0;i<t;i++)s[i]=e.GetValue(i);return s}(s);return{int:this.metadataQuerier.GetIntEntry(e,t),string:this.metadataQuerier.GetStringEntry(e,t),double:this.metadataQuerier.GetDoubleEntry(e,t),intArray:i}}finally{this.draco.destroy(s)}}_disableAttributeTransforms(e){const{quantizedAttributes:t=[],octahedronAttributes:s=[]}=e,i=[...t,...s];for(const e of i)this.decoder.SkipAttributeTransform(this.draco[e])}_getQuantizationTransform(e,t){const{quantizedAttributes:s=[]}=t,i=e.attribute_type();if(s.map((e=>this.decoder[e])).includes(i)){const t=new this.draco.AttributeQuantizationTransform;try{if(t.InitFromAttribute(e))return{quantization_bits:t.quantization_bits(),range:t.range(),min_values:new Float32Array([1,2,3]).map((e=>t.min_value(e)))}}finally{this.draco.destroy(t)}}return null}_getOctahedronTransform(e,t){const{octahedronAttributes:s=[]}=t,i=e.attribute_type();if(s.map((e=>this.decoder[e])).includes(i)){const t=new this.draco.AttributeQuantizationTransform;try{if(t.InitFromAttribute(e))return{quantization_bits:t.quantization_bits()}}finally{this.draco.destroy(t)}}return null}}const ph="https://www.gstatic.com/draco/versioned/decoders/1.5.6",fh="draco_wasm_wrapper.js",gh="draco_decoder.wasm",mh="draco_decoder.js",_h="draco_encoder.js",bh={[fh]:`${ph}/${fh}`,[gh]:`${ph}/${gh}`,[mh]:`${ph}/${mh}`,[_h]:`https://raw.githubusercontent.com/google/draco/1.4.1/javascript/${_h}`};let yh;async function Bh(e){const t=e.modules||{};return t.draco3d?yh||=t.draco3d.createDecoderModule({}).then((e=>({draco:e}))):yh||=async function(e){let t,s;if("js"===(e.draco&&e.draco.decoderType))t=await qo(bh[mh],"draco",e,mh);else[t,s]=await Promise.all([await qo(bh[fh],"draco",e,fh),await qo(bh[gh],"draco",e,gh)]);return t=t||globalThis.DracoDecoderModule,await function(e,t){const s={};t&&(s.wasmBinary=t);return new Promise((t=>{e({...s,onModuleLoaded:e=>t({draco:e})})}))}(t,s)}(e),await yh}const wh={...ah,parse:async function(e,t){const{draco:s}=await Bh(t),i=new dh(s);try{return i.parseSync(e,t?.draco)}finally{i.destroy()}}};function vh(e){const{buffer:t,size:s,count:i}=function(e){let t=e,s=1,i=0;e&&e.value&&(t=e.value,s=e.size||1);t&&(ArrayBuffer.isView(t)||(t=function(e,t,s=!1){if(!e)return null;if(Array.isArray(e))return new t(e);if(s&&!(e instanceof t))return new t(e);return e}(t,Float32Array)),i=t.length/s);return{buffer:t,size:s,count:i}}(e);return{value:t,size:s,byteOffset:0,count:i,type:Ol(s),componentType:Vl(t)}}async function Ch(e,t,s,i){const r=e.getObjectExtension(t,"KHR_draco_mesh_compression");if(!r)return;const n=e.getTypedArrayForBufferView(r.bufferView),A=na(n.buffer,n.byteOffset),o={...s};delete o["3d-tiles"];const a=await ao(A,wh,o,i),l=function(e){const t={};for(const s in e){const i=e[s];if("indices"!==s){const e=vh(i);t[s]=e}}return t}(a.attributes);for(const[s,i]of Object.entries(l))if(s in t.attributes){const r=t.attributes[s],n=e.getAccessor(r);n?.min&&n?.max&&(i.min=n.min,i.max=n.max)}t.attributes=l,a.indices&&(t.indices=vh(a.indices)),e.removeObjectExtension(t,"KHR_draco_mesh_compression"),function(e){if(!e.attributes&&Object.keys(e.attributes).length>0)throw new Error("glTF: Empty primitive detected: Draco decompression failure?")}(t)}function Mh(e,t,s=4,i,r){if(!i.DracoWriter)throw new Error("options.gltf.DracoWriter not provided");const n=i.DracoWriter.encodeSync({attributes:e}),A=r?.parseSync?.({attributes:e}),o=i._addFauxAttributes(A.attributes);return{primitives:[{attributes:o,mode:s,extensions:{KHR_draco_mesh_compression:{bufferView:i.addBufferView(n),attributes:o}}}]}}function*Eh(e){for(const t of e.json.meshes||[])for(const e of t.primitives)yield e}var Fh=Object.freeze({__proto__:null,name:"KHR_draco_mesh_compression",preprocess:function(e,t,s){const i=new Hl(e);for(const e of Eh(i))i.getObjectExtension(e,"KHR_draco_mesh_compression")},decode:async function(e,t,s){if(!t?.gltf?.decompressMeshes)return;const i=new Hl(e),r=[];for(const e of Eh(i))i.getObjectExtension(e,"KHR_draco_mesh_compression")&&r.push(Ch(i,e,t,s));await Promise.all(r),i.removeExtension("KHR_draco_mesh_compression")},encode:function(e,t={}){const s=new Hl(e);for(const e of s.json.meshes||[])Mh(e),s.addRequiredExtension("KHR_draco_mesh_compression")}});globalThis.mathgl=globalThis.mathgl||{config:{EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1}};const xh=globalThis.mathgl.config;function Uh(e,{precision:t=xh.precision}={}){return e=function(e){return Math.round(e/xh.EPSILON)*xh.EPSILON}(e),`${parseFloat(e.toPrecision(t))}`}function Ih(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Th(e,t,s){const i=xh.EPSILON;s&&(xh.EPSILON=s);try{if(e===t)return!0;if(Ih(e)&&Ih(t)){if(e.length!==t.length)return!1;for(let s=0;s<e.length;++s)if(!Th(e[s],t[s]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):"number"==typeof e&&"number"==typeof t&&Math.abs(e-t)<=xh.EPSILON*Math.max(1,Math.abs(e),Math.abs(t))}finally{xh.EPSILON=i}}class Ph extends Array{clone(){return(new this.constructor).copy(this)}fromArray(e,t=0){for(let s=0;s<this.ELEMENTS;++s)this[s]=e[s+t];return this.check()}toArray(e=[],t=0){for(let s=0;s<this.ELEMENTS;++s)e[t+s]=this[s];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:Ih(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(xh)}formatString(e){let t="";for(let s=0;s<this.ELEMENTS;++s)t+=(s>0?", ":"")+Uh(this[s],e);return`${e.printTypes?this.constructor.name:""}[${t}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(!Th(this[t],e[t]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(this[t]!==e[t])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,t,s){if(void 0===s)return this.lerp(this,e,t);for(let i=0;i<this.ELEMENTS;++i){const r=e[i],n="number"==typeof t?t:t[i];this[i]=r+s*(n-r)}return this.check()}min(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.min(e[t],this[t]);return this.check()}max(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.max(e[t],this[t]);return this.check()}clamp(e,t){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],e[s]),t[s]);return this.check()}add(...e){for(const t of e)for(let e=0;e<this.ELEMENTS;++e)this[e]+=t[e];return this.check()}subtract(...e){for(const t of e)for(let e=0;e<this.ELEMENTS;++e)this[e]-=t[e];return this.check()}scale(e){if("number"==typeof e)for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;else for(let t=0;t<this.ELEMENTS&&t<e.length;++t)this[t]*=e[t];return this.check()}multiplyByScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}check(){if(xh.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let t=0;t<this.ELEMENTS;++t)e=e&&Number.isFinite(this[t]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=e;return this.check()}addScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,t){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],e),t);return this.check()}get elements(){return this}}function Sh(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function Dh(e,t,s=""){if(xh.debug&&!function(e,t){if(e.length!==t)return!1;for(let t=0;t<e.length;++t)if(!Number.isFinite(e[t]))return!1;return!0}(e,t))throw new Error(`math.gl: ${s} some fields set to invalid numbers'`);return e}function kh(e,t){if(!e)throw new Error(`math.gl assertion ${t}`)}class Qh extends Ph{get x(){return this[0]}set x(e){this[0]=Sh(e)}get y(){return this[1]}set y(e){this[1]=Sh(e)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let e=0;for(let t=0;t<this.ELEMENTS;++t)e+=this[t]*this[t];return e}magnitudeSquared(){return this.lengthSquared()}distance(e){return Math.sqrt(this.distanceSquared(e))}distanceSquared(e){let t=0;for(let s=0;s<this.ELEMENTS;++s){const i=this[s]-e[s];t+=i*i}return Sh(t)}dot(e){let t=0;for(let s=0;s<this.ELEMENTS;++s)t+=this[s]*e[s];return Sh(t)}normalize(){const e=this.magnitude();if(0!==e)for(let t=0;t<this.ELEMENTS;++t)this[t]/=e;return this.check()}multiply(...e){for(const t of e)for(let e=0;e<this.ELEMENTS;++e)this[e]*=t[e];return this.check()}divide(...e){for(const t of e)for(let e=0;e<this.ELEMENTS;++e)this[e]/=t[e];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(e){return this.distance(e)}distanceToSquared(e){return this.distanceSquared(e)}getComponent(e){return kh(e>=0&&e<this.ELEMENTS,"index is out of range"),Sh(this[e])}setComponent(e,t){return kh(e>=0&&e<this.ELEMENTS,"index is out of range"),this[e]=t,this.check()}addVectors(e,t){return this.copy(e).add(t)}subVectors(e,t){return this.copy(e).subtract(t)}multiplyVectors(e,t){return this.copy(e).multiply(t)}addScaledVector(e,t){return this.add(new this.constructor(e).multiplyScalar(t))}}let Rh="undefined"!=typeof Float32Array?Float32Array:Array;function Oh(e,t,s){const i=t[0],r=t[1],n=t[2];return e[0]=i*s[0]+r*s[3]+n*s[6],e[1]=i*s[1]+r*s[4]+n*s[7],e[2]=i*s[2]+r*s[5]+n*s[8],e}!function(){const e=function(){const e=new Rh(2);return Rh!=Float32Array&&(e[0]=0,e[1]=0),e}()}(),function(){const e=function(){const e=new Rh(3);return Rh!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}()}();const Vh=[0,0,0];let Lh;class Hh extends Qh{static get ZERO(){return Lh||(Lh=new Hh(0,0,0),Object.freeze(Lh)),Lh}constructor(e=0,t=0,s=0){super(-0,-0,-0),1===arguments.length&&Ih(e)?this.copy(e):(xh.debug&&(Sh(e),Sh(t),Sh(s)),this[0]=e,this[1]=t,this[2]=s)}set(e,t,s){return this[0]=e,this[1]=t,this[2]=s,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this.check()}fromObject(e){return xh.debug&&(Sh(e.x),Sh(e.y),Sh(e.z)),this[0]=e.x,this[1]=e.y,this[2]=e.z,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e.z=this[2],e}get ELEMENTS(){return 3}get z(){return this[2]}set z(e){this[2]=Sh(e)}angle(e){return function(e,t){const s=e[0],i=e[1],r=e[2],n=t[0],A=t[1],o=t[2],a=Math.sqrt((s*s+i*i+r*r)*(n*n+A*A+o*o)),l=a&&function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}(e,t)/a;return Math.acos(Math.min(Math.max(l,-1),1))}(this,e)}cross(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2],A=s[0],o=s[1],a=s[2];e[0]=r*a-n*o,e[1]=n*A-i*a,e[2]=i*o-r*A}(this,this,e),this.check()}rotateX({radians:e,origin:t=Vh}){return function(e,t,s,i){const r=[],n=[];r[0]=t[0]-s[0],r[1]=t[1]-s[1],r[2]=t[2]-s[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),e[0]=n[0]+s[0],e[1]=n[1]+s[1],e[2]=n[2]+s[2]}(this,this,t,e),this.check()}rotateY({radians:e,origin:t=Vh}){return function(e,t,s,i){const r=[],n=[];r[0]=t[0]-s[0],r[1]=t[1]-s[1],r[2]=t[2]-s[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),e[0]=n[0]+s[0],e[1]=n[1]+s[1],e[2]=n[2]+s[2]}(this,this,t,e),this.check()}rotateZ({radians:e,origin:t=Vh}){return function(e,t,s,i){const r=[],n=[];r[0]=t[0]-s[0],r[1]=t[1]-s[1],r[2]=t[2]-s[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],e[0]=n[0]+s[0],e[1]=n[1]+s[1],e[2]=n[2]+s[2]}(this,this,t,e),this.check()}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2];let A=s[3]*i+s[7]*r+s[11]*n+s[15];A=A||1,e[0]=(s[0]*i+s[4]*r+s[8]*n+s[12])/A,e[1]=(s[1]*i+s[5]*r+s[9]*n+s[13])/A,e[2]=(s[2]*i+s[6]*r+s[10]*n+s[14])/A}(this,this,e),this.check()}transformAsVector(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2],A=s[3]*i+s[7]*r+s[11]*n||1;e[0]=(s[0]*i+s[4]*r+s[8]*n)/A,e[1]=(s[1]*i+s[5]*r+s[9]*n)/A,e[2]=(s[2]*i+s[6]*r+s[10]*n)/A}(this,this,e),this.check()}transformByMatrix3(e){return Oh(this,this,e),this.check()}transformByMatrix2(e){return function(e,t,s){const i=t[0],r=t[1];e[0]=s[0]*i+s[2]*r,e[1]=s[1]*i+s[3]*r,e[2]=t[2]}(this,this,e),this.check()}transformByQuaternion(e){return function(e,t,s){const i=s[0],r=s[1],n=s[2],A=s[3],o=t[0],a=t[1],l=t[2];let c=r*l-n*a,h=n*o-i*l,u=i*a-r*o,d=r*u-n*h,p=n*c-i*u,f=i*h-r*c;const g=2*A;c*=g,h*=g,u*=g,d*=2,p*=2,f*=2,e[0]=o+c+d,e[1]=a+h+p,e[2]=l+u+f}(this,this,e),this.check()}}class Nh extends Ph{toString(){let e="[";if(xh.printRowMajor){e+="row-major:";for(let t=0;t<this.RANK;++t)for(let s=0;s<this.RANK;++s)e+=` ${this[s*this.RANK+t]}`}else{e+="column-major:";for(let t=0;t<this.ELEMENTS;++t)e+=` ${this[t]}`}return e+="]",e}getElementIndex(e,t){return t*this.RANK+e}getElement(e,t){return this[t*this.RANK+e]}setElement(e,t,s){return this[t*this.RANK+e]=Sh(s),this}getColumn(e,t=new Array(this.RANK).fill(-0)){const s=e*this.RANK;for(let e=0;e<this.RANK;++e)t[e]=this[s+e];return t}setColumn(e,t){const s=e*this.RANK;for(let e=0;e<this.RANK;++e)this[s+e]=t[e];return this}}function Gh(e,t,s){const i=t[0],r=t[1],n=t[2],A=t[3],o=t[4],a=t[5],l=t[6],c=t[7],h=t[8],u=s[0],d=s[1],p=s[2],f=s[3],g=s[4],m=s[5],_=s[6],b=s[7],y=s[8];return e[0]=u*i+d*A+p*l,e[1]=u*r+d*o+p*c,e[2]=u*n+d*a+p*h,e[3]=f*i+g*A+m*l,e[4]=f*r+g*o+m*c,e[5]=f*n+g*a+m*h,e[6]=_*i+b*A+y*l,e[7]=_*r+b*o+y*c,e[8]=_*n+b*a+y*h,e}function jh(e,t,s){const i=s[0],r=s[1];return e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=r*t[3],e[4]=r*t[4],e[5]=r*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}var zh;!function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL1ROW0=3]="COL1ROW0",e[e.COL1ROW1=4]="COL1ROW1",e[e.COL1ROW2=5]="COL1ROW2",e[e.COL2ROW0=6]="COL2ROW0",e[e.COL2ROW1=7]="COL2ROW1",e[e.COL2ROW2=8]="COL2ROW2"}(zh||(zh={}));const Wh=Object.freeze([1,0,0,0,1,0,0,0,1]);class Xh extends Nh{static get IDENTITY(){return function(){Zh||(Zh=new Xh,Object.freeze(Zh));return Zh}()}static get ZERO(){return function(){Kh||(Kh=new Xh([0,0,0,0,0,0,0,0,0]),Object.freeze(Kh));return Kh}()}get ELEMENTS(){return 9}get RANK(){return 3}get INDICES(){return zh}constructor(e,...t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0),1===arguments.length&&Array.isArray(e)?this.copy(e):t.length>0?this.copy([e,...t]):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this.check()}identity(){return this.copy(Wh)}fromObject(e){return this.check()}fromQuaternion(e){return function(e,t){const s=t[0],i=t[1],r=t[2],n=t[3],A=s+s,o=i+i,a=r+r,l=s*A,c=i*A,h=i*o,u=r*A,d=r*o,p=r*a,f=n*A,g=n*o,m=n*a;e[0]=1-h-p,e[3]=c-m,e[6]=u+g,e[1]=c+m,e[4]=1-l-p,e[7]=d-f,e[2]=u-g,e[5]=d+f,e[8]=1-l-h}(this,e),this.check()}set(e,t,s,i,r,n,A,o,a){return this[0]=e,this[1]=t,this[2]=s,this[3]=i,this[4]=r,this[5]=n,this[6]=A,this[7]=o,this[8]=a,this.check()}setRowMajor(e,t,s,i,r,n,A,o,a){return this[0]=e,this[1]=i,this[2]=A,this[3]=t,this[4]=r,this[5]=o,this[6]=s,this[7]=n,this[8]=a,this.check()}determinant(){return function(e){const t=e[0],s=e[1],i=e[2],r=e[3],n=e[4],A=e[5],o=e[6],a=e[7],l=e[8];return t*(l*n-A*a)+s*(-l*r+A*o)+i*(a*r-n*o)}(this)}transpose(){return function(e,t){if(e===t){const s=t[1],i=t[2],r=t[5];e[1]=t[3],e[2]=t[6],e[3]=s,e[5]=t[7],e[6]=i,e[7]=r}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8]}(this,this),this.check()}invert(){return function(e,t){const s=t[0],i=t[1],r=t[2],n=t[3],A=t[4],o=t[5],a=t[6],l=t[7],c=t[8],h=c*A-o*l,u=-c*n+o*a,d=l*n-A*a;let p=s*h+i*u+r*d;p&&(p=1/p,e[0]=h*p,e[1]=(-c*i+r*l)*p,e[2]=(o*i-r*A)*p,e[3]=u*p,e[4]=(c*s-r*a)*p,e[5]=(-o*s+r*n)*p,e[6]=d*p,e[7]=(-l*s+i*a)*p,e[8]=(A*s-i*n)*p)}(this,this),this.check()}multiplyLeft(e){return Gh(this,e,this),this.check()}multiplyRight(e){return Gh(this,this,e),this.check()}rotate(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2],A=t[3],o=t[4],a=t[5],l=t[6],c=t[7],h=t[8],u=Math.sin(s),d=Math.cos(s);e[0]=d*i+u*A,e[1]=d*r+u*o,e[2]=d*n+u*a,e[3]=d*A-u*i,e[4]=d*o-u*r,e[5]=d*a-u*n,e[6]=l,e[7]=c,e[8]=h}(this,this,e),this.check()}scale(e){return Array.isArray(e)?jh(this,this,e):jh(this,this,[e,e]),this.check()}translate(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2],A=t[3],o=t[4],a=t[5],l=t[6],c=t[7],h=t[8],u=s[0],d=s[1];e[0]=i,e[1]=r,e[2]=n,e[3]=A,e[4]=o,e[5]=a,e[6]=u*i+d*A+l,e[7]=u*r+d*o+c,e[8]=u*n+d*a+h}(this,this,e),this.check()}transform(e,t){let s;switch(e.length){case 2:s=function(e,t,s){const i=t[0],r=t[1];return e[0]=s[0]*i+s[3]*r+s[6],e[1]=s[1]*i+s[4]*r+s[7],e}(t||[-0,-0],e,this);break;case 3:s=Oh(t||[-0,-0,-0],e,this);break;case 4:s=function(e,t,s){const i=t[0],r=t[1],n=t[2];return e[0]=s[0]*i+s[3]*r+s[6]*n,e[1]=s[1]*i+s[4]*r+s[7]*n,e[2]=s[2]*i+s[5]*r+s[8]*n,e[3]=t[3],e}(t||[-0,-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Dh(s,e.length),s}transformVector(e,t){return this.transform(e,t)}transformVector2(e,t){return this.transform(e,t)}transformVector3(e,t){return this.transform(e,t)}}let Kh,Zh=null;const Jh=new Hh,Yh=new Xh,$h=new Xh;function qh(e,t){const s=t.json.materials?.[e],i=[s?.pbrMetallicRoughness?.baseColorTexture,s?.emissiveTexture,s?.normalTexture,s?.occlusionTexture,s?.pbrMetallicRoughness?.metallicRoughnessTexture],r=[];for(const s of i)s&&s?.extensions?.KHR_texture_transform&&eu(t,e,s,r)}function eu(e,t,s,i){const r=function(e,t){const s=e.extensions?.KHR_texture_transform,{texCoord:i=0}=e,{texCoord:r=i}=s;if(-1===t.findIndex((([e,t])=>e===i&&t===r))){const n=function(e){const{offset:t=[0,0],rotation:s=0,scale:i=[1,1]}=e,r=(new Xh).set(1,0,0,0,1,0,t[0],t[1],1),n=Yh.set(Math.cos(s),Math.sin(s),0,-Math.sin(s),Math.cos(s),0,0,0,1),A=$h.set(i[0],0,0,0,i[1],0,0,0,1);return r.multiplyRight(n).multiplyRight(A)}(s);return i!==r&&(e.texCoord=r),t.push([i,r]),{originalTexCoord:i,texCoord:r,matrix:n}}return null}(s,i);if(!r)return;const n=e.json.meshes||[];for(const s of n)for(const i of s.primitives){const s=i.material;Number.isFinite(s)&&t===s&&tu(e,i,r)}}function tu(e,t,s){const{originalTexCoord:i,texCoord:r,matrix:n}=s,A=t.attributes[`TEXCOORD_${i}`];if(Number.isFinite(A)){const s=e.json.accessors?.[A];if(s&&s.bufferView){const A=e.json.bufferViews?.[s.bufferView];if(A){const{arrayBuffer:o,byteOffset:a}=e.buffers[A.buffer],l=(a||0)+(s.byteOffset||0)+(A.byteOffset||0),{ArrayType:c,length:h}=Ll(s,A),u=Tl[s.componentType],d=Il[s.type],p=A.byteStride||u*d,f=new Float32Array(h);for(let e=0;e<s.count;e++){const t=new c(o,l+e*p,2);Jh.set(t[0],t[1],1),Jh.transformByMatrix3(n),f.set([Jh[0],Jh[1]],e*d)}i===r?function(e,t,s,i){e.componentType=5126,s.push({arrayBuffer:i.buffer,byteOffset:0,byteLength:i.buffer.byteLength}),t.buffer=s.length-1,t.byteLength=i.buffer.byteLength,t.byteOffset=0,delete t.byteStride}(s,A,e.buffers,f):function(e,t,s,i,r){i.buffers.push({arrayBuffer:r.buffer,byteOffset:0,byteLength:r.buffer.byteLength});const n=i.json.bufferViews;if(!n)return;n.push({buffer:i.buffers.length-1,byteLength:r.buffer.byteLength,byteOffset:0});const A=i.json.accessors;if(!A)return;A.push({bufferView:n?.length-1,byteOffset:0,componentType:5126,count:t.count,type:"VEC2"}),s.attributes[`TEXCOORD_${e}`]=A.length-1}(r,s,t,e,f)}}}}var su=Object.freeze({__proto__:null,name:"KHR_texture_transform",decode:async function(e,t){if(!new Hl(e).hasExtension("KHR_texture_transform")||!t.gltf?.loadBuffers)return;const s=e.json.materials||[];for(let t=0;t<s.length;t++)qh(t,e)}});function iu(e,t){const s=Object.assign({},e.values);return Object.keys(e.uniforms||{}).forEach((t=>{e.uniforms[t].value&&!(t in s)&&(s[t]=e.uniforms[t].value)})),Object.keys(s).forEach((e=>{"object"==typeof s[e]&&void 0!==s[e].index&&(s[e].texture=t.getTexture(s[e].index))})),s}const ru=[fc,ic,nh,Ah,oh,Fh,Object.freeze({__proto__:null,name:"KHR_lights_punctual",decode:async function(e){const t=new Hl(e),{json:s}=t,i=t.getExtension("KHR_lights_punctual");i&&(t.json.lights=i.lights,t.removeExtension("KHR_lights_punctual"));for(const e of s.nodes||[]){const s=t.getObjectExtension(e,"KHR_lights_punctual");s&&(e.light=s.light),t.removeObjectExtension(e,"KHR_lights_punctual")}},encode:async function(e){const t=new Hl(e),{json:s}=t;if(s.lights){const e=t.addExtension("KHR_lights_punctual");Ul(!e.lights),e.lights=s.lights,delete s.lights}if(t.json.lights){for(const e of t.json.lights){const s=e.node;t.addObjectExtension(s,"KHR_lights_punctual",e)}delete t.json.lights}}}),Object.freeze({__proto__:null,name:"KHR_materials_unlit",decode:async function(e){const t=new Hl(e),{json:s}=t;for(const e of s.materials||[]){e.extensions&&e.extensions.KHR_materials_unlit&&(e.unlit=!0),t.removeObjectExtension(e,"KHR_materials_unlit")}t.removeExtension("KHR_materials_unlit")},encode:function(e){const t=new Hl(e),{json:s}=t;if(t.materials)for(const e of s.materials||[])e.unlit&&(delete e.unlit,t.addObjectExtension(e,"KHR_materials_unlit",{}),t.addExtension("KHR_materials_unlit"))}}),Object.freeze({__proto__:null,name:"KHR_techniques_webgl",decode:async function(e){const t=new Hl(e),{json:s}=t,i=t.getExtension("KHR_techniques_webgl");if(i){const e=function(e,t){const{programs:s=[],shaders:i=[],techniques:r=[]}=e,n=new TextDecoder;return i.forEach((e=>{if(!Number.isFinite(e.bufferView))throw new Error("KHR_techniques_webgl: no shader code");e.code=n.decode(t.getTypedArrayForBufferView(e.bufferView))})),s.forEach((e=>{e.fragmentShader=i[e.fragmentShader],e.vertexShader=i[e.vertexShader]})),r.forEach((e=>{e.program=s[e.program]})),r}(i,t);for(const i of s.materials||[]){const s=t.getObjectExtension(i,"KHR_techniques_webgl");s&&(i.technique=Object.assign({},s,e[s.technique]),i.technique.values=iu(i.technique,t)),t.removeObjectExtension(i,"KHR_techniques_webgl")}t.removeExtension("KHR_techniques_webgl")}},encode:async function(e,t){}}),su,vc];function nu(e,t){const s=t?.gltf?.excludeExtensions||{};return!(e in s&&!s[e])}const Au={accessors:"accessor",animations:"animation",buffers:"buffer",bufferViews:"bufferView",images:"image",materials:"material",meshes:"mesh",nodes:"node",samplers:"sampler",scenes:"scene",skins:"skin",textures:"texture"},ou={accessor:"accessors",animations:"animation",buffer:"buffers",bufferView:"bufferViews",image:"images",material:"materials",mesh:"meshes",node:"nodes",sampler:"samplers",scene:"scenes",skin:"skins",texture:"textures"};class au{idToIndexMap={animations:{},accessors:{},buffers:{},bufferViews:{},images:{},materials:{},meshes:{},nodes:{},samplers:{},scenes:{},skins:{},textures:{}};json;normalize(e,t){this.json=e.json;const s=e.json;switch(s.asset&&s.asset.version){case"2.0":return;case void 0:case"1.0":break;default:return void console.warn(`glTF: Unknown version ${s.asset.version}`)}if(!t.normalize)throw new Error("glTF v1 is not supported.");console.warn("Converting glTF v1 to glTF v2 format. This is experimental and may fail."),this._addAsset(s),this._convertTopLevelObjectsToArrays(s),function(e){const t=new Hl(e),{json:s}=t;for(const e of s.images||[]){const s=t.getObjectExtension(e,"KHR_binary_glTF");s&&Object.assign(e,s),t.removeObjectExtension(e,"KHR_binary_glTF")}s.buffers&&s.buffers[0]&&delete s.buffers[0].uri,t.removeExtension("KHR_binary_glTF")}(e),this._convertObjectIdsToArrayIndices(s),this._updateObjects(s),this._updateMaterial(s)}_addAsset(e){e.asset=e.asset||{},e.asset.version="2.0",e.asset.generator=e.asset.generator||"Normalized to glTF 2.0 by loaders.gl"}_convertTopLevelObjectsToArrays(e){for(const t in Au)this._convertTopLevelObjectToArray(e,t)}_convertTopLevelObjectToArray(e,t){const s=e[t];if(s&&!Array.isArray(s)){e[t]=[];for(const i in s){const r=s[i];r.id=r.id||i;const n=e[t].length;e[t].push(r),this.idToIndexMap[t][i]=n}}}_convertObjectIdsToArrayIndices(e){for(const t in Au)this._convertIdsToIndices(e,t);"scene"in e&&(e.scene=this._convertIdToIndex(e.scene,"scene"));for(const t of e.textures)this._convertTextureIds(t);for(const t of e.meshes)this._convertMeshIds(t);for(const t of e.nodes)this._convertNodeIds(t);for(const t of e.scenes)this._convertSceneIds(t)}_convertTextureIds(e){e.source&&(e.source=this._convertIdToIndex(e.source,"image"))}_convertMeshIds(e){for(const t of e.primitives){const{attributes:e,indices:s,material:i}=t;for(const t in e)e[t]=this._convertIdToIndex(e[t],"accessor");s&&(t.indices=this._convertIdToIndex(s,"accessor")),i&&(t.material=this._convertIdToIndex(i,"material"))}}_convertNodeIds(e){e.children&&(e.children=e.children.map((e=>this._convertIdToIndex(e,"node")))),e.meshes&&(e.meshes=e.meshes.map((e=>this._convertIdToIndex(e,"mesh"))))}_convertSceneIds(e){e.nodes&&(e.nodes=e.nodes.map((e=>this._convertIdToIndex(e,"node"))))}_convertIdsToIndices(e,t){e[t]||(console.warn(`gltf v1: json doesn't contain attribute ${t}`),e[t]=[]);for(const s of e[t])for(const e in s){const t=s[e],i=this._convertIdToIndex(t,e);s[e]=i}}_convertIdToIndex(e,t){const s=ou[t];if(s in this.idToIndexMap){const i=this.idToIndexMap[s][e];if(!Number.isFinite(i))throw new Error(`gltf v1: failed to resolve ${t} with id ${e}`);return i}return e}_updateObjects(e){for(const e of this.json.buffers)delete e.type}_updateMaterial(e){for(const t of e.materials){t.pbrMetallicRoughness={baseColorFactor:[1,1,1,1],metallicFactor:1,roughnessFactor:1};const s=t.values?.tex||t.values?.texture2d_0||t.values?.diffuseTex,i=e.textures.findIndex((e=>e.id===s));-1!==i&&(t.pbrMetallicRoughness.baseColorTexture={index:i})}}}async function lu(e,t,s=0,i,r){return function(e,t,s,i){i.uri&&(e.baseUri=i.uri);if(t instanceof ArrayBuffer&&!function(e,t=0,s={}){const i=new DataView(e),{magic:r=zc}=s,n=i.getUint32(t,!1);return n===r||n===zc}(t,s,i)){t=(new TextDecoder).decode(t)}if("string"==typeof t)e.json=ia(t);else if(t instanceof ArrayBuffer){const r={};s=Wc(r,t,s,i.glb),Ul("glTF"===r.type,`Invalid GLB magic string ${r.type}`),e._glb=r,e.json=r.json}else Ul(!1,"GLTF: must be ArrayBuffer or string");const r=e.json.buffers||[];if(e.buffers=new Array(r.length).fill(null),e._glb&&e._glb.header.hasBinChunk){const{binChunks:t}=e._glb;e.buffers[0]={arrayBuffer:t[0].arrayBuffer,byteOffset:t[0].byteOffset,byteLength:t[0].byteLength}}const n=e.json.images||[];e.images=new Array(n.length).fill({})}(e,t,s,i),function(e,t={}){(new au).normalize(e,t)}(e,{normalize:i?.gltf?.normalize}),function(e,t={},s){const i=ru.filter((e=>nu(e.name,t)));for(const r of i)r.preprocess?.(e,t,s)}(e,i,r),i?.gltf?.loadBuffers&&e.json.buffers&&await async function(e,t,s){const i=e.json.buffers||[];for(let r=0;r<i.length;++r){const n=i[r];if(n.uri){const{fetch:i}=s;Ul(i);const A=Zc(n.uri,t),o=await(s?.fetch?.(A)),a=await(o?.arrayBuffer?.());e.buffers[r]={arrayBuffer:a,byteOffset:0,byteLength:a.byteLength},delete n.uri}else null===e.buffers[r]&&(e.buffers[r]={arrayBuffer:new ArrayBuffer(n.byteLength),byteOffset:0,byteLength:n.byteLength})}}(e,i,r),i?.gltf?.loadImages&&await async function(e,t,s){const i=function(e){const t=new Set,s=e.json.textures||[];for(const e of s)void 0!==e.source&&t.add(e.source);return Array.from(t).sort()}(e),r=e.json.images||[],n=[];for(const A of i)n.push(cu(e,r[A],A,t,s));return await Promise.all(n)}(e,i,r),await async function(e,t={},s){const i=ru.filter((e=>nu(e.name,t)));for(const r of i)await(r.decode?.(e,t,s))}(e,i,r),e}async function cu(e,t,s,i,r){let n;if(t.uri&&!t.hasOwnProperty("bufferView")){const e=Zc(t.uri,i),{fetch:s}=r,A=await s(e);n=await A.arrayBuffer(),t.bufferView={data:n}}if(Number.isFinite(t.bufferView)){const s=function(e,t,s){const i=e.bufferViews[s];Ul(i);const r=t[i.buffer];Ul(r);const n=(i.byteOffset||0)+r.byteOffset;return new Uint8Array(r.arrayBuffer,n,i.byteLength)}(e.json,e.buffers,t.bufferView);n=na(s.buffer,s.byteOffset,s.byteLength)}Ul(n,"glTF image has no data");let A=await ao(n,[El,jc],{...i,mimeType:t.mimeType,basis:i.basis||{format:Gc()}},r);A&&A[0]&&(A={compressed:!0,mipmaps:!1,width:A[0].width,height:A[0].height,data:A[0]}),e.images=e.images||[],e.images[s]=A}const hu={dataType:null,batchType:null,name:"glTF",id:"gltf",module:"gltf",version:"4.3.3",extensions:["gltf","glb"],mimeTypes:["model/gltf+json","model/gltf-binary"],text:!0,binary:!0,tests:["glTF"],parse:async function(e,t={},s){(t={...hu.options,...t}).gltf={...hu.options.gltf,...t.gltf};const{byteOffset:i=0}=t;return await lu({},e,i,t,s)},options:{gltf:{normalize:!0,loadBuffers:!0,loadImages:!0,decompressMeshes:!0},log:console}};const uu={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},du={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},pu=10240,fu=10241,gu=10242,mu=10243,_u=10497,bu={magFilter:pu,minFilter:fu,wrapS:gu,wrapT:mu},yu={[pu]:9729,[fu]:9986,[gu]:_u,[mu]:_u};class Bu{baseUri="";jsonUnprocessed;json;buffers=[];images=[];postProcess(e,t={}){const{json:s,buffers:i=[],images:r=[]}=e,{baseUri:n=""}=e;return Ul(s),this.baseUri=n,this.buffers=i,this.images=r,this.jsonUnprocessed=s,this.json=this._resolveTree(e.json,t),this.json}_resolveTree(e,t={}){const s={...e};return this.json=s,e.bufferViews&&(s.bufferViews=e.bufferViews.map(((e,t)=>this._resolveBufferView(e,t)))),e.images&&(s.images=e.images.map(((e,t)=>this._resolveImage(e,t)))),e.samplers&&(s.samplers=e.samplers.map(((e,t)=>this._resolveSampler(e,t)))),e.textures&&(s.textures=e.textures.map(((e,t)=>this._resolveTexture(e,t)))),e.accessors&&(s.accessors=e.accessors.map(((e,t)=>this._resolveAccessor(e,t)))),e.materials&&(s.materials=e.materials.map(((e,t)=>this._resolveMaterial(e,t)))),e.meshes&&(s.meshes=e.meshes.map(((e,t)=>this._resolveMesh(e,t)))),e.nodes&&(s.nodes=e.nodes.map(((e,t)=>this._resolveNode(e,t))),s.nodes=s.nodes.map(((e,t)=>this._resolveNodeChildren(e)))),e.skins&&(s.skins=e.skins.map(((e,t)=>this._resolveSkin(e,t)))),e.scenes&&(s.scenes=e.scenes.map(((e,t)=>this._resolveScene(e,t)))),"number"==typeof this.json.scene&&s.scenes&&(s.scene=s.scenes[this.json.scene]),s}getScene(e){return this._get(this.json.scenes,e)}getNode(e){return this._get(this.json.nodes,e)}getSkin(e){return this._get(this.json.skins,e)}getMesh(e){return this._get(this.json.meshes,e)}getMaterial(e){return this._get(this.json.materials,e)}getAccessor(e){return this._get(this.json.accessors,e)}getCamera(e){return this._get(this.json.cameras,e)}getTexture(e){return this._get(this.json.textures,e)}getSampler(e){return this._get(this.json.samplers,e)}getImage(e){return this._get(this.json.images,e)}getBufferView(e){return this._get(this.json.bufferViews,e)}getBuffer(e){return this._get(this.json.buffers,e)}_get(e,t){if("object"==typeof t)return t;const s=e&&e[t];return s||console.warn(`glTF file error: Could not find ${e}[${t}]`),s}_resolveScene(e,t){return{...e,id:e.id||`scene-${t}`,nodes:(e.nodes||[]).map((e=>this.getNode(e)))}}_resolveNode(e,t){const s={...e,id:e?.id||`node-${t}`};return void 0!==e.mesh&&(s.mesh=this.getMesh(e.mesh)),void 0!==e.camera&&(s.camera=this.getCamera(e.camera)),void 0!==e.skin&&(s.skin=this.getSkin(e.skin)),void 0!==e.meshes&&e.meshes.length&&(s.mesh=e.meshes.reduce(((e,t)=>{const s=this.getMesh(t);return e.id=s.id,e.primitives=e.primitives.concat(s.primitives),e}),{primitives:[]})),s}_resolveNodeChildren(e){return e.children&&(e.children=e.children.map((e=>this.getNode(e)))),e}_resolveSkin(e,t){const s="number"==typeof e.inverseBindMatrices?this.getAccessor(e.inverseBindMatrices):void 0;return{...e,id:e.id||`skin-${t}`,inverseBindMatrices:s}}_resolveMesh(e,t){const s={...e,id:e.id||`mesh-${t}`,primitives:[]};return e.primitives&&(s.primitives=e.primitives.map((e=>{const t={...e,attributes:{},indices:void 0,material:void 0},s=e.attributes;for(const e in s)t.attributes[e]=this.getAccessor(s[e]);return void 0!==e.indices&&(t.indices=this.getAccessor(e.indices)),void 0!==e.material&&(t.material=this.getMaterial(e.material)),t}))),s}_resolveMaterial(e,t){const s={...e,id:e.id||`material-${t}`};if(s.normalTexture&&(s.normalTexture={...s.normalTexture},s.normalTexture.texture=this.getTexture(s.normalTexture.index)),s.occlusionTexture&&(s.occlusionTexture={...s.occlusionTexture},s.occlusionTexture.texture=this.getTexture(s.occlusionTexture.index)),s.emissiveTexture&&(s.emissiveTexture={...s.emissiveTexture},s.emissiveTexture.texture=this.getTexture(s.emissiveTexture.index)),s.emissiveFactor||(s.emissiveFactor=s.emissiveTexture?[1,1,1]:[0,0,0]),s.pbrMetallicRoughness){s.pbrMetallicRoughness={...s.pbrMetallicRoughness};const e=s.pbrMetallicRoughness;e.baseColorTexture&&(e.baseColorTexture={...e.baseColorTexture},e.baseColorTexture.texture=this.getTexture(e.baseColorTexture.index)),e.metallicRoughnessTexture&&(e.metallicRoughnessTexture={...e.metallicRoughnessTexture},e.metallicRoughnessTexture.texture=this.getTexture(e.metallicRoughnessTexture.index))}return s}_resolveAccessor(e,t){const s=(i=e.componentType,du[i]);var i;const r=(n=e.type,uu[n]);var n;const A=s*r,o={...e,id:e.id||`accessor-${t}`,bytesPerComponent:s,components:r,bytesPerElement:A,value:void 0,bufferView:void 0,sparse:void 0};if(void 0!==e.bufferView&&(o.bufferView=this.getBufferView(e.bufferView)),o.bufferView){const e=o.bufferView.buffer,{ArrayType:t,byteLength:s}=Ll(o,o.bufferView),i=(o.bufferView.byteOffset||0)+(o.byteOffset||0)+e.byteOffset;let r=e.arrayBuffer.slice(i,i+s);o.bufferView.byteStride&&(r=this._getValueFromInterleavedBuffer(e,i,o.bufferView.byteStride,o.bytesPerElement,o.count)),o.value=new t(r)}return o}_getValueFromInterleavedBuffer(e,t,s,i,r){const n=new Uint8Array(r*i);for(let A=0;A<r;A++){const r=t+A*s;n.set(new Uint8Array(e.arrayBuffer.slice(r,r+i)),A*i)}return n.buffer}_resolveTexture(e,t){return{...e,id:e.id||`texture-${t}`,sampler:"number"==typeof e.sampler?this.getSampler(e.sampler):{id:"default-sampler",parameters:yu},source:"number"==typeof e.source?this.getImage(e.source):void 0}}_resolveSampler(e,t){const s={id:e.id||`sampler-${t}`,...e,parameters:{}};for(const e in s){const t=this._enumSamplerParameter(e);void 0!==t&&(s.parameters[t]=s[e])}return s}_enumSamplerParameter(e){return bu[e]}_resolveImage(e,t){const s={...e,id:e.id||`image-${t}`,image:null,bufferView:void 0!==e.bufferView?this.getBufferView(e.bufferView):void 0},i=this.images[t];return i&&(s.image=i),s}_resolveBufferView(e,t){const s=e.buffer,i=this.buffers[s].arrayBuffer;let r=this.buffers[s].byteOffset||0;e.byteOffset&&(r+=e.byteOffset);return{id:`bufferView-${t}`,...e,buffer:this.buffers[s],data:new Uint8Array(i,r,e.byteLength)}}_resolveCamera(e,t){return{...e,id:e.id||`camera-${t}`}}}function wu(e,t){return(new Bu).postProcess(e,t)}const vu={dataType:null,batchType:null,name:"LAS",id:"las",module:"las",version:"4.3.3",worker:!0,extensions:["las","laz"],mimeTypes:["application/octet-stream"],text:!0,binary:!0,tests:["LAS"],options:{las:{shape:"mesh",fp64:!1,skip:1,colorDepth:8}}};function Cu(){var e,t=void 0!==t?t:{},s={};for(e in t)t.hasOwnProperty(e)&&(s[e]=t[e]);var i,r,n,A;i="object"==typeof window,r="function"==typeof importScripts,n="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,A=!i&&!n&&!r;var o,a,l,c,h,u="";if(n){if(r)u=require("path").dirname(u)+"/";else{const e="undefined"!=typeof __dirname?__dirname:"";u=e+"/"}o=function(e,t){var s=ht(e);return s?t?s:s.toString():(c||(c=require("fs")),h||(h=require("path")),e=h.normalize(e),c.readFileSync(e,t?null:"utf8"))},l=function(e){var t=o(e,!0);return t.buffer||(t=new Uint8Array(t)),m(t.buffer),t},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),"undefined"!=typeof module&&(module.exports=t),process.on("uncaughtException",(function(e){if(!(e instanceof Et))throw e})),process.on("unhandledRejection",z),t.inspect=function(){return"[Emscripten Module object]"}}else A?("undefined"!=typeof read&&(o=function(e){var t=ht(e);return t?lt(t):read(e)}),l=function(e){var t;return(t=ht(e))?t:"function"==typeof readbuffer?new Uint8Array(readbuffer(e)):(m("object"==typeof(t=read(e,"binary"))),t)},"undefined"!=typeof scriptArgs&&scriptArgs,"undefined"!=typeof print&&("undefined"==typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!=typeof printErr?printErr:print)):(i||r)&&(r?u=self.location.href:document.currentScript&&(u=document.currentScript.src),u=0!==u.indexOf("blob:")?u.substr(0,u.lastIndexOf("/")+1):"",o=function(e){try{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),t.responseText}catch(t){var s=ht(e);if(s)return lt(s);throw t}},r&&(l=function(e){try{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}catch(t){var s=ht(e);if(s)return s;throw t}}),a=function(e,t,s){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onload=function(){if(200==i.status||0==i.status&&i.response)t(i.response);else{var r=ht(e);r?t(r.buffer):s()}},i.onerror=s,i.send(null)});var d=t.print||console.log.bind(console),p=t.printErr||console.warn.bind(console);for(e in s)s.hasOwnProperty(e)&&(t[e]=s[e]);s=null,t.arguments,t.thisProgram,t.quit,new Array(0);var f=0;t.wasmBinary,t.noExitRuntime;var g=!1;function m(e,t){e||z("Assertion failed: "+t)}var _="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function b(e,t){return e?function(e,t,s){for(var i=t+s,r=t;e[r]&&!(r>=i);)++r;if(r-t>16&&e.subarray&&_)return _.decode(e.subarray(t,r));for(var n="";t<r;){var A=e[t++];if(128&A){var o=63&e[t++];if(192!=(224&A)){var a=63&e[t++];if((A=224==(240&A)?(15&A)<<12|o<<6|a:(7&A)<<18|o<<12|a<<6|63&e[t++])<65536)n+=String.fromCharCode(A);else{var l=A-65536;n+=String.fromCharCode(55296|l>>10,56320|1023&l)}}else n+=String.fromCharCode((31&A)<<6|o)}else n+=String.fromCharCode(A)}return n}(w,e,t):""}var y,B,w,v,C,M,E,F,x,U="undefined"!=typeof TextDecoder?new TextDecoder("utf-16le"):void 0;function I(e,t){for(var s=e,i=s>>1,r=i+t/2;!(i>=r)&&C[i];)++i;if((s=i<<1)-e>32&&U)return U.decode(w.subarray(e,s));for(var n=0,A="";;){var o=v[e+2*n>>1];if(0==o||n==t/2)return A;++n,A+=String.fromCharCode(o)}}function T(e,t,s){if(void 0===s&&(s=2147483647),s<2)return 0;for(var i=t,r=(s-=2)<2*e.length?s/2:e.length,n=0;n<r;++n){var A=e.charCodeAt(n);v[t>>1]=A,t+=2}return v[t>>1]=0,t-i}function P(e){return 2*e.length}function S(e,t){for(var s=0,i="";!(s>=t/4);){var r=M[e+4*s>>2];if(0==r)break;if(++s,r>=65536){var n=r-65536;i+=String.fromCharCode(55296|n>>10,56320|1023&n)}else i+=String.fromCharCode(r)}return i}function D(e,t,s){if(void 0===s&&(s=2147483647),s<4)return 0;for(var i=t,r=i+s-4,n=0;n<e.length;++n){var A=e.charCodeAt(n);if(A>=55296&&A<=57343)A=65536+((1023&A)<<10)|1023&e.charCodeAt(++n);if(M[t>>2]=A,(t+=4)+4>r)break}return M[t>>2]=0,t-i}function k(e){for(var t=0,s=0;s<e.length;++s){var i=e.charCodeAt(s);i>=55296&&i<=57343&&++s,t+=4}return t}var Q,R=t.INITIAL_MEMORY||167772160;function O(e){for(;e.length>0;){var s=e.shift();if("function"!=typeof s){var i=s.func;"number"==typeof i?void 0===s.arg?t.dynCall_v(i):t.dynCall_vi(i,s.arg):i(void 0===s.arg?null:s.arg)}else s(t)}}R=(y=t.buffer?t.buffer:new ArrayBuffer(R)).byteLength,y=Q=y,t.HEAP8=B=new Int8Array(Q),t.HEAP16=v=new Int16Array(Q),t.HEAP32=M=new Int32Array(Q),t.HEAPU8=w=new Uint8Array(Q),t.HEAPU16=C=new Uint16Array(Q),t.HEAPU32=E=new Uint32Array(Q),t.HEAPF32=F=new Float32Array(Q),t.HEAPF64=x=new Float64Array(Q),M[5544]=5265264;var V=[],L=[],H=[],N=[];var G=0,j=null;function z(e){throw t.onAbort&&t.onAbort(e),d(e+=""),p(e),g=!0,e="abort("+e+"). Build with -s ASSERTIONS=1 for more info."}t.preloadedImages={},t.preloadedAudios={};var W=null;var X="data:application/octet-stream;base64,";function K(e){return t=e,s=X,String.prototype.startsWith?t.startsWith(s):0===t.indexOf(s);var t,s}L.push({func:function(){yt()}}),W="data:application/octet-stream;base64,AAAAAAAAAAAPDg0MCwoJCA4AAQMGCgoJDQECBAcLCwoMAwQFCAwMCwsGBwgJDQ0MCgoLDA0ODg0JCgsMDQ4PDggJCgsMDQ4PAAECAwQFBgcBAAECAwQFBgIBAAECAwQFAwIBAAECAwQEAwIBAAECAwUEAwIBAAECBgUEAwIBAAEHBgUEAwIBAMgPAAAoDQAAEBAAACAQAADIDwAAUA0AABAQAAAgEAAAEQAKABEREQAAAAAFAAAAAAAACQAAAAALAAAAAAAAAAARAA8KERERAwoHAAEACQsLAAAJBgsAAAsABhEAAAAREREAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAEQAKChEREQAKAAACAAkLAAAACQALAAALAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAADAAAAAAJDAAAAAAADAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAANAAAABA0AAAAACQ4AAAAAAA4AAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAADwAAAAAPAAAAAAkQAAAAAAAQAAAQAAASAAAAEhISAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAASEhIAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAAAAAAKAAAAAAoAAAAACQsAAAAAAAsAAAsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAMAAAAAAkMAAAAAAAMAAAMAAAwMTIzNDU2Nzg5QUJDREVGGRJEOwI/LEcUPTMwChsGRktFNw9JDo4XA0AdPGkrNh9KLRwBICUpIQgMFRYiLhA4Pgs0MRhkdHV2L0EJfzkRI0MyQomKiwUEJignDSoeNYwHGkiTE5SVAAAAAAAAAAAASWxsZWdhbCBieXRlIHNlcXVlbmNlAERvbWFpbiBlcnJvcgBSZXN1bHQgbm90IHJlcHJlc2VudGFibGUATm90IGEgdHR5AFBlcm1pc3Npb24gZGVuaWVkAE9wZXJhdGlvbiBub3QgcGVybWl0dGVkAE5vIHN1Y2ggZmlsZSBvciBkaXJlY3RvcnkATm8gc3VjaCBwcm9jZXNzAEZpbGUgZXhpc3RzAFZhbHVlIHRvbyBsYXJnZSBmb3IgZGF0YSB0eXBlAE5vIHNwYWNlIGxlZnQgb24gZGV2aWNlAE91dCBvZiBtZW1vcnkAUmVzb3VyY2UgYnVzeQBJbnRlcnJ1cHRlZCBzeXN0ZW0gY2FsbABSZXNvdXJjZSB0ZW1wb3JhcmlseSB1bmF2YWlsYWJsZQBJbnZhbGlkIHNlZWsAQ3Jvc3MtZGV2aWNlIGxpbmsAUmVhZC1vbmx5IGZpbGUgc3lzdGVtAERpcmVjdG9yeSBub3QgZW1wdHkAQ29ubmVjdGlvbiByZXNldCBieSBwZWVyAE9wZXJhdGlvbiB0aW1lZCBvdXQAQ29ubmVjdGlvbiByZWZ1c2VkAEhvc3QgaXMgZG93bgBIb3N0IGlzIHVucmVhY2hhYmxlAEFkZHJlc3MgaW4gdXNlAEJyb2tlbiBwaXBlAEkvTyBlcnJvcgBObyBzdWNoIGRldmljZSBvciBhZGRyZXNzAEJsb2NrIGRldmljZSByZXF1aXJlZABObyBzdWNoIGRldmljZQBOb3QgYSBkaXJlY3RvcnkASXMgYSBkaXJlY3RvcnkAVGV4dCBmaWxlIGJ1c3kARXhlYyBmb3JtYXQgZXJyb3IASW52YWxpZCBhcmd1bWVudABBcmd1bWVudCBsaXN0IHRvbyBsb25nAFN5bWJvbGljIGxpbmsgbG9vcABGaWxlbmFtZSB0b28gbG9uZwBUb28gbWFueSBvcGVuIGZpbGVzIGluIHN5c3RlbQBObyBmaWxlIGRlc2NyaXB0b3JzIGF2YWlsYWJsZQBCYWQgZmlsZSBkZXNjcmlwdG9yAE5vIGNoaWxkIHByb2Nlc3MAQmFkIGFkZHJlc3MARmlsZSB0b28gbGFyZ2UAVG9vIG1hbnkgbGlua3MATm8gbG9ja3MgYXZhaWxhYmxlAFJlc291cmNlIGRlYWRsb2NrIHdvdWxkIG9jY3VyAFN0YXRlIG5vdCByZWNvdmVyYWJsZQBQcmV2aW91cyBvd25lciBkaWVkAE9wZXJhdGlvbiBjYW5jZWxlZABGdW5jdGlvbiBub3QgaW1wbGVtZW50ZWQATm8gbWVzc2FnZSBvZiBkZXNpcmVkIHR5cGUASWRlbnRpZmllciByZW1vdmVkAERldmljZSBub3QgYSBzdHJlYW0ATm8gZGF0YSBhdmFpbGFibGUARGV2aWNlIHRpbWVvdXQAT3V0IG9mIHN0cmVhbXMgcmVzb3VyY2VzAExpbmsgaGFzIGJlZW4gc2V2ZXJlZABQcm90b2NvbCBlcnJvcgBCYWQgbWVzc2FnZQBGaWxlIGRlc2NyaXB0b3IgaW4gYmFkIHN0YXRlAE5vdCBhIHNvY2tldABEZXN0aW5hdGlvbiBhZGRyZXNzIHJlcXVpcmVkAE1lc3NhZ2UgdG9vIGxhcmdlAFByb3RvY29sIHdyb25nIHR5cGUgZm9yIHNvY2tldABQcm90b2NvbCBub3QgYXZhaWxhYmxlAFByb3RvY29sIG5vdCBzdXBwb3J0ZWQAU29ja2V0IHR5cGUgbm90IHN1cHBvcnRlZABOb3Qgc3VwcG9ydGVkAFByb3RvY29sIGZhbWlseSBub3Qgc3VwcG9ydGVkAEFkZHJlc3MgZmFtaWx5IG5vdCBzdXBwb3J0ZWQgYnkgcHJvdG9jb2wAQWRkcmVzcyBub3QgYXZhaWxhYmxlAE5ldHdvcmsgaXMgZG93bgBOZXR3b3JrIHVucmVhY2hhYmxlAENvbm5lY3Rpb24gcmVzZXQgYnkgbmV0d29yawBDb25uZWN0aW9uIGFib3J0ZWQATm8gYnVmZmVyIHNwYWNlIGF2YWlsYWJsZQBTb2NrZXQgaXMgY29ubmVjdGVkAFNvY2tldCBub3QgY29ubmVjdGVkAENhbm5vdCBzZW5kIGFmdGVyIHNvY2tldCBzaHV0ZG93bgBPcGVyYXRpb24gYWxyZWFkeSBpbiBwcm9ncmVzcwBPcGVyYXRpb24gaW4gcHJvZ3Jlc3MAU3RhbGUgZmlsZSBoYW5kbGUAUmVtb3RlIEkvTyBlcnJvcgBRdW90YSBleGNlZWRlZABObyBtZWRpdW0gZm91bmQAV3JvbmcgbWVkaXVtIHR5cGUATm8gZXJyb3IgaW5mb3JtYXRpb24AAAAAAADgFgAAmRgAAGAQAAAAAAAA4BYAAEIZAABgEAAAAAAAAOAWAAAqGgAASA8AAAAAAAC4FgAANBsAAOAWAACfGgAAMAoAAAAAAADgFgAAaRsAAEgPAAAAAAAA4BYAAIobAABIDwAAAAAAALgWAAAPHAAA4BYAAHwcAABIDwAAAAAAAOAWAACVHAAASA8AAAAAAADgFgAAHh0AAEgPAAAAAAAA4BYAAHcdAABIDwAAAAAAAOAWAACQHQAASA8AAAAAAADgFgAAQh4AAEgPAAAAAAAA4BYAAIceAABgEAAAAAAAAOAWAACkHwAASA8AAAAAAAC4FgAAZyAAAOAWAADkHwAA8AoAAAAAAADgFgAAjyAAAGAQAAAAAAAAuBYAAMMiAADgFgAAAiIAABgLAAAAAAAA4BYAAOEiAABgEAAAAAAAAOAWAADQJAAAGAsAAAAAAADgFgAAkSUAAGAQAAAAAAAA4BYAAIAnAAAYCwAAAAAAAOAWAAA9KAAAYBAAAAAAAADgFgAAJCoAABgLAAAAAAAA4BYAAOkqAABgEAAAAAAAAOAWAADgLAAA8AoAAAAAAADgFgAAui0AAGAQAAAAAAAA4BYAANsvAADwCgAAAAAAAOAWAADTMAAAYBAAAAAAAADgFgAAMDMAAPAKAAAAAAAA4BYAACQ0AABgEAAAAAAAAOAWAAB5NgAA8AoAAAAAAADgFgAAizcAAGAQAAAAAAAA4BYAABw6AABgEAAAAAAAAOAWAACdOgAAYBAAAAAAAADgFgAAXjsAAPAKAAAAAAAA4BYAALU7AABgEAAAAAAAAOAWAADMPAAAGAsAAAAAAADgFgAATz0AAGAQAAAAAAAA4BYAAL4+AAAYCwAAAAAAAOAWAABBPwAAYBAAAAAAAADgFgAAsEAAABgLAAAAAAAA4BYAADNBAABgEAAAAAAAAOAWAACiQgAAGAsAAAAAAADgFgAAJUMAAGAQAAAAAAAA4BYAAJREAAAYCwAAAAAAAOAWAAAXRQAAYBAAAAAAAADgFgAAhkYAABgLAAAAAAAA4BYAAAlHAABgEAAAAAAAALgWAAB4SAAAiBcAAIBIAAAAAAAAIA0AAIgXAACJSAAAAQAAACANAAC4FgAAqkgAAIgXAAC6SAAAAAAAAEgNAACIFwAAy0gAAAEAAABIDQAAuBYAABhMAAC4FgAAN0wAALgWAABWTAAAuBYAAHVMAAC4FgAAlEwAALgWAACzTAAAuBYAANJMAAC4FgAA8UwAALgWAAAQTQAAuBYAAC9NAAC4FgAATk0AALgWAABtTQAAuBYAAIxNAACkFwAAn00AAAAAAAABAAAA8A0AAAAAAAC4FgAA4U0AAKQXAAAHTgAAAAAAAAEAAADwDQAAAAAAAKQXAABJTgAAAAAAAAEAAADwDQAAAAAAAKQXAACITgAAAAAAAAEAAADwDQAAAAAAAKQXAADHTgAAAAAAAAEAAADwDQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALgWAADNTwAA4BYAAC1QAAAADwAAAAAAAOAWAADaTwAAEA8AAAAAAAC4FgAA+08AAOAWAAAIUAAA8A4AAAAAAADgFgAAhlAAAOgOAAAAAAAA4BYAAJNQAADoDgAAAAAAAOAWAACjUAAA6A4AAAAAAADgFgAAtVAAADgPAAAAAAAA4BYAAMZQAAA4DwAAAAAAAOAWAADXUAAAAA8AAAAAAADgFgAA+VAAAHgPAAAAAAAA4BYAAB1RAAAADwAAAAAAAOAWAABCUQAAeA8AAAAAAADgFgAAjlEAAAAPAAAAAAAAbBcAALZRAABsFwAAuFEAAGwXAAC7UQAAbBcAAL1RAABsFwAAv1EAAGwXAADBUQAAbBcAAMNRAABsFwAAxVEAAGwXAADHUQAAbBcAAMlRAABsFwAAy1EAAGwXAADNUQAAbBcAAM9RAABsFwAA0VEAAOAWAADTUQAA8A4AAAAAAADgFgAARlIAAOgOAAAAAAAAuBYAAGJSAACkFwAAe1IAAAAAAAABAAAAWBAAAAAAAADgFgAA9FIAAIgQAAAAAAAA4BYAABdTAACYEAAAAAAAALgWAAAuUwAA4BYAAHBTAACIEAAAAAAAAOAWAACSUwAASA8AAAAAAAAAAAAAAAoAAAEAAAACAAAAAwAAAAEAAAAEAAAAAAAAABAKAAABAAAABQAAAAYAAAACAAAABwAAAAAAAAAgCgAACAAAAAkAAAABAAAAAAAAADgKAAAKAAAACwAAAAIAAAABAAAADAAAAA0AAAACAAAAAwAAAAMAAAAAAAAASAoAAAgAAAAOAAAAAQAAAAAAAABYCgAACAAAAA8AAAABAAAAAAAAAIAKAAAIAAAAEAAAAAEAAAAAAAAAcAoAAAgAAAARAAAAAQAAAAAAAACQCgAACAAAABIAAAABAAAAAAAAAKAKAAAIAAAAEwAAAAEAAAAAAAAAsAoAAAgAAAAUAAAAAQAAAAAAAADACgAACAAAABUAAAABAAAAAAAAANAKAAABAAAAFgAAABcAAAAEAAAAGAAAAAAAAADgCgAACAAAABkAAAABAAAAAAAAAPgKAAAFAAAAGgAAABsAAAAAAAAA8AoAAAEAAAAcAAAAHQAAAAAAAAAICwAAAQAAAB4AAAAfAAAABgAAACAAAAAAAAAAIAsAACEAAAAiAAAABwAAAAgAAAAAAAAAGAsAACMAAAAkAAAABwAAAAkAAAAAAAAAMAsAAAEAAAAlAAAAJgAAAAoAAAAnAAAAAAAAAEALAAAoAAAAKQAAAAcAAAALAAAAAAAAAFALAAABAAAAKgAAACsAAAAMAAAALAAAAAAAAABgCwAALQAAAC4AAAAHAAAADQAAAAAAAABwCwAAAQAAAC8AAAAwAAAADgAAADEAAAAAAAAAgAsAADIAAAAzAAAABwAAAA8AAAAAAAAAkAsAAAEAAAA0AAAANQAAABAAAAA2AAAAAAAAAKALAAARAAAANwAAADgAAAAAAAAAsAsAAAEAAAA5AAAAOgAAABIAAAA7AAAAAAAAAMALAAATAAAAPAAAAD0AAAAAAAAA0AsAAAEAAAA+AAAAPwAAABQAAABAAAAAAAAAAOALAAAVAAAAQQAAAEIAAAAAAAAA8AsAAAEAAABDAAAARAAAABYAAABFAAAAAAAAAAAMAAAXAAAARgAAAEcAAAAAAAAAEAwAAAEAAABIAAAASQAAABgAAABKAAAAAAAAACAMAAABAAAASwAAAEwAAAAZAAAATQAAAAAAAAAwDAAAAQAAAE4AAABPAAAAGgAAAFAAAAAAAAAAQAwAABsAAABRAAAAUgAAAAAAAABQDAAAAQAAAFMAAABUAAAAHAAAAFUAAAAAAAAAYAwAAFYAAABXAAAABwAAAB0AAAAAAAAAcAwAAAEAAABYAAAAWQAAAB4AAABaAAAAAAAAAIAMAABbAAAAXAAAAAcAAAAfAAAAAAAAAJAMAAABAAAAXQAAAF4AAAAgAAAAXwAAAAAAAACgDAAAYAAAAGEAAAAHAAAAIQAAAAAAAACwDAAAAQAAAGIAAABjAAAAIgAAAGQAAAAAAAAAwAwAAGUAAABmAAAABwAAACMAAAAAAAAA0AwAAAEAAABnAAAAaAAAACQAAABpAAAAAAAAAOAMAABqAAAAawAAAAcAAAAlAAAAAAAAAPAMAAABAAAAbAAAAG0AAAAmAAAAbgAAAAAAAAAADQAAbwAAAHAAAAAHAAAAJwAAAAAAAAAQDQAAAQAAAHEAAAByAAAAKAAAAHMAAAAoDQAAyA8AACgNAAAIEAAAEBAAACgNAABQDQAAyA8AAFANAAAgEAAAyA8AAFANAAAIEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwDgAAdAAAAHUAAAB2AAAAdwAAAAIAAAABAAAAAQAAAAEAAAAAAAAAGA8AAHQAAAB4AAAAdgAAAHcAAAACAAAAAgAAAAIAAAACAAAAAAAAACgPAAB5AAAAegAAAAQAAAAAAAAAOA8AAHsAAAB8AAAABQAAAAAAAABIDwAACAAAAH0AAAABAAAAAAAAAFgPAAB7AAAAfgAAAAUAAAAAAAAAaA8AAHsAAAB/AAAABQAAAAAAAAC4DwAAdAAAAIAAAAB2AAAAdwAAAAMAAAAAAAAAiA8AAHQAAACBAAAAdgAAAHcAAAAEAAAAAAAAADgQAAB0AAAAggAAAHYAAAB3AAAAAgAAAAMAAAADAAAAAwAAAAAAAABIEAAAgwAAAIQAAAAGAAAAAAAAAHgQAACFAAAAhgAAAAcAAAABAAAABQAAAAYAAAACAAAAAAAAAKAQAACFAAAAhwAAAAgAAAADAAAABQAAAAYAAAAEAAAA4BcAAAQYAAAAAAAAsBAAAIgAAACJAAAAAQAAAExBU1ppcABvcGVuAGdldFBvaW50AGdldENvdW50AER5bmFtaWNMQVNaaXAAYWRkRmllbGRGbG9hdGluZwBhZGRGaWVsZFNpZ25lZABhZGRGaWVsZFVuc2lnbmVkAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRU5TXzE0ZGVmYXVsdF9kZWxldGVJUzNfRUVOU185YWxsb2NhdG9ySVMzX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXAyaW82cmVhZGVyMTBiYXNpY19maWxlSU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJUzdfRUVOU185YWxsb2NhdG9ySVM3X0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXAyaW82cmVhZGVyMTBiYXNpY19maWxlSU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFAExBU0YATjZsYXN6aXAxM2ludmFsaWRfbWFnaWNFAGFsbG9jYXRvcjxUPjo6YWxsb2NhdGUoc2l6ZV90IG4pICduJyBleGNlZWRzIG1heGltdW0gc3VwcG9ydGVkIHNpemUARmlsZSBtYWdpYyBpcyBub3QgdmFsaWQATlN0M19fMjEwX19mdW5jdGlvbjZfX2Z1bmNJWk42bGFzemlwMmlvNnJlYWRlcjEwYmFzaWNfZmlsZUlOUzJfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRTExX3ZhbGlkYXRvcnNFdkVVbFJOUzNfNmhlYWRlckVFX05TXzlhbGxvY2F0b3JJU0JfRUVGdlNBX0VFRQBOU3QzX18yMTBfX2Z1bmN0aW9uNl9fYmFzZUlGdlJONmxhc3ppcDJpbzZoZWFkZXJFRUVFAE42bGFzemlwMjFvbGRfc3R5bGVfY29tcHJlc3Npb25FAE42bGFzemlwMTRub3RfY29tcHJlc3NlZEUAVGhlIGZpbGUgc2VlbXMgdG8gaGF2ZSBvbGQgc3R5bGUgY29tcHJlc3Npb24gd2hpY2ggaXMgbm90IHN1cHBvcnRlZABUaGUgZmlsZSBkb2Vzbid0IHNlZW0gdG8gYmUgY29tcHJlc3NlZABaTjZsYXN6aXAyaW82cmVhZGVyMTBiYXNpY19maWxlSU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUUxMV92YWxpZGF0b3JzRXZFVWxSTlMwXzZoZWFkZXJFRV8AbGFzemlwIGVuY29kZWQATjZsYXN6aXAxM25vX2xhc3ppcF92bHJFAE42bGFzemlwMjVsYXN6aXBfZm9ybWF0X3Vuc3VwcG9ydGVkRQBPbmx5IExBU3ppcCBQT0lOVFdJU0UgQ0hVTktFRCBkZWNvbXByZXNzb3IgaXMgc3VwcG9ydGVkAE5vIExBU3ppcCBWTFIgd2FzIGZvdW5kIGluIHRoZSBWTFJzIHNlY3Rpb24ATjZsYXN6aXAyMmNodW5rX3RhYmxlX3JlYWRfZXJyb3JFAENodW5rIHRhYmxlIG9mZnNldCA9PSAtMSBpcyBub3Qgc3VwcG9ydGVkIGF0IHRoaXMgdGltZQBONmxhc3ppcDEzbm90X3N1cHBvcnRlZEUATjZsYXN6aXAyNnVua25vd25fY2h1bmtfdGFibGVfZm9ybWF0RQBjaHVua19zaXplID09IHVpbnQubWF4IGlzIG5vdCBzdXBwb3J0ZWQgYXQgdGhpcyB0aW1lLgBUaGVyZSB3YXMgYSBwcm9ibGVtIHJlYWRpbmcgdGhlIGNodW5rIHRhYmxlAFRoZSBjaHVuayB0YWJsZSB2ZXJzaW9uIG51bWJlciBpcyB1bmtub3duAE42bGFzemlwMTFlbmRfb2ZfZmlsZUUAUmVhY2hlZCBFbmQgb2YgZmlsZQBJbnZhbGlkIG51bWJlciBvZiBzeW1ib2xzAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOU18xNGRlZmF1bHRfZGVsZXRlSVM5X0VFTlNfOWFsbG9jYXRvcklTOV9FRUVFAE5TdDNfXzIxNGRlZmF1bHRfZGVsZXRlSU42bGFzemlwOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRUVFAE42bGFzemlwMTl1bmtub3duX3NjaGVtYV90eXBlRQBUaGUgTEFaIHNjaGVtYSBpcyBub3QgcmVjb2duaXplZABONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2ZpZWxkX2RlY29tcHJlc3NvcklOU184ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlNfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlNfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyMGR5bmFtaWNfZGVjb21wcmVzc29yRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19maWVsZF9kZWNvbXByZXNzb3JJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU0NfRUVOU185YWxsb2NhdG9ySVNDX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19maWVsZF9kZWNvbXByZXNzb3JJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOU18yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOU183c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMwXzVmaWVsZElOUzBfM2xhczdwb2ludDEwRU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNDX0VFRUVFRQBONmxhc3ppcDdmb3JtYXRzMTBiYXNlX2ZpZWxkRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19kZWNvbXByZXNzb3JfZmllbGRJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0VfRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTSV9FRU5TXzlhbGxvY2F0b3JJU0lfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMl81ZmllbGRJTlMyXzNsYXM3cG9pbnQxMEVOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRV9FRUVFRUVFRQBONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOU184ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlNfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlNfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMF81ZmllbGRJTlMwXzNsYXM3Z3BzdGltZUVOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTQ19FRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczdncHN0aW1lRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNFX0VFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU0lfRUVOU185YWxsb2NhdG9ySVNJX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19kZWNvbXByZXNzb3JfZmllbGRJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfNWZpZWxkSU5TMl8zbGFzN2dwc3RpbWVFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0VfRUVFRUVFRUUATjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19kZWNvbXByZXNzb3JfZmllbGRJTlNfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzBfNWZpZWxkSU5TMF8zbGFzM3JnYkVOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTQ19FRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczNyZ2JFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0VfRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTSV9FRU5TXzlhbGxvY2F0b3JJU0lfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMl81ZmllbGRJTlMyXzNsYXMzcmdiRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNFX0VFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOU18yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOU183c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMwXzVmaWVsZElOUzBfM2xhczEwZXh0cmFieXRlc0VOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTQ19FRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczEwZXh0cmFieXRlc0VOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRV9FRUVFRUVOU18xNGRlZmF1bHRfZGVsZXRlSVNJX0VFTlNfOWFsbG9jYXRvcklTSV9FRUVFAE5TdDNfXzIxNGRlZmF1bHRfZGVsZXRlSU42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczEwZXh0cmFieXRlc0VOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRV9FRUVFRUVFRQBONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlNfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzBfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzBfNWZpZWxkSU5TMF8zbGFzN3BvaW50MTBFTlMwXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0RfRUVFRUVFRUVFAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0ZfRUVFRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTS19FRU5TXzlhbGxvY2F0b3JJU0tfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0ZfRUVFRUVFRUVFRUUATjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOU18yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOU183c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMwXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMwXzVmaWVsZElOUzBfM2xhczdwb2ludDEwRU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNEX0VFRUVOU0JfSU5TQ183Z3BzdGltZUVOU0VfSVNIX0VFRUVFRUVFRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV83Z3BzdGltZUVOU0dfSVNKX0VFRUVFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU05fRUVOU185YWxsb2NhdG9ySVNOX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV83Z3BzdGltZUVOU0dfSVNKX0VFRUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyMWR5bmFtaWNfZGVjb21wcmVzc29yMUlOU184ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlNfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlNfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMF8xOXJlY29yZF9kZWNvbXByZXNzb3JJSk5TMF81ZmllbGRJTlMwXzNsYXM3cG9pbnQxMEVOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRF9FRUVFTlNCX0lOU0NfM3JnYkVOU0VfSVNIX0VFRUVFRUVFRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV8zcmdiRU5TR19JU0pfRUVFRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTTl9FRU5TXzlhbGxvY2F0b3JJU05fRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0ZfRUVFRU5TRF9JTlNFXzNyZ2JFTlNHX0lTSl9FRUVFRUVFRUVFRQBONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlNfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzBfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzBfNWZpZWxkSU5TMF8zbGFzN3BvaW50MTBFTlMwXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0RfRUVFRU5TQl9JTlNDXzdncHN0aW1lRU5TRV9JU0hfRUVFRU5TQl9JTlNDXzNyZ2JFTlNFX0lTS19FRUVFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyMWR5bmFtaWNfZGVjb21wcmVzc29yMUlOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMl8xOXJlY29yZF9kZWNvbXByZXNzb3JJSk5TMl81ZmllbGRJTlMyXzNsYXM3cG9pbnQxMEVOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRl9FRUVFTlNEX0lOU0VfN2dwc3RpbWVFTlNHX0lTSl9FRUVFTlNEX0lOU0VfM3JnYkVOU0dfSVNNX0VFRUVFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU1FfRUVOU185YWxsb2NhdG9ySVNRX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV83Z3BzdGltZUVOU0dfSVNKX0VFRUVOU0RfSU5TRV8zcmdiRU5TR19JU01fRUVFRUVFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUDEwYnVmX3N0cmVhbU5TXzE0ZGVmYXVsdF9kZWxldGVJUzFfRUVOU185YWxsb2NhdG9ySVMxX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJMTBidWZfc3RyZWFtRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTNV9FRU5TXzlhbGxvY2F0b3JJUzVfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZmllbGRfZGVjb21wcmVzc29ySU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRUVFAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2ZpZWxkX2RlY29tcHJlc3NvcklOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFRUVOU18xNGRlZmF1bHRfZGVsZXRlSVM4X0VFTlNfOWFsbG9jYXRvcklTOF9FRUVFAE5TdDNfXzIxNGRlZmF1bHRfZGVsZXRlSU42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZmllbGRfZGVjb21wcmVzc29ySU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJaU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWlFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWlOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElpRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElpTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJaUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJak5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWpFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWpOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElqRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElqTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJakVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJYU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWFFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWFOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElhRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElhTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJYUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJc05TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSXNFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSXNOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElzRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElzTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJc0VFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJaE5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWhFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWhOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZEloRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZEloTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJaEVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJdE5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSXRFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSXROUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZEl0RUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZEl0TlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJdEVFRUVFRUVFADZMQVNaaXAAUDZMQVNaaXAAUEs2TEFTWmlwAGlpAHYAdmkAdmlpaWkAdmlpaQBpaWkAMTNEeW5hbWljTEFTWmlwAFAxM0R5bmFtaWNMQVNaaXAAUEsxM0R5bmFtaWNMQVNaaXAAdm9pZABib29sAGNoYXIAc2lnbmVkIGNoYXIAdW5zaWduZWQgY2hhcgBzaG9ydAB1bnNpZ25lZCBzaG9ydABpbnQAdW5zaWduZWQgaW50AGxvbmcAdW5zaWduZWQgbG9uZwBmbG9hdABkb3VibGUAc3RkOjpzdHJpbmcAc3RkOjpiYXNpY19zdHJpbmc8dW5zaWduZWQgY2hhcj4Ac3RkOjp3c3RyaW5nAHN0ZDo6dTE2c3RyaW5nAHN0ZDo6dTMyc3RyaW5nAGVtc2NyaXB0ZW46OnZhbABlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxjaGFyPgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxzaWduZWQgY2hhcj4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8dW5zaWduZWQgY2hhcj4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8c2hvcnQ+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PHVuc2lnbmVkIHNob3J0PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxpbnQ+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PHVuc2lnbmVkIGludD4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8bG9uZz4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8dW5zaWduZWQgbG9uZz4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8aW50OF90PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzx1aW50OF90PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxpbnQxNl90PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzx1aW50MTZfdD4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8aW50MzJfdD4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8dWludDMyX3Q+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PGZsb2F0PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxkb3VibGU+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PGxvbmcgZG91YmxlPgBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0llRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJZEVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SWZFRQBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0ltRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJbEVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SWpFRQBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0lpRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJdEVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SXNFRQBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0loRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJYUVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SWNFRQBOMTBlbXNjcmlwdGVuM3ZhbEUATlN0M19fMjEyYmFzaWNfc3RyaW5nSURpTlNfMTFjaGFyX3RyYWl0c0lEaUVFTlNfOWFsbG9jYXRvcklEaUVFRUUATlN0M19fMjIxX19iYXNpY19zdHJpbmdfY29tbW9uSUxiMUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJRHNOU18xMWNoYXJfdHJhaXRzSURzRUVOU185YWxsb2NhdG9ySURzRUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJd05TXzExY2hhcl90cmFpdHNJd0VFTlNfOWFsbG9jYXRvckl3RUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJaE5TXzExY2hhcl90cmFpdHNJaEVFTlNfOWFsbG9jYXRvckloRUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJY05TXzExY2hhcl90cmFpdHNJY0VFTlNfOWFsbG9jYXRvckljRUVFRQAtKyAgIDBYMHgAKG51bGwpAC0wWCswWCAwWC0weCsweCAweABpbmYASU5GAG5hbgBOQU4ALgB0ZXJtaW5hdGluZyB3aXRoICVzIGV4Y2VwdGlvbiBvZiB0eXBlICVzOiAlcwB0ZXJtaW5hdGluZyB3aXRoICVzIGV4Y2VwdGlvbiBvZiB0eXBlICVzAHRlcm1pbmF0aW5nIHdpdGggJXMgZm9yZWlnbiBleGNlcHRpb24AdGVybWluYXRpbmcAdW5jYXVnaHQAU3Q5ZXhjZXB0aW9uAE4xMF9fY3h4YWJpdjExNl9fc2hpbV90eXBlX2luZm9FAFN0OXR5cGVfaW5mbwBOMTBfX2N4eGFiaXYxMjBfX3NpX2NsYXNzX3R5cGVfaW5mb0UATjEwX19jeHhhYml2MTE3X19jbGFzc190eXBlX2luZm9FAHRlcm1pbmF0ZV9oYW5kbGVyIHVuZXhwZWN0ZWRseSByZXR1cm5lZABzdGQ6OmJhZF9hbGxvYwBTdDliYWRfYWxsb2MAU3QxMWxvZ2ljX2Vycm9yAFN0MTNydW50aW1lX2Vycm9yAFN0MTJsZW5ndGhfZXJyb3IAU3QxMm91dF9vZl9yYW5nZQBOMTBfX2N4eGFiaXYxMTdfX3BiYXNlX3R5cGVfaW5mb0UATjEwX19jeHhhYml2MTE5X19wb2ludGVyX3R5cGVfaW5mb0UATjEwX19jeHhhYml2MTIwX19mdW5jdGlvbl90eXBlX2luZm9FAE4xMF9fY3h4YWJpdjEyOV9fcG9pbnRlcl90b19tZW1iZXJfdHlwZV9pbmZvRQBQdXJlIHZpcnR1YWwgZnVuY3Rpb24gY2FsbGVkIQBOMTBfX2N4eGFiaXYxMjNfX2Z1bmRhbWVudGFsX3R5cGVfaW5mb0UAdgBEbgBiAGMAaABhAHMAdABpAGoAbABtAGYAZABOMTBfX2N4eGFiaXYxMjFfX3ZtaV9jbGFzc190eXBlX2luZm9FAF9fY3hhX2d1YXJkX2FjcXVpcmUgZGV0ZWN0ZWQgcmVjdXJzaXZlIGluaXRpYWxpemF0aW9uAHN0ZDo6YmFkX2Z1bmN0aW9uX2NhbGwATlN0M19fMjE3YmFkX2Z1bmN0aW9uX2NhbGxFAE5TdDNfXzIxNF9fc2hhcmVkX2NvdW50RQBOU3QzX18yMTlfX3NoYXJlZF93ZWFrX2NvdW50RQBtdXRleCBsb2NrIGZhaWxlZABiYXNpY19zdHJpbmcAdW5zcGVjaWZpZWQgZ2VuZXJpY19jYXRlZ29yeSBlcnJvcgBVbmtub3duIGVycm9yICVkAGdlbmVyaWMATlN0M19fMjI0X19nZW5lcmljX2Vycm9yX2NhdGVnb3J5RQBOU3QzX18yMTJfX2RvX21lc3NhZ2VFAE5TdDNfXzIxNGVycm9yX2NhdGVnb3J5RQB1bnNwZWNpZmllZCBzeXN0ZW1fY2F0ZWdvcnkgZXJyb3IAc3lzdGVtAE5TdDNfXzIyM19fc3lzdGVtX2Vycm9yX2NhdGVnb3J5RQBOU3QzX18yMTJzeXN0ZW1fZXJyb3JFADogAHZlY3Rvcg==";var Z={};function J(e){e&&Z[e].refcount++}function Y(e){if(!e||Z[e])return e;for(var t in Z)for(var s=+t,i=Z[s].adjusted,r=i.length,n=0;n<r;n++)if(i[n]===e)return s;return e}function $(e){switch(e){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+e)}}var q=void 0;function ee(e){for(var t="",s=e;w[s];)t+=q[w[s++]];return t}var te={},se={},ie={};function re(e){if(void 0===e)return"_unknown";var t=(e=e.replace(/[^a-zA-Z0-9_]/g,"$")).charCodeAt(0);return t>=48&&t<=57?"_"+e:e}function ne(e,t){return e=re(e),new Function("body","return function "+e+'() {\n "use strict"; return body.apply(this, arguments);\n};\n')(t)}function Ae(e,t){var s=ne(t,(function(e){this.name=t,this.message=e;var s=new Error(e).stack;void 0!==s&&(this.stack=this.toString()+"\n"+s.replace(/^Error(:[^\n]*)?\n/,""))}));return s.prototype=Object.create(e.prototype),s.prototype.constructor=s,s.prototype.toString=function(){return void 0===this.message?this.name:this.name+": "+this.message},s}var oe=void 0;function ae(e){throw new oe(e)}var le=void 0;function ce(e){throw new le(e)}function he(e,t,s){function i(t){var i=s(t);i.length!==e.length&&ce("Mismatched type converter count");for(var r=0;r<e.length;++r)ue(e[r],i[r])}e.forEach((function(e){ie[e]=t}));var r=new Array(t.length),n=[],A=0;t.forEach((function(e,t){se.hasOwnProperty(e)?r[t]=se[e]:(n.push(e),te.hasOwnProperty(e)||(te[e]=[]),te[e].push((function(){r[t]=se[e],++A===n.length&&i(r)})))})),0===n.length&&i(r)}function ue(e,t,s){if(s=s||{},!("argPackAdvance"in t))throw new TypeError("registerType registeredInstance requires argPackAdvance");var i=t.name;if(e||ae('type "'+i+'" must have a positive integer typeid pointer'),se.hasOwnProperty(e)){if(s.ignoreDuplicateRegistrations)return;ae("Cannot register type '"+i+"' twice")}if(se[e]=t,delete ie[e],te.hasOwnProperty(e)){var r=te[e];delete te[e],r.forEach((function(e){e()}))}}function de(e){if(!(this instanceof Ee))return!1;if(!(e instanceof Ee))return!1;for(var t=this.$$.ptrType.registeredClass,s=this.$$.ptr,i=e.$$.ptrType.registeredClass,r=e.$$.ptr;t.baseClass;)s=t.upcast(s),t=t.baseClass;for(;i.baseClass;)r=i.upcast(r),i=i.baseClass;return t===i&&s===r}function pe(e){ae(e.$$.ptrType.registeredClass.name+" instance already deleted")}var fe=!1;function ge(e){}function me(e){e.count.value-=1,0===e.count.value&&function(e){e.smartPtr?e.smartPtrType.rawDestructor(e.smartPtr):e.ptrType.registeredClass.rawDestructor(e.ptr)}(e)}function _e(e){return"undefined"==typeof FinalizationGroup?(_e=function(e){return e},e):(fe=new FinalizationGroup((function(e){for(var t=e.next();!t.done;t=e.next()){var s=t.value;s.ptr?me(s):console.warn("object already deleted: "+s.ptr)}})),_e=function(e){return fe.register(e,e.$$,e.$$),e},ge=function(e){fe.unregister(e.$$)},_e(e))}function be(){if(this.$$.ptr||pe(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var e,t=_e(Object.create(Object.getPrototypeOf(this),{$$:{value:(e=this.$$,{count:e.count,deleteScheduled:e.deleteScheduled,preservePointerOnDelete:e.preservePointerOnDelete,ptr:e.ptr,ptrType:e.ptrType,smartPtr:e.smartPtr,smartPtrType:e.smartPtrType})}}));return t.$$.count.value+=1,t.$$.deleteScheduled=!1,t}function ye(){this.$$.ptr||pe(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&ae("Object already scheduled for deletion"),ge(this),me(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function Be(){return!this.$$.ptr}var we=void 0,ve=[];function Ce(){for(;ve.length;){var e=ve.pop();e.$$.deleteScheduled=!1,e.delete()}}function Me(){return this.$$.ptr||pe(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&ae("Object already scheduled for deletion"),ve.push(this),1===ve.length&&we&&we(Ce),this.$$.deleteScheduled=!0,this}function Ee(){}var Fe={};function xe(e,t,s){if(void 0===e[t].overloadTable){var i=e[t];e[t]=function(){return e[t].overloadTable.hasOwnProperty(arguments.length)||ae("Function '"+s+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+e[t].overloadTable+")!"),e[t].overloadTable[arguments.length].apply(this,arguments)},e[t].overloadTable=[],e[t].overloadTable[i.argCount]=i}}function Ue(e,t,s,i,r,n,A,o){this.name=e,this.constructor=t,this.instancePrototype=s,this.rawDestructor=i,this.baseClass=r,this.getActualType=n,this.upcast=A,this.downcast=o,this.pureVirtualFunctions=[]}function Ie(e,t,s){for(;t!==s;)t.upcast||ae("Expected null or instance of "+s.name+", got an instance of "+t.name),e=t.upcast(e),t=t.baseClass;return e}function Te(e,t){if(null===t)return this.isReference&&ae("null is not a valid "+this.name),0;t.$$||ae('Cannot pass "'+At(t)+'" as a '+this.name),t.$$.ptr||ae("Cannot pass deleted object as a pointer of type "+this.name);var s=t.$$.ptrType.registeredClass;return Ie(t.$$.ptr,s,this.registeredClass)}function Pe(e,t){var s;if(null===t)return this.isReference&&ae("null is not a valid "+this.name),this.isSmartPointer?(s=this.rawConstructor(),null!==e&&e.push(this.rawDestructor,s),s):0;t.$$||ae('Cannot pass "'+At(t)+'" as a '+this.name),t.$$.ptr||ae("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&t.$$.ptrType.isConst&&ae("Cannot convert argument of type "+(t.$$.smartPtrType?t.$$.smartPtrType.name:t.$$.ptrType.name)+" to parameter type "+this.name);var i=t.$$.ptrType.registeredClass;if(s=Ie(t.$$.ptr,i,this.registeredClass),this.isSmartPointer)switch(void 0===t.$$.smartPtr&&ae("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:t.$$.smartPtrType===this?s=t.$$.smartPtr:ae("Cannot convert argument of type "+(t.$$.smartPtrType?t.$$.smartPtrType.name:t.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:s=t.$$.smartPtr;break;case 2:if(t.$$.smartPtrType===this)s=t.$$.smartPtr;else{var r=t.clone();s=this.rawShare(s,nt((function(){r.delete()}))),null!==e&&e.push(this.rawDestructor,s)}break;default:ae("Unsupporting sharing policy")}return s}function Se(e,t){if(null===t)return this.isReference&&ae("null is not a valid "+this.name),0;t.$$||ae('Cannot pass "'+At(t)+'" as a '+this.name),t.$$.ptr||ae("Cannot pass deleted object as a pointer of type "+this.name),t.$$.ptrType.isConst&&ae("Cannot convert argument of type "+t.$$.ptrType.name+" to parameter type "+this.name);var s=t.$$.ptrType.registeredClass;return Ie(t.$$.ptr,s,this.registeredClass)}function De(e){return this.fromWireType(E[e>>2])}function ke(e){return this.rawGetPointee&&(e=this.rawGetPointee(e)),e}function Qe(e){this.rawDestructor&&this.rawDestructor(e)}function Re(e){null!==e&&e.delete()}function Oe(e,t,s){if(t===s)return e;if(void 0===s.baseClass)return null;var i=Oe(e,t,s.baseClass);return null===i?null:s.downcast(i)}function Ve(){return Object.keys(Ne).length}function Le(){var e=[];for(var t in Ne)Ne.hasOwnProperty(t)&&e.push(Ne[t]);return e}function He(e){we=e,ve.length&&we&&we(Ce)}var Ne={};function Ge(e,t){return t=function(e,t){for(void 0===t&&ae("ptr should not be undefined");e.baseClass;)t=e.upcast(t),e=e.baseClass;return t}(e,t),Ne[t]}function je(e,t){return t.ptrType&&t.ptr||ce("makeClassHandle requires ptr and ptrType"),!!t.smartPtrType!==!!t.smartPtr&&ce("Both smartPtrType and smartPtr must be specified"),t.count={value:1},_e(Object.create(e,{$$:{value:t}}))}function ze(e){var t=this.getPointee(e);if(!t)return this.destructor(e),null;var s=Ge(this.registeredClass,t);if(void 0!==s){if(0===s.$$.count.value)return s.$$.ptr=t,s.$$.smartPtr=e,s.clone();var i=s.clone();return this.destructor(e),i}function r(){return this.isSmartPointer?je(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:t,smartPtrType:this,smartPtr:e}):je(this.registeredClass.instancePrototype,{ptrType:this,ptr:e})}var n,A=this.registeredClass.getActualType(t),o=Fe[A];if(!o)return r.call(this);n=this.isConst?o.constPointerType:o.pointerType;var a=Oe(t,this.registeredClass,n.registeredClass);return null===a?r.call(this):this.isSmartPointer?je(n.registeredClass.instancePrototype,{ptrType:n,ptr:a,smartPtrType:this,smartPtr:e}):je(n.registeredClass.instancePrototype,{ptrType:n,ptr:a})}function We(e,t,s,i,r,n,A,o,a,l,c){this.name=e,this.registeredClass=t,this.isReference=s,this.isConst=i,this.isSmartPointer=r,this.pointeeType=n,this.sharingPolicy=A,this.rawGetPointee=o,this.rawConstructor=a,this.rawShare=l,this.rawDestructor=c,r||void 0!==t.baseClass?this.toWireType=Pe:i?(this.toWireType=Te,this.destructorFunction=null):(this.toWireType=Se,this.destructorFunction=null)}function Xe(e,s){e=ee(e);var i=function(t){for(var i=[],r=1;r<e.length;++r)i.push("a"+r);var n="return function "+("dynCall_"+e+"_"+s)+"("+i.join(", ")+") {\n";return n+=" return dynCall(rawFunction"+(i.length?", ":"")+i.join(", ")+");\n",n+="};\n",new Function("dynCall","rawFunction",n)(t,s)}(t["dynCall_"+e]);return"function"!=typeof i&&ae("unknown function pointer with signature "+e+": "+s),i}var Ke=void 0;function Ze(e){var t=ft(e),s=ee(t);return gt(t),s}function Je(e,t){var s=[],i={};throw t.forEach((function e(t){i[t]||se[t]||(ie[t]?ie[t].forEach(e):(s.push(t),i[t]=!0))})),new Ke(e+": "+s.map(Ze).join([", "]))}function Ye(e,t){for(var s=[],i=0;i<e;i++)s.push(M[(t>>2)+i]);return s}function $e(e){for(;e.length;){var t=e.pop();e.pop()(t)}}function qe(e,t,s,i,r){var n=t.length;n<2&&ae("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var A=null!==t[1]&&null!==s,o=!1,a=1;a<t.length;++a)if(null!==t[a]&&void 0===t[a].destructorFunction){o=!0;break}var l="void"!==t[0].name,c="",h="";for(a=0;a<n-2;++a)c+=(0!==a?", ":"")+"arg"+a,h+=(0!==a?", ":"")+"arg"+a+"Wired";var u="return function "+re(e)+"("+c+") {\nif (arguments.length !== "+(n-2)+") {\nthrowBindingError('function "+e+" called with ' + arguments.length + ' arguments, expected "+(n-2)+" args!');\n}\n";o&&(u+="var destructors = [];\n");var d=o?"destructors":"null",p=["throwBindingError","invoker","fn","runDestructors","retType","classParam"],f=[ae,i,r,$e,t[0],t[1]];A&&(u+="var thisWired = classParam.toWireType("+d+", this);\n");for(a=0;a<n-2;++a)u+="var arg"+a+"Wired = argType"+a+".toWireType("+d+", arg"+a+"); // "+t[a+2].name+"\n",p.push("argType"+a),f.push(t[a+2]);if(A&&(h="thisWired"+(h.length>0?", ":"")+h),u+=(l?"var rv = ":"")+"invoker(fn"+(h.length>0?", ":"")+h+");\n",o)u+="runDestructors(destructors);\n";else for(a=A?1:2;a<t.length;++a){var g=1===a?"thisWired":"arg"+(a-2)+"Wired";null!==t[a].destructorFunction&&(u+=g+"_dtor("+g+"); // "+t[a].name+"\n",p.push(g+"_dtor"),f.push(t[a].destructorFunction))}return l&&(u+="var ret = retType.fromWireType(rv);\nreturn ret;\n"),u+="}\n",p.push(u),function(e,t){if(!(e instanceof Function))throw new TypeError("new_ called with constructor type "+typeof e+" which is not a function");var s=ne(e.name||"unknownFunctionName",(function(){}));s.prototype=e.prototype;var i=new s,r=e.apply(i,t);return r instanceof Object?r:i}(Function,p).apply(null,f)}var et=[],tt=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function st(e){e>4&&0==--tt[e].refcount&&(tt[e]=void 0,et.push(e))}function it(){for(var e=0,t=5;t<tt.length;++t)void 0!==tt[t]&&++e;return e}function rt(){for(var e=5;e<tt.length;++e)if(void 0!==tt[e])return tt[e];return null}function nt(e){switch(e){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:var t=et.length?et.pop():tt.length;return tt[t]={refcount:1,value:e},t}}function At(e){if(null===e)return"null";var t=typeof e;return"object"===t||"array"===t||"function"===t?e.toString():""+e}function ot(e,t){switch(t){case 2:return function(e){return this.fromWireType(F[e>>2])};case 3:return function(e){return this.fromWireType(x[e>>3])};default:throw new TypeError("Unknown float type: "+e)}}function at(e,t,s){switch(t){case 0:return s?function(e){return B[e]}:function(e){return w[e]};case 1:return s?function(e){return v[e>>1]}:function(e){return C[e>>1]};case 2:return s?function(e){return M[e>>2]}:function(e){return E[e>>2]};default:throw new TypeError("Unknown integer type: "+e)}}function lt(e){for(var t=[],s=0;s<e.length;s++){var i=e[s];i>255&&(i&=255),t.push(String.fromCharCode(i))}return t.join("")}!function(){for(var e=new Array(256),t=0;t<256;++t)e[t]=String.fromCharCode(t);q=e}(),oe=t.BindingError=Ae(Error,"BindingError"),le=t.InternalError=Ae(Error,"InternalError"),Ee.prototype.isAliasOf=de,Ee.prototype.clone=be,Ee.prototype.delete=ye,Ee.prototype.isDeleted=Be,Ee.prototype.deleteLater=Me,We.prototype.getPointee=ke,We.prototype.destructor=Qe,We.prototype.argPackAdvance=8,We.prototype.readValueFromPointer=De,We.prototype.deleteObject=Re,We.prototype.fromWireType=ze,t.getInheritedInstanceCount=Ve,t.getLiveInheritedInstances=Le,t.flushPendingDeletes=Ce,t.setDelayFunction=He,Ke=t.UnboundTypeError=Ae(Error,"UnboundTypeError"),t.count_emval_handles=it,t.get_first_emval=rt;var ct="function"==typeof atob?atob:function(e){var t,s,i,r,n,A,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",a="",l=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{t=o.indexOf(e.charAt(l++))<<2|(r=o.indexOf(e.charAt(l++)))>>4,s=(15&r)<<4|(n=o.indexOf(e.charAt(l++)))>>2,i=(3&n)<<6|(A=o.indexOf(e.charAt(l++))),a+=String.fromCharCode(t),64!==n&&(a+=String.fromCharCode(s)),64!==A&&(a+=String.fromCharCode(i))}while(l<e.length);return a};function ht(e){if(K(e))return function(e){if("boolean"==typeof n&&n){var t;try{t=Buffer.from(e,"base64")}catch(s){t=new Buffer(e,"base64")}return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}try{for(var s=ct(e),i=new Uint8Array(s.length),r=0;r<s.length;++r)i[r]=s.charCodeAt(r);return i}catch(e){throw new Error("Converting base64 string to bytes failed.")}}(e.slice(X.length))}var ut={A:function(e,t,s){w.copyWithin(e,t,t+s)},B:function(e){z("OOM")},C:function(){z("trap!")},D:22368,a:z,b:function(e){f=e},c:function(){return f},d:function(e){return mt(e)},e:function(e){var t=Z[e];return t&&!t.caught&&(t.caught=!0,pt.uncaught_exceptions--),t&&(t.rethrown=!1),J(Y(e)),e},f:function(e,t,s){throw Z[e]={ptr:e,adjusted:[e],type:t,destructor:s,refcount:0,caught:!1,rethrown:!1},"uncaught_exception"in pt?pt.uncaught_exceptions++:pt.uncaught_exceptions=1,e},g:function(){return pt.uncaught_exceptions},h:J,i:Y,j:function(){},k:function(e,t,s,i,r){var n=$(s);ue(e,{name:t=ee(t),fromWireType:function(e){return!!e},toWireType:function(e,t){return t?i:r},argPackAdvance:8,readValueFromPointer:function(e){var i;if(1===s)i=B;else if(2===s)i=v;else{if(4!==s)throw new TypeError("Unknown boolean type size: "+t);i=M}return this.fromWireType(i[e>>n])},destructorFunction:null})},l:function(e,s,i,r,n,A,o,a,l,c,h,u,d){h=ee(h),A=Xe(n,A),a&&(a=Xe(o,a)),c&&(c=Xe(l,c)),d=Xe(u,d);var p=re(h);!function(e,s,i){t.hasOwnProperty(e)?((void 0===i||void 0!==t[e].overloadTable&&void 0!==t[e].overloadTable[i])&&ae("Cannot register public name '"+e+"' twice"),xe(t,e,e),t.hasOwnProperty(i)&&ae("Cannot register multiple overloads of a function with the same number of arguments ("+i+")!"),t[e].overloadTable[i]=s):(t[e]=s,void 0!==i&&(t[e].numArguments=i))}(p,(function(){Je("Cannot construct "+h+" due to unbound types",[r])})),he([e,s,i],r?[r]:[],(function(s){var i,n;s=s[0],n=r?(i=s.registeredClass).instancePrototype:Ee.prototype;var o=ne(p,(function(){if(Object.getPrototypeOf(this)!==l)throw new oe("Use 'new' to construct "+h);if(void 0===u.constructor_body)throw new oe(h+" has no accessible constructor");var e=u.constructor_body[arguments.length];if(void 0===e)throw new oe("Tried to invoke ctor of "+h+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(u.constructor_body).toString()+") parameters instead!");return e.apply(this,arguments)})),l=Object.create(n,{constructor:{value:o}});o.prototype=l;var u=new Ue(h,o,l,d,i,A,a,c),f=new We(h,u,!0,!1,!1),g=new We(h+"*",u,!1,!1,!1),m=new We(h+" const*",u,!1,!0,!1);return Fe[e]={pointerType:g,constPointerType:m},function(e,s,i){t.hasOwnProperty(e)||ce("Replacing nonexistant public symbol"),void 0!==t[e].overloadTable&&void 0!==i?t[e].overloadTable[i]=s:(t[e]=s,t[e].argCount=i)}(p,o),[f,g,m]}))},m:function(e,t,s,i,r,n){m(t>0);var A=Ye(t,s);r=Xe(i,r);var o=[n],a=[];he([],[e],(function(e){var s="constructor "+(e=e[0]).name;if(void 0===e.registeredClass.constructor_body&&(e.registeredClass.constructor_body=[]),void 0!==e.registeredClass.constructor_body[t-1])throw new oe("Cannot register multiple constructors with identical number of parameters ("+(t-1)+") for class '"+e.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");return e.registeredClass.constructor_body[t-1]=function(){Je("Cannot construct "+e.name+" due to unbound types",A)},he([],A,(function(i){return e.registeredClass.constructor_body[t-1]=function(){arguments.length!==t-1&&ae(s+" called with "+arguments.length+" arguments, expected "+(t-1)),a.length=0,o.length=t;for(var e=1;e<t;++e)o[e]=i[e].toWireType(a,arguments[e-1]);var n=r.apply(null,o);return $e(a),i[0].fromWireType(n)},[]})),[]}))},n:function(e,t,s,i,r,n,A,o){var a=Ye(s,i);t=ee(t),n=Xe(r,n),he([],[e],(function(e){var i=(e=e[0]).name+"."+t;function r(){Je("Cannot call "+i+" due to unbound types",a)}o&&e.registeredClass.pureVirtualFunctions.push(t);var l=e.registeredClass.instancePrototype,c=l[t];return void 0===c||void 0===c.overloadTable&&c.className!==e.name&&c.argCount===s-2?(r.argCount=s-2,r.className=e.name,l[t]=r):(xe(l,t,i),l[t].overloadTable[s-2]=r),he([],a,(function(r){var o=qe(i,r,e,n,A);return void 0===l[t].overloadTable?(o.argCount=s-2,l[t]=o):l[t].overloadTable[s-2]=o,[]})),[]}))},o:function(e,t){ue(e,{name:t=ee(t),fromWireType:function(e){var t=tt[e].value;return st(e),t},toWireType:function(e,t){return nt(t)},argPackAdvance:8,readValueFromPointer:De,destructorFunction:null})},p:function(e,t,s){var i=$(s);ue(e,{name:t=ee(t),fromWireType:function(e){return e},toWireType:function(e,t){if("number"!=typeof t&&"boolean"!=typeof t)throw new TypeError('Cannot convert "'+At(t)+'" to '+this.name);return t},argPackAdvance:8,readValueFromPointer:ot(t,i),destructorFunction:null})},q:function(e,t,s,i,r){t=ee(t),-1===r&&(r=4294967295);var n=$(s),A=function(e){return e};if(0===i){var o=32-8*s;A=function(e){return e<<o>>>o}}var a=-1!=t.indexOf("unsigned");ue(e,{name:t,fromWireType:A,toWireType:function(e,s){if("number"!=typeof s&&"boolean"!=typeof s)throw new TypeError('Cannot convert "'+At(s)+'" to '+this.name);if(s<i||s>r)throw new TypeError('Passing a number "'+At(s)+'" from JS side to C/C++ side to an argument of type "'+t+'", which is outside the valid range ['+i+", "+r+"]!");return a?s>>>0:0|s},argPackAdvance:8,readValueFromPointer:at(t,n,0!==i),destructorFunction:null})},r:function(e,t,s){var i=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][t];function r(e){var t=E,s=t[e>>=2],r=t[e+1];return new i(y,r,s)}ue(e,{name:s=ee(s),fromWireType:r,argPackAdvance:8,readValueFromPointer:r},{ignoreDuplicateRegistrations:!0})},s:function(e,t){var s="std::string"===(t=ee(t));ue(e,{name:t,fromWireType:function(e){var t,i=E[e>>2];if(s)for(var r=e+4,n=0;n<=i;++n){var A=e+4+n;if(0==w[A]||n==i){var o=b(r,A-r);void 0===t?t=o:(t+=String.fromCharCode(0),t+=o),r=A+1}}else{var a=new Array(i);for(n=0;n<i;++n)a[n]=String.fromCharCode(w[e+4+n]);t=a.join("")}return gt(e),t},toWireType:function(e,t){var i;t instanceof ArrayBuffer&&(t=new Uint8Array(t));var r="string"==typeof t;r||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int8Array||ae("Cannot pass non-string to std::string"),i=s&&r?function(){return function(e){for(var t=0,s=0;s<e.length;++s){var i=e.charCodeAt(s);i>=55296&&i<=57343&&(i=65536+((1023&i)<<10)|1023&e.charCodeAt(++s)),i<=127?++t:t+=i<=2047?2:i<=65535?3:4}return t}(t)}:function(){return t.length};var n=i(),A=mt(4+n+1);if(E[A>>2]=n,s&&r)(function(e,t,s,i){if(!(i>0))return 0;for(var r=s,n=s+i-1,A=0;A<e.length;++A){var o=e.charCodeAt(A);if(o>=55296&&o<=57343&&(o=65536+((1023&o)<<10)|1023&e.charCodeAt(++A)),o<=127){if(s>=n)break;t[s++]=o}else if(o<=2047){if(s+1>=n)break;t[s++]=192|o>>6,t[s++]=128|63&o}else if(o<=65535){if(s+2>=n)break;t[s++]=224|o>>12,t[s++]=128|o>>6&63,t[s++]=128|63&o}else{if(s+3>=n)break;t[s++]=240|o>>18,t[s++]=128|o>>12&63,t[s++]=128|o>>6&63,t[s++]=128|63&o}}t[s]=0})(t,w,A+4,n+1);else if(r)for(var o=0;o<n;++o){var a=t.charCodeAt(o);a>255&&(gt(A),ae("String has UTF-16 code units that do not fit in 8 bits")),w[A+4+o]=a}else for(o=0;o<n;++o)w[A+4+o]=t[o];return null!==e&&e.push(gt,A),A},argPackAdvance:8,readValueFromPointer:De,destructorFunction:function(e){gt(e)}})},t:function(e,t,s){var i,r,n,A,o;s=ee(s),2===t?(i=I,r=T,A=P,n=function(){return C},o=1):4===t&&(i=S,r=D,A=k,n=function(){return E},o=2),ue(e,{name:s,fromWireType:function(e){for(var s,r=E[e>>2],A=n(),a=e+4,l=0;l<=r;++l){var c=e+4+l*t;if(0==A[c>>o]||l==r){var h=i(a,c-a);void 0===s?s=h:(s+=String.fromCharCode(0),s+=h),a=c+t}}return gt(e),s},toWireType:function(e,i){"string"!=typeof i&&ae("Cannot pass non-string to C++ string type "+s);var n=A(i),a=mt(4+n+t);return E[a>>2]=n>>o,r(i,a+4,n+t),null!==e&&e.push(gt,a),a},argPackAdvance:8,readValueFromPointer:De,destructorFunction:function(e){gt(e)}})},u:function(e,t){ue(e,{isVoid:!0,name:t=ee(t),argPackAdvance:0,fromWireType:function(){},toWireType:function(e,t){}})},v:st,w:nt,x:function(){z()},y:At,z:function(){return w.length}},dt=function(e,t,s){"use asm";var i=new e.Int8Array(s),r=new e.Int16Array(s),n=new e.Int32Array(s),A=new e.Uint8Array(s),o=new e.Uint16Array(s),a=new e.Float32Array(s),l=new e.Float64Array(s),c=t.D|0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0.0,b=e.Math.imul,y=e.Math.clz32,B=t.a,w=t.b,v=t.c,C=t.d,M=t.e,E=t.f,F=t.g,x=t.h,U=t.i,I=t.j,T=t.k,P=t.l,S=t.m,D=t.n,k=t.o,Q=t.p,R=t.q,O=t.r,V=t.s,L=t.t,H=t.u,N=t.v,G=t.w,j=t.x,z=t.y,W=t.z,X=t.A,K=t.B,Z=t.C,J=22384,Y=5265264,$=0.0;function q(){Jh();Yh()}function ee(){te(0);return}function te(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0;e=J;J=J+16|0;t=e+8|0;s=e;dc();u=fc()|0;A=gc()|0;r=_c()|0;o=bc()|0;a=yc()|0;l=Bc()|0;c=Fc()|0;h=xc()|0;i=xc()|0;P(r|0,o|0,a|0,l|0,c|0,9,h|0,u|0,i|0,A|0,6204,Uc()|0,138);Tc(1);n[s>>2]=5;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Oc(6211,t);n[s>>2]=3;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Kc(6216,t);n[s>>2]=10;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];sh(6225,t);ch();A=uh()|0;i=dh()|0;u=fh()|0;h=gh()|0;c=mh()|0;l=Bc()|0;a=Fc()|0;o=xc()|0;r=xc()|0;P(u|0,h|0,c|0,l|0,a|0,11,o|0,A|0,r|0,i|0,6234,Uc()|0,139);Ch(2);n[s>>2]=6;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Th(6211,t);n[s>>2]=4;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Oh(6248,t);n[s>>2]=5;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Oh(6265,t);n[s>>2]=6;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Oh(6280,t);n[s>>2]=7;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];jh(6216,t);J=e;return}function se(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0,a=0;i=J;J=J+32|0;o=i+16|0;r=i+8|0;a=i;A=Zf(20)|0;ce(A,t,s);n[a>>2]=0;n[o>>2]=n[a>>2];ue(r,A,o);t=n[r>>2]|0;n[r>>2]=n[e>>2];n[e>>2]=t;t=r+4|0;s=e+4|0;A=n[t>>2]|0;n[t>>2]=n[s>>2];n[s>>2]=A;de(r);s=Zf(352)|0;he(s,n[e>>2]|0);A=e+8|0;n[a>>2]=0;n[o>>2]=n[a>>2];we(r,s,o);s=n[r>>2]|0;n[r>>2]=n[A>>2];n[A>>2]=s;A=r+4|0;s=e+12|0;t=n[A>>2]|0;n[A>>2]=n[s>>2];n[s>>2]=t;ve(r);J=i;return}function ie(e,t){e=e|0;t=t|0;Ks(n[e+8>>2]|0,t);return}function re(e){e=e|0;e=(Do(n[e+8>>2]|0)|0)+107|0;return A[e>>0]|A[e+1>>0]<<8|A[e+2>>0]<<16|A[e+3>>0]<<24|0}function ne(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0,a=0;i=J;J=J+32|0;A=i+16|0;r=i+8|0;o=i;a=Zf(12)|0;ko(a,t,s);n[o>>2]=0;n[A>>2]=n[o>>2];Vo(r,a,A);a=n[r>>2]|0;n[r>>2]=n[e>>2];n[e>>2]=a;a=r+4|0;s=e+4|0;t=n[a>>2]|0;n[a>>2]=n[s>>2];n[s>>2]=t;Lo(r);s=e+8|0;t=Zf(12)|0;Qo(t,n[e>>2]|0);n[o>>2]=0;n[A>>2]=n[o>>2];Wo(r,t,A);t=n[r>>2]|0;n[r>>2]=n[s>>2];n[s>>2]=t;t=r+4|0;o=e+12|0;a=n[t>>2]|0;n[t>>2]=n[o>>2];n[o>>2]=a;Xo(r);Ro(r,n[s>>2]|0);s=e+16|0;o=n[r>>2]|0;a=r+4|0;t=n[a>>2]|0;n[r>>2]=0;n[a>>2]=0;n[A>>2]=n[s>>2];n[s>>2]=o;s=e+20|0;n[A+4>>2]=n[s>>2];n[s>>2]=t;Oo(A);Oo(r);J=i;return}function Ae(e,t){e=e|0;t=t|0;var s=0;e=e+16|0;s=n[e>>2]|0;e:do{if(s|0)switch(t|0){case 4:{ua(s);break e}case 8:{da(s);da(n[e>>2]|0);break e}default:break e}}while(0);return}function oe(e,t){e=e|0;t=t|0;var s=0;s=e+16|0;e=n[s>>2]|0;e:do{if(e|0){switch(t|0){case 1:{qa(e);break e}case 2:{el(e);break e}case 8:{ua(e);e=n[s>>2]|0;break}case 4:break;default:break e}ua(e)}}while(0);return}function ae(e,t){e=e|0;t=t|0;var s=0;s=e+16|0;e=n[s>>2]|0;e:do{if(e|0){switch(t|0){case 1:{kl(e);break e}case 2:{Ql(e);break e}case 8:{da(e);e=n[s>>2]|0;break}case 4:break;default:break e}da(e)}}while(0);return}function le(e,t){e=e|0;t=t|0;e=n[e+16>>2]|0;if(e|0)Hm[n[n[e>>2]>>2]&63](e,t)|0;return}function ce(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;n[e+4>>2]=s;n[e+8>>2]=0;i[e+12>>0]=0;i[e+13>>0]=0;n[e+16>>2]=0;return}function he(e,t){e=e|0;t=t|0;n[e>>2]=t;Oe(e+4|0,t);Ve(e+247|0);n[e+288>>2]=0;n[e+292>>2]=0;n[e+296>>2]=0;Le(e+300|0);t=e+312|0;n[t>>2]=0;n[t+4>>2]=0;n[t+8>>2]=0;n[t+12>>2]=0;He(e+328|0);Ne(e);return}function ue(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4296;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;pe(e,i);J=s;return}function de(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function pe(e,t){e=e|0;t=t|0;return}function fe(e){e=e|0;M(e|0)|0;tf()}function ge(e){e=e|0;Ag(e);qp(e);return}function me(e){e=e|0;e=n[e+12>>2]|0;if(e|0)qp(e);return}function _e(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==6407?e+12|0:0)|0}function be(e){e=e|0;ye(e,16);return}function ye(e,t){e=e|0;t=t|0;Be(e);return}function Be(e){e=e|0;qp(e);return}function we(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4324;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ce(e,i);J=s;return}function ve(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Ce(e,t){e=e|0;t=t|0;return}function Me(e){e=e|0;Ag(e);qp(e);return}function Ee(e){e=e|0;e=n[e+12>>2]|0;if(e|0){Ue(e);qp(e)}return}function Fe(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==6605?e+12|0:0)|0}function xe(e){e=e|0;ye(e,16);return}function Ue(e){e=e|0;Ie(e+320|0);Te(e+312|0);Pe(e+300|0);Qe(e+288|0);Se(e+247|0);De(e+4|0);return}function Ie(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Te(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Pe(e){e=e|0;ke(e);return}function Se(e){e=e|0;e=e+34|0;e=A[e>>0]|A[e+1>>0]<<8|A[e+2>>0]<<16|A[e+3>>0]<<24;if(e|0)Yf(e);return}function De(e){e=e|0;Re(n[e+12>>2]|0);return}function ke(e){e=e|0;var t=0,s=0;t=n[e>>2]|0;s=t;if(t|0){n[e+4>>2]=s;ye(t,(n[e+8>>2]|0)-s|0)}return}function Qe(e){e=e|0;var t=0,s=0;t=n[e>>2]|0;s=t;if(t|0){n[e+4>>2]=s;ye(t,(n[e+8>>2]|0)-s|0)}return}function Re(e){e=e|0;Zg(n[e+-4>>2]|0);return}function Oe(e,t){e=e|0;t=t|0;n[e>>2]=t;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=Ge(1048576)|0;return}function Ve(e){e=e|0;var t=0;t=e+32|0;i[t>>0]=0;i[t+1>>0]=0;e=e+34|0;i[e>>0]=0;i[e+1>>0]=0;i[e+2>>0]=0;i[e+3>>0]=0;return}function Le(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;return}function He(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;e=e+16|0;n[e>>2]=-1;n[e+4>>2]=-1;return}function Ne(e){e=e|0;var t=0,s=0,r=0,A=0,o=0,a=0;a=J;J=J+64|0;A=a+32|0;s=a+56|0;t=a+16|0;o=a;je(n[e>>2]|0,s,4);it(A,s,s+4|0);s=st(6693)|0;r=i[A+11>>0]|0;if((s|0)==((r<<24>>24<0?n[A+4>>2]|0:r&255)|0)){r=(Cg(A,0,-1,6693,s)|0)==0;bg(A);if(r){s=n[e>>2]|0;n[t>>2]=0;n[t+4>>2]=0;n[t+8>>2]=0;n[t+12>>2]=0;n[A>>2]=n[t>>2];n[A+4>>2]=n[t+4>>2];n[A+8>>2]=n[t+8>>2];n[A+12>>2]=n[t+12>>2];We(s,A);s=e+20|0;je(n[e>>2]|0,s,227);Xe(e,s);r=Ke()|0;t=n[r>>2]|0;r=n[r+4>>2]|0;if((t|0)!=(r|0))do{Ze(A,t);Je(A,s);Ye(A);t=t+24|0}while((t|0)!=(r|0));$e(e);qe(e);et(n[e>>2]|0);r=n[e>>2]|0;t=(n[e+116>>2]|0)+8|0;s=o;n[s>>2]=0;n[s+4>>2]=0;s=o+8|0;n[s>>2]=t;n[s+4>>2]=0;n[A>>2]=n[o>>2];n[A+4>>2]=n[o+4>>2];n[A+8>>2]=n[o+8>>2];n[A+12>>2]=n[o+12>>2];We(r,A);tt(e+4|0);J=a;return}}else bg(A);a=C(8)|0;ze(a);E(a|0,2592,8)}function Ge(e){e=e|0;var t=0;t=Kg(e+68|0)|0;e=t+68&-64;n[e+-4>>2]=t;return e|0}function je(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0;a=e+13|0;if(!(i[a>>0]|0)){o=e+4|0;r=n[o>>2]|0;l=e+8|0;A=n[l>>2]|0;c=r-A|0;s=(c|0)<(s|0)?c:s;if(s){um(t|0,(n[e>>2]|0)+A|0,s|0)|0;A=n[l>>2]|0;r=n[o>>2]|0}c=A+s|0;n[l>>2]=c;n[e+16>>2]=s;if((c|0)>=(r|0))i[a>>0]=1}else i[e+12>>0]=1;return}function ze(e){e=e|0;pg(e,6791);n[e>>2]=4352;return}function We(e,t){e=e|0;t=t|0;var s=0,r=0,A=0;A=t+8|0;t=n[A>>2]|0;A=n[A+4>>2]|0;s=n[e+4>>2]|0;r=((s|0)<0)<<31>>31;if((A|0)<(r|0)|(A|0)==(r|0)&t>>>0<s>>>0)n[e+8>>2]=t;else i[e+12>>0]=1;return}function Xe(e,t){e=e|0;t=t|0;var s=0.0,r=0.0,n=0,A=0.0,o=0,a=0.0,h=0,u=0.0,d=0,p=0.0;d=t+179|0;i[c>>0]=i[d>>0];i[c+1>>0]=i[d+1>>0];i[c+2>>0]=i[d+2>>0];i[c+3>>0]=i[d+3>>0];i[c+4>>0]=i[d+4>>0];i[c+5>>0]=i[d+5>>0];i[c+6>>0]=i[d+6>>0];i[c+7>>0]=i[d+7>>0];u=+l[c>>3];o=t+187|0;i[c>>0]=i[o>>0];i[c+1>>0]=i[o+1>>0];i[c+2>>0]=i[o+2>>0];i[c+3>>0]=i[o+3>>0];i[c+4>>0]=i[o+4>>0];i[c+5>>0]=i[o+5>>0];i[c+6>>0]=i[o+6>>0];i[c+7>>0]=i[o+7>>0];p=+l[c>>3];e=t+195|0;i[c>>0]=i[e>>0];i[c+1>>0]=i[e+1>>0];i[c+2>>0]=i[e+2>>0];i[c+3>>0]=i[e+3>>0];i[c+4>>0]=i[e+4>>0];i[c+5>>0]=i[e+5>>0];i[c+6>>0]=i[e+6>>0];i[c+7>>0]=i[e+7>>0];A=+l[c>>3];h=t+203|0;i[c>>0]=i[h>>0];i[c+1>>0]=i[h+1>>0];i[c+2>>0]=i[h+2>>0];i[c+3>>0]=i[h+3>>0];i[c+4>>0]=i[h+4>>0];i[c+5>>0]=i[h+5>>0];i[c+6>>0]=i[h+6>>0];i[c+7>>0]=i[h+7>>0];a=+l[c>>3];n=t+211|0;i[c>>0]=i[n>>0];i[c+1>>0]=i[n+1>>0];i[c+2>>0]=i[n+2>>0];i[c+3>>0]=i[n+3>>0];i[c+4>>0]=i[n+4>>0];i[c+5>>0]=i[n+5>>0];i[c+6>>0]=i[n+6>>0];i[c+7>>0]=i[n+7>>0];s=+l[c>>3];t=t+219|0;i[c>>0]=i[t>>0];i[c+1>>0]=i[t+1>>0];i[c+2>>0]=i[t+2>>0];i[c+3>>0]=i[t+3>>0];i[c+4>>0]=i[t+4>>0];i[c+5>>0]=i[t+5>>0];i[c+6>>0]=i[t+6>>0];i[c+7>>0]=i[t+7>>0];r=+l[c>>3];l[c>>3]=p;i[d>>0]=i[c>>0];i[d+1>>0]=i[c+1>>0];i[d+2>>0]=i[c+2>>0];i[d+3>>0]=i[c+3>>0];i[d+4>>0]=i[c+4>>0];i[d+5>>0]=i[c+5>>0];i[d+6>>0]=i[c+6>>0];i[d+7>>0]=i[c+7>>0];l[c>>3]=u;i[h>>0]=i[c>>0];i[h+1>>0]=i[c+1>>0];i[h+2>>0]=i[c+2>>0];i[h+3>>0]=i[c+3>>0];i[h+4>>0]=i[c+4>>0];i[h+5>>0]=i[c+5>>0];i[h+6>>0]=i[c+6>>0];i[h+7>>0]=i[c+7>>0];l[c>>3]=a;i[o>>0]=i[c>>0];i[o+1>>0]=i[c+1>>0];i[o+2>>0]=i[c+2>>0];i[o+3>>0]=i[c+3>>0];i[o+4>>0]=i[c+4>>0];i[o+5>>0]=i[c+5>>0];i[o+6>>0]=i[c+6>>0];i[o+7>>0]=i[c+7>>0];l[c>>3]=A;i[n>>0]=i[c>>0];i[n+1>>0]=i[c+1>>0];i[n+2>>0]=i[c+2>>0];i[n+3>>0]=i[c+3>>0];i[n+4>>0]=i[c+4>>0];i[n+5>>0]=i[c+5>>0];i[n+6>>0]=i[c+6>>0];i[n+7>>0]=i[c+7>>0];l[c>>3]=r;i[e>>0]=i[c>>0];i[e+1>>0]=i[c+1>>0];i[e+2>>0]=i[c+2>>0];i[e+3>>0]=i[c+3>>0];i[e+4>>0]=i[c+4>>0];i[e+5>>0]=i[c+5>>0];i[e+6>>0]=i[c+6>>0];i[e+7>>0]=i[c+7>>0];l[c>>3]=s;i[t>>0]=i[c>>0];i[t+1>>0]=i[c+1>>0];i[t+2>>0]=i[c+2>>0];i[t+3>>0]=i[c+3>>0];i[t+4>>0]=i[c+4>>0];i[t+5>>0]=i[c+5>>0];i[t+6>>0]=i[c+6>>0];i[t+7>>0]=i[c+7>>0];return}function Ke(){var e=0,t=0,s=0,r=0,A=0,o=0,a=0,l=0;A=J;J=J+48|0;s=A+24|0;r=A;e=A+44|0;if((i[21440]|0)==0?Qf(21440)|0:0){n[5374]=0;n[5375]=0;n[5376]=0;jf(21440)}if((i[21448]|0)==0?Qf(21448)|0:0)jf(21448);if((n[5374]|0)==(n[5375]|0)){ag(21508);if((n[5374]|0)==(n[5375]|0)){i[s>>0]=i[e>>0]|0;At(r,s);e=n[5375]|0;do{if(e>>>0>=(n[5376]|0)>>>0){e=((e-(n[5374]|0)|0)/24|0)+1|0;t=pt(21496)|0;if(t>>>0<e>>>0)Xg(21496);else{o=n[5374]|0;l=((n[5376]|0)-o|0)/24|0;a=l<<1;ht(s,l>>>0<t>>>1>>>0?a>>>0<e>>>0?e:a:t,((n[5375]|0)-o|0)/24|0,21504);t=s+8|0;lt(n[t>>2]|0,r);n[t>>2]=(n[t>>2]|0)+24;ut(21496,s);dt(s);break}}else{ot(s,21496,1);l=s+4|0;lt(n[l>>2]|0,r);n[l>>2]=(n[l>>2]|0)+24;at(s)}}while(0);Ye(r)}lg(21508)}J=A;return 21496}function Ze(e,t){e=e|0;t=t|0;var s=0,i=0;s=t+16|0;i=n[s>>2]|0;do{if(i)if((t|0)==(i|0)){i=ct(e)|0;n[e+16>>2]=i;s=n[s>>2]|0;zm[n[(n[s>>2]|0)+12>>2]&15](s,i);break}else{n[e+16>>2]=Vm[n[(n[i>>2]|0)+8>>2]&15](i)|0;break}else n[e+16>>2]=0}while(0);return}function Je(e,t){e=e|0;t=t|0;e=n[e+16>>2]|0;if(!e){t=C(4)|0;n[t>>2]=0;It(t);E(t|0,4168,131)}else{zm[n[(n[e>>2]|0)+24>>2]&15](e,t);return}}function Ye(e){e=e|0;var t=0;t=n[e+16>>2]|0;if((e|0)!=(t|0)){if(t|0)jm[n[(n[t>>2]|0)+20>>2]&255](t)}else jm[n[(n[t>>2]|0)+16>>2]&255](t);return}function $e(e){e=e|0;var t=0,s=0,r=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;g=J;J=J+96|0;a=g+16|0;p=g;h=g+72|0;l=n[e>>2]|0;u=o[e+114>>1]|0;d=p;n[d>>2]=0;n[d+4>>2]=0;d=p+8|0;n[d>>2]=u;n[d+4>>2]=0;n[a>>2]=n[p>>2];n[a+4>>2]=n[p+4>>2];n[a+8>>2]=n[p+8>>2];n[a+12>>2]=n[p+12>>2];We(l,a);l=e+120|0;e:do{if(n[l>>2]|0){c=a+2|0;u=a+16|0;d=a+20|0;p=a+18|0;s=0;while(1){if(!(Tt(n[e>>2]|0)|0))break e;if(Pt(n[e>>2]|0)|0)break e;je(n[e>>2]|0,a,54);t=7277;r=c;while(1){if((i[r>>0]|0)!=(i[t>>0]|0))break;r=r+1|0;if((r|0)==(u|0)){f=8;break}else t=t+1|0}if((f|0)==8?(f=0,(A[p>>0]|A[p+1>>0]<<8)<<16>>16==22204):0)break;Dt(n[e>>2]|0,(A[d>>0]|A[d+1>>0]<<8)&65535,0,1);s=s+1|0;if(s>>>0>=(n[l>>2]|0)>>>0)break e}p=(A[d>>0]|A[d+1>>0]<<8)&65535;f=Jf(p)|0;je(n[e>>2]|0,f,p);St(e,f);qp(f);f=e+125|0;Qt(h,e+247|0,(A[f>>0]|A[f+1>>0]<<8)&65535);Rt(e+300|0,h)|0;Pe(h);J=g;return}}while(0);g=C(8)|0;kt(g);E(g|0,2672,8)}function qe(e){e=e|0;var t=0,s=0,i=0,r=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;d=J;J=J+176|0;r=d+40|0;o=d+24|0;t=d+16|0;i=d;c=d+152|0;h=d+136|0;u=d+56|0;l=n[e>>2]|0;a=e+116|0;p=n[a>>2]|0;s=o;n[s>>2]=0;n[s+4>>2]=0;s=o+8|0;n[s>>2]=p;n[s+4>>2]=0;n[r>>2]=n[o>>2];n[r+4>>2]=n[o+4>>2];n[r+8>>2]=n[o+8>>2];n[r+12>>2]=n[o+12>>2];We(l,r);l=t;n[l>>2]=0;n[l+4>>2]=0;je(n[e>>2]|0,t,8);if(!(Tt(n[e>>2]|0)|0)){p=C(8)|0;$t(p);E(p|0,2704,8)}s=t;t=n[s>>2]|0;s=n[s+4>>2]|0;if((t|0)==-1&(s|0)==-1){p=C(8)|0;qt(p,7488);E(p|0,2720,8)}p=n[e>>2]|0;l=i;n[l>>2]=0;n[l+4>>2]=0;l=i+8|0;n[l>>2]=t;n[l+4>>2]=s;n[r>>2]=n[i>>2];n[r+4>>2]=n[i+4>>2];n[r+8>>2]=n[i+8>>2];n[r+12>>2]=n[i+12>>2];We(p,r);if(!(Tt(n[e>>2]|0)|0)){p=C(8)|0;$t(p);E(p|0,2704,8)}je(n[e>>2]|0,r,8);if(!(Tt(n[e>>2]|0)|0)){p=C(8)|0;$t(p);E(p|0,2704,8)}if(n[r>>2]|0){p=C(8)|0;es(p);E(p|0,2736,8)}o=e+288|0;l=e+292|0;n[l>>2]=n[o>>2];p=e+259|0;if((A[p>>0]|A[p+1>>0]<<8|A[p+2>>0]<<16|A[p+3>>0]<<24|0)==-1){p=C(8)|0;qt(p,7606);E(p|0,2720,8)}i=r+4|0;ts(o,(n[i>>2]|0)+1|0);p=n[o>>2]|0;n[p>>2]=(n[a>>2]|0)+8;n[p+4>>2]=0;if((n[i>>2]|0)>>>0>1){Oe(c,n[e>>2]|0);ss(h,c);is(u,32,2,8,0);rs(h);ns(u);if(!(n[i>>2]|0)){o=n[o>>2]|0;s=o}else{s=1;do{if(s>>>0>1)t=n[(n[o>>2]|0)+(s+-1<<3)>>2]|0;else t=0;a=As(u,h,t,1)|0;t=n[o>>2]|0;p=t+(s<<3)|0;n[p>>2]=a;n[p+4>>2]=((a|0)<0)<<31>>31;s=s+1|0}while(s>>>0<=(n[i>>2]|0)>>>0);s=t;o=t}t=n[l>>2]|0;if(t-s>>3>>>0>1){r=t-o>>3;i=o;t=1;s=n[i>>2]|0;i=n[i+4>>2]|0;do{p=o+(t<<3)|0;l=p;s=sm(n[l>>2]|0,n[l+4>>2]|0,s|0,i|0)|0;i=v()|0;n[p>>2]=s;n[p+4>>2]=i;t=t+1|0}while(t>>>0<r>>>0)}os(u);as(h);De(c)}J=d;return}function et(e){e=e|0;i[e+12>>0]=0;i[e+13>>0]=0;return}function tt(e){e=e|0;n[e+8>>2]=0;n[e+4>>2]=0;return}function st(e){e=e|0;return Zd(e)|0}function it(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0;a=J;J=J+16|0;A=t;o=a;r=s-A|0;if(r>>>0>4294967279)fg(e);if(r>>>0<11)i[e+11>>0]=r;else{c=r+16&-16;l=Zf(c)|0;n[e>>2]=l;n[e+8>>2]=c|-2147483648;n[e+4>>2]=r;e=l}if((t|0)!=(s|0)){A=s-A|0;r=e;while(1){rt(r,t);t=t+1|0;if((t|0)==(s|0))break;else r=r+1|0}e=e+A|0}i[o>>0]=0;rt(e,o);J=a;return}function rt(e,t){e=e|0;t=t|0;i[e>>0]=i[t>>0]|0;return}function nt(e){e=e|0;ff(e);qp(e);return}function At(e,t){e=e|0;t=t|0;n[e>>2]=4372;n[e+16>>2]=e;return}function ot(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s*24|0);return}function at(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function lt(e,t){e=e|0;t=t|0;var s=0,i=0;s=t+16|0;i=n[s>>2]|0;do{if(i)if((t|0)==(i|0)){i=ct(e)|0;n[e+16>>2]=i;s=n[s>>2]|0;zm[n[(n[s>>2]|0)+12>>2]&15](s,i);break}else{n[e+16>>2]=i;n[s>>2]=0;break}else n[e+16>>2]=0}while(0);return}function ct(e){e=e|0;return e|0}function ht(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>178956970){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t*24|0)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s*24|0)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t*24|0);return}function ut(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0;a=n[e>>2]|0;l=e+4|0;s=n[l>>2]|0;o=t+4|0;if((s|0)==(a|0)){r=o;A=e;i=n[o>>2]|0;s=a}else{i=n[o>>2]|0;do{s=s+-24|0;lt(i+-24|0,s);i=(n[o>>2]|0)+-24|0;n[o>>2]=i}while((s|0)!=(a|0));r=o;A=e;s=n[e>>2]|0}n[A>>2]=i;n[r>>2]=s;a=t+8|0;o=n[l>>2]|0;n[l>>2]=n[a>>2];n[a>>2]=o;a=e+8|0;l=t+12|0;e=n[a>>2]|0;n[a>>2]=n[l>>2];n[l>>2]=e;n[t>>2]=n[r>>2];return}function dt(e){e=e|0;var t=0,s=0,i=0,r=0;s=n[e+4>>2]|0;i=e+8|0;t=n[i>>2]|0;if((t|0)!=(s|0))do{r=t+-24|0;n[i>>2]=r;Ye(r);t=n[i>>2]|0}while((t|0)!=(s|0));t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function pt(e){e=e|0;return 178956970}function ft(e){e=e|0;qp(e);return}function gt(e){e=e|0;e=Zf(8)|0;n[e>>2]=4372;return e|0}function mt(e,t){e=e|0;t=t|0;n[t>>2]=4372;return}function _t(e){e=e|0;return}function bt(e){e=e|0;ye(e,8);return}function yt(e,t){e=e|0;t=t|0;Ct(e+4|0,t);return}function Bt(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==7183?e+4|0:0)|0}function wt(e){e=e|0;return 2664}function vt(e){e=e|0;return}function Ct(e,t){e=e|0;t=t|0;Mt(e,t);return}function Mt(e,t){e=e|0;t=t|0;var s=0,r=0;e=t+104|0;t=A[e>>0]|0;s=t>>>7;r=t>>>6&1;if((s|0)==1&(r|0)!=0){r=C(8)|0;Et(r);E(r|0,2632,8)}if((s|0)==(r|0)){r=C(8)|0;Ft(r);E(r|0,2648,8)}else{i[e>>0]=t&63;return}}function Et(e){e=e|0;pg(e,7076);n[e>>2]=4416;return}function Ft(e){e=e|0;pg(e,7144);n[e>>2]=4436;return}function xt(e){e=e|0;ff(e);qp(e);return}function Ut(e){e=e|0;ff(e);qp(e);return}function It(e){e=e|0;n[e>>2]=6092;return}function Tt(e){e=e|0;var t=0;t=e+12|0;e=(i[t>>0]|0)==0;i[t>>0]=0;return e|0}function Pt(e){e=e|0;return(i[e+13>>0]|0)!=0|0}function St(e,t){e=e|0;t=t|0;e=e+247|0;Ot(e,t);if((A[e>>0]|A[e+1>>0]<<8)<<16>>16==2)return;else{t=C(8)|0;Vt(t);E(t|0,2688,8)}}function Dt(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0,o=0;switch(r|0){case 0:break;case 2:{r=n[e+4>>2]|0;t=sm(sm(t|0,s|0,-1,-1)|0,v()|0,r|0,((r|0)<0)<<31>>31|0)|0;s=v()|0;break}case 1:{r=n[e+8>>2]|0;t=sm(r|0,((r|0)<0)<<31>>31|0,t|0,s|0)|0;s=v()|0;break}default:{s=0;t=0}}A=n[e+4>>2]|0;o=((A|0)<0)<<31>>31;r=e+12|0;if((s|0)<0|((s|0)>(o|0)|(s|0)==(o|0)&t>>>0>=A>>>0))i[r>>0]=1;else{i[r>>0]=0;n[e+8>>2]=t}return}function kt(e){e=e|0;pg(e,7410);n[e>>2]=4476;return}function Qt(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,n=0,o=0,a=0,l=0,c=0;o=J;J=J+16|0;n=o;Le(e);r=t+32|0;if((A[r>>0]|A[r+1>>0]<<8)<<16>>16){i=t+34|0;t=0;do{l=A[i>>0]|A[i+1>>0]<<8|A[i+2>>0]<<16|A[i+3>>0]<<24;c=l+(t*6|0)|0;a=l+(t*6|0)+2|0;l=l+(t*6|0)+4|0;Gt(n,(A[c>>0]|A[c+1>>0]<<8)&65535,(A[a>>0]|A[a+1>>0]<<8)&65535,(A[l>>0]|A[l+1>>0]<<8)&65535);Nt(e,n);s=s-((A[a>>0]|A[a+1>>0]<<8)&65535)|0;t=t+1|0}while(t>>>0<((A[r>>0]|A[r+1>>0]<<8)&65535)>>>0)}if((s|0)<0){c=C(8)|0;Vt(c);E(c|0,2688,8)}if(s|0){Gt(n,0,s,2);Nt(e,n)}J=o;return}function Rt(e,t){e=e|0;t=t|0;var s=0,r=0;s=J;J=J+16|0;r=s+1|0;i[r>>0]=i[s>>0]|0;Jt(e,t,r);J=s;return e|0}function Ot(e,t){e=e|0;t=t|0;var s=0,r=0,n=0,o=0,a=0,l=0,c=0;r=t+2|0;o=A[t>>0]|A[t+1>>0]<<8;i[e>>0]=o;i[e+1>>0]=o>>8;o=e+2|0;r=A[r>>0]|A[r+1>>0]<<8;i[o>>0]=r;i[o+1>>0]=r>>8;i[e+4>>0]=i[t+4>>0]|0;o=t+6|0;i[e+5>>0]=i[t+5>>0]|0;r=t+8|0;s=e+6|0;o=A[o>>0]|A[o+1>>0]<<8;i[s>>0]=o;i[s+1>>0]=o>>8;s=t+12|0;o=e+8|0;r=A[r>>0]|A[r+1>>0]<<8|A[r+2>>0]<<16|A[r+3>>0]<<24;i[o>>0]=r;i[o+1>>0]=r>>8;i[o+2>>0]=r>>16;i[o+3>>0]=r>>24;o=e+12|0;s=A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24;i[o>>0]=s;i[o+1>>0]=s>>8;i[o+2>>0]=s>>16;i[o+3>>0]=s>>24;o=t+16|0;s=o;s=A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24;o=o+4|0;o=A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24;r=e+16|0;a=r;i[a>>0]=s;i[a+1>>0]=s>>8;i[a+2>>0]=s>>16;i[a+3>>0]=s>>24;r=r+4|0;i[r>>0]=o;i[r+1>>0]=o>>8;i[r+2>>0]=o>>16;i[r+3>>0]=o>>24;r=t+32|0;o=t+24|0;a=o;a=A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24;o=o+4|0;o=A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24;s=e+24|0;n=s;i[n>>0]=a;i[n+1>>0]=a>>8;i[n+2>>0]=a>>16;i[n+3>>0]=a>>24;s=s+4|0;i[s>>0]=o;i[s+1>>0]=o>>8;i[s+2>>0]=o>>16;i[s+3>>0]=o>>24;s=t+34|0;o=e+32|0;r=A[r>>0]|A[r+1>>0]<<8;i[o>>0]=r;i[o+1>>0]=r>>8;n=e+34|0;e=A[n>>0]|A[n+1>>0]<<8|A[n+2>>0]<<16|A[n+3>>0]<<24;if(!e)e=r;else{Yf(e);e=A[o>>0]|A[o+1>>0]<<8}r=Jf((e&65535)*6|0)|0;i[n>>0]=r;i[n+1>>0]=r>>8;i[n+2>>0]=r>>16;i[n+3>>0]=r>>24;if(e<<16>>16?(e=t+36|0,a=A[s>>0]|A[s+1>>0]<<8,i[r>>0]=a,i[r+1>>0]=a>>8,t=t+38|0,a=r+2|0,e=A[e>>0]|A[e+1>>0]<<8,i[a>>0]=e,i[a+1>>0]=e>>8,a=r+4|0,t=A[t>>0]|A[t+1>>0]<<8,i[a>>0]=t,i[a+1>>0]=t>>8,((A[o>>0]|A[o+1>>0]<<8)&65535)>1):0){e=1;do{t=s;s=s+6|0;a=A[n>>0]|A[n+1>>0]<<8|A[n+2>>0]<<16|A[n+3>>0]<<24;l=t+8|0;r=a+(e*6|0)|0;c=A[s>>0]|A[s+1>>0]<<8;i[r>>0]=c;i[r+1>>0]=c>>8;t=t+10|0;r=a+(e*6|0)+2|0;l=A[l>>0]|A[l+1>>0]<<8;i[r>>0]=l;i[r+1>>0]=l>>8;a=a+(e*6|0)+4|0;t=A[t>>0]|A[t+1>>0]<<8;i[a>>0]=t;i[a+1>>0]=t>>8;e=e+1|0}while(e>>>0<((A[o>>0]|A[o+1>>0]<<8)&65535)>>>0)}return}function Vt(e){e=e|0;pg(e,7354);n[e>>2]=4456;return}function Lt(e){e=e|0;ff(e);qp(e);return}function Ht(e){e=e|0;ff(e);qp(e);return}function Nt(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0;a=J;J=J+32|0;r=a;A=e+4|0;s=n[A>>2]|0;o=e+8|0;do{if((s|0)==(n[o>>2]|0)){s=((s-(n[e>>2]|0)|0)/12|0)+1|0;i=Zt(e)|0;if(i>>>0<s>>>0)Xg(e);else{l=n[e>>2]|0;c=((n[o>>2]|0)-l|0)/12|0;o=c<<1;Wt(r,c>>>0<i>>>1>>>0?o>>>0<s>>>0?s:o:i,((n[A>>2]|0)-l|0)/12|0,e+8|0);o=r+8|0;A=n[o>>2]|0;n[A>>2]=n[t>>2];n[A+4>>2]=n[t+4>>2];n[A+8>>2]=n[t+8>>2];n[o>>2]=(n[o>>2]|0)+12;Xt(e,r);Kt(r);break}}else{jt(r,e,1);c=r+4|0;l=n[c>>2]|0;n[l>>2]=n[t>>2];n[l+4>>2]=n[t+4>>2];n[l+8>>2]=n[t+8>>2];n[c>>2]=(n[c>>2]|0)+12;zt(r)}}while(0);J=a;return}function Gt(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;n[e>>2]=t;n[e+4>>2]=s;n[e+8>>2]=i;return}function jt(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s*12|0);return}function zt(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function Wt(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>357913941){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t*12|0)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s*12|0)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t*12|0);return}function Xt(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;i=n[e>>2]|0;o=e+4|0;A=t+4|0;r=(n[o>>2]|0)-i|0;s=(n[A>>2]|0)+(((r|0)/-12|0)*12|0)|0;n[A>>2]=s;if((r|0)>0){hm(s|0,i|0,r|0)|0;i=A;s=n[A>>2]|0}else i=A;A=n[e>>2]|0;n[e>>2]=s;n[i>>2]=A;A=t+8|0;r=n[o>>2]|0;n[o>>2]=n[A>>2];n[A>>2]=r;A=e+8|0;o=t+12|0;e=n[A>>2]|0;n[A>>2]=n[o>>2];n[o>>2]=e;n[t>>2]=n[i>>2];return}function Kt(e){e=e|0;var t=0,s=0,i=0;t=n[e+4>>2]|0;s=e+8|0;i=n[s>>2]|0;if((i|0)!=(t|0))n[s>>2]=i+(~(((i+-12-t|0)>>>0)/12|0)*12|0);t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function Zt(e){e=e|0;return 357913941}function Jt(e,t,s){e=e|0;t=t|0;s=s|0;var i=0;Yt(e);n[e>>2]=n[t>>2];s=t+4|0;n[e+4>>2]=n[s>>2];i=t+8|0;n[e+8>>2]=n[i>>2];n[i>>2]=0;n[s>>2]=0;n[t>>2]=0;return}function Yt(e){e=e|0;var t=0,s=0,i=0,r=0;t=n[e>>2]|0;s=t;if(t|0){i=e+4|0;n[i>>2]=s;r=e+8|0;ye(t,(n[r>>2]|0)-s|0);n[r>>2]=0;n[i>>2]=0;n[e>>2]=0}return}function $t(e){e=e|0;pg(e,7660);n[e>>2]=4496;return}function qt(e,t){e=e|0;t=t|0;pg(e,t);n[e>>2]=4516;return}function es(e){e=e|0;pg(e,7704);n[e>>2]=4536;return}function ts(e,t){e=e|0;t=t|0;var s=0,i=0,r=0;s=e+4|0;r=n[e>>2]|0;i=(n[s>>2]|0)-r>>3;if(i>>>0>=t>>>0){if(i>>>0>t>>>0)n[s>>2]=r+(t<<3)}else us(e,t-i|0);return}function ss(e,t){e=e|0;t=t|0;n[e>>2]=t;n[e+4>>2]=0;n[e+8>>2]=-1;return}function is(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var A=0;n[e+4>>2]=t;n[e+8>>2]=s;n[e+12>>2]=i;n[e+16>>2]=r;n[e+36>>2]=0;n[e+40>>2]=0;n[e+44>>2]=0;vs(e+48|0);n[e+68>>2]=0;n[e+72>>2]=0;n[e+76>>2]=0;do{if(!r){s=e+20|0;if((t+-1|0)>>>0<31){n[s>>2]=t;r=1<<t;n[e+24>>2]=r;s=r>>>1;n[e+28>>2]=0-s;s=r+-1-s|0;break}else{n[s>>2]=32;n[e+24>>2]=0;n[e+28>>2]=-2147483648;s=2147483647;break}}else{i=e+20|0;n[i>>2]=0;n[e+24>>2]=r;s=r;A=0;while(1){s=s>>>1;t=A+1|0;if(!s)break;else A=t}n[i>>2]=(1<<A|0)==(r|0)?A:t;s=r>>>1;n[e+28>>2]=0-s;s=r+-1-s|0}}while(0);n[e+32>>2]=s;n[e>>2]=0;return}function rs(e){e=e|0;var t=0;t=((Es(n[e>>2]|0)|0)&255)<<24;t=((Es(n[e>>2]|0)|0)&255)<<16|t;t=t|((Es(n[e>>2]|0)|0)&255)<<8;n[e+4>>2]=t|(Es(n[e>>2]|0)|0)&255;return}function ns(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,b=0;g=J;J=J+64|0;p=g+44|0;f=g;c=e+36|0;h=e+40|0;e:do{if((n[c>>2]|0)==(n[h>>2]|0)){u=e+8|0;t:do{if(!(n[u>>2]|0))d=e+20|0;else{r=e+20|0;A=e+44|0;o=p+4|0;a=e+44|0;l=p+8|0;i=0;while(1){Ts(f,(n[r>>2]|0)+1|0,0,0);t=n[h>>2]|0;if(t>>>0<(n[A>>2]|0)>>>0){Ps(p,c,1);Ds(n[o>>2]|0,f);n[o>>2]=(n[o>>2]|0)+44;Ss(p)}else{t=((t-(n[c>>2]|0)|0)/44|0)+1|0;s=Os(c)|0;if(s>>>0<t>>>0)break;m=n[c>>2]|0;b=((n[A>>2]|0)-m|0)/44|0;_=b<<1;ks(p,b>>>0<s>>>1>>>0?_>>>0<t>>>0?t:_:s,((n[h>>2]|0)-m|0)/44|0,a);Ds(n[l>>2]|0,f);n[l>>2]=(n[l>>2]|0)+44;Qs(c,p);Rs(p)}Ms(f);i=i+1|0;if(i>>>0>=(n[u>>2]|0)>>>0){d=r;break t}}Xg(c)}}while(0);if(n[d>>2]|0){o=e+12|0;a=e+68|0;l=e+72|0;c=e+76|0;h=p+4|0;r=e+76|0;A=p+8|0;i=1;while(1){t=n[o>>2]|0;Ts(f,1<<(i>>>0>t>>>0?t:i),0,0);t=n[l>>2]|0;if(t>>>0<(n[c>>2]|0)>>>0){Ps(p,a,1);Ds(n[h>>2]|0,f);n[h>>2]=(n[h>>2]|0)+44;Ss(p)}else{t=((t-(n[a>>2]|0)|0)/44|0)+1|0;s=Os(a)|0;if(s>>>0<t>>>0)break;b=n[a>>2]|0;m=((n[c>>2]|0)-b|0)/44|0;_=m<<1;ks(p,m>>>0<s>>>1>>>0?_>>>0<t>>>0?t:_:s,((n[l>>2]|0)-b|0)/44|0,r);Ds(n[A>>2]|0,f);n[A>>2]=(n[A>>2]|0)+44;Qs(a,p);Rs(p)}Ms(f);i=i+1|0;if(i>>>0>(n[d>>2]|0)>>>0)break e}Xg(a)}}}while(0);J=g;return}function As(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;s=(Hs(e,t,(n[e+36>>2]|0)+(i*44|0)|0)|0)+s|0;t=n[e+24>>2]|0;if((s|0)<0)return s+t|0;else return s-(s>>>0<t>>>0?0:t)|0;return 0}function os(e){e=e|0;Cs(e+68|0);Cs(e+36|0);return}function as(e){e=e|0;return}function ls(e){e=e|0;ff(e);qp(e);return}function cs(e){e=e|0;ff(e);qp(e);return}function hs(e){e=e|0;ff(e);qp(e);return}function us(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0;a=J;J=J+32|0;r=a;A=e+8|0;o=e+4|0;s=n[o>>2]|0;do{if((n[A>>2]|0)-s>>3>>>0<t>>>0){s=(s-(n[e>>2]|0)>>3)+t|0;i=ys(e)|0;if(i>>>0<s>>>0)Xg(e);else{l=n[e>>2]|0;c=(n[A>>2]|0)-l|0;A=c>>2;ps(r,c>>3>>>0<i>>>1>>>0?A>>>0<s>>>0?s:A:i,(n[o>>2]|0)-l>>3,e+8|0);fs(r,t);gs(e,r);ms(r);break}}else ds(e,t)}while(0);J=a;return}function ds(e,t){e=e|0;t=t|0;var s=0,i=0,r=0;r=J;J=J+16|0;i=r;_s(i,e,t);e=i+4|0;t=n[e>>2]|0;s=n[i+8>>2]|0;if((t|0)!=(s|0)){s=s+-8-t|0;dm(t|0,0,s+8&-8|0)|0;n[e>>2]=t+((s>>>3)+1<<3)}bs(i);J=r;return}function ps(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>536870911){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t<<3)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s<<3)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t<<3);return}function fs(e,t){e=e|0;t=t|0;var s=0,i=0;i=J;J=J+16|0;s=i;Bs(s,e+8|0,t);e=n[s>>2]|0;t=n[s+4>>2]|0;if((e|0)!=(t|0)){t=t+-8-e|0;dm(e|0,0,t+8&-8|0)|0;n[s>>2]=e+((t>>>3)+1<<3)}ws(s);J=i;return}function gs(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;i=n[e>>2]|0;o=e+4|0;A=t+4|0;r=(n[o>>2]|0)-i|0;s=(n[A>>2]|0)+(0-(r>>3)<<3)|0;n[A>>2]=s;if((r|0)>0){hm(s|0,i|0,r|0)|0;i=A;s=n[A>>2]|0}else i=A;A=n[e>>2]|0;n[e>>2]=s;n[i>>2]=A;A=t+8|0;r=n[o>>2]|0;n[o>>2]=n[A>>2];n[A>>2]=r;A=e+8|0;o=t+12|0;e=n[A>>2]|0;n[A>>2]=n[o>>2];n[o>>2]=e;n[t>>2]=n[i>>2];return}function ms(e){e=e|0;var t=0,s=0,i=0;t=n[e+4>>2]|0;s=e+8|0;i=n[s>>2]|0;if((i|0)!=(t|0))n[s>>2]=i+(~((i+-8-t|0)>>>3)<<3);t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function _s(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s<<3);return}function bs(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function ys(e){e=e|0;return 536870911}function Bs(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=n[t>>2];n[e+4>>2]=(n[t>>2]|0)+(s<<3);n[e+8>>2]=t;return}function ws(e){e=e|0;n[n[e+8>>2]>>2]=n[e>>2];return}function vs(e){e=e|0;n[e+12>>2]=1;n[e+16>>2]=2;n[e+8>>2]=4096;n[e+4>>2]=4;n[e>>2]=4;return}function Cs(e){e=e|0;var t=0,s=0,i=0;s=n[e>>2]|0;if(s|0){i=e+4|0;t=n[i>>2]|0;if((t|0)==(s|0))t=s;else{do{t=t+-44|0;Ms(t)}while((t|0)!=(s|0));t=n[e>>2]|0}n[i>>2]=s;ye(t,(n[e+8>>2]|0)-t|0)}return}function Ms(e){e=e|0;var t=0;t=n[e+8>>2]|0;if(t|0)Re(t);t=n[e+12>>2]|0;if(t|0)Re(t);t=n[e+16>>2]|0;if(t|0)Re(t);return}function Es(e){e=e|0;var t=0,s=0;s=e+4|0;t=n[s>>2]|0;if((t|0)>=(n[e+8>>2]|0)){Fs(e);t=n[s>>2]|0}e=n[e+12>>2]|0;n[s>>2]=t+1;return i[e+t>>0]|0}function Fs(e){e=e|0;var t=0;n[e+4>>2]=0;je(n[e>>2]|0,n[e+12>>2]|0,1048576);t=xs(n[e>>2]|0)|0;n[e+8>>2]=t;if(!t){t=C(8)|0;Us(t);E(t|0,2752,8)}else return}function xs(e){e=e|0;return n[e+16>>2]|0}function Us(e){e=e|0;pg(e,7769);n[e>>2]=4556;return}function Is(e){e=e|0;ff(e);qp(e);return}function Ts(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0,o=0,a=0;n[e>>2]=t;i[e+4>>0]=s&1;o=e+8|0;n[o>>2]=0;a=e+12|0;n[a>>2]=0;A=e+16|0;n[A>>2]=0;if((t+-2|0)>>>0>2046){e=C(8)|0;pg(e,7789);E(e|0,3912,8)}n[e+32>>2]=t+-1;if(t>>>0>16&(s^1)){s=3;while(1)if(1<<s+2>>>0<t>>>0)s=s+1|0;else break;t=1<<s;n[e+36>>2]=t;n[e+40>>2]=15-s;n[A>>2]=Ge((t<<2)+8|0)|0;t=n[e>>2]|0}else{n[A>>2]=0;n[e+40>>2]=0;n[e+36>>2]=0}n[o>>2]=Ge(t<<2)|0;A=Ge(n[e>>2]<<2)|0;n[a>>2]=A;n[e+20>>2]=0;t=n[e>>2]|0;s=e+24|0;n[s>>2]=t;t=(t|0)!=0;if(!r){if(t){t=0;do{n[A+(t<<2)>>2]=1;t=t+1|0}while(t>>>0<(n[e>>2]|0)>>>0)}}else if(t){t=0;do{n[A+(t<<2)>>2]=n[r+(t<<2)>>2];t=t+1|0}while(t>>>0<(n[e>>2]|0)>>>0)}Ls(e);r=((n[e>>2]|0)+6|0)>>>1;n[s>>2]=r;n[e+28>>2]=r;return}function Ps(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s*44|0);return}function Ss(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function Ds(e,t){e=e|0;t=t|0;var s=0;n[e>>2]=n[t>>2];i[e+4>>0]=i[t+4>>0]|0;s=t+8|0;n[e+8>>2]=n[s>>2];n[e+12>>2]=n[t+12>>2];n[e+16>>2]=n[t+16>>2];n[e+20>>2]=n[t+20>>2];n[e+24>>2]=n[t+24>>2];n[e+28>>2]=n[t+28>>2];n[e+32>>2]=n[t+32>>2];n[e+36>>2]=n[t+36>>2];n[e+40>>2]=n[t+40>>2];n[s>>2]=0;n[s+4>>2]=0;n[s+8>>2]=0;return}function ks(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>97612893){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t*44|0)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s*44|0)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t*44|0);return}function Qs(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0;a=n[e>>2]|0;l=e+4|0;s=n[l>>2]|0;o=t+4|0;if((s|0)==(a|0)){r=o;A=e;i=n[o>>2]|0;s=a}else{i=n[o>>2]|0;do{s=s+-44|0;Vs(i+-44|0,s);i=(n[o>>2]|0)+-44|0;n[o>>2]=i}while((s|0)!=(a|0));r=o;A=e;s=n[e>>2]|0}n[A>>2]=i;n[r>>2]=s;a=t+8|0;o=n[l>>2]|0;n[l>>2]=n[a>>2];n[a>>2]=o;a=e+8|0;l=t+12|0;e=n[a>>2]|0;n[a>>2]=n[l>>2];n[l>>2]=e;n[t>>2]=n[r>>2];return}function Rs(e){e=e|0;var t=0,s=0,i=0,r=0;s=n[e+4>>2]|0;i=e+8|0;t=n[i>>2]|0;if((t|0)!=(s|0))do{r=t+-44|0;n[i>>2]=r;Ms(r);t=n[i>>2]|0}while((t|0)!=(s|0));t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function Os(e){e=e|0;return 97612893}function Vs(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0;s=n[t>>2]|0;n[e>>2]=s;i[e+4>>0]=i[t+4>>0]|0;n[e+20>>2]=n[t+20>>2];n[e+24>>2]=n[t+24>>2];n[e+28>>2]=n[t+28>>2];n[e+32>>2]=n[t+32>>2];o=e+36|0;n[o>>2]=n[t+36>>2];n[e+40>>2]=n[t+40>>2];s=s<<2;r=Ge(s)|0;n[e+8>>2]=r;A=n[e>>2]|0;if(A|0)um(r|0,n[t+8>>2]|0,A<<2|0)|0;s=Ge(s)|0;n[e+12>>2]=s;r=n[e>>2]|0;if(r|0)um(s|0,n[t+12>>2]|0,r<<2|0)|0;s=n[o>>2]|0;if(s){r=Ge((s<<2)+8|0)|0;n[e+16>>2]=r;s=(n[o>>2]<<2)+8|0;if(s|0)um(r|0,n[t+16>>2]|0,s|0)|0}else n[e+16>>2]=0;return}function Ls(e){e=e|0;var t=0,s=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;g=e+24|0;A=e+20|0;t=(n[A>>2]|0)+(n[g>>2]|0)|0;n[A>>2]=t;if(t>>>0>32768){n[A>>2]=0;if(!(n[e>>2]|0))t=0;else{r=n[e+12>>2]|0;s=0;do{d=r+(s<<2)|0;t=((n[d>>2]|0)+1|0)>>>1;n[d>>2]=t;t=(n[A>>2]|0)+t|0;n[A>>2]=t;s=s+1|0}while(s>>>0<(n[e>>2]|0)>>>0)}}d=2147483648/(t>>>0)|0;do{if((i[e+4>>0]|0)==0?(p=e+36|0,(n[p>>2]|0)!=0):0){if(n[e>>2]|0){l=n[e+8>>2]|0;c=n[e+12>>2]|0;h=e+40|0;u=e+16|0;t=0;o=0;a=0;do{s=(b(o,d)|0)>>>16;n[l+(a<<2)>>2]=s;o=(n[c+(a<<2)>>2]|0)+o|0;s=s>>>(n[h>>2]|0);if(t>>>0<s>>>0){r=a+-1|0;A=n[u>>2]|0;do{t=t+1|0;n[A+(t<<2)>>2]=r}while((t|0)!=(s|0));t=s}a=a+1|0}while(a>>>0<(n[e>>2]|0)>>>0);s=n[u>>2]|0;n[s>>2]=0;if(t>>>0>(n[p>>2]|0)>>>0){t=e;break}}else{s=n[e+16>>2]|0;n[s>>2]=0;t=0}do{t=t+1|0;n[s+(t<<2)>>2]=(n[e>>2]|0)+-1}while(t>>>0<=(n[p>>2]|0)>>>0);t=e}else f=7}while(0);if((f|0)==7)if(!(n[e>>2]|0))t=e;else{r=n[e+8>>2]|0;A=n[e+12>>2]|0;t=0;s=0;do{n[r+(t<<2)>>2]=(b(s,d)|0)>>>16;s=(n[A+(t<<2)>>2]|0)+s|0;t=t+1|0}while(t>>>0<(n[e>>2]|0)>>>0);t=e}f=((n[g>>2]|0)*5|0)>>>2;p=(n[t>>2]<<3)+48|0;f=f>>>0>p>>>0?p:f;n[g>>2]=f;n[e+28>>2]=f;return}function Hs(e,t,s){e=e|0;t=t|0;s=s|0;var i=0;s=Ns(t,s)|0;n[e>>2]=s;do{if(s){if(s>>>0>=32){s=n[e+28>>2]|0;break}i=n[e+12>>2]|0;if(s>>>0>i>>>0){i=s-i|0;s=Ns(t,(n[e+68>>2]|0)+((s+-1|0)*44|0)|0)|0;i=s<<i|(Gs(t,i)|0)}else i=Ns(t,(n[e+68>>2]|0)+((s+-1|0)*44|0)|0)|0;s=n[e>>2]|0;if((i|0)<(1<<s+-1|0)){s=i+1+(-1<<s)|0;break}else{s=i+1|0;break}}else s=js(t,e+48|0)|0}while(0);return s|0}function Ns(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;d=e+8|0;u=n[d>>2]|0;r=n[t+16>>2]|0;if(r){i=e+4|0;s=n[i>>2]|0;h=u>>>15;n[d>>2]=h;l=(s>>>0)/(h>>>0)|0;a=l>>>(n[t+40>>2]|0);A=n[r+(a<<2)>>2]|0;a=(n[r+(a+1<<2)>>2]|0)+1|0;o=A+1|0;c=n[t+8>>2]|0;if(a>>>0>o>>>0){r=A;A=a;do{o=(A+r|0)>>>1;a=(n[c+(o<<2)>>2]|0)>>>0>l>>>0;r=a?r:o;A=a?o:A;o=r+1|0}while(A>>>0>o>>>0);A=r}r=b(n[c+(A<<2)>>2]|0,h)|0;if((A|0)==(n[t+32>>2]|0))o=u;else o=b(n[c+(o<<2)>>2]|0,h)|0}else{c=u>>>15;n[d>>2]=c;a=n[t>>2]|0;h=n[t+8>>2]|0;i=e+4|0;s=n[i>>2]|0;l=a>>>1;r=0;o=u;A=0;do{p=b(n[h+(l<<2)>>2]|0,c)|0;u=p>>>0>s>>>0;o=u?p:o;r=u?r:p;A=u?A:l;a=u?l:a;l=(A+a|0)>>>1}while((l|0)!=(A|0))}n[i>>2]=s-r;p=o-r|0;n[d>>2]=p;if(p>>>0<16777216)zs(e);d=(n[t+12>>2]|0)+(A<<2)|0;n[d>>2]=(n[d>>2]|0)+1;d=t+28|0;p=(n[d>>2]|0)+-1|0;n[d>>2]=p;if(!p)Ls(t);return A|0}function Gs(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;if(t>>>0>19){s=(Ws(e)|0)&65535;return(Gs(e,t+-16|0)|0)<<16|s|0}i=e+4|0;r=n[i>>2]|0;A=e+8|0;s=(n[A>>2]|0)>>>t;n[A>>2]=s;t=(r>>>0)/(s>>>0)|0;n[i>>2]=r-(b(t,s)|0);if(s>>>0<16777216)zs(e);return t|0}function js(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0;i=e+8|0;r=n[i>>2]|0;s=b(r>>>13,n[t+8>>2]|0)|0;A=e+4|0;o=n[A>>2]|0;a=o>>>0>=s>>>0;if(a){n[A>>2]=o-s;s=r-s|0;n[i>>2]=s}else{n[i>>2]=s;o=t+12|0;n[o>>2]=(n[o>>2]|0)+1}if(s>>>0<16777216)zs(e);o=t+4|0;e=(n[o>>2]|0)+-1|0;n[o>>2]=e;if(!e)Xs(t);return a&1|0}function zs(e){e=e|0;var t=0,s=0,i=0,r=0;t=e+4|0;s=e+8|0;i=n[t>>2]|0;do{i=i<<8|(Es(n[e>>2]|0)|0)&255;n[t>>2]=i;r=n[s>>2]<<8;n[s>>2]=r}while(r>>>0<16777216);return}function Ws(e){e=e|0;var t=0,s=0,i=0,r=0;s=e+4|0;r=n[s>>2]|0;t=e+8|0;i=(n[t>>2]|0)>>>16;n[t>>2]=i;t=(r>>>0)/(i>>>0)|0;n[s>>2]=r-(b(t,i)|0);zs(e);return t&65535|0}function Xs(e){e=e|0;var t=0,s=0,i=0,r=0,A=0;r=n[e>>2]|0;s=e+16|0;t=(n[s>>2]|0)+r|0;n[s>>2]=t;if(t>>>0>8192){i=(t+1|0)>>>1;n[s>>2]=i;A=e+12|0;t=((n[A>>2]|0)+1|0)>>>1;n[A>>2]=t;if((t|0)==(i|0)){t=i+1|0;n[s>>2]=t;s=t;t=i}else s=i}else{s=t;t=n[e+12>>2]|0}n[e+8>>2]=(b(t,2147483648/(s>>>0)|0)|0)>>>18;A=r*5|0;A=A>>>0>259?64:A>>>2;n[e>>2]=A;n[e+4>>2]=A;return}function Ks(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;u=J;J=J+32|0;o=u+16|0;a=u+8|0;l=u;c=e+336|0;i=c;r=e+259|0;if(!((n[i+4>>2]|0)==0?(n[i>>2]|0)==(A[r>>0]|A[r+1>>0]<<8|A[r+2>>0]<<16|A[r+3>>0]<<24|0):0)){i=e+320|0;s=n[i>>2]|0;r=s;if(!((s|0)!=0?(n[e+312>>2]|0)!=0:0)){s=r;h=5}}else{i=e+320|0;s=n[e+320>>2]|0;h=5}if((h|0)==5){h=e+320|0;n[o>>2]=s;n[h>>2]=0;s=e+324|0;n[o+4>>2]=n[s>>2];n[s>>2]=0;Ie(o);r=e+312|0;n[o>>2]=n[r>>2];n[r>>2]=0;d=e+316|0;n[o+4>>2]=n[d>>2];n[d>>2]=0;Te(o);p=Zf(12)|0;ss(p,e+4|0);n[l>>2]=0;n[o>>2]=n[l>>2];Js(a,p,o);p=n[a>>2]|0;n[a>>2]=n[r>>2];n[r>>2]=p;p=a+4|0;l=n[p>>2]|0;n[p>>2]=n[d>>2];n[d>>2]=l;Te(a);Zs(a,n[r>>2]|0,e+300|0);r=n[a>>2]|0;d=a+4|0;l=n[d>>2]|0;n[a>>2]=0;n[d>>2]=0;n[o>>2]=n[h>>2];n[h>>2]=r;n[o+4>>2]=n[s>>2];n[s>>2]=l;Ie(o);Ie(a);s=e+328|0;l=s;l=sm(n[l>>2]|0,n[l+4>>2]|0,1,0)|0;h=v()|0;n[s>>2]=l;n[s+4>>2]=h;s=c;n[s>>2]=0;n[s+4>>2]=0;s=n[i>>2]|0}Hm[n[n[s>>2]>>2]&63](s,t)|0;h=c;h=sm(n[h>>2]|0,n[h+4>>2]|0,1,0)|0;d=v()|0;p=c;n[p>>2]=h;n[p+4>>2]=d;J=u;return}function Zs(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;o=J;J=J+64|0;i=o+56|0;r=o;A=si(s)|0;if((A|0)==-1){o=C(8)|0;ii(o);E(o|0,2784,8)}s=ri(s)|0;e:do{if(!s)switch(A|0){case 0:{A=Zf(4788)|0;pi(A);di(e,t,A);break e}case 1:{A=Zf(5116)|0;gi(A);fi(e,t,A);break e}case 2:{A=Zf(5104)|0;_i(A);mi(e,t,A);break e}case 3:{A=Zf(5432)|0;yi(A);bi(e,t,A);break e}default:{n[e>>2]=0;n[e+4>>2]=0;break e}}else{ni(i,t);Ai(n[i>>2]|0);if((A|2|0)==3)oi(n[i>>2]|0);if((A|1|0)==3)ai(n[i>>2]|0);A=n[i>>2]|0;ci(r,s);li(A,r);hi(r);n[e>>2]=n[i>>2];A=i+4|0;n[e+4>>2]=n[A>>2];n[i>>2]=0;n[A>>2]=0;ui(i)}}while(0);J=o;return}function Js(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4576;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ys(e,i);J=s;return}function Ys(e,t){e=e|0;t=t|0;return}function $s(e){e=e|0;Ag(e);qp(e);return}function qs(e){e=e|0;e=n[e+12>>2]|0;if(e|0){as(e);qp(e)}return}function ei(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==7983?e+12|0:0)|0}function ti(e){e=e|0;ye(e,16);return}function si(e){e=e|0;var t=0,s=0;t=(n[e+4>>2]|0)-(n[e>>2]|0)|0;e:do{if(((t|0)!=0?(s=((t|0)/12|0)+(((ri(e)|0)!=0)<<31>>31)|0,(s|0)!=0):0)?(t=n[e>>2]|0,!(Bi(t,wi()|0)|0)):0){switch(s|0){case 1:{e=0;break e}case 2:{if(vi((n[e>>2]|0)+12|0,Ci()|0)|0){e=1;break e}if(vi((n[e>>2]|0)+12|0,Mi()|0)|0){e=2;break e}break}case 3:{if(vi((n[e>>2]|0)+12|0,Ci()|0)|0?(s=(n[e>>2]|0)+24|0,vi(s,Mi()|0)|0):0){e=3;break e}break}default:{}}e=-1}else e=-1}while(0);return e|0}function ii(e){e=e|0;pg(e,8131);n[e>>2]=4604;return}function ri(e){e=e|0;var t=0,s=0;t=n[e+4>>2]|0;if(((t|0)!=(n[e>>2]|0)?(s=t,(n[s+-12>>2]|0)==0):0)?(n[s+-4>>2]|0)==2:0)e=n[s+-8>>2]|0;else e=0;return e|0}function ni(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;s=J;J=J+16|0;i=s+4|0;A=s;r=Zf(24)|0;Fi(r,t);n[A>>2]=0;n[i>>2]=n[A>>2];xi(e,r,i);J=s;return}function Ai(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(4792)|0;Ni(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];Gi(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function oi(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(336)|0;zr(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];Wr(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function ai(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(324)|0;mn(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];_n(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function li(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;o=l+12|0;a=l;i=l+8|0;A=Zf(64)|0;Sn(A,n[e+4>>2]|0,t);r=e+8|0;n[i>>2]=0;n[o>>2]=n[i>>2];Dn(a,A,o);A=e+12|0;t=n[A>>2]|0;i=e+16|0;do{if(t>>>0>=(n[i>>2]|0)>>>0){t=(t-(n[r>>2]|0)>>3)+1|0;s=Zi(r)|0;if(s>>>0<t>>>0)Xg(r);else{c=n[r>>2]|0;h=(n[i>>2]|0)-c|0;i=h>>2;Wi(o,h>>3>>>0<s>>>1>>>0?i>>>0<t>>>0?t:i:s,(n[A>>2]|0)-c>>3,e+16|0);e=o+8|0;A=n[e>>2]|0;n[A>>2]=n[a>>2];i=a+4|0;n[A+4>>2]=n[i>>2];n[a>>2]=0;n[i>>2]=0;n[e>>2]=A+8;Xi(r,o);Ki(o);break}}else{ji(o,r,1);h=o+4|0;c=n[h>>2]|0;n[c>>2]=n[a>>2];e=a+4|0;n[c+4>>2]=n[e>>2];n[a>>2]=0;n[e>>2]=0;n[h>>2]=c+8;zi(o)}}while(0);ki(a);J=l;return}function ci(e,t){e=e|0;t=t|0;var s=0,r=0;s=J;J=J+48|0;r=s;n[e>>2]=t;i[e+4>>0]=0;EA(e+8|0,t);EA(e+20|0,t);Ts(r,256,0,0);FA(e+32|0,t,r);Ms(r);J=s;return}function hi(e){e=e|0;IA(e+32|0);Gn(e+20|0);Gn(e+8|0);return}function ui(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function di(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;i=J;J=J+16|0;r=i+4|0;o=i;A=Zf(12)|0;TA(A,t,s);n[o>>2]=0;n[r>>2]=n[o>>2];PA(e,A,r);J=i;return}function pi(e){e=e|0;Yi(e);jA(e+4784|0);return}function fi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;i=J;J=J+16|0;r=i+4|0;o=i;A=Zf(12)|0;zA(A,t,s);n[o>>2]=0;n[r>>2]=n[o>>2];WA(e,A,r);J=i;return}function gi(e){e=e|0;Yi(e);ro(e+4784|0);return}function mi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;i=J;J=J+16|0;r=i+4|0;o=i;A=Zf(12)|0;no(A,t,s);n[o>>2]=0;n[r>>2]=n[o>>2];Ao(e,A,r);J=i;return}function _i(e){e=e|0;Yi(e);bo(e+4784|0);return}function bi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;i=J;J=J+16|0;r=i+4|0;o=i;A=Zf(12)|0;yo(A,t,s);n[o>>2]=0;n[r>>2]=n[o>>2];Bo(e,A,r);J=i;return}function yi(e){e=e|0;Yi(e);So(e+4784|0);return}function Bi(e,t){e=e|0;t=t|0;return(vi(e,t)|0)^1|0}function wi(){if((i[21456]|0)==0?Qf(21456)|0:0){Gt(21536,6,20,2);jf(21456)}return 21536}function vi(e,t){e=e|0;t=t|0;if((n[e>>2]|0)==(n[t>>2]|0)?(n[e+8>>2]|0)==(n[t+8>>2]|0):0)e=(n[e+4>>2]|0)==(n[t+4>>2]|0);else e=0;return e|0}function Ci(){if((i[21464]|0)==0?Qf(21464)|0:0){Gt(21548,7,8,2);jf(21464)}return 21548}function Mi(){if((i[21472]|0)==0?Qf(21472)|0:0){Gt(21560,8,6,2);jf(21472)}return 21560}function Ei(e){e=e|0;ff(e);qp(e);return}function Fi(e,t){e=e|0;t=t|0;Ui(e);n[e>>2]=4624;n[e+4>>2]=t;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;i[e+20>>0]=1;return}function xi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4664;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ri(e,i);J=s;return}function Ui(e){e=e|0;n[e>>2]=4644;return}function Ii(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0,a=0,l=0,c=0;c=J;J=J+16|0;o=c;s=n[e+8>>2]|0;a=n[e+12>>2]|0;if((s|0)!=(a|0)){l=o+4|0;do{r=n[s>>2]|0;n[o>>2]=r;A=n[s+4>>2]|0;n[l>>2]=A;if(A|0){A=A+4|0;n[A>>2]=(n[A>>2]|0)+1}t=Hm[n[(n[r>>2]|0)+12>>2]&63](r,t)|0;ki(o);s=s+8|0}while((s|0)!=(a|0))}s=e+20|0;if(i[s>>0]|0){i[s>>0]=0;rs(n[e+4>>2]|0)}J=c;return t|0}function Ti(e){e=e|0;n[e>>2]=4624;Qi(e+8|0);Si(e);return}function Pi(e){e=e|0;Ti(e);qp(e);return}function Si(e){e=e|0;return}function Di(e){e=e|0;Z()}function ki(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Qi(e){e=e|0;var t=0,s=0,i=0;s=n[e>>2]|0;if(s|0){i=e+4|0;t=n[i>>2]|0;if((t|0)==(s|0))t=s;else{do{t=t+-8|0;ki(t)}while((t|0)!=(s|0));t=n[e>>2]|0}n[i>>2]=s;ye(t,(n[e+8>>2]|0)-t|0)}return}function Ri(e,t){e=e|0;t=t|0;return}function Oi(e){e=e|0;Ag(e);qp(e);return}function Vi(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function Li(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==8546?e+12|0:0)|0}function Hi(e){e=e|0;ye(e,16);return}function Ni(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=4692;n[e+4>>2]=t;Yi(e+8|0);return}function Gi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4740;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function ji(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s<<3);return}function zi(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function Wi(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>536870911){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t<<3)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s<<3)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t<<3);return}function Xi(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0;a=n[e>>2]|0;l=e+4|0;s=n[l>>2]|0;o=t+4|0;if((s|0)==(a|0)){r=o;A=e;i=n[o>>2]|0;s=a}else{i=n[o>>2]|0;do{A=s;s=s+-8|0;n[i+-8>>2]=n[s>>2];A=A+-4|0;n[i+-4>>2]=n[A>>2];n[s>>2]=0;n[A>>2]=0;i=(n[o>>2]|0)+-8|0;n[o>>2]=i}while((s|0)!=(a|0));r=o;A=e;s=n[e>>2]|0}n[A>>2]=i;n[r>>2]=s;a=t+8|0;o=n[l>>2]|0;n[l>>2]=n[a>>2];n[a>>2]=o;a=e+8|0;l=t+12|0;e=n[a>>2]|0;n[a>>2]=n[l>>2];n[l>>2]=e;n[t>>2]=n[r>>2];return}function Ki(e){e=e|0;var t=0,s=0,i=0,r=0;s=n[e+4>>2]|0;i=e+8|0;t=n[i>>2]|0;if((t|0)!=(s|0))do{r=t+-8|0;n[i>>2]=r;ki(r);t=n[i>>2]|0}while((t|0)!=(s|0));t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function Zi(e){e=e|0;return 536870911}function Ji(e){e=e|0;n[e>>2]=4716;return}function Yi(e){e=e|0;nr(e);Ar(e+3980|0);or(e+4380|0);i[e+4780>>0]=0;i[e+4781>>0]=0;return}function $i(e){e=e|0;n[e>>2]=4692;gr(e+8|0);sr(e);return}function qi(e){e=e|0;$i(e);qp(e);return}function er(e,t){e=e|0;t=t|0;return t|0}function tr(e,t){e=e|0;t=t|0;return _r(e+8|0,n[e+4>>2]|0,t)|0}function sr(e){e=e|0;return}function ir(e){e=e|0;sr(e);qp(e);return}function rr(e,t){e=e|0;t=t|0;return t|0}function nr(e){e=e|0;var t=0,s=0;cr(e);hr(e+52|0);hr(e+436|0);Ts(e+852|0,64,0,0);i[e+3976>>0]=0;t=e+20|0;s=t+32|0;do{r[t>>1]=0;t=t+2|0}while((t|0)<(s|0));t=Zf(44)|0;Ts(t,256,0,0);n[e+896>>2]=t;t=Zf(44)|0;Ts(t,256,0,0);n[e+900>>2]=t;t=e+820|0;n[t>>2]=0;n[t+4>>2]=0;n[t+8>>2]=0;n[t+12>>2]=0;n[t+16>>2]=0;n[t+20>>2]=0;n[t+24>>2]=0;n[t+28>>2]=0;t=0;do{s=Zf(44)|0;Ts(s,256,0,0);n[e+904+(t<<2)>>2]=s;s=Zf(44)|0;Ts(s,256,0,0);n[e+1928+(t<<2)>>2]=s;s=Zf(44)|0;Ts(s,256,0,0);n[e+2952+(t<<2)>>2]=s;t=t+1|0}while(t>>>0<256);return}function Ar(e){e=e|0;pr(e,16,4,8,0);pr(e+80|0,16,1,8,0);pr(e+160|0,32,2,8,0);pr(e+240|0,32,22,8,0);pr(e+320|0,32,20,8,0);return}function or(e){e=e|0;is(e,16,4,8,0);is(e+80|0,16,1,8,0);is(e+160|0,32,2,8,0);is(e+240|0,32,22,8,0);is(e+320|0,32,20,8,0);return}function ar(e){e=e|0;fr(e+320|0);fr(e+240|0);fr(e+160|0);fr(e+80|0);fr(e);return}function lr(e){e=e|0;var t=0,s=0;t=n[e+896>>2]|0;if(t|0){Ms(t);qp(t)}t=n[e+900>>2]|0;if(t|0){Ms(t);qp(t)}s=0;do{t=n[e+904+(s<<2)>>2]|0;if(t|0){Ms(t);qp(t)}t=n[e+1928+(s<<2)>>2]|0;if(t|0){Ms(t);qp(t)}t=n[e+2952+(s<<2)>>2]|0;if(t|0){Ms(t);qp(t)}s=s+1|0}while((s|0)!=256);Ms(e+852|0);return}function cr(e){e=e|0;var t=0;i[e>>0]=0;i[e+1>>0]=0;i[e+2>>0]=0;i[e+3>>0]=0;t=e+4|0;i[t>>0]=0;i[t+1>>0]=0;i[t+2>>0]=0;i[t+3>>0]=0;e=e+12|0;t=e;i[t>>0]=0;i[t+1>>0]=0;i[t+2>>0]=0;i[t+3>>0]=0;e=e+4|0;i[e>>0]=0;i[e+1>>0]=0;i[e+2>>0]=0;i[e+3>>0]=0;return}function hr(e){e=e|0;var t=0;t=e+384|0;do{ur(e);e=e+24|0}while((e|0)!=(t|0));return}function ur(e){e=e|0;dr(e);return}function dr(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;i[e+20>>0]=1;return}function pr(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var A=0;n[e+4>>2]=t;n[e+8>>2]=s;n[e+12>>2]=i;n[e+16>>2]=r;n[e+36>>2]=0;n[e+40>>2]=0;n[e+44>>2]=0;vs(e+48|0);n[e+68>>2]=0;n[e+72>>2]=0;n[e+76>>2]=0;do{if(!r){s=e+20|0;if((t+-1|0)>>>0<31){n[s>>2]=t;r=1<<t;n[e+24>>2]=r;s=r>>>1;n[e+28>>2]=0-s;s=r+-1-s|0;break}else{n[s>>2]=32;n[e+24>>2]=0;n[e+28>>2]=-2147483648;s=2147483647;break}}else{i=e+20|0;n[i>>2]=0;n[e+24>>2]=r;s=r;A=0;while(1){s=s>>>1;t=A+1|0;if(!s)break;else A=t}n[i>>2]=(1<<A|0)==(r|0)?A:t;s=r>>>1;n[e+28>>2]=0-s;s=r+-1-s|0}}while(0);n[e+32>>2]=s;n[e>>2]=0;return}function fr(e){e=e|0;var t=0,s=0,i=0,r=0,A=0;A=e+36|0;s=n[A>>2]|0;i=e+40|0;t=n[i>>2]|0;if((t|0)!=(s|0))do{t=t+-44|0;Ms(t)}while((t|0)!=(s|0));n[i>>2]=s;i=e+68|0;r=n[i>>2]|0;s=e+72|0;t=n[s>>2]|0;if((t|0)!=(r|0))do{t=t+-44|0;Ms(t)}while((t|0)!=(r|0));n[s>>2]=r;Cs(i);Cs(A);return}function gr(e){e=e|0;mr(e+4380|0);ar(e+3980|0);lr(e);return}function mr(e){e=e|0;os(e+320|0);os(e+240|0);os(e+160|0);os(e+80|0);os(e);return}function _r(e,t,s){e=e|0;t=t|0;s=s|0;var a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+32|0;p=f;a=e+4781|0;if(!(i[a>>0]|0)){br(e+4380|0);i[a>>0]=1}a=e+3976|0;if(!(i[a>>0]|0)){i[a>>0]=1;Br(yr(t)|0,s,20);wr(p,s);c=e;a=p;l=c+20|0;do{i[c>>0]=i[a>>0]|0;c=c+1|0;a=a+1|0}while((c|0)<(l|0));r[e+12>>1]=0}else{u=Ns(t,e+852|0)|0;if(u){if(u&32|0)Cr((Ns(t,n[e+904+(((vr(e)|0)&255)<<2)>>2]|0)|0)&255,e);d=e+14|0;c=i[d>>0]|0;a=c&7;c=(c&255)>>>3&7;l=A[16+(c<<3)+a>>0]|0;a=A[80+(c<<3)+a>>0]|0;if(!(u&16))h=r[e+20+(l<<1)>>1]|0;else{g=e+20+(l<<1)|0;h=(As(e+4380|0,t,o[g>>1]|0,l>>>0<3?l:3)|0)&65535;r[g>>1]=h}r[e+12>>1]=h;if(u&8|0){g=e+15|0;i[g>>0]=Ns(t,n[e+1928+(A[g>>0]<<2)>>2]|0)|0}if(u&4|0){d=Ns(t,n[e+896+(((A[d>>0]|0)>>>6&1)<<2)>>2]|0)|0;g=e+16|0;i[g>>0]=Mr(d+(i[g>>0]|0)|0)|0}if(u&2|0){g=e+17|0;i[g>>0]=Ns(t,n[e+2952+(A[g>>0]<<2)>>2]|0)|0}if(u&1){g=e+18|0;r[g>>1]=As(e+4460|0,t,o[g>>1]|0,0)|0}}else{g=i[e+14>>0]|0;a=g&7;g=(g&255)>>>3&7;c=g;l=A[16+(g<<3)+a>>0]|0;a=A[80+(g<<3)+a>>0]|0}h=e+52+(l*24|0)|0;u=e+4540|0;d=(c|0)==1&1;c=As(u,t,Er(h)|0,d)|0;n[p>>2]=c;n[e>>2]=(n[e>>2]|0)+c;Fr(h,p);h=e+436+(l*24|0)|0;c=Er(h)|0;l=xr(u)|0;g=e+4620|0;l=As(g,t,c,(l>>>0<20?l&-2:20)|d)|0;n[p>>2]=l;c=e+4|0;n[c>>2]=(n[c>>2]|0)+l;Fr(h,p);p=xr(u)|0;p=(xr(g)|0)+p|0;g=e+820+(a<<2)|0;p=As(e+4700|0,t,n[g>>2]|0,(p>>>0<36?p>>>1&2147483646:18)|d)|0;n[e+8>>2]=p;n[g>>2]=p;Ur(e,s)}J=f;return s+20|0}function br(e){e=e|0;ns(e);ns(e+80|0);ns(e+160|0);ns(e+240|0);ns(e+320|0);return}function yr(e){e=e|0;return n[e>>2]|0}function Br(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0;c=e+4|0;r=n[c>>2]|0;l=(n[e+8>>2]|0)-r|0;l=l>>>0>s>>>0?s:l;a=e+12|0;A=(n[a>>2]|0)+r|0;o=A+l|0;if(l){r=A;A=t;while(1){i[A>>0]=i[r>>0]|0;r=r+1|0;if((r|0)==(o|0))break;else A=A+1|0}r=n[c>>2]|0}n[c>>2]=r+l;s=s-l|0;if(s|0){Fs(e);A=(n[a>>2]|0)+(n[c>>2]|0)|0;o=A+s|0;r=t+l|0;while(1){i[r>>0]=i[A>>0]|0;A=A+1|0;if((A|0)==(o|0))break;else r=r+1|0}n[c>>2]=(n[c>>2]|0)+s}return}function wr(e,t){e=e|0;t=t|0;cr(e);n[e>>2]=Ir(t)|0;n[e+4>>2]=Ir(t+4|0)|0;n[e+8>>2]=Ir(t+8|0)|0;r[e+12>>1]=Tr(t+12|0)|0;Cr(Pr(t+14|0)|0,e);i[e+15>>0]=Pr(t+15|0)|0;i[e+16>>0]=Sr(t+16|0)|0;i[e+17>>0]=Sr(t+17|0)|0;r[e+18>>1]=Tr(t+18|0)|0;return}function vr(e){e=e|0;return i[e+14>>0]|0}function Cr(e,t){e=e|0;t=t|0;i[t+14>>0]=e;return}function Mr(e){e=e|0;return e&255|0}function Er(e){e=e|0;return n[e+8>>2]|0}function Fr(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0,a=0,l=0,c=0;c=e+20|0;do{if(!(i[c>>0]|0)){l=e+8|0;s=n[l>>2]|0;r=n[t>>2]|0;A=e+4|0;o=n[A>>2]|0;if((s|0)>=(r|0)){if((o|0)<(r|0)){n[e>>2]=o;n[A>>2]=n[t>>2]}else n[e>>2]=r;i[c>>0]=1;break}n[e>>2]=o;n[A>>2]=s;A=e+16|0;o=n[A>>2]|0;a=n[t>>2]|0;s=e+12|0;r=n[s>>2]|0;if((o|0)<(a|0)){n[l>>2]=r;n[s>>2]=o;n[A>>2]=n[t>>2];break}if((r|0)<(a|0)){n[l>>2]=r;n[s>>2]=n[t>>2];break}else{n[l>>2]=a;break}}else{A=n[t>>2]|0;a=e+8|0;s=n[a>>2]|0;o=e+12|0;r=n[o>>2]|0;if((A|0)>=(s|0)){s=e+16|0;if((A|0)<(r|0)){n[s>>2]=r;n[o>>2]=n[t>>2]}else n[s>>2]=A;i[c>>0]=0;break}n[e+16>>2]=r;n[o>>2]=s;s=n[t>>2]|0;r=n[e>>2]|0;A=e+4|0;o=n[A>>2]|0;if((s|0)<(r|0)){n[a>>2]=o;n[A>>2]=r;n[e>>2]=n[t>>2];break}if((s|0)<(o|0)){n[a>>2]=o;n[A>>2]=n[t>>2];break}else{n[a>>2]=s;break}}}while(0);return}function xr(e){e=e|0;return n[e>>2]|0}function Ur(e,t){e=e|0;t=t|0;var s=0;kr(A[e>>0]|A[e+1>>0]<<8|A[e+2>>0]<<16|A[e+3>>0]<<24,t);s=e+4|0;kr(A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24,t+4|0);s=e+8|0;kr(A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24,t+8|0);s=e+12|0;Qr(A[s>>0]|A[s+1>>0]<<8,t+12|0);Rr(vr(e)|0,t+14|0);Rr(i[e+15>>0]|0,t+15|0);Or(i[e+16>>0]|0,t+16|0);Or(i[e+17>>0]|0,t+17|0);e=e+18|0;Qr(A[e>>0]|A[e+1>>0]<<8,t+18|0);return}function Ir(e){e=e|0;return Dr(e)|0}function Tr(e){e=e|0;return(i[e+1>>0]<<8|A[e>>0])&65535|0}function Pr(e){e=e|0;return i[e>>0]|0}function Sr(e){e=e|0;return i[e>>0]|0}function Dr(e){e=e|0;return(A[e+1>>0]|0)<<8|(A[e>>0]|0)|(A[e+2>>0]|0)<<16|(A[e+3>>0]|0)<<24|0}function kr(e,t){e=e|0;t=t|0;Vr(e,t);return}function Qr(e,t){e=e|0;t=t|0;i[t+1>>0]=(e&65535)>>>8;i[t>>0]=e;return}function Rr(e,t){e=e|0;t=t|0;i[t>>0]=e;return}function Or(e,t){e=e|0;t=t|0;i[t>>0]=e;return}function Vr(e,t){e=e|0;t=t|0;i[t+3>>0]=e>>>24;i[t+2>>0]=e>>>16;i[t+1>>0]=e>>>8;i[t>>0]=e;return}function Lr(e,t){e=e|0;t=t|0;return}function Hr(e){e=e|0;Ag(e);qp(e);return}function Nr(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Gr(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==9202?e+12|0:0)|0}function jr(e){e=e|0;ye(e,16);return}function zr(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=4768;n[e+4>>2]=t;Xr(e+8|0);return}function Wr(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4792;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function Xr(e){e=e|0;Yr(e);$r(e+164|0);qr(e+244|0);i[e+324>>0]=0;i[e+325>>0]=0;return}function Kr(e){e=e|0;n[e>>2]=4768;nn(e+8|0);sr(e);return}function Zr(e){e=e|0;Kr(e);qp(e);return}function Jr(e,t){e=e|0;t=t|0;return on(e+8|0,n[e+4>>2]|0,t)|0}function Yr(e){e=e|0;var t=0,s=0,r=0,A=0,o=0,a=0,l=0;o=J;J=J+16|0;r=o;i[e>>0]=0;Ts(e+4|0,516,0,0);Ts(e+48|0,6,0,0);n[e+92>>2]=0;n[e+96>>2]=0;s=e+100|0;sn(s);rn(r);A=n[r>>2]|0;r=n[r+4>>2]|0;t=4;while(1){a=s;l=a;i[l>>0]=A;i[l+1>>0]=A>>8;i[l+2>>0]=A>>16;i[l+3>>0]=A>>24;a=a+4|0;i[a>>0]=r;i[a+1>>0]=r>>8;i[a+2>>0]=r>>16;i[a+3>>0]=r>>24;t=t+-1|0;if(!t)break;else s=s+8|0}l=e+132|0;n[l>>2]=0;n[l+4>>2]=0;n[l+8>>2]=0;n[l+12>>2]=0;n[l+16>>2]=0;n[l+20>>2]=0;n[l+24>>2]=0;n[l+28>>2]=0;J=o;return}function $r(e){e=e|0;pr(e,32,9,8,0);return}function qr(e){e=e|0;is(e,32,9,8,0);return}function en(e){e=e|0;fr(e);return}function tn(e){e=e|0;Ms(e+48|0);Ms(e+4|0);return}function sn(e){e=e|0;var t=0;t=e+32|0;do{rn(e);e=e+8|0}while((e|0)!=(t|0));return}function rn(e){e=e|0;var t=0;t=e;i[t>>0]=0;i[t+1>>0]=0;i[t+2>>0]=0;i[t+3>>0]=0;e=e+4|0;i[e>>0]=0;i[e+1>>0]=0;i[e+2>>0]=0;i[e+3>>0]=0;return}function nn(e){e=e|0;An(e+244|0);en(e+164|0);tn(e);return}function An(e){e=e|0;os(e);return}function on(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,o=0,a=0,l=0,c=0;r=e+325|0;if(!(i[r>>0]|0)){an(e+244|0);i[r>>0]=1}if(!(i[e>>0]|0)){i[e>>0]=1;Br(yr(t)|0,s,8);a=ln(s)|0;l=v()|0;e=e+100|0;t=e;i[t>>0]=a;i[t+1>>0]=a>>8;i[t+2>>0]=a>>16;i[t+3>>0]=a>>24;e=e+4|0;i[e>>0]=l;i[e+1>>0]=l>>8;i[e+2>>0]=l>>16;i[e+3>>0]=l>>24}else{l=e+92|0;e:do{if(!(n[e+132+(n[l>>2]<<2)>>2]|0)){r=Ns(t,e+48|0)|0;switch(r|0){case 1:{t=As(e+244|0,t,0,0)|0;n[e+132+(n[l>>2]<<2)>>2]=t;t=n[l>>2]|0;c=n[e+132+(t<<2)>>2]|0;a=e+100+(t<<3)|0;o=a;r=o;o=o+4|0;c=sm(A[r>>0]|A[r+1>>0]<<8|A[r+2>>0]<<16|A[r+3>>0]<<24|0,A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|0,c|0,((c|0)<0)<<31>>31|0)|0;o=v()|0;r=a;i[r>>0]=c;i[r+1>>0]=c>>8;i[r+2>>0]=c>>16;i[r+3>>0]=c>>24;a=a+4|0;i[a>>0]=o;i[a+1>>0]=o>>8;i[a+2>>0]=o>>16;i[a+3>>0]=o>>24;n[e+148+(t<<2)>>2]=0;break e}case 2:{c=e+96|0;n[c>>2]=(n[c>>2]|0)+1&3;a=e+100+(n[l>>2]<<3)+4|0;a=As(e+244|0,t,A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24,8)|0;r=e+100+(n[c>>2]<<3)|0;o=r;i[o>>0]=0;i[o+1>>0]=0;i[o+2>>0]=0;i[o+3>>0]=0;r=r+4|0;i[r>>0]=a;i[r+1>>0]=a>>8;i[r+2>>0]=a>>16;i[r+3>>0]=a>>24;r=cn(t)|0;c=n[c>>2]|0;t=e+100+(c<<3)|0;a=t;o=a;a=a+4|0;a=A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24;r=A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|r;o=t;i[o>>0]=r;i[o+1>>0]=r>>8;i[o+2>>0]=r>>16;i[o+3>>0]=r>>24;t=t+4|0;i[t>>0]=a;i[t+1>>0]=a>>8;i[t+2>>0]=a>>16;i[t+3>>0]=a>>24;n[l>>2]=c;n[e+132+(c<<2)>>2]=0;n[e+148+(n[l>>2]<<2)>>2]=0;break e}default:{if((r|0)<=2)break e;n[l>>2]=r+2+(n[l>>2]|0)&3;on(e,t,s)|0;break e}}}else{a=Ns(t,e+4|0)|0;if((a|0)==1){r=As(e+244|0,t,n[e+132+(n[l>>2]<<2)>>2]|0,1)|0;c=n[l>>2]|0;t=e+100+(c<<3)|0;a=t;o=a;a=a+4|0;r=sm(A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|0,A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24|0,r|0,((r|0)<0)<<31>>31|0)|0;a=v()|0;o=t;i[o>>0]=r;i[o+1>>0]=r>>8;i[o+2>>0]=r>>16;i[o+3>>0]=r>>24;t=t+4|0;i[t>>0]=a;i[t+1>>0]=a>>8;i[t+2>>0]=a>>16;i[t+3>>0]=a>>24;n[e+148+(c<<2)>>2]=0;break}if((a|0)>=511){if((a|0)==512){c=e+96|0;n[c>>2]=(n[c>>2]|0)+1&3;a=e+100+(n[l>>2]<<3)+4|0;a=As(e+244|0,t,A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24,8)|0;r=e+100+(n[c>>2]<<3)|0;o=r;i[o>>0]=0;i[o+1>>0]=0;i[o+2>>0]=0;i[o+3>>0]=0;r=r+4|0;i[r>>0]=a;i[r+1>>0]=a>>8;i[r+2>>0]=a>>16;i[r+3>>0]=a>>24;r=cn(t)|0;c=n[c>>2]|0;t=e+100+(c<<3)|0;a=t;o=a;a=a+4|0;a=A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24;r=A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|r;o=t;i[o>>0]=r;i[o+1>>0]=r>>8;i[o+2>>0]=r>>16;i[o+3>>0]=r>>24;t=t+4|0;i[t>>0]=a;i[t+1>>0]=a>>8;i[t+2>>0]=a>>16;i[t+3>>0]=a>>24;n[l>>2]=c;n[e+132+(c<<2)>>2]=0;n[e+148+(n[l>>2]<<2)>>2]=0;break}if((a|0)<=511)break;n[l>>2]=(n[l>>2]|0)+a&3;on(e,t,s)|0;break}do{if(!a){r=As(e+244|0,t,0,7)|0;o=e+148+(n[l>>2]<<2)|0;n[o>>2]=(n[o>>2]|0)+1;o=n[l>>2]|0;if((n[e+148+(o<<2)>>2]|0)>3){n[e+132+(o<<2)>>2]=r;n[e+148+(n[l>>2]<<2)>>2]=0}}else{if((a|0)<500){r=e+244|0;o=b(n[e+132+(n[l>>2]<<2)>>2]|0,a)|0;if((a|0)<10){r=As(r,t,o,2)|0;break}else{r=As(r,t,o,3)|0;break}}if((a|0)==500){r=As(e+244|0,t,(n[e+132+(n[l>>2]<<2)>>2]|0)*500|0,4)|0;o=e+148+(n[l>>2]<<2)|0;n[o>>2]=(n[o>>2]|0)+1;o=n[l>>2]|0;if((n[e+148+(o<<2)>>2]|0)<=3)break;n[e+132+(o<<2)>>2]=r;n[e+148+(n[l>>2]<<2)>>2]=0;break}r=500-a|0;o=e+244|0;a=n[e+132+(n[l>>2]<<2)>>2]|0;if((r|0)>-10){r=As(o,t,b(a,r)|0,5)|0;break}r=As(o,t,b(a,-10)|0,6)|0;o=e+148+(n[l>>2]<<2)|0;n[o>>2]=(n[o>>2]|0)+1;o=n[l>>2]|0;if((n[e+148+(o<<2)>>2]|0)>3){n[e+132+(o<<2)>>2]=r;n[e+148+(n[l>>2]<<2)>>2]=0}}}while(0);c=e+100+(n[l>>2]<<3)|0;o=c;t=o;o=o+4|0;o=sm(A[t>>0]|A[t+1>>0]<<8|A[t+2>>0]<<16|A[t+3>>0]<<24|0,A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|0,r|0,((r|0)<0)<<31>>31|0)|0;t=v()|0;a=c;i[a>>0]=o;i[a+1>>0]=o>>8;i[a+2>>0]=o>>16;i[a+3>>0]=o>>24;c=c+4|0;i[c>>0]=t;i[c+1>>0]=t>>8;i[c+2>>0]=t>>16;i[c+3>>0]=t>>24}}while(0);hn(e+100+(n[l>>2]<<3)|0,s)}return s+8|0}function an(e){e=e|0;ns(e);return}function ln(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;i=Dr(e)|0;un(s,i,Dr(e+4|0)|0);e=n[s>>2]|0;w(n[s+4>>2]|0);J=t;return e|0}function cn(e){e=e|0;var t=0;t=(Ws(e)|0)&65535;return((Ws(e)|0)&65535)<<16|t|0}function hn(e,t){e=e|0;t=t|0;var s=0;s=e;Vr(A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24,t);e=e+4|0;Vr(A[e>>0]|A[e+1>>0]<<8|A[e+2>>0]<<16|A[e+3>>0]<<24,t+4|0);return}function un(e,t,s){e=e|0;t=t|0;s=s|0;var r=0;r=e;i[r>>0]=t;i[r+1>>0]=t>>8;i[r+2>>0]=t>>16;i[r+3>>0]=t>>24;t=e+4|0;i[t>>0]=s;i[t+1>>0]=s>>8;i[t+2>>0]=s>>16;i[t+3>>0]=s>>24;return}function dn(e){e=e|0;Ag(e);qp(e);return}function pn(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function fn(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==9890?e+12|0:0)|0}function gn(e){e=e|0;ye(e,16);return}function mn(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=4820;n[e+4>>2]=t;bn(e+8|0);return}function _n(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4844;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function bn(e){e=e|0;i[e>>0]=0;vn(e+1|0);Ts(e+8|0,128,0,0);Ts(e+52|0,256,0,0);Ts(e+96|0,256,0,0);Ts(e+140|0,256,0,0);Ts(e+184|0,256,0,0);Ts(e+228|0,256,0,0);Ts(e+272|0,256,0,0);return}function yn(e){e=e|0;n[e>>2]=4820;Cn(e+8|0);sr(e);return}function Bn(e){e=e|0;yn(e);qp(e);return}function wn(e,t){e=e|0;t=t|0;return Mn(e+8|0,n[e+4>>2]|0,t)|0}function vn(e){e=e|0;var t=0;i[e>>0]=0;i[e+1>>0]=0;t=e+2|0;i[t>>0]=0;i[t+1>>0]=0;e=e+4|0;i[e>>0]=0;i[e+1>>0]=0;return}function Cn(e){e=e|0;Ms(e+272|0);Ms(e+228|0);Ms(e+184|0);Ms(e+140|0);Ms(e+96|0);Ms(e+52|0);Ms(e+8|0);return}function Mn(e,t,s){e=e|0;t=t|0;s=s|0;var n=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0;p=J;J=J+16|0;u=p;if(!(i[e>>0]|0)){i[e>>0]=1;Br(yr(t)|0,s,6);En(u,s);d=e+1|0;i[d>>0]=i[u>>0]|0;i[d+1>>0]=i[u+1>>0]|0;i[d+2>>0]=i[u+2>>0]|0;i[d+3>>0]=i[u+3>>0]|0;i[d+4>>0]=i[u+4>>0]|0;i[d+5>>0]=i[u+5>>0]|0}else{d=Ns(t,e+8|0)|0;vn(u);if(!(d&1)){n=e+1|0;n=(A[n>>0]|A[n+1>>0]<<8)&255}else{h=(Ns(t,e+52|0)|0)&255;n=e+1|0;n=(Mr(h+((A[n>>0]|A[n+1>>0]<<8)&255)|0)|0)&255}r[u>>1]=n;if(!(d&2)){h=e+1|0;n=n|(A[h>>0]|A[h+1>>0]<<8)&-256}else{n=(Ns(t,e+96|0)|0)&255;h=e+1|0;n=((Mr((((A[h>>0]|A[h+1>>0]<<8)&65535)>>>8)+n|0)|0)&255)<<8;n=(n|o[u>>1])&65535}r[u>>1]=n;do{if(d&64){c=e+1|0;a=(n&255)-((A[c>>0]|A[c+1>>0]<<8)&255)|0;if(!(d&4)){n=e+3|0;n=(A[n>>0]|A[n+1>>0]<<8)&255}else{n=(Ns(t,e+140|0)|0)&255;h=e+3|0;h=a+((A[h>>0]|A[h+1>>0]<<8)&255)|0;n=(Mr(((h|0)<1?0:(h|0)>254?255:h&255)+n|0)|0)&255}h=u+2|0;r[h>>1]=n;if(!(d&16)){n=e+5|0;n=(A[n>>0]|A[n+1>>0]<<8)&255}else{n=Ns(t,e+228|0)|0;f=e+3|0;l=e+5|0;l=((a+(r[h>>1]&255)-((A[f>>0]|A[f+1>>0]<<8)&255)|0)/2|0)+((A[l>>0]|A[l+1>>0]<<8)&255)|0;n=(Mr(((l|0)<1?0:(l|0)>254?255:l&255)+(n&255)|0)|0)&255}l=u+4|0;r[l>>1]=n;n=((o[u>>1]|0)>>>8)-(((A[c>>0]|A[c+1>>0]<<8)&65535)>>>8)|0;if(!(d&8)){a=e+3|0;a=r[h>>1]|(A[a>>0]|A[a+1>>0]<<8)&-256}else{a=(Ns(t,e+184|0)|0)&255;f=e+3|0;f=(((A[f>>0]|A[f+1>>0]<<8)&65535)>>>8)+n|0;a=((Mr(((f|0)<1?0:(f|0)>254?255:f&255)+a|0)|0)&255)<<8;a=(a|o[h>>1])&65535}r[h>>1]=a;if(!(d&32)){f=e+5|0;r[l>>1]=r[l>>1]|(A[f>>0]|A[f+1>>0]<<8)&-256;break}else{f=Ns(t,e+272|0)|0;t=e+3|0;d=e+5|0;d=((((o[h>>1]|0)>>>8)+n-(((A[t>>0]|A[t+1>>0]<<8)&65535)>>>8)|0)/2|0)+(((A[d>>0]|A[d+1>>0]<<8)&65535)>>>8)|0;f=((Mr(((d|0)<1?0:(d|0)>254?255:d&255)+(f&255)|0)|0)&255)<<8;r[l>>1]=f|o[l>>1];break}}else{r[u+2>>1]=n;r[u+4>>1]=n}}while(0);f=e+1|0;i[f>>0]=i[u>>0]|0;i[f+1>>0]=i[u+1>>0]|0;i[f+2>>0]=i[u+2>>0]|0;i[f+3>>0]=i[u+3>>0]|0;i[f+4>>0]=i[u+4>>0]|0;i[f+5>>0]=i[u+5>>0]|0;Fn(f,s)}J=p;return s+6|0}function En(e,t){e=e|0;t=t|0;var s=0,i=0;i=Tr(t)|0;s=Tr(t+2|0)|0;xn(e,i,s,Tr(t+4|0)|0);return}function Fn(e,t){e=e|0;t=t|0;var s=0;Qr(A[e>>0]|A[e+1>>0]<<8,t);s=e+2|0;Qr(A[s>>0]|A[s+1>>0]<<8,t+2|0);e=e+4|0;Qr(A[e>>0]|A[e+1>>0]<<8,t+4|0);return}function xn(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;i[e>>0]=t;i[e+1>>0]=t>>8;t=e+2|0;i[t>>0]=s;i[t+1>>0]=s>>8;s=e+4|0;i[s>>0]=r;i[s+1>>0]=r>>8;return}function Un(e){e=e|0;Ag(e);qp(e);return}function In(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Tn(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==10570?e+12|0:0)|0}function Pn(e){e=e|0;ye(e,16);return}function Sn(e,t,s){e=e|0;t=t|0;s=s|0;Ji(e);n[e>>2]=4872;n[e+4>>2]=t;kn(e+8|0,s);return}function Dn(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4896;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function kn(e,t){e=e|0;t=t|0;n[e>>2]=n[t>>2];i[e+4>>0]=i[t+4>>0]|0;Vn(e+8|0,t+8|0);Vn(e+20|0,t+20|0);Ln(e+32|0,t+32|0);return}function Qn(e){e=e|0;n[e>>2]=4872;hi(e+8|0);sr(e);return}function Rn(e){e=e|0;Qn(e);qp(e);return}function On(e,t){e=e|0;t=t|0;return yA(e+8|0,n[e+4>>2]|0,t)|0}function Vn(e,t){e=e|0;t=t|0;var s=0,i=0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;s=t+4|0;i=(n[s>>2]|0)-(n[t>>2]|0)|0;if(i|0){Hn(e,i);Nn(e,n[t>>2]|0,n[s>>2]|0,i)}return}function Ln(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+32|0;i=s+24|0;r=s+16|0;o=s+8|0;A=s;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;n[e+20>>2]=0;gA(o,t);mA(A,t);n[r>>2]=n[o>>2];n[r+4>>2]=n[o+4>>2];n[i>>2]=n[A>>2];n[i+4>>2]=n[A+4>>2];Xn(e,r,i,0);J=s;return}function Hn(e,t){e=e|0;t=t|0;var s=0;if((jn(e)|0)>>>0<t>>>0)Xg(e);else{s=Zf(t)|0;n[e+4>>2]=s;n[e>>2]=s;n[e+8>>2]=s+t;return}}function Nn(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;A=J;J=J+16|0;r=A;zn(r,e,i);i=r+4|0;e=s-t|0;if((e|0)>0){hm(n[i>>2]|0,t|0,e|0)|0;n[i>>2]=(n[i>>2]|0)+e}Wn(r);J=A;return}function Gn(e){e=e|0;var t=0,s=0;t=n[e>>2]|0;s=t;if(t|0){n[e+4>>2]=s;ye(t,(n[e+8>>2]|0)-s|0)}return}function jn(e){e=e|0;return 2147483647}function zn(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+s;return}function Wn(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function Xn(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;g=J;J=J+96|0;f=g+80|0;u=g+64|0;l=g+48|0;c=g+40|0;h=g+8|0;a=g;d=g+32|0;p=g+16|0;o=t;A=n[o>>2]|0;o=n[o+4>>2]|0;r=s;s=n[r>>2]|0;r=n[r+4>>2]|0;i=A;if((r|0)==(o|0))o=0;else o=((r-(n[s>>2]|0)|0)/44|0)+((s-A>>2)*93|0)+((o-(n[A>>2]|0)|0)/-44|0)|0;s=(n[e+8>>2]|0)-(n[e+4>>2]|0)|0;s=((s|0)==0?0:((s>>2)*93|0)+-1|0)-((n[e+20>>2]|0)+(n[e+16>>2]|0))|0;if(o>>>0>s>>>0)Zn(e,o-s|0);Jn(c,e);Jn(a,e);r=a;s=n[r>>2]|0;r=n[r+4>>2]|0;A=h;n[A>>2]=s;n[A+4>>2]=r;A=s;if(o|0){s=((r-(n[s>>2]|0)|0)/44|0)+o|0;if((s|0)>0){a=(s>>>0)/93|0;o=A+(a<<2)|0;n[h>>2]=o;s=(n[o>>2]|0)+((s-(a*93|0)|0)*44|0)|0}else{s=92-s|0;a=A+(((s|0)/-93|0)<<2)|0;n[h>>2]=a;s=(n[a>>2]|0)+((92-((s|0)%93|0)|0)*44|0)|0}n[h+4>>2]=s}n[u>>2]=n[c>>2];n[u+4>>2]=n[c+4>>2];n[f>>2]=n[h>>2];n[f+4>>2]=n[h+4>>2];Yn(l,u,f);$n(f,l);qn(u,l);if(eA(f,u)|0){A=p+4|0;o=t+4|0;do{tA(d,f);sA(p,e,d);s=n[p>>2]|0;if((s|0)!=(n[A>>2]|0)){r=n[o>>2]|0;do{Vs(s,r);s=(n[p>>2]|0)+44|0;n[p>>2]=s;r=r+44|0;n[o>>2]=r;if((r-(n[i>>2]|0)|0)==4092){i=i+4|0;n[t>>2]=i;r=n[i>>2]|0;n[o>>2]=r}}while((s|0)!=(n[A>>2]|0))}iA(p);rA(f)|0}while(eA(f,u)|0)}J=g;return}function Kn(e){e=e|0;var t=0,s=0,i=0;t=n[e+4>>2]|0;s=e+8|0;i=n[s>>2]|0;if((i|0)!=(t|0))n[s>>2]=i+(~((i+-4-t|0)>>>2)<<2);t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function Zn(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,y=0,B=0,w=0,v=0,C=0,M=0,E=0,F=0,x=0;F=J;J=J+64|0;B=F+52|0;y=F+48|0;w=F+28|0;v=F+24|0;C=F+20|0;f=F;M=e+8|0;s=n[M>>2]|0;E=e+4|0;l=n[E>>2]|0;m=((s|0)==(l|0)&1)+t|0;o=(m>>>0)/93|0;o=o+((m-(o*93|0)|0)!=0&1)|0;m=e+16|0;i=n[m>>2]|0;a=(i>>>0)/93|0;g=o>>>0<a>>>0?o:a;t=o-g|0;A=s;e:do{if(!t){n[m>>2]=(b(g,-93)|0)+i;if(g|0){a=e+12|0;c=e+12|0;h=w+4|0;u=w+8|0;d=w+12|0;t=g;i=l;while(1){o=n[i>>2]|0;A=i+4|0;n[E>>2]=A;_=n[a>>2]|0;i=_;do{if((s|0)==(_|0)){_=n[e>>2]|0;s=_;if(A>>>0<=_>>>0){s=i-s|0;s=(s|0)==0?1:s>>1;oA(w,s,s>>>2,c);n[v>>2]=n[E>>2];n[C>>2]=n[M>>2];n[y>>2]=n[v>>2];n[B>>2]=n[C>>2];hA(w,y,B);s=n[e>>2]|0;n[e>>2]=n[w>>2];n[w>>2]=s;s=n[E>>2]|0;n[E>>2]=n[h>>2];n[h>>2]=s;s=n[M>>2]|0;n[M>>2]=n[u>>2];n[u>>2]=s;s=n[a>>2]|0;n[a>>2]=n[d>>2];n[d>>2]=s;cA(w);s=n[M>>2]|0;break}_=A;s=((_-s>>2)+1|0)/-2|0;r=A+(s<<2)|0;i=i-_|0;if(!i)s=r;else{um(r|0,A|0,i|0)|0;s=(n[E>>2]|0)+(s<<2)|0}_=r+(i>>2<<2)|0;n[M>>2]=_;n[E>>2]=s;s=_}}while(0);n[s>>2]=o;s=(n[M>>2]|0)+4|0;n[M>>2]=s;t=t+-1|0;if(!t)break e;i=n[E>>2]|0}}}else{_=e+12|0;i=n[_>>2]|0;r=i-(n[e>>2]|0)|0;s=A-l>>2;if(t>>>0>((r>>2)-s|0)>>>0){p=r>>1;d=s+t|0;oA(f,p>>>0<d>>>0?d:p,s-g|0,e+12|0);do{n[B>>2]=Zf(4092)|0;aA(f,B);t=t+-1|0}while((t|0)!=0);if(!g)s=n[E>>2]|0;else{a=f+8|0;l=f+12|0;c=f+4|0;h=f+16|0;u=w+4|0;d=w+8|0;p=w+12|0;o=g;t=n[a>>2]|0;s=n[E>>2]|0;do{A=n[l>>2]|0;i=A;do{if((t|0)==(A|0)){r=n[c>>2]|0;A=n[f>>2]|0;t=A;if(r>>>0<=A>>>0){t=i-t|0;t=(t|0)==0?1:t>>1;oA(w,t,t>>>2,n[h>>2]|0);n[v>>2]=n[c>>2];n[C>>2]=n[a>>2];n[y>>2]=n[v>>2];n[B>>2]=n[C>>2];hA(w,y,B);t=n[f>>2]|0;n[f>>2]=n[w>>2];n[w>>2]=t;t=n[c>>2]|0;n[c>>2]=n[u>>2];n[u>>2]=t;t=n[a>>2]|0;n[a>>2]=n[d>>2];n[d>>2]=t;t=n[l>>2]|0;n[l>>2]=n[p>>2];n[p>>2]=t;cA(w);t=n[a>>2]|0;break}x=r;t=((x-t>>2)+1|0)/-2|0;A=r+(t<<2)|0;i=i-x|0;if(!i)t=A;else{um(A|0,r|0,i|0)|0;t=(n[c>>2]|0)+(t<<2)|0}x=A+(i>>2<<2)|0;n[a>>2]=x;n[c>>2]=t;t=x}}while(0);n[t>>2]=n[s>>2];t=(n[a>>2]|0)+4|0;n[a>>2]=t;s=(n[E>>2]|0)+4|0;n[E>>2]=s;o=o+-1|0}while((o|0)!=0)}t=n[M>>2]|0;if((t|0)!=(s|0)){do{t=t+-4|0;lA(f,t);s=n[E>>2]|0}while((t|0)!=(s|0));t=n[M>>2]|0}x=n[e>>2]|0;n[e>>2]=n[f>>2];n[f>>2]=x;x=f+4|0;n[E>>2]=n[x>>2];n[x>>2]=s;x=f+8|0;n[M>>2]=n[x>>2];n[x>>2]=t;x=f+12|0;E=n[_>>2]|0;n[_>>2]=n[x>>2];n[x>>2]=E;n[m>>2]=(n[m>>2]|0)+(b(g,-93)|0);cA(f);break}else{t:do{if((i|0)==(A|0))c=18;else{while(1){n[B>>2]=Zf(4092)|0;nA(e,B);t=t+-1|0;if(!t)break;if((n[_>>2]|0)==(n[M>>2]|0)){c=18;break t}}s=g;t=n[m>>2]|0}}while(0);if((c|0)==18){i=~(o>>>0>a>>>0?a:o);s=t;do{n[B>>2]=Zf(4092)|0;AA(e,B);s=s+-1|0;r=(((n[M>>2]|0)-(n[E>>2]|0)|0)==4?92:93)+(n[m>>2]|0)|0;n[m>>2]=r}while((s|0)!=0);s=t+-1-i|0;t=r}n[m>>2]=t+(b(s,-93)|0);if(!s)break;a=e+12|0;l=w+4|0;c=w+8|0;h=w+12|0;t=n[M>>2]|0;do{A=n[E>>2]|0;o=n[A>>2]|0;A=A+4|0;n[E>>2]=A;x=n[_>>2]|0;i=x;do{if((t|0)==(x|0)){x=n[e>>2]|0;t=x;if(A>>>0<=x>>>0){t=i-t|0;t=(t|0)==0?1:t>>1;oA(w,t,t>>>2,a);n[v>>2]=n[E>>2];n[C>>2]=n[M>>2];n[y>>2]=n[v>>2];n[B>>2]=n[C>>2];hA(w,y,B);t=n[e>>2]|0;n[e>>2]=n[w>>2];n[w>>2]=t;t=n[E>>2]|0;n[E>>2]=n[l>>2];n[l>>2]=t;t=n[M>>2]|0;n[M>>2]=n[c>>2];n[c>>2]=t;t=n[_>>2]|0;n[_>>2]=n[h>>2];n[h>>2]=t;cA(w);t=n[M>>2]|0;break}x=A;t=((x-t>>2)+1|0)/-2|0;r=A+(t<<2)|0;i=i-x|0;if(!i)t=r;else{um(r|0,A|0,i|0)|0;t=(n[E>>2]|0)+(t<<2)|0}x=r+(i>>2<<2)|0;n[M>>2]=x;n[E>>2]=t;t=x}}while(0);n[t>>2]=o;t=(n[M>>2]|0)+4|0;n[M>>2]=t;s=s+-1|0}while((s|0)!=0)}}}while(0);J=F;return}function Jn(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;s=(n[t+16>>2]|0)+(n[t+20>>2]|0)|0;A=n[t+4>>2]|0;i=(s>>>0)/93|0;r=A+(i<<2)|0;if((n[t+8>>2]|0)==(A|0))t=0;else t=(n[r>>2]|0)+((s-(i*93|0)|0)*44|0)|0;n[e>>2]=r;n[e+4>>2]=t;return}function Yn(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=t;t=n[r+4>>2]|0;i=e;n[i>>2]=n[r>>2];n[i+4>>2]=t;i=s;t=n[i+4>>2]|0;s=e+8|0;n[s>>2]=n[i>>2];n[s+4>>2]=t;return}function $n(e,t){e=e|0;t=t|0;n[e>>2]=n[t>>2];n[e+4>>2]=n[t+4>>2];n[e+8>>2]=n[t+8>>2];n[e+12>>2]=n[t+12>>2];return}function qn(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0;s=J;J=J+32|0;i=s+24|0;r=s+16|0;o=s+8|0;A=s;a=t+8|0;l=n[a>>2]|0;a=n[a+4>>2]|0;t=o;n[t>>2]=l;n[t+4>>2]=a;t=A;n[t>>2]=l;n[t+4>>2]=a;n[r>>2]=n[o>>2];n[r+4>>2]=n[o+4>>2];n[i>>2]=n[A>>2];n[i+4>>2]=n[A+4>>2];Yn(e,r,i);J=s;return}function eA(e,t){e=e|0;t=t|0;return(pA(e,t)|0)^1|0}function tA(e,t){e=e|0;t=t|0;var s=0,i=0;s=n[t>>2]|0;i=n[t+4>>2]|0;if((s|0)==(n[t+8>>2]|0))fA(e,i,n[t+12>>2]|0);else fA(e,i,(n[s>>2]|0)+4092|0);return}function sA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0;i=n[s>>2]|0;n[e>>2]=i;n[e+4>>2]=n[s+4>>2];n[e+8>>2]=i;n[e+12>>2]=t;return}function iA(e){e=e|0;var t=0;t=(n[e+12>>2]|0)+20|0;n[t>>2]=(n[t>>2]|0)+(((n[e>>2]|0)-(n[e+8>>2]|0)|0)/44|0);return}function rA(e){e=e|0;var t=0,s=0,i=0;t=n[e>>2]|0;s=e+8|0;if((t|0)==(n[s>>2]|0)){i=s;t=n[i+4>>2]|0;s=e;n[s>>2]=n[i>>2];n[s+4>>2]=t}else{i=t+4|0;n[e>>2]=i;n[e+4>>2]=n[i>>2]}return e|0}function nA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+48|0;r=f+32|0;i=f+28|0;a=f+8|0;l=f+4|0;c=f;p=e+8|0;s=n[p>>2]|0;h=e+12|0;d=n[h>>2]|0;A=d;do{if((s|0)==(d|0)){d=e+4|0;u=n[d>>2]|0;g=n[e>>2]|0;o=g;if(u>>>0<=g>>>0){s=A-o|0;s=(s|0)==0?1:s>>1;oA(a,s,s>>>2,e+12|0);n[l>>2]=n[d>>2];n[c>>2]=n[p>>2];n[i>>2]=n[l>>2];n[r>>2]=n[c>>2];hA(a,i,r);s=n[e>>2]|0;n[e>>2]=n[a>>2];n[a>>2]=s;s=a+4|0;g=n[d>>2]|0;n[d>>2]=n[s>>2];n[s>>2]=g;s=a+8|0;g=n[p>>2]|0;n[p>>2]=n[s>>2];n[s>>2]=g;s=a+12|0;g=n[h>>2]|0;n[h>>2]=n[s>>2];n[s>>2]=g;cA(a);s=n[p>>2]|0;break}r=u;i=((r-o>>2)+1|0)/-2|0;e=u+(i<<2)|0;r=s-r|0;if(!r)s=e;else{um(e|0,u|0,r|0)|0;s=(n[d>>2]|0)+(i<<2)|0}g=e+(r>>2<<2)|0;n[p>>2]=g;n[d>>2]=s;s=g}}while(0);n[s>>2]=n[t>>2];n[p>>2]=(n[p>>2]|0)+4;J=f;return}function AA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+48|0;i=f+32|0;s=f+28|0;o=f+8|0;a=f+4|0;l=f;p=e+4|0;u=n[p>>2]|0;d=n[e>>2]|0;c=d;do{if((u|0)==(d|0)){d=e+8|0;h=n[d>>2]|0;A=e+12|0;g=n[A>>2]|0;r=g;if(h>>>0>=g>>>0){g=r-c|0;g=(g|0)==0?1:g>>1;oA(o,g,(g+3|0)>>>2,e+12|0);n[a>>2]=n[p>>2];n[l>>2]=n[d>>2];n[s>>2]=n[a>>2];n[i>>2]=n[l>>2];hA(o,s,i);s=n[e>>2]|0;n[e>>2]=n[o>>2];n[o>>2]=s;s=o+4|0;g=n[p>>2]|0;n[p>>2]=n[s>>2];n[s>>2]=g;s=o+8|0;g=n[d>>2]|0;n[d>>2]=n[s>>2];n[s>>2]=g;s=o+12|0;g=n[A>>2]|0;n[A>>2]=n[s>>2];n[s>>2]=g;cA(o);s=n[p>>2]|0;break}i=h;e=((r-i>>2)+1|0)/2|0;r=h+(e<<2)|0;i=i-u|0;s=r+(0-(i>>2)<<2)|0;if(!i){s=r;i=r}else{um(s|0,u|0,i|0)|0;i=(n[d>>2]|0)+(e<<2)|0}n[p>>2]=s;n[d>>2]=i}else s=u}while(0);n[s+-4>>2]=n[t>>2];n[p>>2]=(n[p>>2]|0)+-4;J=f;return}function oA(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>1073741823){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t<<2)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s<<2)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t<<2);return}function aA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+48|0;r=f+32|0;i=f+28|0;a=f+8|0;l=f+4|0;c=f;p=e+8|0;s=n[p>>2]|0;h=e+12|0;d=n[h>>2]|0;A=d;do{if((s|0)==(d|0)){d=e+4|0;u=n[d>>2]|0;g=n[e>>2]|0;o=g;if(u>>>0<=g>>>0){s=A-o|0;s=(s|0)==0?1:s>>1;oA(a,s,s>>>2,n[e+16>>2]|0);n[l>>2]=n[d>>2];n[c>>2]=n[p>>2];n[i>>2]=n[l>>2];n[r>>2]=n[c>>2];hA(a,i,r);s=n[e>>2]|0;n[e>>2]=n[a>>2];n[a>>2]=s;s=a+4|0;g=n[d>>2]|0;n[d>>2]=n[s>>2];n[s>>2]=g;s=a+8|0;g=n[p>>2]|0;n[p>>2]=n[s>>2];n[s>>2]=g;s=a+12|0;g=n[h>>2]|0;n[h>>2]=n[s>>2];n[s>>2]=g;cA(a);s=n[p>>2]|0;break}r=u;i=((r-o>>2)+1|0)/-2|0;e=u+(i<<2)|0;r=s-r|0;if(!r)s=e;else{um(e|0,u|0,r|0)|0;s=(n[d>>2]|0)+(i<<2)|0}g=e+(r>>2<<2)|0;n[p>>2]=g;n[d>>2]=s;s=g}}while(0);n[s>>2]=n[t>>2];n[p>>2]=(n[p>>2]|0)+4;J=f;return}function lA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+48|0;i=f+32|0;s=f+28|0;o=f+8|0;a=f+4|0;l=f;p=e+4|0;u=n[p>>2]|0;d=n[e>>2]|0;c=d;do{if((u|0)==(d|0)){d=e+8|0;h=n[d>>2]|0;A=e+12|0;g=n[A>>2]|0;r=g;if(h>>>0>=g>>>0){g=r-c|0;g=(g|0)==0?1:g>>1;oA(o,g,(g+3|0)>>>2,n[e+16>>2]|0);n[a>>2]=n[p>>2];n[l>>2]=n[d>>2];n[s>>2]=n[a>>2];n[i>>2]=n[l>>2];hA(o,s,i);s=n[e>>2]|0;n[e>>2]=n[o>>2];n[o>>2]=s;s=o+4|0;g=n[p>>2]|0;n[p>>2]=n[s>>2];n[s>>2]=g;s=o+8|0;g=n[d>>2]|0;n[d>>2]=n[s>>2];n[s>>2]=g;s=o+12|0;g=n[A>>2]|0;n[A>>2]=n[s>>2];n[s>>2]=g;cA(o);s=n[p>>2]|0;break}i=h;e=((r-i>>2)+1|0)/2|0;r=h+(e<<2)|0;i=i-u|0;s=r+(0-(i>>2)<<2)|0;if(!i){s=r;i=r}else{um(s|0,u|0,i|0)|0;i=(n[d>>2]|0)+(e<<2)|0}n[p>>2]=s;n[d>>2]=i}else s=u}while(0);n[s+-4>>2]=n[t>>2];n[p>>2]=(n[p>>2]|0)+-4;J=f;return}function cA(e){e=e|0;var t=0,s=0,i=0;t=n[e+4>>2]|0;s=e+8|0;i=n[s>>2]|0;if((i|0)!=(t|0))n[s>>2]=i+(~((i+-4-t|0)>>>2)<<2);t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function hA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;o=J;J=J+16|0;A=o;r=n[t>>2]|0;uA(A,e+8|0,(n[s>>2]|0)-r>>2);e=n[A>>2]|0;i=A+4|0;if((e|0)!=(n[i>>2]|0)){s=r;do{n[e>>2]=n[s>>2];e=(n[A>>2]|0)+4|0;n[A>>2]=e;s=s+4|0}while((e|0)!=(n[i>>2]|0));n[t>>2]=s}dA(A);J=o;return}function uA(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=n[t>>2];n[e+4>>2]=(n[t>>2]|0)+(s<<2);n[e+8>>2]=t;return}function dA(e){e=e|0;n[n[e+8>>2]>>2]=n[e>>2];return}function pA(e,t){e=e|0;t=t|0;return(n[e+4>>2]|0)==(n[t+4>>2]|0)|0}function fA(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;n[e+4>>2]=s;return}function gA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;A=n[t+4>>2]|0;s=n[t+16>>2]|0;i=(s>>>0)/93|0;r=A+(i<<2)|0;if((n[t+8>>2]|0)==(A|0))t=0;else t=(n[r>>2]|0)+((s-(i*93|0)|0)*44|0)|0;n[e>>2]=r;n[e+4>>2]=t;return}function mA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;s=(n[t+16>>2]|0)+(n[t+20>>2]|0)|0;A=n[t+4>>2]|0;i=(s>>>0)/93|0;r=A+(i<<2)|0;if((n[t+8>>2]|0)==(A|0))t=0;else t=(n[r>>2]|0)+((s-(i*93|0)|0)*44|0)|0;n[e>>2]=r;n[e+4>>2]=t;return}function _A(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0;a=J;J=J+16|0;i=a+8|0;A=a;bA(i,e);Jn(A,e);r=i+4|0;t=n[r>>2]|0;A=A+4|0;if((t|0)!=(n[A>>2]|0))do{Ms(t);t=(n[r>>2]|0)+44|0;n[r>>2]=t;s=n[i>>2]|0;if((t-(n[s>>2]|0)|0)==4092){t=s+4|0;n[i>>2]=t;t=n[t>>2]|0;n[r>>2]=t}}while((t|0)!=(n[A>>2]|0));n[e+20>>2]=0;r=e+8|0;i=e+4|0;s=n[i>>2]|0;t=(n[r>>2]|0)-s>>2;if(t>>>0>2)do{ye(n[s>>2]|0,4092);s=(n[i>>2]|0)+4|0;n[i>>2]=s;t=(n[r>>2]|0)-s>>2}while(t>>>0>2);switch(t|0){case 1:{t=46;o=11;break}case 2:{t=93;o=11;break}default:{}}if((o|0)==11)n[e+16>>2]=t;J=a;return}function bA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;A=n[t+4>>2]|0;s=n[t+16>>2]|0;i=(s>>>0)/93|0;r=A+(i<<2)|0;if((n[t+8>>2]|0)==(A|0))t=0;else t=(n[r>>2]|0)+((s-(i*93|0)|0)*44|0)|0;n[e>>2]=r;n[e+4>>2]=t;return}function yA(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,o=0,a=0,l=0,c=0,h=0,u=0;u=J;J=J+16|0;h=u;l=e+4|0;if(!(i[l>>0]|0)){h=yr(t)|0;Br(h,s,n[e>>2]|0);h=n[e>>2]|0;a=s+h|0;if(!h)r=0;else{r=s;o=n[e+8>>2]|0;while(1){i[o>>0]=i[r>>0]|0;r=r+1|0;if((r|0)==(a|0))break;else o=o+1|0}r=n[e>>2]|0}i[l>>0]=1;s=s+r|0}else{o=n[e+20>>2]|0;r=n[e+8>>2]|0;bA(h,e+32|0);e=e+12|0;if((r|0)!=(n[e>>2]|0)){c=h+4|0;l=r;a=o;r=n[c>>2]|0;while(1){o=A[l>>0]|0;o=BA((Ns(t,r)|0)+o|0)|0;i[a>>0]=o;i[s>>0]=o;i[l>>0]=o;l=l+1|0;s=s+1|0;o=n[h>>2]|0;r=(n[c>>2]|0)+44|0;n[c>>2]=r;if((r-(n[o>>2]|0)|0)==4092){r=o+4|0;n[h>>2]=r;r=n[r>>2]|0;n[c>>2]=r}if((l|0)==(n[e>>2]|0))break;else a=a+1|0}}}J=u;return s|0}function BA(e){e=e|0;return e&255|0}function wA(e){e=e|0;Ag(e);qp(e);return}function vA(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function CA(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==11262?e+12|0:0)|0}function MA(e){e=e|0;ye(e,16);return}function EA(e,t){e=e|0;t=t|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;if(t|0){Hn(e,t);xA(e,t)}return}function FA(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;n[e+20>>2]=0;if(t|0)UA(e,t,s);return}function xA(e,t){e=e|0;t=t|0;var s=0,r=0,A=0;A=J;J=J+16|0;r=A;zn(r,e,t);t=r+4|0;e=n[t>>2]|0;s=r+8|0;if((e|0)!=(n[s>>2]|0))do{i[e>>0]=0;e=(n[t>>2]|0)+1|0;n[t>>2]=e}while((e|0)!=(n[s>>2]|0));Wn(r);J=A;return}function UA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;p=J;J=J+96|0;d=p+80|0;c=p+64|0;o=p+48|0;a=p+40|0;l=p+8|0;r=p;h=p+32|0;u=p+16|0;i=(n[e+8>>2]|0)-(n[e+4>>2]|0)|0;i=((i|0)==0?0:((i>>2)*93|0)+-1|0)-((n[e+20>>2]|0)+(n[e+16>>2]|0))|0;if(i>>>0<t>>>0)Zn(e,t-i|0);Jn(a,e);Jn(r,e);i=n[r>>2]|0;r=n[r+4>>2]|0;A=l;n[A>>2]=i;n[A+4>>2]=r;A=i;if(t|0){i=((r-(n[i>>2]|0)|0)/44|0)+t|0;if((i|0)>0){t=(i>>>0)/93|0;A=A+(t<<2)|0;n[l>>2]=A;i=(n[A>>2]|0)+((i-(t*93|0)|0)*44|0)|0}else{i=92-i|0;t=A+(((i|0)/-93|0)<<2)|0;n[l>>2]=t;i=(n[t>>2]|0)+((92-((i|0)%93|0)|0)*44|0)|0}n[l+4>>2]=i}n[c>>2]=n[a>>2];n[c+4>>2]=n[a+4>>2];n[d>>2]=n[l>>2];n[d+4>>2]=n[l+4>>2];Yn(o,c,d);$n(d,o);qn(c,o);if(eA(d,c)|0){r=u+4|0;do{tA(h,d);sA(u,e,h);i=n[u>>2]|0;if((i|0)!=(n[r>>2]|0))do{Vs(i,s);i=(n[u>>2]|0)+44|0;n[u>>2]=i}while((i|0)!=(n[r>>2]|0));iA(u);rA(d)|0}while(eA(d,c)|0)}J=p;return}function IA(e){e=e|0;var t=0,s=0;_A(e);t=n[e+4>>2]|0;s=n[e+8>>2]|0;if((t|0)!=(s|0))do{ye(n[t>>2]|0,4092);t=t+4|0}while((t|0)!=(s|0));Kn(e);return}function TA(e,t,s){e=e|0;t=t|0;s=s|0;Ui(e);n[e>>2]=4924;n[e+4>>2]=t;n[e+8>>2]=s;return}function PA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4944;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;VA(e,i);J=s;return}function SA(e,t){e=e|0;t=t|0;return QA(n[e+8>>2]|0,n[e+4>>2]|0,t)|0}function DA(e){e=e|0;var t=0,s=0;n[e>>2]=4924;s=e+8|0;t=n[s>>2]|0;n[s>>2]=0;if(t|0){OA(t);qp(t)}Si(e);return}function kA(e){e=e|0;DA(e);qp(e);return}function QA(e,t,s){e=e|0;t=t|0;s=s|0;return RA(e+4784|0,t,_r(e,t,s)|0)|0}function RA(e,t,s){e=e|0;t=t|0;s=s|0;if(i[e>>0]|0){rs(t);i[e>>0]=0}return s|0}function OA(e){e=e|0;gr(e);return}function VA(e,t){e=e|0;t=t|0;return}function LA(e){e=e|0;Ag(e);qp(e);return}function HA(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function NA(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==12004?e+12|0:0)|0}function GA(e){e=e|0;ye(e,16);return}function jA(e){e=e|0;i[e>>0]=1;return}function zA(e,t,s){e=e|0;t=t|0;s=s|0;Ui(e);n[e>>2]=4972;n[e+4>>2]=t;n[e+8>>2]=s;return}function WA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4992;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;VA(e,i);J=s;return}function XA(e,t){e=e|0;t=t|0;return JA(n[e+8>>2]|0,n[e+4>>2]|0,t)|0}function KA(e){e=e|0;var t=0,s=0;n[e>>2]=4972;s=e+8|0;t=n[s>>2]|0;n[s>>2]=0;if(t|0){$A(t);qp(t)}Si(e);return}function ZA(e){e=e|0;KA(e);qp(e);return}function JA(e,t,s){e=e|0;t=t|0;s=s|0;return YA(e+4784|0,t,_r(e,t,s)|0)|0}function YA(e,t,s){e=e|0;t=t|0;s=s|0;return RA(e+328|0,t,on(e,t,s)|0)|0}function $A(e){e=e|0;qA(e+4784|0);gr(e);return}function qA(e){e=e|0;nn(e);return}function eo(e){e=e|0;Ag(e);qp(e);return}function to(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function so(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==12827?e+12|0:0)|0}function io(e){e=e|0;ye(e,16);return}function ro(e){e=e|0;Xr(e);jA(e+328|0);return}function no(e,t,s){e=e|0;t=t|0;s=s|0;Ui(e);n[e>>2]=5020;n[e+4>>2]=t;n[e+8>>2]=s;return}function Ao(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5040;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;VA(e,i);J=s;return}function oo(e,t){e=e|0;t=t|0;return co(n[e+8>>2]|0,n[e+4>>2]|0,t)|0}function ao(e){e=e|0;var t=0,s=0;n[e>>2]=5020;s=e+8|0;t=n[s>>2]|0;n[s>>2]=0;if(t|0){uo(t);qp(t)}Si(e);return}function lo(e){e=e|0;ao(e);qp(e);return}function co(e,t,s){e=e|0;t=t|0;s=s|0;return ho(e+4784|0,t,_r(e,t,s)|0)|0}function ho(e,t,s){e=e|0;t=t|0;s=s|0;return RA(e+316|0,t,Mn(e,t,s)|0)|0}function uo(e){e=e|0;po(e+4784|0);gr(e);return}function po(e){e=e|0;Cn(e);return}function fo(e){e=e|0;Ag(e);qp(e);return}function go(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function mo(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==13672?e+12|0:0)|0}function _o(e){e=e|0;ye(e,16);return}function bo(e){e=e|0;bn(e);jA(e+316|0);return}function yo(e,t,s){e=e|0;t=t|0;s=s|0;Ui(e);n[e>>2]=5068;n[e+4>>2]=t;n[e+8>>2]=s;return}function Bo(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5088;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;VA(e,i);J=s;return}function wo(e,t){e=e|0;t=t|0;return Mo(n[e+8>>2]|0,n[e+4>>2]|0,t)|0}function vo(e){e=e|0;var t=0,s=0;n[e>>2]=5068;s=e+8|0;t=n[s>>2]|0;n[s>>2]=0;if(t|0){Fo(t);qp(t)}Si(e);return}function Co(e){e=e|0;vo(e);qp(e);return}function Mo(e,t,s){e=e|0;t=t|0;s=s|0;return Eo(e+4784|0,t,_r(e,t,s)|0)|0}function Eo(e,t,s){e=e|0;t=t|0;s=s|0;return ho(e+328|0,t,on(e,t,s)|0)|0}function Fo(e){e=e|0;xo(e+4784|0);gr(e);return}function xo(e){e=e|0;po(e+328|0);nn(e);return}function Uo(e){e=e|0;Ag(e);qp(e);return}function Io(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function To(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==14573?e+12|0:0)|0}function Po(e){e=e|0;ye(e,16);return}function So(e){e=e|0;Xr(e);bo(e+328|0);return}function Do(e){e=e|0;return e+20|0}function ko(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;n[e+4>>2]=s;n[e+8>>2]=0;return}function Qo(e,t){e=e|0;t=t|0;n[e>>2]=t;n[e+4>>2]=0;n[e+8>>2]=-1;return}function Ro(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;s=J;J=J+16|0;i=s+4|0;A=s;r=Zf(24)|0;ea(r,t);n[A>>2]=0;n[i>>2]=n[A>>2];ta(e,r,i);J=s;return}function Oo(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Vo(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5116;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ho(e,i);J=s;return}function Lo(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Ho(e,t){e=e|0;t=t|0;return}function No(e){e=e|0;Ag(e);qp(e);return}function Go(e){e=e|0;e=n[e+12>>2]|0;if(e|0)qp(e);return}function jo(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==14966?e+12|0:0)|0}function zo(e){e=e|0;ye(e,16);return}function Wo(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5144;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ko(e,i);J=s;return}function Xo(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Ko(e,t){e=e|0;t=t|0;return}function Zo(e){e=e|0;Ag(e);qp(e);return}function Jo(e){e=e|0;e=n[e+12>>2]|0;if(e|0){qo(e);qp(e)}return}function Yo(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==15127?e+12|0:0)|0}function $o(e){e=e|0;ye(e,16);return}function qo(e){e=e|0;return}function ea(e,t){e=e|0;t=t|0;Ui(e);n[e>>2]=5172;n[e+4>>2]=t;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;i[e+20>>0]=1;return}function ta(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5192;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;oa(e,i);J=s;return}function sa(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0,a=0,l=0,c=0;c=J;J=J+16|0;o=c;s=n[e+8>>2]|0;a=n[e+12>>2]|0;if((s|0)!=(a|0)){l=o+4|0;do{r=n[s>>2]|0;n[o>>2]=r;A=n[s+4>>2]|0;n[l>>2]=A;if(A|0){A=A+4|0;n[A>>2]=(n[A>>2]|0)+1}t=Hm[n[(n[r>>2]|0)+12>>2]&63](r,t)|0;ki(o);s=s+8|0}while((s|0)!=(a|0))}s=e+20|0;if(i[s>>0]|0){i[s>>0]=0;na(n[e+4>>2]|0)}J=c;return t|0}function ia(e){e=e|0;n[e>>2]=5172;Qi(e+8|0);Si(e);return}function ra(e){e=e|0;ia(e);qp(e);return}function na(e){e=e|0;var t=0;t=((Aa(n[e>>2]|0)|0)&255)<<24;t=((Aa(n[e>>2]|0)|0)&255)<<16|t;t=t|((Aa(n[e>>2]|0)|0)&255)<<8;n[e+4>>2]=t|(Aa(n[e>>2]|0)|0)&255;return}function Aa(e){e=e|0;var t=0,s=0;t=n[e>>2]|0;s=e+8|0;e=n[s>>2]|0;n[s>>2]=e+1;return i[t+e>>0]|0}function oa(e,t){e=e|0;t=t|0;return}function aa(e){e=e|0;Ag(e);qp(e);return}function la(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function ca(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==15450?e+12|0:0)|0}function ha(e){e=e|0;ye(e,16);return}function ua(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(180)|0;pa(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];fa(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function da(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(180)|0;Oa(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];Va(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function pa(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5220;n[e+4>>2]=t;ga(e+8|0);return}function fa(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5244;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function ga(e){e=e|0;pr(e,32,1,8,0);is(e+80|0,32,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;ya(e+164|0);return}function ma(e){e=e|0;n[e>>2]=5220;Ba(e+8|0);sr(e);return}function _a(e){e=e|0;ma(e);qp(e);return}function ba(e,t){e=e|0;t=t|0;return wa(e+8|0,n[e+4>>2]|0,t)|0}function ya(e){e=e|0;i[e+4>>0]=0;return}function Ba(e){e=e|0;os(e+80|0);fr(e);return}function wa(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;o=J;J=J+16|0;r=o;if(!(i[e+161>>0]|0))ns(e+80|0);A=e+164|0;if(va(A)|0){t=Ca(e+80|0,t,n[A>>2]|0,0)|0;n[r>>2]=t;kr(t,s)}else{Ea(Ma(t)|0,s,4);n[r>>2]=Ir(s)|0}Fa(A,r);J=o;return s+4|0}function va(e){e=e|0;return(i[e+4>>0]|0)!=0|0}function Ca(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;s=(xa(e,t,(n[e+36>>2]|0)+(i*44|0)|0)|0)+s|0;t=n[e+24>>2]|0;if((s|0)<0)return s+t|0;else return s-(s>>>0<t>>>0?0:t)|0;return 0}function Ma(e){e=e|0;return n[e>>2]|0}function Ea(e,t,s){e=e|0;t=t|0;s=s|0;var r=0;if((s|0)>0){r=0;do{i[t+r>>0]=Aa(e)|0;r=r+1|0}while((r|0)!=(s|0))}return}function Fa(e,t){e=e|0;t=t|0;var s=0;s=e+4|0;if(!(i[s>>0]|0))i[s>>0]=1;n[e>>2]=n[t>>2];return}function xa(e,t,s){e=e|0;t=t|0;s=s|0;var i=0;s=Ua(t,s)|0;n[e>>2]=s;do{if(s){if(s>>>0>=32){s=n[e+28>>2]|0;break}i=n[e+12>>2]|0;if(s>>>0>i>>>0){i=s-i|0;s=Ua(t,(n[e+68>>2]|0)+((s+-1|0)*44|0)|0)|0;i=s<<i|(Ia(t,i)|0)}else i=Ua(t,(n[e+68>>2]|0)+((s+-1|0)*44|0)|0)|0;s=n[e>>2]|0;if((i|0)<(1<<s+-1|0)){s=i+1+(-1<<s)|0;break}else{s=i+1|0;break}}else s=Ta(t,e+48|0)|0}while(0);return s|0}function Ua(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;d=e+8|0;u=n[d>>2]|0;r=n[t+16>>2]|0;if(r){i=e+4|0;s=n[i>>2]|0;h=u>>>15;n[d>>2]=h;l=(s>>>0)/(h>>>0)|0;a=l>>>(n[t+40>>2]|0);A=n[r+(a<<2)>>2]|0;a=(n[r+(a+1<<2)>>2]|0)+1|0;o=A+1|0;c=n[t+8>>2]|0;if(a>>>0>o>>>0){r=A;A=a;do{o=(A+r|0)>>>1;a=(n[c+(o<<2)>>2]|0)>>>0>l>>>0;r=a?r:o;A=a?o:A;o=r+1|0}while(A>>>0>o>>>0);A=r}r=b(n[c+(A<<2)>>2]|0,h)|0;if((A|0)==(n[t+32>>2]|0))o=u;else o=b(n[c+(o<<2)>>2]|0,h)|0}else{c=u>>>15;n[d>>2]=c;a=n[t>>2]|0;h=n[t+8>>2]|0;i=e+4|0;s=n[i>>2]|0;l=a>>>1;r=0;o=u;A=0;do{p=b(n[h+(l<<2)>>2]|0,c)|0;u=p>>>0>s>>>0;o=u?p:o;r=u?r:p;A=u?A:l;a=u?l:a;l=(A+a|0)>>>1}while((l|0)!=(A|0))}n[i>>2]=s-r;p=o-r|0;n[d>>2]=p;if(p>>>0<16777216)Pa(e);d=(n[t+12>>2]|0)+(A<<2)|0;n[d>>2]=(n[d>>2]|0)+1;d=t+28|0;p=(n[d>>2]|0)+-1|0;n[d>>2]=p;if(!p)Ls(t);return A|0}function Ia(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;if(t>>>0>19){s=(Sa(e)|0)&65535;return(Ia(e,t+-16|0)|0)<<16|s|0}i=e+4|0;r=n[i>>2]|0;A=e+8|0;s=(n[A>>2]|0)>>>t;n[A>>2]=s;t=(r>>>0)/(s>>>0)|0;n[i>>2]=r-(b(t,s)|0);if(s>>>0<16777216)Pa(e);return t|0}function Ta(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0;i=e+8|0;r=n[i>>2]|0;s=b(r>>>13,n[t+8>>2]|0)|0;A=e+4|0;o=n[A>>2]|0;a=o>>>0>=s>>>0;if(a){n[A>>2]=o-s;s=r-s|0;n[i>>2]=s}else{n[i>>2]=s;o=t+12|0;n[o>>2]=(n[o>>2]|0)+1}if(s>>>0<16777216)Pa(e);o=t+4|0;e=(n[o>>2]|0)+-1|0;n[o>>2]=e;if(!e)Xs(t);return a&1|0}function Pa(e){e=e|0;var t=0,s=0,i=0,r=0;t=e+4|0;s=e+8|0;i=n[t>>2]|0;do{i=i<<8|(Aa(n[e>>2]|0)|0)&255;n[t>>2]=i;r=n[s>>2]<<8;n[s>>2]=r}while(r>>>0<16777216);return}function Sa(e){e=e|0;var t=0,s=0,i=0,r=0;s=e+4|0;r=n[s>>2]|0;t=e+8|0;i=(n[t>>2]|0)>>>16;n[t>>2]=i;t=(r>>>0)/(i>>>0)|0;n[s>>2]=r-(b(t,i)|0);Pa(e);return t&65535|0}function Da(e){e=e|0;Ag(e);qp(e);return}function ka(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Qa(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==15904?e+12|0:0)|0}function Ra(e){e=e|0;ye(e,16);return}function Oa(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5272;n[e+4>>2]=t;La(e+8|0);return}function Va(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5296;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function La(e){e=e|0;pr(e,32,1,8,0);is(e+80|0,32,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;ja(e+164|0);return}function Ha(e){e=e|0;n[e>>2]=5272;za(e+8|0);sr(e);return}function Na(e){e=e|0;Ha(e);qp(e);return}function Ga(e,t){e=e|0;t=t|0;return Wa(e+8|0,n[e+4>>2]|0,t)|0}function ja(e){e=e|0;i[e+4>>0]=0;return}function za(e){e=e|0;os(e+80|0);fr(e);return}function Wa(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;o=J;J=J+16|0;r=o;if(!(i[e+161>>0]|0))ns(e+80|0);A=e+164|0;if(Xa(A)|0){t=Ca(e+80|0,t,n[A>>2]|0,0)|0;n[r>>2]=t;Vr(t,s)}else{Ea(Ma(t)|0,s,4);n[r>>2]=Dr(s)|0}Ka(A,r);J=o;return s+4|0}function Xa(e){e=e|0;return(i[e+4>>0]|0)!=0|0}function Ka(e,t){e=e|0;t=t|0;var s=0;s=e+4|0;if(!(i[s>>0]|0))i[s>>0]=1;n[e>>2]=n[t>>2];return}function Za(e){e=e|0;Ag(e);qp(e);return}function Ja(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Ya(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==16402?e+12|0:0)|0}function $a(e){e=e|0;ye(e,16);return}function qa(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(172)|0;tl(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];sl(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function el(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(176)|0;_l(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];bl(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function tl(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5324;n[e+4>>2]=t;il(e+8|0);return}function sl(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5348;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function il(e){e=e|0;pr(e,8,1,8,0);is(e+80|0,8,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;ol(e+162|0);return}function rl(e){e=e|0;n[e>>2]=5324;al(e+8|0);sr(e);return}function nl(e){e=e|0;rl(e);qp(e);return}function Al(e,t){e=e|0;t=t|0;return ll(e+8|0,n[e+4>>2]|0,t)|0}function ol(e){e=e|0;i[e+1>>0]=0;return}function al(e){e=e|0;os(e+80|0);fr(e);return}function ll(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,n=0,A=0;A=J;J=J+16|0;r=A;if(!(i[e+161>>0]|0))ns(e+80|0);n=e+162|0;if(cl(n)|0){t=(Ca(e+80|0,t,i[n>>0]|0,0)|0)&255;i[r>>0]=t;hl(t,s)}else{Ea(Ma(t)|0,s,1);i[r>>0]=ul(s)|0}dl(n,r);J=A;return s+1|0}function cl(e){e=e|0;return(i[e+1>>0]|0)!=0|0}function hl(e,t){e=e|0;t=t|0;i[t>>0]=e;return}function ul(e){e=e|0;return i[e>>0]|0}function dl(e,t){e=e|0;t=t|0;var s=0;s=e+1|0;if(!(i[s>>0]|0))i[s>>0]=1;i[e>>0]=i[t>>0]|0;return}function pl(e){e=e|0;Ag(e);qp(e);return}function fl(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function gl(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==16900?e+12|0:0)|0}function ml(e){e=e|0;ye(e,16);return}function _l(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5376;n[e+4>>2]=t;yl(e+8|0);return}function bl(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5400;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function yl(e){e=e|0;pr(e,16,1,8,0);is(e+80|0,16,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;Cl(e+162|0);return}function Bl(e){e=e|0;n[e>>2]=5376;Ml(e+8|0);sr(e);return}function wl(e){e=e|0;Bl(e);qp(e);return}function vl(e,t){e=e|0;t=t|0;return El(e+8|0,n[e+4>>2]|0,t)|0}function Cl(e){e=e|0;i[e+2>>0]=0;return}function Ml(e){e=e|0;os(e+80|0);fr(e);return}function El(e,t,s){e=e|0;t=t|0;s=s|0;var n=0,A=0,o=0;o=J;J=J+16|0;n=o;if(!(i[e+161>>0]|0))ns(e+80|0);A=e+162|0;if(Fl(A)|0){t=(Ca(e+80|0,t,r[A>>1]|0,0)|0)&65535;r[n>>1]=t;xl(t,s)}else{Ea(Ma(t)|0,s,2);r[n>>1]=Ul(s)|0}Il(A,n);J=o;return s+2|0}function Fl(e){e=e|0;return(i[e+2>>0]|0)!=0|0}function xl(e,t){e=e|0;t=t|0;Qr(e,t);return}function Ul(e){e=e|0;return Tr(e)|0}function Il(e,t){e=e|0;t=t|0;var s=0;s=e+2|0;if(!(i[s>>0]|0))i[s>>0]=1;r[e>>1]=r[t>>1]|0;return}function Tl(e){e=e|0;Ag(e);qp(e);return}function Pl(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Sl(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==17398?e+12|0:0)|0}function Dl(e){e=e|0;ye(e,16);return}function kl(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(172)|0;Rl(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];Ol(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function Ql(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(176)|0;$l(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];ql(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function Rl(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5428;n[e+4>>2]=t;Vl(e+8|0);return}function Ol(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5452;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function Vl(e){e=e|0;pr(e,8,1,8,0);is(e+80|0,8,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;Gl(e+162|0);return}function Ll(e){e=e|0;n[e>>2]=5428;jl(e+8|0);sr(e);return}function Hl(e){e=e|0;Ll(e);qp(e);return}function Nl(e,t){e=e|0;t=t|0;return zl(e+8|0,n[e+4>>2]|0,t)|0}function Gl(e){e=e|0;i[e+1>>0]=0;return}function jl(e){e=e|0;os(e+80|0);fr(e);return}function zl(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,n=0,o=0;o=J;J=J+16|0;r=o;if(!(i[e+161>>0]|0))ns(e+80|0);n=e+162|0;if(Wl(n)|0){t=(Ca(e+80|0,t,A[n>>0]|0,0)|0)&255;i[r>>0]=t;Rr(t,s)}else{Ea(Ma(t)|0,s,1);i[r>>0]=Pr(s)|0}Xl(n,r);J=o;return s+1|0}function Wl(e){e=e|0;return(i[e+1>>0]|0)!=0|0}function Xl(e,t){e=e|0;t=t|0;var s=0;s=e+1|0;if(!(i[s>>0]|0))i[s>>0]=1;i[e>>0]=i[t>>0]|0;return}function Kl(e){e=e|0;Ag(e);qp(e);return}function Zl(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Jl(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==17896?e+12|0:0)|0}function Yl(e){e=e|0;ye(e,16);return}function $l(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5480;n[e+4>>2]=t;ec(e+8|0);return}function ql(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5504;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function ec(e){e=e|0;pr(e,16,1,8,0);is(e+80|0,16,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;rc(e+162|0);return}function tc(e){e=e|0;n[e>>2]=5480;nc(e+8|0);sr(e);return}function sc(e){e=e|0;tc(e);qp(e);return}function ic(e,t){e=e|0;t=t|0;return Ac(e+8|0,n[e+4>>2]|0,t)|0}function rc(e){e=e|0;i[e+2>>0]=0;return}function nc(e){e=e|0;os(e+80|0);fr(e);return}function Ac(e,t,s){e=e|0;t=t|0;s=s|0;var n=0,A=0,a=0;a=J;J=J+16|0;n=a;if(!(i[e+161>>0]|0))ns(e+80|0);A=e+162|0;if(oc(A)|0){t=(Ca(e+80|0,t,o[A>>1]|0,0)|0)&65535;r[n>>1]=t;Qr(t,s)}else{Ea(Ma(t)|0,s,2);r[n>>1]=Tr(s)|0}ac(A,n);J=a;return s+2|0}function oc(e){e=e|0;return(i[e+2>>0]|0)!=0|0}function ac(e,t){e=e|0;t=t|0;var s=0;s=e+2|0;if(!(i[s>>0]|0))i[s>>0]=1;r[e>>1]=r[t>>1]|0;return}function lc(e){e=e|0;Ag(e);qp(e);return}function cc(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function hc(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==18394?e+12|0:0)|0}function uc(e){e=e|0;ye(e,16);return}function dc(){return}function pc(e){e=e|0;return wc(e)|0}function fc(){return 0}function gc(){return 0}function mc(e){e=e|0;if(e|0){vc(e);qp(e)}return}function _c(){return Cc()|0}function bc(){return Mc()|0}function yc(){return Ec()|0}function Bc(){return 0}function wc(e){e=e|0;return 3360}function vc(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;i=t;n[i>>2]=n[e>>2];n[e>>2]=0;s=e+4|0;n[i+4>>2]=n[s>>2];n[s>>2]=0;de(i);s=e+8|0;n[i>>2]=n[s>>2];n[s>>2]=0;r=e+12|0;n[i+4>>2]=n[r>>2];n[r>>2]=0;ve(i);ve(s);de(e);J=t;return}function Cc(){return 3360}function Mc(){return 3368}function Ec(){return 3384}function Fc(){return 18579}function xc(){return 18582}function Uc(){return 18584}function Ic(){var e=0;e=Zf(16)|0;Rc(e);return e|0}function Tc(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;s=t;r=_c()|0;i=Sc(s)|0;s=Dc(s)|0;S(r|0,i|0,s|0,Fc()|0,12,e|0);J=t;return}function Pc(e){e=e|0;return kc(Om[e&3]()|0)|0}function Sc(e){e=e|0;return 1}function Dc(e){e=e|0;return Qc()|0}function kc(e){e=e|0;return e|0}function Qc(){return 5524}function Rc(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;return}function Oc(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=_c()|0;A=Lc(r)|0;r=Hc(r)|0;t=Xc()|0;D(o|0,e|0,A|0,r|0,t|0,4,Nc(i)|0,0);J=s;return}function Vc(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;A=Gc(t)|0;t=n[e>>2]|0;r=n[e+4>>2]|0;e=A+(r>>1)|0;if(r&1)t=n[(n[e>>2]|0)+t>>2]|0;r=jc(s)|0;A=zc(i)|0;Wm[t&15](e,r,A);return}function Lc(e){e=e|0;return 4}function Hc(e){e=e|0;return Wc()|0}function Nc(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function Gc(e){e=e|0;return e|0}function jc(e){e=e|0;return e|0}function zc(e){e=e|0;return e|0}function Wc(){return 144}function Xc(){return 18587}function Kc(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=_c()|0;A=Jc(r)|0;r=Yc(r)|0;t=th()|0;D(o|0,e|0,A|0,r|0,t|0,7,$c(i)|0,0);J=s;return}function Zc(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=Gc(t)|0;t=n[e>>2]|0;i=n[e+4>>2]|0;e=r+(i>>1)|0;if(i&1)t=n[(n[e>>2]|0)+t>>2]|0;r=qc(s)|0;zm[t&15](e,r);return}function Jc(e){e=e|0;return 3}function Yc(e){e=e|0;return eh()|0}function $c(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function qc(e){e=e|0;return e|0}function eh(){return 5528}function th(){return 18593}function sh(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=_c()|0;A=rh(r)|0;r=nh(r)|0;t=lh()|0;D(o|0,e|0,A|0,r|0,t|0,41,Ah(i)|0,0);J=s;return}function ih(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;i=J;J=J+16|0;s=i;A=Gc(t)|0;t=n[e>>2]|0;r=n[e+4>>2]|0;e=A+(r>>1)|0;if(r&1)t=n[(n[e>>2]|0)+t>>2]|0;n[s>>2]=Vm[t&15](e)|0;A=oh(s)|0;J=i;return A|0}function rh(e){e=e|0;return 2}function nh(e){e=e|0;return ah()|0}function Ah(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function oh(e){e=e|0;return n[e>>2]|0}function ah(){return 5540}function lh(){return 18598}function ch(){return}function hh(e){e=e|0;return _h(e)|0}function uh(){return 0}function dh(){return 0}function ph(e){e=e|0;if(e|0){bh(e);qp(e)}return}function fh(){return yh()|0}function gh(){return Bh()|0}function mh(){return wh()|0}function _h(e){e=e|0;return 3400}function bh(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;i=t;n[i>>2]=n[e>>2];n[e>>2]=0;s=e+4|0;n[i+4>>2]=n[s>>2];n[s>>2]=0;Lo(i);s=e+16|0;n[i>>2]=n[s>>2];n[s>>2]=0;r=e+20|0;n[i+4>>2]=n[r>>2];n[r>>2]=0;Oo(i);n[i>>2]=n[s>>2];n[s>>2]=0;n[i+4>>2]=n[r>>2];n[r>>2]=0;Oo(i);Oo(s);Xo(e+8|0);Lo(e);J=t;return}function yh(){return 3400}function Bh(){return 3408}function wh(){return 3424}function vh(){var e=0;e=Zf(24)|0;Ih(e);return e|0}function Ch(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;s=t;r=fh()|0;i=Eh(s)|0;s=Fh(s)|0;S(r|0,i|0,s|0,Fc()|0,13,e|0);J=t;return}function Mh(e){e=e|0;return xh(Om[e&3]()|0)|0}function Eh(e){e=e|0;return 1}function Fh(e){e=e|0;return Uh()|0}function xh(e){e=e|0;return e|0}function Uh(){return 5548}function Ih(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;n[e+20>>2]=0;return}function Th(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=fh()|0;A=Sh(r)|0;r=Dh(r)|0;t=Xc()|0;D(o|0,e|0,A|0,r|0,t|0,5,kh(i)|0,0);J=s;return}function Ph(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;A=Qh(t)|0;t=n[e>>2]|0;r=n[e+4>>2]|0;e=A+(r>>1)|0;if(r&1)t=n[(n[e>>2]|0)+t>>2]|0;r=jc(s)|0;A=zc(i)|0;Wm[t&15](e,r,A);return}function Sh(e){e=e|0;return 4}function Dh(e){e=e|0;return Rh()|0}function kh(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function Qh(e){e=e|0;return e|0}function Rh(){return 160}function Oh(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=fh()|0;A=Lh(r)|0;r=Hh(r)|0;t=th()|0;D(o|0,e|0,A|0,r|0,t|0,8,Nh(i)|0,0);J=s;return}function Vh(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=Qh(t)|0;t=n[e>>2]|0;i=n[e+4>>2]|0;e=r+(i>>1)|0;if(i&1)t=n[(n[e>>2]|0)+t>>2]|0;r=zc(s)|0;zm[t&15](e,r);return}function Lh(e){e=e|0;return 3}function Hh(e){e=e|0;return Gh()|0}function Nh(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function Gh(){return 5552}function jh(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=fh()|0;A=Wh(r)|0;r=Xh(r)|0;t=th()|0;D(o|0,e|0,A|0,r|0,t|0,9,Kh(i)|0,0);J=s;return}function zh(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=Qh(t)|0;t=n[e>>2]|0;i=n[e+4>>2]|0;e=r+(i>>1)|0;if(i&1)t=n[(n[e>>2]|0)+t>>2]|0;r=qc(s)|0;zm[t&15](e,r);return}function Wh(e){e=e|0;return 3}function Xh(e){e=e|0;return Zh()|0}function Kh(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function Zh(){return 5564}function Jh(){ee();return}function Yh(){$h();return}function $h(){qh(22144);return}function qh(e){e=e|0;var t=0;t=J;J=J+16|0;n[t>>2]=e;eu();J=t;return}function eu(){H(tu()|0,18653);T(su()|0,18658,1,1,0);iu(18663);ru(18668);nu(18680);Au(18694);ou(18700);au(18715);lu(18719);cu(18732);hu(18737);uu(18751);du(18757);V(pu()|0,18764);V(fu()|0,18776);L(gu()|0,4,18809);L(mu()|0,2,18822);L(_u()|0,4,18837);k(bu()|0,18852);yu(18868);Bu(18898);wu(18935);vu(18974);Cu(19005);Mu(19045);Eu(19074);Fu(19112);xu(19142);Bu(19181);wu(19213);vu(19246);Cu(19279);Mu(19313);Eu(19346);Uu(19380);Iu(19411);Tu(19443);return}function tu(){return Gd()|0}function su(){return Nd()|0}function iu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Ld()|0;R(e|0,n[s>>2]|0,1,-128<<24>>24|0,127<<24>>24|0);J=t;return}function ru(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Od()|0;R(e|0,n[s>>2]|0,1,-128<<24>>24|0,127<<24>>24|0);J=t;return}function nu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Qd()|0;R(e|0,n[s>>2]|0,1,0,255);J=t;return}function Au(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Dd()|0;R(e|0,n[s>>2]|0,2,-32768<<16>>16|0,32767<<16>>16|0);J=t;return}function ou(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Pd()|0;R(e|0,n[s>>2]|0,2,0,65535);J=t;return}function au(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Id()|0;R(e|0,n[s>>2]|0,4,-2147483648,2147483647);J=t;return}function lu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=xd()|0;R(e|0,n[s>>2]|0,4,0,-1);J=t;return}function cu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Ed()|0;R(e|0,n[s>>2]|0,4,-2147483648,2147483647);J=t;return}function hu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Cd()|0;R(e|0,n[s>>2]|0,4,0,-1);J=t;return}function uu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=wd()|0;Q(e|0,n[s>>2]|0,4);J=t;return}function du(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=yd()|0;Q(e|0,n[s>>2]|0,8);J=t;return}function pu(){return bd()|0}function fu(){return _d()|0}function gu(){return md()|0}function mu(){return gd()|0}function _u(){return fd()|0}function bu(){return pd()|0}function yu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=hd()|0;e=ud()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Bu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=ad()|0;e=ld()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function wu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=nd()|0;e=Ad()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function vu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=sd()|0;e=id()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Cu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=qu()|0;e=ed()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Mu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Ju()|0;e=Yu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Eu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Xu()|0;e=Ku()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Fu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=ju()|0;e=zu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function xu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Hu()|0;e=Nu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Uu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Ou()|0;e=Vu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Iu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=ku()|0;e=Qu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Tu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Pu()|0;e=Su()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Pu(){return Du()|0}function Su(){return 7}function Du(){return 3440}function ku(){return Ru()|0}function Qu(){return 7}function Ru(){return 3448}function Ou(){return Lu()|0}function Vu(){return 6}function Lu(){return 3456}function Hu(){return Gu()|0}function Nu(){return 5}function Gu(){return 3464}function ju(){return Wu()|0}function zu(){return 4}function Wu(){return 3472}function Xu(){return Zu()|0}function Ku(){return 5}function Zu(){return 3480}function Ju(){return $u()|0}function Yu(){return 4}function $u(){return 3488}function qu(){return td()|0}function ed(){return 3}function td(){return 3496}function sd(){return rd()|0}function id(){return 2}function rd(){return 3504}function nd(){return od()|0}function Ad(){return 1}function od(){return 3512}function ad(){return cd()|0}function ld(){return 0}function cd(){return 3520}function hd(){return dd()|0}function ud(){return 0}function dd(){return 3528}function pd(){return 3536}function fd(){return 3544}function gd(){return 3576}function md(){return 3600}function _d(){return 3624}function bd(){return 3648}function yd(){return Bd()|0}function Bd(){return 4144}function wd(){return vd()|0}function vd(){return 4136}function Cd(){return Md()|0}function Md(){return 4128}function Ed(){return Fd()|0}function Fd(){return 4120}function xd(){return Ud()|0}function Ud(){return 4112}function Id(){return Td()|0}function Td(){return 4104}function Pd(){return Sd()|0}function Sd(){return 4096}function Dd(){return kd()|0}function kd(){return 4088}function Qd(){return Rd()|0}function Rd(){return 4072}function Od(){return Vd()|0}function Vd(){return 4080}function Ld(){return Hd()|0}function Hd(){return 4064}function Nd(){return 4056}function Gd(){return 4040}function jd(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;s=t+8|0;i=t+4|0;r=t;n[r>>2]=e;n[i>>2]=n[r>>2];n[s>>2]=n[(n[i>>2]|0)+4>>2];e=Mp(n[s>>2]|0)|0;J=t;return e|0}function zd(){return 21636}function Wd(e){e=e|0;return(e+-48|0)>>>0<10|0}function Xd(){return 5576}function Kd(e,t){e=e|0;t=t|0;var s=0,r=0;s=i[e>>0]|0;r=i[t>>0]|0;if(s<<24>>24==0?1:s<<24>>24!=r<<24>>24)e=r;else{do{e=e+1|0;t=t+1|0;s=i[e>>0]|0;r=i[t>>0]|0}while(!(s<<24>>24==0?1:s<<24>>24!=r<<24>>24));e=r}return(s&255)-(e&255)|0}function Zd(e){e=e|0;var t=0,s=0,r=0;r=e;e:do{if(!(r&3))s=5;else{t=r;while(1){if(!(i[e>>0]|0)){e=t;break e}e=e+1|0;t=e;if(!(t&3)){s=5;break}}}}while(0);if((s|0)==5){while(1){t=n[e>>2]|0;if(!((t&-2139062144^-2139062144)&t+-16843009))e=e+4|0;else break}if((t&255)<<24>>24)do{e=e+1|0}while((i[e>>0]|0)!=0)}return e-r|0}function Jd(e){e=e|0;return}function Yd(e){e=e|0;return 1}function $d(e){e=e|0;var t=0,s=0;t=e+74|0;s=i[t>>0]|0;i[t>>0]=s+255|s;t=n[e>>2]|0;if(!(t&8)){n[e+8>>2]=0;n[e+4>>2]=0;s=n[e+44>>2]|0;n[e+28>>2]=s;n[e+20>>2]=s;n[e+16>>2]=s+(n[e+48>>2]|0);e=0}else{n[e>>2]=t|32;e=-1}return e|0}function qd(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0;r=s+16|0;A=n[r>>2]|0;if(!A)if(!($d(s)|0)){A=n[r>>2]|0;o=5}else r=0;else o=5;e:do{if((o|0)==5){l=s+20|0;a=n[l>>2]|0;r=a;if((A-a|0)>>>0<t>>>0){r=Nm[n[s+36>>2]&7](s,e,t)|0;break}t:do{if((i[s+75>>0]|0)<0|(t|0)==0){o=0;A=e}else{a=t;while(1){A=a+-1|0;if((i[e+A>>0]|0)==10)break;if(!A){o=0;A=e;break t}else a=A}r=Nm[n[s+36>>2]&7](s,e,a)|0;if(r>>>0<a>>>0)break e;o=a;A=e+a|0;t=t-a|0;r=n[l>>2]|0}}while(0);hm(r|0,A|0,t|0)|0;n[l>>2]=(n[l>>2]|0)+t;r=o+t|0}}while(0);return r|0}function ep(e,t){e=e|0;t=t|0;if(!t)t=0;else t=tp(n[t>>2]|0,n[t+4>>2]|0,e)|0;return((t|0)==0?e:t)|0}function tp(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;p=(n[e>>2]|0)+1794895138|0;o=sp(n[e+8>>2]|0,p)|0;r=sp(n[e+12>>2]|0,p)|0;A=sp(n[e+16>>2]|0,p)|0;e:do{if((o>>>0<t>>>2>>>0?(d=t-(o<<2)|0,r>>>0<d>>>0&A>>>0<d>>>0):0)?((A|r)&3|0)==0:0){d=r>>>2;u=A>>>2;h=0;while(1){l=o>>>1;c=h+l|0;a=c<<1;A=a+d|0;r=sp(n[e+(A<<2)>>2]|0,p)|0;A=sp(n[e+(A+1<<2)>>2]|0,p)|0;if(!(A>>>0<t>>>0&r>>>0<(t-A|0)>>>0)){r=0;break e}if(i[e+(A+r)>>0]|0){r=0;break e}r=Kd(s,e+A|0)|0;if(!r)break;r=(r|0)<0;if((o|0)==1){r=0;break e}h=r?h:c;o=r?l:o-l|0}r=a+u|0;A=sp(n[e+(r<<2)>>2]|0,p)|0;r=sp(n[e+(r+1<<2)>>2]|0,p)|0;if(r>>>0<t>>>0&A>>>0<(t-r|0)>>>0)r=(i[e+(r+A)>>0]|0)==0?e+r|0:0;else r=0}else r=0}while(0);return r|0}function sp(e,t){e=e|0;t=t|0;var s=0;s=cm(e|0)|0;return((t|0)==0?e:s)|0}function ip(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;o=t&255;r=(s|0)!=0;e:do{if(r&(e&3|0)!=0){A=t&255;while(1){if((i[e>>0]|0)==A<<24>>24){A=6;break e}e=e+1|0;s=s+-1|0;r=(s|0)!=0;if(!(r&(e&3|0)!=0)){A=5;break}}}else A=5}while(0);if((A|0)==5)if(r)A=6;else e=0;e:do{if((A|0)==6){if((i[e>>0]|0)!=(t&255)<<24>>24){r=b(o,16843009)|0;t:do{if(s>>>0>3)do{o=n[e>>2]^r;if((o&-2139062144^-2139062144)&o+-16843009|0)break t;e=e+4|0;s=s+-4|0}while(s>>>0>3)}while(0)}if(!s)e=0;else{r=t&255;while(1){if((i[e>>0]|0)==r<<24>>24)break e;s=s+-1|0;if(!s){e=0;break}else e=e+1|0}}}}while(0);return e|0}function rp(e,t,s){e=e|0;t=t|0;s=s|0;return op(e,t,s,1,8)|0}function np(e,t,s,r,o,a){e=e|0;t=+t;s=s|0;r=r|0;o=o|0;a=a|0;var l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0.0,m=0,_=0,y=0,B=0,w=0,C=0,M=0,E=0,F=0,x=0,U=0,I=0,T=0,P=0,S=0;S=J;J=J+560|0;h=S+32|0;B=S+536|0;P=S;T=P;u=S+540|0;n[B>>2]=0;I=u+12|0;bp(t)|0;l=v()|0;if((l|0)<0){t=-t;bp(t)|0;U=1;x=20247;l=v()|0}else{U=(o&2049|0)!=0&1;x=(o&2048|0)==0?(o&1|0)==0?20248:20253:20250}do{if(0==0&(l&2146435072|0)==2146435072){P=(a&32|0)!=0;l=U+3|0;fp(e,32,s,l,o&-65537);lp(e,x,U);lp(e,t!=t|0.0!=0.0?P?20274:20278:P?20266:20270,3);fp(e,32,s,l,o^8192)}else{g=+yp(t,B)*2.0;l=g!=0.0;if(l)n[B>>2]=(n[B>>2]|0)+-1;y=a|32;if((y|0)==97){p=a&32;m=(p|0)==0?x:x+9|0;f=U|2;l=12-r|0;do{if(!(r>>>0>11|(l|0)==0)){t=8.0;do{l=l+-1|0;t=t*16.0}while((l|0)!=0);if((i[m>>0]|0)==45){t=-(t+(-g-t));break}else{t=g+t-t;break}}else t=g}while(0);c=n[B>>2]|0;l=(c|0)<0?0-c|0:c;l=pp(l,((l|0)<0)<<31>>31,I)|0;if((l|0)==(I|0)){l=u+11|0;i[l>>0]=48}i[l+-1>>0]=(c>>31&2)+43;d=l+-2|0;i[d>>0]=a+15;c=(r|0)<1;h=(o&8|0)==0;u=P;do{U=~~t;l=u+1|0;i[u>>0]=p|A[640+U>>0];t=(t-+(U|0))*16.0;if((l-T|0)==1?!(h&(c&t==0.0)):0){i[l>>0]=46;u=u+2|0}else u=l}while(t!=0.0);if((r|0)!=0?(-2-T+u|0)<(r|0):0){c=I;h=d;l=r+2+c-h|0}else{c=I;h=d;l=c-T-h+u|0}I=l+f|0;fp(e,32,s,I,o);lp(e,m,f);fp(e,48,s,I,o^65536);T=u-T|0;lp(e,P,T);P=c-h|0;fp(e,48,l-(T+P)|0,0,0);lp(e,d,P);fp(e,32,s,I,o^8192);l=I;break}c=(r|0)<0?6:r;if(l){l=(n[B>>2]|0)+-28|0;n[B>>2]=l;t=g*268435456.0}else{t=g;l=n[B>>2]|0}F=(l|0)<0?h:h+288|0;h=F;do{M=~~t>>>0;n[h>>2]=M;h=h+4|0;t=(t-+(M>>>0))*1.0e9}while(t!=0.0);M=F;if((l|0)>0){p=F;while(1){d=(l|0)<29?l:29;l=h+-4|0;if(l>>>0>=p>>>0){u=0;do{_=am(n[l>>2]|0,0,d|0)|0;_=sm(_|0,v()|0,u|0,0)|0;w=v()|0;u=Am(_|0,w|0,1e9,0)|0;C=tm(u|0,v()|0,1e9,0)|0;C=im(_|0,w|0,C|0,v()|0)|0;v()|0;n[l>>2]=C;l=l+-4|0}while(l>>>0>=p>>>0);if(u){C=p+-4|0;n[C>>2]=u;u=C}else u=p}else u=p;e:do{if(h>>>0>u>>>0){l=h;while(1){h=l+-4|0;if(n[h>>2]|0){h=l;break e}if(h>>>0>u>>>0)l=h;else break}}}while(0);l=(n[B>>2]|0)-d|0;n[B>>2]=l;if((l|0)>0)p=u;else break}}else u=F;if((l|0)<0){r=((c+25|0)/9|0)+1|0;_=(y|0)==102;do{m=0-l|0;m=(m|0)<9?m:9;if(u>>>0<h>>>0){d=(1<<m)+-1|0;p=1e9>>>m;f=0;l=u;do{C=n[l>>2]|0;n[l>>2]=(C>>>m)+f;f=b(C&d,p)|0;l=l+4|0}while(l>>>0<h>>>0);u=(n[u>>2]|0)==0?u+4|0:u;if(f){n[h>>2]=f;h=h+4|0}}else u=(n[u>>2]|0)==0?u+4|0:u;l=_?F:u;h=(h-l>>2|0)>(r|0)?l+(r<<2)|0:h;l=(n[B>>2]|0)+m|0;n[B>>2]=l}while((l|0)<0);_=u}else _=u;if(_>>>0<h>>>0){l=(M-_>>2)*9|0;d=n[_>>2]|0;if(d>>>0>=10){u=10;do{u=u*10|0;l=l+1|0}while(d>>>0>=u>>>0)}}else l=0;w=(y|0)==103;C=(c|0)!=0;u=c-((y|0)==102?0:l)+((C&w)<<31>>31)|0;if((u|0)<(((h-M>>2)*9|0)+-9|0)){B=u+9216|0;u=(B|0)/9|0;r=F+4+(u+-1024<<2)|0;u=B-(u*9|0)|0;if((u|0)<8){d=10;while(1){d=d*10|0;if((u|0)<7)u=u+1|0;else break}}else d=10;f=n[r>>2]|0;u=(f>>>0)/(d>>>0)|0;m=f-(b(u,d)|0)|0;p=(r+4|0)==(h|0);if(!(p&(m|0)==0)){g=(u&1|0)==0?9007199254740992.0:9007199254740994.0;B=d>>>1;t=m>>>0<B>>>0?0.5:p&(m|0)==(B|0)?1.0:1.5;if(U){B=(i[x>>0]|0)==45;t=B?-t:t;g=B?-g:g}u=f-m|0;n[r>>2]=u;if(g+t!=g){B=u+d|0;n[r>>2]=B;if(B>>>0>999999999){d=r;l=_;while(1){u=d+-4|0;n[d>>2]=0;if(u>>>0<l>>>0){l=l+-4|0;n[l>>2]=0}B=(n[u>>2]|0)+1|0;n[u>>2]=B;if(B>>>0>999999999)d=u;else{d=l;break}}}else{u=r;d=_}l=(M-d>>2)*9|0;f=n[d>>2]|0;if(f>>>0>=10){p=10;do{p=p*10|0;l=l+1|0}while(f>>>0>=p>>>0)}}else{u=r;d=_}}else{u=r;d=_}B=u+4|0;h=h>>>0>B>>>0?B:h}else d=_;r=0-l|0;e:do{if(h>>>0>d>>>0)while(1){u=h+-4|0;if(n[u>>2]|0){B=h;y=1;break e}if(u>>>0>d>>>0)h=u;else{B=u;y=0;break}}else{B=h;y=0}}while(0);do{if(w){c=c+((C^1)&1)|0;if((c|0)>(l|0)&(l|0)>-5){p=a+-1|0;c=c+-1-l|0}else{p=a+-2|0;c=c+-1|0}if(!(o&8)){if(y?(E=n[B+-4>>2]|0,(E|0)!=0):0)if(!((E>>>0)%10|0)){u=0;h=10;do{h=h*10|0;u=u+1|0}while(!((E>>>0)%(h>>>0)|0|0))}else u=0;else u=9;h=((B-M>>2)*9|0)+-9|0;if((p|32|0)==102){a=h-u|0;a=(a|0)>0?a:0;c=(c|0)<(a|0)?c:a;break}else{a=h+l-u|0;a=(a|0)>0?a:0;c=(c|0)<(a|0)?c:a;break}}}else p=a}while(0);_=(c|0)!=0;f=_?1:o>>>3&1;m=(p|32|0)==102;if(m){w=0;l=(l|0)>0?l:0}else{h=(l|0)<0?r:l;h=pp(h,((h|0)<0)<<31>>31,I)|0;u=I;if((u-h|0)<2)do{h=h+-1|0;i[h>>0]=48}while((u-h|0)<2);i[h+-1>>0]=(l>>31&2)+43;l=h+-2|0;i[l>>0]=p;w=l;l=u-l|0}l=U+1+c+f+l|0;fp(e,32,s,l,o);lp(e,x,U);fp(e,48,s,l,o^65536);if(m){f=d>>>0>F>>>0?F:d;m=P+9|0;d=m;p=P+8|0;u=f;do{h=pp(n[u>>2]|0,0,m)|0;if((u|0)==(f|0)){if((h|0)==(m|0)){i[p>>0]=48;h=p}}else if(h>>>0>P>>>0){dm(P|0,48,h-T|0)|0;do{h=h+-1|0}while(h>>>0>P>>>0)}lp(e,h,d-h|0);u=u+4|0}while(u>>>0<=F>>>0);if(!((o&8|0)==0&(_^1)))lp(e,20282,1);if(u>>>0<B>>>0&(c|0)>0)while(1){h=pp(n[u>>2]|0,0,m)|0;if(h>>>0>P>>>0){dm(P|0,48,h-T|0)|0;do{h=h+-1|0}while(h>>>0>P>>>0)}lp(e,h,(c|0)<9?c:9);u=u+4|0;h=c+-9|0;if(!(u>>>0<B>>>0&(c|0)>9)){c=h;break}else c=h}fp(e,48,c+9|0,9,0)}else{B=y?B:d+4|0;if(d>>>0<B>>>0&(c|0)>-1){r=P+9|0;_=(o&8|0)==0;y=r;f=0-T|0;m=P+8|0;p=d;do{h=pp(n[p>>2]|0,0,r)|0;if((h|0)==(r|0)){i[m>>0]=48;h=m}do{if((p|0)==(d|0)){u=h+1|0;lp(e,h,1);if(_&(c|0)<1){h=u;break}lp(e,20282,1);h=u}else{if(h>>>0<=P>>>0)break;dm(P|0,48,h+f|0)|0;do{h=h+-1|0}while(h>>>0>P>>>0)}}while(0);T=y-h|0;lp(e,h,(c|0)>(T|0)?T:c);c=c-T|0;p=p+4|0}while(p>>>0<B>>>0&(c|0)>-1)}fp(e,48,c+18|0,18,0);lp(e,w,I-w|0)}fp(e,32,s,l,o^8192)}}while(0);J=S;return((l|0)<(s|0)?s:l)|0}function Ap(e,t){e=e|0;t=t|0;var s=0.0,i=0;i=(n[t>>2]|0)+(8-1)&~(8-1);s=+l[i>>3];n[t>>2]=i+8;l[e>>3]=s;return}function op(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,b=0;b=J;J=J+224|0;f=b+208|0;g=b+160|0;m=b+80|0;_=b;o=g;a=o+40|0;do{n[o>>2]=0;o=o+4|0}while((o|0)<(a|0));n[f>>2]=n[s>>2];if((ap(0,t,f,m,g,r,A)|0)<0)s=-1;else{if((n[e+76>>2]|0)>-1)p=Yd(e)|0;else p=0;s=n[e>>2]|0;d=s&32;if((i[e+74>>0]|0)<1)n[e>>2]=s&-33;o=e+48|0;if(!(n[o>>2]|0)){a=e+44|0;l=n[a>>2]|0;n[a>>2]=_;c=e+28|0;n[c>>2]=_;h=e+20|0;n[h>>2]=_;n[o>>2]=80;u=e+16|0;n[u>>2]=_+80;s=ap(e,t,f,m,g,r,A)|0;if(l){Nm[n[e+36>>2]&7](e,0,0)|0;s=(n[h>>2]|0)==0?-1:s;n[a>>2]=l;n[o>>2]=0;n[u>>2]=0;n[c>>2]=0;n[h>>2]=0}}else s=ap(e,t,f,m,g,r,A)|0;o=n[e>>2]|0;n[e>>2]=o|d;if(p|0)Jd(e);s=(o&32|0)==0?s:-1}J=b;return s|0}function ap(e,t,s,A,o,a,c){e=e|0;t=t|0;s=s|0;A=A|0;o=o|0;a=a|0;c=c|0;var h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,b=0,y=0,B=0,w=0,C=0,M=0,E=0,F=0,x=0,U=0,I=0,T=0,P=0,S=0,D=0,k=0,Q=0;k=J;J=J+64|0;P=k+56|0;D=k+40|0;F=k;U=k+48|0;I=k+60|0;n[P>>2]=t;C=(e|0)!=0;M=F+40|0;E=M;F=F+39|0;x=U+4|0;h=0;t=0;d=0;e:while(1){do{do{if((t|0)>-1)if((h|0)>(2147483647-t|0)){n[(zd()|0)>>2]=61;t=-1;break}else{t=h+t|0;break}}while(0);m=n[P>>2]|0;h=i[m>>0]|0;if(!(h<<24>>24)){w=92;break e}u=m;t:while(1){switch(h<<24>>24){case 37:{w=10;break t}case 0:{h=u;break t}default:{}}B=u+1|0;n[P>>2]=B;h=i[B>>0]|0;u=B}t:do{if((w|0)==10){w=0;h=u;do{if((i[u+1>>0]|0)!=37)break t;h=h+1|0;u=u+2|0;n[P>>2]=u}while((i[u>>0]|0)==37)}}while(0);h=h-m|0;if(C)lp(e,m,h)}while((h|0)!=0);B=(Wd(i[(n[P>>2]|0)+1>>0]|0)|0)==0;u=n[P>>2]|0;if(!B?(i[u+2>>0]|0)==36:0){b=(i[u+1>>0]|0)+-48|0;f=1;h=3}else{b=-1;f=d;h=1}h=u+h|0;n[P>>2]=h;u=i[h>>0]|0;d=(u<<24>>24)+-32|0;if(d>>>0>31|(1<<d&75913|0)==0)p=0;else{p=0;do{p=1<<d|p;h=h+1|0;n[P>>2]=h;u=i[h>>0]|0;d=(u<<24>>24)+-32|0}while(!(d>>>0>31|(1<<d&75913|0)==0))}if(u<<24>>24==42){if((Wd(i[h+1>>0]|0)|0)!=0?(S=n[P>>2]|0,(i[S+2>>0]|0)==36):0){h=S+1|0;n[o+((i[h>>0]|0)+-48<<2)>>2]=10;h=n[A+((i[h>>0]|0)+-48<<3)>>2]|0;d=1;u=S+3|0}else{if(f|0){t=-1;break}if(C){B=(n[s>>2]|0)+(4-1)&~(4-1);h=n[B>>2]|0;n[s>>2]=B+4}else h=0;d=0;u=(n[P>>2]|0)+1|0}n[P>>2]=u;B=(h|0)<0;y=B?0-h|0:h;p=B?p|8192:p;B=d}else{h=cp(P)|0;if((h|0)<0){t=-1;break}y=h;B=f;u=n[P>>2]|0}do{if((i[u>>0]|0)==46){h=u+1|0;if((i[h>>0]|0)!=42){n[P>>2]=h;h=cp(P)|0;u=n[P>>2]|0;break}if(Wd(i[u+2>>0]|0)|0?(T=n[P>>2]|0,(i[T+3>>0]|0)==36):0){h=T+2|0;n[o+((i[h>>0]|0)+-48<<2)>>2]=10;h=n[A+((i[h>>0]|0)+-48<<3)>>2]|0;u=T+4|0;n[P>>2]=u;break}if(B|0){t=-1;break e}if(C){_=(n[s>>2]|0)+(4-1)&~(4-1);h=n[_>>2]|0;n[s>>2]=_+4}else h=0;u=(n[P>>2]|0)+2|0;n[P>>2]=u}else h=-1}while(0);_=0;while(1){if(((i[u>>0]|0)+-65|0)>>>0>57){t=-1;break e}d=u;u=u+1|0;n[P>>2]=u;d=i[(i[d>>0]|0)+-65+(176+(_*58|0))>>0]|0;f=d&255;if((f+-1|0)>>>0>=8)break;else _=f}if(!(d<<24>>24)){t=-1;break}g=(b|0)>-1;do{if(d<<24>>24==19)if(g){t=-1;break e}else w=54;else{if(g){n[o+(b<<2)>>2]=f;g=A+(b<<3)|0;b=n[g+4>>2]|0;w=D;n[w>>2]=n[g>>2];n[w+4>>2]=b;w=54;break}if(!C){t=0;break e}hp(D,f,s,c);u=n[P>>2]|0;w=55}}while(0);if((w|0)==54){w=0;if(C)w=55;else h=0}t:do{if((w|0)==55){w=0;u=i[u+-1>>0]|0;u=(_|0)!=0&(u&15|0)==3?u&-33:u;d=p&-65537;b=(p&8192|0)==0?p:d;s:do{switch(u|0){case 110:switch((_&255)<<24>>24){case 0:{n[n[D>>2]>>2]=t;h=0;break t}case 1:{n[n[D>>2]>>2]=t;h=0;break t}case 2:{h=n[D>>2]|0;n[h>>2]=t;n[h+4>>2]=((t|0)<0)<<31>>31;h=0;break t}case 3:{r[n[D>>2]>>1]=t;h=0;break t}case 4:{i[n[D>>2]>>0]=t;h=0;break t}case 6:{n[n[D>>2]>>2]=t;h=0;break t}case 7:{h=n[D>>2]|0;n[h>>2]=t;n[h+4>>2]=((t|0)<0)<<31>>31;h=0;break t}default:{h=0;break t}}case 112:{u=120;h=h>>>0>8?h:8;d=b|8;w=67;break}case 88:case 120:{d=b;w=67;break}case 111:{g=D;g=dp(n[g>>2]|0,n[g+4>>2]|0,M)|0;d=E-g|0;p=0;f=20230;h=(b&8|0)==0|(h|0)>(d|0)?h:d+1|0;d=b;w=73;break}case 105:case 100:{d=D;u=n[d>>2]|0;d=n[d+4>>2]|0;if((d|0)<0){u=im(0,0,u|0,d|0)|0;d=v()|0;p=D;n[p>>2]=u;n[p+4>>2]=d;p=1;f=20230;w=72;break s}else{p=(b&2049|0)!=0&1;f=(b&2048|0)==0?(b&1|0)==0?20230:20232:20231;w=72;break s}}case 117:{d=D;p=0;f=20230;u=n[d>>2]|0;d=n[d+4>>2]|0;w=72;break}case 99:{i[F>>0]=n[D>>2];m=F;p=0;f=20230;g=1;u=d;h=E;break}case 115:{_=n[D>>2]|0;_=(_|0)==0?20240:_;b=ip(_,0,h)|0;Q=(b|0)==0;m=_;p=0;f=20230;g=Q?h:b-_|0;u=d;h=Q?_+h|0:b;break}case 67:{n[U>>2]=n[D>>2];n[x>>2]=0;n[D>>2]=U;f=-1;w=79;break}case 83:{if(!h){fp(e,32,y,0,b);h=0;w=89}else{f=h;w=79}break}case 65:case 71:case 70:case 69:case 97:case 103:case 102:case 101:{h=Lm[a&1](e,+l[D>>3],y,h,b,u)|0;break t}default:{p=0;f=20230;g=h;u=b;h=E}}}while(0);s:do{if((w|0)==67){g=D;g=up(n[g>>2]|0,n[g+4>>2]|0,M,u&32)|0;f=D;f=(d&8|0)==0|(n[f>>2]|0)==0&(n[f+4>>2]|0)==0;p=f?0:2;f=f?20230:20230+(u>>>4)|0;w=73}else if((w|0)==72){g=pp(u,d,M)|0;d=b;w=73}else if((w|0)==79){w=0;p=n[D>>2]|0;h=0;while(1){u=n[p>>2]|0;if(!u)break;u=gp(I,u)|0;d=(u|0)<0;if(d|u>>>0>(f-h|0)>>>0){w=83;break}h=u+h|0;if(f>>>0>h>>>0)p=p+4|0;else break}if((w|0)==83){w=0;if(d){t=-1;break e}}fp(e,32,y,h,b);if(!h){h=0;w=89}else{d=n[D>>2]|0;p=0;while(1){u=n[d>>2]|0;if(!u){w=89;break s}u=gp(I,u)|0;p=u+p|0;if((p|0)>(h|0)){w=89;break s}lp(e,I,u);if(p>>>0>=h>>>0){w=89;break}else d=d+4|0}}}}while(0);if((w|0)==73){w=0;u=D;u=(n[u>>2]|0)!=0|(n[u+4>>2]|0)!=0;Q=(h|0)!=0|u;u=E-g+((u^1)&1)|0;m=Q?g:M;g=Q?(h|0)>(u|0)?h:u:0;u=(h|0)>-1?d&-65537:d;h=E}else if((w|0)==89){w=0;fp(e,32,y,h,b^8192);h=(y|0)>(h|0)?y:h;break}b=h-m|0;_=(g|0)<(b|0)?b:g;Q=_+p|0;h=(y|0)<(Q|0)?Q:y;fp(e,32,h,Q,u);lp(e,f,p);fp(e,48,h,Q,u^65536);fp(e,48,_,b,0);lp(e,m,b);fp(e,32,h,Q,u^8192)}}while(0);d=B}e:do{if((w|0)==92)if(!e)if(!d)t=0;else{t=1;while(1){h=n[o+(t<<2)>>2]|0;if(!h)break;hp(A+(t<<3)|0,h,s,c);t=t+1|0;if(t>>>0>=10){t=1;break e}}while(1){if(n[o+(t<<2)>>2]|0){t=-1;break e}t=t+1|0;if(t>>>0>=10){t=1;break}}}}while(0);J=k;return t|0}function lp(e,t,s){e=e|0;t=t|0;s=s|0;if(!(n[e>>2]&32))qd(t,s,e)|0;return}function cp(e){e=e|0;var t=0,s=0;if(!(Wd(i[n[e>>2]>>0]|0)|0))t=0;else{t=0;do{s=n[e>>2]|0;t=(t*10|0)+-48+(i[s>>0]|0)|0;s=s+1|0;n[e>>2]=s}while((Wd(i[s>>0]|0)|0)!=0)}return t|0}function hp(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0.0;e:do{if(t>>>0<=20)do{switch(t|0){case 9:{t=(n[s>>2]|0)+(4-1)&~(4-1);i=n[t>>2]|0;n[s>>2]=t+4;n[e>>2]=i;break e}case 10:{i=(n[s>>2]|0)+(4-1)&~(4-1);t=n[i>>2]|0;n[s>>2]=i+4;i=e;n[i>>2]=t;n[i+4>>2]=((t|0)<0)<<31>>31;break e}case 11:{i=(n[s>>2]|0)+(4-1)&~(4-1);t=n[i>>2]|0;n[s>>2]=i+4;i=e;n[i>>2]=t;n[i+4>>2]=0;break e}case 12:{i=(n[s>>2]|0)+(8-1)&~(8-1);t=i;r=n[t>>2]|0;t=n[t+4>>2]|0;n[s>>2]=i+8;i=e;n[i>>2]=r;n[i+4>>2]=t;break e}case 13:{r=(n[s>>2]|0)+(4-1)&~(4-1);i=n[r>>2]|0;n[s>>2]=r+4;i=(i&65535)<<16>>16;r=e;n[r>>2]=i;n[r+4>>2]=((i|0)<0)<<31>>31;break e}case 14:{r=(n[s>>2]|0)+(4-1)&~(4-1);i=n[r>>2]|0;n[s>>2]=r+4;r=e;n[r>>2]=i&65535;n[r+4>>2]=0;break e}case 15:{r=(n[s>>2]|0)+(4-1)&~(4-1);i=n[r>>2]|0;n[s>>2]=r+4;i=(i&255)<<24>>24;r=e;n[r>>2]=i;n[r+4>>2]=((i|0)<0)<<31>>31;break e}case 16:{r=(n[s>>2]|0)+(4-1)&~(4-1);i=n[r>>2]|0;n[s>>2]=r+4;r=e;n[r>>2]=i&255;n[r+4>>2]=0;break e}case 17:{r=(n[s>>2]|0)+(8-1)&~(8-1);A=+l[r>>3];n[s>>2]=r+8;l[e>>3]=A;break e}case 18:{zm[i&15](e,s);break e}default:break e}}while(0)}while(0);return}function up(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;if(!((e|0)==0&(t|0)==0))do{s=s+-1|0;i[s>>0]=A[640+(e&15)>>0]|0|r;e=om(e|0,t|0,4)|0;t=v()|0}while(!((e|0)==0&(t|0)==0));return s|0}function dp(e,t,s){e=e|0;t=t|0;s=s|0;if(!((e|0)==0&(t|0)==0))do{s=s+-1|0;i[s>>0]=e&7|48;e=om(e|0,t|0,3)|0;t=v()|0}while(!((e|0)==0&(t|0)==0));return s|0}function pp(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,n=0,A=0;if(t>>>0>0|(t|0)==0&e>>>0>4294967295){do{r=e;e=Am(e|0,t|0,10,0)|0;n=t;t=v()|0;A=tm(e|0,t|0,10,0)|0;A=im(r|0,n|0,A|0,v()|0)|0;v()|0;s=s+-1|0;i[s>>0]=A&255|48}while(n>>>0>9|(n|0)==9&r>>>0>4294967295);t=e}else t=e;if(t)do{A=t;t=(t>>>0)/10|0;s=s+-1|0;i[s>>0]=A-(t*10|0)|48}while(A>>>0>=10);return s|0}function fp(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var n=0,A=0;A=J;J=J+256|0;n=A;if((s|0)>(i|0)&(r&73728|0)==0){r=s-i|0;dm(n|0,t<<24>>24|0,(r>>>0<256?r:256)|0)|0;if(r>>>0>255){t=s-i|0;do{lp(e,n,256);r=r+-256|0}while(r>>>0>255);r=t&255}lp(e,n,r)}J=A;return}function gp(e,t){e=e|0;t=t|0;if(!e)e=0;else e=mp(e,t,0)|0;return e|0}function mp(e,t,s){e=e|0;t=t|0;s=s|0;do{if(e){if(t>>>0<128){i[e>>0]=t;e=1;break}if(!(n[n[(_p()|0)+176>>2]>>2]|0))if((t&-128|0)==57216){i[e>>0]=t;e=1;break}else{n[(zd()|0)>>2]=25;e=-1;break}if(t>>>0<2048){i[e>>0]=t>>>6|192;i[e+1>>0]=t&63|128;e=2;break}if(t>>>0<55296|(t&-8192|0)==57344){i[e>>0]=t>>>12|224;i[e+1>>0]=t>>>6&63|128;i[e+2>>0]=t&63|128;e=3;break}if((t+-65536|0)>>>0<1048576){i[e>>0]=t>>>18|240;i[e+1>>0]=t>>>12&63|128;i[e+2>>0]=t>>>6&63|128;i[e+3>>0]=t&63|128;e=4;break}else{n[(zd()|0)>>2]=25;e=-1;break}}else e=1}while(0);return e|0}function _p(){return Xd()|0}function bp(e){e=+e;var t=0;l[c>>3]=e;t=n[c>>2]|0;w(n[c+4>>2]|0);return t|0}function yp(e,t){e=+e;t=t|0;var s=0,i=0,r=0;l[c>>3]=e;s=n[c>>2]|0;i=n[c+4>>2]|0;r=om(s|0,i|0,52)|0;v()|0;switch(r&2047){case 0:{if(e!=0.0){e=+yp(e*18446744073709551616.0,t);s=(n[t>>2]|0)+-64|0}else s=0;n[t>>2]=s;break}case 2047:break;default:{n[t>>2]=(r&2047)+-1022;n[c>>2]=s;n[c+4>>2]=i&-2146435073|1071644672;e=+l[c>>3]}}return+e}function Bp(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,n=0;e:do{if(!s)e=0;else{while(1){r=i[e>>0]|0;n=i[t>>0]|0;if(r<<24>>24!=n<<24>>24)break;s=s+-1|0;if(!s){e=0;break e}else{e=e+1|0;t=t+1|0}}e=(r&255)-(n&255)|0}}while(0);return e|0}function wp(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;r=J;J=J+16|0;A=r;n[A>>2]=i;i=vp(e,t,s,A)|0;J=r;return i|0}function vp(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0,o=0,a=0,l=0;l=J;J=J+160|0;A=l+144|0;a=l;hm(a|0,3672,144)|0;if((t+-1|0)>>>0>2147483646)if(!t){e=A;t=1;o=4}else{n[(zd()|0)>>2]=61;t=-1}else o=4;if((o|0)==4){o=-2-e|0;o=t>>>0>o>>>0?o:t;n[a+48>>2]=o;A=a+20|0;n[A>>2]=e;n[a+44>>2]=e;t=e+o|0;e=a+16|0;n[e>>2]=t;n[a+28>>2]=t;t=rp(a,s,r)|0;if(o){a=n[A>>2]|0;i[a+(((a|0)==(n[e>>2]|0))<<31>>31)>>0]=0}}J=l;return t|0}function Cp(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;i=e+20|0;r=n[i>>2]|0;e=(n[e+16>>2]|0)-r|0;e=e>>>0>s>>>0?s:e;hm(r|0,t|0,e|0)|0;n[i>>2]=(n[i>>2]|0)+e;return s|0}function Mp(e){e=e|0;var t=0,s=0;t=(Zd(e)|0)+1|0;s=Kg(t)|0;if(!s)e=0;else e=hm(s|0,e|0,t|0)|0;return e|0}function Ep(e,t){e=e|0;t=t|0;var s=0,r=0;s=0;while(1){if((A[656+s>>0]|0)==(e|0)){r=4;break}s=s+1|0;if((s|0)==87){e=87;r=5;break}}if((r|0)==4)if(!s)s=752;else{e=s;r=5}if((r|0)==5){s=752;do{do{r=s;s=s+1|0}while((i[r>>0]|0)!=0);e=e+-1|0}while((e|0)!=0)}return Fp(s,n[t+20>>2]|0)|0}function Fp(e,t){e=e|0;t=t|0;return ep(e,t)|0}function xp(e){e=e|0;return Ep(e,n[(Up()|0)+176>>2]|0)|0}function Up(){return Xd()|0}function Ip(e,t,s){e=e|0;t=t|0;s=s|0;var r=0;r=xp(e)|0;e=Zd(r)|0;if(e>>>0>=s>>>0){e=s+-1|0;if(!s)e=68;else{hm(t|0,r|0,e|0)|0;i[t+e>>0]=0;e=68}}else{hm(t|0,r|0,e+1|0)|0;e=0}return e|0}function Tp(){var e=0,t=0,s=0,i=0,r=0,A=0,o=0;i=J;J=J+48|0;A=i+32|0;t=i+24|0;o=i+16|0;r=i;i=i+36|0;e=Pp()|0;if(e|0?(s=n[e>>2]|0,s|0):0){e=s+48|0;if(!(Sp(e)|0)){n[t>>2]=20420;kp(20370,t)}t=Dp(e)|0;if((t|0)==1126902529&(v()|0)==1129074247)e=n[s+44>>2]|0;else e=s+80|0;n[i>>2]=e;s=n[s>>2]|0;e=n[s+4>>2]|0;if(Nm[n[(n[954]|0)+16>>2]&7](3816,s,i)|0){o=n[i>>2]|0;o=Vm[n[(n[o>>2]|0)+8>>2]&15](o)|0;n[r>>2]=20420;n[r+4>>2]=e;n[r+8>>2]=o;kp(20284,r)}else{n[o>>2]=20420;n[o+4>>2]=e;kp(20329,o)}}kp(20408,A)}function Pp(){return 21640}function Sp(e){e=e|0;e=Dp(e)|0;return(e&-256|0)==1126902528&(v()|0)==1129074247|0}function Dp(e){e=e|0;var t=0;t=e;e=n[t>>2]|0;w(n[t+4>>2]|0);return e|0}function kp(e,t){e=e|0;t=t|0;Z()}function Qp(e){e=e|0;return}function Rp(e){e=e|0;Qp(e);qp(e);return}function Op(e){e=e|0;return}function Vp(e){e=e|0;return}function Lp(e,t,s){e=e|0;t=t|0;s=s|0;var A=0,o=0,a=0,l=0,c=0,h=0;h=J;J=J+64|0;l=h;if(!(jp(e,t,0)|0))if((t|0)!=0?(c=Kp(t,3840,3824,0)|0,(c|0)!=0):0){n[l>>2]=c;n[l+4>>2]=0;n[l+8>>2]=e;n[l+12>>2]=-1;e=l+16|0;t=l+24|0;A=l+48|0;o=e;a=o+36|0;do{n[o>>2]=0;o=o+4|0}while((o|0)<(a|0));r[e+36>>1]=0;i[e+38>>0]=0;n[A>>2]=1;Xm[n[(n[c>>2]|0)+28>>2]&7](c,l,n[s>>2]|0,1);if((n[t>>2]|0)==1){n[s>>2]=n[e>>2];e=1}else e=0}else e=0;else e=1;J=h;return e|0}function Hp(e,t,s,i,r,A){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;A=A|0;if(jp(e,n[t+8>>2]|0,A)|0)Xp(0,t,s,i,r);return}function Np(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0;do{if(!(jp(e,n[t+8>>2]|0,A)|0)){if(jp(e,n[t>>2]|0,A)|0){if((n[t+16>>2]|0)!=(s|0)?(o=t+20|0,(n[o>>2]|0)!=(s|0)):0){n[t+32>>2]=r;n[o>>2]=s;A=t+40|0;n[A>>2]=(n[A>>2]|0)+1;if((n[t+36>>2]|0)==1?(n[t+24>>2]|0)==2:0)i[t+54>>0]=1;n[t+44>>2]=4;break}if((r|0)==1)n[t+32>>2]=1}}else Wp(0,t,s,r)}while(0);return}function Gp(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;if(jp(e,n[t+8>>2]|0,0)|0)zp(0,t,s,i);return}function jp(e,t,s){e=e|0;t=t|0;s=s|0;if(s)if((e|0)==(t|0))e=1;else e=(Kd(n[e+4>>2]|0,n[t+4>>2]|0)|0)==0;else e=(n[e+4>>2]|0)==(n[t+4>>2]|0);return e|0}function zp(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0;e=t+16|0;A=n[e>>2]|0;do{if(A){if((A|0)!=(s|0)){r=t+36|0;n[r>>2]=(n[r>>2]|0)+1;n[t+24>>2]=2;i[t+54>>0]=1;break}e=t+24|0;if((n[e>>2]|0)==2)n[e>>2]=r}else{n[e>>2]=s;n[t+24>>2]=r;n[t+36>>2]=1}}while(0);return}function Wp(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;if((n[t+4>>2]|0)==(s|0)?(r=t+28|0,(n[r>>2]|0)!=1):0)n[r>>2]=i;return}function Xp(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;i[t+53>>0]=1;do{if((n[t+4>>2]|0)==(r|0)){i[t+52>>0]=1;e=t+16|0;r=n[e>>2]|0;if(!r){n[e>>2]=s;n[t+24>>2]=A;n[t+36>>2]=1;if(!((A|0)==1?(n[t+48>>2]|0)==1:0))break;i[t+54>>0]=1;break}if((r|0)!=(s|0)){A=t+36|0;n[A>>2]=(n[A>>2]|0)+1;i[t+54>>0]=1;break}r=t+24|0;e=n[r>>2]|0;if((e|0)==2){n[r>>2]=A;e=A}if((e|0)==1?(n[t+48>>2]|0)==1:0)i[t+54>>0]=1}}while(0);return}function Kp(e,t,s,A){e=e|0;t=t|0;s=s|0;A=A|0;var o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0;f=J;J=J+64|0;d=f;u=n[e>>2]|0;p=e+(n[u+-8>>2]|0)|0;u=n[u+-4>>2]|0;n[d>>2]=s;n[d+4>>2]=e;n[d+8>>2]=t;n[d+12>>2]=A;e=d+16|0;t=d+20|0;A=d+24|0;o=d+28|0;a=d+32|0;l=d+40|0;c=e;h=c+36|0;do{n[c>>2]=0;c=c+4|0}while((c|0)<(h|0));r[e+36>>1]=0;i[e+38>>0]=0;e:do{if(jp(u,s,0)|0){n[d+48>>2]=1;Zm[n[(n[u>>2]|0)+20>>2]&3](u,d,p,p,1,0);e=(n[A>>2]|0)==1?p:0}else{Km[n[(n[u>>2]|0)+24>>2]&3](u,d,p,1,0);switch(n[d+36>>2]|0){case 0:{e=(n[l>>2]|0)==1&(n[o>>2]|0)==1&(n[a>>2]|0)==1?n[t>>2]|0:0;break e}case 1:break;default:{e=0;break e}}if((n[A>>2]|0)!=1?!((n[l>>2]|0)==0&(n[o>>2]|0)==1&(n[a>>2]|0)==1):0){e=0;break}e=n[e>>2]|0}}while(0);J=f;return e|0}function Zp(e){e=e|0;Qp(e);qp(e);return}function Jp(e,t,s,i,r,A){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;A=A|0;if(jp(e,n[t+8>>2]|0,A)|0)Xp(0,t,s,i,r);else{e=n[e+8>>2]|0;Zm[n[(n[e>>2]|0)+20>>2]&3](e,t,s,i,r,A)}return}function Yp(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0,a=0,l=0;e:do{if(!(jp(e,n[t+8>>2]|0,A)|0)){if(!(jp(e,n[t>>2]|0,A)|0)){a=n[e+8>>2]|0;Km[n[(n[a>>2]|0)+24>>2]&3](a,t,s,r,A);break}if((n[t+16>>2]|0)!=(s|0)?(a=t+20|0,(n[a>>2]|0)!=(s|0)):0){n[t+32>>2]=r;r=t+44|0;do{if((n[r>>2]|0)!=4){o=t+52|0;i[o>>0]=0;l=t+53|0;i[l>>0]=0;e=n[e+8>>2]|0;Zm[n[(n[e>>2]|0)+20>>2]&3](e,t,s,s,1,A);if(i[l>>0]|0){l=(i[o>>0]|0)==0;n[r>>2]=3;if(l)break;else break e}else{n[r>>2]=4;break}}}while(0);n[a>>2]=s;l=t+40|0;n[l>>2]=(n[l>>2]|0)+1;if((n[t+36>>2]|0)!=1)break;if((n[t+24>>2]|0)!=2)break;i[t+54>>0]=1;break}if((r|0)==1)n[t+32>>2]=1}else Wp(0,t,s,r)}while(0);return}function $p(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;if(jp(e,n[t+8>>2]|0,0)|0)zp(0,t,s,i);else{e=n[e+8>>2]|0;Xm[n[(n[e>>2]|0)+28>>2]&7](e,t,s,i)}return}function qp(e){e=e|0;Zg(e);return}function ef(e){e=e|0;return}function tf(){var e=0,t=0;e=Pp()|0;if((e|0?(t=n[e>>2]|0,t|0):0)?Sp(t+48|0)|0:0)sf(n[t+12>>2]|0);sf(rf()|0)}function sf(e){e=e|0;var t=0;t=J;J=J+16|0;Gm[e&3]();kp(20559,t)}function rf(){return 2}function nf(e){e=e|0;return}function Af(e){e=e|0;qp(e);return}function of(e){e=e|0;return 20599}function af(e){e=e|0;n[e>>2]=5916;uf(e+4|0);return}function lf(e){e=e|0;af(e);qp(e);return}function cf(e){e=e|0;return hf(e+4|0)|0}function hf(e){e=e|0;return n[e>>2]|0}function uf(e){e=e|0;var t=0,s=0;if(df(e)|0?(t=pf(n[e>>2]|0)|0,s=t+8|0,e=n[s>>2]|0,n[s>>2]=e+-1,(e|0)<1):0)qp(t);return}function df(e){e=e|0;return 1}function pf(e){e=e|0;return e+-12|0}function ff(e){e=e|0;n[e>>2]=5936;uf(e+4|0);return}function gf(e){e=e|0;ff(e);qp(e);return}function mf(e){e=e|0;return hf(e+4|0)|0}function _f(e){e=e|0;af(e);qp(e);return}function bf(e){e=e|0;af(e);qp(e);return}function yf(){var e=0;e=J;J=J+16|0;kp(20848,e)}function Bf(e){e=e|0;Qp(e);qp(e);return}function wf(e,t,s){e=e|0;t=t|0;s=s|0;return jp(e,t,0)|0}function vf(e){e=e|0;Qp(e);qp(e);return}function Cf(e,t,s){e=e|0;t=t|0;s=s|0;var A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0;d=J;J=J+64|0;h=d;do{if(!(jp(t,4048,0)|0)){if(Mf(e,t,0)|0){t=n[s>>2]|0;if(!t){t=1;break}n[s>>2]=n[t>>2];t=1;break}if((t|0)!=0?(A=Kp(t,3840,3976,0)|0,(A|0)!=0):0){t=n[s>>2]|0;if(t|0)n[s>>2]=n[t>>2];t=n[A+8>>2]|0;a=e+8|0;o=n[a>>2]|0;if((t&7&(o^7)|0)==0?((t&96^96)&o|0)==0:0){o=e+12|0;e=n[o>>2]|0;A=A+12|0;t=n[A>>2]|0;if(!(jp(e,t,0)|0)){if(jp(e,4040,0)|0){if(!t){t=1;break}t=(Kp(t,3840,3992,0)|0)==0;break}if(e){t=Kp(e,3840,3976,0)|0;if(t|0){if(!(n[a>>2]&1)){t=0;break}t=Ef(t,n[A>>2]|0)|0;break}t=n[o>>2]|0;if(t){t=Kp(t,3840,4008,0)|0;if(t|0){if(!(n[a>>2]&1)){t=0;break}t=Ff(t,n[A>>2]|0)|0;break}t=n[o>>2]|0;if((((t|0)!=0?(l=Kp(t,3840,3824,0)|0,(l|0)!=0):0)?(c=n[A>>2]|0,(c|0)!=0):0)?(u=Kp(c,3840,3824,0)|0,(u|0)!=0):0){n[h>>2]=u;n[h+4>>2]=0;n[h+8>>2]=l;n[h+12>>2]=-1;t=h+16|0;e=h+24|0;A=h+48|0;o=t;a=o+36|0;do{n[o>>2]=0;o=o+4|0}while((o|0)<(a|0));r[t+36>>1]=0;i[t+38>>0]=0;n[A>>2]=1;Xm[n[(n[u>>2]|0)+28>>2]&7](u,h,n[s>>2]|0,1);do{if((n[e>>2]|0)==1){if(!(n[s>>2]|0)){t=1;break}n[s>>2]=n[t>>2];t=1}else t=0}while(0)}else t=0}else t=0}else t=0}else t=1}else t=0}else t=0}else{n[s>>2]=0;t=1}}while(0);J=d;return t|0}function Mf(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;if(!(n[e+8>>2]&24))if((t|0)!=0?(i=Kp(t,3840,3960,0)|0,(i|0)!=0):0){s=(n[i+8>>2]&24|0)!=0;r=5}else s=0;else{s=1;r=5}if((r|0)==5)s=jp(e,t,s)|0;return s|0}function Ef(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;while(1){if(!t){t=0;break}s=Kp(t,3840,3976,0)|0;if(!s){t=0;break}r=n[e+8>>2]|0;if(n[s+8>>2]&~r|0){t=0;break}i=e+12|0;t=n[i>>2]|0;s=s+12|0;if(jp(t,n[s>>2]|0,0)|0){t=1;break}if((r&1|0)==0|(t|0)==0){t=0;break}e=Kp(t,3840,3976,0)|0;if(!e){o=9;break}t=n[s>>2]|0}if((o|0)==9){t=n[i>>2]|0;if((t|0)!=0?(A=Kp(t,3840,4008,0)|0,(A|0)!=0):0)t=Ff(A,n[s>>2]|0)|0;else t=0}return t|0}function Ff(e,t){e=e|0;t=t|0;var s=0;if((((t|0)!=0?(s=Kp(t,3840,4008,0)|0,(s|0)!=0):0)?(n[s+8>>2]&~n[e+8>>2]|0)==0:0)?jp(n[e+12>>2]|0,n[s+12>>2]|0,0)|0:0)e=jp(n[e+16>>2]|0,n[s+16>>2]|0,0)|0;else e=0;return e|0}function xf(e){e=e|0;Qp(e);qp(e);return}function Uf(e,t,s,r,A,o){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;o=o|0;var a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0;if(jp(e,n[t+8>>2]|0,o)|0)Xp(0,t,s,r,A);else{m=t+52|0;l=i[m>>0]|0;g=t+53|0;a=i[g>>0]|0;f=n[e+12>>2]|0;u=e+16+(f<<3)|0;i[m>>0]=0;i[g>>0]=0;Sf(e+16|0,t,s,r,A,o);c=i[m>>0]|0;l=c|l;h=i[g>>0]|0;a=h|a;e:do{if((f|0)>1){d=t+24|0;p=e+8|0;f=t+54|0;e=e+24|0;do{a=a&1;l=l&1;if(i[f>>0]|0)break e;if(!(c<<24>>24)){if(h<<24>>24?(n[p>>2]&1|0)==0:0)break e}else{if((n[d>>2]|0)==1)break e;if(!(n[p>>2]&2))break e}i[m>>0]=0;i[g>>0]=0;Sf(e,t,s,r,A,o);c=i[m>>0]|0;l=c|l;h=i[g>>0]|0;a=h|a;e=e+8|0}while(e>>>0<u>>>0)}}while(0);i[m>>0]=l<<24>>24!=0&1;i[g>>0]=a<<24>>24!=0&1}return}function If(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0;e:do{if(!(jp(e,n[t+8>>2]|0,A)|0)){if(!(jp(e,n[t>>2]|0,A)|0)){f=n[e+12>>2]|0;c=e+16+(f<<3)|0;Df(e+16|0,t,s,r,A);o=e+24|0;if((f|0)<=1)break;e=n[e+8>>2]|0;if((e&2|0)==0?(l=t+36|0,(n[l>>2]|0)!=1):0){if(!(e&1)){e=t+54|0;while(1){if(i[e>>0]|0)break e;if((n[l>>2]|0)==1)break e;Df(o,t,s,r,A);o=o+8|0;if(o>>>0>=c>>>0)break e}}e=t+24|0;a=t+54|0;while(1){if(i[a>>0]|0)break e;if((n[l>>2]|0)==1?(n[e>>2]|0)==1:0)break e;Df(o,t,s,r,A);o=o+8|0;if(o>>>0>=c>>>0)break e}}e=t+54|0;while(1){if(i[e>>0]|0)break e;Df(o,t,s,r,A);o=o+8|0;if(o>>>0>=c>>>0)break e}}if((n[t+16>>2]|0)!=(s|0)?(f=t+20|0,(n[f>>2]|0)!=(s|0)):0){n[t+32>>2]=r;p=t+44|0;if((n[p>>2]|0)!=4){l=e+16+(n[e+12>>2]<<3)|0;c=t+52|0;r=t+53|0;h=t+54|0;u=e+8|0;d=t+24|0;o=0;a=e+16|0;e=0;t:while(1){if(a>>>0>=l>>>0){a=18;break}i[c>>0]=0;i[r>>0]=0;Sf(a,t,s,s,1,A);if(i[h>>0]|0){a=18;break}do{if(i[r>>0]|0){if(!(i[c>>0]|0))if(!(n[u>>2]&1)){a=19;break t}else{e=1;break}if((n[d>>2]|0)==1){o=1;a=19;break t}if(!(n[u>>2]&2)){o=1;a=19;break t}else{o=1;e=1}}}while(0);a=a+8|0}if((a|0)==18)if(e)a=19;else e=4;if((a|0)==19)e=3;n[p>>2]=e;if(o&1)break}n[f>>2]=s;s=t+40|0;n[s>>2]=(n[s>>2]|0)+1;if((n[t+36>>2]|0)!=1)break;if((n[t+24>>2]|0)!=2)break;i[t+54>>0]=1;break}if((r|0)==1)n[t+32>>2]=1}else Wp(0,t,s,r)}while(0);return}function Tf(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0,o=0;e:do{if(!(jp(e,n[t+8>>2]|0,0)|0)){o=n[e+12>>2]|0;A=e+16+(o<<3)|0;Pf(e+16|0,t,s,r);if((o|0)>1){o=t+54|0;e=e+24|0;do{Pf(e,t,s,r);if(i[o>>0]|0)break e;e=e+8|0}while(e>>>0<A>>>0)}}else zp(0,t,s,r)}while(0);return}function Pf(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;A=n[e+4>>2]|0;if(s){r=A>>8;if(A&1)r=n[(n[s>>2]|0)+r>>2]|0}else r=0;e=n[e>>2]|0;Xm[n[(n[e>>2]|0)+28>>2]&7](e,t,s+r|0,(A&2|0)==0?2:i);return}function Sf(e,t,s,i,r,A){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;A=A|0;var o=0,a=0;a=n[e+4>>2]|0;o=a>>8;if(a&1)o=n[(n[i>>2]|0)+o>>2]|0;e=n[e>>2]|0;Zm[n[(n[e>>2]|0)+20>>2]&3](e,t,s,i+o|0,(a&2|0)==0?2:r,A);return}function Df(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var A=0,o=0;o=n[e+4>>2]|0;A=o>>8;if(o&1)A=n[(n[s>>2]|0)+A>>2]|0;e=n[e>>2]|0;Km[n[(n[e>>2]|0)+24>>2]&3](e,t,s+A|0,(o&2|0)==0?2:i,r);return}function kf(e){e=e|0;n[e>>2]=5896;return}function Qf(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;Rf(s,e);e=Of(s)|0;J=t;return e|0}function Rf(e,t){e=e|0;t=t|0;Gf(e,t);return}function Of(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;Vf(s,n[e+4>>2]|0);if(!((Lf(s)|0)<<24>>24))e=Nf(Hf(e)|0)|0;else e=0;J=t;return e|0}function Vf(e,t){e=e|0;t=t|0;n[e>>2]=t;return}function Lf(e){e=e|0;return i[n[e>>2]>>0]|0}function Hf(e){e=e|0;return e|0}function Nf(e){e=e|0;var t=0,s=0,r=0,A=0;A=J;J=J+16|0;r=A;e=n[e+8>>2]|0;t=i[e>>0]|0;do{if(t<<24>>24!=1)if(!(t&2)){i[e>>0]=2;s=1;break}else kp(20985,r);else s=0}while(0);J=A;return s|0}function Gf(e,t){e=e|0;t=t|0;n[e>>2]=t;n[e+4>>2]=t;n[e+8>>2]=t+1;n[e+12>>2]=0;return}function jf(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;Rf(s,e);zf(s);J=t;return}function zf(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;Vf(s,n[e+4>>2]|0);Wf(s);Xf(Hf(e)|0);J=t;return}function Wf(e){e=e|0;i[n[e>>2]>>0]=1;return}function Xf(e){e=e|0;i[n[e+8>>2]>>0]=1;return}function Kf(){return 0}function Zf(e){e=e|0;var t=0,s=0;s=(e|0)==0?1:e;while(1){t=Kg(s)|0;if(t|0){e=6;break}e=Kf()|0;if(!e){e=5;break}Gm[e&3]()}if((e|0)==5){s=C(4)|0;kf(s);E(s|0,3880,121)}else if((e|0)==6)return t|0;return 0}function Jf(e){e=e|0;return Zf(e)|0}function Yf(e){e=e|0;qp(e);return}function $f(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=J;J=J+16|0;i=r;n[i>>2]=n[s>>2];e=Nm[n[(n[e>>2]|0)+16>>2]&7](e,t,i)|0;if(e)n[s>>2]=n[i>>2];J=r;return e&1|0}function qf(e){e=e|0;if(!e)e=0;else e=(Kp(e,3840,3976,0)|0)!=0&1;return e|0}function eg(e){e=e|0;return 0}function tg(){return(sg()|0)>0|0}function sg(){return F()|0}function ig(e){e=e|0;return}function rg(e){e=e|0;ig(e);qp(e);return}function ng(e){e=e|0;return 21039}function Ag(e){e=e|0;return}function og(e){e=e|0;var t=0,s=0;t=e+8|0;if(!((n[t>>2]|0)!=0?(s=n[t>>2]|0,n[t>>2]=s+-1,(s|0)!=0):0))jm[n[(n[e>>2]|0)+16>>2]&255](e);return}function ag(e){e=e|0;e=eg(e)|0;if(!e)return;else Wg(e,21145)}function lg(e){e=e|0;return}function cg(e,t){e=e|0;t=t|0;var s=0,i=0;i=Zd(t)|0;s=Zf(i+13|0)|0;n[s>>2]=i;n[s+4>>2]=i;n[s+8>>2]=0;s=hg(s)|0;hm(s|0,t|0,i+1|0)|0;n[e>>2]=s;return}function hg(e){e=e|0;return e+12|0}function ug(e,t){e=e|0;t=t|0;n[e>>2]=5916;cg(e+4|0,t);return}function dg(e,t){e=e|0;t=t|0;n[e>>2]=5936;cg(e+4|0,(i[t+11>>0]|0)<0?n[t>>2]|0:t);return}function pg(e,t){e=e|0;t=t|0;n[e>>2]=5936;cg(e+4|0,t);return}function fg(e){e=e|0;e=C(8)|0;ug(e,21163);n[e>>2]=5956;E(e|0,3928,123)}function gg(e){e=e|0;e=C(8)|0;ug(e,21163);n[e>>2]=5976;E(e|0,3944,123)}function mg(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0;A=J;J=J+16|0;r=A;if(s>>>0>4294967279)fg(e);if(s>>>0<11)i[e+11>>0]=s;else{a=s+16&-16;o=Zf(a)|0;n[e>>2]=o;n[e+8>>2]=a|-2147483648;n[e+4>>2]=s;e=o}_g(e,t,s)|0;i[r>>0]=0;rt(e+s|0,r);J=A;return}function _g(e,t,s){e=e|0;t=t|0;s=s|0;if(s|0)hm(e|0,t|0,s|0)|0;return e|0}function bg(e){e=e|0;if((i[e+11>>0]|0)<0)ye(n[e>>2]|0,n[e+8>>2]&2147483647);return}function yg(e,t,s,r,A,o,a,l){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;o=o|0;a=a|0;l=l|0;var c=0,h=0,u=0,d=0,p=0;p=J;J=J+16|0;d=p;if((-18-t|0)>>>0<s>>>0)fg(e);if((i[e+11>>0]|0)<0)u=n[e>>2]|0;else u=e;if(t>>>0<2147483623){c=s+t|0;h=t<<1;c=c>>>0<h>>>0?h:c;c=c>>>0<11?11:c+16&-16}else c=-17;h=Zf(c)|0;if(A|0)_g(h,u,A)|0;if(a|0)_g(h+A|0,l,a)|0;r=r-o|0;s=r-A|0;if(s|0)_g(h+A+a|0,u+A+o|0,s)|0;s=t+1|0;if((s|0)!=11)ye(u,s);n[e>>2]=h;n[e+8>>2]=c|-2147483648;a=r+a|0;n[e+4>>2]=a;i[d>>0]=0;rt(h+a|0,d);J=p;return}function Bg(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0;c=J;J=J+16|0;a=c;l=e+11|0;r=i[l>>0]|0;o=r<<24>>24<0;if(o){A=(n[e+8>>2]&2147483647)+-1|0;r=n[e+4>>2]|0}else{A=10;r=r&255}if((A-r|0)>>>0>=s>>>0){if(s|0){if(o)A=n[e>>2]|0;else A=e;_g(A+r|0,t,s)|0;r=r+s|0;if((i[l>>0]|0)<0)n[e+4>>2]=r;else i[l>>0]=r;i[a>>0]=0;rt(A+r|0,a)}}else yg(e,A,r+s-A|0,r,r,0,s,t);J=c;return e|0}function wg(e,t){e=e|0;t=t|0;return Bg(e,t,st(t)|0)|0}function vg(e,t,s){e=e|0;t=t|0;s=s|0;if(!s)e=0;else e=Bp(e,t,s)|0;return e|0}function Cg(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0,a=0;o=i[e+11>>0]|0;a=o<<24>>24<0;if(a)o=n[e+4>>2]|0;else o=o&255;if((A|0)==-1|o>>>0<t>>>0)gg(e);o=o-t|0;s=o>>>0<s>>>0?o:s;if(a)e=n[e>>2]|0;o=s>>>0>A>>>0;e=vg(e+t|0,r,o?A:s)|0;if(!e)return(s>>>0<A>>>0?-1:o&1)|0;else return e|0;return 0}function Mg(e){e=e|0;return}function Eg(e){e=e|0;qp(e);return}function Fg(e){e=e|0;return 21228}function xg(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=s;n[e+4>>2]=t;return}function Ug(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=J;J=J+16|0;i=r;Wm[n[(n[e>>2]|0)+12>>2]&15](i,e,t);if((n[i+4>>2]|0)==(n[s+4>>2]|0))e=(n[i>>2]|0)==(n[s>>2]|0);else e=0;J=r;return e|0}function Ig(e,t,s){e=e|0;t=t|0;s=s|0;return((n[t>>2]|0)==(s|0)?(n[t+4>>2]|0)==(e|0):0)|0}function Tg(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)>256)mg(e,21176,st(21176)|0);else Pg(e,0,s);return}function Pg(e,t,s){e=e|0;t=t|0;s=s|0;Sg(e,s);return}function Sg(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0,a=0;a=J;J=J+1040|0;A=a+1024|0;s=a;o=n[(zd()|0)>>2]|0;r=Dg(Ip(t,s,1024)|0,s)|0;if(!(i[r>>0]|0)){n[A>>2]=t;wp(s,1024,21211,A)|0}else s=r;n[(zd()|0)>>2]=o;mg(e,s,st(s)|0);J=a;return}function Dg(e,t){e=e|0;t=t|0;var s=0,i=0;switch(e|0){case 0:{s=t;break}case-1:{e=n[(zd()|0)>>2]|0;i=3;break}default:i=3}if((i|0)==3)if((e|0)==28)s=22145;else j();return s|0}function kg(e){e=e|0;qp(e);return}function Qg(e){e=e|0;return 21353}function Rg(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)>256){Vg()|0;t=6180}else{Lg()|0;t=6176}n[e>>2]=s;n[e+4>>2]=t;return}function Og(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)>256)mg(e,21319,st(21319)|0);else Pg(e,0,s);return}function Vg(){if((i[21488]|0)==0?Qf(21488)|0:0)jf(21488);return 6180}function Lg(){if((i[21480]|0)==0?Qf(21480)|0:0)jf(21480);return 6176}function Hg(e){e=e|0;ff(e);return}function Ng(e){e=e|0;Hg(e);qp(e);return}function Gg(e,t){e=e|0;t=t|0;var s=0;s=n[t+4>>2]|0;Wm[n[(n[s>>2]|0)+24>>2]&15](e,s,n[t>>2]|0);return}function jg(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;o=J;J=J+16|0;A=o;if(n[t>>2]|0){r=i[s+11>>0]|0;if(r<<24>>24<0)r=n[s+4>>2]|0;else r=r&255;if(r|0)wg(s,21417)|0;Gg(A,t);t=i[A+11>>0]|0;r=t<<24>>24<0;Bg(s,r?n[A>>2]|0:A,r?n[A+4>>2]|0:t&255)|0;bg(A)}n[e>>2]=n[s>>2];n[e+4>>2]=n[s+4>>2];n[e+8>>2]=n[s+8>>2];r=0;while(1){if((r|0)==3)break;n[s+(r<<2)>>2]=0;r=r+1|0}J=o;return}function zg(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0;i=J;J=J+32|0;A=i+12|0;r=i;mg(r,s,st(s)|0);jg(A,t,r);dg(e,A);bg(A);bg(r);n[e>>2]=6192;r=t;t=n[r+4>>2]|0;s=e+8|0;n[s>>2]=n[r>>2];n[s+4>>2]=t;J=i;return}function Wg(e,t){e=e|0;t=t|0;var s=0,i=0,r=0;r=J;J=J+16|0;i=r+8|0;s=C(16)|0;Vg()|0;n[r>>2]=e;n[r+4>>2]=6180;n[i>>2]=n[r>>2];n[i+4>>2]=n[r+4>>2];zg(s,i,t);E(s|0,4272,136)}function Xg(e){e=e|0;e=C(8)|0;ug(e,21420);n[e>>2]=5956;E(e|0,3928,123)}function Kg(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,b=0,y=0,B=0,w=0;w=J;J=J+16|0;d=w;do{if(e>>>0<245){c=e>>>0<11?16:e+11&-8;e=c>>>3;u=n[5412]|0;s=u>>>e;if(s&3|0){t=(s&1^1)+e|0;e=21688+(t<<1<<2)|0;s=e+8|0;i=n[s>>2]|0;r=i+8|0;A=n[r>>2]|0;if((A|0)==(e|0))n[5412]=u&~(1<<t);else{n[A+12>>2]=e;n[s>>2]=A}B=t<<3;n[i+4>>2]=B|3;B=i+B+4|0;n[B>>2]=n[B>>2]|1;B=r;J=w;return B|0}h=n[5414]|0;if(c>>>0>h>>>0){if(s|0){t=2<<e;t=s<<e&(t|0-t);t=(t&0-t)+-1|0;a=t>>>12&16;t=t>>>a;s=t>>>5&8;t=t>>>s;A=t>>>2&4;t=t>>>A;e=t>>>1&2;t=t>>>e;i=t>>>1&1;i=(s|a|A|e|i)+(t>>>i)|0;t=21688+(i<<1<<2)|0;e=t+8|0;A=n[e>>2]|0;a=A+8|0;s=n[a>>2]|0;if((s|0)==(t|0)){e=u&~(1<<i);n[5412]=e}else{n[s+12>>2]=t;n[e>>2]=s;e=u}B=i<<3;o=B-c|0;n[A+4>>2]=c|3;r=A+c|0;n[r+4>>2]=o|1;n[A+B>>2]=o;if(h|0){i=n[5417]|0;t=h>>>3;s=21688+(t<<1<<2)|0;t=1<<t;if(!(e&t)){n[5412]=e|t;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=i;n[t+12>>2]=i;n[i+8>>2]=t;n[i+12>>2]=s}n[5414]=o;n[5417]=r;B=a;J=w;return B|0}A=n[5413]|0;if(A){s=(A&0-A)+-1|0;r=s>>>12&16;s=s>>>r;i=s>>>5&8;s=s>>>i;o=s>>>2&4;s=s>>>o;a=s>>>1&2;s=s>>>a;l=s>>>1&1;l=n[21952+((i|r|o|a|l)+(s>>>l)<<2)>>2]|0;s=l;a=l;l=(n[l+4>>2]&-8)-c|0;while(1){e=n[s+16>>2]|0;if(!e){e=n[s+20>>2]|0;if(!e)break}o=(n[e+4>>2]&-8)-c|0;r=o>>>0<l>>>0;s=e;a=r?e:a;l=r?o:l}o=a+c|0;if(o>>>0>a>>>0){r=n[a+24>>2]|0;t=n[a+12>>2]|0;do{if((t|0)==(a|0)){e=a+20|0;t=n[e>>2]|0;if(!t){e=a+16|0;t=n[e>>2]|0;if(!t){s=0;break}}while(1){i=t+20|0;s=n[i>>2]|0;if(!s){i=t+16|0;s=n[i>>2]|0;if(!s)break;else{t=s;e=i}}else{t=s;e=i}}n[e>>2]=0;s=t}else{s=n[a+8>>2]|0;n[s+12>>2]=t;n[t+8>>2]=s;s=t}}while(0);do{if(r|0){t=n[a+28>>2]|0;e=21952+(t<<2)|0;if((a|0)==(n[e>>2]|0)){n[e>>2]=s;if(!s){n[5413]=A&~(1<<t);break}}else{B=r+16|0;n[((n[B>>2]|0)==(a|0)?B:r+20|0)>>2]=s;if(!s)break}n[s+24>>2]=r;t=n[a+16>>2]|0;if(t|0){n[s+16>>2]=t;n[t+24>>2]=s}t=n[a+20>>2]|0;if(t|0){n[s+20>>2]=t;n[t+24>>2]=s}}}while(0);if(l>>>0<16){B=l+c|0;n[a+4>>2]=B|3;B=a+B+4|0;n[B>>2]=n[B>>2]|1}else{n[a+4>>2]=c|3;n[o+4>>2]=l|1;n[o+l>>2]=l;if(h|0){i=n[5417]|0;t=h>>>3;s=21688+(t<<1<<2)|0;t=1<<t;if(!(t&u)){n[5412]=t|u;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=i;n[t+12>>2]=i;n[i+8>>2]=t;n[i+12>>2]=s}n[5414]=l;n[5417]=o}B=a+8|0;J=w;return B|0}else u=c}else u=c}else u=c}else if(e>>>0<=4294967231){e=e+11|0;c=e&-8;i=n[5413]|0;if(i){r=0-c|0;e=e>>>8;if(e)if(c>>>0>16777215)l=31;else{u=(e+1048320|0)>>>16&8;g=e<<u;a=(g+520192|0)>>>16&4;g=g<<a;l=(g+245760|0)>>>16&2;l=14-(a|u|l)+(g<<l>>>15)|0;l=c>>>(l+7|0)&1|l<<1}else l=0;s=n[21952+(l<<2)>>2]|0;e:do{if(!s){s=0;e=0;g=61}else{e=0;a=c<<((l|0)==31?0:25-(l>>>1)|0);A=0;while(1){o=(n[s+4>>2]&-8)-c|0;if(o>>>0<r>>>0)if(!o){e=s;r=0;g=65;break e}else{e=s;r=o}g=n[s+20>>2]|0;s=n[s+16+(a>>>31<<2)>>2]|0;A=(g|0)==0|(g|0)==(s|0)?A:g;if(!s){s=A;g=61;break}else a=a<<1}}}while(0);if((g|0)==61){if((s|0)==0&(e|0)==0){e=2<<l;e=(e|0-e)&i;if(!e){u=c;break}u=(e&0-e)+-1|0;o=u>>>12&16;u=u>>>o;A=u>>>5&8;u=u>>>A;a=u>>>2&4;u=u>>>a;l=u>>>1&2;u=u>>>l;s=u>>>1&1;e=0;s=n[21952+((A|o|a|l|s)+(u>>>s)<<2)>>2]|0}if(!s){a=e;o=r}else g=65}if((g|0)==65){A=s;while(1){u=(n[A+4>>2]&-8)-c|0;s=u>>>0<r>>>0;r=s?u:r;e=s?A:e;s=n[A+16>>2]|0;if(!s)s=n[A+20>>2]|0;if(!s){a=e;o=r;break}else A=s}}if(((a|0)!=0?o>>>0<((n[5414]|0)-c|0)>>>0:0)?(h=a+c|0,h>>>0>a>>>0):0){A=n[a+24>>2]|0;t=n[a+12>>2]|0;do{if((t|0)==(a|0)){e=a+20|0;t=n[e>>2]|0;if(!t){e=a+16|0;t=n[e>>2]|0;if(!t){t=0;break}}while(1){r=t+20|0;s=n[r>>2]|0;if(!s){r=t+16|0;s=n[r>>2]|0;if(!s)break;else{t=s;e=r}}else{t=s;e=r}}n[e>>2]=0}else{B=n[a+8>>2]|0;n[B+12>>2]=t;n[t+8>>2]=B}}while(0);do{if(A){e=n[a+28>>2]|0;s=21952+(e<<2)|0;if((a|0)==(n[s>>2]|0)){n[s>>2]=t;if(!t){i=i&~(1<<e);n[5413]=i;break}}else{B=A+16|0;n[((n[B>>2]|0)==(a|0)?B:A+20|0)>>2]=t;if(!t)break}n[t+24>>2]=A;e=n[a+16>>2]|0;if(e|0){n[t+16>>2]=e;n[e+24>>2]=t}e=n[a+20>>2]|0;if(e){n[t+20>>2]=e;n[e+24>>2]=t}}}while(0);e:do{if(o>>>0<16){B=o+c|0;n[a+4>>2]=B|3;B=a+B+4|0;n[B>>2]=n[B>>2]|1}else{n[a+4>>2]=c|3;n[h+4>>2]=o|1;n[h+o>>2]=o;t=o>>>3;if(o>>>0<256){s=21688+(t<<1<<2)|0;e=n[5412]|0;t=1<<t;if(!(e&t)){n[5412]=e|t;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=h;n[t+12>>2]=h;n[h+8>>2]=t;n[h+12>>2]=s;break}t=o>>>8;if(t)if(o>>>0>16777215)s=31;else{y=(t+1048320|0)>>>16&8;B=t<<y;b=(B+520192|0)>>>16&4;B=B<<b;s=(B+245760|0)>>>16&2;s=14-(b|y|s)+(B<<s>>>15)|0;s=o>>>(s+7|0)&1|s<<1}else s=0;t=21952+(s<<2)|0;n[h+28>>2]=s;e=h+16|0;n[e+4>>2]=0;n[e>>2]=0;e=1<<s;if(!(i&e)){n[5413]=i|e;n[t>>2]=h;n[h+24>>2]=t;n[h+12>>2]=h;n[h+8>>2]=h;break}t=n[t>>2]|0;t:do{if((n[t+4>>2]&-8|0)!=(o|0)){i=o<<((s|0)==31?0:25-(s>>>1)|0);while(1){s=t+16+(i>>>31<<2)|0;e=n[s>>2]|0;if(!e)break;if((n[e+4>>2]&-8|0)==(o|0)){t=e;break t}else{i=i<<1;t=e}}n[s>>2]=h;n[h+24>>2]=t;n[h+12>>2]=h;n[h+8>>2]=h;break e}}while(0);y=t+8|0;B=n[y>>2]|0;n[B+12>>2]=h;n[y>>2]=h;n[h+8>>2]=B;n[h+12>>2]=t;n[h+24>>2]=0}}while(0);B=a+8|0;J=w;return B|0}else u=c}else u=c}else u=-1}while(0);s=n[5414]|0;if(s>>>0>=u>>>0){t=s-u|0;e=n[5417]|0;if(t>>>0>15){B=e+u|0;n[5417]=B;n[5414]=t;n[B+4>>2]=t|1;n[e+s>>2]=t;n[e+4>>2]=u|3}else{n[5414]=0;n[5417]=0;n[e+4>>2]=s|3;B=e+s+4|0;n[B>>2]=n[B>>2]|1}B=e+8|0;J=w;return B|0}o=n[5415]|0;if(o>>>0>u>>>0){b=o-u|0;n[5415]=b;B=n[5418]|0;y=B+u|0;n[5418]=y;n[y+4>>2]=b|1;n[B+4>>2]=u|3;B=B+8|0;J=w;return B|0}if(!(n[5530]|0)){n[5532]=4096;n[5531]=4096;n[5533]=-1;n[5534]=-1;n[5535]=0;n[5523]=0;n[5530]=d&-16^1431655768;e=4096}else e=n[5532]|0;a=u+48|0;l=u+47|0;A=e+l|0;r=0-e|0;c=A&r;if(c>>>0<=u>>>0){B=0;J=w;return B|0}e=n[5522]|0;if(e|0?(h=n[5520]|0,d=h+c|0,d>>>0<=h>>>0|d>>>0>e>>>0):0){B=0;J=w;return B|0}e:do{if(!(n[5523]&4)){s=n[5418]|0;t:do{if(s){i=22096;while(1){d=n[i>>2]|0;if(d>>>0<=s>>>0?(d+(n[i+4>>2]|0)|0)>>>0>s>>>0:0)break;e=n[i+8>>2]|0;if(!e){g=128;break t}else i=e}t=A-o&r;if(t>>>0<2147483647){e=Jg(t)|0;if((e|0)==((n[i>>2]|0)+(n[i+4>>2]|0)|0)){if((e|0)!=(-1|0)){o=t;A=e;g=145;break e}}else{i=e;g=136}}else t=0}else g=128}while(0);do{if((g|0)==128){s=Jg(0)|0;if((s|0)!=(-1|0)?(t=s,p=n[5531]|0,f=p+-1|0,t=((f&t|0)==0?0:(f+t&0-p)-t|0)+c|0,p=n[5520]|0,f=t+p|0,t>>>0>u>>>0&t>>>0<2147483647):0){d=n[5522]|0;if(d|0?f>>>0<=p>>>0|f>>>0>d>>>0:0){t=0;break}e=Jg(t)|0;if((e|0)==(s|0)){o=t;A=s;g=145;break e}else{i=e;g=136}}else t=0}}while(0);do{if((g|0)==136){s=0-t|0;if(!(a>>>0>t>>>0&(t>>>0<2147483647&(i|0)!=(-1|0))))if((i|0)==(-1|0)){t=0;break}else{o=t;A=i;g=145;break e}e=n[5532]|0;e=l-t+e&0-e;if(e>>>0>=2147483647){o=t;A=i;g=145;break e}if((Jg(e)|0)==(-1|0)){Jg(s)|0;t=0;break}else{o=e+t|0;A=i;g=145;break e}}}while(0);n[5523]=n[5523]|4;g=143}else{t=0;g=143}}while(0);if(((g|0)==143?c>>>0<2147483647:0)?(b=Jg(c)|0,f=Jg(0)|0,m=f-b|0,_=m>>>0>(u+40|0)>>>0,!((b|0)==(-1|0)|_^1|b>>>0<f>>>0&((b|0)!=(-1|0)&(f|0)!=(-1|0))^1)):0){o=_?m:t;A=b;g=145}if((g|0)==145){t=(n[5520]|0)+o|0;n[5520]=t;if(t>>>0>(n[5521]|0)>>>0)n[5521]=t;l=n[5418]|0;e:do{if(l){t=22096;while(1){e=n[t>>2]|0;s=n[t+4>>2]|0;if((A|0)==(e+s|0)){g=154;break}i=n[t+8>>2]|0;if(!i)break;else t=i}if(((g|0)==154?(y=t+4|0,(n[t+12>>2]&8|0)==0):0)?A>>>0>l>>>0&e>>>0<=l>>>0:0){n[y>>2]=s+o;B=(n[5415]|0)+o|0;b=l+8|0;b=(b&7|0)==0?0:0-b&7;y=l+b|0;b=B-b|0;n[5418]=y;n[5415]=b;n[y+4>>2]=b|1;n[l+B+4>>2]=40;n[5419]=n[5534];break}if(A>>>0<(n[5416]|0)>>>0)n[5416]=A;s=A+o|0;t=22096;while(1){if((n[t>>2]|0)==(s|0)){g=162;break}e=n[t+8>>2]|0;if(!e)break;else t=e}if((g|0)==162?(n[t+12>>2]&8|0)==0:0){n[t>>2]=A;h=t+4|0;n[h>>2]=(n[h>>2]|0)+o;h=A+8|0;h=A+((h&7|0)==0?0:0-h&7)|0;t=s+8|0;t=s+((t&7|0)==0?0:0-t&7)|0;c=h+u|0;a=t-h-u|0;n[h+4>>2]=u|3;t:do{if((l|0)==(t|0)){B=(n[5415]|0)+a|0;n[5415]=B;n[5418]=c;n[c+4>>2]=B|1}else{if((n[5417]|0)==(t|0)){B=(n[5414]|0)+a|0;n[5414]=B;n[5417]=c;n[c+4>>2]=B|1;n[c+B>>2]=B;break}e=n[t+4>>2]|0;if((e&3|0)==1){o=e&-8;i=e>>>3;s:do{if(e>>>0<256){e=n[t+8>>2]|0;s=n[t+12>>2]|0;if((s|0)==(e|0)){n[5412]=n[5412]&~(1<<i);break}else{n[e+12>>2]=s;n[s+8>>2]=e;break}}else{A=n[t+24>>2]|0;e=n[t+12>>2]|0;do{if((e|0)==(t|0)){s=t+16|0;i=s+4|0;e=n[i>>2]|0;if(!e){e=n[s>>2]|0;if(!e){e=0;break}}else s=i;while(1){r=e+20|0;i=n[r>>2]|0;if(!i){r=e+16|0;i=n[r>>2]|0;if(!i)break;else{e=i;s=r}}else{e=i;s=r}}n[s>>2]=0}else{B=n[t+8>>2]|0;n[B+12>>2]=e;n[e+8>>2]=B}}while(0);if(!A)break;s=n[t+28>>2]|0;i=21952+(s<<2)|0;do{if((n[i>>2]|0)!=(t|0)){B=A+16|0;n[((n[B>>2]|0)==(t|0)?B:A+20|0)>>2]=e;if(!e)break s}else{n[i>>2]=e;if(e|0)break;n[5413]=n[5413]&~(1<<s);break s}}while(0);n[e+24>>2]=A;s=t+16|0;i=n[s>>2]|0;if(i|0){n[e+16>>2]=i;n[i+24>>2]=e}s=n[s+4>>2]|0;if(!s)break;n[e+20>>2]=s;n[s+24>>2]=e}}while(0);t=t+o|0;r=o+a|0}else r=a;t=t+4|0;n[t>>2]=n[t>>2]&-2;n[c+4>>2]=r|1;n[c+r>>2]=r;t=r>>>3;if(r>>>0<256){s=21688+(t<<1<<2)|0;e=n[5412]|0;t=1<<t;if(!(e&t)){n[5412]=e|t;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=c;n[t+12>>2]=c;n[c+8>>2]=t;n[c+12>>2]=s;break}t=r>>>8;do{if(!t)i=0;else{if(r>>>0>16777215){i=31;break}y=(t+1048320|0)>>>16&8;B=t<<y;b=(B+520192|0)>>>16&4;B=B<<b;i=(B+245760|0)>>>16&2;i=14-(b|y|i)+(B<<i>>>15)|0;i=r>>>(i+7|0)&1|i<<1}}while(0);t=21952+(i<<2)|0;n[c+28>>2]=i;e=c+16|0;n[e+4>>2]=0;n[e>>2]=0;e=n[5413]|0;s=1<<i;if(!(e&s)){n[5413]=e|s;n[t>>2]=c;n[c+24>>2]=t;n[c+12>>2]=c;n[c+8>>2]=c;break}t=n[t>>2]|0;s:do{if((n[t+4>>2]&-8|0)!=(r|0)){i=r<<((i|0)==31?0:25-(i>>>1)|0);while(1){s=t+16+(i>>>31<<2)|0;e=n[s>>2]|0;if(!e)break;if((n[e+4>>2]&-8|0)==(r|0)){t=e;break s}else{i=i<<1;t=e}}n[s>>2]=c;n[c+24>>2]=t;n[c+12>>2]=c;n[c+8>>2]=c;break t}}while(0);y=t+8|0;B=n[y>>2]|0;n[B+12>>2]=c;n[y>>2]=c;n[c+8>>2]=B;n[c+12>>2]=t;n[c+24>>2]=0}}while(0);B=h+8|0;J=w;return B|0}t=22096;while(1){e=n[t>>2]|0;if(e>>>0<=l>>>0?(B=e+(n[t+4>>2]|0)|0,B>>>0>l>>>0):0)break;t=n[t+8>>2]|0}r=B+-47|0;e=r+8|0;e=r+((e&7|0)==0?0:0-e&7)|0;r=l+16|0;e=e>>>0<r>>>0?l:e;t=e+8|0;s=o+-40|0;b=A+8|0;b=(b&7|0)==0?0:0-b&7;y=A+b|0;b=s-b|0;n[5418]=y;n[5415]=b;n[y+4>>2]=b|1;n[A+s+4>>2]=40;n[5419]=n[5534];s=e+4|0;n[s>>2]=27;n[t>>2]=n[5524];n[t+4>>2]=n[5525];n[t+8>>2]=n[5526];n[t+12>>2]=n[5527];n[5524]=A;n[5525]=o;n[5527]=0;n[5526]=t;t=e+24|0;do{y=t;t=t+4|0;n[t>>2]=7}while((y+8|0)>>>0<B>>>0);if((e|0)!=(l|0)){A=e-l|0;n[s>>2]=n[s>>2]&-2;n[l+4>>2]=A|1;n[e>>2]=A;t=A>>>3;if(A>>>0<256){s=21688+(t<<1<<2)|0;e=n[5412]|0;t=1<<t;if(!(e&t)){n[5412]=e|t;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=l;n[t+12>>2]=l;n[l+8>>2]=t;n[l+12>>2]=s;break}t=A>>>8;if(t)if(A>>>0>16777215)i=31;else{y=(t+1048320|0)>>>16&8;B=t<<y;b=(B+520192|0)>>>16&4;B=B<<b;i=(B+245760|0)>>>16&2;i=14-(b|y|i)+(B<<i>>>15)|0;i=A>>>(i+7|0)&1|i<<1}else i=0;s=21952+(i<<2)|0;n[l+28>>2]=i;n[l+20>>2]=0;n[r>>2]=0;t=n[5413]|0;e=1<<i;if(!(t&e)){n[5413]=t|e;n[s>>2]=l;n[l+24>>2]=s;n[l+12>>2]=l;n[l+8>>2]=l;break}t=n[s>>2]|0;t:do{if((n[t+4>>2]&-8|0)!=(A|0)){i=A<<((i|0)==31?0:25-(i>>>1)|0);while(1){s=t+16+(i>>>31<<2)|0;e=n[s>>2]|0;if(!e)break;if((n[e+4>>2]&-8|0)==(A|0)){t=e;break t}else{i=i<<1;t=e}}n[s>>2]=l;n[l+24>>2]=t;n[l+12>>2]=l;n[l+8>>2]=l;break e}}while(0);y=t+8|0;B=n[y>>2]|0;n[B+12>>2]=l;n[y>>2]=l;n[l+8>>2]=B;n[l+12>>2]=t;n[l+24>>2]=0}}else{B=n[5416]|0;if((B|0)==0|A>>>0<B>>>0)n[5416]=A;n[5524]=A;n[5525]=o;n[5527]=0;n[5421]=n[5530];n[5420]=-1;n[5425]=21688;n[5424]=21688;n[5427]=21696;n[5426]=21696;n[5429]=21704;n[5428]=21704;n[5431]=21712;n[5430]=21712;n[5433]=21720;n[5432]=21720;n[5435]=21728;n[5434]=21728;n[5437]=21736;n[5436]=21736;n[5439]=21744;n[5438]=21744;n[5441]=21752;n[5440]=21752;n[5443]=21760;n[5442]=21760;n[5445]=21768;n[5444]=21768;n[5447]=21776;n[5446]=21776;n[5449]=21784;n[5448]=21784;n[5451]=21792;n[5450]=21792;n[5453]=21800;n[5452]=21800;n[5455]=21808;n[5454]=21808;n[5457]=21816;n[5456]=21816;n[5459]=21824;n[5458]=21824;n[5461]=21832;n[5460]=21832;n[5463]=21840;n[5462]=21840;n[5465]=21848;n[5464]=21848;n[5467]=21856;n[5466]=21856;n[5469]=21864;n[5468]=21864;n[5471]=21872;n[5470]=21872;n[5473]=21880;n[5472]=21880;n[5475]=21888;n[5474]=21888;n[5477]=21896;n[5476]=21896;n[5479]=21904;n[5478]=21904;n[5481]=21912;n[5480]=21912;n[5483]=21920;n[5482]=21920;n[5485]=21928;n[5484]=21928;n[5487]=21936;n[5486]=21936;B=o+-40|0;b=A+8|0;b=(b&7|0)==0?0:0-b&7;y=A+b|0;b=B-b|0;n[5418]=y;n[5415]=b;n[y+4>>2]=b|1;n[A+B+4>>2]=40;n[5419]=n[5534]}}while(0);t=n[5415]|0;if(t>>>0>u>>>0){b=t-u|0;n[5415]=b;B=n[5418]|0;y=B+u|0;n[5418]=y;n[y+4>>2]=b|1;n[B+4>>2]=u|3;B=B+8|0;J=w;return B|0}}n[(zd()|0)>>2]=48;B=0;J=w;return B|0}function Zg(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0;if(!e)return;s=e+-8|0;r=n[5416]|0;e=n[e+-4>>2]|0;t=e&-8;l=s+t|0;do{if(!(e&1)){i=n[s>>2]|0;if(!(e&3))return;o=s+(0-i)|0;A=i+t|0;if(o>>>0<r>>>0)return;if((n[5417]|0)==(o|0)){e=l+4|0;t=n[e>>2]|0;if((t&3|0)!=3){a=o;t=A;break}n[5414]=A;n[e>>2]=t&-2;n[o+4>>2]=A|1;n[o+A>>2]=A;return}s=i>>>3;if(i>>>0<256){e=n[o+8>>2]|0;t=n[o+12>>2]|0;if((t|0)==(e|0)){n[5412]=n[5412]&~(1<<s);a=o;t=A;break}else{n[e+12>>2]=t;n[t+8>>2]=e;a=o;t=A;break}}r=n[o+24>>2]|0;e=n[o+12>>2]|0;do{if((e|0)==(o|0)){t=o+16|0;s=t+4|0;e=n[s>>2]|0;if(!e){e=n[t>>2]|0;if(!e){e=0;break}}else t=s;while(1){i=e+20|0;s=n[i>>2]|0;if(!s){i=e+16|0;s=n[i>>2]|0;if(!s)break;else{e=s;t=i}}else{e=s;t=i}}n[t>>2]=0}else{a=n[o+8>>2]|0;n[a+12>>2]=e;n[e+8>>2]=a}}while(0);if(r){t=n[o+28>>2]|0;s=21952+(t<<2)|0;if((n[s>>2]|0)==(o|0)){n[s>>2]=e;if(!e){n[5413]=n[5413]&~(1<<t);a=o;t=A;break}}else{a=r+16|0;n[((n[a>>2]|0)==(o|0)?a:r+20|0)>>2]=e;if(!e){a=o;t=A;break}}n[e+24>>2]=r;t=o+16|0;s=n[t>>2]|0;if(s|0){n[e+16>>2]=s;n[s+24>>2]=e}t=n[t+4>>2]|0;if(t){n[e+20>>2]=t;n[t+24>>2]=e;a=o;t=A}else{a=o;t=A}}else{a=o;t=A}}else{a=s;o=s}}while(0);if(o>>>0>=l>>>0)return;e=l+4|0;i=n[e>>2]|0;if(!(i&1))return;if(!(i&2)){if((n[5418]|0)==(l|0)){l=(n[5415]|0)+t|0;n[5415]=l;n[5418]=a;n[a+4>>2]=l|1;if((a|0)!=(n[5417]|0))return;n[5417]=0;n[5414]=0;return}if((n[5417]|0)==(l|0)){l=(n[5414]|0)+t|0;n[5414]=l;n[5417]=o;n[a+4>>2]=l|1;n[o+l>>2]=l;return}r=(i&-8)+t|0;s=i>>>3;do{if(i>>>0<256){t=n[l+8>>2]|0;e=n[l+12>>2]|0;if((e|0)==(t|0)){n[5412]=n[5412]&~(1<<s);break}else{n[t+12>>2]=e;n[e+8>>2]=t;break}}else{A=n[l+24>>2]|0;e=n[l+12>>2]|0;do{if((e|0)==(l|0)){t=l+16|0;s=t+4|0;e=n[s>>2]|0;if(!e){e=n[t>>2]|0;if(!e){s=0;break}}else t=s;while(1){i=e+20|0;s=n[i>>2]|0;if(!s){i=e+16|0;s=n[i>>2]|0;if(!s)break;else{e=s;t=i}}else{e=s;t=i}}n[t>>2]=0;s=e}else{s=n[l+8>>2]|0;n[s+12>>2]=e;n[e+8>>2]=s;s=e}}while(0);if(A|0){e=n[l+28>>2]|0;t=21952+(e<<2)|0;if((n[t>>2]|0)==(l|0)){n[t>>2]=s;if(!s){n[5413]=n[5413]&~(1<<e);break}}else{i=A+16|0;n[((n[i>>2]|0)==(l|0)?i:A+20|0)>>2]=s;if(!s)break}n[s+24>>2]=A;e=l+16|0;t=n[e>>2]|0;if(t|0){n[s+16>>2]=t;n[t+24>>2]=s}e=n[e+4>>2]|0;if(e|0){n[s+20>>2]=e;n[e+24>>2]=s}}}}while(0);n[a+4>>2]=r|1;n[o+r>>2]=r;if((a|0)==(n[5417]|0)){n[5414]=r;return}}else{n[e>>2]=i&-2;n[a+4>>2]=t|1;n[o+t>>2]=t;r=t}e=r>>>3;if(r>>>0<256){s=21688+(e<<1<<2)|0;t=n[5412]|0;e=1<<e;if(!(t&e)){n[5412]=t|e;e=s;t=s+8|0}else{t=s+8|0;e=n[t>>2]|0}n[t>>2]=a;n[e+12>>2]=a;n[a+8>>2]=e;n[a+12>>2]=s;return}e=r>>>8;if(e)if(r>>>0>16777215)i=31;else{o=(e+1048320|0)>>>16&8;l=e<<o;A=(l+520192|0)>>>16&4;l=l<<A;i=(l+245760|0)>>>16&2;i=14-(A|o|i)+(l<<i>>>15)|0;i=r>>>(i+7|0)&1|i<<1}else i=0;e=21952+(i<<2)|0;n[a+28>>2]=i;n[a+20>>2]=0;n[a+16>>2]=0;t=n[5413]|0;s=1<<i;e:do{if(!(t&s)){n[5413]=t|s;n[e>>2]=a;n[a+24>>2]=e;n[a+12>>2]=a;n[a+8>>2]=a}else{e=n[e>>2]|0;t:do{if((n[e+4>>2]&-8|0)!=(r|0)){i=r<<((i|0)==31?0:25-(i>>>1)|0);while(1){s=e+16+(i>>>31<<2)|0;t=n[s>>2]|0;if(!t)break;if((n[t+4>>2]&-8|0)==(r|0)){e=t;break t}else{i=i<<1;e=t}}n[s>>2]=a;n[a+24>>2]=e;n[a+12>>2]=a;n[a+8>>2]=a;break e}}while(0);o=e+8|0;l=n[o>>2]|0;n[l+12>>2]=a;n[o>>2]=a;n[a+8>>2]=l;n[a+12>>2]=e;n[a+24>>2]=0}}while(0);l=(n[5420]|0)+-1|0;n[5420]=l;if(l|0)return;e=22104;while(1){e=n[e>>2]|0;if(!e)break;else e=e+8|0}n[5420]=-1;return}function Jg(e){e=e|0;var t=0,s=0,i=0;i=e+3&-4;e=lm()|0;t=n[e>>2]|0;s=t+i|0;do{if((i|0)<1|s>>>0>t>>>0){if(s>>>0>(W()|0)>>>0?(K(s|0)|0)==0:0)break;n[e>>2]=s;i=t;return i|0}}while(0);n[(zd()|0)>>2]=48;i=-1;return i|0}function Yg(e){e=e|0;var t=0;t=J;J=J+e|0;J=J+15&-16;return t|0}function $g(e){e=e|0;J=e}function qg(){return J|0}function em(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,n=0;n=e&65535;r=t&65535;s=b(r,n)|0;i=e>>>16;e=(s>>>16)+(b(r,i)|0)|0;r=t>>>16;t=b(r,n)|0;return(w((e>>>16)+(b(r,i)|0)+(((e&65535)+t|0)>>>16)|0),e+t<<16|s&65535|0)|0}function tm(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,n=0;r=e;n=s;s=em(r,n)|0;e=v()|0;return(w((b(t,n)|0)+(b(i,r)|0)+e|e&0|0),s|0|0)|0}function sm(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;s=e+s>>>0;return(w(t+i+(s>>>0<e>>>0|0)>>>0|0),s|0)|0}function im(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;i=t-i-(s>>>0>e>>>0|0)>>>0;return(w(i|0),e-s>>>0|0)|0}function rm(e){e=e|0;return(e?31-(y(e^e-1)|0)|0:32)|0}function nm(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0;h=e;l=t;c=l;o=s;d=i;a=d;if(!c){A=(r|0)!=0;if(!a){if(A){n[r>>2]=(h>>>0)%(o>>>0);n[r+4>>2]=0}d=0;r=(h>>>0)/(o>>>0)>>>0;return(w(d|0),r)|0}else{if(!A){d=0;r=0;return(w(d|0),r)|0}n[r>>2]=e|0;n[r+4>>2]=t&0;d=0;r=0;return(w(d|0),r)|0}}A=(a|0)==0;do{if(o){if(!A){A=(y(a|0)|0)-(y(c|0)|0)|0;if(A>>>0<=31){u=A+1|0;a=31-A|0;t=A-31>>31;o=u;e=h>>>(u>>>0)&t|c<<a;t=c>>>(u>>>0)&t;A=0;a=h<<a;break}if(!r){d=0;r=0;return(w(d|0),r)|0}n[r>>2]=e|0;n[r+4>>2]=l|t&0;d=0;r=0;return(w(d|0),r)|0}A=o-1|0;if(A&o|0){a=(y(o|0)|0)+33-(y(c|0)|0)|0;f=64-a|0;u=32-a|0;l=u>>31;p=a-32|0;t=p>>31;o=a;e=u-1>>31&c>>>(p>>>0)|(c<<u|h>>>(a>>>0))&t;t=t&c>>>(a>>>0);A=h<<f&l;a=(c<<f|h>>>(p>>>0))&l|h<<u&a-33>>31;break}if(r|0){n[r>>2]=A&h;n[r+4>>2]=0}if((o|0)==1){p=l|t&0;f=e|0|0;return(w(p|0),f)|0}else{f=rm(o|0)|0;p=c>>>(f>>>0)|0;f=c<<32-f|h>>>(f>>>0)|0;return(w(p|0),f)|0}}else{if(A){if(r|0){n[r>>2]=(c>>>0)%(o>>>0);n[r+4>>2]=0}p=0;f=(c>>>0)/(o>>>0)>>>0;return(w(p|0),f)|0}if(!h){if(r|0){n[r>>2]=0;n[r+4>>2]=(c>>>0)%(a>>>0)}p=0;f=(c>>>0)/(a>>>0)>>>0;return(w(p|0),f)|0}A=a-1|0;if(!(A&a)){if(r|0){n[r>>2]=e|0;n[r+4>>2]=A&c|t&0}p=0;f=c>>>((rm(a|0)|0)>>>0);return(w(p|0),f)|0}A=(y(a|0)|0)-(y(c|0)|0)|0;if(A>>>0<=30){t=A+1|0;a=31-A|0;o=t;e=c<<a|h>>>(t>>>0);t=c>>>(t>>>0);A=0;a=h<<a;break}if(!r){p=0;f=0;return(w(p|0),f)|0}n[r>>2]=e|0;n[r+4>>2]=l|t&0;p=0;f=0;return(w(p|0),f)|0}}while(0);if(!o){c=a;l=0;a=0}else{u=s|0|0;h=d|i&0;c=sm(u|0,h|0,-1,-1)|0;s=v()|0;l=a;a=0;do{i=l;l=A>>>31|l<<1;A=a|A<<1;i=e<<1|i>>>31|0;d=e>>>31|t<<1|0;im(c|0,s|0,i|0,d|0)|0;f=v()|0;p=f>>31|((f|0)<0?-1:0)<<1;a=p&1;e=im(i|0,d|0,p&u|0,(((f|0)<0?-1:0)>>31|((f|0)<0?-1:0)<<1)&h|0)|0;t=v()|0;o=o-1|0}while((o|0)!=0);c=l;l=0}o=0;if(r|0){n[r>>2]=e;n[r+4>>2]=t}p=(A|0)>>>31|(c|o)<<1|(o<<1|A>>>31)&0|l;f=(A<<1|0>>>31)&-2|a;return(w(p|0),f)|0}function Am(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;return nm(e,t,s,i,0)|0}function om(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)<32){w(t>>>s|0);return e>>>s|(t&(1<<s)-1)<<32-s}w(0);return t>>>s-32|0}function am(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)<32){w(t<<s|(e&(1<<s)-1<<32-s)>>>32-s|0);return e<<s}w(e<<s-32|0);return 0}function lm(){return 22176}function cm(e){e=e|0;return(e&255)<<24|(e>>8&255)<<16|(e>>16&255)<<8|e>>>24|0}function hm(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;if((s|0)>=512){X(e|0,t|0,s|0)|0;return e|0}o=e|0;A=e+s|0;if((e&3)==(t&3)){while(e&3){if(!s)return o|0;i[e>>0]=i[t>>0]|0;e=e+1|0;t=t+1|0;s=s-1|0}s=A&-4|0;r=s-64|0;while((e|0)<=(r|0)){n[e>>2]=n[t>>2];n[e+4>>2]=n[t+4>>2];n[e+8>>2]=n[t+8>>2];n[e+12>>2]=n[t+12>>2];n[e+16>>2]=n[t+16>>2];n[e+20>>2]=n[t+20>>2];n[e+24>>2]=n[t+24>>2];n[e+28>>2]=n[t+28>>2];n[e+32>>2]=n[t+32>>2];n[e+36>>2]=n[t+36>>2];n[e+40>>2]=n[t+40>>2];n[e+44>>2]=n[t+44>>2];n[e+48>>2]=n[t+48>>2];n[e+52>>2]=n[t+52>>2];n[e+56>>2]=n[t+56>>2];n[e+60>>2]=n[t+60>>2];e=e+64|0;t=t+64|0}while((e|0)<(s|0)){n[e>>2]=n[t>>2];e=e+4|0;t=t+4|0}}else{s=A-4|0;while((e|0)<(s|0)){i[e>>0]=i[t>>0]|0;i[e+1>>0]=i[t+1>>0]|0;i[e+2>>0]=i[t+2>>0]|0;i[e+3>>0]=i[t+3>>0]|0;e=e+4|0;t=t+4|0}}while((e|0)<(A|0)){i[e>>0]=i[t>>0]|0;e=e+1|0;t=t+1|0}return o|0}function um(e,t,s){e=e|0;t=t|0;s=s|0;var r=0;if((t|0)<(e|0)&(e|0)<(t+s|0)){r=e;t=t+s|0;e=e+s|0;while((s|0)>0){e=e-1|0;t=t-1|0;s=s-1|0;i[e>>0]=i[t>>0]|0}e=r}else hm(e,t,s)|0;return e|0}function dm(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0;o=e+s|0;t=t&255;if((s|0)>=67){while(e&3){i[e>>0]=t;e=e+1|0}r=o&-4|0;a=t|t<<8|t<<16|t<<24;A=r-64|0;while((e|0)<=(A|0)){n[e>>2]=a;n[e+4>>2]=a;n[e+8>>2]=a;n[e+12>>2]=a;n[e+16>>2]=a;n[e+20>>2]=a;n[e+24>>2]=a;n[e+28>>2]=a;n[e+32>>2]=a;n[e+36>>2]=a;n[e+40>>2]=a;n[e+44>>2]=a;n[e+48>>2]=a;n[e+52>>2]=a;n[e+56>>2]=a;n[e+60>>2]=a;e=e+64|0}while((e|0)<(r|0)){n[e>>2]=a;e=e+4|0}}while((e|0)<(o|0)){i[e>>0]=t;e=e+1|0}return o-s|0}function pm(e){e=e|0;return Om[e&3]()|0}function fm(e,t){e=e|0;t=t|0;return Vm[e&15](t|0)|0}function gm(e,t,s,i,r,n,A){e=e|0;t=t|0;s=+s;i=i|0;r=r|0;n=n|0;A=A|0;return Lm[e&1](t|0,+s,i|0,r|0,n|0,A|0)|0}function mm(e,t,s){e=e|0;t=t|0;s=s|0;return Hm[e&63](t|0,s|0)|0}function _m(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;return Nm[e&7](t|0,s|0,i|0)|0}function bm(e){e=e|0;Gm[e&3]()}function ym(e,t){e=e|0;t=t|0;jm[e&255](t|0)}function Bm(e,t,s){e=e|0;t=t|0;s=s|0;zm[e&15](t|0,s|0)}function wm(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;Wm[e&15](t|0,s|0,i|0)}function vm(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;Xm[e&7](t|0,s|0,i|0,r|0)}function Cm(e,t,s,i,r,n){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;n=n|0;Km[e&3](t|0,s|0,i|0,r|0,n|0)}function Mm(e,t,s,i,r,n,A){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;n=n|0;A=A|0;Zm[e&3](t|0,s|0,i|0,r|0,n|0,A|0)}function Em(){B(0);return 0}function Fm(e){e=e|0;B(1);return 0}function xm(e,t,s,i,r,n){e=e|0;t=+t;s=s|0;i=i|0;r=r|0;n=n|0;B(2);return 0}function Um(e,t){e=e|0;t=t|0;B(3);return 0}function Im(e,t,s){e=e|0;t=t|0;s=s|0;B(4);return 0}function Tm(){B(5)}function Pm(e){e=e|0;B(6)}function Sm(e,t){e=e|0;t=t|0;B(7)}function Dm(e,t,s){e=e|0;t=t|0;s=s|0;B(8)}function km(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;B(9)}function Qm(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;B(10)}function Rm(e,t,s,i,r,n){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;n=n|0;B(11)}var Om=[Em,Ic,vh,Em];var Vm=[Fm,mf,gt,wt,of,cf,ng,Fg,Qg,pc,re,hh,Pc,Mh,Fm,Fm];var Lm=[xm,np];var Hm=[Um,_e,Fe,Bt,ei,Ii,Li,er,tr,rr,Gr,Jr,fn,wn,Tn,On,CA,SA,NA,XA,so,oo,mo,wo,To,jo,Yo,sa,ca,ba,Qa,Ga,Ya,Al,gl,vl,Sl,Nl,Jl,ic,hc,ih,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um];var Nm=[Im,Cp,Lp,wf,Cf,Ug,Ig,Im];var Gm=[Tm,yf,Tp,Tm];var jm=[Pm,Ag,ge,me,be,Me,Ee,xe,ff,nt,vt,ft,_t,bt,xt,Ut,Lt,Ht,ls,cs,hs,Is,$s,qs,ti,Ei,Ti,Pi,Si,Di,Oi,Vi,Hi,$i,qi,sr,ir,Hr,Nr,jr,Kr,Zr,dn,pn,gn,yn,Bn,Un,In,Pn,Qn,Rn,wA,vA,MA,DA,kA,LA,HA,GA,KA,ZA,eo,to,io,ao,lo,fo,go,_o,vo,Co,Uo,Io,Po,No,Go,zo,Zo,Jo,$o,ia,ra,aa,la,ha,ma,_a,Da,ka,Ra,Ha,Na,Za,Ja,$a,rl,nl,pl,fl,ml,Bl,wl,Tl,Pl,Dl,Ll,Hl,Kl,Zl,Yl,tc,sc,lc,cc,uc,Qp,Rp,Op,Vp,Zp,nf,Af,af,lf,gf,_f,bf,Bf,vf,xf,ig,rg,Mg,Eg,kg,Hg,Ng,mc,ph,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm];var zm=[Sm,mt,yt,ie,Ae,oe,ae,le,Ap,Sm,Sm,Sm,Sm,Sm,Sm,Sm];var Wm=[Dm,xg,Tg,Rg,Og,se,ne,Zc,Vh,zh,Dm,Dm,Dm,Dm,Dm,Dm];var Xm=[km,Gp,$p,Tf,Vc,Ph,km,km];var Km=[Qm,Np,Yp,If];var Zm=[Rm,Hp,Jp,Uf];return{__ZSt18uncaught_exceptionv:tg,___cxa_can_catch:$f,___cxa_is_pointer_type:qf,___embind_register_native_and_builtin_types:eu,___errno_location:zd,___getTypeName:jd,___muldi3:tm,___udivdi3:Am,_bitshift64Lshr:om,_bitshift64Shl:am,_emscripten_get_sbrk_ptr:lm,_free:Zg,_i64Add:sm,_i64Subtract:im,_llvm_bswap_i32:cm,_malloc:Kg,_memcpy:hm,_memmove:um,_memset:dm,dynCall_i:pm,dynCall_ii:fm,dynCall_iidiiii:gm,dynCall_iii:mm,dynCall_iiii:_m,dynCall_v:bm,dynCall_vi:ym,dynCall_vii:Bm,dynCall_viii:wm,dynCall_viiii:vm,dynCall_viiiii:Cm,dynCall_viiiiii:Mm,globalCtors:q,stackAlloc:Yg,stackRestore:$g,stackSave:qg}}({Math:Math,Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array,Float32Array:Float32Array,Float64Array:Float64Array},ut,y),pt=t.__ZSt18uncaught_exceptionv=dt.__ZSt18uncaught_exceptionv;t.___cxa_can_catch=dt.___cxa_can_catch,t.___cxa_is_pointer_type=dt.___cxa_is_pointer_type,t.___embind_register_native_and_builtin_types=dt.___embind_register_native_and_builtin_types,t.___errno_location=dt.___errno_location;var ft=t.___getTypeName=dt.___getTypeName;t.___muldi3=dt.___muldi3,t.___udivdi3=dt.___udivdi3,t._bitshift64Lshr=dt._bitshift64Lshr,t._bitshift64Shl=dt._bitshift64Shl,t._emscripten_get_sbrk_ptr=dt._emscripten_get_sbrk_ptr;var gt=t._free=dt._free;t._i64Add=dt._i64Add,t._i64Subtract=dt._i64Subtract,t._llvm_bswap_i32=dt._llvm_bswap_i32;var mt=t._malloc=dt._malloc;t._memcpy=dt._memcpy,t._memmove=dt._memmove,t._memset=dt._memset;var _t,bt,yt=t.globalCtors=dt.globalCtors;if(t.stackAlloc=dt.stackAlloc,t.stackRestore=dt.stackRestore,t.stackSave=dt.stackSave,t.dynCall_i=dt.dynCall_i,t.dynCall_ii=dt.dynCall_ii,t.dynCall_iidiiii=dt.dynCall_iidiiii,t.dynCall_iii=dt.dynCall_iii,t.dynCall_iiii=dt.dynCall_iiii,t.dynCall_v=dt.dynCall_v,t.dynCall_vi=dt.dynCall_vi,t.dynCall_vii=dt.dynCall_vii,t.dynCall_viii=dt.dynCall_viii,t.dynCall_viiii=dt.dynCall_viiii,t.dynCall_viiiii=dt.dynCall_viiiii,t.dynCall_viiiiii=dt.dynCall_viiiiii,t.asm=dt,W)if(K(W)||(_t=W,W=t.locateFile?t.locateFile(_t,u):u+_t),n||A){var Bt=l(W);w.set(Bt,8)}else{G++,t.monitorRunDependencies&&t.monitorRunDependencies(G);var wt=function(e){e.byteLength&&(e=new Uint8Array(e)),w.set(e,8),t.memoryInitializerRequest&&delete t.memoryInitializerRequest.response,function(e){if(G--,t.monitorRunDependencies&&t.monitorRunDependencies(G),0==G&&j){var s=j;j=null,s()}}()},vt=function(){a(W,wt,(function(){throw new Error("could not load memory initializer "+W)}))},Ct=ht(W);if(Ct)wt(Ct.buffer);else if(t.memoryInitializerRequest){var Mt=function(){var e=t.memoryInitializerRequest,s=e.response;if(200!==e.status&&0!==e.status){var i=ht(t.memoryInitializerRequestURL);if(!i)return console.warn("a problem seems to have happened with Module.memoryInitializerRequest, status: "+e.status+", retrying "+W),void vt();s=i.buffer}wt(s)};t.memoryInitializerRequest.response?setTimeout(Mt,0):t.memoryInitializerRequest.addEventListener("load",Mt)}else vt()}function Et(e){this.name="ExitStatus",this.message="Program terminated with exit("+e+")",this.status=e}function Ft(e){function s(){bt||(bt=!0,t.calledRun=!0,g||(O(L),O(H),t.onRuntimeInitialized&&t.onRuntimeInitialized(),function(){if(t.postRun)for("function"==typeof t.postRun&&(t.postRun=[t.postRun]);t.postRun.length;)e=t.postRun.shift(),N.unshift(e);var e;O(N)}()))}G>0||(!function(){if(t.preRun)for("function"==typeof t.preRun&&(t.preRun=[t.preRun]);t.preRun.length;)e=t.preRun.shift(),V.unshift(e);var e;O(V)}(),G>0||(t.setStatus?(t.setStatus("Running..."),setTimeout((function(){setTimeout((function(){t.setStatus("")}),1),s()}),1)):s()))}if(j=function e(){bt||Ft(),bt||(j=e)},t.run=Ft,t.preInit)for("function"==typeof t.preInit&&(t.preInit=[t.preInit]);t.preInit.length>0;)t.preInit.pop()();return Ft(),t}let Mu=null;const Eu={0:e=>({position:[e.getInt32(0,!0),e.getInt32(4,!0),e.getInt32(8,!0)],intensity:e.getUint16(12,!0),classification:e.getUint8(15)}),1:e=>({position:[e.getInt32(0,!0),e.getInt32(4,!0),e.getInt32(8,!0)],intensity:e.getUint16(12,!0),classification:e.getUint8(15)}),2:e=>({position:[e.getInt32(0,!0),e.getInt32(4,!0),e.getInt32(8,!0)],intensity:e.getUint16(12,!0),classification:e.getUint8(15),color:[e.getUint16(20,!0),e.getUint16(22,!0),e.getUint16(24,!0)]}),3:e=>({position:[e.getInt32(0,!0),e.getInt32(4,!0),e.getInt32(8,!0)],intensity:e.getUint16(12,!0),classification:e.getUint8(15),color:[e.getUint16(28,!0),e.getUint16(30,!0),e.getUint16(32,!0)]})};function Fu(e,t={},s,i){i=void 0===i||0===i?1:i;const r=new t(e.slice(s,s+t.BYTES_PER_ELEMENT*i));if(1===i)return r[0];const n=[];for(let e=0;e<i;e++)n.push(r[e]);return n}function xu(e){let t=131;const s={pointsOffset:Fu(e,Uint32Array,96),pointsFormatId:Fu(e,Uint8Array,104),pointsStructSize:Fu(e,Uint16Array,105),pointsCount:Fu(e,Uint32Array,107),scale:Fu(e,Float64Array,t,3)};t+=24,s.offset=Fu(e,Float64Array,t,3),t+=24;const i=Fu(e,Float64Array,t,6);return t+=48,s.maxs=[i[0],i[2],i[4]],s.mins=[i[1],i[3],i[5]],s}class Uu{arraybuffer;readOffset=0;header={pointsOffset:0,pointsFormatId:0,pointsStructSize:0,pointsCount:0,scale:[0,0,0],offset:[0,0,0],maxs:[0],mins:[0],totalToRead:0,totalRead:0,versionAsString:"",isCompressed:!0};constructor(e){this.arraybuffer=e}open(){return!0}getHeader(){return this.header=xu(this.arraybuffer),this.header}readData(e,t){const{header:s,arraybuffer:i}=this;if(!s)throw new Error("Cannot start reading data till a header request is issued");let r,{readOffset:n}=this;if(t<=1){e=Math.min(e,s.pointsCount-n),r=s.pointsOffset+n*s.pointsStructSize;const t=r+e*s.pointsStructSize;return n+=e,this.readOffset=n,{buffer:i.slice(r,t),count:e,hasMoreData:n<s.pointsCount}}const A=Math.min(e*t,s.pointsCount-n),o=Math.ceil(A/t);let a=0;const l=new Uint8Array(o*s.pointsStructSize);for(let e=0;e<A;e++){if(e%t==0){r=s.pointsOffset+n*s.pointsStructSize;const e=new Uint8Array(i,r,s.pointsStructSize);l.set(e,a*s.pointsStructSize),a++}n++}return this.readOffset=n,{buffer:l.buffer,count:a,hasMoreData:n<s.pointsCount}}close(){return this.arraybuffer=null,!0}}class Iu{arraybuffer;instance=null;header=null;constructor(e){this.arraybuffer=e,Mu||(Mu=Cu())}open(){try{const{arraybuffer:e}=this;this.instance=new Mu.LASZip;const t=new Uint8Array(e),s=Mu._malloc(e.byteLength);return this.instance.arraybuffer=e,this.instance.buf=s,Mu.HEAPU8.set(t,s),this.instance.open(s,e.byteLength),this.instance.readOffset=0,!0}catch(e){throw new Error(`Failed to open file: ${e.message}`)}}getHeader(){if(!this.instance)throw new Error("You need to open the file before trying to read header");try{const e=xu(this.instance.arraybuffer);return e.pointsFormatId&=63,this.header=e,e}catch(e){throw new Error(`Failed to get header: ${e.message}`)}}readData(e,t,s){if(!this.instance)throw new Error("You need to open the file before trying to read stuff");const{header:i,instance:r}=this;if(!i)throw new Error("You need to query header before reading, I maintain state that way, sorry :(");try{const t=Math.min(e*s,i.pointsCount-r.readOffset),n=Math.ceil(t/s);let A=0;const o=new Uint8Array(n*i.pointsStructSize),a=Mu._malloc(i.pointsStructSize);for(let e=0;e<t;e++){if(r.getPoint(a),e%s==0){const e=new Uint8Array(Mu.HEAPU8.buffer,a,i.pointsStructSize);o.set(e,A*i.pointsStructSize),A++}r.readOffset++}return Mu._free(a),{buffer:o.buffer,count:A,hasMoreData:r.readOffset<i.pointsCount}}catch(e){throw new Error(`Failed to read data: ${e.message}`)}}close(){try{return null!==this.instance&&(Mu._free(this.instance.buf),this.instance.delete(),this.instance=null),!0}catch(e){throw new Error(`Failed to close file: ${e.message}`)}}}class Tu{arrayb;decoder;pointsCount;pointSize;scale;offset;mins;maxs;constructor(e,t,s){this.arrayb=e,this.decoder=Eu[s.pointsFormatId],this.pointsCount=t,this.pointSize=s.pointsStructSize,this.scale=s.scale,this.offset=s.offset,this.mins=s.mins,this.maxs=s.maxs}getPoint(e){if(e<0||e>=this.pointsCount)throw new Error("Point index out of range");const t=new DataView(this.arrayb,e*this.pointSize,this.pointSize);return this.decoder(t)}}class Pu{arraybuffer;formatId=0;loader;isCompressed=!0;isOpen=!1;version=0;versionAsString="";constructor(e){if(this.arraybuffer=e,this.determineVersion()>13)throw new Error("Only file versions <= 1.3 are supported at this time");if(this.determineFormat(),void 0===Eu[this.formatId])throw new Error("The point format ID is not supported");this.loader=this.isCompressed?new Iu(this.arraybuffer):new Uu(this.arraybuffer)}determineFormat(){const e=Fu(this.arraybuffer,Uint8Array,104),t=(128&e)>>7,s=(64&e)>>6;if(1===t&&1===s)throw new Error("Old style compression not supported");this.formatId=63&e,this.isCompressed=1===t||1===s}determineVersion(){const e=new Int8Array(this.arraybuffer,24,2);return this.version=10*e[0]+e[1],this.versionAsString=`${e[0]}.${e[1]}`,this.version}open(){this.loader.open()&&(this.isOpen=!0)}getHeader(){return this.loader.getHeader()}readData(e,t,s){return this.loader.readData(e,t,s)}close(){this.loader.close()&&(this.isOpen=!1)}getUnpacker(){return Tu}}function Su(e,t){const s=function(e){const t={};t.las_pointsOffset=e.pointsOffset.toString(10),t.las_pointsFormatId=e.pointsFormatId.toString(10),t.las_pointsStructSize=e.pointsStructSize.toString(10),t.las_pointsCount=e.pointsCount.toString(10),t.las_scale=JSON.stringify(e.scale),t.las_offset=JSON.stringify(e.offset),void 0!==e.maxs&&(t.las_maxs=JSON.stringify(e.maxs));void 0!==e.mins&&(t.las_mins=JSON.stringify(e.mins));t.las_totalToRead=e.totalToRead.toString(10),t.las_pointsFortotalReadmatId=e.totalRead.toString(10),void 0!==e.versionAsString&&(t.las_versionAsString=e.versionAsString);void 0!==e.isCompressed&&(t.las_isCompressed=e.isCompressed.toString());return t}(e);return Al(t,s)}function Du(e,t){return function(e,t={}){let s,i,r,n,A,o=0;const a={loader:"las",loaderData:{},schema:{fields:[],metadata:{}},header:{vertexCount:0,boundingBox:[[0,0,0],[0,0,0]]},attributes:{},topology:"point-list",mode:0};(function(e,t,s={}){const i=new Pu(e);try{i.open();const e=i.getHeader(),r=i.getUnpacker(),n=Math.ceil(e.pointsCount/Math.max(1,t));e.totalToRead=n;let A=0;for(;;){const o=i.readData(1e5,0,t);A+=o.count,e.totalRead=A,e.versionAsString=o.versionAsString,e.isCompressed=o.isCompressed;if(s(new r(o.buffer,o.count,e),e),!o.hasMoreData||A>=n)break}}catch(e){throw e}finally{i.close()}})(e,t.las?.skip,((e={},l)=>{if(!A){A=l;const e=l.totalToRead,o=t.las?.fp64?Float64Array:Float32Array;s=new o(3*e),i=l.pointsFormatId>=2?new Uint8Array(4*e):null,r=new Uint16Array(e),n=new Uint8Array(e),a.loaderData=l,a.attributes={POSITION:{value:s,size:3},intensity:{value:r,size:1},classification:{value:n,size:1}},i&&(a.attributes.COLOR_0={value:i,size:4})}const c=e.pointsCount,{scale:[h,u,d],offset:[p,f,g]}=l,m=function(e={},t,s){let i=!1;switch(s){case 8:i=!1;break;case 16:i=!0;break;case"auto":if(e.getPoint(0).color)for(let s=0;s<t;s++){const{color:t}=e.getPoint(s);(t[0]>255||t[1]>255||t[2]>255)&&(i=!0)}break;default:console.warn("las: illegal value for options.las.colorDepth")}return i}(e,c,t.las?.colorDepth);for(let t=0;t<c;t++){const{position:A,color:a,intensity:l,classification:c}=e.getPoint(t);s[3*o]=A[0]*h+p,s[3*o+1]=A[1]*u+f,s[3*o+2]=A[2]*d+g,a&&i&&(m?(i[4*o]=a[0]/256,i[4*o+1]=a[1]/256,i[4*o+2]=a[2]/256):(i[4*o]=a[0],i[4*o+1]=a[1],i[4*o+2]=a[2]),i[4*o+3]=255),r[o]=l,n[o]=c,o++}const _={...a,header:{vertexCount:l.totalRead},progress:l.totalRead/l.totalToRead};t?.onProgress?.(_)})),a.header={vertexCount:A.totalToRead,boundingBox:nl(a?.attributes||{})},a&&(a.schema=Su(a.loaderData,a.attributes));return a}(e,t)}const ku={...vu,parse:async(e,t)=>Du(e,t),parseSync:(e,t)=>Du(e,t)};
23
+ **/let yr=null;function Br(e,t){const s=3*e,i=3*t;let r,n,A,o,a,l;const c=Math.min(r=yr[s],n=yr[s+1],A=yr[s+2]),h=Math.min(o=yr[i],a=yr[i+1],l=yr[i+2]);if(c!==h)return c-h;const u=Math.max(r,n,A),d=Math.max(o,a,l);return u!==d?u-d:0}let wr=null;function vr(e,t){let s=wr[2*e]-wr[2*t];return 0!==s?s:wr[2*e+1]-wr[2*t+1]}function Cr(e,t,s=!1){const i=e.positionsCompressed||[],r=function(e,t){const s=new Int32Array(e.length/3);for(let e=0,t=s.length;e<t;e++)s[e]=e;yr=new Int32Array(e.length);for(let s=0,i=e.length;s<i;s++)yr[s]=e[s]>>t;s.sort(Br);const i=new Int32Array(e.length);for(let t=0,r=s.length;t<r;t++)i[3*t+0]=e[3*s[t]+0],i[3*t+1]=e[3*s[t]+1],i[3*t+2]=e[3*s[t]+2];return i}(e.indices||[],t),n=function(e){if(0===(e||[]).length)return[];let t=new Int32Array(e.length/2);for(let e=0,s=t.length;e<s;e++)t[e]=e;for(let t=0,s=e.length;t<s;t+=2)if(e[t]>e[t+1]){let s=e[t];e[t]=e[t+1],e[t+1]=s}wr=new Int32Array(e),t.sort(vr);const s=new Int32Array(e.length);for(let i=0,r=t.length;i<r;i++)s[2*i+0]=e[2*t[i]+0],s[2*i+1]=e[2*t[i]+1];return s}(e.edgeIndices||[]);function A(e,t){if(e>t){let s=e;e=t,t=s}function s(s,i){return s!==e?e-s:i!==t?t-i:0}let i=0,r=(n.length>>1)-1;for(;i<=r;){const e=r+i>>1,t=s(n[2*e],n[2*e+1]);if(t>0)i=e+1;else{if(!(t<0))return e;r=e-1}}return-i-1}const o=new Int32Array(n.length/2);o.fill(0);const a=i.length/3;if(a>8*(1<<t))return[e];const l=new Int32Array(a);l.fill(-1);const c=[];function h(){l.fill(-1);const e={positionsCompressed:[],indices:[],edgeIndices:[],maxNumPositions:(1<<t)-t,numPositions:0,bucketNumber:c.length};return c.push(e),e}let u=h();for(let t=0,s=r.length;t<s;t+=3){let s=0;const a=r[t],c=r[t+1],d=r[t+2];if(-1===l[a]&&s++,-1===l[c]&&s++,-1===l[d]&&s++,s+u.numPositions>u.maxNumPositions&&(u=h()),u.bucketNumber>8)return[e];let p;-1===l[a]&&(l[a]=u.numPositions++,u.positionsCompressed.push(i[3*a]),u.positionsCompressed.push(i[3*a+1]),u.positionsCompressed.push(i[3*a+2])),-1===l[c]&&(l[c]=u.numPositions++,u.positionsCompressed.push(i[3*c]),u.positionsCompressed.push(i[3*c+1]),u.positionsCompressed.push(i[3*c+2])),-1===l[d]&&(l[d]=u.numPositions++,u.positionsCompressed.push(i[3*d]),u.positionsCompressed.push(i[3*d+1]),u.positionsCompressed.push(i[3*d+2])),u.indices.push(l[a]),u.indices.push(l[c]),u.indices.push(l[d]),(p=A(a,c))>=0&&0===o[p]&&(o[p]=1,u.edgeIndices.push(l[n[2*p]]),u.edgeIndices.push(l[n[2*p+1]])),(p=A(a,d))>=0&&0===o[p]&&(o[p]=1,u.edgeIndices.push(l[n[2*p]]),u.edgeIndices.push(l[n[2*p+1]])),(p=A(c,d))>=0&&0===o[p]&&(o[p]=1,u.edgeIndices.push(l[n[2*p]]),u.edgeIndices.push(l[n[2*p+1]]))}const d=t/8*2,p=t/8,f=2*i.length+(r.length+n.length)*d;let g=0,m=-i.length/3;return c.forEach((e=>{g+=2*e.positionsCompressed.length+(e.indices.length+e.edgeIndices.length)*p,m+=e.positionsCompressed.length/3})),g>f?[e]:(s&&function(e,t){const s={},i={};let r=0;e.forEach((e=>{const t=e.indices,n=e.edgeIndices,A=e.positionsCompressed;for(let e=0,i=t.length;e<i;e+=3){const i=A[3*t[e]]+"_"+A[3*t[e]+1]+"_"+A[3*t[e]+2]+"/"+A[3*t[e+1]]+"_"+A[3*t[e+1]+1]+"_"+A[3*t[e+1]+2]+"/"+A[3*t[e+2]]+"_"+A[3*t[e+2]+1]+"_"+A[3*t[e+2]+2];s[i]=!0}r+=e.edgeIndices.length/2;for(let e=0,t=n.length;e<t;e+=2){const t=A[3*n[e]]+"_"+A[3*n[e]+1]+"_"+A[3*n[e]+2]+"/"+A[3*n[e+1]]+"_"+A[3*n[e+1]+1]+"_"+A[3*n[e+1]+2]+"/";i[t]=!0}}));{const e=t.indices;t.edgeIndices;const i=t.positionsCompressed;for(let t=0,r=e.length;t<r;t+=3){const r=i[3*e[t]]+"_"+i[3*e[t]+1]+"_"+i[3*e[t]+2]+"/"+i[3*e[t+1]]+"_"+i[3*e[t+1]+1]+"_"+i[3*e[t+1]+2]+"/"+i[3*e[t+2]]+"_"+i[3*e[t+2]+1]+"_"+i[3*e[t+2]+2];if(!(r in s))throw console.log("Not found "+r),"Ohhhh!"}}}(c,e),c)}const Mr=new Float32Array([0,0,0]),Er=new Uint16Array([0,0,0]);R.OBB3();class Fr{constructor(e,t,s,i,r,n){this._isObject=t,this.scene=e.scene,this.model=e,this.isSceneModelEntity=!0,this.meshes=i,this._numPrimitives=0,this._capMaterial=null;for(let e=0,t=this.meshes.length;e<t;e++){const t=this.meshes[e];t.parent=this,t.entity=this,this._numPrimitives+=t.numPrimitives}this.id=s,this.originalSystemId=R.unglobalizeObjectId(e.id,s),this._flags=r,this._aabb=R.AABB3(),this._aabbDirty=!0,this._offset=R.vec3(),this._colorizeUpdated=!1,this._opacityUpdated=!1,this._lodCullable=!!n,this._culled=!1,this._culledVFC=!1,this._culledLOD=!1,this._isObject&&e.scene._registerObject(this)}_transformDirty(){this._aabbDirty=!0,this.model._transformDirty()}_sceneModelDirty(){this._aabbDirty=!0;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._sceneModelDirty()}get aabb(){if(this._aabbDirty){R.collapseAABB3(this._aabb);for(let e=0,t=this.meshes.length;e<t;e++)R.expandAABB3(this._aabb,this.meshes[e].aabb);this._aabbDirty=!1}return this._aabb}get isEntity(){return!0}get isModel(){return!1}get isObject(){return this._isObject}get numPrimitives(){return this._numPrimitives}get numTriangles(){return this._numPrimitives}get visible(){return this._getFlag(ks)}set visible(e){if(!!(this._flags&ks)!==e){this._flags=e?this._flags|ks:this._flags&~ks;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setVisible(this._flags);this._isObject&&this.model.scene._objectVisibilityUpdated(this),this.model.glRedraw()}}get highlighted(){return this._getFlag(Hs)}set highlighted(e){if(!!(this._flags&Hs)!==e){this._flags=e?this._flags|Hs:this._flags&~Hs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setHighlighted(this._flags);this._isObject&&this.model.scene._objectHighlightedUpdated(this),this.model.glRedraw()}}get xrayed(){return this._getFlag(Ls)}set xrayed(e){if(!!(this._flags&Ls)!==e){this._flags=e?this._flags|Ls:this._flags&~Ls;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setXRayed(this._flags);this._isObject&&this.model.scene._objectXRayedUpdated(this),this.model.glRedraw()}}get selected(){return this._getFlag(Ns)}set selected(e){if(!!(this._flags&Ns)!==e){this._flags=e?this._flags|Ns:this._flags&~Ns;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setSelected(this._flags);this._isObject&&this.model.scene._objectSelectedUpdated(this),this.model.glRedraw()}}get edges(){return this._getFlag(Gs)}set edges(e){if(!!(this._flags&Gs)!==e){this._flags=e?this._flags|Gs:this._flags&~Gs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setEdges(this._flags);this.model.glRedraw()}}get culledVFC(){return!!this._culledVFC}set culledVFC(e){this._culledVFC=e,this._setCulled()}get culledLOD(){return!!this._culledLOD}set culledLOD(e){this._culledLOD=e,this._setCulled()}get culled(){return!!this._culled}set culled(e){this._culled=e,this._setCulled()}_setCulled(){let e=!!this._culled||!(!this._culledLOD||!this._lodCullable)||!!this._culledVFC;if(!!(this._flags&Qs)!==e){this._flags=e?this._flags|Qs:this._flags&~Qs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setCulled(this._flags);this.model.glRedraw()}}get clippable(){return this._getFlag(Os)}set clippable(e){if(!!(this._flags&Os)!==e){this._flags=e?this._flags|Os:this._flags&~Os;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setClippable(this._flags);this.model.glRedraw()}}get collidable(){return this._getFlag(Vs)}set collidable(e){if(!!(this._flags&Vs)!==e){this._flags=e?this._flags|Vs:this._flags&~Vs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setCollidable(this._flags)}}get pickable(){return this._getFlag(Rs)}set pickable(e){if(!!(this._flags&Rs)!==e){this._flags=e?this._flags|Rs:this._flags&~Rs;for(var t=0,s=this.meshes.length;t<s;t++)this.meshes[t]._setPickable(this._flags)}}get colorize(){if(0===this.meshes.length)return null;const e=this.meshes[0]._colorize;return Mr[0]=e[0]/255,Mr[1]=e[1]/255,Mr[2]=e[2]/255,Mr}set colorize(e){if(e){Er[0]=Math.floor(255*e[0]),Er[1]=Math.floor(255*e[1]),Er[2]=Math.floor(255*e[2]);for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setColorize(Er)}else for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setColorize(null);if(this._isObject){const t=!!e;this.scene._objectColorizeUpdated(this,t),this._colorizeUpdated=t}this.model.glRedraw()}get opacity(){return this.meshes.length>0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let i=255;if(t){if(e<0?e=0:e>1&&(e=1),i=Math.floor(255*e),s===i)return}else if(i=255,s===i)return;for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._setOpacity(i,this._flags);this._isObject&&(this.scene._objectOpacityUpdated(this,t),this._opacityUpdated=t),this.model.glRedraw()}get offset(){return this._offset}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.meshes.length;e<t;e++)this.meshes[e]._setOffset(this._offset);this._aabbDirty=!0,this.model._aabbDirty=!0,this.scene._aabbDirty=!0,this.scene._objectOffsetUpdated(this,e),this.model.glRedraw()}get saoEnabled(){return this.model.saoEnabled}set capMaterial(e){if(!this.scene.readableGeometryEnabled)throw"The `capMaterial` assignment requires `Viewer::readableGeometryEnabled` to be `true`";this._capMaterial=e,this.scene._sectionCaps._onCapMaterialUpdated(this)}get capMaterial(){return this._capMaterial}getEachVertex(e){for(let t=0,s=this.meshes.length;t<s;t++)this.meshes[t].getEachVertex(e)}getEachIndex(e){for(let t=0,s=this.meshes.length;t<s;t++)this.meshes[t].getEachIndex(e)}getGeometryData(){let e=0;const t=[],s=[];for(let i=0,r=this.meshes.length;i<r;i++){const r=this.meshes[i];if(r.layer.readGeometryData){const i=r.layer.readGeometryData(r.portionId);for(let t=0,r=i.indices.length;t<r;t++)s.push(i.indices[t]+e);for(let e=0,s=i.positions.length;e<s;e++)t.push(i.positions[e]);e+=i.positions.length/3}}return{indices:s,positions:t}}get volume(){let e=0;for(let t=0,s=this.meshes.length;t<s;t++){const s=this.meshes[t].volume;if(s<0)return-1;e+=s}return e}get surfaceArea(){let e=0;for(let t=0,s=this.meshes.length;t<s;t++){const s=this.meshes[t].surfaceArea;s>=0&&(e+=s)}return e>0?e:-1}_getFlag(e){return!!(this._flags&e)}_finalize(){const e=this.model.scene;this._isObject&&(this.visible&&e._objectVisibilityUpdated(this),this.highlighted&&e._objectHighlightedUpdated(this),this.xrayed&&e._objectXRayedUpdated(this),this.selected&&e._objectSelectedUpdated(this));for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._finalize(this._flags)}_finalize2(){for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._finalize2()}_destroy(){const e=this.model.scene;this._isObject&&(e._deregisterObject(this),this.visible&&e._deRegisterVisibleObject(this),this.xrayed&&e._deRegisterXRayedObject(this),this.selected&&e._deRegisterSelectedObject(this),this.highlighted&&e._deRegisterHighlightedObject(this),this._colorizeUpdated&&this.scene._deRegisterColorizedObject(this),this._opacityUpdated&&this.scene._deRegisterOpacityObject(this),!this._offset||0===this._offset[0]&&0===this._offset[1]&&0===this._offset[2]||this.scene._deRegisterOffsetObject(this));for(let e=0,t=this.meshes.length;e<t;e++)this.meshes[e]._destroy();e._aabbDirty=!0}}const xr=R.vec4(4),Ur=R.vec4(),Ir=R.vec4(),Tr=R.vec3([1,0,0]),Pr=R.vec3([0,1,0]),Sr=R.vec3([0,0,1]);R.vec3(3),R.vec3(3);const Dr=R.identityMat4();class kr{constructor(e){this._model=e.model,this.id=e.id,this._parentTransform=e.parent,this._childTransforms=[],this._meshes=[],this._scale=new Float32Array([1,1,1]),this._quaternion=R.identityQuaternion(new Float32Array(4)),this._rotation=new Float32Array(3),this._position=new Float32Array(3),this._localMatrix=R.identityMat4(new Float32Array(16)),this._worldMatrix=R.identityMat4(new Float32Array(16)),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,e.matrix?this.matrix=e.matrix:(this.scale=e.scale,this.position=e.position,e.quaternion||(this.rotation=e.rotation)),e.parent&&e.parent._addChildTransform(this)}_addChildTransform(e){this._childTransforms.push(e),e._parentTransform=this,e._transformDirty(),e._setSubtreeAABBsDirty(this)}_addMesh(e){this._meshes.push(e),e.transform=this}get parentTransform(){return this._parentTransform}get meshes(){return this._meshes}set position(e){this._position.set(e||[0,0,0]),this._setLocalMatrixDirty(),this._model.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),R.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setLocalMatrixDirty(),this._model.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),R.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setLocalMatrixDirty(),this._model.glRedraw()}get quaternion(){return this._quaternion}set scale(e){this._scale.set(e||[1,1,1]),this._setLocalMatrixDirty(),this._model.glRedraw()}get scale(){return this._scale}set matrix(e){this._localMatrix||(this._localMatrix=R.identityMat4()),this._localMatrix.set(e||Dr),R.decomposeMat4(this._localMatrix,this._position,this._quaternion,this._scale),this._localMatrixDirty=!1,this._transformDirty(),this._model.glRedraw()}get matrix(){return this._localMatrixDirty&&(this._localMatrix||(this._localMatrix=R.identityMat4()),R.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 xr[0]=e[0],xr[1]=e[1],xr[2]=e[2],xr[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(xr,Ur),R.mulQuaternions(this.quaternion,Ur,Ir),this.quaternion=Ir,this._setLocalMatrixDirty(),this._model.glRedraw(),this}rotateOnWorldAxis(e,t){return xr[0]=e[0],xr[1]=e[1],xr[2]=e[2],xr[3]=t*R.DEGTORAD,R.angleAxisToQuaternion(xr,Ur),R.mulQuaternions(Ur,this.quaternion,Ur),this}rotateX(e){return this.rotate(Tr,e)}rotateY(e){return this.rotate(Pr,e)}rotateZ(e){return this.rotate(Sr,e)}translate(e){return this._position[0]+=e[0],this._position[1]+=e[1],this._position[2]+=e[2],this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateX(e){return this._position[0]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateY(e){return this._position[1]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}translateZ(e){return this._position[2]+=e,this._setLocalMatrixDirty(),this._model.glRedraw(),this}_setLocalMatrixDirty(){this._localMatrixDirty=!0,this._transformDirty()}_transformDirty(){this._worldMatrixDirty=!0;for(let e=0,t=this._childTransforms.length;e<t;e++){const t=this._childTransforms[e];if(t._transformDirty(),t._meshes&&t._meshes.length>0){const e=t._meshes;for(let t=0,s=e.length;t<s;t++)e[t]._transformDirty()}}if(this._meshes&&this._meshes.length>0){const e=this._meshes;for(let t=0,s=e.length;t<s;t++)e[t]._transformDirty()}}_buildWorldMatrix(){const e=this.matrix;if(this._parentTransform)R.mulMat4(this._parentTransform.worldMatrix,e,this._worldMatrix);else for(let t=0,s=e.length;t<s;t++)this._worldMatrix[t]=e[t];this._worldMatrixDirty=!1}_setSubtreeAABBsDirty(e){if(e._aabbDirty=!0,e._childTransforms)for(let t=0,s=e._childTransforms.length;t<s;t++)this._setSubtreeAABBsDirty(e._childTransforms[t])}}const Qr=R.vec3(),Rr=R.OBB3(),Or=R.vec4(),Vr=R.vec3([1,1,1]),Lr=R.vec3([0,0,0]);R.vec3([0,0,0]);const Hr=R.identityQuaternion(),Nr=R.identityMat4(),Gr=new Uint8Array([255,255,255]);class jr extends ie{constructor(e,t={}){super(e,t),this.renderOrder=t.renderOrder||0,this._dtxEnabled=this.scene.dtxEnabled&&!1!==t.dtxEnabled,this._enableVertexWelding=!1,this._enableIndexBucketing=!1,this._textureTranscoder=t.textureTranscoder||fr(this.scene.viewer),this._maxGeometryBatchSize=t.maxGeometryBatchSize??5e6,this._aabb=R.collapseAABB3(),this._aabbDirty=!0,this._quantizationRanges={},this._vboLayers={},this._dtxLayers={},this._meshList=[],this.layerList=[],this._layersToFinalize=[],this._entityList=[],this._entitiesToFinalize=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._transforms={},this._meshes={},this._unusedMeshes={},this._entities={},this.renderFlags=new Mt,this.numGeometries=0,this.numPortions=0,this.numVisibleLayerPortions=0,this.numTransparentLayerPortions=0,this.numXRayedLayerPortions=0,this.numHighlightedLayerPortions=0,this.numSelectedLayerPortions=0,this.numEdgesLayerPortions=0,this.numPickableLayerPortions=0,this.numClippableLayerPortions=0,this.numCulledLayerPortions=0,this.numEntities=0,this._numTriangles=0,this._numLines=0,this._numPoints=0,this._layersFinalized=!1,this._edgeThreshold=t.edgeThreshold||10,this._origin=R.vec3(t.origin||[0,0,0]),this._position=R.vec3(t.position||[0,0,0]),this._rotation=R.vec3(t.rotation||[0,0,0]),this._quaternion=R.vec4(t.quaternion||[0,0,0,1]),this._conjugateQuaternion=R.vec4(t.quaternion||[0,0,0,1]),t.rotation&&R.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._scale=R.vec3(t.scale||[1,1,1]),this._worldRotationMatrix=R.mat4(),this._worldRotationMatrixConjugate=R.mat4(),this._matrix=R.mat4(),this._matrixDirty=!0,this._rebuildMatrices(),this._worldNormalMatrix=R.mat4(),R.inverseMat4(this._matrix,this._worldNormalMatrix),R.transposeMat4(this._worldNormalMatrix),(t.matrix||t.position||t.rotation||t.scale||t.quaternion)&&(this._viewMatrix=R.mat4(),this._viewNormalMatrix=R.mat4(),this._viewMatrixDirty=!0,this._matrixNonIdentity=!0),this._opacity=1,this._colorize=[1,1,1],this._saoEnabled=!1!==t.saoEnabled,this._pbrEnabled=!1!==t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._isModel=t.isModel,this._isModel&&this.scene._registerModel(this),this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{this._viewMatrixDirty=!0})),this._meshesWithDirtyMatrices=[],this._numMeshesWithDirtyMatrices=0,this._onTick=this.scene.on("tick",(()=>{for(;this._numMeshesWithDirtyMatrices>0;)this._meshesWithDirtyMatrices[--this._numMeshesWithDirtyMatrices]._updateMatrix()}));const s=(e,t)=>this._textures[e]=new rr({id:e,texture:new Kt({gl:this.scene.canvas.gl,preloadColor:t})});this._textureSets.defaultTextureSet=new ir({id:"defaultTextureSet",colorTexture:s("defaultColorTexture",[1,1,1,1]),metallicRoughnessTexture:s("defaultMetalRoughTexture",[0,1,1,1]),normalsTexture:s("defaultNormalsTexture",[0,0,0,0]),emissiveTexture:s("defaultEmissiveTexture",[0,0,0,1]),occlusionTexture:s("defaultOcclusionTexture",[1,1,1,1])}),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.backfaces=t.backfaces}_meshMatrixDirty(e){this._meshesWithDirtyMatrices[this._numMeshesWithDirtyMatrices++]=e}get isPerformanceModel(){return!0}get transforms(){return this._transforms}get textures(){return this._textures}get textureSets(){return this._textureSets}get meshes(){return this._meshes}get objects(){return this._entities}get origin(){return this._origin}set position(e){this._position.set(e||[0,0,0]),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get position(){return this._position}set rotation(e){this._rotation.set(e||[0,0,0]),R.eulerToQuaternion(this._rotation,"XYZ",this._quaternion),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get rotation(){return this._rotation}set quaternion(e){this._quaternion.set(e||[0,0,0,1]),R.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get quaternion(){return this._quaternion}set scale(e){}get scale(){return this._scale}set matrix(e){this._matrix.set(e||Nr),R.decomposeMat4(this._matrix,this._position,this._quaternion,this._scale),R.quaternionToEuler(this._quaternion,"XYZ",this._rotation),this._matrixDirty=!1,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.glRedraw()}get matrix(){return this._rebuildMatrices(),this._matrix}get rotationMatrix(){return this._rebuildMatrices(),this._worldRotationMatrix}_rebuildMatrices(){this._matrixDirty&&(R.quaternionToRotationMat4(this._quaternion,this._worldRotationMatrix),R.conjugateQuaternion(this._quaternion,this._conjugateQuaternion),R.quaternionToRotationMat4(this._conjugateQuaternion,this._worldRotationMatrixConjugate),R.scaleMat4v(this._scale,this._worldRotationMatrix),R.scaleMat4v(this._scale,this._worldRotationMatrixConjugate),this._matrix.set(this._worldRotationMatrix),R.translateMat4v(this._position,this._matrix),this._matrixDirty=!1,this._viewMatrixDirty=!0)}get rotationMatrixConjugate(){return this._rebuildMatrices(),this._worldRotationMatrixConjugate}_setWorldMatrixDirty(){this._matrixDirty=!0,this._aabbDirty=!0}_transformDirty(){this._matrixDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0}_sceneModelDirty(){this.scene._aabbDirty=!0,this._aabbDirty=!0,this.scene._aabbDirty=!0,this._matrixDirty=!0;for(let e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._sceneModelDirty()}get worldMatrix(){return this.matrix}get worldNormalMatrix(){return this._worldNormalMatrix}_rebuildViewMatrices(){this._rebuildMatrices(),this._viewMatrixDirty&&(R.mulMat4(this.scene.camera.viewMatrix,this._matrix,this._viewMatrix),R.inverseMat4(this._viewMatrix,this._viewNormalMatrix),R.transposeMat4(this._viewNormalMatrix),this._viewMatrixDirty=!1)}get viewMatrix(){return this._viewMatrix?(this._rebuildViewMatrices(),this._viewMatrix):this.scene.camera.viewMatrix}get viewNormalMatrix(){return this._viewNormalMatrix?(this._rebuildViewMatrices(),this._viewNormalMatrix):this.scene.camera.viewNormalMatrix}get backfaces(){return this._backfaces}set backfaces(e){e=!!e,this._backfaces=e,this.glRedraw()}get entityList(){return this._entityList}get isEntity(){return!0}get isModel(){return this._isModel}get isObject(){return!1}get aabb(){if(this._aabbDirty){R.collapseAABB3(this._aabb);for(let e=0,t=this._entityList.length;e<t;e++)R.expandAABB3(this._aabb,this._entityList[e].aabb);this._aabbDirty=!1}return this._aabb}get numTriangles(){return this._numTriangles}get numLines(){return this._numLines}get numPoints(){return this._numPoints}get visible(){return this.numVisibleLayerPortions>0}set visible(e){e=!1!==e,this._visible=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].visible=e;this.glRedraw()}get xrayed(){return this.numXRayedLayerPortions>0}set xrayed(e){e=!!e,this._xrayed=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].xrayed=e;this.glRedraw()}get highlighted(){return this.numHighlightedLayerPortions>0}set highlighted(e){e=!!e,this._highlighted=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].highlighted=e;this.glRedraw()}get selected(){return this.numSelectedLayerPortions>0}set selected(e){e=!!e,this._selected=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].selected=e;this.glRedraw()}get edges(){return this.numEdgesLayerPortions>0}set edges(e){e=!!e,this._edges=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].edges=e;this.glRedraw()}get culled(){return this._culled}set culled(e){e=!!e,this._culled=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].culled=e;this.glRedraw()}get clippable(){return this._clippable}set clippable(e){e=!1!==e,this._clippable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].clippable=e;this.glRedraw()}get collidable(){return this._collidable}set collidable(e){e=!1!==e,this._collidable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].collidable=e}get pickable(){return this.numPickableLayerPortions>0}set pickable(e){e=!1!==e,this._pickable=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].pickable=e}get colorize(){return this._colorize}set colorize(e){this._colorize=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].colorize=e}get opacity(){return this._opacity}set opacity(e){this._opacity=e;for(let t=0,s=this._entityList.length;t<s;t++)this._entityList[t].opacity=e}get castsShadow(){return this._castsShadow}set castsShadow(e){(e=!1!==e)!==this._castsShadow&&(this._castsShadow=e,this.glRedraw())}get receivesShadow(){return this._receivesShadow}set receivesShadow(e){(e=!1!==e)!==this._receivesShadow&&(this._receivesShadow=e,this.glRedraw())}get saoEnabled(){return this._saoEnabled}get pbrEnabled(){return this._pbrEnabled}get colorTextureEnabled(){return this._colorTextureEnabled}get isDrawable(){return!0}get isStateSortable(){return!1}get xrayMaterial(){return this.scene.xrayMaterial}get highlightMaterial(){return this.scene.highlightMaterial}get selectedMaterial(){return this.scene.selectedMaterial}get edgeMaterial(){return this.scene.edgeMaterial}getPickViewMatrix(e){return this._viewMatrix?this._viewMatrix:e}createQuantizationRange(e){void 0!==e.id&&null!==e.id?e.aabb?this.error("[createQuantizationRange] Config missing: aabb"):this._quantizationRanges[e.id]?this.error("[createQuantizationRange] QuantizationRange already created: "+e.id):this._quantizationRanges[e.id]={id:e.id,aabb:e.aabb,matrix:Si(e.aabb,R.mat4())}:this.error("[createQuantizationRange] Config missing: id")}_createDefaultIndices(e){const t=[];for(let s=0;s<e;s++)t.push(s);return t}createGeometry(e){if(void 0!==e.id&&null!==e.id)if(this._geometries[e.id])this.error("[createGeometry] Geometry already created: "+e.id);else if(void 0!==e.primitive&&null!==e.primitive||(e.primitive="triangles"),"points"===e.primitive||"lines"===e.primitive||"triangles"===e.primitive||"solid"===e.primitive||"surface"===e.primitive){if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("[createGeometry] Param expected: `positions`, `positionsCompressed' or 'buckets"),null;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("[createGeometry] Param expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.positionsDecodeMatrix&&e.positionsDecodeBoundary)return this.error("[createGeometry] Only one of these params expected: `positionsDecodeMatrix` or 'positionsDecodeBoundary' (required for `positionsCompressed')"),null;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')"),null;if(e.buckets||e.indices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.indices=this._createDefaultIndices((e.positions||e.positionsCompressed).length/3)),!e.buckets&&!e.indices&&"points"!==e.primitive)return this.error(`[createGeometry] Param expected: indices (required for '${e.primitive}' primitive type)`),null;if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Si(e.positionsDecodeBoundary,R.mat4())),e.positions){const t=R.collapseAABB3();e.positionsDecodeMatrix=R.mat4(),R.expandAABB3Points3(t,e.positions),e.positionsCompressed=Pi(e.positions,t,e.positionsDecodeMatrix),e.aabb=t}else if(e.positionsCompressed){const t=R.collapseAABB3();e.positionsDecodeMatrix=new Float64Array(e.positionsDecodeMatrix),e.positionsCompressed=new Uint16Array(e.positionsCompressed),R.expandAABB3Points3(t,e.positionsCompressed),Re.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}else if(e.buckets){const t=R.collapseAABB3();this._dtxBuckets[e.id]=e.buckets;for(let s=0,i=e.buckets.length;s<i;s++){const i=e.buckets[s];i.positions?R.expandAABB3Points3(t,i.positions):i.positionsCompressed&&R.expandAABB3Points3(t,i.positionsCompressed)}e.positionsDecodeMatrix&&Re.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(e.colorsCompressed&&e.colorsCompressed.length>0)e.colorsCompressed=new Uint8Array(e.colorsCompressed);else if(e.colors&&e.colors.length>0){const t=e.colors,s=new Uint8Array(t.length);for(let e=0,i=t.length;e<i;e++)s[e]=255*t[e];e.colorsCompressed=s}if(e.buckets||e.edgeIndices||"triangles"!==e.primitive&&"solid"!==e.primitive&&"surface"!==e.primitive||(e.positions?e.edgeIndices=Ie(e.positions,e.indices,null,5):e.edgeIndices=Ie(e.positionsCompressed,e.indices,e.positionsDecodeMatrix,2)),e.uv){const t=Re.getUVBounds(e.uv),s=Re.compressUVs(e.uv,t.min,t.max);e.uvCompressed=s.quantized,e.uvDecodeMatrix=s.decodeMatrix}else e.uvCompressed&&(e.uvCompressed=new Uint16Array(e.uvCompressed),e.uvDecodeMatrix=new Float64Array(e.uvDecodeMatrix));e.normals&&(e.normals=null),this._geometries[e.id]=e,this._numTriangles+=e.indices?Math.round(e.indices.length/3):0,this.numGeometries++}else this.error(`[createGeometry] Unsupported value for 'primitive': '${e.primitive}' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'.`);else this.error("[createGeometry] Config missing: id")}createTexture(e){const t=e.id;if(null==t)return void this.error("[createTexture] Config missing: id");if(this._textures[t])return void this.error("[createTexture] Texture already created: "+t);if(!e.src&&!e.image&&!e.buffers)return this.error("[createTexture] Param expected: `src`, `image' or 'buffers'"),null;let s=e.minFilter||1008;1006!==s&&1007!==s&&1008!==s&&1005!==s&&1004!==s&&(this.error("[createTexture] Unsupported value for 'minFilter' - \n supported values are LinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, \n NearestMipMapLinearFilter and LinearMipmapLinearFilter. Defaulting to LinearMipmapLinearFilter."),s=1008);let i=e.magFilter||1006;1006!==i&&1003!==i&&(this.error("[createTexture] Unsupported value for 'magFilter' - supported values are LinearFilter and NearestFilter. Defaulting to LinearFilter."),i=1006);let r=e.wrapS||1e3;1001!==r&&1002!==r&&1e3!==r&&(this.error("[createTexture] Unsupported value for 'wrapS' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),r=1e3);let n=e.wrapT||1e3;1001!==n&&1002!==n&&1e3!==n&&(this.error("[createTexture] Unsupported value for 'wrapT' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),n=1e3);let A=e.wrapR||1e3;1001!==A&&1002!==A&&1e3!==A&&(this.error("[createTexture] Unsupported value for 'wrapR' - supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Defaulting to RepeatWrapping."),A=1e3);let o=e.encoding||3e3;3e3!==o&&3001!==o&&(this.error("[createTexture] Unsupported value for 'encoding' - supported values are LinearEncoding and sRGBEncoding. Defaulting to LinearEncoding."),o=3e3);const a=new Kt({gl:this.scene.canvas.gl,minFilter:s,magFilter:i,wrapS:r,wrapT:n,wrapR:A,encoding:o});if(e.preloadColor&&a.setPreloadColor(e.preloadColor),e.image){const t=e.image;if(t.crossOrigin="Anonymous",t.compressed){const e=t.data;a.setCompressedData({mipmaps:e,props:{format:e[0].format,minFilter:s,magFilter:i}})}else a.setImage(t,{minFilter:s,magFilter:i,wrapS:r,wrapT:n,wrapR:A,flipY:e.flipY,encoding:o})}else if(e.src){const t=e.src.split(".").pop();switch(t){case"jpeg":case"jpg":case"png":case"gif":const l=new Image;l.onload=()=>{a.setImage(l,{minFilter:s,magFilter:i,wrapS:r,wrapT:n,wrapR:A,flipY:e.flipY,encoding:o}),this.glRedraw()},l.src=e.src;break;default:this._textureTranscoder?j.loadArraybuffer(e.src,(e=>{e.byteLength?this._textureTranscoder.transcode([e],a).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'src': file data is zero length")}),(function(e){this.error(`[createTexture] Can't create texture from 'src': ${e}`)})):this.error(`[createTexture] Can't create texture from 'src' - SceneModel needs to be configured with a TextureTranscoder for this file type ('${t}')`)}}else e.buffers&&(this._textureTranscoder?this._textureTranscoder.transcode(e.buffers,a).then((()=>{this.glRedraw()})):this.error("[createTexture] Can't create texture from 'buffers' - SceneModel needs to be configured with a TextureTranscoder for this option"));this._textures[t]=new rr({id:t,texture:a})}createTextureSet(e){const t=e.id;if(null==t)return this.error("[createTextureSet] Config missing: id"),!1;if(this._textureSets[t])return this.error(`[createTextureSet] Texture set already created: ${t}`),!1;const s=(e,t)=>{const s=e??t;if(s in this._textures)return this._textures[s];throw e};try{const i=new ir({id:t,model:this,alphaCutoff:e.alphaCutoff,colorTexture:s(e.colorTextureId,"defaultColorTexture"),metallicRoughnessTexture:s(e.metallicRoughnessTextureId,"defaultMetalRoughTexture"),normalsTexture:s(e.normalsTextureId,"defaultNormalsTexture"),emissiveTexture:s(e.emissiveTextureId,"defaultEmissiveTexture"),occlusionTexture:s(e.occlusionTextureId,"defaultOcclusionTexture")});return this._textureSets[t]=i,i}catch(e){return this.error(`[createTextureSet] Texture not found: ${e} - ensure that you create it first with createTexture()`),!1}}createTransform(e){if(void 0===e.id||null===e.id)return void this.error("[createTransform] SceneModel.createTransform() config missing: id");if(this._transforms[e.id])return void this.error(`[createTransform] SceneModel already has a transform with this ID: ${e.id}`);let t;if(e.parentTransformId&&(t=this._transforms[e.parentTransformId],!t))return void this.error("[createTransform] SceneModel.createTransform() config missing: id");const s=new kr({id:e.id,model:this,parent:t,matrix:e.matrix,position:e.position,scale:e.scale,rotation:e.rotation,quaternion:e.quaternion});return this._transforms[s.id]=s,s}createMesh(e){if(void 0===e.id||null===e.id)return this.error("[createMesh] SceneModel.createMesh() config missing: id"),!1;if(this._meshes[e.id])return this.error(`[createMesh] SceneModel already has a mesh with this ID: ${e.id}`),!1;const t=e.geometryId,s=void 0!==t;if(s){if(e.positions||e.positionsCompressed||e.indices||e.edgeIndices||e.normals||e.normalsCompressed||e.uv||e.uvCompressed||e.positionsDecodeMatrix)return this.error("Mesh geometry parameters not expected when instancing a geometry (not expected: positions, positionsCompressed, indices, edgeIndices, normals, normalsCompressed, uv, uvCompressed, positionsDecodeMatrix)"),!1;if(e.geometry=this._geometries[t],!e.geometry)return this.error(`[createMesh] Geometry not found: ${t} - ensure that you create it first with createGeometry()`),!1}else e.primitive??="triangles";const i=s?e.geometry.primitive:e.primitive,r="triangles"===i||"solid"===i||"surface"===i,n=e.textureSetId,A=this._dtxEnabled&&r&&!n;if(e.origin=e.origin?R.addVec3(this._origin,e.origin,R.vec3()):this._origin,s){e.positionsDecodeMatrix=e.geometry.positionsDecodeMatrix,e.aabb=R.AABB3(e.geometry.aabb);const t=e.transformId;if(t){if(e.transform=this._transforms[t],!e.transform)return this.error(`[createMesh] Transform not found: ${t} - ensure that you create it first with createTransform()`),!1}else if(e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){const t=e.scale||Vr,s=e.position||Lr,i=e.rotation?R.eulerToQuaternion(e.rotation,"XYZ",Or):e.quaternion||Hr;e.meshMatrix=R.composeMat4(s,i,t,R.mat4())}}else{if("points"!==i&&"lines"!==i&&"triangles"!==i&&"solid"!==i&&"surface"!==i)return this.error(`Unsupported value for 'primitive': '${i}' ('geometryId' is absent) - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'.`),!1;if(!e.positions&&!e.positionsCompressed&&!e.buckets)return this.error("Param expected: 'positions', 'positionsCompressed' or `buckets` ('geometryId' is absent)"),!1;if(e.positions&&(e.positionsDecodeMatrix||e.positionsDecodeBoundary))return this.error("Illegal params: 'positions' not expected with 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.positionsCompressed&&!e.positionsDecodeMatrix&&!e.positionsDecodeBoundary)return this.error("Param expected: 'positionsCompressed' should be accompanied by 'positionsDecodeMatrix'/'positionsDecodeBoundary' ('geometryId' is absent)"),!1;if(e.uvCompressed&&!e.uvDecodeMatrix)return this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)"),!1;if(!e.buckets&&!e.indices)if(r)e.indices=this._createDefaultIndices((e.positions||e.positionsCompressed).length/3);else if("lines"===i)return this.error(`Param expected: indices (required for '${i}' primitive type)`),!1;if((e.matrix||e.position||e.rotation||e.scale)&&(e.positionsCompressed||e.positionsDecodeBoundary))return this.error("Unexpected params: 'matrix', 'rotation', 'scale', 'position' not allowed with 'positionsCompressed'"),!1;if(e.matrix)e.meshMatrix=e.matrix;else if(e.scale||e.rotation||e.position||e.quaternion){const t=e.scale||Vr,s=e.position||Lr,i=e.rotation?R.eulerToQuaternion(e.rotation,"XYZ",Or):e.quaternion||Hr;e.meshMatrix=R.composeMat4(s,i,t,R.mat4())}if(e.positionsDecodeBoundary&&(e.positionsDecodeMatrix=Si(e.positionsDecodeBoundary,R.mat4())),e.positions){const t=[];pt(e.positions,t,Qr)&&(e.positions=t,e.origin=R.addVec3(e.origin,Qr,R.vec3()));const s=R.collapseAABB3();A?(e.positionsDecodeMatrix=R.mat4(),R.expandAABB3Points3(s,e.positions),e.positionsCompressed=Pi(e.positions,s,e.positionsDecodeMatrix)):(e.meshMatrix&&(R.transformPositions3(e.meshMatrix,e.positions,e.positions),e.meshMatrix=null),R.expandAABB3Points3(s,e.positions)),e.aabb=s}else if(e.positionsCompressed){const t=R.collapseAABB3();R.expandAABB3Points3(t,e.positionsCompressed),Re.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}if(A&&e.buckets){const t=R.collapseAABB3();e.buckets.forEach((e=>{const s=e.positions||e.positionsCompressed;s&&R.expandAABB3Points3(t,s)})),e.positionsDecodeMatrix&&Re.decompressAABB(t,e.positionsDecodeMatrix),e.aabb=t}r&&!e.buckets&&(e.edgeIndices||=Ie(e.positions||e.positionsCompressed,e.indices,e.positions?null:e.positionsDecodeMatrix,2))}if(e.meshMatrix&&(R.AABB3ToOBB3(e.aabb,Rr),R.transformOBB3(e.meshMatrix,Rr,Rr),R.OBB3ToAABB3(Rr,e.aabb)),e.color=e.color?new Uint8Array(e.color.slice(0,3).map((e=>Math.floor(255*e)))):Gr,e.opacity=Math.floor(255*(e.opacity??1)),A)e.type=2,s&&(e.buckets=this._dtxBuckets[t]),e.buckets||(e.buckets=function(e,t,s){let i,r,n,A;t||s?[i,r,n]=br({positionsCompressed:e.positionsCompressed,indices:e.indices,edgeIndices:e.edgeIndices}):(i=e.positionsCompressed,r=e.indices,n=e.edgeIndices);if(s){A=Cr({positionsCompressed:i,indices:r,edgeIndices:n},i.length/3>65536?16:8)}else A=[{positionsCompressed:i,indices:r,edgeIndices:n}];return A}(s?e.geometry:e,this._enableVertexWelding,this._enableIndexBucketing),s&&(this._dtxBuckets[t]=e.buckets));else if(e.type=s?0:1,e.metallic=Math.floor(255*(e.metallic??0)),e.roughness=Math.floor(255*(e.roughness??1)),n&&(e.textureSet=this._textureSets[n],!s&&!e.textureSet))return this.error(`[createMesh] Texture set not found: ${n} - ensure that you create it first with createTextureSet()`),!1;e.numPrimitives=this._getNumPrimitives(e);const o=new Ds(this,e.id,e.color,e.opacity,e.transform,e.textureSet),a=this.scene._renderer.getPickID(o);return o.pickId=a,o.origin=R.vec3(e.origin),o.layer=2===e.type?this._getDTXLayer(e):this._getVBOLayer(0===e.type,e),o.aabb=e.aabb,e.pickColor=new Uint8Array([255&a,a>>8&255,a>>16&255,a>>24&255]),e.solid="solid"===e.primitive,e.meshMatrix=e.transform?e.transform.worldMatrix:e.meshMatrix,o.portionId=o.layer.createPortion(o,e),o.numPrimitives=e.numPrimitives,this._meshes[e.id]=o,this._unusedMeshes[e.id]=o,this._meshList.push(o),o}_getNumPrimitives(e){let t=0;switch(e.geometry?e.geometry.primitive:e.primitive){case"triangles":case"solid":case"surface":switch(e.type){case 2:for(let s=0,i=e.buckets.length;s<i;s++)t+=e.buckets[s].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/3);case"points":switch(e.type){case 2:for(let s=0,i=e.buckets.length;s<i;s++)t+=e.buckets[s].positionsCompressed.length;break;case 1:t+=e.positions?e.positions.length:e.positionsCompressed.length;break;case 0:const s=e.geometry;t+=s.positions?s.positions.length:s.positionsCompressed.length}return Math.round(t);case"lines":case"line-strip":switch(e.type){case 2:for(let s=0,i=e.buckets.length;s<i;s++)t+=e.buckets[s].indices.length;break;case 1:t+=e.indices.length;break;case 0:t+=e.geometry.indices.length}return Math.round(t/2)}return 0}_getDTXLayer(e){const t=e.origin,s=e.geometry?e.geometry.primitive:e.primitive,i=`.${s}.${Math.round(t[0])}.${Math.round(t[1])}.${Math.round(t[2])}`;let r=this._dtxLayers[i];if(r){if(r.canCreatePortion(e))return r;delete this._dtxLayers[i],r=null}switch(s){case"triangles":case"solid":case"surface":r=new Fi(this,s,t);break;default:return}return this._dtxLayers[i]=r,this.layerList.push(r),this._layersToFinalize.push(r),r}_getVBOLayer(e,t){const s=e&&t.geometry,i=e?s.primitive:t.primitive,r=t.origin,n=!e&&(t.positionsDecodeMatrix||t.positionsDecodeBoundary),A=n?this._createHashStringFromMatrix(n):"-",o=t.textureSetId||"-",a=e?t.geometryId:"-",l=(e?"instancing":"batching")+`.${Math.round(r[0])}.${Math.round(r[1])}.${Math.round(r[2])}.${i}.${A}.${o}.${a}.${(t.normalsCompressed||t.normals||[]).length>0?"n":"-"}`;if(!e&&l in this._vboLayers){const e=this._vboLayers[l],s=t.positionsCompressed?t.positionsCompressed.length:t.positions.length;e.canCreatePortion(s,"points"===i?0:t.indices.length)||(e.finalize(),delete this._vboLayers[l])}if(!(l in this._vboLayers)){const n=new er(this,i,r,{textureSet:t.textureSet,...e?{geometry:s}:{maxGeometryBatchSize:this._maxGeometryBatchSize,positionsDecodeMatrix:t.positionsDecodeMatrix,uvDecodeMatrix:t.uvDecodeMatrix}});this.layerList.push(n),this._layersToFinalize.push(n),this._vboLayers[l]=n}return this._vboLayers[l]}_createHashStringFromMatrix(e){const t=e.join(";");let s=0;for(let e=0;e<t.length;e++){s=(s<<5)-s+t.charCodeAt(e),s|=0}return(s>>>0).toString(16)}createEntity(e){if(void 0===e.id?e.id=R.createUUID():this.scene.components[e.id]&&(this.error(`Scene already has a Component with this ID: ${e.id} - will assign random ID`),e.id=R.createUUID()),void 0===e.meshIds)return this.error("Config missing: meshIds"),null;const t=e=>!1!==e;let s=0;s|=this._visible&&t(e.visible)&&ks,s|=this._pickable&&t(e.pickable)&&Rs,s|=this._culled&&t(e.culled)&&Qs,s|=this._clippable&&t(e.clippable)&&Os,s|=this._collidable&&t(e.collidable)&&Vs,s|=this._xrayed&&t(e.xrayed)&&Ls,s|=this._highlighted&&t(e.highlighted)&&Hs,s|=this._selected&&t(e.selected)&&Ns,s|=this._edges&&t(e.edges)&&Gs,e.flags=s;let i=[];for(let t=0,s=e.meshIds.length;t<s;t++){const s=e.meshIds[t];let r=this._meshes[s];r?r.parent?this.error(`Mesh with ID "${s}" already belongs to object with ID "${r.parent.id}" - ignoring this mesh`):(i.push(r),delete this._unusedMeshes[s]):this.error(`Mesh with this ID not found: "${s}" - ignoring this mesh`)}const r=new Fr(this,e.isObject,e.id,i,e.flags,!0);return this._entityList.push(r),this._entities[e.id]=r,this._entitiesToFinalize.push(r),this.numEntities++,r}preFinalize(){if(this.destroyed)return!1;if(0===this._layersToFinalize.length)return!1;this._createDummyEntityForUnusedMeshes();for(let e=0,t=this._layersToFinalize.length;e<t;e++){this._layersToFinalize[e].finalize()}this._vboLayers={},this._dtxLayers={},this._layersToFinalize=[];for(let e=0,t=this._entitiesToFinalize.length;e<t;e++){this._entitiesToFinalize[e]._finalize()}for(let e=0,t=this._entitiesToFinalize.length;e<t;e++){this._entitiesToFinalize[e]._finalize2()}this._entitiesToFinalize=[],this.scene._aabbDirty=!0,this._viewMatrixDirty=!0,this._matrixDirty=!0,this._aabbDirty=!0,this._setWorldMatrixDirty(),this._sceneModelDirty(),this.position=this._position,this.layerList.sort(((e,t)=>e.sortId<t.sortId?-1:e.sortId>t.sortId?1:0));for(let e=0,t=this.layerList.length;e<t;e++){this.layerList[e].layerIndex=e}this.glRedraw(),this._layersFinalized=!0}finalize(){this.destroyed||(this.preFinalize(),this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={})}stateSortCompare(e,t){}rebuildRenderFlags(){this.renderFlags.reset(),this._updateRenderFlagsVisibleLayers(),this.renderFlags.numLayers>0&&0===this.renderFlags.numVisibleLayers?this.renderFlags.culled=!0:this._updateRenderFlags()}_updateRenderFlagsVisibleLayers(){const e=this.renderFlags;e.numLayers=this.layerList.length,e.numVisibleLayers=0;for(let t=0,s=this.layerList.length;t<s;t++){const s=this.layerList[t];this._getActiveSectionPlanesForLayer(s)&&(e.visibleLayers[e.numVisibleLayers++]=t)}}_createDummyEntityForUnusedMeshes(){const e=Object.keys(this._unusedMeshes);if(e.length>0){const t=`${this.id}-${R.createUUID()}`;this.warn(`Creating dummy SceneModelEntity "${t}" for unused SceneMeshes: [${e.join(",")}]`),this.createEntity({id:t,meshIds:e,isObject:!0})}this._unusedMeshes={}}_getActiveSectionPlanesForLayer(e){const t=this.renderFlags,s=this.scene._sectionPlanesState.sectionPlanes,i=s.length,r=e.layerIndex*i;if(i>0)for(let e=0;e<i;e++){s[e].active?(t.sectionPlanesActivePerLayer[r+e]=!0,t.sectioned=!0):t.sectionPlanesActivePerLayer[r+e]=!1}return!0}_updateRenderFlags(){if(0===this.numVisibleLayerPortions)return;if(this.numCulledLayerPortions===this.numPortions)return;const e=this.renderFlags;if(e.colorOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.colorTransparent=!0),this.numXRayedLayerPortions>0){const t=this.scene.xrayMaterial._state;t.fill&&(t.fillAlpha<1?e.xrayedSilhouetteTransparent=!0:e.xrayedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.xrayedEdgesTransparent=!0:e.xrayedEdgesOpaque=!0)}if(this.numEdgesLayerPortions>0){this.scene.edgeMaterial._state.edges&&(e.edgesOpaque=this.numTransparentLayerPortions<this.numPortions,this.numTransparentLayerPortions>0&&(e.edgesTransparent=!0))}if(this.numSelectedLayerPortions>0){const t=this.scene.selectedMaterial._state;t.fill&&(t.fillAlpha<1?e.selectedSilhouetteTransparent=!0:e.selectedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.selectedEdgesTransparent=!0:e.selectedEdgesOpaque=!0)}if(this.numHighlightedLayerPortions>0){const t=this.scene.highlightMaterial._state;t.fill&&(t.fillAlpha<1?e.highlightedSilhouetteTransparent=!0:e.highlightedSilhouetteOpaque=!0),t.edges&&(t.edgeAlpha<1?e.highlightedEdgesTransparent=!0:e.highlightedEdgesOpaque=!0)}}_withEachVisibleLayer(e,t,s){if(t&&0===this.numVisibleLayerPortions)return;const i=this.scene._sectionPlanesState.sectionPlanes.filter((e=>e.active)),r=e.testAABB,n=this.renderFlags;for(let e=0,t=n.visibleLayers.length;e<t;e++){const t=this.layerList[n.visibleLayers[e]],A=t.getAABB();r&&!r(A)||!i.every((e=>R.planeAABB3Intersect(e.dir,e.dist,A)>=0))||s(t)}}drawColorOpaque(e){this._withEachVisibleLayer(e,!1,(t=>t.drawColorOpaque(this.renderFlags,e)))}drawColorTransparent(e){this._withEachVisibleLayer(e,!1,(t=>t.drawColorTransparent(this.renderFlags,e)))}drawDepth(e){this._withEachVisibleLayer(e,!1,(t=>t.drawDepth(this.renderFlags,e)))}drawSilhouetteXRayed(e){this._withEachVisibleLayer(e,!1,(t=>t.drawSilhouetteXRayed(this.renderFlags,e)))}drawSilhouetteHighlighted(e){this._withEachVisibleLayer(e,!1,(t=>t.drawSilhouetteHighlighted(this.renderFlags,e)))}drawSilhouetteSelected(e){this._withEachVisibleLayer(e,!1,(t=>t.drawSilhouetteSelected(this.renderFlags,e)))}drawEdgesColorOpaque(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesColorOpaque(this.renderFlags,e)))}drawEdgesColorTransparent(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesColorTransparent(this.renderFlags,e)))}drawEdgesXRayed(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesXRayed(this.renderFlags,e)))}drawEdgesHighlighted(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesHighlighted(this.renderFlags,e)))}drawEdgesSelected(e){this._withEachVisibleLayer(e,!1,(t=>t.drawEdgesSelected(this.renderFlags,e)))}drawOcclusion(e){this._withEachVisibleLayer(e,!0,(t=>t.drawOcclusion(this.renderFlags,e)))}drawShadow(e){this._withEachVisibleLayer(e,!0,(t=>t.drawShadow(this.renderFlags,e)))}drawPickMesh(e){this._withEachVisibleLayer(e,!0,(t=>t.drawPickMesh(this.renderFlags,e)))}drawPickDepths(e){this._withEachVisibleLayer(e,!0,(t=>t.drawPickDepths(this.renderFlags,e)))}drawPickNormals(e){this._withEachVisibleLayer(e,!0,(t=>t.drawPickNormals(this.renderFlags,e)))}_drawSnap(e,t){this._withEachVisibleLayer(e,!0,(s=>s.drawSnap(this.renderFlags,e,t)))}drawSnapInit(e){this._drawSnap(e,!0)}drawSnap(e){this._drawSnap(e,!1)}destroy(){Object.values(this._vboLayers).forEach((e=>e.destroy())),this._vboLayers={},this.scene.camera.off(this._onCameraViewMatrix),this.scene.off(this._onTick);for(let e=0,t=this.layerList.length;e<t;e++)this.layerList[e].destroy();this.layerList=[];for(let e=0,t=this._entityList.length;e<t;e++)this._entityList[e]._destroy();this._layersToFinalize=[],this._geometries={},this._dtxBuckets={},this._textures={},this._textureSets={},this._meshes={},this._entities={},this.scene._aabbDirty=!0,this._isModel&&this.scene._deregisterModel(this),super.destroy()}}class zr extends ie{constructor(e,t={}){if(super(e,t),this._positions=t.positions||[],t.indices)this._indices=t.indices;else{this._indices=[];for(let e=0,t=this._positions.length/3-1;e<t;e+=2)this._indices.push(e),this._indices.push(e+1)}this._color=t.color||[1,1,1],this._opacity=t.opacity||1,this._sceneModel=new jr(this,{isModel:!1}),this._sceneModel.createMesh({id:"linesMesh",primitive:"lines",positions:this._positions,indices:this._indices,color:this._color,opacity:this._opacity}),this._sceneModel.createEntity({meshIds:["linesMesh"],visible:t.visible,clippable:t.clippable,collidable:t.collidable}),this._sceneModel.finalize(),this.scene._lineSetCreated(this)}set visible(e){this._sceneModel.visible=e}get visible(){return this._sceneModel.visible}get positions(){return this._positions}get indices(){return this._indices}destroy(){super.destroy(),this.scene._lineSetDestroyed(this)}}class Wr extends ie{get type(){return"Light"}get isLight(){return!0}constructor(e,t={}){super(e,t)}}class Xr extends Wr{get type(){return"AmbientLight"}constructor(e,t={}){super(e,t),this._state={type:"ambient",color:R.vec3([.7,.7,.7]),intensity:1},this.color=t.color,this.intensity=t.intensity,this.scene._lightCreated(this)}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}get intensity(){return this._state.intensity}destroy(){super.destroy(),this.scene._lightDestroyed(this)}}class Kr{constructor(e,t,s){this.gl=e,this.allocated=!1,this.buffer=null,this.bound=!1,this._colorFormats=t,this._hasDepthTexture=s}setSize(e){this.size=e}bind(){const e=this.size[0],t=this.size[1];if(!this.buffer||this.buffer.width===e&&this.buffer.height===t||(this.buffer.cleanup(),this.buffer=null),this.buffer||(this._allocateBuffer(e,t),this.bound=!1),!this.bound){const e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}_allocateBuffer(e,t){const s=this._colorFormats||[],i=this.gl,r=()=>{const e=i.createTexture();return i.bindTexture(i.TEXTURE_2D,e),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),e},n=(s.length>0?s:[null]).map((s=>{const n=r();return s?i.texStorage2D(i.TEXTURE_2D,1,s,e,t):i.texImage2D(i.TEXTURE_2D,0,i.RGBA,e,t,0,i.RGBA,i.UNSIGNED_BYTE,null),n})),A=i.createRenderbuffer();i.bindRenderbuffer(i.RENDERBUFFER,A),i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_COMPONENT32F,e,t);const o=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,o);for(let e=0;e<n.length;e++)i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+e,i.TEXTURE_2D,n[e],0);s.length>0&&i.drawBuffers(n.map(((e,t)=>i.COLOR_ATTACHMENT0+t)));const a=this._hasDepthTexture&&r();if(a?(i.texImage2D(i.TEXTURE_2D,0,i.DEPTH_COMPONENT32F,e,t,0,i.DEPTH_COMPONENT,i.FLOAT,null),i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,a,0)):i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,A),i.bindTexture(i.TEXTURE_2D,null),i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,o),!i.isFramebuffer(o))throw"Invalid framebuffer";i.bindFramebuffer(i.FRAMEBUFFER,null);const l=i.checkFramebufferStatus(i.FRAMEBUFFER);switch(l){case i.FRAMEBUFFER_COMPLETE:break;case i.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case i.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case i.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case i.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+l}this.buffer={cleanup:()=>{n.forEach((e=>i.deleteTexture(e))),a&&i.deleteTexture(a),i.deleteFramebuffer(o),i.deleteRenderbuffer(A)},framebuf:o,width:e,height:t},this.colorTextures=n.map((e=>({bind:function(t){return i.activeTexture(i["TEXTURE"+t]),i.bindTexture(i.TEXTURE_2D,e),!0}}))),this.depthTexture=a&&{bind:function(e){return i.activeTexture(i["TEXTURE"+e]),i.bindTexture(i.TEXTURE_2D,a),!0}}}read(e,t,s=null,i=null,r=Uint8Array,n=4,A=0){const o=new r(n),a=this.gl;return a.readBuffer(a.COLOR_ATTACHMENT0+A),a.readPixels(e,this.buffer.height-t-1,1,1,s||a.RGBA,i||a.UNSIGNED_BYTE,o,0),o}unbind(){const e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}destroy(){this.allocated&&(this.buffer.cleanup(),this.allocated=!1,this.buffer=null,this.bound=!1),this.colorTextures=null,this.depthTexture=null}}class Zr extends Wr{get type(){return"DirLight"}constructor(e,t={}){super(e,t),this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,i=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=i.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new xe({type:"dir",dir:R.vec3([1,1,1]),color:R.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=R.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,i=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],r=[0,1,0];R.lookAtMat4v(i,s,r,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=R.identityMat4()),R.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new Kr(this.scene.canvas.gl),this._shadowRenderBuf.setSize([1024,1024])),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}function Jr(e){if(!Yr(e.width)||!Yr(e.height)){const t=document.createElement("canvas");t.width=$r(e.width),t.height=$r(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Yr(e){return 0==(e&e-1)}function $r(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class qr extends ie{get type(){return"CubeTexture"}constructor(e,t={}){super(e,t);const s=this.scene.canvas.gl;this._state=new xe({texture:new Kt({gl:s,target:s.TEXTURE_CUBE_MAP}),flipY:this._checkFlipY(t.minFilter),encoding:this._checkEncoding(t.encoding),minFilter:1008,magFilter:1006,wrapS:1001,wrapT:1001,mipmaps:!0}),this._src=t.src,this._images=[],this._loadSrc(t.src),L.memory.textures++}_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}_loadSrc(e){const t=this,s=this.scene.canvas.gl;this._images=[];let i=!1,r=0;for(let n=0;n<e.length;n++){const A=new Image;A.onload=function(){let e=A;const o=n;return function(){if(!i&&(e=Jr(e),t._images[o]=e,r++,6===r)){let e=t._state.texture;e||(e=new Kt({gl:s,target:s.TEXTURE_CUBE_MAP}),t._state.texture=e),e.setImage(t._images,t._state),t.fire("loaded",t._src,!1),t.glRedraw()}}}(),A.onerror=function(){i=!0},A.src=e[n]}}destroy(){super.destroy(),this._state.texture&&this._state.texture.destroy(),L.memory.textures--,this._state.destroy()}}const en=R.vec4(),tn=R.vec4();class sn extends ie{constructor(e,t){super(e,t),this._entity=null,this._visible=null,this._worldPos=R.vec3(),this._origin=R.vec3(),this._rtcPos=R.vec3(),this._viewPos=R.vec3(),this._canvasPos=R.vec2(),this._occludable=!1,this._onCameraViewMatrix=this.scene.camera.on("matrix",(()=>{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(R.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){en.set(this._viewPos),en[3]=1,R.transformPoint4(this.scene.camera.projMatrix,en,tn);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+tn[0]/tn[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-tn[1]/tn[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){this._entity!==e&&(this._cleanupDestroyedHandlers(),this._entity=e,this._entity&&(this._entity.isSceneModelEntity?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0))}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e,this._occludable&&this._renderer.markerWorldPosUpdated(this))}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),dt(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._cleanupDestroyedHandlers(),this._renderer.removeMarker(this),super.destroy()}_cleanupDestroyedHandlers(){this._entity&&(null!==this._onEntityDestroyed&&(this._entity.model?this._entity.model.off(this._onEntityDestroyed):this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model&&this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null))}}class rn{constructor(e){this._eye=R.vec3(),this._look=R.vec3(),this._up=R.vec3(),this._projection={},e&&this.saveCamera(e)}saveCamera(e){const t=e.camera,s=t.project;switch(this._eye.set(t.eye),this._look.set(t.look),this._up.set(t.up),t.projection){case"perspective":this._projection={projection:"perspective",fov:s.fov,fovAxis:s.fovAxis,near:s.near,far:s.far};break;case"ortho":this._projection={projection:"ortho",scale:s.scale,near:s.near,far:s.far};break;case"frustum":this._projection={projection:"frustum",left:s.left,right:s.right,top:s.top,bottom:s.bottom,near:s.near,far:s.far};break;case"custom":this._projection={projection:"custom",matrix:s.matrix.slice()}}}restoreCamera(e,t){const s=e.camera,i=this._projection;function r(){switch(i.type){case"perspective":s.perspective.fov=i.fov,s.perspective.fovAxis=i.fovAxis,s.perspective.near=i.near,s.perspective.far=i.far;break;case"ortho":s.ortho.scale=i.scale,s.ortho.near=i.near,s.ortho.far=i.far;break;case"frustum":s.frustum.left=i.left,s.frustum.right=i.right,s.frustum.top=i.top,s.frustum.bottom=i.bottom,s.frustum.near=i.near,s.frustum.far=i.far;break;case"custom":s.customProjection.matrix=i.matrix}}t?e.viewer.cameraFlight.flyTo({eye:this._eye,look:this._look,up:this._up,orthoScale:i.scale,projection:i.projection},(()=>{r(),t()})):(s.eye=this._eye,s.look=this._look,s.up=this._up,r(),s.projection=i.projection)}}const nn=R.vec3();const An=R.vec3();class on{constructor(){this.objectsVisible=[],this.objectsEdges=[],this.objectsXrayed=[],this.objectsHighlighted=[],this.objectsSelected=[],this.objectsClippable=[],this.objectsPickable=[],this.objectsColorize=[],this.objectsHasColorize=[],this.objectsOpacity=[],this.numObjects=0}saveObjects(e,t){this.numObjects=0,this._mask=t?j.apply(t,{}):null;const s=e.objects,i=!t||t.visible,r=!t||t.edges,n=!t||t.xrayed,A=!t||t.highlighted,o=!t||t.selected,a=!t||t.clippable,l=!t||t.pickable,c=!t||t.colorize,h=!t||t.opacity;for(let e in s)if(s.hasOwnProperty(e)){const t=s[e],u=this.numObjects;if(i&&(this.objectsVisible[u]=t.visible),r&&(this.objectsEdges[u]=t.edges),n&&(this.objectsXrayed[u]=t.xrayed),A&&(this.objectsHighlighted[u]=t.highlighted),o&&(this.objectsSelected[u]=t.selected),a&&(this.objectsClippable[u]=t.clippable),l&&(this.objectsPickable[u]=t.pickable),c){const e=t.colorize;e?(this.objectsColorize[3*u+0]=e[0],this.objectsColorize[3*u+1]=e[1],this.objectsColorize[3*u+2]=e[2],this.objectsHasColorize[u]=!0):this.objectsHasColorize[u]=!1}h&&(this.objectsOpacity[u]=t.opacity),this.numObjects++}}restoreObjects(e){const t=this._mask,s=!t||t.visible,i=!t||t.edges,r=!t||t.xrayed,n=!t||t.highlighted,A=!t||t.selected,o=!t||t.clippable,a=!t||t.pickable,l=!t||t.colorize,c=!t||t.opacity;var h=0;const u=e.objects;for(let e in u)if(u.hasOwnProperty(e)){const t=u[e];s&&(t.visible=this.objectsVisible[h]),i&&(t.edges=this.objectsEdges[h]),r&&(t.xrayed=this.objectsXrayed[h]),n&&(t.highlighted=this.objectsHighlighted[h]),A&&(t.selected=this.objectsSelected[h]),o&&(t.clippable=this.objectsClippable[h]),a&&(t.pickable=this.objectsPickable[h]),l&&(this.objectsHasColorize[h]?(An[0]=this.objectsColorize[3*h+0],An[1]=this.objectsColorize[3*h+1],An[2]=this.objectsColorize[3*h+2],t.colorize=An):t.colorize=null),c&&(t.opacity=this.objectsOpacity[h]),h++}}}const an=R.vec3(),ln=R.vec3(),cn=R.vec4(),hn=R.vec3([0,0,-1]),un=R.vec3([0,0,1]),dn=R.vec3([0,1,0]);class pn extends ie{get type(){return"SectionPlane"}constructor(e,t={}){super(e,t),this._state=new xe({active:!0,pos:R.vec3(),quaternion:R.vec4(),roll:0,dir:R.vec3(),dist:0}),this.active=t.active,this.pos=t.pos,this.dir=t.dir,this.scene._sectionPlaneCreated(this)}set active(e){this._state.active=!1!==e,this.glRedraw(),this.fire("active",this._state.active),this.scene.fire("sectionPlaneUpdated",this)}get active(){return this._state.active}set pos(e){this._state.pos.set(e||[0,0,0]),this._state.dist=-R.dotVec3(this._state.pos,this._state.dir),this.fire("pos",this._state.pos),this.scene.fire("sectionPlaneUpdated",this)}get pos(){return this._state.pos}set quaternion(e){this._state.quaternion.set(e||[0,0,0,-1]),R.vec3ApplyQuaternion(this._state.quaternion,un,this._state.dir);const t=R.vec3ApplyQuaternion(this._state.quaternion,dn,an),s=R.vec3PairToQuaternion(un,this._state.dir,cn),i=R.vec3ApplyQuaternion(s,dn,ln),r=Math.acos(Math.min(1,R.dotVec3(t,i))),n=Math.sign(R.dotVec3(this._state.dir,R.cross3Vec3(t,i,ln)));this._state.roll=n*r,this._onDirUpdated()}get quaternion(){return this._state.quaternion}set roll(e){this._state.roll=e||0,this._onDirRollUpdated()}get roll(){return this._state.roll}set dir(e){this._state.dir.set(e||hn),this._onDirRollUpdated()}_onDirRollUpdated(){R.vec3PairToQuaternion(un,this._state.dir,this._state.quaternion),cn[0]=0,cn[1]=0,cn[2]=-1,cn[3]=this._state.roll,R.angleAxisToQuaternion(cn,cn),R.mulQuaternions(this._state.quaternion,cn,this._state.quaternion),this._onDirUpdated()}_onDirUpdated(){this._state.dist=-R.dotVec3(this._state.pos,this._state.dir),this.glRedraw(),this.fire("dir",this._state.dir),this.scene.fire("sectionPlaneUpdated",this)}get dir(){return this._state.dir}get dist(){return this._state.dist}flipDir(){R.mulVec3Scalar(this._state.dir,-1,this._state.dir),this.dir=this._state.dir}destroy(){this._state.destroy(),this.scene._sectionPlaneDestroyed(this),super.destroy()}}class fn{constructor(){this.entity=null,this.primitive=null,this.primIndex=-1,this.pickSurfacePrecision=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1,this._origin=new Float64Array([0,0,0]),this._direction=new Float64Array([0,0,0]),this._indices=new Int32Array(3),this._localPos=new Float64Array([0,0,0]),this._worldPos=new Float64Array([0,0,0]),this._viewPos=new Float64Array([0,0,0]),this._canvasPos=new Int16Array([0,0]),this._snappedCanvasPos=new Int16Array([0,0]),this._bary=new Float64Array([0,0,0]),this._worldNormal=new Float64Array([0,0,0]),this._uv=new Float64Array([0,0]),this.reset()}get canvasPos(){return this._gotCanvasPos?this._canvasPos:null}set canvasPos(e){e?(this._canvasPos[0]=e[0],this._canvasPos[1]=e[1],this._gotCanvasPos=!0):this._gotCanvasPos=!1}get origin(){return this._gotOrigin?this._origin:null}set origin(e){e?(this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this._gotOrigin=!0):this._gotOrigin=!1}get direction(){return this._gotDirection?this._direction:null}set direction(e){e?(this._direction[0]=e[0],this._direction[1]=e[1],this._direction[2]=e[2],this._gotDirection=!0):this._gotDirection=!1}get indices(){return this.entity&&this._gotIndices?this._indices:null}set indices(e){e?(this._indices[0]=e[0],this._indices[1]=e[1],this._indices[2]=e[2],this._gotIndices=!0):this._gotIndices=!1}get localPos(){return this.entity&&this._gotLocalPos?this._localPos:null}set localPos(e){e?(this._localPos[0]=e[0],this._localPos[1]=e[1],this._localPos[2]=e[2],this._gotLocalPos=!0):this._gotLocalPos=!1}get snappedCanvasPos(){return this._gotSnappedCanvasPos?this._snappedCanvasPos:null}set snappedCanvasPos(e){e?(this._snappedCanvasPos[0]=e[0],this._snappedCanvasPos[1]=e[1],this._gotSnappedCanvasPos=!0):this._gotSnappedCanvasPos=!1}get worldPos(){return this._gotWorldPos?this._worldPos:null}set worldPos(e){e?(this._worldPos[0]=e[0],this._worldPos[1]=e[1],this._worldPos[2]=e[2],this._gotWorldPos=!0):this._gotWorldPos=!1}get viewPos(){return this.entity&&this._gotViewPos?this._viewPos:null}set viewPos(e){e?(this._viewPos[0]=e[0],this._viewPos[1]=e[1],this._viewPos[2]=e[2],this._gotViewPos=!0):this._gotViewPos=!1}get bary(){return this.entity&&this._gotBary?this._bary:null}set bary(e){e?(this._bary[0]=e[0],this._bary[1]=e[1],this._bary[2]=e[2],this._gotBary=!0):this._gotBary=!1}get worldNormal(){return this.entity&&this._gotWorldNormal?this._worldNormal:null}set worldNormal(e){e?(this._worldNormal[0]=e[0],this._worldNormal[1]=e[1],this._worldNormal[2]=e[2],this._gotWorldNormal=!0):this._gotWorldNormal=!1}get uv(){return this.entity&&this._gotUV?this._uv:null}set uv(e){e?(this._uv[0]=e[0],this._uv[1]=e[1],this._gotUV=!0):this._gotUV=!1}get snapped(){return this.snappedToEdge||this.snappedToVertex}reset(){this.entity=null,this.primIndex=-1,this.primitive=null,this.pickSurfacePrecision=!1,this._gotCanvasPos=!1,this._gotSnappedCanvasPos=!1,this._gotOrigin=!1,this._gotDirection=!1,this._gotIndices=!1,this._gotLocalPos=!1,this._gotWorldPos=!1,this._gotViewPos=!1,this._gotBary=!1,this._gotWorldNormal=!1,this._gotUV=!1,this.touchInput=!1,this.snappedToEdge=!1,this.snappedToVertex=!1}}const gn={isIphoneSafari(){const e=window.navigator.userAgent,t=/iPhone/i.test(e),s=/Safari/i.test(e)&&!/Chrome/i.test(e);return t&&s},isIphoneOrIpadSafari(){const e=window.navigator.userAgent,t=/iPhone|iPad/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>2,s=/Safari/i.test(e)&&!/Chrome/i.test(e);return t&&s},isTouchDevice:()=>"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.mxMaxTouchPoints>0};class mn{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}scheduleTask(e){q.scheduleTask(e,null)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const i=this._eventSubs[e];let r;if(i)for(const s in i)i.hasOwnProperty(s)&&(r=i[s],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,s,i){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:s,scope:i||this},this._subIdEvents[n]=t;const A=this._events[t];return void 0!==A&&s.call(i||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 s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const i=this,r=this.on(e,(function(e){i.off(r),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}class _n extends ie{get type(){return"Spinner"}constructor(e,t={}){super(e,t),this._canvas=t.canvas,this._element=null,this._isCustom=!1,t.elementId&&(this._element=document.getElementById(t.elementId),this._element?this._adjustPosition():this.error("Can't find given Spinner HTML element: '"+t.elementId+"' - will automatically create default element")),this._element||this._createDefaultSpinner(),this.processes=0}_createDefaultSpinner(){this._injectDefaultCSS();const e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='<div class="sk-fading-circle"> <div class="sk-circle1 sk-circle"></div> <div class="sk-circle2 sk-circle"></div> <div class="sk-circle3 sk-circle"></div> <div class="sk-circle4 sk-circle"></div> <div class="sk-circle5 sk-circle"></div> <div class="sk-circle6 sk-circle"></div> <div class="sk-circle7 sk-circle"></div> <div class="sk-circle8 sk-circle"></div> <div class="sk-circle9 sk-circle"></div> <div class="sk-circle10 sk-circle"></div> <div class="sk-circle11 sk-circle"></div> <div class="sk-circle12 sk-circle"></div> </div>',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const bn=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class yn extends ie{constructor(e,t={}){super(e,t),this._backgroundColor=R.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;let i=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(i=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{i&&(i=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new _n(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+R.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),i=s.style;i.height="100%",i.width="100%",i.padding="0",i.margin="0",i.background="rgba(0,0,0,0);",i.float="left",i.left="0",i.top="0",i.position="absolute",i.opacity="1.0",i["z-index"]="-10000",s.innerHTML+='<canvas id="'+e+'" style="width: 100%; height: 100%; float: left; margin: 0; padding: 0;"></canvas>',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e<bn.length;e++)try{this.gl=this.canvas.getContext(bn[e],this.contextAttr)}catch(e){}this.gl||(this.error("Failed to get a WebGL context"),this.fire("webglContextFailed",!0,!0));{const e=this.gl;let t="__",s=e.activeTexture;e.activeTexture=function(e){t!==e&&(t=e,s.call(this,e))};let i={},r=e.bindTexture;e.bindTexture=function(e,s){i[t]!==s&&(i[t]=s,r.call(this,e,s))}}this.gl&&this.webgl2&&(this.gl.hint(this.gl.FRAGMENT_SHADER_DERIVATIVE_HINT,this.gl.FASTEST),this.gl,WebGL2RenderingContext)}getSnapshot(e){throw"Canvas#getSnapshot() has been replaced by Viewer#getSnapshot() - use that method instead."}readPixels(e,t,s){return this.scene._renderer.snapshot.readPixels(e,t,s)}loseWebGLContext(){this.canvas.loseContext&&this.canvas.loseContext()}destroy(){this.scene.off(this._tick),this._spinner._destroy(),this.gl=null,super.destroy()}}class Bn{constructor(e){this._matPool=[],this.reset()}reset(){this._matPoolNextFreeIndex=0,this._rtcViewMats={},this.lastProgramId=null,this.pbrEnabled=!1,this.colorTextureEnabled=!1,this.withSAO=!1,this.backfaces=!1,this.frontface=!0,this.textureUnit=0,this.drawElements=0,this.drawArrays=0,this.useProgram=0,this.bindTexture=0,this.bindArray=0,this.pass=0,this.viewParams={},this.viewParams.viewMatrix=null,this.viewParams.projMatrix=null,this.viewParams.near=.01,this.viewParams.far=5e3,this.pickInvisible=!1,this.lineWidth=1,this.snapPickLayerParams=[],this.snapPickCoordinateScale=R.vec3(),this.snapPickOrigin=R.vec3()}getRTCViewMatrix(e,t){let s=this._rtcViewMats[e];return s||(s=this._getNewMat(),ut(this.viewParams.viewMatrix,t,s),this._rtcViewMats[e]=s),s}_getNewMat(){let e=this._matPool[this._matPoolNextFreeIndex];return e||(e=R.mat4(),this._matPool[this._matPoolNextFreeIndex]=e),this._matPoolNextFreeIndex++,e}}const wn={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},vn=document.createElement("canvas");if(vn){const e=vn.getContext("webgl",{antialias:!0})||vn.getContext("experimental-webgl",{antialias:!0});wn.WEBGL=!!e,wn.WEBGL&&(wn.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?wn.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?wn.FS_MAX_FLOAT_PRECISION="mediump":wn.FS_MAX_FLOAT_PRECISION="lowp":wn.FS_MAX_FLOAT_PRECISION="mediump",wn.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),wn.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),wn.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),wn.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),wn.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),wn.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),wn.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),wn.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),wn.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),wn.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){wn.SUPPORTED_EXTENSIONS[e]=!0})))}class Cn{constructor(e){this.aabb=R.AABB3(),this.origin=R.vec3(e),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(e,t){if(this.markerListDirty){for(var s in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(s)&&(this.markerList[this.numMarkers]=this.markers[s],this.markerIndices[s]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0}if(this.positionsDirty){let t=0;for(let e=0;e<this.numMarkers;e++)if(this.markerList[e]){const s=this.markerList[e].rtcPos;this.positions[t++]=s[0],this.positions[t++]=s[1],this.positions[t++]=s[2],this.indices[e]=e}this.positions.length=3*this.numMarkers,this.indices.length=this.numMarkers,this.positionsDirty=!1;const s=this.aabb;R.collapseAABB3(s),R.expandAABB3Points3(s,this.positions);const i=this.origin;s[0]+=i[0],s[1]+=i[1],s[2]+=i[2],s[3]+=i[0],s[4]+=i[1],s[5]+=i[2],this.positionsBuf&&this.lenPositionsBuf!==this.positions.length&&(this.positionsBuf.destroy(),this.positionsBuf=null,this.indicesBuf.destroy(),this.indicesBuf=null);const r=new Float32Array(this.positions);this.positionsBuf?this.positionsBuf.setData(r):(this.positionsBuf=new Ue(e,e.ARRAY_BUFFER,r,r.length,3,e.STATIC_DRAW),this.indicesBuf=new Ue(e,e.ELEMENT_ARRAY_BUFFER,new Uint16Array(this.indices),this.indices.length,1,e.STATIC_DRAW),this.lenPositionsBuf=this.positions.length)}if(this.occlusionTestListDirty){let e=0;this.lenOcclusionTestList=0;for(let s=0;s<this.numMarkers;s++){const i=this.markerList[s];i.entity&&!i.entity.visible||!t(i)?i._setVisible(!1):i.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=i,this.pixels[e++]=i.canvasPos[0],this.pixels[e++]=i.canvasPos[1]):i._setVisible(!0)}}}destroy(){this.markers={},this.markerList.length=0,this.positionsBuf&&this.positionsBuf.destroy(),this.indicesBuf&&this.indicesBuf.destroy()}}const Mn=R.vec3([255,0,0]);R.vec3();class En{constructor(e){this._scene=e,this._occlusionLayers={},this._occlusionLayersList=[],this._occlusionLayersListDirty=!1,this._drawable=null,this._markersToOcclusionLayersMap={};const t=e.camera,s=()=>{this._occlusionTestListDirty=!0};this._onCameraViewMatrix=t.on("viewMatrix",s),this._onCameraProjMatrix=t.on("projMatrix",s),this._onCanvasBoundary=e.canvas.on("boundary",s)}_addMarker(e,t){this._occlusionLayers[t]||(this._occlusionLayers[t]=new Cn(e.origin),this._occlusionLayersListDirty=!0);const s=this._occlusionLayers[t];s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s}_removeMarker(e,t){1===e.numMarkers?(e.destroy(),delete this._occlusionLayers[e.originHash],this._occlusionLayersListDirty=!0):e.removeMarker(t),delete this._markersToOcclusionLayersMap[t.id]}addMarker(e){const t=e.origin.join();this._addMarker(e,t),this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(t){const s=e.origin.join();s!==t.originHash?(this._removeMarker(t,e),this._addMarker(e,s)):t.markerWorldPosUpdated(e)}}removeMarker(e){const t=e.origin.join(),s=this._occlusionLayers[t];s&&this._removeMarker(s,e)}get needOcclusionTest(){return this._occlusionTestListDirty}drawMarkers(){const e=this._scene,t=e.canvas,s=t.gl,i=e._sectionPlanesState,r=[t.canvas.id,i.getHash()].join(";");if(!this._drawable||r!==this._drawable.shaderSourceHash){this._drawable&&this._drawable.destroy();const n=bt(),A=n.programVariables,o=A.createUniform("mat4","viewMatrix"),a=A.createUniform("mat4","projMatrix"),l=A.createAttribute("vec3","position"),c=A.createOutput("vec4","outColor"),h="clipPos",[u,d]=n.buildProgram(s,"OcclusionTester",{sectionPlanesState:i,clippableTest:()=>"true",getVertexData:()=>{const t=[];return t.push(`vec4 worldPosition = vec4(${l}, 1.0);`),t.push(`vec4 ${h} = ${a} * ${o} * worldPosition;`),e.markerZOffset<0&&t.push(`${h}.z += ${e.markerZOffset};`),t},worldPositionAttribute:"worldPosition",getPointSize:()=>"20.0",clipPos:h,appendFragmentOutputs:e=>e.push(`${c} = vec4(1.0, 0.0, 0.0, 1.0);`)});if(d)throw console.error(d.join("\n")),d.join("\n");this._occlusionTestListDirty=!0,this._drawable={shaderSourceHash:r,destroy:()=>u.destroy(),drawCall:()=>{const r=e.camera,n=r.project;u.bind(),a.setInputValue(n.matrix);const A=t.boundary,c=A[2],h=A[3],d=r.perspective.near,p=e=>{const t=e.viewPos,s=e.canvasPos,i=s[0],r=s[1];return t[2]<=-d&&i>=-10&&r>=-10&&i<=c+10&&r<=h+10};this._occlusionLayersList.forEach((e=>{e.update(s,p);const t=i.sectionPlanes.some(((t,s)=>{const i=t.active?R.planeAABB3Intersect(t.dir,t.dist,e.aabb):1,r=-1===i;return e.sectionPlanesActive[s]=0===i,r}));if(!t){const t=e.origin;o.setInputValue(ut(r.viewMatrix,t)),u.inputSetters.setUniforms(null,{view:{far:n.far},mesh:{origin:t,renderFlags:{sectionPlanesActivePerLayer:e.sectionPlanesActive}}}),l.setInputValue(e.positionsBuf);const i=e.indicesBuf;i.bind(),s.drawElements(s.POINTS,i.numItems,i.itemType,0)}}))}}}if(this._occlusionLayersListDirty){let e=0;for(let t in this._occlusionLayers)this._occlusionLayers.hasOwnProperty(t)&&(this._occlusionLayersList[e++]=this._occlusionLayers[t]);this._occlusionLayersList.length=e,this._occlusionLayersListDirty=!1}if(this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e<t;e++){this._occlusionLayersList[e].occlusionTestListDirty=!0}this._occlusionTestListDirty=!1}this._drawable.drawCall()}doOcclusionTest(e){this._occlusionLayersList.forEach((t=>{for(let s=0;s<t.lenOcclusionTestList;s++){const i=2*s,r=e(t.pixels[i],t.pixels[i+1]);t.occlusionTestList[s]._setVisible(R.compareVec3(Mn,r))}}))}destroy(){this.destroyed||(this._occlusionLayersList.forEach((e=>e.destroy())),this._drawable&&this._drawable.destroy(),this._scene.camera.off(this._onCameraViewMatrix),this._scene.camera.off(this._onCameraProjMatrix),this._scene.canvas.off(this._onCanvasBoundary),this.destroyed=!0)}}const Fn=R.vec3([0,0,0]),xn=e=>{const t=[];for(let s=0;s<e;++s)t.push(s);return t},Un=xn(6).map((()=>R.vec4())),In=R.vec4(),Tn=R.vec4([1/4294967296,1/16777216,1/65536,1/256]),Pn=e=>e[0]+(e[1]<<8)+(e[2]<<16)+(e[3]<<24),Sn=e=>R.normalizeVec3(R.divVec3Scalar(e,R.MAX_INT,R.vec3())),Dn=(e,t,s)=>R.vec3([e[0]*s[0]+t[0],e[1]*s[1]+t[1],e[2]*s[2]+t[2]]),kn=(e,t)=>s=>{let i=-1/0,r=1/0;for(let n=0;n<3;n++){const A=e[n],o=t[n],a=s[n],l=s[n+3];if(Math.abs(o)<1e-8){if(A<a||A>l)return!1}else{const e=(a-A)/o,t=(l-A)/o;if(i=Math.max(i,Math.min(e,t)),r=Math.min(r,Math.max(e,t)),i>r)return!1}}return r>=0},Qn=function(t,s){s=s||{};const i=new Bn,r=t.canvas.canvas,n=t.canvas.gl,A=!!s.transparent,o=s.alphaDepthMask,a=new e({});let l={},c={},h=[],u=[],d=[],p=!0,f=!0,g=!0,m=!0,_=!0,b=!0,y=!0,B=!0;const w=function(){const e={},s={};return{getRenderBuffer:(i,r,A)=>{const o=1===t.canvas.resolutionScale?e:s;return o[i]||(o[i]=new Kr(n,r,A)),o[i]},destroy:()=>{Object.values(e).forEach((e=>e.destroy())),Object.values(s).forEach((e=>e.destroy()))}}}(),v=(e,t,s,i)=>{const r=s.programVariables,n=r.createUniform("vec2","uViewportInv"),A=r.createUniform("float","uCameraNear"),o=r.createUniform("float","uCameraFar"),a=r.createUniform("sampler2D","uDepthTexture"),l=r.createAttribute("vec2","uv"),c=r.createVarying("vec2","vUV",(()=>l)),h=r.createOutput("vec4","outColor"),u=r.createFragmentDefinition("getOutColor",((e,t)=>{const s="getDepth";t.push(`\n float getDepth(const in vec2 uv) {\n return texture(${a}, uv).r;\n }\n `),t.push(i(e,c,n,A,o,s))})),[d,p]=s.buildProgram(e,t,{clipPos:`vec4(2.0 * ${l} - 1.0, 0.0, 1.0)`,appendFragmentOutputs:e=>e.push(`${h} = ${u}();`)});if(p)throw console.error(p.join("\n")),p;{const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Ue(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),i=new Uint32Array([0,1,2,0,2,3]),r=new Ue(e,e.ELEMENT_ARRAY_BUFFER,i,i.length,1,e.STATIC_DRAW);return{destroy:d.destroy,bind:(e,t,i)=>{d.bind(),n.setInputValue([1/e[0],1/e[1]]),A.setInputValue(t.near),o.setInputValue(t.far),a.setInputValue(i),l.setInputValue(s)},draw:()=>{r.bind(),e.drawElements(e.TRIANGLES,r.numItems,r.itemType,0)}}}},C=function(){let e=null,t=null;return{destroy:()=>e&&e.destroy(),render:(s,i,r,A)=>{const o=Math.floor(r.numSamples);if(t!==o){e&&e.destroy();const s=bt(),i=s.programVariables,r=i.createUniform("mat4","uProjectMatrix"),A=i.createUniform("mat4","uInvProjMatrix"),a=i.createUniform("bool","uPerspective"),l=i.createUniform("float","uScale"),c=i.createUniform("float","uIntensity"),h=i.createUniform("float","uBias"),u=i.createUniform("float","uKernelRadius"),d=i.createUniform("float","uMinResolution"),p=i.createUniform("float","uRandomSeed"),f=v(n,"SAOOcclusionRenderer",s,((e,t,s,i,n,f)=>`\n #define EPSILON 1e-6\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define NUM_SAMPLES ${o}\n #define NUM_RINGS 4\n\n const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.);\n\n vec4 packFloatToRGBA(const in float v) {\n vec4 r = vec4(fract(v * packFactors), v);\n r.yzw -= r.xyz / 256.;\n return r * 256. / 255.;\n }\n\n highp float rand(const in vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n return fract(sin(mod(dot(uv, vec2(a, b)), PI)) * c);\n }\n\n vec3 getViewPos(const in vec2 screenPos, const in float depth) {\n float near = ${i};\n float far = ${n};\n float viewZ = (${a}\n ? ((near * far) / ((far - near) * depth - far))\n : (depth * (near - far) - near));\n float clipW = ${r}[2][3] * viewZ + ${r}[3][3];\n return (${A} * (clipW * vec4((vec3(screenPos, depth) - 0.5) * 2.0, 1.0))).xyz;\n }\n\n vec4 ${e}() {\n float centerDepth = ${f}(${t});\n if (centerDepth >= (1.0 - EPSILON)) {\n discard;\n }\n\n vec3 centerViewPosition = getViewPos(${t}, centerDepth);\n float scaleDividedByCameraFar = ${l} / ${n};\n float minResolutionMultipliedByCameraFar = ${d} * ${n};\n vec3 centerViewNormal = normalize(cross(dFdx(centerViewPosition), dFdy(centerViewPosition)));\n\n vec2 radiusStep = ${u} * ${s} / float(NUM_SAMPLES);\n vec2 radius = radiusStep;\n const float angleStep = PI2 * float(NUM_RINGS) / float(NUM_SAMPLES);\n float angle = PI2 * rand(${t} + ${p});\n\n float occlusionSum = 0.0;\n float weightSum = 0.0;\n\n for (int i = 0; i < NUM_SAMPLES; i++) {\n vec2 sampleUv = ${t} + vec2(cos(angle), sin(angle)) * radius;\n radius += radiusStep;\n angle += angleStep;\n\n float sampleDepth = ${f}(sampleUv);\n if (sampleDepth >= (1.0 - EPSILON)) {\n continue;\n }\n\n vec3 sampleViewPosition = getViewPos(sampleUv, sampleDepth);\n vec3 viewDelta = sampleViewPosition - centerViewPosition;\n float scaledScreenDistance = scaleDividedByCameraFar * length(viewDelta);\n occlusionSum += max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - ${h}) / (1.0 + scaledScreenDistance * scaledScreenDistance );\n weightSum += 1.0;\n }\n\n return packFloatToRGBA(1.0 - occlusionSum * ${c} / weightSum);\n }`));e={destroy:f.destroy,render:(e,t,s,i)=>{f.bind(e,t,i),r.setInputValue(t.matrix),A.setInputValue(t.inverseMatrix),a.setInputValue("Perspective"===t.type),l.setInputValue(s.scale*t.far/5),c.setInputValue(s.intensity),h.setInputValue(s.bias),u.setInputValue(s.kernelRadius),d.setInputValue(s.minResolution),p.setInputValue(Math.random()),f.draw()}},t=o}e.render(s,i,r,A)}}}(),M=function(){const e=e=>{const t=[];for(let s=0;s<=17;s++)t.push(e[0]*s),t.push(e[1]*s);return new Float32Array(t)},t=e([0,1]),s=e([1,0]),i=new Float32Array(xn(17).map((e=>((e,t)=>Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t))(e,4)))),r=bt(),A=r.programVariables,o=A.createUniform("float","uDepthCutoff"),a=A.createUniformArray("vec2","uSampleOffsets",17),l=A.createUniformArray("float","uSampleWeights",17),c=A.createUniform("sampler2D","uOcclusionTex"),h=v(n,"SAODepthLimitedBlurRenderer",r,((e,t,s,i,r,n)=>`\n #define EPSILON 1e-6\n\n const vec3 packFactors = vec3(256. * 256. * 256., 256. * 256., 256.);\n\n vec4 packFloatToRGBA(const in float v) {\n vec4 r = vec4(fract(v * packFactors), v);\n r.yzw -= r.xyz / 256.;\n return r * 256. / 255.;\n }\n\n float getOcclusion(const in vec2 uv) {\n vec4 v = texture(${c}, uv);\n return dot(floor(v * 255.0 + 0.5) / 255.0, 255. / 256. / vec4(packFactors, 1.)); // unpackRGBAToFloat\n }\n\n float getViewZ(const in float depth) {\n return (${i} * ${r}) / ((${r} - ${i}) * depth - ${r});\n }\n\n vec4 ${e}() {\n float centerDepth = ${n}(${t});\n if (centerDepth >= (1.0 - EPSILON)) {\n discard;\n }\n\n float centerViewZ = getViewZ(centerDepth);\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = ${l}[0];\n float occlusionSum = getOcclusion(${t}) * weightSum;\n\n for (int i = 1; i <= 16; i++) {\n float sampleWeight = ${l}[i];\n vec2 sampleUVOffset = ${a}[i] * ${s};\n\n if (! rBreak) {\n vec2 rSampleUV = ${t} + sampleUVOffset;\n if (abs(centerViewZ - getViewZ(${n}(rSampleUV))) > ${o}) {\n rBreak = true;\n } else {\n occlusionSum += getOcclusion(rSampleUV) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n if (! lBreak) {\n vec2 lSampleUV = ${t} - sampleUVOffset;\n if (abs(centerViewZ - getViewZ(${n}(lSampleUV))) > ${o}) {\n lBreak = true;\n } else {\n occlusionSum += getOcclusion(lSampleUV) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n }\n\n return packFloatToRGBA(occlusionSum / weightSum);\n }`));return{destroy:h.destroy,render:(e,r,n,A,u)=>{h.bind(e,r,A),o.setInputValue(.01),a.setInputValue(0===n?s:t),l.setInputValue(i),c.setInputValue(u),h.draw()}}}(),E=function(){let e=null;return function(){if(!e){const s=t.camera;e={get eye(){return s.eye},get far(){return s.project.far},get projMatrix(){return s.projMatrix},get viewMatrix(){return s.viewMatrix},get viewNormalMatrix(){return s.viewNormalMatrix}}}return e}}(),F=(e,t)=>"ortho"===e.projection?1:t/(2*Math.tan(.5*e.perspective.fov*Math.PI/180));function x(){if(p&&(Object.values(l).forEach((e=>{const t=e.drawableListPreCull;let s=0;Object.values(e.drawableMap).forEach((e=>{t[s++]=e})),t.length=s})),p=!1,f=!0),f){let e=0;Object.values(l).forEach((t=>{t.drawableListPreCull.forEach((t=>{h[e++]=t}))})),h.length=e,h.sort(((e,t)=>e.renderOrder-t.renderOrder)),f=!1,g=!0}if(g){let e=0,t=0;h.forEach((s=>{s.rebuildRenderFlags(),s.renderFlags.culled||(s.isUI?d[t++]=s:u[e++]=s)})),u.length=e,d.length=t}}this.scene=t,this._occlusionTester=null,this.capabilities={astcSupported:!!zt(n,"WEBGL_compressed_texture_astc"),etc1Supported:!0,etc2Supported:!!zt(n,"WEBGL_compressed_texture_etc"),dxtSupported:!!zt(n,"WEBGL_compressed_texture_s3tc"),bptcSupported:!!zt(n,"EXT_texture_compression_bptc"),pvrtcSupported:!(!zt(n,"WEBGL_compressed_texture_pvrtc")&&!zt(n,"WEBKIT_WEBGL_compressed_texture_pvrtc"))},this.setTransparentEnabled=function(e){m=e,g=!0},this.setEdgesEnabled=function(e){_=e,g=!0},this.setSAOEnabled=function(e){b=e,g=!0},this.setPBREnabled=function(e){y=e,g=!0},this.setColorTextureEnabled=function(e){B=e,g=!0},this.needStateSort=function(){f=!0},this.shadowsDirty=function(){},this.imageDirty=function(){g=!0},this.addDrawable=function(e,t){const s=t.type;if(!s)return void console.error("Renderer#addDrawable() : drawable with ID "+e+" has no 'type' - ignoring");let i=l[s];i||(i={type:t.type,count:0,isStateSortable:t.isStateSortable,stateSortCompare:t.stateSortCompare,drawableMap:{},drawableListPreCull:[],drawableList:[]},l[s]=i),i.count++,i.drawableMap[e]=t,c[e]=t,p=!0},this.removeDrawable=function(e){const t=c[e];if(!t)return void console.error("Renderer#removeDrawable() : drawable not found with ID "+e+" - ignoring");const s=t.type,i=l[s];--i.count<=0?delete l[s]:delete i.drawableMap[e],delete c[e],p=!0},this.getPickID=function(e){return a.addItem(e)},this.putPickID=function(e){a.removeItem(e)},this.clear=function(e){if(n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),A)n.clearColor(1,1,1,1);else{const e=t.canvas.backgroundColorFromAmbientLight?this.lights.getAmbientColorAndIntensity():t.canvas.backgroundColor;n.clearColor(e[0],e[1],e[2],1)}n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT)},this.needsRender=function(){return g||p||f},this.render=function(e,s){x(),g&&(!function(e,s){const r=t.sao,a=b&&r.possible&&r.numSamples>=1&&function(e){const s=t.sao,r=[n.drawingBufferWidth,n.drawingBufferHeight],A=w.getRenderBuffer("saoDepth",[],!0);A.setSize(r),A.bind(),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.reset(),i.pass=e,i.viewParams=E(),i.nearPlaneHeight=F(t.camera,n.drawingBufferHeight),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),n.clearColor(0,0,0,0),n.enable(n.DEPTH_TEST),n.frontFace(n.CCW),n.enable(n.CULL_FACE),n.depthMask(!0),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),u.forEach((e=>{!e.culled&&e.visible&&e.drawDepth&&e.saoEnabled&&e.renderFlags.colorOpaque&&e.drawDepth(i)})),A.unbind();const o=A.depthTexture,a=w.getRenderBuffer("saoOcclusion");if(a.setSize(r),a.bind(),n.viewport(0,0,r[0],r[1]),n.clearColor(0,0,0,1),n.disable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT),C.render(r,t.camera.project,s,o),a.unbind(),s.blur){const e=w.getRenderBuffer("saoOcclusion2");e.setSize(r);const s=(e,s,i)=>{s.bind(),n.viewport(0,0,r[0],r[1]),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT);const A=t.camera.project;M.render(r,A,i,o,e.colorTextures[0]),s.unbind()};s(a,e,0),s(e,a,1)}return a.colorTextures[0]}(e);t._lightsState.lights.forEach((e=>{if(e.castsShadow){const s=e.getShadowRenderBuf();s.bind(),i.reset(),i.backfaces=!0,i.frontface=!0,i.viewParams.viewMatrix=e.getShadowViewMatrix(),i.viewParams.projMatrix=e.getShadowProjMatrix(),i.nearPlaneHeight=F(t.camera,n.drawingBufferHeight),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),Object.values(l).forEach((e=>{e.drawableList.forEach((e=>{!1!==e.visible&&e.castsShadow&&e.drawShadow&&e.renderFlags.colorOpaque&&e.drawShadow(i)}))})),s.unbind()}})),function(e,s,r){const a=[],l=[],c=[],h=[],p=[],f=[],g=[],b=[],w=[],v=[],C=[],M=[],x=[],U=[],I=[],T=[],P=t._lightsState.getAmbientColorAndIntensity();if(i.reset(),i.pass=e,i.withSAO=!1,i.pbrEnabled=y&&!!t.pbrEnabled,i.colorTextureEnabled=B&&!!t.colorTextureEnabled,i.viewParams=E(),i.nearPlaneHeight=F(t.camera,n.drawingBufferHeight),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),A)n.clearColor(0,0,0,0);else{const e=t.canvas.backgroundColorFromAmbientLight?P:t.canvas.backgroundColor;n.clearColor(e[0],e[1],e[2],1)}let S,D;n.enable(n.DEPTH_TEST),n.frontFace(n.CCW),n.enable(n.CULL_FACE),n.depthMask(!0),n.lineWidth(1),i.lineWidth=1,t.sao,i.saoParams=[n.drawingBufferWidth,n.drawingBufferHeight,t.sao.blendCutoff,t.sao.blendFactor],i.occlusionTexture=r;const k=Date.now();s&&n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT);i.testAABB=function(e){const t=R.mat4();R.mulMat4(e.projMatrix,e.viewMatrix,t);for(let e=0;e<3;++e)Un[2*e+0][0]=t[3]+t[e],Un[2*e+0][1]=t[7]+t[e+4],Un[2*e+0][2]=t[11]+t[e+8],Un[2*e+0][3]=t[15]+t[e+12],Un[2*e+1][0]=t[3]-t[e],Un[2*e+1][1]=t[7]-t[e+4],Un[2*e+1][2]=t[11]-t[e+8],Un[2*e+1][3]=t[15]-t[e+12];return Un.forEach((e=>R.divVec4Scalar(e,R.lenVec3(e),e))),e=>Un.every((t=>(In[0]=e[t[0]>=0?3:0],In[1]=e[t[1]>=0?4:1],In[2]=e[t[2]>=0?5:2],In[3]=1,R.dotVec4(t,In)>=0)))}(t.camera);const Q=function(e){let s=0,u=0,d=0,y=0,B=0,E=0,F=0,P=0,k=0,Q=0,O=0,V=0,L=0,H=0,N=0,G=0;for(let t=0,n=e.length;t<n;t++){if(D=e[t],!0===D.culled||!1===D.visible)continue;const n=D.renderFlags;n.colorOpaque&&(D.saoEnabled&&r?a[s++]=D:D.drawColorOpaque(i)),m&&n.colorTransparent&&(c[d++]=D),n.xrayedSilhouetteTransparent&&(g[F++]=D),n.xrayedSilhouetteOpaque&&(p[B++]=D),n.highlightedSilhouetteTransparent&&(C[O++]=D),n.highlightedSilhouetteOpaque&&(w[k++]=D),n.selectedSilhouetteTransparent&&(I[N++]=D),n.selectedSilhouetteOpaque&&(x[L++]=D),D.edges&&_&&(n.edgesOpaque&&(l[u++]=D),n.edgesTransparent&&(h[y++]=D),n.selectedEdgesTransparent&&(T[G++]=D),n.selectedEdgesOpaque&&(U[H++]=D),n.xrayedEdgesTransparent&&(b[P++]=D),n.xrayedEdgesOpaque&&(f[E++]=D),n.highlightedEdgesTransparent&&(M[V++]=D),n.highlightedEdgesOpaque&&(v[Q++]=D))}if(s>0)for(i.withSAO=!0,S=0;S<s;S++)a[S].drawColorOpaque(i);if(u>0)for(S=0;S<u;S++)l[S].drawEdgesColorOpaque(i);if(B>0)for(S=0;S<B;S++)p[S].drawSilhouetteXRayed(i);if(E>0)for(S=0;S<E;S++)f[S].drawEdgesXRayed(i);if(F>0||P>0||d>0||y>0){if(n.enable(n.CULL_FACE),n.enable(n.BLEND),A?(n.blendEquation(n.FUNC_ADD),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)):(n.blendEquation(n.FUNC_ADD),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA)),i.backfaces=!1,o||n.depthMask(!1),(d>0||y>0)&&n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),y>0)for(S=0;S<y;S++)D=h[S],D.drawEdgesColorTransparent(i);if(d>0){const e=i.viewParams.eye;c.length=d;const t=c.map((t=>({drawable:t,distSq:R.distVec3(t.origin||Fn,e)})));for(t.sort(((e,t)=>t.distSq-e.distSq)),S=0;S<d;S++)t[S].drawable.drawColorTransparent(i)}if(P>0)for(S=0;S<P;S++)b[S].drawEdgesXRayed(i);if(F>0)for(S=0;S<F;S++)g[S].drawSilhouetteXRayed(i);n.disable(n.BLEND),o||n.depthMask(!0)}if(k>0||Q>0){if(i.lastProgramId=null,t.highlightMaterial.glowThrough&&n.clear(n.DEPTH_BUFFER_BIT),Q>0)for(S=0;S<Q;S++)v[S].drawEdgesHighlighted(i);if(k>0)for(S=0;S<k;S++)w[S].drawSilhouetteHighlighted(i)}if(O>0||V>0||k>0){if(i.lastProgramId=null,t.selectedMaterial.glowThrough&&n.clear(n.DEPTH_BUFFER_BIT),n.enable(n.BLEND),A?(n.blendEquation(n.FUNC_ADD),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)):n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),n.enable(n.CULL_FACE),V>0)for(S=0;S<V;S++)M[S].drawEdgesHighlighted(i);if(O>0)for(S=0;S<O;S++)C[S].drawSilhouetteHighlighted(i);n.disable(n.BLEND)}if(L>0||H>0){if(i.lastProgramId=null,t.selectedMaterial.glowThrough&&n.clear(n.DEPTH_BUFFER_BIT),H>0)for(S=0;S<H;S++)U[S].drawEdgesSelected(i);if(L>0)for(S=0;S<L;S++)x[S].drawSilhouetteSelected(i)}if(N>0||G>0){if(i.lastProgramId=null,t.selectedMaterial.glowThrough&&n.clear(n.DEPTH_BUFFER_BIT),n.enable(n.CULL_FACE),n.enable(n.BLEND),A?(n.blendEquation(n.FUNC_ADD),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)):n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),G>0)for(S=0;S<G;S++)T[S].drawEdgesSelected(i);if(N>0)for(S=0;S<N;S++)I[S].drawSilhouetteSelected(i);n.disable(n.BLEND)}};Q(u),d.length>0&&(n.clear(n.DEPTH_BUFFER_BIT),Q(d));i.testAABB=null;const O=Date.now(),V=L.frame;V.renderTime=(O-k)/1e3,V.drawElements=i.drawElements,V.drawArrays=i.drawArrays,V.useProgram=i.useProgram,V.bindTexture=i.bindTexture,V.bindArray=i.bindArray;const H=wn.MAX_TEXTURE_IMAGE_UNITS;for(let e=0;e<H;e++)n.activeTexture(n.TEXTURE0+e);n.bindTexture(n.TEXTURE_CUBE_MAP,null),n.bindTexture(n.TEXTURE_2D,null);const N=wn.MAX_VERTEX_ATTRIBS;for(let e=0;e<N;e++)n.disableVertexAttribArray(e)}(e,s,a)}(e,s),L.frame.frameCount++,g=!1)};const U=(e,s,i,r,A,o,a)=>{a.reset(),a.backfaces=!0,a.frontface=!0,a.viewParams.eye=r,a.viewParams.projMatrix=A,a.viewParams.viewMatrix=o,a.nearPlaneHeight=F(i,n.drawingBufferHeight);const l=t.canvas.resolutionScale;a.pickClipPos=[e?2*e[0]*l/n.drawingBufferWidth-1:0,e?1-2*e[1]*l/n.drawingBufferHeight:0],a.pickClipPosInv=[n.drawingBufferWidth/s,n.drawingBufferHeight/s]};this.pick=function(){const e=R.vec3(),s=R.vec3(),A=R.vec4(),o=R.vec4(),l=R.vec4(),c=R.vec4(),h=R.vec4(),p=R.mat4(),f=R.mat4(),g=R.mat4(),m=R.mat4(),_=R.vec3([0,1,0]),b=new fn,y=R.vec2(),B=R.vec3(),w=R.vec3(),v=R.vec3();R.vec3(),R.vec3();const C=new Kr(n);C.setSize([1,1]);const M=new Kr(n,[n.RGBA32I]);return M.setSize([3,3]),function(E,F=b){F.reset(),x();let I=null,T=null,P=null;const S=t.camera;if(F.pickSurface=E.pickSurface,E.canvasPos)B[0]=E.canvasPos[0],B[1]=E.canvasPos[1],I=S.viewMatrix,T=S.projMatrix,P=S.projection,y[0]=S.project.near,y[1]=S.project.far,F.canvasPos=E.canvasPos,R.canvasPosToWorldRay(r,I,T,P,B,e,s),i.testAABB=kn(e,s);else if(B[0]=.5*r.clientWidth,B[1]=.5*r.clientHeight,E.matrix)I=E.matrix,T=S.projMatrix,P=S.projection,y[0]=S.project.near,y[1]=S.project.far,R.canvasPosToWorldRay(r,I,T,P,B,e,s),i.testAABB=kn(e,s);else{w.set(E.origin||[0,0,0]),v.set(E.direction||[0,0,1]);const t=R.addVec3(w,v,e),r=s;Math.abs(R.dotVec3(v,_))>.999999?(r[0]=0,r[1]=0,r[2]=Math.sign(v[1])):(R.cross3Vec3(v,_,r),R.cross3Vec3(r,v,r),R.normalizeVec3(r,r)),I=R.lookAtMat4v(w,t,r,f),T=S.ortho.matrix,P="ortho",y[0]=S.ortho.near,y[1]=S.ortho.far,F.origin=w,F.direction=v,i.testAABB=kn(F.origin,F.direction)}C.bind();const D=e=>U(B,e,S,F.origin||S.eye,T||S.projMatrix,I||S.viewMatrix,i);D(1),i.pickInvisible=!!E.pickInvisible,n.viewport(0,0,1,1),n.depthMask(!0),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT);const k=E.includeEntityIds,Q=E.excludeEntityIds,O=function(e){e.forEach((e=>{e.culled||!e.visible||!e.pickable||!e.drawPickMesh||k&&!k[e.id]||Q&&Q[e.id]||e.drawPickMesh(i)}))};O(u),d.length>0&&(n.clear(n.DEPTH_BUFFER_BIT),O(d)),i.testAABB=null;const V=Pn(C.read(0,0)),L=V>=0&&a.items[V];if(!L)return C.unbind(),null;const H=L.delegatePickedEntity?L.delegatePickedEntity():L;if(!H)return C.unbind(),null;if(E.pickSurface)if(L.canPickTriangle&&L.canPickTriangle())L.drawPickTriangles&&(D(1),n.viewport(0,0,1,1),n.clearColor(0,0,0,0),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),L.drawPickTriangles(i),F.primIndex=3*Pn(C.read(0,0))),L.pickTriangleSurface(I,T,P,F),F.pickSurfacePrecision=!1;else if(L.canPickWorldPos&&L.canPickWorldPos()){D(1),i.viewParams.near=y[0],i.viewParams.far=y[1],n.viewport(0,0,1,1),n.clearColor(0,0,0,0),n.depthMask(!0),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),L.drawPickDepths(i);const e=R.dotVec4(C.read(0,0),Tn),t=(B[0]-r.clientWidth/2)/(r.clientWidth/2),s=-(B[1]-r.clientHeight/2)/(r.clientHeight/2),a=L.origin,u=R.inverseMat4(R.mulMat4(T,a?ut(I,a,p):I,g),m),d=(e,i)=>(i[0]=t,i[1]=s,i[2]=e,i[3]=1,R.transformVec4(u,i,i),R.mulVec4Scalar(i,1/i[3])),f=d(-1,A),_=d(1,o),b=R.subVec3(_,f,l),w=R.addVec3(f,R.mulVec4Scalar(b,e,c),h);if(a&&R.addVec3(w,a),F.worldPos=w,!1!==E.pickSurfaceNormal){D(3),M.bind(),n.viewport(0,0,M.size[0],M.size[1]),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.DEPTH_BUFFER_BIT),n.clearBufferiv(n.COLOR,0,new Int32Array([0,0,0,0])),L.drawPickNormals(i);const e=M.read(1,1,n.RGBA_INTEGER,n.INT,Int32Array,4);M.unbind(),F.worldNormal=Sn(e)}F.pickSurfacePrecision=!1}return C.unbind(),F.entity=H,F}}(),this.snapPick=function(){const e=new fn,s=function(){const e={};return t=>{if(!(t in e)){const s=new Kr(n,[n.RGBA32I,n.RGBA32I,n.RGBA8UI],!0);s.setSize([2*t+1,2*t+1]),e[t]=s}return e[t]}}();return function(r,A=e){const{canvasPos:o,origin:l,direction:c,snapRadius:h,snapToVertex:d,snapToEdge:p}=r;if(!d&&!p)return this.pick({canvasPos:o,pickSurface:!0});const f=t.camera,g=h||30,m=o?f.viewMatrix:R.lookAtMat4v(l,R.addVec3(l,c,R.vec3()),R.vec3([0,1,0]),R.mat4());U(o,2*g,f,f.eye,f.projMatrix,m,i);const _=s(g);_.bind(),n.viewport(0,0,_.size[0],_.size[1]),n.enable(n.DEPTH_TEST),n.frontFace(n.CCW),n.disable(n.CULL_FACE),n.depthMask(!0),n.disable(n.BLEND),n.depthFunc(n.LEQUAL),n.clear(n.DEPTH_BUFFER_BIT),n.clearBufferiv(n.COLOR,0,new Int32Array([0,0,0,0])),n.clearBufferiv(n.COLOR,1,new Int32Array([0,0,0,0])),n.clearBufferuiv(n.COLOR,2,new Uint32Array([0,0,0,0])),n.drawBuffers([n.COLOR_ATTACHMENT0,n.COLOR_ATTACHMENT1,n.COLOR_ATTACHMENT2]),i.snapPickLayerParams=[],i.snapPickLayerParams.push(null),u.forEach((e=>{!e.culled&&e.visible&&e.pickable&&e.drawSnapInit&&e.drawSnapInit(i)}));const b=i.snapPickLayerParams;i.snapPickLayerParams=[],n.depthMask(!1),n.drawBuffers([n.COLOR_ATTACHMENT0]);const y=e=>{i.snapMode=e,i.snapPickLayerParams.push(null),u.forEach((e=>{!e.culled&&e.visible&&e.pickable&&e.drawSnap&&e.drawSnap(i)}))};p&&y("edge"),d&&y("vertex"),n.depthMask(!0);const B=i.snapPickLayerParams,w=(e,t,s)=>{const i=_.buffer.width,r=_.buffer.height,A=new t(4*i*r);return n.readBuffer(e),n.readPixels(0,0,i,r,n.RGBA_INTEGER,s,A,0),A},v=w(n.COLOR_ATTACHMENT0,Int32Array,n.INT),C=w(n.COLOR_ATTACHMENT1,Int32Array,n.INT),M=w(n.COLOR_ATTACHMENT2,Uint32Array,n.UNSIGNED_INT);_.unbind();let E=null,F=null,x=null;const I=4*g+g*_.size[0]*4,T=v.slice(I,I+4),P=C.slice(I,I+4),S=M.slice(I,I+4);if(0!==T[3]){const e=b[Math.abs(T[3])%b.length];E=Dn(T,e.origin,e.coordinateScale),F=Sn(P),x=a.items[Pn(S)]}const D=[];for(let e=0;e<v.length;e+=4){const t=v[e+3];if(t>0){const s=Math.floor(e/4),i=_.size[0],r=s%i-Math.floor(i/2),n=Math.floor(s/i)-Math.floor(i/2);D.push({dist:R.lenVec2([r,n]),isVertex:d&&p?t>B.length/2:d,result:v.subarray(e,e+4),normal:C.subarray(e,e+4),id:M.subarray(e,e+4)})}}const k=e=>e&&e.delegatePickedEntity?e.delegatePickedEntity():e;if(D.length>0){const e=D.reduce(((e,t)=>(e.isVertex-t.isVertex||t.dist-e.dist)>0?e:t)),t=e.result,s=B[t[3]],i=Dn(t,s.origin,s.coordinateScale),r=f.projectWorldPos(i);return A.reset(),A.snappedToEdge=!e.isVertex,A.snappedToVertex=e.isVertex,A.worldPos=i,A.worldNormal=Sn(e.normal),A.entity=k(a.items[Pn(e.id)]),A.canvasPos=o||E&&f.projectWorldPos(E)||r,A.snappedCanvasPos=r,A}return E?(A.reset(),A.snappedToEdge=!1,A.snappedToVertex=!1,A.worldPos=E,A.worldNormal=F,A.entity=k(x),A.canvasPos=o||f.projectWorldPos(E),A.snappedCanvasPos=o,A):null}}(),this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new En(t),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){x();const e=w.getRenderBuffer("occlusionReadPix");if(e&&(e.setSize([n.drawingBufferWidth,n.drawingBufferHeight]),e.bind()),i.reset(),i.backfaces=!0,i.frontface=!0,i.viewParams=E(),i.nearPlaneHeight=F(t.camera,n.drawingBufferHeight),n.viewport(0,0,n.drawingBufferWidth,n.drawingBufferHeight),n.clearColor(0,0,0,0),n.enable(n.DEPTH_TEST),n.disable(n.CULL_FACE),n.disable(n.BLEND),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),u.forEach((e=>{!e.culled&&e.visible&&e.pickable&&e.drawOcclusion&&e.drawOcclusion(i)})),this._occlusionTester.drawMarkers(),e){const s=t.canvas.resolutionScale;this._occlusionTester.doOcclusionTest(((t,i)=>e.read(Math.round(s*t),Math.round(s*i)))),e.unbind()}}},this.snapshot=(()=>{let e=!1;const t=new Kr(n);let s=null;return{readPixels:(e,s,i)=>{t.bind(),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),g=!0,this.render();for(let r=0;r<i;r++){const i=2*r,n=4*r,A=t.read(e[i],e[i+1]);s[n]=A[0],s[n+1]=A[1],s[n+2]=A[2],s[n+3]=A[3]}t.unbind(),g=!0},beginSnapshot:()=>{t.setSize([n.drawingBufferWidth,n.drawingBufferHeight]),t.bind(),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),e=!0},renderSnapshotToCanvas:()=>{const i=t.buffer.width,r=t.buffer.height;return s&&s.width===i&&s.height===r||(s=function(){const e=document.createElement("canvas"),t=e.getContext("2d");e.width=i,e.height=r;const s=new Uint8Array(i*r*4),A=t.createImageData(i,r);return{width:i,height:r,getUpdatedCanvas:()=>{n.readPixels(0,0,i,r,n.RGBA,n.UNSIGNED_BYTE,s);const o=Math.floor(r/2),a=4*i,l=new Uint8Array(a);for(let e=0;e<o;++e){const t=e*a,i=(r-e-1)*a;l.set(s.subarray(t,t+a)),s.copyWithin(t,i,i+a),s.set(l,i)}return A.data.set(s),t.resetTransform(),t.putImageData(A,0,0),e}}}()),e&&(n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),g=!0,this.render(),g=!0),s.getUpdatedCanvas()},endSnapshot:()=>{e&&(t.unbind(),e=!1),g=!0,this.render()}}})(),this.destroy=function(){l={},c={},w.destroy(),C.destroy(),M.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}};class Rn extends ie{constructor(e,t={}){super(e,t),this.KEY_BACKSPACE=8,this.KEY_TAB=9,this.KEY_ENTER=13,this.KEY_SHIFT=16,this.KEY_CTRL=17,this.KEY_ALT=18,this.KEY_PAUSE_BREAK=19,this.KEY_CAPS_LOCK=20,this.KEY_ESCAPE=27,this.KEY_PAGE_UP=33,this.KEY_PAGE_DOWN=34,this.KEY_END=35,this.KEY_HOME=36,this.KEY_LEFT_ARROW=37,this.KEY_UP_ARROW=38,this.KEY_RIGHT_ARROW=39,this.KEY_DOWN_ARROW=40,this.KEY_INSERT=45,this.KEY_DELETE=46,this.KEY_NUM_0=48,this.KEY_NUM_1=49,this.KEY_NUM_2=50,this.KEY_NUM_3=51,this.KEY_NUM_4=52,this.KEY_NUM_5=53,this.KEY_NUM_6=54,this.KEY_NUM_7=55,this.KEY_NUM_8=56,this.KEY_NUM_9=57,this.KEY_A=65,this.KEY_B=66,this.KEY_C=67,this.KEY_D=68,this.KEY_E=69,this.KEY_F=70,this.KEY_G=71,this.KEY_H=72,this.KEY_I=73,this.KEY_J=74,this.KEY_K=75,this.KEY_L=76,this.KEY_M=77,this.KEY_N=78,this.KEY_O=79,this.KEY_P=80,this.KEY_Q=81,this.KEY_R=82,this.KEY_S=83,this.KEY_T=84,this.KEY_U=85,this.KEY_V=86,this.KEY_W=87,this.KEY_X=88,this.KEY_Y=89,this.KEY_Z=90,this.KEY_LEFT_WINDOW=91,this.KEY_RIGHT_WINDOW=92,this.KEY_SELECT_KEY=93,this.KEY_NUMPAD_0=96,this.KEY_NUMPAD_1=97,this.KEY_NUMPAD_2=98,this.KEY_NUMPAD_3=99,this.KEY_NUMPAD_4=100,this.KEY_NUMPAD_5=101,this.KEY_NUMPAD_6=102,this.KEY_NUMPAD_7=103,this.KEY_NUMPAD_8=104,this.KEY_NUMPAD_9=105,this.KEY_MULTIPLY=106,this.KEY_ADD=107,this.KEY_SUBTRACT=109,this.KEY_DECIMAL_POINT=110,this.KEY_DIVIDE=111,this.KEY_F1=112,this.KEY_F2=113,this.KEY_F3=114,this.KEY_F4=115,this.KEY_F5=116,this.KEY_F6=117,this.KEY_F7=118,this.KEY_F8=119,this.KEY_F9=120,this.KEY_F10=121,this.KEY_F11=122,this.KEY_F12=123,this.KEY_NUM_LOCK=144,this.KEY_SCROLL_LOCK=145,this.KEY_SEMI_COLON=186,this.KEY_EQUAL_SIGN=187,this.KEY_COMMA=188,this.KEY_DASH=189,this.KEY_PERIOD=190,this.KEY_FORWARD_SLASH=191,this.KEY_GRAVE_ACCENT=192,this.KEY_OPEN_BRACKET=219,this.KEY_BACK_SLASH=220,this.KEY_CLOSE_BRACKET=221,this.KEY_SINGLE_QUOTE=222,this.KEY_SPACE=32,this.MOUSE_LEFT_BUTTON=260,this.MOUSE_MIDDLE_BUTTON=261,this.MOUSE_RIGHT_BUTTON=262,this.element=t.element,this.altDown=!1,this.ctrlDown=!1,this.mouseDownLeft=!1,this.mouseDownMiddle=!1,this.mouseDownRight=!1,this.keyDown=[],this.enabled=!0,this.keyboardEnabled=!0,this.mouseover=!1,this.mouseCanvasPos=R.vec2(),this._keyboardEventsElement=t.keyboardEventsElement||document,this._bindEvents()}_bindEvents(){if(this._eventsBound)return;this._keyboardEventsElement.addEventListener("keydown",this._keyDownListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}});const e=this.scene.tickify((()=>this.fire("mousemove",this.mouseCanvasPos,!0)));this.element.addEventListener("mousemove",this._mouseMoveListener=t=>{this.enabled&&(this._getMouseCanvasPos(t),e(),this.mouseover&&t.preventDefault())}),this.element.addEventListener("contextmenu",this._contextmenuListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("contextmenu",this.mouseCanvasPos,!0))});const t=this.scene.tickify((e=>{this.fire("mousewheel",e,!0)}));this.element.addEventListener("wheel",this._mouseWheelListener=(e,s)=>{if(!this.enabled)return;const i=Math.max(-1,Math.min(1,40*-e.deltaY));t(i)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(i=>{e>=i[0]-s&&e<=i[0]+s&&t>=i[1]-s&&t<=i[1]+s&&this.fire("mouseclicked",i,!0)}))}this.element.addEventListener("touchstart",this._touchstartListener=e=>{this.enabled&&[...e.changedTouches].forEach((e=>{this.fire("touchstart",[e.identifier,this._getTouchCanvasPos(e)],!0)}))}),this.element.addEventListener("touchend",this._touchendListener=e=>{this.enabled&&[...e.changedTouches].forEach((e=>{this.fire("touchend",[e.identifier,this._getTouchCanvasPos(e)],!0)}))}),this._eventsBound=!0}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("contextmenu",this._contextmenuListener),this.element.removeEventListener("wheel",this._mouseWheelListener),this.element.removeEventListener("touchstart",this._touchstartListener),this.element.removeEventListener("touchend",this._touchendListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getTouchCanvasPos(e){let t=e.target,s=0,i=0;for(;t.offsetParent;)s+=t.offsetLeft,i+=t.offsetTop,t=t.offsetParent;return[e.pageX-s,e.pageY-i]}_getMouseCanvasPos(e){if(e){const t=e.target.getBoundingClientRect();this.mouseCanvasPos[0]=e.clientX-t.left,this.mouseCanvasPos[1]=e.clientY-t.top}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}class On extends ie{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new xe({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class Vn extends ie{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new xe({matrix:R.mat4(),inverseMatrix:R.mat4(),transposedMatrix:R.mat4(),near:.1,far:1e4}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.canvas.boundary,t=e[2]/e[3],s=this._fovAxis;let i=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(i/=t),i=Math.min(i,120),R.perspectiveMat4(i*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:1e4;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(R.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(R.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,i,r){const n=this.scene.canvas.canvas,A=n.offsetWidth/2,o=n.offsetHeight/2;return s[0]=(e[0]-A)/A,s[1]=(e[1]-o)/o,s[2]=t,s[3]=1,R.mulMat4v4(this.inverseMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1,R.mulMat4v4(this.camera.inverseViewMatrix,i,r),r}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class Ln extends ie{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new xe({matrix:R.mat4(),inverseMatrix:R.mat4(),transposedMatrix:R.mat4(),near:.1,far:1e4}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.canvas.boundary,i=s[2],r=s[3],n=i/r;let A,o,a,l;i>r?(A=-t,o=t,a=t/n,l=-t/n):(A=-t*n,o=t*n,a=t,l=-t),R.orthoMat4c(A,o,l,a,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:1e4;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(R.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(R.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,i,r){const n=this.scene.canvas.canvas,A=n.offsetWidth/2,o=n.offsetHeight/2;return s[0]=(e[0]-A)/A,s[1]=(e[1]-o)/o,s[2]=t,s[3]=1,R.mulMat4v4(this.inverseMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1,R.mulMat4v4(this.camera.inverseViewMatrix,i,r),r}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class Hn extends ie{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new xe({matrix:R.mat4(),inverseMatrix:R.mat4(),transposedMatrix:R.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){R.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(R.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(R.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,i,r){const n=this.scene.canvas.canvas,A=n.offsetWidth/2,o=n.offsetHeight/2;return s[0]=(e[0]-A)/A,s[1]=(e[1]-o)/o,s[2]=t,s[3]=1,R.mulMat4v4(this.inverseMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1,R.mulMat4v4(this.camera.inverseViewMatrix,i,r),r}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class Nn extends ie{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new xe({matrix:R.mat4(),inverseMatrix:R.mat4(),transposedMatrix:R.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(R.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(R.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,i,r){const n=this.scene.canvas.canvas,A=n.offsetWidth/2,o=n.offsetHeight/2;return s[0]=(e[0]-A)/A,s[1]=(e[1]-o)/o,s[2]=t,s[3]=1,R.mulMat4v4(this.inverseMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1,R.mulMat4v4(this.camera.inverseViewMatrix,i,r),r}destroy(){super.destroy(),this._state.destroy()}}const Gn=R.vec3(),jn=R.vec3(),zn=R.vec3(),Wn=R.vec3(),Xn=R.vec3(),Kn=R.vec3(),Zn=R.vec4(),Jn=R.vec4(),Yn=R.vec4(),$n=R.mat4(),qn=R.mat4(),eA=R.vec3(),tA=R.vec3(),sA=R.vec3(),iA=R.vec3();class rA extends ie{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new xe({offsetEyeFromLook:!0,deviceMatrix:R.mat4(),hasDeviceMatrix:!1,matrix:R.mat4(),normalMatrix:R.mat4(),inverseMatrix:R.mat4()}),this._perspective=new Vn(this),this._ortho=new Ln(this),this._frustum=new Hn(this),this._customProjection=new Nn(this),this._project=this._perspective,this._eye=R.vec3([0,0,10]),this._look=R.vec3([0,0,0]),this._up=R.vec3([0,1,0]),this._worldUp=R.vec3([0,1,0]),this._worldRight=R.vec3([1,0,0]),this._worldForward=R.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection&&this._state.offsetEyeFromLook?(R.subVec3(this._eye,this._look,eA),R.normalizeVec3(eA,tA),R.mulVec3Scalar(tA,1e3,sA),R.addVec3(this._look,sA,iA),t=iA):t=this._eye,e.hasDeviceMatrix?(R.lookAtMat4v(t,this._look,this._up,qn),R.mulMat4(e.deviceMatrix,qn,e.matrix)):R.lookAtMat4v(t,this._look,this._up,e.matrix),R.inverseMat4(this._state.matrix,this._state.inverseMatrix),R.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=R.subVec3(this._eye,this._look,Gn);R.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,$n),t=R.transformPoint3($n,t,jn),this.eye=R.addVec3(this._look,t,zn),this.up=R.transformPoint3($n,this._up,Wn)}orbitPitch(e){if(this._constrainPitch&&(e=R.dotVec3(this._up,this._worldUp)/R.DEGTORAD)<1)return;let t=R.subVec3(this._eye,this._look,Gn);const s=R.cross3Vec3(R.normalizeVec3(t,jn),R.normalizeVec3(this._up,zn));R.rotationMat4v(.0174532925*e,s,$n),t=R.transformPoint3($n,t,Wn),this.up=R.transformPoint3($n,this._up,Xn),this.eye=R.addVec3(t,this._look,Kn)}yaw(e){let t=R.subVec3(this._look,this._eye,Gn);R.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,$n),t=R.transformPoint3($n,t,jn),this.look=R.addVec3(t,this._eye,zn),this._gimbalLock&&(this.up=R.transformPoint3($n,this._up,Wn))}pitch(e){if(this._constrainPitch&&(e=R.dotVec3(this._up,this._worldUp)/R.DEGTORAD)<1)return;let t=R.subVec3(this._look,this._eye,Gn);const s=R.cross3Vec3(R.normalizeVec3(t,jn),R.normalizeVec3(this._up,zn));R.rotationMat4v(.0174532925*e,s,$n),this.up=R.transformPoint3($n,this._up,Kn),t=R.transformPoint3($n,t,Wn),this.look=R.addVec3(t,this._eye,Xn)}pan(e){const t=R.subVec3(this._eye,this._look,Gn),s=[0,0,0];let i;if(0!==e[0]){const r=R.cross3Vec3(R.normalizeVec3(t,[]),R.normalizeVec3(this._up,jn));i=R.mulVec3Scalar(r,e[0]),s[0]+=i[0],s[1]+=i[1],s[2]+=i[2]}0!==e[1]&&(i=R.mulVec3Scalar(R.normalizeVec3(this._up,zn),e[1]),s[0]+=i[0],s[1]+=i[1],s[2]+=i[2]),0!==e[2]&&(i=R.mulVec3Scalar(R.normalizeVec3(t,Wn),e[2]),s[0]+=i[0],s[1]+=i[1],s[2]+=i[2]),this.eye=R.addVec3(this._eye,s,Xn),this.look=R.addVec3(this._look,s,Kn)}zoom(e){const t=R.subVec3(this._eye,this._look,Gn),s=Math.abs(R.lenVec3(t,jn)),i=Math.abs(s+e);if(i<.5)return;const r=R.normalizeVec3(t,zn);this.eye=R.addVec3(this._look,R.mulVec3Scalar(r,i),Wn)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=R.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return R.lenVec3(R.subVec3(this._look,this._eye,Gn))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}get offsetEyeFromLook(){return this._state.offsetEyeFromLook}set offsetEyeFromLook(e){this._state.offsetEyeFromLook=e,this._needUpdate(0)}projectWorldPos(e){const t=Zn,s=Jn,i=Yn;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,R.mulMat4v4(this.viewMatrix,t,s),R.mulMat4v4(this.projMatrix,s,i),R.mulVec3Scalar(i,1/i[3]),i[3]=1,i[1]*=-1;const r=this.scene.canvas.canvas,n=r.offsetWidth/2,A=r.offsetHeight/2;return[i[0]*n+n,i[1]*A+A]}destroy(){super.destroy(),this._state.destroy()}}const nA={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class AA extends ie{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=R.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return nA}set units(e){e||(e="meters");nA[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=R.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=R.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class oA extends ie{constructor(e,t={}){super(e,t),this._supported=wn.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}class aA extends ie{constructor(e,t={}){super(e,t),this.sliceColor=t.sliceColor,this.sliceThickness=t.sliceThickness}set sliceThickness(e){null==e&&(e=0),this._sliceThickness!==e&&(this._sliceThickness=e,this.glRedraw())}get sliceThickness(){return this._sliceThickness}set sliceColor(e){null==e&&(e=[0,0,0,1]),this._sliceColor!==e&&(this._sliceColor=e,this.glRedraw())}get sliceColor(){return this._sliceColor}destroy(){super.destroy()}}const lA={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class cA extends Ht{get type(){return"PointsMaterial"}get presets(){return lA}constructor(e,t={}){super(e,t),this._state=new xe({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=lA[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(lA).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const hA={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class uA extends Ht{get type(){return"LinesMaterial"}get presets(){return hA}constructor(e,t={}){super(e,t),this._state=new xe({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=hA[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(hA).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}const dA=R.vec3();class pA{constructor(e){let t=null;const s={},i=[];this.destroy=()=>t&&t();let r=null;const n=()=>{clearTimeout(r),r=setTimeout((()=>{const t=Object.values(e.models).filter((e=>e.id in s&&e.visible));i.forEach((i=>{if(i.active){const r=R.makeSectionPlaneSlicer(i);t.forEach((t=>{const n=t.aabb;if(R.planeIntersectsAABB3(i,n)){const A=R.getAABB3Center(n,R.vec3());s[t.id].entityCaches.forEach(((s,n)=>{const o=t.objects[n];s.generateCaps&&o.capMaterial&&R.planeIntersectsAABB3(i,o.aabb)&&(s.meshCaches||=o.meshes.filter((e=>e.isSolid())).map((e=>{const t=[],s=[];return e.getEachIndex((e=>t.push(e))),e.getEachVertex((e=>s.push(...R.subVec3(e,A,dA)))),{mesh:e,meshIndices:t,meshVertices:s}})),s.meshCaches.filter((e=>R.planeIntersectsAABB3(i,e.mesh.aabb))).forEach(((t,a)=>{const l=r({origin:A,indices:t.meshIndices,positions:t.meshVertices},{onlyPosSliceWithUV:!0}).pos;l&&s.capMeshes.push(new Ot(e,{isObject:!0,id:`${i.id}-${n}-${a}`,material:o.capMaterial,origin:R.addVec3(A,R.mulVec3Scalar(i.dir,.001,dA),dA),geometry:new Le(e,{primitive:"triangles",indices:l.indices,positions:l.positions,normals:l.normals,uv:l.uv})}))})))}))}}))}})),t.forEach((e=>s[e.id].entityCaches.forEach((e=>e.generateCaps=!1))))}),100)};this._onCapMaterialUpdated=A=>{if(!t){r=null;const A=e=>{const t=()=>{Object.values(s).forEach((e=>e.entityCaches.forEach((e=>{e.destroyCaps(),e.generateCaps=!0})))),n()};i.push(e),e.on("pos",t),e.on("dir",t),e.on("active",t),e.once("destroyed",(()=>{const s=i.indexOf(e);s>=0&&(i.splice(s,1),t())}))};for(const t in e.sectionPlanes)A(e.sectionPlanes[t]);const o=e.on("sectionPlaneCreated",A),a=e.on("tick",(()=>{let t=!1;for(const i in s){const r=e.models[i];if(r){if(s[i].modelVisible!=r.visible){const e=s[i];e.modelVisible=!!r.visible,e.entityCaches.forEach((e=>{e.destroyCaps(),e.generateCaps=!0})),t=!0}}else s[i].entityCaches.forEach((e=>e.destroyCaps())),delete s[i],t=!0}t&&n()}));t=()=>{for(const e in s)s[e].entityCaches.forEach((e=>e.destroyCaps()));e.off(o),e.off(a)}}const o=A.model,a=o.id;s[a]||={modelVisible:o.visible,entityCaches:new Map};const l=s[a].entityCaches,c=A.id;if(!l.has(c)){const e={capMeshes:[],meshCaches:null,generateCaps:!1,destroyCaps:()=>{e.capMeshes.forEach((e=>e.destroy())),e.capMeshes.length=0}};l.set(c,e)}const h=l.get(c);h.destroyCaps(),h.generateCaps=!0,n()}}}function fA(e,t){const s={};let i,r;for(let n=0,A=t.length;n<A;n++)i=t[n],r=e.components[i],r?r.isEntity?s[i]=!0:e.warn("pick(): Component is not an Entity: "+i):e.warn("pick(): Component not found: "+i);return s}class gA extends ie{get type(){return"Scene"}constructor(e,t={}){super(null,t);const s=t.canvasElement||document.querySelector(`#${t.canvasId}`);if(!(s instanceof HTMLCanvasElement))throw"Mandatory config expected: valid canvasId or canvasElement";this._tickifiedFunctions={};const i=!!t.transparent,r=!!t.alphaDepthMask;this._aabbDirty=!0,this._readableGeometry=!!t.readableGeometryEnabled,this.viewer=e,this.occlusionTestCountdown=0,this.loading=0,this.startTime=(new Date).getTime(),this.models={},this.objects={},this._numObjects=0,this.visibleObjects={},this._numVisibleObjects=0,this.xrayedObjects={},this._numXRayedObjects=0,this.highlightedObjects={},this._numHighlightedObjects=0,this.selectedObjects={},this._numSelectedObjects=0,this.colorizedObjects={},this._numColorizedObjects=0,this.opacityObjects={},this._numOpacityObjects=0,this.offsetObjects={},this._numOffsetObjects=0,this._modelIds=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this._opacityObjectIds=null,this._offsetObjectIds=null,this._collidables={},this._compilables={},this._needRecompile=!1,this.types={},this.components={},this.sectionPlanes={},this.lights={},this.lightMaps={},this.reflectionMaps={},this.bitmaps={},this.lineSets={},this.realWorldOffset=t.realWorldOffset||new Float64Array([0,0,0]),this.canvas=new yn(this,{dontClear:!0,canvas:s,spinnerElementId:t.spinnerElementId,transparent:i,webgl2:!1!==t.webgl2,contextAttr:t.contextAttr||{},backgroundColor:t.backgroundColor,backgroundColorFromAmbientLight:t.backgroundColorFromAmbientLight,premultipliedAlpha:t.premultipliedAlpha});const n=e=>this.viewer.destroy();s.addEventListener("webglcontextlost",n,!1),this._removeWebglcontextlostListener=()=>s.removeEventListener("webglcontextlost",n,!1),this.canvas.on("boundary",(()=>{this.glRedraw()})),this.canvas.on("webglContextFailed",(()=>{alert("xeokit failed to find WebGL!")})),this._renderer=new Qn(this,{transparent:i,alphaDepthMask:r}),this.canvas._renderer=this._renderer,this._sectionPlanesState=new function(){this.sectionPlanes=[],this.clippingCaps=!1,this._numCachedSectionPlanes=0;let e=null;this.getHash=function(){if(e)return e;const t=this.getNumAllocatedSectionPlanes();if(this.sectionPlanes,0===t)return this.hash=";";const s=[];for(let e=0,i=t;e<i;e++)s.push("cp");return s.push(";"),e=s.join(""),e},this.addSectionPlane=function(t){this.sectionPlanes.push(t),e=null},this.removeSectionPlane=function(t){for(let s=0,i=this.sectionPlanes.length;s<i;s++)if(this.sectionPlanes[s].id===t.id)return this.sectionPlanes.splice(s,1),void(e=null)},this.setNumCachedSectionPlanes=function(t){this._numCachedSectionPlanes=t,e=null},this.getNumCachedSectionPlanes=function(){return this._numCachedSectionPlanes},this.getNumAllocatedSectionPlanes=function(){const e=this.sectionPlanes.length;return e>this._numCachedSectionPlanes?e:this._numCachedSectionPlanes}},this._sectionPlanesState.setNumCachedSectionPlanes(t.numCachedSectionPlanes||0),this._lightsState=new function(){const e=R.vec4([0,0,0,0]),t=R.vec4();this.lights=[],this.reflectionMaps=[],this.lightMaps=[];let s=null,i=null;this.getHash=function(){if(s)return s;const e=[],t=this.lights;let i;for(let s=0,r=t.length;s<r;s++)i=t[s],e.push("/"),e.push(i.type),e.push("world"===i.space?"w":"v"),i.castsShadow&&e.push("sh");return this.lightMaps.length>0&&e.push("/lm"),this.reflectionMaps.length>0&&e.push("/rm"),e.push(";"),s=e.join(""),s},this.addLight=function(e){this.lights.push(e),i=null,s=null},this.removeLight=function(e){for(let t=0,r=this.lights.length;t<r;t++){if(this.lights[t].id===e.id)return this.lights.splice(t,1),i&&i.id===e.id&&(i=null),void(s=null)}},this.addReflectionMap=function(e){this.reflectionMaps.push(e),s=null},this.removeReflectionMap=function(e){for(let t=0,i=this.reflectionMaps.length;t<i;t++)if(this.reflectionMaps[t].id===e.id)return this.reflectionMaps.splice(t,1),void(s=null)},this.addLightMap=function(e){this.lightMaps.push(e),s=null},this.removeLightMap=function(e){for(let t=0,i=this.lightMaps.length;t<i;t++)if(this.lightMaps[t].id===e.id)return this.lightMaps.splice(t,1),void(s=null)},this.getAmbientColorAndIntensity=function(){if(!i)for(let e=0,t=this.lights.length;e<t;e++){const t=this.lights[e];if("ambient"===t.type){i=t;break}}if(i){const e=i.color,s=i.intensity;return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=s,t}return e}},this.input=new Rn(this,{dontClear:!0,element:this.canvas.canvas,keyboardEventsElement:t.keyboardEventsElement}),this.metrics=new AA(this,{units:t.units,scale:t.scale,origin:t.origin}),this.sao=new oA(this,{enabled:t.saoEnabled}),this.crossSections=new aA(this,{}),this.ticksPerRender=t.ticksPerRender,this.ticksPerOcclusionTest=t.ticksPerOcclusionTest,this.passes=t.passes,this.clearEachPass=t.clearEachPass,this.gammaInput=t.gammaInput,this.gammaOutput=t.gammaOutput,this.gammaFactor=t.gammaFactor,this._entityOffsetsEnabled=!!t.entityOffsetsEnabled,this._logarithmicDepthBufferEnabled=!!t.logarithmicDepthBufferEnabled,this._dtxEnabled=!1!==t.dtxEnabled,this._pbrEnabled=!!t.pbrEnabled,this._colorTextureEnabled=!1!==t.colorTextureEnabled,this._dtxEnabled=!!t.dtxEnabled,this._markerZOffset=t.markerZOffset,q._addScene(this),this._initDefaults(),this._viewport=new On(this,{id:"default.viewport",autoBoundary:!0,dontClear:!0}),this._camera=new rA(this,{id:"default.camera",dontClear:!0}),this._sectionCaps=new pA(this),new Xr(this,{color:[1,1,1],intensity:.7}),new Zr(this,{dir:[.8,-.5,-.5],color:[.67,.67,1],intensity:.7,space:"world"}),new Zr(this,{dir:[-.8,-1,.5],color:[1,1,.9],intensity:.9,space:"world"}),this._camera.on("dirty",(()=>{this._renderer.imageDirty()}))}_initDefaults(){}_addComponent(e){if(e.id&&this.components[e.id]&&(this.error("Component "+j.inQuotes(e.id)+" already exists in Scene - ignoring ID, will randomly-generate instead"),e.id=null),!e.id)for(void 0===window.nextID&&(window.nextID=0),e.id="__"+window.nextID++;this.components[e.id];)e.id=R.createUUID();this.components[e.id]=e;const t=e.type;let s=this.types[e.type];s||(s=this.types[t]={}),s[e.id]=e,e.compile&&(this._compilables[e.id]=e),e.isDrawable&&(this._renderer.addDrawable(e.id,e),this._collidables[e.id]=e)}_removeComponent(e){var t=e.id,s=e.type;delete this.components[t];const i=this.types[s];i&&(delete i[t],j.isEmptyObject(i)&&delete this.types[s]),e.compile&&delete this._compilables[e.id],e.isDrawable&&(this._renderer.removeDrawable(e.id),delete this._collidables[e.id])}_sectionPlaneCreated(e){this.sectionPlanes[e.id]=e,this.scene._sectionPlanesState.addSectionPlane(e._state),this.scene.fire("sectionPlaneCreated",e,!0),this._needRecompile=!0}_bitmapCreated(e){this.bitmaps[e.id]=e,this.scene.fire("bitmapCreated",e,!0)}_lineSetCreated(e){this.lineSets[e.id]=e,this.scene.fire("lineSetCreated",e,!0)}_lightCreated(e){this.lights[e.id]=e,this.scene._lightsState.addLight(e._state),this._needRecompile=!0}_lightMapCreated(e){this.lightMaps[e.id]=e,this.scene._lightsState.addLightMap(e._state),this._needRecompile=!0}_reflectionMapCreated(e){this.reflectionMaps[e.id]=e,this.scene._lightsState.addReflectionMap(e._state),this._needRecompile=!0}_sectionPlaneDestroyed(e){delete this.sectionPlanes[e.id],this.scene._sectionPlanesState.removeSectionPlane(e._state),this.scene.fire("sectionPlaneDestroyed",e,!0),this._needRecompile=!0}_bitmapDestroyed(e){delete this.bitmaps[e.id],this.scene.fire("bitmapDestroyed",e,!0)}_lineSetDestroyed(e){delete this.lineSets[e.id],this.scene.fire("lineSetDestroyed",e,!0)}_lightDestroyed(e){delete this.lights[e.id],this.scene._lightsState.removeLight(e._state),this._needRecompile=!0}_lightMapDestroyed(e){delete this.lightMaps[e.id],this.scene._lightsState.removeLightMap(e._state),this._needRecompile=!0}_reflectionMapDestroyed(e){delete this.reflectionMaps[e.id],this.scene._lightsState.removeReflectionMap(e._state),this._needRecompile=!0}_registerModel(e){this.models[e.id]=e,this._modelIds=null}_deregisterModel(e){const t=e.id;delete this.models[t],this._modelIds=null,this.fire("modelUnloaded",t)}_registerObject(e){this.objects[e.id]=e,this._numObjects++,this._objectIds=null}_deregisterObject(e){delete this.objects[e.id],this._numObjects--,this._objectIds=null}_objectVisibilityUpdated(e,t=!0){e.visible?(this.visibleObjects[e.id]=e,this._numVisibleObjects++):(delete this.visibleObjects[e.id],this._numVisibleObjects--),this._visibleObjectIds=null,t&&this.fire("objectVisibility",e,!0)}_deRegisterVisibleObject(e){delete this.visibleObjects[e.id],this._numVisibleObjects--,this._visibleObjectIds=null}_objectXRayedUpdated(e,t=!0){e.xrayed?(this.xrayedObjects[e.id]=e,this._numXRayedObjects++):(delete this.xrayedObjects[e.id],this._numXRayedObjects--),this._xrayedObjectIds=null,t&&this.fire("objectXRayed",e,!0)}_deRegisterXRayedObject(e){delete this.xrayedObjects[e.id],this._numXRayedObjects--,this._xrayedObjectIds=null}_objectHighlightedUpdated(e){e.highlighted?(this.highlightedObjects[e.id]=e,this._numHighlightedObjects++):(delete this.highlightedObjects[e.id],this._numHighlightedObjects--),this._highlightedObjectIds=null}_deRegisterHighlightedObject(e){delete this.highlightedObjects[e.id],this._numHighlightedObjects--,this._highlightedObjectIds=null}_objectSelectedUpdated(e,t=!0){e.selected?(this.selectedObjects[e.id]=e,this._numSelectedObjects++):(delete this.selectedObjects[e.id],this._numSelectedObjects--),this._selectedObjectIds=null,t&&this.fire("objectSelected",e,!0)}_deRegisterSelectedObject(e){delete this.selectedObjects[e.id],this._numSelectedObjects--,this._selectedObjectIds=null}_objectColorizeUpdated(e,t){t?(this.colorizedObjects[e.id]=e,this._numColorizedObjects++):(delete this.colorizedObjects[e.id],this._numColorizedObjects--),this._colorizedObjectIds=null}_deRegisterColorizedObject(e){delete this.colorizedObjects[e.id],this._numColorizedObjects--,this._colorizedObjectIds=null}_objectOpacityUpdated(e,t){t?(this.opacityObjects[e.id]=e,this._numOpacityObjects++):(delete this.opacityObjects[e.id],this._numOpacityObjects--),this._opacityObjectIds=null}_deRegisterOpacityObject(e){delete this.opacityObjects[e.id],this._numOpacityObjects--,this._opacityObjectIds=null}_objectOffsetUpdated(e,t){!t||0===t[0]&&0===t[1]&&0===t[2]?(this.offsetObjects[e.id]=e,this._numOffsetObjects++):(delete this.offsetObjects[e.id],this._numOffsetObjects--),this._offsetObjectIds=null}_deRegisterOffsetObject(e){delete this.offsetObjects[e.id],this._numOffsetObjects--,this._offsetObjectIds=null}get capabilities(){return this._renderer.capabilities}get entityOffsetsEnabled(){return this._entityOffsetsEnabled}get readableGeometryEnabled(){return this._readableGeometry}get pickSurfacePrecisionEnabled(){return this._readableGeometry}get logarithmicDepthBufferEnabled(){return this._logarithmicDepthBufferEnabled}set numCachedSectionPlanes(e){e=e||0,this._sectionPlanesState.getNumCachedSectionPlanes()!==e&&(this._sectionPlanesState.setNumCachedSectionPlanes(e),this._needRecompile=!0,this.glRedraw())}get numCachedSectionPlanes(){return this._sectionPlanesState.getNumCachedSectionPlanes()}set pbrEnabled(e){this._pbrEnabled=!!e,this.glRedraw()}get pbrEnabled(){return this._pbrEnabled}set dtxEnabled(e){e=!!e,this._dtxEnabled!==e&&(this._dtxEnabled=e)}get dtxEnabled(){return this._dtxEnabled}set colorTextureEnabled(e){this._colorTextureEnabled=!!e,this.glRedraw()}get colorTextureEnabled(){return this._colorTextureEnabled}get markerZOffset(){return null==this._markerZOffset?-.001:this._markerZOffset}doOcclusionTest(){this._needRecompile&&(this._recompile(),this._needRecompile=!1),this._renderer.doOcclusionTest()}render(e){e&&q.runTasks();const t={sceneId:null,pass:0};if(this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),e||this._renderer.needsRender()){t.sceneId=this.id;for(let s=0;s<this._passes;s++)t.pass=s,this.fire("rendering",t,!0),e&&this._renderer.imageDirty(),this._renderer.render(s,this._clearEachPass||0===s),this.fire("rendered",t,!0);this._saveAmbientColor()}}compile(){this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1)}_recompile(){for(const e in this._compilables)this._compilables.hasOwnProperty(e)&&this._compilables[e].compile();this._renderer.shadowsDirty(),this.fire("compile",this,!0)}_saveAmbientColor(){const e=this.canvas;if(e.transparent||e.backgroundImage||e.backgroundColor)this._lastAmbientColor=null;else{const t=this._lightsState.getAmbientColorAndIntensity();this._lastAmbientColor&&this._lastAmbientColor[0]===t[0]&&this._lastAmbientColor[1]===t[1]&&this._lastAmbientColor[2]===t[2]&&this._lastAmbientColor[3]===t[3]||(e.backgroundColor=t,this._lastAmbientColor||(this._lastAmbientColor=R.vec4([0,0,0,1])),this._lastAmbientColor.set(t))}}get modelIds(){return this._modelIds||(this._modelIds=Object.keys(this.models)),this._modelIds}get numObjects(){return this._numObjects}get objectIds(){return this._objectIds||(this._objectIds=Object.keys(this.objects)),this._objectIds}get numVisibleObjects(){return this._numVisibleObjects}get visibleObjectIds(){return this._visibleObjectIds||(this._visibleObjectIds=Object.keys(this.visibleObjects)),this._visibleObjectIds}get numXRayedObjects(){return this._numXRayedObjects}get xrayedObjectIds(){return this._xrayedObjectIds||(this._xrayedObjectIds=Object.keys(this.xrayedObjects)),this._xrayedObjectIds}get numHighlightedObjects(){return this._numHighlightedObjects}get highlightedObjectIds(){return this._highlightedObjectIds||(this._highlightedObjectIds=Object.keys(this.highlightedObjects)),this._highlightedObjectIds}get numSelectedObjects(){return this._numSelectedObjects}get selectedObjectIds(){return this._selectedObjectIds||(this._selectedObjectIds=Object.keys(this.selectedObjects)),this._selectedObjectIds}get numColorizedObjects(){return this._numColorizedObjects}get colorizedObjectIds(){return this._colorizedObjectIds||(this._colorizedObjectIds=Object.keys(this.colorizedObjects)),this._colorizedObjectIds}get opacityObjectIds(){return this._opacityObjectIds||(this._opacityObjectIds=Object.keys(this.opacityObjects)),this._opacityObjectIds}get offsetObjectIds(){return this._offsetObjectIds||(this._offsetObjectIds=Object.keys(this.offsetObjects)),this._offsetObjectIds}set ticksPerRender(e){null==e?e=1:(!j.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerRender': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._ticksPerRender&&(this._ticksPerRender=e)}get ticksPerRender(){return this._ticksPerRender}set ticksPerOcclusionTest(e){null==e?e=20:(!j.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'ticksPerOcclusionTest': '"+e+"' - should be an integer greater than zero."),e=20),e!==this._ticksPerOcclusionTest&&(this._ticksPerOcclusionTest=e)}get ticksPerOcclusionTest(){return this._ticksPerOcclusionTest}set passes(e){null==e?e=1:(!j.isNumeric(e)||e<=0)&&(this.error("Unsupported value for 'passes': '"+e+"' - should be an integer greater than zero."),e=1),e!==this._passes&&(this._passes=e,this.glRedraw())}get passes(){return this._passes}set clearEachPass(e){(e=!!e)!==this._clearEachPass&&(this._clearEachPass=e,this.glRedraw())}get clearEachPass(){return this._clearEachPass}set gammaInput(e){(e=!1!==e)!==this._renderer.gammaInput&&(this._renderer.gammaInput=e,this._needRecompile=!0,this.glRedraw())}get gammaInput(){return this._renderer.gammaInput}set gammaOutput(e){(e=!!e)!==this._renderer.gammaOutput&&(this._renderer.gammaOutput=e,this._needRecompile=!0,this.glRedraw())}get gammaOutput(){return this._renderer.gammaOutput}set gammaFactor(e){(e=null==e?2.2:e)!==this._renderer.gammaFactor&&(this._renderer.gammaFactor=e,this.glRedraw())}get gammaFactor(){return this._renderer.gammaFactor}get geometry(){return this.components["default.geometry"]||ze(Le)}get material(){return this.components["default.material"]||new jt(this,{id:"default.material",emissive:[.4,.4,.4],dontClear:!0})}get xrayMaterial(){return this.components["default.xrayMaterial"]||new ds(this,{id:"default.xrayMaterial",fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1,dontClear:!0})}get highlightMaterial(){return this.components["default.highlightMaterial"]||new ds(this,{id:"default.highlightMaterial",fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1,dontClear:!0})}get selectedMaterial(){return this.components["default.selectedMaterial"]||new ds(this,{id:"default.selectedMaterial",fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[1,1,1],edgeAlpha:1,edgeWidth:1,dontClear:!0})}get edgeMaterial(){return this.components["default.edgeMaterial"]||new fs(this,{id:"default.edgeMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1,dontClear:!0})}get pointsMaterial(){return this.components["default.pointsMaterial"]||new cA(this,{id:"default.pointsMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1,dontClear:!0})}get linesMaterial(){return this.components["default.linesMaterial"]||new uA(this,{id:"default.linesMaterial",fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1,dontClear:!0})}get viewport(){return this._viewport}get camera(){return this._camera}get center(){if(this._aabbDirty||!this._center){const e=this.aabb;this._center||(this._center=R.vec3()),this._center[0]=(e[0]+e[3])/2,this._center[1]=(e[1]+e[4])/2,this._center[2]=(e[2]+e[5])/2}return this._center}get aabb(){if(this._aabbDirty){this._aabb||(this._aabb=R.AABB3());let e,t=R.MAX_DOUBLE,s=R.MAX_DOUBLE,i=R.MAX_DOUBLE,r=R.MIN_DOUBLE,n=R.MIN_DOUBLE,A=R.MIN_DOUBLE;const o=this._collidables;let a,l=!1;for(const c in o)if(o.hasOwnProperty(c)){if(a=o[c],!1===a.collidable)continue;e=a.aabb,e[0]<t&&(t=e[0]),e[1]<s&&(s=e[1]),e[2]<i&&(i=e[2]),e[3]>r&&(r=e[3]),e[4]>n&&(n=e[4]),e[5]>A&&(A=e[5]),l=!0}l||(t=-100,s=-100,i=-100,r=100,n=100,A=100),this._aabb[0]=t,this._aabb[1]=s,this._aabb[2]=i,this._aabb[3]=r,this._aabb[4]=n,this._aabb[5]=A,this._aabbDirty=!1,this._center=null}return this._aabb}_setAABBDirty(){this._aabbDirty=!0,this.fire("boundary")}pick(e,t){if(!this.canvas)return this.error("Picking not allowed on a destroyed Scene"),null;if(0===this.canvas.boundary[2]||0===this.canvas.boundary[3])return this.error("Picking not allowed while canvas has zero width or height"),null;(e=e||{}).pickSurface=e.pickSurface||e.rayPick,e.canvasPos||e.matrix||e.origin&&e.direction||this.warn("picking without canvasPos, matrix, or ray origin and direction");const s=e.includeEntities||e.include;s&&(e.includeEntityIds=fA(this,s));const i=e.excludeEntities||e.exclude;return i&&(e.excludeEntityIds=fA(this,i)),this._needRecompile&&(this._recompile(),this._renderer.imageDirty(),this._needRecompile=!1),(t=e.snapToEdge||e.snapToVertex?this._renderer.snapPick(e,t):this._renderer.pick(e,t))&&t.entity&&t.entity.fire&&t.entity.fire("picked",t),t}snapPick(e){return this.canvas?(void 0===this._warnSnapPickDeprecated&&(this._warnSnapPickDeprecated=!0,this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead")),e.canvasPos?this._renderer.snapPick(e):void this.error("Scene.snapPick() canvasPos parameter expected")):(this.error("Picking not allowed on a destroyed Scene"),null)}clear(){var e;for(const t in this.components)this.components.hasOwnProperty(t)&&((e=this.components[t])._dontClear||e.destroy())}clearLights(){const e=Object.keys(this.lights);for(let t=0,s=e.length;t<s;t++)this.lights[e[t]].destroy()}clearSectionPlanes(){const e=Object.keys(this.sectionPlanes);for(let t=0,s=e.length;t<s;t++)this.sectionPlanes[e[t]].destroy()}clearBitmaps(){const e=Object.keys(this.bitmaps);for(let t=0,s=e.length;t<s;t++)this.bitmaps[e[t]].destroy()}clearLines(){const e=Object.keys(this.lineSets);for(let t=0,s=e.length;t<s;t++)this.lineSets[e[t]].destroy()}getAABB(e){if(void 0===e)return this.aabb;if(j.isString(e)){const t=this.objects[e];if(t&&t.aabb)return t.aabb;e=[e]}if(0===e.length)return this.aabb;let t,s=R.MAX_DOUBLE,i=R.MAX_DOUBLE,r=R.MAX_DOUBLE,n=R.MIN_DOUBLE,A=R.MIN_DOUBLE,o=R.MIN_DOUBLE;if(this.withObjects(e,(e=>{if(e.collidable){const a=e.aabb;a[0]<s&&(s=a[0]),a[1]<i&&(i=a[1]),a[2]<r&&(r=a[2]),a[3]>n&&(n=a[3]),a[4]>A&&(A=a[4]),a[5]>o&&(o=a[5]),t=!0}})),t){const e=R.AABB3();return e[0]=s,e[1]=i,e[2]=r,e[3]=n,e[4]=A,e[5]=o,e}return this.aabb}setObjectsVisible(e,t){return this.withObjects(e,(e=>{const s=e.visible!==t;return e.visible=t,s}))}setObjectsCollidable(e,t){return this.withObjects(e,(e=>{const s=e.collidable!==t;return e.collidable=t,s}))}setObjectsCulled(e,t){return this.withObjects(e,(e=>{const s=e.culled!==t;return e.culled=t,s}))}setObjectsSelected(e,t){return this.withObjects(e,(e=>{const s=e.selected!==t;return e.selected=t,s}))}setObjectsHighlighted(e,t){return this.withObjects(e,(e=>{const s=e.highlighted!==t;return e.highlighted=t,s}))}setObjectsXRayed(e,t){return this.withObjects(e,(e=>{const s=e.xrayed!==t;return e.xrayed=t,s}))}setObjectsEdges(e,t){return this.withObjects(e,(e=>{const s=e.edges!==t;return e.edges=t,s}))}setObjectsColorized(e,t){return this.withObjects(e,(e=>{e.colorize=t}))}setObjectsOpacity(e,t){return this.withObjects(e,(e=>{const s=e.opacity!==t;return e.opacity=t,s}))}setObjectsPickable(e,t){return this.withObjects(e,(e=>{const s=e.pickable!==t;return e.pickable=t,s}))}setObjectsOffset(e,t){this.withObjects(e,(e=>{e.offset=t}))}withObjects(e,t){j.isString(e)&&(e=[e]);let s=!1;for(let i=0,r=e.length;i<r;i++){const r=e[i];let n=this.objects[r];if(n)s=t(n)||s;else{const e=this.modelIds;for(let i=0,A=e.length;i<A;i++){const A=e[i],o=R.globalizeObjectId(A,r);n=this.objects[o],n&&(s=t(n)||s)}}}return s}tickify(e){const t=e.toString();if(t in this._tickifiedFunctions)return this._tickifiedFunctions[t].wrapperFunc;let s,i=0,r=0;const n=function(...e){s=e,r++},A=this.on("tick",(()=>{r>i&&(i=r,e(...s))}));return this._tickifiedFunctions[t]={tickSubId:A,wrapperFunc:n},n}destroy(){super.destroy(),this._removeWebglcontextlostListener();for(const e in this.components)this.components.hasOwnProperty(e)&&this.components[e].destroy();this._sectionCaps.destroy(),this.canvas.gl=null,this.components=null,this.models=null,this.objects=null,this.visibleObjects=null,this.xrayedObjects=null,this.highlightedObjects=null,this.selectedObjects=null,this.colorizedObjects=null,this.opacityObjects=null,this.sectionPlanes=null,this.lights=null,this.lightMaps=null,this.reflectionMaps=null,this._objectIds=null,this._visibleObjectIds=null,this._xrayedObjectIds=null,this._highlightedObjectIds=null,this._selectedObjectIds=null,this._colorizedObjectIds=null,this._sectionCaps=null,this.types=null,this.components=null,this.canvas=null,this._renderer=null,this.input=null,this._viewport=null,this._camera=null}}const mA=R.vec4(),_A=R.vec4(),bA=R.vec3(),yA=R.vec3(),BA=R.vec3(),wA=R.vec4(),vA=R.vec4(),CA=R.vec4();class MA{constructor(e){this._scene=e}dollyToCanvasPos(e,t,s){let i=!1;const r=this._scene.camera;if(e){const t=R.subVec3(e,r.eye,bA);i=R.lenVec3(t)<s}if("perspective"===r.projection){r.ortho.scale=r.ortho.scale-s;const i=this._unproject(t,wA),n=R.subVec3(i,r.eye,CA),A=R.mulVec3Scalar(R.normalizeVec3(n),-s,[]);if(r.eye=[r.eye[0]-A[0],r.eye[1]-A[1],r.eye[2]-A[2]],r.look=[r.look[0]-A[0],r.look[1]-A[1],r.look[2]-A[2]],e){const t=R.subVec3(e,r.eye,bA),s=R.lenVec3(t),i=R.mulVec3Scalar(R.normalizeVec3(R.subVec3(r.look,r.eye,yA)),s);r.look=[r.eye[0]+i[0],r.eye[1]+i[1],r.eye[2]+i[2]]}}else if("ortho"===r.projection){const e=this._unproject(t,wA);r.ortho.scale=r.ortho.scale-s,r.ortho._update();const i=this._unproject(t,vA),n=R.subVec3(i,e,CA),A=R.mulVec3Scalar(R.normalizeVec3(R.subVec3(r.look,r.eye,bA)),-s,yA),o=R.addVec3(n,A,BA);r.eye=[r.eye[0]-o[0],r.eye[1]-o[1],r.eye[2]-o[2]],r.look=[r.look[0]-o[0],r.look[1]-o[1],r.look[2]-o[2]]}return i}_unproject(e,t){const s=this._scene.camera,i=s.project.transposedMatrix,r=i.subarray(8,12),n=i.subarray(12),A=[0,0,-1,1],o=R.dotVec4(A,r)/R.dotVec4(A,n);return s.project.unproject(e,o,mA,_A,t),t}destroy(){}}const EA=R.vec3(),FA=R.vec3(),xA=R.vec3(),UA=R.vec4(),IA=R.vec4(),TA=R.vec4(),PA=Math.PI-.001;class SA{constructor(e,t){this._scene=e,this._configs=t,this._pivotWorldPos=R.vec3(),this._cameraOffset=R.vec3(),this._azimuth=0,this._polar=0,this._radius=0,this._pivotPosSet=!1,this._pivoting=!1,this._shown=!1,this._pivotSphereEnabled=!1,this._pivotSphere=null,this._pivotSphereSize=1,this._pivotSphereGeometry=null,this._pivotSphereMaterial=null,this._rtcCenter=R.vec3(),this._rtcPos=R.vec3(),this._pivotViewPos=R.vec4(),this._pivotProjPos=R.vec4(),this._pivotCanvasPos=R.vec2(),this._cameraDirty=!0,this._onViewMatrix=this._scene.camera.on("viewMatrix",(()=>{this._cameraDirty=!0})),this._onProjMatrix=this._scene.camera.on("projMatrix",(()=>{this._cameraDirty=!0})),this._onTick=this._scene.on("tick",(()=>{this.updatePivotElement(),this.updatePivotSphere()}))}createPivotSphere(){const e=this.getPivotPos(),t=R.vec3();R.decomposeMat4(R.inverseMat4(this._scene.viewer.camera.viewMatrix,R.mat4()),t,R.vec4(),R.vec3());const s=R.distVec3(t,e);let i=Math.tan(Math.PI/500)*s*this._pivotSphereSize;"ortho"==this._scene.camera.projection&&(i/=this._scene.camera.ortho.scale/2),dt(e,this._rtcCenter,this._rtcPos),this._pivotSphereGeometry=new Ge(this._scene,Je({radius:i})),this._pivotSphere=new Ot(this._scene,{geometry:this._pivotSphereGeometry,material:this._pivotSphereMaterial,pickable:!1,position:this._rtcPos,rtcCenter:this._rtcCenter})}destroyPivotSphere(){this._pivotSphere&&(this._pivotSphere.destroy(),this._pivotSphere=null),this._pivotSphereGeometry&&(this._pivotSphereGeometry.destroy(),this._pivotSphereGeometry=null)}updatePivotElement(){const e=this._scene.camera,t=this._scene.canvas;if(this._pivoting&&this._cameraDirty){R.transformPoint3(e.viewMatrix,this.getPivotPos(),this._pivotViewPos),this._pivotViewPos[3]=1,R.transformPoint4(e.projMatrix,this._pivotViewPos,this._pivotProjPos);const s=t.boundary,i=s[2],r=s[3];this._pivotCanvasPos[0]=Math.floor((1+this._pivotProjPos[0]/this._pivotProjPos[3])*i/2),this._pivotCanvasPos[1]=Math.floor((1-this._pivotProjPos[1]/this._pivotProjPos[3])*r/2);let n=t._lastBoundingClientRect;if(!n||t._canvasSizeChanged){const e=t.canvas;n=t._lastBoundingClientRect=e.getBoundingClientRect()}this._pivotElement&&(this._pivotElement.style.left=Math.floor(n.left+this._pivotCanvasPos[0])-this._pivotElement.clientWidth/2+window.scrollX+"px",this._pivotElement.style.top=Math.floor(n.top+this._pivotCanvasPos[1])-this._pivotElement.clientHeight/2+window.scrollY+"px"),this._cameraDirty=!1}}updatePivotSphere(){this._pivoting&&this._pivotSphere&&(dt(this.getPivotPos(),this._rtcCenter,this._rtcPos),R.compareVec3(this._rtcPos,this._pivotSphere.position)||(this.destroyPivotSphere(),this.createPivotSphere()))}setPivotElement(e){this._pivotElement=e}enablePivotSphere(e={}){this.destroyPivotSphere(),this._pivotSphereEnabled=!0,e.size&&(this._pivotSphereSize=e.size);const t=e.color||[1,0,0];this._pivotSphereMaterial=new jt(this._scene,{emissive:t,ambient:t,specular:[0,0,0],diffuse:[0,0,0]})}disablePivotSphere(){this.destroyPivotSphere(),this._pivotSphereEnabled=!1}startPivot(){const e=this._scene.camera;let t=R.lookAtMat4v(e.eye,e.look,e.up);R.transformPoint3(t,this.getPivotPos(),this._cameraOffset);const s=this.getPivotPos();this._cameraOffset[2]+=R.distVec3(e.eye,s),t=R.inverseMat4(t);const i=R.transformVec3(t,this._cameraOffset),r=R.vec3();if(R.subVec3(e.eye,s,r),R.addVec3(r,i),e.zUp){const e=r[1];r[1]=r[2],r[2]=e}this._radius=R.lenVec3(r),this._polar=Math.acos(r[1]/this._radius),this._azimuth=Math.atan2(r[0],r[2]),this._pivoting=!0}_cameraLookingDownwards(){const e=this._scene.camera,t=R.normalizeVec3(R.subVec3(e.look,e.eye,EA)),s=R.cross3Vec3(t,e.worldUp,FA);return R.sqLenVec3(s)<=1e-4}getPivoting(){return this._pivoting}setPivotPos(e){this._pivotWorldPos.set(e),this._pivotPosSet=!0}setCanvasPivotPos(e){const t=this._scene.camera,s=Math.abs(R.distVec3(this._scene.center,t.eye)),i=t.project.transposedMatrix,r=i.subarray(8,12),n=i.subarray(12),A=[0,0,-1,1],o=R.dotVec4(A,r)/R.dotVec4(A,n),a=UA;t.project.unproject(e,o,IA,TA,a);const l=R.normalizeVec3(R.subVec3(a,t.eye,EA)),c=R.addVec3(t.eye,R.mulVec3Scalar(l,s,FA),xA);this.setPivotPos(c)}getPivotPos(){return this._pivotPosSet?this._pivotWorldPos:this._scene.camera.look}continuePivot(e,t){if(!this._pivoting)return;if(0===e&&0===t)return;const s=this._scene.camera;var i=-e;const r=-t;1===s.worldUp[2]&&(i=-i),this._azimuth+=.01*-i;const n=r<0,A=r>0,o=Math.abs(this._polar-.001)<.005,a=Math.abs(this._polar-PA)<.005;let l=this._polar+.01*r;l=o&&n?.001:a&&A?PA:R.clamp(l,.001,PA),this._polar=l;const c=[this._radius*Math.sin(this._polar)*Math.sin(this._azimuth),this._radius*Math.cos(this._polar),this._radius*Math.sin(this._polar)*Math.cos(this._azimuth)];if(1===s.worldUp[2]){const e=c[1];c[1]=c[2],c[2]=e}const h=R.lenVec3(R.subVec3(s.look,s.eye,R.vec3())),u=this.getPivotPos();R.addVec3(c,u);let d=R.lookAtMat4v(c,u,s.worldUp);d=R.inverseMat4(d);const p=R.transformVec3(d,this._cameraOffset);d[12]-=p[0],d[13]-=p[1],d[14]-=p[2];const f=[d[8],d[9],d[10]];s.eye=[d[12],d[13],d[14]],R.subVec3(s.eye,R.mulVec3Scalar(f,h),s.look),s.up=[d[4],d[5],d[6]],this.showPivot()}showPivot(){this._shown||(this._pivotElement&&(this.updatePivotElement(),this._pivotElement.style.visibility="visible"),this._pivotSphereEnabled&&(this.destroyPivotSphere(),this.createPivotSphere()),this._shown=!0)}hidePivot(){this._shown&&(this._pivotElement&&(this._pivotElement.style.visibility="hidden"),this._pivotSphereEnabled&&this.destroyPivotSphere(),this._shown=!1)}endPivot(){this._pivoting=!1}destroy(){this.destroyPivotSphere(),this._scene.camera.off(this._onViewMatrix),this._scene.camera.off(this._onProjMatrix),this._scene.off(this._onTick)}}class DA{constructor(e,t){this._scene=e.scene,this._cameraControl=e,this._scene.canvas.canvas.oncontextmenu=function(e){e.preventDefault()},this._configs=t,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick=!1,this.pickCursorPos=R.vec2(),this.picked=!1,this.pickedSurface=!1,this.pickResult=null,this._lastPickedEntityId=null,this._lastHash=null,this._needFireEvents=0}update(){if(!this._configs.pointerEnabled)return;if(!this.schedulePickEntity&&!this.schedulePickSurface)return;const e=`${~~this.pickCursorPos[0]}-${~~this.pickCursorPos[1]}-${this.scheduleSnapOrPick}-${this.schedulePickSurface}-${this.schedulePickEntity}`;if(this._lastHash===e)return;this.picked=!1,this.pickedSurface=!1,this.snappedOrPicked=!1,this.hoveredSnappedOrSurfaceOff=!1;const t=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){const e=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});e&&(e.snappedToEdge||e.snappedToVertex)?(this.snapPickResult=e,this.snappedOrPicked=!0,this._needFireEvents++):(this.schedulePickSurface=!0,this.snapPickResult=null)}if(this.schedulePickSurface&&this.pickResult&&this.pickResult.worldPos){const e=this.pickResult.canvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!0,this._needFireEvents+=t?1:0,this.schedulePickEntity=!1,this.schedulePickSurface=!1,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.hoveredSnappedOrSurfaceOff=!0,void(this.scheduleSnapOrPick=!1)}if(this.schedulePickEntity&&this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){const e=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(e[0]===this.pickCursorPos[0]&&e[1]===this.pickCursorPos[1])return this.picked=!0,this.pickedSurface=!1,this.schedulePickEntity=!1,void(this.schedulePickSurface=!1)}this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult?(this.pickResult=this._scene.pick({pickSurface:!0,pickSurfaceNormal:!1,canvasPos:this.pickCursorPos}),this.pickResult?(this.picked=!0,this.scheduleSnapOrPick?this.snappedOrPicked=!0:this.pickedSurface=!0,this._needFireEvents++):this.scheduleSnapOrPick&&(this.hoveredSnappedOrSurfaceOff=!0,this._needFireEvents++)):(this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos}),this.pickResult&&(this.picked=!0,this.pickedSurface=!1,this._needFireEvents++)),this.scheduleSnapOrPick=!1,this.schedulePickEntity=!1,this.schedulePickSurface=!1}fireEvents(){if(0!==this._needFireEvents){if(this.hoveredSnappedOrSurfaceOff&&this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},!0),this.snappedOrPicked)if(this.snapPickResult){const e=new fn;e.entity=this.snapPickResult.entity,e.snappedToVertex=this.snapPickResult.snappedToVertex,e.snappedToEdge=this.snapPickResult.snappedToEdge,e.worldPos=this.snapPickResult.worldPos,e.canvasPos=this.pickCursorPos,e.snappedCanvasPos=this.snapPickResult.snappedCanvasPos,this._cameraControl.fire("hoverSnapOrSurface",e,!0),this.snapPickResult=null}else this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,!0);if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){const e=this.pickResult.entity.id;this._lastPickedEntityId!==e&&(void 0!==this._lastPickedEntityId&&this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._cameraControl.fire("hoverEnter",this.pickResult,!0),this._lastPickedEntityId=e)}this._cameraControl.fire("hover",this.pickResult,!0),this.pickResult.worldPos&&(this.pickedSurface=!0,this._cameraControl.fire("hoverSurface",this.pickResult,!0))}else void 0!==this._lastPickedEntityId&&(this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},!0);this.pickResult=null,this._needFireEvents=0}}}const kA=R.vec2(),QA=function(e,t,s){if(e){const i=t.getBoundingClientRect();s[0]=e.clientX-i.left,s[1]=e.clientY-i.top}else e=window.event,s[0]=e.x,s[1]=e.y;return s};class RA{constructor(e,t,s,i,r){this._scene=e;const n=t.pickController,A=t.cameraControl;let o,a,l,c=0,h=0,u=0,d=0,p=!1;const f=R.vec3();let g=!0;const m=this._scene.canvas.canvas,_=[];function b(e=!0){c=i.pointerCanvasPos[0],h=i.pointerCanvasPos[1],u=i.pointerCanvasPos[0],d=i.pointerCanvasPos[1],e&&(n.pickCursorPos=i.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),n.picked&&n.pickedSurface&&n.pickResult&&n.pickResult.worldPos?(p=!0,f.set(n.pickResult.worldPos)):p=!1)}document.addEventListener("keydown",this._documentKeyDownHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const i=t.keyCode;_[i]=!0}),document.addEventListener("keyup",this._documentKeyUpHandler=t=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;const i=t.keyCode;_[i]=!1}),document.addEventListener("visibilitychange",this._onVisibilityChange=()=>{_.splice(0)}),window.addEventListener("blur",this._onBlur=()=>{_.splice(0)}),m.addEventListener("mousedown",this._mouseDownHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:_[e.input.KEY_SHIFT]||s.planView?(o=!0,_[e.input.MOUSE_LEFT_BUTTON]=!0,b()):(o=!0,_[e.input.MOUSE_LEFT_BUTTON]=!0,b(!1));break;case 2:a=!0,_[e.input.MOUSE_MIDDLE_BUTTON]=!0,b();break;case 3:l=!0,_[e.input.MOUSE_RIGHT_BUTTON]=!0,s.panRightClick&&b()}}),document.addEventListener("mousemove",this._documentMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(!o&&!a&&!l)return;const n=e.canvas.boundary,u=n[2],d=n[3],g=i.pointerCanvasPos[0],m=i.pointerCanvasPos[1],b=s.planView||A._isKeyDownForAction(A.MOUSE_PAN,_),y=A._isKeyDownForAction(A.MOUSE_ROTATE,_),B=document.pointerLockElement?t.movementX:g-c,w=document.pointerLockElement?t.movementY:m-h;if(b){const t=e.camera;if("perspective"===t.projection){const s=Math.abs(p?R.lenVec3(R.subVec3(f,e.camera.eye,[])):e.camera.eyeLookDist)*Math.tan(t.perspective.fov/2*Math.PI/180);r.panDeltaX+=1.5*B*s/d,r.panDeltaY+=1.5*w*s/d}else r.panDeltaX+=.5*t.ortho.scale*(B/d),r.panDeltaY+=.5*t.ortho.scale*(w/d)}else y&&(s.planView||(s.firstPerson?(r.rotateDeltaY-=B/u*s.dragRotationRate/2,r.rotateDeltaX+=w/d*(s.dragRotationRate/4)):(r.rotateDeltaY-=B/u*(1.5*s.dragRotationRate),r.rotateDeltaX+=w/d*(1.5*s.dragRotationRate))));c=g,h=m}),m.addEventListener("mousemove",this._canvasMouseMoveHandler=e=>{s.active&&s.pointerEnabled&&i.mouseover&&(g=!0)}),document.addEventListener("mouseup",this._documentMouseUpHandler=t=>{if(s.active&&s.pointerEnabled)switch(t.which){case 1:case 2:case 3:o=!1,a=!1,l=!1,_[e.input.MOUSE_LEFT_BUTTON]=!1,_[e.input.MOUSE_MIDDLE_BUTTON]=!1,_[e.input.MOUSE_RIGHT_BUTTON]=!1}}),m.addEventListener("mouseup",this._mouseUpHandler=e=>{if(s.active&&s.pointerEnabled){if(3===e.which){QA(e,m,kA);const s=kA[0],i=kA[1];Math.abs(s-u)<3&&Math.abs(i-d)<3&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(e.pageX),Math.round(e.pageY)],canvasPos:kA,event:e},!0)}m.style.removeProperty("cursor")}}),m.addEventListener("mouseenter",this._mouseEnterHandler=()=>{s.active&&s.pointerEnabled});const y=1/60;let B=null;m.addEventListener("wheel",this._mouseWheelHandler=e=>{if(!(s.active&&s.pointerEnabled&&s.zoomOnMouseWheel&&A._isKeyDownForAction(A.MOUSE_DOLLY,_)))return;const t=performance.now()/1e3;var n=null!==B?t-B:0;B=t,n>.05&&(n=.05),n<y&&(n=y);const o=Math.max(-1,Math.min(1,40*-e.deltaY));if(0===o)return;const a=o/Math.abs(o);r.dollyDelta+=-a*n*s.mouseWheelDollyRate,g&&(0===i.pointerCanvasPos[0]&&0===i.pointerCanvasPos[1]&&QA(e,m,i.pointerCanvasPos),i.followPointerDirty=!0,g=!1)},{passive:!0})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("keydown",this._documentKeyDownHandler),document.removeEventListener("keyup",this._documentKeyUpHandler),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("blur",this._onBlur),e.removeEventListener("mousedown",this._mouseDownHandler),document.removeEventListener("mousemove",this._documentMouseMoveHandler),e.removeEventListener("mousemove",this._canvasMouseMoveHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._mouseUpHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("wheel",this._mouseWheelHandler)}}const OA=R.vec3(),VA=R.vec3(),LA=R.vec3(),HA=R.vec3(),NA=R.vec3(),GA={eye:R.vec3(),look:R.vec3(),up:R.vec3()};class jA{constructor(e,t,s,i){this._scene=e;const r=t.cameraControl,n=e.camera;this._onSceneKeyDown=e.input.on("keydown",(()=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(s.keyboardEnabledOnlyIfMouseover&&!i.mouseover)return;const A=r._isKeyDownForAction(r.AXIS_VIEW_RIGHT),o=r._isKeyDownForAction(r.AXIS_VIEW_BACK),a=r._isKeyDownForAction(r.AXIS_VIEW_LEFT),l=r._isKeyDownForAction(r.AXIS_VIEW_FRONT),c=r._isKeyDownForAction(r.AXIS_VIEW_TOP),h=r._isKeyDownForAction(r.AXIS_VIEW_BOTTOM);if(!(A||o||a||l||c||h))return;const u=e.aabb,d=R.getAABB3Diag(u);R.getAABB3Center(u,OA);const p=Math.abs(d/Math.tan(t.cameraFlight.fitFOV*R.DEGTORAD)),f=1.1*d;GA.orthoScale=f,A?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldRight,p,VA),NA)),GA.look.set(OA),GA.up.set(n.worldUp)):o?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldForward,p,VA),NA)),GA.look.set(OA),GA.up.set(n.worldUp)):a?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldRight,-p,VA),NA)),GA.look.set(OA),GA.up.set(n.worldUp)):l?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldForward,-p,VA),NA)),GA.look.set(OA),GA.up.set(n.worldUp)):c?(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldUp,p,VA),NA)),GA.look.set(OA),GA.up.set(R.normalizeVec3(R.mulVec3Scalar(n.worldForward,1,LA),HA))):h&&(GA.eye.set(R.addVec3(OA,R.mulVec3Scalar(n.worldUp,-p,VA),NA)),GA.look.set(OA),GA.up.set(R.normalizeVec3(R.mulVec3Scalar(n.worldForward,-1,LA)))),!s.firstPerson&&s.followPointer&&t.pivotController.setPivotPos(OA),t.cameraFlight.duration>0?t.cameraFlight.flyTo(GA,(()=>{t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot()})):(t.cameraFlight.jumpTo(GA),t.pivotController.getPivoting()&&s.followPointer&&t.pivotController.showPivot())}))}reset(){}destroy(){this._scene.input.off(this._onSceneKeyDown)}}class zA{constructor(e,t,s,i,r){this._scene=e;const n=t.pickController,A=t.pivotController,o=t.cameraControl;this._clicks=0,this._timeout=null,this._lastPickedEntityId=null,this._lastClickedWorldPos=null;let a=!1,l=!1;const c=this._scene.canvas.canvas,h=s=>{let i;s&&s.worldPos&&(i=s.worldPos);const r=s&&s.entity?s.entity.aabb:e.aabb;if(i){const s=e.camera;R.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})},u=e.tickify(this._canvasMouseMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(a||l)return;if(o.hasSubs("rayMove")){const t=R.vec3(),s=R.vec3();R.canvasPosToWorldRay(e.canvas.canvas,e.camera.viewMatrix,e.camera.projMatrix,e.camera.projection,i.pointerCanvasPos,t,s),o.fire("rayMove",{canvasPos:i.pointerCanvasPos,ray:{origin:t,direction:s,canvasPos:i.pointerCanvasPos}},!0)}const r=o.hasSubs("hover"),A=o.hasSubs("hoverEnter"),c=o.hasSubs("hoverOut"),h=o.hasSubs("hoverOff"),u=o.hasSubs("hoverSurface"),d=o.hasSubs("hoverSnapOrSurface");if(r||A||c||h||u||d)if(n.pickCursorPos=i.pointerCanvasPos,n.schedulePickEntity=!0,n.schedulePickSurface=u,n.scheduleSnapOrPick=d,n.update(),n.pickResult){if(n.pickResult.entity){const t=n.pickResult.entity.id;this._lastPickedEntityId!==t&&(void 0!==this._lastPickedEntityId&&o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),o.fire("hoverEnter",n.pickResult,!0),this._lastPickedEntityId=t)}o.fire("hover",n.pickResult,!0),(n.pickResult.worldPos||n.pickResult.snappedWorldPos)&&o.fire("hoverSurface",n.pickResult,!0)}else void 0!==this._lastPickedEntityId&&(o.fire("hoverOut",{entity:e.objects[this._lastPickedEntityId]},!0),this._lastPickedEntityId=void 0),o.fire("hoverOff",{canvasPos:n.pickCursorPos},!0)});c.addEventListener("mousemove",u),c.addEventListener("mousedown",this._canvasMouseDownHandler=t=>{1===t.which&&(a=!0),3===t.which&&(l=!0);if(1===t.which&&s.active&&s.pointerEnabled&&(i.mouseDownClientX=t.clientX,i.mouseDownClientY=t.clientY,i.mouseDownCursorX=i.pointerCanvasPos[0],i.mouseDownCursorY=i.pointerCanvasPos[1],!s.firstPerson&&s.followPointer&&(n.pickCursorPos=i.pointerCanvasPos,n.schedulePickSurface=!0,n.update(),1===t.which))){const t=n.pickResult;t&&t.worldPos?(A.setPivotPos(t.worldPos),A.startPivot(),this._lastClickedWorldPos=t.worldPos.slice()):(s.smartPivot?A.setCanvasPivotPos(i.pointerCanvasPos):this._lastClickedWorldPos?A.setPivotPos(this._lastClickedWorldPos):A.setPivotPos(e.camera.look),A.startPivot())}}),document.addEventListener("mouseup",this._documentMouseUpHandler=e=>{1===e.which&&(a=!1),3===e.which&&(l=!1),A.getPivoting()&&A.endPivot()}),c.addEventListener("mouseup",this._canvasMouseUpHandler=r=>{if(!s.active||!s.pointerEnabled)return;if(!(1===r.which))return;if(A.hidePivot(),Math.abs(r.clientX-i.mouseDownClientX)>3||Math.abs(r.clientY-i.mouseDownClientY)>3)return;const a=o.hasSubs("picked"),l=o.hasSubs("pickedNothing"),c=o.hasSubs("pickedSurface"),u=o.hasSubs("doublePicked"),d=o.hasSubs("doublePickedSurface"),p=o.hasSubs("doublePickedNothing");if(!(s.doublePickFlyTo||u||d||p))return(a||l||c)&&(n.pickCursorPos=i.pointerCanvasPos,n.schedulePickEntity=!0,n.schedulePickSurface=c,n.update(),n.pickResult?(o.fire("picked",n.pickResult,!0),n.pickedSurface&&o.fire("pickedSurface",n.pickResult,!0)):o.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0)),void(this._clicks=0);if(this._clicks++,1===this._clicks){n.pickCursorPos=i.pointerCanvasPos,n.schedulePickEntity=s.doublePickFlyTo,n.schedulePickSurface=c,n.update();const e=n.pickResult,r=n.pickedSurface;this._timeout=setTimeout((()=>{e?(o.fire("picked",e,!0),r&&(o.fire("pickedSurface",e,!0),!s.firstPerson&&s.followPointer&&(t.pivotController.setPivotPos(e.worldPos),t.pivotController.startPivot()&&t.pivotController.showPivot()))):o.fire("pickedNothing",{canvasPos:i.pointerCanvasPos},!0),this._clicks=0}),s.doubleClickTimeFrame)}else{if(null!==this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null),n.pickCursorPos=i.pointerCanvasPos,n.schedulePickEntity=s.doublePickFlyTo||u||d,n.schedulePickSurface=n.schedulePickEntity&&d,n.update(),n.pickResult){if(o.fire("doublePicked",n.pickResult,!0),n.pickedSurface&&o.fire("doublePickedSurface",n.pickResult,!0),s.doublePickFlyTo&&(h(n.pickResult),!s.firstPerson&&s.followPointer)){const e=n.pickResult.entity.aabb,s=R.getAABB3Center(e);t.pivotController.setPivotPos(s),t.pivotController.startPivot()&&t.pivotController.showPivot()}}else if(o.fire("doublePickedNothing",{canvasPos:i.pointerCanvasPos},!0),s.doublePickFlyTo&&(h(),!s.firstPerson&&s.followPointer)){const s=e.aabb,i=R.getAABB3Center(s);t.pivotController.setPivotPos(i),t.pivotController.startPivot()&&t.pivotController.showPivot()}this._clicks=0}},!1)}reset(){this._clicks=0,this._lastPickedEntityId=null,this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("mousemove",this._canvasMouseMoveHandler),e.removeEventListener("mousedown",this._canvasMouseDownHandler),document.removeEventListener("mouseup",this._documentMouseUpHandler),e.removeEventListener("mouseup",this._canvasMouseUpHandler),this._timeout&&(window.clearTimeout(this._timeout),this._timeout=null)}}class WA{constructor(e,t,s,i,r){this._scene=e;const n=e.input,A=[];e.canvas.canvas;let o=!0;this._onSceneMouseMove=n.on("mousemove",(()=>{o=!0})),this._onSceneKeyDown=n.on("keydown",(t=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(s.keyboardEnabledOnlyIfMouseover&&!i.mouseover||(A[t]=!0))})),this._onSceneKeyUp=n.on("keyup",(i=>{s.active&&s.pointerEnabled&&e.input.keyboardEnabled&&(A[i]=!1,t.pivotController.getPivoting()&&t.pivotController.endPivot())})),document.addEventListener("visibilitychange",this._onVisibilityChange=()=>{A.splice(0)}),window.addEventListener("blur",this._onBlur=()=>{A.splice(0)}),this._onTick=e.on("tick",(a=>{if(!s.active||!s.pointerEnabled||!e.input.keyboardEnabled)return;if(s.keyboardEnabledOnlyIfMouseover&&!i.mouseover)return;const l=t.cameraControl,c=a.deltaTime/1e3;if(!s.planView){const e=l._isKeyDownForAction(l.ROTATE_Y_POS,A),i=l._isKeyDownForAction(l.ROTATE_Y_NEG,A),n=l._isKeyDownForAction(l.ROTATE_X_POS,A),o=l._isKeyDownForAction(l.ROTATE_X_NEG,A),a=c*s.keyboardRotationRate;(e||i||n||o)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),e?r.rotateDeltaY+=a:i&&(r.rotateDeltaY-=a),n?r.rotateDeltaX+=a:o&&(r.rotateDeltaX-=a),!s.firstPerson&&s.followPointer&&t.pivotController.startPivot())}if(!A[n.KEY_CTRL]&&!A[n.KEY_ALT]){const e=l._isKeyDownForAction(l.DOLLY_BACKWARDS,A),n=l._isKeyDownForAction(l.DOLLY_FORWARDS,A);if(e||n){const A=c*s.keyboardDollyRate;!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),n?r.dollyDelta-=A:e&&(r.dollyDelta+=A),o&&(i.followPointerDirty=!0,o=!1)}}const h=l._isKeyDownForAction(l.PAN_FORWARDS,A),u=l._isKeyDownForAction(l.PAN_BACKWARDS,A),d=l._isKeyDownForAction(l.PAN_LEFT,A),p=l._isKeyDownForAction(l.PAN_RIGHT,A),f=l._isKeyDownForAction(l.PAN_UP,A),g=l._isKeyDownForAction(l.PAN_DOWN,A),m=(A[n.KEY_ALT]?.3:1)*c*s.keyboardPanRate;(h||u||d||p||f||g)&&(!s.firstPerson&&s.followPointer&&t.pivotController.startPivot(),g?r.panDeltaY+=m:f&&(r.panDeltaY+=-m),p?r.panDeltaX+=-m:d&&(r.panDeltaX+=m),u?r.panDeltaZ+=m:h&&(r.panDeltaZ+=-m))}))}reset(){}destroy(){this._scene.off(this._onTick),this._scene.input.off(this._onSceneMouseMove),this._scene.input.off(this._onSceneKeyDown),document.removeEventListener("visibilitychange",this._onVisibilityChange),window.removeEventListener("blur",this._onBlur),this._scene.input.off(this._onSceneKeyUp)}}const XA=R.vec3();class KA{constructor(e,t,s,i,r){this._scene=e;const n=e.camera,A=t.pickController,o=t.pivotController,a=t.panController,l=t.cameraControl;let c=1,h=1,u=null;this._onTick=e.on("tick",(()=>{if(!s.active||!s.pointerEnabled)return;let t="default";if(Math.abs(r.dollyDelta)<.001&&(r.dollyDelta=0),Math.abs(r.rotateDeltaX)<.001&&(r.rotateDeltaX=0),Math.abs(r.rotateDeltaY)<.001&&(r.rotateDeltaY=0),0===r.rotateDeltaX&&0===r.rotateDeltaY||(r.dollyDelta=0),s.followPointer){if(--c<=0&&(c=1,0!==r.dollyDelta)){if(0===r.rotateDeltaY&&0===r.rotateDeltaX&&s.followPointer&&i.followPointerDirty&&(A.pickCursorPos=i.pointerCanvasPos,A.schedulePickSurface=!0,A.update(),A.pickResult&&A.pickResult.worldPos?u=A.pickResult.worldPos:(h=1,u=null),i.followPointerDirty=!1),u){const t=Math.abs(R.lenVec3(R.subVec3(u,e.camera.eye,XA)));h=t/s.dollyProximityThreshold}h<s.dollyMinSpeed&&(h=s.dollyMinSpeed)}}else h=1,u=null;const d=r.dollyDelta*h;if(0===r.rotateDeltaY&&0===r.rotateDeltaX||(s.firstPerson?(0!==r.rotateDeltaX&&n.pitch(-r.rotateDeltaX),0!==r.rotateDeltaY&&n.yaw(r.rotateDeltaY)):s.followPointer&&o.getPivoting()&&(o.continuePivot(r.rotateDeltaY,r.rotateDeltaX),o.showPivot()),r.rotateDeltaX*=s.rotationInertia,r.rotateDeltaY*=s.rotationInertia,t=l._cursors.rotate),Math.abs(r.panDeltaX)<.001&&(r.panDeltaX=0),Math.abs(r.panDeltaY)<.001&&(r.panDeltaY=0),Math.abs(r.panDeltaZ)<.001&&(r.panDeltaZ=0),0!==r.panDeltaX||0!==r.panDeltaY||0!==r.panDeltaZ){const e=R.vec3();let i,A;if(e[0]=r.panDeltaX,e[1]=r.panDeltaY,e[2]=r.panDeltaZ,s.constrainVertical){n.xUp?(i=n.eye[0],A=n.look[0]):n.yUp?(i=n.eye[1],A=n.look[1]):n.zUp&&(i=n.eye[2],A=n.look[2]),n.pan(e);const t=n.eye,s=n.look;n.xUp?(t[0]=i,s[0]=A):n.yUp?(t[1]=i,s[1]=A):n.zUp&&(t[2]=i,s[2]=A),n.eye=t,n.look=s}else n.pan(e);t=l._cursors.pan}if(r.panDeltaX*=s.panInertia,r.panDeltaY*=s.panInertia,r.panDeltaZ*=s.panInertia,0!==d){if(t=d<0?l._cursors.dollyForward:l._cursors.dollyBackward,s.firstPerson){let e,t;if(s.constrainVertical&&(n.xUp?(e=n.eye[0],t=n.look[0]):n.yUp?(e=n.eye[1],t=n.look[1]):n.zUp&&(e=n.eye[2],t=n.look[2])),s.followPointer){a.dollyToCanvasPos(u,i.pointerCanvasPos,-d)&&(i.followPointerDirty=!0)}else n.pan([0,0,d]),n.ortho.scale=n.ortho.scale-d;if(s.constrainVertical){const s=n.eye,i=n.look;n.xUp?(s[0]=e,i[0]=t):n.yUp?(s[1]=e,i[1]=t):n.zUp&&(s[2]=e,i[2]=t),n.eye=s,n.look=i}}else if(s.planView)if(s.followPointer){a.dollyToCanvasPos(u,i.pointerCanvasPos,-d)&&(i.followPointerDirty=!0)}else n.ortho.scale=n.ortho.scale+d,n.zoom(d);else if(s.followPointer){a.dollyToCanvasPos(u,i.pointerCanvasPos,-d)&&(i.followPointerDirty=!0)}else n.ortho.scale=n.ortho.scale+d,n.zoom(d);r.dollyDelta*=s.dollyInertia}A.fireEvents(),document.body.style.cursor=t}))}destroy(){this._scene.off(this._onTick)}}class ZA{constructor(e,t,s,i,r){this._scene=e;const n=this._scene.canvas.canvas;n.addEventListener("mouseenter",this._mouseEnterHandler=()=>{i.mouseover=!0}),n.addEventListener("mouseleave",this._mouseLeaveHandler=()=>{i.mouseover=!1,n.style.cursor=null}),document.addEventListener("mousemove",this._mouseMoveHandler=e=>{JA(e,n,i.pointerCanvasPos),i.mouseover=!0}),n.addEventListener("mousedown",this._mouseDownHandler=e=>{s.active&&s.pointerEnabled&&(JA(e,n,i.pointerCanvasPos),i.mouseover=!0)}),n.addEventListener("mouseup",this._mouseUpHandler=e=>{s.active&&s.pointerEnabled})}reset(){}destroy(){const e=this._scene.canvas.canvas;document.removeEventListener("mousemove",this._mouseMoveHandler),e.removeEventListener("mouseenter",this._mouseEnterHandler),e.removeEventListener("mouseleave",this._mouseLeaveHandler),e.removeEventListener("mousedown",this._mouseDownHandler),e.removeEventListener("mouseup",this._mouseUpHandler)}}function JA(e,t,s){if(e){const{left:i,top:r}=t.getBoundingClientRect();s[0]=e.clientX-i,s[1]=e.clientY-r}else e=window.event,s[0]=e.x,s[1]=e.y;return s}const YA=function(e,t,s){if(e){const i=t.getBoundingClientRect();s[0]=e.clientX-i.left,s[1]=e.clientY-i.top}else e=window.event,s[0]=e.x,s[1]=e.y;return s};class $A{constructor(e,t,s,i,r){this._scene=e;const n=t.pickController,A=t.pivotController,o=R.vec2(),a=R.vec2(),l=R.vec2(),c=R.vec2(),h=[],u=this._scene.canvas.canvas;let d=0,p=!1;this._onTick=e.on("tick",(()=>{p=!1})),u.addEventListener("touchstart",this._canvasTouchStartHandler=t=>{if(!s.active||!s.pointerEnabled)return;t.preventDefault();const r=t.touches,a=t.changedTouches;for(i.touchStartTime=Date.now(),1===r.length&&1===a.length&&(YA(r[0],u,o),s.followPointer&&(n.pickCursorPos=o,n.schedulePickSurface=!0,n.update(),s.planView||(n.picked&&n.pickedSurface&&n.pickResult&&n.pickResult.worldPos?(A.setPivotPos(n.pickResult.worldPos),!s.firstPerson&&A.startPivot()&&A.showPivot()):(s.smartPivot?A.setCanvasPivotPos(i.pointerCanvasPos):A.setPivotPos(e.camera.look),!s.firstPerson&&A.startPivot()&&A.showPivot()))));h.length<r.length;)h.push(R.vec2());for(let e=0,t=r.length;e<t;++e)YA(r[e],u,h[e]);d=r.length}),u.addEventListener("touchend",this._canvasTouchEndHandler=()=>{A.getPivoting()&&(A.endPivot(),A.hidePivot())}),u.addEventListener("touchmove",this._canvasTouchMoveHandler=t=>{if(!s.active||!s.pointerEnabled)return;if(t.stopPropagation(),t.preventDefault(),p)return;p=!0;const A=e.canvas.boundary,o=A[2],f=A[3],g=t.touches;if(t.touches.length===d){if(1===d){YA(g[0],u,a),R.subVec2(a,h[0],c);const t=c[0],n=c[1];if(null!==i.longTouchTimeout&&(Math.abs(t)>s.longTapRadius||Math.abs(n)>s.longTapRadius)&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),s.planView){const i=e.camera;if("perspective"===i.projection){const A=Math.abs(e.camera.eyeLookDist)*Math.tan(i.perspective.fov/2*Math.PI/180);r.panDeltaX+=t*A/f*s.touchPanRate,r.panDeltaY+=n*A/f*s.touchPanRate}else r.panDeltaX+=.5*i.ortho.scale*(t/f)*s.touchPanRate,r.panDeltaY+=.5*i.ortho.scale*(n/f)*s.touchPanRate}else r.rotateDeltaY-=t/o*(1*s.dragRotationRate),r.rotateDeltaX+=n/f*(1.5*s.dragRotationRate)}else if(2===d){const t=g[0],A=g[1];YA(t,u,a),YA(A,u,l);const o=R.geometricMeanVec2(h[0],h[1]),c=R.geometricMeanVec2(a,l),d=R.vec2();R.subVec2(o,c,d);const p=d[0],m=d[1],_=e.camera,b=R.distVec2([t.pageX,t.pageY],[A.pageX,A.pageY]),y=(R.distVec2(h[0],h[1])-b)*s.touchDollyRate;if(r.dollyDelta=y,i.followPointerDirty=!0,Math.abs(y)<1)if("perspective"===_.projection){const t=n.pickResult?n.pickResult.worldPos:e.center,i=Math.abs(R.lenVec3(R.subVec3(t,e.camera.eye,[])))*Math.tan(_.perspective.fov/2*Math.PI/180);r.panDeltaX-=p*i/f*s.touchPanRate,r.panDeltaY-=m*i/f*s.touchPanRate}else r.panDeltaX-=.5*_.ortho.scale*(p/f)*s.touchPanRate,r.panDeltaY-=.5*_.ortho.scale*(m/f)*s.touchPanRate;i.pointerCanvasPos=c}for(let e=0;e<d;++e)YA(g[e],u,h[e])}})}reset(){}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler),e.removeEventListener("touchmove",this._canvasTouchMoveHandler),this._scene.off(this._onTick)}}const qA=function(e,t){if(e){let s=e.target,i=0,r=0;for(;s.offsetParent;)i+=s.offsetLeft,r+=s.offsetTop,s=s.offsetParent;t[0]=e.pageX-i,t[1]=e.pageY-r}else e=window.event,t[0]=e.x,t[1]=e.y;return t};class eo{constructor(e,t,s,i,r){this._scene=e;const n=t.pickController,A=t.cameraControl;let o;const a=[],l=new Float32Array(2);let c=-1,h=-1;const u=this._scene.canvas.canvas,d=s=>{let i;s&&s.worldPos&&(i=s.worldPos);const r=s?s.entity.aabb:e.aabb;if(i){const s=e.camera;R.subVec3(s.eye,s.look,[]),t.cameraFlight.flyTo({aabb:r})}else t.cameraFlight.flyTo({aabb:r})};u.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{if(!s.active||!s.pointerEnabled)return;null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null);const r=e.touches,n=e.changedTouches;if(o=Date.now(),1===r.length&&1===n.length){c=o,qA(r[0],l);const n=l[0],A=l[1],a=r[0].pageX,h=r[0].pageY;i.longTouchTimeout=setTimeout((()=>{s.active&&s.pointerEnabled&&t.cameraControl.fire("rightClick",{pagePos:[Math.round(a),Math.round(h)],canvasPos:[Math.round(n),Math.round(A)],event:e},!0),i.longTouchTimeout=null}),s.longTapTimeout)}else c=-1;for(;a.length<r.length;)a.push(new Float32Array(2));for(let e=0,t=r.length;e<t;++e)qA(r[e],a[e]);a.length=r.length},{passive:!0}),u.addEventListener("touchend",this._canvasTouchEndHandler=e=>{if(!s.active||!s.pointerEnabled)return;const t=Date.now(),r=e.touches,o=e.changedTouches,u=A.hasSubs("pickedSurface");null!==i.longTouchTimeout&&(clearTimeout(i.longTouchTimeout),i.longTouchTimeout=null),0===r.length&&1===o.length&&c>-1&&t-c<150&&(h>-1&&c-h<325?(qA(o[0],n.pickCursorPos),n.schedulePickEntity=!0,n.schedulePickSurface=u,n.update(),n.pickResult?(n.pickResult.touchInput=!0,A.fire("doublePicked",n.pickResult),n.pickedSurface&&A.fire("doublePickedSurface",n.pickResult),s.doublePickFlyTo&&d(n.pickResult)):(A.fire("doublePickedNothing"),s.doublePickFlyTo&&d()),h=-1):R.distVec2(a[0],l)<4&&(qA(o[0],n.pickCursorPos),n.schedulePickEntity=!0,n.schedulePickSurface=u,n.update(),n.pickResult?(n.pickResult.touchInput=!0,A.fire("picked",n.pickResult),n.pickedSurface&&A.fire("pickedSurface",n.pickResult)):A.fire("pickedNothing"),h=t),c=-1),a.length=r.length;for(let e=0,t=r.length;e<t;++e)a[e][0]=r[e].pageX,a[e][1]=r[e].pageY},{passive:!0})}reset(){}destroy(){const e=this._scene.canvas.canvas;e.removeEventListener("touchstart",this._canvasTouchStartHandler),e.removeEventListener("touchend",this._canvasTouchEndHandler)}}class to extends ie{constructor(e,t={}){super(e,t),this.PAN_LEFT=0,this.PAN_RIGHT=1,this.PAN_UP=2,this.PAN_DOWN=3,this.PAN_FORWARDS=4,this.PAN_BACKWARDS=5,this.ROTATE_X_POS=6,this.ROTATE_X_NEG=7,this.ROTATE_Y_POS=8,this.ROTATE_Y_NEG=9,this.DOLLY_FORWARDS=10,this.DOLLY_BACKWARDS=11,this.AXIS_VIEW_RIGHT=12,this.AXIS_VIEW_BACK=13,this.AXIS_VIEW_LEFT=14,this.AXIS_VIEW_FRONT=15,this.AXIS_VIEW_TOP=16,this.AXIS_VIEW_BOTTOM=17,this.MOUSE_PAN=18,this.MOUSE_ROTATE=19,this.MOUSE_DOLLY=20,this._keyMap={},this.scene.canvas.canvas.oncontextmenu=e=>{e.preventDefault()},this._configs={longTapTimeout:600,longTapRadius:5,active:!0,keyboardLayout:"qwerty",navMode:"orbit",planView:!1,firstPerson:!1,followPointer:!0,doublePickFlyTo:!0,panRightClick:!0,showPivot:!1,pointerEnabled:!0,constrainVertical:!1,smartPivot:!1,doubleClickTimeFrame:250,zoomOnMouseWheel:!0,snapToVertex:true,snapToEdge:true,snapRadius:30,keyboardEnabledOnlyIfMouseover:!0,dragRotationRate:360,keyboardRotationRate:90,rotationInertia:0,keyboardPanRate:1,touchPanRate:1,panInertia:.5,keyboardDollyRate:10,mouseWheelDollyRate:100,touchDollyRate:.2,dollyInertia:0,dollyProximityThreshold:30,dollyMinSpeed:.04},this._states={pointerCanvasPos:R.vec2(),mouseover:!1,followPointerDirty:!0,mouseDownClientX:0,mouseDownClientY:0,mouseDownCursorX:0,mouseDownCursorY:0,touchStartTime:null,activeTouches:[],tapStartPos:R.vec2(),tapStartTime:-1,lastTapTime:-1,longTouchTimeout:null},this._updates={rotateDeltaX:0,rotateDeltaY:0,panDeltaX:0,panDeltaY:0,panDeltaZ:0,dollyDelta:0};const s=this.scene;this._controllers={cameraControl:this,pickController:new DA(this,this._configs),pivotController:new SA(s,this._configs),panController:new MA(s),cameraFlight:new Ce(this,{duration:.5})},this._handlers=[new ZA(this.scene,this._controllers,this._configs,this._states,this._updates),new $A(this.scene,this._controllers,this._configs,this._states,this._updates),new RA(this.scene,this._controllers,this._configs,this._states,this._updates),new jA(this.scene,this._controllers,this._configs,this._states,this._updates),new zA(this.scene,this._controllers,this._configs,this._states,this._updates),new eo(this.scene,this._controllers,this._configs,this._states,this._updates),new WA(this.scene,this._controllers,this._configs,this._states,this._updates)],this._cursors={dollyForward:"zoom-in",dollyBackward:"zoom-out",rotate:"grabbing",pan:"move"},this._cameraUpdater=new KA(this.scene,this._controllers,this._configs,this._states,this._updates),this.navMode=t.navMode,t.planView&&(this.planView=t.planView),this.constrainVertical=t.constrainVertical,t.keyboardLayout?this.keyboardLayout=t.keyboardLayout:this.keyMap=t.keyMap,this.doublePickFlyTo=t.doublePickFlyTo,this.panRightClick=t.panRightClick,this.active=t.active,this.followPointer=t.followPointer,this.rotationInertia=t.rotationInertia,this.keyboardPanRate=t.keyboardPanRate,this.touchPanRate=t.touchPanRate,this.keyboardRotationRate=t.keyboardRotationRate,this.dragRotationRate=t.dragRotationRate,this.touchDollyRate=t.touchDollyRate,this.dollyInertia=t.dollyInertia,this.dollyProximityThreshold=t.dollyProximityThreshold,this.dollyMinSpeed=t.dollyMinSpeed,this.panInertia=t.panInertia,this.pointerEnabled=!0,this.keyboardDollyRate=t.keyboardDollyRate,this.mouseWheelDollyRate=t.mouseWheelDollyRate}set keyMap(e){if(e=e||"qwerty",j.isString(e)){const t=this.scene.input,s={};switch(e){default:this.error("Unsupported value for 'keyMap': "+e+" defaulting to 'qwerty'");case"qwerty":s[this.PAN_LEFT]=[t.KEY_A],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_Z],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_W,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_Q,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6],s[this.MOUSE_PAN]=[[t.MOUSE_LEFT_BUTTON,t.KEY_SHIFT],this._configs.panRightClick?t.MOUSE_RIGHT_BUTTON:t.MOUSE_MIDDLE_BUTTON],s[this.MOUSE_ROTATE]=[t.MOUSE_LEFT_BUTTON],s[this.MOUSE_DOLLY]=[];break;case"azerty":s[this.PAN_LEFT]=[t.KEY_Q],s[this.PAN_RIGHT]=[t.KEY_D],s[this.PAN_UP]=[t.KEY_W],s[this.PAN_DOWN]=[t.KEY_X],s[this.PAN_BACKWARDS]=[],s[this.PAN_FORWARDS]=[],s[this.DOLLY_FORWARDS]=[t.KEY_Z,t.KEY_ADD],s[this.DOLLY_BACKWARDS]=[t.KEY_S,t.KEY_SUBTRACT],s[this.ROTATE_X_POS]=[t.KEY_DOWN_ARROW],s[this.ROTATE_X_NEG]=[t.KEY_UP_ARROW],s[this.ROTATE_Y_POS]=[t.KEY_A,t.KEY_LEFT_ARROW],s[this.ROTATE_Y_NEG]=[t.KEY_E,t.KEY_RIGHT_ARROW],s[this.AXIS_VIEW_RIGHT]=[t.KEY_NUM_1],s[this.AXIS_VIEW_BACK]=[t.KEY_NUM_2],s[this.AXIS_VIEW_LEFT]=[t.KEY_NUM_3],s[this.AXIS_VIEW_FRONT]=[t.KEY_NUM_4],s[this.AXIS_VIEW_TOP]=[t.KEY_NUM_5],s[this.AXIS_VIEW_BOTTOM]=[t.KEY_NUM_6],s[this.MOUSE_PAN]=[[t.MOUSE_LEFT_BUTTON,t.KEY_SHIFT],this._configs.panRightClick?t.MOUSE_RIGHT_BUTTON:t.MOUSE_MIDDLE_BUTTON],s[this.MOUSE_ROTATE]=[t.MOUSE_LEFT_BUTTON],s[this.MOUSE_DOLLY]=[]}this._keyMap=s}else{const t=e;this._keyMap=t}}get keyMap(){return this._keyMap}_areAllKeysDown(e,t){if(!t||t.length<=0)return!0;if(!e)return!1;for(let s=0,i=t.length;s<i;s++){if(!e[t[s]])return!1}return!0}_isAnyOtherKeyDown(e,t){for(let s=0,i=e.length;s<i;s++)if(e[s])if(Array.isArray(t)){if(t.indexOf(s)<0)return!0}else if(s!==t)return!0;return!1}_isMouseAction(e){switch(e){case this.MOUSE_ROTATE:case this.MOUSE_DOLLY:case this.MOUSE_PAN:return!0;default:return!1}}_isKeyDownForAction(e,t){const s=this._keyMap[e];if(!s)return!1;if(0===s.length&&this._isMouseAction(e))return!0;t||(t=this.scene.input.keyDown);for(let e=0,i=s.length;e<i;e++){const i=s[e];if(Array.isArray(i)){if(this._areAllKeysDown(t,i)&&!this._isAnyOtherKeyDown(t,i))return!0}else if(t[i]&&!this._isAnyOtherKeyDown(t,i))return!0}return!1}set pivotElement(e){this._controllers.pivotController.setPivotElement(e)}set active(e){e=!1!==e,this._configs.active=e,this._handlers[1]._active=e,this._handlers[5]._active=e}get active(){return this._configs.active}set snapToVertex(e){this._configs.snapToVertex=!!e}get snapToVertex(){return this._configs.snapToVertex}set snapToEdge(e){this._configs.snapToEdge=!!e}get snapToEdge(){return this._configs.snapToEdge}set snapRadius(e){e=e||30,this._configs.snapRadius=e}get snapRadius(){return this._configs.snapRadius}set keyboardEnabledOnlyIfMouseover(e){this._configs.keyboardEnabledOnlyIfMouseover=!!e}get keyboardEnabledOnlyIfMouseover(){return this._configs.keyboardEnabledOnlyIfMouseover}set navMode(e){"firstPerson"!==(e=e||"orbit")&&"orbit"!==e&&"planView"!==e&&(this.error("Unsupported value for navMode: "+e+" - supported values are 'orbit', 'firstPerson' and 'planView' - defaulting to 'orbit'"),e="orbit"),this._configs.firstPerson="firstPerson"===e,this._configs.planView="planView"===e,(this._configs.firstPerson||this._configs.planView)&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this._configs.navMode=e}get navMode(){return this._configs.navMode}set pointerEnabled(e){this._reset(),this._configs.pointerEnabled=!!e}setCursorStyle(e,t){Object.prototype.hasOwnProperty.call(this._cursors,e)?this._cursors={...this._cursors,[e]:t}:console.warn(`Action '${e}' is not valid for cursor styles.`)}getCursorStyle(e){return this._cursors[e]||null}_reset(){for(let e=0,t=this._handlers.length;e<t;e++){const t=this._handlers[e];t.reset&&t.reset()}this._updates.panDeltaX=0,this._updates.panDeltaY=0,this._updates.rotateDeltaX=0,this._updates.rotateDeltaY=0,this._updates.dolyDelta=0}get pointerEnabled(){return this._configs.pointerEnabled}set followPointer(e){this._configs.followPointer=!1!==e}get followPointer(){return this._configs.followPointer}set pivotPos(e){this._controllers.pivotController.setPivotPos(e)}get pivotPos(){return this._controllers.pivotController.getPivotPos()}set dollyToPointer(e){this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer=e}get dollyToPointer(){return this.warn("dollyToPointer property is deprecated - replaced with followPointer"),this.followPointer}set panToPointer(e){this.warn("panToPointer property is deprecated - replaced with followPointer")}get panToPointer(){return this.warn("panToPointer property is deprecated - replaced with followPointer"),!1}set planView(e){this._configs.planView=!!e,this._configs.firstPerson=!1,this._configs.planView&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot()),this.warn("planView property is deprecated - replaced with navMode")}get planView(){return this.warn("planView property is deprecated - replaced with navMode"),this._configs.planView}set firstPerson(e){this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson=!!e,this._configs.planView=!1,this._configs.firstPerson&&(this._controllers.pivotController.hidePivot(),this._controllers.pivotController.endPivot())}get firstPerson(){return this.warn("firstPerson property is deprecated - replaced with navMode"),this._configs.firstPerson}set constrainVertical(e){this._configs.constrainVertical=!!e}get constrainVertical(){return this._configs.constrainVertical}set doublePickFlyTo(e){this._configs.doublePickFlyTo=!1!==e}get doublePickFlyTo(){return this._configs.doublePickFlyTo}set panRightClick(e){this._configs.panRightClick=!1!==e;const t=this._keyMap[this.MOUSE_PAN];if(t&&t.length>0){const e=this.scene.input;for(let s=0,i=t.length;s<i;s++)this._configs.panRightClick&&t[s]===e.MOUSE_MIDDLE_BUTTON?this._keyMap[this.MOUSE_PAN][s]=e.MOUSE_RIGHT_BUTTON:this._configs.panRightClick||t[s]!==e.MOUSE_RIGHT_BUTTON||(this._keyMap[this.MOUSE_PAN][s]=e.MOUSE_MIDDLE_BUTTON)}}get panRightClick(){return this._configs.panRightClick}set rotationInertia(e){this._configs.rotationInertia=null!=e?e:0}get rotationInertia(){return this._configs.rotationInertia}set keyboardPanRate(e){this._configs.keyboardPanRate=null!=e?e:5}set touchPanRate(e){this._configs.touchPanRate=null!=e?e:1}get touchPanRate(){return this._configs.touchPanRate}get keyboardPanRate(){return this._configs.keyboardPanRate}set keyboardRotationRate(e){this._configs.keyboardRotationRate=null!=e?e:90}get keyboardRotationRate(){return this._configs.keyboardRotationRate}set dragRotationRate(e){this._configs.dragRotationRate=null!=e?e:360}get dragRotationRate(){return this._configs.dragRotationRate}set keyboardDollyRate(e){this._configs.keyboardDollyRate=null!=e?e:15}get keyboardDollyRate(){return this._configs.keyboardDollyRate}set touchDollyRate(e){this._configs.touchDollyRate=null!=e?e:.2}get touchDollyRate(){return this._configs.touchDollyRate}set mouseWheelDollyRate(e){this._configs.mouseWheelDollyRate=null!=e?e:100}get mouseWheelDollyRate(){return this._configs.mouseWheelDollyRate}set dollyInertia(e){this._configs.dollyInertia=null!=e?e:0}get dollyInertia(){return this._configs.dollyInertia}set dollyProximityThreshold(e){this._configs.dollyProximityThreshold=null!=e?e:35}get dollyProximityThreshold(){return this._configs.dollyProximityThreshold}set dollyMinSpeed(e){this._configs.dollyMinSpeed=null!=e?e:.04}get dollyMinSpeed(){return this._configs.dollyMinSpeed}set panInertia(e){this._configs.panInertia=null!=e?e:.5}get panInertia(){return this._configs.panInertia}set keyboardLayout(e){"qwerty"!==(e=e||"qwerty")&&"azerty"!==e&&(this.error("Unsupported value for keyboardLayout - defaulting to 'qwerty'"),e="qwerty"),this._configs.keyboardLayout=e,this.keyMap=this._configs.keyboardLayout}get keyboardLayout(){return this._configs.keyboardLayout}enablePivotSphere(e={}){this._controllers.pivotController.enablePivotSphere(e)}disablePivotSphere(){this._controllers.pivotController.disablePivotSphere()}set smartPivot(e){this._configs.smartPivot=!1!==e}get smartPivot(){return this._configs.smartPivot}set doubleClickTimeFrame(e){this._configs.doubleClickTimeFrame=null!=e?e:250}get doubleClickTimeFrame(){return this._configs.doubleClickTimeFrame}set zoomOnMouseWheel(e){this._configs.zoomOnMouseWheel=!!e}get zoomOnMouseWheel(){return this._configs.zoomOnMouseWheel}destroy(){this._destroyHandlers(),this._destroyControllers(),this._cameraUpdater.destroy(),super.destroy()}_destroyHandlers(){for(let e=0,t=this._handlers.length;e<t;e++){const t=this._handlers[e];t.destroy&&t.destroy()}}_destroyControllers(){for(let e=0,t=this._controllers.length;e<t;e++){const t=this._controllers[e];t.destroy&&t.destroy()}}}class so{constructor(e,t,s,i,r){this.name=e,this.type=s,this.value=t,this.valueType=i,this.description=r}}class io{constructor(e){if(this.id=e.id,this.originalSystemId=e.originalSystemId,this.metaModels=[],this.name=e.name,this.type=e.type,this.properties=[],e.properties){const t=e.properties;for(let e=0,s=t.length;e<s;e++){const s=t[e];Number.isInteger(s)?this.properties.push(s):this.properties.push(new so(s.name,s.value,s.type,s.valueType,s.description))}}}}class ro{constructor(e){this.metaModels=[],this.id=e.id,this.parentId=e.parentId,this.parent=null,this.originalSystemId=e.originalSystemId,this.name=e.name,this.type=e.type,this.propertySetIds=e.propertySetIds,this.propertySets=[],this.attributes=e.attributes||{},void 0!==e.external&&null!==e.external&&(this.external=e.external)}get metaModel(){return 1==this.metaModels.length?this.metaModels[0]:null}getObjectIDsInSubtree(){const e=[];return function t(s){if(!s)return;e.push(s.id);const i=s.children;if(i)for(var r=0,n=i.length;r<n;r++)t(i[r])}(this),e}withMetaObjectsInSubtree(e){!function t(s){if(!s)return;e(s);const i=s.children;if(i)for(var r=0,n=i.length;r<n;r++)t(i[r])}(this)}getObjectIDsInSubtreeByType(e){const t={};for(var s=0,i=e.length;s<i;s++)t[e[s]]=e[s];const r=[];return function e(s){if(!s)return;t[s.type]&&r.push(s.id);const i=s.children;if(i)for(var n=0,A=i.length;n<A;n++)e(i[n])}(this),r}getJSON(){var e={id:this.id,type:this.type,name:this.name};return this.parent&&(e.parent=this.parent.id),e}}class no{constructor(e){this.id=e.id,this.projectId=e.projectId,this.revisionId=e.revisionId,this.author=e.author,this.createdAt=e.createdAt,this.creatingApplication=e.creatingApplication,this.schema=e.schema,this.metaScene=e.metaScene,this.propertySets=[],this.rootMetaObjects=[],this.metaObjects={},this.graph=e.graph||{},this.metaScene.metaModels[this.id]=this,this._propertyLookup=[],this.finalized=!1}get rootMetaObject(){return 1===this.rootMetaObjects.length?this.rootMetaObjects[0]:null}loadData(e,t={}){if(this.finalized)throw"MetaScene already finalized - can't add more data";this._globalizeIDs(e,t);const s=this.metaScene,i=e.properties;if(i)for(let e=0,t=i.length;e<t;e++)this._propertyLookup.push(i[e]);if(e.propertySets)for(let t=0,i=e.propertySets.length;t<i;t++){const i=e.propertySets[t];i.properties||(i.properties=[]);let r=s.propertySets[i.id];r||(r=new io({id:i.id,originalSystemId:i.originalSystemId||i.id,type:i.type,name:i.name,properties:i.properties}),s.propertySets[r.id]=r),r.metaModels.push(this),this.propertySets.push(r)}if(e.metaObjects)for(let t=0,i=e.metaObjects.length;t<i;t++){const i=e.metaObjects[t],r=i.id;let n=s.metaObjects[r];if(!n){const e=i.type,t=i.originalSystemId,s=i.propertySets||i.propertySetIds;n=new ro({id:r,originalSystemId:t,parentId:i.parent,type:e,name:i.name,attributes:i.attributes,propertySetIds:s,external:i.external}),this.metaScene.metaObjects[r]=n,n.metaModels=[]}this.metaObjects[r]=n,i.parent||(this.rootMetaObjects.push(n),s.rootMetaObjects[r]=n),n.metaModels.push(this)}}_decompressProperties(e,t){const s=[];for(let i=0,r=t.length;i<r;i++){const r=t[i];if(Number.isInteger(r)){const n=e[r];n?t[i]=n:s.push(r)}}s.length>0&&console.error(`[MetaModel._decompressProperties] Properties not found: ${s}`)}finalize(){if(this.finalized)throw"MetaScene already finalized - can't re-finalize";const e=this.metaScene;for(let t in e.metaObjects){const s=e.metaObjects[t];if(s.children&&(s.children=[]),s.propertySets&&(s.propertySets=[]),s.propertySetIds)for(let t=0,i=s.propertySetIds.length;t<i;t++){const i=s.propertySetIds[t],r=e.propertySets[i];s.propertySets.push(r)}}for(let t in e.metaObjects){const s=e.metaObjects[t];if(s.parentId){const t=e.metaObjects[s.parentId];t&&(s.parent=t,(t.children||(t.children=[])).push(s))}}for(let t in e.metaObjects){e.metaObjects[t].metaModels=[]}for(let t in e.metaModels){const s=e.metaModels[t];for(let e in s.metaObjects){s.metaObjects[e].metaModels.push(s)}}e.metaObjectsByType={};for(let t in e.metaObjects){const s=e.metaObjects[t],i=s.type;(e.metaObjectsByType[i]||(e.metaObjectsByType[i]={}))[t]=s}if(this.propertySets)for(let e=0,t=this.propertySets.length;e<t;e++){const t=this.propertySets[e];this._decompressProperties(this._propertyLookup,t.properties)}this._propertyLookup=[],this.finalized=!0,this.metaScene.fire("metaModelCreated",this.id)}getJSON(){const e={id:this.id,projectId:this.projectId,author:this.author,createdAt:this.createdAt,schema:this.schema,creatingApplication:this.creatingApplication,metaObjects:[],propertySets:[]},t=Object.values(this.metaObjects);for(let s=0,i=t.length;s<i;s++){const i=t[s],r={id:i.id,originalSystemId:i.originalSystemId,extId:i.extId,type:i.type,name:i.name};i.parent&&(r.parent=i.parent.id),i.attributes&&(r.attributes=i.attributes),i.propertySetIds&&(r.propertySetIds=i.propertySetIds),e.metaObjects.push(r)}for(let t=0,s=this.propertySets.length;t<s;t++){const s=this.propertySets[t],i={id:s.id,originalSystemId:s.originalSystemId,extId:s.extId,type:s.type,name:s.name,propertyies:[]};for(let e=0,t=s.properties.length;e<t;e++){const t=s.properties[e],r={id:t.id,description:t.description,type:t.type,name:t.name,value:t.value,valueType:t.valueType};i.properties.push(r)}e.propertySets.push(i)}return e}_globalizeIDs(e,t){const s=!!t.globalizeObjectIds;if(e.metaObjects)for(let t=0,i=e.metaObjects.length;t<i;t++){const i=e.metaObjects[t];if(i.originalSystemId=i.id,i.parent&&(i.originalParentSystemId=i.parent),s&&(i.id=R.globalizeObjectId(this.id,i.id),i.parent&&(i.parent=R.globalizeObjectId(this.id,i.parent))),s){const e=i.propertySetIds;if(e){const t=[];for(let s=0,i=e.length;s<i;s++)t.push(R.globalizeObjectId(this.id,e[s]));i.propertySetIds=t,i.originalSystemPropertySetIds=e}}else i.originalSystemPropertySetIds=i.propertySetIds}if(e.propertySets)for(let t=0,i=e.propertySets.length;t<i;t++){const i=e.propertySets[t];i.originalSystemId=i.id,s&&(i.id=R.globalizeObjectId(this.id,i.id))}}}class Ao{constructor(e,t){this.viewer=e,this.scene=t,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,i=s.length;e<i;e++)s[e](t)}off(e){}createMetaModel(e,t,s={}){const i=new no({metaScene:this,id:e,projectId:t.projectId||"none",revisionId:t.revisionId||"none",author:t.author||"none",createdAt:t.createdAt||"none",creatingApplication:t.creatingApplication||"none",schema:t.schema||"none",propertySets:[]});return i.loadData(t),i.finalize(),i}_destroy(){this.viewer=null,this.scene=null,this.metaModels={},this.propertySets={},this.metaObjects={},this.metaObjectsByType={},this.rootMetaObjects={},this._eventSubs={}}destroyMetaModel(e){const t=this.metaModels[e];if(t){if(t.propertySets)for(let s=0,i=t.propertySets.length;s<i;s++){const i=t.propertySets[s];if(1===i.metaModels.length&&i.metaModels[0].id===e)delete this.propertySets[i.id];else{const t=[];for(let s=0,r=i.metaModels.length;s<r;s++)i.metaModels[s].id!==e&&t.push(i.metaModels[s]);i.metaModels=t}}if(t.metaObjects)for(let s in t.metaObjects){const i=t.metaObjects[s];1===i.metaModels.length&&i.metaModels[0].id===e?(delete this.metaObjects[s],i.parent||delete this.rootMetaObjects[s]):i.metaModels=i.metaModels.filter((t=>t.id!==e))}for(let e in this.metaObjects){const t=this.metaObjects[e];if(t.children&&(t.children=[]),t.propertySets&&(t.propertySets=[]),t.propertySetIds)for(let e=0,s=t.propertySetIds.length;e<s;e++){const s=t.propertySetIds[e],i=this.propertySets[s];t.propertySets.push(i)}}this.metaObjectsByType={};for(let e in this.metaObjects){const t=this.metaObjects[e],s=t.type;t.children&&(t.children=null),(this.metaObjectsByType[s]||(this.metaObjectsByType[s]={}))[e]=t}for(let e in this.metaObjects){const t=this.metaObjects[e];if(t.parentId){const e=this.metaObjects[t.parentId];e&&(t.parent=e,(e.children||(e.children=[])).push(t))}}delete this.metaModels[e];for(let e in this.metaObjects){this.metaObjects[e].metaModels=[]}for(let e in this.metaModels){const t=this.metaModels[e];for(let e in t.metaObjects){t.metaObjects[e].metaModels.push(t)}}this.fire("metaModelDestroyed",e)}}getObjectIDsByType(e){const t=this.metaObjectsByType[e];return t?Object.keys(t):[]}getObjectIDsInSubtree(e,t,s){const i=[],r=this.metaObjects[e],n=t&&t.length>0?oo(t):null,A=s&&s.length>0?oo(s):null,o=e=>{if(!e)return;var t=!0;(A&&A[e.type]||n&&!n[e.type])&&(t=!1),t&&i.push(e.id);const s=e.children;if(s)for(var r=0,a=s.length;r<a;r++)o(s[r])};return o(r),i}withMetaObjectsInSubtree(e,t){const s=this.metaObjects[e];s&&s.withMetaObjectsInSubtree(t)}}function oo(e){const t={};for(var s=0,i=e.length;s<i;s++)t[e[s]]=!0;return t}async function ao(e,t,s,i){return i._parse(e,t,s,i)}function lo(e,t){if(!e)throw new Error(t||"loader assertion failed.")}const co=Boolean("object"!=typeof process||"[object process]"!==String(process)||process.browser),ho="undefined"!=typeof process&&process.version&&/v([0-9]*)/.exec(process.version);ho&&parseFloat(ho[1]);const uo=globalThis,po=globalThis.process||{};function fo(){return!("object"==typeof process&&"[object process]"===String(process)&&!process?.browser)||function(e){if("undefined"!=typeof window&&"renderer"===window.process?.type)return!0;if("undefined"!=typeof process&&Boolean(process.versions?.electron))return!0;const t="undefined"!=typeof navigator&&navigator.userAgent,s=e||t;return Boolean(s&&s.indexOf("Electron")>=0)}()}class go{constructor(e,t,s="sessionStorage"){this.storage=function(e){try{const t=window[e],s="__storage_test__";return t.setItem(s,s),t.removeItem(s),t}catch(e){return null}}(s),this.id=e,this.config=t,this._loadConfiguration()}getConfiguration(){return this.config}setConfiguration(e){if(Object.assign(this.config,e),this.storage){const e=JSON.stringify(this.config);this.storage.setItem(this.id,e)}}_loadConfiguration(){let e={};if(this.storage){const t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}}var mo;!function(e){e[e.BLACK=30]="BLACK",e[e.RED=31]="RED",e[e.GREEN=32]="GREEN",e[e.YELLOW=33]="YELLOW",e[e.BLUE=34]="BLUE",e[e.MAGENTA=35]="MAGENTA",e[e.CYAN=36]="CYAN",e[e.WHITE=37]="WHITE",e[e.BRIGHT_BLACK=90]="BRIGHT_BLACK",e[e.BRIGHT_RED=91]="BRIGHT_RED",e[e.BRIGHT_GREEN=92]="BRIGHT_GREEN",e[e.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",e[e.BRIGHT_BLUE=94]="BRIGHT_BLUE",e[e.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",e[e.BRIGHT_CYAN=96]="BRIGHT_CYAN",e[e.BRIGHT_WHITE=97]="BRIGHT_WHITE"}(mo||(mo={}));function _o(e){return"string"!=typeof e?e:(e=e.toUpperCase(),mo[e]||mo.WHITE)}function bo(e,t){if(!e)throw new Error(t||"Assertion failed")}function yo(){let e;if(fo()&&uo.performance)e=uo?.performance?.now?.();else if("hrtime"in po){const t=po?.hrtime?.();e=1e3*t[0]+t[1]/1e6}else e=Date.now();return e}const Bo={debug:fo()&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},wo={enabled:!0,level:0};function vo(){}const Co={},Mo={once:!0};class Eo{constructor({id:e}={id:""}){this.VERSION="4.1.0",this._startTs=yo(),this._deltaTs=yo(),this.userData={},this.LOG_THROTTLE_TIMEOUT=0,this.id=e,this.userData={},this._storage=new go(`__probe-${this.id}__`,wo),this.timeStamp(`${this.id} started`),function(e,t=["constructor"]){const s=Object.getPrototypeOf(e),i=Object.getOwnPropertyNames(s),r=e;for(const s of i){const i=r[s];"function"==typeof i&&(t.find((e=>s===e))||(r[s]=i.bind(e)))}}(this),Object.seal(this)}set level(e){this.setLevel(e)}get level(){return this.getLevel()}isEnabled(){return this._storage.config.enabled}getLevel(){return this._storage.config.level}getTotal(){return Number((yo()-this._startTs).toPrecision(10))}getDelta(){return Number((yo()-this._deltaTs).toPrecision(10))}set priority(e){this.level=e}get priority(){return this.level}getPriority(){return this.level}enable(e=!0){return this._storage.setConfiguration({enabled:e}),this}setLevel(e){return this._storage.setConfiguration({level:e}),this}get(e){return this._storage.config[e]}set(e,t){this._storage.setConfiguration({[e]:t})}settings(){console.table?console.table(this._storage.config):console.log(this._storage.config)}assert(e,t){if(!e)throw new Error(t||"Assertion failed")}warn(e){return this._getLogFunction(0,e,Bo.warn,arguments,Mo)}error(e){return this._getLogFunction(0,e,Bo.error,arguments)}deprecated(e,t){return this.warn(`\`${e}\` is deprecated and will be removed in a later version. Use \`${t}\` instead`)}removed(e,t){return this.error(`\`${e}\` has been removed. Use \`${t}\` instead`)}probe(e,t){return this._getLogFunction(e,t,Bo.log,arguments,{time:!0,once:!0})}log(e,t){return this._getLogFunction(e,t,Bo.debug,arguments)}info(e,t){return this._getLogFunction(e,t,console.info,arguments)}once(e,t){return this._getLogFunction(e,t,Bo.debug||Bo.info,arguments,Mo)}table(e,t,s){return t?this._getLogFunction(e,t,console.table||vo,s&&[s],{tag:Uo(t)}):vo}time(e,t){return this._getLogFunction(e,t,console.time?console.time:console.info)}timeEnd(e,t){return this._getLogFunction(e,t,console.timeEnd?console.timeEnd:console.info)}timeStamp(e,t){return this._getLogFunction(e,t,console.timeStamp||vo)}group(e,t,s={collapsed:!1}){const i=xo({logLevel:e,message:t,opts:s}),{collapsed:r}=s;return i.method=(r?console.groupCollapsed:console.group)||console.info,this._getLogFunction(i)}groupCollapsed(e,t,s={}){return this.group(e,t,Object.assign({},s,{collapsed:!0}))}groupEnd(e){return this._getLogFunction(e,"",console.groupEnd||vo)}withGroup(e,t,s){this.group(e,t)();try{s()}finally{this.groupEnd(e)()}}trace(){console.trace&&console.trace()}_shouldLog(e){return this.isEnabled()&&this.getLevel()>=Fo(e)}_getLogFunction(e,t,s,i,r){if(this._shouldLog(e)){r=xo({logLevel:e,message:t,args:i,opts:r}),bo(s=s||r.method),r.total=this.getTotal(),r.delta=this.getDelta(),this._deltaTs=yo();const n=r.tag||r.message;if(r.once&&n){if(Co[n])return vo;Co[n]=yo()}return t=function(e,t,s){if("string"==typeof t){const i=s.time?function(e,t=8){const s=Math.max(t-e.length,0);return`${" ".repeat(s)}${e}`}(function(e){let t;return t=e<10?`${e.toFixed(2)}ms`:e<100?`${e.toFixed(1)}ms`:e<1e3?`${e.toFixed(0)}ms`:`${(e/1e3).toFixed(2)}s`,t}(s.total)):"";t=s.time?`${e}: ${i} ${t}`:`${e}: ${t}`,t=function(e,t,s){fo||"string"!=typeof e||(t&&(e=`[${_o(t)}m${e}`),s&&(e=`[${_o(s)+10}m${e}`));return e}(t,s.color,s.background)}return t}(this.id,r.message,r),s.bind(console,t,...r.args)}return vo}}function Fo(e){if(!e)return 0;let t;switch(typeof e){case"number":t=e;break;case"object":t=e.logLevel||e.priority||0;break;default:return 0}return bo(Number.isFinite(t)&&t>=0),t}function xo(e){const{logLevel:t,message:s}=e;e.logLevel=Fo(t);const i=e.args?Array.from(e.args):[];for(;i.length&&i.shift()!==s;);switch(typeof t){case"string":case"function":void 0!==s&&i.unshift(s),e.message=t;break;case"object":Object.assign(e,t)}"function"==typeof e.message&&(e.message=e.message());const r=typeof e.message;return bo("string"===r||"object"===r),Object.assign(e,{args:i},e.opts)}function Uo(e){for(const t in e)for(const s in e[t])return s||"untitled";return"empty"}Eo.VERSION="4.1.0";const Io="4.3.3"[0]>="0"&&"4.3.3"[0]<="9"?"v4.3.3":"";const To=function(){const e=new Eo({id:"loaders.gl"});return globalThis.loaders=globalThis.loaders||{},globalThis.loaders.log=e,globalThis.loaders.version=Io,globalThis.probe=globalThis.probe||{},globalThis.probe.loaders=e,e}();function Po(e,t){return So(e||{},t)}function So(e,t,s=0){if(s>3)return t;const i={...e};for(const[e,r]of Object.entries(t))r&&"object"==typeof r&&!Array.isArray(r)?i[e]=So(i[e]||{},t[e],s+1):i[e]=t[e];return i}const Do=(globalThis._loadersgl_?.version||(globalThis._loadersgl_=globalThis._loadersgl_||{},globalThis._loadersgl_.version="4.3.3"),globalThis._loadersgl_.version);function ko(e,t){if(!e)throw new Error(t||"loaders.gl assertion failed.")}const Qo="object"!=typeof process||"[object process]"!==String(process)||process.browser,Ro="function"==typeof importScripts,Oo="undefined"!=typeof window&&void 0!==window.orientation,Vo="undefined"!=typeof process&&process.version&&/v([0-9]*)/.exec(process.version);Vo&&parseFloat(Vo[1]);class Lo{name;workerThread;isRunning=!0;result;_resolve=()=>{};_reject=()=>{};constructor(e,t){this.name=e,this.workerThread=t,this.result=new Promise(((e,t)=>{this._resolve=e,this._reject=t}))}postMessage(e,t){this.workerThread.postMessage({source:"loaders.gl",type:e,payload:t})}done(e){ko(this.isRunning),this.isRunning=!1,this._resolve(e)}error(e){ko(this.isRunning),this.isRunning=!1,this._reject(e)}}class Ho{terminate(){}}const No=new Map;function Go(e){ko(e.source&&!e.url||!e.source&&e.url);let t=No.get(e.source||e.url);return t||(e.url&&(t=function(e){if(!e.startsWith("http"))return e;return jo((t=e,`try {\n importScripts('${t}');\n} catch (error) {\n console.error(error);\n throw error;\n}`));var t}(e.url),No.set(e.url,t)),e.source&&(t=jo(e.source),No.set(e.source,t))),ko(t),t}function jo(e){const t=new Blob([e],{type:"application/javascript"});return URL.createObjectURL(t)}function zo(e,t=!0,s){const i=s||new Set;if(e){if(Wo(e))i.add(e);else if(Wo(e.buffer))i.add(e.buffer);else if(ArrayBuffer.isView(e));else if(t&&"object"==typeof e)for(const s in e)zo(e[s],t,i)}else;return void 0===s?Array.from(i):[]}function Wo(e){return!!e&&(e instanceof ArrayBuffer||("undefined"!=typeof MessagePort&&e instanceof MessagePort||("undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||"undefined"!=typeof OffscreenCanvas&&e instanceof OffscreenCanvas)))}const Xo=()=>{};class Ko{name;source;url;terminated=!1;worker;onMessage;onError;_loadableURL="";static isSupported(){return"undefined"!=typeof Worker&&Qo||void 0!==Ho&&!Qo}constructor(e){const{name:t,source:s,url:i}=e;ko(s||i),this.name=t,this.source=s,this.url=i,this.onMessage=Xo,this.onError=e=>console.log(e),this.worker=Qo?this._createBrowserWorker():this._createNodeWorker()}destroy(){this.onMessage=Xo,this.onError=Xo,this.worker.terminate(),this.terminated=!0}get isRunning(){return Boolean(this.onMessage)}postMessage(e,t){t=t||zo(e),this.worker.postMessage(e,t)}_getErrorFromErrorEvent(e){let t="Failed to load ";return t+=`worker ${this.name} from ${this.url}. `,e.message&&(t+=`${e.message} in `),e.lineno&&(t+=`:${e.lineno}:${e.colno}`),new Error(t)}_createBrowserWorker(){this._loadableURL=Go({source:this.source,url:this.url});const e=new Worker(this._loadableURL,{name:this.name});return e.onmessage=e=>{e.data?this.onMessage(e.data):this.onError(new Error("No data received"))},e.onerror=e=>{this.onError(this._getErrorFromErrorEvent(e)),this.terminated=!0},e.onmessageerror=e=>console.error(e),e}_createNodeWorker(){let e;if(this.url){const t=this.url.includes(":/")||this.url.startsWith("/")?this.url:`./${this.url}`;e=new Ho(t,{eval:!1})}else{if(!this.source)throw new Error("no worker");e=new Ho(this.source,{eval:!0})}return e.on("message",(e=>{this.onMessage(e)})),e.on("error",(e=>{this.onError(e)})),e.on("exit",(e=>{})),e}}class Zo{name="unnamed";source;url;maxConcurrency=1;maxMobileConcurrency=1;onDebug=()=>{};reuseWorkers=!0;props={};jobQueue=[];idleQueue=[];count=0;isDestroyed=!1;static isSupported(){return Ko.isSupported()}constructor(e){this.source=e.source,this.url=e.url,this.setProps(e)}destroy(){this.idleQueue.forEach((e=>e.destroy())),this.isDestroyed=!0}setProps(e){this.props={...this.props,...e},void 0!==e.name&&(this.name=e.name),void 0!==e.maxConcurrency&&(this.maxConcurrency=e.maxConcurrency),void 0!==e.maxMobileConcurrency&&(this.maxMobileConcurrency=e.maxMobileConcurrency),void 0!==e.reuseWorkers&&(this.reuseWorkers=e.reuseWorkers),void 0!==e.onDebug&&(this.onDebug=e.onDebug)}async startJob(e,t=((e,t,s)=>e.done(s)),s=((e,t)=>e.error(t))){const i=new Promise((i=>(this.jobQueue.push({name:e,onMessage:t,onError:s,onStart:i}),this)));return this._startQueuedJob(),await i}async _startQueuedJob(){if(!this.jobQueue.length)return;const e=this._getAvailableWorker();if(!e)return;const t=this.jobQueue.shift();if(t){this.onDebug({message:"Starting job",name:t.name,workerThread:e,backlog:this.jobQueue.length});const s=new Lo(t.name,e);e.onMessage=e=>t.onMessage(s,e.type,e.payload),e.onError=e=>t.onError(s,e),t.onStart(s);try{await s.result}catch(e){console.error(`Worker exception: ${e}`)}finally{this.returnWorkerToQueue(e)}}}returnWorkerToQueue(e){!Qo||this.isDestroyed||!this.reuseWorkers||this.count>this._getMaxConcurrency()?(e.destroy(),this.count--):this.idleQueue.push(e),this.isDestroyed||this._startQueuedJob()}_getAvailableWorker(){if(this.idleQueue.length>0)return this.idleQueue.shift()||null;if(this.count<this._getMaxConcurrency()){this.count++;const e=`${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;return new Ko({name:e,source:this.source,url:this.url})}return null}_getMaxConcurrency(){return Oo?this.maxMobileConcurrency:this.maxConcurrency}}const Jo={maxConcurrency:3,maxMobileConcurrency:1,reuseWorkers:!0,onDebug:()=>{}};class Yo{props;workerPools=new Map;static _workerFarm;static isSupported(){return Ko.isSupported()}static getWorkerFarm(e={}){return Yo._workerFarm=Yo._workerFarm||new Yo({}),Yo._workerFarm.setProps(e),Yo._workerFarm}constructor(e){this.props={...Jo},this.setProps(e),this.workerPools=new Map}destroy(){for(const e of this.workerPools.values())e.destroy();this.workerPools=new Map}setProps(e){this.props={...this.props,...e};for(const e of this.workerPools.values())e.setProps(this._getWorkerPoolProps())}getWorkerPool(e){const{name:t,source:s,url:i}=e;let r=this.workerPools.get(t);return r||(r=new Zo({name:t,source:s,url:i}),r.setProps(this._getWorkerPoolProps()),this.workerPools.set(t,r)),r}_getWorkerPoolProps(){return{maxConcurrency:this.props.maxConcurrency,maxMobileConcurrency:this.props.maxMobileConcurrency,reuseWorkers:this.props.reuseWorkers,onDebug:this.props.onDebug}}}const $o={};async function qo(e,t=null,s={},i=null){return t&&(e=function(e,t,s={},i=null){if(!s.useLocalLibraries&&e.startsWith("http"))return e;i=i||e;const r=s.modules||{};if(r[i])return r[i];if(!Qo)return`modules/${t}/dist/libs/${i}`;if(s.CDN)return ko(s.CDN.startsWith("http")),`${s.CDN}/${t}@${Do}/dist/libs/${i}`;if(Ro)return`../src/libs/${i}`;return`modules/${t}/src/libs/${i}`}(e,t,s,i)),$o[e]=$o[e]||async function(e){if(e.endsWith("wasm"))return await async function(e){const{readFileAsArrayBuffer:t}=globalThis.loaders||{};if(Qo||!t||e.startsWith("http")){const t=await fetch(e);return await t.arrayBuffer()}return await t(e)}(e);if(!Qo)try{const{requireFromFile:t}=globalThis.loaders||{};return await(t?.(e))}catch(e){return console.error(e),null}if(Ro)return importScripts(e);return function(e,t){if(!Qo){const{requireFromString:s}=globalThis.loaders||{};return s?.(e,t)}if(Ro)return eval.call(globalThis,e),null;const s=document.createElement("script");s.id=t;try{s.appendChild(document.createTextNode(e))}catch(t){s.text=e}return document.body.appendChild(s),null}(await async function(e){const{readFileAsText:t}=globalThis.loaders||{};if(Qo||!t||e.startsWith("http")){const t=await fetch(e);return await t.text()}return await t(e)}(e),e)}(e),await $o[e]}async function ea(e,t,s,i,r){const n=e.id,A=function(e,t={}){const s=t[e.id]||{},i=Qo?`${e.id}-worker.js`:`${e.id}-worker-node.js`;let r=s.workerUrl;if(r||"compression"!==e.id||(r=t.workerUrl),"test"===t._workerType&&(r=Qo?`modules/${e.module}/dist/${i}`:`modules/${e.module}/src/workers/${e.id}-worker-node.ts`),!r){let t=e.version;"latest"===t&&(t="latest");const s=t?`@${t}`:"";r=`https://unpkg.com/@loaders.gl/${e.module}${s}/dist/${i}`}return ko(r),r}(e,s),o=Yo.getWorkerFarm(s).getWorkerPool({name:n,url:A});s=JSON.parse(JSON.stringify(s)),i=JSON.parse(JSON.stringify(i||{}));const a=await o.startJob("process-on-worker",ta.bind(null,r));a.postMessage("process",{input:t,options:s,context:i});const l=await a.result;return await l.result}async function ta(e,t,s,i){switch(s){case"done":t.done(i);break;case"error":t.error(new Error(i.error));break;case"process":const{id:r,input:n,options:A}=i;try{const s=await e(n,A);t.postMessage("done",{id:r,result:s})}catch(e){const s=e instanceof Error?e.message:"unknown error";t.postMessage("error",{id:r,error:s})}break;default:console.warn(`parse-with-worker unknown message ${s}`)}}function sa(e,t,s){if(e.byteLength<=t+s)return"";const i=new DataView(e);let r="";for(let e=0;e<s;e++)r+=String.fromCharCode(i.getUint8(t+e));return r}function ia(e){try{return JSON.parse(e)}catch(t){throw new Error(`Failed to parse JSON from data starting with "${function(e,t=5){if("string"==typeof e)return e.slice(0,t);if(ArrayBuffer.isView(e))return sa(e.buffer,e.byteOffset,t);if(e instanceof ArrayBuffer)return sa(e,0,t);return""}(e)}"`)}}function ra(...e){return function(e){const t=e.map((e=>e instanceof ArrayBuffer?new Uint8Array(e):e)),s=t.reduce(((e,t)=>e+t.byteLength),0),i=new Uint8Array(s);let r=0;for(const e of t)i.set(e,r),r+=e.byteLength;return i.buffer}(e)}function na(e,t,s){const i=void 0!==s?new Uint8Array(e).subarray(t,t+s):new Uint8Array(e).subarray(t);return new Uint8Array(i).buffer}function Aa(e,t){return lo(e>=0),lo(t>0),e+(t-1)&~(t-1)}function oa(e,t,s){let i;if(e instanceof ArrayBuffer)i=new Uint8Array(e);else{const t=e.byteOffset,s=e.byteLength;i=new Uint8Array(e.buffer||e.arrayBuffer,t,s)}return t.set(i,s),s+Aa(i.byteLength,4)}const aa={};function la(e){if((t=e)&&"object"==typeof t&&t.isBuffer)return e;var t;if(e instanceof ArrayBuffer)return e;if(ArrayBuffer.isView(e))return 0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);if("string"==typeof e){const t=e;return(new TextEncoder).encode(t).buffer}if(e&&"object"==typeof e&&e._toArrayBuffer)return e._toArrayBuffer();throw new Error("toArrayBuffer")}function ca(e){const t=e?e.lastIndexOf("/"):-1;return t>=0?e.substr(t+1):""}const ha=e=>"function"==typeof e,ua=e=>null!==e&&"object"==typeof e,da=e=>ua(e)&&e.constructor==={}.constructor,pa=e=>"undefined"!=typeof Response&&e instanceof Response||e&&e.arrayBuffer&&e.text&&e.json,fa=e=>"undefined"!=typeof Blob&&e instanceof Blob,ga=e=>(e=>"undefined"!=typeof ReadableStream&&e instanceof ReadableStream||ua(e)&&ha(e.tee)&&ha(e.cancel)&&ha(e.getReader))(e)||(e=>ua(e)&&ha(e.read)&&ha(e.pipe)&&(e=>"boolean"==typeof e)(e.readable))(e);class ma extends Error{constructor(e,t){super(e),this.reason=t.reason,this.url=t.url,this.response=t.response}reason;url;response}const _a=/^data:([-\w.]+\/[-\w.+]+)(;|,)/,ba=/^([-\w.]+\/[-\w.+]+)/;function ya(e,t){return e.toLowerCase()===t.toLowerCase()}function Ba(e){const t=_a.exec(e);return t?t[1]:""}const wa=/\?.*/;function va(e){return e.replace(wa,"")}function Ca(e){if(pa(e)){return e.url}if(fa(e)){return e.name||""}return"string"==typeof e?e:""}function Ma(e){if(pa(e)){const t=e,s=t.headers.get("content-type")||"",i=va(t.url);return function(e){const t=ba.exec(e);return t?t[1]:e}(s)||Ba(i)}if(fa(e)){return e.type||""}return"string"==typeof e?Ba(e):""}async function Ea(e){if(pa(e))return e;const t={},s=function(e){if(pa(e))return e.headers["content-length"]||-1;if(fa(e))return e.size;return"string"==typeof e?e.length:e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e.byteLength:-1}(e);s>=0&&(t["content-length"]=String(s));const i=Ca(e),r=Ma(e);r&&(t["content-type"]=r);const n=await async function(e){const t=5;if("string"==typeof e)return`data:,${e.slice(0,t)}`;if(e instanceof Blob){const t=e.slice(0,5);return await new Promise((e=>{const s=new FileReader;s.onload=t=>e(t?.target?.result),s.readAsDataURL(t)}))}if(e instanceof ArrayBuffer){const s=function(e){let t="";const s=new Uint8Array(e);for(let e=0;e<s.byteLength;e++)t+=String.fromCharCode(s[e]);return btoa(t)}(e.slice(0,t));return`data:base64,${s}`}return null}(e);n&&(t["x-first-bytes"]=n),"string"==typeof e&&(e=(new TextEncoder).encode(e));const A=new Response(e,{headers:t});return Object.defineProperty(A,"url",{value:i}),A}async function Fa(e){if(!e.ok){const t=await async function(e){const t=function(e){if(e.length<50)return e;const t=e.slice(e.length-15);return`${e.substr(0,32)}...${t}`}(e.url);let s=`Failed to fetch resource (${e.status}) ${e.statusText}: ${t}`;s=s.length>100?`${s.slice(0,100)}...`:s;const i={reason:e.statusText,url:e.url,response:e};try{const t=e.headers.get("Content-Type");i.reason=!e.bodyUsed&&t?.includes("application/json")?await e.json():await e.text()}catch(e){}return new ma(s,i)}(e);throw t}}async function xa(e,t){if("string"==typeof e){const s=function(e){for(const t in aa)if(e.startsWith(t)){const s=aa[t];e=e.replace(t,s)}return e.startsWith("http://")||e.startsWith("https://")||(e=`${e}`),e}(e);return function(e){return!function(e){return e.startsWith("http:")||e.startsWith("https:")}(e)&&!function(e){return e.startsWith("data:")}(e)}(s)&&globalThis.loaders?.fetchNode?globalThis.loaders?.fetchNode(s,t):await fetch(s,t)}return await Ea(e)}const Ua=new Eo({id:"loaders.gl"});class Ia{log(){return()=>{}}info(){return()=>{}}warn(){return()=>{}}error(){return()=>{}}}const Ta={fetch:null,mimeType:void 0,nothrow:!1,log:new class{console;constructor(){this.console=console}log(...e){return this.console.log.bind(this.console,...e)}info(...e){return this.console.info.bind(this.console,...e)}warn(...e){return this.console.warn.bind(this.console,...e)}error(...e){return this.console.error.bind(this.console,...e)}},useLocalLibraries:!1,CDN:"https://unpkg.com/@loaders.gl",worker:!0,maxConcurrency:3,maxMobileConcurrency:1,reuseWorkers:co,_nodeWorkers:!1,_workerType:"",limit:0,_limitMB:0,batchSize:"auto",batchDebounceMs:0,metadata:!1,transforms:[]},Pa={throws:"nothrow",dataType:"(no longer used)",uri:"baseUri",method:"fetch.method",headers:"fetch.headers",body:"fetch.body",mode:"fetch.mode",credentials:"fetch.credentials",cache:"fetch.cache",redirect:"fetch.redirect",referrer:"fetch.referrer",referrerPolicy:"fetch.referrerPolicy",integrity:"fetch.integrity",keepalive:"fetch.keepalive",signal:"fetch.signal"};function Sa(){globalThis.loaders=globalThis.loaders||{};const{loaders:e}=globalThis;return e._state||(e._state={}),e._state}function Da(){const e=Sa();return e.globalOptions=e.globalOptions||{...Ta},e.globalOptions}function ka(e,t,s,i){return s=s||[],function(e,t){Qa(e,null,Ta,Pa,t);for(const s of t){const i=e&&e[s.id]||{},r=s.options&&s.options[s.id]||{},n=s.deprecatedOptions&&s.deprecatedOptions[s.id]||{};Qa(i,s.id,r,n,t)}}(e,s=Array.isArray(s)?s:[s]),function(e,t,s){const i={...e.options||{}};(function(e,t){t&&!("baseUri"in e)&&(e.baseUri=t)})(i,s),null===i.log&&(i.log=new Ia);return Oa(i,Da()),Oa(i,t),i}(t,e,i)}function Qa(e,t,s,i,r){const n=t||"Top level",A=t?`${t}.`:"";for(const o in e){const a=!t&&ua(e[o]),l="baseUri"===o&&!t,c="workerUrl"===o&&t;if(!(o in s)&&!l&&!c)if(o in i)Ua.warn(`${n} loader option '${A}${o}' no longer supported, use '${i[o]}'`)();else if(!a){const e=Ra(o,r);Ua.warn(`${n} loader option '${A}${o}' not recognized. ${e}`)()}}}function Ra(e,t){const s=e.toLowerCase();let i="";for(const r of t)for(const t in r.options){if(e===t)return`Did you mean '${r.id}.${t}'?`;const n=t.toLowerCase();(s.startsWith(n)||n.startsWith(s))&&(i=i||`Did you mean '${r.id}.${t}'?`)}return i}function Oa(e,t){for(const s in t)if(s in t){const i=t[s];da(i)&&da(e[s])?e[s]={...e[s],...t[s]}:e[s]=t[s]}}function Va(e){if(!e)return!1;Array.isArray(e)&&(e=e[0]);return Array.isArray(e?.extensions)}function La(e){let t;return lo(e,"null loader"),lo(Va(e),"invalid loader"),Array.isArray(e)&&(t=e[1],e=e[0],e={...e,options:{...e.options,...t}}),(e?.parseTextSync||e?.parseText)&&(e.text=!0),e.text||(e.binary=!0),e}function Ha(){return(()=>{const e=Sa();return e.loaderRegistry=e.loaderRegistry||[],e.loaderRegistry})()}const Na=/\.([^.]+)$/;function Ga(e,t=[],s,i){if(!ja(e))return null;if(t&&!Array.isArray(t))return La(t);let r=[];t&&(r=r.concat(t)),s?.ignoreRegisteredLoaders||r.push(...Ha()),function(e){for(const t of e)La(t)}(r);const n=function(e,t,s,i){const r=Ca(e),n=Ma(e),A=va(r)||i?.url;let o=null,a="";s?.mimeType&&(o=Wa(t,s?.mimeType),a=`match forced by supplied MIME type ${s?.mimeType}`);o=o||function(e,t){const s=t&&Na.exec(t),i=s&&s[1];return i?function(e,t){t=t.toLowerCase();for(const s of e)for(const e of s.extensions)if(e.toLowerCase()===t)return s;return null}(e,i):null}(t,A),a=a||(o?`matched url ${A}`:""),o=o||Wa(t,n),a=a||(o?`matched MIME type ${n}`:""),o=o||function(e,t){if(!t)return null;for(const s of e)if("string"==typeof t){if(Xa(t,s))return s}else if(ArrayBuffer.isView(t)){if(Ka(t.buffer,t.byteOffset,s))return s}else if(t instanceof ArrayBuffer){if(Ka(t,0,s))return s}return null}(t,e),a=a||(o?`matched initial data ${Za(e)}`:""),s?.fallbackMimeType&&(o=o||Wa(t,s?.fallbackMimeType),a=a||(o?`matched fallback MIME type ${n}`:""));a&&To.log(1,`selectLoader selected ${o?.name}: ${a}.`);return o}(e,r,s,i);if(!n&&!s?.nothrow)throw new Error(za(e));return n}function ja(e){return!(e instanceof Response&&204===e.status)}function za(e){const t=Ca(e),s=Ma(e);let i="No valid loader found (";i+=t?`${ca(t)}, `:"no url provided, ",i+=`MIME type: ${s?`"${s}"`:"not provided"}, `;const r=e?Za(e):"";return i+=r?` first bytes: "${r}"`:"first bytes: not available",i+=")",i}function Wa(e,t){for(const s of e){if(s.mimeTypes?.some((e=>ya(t,e))))return s;if(ya(t,`application/x.${s.id}`))return s}return null}function Xa(e,t){if(t.testText)return t.testText(e);return(Array.isArray(t.tests)?t.tests:[t.tests]).some((t=>e.startsWith(t)))}function Ka(e,t,s){return(Array.isArray(s.tests)?s.tests:[s.tests]).some((s=>function(e,t,s,i){if(i instanceof ArrayBuffer)return function(e,t,s){if(s=s||e.byteLength,e.byteLength<s||t.byteLength<s)return!1;const i=new Uint8Array(e),r=new Uint8Array(t);for(let e=0;e<i.length;++e)if(i[e]!==r[e])return!1;return!0}(i,e,i.byteLength);switch(typeof i){case"function":return i(e);case"string":return i===Ja(e,t,i.length);default:return!1}}(e,t,0,s)))}function Za(e,t=5){if("string"==typeof e)return e.slice(0,t);if(ArrayBuffer.isView(e))return Ja(e.buffer,e.byteOffset,t);if(e instanceof ArrayBuffer){return Ja(e,0,t)}return""}function Ja(e,t,s){if(e.byteLength<t+s)return"";const i=new DataView(e);let r="";for(let e=0;e<s;e++)r+=String.fromCharCode(i.getUint8(t+e));return r}const Ya=262144;function $a(e,t){return co?async function*(e,t){const s=e.getReader();let i;try{for(;;){const e=i||s.read();t?._streamReadAhead&&(i=s.read());const{done:r,value:n}=await e;if(r)return;yield la(n)}}catch(e){s.releaseLock()}}(e,t):async function*(e,t){for await(const t of e)yield la(t)}(e)}function qa(e,t){if("string"==typeof e)return function*(e,t){const s=t?.chunkSize||262144;let i=0;const r=new TextEncoder;for(;i<e.length;){const t=Math.min(e.length-i,s),n=e.slice(i,i+t);i+=t,yield r.encode(n)}}(e,t);if(e instanceof ArrayBuffer)return function*(e,t={}){const{chunkSize:s=Ya}=t;let i=0;for(;i<e.byteLength;){const t=Math.min(e.byteLength-i,s),r=new ArrayBuffer(t),n=new Uint8Array(e,i,t);new Uint8Array(r).set(n),i+=t,yield r}}(e,t);if(fa(e))return async function*(e,t){const s=t?.chunkSize||1048576;let i=0;for(;i<e.size;){const t=i+s,r=await e.slice(i,t).arrayBuffer();i=t,yield r}}(e,t);if(ga(e))return $a(e,t);if(pa(e)){return $a(e.body,t)}throw new Error("makeIterator")}const el="Cannot convert supplied data type";async function tl(e,t,s){const i=e instanceof ArrayBuffer||ArrayBuffer.isView(e);if("string"==typeof e||i)return function(e,t,s){if(t.text&&"string"==typeof e)return e;var i;if((i=e)&&"object"==typeof i&&i.isBuffer&&(e=e.buffer),e instanceof ArrayBuffer){const s=e;return t.text&&!t.binary?new TextDecoder("utf8").decode(s):s}if(ArrayBuffer.isView(e)){if(t.text&&!t.binary)return new TextDecoder("utf8").decode(e);let s=e.buffer;const i=e.byteLength||e.length;return 0===e.byteOffset&&i===s.byteLength||(s=s.slice(e.byteOffset,e.byteOffset+i)),s}throw new Error(el)}(e,t);if(fa(e)&&(e=await Ea(e)),pa(e)){const s=e;return await Fa(s),t.binary?await s.arrayBuffer():await s.text()}if(ga(e)&&(e=qa(e,s)),r=e,Boolean(r)&&"function"==typeof r[Symbol.iterator]||(e=>e&&"function"==typeof e[Symbol.asyncIterator])(e))return async function(e){const t=[];for await(const s of e)t.push(s);return ra(...t)}(e);var r;throw new Error(el)}function sl(e,t){const s=Da(),i=e||s;return"function"==typeof i.fetch?i.fetch:ua(i.fetch)?e=>xa(e,i.fetch):t?.fetch?t?.fetch:xa}function il(e,t,s){if(s)return s;const i={fetch:sl(t,e),...e};if(i.url){const e=va(i.url);i.baseUrl=e,i.queryString=function(e){const t=e.match(wa);return t&&t[0]}(i.url),i.filename=ca(e),i.baseUrl=function(e){const t=e?e.lastIndexOf("/"):-1;return t>=0?e.substr(0,t):""}(e)}return Array.isArray(i.loaders)||(i.loaders=null),i}async function rl(e,t,s,i){!t||Array.isArray(t)||Va(t)||(i=void 0,s=t,t=void 0),s=s||{};const r=Ca(e=await e),n=function(e,t){if(e&&!Array.isArray(e))return e;let s;if(e&&(s=Array.isArray(e)?e:[e]),t&&t.loaders){const e=Array.isArray(t.loaders)?t.loaders:[t.loaders];s=s?[...s,...e]:e}return s&&s.length?s:void 0}(t,i),A=await async function(e,t=[],s,i){if(!ja(e))return null;let r=Ga(e,t,{...s,nothrow:!0},i);if(r)return r;if(fa(e)&&(r=Ga(e=await e.slice(0,10).arrayBuffer(),t,s,i)),!r&&!s?.nothrow)throw new Error(za(e));return r}(e,n,s);return A?(i=il({url:r,_parse:rl,loaders:n},s=ka(s,A,n,r),i||null),await async function(e,t,s,i){if(function(e,t=Do){ko(e,"no worker provided");const s=e.version}(e),s=Po(e.options,s),pa(t)){const e=t,{ok:s,redirected:r,status:n,statusText:A,type:o,url:a}=e,l=Object.fromEntries(e.headers.entries());i.response={headers:l,ok:s,redirected:r,status:n,statusText:A,type:o,url:a}}t=await tl(t,e,s);const r=e;if(r.parseTextSync&&"string"==typeof t)return r.parseTextSync(t,s,i);if(function(e,t){return!!Yo.isSupported()&&!(!Qo&&!t?._nodeWorkers)&&e.worker&&t?.worker}(e,s))return await ea(e,t,s,i,rl);if(r.parseText&&"string"==typeof t)return await r.parseText(t,s,i);if(r.parse)return await r.parse(t,s,i);throw ko(!r.parseSync),new Error(`${e.id} loader - no parser found and worker is disabled`)}(A,e,s,i)):null}function nl(e){let t=1/0,s=1/0,i=1/0,r=-1/0,n=-1/0,A=-1/0;const o=e.POSITION?e.POSITION.value:[],a=o&&o.length;for(let e=0;e<a;e+=3){const a=o[e],l=o[e+1],c=o[e+2];t=a<t?a:t,s=l<s?l:s,i=c<i?c:i,r=a>r?a:r,n=l>n?l:n,A=c>A?c:A}return[[t,s,i],[r,n,A]]}function Al(e,t={}){const s=function(e){const t=[];for(const s in e){const i=e[s];t.push(ol(s,i))}return t}(e);return{fields:s,metadata:t}}function ol(e,t,s){const i=function(e){switch(e.constructor){case Int8Array:return"int8";case Uint8Array:case Uint8ClampedArray:return"uint8";case Int16Array:return"int16";case Uint16Array:return"uint16";case Int32Array:return"int32";case Uint32Array:return"uint32";case Float32Array:return"float32";case Float64Array:return"float64";default:return"null"}}(t.value),r=s||function(e){const t={};"byteOffset"in e&&(t.byteOffset=e.byteOffset.toString(10));"byteStride"in e&&(t.byteStride=e.byteStride.toString(10));"normalized"in e&&(t.normalized=e.normalized.toString());return t}(t);return{name:e,type:{type:"fixed-size-list",listSize:t.size,children:[{name:"value",type:i}]},nullable:!1,metadata:r}}const al=globalThis.loaders?.parseImageNode,ll="undefined"!=typeof Image,cl="undefined"!=typeof ImageBitmap,hl=Boolean(al),ul=!!co||hl;function dl(e){const t=function(e){if("undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap)return"imagebitmap";if("undefined"!=typeof Image&&e instanceof Image)return"image";if(e&&"object"==typeof e&&e.data&&e.width&&e.height)return"data";return null}(e);if(!t)throw new Error("Not an image");return t}function pl(e){switch(dl(e)){case"data":return e;case"image":case"imagebitmap":const t=document.createElement("canvas"),s=t.getContext("2d");if(!s)throw new Error("getImageData");return t.width=e.width,t.height=e.height,s.drawImage(e,0,0),s.getImageData(0,0,e.width,e.height);default:throw new Error("getImageData")}}const fl=/^data:image\/svg\+xml/,gl=/\.svg((\?|#).*)?$/;function ml(e){return e&&(fl.test(e)||gl.test(e))}function _l(e,t){if(ml(t))throw new Error("SVG cannot be parsed directly to imagebitmap");return new Blob([new Uint8Array(e)])}async function bl(e,t,s){const i=function(e,t){if(ml(t)){let t=(new TextDecoder).decode(e);try{"function"==typeof unescape&&"function"==typeof encodeURIComponent&&(t=unescape(encodeURIComponent(t)))}catch(e){throw new Error(e.message)}return`data:image/svg+xml;base64,${btoa(t)}`}return _l(e,t)}(e,s),r=self.URL||self.webkitURL,n="string"!=typeof i&&r.createObjectURL(i);try{return await async function(e,t){const s=new Image;if(s.src=e,t.image&&t.image.decode&&s.decode)return await s.decode(),s;return await new Promise(((e,t)=>{try{s.onload=()=>e(s),s.onerror=e=>{const s=e instanceof Error?e.message:"error";t(new Error(s))}}catch(e){t(e)}}))}(n||i,t)}finally{n&&r.revokeObjectURL(n)}}const yl={};let Bl=!0;async function wl(e,t,s){let i;if(ml(s)){i=await bl(e,t,s)}else i=_l(e,s);const r=t&&t.imagebitmap;return await async function(e,t=null){!function(e){for(const t in e||yl)return!1;return!0}(t)&&Bl||(t=null);if(t)try{return await createImageBitmap(e,t)}catch(e){console.warn(e),Bl=!1}return await createImageBitmap(e)}(i,r)}function vl(e){return function(e,t,s=0){const i=(r=t,[...r].map((e=>e.charCodeAt(0))));var r;for(let t=0;t<i.length;++t)if(i[t]!==e[t+s])return!1;return!0}(e,"ftyp",4)?0==(96&e[8])?null:function(e){switch((t=e,s=8,i=12,String.fromCharCode(...t.slice(s,i))).replace("\0"," ").trim()){case"avif":case"avis":return{extension:"avif",mimeType:"image/avif"};default:return null}var t,s,i}(e):null}function Cl(e){const t=Ml(e);return function(e){const t=Ml(e);if(!(t.byteLength>=24&&2303741511===t.getUint32(0,false)))return null;return{mimeType:"image/png",width:t.getUint32(16,false),height:t.getUint32(20,false)}}(t)||function(e){const t=Ml(e);if(!(t.byteLength>=3&&65496===t.getUint16(0,false)&&255===t.getUint8(2)))return null;const{tableMarkers:s,sofMarkers:i}=function(){const e=new Set([65499,65476,65484,65501,65534]);for(let t=65504;t<65520;++t)e.add(t);const t=new Set([65472,65473,65474,65475,65477,65478,65479,65481,65482,65483,65485,65486,65487,65502]);return{tableMarkers:e,sofMarkers:t}}();let r=2;for(;r+9<t.byteLength;){const e=t.getUint16(r,false);if(i.has(e))return{mimeType:"image/jpeg",height:t.getUint16(r+5,false),width:t.getUint16(r+7,false)};if(!s.has(e))return null;r+=2,r+=t.getUint16(r,false)}return null}(t)||function(e){const t=Ml(e);if(!(t.byteLength>=10&&1195984440===t.getUint32(0,false)))return null;return{mimeType:"image/gif",width:t.getUint16(6,true),height:t.getUint16(8,true)}}(t)||function(e){const t=Ml(e);if(!(t.byteLength>=14&&16973===t.getUint16(0,false)&&t.getUint32(2,true)===t.byteLength))return null;return{mimeType:"image/bmp",width:t.getUint32(18,true),height:t.getUint32(22,true)}}(t)||function(e){const t=vl(new Uint8Array(e instanceof DataView?e.buffer:e));if(!t)return null;return{mimeType:t.mimeType,width:0,height:0}}(t)}function Ml(e){if(e instanceof DataView)return e;if(ArrayBuffer.isView(e))return new DataView(e.buffer);if(e instanceof ArrayBuffer)return new DataView(e);throw new Error("toDataView")}const El={dataType:null,batchType:null,id:"image",module:"images",name:"Images",version:"4.3.3",mimeTypes:["image/png","image/jpeg","image/gif","image/webp","image/avif","image/bmp","image/vnd.microsoft.icon","image/svg+xml"],extensions:["png","jpg","jpeg","gif","webp","bmp","ico","svg","avif"],parse:async function(e,t,s){const i=((t=t||{}).image||{}).type||"auto",{url:r}=s||{};let n;switch(function(e){switch(e){case"auto":case"data":return function(){if(cl)return"imagebitmap";if(ll)return"image";if(ul)return"data";throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js")}();default:return function(e){switch(e){case"auto":return cl||ll||ul;case"imagebitmap":return cl;case"image":return ll;case"data":return ul;default:throw new Error(`@loaders.gl/images: image ${e} not supported in this environment`)}}(e),e}}(i)){case"imagebitmap":n=await wl(e,t,r);break;case"image":n=await bl(e,t,r);break;case"data":n=await async function(e,t){const{mimeType:s}=Cl(e)||{},i=globalThis.loaders?.parseImageNode;return lo(i),await i(e,s)}(e);break;default:lo(!1)}return"data"===i&&(n=pl(n)),n},tests:[e=>Boolean(Cl(new DataView(e)))],options:{image:{type:"auto",decode:!0}}},Fl={};function xl(e){if(void 0===Fl[e]){const t=co?function(e){switch(e){case"image/avif":case"image/webp":return function(e){try{const t=document.createElement("canvas");return 0===t.toDataURL(e).indexOf(`data:${e}`)}catch{return!1}}(e);default:return!0}}(e):function(e){const t=["image/png","image/jpeg","image/gif"],s=globalThis.loaders?.imageFormatsNode||t,i=globalThis.loaders?.parseImageNode;return Boolean(i)&&s.includes(e)}(e);Fl[e]=t}return Fl[e]}function Ul(e,t){if(!e)throw new Error(t||"assert failed: gltf")}const Il={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Tl={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Pl=["SCALAR","VEC2","VEC3","VEC4"],Sl=[[Int8Array,5120],[Uint8Array,5121],[Int16Array,5122],[Uint16Array,5123],[Uint32Array,5125],[Float32Array,5126],[Float64Array,5130]],Dl=new Map(Sl),kl={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ql={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},Rl={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function Ol(e){return Pl[e-1]||Pl[0]}function Vl(e){const t=Dl.get(e.constructor);if(!t)throw new Error("Illegal typed array");return t}function Ll(e,t){const s=Rl[e.componentType],i=kl[e.type],r=Ql[e.componentType],n=e.count*i,A=e.count*i*r;Ul(A>=0&&A<=t.byteLength);return{ArrayType:s,length:n,byteLength:A,componentByteSize:Tl[e.componentType],numberOfComponentsInElement:Il[e.type]}}class Hl{gltf;sourceBuffers;byteLength;constructor(e){this.gltf={json:e?.json||{asset:{version:"2.0",generator:"loaders.gl"},buffers:[],extensions:{},extensionsRequired:[],extensionsUsed:[]},buffers:e?.buffers||[],images:e?.images||[]},this.sourceBuffers=[],this.byteLength=0,this.gltf.buffers&&this.gltf.buffers[0]&&(this.byteLength=this.gltf.buffers[0].byteLength,this.sourceBuffers=[this.gltf.buffers[0]])}get json(){return this.gltf.json}getApplicationData(e){return this.json[e]}getExtraData(e){return(this.json.extras||{})[e]}hasExtension(e){const t=this.getUsedExtensions().find((t=>t===e)),s=this.getRequiredExtensions().find((t=>t===e));return"string"==typeof t||"string"==typeof s}getExtension(e){const t=this.getUsedExtensions().find((t=>t===e)),s=this.json.extensions||{};return t?s[e]:null}getRequiredExtension(e){const t=this.getRequiredExtensions().find((t=>t===e));return t?this.getExtension(e):null}getRequiredExtensions(){return this.json.extensionsRequired||[]}getUsedExtensions(){return this.json.extensionsUsed||[]}getRemovedExtensions(){return this.json.extensionsRemoved||[]}getObjectExtension(e,t){return(e.extensions||{})[t]}getScene(e){return this.getObject("scenes",e)}getNode(e){return this.getObject("nodes",e)}getSkin(e){return this.getObject("skins",e)}getMesh(e){return this.getObject("meshes",e)}getMaterial(e){return this.getObject("materials",e)}getAccessor(e){return this.getObject("accessors",e)}getTexture(e){return this.getObject("textures",e)}getSampler(e){return this.getObject("samplers",e)}getImage(e){return this.getObject("images",e)}getBufferView(e){return this.getObject("bufferViews",e)}getBuffer(e){return this.getObject("buffers",e)}getObject(e,t){if("object"==typeof t)return t;const s=this.json[e]&&this.json[e][t];if(!s)throw new Error(`glTF file error: Could not find ${e}[${t}]`);return s}getTypedArrayForBufferView(e){const t=(e=this.getBufferView(e)).buffer,s=this.gltf.buffers[t];Ul(s);const i=(e.byteOffset||0)+s.byteOffset;return new Uint8Array(s.arrayBuffer,i,e.byteLength)}getTypedArrayForAccessor(e){const t=this.getAccessor(e);return function(e,t,s){const i="number"==typeof s?e.accessors?.[s]:s;if(!i)throw new Error(`No gltf accessor ${JSON.stringify(s)}`);const r=e.bufferViews?.[i.bufferView||0];if(!r)throw new Error(`No gltf buffer view for accessor ${r}`);const{arrayBuffer:n,byteOffset:A}=t[r.buffer],o=(A||0)+(i.byteOffset||0)+(r.byteOffset||0),{ArrayType:a,length:l,componentByteSize:c,numberOfComponentsInElement:h}=Ll(i,r),u=c*h,d=r.byteStride||u;if(void 0===r.byteStride||r.byteStride===u)return new a(n,o,l);const p=new a(l);for(let e=0;e<i.count;e++){const t=new a(n,o+e*d,h);p.set(t,e*h)}return p}(this.gltf.json,this.gltf.buffers,t)}getTypedArrayForImageData(e){e=this.getAccessor(e);const t=this.getBufferView(e.bufferView),s=this.getBuffer(t.buffer).data,i=t.byteOffset||0;return new Uint8Array(s,i,t.byteLength)}addApplicationData(e,t){return this.json[e]=t,this}addExtraData(e,t){return this.json.extras=this.json.extras||{},this.json.extras[e]=t,this}addObjectExtension(e,t,s){return e.extensions=e.extensions||{},e.extensions[t]=s,this.registerUsedExtension(t),this}setObjectExtension(e,t,s){(e.extensions||{})[t]=s}removeObjectExtension(e,t){const s=e?.extensions||{};if(s[t]){this.json.extensionsRemoved=this.json.extensionsRemoved||[];const e=this.json.extensionsRemoved;e.includes(t)||e.push(t)}delete s[t]}addExtension(e,t={}){return Ul(t),this.json.extensions=this.json.extensions||{},this.json.extensions[e]=t,this.registerUsedExtension(e),t}addRequiredExtension(e,t={}){return Ul(t),this.addExtension(e,t),this.registerRequiredExtension(e),t}registerUsedExtension(e){this.json.extensionsUsed=this.json.extensionsUsed||[],this.json.extensionsUsed.find((t=>t===e))||this.json.extensionsUsed.push(e)}registerRequiredExtension(e){this.registerUsedExtension(e),this.json.extensionsRequired=this.json.extensionsRequired||[],this.json.extensionsRequired.find((t=>t===e))||this.json.extensionsRequired.push(e)}removeExtension(e){if(this.json.extensions?.[e]){this.json.extensionsRemoved=this.json.extensionsRemoved||[];const t=this.json.extensionsRemoved;t.includes(e)||t.push(e)}this.json.extensions&&delete this.json.extensions[e],this.json.extensionsRequired&&this._removeStringFromArray(this.json.extensionsRequired,e),this.json.extensionsUsed&&this._removeStringFromArray(this.json.extensionsUsed,e)}setDefaultScene(e){this.json.scene=e}addScene(e){const{nodeIndices:t}=e;return this.json.scenes=this.json.scenes||[],this.json.scenes.push({nodes:t}),this.json.scenes.length-1}addNode(e){const{meshIndex:t,matrix:s}=e;this.json.nodes=this.json.nodes||[];const i={mesh:t};return s&&(i.matrix=s),this.json.nodes.push(i),this.json.nodes.length-1}addMesh(e){const{attributes:t,indices:s,material:i,mode:r=4}=e,n={primitives:[{attributes:this._addAttributes(t),mode:r}]};if(s){const e=this._addIndices(s);n.primitives[0].indices=e}return Number.isFinite(i)&&(n.primitives[0].material=i),this.json.meshes=this.json.meshes||[],this.json.meshes.push(n),this.json.meshes.length-1}addPointCloud(e){const t={primitives:[{attributes:this._addAttributes(e),mode:0}]};return this.json.meshes=this.json.meshes||[],this.json.meshes.push(t),this.json.meshes.length-1}addImage(e,t){const s=Cl(e),i=t||s?.mimeType,r={bufferView:this.addBufferView(e),mimeType:i};return this.json.images=this.json.images||[],this.json.images.push(r),this.json.images.length-1}addBufferView(e,t=0,s=this.byteLength){const i=e.byteLength;Ul(Number.isFinite(i)),this.sourceBuffers=this.sourceBuffers||[],this.sourceBuffers.push(e);const r={buffer:t,byteOffset:s,byteLength:i};return this.byteLength+=Aa(i,4),this.json.bufferViews=this.json.bufferViews||[],this.json.bufferViews.push(r),this.json.bufferViews.length-1}addAccessor(e,t){const s={bufferView:e,type:Ol(t.size),componentType:t.componentType,count:t.count,max:t.max,min:t.min};return this.json.accessors=this.json.accessors||[],this.json.accessors.push(s),this.json.accessors.length-1}addBinaryBuffer(e,t={size:3}){const s=this.addBufferView(e);let i={min:t.min,max:t.max};i.min&&i.max||(i=this._getAccessorMinMax(e,t.size));const r={size:t.size,componentType:Vl(e),count:Math.round(e.length/t.size),min:i.min,max:i.max};return this.addAccessor(s,Object.assign(r,t))}addTexture(e){const{imageIndex:t}=e,s={source:t};return this.json.textures=this.json.textures||[],this.json.textures.push(s),this.json.textures.length-1}addMaterial(e){return this.json.materials=this.json.materials||[],this.json.materials.push(e),this.json.materials.length-1}createBinaryChunk(){const e=this.byteLength,t=new ArrayBuffer(e),s=new Uint8Array(t);let i=0;for(const e of this.sourceBuffers||[])i=oa(e,s,i);this.json?.buffers?.[0]?this.json.buffers[0].byteLength=e:this.json.buffers=[{byteLength:e}],this.gltf.binary=t,this.sourceBuffers=[t],this.gltf.buffers=[{arrayBuffer:t,byteOffset:0,byteLength:t.byteLength}]}_removeStringFromArray(e,t){let s=!0;for(;s;){const i=e.indexOf(t);i>-1?e.splice(i,1):s=!1}}_addAttributes(e={}){const t={};for(const s in e){const i=e[s],r=this._getGltfAttributeName(s),n=this.addBinaryBuffer(i.value,i);t[r]=n}return t}_addIndices(e){return this.addBinaryBuffer(e,{size:1})}_getGltfAttributeName(e){switch(e.toLowerCase()){case"position":case"positions":case"vertices":return"POSITION";case"normal":case"normals":return"NORMAL";case"color":case"colors":return"COLOR_0";case"texcoord":case"texcoords":return"TEXCOORD_0";default:return e}}_getAccessorMinMax(e,t){const s={min:null,max:null};if(e.length<t)return s;s.min=[],s.max=[];const i=e.subarray(0,t);for(const e of i)s.min.push(e),s.max.push(e);for(let i=t;i<e.length;i+=t)for(let r=0;r<t;r++)s.min[0+r]=Math.min(s.min[0+r],e[i+r]),s.max[0+r]=Math.max(s.max[0+r],e[i+r]);return s}}function Nl(e){return(e%1+1)%1}const Gl={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16,BOOLEAN:1,STRING:1,ENUM:1},jl={INT8:Int8Array,UINT8:Uint8Array,INT16:Int16Array,UINT16:Uint16Array,INT32:Int32Array,UINT32:Uint32Array,INT64:BigInt64Array,UINT64:BigUint64Array,FLOAT32:Float32Array,FLOAT64:Float64Array},zl={INT8:1,UINT8:1,INT16:2,UINT16:2,INT32:4,UINT32:4,INT64:8,UINT64:8,FLOAT32:4,FLOAT64:8};function Wl(e,t){return zl[t]*Gl[e]}function Xl(e,t,s,i){if("UINT8"!==s&&"UINT16"!==s&&"UINT32"!==s&&"UINT64"!==s)return null;const r=Kl(e.getTypedArrayForBufferView(t),"SCALAR",s,i+1);return r instanceof BigInt64Array||r instanceof BigUint64Array?null:r}function Kl(e,t,s,i=1){const r=jl[s],n=zl[s],A=i*Gl[t],o=A*n;let a=e.buffer,l=e.byteOffset;if(l%n!=0){a=new Uint8Array(a).slice(l,l+o).buffer,l=0}return new r(a,l,A)}function Zl(e,t,s){const i=`TEXCOORD_${t.texCoord||0}`,r=s.attributes[i],n=e.getTypedArrayForAccessor(r),A=e.gltf.json,o=t.index,a=A.textures?.[o]?.source;if(void 0!==a){const s=A.images?.[a]?.mimeType,i=e.gltf.images?.[a];if(i&&void 0!==i.width){const e=[];for(let r=0;r<n.length;r+=2){const A=Yl(i,s,n,r,t.channels);e.push(A)}return e}}return[]}function Jl(e,t,s,i,r){if(!s?.length)return;const n=[];for(const e of s){let t=i.findIndex((t=>t===e));-1===t&&(t=i.push(e)-1),n.push(t)}const A=new Uint32Array(n),o=e.gltf.buffers.push({arrayBuffer:A.buffer,byteOffset:A.byteOffset,byteLength:A.byteLength})-1,a=e.addBufferView(A,o,0),l=e.addAccessor(a,{size:1,componentType:Vl(A),count:A.length});r.attributes[t]=l}function Yl(e,t,s,i,r=[0]){const n={r:{offset:0,shift:0},g:{offset:1,shift:8},b:{offset:2,shift:16},a:{offset:3,shift:24}},A=s[i],o=s[i+1];let a=1;!t||-1===t.indexOf("image/jpeg")&&-1===t.indexOf("image/png")||(a=4);const l=function(e,t,s,i=1){const r=s.width,n=Nl(e)*(r-1),A=Math.round(n),o=s.height,a=Nl(t)*(o-1),l=Math.round(a),c=s.components?s.components:i;return(l*r+A)*c}(A,o,e,a);let c=0;for(const t of r){const s="number"==typeof t?Object.values(n)[t]:n[t],i=l+s.offset,r=pl(e);if(r.data.length<=i)throw new Error(`${r.data.length} <= ${i}`);c|=r.data[i]<<s.shift}return c}function $l(e,t,s,i,r){const n=[];for(let A=0;A<t;A++){const t=s[A],o=s[A+1]-s[A];if(o+t>i)break;const a=t/r,l=o/r;n.push(e.slice(a,a+l))}return n}function ql(e,t,s){const i=[];for(let r=0;r<t;r++){const t=r*s;i.push(e.slice(t,t+s))}return i}function ec(e,t,s,i){if(s)throw new Error("Not implemented - arrayOffsets for strings is specified");if(i){const s=[],r=new TextDecoder("utf8");let n=0;for(let A=0;A<e;A++){const e=i[A+1]-i[A];if(e+n<=t.length){const i=t.subarray(n,e+n),A=r.decode(i);s.push(A),n+=e}}return s}return[]}function tc(e,t,s){if(!s?.gltf?.loadBuffers)return;const i=t.extensions?.EXT_mesh_features,r=i?.featureIds;if(r)for(const i of r){let r;if(void 0!==i.attribute){const s=`_FEATURE_ID_${i.attribute}`,n=t.attributes[s];r=e.getTypedArrayForAccessor(n)}else r=void 0!==i.texture&&s?.gltf?.loadImages?Zl(e,i.texture,t):[];i.data=r}}function sc(e,t){const s=t.extensions?.EXT_mesh_features;if(!s)return;const i=s.featureIds;i.forEach(((s,r)=>{if(s.data){const{accessorKey:n,index:A}=function(e){const t="_FEATURE_ID_",s=Object.keys(e).filter((e=>0===e.indexOf(t)));let i=-1;for(const e of s){const s=Number(e.substring(t.length));s>i&&(i=s)}i++;return{accessorKey:`${t}${i}`,index:i}}(t.attributes),o=new Uint32Array(s.data);i[r]={featureCount:o.length,propertyTable:s.propertyTable,attribute:A},e.gltf.buffers.push({arrayBuffer:o.buffer,byteOffset:o.byteOffset,byteLength:o.byteLength});const a=e.addBufferView(o),l=e.addAccessor(a,{size:1,componentType:Vl(o),count:o.length});t.attributes[n]=l}}))}var ic=Object.freeze({__proto__:null,name:"EXT_mesh_features",decode:async function(e,t){!function(e,t){const s=e.gltf.json;if(!s.meshes)return;for(const i of s.meshes)for(const s of i.primitives)tc(e,s,t)}(new Hl(e),t)},encode:function(e,t){const s=new Hl(e);return function(e,t){const s=e.gltf.json.meshes;if(!s)return;for(const t of s)for(const s of t.primitives)sc(e,s)}(s),s.createBinaryChunk(),s.gltf},createExtMeshFeatures:function(e,t,s,i){t.extensions||(t.extensions={});let r=t.extensions.EXT_mesh_features;r||(r={featureIds:[]},t.extensions.EXT_mesh_features=r);const{featureIds:n}=r,A={featureCount:s.length,propertyTable:i,data:s};n.push(A),e.addObjectExtension(t,"EXT_mesh_features",r)}});function rc(e,t){for(const s of e)if(s.class===t)return s;return null}function nc(e,t,s,i){if(!t)return;const r=s.extensions?.EXT_structural_metadata,n=r?.propertyTextures;if(n)for(const r of n){Ac(e,t[r],s,i)}}function Ac(e,t,s,i){if(!t.properties)return;i.dataAttributeNames||(i.dataAttributeNames=[]);const r=t.class;for(const n in t.properties){const A=`${r}_${n}`,o=t.properties?.[n];if(!o)continue;o.data||(o.data=[]);const a=o.data,l=Zl(e,o,s);null!==l&&(Jl(e,A,l,a,s),o.data=a,i.dataAttributeNames.push(A))}}function oc(e,t,s){const i=t.classes?.[s.class];if(!i)throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${s.class}`);const r=s.count;for(const n in i.properties){const A=i.properties[n],o=s.properties?.[n];if(o){const s=ac(e,t,A,r,o);o.data=s}}}function ac(e,t,s,i,r){let n=[];const A=r.values,o=e.getTypedArrayForBufferView(A),a=function(e,t,s,i){if(t.array&&void 0===t.count&&void 0!==s.arrayOffsets)return Xl(e,s.arrayOffsets,s.arrayOffsetType||"UINT32",i);return null}(e,s,r,i),l=function(e,t,s){if(void 0!==t.stringOffsets)return Xl(e,t.stringOffsets,t.stringOffsetType||"UINT32",s);return null}(e,r,i);switch(s.type){case"SCALAR":case"VEC2":case"VEC3":case"VEC4":case"MAT2":case"MAT3":case"MAT4":n=function(e,t,s,i){const r=e.array,n=e.count,A=Wl(e.type,e.componentType),o=s.byteLength/A;let a;a=e.componentType?Kl(s,e.type,e.componentType,o):s;if(r)return i?$l(a,t,i,s.length,A):n?ql(a,t,n):[];return a}(s,i,o,a);break;case"BOOLEAN":throw new Error(`Not implemented - classProperty.type=${s.type}`);case"STRING":n=ec(i,o,a,l);break;case"ENUM":n=function(e,t,s,i,r){const n=t.enumType;if(!n)throw new Error("Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM");const A=e.enums?.[n];if(!A)throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${n}`);const o=A.valueType||"UINT16",a=Wl(t.type,o),l=i.byteLength/a;let c=Kl(i,t.type,o,l);c||(c=i);if(t.array){if(r)return function(e){const{valuesData:t,numberOfElements:s,arrayOffsets:i,valuesDataBytesLength:r,elementSize:n,enumEntry:A}=e,o=[];for(let e=0;e<s;e++){const s=i[e],a=i[e+1]-i[e];if(a+s>r)break;const l=lc(t,s/n,a/n,A);o.push(l)}return o}({valuesData:c,numberOfElements:s,arrayOffsets:r,valuesDataBytesLength:i.length,elementSize:a,enumEntry:A});const e=t.count;return e?function(e,t,s,i){const r=[];for(let n=0;n<t;n++){const t=lc(e,s*n,s,i);r.push(t)}return r}(c,s,e,A):[]}return lc(c,0,s,A)}(t,s,i,o,a);break;default:throw new Error(`Unknown classProperty type ${s.type}`)}return n}function lc(e,t,s,i){const r=[];for(let n=0;n<s;n++)if(e instanceof BigInt64Array||e instanceof BigUint64Array)r.push("");else{const s=cc(i,e[t+n]);s?r.push(s.name):r.push("")}return r}function cc(e,t){for(const s of e.values)if(s.value===t)return s;return null}function hc(e,t,s){for(const i in e.properties){const r=e.properties[i].data;if(r){const n=t.properties[i];if(n){const t=uc(r,n,s);e.properties[i]=t}}}}function uc(e,t,s){const i={values:0};if("STRING"===t.type){const{stringData:t,stringOffsets:r}=function(e){const t=new TextEncoder,s=[];let i=0;for(const r of e){const e=t.encode(r);i+=e.length,s.push(e)}const r=new Uint8Array(i),n=[];let A=0;for(const e of s)r.set(e,A),n.push(A),A+=e.length;n.push(A);const o=new Uint32Array(n);return{stringData:r,stringOffsets:o}}(e);i.stringOffsets=pc(r,s),i.values=pc(t,s)}else if("SCALAR"===t.type&&t.componentType){const r=function(e,t){const s=[];for(const t of e)s.push(Number(t));const i=dc[t];if(!i)throw new Error("Illegal component type");return new i(s)}(e,t.componentType);i.values=pc(r,s)}return i}const dc={INT8:Int8Array,UINT8:Uint8Array,INT16:Int16Array,UINT16:Uint16Array,INT32:Int32Array,UINT32:Uint32Array,INT64:Int32Array,UINT64:Uint32Array,FLOAT32:Float32Array,FLOAT64:Float64Array};function pc(e,t){return t.gltf.buffers.push({arrayBuffer:e.buffer,byteOffset:e.byteOffset,byteLength:e.byteLength}),t.addBufferView(e)}var fc=Object.freeze({__proto__:null,name:"EXT_structural_metadata",decode:async function(e,t){!function(e,t){if(!t.gltf?.loadBuffers)return;const s=e.getExtension("EXT_structural_metadata");if(!s)return;t.gltf?.loadImages&&function(e,t){const s=t.propertyTextures,i=e.gltf.json;if(s&&i.meshes)for(const r of i.meshes)for(const i of r.primitives)nc(e,s,i,t)}(e,s);!function(e,t){const s=t.schema;if(!s)return;const i=s.classes,r=t.propertyTables;if(i&&r)for(const t in i){const i=rc(r,t);i&&oc(e,s,i)}}(e,s)}(new Hl(e),t)},encode:function(e,t){const s=new Hl(e);return function(e,t){const s=e.getExtension("EXT_structural_metadata");if(!s)return;if(s.propertyTables)for(const t of s.propertyTables){const i=t.class,r=s.schema?.classes?.[i];t.properties&&r&&hc(t,r,e)}}(s),s.createBinaryChunk(),s.gltf},createExtStructuralMetadata:function(e,t,s="schemaClassId"){let i=e.getExtension("EXT_structural_metadata");i||(i=e.addExtension("EXT_structural_metadata")),i.schema=function(e,t,s){const i=s??{id:"schema_id"},r={properties:{}};for(const t of e){const e={type:t.elementType,componentType:t.componentType};r.properties[t.name]=e}return i.classes={},i.classes[t]=r,i}(t,s,i.schema);const r=function(e,t,s){const i={class:t,count:0};let r=0;const n=s.classes?.[t];for(const t of e){if(0===r&&(r=t.values.length),r!==t.values.length&&t.values.length)throw new Error("Illegal values in attributes");const e=n?.properties[t.name];e&&(i.properties||(i.properties={}),i.properties[t.name]={values:0,data:t.values})}return i.count=r,i}(t,s,i.schema);return i.propertyTables||(i.propertyTables=[]),i.propertyTables.push(r)-1}});function gc(e,t){for(const s in e){const i=e[s];if(i.class===t)return i}return null}function mc(e,t){for(const s in e){const i=e[s];if(i.class===t)return i}return null}function _c(e,t,s){if(!s.class)return;const i=t.classes?.[s.class];if(!i)throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${s.class}`);const r=s.count;for(const n in i.properties){const A=i.properties[n],o=s.properties?.[n];if(o){const s=yc(e,t,A,r,o);o.data=s}}}function bc(e,t,s){const i=t.class;for(const r in s.properties){const s=t?.properties?.[r];if(s){const t=Bc(e,s,i);s.data=t}}}function yc(e,t,s,i,r){let n=[];const A=r.bufferView,o=e.getTypedArrayForBufferView(A),a=function(e,t,s,i){if("ARRAY"===t.type&&void 0===t.componentCount&&void 0!==s.arrayOffsetBufferView)return Xl(e,s.arrayOffsetBufferView,s.offsetType||"UINT32",i);return null}(e,s,r,i),l=function(e,t,s,i){if(void 0!==s.stringOffsetBufferView)return Xl(e,s.stringOffsetBufferView,s.offsetType||"UINT32",i);return null}(e,0,r,i);return"STRING"===s.type||"STRING"===s.componentType?n=ec(i,o,a,l):function(e){const t=["UINT8","INT16","UINT16","INT32","UINT32","INT64","UINT64","FLOAT32","FLOAT64"];return t.includes(e.type)||void 0!==e.componentType&&t.includes(e.componentType)}(s)&&(n=function(e,t,s,i){const r="ARRAY"===e.type,n=e.componentCount,A="SCALAR",o=e.componentType||e.type,a=Wl(A,o),l=s.byteLength/a,c=Kl(s,A,o,l);if(r)return i?$l(c,t,i,s.length,a):n?ql(c,t,n):[];return c}(s,i,o,a)),n}function Bc(e,t,s){const i=e.gltf.json;if(!i.meshes)return[];const r=[];for(const n of i.meshes)for(const i of n.primitives)wc(e,s,t,r,i);return r}function wc(e,t,s,i,r){const n=Zl(e,{channels:s.channels,...s.texture},r);n&&Jl(e,t,n,i,r)}var vc=Object.freeze({__proto__:null,name:"EXT_feature_metadata",decode:async function(e,t){!function(e,t){if(!t.gltf?.loadBuffers)return;const s=e.getExtension("EXT_feature_metadata");if(!s)return;t.gltf?.loadImages&&function(e,t){const s=t.schema;if(!s)return;const i=s.classes,{featureTextures:r}=t;if(i&&r)for(const t in i){const s=i[t],n=mc(r,t);n&&bc(e,n,s)}}(e,s);!function(e,t){const s=t.schema;if(!s)return;const i=s.classes,r=t.featureTables;if(i&&r)for(const t in i){const i=gc(r,t);i&&_c(e,s,i)}}(e,s)}(new Hl(e),t)}});const Cc="basis_transcoder.js",Mc="basis_transcoder.wasm",Ec="basis_encoder.js",Fc="basis_encoder.wasm";let xc,Uc;async function Ic(e){var t;t=e.modules,globalThis.loaders||={},globalThis.loaders.modules||={},Object.assign(globalThis.loaders.modules,t);const s=function(e){const t=globalThis.loaders?.modules?.[e];return t||null}("basis");return s||(xc||=async function(e){let t=null,s=null;return[t,s]=await Promise.all([await qo(Cc,"textures",e),await qo(Mc,"textures",e)]),t=t||globalThis.BASIS,await function(e,t){const s={};t&&(s.wasmBinary=t);return new Promise((t=>{e(s).then((e=>{const{BasisFile:s,initializeBasis:i}=e;i(),t({BasisFile:s})}))}))}(t,s)}(e),await xc)}async function Tc(e){const t=e.modules||{};return t.basisEncoder?t.basisEncoder:(Uc=Uc||async function(e){let t=null,s=null;return[t,s]=await Promise.all([await qo(Ec,"textures",e),await qo(Fc,"textures",e)]),t=t||globalThis.BASIS,await function(e,t){const s={};t&&(s.wasmBinary=t);return new Promise((t=>{e(s).then((e=>{const{BasisFile:s,KTX2File:i,initializeBasis:r,BasisEncoder:n}=e;r(),t({BasisFile:s,KTX2File:i,BasisEncoder:n})}))}))}(t,s)}(e),await Uc)}const Pc=["","WEBKIT_","MOZ_"],Sc={WEBGL_compressed_texture_s3tc:"dxt",WEBGL_compressed_texture_s3tc_srgb:"dxt-srgb",WEBGL_compressed_texture_etc1:"etc1",WEBGL_compressed_texture_etc:"etc2",WEBGL_compressed_texture_pvrtc:"pvrtc",WEBGL_compressed_texture_atc:"atc",WEBGL_compressed_texture_astc:"astc",EXT_texture_compression_rgtc:"rgtc"};let Dc=null;function kc(e){if(!Dc){e=e||function(){try{return document.createElement("canvas").getContext("webgl")}catch(e){return null}}()||void 0,Dc=new Set;for(const t of Pc)for(const s in Sc)if(e&&e.getExtension(`${t}${s}`)){const e=Sc[s];Dc.add(e)}}return Dc}const Qc=[171,75,84,88,32,50,48,187,13,10,26,10];const Rc={etc1:{basisFormat:0,compressed:!0,format:36196},etc2:{basisFormat:1,compressed:!0},bc1:{basisFormat:2,compressed:!0,format:33776},bc3:{basisFormat:3,compressed:!0,format:33779},bc4:{basisFormat:4,compressed:!0},bc5:{basisFormat:5,compressed:!0},"bc7-m6-opaque-only":{basisFormat:6,compressed:!0},"bc7-m5":{basisFormat:7,compressed:!0},"pvrtc1-4-rgb":{basisFormat:8,compressed:!0,format:35840},"pvrtc1-4-rgba":{basisFormat:9,compressed:!0,format:35842},"astc-4x4":{basisFormat:10,compressed:!0,format:37808},"atc-rgb":{basisFormat:11,compressed:!0},"atc-rgba-interpolated-alpha":{basisFormat:12,compressed:!0},rgba32:{basisFormat:13,compressed:!1},rgb565:{basisFormat:14,compressed:!1},bgr565:{basisFormat:15,compressed:!1},rgba4444:{basisFormat:16,compressed:!1}};function Oc(e,t,s){const i=new e(new Uint8Array(t));try{if(!i.startTranscoding())throw new Error("Failed to start basis transcoding");const e=i.getNumImages(),t=[];for(let r=0;r<e;r++){const e=i.getNumLevels(r),n=[];for(let t=0;t<e;t++)n.push(Vc(i,r,t,s));t.push(n)}return t}finally{i.close(),i.delete()}}function Vc(e,t,s,i){const r=e.getImageWidth(t,s),n=e.getImageHeight(t,s),A=e.getHasAlpha(),{compressed:o,format:a,basisFormat:l}=Nc(i,A),c=e.getImageTranscodedSizeInBytes(t,s,l),h=new Uint8Array(c);if(!e.transcodeImage(h,t,s,l,0,0))throw new Error("failed to start Basis transcoding");return{width:r,height:n,data:h,compressed:o,format:a,hasAlpha:A}}function Lc(e,t,s){const i=new e(new Uint8Array(t));try{if(!i.startTranscoding())throw new Error("failed to start KTX2 transcoding");const e=i.getLevels(),t=[];for(let r=0;r<e;r++)t.push(Hc(i,r,s));return[t]}finally{i.close(),i.delete()}}function Hc(e,t,s){const{alphaFlag:i,height:r,width:n}=e.getImageLevelInfo(t,0,0),{compressed:A,format:o,basisFormat:a}=Nc(s,i),l=e.getImageTranscodedSizeInBytes(t,0,0,a),c=new Uint8Array(l);if(!e.transcodeImage(c,t,0,0,a,0,-1,-1))throw new Error("Failed to transcode KTX2 image");return{width:n,height:r,data:c,compressed:A,levelSize:l,hasAlpha:i,format:o}}function Nc(e,t){let s=e&&e.basis&&e.basis.format;return"auto"===s&&(s=Gc()),"object"==typeof s&&(s=t?s.alpha:s.noAlpha),s=s.toLowerCase(),Rc[s]}function Gc(){const e=kc();return e.has("astc")?"astc-4x4":e.has("dxt")?{alpha:"bc3",noAlpha:"bc1"}:e.has("pvrtc")?{alpha:"pvrtc1-4-rgba",noAlpha:"pvrtc1-4-rgb"}:e.has("etc1")?"etc1":e.has("etc2")?"etc2":"rgb565"}const jc={...{dataType:null,batchType:null,name:"Basis",id:"basis",module:"textures",version:"4.3.3",worker:!0,extensions:["basis","ktx2"],mimeTypes:["application/octet-stream","image/ktx2"],tests:["sB"],binary:!0,options:{basis:{format:"auto",libraryPath:"libs/",containerFormat:"auto",module:"transcoder"}}},parse:async function(e,t){if("auto"===t.basis.containerFormat){if(function(e){const t=new Uint8Array(e);return!(t.byteLength<Qc.length||t[0]!==Qc[0]||t[1]!==Qc[1]||t[2]!==Qc[2]||t[3]!==Qc[3]||t[4]!==Qc[4]||t[5]!==Qc[5]||t[6]!==Qc[6]||t[7]!==Qc[7]||t[8]!==Qc[8]||t[9]!==Qc[9]||t[10]!==Qc[10]||t[11]!==Qc[11])}(e)){return Lc((await Tc(t)).KTX2File,e,t)}const{BasisFile:s}=await Ic(t);return Oc(s,e,t)}if("encoder"===t.basis.module){const s=await Tc(t);return"ktx2"===t.basis.containerFormat?Lc(s.KTX2File,e,t):Oc(s.BasisFile,e,t)}{const{BasisFile:s}=await Ic(t);return Oc(s,e,t)}}},zc=1735152710;function Wc(e,t,s=0,i={}){const r=new DataView(t),n=function(e,t=0){return`${String.fromCharCode(e.getUint8(t+0))}${String.fromCharCode(e.getUint8(t+1))}${String.fromCharCode(e.getUint8(t+2))}${String.fromCharCode(e.getUint8(t+3))}`}(r,s+0),A=r.getUint32(s+4,true),o=r.getUint32(s+8,true);switch(Object.assign(e,{header:{byteOffset:s,byteLength:o,hasBinChunk:!1},type:n,version:A,json:{},binChunks:[]}),s+=12,e.version){case 1:return function(e,t,s){lo(e.header.byteLength>20);const i=t.getUint32(s+0,true),r=t.getUint32(s+4,true);return s+=8,lo(0===r),Xc(e,t,s,i),s+=i,s+=Kc(e,t,s,e.header.byteLength)}(e,r,s);case 2:return function(e,t,s,i){return lo(e.header.byteLength>20),function(e,t,s,i){for(;s+8<=e.header.byteLength;){const r=t.getUint32(s+0,true),n=t.getUint32(s+4,true);switch(s+=8,n){case 1313821514:Xc(e,t,s,r);break;case 5130562:Kc(e,t,s,r);break;case 0:i.strict||Xc(e,t,s,r);break;case 1:i.strict||Kc(e,t,s,r)}s+=Aa(r,4)}}(e,t,s,i),s+e.header.byteLength}(e,r,s,{});default:throw new Error(`Invalid GLB version ${e.version}. Only supports version 1 and 2.`)}}function Xc(e,t,s,i){const r=new Uint8Array(t.buffer,s,i),n=new TextDecoder("utf8").decode(r);return e.json=JSON.parse(n),Aa(i,4)}function Kc(e,t,s,i){return e.header.hasBinChunk=!0,e.binChunks.push({byteOffset:s,byteLength:i,arrayBuffer:t.buffer}),Aa(i,4)}function Zc(e,t){if(e.startsWith("data:")||e.startsWith("http:")||e.startsWith("https:"))return e;const s=t.baseUri||t.uri;if(!s)throw new Error(`'baseUri' must be provided to resolve relative url ${e}`);return s.substr(0,s.lastIndexOf("/")+1)+e}const Jc="B9h9z9tFBBBF8fL9gBB9gLaaaaaFa9gEaaaB9gFaFa9gEaaaFaEMcBFFFGGGEIIILF9wFFFLEFBFKNFaFCx/IFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBF8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBGy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBEn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBIi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBKI9z9iqlBOc+x8ycGBM/qQFTa8jUUUUBCU/EBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAGTkUUUBRNCUoBAG9uC/wgBZHKCUGAKCUG9JyRVAECFJRICBRcGXEXAcAF9PQFAVAFAclAcAVJAF9JyRMGXGXAG9FQBAMCbJHKC9wZRSAKCIrCEJCGrRQANCUGJRfCBRbAIRTEXGXAOATlAQ9PQBCBRISEMATAQJRIGXAS9FQBCBRtCBREEXGXAOAIlCi9PQBCBRISLMANCU/CBJAEJRKGXGXGXGXGXATAECKrJ2BBAtCKZrCEZfIBFGEBMAKhB83EBAKCNJhB83EBSEMAKAI2BIAI2BBHmCKrHYAYCE6HYy86BBAKCFJAICIJAYJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCGJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCEJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCIJAYAmJHY2BBAI2BFHmCKrHPAPCE6HPy86BBAKCLJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCKJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCOJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCNJAYAmJHY2BBAI2BGHmCKrHPAPCE6HPy86BBAKCVJAYAPJHY2BBAmCIrCEZHPAPCE6HPy86BBAKCcJAYAPJHY2BBAmCGrCEZHPAPCE6HPy86BBAKCMJAYAPJHY2BBAmCEZHmAmCE6Hmy86BBAKCSJAYAmJHm2BBAI2BEHICKrHYAYCE6HYy86BBAKCQJAmAYJHm2BBAICIrCEZHYAYCE6HYy86BBAKCfJAmAYJHm2BBAICGrCEZHYAYCE6HYy86BBAKCbJAmAYJHK2BBAICEZHIAICE6HIy86BBAKAIJRISGMAKAI2BNAI2BBHmCIrHYAYCb6HYy86BBAKCFJAICNJAYJHY2BBAmCbZHmAmCb6Hmy86BBAKCGJAYAmJHm2BBAI2BFHYCIrHPAPCb6HPy86BBAKCEJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCIJAmAYJHm2BBAI2BGHYCIrHPAPCb6HPy86BBAKCLJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCKJAmAYJHm2BBAI2BEHYCIrHPAPCb6HPy86BBAKCOJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCNJAmAYJHm2BBAI2BIHYCIrHPAPCb6HPy86BBAKCVJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCcJAmAYJHm2BBAI2BLHYCIrHPAPCb6HPy86BBAKCMJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCSJAmAYJHm2BBAI2BKHYCIrHPAPCb6HPy86BBAKCQJAmAPJHm2BBAYCbZHYAYCb6HYy86BBAKCfJAmAYJHm2BBAI2BOHICIrHYAYCb6HYy86BBAKCbJAmAYJHK2BBAICbZHIAICb6HIy86BBAKAIJRISFMAKAI8pBB83BBAKCNJAICNJ8pBB83BBAICTJRIMAtCGJRtAECTJHEAS9JQBMMGXAIQBCBRISEMGXAM9FQBANAbJ2BBRtCBRKAfREEXAEANCU/CBJAKJ2BBHTCFrCBATCFZl9zAtJHt86BBAEAGJREAKCFJHKAM9HQBMMAfCFJRfAIRTAbCFJHbAG9HQBMMABAcAG9sJANCUGJAMAG9sTkUUUBpANANCUGJAMCaJAG9sJAGTkUUUBpMAMCBAIyAcJRcAIQBMC9+RKSFMCBC99AOAIlAGCAAGCA9Ly6yRKMALCU/EBJ8kUUUUBAKM+OmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUFT+JUUUBpALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM+lLKFaF99GaG99FaG99GXGXAGCI9HQBAF9FQFEXGXGX9DBBB8/9DBBB+/ABCGJHG1BB+yAB1BBHE+yHI+L+TABCFJHL1BBHK+yHO+L+THN9DBBBB9gHVyAN9DBB/+hANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE86BBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG86BBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG86BBABCIJRBAFCaJHFQBSGMMAF9FQBEXGXGX9DBBB8/9DBBB+/ABCIJHG8uFB+yAB8uFBHE+yHI+L+TABCGJHL8uFBHK+yHO+L+THN9DBBBB9gHVyAN9DB/+g6ANAN+U9DBBBBANAVyHcAc+MHMAECa3yAI+SHIAI+UAcAMAKCa3yAO+SHcAc+U+S+S+R+VHO+U+SHN+L9DBBB9P9d9FQBAN+oRESFMCUUUU94REMAGAE87FBGXGX9DBBB8/9DBBB+/Ac9DBBBB9gyAcAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMALAG87FBGXGX9DBBB8/9DBBB+/AI9DBBBB9gyAIAO+U+SHN+L9DBBB9P9d9FQBAN+oRGSFMCUUUU94RGMABAG87FBABCNJRBAFCaJHFQBMMM/SEIEaE99EaF99GXAF9FQBCBREABRIEXGXGX9D/zI818/AICKJ8uFBHLCEq+y+VHKAI8uFB+y+UHO9DB/+g6+U9DBBB8/9DBBB+/AO9DBBBB9gy+SHN+L9DBBB9P9d9FQBAN+oRVSFMCUUUU94RVMAICIJ8uFBRcAICGJ8uFBRMABALCFJCEZAEqCFWJAV87FBGXGXAKAM+y+UHN9DB/+g6+U9DBBB8/9DBBB+/AN9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRMSFMCUUUU94RMMABALCGJCEZAEqCFWJAM87FBGXGXAKAc+y+UHK9DB/+g6+U9DBBB8/9DBBB+/AK9DBBBB9gy+SHS+L9DBBB9P9d9FQBAS+oRcSFMCUUUU94RcMABALCaJCEZAEqCFWJAc87FBGXGX9DBBU8/AOAO+U+TANAN+U+TAKAK+U+THO9DBBBBAO9DBBBB9gy+R9DB/+g6+U9DBBB8/+SHO+L9DBBB9P9d9FQBAO+oRcSFMCUUUU94RcMABALCEZAEqCFWJAc87FBAICNJRIAECIJREAFCaJHFQBMMM9JBGXAGCGrAF9sHF9FQBEXABAB8oGBHGCNWCN91+yAGCi91CnWCUUU/8EJ+++U84GBABCIJRBAFCaJHFQBMMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEM/lFFFaGXGXAFABqCEZ9FQBABRESFMGXGXAGCT9PQBABRESFMABREEXAEAF8oGBjGBAECIJAFCIJ8oGBjGBAECNJAFCNJ8oGBjGBAECSJAFCSJ8oGBjGBAECTJREAFCTJRFAGC9wJHGCb9LQBMMAGCI9JQBEXAEAF8oGBjGBAFCIJRFAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF2BB86BBAECFJREAFCFJRFAGCaJHGQBMMABMoFFGaGXGXABCEZ9FQBABRESFMAFCgFZC+BwsN9sRIGXGXAGCT9PQBABRESFMABREEXAEAIjGBAECSJAIjGBAECNJAIjGBAECIJAIjGBAECTJREAGC9wJHGCb9LQBMMAGCI9JQBEXAEAIjGBAECIJREAGC98JHGCE9LQBMMGXAG9FQBEXAEAF86BBAECFJREAGCaJHGQBMMABMMMFBCUNMIT9kBB",Yc="B9h9z9tFBBBF8dL9gBB9gLaaaaaFa9gEaaaB9gGaaB9gFaFaEQSBBFBFFGEGEGIILF9wFFFLEFBFKNFaFCx/aFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBG8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBIy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBKi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBNn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9F949wBcI9z9iqlBMc/j9JSIBTEM9+FLa8jUUUUBCTlRBCBRFEXCBRGCBREEXABCNJAGJAECUaAFAGrCFZHIy86BBAEAIJREAGCFJHGCN9HQBMAFCx+YUUBJAE86BBAFCEWCxkUUBJAB8pEN83EBAFCFJHFCUG9HQBMMkRIbaG97FaK978jUUUUBCU/KBlHL8kUUUUBC9+RKGXAGCFJAI9LQBCaRKAE2BBC+gF9HQBALAEAIJHOAGlAG/8cBBCUoBAG9uC/wgBZHKCUGAKCUG9JyRNAECFJRKCBRVGXEXAVAF9PQFANAFAVlAVANJAF9JyRcGXGXAG9FQBAcCbJHIC9wZHMCE9sRSAMCFWRQAICIrCEJCGrRfCBRbEXAKRTCBRtGXEXGXAOATlAf9PQBCBRKSLMALCU/CBJAtAM9sJRmATAfJRKCBREGXAMCoB9JQBAOAKlC/gB9JQBCBRIEXAmAIJREGXGXGXGXGXATAICKrJ2BBHYCEZfIBFGEBMAECBDtDMIBSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMIBAKCTJRKMGXGXGXGXGXAYCGrCEZfIBFGEBMAECBDtDMITSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMITAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMITAKCTJRKMGXGXGXGXGXAYCIrCEZfIBFGEBMAECBDtDMIASEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIAAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAEAKDBBBDMIAAKCTJRKMGXGXGXGXGXAYCKrfIBFGEBMAECBDtDMI8wSEMAEAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCIJAnDeBJAYCx+YUUBJ2BBJRKSGMAEAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBAYCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HYCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMI8wAKCNJAnDeBJAYCx+YUUBJ2BBJRKSFMAEAKDBBBDMI8wAKCTJRKMAICoBJREAICUFJAM9LQFAERIAOAKlC/fB9LQBMMGXAEAM9PQBAECErRIEXGXAOAKlCi9PQBCBRKSOMAmAEJRYGXGXGXGXGXATAECKrJ2BBAICKZrCEZfIBFGEBMAYCBDtDMIBSEMAYAKDBBIAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnHPCGD+MFAPDQBTFtGmEYIPLdKeOnC0+G+MiDtD9OHdCEDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCIJAnDeBJAeCx+YUUBJ2BBJRKSGMAYAKDBBNAKDBBBHPCID+MFAPDQBTFtGmEYIPLdKeOnC+P+e+8/4BDtD9OHdCbDbD8jHPD8dBhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBAeCx+YUUBJDBBBHnAnDQBBBBBBBBBBBBBBBBAPD8dFhUg/8/4/w/goB9+h84k7HeCEWCxkUUBJDBEBD9uDQBFGEILKOTtmYPdenDfAdAPD9SDMIBAKCNJAnDeBJAeCx+YUUBJ2BBJRKSFMAYAKDBBBDMIBAKCTJRKMAICGJRIAECTJHEAM9JQBMMGXAK9FQBAKRTAtCFJHtCI6QGSFMMCBRKSEMGXAM9FQBALCUGJAbJREALAbJDBGBRnCBRYEXAEALCU/CBJAYJHIDBIBHdCFD9tAdCFDbHPD9OD9hD9RHdAIAMJDBIBHiCFD9tAiAPD9OD9hD9RHiDQBTFtGmEYIPLdKeOnH8ZAIAQJDBIBHpCFD9tApAPD9OD9hD9RHpAIASJDBIBHyCFD9tAyAPD9OD9hD9RHyDQBTFtGmEYIPLdKeOnH8cDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGEAnD9uHnDyBjGBAEAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnA8ZA8cDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnAdAiDQNiV8ZcpMyS8cQ8df8eb8fHdApAyDQNiV8ZcpMyS8cQ8df8eb8fHiDQBFTtGEmYILPdKOenHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJHIAnAdAiDQNVi8ZcMpySQ8c8dfb8e8fHPAPDQBFGEBFGEBFGEBFGED9uHnDyBjGBAIAGJHIAnAPAPDQILKOILKOILKOILKOD9uHnDyBjGBAIAGJHIAnAPAPDQNVcMNVcMNVcMNVcMD9uHnDyBjGBAIAGJHIAnAPAPDQSQfbSQfbSQfbSQfbD9uHnDyBjGBAIAGJREAYCTJHYAM9JQBMMAbCIJHbAG9JQBMMABAVAG9sJALCUGJAcAG9s/8cBBALALCUGJAcCaJAG9sJAG/8cBBMAcCBAKyAVJRVAKQBMC9+RKSFMCBC99AOAKlAGCAAGCA9Ly6yRKMALCU/KBJ8kUUUUBAKMNBT+BUUUBM+KmFTa8jUUUUBCoFlHL8kUUUUBC9+RKGXAFCE9uHOCtJAI9LQBCaRKAE2BBHNC/wFZC/gF9HQBANCbZHVCF9LQBALCoBJCgFCUF/8MBALC84Jha83EBALC8wJha83EBALC8oJha83EBALCAJha83EBALCiJha83EBALCTJha83EBALha83ENALha83EBAEAIJC9wJRcAECFJHNAOJRMGXAF9FQBCQCbAVCF6yRSABRECBRVCBRQCBRfCBRICBRKEXGXAMAcuQBC9+RKSEMGXGXAN2BBHOC/vF9LQBALCoBJAOCIrCa9zAKJCbZCEWJHb8oGIRTAb8oGBRtGXAOCbZHbAS9PQBALAOCa9zAIJCbZCGWJ8oGBAVAbyROAb9FRbGXGXAGCG9HQBABAt87FBABCIJAO87FBABCGJAT87FBSFMAEAtjGBAECNJAOjGBAECIJATjGBMAVAbJRVALCoBJAKCEWJHmAOjGBAmATjGIALAICGWJAOjGBALCoBJAKCFJCbZHKCEWJHTAtjGBATAOjGIAIAbJRIAKCFJRKSGMGXGXAbCb6QBAQAbJAbC989zJCFJRQSFMAM1BBHbCgFZROGXGXAbCa9MQBAMCFJRMSFMAM1BFHbCgBZCOWAOCgBZqROGXAbCa9MQBAMCGJRMSFMAM1BGHbCgBZCfWAOqROGXAbCa9MQBAMCEJRMSFMAM1BEHbCgBZCdWAOqROGXAbCa9MQBAMCIJRMSFMAM2BIC8cWAOqROAMCLJRMMAOCFrCBAOCFZl9zAQJRQMGXGXAGCG9HQBABAt87FBABCIJAQ87FBABCGJAT87FBSFMAEAtjGBAECNJAQjGBAECIJATjGBMALCoBJAKCEWJHOAQjGBAOATjGIALAICGWJAQjGBALCoBJAKCFJCbZHKCEWJHOAtjGBAOAQjGIAICFJRIAKCFJRKSFMGXAOCDF9LQBALAIAcAOCbZJ2BBHbCIrHTlCbZCGWJ8oGBAVCFJHtATyROALAIAblCbZCGWJ8oGBAtAT9FHmJHtAbCbZHTyRbAT9FRTGXGXAGCG9HQBABAV87FBABCIJAb87FBABCGJAO87FBSFMAEAVjGBAECNJAbjGBAECIJAOjGBMALAICGWJAVjGBALCoBJAKCEWJHYAOjGBAYAVjGIALAICFJHICbZCGWJAOjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAIAmJCbZHICGWJAbjGBALCoBJAKCGJCbZHKCEWJHOAVjGBAOAbjGIAKCFJRKAIATJRIAtATJRVSFMAVCBAM2BBHYyHTAOC/+F6HPJROAYCbZRtGXGXAYCIrHmQBAOCFJRbSFMAORbALAIAmlCbZCGWJ8oGBROMGXGXAtQBAbCFJRVSFMAbRVALAIAYlCbZCGWJ8oGBRbMGXGXAP9FQBAMCFJRYSFMAM1BFHYCgFZRTGXGXAYCa9MQBAMCGJRYSFMAM1BGHYCgBZCOWATCgBZqRTGXAYCa9MQBAMCEJRYSFMAM1BEHYCgBZCfWATqRTGXAYCa9MQBAMCIJRYSFMAM1BIHYCgBZCdWATqRTGXAYCa9MQBAMCLJRYSFMAMCKJRYAM2BLC8cWATqRTMATCFrCBATCFZl9zAQJHQRTMGXGXAmCb6QBAYRPSFMAY1BBHMCgFZROGXGXAMCa9MQBAYCFJRPSFMAY1BFHMCgBZCOWAOCgBZqROGXAMCa9MQBAYCGJRPSFMAY1BGHMCgBZCfWAOqROGXAMCa9MQBAYCEJRPSFMAY1BEHMCgBZCdWAOqROGXAMCa9MQBAYCIJRPSFMAYCLJRPAY2BIC8cWAOqROMAOCFrCBAOCFZl9zAQJHQROMGXGXAtCb6QBAPRMSFMAP1BBHMCgFZRbGXGXAMCa9MQBAPCFJRMSFMAP1BFHMCgBZCOWAbCgBZqRbGXAMCa9MQBAPCGJRMSFMAP1BGHMCgBZCfWAbqRbGXAMCa9MQBAPCEJRMSFMAP1BEHMCgBZCdWAbqRbGXAMCa9MQBAPCIJRMSFMAPCLJRMAP2BIC8cWAbqRbMAbCFrCBAbCFZl9zAQJHQRbMGXGXAGCG9HQBABAT87FBABCIJAb87FBABCGJAO87FBSFMAEATjGBAECNJAbjGBAECIJAOjGBMALCoBJAKCEWJHYAOjGBAYATjGIALAICGWJATjGBALCoBJAKCFJCbZCEWJHYAbjGBAYAOjGIALAICFJHICbZCGWJAOjGBALCoBJAKCGJCbZCEWJHOATjGBAOAbjGIALAIAm9FAmCb6qJHICbZCGWJAbjGBAIAt9FAtCb6qJRIAKCEJRKMANCFJRNABCKJRBAECSJREAKCbZRKAICbZRIAfCEJHfAF9JQBMMCBC99AMAc6yRKMALCoFJ8kUUUUBAKM/tIFGa8jUUUUBCTlRLC9+RKGXAFCLJAI9LQBCaRKAE2BBC/+FZC/QF9HQBALhB83ENAECFJRKAEAIJC98JREGXAF9FQBGXAGCG6QBEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMALCNJAICFZCGWqHGAICGrCBAICFrCFZl9zAG8oGBJHIjGBABAIjGBABCIJRBAFCaJHFQBSGMMEXGXAKAE9JQBC9+bMAK1BBHGCgFZRIGXGXAGCa9MQBAKCFJRKSFMAK1BFHGCgBZCOWAICgBZqRIGXAGCa9MQBAKCGJRKSFMAK1BGHGCgBZCfWAIqRIGXAGCa9MQBAKCEJRKSFMAK1BEHGCgBZCdWAIqRIGXAGCa9MQBAKCIJRKSFMAK2BIC8cWAIqRIAKCLJRKMABAICGrCBAICFrCFZl9zALCNJAICFZCGWqHI8oGBJHG87FBAIAGjGBABCGJRBAFCaJHFQBMMCBC99AKAE6yRKMAKM/xLGEaK978jUUUUBCAlHE8kUUUUBGXGXAGCI9HQBGXAFC98ZHI9FQBABRGCBRLEXAGAGDBBBHKCiD+rFCiD+sFD/6FHOAKCND+rFCiD+sFD/6FAOD/gFAKCTD+rFCiD+sFD/6FHND/gFD/kFD/lFHVCBDtD+2FHcAOCUUUU94DtHMD9OD9RD/kFHO9DBB/+hDYAOAOD/mFAVAVD/mFANAcANAMD9OD9RD/kFHOAOD/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHcD/kFCgFDtD9OAKCUUU94DtD9OD9QAOAND/mFAcD/kFCND+rFCU/+EDtD9OD9QAVAND/mFAcD/kFCTD+rFCUU/8ODtD9OD9QDMBBAGCTJRGALCIJHLAI9JQBMMAIAF9PQFAEAFCEZHLCGWHGqCBCTAGl/8MBAEABAICGWJHIAG/8cBBGXAL9FQBAEAEDBIBHKCiD+rFCiD+sFD/6FHOAKCND+rFCiD+sFD/6FAOD/gFAKCTD+rFCiD+sFD/6FHND/gFD/kFD/lFHVCBDtD+2FHcAOCUUUU94DtHMD9OD9RD/kFHO9DBB/+hDYAOAOD/mFAVAVD/mFANAcANAMD9OD9RD/kFHOAOD/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHcD/kFCgFDtD9OAKCUUU94DtD9OD9QAOAND/mFAcD/kFCND+rFCU/+EDtD9OD9QAVAND/mFAcD/kFCTD+rFCUU/8ODtD9OD9QDMIBMAIAEAG/8cBBSFMABAFC98ZHGT+HUUUBAGAF9PQBAEAFCEZHICEWHLJCBCAALl/8MBAEABAGCEWJHGAL/8cBBAEAIT+HUUUBAGAEAL/8cBBMAECAJ8kUUUUBM+yEGGaO97GXAF9FQBCBRGEXABCTJHEAEDBBBHICBDtHLCUU98D8cFCUU98D8cEHKD9OABDBBBHOAIDQILKOSQfbPden8c8d8e8fCggFDtD9OD/6FAOAIDQBFGENVcMTtmYi8ZpyHICTD+sFD/6FHND/gFAICTD+rFCTD+sFD/6FHVD/gFD/kFD/lFHI9DB/+g6DYAVAIALD+2FHLAVCUUUU94DtHcD9OD9RD/kFHVAVD/mFAIAID/mFANALANAcD9OD9RD/kFHIAID/mFD/kFD/kFD/jFD/nFHND/mF9DBBX9LDYHLD/kFCTD+rFAVAND/mFALD/kFCggEDtD9OD9QHVAIAND/mFALD/kFCaDbCBDnGCBDnECBDnKCBDnOCBDncCBDnMCBDnfCBDnbD9OHIDQNVi8ZcMpySQ8c8dfb8e8fD9QDMBBABAOAKD9OAVAIDQBFTtGEmYILPdKOenD9QDMBBABCAJRBAGCIJHGAF9JQBMMM94FEa8jUUUUBCAlHE8kUUUUBABAFC98ZHIT+JUUUBGXAIAF9PQBAEAFCEZHLCEWHFJCBCAAFl/8MBAEABAICEWJHBAF/8cBBAEALT+JUUUBABAEAF/8cBBMAECAJ8kUUUUBM/hEIGaF97FaL978jUUUUBCTlRGGXAF9FQBCBREEXAGABDBBBHIABCTJHLDBBBHKDQILKOSQfbPden8c8d8e8fHOCTD+sFHNCID+rFDMIBAB9DBBU8/DY9D/zI818/DYANCEDtD9QD/6FD/nFHNAIAKDQBFGENVcMTtmYi8ZpyHICTD+rFCTD+sFD/6FD/mFHKAKD/mFANAICTD+sFD/6FD/mFHVAVD/mFANAOCTD+rFCTD+sFD/6FD/mFHOAOD/mFD/kFD/kFD/lFCBDtD+4FD/jF9DB/+g6DYHND/mF9DBBX9LDYHID/kFCggEDtHcD9OAVAND/mFAID/kFCTD+rFD9QHVAOAND/mFAID/kFCTD+rFAKAND/mFAID/kFAcD9OD9QHNDQBFTtGEmYILPdKOenHID8dBAGDBIBDyB+t+J83EBABCNJAID8dFAGDBIBDyF+t+J83EBALAVANDQNVi8ZcMpySQ8c8dfb8e8fHND8dBAGDBIBDyG+t+J83EBABCiJAND8dFAGDBIBDyE+t+J83EBABCAJRBAECIJHEAF9JQBMMM/3FGEaF978jUUUUBCoBlREGXAGCGrAF9sHIC98ZHL9FQBCBRGABRFEXAFAFDBBBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMBBAFCTJRFAGCIJHGAL9JQBMMGXALAI9PQBAEAICEZHGCGWHFqCBCoBAFl/8MBAEABALCGWJHLAF/8cBBGXAG9FQBAEAEDBIBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMIBMALAEAF/8cBBMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEMMMFBCUNMIT9tBB",$c=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]),qc=new Uint8Array([32,0,65,253,3,1,2,34,4,106,6,5,11,8,7,20,13,33,12,16,128,9,116,64,19,113,127,15,10,21,22,14,255,66,24,54,136,107,18,23,192,26,114,118,132,17,77,101,130,144,27,87,131,44,45,74,156,154,70,167]),eh={0:"",1:"meshopt_decodeFilterOct",2:"meshopt_decodeFilterQuat",3:"meshopt_decodeFilterExp",NONE:"",OCTAHEDRAL:"meshopt_decodeFilterOct",QUATERNION:"meshopt_decodeFilterQuat",EXPONENTIAL:"meshopt_decodeFilterExp"},th={0:"meshopt_decodeVertexBuffer",1:"meshopt_decodeIndexBuffer",2:"meshopt_decodeIndexSequence",ATTRIBUTES:"meshopt_decodeVertexBuffer",TRIANGLES:"meshopt_decodeIndexBuffer",INDICES:"meshopt_decodeIndexSequence"};async function sh(e,t,s,i,r,n="NONE"){const A=await async function(){ih||(ih=async function(){let e=Jc;WebAssembly.validate($c)&&(e=Yc,console.log("Warning: meshopt_decoder is using experimental SIMD support"));const t=await WebAssembly.instantiate(function(e){const t=new Uint8Array(e.length);for(let s=0;s<e.length;++s){const i=e.charCodeAt(s);t[s]=i>96?i-71:i>64?i-65:i>47?i+4:i>46?63:62}let s=0;for(let i=0;i<e.length;++i)t[s++]=t[i]<60?qc[t[i]]:64*(t[i]-60)+t[++i];return t.buffer.slice(0,s)}(e),{});return await t.instance.exports.__wasm_call_ctors(),t.instance}());return ih}();!function(e,t,s,i,r,n,A){const o=e.exports.sbrk,a=i+3&-4,l=o(a*r),c=o(n.length),h=new Uint8Array(e.exports.memory.buffer);h.set(n,c);const u=t(l,i,r,c,n.length);0===u&&A&&A(l,a,r);if(s.set(h.subarray(l,l+i*r)),o(l-o(0)),0!==u)throw new Error(`Malformed buffer data: ${u}`)}(A,A.exports[th[r]],e,t,s,i,A.exports[eh[n||"NONE"]])}let ih;async function rh(e,t){const s=e.getObjectExtension(t,"EXT_meshopt_compression");if(s){const{byteOffset:i=0,byteLength:r=0,byteStride:n,count:A,mode:o,filter:a="NONE",buffer:l}=s,c=e.gltf.buffers[l],h=new Uint8Array(c.arrayBuffer,c.byteOffset+i,r),u=new Uint8Array(e.gltf.buffers[t.buffer].arrayBuffer,t.byteOffset,t.byteLength);await sh(u,A,n,h,o,a),e.removeObjectExtension(t,"EXT_meshopt_compression")}}var nh=Object.freeze({__proto__:null,name:"EXT_meshopt_compression",decode:async function(e,t){const s=new Hl(e);if(!t?.gltf?.decompressMeshes||!t.gltf?.loadBuffers)return;const i=[];for(const t of e.json.bufferViews||[])i.push(rh(s,t));await Promise.all(i),s.removeExtension("EXT_meshopt_compression")}});var Ah=Object.freeze({__proto__:null,name:"EXT_texture_webp",preprocess:function(e,t){const s=new Hl(e);if(!xl("image/webp")){if(s.getRequiredExtensions().includes("EXT_texture_webp"))throw new Error("gltf: Required extension EXT_texture_webp not supported by browser");return}const{json:i}=s;for(const e of i.textures||[]){const t=s.getObjectExtension(e,"EXT_texture_webp");t&&(e.source=t.source),s.removeObjectExtension(e,"EXT_texture_webp")}s.removeExtension("EXT_texture_webp")}});var oh=Object.freeze({__proto__:null,name:"KHR_texture_basisu",preprocess:function(e,t){const s=new Hl(e),{json:i}=s;for(const e of i.textures||[]){const t=s.getObjectExtension(e,"KHR_texture_basisu");t&&(e.source=t.source,s.removeObjectExtension(e,"KHR_texture_basisu"))}s.removeExtension("KHR_texture_basisu")}});const ah={dataType:null,batchType:null,name:"Draco",id:"draco",module:"draco",version:"4.3.3",worker:!0,extensions:["drc"],mimeTypes:["application/octet-stream"],binary:!0,tests:["DRACO"],options:{draco:{decoderType:"object"==typeof WebAssembly?"wasm":"js",libraryPath:"libs/",extraAttributes:{},attributeNameEntry:void 0}}};function lh(e,t,s){return ol(e,t,s?ch(s.metadata):void 0)}function ch(e){const t={};for(const s in e)t[`${s}.string`]=JSON.stringify(e[s]);return t}const hh={POSITION:"POSITION",NORMAL:"NORMAL",COLOR:"COLOR_0",TEX_COORD:"TEXCOORD_0"},uh={1:Int8Array,2:Uint8Array,3:Int16Array,4:Uint16Array,5:Int32Array,6:Uint32Array,9:Float32Array};class dh{draco;decoder;metadataQuerier;constructor(e){this.draco=e,this.decoder=new this.draco.Decoder,this.metadataQuerier=new this.draco.MetadataQuerier}destroy(){this.draco.destroy(this.decoder),this.draco.destroy(this.metadataQuerier)}parseSync(e,t={}){const s=new this.draco.DecoderBuffer;s.Init(new Int8Array(e),e.byteLength),this._disableAttributeTransforms(t);const i=this.decoder.GetEncodedGeometryType(s),r=i===this.draco.TRIANGULAR_MESH?new this.draco.Mesh:new this.draco.PointCloud;try{let e;switch(i){case this.draco.TRIANGULAR_MESH:e=this.decoder.DecodeBufferToMesh(s,r);break;case this.draco.POINT_CLOUD:e=this.decoder.DecodeBufferToPointCloud(s,r);break;default:throw new Error("DRACO: Unknown geometry type.")}if(!e.ok()||!r.ptr){const t=`DRACO decompression failed: ${e.error_msg()}`;throw new Error(t)}const n=this._getDracoLoaderData(r,i,t),A=this._getMeshData(r,n,t),o=nl(A.attributes),a=function(e,t,s){const i=ch(t.metadata),r=[],n=function(e){const t={};for(const s in e){const i=e[s];t[i.name||"undefined"]=i}return t}(t.attributes);for(const t in e){const s=lh(t,e[t],n[t]);r.push(s)}if(s){const e=lh("indices",s);r.push(e)}return{fields:r,metadata:i}}(A.attributes,n,A.indices);return{loader:"draco",loaderData:n,header:{vertexCount:r.num_points(),boundingBox:o},...A,schema:a}}finally{this.draco.destroy(s),r&&this.draco.destroy(r)}}_getDracoLoaderData(e,t,s){const i=this._getTopLevelMetadata(e),r=this._getDracoAttributes(e,s);return{geometry_type:t,num_attributes:e.num_attributes(),num_points:e.num_points(),num_faces:e instanceof this.draco.Mesh?e.num_faces():0,metadata:i,attributes:r}}_getDracoAttributes(e,t){const s={};for(let i=0;i<e.num_attributes();i++){const r=this.decoder.GetAttribute(e,i),n=this._getAttributeMetadata(e,i);s[r.unique_id()]={unique_id:r.unique_id(),attribute_type:r.attribute_type(),data_type:r.data_type(),num_components:r.num_components(),byte_offset:r.byte_offset(),byte_stride:r.byte_stride(),normalized:r.normalized(),attribute_index:i,metadata:n};const A=this._getQuantizationTransform(r,t);A&&(s[r.unique_id()].quantization_transform=A);const o=this._getOctahedronTransform(r,t);o&&(s[r.unique_id()].octahedron_transform=o)}return s}_getMeshData(e,t,s){const i=this._getMeshAttributes(t,e,s);if(!i.POSITION)throw new Error("DRACO: No position attribute found.");return e instanceof this.draco.Mesh?"triangle-strip"===s.topology?{topology:"triangle-strip",mode:4,attributes:i,indices:{value:this._getTriangleStripIndices(e),size:1}}:{topology:"triangle-list",mode:5,attributes:i,indices:{value:this._getTriangleListIndices(e),size:1}}:{topology:"point-list",mode:0,attributes:i}}_getMeshAttributes(e,t,s){const i={};for(const r of Object.values(e.attributes)){const e=this._deduceAttributeName(r,s);r.name=e;const n=this._getAttributeValues(t,r);if(n){const{value:t,size:s}=n;i[e]={value:t,size:s,byteOffset:r.byte_offset,byteStride:r.byte_stride,normalized:r.normalized}}}return i}_getTriangleListIndices(e){const t=3*e.num_faces(),s=4*t,i=this.draco._malloc(s);try{return this.decoder.GetTrianglesUInt32Array(e,s,i),new Uint32Array(this.draco.HEAPF32.buffer,i,t).slice()}finally{this.draco._free(i)}}_getTriangleStripIndices(e){const t=new this.draco.DracoInt32Array;try{return this.decoder.GetTriangleStripsFromMesh(e,t),function(e){const t=e.size(),s=new Int32Array(t);for(let i=0;i<t;i++)s[i]=e.GetValue(i);return s}(t)}finally{this.draco.destroy(t)}}_getAttributeValues(e,t){const s=uh[t.data_type];if(!s)return console.warn(`DRACO: Unsupported attribute type ${t.data_type}`),null;const i=t.num_components,r=e.num_points()*i,n=r*s.BYTES_PER_ELEMENT,A=function(e,t){switch(t){case Float32Array:return e.DT_FLOAT32;case Int8Array:return e.DT_INT8;case Int16Array:return e.DT_INT16;case Int32Array:return e.DT_INT32;case Uint8Array:return e.DT_UINT8;case Uint16Array:return e.DT_UINT16;case Uint32Array:return e.DT_UINT32;default:return e.DT_INVALID}}(this.draco,s);let o;const a=this.draco._malloc(n);try{const i=this.decoder.GetAttribute(e,t.attribute_index);this.decoder.GetAttributeDataArrayForAllPoints(e,i,A,n,a),o=new s(this.draco.HEAPF32.buffer,a,r).slice()}finally{this.draco._free(a)}return{value:o,size:i}}_deduceAttributeName(e,t){const s=e.unique_id;for(const[e,i]of Object.entries(t.extraAttributes||{}))if(i===s)return e;const i=e.attribute_type;for(const e in hh){if(this.draco[e]===i)return hh[e]}const r=t.attributeNameEntry||"name";return e.metadata[r]?e.metadata[r].string:`CUSTOM_ATTRIBUTE_${s}`}_getTopLevelMetadata(e){const t=this.decoder.GetMetadata(e);return this._getDracoMetadata(t)}_getAttributeMetadata(e,t){const s=this.decoder.GetAttributeMetadata(e,t);return this._getDracoMetadata(s)}_getDracoMetadata(e){if(!e||!e.ptr)return{};const t={},s=this.metadataQuerier.NumEntries(e);for(let i=0;i<s;i++){const s=this.metadataQuerier.GetEntryName(e,i);t[s]=this._getDracoMetadataField(e,s)}return t}_getDracoMetadataField(e,t){const s=new this.draco.DracoInt32Array;try{this.metadataQuerier.GetIntEntryArray(e,t,s);const i=function(e){const t=e.size(),s=new Int32Array(t);for(let i=0;i<t;i++)s[i]=e.GetValue(i);return s}(s);return{int:this.metadataQuerier.GetIntEntry(e,t),string:this.metadataQuerier.GetStringEntry(e,t),double:this.metadataQuerier.GetDoubleEntry(e,t),intArray:i}}finally{this.draco.destroy(s)}}_disableAttributeTransforms(e){const{quantizedAttributes:t=[],octahedronAttributes:s=[]}=e,i=[...t,...s];for(const e of i)this.decoder.SkipAttributeTransform(this.draco[e])}_getQuantizationTransform(e,t){const{quantizedAttributes:s=[]}=t,i=e.attribute_type();if(s.map((e=>this.decoder[e])).includes(i)){const t=new this.draco.AttributeQuantizationTransform;try{if(t.InitFromAttribute(e))return{quantization_bits:t.quantization_bits(),range:t.range(),min_values:new Float32Array([1,2,3]).map((e=>t.min_value(e)))}}finally{this.draco.destroy(t)}}return null}_getOctahedronTransform(e,t){const{octahedronAttributes:s=[]}=t,i=e.attribute_type();if(s.map((e=>this.decoder[e])).includes(i)){const t=new this.draco.AttributeQuantizationTransform;try{if(t.InitFromAttribute(e))return{quantization_bits:t.quantization_bits()}}finally{this.draco.destroy(t)}}return null}}const ph="https://www.gstatic.com/draco/versioned/decoders/1.5.6",fh="draco_wasm_wrapper.js",gh="draco_decoder.wasm",mh="draco_decoder.js",_h="draco_encoder.js",bh={[fh]:`${ph}/${fh}`,[gh]:`${ph}/${gh}`,[mh]:`${ph}/${mh}`,[_h]:`https://raw.githubusercontent.com/google/draco/1.4.1/javascript/${_h}`};let yh;async function Bh(e){const t=e.modules||{};return t.draco3d?yh||=t.draco3d.createDecoderModule({}).then((e=>({draco:e}))):yh||=async function(e){let t,s;if("js"===(e.draco&&e.draco.decoderType))t=await qo(bh[mh],"draco",e,mh);else[t,s]=await Promise.all([await qo(bh[fh],"draco",e,fh),await qo(bh[gh],"draco",e,gh)]);return t=t||globalThis.DracoDecoderModule,await function(e,t){const s={};t&&(s.wasmBinary=t);return new Promise((t=>{e({...s,onModuleLoaded:e=>t({draco:e})})}))}(t,s)}(e),await yh}const wh={...ah,parse:async function(e,t){const{draco:s}=await Bh(t),i=new dh(s);try{return i.parseSync(e,t?.draco)}finally{i.destroy()}}};function vh(e){const{buffer:t,size:s,count:i}=function(e){let t=e,s=1,i=0;e&&e.value&&(t=e.value,s=e.size||1);t&&(ArrayBuffer.isView(t)||(t=function(e,t,s=!1){if(!e)return null;if(Array.isArray(e))return new t(e);if(s&&!(e instanceof t))return new t(e);return e}(t,Float32Array)),i=t.length/s);return{buffer:t,size:s,count:i}}(e);return{value:t,size:s,byteOffset:0,count:i,type:Ol(s),componentType:Vl(t)}}async function Ch(e,t,s,i){const r=e.getObjectExtension(t,"KHR_draco_mesh_compression");if(!r)return;const n=e.getTypedArrayForBufferView(r.bufferView),A=na(n.buffer,n.byteOffset),o={...s};delete o["3d-tiles"];const a=await ao(A,wh,o,i),l=function(e){const t={};for(const s in e){const i=e[s];if("indices"!==s){const e=vh(i);t[s]=e}}return t}(a.attributes);for(const[s,i]of Object.entries(l))if(s in t.attributes){const r=t.attributes[s],n=e.getAccessor(r);n?.min&&n?.max&&(i.min=n.min,i.max=n.max)}t.attributes=l,a.indices&&(t.indices=vh(a.indices)),e.removeObjectExtension(t,"KHR_draco_mesh_compression"),function(e){if(!e.attributes&&Object.keys(e.attributes).length>0)throw new Error("glTF: Empty primitive detected: Draco decompression failure?")}(t)}function Mh(e,t,s=4,i,r){if(!i.DracoWriter)throw new Error("options.gltf.DracoWriter not provided");const n=i.DracoWriter.encodeSync({attributes:e}),A=r?.parseSync?.({attributes:e}),o=i._addFauxAttributes(A.attributes);return{primitives:[{attributes:o,mode:s,extensions:{KHR_draco_mesh_compression:{bufferView:i.addBufferView(n),attributes:o}}}]}}function*Eh(e){for(const t of e.json.meshes||[])for(const e of t.primitives)yield e}var Fh=Object.freeze({__proto__:null,name:"KHR_draco_mesh_compression",preprocess:function(e,t,s){const i=new Hl(e);for(const e of Eh(i))i.getObjectExtension(e,"KHR_draco_mesh_compression")},decode:async function(e,t,s){if(!t?.gltf?.decompressMeshes)return;const i=new Hl(e),r=[];for(const e of Eh(i))i.getObjectExtension(e,"KHR_draco_mesh_compression")&&r.push(Ch(i,e,t,s));await Promise.all(r),i.removeExtension("KHR_draco_mesh_compression")},encode:function(e,t={}){const s=new Hl(e);for(const e of s.json.meshes||[])Mh(e),s.addRequiredExtension("KHR_draco_mesh_compression")}});globalThis.mathgl=globalThis.mathgl||{config:{EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1}};const xh=globalThis.mathgl.config;function Uh(e,{precision:t=xh.precision}={}){return e=function(e){return Math.round(e/xh.EPSILON)*xh.EPSILON}(e),`${parseFloat(e.toPrecision(t))}`}function Ih(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Th(e,t,s){const i=xh.EPSILON;s&&(xh.EPSILON=s);try{if(e===t)return!0;if(Ih(e)&&Ih(t)){if(e.length!==t.length)return!1;for(let s=0;s<e.length;++s)if(!Th(e[s],t[s]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):"number"==typeof e&&"number"==typeof t&&Math.abs(e-t)<=xh.EPSILON*Math.max(1,Math.abs(e),Math.abs(t))}finally{xh.EPSILON=i}}class Ph extends Array{clone(){return(new this.constructor).copy(this)}fromArray(e,t=0){for(let s=0;s<this.ELEMENTS;++s)this[s]=e[s+t];return this.check()}toArray(e=[],t=0){for(let s=0;s<this.ELEMENTS;++s)e[t+s]=this[s];return e}toObject(e){return e}from(e){return Array.isArray(e)?this.copy(e):this.fromObject(e)}to(e){return e===this?this:Ih(e)?this.toArray(e):this.toObject(e)}toTarget(e){return e?this.to(e):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(xh)}formatString(e){let t="";for(let s=0;s<this.ELEMENTS;++s)t+=(s>0?", ":"")+Uh(this[s],e);return`${e.printTypes?this.constructor.name:""}[${t}]`}equals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(!Th(this[t],e[t]))return!1;return!0}exactEquals(e){if(!e||this.length!==e.length)return!1;for(let t=0;t<this.ELEMENTS;++t)if(this[t]!==e[t])return!1;return!0}negate(){for(let e=0;e<this.ELEMENTS;++e)this[e]=-this[e];return this.check()}lerp(e,t,s){if(void 0===s)return this.lerp(this,e,t);for(let i=0;i<this.ELEMENTS;++i){const r=e[i],n="number"==typeof t?t:t[i];this[i]=r+s*(n-r)}return this.check()}min(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.min(e[t],this[t]);return this.check()}max(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=Math.max(e[t],this[t]);return this.check()}clamp(e,t){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],e[s]),t[s]);return this.check()}add(...e){for(const t of e)for(let e=0;e<this.ELEMENTS;++e)this[e]+=t[e];return this.check()}subtract(...e){for(const t of e)for(let e=0;e<this.ELEMENTS;++e)this[e]-=t[e];return this.check()}scale(e){if("number"==typeof e)for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;else for(let t=0;t<this.ELEMENTS&&t<e.length;++t)this[t]*=e[t];return this.check()}multiplyByScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}check(){if(xh.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let e=this.length===this.ELEMENTS;for(let t=0;t<this.ELEMENTS;++t)e=e&&Number.isFinite(this[t]);return e}sub(e){return this.subtract(e)}setScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]=e;return this.check()}addScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]+=e;return this.check()}subScalar(e){return this.addScalar(-e)}multiplyScalar(e){for(let t=0;t<this.ELEMENTS;++t)this[t]*=e;return this.check()}divideScalar(e){return this.multiplyByScalar(1/e)}clampScalar(e,t){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],e),t);return this.check()}get elements(){return this}}function Sh(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function Dh(e,t,s=""){if(xh.debug&&!function(e,t){if(e.length!==t)return!1;for(let t=0;t<e.length;++t)if(!Number.isFinite(e[t]))return!1;return!0}(e,t))throw new Error(`math.gl: ${s} some fields set to invalid numbers'`);return e}function kh(e,t){if(!e)throw new Error(`math.gl assertion ${t}`)}class Qh extends Ph{get x(){return this[0]}set x(e){this[0]=Sh(e)}get y(){return this[1]}set y(e){this[1]=Sh(e)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let e=0;for(let t=0;t<this.ELEMENTS;++t)e+=this[t]*this[t];return e}magnitudeSquared(){return this.lengthSquared()}distance(e){return Math.sqrt(this.distanceSquared(e))}distanceSquared(e){let t=0;for(let s=0;s<this.ELEMENTS;++s){const i=this[s]-e[s];t+=i*i}return Sh(t)}dot(e){let t=0;for(let s=0;s<this.ELEMENTS;++s)t+=this[s]*e[s];return Sh(t)}normalize(){const e=this.magnitude();if(0!==e)for(let t=0;t<this.ELEMENTS;++t)this[t]/=e;return this.check()}multiply(...e){for(const t of e)for(let e=0;e<this.ELEMENTS;++e)this[e]*=t[e];return this.check()}divide(...e){for(const t of e)for(let e=0;e<this.ELEMENTS;++e)this[e]/=t[e];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(e){return this.distance(e)}distanceToSquared(e){return this.distanceSquared(e)}getComponent(e){return kh(e>=0&&e<this.ELEMENTS,"index is out of range"),Sh(this[e])}setComponent(e,t){return kh(e>=0&&e<this.ELEMENTS,"index is out of range"),this[e]=t,this.check()}addVectors(e,t){return this.copy(e).add(t)}subVectors(e,t){return this.copy(e).subtract(t)}multiplyVectors(e,t){return this.copy(e).multiply(t)}addScaledVector(e,t){return this.add(new this.constructor(e).multiplyScalar(t))}}let Rh="undefined"!=typeof Float32Array?Float32Array:Array;function Oh(e,t,s){const i=t[0],r=t[1],n=t[2];return e[0]=i*s[0]+r*s[3]+n*s[6],e[1]=i*s[1]+r*s[4]+n*s[7],e[2]=i*s[2]+r*s[5]+n*s[8],e}!function(){const e=function(){const e=new Rh(2);return Rh!=Float32Array&&(e[0]=0,e[1]=0),e}()}(),function(){const e=function(){const e=new Rh(3);return Rh!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}()}();const Vh=[0,0,0];let Lh;class Hh extends Qh{static get ZERO(){return Lh||(Lh=new Hh(0,0,0),Object.freeze(Lh)),Lh}constructor(e=0,t=0,s=0){super(-0,-0,-0),1===arguments.length&&Ih(e)?this.copy(e):(xh.debug&&(Sh(e),Sh(t),Sh(s)),this[0]=e,this[1]=t,this[2]=s)}set(e,t,s){return this[0]=e,this[1]=t,this[2]=s,this.check()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this.check()}fromObject(e){return xh.debug&&(Sh(e.x),Sh(e.y),Sh(e.z)),this[0]=e.x,this[1]=e.y,this[2]=e.z,this.check()}toObject(e){return e.x=this[0],e.y=this[1],e.z=this[2],e}get ELEMENTS(){return 3}get z(){return this[2]}set z(e){this[2]=Sh(e)}angle(e){return function(e,t){const s=e[0],i=e[1],r=e[2],n=t[0],A=t[1],o=t[2],a=Math.sqrt((s*s+i*i+r*r)*(n*n+A*A+o*o)),l=a&&function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}(e,t)/a;return Math.acos(Math.min(Math.max(l,-1),1))}(this,e)}cross(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2],A=s[0],o=s[1],a=s[2];e[0]=r*a-n*o,e[1]=n*A-i*a,e[2]=i*o-r*A}(this,this,e),this.check()}rotateX({radians:e,origin:t=Vh}){return function(e,t,s,i){const r=[],n=[];r[0]=t[0]-s[0],r[1]=t[1]-s[1],r[2]=t[2]-s[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),e[0]=n[0]+s[0],e[1]=n[1]+s[1],e[2]=n[2]+s[2]}(this,this,t,e),this.check()}rotateY({radians:e,origin:t=Vh}){return function(e,t,s,i){const r=[],n=[];r[0]=t[0]-s[0],r[1]=t[1]-s[1],r[2]=t[2]-s[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),e[0]=n[0]+s[0],e[1]=n[1]+s[1],e[2]=n[2]+s[2]}(this,this,t,e),this.check()}rotateZ({radians:e,origin:t=Vh}){return function(e,t,s,i){const r=[],n=[];r[0]=t[0]-s[0],r[1]=t[1]-s[1],r[2]=t[2]-s[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],e[0]=n[0]+s[0],e[1]=n[1]+s[1],e[2]=n[2]+s[2]}(this,this,t,e),this.check()}transform(e){return this.transformAsPoint(e)}transformAsPoint(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2];let A=s[3]*i+s[7]*r+s[11]*n+s[15];A=A||1,e[0]=(s[0]*i+s[4]*r+s[8]*n+s[12])/A,e[1]=(s[1]*i+s[5]*r+s[9]*n+s[13])/A,e[2]=(s[2]*i+s[6]*r+s[10]*n+s[14])/A}(this,this,e),this.check()}transformAsVector(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2],A=s[3]*i+s[7]*r+s[11]*n||1;e[0]=(s[0]*i+s[4]*r+s[8]*n)/A,e[1]=(s[1]*i+s[5]*r+s[9]*n)/A,e[2]=(s[2]*i+s[6]*r+s[10]*n)/A}(this,this,e),this.check()}transformByMatrix3(e){return Oh(this,this,e),this.check()}transformByMatrix2(e){return function(e,t,s){const i=t[0],r=t[1];e[0]=s[0]*i+s[2]*r,e[1]=s[1]*i+s[3]*r,e[2]=t[2]}(this,this,e),this.check()}transformByQuaternion(e){return function(e,t,s){const i=s[0],r=s[1],n=s[2],A=s[3],o=t[0],a=t[1],l=t[2];let c=r*l-n*a,h=n*o-i*l,u=i*a-r*o,d=r*u-n*h,p=n*c-i*u,f=i*h-r*c;const g=2*A;c*=g,h*=g,u*=g,d*=2,p*=2,f*=2,e[0]=o+c+d,e[1]=a+h+p,e[2]=l+u+f}(this,this,e),this.check()}}class Nh extends Ph{toString(){let e="[";if(xh.printRowMajor){e+="row-major:";for(let t=0;t<this.RANK;++t)for(let s=0;s<this.RANK;++s)e+=` ${this[s*this.RANK+t]}`}else{e+="column-major:";for(let t=0;t<this.ELEMENTS;++t)e+=` ${this[t]}`}return e+="]",e}getElementIndex(e,t){return t*this.RANK+e}getElement(e,t){return this[t*this.RANK+e]}setElement(e,t,s){return this[t*this.RANK+e]=Sh(s),this}getColumn(e,t=new Array(this.RANK).fill(-0)){const s=e*this.RANK;for(let e=0;e<this.RANK;++e)t[e]=this[s+e];return t}setColumn(e,t){const s=e*this.RANK;for(let e=0;e<this.RANK;++e)this[s+e]=t[e];return this}}function Gh(e,t,s){const i=t[0],r=t[1],n=t[2],A=t[3],o=t[4],a=t[5],l=t[6],c=t[7],h=t[8],u=s[0],d=s[1],p=s[2],f=s[3],g=s[4],m=s[5],_=s[6],b=s[7],y=s[8];return e[0]=u*i+d*A+p*l,e[1]=u*r+d*o+p*c,e[2]=u*n+d*a+p*h,e[3]=f*i+g*A+m*l,e[4]=f*r+g*o+m*c,e[5]=f*n+g*a+m*h,e[6]=_*i+b*A+y*l,e[7]=_*r+b*o+y*c,e[8]=_*n+b*a+y*h,e}function jh(e,t,s){const i=s[0],r=s[1];return e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=r*t[3],e[4]=r*t[4],e[5]=r*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}var zh;!function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL1ROW0=3]="COL1ROW0",e[e.COL1ROW1=4]="COL1ROW1",e[e.COL1ROW2=5]="COL1ROW2",e[e.COL2ROW0=6]="COL2ROW0",e[e.COL2ROW1=7]="COL2ROW1",e[e.COL2ROW2=8]="COL2ROW2"}(zh||(zh={}));const Wh=Object.freeze([1,0,0,0,1,0,0,0,1]);class Xh extends Nh{static get IDENTITY(){return function(){Zh||(Zh=new Xh,Object.freeze(Zh));return Zh}()}static get ZERO(){return function(){Kh||(Kh=new Xh([0,0,0,0,0,0,0,0,0]),Object.freeze(Kh));return Kh}()}get ELEMENTS(){return 9}get RANK(){return 3}get INDICES(){return zh}constructor(e,...t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0),1===arguments.length&&Array.isArray(e)?this.copy(e):t.length>0?this.copy([e,...t]):this.identity()}copy(e){return this[0]=e[0],this[1]=e[1],this[2]=e[2],this[3]=e[3],this[4]=e[4],this[5]=e[5],this[6]=e[6],this[7]=e[7],this[8]=e[8],this.check()}identity(){return this.copy(Wh)}fromObject(e){return this.check()}fromQuaternion(e){return function(e,t){const s=t[0],i=t[1],r=t[2],n=t[3],A=s+s,o=i+i,a=r+r,l=s*A,c=i*A,h=i*o,u=r*A,d=r*o,p=r*a,f=n*A,g=n*o,m=n*a;e[0]=1-h-p,e[3]=c-m,e[6]=u+g,e[1]=c+m,e[4]=1-l-p,e[7]=d-f,e[2]=u-g,e[5]=d+f,e[8]=1-l-h}(this,e),this.check()}set(e,t,s,i,r,n,A,o,a){return this[0]=e,this[1]=t,this[2]=s,this[3]=i,this[4]=r,this[5]=n,this[6]=A,this[7]=o,this[8]=a,this.check()}setRowMajor(e,t,s,i,r,n,A,o,a){return this[0]=e,this[1]=i,this[2]=A,this[3]=t,this[4]=r,this[5]=o,this[6]=s,this[7]=n,this[8]=a,this.check()}determinant(){return function(e){const t=e[0],s=e[1],i=e[2],r=e[3],n=e[4],A=e[5],o=e[6],a=e[7],l=e[8];return t*(l*n-A*a)+s*(-l*r+A*o)+i*(a*r-n*o)}(this)}transpose(){return function(e,t){if(e===t){const s=t[1],i=t[2],r=t[5];e[1]=t[3],e[2]=t[6],e[3]=s,e[5]=t[7],e[6]=i,e[7]=r}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8]}(this,this),this.check()}invert(){return function(e,t){const s=t[0],i=t[1],r=t[2],n=t[3],A=t[4],o=t[5],a=t[6],l=t[7],c=t[8],h=c*A-o*l,u=-c*n+o*a,d=l*n-A*a;let p=s*h+i*u+r*d;p&&(p=1/p,e[0]=h*p,e[1]=(-c*i+r*l)*p,e[2]=(o*i-r*A)*p,e[3]=u*p,e[4]=(c*s-r*a)*p,e[5]=(-o*s+r*n)*p,e[6]=d*p,e[7]=(-l*s+i*a)*p,e[8]=(A*s-i*n)*p)}(this,this),this.check()}multiplyLeft(e){return Gh(this,e,this),this.check()}multiplyRight(e){return Gh(this,this,e),this.check()}rotate(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2],A=t[3],o=t[4],a=t[5],l=t[6],c=t[7],h=t[8],u=Math.sin(s),d=Math.cos(s);e[0]=d*i+u*A,e[1]=d*r+u*o,e[2]=d*n+u*a,e[3]=d*A-u*i,e[4]=d*o-u*r,e[5]=d*a-u*n,e[6]=l,e[7]=c,e[8]=h}(this,this,e),this.check()}scale(e){return Array.isArray(e)?jh(this,this,e):jh(this,this,[e,e]),this.check()}translate(e){return function(e,t,s){const i=t[0],r=t[1],n=t[2],A=t[3],o=t[4],a=t[5],l=t[6],c=t[7],h=t[8],u=s[0],d=s[1];e[0]=i,e[1]=r,e[2]=n,e[3]=A,e[4]=o,e[5]=a,e[6]=u*i+d*A+l,e[7]=u*r+d*o+c,e[8]=u*n+d*a+h}(this,this,e),this.check()}transform(e,t){let s;switch(e.length){case 2:s=function(e,t,s){const i=t[0],r=t[1];return e[0]=s[0]*i+s[3]*r+s[6],e[1]=s[1]*i+s[4]*r+s[7],e}(t||[-0,-0],e,this);break;case 3:s=Oh(t||[-0,-0,-0],e,this);break;case 4:s=function(e,t,s){const i=t[0],r=t[1],n=t[2];return e[0]=s[0]*i+s[3]*r+s[6]*n,e[1]=s[1]*i+s[4]*r+s[7]*n,e[2]=s[2]*i+s[5]*r+s[8]*n,e[3]=t[3],e}(t||[-0,-0,-0,-0],e,this);break;default:throw new Error("Illegal vector")}return Dh(s,e.length),s}transformVector(e,t){return this.transform(e,t)}transformVector2(e,t){return this.transform(e,t)}transformVector3(e,t){return this.transform(e,t)}}let Kh,Zh=null;const Jh=new Hh,Yh=new Xh,$h=new Xh;function qh(e,t){const s=t.json.materials?.[e],i=[s?.pbrMetallicRoughness?.baseColorTexture,s?.emissiveTexture,s?.normalTexture,s?.occlusionTexture,s?.pbrMetallicRoughness?.metallicRoughnessTexture],r=[];for(const s of i)s&&s?.extensions?.KHR_texture_transform&&eu(t,e,s,r)}function eu(e,t,s,i){const r=function(e,t){const s=e.extensions?.KHR_texture_transform,{texCoord:i=0}=e,{texCoord:r=i}=s;if(-1===t.findIndex((([e,t])=>e===i&&t===r))){const n=function(e){const{offset:t=[0,0],rotation:s=0,scale:i=[1,1]}=e,r=(new Xh).set(1,0,0,0,1,0,t[0],t[1],1),n=Yh.set(Math.cos(s),Math.sin(s),0,-Math.sin(s),Math.cos(s),0,0,0,1),A=$h.set(i[0],0,0,0,i[1],0,0,0,1);return r.multiplyRight(n).multiplyRight(A)}(s);return i!==r&&(e.texCoord=r),t.push([i,r]),{originalTexCoord:i,texCoord:r,matrix:n}}return null}(s,i);if(!r)return;const n=e.json.meshes||[];for(const s of n)for(const i of s.primitives){const s=i.material;Number.isFinite(s)&&t===s&&tu(e,i,r)}}function tu(e,t,s){const{originalTexCoord:i,texCoord:r,matrix:n}=s,A=t.attributes[`TEXCOORD_${i}`];if(Number.isFinite(A)){const s=e.json.accessors?.[A];if(s&&s.bufferView){const A=e.json.bufferViews?.[s.bufferView];if(A){const{arrayBuffer:o,byteOffset:a}=e.buffers[A.buffer],l=(a||0)+(s.byteOffset||0)+(A.byteOffset||0),{ArrayType:c,length:h}=Ll(s,A),u=Tl[s.componentType],d=Il[s.type],p=A.byteStride||u*d,f=new Float32Array(h);for(let e=0;e<s.count;e++){const t=new c(o,l+e*p,2);Jh.set(t[0],t[1],1),Jh.transformByMatrix3(n),f.set([Jh[0],Jh[1]],e*d)}i===r?function(e,t,s,i){e.componentType=5126,s.push({arrayBuffer:i.buffer,byteOffset:0,byteLength:i.buffer.byteLength}),t.buffer=s.length-1,t.byteLength=i.buffer.byteLength,t.byteOffset=0,delete t.byteStride}(s,A,e.buffers,f):function(e,t,s,i,r){i.buffers.push({arrayBuffer:r.buffer,byteOffset:0,byteLength:r.buffer.byteLength});const n=i.json.bufferViews;if(!n)return;n.push({buffer:i.buffers.length-1,byteLength:r.buffer.byteLength,byteOffset:0});const A=i.json.accessors;if(!A)return;A.push({bufferView:n?.length-1,byteOffset:0,componentType:5126,count:t.count,type:"VEC2"}),s.attributes[`TEXCOORD_${e}`]=A.length-1}(r,s,t,e,f)}}}}var su=Object.freeze({__proto__:null,name:"KHR_texture_transform",decode:async function(e,t){if(!new Hl(e).hasExtension("KHR_texture_transform")||!t.gltf?.loadBuffers)return;const s=e.json.materials||[];for(let t=0;t<s.length;t++)qh(t,e)}});function iu(e,t){const s=Object.assign({},e.values);return Object.keys(e.uniforms||{}).forEach((t=>{e.uniforms[t].value&&!(t in s)&&(s[t]=e.uniforms[t].value)})),Object.keys(s).forEach((e=>{"object"==typeof s[e]&&void 0!==s[e].index&&(s[e].texture=t.getTexture(s[e].index))})),s}const ru=[fc,ic,nh,Ah,oh,Fh,Object.freeze({__proto__:null,name:"KHR_lights_punctual",decode:async function(e){const t=new Hl(e),{json:s}=t,i=t.getExtension("KHR_lights_punctual");i&&(t.json.lights=i.lights,t.removeExtension("KHR_lights_punctual"));for(const e of s.nodes||[]){const s=t.getObjectExtension(e,"KHR_lights_punctual");s&&(e.light=s.light),t.removeObjectExtension(e,"KHR_lights_punctual")}},encode:async function(e){const t=new Hl(e),{json:s}=t;if(s.lights){const e=t.addExtension("KHR_lights_punctual");Ul(!e.lights),e.lights=s.lights,delete s.lights}if(t.json.lights){for(const e of t.json.lights){const s=e.node;t.addObjectExtension(s,"KHR_lights_punctual",e)}delete t.json.lights}}}),Object.freeze({__proto__:null,name:"KHR_materials_unlit",decode:async function(e){const t=new Hl(e),{json:s}=t;for(const e of s.materials||[]){e.extensions&&e.extensions.KHR_materials_unlit&&(e.unlit=!0),t.removeObjectExtension(e,"KHR_materials_unlit")}t.removeExtension("KHR_materials_unlit")},encode:function(e){const t=new Hl(e),{json:s}=t;if(t.materials)for(const e of s.materials||[])e.unlit&&(delete e.unlit,t.addObjectExtension(e,"KHR_materials_unlit",{}),t.addExtension("KHR_materials_unlit"))}}),Object.freeze({__proto__:null,name:"KHR_techniques_webgl",decode:async function(e){const t=new Hl(e),{json:s}=t,i=t.getExtension("KHR_techniques_webgl");if(i){const e=function(e,t){const{programs:s=[],shaders:i=[],techniques:r=[]}=e,n=new TextDecoder;return i.forEach((e=>{if(!Number.isFinite(e.bufferView))throw new Error("KHR_techniques_webgl: no shader code");e.code=n.decode(t.getTypedArrayForBufferView(e.bufferView))})),s.forEach((e=>{e.fragmentShader=i[e.fragmentShader],e.vertexShader=i[e.vertexShader]})),r.forEach((e=>{e.program=s[e.program]})),r}(i,t);for(const i of s.materials||[]){const s=t.getObjectExtension(i,"KHR_techniques_webgl");s&&(i.technique=Object.assign({},s,e[s.technique]),i.technique.values=iu(i.technique,t)),t.removeObjectExtension(i,"KHR_techniques_webgl")}t.removeExtension("KHR_techniques_webgl")}},encode:async function(e,t){}}),su,vc];function nu(e,t){const s=t?.gltf?.excludeExtensions||{};return!(e in s&&!s[e])}const Au={accessors:"accessor",animations:"animation",buffers:"buffer",bufferViews:"bufferView",images:"image",materials:"material",meshes:"mesh",nodes:"node",samplers:"sampler",scenes:"scene",skins:"skin",textures:"texture"},ou={accessor:"accessors",animations:"animation",buffer:"buffers",bufferView:"bufferViews",image:"images",material:"materials",mesh:"meshes",node:"nodes",sampler:"samplers",scene:"scenes",skin:"skins",texture:"textures"};class au{idToIndexMap={animations:{},accessors:{},buffers:{},bufferViews:{},images:{},materials:{},meshes:{},nodes:{},samplers:{},scenes:{},skins:{},textures:{}};json;normalize(e,t){this.json=e.json;const s=e.json;switch(s.asset&&s.asset.version){case"2.0":return;case void 0:case"1.0":break;default:return void console.warn(`glTF: Unknown version ${s.asset.version}`)}if(!t.normalize)throw new Error("glTF v1 is not supported.");console.warn("Converting glTF v1 to glTF v2 format. This is experimental and may fail."),this._addAsset(s),this._convertTopLevelObjectsToArrays(s),function(e){const t=new Hl(e),{json:s}=t;for(const e of s.images||[]){const s=t.getObjectExtension(e,"KHR_binary_glTF");s&&Object.assign(e,s),t.removeObjectExtension(e,"KHR_binary_glTF")}s.buffers&&s.buffers[0]&&delete s.buffers[0].uri,t.removeExtension("KHR_binary_glTF")}(e),this._convertObjectIdsToArrayIndices(s),this._updateObjects(s),this._updateMaterial(s)}_addAsset(e){e.asset=e.asset||{},e.asset.version="2.0",e.asset.generator=e.asset.generator||"Normalized to glTF 2.0 by loaders.gl"}_convertTopLevelObjectsToArrays(e){for(const t in Au)this._convertTopLevelObjectToArray(e,t)}_convertTopLevelObjectToArray(e,t){const s=e[t];if(s&&!Array.isArray(s)){e[t]=[];for(const i in s){const r=s[i];r.id=r.id||i;const n=e[t].length;e[t].push(r),this.idToIndexMap[t][i]=n}}}_convertObjectIdsToArrayIndices(e){for(const t in Au)this._convertIdsToIndices(e,t);"scene"in e&&(e.scene=this._convertIdToIndex(e.scene,"scene"));for(const t of e.textures)this._convertTextureIds(t);for(const t of e.meshes)this._convertMeshIds(t);for(const t of e.nodes)this._convertNodeIds(t);for(const t of e.scenes)this._convertSceneIds(t)}_convertTextureIds(e){e.source&&(e.source=this._convertIdToIndex(e.source,"image"))}_convertMeshIds(e){for(const t of e.primitives){const{attributes:e,indices:s,material:i}=t;for(const t in e)e[t]=this._convertIdToIndex(e[t],"accessor");s&&(t.indices=this._convertIdToIndex(s,"accessor")),i&&(t.material=this._convertIdToIndex(i,"material"))}}_convertNodeIds(e){e.children&&(e.children=e.children.map((e=>this._convertIdToIndex(e,"node")))),e.meshes&&(e.meshes=e.meshes.map((e=>this._convertIdToIndex(e,"mesh"))))}_convertSceneIds(e){e.nodes&&(e.nodes=e.nodes.map((e=>this._convertIdToIndex(e,"node"))))}_convertIdsToIndices(e,t){e[t]||(console.warn(`gltf v1: json doesn't contain attribute ${t}`),e[t]=[]);for(const s of e[t])for(const e in s){const t=s[e],i=this._convertIdToIndex(t,e);s[e]=i}}_convertIdToIndex(e,t){const s=ou[t];if(s in this.idToIndexMap){const i=this.idToIndexMap[s][e];if(!Number.isFinite(i))throw new Error(`gltf v1: failed to resolve ${t} with id ${e}`);return i}return e}_updateObjects(e){for(const e of this.json.buffers)delete e.type}_updateMaterial(e){for(const t of e.materials){t.pbrMetallicRoughness={baseColorFactor:[1,1,1,1],metallicFactor:1,roughnessFactor:1};const s=t.values?.tex||t.values?.texture2d_0||t.values?.diffuseTex,i=e.textures.findIndex((e=>e.id===s));-1!==i&&(t.pbrMetallicRoughness.baseColorTexture={index:i})}}}async function lu(e,t,s=0,i,r){return function(e,t,s,i){i.uri&&(e.baseUri=i.uri);if(t instanceof ArrayBuffer&&!function(e,t=0,s={}){const i=new DataView(e),{magic:r=zc}=s,n=i.getUint32(t,!1);return n===r||n===zc}(t,s,i)){t=(new TextDecoder).decode(t)}if("string"==typeof t)e.json=ia(t);else if(t instanceof ArrayBuffer){const r={};s=Wc(r,t,s,i.glb),Ul("glTF"===r.type,`Invalid GLB magic string ${r.type}`),e._glb=r,e.json=r.json}else Ul(!1,"GLTF: must be ArrayBuffer or string");const r=e.json.buffers||[];if(e.buffers=new Array(r.length).fill(null),e._glb&&e._glb.header.hasBinChunk){const{binChunks:t}=e._glb;e.buffers[0]={arrayBuffer:t[0].arrayBuffer,byteOffset:t[0].byteOffset,byteLength:t[0].byteLength}}const n=e.json.images||[];e.images=new Array(n.length).fill({})}(e,t,s,i),function(e,t={}){(new au).normalize(e,t)}(e,{normalize:i?.gltf?.normalize}),function(e,t={},s){const i=ru.filter((e=>nu(e.name,t)));for(const r of i)r.preprocess?.(e,t,s)}(e,i,r),i?.gltf?.loadBuffers&&e.json.buffers&&await async function(e,t,s){const i=e.json.buffers||[];for(let r=0;r<i.length;++r){const n=i[r];if(n.uri){const{fetch:i}=s;Ul(i);const A=Zc(n.uri,t),o=await(s?.fetch?.(A)),a=await(o?.arrayBuffer?.());e.buffers[r]={arrayBuffer:a,byteOffset:0,byteLength:a.byteLength},delete n.uri}else null===e.buffers[r]&&(e.buffers[r]={arrayBuffer:new ArrayBuffer(n.byteLength),byteOffset:0,byteLength:n.byteLength})}}(e,i,r),i?.gltf?.loadImages&&await async function(e,t,s){const i=function(e){const t=new Set,s=e.json.textures||[];for(const e of s)void 0!==e.source&&t.add(e.source);return Array.from(t).sort()}(e),r=e.json.images||[],n=[];for(const A of i)n.push(cu(e,r[A],A,t,s));return await Promise.all(n)}(e,i,r),await async function(e,t={},s){const i=ru.filter((e=>nu(e.name,t)));for(const r of i)await(r.decode?.(e,t,s))}(e,i,r),e}async function cu(e,t,s,i,r){let n;if(t.uri&&!t.hasOwnProperty("bufferView")){const e=Zc(t.uri,i),{fetch:s}=r,A=await s(e);n=await A.arrayBuffer(),t.bufferView={data:n}}if(Number.isFinite(t.bufferView)){const s=function(e,t,s){const i=e.bufferViews[s];Ul(i);const r=t[i.buffer];Ul(r);const n=(i.byteOffset||0)+r.byteOffset;return new Uint8Array(r.arrayBuffer,n,i.byteLength)}(e.json,e.buffers,t.bufferView);n=na(s.buffer,s.byteOffset,s.byteLength)}Ul(n,"glTF image has no data");let A=await ao(n,[El,jc],{...i,mimeType:t.mimeType,basis:i.basis||{format:Gc()}},r);A&&A[0]&&(A={compressed:!0,mipmaps:!1,width:A[0].width,height:A[0].height,data:A[0]}),e.images=e.images||[],e.images[s]=A}const hu={dataType:null,batchType:null,name:"glTF",id:"gltf",module:"gltf",version:"4.3.3",extensions:["gltf","glb"],mimeTypes:["model/gltf+json","model/gltf-binary"],text:!0,binary:!0,tests:["glTF"],parse:async function(e,t={},s){(t={...hu.options,...t}).gltf={...hu.options.gltf,...t.gltf};const{byteOffset:i=0}=t;return await lu({},e,i,t,s)},options:{gltf:{normalize:!0,loadBuffers:!0,loadImages:!0,decompressMeshes:!0},log:console}};const uu={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},du={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},pu=10240,fu=10241,gu=10242,mu=10243,_u=10497,bu={magFilter:pu,minFilter:fu,wrapS:gu,wrapT:mu},yu={[pu]:9729,[fu]:9986,[gu]:_u,[mu]:_u};class Bu{baseUri="";jsonUnprocessed;json;buffers=[];images=[];postProcess(e,t={}){const{json:s,buffers:i=[],images:r=[]}=e,{baseUri:n=""}=e;return Ul(s),this.baseUri=n,this.buffers=i,this.images=r,this.jsonUnprocessed=s,this.json=this._resolveTree(e.json,t),this.json}_resolveTree(e,t={}){const s={...e};return this.json=s,e.bufferViews&&(s.bufferViews=e.bufferViews.map(((e,t)=>this._resolveBufferView(e,t)))),e.images&&(s.images=e.images.map(((e,t)=>this._resolveImage(e,t)))),e.samplers&&(s.samplers=e.samplers.map(((e,t)=>this._resolveSampler(e,t)))),e.textures&&(s.textures=e.textures.map(((e,t)=>this._resolveTexture(e,t)))),e.accessors&&(s.accessors=e.accessors.map(((e,t)=>this._resolveAccessor(e,t)))),e.materials&&(s.materials=e.materials.map(((e,t)=>this._resolveMaterial(e,t)))),e.meshes&&(s.meshes=e.meshes.map(((e,t)=>this._resolveMesh(e,t)))),e.nodes&&(s.nodes=e.nodes.map(((e,t)=>this._resolveNode(e,t))),s.nodes=s.nodes.map(((e,t)=>this._resolveNodeChildren(e)))),e.skins&&(s.skins=e.skins.map(((e,t)=>this._resolveSkin(e,t)))),e.scenes&&(s.scenes=e.scenes.map(((e,t)=>this._resolveScene(e,t)))),"number"==typeof this.json.scene&&s.scenes&&(s.scene=s.scenes[this.json.scene]),s}getScene(e){return this._get(this.json.scenes,e)}getNode(e){return this._get(this.json.nodes,e)}getSkin(e){return this._get(this.json.skins,e)}getMesh(e){return this._get(this.json.meshes,e)}getMaterial(e){return this._get(this.json.materials,e)}getAccessor(e){return this._get(this.json.accessors,e)}getCamera(e){return this._get(this.json.cameras,e)}getTexture(e){return this._get(this.json.textures,e)}getSampler(e){return this._get(this.json.samplers,e)}getImage(e){return this._get(this.json.images,e)}getBufferView(e){return this._get(this.json.bufferViews,e)}getBuffer(e){return this._get(this.json.buffers,e)}_get(e,t){if("object"==typeof t)return t;const s=e&&e[t];return s||console.warn(`glTF file error: Could not find ${e}[${t}]`),s}_resolveScene(e,t){return{...e,id:e.id||`scene-${t}`,nodes:(e.nodes||[]).map((e=>this.getNode(e)))}}_resolveNode(e,t){const s={...e,id:e?.id||`node-${t}`};return void 0!==e.mesh&&(s.mesh=this.getMesh(e.mesh)),void 0!==e.camera&&(s.camera=this.getCamera(e.camera)),void 0!==e.skin&&(s.skin=this.getSkin(e.skin)),void 0!==e.meshes&&e.meshes.length&&(s.mesh=e.meshes.reduce(((e,t)=>{const s=this.getMesh(t);return e.id=s.id,e.primitives=e.primitives.concat(s.primitives),e}),{primitives:[]})),s}_resolveNodeChildren(e){return e.children&&(e.children=e.children.map((e=>this.getNode(e)))),e}_resolveSkin(e,t){const s="number"==typeof e.inverseBindMatrices?this.getAccessor(e.inverseBindMatrices):void 0;return{...e,id:e.id||`skin-${t}`,inverseBindMatrices:s}}_resolveMesh(e,t){const s={...e,id:e.id||`mesh-${t}`,primitives:[]};return e.primitives&&(s.primitives=e.primitives.map((e=>{const t={...e,attributes:{},indices:void 0,material:void 0},s=e.attributes;for(const e in s)t.attributes[e]=this.getAccessor(s[e]);return void 0!==e.indices&&(t.indices=this.getAccessor(e.indices)),void 0!==e.material&&(t.material=this.getMaterial(e.material)),t}))),s}_resolveMaterial(e,t){const s={...e,id:e.id||`material-${t}`};if(s.normalTexture&&(s.normalTexture={...s.normalTexture},s.normalTexture.texture=this.getTexture(s.normalTexture.index)),s.occlusionTexture&&(s.occlusionTexture={...s.occlusionTexture},s.occlusionTexture.texture=this.getTexture(s.occlusionTexture.index)),s.emissiveTexture&&(s.emissiveTexture={...s.emissiveTexture},s.emissiveTexture.texture=this.getTexture(s.emissiveTexture.index)),s.emissiveFactor||(s.emissiveFactor=s.emissiveTexture?[1,1,1]:[0,0,0]),s.pbrMetallicRoughness){s.pbrMetallicRoughness={...s.pbrMetallicRoughness};const e=s.pbrMetallicRoughness;e.baseColorTexture&&(e.baseColorTexture={...e.baseColorTexture},e.baseColorTexture.texture=this.getTexture(e.baseColorTexture.index)),e.metallicRoughnessTexture&&(e.metallicRoughnessTexture={...e.metallicRoughnessTexture},e.metallicRoughnessTexture.texture=this.getTexture(e.metallicRoughnessTexture.index))}return s}_resolveAccessor(e,t){const s=(i=e.componentType,du[i]);var i;const r=(n=e.type,uu[n]);var n;const A=s*r,o={...e,id:e.id||`accessor-${t}`,bytesPerComponent:s,components:r,bytesPerElement:A,value:void 0,bufferView:void 0,sparse:void 0};if(void 0!==e.bufferView&&(o.bufferView=this.getBufferView(e.bufferView)),o.bufferView){const e=o.bufferView.buffer,{ArrayType:t,byteLength:s}=Ll(o,o.bufferView),i=(o.bufferView.byteOffset||0)+(o.byteOffset||0)+e.byteOffset;let r=e.arrayBuffer.slice(i,i+s);o.bufferView.byteStride&&(r=this._getValueFromInterleavedBuffer(e,i,o.bufferView.byteStride,o.bytesPerElement,o.count)),o.value=new t(r)}return o}_getValueFromInterleavedBuffer(e,t,s,i,r){const n=new Uint8Array(r*i);for(let A=0;A<r;A++){const r=t+A*s;n.set(new Uint8Array(e.arrayBuffer.slice(r,r+i)),A*i)}return n.buffer}_resolveTexture(e,t){return{...e,id:e.id||`texture-${t}`,sampler:"number"==typeof e.sampler?this.getSampler(e.sampler):{id:"default-sampler",parameters:yu},source:"number"==typeof e.source?this.getImage(e.source):void 0}}_resolveSampler(e,t){const s={id:e.id||`sampler-${t}`,...e,parameters:{}};for(const e in s){const t=this._enumSamplerParameter(e);void 0!==t&&(s.parameters[t]=s[e])}return s}_enumSamplerParameter(e){return bu[e]}_resolveImage(e,t){const s={...e,id:e.id||`image-${t}`,image:null,bufferView:void 0!==e.bufferView?this.getBufferView(e.bufferView):void 0},i=this.images[t];return i&&(s.image=i),s}_resolveBufferView(e,t){const s=e.buffer,i=this.buffers[s].arrayBuffer;let r=this.buffers[s].byteOffset||0;e.byteOffset&&(r+=e.byteOffset);return{id:`bufferView-${t}`,...e,buffer:this.buffers[s],data:new Uint8Array(i,r,e.byteLength)}}_resolveCamera(e,t){return{...e,id:e.id||`camera-${t}`}}}function wu(e,t){return(new Bu).postProcess(e,t)}const vu={dataType:null,batchType:null,name:"LAS",id:"las",module:"las",version:"4.3.3",worker:!0,extensions:["las","laz"],mimeTypes:["application/octet-stream"],text:!0,binary:!0,tests:["LAS"],options:{las:{shape:"mesh",fp64:!1,skip:1,colorDepth:8}}};function Cu(){var e,t=void 0!==t?t:{},s={};for(e in t)t.hasOwnProperty(e)&&(s[e]=t[e]);var i,r,n,A;i="object"==typeof window,r="function"==typeof importScripts,n="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,A=!i&&!n&&!r;var o,a,l,c,h,u="";if(n){if(r)u=require("path").dirname(u)+"/";else{const e="undefined"!=typeof __dirname?__dirname:"";u=e+"/"}o=function(e,t){var s=ht(e);return s?t?s:s.toString():(c||(c=require("fs")),h||(h=require("path")),e=h.normalize(e),c.readFileSync(e,t?null:"utf8"))},l=function(e){var t=o(e,!0);return t.buffer||(t=new Uint8Array(t)),m(t.buffer),t},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),"undefined"!=typeof module&&(module.exports=t),process.on("uncaughtException",(function(e){if(!(e instanceof Et))throw e})),process.on("unhandledRejection",z),t.inspect=function(){return"[Emscripten Module object]"}}else A?("undefined"!=typeof read&&(o=function(e){var t=ht(e);return t?lt(t):read(e)}),l=function(e){var t;return(t=ht(e))?t:"function"==typeof readbuffer?new Uint8Array(readbuffer(e)):(m("object"==typeof(t=read(e,"binary"))),t)},"undefined"!=typeof scriptArgs&&scriptArgs,"undefined"!=typeof print&&("undefined"==typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!=typeof printErr?printErr:print)):(i||r)&&(r?u=self.location.href:document.currentScript&&(u=document.currentScript.src),u=0!==u.indexOf("blob:")?u.substr(0,u.lastIndexOf("/")+1):"",o=function(e){try{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),t.responseText}catch(t){var s=ht(e);if(s)return lt(s);throw t}},r&&(l=function(e){try{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}catch(t){var s=ht(e);if(s)return s;throw t}}),a=function(e,t,s){var i=new XMLHttpRequest;i.open("GET",e,!0),i.responseType="arraybuffer",i.onload=function(){if(200==i.status||0==i.status&&i.response)t(i.response);else{var r=ht(e);r?t(r.buffer):s()}},i.onerror=s,i.send(null)});var d=t.print||console.log.bind(console),p=t.printErr||console.warn.bind(console);for(e in s)s.hasOwnProperty(e)&&(t[e]=s[e]);s=null,t.arguments,t.thisProgram,t.quit,new Array(0);var f=0;t.wasmBinary,t.noExitRuntime;var g=!1;function m(e,t){e||z("Assertion failed: "+t)}var _="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function b(e,t){return e?function(e,t,s){for(var i=t+s,r=t;e[r]&&!(r>=i);)++r;if(r-t>16&&e.subarray&&_)return _.decode(e.subarray(t,r));for(var n="";t<r;){var A=e[t++];if(128&A){var o=63&e[t++];if(192!=(224&A)){var a=63&e[t++];if((A=224==(240&A)?(15&A)<<12|o<<6|a:(7&A)<<18|o<<12|a<<6|63&e[t++])<65536)n+=String.fromCharCode(A);else{var l=A-65536;n+=String.fromCharCode(55296|l>>10,56320|1023&l)}}else n+=String.fromCharCode((31&A)<<6|o)}else n+=String.fromCharCode(A)}return n}(w,e,t):""}var y,B,w,v,C,M,E,F,x,U="undefined"!=typeof TextDecoder?new TextDecoder("utf-16le"):void 0;function I(e,t){for(var s=e,i=s>>1,r=i+t/2;!(i>=r)&&C[i];)++i;if((s=i<<1)-e>32&&U)return U.decode(w.subarray(e,s));for(var n=0,A="";;){var o=v[e+2*n>>1];if(0==o||n==t/2)return A;++n,A+=String.fromCharCode(o)}}function T(e,t,s){if(void 0===s&&(s=2147483647),s<2)return 0;for(var i=t,r=(s-=2)<2*e.length?s/2:e.length,n=0;n<r;++n){var A=e.charCodeAt(n);v[t>>1]=A,t+=2}return v[t>>1]=0,t-i}function P(e){return 2*e.length}function S(e,t){for(var s=0,i="";!(s>=t/4);){var r=M[e+4*s>>2];if(0==r)break;if(++s,r>=65536){var n=r-65536;i+=String.fromCharCode(55296|n>>10,56320|1023&n)}else i+=String.fromCharCode(r)}return i}function D(e,t,s){if(void 0===s&&(s=2147483647),s<4)return 0;for(var i=t,r=i+s-4,n=0;n<e.length;++n){var A=e.charCodeAt(n);if(A>=55296&&A<=57343)A=65536+((1023&A)<<10)|1023&e.charCodeAt(++n);if(M[t>>2]=A,(t+=4)+4>r)break}return M[t>>2]=0,t-i}function k(e){for(var t=0,s=0;s<e.length;++s){var i=e.charCodeAt(s);i>=55296&&i<=57343&&++s,t+=4}return t}var Q,R=t.INITIAL_MEMORY||167772160;function O(e){for(;e.length>0;){var s=e.shift();if("function"!=typeof s){var i=s.func;"number"==typeof i?void 0===s.arg?t.dynCall_v(i):t.dynCall_vi(i,s.arg):i(void 0===s.arg?null:s.arg)}else s(t)}}R=(y=t.buffer?t.buffer:new ArrayBuffer(R)).byteLength,y=Q=y,t.HEAP8=B=new Int8Array(Q),t.HEAP16=v=new Int16Array(Q),t.HEAP32=M=new Int32Array(Q),t.HEAPU8=w=new Uint8Array(Q),t.HEAPU16=C=new Uint16Array(Q),t.HEAPU32=E=new Uint32Array(Q),t.HEAPF32=F=new Float32Array(Q),t.HEAPF64=x=new Float64Array(Q),M[5544]=5265264;var V=[],L=[],H=[],N=[];var G=0,j=null;function z(e){throw t.onAbort&&t.onAbort(e),d(e+=""),p(e),g=!0,e="abort("+e+"). Build with -s ASSERTIONS=1 for more info."}t.preloadedImages={},t.preloadedAudios={};var W=null;var X="data:application/octet-stream;base64,";function K(e){return t=e,s=X,String.prototype.startsWith?t.startsWith(s):0===t.indexOf(s);var t,s}L.push({func:function(){yt()}}),W="data:application/octet-stream;base64,AAAAAAAAAAAPDg0MCwoJCA4AAQMGCgoJDQECBAcLCwoMAwQFCAwMCwsGBwgJDQ0MCgoLDA0ODg0JCgsMDQ4PDggJCgsMDQ4PAAECAwQFBgcBAAECAwQFBgIBAAECAwQFAwIBAAECAwQEAwIBAAECAwUEAwIBAAECBgUEAwIBAAEHBgUEAwIBAMgPAAAoDQAAEBAAACAQAADIDwAAUA0AABAQAAAgEAAAEQAKABEREQAAAAAFAAAAAAAACQAAAAALAAAAAAAAAAARAA8KERERAwoHAAEACQsLAAAJBgsAAAsABhEAAAAREREAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAEQAKChEREQAKAAACAAkLAAAACQALAAALAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAADAAAAAAJDAAAAAAADAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAANAAAABA0AAAAACQ4AAAAAAA4AAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAADwAAAAAPAAAAAAkQAAAAAAAQAAAQAAASAAAAEhISAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAASEhIAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAAAAAAKAAAAAAoAAAAACQsAAAAAAAsAAAsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAMAAAAAAkMAAAAAAAMAAAMAAAwMTIzNDU2Nzg5QUJDREVGGRJEOwI/LEcUPTMwChsGRktFNw9JDo4XA0AdPGkrNh9KLRwBICUpIQgMFRYiLhA4Pgs0MRhkdHV2L0EJfzkRI0MyQomKiwUEJignDSoeNYwHGkiTE5SVAAAAAAAAAAAASWxsZWdhbCBieXRlIHNlcXVlbmNlAERvbWFpbiBlcnJvcgBSZXN1bHQgbm90IHJlcHJlc2VudGFibGUATm90IGEgdHR5AFBlcm1pc3Npb24gZGVuaWVkAE9wZXJhdGlvbiBub3QgcGVybWl0dGVkAE5vIHN1Y2ggZmlsZSBvciBkaXJlY3RvcnkATm8gc3VjaCBwcm9jZXNzAEZpbGUgZXhpc3RzAFZhbHVlIHRvbyBsYXJnZSBmb3IgZGF0YSB0eXBlAE5vIHNwYWNlIGxlZnQgb24gZGV2aWNlAE91dCBvZiBtZW1vcnkAUmVzb3VyY2UgYnVzeQBJbnRlcnJ1cHRlZCBzeXN0ZW0gY2FsbABSZXNvdXJjZSB0ZW1wb3JhcmlseSB1bmF2YWlsYWJsZQBJbnZhbGlkIHNlZWsAQ3Jvc3MtZGV2aWNlIGxpbmsAUmVhZC1vbmx5IGZpbGUgc3lzdGVtAERpcmVjdG9yeSBub3QgZW1wdHkAQ29ubmVjdGlvbiByZXNldCBieSBwZWVyAE9wZXJhdGlvbiB0aW1lZCBvdXQAQ29ubmVjdGlvbiByZWZ1c2VkAEhvc3QgaXMgZG93bgBIb3N0IGlzIHVucmVhY2hhYmxlAEFkZHJlc3MgaW4gdXNlAEJyb2tlbiBwaXBlAEkvTyBlcnJvcgBObyBzdWNoIGRldmljZSBvciBhZGRyZXNzAEJsb2NrIGRldmljZSByZXF1aXJlZABObyBzdWNoIGRldmljZQBOb3QgYSBkaXJlY3RvcnkASXMgYSBkaXJlY3RvcnkAVGV4dCBmaWxlIGJ1c3kARXhlYyBmb3JtYXQgZXJyb3IASW52YWxpZCBhcmd1bWVudABBcmd1bWVudCBsaXN0IHRvbyBsb25nAFN5bWJvbGljIGxpbmsgbG9vcABGaWxlbmFtZSB0b28gbG9uZwBUb28gbWFueSBvcGVuIGZpbGVzIGluIHN5c3RlbQBObyBmaWxlIGRlc2NyaXB0b3JzIGF2YWlsYWJsZQBCYWQgZmlsZSBkZXNjcmlwdG9yAE5vIGNoaWxkIHByb2Nlc3MAQmFkIGFkZHJlc3MARmlsZSB0b28gbGFyZ2UAVG9vIG1hbnkgbGlua3MATm8gbG9ja3MgYXZhaWxhYmxlAFJlc291cmNlIGRlYWRsb2NrIHdvdWxkIG9jY3VyAFN0YXRlIG5vdCByZWNvdmVyYWJsZQBQcmV2aW91cyBvd25lciBkaWVkAE9wZXJhdGlvbiBjYW5jZWxlZABGdW5jdGlvbiBub3QgaW1wbGVtZW50ZWQATm8gbWVzc2FnZSBvZiBkZXNpcmVkIHR5cGUASWRlbnRpZmllciByZW1vdmVkAERldmljZSBub3QgYSBzdHJlYW0ATm8gZGF0YSBhdmFpbGFibGUARGV2aWNlIHRpbWVvdXQAT3V0IG9mIHN0cmVhbXMgcmVzb3VyY2VzAExpbmsgaGFzIGJlZW4gc2V2ZXJlZABQcm90b2NvbCBlcnJvcgBCYWQgbWVzc2FnZQBGaWxlIGRlc2NyaXB0b3IgaW4gYmFkIHN0YXRlAE5vdCBhIHNvY2tldABEZXN0aW5hdGlvbiBhZGRyZXNzIHJlcXVpcmVkAE1lc3NhZ2UgdG9vIGxhcmdlAFByb3RvY29sIHdyb25nIHR5cGUgZm9yIHNvY2tldABQcm90b2NvbCBub3QgYXZhaWxhYmxlAFByb3RvY29sIG5vdCBzdXBwb3J0ZWQAU29ja2V0IHR5cGUgbm90IHN1cHBvcnRlZABOb3Qgc3VwcG9ydGVkAFByb3RvY29sIGZhbWlseSBub3Qgc3VwcG9ydGVkAEFkZHJlc3MgZmFtaWx5IG5vdCBzdXBwb3J0ZWQgYnkgcHJvdG9jb2wAQWRkcmVzcyBub3QgYXZhaWxhYmxlAE5ldHdvcmsgaXMgZG93bgBOZXR3b3JrIHVucmVhY2hhYmxlAENvbm5lY3Rpb24gcmVzZXQgYnkgbmV0d29yawBDb25uZWN0aW9uIGFib3J0ZWQATm8gYnVmZmVyIHNwYWNlIGF2YWlsYWJsZQBTb2NrZXQgaXMgY29ubmVjdGVkAFNvY2tldCBub3QgY29ubmVjdGVkAENhbm5vdCBzZW5kIGFmdGVyIHNvY2tldCBzaHV0ZG93bgBPcGVyYXRpb24gYWxyZWFkeSBpbiBwcm9ncmVzcwBPcGVyYXRpb24gaW4gcHJvZ3Jlc3MAU3RhbGUgZmlsZSBoYW5kbGUAUmVtb3RlIEkvTyBlcnJvcgBRdW90YSBleGNlZWRlZABObyBtZWRpdW0gZm91bmQAV3JvbmcgbWVkaXVtIHR5cGUATm8gZXJyb3IgaW5mb3JtYXRpb24AAAAAAADgFgAAmRgAAGAQAAAAAAAA4BYAAEIZAABgEAAAAAAAAOAWAAAqGgAASA8AAAAAAAC4FgAANBsAAOAWAACfGgAAMAoAAAAAAADgFgAAaRsAAEgPAAAAAAAA4BYAAIobAABIDwAAAAAAALgWAAAPHAAA4BYAAHwcAABIDwAAAAAAAOAWAACVHAAASA8AAAAAAADgFgAAHh0AAEgPAAAAAAAA4BYAAHcdAABIDwAAAAAAAOAWAACQHQAASA8AAAAAAADgFgAAQh4AAEgPAAAAAAAA4BYAAIceAABgEAAAAAAAAOAWAACkHwAASA8AAAAAAAC4FgAAZyAAAOAWAADkHwAA8AoAAAAAAADgFgAAjyAAAGAQAAAAAAAAuBYAAMMiAADgFgAAAiIAABgLAAAAAAAA4BYAAOEiAABgEAAAAAAAAOAWAADQJAAAGAsAAAAAAADgFgAAkSUAAGAQAAAAAAAA4BYAAIAnAAAYCwAAAAAAAOAWAAA9KAAAYBAAAAAAAADgFgAAJCoAABgLAAAAAAAA4BYAAOkqAABgEAAAAAAAAOAWAADgLAAA8AoAAAAAAADgFgAAui0AAGAQAAAAAAAA4BYAANsvAADwCgAAAAAAAOAWAADTMAAAYBAAAAAAAADgFgAAMDMAAPAKAAAAAAAA4BYAACQ0AABgEAAAAAAAAOAWAAB5NgAA8AoAAAAAAADgFgAAizcAAGAQAAAAAAAA4BYAABw6AABgEAAAAAAAAOAWAACdOgAAYBAAAAAAAADgFgAAXjsAAPAKAAAAAAAA4BYAALU7AABgEAAAAAAAAOAWAADMPAAAGAsAAAAAAADgFgAATz0AAGAQAAAAAAAA4BYAAL4+AAAYCwAAAAAAAOAWAABBPwAAYBAAAAAAAADgFgAAsEAAABgLAAAAAAAA4BYAADNBAABgEAAAAAAAAOAWAACiQgAAGAsAAAAAAADgFgAAJUMAAGAQAAAAAAAA4BYAAJREAAAYCwAAAAAAAOAWAAAXRQAAYBAAAAAAAADgFgAAhkYAABgLAAAAAAAA4BYAAAlHAABgEAAAAAAAALgWAAB4SAAAiBcAAIBIAAAAAAAAIA0AAIgXAACJSAAAAQAAACANAAC4FgAAqkgAAIgXAAC6SAAAAAAAAEgNAACIFwAAy0gAAAEAAABIDQAAuBYAABhMAAC4FgAAN0wAALgWAABWTAAAuBYAAHVMAAC4FgAAlEwAALgWAACzTAAAuBYAANJMAAC4FgAA8UwAALgWAAAQTQAAuBYAAC9NAAC4FgAATk0AALgWAABtTQAAuBYAAIxNAACkFwAAn00AAAAAAAABAAAA8A0AAAAAAAC4FgAA4U0AAKQXAAAHTgAAAAAAAAEAAADwDQAAAAAAAKQXAABJTgAAAAAAAAEAAADwDQAAAAAAAKQXAACITgAAAAAAAAEAAADwDQAAAAAAAKQXAADHTgAAAAAAAAEAAADwDQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP//////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALgWAADNTwAA4BYAAC1QAAAADwAAAAAAAOAWAADaTwAAEA8AAAAAAAC4FgAA+08AAOAWAAAIUAAA8A4AAAAAAADgFgAAhlAAAOgOAAAAAAAA4BYAAJNQAADoDgAAAAAAAOAWAACjUAAA6A4AAAAAAADgFgAAtVAAADgPAAAAAAAA4BYAAMZQAAA4DwAAAAAAAOAWAADXUAAAAA8AAAAAAADgFgAA+VAAAHgPAAAAAAAA4BYAAB1RAAAADwAAAAAAAOAWAABCUQAAeA8AAAAAAADgFgAAjlEAAAAPAAAAAAAAbBcAALZRAABsFwAAuFEAAGwXAAC7UQAAbBcAAL1RAABsFwAAv1EAAGwXAADBUQAAbBcAAMNRAABsFwAAxVEAAGwXAADHUQAAbBcAAMlRAABsFwAAy1EAAGwXAADNUQAAbBcAAM9RAABsFwAA0VEAAOAWAADTUQAA8A4AAAAAAADgFgAARlIAAOgOAAAAAAAAuBYAAGJSAACkFwAAe1IAAAAAAAABAAAAWBAAAAAAAADgFgAA9FIAAIgQAAAAAAAA4BYAABdTAACYEAAAAAAAALgWAAAuUwAA4BYAAHBTAACIEAAAAAAAAOAWAACSUwAASA8AAAAAAAAAAAAAAAoAAAEAAAACAAAAAwAAAAEAAAAEAAAAAAAAABAKAAABAAAABQAAAAYAAAACAAAABwAAAAAAAAAgCgAACAAAAAkAAAABAAAAAAAAADgKAAAKAAAACwAAAAIAAAABAAAADAAAAA0AAAACAAAAAwAAAAMAAAAAAAAASAoAAAgAAAAOAAAAAQAAAAAAAABYCgAACAAAAA8AAAABAAAAAAAAAIAKAAAIAAAAEAAAAAEAAAAAAAAAcAoAAAgAAAARAAAAAQAAAAAAAACQCgAACAAAABIAAAABAAAAAAAAAKAKAAAIAAAAEwAAAAEAAAAAAAAAsAoAAAgAAAAUAAAAAQAAAAAAAADACgAACAAAABUAAAABAAAAAAAAANAKAAABAAAAFgAAABcAAAAEAAAAGAAAAAAAAADgCgAACAAAABkAAAABAAAAAAAAAPgKAAAFAAAAGgAAABsAAAAAAAAA8AoAAAEAAAAcAAAAHQAAAAAAAAAICwAAAQAAAB4AAAAfAAAABgAAACAAAAAAAAAAIAsAACEAAAAiAAAABwAAAAgAAAAAAAAAGAsAACMAAAAkAAAABwAAAAkAAAAAAAAAMAsAAAEAAAAlAAAAJgAAAAoAAAAnAAAAAAAAAEALAAAoAAAAKQAAAAcAAAALAAAAAAAAAFALAAABAAAAKgAAACsAAAAMAAAALAAAAAAAAABgCwAALQAAAC4AAAAHAAAADQAAAAAAAABwCwAAAQAAAC8AAAAwAAAADgAAADEAAAAAAAAAgAsAADIAAAAzAAAABwAAAA8AAAAAAAAAkAsAAAEAAAA0AAAANQAAABAAAAA2AAAAAAAAAKALAAARAAAANwAAADgAAAAAAAAAsAsAAAEAAAA5AAAAOgAAABIAAAA7AAAAAAAAAMALAAATAAAAPAAAAD0AAAAAAAAA0AsAAAEAAAA+AAAAPwAAABQAAABAAAAAAAAAAOALAAAVAAAAQQAAAEIAAAAAAAAA8AsAAAEAAABDAAAARAAAABYAAABFAAAAAAAAAAAMAAAXAAAARgAAAEcAAAAAAAAAEAwAAAEAAABIAAAASQAAABgAAABKAAAAAAAAACAMAAABAAAASwAAAEwAAAAZAAAATQAAAAAAAAAwDAAAAQAAAE4AAABPAAAAGgAAAFAAAAAAAAAAQAwAABsAAABRAAAAUgAAAAAAAABQDAAAAQAAAFMAAABUAAAAHAAAAFUAAAAAAAAAYAwAAFYAAABXAAAABwAAAB0AAAAAAAAAcAwAAAEAAABYAAAAWQAAAB4AAABaAAAAAAAAAIAMAABbAAAAXAAAAAcAAAAfAAAAAAAAAJAMAAABAAAAXQAAAF4AAAAgAAAAXwAAAAAAAACgDAAAYAAAAGEAAAAHAAAAIQAAAAAAAACwDAAAAQAAAGIAAABjAAAAIgAAAGQAAAAAAAAAwAwAAGUAAABmAAAABwAAACMAAAAAAAAA0AwAAAEAAABnAAAAaAAAACQAAABpAAAAAAAAAOAMAABqAAAAawAAAAcAAAAlAAAAAAAAAPAMAAABAAAAbAAAAG0AAAAmAAAAbgAAAAAAAAAADQAAbwAAAHAAAAAHAAAAJwAAAAAAAAAQDQAAAQAAAHEAAAByAAAAKAAAAHMAAAAoDQAAyA8AACgNAAAIEAAAEBAAACgNAABQDQAAyA8AAFANAAAgEAAAyA8AAFANAAAIEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsVAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwDgAAdAAAAHUAAAB2AAAAdwAAAAIAAAABAAAAAQAAAAEAAAAAAAAAGA8AAHQAAAB4AAAAdgAAAHcAAAACAAAAAgAAAAIAAAACAAAAAAAAACgPAAB5AAAAegAAAAQAAAAAAAAAOA8AAHsAAAB8AAAABQAAAAAAAABIDwAACAAAAH0AAAABAAAAAAAAAFgPAAB7AAAAfgAAAAUAAAAAAAAAaA8AAHsAAAB/AAAABQAAAAAAAAC4DwAAdAAAAIAAAAB2AAAAdwAAAAMAAAAAAAAAiA8AAHQAAACBAAAAdgAAAHcAAAAEAAAAAAAAADgQAAB0AAAAggAAAHYAAAB3AAAAAgAAAAMAAAADAAAAAwAAAAAAAABIEAAAgwAAAIQAAAAGAAAAAAAAAHgQAACFAAAAhgAAAAcAAAABAAAABQAAAAYAAAACAAAAAAAAAKAQAACFAAAAhwAAAAgAAAADAAAABQAAAAYAAAAEAAAA4BcAAAQYAAAAAAAAsBAAAIgAAACJAAAAAQAAAExBU1ppcABvcGVuAGdldFBvaW50AGdldENvdW50AER5bmFtaWNMQVNaaXAAYWRkRmllbGRGbG9hdGluZwBhZGRGaWVsZFNpZ25lZABhZGRGaWVsZFVuc2lnbmVkAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRU5TXzE0ZGVmYXVsdF9kZWxldGVJUzNfRUVOU185YWxsb2NhdG9ySVMzX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXAyaW82cmVhZGVyMTBiYXNpY19maWxlSU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJUzdfRUVOU185YWxsb2NhdG9ySVM3X0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXAyaW82cmVhZGVyMTBiYXNpY19maWxlSU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFAExBU0YATjZsYXN6aXAxM2ludmFsaWRfbWFnaWNFAGFsbG9jYXRvcjxUPjo6YWxsb2NhdGUoc2l6ZV90IG4pICduJyBleGNlZWRzIG1heGltdW0gc3VwcG9ydGVkIHNpemUARmlsZSBtYWdpYyBpcyBub3QgdmFsaWQATlN0M19fMjEwX19mdW5jdGlvbjZfX2Z1bmNJWk42bGFzemlwMmlvNnJlYWRlcjEwYmFzaWNfZmlsZUlOUzJfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRTExX3ZhbGlkYXRvcnNFdkVVbFJOUzNfNmhlYWRlckVFX05TXzlhbGxvY2F0b3JJU0JfRUVGdlNBX0VFRQBOU3QzX18yMTBfX2Z1bmN0aW9uNl9fYmFzZUlGdlJONmxhc3ppcDJpbzZoZWFkZXJFRUVFAE42bGFzemlwMjFvbGRfc3R5bGVfY29tcHJlc3Npb25FAE42bGFzemlwMTRub3RfY29tcHJlc3NlZEUAVGhlIGZpbGUgc2VlbXMgdG8gaGF2ZSBvbGQgc3R5bGUgY29tcHJlc3Npb24gd2hpY2ggaXMgbm90IHN1cHBvcnRlZABUaGUgZmlsZSBkb2Vzbid0IHNlZW0gdG8gYmUgY29tcHJlc3NlZABaTjZsYXN6aXAyaW82cmVhZGVyMTBiYXNpY19maWxlSU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUUxMV92YWxpZGF0b3JzRXZFVWxSTlMwXzZoZWFkZXJFRV8AbGFzemlwIGVuY29kZWQATjZsYXN6aXAxM25vX2xhc3ppcF92bHJFAE42bGFzemlwMjVsYXN6aXBfZm9ybWF0X3Vuc3VwcG9ydGVkRQBPbmx5IExBU3ppcCBQT0lOVFdJU0UgQ0hVTktFRCBkZWNvbXByZXNzb3IgaXMgc3VwcG9ydGVkAE5vIExBU3ppcCBWTFIgd2FzIGZvdW5kIGluIHRoZSBWTFJzIHNlY3Rpb24ATjZsYXN6aXAyMmNodW5rX3RhYmxlX3JlYWRfZXJyb3JFAENodW5rIHRhYmxlIG9mZnNldCA9PSAtMSBpcyBub3Qgc3VwcG9ydGVkIGF0IHRoaXMgdGltZQBONmxhc3ppcDEzbm90X3N1cHBvcnRlZEUATjZsYXN6aXAyNnVua25vd25fY2h1bmtfdGFibGVfZm9ybWF0RQBjaHVua19zaXplID09IHVpbnQubWF4IGlzIG5vdCBzdXBwb3J0ZWQgYXQgdGhpcyB0aW1lLgBUaGVyZSB3YXMgYSBwcm9ibGVtIHJlYWRpbmcgdGhlIGNodW5rIHRhYmxlAFRoZSBjaHVuayB0YWJsZSB2ZXJzaW9uIG51bWJlciBpcyB1bmtub3duAE42bGFzemlwMTFlbmRfb2ZfZmlsZUUAUmVhY2hlZCBFbmQgb2YgZmlsZQBJbnZhbGlkIG51bWJlciBvZiBzeW1ib2xzAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOU18xNGRlZmF1bHRfZGVsZXRlSVM5X0VFTlNfOWFsbG9jYXRvcklTOV9FRUVFAE5TdDNfXzIxNGRlZmF1bHRfZGVsZXRlSU42bGFzemlwOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRUVFAE42bGFzemlwMTl1bmtub3duX3NjaGVtYV90eXBlRQBUaGUgTEFaIHNjaGVtYSBpcyBub3QgcmVjb2duaXplZABONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2ZpZWxkX2RlY29tcHJlc3NvcklOU184ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlNfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlNfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyMGR5bmFtaWNfZGVjb21wcmVzc29yRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19maWVsZF9kZWNvbXByZXNzb3JJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU0NfRUVOU185YWxsb2NhdG9ySVNDX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19maWVsZF9kZWNvbXByZXNzb3JJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOU18yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOU183c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMwXzVmaWVsZElOUzBfM2xhczdwb2ludDEwRU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNDX0VFRUVFRQBONmxhc3ppcDdmb3JtYXRzMTBiYXNlX2ZpZWxkRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19kZWNvbXByZXNzb3JfZmllbGRJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0VfRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTSV9FRU5TXzlhbGxvY2F0b3JJU0lfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMl81ZmllbGRJTlMyXzNsYXM3cG9pbnQxMEVOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRV9FRUVFRUVFRQBONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOU184ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlNfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlNfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMF81ZmllbGRJTlMwXzNsYXM3Z3BzdGltZUVOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTQ19FRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczdncHN0aW1lRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNFX0VFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU0lfRUVOU185YWxsb2NhdG9ySVNJX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19kZWNvbXByZXNzb3JfZmllbGRJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfNWZpZWxkSU5TMl8zbGFzN2dwc3RpbWVFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0VfRUVFRUVFRUUATjZsYXN6aXA3Zm9ybWF0czI2ZHluYW1pY19kZWNvbXByZXNzb3JfZmllbGRJTlNfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzBfNWZpZWxkSU5TMF8zbGFzM3JnYkVOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTQ19FRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczNyZ2JFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0VfRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTSV9FRU5TXzlhbGxvY2F0b3JJU0lfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMl81ZmllbGRJTlMyXzNsYXMzcmdiRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNFX0VFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOU18yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOU183c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMwXzVmaWVsZElOUzBfM2xhczEwZXh0cmFieXRlc0VOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTQ19FRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczEwZXh0cmFieXRlc0VOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRV9FRUVFRUVOU18xNGRlZmF1bHRfZGVsZXRlSVNJX0VFTlNfOWFsbG9jYXRvcklTSV9FRUVFAE5TdDNfXzIxNGRlZmF1bHRfZGVsZXRlSU42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzVmaWVsZElOUzJfM2xhczEwZXh0cmFieXRlc0VOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRV9FRUVFRUVFRQBONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlNfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzBfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzBfNWZpZWxkSU5TMF8zbGFzN3BvaW50MTBFTlMwXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0RfRUVFRUVFRUVFAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0ZfRUVFRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTS19FRU5TXzlhbGxvY2F0b3JJU0tfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0ZfRUVFRUVFRUVFRUUATjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOU18yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOU183c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMwXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMwXzVmaWVsZElOUzBfM2xhczdwb2ludDEwRU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNEX0VFRUVOU0JfSU5TQ183Z3BzdGltZUVOU0VfSVNIX0VFRUVFRUVFRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV83Z3BzdGltZUVOU0dfSVNKX0VFRUVFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU05fRUVOU185YWxsb2NhdG9ySVNOX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV83Z3BzdGltZUVOU0dfSVNKX0VFRUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyMWR5bmFtaWNfZGVjb21wcmVzc29yMUlOU184ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlNfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlNfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMF8xOXJlY29yZF9kZWNvbXByZXNzb3JJSk5TMF81ZmllbGRJTlMwXzNsYXM3cG9pbnQxMEVOUzBfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRF9FRUVFTlNCX0lOU0NfM3JnYkVOU0VfSVNIX0VFRUVFRUVFRQBOU3QzX18yMjBfX3NoYXJlZF9wdHJfcG9pbnRlcklQTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV8zcmdiRU5TR19JU0pfRUVFRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTTl9FRU5TXzlhbGxvY2F0b3JJU05fRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlMxXzhkZWNvZGVyczEwYXJpdGhtZXRpY0lOUzFfMmlvMThfX2lmc3RyZWFtX3dyYXBwZXJJTlMxXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzJfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzJfNWZpZWxkSU5TMl8zbGFzN3BvaW50MTBFTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0ZfRUVFRU5TRF9JTlNFXzNyZ2JFTlNHX0lTSl9FRUVFRUVFRUVFRQBONmxhc3ppcDdmb3JtYXRzMjFkeW5hbWljX2RlY29tcHJlc3NvcjFJTlNfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TXzdzdHJlYW1zMTNtZW1vcnlfc3RyZWFtRUVFRUVOUzBfMTlyZWNvcmRfZGVjb21wcmVzc29ySUpOUzBfNWZpZWxkSU5TMF8zbGFzN3BvaW50MTBFTlMwXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJU0RfRUVFRU5TQl9JTlNDXzdncHN0aW1lRU5TRV9JU0hfRUVFRU5TQl9JTlNDXzNyZ2JFTlNFX0lTS19FRUVFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyMWR5bmFtaWNfZGVjb21wcmVzc29yMUlOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSU5TMV8yaW8xOF9faWZzdHJlYW1fd3JhcHBlcklOUzFfN3N0cmVhbXMxM21lbW9yeV9zdHJlYW1FRUVFRU5TMl8xOXJlY29yZF9kZWNvbXByZXNzb3JJSk5TMl81ZmllbGRJTlMyXzNsYXM3cG9pbnQxMEVOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElTRl9FRUVFTlNEX0lOU0VfN2dwc3RpbWVFTlNHX0lTSl9FRUVFTlNEX0lOU0VfM3JnYkVOU0dfSVNNX0VFRUVFRUVFRU5TXzE0ZGVmYXVsdF9kZWxldGVJU1FfRUVOU185YWxsb2NhdG9ySVNRX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJTjZsYXN6aXA3Zm9ybWF0czIxZHluYW1pY19kZWNvbXByZXNzb3IxSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJTlMxXzJpbzE4X19pZnN0cmVhbV93cmFwcGVySU5TMV83c3RyZWFtczEzbWVtb3J5X3N0cmVhbUVFRUVFTlMyXzE5cmVjb3JkX2RlY29tcHJlc3NvcklKTlMyXzVmaWVsZElOUzJfM2xhczdwb2ludDEwRU5TMl8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSVNGX0VFRUVOU0RfSU5TRV83Z3BzdGltZUVOU0dfSVNKX0VFRUVOU0RfSU5TRV8zcmdiRU5TR19JU01fRUVFRUVFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUDEwYnVmX3N0cmVhbU5TXzE0ZGVmYXVsdF9kZWxldGVJUzFfRUVOU185YWxsb2NhdG9ySVMxX0VFRUUATlN0M19fMjE0ZGVmYXVsdF9kZWxldGVJMTBidWZfc3RyZWFtRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTNV9FRU5TXzlhbGxvY2F0b3JJUzVfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZmllbGRfZGVjb21wcmVzc29ySU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRUVFAE5TdDNfXzIyMF9fc2hhcmVkX3B0cl9wb2ludGVySVBONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2ZpZWxkX2RlY29tcHJlc3NvcklOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFRUVOU18xNGRlZmF1bHRfZGVsZXRlSVM4X0VFTlNfOWFsbG9jYXRvcklTOF9FRUVFAE5TdDNfXzIxNGRlZmF1bHRfZGVsZXRlSU42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZmllbGRfZGVjb21wcmVzc29ySU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJaU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWlFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWlOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElpRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElpTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJaUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJak5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWpFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWpOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElqRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElqTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJakVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJYU5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWFFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWFOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElhRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElhTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJYUVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJc05TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSXNFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSXNOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZElzRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZElzTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJc0VFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJaE5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSWhFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSWhOUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZEloRUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZEloTlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJaEVFRUVFRUVFAE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TXzhkZWNvZGVyczEwYXJpdGhtZXRpY0kxMGJ1Zl9zdHJlYW1FRU5TMF81ZmllbGRJdE5TMF8yMHN0YW5kYXJkX2RpZmZfbWV0aG9kSXRFRUVFRUUATlN0M19fMjIwX19zaGFyZWRfcHRyX3BvaW50ZXJJUE42bGFzemlwN2Zvcm1hdHMyNmR5bmFtaWNfZGVjb21wcmVzc29yX2ZpZWxkSU5TMV84ZGVjb2RlcnMxMGFyaXRobWV0aWNJMTBidWZfc3RyZWFtRUVOUzJfNWZpZWxkSXROUzJfMjBzdGFuZGFyZF9kaWZmX21ldGhvZEl0RUVFRUVFTlNfMTRkZWZhdWx0X2RlbGV0ZUlTQ19FRU5TXzlhbGxvY2F0b3JJU0NfRUVFRQBOU3QzX18yMTRkZWZhdWx0X2RlbGV0ZUlONmxhc3ppcDdmb3JtYXRzMjZkeW5hbWljX2RlY29tcHJlc3Nvcl9maWVsZElOUzFfOGRlY29kZXJzMTBhcml0aG1ldGljSTEwYnVmX3N0cmVhbUVFTlMyXzVmaWVsZEl0TlMyXzIwc3RhbmRhcmRfZGlmZl9tZXRob2RJdEVFRUVFRUVFADZMQVNaaXAAUDZMQVNaaXAAUEs2TEFTWmlwAGlpAHYAdmkAdmlpaWkAdmlpaQBpaWkAMTNEeW5hbWljTEFTWmlwAFAxM0R5bmFtaWNMQVNaaXAAUEsxM0R5bmFtaWNMQVNaaXAAdm9pZABib29sAGNoYXIAc2lnbmVkIGNoYXIAdW5zaWduZWQgY2hhcgBzaG9ydAB1bnNpZ25lZCBzaG9ydABpbnQAdW5zaWduZWQgaW50AGxvbmcAdW5zaWduZWQgbG9uZwBmbG9hdABkb3VibGUAc3RkOjpzdHJpbmcAc3RkOjpiYXNpY19zdHJpbmc8dW5zaWduZWQgY2hhcj4Ac3RkOjp3c3RyaW5nAHN0ZDo6dTE2c3RyaW5nAHN0ZDo6dTMyc3RyaW5nAGVtc2NyaXB0ZW46OnZhbABlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxjaGFyPgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxzaWduZWQgY2hhcj4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8dW5zaWduZWQgY2hhcj4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8c2hvcnQ+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PHVuc2lnbmVkIHNob3J0PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxpbnQ+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PHVuc2lnbmVkIGludD4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8bG9uZz4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8dW5zaWduZWQgbG9uZz4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8aW50OF90PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzx1aW50OF90PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxpbnQxNl90PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzx1aW50MTZfdD4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8aW50MzJfdD4AZW1zY3JpcHRlbjo6bWVtb3J5X3ZpZXc8dWludDMyX3Q+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PGZsb2F0PgBlbXNjcmlwdGVuOjptZW1vcnlfdmlldzxkb3VibGU+AGVtc2NyaXB0ZW46Om1lbW9yeV92aWV3PGxvbmcgZG91YmxlPgBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0llRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJZEVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SWZFRQBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0ltRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJbEVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SWpFRQBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0lpRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJdEVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SXNFRQBOMTBlbXNjcmlwdGVuMTFtZW1vcnlfdmlld0loRUUATjEwZW1zY3JpcHRlbjExbWVtb3J5X3ZpZXdJYUVFAE4xMGVtc2NyaXB0ZW4xMW1lbW9yeV92aWV3SWNFRQBOMTBlbXNjcmlwdGVuM3ZhbEUATlN0M19fMjEyYmFzaWNfc3RyaW5nSURpTlNfMTFjaGFyX3RyYWl0c0lEaUVFTlNfOWFsbG9jYXRvcklEaUVFRUUATlN0M19fMjIxX19iYXNpY19zdHJpbmdfY29tbW9uSUxiMUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJRHNOU18xMWNoYXJfdHJhaXRzSURzRUVOU185YWxsb2NhdG9ySURzRUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJd05TXzExY2hhcl90cmFpdHNJd0VFTlNfOWFsbG9jYXRvckl3RUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJaE5TXzExY2hhcl90cmFpdHNJaEVFTlNfOWFsbG9jYXRvckloRUVFRQBOU3QzX18yMTJiYXNpY19zdHJpbmdJY05TXzExY2hhcl90cmFpdHNJY0VFTlNfOWFsbG9jYXRvckljRUVFRQAtKyAgIDBYMHgAKG51bGwpAC0wWCswWCAwWC0weCsweCAweABpbmYASU5GAG5hbgBOQU4ALgB0ZXJtaW5hdGluZyB3aXRoICVzIGV4Y2VwdGlvbiBvZiB0eXBlICVzOiAlcwB0ZXJtaW5hdGluZyB3aXRoICVzIGV4Y2VwdGlvbiBvZiB0eXBlICVzAHRlcm1pbmF0aW5nIHdpdGggJXMgZm9yZWlnbiBleGNlcHRpb24AdGVybWluYXRpbmcAdW5jYXVnaHQAU3Q5ZXhjZXB0aW9uAE4xMF9fY3h4YWJpdjExNl9fc2hpbV90eXBlX2luZm9FAFN0OXR5cGVfaW5mbwBOMTBfX2N4eGFiaXYxMjBfX3NpX2NsYXNzX3R5cGVfaW5mb0UATjEwX19jeHhhYml2MTE3X19jbGFzc190eXBlX2luZm9FAHRlcm1pbmF0ZV9oYW5kbGVyIHVuZXhwZWN0ZWRseSByZXR1cm5lZABzdGQ6OmJhZF9hbGxvYwBTdDliYWRfYWxsb2MAU3QxMWxvZ2ljX2Vycm9yAFN0MTNydW50aW1lX2Vycm9yAFN0MTJsZW5ndGhfZXJyb3IAU3QxMm91dF9vZl9yYW5nZQBOMTBfX2N4eGFiaXYxMTdfX3BiYXNlX3R5cGVfaW5mb0UATjEwX19jeHhhYml2MTE5X19wb2ludGVyX3R5cGVfaW5mb0UATjEwX19jeHhhYml2MTIwX19mdW5jdGlvbl90eXBlX2luZm9FAE4xMF9fY3h4YWJpdjEyOV9fcG9pbnRlcl90b19tZW1iZXJfdHlwZV9pbmZvRQBQdXJlIHZpcnR1YWwgZnVuY3Rpb24gY2FsbGVkIQBOMTBfX2N4eGFiaXYxMjNfX2Z1bmRhbWVudGFsX3R5cGVfaW5mb0UAdgBEbgBiAGMAaABhAHMAdABpAGoAbABtAGYAZABOMTBfX2N4eGFiaXYxMjFfX3ZtaV9jbGFzc190eXBlX2luZm9FAF9fY3hhX2d1YXJkX2FjcXVpcmUgZGV0ZWN0ZWQgcmVjdXJzaXZlIGluaXRpYWxpemF0aW9uAHN0ZDo6YmFkX2Z1bmN0aW9uX2NhbGwATlN0M19fMjE3YmFkX2Z1bmN0aW9uX2NhbGxFAE5TdDNfXzIxNF9fc2hhcmVkX2NvdW50RQBOU3QzX18yMTlfX3NoYXJlZF93ZWFrX2NvdW50RQBtdXRleCBsb2NrIGZhaWxlZABiYXNpY19zdHJpbmcAdW5zcGVjaWZpZWQgZ2VuZXJpY19jYXRlZ29yeSBlcnJvcgBVbmtub3duIGVycm9yICVkAGdlbmVyaWMATlN0M19fMjI0X19nZW5lcmljX2Vycm9yX2NhdGVnb3J5RQBOU3QzX18yMTJfX2RvX21lc3NhZ2VFAE5TdDNfXzIxNGVycm9yX2NhdGVnb3J5RQB1bnNwZWNpZmllZCBzeXN0ZW1fY2F0ZWdvcnkgZXJyb3IAc3lzdGVtAE5TdDNfXzIyM19fc3lzdGVtX2Vycm9yX2NhdGVnb3J5RQBOU3QzX18yMTJzeXN0ZW1fZXJyb3JFADogAHZlY3Rvcg==";var Z={};function J(e){e&&Z[e].refcount++}function Y(e){if(!e||Z[e])return e;for(var t in Z)for(var s=+t,i=Z[s].adjusted,r=i.length,n=0;n<r;n++)if(i[n]===e)return s;return e}function $(e){switch(e){case 1:return 0;case 2:return 1;case 4:return 2;case 8:return 3;default:throw new TypeError("Unknown type size: "+e)}}var q=void 0;function ee(e){for(var t="",s=e;w[s];)t+=q[w[s++]];return t}var te={},se={},ie={};function re(e){if(void 0===e)return"_unknown";var t=(e=e.replace(/[^a-zA-Z0-9_]/g,"$")).charCodeAt(0);return t>=48&&t<=57?"_"+e:e}function ne(e,t){return e=re(e),new Function("body","return function "+e+'() {\n "use strict"; return body.apply(this, arguments);\n};\n')(t)}function Ae(e,t){var s=ne(t,(function(e){this.name=t,this.message=e;var s=new Error(e).stack;void 0!==s&&(this.stack=this.toString()+"\n"+s.replace(/^Error(:[^\n]*)?\n/,""))}));return s.prototype=Object.create(e.prototype),s.prototype.constructor=s,s.prototype.toString=function(){return void 0===this.message?this.name:this.name+": "+this.message},s}var oe=void 0;function ae(e){throw new oe(e)}var le=void 0;function ce(e){throw new le(e)}function he(e,t,s){function i(t){var i=s(t);i.length!==e.length&&ce("Mismatched type converter count");for(var r=0;r<e.length;++r)ue(e[r],i[r])}e.forEach((function(e){ie[e]=t}));var r=new Array(t.length),n=[],A=0;t.forEach((function(e,t){se.hasOwnProperty(e)?r[t]=se[e]:(n.push(e),te.hasOwnProperty(e)||(te[e]=[]),te[e].push((function(){r[t]=se[e],++A===n.length&&i(r)})))})),0===n.length&&i(r)}function ue(e,t,s){if(s=s||{},!("argPackAdvance"in t))throw new TypeError("registerType registeredInstance requires argPackAdvance");var i=t.name;if(e||ae('type "'+i+'" must have a positive integer typeid pointer'),se.hasOwnProperty(e)){if(s.ignoreDuplicateRegistrations)return;ae("Cannot register type '"+i+"' twice")}if(se[e]=t,delete ie[e],te.hasOwnProperty(e)){var r=te[e];delete te[e],r.forEach((function(e){e()}))}}function de(e){if(!(this instanceof Ee))return!1;if(!(e instanceof Ee))return!1;for(var t=this.$$.ptrType.registeredClass,s=this.$$.ptr,i=e.$$.ptrType.registeredClass,r=e.$$.ptr;t.baseClass;)s=t.upcast(s),t=t.baseClass;for(;i.baseClass;)r=i.upcast(r),i=i.baseClass;return t===i&&s===r}function pe(e){ae(e.$$.ptrType.registeredClass.name+" instance already deleted")}var fe=!1;function ge(e){}function me(e){e.count.value-=1,0===e.count.value&&function(e){e.smartPtr?e.smartPtrType.rawDestructor(e.smartPtr):e.ptrType.registeredClass.rawDestructor(e.ptr)}(e)}function _e(e){return"undefined"==typeof FinalizationGroup?(_e=function(e){return e},e):(fe=new FinalizationGroup((function(e){for(var t=e.next();!t.done;t=e.next()){var s=t.value;s.ptr?me(s):console.warn("object already deleted: "+s.ptr)}})),_e=function(e){return fe.register(e,e.$$,e.$$),e},ge=function(e){fe.unregister(e.$$)},_e(e))}function be(){if(this.$$.ptr||pe(this),this.$$.preservePointerOnDelete)return this.$$.count.value+=1,this;var e,t=_e(Object.create(Object.getPrototypeOf(this),{$$:{value:(e=this.$$,{count:e.count,deleteScheduled:e.deleteScheduled,preservePointerOnDelete:e.preservePointerOnDelete,ptr:e.ptr,ptrType:e.ptrType,smartPtr:e.smartPtr,smartPtrType:e.smartPtrType})}}));return t.$$.count.value+=1,t.$$.deleteScheduled=!1,t}function ye(){this.$$.ptr||pe(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&ae("Object already scheduled for deletion"),ge(this),me(this.$$),this.$$.preservePointerOnDelete||(this.$$.smartPtr=void 0,this.$$.ptr=void 0)}function Be(){return!this.$$.ptr}var we=void 0,ve=[];function Ce(){for(;ve.length;){var e=ve.pop();e.$$.deleteScheduled=!1,e.delete()}}function Me(){return this.$$.ptr||pe(this),this.$$.deleteScheduled&&!this.$$.preservePointerOnDelete&&ae("Object already scheduled for deletion"),ve.push(this),1===ve.length&&we&&we(Ce),this.$$.deleteScheduled=!0,this}function Ee(){}var Fe={};function xe(e,t,s){if(void 0===e[t].overloadTable){var i=e[t];e[t]=function(){return e[t].overloadTable.hasOwnProperty(arguments.length)||ae("Function '"+s+"' called with an invalid number of arguments ("+arguments.length+") - expects one of ("+e[t].overloadTable+")!"),e[t].overloadTable[arguments.length].apply(this,arguments)},e[t].overloadTable=[],e[t].overloadTable[i.argCount]=i}}function Ue(e,t,s,i,r,n,A,o){this.name=e,this.constructor=t,this.instancePrototype=s,this.rawDestructor=i,this.baseClass=r,this.getActualType=n,this.upcast=A,this.downcast=o,this.pureVirtualFunctions=[]}function Ie(e,t,s){for(;t!==s;)t.upcast||ae("Expected null or instance of "+s.name+", got an instance of "+t.name),e=t.upcast(e),t=t.baseClass;return e}function Te(e,t){if(null===t)return this.isReference&&ae("null is not a valid "+this.name),0;t.$$||ae('Cannot pass "'+At(t)+'" as a '+this.name),t.$$.ptr||ae("Cannot pass deleted object as a pointer of type "+this.name);var s=t.$$.ptrType.registeredClass;return Ie(t.$$.ptr,s,this.registeredClass)}function Pe(e,t){var s;if(null===t)return this.isReference&&ae("null is not a valid "+this.name),this.isSmartPointer?(s=this.rawConstructor(),null!==e&&e.push(this.rawDestructor,s),s):0;t.$$||ae('Cannot pass "'+At(t)+'" as a '+this.name),t.$$.ptr||ae("Cannot pass deleted object as a pointer of type "+this.name),!this.isConst&&t.$$.ptrType.isConst&&ae("Cannot convert argument of type "+(t.$$.smartPtrType?t.$$.smartPtrType.name:t.$$.ptrType.name)+" to parameter type "+this.name);var i=t.$$.ptrType.registeredClass;if(s=Ie(t.$$.ptr,i,this.registeredClass),this.isSmartPointer)switch(void 0===t.$$.smartPtr&&ae("Passing raw pointer to smart pointer is illegal"),this.sharingPolicy){case 0:t.$$.smartPtrType===this?s=t.$$.smartPtr:ae("Cannot convert argument of type "+(t.$$.smartPtrType?t.$$.smartPtrType.name:t.$$.ptrType.name)+" to parameter type "+this.name);break;case 1:s=t.$$.smartPtr;break;case 2:if(t.$$.smartPtrType===this)s=t.$$.smartPtr;else{var r=t.clone();s=this.rawShare(s,nt((function(){r.delete()}))),null!==e&&e.push(this.rawDestructor,s)}break;default:ae("Unsupporting sharing policy")}return s}function Se(e,t){if(null===t)return this.isReference&&ae("null is not a valid "+this.name),0;t.$$||ae('Cannot pass "'+At(t)+'" as a '+this.name),t.$$.ptr||ae("Cannot pass deleted object as a pointer of type "+this.name),t.$$.ptrType.isConst&&ae("Cannot convert argument of type "+t.$$.ptrType.name+" to parameter type "+this.name);var s=t.$$.ptrType.registeredClass;return Ie(t.$$.ptr,s,this.registeredClass)}function De(e){return this.fromWireType(E[e>>2])}function ke(e){return this.rawGetPointee&&(e=this.rawGetPointee(e)),e}function Qe(e){this.rawDestructor&&this.rawDestructor(e)}function Re(e){null!==e&&e.delete()}function Oe(e,t,s){if(t===s)return e;if(void 0===s.baseClass)return null;var i=Oe(e,t,s.baseClass);return null===i?null:s.downcast(i)}function Ve(){return Object.keys(Ne).length}function Le(){var e=[];for(var t in Ne)Ne.hasOwnProperty(t)&&e.push(Ne[t]);return e}function He(e){we=e,ve.length&&we&&we(Ce)}var Ne={};function Ge(e,t){return t=function(e,t){for(void 0===t&&ae("ptr should not be undefined");e.baseClass;)t=e.upcast(t),e=e.baseClass;return t}(e,t),Ne[t]}function je(e,t){return t.ptrType&&t.ptr||ce("makeClassHandle requires ptr and ptrType"),!!t.smartPtrType!==!!t.smartPtr&&ce("Both smartPtrType and smartPtr must be specified"),t.count={value:1},_e(Object.create(e,{$$:{value:t}}))}function ze(e){var t=this.getPointee(e);if(!t)return this.destructor(e),null;var s=Ge(this.registeredClass,t);if(void 0!==s){if(0===s.$$.count.value)return s.$$.ptr=t,s.$$.smartPtr=e,s.clone();var i=s.clone();return this.destructor(e),i}function r(){return this.isSmartPointer?je(this.registeredClass.instancePrototype,{ptrType:this.pointeeType,ptr:t,smartPtrType:this,smartPtr:e}):je(this.registeredClass.instancePrototype,{ptrType:this,ptr:e})}var n,A=this.registeredClass.getActualType(t),o=Fe[A];if(!o)return r.call(this);n=this.isConst?o.constPointerType:o.pointerType;var a=Oe(t,this.registeredClass,n.registeredClass);return null===a?r.call(this):this.isSmartPointer?je(n.registeredClass.instancePrototype,{ptrType:n,ptr:a,smartPtrType:this,smartPtr:e}):je(n.registeredClass.instancePrototype,{ptrType:n,ptr:a})}function We(e,t,s,i,r,n,A,o,a,l,c){this.name=e,this.registeredClass=t,this.isReference=s,this.isConst=i,this.isSmartPointer=r,this.pointeeType=n,this.sharingPolicy=A,this.rawGetPointee=o,this.rawConstructor=a,this.rawShare=l,this.rawDestructor=c,r||void 0!==t.baseClass?this.toWireType=Pe:i?(this.toWireType=Te,this.destructorFunction=null):(this.toWireType=Se,this.destructorFunction=null)}function Xe(e,s){e=ee(e);var i=function(t){for(var i=[],r=1;r<e.length;++r)i.push("a"+r);var n="return function "+("dynCall_"+e+"_"+s)+"("+i.join(", ")+") {\n";return n+=" return dynCall(rawFunction"+(i.length?", ":"")+i.join(", ")+");\n",n+="};\n",new Function("dynCall","rawFunction",n)(t,s)}(t["dynCall_"+e]);return"function"!=typeof i&&ae("unknown function pointer with signature "+e+": "+s),i}var Ke=void 0;function Ze(e){var t=ft(e),s=ee(t);return gt(t),s}function Je(e,t){var s=[],i={};throw t.forEach((function e(t){i[t]||se[t]||(ie[t]?ie[t].forEach(e):(s.push(t),i[t]=!0))})),new Ke(e+": "+s.map(Ze).join([", "]))}function Ye(e,t){for(var s=[],i=0;i<e;i++)s.push(M[(t>>2)+i]);return s}function $e(e){for(;e.length;){var t=e.pop();e.pop()(t)}}function qe(e,t,s,i,r){var n=t.length;n<2&&ae("argTypes array size mismatch! Must at least get return value and 'this' types!");for(var A=null!==t[1]&&null!==s,o=!1,a=1;a<t.length;++a)if(null!==t[a]&&void 0===t[a].destructorFunction){o=!0;break}var l="void"!==t[0].name,c="",h="";for(a=0;a<n-2;++a)c+=(0!==a?", ":"")+"arg"+a,h+=(0!==a?", ":"")+"arg"+a+"Wired";var u="return function "+re(e)+"("+c+") {\nif (arguments.length !== "+(n-2)+") {\nthrowBindingError('function "+e+" called with ' + arguments.length + ' arguments, expected "+(n-2)+" args!');\n}\n";o&&(u+="var destructors = [];\n");var d=o?"destructors":"null",p=["throwBindingError","invoker","fn","runDestructors","retType","classParam"],f=[ae,i,r,$e,t[0],t[1]];A&&(u+="var thisWired = classParam.toWireType("+d+", this);\n");for(a=0;a<n-2;++a)u+="var arg"+a+"Wired = argType"+a+".toWireType("+d+", arg"+a+"); // "+t[a+2].name+"\n",p.push("argType"+a),f.push(t[a+2]);if(A&&(h="thisWired"+(h.length>0?", ":"")+h),u+=(l?"var rv = ":"")+"invoker(fn"+(h.length>0?", ":"")+h+");\n",o)u+="runDestructors(destructors);\n";else for(a=A?1:2;a<t.length;++a){var g=1===a?"thisWired":"arg"+(a-2)+"Wired";null!==t[a].destructorFunction&&(u+=g+"_dtor("+g+"); // "+t[a].name+"\n",p.push(g+"_dtor"),f.push(t[a].destructorFunction))}return l&&(u+="var ret = retType.fromWireType(rv);\nreturn ret;\n"),u+="}\n",p.push(u),function(e,t){if(!(e instanceof Function))throw new TypeError("new_ called with constructor type "+typeof e+" which is not a function");var s=ne(e.name||"unknownFunctionName",(function(){}));s.prototype=e.prototype;var i=new s,r=e.apply(i,t);return r instanceof Object?r:i}(Function,p).apply(null,f)}var et=[],tt=[{},{value:void 0},{value:null},{value:!0},{value:!1}];function st(e){e>4&&0==--tt[e].refcount&&(tt[e]=void 0,et.push(e))}function it(){for(var e=0,t=5;t<tt.length;++t)void 0!==tt[t]&&++e;return e}function rt(){for(var e=5;e<tt.length;++e)if(void 0!==tt[e])return tt[e];return null}function nt(e){switch(e){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:var t=et.length?et.pop():tt.length;return tt[t]={refcount:1,value:e},t}}function At(e){if(null===e)return"null";var t=typeof e;return"object"===t||"array"===t||"function"===t?e.toString():""+e}function ot(e,t){switch(t){case 2:return function(e){return this.fromWireType(F[e>>2])};case 3:return function(e){return this.fromWireType(x[e>>3])};default:throw new TypeError("Unknown float type: "+e)}}function at(e,t,s){switch(t){case 0:return s?function(e){return B[e]}:function(e){return w[e]};case 1:return s?function(e){return v[e>>1]}:function(e){return C[e>>1]};case 2:return s?function(e){return M[e>>2]}:function(e){return E[e>>2]};default:throw new TypeError("Unknown integer type: "+e)}}function lt(e){for(var t=[],s=0;s<e.length;s++){var i=e[s];i>255&&(i&=255),t.push(String.fromCharCode(i))}return t.join("")}!function(){for(var e=new Array(256),t=0;t<256;++t)e[t]=String.fromCharCode(t);q=e}(),oe=t.BindingError=Ae(Error,"BindingError"),le=t.InternalError=Ae(Error,"InternalError"),Ee.prototype.isAliasOf=de,Ee.prototype.clone=be,Ee.prototype.delete=ye,Ee.prototype.isDeleted=Be,Ee.prototype.deleteLater=Me,We.prototype.getPointee=ke,We.prototype.destructor=Qe,We.prototype.argPackAdvance=8,We.prototype.readValueFromPointer=De,We.prototype.deleteObject=Re,We.prototype.fromWireType=ze,t.getInheritedInstanceCount=Ve,t.getLiveInheritedInstances=Le,t.flushPendingDeletes=Ce,t.setDelayFunction=He,Ke=t.UnboundTypeError=Ae(Error,"UnboundTypeError"),t.count_emval_handles=it,t.get_first_emval=rt;var ct="function"==typeof atob?atob:function(e){var t,s,i,r,n,A,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",a="",l=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{t=o.indexOf(e.charAt(l++))<<2|(r=o.indexOf(e.charAt(l++)))>>4,s=(15&r)<<4|(n=o.indexOf(e.charAt(l++)))>>2,i=(3&n)<<6|(A=o.indexOf(e.charAt(l++))),a+=String.fromCharCode(t),64!==n&&(a+=String.fromCharCode(s)),64!==A&&(a+=String.fromCharCode(i))}while(l<e.length);return a};function ht(e){if(K(e))return function(e){if("boolean"==typeof n&&n){var t;try{t=Buffer.from(e,"base64")}catch(s){t=new Buffer(e,"base64")}return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}try{for(var s=ct(e),i=new Uint8Array(s.length),r=0;r<s.length;++r)i[r]=s.charCodeAt(r);return i}catch(e){throw new Error("Converting base64 string to bytes failed.")}}(e.slice(X.length))}var ut={A:function(e,t,s){w.copyWithin(e,t,t+s)},B:function(e){z("OOM")},C:function(){z("trap!")},D:22368,a:z,b:function(e){f=e},c:function(){return f},d:function(e){return mt(e)},e:function(e){var t=Z[e];return t&&!t.caught&&(t.caught=!0,pt.uncaught_exceptions--),t&&(t.rethrown=!1),J(Y(e)),e},f:function(e,t,s){throw Z[e]={ptr:e,adjusted:[e],type:t,destructor:s,refcount:0,caught:!1,rethrown:!1},"uncaught_exception"in pt?pt.uncaught_exceptions++:pt.uncaught_exceptions=1,e},g:function(){return pt.uncaught_exceptions},h:J,i:Y,j:function(){},k:function(e,t,s,i,r){var n=$(s);ue(e,{name:t=ee(t),fromWireType:function(e){return!!e},toWireType:function(e,t){return t?i:r},argPackAdvance:8,readValueFromPointer:function(e){var i;if(1===s)i=B;else if(2===s)i=v;else{if(4!==s)throw new TypeError("Unknown boolean type size: "+t);i=M}return this.fromWireType(i[e>>n])},destructorFunction:null})},l:function(e,s,i,r,n,A,o,a,l,c,h,u,d){h=ee(h),A=Xe(n,A),a&&(a=Xe(o,a)),c&&(c=Xe(l,c)),d=Xe(u,d);var p=re(h);!function(e,s,i){t.hasOwnProperty(e)?((void 0===i||void 0!==t[e].overloadTable&&void 0!==t[e].overloadTable[i])&&ae("Cannot register public name '"+e+"' twice"),xe(t,e,e),t.hasOwnProperty(i)&&ae("Cannot register multiple overloads of a function with the same number of arguments ("+i+")!"),t[e].overloadTable[i]=s):(t[e]=s,void 0!==i&&(t[e].numArguments=i))}(p,(function(){Je("Cannot construct "+h+" due to unbound types",[r])})),he([e,s,i],r?[r]:[],(function(s){var i,n;s=s[0],n=r?(i=s.registeredClass).instancePrototype:Ee.prototype;var o=ne(p,(function(){if(Object.getPrototypeOf(this)!==l)throw new oe("Use 'new' to construct "+h);if(void 0===u.constructor_body)throw new oe(h+" has no accessible constructor");var e=u.constructor_body[arguments.length];if(void 0===e)throw new oe("Tried to invoke ctor of "+h+" with invalid number of parameters ("+arguments.length+") - expected ("+Object.keys(u.constructor_body).toString()+") parameters instead!");return e.apply(this,arguments)})),l=Object.create(n,{constructor:{value:o}});o.prototype=l;var u=new Ue(h,o,l,d,i,A,a,c),f=new We(h,u,!0,!1,!1),g=new We(h+"*",u,!1,!1,!1),m=new We(h+" const*",u,!1,!0,!1);return Fe[e]={pointerType:g,constPointerType:m},function(e,s,i){t.hasOwnProperty(e)||ce("Replacing nonexistant public symbol"),void 0!==t[e].overloadTable&&void 0!==i?t[e].overloadTable[i]=s:(t[e]=s,t[e].argCount=i)}(p,o),[f,g,m]}))},m:function(e,t,s,i,r,n){m(t>0);var A=Ye(t,s);r=Xe(i,r);var o=[n],a=[];he([],[e],(function(e){var s="constructor "+(e=e[0]).name;if(void 0===e.registeredClass.constructor_body&&(e.registeredClass.constructor_body=[]),void 0!==e.registeredClass.constructor_body[t-1])throw new oe("Cannot register multiple constructors with identical number of parameters ("+(t-1)+") for class '"+e.name+"'! Overload resolution is currently only performed using the parameter count, not actual type info!");return e.registeredClass.constructor_body[t-1]=function(){Je("Cannot construct "+e.name+" due to unbound types",A)},he([],A,(function(i){return e.registeredClass.constructor_body[t-1]=function(){arguments.length!==t-1&&ae(s+" called with "+arguments.length+" arguments, expected "+(t-1)),a.length=0,o.length=t;for(var e=1;e<t;++e)o[e]=i[e].toWireType(a,arguments[e-1]);var n=r.apply(null,o);return $e(a),i[0].fromWireType(n)},[]})),[]}))},n:function(e,t,s,i,r,n,A,o){var a=Ye(s,i);t=ee(t),n=Xe(r,n),he([],[e],(function(e){var i=(e=e[0]).name+"."+t;function r(){Je("Cannot call "+i+" due to unbound types",a)}o&&e.registeredClass.pureVirtualFunctions.push(t);var l=e.registeredClass.instancePrototype,c=l[t];return void 0===c||void 0===c.overloadTable&&c.className!==e.name&&c.argCount===s-2?(r.argCount=s-2,r.className=e.name,l[t]=r):(xe(l,t,i),l[t].overloadTable[s-2]=r),he([],a,(function(r){var o=qe(i,r,e,n,A);return void 0===l[t].overloadTable?(o.argCount=s-2,l[t]=o):l[t].overloadTable[s-2]=o,[]})),[]}))},o:function(e,t){ue(e,{name:t=ee(t),fromWireType:function(e){var t=tt[e].value;return st(e),t},toWireType:function(e,t){return nt(t)},argPackAdvance:8,readValueFromPointer:De,destructorFunction:null})},p:function(e,t,s){var i=$(s);ue(e,{name:t=ee(t),fromWireType:function(e){return e},toWireType:function(e,t){if("number"!=typeof t&&"boolean"!=typeof t)throw new TypeError('Cannot convert "'+At(t)+'" to '+this.name);return t},argPackAdvance:8,readValueFromPointer:ot(t,i),destructorFunction:null})},q:function(e,t,s,i,r){t=ee(t),-1===r&&(r=4294967295);var n=$(s),A=function(e){return e};if(0===i){var o=32-8*s;A=function(e){return e<<o>>>o}}var a=-1!=t.indexOf("unsigned");ue(e,{name:t,fromWireType:A,toWireType:function(e,s){if("number"!=typeof s&&"boolean"!=typeof s)throw new TypeError('Cannot convert "'+At(s)+'" to '+this.name);if(s<i||s>r)throw new TypeError('Passing a number "'+At(s)+'" from JS side to C/C++ side to an argument of type "'+t+'", which is outside the valid range ['+i+", "+r+"]!");return a?s>>>0:0|s},argPackAdvance:8,readValueFromPointer:at(t,n,0!==i),destructorFunction:null})},r:function(e,t,s){var i=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][t];function r(e){var t=E,s=t[e>>=2],r=t[e+1];return new i(y,r,s)}ue(e,{name:s=ee(s),fromWireType:r,argPackAdvance:8,readValueFromPointer:r},{ignoreDuplicateRegistrations:!0})},s:function(e,t){var s="std::string"===(t=ee(t));ue(e,{name:t,fromWireType:function(e){var t,i=E[e>>2];if(s)for(var r=e+4,n=0;n<=i;++n){var A=e+4+n;if(0==w[A]||n==i){var o=b(r,A-r);void 0===t?t=o:(t+=String.fromCharCode(0),t+=o),r=A+1}}else{var a=new Array(i);for(n=0;n<i;++n)a[n]=String.fromCharCode(w[e+4+n]);t=a.join("")}return gt(e),t},toWireType:function(e,t){var i;t instanceof ArrayBuffer&&(t=new Uint8Array(t));var r="string"==typeof t;r||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int8Array||ae("Cannot pass non-string to std::string"),i=s&&r?function(){return function(e){for(var t=0,s=0;s<e.length;++s){var i=e.charCodeAt(s);i>=55296&&i<=57343&&(i=65536+((1023&i)<<10)|1023&e.charCodeAt(++s)),i<=127?++t:t+=i<=2047?2:i<=65535?3:4}return t}(t)}:function(){return t.length};var n=i(),A=mt(4+n+1);if(E[A>>2]=n,s&&r)(function(e,t,s,i){if(!(i>0))return 0;for(var r=s,n=s+i-1,A=0;A<e.length;++A){var o=e.charCodeAt(A);if(o>=55296&&o<=57343&&(o=65536+((1023&o)<<10)|1023&e.charCodeAt(++A)),o<=127){if(s>=n)break;t[s++]=o}else if(o<=2047){if(s+1>=n)break;t[s++]=192|o>>6,t[s++]=128|63&o}else if(o<=65535){if(s+2>=n)break;t[s++]=224|o>>12,t[s++]=128|o>>6&63,t[s++]=128|63&o}else{if(s+3>=n)break;t[s++]=240|o>>18,t[s++]=128|o>>12&63,t[s++]=128|o>>6&63,t[s++]=128|63&o}}t[s]=0})(t,w,A+4,n+1);else if(r)for(var o=0;o<n;++o){var a=t.charCodeAt(o);a>255&&(gt(A),ae("String has UTF-16 code units that do not fit in 8 bits")),w[A+4+o]=a}else for(o=0;o<n;++o)w[A+4+o]=t[o];return null!==e&&e.push(gt,A),A},argPackAdvance:8,readValueFromPointer:De,destructorFunction:function(e){gt(e)}})},t:function(e,t,s){var i,r,n,A,o;s=ee(s),2===t?(i=I,r=T,A=P,n=function(){return C},o=1):4===t&&(i=S,r=D,A=k,n=function(){return E},o=2),ue(e,{name:s,fromWireType:function(e){for(var s,r=E[e>>2],A=n(),a=e+4,l=0;l<=r;++l){var c=e+4+l*t;if(0==A[c>>o]||l==r){var h=i(a,c-a);void 0===s?s=h:(s+=String.fromCharCode(0),s+=h),a=c+t}}return gt(e),s},toWireType:function(e,i){"string"!=typeof i&&ae("Cannot pass non-string to C++ string type "+s);var n=A(i),a=mt(4+n+t);return E[a>>2]=n>>o,r(i,a+4,n+t),null!==e&&e.push(gt,a),a},argPackAdvance:8,readValueFromPointer:De,destructorFunction:function(e){gt(e)}})},u:function(e,t){ue(e,{isVoid:!0,name:t=ee(t),argPackAdvance:0,fromWireType:function(){},toWireType:function(e,t){}})},v:st,w:nt,x:function(){z()},y:At,z:function(){return w.length}},dt=function(e,t,s){"use asm";var i=new e.Int8Array(s),r=new e.Int16Array(s),n=new e.Int32Array(s),A=new e.Uint8Array(s),o=new e.Uint16Array(s),a=new e.Float32Array(s),l=new e.Float64Array(s),c=t.D|0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0.0,b=e.Math.imul,y=e.Math.clz32,B=t.a,w=t.b,v=t.c,C=t.d,M=t.e,E=t.f,F=t.g,x=t.h,U=t.i,I=t.j,T=t.k,P=t.l,S=t.m,D=t.n,k=t.o,Q=t.p,R=t.q,O=t.r,V=t.s,L=t.t,H=t.u,N=t.v,G=t.w,j=t.x,z=t.y,W=t.z,X=t.A,K=t.B,Z=t.C,J=22384,Y=5265264,$=0.0;function q(){Jh();Yh()}function ee(){te(0);return}function te(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0;e=J;J=J+16|0;t=e+8|0;s=e;dc();u=fc()|0;A=gc()|0;r=_c()|0;o=bc()|0;a=yc()|0;l=Bc()|0;c=Fc()|0;h=xc()|0;i=xc()|0;P(r|0,o|0,a|0,l|0,c|0,9,h|0,u|0,i|0,A|0,6204,Uc()|0,138);Tc(1);n[s>>2]=5;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Oc(6211,t);n[s>>2]=3;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Kc(6216,t);n[s>>2]=10;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];sh(6225,t);ch();A=uh()|0;i=dh()|0;u=fh()|0;h=gh()|0;c=mh()|0;l=Bc()|0;a=Fc()|0;o=xc()|0;r=xc()|0;P(u|0,h|0,c|0,l|0,a|0,11,o|0,A|0,r|0,i|0,6234,Uc()|0,139);Ch(2);n[s>>2]=6;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Th(6211,t);n[s>>2]=4;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Oh(6248,t);n[s>>2]=5;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Oh(6265,t);n[s>>2]=6;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];Oh(6280,t);n[s>>2]=7;n[s+4>>2]=0;n[t>>2]=n[s>>2];n[t+4>>2]=n[s+4>>2];jh(6216,t);J=e;return}function se(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0,a=0;i=J;J=J+32|0;o=i+16|0;r=i+8|0;a=i;A=Zf(20)|0;ce(A,t,s);n[a>>2]=0;n[o>>2]=n[a>>2];ue(r,A,o);t=n[r>>2]|0;n[r>>2]=n[e>>2];n[e>>2]=t;t=r+4|0;s=e+4|0;A=n[t>>2]|0;n[t>>2]=n[s>>2];n[s>>2]=A;de(r);s=Zf(352)|0;he(s,n[e>>2]|0);A=e+8|0;n[a>>2]=0;n[o>>2]=n[a>>2];we(r,s,o);s=n[r>>2]|0;n[r>>2]=n[A>>2];n[A>>2]=s;A=r+4|0;s=e+12|0;t=n[A>>2]|0;n[A>>2]=n[s>>2];n[s>>2]=t;ve(r);J=i;return}function ie(e,t){e=e|0;t=t|0;Ks(n[e+8>>2]|0,t);return}function re(e){e=e|0;e=(Do(n[e+8>>2]|0)|0)+107|0;return A[e>>0]|A[e+1>>0]<<8|A[e+2>>0]<<16|A[e+3>>0]<<24|0}function ne(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0,a=0;i=J;J=J+32|0;A=i+16|0;r=i+8|0;o=i;a=Zf(12)|0;ko(a,t,s);n[o>>2]=0;n[A>>2]=n[o>>2];Vo(r,a,A);a=n[r>>2]|0;n[r>>2]=n[e>>2];n[e>>2]=a;a=r+4|0;s=e+4|0;t=n[a>>2]|0;n[a>>2]=n[s>>2];n[s>>2]=t;Lo(r);s=e+8|0;t=Zf(12)|0;Qo(t,n[e>>2]|0);n[o>>2]=0;n[A>>2]=n[o>>2];Wo(r,t,A);t=n[r>>2]|0;n[r>>2]=n[s>>2];n[s>>2]=t;t=r+4|0;o=e+12|0;a=n[t>>2]|0;n[t>>2]=n[o>>2];n[o>>2]=a;Xo(r);Ro(r,n[s>>2]|0);s=e+16|0;o=n[r>>2]|0;a=r+4|0;t=n[a>>2]|0;n[r>>2]=0;n[a>>2]=0;n[A>>2]=n[s>>2];n[s>>2]=o;s=e+20|0;n[A+4>>2]=n[s>>2];n[s>>2]=t;Oo(A);Oo(r);J=i;return}function Ae(e,t){e=e|0;t=t|0;var s=0;e=e+16|0;s=n[e>>2]|0;e:do{if(s|0)switch(t|0){case 4:{ua(s);break e}case 8:{da(s);da(n[e>>2]|0);break e}default:break e}}while(0);return}function oe(e,t){e=e|0;t=t|0;var s=0;s=e+16|0;e=n[s>>2]|0;e:do{if(e|0){switch(t|0){case 1:{qa(e);break e}case 2:{el(e);break e}case 8:{ua(e);e=n[s>>2]|0;break}case 4:break;default:break e}ua(e)}}while(0);return}function ae(e,t){e=e|0;t=t|0;var s=0;s=e+16|0;e=n[s>>2]|0;e:do{if(e|0){switch(t|0){case 1:{kl(e);break e}case 2:{Ql(e);break e}case 8:{da(e);e=n[s>>2]|0;break}case 4:break;default:break e}da(e)}}while(0);return}function le(e,t){e=e|0;t=t|0;e=n[e+16>>2]|0;if(e|0)Hm[n[n[e>>2]>>2]&63](e,t)|0;return}function ce(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;n[e+4>>2]=s;n[e+8>>2]=0;i[e+12>>0]=0;i[e+13>>0]=0;n[e+16>>2]=0;return}function he(e,t){e=e|0;t=t|0;n[e>>2]=t;Oe(e+4|0,t);Ve(e+247|0);n[e+288>>2]=0;n[e+292>>2]=0;n[e+296>>2]=0;Le(e+300|0);t=e+312|0;n[t>>2]=0;n[t+4>>2]=0;n[t+8>>2]=0;n[t+12>>2]=0;He(e+328|0);Ne(e);return}function ue(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4296;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;pe(e,i);J=s;return}function de(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function pe(e,t){e=e|0;t=t|0;return}function fe(e){e=e|0;M(e|0)|0;tf()}function ge(e){e=e|0;Ag(e);qp(e);return}function me(e){e=e|0;e=n[e+12>>2]|0;if(e|0)qp(e);return}function _e(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==6407?e+12|0:0)|0}function be(e){e=e|0;ye(e,16);return}function ye(e,t){e=e|0;t=t|0;Be(e);return}function Be(e){e=e|0;qp(e);return}function we(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4324;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ce(e,i);J=s;return}function ve(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Ce(e,t){e=e|0;t=t|0;return}function Me(e){e=e|0;Ag(e);qp(e);return}function Ee(e){e=e|0;e=n[e+12>>2]|0;if(e|0){Ue(e);qp(e)}return}function Fe(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==6605?e+12|0:0)|0}function xe(e){e=e|0;ye(e,16);return}function Ue(e){e=e|0;Ie(e+320|0);Te(e+312|0);Pe(e+300|0);Qe(e+288|0);Se(e+247|0);De(e+4|0);return}function Ie(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Te(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Pe(e){e=e|0;ke(e);return}function Se(e){e=e|0;e=e+34|0;e=A[e>>0]|A[e+1>>0]<<8|A[e+2>>0]<<16|A[e+3>>0]<<24;if(e|0)Yf(e);return}function De(e){e=e|0;Re(n[e+12>>2]|0);return}function ke(e){e=e|0;var t=0,s=0;t=n[e>>2]|0;s=t;if(t|0){n[e+4>>2]=s;ye(t,(n[e+8>>2]|0)-s|0)}return}function Qe(e){e=e|0;var t=0,s=0;t=n[e>>2]|0;s=t;if(t|0){n[e+4>>2]=s;ye(t,(n[e+8>>2]|0)-s|0)}return}function Re(e){e=e|0;Zg(n[e+-4>>2]|0);return}function Oe(e,t){e=e|0;t=t|0;n[e>>2]=t;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=Ge(1048576)|0;return}function Ve(e){e=e|0;var t=0;t=e+32|0;i[t>>0]=0;i[t+1>>0]=0;e=e+34|0;i[e>>0]=0;i[e+1>>0]=0;i[e+2>>0]=0;i[e+3>>0]=0;return}function Le(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;return}function He(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;e=e+16|0;n[e>>2]=-1;n[e+4>>2]=-1;return}function Ne(e){e=e|0;var t=0,s=0,r=0,A=0,o=0,a=0;a=J;J=J+64|0;A=a+32|0;s=a+56|0;t=a+16|0;o=a;je(n[e>>2]|0,s,4);it(A,s,s+4|0);s=st(6693)|0;r=i[A+11>>0]|0;if((s|0)==((r<<24>>24<0?n[A+4>>2]|0:r&255)|0)){r=(Cg(A,0,-1,6693,s)|0)==0;bg(A);if(r){s=n[e>>2]|0;n[t>>2]=0;n[t+4>>2]=0;n[t+8>>2]=0;n[t+12>>2]=0;n[A>>2]=n[t>>2];n[A+4>>2]=n[t+4>>2];n[A+8>>2]=n[t+8>>2];n[A+12>>2]=n[t+12>>2];We(s,A);s=e+20|0;je(n[e>>2]|0,s,227);Xe(e,s);r=Ke()|0;t=n[r>>2]|0;r=n[r+4>>2]|0;if((t|0)!=(r|0))do{Ze(A,t);Je(A,s);Ye(A);t=t+24|0}while((t|0)!=(r|0));$e(e);qe(e);et(n[e>>2]|0);r=n[e>>2]|0;t=(n[e+116>>2]|0)+8|0;s=o;n[s>>2]=0;n[s+4>>2]=0;s=o+8|0;n[s>>2]=t;n[s+4>>2]=0;n[A>>2]=n[o>>2];n[A+4>>2]=n[o+4>>2];n[A+8>>2]=n[o+8>>2];n[A+12>>2]=n[o+12>>2];We(r,A);tt(e+4|0);J=a;return}}else bg(A);a=C(8)|0;ze(a);E(a|0,2592,8)}function Ge(e){e=e|0;var t=0;t=Kg(e+68|0)|0;e=t+68&-64;n[e+-4>>2]=t;return e|0}function je(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0;a=e+13|0;if(!(i[a>>0]|0)){o=e+4|0;r=n[o>>2]|0;l=e+8|0;A=n[l>>2]|0;c=r-A|0;s=(c|0)<(s|0)?c:s;if(s){um(t|0,(n[e>>2]|0)+A|0,s|0)|0;A=n[l>>2]|0;r=n[o>>2]|0}c=A+s|0;n[l>>2]=c;n[e+16>>2]=s;if((c|0)>=(r|0))i[a>>0]=1}else i[e+12>>0]=1;return}function ze(e){e=e|0;pg(e,6791);n[e>>2]=4352;return}function We(e,t){e=e|0;t=t|0;var s=0,r=0,A=0;A=t+8|0;t=n[A>>2]|0;A=n[A+4>>2]|0;s=n[e+4>>2]|0;r=((s|0)<0)<<31>>31;if((A|0)<(r|0)|(A|0)==(r|0)&t>>>0<s>>>0)n[e+8>>2]=t;else i[e+12>>0]=1;return}function Xe(e,t){e=e|0;t=t|0;var s=0.0,r=0.0,n=0,A=0.0,o=0,a=0.0,h=0,u=0.0,d=0,p=0.0;d=t+179|0;i[c>>0]=i[d>>0];i[c+1>>0]=i[d+1>>0];i[c+2>>0]=i[d+2>>0];i[c+3>>0]=i[d+3>>0];i[c+4>>0]=i[d+4>>0];i[c+5>>0]=i[d+5>>0];i[c+6>>0]=i[d+6>>0];i[c+7>>0]=i[d+7>>0];u=+l[c>>3];o=t+187|0;i[c>>0]=i[o>>0];i[c+1>>0]=i[o+1>>0];i[c+2>>0]=i[o+2>>0];i[c+3>>0]=i[o+3>>0];i[c+4>>0]=i[o+4>>0];i[c+5>>0]=i[o+5>>0];i[c+6>>0]=i[o+6>>0];i[c+7>>0]=i[o+7>>0];p=+l[c>>3];e=t+195|0;i[c>>0]=i[e>>0];i[c+1>>0]=i[e+1>>0];i[c+2>>0]=i[e+2>>0];i[c+3>>0]=i[e+3>>0];i[c+4>>0]=i[e+4>>0];i[c+5>>0]=i[e+5>>0];i[c+6>>0]=i[e+6>>0];i[c+7>>0]=i[e+7>>0];A=+l[c>>3];h=t+203|0;i[c>>0]=i[h>>0];i[c+1>>0]=i[h+1>>0];i[c+2>>0]=i[h+2>>0];i[c+3>>0]=i[h+3>>0];i[c+4>>0]=i[h+4>>0];i[c+5>>0]=i[h+5>>0];i[c+6>>0]=i[h+6>>0];i[c+7>>0]=i[h+7>>0];a=+l[c>>3];n=t+211|0;i[c>>0]=i[n>>0];i[c+1>>0]=i[n+1>>0];i[c+2>>0]=i[n+2>>0];i[c+3>>0]=i[n+3>>0];i[c+4>>0]=i[n+4>>0];i[c+5>>0]=i[n+5>>0];i[c+6>>0]=i[n+6>>0];i[c+7>>0]=i[n+7>>0];s=+l[c>>3];t=t+219|0;i[c>>0]=i[t>>0];i[c+1>>0]=i[t+1>>0];i[c+2>>0]=i[t+2>>0];i[c+3>>0]=i[t+3>>0];i[c+4>>0]=i[t+4>>0];i[c+5>>0]=i[t+5>>0];i[c+6>>0]=i[t+6>>0];i[c+7>>0]=i[t+7>>0];r=+l[c>>3];l[c>>3]=p;i[d>>0]=i[c>>0];i[d+1>>0]=i[c+1>>0];i[d+2>>0]=i[c+2>>0];i[d+3>>0]=i[c+3>>0];i[d+4>>0]=i[c+4>>0];i[d+5>>0]=i[c+5>>0];i[d+6>>0]=i[c+6>>0];i[d+7>>0]=i[c+7>>0];l[c>>3]=u;i[h>>0]=i[c>>0];i[h+1>>0]=i[c+1>>0];i[h+2>>0]=i[c+2>>0];i[h+3>>0]=i[c+3>>0];i[h+4>>0]=i[c+4>>0];i[h+5>>0]=i[c+5>>0];i[h+6>>0]=i[c+6>>0];i[h+7>>0]=i[c+7>>0];l[c>>3]=a;i[o>>0]=i[c>>0];i[o+1>>0]=i[c+1>>0];i[o+2>>0]=i[c+2>>0];i[o+3>>0]=i[c+3>>0];i[o+4>>0]=i[c+4>>0];i[o+5>>0]=i[c+5>>0];i[o+6>>0]=i[c+6>>0];i[o+7>>0]=i[c+7>>0];l[c>>3]=A;i[n>>0]=i[c>>0];i[n+1>>0]=i[c+1>>0];i[n+2>>0]=i[c+2>>0];i[n+3>>0]=i[c+3>>0];i[n+4>>0]=i[c+4>>0];i[n+5>>0]=i[c+5>>0];i[n+6>>0]=i[c+6>>0];i[n+7>>0]=i[c+7>>0];l[c>>3]=r;i[e>>0]=i[c>>0];i[e+1>>0]=i[c+1>>0];i[e+2>>0]=i[c+2>>0];i[e+3>>0]=i[c+3>>0];i[e+4>>0]=i[c+4>>0];i[e+5>>0]=i[c+5>>0];i[e+6>>0]=i[c+6>>0];i[e+7>>0]=i[c+7>>0];l[c>>3]=s;i[t>>0]=i[c>>0];i[t+1>>0]=i[c+1>>0];i[t+2>>0]=i[c+2>>0];i[t+3>>0]=i[c+3>>0];i[t+4>>0]=i[c+4>>0];i[t+5>>0]=i[c+5>>0];i[t+6>>0]=i[c+6>>0];i[t+7>>0]=i[c+7>>0];return}function Ke(){var e=0,t=0,s=0,r=0,A=0,o=0,a=0,l=0;A=J;J=J+48|0;s=A+24|0;r=A;e=A+44|0;if((i[21440]|0)==0?Qf(21440)|0:0){n[5374]=0;n[5375]=0;n[5376]=0;jf(21440)}if((i[21448]|0)==0?Qf(21448)|0:0)jf(21448);if((n[5374]|0)==(n[5375]|0)){ag(21508);if((n[5374]|0)==(n[5375]|0)){i[s>>0]=i[e>>0]|0;At(r,s);e=n[5375]|0;do{if(e>>>0>=(n[5376]|0)>>>0){e=((e-(n[5374]|0)|0)/24|0)+1|0;t=pt(21496)|0;if(t>>>0<e>>>0)Xg(21496);else{o=n[5374]|0;l=((n[5376]|0)-o|0)/24|0;a=l<<1;ht(s,l>>>0<t>>>1>>>0?a>>>0<e>>>0?e:a:t,((n[5375]|0)-o|0)/24|0,21504);t=s+8|0;lt(n[t>>2]|0,r);n[t>>2]=(n[t>>2]|0)+24;ut(21496,s);dt(s);break}}else{ot(s,21496,1);l=s+4|0;lt(n[l>>2]|0,r);n[l>>2]=(n[l>>2]|0)+24;at(s)}}while(0);Ye(r)}lg(21508)}J=A;return 21496}function Ze(e,t){e=e|0;t=t|0;var s=0,i=0;s=t+16|0;i=n[s>>2]|0;do{if(i)if((t|0)==(i|0)){i=ct(e)|0;n[e+16>>2]=i;s=n[s>>2]|0;zm[n[(n[s>>2]|0)+12>>2]&15](s,i);break}else{n[e+16>>2]=Vm[n[(n[i>>2]|0)+8>>2]&15](i)|0;break}else n[e+16>>2]=0}while(0);return}function Je(e,t){e=e|0;t=t|0;e=n[e+16>>2]|0;if(!e){t=C(4)|0;n[t>>2]=0;It(t);E(t|0,4168,131)}else{zm[n[(n[e>>2]|0)+24>>2]&15](e,t);return}}function Ye(e){e=e|0;var t=0;t=n[e+16>>2]|0;if((e|0)!=(t|0)){if(t|0)jm[n[(n[t>>2]|0)+20>>2]&255](t)}else jm[n[(n[t>>2]|0)+16>>2]&255](t);return}function $e(e){e=e|0;var t=0,s=0,r=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;g=J;J=J+96|0;a=g+16|0;p=g;h=g+72|0;l=n[e>>2]|0;u=o[e+114>>1]|0;d=p;n[d>>2]=0;n[d+4>>2]=0;d=p+8|0;n[d>>2]=u;n[d+4>>2]=0;n[a>>2]=n[p>>2];n[a+4>>2]=n[p+4>>2];n[a+8>>2]=n[p+8>>2];n[a+12>>2]=n[p+12>>2];We(l,a);l=e+120|0;e:do{if(n[l>>2]|0){c=a+2|0;u=a+16|0;d=a+20|0;p=a+18|0;s=0;while(1){if(!(Tt(n[e>>2]|0)|0))break e;if(Pt(n[e>>2]|0)|0)break e;je(n[e>>2]|0,a,54);t=7277;r=c;while(1){if((i[r>>0]|0)!=(i[t>>0]|0))break;r=r+1|0;if((r|0)==(u|0)){f=8;break}else t=t+1|0}if((f|0)==8?(f=0,(A[p>>0]|A[p+1>>0]<<8)<<16>>16==22204):0)break;Dt(n[e>>2]|0,(A[d>>0]|A[d+1>>0]<<8)&65535,0,1);s=s+1|0;if(s>>>0>=(n[l>>2]|0)>>>0)break e}p=(A[d>>0]|A[d+1>>0]<<8)&65535;f=Jf(p)|0;je(n[e>>2]|0,f,p);St(e,f);qp(f);f=e+125|0;Qt(h,e+247|0,(A[f>>0]|A[f+1>>0]<<8)&65535);Rt(e+300|0,h)|0;Pe(h);J=g;return}}while(0);g=C(8)|0;kt(g);E(g|0,2672,8)}function qe(e){e=e|0;var t=0,s=0,i=0,r=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;d=J;J=J+176|0;r=d+40|0;o=d+24|0;t=d+16|0;i=d;c=d+152|0;h=d+136|0;u=d+56|0;l=n[e>>2]|0;a=e+116|0;p=n[a>>2]|0;s=o;n[s>>2]=0;n[s+4>>2]=0;s=o+8|0;n[s>>2]=p;n[s+4>>2]=0;n[r>>2]=n[o>>2];n[r+4>>2]=n[o+4>>2];n[r+8>>2]=n[o+8>>2];n[r+12>>2]=n[o+12>>2];We(l,r);l=t;n[l>>2]=0;n[l+4>>2]=0;je(n[e>>2]|0,t,8);if(!(Tt(n[e>>2]|0)|0)){p=C(8)|0;$t(p);E(p|0,2704,8)}s=t;t=n[s>>2]|0;s=n[s+4>>2]|0;if((t|0)==-1&(s|0)==-1){p=C(8)|0;qt(p,7488);E(p|0,2720,8)}p=n[e>>2]|0;l=i;n[l>>2]=0;n[l+4>>2]=0;l=i+8|0;n[l>>2]=t;n[l+4>>2]=s;n[r>>2]=n[i>>2];n[r+4>>2]=n[i+4>>2];n[r+8>>2]=n[i+8>>2];n[r+12>>2]=n[i+12>>2];We(p,r);if(!(Tt(n[e>>2]|0)|0)){p=C(8)|0;$t(p);E(p|0,2704,8)}je(n[e>>2]|0,r,8);if(!(Tt(n[e>>2]|0)|0)){p=C(8)|0;$t(p);E(p|0,2704,8)}if(n[r>>2]|0){p=C(8)|0;es(p);E(p|0,2736,8)}o=e+288|0;l=e+292|0;n[l>>2]=n[o>>2];p=e+259|0;if((A[p>>0]|A[p+1>>0]<<8|A[p+2>>0]<<16|A[p+3>>0]<<24|0)==-1){p=C(8)|0;qt(p,7606);E(p|0,2720,8)}i=r+4|0;ts(o,(n[i>>2]|0)+1|0);p=n[o>>2]|0;n[p>>2]=(n[a>>2]|0)+8;n[p+4>>2]=0;if((n[i>>2]|0)>>>0>1){Oe(c,n[e>>2]|0);ss(h,c);is(u,32,2,8,0);rs(h);ns(u);if(!(n[i>>2]|0)){o=n[o>>2]|0;s=o}else{s=1;do{if(s>>>0>1)t=n[(n[o>>2]|0)+(s+-1<<3)>>2]|0;else t=0;a=As(u,h,t,1)|0;t=n[o>>2]|0;p=t+(s<<3)|0;n[p>>2]=a;n[p+4>>2]=((a|0)<0)<<31>>31;s=s+1|0}while(s>>>0<=(n[i>>2]|0)>>>0);s=t;o=t}t=n[l>>2]|0;if(t-s>>3>>>0>1){r=t-o>>3;i=o;t=1;s=n[i>>2]|0;i=n[i+4>>2]|0;do{p=o+(t<<3)|0;l=p;s=sm(n[l>>2]|0,n[l+4>>2]|0,s|0,i|0)|0;i=v()|0;n[p>>2]=s;n[p+4>>2]=i;t=t+1|0}while(t>>>0<r>>>0)}os(u);as(h);De(c)}J=d;return}function et(e){e=e|0;i[e+12>>0]=0;i[e+13>>0]=0;return}function tt(e){e=e|0;n[e+8>>2]=0;n[e+4>>2]=0;return}function st(e){e=e|0;return Zd(e)|0}function it(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0;a=J;J=J+16|0;A=t;o=a;r=s-A|0;if(r>>>0>4294967279)fg(e);if(r>>>0<11)i[e+11>>0]=r;else{c=r+16&-16;l=Zf(c)|0;n[e>>2]=l;n[e+8>>2]=c|-2147483648;n[e+4>>2]=r;e=l}if((t|0)!=(s|0)){A=s-A|0;r=e;while(1){rt(r,t);t=t+1|0;if((t|0)==(s|0))break;else r=r+1|0}e=e+A|0}i[o>>0]=0;rt(e,o);J=a;return}function rt(e,t){e=e|0;t=t|0;i[e>>0]=i[t>>0]|0;return}function nt(e){e=e|0;ff(e);qp(e);return}function At(e,t){e=e|0;t=t|0;n[e>>2]=4372;n[e+16>>2]=e;return}function ot(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s*24|0);return}function at(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function lt(e,t){e=e|0;t=t|0;var s=0,i=0;s=t+16|0;i=n[s>>2]|0;do{if(i)if((t|0)==(i|0)){i=ct(e)|0;n[e+16>>2]=i;s=n[s>>2]|0;zm[n[(n[s>>2]|0)+12>>2]&15](s,i);break}else{n[e+16>>2]=i;n[s>>2]=0;break}else n[e+16>>2]=0}while(0);return}function ct(e){e=e|0;return e|0}function ht(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>178956970){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t*24|0)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s*24|0)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t*24|0);return}function ut(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0;a=n[e>>2]|0;l=e+4|0;s=n[l>>2]|0;o=t+4|0;if((s|0)==(a|0)){r=o;A=e;i=n[o>>2]|0;s=a}else{i=n[o>>2]|0;do{s=s+-24|0;lt(i+-24|0,s);i=(n[o>>2]|0)+-24|0;n[o>>2]=i}while((s|0)!=(a|0));r=o;A=e;s=n[e>>2]|0}n[A>>2]=i;n[r>>2]=s;a=t+8|0;o=n[l>>2]|0;n[l>>2]=n[a>>2];n[a>>2]=o;a=e+8|0;l=t+12|0;e=n[a>>2]|0;n[a>>2]=n[l>>2];n[l>>2]=e;n[t>>2]=n[r>>2];return}function dt(e){e=e|0;var t=0,s=0,i=0,r=0;s=n[e+4>>2]|0;i=e+8|0;t=n[i>>2]|0;if((t|0)!=(s|0))do{r=t+-24|0;n[i>>2]=r;Ye(r);t=n[i>>2]|0}while((t|0)!=(s|0));t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function pt(e){e=e|0;return 178956970}function ft(e){e=e|0;qp(e);return}function gt(e){e=e|0;e=Zf(8)|0;n[e>>2]=4372;return e|0}function mt(e,t){e=e|0;t=t|0;n[t>>2]=4372;return}function _t(e){e=e|0;return}function bt(e){e=e|0;ye(e,8);return}function yt(e,t){e=e|0;t=t|0;Ct(e+4|0,t);return}function Bt(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==7183?e+4|0:0)|0}function wt(e){e=e|0;return 2664}function vt(e){e=e|0;return}function Ct(e,t){e=e|0;t=t|0;Mt(e,t);return}function Mt(e,t){e=e|0;t=t|0;var s=0,r=0;e=t+104|0;t=A[e>>0]|0;s=t>>>7;r=t>>>6&1;if((s|0)==1&(r|0)!=0){r=C(8)|0;Et(r);E(r|0,2632,8)}if((s|0)==(r|0)){r=C(8)|0;Ft(r);E(r|0,2648,8)}else{i[e>>0]=t&63;return}}function Et(e){e=e|0;pg(e,7076);n[e>>2]=4416;return}function Ft(e){e=e|0;pg(e,7144);n[e>>2]=4436;return}function xt(e){e=e|0;ff(e);qp(e);return}function Ut(e){e=e|0;ff(e);qp(e);return}function It(e){e=e|0;n[e>>2]=6092;return}function Tt(e){e=e|0;var t=0;t=e+12|0;e=(i[t>>0]|0)==0;i[t>>0]=0;return e|0}function Pt(e){e=e|0;return(i[e+13>>0]|0)!=0|0}function St(e,t){e=e|0;t=t|0;e=e+247|0;Ot(e,t);if((A[e>>0]|A[e+1>>0]<<8)<<16>>16==2)return;else{t=C(8)|0;Vt(t);E(t|0,2688,8)}}function Dt(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0,o=0;switch(r|0){case 0:break;case 2:{r=n[e+4>>2]|0;t=sm(sm(t|0,s|0,-1,-1)|0,v()|0,r|0,((r|0)<0)<<31>>31|0)|0;s=v()|0;break}case 1:{r=n[e+8>>2]|0;t=sm(r|0,((r|0)<0)<<31>>31|0,t|0,s|0)|0;s=v()|0;break}default:{s=0;t=0}}A=n[e+4>>2]|0;o=((A|0)<0)<<31>>31;r=e+12|0;if((s|0)<0|((s|0)>(o|0)|(s|0)==(o|0)&t>>>0>=A>>>0))i[r>>0]=1;else{i[r>>0]=0;n[e+8>>2]=t}return}function kt(e){e=e|0;pg(e,7410);n[e>>2]=4476;return}function Qt(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,n=0,o=0,a=0,l=0,c=0;o=J;J=J+16|0;n=o;Le(e);r=t+32|0;if((A[r>>0]|A[r+1>>0]<<8)<<16>>16){i=t+34|0;t=0;do{l=A[i>>0]|A[i+1>>0]<<8|A[i+2>>0]<<16|A[i+3>>0]<<24;c=l+(t*6|0)|0;a=l+(t*6|0)+2|0;l=l+(t*6|0)+4|0;Gt(n,(A[c>>0]|A[c+1>>0]<<8)&65535,(A[a>>0]|A[a+1>>0]<<8)&65535,(A[l>>0]|A[l+1>>0]<<8)&65535);Nt(e,n);s=s-((A[a>>0]|A[a+1>>0]<<8)&65535)|0;t=t+1|0}while(t>>>0<((A[r>>0]|A[r+1>>0]<<8)&65535)>>>0)}if((s|0)<0){c=C(8)|0;Vt(c);E(c|0,2688,8)}if(s|0){Gt(n,0,s,2);Nt(e,n)}J=o;return}function Rt(e,t){e=e|0;t=t|0;var s=0,r=0;s=J;J=J+16|0;r=s+1|0;i[r>>0]=i[s>>0]|0;Jt(e,t,r);J=s;return e|0}function Ot(e,t){e=e|0;t=t|0;var s=0,r=0,n=0,o=0,a=0,l=0,c=0;r=t+2|0;o=A[t>>0]|A[t+1>>0]<<8;i[e>>0]=o;i[e+1>>0]=o>>8;o=e+2|0;r=A[r>>0]|A[r+1>>0]<<8;i[o>>0]=r;i[o+1>>0]=r>>8;i[e+4>>0]=i[t+4>>0]|0;o=t+6|0;i[e+5>>0]=i[t+5>>0]|0;r=t+8|0;s=e+6|0;o=A[o>>0]|A[o+1>>0]<<8;i[s>>0]=o;i[s+1>>0]=o>>8;s=t+12|0;o=e+8|0;r=A[r>>0]|A[r+1>>0]<<8|A[r+2>>0]<<16|A[r+3>>0]<<24;i[o>>0]=r;i[o+1>>0]=r>>8;i[o+2>>0]=r>>16;i[o+3>>0]=r>>24;o=e+12|0;s=A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24;i[o>>0]=s;i[o+1>>0]=s>>8;i[o+2>>0]=s>>16;i[o+3>>0]=s>>24;o=t+16|0;s=o;s=A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24;o=o+4|0;o=A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24;r=e+16|0;a=r;i[a>>0]=s;i[a+1>>0]=s>>8;i[a+2>>0]=s>>16;i[a+3>>0]=s>>24;r=r+4|0;i[r>>0]=o;i[r+1>>0]=o>>8;i[r+2>>0]=o>>16;i[r+3>>0]=o>>24;r=t+32|0;o=t+24|0;a=o;a=A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24;o=o+4|0;o=A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24;s=e+24|0;n=s;i[n>>0]=a;i[n+1>>0]=a>>8;i[n+2>>0]=a>>16;i[n+3>>0]=a>>24;s=s+4|0;i[s>>0]=o;i[s+1>>0]=o>>8;i[s+2>>0]=o>>16;i[s+3>>0]=o>>24;s=t+34|0;o=e+32|0;r=A[r>>0]|A[r+1>>0]<<8;i[o>>0]=r;i[o+1>>0]=r>>8;n=e+34|0;e=A[n>>0]|A[n+1>>0]<<8|A[n+2>>0]<<16|A[n+3>>0]<<24;if(!e)e=r;else{Yf(e);e=A[o>>0]|A[o+1>>0]<<8}r=Jf((e&65535)*6|0)|0;i[n>>0]=r;i[n+1>>0]=r>>8;i[n+2>>0]=r>>16;i[n+3>>0]=r>>24;if(e<<16>>16?(e=t+36|0,a=A[s>>0]|A[s+1>>0]<<8,i[r>>0]=a,i[r+1>>0]=a>>8,t=t+38|0,a=r+2|0,e=A[e>>0]|A[e+1>>0]<<8,i[a>>0]=e,i[a+1>>0]=e>>8,a=r+4|0,t=A[t>>0]|A[t+1>>0]<<8,i[a>>0]=t,i[a+1>>0]=t>>8,((A[o>>0]|A[o+1>>0]<<8)&65535)>1):0){e=1;do{t=s;s=s+6|0;a=A[n>>0]|A[n+1>>0]<<8|A[n+2>>0]<<16|A[n+3>>0]<<24;l=t+8|0;r=a+(e*6|0)|0;c=A[s>>0]|A[s+1>>0]<<8;i[r>>0]=c;i[r+1>>0]=c>>8;t=t+10|0;r=a+(e*6|0)+2|0;l=A[l>>0]|A[l+1>>0]<<8;i[r>>0]=l;i[r+1>>0]=l>>8;a=a+(e*6|0)+4|0;t=A[t>>0]|A[t+1>>0]<<8;i[a>>0]=t;i[a+1>>0]=t>>8;e=e+1|0}while(e>>>0<((A[o>>0]|A[o+1>>0]<<8)&65535)>>>0)}return}function Vt(e){e=e|0;pg(e,7354);n[e>>2]=4456;return}function Lt(e){e=e|0;ff(e);qp(e);return}function Ht(e){e=e|0;ff(e);qp(e);return}function Nt(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0;a=J;J=J+32|0;r=a;A=e+4|0;s=n[A>>2]|0;o=e+8|0;do{if((s|0)==(n[o>>2]|0)){s=((s-(n[e>>2]|0)|0)/12|0)+1|0;i=Zt(e)|0;if(i>>>0<s>>>0)Xg(e);else{l=n[e>>2]|0;c=((n[o>>2]|0)-l|0)/12|0;o=c<<1;Wt(r,c>>>0<i>>>1>>>0?o>>>0<s>>>0?s:o:i,((n[A>>2]|0)-l|0)/12|0,e+8|0);o=r+8|0;A=n[o>>2]|0;n[A>>2]=n[t>>2];n[A+4>>2]=n[t+4>>2];n[A+8>>2]=n[t+8>>2];n[o>>2]=(n[o>>2]|0)+12;Xt(e,r);Kt(r);break}}else{jt(r,e,1);c=r+4|0;l=n[c>>2]|0;n[l>>2]=n[t>>2];n[l+4>>2]=n[t+4>>2];n[l+8>>2]=n[t+8>>2];n[c>>2]=(n[c>>2]|0)+12;zt(r)}}while(0);J=a;return}function Gt(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;n[e>>2]=t;n[e+4>>2]=s;n[e+8>>2]=i;return}function jt(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s*12|0);return}function zt(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function Wt(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>357913941){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t*12|0)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s*12|0)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t*12|0);return}function Xt(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;i=n[e>>2]|0;o=e+4|0;A=t+4|0;r=(n[o>>2]|0)-i|0;s=(n[A>>2]|0)+(((r|0)/-12|0)*12|0)|0;n[A>>2]=s;if((r|0)>0){hm(s|0,i|0,r|0)|0;i=A;s=n[A>>2]|0}else i=A;A=n[e>>2]|0;n[e>>2]=s;n[i>>2]=A;A=t+8|0;r=n[o>>2]|0;n[o>>2]=n[A>>2];n[A>>2]=r;A=e+8|0;o=t+12|0;e=n[A>>2]|0;n[A>>2]=n[o>>2];n[o>>2]=e;n[t>>2]=n[i>>2];return}function Kt(e){e=e|0;var t=0,s=0,i=0;t=n[e+4>>2]|0;s=e+8|0;i=n[s>>2]|0;if((i|0)!=(t|0))n[s>>2]=i+(~(((i+-12-t|0)>>>0)/12|0)*12|0);t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function Zt(e){e=e|0;return 357913941}function Jt(e,t,s){e=e|0;t=t|0;s=s|0;var i=0;Yt(e);n[e>>2]=n[t>>2];s=t+4|0;n[e+4>>2]=n[s>>2];i=t+8|0;n[e+8>>2]=n[i>>2];n[i>>2]=0;n[s>>2]=0;n[t>>2]=0;return}function Yt(e){e=e|0;var t=0,s=0,i=0,r=0;t=n[e>>2]|0;s=t;if(t|0){i=e+4|0;n[i>>2]=s;r=e+8|0;ye(t,(n[r>>2]|0)-s|0);n[r>>2]=0;n[i>>2]=0;n[e>>2]=0}return}function $t(e){e=e|0;pg(e,7660);n[e>>2]=4496;return}function qt(e,t){e=e|0;t=t|0;pg(e,t);n[e>>2]=4516;return}function es(e){e=e|0;pg(e,7704);n[e>>2]=4536;return}function ts(e,t){e=e|0;t=t|0;var s=0,i=0,r=0;s=e+4|0;r=n[e>>2]|0;i=(n[s>>2]|0)-r>>3;if(i>>>0>=t>>>0){if(i>>>0>t>>>0)n[s>>2]=r+(t<<3)}else us(e,t-i|0);return}function ss(e,t){e=e|0;t=t|0;n[e>>2]=t;n[e+4>>2]=0;n[e+8>>2]=-1;return}function is(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var A=0;n[e+4>>2]=t;n[e+8>>2]=s;n[e+12>>2]=i;n[e+16>>2]=r;n[e+36>>2]=0;n[e+40>>2]=0;n[e+44>>2]=0;vs(e+48|0);n[e+68>>2]=0;n[e+72>>2]=0;n[e+76>>2]=0;do{if(!r){s=e+20|0;if((t+-1|0)>>>0<31){n[s>>2]=t;r=1<<t;n[e+24>>2]=r;s=r>>>1;n[e+28>>2]=0-s;s=r+-1-s|0;break}else{n[s>>2]=32;n[e+24>>2]=0;n[e+28>>2]=-2147483648;s=2147483647;break}}else{i=e+20|0;n[i>>2]=0;n[e+24>>2]=r;s=r;A=0;while(1){s=s>>>1;t=A+1|0;if(!s)break;else A=t}n[i>>2]=(1<<A|0)==(r|0)?A:t;s=r>>>1;n[e+28>>2]=0-s;s=r+-1-s|0}}while(0);n[e+32>>2]=s;n[e>>2]=0;return}function rs(e){e=e|0;var t=0;t=((Es(n[e>>2]|0)|0)&255)<<24;t=((Es(n[e>>2]|0)|0)&255)<<16|t;t=t|((Es(n[e>>2]|0)|0)&255)<<8;n[e+4>>2]=t|(Es(n[e>>2]|0)|0)&255;return}function ns(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,b=0;g=J;J=J+64|0;p=g+44|0;f=g;c=e+36|0;h=e+40|0;e:do{if((n[c>>2]|0)==(n[h>>2]|0)){u=e+8|0;t:do{if(!(n[u>>2]|0))d=e+20|0;else{r=e+20|0;A=e+44|0;o=p+4|0;a=e+44|0;l=p+8|0;i=0;while(1){Ts(f,(n[r>>2]|0)+1|0,0,0);t=n[h>>2]|0;if(t>>>0<(n[A>>2]|0)>>>0){Ps(p,c,1);Ds(n[o>>2]|0,f);n[o>>2]=(n[o>>2]|0)+44;Ss(p)}else{t=((t-(n[c>>2]|0)|0)/44|0)+1|0;s=Os(c)|0;if(s>>>0<t>>>0)break;m=n[c>>2]|0;b=((n[A>>2]|0)-m|0)/44|0;_=b<<1;ks(p,b>>>0<s>>>1>>>0?_>>>0<t>>>0?t:_:s,((n[h>>2]|0)-m|0)/44|0,a);Ds(n[l>>2]|0,f);n[l>>2]=(n[l>>2]|0)+44;Qs(c,p);Rs(p)}Ms(f);i=i+1|0;if(i>>>0>=(n[u>>2]|0)>>>0){d=r;break t}}Xg(c)}}while(0);if(n[d>>2]|0){o=e+12|0;a=e+68|0;l=e+72|0;c=e+76|0;h=p+4|0;r=e+76|0;A=p+8|0;i=1;while(1){t=n[o>>2]|0;Ts(f,1<<(i>>>0>t>>>0?t:i),0,0);t=n[l>>2]|0;if(t>>>0<(n[c>>2]|0)>>>0){Ps(p,a,1);Ds(n[h>>2]|0,f);n[h>>2]=(n[h>>2]|0)+44;Ss(p)}else{t=((t-(n[a>>2]|0)|0)/44|0)+1|0;s=Os(a)|0;if(s>>>0<t>>>0)break;b=n[a>>2]|0;m=((n[c>>2]|0)-b|0)/44|0;_=m<<1;ks(p,m>>>0<s>>>1>>>0?_>>>0<t>>>0?t:_:s,((n[l>>2]|0)-b|0)/44|0,r);Ds(n[A>>2]|0,f);n[A>>2]=(n[A>>2]|0)+44;Qs(a,p);Rs(p)}Ms(f);i=i+1|0;if(i>>>0>(n[d>>2]|0)>>>0)break e}Xg(a)}}}while(0);J=g;return}function As(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;s=(Hs(e,t,(n[e+36>>2]|0)+(i*44|0)|0)|0)+s|0;t=n[e+24>>2]|0;if((s|0)<0)return s+t|0;else return s-(s>>>0<t>>>0?0:t)|0;return 0}function os(e){e=e|0;Cs(e+68|0);Cs(e+36|0);return}function as(e){e=e|0;return}function ls(e){e=e|0;ff(e);qp(e);return}function cs(e){e=e|0;ff(e);qp(e);return}function hs(e){e=e|0;ff(e);qp(e);return}function us(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0;a=J;J=J+32|0;r=a;A=e+8|0;o=e+4|0;s=n[o>>2]|0;do{if((n[A>>2]|0)-s>>3>>>0<t>>>0){s=(s-(n[e>>2]|0)>>3)+t|0;i=ys(e)|0;if(i>>>0<s>>>0)Xg(e);else{l=n[e>>2]|0;c=(n[A>>2]|0)-l|0;A=c>>2;ps(r,c>>3>>>0<i>>>1>>>0?A>>>0<s>>>0?s:A:i,(n[o>>2]|0)-l>>3,e+8|0);fs(r,t);gs(e,r);ms(r);break}}else ds(e,t)}while(0);J=a;return}function ds(e,t){e=e|0;t=t|0;var s=0,i=0,r=0;r=J;J=J+16|0;i=r;_s(i,e,t);e=i+4|0;t=n[e>>2]|0;s=n[i+8>>2]|0;if((t|0)!=(s|0)){s=s+-8-t|0;dm(t|0,0,s+8&-8|0)|0;n[e>>2]=t+((s>>>3)+1<<3)}bs(i);J=r;return}function ps(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>536870911){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t<<3)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s<<3)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t<<3);return}function fs(e,t){e=e|0;t=t|0;var s=0,i=0;i=J;J=J+16|0;s=i;Bs(s,e+8|0,t);e=n[s>>2]|0;t=n[s+4>>2]|0;if((e|0)!=(t|0)){t=t+-8-e|0;dm(e|0,0,t+8&-8|0)|0;n[s>>2]=e+((t>>>3)+1<<3)}ws(s);J=i;return}function gs(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;i=n[e>>2]|0;o=e+4|0;A=t+4|0;r=(n[o>>2]|0)-i|0;s=(n[A>>2]|0)+(0-(r>>3)<<3)|0;n[A>>2]=s;if((r|0)>0){hm(s|0,i|0,r|0)|0;i=A;s=n[A>>2]|0}else i=A;A=n[e>>2]|0;n[e>>2]=s;n[i>>2]=A;A=t+8|0;r=n[o>>2]|0;n[o>>2]=n[A>>2];n[A>>2]=r;A=e+8|0;o=t+12|0;e=n[A>>2]|0;n[A>>2]=n[o>>2];n[o>>2]=e;n[t>>2]=n[i>>2];return}function ms(e){e=e|0;var t=0,s=0,i=0;t=n[e+4>>2]|0;s=e+8|0;i=n[s>>2]|0;if((i|0)!=(t|0))n[s>>2]=i+(~((i+-8-t|0)>>>3)<<3);t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function _s(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s<<3);return}function bs(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function ys(e){e=e|0;return 536870911}function Bs(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=n[t>>2];n[e+4>>2]=(n[t>>2]|0)+(s<<3);n[e+8>>2]=t;return}function ws(e){e=e|0;n[n[e+8>>2]>>2]=n[e>>2];return}function vs(e){e=e|0;n[e+12>>2]=1;n[e+16>>2]=2;n[e+8>>2]=4096;n[e+4>>2]=4;n[e>>2]=4;return}function Cs(e){e=e|0;var t=0,s=0,i=0;s=n[e>>2]|0;if(s|0){i=e+4|0;t=n[i>>2]|0;if((t|0)==(s|0))t=s;else{do{t=t+-44|0;Ms(t)}while((t|0)!=(s|0));t=n[e>>2]|0}n[i>>2]=s;ye(t,(n[e+8>>2]|0)-t|0)}return}function Ms(e){e=e|0;var t=0;t=n[e+8>>2]|0;if(t|0)Re(t);t=n[e+12>>2]|0;if(t|0)Re(t);t=n[e+16>>2]|0;if(t|0)Re(t);return}function Es(e){e=e|0;var t=0,s=0;s=e+4|0;t=n[s>>2]|0;if((t|0)>=(n[e+8>>2]|0)){Fs(e);t=n[s>>2]|0}e=n[e+12>>2]|0;n[s>>2]=t+1;return i[e+t>>0]|0}function Fs(e){e=e|0;var t=0;n[e+4>>2]=0;je(n[e>>2]|0,n[e+12>>2]|0,1048576);t=xs(n[e>>2]|0)|0;n[e+8>>2]=t;if(!t){t=C(8)|0;Us(t);E(t|0,2752,8)}else return}function xs(e){e=e|0;return n[e+16>>2]|0}function Us(e){e=e|0;pg(e,7769);n[e>>2]=4556;return}function Is(e){e=e|0;ff(e);qp(e);return}function Ts(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0,o=0,a=0;n[e>>2]=t;i[e+4>>0]=s&1;o=e+8|0;n[o>>2]=0;a=e+12|0;n[a>>2]=0;A=e+16|0;n[A>>2]=0;if((t+-2|0)>>>0>2046){e=C(8)|0;pg(e,7789);E(e|0,3912,8)}n[e+32>>2]=t+-1;if(t>>>0>16&(s^1)){s=3;while(1)if(1<<s+2>>>0<t>>>0)s=s+1|0;else break;t=1<<s;n[e+36>>2]=t;n[e+40>>2]=15-s;n[A>>2]=Ge((t<<2)+8|0)|0;t=n[e>>2]|0}else{n[A>>2]=0;n[e+40>>2]=0;n[e+36>>2]=0}n[o>>2]=Ge(t<<2)|0;A=Ge(n[e>>2]<<2)|0;n[a>>2]=A;n[e+20>>2]=0;t=n[e>>2]|0;s=e+24|0;n[s>>2]=t;t=(t|0)!=0;if(!r){if(t){t=0;do{n[A+(t<<2)>>2]=1;t=t+1|0}while(t>>>0<(n[e>>2]|0)>>>0)}}else if(t){t=0;do{n[A+(t<<2)>>2]=n[r+(t<<2)>>2];t=t+1|0}while(t>>>0<(n[e>>2]|0)>>>0)}Ls(e);r=((n[e>>2]|0)+6|0)>>>1;n[s>>2]=r;n[e+28>>2]=r;return}function Ps(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s*44|0);return}function Ss(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function Ds(e,t){e=e|0;t=t|0;var s=0;n[e>>2]=n[t>>2];i[e+4>>0]=i[t+4>>0]|0;s=t+8|0;n[e+8>>2]=n[s>>2];n[e+12>>2]=n[t+12>>2];n[e+16>>2]=n[t+16>>2];n[e+20>>2]=n[t+20>>2];n[e+24>>2]=n[t+24>>2];n[e+28>>2]=n[t+28>>2];n[e+32>>2]=n[t+32>>2];n[e+36>>2]=n[t+36>>2];n[e+40>>2]=n[t+40>>2];n[s>>2]=0;n[s+4>>2]=0;n[s+8>>2]=0;return}function ks(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>97612893){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t*44|0)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s*44|0)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t*44|0);return}function Qs(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0;a=n[e>>2]|0;l=e+4|0;s=n[l>>2]|0;o=t+4|0;if((s|0)==(a|0)){r=o;A=e;i=n[o>>2]|0;s=a}else{i=n[o>>2]|0;do{s=s+-44|0;Vs(i+-44|0,s);i=(n[o>>2]|0)+-44|0;n[o>>2]=i}while((s|0)!=(a|0));r=o;A=e;s=n[e>>2]|0}n[A>>2]=i;n[r>>2]=s;a=t+8|0;o=n[l>>2]|0;n[l>>2]=n[a>>2];n[a>>2]=o;a=e+8|0;l=t+12|0;e=n[a>>2]|0;n[a>>2]=n[l>>2];n[l>>2]=e;n[t>>2]=n[r>>2];return}function Rs(e){e=e|0;var t=0,s=0,i=0,r=0;s=n[e+4>>2]|0;i=e+8|0;t=n[i>>2]|0;if((t|0)!=(s|0))do{r=t+-44|0;n[i>>2]=r;Ms(r);t=n[i>>2]|0}while((t|0)!=(s|0));t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function Os(e){e=e|0;return 97612893}function Vs(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0;s=n[t>>2]|0;n[e>>2]=s;i[e+4>>0]=i[t+4>>0]|0;n[e+20>>2]=n[t+20>>2];n[e+24>>2]=n[t+24>>2];n[e+28>>2]=n[t+28>>2];n[e+32>>2]=n[t+32>>2];o=e+36|0;n[o>>2]=n[t+36>>2];n[e+40>>2]=n[t+40>>2];s=s<<2;r=Ge(s)|0;n[e+8>>2]=r;A=n[e>>2]|0;if(A|0)um(r|0,n[t+8>>2]|0,A<<2|0)|0;s=Ge(s)|0;n[e+12>>2]=s;r=n[e>>2]|0;if(r|0)um(s|0,n[t+12>>2]|0,r<<2|0)|0;s=n[o>>2]|0;if(s){r=Ge((s<<2)+8|0)|0;n[e+16>>2]=r;s=(n[o>>2]<<2)+8|0;if(s|0)um(r|0,n[t+16>>2]|0,s|0)|0}else n[e+16>>2]=0;return}function Ls(e){e=e|0;var t=0,s=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;g=e+24|0;A=e+20|0;t=(n[A>>2]|0)+(n[g>>2]|0)|0;n[A>>2]=t;if(t>>>0>32768){n[A>>2]=0;if(!(n[e>>2]|0))t=0;else{r=n[e+12>>2]|0;s=0;do{d=r+(s<<2)|0;t=((n[d>>2]|0)+1|0)>>>1;n[d>>2]=t;t=(n[A>>2]|0)+t|0;n[A>>2]=t;s=s+1|0}while(s>>>0<(n[e>>2]|0)>>>0)}}d=2147483648/(t>>>0)|0;do{if((i[e+4>>0]|0)==0?(p=e+36|0,(n[p>>2]|0)!=0):0){if(n[e>>2]|0){l=n[e+8>>2]|0;c=n[e+12>>2]|0;h=e+40|0;u=e+16|0;t=0;o=0;a=0;do{s=(b(o,d)|0)>>>16;n[l+(a<<2)>>2]=s;o=(n[c+(a<<2)>>2]|0)+o|0;s=s>>>(n[h>>2]|0);if(t>>>0<s>>>0){r=a+-1|0;A=n[u>>2]|0;do{t=t+1|0;n[A+(t<<2)>>2]=r}while((t|0)!=(s|0));t=s}a=a+1|0}while(a>>>0<(n[e>>2]|0)>>>0);s=n[u>>2]|0;n[s>>2]=0;if(t>>>0>(n[p>>2]|0)>>>0){t=e;break}}else{s=n[e+16>>2]|0;n[s>>2]=0;t=0}do{t=t+1|0;n[s+(t<<2)>>2]=(n[e>>2]|0)+-1}while(t>>>0<=(n[p>>2]|0)>>>0);t=e}else f=7}while(0);if((f|0)==7)if(!(n[e>>2]|0))t=e;else{r=n[e+8>>2]|0;A=n[e+12>>2]|0;t=0;s=0;do{n[r+(t<<2)>>2]=(b(s,d)|0)>>>16;s=(n[A+(t<<2)>>2]|0)+s|0;t=t+1|0}while(t>>>0<(n[e>>2]|0)>>>0);t=e}f=((n[g>>2]|0)*5|0)>>>2;p=(n[t>>2]<<3)+48|0;f=f>>>0>p>>>0?p:f;n[g>>2]=f;n[e+28>>2]=f;return}function Hs(e,t,s){e=e|0;t=t|0;s=s|0;var i=0;s=Ns(t,s)|0;n[e>>2]=s;do{if(s){if(s>>>0>=32){s=n[e+28>>2]|0;break}i=n[e+12>>2]|0;if(s>>>0>i>>>0){i=s-i|0;s=Ns(t,(n[e+68>>2]|0)+((s+-1|0)*44|0)|0)|0;i=s<<i|(Gs(t,i)|0)}else i=Ns(t,(n[e+68>>2]|0)+((s+-1|0)*44|0)|0)|0;s=n[e>>2]|0;if((i|0)<(1<<s+-1|0)){s=i+1+(-1<<s)|0;break}else{s=i+1|0;break}}else s=js(t,e+48|0)|0}while(0);return s|0}function Ns(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;d=e+8|0;u=n[d>>2]|0;r=n[t+16>>2]|0;if(r){i=e+4|0;s=n[i>>2]|0;h=u>>>15;n[d>>2]=h;l=(s>>>0)/(h>>>0)|0;a=l>>>(n[t+40>>2]|0);A=n[r+(a<<2)>>2]|0;a=(n[r+(a+1<<2)>>2]|0)+1|0;o=A+1|0;c=n[t+8>>2]|0;if(a>>>0>o>>>0){r=A;A=a;do{o=(A+r|0)>>>1;a=(n[c+(o<<2)>>2]|0)>>>0>l>>>0;r=a?r:o;A=a?o:A;o=r+1|0}while(A>>>0>o>>>0);A=r}r=b(n[c+(A<<2)>>2]|0,h)|0;if((A|0)==(n[t+32>>2]|0))o=u;else o=b(n[c+(o<<2)>>2]|0,h)|0}else{c=u>>>15;n[d>>2]=c;a=n[t>>2]|0;h=n[t+8>>2]|0;i=e+4|0;s=n[i>>2]|0;l=a>>>1;r=0;o=u;A=0;do{p=b(n[h+(l<<2)>>2]|0,c)|0;u=p>>>0>s>>>0;o=u?p:o;r=u?r:p;A=u?A:l;a=u?l:a;l=(A+a|0)>>>1}while((l|0)!=(A|0))}n[i>>2]=s-r;p=o-r|0;n[d>>2]=p;if(p>>>0<16777216)zs(e);d=(n[t+12>>2]|0)+(A<<2)|0;n[d>>2]=(n[d>>2]|0)+1;d=t+28|0;p=(n[d>>2]|0)+-1|0;n[d>>2]=p;if(!p)Ls(t);return A|0}function Gs(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;if(t>>>0>19){s=(Ws(e)|0)&65535;return(Gs(e,t+-16|0)|0)<<16|s|0}i=e+4|0;r=n[i>>2]|0;A=e+8|0;s=(n[A>>2]|0)>>>t;n[A>>2]=s;t=(r>>>0)/(s>>>0)|0;n[i>>2]=r-(b(t,s)|0);if(s>>>0<16777216)zs(e);return t|0}function js(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0;i=e+8|0;r=n[i>>2]|0;s=b(r>>>13,n[t+8>>2]|0)|0;A=e+4|0;o=n[A>>2]|0;a=o>>>0>=s>>>0;if(a){n[A>>2]=o-s;s=r-s|0;n[i>>2]=s}else{n[i>>2]=s;o=t+12|0;n[o>>2]=(n[o>>2]|0)+1}if(s>>>0<16777216)zs(e);o=t+4|0;e=(n[o>>2]|0)+-1|0;n[o>>2]=e;if(!e)Xs(t);return a&1|0}function zs(e){e=e|0;var t=0,s=0,i=0,r=0;t=e+4|0;s=e+8|0;i=n[t>>2]|0;do{i=i<<8|(Es(n[e>>2]|0)|0)&255;n[t>>2]=i;r=n[s>>2]<<8;n[s>>2]=r}while(r>>>0<16777216);return}function Ws(e){e=e|0;var t=0,s=0,i=0,r=0;s=e+4|0;r=n[s>>2]|0;t=e+8|0;i=(n[t>>2]|0)>>>16;n[t>>2]=i;t=(r>>>0)/(i>>>0)|0;n[s>>2]=r-(b(t,i)|0);zs(e);return t&65535|0}function Xs(e){e=e|0;var t=0,s=0,i=0,r=0,A=0;r=n[e>>2]|0;s=e+16|0;t=(n[s>>2]|0)+r|0;n[s>>2]=t;if(t>>>0>8192){i=(t+1|0)>>>1;n[s>>2]=i;A=e+12|0;t=((n[A>>2]|0)+1|0)>>>1;n[A>>2]=t;if((t|0)==(i|0)){t=i+1|0;n[s>>2]=t;s=t;t=i}else s=i}else{s=t;t=n[e+12>>2]|0}n[e+8>>2]=(b(t,2147483648/(s>>>0)|0)|0)>>>18;A=r*5|0;A=A>>>0>259?64:A>>>2;n[e>>2]=A;n[e+4>>2]=A;return}function Ks(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;u=J;J=J+32|0;o=u+16|0;a=u+8|0;l=u;c=e+336|0;i=c;r=e+259|0;if(!((n[i+4>>2]|0)==0?(n[i>>2]|0)==(A[r>>0]|A[r+1>>0]<<8|A[r+2>>0]<<16|A[r+3>>0]<<24|0):0)){i=e+320|0;s=n[i>>2]|0;r=s;if(!((s|0)!=0?(n[e+312>>2]|0)!=0:0)){s=r;h=5}}else{i=e+320|0;s=n[e+320>>2]|0;h=5}if((h|0)==5){h=e+320|0;n[o>>2]=s;n[h>>2]=0;s=e+324|0;n[o+4>>2]=n[s>>2];n[s>>2]=0;Ie(o);r=e+312|0;n[o>>2]=n[r>>2];n[r>>2]=0;d=e+316|0;n[o+4>>2]=n[d>>2];n[d>>2]=0;Te(o);p=Zf(12)|0;ss(p,e+4|0);n[l>>2]=0;n[o>>2]=n[l>>2];Js(a,p,o);p=n[a>>2]|0;n[a>>2]=n[r>>2];n[r>>2]=p;p=a+4|0;l=n[p>>2]|0;n[p>>2]=n[d>>2];n[d>>2]=l;Te(a);Zs(a,n[r>>2]|0,e+300|0);r=n[a>>2]|0;d=a+4|0;l=n[d>>2]|0;n[a>>2]=0;n[d>>2]=0;n[o>>2]=n[h>>2];n[h>>2]=r;n[o+4>>2]=n[s>>2];n[s>>2]=l;Ie(o);Ie(a);s=e+328|0;l=s;l=sm(n[l>>2]|0,n[l+4>>2]|0,1,0)|0;h=v()|0;n[s>>2]=l;n[s+4>>2]=h;s=c;n[s>>2]=0;n[s+4>>2]=0;s=n[i>>2]|0}Hm[n[n[s>>2]>>2]&63](s,t)|0;h=c;h=sm(n[h>>2]|0,n[h+4>>2]|0,1,0)|0;d=v()|0;p=c;n[p>>2]=h;n[p+4>>2]=d;J=u;return}function Zs(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;o=J;J=J+64|0;i=o+56|0;r=o;A=si(s)|0;if((A|0)==-1){o=C(8)|0;ii(o);E(o|0,2784,8)}s=ri(s)|0;e:do{if(!s)switch(A|0){case 0:{A=Zf(4788)|0;pi(A);di(e,t,A);break e}case 1:{A=Zf(5116)|0;gi(A);fi(e,t,A);break e}case 2:{A=Zf(5104)|0;_i(A);mi(e,t,A);break e}case 3:{A=Zf(5432)|0;yi(A);bi(e,t,A);break e}default:{n[e>>2]=0;n[e+4>>2]=0;break e}}else{ni(i,t);Ai(n[i>>2]|0);if((A|2|0)==3)oi(n[i>>2]|0);if((A|1|0)==3)ai(n[i>>2]|0);A=n[i>>2]|0;ci(r,s);li(A,r);hi(r);n[e>>2]=n[i>>2];A=i+4|0;n[e+4>>2]=n[A>>2];n[i>>2]=0;n[A>>2]=0;ui(i)}}while(0);J=o;return}function Js(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4576;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ys(e,i);J=s;return}function Ys(e,t){e=e|0;t=t|0;return}function $s(e){e=e|0;Ag(e);qp(e);return}function qs(e){e=e|0;e=n[e+12>>2]|0;if(e|0){as(e);qp(e)}return}function ei(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==7983?e+12|0:0)|0}function ti(e){e=e|0;ye(e,16);return}function si(e){e=e|0;var t=0,s=0;t=(n[e+4>>2]|0)-(n[e>>2]|0)|0;e:do{if(((t|0)!=0?(s=((t|0)/12|0)+(((ri(e)|0)!=0)<<31>>31)|0,(s|0)!=0):0)?(t=n[e>>2]|0,!(Bi(t,wi()|0)|0)):0){switch(s|0){case 1:{e=0;break e}case 2:{if(vi((n[e>>2]|0)+12|0,Ci()|0)|0){e=1;break e}if(vi((n[e>>2]|0)+12|0,Mi()|0)|0){e=2;break e}break}case 3:{if(vi((n[e>>2]|0)+12|0,Ci()|0)|0?(s=(n[e>>2]|0)+24|0,vi(s,Mi()|0)|0):0){e=3;break e}break}default:{}}e=-1}else e=-1}while(0);return e|0}function ii(e){e=e|0;pg(e,8131);n[e>>2]=4604;return}function ri(e){e=e|0;var t=0,s=0;t=n[e+4>>2]|0;if(((t|0)!=(n[e>>2]|0)?(s=t,(n[s+-12>>2]|0)==0):0)?(n[s+-4>>2]|0)==2:0)e=n[s+-8>>2]|0;else e=0;return e|0}function ni(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;s=J;J=J+16|0;i=s+4|0;A=s;r=Zf(24)|0;Fi(r,t);n[A>>2]=0;n[i>>2]=n[A>>2];xi(e,r,i);J=s;return}function Ai(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(4792)|0;Ni(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];Gi(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function oi(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(336)|0;zr(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];Wr(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function ai(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(324)|0;mn(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];_n(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function li(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;o=l+12|0;a=l;i=l+8|0;A=Zf(64)|0;Sn(A,n[e+4>>2]|0,t);r=e+8|0;n[i>>2]=0;n[o>>2]=n[i>>2];Dn(a,A,o);A=e+12|0;t=n[A>>2]|0;i=e+16|0;do{if(t>>>0>=(n[i>>2]|0)>>>0){t=(t-(n[r>>2]|0)>>3)+1|0;s=Zi(r)|0;if(s>>>0<t>>>0)Xg(r);else{c=n[r>>2]|0;h=(n[i>>2]|0)-c|0;i=h>>2;Wi(o,h>>3>>>0<s>>>1>>>0?i>>>0<t>>>0?t:i:s,(n[A>>2]|0)-c>>3,e+16|0);e=o+8|0;A=n[e>>2]|0;n[A>>2]=n[a>>2];i=a+4|0;n[A+4>>2]=n[i>>2];n[a>>2]=0;n[i>>2]=0;n[e>>2]=A+8;Xi(r,o);Ki(o);break}}else{ji(o,r,1);h=o+4|0;c=n[h>>2]|0;n[c>>2]=n[a>>2];e=a+4|0;n[c+4>>2]=n[e>>2];n[a>>2]=0;n[e>>2]=0;n[h>>2]=c+8;zi(o)}}while(0);ki(a);J=l;return}function ci(e,t){e=e|0;t=t|0;var s=0,r=0;s=J;J=J+48|0;r=s;n[e>>2]=t;i[e+4>>0]=0;EA(e+8|0,t);EA(e+20|0,t);Ts(r,256,0,0);FA(e+32|0,t,r);Ms(r);J=s;return}function hi(e){e=e|0;IA(e+32|0);Gn(e+20|0);Gn(e+8|0);return}function ui(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function di(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;i=J;J=J+16|0;r=i+4|0;o=i;A=Zf(12)|0;TA(A,t,s);n[o>>2]=0;n[r>>2]=n[o>>2];PA(e,A,r);J=i;return}function pi(e){e=e|0;Yi(e);jA(e+4784|0);return}function fi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;i=J;J=J+16|0;r=i+4|0;o=i;A=Zf(12)|0;zA(A,t,s);n[o>>2]=0;n[r>>2]=n[o>>2];WA(e,A,r);J=i;return}function gi(e){e=e|0;Yi(e);ro(e+4784|0);return}function mi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;i=J;J=J+16|0;r=i+4|0;o=i;A=Zf(12)|0;no(A,t,s);n[o>>2]=0;n[r>>2]=n[o>>2];Ao(e,A,r);J=i;return}function _i(e){e=e|0;Yi(e);bo(e+4784|0);return}function bi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;i=J;J=J+16|0;r=i+4|0;o=i;A=Zf(12)|0;yo(A,t,s);n[o>>2]=0;n[r>>2]=n[o>>2];Bo(e,A,r);J=i;return}function yi(e){e=e|0;Yi(e);So(e+4784|0);return}function Bi(e,t){e=e|0;t=t|0;return(vi(e,t)|0)^1|0}function wi(){if((i[21456]|0)==0?Qf(21456)|0:0){Gt(21536,6,20,2);jf(21456)}return 21536}function vi(e,t){e=e|0;t=t|0;if((n[e>>2]|0)==(n[t>>2]|0)?(n[e+8>>2]|0)==(n[t+8>>2]|0):0)e=(n[e+4>>2]|0)==(n[t+4>>2]|0);else e=0;return e|0}function Ci(){if((i[21464]|0)==0?Qf(21464)|0:0){Gt(21548,7,8,2);jf(21464)}return 21548}function Mi(){if((i[21472]|0)==0?Qf(21472)|0:0){Gt(21560,8,6,2);jf(21472)}return 21560}function Ei(e){e=e|0;ff(e);qp(e);return}function Fi(e,t){e=e|0;t=t|0;Ui(e);n[e>>2]=4624;n[e+4>>2]=t;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;i[e+20>>0]=1;return}function xi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4664;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ri(e,i);J=s;return}function Ui(e){e=e|0;n[e>>2]=4644;return}function Ii(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0,a=0,l=0,c=0;c=J;J=J+16|0;o=c;s=n[e+8>>2]|0;a=n[e+12>>2]|0;if((s|0)!=(a|0)){l=o+4|0;do{r=n[s>>2]|0;n[o>>2]=r;A=n[s+4>>2]|0;n[l>>2]=A;if(A|0){A=A+4|0;n[A>>2]=(n[A>>2]|0)+1}t=Hm[n[(n[r>>2]|0)+12>>2]&63](r,t)|0;ki(o);s=s+8|0}while((s|0)!=(a|0))}s=e+20|0;if(i[s>>0]|0){i[s>>0]=0;rs(n[e+4>>2]|0)}J=c;return t|0}function Ti(e){e=e|0;n[e>>2]=4624;Qi(e+8|0);Si(e);return}function Pi(e){e=e|0;Ti(e);qp(e);return}function Si(e){e=e|0;return}function Di(e){e=e|0;Z()}function ki(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Qi(e){e=e|0;var t=0,s=0,i=0;s=n[e>>2]|0;if(s|0){i=e+4|0;t=n[i>>2]|0;if((t|0)==(s|0))t=s;else{do{t=t+-8|0;ki(t)}while((t|0)!=(s|0));t=n[e>>2]|0}n[i>>2]=s;ye(t,(n[e+8>>2]|0)-t|0)}return}function Ri(e,t){e=e|0;t=t|0;return}function Oi(e){e=e|0;Ag(e);qp(e);return}function Vi(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function Li(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==8546?e+12|0:0)|0}function Hi(e){e=e|0;ye(e,16);return}function Ni(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=4692;n[e+4>>2]=t;Yi(e+8|0);return}function Gi(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4740;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function ji(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+(s<<3);return}function zi(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function Wi(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>536870911){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t<<3)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s<<3)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t<<3);return}function Xi(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0;a=n[e>>2]|0;l=e+4|0;s=n[l>>2]|0;o=t+4|0;if((s|0)==(a|0)){r=o;A=e;i=n[o>>2]|0;s=a}else{i=n[o>>2]|0;do{A=s;s=s+-8|0;n[i+-8>>2]=n[s>>2];A=A+-4|0;n[i+-4>>2]=n[A>>2];n[s>>2]=0;n[A>>2]=0;i=(n[o>>2]|0)+-8|0;n[o>>2]=i}while((s|0)!=(a|0));r=o;A=e;s=n[e>>2]|0}n[A>>2]=i;n[r>>2]=s;a=t+8|0;o=n[l>>2]|0;n[l>>2]=n[a>>2];n[a>>2]=o;a=e+8|0;l=t+12|0;e=n[a>>2]|0;n[a>>2]=n[l>>2];n[l>>2]=e;n[t>>2]=n[r>>2];return}function Ki(e){e=e|0;var t=0,s=0,i=0,r=0;s=n[e+4>>2]|0;i=e+8|0;t=n[i>>2]|0;if((t|0)!=(s|0))do{r=t+-8|0;n[i>>2]=r;ki(r);t=n[i>>2]|0}while((t|0)!=(s|0));t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function Zi(e){e=e|0;return 536870911}function Ji(e){e=e|0;n[e>>2]=4716;return}function Yi(e){e=e|0;nr(e);Ar(e+3980|0);or(e+4380|0);i[e+4780>>0]=0;i[e+4781>>0]=0;return}function $i(e){e=e|0;n[e>>2]=4692;gr(e+8|0);sr(e);return}function qi(e){e=e|0;$i(e);qp(e);return}function er(e,t){e=e|0;t=t|0;return t|0}function tr(e,t){e=e|0;t=t|0;return _r(e+8|0,n[e+4>>2]|0,t)|0}function sr(e){e=e|0;return}function ir(e){e=e|0;sr(e);qp(e);return}function rr(e,t){e=e|0;t=t|0;return t|0}function nr(e){e=e|0;var t=0,s=0;cr(e);hr(e+52|0);hr(e+436|0);Ts(e+852|0,64,0,0);i[e+3976>>0]=0;t=e+20|0;s=t+32|0;do{r[t>>1]=0;t=t+2|0}while((t|0)<(s|0));t=Zf(44)|0;Ts(t,256,0,0);n[e+896>>2]=t;t=Zf(44)|0;Ts(t,256,0,0);n[e+900>>2]=t;t=e+820|0;n[t>>2]=0;n[t+4>>2]=0;n[t+8>>2]=0;n[t+12>>2]=0;n[t+16>>2]=0;n[t+20>>2]=0;n[t+24>>2]=0;n[t+28>>2]=0;t=0;do{s=Zf(44)|0;Ts(s,256,0,0);n[e+904+(t<<2)>>2]=s;s=Zf(44)|0;Ts(s,256,0,0);n[e+1928+(t<<2)>>2]=s;s=Zf(44)|0;Ts(s,256,0,0);n[e+2952+(t<<2)>>2]=s;t=t+1|0}while(t>>>0<256);return}function Ar(e){e=e|0;pr(e,16,4,8,0);pr(e+80|0,16,1,8,0);pr(e+160|0,32,2,8,0);pr(e+240|0,32,22,8,0);pr(e+320|0,32,20,8,0);return}function or(e){e=e|0;is(e,16,4,8,0);is(e+80|0,16,1,8,0);is(e+160|0,32,2,8,0);is(e+240|0,32,22,8,0);is(e+320|0,32,20,8,0);return}function ar(e){e=e|0;fr(e+320|0);fr(e+240|0);fr(e+160|0);fr(e+80|0);fr(e);return}function lr(e){e=e|0;var t=0,s=0;t=n[e+896>>2]|0;if(t|0){Ms(t);qp(t)}t=n[e+900>>2]|0;if(t|0){Ms(t);qp(t)}s=0;do{t=n[e+904+(s<<2)>>2]|0;if(t|0){Ms(t);qp(t)}t=n[e+1928+(s<<2)>>2]|0;if(t|0){Ms(t);qp(t)}t=n[e+2952+(s<<2)>>2]|0;if(t|0){Ms(t);qp(t)}s=s+1|0}while((s|0)!=256);Ms(e+852|0);return}function cr(e){e=e|0;var t=0;i[e>>0]=0;i[e+1>>0]=0;i[e+2>>0]=0;i[e+3>>0]=0;t=e+4|0;i[t>>0]=0;i[t+1>>0]=0;i[t+2>>0]=0;i[t+3>>0]=0;e=e+12|0;t=e;i[t>>0]=0;i[t+1>>0]=0;i[t+2>>0]=0;i[t+3>>0]=0;e=e+4|0;i[e>>0]=0;i[e+1>>0]=0;i[e+2>>0]=0;i[e+3>>0]=0;return}function hr(e){e=e|0;var t=0;t=e+384|0;do{ur(e);e=e+24|0}while((e|0)!=(t|0));return}function ur(e){e=e|0;dr(e);return}function dr(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;i[e+20>>0]=1;return}function pr(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var A=0;n[e+4>>2]=t;n[e+8>>2]=s;n[e+12>>2]=i;n[e+16>>2]=r;n[e+36>>2]=0;n[e+40>>2]=0;n[e+44>>2]=0;vs(e+48|0);n[e+68>>2]=0;n[e+72>>2]=0;n[e+76>>2]=0;do{if(!r){s=e+20|0;if((t+-1|0)>>>0<31){n[s>>2]=t;r=1<<t;n[e+24>>2]=r;s=r>>>1;n[e+28>>2]=0-s;s=r+-1-s|0;break}else{n[s>>2]=32;n[e+24>>2]=0;n[e+28>>2]=-2147483648;s=2147483647;break}}else{i=e+20|0;n[i>>2]=0;n[e+24>>2]=r;s=r;A=0;while(1){s=s>>>1;t=A+1|0;if(!s)break;else A=t}n[i>>2]=(1<<A|0)==(r|0)?A:t;s=r>>>1;n[e+28>>2]=0-s;s=r+-1-s|0}}while(0);n[e+32>>2]=s;n[e>>2]=0;return}function fr(e){e=e|0;var t=0,s=0,i=0,r=0,A=0;A=e+36|0;s=n[A>>2]|0;i=e+40|0;t=n[i>>2]|0;if((t|0)!=(s|0))do{t=t+-44|0;Ms(t)}while((t|0)!=(s|0));n[i>>2]=s;i=e+68|0;r=n[i>>2]|0;s=e+72|0;t=n[s>>2]|0;if((t|0)!=(r|0))do{t=t+-44|0;Ms(t)}while((t|0)!=(r|0));n[s>>2]=r;Cs(i);Cs(A);return}function gr(e){e=e|0;mr(e+4380|0);ar(e+3980|0);lr(e);return}function mr(e){e=e|0;os(e+320|0);os(e+240|0);os(e+160|0);os(e+80|0);os(e);return}function _r(e,t,s){e=e|0;t=t|0;s=s|0;var a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+32|0;p=f;a=e+4781|0;if(!(i[a>>0]|0)){br(e+4380|0);i[a>>0]=1}a=e+3976|0;if(!(i[a>>0]|0)){i[a>>0]=1;Br(yr(t)|0,s,20);wr(p,s);c=e;a=p;l=c+20|0;do{i[c>>0]=i[a>>0]|0;c=c+1|0;a=a+1|0}while((c|0)<(l|0));r[e+12>>1]=0}else{u=Ns(t,e+852|0)|0;if(u){if(u&32|0)Cr((Ns(t,n[e+904+(((vr(e)|0)&255)<<2)>>2]|0)|0)&255,e);d=e+14|0;c=i[d>>0]|0;a=c&7;c=(c&255)>>>3&7;l=A[16+(c<<3)+a>>0]|0;a=A[80+(c<<3)+a>>0]|0;if(!(u&16))h=r[e+20+(l<<1)>>1]|0;else{g=e+20+(l<<1)|0;h=(As(e+4380|0,t,o[g>>1]|0,l>>>0<3?l:3)|0)&65535;r[g>>1]=h}r[e+12>>1]=h;if(u&8|0){g=e+15|0;i[g>>0]=Ns(t,n[e+1928+(A[g>>0]<<2)>>2]|0)|0}if(u&4|0){d=Ns(t,n[e+896+(((A[d>>0]|0)>>>6&1)<<2)>>2]|0)|0;g=e+16|0;i[g>>0]=Mr(d+(i[g>>0]|0)|0)|0}if(u&2|0){g=e+17|0;i[g>>0]=Ns(t,n[e+2952+(A[g>>0]<<2)>>2]|0)|0}if(u&1){g=e+18|0;r[g>>1]=As(e+4460|0,t,o[g>>1]|0,0)|0}}else{g=i[e+14>>0]|0;a=g&7;g=(g&255)>>>3&7;c=g;l=A[16+(g<<3)+a>>0]|0;a=A[80+(g<<3)+a>>0]|0}h=e+52+(l*24|0)|0;u=e+4540|0;d=(c|0)==1&1;c=As(u,t,Er(h)|0,d)|0;n[p>>2]=c;n[e>>2]=(n[e>>2]|0)+c;Fr(h,p);h=e+436+(l*24|0)|0;c=Er(h)|0;l=xr(u)|0;g=e+4620|0;l=As(g,t,c,(l>>>0<20?l&-2:20)|d)|0;n[p>>2]=l;c=e+4|0;n[c>>2]=(n[c>>2]|0)+l;Fr(h,p);p=xr(u)|0;p=(xr(g)|0)+p|0;g=e+820+(a<<2)|0;p=As(e+4700|0,t,n[g>>2]|0,(p>>>0<36?p>>>1&2147483646:18)|d)|0;n[e+8>>2]=p;n[g>>2]=p;Ur(e,s)}J=f;return s+20|0}function br(e){e=e|0;ns(e);ns(e+80|0);ns(e+160|0);ns(e+240|0);ns(e+320|0);return}function yr(e){e=e|0;return n[e>>2]|0}function Br(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0;c=e+4|0;r=n[c>>2]|0;l=(n[e+8>>2]|0)-r|0;l=l>>>0>s>>>0?s:l;a=e+12|0;A=(n[a>>2]|0)+r|0;o=A+l|0;if(l){r=A;A=t;while(1){i[A>>0]=i[r>>0]|0;r=r+1|0;if((r|0)==(o|0))break;else A=A+1|0}r=n[c>>2]|0}n[c>>2]=r+l;s=s-l|0;if(s|0){Fs(e);A=(n[a>>2]|0)+(n[c>>2]|0)|0;o=A+s|0;r=t+l|0;while(1){i[r>>0]=i[A>>0]|0;A=A+1|0;if((A|0)==(o|0))break;else r=r+1|0}n[c>>2]=(n[c>>2]|0)+s}return}function wr(e,t){e=e|0;t=t|0;cr(e);n[e>>2]=Ir(t)|0;n[e+4>>2]=Ir(t+4|0)|0;n[e+8>>2]=Ir(t+8|0)|0;r[e+12>>1]=Tr(t+12|0)|0;Cr(Pr(t+14|0)|0,e);i[e+15>>0]=Pr(t+15|0)|0;i[e+16>>0]=Sr(t+16|0)|0;i[e+17>>0]=Sr(t+17|0)|0;r[e+18>>1]=Tr(t+18|0)|0;return}function vr(e){e=e|0;return i[e+14>>0]|0}function Cr(e,t){e=e|0;t=t|0;i[t+14>>0]=e;return}function Mr(e){e=e|0;return e&255|0}function Er(e){e=e|0;return n[e+8>>2]|0}function Fr(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0,a=0,l=0,c=0;c=e+20|0;do{if(!(i[c>>0]|0)){l=e+8|0;s=n[l>>2]|0;r=n[t>>2]|0;A=e+4|0;o=n[A>>2]|0;if((s|0)>=(r|0)){if((o|0)<(r|0)){n[e>>2]=o;n[A>>2]=n[t>>2]}else n[e>>2]=r;i[c>>0]=1;break}n[e>>2]=o;n[A>>2]=s;A=e+16|0;o=n[A>>2]|0;a=n[t>>2]|0;s=e+12|0;r=n[s>>2]|0;if((o|0)<(a|0)){n[l>>2]=r;n[s>>2]=o;n[A>>2]=n[t>>2];break}if((r|0)<(a|0)){n[l>>2]=r;n[s>>2]=n[t>>2];break}else{n[l>>2]=a;break}}else{A=n[t>>2]|0;a=e+8|0;s=n[a>>2]|0;o=e+12|0;r=n[o>>2]|0;if((A|0)>=(s|0)){s=e+16|0;if((A|0)<(r|0)){n[s>>2]=r;n[o>>2]=n[t>>2]}else n[s>>2]=A;i[c>>0]=0;break}n[e+16>>2]=r;n[o>>2]=s;s=n[t>>2]|0;r=n[e>>2]|0;A=e+4|0;o=n[A>>2]|0;if((s|0)<(r|0)){n[a>>2]=o;n[A>>2]=r;n[e>>2]=n[t>>2];break}if((s|0)<(o|0)){n[a>>2]=o;n[A>>2]=n[t>>2];break}else{n[a>>2]=s;break}}}while(0);return}function xr(e){e=e|0;return n[e>>2]|0}function Ur(e,t){e=e|0;t=t|0;var s=0;kr(A[e>>0]|A[e+1>>0]<<8|A[e+2>>0]<<16|A[e+3>>0]<<24,t);s=e+4|0;kr(A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24,t+4|0);s=e+8|0;kr(A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24,t+8|0);s=e+12|0;Qr(A[s>>0]|A[s+1>>0]<<8,t+12|0);Rr(vr(e)|0,t+14|0);Rr(i[e+15>>0]|0,t+15|0);Or(i[e+16>>0]|0,t+16|0);Or(i[e+17>>0]|0,t+17|0);e=e+18|0;Qr(A[e>>0]|A[e+1>>0]<<8,t+18|0);return}function Ir(e){e=e|0;return Dr(e)|0}function Tr(e){e=e|0;return(i[e+1>>0]<<8|A[e>>0])&65535|0}function Pr(e){e=e|0;return i[e>>0]|0}function Sr(e){e=e|0;return i[e>>0]|0}function Dr(e){e=e|0;return(A[e+1>>0]|0)<<8|(A[e>>0]|0)|(A[e+2>>0]|0)<<16|(A[e+3>>0]|0)<<24|0}function kr(e,t){e=e|0;t=t|0;Vr(e,t);return}function Qr(e,t){e=e|0;t=t|0;i[t+1>>0]=(e&65535)>>>8;i[t>>0]=e;return}function Rr(e,t){e=e|0;t=t|0;i[t>>0]=e;return}function Or(e,t){e=e|0;t=t|0;i[t>>0]=e;return}function Vr(e,t){e=e|0;t=t|0;i[t+3>>0]=e>>>24;i[t+2>>0]=e>>>16;i[t+1>>0]=e>>>8;i[t>>0]=e;return}function Lr(e,t){e=e|0;t=t|0;return}function Hr(e){e=e|0;Ag(e);qp(e);return}function Nr(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Gr(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==9202?e+12|0:0)|0}function jr(e){e=e|0;ye(e,16);return}function zr(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=4768;n[e+4>>2]=t;Xr(e+8|0);return}function Wr(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4792;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function Xr(e){e=e|0;Yr(e);$r(e+164|0);qr(e+244|0);i[e+324>>0]=0;i[e+325>>0]=0;return}function Kr(e){e=e|0;n[e>>2]=4768;nn(e+8|0);sr(e);return}function Zr(e){e=e|0;Kr(e);qp(e);return}function Jr(e,t){e=e|0;t=t|0;return on(e+8|0,n[e+4>>2]|0,t)|0}function Yr(e){e=e|0;var t=0,s=0,r=0,A=0,o=0,a=0,l=0;o=J;J=J+16|0;r=o;i[e>>0]=0;Ts(e+4|0,516,0,0);Ts(e+48|0,6,0,0);n[e+92>>2]=0;n[e+96>>2]=0;s=e+100|0;sn(s);rn(r);A=n[r>>2]|0;r=n[r+4>>2]|0;t=4;while(1){a=s;l=a;i[l>>0]=A;i[l+1>>0]=A>>8;i[l+2>>0]=A>>16;i[l+3>>0]=A>>24;a=a+4|0;i[a>>0]=r;i[a+1>>0]=r>>8;i[a+2>>0]=r>>16;i[a+3>>0]=r>>24;t=t+-1|0;if(!t)break;else s=s+8|0}l=e+132|0;n[l>>2]=0;n[l+4>>2]=0;n[l+8>>2]=0;n[l+12>>2]=0;n[l+16>>2]=0;n[l+20>>2]=0;n[l+24>>2]=0;n[l+28>>2]=0;J=o;return}function $r(e){e=e|0;pr(e,32,9,8,0);return}function qr(e){e=e|0;is(e,32,9,8,0);return}function en(e){e=e|0;fr(e);return}function tn(e){e=e|0;Ms(e+48|0);Ms(e+4|0);return}function sn(e){e=e|0;var t=0;t=e+32|0;do{rn(e);e=e+8|0}while((e|0)!=(t|0));return}function rn(e){e=e|0;var t=0;t=e;i[t>>0]=0;i[t+1>>0]=0;i[t+2>>0]=0;i[t+3>>0]=0;e=e+4|0;i[e>>0]=0;i[e+1>>0]=0;i[e+2>>0]=0;i[e+3>>0]=0;return}function nn(e){e=e|0;An(e+244|0);en(e+164|0);tn(e);return}function An(e){e=e|0;os(e);return}function on(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,o=0,a=0,l=0,c=0;r=e+325|0;if(!(i[r>>0]|0)){an(e+244|0);i[r>>0]=1}if(!(i[e>>0]|0)){i[e>>0]=1;Br(yr(t)|0,s,8);a=ln(s)|0;l=v()|0;e=e+100|0;t=e;i[t>>0]=a;i[t+1>>0]=a>>8;i[t+2>>0]=a>>16;i[t+3>>0]=a>>24;e=e+4|0;i[e>>0]=l;i[e+1>>0]=l>>8;i[e+2>>0]=l>>16;i[e+3>>0]=l>>24}else{l=e+92|0;e:do{if(!(n[e+132+(n[l>>2]<<2)>>2]|0)){r=Ns(t,e+48|0)|0;switch(r|0){case 1:{t=As(e+244|0,t,0,0)|0;n[e+132+(n[l>>2]<<2)>>2]=t;t=n[l>>2]|0;c=n[e+132+(t<<2)>>2]|0;a=e+100+(t<<3)|0;o=a;r=o;o=o+4|0;c=sm(A[r>>0]|A[r+1>>0]<<8|A[r+2>>0]<<16|A[r+3>>0]<<24|0,A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|0,c|0,((c|0)<0)<<31>>31|0)|0;o=v()|0;r=a;i[r>>0]=c;i[r+1>>0]=c>>8;i[r+2>>0]=c>>16;i[r+3>>0]=c>>24;a=a+4|0;i[a>>0]=o;i[a+1>>0]=o>>8;i[a+2>>0]=o>>16;i[a+3>>0]=o>>24;n[e+148+(t<<2)>>2]=0;break e}case 2:{c=e+96|0;n[c>>2]=(n[c>>2]|0)+1&3;a=e+100+(n[l>>2]<<3)+4|0;a=As(e+244|0,t,A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24,8)|0;r=e+100+(n[c>>2]<<3)|0;o=r;i[o>>0]=0;i[o+1>>0]=0;i[o+2>>0]=0;i[o+3>>0]=0;r=r+4|0;i[r>>0]=a;i[r+1>>0]=a>>8;i[r+2>>0]=a>>16;i[r+3>>0]=a>>24;r=cn(t)|0;c=n[c>>2]|0;t=e+100+(c<<3)|0;a=t;o=a;a=a+4|0;a=A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24;r=A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|r;o=t;i[o>>0]=r;i[o+1>>0]=r>>8;i[o+2>>0]=r>>16;i[o+3>>0]=r>>24;t=t+4|0;i[t>>0]=a;i[t+1>>0]=a>>8;i[t+2>>0]=a>>16;i[t+3>>0]=a>>24;n[l>>2]=c;n[e+132+(c<<2)>>2]=0;n[e+148+(n[l>>2]<<2)>>2]=0;break e}default:{if((r|0)<=2)break e;n[l>>2]=r+2+(n[l>>2]|0)&3;on(e,t,s)|0;break e}}}else{a=Ns(t,e+4|0)|0;if((a|0)==1){r=As(e+244|0,t,n[e+132+(n[l>>2]<<2)>>2]|0,1)|0;c=n[l>>2]|0;t=e+100+(c<<3)|0;a=t;o=a;a=a+4|0;r=sm(A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|0,A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24|0,r|0,((r|0)<0)<<31>>31|0)|0;a=v()|0;o=t;i[o>>0]=r;i[o+1>>0]=r>>8;i[o+2>>0]=r>>16;i[o+3>>0]=r>>24;t=t+4|0;i[t>>0]=a;i[t+1>>0]=a>>8;i[t+2>>0]=a>>16;i[t+3>>0]=a>>24;n[e+148+(c<<2)>>2]=0;break}if((a|0)>=511){if((a|0)==512){c=e+96|0;n[c>>2]=(n[c>>2]|0)+1&3;a=e+100+(n[l>>2]<<3)+4|0;a=As(e+244|0,t,A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24,8)|0;r=e+100+(n[c>>2]<<3)|0;o=r;i[o>>0]=0;i[o+1>>0]=0;i[o+2>>0]=0;i[o+3>>0]=0;r=r+4|0;i[r>>0]=a;i[r+1>>0]=a>>8;i[r+2>>0]=a>>16;i[r+3>>0]=a>>24;r=cn(t)|0;c=n[c>>2]|0;t=e+100+(c<<3)|0;a=t;o=a;a=a+4|0;a=A[a>>0]|A[a+1>>0]<<8|A[a+2>>0]<<16|A[a+3>>0]<<24;r=A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|r;o=t;i[o>>0]=r;i[o+1>>0]=r>>8;i[o+2>>0]=r>>16;i[o+3>>0]=r>>24;t=t+4|0;i[t>>0]=a;i[t+1>>0]=a>>8;i[t+2>>0]=a>>16;i[t+3>>0]=a>>24;n[l>>2]=c;n[e+132+(c<<2)>>2]=0;n[e+148+(n[l>>2]<<2)>>2]=0;break}if((a|0)<=511)break;n[l>>2]=(n[l>>2]|0)+a&3;on(e,t,s)|0;break}do{if(!a){r=As(e+244|0,t,0,7)|0;o=e+148+(n[l>>2]<<2)|0;n[o>>2]=(n[o>>2]|0)+1;o=n[l>>2]|0;if((n[e+148+(o<<2)>>2]|0)>3){n[e+132+(o<<2)>>2]=r;n[e+148+(n[l>>2]<<2)>>2]=0}}else{if((a|0)<500){r=e+244|0;o=b(n[e+132+(n[l>>2]<<2)>>2]|0,a)|0;if((a|0)<10){r=As(r,t,o,2)|0;break}else{r=As(r,t,o,3)|0;break}}if((a|0)==500){r=As(e+244|0,t,(n[e+132+(n[l>>2]<<2)>>2]|0)*500|0,4)|0;o=e+148+(n[l>>2]<<2)|0;n[o>>2]=(n[o>>2]|0)+1;o=n[l>>2]|0;if((n[e+148+(o<<2)>>2]|0)<=3)break;n[e+132+(o<<2)>>2]=r;n[e+148+(n[l>>2]<<2)>>2]=0;break}r=500-a|0;o=e+244|0;a=n[e+132+(n[l>>2]<<2)>>2]|0;if((r|0)>-10){r=As(o,t,b(a,r)|0,5)|0;break}r=As(o,t,b(a,-10)|0,6)|0;o=e+148+(n[l>>2]<<2)|0;n[o>>2]=(n[o>>2]|0)+1;o=n[l>>2]|0;if((n[e+148+(o<<2)>>2]|0)>3){n[e+132+(o<<2)>>2]=r;n[e+148+(n[l>>2]<<2)>>2]=0}}}while(0);c=e+100+(n[l>>2]<<3)|0;o=c;t=o;o=o+4|0;o=sm(A[t>>0]|A[t+1>>0]<<8|A[t+2>>0]<<16|A[t+3>>0]<<24|0,A[o>>0]|A[o+1>>0]<<8|A[o+2>>0]<<16|A[o+3>>0]<<24|0,r|0,((r|0)<0)<<31>>31|0)|0;t=v()|0;a=c;i[a>>0]=o;i[a+1>>0]=o>>8;i[a+2>>0]=o>>16;i[a+3>>0]=o>>24;c=c+4|0;i[c>>0]=t;i[c+1>>0]=t>>8;i[c+2>>0]=t>>16;i[c+3>>0]=t>>24}}while(0);hn(e+100+(n[l>>2]<<3)|0,s)}return s+8|0}function an(e){e=e|0;ns(e);return}function ln(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;i=Dr(e)|0;un(s,i,Dr(e+4|0)|0);e=n[s>>2]|0;w(n[s+4>>2]|0);J=t;return e|0}function cn(e){e=e|0;var t=0;t=(Ws(e)|0)&65535;return((Ws(e)|0)&65535)<<16|t|0}function hn(e,t){e=e|0;t=t|0;var s=0;s=e;Vr(A[s>>0]|A[s+1>>0]<<8|A[s+2>>0]<<16|A[s+3>>0]<<24,t);e=e+4|0;Vr(A[e>>0]|A[e+1>>0]<<8|A[e+2>>0]<<16|A[e+3>>0]<<24,t+4|0);return}function un(e,t,s){e=e|0;t=t|0;s=s|0;var r=0;r=e;i[r>>0]=t;i[r+1>>0]=t>>8;i[r+2>>0]=t>>16;i[r+3>>0]=t>>24;t=e+4|0;i[t>>0]=s;i[t+1>>0]=s>>8;i[t+2>>0]=s>>16;i[t+3>>0]=s>>24;return}function dn(e){e=e|0;Ag(e);qp(e);return}function pn(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function fn(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==9890?e+12|0:0)|0}function gn(e){e=e|0;ye(e,16);return}function mn(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=4820;n[e+4>>2]=t;bn(e+8|0);return}function _n(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4844;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function bn(e){e=e|0;i[e>>0]=0;vn(e+1|0);Ts(e+8|0,128,0,0);Ts(e+52|0,256,0,0);Ts(e+96|0,256,0,0);Ts(e+140|0,256,0,0);Ts(e+184|0,256,0,0);Ts(e+228|0,256,0,0);Ts(e+272|0,256,0,0);return}function yn(e){e=e|0;n[e>>2]=4820;Cn(e+8|0);sr(e);return}function Bn(e){e=e|0;yn(e);qp(e);return}function wn(e,t){e=e|0;t=t|0;return Mn(e+8|0,n[e+4>>2]|0,t)|0}function vn(e){e=e|0;var t=0;i[e>>0]=0;i[e+1>>0]=0;t=e+2|0;i[t>>0]=0;i[t+1>>0]=0;e=e+4|0;i[e>>0]=0;i[e+1>>0]=0;return}function Cn(e){e=e|0;Ms(e+272|0);Ms(e+228|0);Ms(e+184|0);Ms(e+140|0);Ms(e+96|0);Ms(e+52|0);Ms(e+8|0);return}function Mn(e,t,s){e=e|0;t=t|0;s=s|0;var n=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0;p=J;J=J+16|0;u=p;if(!(i[e>>0]|0)){i[e>>0]=1;Br(yr(t)|0,s,6);En(u,s);d=e+1|0;i[d>>0]=i[u>>0]|0;i[d+1>>0]=i[u+1>>0]|0;i[d+2>>0]=i[u+2>>0]|0;i[d+3>>0]=i[u+3>>0]|0;i[d+4>>0]=i[u+4>>0]|0;i[d+5>>0]=i[u+5>>0]|0}else{d=Ns(t,e+8|0)|0;vn(u);if(!(d&1)){n=e+1|0;n=(A[n>>0]|A[n+1>>0]<<8)&255}else{h=(Ns(t,e+52|0)|0)&255;n=e+1|0;n=(Mr(h+((A[n>>0]|A[n+1>>0]<<8)&255)|0)|0)&255}r[u>>1]=n;if(!(d&2)){h=e+1|0;n=n|(A[h>>0]|A[h+1>>0]<<8)&-256}else{n=(Ns(t,e+96|0)|0)&255;h=e+1|0;n=((Mr((((A[h>>0]|A[h+1>>0]<<8)&65535)>>>8)+n|0)|0)&255)<<8;n=(n|o[u>>1])&65535}r[u>>1]=n;do{if(d&64){c=e+1|0;a=(n&255)-((A[c>>0]|A[c+1>>0]<<8)&255)|0;if(!(d&4)){n=e+3|0;n=(A[n>>0]|A[n+1>>0]<<8)&255}else{n=(Ns(t,e+140|0)|0)&255;h=e+3|0;h=a+((A[h>>0]|A[h+1>>0]<<8)&255)|0;n=(Mr(((h|0)<1?0:(h|0)>254?255:h&255)+n|0)|0)&255}h=u+2|0;r[h>>1]=n;if(!(d&16)){n=e+5|0;n=(A[n>>0]|A[n+1>>0]<<8)&255}else{n=Ns(t,e+228|0)|0;f=e+3|0;l=e+5|0;l=((a+(r[h>>1]&255)-((A[f>>0]|A[f+1>>0]<<8)&255)|0)/2|0)+((A[l>>0]|A[l+1>>0]<<8)&255)|0;n=(Mr(((l|0)<1?0:(l|0)>254?255:l&255)+(n&255)|0)|0)&255}l=u+4|0;r[l>>1]=n;n=((o[u>>1]|0)>>>8)-(((A[c>>0]|A[c+1>>0]<<8)&65535)>>>8)|0;if(!(d&8)){a=e+3|0;a=r[h>>1]|(A[a>>0]|A[a+1>>0]<<8)&-256}else{a=(Ns(t,e+184|0)|0)&255;f=e+3|0;f=(((A[f>>0]|A[f+1>>0]<<8)&65535)>>>8)+n|0;a=((Mr(((f|0)<1?0:(f|0)>254?255:f&255)+a|0)|0)&255)<<8;a=(a|o[h>>1])&65535}r[h>>1]=a;if(!(d&32)){f=e+5|0;r[l>>1]=r[l>>1]|(A[f>>0]|A[f+1>>0]<<8)&-256;break}else{f=Ns(t,e+272|0)|0;t=e+3|0;d=e+5|0;d=((((o[h>>1]|0)>>>8)+n-(((A[t>>0]|A[t+1>>0]<<8)&65535)>>>8)|0)/2|0)+(((A[d>>0]|A[d+1>>0]<<8)&65535)>>>8)|0;f=((Mr(((d|0)<1?0:(d|0)>254?255:d&255)+(f&255)|0)|0)&255)<<8;r[l>>1]=f|o[l>>1];break}}else{r[u+2>>1]=n;r[u+4>>1]=n}}while(0);f=e+1|0;i[f>>0]=i[u>>0]|0;i[f+1>>0]=i[u+1>>0]|0;i[f+2>>0]=i[u+2>>0]|0;i[f+3>>0]=i[u+3>>0]|0;i[f+4>>0]=i[u+4>>0]|0;i[f+5>>0]=i[u+5>>0]|0;Fn(f,s)}J=p;return s+6|0}function En(e,t){e=e|0;t=t|0;var s=0,i=0;i=Tr(t)|0;s=Tr(t+2|0)|0;xn(e,i,s,Tr(t+4|0)|0);return}function Fn(e,t){e=e|0;t=t|0;var s=0;Qr(A[e>>0]|A[e+1>>0]<<8,t);s=e+2|0;Qr(A[s>>0]|A[s+1>>0]<<8,t+2|0);e=e+4|0;Qr(A[e>>0]|A[e+1>>0]<<8,t+4|0);return}function xn(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;i[e>>0]=t;i[e+1>>0]=t>>8;t=e+2|0;i[t>>0]=s;i[t+1>>0]=s>>8;s=e+4|0;i[s>>0]=r;i[s+1>>0]=r>>8;return}function Un(e){e=e|0;Ag(e);qp(e);return}function In(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Tn(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==10570?e+12|0:0)|0}function Pn(e){e=e|0;ye(e,16);return}function Sn(e,t,s){e=e|0;t=t|0;s=s|0;Ji(e);n[e>>2]=4872;n[e+4>>2]=t;kn(e+8|0,s);return}function Dn(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4896;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function kn(e,t){e=e|0;t=t|0;n[e>>2]=n[t>>2];i[e+4>>0]=i[t+4>>0]|0;Vn(e+8|0,t+8|0);Vn(e+20|0,t+20|0);Ln(e+32|0,t+32|0);return}function Qn(e){e=e|0;n[e>>2]=4872;hi(e+8|0);sr(e);return}function Rn(e){e=e|0;Qn(e);qp(e);return}function On(e,t){e=e|0;t=t|0;return yA(e+8|0,n[e+4>>2]|0,t)|0}function Vn(e,t){e=e|0;t=t|0;var s=0,i=0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;s=t+4|0;i=(n[s>>2]|0)-(n[t>>2]|0)|0;if(i|0){Hn(e,i);Nn(e,n[t>>2]|0,n[s>>2]|0,i)}return}function Ln(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+32|0;i=s+24|0;r=s+16|0;o=s+8|0;A=s;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;n[e+20>>2]=0;gA(o,t);mA(A,t);n[r>>2]=n[o>>2];n[r+4>>2]=n[o+4>>2];n[i>>2]=n[A>>2];n[i+4>>2]=n[A+4>>2];Xn(e,r,i,0);J=s;return}function Hn(e,t){e=e|0;t=t|0;var s=0;if((jn(e)|0)>>>0<t>>>0)Xg(e);else{s=Zf(t)|0;n[e+4>>2]=s;n[e>>2]=s;n[e+8>>2]=s+t;return}}function Nn(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;A=J;J=J+16|0;r=A;zn(r,e,i);i=r+4|0;e=s-t|0;if((e|0)>0){hm(n[i>>2]|0,t|0,e|0)|0;n[i>>2]=(n[i>>2]|0)+e}Wn(r);J=A;return}function Gn(e){e=e|0;var t=0,s=0;t=n[e>>2]|0;s=t;if(t|0){n[e+4>>2]=s;ye(t,(n[e+8>>2]|0)-s|0)}return}function jn(e){e=e|0;return 2147483647}function zn(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;t=n[t+4>>2]|0;n[e+4>>2]=t;n[e+8>>2]=t+s;return}function Wn(e){e=e|0;n[(n[e>>2]|0)+4>>2]=n[e+4>>2];return}function Xn(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;g=J;J=J+96|0;f=g+80|0;u=g+64|0;l=g+48|0;c=g+40|0;h=g+8|0;a=g;d=g+32|0;p=g+16|0;o=t;A=n[o>>2]|0;o=n[o+4>>2]|0;r=s;s=n[r>>2]|0;r=n[r+4>>2]|0;i=A;if((r|0)==(o|0))o=0;else o=((r-(n[s>>2]|0)|0)/44|0)+((s-A>>2)*93|0)+((o-(n[A>>2]|0)|0)/-44|0)|0;s=(n[e+8>>2]|0)-(n[e+4>>2]|0)|0;s=((s|0)==0?0:((s>>2)*93|0)+-1|0)-((n[e+20>>2]|0)+(n[e+16>>2]|0))|0;if(o>>>0>s>>>0)Zn(e,o-s|0);Jn(c,e);Jn(a,e);r=a;s=n[r>>2]|0;r=n[r+4>>2]|0;A=h;n[A>>2]=s;n[A+4>>2]=r;A=s;if(o|0){s=((r-(n[s>>2]|0)|0)/44|0)+o|0;if((s|0)>0){a=(s>>>0)/93|0;o=A+(a<<2)|0;n[h>>2]=o;s=(n[o>>2]|0)+((s-(a*93|0)|0)*44|0)|0}else{s=92-s|0;a=A+(((s|0)/-93|0)<<2)|0;n[h>>2]=a;s=(n[a>>2]|0)+((92-((s|0)%93|0)|0)*44|0)|0}n[h+4>>2]=s}n[u>>2]=n[c>>2];n[u+4>>2]=n[c+4>>2];n[f>>2]=n[h>>2];n[f+4>>2]=n[h+4>>2];Yn(l,u,f);$n(f,l);qn(u,l);if(eA(f,u)|0){A=p+4|0;o=t+4|0;do{tA(d,f);sA(p,e,d);s=n[p>>2]|0;if((s|0)!=(n[A>>2]|0)){r=n[o>>2]|0;do{Vs(s,r);s=(n[p>>2]|0)+44|0;n[p>>2]=s;r=r+44|0;n[o>>2]=r;if((r-(n[i>>2]|0)|0)==4092){i=i+4|0;n[t>>2]=i;r=n[i>>2]|0;n[o>>2]=r}}while((s|0)!=(n[A>>2]|0))}iA(p);rA(f)|0}while(eA(f,u)|0)}J=g;return}function Kn(e){e=e|0;var t=0,s=0,i=0;t=n[e+4>>2]|0;s=e+8|0;i=n[s>>2]|0;if((i|0)!=(t|0))n[s>>2]=i+(~((i+-4-t|0)>>>2)<<2);t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function Zn(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,y=0,B=0,w=0,v=0,C=0,M=0,E=0,F=0,x=0;F=J;J=J+64|0;B=F+52|0;y=F+48|0;w=F+28|0;v=F+24|0;C=F+20|0;f=F;M=e+8|0;s=n[M>>2]|0;E=e+4|0;l=n[E>>2]|0;m=((s|0)==(l|0)&1)+t|0;o=(m>>>0)/93|0;o=o+((m-(o*93|0)|0)!=0&1)|0;m=e+16|0;i=n[m>>2]|0;a=(i>>>0)/93|0;g=o>>>0<a>>>0?o:a;t=o-g|0;A=s;e:do{if(!t){n[m>>2]=(b(g,-93)|0)+i;if(g|0){a=e+12|0;c=e+12|0;h=w+4|0;u=w+8|0;d=w+12|0;t=g;i=l;while(1){o=n[i>>2]|0;A=i+4|0;n[E>>2]=A;_=n[a>>2]|0;i=_;do{if((s|0)==(_|0)){_=n[e>>2]|0;s=_;if(A>>>0<=_>>>0){s=i-s|0;s=(s|0)==0?1:s>>1;oA(w,s,s>>>2,c);n[v>>2]=n[E>>2];n[C>>2]=n[M>>2];n[y>>2]=n[v>>2];n[B>>2]=n[C>>2];hA(w,y,B);s=n[e>>2]|0;n[e>>2]=n[w>>2];n[w>>2]=s;s=n[E>>2]|0;n[E>>2]=n[h>>2];n[h>>2]=s;s=n[M>>2]|0;n[M>>2]=n[u>>2];n[u>>2]=s;s=n[a>>2]|0;n[a>>2]=n[d>>2];n[d>>2]=s;cA(w);s=n[M>>2]|0;break}_=A;s=((_-s>>2)+1|0)/-2|0;r=A+(s<<2)|0;i=i-_|0;if(!i)s=r;else{um(r|0,A|0,i|0)|0;s=(n[E>>2]|0)+(s<<2)|0}_=r+(i>>2<<2)|0;n[M>>2]=_;n[E>>2]=s;s=_}}while(0);n[s>>2]=o;s=(n[M>>2]|0)+4|0;n[M>>2]=s;t=t+-1|0;if(!t)break e;i=n[E>>2]|0}}}else{_=e+12|0;i=n[_>>2]|0;r=i-(n[e>>2]|0)|0;s=A-l>>2;if(t>>>0>((r>>2)-s|0)>>>0){p=r>>1;d=s+t|0;oA(f,p>>>0<d>>>0?d:p,s-g|0,e+12|0);do{n[B>>2]=Zf(4092)|0;aA(f,B);t=t+-1|0}while((t|0)!=0);if(!g)s=n[E>>2]|0;else{a=f+8|0;l=f+12|0;c=f+4|0;h=f+16|0;u=w+4|0;d=w+8|0;p=w+12|0;o=g;t=n[a>>2]|0;s=n[E>>2]|0;do{A=n[l>>2]|0;i=A;do{if((t|0)==(A|0)){r=n[c>>2]|0;A=n[f>>2]|0;t=A;if(r>>>0<=A>>>0){t=i-t|0;t=(t|0)==0?1:t>>1;oA(w,t,t>>>2,n[h>>2]|0);n[v>>2]=n[c>>2];n[C>>2]=n[a>>2];n[y>>2]=n[v>>2];n[B>>2]=n[C>>2];hA(w,y,B);t=n[f>>2]|0;n[f>>2]=n[w>>2];n[w>>2]=t;t=n[c>>2]|0;n[c>>2]=n[u>>2];n[u>>2]=t;t=n[a>>2]|0;n[a>>2]=n[d>>2];n[d>>2]=t;t=n[l>>2]|0;n[l>>2]=n[p>>2];n[p>>2]=t;cA(w);t=n[a>>2]|0;break}x=r;t=((x-t>>2)+1|0)/-2|0;A=r+(t<<2)|0;i=i-x|0;if(!i)t=A;else{um(A|0,r|0,i|0)|0;t=(n[c>>2]|0)+(t<<2)|0}x=A+(i>>2<<2)|0;n[a>>2]=x;n[c>>2]=t;t=x}}while(0);n[t>>2]=n[s>>2];t=(n[a>>2]|0)+4|0;n[a>>2]=t;s=(n[E>>2]|0)+4|0;n[E>>2]=s;o=o+-1|0}while((o|0)!=0)}t=n[M>>2]|0;if((t|0)!=(s|0)){do{t=t+-4|0;lA(f,t);s=n[E>>2]|0}while((t|0)!=(s|0));t=n[M>>2]|0}x=n[e>>2]|0;n[e>>2]=n[f>>2];n[f>>2]=x;x=f+4|0;n[E>>2]=n[x>>2];n[x>>2]=s;x=f+8|0;n[M>>2]=n[x>>2];n[x>>2]=t;x=f+12|0;E=n[_>>2]|0;n[_>>2]=n[x>>2];n[x>>2]=E;n[m>>2]=(n[m>>2]|0)+(b(g,-93)|0);cA(f);break}else{t:do{if((i|0)==(A|0))c=18;else{while(1){n[B>>2]=Zf(4092)|0;nA(e,B);t=t+-1|0;if(!t)break;if((n[_>>2]|0)==(n[M>>2]|0)){c=18;break t}}s=g;t=n[m>>2]|0}}while(0);if((c|0)==18){i=~(o>>>0>a>>>0?a:o);s=t;do{n[B>>2]=Zf(4092)|0;AA(e,B);s=s+-1|0;r=(((n[M>>2]|0)-(n[E>>2]|0)|0)==4?92:93)+(n[m>>2]|0)|0;n[m>>2]=r}while((s|0)!=0);s=t+-1-i|0;t=r}n[m>>2]=t+(b(s,-93)|0);if(!s)break;a=e+12|0;l=w+4|0;c=w+8|0;h=w+12|0;t=n[M>>2]|0;do{A=n[E>>2]|0;o=n[A>>2]|0;A=A+4|0;n[E>>2]=A;x=n[_>>2]|0;i=x;do{if((t|0)==(x|0)){x=n[e>>2]|0;t=x;if(A>>>0<=x>>>0){t=i-t|0;t=(t|0)==0?1:t>>1;oA(w,t,t>>>2,a);n[v>>2]=n[E>>2];n[C>>2]=n[M>>2];n[y>>2]=n[v>>2];n[B>>2]=n[C>>2];hA(w,y,B);t=n[e>>2]|0;n[e>>2]=n[w>>2];n[w>>2]=t;t=n[E>>2]|0;n[E>>2]=n[l>>2];n[l>>2]=t;t=n[M>>2]|0;n[M>>2]=n[c>>2];n[c>>2]=t;t=n[_>>2]|0;n[_>>2]=n[h>>2];n[h>>2]=t;cA(w);t=n[M>>2]|0;break}x=A;t=((x-t>>2)+1|0)/-2|0;r=A+(t<<2)|0;i=i-x|0;if(!i)t=r;else{um(r|0,A|0,i|0)|0;t=(n[E>>2]|0)+(t<<2)|0}x=r+(i>>2<<2)|0;n[M>>2]=x;n[E>>2]=t;t=x}}while(0);n[t>>2]=o;t=(n[M>>2]|0)+4|0;n[M>>2]=t;s=s+-1|0}while((s|0)!=0)}}}while(0);J=F;return}function Jn(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;s=(n[t+16>>2]|0)+(n[t+20>>2]|0)|0;A=n[t+4>>2]|0;i=(s>>>0)/93|0;r=A+(i<<2)|0;if((n[t+8>>2]|0)==(A|0))t=0;else t=(n[r>>2]|0)+((s-(i*93|0)|0)*44|0)|0;n[e>>2]=r;n[e+4>>2]=t;return}function Yn(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=t;t=n[r+4>>2]|0;i=e;n[i>>2]=n[r>>2];n[i+4>>2]=t;i=s;t=n[i+4>>2]|0;s=e+8|0;n[s>>2]=n[i>>2];n[s+4>>2]=t;return}function $n(e,t){e=e|0;t=t|0;n[e>>2]=n[t>>2];n[e+4>>2]=n[t+4>>2];n[e+8>>2]=n[t+8>>2];n[e+12>>2]=n[t+12>>2];return}function qn(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0;s=J;J=J+32|0;i=s+24|0;r=s+16|0;o=s+8|0;A=s;a=t+8|0;l=n[a>>2]|0;a=n[a+4>>2]|0;t=o;n[t>>2]=l;n[t+4>>2]=a;t=A;n[t>>2]=l;n[t+4>>2]=a;n[r>>2]=n[o>>2];n[r+4>>2]=n[o+4>>2];n[i>>2]=n[A>>2];n[i+4>>2]=n[A+4>>2];Yn(e,r,i);J=s;return}function eA(e,t){e=e|0;t=t|0;return(pA(e,t)|0)^1|0}function tA(e,t){e=e|0;t=t|0;var s=0,i=0;s=n[t>>2]|0;i=n[t+4>>2]|0;if((s|0)==(n[t+8>>2]|0))fA(e,i,n[t+12>>2]|0);else fA(e,i,(n[s>>2]|0)+4092|0);return}function sA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0;i=n[s>>2]|0;n[e>>2]=i;n[e+4>>2]=n[s+4>>2];n[e+8>>2]=i;n[e+12>>2]=t;return}function iA(e){e=e|0;var t=0;t=(n[e+12>>2]|0)+20|0;n[t>>2]=(n[t>>2]|0)+(((n[e>>2]|0)-(n[e+8>>2]|0)|0)/44|0);return}function rA(e){e=e|0;var t=0,s=0,i=0;t=n[e>>2]|0;s=e+8|0;if((t|0)==(n[s>>2]|0)){i=s;t=n[i+4>>2]|0;s=e;n[s>>2]=n[i>>2];n[s+4>>2]=t}else{i=t+4|0;n[e>>2]=i;n[e+4>>2]=n[i>>2]}return e|0}function nA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+48|0;r=f+32|0;i=f+28|0;a=f+8|0;l=f+4|0;c=f;p=e+8|0;s=n[p>>2]|0;h=e+12|0;d=n[h>>2]|0;A=d;do{if((s|0)==(d|0)){d=e+4|0;u=n[d>>2]|0;g=n[e>>2]|0;o=g;if(u>>>0<=g>>>0){s=A-o|0;s=(s|0)==0?1:s>>1;oA(a,s,s>>>2,e+12|0);n[l>>2]=n[d>>2];n[c>>2]=n[p>>2];n[i>>2]=n[l>>2];n[r>>2]=n[c>>2];hA(a,i,r);s=n[e>>2]|0;n[e>>2]=n[a>>2];n[a>>2]=s;s=a+4|0;g=n[d>>2]|0;n[d>>2]=n[s>>2];n[s>>2]=g;s=a+8|0;g=n[p>>2]|0;n[p>>2]=n[s>>2];n[s>>2]=g;s=a+12|0;g=n[h>>2]|0;n[h>>2]=n[s>>2];n[s>>2]=g;cA(a);s=n[p>>2]|0;break}r=u;i=((r-o>>2)+1|0)/-2|0;e=u+(i<<2)|0;r=s-r|0;if(!r)s=e;else{um(e|0,u|0,r|0)|0;s=(n[d>>2]|0)+(i<<2)|0}g=e+(r>>2<<2)|0;n[p>>2]=g;n[d>>2]=s;s=g}}while(0);n[s>>2]=n[t>>2];n[p>>2]=(n[p>>2]|0)+4;J=f;return}function AA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+48|0;i=f+32|0;s=f+28|0;o=f+8|0;a=f+4|0;l=f;p=e+4|0;u=n[p>>2]|0;d=n[e>>2]|0;c=d;do{if((u|0)==(d|0)){d=e+8|0;h=n[d>>2]|0;A=e+12|0;g=n[A>>2]|0;r=g;if(h>>>0>=g>>>0){g=r-c|0;g=(g|0)==0?1:g>>1;oA(o,g,(g+3|0)>>>2,e+12|0);n[a>>2]=n[p>>2];n[l>>2]=n[d>>2];n[s>>2]=n[a>>2];n[i>>2]=n[l>>2];hA(o,s,i);s=n[e>>2]|0;n[e>>2]=n[o>>2];n[o>>2]=s;s=o+4|0;g=n[p>>2]|0;n[p>>2]=n[s>>2];n[s>>2]=g;s=o+8|0;g=n[d>>2]|0;n[d>>2]=n[s>>2];n[s>>2]=g;s=o+12|0;g=n[A>>2]|0;n[A>>2]=n[s>>2];n[s>>2]=g;cA(o);s=n[p>>2]|0;break}i=h;e=((r-i>>2)+1|0)/2|0;r=h+(e<<2)|0;i=i-u|0;s=r+(0-(i>>2)<<2)|0;if(!i){s=r;i=r}else{um(s|0,u|0,i|0)|0;i=(n[d>>2]|0)+(e<<2)|0}n[p>>2]=s;n[d>>2]=i}else s=u}while(0);n[s+-4>>2]=n[t>>2];n[p>>2]=(n[p>>2]|0)+-4;J=f;return}function oA(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;r=e+12|0;n[r>>2]=0;n[e+16>>2]=i;do{if(t)if(t>>>0>1073741823){r=C(8)|0;ug(r,6723);n[r>>2]=5956;E(r|0,3928,123)}else{i=Zf(t<<2)|0;break}else i=0}while(0);n[e>>2]=i;s=i+(s<<2)|0;n[e+8>>2]=s;n[e+4>>2]=s;n[r>>2]=i+(t<<2);return}function aA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+48|0;r=f+32|0;i=f+28|0;a=f+8|0;l=f+4|0;c=f;p=e+8|0;s=n[p>>2]|0;h=e+12|0;d=n[h>>2]|0;A=d;do{if((s|0)==(d|0)){d=e+4|0;u=n[d>>2]|0;g=n[e>>2]|0;o=g;if(u>>>0<=g>>>0){s=A-o|0;s=(s|0)==0?1:s>>1;oA(a,s,s>>>2,n[e+16>>2]|0);n[l>>2]=n[d>>2];n[c>>2]=n[p>>2];n[i>>2]=n[l>>2];n[r>>2]=n[c>>2];hA(a,i,r);s=n[e>>2]|0;n[e>>2]=n[a>>2];n[a>>2]=s;s=a+4|0;g=n[d>>2]|0;n[d>>2]=n[s>>2];n[s>>2]=g;s=a+8|0;g=n[p>>2]|0;n[p>>2]=n[s>>2];n[s>>2]=g;s=a+12|0;g=n[h>>2]|0;n[h>>2]=n[s>>2];n[s>>2]=g;cA(a);s=n[p>>2]|0;break}r=u;i=((r-o>>2)+1|0)/-2|0;e=u+(i<<2)|0;r=s-r|0;if(!r)s=e;else{um(e|0,u|0,r|0)|0;s=(n[d>>2]|0)+(i<<2)|0}g=e+(r>>2<<2)|0;n[p>>2]=g;n[d>>2]=s;s=g}}while(0);n[s>>2]=n[t>>2];n[p>>2]=(n[p>>2]|0)+4;J=f;return}function lA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0;f=J;J=J+48|0;i=f+32|0;s=f+28|0;o=f+8|0;a=f+4|0;l=f;p=e+4|0;u=n[p>>2]|0;d=n[e>>2]|0;c=d;do{if((u|0)==(d|0)){d=e+8|0;h=n[d>>2]|0;A=e+12|0;g=n[A>>2]|0;r=g;if(h>>>0>=g>>>0){g=r-c|0;g=(g|0)==0?1:g>>1;oA(o,g,(g+3|0)>>>2,n[e+16>>2]|0);n[a>>2]=n[p>>2];n[l>>2]=n[d>>2];n[s>>2]=n[a>>2];n[i>>2]=n[l>>2];hA(o,s,i);s=n[e>>2]|0;n[e>>2]=n[o>>2];n[o>>2]=s;s=o+4|0;g=n[p>>2]|0;n[p>>2]=n[s>>2];n[s>>2]=g;s=o+8|0;g=n[d>>2]|0;n[d>>2]=n[s>>2];n[s>>2]=g;s=o+12|0;g=n[A>>2]|0;n[A>>2]=n[s>>2];n[s>>2]=g;cA(o);s=n[p>>2]|0;break}i=h;e=((r-i>>2)+1|0)/2|0;r=h+(e<<2)|0;i=i-u|0;s=r+(0-(i>>2)<<2)|0;if(!i){s=r;i=r}else{um(s|0,u|0,i|0)|0;i=(n[d>>2]|0)+(e<<2)|0}n[p>>2]=s;n[d>>2]=i}else s=u}while(0);n[s+-4>>2]=n[t>>2];n[p>>2]=(n[p>>2]|0)+-4;J=f;return}function cA(e){e=e|0;var t=0,s=0,i=0;t=n[e+4>>2]|0;s=e+8|0;i=n[s>>2]|0;if((i|0)!=(t|0))n[s>>2]=i+(~((i+-4-t|0)>>>2)<<2);t=n[e>>2]|0;if(t|0)ye(t,(n[e+12>>2]|0)-t|0);return}function hA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0;o=J;J=J+16|0;A=o;r=n[t>>2]|0;uA(A,e+8|0,(n[s>>2]|0)-r>>2);e=n[A>>2]|0;i=A+4|0;if((e|0)!=(n[i>>2]|0)){s=r;do{n[e>>2]=n[s>>2];e=(n[A>>2]|0)+4|0;n[A>>2]=e;s=s+4|0}while((e|0)!=(n[i>>2]|0));n[t>>2]=s}dA(A);J=o;return}function uA(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=n[t>>2];n[e+4>>2]=(n[t>>2]|0)+(s<<2);n[e+8>>2]=t;return}function dA(e){e=e|0;n[n[e+8>>2]>>2]=n[e>>2];return}function pA(e,t){e=e|0;t=t|0;return(n[e+4>>2]|0)==(n[t+4>>2]|0)|0}function fA(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;n[e+4>>2]=s;return}function gA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;A=n[t+4>>2]|0;s=n[t+16>>2]|0;i=(s>>>0)/93|0;r=A+(i<<2)|0;if((n[t+8>>2]|0)==(A|0))t=0;else t=(n[r>>2]|0)+((s-(i*93|0)|0)*44|0)|0;n[e>>2]=r;n[e+4>>2]=t;return}function mA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;s=(n[t+16>>2]|0)+(n[t+20>>2]|0)|0;A=n[t+4>>2]|0;i=(s>>>0)/93|0;r=A+(i<<2)|0;if((n[t+8>>2]|0)==(A|0))t=0;else t=(n[r>>2]|0)+((s-(i*93|0)|0)*44|0)|0;n[e>>2]=r;n[e+4>>2]=t;return}function _A(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0;a=J;J=J+16|0;i=a+8|0;A=a;bA(i,e);Jn(A,e);r=i+4|0;t=n[r>>2]|0;A=A+4|0;if((t|0)!=(n[A>>2]|0))do{Ms(t);t=(n[r>>2]|0)+44|0;n[r>>2]=t;s=n[i>>2]|0;if((t-(n[s>>2]|0)|0)==4092){t=s+4|0;n[i>>2]=t;t=n[t>>2]|0;n[r>>2]=t}}while((t|0)!=(n[A>>2]|0));n[e+20>>2]=0;r=e+8|0;i=e+4|0;s=n[i>>2]|0;t=(n[r>>2]|0)-s>>2;if(t>>>0>2)do{ye(n[s>>2]|0,4092);s=(n[i>>2]|0)+4|0;n[i>>2]=s;t=(n[r>>2]|0)-s>>2}while(t>>>0>2);switch(t|0){case 1:{t=46;o=11;break}case 2:{t=93;o=11;break}default:{}}if((o|0)==11)n[e+16>>2]=t;J=a;return}function bA(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;A=n[t+4>>2]|0;s=n[t+16>>2]|0;i=(s>>>0)/93|0;r=A+(i<<2)|0;if((n[t+8>>2]|0)==(A|0))t=0;else t=(n[r>>2]|0)+((s-(i*93|0)|0)*44|0)|0;n[e>>2]=r;n[e+4>>2]=t;return}function yA(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,o=0,a=0,l=0,c=0,h=0,u=0;u=J;J=J+16|0;h=u;l=e+4|0;if(!(i[l>>0]|0)){h=yr(t)|0;Br(h,s,n[e>>2]|0);h=n[e>>2]|0;a=s+h|0;if(!h)r=0;else{r=s;o=n[e+8>>2]|0;while(1){i[o>>0]=i[r>>0]|0;r=r+1|0;if((r|0)==(a|0))break;else o=o+1|0}r=n[e>>2]|0}i[l>>0]=1;s=s+r|0}else{o=n[e+20>>2]|0;r=n[e+8>>2]|0;bA(h,e+32|0);e=e+12|0;if((r|0)!=(n[e>>2]|0)){c=h+4|0;l=r;a=o;r=n[c>>2]|0;while(1){o=A[l>>0]|0;o=BA((Ns(t,r)|0)+o|0)|0;i[a>>0]=o;i[s>>0]=o;i[l>>0]=o;l=l+1|0;s=s+1|0;o=n[h>>2]|0;r=(n[c>>2]|0)+44|0;n[c>>2]=r;if((r-(n[o>>2]|0)|0)==4092){r=o+4|0;n[h>>2]=r;r=n[r>>2]|0;n[c>>2]=r}if((l|0)==(n[e>>2]|0))break;else a=a+1|0}}}J=u;return s|0}function BA(e){e=e|0;return e&255|0}function wA(e){e=e|0;Ag(e);qp(e);return}function vA(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function CA(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==11262?e+12|0:0)|0}function MA(e){e=e|0;ye(e,16);return}function EA(e,t){e=e|0;t=t|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;if(t|0){Hn(e,t);xA(e,t)}return}function FA(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;n[e+20>>2]=0;if(t|0)UA(e,t,s);return}function xA(e,t){e=e|0;t=t|0;var s=0,r=0,A=0;A=J;J=J+16|0;r=A;zn(r,e,t);t=r+4|0;e=n[t>>2]|0;s=r+8|0;if((e|0)!=(n[s>>2]|0))do{i[e>>0]=0;e=(n[t>>2]|0)+1|0;n[t>>2]=e}while((e|0)!=(n[s>>2]|0));Wn(r);J=A;return}function UA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;p=J;J=J+96|0;d=p+80|0;c=p+64|0;o=p+48|0;a=p+40|0;l=p+8|0;r=p;h=p+32|0;u=p+16|0;i=(n[e+8>>2]|0)-(n[e+4>>2]|0)|0;i=((i|0)==0?0:((i>>2)*93|0)+-1|0)-((n[e+20>>2]|0)+(n[e+16>>2]|0))|0;if(i>>>0<t>>>0)Zn(e,t-i|0);Jn(a,e);Jn(r,e);i=n[r>>2]|0;r=n[r+4>>2]|0;A=l;n[A>>2]=i;n[A+4>>2]=r;A=i;if(t|0){i=((r-(n[i>>2]|0)|0)/44|0)+t|0;if((i|0)>0){t=(i>>>0)/93|0;A=A+(t<<2)|0;n[l>>2]=A;i=(n[A>>2]|0)+((i-(t*93|0)|0)*44|0)|0}else{i=92-i|0;t=A+(((i|0)/-93|0)<<2)|0;n[l>>2]=t;i=(n[t>>2]|0)+((92-((i|0)%93|0)|0)*44|0)|0}n[l+4>>2]=i}n[c>>2]=n[a>>2];n[c+4>>2]=n[a+4>>2];n[d>>2]=n[l>>2];n[d+4>>2]=n[l+4>>2];Yn(o,c,d);$n(d,o);qn(c,o);if(eA(d,c)|0){r=u+4|0;do{tA(h,d);sA(u,e,h);i=n[u>>2]|0;if((i|0)!=(n[r>>2]|0))do{Vs(i,s);i=(n[u>>2]|0)+44|0;n[u>>2]=i}while((i|0)!=(n[r>>2]|0));iA(u);rA(d)|0}while(eA(d,c)|0)}J=p;return}function IA(e){e=e|0;var t=0,s=0;_A(e);t=n[e+4>>2]|0;s=n[e+8>>2]|0;if((t|0)!=(s|0))do{ye(n[t>>2]|0,4092);t=t+4|0}while((t|0)!=(s|0));Kn(e);return}function TA(e,t,s){e=e|0;t=t|0;s=s|0;Ui(e);n[e>>2]=4924;n[e+4>>2]=t;n[e+8>>2]=s;return}function PA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4944;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;VA(e,i);J=s;return}function SA(e,t){e=e|0;t=t|0;return QA(n[e+8>>2]|0,n[e+4>>2]|0,t)|0}function DA(e){e=e|0;var t=0,s=0;n[e>>2]=4924;s=e+8|0;t=n[s>>2]|0;n[s>>2]=0;if(t|0){OA(t);qp(t)}Si(e);return}function kA(e){e=e|0;DA(e);qp(e);return}function QA(e,t,s){e=e|0;t=t|0;s=s|0;return RA(e+4784|0,t,_r(e,t,s)|0)|0}function RA(e,t,s){e=e|0;t=t|0;s=s|0;if(i[e>>0]|0){rs(t);i[e>>0]=0}return s|0}function OA(e){e=e|0;gr(e);return}function VA(e,t){e=e|0;t=t|0;return}function LA(e){e=e|0;Ag(e);qp(e);return}function HA(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function NA(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==12004?e+12|0:0)|0}function GA(e){e=e|0;ye(e,16);return}function jA(e){e=e|0;i[e>>0]=1;return}function zA(e,t,s){e=e|0;t=t|0;s=s|0;Ui(e);n[e>>2]=4972;n[e+4>>2]=t;n[e+8>>2]=s;return}function WA(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=4992;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;VA(e,i);J=s;return}function XA(e,t){e=e|0;t=t|0;return JA(n[e+8>>2]|0,n[e+4>>2]|0,t)|0}function KA(e){e=e|0;var t=0,s=0;n[e>>2]=4972;s=e+8|0;t=n[s>>2]|0;n[s>>2]=0;if(t|0){$A(t);qp(t)}Si(e);return}function ZA(e){e=e|0;KA(e);qp(e);return}function JA(e,t,s){e=e|0;t=t|0;s=s|0;return YA(e+4784|0,t,_r(e,t,s)|0)|0}function YA(e,t,s){e=e|0;t=t|0;s=s|0;return RA(e+328|0,t,on(e,t,s)|0)|0}function $A(e){e=e|0;qA(e+4784|0);gr(e);return}function qA(e){e=e|0;nn(e);return}function eo(e){e=e|0;Ag(e);qp(e);return}function to(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function so(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==12827?e+12|0:0)|0}function io(e){e=e|0;ye(e,16);return}function ro(e){e=e|0;Xr(e);jA(e+328|0);return}function no(e,t,s){e=e|0;t=t|0;s=s|0;Ui(e);n[e>>2]=5020;n[e+4>>2]=t;n[e+8>>2]=s;return}function Ao(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5040;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;VA(e,i);J=s;return}function oo(e,t){e=e|0;t=t|0;return co(n[e+8>>2]|0,n[e+4>>2]|0,t)|0}function ao(e){e=e|0;var t=0,s=0;n[e>>2]=5020;s=e+8|0;t=n[s>>2]|0;n[s>>2]=0;if(t|0){uo(t);qp(t)}Si(e);return}function lo(e){e=e|0;ao(e);qp(e);return}function co(e,t,s){e=e|0;t=t|0;s=s|0;return ho(e+4784|0,t,_r(e,t,s)|0)|0}function ho(e,t,s){e=e|0;t=t|0;s=s|0;return RA(e+316|0,t,Mn(e,t,s)|0)|0}function uo(e){e=e|0;po(e+4784|0);gr(e);return}function po(e){e=e|0;Cn(e);return}function fo(e){e=e|0;Ag(e);qp(e);return}function go(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function mo(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==13672?e+12|0:0)|0}function _o(e){e=e|0;ye(e,16);return}function bo(e){e=e|0;bn(e);jA(e+316|0);return}function yo(e,t,s){e=e|0;t=t|0;s=s|0;Ui(e);n[e>>2]=5068;n[e+4>>2]=t;n[e+8>>2]=s;return}function Bo(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5088;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;VA(e,i);J=s;return}function wo(e,t){e=e|0;t=t|0;return Mo(n[e+8>>2]|0,n[e+4>>2]|0,t)|0}function vo(e){e=e|0;var t=0,s=0;n[e>>2]=5068;s=e+8|0;t=n[s>>2]|0;n[s>>2]=0;if(t|0){Fo(t);qp(t)}Si(e);return}function Co(e){e=e|0;vo(e);qp(e);return}function Mo(e,t,s){e=e|0;t=t|0;s=s|0;return Eo(e+4784|0,t,_r(e,t,s)|0)|0}function Eo(e,t,s){e=e|0;t=t|0;s=s|0;return ho(e+328|0,t,on(e,t,s)|0)|0}function Fo(e){e=e|0;xo(e+4784|0);gr(e);return}function xo(e){e=e|0;po(e+328|0);nn(e);return}function Uo(e){e=e|0;Ag(e);qp(e);return}function Io(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function To(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==14573?e+12|0:0)|0}function Po(e){e=e|0;ye(e,16);return}function So(e){e=e|0;Xr(e);bo(e+328|0);return}function Do(e){e=e|0;return e+20|0}function ko(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=t;n[e+4>>2]=s;n[e+8>>2]=0;return}function Qo(e,t){e=e|0;t=t|0;n[e>>2]=t;n[e+4>>2]=0;n[e+8>>2]=-1;return}function Ro(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;s=J;J=J+16|0;i=s+4|0;A=s;r=Zf(24)|0;ea(r,t);n[A>>2]=0;n[i>>2]=n[A>>2];ta(e,r,i);J=s;return}function Oo(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Vo(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5116;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ho(e,i);J=s;return}function Lo(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Ho(e,t){e=e|0;t=t|0;return}function No(e){e=e|0;Ag(e);qp(e);return}function Go(e){e=e|0;e=n[e+12>>2]|0;if(e|0)qp(e);return}function jo(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==14966?e+12|0:0)|0}function zo(e){e=e|0;ye(e,16);return}function Wo(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5144;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Ko(e,i);J=s;return}function Xo(e){e=e|0;var t=0,s=0;e=n[e+4>>2]|0;if(e|0?(s=e+4|0,t=n[s>>2]|0,n[s>>2]=t+-1,(t|0)==0):0){jm[n[(n[e>>2]|0)+8>>2]&255](e);og(e)}return}function Ko(e,t){e=e|0;t=t|0;return}function Zo(e){e=e|0;Ag(e);qp(e);return}function Jo(e){e=e|0;e=n[e+12>>2]|0;if(e|0){qo(e);qp(e)}return}function Yo(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==15127?e+12|0:0)|0}function $o(e){e=e|0;ye(e,16);return}function qo(e){e=e|0;return}function ea(e,t){e=e|0;t=t|0;Ui(e);n[e>>2]=5172;n[e+4>>2]=t;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;i[e+20>>0]=1;return}function ta(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5192;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;oa(e,i);J=s;return}function sa(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0,a=0,l=0,c=0;c=J;J=J+16|0;o=c;s=n[e+8>>2]|0;a=n[e+12>>2]|0;if((s|0)!=(a|0)){l=o+4|0;do{r=n[s>>2]|0;n[o>>2]=r;A=n[s+4>>2]|0;n[l>>2]=A;if(A|0){A=A+4|0;n[A>>2]=(n[A>>2]|0)+1}t=Hm[n[(n[r>>2]|0)+12>>2]&63](r,t)|0;ki(o);s=s+8|0}while((s|0)!=(a|0))}s=e+20|0;if(i[s>>0]|0){i[s>>0]=0;na(n[e+4>>2]|0)}J=c;return t|0}function ia(e){e=e|0;n[e>>2]=5172;Qi(e+8|0);Si(e);return}function ra(e){e=e|0;ia(e);qp(e);return}function na(e){e=e|0;var t=0;t=((Aa(n[e>>2]|0)|0)&255)<<24;t=((Aa(n[e>>2]|0)|0)&255)<<16|t;t=t|((Aa(n[e>>2]|0)|0)&255)<<8;n[e+4>>2]=t|(Aa(n[e>>2]|0)|0)&255;return}function Aa(e){e=e|0;var t=0,s=0;t=n[e>>2]|0;s=e+8|0;e=n[s>>2]|0;n[s>>2]=e+1;return i[t+e>>0]|0}function oa(e,t){e=e|0;t=t|0;return}function aa(e){e=e|0;Ag(e);qp(e);return}function la(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+8>>2]&255](e);return}function ca(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==15450?e+12|0:0)|0}function ha(e){e=e|0;ye(e,16);return}function ua(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(180)|0;pa(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];fa(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function da(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(180)|0;Oa(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];Va(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function pa(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5220;n[e+4>>2]=t;ga(e+8|0);return}function fa(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5244;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function ga(e){e=e|0;pr(e,32,1,8,0);is(e+80|0,32,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;ya(e+164|0);return}function ma(e){e=e|0;n[e>>2]=5220;Ba(e+8|0);sr(e);return}function _a(e){e=e|0;ma(e);qp(e);return}function ba(e,t){e=e|0;t=t|0;return wa(e+8|0,n[e+4>>2]|0,t)|0}function ya(e){e=e|0;i[e+4>>0]=0;return}function Ba(e){e=e|0;os(e+80|0);fr(e);return}function wa(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;o=J;J=J+16|0;r=o;if(!(i[e+161>>0]|0))ns(e+80|0);A=e+164|0;if(va(A)|0){t=Ca(e+80|0,t,n[A>>2]|0,0)|0;n[r>>2]=t;kr(t,s)}else{Ea(Ma(t)|0,s,4);n[r>>2]=Ir(s)|0}Fa(A,r);J=o;return s+4|0}function va(e){e=e|0;return(i[e+4>>0]|0)!=0|0}function Ca(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;s=(xa(e,t,(n[e+36>>2]|0)+(i*44|0)|0)|0)+s|0;t=n[e+24>>2]|0;if((s|0)<0)return s+t|0;else return s-(s>>>0<t>>>0?0:t)|0;return 0}function Ma(e){e=e|0;return n[e>>2]|0}function Ea(e,t,s){e=e|0;t=t|0;s=s|0;var r=0;if((s|0)>0){r=0;do{i[t+r>>0]=Aa(e)|0;r=r+1|0}while((r|0)!=(s|0))}return}function Fa(e,t){e=e|0;t=t|0;var s=0;s=e+4|0;if(!(i[s>>0]|0))i[s>>0]=1;n[e>>2]=n[t>>2];return}function xa(e,t,s){e=e|0;t=t|0;s=s|0;var i=0;s=Ua(t,s)|0;n[e>>2]=s;do{if(s){if(s>>>0>=32){s=n[e+28>>2]|0;break}i=n[e+12>>2]|0;if(s>>>0>i>>>0){i=s-i|0;s=Ua(t,(n[e+68>>2]|0)+((s+-1|0)*44|0)|0)|0;i=s<<i|(Ia(t,i)|0)}else i=Ua(t,(n[e+68>>2]|0)+((s+-1|0)*44|0)|0)|0;s=n[e>>2]|0;if((i|0)<(1<<s+-1|0)){s=i+1+(-1<<s)|0;break}else{s=i+1|0;break}}else s=Ta(t,e+48|0)|0}while(0);return s|0}function Ua(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;d=e+8|0;u=n[d>>2]|0;r=n[t+16>>2]|0;if(r){i=e+4|0;s=n[i>>2]|0;h=u>>>15;n[d>>2]=h;l=(s>>>0)/(h>>>0)|0;a=l>>>(n[t+40>>2]|0);A=n[r+(a<<2)>>2]|0;a=(n[r+(a+1<<2)>>2]|0)+1|0;o=A+1|0;c=n[t+8>>2]|0;if(a>>>0>o>>>0){r=A;A=a;do{o=(A+r|0)>>>1;a=(n[c+(o<<2)>>2]|0)>>>0>l>>>0;r=a?r:o;A=a?o:A;o=r+1|0}while(A>>>0>o>>>0);A=r}r=b(n[c+(A<<2)>>2]|0,h)|0;if((A|0)==(n[t+32>>2]|0))o=u;else o=b(n[c+(o<<2)>>2]|0,h)|0}else{c=u>>>15;n[d>>2]=c;a=n[t>>2]|0;h=n[t+8>>2]|0;i=e+4|0;s=n[i>>2]|0;l=a>>>1;r=0;o=u;A=0;do{p=b(n[h+(l<<2)>>2]|0,c)|0;u=p>>>0>s>>>0;o=u?p:o;r=u?r:p;A=u?A:l;a=u?l:a;l=(A+a|0)>>>1}while((l|0)!=(A|0))}n[i>>2]=s-r;p=o-r|0;n[d>>2]=p;if(p>>>0<16777216)Pa(e);d=(n[t+12>>2]|0)+(A<<2)|0;n[d>>2]=(n[d>>2]|0)+1;d=t+28|0;p=(n[d>>2]|0)+-1|0;n[d>>2]=p;if(!p)Ls(t);return A|0}function Ia(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;if(t>>>0>19){s=(Sa(e)|0)&65535;return(Ia(e,t+-16|0)|0)<<16|s|0}i=e+4|0;r=n[i>>2]|0;A=e+8|0;s=(n[A>>2]|0)>>>t;n[A>>2]=s;t=(r>>>0)/(s>>>0)|0;n[i>>2]=r-(b(t,s)|0);if(s>>>0<16777216)Pa(e);return t|0}function Ta(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0,a=0;i=e+8|0;r=n[i>>2]|0;s=b(r>>>13,n[t+8>>2]|0)|0;A=e+4|0;o=n[A>>2]|0;a=o>>>0>=s>>>0;if(a){n[A>>2]=o-s;s=r-s|0;n[i>>2]=s}else{n[i>>2]=s;o=t+12|0;n[o>>2]=(n[o>>2]|0)+1}if(s>>>0<16777216)Pa(e);o=t+4|0;e=(n[o>>2]|0)+-1|0;n[o>>2]=e;if(!e)Xs(t);return a&1|0}function Pa(e){e=e|0;var t=0,s=0,i=0,r=0;t=e+4|0;s=e+8|0;i=n[t>>2]|0;do{i=i<<8|(Aa(n[e>>2]|0)|0)&255;n[t>>2]=i;r=n[s>>2]<<8;n[s>>2]=r}while(r>>>0<16777216);return}function Sa(e){e=e|0;var t=0,s=0,i=0,r=0;s=e+4|0;r=n[s>>2]|0;t=e+8|0;i=(n[t>>2]|0)>>>16;n[t>>2]=i;t=(r>>>0)/(i>>>0)|0;n[s>>2]=r-(b(t,i)|0);Pa(e);return t&65535|0}function Da(e){e=e|0;Ag(e);qp(e);return}function ka(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Qa(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==15904?e+12|0:0)|0}function Ra(e){e=e|0;ye(e,16);return}function Oa(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5272;n[e+4>>2]=t;La(e+8|0);return}function Va(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5296;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function La(e){e=e|0;pr(e,32,1,8,0);is(e+80|0,32,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;ja(e+164|0);return}function Ha(e){e=e|0;n[e>>2]=5272;za(e+8|0);sr(e);return}function Na(e){e=e|0;Ha(e);qp(e);return}function Ga(e,t){e=e|0;t=t|0;return Wa(e+8|0,n[e+4>>2]|0,t)|0}function ja(e){e=e|0;i[e+4>>0]=0;return}function za(e){e=e|0;os(e+80|0);fr(e);return}function Wa(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;o=J;J=J+16|0;r=o;if(!(i[e+161>>0]|0))ns(e+80|0);A=e+164|0;if(Xa(A)|0){t=Ca(e+80|0,t,n[A>>2]|0,0)|0;n[r>>2]=t;Vr(t,s)}else{Ea(Ma(t)|0,s,4);n[r>>2]=Dr(s)|0}Ka(A,r);J=o;return s+4|0}function Xa(e){e=e|0;return(i[e+4>>0]|0)!=0|0}function Ka(e,t){e=e|0;t=t|0;var s=0;s=e+4|0;if(!(i[s>>0]|0))i[s>>0]=1;n[e>>2]=n[t>>2];return}function Za(e){e=e|0;Ag(e);qp(e);return}function Ja(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Ya(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==16402?e+12|0:0)|0}function $a(e){e=e|0;ye(e,16);return}function qa(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(172)|0;tl(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];sl(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function el(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(176)|0;_l(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];bl(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function tl(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5324;n[e+4>>2]=t;il(e+8|0);return}function sl(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5348;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function il(e){e=e|0;pr(e,8,1,8,0);is(e+80|0,8,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;ol(e+162|0);return}function rl(e){e=e|0;n[e>>2]=5324;al(e+8|0);sr(e);return}function nl(e){e=e|0;rl(e);qp(e);return}function Al(e,t){e=e|0;t=t|0;return ll(e+8|0,n[e+4>>2]|0,t)|0}function ol(e){e=e|0;i[e+1>>0]=0;return}function al(e){e=e|0;os(e+80|0);fr(e);return}function ll(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,n=0,A=0;A=J;J=J+16|0;r=A;if(!(i[e+161>>0]|0))ns(e+80|0);n=e+162|0;if(cl(n)|0){t=(Ca(e+80|0,t,i[n>>0]|0,0)|0)&255;i[r>>0]=t;hl(t,s)}else{Ea(Ma(t)|0,s,1);i[r>>0]=ul(s)|0}dl(n,r);J=A;return s+1|0}function cl(e){e=e|0;return(i[e+1>>0]|0)!=0|0}function hl(e,t){e=e|0;t=t|0;i[t>>0]=e;return}function ul(e){e=e|0;return i[e>>0]|0}function dl(e,t){e=e|0;t=t|0;var s=0;s=e+1|0;if(!(i[s>>0]|0))i[s>>0]=1;i[e>>0]=i[t>>0]|0;return}function pl(e){e=e|0;Ag(e);qp(e);return}function fl(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function gl(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==16900?e+12|0:0)|0}function ml(e){e=e|0;ye(e,16);return}function _l(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5376;n[e+4>>2]=t;yl(e+8|0);return}function bl(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5400;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function yl(e){e=e|0;pr(e,16,1,8,0);is(e+80|0,16,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;Cl(e+162|0);return}function Bl(e){e=e|0;n[e>>2]=5376;Ml(e+8|0);sr(e);return}function wl(e){e=e|0;Bl(e);qp(e);return}function vl(e,t){e=e|0;t=t|0;return El(e+8|0,n[e+4>>2]|0,t)|0}function Cl(e){e=e|0;i[e+2>>0]=0;return}function Ml(e){e=e|0;os(e+80|0);fr(e);return}function El(e,t,s){e=e|0;t=t|0;s=s|0;var n=0,A=0,o=0;o=J;J=J+16|0;n=o;if(!(i[e+161>>0]|0))ns(e+80|0);A=e+162|0;if(Fl(A)|0){t=(Ca(e+80|0,t,r[A>>1]|0,0)|0)&65535;r[n>>1]=t;xl(t,s)}else{Ea(Ma(t)|0,s,2);r[n>>1]=Ul(s)|0}Il(A,n);J=o;return s+2|0}function Fl(e){e=e|0;return(i[e+2>>0]|0)!=0|0}function xl(e,t){e=e|0;t=t|0;Qr(e,t);return}function Ul(e){e=e|0;return Tr(e)|0}function Il(e,t){e=e|0;t=t|0;var s=0;s=e+2|0;if(!(i[s>>0]|0))i[s>>0]=1;r[e>>1]=r[t>>1]|0;return}function Tl(e){e=e|0;Ag(e);qp(e);return}function Pl(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Sl(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==17398?e+12|0:0)|0}function Dl(e){e=e|0;ye(e,16);return}function kl(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(172)|0;Rl(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];Ol(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function Ql(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0;l=J;J=J+32|0;i=l+12|0;r=l;t=l+8|0;o=Zf(176)|0;$l(o,n[e+4>>2]|0);A=e+8|0;n[t>>2]=0;n[i>>2]=n[t>>2];ql(r,o,i);o=e+12|0;t=n[o>>2]|0;a=e+16|0;do{if(t>>>0>=(n[a>>2]|0)>>>0){t=(t-(n[A>>2]|0)>>3)+1|0;s=Zi(A)|0;if(s>>>0<t>>>0)Xg(A);else{c=n[A>>2]|0;h=(n[a>>2]|0)-c|0;a=h>>2;Wi(i,h>>3>>>0<s>>>1>>>0?a>>>0<t>>>0?t:a:s,(n[o>>2]|0)-c>>3,e+16|0);a=i+8|0;o=n[a>>2]|0;n[o>>2]=n[r>>2];e=r+4|0;n[o+4>>2]=n[e>>2];n[r>>2]=0;n[e>>2]=0;n[a>>2]=o+8;Xi(A,i);Ki(i);break}}else{ji(i,A,1);h=i+4|0;c=n[h>>2]|0;n[c>>2]=n[r>>2];a=r+4|0;n[c+4>>2]=n[a>>2];n[r>>2]=0;n[a>>2]=0;n[h>>2]=c+8;zi(i)}}while(0);ki(r);J=l;return}function Rl(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5428;n[e+4>>2]=t;Vl(e+8|0);return}function Ol(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5452;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function Vl(e){e=e|0;pr(e,8,1,8,0);is(e+80|0,8,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;Gl(e+162|0);return}function Ll(e){e=e|0;n[e>>2]=5428;jl(e+8|0);sr(e);return}function Hl(e){e=e|0;Ll(e);qp(e);return}function Nl(e,t){e=e|0;t=t|0;return zl(e+8|0,n[e+4>>2]|0,t)|0}function Gl(e){e=e|0;i[e+1>>0]=0;return}function jl(e){e=e|0;os(e+80|0);fr(e);return}function zl(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,n=0,o=0;o=J;J=J+16|0;r=o;if(!(i[e+161>>0]|0))ns(e+80|0);n=e+162|0;if(Wl(n)|0){t=(Ca(e+80|0,t,A[n>>0]|0,0)|0)&255;i[r>>0]=t;Rr(t,s)}else{Ea(Ma(t)|0,s,1);i[r>>0]=Pr(s)|0}Xl(n,r);J=o;return s+1|0}function Wl(e){e=e|0;return(i[e+1>>0]|0)!=0|0}function Xl(e,t){e=e|0;t=t|0;var s=0;s=e+1|0;if(!(i[s>>0]|0))i[s>>0]=1;i[e>>0]=i[t>>0]|0;return}function Kl(e){e=e|0;Ag(e);qp(e);return}function Zl(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function Jl(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==17896?e+12|0:0)|0}function Yl(e){e=e|0;ye(e,16);return}function $l(e,t){e=e|0;t=t|0;Ji(e);n[e>>2]=5480;n[e+4>>2]=t;ec(e+8|0);return}function ql(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;s=J;J=J+16|0;i=s;n[e>>2]=t;r=Zf(16)|0;n[r+4>>2]=0;n[r+8>>2]=0;n[r>>2]=5504;n[r+12>>2]=t;n[e+4>>2]=r;n[i>>2]=t;n[i+4>>2]=t;Lr(e,i);J=s;return}function ec(e){e=e|0;pr(e,16,1,8,0);is(e+80|0,16,1,8,0);i[e+160>>0]=0;i[e+161>>0]=0;rc(e+162|0);return}function tc(e){e=e|0;n[e>>2]=5480;nc(e+8|0);sr(e);return}function sc(e){e=e|0;tc(e);qp(e);return}function ic(e,t){e=e|0;t=t|0;return Ac(e+8|0,n[e+4>>2]|0,t)|0}function rc(e){e=e|0;i[e+2>>0]=0;return}function nc(e){e=e|0;os(e+80|0);fr(e);return}function Ac(e,t,s){e=e|0;t=t|0;s=s|0;var n=0,A=0,a=0;a=J;J=J+16|0;n=a;if(!(i[e+161>>0]|0))ns(e+80|0);A=e+162|0;if(oc(A)|0){t=(Ca(e+80|0,t,o[A>>1]|0,0)|0)&65535;r[n>>1]=t;Qr(t,s)}else{Ea(Ma(t)|0,s,2);r[n>>1]=Tr(s)|0}ac(A,n);J=a;return s+2|0}function oc(e){e=e|0;return(i[e+2>>0]|0)!=0|0}function ac(e,t){e=e|0;t=t|0;var s=0;s=e+2|0;if(!(i[s>>0]|0))i[s>>0]=1;r[e>>1]=r[t>>1]|0;return}function lc(e){e=e|0;Ag(e);qp(e);return}function cc(e){e=e|0;e=n[e+12>>2]|0;if(e|0)jm[n[(n[e>>2]|0)+4>>2]&255](e);return}function hc(e,t){e=e|0;t=t|0;return((n[t+4>>2]|0)==18394?e+12|0:0)|0}function uc(e){e=e|0;ye(e,16);return}function dc(){return}function pc(e){e=e|0;return wc(e)|0}function fc(){return 0}function gc(){return 0}function mc(e){e=e|0;if(e|0){vc(e);qp(e)}return}function _c(){return Cc()|0}function bc(){return Mc()|0}function yc(){return Ec()|0}function Bc(){return 0}function wc(e){e=e|0;return 3360}function vc(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;i=t;n[i>>2]=n[e>>2];n[e>>2]=0;s=e+4|0;n[i+4>>2]=n[s>>2];n[s>>2]=0;de(i);s=e+8|0;n[i>>2]=n[s>>2];n[s>>2]=0;r=e+12|0;n[i+4>>2]=n[r>>2];n[r>>2]=0;ve(i);ve(s);de(e);J=t;return}function Cc(){return 3360}function Mc(){return 3368}function Ec(){return 3384}function Fc(){return 18579}function xc(){return 18582}function Uc(){return 18584}function Ic(){var e=0;e=Zf(16)|0;Rc(e);return e|0}function Tc(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;s=t;r=_c()|0;i=Sc(s)|0;s=Dc(s)|0;S(r|0,i|0,s|0,Fc()|0,12,e|0);J=t;return}function Pc(e){e=e|0;return kc(Om[e&3]()|0)|0}function Sc(e){e=e|0;return 1}function Dc(e){e=e|0;return Qc()|0}function kc(e){e=e|0;return e|0}function Qc(){return 5524}function Rc(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;return}function Oc(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=_c()|0;A=Lc(r)|0;r=Hc(r)|0;t=Xc()|0;D(o|0,e|0,A|0,r|0,t|0,4,Nc(i)|0,0);J=s;return}function Vc(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;A=Gc(t)|0;t=n[e>>2]|0;r=n[e+4>>2]|0;e=A+(r>>1)|0;if(r&1)t=n[(n[e>>2]|0)+t>>2]|0;r=jc(s)|0;A=zc(i)|0;Wm[t&15](e,r,A);return}function Lc(e){e=e|0;return 4}function Hc(e){e=e|0;return Wc()|0}function Nc(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function Gc(e){e=e|0;return e|0}function jc(e){e=e|0;return e|0}function zc(e){e=e|0;return e|0}function Wc(){return 144}function Xc(){return 18587}function Kc(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=_c()|0;A=Jc(r)|0;r=Yc(r)|0;t=th()|0;D(o|0,e|0,A|0,r|0,t|0,7,$c(i)|0,0);J=s;return}function Zc(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=Gc(t)|0;t=n[e>>2]|0;i=n[e+4>>2]|0;e=r+(i>>1)|0;if(i&1)t=n[(n[e>>2]|0)+t>>2]|0;r=qc(s)|0;zm[t&15](e,r);return}function Jc(e){e=e|0;return 3}function Yc(e){e=e|0;return eh()|0}function $c(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function qc(e){e=e|0;return e|0}function eh(){return 5528}function th(){return 18593}function sh(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=_c()|0;A=rh(r)|0;r=nh(r)|0;t=lh()|0;D(o|0,e|0,A|0,r|0,t|0,41,Ah(i)|0,0);J=s;return}function ih(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0;i=J;J=J+16|0;s=i;A=Gc(t)|0;t=n[e>>2]|0;r=n[e+4>>2]|0;e=A+(r>>1)|0;if(r&1)t=n[(n[e>>2]|0)+t>>2]|0;n[s>>2]=Vm[t&15](e)|0;A=oh(s)|0;J=i;return A|0}function rh(e){e=e|0;return 2}function nh(e){e=e|0;return ah()|0}function Ah(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function oh(e){e=e|0;return n[e>>2]|0}function ah(){return 5540}function lh(){return 18598}function ch(){return}function hh(e){e=e|0;return _h(e)|0}function uh(){return 0}function dh(){return 0}function ph(e){e=e|0;if(e|0){bh(e);qp(e)}return}function fh(){return yh()|0}function gh(){return Bh()|0}function mh(){return wh()|0}function _h(e){e=e|0;return 3400}function bh(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;i=t;n[i>>2]=n[e>>2];n[e>>2]=0;s=e+4|0;n[i+4>>2]=n[s>>2];n[s>>2]=0;Lo(i);s=e+16|0;n[i>>2]=n[s>>2];n[s>>2]=0;r=e+20|0;n[i+4>>2]=n[r>>2];n[r>>2]=0;Oo(i);n[i>>2]=n[s>>2];n[s>>2]=0;n[i+4>>2]=n[r>>2];n[r>>2]=0;Oo(i);Oo(s);Xo(e+8|0);Lo(e);J=t;return}function yh(){return 3400}function Bh(){return 3408}function wh(){return 3424}function vh(){var e=0;e=Zf(24)|0;Ih(e);return e|0}function Ch(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;s=t;r=fh()|0;i=Eh(s)|0;s=Fh(s)|0;S(r|0,i|0,s|0,Fc()|0,13,e|0);J=t;return}function Mh(e){e=e|0;return xh(Om[e&3]()|0)|0}function Eh(e){e=e|0;return 1}function Fh(e){e=e|0;return Uh()|0}function xh(e){e=e|0;return e|0}function Uh(){return 5548}function Ih(e){e=e|0;n[e>>2]=0;n[e+4>>2]=0;n[e+8>>2]=0;n[e+12>>2]=0;n[e+16>>2]=0;n[e+20>>2]=0;return}function Th(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=fh()|0;A=Sh(r)|0;r=Dh(r)|0;t=Xc()|0;D(o|0,e|0,A|0,r|0,t|0,5,kh(i)|0,0);J=s;return}function Ph(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;A=Qh(t)|0;t=n[e>>2]|0;r=n[e+4>>2]|0;e=A+(r>>1)|0;if(r&1)t=n[(n[e>>2]|0)+t>>2]|0;r=jc(s)|0;A=zc(i)|0;Wm[t&15](e,r,A);return}function Sh(e){e=e|0;return 4}function Dh(e){e=e|0;return Rh()|0}function kh(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function Qh(e){e=e|0;return e|0}function Rh(){return 160}function Oh(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=fh()|0;A=Lh(r)|0;r=Hh(r)|0;t=th()|0;D(o|0,e|0,A|0,r|0,t|0,8,Nh(i)|0,0);J=s;return}function Vh(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=Qh(t)|0;t=n[e>>2]|0;i=n[e+4>>2]|0;e=r+(i>>1)|0;if(i&1)t=n[(n[e>>2]|0)+t>>2]|0;r=zc(s)|0;zm[t&15](e,r);return}function Lh(e){e=e|0;return 3}function Hh(e){e=e|0;return Gh()|0}function Nh(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function Gh(){return 5552}function jh(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;s=J;J=J+16|0;i=s;r=s+8|0;o=n[t+4>>2]|0;n[i>>2]=n[t>>2];n[i+4>>2]=o;o=fh()|0;A=Wh(r)|0;r=Xh(r)|0;t=th()|0;D(o|0,e|0,A|0,r|0,t|0,9,Kh(i)|0,0);J=s;return}function zh(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=Qh(t)|0;t=n[e>>2]|0;i=n[e+4>>2]|0;e=r+(i>>1)|0;if(i&1)t=n[(n[e>>2]|0)+t>>2]|0;r=qc(s)|0;zm[t&15](e,r);return}function Wh(e){e=e|0;return 3}function Xh(e){e=e|0;return Zh()|0}function Kh(e){e=e|0;var t=0,s=0;t=Zf(8)|0;s=n[e+4>>2]|0;n[t>>2]=n[e>>2];n[t+4>>2]=s;return t|0}function Zh(){return 5564}function Jh(){ee();return}function Yh(){$h();return}function $h(){qh(22144);return}function qh(e){e=e|0;var t=0;t=J;J=J+16|0;n[t>>2]=e;eu();J=t;return}function eu(){H(tu()|0,18653);T(su()|0,18658,1,1,0);iu(18663);ru(18668);nu(18680);Au(18694);ou(18700);au(18715);lu(18719);cu(18732);hu(18737);uu(18751);du(18757);V(pu()|0,18764);V(fu()|0,18776);L(gu()|0,4,18809);L(mu()|0,2,18822);L(_u()|0,4,18837);k(bu()|0,18852);yu(18868);Bu(18898);wu(18935);vu(18974);Cu(19005);Mu(19045);Eu(19074);Fu(19112);xu(19142);Bu(19181);wu(19213);vu(19246);Cu(19279);Mu(19313);Eu(19346);Uu(19380);Iu(19411);Tu(19443);return}function tu(){return Gd()|0}function su(){return Nd()|0}function iu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Ld()|0;R(e|0,n[s>>2]|0,1,-128<<24>>24|0,127<<24>>24|0);J=t;return}function ru(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Od()|0;R(e|0,n[s>>2]|0,1,-128<<24>>24|0,127<<24>>24|0);J=t;return}function nu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Qd()|0;R(e|0,n[s>>2]|0,1,0,255);J=t;return}function Au(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Dd()|0;R(e|0,n[s>>2]|0,2,-32768<<16>>16|0,32767<<16>>16|0);J=t;return}function ou(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Pd()|0;R(e|0,n[s>>2]|0,2,0,65535);J=t;return}function au(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Id()|0;R(e|0,n[s>>2]|0,4,-2147483648,2147483647);J=t;return}function lu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=xd()|0;R(e|0,n[s>>2]|0,4,0,-1);J=t;return}function cu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Ed()|0;R(e|0,n[s>>2]|0,4,-2147483648,2147483647);J=t;return}function hu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=Cd()|0;R(e|0,n[s>>2]|0,4,0,-1);J=t;return}function uu(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=wd()|0;Q(e|0,n[s>>2]|0,4);J=t;return}function du(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;n[s>>2]=e;e=yd()|0;Q(e|0,n[s>>2]|0,8);J=t;return}function pu(){return bd()|0}function fu(){return _d()|0}function gu(){return md()|0}function mu(){return gd()|0}function _u(){return fd()|0}function bu(){return pd()|0}function yu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=hd()|0;e=ud()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Bu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=ad()|0;e=ld()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function wu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=nd()|0;e=Ad()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function vu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=sd()|0;e=id()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Cu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=qu()|0;e=ed()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Mu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Ju()|0;e=Yu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Eu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Xu()|0;e=Ku()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Fu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=ju()|0;e=zu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function xu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Hu()|0;e=Nu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Uu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Ou()|0;e=Vu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Iu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=ku()|0;e=Qu()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Tu(e){e=e|0;var t=0,s=0,i=0;t=J;J=J+16|0;s=t;n[s>>2]=e;i=Pu()|0;e=Su()|0;O(i|0,e|0,n[s>>2]|0);J=t;return}function Pu(){return Du()|0}function Su(){return 7}function Du(){return 3440}function ku(){return Ru()|0}function Qu(){return 7}function Ru(){return 3448}function Ou(){return Lu()|0}function Vu(){return 6}function Lu(){return 3456}function Hu(){return Gu()|0}function Nu(){return 5}function Gu(){return 3464}function ju(){return Wu()|0}function zu(){return 4}function Wu(){return 3472}function Xu(){return Zu()|0}function Ku(){return 5}function Zu(){return 3480}function Ju(){return $u()|0}function Yu(){return 4}function $u(){return 3488}function qu(){return td()|0}function ed(){return 3}function td(){return 3496}function sd(){return rd()|0}function id(){return 2}function rd(){return 3504}function nd(){return od()|0}function Ad(){return 1}function od(){return 3512}function ad(){return cd()|0}function ld(){return 0}function cd(){return 3520}function hd(){return dd()|0}function ud(){return 0}function dd(){return 3528}function pd(){return 3536}function fd(){return 3544}function gd(){return 3576}function md(){return 3600}function _d(){return 3624}function bd(){return 3648}function yd(){return Bd()|0}function Bd(){return 4144}function wd(){return vd()|0}function vd(){return 4136}function Cd(){return Md()|0}function Md(){return 4128}function Ed(){return Fd()|0}function Fd(){return 4120}function xd(){return Ud()|0}function Ud(){return 4112}function Id(){return Td()|0}function Td(){return 4104}function Pd(){return Sd()|0}function Sd(){return 4096}function Dd(){return kd()|0}function kd(){return 4088}function Qd(){return Rd()|0}function Rd(){return 4072}function Od(){return Vd()|0}function Vd(){return 4080}function Ld(){return Hd()|0}function Hd(){return 4064}function Nd(){return 4056}function Gd(){return 4040}function jd(e){e=e|0;var t=0,s=0,i=0,r=0;t=J;J=J+16|0;s=t+8|0;i=t+4|0;r=t;n[r>>2]=e;n[i>>2]=n[r>>2];n[s>>2]=n[(n[i>>2]|0)+4>>2];e=Mp(n[s>>2]|0)|0;J=t;return e|0}function zd(){return 21636}function Wd(e){e=e|0;return(e+-48|0)>>>0<10|0}function Xd(){return 5576}function Kd(e,t){e=e|0;t=t|0;var s=0,r=0;s=i[e>>0]|0;r=i[t>>0]|0;if(s<<24>>24==0?1:s<<24>>24!=r<<24>>24)e=r;else{do{e=e+1|0;t=t+1|0;s=i[e>>0]|0;r=i[t>>0]|0}while(!(s<<24>>24==0?1:s<<24>>24!=r<<24>>24));e=r}return(s&255)-(e&255)|0}function Zd(e){e=e|0;var t=0,s=0,r=0;r=e;e:do{if(!(r&3))s=5;else{t=r;while(1){if(!(i[e>>0]|0)){e=t;break e}e=e+1|0;t=e;if(!(t&3)){s=5;break}}}}while(0);if((s|0)==5){while(1){t=n[e>>2]|0;if(!((t&-2139062144^-2139062144)&t+-16843009))e=e+4|0;else break}if((t&255)<<24>>24)do{e=e+1|0}while((i[e>>0]|0)!=0)}return e-r|0}function Jd(e){e=e|0;return}function Yd(e){e=e|0;return 1}function $d(e){e=e|0;var t=0,s=0;t=e+74|0;s=i[t>>0]|0;i[t>>0]=s+255|s;t=n[e>>2]|0;if(!(t&8)){n[e+8>>2]=0;n[e+4>>2]=0;s=n[e+44>>2]|0;n[e+28>>2]=s;n[e+20>>2]=s;n[e+16>>2]=s+(n[e+48>>2]|0);e=0}else{n[e>>2]=t|32;e=-1}return e|0}function qd(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0;r=s+16|0;A=n[r>>2]|0;if(!A)if(!($d(s)|0)){A=n[r>>2]|0;o=5}else r=0;else o=5;e:do{if((o|0)==5){l=s+20|0;a=n[l>>2]|0;r=a;if((A-a|0)>>>0<t>>>0){r=Nm[n[s+36>>2]&7](s,e,t)|0;break}t:do{if((i[s+75>>0]|0)<0|(t|0)==0){o=0;A=e}else{a=t;while(1){A=a+-1|0;if((i[e+A>>0]|0)==10)break;if(!A){o=0;A=e;break t}else a=A}r=Nm[n[s+36>>2]&7](s,e,a)|0;if(r>>>0<a>>>0)break e;o=a;A=e+a|0;t=t-a|0;r=n[l>>2]|0}}while(0);hm(r|0,A|0,t|0)|0;n[l>>2]=(n[l>>2]|0)+t;r=o+t|0}}while(0);return r|0}function ep(e,t){e=e|0;t=t|0;if(!t)t=0;else t=tp(n[t>>2]|0,n[t+4>>2]|0,e)|0;return((t|0)==0?e:t)|0}function tp(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0;p=(n[e>>2]|0)+1794895138|0;o=sp(n[e+8>>2]|0,p)|0;r=sp(n[e+12>>2]|0,p)|0;A=sp(n[e+16>>2]|0,p)|0;e:do{if((o>>>0<t>>>2>>>0?(d=t-(o<<2)|0,r>>>0<d>>>0&A>>>0<d>>>0):0)?((A|r)&3|0)==0:0){d=r>>>2;u=A>>>2;h=0;while(1){l=o>>>1;c=h+l|0;a=c<<1;A=a+d|0;r=sp(n[e+(A<<2)>>2]|0,p)|0;A=sp(n[e+(A+1<<2)>>2]|0,p)|0;if(!(A>>>0<t>>>0&r>>>0<(t-A|0)>>>0)){r=0;break e}if(i[e+(A+r)>>0]|0){r=0;break e}r=Kd(s,e+A|0)|0;if(!r)break;r=(r|0)<0;if((o|0)==1){r=0;break e}h=r?h:c;o=r?l:o-l|0}r=a+u|0;A=sp(n[e+(r<<2)>>2]|0,p)|0;r=sp(n[e+(r+1<<2)>>2]|0,p)|0;if(r>>>0<t>>>0&A>>>0<(t-r|0)>>>0)r=(i[e+(r+A)>>0]|0)==0?e+r|0:0;else r=0}else r=0}while(0);return r|0}function sp(e,t){e=e|0;t=t|0;var s=0;s=cm(e|0)|0;return((t|0)==0?e:s)|0}function ip(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;o=t&255;r=(s|0)!=0;e:do{if(r&(e&3|0)!=0){A=t&255;while(1){if((i[e>>0]|0)==A<<24>>24){A=6;break e}e=e+1|0;s=s+-1|0;r=(s|0)!=0;if(!(r&(e&3|0)!=0)){A=5;break}}}else A=5}while(0);if((A|0)==5)if(r)A=6;else e=0;e:do{if((A|0)==6){if((i[e>>0]|0)!=(t&255)<<24>>24){r=b(o,16843009)|0;t:do{if(s>>>0>3)do{o=n[e>>2]^r;if((o&-2139062144^-2139062144)&o+-16843009|0)break t;e=e+4|0;s=s+-4|0}while(s>>>0>3)}while(0)}if(!s)e=0;else{r=t&255;while(1){if((i[e>>0]|0)==r<<24>>24)break e;s=s+-1|0;if(!s){e=0;break}else e=e+1|0}}}}while(0);return e|0}function rp(e,t,s){e=e|0;t=t|0;s=s|0;return op(e,t,s,1,8)|0}function np(e,t,s,r,o,a){e=e|0;t=+t;s=s|0;r=r|0;o=o|0;a=a|0;var l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0.0,m=0,_=0,y=0,B=0,w=0,C=0,M=0,E=0,F=0,x=0,U=0,I=0,T=0,P=0,S=0;S=J;J=J+560|0;h=S+32|0;B=S+536|0;P=S;T=P;u=S+540|0;n[B>>2]=0;I=u+12|0;bp(t)|0;l=v()|0;if((l|0)<0){t=-t;bp(t)|0;U=1;x=20247;l=v()|0}else{U=(o&2049|0)!=0&1;x=(o&2048|0)==0?(o&1|0)==0?20248:20253:20250}do{if(0==0&(l&2146435072|0)==2146435072){P=(a&32|0)!=0;l=U+3|0;fp(e,32,s,l,o&-65537);lp(e,x,U);lp(e,t!=t|0.0!=0.0?P?20274:20278:P?20266:20270,3);fp(e,32,s,l,o^8192)}else{g=+yp(t,B)*2.0;l=g!=0.0;if(l)n[B>>2]=(n[B>>2]|0)+-1;y=a|32;if((y|0)==97){p=a&32;m=(p|0)==0?x:x+9|0;f=U|2;l=12-r|0;do{if(!(r>>>0>11|(l|0)==0)){t=8.0;do{l=l+-1|0;t=t*16.0}while((l|0)!=0);if((i[m>>0]|0)==45){t=-(t+(-g-t));break}else{t=g+t-t;break}}else t=g}while(0);c=n[B>>2]|0;l=(c|0)<0?0-c|0:c;l=pp(l,((l|0)<0)<<31>>31,I)|0;if((l|0)==(I|0)){l=u+11|0;i[l>>0]=48}i[l+-1>>0]=(c>>31&2)+43;d=l+-2|0;i[d>>0]=a+15;c=(r|0)<1;h=(o&8|0)==0;u=P;do{U=~~t;l=u+1|0;i[u>>0]=p|A[640+U>>0];t=(t-+(U|0))*16.0;if((l-T|0)==1?!(h&(c&t==0.0)):0){i[l>>0]=46;u=u+2|0}else u=l}while(t!=0.0);if((r|0)!=0?(-2-T+u|0)<(r|0):0){c=I;h=d;l=r+2+c-h|0}else{c=I;h=d;l=c-T-h+u|0}I=l+f|0;fp(e,32,s,I,o);lp(e,m,f);fp(e,48,s,I,o^65536);T=u-T|0;lp(e,P,T);P=c-h|0;fp(e,48,l-(T+P)|0,0,0);lp(e,d,P);fp(e,32,s,I,o^8192);l=I;break}c=(r|0)<0?6:r;if(l){l=(n[B>>2]|0)+-28|0;n[B>>2]=l;t=g*268435456.0}else{t=g;l=n[B>>2]|0}F=(l|0)<0?h:h+288|0;h=F;do{M=~~t>>>0;n[h>>2]=M;h=h+4|0;t=(t-+(M>>>0))*1.0e9}while(t!=0.0);M=F;if((l|0)>0){p=F;while(1){d=(l|0)<29?l:29;l=h+-4|0;if(l>>>0>=p>>>0){u=0;do{_=am(n[l>>2]|0,0,d|0)|0;_=sm(_|0,v()|0,u|0,0)|0;w=v()|0;u=Am(_|0,w|0,1e9,0)|0;C=tm(u|0,v()|0,1e9,0)|0;C=im(_|0,w|0,C|0,v()|0)|0;v()|0;n[l>>2]=C;l=l+-4|0}while(l>>>0>=p>>>0);if(u){C=p+-4|0;n[C>>2]=u;u=C}else u=p}else u=p;e:do{if(h>>>0>u>>>0){l=h;while(1){h=l+-4|0;if(n[h>>2]|0){h=l;break e}if(h>>>0>u>>>0)l=h;else break}}}while(0);l=(n[B>>2]|0)-d|0;n[B>>2]=l;if((l|0)>0)p=u;else break}}else u=F;if((l|0)<0){r=((c+25|0)/9|0)+1|0;_=(y|0)==102;do{m=0-l|0;m=(m|0)<9?m:9;if(u>>>0<h>>>0){d=(1<<m)+-1|0;p=1e9>>>m;f=0;l=u;do{C=n[l>>2]|0;n[l>>2]=(C>>>m)+f;f=b(C&d,p)|0;l=l+4|0}while(l>>>0<h>>>0);u=(n[u>>2]|0)==0?u+4|0:u;if(f){n[h>>2]=f;h=h+4|0}}else u=(n[u>>2]|0)==0?u+4|0:u;l=_?F:u;h=(h-l>>2|0)>(r|0)?l+(r<<2)|0:h;l=(n[B>>2]|0)+m|0;n[B>>2]=l}while((l|0)<0);_=u}else _=u;if(_>>>0<h>>>0){l=(M-_>>2)*9|0;d=n[_>>2]|0;if(d>>>0>=10){u=10;do{u=u*10|0;l=l+1|0}while(d>>>0>=u>>>0)}}else l=0;w=(y|0)==103;C=(c|0)!=0;u=c-((y|0)==102?0:l)+((C&w)<<31>>31)|0;if((u|0)<(((h-M>>2)*9|0)+-9|0)){B=u+9216|0;u=(B|0)/9|0;r=F+4+(u+-1024<<2)|0;u=B-(u*9|0)|0;if((u|0)<8){d=10;while(1){d=d*10|0;if((u|0)<7)u=u+1|0;else break}}else d=10;f=n[r>>2]|0;u=(f>>>0)/(d>>>0)|0;m=f-(b(u,d)|0)|0;p=(r+4|0)==(h|0);if(!(p&(m|0)==0)){g=(u&1|0)==0?9007199254740992.0:9007199254740994.0;B=d>>>1;t=m>>>0<B>>>0?0.5:p&(m|0)==(B|0)?1.0:1.5;if(U){B=(i[x>>0]|0)==45;t=B?-t:t;g=B?-g:g}u=f-m|0;n[r>>2]=u;if(g+t!=g){B=u+d|0;n[r>>2]=B;if(B>>>0>999999999){d=r;l=_;while(1){u=d+-4|0;n[d>>2]=0;if(u>>>0<l>>>0){l=l+-4|0;n[l>>2]=0}B=(n[u>>2]|0)+1|0;n[u>>2]=B;if(B>>>0>999999999)d=u;else{d=l;break}}}else{u=r;d=_}l=(M-d>>2)*9|0;f=n[d>>2]|0;if(f>>>0>=10){p=10;do{p=p*10|0;l=l+1|0}while(f>>>0>=p>>>0)}}else{u=r;d=_}}else{u=r;d=_}B=u+4|0;h=h>>>0>B>>>0?B:h}else d=_;r=0-l|0;e:do{if(h>>>0>d>>>0)while(1){u=h+-4|0;if(n[u>>2]|0){B=h;y=1;break e}if(u>>>0>d>>>0)h=u;else{B=u;y=0;break}}else{B=h;y=0}}while(0);do{if(w){c=c+((C^1)&1)|0;if((c|0)>(l|0)&(l|0)>-5){p=a+-1|0;c=c+-1-l|0}else{p=a+-2|0;c=c+-1|0}if(!(o&8)){if(y?(E=n[B+-4>>2]|0,(E|0)!=0):0)if(!((E>>>0)%10|0)){u=0;h=10;do{h=h*10|0;u=u+1|0}while(!((E>>>0)%(h>>>0)|0|0))}else u=0;else u=9;h=((B-M>>2)*9|0)+-9|0;if((p|32|0)==102){a=h-u|0;a=(a|0)>0?a:0;c=(c|0)<(a|0)?c:a;break}else{a=h+l-u|0;a=(a|0)>0?a:0;c=(c|0)<(a|0)?c:a;break}}}else p=a}while(0);_=(c|0)!=0;f=_?1:o>>>3&1;m=(p|32|0)==102;if(m){w=0;l=(l|0)>0?l:0}else{h=(l|0)<0?r:l;h=pp(h,((h|0)<0)<<31>>31,I)|0;u=I;if((u-h|0)<2)do{h=h+-1|0;i[h>>0]=48}while((u-h|0)<2);i[h+-1>>0]=(l>>31&2)+43;l=h+-2|0;i[l>>0]=p;w=l;l=u-l|0}l=U+1+c+f+l|0;fp(e,32,s,l,o);lp(e,x,U);fp(e,48,s,l,o^65536);if(m){f=d>>>0>F>>>0?F:d;m=P+9|0;d=m;p=P+8|0;u=f;do{h=pp(n[u>>2]|0,0,m)|0;if((u|0)==(f|0)){if((h|0)==(m|0)){i[p>>0]=48;h=p}}else if(h>>>0>P>>>0){dm(P|0,48,h-T|0)|0;do{h=h+-1|0}while(h>>>0>P>>>0)}lp(e,h,d-h|0);u=u+4|0}while(u>>>0<=F>>>0);if(!((o&8|0)==0&(_^1)))lp(e,20282,1);if(u>>>0<B>>>0&(c|0)>0)while(1){h=pp(n[u>>2]|0,0,m)|0;if(h>>>0>P>>>0){dm(P|0,48,h-T|0)|0;do{h=h+-1|0}while(h>>>0>P>>>0)}lp(e,h,(c|0)<9?c:9);u=u+4|0;h=c+-9|0;if(!(u>>>0<B>>>0&(c|0)>9)){c=h;break}else c=h}fp(e,48,c+9|0,9,0)}else{B=y?B:d+4|0;if(d>>>0<B>>>0&(c|0)>-1){r=P+9|0;_=(o&8|0)==0;y=r;f=0-T|0;m=P+8|0;p=d;do{h=pp(n[p>>2]|0,0,r)|0;if((h|0)==(r|0)){i[m>>0]=48;h=m}do{if((p|0)==(d|0)){u=h+1|0;lp(e,h,1);if(_&(c|0)<1){h=u;break}lp(e,20282,1);h=u}else{if(h>>>0<=P>>>0)break;dm(P|0,48,h+f|0)|0;do{h=h+-1|0}while(h>>>0>P>>>0)}}while(0);T=y-h|0;lp(e,h,(c|0)>(T|0)?T:c);c=c-T|0;p=p+4|0}while(p>>>0<B>>>0&(c|0)>-1)}fp(e,48,c+18|0,18,0);lp(e,w,I-w|0)}fp(e,32,s,l,o^8192)}}while(0);J=S;return((l|0)<(s|0)?s:l)|0}function Ap(e,t){e=e|0;t=t|0;var s=0.0,i=0;i=(n[t>>2]|0)+(8-1)&~(8-1);s=+l[i>>3];n[t>>2]=i+8;l[e>>3]=s;return}function op(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,b=0;b=J;J=J+224|0;f=b+208|0;g=b+160|0;m=b+80|0;_=b;o=g;a=o+40|0;do{n[o>>2]=0;o=o+4|0}while((o|0)<(a|0));n[f>>2]=n[s>>2];if((ap(0,t,f,m,g,r,A)|0)<0)s=-1;else{if((n[e+76>>2]|0)>-1)p=Yd(e)|0;else p=0;s=n[e>>2]|0;d=s&32;if((i[e+74>>0]|0)<1)n[e>>2]=s&-33;o=e+48|0;if(!(n[o>>2]|0)){a=e+44|0;l=n[a>>2]|0;n[a>>2]=_;c=e+28|0;n[c>>2]=_;h=e+20|0;n[h>>2]=_;n[o>>2]=80;u=e+16|0;n[u>>2]=_+80;s=ap(e,t,f,m,g,r,A)|0;if(l){Nm[n[e+36>>2]&7](e,0,0)|0;s=(n[h>>2]|0)==0?-1:s;n[a>>2]=l;n[o>>2]=0;n[u>>2]=0;n[c>>2]=0;n[h>>2]=0}}else s=ap(e,t,f,m,g,r,A)|0;o=n[e>>2]|0;n[e>>2]=o|d;if(p|0)Jd(e);s=(o&32|0)==0?s:-1}J=b;return s|0}function ap(e,t,s,A,o,a,c){e=e|0;t=t|0;s=s|0;A=A|0;o=o|0;a=a|0;c=c|0;var h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,b=0,y=0,B=0,w=0,C=0,M=0,E=0,F=0,x=0,U=0,I=0,T=0,P=0,S=0,D=0,k=0,Q=0;k=J;J=J+64|0;P=k+56|0;D=k+40|0;F=k;U=k+48|0;I=k+60|0;n[P>>2]=t;C=(e|0)!=0;M=F+40|0;E=M;F=F+39|0;x=U+4|0;h=0;t=0;d=0;e:while(1){do{do{if((t|0)>-1)if((h|0)>(2147483647-t|0)){n[(zd()|0)>>2]=61;t=-1;break}else{t=h+t|0;break}}while(0);m=n[P>>2]|0;h=i[m>>0]|0;if(!(h<<24>>24)){w=92;break e}u=m;t:while(1){switch(h<<24>>24){case 37:{w=10;break t}case 0:{h=u;break t}default:{}}B=u+1|0;n[P>>2]=B;h=i[B>>0]|0;u=B}t:do{if((w|0)==10){w=0;h=u;do{if((i[u+1>>0]|0)!=37)break t;h=h+1|0;u=u+2|0;n[P>>2]=u}while((i[u>>0]|0)==37)}}while(0);h=h-m|0;if(C)lp(e,m,h)}while((h|0)!=0);B=(Wd(i[(n[P>>2]|0)+1>>0]|0)|0)==0;u=n[P>>2]|0;if(!B?(i[u+2>>0]|0)==36:0){b=(i[u+1>>0]|0)+-48|0;f=1;h=3}else{b=-1;f=d;h=1}h=u+h|0;n[P>>2]=h;u=i[h>>0]|0;d=(u<<24>>24)+-32|0;if(d>>>0>31|(1<<d&75913|0)==0)p=0;else{p=0;do{p=1<<d|p;h=h+1|0;n[P>>2]=h;u=i[h>>0]|0;d=(u<<24>>24)+-32|0}while(!(d>>>0>31|(1<<d&75913|0)==0))}if(u<<24>>24==42){if((Wd(i[h+1>>0]|0)|0)!=0?(S=n[P>>2]|0,(i[S+2>>0]|0)==36):0){h=S+1|0;n[o+((i[h>>0]|0)+-48<<2)>>2]=10;h=n[A+((i[h>>0]|0)+-48<<3)>>2]|0;d=1;u=S+3|0}else{if(f|0){t=-1;break}if(C){B=(n[s>>2]|0)+(4-1)&~(4-1);h=n[B>>2]|0;n[s>>2]=B+4}else h=0;d=0;u=(n[P>>2]|0)+1|0}n[P>>2]=u;B=(h|0)<0;y=B?0-h|0:h;p=B?p|8192:p;B=d}else{h=cp(P)|0;if((h|0)<0){t=-1;break}y=h;B=f;u=n[P>>2]|0}do{if((i[u>>0]|0)==46){h=u+1|0;if((i[h>>0]|0)!=42){n[P>>2]=h;h=cp(P)|0;u=n[P>>2]|0;break}if(Wd(i[u+2>>0]|0)|0?(T=n[P>>2]|0,(i[T+3>>0]|0)==36):0){h=T+2|0;n[o+((i[h>>0]|0)+-48<<2)>>2]=10;h=n[A+((i[h>>0]|0)+-48<<3)>>2]|0;u=T+4|0;n[P>>2]=u;break}if(B|0){t=-1;break e}if(C){_=(n[s>>2]|0)+(4-1)&~(4-1);h=n[_>>2]|0;n[s>>2]=_+4}else h=0;u=(n[P>>2]|0)+2|0;n[P>>2]=u}else h=-1}while(0);_=0;while(1){if(((i[u>>0]|0)+-65|0)>>>0>57){t=-1;break e}d=u;u=u+1|0;n[P>>2]=u;d=i[(i[d>>0]|0)+-65+(176+(_*58|0))>>0]|0;f=d&255;if((f+-1|0)>>>0>=8)break;else _=f}if(!(d<<24>>24)){t=-1;break}g=(b|0)>-1;do{if(d<<24>>24==19)if(g){t=-1;break e}else w=54;else{if(g){n[o+(b<<2)>>2]=f;g=A+(b<<3)|0;b=n[g+4>>2]|0;w=D;n[w>>2]=n[g>>2];n[w+4>>2]=b;w=54;break}if(!C){t=0;break e}hp(D,f,s,c);u=n[P>>2]|0;w=55}}while(0);if((w|0)==54){w=0;if(C)w=55;else h=0}t:do{if((w|0)==55){w=0;u=i[u+-1>>0]|0;u=(_|0)!=0&(u&15|0)==3?u&-33:u;d=p&-65537;b=(p&8192|0)==0?p:d;s:do{switch(u|0){case 110:switch((_&255)<<24>>24){case 0:{n[n[D>>2]>>2]=t;h=0;break t}case 1:{n[n[D>>2]>>2]=t;h=0;break t}case 2:{h=n[D>>2]|0;n[h>>2]=t;n[h+4>>2]=((t|0)<0)<<31>>31;h=0;break t}case 3:{r[n[D>>2]>>1]=t;h=0;break t}case 4:{i[n[D>>2]>>0]=t;h=0;break t}case 6:{n[n[D>>2]>>2]=t;h=0;break t}case 7:{h=n[D>>2]|0;n[h>>2]=t;n[h+4>>2]=((t|0)<0)<<31>>31;h=0;break t}default:{h=0;break t}}case 112:{u=120;h=h>>>0>8?h:8;d=b|8;w=67;break}case 88:case 120:{d=b;w=67;break}case 111:{g=D;g=dp(n[g>>2]|0,n[g+4>>2]|0,M)|0;d=E-g|0;p=0;f=20230;h=(b&8|0)==0|(h|0)>(d|0)?h:d+1|0;d=b;w=73;break}case 105:case 100:{d=D;u=n[d>>2]|0;d=n[d+4>>2]|0;if((d|0)<0){u=im(0,0,u|0,d|0)|0;d=v()|0;p=D;n[p>>2]=u;n[p+4>>2]=d;p=1;f=20230;w=72;break s}else{p=(b&2049|0)!=0&1;f=(b&2048|0)==0?(b&1|0)==0?20230:20232:20231;w=72;break s}}case 117:{d=D;p=0;f=20230;u=n[d>>2]|0;d=n[d+4>>2]|0;w=72;break}case 99:{i[F>>0]=n[D>>2];m=F;p=0;f=20230;g=1;u=d;h=E;break}case 115:{_=n[D>>2]|0;_=(_|0)==0?20240:_;b=ip(_,0,h)|0;Q=(b|0)==0;m=_;p=0;f=20230;g=Q?h:b-_|0;u=d;h=Q?_+h|0:b;break}case 67:{n[U>>2]=n[D>>2];n[x>>2]=0;n[D>>2]=U;f=-1;w=79;break}case 83:{if(!h){fp(e,32,y,0,b);h=0;w=89}else{f=h;w=79}break}case 65:case 71:case 70:case 69:case 97:case 103:case 102:case 101:{h=Lm[a&1](e,+l[D>>3],y,h,b,u)|0;break t}default:{p=0;f=20230;g=h;u=b;h=E}}}while(0);s:do{if((w|0)==67){g=D;g=up(n[g>>2]|0,n[g+4>>2]|0,M,u&32)|0;f=D;f=(d&8|0)==0|(n[f>>2]|0)==0&(n[f+4>>2]|0)==0;p=f?0:2;f=f?20230:20230+(u>>>4)|0;w=73}else if((w|0)==72){g=pp(u,d,M)|0;d=b;w=73}else if((w|0)==79){w=0;p=n[D>>2]|0;h=0;while(1){u=n[p>>2]|0;if(!u)break;u=gp(I,u)|0;d=(u|0)<0;if(d|u>>>0>(f-h|0)>>>0){w=83;break}h=u+h|0;if(f>>>0>h>>>0)p=p+4|0;else break}if((w|0)==83){w=0;if(d){t=-1;break e}}fp(e,32,y,h,b);if(!h){h=0;w=89}else{d=n[D>>2]|0;p=0;while(1){u=n[d>>2]|0;if(!u){w=89;break s}u=gp(I,u)|0;p=u+p|0;if((p|0)>(h|0)){w=89;break s}lp(e,I,u);if(p>>>0>=h>>>0){w=89;break}else d=d+4|0}}}}while(0);if((w|0)==73){w=0;u=D;u=(n[u>>2]|0)!=0|(n[u+4>>2]|0)!=0;Q=(h|0)!=0|u;u=E-g+((u^1)&1)|0;m=Q?g:M;g=Q?(h|0)>(u|0)?h:u:0;u=(h|0)>-1?d&-65537:d;h=E}else if((w|0)==89){w=0;fp(e,32,y,h,b^8192);h=(y|0)>(h|0)?y:h;break}b=h-m|0;_=(g|0)<(b|0)?b:g;Q=_+p|0;h=(y|0)<(Q|0)?Q:y;fp(e,32,h,Q,u);lp(e,f,p);fp(e,48,h,Q,u^65536);fp(e,48,_,b,0);lp(e,m,b);fp(e,32,h,Q,u^8192)}}while(0);d=B}e:do{if((w|0)==92)if(!e)if(!d)t=0;else{t=1;while(1){h=n[o+(t<<2)>>2]|0;if(!h)break;hp(A+(t<<3)|0,h,s,c);t=t+1|0;if(t>>>0>=10){t=1;break e}}while(1){if(n[o+(t<<2)>>2]|0){t=-1;break e}t=t+1|0;if(t>>>0>=10){t=1;break}}}}while(0);J=k;return t|0}function lp(e,t,s){e=e|0;t=t|0;s=s|0;if(!(n[e>>2]&32))qd(t,s,e)|0;return}function cp(e){e=e|0;var t=0,s=0;if(!(Wd(i[n[e>>2]>>0]|0)|0))t=0;else{t=0;do{s=n[e>>2]|0;t=(t*10|0)+-48+(i[s>>0]|0)|0;s=s+1|0;n[e>>2]=s}while((Wd(i[s>>0]|0)|0)!=0)}return t|0}function hp(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0.0;e:do{if(t>>>0<=20)do{switch(t|0){case 9:{t=(n[s>>2]|0)+(4-1)&~(4-1);i=n[t>>2]|0;n[s>>2]=t+4;n[e>>2]=i;break e}case 10:{i=(n[s>>2]|0)+(4-1)&~(4-1);t=n[i>>2]|0;n[s>>2]=i+4;i=e;n[i>>2]=t;n[i+4>>2]=((t|0)<0)<<31>>31;break e}case 11:{i=(n[s>>2]|0)+(4-1)&~(4-1);t=n[i>>2]|0;n[s>>2]=i+4;i=e;n[i>>2]=t;n[i+4>>2]=0;break e}case 12:{i=(n[s>>2]|0)+(8-1)&~(8-1);t=i;r=n[t>>2]|0;t=n[t+4>>2]|0;n[s>>2]=i+8;i=e;n[i>>2]=r;n[i+4>>2]=t;break e}case 13:{r=(n[s>>2]|0)+(4-1)&~(4-1);i=n[r>>2]|0;n[s>>2]=r+4;i=(i&65535)<<16>>16;r=e;n[r>>2]=i;n[r+4>>2]=((i|0)<0)<<31>>31;break e}case 14:{r=(n[s>>2]|0)+(4-1)&~(4-1);i=n[r>>2]|0;n[s>>2]=r+4;r=e;n[r>>2]=i&65535;n[r+4>>2]=0;break e}case 15:{r=(n[s>>2]|0)+(4-1)&~(4-1);i=n[r>>2]|0;n[s>>2]=r+4;i=(i&255)<<24>>24;r=e;n[r>>2]=i;n[r+4>>2]=((i|0)<0)<<31>>31;break e}case 16:{r=(n[s>>2]|0)+(4-1)&~(4-1);i=n[r>>2]|0;n[s>>2]=r+4;r=e;n[r>>2]=i&255;n[r+4>>2]=0;break e}case 17:{r=(n[s>>2]|0)+(8-1)&~(8-1);A=+l[r>>3];n[s>>2]=r+8;l[e>>3]=A;break e}case 18:{zm[i&15](e,s);break e}default:break e}}while(0)}while(0);return}function up(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;if(!((e|0)==0&(t|0)==0))do{s=s+-1|0;i[s>>0]=A[640+(e&15)>>0]|0|r;e=om(e|0,t|0,4)|0;t=v()|0}while(!((e|0)==0&(t|0)==0));return s|0}function dp(e,t,s){e=e|0;t=t|0;s=s|0;if(!((e|0)==0&(t|0)==0))do{s=s+-1|0;i[s>>0]=e&7|48;e=om(e|0,t|0,3)|0;t=v()|0}while(!((e|0)==0&(t|0)==0));return s|0}function pp(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,n=0,A=0;if(t>>>0>0|(t|0)==0&e>>>0>4294967295){do{r=e;e=Am(e|0,t|0,10,0)|0;n=t;t=v()|0;A=tm(e|0,t|0,10,0)|0;A=im(r|0,n|0,A|0,v()|0)|0;v()|0;s=s+-1|0;i[s>>0]=A&255|48}while(n>>>0>9|(n|0)==9&r>>>0>4294967295);t=e}else t=e;if(t)do{A=t;t=(t>>>0)/10|0;s=s+-1|0;i[s>>0]=A-(t*10|0)|48}while(A>>>0>=10);return s|0}function fp(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var n=0,A=0;A=J;J=J+256|0;n=A;if((s|0)>(i|0)&(r&73728|0)==0){r=s-i|0;dm(n|0,t<<24>>24|0,(r>>>0<256?r:256)|0)|0;if(r>>>0>255){t=s-i|0;do{lp(e,n,256);r=r+-256|0}while(r>>>0>255);r=t&255}lp(e,n,r)}J=A;return}function gp(e,t){e=e|0;t=t|0;if(!e)e=0;else e=mp(e,t,0)|0;return e|0}function mp(e,t,s){e=e|0;t=t|0;s=s|0;do{if(e){if(t>>>0<128){i[e>>0]=t;e=1;break}if(!(n[n[(_p()|0)+176>>2]>>2]|0))if((t&-128|0)==57216){i[e>>0]=t;e=1;break}else{n[(zd()|0)>>2]=25;e=-1;break}if(t>>>0<2048){i[e>>0]=t>>>6|192;i[e+1>>0]=t&63|128;e=2;break}if(t>>>0<55296|(t&-8192|0)==57344){i[e>>0]=t>>>12|224;i[e+1>>0]=t>>>6&63|128;i[e+2>>0]=t&63|128;e=3;break}if((t+-65536|0)>>>0<1048576){i[e>>0]=t>>>18|240;i[e+1>>0]=t>>>12&63|128;i[e+2>>0]=t>>>6&63|128;i[e+3>>0]=t&63|128;e=4;break}else{n[(zd()|0)>>2]=25;e=-1;break}}else e=1}while(0);return e|0}function _p(){return Xd()|0}function bp(e){e=+e;var t=0;l[c>>3]=e;t=n[c>>2]|0;w(n[c+4>>2]|0);return t|0}function yp(e,t){e=+e;t=t|0;var s=0,i=0,r=0;l[c>>3]=e;s=n[c>>2]|0;i=n[c+4>>2]|0;r=om(s|0,i|0,52)|0;v()|0;switch(r&2047){case 0:{if(e!=0.0){e=+yp(e*18446744073709551616.0,t);s=(n[t>>2]|0)+-64|0}else s=0;n[t>>2]=s;break}case 2047:break;default:{n[t>>2]=(r&2047)+-1022;n[c>>2]=s;n[c+4>>2]=i&-2146435073|1071644672;e=+l[c>>3]}}return+e}function Bp(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,n=0;e:do{if(!s)e=0;else{while(1){r=i[e>>0]|0;n=i[t>>0]|0;if(r<<24>>24!=n<<24>>24)break;s=s+-1|0;if(!s){e=0;break e}else{e=e+1|0;t=t+1|0}}e=(r&255)-(n&255)|0}}while(0);return e|0}function wp(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;r=J;J=J+16|0;A=r;n[A>>2]=i;i=vp(e,t,s,A)|0;J=r;return i|0}function vp(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0,o=0,a=0,l=0;l=J;J=J+160|0;A=l+144|0;a=l;hm(a|0,3672,144)|0;if((t+-1|0)>>>0>2147483646)if(!t){e=A;t=1;o=4}else{n[(zd()|0)>>2]=61;t=-1}else o=4;if((o|0)==4){o=-2-e|0;o=t>>>0>o>>>0?o:t;n[a+48>>2]=o;A=a+20|0;n[A>>2]=e;n[a+44>>2]=e;t=e+o|0;e=a+16|0;n[e>>2]=t;n[a+28>>2]=t;t=rp(a,s,r)|0;if(o){a=n[A>>2]|0;i[a+(((a|0)==(n[e>>2]|0))<<31>>31)>>0]=0}}J=l;return t|0}function Cp(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;i=e+20|0;r=n[i>>2]|0;e=(n[e+16>>2]|0)-r|0;e=e>>>0>s>>>0?s:e;hm(r|0,t|0,e|0)|0;n[i>>2]=(n[i>>2]|0)+e;return s|0}function Mp(e){e=e|0;var t=0,s=0;t=(Zd(e)|0)+1|0;s=Kg(t)|0;if(!s)e=0;else e=hm(s|0,e|0,t|0)|0;return e|0}function Ep(e,t){e=e|0;t=t|0;var s=0,r=0;s=0;while(1){if((A[656+s>>0]|0)==(e|0)){r=4;break}s=s+1|0;if((s|0)==87){e=87;r=5;break}}if((r|0)==4)if(!s)s=752;else{e=s;r=5}if((r|0)==5){s=752;do{do{r=s;s=s+1|0}while((i[r>>0]|0)!=0);e=e+-1|0}while((e|0)!=0)}return Fp(s,n[t+20>>2]|0)|0}function Fp(e,t){e=e|0;t=t|0;return ep(e,t)|0}function xp(e){e=e|0;return Ep(e,n[(Up()|0)+176>>2]|0)|0}function Up(){return Xd()|0}function Ip(e,t,s){e=e|0;t=t|0;s=s|0;var r=0;r=xp(e)|0;e=Zd(r)|0;if(e>>>0>=s>>>0){e=s+-1|0;if(!s)e=68;else{hm(t|0,r|0,e|0)|0;i[t+e>>0]=0;e=68}}else{hm(t|0,r|0,e+1|0)|0;e=0}return e|0}function Tp(){var e=0,t=0,s=0,i=0,r=0,A=0,o=0;i=J;J=J+48|0;A=i+32|0;t=i+24|0;o=i+16|0;r=i;i=i+36|0;e=Pp()|0;if(e|0?(s=n[e>>2]|0,s|0):0){e=s+48|0;if(!(Sp(e)|0)){n[t>>2]=20420;kp(20370,t)}t=Dp(e)|0;if((t|0)==1126902529&(v()|0)==1129074247)e=n[s+44>>2]|0;else e=s+80|0;n[i>>2]=e;s=n[s>>2]|0;e=n[s+4>>2]|0;if(Nm[n[(n[954]|0)+16>>2]&7](3816,s,i)|0){o=n[i>>2]|0;o=Vm[n[(n[o>>2]|0)+8>>2]&15](o)|0;n[r>>2]=20420;n[r+4>>2]=e;n[r+8>>2]=o;kp(20284,r)}else{n[o>>2]=20420;n[o+4>>2]=e;kp(20329,o)}}kp(20408,A)}function Pp(){return 21640}function Sp(e){e=e|0;e=Dp(e)|0;return(e&-256|0)==1126902528&(v()|0)==1129074247|0}function Dp(e){e=e|0;var t=0;t=e;e=n[t>>2]|0;w(n[t+4>>2]|0);return e|0}function kp(e,t){e=e|0;t=t|0;Z()}function Qp(e){e=e|0;return}function Rp(e){e=e|0;Qp(e);qp(e);return}function Op(e){e=e|0;return}function Vp(e){e=e|0;return}function Lp(e,t,s){e=e|0;t=t|0;s=s|0;var A=0,o=0,a=0,l=0,c=0,h=0;h=J;J=J+64|0;l=h;if(!(jp(e,t,0)|0))if((t|0)!=0?(c=Kp(t,3840,3824,0)|0,(c|0)!=0):0){n[l>>2]=c;n[l+4>>2]=0;n[l+8>>2]=e;n[l+12>>2]=-1;e=l+16|0;t=l+24|0;A=l+48|0;o=e;a=o+36|0;do{n[o>>2]=0;o=o+4|0}while((o|0)<(a|0));r[e+36>>1]=0;i[e+38>>0]=0;n[A>>2]=1;Xm[n[(n[c>>2]|0)+28>>2]&7](c,l,n[s>>2]|0,1);if((n[t>>2]|0)==1){n[s>>2]=n[e>>2];e=1}else e=0}else e=0;else e=1;J=h;return e|0}function Hp(e,t,s,i,r,A){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;A=A|0;if(jp(e,n[t+8>>2]|0,A)|0)Xp(0,t,s,i,r);return}function Np(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0;do{if(!(jp(e,n[t+8>>2]|0,A)|0)){if(jp(e,n[t>>2]|0,A)|0){if((n[t+16>>2]|0)!=(s|0)?(o=t+20|0,(n[o>>2]|0)!=(s|0)):0){n[t+32>>2]=r;n[o>>2]=s;A=t+40|0;n[A>>2]=(n[A>>2]|0)+1;if((n[t+36>>2]|0)==1?(n[t+24>>2]|0)==2:0)i[t+54>>0]=1;n[t+44>>2]=4;break}if((r|0)==1)n[t+32>>2]=1}}else Wp(0,t,s,r)}while(0);return}function Gp(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;if(jp(e,n[t+8>>2]|0,0)|0)zp(0,t,s,i);return}function jp(e,t,s){e=e|0;t=t|0;s=s|0;if(s)if((e|0)==(t|0))e=1;else e=(Kd(n[e+4>>2]|0,n[t+4>>2]|0)|0)==0;else e=(n[e+4>>2]|0)==(n[t+4>>2]|0);return e|0}function zp(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0;e=t+16|0;A=n[e>>2]|0;do{if(A){if((A|0)!=(s|0)){r=t+36|0;n[r>>2]=(n[r>>2]|0)+1;n[t+24>>2]=2;i[t+54>>0]=1;break}e=t+24|0;if((n[e>>2]|0)==2)n[e>>2]=r}else{n[e>>2]=s;n[t+24>>2]=r;n[t+36>>2]=1}}while(0);return}function Wp(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0;if((n[t+4>>2]|0)==(s|0)?(r=t+28|0,(n[r>>2]|0)!=1):0)n[r>>2]=i;return}function Xp(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;i[t+53>>0]=1;do{if((n[t+4>>2]|0)==(r|0)){i[t+52>>0]=1;e=t+16|0;r=n[e>>2]|0;if(!r){n[e>>2]=s;n[t+24>>2]=A;n[t+36>>2]=1;if(!((A|0)==1?(n[t+48>>2]|0)==1:0))break;i[t+54>>0]=1;break}if((r|0)!=(s|0)){A=t+36|0;n[A>>2]=(n[A>>2]|0)+1;i[t+54>>0]=1;break}r=t+24|0;e=n[r>>2]|0;if((e|0)==2){n[r>>2]=A;e=A}if((e|0)==1?(n[t+48>>2]|0)==1:0)i[t+54>>0]=1}}while(0);return}function Kp(e,t,s,A){e=e|0;t=t|0;s=s|0;A=A|0;var o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0;f=J;J=J+64|0;d=f;u=n[e>>2]|0;p=e+(n[u+-8>>2]|0)|0;u=n[u+-4>>2]|0;n[d>>2]=s;n[d+4>>2]=e;n[d+8>>2]=t;n[d+12>>2]=A;e=d+16|0;t=d+20|0;A=d+24|0;o=d+28|0;a=d+32|0;l=d+40|0;c=e;h=c+36|0;do{n[c>>2]=0;c=c+4|0}while((c|0)<(h|0));r[e+36>>1]=0;i[e+38>>0]=0;e:do{if(jp(u,s,0)|0){n[d+48>>2]=1;Zm[n[(n[u>>2]|0)+20>>2]&3](u,d,p,p,1,0);e=(n[A>>2]|0)==1?p:0}else{Km[n[(n[u>>2]|0)+24>>2]&3](u,d,p,1,0);switch(n[d+36>>2]|0){case 0:{e=(n[l>>2]|0)==1&(n[o>>2]|0)==1&(n[a>>2]|0)==1?n[t>>2]|0:0;break e}case 1:break;default:{e=0;break e}}if((n[A>>2]|0)!=1?!((n[l>>2]|0)==0&(n[o>>2]|0)==1&(n[a>>2]|0)==1):0){e=0;break}e=n[e>>2]|0}}while(0);J=f;return e|0}function Zp(e){e=e|0;Qp(e);qp(e);return}function Jp(e,t,s,i,r,A){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;A=A|0;if(jp(e,n[t+8>>2]|0,A)|0)Xp(0,t,s,i,r);else{e=n[e+8>>2]|0;Zm[n[(n[e>>2]|0)+20>>2]&3](e,t,s,i,r,A)}return}function Yp(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0,a=0,l=0;e:do{if(!(jp(e,n[t+8>>2]|0,A)|0)){if(!(jp(e,n[t>>2]|0,A)|0)){a=n[e+8>>2]|0;Km[n[(n[a>>2]|0)+24>>2]&3](a,t,s,r,A);break}if((n[t+16>>2]|0)!=(s|0)?(a=t+20|0,(n[a>>2]|0)!=(s|0)):0){n[t+32>>2]=r;r=t+44|0;do{if((n[r>>2]|0)!=4){o=t+52|0;i[o>>0]=0;l=t+53|0;i[l>>0]=0;e=n[e+8>>2]|0;Zm[n[(n[e>>2]|0)+20>>2]&3](e,t,s,s,1,A);if(i[l>>0]|0){l=(i[o>>0]|0)==0;n[r>>2]=3;if(l)break;else break e}else{n[r>>2]=4;break}}}while(0);n[a>>2]=s;l=t+40|0;n[l>>2]=(n[l>>2]|0)+1;if((n[t+36>>2]|0)!=1)break;if((n[t+24>>2]|0)!=2)break;i[t+54>>0]=1;break}if((r|0)==1)n[t+32>>2]=1}else Wp(0,t,s,r)}while(0);return}function $p(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;if(jp(e,n[t+8>>2]|0,0)|0)zp(0,t,s,i);else{e=n[e+8>>2]|0;Xm[n[(n[e>>2]|0)+28>>2]&7](e,t,s,i)}return}function qp(e){e=e|0;Zg(e);return}function ef(e){e=e|0;return}function tf(){var e=0,t=0;e=Pp()|0;if((e|0?(t=n[e>>2]|0,t|0):0)?Sp(t+48|0)|0:0)sf(n[t+12>>2]|0);sf(rf()|0)}function sf(e){e=e|0;var t=0;t=J;J=J+16|0;Gm[e&3]();kp(20559,t)}function rf(){return 2}function nf(e){e=e|0;return}function Af(e){e=e|0;qp(e);return}function of(e){e=e|0;return 20599}function af(e){e=e|0;n[e>>2]=5916;uf(e+4|0);return}function lf(e){e=e|0;af(e);qp(e);return}function cf(e){e=e|0;return hf(e+4|0)|0}function hf(e){e=e|0;return n[e>>2]|0}function uf(e){e=e|0;var t=0,s=0;if(df(e)|0?(t=pf(n[e>>2]|0)|0,s=t+8|0,e=n[s>>2]|0,n[s>>2]=e+-1,(e|0)<1):0)qp(t);return}function df(e){e=e|0;return 1}function pf(e){e=e|0;return e+-12|0}function ff(e){e=e|0;n[e>>2]=5936;uf(e+4|0);return}function gf(e){e=e|0;ff(e);qp(e);return}function mf(e){e=e|0;return hf(e+4|0)|0}function _f(e){e=e|0;af(e);qp(e);return}function bf(e){e=e|0;af(e);qp(e);return}function yf(){var e=0;e=J;J=J+16|0;kp(20848,e)}function Bf(e){e=e|0;Qp(e);qp(e);return}function wf(e,t,s){e=e|0;t=t|0;s=s|0;return jp(e,t,0)|0}function vf(e){e=e|0;Qp(e);qp(e);return}function Cf(e,t,s){e=e|0;t=t|0;s=s|0;var A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0;d=J;J=J+64|0;h=d;do{if(!(jp(t,4048,0)|0)){if(Mf(e,t,0)|0){t=n[s>>2]|0;if(!t){t=1;break}n[s>>2]=n[t>>2];t=1;break}if((t|0)!=0?(A=Kp(t,3840,3976,0)|0,(A|0)!=0):0){t=n[s>>2]|0;if(t|0)n[s>>2]=n[t>>2];t=n[A+8>>2]|0;a=e+8|0;o=n[a>>2]|0;if((t&7&(o^7)|0)==0?((t&96^96)&o|0)==0:0){o=e+12|0;e=n[o>>2]|0;A=A+12|0;t=n[A>>2]|0;if(!(jp(e,t,0)|0)){if(jp(e,4040,0)|0){if(!t){t=1;break}t=(Kp(t,3840,3992,0)|0)==0;break}if(e){t=Kp(e,3840,3976,0)|0;if(t|0){if(!(n[a>>2]&1)){t=0;break}t=Ef(t,n[A>>2]|0)|0;break}t=n[o>>2]|0;if(t){t=Kp(t,3840,4008,0)|0;if(t|0){if(!(n[a>>2]&1)){t=0;break}t=Ff(t,n[A>>2]|0)|0;break}t=n[o>>2]|0;if((((t|0)!=0?(l=Kp(t,3840,3824,0)|0,(l|0)!=0):0)?(c=n[A>>2]|0,(c|0)!=0):0)?(u=Kp(c,3840,3824,0)|0,(u|0)!=0):0){n[h>>2]=u;n[h+4>>2]=0;n[h+8>>2]=l;n[h+12>>2]=-1;t=h+16|0;e=h+24|0;A=h+48|0;o=t;a=o+36|0;do{n[o>>2]=0;o=o+4|0}while((o|0)<(a|0));r[t+36>>1]=0;i[t+38>>0]=0;n[A>>2]=1;Xm[n[(n[u>>2]|0)+28>>2]&7](u,h,n[s>>2]|0,1);do{if((n[e>>2]|0)==1){if(!(n[s>>2]|0)){t=1;break}n[s>>2]=n[t>>2];t=1}else t=0}while(0)}else t=0}else t=0}else t=0}else t=1}else t=0}else t=0}else{n[s>>2]=0;t=1}}while(0);J=d;return t|0}function Mf(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;if(!(n[e+8>>2]&24))if((t|0)!=0?(i=Kp(t,3840,3960,0)|0,(i|0)!=0):0){s=(n[i+8>>2]&24|0)!=0;r=5}else s=0;else{s=1;r=5}if((r|0)==5)s=jp(e,t,s)|0;return s|0}function Ef(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,A=0,o=0;while(1){if(!t){t=0;break}s=Kp(t,3840,3976,0)|0;if(!s){t=0;break}r=n[e+8>>2]|0;if(n[s+8>>2]&~r|0){t=0;break}i=e+12|0;t=n[i>>2]|0;s=s+12|0;if(jp(t,n[s>>2]|0,0)|0){t=1;break}if((r&1|0)==0|(t|0)==0){t=0;break}e=Kp(t,3840,3976,0)|0;if(!e){o=9;break}t=n[s>>2]|0}if((o|0)==9){t=n[i>>2]|0;if((t|0)!=0?(A=Kp(t,3840,4008,0)|0,(A|0)!=0):0)t=Ff(A,n[s>>2]|0)|0;else t=0}return t|0}function Ff(e,t){e=e|0;t=t|0;var s=0;if((((t|0)!=0?(s=Kp(t,3840,4008,0)|0,(s|0)!=0):0)?(n[s+8>>2]&~n[e+8>>2]|0)==0:0)?jp(n[e+12>>2]|0,n[s+12>>2]|0,0)|0:0)e=jp(n[e+16>>2]|0,n[s+16>>2]|0,0)|0;else e=0;return e|0}function xf(e){e=e|0;Qp(e);qp(e);return}function Uf(e,t,s,r,A,o){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;o=o|0;var a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0;if(jp(e,n[t+8>>2]|0,o)|0)Xp(0,t,s,r,A);else{m=t+52|0;l=i[m>>0]|0;g=t+53|0;a=i[g>>0]|0;f=n[e+12>>2]|0;u=e+16+(f<<3)|0;i[m>>0]=0;i[g>>0]=0;Sf(e+16|0,t,s,r,A,o);c=i[m>>0]|0;l=c|l;h=i[g>>0]|0;a=h|a;e:do{if((f|0)>1){d=t+24|0;p=e+8|0;f=t+54|0;e=e+24|0;do{a=a&1;l=l&1;if(i[f>>0]|0)break e;if(!(c<<24>>24)){if(h<<24>>24?(n[p>>2]&1|0)==0:0)break e}else{if((n[d>>2]|0)==1)break e;if(!(n[p>>2]&2))break e}i[m>>0]=0;i[g>>0]=0;Sf(e,t,s,r,A,o);c=i[m>>0]|0;l=c|l;h=i[g>>0]|0;a=h|a;e=e+8|0}while(e>>>0<u>>>0)}}while(0);i[m>>0]=l<<24>>24!=0&1;i[g>>0]=a<<24>>24!=0&1}return}function If(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0;e:do{if(!(jp(e,n[t+8>>2]|0,A)|0)){if(!(jp(e,n[t>>2]|0,A)|0)){f=n[e+12>>2]|0;c=e+16+(f<<3)|0;Df(e+16|0,t,s,r,A);o=e+24|0;if((f|0)<=1)break;e=n[e+8>>2]|0;if((e&2|0)==0?(l=t+36|0,(n[l>>2]|0)!=1):0){if(!(e&1)){e=t+54|0;while(1){if(i[e>>0]|0)break e;if((n[l>>2]|0)==1)break e;Df(o,t,s,r,A);o=o+8|0;if(o>>>0>=c>>>0)break e}}e=t+24|0;a=t+54|0;while(1){if(i[a>>0]|0)break e;if((n[l>>2]|0)==1?(n[e>>2]|0)==1:0)break e;Df(o,t,s,r,A);o=o+8|0;if(o>>>0>=c>>>0)break e}}e=t+54|0;while(1){if(i[e>>0]|0)break e;Df(o,t,s,r,A);o=o+8|0;if(o>>>0>=c>>>0)break e}}if((n[t+16>>2]|0)!=(s|0)?(f=t+20|0,(n[f>>2]|0)!=(s|0)):0){n[t+32>>2]=r;p=t+44|0;if((n[p>>2]|0)!=4){l=e+16+(n[e+12>>2]<<3)|0;c=t+52|0;r=t+53|0;h=t+54|0;u=e+8|0;d=t+24|0;o=0;a=e+16|0;e=0;t:while(1){if(a>>>0>=l>>>0){a=18;break}i[c>>0]=0;i[r>>0]=0;Sf(a,t,s,s,1,A);if(i[h>>0]|0){a=18;break}do{if(i[r>>0]|0){if(!(i[c>>0]|0))if(!(n[u>>2]&1)){a=19;break t}else{e=1;break}if((n[d>>2]|0)==1){o=1;a=19;break t}if(!(n[u>>2]&2)){o=1;a=19;break t}else{o=1;e=1}}}while(0);a=a+8|0}if((a|0)==18)if(e)a=19;else e=4;if((a|0)==19)e=3;n[p>>2]=e;if(o&1)break}n[f>>2]=s;s=t+40|0;n[s>>2]=(n[s>>2]|0)+1;if((n[t+36>>2]|0)!=1)break;if((n[t+24>>2]|0)!=2)break;i[t+54>>0]=1;break}if((r|0)==1)n[t+32>>2]=1}else Wp(0,t,s,r)}while(0);return}function Tf(e,t,s,r){e=e|0;t=t|0;s=s|0;r=r|0;var A=0,o=0;e:do{if(!(jp(e,n[t+8>>2]|0,0)|0)){o=n[e+12>>2]|0;A=e+16+(o<<3)|0;Pf(e+16|0,t,s,r);if((o|0)>1){o=t+54|0;e=e+24|0;do{Pf(e,t,s,r);if(i[o>>0]|0)break e;e=e+8|0}while(e>>>0<A>>>0)}}else zp(0,t,s,r)}while(0);return}function Pf(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,A=0;A=n[e+4>>2]|0;if(s){r=A>>8;if(A&1)r=n[(n[s>>2]|0)+r>>2]|0}else r=0;e=n[e>>2]|0;Xm[n[(n[e>>2]|0)+28>>2]&7](e,t,s+r|0,(A&2|0)==0?2:i);return}function Sf(e,t,s,i,r,A){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;A=A|0;var o=0,a=0;a=n[e+4>>2]|0;o=a>>8;if(a&1)o=n[(n[i>>2]|0)+o>>2]|0;e=n[e>>2]|0;Zm[n[(n[e>>2]|0)+20>>2]&3](e,t,s,i+o|0,(a&2|0)==0?2:r,A);return}function Df(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var A=0,o=0;o=n[e+4>>2]|0;A=o>>8;if(o&1)A=n[(n[s>>2]|0)+A>>2]|0;e=n[e>>2]|0;Km[n[(n[e>>2]|0)+24>>2]&3](e,t,s+A|0,(o&2|0)==0?2:i,r);return}function kf(e){e=e|0;n[e>>2]=5896;return}function Qf(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;Rf(s,e);e=Of(s)|0;J=t;return e|0}function Rf(e,t){e=e|0;t=t|0;Gf(e,t);return}function Of(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;Vf(s,n[e+4>>2]|0);if(!((Lf(s)|0)<<24>>24))e=Nf(Hf(e)|0)|0;else e=0;J=t;return e|0}function Vf(e,t){e=e|0;t=t|0;n[e>>2]=t;return}function Lf(e){e=e|0;return i[n[e>>2]>>0]|0}function Hf(e){e=e|0;return e|0}function Nf(e){e=e|0;var t=0,s=0,r=0,A=0;A=J;J=J+16|0;r=A;e=n[e+8>>2]|0;t=i[e>>0]|0;do{if(t<<24>>24!=1)if(!(t&2)){i[e>>0]=2;s=1;break}else kp(20985,r);else s=0}while(0);J=A;return s|0}function Gf(e,t){e=e|0;t=t|0;n[e>>2]=t;n[e+4>>2]=t;n[e+8>>2]=t+1;n[e+12>>2]=0;return}function jf(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;Rf(s,e);zf(s);J=t;return}function zf(e){e=e|0;var t=0,s=0;t=J;J=J+16|0;s=t;Vf(s,n[e+4>>2]|0);Wf(s);Xf(Hf(e)|0);J=t;return}function Wf(e){e=e|0;i[n[e>>2]>>0]=1;return}function Xf(e){e=e|0;i[n[e+8>>2]>>0]=1;return}function Kf(){return 0}function Zf(e){e=e|0;var t=0,s=0;s=(e|0)==0?1:e;while(1){t=Kg(s)|0;if(t|0){e=6;break}e=Kf()|0;if(!e){e=5;break}Gm[e&3]()}if((e|0)==5){s=C(4)|0;kf(s);E(s|0,3880,121)}else if((e|0)==6)return t|0;return 0}function Jf(e){e=e|0;return Zf(e)|0}function Yf(e){e=e|0;qp(e);return}function $f(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=J;J=J+16|0;i=r;n[i>>2]=n[s>>2];e=Nm[n[(n[e>>2]|0)+16>>2]&7](e,t,i)|0;if(e)n[s>>2]=n[i>>2];J=r;return e&1|0}function qf(e){e=e|0;if(!e)e=0;else e=(Kp(e,3840,3976,0)|0)!=0&1;return e|0}function eg(e){e=e|0;return 0}function tg(){return(sg()|0)>0|0}function sg(){return F()|0}function ig(e){e=e|0;return}function rg(e){e=e|0;ig(e);qp(e);return}function ng(e){e=e|0;return 21039}function Ag(e){e=e|0;return}function og(e){e=e|0;var t=0,s=0;t=e+8|0;if(!((n[t>>2]|0)!=0?(s=n[t>>2]|0,n[t>>2]=s+-1,(s|0)!=0):0))jm[n[(n[e>>2]|0)+16>>2]&255](e);return}function ag(e){e=e|0;e=eg(e)|0;if(!e)return;else Wg(e,21145)}function lg(e){e=e|0;return}function cg(e,t){e=e|0;t=t|0;var s=0,i=0;i=Zd(t)|0;s=Zf(i+13|0)|0;n[s>>2]=i;n[s+4>>2]=i;n[s+8>>2]=0;s=hg(s)|0;hm(s|0,t|0,i+1|0)|0;n[e>>2]=s;return}function hg(e){e=e|0;return e+12|0}function ug(e,t){e=e|0;t=t|0;n[e>>2]=5916;cg(e+4|0,t);return}function dg(e,t){e=e|0;t=t|0;n[e>>2]=5936;cg(e+4|0,(i[t+11>>0]|0)<0?n[t>>2]|0:t);return}function pg(e,t){e=e|0;t=t|0;n[e>>2]=5936;cg(e+4|0,t);return}function fg(e){e=e|0;e=C(8)|0;ug(e,21163);n[e>>2]=5956;E(e|0,3928,123)}function gg(e){e=e|0;e=C(8)|0;ug(e,21163);n[e>>2]=5976;E(e|0,3944,123)}function mg(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0;A=J;J=J+16|0;r=A;if(s>>>0>4294967279)fg(e);if(s>>>0<11)i[e+11>>0]=s;else{a=s+16&-16;o=Zf(a)|0;n[e>>2]=o;n[e+8>>2]=a|-2147483648;n[e+4>>2]=s;e=o}_g(e,t,s)|0;i[r>>0]=0;rt(e+s|0,r);J=A;return}function _g(e,t,s){e=e|0;t=t|0;s=s|0;if(s|0)hm(e|0,t|0,s|0)|0;return e|0}function bg(e){e=e|0;if((i[e+11>>0]|0)<0)ye(n[e>>2]|0,n[e+8>>2]&2147483647);return}function yg(e,t,s,r,A,o,a,l){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;o=o|0;a=a|0;l=l|0;var c=0,h=0,u=0,d=0,p=0;p=J;J=J+16|0;d=p;if((-18-t|0)>>>0<s>>>0)fg(e);if((i[e+11>>0]|0)<0)u=n[e>>2]|0;else u=e;if(t>>>0<2147483623){c=s+t|0;h=t<<1;c=c>>>0<h>>>0?h:c;c=c>>>0<11?11:c+16&-16}else c=-17;h=Zf(c)|0;if(A|0)_g(h,u,A)|0;if(a|0)_g(h+A|0,l,a)|0;r=r-o|0;s=r-A|0;if(s|0)_g(h+A+a|0,u+A+o|0,s)|0;s=t+1|0;if((s|0)!=11)ye(u,s);n[e>>2]=h;n[e+8>>2]=c|-2147483648;a=r+a|0;n[e+4>>2]=a;i[d>>0]=0;rt(h+a|0,d);J=p;return}function Bg(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0,l=0,c=0;c=J;J=J+16|0;a=c;l=e+11|0;r=i[l>>0]|0;o=r<<24>>24<0;if(o){A=(n[e+8>>2]&2147483647)+-1|0;r=n[e+4>>2]|0}else{A=10;r=r&255}if((A-r|0)>>>0>=s>>>0){if(s|0){if(o)A=n[e>>2]|0;else A=e;_g(A+r|0,t,s)|0;r=r+s|0;if((i[l>>0]|0)<0)n[e+4>>2]=r;else i[l>>0]=r;i[a>>0]=0;rt(A+r|0,a)}}else yg(e,A,r+s-A|0,r,r,0,s,t);J=c;return e|0}function wg(e,t){e=e|0;t=t|0;return Bg(e,t,st(t)|0)|0}function vg(e,t,s){e=e|0;t=t|0;s=s|0;if(!s)e=0;else e=Bp(e,t,s)|0;return e|0}function Cg(e,t,s,r,A){e=e|0;t=t|0;s=s|0;r=r|0;A=A|0;var o=0,a=0;o=i[e+11>>0]|0;a=o<<24>>24<0;if(a)o=n[e+4>>2]|0;else o=o&255;if((A|0)==-1|o>>>0<t>>>0)gg(e);o=o-t|0;s=o>>>0<s>>>0?o:s;if(a)e=n[e>>2]|0;o=s>>>0>A>>>0;e=vg(e+t|0,r,o?A:s)|0;if(!e)return(s>>>0<A>>>0?-1:o&1)|0;else return e|0;return 0}function Mg(e){e=e|0;return}function Eg(e){e=e|0;qp(e);return}function Fg(e){e=e|0;return 21228}function xg(e,t,s){e=e|0;t=t|0;s=s|0;n[e>>2]=s;n[e+4>>2]=t;return}function Ug(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0;r=J;J=J+16|0;i=r;Wm[n[(n[e>>2]|0)+12>>2]&15](i,e,t);if((n[i+4>>2]|0)==(n[s+4>>2]|0))e=(n[i>>2]|0)==(n[s>>2]|0);else e=0;J=r;return e|0}function Ig(e,t,s){e=e|0;t=t|0;s=s|0;return((n[t>>2]|0)==(s|0)?(n[t+4>>2]|0)==(e|0):0)|0}function Tg(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)>256)mg(e,21176,st(21176)|0);else Pg(e,0,s);return}function Pg(e,t,s){e=e|0;t=t|0;s=s|0;Sg(e,s);return}function Sg(e,t){e=e|0;t=t|0;var s=0,r=0,A=0,o=0,a=0;a=J;J=J+1040|0;A=a+1024|0;s=a;o=n[(zd()|0)>>2]|0;r=Dg(Ip(t,s,1024)|0,s)|0;if(!(i[r>>0]|0)){n[A>>2]=t;wp(s,1024,21211,A)|0}else s=r;n[(zd()|0)>>2]=o;mg(e,s,st(s)|0);J=a;return}function Dg(e,t){e=e|0;t=t|0;var s=0,i=0;switch(e|0){case 0:{s=t;break}case-1:{e=n[(zd()|0)>>2]|0;i=3;break}default:i=3}if((i|0)==3)if((e|0)==28)s=22145;else j();return s|0}function kg(e){e=e|0;qp(e);return}function Qg(e){e=e|0;return 21353}function Rg(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)>256){Vg()|0;t=6180}else{Lg()|0;t=6176}n[e>>2]=s;n[e+4>>2]=t;return}function Og(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)>256)mg(e,21319,st(21319)|0);else Pg(e,0,s);return}function Vg(){if((i[21488]|0)==0?Qf(21488)|0:0)jf(21488);return 6180}function Lg(){if((i[21480]|0)==0?Qf(21480)|0:0)jf(21480);return 6176}function Hg(e){e=e|0;ff(e);return}function Ng(e){e=e|0;Hg(e);qp(e);return}function Gg(e,t){e=e|0;t=t|0;var s=0;s=n[t+4>>2]|0;Wm[n[(n[s>>2]|0)+24>>2]&15](e,s,n[t>>2]|0);return}function jg(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;o=J;J=J+16|0;A=o;if(n[t>>2]|0){r=i[s+11>>0]|0;if(r<<24>>24<0)r=n[s+4>>2]|0;else r=r&255;if(r|0)wg(s,21417)|0;Gg(A,t);t=i[A+11>>0]|0;r=t<<24>>24<0;Bg(s,r?n[A>>2]|0:A,r?n[A+4>>2]|0:t&255)|0;bg(A)}n[e>>2]=n[s>>2];n[e+4>>2]=n[s+4>>2];n[e+8>>2]=n[s+8>>2];r=0;while(1){if((r|0)==3)break;n[s+(r<<2)>>2]=0;r=r+1|0}J=o;return}function zg(e,t,s){e=e|0;t=t|0;s=s|0;var i=0,r=0,A=0;i=J;J=J+32|0;A=i+12|0;r=i;mg(r,s,st(s)|0);jg(A,t,r);dg(e,A);bg(A);bg(r);n[e>>2]=6192;r=t;t=n[r+4>>2]|0;s=e+8|0;n[s>>2]=n[r>>2];n[s+4>>2]=t;J=i;return}function Wg(e,t){e=e|0;t=t|0;var s=0,i=0,r=0;r=J;J=J+16|0;i=r+8|0;s=C(16)|0;Vg()|0;n[r>>2]=e;n[r+4>>2]=6180;n[i>>2]=n[r>>2];n[i+4>>2]=n[r+4>>2];zg(s,i,t);E(s|0,4272,136)}function Xg(e){e=e|0;e=C(8)|0;ug(e,21420);n[e>>2]=5956;E(e|0,3928,123)}function Kg(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0,g=0,m=0,_=0,b=0,y=0,B=0,w=0;w=J;J=J+16|0;d=w;do{if(e>>>0<245){c=e>>>0<11?16:e+11&-8;e=c>>>3;u=n[5412]|0;s=u>>>e;if(s&3|0){t=(s&1^1)+e|0;e=21688+(t<<1<<2)|0;s=e+8|0;i=n[s>>2]|0;r=i+8|0;A=n[r>>2]|0;if((A|0)==(e|0))n[5412]=u&~(1<<t);else{n[A+12>>2]=e;n[s>>2]=A}B=t<<3;n[i+4>>2]=B|3;B=i+B+4|0;n[B>>2]=n[B>>2]|1;B=r;J=w;return B|0}h=n[5414]|0;if(c>>>0>h>>>0){if(s|0){t=2<<e;t=s<<e&(t|0-t);t=(t&0-t)+-1|0;a=t>>>12&16;t=t>>>a;s=t>>>5&8;t=t>>>s;A=t>>>2&4;t=t>>>A;e=t>>>1&2;t=t>>>e;i=t>>>1&1;i=(s|a|A|e|i)+(t>>>i)|0;t=21688+(i<<1<<2)|0;e=t+8|0;A=n[e>>2]|0;a=A+8|0;s=n[a>>2]|0;if((s|0)==(t|0)){e=u&~(1<<i);n[5412]=e}else{n[s+12>>2]=t;n[e>>2]=s;e=u}B=i<<3;o=B-c|0;n[A+4>>2]=c|3;r=A+c|0;n[r+4>>2]=o|1;n[A+B>>2]=o;if(h|0){i=n[5417]|0;t=h>>>3;s=21688+(t<<1<<2)|0;t=1<<t;if(!(e&t)){n[5412]=e|t;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=i;n[t+12>>2]=i;n[i+8>>2]=t;n[i+12>>2]=s}n[5414]=o;n[5417]=r;B=a;J=w;return B|0}A=n[5413]|0;if(A){s=(A&0-A)+-1|0;r=s>>>12&16;s=s>>>r;i=s>>>5&8;s=s>>>i;o=s>>>2&4;s=s>>>o;a=s>>>1&2;s=s>>>a;l=s>>>1&1;l=n[21952+((i|r|o|a|l)+(s>>>l)<<2)>>2]|0;s=l;a=l;l=(n[l+4>>2]&-8)-c|0;while(1){e=n[s+16>>2]|0;if(!e){e=n[s+20>>2]|0;if(!e)break}o=(n[e+4>>2]&-8)-c|0;r=o>>>0<l>>>0;s=e;a=r?e:a;l=r?o:l}o=a+c|0;if(o>>>0>a>>>0){r=n[a+24>>2]|0;t=n[a+12>>2]|0;do{if((t|0)==(a|0)){e=a+20|0;t=n[e>>2]|0;if(!t){e=a+16|0;t=n[e>>2]|0;if(!t){s=0;break}}while(1){i=t+20|0;s=n[i>>2]|0;if(!s){i=t+16|0;s=n[i>>2]|0;if(!s)break;else{t=s;e=i}}else{t=s;e=i}}n[e>>2]=0;s=t}else{s=n[a+8>>2]|0;n[s+12>>2]=t;n[t+8>>2]=s;s=t}}while(0);do{if(r|0){t=n[a+28>>2]|0;e=21952+(t<<2)|0;if((a|0)==(n[e>>2]|0)){n[e>>2]=s;if(!s){n[5413]=A&~(1<<t);break}}else{B=r+16|0;n[((n[B>>2]|0)==(a|0)?B:r+20|0)>>2]=s;if(!s)break}n[s+24>>2]=r;t=n[a+16>>2]|0;if(t|0){n[s+16>>2]=t;n[t+24>>2]=s}t=n[a+20>>2]|0;if(t|0){n[s+20>>2]=t;n[t+24>>2]=s}}}while(0);if(l>>>0<16){B=l+c|0;n[a+4>>2]=B|3;B=a+B+4|0;n[B>>2]=n[B>>2]|1}else{n[a+4>>2]=c|3;n[o+4>>2]=l|1;n[o+l>>2]=l;if(h|0){i=n[5417]|0;t=h>>>3;s=21688+(t<<1<<2)|0;t=1<<t;if(!(t&u)){n[5412]=t|u;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=i;n[t+12>>2]=i;n[i+8>>2]=t;n[i+12>>2]=s}n[5414]=l;n[5417]=o}B=a+8|0;J=w;return B|0}else u=c}else u=c}else u=c}else if(e>>>0<=4294967231){e=e+11|0;c=e&-8;i=n[5413]|0;if(i){r=0-c|0;e=e>>>8;if(e)if(c>>>0>16777215)l=31;else{u=(e+1048320|0)>>>16&8;g=e<<u;a=(g+520192|0)>>>16&4;g=g<<a;l=(g+245760|0)>>>16&2;l=14-(a|u|l)+(g<<l>>>15)|0;l=c>>>(l+7|0)&1|l<<1}else l=0;s=n[21952+(l<<2)>>2]|0;e:do{if(!s){s=0;e=0;g=61}else{e=0;a=c<<((l|0)==31?0:25-(l>>>1)|0);A=0;while(1){o=(n[s+4>>2]&-8)-c|0;if(o>>>0<r>>>0)if(!o){e=s;r=0;g=65;break e}else{e=s;r=o}g=n[s+20>>2]|0;s=n[s+16+(a>>>31<<2)>>2]|0;A=(g|0)==0|(g|0)==(s|0)?A:g;if(!s){s=A;g=61;break}else a=a<<1}}}while(0);if((g|0)==61){if((s|0)==0&(e|0)==0){e=2<<l;e=(e|0-e)&i;if(!e){u=c;break}u=(e&0-e)+-1|0;o=u>>>12&16;u=u>>>o;A=u>>>5&8;u=u>>>A;a=u>>>2&4;u=u>>>a;l=u>>>1&2;u=u>>>l;s=u>>>1&1;e=0;s=n[21952+((A|o|a|l|s)+(u>>>s)<<2)>>2]|0}if(!s){a=e;o=r}else g=65}if((g|0)==65){A=s;while(1){u=(n[A+4>>2]&-8)-c|0;s=u>>>0<r>>>0;r=s?u:r;e=s?A:e;s=n[A+16>>2]|0;if(!s)s=n[A+20>>2]|0;if(!s){a=e;o=r;break}else A=s}}if(((a|0)!=0?o>>>0<((n[5414]|0)-c|0)>>>0:0)?(h=a+c|0,h>>>0>a>>>0):0){A=n[a+24>>2]|0;t=n[a+12>>2]|0;do{if((t|0)==(a|0)){e=a+20|0;t=n[e>>2]|0;if(!t){e=a+16|0;t=n[e>>2]|0;if(!t){t=0;break}}while(1){r=t+20|0;s=n[r>>2]|0;if(!s){r=t+16|0;s=n[r>>2]|0;if(!s)break;else{t=s;e=r}}else{t=s;e=r}}n[e>>2]=0}else{B=n[a+8>>2]|0;n[B+12>>2]=t;n[t+8>>2]=B}}while(0);do{if(A){e=n[a+28>>2]|0;s=21952+(e<<2)|0;if((a|0)==(n[s>>2]|0)){n[s>>2]=t;if(!t){i=i&~(1<<e);n[5413]=i;break}}else{B=A+16|0;n[((n[B>>2]|0)==(a|0)?B:A+20|0)>>2]=t;if(!t)break}n[t+24>>2]=A;e=n[a+16>>2]|0;if(e|0){n[t+16>>2]=e;n[e+24>>2]=t}e=n[a+20>>2]|0;if(e){n[t+20>>2]=e;n[e+24>>2]=t}}}while(0);e:do{if(o>>>0<16){B=o+c|0;n[a+4>>2]=B|3;B=a+B+4|0;n[B>>2]=n[B>>2]|1}else{n[a+4>>2]=c|3;n[h+4>>2]=o|1;n[h+o>>2]=o;t=o>>>3;if(o>>>0<256){s=21688+(t<<1<<2)|0;e=n[5412]|0;t=1<<t;if(!(e&t)){n[5412]=e|t;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=h;n[t+12>>2]=h;n[h+8>>2]=t;n[h+12>>2]=s;break}t=o>>>8;if(t)if(o>>>0>16777215)s=31;else{y=(t+1048320|0)>>>16&8;B=t<<y;b=(B+520192|0)>>>16&4;B=B<<b;s=(B+245760|0)>>>16&2;s=14-(b|y|s)+(B<<s>>>15)|0;s=o>>>(s+7|0)&1|s<<1}else s=0;t=21952+(s<<2)|0;n[h+28>>2]=s;e=h+16|0;n[e+4>>2]=0;n[e>>2]=0;e=1<<s;if(!(i&e)){n[5413]=i|e;n[t>>2]=h;n[h+24>>2]=t;n[h+12>>2]=h;n[h+8>>2]=h;break}t=n[t>>2]|0;t:do{if((n[t+4>>2]&-8|0)!=(o|0)){i=o<<((s|0)==31?0:25-(s>>>1)|0);while(1){s=t+16+(i>>>31<<2)|0;e=n[s>>2]|0;if(!e)break;if((n[e+4>>2]&-8|0)==(o|0)){t=e;break t}else{i=i<<1;t=e}}n[s>>2]=h;n[h+24>>2]=t;n[h+12>>2]=h;n[h+8>>2]=h;break e}}while(0);y=t+8|0;B=n[y>>2]|0;n[B+12>>2]=h;n[y>>2]=h;n[h+8>>2]=B;n[h+12>>2]=t;n[h+24>>2]=0}}while(0);B=a+8|0;J=w;return B|0}else u=c}else u=c}else u=-1}while(0);s=n[5414]|0;if(s>>>0>=u>>>0){t=s-u|0;e=n[5417]|0;if(t>>>0>15){B=e+u|0;n[5417]=B;n[5414]=t;n[B+4>>2]=t|1;n[e+s>>2]=t;n[e+4>>2]=u|3}else{n[5414]=0;n[5417]=0;n[e+4>>2]=s|3;B=e+s+4|0;n[B>>2]=n[B>>2]|1}B=e+8|0;J=w;return B|0}o=n[5415]|0;if(o>>>0>u>>>0){b=o-u|0;n[5415]=b;B=n[5418]|0;y=B+u|0;n[5418]=y;n[y+4>>2]=b|1;n[B+4>>2]=u|3;B=B+8|0;J=w;return B|0}if(!(n[5530]|0)){n[5532]=4096;n[5531]=4096;n[5533]=-1;n[5534]=-1;n[5535]=0;n[5523]=0;n[5530]=d&-16^1431655768;e=4096}else e=n[5532]|0;a=u+48|0;l=u+47|0;A=e+l|0;r=0-e|0;c=A&r;if(c>>>0<=u>>>0){B=0;J=w;return B|0}e=n[5522]|0;if(e|0?(h=n[5520]|0,d=h+c|0,d>>>0<=h>>>0|d>>>0>e>>>0):0){B=0;J=w;return B|0}e:do{if(!(n[5523]&4)){s=n[5418]|0;t:do{if(s){i=22096;while(1){d=n[i>>2]|0;if(d>>>0<=s>>>0?(d+(n[i+4>>2]|0)|0)>>>0>s>>>0:0)break;e=n[i+8>>2]|0;if(!e){g=128;break t}else i=e}t=A-o&r;if(t>>>0<2147483647){e=Jg(t)|0;if((e|0)==((n[i>>2]|0)+(n[i+4>>2]|0)|0)){if((e|0)!=(-1|0)){o=t;A=e;g=145;break e}}else{i=e;g=136}}else t=0}else g=128}while(0);do{if((g|0)==128){s=Jg(0)|0;if((s|0)!=(-1|0)?(t=s,p=n[5531]|0,f=p+-1|0,t=((f&t|0)==0?0:(f+t&0-p)-t|0)+c|0,p=n[5520]|0,f=t+p|0,t>>>0>u>>>0&t>>>0<2147483647):0){d=n[5522]|0;if(d|0?f>>>0<=p>>>0|f>>>0>d>>>0:0){t=0;break}e=Jg(t)|0;if((e|0)==(s|0)){o=t;A=s;g=145;break e}else{i=e;g=136}}else t=0}}while(0);do{if((g|0)==136){s=0-t|0;if(!(a>>>0>t>>>0&(t>>>0<2147483647&(i|0)!=(-1|0))))if((i|0)==(-1|0)){t=0;break}else{o=t;A=i;g=145;break e}e=n[5532]|0;e=l-t+e&0-e;if(e>>>0>=2147483647){o=t;A=i;g=145;break e}if((Jg(e)|0)==(-1|0)){Jg(s)|0;t=0;break}else{o=e+t|0;A=i;g=145;break e}}}while(0);n[5523]=n[5523]|4;g=143}else{t=0;g=143}}while(0);if(((g|0)==143?c>>>0<2147483647:0)?(b=Jg(c)|0,f=Jg(0)|0,m=f-b|0,_=m>>>0>(u+40|0)>>>0,!((b|0)==(-1|0)|_^1|b>>>0<f>>>0&((b|0)!=(-1|0)&(f|0)!=(-1|0))^1)):0){o=_?m:t;A=b;g=145}if((g|0)==145){t=(n[5520]|0)+o|0;n[5520]=t;if(t>>>0>(n[5521]|0)>>>0)n[5521]=t;l=n[5418]|0;e:do{if(l){t=22096;while(1){e=n[t>>2]|0;s=n[t+4>>2]|0;if((A|0)==(e+s|0)){g=154;break}i=n[t+8>>2]|0;if(!i)break;else t=i}if(((g|0)==154?(y=t+4|0,(n[t+12>>2]&8|0)==0):0)?A>>>0>l>>>0&e>>>0<=l>>>0:0){n[y>>2]=s+o;B=(n[5415]|0)+o|0;b=l+8|0;b=(b&7|0)==0?0:0-b&7;y=l+b|0;b=B-b|0;n[5418]=y;n[5415]=b;n[y+4>>2]=b|1;n[l+B+4>>2]=40;n[5419]=n[5534];break}if(A>>>0<(n[5416]|0)>>>0)n[5416]=A;s=A+o|0;t=22096;while(1){if((n[t>>2]|0)==(s|0)){g=162;break}e=n[t+8>>2]|0;if(!e)break;else t=e}if((g|0)==162?(n[t+12>>2]&8|0)==0:0){n[t>>2]=A;h=t+4|0;n[h>>2]=(n[h>>2]|0)+o;h=A+8|0;h=A+((h&7|0)==0?0:0-h&7)|0;t=s+8|0;t=s+((t&7|0)==0?0:0-t&7)|0;c=h+u|0;a=t-h-u|0;n[h+4>>2]=u|3;t:do{if((l|0)==(t|0)){B=(n[5415]|0)+a|0;n[5415]=B;n[5418]=c;n[c+4>>2]=B|1}else{if((n[5417]|0)==(t|0)){B=(n[5414]|0)+a|0;n[5414]=B;n[5417]=c;n[c+4>>2]=B|1;n[c+B>>2]=B;break}e=n[t+4>>2]|0;if((e&3|0)==1){o=e&-8;i=e>>>3;s:do{if(e>>>0<256){e=n[t+8>>2]|0;s=n[t+12>>2]|0;if((s|0)==(e|0)){n[5412]=n[5412]&~(1<<i);break}else{n[e+12>>2]=s;n[s+8>>2]=e;break}}else{A=n[t+24>>2]|0;e=n[t+12>>2]|0;do{if((e|0)==(t|0)){s=t+16|0;i=s+4|0;e=n[i>>2]|0;if(!e){e=n[s>>2]|0;if(!e){e=0;break}}else s=i;while(1){r=e+20|0;i=n[r>>2]|0;if(!i){r=e+16|0;i=n[r>>2]|0;if(!i)break;else{e=i;s=r}}else{e=i;s=r}}n[s>>2]=0}else{B=n[t+8>>2]|0;n[B+12>>2]=e;n[e+8>>2]=B}}while(0);if(!A)break;s=n[t+28>>2]|0;i=21952+(s<<2)|0;do{if((n[i>>2]|0)!=(t|0)){B=A+16|0;n[((n[B>>2]|0)==(t|0)?B:A+20|0)>>2]=e;if(!e)break s}else{n[i>>2]=e;if(e|0)break;n[5413]=n[5413]&~(1<<s);break s}}while(0);n[e+24>>2]=A;s=t+16|0;i=n[s>>2]|0;if(i|0){n[e+16>>2]=i;n[i+24>>2]=e}s=n[s+4>>2]|0;if(!s)break;n[e+20>>2]=s;n[s+24>>2]=e}}while(0);t=t+o|0;r=o+a|0}else r=a;t=t+4|0;n[t>>2]=n[t>>2]&-2;n[c+4>>2]=r|1;n[c+r>>2]=r;t=r>>>3;if(r>>>0<256){s=21688+(t<<1<<2)|0;e=n[5412]|0;t=1<<t;if(!(e&t)){n[5412]=e|t;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=c;n[t+12>>2]=c;n[c+8>>2]=t;n[c+12>>2]=s;break}t=r>>>8;do{if(!t)i=0;else{if(r>>>0>16777215){i=31;break}y=(t+1048320|0)>>>16&8;B=t<<y;b=(B+520192|0)>>>16&4;B=B<<b;i=(B+245760|0)>>>16&2;i=14-(b|y|i)+(B<<i>>>15)|0;i=r>>>(i+7|0)&1|i<<1}}while(0);t=21952+(i<<2)|0;n[c+28>>2]=i;e=c+16|0;n[e+4>>2]=0;n[e>>2]=0;e=n[5413]|0;s=1<<i;if(!(e&s)){n[5413]=e|s;n[t>>2]=c;n[c+24>>2]=t;n[c+12>>2]=c;n[c+8>>2]=c;break}t=n[t>>2]|0;s:do{if((n[t+4>>2]&-8|0)!=(r|0)){i=r<<((i|0)==31?0:25-(i>>>1)|0);while(1){s=t+16+(i>>>31<<2)|0;e=n[s>>2]|0;if(!e)break;if((n[e+4>>2]&-8|0)==(r|0)){t=e;break s}else{i=i<<1;t=e}}n[s>>2]=c;n[c+24>>2]=t;n[c+12>>2]=c;n[c+8>>2]=c;break t}}while(0);y=t+8|0;B=n[y>>2]|0;n[B+12>>2]=c;n[y>>2]=c;n[c+8>>2]=B;n[c+12>>2]=t;n[c+24>>2]=0}}while(0);B=h+8|0;J=w;return B|0}t=22096;while(1){e=n[t>>2]|0;if(e>>>0<=l>>>0?(B=e+(n[t+4>>2]|0)|0,B>>>0>l>>>0):0)break;t=n[t+8>>2]|0}r=B+-47|0;e=r+8|0;e=r+((e&7|0)==0?0:0-e&7)|0;r=l+16|0;e=e>>>0<r>>>0?l:e;t=e+8|0;s=o+-40|0;b=A+8|0;b=(b&7|0)==0?0:0-b&7;y=A+b|0;b=s-b|0;n[5418]=y;n[5415]=b;n[y+4>>2]=b|1;n[A+s+4>>2]=40;n[5419]=n[5534];s=e+4|0;n[s>>2]=27;n[t>>2]=n[5524];n[t+4>>2]=n[5525];n[t+8>>2]=n[5526];n[t+12>>2]=n[5527];n[5524]=A;n[5525]=o;n[5527]=0;n[5526]=t;t=e+24|0;do{y=t;t=t+4|0;n[t>>2]=7}while((y+8|0)>>>0<B>>>0);if((e|0)!=(l|0)){A=e-l|0;n[s>>2]=n[s>>2]&-2;n[l+4>>2]=A|1;n[e>>2]=A;t=A>>>3;if(A>>>0<256){s=21688+(t<<1<<2)|0;e=n[5412]|0;t=1<<t;if(!(e&t)){n[5412]=e|t;t=s;e=s+8|0}else{e=s+8|0;t=n[e>>2]|0}n[e>>2]=l;n[t+12>>2]=l;n[l+8>>2]=t;n[l+12>>2]=s;break}t=A>>>8;if(t)if(A>>>0>16777215)i=31;else{y=(t+1048320|0)>>>16&8;B=t<<y;b=(B+520192|0)>>>16&4;B=B<<b;i=(B+245760|0)>>>16&2;i=14-(b|y|i)+(B<<i>>>15)|0;i=A>>>(i+7|0)&1|i<<1}else i=0;s=21952+(i<<2)|0;n[l+28>>2]=i;n[l+20>>2]=0;n[r>>2]=0;t=n[5413]|0;e=1<<i;if(!(t&e)){n[5413]=t|e;n[s>>2]=l;n[l+24>>2]=s;n[l+12>>2]=l;n[l+8>>2]=l;break}t=n[s>>2]|0;t:do{if((n[t+4>>2]&-8|0)!=(A|0)){i=A<<((i|0)==31?0:25-(i>>>1)|0);while(1){s=t+16+(i>>>31<<2)|0;e=n[s>>2]|0;if(!e)break;if((n[e+4>>2]&-8|0)==(A|0)){t=e;break t}else{i=i<<1;t=e}}n[s>>2]=l;n[l+24>>2]=t;n[l+12>>2]=l;n[l+8>>2]=l;break e}}while(0);y=t+8|0;B=n[y>>2]|0;n[B+12>>2]=l;n[y>>2]=l;n[l+8>>2]=B;n[l+12>>2]=t;n[l+24>>2]=0}}else{B=n[5416]|0;if((B|0)==0|A>>>0<B>>>0)n[5416]=A;n[5524]=A;n[5525]=o;n[5527]=0;n[5421]=n[5530];n[5420]=-1;n[5425]=21688;n[5424]=21688;n[5427]=21696;n[5426]=21696;n[5429]=21704;n[5428]=21704;n[5431]=21712;n[5430]=21712;n[5433]=21720;n[5432]=21720;n[5435]=21728;n[5434]=21728;n[5437]=21736;n[5436]=21736;n[5439]=21744;n[5438]=21744;n[5441]=21752;n[5440]=21752;n[5443]=21760;n[5442]=21760;n[5445]=21768;n[5444]=21768;n[5447]=21776;n[5446]=21776;n[5449]=21784;n[5448]=21784;n[5451]=21792;n[5450]=21792;n[5453]=21800;n[5452]=21800;n[5455]=21808;n[5454]=21808;n[5457]=21816;n[5456]=21816;n[5459]=21824;n[5458]=21824;n[5461]=21832;n[5460]=21832;n[5463]=21840;n[5462]=21840;n[5465]=21848;n[5464]=21848;n[5467]=21856;n[5466]=21856;n[5469]=21864;n[5468]=21864;n[5471]=21872;n[5470]=21872;n[5473]=21880;n[5472]=21880;n[5475]=21888;n[5474]=21888;n[5477]=21896;n[5476]=21896;n[5479]=21904;n[5478]=21904;n[5481]=21912;n[5480]=21912;n[5483]=21920;n[5482]=21920;n[5485]=21928;n[5484]=21928;n[5487]=21936;n[5486]=21936;B=o+-40|0;b=A+8|0;b=(b&7|0)==0?0:0-b&7;y=A+b|0;b=B-b|0;n[5418]=y;n[5415]=b;n[y+4>>2]=b|1;n[A+B+4>>2]=40;n[5419]=n[5534]}}while(0);t=n[5415]|0;if(t>>>0>u>>>0){b=t-u|0;n[5415]=b;B=n[5418]|0;y=B+u|0;n[5418]=y;n[y+4>>2]=b|1;n[B+4>>2]=u|3;B=B+8|0;J=w;return B|0}}n[(zd()|0)>>2]=48;B=0;J=w;return B|0}function Zg(e){e=e|0;var t=0,s=0,i=0,r=0,A=0,o=0,a=0,l=0;if(!e)return;s=e+-8|0;r=n[5416]|0;e=n[e+-4>>2]|0;t=e&-8;l=s+t|0;do{if(!(e&1)){i=n[s>>2]|0;if(!(e&3))return;o=s+(0-i)|0;A=i+t|0;if(o>>>0<r>>>0)return;if((n[5417]|0)==(o|0)){e=l+4|0;t=n[e>>2]|0;if((t&3|0)!=3){a=o;t=A;break}n[5414]=A;n[e>>2]=t&-2;n[o+4>>2]=A|1;n[o+A>>2]=A;return}s=i>>>3;if(i>>>0<256){e=n[o+8>>2]|0;t=n[o+12>>2]|0;if((t|0)==(e|0)){n[5412]=n[5412]&~(1<<s);a=o;t=A;break}else{n[e+12>>2]=t;n[t+8>>2]=e;a=o;t=A;break}}r=n[o+24>>2]|0;e=n[o+12>>2]|0;do{if((e|0)==(o|0)){t=o+16|0;s=t+4|0;e=n[s>>2]|0;if(!e){e=n[t>>2]|0;if(!e){e=0;break}}else t=s;while(1){i=e+20|0;s=n[i>>2]|0;if(!s){i=e+16|0;s=n[i>>2]|0;if(!s)break;else{e=s;t=i}}else{e=s;t=i}}n[t>>2]=0}else{a=n[o+8>>2]|0;n[a+12>>2]=e;n[e+8>>2]=a}}while(0);if(r){t=n[o+28>>2]|0;s=21952+(t<<2)|0;if((n[s>>2]|0)==(o|0)){n[s>>2]=e;if(!e){n[5413]=n[5413]&~(1<<t);a=o;t=A;break}}else{a=r+16|0;n[((n[a>>2]|0)==(o|0)?a:r+20|0)>>2]=e;if(!e){a=o;t=A;break}}n[e+24>>2]=r;t=o+16|0;s=n[t>>2]|0;if(s|0){n[e+16>>2]=s;n[s+24>>2]=e}t=n[t+4>>2]|0;if(t){n[e+20>>2]=t;n[t+24>>2]=e;a=o;t=A}else{a=o;t=A}}else{a=o;t=A}}else{a=s;o=s}}while(0);if(o>>>0>=l>>>0)return;e=l+4|0;i=n[e>>2]|0;if(!(i&1))return;if(!(i&2)){if((n[5418]|0)==(l|0)){l=(n[5415]|0)+t|0;n[5415]=l;n[5418]=a;n[a+4>>2]=l|1;if((a|0)!=(n[5417]|0))return;n[5417]=0;n[5414]=0;return}if((n[5417]|0)==(l|0)){l=(n[5414]|0)+t|0;n[5414]=l;n[5417]=o;n[a+4>>2]=l|1;n[o+l>>2]=l;return}r=(i&-8)+t|0;s=i>>>3;do{if(i>>>0<256){t=n[l+8>>2]|0;e=n[l+12>>2]|0;if((e|0)==(t|0)){n[5412]=n[5412]&~(1<<s);break}else{n[t+12>>2]=e;n[e+8>>2]=t;break}}else{A=n[l+24>>2]|0;e=n[l+12>>2]|0;do{if((e|0)==(l|0)){t=l+16|0;s=t+4|0;e=n[s>>2]|0;if(!e){e=n[t>>2]|0;if(!e){s=0;break}}else t=s;while(1){i=e+20|0;s=n[i>>2]|0;if(!s){i=e+16|0;s=n[i>>2]|0;if(!s)break;else{e=s;t=i}}else{e=s;t=i}}n[t>>2]=0;s=e}else{s=n[l+8>>2]|0;n[s+12>>2]=e;n[e+8>>2]=s;s=e}}while(0);if(A|0){e=n[l+28>>2]|0;t=21952+(e<<2)|0;if((n[t>>2]|0)==(l|0)){n[t>>2]=s;if(!s){n[5413]=n[5413]&~(1<<e);break}}else{i=A+16|0;n[((n[i>>2]|0)==(l|0)?i:A+20|0)>>2]=s;if(!s)break}n[s+24>>2]=A;e=l+16|0;t=n[e>>2]|0;if(t|0){n[s+16>>2]=t;n[t+24>>2]=s}e=n[e+4>>2]|0;if(e|0){n[s+20>>2]=e;n[e+24>>2]=s}}}}while(0);n[a+4>>2]=r|1;n[o+r>>2]=r;if((a|0)==(n[5417]|0)){n[5414]=r;return}}else{n[e>>2]=i&-2;n[a+4>>2]=t|1;n[o+t>>2]=t;r=t}e=r>>>3;if(r>>>0<256){s=21688+(e<<1<<2)|0;t=n[5412]|0;e=1<<e;if(!(t&e)){n[5412]=t|e;e=s;t=s+8|0}else{t=s+8|0;e=n[t>>2]|0}n[t>>2]=a;n[e+12>>2]=a;n[a+8>>2]=e;n[a+12>>2]=s;return}e=r>>>8;if(e)if(r>>>0>16777215)i=31;else{o=(e+1048320|0)>>>16&8;l=e<<o;A=(l+520192|0)>>>16&4;l=l<<A;i=(l+245760|0)>>>16&2;i=14-(A|o|i)+(l<<i>>>15)|0;i=r>>>(i+7|0)&1|i<<1}else i=0;e=21952+(i<<2)|0;n[a+28>>2]=i;n[a+20>>2]=0;n[a+16>>2]=0;t=n[5413]|0;s=1<<i;e:do{if(!(t&s)){n[5413]=t|s;n[e>>2]=a;n[a+24>>2]=e;n[a+12>>2]=a;n[a+8>>2]=a}else{e=n[e>>2]|0;t:do{if((n[e+4>>2]&-8|0)!=(r|0)){i=r<<((i|0)==31?0:25-(i>>>1)|0);while(1){s=e+16+(i>>>31<<2)|0;t=n[s>>2]|0;if(!t)break;if((n[t+4>>2]&-8|0)==(r|0)){e=t;break t}else{i=i<<1;e=t}}n[s>>2]=a;n[a+24>>2]=e;n[a+12>>2]=a;n[a+8>>2]=a;break e}}while(0);o=e+8|0;l=n[o>>2]|0;n[l+12>>2]=a;n[o>>2]=a;n[a+8>>2]=l;n[a+12>>2]=e;n[a+24>>2]=0}}while(0);l=(n[5420]|0)+-1|0;n[5420]=l;if(l|0)return;e=22104;while(1){e=n[e>>2]|0;if(!e)break;else e=e+8|0}n[5420]=-1;return}function Jg(e){e=e|0;var t=0,s=0,i=0;i=e+3&-4;e=lm()|0;t=n[e>>2]|0;s=t+i|0;do{if((i|0)<1|s>>>0>t>>>0){if(s>>>0>(W()|0)>>>0?(K(s|0)|0)==0:0)break;n[e>>2]=s;i=t;return i|0}}while(0);n[(zd()|0)>>2]=48;i=-1;return i|0}function Yg(e){e=e|0;var t=0;t=J;J=J+e|0;J=J+15&-16;return t|0}function $g(e){e=e|0;J=e}function qg(){return J|0}function em(e,t){e=e|0;t=t|0;var s=0,i=0,r=0,n=0;n=e&65535;r=t&65535;s=b(r,n)|0;i=e>>>16;e=(s>>>16)+(b(r,i)|0)|0;r=t>>>16;t=b(r,n)|0;return(w((e>>>16)+(b(r,i)|0)+(((e&65535)+t|0)>>>16)|0),e+t<<16|s&65535|0)|0}function tm(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;var r=0,n=0;r=e;n=s;s=em(r,n)|0;e=v()|0;return(w((b(t,n)|0)+(b(i,r)|0)+e|e&0|0),s|0|0)|0}function sm(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;s=e+s>>>0;return(w(t+i+(s>>>0<e>>>0|0)>>>0|0),s|0)|0}function im(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;i=t-i-(s>>>0>e>>>0|0)>>>0;return(w(i|0),e-s>>>0|0)|0}function rm(e){e=e|0;return(e?31-(y(e^e-1)|0)|0:32)|0}function nm(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;var A=0,o=0,a=0,l=0,c=0,h=0,u=0,d=0,p=0,f=0;h=e;l=t;c=l;o=s;d=i;a=d;if(!c){A=(r|0)!=0;if(!a){if(A){n[r>>2]=(h>>>0)%(o>>>0);n[r+4>>2]=0}d=0;r=(h>>>0)/(o>>>0)>>>0;return(w(d|0),r)|0}else{if(!A){d=0;r=0;return(w(d|0),r)|0}n[r>>2]=e|0;n[r+4>>2]=t&0;d=0;r=0;return(w(d|0),r)|0}}A=(a|0)==0;do{if(o){if(!A){A=(y(a|0)|0)-(y(c|0)|0)|0;if(A>>>0<=31){u=A+1|0;a=31-A|0;t=A-31>>31;o=u;e=h>>>(u>>>0)&t|c<<a;t=c>>>(u>>>0)&t;A=0;a=h<<a;break}if(!r){d=0;r=0;return(w(d|0),r)|0}n[r>>2]=e|0;n[r+4>>2]=l|t&0;d=0;r=0;return(w(d|0),r)|0}A=o-1|0;if(A&o|0){a=(y(o|0)|0)+33-(y(c|0)|0)|0;f=64-a|0;u=32-a|0;l=u>>31;p=a-32|0;t=p>>31;o=a;e=u-1>>31&c>>>(p>>>0)|(c<<u|h>>>(a>>>0))&t;t=t&c>>>(a>>>0);A=h<<f&l;a=(c<<f|h>>>(p>>>0))&l|h<<u&a-33>>31;break}if(r|0){n[r>>2]=A&h;n[r+4>>2]=0}if((o|0)==1){p=l|t&0;f=e|0|0;return(w(p|0),f)|0}else{f=rm(o|0)|0;p=c>>>(f>>>0)|0;f=c<<32-f|h>>>(f>>>0)|0;return(w(p|0),f)|0}}else{if(A){if(r|0){n[r>>2]=(c>>>0)%(o>>>0);n[r+4>>2]=0}p=0;f=(c>>>0)/(o>>>0)>>>0;return(w(p|0),f)|0}if(!h){if(r|0){n[r>>2]=0;n[r+4>>2]=(c>>>0)%(a>>>0)}p=0;f=(c>>>0)/(a>>>0)>>>0;return(w(p|0),f)|0}A=a-1|0;if(!(A&a)){if(r|0){n[r>>2]=e|0;n[r+4>>2]=A&c|t&0}p=0;f=c>>>((rm(a|0)|0)>>>0);return(w(p|0),f)|0}A=(y(a|0)|0)-(y(c|0)|0)|0;if(A>>>0<=30){t=A+1|0;a=31-A|0;o=t;e=c<<a|h>>>(t>>>0);t=c>>>(t>>>0);A=0;a=h<<a;break}if(!r){p=0;f=0;return(w(p|0),f)|0}n[r>>2]=e|0;n[r+4>>2]=l|t&0;p=0;f=0;return(w(p|0),f)|0}}while(0);if(!o){c=a;l=0;a=0}else{u=s|0|0;h=d|i&0;c=sm(u|0,h|0,-1,-1)|0;s=v()|0;l=a;a=0;do{i=l;l=A>>>31|l<<1;A=a|A<<1;i=e<<1|i>>>31|0;d=e>>>31|t<<1|0;im(c|0,s|0,i|0,d|0)|0;f=v()|0;p=f>>31|((f|0)<0?-1:0)<<1;a=p&1;e=im(i|0,d|0,p&u|0,(((f|0)<0?-1:0)>>31|((f|0)<0?-1:0)<<1)&h|0)|0;t=v()|0;o=o-1|0}while((o|0)!=0);c=l;l=0}o=0;if(r|0){n[r>>2]=e;n[r+4>>2]=t}p=(A|0)>>>31|(c|o)<<1|(o<<1|A>>>31)&0|l;f=(A<<1|0>>>31)&-2|a;return(w(p|0),f)|0}function Am(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;return nm(e,t,s,i,0)|0}function om(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)<32){w(t>>>s|0);return e>>>s|(t&(1<<s)-1)<<32-s}w(0);return t>>>s-32|0}function am(e,t,s){e=e|0;t=t|0;s=s|0;if((s|0)<32){w(t<<s|(e&(1<<s)-1<<32-s)>>>32-s|0);return e<<s}w(e<<s-32|0);return 0}function lm(){return 22176}function cm(e){e=e|0;return(e&255)<<24|(e>>8&255)<<16|(e>>16&255)<<8|e>>>24|0}function hm(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0;if((s|0)>=512){X(e|0,t|0,s|0)|0;return e|0}o=e|0;A=e+s|0;if((e&3)==(t&3)){while(e&3){if(!s)return o|0;i[e>>0]=i[t>>0]|0;e=e+1|0;t=t+1|0;s=s-1|0}s=A&-4|0;r=s-64|0;while((e|0)<=(r|0)){n[e>>2]=n[t>>2];n[e+4>>2]=n[t+4>>2];n[e+8>>2]=n[t+8>>2];n[e+12>>2]=n[t+12>>2];n[e+16>>2]=n[t+16>>2];n[e+20>>2]=n[t+20>>2];n[e+24>>2]=n[t+24>>2];n[e+28>>2]=n[t+28>>2];n[e+32>>2]=n[t+32>>2];n[e+36>>2]=n[t+36>>2];n[e+40>>2]=n[t+40>>2];n[e+44>>2]=n[t+44>>2];n[e+48>>2]=n[t+48>>2];n[e+52>>2]=n[t+52>>2];n[e+56>>2]=n[t+56>>2];n[e+60>>2]=n[t+60>>2];e=e+64|0;t=t+64|0}while((e|0)<(s|0)){n[e>>2]=n[t>>2];e=e+4|0;t=t+4|0}}else{s=A-4|0;while((e|0)<(s|0)){i[e>>0]=i[t>>0]|0;i[e+1>>0]=i[t+1>>0]|0;i[e+2>>0]=i[t+2>>0]|0;i[e+3>>0]=i[t+3>>0]|0;e=e+4|0;t=t+4|0}}while((e|0)<(A|0)){i[e>>0]=i[t>>0]|0;e=e+1|0;t=t+1|0}return o|0}function um(e,t,s){e=e|0;t=t|0;s=s|0;var r=0;if((t|0)<(e|0)&(e|0)<(t+s|0)){r=e;t=t+s|0;e=e+s|0;while((s|0)>0){e=e-1|0;t=t-1|0;s=s-1|0;i[e>>0]=i[t>>0]|0}e=r}else hm(e,t,s)|0;return e|0}function dm(e,t,s){e=e|0;t=t|0;s=s|0;var r=0,A=0,o=0,a=0;o=e+s|0;t=t&255;if((s|0)>=67){while(e&3){i[e>>0]=t;e=e+1|0}r=o&-4|0;a=t|t<<8|t<<16|t<<24;A=r-64|0;while((e|0)<=(A|0)){n[e>>2]=a;n[e+4>>2]=a;n[e+8>>2]=a;n[e+12>>2]=a;n[e+16>>2]=a;n[e+20>>2]=a;n[e+24>>2]=a;n[e+28>>2]=a;n[e+32>>2]=a;n[e+36>>2]=a;n[e+40>>2]=a;n[e+44>>2]=a;n[e+48>>2]=a;n[e+52>>2]=a;n[e+56>>2]=a;n[e+60>>2]=a;e=e+64|0}while((e|0)<(r|0)){n[e>>2]=a;e=e+4|0}}while((e|0)<(o|0)){i[e>>0]=t;e=e+1|0}return o-s|0}function pm(e){e=e|0;return Om[e&3]()|0}function fm(e,t){e=e|0;t=t|0;return Vm[e&15](t|0)|0}function gm(e,t,s,i,r,n,A){e=e|0;t=t|0;s=+s;i=i|0;r=r|0;n=n|0;A=A|0;return Lm[e&1](t|0,+s,i|0,r|0,n|0,A|0)|0}function mm(e,t,s){e=e|0;t=t|0;s=s|0;return Hm[e&63](t|0,s|0)|0}function _m(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;return Nm[e&7](t|0,s|0,i|0)|0}function bm(e){e=e|0;Gm[e&3]()}function ym(e,t){e=e|0;t=t|0;jm[e&255](t|0)}function Bm(e,t,s){e=e|0;t=t|0;s=s|0;zm[e&15](t|0,s|0)}function wm(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;Wm[e&15](t|0,s|0,i|0)}function vm(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;Xm[e&7](t|0,s|0,i|0,r|0)}function Cm(e,t,s,i,r,n){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;n=n|0;Km[e&3](t|0,s|0,i|0,r|0,n|0)}function Mm(e,t,s,i,r,n,A){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;n=n|0;A=A|0;Zm[e&3](t|0,s|0,i|0,r|0,n|0,A|0)}function Em(){B(0);return 0}function Fm(e){e=e|0;B(1);return 0}function xm(e,t,s,i,r,n){e=e|0;t=+t;s=s|0;i=i|0;r=r|0;n=n|0;B(2);return 0}function Um(e,t){e=e|0;t=t|0;B(3);return 0}function Im(e,t,s){e=e|0;t=t|0;s=s|0;B(4);return 0}function Tm(){B(5)}function Pm(e){e=e|0;B(6)}function Sm(e,t){e=e|0;t=t|0;B(7)}function Dm(e,t,s){e=e|0;t=t|0;s=s|0;B(8)}function km(e,t,s,i){e=e|0;t=t|0;s=s|0;i=i|0;B(9)}function Qm(e,t,s,i,r){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;B(10)}function Rm(e,t,s,i,r,n){e=e|0;t=t|0;s=s|0;i=i|0;r=r|0;n=n|0;B(11)}var Om=[Em,Ic,vh,Em];var Vm=[Fm,mf,gt,wt,of,cf,ng,Fg,Qg,pc,re,hh,Pc,Mh,Fm,Fm];var Lm=[xm,np];var Hm=[Um,_e,Fe,Bt,ei,Ii,Li,er,tr,rr,Gr,Jr,fn,wn,Tn,On,CA,SA,NA,XA,so,oo,mo,wo,To,jo,Yo,sa,ca,ba,Qa,Ga,Ya,Al,gl,vl,Sl,Nl,Jl,ic,hc,ih,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um,Um];var Nm=[Im,Cp,Lp,wf,Cf,Ug,Ig,Im];var Gm=[Tm,yf,Tp,Tm];var jm=[Pm,Ag,ge,me,be,Me,Ee,xe,ff,nt,vt,ft,_t,bt,xt,Ut,Lt,Ht,ls,cs,hs,Is,$s,qs,ti,Ei,Ti,Pi,Si,Di,Oi,Vi,Hi,$i,qi,sr,ir,Hr,Nr,jr,Kr,Zr,dn,pn,gn,yn,Bn,Un,In,Pn,Qn,Rn,wA,vA,MA,DA,kA,LA,HA,GA,KA,ZA,eo,to,io,ao,lo,fo,go,_o,vo,Co,Uo,Io,Po,No,Go,zo,Zo,Jo,$o,ia,ra,aa,la,ha,ma,_a,Da,ka,Ra,Ha,Na,Za,Ja,$a,rl,nl,pl,fl,ml,Bl,wl,Tl,Pl,Dl,Ll,Hl,Kl,Zl,Yl,tc,sc,lc,cc,uc,Qp,Rp,Op,Vp,Zp,nf,Af,af,lf,gf,_f,bf,Bf,vf,xf,ig,rg,Mg,Eg,kg,Hg,Ng,mc,ph,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm,Pm];var zm=[Sm,mt,yt,ie,Ae,oe,ae,le,Ap,Sm,Sm,Sm,Sm,Sm,Sm,Sm];var Wm=[Dm,xg,Tg,Rg,Og,se,ne,Zc,Vh,zh,Dm,Dm,Dm,Dm,Dm,Dm];var Xm=[km,Gp,$p,Tf,Vc,Ph,km,km];var Km=[Qm,Np,Yp,If];var Zm=[Rm,Hp,Jp,Uf];return{__ZSt18uncaught_exceptionv:tg,___cxa_can_catch:$f,___cxa_is_pointer_type:qf,___embind_register_native_and_builtin_types:eu,___errno_location:zd,___getTypeName:jd,___muldi3:tm,___udivdi3:Am,_bitshift64Lshr:om,_bitshift64Shl:am,_emscripten_get_sbrk_ptr:lm,_free:Zg,_i64Add:sm,_i64Subtract:im,_llvm_bswap_i32:cm,_malloc:Kg,_memcpy:hm,_memmove:um,_memset:dm,dynCall_i:pm,dynCall_ii:fm,dynCall_iidiiii:gm,dynCall_iii:mm,dynCall_iiii:_m,dynCall_v:bm,dynCall_vi:ym,dynCall_vii:Bm,dynCall_viii:wm,dynCall_viiii:vm,dynCall_viiiii:Cm,dynCall_viiiiii:Mm,globalCtors:q,stackAlloc:Yg,stackRestore:$g,stackSave:qg}}({Math:Math,Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array,Float32Array:Float32Array,Float64Array:Float64Array},ut,y),pt=t.__ZSt18uncaught_exceptionv=dt.__ZSt18uncaught_exceptionv;t.___cxa_can_catch=dt.___cxa_can_catch,t.___cxa_is_pointer_type=dt.___cxa_is_pointer_type,t.___embind_register_native_and_builtin_types=dt.___embind_register_native_and_builtin_types,t.___errno_location=dt.___errno_location;var ft=t.___getTypeName=dt.___getTypeName;t.___muldi3=dt.___muldi3,t.___udivdi3=dt.___udivdi3,t._bitshift64Lshr=dt._bitshift64Lshr,t._bitshift64Shl=dt._bitshift64Shl,t._emscripten_get_sbrk_ptr=dt._emscripten_get_sbrk_ptr;var gt=t._free=dt._free;t._i64Add=dt._i64Add,t._i64Subtract=dt._i64Subtract,t._llvm_bswap_i32=dt._llvm_bswap_i32;var mt=t._malloc=dt._malloc;t._memcpy=dt._memcpy,t._memmove=dt._memmove,t._memset=dt._memset;var _t,bt,yt=t.globalCtors=dt.globalCtors;if(t.stackAlloc=dt.stackAlloc,t.stackRestore=dt.stackRestore,t.stackSave=dt.stackSave,t.dynCall_i=dt.dynCall_i,t.dynCall_ii=dt.dynCall_ii,t.dynCall_iidiiii=dt.dynCall_iidiiii,t.dynCall_iii=dt.dynCall_iii,t.dynCall_iiii=dt.dynCall_iiii,t.dynCall_v=dt.dynCall_v,t.dynCall_vi=dt.dynCall_vi,t.dynCall_vii=dt.dynCall_vii,t.dynCall_viii=dt.dynCall_viii,t.dynCall_viiii=dt.dynCall_viiii,t.dynCall_viiiii=dt.dynCall_viiiii,t.dynCall_viiiiii=dt.dynCall_viiiiii,t.asm=dt,W)if(K(W)||(_t=W,W=t.locateFile?t.locateFile(_t,u):u+_t),n||A){var Bt=l(W);w.set(Bt,8)}else{G++,t.monitorRunDependencies&&t.monitorRunDependencies(G);var wt=function(e){e.byteLength&&(e=new Uint8Array(e)),w.set(e,8),t.memoryInitializerRequest&&delete t.memoryInitializerRequest.response,function(e){if(G--,t.monitorRunDependencies&&t.monitorRunDependencies(G),0==G&&j){var s=j;j=null,s()}}()},vt=function(){a(W,wt,(function(){throw new Error("could not load memory initializer "+W)}))},Ct=ht(W);if(Ct)wt(Ct.buffer);else if(t.memoryInitializerRequest){var Mt=function(){var e=t.memoryInitializerRequest,s=e.response;if(200!==e.status&&0!==e.status){var i=ht(t.memoryInitializerRequestURL);if(!i)return console.warn("a problem seems to have happened with Module.memoryInitializerRequest, status: "+e.status+", retrying "+W),void vt();s=i.buffer}wt(s)};t.memoryInitializerRequest.response?setTimeout(Mt,0):t.memoryInitializerRequest.addEventListener("load",Mt)}else vt()}function Et(e){this.name="ExitStatus",this.message="Program terminated with exit("+e+")",this.status=e}function Ft(e){function s(){bt||(bt=!0,t.calledRun=!0,g||(O(L),O(H),t.onRuntimeInitialized&&t.onRuntimeInitialized(),function(){if(t.postRun)for("function"==typeof t.postRun&&(t.postRun=[t.postRun]);t.postRun.length;)e=t.postRun.shift(),N.unshift(e);var e;O(N)}()))}G>0||(!function(){if(t.preRun)for("function"==typeof t.preRun&&(t.preRun=[t.preRun]);t.preRun.length;)e=t.preRun.shift(),V.unshift(e);var e;O(V)}(),G>0||(t.setStatus?(t.setStatus("Running..."),setTimeout((function(){setTimeout((function(){t.setStatus("")}),1),s()}),1)):s()))}if(j=function e(){bt||Ft(),bt||(j=e)},t.run=Ft,t.preInit)for("function"==typeof t.preInit&&(t.preInit=[t.preInit]);t.preInit.length>0;)t.preInit.pop()();return Ft(),t}let Mu=null;const Eu={0:e=>({position:[e.getInt32(0,!0),e.getInt32(4,!0),e.getInt32(8,!0)],intensity:e.getUint16(12,!0),classification:e.getUint8(15)}),1:e=>({position:[e.getInt32(0,!0),e.getInt32(4,!0),e.getInt32(8,!0)],intensity:e.getUint16(12,!0),classification:e.getUint8(15)}),2:e=>({position:[e.getInt32(0,!0),e.getInt32(4,!0),e.getInt32(8,!0)],intensity:e.getUint16(12,!0),classification:e.getUint8(15),color:[e.getUint16(20,!0),e.getUint16(22,!0),e.getUint16(24,!0)]}),3:e=>({position:[e.getInt32(0,!0),e.getInt32(4,!0),e.getInt32(8,!0)],intensity:e.getUint16(12,!0),classification:e.getUint8(15),color:[e.getUint16(28,!0),e.getUint16(30,!0),e.getUint16(32,!0)]})};function Fu(e,t={},s,i){i=void 0===i||0===i?1:i;const r=new t(e.slice(s,s+t.BYTES_PER_ELEMENT*i));if(1===i)return r[0];const n=[];for(let e=0;e<i;e++)n.push(r[e]);return n}function xu(e){let t=131;const s={pointsOffset:Fu(e,Uint32Array,96),pointsFormatId:Fu(e,Uint8Array,104),pointsStructSize:Fu(e,Uint16Array,105),pointsCount:Fu(e,Uint32Array,107),scale:Fu(e,Float64Array,t,3)};t+=24,s.offset=Fu(e,Float64Array,t,3),t+=24;const i=Fu(e,Float64Array,t,6);return t+=48,s.maxs=[i[0],i[2],i[4]],s.mins=[i[1],i[3],i[5]],s}class Uu{arraybuffer;readOffset=0;header={pointsOffset:0,pointsFormatId:0,pointsStructSize:0,pointsCount:0,scale:[0,0,0],offset:[0,0,0],maxs:[0],mins:[0],totalToRead:0,totalRead:0,versionAsString:"",isCompressed:!0};constructor(e){this.arraybuffer=e}open(){return!0}getHeader(){return this.header=xu(this.arraybuffer),this.header}readData(e,t){const{header:s,arraybuffer:i}=this;if(!s)throw new Error("Cannot start reading data till a header request is issued");let r,{readOffset:n}=this;if(t<=1){e=Math.min(e,s.pointsCount-n),r=s.pointsOffset+n*s.pointsStructSize;const t=r+e*s.pointsStructSize;return n+=e,this.readOffset=n,{buffer:i.slice(r,t),count:e,hasMoreData:n<s.pointsCount}}const A=Math.min(e*t,s.pointsCount-n),o=Math.ceil(A/t);let a=0;const l=new Uint8Array(o*s.pointsStructSize);for(let e=0;e<A;e++){if(e%t==0){r=s.pointsOffset+n*s.pointsStructSize;const e=new Uint8Array(i,r,s.pointsStructSize);l.set(e,a*s.pointsStructSize),a++}n++}return this.readOffset=n,{buffer:l.buffer,count:a,hasMoreData:n<s.pointsCount}}close(){return this.arraybuffer=null,!0}}class Iu{arraybuffer;instance=null;header=null;constructor(e){this.arraybuffer=e,Mu||(Mu=Cu())}open(){try{const{arraybuffer:e}=this;this.instance=new Mu.LASZip;const t=new Uint8Array(e),s=Mu._malloc(e.byteLength);return this.instance.arraybuffer=e,this.instance.buf=s,Mu.HEAPU8.set(t,s),this.instance.open(s,e.byteLength),this.instance.readOffset=0,!0}catch(e){throw new Error(`Failed to open file: ${e.message}`)}}getHeader(){if(!this.instance)throw new Error("You need to open the file before trying to read header");try{const e=xu(this.instance.arraybuffer);return e.pointsFormatId&=63,this.header=e,e}catch(e){throw new Error(`Failed to get header: ${e.message}`)}}readData(e,t,s){if(!this.instance)throw new Error("You need to open the file before trying to read stuff");const{header:i,instance:r}=this;if(!i)throw new Error("You need to query header before reading, I maintain state that way, sorry :(");try{const t=Math.min(e*s,i.pointsCount-r.readOffset),n=Math.ceil(t/s);let A=0;const o=new Uint8Array(n*i.pointsStructSize),a=Mu._malloc(i.pointsStructSize);for(let e=0;e<t;e++){if(r.getPoint(a),e%s==0){const e=new Uint8Array(Mu.HEAPU8.buffer,a,i.pointsStructSize);o.set(e,A*i.pointsStructSize),A++}r.readOffset++}return Mu._free(a),{buffer:o.buffer,count:A,hasMoreData:r.readOffset<i.pointsCount}}catch(e){throw new Error(`Failed to read data: ${e.message}`)}}close(){try{return null!==this.instance&&(Mu._free(this.instance.buf),this.instance.delete(),this.instance=null),!0}catch(e){throw new Error(`Failed to close file: ${e.message}`)}}}class Tu{arrayb;decoder;pointsCount;pointSize;scale;offset;mins;maxs;constructor(e,t,s){this.arrayb=e,this.decoder=Eu[s.pointsFormatId],this.pointsCount=t,this.pointSize=s.pointsStructSize,this.scale=s.scale,this.offset=s.offset,this.mins=s.mins,this.maxs=s.maxs}getPoint(e){if(e<0||e>=this.pointsCount)throw new Error("Point index out of range");const t=new DataView(this.arrayb,e*this.pointSize,this.pointSize);return this.decoder(t)}}class Pu{arraybuffer;formatId=0;loader;isCompressed=!0;isOpen=!1;version=0;versionAsString="";constructor(e){if(this.arraybuffer=e,this.determineVersion()>13)throw new Error("Only file versions <= 1.3 are supported at this time");if(this.determineFormat(),void 0===Eu[this.formatId])throw new Error("The point format ID is not supported");this.loader=this.isCompressed?new Iu(this.arraybuffer):new Uu(this.arraybuffer)}determineFormat(){const e=Fu(this.arraybuffer,Uint8Array,104),t=(128&e)>>7,s=(64&e)>>6;if(1===t&&1===s)throw new Error("Old style compression not supported");this.formatId=63&e,this.isCompressed=1===t||1===s}determineVersion(){const e=new Int8Array(this.arraybuffer,24,2);return this.version=10*e[0]+e[1],this.versionAsString=`${e[0]}.${e[1]}`,this.version}open(){this.loader.open()&&(this.isOpen=!0)}getHeader(){return this.loader.getHeader()}readData(e,t,s){return this.loader.readData(e,t,s)}close(){this.loader.close()&&(this.isOpen=!1)}getUnpacker(){return Tu}}function Su(e,t){const s=function(e){const t={};t.las_pointsOffset=e.pointsOffset.toString(10),t.las_pointsFormatId=e.pointsFormatId.toString(10),t.las_pointsStructSize=e.pointsStructSize.toString(10),t.las_pointsCount=e.pointsCount.toString(10),t.las_scale=JSON.stringify(e.scale),t.las_offset=JSON.stringify(e.offset),void 0!==e.maxs&&(t.las_maxs=JSON.stringify(e.maxs));void 0!==e.mins&&(t.las_mins=JSON.stringify(e.mins));t.las_totalToRead=e.totalToRead.toString(10),t.las_pointsFortotalReadmatId=e.totalRead.toString(10),void 0!==e.versionAsString&&(t.las_versionAsString=e.versionAsString);void 0!==e.isCompressed&&(t.las_isCompressed=e.isCompressed.toString());return t}(e);return Al(t,s)}function Du(e,t){return function(e,t={}){let s,i,r,n,A,o=0;const a={loader:"las",loaderData:{},schema:{fields:[],metadata:{}},header:{vertexCount:0,boundingBox:[[0,0,0],[0,0,0]]},attributes:{},topology:"point-list",mode:0};(function(e,t,s={}){const i=new Pu(e);try{i.open();const e=i.getHeader(),r=i.getUnpacker(),n=Math.ceil(e.pointsCount/Math.max(1,t));e.totalToRead=n;let A=0;for(;;){const o=i.readData(1e5,0,t);A+=o.count,e.totalRead=A,e.versionAsString=o.versionAsString,e.isCompressed=o.isCompressed;if(s(new r(o.buffer,o.count,e),e),!o.hasMoreData||A>=n)break}}catch(e){throw e}finally{i.close()}})(e,t.las?.skip,((e={},l)=>{if(!A){A=l;const e=l.totalToRead,o=t.las?.fp64?Float64Array:Float32Array;s=new o(3*e),i=l.pointsFormatId>=2?new Uint8Array(4*e):null,r=new Uint16Array(e),n=new Uint8Array(e),a.loaderData=l,a.attributes={POSITION:{value:s,size:3},intensity:{value:r,size:1},classification:{value:n,size:1}},i&&(a.attributes.COLOR_0={value:i,size:4})}const c=e.pointsCount,{scale:[h,u,d],offset:[p,f,g]}=l,m=function(e={},t,s){let i=!1;switch(s){case 8:i=!1;break;case 16:i=!0;break;case"auto":if(e.getPoint(0).color)for(let s=0;s<t;s++){const{color:t}=e.getPoint(s);(t[0]>255||t[1]>255||t[2]>255)&&(i=!0)}break;default:console.warn("las: illegal value for options.las.colorDepth")}return i}(e,c,t.las?.colorDepth);for(let t=0;t<c;t++){const{position:A,color:a,intensity:l,classification:c}=e.getPoint(t);s[3*o]=A[0]*h+p,s[3*o+1]=A[1]*u+f,s[3*o+2]=A[2]*d+g,a&&i&&(m?(i[4*o]=a[0]/256,i[4*o+1]=a[1]/256,i[4*o+2]=a[2]/256):(i[4*o]=a[0],i[4*o+1]=a[1],i[4*o+2]=a[2]),i[4*o+3]=255),r[o]=l,n[o]=c,o++}const _={...a,header:{vertexCount:l.totalRead},progress:l.totalRead/l.totalToRead};t?.onProgress?.(_)})),a.header={vertexCount:A.totalToRead,boundingBox:nl(a?.attributes||{})},a&&(a.schema=Su(a.loaderData,a.attributes));return a}(e,t)}const ku={...vu,parse:async(e,t)=>Du(e,t),parseSync:(e,t)=>Du(e,t)};
24
24
  /*!
25
25
  * html2canvas 1.4.1 <https://html2canvas.hertzen.com>
26
26
  * Copyright (c) 2022 Niklas von Hertzen <https://hertzen.com>