@xeokit/xeokit-sdk 2.6.93 → 2.6.94

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.93
3
- * Commit: 00a09510b0b8d1b5f72f56ee2cefec7f33616748
4
- * Built: 2025-10-20T10:22:18.716Z
2
+ * xeokit-sdk v2.6.94
3
+ * Commit: 32b1b9841f49a7817cfc809cbbee180486784356
4
+ * Built: 2025-11-03T13:06:26.987Z
5
5
  */
6
6
 
7
- "undefined"!=typeof window&&(window.__XEOKIT__={version:"2.6.93",commit:"00a09510b0b8d1b5f72f56ee2cefec7f33616748",built:"2025-10-20T10:22:18.716Z"}),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}}let n=!0,A=n?Float64Array:Float32Array;const o=new A(3),a=new A(16),l=new A(16),c=new A(4),h={setDoublePrecisionEnabled(e){n=e,A=n?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>n,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 A(e||2),vec3:e=>new A(e||3),vec4:e=>new A(e||4),mat3:e=>new A(e||9),mat3ToMat4:(e,t=new A(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 A(e||16),mat4ToMat3:(e,t=new A(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 A(2);for(let r=0,n=e.length;r<n;r++)h.splitDouble(e[r],i),t[r]=i[0],s[r]=i[1]},splitDouble(e,t){const s=A.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 A(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=>h.dotVec4(e,e),lenVec4:e=>Math.sqrt(h.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=>h.dotVec3(e,e),sqLenVec2:e=>h.dotVec2(e,e),lenVec3:e=>Math.sqrt(h.sqLenVec3(e)),distVec3:(()=>{const e=new A(3);return(t,s)=>h.lenVec3(h.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(h.sqLenVec2(e)),distVec2:(()=>{const e=new A(2);return(t,s)=>h.lenVec2(h.subVec2(t,s,e))})(),rcpVec3:(e,t)=>h.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/h.lenVec4(e);return h.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/h.lenVec3(e);return h.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/h.lenVec2(e);return h.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=h.dotVec3(e,t)/Math.sqrt(h.sqLenVec3(e)*h.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new A(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=h.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=h.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=h.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||h.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:()=>h.m4s(0),setMat4ToOnes:()=>h.m4s(1),diagonalMat4v:e=>new A([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)=>h.diagonalMat4v([e,t,s,i]),diagonalMat4s:e=>h.diagonalMat4c(e,e,e,e),identityMat4:(e=new A(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 A(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)=>h.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 A(9));const i=e[0],r=e[3],n=e[6],o=e[1],a=e[4],l=e[7],c=e[2],h=e[5],u=e[8],d=t[0],p=t[3],f=t[6],g=t[1],m=t[4],_=t[7],b=t[2],B=t[5],y=t[8];return s[0]=i*d+r*g+n*b,s[3]=i*p+r*m+n*B,s[6]=i*f+r*_+n*y,s[1]=o*d+a*g+l*b,s[4]=o*p+a*m+l*B,s[7]=o*f+a*_+l*y,s[2]=c*d+h*g+u*b,s[5]=c*p+h*m+u*B,s[8]=c*f+h*_+u*y,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=h.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||h.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||h.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new A(3);return(t,s,i,r)=>(e[0]=t,e[1]=s,e[2]=i,h.translationMat4v(e,r))})(),translationMat4s:(e,t)=>h.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>h.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=h.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,u,d,p,f,g;return c=o*a,u=a*l,d=l*o,p=o*r,f=a*r,g=l*r,(s=s||h.mat4())[0]=A*o*o+n,s[1]=A*c+g,s[2]=A*d-f,s[3]=0,s[4]=A*c-g,s[5]=A*a*a+n,s[6]=A*u+p,s[7]=0,s[8]=A*d+f,s[9]=A*u-p,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)=>h.rotationMat4v(e,[t,s,i],r),scalingMat4v:(e,t=h.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=h.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new A(3);return(t,s,i,r)=>(e[0]=t,e[1]=s,e[2]=i,h.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=>h.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=h.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,u=i*a,d=i*l,p=r*a,f=r*l,g=n*l,m=A*o,_=A*a,b=A*l;return s[0]=1-(p+g),s[1]=u+b,s[2]=d-_,s[3]=0,s[4]=u-b,s[5]=1-(c+g),s[6]=f+m,s[7]=0,s[8]=d+_,s[9]=f-m,s[10]=1-(c+p),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=h.vec4()){const i=h.clamp,r=e[0],n=e[4],A=e[8],o=e[1],a=e[5],l=e[9],c=e[2],u=e[6],d=e[10];return"XYZ"===t?(s[1]=Math.asin(i(A,-1,1)),Math.abs(A)<.99999?(s[0]=Math.atan2(-l,d),s[2]=Math.atan2(-n,r)):(s[0]=Math.atan2(u,a),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-i(l,-1,1)),Math.abs(l)<.99999?(s[1]=Math.atan2(A,d),s[2]=Math.atan2(o,a)):(s[1]=Math.atan2(-c,r),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(i(u,-1,1)),Math.abs(u)<.99999?(s[1]=Math.atan2(-c,d),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(u,d),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,d))):"XZY"===t&&(s[2]=Math.asin(-i(n,-1,1)),Math.abs(n)<.99999?(s[0]=Math.atan2(u,a),s[1]=Math.atan2(A,r)):(s[0]=Math.atan2(-l,d),s[1]=0)),s[0]*=h.RADTODEG,s[1]*=h.RADTODEG,s[2]*=h.RADTODEG,s},composeMat4:(e,t,s,i=h.mat4())=>(h.quaternionToRotationMat4(t,i),h.scaleMat4v(s,i),h.translateMat4v(e,i),i),decomposeMat4:(()=>{const e=new A(3),t=new A(16);return function(s,i,r,n){e[0]=s[0],e[1]=s[1],e[2]=s[2];let A=h.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const o=h.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const a=h.lenVec3(e);h.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,u=1/a;return t[0]*=l,t[1]*=l,t[2]*=l,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=u,t[9]*=u,t[10]*=u,h.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=h.mat4());const r=e[0],n=e[1],A=e[2],o=s[0],a=s[1],l=s[2],c=t[0],u=t[1],d=t[2];if(r===c&&n===u&&A===d)return h.identityMat4();let p,f,g,m,_,b,B,y,w,v;return p=r-c,f=n-u,g=A-d,v=1/Math.sqrt(p*p+f*f+g*g),p*=v,f*=v,g*=v,m=a*g-l*f,_=l*p-o*g,b=o*f-a*p,v=Math.sqrt(m*m+_*_+b*b),v?(v=1/v,m*=v,_*=v,b*=v):(m=0,_=0,b=0),B=f*b-g*_,y=g*m-p*b,w=p*_-f*m,v=Math.sqrt(B*B+y*y+w*w),v?(v=1/v,B*=v,y*=v,w*=v):(B=0,y=0,w=0),i[0]=m,i[1]=B,i[2]=p,i[3]=0,i[4]=_,i[5]=y,i[6]=f,i[7]=0,i[8]=b,i[9]=w,i[10]=g,i[11]=0,i[12]=-(m*r+_*n+b*A),i[13]=-(B*r+y*n+w*A),i[14]=-(p*r+f*n+g*A),i[15]=1,i},lookAtMat4c:(e,t,s,i,r,n,A,o,a)=>h.lookAtMat4v([e,t,s],[i,r,n],[A,o,a],[]),orthoMat4c(e,t,s,i,r,n,A){A||(A=h.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=h.mat4());const i=[e[0],e[1],e[2],0],r=[t[0],t[1],t[2],0];h.addVec4(r,i,a),h.subVec4(r,i,l);const n=2*i[2],A=l[0],o=l[1],c=l[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]=a[0]/A,s[9]=a[1]/o,s[10]=-a[2]/c,s[11]=-1,s[12]=0,s[13]=0,s[14]=-n*r[2]/c,s[15]=0,s},frustumMat4(e,t,s,i,r,n,A){A||(A=h.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],h.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=h.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=h.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||h.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||h.vec2())[0]=e[0]*s,t[1]=e[1]*s,t},unprojectVec3:(()=>{const e=new A(16),t=new A(16),s=new A(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||h.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||h.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=h.vec4())=>(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=h.vec4()){const i=e[0]*h.DEGTORAD/2,r=e[1]*h.DEGTORAD/2,n=e[2]*h.DEGTORAD/2,A=Math.cos(i),o=Math.cos(r),a=Math.cos(n),l=Math.sin(i),c=Math.sin(r),u=Math.sin(n);return"XYZ"===t?(s[0]=l*o*a+A*c*u,s[1]=A*c*a-l*o*u,s[2]=A*o*u+l*c*a,s[3]=A*o*a-l*c*u):"YXZ"===t?(s[0]=l*o*a+A*c*u,s[1]=A*c*a-l*o*u,s[2]=A*o*u-l*c*a,s[3]=A*o*a+l*c*u):"ZXY"===t?(s[0]=l*o*a-A*c*u,s[1]=A*c*a+l*o*u,s[2]=A*o*u+l*c*a,s[3]=A*o*a-l*c*u):"ZYX"===t?(s[0]=l*o*a-A*c*u,s[1]=A*c*a+l*o*u,s[2]=A*o*u-l*c*a,s[3]=A*o*a+l*c*u):"YZX"===t?(s[0]=l*o*a+A*c*u,s[1]=A*c*a+l*o*u,s[2]=A*o*u-l*c*a,s[3]=A*o*a-l*c*u):"XZY"===t&&(s[0]=l*o*a-A*c*u,s[1]=A*c*a-l*o*u,s[2]=A*o*u+l*c*a,s[3]=A*o*a+l*c*u),s},mat4ToQuaternion(e,t=h.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 u;const d=s+A+c;return d>0?(u=.5/Math.sqrt(d+1),t[3]=.25/u,t[0]=(l-o)*u,t[1]=(r-a)*u,t[2]=(n-i)*u):s>A&&s>c?(u=2*Math.sqrt(1+s-A-c),t[3]=(l-o)/u,t[0]=.25*u,t[1]=(i+n)/u,t[2]=(r+a)/u):A>c?(u=2*Math.sqrt(1+A-s-c),t[3]=(r-a)/u,t[0]=(i+n)/u,t[1]=.25*u,t[2]=(o+l)/u):(u=2*Math.sqrt(1+c-s-A),t[3]=(n-i)/u,t[0]=(r+a)/u,t[1]=(o+l)/u,t[2]=.25*u),t},vec3PairToQuaternion(e,t,s=h.vec4()){const i=Math.sqrt(h.dotVec3(e,e)*h.dotVec3(t,t));let r=i+h.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])):h.cross3Vec3(e,t,s),s[3]=r,h.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=h.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 A(16);return(t,s,i)=>(i=i||h.vec3(),h.quaternionToRotationMat4(t,e),h.mat4ToEuler(e,s,i),i)})(),mulQuaternions(e,t,s=h.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=h.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,u=l*r+a*i-A*n,d=l*n+A*r-o*i,p=-A*i-o*r-a*n;return s[0]=c*l+p*-A+u*-a-d*-o,s[1]=u*l+p*-o+d*-A-c*-a,s[2]=d*l+p*-a+c*-o-u*-A,s},quaternionToMat4(e,t){t=h.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,u=a*n,d=A*s,p=o*s,f=a*s,g=o*i,m=a*i,_=a*r;return t[0]=1-(g+_),t[1]=p+u,t[2]=f-c,t[4]=p-u,t[5]=1-(d+_),t[6]=m+l,t[8]=f+c,t[9]=m-l,t[10]=1-(d+g),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=h.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)=>h.normalizeQuaternion(h.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=h.vec4()){const s=(e=h.normalizeQuaternion(e,c))[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 A(e||6),AABB2:e=>new A(e||4),OBB3:e=>new A(e||32),OBB2:e=>new A(e||16),Sphere3:(e,t,s,i)=>new A([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 A(3),t=new A(3),s=new A(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],h.subVec3(t,e,s),Math.abs(h.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new A(3),t=new A(3),s=new A(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=h.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],u=i[5]-r[2];return n[0]+=A>o?A:o,n[1]+=a>l?a:l,n[2]+=c>u?c:u,Math.abs(h.lenVec3(n))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||h.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||h.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=h.AABB3())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MAX_DOUBLE,e[3]=h.MIN_DOUBLE,e[4]=h.MIN_DOUBLE,e[5]=h.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=h.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 A(3);return(t,s,i)=>{s=s||h.AABB3();let r,n,A,o=h.MAX_DOUBLE,a=h.MAX_DOUBLE,l=h.MAX_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE,d=h.MIN_DOUBLE;for(let s=0,p=t.length;s<p;s+=3)i?(e[0]=t[s+0],e[1]=t[s+1],e[2]=t[s+2],h.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>u&&(u=n),A>d&&(d=A);return s[0]=o,s[1]=a,s[2]=l,s[3]=c,s[4]=u,s[5]=d,s}})(),OBB3ToAABB3(e,t=h.AABB3()){let s,i,r,n=h.MAX_DOUBLE,A=h.MAX_DOUBLE,o=h.MAX_DOUBLE,a=h.MIN_DOUBLE,l=h.MIN_DOUBLE,c=h.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=h.AABB3()){let s,i,r,n=h.MAX_DOUBLE,A=h.MAX_DOUBLE,o=h.MAX_DOUBLE,a=h.MIN_DOUBLE,l=h.MIN_DOUBLE,c=h.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 A(3);return(t,s)=>{s=s||h.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(h.lenVec3(h.subVec3(t[i],s,e))),a>l&&(l=a);return s[3]=l,s}})(),positions3ToSphere3:(()=>{const e=new A(3),t=new A(3);return(s,i)=>{i=i||h.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 u;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],u=Math.abs(h.lenVec3(h.subVec3(e,i,t))),u>l&&(l=u);return i[3]=l,i}})(),OBB3ToSphere3:(()=>{const e=new A(3),t=new A(3);return(s,i)=>{i=i||h.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,u=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(h.lenVec3(h.subVec3(e,i,t))),c>u&&(u=c);return i[3]=u,i}})(),getSphere3Center:(e,t=h.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=h.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=h.AABB2())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MIN_DOUBLE,e[3]=h.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=h.AABB2()){let s,i,r,n,A=h.MAX_DOUBLE,o=h.MAX_DOUBLE,a=h.MIN_DOUBLE,l=h.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=h.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,u=A*o-r*l,d=r*a-n*o,p=Math.sqrt(c*c+u*u+d*d);return 0===p?(i[0]=0,i[1]=0,i[2]=0):(i[0]=c/p,i[1]=u/p,i[2]=d/p),i},rayTriangleIntersect:(()=>{const e=new A(3),t=new A(3),s=new A(3),i=new A(3),r=new A(3);return(n,A,o,a,l,c)=>{c=c||h.vec3();const u=h.subVec3(a,o,e),d=h.subVec3(l,o,t),p=h.cross3Vec3(A,d,s),f=h.dotVec3(u,p);if(f<1e-6)return null;const g=h.subVec3(n,o,i),m=h.dotVec3(g,p);if(m<0||m>f)return null;const _=h.cross3Vec3(g,u,r),b=h.dotVec3(A,_);if(b<0||m+b>f)return null;const B=h.dotVec3(d,_)/f;return c[0]=n[0]+B*A[0],c[1]=n[1]+B*A[1],c[2]=n[2]+B*A[2],c}})(),rayPlaneIntersect:(()=>{const e=new A(3),t=new A(3),s=new A(3),i=new A(3);return(r,n,A,o,a,l)=>{l=l||h.vec3(),n=h.normalizeVec3(n,e);const c=h.subVec3(o,A,t),u=h.subVec3(a,A,s),d=h.cross3Vec3(c,u,i);h.normalizeVec3(d,d);const p=-h.dotVec3(A,d),f=-(h.dotVec3(r,d)+p)/h.dotVec3(n,d);return l[0]=r[0]+f*n[0],l[1]=r[1]+f*n[1],l[2]=r[2]+f*n[2],l}})(),cartesianToBarycentric:(()=>{const e=new A(3),t=new A(3),s=new A(3);return(i,r,n,A,o)=>{const a=h.subVec3(A,r,e),l=h.subVec3(n,r,t),c=h.subVec3(i,r,s),u=h.dotVec3(a,a),d=h.dotVec3(a,l),p=h.dotVec3(a,c),f=h.dotVec3(l,l),g=h.dotVec3(l,c),m=u*f-d*d;if(0===m)return null;const _=1/m,b=(f*p-d*g)*_,B=(u*g-d*p)*_;return o[0]=1-b-B,o[1]=B,o[2]=b,o}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,i,r=h.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 A(3),t=new A(3),s=new A(3),i=new A(3),r=new A(3),n=new A(3);return(A,o,a)=>{let l,c;const u=new Array(A.length/3);let d,p,f,g,m,_,b;for(l=0,c=o.length;l<c;l+=3){d=o[l],p=o[l+1],f=o[l+2],e[0]=A[3*d],e[1]=A[3*d+1],e[2]=A[3*d+2],t[0]=A[3*p],t[1]=A[3*p+1],t[2]=A[3*p+2],s[0]=A[3*f],s[1]=A[3*f+1],s[2]=A[3*f+2],h.subVec3(t,e,i),h.subVec3(s,e,r);const a=h.vec3();h.normalizeVec3(h.cross3Vec3(i,r,n),a),u[d]||(u[d]=[]),u[p]||(u[p]=[]),u[f]||(u[f]=[]),u[d].push(a),u[p].push(a),u[f].push(a)}for(a=a&&a.length===A.length?a:new Float32Array(A.length),l=0,c=u.length;l<c;l++){g=u[l].length,m=0,_=0,b=0;for(let e=0;e<g;e++)m+=u[l][e][0],_+=u[l][e][1],b+=u[l][e][2];a[3*l]=m/g,a[3*l+1]=_/g,a[3*l+2]=b/g}return a}})(),buildTangents:(()=>{const e=new A(3),t=new A(3),s=new A(3),i=new A(3),r=new A(3),n=new A(3),o=new A(3);return(A,a,l)=>{const c=new Float32Array(A.length);for(let u=0;u<a.length;u+=3){let d=a[u];const p=A.subarray(3*d,3*d+3),f=l.subarray(2*d,2*d+2);d=a[u+1];const g=A.subarray(3*d,3*d+3),m=l.subarray(2*d,2*d+2);d=a[u+2];const _=A.subarray(3*d,3*d+3),b=l.subarray(2*d,2*d+2),B=h.subVec3(g,p,e),y=h.subVec3(_,p,t),w=h.subVec2(m,f,s),v=h.subVec2(b,f,i),C=1/(w[0]*v[1]-w[1]*v[0]),M=h.mulVec3Scalar(h.subVec3(h.mulVec3Scalar(B,v[1],r),h.mulVec3Scalar(y,w[1],n),o),C,n);let E;for(let e=0;e<3;e++)E=3*a[u+e],c[E]+=M[0],c[E+1]+=M[1],c[E+2]+=M[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,u;const d=1e4;let p,f,g,m,_,b;for(f=0,m=e.length;f<m;f+=3){p=f/3,a=e[f],l=e[f+1],c=e[f+2],u=`${Math.round(a*d)}_${Math.round(l*d)}_${Math.round(c*d)}`,void 0===r[u]?r[u]=[p]:r[u].push(p);const s=h.normalizeVec3([t[f],t[f+1],t[f+2]]);n[p]=s,o=h.vec4([s[0],s[1],s[2],1]),A[p]=o}for(u in r)if(r.hasOwnProperty(u)){const e=r[u],t=e.length;for(f=0;f<t;f++){const s=e[f];for(o=A[s],g=0;g<t;g++){if(f===g)continue;const t=e[g];_=n[s],b=n[t];Math.abs(h.angleVec3(_,b)/h.DEGTORAD)<i&&(o[0]+=b[0],o[1]+=b[1],o[2]+=b[2],o[3]+=1)}}}for(f=0,m=t.length;f<m;f+=3)o=A[f/3],t[f+0]=o[0]/o[3],t[f+1]=o[1]/o[3],t[f+2]=o[2]/o[3]},transformRay:(()=>{const e=new A(4),t=new A(4);return(s,i,r,n,A)=>{e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=1,h.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],h.transformVec3(s,e,t),h.normalizeVec3(t),A[0]=t[0],A[1]=t[1],A[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new A(16),t=new A(4),s=new A(4),i=(t,s,i,r,n)=>{n[0]=t,n[1]=s,n[2]=i,n[3]=1,h.transformVec4(e,n,n),r||h.mulVec4Scalar(n,1/n[3])};return(r,n,A,o,a,l,c)=>{const u="ortho"===o;h.mulMat4(A,n,e),h.inverseMat4(e,e);const d=2*a[0]/r.clientWidth-1,p=1-2*a[1]/r.clientHeight;i(d,p,-1,u,t),i(d,p,1,u,s),l[0]=t[0],l[1]=t[1],l[2]=t[2],h.subVec3(s,t,c),h.normalizeVec3(c)}})(),canvasPosToLocalRay:(()=>{const e=new A(3),t=new A(3);return(s,i,r,n,A,o,a,l)=>{h.canvasPosToWorldRay(s,i,r,n,o,e,t),h.worldRayToLocalRay(A,e,t,a,l)}})(),worldRayToLocalRay:(()=>{const e=new A(16),t=new A(4),s=new A(4);return(i,r,n,A,o)=>{const a=h.inverseMat4(i,e);t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,h.transformVec4(a,t,s),A[0]=s[0],A[1]=s[1],A[2]=s[2],h.transformVec3(a,n,o)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,i,r,n){const o=new A(6),a={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:o};let l,c;for(o[0]=o[1]=o[2]=Number.POSITIVE_INFINITY,o[3]=o[4]=o[5]=Number.NEGATIVE_INFINITY,l=0,c=s.length;l<c;++l){var h=3*s[l];for(let e=0;e<3;++e){const t=3*i[h+e];r[t]<o[0]&&(o[0]=r[t]),r[t]>o[3]&&(o[3]=r[t]),r[t+1]<o[1]&&(o[1]=r[t+1]),r[t+1]>o[4]&&(o[4]=r[t+1]),r[t+2]<o[2]&&(o[2]=r[t+2]),r[t+2]>o[5]&&(o[5]=r[t+2])}}if(s.length<20||n>10)return a.triangles=s,a.leaf=!0,a;e[0]=o[3]-o[0],e[1]=o[4]-o[1],e[2]=o[5]-o[2];let u=0;e[1]>e[u]&&(u=1),e[2]>e[u]&&(u=2),a.splitDim=u;const d=(o[u]+o[u+3])/2,p=new Array(s.length);let f=0;const g=new Array(s.length);let m=0;for(l=0,c=s.length;l<c;++l){const e=i[h=3*s[l]],t=3*i[h+1],n=3*i[h+2];r[3*e+u]<=d||r[t+u]<=d||r[n+u]<=d?p[f++]=s[l]:g[m++]=s[l]}return p.length=f,g.length=m,a.left=t(p,i,r,n+1),a.right=t(g,i,r,n+1),a}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}};h.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=h.vec3(),c=h.vec3(),u=h.vec3(),d=h.vec3(),p=h.vec3(),f=h.vec3(),g=h.vec3();return function(m,_,b,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]}(m,_),function(t,s){n=0;for(let m=0,_=t;m<_;m+=3){const t=3*i[m],_=3*i[m+1],b=3*i[m+2];s?(A[0]=e[t],A[1]=e[t+1],A[2]=e[t+2],o[0]=e[_],o[1]=e[_+1],o[2]=e[_+2],a[0]=e[b],a[1]=e[b+1],a[2]=e[b+2],h.decompressPosition(A,s,l),h.decompressPosition(o,s,c),h.decompressPosition(a,s,u)):(l[0]=e[t],l[1]=e[t+1],l[2]=e[t+2],c[0]=e[_],c[1]=e[_+1],c[2]=e[_+2],u[0]=e[b],u[1]=e[b+1],u[2]=e[b+2]),h.subVec3(u,c,d),h.subVec3(l,c,p),h.cross3Vec3(d,p,f),h.normalizeVec3(f,g);const B=r[n]||(r[n]={normal:h.vec3()});B.normal[0]=g[0],B.normal[1]=g[1],B.normal[2]=g[2],n++}}(_.length,b);const y=[],w=Math.cos(h.DEGTORAD*B),v={};let C,M,E,F,x,U,I,T,P,S,D,k=!1;for(let e=0,t=_.length;e<t;e+=3){const t=e/3;for(let s=0;s<3;s++)C=i[e+s],M=i[e+(s+1)%3],E=Math.min(C,M),F=Math.max(C,M),x=E+","+F,void 0===v[x]?v[x]={index1:E,index2:F,face1:t,face2:void 0}:v[x].face2=t}for(x in v)U=v[x],void 0!==U.face2&&(I=r[U.face1].normal,T=r[U.face2].normal,P=h.dotVec3(I,T),P>w)||(S=s[U.index1],D=s[U.index2],(!k&&S>65535||D>65535)&&(k=!0),y.push(S),y.push(D));return k?new Uint32Array(y):new Uint16Array(y)}}(),h.planeClipsPositions3=function(e,t,s,i=3){for(let r=0,n=s.length;r<n;r+=i){if(o[0]=s[r+0]-e[0],o[1]=s[r+1]-e[1],o[2]=s[r+2]-e[2],o[0]*t[0]+o[1]*t[1]+o[2]*t[2]<0)return!0}return!1};const u=new Float32Array(3);class d{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 p={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 f=[["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 g(e,t){return(t&&4!==t?[0,6]:[0,6,12,18]).map((function(t){return f.substr(parseInt(e/(1<<t))%64,1)})).reverse().join("")}const m=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 _={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 g(t[0],2)+[1,4,7,10,13].map((function(e){return g((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);F.scheduleTask((()=>{t(e)}))}catch(e){F.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:m,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 _.isString(e)||_.isNumeric(e)},isSameComponent:function(e,t){return!(!e||!t)&&(_.isNumeric(e)||_.isString(e)?`${e}`:e.id)===(_.isNumeric(t)||_.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 _.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 _.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}},b={},B=new e,y=new d,w={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},v=[];let C,M=0,E=0;const F=new function(){this.version="1.0.0",this.scenes={},this._superTypes={},this._addScene=function(e){if(e.id){if(F.scenes[e.id])return void console.error(`[ERROR] Scene ${_.inQuotes(e.id)} already exists`)}else e.id=B.addItem({});F.scenes[e.id]=e;const t=e.ticksPerOcclusionTest,s=e.ticksPerRender;b[e.id]={ticksPerOcclusionTest:t,ticksPerRender:s,renderCountdown:s},p.components.scenes++,e.once("destroyed",(()=>{B.removeItem(e.id),delete F.scenes[e.id],delete b[e.id],p.components.scenes--}))},this.clear=function(){let e;for(const t in F.scenes)F.scenes.hasOwnProperty(t)&&(e=F.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete F.scenes[e.id]))},this.scheduleTask=function(e,t=null){y.push(e),y.push(t)},this.runTasks=function(e=-1){let t,s,i=(new Date).getTime(),r=0;for(;y.length>0&&(e<0||i<e);)t=y.shift(),s=y.shift(),s?t.call(s):t(),i=(new Date).getTime(),r++;return r},this.getNumTasks=function(){return y.length}},x=function(){let e=Date.now();if(C=e-M,M>0&&C>0){var t=1e3/C;E+=t,v.push(t),v.length>=30&&(E-=v.shift()),p.frame.fps=Math.round(E/v.length)}for(let e in F.scenes)F.scenes[e].compile();I(e),M=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))})()}((()=>{x()}),100);const U=function(){let e=Date.now();if(C=e-M,M>0&&C>0){var t=1e3/C;E+=t,v.push(t),v.length>=30&&(E-=v.shift()),p.frame.fps=Math.round(E/v.length)}I(e),function(e){for(var t in w.time=e,F.scenes)if(F.scenes.hasOwnProperty(t)){var s=F.scenes[t];w.sceneId=t,w.startTime=s.startTime,w.deltaTime=null!=w.prevTime?w.time-w.prevTime:0,s.fire("tick",w,!0)}w.prevTime=e}(e),function(){const e=F.scenes,t=!1;let s,i,r,n,A;for(A in e)e.hasOwnProperty(A)&&(s=e[A],i=b[A],i||(i=b[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(x):requestAnimationFrame(U)};function I(e){const t=F.runTasks(e+10),s=F.getNumTasks();p.frame.tasksRun=t,p.frame.tasksScheduled=s,p.frame.tasksBudget=10}U();class T{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 T))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+" "+_.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&&(_.isNumeric(s)||_.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+_.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+" "+_.inQuotes(s.id));if(n&&!s.isType(n))return void this.error("Expected a "+n+" type or subtype: "+s.type+" "+_.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&&(_.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&&(_.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],_.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(!_.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(!_.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():F.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}scheduleTask(e){F.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 P=h.vec3(),S=h.vec3(),D=h.mat4();class k{constructor(){this.normal=h.vec3(),this.offset=0,this.testVertex=h.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 Q{constructor(){this.planes=[new k,new k,new k,new k,new k,new k]}}function R(e,t,s){const i=h.mulMat4(s,t,D),r=i[0],n=i[1],A=i[2],o=i[3],a=i[4],l=i[5],c=i[6],u=i[7],d=i[8],p=i[9],f=i[10],g=i[11],m=i[12],_=i[13],b=i[14],B=i[15];e.planes[0].set(o-r,u-a,g-d,B-m),e.planes[1].set(o+r,u+a,g+d,B+m),e.planes[2].set(o-n,u-l,g-p,B-_),e.planes[3].set(o+n,u+l,g+p,B+_),e.planes[4].set(o-A,u-c,g-f,B-b),e.planes[5].set(o+A,u+c,g+f,B+b)}function O(e,t){let s=Q.INSIDE;const i=P,r=S;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 Q.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=Q.INTERSECT)}return s}Q.INSIDE=0,Q.INTERSECT=1,Q.OUTSIDE=2;class V extends T{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=h.vec2(),this._canvasMarqueeCorner2=h.vec2(),this._canvasMarquee=h.AABB2(),this._marqueeFrustum=new Q,this._marqueeFrustumProjMat=h.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!==V.PICK_MODE_INSIDE&&e!==V.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===V.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=Q.INTERSECT)=>{if(i===Q.INTERSECT&&(i=O(this._marqueeFrustum,s.aabb)),i!==Q.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===V.PICK_MODE_INSIDE){O(this._marqueeFrustum,r)===Q.INSIDE&&e.push(i.id)}else{O(this._marqueeFrustum,r)!==Q.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,u=-(this._canvasMarquee[1]-r)*A+1,d=this.viewer.scene.camera.frustum.near*(17*o);h.frustumMat4(a,l,c*o,u*o,d,1e4,this._marqueeFrustumProjMat),R(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)}}V.PICK_MODE_INTERSECTS=0,V.PICK_MODE_INSIDE=1;class L{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 H{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=N(e,s);return i?t?G(i,t):i:null}translatePlurals(e,t,s){const i=this._messages[this._locale];if(!i)return null;let r=N(e,i);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=G(r,[t]),s&&(r=G(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 N(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 G(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,s){return"{{"===e?"{":"}}"===e?"}":t[s]}))}class j extends T{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=h.subVec3(n,r,[]);return h.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+=h.lenVec3(h.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 W extends j{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=h.vec3();return l[0]=h.catmullRomInterpolate(n[0],A[0],o[0],a[0],r),l[1]=h.catmullRomInterpolate(n[1],A[1],o[1],a[1],r),l[2]=h.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 z=h.vec3();const X=h.vec3(),K=h.vec3(),Z=h.vec3(),J=h.vec3(),Y=h.vec3();class $ extends T{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.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((_.isNumeric(i)||_.isString(i))&&(l=i,i=this.scene.components[l],!i))return this.error("Component not found: "+_.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=h.getAABB3Center(n);this._look2=c||t;const s=h.subVec3(this._eye1,this._look1,X),i=h.normalizeVec3(s),r=c?h.getAABB3DiagPoint(n,c):h.getAABB3Diag(n),A=e.fitFOV||this._fitFOV,o=Math.abs(r/Math.tan(A*h.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,F.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((_.isNumeric(t)||_.isString(t))&&(i=t,t=this.scene.components[i],!t))return void this.error("Component not found: "+_.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?h.getAABB3DiagPoint(s,o):h.getAABB3Diag(s);let i;n=o||h.getAABB3Center(s,n),this._trail?h.subVec3(t.look,n,Y):h.subVec3(t.eye,t.look,Y),h.normalizeVec3(Y);i=(void 0!==e.fit?e.fit:this._fit)?Math.abs(a/Math.tan((e.fitFOV||this._fitFOV)*h.DEGTORAD)):h.lenVec3(h.subVec3(t.eye,t.look,X)),h.mulVec3Scalar(Y,i),t.eye=h.addVec3(n,Y,X),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?$._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(i.eye,i.look,Y),i.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,Z),i.look=h.subVec3(Z,Y,K)):this._flyingLook&&(i.look=h.lerpVec3(s,0,1,this._look1,this._look2,K),i.up=h.lerpVec3(s,0,1,this._up1,this._up2,J)):this._flyingEyeLookUp&&(i.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,Z),i.look=h.lerpVec3(s,0,1,this._look1,this._look2,K),i.up=h.lerpVec3(s,0,1,this._up1,this._up2,J)),this._projection2){const t="ortho"===this._projection2?$._easeOutExpo(e,0,1,1):$._easeInCubic(e,0,1,1);i.customProjection.matrix=h.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();F.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 q extends T{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new $(this),this._t=0,this.state=q.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 q.SCRUBBING:return;case q.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=q.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case q.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=q.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=q.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=q.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=q.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=q.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=q.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=q.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}q.STOPPED=0,q.SCRUBBING=1,q.PLAYING=2,q.PLAYING_TO=3;class ee extends T{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),p.memory.meshes++}destroy(){super.destroy(),p.memory.meshes--}}const te=new e({});class se{constructor(e){this.id=te.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){te.removeItem(this.id)}}class ie{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 re=function(){const e=[],t=[],s=[],i=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=h.vec3(),c=h.vec3(),u=h.vec3(),d=h.vec3(),p=h.vec3(),f=h.vec3(),g=h.vec3();return function(m,_,b,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]}(m,_),function(t,s){n=0;for(let m=0,_=t;m<_;m+=3){const t=3*i[m],_=3*i[m+1],b=3*i[m+2];s?(A[0]=e[t],A[1]=e[t+1],A[2]=e[t+2],o[0]=e[_],o[1]=e[_+1],o[2]=e[_+2],a[0]=e[b],a[1]=e[b+1],a[2]=e[b+2],h.decompressPosition(A,s,l),h.decompressPosition(o,s,c),h.decompressPosition(a,s,u)):(l[0]=e[t],l[1]=e[t+1],l[2]=e[t+2],c[0]=e[_],c[1]=e[_+1],c[2]=e[_+2],u[0]=e[b],u[1]=e[b+1],u[2]=e[b+2]),h.subVec3(u,c,d),h.subVec3(l,c,p),h.cross3Vec3(d,p,f),h.normalizeVec3(f,g);const B=r[n]||(r[n]={normal:h.vec3()});B.normal[0]=g[0],B.normal[1]=g[1],B.normal[2]=g[2],n++}}(_.length,b);const y=[],w=Math.cos(h.DEGTORAD*B),v={};let C,M,E,F,x,U,I,T,P,S,D,k=!1;for(let e=0,t=_.length;e<t;e+=3){const t=e/3;for(let s=0;s<3;s++)C=i[e+s],M=i[e+(s+1)%3],E=Math.min(C,M),F=Math.max(C,M),x=E+","+F,void 0===v[x]?v[x]={index1:E,index2:F,face1:t,face2:void 0}:v[x].face2=t}for(x in v)U=v[x],void 0!==U.face2&&(I=r[U.face1].normal,T=r[U.face2].normal,P=h.dotVec3(I,T),P>w)||(S=s[U.index1],D=s[U.index2],(!k&&S>65535||D>65535)&&(k=!0),y.push(S),y.push(D));return k?new Uint32Array(y):new Uint16Array(y)}}();const ne=function(){const e=h.mat4(),t=h.mat4();return function(s,i){i=i||h.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 h.identityMat4(e),h.translationMat4v(s,e),h.identityMat4(t),h.scalingMat4v([o/c,a/c,l/c],t),h.mulMat4(e,t,i),i}}();var Ae=function(){const e=h.mat4(),t=h.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])));h.identityMat4(e),h.translationMat4v(i,e),h.identityMat4(t),h.scalingMat4v([(r[0]-i[0])/65535,(r[1]-i[1])/65535,(r[2]-i[2])/65535],t);return{quantized:n,decodeMatrix:h.mulMat4(e,t,h.identityMat4())}}}();var oe=function(){const e=h.mat3(),t=h.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])));h.identityMat3(e),h.translationMat3v(i,e),h.identityMat3(t),h.scalingMat3v([(r[0]-i[0])/65535,(r[1]-i[1])/65535],t);return{quantized:n,decodeMatrix:h.mulMat3(e,t,h.identityMat3())}}}();function ae(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 le(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 ce(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const he={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:ne,compressPositions:Ae,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:oe,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=ae(e,o,"floor","floor"),i=le(s),n=A=ce(e,o,i),s=ae(e,o,"ceil","floor"),i=le(s),n=ce(e,o,i),n>A&&(r=s,A=n),s=ae(e,o,"floor","ceil"),i=le(s),n=ce(e,o,i),n>A&&(r=s,A=n),s=ae(e,o,"ceil","ceil"),i=le(s),n=ce(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}},ue=p.memory,de=h.AABB3();class pe extends ee{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new se({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const 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=he.getPositionsBounds(t.positions),i=he.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=he.getUVBounds(t.uv),i=he.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=he.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(),ue.meshes++,s.indices&&(s.indicesBuf=new ie(i,i.ELEMENT_ARRAY_BUFFER,s.indices,s.indices.length,1,i.STATIC_DRAW),ue.indices+=s.indicesBuf.numItems),s.positions&&(s.positionsBuf=new ie(i,i.ARRAY_BUFFER,s.positions,s.positions.length,3,i.STATIC_DRAW),ue.positions+=s.positionsBuf.numItems),s.normals){let e=s.compressGeometry;s.normalsBuf=new ie(i,i.ARRAY_BUFFER,s.normals,s.normals.length,3,i.STATIC_DRAW,e),ue.normals+=s.normalsBuf.numItems}s.colors&&(s.colorsBuf=new ie(i,i.ARRAY_BUFFER,s.colors,s.colors.length,4,i.STATIC_DRAW),ue.colors+=s.colorsBuf.numItems),s.uv&&(s.uvBuf=new ie(i,i.ARRAY_BUFFER,s.uv,s.uv.length,2,i.STATIC_DRAW),ue.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=re(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new ie(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),ue.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=h.buildPickTriangles(e.positions,e.indices,e.compressGeometry),i=s.positions,r=s.colors;this._pickTrianglePositionsBuf=new ie(t,t.ARRAY_BUFFER,i,i.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new ie(t,t.ARRAY_BUFFER,r,r.length,4,t.STATIC_DRAW,!0),ue.positions+=this._pickTrianglePositionsBuf.numItems,ue.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),he.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=he.getPositionsBounds(e),i=he.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),he.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),he.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=h.AABB3()),h.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=h.OBB3()),h.positions3ToAABB3(this._state.positions,de,this._state.positionsDecodeMatrix),h.AABB3ToOBB3(de,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=[h.vec3(),h.vec3(),h.vec3(),h.vec3()];let r=0;const n=h.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]);h.addVec3(e,A,i[3]),h.addVec3(o,i[3],i[3]);const a=h.lenVec3(h.cross3Vec3(h.subVec3(A,e,i[1]),h.subVec3(o,e,i[2]),i[0]))/2;r+=a,h.mulVec3Scalar(i[3],a,i[3]),h.addVec3(n,i[3],n)}this._metrics={surfaceArea:r,centroid:h.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(),ue.meshes--}}const fe=p.memory,ge=h.AABB3();class me extends ee{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new se({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=h.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=he.getPositionsBounds(t.positions),n=he.compressPositions(t.positions,e.min,e.max);r=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix,s.positionsBuf=new ie(i,i.ARRAY_BUFFER,r,r.length,3,i.STATIC_DRAW),fe.positions+=s.positionsBuf.numItems,h.positions3ToAABB3(t.positions,this._aabb),h.positions3ToAABB3(r,ge,s.positionsDecodeMatrix),h.AABB3ToOBB3(ge,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new ie(i,i.ARRAY_BUFFER,e,e.length,4,i.STATIC_DRAW),fe.colors+=s.colorsBuf.numItems}if(t.uv){const e=he.getUVBounds(t.uv),r=he.compressUVs(t.uv,e.min,e.max),n=r.quantized;s.uvDecodeMatrix=r.decodeMatrix,s.uvBuf=new ie(i,i.ARRAY_BUFFER,n,n.length,2,i.STATIC_DRAW),fe.uvs+=s.uvBuf.numItems}if(t.normals){const e=he.compressNormals(t.normals);let r=s.compressGeometry;s.normalsBuf=new ie(i,i.ARRAY_BUFFER,e,e.length,3,i.STATIC_DRAW,r),fe.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new ie(i,i.ELEMENT_ARRAY_BUFFER,e,e.length,1,i.STATIC_DRAW),fe.indices+=s.indicesBuf.numItems;const n=re(r,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new ie(i,i.ELEMENT_ARRAY_BUFFER,n,n.length,1,i.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),fe.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(),fe.meshes--}}var _e={};function be(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 _.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 Be(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 _.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 ye(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=[],B=[];let y,w,v,C,M,E,F,x,U,I,T;const P=(90-180*Math.atan(i/(s-t))/Math.PI)/90;for(y=0;y<=n;y++)for(M=t-y*f,E=h-y*u,w=0;w<=r;w++)v=Math.sin(w*d),C=Math.cos(w*d),m.push(M*v),m.push(P),m.push(M*C),b.push(w*p),b.push(1*y/n),g.push(M*v+a),g.push(E+l),g.push(M*C+c);for(y=0;y<n;y++)for(w=0;w<=r;w++)F=y*(r+1)+w,x=F+r,B.push(F),B.push(x),B.push(x+1),B.push(F),B.push(x+1),B.push(F+1);if(!A&&t>0){for(U=g.length/3,m.push(0),m.push(1),m.push(0),b.push(.5),b.push(.5),g.push(0+a),g.push(h+l),g.push(0+c),w=0;w<=r;w++)v=Math.sin(w*d),C=Math.cos(w*d),I=.5*Math.sin(w*d)+.5,T=.5*Math.cos(w*d)+.5,m.push(t*v),m.push(1),m.push(t*C),b.push(I),b.push(T),g.push(t*v+a),g.push(h+l),g.push(t*C+c);for(w=0;w<r;w++)o=U,F=U+1+w,B.push(F),B.push(F+1),B.push(o)}if(!A&&s>0){for(U=g.length/3,m.push(0),m.push(-1),m.push(0),b.push(.5),b.push(.5),g.push(0+a),g.push(0-h+l),g.push(0+c),w=0;w<=r;w++)v=Math.sin(w*d),C=Math.cos(w*d),I=.5*Math.sin(w*d)+.5,T=.5*Math.cos(w*d)+.5,m.push(s*v),m.push(-1),m.push(s*C),b.push(I),b.push(T),g.push(s*v+a),g.push(0-h+l),g.push(s*C+c);for(w=0;w<r;w++)o=U,F=U+1+w,B.push(o),B.push(F+1),B.push(F)}return _.apply(e,{positions:g,normals:m,uv:b,indices:B})}function we(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 _.apply(e,{primitive:"lines",positions:n,indices:A})}function ve(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),b=new Float32Array(d*p*3),B=new Float32Array(d*p*2);let y,w,v,C,M,E,F,x=0,U=0;for(y=0;y<p;y++){const e=y*g-c;for(w=0;w<d;w++)v=w*f-l,m[x]=v+A,m[x+1]=o,m[x+2]=-e+a,b[x+1]=1,B[U]=w/h,B[U+1]=(u-y)/u,x+=3,U+=2}x=0;const I=new(m.length/3>65535?Uint32Array:Uint16Array)(h*u*6);for(y=0;y<u;y++)for(w=0;w<h;w++)C=w+d*y,M=w+d*(y+1),E=w+1+d*(y+1),F=w+1+d*y,I[x]=F,I[x+1]=M,I[x+2]=C,I[x+3]=F,I[x+4]=E,I[x+5]=M,x+=6;return _.apply(e,{positions:m,normals:b,uv:B,indices:I})}function Ce(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,F;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,b=Math.sin(m),B=Math.cos(m),y=B*f,w=g,v=b*f,C=1-d/o,M=u/A,l.push(y),l.push(w),l.push(v),c.push(C),c.push(M),a.push(s+n*y),a.push(i+n*w),a.push(r+n*v);for(u=0;u<A;u++)for(d=0;d<o;d++)E=u*(o+1)+d,F=E+o+1,h.push(E+1),h.push(F+1),h.push(F),h.push(E+1),h.push(F),h.push(E);return _.apply(e,{positions:a,normals:l,uv:c,indices:h})}function Me(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=[],u=[],d=[],p=[];let f,g,m,b,B,y,w,v,C,M,E,F;for(v=0;v<=r;v++)for(w=0;w<=i;w++)f=w/i*n,g=.785398+v/r*Math.PI*2,o=t*Math.cos(f),a=t*Math.sin(f),m=(t+s*Math.cos(g))*Math.cos(f),b=(t+s*Math.cos(g))*Math.sin(f),B=s*Math.sin(g),c.push(m+o),c.push(b+a),c.push(B+l),d.push(1-w/i),d.push(v/r),y=h.normalizeVec3(h.subVec3([m,b,B],[o,a,l],[]),[]),u.push(y[0]),u.push(y[1]),u.push(y[2]);for(v=1;v<=r;v++)for(w=1;w<=i;w++)C=(i+1)*v+w-1,M=(i+1)*(v-1)+w-1,E=(i+1)*(v-1)+w,F=(i+1)*v+w,p.push(C),p.push(M),p.push(E),p.push(E),p.push(F),p.push(C);return _.apply(e,{positions:c,normals:u,uv:d,indices:p})}_e.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()},_e.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(_e.parse._buffToStr(e));window.location.href=s},_e.clone=function(e){return JSON.parse(JSON.stringify(e))},_e.bin={},_e.bin.f=new Float32Array(1),_e.bin.fb=new Uint8Array(_e.bin.f.buffer),_e.bin.rf=function(e,t){for(var s=_e.bin.f,i=_e.bin.fb,r=0;r<4;r++)i[r]=e[t+r];return s[0]},_e.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},_e.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},_e.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},_e.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},_e.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},_e.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},_e.parse={},_e.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},_e.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},_e.parse._readLine=function(e,t){for(var s="";10!=e[t];)s+=String.fromCharCode(e[t++]);return s},_e.parse.fromJSON=function(e){return JSON.parse(_e.parse._buffToStr(e))},_e.parse.toJSON=function(e){var t=JSON.stringify(e);return _e.parse._strToBuff(t)},_e.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=_e.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},_e.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},s={};s.ident=_e.bin.ril(e,0),s.version=_e.bin.ril(e,4),s.skinwidth=_e.bin.ril(e,8),s.skinheight=_e.bin.ril(e,12),s.framesize=_e.bin.ril(e,16),s.num_skins=_e.bin.ril(e,20),s.num_vertices=_e.bin.ril(e,24),s.num_st=_e.bin.ril(e,28),s.num_tris=_e.bin.ril(e,32),s.num_glcmds=_e.bin.ril(e,36),s.num_frames=_e.bin.ril(e,40),s.offset_skins=_e.bin.ril(e,44),s.offset_st=_e.bin.ril(e,48),s.offset_tris=_e.bin.ril(e,52),s.offset_frames=_e.bin.ril(e,56),s.offset_glcmds=_e.bin.ril(e,60),s.offset_end=_e.bin.ril(e,64);var i=s.offset_st;t.c_uvt=[];for(var r=0;r<s.num_st;r++){var n=_e.bin.rsl(e,i)/s.skinwidth,A=_e.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(_e.bin.rsl(e,i),_e.bin.rsl(e,i+2),_e.bin.rsl(e,i+4)),a.push(_e.bin.rsl(e,i+6),_e.bin.rsl(e,i+8),_e.bin.rsl(e,i+10)),i+=12;i=s.offset_skins;t.skins=[];for(r=0;r<s.num_skins;r++)t.skins.push(_e.bin.rASCII0(e,i)),i+=64;i=s.offset_frames;t.frames=[];var l=_e.parse.fromMD2._normals;for(r=0;r<s.num_frames;r++){var c={},h=_e.bin.rf(e,i),u=_e.bin.rf(e,i+4),d=_e.bin.rf(e,i+8);i+=12;var p=_e.bin.rf(e,i),f=_e.bin.rf(e,i+4),g=_e.bin.rf(e,i+8);i+=12,c.name=_e.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},_e.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],_e.parse.fromCollada=function(e){var t=_e.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=_e.parse.fromCollada._asset(r)),n&&(i.geometries=_e.parse.fromCollada._libGeometries(n)),A&&(i.images=_e.parse.fromCollada._libImages(A)),o&&(i.materials=_e.parse.fromCollada._libMaterials(o)),a&&(i.effects=_e.parse.fromCollada._libEffects(a)),i},_e.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}},_e.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],s=0;s<e.length;s++){var i=e[s],r=_e.parse.fromCollada._getMesh(i.getElementsByTagName("mesh")[0]);t.push(r)}return t},_e.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},_e.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},_e.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},_e.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},_e.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=_e.bin.rsl(e,0))return null;for(var s=_e.bin.ril(e,2),i=6;i<s;){var r=_e.bin.rsl(e,i),n=_e.bin.ril(e,i+2);15677==r&&(t.edit=_e.parse.from3DS._edit3ds(e,i,n)),45056==r&&(t.keyf=_e.parse.from3DS._keyf3ds(e,i,n)),i+=n}return t},_e.parse.from3DS._edit3ds=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);16384==n&&(null==i.objects&&(i.objects=[]),i.objects.push(_e.parse.from3DS._edit_object(e,r,A))),r+=A}return i},_e.parse.from3DS._keyf3ds=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);45058==n&&(null==i.desc&&(i.desc=[]),i.desc.push(_e.parse.from3DS._keyf_objdes(e,r,A))),r+=A}return i},_e.parse.from3DS._keyf_objdes=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);45072==n&&(i.hierarchy=_e.parse.from3DS._keyf_objhierarch(e,r,A)),45073==n&&(i.dummy_name=_e.bin.rASCII0(e,r+6)),r+=A}return i},_e.parse.from3DS._keyf_objhierarch=function(e,t,s){var i={},r=t+6;return i.name=_e.bin.rASCII0(e,r),r+=i.name.length+1,i.hierarchy=_e.bin.rsl(e,r+4),i},_e.parse.from3DS._edit_object=function(e,t,s){var i={},r=t+6;for(i.name=_e.bin.rASCII0(e,r),r+=i.name.length+1;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);16640==n&&(i.mesh=_e.parse.from3DS._obj_trimesh(e,r,A)),r+=A}return i},_e.parse.from3DS._obj_trimesh=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);16656==n&&(i.vertices=_e.parse.from3DS._tri_vertexl(e,r,A)),16672==n&&(i.indices=_e.parse.from3DS._tri_facel1(e,r,A)),16704==n&&(i.uvt=_e.parse.from3DS._tri_mappingcoors(e,r,A)),16736==n&&(i.local=_e.parse.from3DS._tri_local(e,r,A)),r+=A}return i},_e.parse.from3DS._tri_vertexl=function(e,t,s){var i=[],r=t+6,n=_e.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(_e.bin.rf(e,r)),i.push(_e.bin.rf(e,r+4)),i.push(_e.bin.rf(e,r+8)),r+=12;return i},_e.parse.from3DS._tri_facel1=function(e,t,s){var i=[],r=t+6,n=_e.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(_e.bin.rsl(e,r)),i.push(_e.bin.rsl(e,r+2)),i.push(_e.bin.rsl(e,r+4)),r+=8;return i},_e.parse.from3DS._tri_mappingcoors=function(e,t,s){var i=[],r=t+6,n=_e.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(_e.bin.rf(e,r)),i.push(1-_e.bin.rf(e,r+4)),r+=8;return i},_e.parse.from3DS._tri_local=function(e,t,s){var i={},r=t+6;return i.X=[_e.bin.rf(e,r),_e.bin.rf(e,r+4),_e.bin.rf(e,r+8)],r+=12,i.Y=[_e.bin.rf(e,r),_e.bin.rf(e,r+4),_e.bin.rf(e,r+8)],r+=12,i.Z=[_e.bin.rf(e,r),_e.bin.rf(e,r+4),_e.bin.rf(e,r+8)],r+=12,i.C=[_e.bin.rf(e,r),_e.bin.rf(e,r+4),_e.bin.rf(e,r+8)],r+=12,i},_e.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},s={};return s.id=_e.bin.ril(e,0),s.verS=_e.bin.ril(e,4),s.texS=_e.bin.ril(e,8),s.indS=_e.bin.ril(e,12),s.verO=_e.bin.ril(e,16),s.verL=_e.bin.ril(e,20),s.texO=_e.bin.ril(e,24),s.texL=_e.bin.ril(e,28),s.indO=_e.bin.ril(e,32),s.indL=_e.bin.ril(e,36),0!=s.verO&&(t.vertices=_e.parse.fromBIV._readFloats(e,s.verO,s.verL)),0!=s.texO&&(t.uvt=_e.parse.fromBIV._readFloats(e,s.texO,s.texL)),0!=s.indO&&(t.indices=_e.parse.fromBIV._readInts(e,s.indO,s.indL,s.indS)),t},_e.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);_e.bin.wil(n,0,1769365870),_e.bin.wil(n,4,32),_e.bin.wil(n,8,32),_e.bin.wil(n,12,i);var A=40;return e.vertices&&(_e.bin.wil(n,16,A),_e.bin.wil(n,20,4*e.vertices.length),_e.parse.fromBIV._writeFloats(n,A,e.vertices),A+=4*e.vertices.length),e.uvt&&(_e.bin.wil(n,24,A),_e.bin.wil(n,28,4*e.uvt.length),_e.parse.fromBIV._writeFloats(n,A,e.uvt),A+=4*e.uvt.length),e.indices&&(_e.bin.wil(n,32,A),_e.bin.wil(n,36,4*e.indices.length),_e.parse.fromBIV._writeInts(n,A,e.indices,i)),n.buffer},_e.parse.fromBIV._readFloats=function(e,t,s){for(var i=[],r=0;r<s/4;r++)i.push(_e.bin.rf(e,t+4*r));return i},_e.parse.fromBIV._writeFloats=function(e,t,s){for(var i=0;i<s.length;i++)_e.bin.wf(e,t+4*i,s[i])},_e.parse.fromBIV._readInts=function(e,t,s,i){for(var r=[],n=0;n<s/4;n++)16==i&&r.push(_e.bin.rsl(e,t+2*n)),32==i&&r.push(_e.bin.ril(e,t+4*n));return r},_e.parse.fromBIV._writeInts=function(e,t,s,i){for(var r=0;r<s.length;r++)16==i&&_e.bin.wsl(e,t+2*r,s[r]),32==i&&_e.bin.wil(e,t+4*r,s[r])},_e.gen={},_e.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},_e.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]}},_e.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},_e.mat={},_e.mat.scale=function(e,t,s){return[e,0,0,0,0,t,0,0,0,0,s,0,0,0,0,1]},_e.mat.translate=function(e,t,s){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,s,1]},_e.mat.rotateDeg=function(e,t,s){var i=Math.PI/180;return _e.mat.rotate(e*i,t*i,s*i)},_e.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},_e.edit={},_e.edit.interpolate=function(e,t,s,i){for(var r=0;r<e.length;r++)s[r]=e[r]+i*(t[r]-e[r])},_e.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]}},_e.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},_e.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},_e.utils={},_e.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 Ee={" ":{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 Fe(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;_.isNumeric(a)&&(a=""+a);for(var l,c,h,u,d,p,f,g,m,b=(a||"").split("\n"),B=0,y=0,w=.04,v=0;v<b.length;v++){l=0,h=(c=b[v]).length;for(var C=0;C<h;C++)if(u=Ee[c.charAt(C)]){d=1,p=-1,f=-1,g=u.points.length;for(var M=0;M<g;M++)-1!==(m=u.points[M])[0]||-1!==m[1]?(A.push(l+m[0]*n*w+s),A.push(y+m[1]*n*w+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*w*n}y-=35*w*n}return _.apply(e,{primitive:"lines",positions:A,indices:o})}function xe(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 _.apply(e,{primitive:"lines",positions:e.points,indices:s})}function Ue(e={}){if(3!==e.startPoint.length)throw"Start point should contain 3 elements in array: x, y and z";if(3!==e.endPoint.length)throw"End point should contain 3 elements in array: x, y and z";let t=[],s=[],i=e.startPoint[0],r=e.startPoint[1],n=e.startPoint[2],A=e.endPoint[0],o=e.endPoint[1],a=e.endPoint[2],l=Math.sqrt((A-i)**2+(o-r)**2+(a-n)**2),c=[(A-i)/l,(o-r)/l,(a-n)/l];if(e.pattern){let h=e.pattern.length,u=!1,d=0,p=0,f=0,g=[i,r,n],m=e.pattern[p];for(s.push(g[0],g[1],g[2]);m<=l-d;){let i=[c[0]*m,c[1]*m,c[2]*m],r=[g[0]+i[0],g[1]+i[1],g[2]+i[2]];s.push(r[0],r[1],r[2]),u||(t.push(f),t.push(f+1)),u=!u,f+=1,g=r,p+=1,p>=h&&(p=0),d+=m,m=e.pattern[p]}e.extendToEnd&&(s.push(A,o,a),t.push(t.length-2),t.push(t.length-1))}else t.push(0),t.push(1),s.push(i,r,n,A,o,a);return _.apply(e,{primitive:"lines",positions:s,indices:t})}const Ie=h.vec4(4),Te=h.vec4(),Pe=h.vec4(),Se=h.vec3([1,0,0]),De=h.vec3([0,1,0]),ke=h.vec3([0,0,1]),Qe=h.vec3(3),Re=h.vec3(3),Oe=h.identityMat4();class Ve extends T{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=h.vec3(),this._quaternion=h.identityQuaternion(),this._rotation=h.vec3(),this._position=h.vec3(),this._offset=h.vec3(),this._localMatrix=h.identityMat4(),this._worldMatrix=h.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=h.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)h.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=h.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{let e;h.collapseAABB3(this._aabb);for(let t=0,s=this._children.length;t<s;t++)e=this._children[t],e.collidable&&h.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}addChild(e,t){if(_.isNumeric(e)||_.isString(e)){const t=e;if(!(e=this.scene.component[t]))return void this.warn("Component not found: "+_.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(_.isNumeric(e)||_.isString(e)){const t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+_.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]),h.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]),h.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=h.identityMat4()),this._localMatrix.set(e||Oe),h.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=h.identityMat4()),h.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 Ie[0]=e[0],Ie[1]=e[1],Ie[2]=e[2],Ie[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(Ie,Te),h.mulQuaternions(this.quaternion,Te,Pe),this.quaternion=Pe,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return Ie[0]=e[0],Ie[1]=e[1],Ie[2]=e[2],Ie[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(Ie,Te),h.mulQuaternions(Te,this.quaternion,Te),this}rotateX(e){return this.rotate(Se,e)}rotateY(e){return this.rotate(De,e)}rotateZ(e){return this.rotate(ke,e)}translate(e,t){return h.vec3ApplyQuaternion(this.quaternion,e,Qe),h.mulVec3Scalar(Qe,t,Re),h.addVec3(this.position,Re,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(Se,e)}translateY(e){return this.translate(De,e)}translateZ(e){return this.translate(ke,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 Le=h.vec3(),He=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,h.transformVec4(i,t,s),h.setMat4Translation(i,s,n),n.slice()}}();function Ne(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 Ge(e,t,s,i=1e3){const r=h.getPositionsCenter(e,Le),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 je=new e({}),We=h.vec3(),ze=h.vec4(),Xe={3001:"sRGBToLinear"},Ke=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 u=c.getLogDepth,d=c.clipPos,p=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((${d}.xy / ${d}.w - ${e}) * ${t} * ${d}.w, ${d}.zw)`}}(),f=p?p.transformedClipPos():d,g=[],m=a.createVarying("float","isPerspective",(()=>`(${c.projMatrix}[2][3] == -1.0) ? 1.0 : 0.0`)),_=a.createUniform("float","logDepthBufFC",((e,t)=>e(2/(Math.log(t.view.far+1)/Math.LN2)))),b=a.createVarying("float","vFragDepth",(()=>"1.0 + clipPos.w"));u?g.push(`gl_FragDepth = ${c.testPerspectiveForGl_FragDepth?`${m} == 0.0 ? gl_FragCoord.z : `:""}log2(${u(b)}) * ${_} * 0.5;`):c.cleanerEdges&&g.push("gl_FragDepth = gl_FragCoord.z + length(vec2(dFdx(gl_FragCoord.z), dFdy(gl_FragCoord.z)));");const B=a.createFragmentDefinition("linearToGamma",((e,t)=>{t.push(`vec4 ${e}(in vec4 value, in float gammaFactor) {`),t.push(" return vec4(pow(value.xyz, vec3(1.0 / gammaFactor)), value.w);"),t.push("}")})),y=c.sectionPlanesState,w=y&&function(){const e=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t}(y.getNumAllocatedSectionPlanes()).map((e=>{const t=(t,s,i)=>a.createUniform(t,`sectionPlane${s}${e}`,((t,s)=>{const r=y.sectionPlanes,n=r.length,A=(s.mesh.layerIndex||0)*n,o=e<n&&s.mesh.renderFlags.sectionPlanesActivePerLayer[A+e];return i(t,o,r[e],s.mesh.origin)}));return{act:t("bool","Active",((e,t)=>e(t?1:0))),dir:t("vec3","Dir",((e,t,s)=>t&&e(s.dir))),pos:t("vec3","Pos",((e,t,s,i)=>t&&e(i?h.mulVec3Scalar(h.normalizeVec3(s.dir,We),-(h.dotVec3(s.dir,i)+s.dist),We):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(" + "))}(),v=c.crossSections,C=w?function(){const e=a.createUniform("vec4","sliceColor",(e=>e(v.sliceColor))),t=s=>(t.needed=!0,`(sliced ? ${e} : ${s})`);return t}():e=>e,M=c.getGammaFactor,E=a.createUniform("float","gammaFactor",(e=>e(M())));c.appendFragmentOutputs(g,M&&(e=>`${B}(${e}, ${E})`),"gl_FragCoord",C);const F=function(){const e=[],t=a.createUniform("float","sliceThickness",(e=>e(v.sliceThickness)));if(w){C.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 = ${w(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);`),u&&e.push(` gl_FragDepth = log2(${u(b)}) * ${_} * 0.5;`),e.push(" return;"),e.push(" }")}else e.push(` if (dist > ${C.needed?t:"0.0"}) { discard; }`);C.needed&&e.push(" sliced = dist > 0.0;"),e.push(" }")}return e}(),x=function(){const e=[];return i.forEach((t=>t(e))),e}(),U=[...function(){const e=[];return s.forEach((t=>t(e))),e}(),...x,"void main(void) {",...c.discardPoints?[" vec2 cxy = 2.0 * gl_PointCoord - 1.0;"," if (dot(cxy, cxy) > 1.0) { discard; }"]:[],...F,...g,"}"],I=[`gl_Position = ${f};`,...c.getPointSize?[`gl_PointSize = ${c.getPointSize()};`]:[],...function(){const e=[];return t.forEach((t=>t(e))),e}()],T=c.getVertexData?c.getVertexData():[],P=[...function(){const t=[];return e.forEach((e=>e(t))),t}(),"void main(void) {",...T,...I,"}"],S=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"],D=S("vertex").concat(P),k=S("fragment").concat(["vec4 sRGBToLinear(in vec4 value) {"," return vec4(mix(pow(value.rgb * 0.9478672986 + 0.0521327014, vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);","}"]).concat(U),Q=(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("")]]},[R,O]=Q(o.VERTEX_SHADER,D),[V,L]=Q(o.FRAGMENT_SHADER,k),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,R),o.attachShader(e,V),o.linkProgram(e),o.getProgramParameter(e,o.LINK_STATUS)){const t=Ye(o,e);r.forEach((e=>e(t)));const s=A.map((e=>e(t))).filter((e=>e)),i=je.addItem({});return[{id:i,bind:()=>o.useProgram(e),inputSetters:{attributesHash:n.sort().join(", "),setUniforms:(e,t)=>{p&&p.setClipPosInputValue(e),s.forEach((e=>e(t)))}},destroy:()=>{je.removeItem(i),o.deleteProgram(e),o.deleteShader(R),o.deleteShader(V)}}]}return H(["",o.getProgramInfoLog(this.program),"","Vertex shader:","",...D,"","Fragment shader:","",...k])}return H(["Failed to allocate program"])}}}},Ze=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];ze[0]=t.color[0],ze[1]=t.color[1],ze[2]=t.color[2],ze[3]=t.intensity,e(ze)})),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:{isWorldSpace:"world"===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&&Je(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`)}},Je=(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?`${Xe[i]}(${s})`:s}},Ye=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}},$e=h.vec4(),qe=h.vec4();class et{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 tt=h.OBB3(),st=h.vec4(),it=h.vec4(),rt=h.vec4(),nt=h.vec3([1,0,0]),At=h.vec3([0,1,0]),ot=h.vec3([0,0,1]),at=h.vec3(3),lt=h.vec3(3),ct=h.identityMat4(),ht=new e({}),ut={};class dt extends T{constructor(e,t={}){super(e,t),this.renderOrder=t.renderOrder||0,this.originalSystemId=t.originalSystemId||this.id,this.renderFlags=new et,this._state=new se({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==t.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!t.stationary,background:!!t.background,billboard:this._checkBillboard(t.billboard),layer:null,colorize:null,pickID:this.scene._renderer.getPickID(this),drawHash:"",pickOcclusionHash:"",offset:h.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=Ke(),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 ut)){const e=ft(i,A,{decodedUv:c,worldNormal:a,viewNormal:l},h,s);if(e.errors)return void console.log(e.errors.join("\n"));const t=ht.addItem({});ut[u]={drawMesh:e.drawMesh,id:t,useCount:0,delete:()=>{ht.removeItem(t),e.destroy(),delete ut[u],p.memory.programs--}},p.memory.programs++}t=ut[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&&Ze(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=Ze(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=Ze(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&&Je(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?($e[0]=t,$e[1]=1===e.alphaMode?1:0,$e[2]=e.alphaCutoff,$e):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.isWorldSpace?K[s].vViewLightReverseDir:t.getDirection(null,j)};`);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;qe[0]=255&s,qe[1]=s>>8&255,qe[2]=s>>16&255,qe[3]=s>>24&255,h.mulVec4Scalar(qe,1/255,qe),e(qe)})),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=h.vec3(),this._quaternion=h.identityQuaternion(),this._rotation=h.vec3(),this._position=h.vec3(),this._worldMatrix=h.identityMat4(),this._worldNormalMatrix=h.identityMat4(),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0;const o=t.origin||t.rtcCenter;if(o&&(this._state.origin=h.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]),h.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]),h.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=h.identityMat4()),h.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix}set matrix(e){this.__localMatrix||(this.__localMatrix=h.identityMat4()),this.__localMatrix.set(e||ct),h.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=h.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)h.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=h.mat4()),h.transposeMat4(this._worldMatrix,this._worldNormalMatrix),h.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=h.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}_buildAABB(e,t){h.transformOBB3(e,this._geometry.obb,tt),h.OBB3ToAABB3(tt,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 st[0]=e[0],st[1]=e[1],st[2]=e[2],st[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(st,it),h.mulQuaternions(this.quaternion,it,rt),this.quaternion=rt,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return st[0]=e[0],st[1]=e[1],st[2]=e[2],st[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(st,it),h.mulQuaternions(it,this.quaternion,it),this}rotateX(e){return this.rotate(nt,e)}rotateY(e){return this.rotate(At,e)}rotateZ(e){return this.rotate(ot,e)}translate(e,t){return h.vec3ApplyQuaternion(this.quaternion,e,at),h.mulVec3Scalar(at,t,lt),h.addVec3(this.position,lt,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(nt,e)}translateY(e){return this.translate(At,e)}translateZ(e){return this.translate(ot,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=h.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){pt(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 pt=function(){const e=h.vec3(),t=h.vec3(),s=h.vec3(),i=h.vec3(),r=h.vec3(),n=h.vec3(),A=h.vec4(),o=h.vec3(),a=h.vec3(),l=h.vec3(),c=h.vec3(),u=h.vec3(),d=h.vec3(),p=h.vec3(),f=h.vec3(),g=h.vec3(),m=h.vec4(),_=h.vec4(),b=h.vec4(),B=h.vec3(),y=h.vec3(),w=h.vec3(),v=h.vec3(),C=h.vec3(),M=h.vec3(),E=h.vec3(),F=h.vec3(),x=h.vec3(),U=h.vec3(),I=h.vec3();return function(T,P,S,D,k){var Q=k.primIndex;if(null!=Q&&Q>-1){const L=T.geometry._state,H=T.scene,N=H.camera,G=H.canvas;if("triangles"===L.primitiveName){k.primitive="triangle";const H=Q,j=L.indices,W=L.positions;let z,X,K;if(j){var R=j[H+0],O=j[H+1],V=j[H+2];n[0]=R,n[1]=O,n[2]=V,k.indices=n,z=3*R,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&&(he.decompressPosition(s,e,s),he.decompressPosition(i,e,i),he.decompressPosition(r,e,r))}k.canvasPos?h.canvasPosToLocalRay(G.canvas,T.origin?He(P,T.origin):P,S,D,T.worldMatrix,k.canvasPos,e,t):k.origin&&k.direction&&h.worldRayToLocalRay(T.worldMatrix,k.origin,k.direction,e,t),h.normalizeVec3(t),h.rayPlaneIntersect(e,t,s,i,r,A),k.localPos=A,k.position=A,m[0]=A[0],m[1]=A[1],m[2]=A[2],m[3]=1,h.transformVec4(T.worldMatrix,m,_),o[0]=_[0],o[1]=_[1],o[2]=_[2],k.canvasPos&&T.origin&&(o[0]+=T.origin[0],o[1]+=T.origin[1],o[2]+=T.origin[2]),k.worldPos=o,h.transformVec4(N.matrix,_,b),a[0]=b[0],a[1]=b[1],a[2]=b[2],k.viewPos=a,h.cartesianToBarycentric(A,s,i,r,l),k.bary=l;const Z=L.normals;if(Z){if(L.compressGeometry){const e=3*R,t=3*O,s=3*V;he.decompressNormal(Z.subarray(e,e+2),c),he.decompressNormal(Z.subarray(t,t+2),u),he.decompressNormal(Z.subarray(s,s+2),d)}else c[0]=Z[z],c[1]=Z[z+1],c[2]=Z[z+2],u[0]=Z[X],u[1]=Z[X+1],u[2]=Z[X+2],d[0]=Z[K],d[1]=Z[K+1],d[2]=Z[K+2];const e=h.addVec3(h.addVec3(h.mulVec3Scalar(c,l[0],B),h.mulVec3Scalar(u,l[1],y),w),h.mulVec3Scalar(d,l[2],v),C);k.worldNormal=h.normalizeVec3(h.transformVec3(T.worldNormalMatrix,e,M))}const J=L.uv;if(J){if(p[0]=J[2*R],p[1]=J[2*R+1],f[0]=J[2*O],f[1]=J[2*O+1],g[0]=J[2*V],g[1]=J[2*V+1],L.compressGeometry){const e=L.uvDecodeMatrix;e&&(he.decompressUV(p,e,p),he.decompressUV(f,e,f),he.decompressUV(g,e,g))}k.uv=h.addVec3(h.addVec3(h.mulVec2Scalar(p,l[0],E),h.mulVec2Scalar(f,l[1],F),x),h.mulVec2Scalar(g,l[2],U),I)}}}}}(),ft=(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 gt extends T{get type(){return"Material"}constructor(e,t={}){super(e,t),p.memory.materials++}destroy(){super.destroy(),p.memory.materials--}}const mt={opaque:0,mask:1,blend:2},_t=["opaque","mask","blend"];class bt extends gt{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new se({type:"PhongMaterial",ambient:h.vec3([1,1,1]),diffuse:h.vec3([1,1,1]),specular:h.vec3([1,1,1]),emissive:h.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=mt[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 _t[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 Bt(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 yt(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=Bt(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=Bt(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=Bt(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=Bt(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){const t=Bt(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=Bt(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=Bt(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 wt=new Uint8Array([0,0,0,1]);class vt{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?(wt[0]=Math.floor(255*e[0]),wt[1]=Math.floor(255*e[1]),wt[2]=Math.floor(255*e[2]),wt[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(wt[0]=0,wt[1]=0,wt[2]=0,wt[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,wt)}else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,wt);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=yt(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=yt(s,this.magFilter);l&&s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,l);const c=yt(s,this.wrapS);c&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,c);const h=yt(s,this.wrapT);h&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,h);const u=yt(s,this.format,this.encoding),d=yt(s,this.type),p=Ct(s,this.internalFormat,u,d,this.encoding,!1);if(this.target===s.TEXTURE_CUBE_MAP){if(_.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=yt(s,this.wrapS);n&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,n);const A=yt(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=yt(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,Mt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Mt(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,yt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,yt(s,this.magFilter)));const o=yt(s,this.format,this.encoding),a=yt(s,this.type),l=Ct(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=yt(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=yt(t,e.magFilter);s&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,s))}if(void 0!==e.wrapS){const s=yt(t,e.wrapS);s&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,s))}if(void 0!==e.wrapT){const s=yt(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 Ct(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||Bt(e,"EXT_color_buffer_float"),A}function Mt(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function Et(e){if(!Ft(e.width)||!Ft(e.height)){const t=document.createElement("canvas");t.width=xt(e.width),t.height=xt(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Ft(e){return 0==(e&e-1)}function xt(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Ut extends T{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new se({texture:new vt({gl:this.scene.canvas.gl}),matrix:h.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=h.vec2([0,0]),this._scale=h.vec2([1,1]),this._rotate=h.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),p.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=h.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=h.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?h.mulMat4(t,s):s),0!==this._rotate&&(s=h.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?h.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=Et(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=Et(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(),p.memory.textures--}}const It=h.vec3(),Tt=h.vec3();h.vec3();const Pt=h.vec3([0,-1,0]),St=h.vec4([0,0,0,1]);class Dt extends gt{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new se({type:"LambertMaterial",ambient:h.vec3([1,1,1]),color:h.vec3([1,1,1]),emissive:h.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 kt={opaque:0,mask:1,blend:2},Qt=["opaque","mask","blend"];class Rt extends gt{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new se({type:"MetallicMaterial",baseColor:h.vec4([1,1,1]),emissive:h.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=kt[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 Qt[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 Ot={opaque:0,mask:1,blend:2},Vt=["opaque","mask","blend"];class Lt extends gt{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new se({type:"SpecularMaterial",diffuse:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),specular:h.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=Ot[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 Vt[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 Ht={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 Nt extends gt{get type(){return"EmphasisMaterial"}get presets(){return Ht}constructor(e,t={}){super(e,t),this._state=new se({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),e=e||"default",this._preset===e)return;const t=Ht[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(Ht).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 Gt={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 jt extends gt{get type(){return"EdgeMaterial"}get presets(){return Gt}constructor(e,t={}){super(e,t),this._state=new se({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Gt[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(Gt).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class Wt extends T{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=h.vec3(t.pos||[0,0,0]),this._up=h.vec3(t.up||[0,1,0]),this._normal=h.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=h.vec3(),this._rtcPos=h.vec3(),this._imageSize=h.vec2(),this._texture=new Ut(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 Ve(this,{matrix:h.inverseMat4(h.lookAtMat4v(this._pos,h.subVec3(this._pos,this._normal,h.mat4()),this._up,h.mat4())),children:[this._bitmapMesh=new dt(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new pe(this,ve({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new bt(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 zt=(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)},Xt=h.vec3(),Kt=h.vec3(),Zt=h.vec3();class Jt{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&&!zt(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];Xt[0]=e[r],Xt[1]=e[r+1],Xt[2]=e[r+2],Kt[0]=e[n],Kt[1]=e[n+1],Kt[2]=e[n+2],Zt[0]=e[A],Zt[1]=e[A+1],Zt[2]=e[A+2],h.cross3Vec3(Xt,Kt,Xt),s+=h.dotVec3(Xt,Zt)}return s/6}}const Yt=new Jt,$t=h.vec3(),qt=h.vec3(),es=h.vec3(),ts=h.vec3(),ss=h.vec3(),is=h.vec3();class rs{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];$t[0]=e[r],$t[1]=e[r+1],$t[2]=e[r+2],qt[0]=e[n],qt[1]=e[n+1],qt[2]=e[n+2],es[0]=e[A],es[1]=e[A+1],es[2]=e[A+2],h.subVec3($t,qt,ts),h.subVec3(es,qt,ss),s+=.5*h.lenVec3(h.cross3Vec3(ts,ss,is))}return s}}const ns=new rs,As=h.OBB3(),os=h.OBB3(),as=h.OBB3();class ls{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=h.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":Yt.reset(),Yt.setPrimitive(this.layer.primitive),this.getEachVertex((e=>{Yt.addVertex(e)})),this.getEachIndex((e=>{Yt.addIndex(e)})),this._volume=Yt.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":ns.reset(),this.getEachVertex((e=>{ns.addVertex(e)})),this.getEachIndex((e=>{ns.addIndex(e)})),this._surfaceArea=ns.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&&(h.AABB3ToOBB3(this._aabbLocal,As),this.transform?(h.transformOBB3(this.transform.worldMatrix,As,os),h.transformOBB3(this.model.worldMatrix,os,as),h.OBB3ToAABB3(as,this._aabbWorld)):(h.transformOBB3(this.model.worldMatrix,As,os),h.OBB3ToAABB3(os,this._aabbWorld)),this._aabbWorldDirty=!1),this._aabbWorld}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const cs=1,hs=4,us=8,ds=16,ps=32,fs=256,gs=512,ms=1024,_s=2048,bs=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};`)}},Bs=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);`)}},ys=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}))`)};`)}}},ws=h.vec2(),vs=h.vec3(),Cs=h.vec4(),Ms=h.mat4(),Es=h.vec3([0,0,0]),Fs=0,xs=1,Us=2,Is=3,Ts=4,Ps=5,Ss=6,Ds=7,ks=8,Qs=9,Rs=10,Os=11,Vs=e=>[h.safeInv(e[0]),h.safeInv(e[1]),h.safeInv(e[2])],Ls=(e,t,s,i,r)=>{const n=!!(e&cs),A=!!(e&fs),o=!!(e&gs),a=!!(e&ms),l=!!(e&_s),c=!!(e&us),h=!!(e&hs);let u,d;u=!n||h||A||o&&!i.highlightMaterial.glowThrough||a&&!i.selectedMaterial.glowThrough?Fs:t?Us:xs,d=!n||h?Fs:a?Ts:o?Is:A?Ps:Fs;let p=0;p=s&&n&&!h?a?Qs:o?ks:A?Rs:l?t?Ds:Ss:Fs:Fs;const f=n&&!h&&c?Os:Fs;r[0]=u,r[1]=d,r[2]=p,r[3]=f},Hs=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],u=t.id;if(!(u in c)){const e=t.canvas.gl,l=function(r,n,A){const o=function(){const A=Ke(),o=A.programVariables,l=a(o,n);return r(o,l.geometryParameters,(function(r,a){const c=t.pointsMaterial,u="points"===i&&!n,d=()=>[t._sectionPlanesState.getHash()].concat(u?[c.hash]:[]).concat(r.getHash?r.getHash():[]).join(";"),p=d(),f=()=>p===d(),g=l.geometryParameters,m=r.incrementDrawState,_=r.isShadowProgram,b=g.attributes,B=b.position.world,y="clipPos",[w,v]=A.buildProgram(e,s+" "+i+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:y,clippableTest:function(){const e=o.createVarying("float","vClippable",(()=>`${b.clippable} ? 1.0 : 0.0`),"flat");return()=>`${e} > 0.0`}(),clippingCaps:r.clippingCaps,crossSections:t.crossSections,discardPoints:u&&c.roundPoints,getGammaFactor:t.gammaOutput&&(()=>t.gammaFactor),getLogDepth:r.getLogDepth,getPointSize:function(){const e=[];if(u){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=b.color,t=b.flags[r.renderPassFlag],s=o.createUniform("int","renderPass",((e,t)=>e(t.renderPass))),n=[`if (${_?`(${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=>{ws[0]=c.minIntensity,ws[1]=c.maxIntensity,e(ws)}));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=g.attributes.position.view;return A.push(`vec4 ${a} = ${g.viewMatrix} * ${B};`),A.push(`vec4 clipPos = ${g.projMatrix} * ${a};`),A},projMatrix:g.projMatrix,sectionPlanesState:t._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==i&&"lines"!==i||n,usePickClipPos:a,worldPositionAttribute:B});return v?(console.error(v),{getValid:f,destroy:()=>{},drawLayer:(e,t,s)=>{}}):{getValid:f,destroy:()=>w.destroy(),drawLayer:(e,t,s)=>{e.lastProgramId!==w.id&&(e.lastProgramId=w.id,w.bind());const i=t.origin,r=t.model,A=e.viewParams,o=vs;h.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 u={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:h.compareVec3(o,Es)?a:He(a,o,Ms),viewNormalMatrix:A.viewNormalMatrix}};w.inputSetters.setUniforms(e,u),t.drawCalls[n?n.vertices?"drawVertices":"drawEdges":"drawSurface"](w.inputSetters.attributesHash,l.layerTypeInputs,{projMatrix:c,viewMatrix:h.compareVec3(o,Es)?a:He(a,o,Ms),viewNormalMatrix:A.viewNormalMatrix,eye:A.eye}),m&&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())}}},d=(e,t)=>l(e,t,!0),p=(e,t)=>l(e,t,!1),f=(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),g=(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),m=(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),_=(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(${h.MAX_INT}), 1.0);`)}}}(e,s,t.logarithmicDepthBufferEnabled,r),!0),b=(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(${h.MAX_INT}), 1.0)`};`),e.push(`${c} = uvec4(${o});`))}}}(e,t,i,r),!0);c[u]="points"===i?{colorRenderers:{"sao-":{vertex:p(((e,t,s)=>s(f(e,t,null,null))))}},occlusionRenderer:p(((e,s,i)=>i(Bs(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:p(g),pickMeshRenderer:p(m),silhouetteRenderer:p(((e,s,i)=>i(ys(e,s,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:p(((e,t,s)=>b(e,t,s,!0,!0))),snapVertexRenderer:p(((e,t,s)=>b(e,t,s,!1,!0)),{vertices:!0})}:"lines"===i?{colorRenderers:{"sao-":{vertex:p(((e,t,s)=>s(f(e,t,null,null))))}},silhouetteRenderer:p(((e,s,i)=>i(ys(e,s,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:p(((e,t,s)=>b(e,t,s,!0,!1))),snapEdgeRenderer:p(((e,t,s)=>b(e,t,s,!1,!1)),{vertices:!1}),snapVertexRenderer:p(((e,t,s)=>b(e,t,s,!1,!1)),{vertices:!0})}:{colorRenderers:function(){const e=e=>Ze(e,t._lightsState),s=e=>{const t=e.createUniform("vec4","uSAOParams",((e,t)=>e(t.legacyFrameCtx.saoParams))),s=Je(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=Je(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&&p(((r,n,A)=>A(function(e,t,s,i,r){const n=(t,s,i)=>Je(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-":p(((e,t,s)=>s(r(e,t,!1)))),"alphaCutoff+":p(((e,t,s)=>s(r(e,t,!0))))},vertex:p(o?(t,r,n)=>n(f(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:p(((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:p(((e,s,i)=>i(bs(e,s,t.logarithmicDepthBufferEnabled,!0))),{vertices:!1}),vertex:p(((e,s,i)=>i(bs(e,s,t.logarithmicDepthBufferEnabled,!1))),{vertices:!1})},occlusionRenderer:p(((e,s,i)=>i(Bs(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:d(g),pickMeshRenderer:d(m),pickNormalsFlatRenderer:d(((e,t,s)=>_(e,t,s,!0))),pickNormalsRenderer:d(((e,t,s)=>_(e,t,s,!1))),shadowRenderer:p(((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:d(((e,s,i)=>i(ys(e,s,t.logarithmicDepthBufferEnabled,!1)))),snapInitRenderer:d(((e,t,s)=>b(e,t,s,!0,!1))),snapEdgeRenderer:d(((e,t,s)=>b(e,t,s,!1,!1)),{vertices:!1}),snapVertexRenderer:d(((e,t,s)=>b(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[u])},y=()=>B(!1);y(),t.on("compile",y),t.on("destroyed",(()=>{delete c[u]}))}return c[u]}}();class Ns{constructor(e,t,s){this.model=e,this.primitive=t,this.origin=s,this._meshes=[],this._aabb=h.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(cs,"numVisibleLayerPortions"),e(hs,"numCulledLayerPortions"),e(us,"numPickableLayerPortions"),e(ds,"numClippableLayerPortions"),e(fs,"numXRayedLayerPortions"),e(gs,"numHighlightedLayerPortions"),e(ms,"numSelectedLayerPortions"),this._renderers.edgesRenderers&&e(_s,"numEdgesLayerPortions"),this._countsByFlagArr=Object.values(this._countsByFlag),this._numTransparentLayerPortions=0}}aabbChanged(){this._aabbDirty=!0}__drawLayer(e,t,s,i){if(this._countsByFlag[hs].count<this._portions.length&&this._countsByFlag[cs].count>0){const e="points"!==this.primitive&&"lines"!==this.primitive&&[xs,Us,Os,Is,Ts,Ps];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[fs].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?xs:Us;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[fs].count<this._portions.length&&this.__drawLayer(e,t,s,xs)}__drawSilhouette(e,t,s,i){t.programColor=this.__setVec4FromMaterialColorAlpha(s.fillColor,s.fillAlpha,Cs),this.__drawLayer(e,t,this._renderers.silhouetteRenderer,i)}drawSilhouetteXRayed(e,t){this._countsByFlag[fs].count>0&&this.__drawSilhouette(e,t,this.model.scene.xrayMaterial,Ps)}drawSilhouetteHighlighted(e,t){this._countsByFlag[gs].count>0&&this.__drawSilhouette(e,t,this.model.scene.highlightMaterial,Is)}drawSilhouetteSelected(e,t){this._countsByFlag[ms].count>0&&this.__drawSilhouette(e,t,this.model.scene.selectedMaterial,Ts)}__drawVertexEdges(e,t,s){const i=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.vertex;i&&this._countsByFlag[_s].count>0&&this.__drawLayer(e,t,i,s)}drawEdgesColorOpaque(e,t){this._compiledPortions.edgesColorOpaqueAllowed()&&this.__drawVertexEdges(e,t,Ss)}drawEdgesColorTransparent(e,t){this._numTransparentLayerPortions>0&&this.__drawVertexEdges(e,t,Ds)}__drawUniformEdges(e,t,s,i){const r=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.uniform;r&&(t.programColor=this.__setVec4FromMaterialColorAlpha(s.edgeColor,s.edgeAlpha,Cs),this.__drawLayer(e,t,r,i))}drawEdgesHighlighted(e,t){this._countsByFlag[gs].count>0&&this.__drawUniformEdges(e,t,this.model.scene.highlightMaterial,ks)}drawEdgesSelected(e,t){this._countsByFlag[ms].count>0&&this.__drawUniformEdges(e,t,this.model.scene.selectedMaterial,Qs)}drawEdgesXRayed(e,t){this._countsByFlag[fs].count>0&&this.__drawUniformEdges(e,t,this.model.scene.xrayMaterial,Rs)}__drawPick(e,t,s){s&&this.__drawLayer(e,t,s,Os)}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],this._aabbDirty&&(h.collapseAABB3(this._aabb),this._meshes.forEach((e=>h.expandAABB3(this._aabb,e.aabb))),this._aabbDirty=!1);const i=this._aabb;t.snapPickCoordinateScale=h.mulVec3Scalar(Vs([i[3]-i[0],i[4]-i[1],i[5]-i[2]]),h.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:Vs(t.snapPickCoordinateScale)})}drawOcclusion(e,t){const s=this._renderers.occlusionRenderer;s&&this.__drawLayer(e,t,s,xs)}drawShadow(e,t){const s=this._renderers.shadowRenderer;s&&this.__drawLayer(e,t,s,xs)}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[cs].fromFlags(t),this._setFlags(e,t,s)}setCulled(e,t,s){this._countsByFlag[hs].fromFlags(t),this._setFlags(e,t,s)}setPickable(e,t,s){this._countsByFlag[us].fromFlags(t),this._setFlags(e,t,s)}setClippable(e,t){this._countsByFlag[ds].fromFlags(t),this._compiledPortions.setClippableFlags(e,t)}setCollidable(e,t){}setXRayed(e,t,s){this._countsByFlag[fs].fromFlags(t),this._setFlags(e,t,s)}setHighlighted(e,t,s){this._countsByFlag[gs].fromFlags(t),this._setFlags(e,t,s)}setSelected(e,t,s){this._countsByFlag[ms].fromFlags(t),this._setFlags(e,t,s)}setEdges(e,t,s){this._countsByFlag[_s]&&(this._countsByFlag[_s].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 Gs=65536,js=5e6;class Ws{constructor(){}set doublePrecisionEnabled(e){h.setDoublePrecisionEnabled(e)}get doublePrecisionEnabled(){return h.getDoublePrecisionEnabled()}set maxDataTextureHeight(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),Gs=e}get maxDataTextureHeight(){return Gs}set maxGeometryBatchSize(e){e<1e5?e=1e5:e>5e6&&(e=5e6),js=e}get maxGeometryBatchSize(){return js}}const zs=e=>{const t=[];for(let s=0;s<e;++s)t.push(s);return t},Xs={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(Xs,null,4));let e=0;Object.keys(Xs).forEach((t=>{t.startsWith("size")&&(e+=Xs[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/Xs.totalPolygons).toFixed(2)}`);let t={};Object.keys(Xs).forEach((s=>{s.startsWith("size")&&(t[s]=`${(Xs[s]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};const Ks=new Ws,Zs=Ks.maxDataTextureHeight,Js=h.vec3(),Ys=h.vec3(),$s=h.vec4();h.vec4();const qs=new Float32Array(16),ei=new Uint8Array(4),ti=h.identityMat4();class si extends Ns{constructor(e,t,s){super(e,t,s),Xs.numberOfLayers++,this._sortId=`TriDTX-${Xs.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);Xs[e]+=a,Xs.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);Xs[t]+=s,Xs.totalEdges+=s}}();return Xs.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&&Xs.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*Zs||i+n>4096*Zs)&&Xs.cannotCreatePortion.becauseTextureSize++,s&&=this._numVertices+r<=4096*Zs&&i+n<=4096*Zs}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),Xs[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||ti),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}),Xs.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=ii(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),u=c.textureData,d=function(e,t,s,i,r,n,A){return ii(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)},p=function(e,t,s){const i=e.length;if(0===i)throw"num "+t+" matrices===0";return d(e,i,16,l.FLOAT,512,t,s)},f=p(e.perObjectInstancePositioningMatrices,"sizeDataInstancesMatrices",!0),g=f.textureData,m=p(e.perObjectPositionsDecodeMatrices,"sizeDataPositionDecodeMatrices",!1),_=function(e,t,s,i,r){return d(e,t/s,s,i,4096,r,!1)},b=_(e.positionsCompressed,e.lenPositionsCompressed,3,l.UNSIGNED_SHORT,"sizeDataTexturePositions"),B=e.geometry8Bits.createDrawers(_,l.UNSIGNED_BYTE),y=e.geometry16Bits.createDrawers(_,l.UNSIGNED_SHORT),w=e.geometry32Bits.createDrawers(_,l.UNSIGNED_INT);this._buffer=null;let v=!1,C=!1,M=!1,E=0;const F=()=>{v=!0},x=a.on("rendering",(()=>{C&&(v=!1,C=!1,u.reloadData()),E=0})),U=(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)},I=(e,t,s,i)=>{const r=v||i;r?C=!0:++E>=10&&F(),u.setData(s,e,t,!r)},T=(e,t,s=!1)=>{ei.set([t&ds?255:0,0,1,2]),U(e,(e=>I(e,3,ei,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:T,setFlags:(e,t,s,i=!1)=>{Ls(t,s,!0,a,ei),U(e,(e=>I(e,2,ei,i)))},setFlags2:T,setDeferredFlags:()=>{},setColor:(e,t)=>{ei.set(t),U(e,(e=>I(e,0,ei,!1)))},setMatrix:(e,t)=>{U(e,(e=>{const s=v;s?C=!0:++E>=10&&F(),qs.set(t),g.setData(qs,e,0,!s)}))},setOffset:(e,t)=>{},getEachIndex:(e,t)=>{o&&U(e,(e=>o[e].indices.forEach((e=>t(e)))))},getEachVertex:(e,s)=>{o&&U(e,(e=>{const r=o[e],n=r.positionsCompressed,A=r.positionsDecodeMatrix,a=$s;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,h.decompressPosition(a,A),h.mulMat4v4(t.worldMatrix,a,a),h.addVec3(i,a,a),s(a)}))},precisionRayPickSurface:(e,t,s,i,r)=>!1,renderers:Hs(a,"dtx",n,t.saoEnabled,!1,!1,!0,((e,t)=>ri(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=h.transformPoint3(t.matrix,i,Js);s(n.uCameraEyeRtc,h.subVec3(A.eye,o,Ys)),s(n.perObjPosDecode,m),s(n.perVertIdCoords,b),s(n.perObjColsFlags,c),s(n.perObjectMatrix,f),e(n)}},s=function(t){return e((e=>{B.edges(e,t),y.edges(e,t),w.edges(e,t)}))};return{drawVertices:s(l.POINTS),drawEdges:s(l.LINES),drawSurface:e((e=>{const t=l.TRIANGLES;B.indices(e,t),y.indices(e,t),w.indices(e,t)}))}}(),destroy:()=>{M||(a.off(x),M=!0)}}}}const ii=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);Xs[A]+=f.byteLength,Xs.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)}}}},ri=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{geometryParameters:{attributes:{clippable:"(flags2.r > 0u)",color:p,flags:zs(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}}},ni=h.mat4(),Ai=h.mat4();function oi(e,t,s){const i=e.length,r=new Uint16Array(i),n=t[0],A=t[1],o=t[2],a=t[3]-n,l=t[4]-A,c=t[5]-o,u=65525,d=u/a,p=u/l,f=u/c,g=e=>e>=0?e:0;for(let t=0;t<i;t+=3)r[t+0]=Math.floor(g(e[t+0]-n)*d),r[t+1]=Math.floor(g(e[t+1]-A)*p),r[t+2]=Math.floor(g(e[t+2]-o)*f);return h.identityMat4(ni),h.translationMat4v(t,ni),h.identityMat4(Ai),h.scalingMat4v([a/u,l/u,c/u],Ai),h.mulMat4(ni,Ai,s),r}function ai(e,t){const s=e[0],i=e[1],r=e[2],n=e[3]-s,A=e[4]-i,o=e[5]-r,a=65525;return h.identityMat4(ni),h.translationMat4v(e,ni),h.identityMat4(Ai),h.scalingMat4v([n/a,A/a,o/a],Ai),h.mulMat4(ni,Ai,t),t}function li(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 ci(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 hi=new Float32Array(1),ui=new Float32Array(4),di=new Float32Array(3),pi=h.mat4(),fi=h.vec4([0,0,0,1]),gi=h.vec4(),mi=h.vec3(),_i=h.vec3(),bi=h.vec3(),Bi=h.vec3(),yi=h.vec3(),wi=h.vec3(),vi=h.vec3(),Ci=new Uint8Array(4),Mi=new Float32Array(96),Ei=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t},Fi=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}},xi=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 Ui extends Ns{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&&h.mat4(n),this._cfgUvDecodeMatrix=i.uvDecodeMatrix&&h.mat3(i.uvDecodeMatrix),this._instancedGeometry=i.geometry,this._textureSet=i.textureSet,this._modelAABB=!r&&h.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,u)=>{const d=this._portions.length>0&&this._portions[this._portions.length-1],p={indicesBaseIndex:d?d.indicesBaseIndex+d.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&&h.vec3(),matrix:u&&u.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(p),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=h.inverseMat4(h.transposeMat4(l,h.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,u=t.normals;if(a&&a.length>0)s.normals.append(a);else if(u&&u.length>0){const e=pi;l?(h.transposeMat4(l,e),h.inverseMat4(e,e)):h.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,u,d=new Float32Array([0,0,0,0]),p=new Float32Array([0,0,0,0]);for(u=0;u<s;u+=3)d[0]=t[u],d[1]=t[u+1],d[2]=t[u+2],h.transformVec3(e,d,p),h.normalizeVec3(p,p),a=A=li(p,"floor","floor"),o=ci(A),l=c=n(p,o),A=li(p,"ceil","floor"),o=ci(A),l=n(p,o),l>c&&(a=A,c=l),A=li(p,"floor","ceil"),o=ci(A),l=n(p,o),l>c&&(a=A,c=l),A=li(p,"ceil","ceil"),o=ci(A),l=n(p,o),l>c&&(a=A,c=l),i[r+u+0]=a[0],i[r+u+1]=a[1],i[r+u+2]=0}(e,u,u.length,t,0),s.normals.append(t)}const d=t.colors,p=t.colorsCompressed,f=t.color;if(d)if("points"===A)s.colors.append(d,1,255);else{const e=[];for(let t=0,s=d.length;t<s;t+=3)e.push(255*d[t]),e.push(255*d[t+1]),e.push(255*d[t+2]),e.push(255);s.colors.append(e)}else if(p)if("points"===A)s.colors.append(p);else{const e=[];for(let t=0,s=p.length;t<s;t+=3)e.push(p[t]),e.push(p[t+1]),e.push(p[t+2]),e.push(255);s.colors.append(e)}else f&&s.colors.append([f[0],f[1],f[2],"points"===A?1:t.opacity],r);const g=e=>e&&e.length>0&&e,m=g(t.uv)||g(t.uvCompressed);m&&s.uv.append(m);const _=t.edgeIndices;return _&&s.edgeIndices.append(_,1,1,e),h.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,u=c.canvas.gl,d=!!t,p=[],f=(e,t,s,i)=>{if(t.length>0){const r=t.constructor,[n,A]={[Uint8Array]:[1,u.UNSIGNED_BYTE],[Int8Array]:[1,u.BYTE],[Uint16Array]:[2,u.UNSIGNED_SHORT],[Int16Array]:[2,u.SHORT],[Uint32Array]:[4,u.UNSIGNED_INT],[Int32Array]:[4,u.INT],[Float32Array]:[4,u.FLOAT]}[r],o=u.createBuffer();p.push((()=>u.deleteBuffer(o)));const a=()=>u.bindBuffer(e,o),l=t=>{a(),u.bufferData(e,t,i)};l(t);const c=t.BYTES_PER_ELEMENT,h=t.length/s;return{bindBuffer:a,getData:(t=0,i=h-t)=>{a();const A=new r(i*s);return u.getBufferSubData(e,t*n*s,A,0,i*s),A},numItems:h,setData:l,setSubData:(t,s)=>{a(),u.bufferSubData(e,s*c,t)},type:A}}return null},g=(e,t,s,i=!1,r=!1)=>{const n=f(u.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(),u.vertexAttribPointer(e,t,n.type,!!r,0,0)}}},m=e=>{const t=f(u.ELEMENT_ARRAY_BUFFER,e,1,u.STATIC_DRAW);return t&&{getData:t.getData,bindIndicesBuffer:t.bindBuffer,indicesCount:e.length,indicesType:t.type}},_=n.reduce(((e,t)=>e+t.portionSize),0),b=g(new Float32Array(_),1,u.DYNAMIC_DRAW,d),B=(e,t)=>g(e,4,t,d&&"points"!==A,!0),y=d&&t.colorsCompressed?B(new Uint8Array(t.colorsCompressed),u.STATIC_DRAW):B(e.colors.compileBuffer(Uint8Array),u.DYNAMIC_DRAW),w=c.entityOffsetsEnabled&&g(new Float32Array(3*_),3,u.DYNAMIC_DRAW,d),v=g(e.metallicRoughness.compileBuffer(Uint8Array),2,u.STATIC_DRAW,d),C=g(e.pickColors.compileBuffer(Uint8Array),4,u.STATIC_DRAW,d),M=m(d?new Uint32Array(t.edgeIndices):e.edgeIndices.compileBuffer(Uint32Array)),E=d?"points"!==A&&t.indices&&new Uint32Array(t.indices):e.indices.compileBuffer(Uint32Array),F=E&&m(E),x=d?t.positionsCompressed:a?e.positions.compileBuffer(Uint16Array):oi(e.positions.compileBuffer(Float64Array),i,a=h.mat4()),U=x&&g(x,3,u.STATIC_DRAW);d||n.forEach((e=>{if(e.retainedGeometry){const t=3*e.portionBase;e.retainedGeometry.quantizedPositions=x.subarray(t,t+3*e.portionSize)}}));const I=d&&e.modelMatrixCol.map((e=>g(e.compileBuffer(Float32Array),4,u.STATIC_DRAW,!0))),T=!d&&e.normals.compileBuffer(Int8Array),P=T&&g(T,3,u.STATIC_DRAW,!1,!0),S=I&&P&&e.modelNormalMatrixCol.map((e=>g(e.compileBuffer(Float32Array),4,u.STATIC_DRAW,!0))),D=d?"points"!==A&&"lines"!==A&&t.uvCompressed&&{buf:g(t.uvCompressed,2,u.STATIC_DRAW),mat:t.uvDecodeMatrix}:function(){const t=e.uv.compileBuffer(Float32Array);if(0===t.length)return null;if(l)return{buf:g(t,2,u.STATIC_DRAW),mat:l};{const e=he.getUVBounds(t),s=he.compressUVs(t,e.min,e.max);return{buf:g(s.quantized,2,u.STATIC_DRAW),mat:h.mat3(s.decodeMatrix)}}}();this._buffer=null,xi.acquire(),p.push((()=>xi.release()));let k=null;const Q=(e,s,i,r=!1)=>{Ls(s,i,"points"!==A&&"lines"!==A,c,Ci);const o=s&ds?1:0;let a=0;a|=Ci[0],a|=Ci[1]<<4,a|=Ci[2]<<8,a|=Ci[3]<<12,a|=o<<16,hi[0]=a;const l=n[e],h=l.portionBase,u=l.portionSize;if(r&&!t)k||(k=new Float32Array(_)),Fi(k.subarray(h,h+u),hi);else if(b){const e=xi.getTypeArray(Float32Array,u);Fi(e,hi),b.setSubData(e,h)}},R="solid"===A;return{edgesColorOpaqueAllowed:()=>!0,solid:R,sortId:("points"===A?"Points":"lines"===A?"Lines":"Triangles")+(d?"Instancing":"Batching")+"Layer"+("points"!==A&&"lines"!==A?(R?"-solid":"-surface")+"-autoNormals"+(d?"":(o&&o.colorTexture?"-colorTexture":"")+(o&&o.metallicRoughnessTexture?"-metallicRoughnessTexture":"")):""),setClippableFlags:Q,setFlags:Q,setFlags2:(e,t,s)=>{},setDeferredFlags:()=>{k&&(b.setData(k),k=null)},setColor:(e,t)=>{if(y){const s=n[e],i=xi.getTypeArray(Uint8Array,4*s.portionSize);Fi(i,t.slice(0,4)),y.setSubData(i,4*s.portionBase)}},setMatrix:(e,t)=>{I&&I.forEach(((s,i)=>{ui[0]=t[i+0],ui[1]=t[i+4],ui[2]=t[i+8],ui[3]=t[i+12],s.setSubData(ui,4*e)}))},setOffset:(e,t)=>{if(c.entityOffsetsEnabled){const s=n[e];if(w){di.set(t);const e=xi.getTypeArray(Float32Array,3*s.portionSize);Fi(e,di),w.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=gi;r?e.set(r,0):e[0]=e[1]=e[2]=0,e[3]=1;const n=s.matrix;h.mulMat4v4(n,e,e);const A=i.quantizedPositions,o=fi;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],h.decompressPosition(o,a),i.matrix&&h.transformPoint3(i.matrix,o,o),o[3]=1,h.mulMat4v4(n,o,o),h.addVec3(e,o,o),t(o)}},readGeometryData:"points"!==A&&"lines"!==A&&(e=>{const t=!d&&n[e],i=t?F.getData(t.indicesBaseIndex,t.numIndices).map((e=>e-t.portionBase)):F.getData(),A=s.matrix,o=h.vec4();o.set(r,0),o[3]=1,h.mulMat4v4(A,o,o);const l=I&&h.mat4();if(l){const t=I[0].getData(e,1),s=I[1].getData(e,1),i=I[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=h.mat4();h.mulMat4(A,l?h.mulMat4(l,a,c):a,c),c[12]+=o[0],c[13]+=o[1],c[14]+=o[2];const u=t?U.getData(t.portionBase,t.portionSize):U.getData();return{indices:i,positions:h.transformPositions3(c,u,new Float64Array(u.length))}}),precisionRayPickSurface:(e,t,i,A,o)=>{const l=n[e].retainedGeometry;if(l){l.matrix&&!l.inverseMatrix&&(l.inverseMatrix=h.inverseMat4(l.matrix,h.mat4())),o&&l.inverseMatrix&&!l.normalMatrix&&(l.normalMatrix=h.transposeMat4(l.inverseMatrix,h.mat4()));const e=l.quantizedPositions,n=l.indices,c=l.offset,u=mi,d=_i;u.set(r?h.subVec3(t,r,bi):t),d.set(i),c&&h.subVec3(u,c),h.transformRay(s.worldNormalMatrix,u,d,u,d),l.inverseMatrix&&h.transformRay(l.inverseMatrix,u,d,u,d);const p=Bi,f=yi,g=wi;let m=!1,_=0;const b=vi;for(let i=0,B=n.length;i<B;i+=3){const B=3*n[i],y=3*n[i+1],w=3*n[i+2];if(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],g[0]=e[w],g[1]=e[w+1],g[2]=e[w+2],h.decompressPosition(p,a),h.decompressPosition(f,a),h.decompressPosition(g,a),h.rayTriangleIntersect(u,d,p,f,g,b)){l.matrix&&h.transformPoint3(l.matrix,b,b),h.transformPoint3(s.worldMatrix,b,b),c&&h.addVec3(b,c),r&&h.addVec3(b,r);const e=Math.abs(h.lenVec3(h.subVec3(b,t,[])));(!m||e>_)&&(_=e,A.set(b),o&&h.triangleNormal(p,f,g,o),m=!0)}}return m&&o&&(l.normalMatrix&&h.transformVec3(l.normalMatrix,o,o),h.transformVec3(s.worldNormalMatrix,o,o),h.normalizeVec3(o)),m}return!1},layerTextureSet:o,renderers:Hs(c,d?"instancing":"batching",A,s.saoEnabled,s.pbrEnabled&&D&&o&&o.colorTexture&&P&&v&&o.metallicRoughnessTexture,s.colorTextureEnabled&&D&&o&&o.colorTexture,!!P,(e=>Ti(e,d&&{hasModelNormalMat:!!S},c.entityOffsetsEnabled))),drawCalls:function(){const e={},t=t=>(i,r,o)=>{let l=0;Mi.set(s.rotationMatrix,0),Mi.set(o.viewMatrix,l+=16),Mi.set(o.projMatrix,l+=16),Mi.set(a,l+=16),r.needNormal()&&(Mi.set(s.worldNormalMatrix,l+=16),Mi.set(o.viewNormalMatrix,l+=16)),r.matrices.setInputValue(Mi),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(D.mat),i in e||(e[i]=[null,null,null]);const c=e[i],h=t?t.vertices?0:1:2;if(!c[h]){const e=u.createVertexArray();u.bindVertexArray(e);const s=(e,t)=>{e&&e.setInputValue&&t&&e.setInputValue(t)},i=r.attributes;s(i.position,U),s(i.normal,P),s(i.color,y),s(i.pickColor,C),s(i.uV,D&&D.buf),s(i.metallicRoughness,v),s(i.flags,b),s(i.offset,w),i.modelMatrixCol&&i.modelMatrixCol.forEach(((e,t)=>s(e,I[t]))),i.modelNormalMatrixCol&&i.modelNormalMatrixCol.forEach(((e,t)=>s(e,S[t])));const o=function(){const e=()=>{d?u.drawArraysInstanced(u.POINTS,0,U.numItems,n.length):u.drawArrays(u.POINTS,0,U.numItems)},s=(e,t)=>{t.bindIndicesBuffer();const s=t.indicesCount,i=t.indicesType;return()=>{d?u.drawElementsInstanced(e,s,i,0,n.length):u.drawElements(e,s,i,0)}};return"points"===A?e:"lines"===A?t&&t.vertices?e:s(u.LINES,F):t&&t.vertices?e:t&&M?s(u.LINES,M):s(u.TRIANGLES,F)}();u.bindVertexArray(null),p.push((()=>u.deleteVertexArray(e))),c[h]=()=>{u.bindVertexArray(e),o(),u.bindVertexArray(null)}}c[h]()};return{drawVertices:t({vertices:!0}),drawEdges:t({}),drawSurface:t(null)}}(),destroy:()=>{p.forEach((e=>e())),p.length=0}}}}const Ii=function(e){const t={toString:()=>(t.needed=!0,e)};return t},Ti=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&&Ei(3).map((e=>i("vec4","modelMatrixCol"+e))),modelNormalMatrixCol:t&&t.hasModelNormalMat&&Ei(3).map((e=>i("vec4","modelNormalMatrixCol"+e)))},n=Ii("aUv"),A=Ii("viewNormal"),o=Ii("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,geometryParameters:{attributes:{clippable:`((int(${r.flags}) >> 16 & 0xF) == 1)`,color:r.color,flags:Ei(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 Pi{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 Si{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const Di={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 ki{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 Qi=new ki;class Ri{constructor(e){this.manager=void 0!==e?e:Qi,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 Oi={};class Vi extends Ri{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=Di.get(e);if(void 0!==r)return this.manager.itemStart(e),F.scheduleTask((()=>{t&&t(r),this.manager.itemEnd(e)}),0),r;if(void 0!==Oi[e])return void Oi[e].push({onLoad:t,onProgress:s,onError:i});Oi[e]=[],Oi[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=Oi[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=>{Di.add(e,t);const s=Oi[e];delete Oi[e];for(let e=0,i=s.length;e<i;e++){const i=s[e];i.onLoad&&i.onLoad(t)}})).catch((t=>{const s=Oi[e];if(void 0===s)throw this.manager.itemError(e),t;delete Oi[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 Li{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 Hi=0;class Ni{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 Li,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 Vi;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new Vi;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=Ni.BasisWorker.toString(),i=["/* constants */","let _EngineFormat = "+JSON.stringify(Ni.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(Ni.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(Ni.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}))})),Hi>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Hi++}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(),Hi--}}Ni.BasisFormat={ETC1S:0,UASTC_4x4:1},Ni.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},Ni.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},Ni.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 Gi={};function ji(e){const t=e.scene.id;let s=Gi[t];return s||(s=new Ni({viewer:e}),Gi[t]=s,e.scene.on("destroyed",(()=>{delete Gi[t],s.destroy()}))),s}
7
+ "undefined"!=typeof window&&(window.__XEOKIT__={version:"2.6.94",commit:"32b1b9841f49a7817cfc809cbbee180486784356",built:"2025-11-03T13:06:26.987Z"}),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}}let n=!0,A=n?Float64Array:Float32Array;const o=new A(3),a=new A(16),l=new A(16),c=new A(4),h={setDoublePrecisionEnabled(e){n=e,A=n?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>n,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 A(e||2),vec3:e=>new A(e||3),vec4:e=>new A(e||4),mat3:e=>new A(e||9),mat3ToMat4:(e,t=new A(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 A(e||16),mat4ToMat3:(e,t=new A(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 A(2);for(let r=0,n=e.length;r<n;r++)h.splitDouble(e[r],i),t[r]=i[0],s[r]=i[1]},splitDouble(e,t){const s=A.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 A(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=>h.dotVec4(e,e),lenVec4:e=>Math.sqrt(h.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=>h.dotVec3(e,e),sqLenVec2:e=>h.dotVec2(e,e),lenVec3:e=>Math.sqrt(h.sqLenVec3(e)),distVec3:(()=>{const e=new A(3);return(t,s)=>h.lenVec3(h.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(h.sqLenVec2(e)),distVec2:(()=>{const e=new A(2);return(t,s)=>h.lenVec2(h.subVec2(t,s,e))})(),rcpVec3:(e,t)=>h.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/h.lenVec4(e);return h.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/h.lenVec3(e);return h.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/h.lenVec2(e);return h.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=h.dotVec3(e,t)/Math.sqrt(h.sqLenVec3(e)*h.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new A(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=h.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=h.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=h.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||h.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:()=>h.m4s(0),setMat4ToOnes:()=>h.m4s(1),diagonalMat4v:e=>new A([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)=>h.diagonalMat4v([e,t,s,i]),diagonalMat4s:e=>h.diagonalMat4c(e,e,e,e),identityMat4:(e=new A(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 A(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)=>h.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 A(9));const i=e[0],r=e[3],n=e[6],o=e[1],a=e[4],l=e[7],c=e[2],h=e[5],u=e[8],d=t[0],p=t[3],f=t[6],g=t[1],m=t[4],_=t[7],b=t[2],B=t[5],y=t[8];return s[0]=i*d+r*g+n*b,s[3]=i*p+r*m+n*B,s[6]=i*f+r*_+n*y,s[1]=o*d+a*g+l*b,s[4]=o*p+a*m+l*B,s[7]=o*f+a*_+l*y,s[2]=c*d+h*g+u*b,s[5]=c*p+h*m+u*B,s[8]=c*f+h*_+u*y,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=h.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||h.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||h.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new A(3);return(t,s,i,r)=>(e[0]=t,e[1]=s,e[2]=i,h.translationMat4v(e,r))})(),translationMat4s:(e,t)=>h.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>h.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=h.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,u,d,p,f,g;return c=o*a,u=a*l,d=l*o,p=o*r,f=a*r,g=l*r,(s=s||h.mat4())[0]=A*o*o+n,s[1]=A*c+g,s[2]=A*d-f,s[3]=0,s[4]=A*c-g,s[5]=A*a*a+n,s[6]=A*u+p,s[7]=0,s[8]=A*d+f,s[9]=A*u-p,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)=>h.rotationMat4v(e,[t,s,i],r),scalingMat4v:(e,t=h.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=h.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new A(3);return(t,s,i,r)=>(e[0]=t,e[1]=s,e[2]=i,h.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=>h.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=h.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,u=i*a,d=i*l,p=r*a,f=r*l,g=n*l,m=A*o,_=A*a,b=A*l;return s[0]=1-(p+g),s[1]=u+b,s[2]=d-_,s[3]=0,s[4]=u-b,s[5]=1-(c+g),s[6]=f+m,s[7]=0,s[8]=d+_,s[9]=f-m,s[10]=1-(c+p),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=h.vec4()){const i=h.clamp,r=e[0],n=e[4],A=e[8],o=e[1],a=e[5],l=e[9],c=e[2],u=e[6],d=e[10];return"XYZ"===t?(s[1]=Math.asin(i(A,-1,1)),Math.abs(A)<.99999?(s[0]=Math.atan2(-l,d),s[2]=Math.atan2(-n,r)):(s[0]=Math.atan2(u,a),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-i(l,-1,1)),Math.abs(l)<.99999?(s[1]=Math.atan2(A,d),s[2]=Math.atan2(o,a)):(s[1]=Math.atan2(-c,r),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(i(u,-1,1)),Math.abs(u)<.99999?(s[1]=Math.atan2(-c,d),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(u,d),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,d))):"XZY"===t&&(s[2]=Math.asin(-i(n,-1,1)),Math.abs(n)<.99999?(s[0]=Math.atan2(u,a),s[1]=Math.atan2(A,r)):(s[0]=Math.atan2(-l,d),s[1]=0)),s[0]*=h.RADTODEG,s[1]*=h.RADTODEG,s[2]*=h.RADTODEG,s},composeMat4:(e,t,s,i=h.mat4())=>(h.quaternionToRotationMat4(t,i),h.scaleMat4v(s,i),h.translateMat4v(e,i),i),decomposeMat4:(()=>{const e=new A(3),t=new A(16);return function(s,i,r,n){e[0]=s[0],e[1]=s[1],e[2]=s[2];let A=h.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const o=h.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const a=h.lenVec3(e);h.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,u=1/a;return t[0]*=l,t[1]*=l,t[2]*=l,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=u,t[9]*=u,t[10]*=u,h.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=h.mat4());const r=e[0],n=e[1],A=e[2],o=s[0],a=s[1],l=s[2],c=t[0],u=t[1],d=t[2];if(r===c&&n===u&&A===d)return h.identityMat4();let p,f,g,m,_,b,B,y,w,v;return p=r-c,f=n-u,g=A-d,v=1/Math.sqrt(p*p+f*f+g*g),p*=v,f*=v,g*=v,m=a*g-l*f,_=l*p-o*g,b=o*f-a*p,v=Math.sqrt(m*m+_*_+b*b),v?(v=1/v,m*=v,_*=v,b*=v):(m=0,_=0,b=0),B=f*b-g*_,y=g*m-p*b,w=p*_-f*m,v=Math.sqrt(B*B+y*y+w*w),v?(v=1/v,B*=v,y*=v,w*=v):(B=0,y=0,w=0),i[0]=m,i[1]=B,i[2]=p,i[3]=0,i[4]=_,i[5]=y,i[6]=f,i[7]=0,i[8]=b,i[9]=w,i[10]=g,i[11]=0,i[12]=-(m*r+_*n+b*A),i[13]=-(B*r+y*n+w*A),i[14]=-(p*r+f*n+g*A),i[15]=1,i},lookAtMat4c:(e,t,s,i,r,n,A,o,a)=>h.lookAtMat4v([e,t,s],[i,r,n],[A,o,a],[]),orthoMat4c(e,t,s,i,r,n,A){A||(A=h.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=h.mat4());const i=[e[0],e[1],e[2],0],r=[t[0],t[1],t[2],0];h.addVec4(r,i,a),h.subVec4(r,i,l);const n=2*i[2],A=l[0],o=l[1],c=l[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]=a[0]/A,s[9]=a[1]/o,s[10]=-a[2]/c,s[11]=-1,s[12]=0,s[13]=0,s[14]=-n*r[2]/c,s[15]=0,s},frustumMat4(e,t,s,i,r,n,A){A||(A=h.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],h.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=h.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=h.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||h.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||h.vec2())[0]=e[0]*s,t[1]=e[1]*s,t},unprojectVec3:(()=>{const e=new A(16),t=new A(16),s=new A(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||h.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||h.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=h.vec4())=>(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=h.vec4()){const i=e[0]*h.DEGTORAD/2,r=e[1]*h.DEGTORAD/2,n=e[2]*h.DEGTORAD/2,A=Math.cos(i),o=Math.cos(r),a=Math.cos(n),l=Math.sin(i),c=Math.sin(r),u=Math.sin(n);return"XYZ"===t?(s[0]=l*o*a+A*c*u,s[1]=A*c*a-l*o*u,s[2]=A*o*u+l*c*a,s[3]=A*o*a-l*c*u):"YXZ"===t?(s[0]=l*o*a+A*c*u,s[1]=A*c*a-l*o*u,s[2]=A*o*u-l*c*a,s[3]=A*o*a+l*c*u):"ZXY"===t?(s[0]=l*o*a-A*c*u,s[1]=A*c*a+l*o*u,s[2]=A*o*u+l*c*a,s[3]=A*o*a-l*c*u):"ZYX"===t?(s[0]=l*o*a-A*c*u,s[1]=A*c*a+l*o*u,s[2]=A*o*u-l*c*a,s[3]=A*o*a+l*c*u):"YZX"===t?(s[0]=l*o*a+A*c*u,s[1]=A*c*a+l*o*u,s[2]=A*o*u-l*c*a,s[3]=A*o*a-l*c*u):"XZY"===t&&(s[0]=l*o*a-A*c*u,s[1]=A*c*a-l*o*u,s[2]=A*o*u+l*c*a,s[3]=A*o*a+l*c*u),s},mat4ToQuaternion(e,t=h.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 u;const d=s+A+c;return d>0?(u=.5/Math.sqrt(d+1),t[3]=.25/u,t[0]=(l-o)*u,t[1]=(r-a)*u,t[2]=(n-i)*u):s>A&&s>c?(u=2*Math.sqrt(1+s-A-c),t[3]=(l-o)/u,t[0]=.25*u,t[1]=(i+n)/u,t[2]=(r+a)/u):A>c?(u=2*Math.sqrt(1+A-s-c),t[3]=(r-a)/u,t[0]=(i+n)/u,t[1]=.25*u,t[2]=(o+l)/u):(u=2*Math.sqrt(1+c-s-A),t[3]=(n-i)/u,t[0]=(r+a)/u,t[1]=(o+l)/u,t[2]=.25*u),t},vec3PairToQuaternion(e,t,s=h.vec4()){const i=Math.sqrt(h.dotVec3(e,e)*h.dotVec3(t,t));let r=i+h.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])):h.cross3Vec3(e,t,s),s[3]=r,h.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=h.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 A(16);return(t,s,i)=>(i=i||h.vec3(),h.quaternionToRotationMat4(t,e),h.mat4ToEuler(e,s,i),i)})(),mulQuaternions(e,t,s=h.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=h.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,u=l*r+a*i-A*n,d=l*n+A*r-o*i,p=-A*i-o*r-a*n;return s[0]=c*l+p*-A+u*-a-d*-o,s[1]=u*l+p*-o+d*-A-c*-a,s[2]=d*l+p*-a+c*-o-u*-A,s},quaternionToMat4(e,t){t=h.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,u=a*n,d=A*s,p=o*s,f=a*s,g=o*i,m=a*i,_=a*r;return t[0]=1-(g+_),t[1]=p+u,t[2]=f-c,t[4]=p-u,t[5]=1-(d+_),t[6]=m+l,t[8]=f+c,t[9]=m-l,t[10]=1-(d+g),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=h.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)=>h.normalizeQuaternion(h.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=h.vec4()){const s=(e=h.normalizeQuaternion(e,c))[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 A(e||6),AABB2:e=>new A(e||4),OBB3:e=>new A(e||32),OBB2:e=>new A(e||16),Sphere3:(e,t,s,i)=>new A([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 A(3),t=new A(3),s=new A(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],h.subVec3(t,e,s),Math.abs(h.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new A(3),t=new A(3),s=new A(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=h.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],u=i[5]-r[2];return n[0]+=A>o?A:o,n[1]+=a>l?a:l,n[2]+=c>u?c:u,Math.abs(h.lenVec3(n))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||h.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||h.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=h.AABB3())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MAX_DOUBLE,e[3]=h.MIN_DOUBLE,e[4]=h.MIN_DOUBLE,e[5]=h.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=h.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 A(3);return(t,s,i)=>{s=s||h.AABB3();let r,n,A,o=h.MAX_DOUBLE,a=h.MAX_DOUBLE,l=h.MAX_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE,d=h.MIN_DOUBLE;for(let s=0,p=t.length;s<p;s+=3)i?(e[0]=t[s+0],e[1]=t[s+1],e[2]=t[s+2],h.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>u&&(u=n),A>d&&(d=A);return s[0]=o,s[1]=a,s[2]=l,s[3]=c,s[4]=u,s[5]=d,s}})(),OBB3ToAABB3(e,t=h.AABB3()){let s,i,r,n=h.MAX_DOUBLE,A=h.MAX_DOUBLE,o=h.MAX_DOUBLE,a=h.MIN_DOUBLE,l=h.MIN_DOUBLE,c=h.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=h.AABB3()){let s,i,r,n=h.MAX_DOUBLE,A=h.MAX_DOUBLE,o=h.MAX_DOUBLE,a=h.MIN_DOUBLE,l=h.MIN_DOUBLE,c=h.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 A(3);return(t,s)=>{s=s||h.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(h.lenVec3(h.subVec3(t[i],s,e))),a>l&&(l=a);return s[3]=l,s}})(),positions3ToSphere3:(()=>{const e=new A(3),t=new A(3);return(s,i)=>{i=i||h.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 u;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],u=Math.abs(h.lenVec3(h.subVec3(e,i,t))),u>l&&(l=u);return i[3]=l,i}})(),OBB3ToSphere3:(()=>{const e=new A(3),t=new A(3);return(s,i)=>{i=i||h.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,u=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(h.lenVec3(h.subVec3(e,i,t))),c>u&&(u=c);return i[3]=u,i}})(),getSphere3Center:(e,t=h.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=h.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=h.AABB2())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MIN_DOUBLE,e[3]=h.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=h.AABB2()){let s,i,r,n,A=h.MAX_DOUBLE,o=h.MAX_DOUBLE,a=h.MIN_DOUBLE,l=h.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=h.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,u=A*o-r*l,d=r*a-n*o,p=Math.sqrt(c*c+u*u+d*d);return 0===p?(i[0]=0,i[1]=0,i[2]=0):(i[0]=c/p,i[1]=u/p,i[2]=d/p),i},rayTriangleIntersect:(()=>{const e=new A(3),t=new A(3),s=new A(3),i=new A(3),r=new A(3);return(n,A,o,a,l,c)=>{c=c||h.vec3();const u=h.subVec3(a,o,e),d=h.subVec3(l,o,t),p=h.cross3Vec3(A,d,s),f=h.dotVec3(u,p);if(f<1e-6)return null;const g=h.subVec3(n,o,i),m=h.dotVec3(g,p);if(m<0||m>f)return null;const _=h.cross3Vec3(g,u,r),b=h.dotVec3(A,_);if(b<0||m+b>f)return null;const B=h.dotVec3(d,_)/f;return c[0]=n[0]+B*A[0],c[1]=n[1]+B*A[1],c[2]=n[2]+B*A[2],c}})(),rayPlaneIntersect:(()=>{const e=new A(3),t=new A(3),s=new A(3),i=new A(3);return(r,n,A,o,a,l)=>{l=l||h.vec3(),n=h.normalizeVec3(n,e);const c=h.subVec3(o,A,t),u=h.subVec3(a,A,s),d=h.cross3Vec3(c,u,i);h.normalizeVec3(d,d);const p=-h.dotVec3(A,d),f=-(h.dotVec3(r,d)+p)/h.dotVec3(n,d);return l[0]=r[0]+f*n[0],l[1]=r[1]+f*n[1],l[2]=r[2]+f*n[2],l}})(),cartesianToBarycentric:(()=>{const e=new A(3),t=new A(3),s=new A(3);return(i,r,n,A,o)=>{const a=h.subVec3(A,r,e),l=h.subVec3(n,r,t),c=h.subVec3(i,r,s),u=h.dotVec3(a,a),d=h.dotVec3(a,l),p=h.dotVec3(a,c),f=h.dotVec3(l,l),g=h.dotVec3(l,c),m=u*f-d*d;if(0===m)return null;const _=1/m,b=(f*p-d*g)*_,B=(u*g-d*p)*_;return o[0]=1-b-B,o[1]=B,o[2]=b,o}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,i,r=h.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 A(3),t=new A(3),s=new A(3),i=new A(3),r=new A(3),n=new A(3);return(A,o,a)=>{let l,c;const u=new Array(A.length/3);let d,p,f,g,m,_,b;for(l=0,c=o.length;l<c;l+=3){d=o[l],p=o[l+1],f=o[l+2],e[0]=A[3*d],e[1]=A[3*d+1],e[2]=A[3*d+2],t[0]=A[3*p],t[1]=A[3*p+1],t[2]=A[3*p+2],s[0]=A[3*f],s[1]=A[3*f+1],s[2]=A[3*f+2],h.subVec3(t,e,i),h.subVec3(s,e,r);const a=h.vec3();h.normalizeVec3(h.cross3Vec3(i,r,n),a),u[d]||(u[d]=[]),u[p]||(u[p]=[]),u[f]||(u[f]=[]),u[d].push(a),u[p].push(a),u[f].push(a)}for(a=a&&a.length===A.length?a:new Float32Array(A.length),l=0,c=u.length;l<c;l++){g=u[l].length,m=0,_=0,b=0;for(let e=0;e<g;e++)m+=u[l][e][0],_+=u[l][e][1],b+=u[l][e][2];a[3*l]=m/g,a[3*l+1]=_/g,a[3*l+2]=b/g}return a}})(),buildTangents:(()=>{const e=new A(3),t=new A(3),s=new A(3),i=new A(3),r=new A(3),n=new A(3),o=new A(3);return(A,a,l)=>{const c=new Float32Array(A.length);for(let u=0;u<a.length;u+=3){let d=a[u];const p=A.subarray(3*d,3*d+3),f=l.subarray(2*d,2*d+2);d=a[u+1];const g=A.subarray(3*d,3*d+3),m=l.subarray(2*d,2*d+2);d=a[u+2];const _=A.subarray(3*d,3*d+3),b=l.subarray(2*d,2*d+2),B=h.subVec3(g,p,e),y=h.subVec3(_,p,t),w=h.subVec2(m,f,s),v=h.subVec2(b,f,i),C=1/(w[0]*v[1]-w[1]*v[0]),M=h.mulVec3Scalar(h.subVec3(h.mulVec3Scalar(B,v[1],r),h.mulVec3Scalar(y,w[1],n),o),C,n);let E;for(let e=0;e<3;e++)E=3*a[u+e],c[E]+=M[0],c[E+1]+=M[1],c[E+2]+=M[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,u;const d=1e4;let p,f,g,m,_,b;for(f=0,m=e.length;f<m;f+=3){p=f/3,a=e[f],l=e[f+1],c=e[f+2],u=`${Math.round(a*d)}_${Math.round(l*d)}_${Math.round(c*d)}`,void 0===r[u]?r[u]=[p]:r[u].push(p);const s=h.normalizeVec3([t[f],t[f+1],t[f+2]]);n[p]=s,o=h.vec4([s[0],s[1],s[2],1]),A[p]=o}for(u in r)if(r.hasOwnProperty(u)){const e=r[u],t=e.length;for(f=0;f<t;f++){const s=e[f];for(o=A[s],g=0;g<t;g++){if(f===g)continue;const t=e[g];_=n[s],b=n[t];Math.abs(h.angleVec3(_,b)/h.DEGTORAD)<i&&(o[0]+=b[0],o[1]+=b[1],o[2]+=b[2],o[3]+=1)}}}for(f=0,m=t.length;f<m;f+=3)o=A[f/3],t[f+0]=o[0]/o[3],t[f+1]=o[1]/o[3],t[f+2]=o[2]/o[3]},transformRay:(()=>{const e=new A(4),t=new A(4);return(s,i,r,n,A)=>{e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=1,h.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],h.transformVec3(s,e,t),h.normalizeVec3(t),A[0]=t[0],A[1]=t[1],A[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new A(16),t=new A(4),s=new A(4),i=(t,s,i,r,n)=>{n[0]=t,n[1]=s,n[2]=i,n[3]=1,h.transformVec4(e,n,n),r||h.mulVec4Scalar(n,1/n[3])};return(r,n,A,o,a,l,c)=>{const u="ortho"===o;h.mulMat4(A,n,e),h.inverseMat4(e,e);const d=2*a[0]/r.clientWidth-1,p=1-2*a[1]/r.clientHeight;i(d,p,-1,u,t),i(d,p,1,u,s),l[0]=t[0],l[1]=t[1],l[2]=t[2],h.subVec3(s,t,c),h.normalizeVec3(c)}})(),canvasPosToLocalRay:(()=>{const e=new A(3),t=new A(3);return(s,i,r,n,A,o,a,l)=>{h.canvasPosToWorldRay(s,i,r,n,o,e,t),h.worldRayToLocalRay(A,e,t,a,l)}})(),worldRayToLocalRay:(()=>{const e=new A(16),t=new A(4),s=new A(4);return(i,r,n,A,o)=>{const a=h.inverseMat4(i,e);t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=1,h.transformVec4(a,t,s),A[0]=s[0],A[1]=s[1],A[2]=s[2],h.transformVec3(a,n,o)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,i,r,n){const o=new A(6),a={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:o};let l,c;for(o[0]=o[1]=o[2]=Number.POSITIVE_INFINITY,o[3]=o[4]=o[5]=Number.NEGATIVE_INFINITY,l=0,c=s.length;l<c;++l){var h=3*s[l];for(let e=0;e<3;++e){const t=3*i[h+e];r[t]<o[0]&&(o[0]=r[t]),r[t]>o[3]&&(o[3]=r[t]),r[t+1]<o[1]&&(o[1]=r[t+1]),r[t+1]>o[4]&&(o[4]=r[t+1]),r[t+2]<o[2]&&(o[2]=r[t+2]),r[t+2]>o[5]&&(o[5]=r[t+2])}}if(s.length<20||n>10)return a.triangles=s,a.leaf=!0,a;e[0]=o[3]-o[0],e[1]=o[4]-o[1],e[2]=o[5]-o[2];let u=0;e[1]>e[u]&&(u=1),e[2]>e[u]&&(u=2),a.splitDim=u;const d=(o[u]+o[u+3])/2,p=new Array(s.length);let f=0;const g=new Array(s.length);let m=0;for(l=0,c=s.length;l<c;++l){const e=i[h=3*s[l]],t=3*i[h+1],n=3*i[h+2];r[3*e+u]<=d||r[t+u]<=d||r[n+u]<=d?p[f++]=s[l]:g[m++]=s[l]}return p.length=f,g.length=m,a.left=t(p,i,r,n+1),a.right=t(g,i,r,n+1),a}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}};h.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=h.vec3(),c=h.vec3(),u=h.vec3(),d=h.vec3(),p=h.vec3(),f=h.vec3(),g=h.vec3();return function(m,_,b,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]}(m,_),function(t,s){n=0;for(let m=0,_=t;m<_;m+=3){const t=3*i[m],_=3*i[m+1],b=3*i[m+2];s?(A[0]=e[t],A[1]=e[t+1],A[2]=e[t+2],o[0]=e[_],o[1]=e[_+1],o[2]=e[_+2],a[0]=e[b],a[1]=e[b+1],a[2]=e[b+2],h.decompressPosition(A,s,l),h.decompressPosition(o,s,c),h.decompressPosition(a,s,u)):(l[0]=e[t],l[1]=e[t+1],l[2]=e[t+2],c[0]=e[_],c[1]=e[_+1],c[2]=e[_+2],u[0]=e[b],u[1]=e[b+1],u[2]=e[b+2]),h.subVec3(u,c,d),h.subVec3(l,c,p),h.cross3Vec3(d,p,f),h.normalizeVec3(f,g);const B=r[n]||(r[n]={normal:h.vec3()});B.normal[0]=g[0],B.normal[1]=g[1],B.normal[2]=g[2],n++}}(_.length,b);const y=[],w=Math.cos(h.DEGTORAD*B),v={};let C,M,E,F,x,U,I,T,P,S,D,k=!1;for(let e=0,t=_.length;e<t;e+=3){const t=e/3;for(let s=0;s<3;s++)C=i[e+s],M=i[e+(s+1)%3],E=Math.min(C,M),F=Math.max(C,M),x=E+","+F,void 0===v[x]?v[x]={index1:E,index2:F,face1:t,face2:void 0}:v[x].face2=t}for(x in v)U=v[x],void 0!==U.face2&&(I=r[U.face1].normal,T=r[U.face2].normal,P=h.dotVec3(I,T),P>w)||(S=s[U.index1],D=s[U.index2],(!k&&S>65535||D>65535)&&(k=!0),y.push(S),y.push(D));return k?new Uint32Array(y):new Uint16Array(y)}}(),h.planeClipsPositions3=function(e,t,s,i=3){for(let r=0,n=s.length;r<n;r+=i){if(o[0]=s[r+0]-e[0],o[1]=s[r+1]-e[1],o[2]=s[r+2]-e[2],o[0]*t[0]+o[1]*t[1]+o[2]*t[2]<0)return!0}return!1};const u=new Float32Array(3);class d{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 p={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 f=[["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 g(e,t){return(t&&4!==t?[0,6]:[0,6,12,18]).map((function(t){return f.substr(parseInt(e/(1<<t))%64,1)})).reverse().join("")}const m=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 _={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 g(t[0],2)+[1,4,7,10,13].map((function(e){return g((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);F.scheduleTask((()=>{t(e)}))}catch(e){F.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:m,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 _.isString(e)||_.isNumeric(e)},isSameComponent:function(e,t){return!(!e||!t)&&(_.isNumeric(e)||_.isString(e)?`${e}`:e.id)===(_.isNumeric(t)||_.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 _.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 _.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}},b={},B=new e,y=new d,w={sceneId:null,time:null,startTime:null,prevTime:null,deltaTime:null},v=[];let C,M=0,E=0;const F=new function(){this.version="1.0.0",this.scenes={},this._superTypes={},this._addScene=function(e){if(e.id){if(F.scenes[e.id])return void console.error(`[ERROR] Scene ${_.inQuotes(e.id)} already exists`)}else e.id=B.addItem({});F.scenes[e.id]=e;const t=e.ticksPerOcclusionTest,s=e.ticksPerRender;b[e.id]={ticksPerOcclusionTest:t,ticksPerRender:s,renderCountdown:s},p.components.scenes++,e.once("destroyed",(()=>{B.removeItem(e.id),delete F.scenes[e.id],delete b[e.id],p.components.scenes--}))},this.clear=function(){let e;for(const t in F.scenes)F.scenes.hasOwnProperty(t)&&(e=F.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete F.scenes[e.id]))},this.scheduleTask=function(e,t=null){y.push(e),y.push(t)},this.runTasks=function(e=-1){let t,s,i=(new Date).getTime(),r=0;for(;y.length>0&&(e<0||i<e);)t=y.shift(),s=y.shift(),s?t.call(s):t(),i=(new Date).getTime(),r++;return r},this.getNumTasks=function(){return y.length}},x=function(){let e=Date.now();if(C=e-M,M>0&&C>0){var t=1e3/C;E+=t,v.push(t),v.length>=30&&(E-=v.shift()),p.frame.fps=Math.round(E/v.length)}for(let e in F.scenes)F.scenes[e].compile();I(e),M=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))})()}((()=>{x()}),100);const U=function(){let e=Date.now();if(C=e-M,M>0&&C>0){var t=1e3/C;E+=t,v.push(t),v.length>=30&&(E-=v.shift()),p.frame.fps=Math.round(E/v.length)}I(e),function(e){for(var t in w.time=e,F.scenes)if(F.scenes.hasOwnProperty(t)){var s=F.scenes[t];w.sceneId=t,w.startTime=s.startTime,w.deltaTime=null!=w.prevTime?w.time-w.prevTime:0,s.fire("tick",w,!0)}w.prevTime=e}(e),function(){const e=F.scenes,t=!1;let s,i,r,n,A;for(A in e)e.hasOwnProperty(A)&&(s=e[A],i=b[A],i||(i=b[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(x):requestAnimationFrame(U)};function I(e){const t=F.runTasks(e+10),s=F.getNumTasks();p.frame.tasksRun=t,p.frame.tasksScheduled=s,p.frame.tasksBudget=10}U();class T{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 T))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+" "+_.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&&(_.isNumeric(s)||_.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+_.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+" "+_.inQuotes(s.id));if(n&&!s.isType(n))return void this.error("Expected a "+n+" type or subtype: "+s.type+" "+_.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&&(_.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&&(_.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],_.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(!_.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(!_.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():F.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}scheduleTask(e){F.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 P=h.vec3(),S=h.vec3(),D=h.mat4();class k{constructor(){this.normal=h.vec3(),this.offset=0,this.testVertex=h.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 Q{constructor(){this.planes=[new k,new k,new k,new k,new k,new k]}}function R(e,t,s){const i=h.mulMat4(s,t,D),r=i[0],n=i[1],A=i[2],o=i[3],a=i[4],l=i[5],c=i[6],u=i[7],d=i[8],p=i[9],f=i[10],g=i[11],m=i[12],_=i[13],b=i[14],B=i[15];e.planes[0].set(o-r,u-a,g-d,B-m),e.planes[1].set(o+r,u+a,g+d,B+m),e.planes[2].set(o-n,u-l,g-p,B-_),e.planes[3].set(o+n,u+l,g+p,B+_),e.planes[4].set(o-A,u-c,g-f,B-b),e.planes[5].set(o+A,u+c,g+f,B+b)}function O(e,t){let s=Q.INSIDE;const i=P,r=S;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 Q.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=Q.INTERSECT)}return s}Q.INSIDE=0,Q.INTERSECT=1,Q.OUTSIDE=2;class V extends T{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=h.vec2(),this._canvasMarqueeCorner2=h.vec2(),this._canvasMarquee=h.AABB2(),this._marqueeFrustum=new Q,this._marqueeFrustumProjMat=h.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!==V.PICK_MODE_INSIDE&&e!==V.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===V.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=Q.INTERSECT)=>{if(i===Q.INTERSECT&&(i=O(this._marqueeFrustum,s.aabb)),i!==Q.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===V.PICK_MODE_INSIDE){O(this._marqueeFrustum,r)===Q.INSIDE&&e.push(i.id)}else{O(this._marqueeFrustum,r)!==Q.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,u=-(this._canvasMarquee[1]-r)*A+1,d=this.viewer.scene.camera.frustum.near*(17*o);h.frustumMat4(a,l,c*o,u*o,d,1e4,this._marqueeFrustumProjMat),R(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)}}V.PICK_MODE_INTERSECTS=0,V.PICK_MODE_INSIDE=1;class L{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 H{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=N(e,s);return i?t?G(i,t):i:null}translatePlurals(e,t,s){const i=this._messages[this._locale];if(!i)return null;let r=N(e,i);return r=0===(t=parseInt(""+t,10))?r.zero:t>1?r.other:r.one,r?(r=G(r,[t]),s&&(r=G(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 N(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 G(e,t=[]){return e.replace(/\{\{|\}\}|\{(\d+)\}/g,(function(e,s){return"{{"===e?"{":"}}"===e?"}":t[s]}))}class j extends T{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=h.subVec3(n,r,[]);return h.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+=h.lenVec3(h.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 W extends j{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=h.vec3();return l[0]=h.catmullRomInterpolate(n[0],A[0],o[0],a[0],r),l[1]=h.catmullRomInterpolate(n[1],A[1],o[1],a[1],r),l[2]=h.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 z=h.vec3();const X=h.vec3(),K=h.vec3(),Z=h.vec3(),J=h.vec3(),Y=h.vec3();class $ extends T{get type(){return"CameraFlightAnimation"}constructor(e,t={}){super(e,t),this._look1=h.vec3(),this._eye1=h.vec3(),this._up1=h.vec3(),this._look2=h.vec3(),this._eye2=h.vec3(),this._up2=h.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((_.isNumeric(i)||_.isString(i))&&(l=i,i=this.scene.components[l],!i))return this.error("Component not found: "+_.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=h.getAABB3Center(n);this._look2=c||t;const s=h.subVec3(this._eye1,this._look1,X),i=h.normalizeVec3(s),r=c?h.getAABB3DiagPoint(n,c):h.getAABB3Diag(n),A=e.fitFOV||this._fitFOV,o=Math.abs(r/Math.tan(A*h.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,F.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((_.isNumeric(t)||_.isString(t))&&(i=t,t=this.scene.components[i],!t))return void this.error("Component not found: "+_.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?h.getAABB3DiagPoint(s,o):h.getAABB3Diag(s);let i;n=o||h.getAABB3Center(s,n),this._trail?h.subVec3(t.look,n,Y):h.subVec3(t.eye,t.look,Y),h.normalizeVec3(Y);i=(void 0!==e.fit?e.fit:this._fit)?Math.abs(a/Math.tan((e.fitFOV||this._fitFOV)*h.DEGTORAD)):h.lenVec3(h.subVec3(t.eye,t.look,X)),h.mulVec3Scalar(Y,i),t.eye=h.addVec3(n,Y,X),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?$._ease(e,0,1,1):e,i=this.scene.camera;if(this._flyingEye||this._flyingLook?this._flyingEye?(h.subVec3(i.eye,i.look,Y),i.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,Z),i.look=h.subVec3(Z,Y,K)):this._flyingLook&&(i.look=h.lerpVec3(s,0,1,this._look1,this._look2,K),i.up=h.lerpVec3(s,0,1,this._up1,this._up2,J)):this._flyingEyeLookUp&&(i.eye=h.lerpVec3(s,0,1,this._eye1,this._eye2,Z),i.look=h.lerpVec3(s,0,1,this._look1,this._look2,K),i.up=h.lerpVec3(s,0,1,this._up1,this._up2,J)),this._projection2){const t="ortho"===this._projection2?$._easeOutExpo(e,0,1,1):$._easeInCubic(e,0,1,1);i.customProjection.matrix=h.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();F.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 q extends T{get type(){return"CameraPathAnimation"}constructor(e,t={}){super(e,t),this._cameraFlightAnimation=new $(this),this._t=0,this.state=q.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 q.SCRUBBING:return;case q.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=q.SCRUBBING,this._t=this._cameraPath.frames[t-1].t,void this.fire("stopped");e.loadFrame(this._t);break;case q.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=q.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=q.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=q.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=q.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=q.SCRUBBING)}scrubToFrame(e){const t=this._cameraPath;if(!t)return;if(!this.scene.camera)return;t.frames[e]?(t.loadFrame(this._t),this.state=q.SCRUBBING):this.error("playToFrame - frame index out of range: "+e)}stop(){this.state=q.SCRUBBING,this.fire("stopped")}destroy(){super.destroy(),this.scene.off(this._tick)}}q.STOPPED=0,q.SCRUBBING=1,q.PLAYING=2,q.PLAYING_TO=3;class ee extends T{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),p.memory.meshes++}destroy(){super.destroy(),p.memory.meshes--}}const te=new e({});class se{constructor(e){this.id=te.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){te.removeItem(this.id)}}class ie{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 re=function(){const e=[],t=[],s=[],i=[],r=[];let n=0;const A=new Uint16Array(3),o=new Uint16Array(3),a=new Uint16Array(3),l=h.vec3(),c=h.vec3(),u=h.vec3(),d=h.vec3(),p=h.vec3(),f=h.vec3(),g=h.vec3();return function(m,_,b,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]}(m,_),function(t,s){n=0;for(let m=0,_=t;m<_;m+=3){const t=3*i[m],_=3*i[m+1],b=3*i[m+2];s?(A[0]=e[t],A[1]=e[t+1],A[2]=e[t+2],o[0]=e[_],o[1]=e[_+1],o[2]=e[_+2],a[0]=e[b],a[1]=e[b+1],a[2]=e[b+2],h.decompressPosition(A,s,l),h.decompressPosition(o,s,c),h.decompressPosition(a,s,u)):(l[0]=e[t],l[1]=e[t+1],l[2]=e[t+2],c[0]=e[_],c[1]=e[_+1],c[2]=e[_+2],u[0]=e[b],u[1]=e[b+1],u[2]=e[b+2]),h.subVec3(u,c,d),h.subVec3(l,c,p),h.cross3Vec3(d,p,f),h.normalizeVec3(f,g);const B=r[n]||(r[n]={normal:h.vec3()});B.normal[0]=g[0],B.normal[1]=g[1],B.normal[2]=g[2],n++}}(_.length,b);const y=[],w=Math.cos(h.DEGTORAD*B),v={};let C,M,E,F,x,U,I,T,P,S,D,k=!1;for(let e=0,t=_.length;e<t;e+=3){const t=e/3;for(let s=0;s<3;s++)C=i[e+s],M=i[e+(s+1)%3],E=Math.min(C,M),F=Math.max(C,M),x=E+","+F,void 0===v[x]?v[x]={index1:E,index2:F,face1:t,face2:void 0}:v[x].face2=t}for(x in v)U=v[x],void 0!==U.face2&&(I=r[U.face1].normal,T=r[U.face2].normal,P=h.dotVec3(I,T),P>w)||(S=s[U.index1],D=s[U.index2],(!k&&S>65535||D>65535)&&(k=!0),y.push(S),y.push(D));return k?new Uint32Array(y):new Uint16Array(y)}}();const ne=function(){const e=h.mat4(),t=h.mat4();return function(s,i){i=i||h.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 h.identityMat4(e),h.translationMat4v(s,e),h.identityMat4(t),h.scalingMat4v([o/c,a/c,l/c],t),h.mulMat4(e,t,i),i}}();var Ae=function(){const e=h.mat4(),t=h.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])));h.identityMat4(e),h.translationMat4v(i,e),h.identityMat4(t),h.scalingMat4v([(r[0]-i[0])/65535,(r[1]-i[1])/65535,(r[2]-i[2])/65535],t);return{quantized:n,decodeMatrix:h.mulMat4(e,t,h.identityMat4())}}}();var oe=function(){const e=h.mat3(),t=h.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])));h.identityMat3(e),h.translationMat3v(i,e),h.identityMat3(t),h.scalingMat3v([(r[0]-i[0])/65535,(r[1]-i[1])/65535],t);return{quantized:n,decodeMatrix:h.mulMat3(e,t,h.identityMat3())}}}();function ae(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 le(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 ce(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const he={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:ne,compressPositions:Ae,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:oe,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=ae(e,o,"floor","floor"),i=le(s),n=A=ce(e,o,i),s=ae(e,o,"ceil","floor"),i=le(s),n=ce(e,o,i),n>A&&(r=s,A=n),s=ae(e,o,"floor","ceil"),i=le(s),n=ce(e,o,i),n>A&&(r=s,A=n),s=ae(e,o,"ceil","ceil"),i=le(s),n=ce(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}},ue=p.memory,de=h.AABB3();class pe extends ee{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new se({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const 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=he.getPositionsBounds(t.positions),i=he.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=he.getUVBounds(t.uv),i=he.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=he.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(),ue.meshes++,s.indices&&(s.indicesBuf=new ie(i,i.ELEMENT_ARRAY_BUFFER,s.indices,s.indices.length,1,i.STATIC_DRAW),ue.indices+=s.indicesBuf.numItems),s.positions&&(s.positionsBuf=new ie(i,i.ARRAY_BUFFER,s.positions,s.positions.length,3,i.STATIC_DRAW),ue.positions+=s.positionsBuf.numItems),s.normals){let e=s.compressGeometry;s.normalsBuf=new ie(i,i.ARRAY_BUFFER,s.normals,s.normals.length,3,i.STATIC_DRAW,e),ue.normals+=s.normalsBuf.numItems}s.colors&&(s.colorsBuf=new ie(i,i.ARRAY_BUFFER,s.colors,s.colors.length,4,i.STATIC_DRAW),ue.colors+=s.colorsBuf.numItems),s.uv&&(s.uvBuf=new ie(i,i.ARRAY_BUFFER,s.uv,s.uv.length,2,i.STATIC_DRAW),ue.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=re(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new ie(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),ue.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=h.buildPickTriangles(e.positions,e.indices,e.compressGeometry),i=s.positions,r=s.colors;this._pickTrianglePositionsBuf=new ie(t,t.ARRAY_BUFFER,i,i.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new ie(t,t.ARRAY_BUFFER,r,r.length,4,t.STATIC_DRAW,!0),ue.positions+=this._pickTrianglePositionsBuf.numItems,ue.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),he.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=he.getPositionsBounds(e),i=he.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),he.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),he.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=h.AABB3()),h.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=h.OBB3()),h.positions3ToAABB3(this._state.positions,de,this._state.positionsDecodeMatrix),h.AABB3ToOBB3(de,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=[h.vec3(),h.vec3(),h.vec3(),h.vec3()];let r=0;const n=h.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]);h.addVec3(e,A,i[3]),h.addVec3(o,i[3],i[3]);const a=h.lenVec3(h.cross3Vec3(h.subVec3(A,e,i[1]),h.subVec3(o,e,i[2]),i[0]))/2;r+=a,h.mulVec3Scalar(i[3],a,i[3]),h.addVec3(n,i[3],n)}this._metrics={surfaceArea:r,centroid:h.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(),ue.meshes--}}const fe=p.memory,ge=h.AABB3();class me extends ee{get type(){return"VBOGeometry"}get isVBOGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new se({compressGeometry:!0,primitive:null,primitiveName:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._aabb=null,this._obb=h.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=he.getPositionsBounds(t.positions),n=he.compressPositions(t.positions,e.min,e.max);r=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix,s.positionsBuf=new ie(i,i.ARRAY_BUFFER,r,r.length,3,i.STATIC_DRAW),fe.positions+=s.positionsBuf.numItems,h.positions3ToAABB3(t.positions,this._aabb),h.positions3ToAABB3(r,ge,s.positionsDecodeMatrix),h.AABB3ToOBB3(ge,this._obb)}if(t.colors){const e=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors);s.colorsBuf=new ie(i,i.ARRAY_BUFFER,e,e.length,4,i.STATIC_DRAW),fe.colors+=s.colorsBuf.numItems}if(t.uv){const e=he.getUVBounds(t.uv),r=he.compressUVs(t.uv,e.min,e.max),n=r.quantized;s.uvDecodeMatrix=r.decodeMatrix,s.uvBuf=new ie(i,i.ARRAY_BUFFER,n,n.length,2,i.STATIC_DRAW),fe.uvs+=s.uvBuf.numItems}if(t.normals){const e=he.compressNormals(t.normals);let r=s.compressGeometry;s.normalsBuf=new ie(i,i.ARRAY_BUFFER,e,e.length,3,i.STATIC_DRAW,r),fe.normals+=s.normalsBuf.numItems}{const e=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices);s.indicesBuf=new ie(i,i.ELEMENT_ARRAY_BUFFER,e,e.length,1,i.STATIC_DRAW),fe.indices+=s.indicesBuf.numItems;const n=re(r,e,s.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new ie(i,i.ELEMENT_ARRAY_BUFFER,n,n.length,1,i.STATIC_DRAW),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)}this._buildHash(),fe.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(),fe.meshes--}}var _e={};function be(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 _.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 Be(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 _.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 ye(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=[],B=[];let y,w,v,C,M,E,F,x,U,I,T;const P=(90-180*Math.atan(i/(s-t))/Math.PI)/90;for(y=0;y<=n;y++)for(M=t-y*f,E=h-y*u,w=0;w<=r;w++)v=Math.sin(w*d),C=Math.cos(w*d),m.push(M*v),m.push(P),m.push(M*C),b.push(w*p),b.push(1*y/n),g.push(M*v+a),g.push(E+l),g.push(M*C+c);for(y=0;y<n;y++)for(w=0;w<=r;w++)F=y*(r+1)+w,x=F+r,B.push(F),B.push(x),B.push(x+1),B.push(F),B.push(x+1),B.push(F+1);if(!A&&t>0){for(U=g.length/3,m.push(0),m.push(1),m.push(0),b.push(.5),b.push(.5),g.push(0+a),g.push(h+l),g.push(0+c),w=0;w<=r;w++)v=Math.sin(w*d),C=Math.cos(w*d),I=.5*Math.sin(w*d)+.5,T=.5*Math.cos(w*d)+.5,m.push(t*v),m.push(1),m.push(t*C),b.push(I),b.push(T),g.push(t*v+a),g.push(h+l),g.push(t*C+c);for(w=0;w<r;w++)o=U,F=U+1+w,B.push(F),B.push(F+1),B.push(o)}if(!A&&s>0){for(U=g.length/3,m.push(0),m.push(-1),m.push(0),b.push(.5),b.push(.5),g.push(0+a),g.push(0-h+l),g.push(0+c),w=0;w<=r;w++)v=Math.sin(w*d),C=Math.cos(w*d),I=.5*Math.sin(w*d)+.5,T=.5*Math.cos(w*d)+.5,m.push(s*v),m.push(-1),m.push(s*C),b.push(I),b.push(T),g.push(s*v+a),g.push(0-h+l),g.push(s*C+c);for(w=0;w<r;w++)o=U,F=U+1+w,B.push(o),B.push(F+1),B.push(F)}return _.apply(e,{positions:g,normals:m,uv:b,indices:B})}function we(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 _.apply(e,{primitive:"lines",positions:n,indices:A})}function ve(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),b=new Float32Array(d*p*3),B=new Float32Array(d*p*2);let y,w,v,C,M,E,F,x=0,U=0;for(y=0;y<p;y++){const e=y*g-c;for(w=0;w<d;w++)v=w*f-l,m[x]=v+A,m[x+1]=o,m[x+2]=-e+a,b[x+1]=1,B[U]=w/h,B[U+1]=(u-y)/u,x+=3,U+=2}x=0;const I=new(m.length/3>65535?Uint32Array:Uint16Array)(h*u*6);for(y=0;y<u;y++)for(w=0;w<h;w++)C=w+d*y,M=w+d*(y+1),E=w+1+d*(y+1),F=w+1+d*y,I[x]=F,I[x+1]=M,I[x+2]=C,I[x+3]=F,I[x+4]=E,I[x+5]=M,x+=6;return _.apply(e,{positions:m,normals:b,uv:B,indices:I})}function Ce(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,F;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,b=Math.sin(m),B=Math.cos(m),y=B*f,w=g,v=b*f,C=1-d/o,M=u/A,l.push(y),l.push(w),l.push(v),c.push(C),c.push(M),a.push(s+n*y),a.push(i+n*w),a.push(r+n*v);for(u=0;u<A;u++)for(d=0;d<o;d++)E=u*(o+1)+d,F=E+o+1,h.push(E+1),h.push(F+1),h.push(F),h.push(E+1),h.push(F),h.push(E);return _.apply(e,{positions:a,normals:l,uv:c,indices:h})}function Me(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=[],u=[],d=[],p=[];let f,g,m,b,B,y,w,v,C,M,E,F;for(v=0;v<=r;v++)for(w=0;w<=i;w++)f=w/i*n,g=.785398+v/r*Math.PI*2,o=t*Math.cos(f),a=t*Math.sin(f),m=(t+s*Math.cos(g))*Math.cos(f),b=(t+s*Math.cos(g))*Math.sin(f),B=s*Math.sin(g),c.push(m+o),c.push(b+a),c.push(B+l),d.push(1-w/i),d.push(v/r),y=h.normalizeVec3(h.subVec3([m,b,B],[o,a,l],[]),[]),u.push(y[0]),u.push(y[1]),u.push(y[2]);for(v=1;v<=r;v++)for(w=1;w<=i;w++)C=(i+1)*v+w-1,M=(i+1)*(v-1)+w-1,E=(i+1)*(v-1)+w,F=(i+1)*v+w,p.push(C),p.push(M),p.push(E),p.push(E),p.push(F),p.push(C);return _.apply(e,{positions:c,normals:u,uv:d,indices:p})}_e.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()},_e.save=function(e,t){var s="data:application/octet-stream;base64,"+btoa(_e.parse._buffToStr(e));window.location.href=s},_e.clone=function(e){return JSON.parse(JSON.stringify(e))},_e.bin={},_e.bin.f=new Float32Array(1),_e.bin.fb=new Uint8Array(_e.bin.f.buffer),_e.bin.rf=function(e,t){for(var s=_e.bin.f,i=_e.bin.fb,r=0;r<4;r++)i[r]=e[t+r];return s[0]},_e.bin.rsl=function(e,t){return e[t]|e[t+1]<<8},_e.bin.ril=function(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},_e.bin.rASCII0=function(e,t){for(var s="";0!=e[t];)s+=String.fromCharCode(e[t++]);return s},_e.bin.wf=function(e,t,s){new Float32Array(e.buffer,t,1)[0]=s},_e.bin.wsl=function(e,t,s){e[t]=s,e[t+1]=s>>8},_e.bin.wil=function(e,t,s){e[t]=s,e[t+1]=s>>8,e[t+2]=s>>16,e[t+3]},_e.parse={},_e.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},_e.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},_e.parse._readLine=function(e,t){for(var s="";10!=e[t];)s+=String.fromCharCode(e[t++]);return s},_e.parse.fromJSON=function(e){return JSON.parse(_e.parse._buffToStr(e))},_e.parse.toJSON=function(e){var t=JSON.stringify(e);return _e.parse._strToBuff(t)},_e.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=_e.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},_e.parse.fromMD2=function(e){e=new Uint8Array(e);var t={},s={};s.ident=_e.bin.ril(e,0),s.version=_e.bin.ril(e,4),s.skinwidth=_e.bin.ril(e,8),s.skinheight=_e.bin.ril(e,12),s.framesize=_e.bin.ril(e,16),s.num_skins=_e.bin.ril(e,20),s.num_vertices=_e.bin.ril(e,24),s.num_st=_e.bin.ril(e,28),s.num_tris=_e.bin.ril(e,32),s.num_glcmds=_e.bin.ril(e,36),s.num_frames=_e.bin.ril(e,40),s.offset_skins=_e.bin.ril(e,44),s.offset_st=_e.bin.ril(e,48),s.offset_tris=_e.bin.ril(e,52),s.offset_frames=_e.bin.ril(e,56),s.offset_glcmds=_e.bin.ril(e,60),s.offset_end=_e.bin.ril(e,64);var i=s.offset_st;t.c_uvt=[];for(var r=0;r<s.num_st;r++){var n=_e.bin.rsl(e,i)/s.skinwidth,A=_e.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(_e.bin.rsl(e,i),_e.bin.rsl(e,i+2),_e.bin.rsl(e,i+4)),a.push(_e.bin.rsl(e,i+6),_e.bin.rsl(e,i+8),_e.bin.rsl(e,i+10)),i+=12;i=s.offset_skins;t.skins=[];for(r=0;r<s.num_skins;r++)t.skins.push(_e.bin.rASCII0(e,i)),i+=64;i=s.offset_frames;t.frames=[];var l=_e.parse.fromMD2._normals;for(r=0;r<s.num_frames;r++){var c={},h=_e.bin.rf(e,i),u=_e.bin.rf(e,i+4),d=_e.bin.rf(e,i+8);i+=12;var p=_e.bin.rf(e,i),f=_e.bin.rf(e,i+4),g=_e.bin.rf(e,i+8);i+=12,c.name=_e.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},_e.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],_e.parse.fromCollada=function(e){var t=_e.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=_e.parse.fromCollada._asset(r)),n&&(i.geometries=_e.parse.fromCollada._libGeometries(n)),A&&(i.images=_e.parse.fromCollada._libImages(A)),o&&(i.materials=_e.parse.fromCollada._libMaterials(o)),a&&(i.effects=_e.parse.fromCollada._libEffects(a)),i},_e.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}},_e.parse.fromCollada._libGeometries=function(e){e=e.getElementsByTagName("geometry");for(var t=[],s=0;s<e.length;s++){var i=e[s],r=_e.parse.fromCollada._getMesh(i.getElementsByTagName("mesh")[0]);t.push(r)}return t},_e.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},_e.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},_e.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},_e.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},_e.parse.from3DS=function(e){e=new Uint8Array(e);var t={};if(19789!=_e.bin.rsl(e,0))return null;for(var s=_e.bin.ril(e,2),i=6;i<s;){var r=_e.bin.rsl(e,i),n=_e.bin.ril(e,i+2);15677==r&&(t.edit=_e.parse.from3DS._edit3ds(e,i,n)),45056==r&&(t.keyf=_e.parse.from3DS._keyf3ds(e,i,n)),i+=n}return t},_e.parse.from3DS._edit3ds=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);16384==n&&(null==i.objects&&(i.objects=[]),i.objects.push(_e.parse.from3DS._edit_object(e,r,A))),r+=A}return i},_e.parse.from3DS._keyf3ds=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);45058==n&&(null==i.desc&&(i.desc=[]),i.desc.push(_e.parse.from3DS._keyf_objdes(e,r,A))),r+=A}return i},_e.parse.from3DS._keyf_objdes=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);45072==n&&(i.hierarchy=_e.parse.from3DS._keyf_objhierarch(e,r,A)),45073==n&&(i.dummy_name=_e.bin.rASCII0(e,r+6)),r+=A}return i},_e.parse.from3DS._keyf_objhierarch=function(e,t,s){var i={},r=t+6;return i.name=_e.bin.rASCII0(e,r),r+=i.name.length+1,i.hierarchy=_e.bin.rsl(e,r+4),i},_e.parse.from3DS._edit_object=function(e,t,s){var i={},r=t+6;for(i.name=_e.bin.rASCII0(e,r),r+=i.name.length+1;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);16640==n&&(i.mesh=_e.parse.from3DS._obj_trimesh(e,r,A)),r+=A}return i},_e.parse.from3DS._obj_trimesh=function(e,t,s){for(var i={},r=t+6;r<t+s;){var n=_e.bin.rsl(e,r),A=_e.bin.ril(e,r+2);16656==n&&(i.vertices=_e.parse.from3DS._tri_vertexl(e,r,A)),16672==n&&(i.indices=_e.parse.from3DS._tri_facel1(e,r,A)),16704==n&&(i.uvt=_e.parse.from3DS._tri_mappingcoors(e,r,A)),16736==n&&(i.local=_e.parse.from3DS._tri_local(e,r,A)),r+=A}return i},_e.parse.from3DS._tri_vertexl=function(e,t,s){var i=[],r=t+6,n=_e.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(_e.bin.rf(e,r)),i.push(_e.bin.rf(e,r+4)),i.push(_e.bin.rf(e,r+8)),r+=12;return i},_e.parse.from3DS._tri_facel1=function(e,t,s){var i=[],r=t+6,n=_e.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(_e.bin.rsl(e,r)),i.push(_e.bin.rsl(e,r+2)),i.push(_e.bin.rsl(e,r+4)),r+=8;return i},_e.parse.from3DS._tri_mappingcoors=function(e,t,s){var i=[],r=t+6,n=_e.bin.rsl(e,r);r+=2;for(var A=0;A<n;A++)i.push(_e.bin.rf(e,r)),i.push(1-_e.bin.rf(e,r+4)),r+=8;return i},_e.parse.from3DS._tri_local=function(e,t,s){var i={},r=t+6;return i.X=[_e.bin.rf(e,r),_e.bin.rf(e,r+4),_e.bin.rf(e,r+8)],r+=12,i.Y=[_e.bin.rf(e,r),_e.bin.rf(e,r+4),_e.bin.rf(e,r+8)],r+=12,i.Z=[_e.bin.rf(e,r),_e.bin.rf(e,r+4),_e.bin.rf(e,r+8)],r+=12,i.C=[_e.bin.rf(e,r),_e.bin.rf(e,r+4),_e.bin.rf(e,r+8)],r+=12,i},_e.parse.fromBIV=function(e){e=new Uint8Array(e);var t={},s={};return s.id=_e.bin.ril(e,0),s.verS=_e.bin.ril(e,4),s.texS=_e.bin.ril(e,8),s.indS=_e.bin.ril(e,12),s.verO=_e.bin.ril(e,16),s.verL=_e.bin.ril(e,20),s.texO=_e.bin.ril(e,24),s.texL=_e.bin.ril(e,28),s.indO=_e.bin.ril(e,32),s.indL=_e.bin.ril(e,36),0!=s.verO&&(t.vertices=_e.parse.fromBIV._readFloats(e,s.verO,s.verL)),0!=s.texO&&(t.uvt=_e.parse.fromBIV._readFloats(e,s.texO,s.texL)),0!=s.indO&&(t.indices=_e.parse.fromBIV._readInts(e,s.indO,s.indL,s.indS)),t},_e.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);_e.bin.wil(n,0,1769365870),_e.bin.wil(n,4,32),_e.bin.wil(n,8,32),_e.bin.wil(n,12,i);var A=40;return e.vertices&&(_e.bin.wil(n,16,A),_e.bin.wil(n,20,4*e.vertices.length),_e.parse.fromBIV._writeFloats(n,A,e.vertices),A+=4*e.vertices.length),e.uvt&&(_e.bin.wil(n,24,A),_e.bin.wil(n,28,4*e.uvt.length),_e.parse.fromBIV._writeFloats(n,A,e.uvt),A+=4*e.uvt.length),e.indices&&(_e.bin.wil(n,32,A),_e.bin.wil(n,36,4*e.indices.length),_e.parse.fromBIV._writeInts(n,A,e.indices,i)),n.buffer},_e.parse.fromBIV._readFloats=function(e,t,s){for(var i=[],r=0;r<s/4;r++)i.push(_e.bin.rf(e,t+4*r));return i},_e.parse.fromBIV._writeFloats=function(e,t,s){for(var i=0;i<s.length;i++)_e.bin.wf(e,t+4*i,s[i])},_e.parse.fromBIV._readInts=function(e,t,s,i){for(var r=[],n=0;n<s/4;n++)16==i&&r.push(_e.bin.rsl(e,t+2*n)),32==i&&r.push(_e.bin.ril(e,t+4*n));return r},_e.parse.fromBIV._writeInts=function(e,t,s,i){for(var r=0;r<s.length;r++)16==i&&_e.bin.wsl(e,t+2*r,s[r]),32==i&&_e.bin.wil(e,t+4*r,s[r])},_e.gen={},_e.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},_e.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]}},_e.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},_e.mat={},_e.mat.scale=function(e,t,s){return[e,0,0,0,0,t,0,0,0,0,s,0,0,0,0,1]},_e.mat.translate=function(e,t,s){return[1,0,0,0,0,1,0,0,0,0,1,0,e,t,s,1]},_e.mat.rotateDeg=function(e,t,s){var i=Math.PI/180;return _e.mat.rotate(e*i,t*i,s*i)},_e.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},_e.edit={},_e.edit.interpolate=function(e,t,s,i){for(var r=0;r<e.length;r++)s[r]=e[r]+i*(t[r]-e[r])},_e.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]}},_e.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},_e.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},_e.utils={},_e.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 Ee={" ":{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 Fe(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;_.isNumeric(a)&&(a=""+a);for(var l,c,h,u,d,p,f,g,m,b=(a||"").split("\n"),B=0,y=0,w=.04,v=0;v<b.length;v++){l=0,h=(c=b[v]).length;for(var C=0;C<h;C++)if(u=Ee[c.charAt(C)]){d=1,p=-1,f=-1,g=u.points.length;for(var M=0;M<g;M++)-1!==(m=u.points[M])[0]||-1!==m[1]?(A.push(l+m[0]*n*w+s),A.push(y+m[1]*n*w+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*w*n}y-=35*w*n}return _.apply(e,{primitive:"lines",positions:A,indices:o})}function xe(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 _.apply(e,{primitive:"lines",positions:e.points,indices:s})}function Ue(e={}){if(3!==e.startPoint.length)throw"Start point should contain 3 elements in array: x, y and z";if(3!==e.endPoint.length)throw"End point should contain 3 elements in array: x, y and z";let t=[],s=[],i=e.startPoint[0],r=e.startPoint[1],n=e.startPoint[2],A=e.endPoint[0],o=e.endPoint[1],a=e.endPoint[2],l=Math.sqrt((A-i)**2+(o-r)**2+(a-n)**2),c=[(A-i)/l,(o-r)/l,(a-n)/l];if(e.pattern){let h=e.pattern.length,u=!1,d=0,p=0,f=0,g=[i,r,n],m=e.pattern[p];for(s.push(g[0],g[1],g[2]);m<=l-d;){let i=[c[0]*m,c[1]*m,c[2]*m],r=[g[0]+i[0],g[1]+i[1],g[2]+i[2]];s.push(r[0],r[1],r[2]),u||(t.push(f),t.push(f+1)),u=!u,f+=1,g=r,p+=1,p>=h&&(p=0),d+=m,m=e.pattern[p]}e.extendToEnd&&(s.push(A,o,a),t.push(t.length-2),t.push(t.length-1))}else t.push(0),t.push(1),s.push(i,r,n,A,o,a);return _.apply(e,{primitive:"lines",positions:s,indices:t})}const Ie=h.vec4(4),Te=h.vec4(),Pe=h.vec4(),Se=h.vec3([1,0,0]),De=h.vec3([0,1,0]),ke=h.vec3([0,0,1]),Qe=h.vec3(3),Re=h.vec3(3),Oe=h.identityMat4();class Ve extends T{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=h.vec3(),this._quaternion=h.identityQuaternion(),this._rotation=h.vec3(),this._position=h.vec3(),this._offset=h.vec3(),this._localMatrix=h.identityMat4(),this._worldMatrix=h.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=h.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)h.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=h.AABB3()),this._buildAABB)this._buildAABB(this.worldMatrix,this._aabb);else{let e;h.collapseAABB3(this._aabb);for(let t=0,s=this._children.length;t<s;t++)e=this._children[t],e.collidable&&h.expandAABB3(this._aabb,e.aabb)}this._aabbDirty=!1}addChild(e,t){if(_.isNumeric(e)||_.isString(e)){const t=e;if(!(e=this.scene.component[t]))return void this.warn("Component not found: "+_.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(_.isNumeric(e)||_.isString(e)){const t=e;if(!(e=this.scene.components[t]))return void this.warn("Node not found: "+_.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]),h.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]),h.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=h.identityMat4()),this._localMatrix.set(e||Oe),h.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=h.identityMat4()),h.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 Ie[0]=e[0],Ie[1]=e[1],Ie[2]=e[2],Ie[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(Ie,Te),h.mulQuaternions(this.quaternion,Te,Pe),this.quaternion=Pe,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return Ie[0]=e[0],Ie[1]=e[1],Ie[2]=e[2],Ie[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(Ie,Te),h.mulQuaternions(Te,this.quaternion,Te),this}rotateX(e){return this.rotate(Se,e)}rotateY(e){return this.rotate(De,e)}rotateZ(e){return this.rotate(ke,e)}translate(e,t){return h.vec3ApplyQuaternion(this.quaternion,e,Qe),h.mulVec3Scalar(Qe,t,Re),h.addVec3(this.position,Re,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(Se,e)}translateY(e){return this.translate(De,e)}translateZ(e){return this.translate(ke,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 Le=h.vec3(),He=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,h.transformVec4(i,t,s),h.setMat4Translation(i,s,n),n.slice()}}();function Ne(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 Ge(e,t,s,i=1e3){const r=h.getPositionsCenter(e,Le),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 je=new e({}),We=h.vec3(),ze=h.vec4(),Xe={3001:"sRGBToLinear"},Ke=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 u=c.getLogDepth,d=c.clipPos,p=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((${d}.xy / ${d}.w - ${e}) * ${t} * ${d}.w, ${d}.zw)`}}(),f=p?p.transformedClipPos():d,g=[],m=a.createVarying("float","isPerspective",(()=>`(${c.projMatrix}[2][3] == -1.0) ? 1.0 : 0.0`)),_=a.createUniform("float","logDepthBufFC",((e,t)=>e(2/(Math.log(t.view.far+1)/Math.LN2)))),b=a.createVarying("float","vFragDepth",(()=>"1.0 + clipPos.w"));u?g.push(`gl_FragDepth = ${c.testPerspectiveForGl_FragDepth?`${m} == 0.0 ? gl_FragCoord.z : `:""}log2(${u(b)}) * ${_} * 0.5;`):c.cleanerEdges&&g.push("gl_FragDepth = gl_FragCoord.z + length(vec2(dFdx(gl_FragCoord.z), dFdy(gl_FragCoord.z)));");const B=a.createFragmentDefinition("linearToGamma",((e,t)=>{t.push(`vec4 ${e}(in vec4 value, in float gammaFactor) {`),t.push(" return vec4(pow(value.xyz, vec3(1.0 / gammaFactor)), value.w);"),t.push("}")})),y=c.sectionPlanesState,w=y&&function(){const e=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t}(y.getNumAllocatedSectionPlanes()).map((e=>{const t=(t,s,i)=>a.createUniform(t,`sectionPlane${s}${e}`,((t,s)=>{const r=y.sectionPlanes,n=r.length,A=(s.mesh.layerIndex||0)*n,o=e<n&&s.mesh.renderFlags.sectionPlanesActivePerLayer[A+e];return i(t,o,r[e],s.mesh.origin)}));return{act:t("bool","Active",((e,t)=>e(t?1:0))),dir:t("vec3","Dir",((e,t,s)=>t&&e(s.dir))),pos:t("vec3","Pos",((e,t,s,i)=>t&&e(i?h.mulVec3Scalar(h.normalizeVec3(s.dir,We),-(h.dotVec3(s.dir,i)+s.dist),We):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(" + "))}(),v=c.crossSections,C=w?function(){const e=a.createUniform("vec4","sliceColor",(e=>e(v.sliceColor))),t=s=>(t.needed=!0,`(sliced ? ${e} : ${s})`);return t}():e=>e,M=c.getGammaFactor,E=a.createUniform("float","gammaFactor",(e=>e(M())));c.appendFragmentOutputs(g,M&&(e=>`${B}(${e}, ${E})`),"gl_FragCoord",C);const F=function(){const e=[],t=a.createUniform("float","sliceThickness",(e=>e(v.sliceThickness)));if(w){C.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 = ${w(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);`),u&&e.push(` gl_FragDepth = log2(${u(b)}) * ${_} * 0.5;`),e.push(" return;"),e.push(" }")}else e.push(` if (dist > ${C.needed?t:"0.0"}) { discard; }`);C.needed&&e.push(" sliced = dist > 0.0;"),e.push(" }")}return e}(),x=function(){const e=[];return i.forEach((t=>t(e))),e}(),U=[...function(){const e=[];return s.forEach((t=>t(e))),e}(),...x,"void main(void) {",...c.discardPoints?[" vec2 cxy = 2.0 * gl_PointCoord - 1.0;"," if (dot(cxy, cxy) > 1.0) { discard; }"]:[],...F,...g,"}"],I=[`gl_Position = ${f};`,...c.getPointSize?[`gl_PointSize = ${c.getPointSize()};`]:[],...function(){const e=[];return t.forEach((t=>t(e))),e}()],T=c.getVertexData?c.getVertexData():[],P=[...function(){const t=[];return e.forEach((e=>e(t))),t}(),"void main(void) {",...T,...I,"}"],S=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"],D=S("vertex").concat(P),k=S("fragment").concat(["vec4 sRGBToLinear(in vec4 value) {"," return vec4(mix(pow(value.rgb * 0.9478672986 + 0.0521327014, vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);","}"]).concat(U),Q=(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("")]]},[R,O]=Q(o.VERTEX_SHADER,D),[V,L]=Q(o.FRAGMENT_SHADER,k),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,R),o.attachShader(e,V),o.linkProgram(e),o.getProgramParameter(e,o.LINK_STATUS)){const t=Ye(o,e);r.forEach((e=>e(t)));const s=A.map((e=>e(t))).filter((e=>e)),i=je.addItem({});return[{id:i,bind:()=>o.useProgram(e),inputSetters:{attributesHash:n.sort().join(", "),setUniforms:(e,t)=>{p&&p.setClipPosInputValue(e),s.forEach((e=>e(t)))}},destroy:()=>{je.removeItem(i),o.deleteProgram(e),o.deleteShader(R),o.deleteShader(V)}}]}return H(["",o.getProgramInfoLog(this.program),"","Vertex shader:","",...D,"","Fragment shader:","",...k])}return H(["Failed to allocate program"])}}}},Ze=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];ze[0]=t.color[0],ze[1]=t.color[1],ze[2]=t.color[2],ze[3]=t.intensity,e(ze)})),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&&Je(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`)}},Je=(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?`${Xe[i]}(${s})`:s}},Ye=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}},$e=h.vec4(),qe=h.vec4();class et{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 tt=h.OBB3(),st=h.vec4(),it=h.vec4(),rt=h.vec4(),nt=h.vec3([1,0,0]),At=h.vec3([0,1,0]),ot=h.vec3([0,0,1]),at=h.vec3(3),lt=h.vec3(3),ct=h.identityMat4(),ht=new e({}),ut={};class dt extends T{constructor(e,t={}){super(e,t),this.renderOrder=t.renderOrder||0,this.originalSystemId=t.originalSystemId||this.id,this.renderFlags=new et,this._state=new se({visible:!0,culled:!1,pickable:null,clippable:null,collidable:null,occluder:!1!==t.occluder,castsShadow:null,receivesShadow:null,xrayed:!1,highlighted:!1,selected:!1,edges:!1,stationary:!!t.stationary,background:!!t.background,billboard:this._checkBillboard(t.billboard),layer:null,colorize:null,pickID:this.scene._renderer.getPickID(this),drawHash:"",pickOcclusionHash:"",offset:h.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=Ke(),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 ut)){const e=ft(i,A,{decodedUv:c,worldNormal:a,viewNormal:l},h,s);if(e.errors)return void console.log(e.errors.join("\n"));const t=ht.addItem({});ut[u]={drawMesh:e.drawMesh,id:t,useCount:0,delete:()=>{ht.removeItem(t),e.destroy(),delete ut[u],p.memory.programs--}},p.memory.programs++}t=ut[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&&Ze(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=Ze(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=Ze(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&&Je(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?($e[0]=t,$e[1]=1===e.alphaMode?1:0,$e[2]=e.alphaCutoff,$e):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;qe[0]=255&s,qe[1]=s>>8&255,qe[2]=s>>16&255,qe[3]=s>>24&255,h.mulVec4Scalar(qe,1/255,qe),e(qe)})),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=h.vec3(),this._quaternion=h.identityQuaternion(),this._rotation=h.vec3(),this._position=h.vec3(),this._worldMatrix=h.identityMat4(),this._worldNormalMatrix=h.identityMat4(),this._localMatrixDirty=!0,this._worldMatrixDirty=!0,this._worldNormalMatrixDirty=!0;const o=t.origin||t.rtcCenter;if(o&&(this._state.origin=h.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]),h.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]),h.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=h.identityMat4()),h.composeMat4(this._position,this._quaternion,this._scale,this.__localMatrix),this._localMatrixDirty=!1),this.__localMatrix}set matrix(e){this.__localMatrix||(this.__localMatrix=h.identityMat4()),this.__localMatrix.set(e||ct),h.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=h.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)h.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=h.mat4()),h.transposeMat4(this._worldMatrix,this._worldNormalMatrix),h.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=h.AABB3()),this._buildAABB(this.worldMatrix,this._aabb),this._aabbDirty=!1}_buildAABB(e,t){h.transformOBB3(e,this._geometry.obb,tt),h.OBB3ToAABB3(tt,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 st[0]=e[0],st[1]=e[1],st[2]=e[2],st[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(st,it),h.mulQuaternions(this.quaternion,it,rt),this.quaternion=rt,this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}rotateOnWorldAxis(e,t){return st[0]=e[0],st[1]=e[1],st[2]=e[2],st[3]=t*h.DEGTORAD,h.angleAxisToQuaternion(st,it),h.mulQuaternions(it,this.quaternion,it),this}rotateX(e){return this.rotate(nt,e)}rotateY(e){return this.rotate(At,e)}rotateZ(e){return this.rotate(ot,e)}translate(e,t){return h.vec3ApplyQuaternion(this.quaternion,e,at),h.mulVec3Scalar(at,t,lt),h.addVec3(this.position,lt,this.position),this._setLocalMatrixDirty(),this._setAABBDirty(),this.glRedraw(),this}translateX(e){return this.translate(nt,e)}translateY(e){return this.translate(At,e)}translateZ(e){return this.translate(ot,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=h.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){pt(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 pt=function(){const e=h.vec3(),t=h.vec3(),s=h.vec3(),i=h.vec3(),r=h.vec3(),n=h.vec3(),A=h.vec4(),o=h.vec3(),a=h.vec3(),l=h.vec3(),c=h.vec3(),u=h.vec3(),d=h.vec3(),p=h.vec3(),f=h.vec3(),g=h.vec3(),m=h.vec4(),_=h.vec4(),b=h.vec4(),B=h.vec3(),y=h.vec3(),w=h.vec3(),v=h.vec3(),C=h.vec3(),M=h.vec3(),E=h.vec3(),F=h.vec3(),x=h.vec3(),U=h.vec3(),I=h.vec3();return function(T,P,S,D,k){var Q=k.primIndex;if(null!=Q&&Q>-1){const L=T.geometry._state,H=T.scene,N=H.camera,G=H.canvas;if("triangles"===L.primitiveName){k.primitive="triangle";const H=Q,j=L.indices,W=L.positions;let z,X,K;if(j){var R=j[H+0],O=j[H+1],V=j[H+2];n[0]=R,n[1]=O,n[2]=V,k.indices=n,z=3*R,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&&(he.decompressPosition(s,e,s),he.decompressPosition(i,e,i),he.decompressPosition(r,e,r))}k.canvasPos?h.canvasPosToLocalRay(G.canvas,T.origin?He(P,T.origin):P,S,D,T.worldMatrix,k.canvasPos,e,t):k.origin&&k.direction&&h.worldRayToLocalRay(T.worldMatrix,k.origin,k.direction,e,t),h.normalizeVec3(t),h.rayPlaneIntersect(e,t,s,i,r,A),k.localPos=A,k.position=A,m[0]=A[0],m[1]=A[1],m[2]=A[2],m[3]=1,h.transformVec4(T.worldMatrix,m,_),o[0]=_[0],o[1]=_[1],o[2]=_[2],k.canvasPos&&T.origin&&(o[0]+=T.origin[0],o[1]+=T.origin[1],o[2]+=T.origin[2]),k.worldPos=o,h.transformVec4(N.matrix,_,b),a[0]=b[0],a[1]=b[1],a[2]=b[2],k.viewPos=a,h.cartesianToBarycentric(A,s,i,r,l),k.bary=l;const Z=L.normals;if(Z){if(L.compressGeometry){const e=3*R,t=3*O,s=3*V;he.decompressNormal(Z.subarray(e,e+2),c),he.decompressNormal(Z.subarray(t,t+2),u),he.decompressNormal(Z.subarray(s,s+2),d)}else c[0]=Z[z],c[1]=Z[z+1],c[2]=Z[z+2],u[0]=Z[X],u[1]=Z[X+1],u[2]=Z[X+2],d[0]=Z[K],d[1]=Z[K+1],d[2]=Z[K+2];const e=h.addVec3(h.addVec3(h.mulVec3Scalar(c,l[0],B),h.mulVec3Scalar(u,l[1],y),w),h.mulVec3Scalar(d,l[2],v),C);k.worldNormal=h.normalizeVec3(h.transformVec3(T.worldNormalMatrix,e,M))}const J=L.uv;if(J){if(p[0]=J[2*R],p[1]=J[2*R+1],f[0]=J[2*O],f[1]=J[2*O+1],g[0]=J[2*V],g[1]=J[2*V+1],L.compressGeometry){const e=L.uvDecodeMatrix;e&&(he.decompressUV(p,e,p),he.decompressUV(f,e,f),he.decompressUV(g,e,g))}k.uv=h.addVec3(h.addVec3(h.mulVec2Scalar(p,l[0],E),h.mulVec2Scalar(f,l[1],F),x),h.mulVec2Scalar(g,l[2],U),I)}}}}}(),ft=(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 gt extends T{get type(){return"Material"}constructor(e,t={}){super(e,t),p.memory.materials++}destroy(){super.destroy(),p.memory.materials--}}const mt={opaque:0,mask:1,blend:2},_t=["opaque","mask","blend"];class bt extends gt{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new se({type:"PhongMaterial",ambient:h.vec3([1,1,1]),diffuse:h.vec3([1,1,1]),specular:h.vec3([1,1,1]),emissive:h.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=mt[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 _t[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 Bt(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 yt(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=Bt(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=Bt(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=Bt(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=Bt(e,"WEBGL_compressed_texture_etc1");return null!==t?t.COMPRESSED_RGB_ETC1_WEBGL:null}if(37492===r||37496===r){const t=Bt(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=Bt(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=Bt(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 wt=new Uint8Array([0,0,0,1]);class vt{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?(wt[0]=Math.floor(255*e[0]),wt[1]=Math.floor(255*e[1]),wt[2]=Math.floor(255*e[2]),wt[3]=Math.floor(255*(void 0!==e[3]?e[3]:1))):(wt[0]=0,wt[1]=0,wt[2]=0,wt[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,wt)}else t.texImage2D(this.target,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,wt);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=yt(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=yt(s,this.magFilter);l&&s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,l);const c=yt(s,this.wrapS);c&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,c);const h=yt(s,this.wrapT);h&&s.texParameteri(this.target,s.TEXTURE_WRAP_T,h);const u=yt(s,this.format,this.encoding),d=yt(s,this.type),p=Ct(s,this.internalFormat,u,d,this.encoding,!1);if(this.target===s.TEXTURE_CUBE_MAP){if(_.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=yt(s,this.wrapS);n&&s.texParameteri(this.target,s.TEXTURE_WRAP_S,n);const A=yt(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=yt(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,Mt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,Mt(s,this.magFilter))):(s.texParameteri(this.target,s.TEXTURE_MIN_FILTER,yt(s,this.minFilter)),s.texParameteri(this.target,s.TEXTURE_MAG_FILTER,yt(s,this.magFilter)));const o=yt(s,this.format,this.encoding),a=yt(s,this.type),l=Ct(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=yt(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=yt(t,e.magFilter);s&&(this.magFilter=e.magFilter,t.texParameteri(this.target,t.TEXTURE_MAG_FILTER,s))}if(void 0!==e.wrapS){const s=yt(t,e.wrapS);s&&(this.wrapS=e.wrapS,t.texParameteri(this.target,t.TEXTURE_WRAP_S,s))}if(void 0!==e.wrapT){const s=yt(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 Ct(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||Bt(e,"EXT_color_buffer_float"),A}function Mt(e,t){return 1003===t||1004===t||1005===t?e.NEAREST:e.LINEAR}function Et(e){if(!Ft(e.width)||!Ft(e.height)){const t=document.createElement("canvas");t.width=xt(e.width),t.height=xt(e.height);t.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,t.width,t.height),e=t}return e}function Ft(e){return 0==(e&e-1)}function xt(e){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1}class Ut extends T{get type(){return"Texture"}constructor(e,t={}){super(e,t),this._state=new se({texture:new vt({gl:this.scene.canvas.gl}),matrix:h.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=h.vec2([0,0]),this._scale=h.vec2([1,1]),this._rotate=h.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),p.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=h.translationMat4v([this._translate[0],this._translate[1],0],this._state.matrix)),1===this._scale[0]&&1===this._scale[1]||(s=h.scalingMat4v([this._scale[0],this._scale[1],1]),t=t?h.mulMat4(t,s):s),0!==this._rotate&&(s=h.rotationMat4v(.0174532925*this._rotate,[0,0,1]),t=t?h.mulMat4(t,s):s),t&&(e.matrix=t),this._matrixDirty=!1}this.glRedraw()}set image(e){this._image=Et(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=Et(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(),p.memory.textures--}}const It=h.vec3(),Tt=h.vec3();h.vec3();const Pt=h.vec3([0,-1,0]),St=h.vec4([0,0,0,1]);class Dt extends gt{get type(){return"LambertMaterial"}constructor(e,t={}){super(e,t),this._state=new se({type:"LambertMaterial",ambient:h.vec3([1,1,1]),color:h.vec3([1,1,1]),emissive:h.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 kt={opaque:0,mask:1,blend:2},Qt=["opaque","mask","blend"];class Rt extends gt{get type(){return"MetallicMaterial"}constructor(e,t={}){super(e,t),this._state=new se({type:"MetallicMaterial",baseColor:h.vec4([1,1,1]),emissive:h.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=kt[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 Qt[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 Ot={opaque:0,mask:1,blend:2},Vt=["opaque","mask","blend"];class Lt extends gt{get type(){return"SpecularMaterial"}constructor(e,t={}){super(e,t),this._state=new se({type:"SpecularMaterial",diffuse:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),specular:h.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=Ot[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 Vt[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 Ht={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 Nt extends gt{get type(){return"EmphasisMaterial"}get presets(){return Ht}constructor(e,t={}){super(e,t),this._state=new se({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(console.warn("EmphasisMaterial.preset is deprecated and will be removed in future versions."),e=e||"default",this._preset===e)return;const t=Ht[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(Ht).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 Gt={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 jt extends gt{get type(){return"EdgeMaterial"}get presets(){return Gt}constructor(e,t={}){super(e,t),this._state=new se({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Gt[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(Gt).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}class Wt extends T{constructor(e,t={}){super(e,t),this._type=t.type||(t.src?t.src.split(".").pop():null)||"jpg",this._pos=h.vec3(t.pos||[0,0,0]),this._up=h.vec3(t.up||[0,1,0]),this._normal=h.vec3(t.normal||[0,0,1]),this._height=t.height||1,this._origin=h.vec3(),this._rtcPos=h.vec3(),this._imageSize=h.vec2(),this._texture=new Ut(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 Ve(this,{matrix:h.inverseMat4(h.lookAtMat4v(this._pos,h.subVec3(this._pos,this._normal,h.mat4()),this._up,h.mat4())),children:[this._bitmapMesh=new dt(this,{scale:[1,1,1],rotation:[-90,0,0],collidable:t.collidable,pickable:t.pickable,opacity:t.opacity,clippable:t.clippable,geometry:new pe(this,ve({center:[0,0,0],xSize:1,zSize:1,xSegments:2,zSegments:2})),material:new bt(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 zt=(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)},Xt=h.vec3(),Kt=h.vec3(),Zt=h.vec3();class Jt{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&&!zt(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];Xt[0]=e[r],Xt[1]=e[r+1],Xt[2]=e[r+2],Kt[0]=e[n],Kt[1]=e[n+1],Kt[2]=e[n+2],Zt[0]=e[A],Zt[1]=e[A+1],Zt[2]=e[A+2],h.cross3Vec3(Xt,Kt,Xt),s+=h.dotVec3(Xt,Zt)}return s/6}}const Yt=new Jt,$t=h.vec3(),qt=h.vec3(),es=h.vec3(),ts=h.vec3(),ss=h.vec3(),is=h.vec3();class rs{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];$t[0]=e[r],$t[1]=e[r+1],$t[2]=e[r+2],qt[0]=e[n],qt[1]=e[n+1],qt[2]=e[n+2],es[0]=e[A],es[1]=e[A+1],es[2]=e[A+2],h.subVec3($t,qt,ts),h.subVec3(es,qt,ss),s+=.5*h.lenVec3(h.cross3Vec3(ts,ss,is))}return s}}const ns=new rs,As=h.OBB3(),os=h.OBB3(),as=h.OBB3();class ls{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=h.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":Yt.reset(),Yt.setPrimitive(this.layer.primitive),this.getEachVertex((e=>{Yt.addVertex(e)})),this.getEachIndex((e=>{Yt.addIndex(e)})),this._volume=Yt.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":ns.reset(),this.getEachVertex((e=>{ns.addVertex(e)})),this.getEachIndex((e=>{ns.addIndex(e)})),this._surfaceArea=ns.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&&(h.AABB3ToOBB3(this._aabbLocal,As),this.transform?(h.transformOBB3(this.transform.worldMatrix,As,os),h.transformOBB3(this.model.worldMatrix,os,as),h.OBB3ToAABB3(as,this._aabbWorld)):(h.transformOBB3(this.model.worldMatrix,As,os),h.OBB3ToAABB3(os,this._aabbWorld)),this._aabbWorldDirty=!1),this._aabbWorld}_destroy(){this.model.scene._renderer.putPickID(this.pickId)}}const cs=1,hs=4,us=8,ds=16,ps=32,fs=256,gs=512,ms=1024,_s=2048,bs=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};`)}},Bs=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);`)}},ys=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}))`)};`)}}},ws=h.vec2(),vs=h.vec3(),Cs=h.vec4(),Ms=h.mat4(),Es=h.vec3([0,0,0]),Fs=0,xs=1,Us=2,Is=3,Ts=4,Ps=5,Ss=6,Ds=7,ks=8,Qs=9,Rs=10,Os=11,Vs=e=>[h.safeInv(e[0]),h.safeInv(e[1]),h.safeInv(e[2])],Ls=(e,t,s,i,r)=>{const n=!!(e&cs),A=!!(e&fs),o=!!(e&gs),a=!!(e&ms),l=!!(e&_s),c=!!(e&us),h=!!(e&hs);let u,d;u=!n||h||A||o&&!i.highlightMaterial.glowThrough||a&&!i.selectedMaterial.glowThrough?Fs:t?Us:xs,d=!n||h?Fs:a?Ts:o?Is:A?Ps:Fs;let p=0;p=s&&n&&!h?a?Qs:o?ks:A?Rs:l?t?Ds:Ss:Fs:Fs;const f=n&&!h&&c?Os:Fs;r[0]=u,r[1]=d,r[2]=p,r[3]=f},Hs=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],u=t.id;if(!(u in c)){const e=t.canvas.gl,l=function(r,n,A){const o=function(){const A=Ke(),o=A.programVariables,l=a(o,n);return r(o,l.geometryParameters,(function(r,a){const c=t.pointsMaterial,u="points"===i&&!n,d=()=>[t._sectionPlanesState.getHash()].concat(u?[c.hash]:[]).concat(r.getHash?r.getHash():[]).join(";"),p=d(),f=()=>p===d(),g=l.geometryParameters,m=r.incrementDrawState,_=r.isShadowProgram,b=g.attributes,B=b.position.world,y="clipPos",[w,v]=A.buildProgram(e,s+" "+i+" "+r.programName,{appendFragmentOutputs:r.appendFragmentOutputs,cleanerEdges:r.cleanerEdges,clipPos:y,clippableTest:function(){const e=o.createVarying("float","vClippable",(()=>`${b.clippable} ? 1.0 : 0.0`),"flat");return()=>`${e} > 0.0`}(),clippingCaps:r.clippingCaps,crossSections:t.crossSections,discardPoints:u&&c.roundPoints,getGammaFactor:t.gammaOutput&&(()=>t.gammaFactor),getLogDepth:r.getLogDepth,getPointSize:function(){const e=[];if(u){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=b.color,t=b.flags[r.renderPassFlag],s=o.createUniform("int","renderPass",((e,t)=>e(t.renderPass))),n=[`if (${_?`(${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=>{ws[0]=c.minIntensity,ws[1]=c.maxIntensity,e(ws)}));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=g.attributes.position.view;return A.push(`vec4 ${a} = ${g.viewMatrix} * ${B};`),A.push(`vec4 clipPos = ${g.projMatrix} * ${a};`),A},projMatrix:g.projMatrix,sectionPlanesState:t._sectionPlanesState,testPerspectiveForGl_FragDepth:"points"!==i&&"lines"!==i||n,usePickClipPos:a,worldPositionAttribute:B});return v?(console.error(v),{getValid:f,destroy:()=>{},drawLayer:(e,t,s)=>{}}):{getValid:f,destroy:()=>w.destroy(),drawLayer:(e,t,s)=>{e.lastProgramId!==w.id&&(e.lastProgramId=w.id,w.bind());const i=t.origin,r=t.model,A=e.viewParams,o=vs;h.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 u={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:h.compareVec3(o,Es)?a:He(a,o,Ms),viewNormalMatrix:A.viewNormalMatrix}};w.inputSetters.setUniforms(e,u),t.drawCalls[n?n.vertices?"drawVertices":"drawEdges":"drawSurface"](w.inputSetters.attributesHash,l.layerTypeInputs,{projMatrix:c,viewMatrix:h.compareVec3(o,Es)?a:He(a,o,Ms),viewNormalMatrix:A.viewNormalMatrix,eye:A.eye}),m&&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())}}},d=(e,t)=>l(e,t,!0),p=(e,t)=>l(e,t,!1),f=(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),g=(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),m=(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),_=(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(${h.MAX_INT}), 1.0);`)}}}(e,s,t.logarithmicDepthBufferEnabled,r),!0),b=(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(${h.MAX_INT}), 1.0)`};`),e.push(`${c} = uvec4(${o});`))}}}(e,t,i,r),!0);c[u]="points"===i?{colorRenderers:{"sao-":{vertex:p(((e,t,s)=>s(f(e,t,null,null))))}},occlusionRenderer:p(((e,s,i)=>i(Bs(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:p(g),pickMeshRenderer:p(m),silhouetteRenderer:p(((e,s,i)=>i(ys(e,s,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:p(((e,t,s)=>b(e,t,s,!0,!0))),snapVertexRenderer:p(((e,t,s)=>b(e,t,s,!1,!0)),{vertices:!0})}:"lines"===i?{colorRenderers:{"sao-":{vertex:p(((e,t,s)=>s(f(e,t,null,null))))}},silhouetteRenderer:p(((e,s,i)=>i(ys(e,s,t.logarithmicDepthBufferEnabled,!0)))),snapInitRenderer:p(((e,t,s)=>b(e,t,s,!0,!1))),snapEdgeRenderer:p(((e,t,s)=>b(e,t,s,!1,!1)),{vertices:!1}),snapVertexRenderer:p(((e,t,s)=>b(e,t,s,!1,!1)),{vertices:!0})}:{colorRenderers:function(){const e=e=>Ze(e,t._lightsState),s=e=>{const t=e.createUniform("vec4","uSAOParams",((e,t)=>e(t.legacyFrameCtx.saoParams))),s=Je(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=Je(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&&p(((r,n,A)=>A(function(e,t,s,i,r){const n=(t,s,i)=>Je(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-":p(((e,t,s)=>s(r(e,t,!1)))),"alphaCutoff+":p(((e,t,s)=>s(r(e,t,!0))))},vertex:p(o?(t,r,n)=>n(f(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:p(((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:p(((e,s,i)=>i(bs(e,s,t.logarithmicDepthBufferEnabled,!0))),{vertices:!1}),vertex:p(((e,s,i)=>i(bs(e,s,t.logarithmicDepthBufferEnabled,!1))),{vertices:!1})},occlusionRenderer:p(((e,s,i)=>i(Bs(e,t.logarithmicDepthBufferEnabled)))),pickDepthRenderer:d(g),pickMeshRenderer:d(m),pickNormalsFlatRenderer:d(((e,t,s)=>_(e,t,s,!0))),pickNormalsRenderer:d(((e,t,s)=>_(e,t,s,!1))),shadowRenderer:p(((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:d(((e,s,i)=>i(ys(e,s,t.logarithmicDepthBufferEnabled,!1)))),snapInitRenderer:d(((e,t,s)=>b(e,t,s,!0,!1))),snapEdgeRenderer:d(((e,t,s)=>b(e,t,s,!1,!1)),{vertices:!1}),snapVertexRenderer:d(((e,t,s)=>b(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[u])},y=()=>B(!1);y(),t.on("compile",y),t.on("destroyed",(()=>{delete c[u]}))}return c[u]}}();class Ns{constructor(e,t,s){this.model=e,this.primitive=t,this.origin=s,this._meshes=[],this._aabb=h.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(cs,"numVisibleLayerPortions"),e(hs,"numCulledLayerPortions"),e(us,"numPickableLayerPortions"),e(ds,"numClippableLayerPortions"),e(fs,"numXRayedLayerPortions"),e(gs,"numHighlightedLayerPortions"),e(ms,"numSelectedLayerPortions"),this._renderers.edgesRenderers&&e(_s,"numEdgesLayerPortions"),this._countsByFlagArr=Object.values(this._countsByFlag),this._numTransparentLayerPortions=0}}aabbChanged(){this._aabbDirty=!0}__drawLayer(e,t,s,i){if(this._countsByFlag[hs].count<this._portions.length&&this._countsByFlag[cs].count>0){const e="points"!==this.primitive&&"lines"!==this.primitive&&[xs,Us,Os,Is,Ts,Ps];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[fs].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?xs:Us;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[fs].count<this._portions.length&&this.__drawLayer(e,t,s,xs)}__drawSilhouette(e,t,s,i){t.programColor=this.__setVec4FromMaterialColorAlpha(s.fillColor,s.fillAlpha,Cs),this.__drawLayer(e,t,this._renderers.silhouetteRenderer,i)}drawSilhouetteXRayed(e,t){this._countsByFlag[fs].count>0&&this.__drawSilhouette(e,t,this.model.scene.xrayMaterial,Ps)}drawSilhouetteHighlighted(e,t){this._countsByFlag[gs].count>0&&this.__drawSilhouette(e,t,this.model.scene.highlightMaterial,Is)}drawSilhouetteSelected(e,t){this._countsByFlag[ms].count>0&&this.__drawSilhouette(e,t,this.model.scene.selectedMaterial,Ts)}__drawVertexEdges(e,t,s){const i=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.vertex;i&&this._countsByFlag[_s].count>0&&this.__drawLayer(e,t,i,s)}drawEdgesColorOpaque(e,t){this._compiledPortions.edgesColorOpaqueAllowed()&&this.__drawVertexEdges(e,t,Ss)}drawEdgesColorTransparent(e,t){this._numTransparentLayerPortions>0&&this.__drawVertexEdges(e,t,Ds)}__drawUniformEdges(e,t,s,i){const r=this._renderers.edgesRenderers&&this._renderers.edgesRenderers.uniform;r&&(t.programColor=this.__setVec4FromMaterialColorAlpha(s.edgeColor,s.edgeAlpha,Cs),this.__drawLayer(e,t,r,i))}drawEdgesHighlighted(e,t){this._countsByFlag[gs].count>0&&this.__drawUniformEdges(e,t,this.model.scene.highlightMaterial,ks)}drawEdgesSelected(e,t){this._countsByFlag[ms].count>0&&this.__drawUniformEdges(e,t,this.model.scene.selectedMaterial,Qs)}drawEdgesXRayed(e,t){this._countsByFlag[fs].count>0&&this.__drawUniformEdges(e,t,this.model.scene.xrayMaterial,Rs)}__drawPick(e,t,s){s&&this.__drawLayer(e,t,s,Os)}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],this._aabbDirty&&(h.collapseAABB3(this._aabb),this._meshes.forEach((e=>h.expandAABB3(this._aabb,e.aabb))),this._aabbDirty=!1);const i=this._aabb;t.snapPickCoordinateScale=h.mulVec3Scalar(Vs([i[3]-i[0],i[4]-i[1],i[5]-i[2]]),h.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:Vs(t.snapPickCoordinateScale)})}drawOcclusion(e,t){const s=this._renderers.occlusionRenderer;s&&this.__drawLayer(e,t,s,xs)}drawShadow(e,t){const s=this._renderers.shadowRenderer;s&&this.__drawLayer(e,t,s,xs)}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[cs].fromFlags(t),this._setFlags(e,t,s)}setCulled(e,t,s){this._countsByFlag[hs].fromFlags(t),this._setFlags(e,t,s)}setPickable(e,t,s){this._countsByFlag[us].fromFlags(t),this._setFlags(e,t,s)}setClippable(e,t){this._countsByFlag[ds].fromFlags(t),this._compiledPortions.setClippableFlags(e,t)}setCollidable(e,t){}setXRayed(e,t,s){this._countsByFlag[fs].fromFlags(t),this._setFlags(e,t,s)}setHighlighted(e,t,s){this._countsByFlag[gs].fromFlags(t),this._setFlags(e,t,s)}setSelected(e,t,s){this._countsByFlag[ms].fromFlags(t),this._setFlags(e,t,s)}setEdges(e,t,s){this._countsByFlag[_s]&&(this._countsByFlag[_s].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 Gs=65536,js=5e6;class Ws{constructor(){}set doublePrecisionEnabled(e){h.setDoublePrecisionEnabled(e)}get doublePrecisionEnabled(){return h.getDoublePrecisionEnabled()}set maxDataTextureHeight(e){(e=1024*Math.ceil(e/1024))>4096?e=4096:e<1024&&(e=1024),Gs=e}get maxDataTextureHeight(){return Gs}set maxGeometryBatchSize(e){e<1e5?e=1e5:e>5e6&&(e=5e6),js=e}get maxGeometryBatchSize(){return js}}const zs=e=>{const t=[];for(let s=0;s<e;++s)t.push(s);return t},Xs={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(Xs,null,4));let e=0;Object.keys(Xs).forEach((t=>{t.startsWith("size")&&(e+=Xs[t])})),console.log(`Total size ${e} bytes (${(e/1e3/1e3).toFixed(2)} MB)`),console.log(`Avg bytes / triangle: ${(e/Xs.totalPolygons).toFixed(2)}`);let t={};Object.keys(Xs).forEach((s=>{s.startsWith("size")&&(t[s]=`${(Xs[s]/e*100).toFixed(2)} % of total`)})),console.log(JSON.stringify({percentualRamUsage:t},null,4))};const Ks=new Ws,Zs=Ks.maxDataTextureHeight,Js=h.vec3(),Ys=h.vec3(),$s=h.vec4();h.vec4();const qs=new Float32Array(16),ei=new Uint8Array(4),ti=h.identityMat4();class si extends Ns{constructor(e,t,s){super(e,t,s),Xs.numberOfLayers++,this._sortId=`TriDTX-${Xs.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);Xs[e]+=a,Xs.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);Xs[t]+=s,Xs.totalEdges+=s}}();return Xs.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&&Xs.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*Zs||i+n>4096*Zs)&&Xs.cannotCreatePortion.becauseTextureSize++,s&&=this._numVertices+r<=4096*Zs&&i+n<=4096*Zs}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),Xs[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||ti),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}),Xs.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=ii(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),u=c.textureData,d=function(e,t,s,i,r,n,A){return ii(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)},p=function(e,t,s){const i=e.length;if(0===i)throw"num "+t+" matrices===0";return d(e,i,16,l.FLOAT,512,t,s)},f=p(e.perObjectInstancePositioningMatrices,"sizeDataInstancesMatrices",!0),g=f.textureData,m=p(e.perObjectPositionsDecodeMatrices,"sizeDataPositionDecodeMatrices",!1),_=function(e,t,s,i,r){return d(e,t/s,s,i,4096,r,!1)},b=_(e.positionsCompressed,e.lenPositionsCompressed,3,l.UNSIGNED_SHORT,"sizeDataTexturePositions"),B=e.geometry8Bits.createDrawers(_,l.UNSIGNED_BYTE),y=e.geometry16Bits.createDrawers(_,l.UNSIGNED_SHORT),w=e.geometry32Bits.createDrawers(_,l.UNSIGNED_INT);this._buffer=null;let v=!1,C=!1,M=!1,E=0;const F=()=>{v=!0},x=a.on("rendering",(()=>{C&&(v=!1,C=!1,u.reloadData()),E=0})),U=(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)},I=(e,t,s,i)=>{const r=v||i;r?C=!0:++E>=10&&F(),u.setData(s,e,t,!r)},T=(e,t,s=!1)=>{ei.set([t&ds?255:0,0,1,2]),U(e,(e=>I(e,3,ei,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:T,setFlags:(e,t,s,i=!1)=>{Ls(t,s,!0,a,ei),U(e,(e=>I(e,2,ei,i)))},setFlags2:T,setDeferredFlags:()=>{},setColor:(e,t)=>{ei.set(t),U(e,(e=>I(e,0,ei,!1)))},setMatrix:(e,t)=>{U(e,(e=>{const s=v;s?C=!0:++E>=10&&F(),qs.set(t),g.setData(qs,e,0,!s)}))},setOffset:(e,t)=>{},getEachIndex:(e,t)=>{o&&U(e,(e=>o[e].indices.forEach((e=>t(e)))))},getEachVertex:(e,s)=>{o&&U(e,(e=>{const r=o[e],n=r.positionsCompressed,A=r.positionsDecodeMatrix,a=$s;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,h.decompressPosition(a,A),h.mulMat4v4(t.worldMatrix,a,a),h.addVec3(i,a,a),s(a)}))},precisionRayPickSurface:(e,t,s,i,r)=>!1,renderers:Hs(a,"dtx",n,t.saoEnabled,!1,!1,!0,((e,t)=>ri(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=h.transformPoint3(t.matrix,i,Js);s(n.uCameraEyeRtc,h.subVec3(A.eye,o,Ys)),s(n.perObjPosDecode,m),s(n.perVertIdCoords,b),s(n.perObjColsFlags,c),s(n.perObjectMatrix,f),e(n)}},s=function(t){return e((e=>{B.edges(e,t),y.edges(e,t),w.edges(e,t)}))};return{drawVertices:s(l.POINTS),drawEdges:s(l.LINES),drawSurface:e((e=>{const t=l.TRIANGLES;B.indices(e,t),y.indices(e,t),w.indices(e,t)}))}}(),destroy:()=>{M||(a.off(x),M=!0)}}}}const ii=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);Xs[A]+=f.byteLength,Xs.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)}}}},ri=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{geometryParameters:{attributes:{clippable:"(flags2.r > 0u)",color:p,flags:zs(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}}},ni=h.mat4(),Ai=h.mat4();function oi(e,t,s){const i=e.length,r=new Uint16Array(i),n=t[0],A=t[1],o=t[2],a=t[3]-n,l=t[4]-A,c=t[5]-o,u=65525,d=u/a,p=u/l,f=u/c,g=e=>e>=0?e:0;for(let t=0;t<i;t+=3)r[t+0]=Math.floor(g(e[t+0]-n)*d),r[t+1]=Math.floor(g(e[t+1]-A)*p),r[t+2]=Math.floor(g(e[t+2]-o)*f);return h.identityMat4(ni),h.translationMat4v(t,ni),h.identityMat4(Ai),h.scalingMat4v([a/u,l/u,c/u],Ai),h.mulMat4(ni,Ai,s),r}function ai(e,t){const s=e[0],i=e[1],r=e[2],n=e[3]-s,A=e[4]-i,o=e[5]-r,a=65525;return h.identityMat4(ni),h.translationMat4v(e,ni),h.identityMat4(Ai),h.scalingMat4v([n/a,A/a,o/a],Ai),h.mulMat4(ni,Ai,t),t}function li(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 ci(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 hi=new Float32Array(1),ui=new Float32Array(4),di=new Float32Array(3),pi=h.mat4(),fi=h.vec4([0,0,0,1]),gi=h.vec4(),mi=h.vec3(),_i=h.vec3(),bi=h.vec3(),Bi=h.vec3(),yi=h.vec3(),wi=h.vec3(),vi=h.vec3(),Ci=new Uint8Array(4),Mi=new Float32Array(96),Ei=function(e){const t=[];for(let s=0;s<e;++s)t.push(s);return t},Fi=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}},xi=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 Ui extends Ns{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&&h.mat4(n),this._cfgUvDecodeMatrix=i.uvDecodeMatrix&&h.mat3(i.uvDecodeMatrix),this._instancedGeometry=i.geometry,this._textureSet=i.textureSet,this._modelAABB=!r&&h.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,u)=>{const d=this._portions.length>0&&this._portions[this._portions.length-1],p={indicesBaseIndex:d?d.indicesBaseIndex+d.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&&h.vec3(),matrix:u&&u.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(p),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=h.inverseMat4(h.transposeMat4(l,h.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,u=t.normals;if(a&&a.length>0)s.normals.append(a);else if(u&&u.length>0){const e=pi;l?(h.transposeMat4(l,e),h.inverseMat4(e,e)):h.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,u,d=new Float32Array([0,0,0,0]),p=new Float32Array([0,0,0,0]);for(u=0;u<s;u+=3)d[0]=t[u],d[1]=t[u+1],d[2]=t[u+2],h.transformVec3(e,d,p),h.normalizeVec3(p,p),a=A=li(p,"floor","floor"),o=ci(A),l=c=n(p,o),A=li(p,"ceil","floor"),o=ci(A),l=n(p,o),l>c&&(a=A,c=l),A=li(p,"floor","ceil"),o=ci(A),l=n(p,o),l>c&&(a=A,c=l),A=li(p,"ceil","ceil"),o=ci(A),l=n(p,o),l>c&&(a=A,c=l),i[r+u+0]=a[0],i[r+u+1]=a[1],i[r+u+2]=0}(e,u,u.length,t,0),s.normals.append(t)}const d=t.colors,p=t.colorsCompressed,f=t.color;if(d)if("points"===A)s.colors.append(d,1,255);else{const e=[];for(let t=0,s=d.length;t<s;t+=3)e.push(255*d[t]),e.push(255*d[t+1]),e.push(255*d[t+2]),e.push(255);s.colors.append(e)}else if(p)if("points"===A)s.colors.append(p);else{const e=[];for(let t=0,s=p.length;t<s;t+=3)e.push(p[t]),e.push(p[t+1]),e.push(p[t+2]),e.push(255);s.colors.append(e)}else f&&s.colors.append([f[0],f[1],f[2],"points"===A?1:t.opacity],r);const g=e=>e&&e.length>0&&e,m=g(t.uv)||g(t.uvCompressed);m&&s.uv.append(m);const _=t.edgeIndices;return _&&s.edgeIndices.append(_,1,1,e),h.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,u=c.canvas.gl,d=!!t,p=[],f=(e,t,s,i)=>{if(t.length>0){const r=t.constructor,[n,A]={[Uint8Array]:[1,u.UNSIGNED_BYTE],[Int8Array]:[1,u.BYTE],[Uint16Array]:[2,u.UNSIGNED_SHORT],[Int16Array]:[2,u.SHORT],[Uint32Array]:[4,u.UNSIGNED_INT],[Int32Array]:[4,u.INT],[Float32Array]:[4,u.FLOAT]}[r],o=u.createBuffer();p.push((()=>u.deleteBuffer(o)));const a=()=>u.bindBuffer(e,o),l=t=>{a(),u.bufferData(e,t,i)};l(t);const c=t.BYTES_PER_ELEMENT,h=t.length/s;return{bindBuffer:a,getData:(t=0,i=h-t)=>{a();const A=new r(i*s);return u.getBufferSubData(e,t*n*s,A,0,i*s),A},numItems:h,setData:l,setSubData:(t,s)=>{a(),u.bufferSubData(e,s*c,t)},type:A}}return null},g=(e,t,s,i=!1,r=!1)=>{const n=f(u.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(),u.vertexAttribPointer(e,t,n.type,!!r,0,0)}}},m=e=>{const t=f(u.ELEMENT_ARRAY_BUFFER,e,1,u.STATIC_DRAW);return t&&{getData:t.getData,bindIndicesBuffer:t.bindBuffer,indicesCount:e.length,indicesType:t.type}},_=n.reduce(((e,t)=>e+t.portionSize),0),b=g(new Float32Array(_),1,u.DYNAMIC_DRAW,d),B=(e,t)=>g(e,4,t,d&&"points"!==A,!0),y=d&&t.colorsCompressed?B(new Uint8Array(t.colorsCompressed),u.STATIC_DRAW):B(e.colors.compileBuffer(Uint8Array),u.DYNAMIC_DRAW),w=c.entityOffsetsEnabled&&g(new Float32Array(3*_),3,u.DYNAMIC_DRAW,d),v=g(e.metallicRoughness.compileBuffer(Uint8Array),2,u.STATIC_DRAW,d),C=g(e.pickColors.compileBuffer(Uint8Array),4,u.STATIC_DRAW,d),M=m(d?new Uint32Array(t.edgeIndices):e.edgeIndices.compileBuffer(Uint32Array)),E=d?"points"!==A&&t.indices&&new Uint32Array(t.indices):e.indices.compileBuffer(Uint32Array),F=E&&m(E),x=d?t.positionsCompressed:a?e.positions.compileBuffer(Uint16Array):oi(e.positions.compileBuffer(Float64Array),i,a=h.mat4()),U=x&&g(x,3,u.STATIC_DRAW);d||n.forEach((e=>{if(e.retainedGeometry){const t=3*e.portionBase;e.retainedGeometry.quantizedPositions=x.subarray(t,t+3*e.portionSize)}}));const I=d&&e.modelMatrixCol.map((e=>g(e.compileBuffer(Float32Array),4,u.STATIC_DRAW,!0))),T=!d&&e.normals.compileBuffer(Int8Array),P=T&&g(T,3,u.STATIC_DRAW,!1,!0),S=I&&P&&e.modelNormalMatrixCol.map((e=>g(e.compileBuffer(Float32Array),4,u.STATIC_DRAW,!0))),D=d?"points"!==A&&"lines"!==A&&t.uvCompressed&&{buf:g(t.uvCompressed,2,u.STATIC_DRAW),mat:t.uvDecodeMatrix}:function(){const t=e.uv.compileBuffer(Float32Array);if(0===t.length)return null;if(l)return{buf:g(t,2,u.STATIC_DRAW),mat:l};{const e=he.getUVBounds(t),s=he.compressUVs(t,e.min,e.max);return{buf:g(s.quantized,2,u.STATIC_DRAW),mat:h.mat3(s.decodeMatrix)}}}();this._buffer=null,xi.acquire(),p.push((()=>xi.release()));let k=null;const Q=(e,s,i,r=!1)=>{Ls(s,i,"points"!==A&&"lines"!==A,c,Ci);const o=s&ds?1:0;let a=0;a|=Ci[0],a|=Ci[1]<<4,a|=Ci[2]<<8,a|=Ci[3]<<12,a|=o<<16,hi[0]=a;const l=n[e],h=l.portionBase,u=l.portionSize;if(r&&!t)k||(k=new Float32Array(_)),Fi(k.subarray(h,h+u),hi);else if(b){const e=xi.getTypeArray(Float32Array,u);Fi(e,hi),b.setSubData(e,h)}},R="solid"===A;return{edgesColorOpaqueAllowed:()=>!0,solid:R,sortId:("points"===A?"Points":"lines"===A?"Lines":"Triangles")+(d?"Instancing":"Batching")+"Layer"+("points"!==A&&"lines"!==A?(R?"-solid":"-surface")+"-autoNormals"+(d?"":(o&&o.colorTexture?"-colorTexture":"")+(o&&o.metallicRoughnessTexture?"-metallicRoughnessTexture":"")):""),setClippableFlags:Q,setFlags:Q,setFlags2:(e,t,s)=>{},setDeferredFlags:()=>{k&&(b.setData(k),k=null)},setColor:(e,t)=>{if(y){const s=n[e],i=xi.getTypeArray(Uint8Array,4*s.portionSize);Fi(i,t.slice(0,4)),y.setSubData(i,4*s.portionBase)}},setMatrix:(e,t)=>{I&&I.forEach(((s,i)=>{ui[0]=t[i+0],ui[1]=t[i+4],ui[2]=t[i+8],ui[3]=t[i+12],s.setSubData(ui,4*e)}))},setOffset:(e,t)=>{if(c.entityOffsetsEnabled){const s=n[e];if(w){di.set(t);const e=xi.getTypeArray(Float32Array,3*s.portionSize);Fi(e,di),w.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=gi;r?e.set(r,0):e[0]=e[1]=e[2]=0,e[3]=1;const n=s.matrix;h.mulMat4v4(n,e,e);const A=i.quantizedPositions,o=fi;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],h.decompressPosition(o,a),i.matrix&&h.transformPoint3(i.matrix,o,o),o[3]=1,h.mulMat4v4(n,o,o),h.addVec3(e,o,o),t(o)}},readGeometryData:"points"!==A&&"lines"!==A&&(e=>{const t=!d&&n[e],i=t?F.getData(t.indicesBaseIndex,t.numIndices).map((e=>e-t.portionBase)):F.getData(),A=s.matrix,o=h.vec4();o.set(r,0),o[3]=1,h.mulMat4v4(A,o,o);const l=I&&h.mat4();if(l){const t=I[0].getData(e,1),s=I[1].getData(e,1),i=I[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=h.mat4();h.mulMat4(A,l?h.mulMat4(l,a,c):a,c),c[12]+=o[0],c[13]+=o[1],c[14]+=o[2];const u=t?U.getData(t.portionBase,t.portionSize):U.getData();return{indices:i,positions:h.transformPositions3(c,u,new Float64Array(u.length))}}),precisionRayPickSurface:(e,t,i,A,o)=>{const l=n[e].retainedGeometry;if(l){l.matrix&&!l.inverseMatrix&&(l.inverseMatrix=h.inverseMat4(l.matrix,h.mat4())),o&&l.inverseMatrix&&!l.normalMatrix&&(l.normalMatrix=h.transposeMat4(l.inverseMatrix,h.mat4()));const e=l.quantizedPositions,n=l.indices,c=l.offset,u=mi,d=_i;u.set(r?h.subVec3(t,r,bi):t),d.set(i),c&&h.subVec3(u,c),h.transformRay(s.worldNormalMatrix,u,d,u,d),l.inverseMatrix&&h.transformRay(l.inverseMatrix,u,d,u,d);const p=Bi,f=yi,g=wi;let m=!1,_=0;const b=vi;for(let i=0,B=n.length;i<B;i+=3){const B=3*n[i],y=3*n[i+1],w=3*n[i+2];if(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],g[0]=e[w],g[1]=e[w+1],g[2]=e[w+2],h.decompressPosition(p,a),h.decompressPosition(f,a),h.decompressPosition(g,a),h.rayTriangleIntersect(u,d,p,f,g,b)){l.matrix&&h.transformPoint3(l.matrix,b,b),h.transformPoint3(s.worldMatrix,b,b),c&&h.addVec3(b,c),r&&h.addVec3(b,r);const e=Math.abs(h.lenVec3(h.subVec3(b,t,[])));(!m||e>_)&&(_=e,A.set(b),o&&h.triangleNormal(p,f,g,o),m=!0)}}return m&&o&&(l.normalMatrix&&h.transformVec3(l.normalMatrix,o,o),h.transformVec3(s.worldNormalMatrix,o,o),h.normalizeVec3(o)),m}return!1},layerTextureSet:o,renderers:Hs(c,d?"instancing":"batching",A,s.saoEnabled,s.pbrEnabled&&D&&o&&o.colorTexture&&P&&v&&o.metallicRoughnessTexture,s.colorTextureEnabled&&D&&o&&o.colorTexture,!!P,(e=>Ti(e,d&&{hasModelNormalMat:!!S},c.entityOffsetsEnabled))),drawCalls:function(){const e={},t=t=>(i,r,o)=>{let l=0;Mi.set(s.rotationMatrix,0),Mi.set(o.viewMatrix,l+=16),Mi.set(o.projMatrix,l+=16),Mi.set(a,l+=16),r.needNormal()&&(Mi.set(s.worldNormalMatrix,l+=16),Mi.set(o.viewNormalMatrix,l+=16)),r.matrices.setInputValue(Mi),r.uvDecodeMatrix.setInputValue&&r.uvDecodeMatrix.setInputValue(D.mat),i in e||(e[i]=[null,null,null]);const c=e[i],h=t?t.vertices?0:1:2;if(!c[h]){const e=u.createVertexArray();u.bindVertexArray(e);const s=(e,t)=>{e&&e.setInputValue&&t&&e.setInputValue(t)},i=r.attributes;s(i.position,U),s(i.normal,P),s(i.color,y),s(i.pickColor,C),s(i.uV,D&&D.buf),s(i.metallicRoughness,v),s(i.flags,b),s(i.offset,w),i.modelMatrixCol&&i.modelMatrixCol.forEach(((e,t)=>s(e,I[t]))),i.modelNormalMatrixCol&&i.modelNormalMatrixCol.forEach(((e,t)=>s(e,S[t])));const o=function(){const e=()=>{d?u.drawArraysInstanced(u.POINTS,0,U.numItems,n.length):u.drawArrays(u.POINTS,0,U.numItems)},s=(e,t)=>{t.bindIndicesBuffer();const s=t.indicesCount,i=t.indicesType;return()=>{d?u.drawElementsInstanced(e,s,i,0,n.length):u.drawElements(e,s,i,0)}};return"points"===A?e:"lines"===A?t&&t.vertices?e:s(u.LINES,F):t&&t.vertices?e:t&&M?s(u.LINES,M):s(u.TRIANGLES,F)}();u.bindVertexArray(null),p.push((()=>u.deleteVertexArray(e))),c[h]=()=>{u.bindVertexArray(e),o(),u.bindVertexArray(null)}}c[h]()};return{drawVertices:t({vertices:!0}),drawEdges:t({}),drawSurface:t(null)}}(),destroy:()=>{p.forEach((e=>e())),p.length=0}}}}const Ii=function(e){const t={toString:()=>(t.needed=!0,e)};return t},Ti=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&&Ei(3).map((e=>i("vec4","modelMatrixCol"+e))),modelNormalMatrixCol:t&&t.hasModelNormalMat&&Ei(3).map((e=>i("vec4","modelNormalMatrixCol"+e)))},n=Ii("aUv"),A=Ii("viewNormal"),o=Ii("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,geometryParameters:{attributes:{clippable:`((int(${r.flags}) >> 16 & 0xF) == 1)`,color:r.color,flags:Ei(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 Pi{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 Si{constructor(e){this.id=e.id,this.texture=e.texture}destroy(){this.texture&&(this.texture.destroy(),this.texture=null)}}const Di={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 ki{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 Qi=new ki;class Ri{constructor(e){this.manager=void 0!==e?e:Qi,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 Oi={};class Vi extends Ri{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=Di.get(e);if(void 0!==r)return this.manager.itemStart(e),F.scheduleTask((()=>{t&&t(r),this.manager.itemEnd(e)}),0),r;if(void 0!==Oi[e])return void Oi[e].push({onLoad:t,onProgress:s,onError:i});Oi[e]=[],Oi[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=Oi[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=>{Di.add(e,t);const s=Oi[e];delete Oi[e];for(let e=0,i=s.length;e<i;e++){const i=s[e];i.onLoad&&i.onLoad(t)}})).catch((t=>{const s=Oi[e];if(void 0===s)throw this.manager.itemError(e),t;delete Oi[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 Li{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 Hi=0;class Ni{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 Li,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 Vi;e.setPath(this._transcoderPath),e.setWithCredentials(this.withCredentials);const t=e.loadAsync("basis_transcoder.js"),s=new Vi;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=Ni.BasisWorker.toString(),i=["/* constants */","let _EngineFormat = "+JSON.stringify(Ni.EngineFormat),"let _TranscoderFormat = "+JSON.stringify(Ni.TranscoderFormat),"let _BasisFormat = "+JSON.stringify(Ni.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}))})),Hi>0&&console.warn("KTX2TextureTranscoder: Multiple active KTX2TextureTranscoder may cause performance issues. Use a single KTX2TextureTranscoder instance, or call .dispose() on old instances."),Hi++}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(),Hi--}}Ni.BasisFormat={ETC1S:0,UASTC_4x4:1},Ni.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},Ni.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},Ni.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 Gi={};function ji(e){const t=e.scene.id;let s=Gi[t];return s||(s=new Ni({viewer:e}),Gi[t]=s,e.scene.on("destroyed",(()=>{delete Gi[t],s.destroy()}))),s}
8
8
  /**
9
9
  * @author https://github.com/tmarti, with support from https://tribia.com/
10
10
  * @license MIT