@xeokit/xeokit-sdk 2.6.97 → 2.6.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  /**
2
- * xeokit-sdk v2.6.97
3
- * Commit: fd8731b8272e4958c8231a6794a98a1874564a08
4
- * Built: 2025-12-03T17:04:45.022Z
2
+ * xeokit-sdk v2.6.98
3
+ * Commit: 30ac0fa9a4eaf6759fe306bb2e332cce49884787
4
+ * Built: 2025-12-08T14:34:05.193Z
5
5
  */
6
6
 
7
- "undefined"!=typeof window&&(window.__XEOKIT__={version:"2.6.97",commit:"fd8731b8272e4958c8231a6794a98a1874564a08",built:"2025-12-03T17:04:45.022Z"}),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!==y(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(y(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)&&y(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(y(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),B=g(f,m,t,s,i);let w=e.prevZ,v=e.nextZ;for(;w&&w.z>=_&&v&&v.z<=B;){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)&&y(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)&&y(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)&&y(w.prev,w,w.next)>=0)return!1;w=w.prevZ}for(;v&&v.z<=B;){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)&&y(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&&B(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 y(e.prev,e,t.prev)<0&&y(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 B(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)&&(y(e.prev,e,t.prev)||y(e,t.prev,t))||w(e,t)&&y(e.prev,e,e.next)>0&&y(t.prev,t,t.next)>0)}function y(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(y(e,t,s)),n=M(y(e,t,i)),A=M(y(s,i,e)),o=M(y(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 y(e.prev,e,e.next)<0?y(e,t,e.next)>=0&&y(e,e.prev,t)>=0:y(e,t,e.prev)<0||y(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},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),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),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],B=t[1],y=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+B*o+y*h+w*f,s[1]=b*r+B*a+y*u+w*g,s[2]=b*n+B*l+y*d+w*m,s[3]=b*A+B*c+y*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],B=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*B,s[1]=A*u+o*f+a*_,s[4]=A*d+o*g+a*b,s[7]=A*p+o*m+a*B,s[2]=l*u+c*f+h*_,s[5]=l*d+c*g+h*b,s[8]=l*p+c*m+h*B,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,B=s*l-n*A,y=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+B*F+y*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*y)*I,t[3]=(-h*v+u*w-d*y)*I,t[4]=(-A*U+a*E-l*M)*I,t[5]=(s*U-r*E+n*M)*I,t[6]=(-p*v+g*B-m*b)*I,t[7]=(c*v-u*B+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*B+m*_)*I,t[11]=(-c*w+h*B-d*_)*I,t[12]=(-A*F+o*M-a*C)*I,t[13]=(s*F-i*M+r*C)*I,t[14]=(-p*y+f*b-g*_)*I,t[15]=(c*y-h*b+u*_)*I,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const 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[8]=s[8],e[9]=s[9],e[10]=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,B,y,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,B=f*g-d*_,y=d*m-p*g,w=Math.sqrt(b*b+B*B+y*y),w?(w=1/w,b*=w,B*=w,y*=w):(b=0,B=0,y=0),i[0]=g,i[1]=b,i[2]=d,i[3]=0,i[4]=m,i[5]=B,i[6]=p,i[7]=0,i[8]=_,i[9]=y,i[10]=f,i[11]=0,i[12]=-(g*r+m*n+_*A),i[13]=-(b*r+B*n+y*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],B=e[11],y=e[12],w=e[13],v=e[14],C=e[15];let M;for(let e=0;e<r;++e)a=t[e],n=a[0],A=a[1],o=a[2],M=i[e]||(i[e]=[0,0,0]),M[0]=l*n+d*A+m*o+y,M[1]=c*n+p*A+_*o+w,M[2]=h*n+f*A+b*o+v,M[3]=u*n+g*A+B*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],B=e[12],y=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+B,s[i+1]=l*n+d*A+m*o+y,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],B=e[12],y=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+B,s[i+1]=l*n+d*A+m*o+y,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),B=R.subVec3(m,d,t),y=R.subVec2(g,p,s),w=R.subVec2(_,p,i),v=1/(y[0]*w[1]-y[1]*w[0]),C=R.mulVec3Scalar(R.subVec3(R.mulVec3Scalar(b,w[1],r),R.mulVec3Scalar(B,y[1],n),A),v,n);let M;for(let e=0;e<3;e++)M=3*a[h+e],c[M]+=C[0],c[M+1]+=C[1],c[M+2]+=C[2]}return c}})(),buildPickTriangles(e,t,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 B=[],y=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>y)||(P=s[x.index1],S=s[x.index2],(!D&&P>65535||S>65535)&&(D=!0),B.push(P),B.push(S));return D?new Uint32Array(B):new Uint16Array(B)}}(),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()),B=R.vec3ApplyQuaternion(_.quaternion,d,R.vec3()),y=R.vec3ApplyQuaternion(_.quaternion,p,R.vec3());return function(u,d={}){const p=R.subVec3(u.origin,_.pos,R.vec3()),w=R.dotVec3(y,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(B,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,B=f-d,y=(0!==b||0!==B)&&Math.abs(b*_-B*g)<1e-10?g*b+_*B:-1;if(y>=0&&y<=Math.pow(b,2)+Math.pow(B,2))return!1;d>c!=f>c&&g<_*b/B&&(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(y,t),A=w+R.dotVec3(y,s),o=w+R.dotVec3(y,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,y)<=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}},W={},z=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=z.addItem({});q.scenes[e.id]=e;const t=e.ticksPerOcclusionTest,s=e.ticksPerRender;W[e.id]={ticksPerOcclusionTest:t,ticksPerRender:s,renderCountdown:s},L.components.scenes++,e.once("destroyed",(()=>{z.removeItem(e.id),delete q.scenes[e.id],delete W[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=W[A],i||(i=W[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}}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(),Be=R.vec3(),ye=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,ye),i.look=R.subVec3(ye,ve,Be)):this._flyingLook&&(i.look=R.lerpVec3(s,0,1,this._look1,this._look2,Be),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,ye),i.look=R.lerpVec3(s,0,1,this._look1,this._look2,Be),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 B=[],y=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>y)||(P=s[x.index1],S=s[x.index2],(!D&&P>65535||S>65535)&&(D=!0),B.push(P),B.push(S));return D?new Uint32Array(B):new Uint16Array(B)}}();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,a=s[4]-n,l=s[5]-A,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 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,{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 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,{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 B,y,w,v,C,M,E,F,x,U,I;const T=(90-180*Math.atan(i/(s-t))/Math.PI)/90;for(B=0;B<=n;B++)for(C=t-B*f,M=h-B*u,y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),m.push(C*w),m.push(T),m.push(C*v),_.push(y*p),_.push(1*B/n),g.push(C*w+a),g.push(M+l),g.push(C*v+c);for(B=0;B<n;B++)for(y=0;y<=r;y++)E=B*(r+1)+y,F=E+r,b.push(E),b.push(F),b.push(F+1),b.push(E),b.push(F+1),b.push(E+1);if(!A&&t>0){for(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),y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),U=.5*Math.sin(y*d)+.5,I=.5*Math.cos(y*d)+.5,m.push(t*w),m.push(1),m.push(t*v),_.push(U),_.push(I),g.push(t*w+a),g.push(h+l),g.push(t*v+c);for(y=0;y<r;y++)o=x,E=x+1+y,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),y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),U=.5*Math.sin(y*d)+.5,I=.5*Math.cos(y*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(y=0;y<r;y++)o=x,E=x+1+y,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 B,y,w,v,C,M,E,F=0,x=0;for(B=0;B<p;B++){const e=B*g-c;for(y=0;y<d;y++)w=y*f-l,m[F]=w+A,m[F+1]=o,m[F+2]=-e+a,_[F+1]=1,b[x]=y/h,b[x+1]=(u-B)/u,F+=3,x+=2}F=0;const U=new(m.length/3>65535?Uint32Array:Uint16Array)(h*u*6);for(B=0;B<u;B++)for(y=0;y<h;y++)v=y+d*B,C=y+d*(B+1),M=y+1+d*(B+1),E=y+1+d*B,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,B,y,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),B=b*f,y=g,w=_*f,v=1-d/o,C=u/A,l.push(B),l.push(y),l.push(w),c.push(v),c.push(C),a.push(s+n*B),a.push(i+n*y),a.push(r+n*w);for(u=0;u<A;u++)for(d=0;d<o;d++)M=u*(o+1)+d,E=M+o+1,h.push(M+1),h.push(E+1),h.push(E),h.push(M+1),h.push(E),h.push(M);return 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,B,y,w,v,C,M;for(y=0;y<=r;y++)for(B=0;B<=i;B++)p=B/i*n,f=.785398+y/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-B/i),u.push(y/r),b=R.normalizeVec3(R.subVec3([g,m,_],[o,a,l],[]),[]),h.push(b[0]),h.push(b[1]),h.push(b[2]);for(y=1;y<=r;y++)for(B=1;B<=i;B++)w=(i+1)*y+B-1,v=(i+1)*(y-1)+B-1,C=(i+1)*(y-1)+B,M=(i+1)*y+B,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,B=parseInt(h[2])-1,y=parseInt(u[2])-1,w=t.c_verts.length/3,v=t.c_uvt.length/2,C=t.c_norms.length/3;if(d<0&&(d=w+d+1),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),B<0&&(B=C+B+1),y<0&&(y=C+y+1),t.i_verts.push(d,p,f),t.i_uvt.push(g,m,_),t.i_norms.push(b,B,y),5==A.length){var M=A[4].split("/"),E=parseInt(M[0])-1,F=parseInt(M[1])-1,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,y,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,B=0,y=.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*y+s),A.push(B+m[1]*n*y+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*y*n}B-=35*y*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("}")})),B=c.sectionPlanesState,y=B&&function(){const e=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t}(B.getNumAllocatedSectionPlanes()).map((e=>{const t=(t,s,i)=>a.createUniform(t,`sectionPlane${s}${e}`,((t,s)=>{const r=B.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=y?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(y){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 = ${y(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"])}}}},Bt=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&&yt(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`)}},yt=(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&&Bt(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=Bt(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=Bt(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&&yt(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)),B=_("baseColor",(e=>e._baseColorMap)),y=_("diffuse",(e=>e._diffuseMap)),w=_("emissive",(e=>e._emissiveMap)),v=_("occlusion",(e=>e._occlusionMap)),C=_("alpha",(e=>e._alphaMap)),M=_("metallic",(e=>e._metallicMap)),E=_("roughness",(e=>e._roughnessMap)),F=_("metallicRoughness",(e=>e._metallicRoughnessMap)),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`)),W=t.createVarying("vec4","texturePos",(()=>`vec4(${l.uv}, 1.0, 1.0)`)),z=l.color&&t.createVarying("vec4","vColor",(()=>l.color)),X=t.createVarying("vec3","vViewNormal",(()=>l.normal.view)),K=c.directionalLights.map(((e,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(W)}.r;`),z&&(e.push(`diffuseColor *= ${z}.rgb;`),e.push(`alpha *= ${z}.a;`)),o&&B&&(e.push("vec4 baseColorTexel = "+B(W)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(A||a)&&y&&(e.push("vec4 diffuseTexel = "+y(W)+";"),e.push("diffuseColor *= diffuseTexel.rgb;"),e.push("alpha *= diffuseTexel.a;")),e.push(`vec3 emissiveColor = ${(A||o||a)&&Q||"vec3(0.0)"};`),(A||o||a)&&w&&e.push(`emissiveColor = ${w(W)}.rgb;`),r){e.push(`vec3 specular = ${(A||a)&&R||"vec3(1.0)"};`),e.push(`float glossiness = ${a&&O||"1.0"};`),e.push(`float metallic = ${o&&V||"1.0"};`),e.push(`float roughness = ${(o||a)&&L||"1.0"};`),e.push(`float shininess = ${A&&H||"1.0"};`),e.push(`float specularF0 = ${o&&N||"1.0"};`),e.push(`float occlusion = ${(A||o||a)&&v?`${v(W)}.r`:"1.0"};`),o&&M&&e.push(`metallic *= ${M(W)}.r;`),o&&E&&e.push(`roughness *= ${E(W)}.r;`),o&&F&&(e.push("vec4 metalRoughTexel = "+F(W)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(A||a)&&x&&e.push(`specular *= ${x(W)}.rgb;`),a&&U&&e.push(`glossiness *= ${U(W)}.r;`),a&&I&&(e.push("vec4 specGlossTexel = "+I(W)+";"),e.push("specular *= specGlossTexel.rgb;"),e.push("glossiness *= specGlossTexel.a;"));const t=`normalize(${X})`,i=(A||o||a)&&T?`${ee}(${j}, ${t}, ${T.getTexCoordExpression(W)}, ${T(W)})`: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(W)}.rgb;`),e.push(`ambientColor *= ${c.getAmbientColor()};`),e.push("vec3 outgoingLight = emissiveColor + ambientColor;");e.push(`vec4 fragColor = ${h} * vec4(outgoingLight, alpha);`),e.push(`${J} = ${t?t("fragColor"):"fragColor"};`)}}}(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,dontBillboardAnything:!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,dontBillboardAnything:!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,dontBillboardAnything:!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(),B=R.vec3(),y=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,W=L.positions;let z,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,z=3*Q,X=3*O,K=3*V}else z=3*H,X=z+3,K=X+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],i[0]=W[X+0],i[1]=W[X+1],i[2]=W[X+2],r[0]=W[K+0],r[1]=W[K+1],r[2]=W[K+2],L.compressGeometry){const e=L.positionsDecodeMatrix;e&&(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[z],c[1]=Z[z+1],c[2]=Z[z+2],h[0]=Z[X],h[1]=Z[X+1],h[2]=Z[X+2],u[0]=Z[K],u[1]=Z[K+1],u[2]=Z[K+2];const e=R.addVec3(R.addVec3(R.mulVec3Scalar(c,l[0],b),R.mulVec3Scalar(h,l[1],B),y),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"),B=n.createUniform("mat4","positionsDecodeMatrix"),y=n.createUniform("mat3","uvDecodeMatrix"),w=n.createUniform("mat4","viewMatrix"),v=n.createUniform("mat4","viewNormalMatrix"),C=n.createUniform("mat4","projMatrix"),M=e.billboard,E=!i.dontBillboardAnything&&("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=[];i.dontBillboardAnything?T.push(`mat4 viewMatrix2 = ${w};`):(T.push(`mat4 viewMatrix1 = ${w};`),F?T.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):h&&T.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),T.push(`mat4 viewMatrix2 = ${I("viewMatrix1")};`));const P="clipPos",S=n.createUniform("bool","clippable"),[D,k]=r.buildProgram(c,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 = ${B} * localPosition;`),s.push(`vec4 worldPosition = ${U(g)} * localPosition;`),s.push(`worldPosition.xyz = worldPosition.xyz + ${_};`),i.dontBillboardAnything?s.push(`vec4 viewPosition = ${w} * worldPosition;`):(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?`(${y} * 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(B,d.positionsDecodeMatrix),i(y,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 Wt(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 zt(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=Wt(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=Wt(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=Wt(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=Wt(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){const t=Wt(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=Wt(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=Wt(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),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=zt(s,this.minFilter);s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,a),a!==s.NEAREST_MIPMAP_NEAREST&&a!==s.LINEAR_MIPMAP_NEAREST&&a!==s.NEAREST_MIPMAP_LINEAR&&a!==s.LINEAR_MIPMAP_LINEAR||(i=!0);const l=zt(s,this.magFilter);l&&s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,l);const c=zt(s,this.wrapS);c&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,c);const h=zt(s,this.wrapT);h&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,h);const u=zt(s,this.format,this.encoding),d=zt(s,this.type),p=Zt(s,this.internalFormat,u,d,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,p,u,d,t[e])}}else s.texImage2D(s.TEXTURE_2D,0,p,u,d,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=zt(s,this.wrapS);n&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,n);const A=zt(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=zt(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,zt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,zt(s,this.magFilter)));const o=zt(s,this.format,this.encoding),a=zt(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=zt(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=zt(t,e.magFilter);s&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,s))}if(void 0!==e.wrapS){const s=zt(t,e.wrapS);s&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,s))}if(void 0!==e.wrapT){const s=zt(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||Wt(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]),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(),Bs=R.vec3();class ys{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],Bs[0]=e[A],Bs[1]=e[A+1],Bs[2]=e[A+2],R.cross3Vec3(_s,bs,_s),s+=R.dotVec3(_s,Bs)}return s/6}}const ws=new ys,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};`)}},Ws=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);`)}},zs=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,B="clipPos",[y,w]=A.buildProgram(e,s+" "+i+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:B,clippableTest:l.clippableTest,clippingCaps:r.clippingCaps,crossSections:t.crossSections,discardPoints:h&&c.roundPoints,getGammaFactor:t.gammaOutput&&(()=>t.gammaFactor),getLogDepth:r.getLogDepth,getPointSize:function(){const e=[];if(h){const t=o.createUniform("float","pointSize",(e=>e(c.pointSize)));if(c.perspectivePoints){const 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:()=>y.destroy(),drawLayer:(e,t,s)=>{e.lastProgramId!==y.id&&(e.lastProgramId=y.id,y.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}};y.inputSetters.setUniforms(e,h),t.drawCalls[n?n.vertices?"drawVertices":"drawEdges":"drawSurface"](y.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),"flat"),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(Ws(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:d(f),pickMeshRenderer:d(g),silhouetteRenderer:d(((e,s,i)=>i(zs(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(zs(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=>Bt(e,t._lightsState),s=e=>{const t=e.createUniform("vec4","uSAOParams",((e,t)=>e(t.legacyFrameCtx.saoParams))),s=yt(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=yt(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)=>yt(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"),B=e.createFragmentDefinition("saturate",((e,t)=>t.push(`float ${e}(const in float a) { return clamp(a, 0.0, 1.0); }`))),y=e.createFragmentDefinition("BRDF_Specular_GGX",((e,t)=>{t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push(`vec3 ${e}(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(` float dotNL = ${B}( dot( viewNormal, incidentLightDirection ) );`),t.push(` float dotNV = ${B}( dot( viewNormal, viewEyeDir ) );`),t.push(` float dotNH = ${B}( dot( viewNormal, halfDir ) );`),t.push(` float dotLH = ${B}( dot( incidentLightDirection, halfDir ) );`),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),w=e.createFragmentDefinition("BRDF_Specular_GGX_Environment",((e,t)=>{t.push(`vec3 ${e}(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(` float dotNV = ${B}(dot(viewNormal, viewEyeDir));`),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),v=e.createFragmentDefinition("perturbNormal2Arb",((e,t)=>{t.push(`vec3 ${e}( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {`),t.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),t.push(" return surf_norm;"),t.push(" }"),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{programName:"PBR",getHash:()=>[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=`${B}(dot(viewNormal, lightDirection${i}))`;e.push(`vec3 irradiance${i} = ${r} * ${s.getColor()};`),e.push(`reflDiff += irradiance${i};`),e.push(`reflSpec += irradiance${i} * PI * ${y}(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(Ws(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(zs(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])},B=()=>b(!1);B(),t.on("compile",B),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._compiledPortions.edgesColorOpaqueAllowed()&&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,Bi=bi.maxDataTextureHeight,yi=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))}}}}},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*Bi||i+n>4096*Bi)&&_i.cannotCreatePortion.becauseTextureSize++,s&&=this._numVertices+r<=4096*Bi&&i+n<=4096*Bi}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),B=e.geometry16Bits.createDrawers(m,l.UNSIGNED_SHORT),y=e.geometry32Bits.createDrawers(m,l.UNSIGNED_INT);this._buffer=null;let w=!1,v=!1,C=!1,M=0;const E=()=>{w=!0},F=a.on("rendering",(()=>{v&&(w=!1,v=!1,h.reloadData()),M=0})),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{edgesColorOpaqueAllowed:()=>!a.logarithmicDepthBufferEnabled||(a._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),a._loggedWarning=!0),!1),sortId:A,setClippableFlags:I,setFlags:(e,t,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,yi);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),B.edges(e,t),y.edges(e,t)}))};return{drawVertices:s(l.POINTS),drawEdges:s(l.LINES),drawSurface:e((e=>{const t=l.TRIANGLES;b.indices(e,t),B.indices(e,t),y.indices(e,t)}))}}(),destroy:()=>{C||(a.off(F),C=!0)}}}}const 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";const 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),{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(),Wi=R.vec3(),zi=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}}};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),B=u&&t.colorsCompressed?b(new Uint8Array(t.colorsCompressed),h.STATIC_DRAW):b(e.colors.compileBuffer(Uint8Array),h.DYNAMIC_DRAW),y=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);u||n.forEach((e=>{if(e.retainedGeometry){const t=3*e.portionBase;e.retainedGeometry.quantizedPositions=F.subarray(t,t+3*e.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)}}}();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{edgesColorOpaqueAllowed:()=>!0,solid:Q,sortId:("points"===A?"Points":"lines"===A?"Lines":"Triangles")+(u?"Instancing":"Batching")+"Layer"+("points"!==A&&"lines"!==A?(Q?"-solid":"-surface")+"-autoNormals"+(u?"":(o&&o.colorTexture?"-colorTexture":"")+(o&&o.metallicRoughnessTexture?"-metallicRoughnessTexture":"")):""),setClippableFlags:k,setFlags:k,setFlags2:(e,t,s)=>{},setDeferredFlags:()=>{D&&(_.setData(D),D=null)},setColor:(e,t)=>{if(B){const s=n[e],i=qi.getTypeArray(Uint8Array,4*s.portionSize);$i(i,t.slice(0,4)),B.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(y){Oi.set(t);const e=qi.getTypeArray(Float32Array,3*s.portionSize);$i(e,Oi),y.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;R.mulMat4v4(n,e,e);const 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.mulMat4v4(n,o,o),R.addVec3(e,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=Wi,p=zi,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],B=3*n[i+1],y=3*n[i+2];if(d[0]=e[b],d[1]=e[b+1],d[2]=e[b+2],p[0]=e[B],p[1]=e[B+1],p[2]=e[B+2],f[0]=e[y],f[1]=e[y+1],f[2]=e[y+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,B),s(i.pickColor,v),s(i.uV,S&&S.buf),s(i.metallicRoughness,w),s(i.flags,_),s(i.offset,y),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 B=[];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.");B.push({data:r,width:s,height:i})}return c(),{width:u,height:d,hasAlpha:f,mipmaps:B,format:b,dfdTransferFn:g,dfdFlags:m}}(c.buffers[0]),g=[];for(let e=0;e<u.length;++e)g.push(u[e].data.buffer);self.postMessage({type:"transcode",id:c.id,width:t,height:A,hasAlpha:h,mipmaps:u,format:d,dfdTransferFn: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.98",commit:"30ac0fa9a4eaf6759fe306bb2e332cce49884787",built:"2025-12-08T14:34:05.193Z"}),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!==y(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(y(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)&&y(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(y(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),B=g(f,m,t,s,i);let w=e.prevZ,v=e.nextZ;for(;w&&w.z>=_&&v&&v.z<=B;){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)&&y(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)&&y(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)&&y(w.prev,w,w.next)>=0)return!1;w=w.prevZ}for(;v&&v.z<=B;){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)&&y(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&&B(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 y(e.prev,e,t.prev)<0&&y(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 B(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)&&(y(e.prev,e,t.prev)||y(e,t.prev,t))||w(e,t)&&y(e.prev,e,e.next)>0&&y(t.prev,t,t.next)>0)}function y(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(y(e,t,s)),n=M(y(e,t,i)),A=M(y(s,i,e)),o=M(y(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 y(e.prev,e,e.next)<0?y(e,t,e.next)>=0&&y(e,e.prev,t)>=0:y(e,t,e.prev)<0||y(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},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),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),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],B=t[1],y=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+B*o+y*h+w*f,s[1]=b*r+B*a+y*u+w*g,s[2]=b*n+B*l+y*d+w*m,s[3]=b*A+B*c+y*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],B=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*B,s[1]=A*u+o*f+a*_,s[4]=A*d+o*g+a*b,s[7]=A*p+o*m+a*B,s[2]=l*u+c*f+h*_,s[5]=l*d+c*g+h*b,s[8]=l*p+c*m+h*B,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,B=s*l-n*A,y=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+B*F+y*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*y)*I,t[3]=(-h*v+u*w-d*y)*I,t[4]=(-A*U+a*E-l*M)*I,t[5]=(s*U-r*E+n*M)*I,t[6]=(-p*v+g*B-m*b)*I,t[7]=(c*v-u*B+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*B+m*_)*I,t[11]=(-c*w+h*B-d*_)*I,t[12]=(-A*F+o*M-a*C)*I,t[13]=(s*F-i*M+r*C)*I,t[14]=(-p*y+f*b-g*_)*I,t[15]=(c*y-h*b+u*_)*I,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const 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,B,y,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,B=f*g-d*_,y=d*m-p*g,w=Math.sqrt(b*b+B*B+y*y),w?(w=1/w,b*=w,B*=w,y*=w):(b=0,B=0,y=0),i[0]=g,i[1]=b,i[2]=d,i[3]=0,i[4]=m,i[5]=B,i[6]=p,i[7]=0,i[8]=_,i[9]=y,i[10]=f,i[11]=0,i[12]=-(g*r+m*n+_*A),i[13]=-(b*r+B*n+y*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],B=e[11],y=e[12],w=e[13],v=e[14],C=e[15];let M;for(let e=0;e<r;++e)a=t[e],n=a[0],A=a[1],o=a[2],M=i[e]||(i[e]=[0,0,0]),M[0]=l*n+d*A+m*o+y,M[1]=c*n+p*A+_*o+w,M[2]=h*n+f*A+b*o+v,M[3]=u*n+g*A+B*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],B=e[12],y=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+B,s[i+1]=l*n+d*A+m*o+y,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],B=e[12],y=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+B,s[i+1]=l*n+d*A+m*o+y,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),B=R.subVec3(m,d,t),y=R.subVec2(g,p,s),w=R.subVec2(_,p,i),v=1/(y[0]*w[1]-y[1]*w[0]),C=R.mulVec3Scalar(R.subVec3(R.mulVec3Scalar(b,w[1],r),R.mulVec3Scalar(B,y[1],n),A),v,n);let M;for(let e=0;e<3;e++)M=3*a[h+e],c[M]+=C[0],c[M+1]+=C[1],c[M+2]+=C[2]}return c}})(),buildPickTriangles(e,t,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 B=[],y=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>y)||(P=s[x.index1],S=s[x.index2],(!D&&P>65535||S>65535)&&(D=!0),B.push(P),B.push(S));return D?new Uint32Array(B):new Uint16Array(B)}}(),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()),B=R.vec3ApplyQuaternion(_.quaternion,d,R.vec3()),y=R.vec3ApplyQuaternion(_.quaternion,p,R.vec3());return function(u,d={}){const p=R.subVec3(u.origin,_.pos,R.vec3()),w=R.dotVec3(y,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(B,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,B=f-d,y=(0!==b||0!==B)&&Math.abs(b*_-B*g)<1e-10?g*b+_*B:-1;if(y>=0&&y<=Math.pow(b,2)+Math.pow(B,2))return!1;d>c!=f>c&&g<_*b/B&&(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(y,t),A=w+R.dotVec3(y,s),o=w+R.dotVec3(y,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,y)<=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}},W={},z=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=z.addItem({});q.scenes[e.id]=e;const t=e.ticksPerOcclusionTest,s=e.ticksPerRender;W[e.id]={ticksPerOcclusionTest:t,ticksPerRender:s,renderCountdown:s},L.components.scenes++,e.once("destroyed",(()=>{z.removeItem(e.id),delete q.scenes[e.id],delete W[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=W[A],i||(i=W[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(),Be=R.vec3(),ye=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,ye),i.look=R.subVec3(ye,ve,Be)):this._flyingLook&&(i.look=R.lerpVec3(s,0,1,this._look1,this._look2,Be),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,ye),i.look=R.lerpVec3(s,0,1,this._look1,this._look2,Be),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 B=[],y=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>y)||(P=s[x.index1],S=s[x.index2],(!D&&P>65535||S>65535)&&(D=!0),B.push(P),B.push(S));return D?new Uint32Array(B):new Uint16Array(B)}}();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,a=s[4]-n,l=s[5]-A,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 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,{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 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,{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 B,y,w,v,C,M,E,F,x,U,I;const T=(90-180*Math.atan(i/(s-t))/Math.PI)/90;for(B=0;B<=n;B++)for(C=t-B*f,M=h-B*u,y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),m.push(C*w),m.push(T),m.push(C*v),_.push(y*p),_.push(1*B/n),g.push(C*w+a),g.push(M+l),g.push(C*v+c);for(B=0;B<n;B++)for(y=0;y<=r;y++)E=B*(r+1)+y,F=E+r,b.push(E),b.push(F),b.push(F+1),b.push(E),b.push(F+1),b.push(E+1);if(!A&&t>0){for(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),y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),U=.5*Math.sin(y*d)+.5,I=.5*Math.cos(y*d)+.5,m.push(t*w),m.push(1),m.push(t*v),_.push(U),_.push(I),g.push(t*w+a),g.push(h+l),g.push(t*v+c);for(y=0;y<r;y++)o=x,E=x+1+y,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),y=0;y<=r;y++)w=Math.sin(y*d),v=Math.cos(y*d),U=.5*Math.sin(y*d)+.5,I=.5*Math.cos(y*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(y=0;y<r;y++)o=x,E=x+1+y,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 B,y,w,v,C,M,E,F=0,x=0;for(B=0;B<p;B++){const e=B*g-c;for(y=0;y<d;y++)w=y*f-l,m[F]=w+A,m[F+1]=o,m[F+2]=-e+a,_[F+1]=1,b[x]=y/h,b[x+1]=(u-B)/u,F+=3,x+=2}F=0;const U=new(m.length/3>65535?Uint32Array:Uint16Array)(h*u*6);for(B=0;B<u;B++)for(y=0;y<h;y++)v=y+d*B,C=y+d*(B+1),M=y+1+d*(B+1),E=y+1+d*B,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,B,y,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),B=b*f,y=g,w=_*f,v=1-d/o,C=u/A,l.push(B),l.push(y),l.push(w),c.push(v),c.push(C),a.push(s+n*B),a.push(i+n*y),a.push(r+n*w);for(u=0;u<A;u++)for(d=0;d<o;d++)M=u*(o+1)+d,E=M+o+1,h.push(M+1),h.push(E+1),h.push(E),h.push(M+1),h.push(E),h.push(M);return 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,B,y,w,v,C,M;for(y=0;y<=r;y++)for(B=0;B<=i;B++)p=B/i*n,f=.785398+y/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-B/i),u.push(y/r),b=R.normalizeVec3(R.subVec3([g,m,_],[o,a,l],[]),[]),h.push(b[0]),h.push(b[1]),h.push(b[2]);for(y=1;y<=r;y++)for(B=1;B<=i;B++)w=(i+1)*y+B-1,v=(i+1)*(y-1)+B-1,C=(i+1)*(y-1)+B,M=(i+1)*y+B,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,B=parseInt(h[2])-1,y=parseInt(u[2])-1,w=t.c_verts.length/3,v=t.c_uvt.length/2,C=t.c_norms.length/3;if(d<0&&(d=w+d+1),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),B<0&&(B=C+B+1),y<0&&(y=C+y+1),t.i_verts.push(d,p,f),t.i_uvt.push(g,m,_),t.i_norms.push(b,B,y),5==A.length){var M=A[4].split("/"),E=parseInt(M[0])-1,F=parseInt(M[1])-1,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,y,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,B=0,y=.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*y+s),A.push(B+m[1]*n*y+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*y*n}B-=35*y*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("}")})),B=c.sectionPlanesState,y=B&&function(){const e=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t}(B.getNumAllocatedSectionPlanes()).map((e=>{const t=(t,s,i)=>a.createUniform(t,`sectionPlane${s}${e}`,((t,s)=>{const r=B.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=y?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(y){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 = ${y(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"])}}}},Bt=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&&yt(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`)}},yt=(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&&Bt(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=Bt(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=Bt(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&&yt(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)),B=_("baseColor",(e=>e._baseColorMap)),y=_("diffuse",(e=>e._diffuseMap)),w=_("emissive",(e=>e._emissiveMap)),v=_("occlusion",(e=>e._occlusionMap)),C=_("alpha",(e=>e._alphaMap)),M=_("metallic",(e=>e._metallicMap)),E=_("roughness",(e=>e._roughnessMap)),F=_("metallicRoughness",(e=>e._metallicRoughnessMap)),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`)),W=t.createVarying("vec4","texturePos",(()=>`vec4(${l.uv}, 1.0, 1.0)`)),z=l.color&&t.createVarying("vec4","vColor",(()=>l.color)),X=t.createVarying("vec3","vViewNormal",(()=>l.normal.view)),K=c.directionalLights.map(((e,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(W)}.r;`),z&&(e.push(`diffuseColor *= ${z}.rgb;`),e.push(`alpha *= ${z}.a;`)),o&&B&&(e.push("vec4 baseColorTexel = "+B(W)+";"),e.push("diffuseColor *= baseColorTexel.rgb;"),e.push("alpha *= baseColorTexel.a;")),(A||a)&&y&&(e.push("vec4 diffuseTexel = "+y(W)+";"),e.push("diffuseColor *= diffuseTexel.rgb;"),e.push("alpha *= diffuseTexel.a;")),e.push(`vec3 emissiveColor = ${(A||o||a)&&Q||"vec3(0.0)"};`),(A||o||a)&&w&&e.push(`emissiveColor = ${w(W)}.rgb;`),r){e.push(`vec3 specular = ${(A||a)&&R||"vec3(1.0)"};`),e.push(`float glossiness = ${a&&O||"1.0"};`),e.push(`float metallic = ${o&&V||"1.0"};`),e.push(`float roughness = ${(o||a)&&L||"1.0"};`),e.push(`float shininess = ${A&&H||"1.0"};`),e.push(`float specularF0 = ${o&&N||"1.0"};`),e.push(`float occlusion = ${(A||o||a)&&v?`${v(W)}.r`:"1.0"};`),o&&M&&e.push(`metallic *= ${M(W)}.r;`),o&&E&&e.push(`roughness *= ${E(W)}.r;`),o&&F&&(e.push("vec4 metalRoughTexel = "+F(W)+";"),e.push("metallic *= metalRoughTexel.b;"),e.push("roughness *= metalRoughTexel.g;")),(A||a)&&x&&e.push(`specular *= ${x(W)}.rgb;`),a&&U&&e.push(`glossiness *= ${U(W)}.r;`),a&&I&&(e.push("vec4 specGlossTexel = "+I(W)+";"),e.push("specular *= specGlossTexel.rgb;"),e.push("glossiness *= specGlossTexel.a;"));const t=`normalize(${X})`,i=(A||o||a)&&T?`${ee}(${j}, ${t}, ${T.getTexCoordExpression(W)}, ${T(W)})`: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(W)}.rgb;`),e.push(`ambientColor *= ${c.getAmbientColor()};`),e.push("vec3 outgoingLight = emissiveColor + ambientColor;");e.push(`vec4 fragColor = ${h} * vec4(outgoingLight, alpha);`),e.push(`${J} = ${t?t("fragColor"):"fragColor"};`)}}}(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,dontBillboardAnything:!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,dontBillboardAnything:!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,dontBillboardAnything:!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(),B=R.vec3(),y=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,W=L.positions;let z,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,z=3*Q,X=3*O,K=3*V}else z=3*H,X=z+3,K=X+3;if(s[0]=W[z+0],s[1]=W[z+1],s[2]=W[z+2],i[0]=W[X+0],i[1]=W[X+1],i[2]=W[X+2],r[0]=W[K+0],r[1]=W[K+1],r[2]=W[K+2],L.compressGeometry){const e=L.positionsDecodeMatrix;e&&(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[z],c[1]=Z[z+1],c[2]=Z[z+2],h[0]=Z[X],h[1]=Z[X+1],h[2]=Z[X+2],u[0]=Z[K],u[1]=Z[K+1],u[2]=Z[K+2];const e=R.addVec3(R.addVec3(R.mulVec3Scalar(c,l[0],b),R.mulVec3Scalar(h,l[1],B),y),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"),B=n.createUniform("mat4","positionsDecodeMatrix"),y=n.createUniform("mat3","uvDecodeMatrix"),w=n.createUniform("mat4","viewMatrix"),v=n.createUniform("mat4","viewNormalMatrix"),C=n.createUniform("mat4","projMatrix"),M=e.billboard,E=!i.dontBillboardAnything&&("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=[];i.dontBillboardAnything?T.push(`mat4 viewMatrix2 = ${w};`):(T.push(`mat4 viewMatrix1 = ${w};`),F?T.push("viewMatrix1[3].xyz = vec3(0.0, 0.0, 0.0);"):h&&T.push("viewMatrix1[3] = vec4(0.0, 0.0, 0.0, 1.0);"),T.push(`mat4 viewMatrix2 = ${I("viewMatrix1")};`));const P="clipPos",S=n.createUniform("bool","clippable"),[D,k]=r.buildProgram(c,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 = ${B} * localPosition;`),s.push(`vec4 worldPosition = ${U(g)} * localPosition;`),s.push(`worldPosition.xyz = worldPosition.xyz + ${_};`),i.dontBillboardAnything?s.push(`vec4 viewPosition = ${w} * worldPosition;`):(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?`(${y} * 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(B,d.positionsDecodeMatrix),i(y,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 Wt(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 zt(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=Wt(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=Wt(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=Wt(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=Wt(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){const t=Wt(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=Wt(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=Wt(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),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=zt(s,this.minFilter);s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,a),a!==s.NEAREST_MIPMAP_NEAREST&&a!==s.LINEAR_MIPMAP_NEAREST&&a!==s.NEAREST_MIPMAP_LINEAR&&a!==s.LINEAR_MIPMAP_LINEAR||(i=!0);const l=zt(s,this.magFilter);l&&s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,l);const c=zt(s,this.wrapS);c&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,c);const h=zt(s,this.wrapT);h&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,h);const u=zt(s,this.format,this.encoding),d=zt(s,this.type),p=Zt(s,this.internalFormat,u,d,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,p,u,d,t[e])}}else s.texImage2D(s.TEXTURE_2D,0,p,u,d,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=zt(s,this.wrapS);n&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,n);const A=zt(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=zt(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,zt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,zt(s,this.magFilter)));const o=zt(s,this.format,this.encoding),a=zt(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=zt(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=zt(t,e.magFilter);s&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,s))}if(void 0!==e.wrapS){const s=zt(t,e.wrapS);s&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,s))}if(void 0!==e.wrapT){const s=zt(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||Wt(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]),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(),Bs=R.vec3();class ys{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],Bs[0]=e[A],Bs[1]=e[A+1],Bs[2]=e[A+2],R.cross3Vec3(_s,bs,_s),s+=R.dotVec3(_s,Bs)}return s/6}}const ws=new ys,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};`)}},Ws=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);`)}},zs=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,B="clipPos",[y,w]=A.buildProgram(e,s+" "+i+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:B,clippableTest:l.clippableTest,clippingCaps:r.clippingCaps,crossSections:t.crossSections,discardPoints:h&&c.roundPoints,getGammaFactor:t.gammaOutput&&(()=>t.gammaFactor),getLogDepth:r.getLogDepth,getPointSize:function(){const e=[];if(h){const t=o.createUniform("float","pointSize",(e=>e(c.pointSize)));if(c.perspectivePoints){const 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:()=>y.destroy(),drawLayer:(e,t,s)=>{e.lastProgramId!==y.id&&(e.lastProgramId=y.id,y.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}};y.inputSetters.setUniforms(e,h),t.drawCalls[n?n.vertices?"drawVertices":"drawEdges":"drawSurface"](y.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(Ws(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:d(f),pickMeshRenderer:d(g),silhouetteRenderer:d(((e,s,i)=>i(zs(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(zs(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=>Bt(e,t._lightsState),s=e=>{const t=e.createUniform("vec4","uSAOParams",((e,t)=>e(t.legacyFrameCtx.saoParams))),s=yt(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=yt(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)=>yt(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"),B=e.createFragmentDefinition("saturate",((e,t)=>t.push(`float ${e}(const in float a) { return clamp(a, 0.0, 1.0); }`))),y=e.createFragmentDefinition("BRDF_Specular_GGX",((e,t)=>{t.push("vec3 F_Schlick(const in vec3 specularColor, const in float dotLH) {"),t.push(" float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );"),t.push(" return ( 1.0 - specularColor ) * fresnel + specularColor;"),t.push("}"),t.push("float G_GGX_Smith(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" return 1.0 / ( gl * gv );"),t.push("}"),t.push("float G_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * ( dotNV * dotNV ) );"),t.push(" float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * ( dotNL * dotNL ) );"),t.push(" return 0.5 / max( gv + gl, 1e-6 );"),t.push("}"),t.push("float D_GGX(const in float alpha, const in float dotNH) {"),t.push(" float a2 = ( alpha * alpha );"),t.push(" float denom = ( dotNH * dotNH) * ( a2 - 1.0 ) + 1.0;"),t.push(" return 0.31830988618 * a2 / ( denom * denom);"),t.push("}"),t.push(`vec3 ${e}(const in vec3 incidentLightDirection, const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(" float alpha = ( roughness * roughness );"),t.push(" vec3 halfDir = normalize( incidentLightDirection + viewEyeDir );"),t.push(` float dotNL = ${B}( dot( viewNormal, incidentLightDirection ) );`),t.push(` float dotNV = ${B}( dot( viewNormal, viewEyeDir ) );`),t.push(` float dotNH = ${B}( dot( viewNormal, halfDir ) );`),t.push(` float dotLH = ${B}( dot( incidentLightDirection, halfDir ) );`),t.push(" vec3 F = F_Schlick( specularColor, dotLH );"),t.push(" float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );"),t.push(" float D = D_GGX( alpha, dotNH );"),t.push(" return F * (G * D);"),t.push("}")})),w=e.createFragmentDefinition("BRDF_Specular_GGX_Environment",((e,t)=>{t.push(`vec3 ${e}(const in vec3 viewNormal, const in vec3 viewEyeDir, const in vec3 specularColor, const in float roughness) {`),t.push(` float dotNV = ${B}(dot(viewNormal, viewEyeDir));`),t.push(" const vec4 c0 = vec4( -1, -0.0275, -0.572, 0.022);"),t.push(" const vec4 c1 = vec4( 1, 0.0425, 1.04, -0.04);"),t.push(" vec4 r = roughness * c0 + c1;"),t.push(" float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y;"),t.push(" vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw;"),t.push(" return specularColor * AB.x + AB.y;"),t.push("}")})),v=e.createFragmentDefinition("perturbNormal2Arb",((e,t)=>{t.push(`vec3 ${e}( vec3 eye_pos, vec3 surf_norm, vec2 uv, vec4 texel ) {`),t.push(" if (texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0) {"),t.push(" return surf_norm;"),t.push(" }"),t.push(" vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );"),t.push(" vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );"),t.push(" vec2 st0 = dFdx( uv.st );"),t.push(" vec2 st1 = dFdy( uv.st );"),t.push(" vec3 S = normalize( q0 * st1.t - q1 * st0.t );"),t.push(" vec3 T = normalize( -q0 * st1.s + q1 * st0.s );"),t.push(" vec3 N = normalize( surf_norm );"),t.push(" vec3 mapN = texel.xyz * 2.0 - 1.0;"),t.push(" mat3 tsn = mat3( S, T, N );"),t.push(" return normalize( tsn * mapN );"),t.push("}")}));return{programName:"PBR",getHash:()=>[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=`${B}(dot(viewNormal, lightDirection${i}))`;e.push(`vec3 irradiance${i} = ${r} * ${s.getColor()};`),e.push(`reflDiff += irradiance${i};`),e.push(`reflSpec += irradiance${i} * PI * ${y}(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(Ws(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(zs(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])},B=()=>b(!1);B(),t.on("compile",B),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._compiledPortions.edgesColorOpaqueAllowed()&&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,Bi=bi.maxDataTextureHeight,yi=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))}}}}},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*Bi||i+n>4096*Bi)&&_i.cannotCreatePortion.becauseTextureSize++,s&&=this._numVertices+r<=4096*Bi&&i+n<=4096*Bi}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),B=e.geometry16Bits.createDrawers(m,l.UNSIGNED_SHORT),y=e.geometry32Bits.createDrawers(m,l.UNSIGNED_INT);this._buffer=null;let w=!1,v=!1,C=!1,M=0;const E=()=>{w=!0},F=a.on("rendering",(()=>{v&&(w=!1,v=!1,h.reloadData()),M=0})),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{edgesColorOpaqueAllowed:()=>!a.logarithmicDepthBufferEnabled||(a._loggedWarning||(console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer"),a._loggedWarning=!0),!1),sortId:A,setClippableFlags:I,setFlags:(e,t,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,yi);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),B.edges(e,t),y.edges(e,t)}))};return{drawVertices:s(l.POINTS),drawEdges:s(l.LINES),drawSurface:e((e=>{const t=l.TRIANGLES;b.indices(e,t),B.indices(e,t),y.indices(e,t)}))}}(),destroy:()=>{C||(a.off(F),C=!0)}}}}const 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";const 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),{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(),Wi=R.vec3(),zi=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}}};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),B=u&&t.colorsCompressed?b(new Uint8Array(t.colorsCompressed),h.STATIC_DRAW):b(e.colors.compileBuffer(Uint8Array),h.DYNAMIC_DRAW),y=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);u||n.forEach((e=>{if(e.retainedGeometry){const t=3*e.portionBase;e.retainedGeometry.quantizedPositions=F.subarray(t,t+3*e.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)}}}();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{edgesColorOpaqueAllowed:()=>!0,solid:Q,sortId:("points"===A?"Points":"lines"===A?"Lines":"Triangles")+(u?"Instancing":"Batching")+"Layer"+("points"!==A&&"lines"!==A?(Q?"-solid":"-surface")+"-autoNormals"+(u?"":(o&&o.colorTexture?"-colorTexture":"")+(o&&o.metallicRoughnessTexture?"-metallicRoughnessTexture":"")):""),setClippableFlags:k,setFlags:k,setFlags2:(e,t,s)=>{},setDeferredFlags:()=>{D&&(_.setData(D),D=null)},setColor:(e,t)=>{if(B){const s=n[e],i=qi.getTypeArray(Uint8Array,4*s.portionSize);$i(i,t.slice(0,4)),B.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(y){Oi.set(t);const e=qi.getTypeArray(Float32Array,3*s.portionSize);$i(e,Oi),y.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;R.mulMat4v4(n,e,e);const 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.mulMat4v4(n,o,o),R.addVec3(e,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=Wi,p=zi,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],B=3*n[i+1],y=3*n[i+2];if(d[0]=e[b],d[1]=e[b+1],d[2]=e[b+2],p[0]=e[B],p[1]=e[B+1],p[2]=e[B+2],f[0]=e[y],f[1]=e[y+1],f[2]=e[y+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,B),s(i.pickColor,v),s(i.uV,S&&S.buf),s(i.metallicRoughness,w),s(i.flags,_),s(i.offset,y),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 B=[];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.");B.push({data:r,width:s,height:i})}return c(),{width:u,height:d,hasAlpha:f,mipmaps:B,format:b,dfdTransferFn:g,dfdFlags:m}}(c.buffers[0]),g=[];for(let e=0;e<u.length;++e)g.push(u[e].data.buffer);self.postMessage({type:"transcode",id:c.id,width:t,height:A,hasAlpha:h,mipmaps:u,format:d,dfdTransferFn: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