!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).NGL={})}(this,(function(e){"use strict";const t=1,i=2,n=3,r=0,s=1,a=2,o=100,l=101,c=102,u=200,h=201,d=202,f=203,m=204,p=205,g=206,_=207,y=208,v=209,b=210,x=211,w=212,S=213,M=214,A=0,C=1,T=2,P=0,E=1,I=2,D=3,R=4,L=5,k=301,O=302,N=306,F=1e3,B=1001,z=1002,U=1003,V=1004,$=1005,G=1006,H=1007,j=1008,W=1009,q=1012,X=1013,Y=1014,K=1015,Z=1016,Q=1020,J=1023,ee=1026,te=1027,ie=33776,ne=33777,re=33778,se=33779,ae=36492,oe=3001,le="",ce="srgb",ue="srgb-linear",he="display-p3",de="display-p3-linear",fe="linear",me="srgb",pe="rec709",ge="p3",_e=7680,ye=512,ve=513,be=514,xe=515,we=516,Se=517,Me=518,Ae=519,Ce=35044,Te=35048,Pe="300 es",Ee=1035,Ie=2e3,De=2001;class Re{addEventListener(e,t){void 0===this._listeners&&(this._listeners={});const i=this._listeners;void 0===i[e]&&(i[e]=[]),-1===i[e].indexOf(t)&&i[e].push(t)}hasEventListener(e,t){if(void 0===this._listeners)return!1;const i=this._listeners;return void 0!==i[e]&&-1!==i[e].indexOf(t)}removeEventListener(e,t){if(void 0===this._listeners)return;const i=this._listeners[e];if(void 0!==i){const e=i.indexOf(t);-1!==e&&i.splice(e,1)}}dispatchEvent(e){if(void 0===this._listeners)return;const t=this._listeners[e.type];if(void 0!==t){e.target=this;const i=t.slice(0);for(let t=0,n=i.length;t>8&255]+Le[e>>16&255]+Le[e>>24&255]+"-"+Le[255&t]+Le[t>>8&255]+"-"+Le[t>>16&15|64]+Le[t>>24&255]+"-"+Le[63&i|128]+Le[i>>8&255]+"-"+Le[i>>16&255]+Le[i>>24&255]+Le[255&n]+Le[n>>8&255]+Le[n>>16&255]+Le[n>>24&255]).toLowerCase()}function Fe(e,t,i){return Math.max(t,Math.min(i,e))}function Be(e,t,i){return(1-i)*e+i*t}function ze(e){return!(e&e-1)&&0!==e}function Ue(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))}function Ve(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return e/4294967295;case Uint16Array:return e/65535;case Uint8Array:return e/255;case Int32Array:return Math.max(e/2147483647,-1);case Int16Array:return Math.max(e/32767,-1);case Int8Array:return Math.max(e/127,-1);default:throw new Error("Invalid component type.")}}function $e(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return Math.round(4294967295*e);case Uint16Array:return Math.round(65535*e);case Uint8Array:return Math.round(255*e);case Int32Array:return Math.round(2147483647*e);case Int16Array:return Math.round(32767*e);case Int8Array:return Math.round(127*e);default:throw new Error("Invalid component type.")}}class Ge{constructor(e=0,t=0){Ge.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,i=this.y,n=e.elements;return this.x=n[0]*t+n[3]*i+n[6],this.y=n[1]*t+n[4]*i+n[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(0===t)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(Fe(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const i=Math.cos(t),n=Math.sin(t),r=this.x-e.x,s=this.y-e.y;return this.x=r*i-s*n+e.x,this.y=r*n+s*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class He{constructor(e,t,i,n,r,s,a,o,l){He.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==e&&this.set(e,t,i,n,r,s,a,o,l)}set(e,t,i,n,r,s,a,o,l){const c=this.elements;return c[0]=e,c[1]=n,c[2]=a,c[3]=t,c[4]=r,c[5]=o,c[6]=i,c[7]=s,c[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,r=this.elements,s=i[0],a=i[3],o=i[6],l=i[1],c=i[4],u=i[7],h=i[2],d=i[5],f=i[8],m=n[0],p=n[3],g=n[6],_=n[1],y=n[4],v=n[7],b=n[2],x=n[5],w=n[8];return r[0]=s*m+a*_+o*b,r[3]=s*p+a*y+o*x,r[6]=s*g+a*v+o*w,r[1]=l*m+c*_+u*b,r[4]=l*p+c*y+u*x,r[7]=l*g+c*v+u*w,r[2]=h*m+d*_+f*b,r[5]=h*p+d*y+f*x,r[8]=h*g+d*v+f*w,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[1],n=e[2],r=e[3],s=e[4],a=e[5],o=e[6],l=e[7],c=e[8];return t*s*c-t*a*l-i*r*c+i*a*o+n*r*l-n*s*o}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],r=e[3],s=e[4],a=e[5],o=e[6],l=e[7],c=e[8],u=c*s-a*l,h=a*o-c*r,d=l*r-s*o,f=t*u+i*h+n*d;if(0===f)return this.set(0,0,0,0,0,0,0,0,0);const m=1/f;return e[0]=u*m,e[1]=(n*l-c*i)*m,e[2]=(a*i-n*s)*m,e[3]=h*m,e[4]=(c*t-n*o)*m,e[5]=(n*r-a*t)*m,e[6]=d*m,e[7]=(i*o-l*t)*m,e[8]=(s*t-i*r)*m,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,n,r,s,a){const o=Math.cos(r),l=Math.sin(r);return this.set(i*o,i*l,-i*(o*s+l*a)+s+e,-n*l,n*o,-n*(-l*s+o*a)+a+t,0,0,1),this}scale(e,t){return this.premultiply(je.makeScale(e,t)),this}rotate(e){return this.premultiply(je.makeRotation(-e)),this}translate(e,t){return this.premultiply(je.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,i,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,i=e.elements;for(let e=0;e<9;e++)if(t[e]!==i[e])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return(new this.constructor).fromArray(this.elements)}}const je=new He;function We(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}function qe(e){return document.createElementNS("http://www.w3.org/1999/xhtml",e)}function Xe(){const e=qe("canvas");return e.style.display="block",e}const Ye={};function Ke(e){e in Ye||(Ye[e]=!0,console.warn(e))}const Ze=(new He).set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),Qe=(new He).set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),Je={[ue]:{transfer:fe,primaries:pe,toReference:e=>e,fromReference:e=>e},[ce]:{transfer:me,primaries:pe,toReference:e=>e.convertSRGBToLinear(),fromReference:e=>e.convertLinearToSRGB()},[de]:{transfer:fe,primaries:ge,toReference:e=>e.applyMatrix3(Qe),fromReference:e=>e.applyMatrix3(Ze)},[he]:{transfer:me,primaries:ge,toReference:e=>e.convertSRGBToLinear().applyMatrix3(Qe),fromReference:e=>e.applyMatrix3(Ze).convertLinearToSRGB()}},et=new Set([ue,de]),tt={enabled:!0,_workingColorSpace:ue,get legacyMode(){return console.warn("THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150."),!this.enabled},set legacyMode(e){console.warn("THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150."),this.enabled=!e},get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(e){if(!et.has(e))throw new Error(`Unsupported working color space, "${e}".`);this._workingColorSpace=e},convert:function(e,t,i){if(!1===this.enabled||t===i||!t||!i)return e;const n=Je[t].toReference;return(0,Je[i].fromReference)(n(e))},fromWorkingColorSpace:function(e,t){return this.convert(e,this._workingColorSpace,t)},toWorkingColorSpace:function(e,t){return this.convert(e,t,this._workingColorSpace)},getPrimaries:function(e){return Je[e].primaries},getTransfer:function(e){return e===le?fe:Je[e].transfer}};function it(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function nt(e){return e<.0031308?12.92*e:1.055*Math.pow(e,.41666)-.055}let rt;class st{static getDataURL(e){if(/^data:/i.test(e.src))return e.src;if("undefined"==typeof HTMLCanvasElement)return e.src;let t;if(e instanceof HTMLCanvasElement)t=e;else{void 0===rt&&(rt=qe("canvas")),rt.width=e.width,rt.height=e.height;const i=rt.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),t=rt}return t.width>2048||t.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",e),t.toDataURL("image/jpeg",.6)):t.toDataURL("image/png")}static sRGBToLinear(e){if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap){const t=qe("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");i.drawImage(e,0,0,e.width,e.height);const n=i.getImageData(0,0,e.width,e.height),r=n.data;for(let e=0;e0&&(i.userData=this.userData),t||(e.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(300!==this.mapping)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case F:e.x=e.x-Math.floor(e.x);break;case B:e.x=e.x<0?0:1;break;case z:1===Math.abs(Math.floor(e.x)%2)?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x)}if(e.y<0||e.y>1)switch(this.wrapT){case F:e.y=e.y-Math.floor(e.y);break;case B:e.y=e.y<0?0:1;break;case z:1===Math.abs(Math.floor(e.y)%2)?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y)}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){!0===e&&(this.version++,this.source.needsUpdate=!0)}get encoding(){return Ke("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace===ce?oe:3e3}set encoding(e){Ke("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace=e===oe?ce:le}}ut.DEFAULT_IMAGE=null,ut.DEFAULT_MAPPING=300,ut.DEFAULT_ANISOTROPY=1;class ht{constructor(e=0,t=0,i=0,n=1){ht.prototype.isVector4=!0,this.x=e,this.y=t,this.z=i,this.w=n}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=void 0!==e.w?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,r=this.w,s=e.elements;return this.x=s[0]*t+s[4]*i+s[8]*n+s[12]*r,this.y=s[1]*t+s[5]*i+s[9]*n+s[13]*r,this.z=s[2]*t+s[6]*i+s[10]*n+s[14]*r,this.w=s[3]*t+s[7]*i+s[11]*n+s[15]*r,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,i,n,r;const s=.01,a=.1,o=e.elements,l=o[0],c=o[4],u=o[8],h=o[1],d=o[5],f=o[9],m=o[2],p=o[6],g=o[10];if(Math.abs(c-h)o&&e>_?e_?o=0?1:-1,n=1-t*t;if(n>Number.EPSILON){const r=Math.sqrt(n),s=Math.atan2(r,t*i);e=Math.sin(e*s)/r,a=Math.sin(a*s)/r}const r=a*i;if(o=o*e+h*r,l=l*e+d*r,c=c*e+f*r,u=u*e+m*r,e===1-a){const e=1/Math.sqrt(o*o+l*l+c*c+u*u);o*=e,l*=e,c*=e,u*=e}}e[t]=o,e[t+1]=l,e[t+2]=c,e[t+3]=u}static multiplyQuaternionsFlat(e,t,i,n,r,s){const a=i[n],o=i[n+1],l=i[n+2],c=i[n+3],u=r[s],h=r[s+1],d=r[s+2],f=r[s+3];return e[t]=a*f+c*u+o*d-l*h,e[t+1]=o*f+c*h+l*u-a*d,e[t+2]=l*f+c*d+a*h-o*u,e[t+3]=c*f-a*u-o*h-l*d,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,i,n){return this._x=e,this._y=t,this._z=i,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t){const i=e._x,n=e._y,r=e._z,s=e._order,a=Math.cos,o=Math.sin,l=a(i/2),c=a(n/2),u=a(r/2),h=o(i/2),d=o(n/2),f=o(r/2);switch(s){case"XYZ":this._x=h*c*u+l*d*f,this._y=l*d*u-h*c*f,this._z=l*c*f+h*d*u,this._w=l*c*u-h*d*f;break;case"YXZ":this._x=h*c*u+l*d*f,this._y=l*d*u-h*c*f,this._z=l*c*f-h*d*u,this._w=l*c*u+h*d*f;break;case"ZXY":this._x=h*c*u-l*d*f,this._y=l*d*u+h*c*f,this._z=l*c*f+h*d*u,this._w=l*c*u-h*d*f;break;case"ZYX":this._x=h*c*u-l*d*f,this._y=l*d*u+h*c*f,this._z=l*c*f-h*d*u,this._w=l*c*u+h*d*f;break;case"YZX":this._x=h*c*u+l*d*f,this._y=l*d*u+h*c*f,this._z=l*c*f-h*d*u,this._w=l*c*u-h*d*f;break;case"XZY":this._x=h*c*u-l*d*f,this._y=l*d*u-h*c*f,this._z=l*c*f+h*d*u,this._w=l*c*u+h*d*f;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+s)}return!1!==t&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const i=t/2,n=Math.sin(i);return this._x=e.x*n,this._y=e.y*n,this._z=e.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,i=t[0],n=t[4],r=t[8],s=t[1],a=t[5],o=t[9],l=t[2],c=t[6],u=t[10],h=i+a+u;if(h>0){const e=.5/Math.sqrt(h+1);this._w=.25/e,this._x=(c-o)*e,this._y=(r-l)*e,this._z=(s-n)*e}else if(i>a&&i>u){const e=2*Math.sqrt(1+i-a-u);this._w=(c-o)/e,this._x=.25*e,this._y=(n+s)/e,this._z=(r+l)/e}else if(a>u){const e=2*Math.sqrt(1+a-i-u);this._w=(r-l)/e,this._x=(n+s)/e,this._y=.25*e,this._z=(o+c)/e}else{const e=2*Math.sqrt(1+u-i-a);this._w=(s-n)/e,this._x=(r+l)/e,this._y=(o+c)/e,this._z=.25*e}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let i=e.dot(t)+1;return iMath.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=i):(this._x=0,this._y=-e.z,this._z=e.y,this._w=i)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=i),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Fe(this.dot(e),-1,1)))}rotateTowards(e,t){const i=this.angleTo(e);if(0===i)return this;const n=Math.min(1,t/i);return this.slerp(e,n),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return 0===e?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const i=e._x,n=e._y,r=e._z,s=e._w,a=t._x,o=t._y,l=t._z,c=t._w;return this._x=i*c+s*a+n*l-r*o,this._y=n*c+s*o+r*a-i*l,this._z=r*c+s*l+i*o-n*a,this._w=s*c-i*a-n*o-r*l,this._onChangeCallback(),this}slerp(e,t){if(0===t)return this;if(1===t)return this.copy(e);const i=this._x,n=this._y,r=this._z,s=this._w;let a=s*e._w+i*e._x+n*e._y+r*e._z;if(a<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,a=-a):this.copy(e),a>=1)return this._w=s,this._x=i,this._y=n,this._z=r,this;const o=1-a*a;if(o<=Number.EPSILON){const e=1-t;return this._w=e*s+t*this._w,this._x=e*i+t*this._x,this._y=e*n+t*this._y,this._z=e*r+t*this._z,this.normalize(),this._onChangeCallback(),this}const l=Math.sqrt(o),c=Math.atan2(l,a),u=Math.sin((1-t)*c)/l,h=Math.sin(t*c)/l;return this._w=s*u+this._w*h,this._x=i*u+this._x*h,this._y=n*u+this._y*h,this._z=r*u+this._z*h,this._onChangeCallback(),this}slerpQuaternions(e,t,i){return this.copy(e).slerp(t,i)}random(){const e=Math.random(),t=Math.sqrt(1-e),i=Math.sqrt(e),n=2*Math.PI*Math.random(),r=2*Math.PI*Math.random();return this.set(t*Math.cos(n),i*Math.sin(r),i*Math.cos(r),t*Math.sin(n))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class _t{constructor(e=0,t=0,i=0){_t.prototype.isVector3=!0,this.x=e,this.y=t,this.z=i}set(e,t,i){return void 0===i&&(i=this.z),this.x=e,this.y=t,this.z=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(vt.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(vt.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,i=this.y,n=this.z,r=e.elements;return this.x=r[0]*t+r[3]*i+r[6]*n,this.y=r[1]*t+r[4]*i+r[7]*n,this.z=r[2]*t+r[5]*i+r[8]*n,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,i=this.y,n=this.z,r=e.elements,s=1/(r[3]*t+r[7]*i+r[11]*n+r[15]);return this.x=(r[0]*t+r[4]*i+r[8]*n+r[12])*s,this.y=(r[1]*t+r[5]*i+r[9]*n+r[13])*s,this.z=(r[2]*t+r[6]*i+r[10]*n+r[14])*s,this}applyQuaternion(e){const t=this.x,i=this.y,n=this.z,r=e.x,s=e.y,a=e.z,o=e.w,l=2*(s*n-a*i),c=2*(a*t-r*n),u=2*(r*i-s*t);return this.x=t+o*l+s*u-a*c,this.y=i+o*c+a*l-r*u,this.z=n+o*u+r*c-s*l,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,i=this.y,n=this.z,r=e.elements;return this.x=r[0]*t+r[4]*i+r[8]*n,this.y=r[1]*t+r[5]*i+r[9]*n,this.z=r[2]*t+r[6]*i+r[10]*n,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const i=e.x,n=e.y,r=e.z,s=t.x,a=t.y,o=t.z;return this.x=n*o-r*a,this.y=r*s-i*o,this.z=i*a-n*s,this}projectOnVector(e){const t=e.lengthSq();if(0===t)return this.set(0,0,0);const i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}projectOnPlane(e){return yt.copy(this).projectOnVector(e),this.sub(yt)}reflect(e){return this.sub(yt.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(0===t)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(Fe(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y,n=this.z-e.z;return t*t+i*i+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,i){const n=Math.sin(t)*e;return this.x=n*Math.sin(i),this.y=Math.cos(t)*e,this.z=n*Math.cos(i),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),n=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=n,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,4*t)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,3*t)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=2*(Math.random()-.5),t=Math.random()*Math.PI*2,i=Math.sqrt(1-e**2);return this.x=i*Math.cos(t),this.y=i*Math.sin(t),this.z=e,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const yt=new _t,vt=new gt;class bt{constructor(e=new _t(1/0,1/0,1/0),t=new _t(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,i=e.length;tthis.max.x||e.ythis.max.y||e.zthis.max.z)}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return!(e.max.xthis.max.x||e.max.ythis.max.y||e.max.zthis.max.z)}intersectsSphere(e){return this.clampPoint(e.center,wt),wt.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,i;return e.normal.x>0?(t=e.normal.x*this.min.x,i=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,i=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,i+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,i+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,i+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,i+=e.normal.z*this.min.z),t<=-e.constant&&i>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(It),Dt.subVectors(this.max,It),Mt.subVectors(e.a,It),At.subVectors(e.b,It),Ct.subVectors(e.c,It),Tt.subVectors(At,Mt),Pt.subVectors(Ct,At),Et.subVectors(Mt,Ct);let t=[0,-Tt.z,Tt.y,0,-Pt.z,Pt.y,0,-Et.z,Et.y,Tt.z,0,-Tt.x,Pt.z,0,-Pt.x,Et.z,0,-Et.x,-Tt.y,Tt.x,0,-Pt.y,Pt.x,0,-Et.y,Et.x,0];return!!kt(t,Mt,At,Ct,Dt)&&(t=[1,0,0,0,1,0,0,0,1],!!kt(t,Mt,At,Ct,Dt)&&(Rt.crossVectors(Tt,Pt),t=[Rt.x,Rt.y,Rt.z],kt(t,Mt,At,Ct,Dt)))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,wt).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=.5*this.getSize(wt).length()),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()||(xt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),xt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),xt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),xt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),xt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),xt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),xt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),xt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(xt)),this}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}}const xt=[new _t,new _t,new _t,new _t,new _t,new _t,new _t,new _t],wt=new _t,St=new bt,Mt=new _t,At=new _t,Ct=new _t,Tt=new _t,Pt=new _t,Et=new _t,It=new _t,Dt=new _t,Rt=new _t,Lt=new _t;function kt(e,t,i,n,r){for(let s=0,a=e.length-3;s<=a;s+=3){Lt.fromArray(e,s);const a=r.x*Math.abs(Lt.x)+r.y*Math.abs(Lt.y)+r.z*Math.abs(Lt.z),o=t.dot(Lt),l=i.dot(Lt),c=n.dot(Lt);if(Math.max(-Math.max(o,l,c),Math.min(o,l,c))>a)return!1}return!0}const Ot=new bt,Nt=new _t,Ft=new _t;class Bt{constructor(e=new _t,t=-1){this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const i=this.center;void 0!==t?i.copy(t):Ot.setFromPoints(e).getCenter(i);let n=0;for(let t=0,r=e.length;tthis.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;Nt.subVectors(e,this.center);const t=Nt.lengthSq();if(t>this.radius*this.radius){const e=Math.sqrt(t),i=.5*(e-this.radius);this.center.addScaledVector(Nt,i/e),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(!0===this.center.equals(e.center)?this.radius=Math.max(this.radius,e.radius):(Ft.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(Nt.copy(e.center).add(Ft)),this.expandByPoint(Nt.copy(e.center).sub(Ft))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const zt=new _t,Ut=new _t,Vt=new _t,$t=new _t,Gt=new _t,Ht=new _t,jt=new _t;class Wt{constructor(e=new _t,t=new _t(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,zt)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const i=t.dot(this.direction);return i<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=zt.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(zt.copy(this.origin).addScaledVector(this.direction,t),zt.distanceToSquared(e))}distanceSqToSegment(e,t,i,n){Ut.copy(e).add(t).multiplyScalar(.5),Vt.copy(t).sub(e).normalize(),$t.copy(this.origin).sub(Ut);const r=.5*e.distanceTo(t),s=-this.direction.dot(Vt),a=$t.dot(this.direction),o=-$t.dot(Vt),l=$t.lengthSq(),c=Math.abs(1-s*s);let u,h,d,f;if(c>0)if(u=s*o-a,h=s*a-o,f=r*c,u>=0)if(h>=-f)if(h<=f){const e=1/c;u*=e,h*=e,d=u*(u+s*h+2*a)+h*(s*u+h+2*o)+l}else h=r,u=Math.max(0,-(s*h+a)),d=-u*u+h*(h+2*o)+l;else h=-r,u=Math.max(0,-(s*h+a)),d=-u*u+h*(h+2*o)+l;else h<=-f?(u=Math.max(0,-(-s*r+a)),h=u>0?-r:Math.min(Math.max(-r,-o),r),d=-u*u+h*(h+2*o)+l):h<=f?(u=0,h=Math.min(Math.max(-r,-o),r),d=h*(h+2*o)+l):(u=Math.max(0,-(s*r+a)),h=u>0?r:Math.min(Math.max(-r,-o),r),d=-u*u+h*(h+2*o)+l);else h=s>0?-r:r,u=Math.max(0,-(s*h+a)),d=-u*u+h*(h+2*o)+l;return i&&i.copy(this.origin).addScaledVector(this.direction,u),n&&n.copy(Ut).addScaledVector(Vt,h),d}intersectSphere(e,t){zt.subVectors(e.center,this.origin);const i=zt.dot(this.direction),n=zt.dot(zt)-i*i,r=e.radius*e.radius;if(n>r)return null;const s=Math.sqrt(r-n),a=i-s,o=i+s;return o<0?null:a<0?this.at(o,t):this.at(a,t)}intersectsSphere(e){return this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(0===t)return 0===e.distanceToPoint(this.origin)?0:null;const i=-(this.origin.dot(e.normal)+e.constant)/t;return i>=0?i:null}intersectPlane(e,t){const i=this.distanceToPlane(e);return null===i?null:this.at(i,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);if(0===t)return!0;return e.normal.dot(this.direction)*t<0}intersectBox(e,t){let i,n,r,s,a,o;const l=1/this.direction.x,c=1/this.direction.y,u=1/this.direction.z,h=this.origin;return l>=0?(i=(e.min.x-h.x)*l,n=(e.max.x-h.x)*l):(i=(e.max.x-h.x)*l,n=(e.min.x-h.x)*l),c>=0?(r=(e.min.y-h.y)*c,s=(e.max.y-h.y)*c):(r=(e.max.y-h.y)*c,s=(e.min.y-h.y)*c),i>s||r>n?null:((r>i||isNaN(i))&&(i=r),(s=0?(a=(e.min.z-h.z)*u,o=(e.max.z-h.z)*u):(a=(e.max.z-h.z)*u,o=(e.min.z-h.z)*u),i>o||a>n?null:((a>i||i!=i)&&(i=a),(o=0?i:n,t)))}intersectsBox(e){return null!==this.intersectBox(e,zt)}intersectTriangle(e,t,i,n,r){Gt.subVectors(t,e),Ht.subVectors(i,e),jt.crossVectors(Gt,Ht);let s,a=this.direction.dot(jt);if(a>0){if(n)return null;s=1}else{if(!(a<0))return null;s=-1,a=-a}$t.subVectors(this.origin,e);const o=s*this.direction.dot(Ht.crossVectors($t,Ht));if(o<0)return null;const l=s*this.direction.dot(Gt.cross($t));if(l<0)return null;if(o+l>a)return null;const c=-s*$t.dot(jt);return c<0?null:this.at(c/a,r)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class qt{constructor(e,t,i,n,r,s,a,o,l,c,u,h,d,f,m,p){qt.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==e&&this.set(e,t,i,n,r,s,a,o,l,c,u,h,d,f,m,p)}set(e,t,i,n,r,s,a,o,l,c,u,h,d,f,m,p){const g=this.elements;return g[0]=e,g[4]=t,g[8]=i,g[12]=n,g[1]=r,g[5]=s,g[9]=a,g[13]=o,g[2]=l,g[6]=c,g[10]=u,g[14]=h,g[3]=d,g[7]=f,g[11]=m,g[15]=p,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new qt).fromArray(this.elements)}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],this}copyPosition(e){const t=this.elements,i=e.elements;return t[12]=i[12],t[13]=i[13],t[14]=i[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,i){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(e,t,i){return this.set(e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,i=e.elements,n=1/Xt.setFromMatrixColumn(e,0).length(),r=1/Xt.setFromMatrixColumn(e,1).length(),s=1/Xt.setFromMatrixColumn(e,2).length();return t[0]=i[0]*n,t[1]=i[1]*n,t[2]=i[2]*n,t[3]=0,t[4]=i[4]*r,t[5]=i[5]*r,t[6]=i[6]*r,t[7]=0,t[8]=i[8]*s,t[9]=i[9]*s,t[10]=i[10]*s,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,i=e.x,n=e.y,r=e.z,s=Math.cos(i),a=Math.sin(i),o=Math.cos(n),l=Math.sin(n),c=Math.cos(r),u=Math.sin(r);if("XYZ"===e.order){const e=s*c,i=s*u,n=a*c,r=a*u;t[0]=o*c,t[4]=-o*u,t[8]=l,t[1]=i+n*l,t[5]=e-r*l,t[9]=-a*o,t[2]=r-e*l,t[6]=n+i*l,t[10]=s*o}else if("YXZ"===e.order){const e=o*c,i=o*u,n=l*c,r=l*u;t[0]=e+r*a,t[4]=n*a-i,t[8]=s*l,t[1]=s*u,t[5]=s*c,t[9]=-a,t[2]=i*a-n,t[6]=r+e*a,t[10]=s*o}else if("ZXY"===e.order){const e=o*c,i=o*u,n=l*c,r=l*u;t[0]=e-r*a,t[4]=-s*u,t[8]=n+i*a,t[1]=i+n*a,t[5]=s*c,t[9]=r-e*a,t[2]=-s*l,t[6]=a,t[10]=s*o}else if("ZYX"===e.order){const e=s*c,i=s*u,n=a*c,r=a*u;t[0]=o*c,t[4]=n*l-i,t[8]=e*l+r,t[1]=o*u,t[5]=r*l+e,t[9]=i*l-n,t[2]=-l,t[6]=a*o,t[10]=s*o}else if("YZX"===e.order){const e=s*o,i=s*l,n=a*o,r=a*l;t[0]=o*c,t[4]=r-e*u,t[8]=n*u+i,t[1]=u,t[5]=s*c,t[9]=-a*c,t[2]=-l*c,t[6]=i*u+n,t[10]=e-r*u}else if("XZY"===e.order){const e=s*o,i=s*l,n=a*o,r=a*l;t[0]=o*c,t[4]=-u,t[8]=l*c,t[1]=e*u+r,t[5]=s*c,t[9]=i*u-n,t[2]=n*u-i,t[6]=a*c,t[10]=r*u+e}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(Kt,e,Zt)}lookAt(e,t,i){const n=this.elements;return ei.subVectors(e,t),0===ei.lengthSq()&&(ei.z=1),ei.normalize(),Qt.crossVectors(i,ei),0===Qt.lengthSq()&&(1===Math.abs(i.z)?ei.x+=1e-4:ei.z+=1e-4,ei.normalize(),Qt.crossVectors(i,ei)),Qt.normalize(),Jt.crossVectors(ei,Qt),n[0]=Qt.x,n[4]=Jt.x,n[8]=ei.x,n[1]=Qt.y,n[5]=Jt.y,n[9]=ei.y,n[2]=Qt.z,n[6]=Jt.z,n[10]=ei.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,n=t.elements,r=this.elements,s=i[0],a=i[4],o=i[8],l=i[12],c=i[1],u=i[5],h=i[9],d=i[13],f=i[2],m=i[6],p=i[10],g=i[14],_=i[3],y=i[7],v=i[11],b=i[15],x=n[0],w=n[4],S=n[8],M=n[12],A=n[1],C=n[5],T=n[9],P=n[13],E=n[2],I=n[6],D=n[10],R=n[14],L=n[3],k=n[7],O=n[11],N=n[15];return r[0]=s*x+a*A+o*E+l*L,r[4]=s*w+a*C+o*I+l*k,r[8]=s*S+a*T+o*D+l*O,r[12]=s*M+a*P+o*R+l*N,r[1]=c*x+u*A+h*E+d*L,r[5]=c*w+u*C+h*I+d*k,r[9]=c*S+u*T+h*D+d*O,r[13]=c*M+u*P+h*R+d*N,r[2]=f*x+m*A+p*E+g*L,r[6]=f*w+m*C+p*I+g*k,r[10]=f*S+m*T+p*D+g*O,r[14]=f*M+m*P+p*R+g*N,r[3]=_*x+y*A+v*E+b*L,r[7]=_*w+y*C+v*I+b*k,r[11]=_*S+y*T+v*D+b*O,r[15]=_*M+y*P+v*R+b*N,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[4],n=e[8],r=e[12],s=e[1],a=e[5],o=e[9],l=e[13],c=e[2],u=e[6],h=e[10],d=e[14];return e[3]*(+r*o*u-n*l*u-r*a*h+i*l*h+n*a*d-i*o*d)+e[7]*(+t*o*d-t*l*h+r*s*h-n*s*d+n*l*c-r*o*c)+e[11]*(+t*l*u-t*a*d-r*s*u+i*s*d+r*a*c-i*l*c)+e[15]*(-n*a*c-t*o*u+t*a*h+n*s*u-i*s*h+i*o*c)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,i){const n=this.elements;return e.isVector3?(n[12]=e.x,n[13]=e.y,n[14]=e.z):(n[12]=e,n[13]=t,n[14]=i),this}invert(){const e=this.elements,t=e[0],i=e[1],n=e[2],r=e[3],s=e[4],a=e[5],o=e[6],l=e[7],c=e[8],u=e[9],h=e[10],d=e[11],f=e[12],m=e[13],p=e[14],g=e[15],_=u*p*l-m*h*l+m*o*d-a*p*d-u*o*g+a*h*g,y=f*h*l-c*p*l-f*o*d+s*p*d+c*o*g-s*h*g,v=c*m*l-f*u*l+f*a*d-s*m*d-c*a*g+s*u*g,b=f*u*o-c*m*o-f*a*h+s*m*h+c*a*p-s*u*p,x=t*_+i*y+n*v+r*b;if(0===x)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const w=1/x;return e[0]=_*w,e[1]=(m*h*r-u*p*r-m*n*d+i*p*d+u*n*g-i*h*g)*w,e[2]=(a*p*r-m*o*r+m*n*l-i*p*l-a*n*g+i*o*g)*w,e[3]=(u*o*r-a*h*r-u*n*l+i*h*l+a*n*d-i*o*d)*w,e[4]=y*w,e[5]=(c*p*r-f*h*r+f*n*d-t*p*d-c*n*g+t*h*g)*w,e[6]=(f*o*r-s*p*r-f*n*l+t*p*l+s*n*g-t*o*g)*w,e[7]=(s*h*r-c*o*r+c*n*l-t*h*l-s*n*d+t*o*d)*w,e[8]=v*w,e[9]=(f*u*r-c*m*r-f*i*d+t*m*d+c*i*g-t*u*g)*w,e[10]=(s*m*r-f*a*r+f*i*l-t*m*l-s*i*g+t*a*g)*w,e[11]=(c*a*r-s*u*r-c*i*l+t*u*l+s*i*d-t*a*d)*w,e[12]=b*w,e[13]=(c*m*n-f*u*n+f*i*h-t*m*h-c*i*p+t*u*p)*w,e[14]=(f*a*n-s*m*n-f*i*o+t*m*o+s*i*p-t*a*p)*w,e[15]=(s*u*n-c*a*n+c*i*o-t*u*o-s*i*h+t*a*h)*w,this}scale(e){const t=this.elements,i=e.x,n=e.y,r=e.z;return t[0]*=i,t[4]*=n,t[8]*=r,t[1]*=i,t[5]*=n,t[9]*=r,t[2]*=i,t[6]*=n,t[10]*=r,t[3]*=i,t[7]*=n,t[11]*=r,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],n=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,i,n))}makeTranslation(e,t,i){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,i,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),i=Math.sin(e);return this.set(1,0,0,0,0,t,-i,0,0,i,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,0,i,0,0,1,0,0,-i,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,0,i,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const i=Math.cos(t),n=Math.sin(t),r=1-i,s=e.x,a=e.y,o=e.z,l=r*s,c=r*a;return this.set(l*s+i,l*a-n*o,l*o+n*a,0,l*a+n*o,c*a+i,c*o-n*s,0,l*o-n*a,c*o+n*s,r*o*o+i,0,0,0,0,1),this}makeScale(e,t,i){return this.set(e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1),this}makeShear(e,t,i,n,r,s){return this.set(1,i,r,0,e,1,s,0,t,n,1,0,0,0,0,1),this}compose(e,t,i){const n=this.elements,r=t._x,s=t._y,a=t._z,o=t._w,l=r+r,c=s+s,u=a+a,h=r*l,d=r*c,f=r*u,m=s*c,p=s*u,g=a*u,_=o*l,y=o*c,v=o*u,b=i.x,x=i.y,w=i.z;return n[0]=(1-(m+g))*b,n[1]=(d+v)*b,n[2]=(f-y)*b,n[3]=0,n[4]=(d-v)*x,n[5]=(1-(h+g))*x,n[6]=(p+_)*x,n[7]=0,n[8]=(f+y)*w,n[9]=(p-_)*w,n[10]=(1-(h+m))*w,n[11]=0,n[12]=e.x,n[13]=e.y,n[14]=e.z,n[15]=1,this}decompose(e,t,i){const n=this.elements;let r=Xt.set(n[0],n[1],n[2]).length();const s=Xt.set(n[4],n[5],n[6]).length(),a=Xt.set(n[8],n[9],n[10]).length();this.determinant()<0&&(r=-r),e.x=n[12],e.y=n[13],e.z=n[14],Yt.copy(this);const o=1/r,l=1/s,c=1/a;return Yt.elements[0]*=o,Yt.elements[1]*=o,Yt.elements[2]*=o,Yt.elements[4]*=l,Yt.elements[5]*=l,Yt.elements[6]*=l,Yt.elements[8]*=c,Yt.elements[9]*=c,Yt.elements[10]*=c,t.setFromRotationMatrix(Yt),i.x=r,i.y=s,i.z=a,this}makePerspective(e,t,i,n,r,s,a=2e3){const o=this.elements,l=2*r/(t-e),c=2*r/(i-n),u=(t+e)/(t-e),h=(i+n)/(i-n);let d,f;if(a===Ie)d=-(s+r)/(s-r),f=-2*s*r/(s-r);else{if(a!==De)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);d=-s/(s-r),f=-s*r/(s-r)}return o[0]=l,o[4]=0,o[8]=u,o[12]=0,o[1]=0,o[5]=c,o[9]=h,o[13]=0,o[2]=0,o[6]=0,o[10]=d,o[14]=f,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(e,t,i,n,r,s,a=2e3){const o=this.elements,l=1/(t-e),c=1/(i-n),u=1/(s-r),h=(t+e)*l,d=(i+n)*c;let f,m;if(a===Ie)f=(s+r)*u,m=-2*u;else{if(a!==De)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);f=r*u,m=-1*u}return o[0]=2*l,o[4]=0,o[8]=0,o[12]=-h,o[1]=0,o[5]=2*c,o[9]=0,o[13]=-d,o[2]=0,o[6]=0,o[10]=m,o[14]=-f,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(e){const t=this.elements,i=e.elements;for(let e=0;e<16;e++)if(t[e]!==i[e])return!1;return!0}fromArray(e,t=0){for(let i=0;i<16;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e[t+9]=i[9],e[t+10]=i[10],e[t+11]=i[11],e[t+12]=i[12],e[t+13]=i[13],e[t+14]=i[14],e[t+15]=i[15],e}}const Xt=new _t,Yt=new qt,Kt=new _t(0,0,0),Zt=new _t(1,1,1),Qt=new _t,Jt=new _t,ei=new _t,ti=new qt,ii=new gt;class ni{constructor(e=0,t=0,i=0,n=ni.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=i,this._order=n}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,i,n=this._order){return this._x=e,this._y=t,this._z=i,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,i=!0){const n=e.elements,r=n[0],s=n[4],a=n[8],o=n[1],l=n[5],c=n[9],u=n[2],h=n[6],d=n[10];switch(t){case"XYZ":this._y=Math.asin(Fe(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-c,d),this._z=Math.atan2(-s,r)):(this._x=Math.atan2(h,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Fe(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,l)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(Fe(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-s,l)):(this._y=0,this._z=Math.atan2(o,r));break;case"ZYX":this._y=Math.asin(-Fe(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(h,d),this._z=Math.atan2(o,r)):(this._x=0,this._z=Math.atan2(-s,l));break;case"YZX":this._z=Math.asin(Fe(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-c,l),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-Fe(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(h,l),this._y=Math.atan2(a,r)):(this._x=Math.atan2(-c,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,!0===i&&this._onChangeCallback(),this}setFromQuaternion(e,t,i){return ti.makeRotationFromQuaternion(e),this.setFromRotationMatrix(ti,t,i)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return ii.setFromEuler(this),this.setFromQuaternion(ii,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],void 0!==e[3]&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}ni.DEFAULT_ORDER="XYZ";class ri{constructor(){this.mask=1}set(e){this.mask=1<>>0}enable(e){this.mask|=1<1){for(let e=0;e1){for(let e=0;e0&&(i=i.concat(r))}return i}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ui,e,hi),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ui,di,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let i=0,n=t.length;i0&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),n.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(n.matrixAutoUpdate=!1),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(n.instanceColor=this.instanceColor.toJSON())),this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(n.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=r(e.geometries,this.geometry);const t=this.geometry.parameters;if(void 0!==t&&void 0!==t.shapes){const i=t.shapes;if(Array.isArray(i))for(let t=0,n=i.length;t0){n.children=[];for(let t=0;t0){n.animations=[];for(let t=0;t0&&(i.geometries=t),n.length>0&&(i.materials=n),r.length>0&&(i.textures=r),a.length>0&&(i.images=a),o.length>0&&(i.shapes=o),l.length>0&&(i.skeletons=l),c.length>0&&(i.animations=c),u.length>0&&(i.nodes=u)}return i.object=n,i;function s(e){const t=[];for(const i in e){const n=e[i];delete n.metadata,t.push(n)}return t}}clone(e){return(new this.constructor).copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),!0===t)for(let t=0;t0?n.multiplyScalar(1/Math.sqrt(r)):n.set(0,0,0)}static getBarycoord(e,t,i,n,r){vi.subVectors(n,t),bi.subVectors(i,t),xi.subVectors(e,t);const s=vi.dot(vi),a=vi.dot(bi),o=vi.dot(xi),l=bi.dot(bi),c=bi.dot(xi),u=s*l-a*a;if(0===u)return r.set(-2,-1,-1);const h=1/u,d=(l*o-a*c)*h,f=(s*c-a*o)*h;return r.set(1-d-f,f,d)}static containsPoint(e,t,i,n){return this.getBarycoord(e,t,i,n,wi),wi.x>=0&&wi.y>=0&&wi.x+wi.y<=1}static getUV(e,t,i,n,r,s,a,o){return!1===Ei&&(console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."),Ei=!0),this.getInterpolation(e,t,i,n,r,s,a,o)}static getInterpolation(e,t,i,n,r,s,a,o){return this.getBarycoord(e,t,i,n,wi),o.setScalar(0),o.addScaledVector(r,wi.x),o.addScaledVector(s,wi.y),o.addScaledVector(a,wi.z),o}static isFrontFacing(e,t,i,n){return vi.subVectors(i,t),bi.subVectors(e,t),vi.cross(bi).dot(n)<0}set(e,t,i){return this.a.copy(e),this.b.copy(t),this.c.copy(i),this}setFromPointsAndIndices(e,t,i,n){return this.a.copy(e[t]),this.b.copy(e[i]),this.c.copy(e[n]),this}setFromAttributeAndIndices(e,t,i,n){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,i),this.c.fromBufferAttribute(e,n),this}clone(){return(new this.constructor).copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return vi.subVectors(this.c,this.b),bi.subVectors(this.a,this.b),.5*vi.cross(bi).length()}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return Ii.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return Ii.getBarycoord(e,this.a,this.b,this.c,t)}getUV(e,t,i,n,r){return!1===Ei&&(console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."),Ei=!0),Ii.getInterpolation(e,this.a,this.b,this.c,t,i,n,r)}getInterpolation(e,t,i,n,r){return Ii.getInterpolation(e,this.a,this.b,this.c,t,i,n,r)}containsPoint(e){return Ii.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return Ii.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const i=this.a,n=this.b,r=this.c;let s,a;Si.subVectors(n,i),Mi.subVectors(r,i),Ci.subVectors(e,i);const o=Si.dot(Ci),l=Mi.dot(Ci);if(o<=0&&l<=0)return t.copy(i);Ti.subVectors(e,n);const c=Si.dot(Ti),u=Mi.dot(Ti);if(c>=0&&u<=c)return t.copy(n);const h=o*u-c*l;if(h<=0&&o>=0&&c<=0)return s=o/(o-c),t.copy(i).addScaledVector(Si,s);Pi.subVectors(e,r);const d=Si.dot(Pi),f=Mi.dot(Pi);if(f>=0&&d<=f)return t.copy(r);const m=d*l-o*f;if(m<=0&&l>=0&&f<=0)return a=l/(l-f),t.copy(i).addScaledVector(Mi,a);const p=c*f-d*u;if(p<=0&&u-c>=0&&d-f>=0)return Ai.subVectors(r,n),a=(u-c)/(u-c+(d-f)),t.copy(n).addScaledVector(Ai,a);const g=1/(p+m+h);return s=m*g,a=h*g,t.copy(i).addScaledVector(Si,s).addScaledVector(Mi,a)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}const Di={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},Ri={h:0,s:0,l:0},Li={h:0,s:0,l:0};function ki(e,t,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?e+6*(t-e)*i:i<.5?t:i<2/3?e+6*(t-e)*(2/3-i):e}class Oi{constructor(e,t,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,i)}set(e,t,i){if(void 0===t&&void 0===i){const t=e;t&&t.isColor?this.copy(t):"number"==typeof t?this.setHex(t):"string"==typeof t&&this.setStyle(t)}else this.setRGB(e,t,i);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=ce){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(255&e)/255,tt.toWorkingColorSpace(this,t),this}setRGB(e,t,i,n=tt.workingColorSpace){return this.r=e,this.g=t,this.b=i,tt.toWorkingColorSpace(this,n),this}setHSL(e,t,i,n=tt.workingColorSpace){var r;if(e=(e%(r=1)+r)%r,t=Fe(t,0,1),i=Fe(i,0,1),0===t)this.r=this.g=this.b=i;else{const n=i<=.5?i*(1+t):i+t-i*t,r=2*i-n;this.r=ki(r,n,e+1/3),this.g=ki(r,n,e),this.b=ki(r,n,e-1/3)}return tt.toWorkingColorSpace(this,n),this}setStyle(e,t=ce){function i(t){void 0!==t&&parseFloat(t)<1&&console.warn("THREE.Color: Alpha component of "+e+" will be ignored.")}let n;if(n=/^(\w+)\(([^\)]*)\)/.exec(e)){let r;const s=n[1],a=n[2];switch(s){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,t);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,t);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,t);break;default:console.warn("THREE.Color: Unknown color model "+e)}}else if(n=/^\#([A-Fa-f\d]+)$/.exec(e)){const i=n[1],r=i.length;if(3===r)return this.setRGB(parseInt(i.charAt(0),16)/15,parseInt(i.charAt(1),16)/15,parseInt(i.charAt(2),16)/15,t);if(6===r)return this.setHex(parseInt(i,16),t);console.warn("THREE.Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=ce){const i=Di[e.toLowerCase()];return void 0!==i?this.setHex(i,t):console.warn("THREE.Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=it(e.r),this.g=it(e.g),this.b=it(e.b),this}copyLinearToSRGB(e){return this.r=nt(e.r),this.g=nt(e.g),this.b=nt(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=ce){return tt.fromWorkingColorSpace(Ni.copy(this),e),65536*Math.round(Fe(255*Ni.r,0,255))+256*Math.round(Fe(255*Ni.g,0,255))+Math.round(Fe(255*Ni.b,0,255))}getHexString(e=ce){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=tt.workingColorSpace){tt.fromWorkingColorSpace(Ni.copy(this),t);const i=Ni.r,n=Ni.g,r=Ni.b,s=Math.max(i,n,r),a=Math.min(i,n,r);let o,l;const c=(a+s)/2;if(a===s)o=0,l=0;else{const e=s-a;switch(l=c<=.5?e/(s+a):e/(2-s-a),s){case i:o=(n-r)/e+(n0!=e>0&&this.version++,this._alphaTest=e}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(void 0!==e)for(const t in e){const i=e[t];if(void 0===i){console.warn(`THREE.Material: parameter '${t}' has value of undefined.`);continue}const n=this[t];void 0!==n?n&&n.isColor?n.set(i):n&&n.isVector3&&i&&i.isVector3?n.copy(i):this[t]=i:console.warn(`THREE.Material: '${t}' is not a property of THREE.${this.type}.`)}}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{}});const i={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function n(e){const t=[];for(const i in e){const n=e[i];delete n.metadata,t.push(n)}return t}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),void 0!==this.roughness&&(i.roughness=this.roughness),void 0!==this.metalness&&(i.metalness=this.metalness),void 0!==this.sheen&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity&&1!==this.emissiveIntensity&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(i.shininess=this.shininess),void 0!==this.clearcoat&&(i.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.iridescence&&(i.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(i.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),void 0!==this.anisotropy&&(i.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(e).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(e).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(e).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(e).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(e).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(e).uuid,void 0!==this.combine&&(i.combine=this.combine)),void 0!==this.envMapIntensity&&(i.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(i.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(e).uuid),void 0!==this.transmission&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(e).uuid),void 0!==this.thickness&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(e).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(i.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(i.size=this.size),null!==this.shadowSide&&(i.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(i.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(i.blending=this.blending),this.side!==r&&(i.side=this.side),!0===this.vertexColors&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),!0===this.transparent&&(i.transparent=!0),204!==this.blendSrc&&(i.blendSrc=this.blendSrc),205!==this.blendDst&&(i.blendDst=this.blendDst),this.blendEquation!==o&&(i.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(i.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(i.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(i.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(i.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(i.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(i.depthFunc=this.depthFunc),!1===this.depthTest&&(i.depthTest=this.depthTest),!1===this.depthWrite&&(i.depthWrite=this.depthWrite),!1===this.colorWrite&&(i.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(i.stencilWriteMask=this.stencilWriteMask),519!==this.stencilFunc&&(i.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(i.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==_e&&(i.stencilFail=this.stencilFail),this.stencilZFail!==_e&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==_e&&(i.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(i.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(i.rotation=this.rotation),!0===this.polygonOffset&&(i.polygonOffset=!0),0!==this.polygonOffsetFactor&&(i.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(i.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(i.linewidth=this.linewidth),void 0!==this.dashSize&&(i.dashSize=this.dashSize),void 0!==this.gapSize&&(i.gapSize=this.gapSize),void 0!==this.scale&&(i.scale=this.scale),!0===this.dithering&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),!0===this.alphaHash&&(i.alphaHash=!0),!0===this.alphaToCoverage&&(i.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(i.premultipliedAlpha=!0),!0===this.forceSinglePass&&(i.forceSinglePass=!0),!0===this.wireframe&&(i.wireframe=!0),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(i.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(i.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(i.flatShading=!0),!1===this.visible&&(i.visible=!1),!1===this.toneMapped&&(i.toneMapped=!1),!1===this.fog&&(i.fog=!1),Object.keys(this.userData).length>0&&(i.userData=this.userData),t){const t=n(e.textures),r=n(e.images);t.length>0&&(i.textures=t),r.length>0&&(i.images=r)}return i}clone(){return(new this.constructor).copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let i=null;if(null!==t){const e=t.length;i=new Array(e);for(let n=0;n!==e;++n)i[n]=t[n].clone()}return this.clippingPlanes=i,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}}class zi extends Bi{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Oi(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=A,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const Ui=new _t,Vi=new Ge;class $i{constructor(e,t,i=!1){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=e,this.itemSize=t,this.count=void 0!==e?e.length/t:0,this.normalized=i,this.usage=Ce,this.updateRange={offset:0,count:-1},this.gpuType=K,this.version=0}onUploadCallback(){}set needsUpdate(e){!0===e&&this.version++}setUsage(e){return this.usage=e,this}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,i){e*=this.itemSize,i*=t.itemSize;for(let n=0,r=this.itemSize;n0&&(e.userData=this.userData),void 0!==this.parameters){const t=this.parameters;for(const i in t)void 0!==t[i]&&(e[i]=t[i]);return e}e.data={attributes:{}};const t=this.index;null!==t&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const i=this.attributes;for(const t in i){const n=i[t];e.data.attributes[t]=n.toJSON(e.data)}const n={};let r=!1;for(const t in this.morphAttributes){const i=this.morphAttributes[t],s=[];for(let t=0,n=i.length;t0&&(n[t]=s,r=!0)}r&&(e.data.morphAttributes=n,e.data.morphTargetsRelative=this.morphTargetsRelative);const s=this.groups;s.length>0&&(e.data.groups=JSON.parse(JSON.stringify(s)));const a=this.boundingSphere;return null!==a&&(e.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),e}clone(){return(new this.constructor).copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const i=e.index;null!==i&&this.setIndex(i.clone(t));const n=e.attributes;for(const e in n){const i=n[e];this.setAttribute(e,i.clone(t))}const r=e.morphAttributes;for(const e in r){const i=[],n=r[e];for(let e=0,r=n.length;e0){const i=e[t[0]];if(void 0!==i){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=i.length;e(e.far-e.near)**2)return}en.copy(r).invert(),tn.copy(e.ray).applyMatrix4(en),null!==i.boundingBox&&!1===tn.intersectsBox(i.boundingBox)||this._computeIntersections(e,t,tn)}}_computeIntersections(e,t,i){let n;const r=this.geometry,s=this.material,a=r.index,o=r.attributes.position,l=r.attributes.uv,c=r.attributes.uv1,u=r.attributes.normal,h=r.groups,d=r.drawRange;if(null!==a)if(Array.isArray(s))for(let r=0,o=h.length;ri.far?null:{distance:h,point:_n.clone(),object:e}}(e,t,i,n,sn,an,on,gn);if(d){a&&(un.fromBufferAttribute(a,c),hn.fromBufferAttribute(a,u),dn.fromBufferAttribute(a,h),d.uv=Ii.getInterpolation(gn,sn,an,on,un,hn,dn,new Ge)),o&&(un.fromBufferAttribute(o,c),hn.fromBufferAttribute(o,u),dn.fromBufferAttribute(o,h),d.uv1=Ii.getInterpolation(gn,sn,an,on,un,hn,dn,new Ge),d.uv2=d.uv1),l&&(fn.fromBufferAttribute(l,c),mn.fromBufferAttribute(l,u),pn.fromBufferAttribute(l,h),d.normal=Ii.getInterpolation(gn,sn,an,on,fn,mn,pn,new _t),d.normal.dot(n.direction)>0&&d.normal.multiplyScalar(-1));const e={a:c,b:u,c:h,normal:new _t,materialIndex:0};Ii.getNormal(sn,an,on,e.normal),d.face=e}return d}class bn extends Ji{constructor(e=1,t=1,i=1,n=1,r=1,s=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:i,widthSegments:n,heightSegments:r,depthSegments:s};const a=this;n=Math.floor(n),r=Math.floor(r),s=Math.floor(s);const o=[],l=[],c=[],u=[];let h=0,d=0;function f(e,t,i,n,r,s,f,m,p,g,_){const y=s/p,v=f/g,b=s/2,x=f/2,w=m/2,S=p+1,M=g+1;let A=0,C=0;const T=new _t;for(let s=0;s0?1:-1,c.push(T.x,T.y,T.z),u.push(o/p),u.push(1-s/g),A+=1}}for(let e=0;e0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;const i={};for(const e in this.extensions)!0===this.extensions[e]&&(i[e]=!0);return Object.keys(i).length>0&&(t.extensions=i),t}}class Cn extends yi{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new qt,this.projectionMatrix=new qt,this.projectionMatrixInverse=new qt,this.coordinateSystem=Ie}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return(new this.constructor).copy(this)}}class Tn extends Cn{constructor(e=50,t=1,i=.1,n=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=i,this.far=n,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=null===e.view?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){const t=.5*this.getFilmHeight()/e;this.fov=2*Oe*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){const e=Math.tan(.5*ke*this.fov);return.5*this.getFilmHeight()/e}getEffectiveFOV(){return 2*Oe*Math.atan(Math.tan(.5*ke*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}setViewOffset(e,t,i,n,r,s){this.aspect=e/t,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=i,this.view.offsetY=n,this.view.width=r,this.view.height=s,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=this.near;let t=e*Math.tan(.5*ke*this.fov)/this.zoom,i=2*t,n=this.aspect*i,r=-.5*n;const s=this.view;if(null!==this.view&&this.view.enabled){const e=s.fullWidth,a=s.fullHeight;r+=s.offsetX*n/e,t-=s.offsetY*i/a,n*=s.width/e,i*=s.height/a}const a=this.filmOffset;0!==a&&(r+=e*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+n,t,t-i,e,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,null!==this.view&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}}const Pn=-90;class En extends yi{constructor(e,t,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const n=new Tn(Pn,1,e,t);n.layers=this.layers,this.add(n);const r=new Tn(Pn,1,e,t);r.layers=this.layers,this.add(r);const s=new Tn(Pn,1,e,t);s.layers=this.layers,this.add(s);const a=new Tn(Pn,1,e,t);a.layers=this.layers,this.add(a);const o=new Tn(Pn,1,e,t);o.layers=this.layers,this.add(o);const l=new Tn(Pn,1,e,t);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const e=this.coordinateSystem,t=this.children.concat(),[i,n,r,s,a,o]=t;for(const e of t)this.remove(e);if(e===Ie)i.up.set(0,1,0),i.lookAt(1,0,0),n.up.set(0,1,0),n.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),s.up.set(0,0,1),s.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),o.up.set(0,1,0),o.lookAt(0,0,-1);else{if(e!==De)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);i.up.set(0,-1,0),i.lookAt(-1,0,0),n.up.set(0,-1,0),n.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),s.up.set(0,0,-1),s.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),o.up.set(0,-1,0),o.lookAt(0,0,-1)}for(const e of t)this.add(e),e.updateMatrixWorld()}update(e,t){null===this.parent&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:n}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());const[r,s,a,o,l,c]=this.children,u=e.getRenderTarget(),h=e.getActiveCubeFace(),d=e.getActiveMipmapLevel(),f=e.xr.enabled;e.xr.enabled=!1;const m=i.texture.generateMipmaps;i.texture.generateMipmaps=!1,e.setRenderTarget(i,0,n),e.render(t,r),e.setRenderTarget(i,1,n),e.render(t,s),e.setRenderTarget(i,2,n),e.render(t,a),e.setRenderTarget(i,3,n),e.render(t,o),e.setRenderTarget(i,4,n),e.render(t,l),i.texture.generateMipmaps=m,e.setRenderTarget(i,5,n),e.render(t,c),e.setRenderTarget(u,h,d),e.xr.enabled=f,i.texture.needsPMREMUpdate=!0}}class In extends ut{constructor(e,t,i,n,r,s,a,o,l,c){super(e=void 0!==e?e:[],t=void 0!==t?t:k,i,n,r,s,a,o,l,c),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class Dn extends ft{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;const i={width:e,height:e,depth:1},n=[i,i,i,i,i,i];void 0!==t.encoding&&(Ke("THREE.WebGLCubeRenderTarget: option.encoding has been replaced by option.colorSpace."),t.colorSpace=t.encoding===oe?ce:le),this.texture=new In(n,t.mapping,t.wrapS,t.wrapT,t.magFilter,t.minFilter,t.format,t.type,t.anisotropy,t.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==t.generateMipmaps&&t.generateMipmaps,this.texture.minFilter=void 0!==t.minFilter?t.minFilter:G}fromEquirectangularTexture(e,t){this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const i={uniforms:{tEquirect:{value:null}},vertexShader:"varying vec3 vWorldDirection;vec3 transformDirection(in vec3 dir,in mat4 matrix){return normalize((matrix*vec4(dir,0.0)).xyz);}void main(){vWorldDirection=transformDirection(position,modelMatrix);\n#include \n#include \n}",fragmentShader:"uniform sampler2D tEquirect;varying vec3 vWorldDirection;\n#include \nvoid main(){vec3 direction=normalize(vWorldDirection);vec2 sampleUV=equirectUv(direction);gl_FragColor=texture2D(tEquirect,sampleUV);}"},n=new bn(5,5,5),r=new An({name:"CubemapFromEquirect",uniforms:xn(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:s,blending:0});r.uniforms.tEquirect.value=t;const a=new yn(n,r),o=t.minFilter;t.minFilter===j&&(t.minFilter=G);return new En(1,10,this).update(e,a),t.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(e,t,i,n){const r=e.getRenderTarget();for(let r=0;r<6;r++)e.setRenderTarget(this,r),e.clear(t,i,n);e.setRenderTarget(r)}}const Rn=new _t,Ln=new _t,kn=new He;class On{constructor(e=new _t(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,i,n){return this.normal.set(e,t,i),this.constant=n,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,i){const n=Rn.subVectors(i,t).cross(Ln.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(n,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t){const i=e.delta(Rn),n=this.normal.dot(i);if(0===n)return 0===this.distanceToPoint(e.start)?t.copy(e.start):null;const r=-(e.start.dot(this.normal)+this.constant)/n;return r<0||r>1?null:t.copy(e.start).addScaledVector(i,r)}intersectsLine(e){const t=this.distanceToPoint(e.start),i=this.distanceToPoint(e.end);return t<0&&i>0||i<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const i=t||kn.getNormalMatrix(e),n=this.coplanarPoint(Rn).applyMatrix4(e),r=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(r),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const Nn=new Bt,Fn=new _t;class Bn{constructor(e=new On,t=new On,i=new On,n=new On,r=new On,s=new On){this.planes=[e,t,i,n,r,s]}set(e,t,i,n,r,s){const a=this.planes;return a[0].copy(e),a[1].copy(t),a[2].copy(i),a[3].copy(n),a[4].copy(r),a[5].copy(s),this}copy(e){const t=this.planes;for(let i=0;i<6;i++)t[i].copy(e.planes[i]);return this}setFromProjectionMatrix(e,t=2e3){const i=this.planes,n=e.elements,r=n[0],s=n[1],a=n[2],o=n[3],l=n[4],c=n[5],u=n[6],h=n[7],d=n[8],f=n[9],m=n[10],p=n[11],g=n[12],_=n[13],y=n[14],v=n[15];if(i[0].setComponents(o-r,h-l,p-d,v-g).normalize(),i[1].setComponents(o+r,h+l,p+d,v+g).normalize(),i[2].setComponents(o+s,h+c,p+f,v+_).normalize(),i[3].setComponents(o-s,h-c,p-f,v-_).normalize(),i[4].setComponents(o-a,h-u,p-m,v-y).normalize(),t===Ie)i[5].setComponents(o+a,h+u,p+m,v+y).normalize();else{if(t!==De)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);i[5].setComponents(a,u,m,y).normalize()}return this}intersectsObject(e){if(void 0!==e.boundingSphere)null===e.boundingSphere&&e.computeBoundingSphere(),Nn.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;null===t.boundingSphere&&t.computeBoundingSphere(),Nn.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(Nn)}intersectsSprite(e){return Nn.center.set(0,0,0),Nn.radius=.7071067811865476,Nn.applyMatrix4(e.matrixWorld),this.intersectsSphere(Nn)}intersectsSphere(e){const t=this.planes,i=e.center,n=-e.radius;for(let e=0;e<6;e++){if(t[e].distanceToPoint(i)0?e.max.x:e.min.x,Fn.y=n.normal.y>0?e.max.y:e.min.y,Fn.z=n.normal.z>0?e.max.z:e.min.z,n.distanceToPoint(Fn)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let i=0;i<6;i++)if(t[i].distanceToPoint(e)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function zn(){let e=null,t=!1,i=null,n=null;function r(t,s){i(t,s),n=e.requestAnimationFrame(r)}return{start:function(){!0!==t&&null!==i&&(n=e.requestAnimationFrame(r),t=!0)},stop:function(){e.cancelAnimationFrame(n),t=!1},setAnimationLoop:function(e){i=e},setContext:function(t){e=t}}}function Un(e,t){const i=t.isWebGL2,n=new WeakMap;return{get:function(e){return e.isInterleavedBufferAttribute&&(e=e.data),n.get(e)},remove:function(t){t.isInterleavedBufferAttribute&&(t=t.data);const i=n.get(t);i&&(e.deleteBuffer(i.buffer),n.delete(t))},update:function(t,r){if(t.isGLBufferAttribute){const e=n.get(t);return void((!e||e.version0\nvec4 plane;\n#pragma unroll_loop_start\nfor(int i=0;iplane.w)discard;}\n#pragma unroll_loop_end\n#if UNION_CLIPPING_PLANESplane.w)&&clipped;}\n#pragma unroll_loop_end\nif(clipped)discard;\n#endif\n#endif",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES>0\nvarying vec3 vClipPosition;uniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES>0\nvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES>0\nvClipPosition=-mvPosition.xyz;\n#endif",color_fragment:"#if defined(USE_COLOR_ALPHA)\ndiffuseColor*=vColor;\n#elif defined(USE_COLOR)\ndiffuseColor.rgb*=vColor;\n#endif",color_pars_fragment:"#if defined(USE_COLOR_ALPHA)\nvarying vec4 vColor;\n#elif defined(USE_COLOR)\nvarying vec3 vColor;\n#endif",color_pars_vertex:"#if defined(USE_COLOR_ALPHA)\nvarying vec4 vColor;\n#elif defined(USE_COLOR)||defined(USE_INSTANCING_COLOR)\nvarying vec3 vColor;\n#endif",color_vertex:"#if defined(USE_COLOR_ALPHA)\nvColor=vec4(1.0);\n#elif defined(USE_COLOR)||defined(USE_INSTANCING_COLOR)\nvColor=vec3(1.0);\n#endif\n#ifdef USE_COLOR\nvColor*=color;\n#endif\n#ifdef USE_INSTANCING_COLOR\nvColor.xyz*=instanceColor.xyz;\n#endif",common:"#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate(a)clamp(a,0.0,1.0)\n#endif\n#define whiteComplement(a)(1.0-saturate(a))\nfloat pow2(const in float x){return x*x;}vec3 pow2(const in vec3 x){return x*x;}float pow3(const in float x){return x*x*x;}float pow4(const in float x){float x2=x*x;return x2*x2;}float max3(const in vec3 v){return max(max(v.x,v.y),v.z);}float average(const in vec3 v){return dot(v,vec3(0.3333333));}highp float rand(const in vec2 uv){const highp float a=12.9898,b=78.233,c=43758.5453;highp float dt=dot(uv.xy,vec2(a,b)),sn=mod(dt,PI);return fract(sin(sn)*c);}\n#ifdef HIGH_PRECISION\nfloat precisionSafeLength(vec3 v){return length(v);}\n#else\nfloat precisionSafeLength(vec3 v){float maxComponent=max3(abs(v));return length(v/maxComponent)*maxComponent;}\n#endif\nstruct IncidentLight{vec3 color;vec3 direction;bool visible;};struct ReflectedLight{vec3 directDiffuse;vec3 directSpecular;vec3 indirectDiffuse;vec3 indirectSpecular;};\n#ifdef USE_ALPHAHASH\nvarying vec3 vPosition;\n#endif\nvec3 transformDirection(in vec3 dir,in mat4 matrix){return normalize((matrix*vec4(dir,0.0)).xyz);}vec3 inverseTransformDirection(in vec3 dir,in mat4 matrix){return normalize((vec4(dir,0.0)*matrix).xyz);}mat3 transposeMat3(const in mat3 m){mat3 tmp;tmp[0]=vec3(m[0].x,m[1].x,m[2].x);tmp[1]=vec3(m[0].y,m[1].y,m[2].y);tmp[2]=vec3(m[0].z,m[1].z,m[2].z);return tmp;}float luminance(const in vec3 rgb){const vec3 weights=vec3(0.2126729,0.7151522,0.0721750);return dot(weights,rgb);}bool isPerspectiveMatrix(mat4 m){return m[2][3]==-1.0;}vec2 equirectUv(in vec3 dir){float u=atan(dir.z,dir.x)*RECIPROCAL_PI2+0.5;float v=asin(clamp(dir.y,-1.0,1.0))*RECIPROCAL_PI+0.5;return vec2(u,v);}vec3 BRDF_Lambert(const in vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}vec3 F_Schlick(const in vec3 f0,const in float f90,const in float dotVH){float fresnel=exp2((-5.55473*dotVH-6.98316)*dotVH);return f0*(1.0-fresnel)+(f90*fresnel);}float F_Schlick(const in float f0,const in float f90,const in float dotVH){float fresnel=exp2((-5.55473*dotVH-6.98316)*dotVH);return f0*(1.0-fresnel)+(f90*fresnel);}",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_minMipLevel 4.0\n#define cubeUV_minTileSize 16.0\nfloat getFace(vec3 direction){vec3 absDirection=abs(direction);float face=-1.0;if(absDirection.x>absDirection.z){if(absDirection.x>absDirection.y)face=direction.x>0.0?0.0:3.0;else face=direction.y>0.0?1.0:4.0;}else{if(absDirection.z>absDirection.y)face=direction.z>0.0?2.0:5.0;else face=direction.y>0.0?1.0:4.0;}return face;}vec2 getUV(vec3 direction,float face){vec2 uv;if(face==0.0){uv=vec2(direction.z,direction.y)/abs(direction.x);}else if(face==1.0){uv=vec2(-direction.x,-direction.z)/abs(direction.y);}else if(face==2.0){uv=vec2(-direction.x,direction.y)/abs(direction.z);}else if(face==3.0){uv=vec2(-direction.z,direction.y)/abs(direction.x);}else if(face==4.0){uv=vec2(-direction.x,direction.z)/abs(direction.y);}else{uv=vec2(direction.x,direction.y)/abs(direction.z);}return 0.5*(uv+1.0);}vec3 bilinearCubeUV(sampler2D envMap,vec3 direction,float mipInt){float face=getFace(direction);float filterInt=max(cubeUV_minMipLevel-mipInt,0.0);mipInt=max(mipInt,cubeUV_minMipLevel);float faceSize=exp2(mipInt);highp vec2 uv=getUV(direction,face)*(faceSize-2.0)+1.0;if(face>2.0){uv.y+=faceSize;face-=3.0;}uv.x+=face*faceSize;uv.x+=filterInt*3.0*cubeUV_minTileSize;uv.y+=4.0*(exp2(CUBEUV_MAX_MIP)-faceSize);uv.x*=CUBEUV_TEXEL_WIDTH;uv.y*=CUBEUV_TEXEL_HEIGHT;\n#ifdef texture2DGradEXT\nreturn texture2DGradEXT(envMap,uv,vec2(0.0),vec2(0.0)).rgb;\n#else\nreturn texture2D(envMap,uv).rgb;\n#endif\n}\n#define cubeUV_r0 1.0\n#define cubeUV_v0 0.339\n#define cubeUV_m0-2.0\n#define cubeUV_r1 0.8\n#define cubeUV_v1 0.276\n#define cubeUV_m1-1.0\n#define cubeUV_r4 0.4\n#define cubeUV_v4 0.046\n#define cubeUV_m4 2.0\n#define cubeUV_r5 0.305\n#define cubeUV_v5 0.016\n#define cubeUV_m5 3.0\n#define cubeUV_r6 0.21\n#define cubeUV_v6 0.0038\n#define cubeUV_m6 4.0\nfloat roughnessToMip(float roughness){float mip=0.0;if(roughness>=cubeUV_r1){mip=(cubeUV_r0-roughness)*(cubeUV_m1-cubeUV_m0)/(cubeUV_r0-cubeUV_r1)+cubeUV_m0;}else if(roughness>=cubeUV_r4){mip=(cubeUV_r1-roughness)*(cubeUV_m4-cubeUV_m1)/(cubeUV_r1-cubeUV_r4)+cubeUV_m1;}else if(roughness>=cubeUV_r5){mip=(cubeUV_r4-roughness)*(cubeUV_m5-cubeUV_m4)/(cubeUV_r4-cubeUV_r5)+cubeUV_m4;}else if(roughness>=cubeUV_r6){mip=(cubeUV_r5-roughness)*(cubeUV_m6-cubeUV_m5)/(cubeUV_r5-cubeUV_r6)+cubeUV_m5;}else{mip=-2.0*log2(1.16*roughness);}return mip;}vec4 textureCubeUV(sampler2D envMap,vec3 sampleDir,float roughness){float mip=clamp(roughnessToMip(roughness),cubeUV_m0,CUBEUV_MAX_MIP);float mipF=fract(mip);float mipInt=floor(mip);vec3 color0=bilinearCubeUV(envMap,sampleDir,mipInt);if(mipF==0.0){return vec4(color0,1.0);}else{vec3 color1=bilinearCubeUV(envMap,sampleDir,mipInt+1.0);return vec4(mix(color0,color1,mipF),1.0);}}\n#endif",defaultnormal_vertex:"vec3 transformedNormal=objectNormal;\n#ifdef USE_INSTANCING\nmat3 m=mat3(instanceMatrix);transformedNormal/=vec3(dot(m[0],m[0]),dot(m[1],m[1]),dot(m[2],m[2]));transformedNormal=m*transformedNormal;\n#endif\ntransformedNormal=normalMatrix*transformedNormal;\n#ifdef FLIP_SIDED\ntransformedNormal=-transformedNormal;\n#endif\n#ifdef USE_TANGENT\nvec3 transformedTangent=(modelViewMatrix*vec4(objectTangent,0.0)).xyz;\n#ifdef FLIP_SIDED\ntransformedTangent=-transformedTangent;\n#endif\n#endif",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\nuniform sampler2D displacementMap;uniform float displacementScale;uniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\ntransformed+=normalize(objectNormal)*(texture2D(displacementMap,vDisplacementMapUv).x*displacementScale+displacementBias);\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\nvec4 emissiveColor=texture2D(emissiveMap,vEmissiveMapUv);totalEmissiveRadiance*=emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\nuniform sampler2D emissiveMap;\n#endif",colorspace_fragment:"gl_FragColor=linearToOutputTexel(gl_FragColor);",colorspace_pars_fragment:"const mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3=mat3(vec3(0.8224621,0.177538,0.0),vec3(0.0331941,0.9668058,0.0),vec3(0.0170827,0.0723974,0.9105199));const mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB=mat3(vec3(1.2249401,-0.2249404,0.0),vec3(-0.0420569,1.0420571,0.0),vec3(-0.0196376,-0.0786361,1.0982735));vec4 LinearSRGBToLinearDisplayP3(in vec4 value){return vec4(value.rgb*LINEAR_SRGB_TO_LINEAR_DISPLAY_P3,value.a);}vec4 LinearDisplayP3ToLinearSRGB(in vec4 value){return vec4(value.rgb*LINEAR_DISPLAY_P3_TO_LINEAR_SRGB,value.a);}vec4 LinearTransferOETF(in vec4 value){return value;}vec4 sRGBTransferOETF(in vec4 value){return vec4(mix(pow(value.rgb,vec3(0.41666))*1.055-vec3(0.055),value.rgb*12.92,vec3(lessThanEqual(value.rgb,vec3(0.0031308)))),value.a);}vec4 LinearToLinear(in vec4 value){return value;}vec4 LinearTosRGB(in vec4 value){return sRGBTransferOETF(value);}",envmap_fragment:"#ifdef USE_ENVMAP\n#ifdef ENV_WORLDPOS\nvec3 cameraToFrag;if(isOrthographic){cameraToFrag=normalize(vec3(-viewMatrix[0][2],-viewMatrix[1][2],-viewMatrix[2][2]));}else{cameraToFrag=normalize(vWorldPosition-cameraPosition);}vec3 worldNormal=inverseTransformDirection(normal,viewMatrix);\n#ifdef ENVMAP_MODE_REFLECTION\nvec3 reflectVec=reflect(cameraToFrag,worldNormal);\n#else\nvec3 reflectVec=refract(cameraToFrag,worldNormal,refractionRatio);\n#endif\n#else\nvec3 reflectVec=vReflect;\n#endif\n#ifdef ENVMAP_TYPE_CUBE\nvec4 envColor=textureCube(envMap,vec3(flipEnvMap*reflectVec.x,reflectVec.yz));\n#else\nvec4 envColor=vec4(0.0);\n#endif\n#ifdef ENVMAP_BLENDING_MULTIPLY\noutgoingLight=mix(outgoingLight,outgoingLight*envColor.xyz,specularStrength*reflectivity);\n#elif defined(ENVMAP_BLENDING_MIX)\noutgoingLight=mix(outgoingLight,envColor.xyz,specularStrength*reflectivity);\n#elif defined(ENVMAP_BLENDING_ADD)\noutgoingLight+=envColor.xyz*specularStrength*reflectivity;\n#endif\n#endif",envmap_common_pars_fragment:"#ifdef USE_ENVMAP\nuniform float envMapIntensity;uniform float flipEnvMap;\n#ifdef ENVMAP_TYPE_CUBE\nuniform samplerCube envMap;\n#else\nuniform sampler2D envMap;\n#endif\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\nuniform float reflectivity;\n#if defined(USE_BUMPMAP)||defined(USE_NORMALMAP)||defined(PHONG)||defined(LAMBERT)\n#define ENV_WORLDPOS\n#endif\n#ifdef ENV_WORLDPOS\nvarying vec3 vWorldPosition;uniform float refractionRatio;\n#else\nvarying vec3 vReflect;\n#endif\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\n#if defined(USE_BUMPMAP)||defined(USE_NORMALMAP)||defined(PHONG)||defined(LAMBERT)\n#define ENV_WORLDPOS\n#endif\n#ifdef ENV_WORLDPOS\nvarying vec3 vWorldPosition;\n#else\nvarying vec3 vReflect;uniform float refractionRatio;\n#endif\n#endif",envmap_physical_pars_fragment:"#ifdef USE_ENVMAP\nvec3 getIBLIrradiance(const in vec3 normal){\n#ifdef ENVMAP_TYPE_CUBE_UV\nvec3 worldNormal=inverseTransformDirection(normal,viewMatrix);vec4 envMapColor=textureCubeUV(envMap,worldNormal,1.0);return PI*envMapColor.rgb*envMapIntensity;\n#else\nreturn vec3(0.0);\n#endif\n}vec3 getIBLRadiance(const in vec3 viewDir,const in vec3 normal,const in float roughness){\n#ifdef ENVMAP_TYPE_CUBE_UV\nvec3 reflectVec=reflect(-viewDir,normal);reflectVec=normalize(mix(reflectVec,normal,roughness*roughness));reflectVec=inverseTransformDirection(reflectVec,viewMatrix);vec4 envMapColor=textureCubeUV(envMap,reflectVec,roughness);return envMapColor.rgb*envMapIntensity;\n#else\nreturn vec3(0.0);\n#endif\n}\n#ifdef USE_ANISOTROPY\nvec3 getIBLAnisotropyRadiance(const in vec3 viewDir,const in vec3 normal,const in float roughness,const in vec3 bitangent,const in float anisotropy){\n#ifdef ENVMAP_TYPE_CUBE_UV\nvec3 bentNormal=cross(bitangent,viewDir);bentNormal=normalize(cross(bentNormal,bitangent));bentNormal=normalize(mix(bentNormal,normal,pow2(pow2(1.0-anisotropy*(1.0-roughness)))));return getIBLRadiance(viewDir,bentNormal,roughness);\n#else\nreturn vec3(0.0);\n#endif\n}\n#endif\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\n#ifdef ENV_WORLDPOS\nvWorldPosition=worldPosition.xyz;\n#else\nvec3 cameraToVertex;if(isOrthographic){cameraToVertex=normalize(vec3(-viewMatrix[0][2],-viewMatrix[1][2],-viewMatrix[2][2]));}else{cameraToVertex=normalize(worldPosition.xyz-cameraPosition);}vec3 worldNormal=inverseTransformDirection(transformedNormal,viewMatrix);\n#ifdef ENVMAP_MODE_REFLECTION\nvReflect=reflect(cameraToVertex,worldNormal);\n#else\nvReflect=refract(cameraToVertex,worldNormal,refractionRatio);\n#endif\n#endif\n#endif",fog_vertex:"#ifdef USE_FOG\nvFogDepth=-mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\nvarying float vFogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n#ifdef FOG_EXP2\nfloat fogFactor=1.0-exp(-fogDensity*fogDensity*vFogDepth*vFogDepth);\n#else\nfloat fogFactor=smoothstep(fogNear,fogFar,vFogDepth);\n#endif\ngl_FragColor.rgb=mix(gl_FragColor.rgb,fogColor,fogFactor);\n#endif",fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;varying float vFogDepth;\n#ifdef FOG_EXP2\nuniform float fogDensity;\n#else\nuniform float fogNear;uniform float fogFar;\n#endif\n#endif",gradientmap_pars_fragment:"#ifdef USE_GRADIENTMAP\nuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance(vec3 normal,vec3 lightDirection){float dotNL=dot(normal,lightDirection);vec2 coord=vec2(dotNL*0.5+0.5,0.0);\n#ifdef USE_GRADIENTMAP\nreturn vec3(texture2D(gradientMap,coord).r);\n#else\nvec2 fw=fwidth(coord)*0.5;return mix(vec3(0.7),vec3(1.0),smoothstep(0.7-fw.x,0.7+fw.x,coord.x));\n#endif\n}",lightmap_fragment:"#ifdef USE_LIGHTMAP\nvec4 lightMapTexel=texture2D(lightMap,vLightMapUv);vec3 lightMapIrradiance=lightMapTexel.rgb*lightMapIntensity;reflectedLight.indirectDiffuse+=lightMapIrradiance;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nuniform sampler2D lightMap;uniform float lightMapIntensity;\n#endif",lights_lambert_fragment:"LambertMaterial material;material.diffuseColor=diffuseColor.rgb;material.specularStrength=specularStrength;",lights_lambert_pars_fragment:"varying vec3 vViewPosition;struct LambertMaterial{vec3 diffuseColor;float specularStrength;};void RE_Direct_Lambert(const in IncidentLight directLight,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in LambertMaterial material,inout ReflectedLight reflectedLight){float dotNL=saturate(dot(geometryNormal,directLight.direction));vec3 irradiance=dotNL*directLight.color;reflectedLight.directDiffuse+=irradiance*BRDF_Lambert(material.diffuseColor);}void RE_IndirectDiffuse_Lambert(const in vec3 irradiance,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in LambertMaterial material,inout ReflectedLight reflectedLight){reflectedLight.indirectDiffuse+=irradiance*BRDF_Lambert(material.diffuseColor);}\n#define RE_Direct RE_Direct_Lambert\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert",lights_pars_begin:"uniform bool receiveShadow;uniform vec3 ambientLightColor;\n#if defined(USE_LIGHT_PROBES)\nuniform vec3 lightProbe[9];\n#endif\nvec3 shGetIrradianceAt(in vec3 normal,in vec3 shCoefficients[9]){float x=normal.x,y=normal.y,z=normal.z;vec3 result=shCoefficients[0]*0.886227;result+=shCoefficients[1]*2.0*0.511664*y;result+=shCoefficients[2]*2.0*0.511664*z;result+=shCoefficients[3]*2.0*0.511664*x;result+=shCoefficients[4]*2.0*0.429043*x*y;result+=shCoefficients[5]*2.0*0.429043*y*z;result+=shCoefficients[6]*(0.743125*z*z-0.247708);result+=shCoefficients[7]*2.0*0.429043*x*z;result+=shCoefficients[8]*0.429043*(x*x-y*y);return result;}vec3 getLightProbeIrradiance(const in vec3 lightProbe[9],const in vec3 normal){vec3 worldNormal=inverseTransformDirection(normal,viewMatrix);vec3 irradiance=shGetIrradianceAt(worldNormal,lightProbe);return irradiance;}vec3 getAmbientLightIrradiance(const in vec3 ambientLightColor){vec3 irradiance=ambientLightColor;return irradiance;}float getDistanceAttenuation(const in float lightDistance,const in float cutoffDistance,const in float decayExponent){\n#if defined(LEGACY_LIGHTS)\nif(cutoffDistance>0.0&&decayExponent>0.0){return pow(saturate(-lightDistance/cutoffDistance+1.0),decayExponent);}return 1.0;\n#else\nfloat distanceFalloff=1.0/max(pow(lightDistance,decayExponent),0.01);if(cutoffDistance>0.0){distanceFalloff*=pow2(saturate(1.0-pow4(lightDistance/cutoffDistance)));}return distanceFalloff;\n#endif\n}float getSpotAttenuation(const in float coneCosine,const in float penumbraCosine,const in float angleCosine){return smoothstep(coneCosine,penumbraCosine,angleCosine);}\n#if NUM_DIR_LIGHTS>0\nstruct DirectionalLight{vec3 direction;vec3 color;};uniform DirectionalLight directionalLights[NUM_DIR_LIGHTS];void getDirectionalLightInfo(const in DirectionalLight directionalLight,out IncidentLight light){light.color=directionalLight.color;light.direction=directionalLight.direction;light.visible=true;}\n#endif\n#if NUM_POINT_LIGHTS>0\nstruct PointLight{vec3 position;vec3 color;float distance;float decay;};uniform PointLight pointLights[NUM_POINT_LIGHTS];void getPointLightInfo(const in PointLight pointLight,const in vec3 geometryPosition,out IncidentLight light){vec3 lVector=pointLight.position-geometryPosition;light.direction=normalize(lVector);float lightDistance=length(lVector);light.color=pointLight.color;light.color*=getDistanceAttenuation(lightDistance,pointLight.distance,pointLight.decay);light.visible=(light.color!=vec3(0.0));}\n#endif\n#if NUM_SPOT_LIGHTS>0\nstruct SpotLight{vec3 position;vec3 direction;vec3 color;float distance;float decay;float coneCos;float penumbraCos;};uniform SpotLight spotLights[NUM_SPOT_LIGHTS];void getSpotLightInfo(const in SpotLight spotLight,const in vec3 geometryPosition,out IncidentLight light){vec3 lVector=spotLight.position-geometryPosition;light.direction=normalize(lVector);float angleCos=dot(light.direction,spotLight.direction);float spotAttenuation=getSpotAttenuation(spotLight.coneCos,spotLight.penumbraCos,angleCos);if(spotAttenuation>0.0){float lightDistance=length(lVector);light.color=spotLight.color*spotAttenuation;light.color*=getDistanceAttenuation(lightDistance,spotLight.distance,spotLight.decay);light.visible=(light.color!=vec3(0.0));}else{light.color=vec3(0.0);light.visible=false;}}\n#endif\n#if NUM_RECT_AREA_LIGHTS>0\nstruct RectAreaLight{vec3 color;vec3 position;vec3 halfWidth;vec3 halfHeight;};uniform sampler2D ltc_1;uniform sampler2D ltc_2;uniform RectAreaLight rectAreaLights[NUM_RECT_AREA_LIGHTS];\n#endif\n#if NUM_HEMI_LIGHTS>0\nstruct HemisphereLight{vec3 direction;vec3 skyColor;vec3 groundColor;};uniform HemisphereLight hemisphereLights[NUM_HEMI_LIGHTS];vec3 getHemisphereLightIrradiance(const in HemisphereLight hemiLight,const in vec3 normal){float dotNL=dot(normal,hemiLight.direction);float hemiDiffuseWeight=0.5*dotNL+0.5;vec3 irradiance=mix(hemiLight.groundColor,hemiLight.skyColor,hemiDiffuseWeight);return irradiance;}\n#endif",lights_toon_fragment:"ToonMaterial material;material.diffuseColor=diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;struct ToonMaterial{vec3 diffuseColor;};void RE_Direct_Toon(const in IncidentLight directLight,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in ToonMaterial material,inout ReflectedLight reflectedLight){vec3 irradiance=getGradientIrradiance(geometryNormal,directLight.direction)*directLight.color;reflectedLight.directDiffuse+=irradiance*BRDF_Lambert(material.diffuseColor);}void RE_IndirectDiffuse_Toon(const in vec3 irradiance,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in ToonMaterial material,inout ReflectedLight reflectedLight){reflectedLight.indirectDiffuse+=irradiance*BRDF_Lambert(material.diffuseColor);}\n#define RE_Direct RE_Direct_Toon\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon",lights_phong_fragment:"BlinnPhongMaterial material;material.diffuseColor=diffuseColor.rgb;material.specularColor=specular;material.specularShininess=shininess;material.specularStrength=specularStrength;",lights_phong_pars_fragment:"varying vec3 vViewPosition;struct BlinnPhongMaterial{vec3 diffuseColor;vec3 specularColor;float specularShininess;float specularStrength;};void RE_Direct_BlinnPhong(const in IncidentLight directLight,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in BlinnPhongMaterial material,inout ReflectedLight reflectedLight){float dotNL=saturate(dot(geometryNormal,directLight.direction));vec3 irradiance=dotNL*directLight.color;reflectedLight.directDiffuse+=irradiance*BRDF_Lambert(material.diffuseColor);reflectedLight.directSpecular+=irradiance*BRDF_BlinnPhong(directLight.direction,geometryViewDir,geometryNormal,material.specularColor,material.specularShininess)*material.specularStrength;}void RE_IndirectDiffuse_BlinnPhong(const in vec3 irradiance,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in BlinnPhongMaterial material,inout ReflectedLight reflectedLight){reflectedLight.indirectDiffuse+=irradiance*BRDF_Lambert(material.diffuseColor);}\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong",lights_physical_fragment:"PhysicalMaterial material;material.diffuseColor=diffuseColor.rgb*(1.0-metalnessFactor);vec3 dxy=max(abs(dFdx(nonPerturbedNormal)),abs(dFdy(nonPerturbedNormal)));float geometryRoughness=max(max(dxy.x,dxy.y),dxy.z);material.roughness=max(roughnessFactor,0.0525);material.roughness+=geometryRoughness;material.roughness=min(material.roughness,1.0);\n#ifdef IOR\nmaterial.ior=ior;\n#ifdef USE_SPECULAR\nfloat specularIntensityFactor=specularIntensity;vec3 specularColorFactor=specularColor;\n#ifdef USE_SPECULAR_COLORMAP\nspecularColorFactor*=texture2D(specularColorMap,vSpecularColorMapUv).rgb;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\nspecularIntensityFactor*=texture2D(specularIntensityMap,vSpecularIntensityMapUv).a;\n#endif\nmaterial.specularF90=mix(specularIntensityFactor,1.0,metalnessFactor);\n#else\nfloat specularIntensityFactor=1.0;vec3 specularColorFactor=vec3(1.0);material.specularF90=1.0;\n#endif\nmaterial.specularColor=mix(min(pow2((material.ior-1.0)/(material.ior+1.0))*specularColorFactor,vec3(1.0))*specularIntensityFactor,diffuseColor.rgb,metalnessFactor);\n#else\nmaterial.specularColor=mix(vec3(0.04),diffuseColor.rgb,metalnessFactor);material.specularF90=1.0;\n#endif\n#ifdef USE_CLEARCOAT\nmaterial.clearcoat=clearcoat;material.clearcoatRoughness=clearcoatRoughness;material.clearcoatF0=vec3(0.04);material.clearcoatF90=1.0;\n#ifdef USE_CLEARCOATMAP\nmaterial.clearcoat*=texture2D(clearcoatMap,vClearcoatMapUv).x;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\nmaterial.clearcoatRoughness*=texture2D(clearcoatRoughnessMap,vClearcoatRoughnessMapUv).y;\n#endif\nmaterial.clearcoat=saturate(material.clearcoat);material.clearcoatRoughness=max(material.clearcoatRoughness,0.0525);material.clearcoatRoughness+=geometryRoughness;material.clearcoatRoughness=min(material.clearcoatRoughness,1.0);\n#endif\n#ifdef USE_IRIDESCENCE\nmaterial.iridescence=iridescence;material.iridescenceIOR=iridescenceIOR;\n#ifdef USE_IRIDESCENCEMAP\nmaterial.iridescence*=texture2D(iridescenceMap,vIridescenceMapUv).r;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\nmaterial.iridescenceThickness=(iridescenceThicknessMaximum-iridescenceThicknessMinimum)*texture2D(iridescenceThicknessMap,vIridescenceThicknessMapUv).g+iridescenceThicknessMinimum;\n#else\nmaterial.iridescenceThickness=iridescenceThicknessMaximum;\n#endif\n#endif\n#ifdef USE_SHEEN\nmaterial.sheenColor=sheenColor;\n#ifdef USE_SHEEN_COLORMAP\nmaterial.sheenColor*=texture2D(sheenColorMap,vSheenColorMapUv).rgb;\n#endif\nmaterial.sheenRoughness=clamp(sheenRoughness,0.07,1.0);\n#ifdef USE_SHEEN_ROUGHNESSMAP\nmaterial.sheenRoughness*=texture2D(sheenRoughnessMap,vSheenRoughnessMapUv).a;\n#endif\n#endif\n#ifdef USE_ANISOTROPY\n#ifdef USE_ANISOTROPYMAP\nmat2 anisotropyMat=mat2(anisotropyVector.x,anisotropyVector.y,-anisotropyVector.y,anisotropyVector.x);vec3 anisotropyPolar=texture2D(anisotropyMap,vAnisotropyMapUv).rgb;vec2 anisotropyV=anisotropyMat*normalize(2.0*anisotropyPolar.rg-vec2(1.0))*anisotropyPolar.b;\n#else\nvec2 anisotropyV=anisotropyVector;\n#endif\nmaterial.anisotropy=length(anisotropyV);anisotropyV/=material.anisotropy;material.anisotropy=saturate(material.anisotropy);material.alphaT=mix(pow2(material.roughness),1.0,pow2(material.anisotropy));material.anisotropyT=tbn[0]*anisotropyV.x-tbn[1]*anisotropyV.y;material.anisotropyB=tbn[1]*anisotropyV.x+tbn[0]*anisotropyV.y;\n#endif",lights_physical_pars_fragment:"struct PhysicalMaterial{vec3 diffuseColor;float roughness;vec3 specularColor;float specularF90;\n#ifdef USE_CLEARCOAT\nfloat clearcoat;float clearcoatRoughness;vec3 clearcoatF0;float clearcoatF90;\n#endif\n#ifdef USE_IRIDESCENCE\nfloat iridescence;float iridescenceIOR;float iridescenceThickness;vec3 iridescenceFresnel;vec3 iridescenceF0;\n#endif\n#ifdef USE_SHEEN\nvec3 sheenColor;float sheenRoughness;\n#endif\n#ifdef IOR\nfloat ior;\n#endif\n#ifdef USE_TRANSMISSION\nfloat transmission;float transmissionAlpha;float thickness;float attenuationDistance;vec3 attenuationColor;\n#endif\n#ifdef USE_ANISOTROPY\nfloat anisotropy;float alphaT;vec3 anisotropyT;vec3 anisotropyB;\n#endif\n};vec3 clearcoatSpecularDirect=vec3(0.0);vec3 clearcoatSpecularIndirect=vec3(0.0);vec3 sheenSpecularDirect=vec3(0.0);vec3 sheenSpecularIndirect=vec3(0.0);vec3 Schlick_to_F0(const in vec3 f,const in float f90,const in float dotVH){float x=clamp(1.0-dotVH,0.0,1.0);float x2=x*x;float x5=clamp(x*x2*x2,0.0,0.9999);return(f-vec3(f90)*x5)/(1.0-x5);}float V_GGX_SmithCorrelated(const in float alpha,const in float dotNL,const in float dotNV){float a2=pow2(alpha);float gv=dotNL*sqrt(a2+(1.0-a2)*pow2(dotNV));float gl=dotNV*sqrt(a2+(1.0-a2)*pow2(dotNL));return 0.5/max(gv+gl,EPSILON);}float D_GGX(const in float alpha,const in float dotNH){float a2=pow2(alpha);float denom=pow2(dotNH)*(a2-1.0)+1.0;return RECIPROCAL_PI*a2/pow2(denom);}\n#ifdef USE_ANISOTROPY\nfloat V_GGX_SmithCorrelated_Anisotropic(const in float alphaT,const in float alphaB,const in float dotTV,const in float dotBV,const in float dotTL,const in float dotBL,const in float dotNV,const in float dotNL){float gv=dotNL*length(vec3(alphaT*dotTV,alphaB*dotBV,dotNV));float gl=dotNV*length(vec3(alphaT*dotTL,alphaB*dotBL,dotNL));float v=0.5/(gv+gl);return saturate(v);}float D_GGX_Anisotropic(const in float alphaT,const in float alphaB,const in float dotNH,const in float dotTH,const in float dotBH){float a2=alphaT*alphaB;highp vec3 v=vec3(alphaB*dotTH,alphaT*dotBH,a2*dotNH);highp float v2=dot(v,v);float w2=a2/v2;return RECIPROCAL_PI*a2*pow2(w2);}\n#endif\n#ifdef USE_CLEARCOAT\nvec3 BRDF_GGX_Clearcoat(const in vec3 lightDir,const in vec3 viewDir,const in vec3 normal,const in PhysicalMaterial material){vec3 f0=material.clearcoatF0;float f90=material.clearcoatF90;float roughness=material.clearcoatRoughness;float alpha=pow2(roughness);vec3 halfDir=normalize(lightDir+viewDir);float dotNL=saturate(dot(normal,lightDir));float dotNV=saturate(dot(normal,viewDir));float dotNH=saturate(dot(normal,halfDir));float dotVH=saturate(dot(viewDir,halfDir));vec3 F=F_Schlick(f0,f90,dotVH);float V=V_GGX_SmithCorrelated(alpha,dotNL,dotNV);float D=D_GGX(alpha,dotNH);return F*(V*D);}\n#endif\nvec3 BRDF_GGX(const in vec3 lightDir,const in vec3 viewDir,const in vec3 normal,const in PhysicalMaterial material){vec3 f0=material.specularColor;float f90=material.specularF90;float roughness=material.roughness;float alpha=pow2(roughness);vec3 halfDir=normalize(lightDir+viewDir);float dotNL=saturate(dot(normal,lightDir));float dotNV=saturate(dot(normal,viewDir));float dotNH=saturate(dot(normal,halfDir));float dotVH=saturate(dot(viewDir,halfDir));vec3 F=F_Schlick(f0,f90,dotVH);\n#ifdef USE_IRIDESCENCE\nF=mix(F,material.iridescenceFresnel,material.iridescence);\n#endif\n#ifdef USE_ANISOTROPY\nfloat dotTL=dot(material.anisotropyT,lightDir);float dotTV=dot(material.anisotropyT,viewDir);float dotTH=dot(material.anisotropyT,halfDir);float dotBL=dot(material.anisotropyB,lightDir);float dotBV=dot(material.anisotropyB,viewDir);float dotBH=dot(material.anisotropyB,halfDir);float V=V_GGX_SmithCorrelated_Anisotropic(material.alphaT,alpha,dotTV,dotBV,dotTL,dotBL,dotNV,dotNL);float D=D_GGX_Anisotropic(material.alphaT,alpha,dotNH,dotTH,dotBH);\n#else\nfloat V=V_GGX_SmithCorrelated(alpha,dotNL,dotNV);float D=D_GGX(alpha,dotNH);\n#endif\nreturn F*(V*D);}vec2 LTC_Uv(const in vec3 N,const in vec3 V,const in float roughness){const float LUT_SIZE=64.0;const float LUT_SCALE=(LUT_SIZE-1.0)/LUT_SIZE;const float LUT_BIAS=0.5/LUT_SIZE;float dotNV=saturate(dot(N,V));vec2 uv=vec2(roughness,sqrt(1.0-dotNV));uv=uv*LUT_SCALE+LUT_BIAS;return uv;}float LTC_ClippedSphereFormFactor(const in vec3 f){float l=length(f);return max((l*l+f.z)/(l+1.0),0.0);}vec3 LTC_EdgeVectorFormFactor(const in vec3 v1,const in vec3 v2){float x=dot(v1,v2);float y=abs(x);float a=0.8543985+(0.4965155+0.0145206*y)*y;float b=3.4175940+(4.1616724+y)*y;float v=a/b;float theta_sintheta=(x>0.0)?v:0.5*inversesqrt(max(1.0-x*x,1e-7))-v;return cross(v1,v2)*theta_sintheta;}vec3 LTC_Evaluate(const in vec3 N,const in vec3 V,const in vec3 P,const in mat3 mInv,const in vec3 rectCoords[4]){vec3 v1=rectCoords[1]-rectCoords[0];vec3 v2=rectCoords[3]-rectCoords[0];vec3 lightNormal=cross(v1,v2);if(dot(lightNormal,P-rectCoords[0])<0.0)return vec3(0.0);vec3 T1,T2;T1=normalize(V-N*dot(V,N));T2=-cross(N,T1);mat3 mat=mInv*transposeMat3(mat3(T1,T2,N));vec3 coords[4];coords[0]=mat*(rectCoords[0]-P);coords[1]=mat*(rectCoords[1]-P);coords[2]=mat*(rectCoords[2]-P);coords[3]=mat*(rectCoords[3]-P);coords[0]=normalize(coords[0]);coords[1]=normalize(coords[1]);coords[2]=normalize(coords[2]);coords[3]=normalize(coords[3]);vec3 vectorFormFactor=vec3(0.0);vectorFormFactor+=LTC_EdgeVectorFormFactor(coords[0],coords[1]);vectorFormFactor+=LTC_EdgeVectorFormFactor(coords[1],coords[2]);vectorFormFactor+=LTC_EdgeVectorFormFactor(coords[2],coords[3]);vectorFormFactor+=LTC_EdgeVectorFormFactor(coords[3],coords[0]);float result=LTC_ClippedSphereFormFactor(vectorFormFactor);return vec3(result);}\n#if defined(USE_SHEEN)\nfloat D_Charlie(float roughness,float dotNH){float alpha=pow2(roughness);float invAlpha=1.0/alpha;float cos2h=dotNH*dotNH;float sin2h=max(1.0-cos2h,0.0078125);return(2.0+invAlpha)*pow(sin2h,invAlpha*0.5)/(2.0*PI);}float V_Neubelt(float dotNV,float dotNL){return saturate(1.0/(4.0*(dotNL+dotNV-dotNL*dotNV)));}vec3 BRDF_Sheen(const in vec3 lightDir,const in vec3 viewDir,const in vec3 normal,vec3 sheenColor,const in float sheenRoughness){vec3 halfDir=normalize(lightDir+viewDir);float dotNL=saturate(dot(normal,lightDir));float dotNV=saturate(dot(normal,viewDir));float dotNH=saturate(dot(normal,halfDir));float D=D_Charlie(sheenRoughness,dotNH);float V=V_Neubelt(dotNV,dotNL);return sheenColor*(D*V);}\n#endif\nfloat IBLSheenBRDF(const in vec3 normal,const in vec3 viewDir,const in float roughness){float dotNV=saturate(dot(normal,viewDir));float r2=roughness*roughness;float a=roughness<0.25?-339.2*r2+161.4*roughness-25.9:-8.48*r2+14.3*roughness-9.95;float b=roughness<0.25?44.0*r2-23.7*roughness+3.26:1.97*r2-3.27*roughness+0.72;float DG=exp(a*dotNV+b)+(roughness<0.25?0.0:0.1*(roughness-0.25));return saturate(DG*RECIPROCAL_PI);}vec2 DFGApprox(const in vec3 normal,const in vec3 viewDir,const in float roughness){float dotNV=saturate(dot(normal,viewDir));const vec4 c0=vec4(-1,-0.0275,-0.572,0.022);const vec4 c1=vec4(1,0.0425,1.04,-0.04);vec4 r=roughness*c0+c1;float a004=min(r.x*r.x,exp2(-9.28*dotNV))*r.x+r.y;vec2 fab=vec2(-1.04,1.04)*a004+r.zw;return fab;}vec3 EnvironmentBRDF(const in vec3 normal,const in vec3 viewDir,const in vec3 specularColor,const in float specularF90,const in float roughness){vec2 fab=DFGApprox(normal,viewDir,roughness);return specularColor*fab.x+specularF90*fab.y;}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence(const in vec3 normal,const in vec3 viewDir,const in vec3 specularColor,const in float specularF90,const in float iridescence,const in vec3 iridescenceF0,const in float roughness,inout vec3 singleScatter,inout vec3 multiScatter){\n#else\nvoid computeMultiscattering(const in vec3 normal,const in vec3 viewDir,const in vec3 specularColor,const in float specularF90,const in float roughness,inout vec3 singleScatter,inout vec3 multiScatter){\n#endif\nvec2 fab=DFGApprox(normal,viewDir,roughness);\n#ifdef USE_IRIDESCENCE\nvec3 Fr=mix(specularColor,iridescenceF0,iridescence);\n#else\nvec3 Fr=specularColor;\n#endif\nvec3 FssEss=Fr*fab.x+specularF90*fab.y;float Ess=fab.x+fab.y;float Ems=1.0-Ess;vec3 Favg=Fr+(1.0-Fr)*0.047619;vec3 Fms=FssEss*Favg/(1.0-Ems*Favg);singleScatter+=FssEss;multiScatter+=Fms*Ems;}\n#if NUM_RECT_AREA_LIGHTS>0\nvoid RE_Direct_RectArea_Physical(const in RectAreaLight rectAreaLight,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in PhysicalMaterial material,inout ReflectedLight reflectedLight){vec3 normal=geometryNormal;vec3 viewDir=geometryViewDir;vec3 position=geometryPosition;vec3 lightPos=rectAreaLight.position;vec3 halfWidth=rectAreaLight.halfWidth;vec3 halfHeight=rectAreaLight.halfHeight;vec3 lightColor=rectAreaLight.color;float roughness=material.roughness;vec3 rectCoords[4];rectCoords[0]=lightPos+halfWidth-halfHeight;rectCoords[1]=lightPos-halfWidth-halfHeight;rectCoords[2]=lightPos-halfWidth+halfHeight;rectCoords[3]=lightPos+halfWidth+halfHeight;vec2 uv=LTC_Uv(normal,viewDir,roughness);vec4 t1=texture2D(ltc_1,uv);vec4 t2=texture2D(ltc_2,uv);mat3 mInv=mat3(vec3(t1.x,0,t1.y),vec3(0,1,0),vec3(t1.z,0,t1.w));vec3 fresnel=(material.specularColor*t2.x+(vec3(1.0)-material.specularColor)*t2.y);reflectedLight.directSpecular+=lightColor*fresnel*LTC_Evaluate(normal,viewDir,position,mInv,rectCoords);reflectedLight.directDiffuse+=lightColor*material.diffuseColor*LTC_Evaluate(normal,viewDir,position,mat3(1.0),rectCoords);}\n#endif\nvoid RE_Direct_Physical(const in IncidentLight directLight,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in PhysicalMaterial material,inout ReflectedLight reflectedLight){float dotNL=saturate(dot(geometryNormal,directLight.direction));vec3 irradiance=dotNL*directLight.color;\n#ifdef USE_CLEARCOAT\nfloat dotNLcc=saturate(dot(geometryClearcoatNormal,directLight.direction));vec3 ccIrradiance=dotNLcc*directLight.color;clearcoatSpecularDirect+=ccIrradiance*BRDF_GGX_Clearcoat(directLight.direction,geometryViewDir,geometryClearcoatNormal,material);\n#endif\n#ifdef USE_SHEEN\nsheenSpecularDirect+=irradiance*BRDF_Sheen(directLight.direction,geometryViewDir,geometryNormal,material.sheenColor,material.sheenRoughness);\n#endif\nreflectedLight.directSpecular+=irradiance*BRDF_GGX(directLight.direction,geometryViewDir,geometryNormal,material);reflectedLight.directDiffuse+=irradiance*BRDF_Lambert(material.diffuseColor);}void RE_IndirectDiffuse_Physical(const in vec3 irradiance,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in PhysicalMaterial material,inout ReflectedLight reflectedLight){reflectedLight.indirectDiffuse+=irradiance*BRDF_Lambert(material.diffuseColor);}void RE_IndirectSpecular_Physical(const in vec3 radiance,const in vec3 irradiance,const in vec3 clearcoatRadiance,const in vec3 geometryPosition,const in vec3 geometryNormal,const in vec3 geometryViewDir,const in vec3 geometryClearcoatNormal,const in PhysicalMaterial material,inout ReflectedLight reflectedLight){\n#ifdef USE_CLEARCOAT\nclearcoatSpecularIndirect+=clearcoatRadiance*EnvironmentBRDF(geometryClearcoatNormal,geometryViewDir,material.clearcoatF0,material.clearcoatF90,material.clearcoatRoughness);\n#endif\n#ifdef USE_SHEEN\nsheenSpecularIndirect+=irradiance*material.sheenColor*IBLSheenBRDF(geometryNormal,geometryViewDir,material.sheenRoughness);\n#endif\nvec3 singleScattering=vec3(0.0);vec3 multiScattering=vec3(0.0);vec3 cosineWeightedIrradiance=irradiance*RECIPROCAL_PI;\n#ifdef USE_IRIDESCENCE\ncomputeMultiscatteringIridescence(geometryNormal,geometryViewDir,material.specularColor,material.specularF90,material.iridescence,material.iridescenceFresnel,material.roughness,singleScattering,multiScattering);\n#else\ncomputeMultiscattering(geometryNormal,geometryViewDir,material.specularColor,material.specularF90,material.roughness,singleScattering,multiScattering);\n#endif\nvec3 totalScattering=singleScattering+multiScattering;vec3 diffuse=material.diffuseColor*(1.0-max(max(totalScattering.r,totalScattering.g),totalScattering.b));reflectedLight.indirectSpecular+=radiance*singleScattering;reflectedLight.indirectSpecular+=multiScattering*cosineWeightedIrradiance;reflectedLight.indirectDiffuse+=diffuse*cosineWeightedIrradiance;}\n#define RE_Direct RE_Direct_Physical\n#define RE_Direct_RectArea RE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular RE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion(const in float dotNV,const in float ambientOcclusion,const in float roughness){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}",lights_fragment_begin:"vec3 geometryPosition=-vViewPosition;vec3 geometryNormal=normal;vec3 geometryViewDir=(isOrthographic)?vec3(0,0,1):normalize(vViewPosition);vec3 geometryClearcoatNormal=vec3(0.0);\n#ifdef USE_CLEARCOAT\ngeometryClearcoatNormal=clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\nfloat dotNVi=saturate(dot(normal,geometryViewDir));if(material.iridescenceThickness==0.0){material.iridescence=0.0;}else{material.iridescence=saturate(material.iridescence);}if(material.iridescence>0.0){material.iridescenceFresnel=evalIridescence(1.0,material.iridescenceIOR,dotNVi,material.iridescenceThickness,material.specularColor);material.iridescenceF0=Schlick_to_F0(material.iridescenceFresnel,1.0,dotNVi);}\n#endif\nIncidentLight directLight;\n#if (NUM_POINT_LIGHTS>0)&&defined(RE_Direct)\nPointLight pointLight;\n#if defined(USE_SHADOWMAP)&&NUM_POINT_LIGHT_SHADOWS>0\nPointLightShadow pointLightShadow;\n#endif\n#pragma unroll_loop_start\nfor(int i=0;i0)&&defined(RE_Direct)\nSpotLight spotLight;vec4 spotColor;vec3 spotLightCoord;bool inSpotLightMap;\n#if defined(USE_SHADOWMAP)&&NUM_SPOT_LIGHT_SHADOWS>0\nSpotLightShadow spotLightShadow;\n#endif\n#pragma unroll_loop_start\nfor(int i=0;i0)&&defined(RE_Direct)\nDirectionalLight directionalLight;\n#if defined(USE_SHADOWMAP)&&NUM_DIR_LIGHT_SHADOWS>0\nDirectionalLightShadow directionalLightShadow;\n#endif\n#pragma unroll_loop_start\nfor(int i=0;i0)&&defined(RE_Direct_RectArea)\nRectAreaLight rectAreaLight;\n#pragma unroll_loop_start\nfor(int i=0;i0)\n#pragma unroll_loop_start\nfor(int i=0;i0\nvarying vec4 vSpotLightCoord[NUM_SPOT_LIGHT_COORDS];\n#endif\n#if NUM_SPOT_LIGHT_MAPS>0\nuniform sampler2D spotLightMap[NUM_SPOT_LIGHT_MAPS];\n#endif\n#ifdef USE_SHADOWMAP\n#if NUM_DIR_LIGHT_SHADOWS>0\nuniform sampler2D directionalShadowMap[NUM_DIR_LIGHT_SHADOWS];varying vec4 vDirectionalShadowCoord[NUM_DIR_LIGHT_SHADOWS];struct DirectionalLightShadow{float shadowBias;float shadowNormalBias;float shadowRadius;vec2 shadowMapSize;};uniform DirectionalLightShadow directionalLightShadows[NUM_DIR_LIGHT_SHADOWS];\n#endif\n#if NUM_SPOT_LIGHT_SHADOWS>0\nuniform sampler2D spotShadowMap[NUM_SPOT_LIGHT_SHADOWS];struct SpotLightShadow{float shadowBias;float shadowNormalBias;float shadowRadius;vec2 shadowMapSize;};uniform SpotLightShadow spotLightShadows[NUM_SPOT_LIGHT_SHADOWS];\n#endif\n#if NUM_POINT_LIGHT_SHADOWS>0\nuniform sampler2D pointShadowMap[NUM_POINT_LIGHT_SHADOWS];varying vec4 vPointShadowCoord[NUM_POINT_LIGHT_SHADOWS];struct PointLightShadow{float shadowBias;float shadowNormalBias;float shadowRadius;vec2 shadowMapSize;float shadowCameraNear;float shadowCameraFar;};uniform PointLightShadow pointLightShadows[NUM_POINT_LIGHT_SHADOWS];\n#endif\nfloat texture2DCompare(sampler2D depths,vec2 uv,float compare){return step(compare,unpackRGBAToDepth(texture2D(depths,uv)));}vec2 texture2DDistribution(sampler2D shadow,vec2 uv){return unpackRGBATo2Half(texture2D(shadow,uv));}float VSMShadow(sampler2D shadow,vec2 uv,float compare){float occlusion=1.0;vec2 distribution=texture2DDistribution(shadow,uv);float hard_shadow=step(compare,distribution.x);if(hard_shadow!=1.0){float distance=compare-distribution.x;float variance=max(0.00000,distribution.y*distribution.y);float softness_probability=variance/(variance+distance*distance);softness_probability=clamp((softness_probability-0.3)/(0.95-0.3),0.0,1.0);occlusion=clamp(max(hard_shadow,softness_probability),0.0,1.0);}return occlusion;}float getShadow(sampler2D shadowMap,vec2 shadowMapSize,float shadowBias,float shadowRadius,vec4 shadowCoord){float shadow=1.0;shadowCoord.xyz/=shadowCoord.w;shadowCoord.z+=shadowBias;bool inFrustum=shadowCoord.x>=0.0&&shadowCoord.x<=1.0&&shadowCoord.y>=0.0&&shadowCoord.y<=1.0;bool frustumTest=inFrustum&&shadowCoord.z<=1.0;if(frustumTest){\n#if defined(SHADOWMAP_TYPE_PCF)\nvec2 texelSize=vec2(1.0)/shadowMapSize;float dx0=-texelSize.x*shadowRadius;float dy0=-texelSize.y*shadowRadius;float dx1=+texelSize.x*shadowRadius;float dy1=+texelSize.y*shadowRadius;float dx2=dx0/2.0;float dy2=dy0/2.0;float dx3=dx1/2.0;float dy3=dy1/2.0;shadow=(texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx0,dy0),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(0.0,dy0),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx1,dy0),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx2,dy2),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(0.0,dy2),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx3,dy2),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx0,0.0),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx2,0.0),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy,shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx3,0.0),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx1,0.0),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx2,dy3),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(0.0,dy3),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx3,dy3),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx0,dy1),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(0.0,dy1),shadowCoord.z)+texture2DCompare(shadowMap,shadowCoord.xy+vec2(dx1,dy1),shadowCoord.z))*(1.0/17.0);\n#elif defined(SHADOWMAP_TYPE_PCF_SOFT)\nvec2 texelSize=vec2(1.0)/shadowMapSize;float dx=texelSize.x;float dy=texelSize.y;vec2 uv=shadowCoord.xy;vec2 f=fract(uv*shadowMapSize+0.5);uv-=f*texelSize;shadow=(texture2DCompare(shadowMap,uv,shadowCoord.z)+texture2DCompare(shadowMap,uv+vec2(dx,0.0),shadowCoord.z)+texture2DCompare(shadowMap,uv+vec2(0.0,dy),shadowCoord.z)+texture2DCompare(shadowMap,uv+texelSize,shadowCoord.z)+mix(texture2DCompare(shadowMap,uv+vec2(-dx,0.0),shadowCoord.z),texture2DCompare(shadowMap,uv+vec2(2.0*dx,0.0),shadowCoord.z),f.x)+mix(texture2DCompare(shadowMap,uv+vec2(-dx,dy),shadowCoord.z),texture2DCompare(shadowMap,uv+vec2(2.0*dx,dy),shadowCoord.z),f.x)+mix(texture2DCompare(shadowMap,uv+vec2(0.0,-dy),shadowCoord.z),texture2DCompare(shadowMap,uv+vec2(0.0,2.0*dy),shadowCoord.z),f.y)+mix(texture2DCompare(shadowMap,uv+vec2(dx,-dy),shadowCoord.z),texture2DCompare(shadowMap,uv+vec2(dx,2.0*dy),shadowCoord.z),f.y)+mix(mix(texture2DCompare(shadowMap,uv+vec2(-dx,-dy),shadowCoord.z),texture2DCompare(shadowMap,uv+vec2(2.0*dx,-dy),shadowCoord.z),f.x),mix(texture2DCompare(shadowMap,uv+vec2(-dx,2.0*dy),shadowCoord.z),texture2DCompare(shadowMap,uv+vec2(2.0*dx,2.0*dy),shadowCoord.z),f.x),f.y))*(1.0/9.0);\n#elif defined(SHADOWMAP_TYPE_VSM)\nshadow=VSMShadow(shadowMap,shadowCoord.xy,shadowCoord.z);\n#else\nshadow=texture2DCompare(shadowMap,shadowCoord.xy,shadowCoord.z);\n#endif\n}return shadow;}vec2 cubeToUV(vec3 v,float texelSizeY){vec3 absV=abs(v);float scaleToCube=1.0/max(absV.x,max(absV.y,absV.z));absV*=scaleToCube;v*=scaleToCube*(1.0-2.0*texelSizeY);vec2 planar=v.xy;float almostATexel=1.5*texelSizeY;float almostOne=1.0-almostATexel;if(absV.z>=almostOne){if(v.z>0.0)planar.x=4.0-v.x;}else if(absV.x>=almostOne){float signX=sign(v.x);planar.x=v.z*signX+2.0*signX;}else if(absV.y>=almostOne){float signY=sign(v.y);planar.x=v.x+2.0*signY+2.0;planar.y=v.z*signY-2.0;}return vec2(0.125,0.25)*planar+vec2(0.375,0.75);}float getPointShadow(sampler2D shadowMap,vec2 shadowMapSize,float shadowBias,float shadowRadius,vec4 shadowCoord,float shadowCameraNear,float shadowCameraFar){vec2 texelSize=vec2(1.0)/(shadowMapSize*vec2(4.0,2.0));vec3 lightToPosition=shadowCoord.xyz;float dp=(length(lightToPosition)-shadowCameraNear)/(shadowCameraFar-shadowCameraNear);dp+=shadowBias;vec3 bd3D=normalize(lightToPosition);\n#if defined(SHADOWMAP_TYPE_PCF)||defined(SHADOWMAP_TYPE_PCF_SOFT)||defined(SHADOWMAP_TYPE_VSM)\nvec2 offset=vec2(-1,1)*shadowRadius*texelSize.y;return(texture2DCompare(shadowMap,cubeToUV(bd3D+offset.xyy,texelSize.y),dp)+texture2DCompare(shadowMap,cubeToUV(bd3D+offset.yyy,texelSize.y),dp)+texture2DCompare(shadowMap,cubeToUV(bd3D+offset.xyx,texelSize.y),dp)+texture2DCompare(shadowMap,cubeToUV(bd3D+offset.yyx,texelSize.y),dp)+texture2DCompare(shadowMap,cubeToUV(bd3D,texelSize.y),dp)+texture2DCompare(shadowMap,cubeToUV(bd3D+offset.xxy,texelSize.y),dp)+texture2DCompare(shadowMap,cubeToUV(bd3D+offset.yxy,texelSize.y),dp)+texture2DCompare(shadowMap,cubeToUV(bd3D+offset.xxx,texelSize.y),dp)+texture2DCompare(shadowMap,cubeToUV(bd3D+offset.yxx,texelSize.y),dp))*(1.0/9.0);\n#else\nreturn texture2DCompare(shadowMap,cubeToUV(bd3D,texelSize.y),dp);\n#endif\n}\n#endif",shadowmap_pars_vertex:"#if NUM_SPOT_LIGHT_COORDS>0\nuniform mat4 spotLightMatrix[NUM_SPOT_LIGHT_COORDS];varying vec4 vSpotLightCoord[NUM_SPOT_LIGHT_COORDS];\n#endif\n#ifdef USE_SHADOWMAP\n#if NUM_DIR_LIGHT_SHADOWS>0\nuniform mat4 directionalShadowMatrix[NUM_DIR_LIGHT_SHADOWS];varying vec4 vDirectionalShadowCoord[NUM_DIR_LIGHT_SHADOWS];struct DirectionalLightShadow{float shadowBias;float shadowNormalBias;float shadowRadius;vec2 shadowMapSize;};uniform DirectionalLightShadow directionalLightShadows[NUM_DIR_LIGHT_SHADOWS];\n#endif\n#if NUM_SPOT_LIGHT_SHADOWS>0\nstruct SpotLightShadow{float shadowBias;float shadowNormalBias;float shadowRadius;vec2 shadowMapSize;};uniform SpotLightShadow spotLightShadows[NUM_SPOT_LIGHT_SHADOWS];\n#endif\n#if NUM_POINT_LIGHT_SHADOWS>0\nuniform mat4 pointShadowMatrix[NUM_POINT_LIGHT_SHADOWS];varying vec4 vPointShadowCoord[NUM_POINT_LIGHT_SHADOWS];struct PointLightShadow{float shadowBias;float shadowNormalBias;float shadowRadius;vec2 shadowMapSize;float shadowCameraNear;float shadowCameraFar;};uniform PointLightShadow pointLightShadows[NUM_POINT_LIGHT_SHADOWS];\n#endif\n#endif",shadowmap_vertex:"#if (defined(USE_SHADOWMAP)&&(NUM_DIR_LIGHT_SHADOWS>0||NUM_POINT_LIGHT_SHADOWS>0))||(NUM_SPOT_LIGHT_COORDS>0)\nvec3 shadowWorldNormal=inverseTransformDirection(transformedNormal,viewMatrix);vec4 shadowWorldPosition;\n#endif\n#if defined(USE_SHADOWMAP)\n#if NUM_DIR_LIGHT_SHADOWS>0\n#pragma unroll_loop_start\nfor(int i=0;i0\n#pragma unroll_loop_start\nfor(int i=0;i0\n#pragma unroll_loop_start\nfor(int i=0;i0\nDirectionalLightShadow directionalLight;\n#pragma unroll_loop_start\nfor(int i=0;i0\nSpotLightShadow spotLight;\n#pragma unroll_loop_start\nfor(int i=0;i0\nPointLightShadow pointLight;\n#pragma unroll_loop_start\nfor(int i=0;i0\nvec4 worldPosition=vec4(transformed,1.0);\n#ifdef USE_INSTANCING\nworldPosition=instanceMatrix*worldPosition;\n#endif\nworldPosition=modelMatrix*worldPosition;\n#endif",background_vert:"varying vec2 vUv;uniform mat3 uvTransform;void main(){vUv=(uvTransform*vec3(uv,1)).xy;gl_Position=vec4(position.xy,1.0,1.0);}",background_frag:"uniform sampler2D t2D;uniform float backgroundIntensity;varying vec2 vUv;void main(){vec4 texColor=texture2D(t2D,vUv);\n#ifdef DECODE_VIDEO_TEXTURE\ntexColor=vec4(mix(pow(texColor.rgb*0.9478672986+vec3(0.0521327014),vec3(2.4)),texColor.rgb*0.0773993808,vec3(lessThanEqual(texColor.rgb,vec3(0.04045)))),texColor.w);\n#endif\ntexColor.rgb*=backgroundIntensity;gl_FragColor=texColor;\n#include \n#include \n}",backgroundCube_vert:"varying vec3 vWorldDirection;\n#include \nvoid main(){vWorldDirection=transformDirection(position,modelMatrix);\n#include \n#include \ngl_Position.z=gl_Position.w;}",backgroundCube_frag:"#ifdef ENVMAP_TYPE_CUBE\nuniform samplerCube envMap;\n#elif defined(ENVMAP_TYPE_CUBE_UV)\nuniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;uniform float backgroundBlurriness;uniform float backgroundIntensity;varying vec3 vWorldDirection;\n#include \nvoid main(){\n#ifdef ENVMAP_TYPE_CUBE\nvec4 texColor=textureCube(envMap,vec3(flipEnvMap*vWorldDirection.x,vWorldDirection.yz));\n#elif defined(ENVMAP_TYPE_CUBE_UV)\nvec4 texColor=textureCubeUV(envMap,vWorldDirection,backgroundBlurriness);\n#else\nvec4 texColor=vec4(0.0,0.0,0.0,1.0);\n#endif\ntexColor.rgb*=backgroundIntensity;gl_FragColor=texColor;\n#include \n#include \n}",cube_vert:"varying vec3 vWorldDirection;\n#include \nvoid main(){vWorldDirection=transformDirection(position,modelMatrix);\n#include \n#include \ngl_Position.z=gl_Position.w;}",cube_frag:"uniform samplerCube tCube;uniform float tFlip;uniform float opacity;varying vec3 vWorldDirection;void main(){vec4 texColor=textureCube(tCube,vec3(tFlip*vWorldDirection.x,vWorldDirection.yz));gl_FragColor=texColor;gl_FragColor.a*=opacity;\n#include \n#include \n}",depth_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;void main(){\n#include \n#include \n#ifdef USE_DISPLACEMENTMAP\n#include \n#include \n#include \n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvHighPrecisionZW=gl_Position.zw;}",depth_frag:"#if DEPTH_PACKING==3200\nuniform float opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;void main(){\n#include \nvec4 diffuseColor=vec4(1.0);\n#if DEPTH_PACKING==3200\ndiffuseColor.a=opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \nfloat fragCoordZ=0.5*vHighPrecisionZW[0]/vHighPrecisionZW[1]+0.5;\n#if DEPTH_PACKING==3200\ngl_FragColor=vec4(vec3(1.0-fragCoordZ),opacity);\n#elif DEPTH_PACKING==3201\ngl_FragColor=packDepthToRGBA(fragCoordZ);\n#endif\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#ifdef USE_DISPLACEMENTMAP\n#include \n#include \n#include \n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvWorldPosition=worldPosition.xyz;}",distanceRGBA_frag:"#define DISTANCE\nuniform vec3 referencePosition;uniform float nearDistance;uniform float farDistance;varying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec4 diffuseColor=vec4(1.0);\n#include \n#include \n#include \n#include \nfloat dist=length(vWorldPosition-referencePosition);dist=(dist-nearDistance)/(farDistance-nearDistance);dist=saturate(dist);gl_FragColor=packDepthToRGBA(dist);}",equirect_vert:"varying vec3 vWorldDirection;\n#include \nvoid main(){vWorldDirection=transformDirection(position,modelMatrix);\n#include \n#include \n}",equirect_frag:"uniform sampler2D tEquirect;varying vec3 vWorldDirection;\n#include \nvoid main(){vec3 direction=normalize(vWorldDirection);vec2 sampleUV=equirectUv(direction);gl_FragColor=texture2D(tEquirect,sampleUV);\n#include \n#include \n}",linedashed_vert:"uniform float scale;attribute float lineDistance;varying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){vLineDistance=scale*lineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n}",linedashed_frag:"uniform vec3 diffuse;uniform float opacity;uniform float dashSize;uniform float totalSize;varying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nif(mod(vLineDistance,totalSize)>dashSize){discard;}vec3 outgoingLight=vec3(0.0);vec4 diffuseColor=vec4(diffuse,opacity);\n#include \n#include \n#include \noutgoingLight=diffuseColor.rgb;\n#include \n#include \n#include \n#include \n#include \n}",meshbasic_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#include \n#if defined(USE_ENVMAP)||defined(USE_SKINNING)\n#include \n#include \n#include \n#include \n#include \n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n}",meshbasic_frag:"uniform vec3 diffuse;uniform float opacity;\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec4 diffuseColor=vec4(diffuse,opacity);\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));\n#ifdef USE_LIGHTMAP\nvec4 lightMapTexel=texture2D(lightMap,vLightMapUv);reflectedLight.indirectDiffuse+=lightMapTexel.rgb*lightMapIntensity*RECIPROCAL_PI;\n#else\nreflectedLight.indirectDiffuse+=vec3(1.0);\n#endif\n#include \nreflectedLight.indirectDiffuse*=diffuseColor.rgb;vec3 outgoingLight=reflectedLight.indirectDiffuse;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvViewPosition=-mvPosition.xyz;\n#include \n#include \n#include \n#include \n}",meshlambert_frag:"#define LAMBERT\nuniform vec3 diffuse;uniform vec3 emissive;uniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec4 diffuseColor=vec4(diffuse,opacity);ReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));vec3 totalEmissiveRadiance=emissive;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvec3 outgoingLight=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+totalEmissiveRadiance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvViewPosition=-mvPosition.xyz;}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;uniform float opacity;uniform sampler2D matcap;varying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec4 diffuseColor=vec4(diffuse,opacity);\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvec3 viewDir=normalize(vViewPosition);vec3 x=normalize(vec3(viewDir.z,0.0,-viewDir.x));vec3 y=cross(viewDir,x);vec2 uv=vec2(dot(x,normal),dot(y,normal))*0.495+0.5;\n#ifdef USE_MATCAP\nvec4 matcapColor=texture2D(matcap,uv);\n#else\nvec4 matcapColor=vec4(vec3(mix(0.2,0.8,uv.y)),1.0);\n#endif\nvec3 outgoingLight=diffuseColor.rgb*matcapColor.rgb;\n#include \n#include \n#include \n#include \n#include \n#include \n}",meshnormal_vert:"#define NORMAL\n#if defined(FLAT_SHADED)||defined(USE_BUMPMAP)||defined(USE_NORMALMAP_TANGENTSPACE)\nvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#if defined(FLAT_SHADED)||defined(USE_BUMPMAP)||defined(USE_NORMALMAP_TANGENTSPACE)\nvViewPosition=-mvPosition.xyz;\n#endif\n}",meshnormal_frag:"#define NORMAL\nuniform float opacity;\n#if defined(FLAT_SHADED)||defined(USE_BUMPMAP)||defined(USE_NORMALMAP_TANGENTSPACE)\nvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#include \n#include \ngl_FragColor=vec4(packNormalToRGB(normal),opacity);\n#ifdef OPAQUE\ngl_FragColor.a=1.0;\n#endif\n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvViewPosition=-mvPosition.xyz;\n#include \n#include \n#include \n#include \n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;uniform vec3 emissive;uniform vec3 specular;uniform float shininess;uniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec4 diffuseColor=vec4(diffuse,opacity);ReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));vec3 totalEmissiveRadiance=emissive;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvec3 outgoingLight=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+reflectedLight.directSpecular+reflectedLight.indirectSpecular+totalEmissiveRadiance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\nvarying vec3 vWorldPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvViewPosition=-mvPosition.xyz;\n#include \n#include \n#include \n#ifdef USE_TRANSMISSION\nvWorldPosition=worldPosition.xyz;\n#endif\n}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n#define IOR\n#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;uniform vec3 emissive;uniform float roughness;uniform float metalness;uniform float opacity;\n#ifdef IOR\nuniform float ior;\n#endif\n#ifdef USE_SPECULAR\nuniform float specularIntensity;uniform vec3 specularColor;\n#ifdef USE_SPECULAR_COLORMAP\nuniform sampler2D specularColorMap;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\nuniform sampler2D specularIntensityMap;\n#endif\n#endif\n#ifdef USE_CLEARCOAT\nuniform float clearcoat;uniform float clearcoatRoughness;\n#endif\n#ifdef USE_IRIDESCENCE\nuniform float iridescence;uniform float iridescenceIOR;uniform float iridescenceThicknessMinimum;uniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\nuniform vec3 sheenColor;uniform float sheenRoughness;\n#ifdef USE_SHEEN_COLORMAP\nuniform sampler2D sheenColorMap;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\nuniform sampler2D sheenRoughnessMap;\n#endif\n#endif\n#ifdef USE_ANISOTROPY\nuniform vec2 anisotropyVector;\n#ifdef USE_ANISOTROPYMAP\nuniform sampler2D anisotropyMap;\n#endif\n#endif\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec4 diffuseColor=vec4(diffuse,opacity);ReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));vec3 totalEmissiveRadiance=emissive;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvec3 totalDiffuse=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse;vec3 totalSpecular=reflectedLight.directSpecular+reflectedLight.indirectSpecular;\n#include \nvec3 outgoingLight=totalDiffuse+totalSpecular+totalEmissiveRadiance;\n#ifdef USE_SHEEN\nfloat sheenEnergyComp=1.0-0.157*max3(material.sheenColor);outgoingLight=outgoingLight*sheenEnergyComp+sheenSpecularDirect+sheenSpecularIndirect;\n#endif\n#ifdef USE_CLEARCOAT\nfloat dotNVcc=saturate(dot(geometryClearcoatNormal,geometryViewDir));vec3 Fcc=F_Schlick(material.clearcoatF0,material.clearcoatF90,dotNVcc);outgoingLight=outgoingLight*(1.0-material.clearcoat*Fcc)+(clearcoatSpecularDirect+clearcoatSpecularIndirect)*material.clearcoat;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvViewPosition=-mvPosition.xyz;\n#include \n#include \n#include \n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;uniform vec3 emissive;uniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec4 diffuseColor=vec4(diffuse,opacity);ReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));vec3 totalEmissiveRadiance=emissive;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvec3 outgoingLight=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+totalEmissiveRadiance;\n#include \n#include \n#include \n#include \n#include \n#include \n}",points_vert:"uniform float size;uniform float scale;\n#include \n#include \n#include \n#include \n#include \n#include \n#ifdef USE_POINTS_UV\nvarying vec2 vUv;uniform mat3 uvTransform;\n#endif\nvoid main(){\n#ifdef USE_POINTS_UV\nvUv=(uvTransform*vec3(uv,1)).xy;\n#endif\n#include \n#include \n#include \n#include \n#include \ngl_PointSize=size;\n#ifdef USE_SIZEATTENUATION\nbool isPerspective=isPerspectiveMatrix(projectionMatrix);if(isPerspective)gl_PointSize*=(scale/-mvPosition.z);\n#endif\n#include \n#include \n#include \n#include \n}",points_frag:"uniform vec3 diffuse;uniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec3 outgoingLight=vec3(0.0);vec4 diffuseColor=vec4(diffuse,opacity);\n#include \n#include \n#include \n#include \n#include \noutgoingLight=diffuseColor.rgb;\n#include \n#include \n#include \n#include \n#include \n}",shadow_vert:"#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n}",shadow_frag:"uniform vec3 color;uniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \ngl_FragColor=vec4(color,opacity*(1.0-getShadowMask()));\n#include \n#include \n#include \n}",sprite_vert:"uniform float rotation;uniform vec2 center;\n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec4 mvPosition=modelViewMatrix*vec4(0.0,0.0,0.0,1.0);vec2 scale;scale.x=length(vec3(modelMatrix[0].x,modelMatrix[0].y,modelMatrix[0].z));scale.y=length(vec3(modelMatrix[1].x,modelMatrix[1].y,modelMatrix[1].z));\n#ifndef USE_SIZEATTENUATION\nbool isPerspective=isPerspectiveMatrix(projectionMatrix);if(isPerspective)scale*=-mvPosition.z;\n#endif\nvec2 alignedPosition=(position.xy-(center-vec2(0.5)))*scale;vec2 rotatedPosition;rotatedPosition.x=cos(rotation)*alignedPosition.x-sin(rotation)*alignedPosition.y;rotatedPosition.y=sin(rotation)*alignedPosition.x+cos(rotation)*alignedPosition.y;mvPosition.xy+=rotatedPosition;gl_Position=projectionMatrix*mvPosition;\n#include \n#include \n#include \n}",sprite_frag:"uniform vec3 diffuse;uniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){\n#include \nvec3 outgoingLight=vec3(0.0);vec4 diffuseColor=vec4(diffuse,opacity);\n#include \n#include \n#include \n#include \n#include \noutgoingLight=diffuseColor.rgb;\n#include \n#include \n#include \n#include \n}"},Gn={common:{diffuse:{value:new Oi(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new He},alphaMap:{value:null},alphaMapTransform:{value:new He},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new He}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new He}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new He}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new He},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new He},normalScale:{value:new Ge(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new He},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new He}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new He}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new He}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Oi(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Oi(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new He},alphaTest:{value:0},uvTransform:{value:new He}},sprite:{diffuse:{value:new Oi(16777215)},opacity:{value:1},center:{value:new Ge(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new He},alphaMap:{value:null},alphaMapTransform:{value:new He},alphaTest:{value:0}}},Hn={basic:{uniforms:wn([Gn.common,Gn.specularmap,Gn.envmap,Gn.aomap,Gn.lightmap,Gn.fog]),vertexShader:$n.meshbasic_vert,fragmentShader:$n.meshbasic_frag},lambert:{uniforms:wn([Gn.common,Gn.specularmap,Gn.envmap,Gn.aomap,Gn.lightmap,Gn.emissivemap,Gn.bumpmap,Gn.normalmap,Gn.displacementmap,Gn.fog,Gn.lights,{emissive:{value:new Oi(0)}}]),vertexShader:$n.meshlambert_vert,fragmentShader:$n.meshlambert_frag},phong:{uniforms:wn([Gn.common,Gn.specularmap,Gn.envmap,Gn.aomap,Gn.lightmap,Gn.emissivemap,Gn.bumpmap,Gn.normalmap,Gn.displacementmap,Gn.fog,Gn.lights,{emissive:{value:new Oi(0)},specular:{value:new Oi(1118481)},shininess:{value:30}}]),vertexShader:$n.meshphong_vert,fragmentShader:$n.meshphong_frag},standard:{uniforms:wn([Gn.common,Gn.envmap,Gn.aomap,Gn.lightmap,Gn.emissivemap,Gn.bumpmap,Gn.normalmap,Gn.displacementmap,Gn.roughnessmap,Gn.metalnessmap,Gn.fog,Gn.lights,{emissive:{value:new Oi(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:$n.meshphysical_vert,fragmentShader:$n.meshphysical_frag},toon:{uniforms:wn([Gn.common,Gn.aomap,Gn.lightmap,Gn.emissivemap,Gn.bumpmap,Gn.normalmap,Gn.displacementmap,Gn.gradientmap,Gn.fog,Gn.lights,{emissive:{value:new Oi(0)}}]),vertexShader:$n.meshtoon_vert,fragmentShader:$n.meshtoon_frag},matcap:{uniforms:wn([Gn.common,Gn.bumpmap,Gn.normalmap,Gn.displacementmap,Gn.fog,{matcap:{value:null}}]),vertexShader:$n.meshmatcap_vert,fragmentShader:$n.meshmatcap_frag},points:{uniforms:wn([Gn.points,Gn.fog]),vertexShader:$n.points_vert,fragmentShader:$n.points_frag},dashed:{uniforms:wn([Gn.common,Gn.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:$n.linedashed_vert,fragmentShader:$n.linedashed_frag},depth:{uniforms:wn([Gn.common,Gn.displacementmap]),vertexShader:$n.depth_vert,fragmentShader:$n.depth_frag},normal:{uniforms:wn([Gn.common,Gn.bumpmap,Gn.normalmap,Gn.displacementmap,{opacity:{value:1}}]),vertexShader:$n.meshnormal_vert,fragmentShader:$n.meshnormal_frag},sprite:{uniforms:wn([Gn.sprite,Gn.fog]),vertexShader:$n.sprite_vert,fragmentShader:$n.sprite_frag},background:{uniforms:{uvTransform:{value:new He},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:$n.background_vert,fragmentShader:$n.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1}},vertexShader:$n.backgroundCube_vert,fragmentShader:$n.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:$n.cube_vert,fragmentShader:$n.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:$n.equirect_vert,fragmentShader:$n.equirect_frag},distanceRGBA:{uniforms:wn([Gn.common,Gn.displacementmap,{referencePosition:{value:new _t},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:$n.distanceRGBA_vert,fragmentShader:$n.distanceRGBA_frag},shadow:{uniforms:wn([Gn.lights,Gn.fog,{color:{value:new Oi(0)},opacity:{value:1}}]),vertexShader:$n.shadow_vert,fragmentShader:$n.shadow_frag}};Hn.physical={uniforms:wn([Hn.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new He},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new He},clearcoatNormalScale:{value:new Ge(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new He},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new He},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new He},sheen:{value:0},sheenColor:{value:new Oi(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new He},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new He},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new He},transmissionSamplerSize:{value:new Ge},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new He},attenuationDistance:{value:0},attenuationColor:{value:new Oi(0)},specularColor:{value:new Oi(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new He},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new He},anisotropyVector:{value:new Ge},anisotropyMap:{value:null},anisotropyMapTransform:{value:new He}}]),vertexShader:$n.meshphysical_vert,fragmentShader:$n.meshphysical_frag};const jn={r:0,b:0,g:0};function Wn(e,t,i,n,a,o,l){const c=new Oi(0);let u,h,d=!0===o?0:1,f=null,m=0,p=null;function g(t,i){t.getRGB(jn,Sn(e)),n.buffers.color.setClear(jn.r,jn.g,jn.b,i,l)}return{getClearColor:function(){return c},setClearColor:function(e,t=1){c.set(e),d=t,g(c,d)},getClearAlpha:function(){return d},setClearAlpha:function(e){d=e,g(c,d)},render:function(o,_){let y=!1,v=!0===_.isScene?_.background:null;if(v&&v.isTexture){v=(_.backgroundBlurriness>0?i:t).get(v)}null===v?g(c,d):v&&v.isColor&&(g(v,1),y=!0);const b=e.xr.getEnvironmentBlendMode();"additive"===b?n.buffers.color.setClear(0,0,0,1,l):"alpha-blend"===b&&n.buffers.color.setClear(0,0,0,0,l),(e.autoClear||y)&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),v&&(v.isCubeTexture||v.mapping===N)?(void 0===h&&(h=new yn(new bn(1,1,1),new An({name:"BackgroundCubeMaterial",uniforms:xn(Hn.backgroundCube.uniforms),vertexShader:Hn.backgroundCube.vertexShader,fragmentShader:Hn.backgroundCube.fragmentShader,side:s,depthTest:!1,depthWrite:!1,fog:!1})),h.geometry.deleteAttribute("normal"),h.geometry.deleteAttribute("uv"),h.onBeforeRender=function(e,t,i){this.matrixWorld.copyPosition(i.matrixWorld)},Object.defineProperty(h.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),a.update(h)),h.material.uniforms.envMap.value=v,h.material.uniforms.flipEnvMap.value=v.isCubeTexture&&!1===v.isRenderTargetTexture?-1:1,h.material.uniforms.backgroundBlurriness.value=_.backgroundBlurriness,h.material.uniforms.backgroundIntensity.value=_.backgroundIntensity,h.material.toneMapped=tt.getTransfer(v.colorSpace)!==me,f===v&&m===v.version&&p===e.toneMapping||(h.material.needsUpdate=!0,f=v,m=v.version,p=e.toneMapping),h.layers.enableAll(),o.unshift(h,h.geometry,h.material,0,0,null)):v&&v.isTexture&&(void 0===u&&(u=new yn(new Vn(2,2),new An({name:"BackgroundMaterial",uniforms:xn(Hn.background.uniforms),vertexShader:Hn.background.vertexShader,fragmentShader:Hn.background.fragmentShader,side:r,depthTest:!1,depthWrite:!1,fog:!1})),u.geometry.deleteAttribute("normal"),Object.defineProperty(u.material,"map",{get:function(){return this.uniforms.t2D.value}}),a.update(u)),u.material.uniforms.t2D.value=v,u.material.uniforms.backgroundIntensity.value=_.backgroundIntensity,u.material.toneMapped=tt.getTransfer(v.colorSpace)!==me,!0===v.matrixAutoUpdate&&v.updateMatrix(),u.material.uniforms.uvTransform.value.copy(v.matrix),f===v&&m===v.version&&p===e.toneMapping||(u.material.needsUpdate=!0,f=v,m=v.version,p=e.toneMapping),u.layers.enableAll(),o.unshift(u,u.geometry,u.material,0,0,null))}}}function qn(e,t,i,n){const r=e.getParameter(34921),s=n.isWebGL2?null:t.get("OES_vertex_array_object"),a=n.isWebGL2||null!==s,o={},l=f(null);let c=l,u=!1;function h(t){return n.isWebGL2?e.bindVertexArray(t):s.bindVertexArrayOES(t)}function d(t){return n.isWebGL2?e.deleteVertexArray(t):s.deleteVertexArrayOES(t)}function f(e){const t=[],i=[],n=[];for(let e=0;e=0){const i=r[t];let n=s[t];if(void 0===n&&("instanceMatrix"===t&&e.instanceMatrix&&(n=e.instanceMatrix),"instanceColor"===t&&e.instanceColor&&(n=e.instanceColor)),void 0===i)return!0;if(i.attribute!==n)return!0;if(n&&i.data!==n.data)return!0;a++}}return c.attributesNum!==a||c.index!==n}(r,v,d,b),x&&function(e,t,i,n){const r={},s=t.attributes;let a=0;const o=i.getAttributes();for(const t in o){if(o[t].location>=0){let i=s[t];void 0===i&&("instanceMatrix"===t&&e.instanceMatrix&&(i=e.instanceMatrix),"instanceColor"===t&&e.instanceColor&&(i=e.instanceColor));const n={};n.attribute=i,i&&i.data&&(n.data=i.data),r[t]=n,a++}}c.attributes=r,c.attributesNum=a,c.index=n}(r,v,d,b)}else{const e=!0===l.wireframe;c.geometry===v.id&&c.program===d.id&&c.wireframe===e||(c.geometry=v.id,c.program=d.id,c.wireframe=e,x=!0)}null!==b&&i.update(b,34963),(x||u)&&(u=!1,function(r,s,a,o){if(!1===n.isWebGL2&&(r.isInstancedMesh||o.isInstancedBufferGeometry)&&null===t.get("ANGLE_instanced_arrays"))return;m();const l=o.attributes,c=a.getAttributes(),u=s.defaultAttributeValues;for(const t in c){const s=c[t];if(s.location>=0){let a=l[t];if(void 0===a&&("instanceMatrix"===t&&r.instanceMatrix&&(a=r.instanceMatrix),"instanceColor"===t&&r.instanceColor&&(a=r.instanceColor)),void 0!==a){const t=a.normalized,l=a.itemSize,c=i.get(a);if(void 0===c)continue;const u=c.buffer,h=c.type,d=c.bytesPerElement,f=!0===n.isWebGL2&&(5124===h||5125===h||a.gpuType===X);if(a.isInterleavedBufferAttribute){const i=a.data,n=i.stride,c=a.offset;if(i.isInstancedInterleavedBuffer){for(let e=0;e0&&e.getShaderPrecisionFormat(35632,36338).precision>0)return"highp";t="mediump"}return"mediump"===t&&e.getShaderPrecisionFormat(35633,36337).precision>0&&e.getShaderPrecisionFormat(35632,36337).precision>0?"mediump":"lowp"}const s="undefined"!=typeof WebGL2RenderingContext&&"WebGL2RenderingContext"===e.constructor.name;let a=void 0!==i.precision?i.precision:"highp";const o=r(a);o!==a&&(console.warn("THREE.WebGLRenderer:",a,"not supported, using",o,"instead."),a=o);const l=s||t.has("WEBGL_draw_buffers"),c=!0===i.logarithmicDepthBuffer,u=e.getParameter(34930),h=e.getParameter(35660),d=e.getParameter(3379),f=e.getParameter(34076),m=e.getParameter(34921),p=e.getParameter(36347),g=e.getParameter(36348),_=e.getParameter(36349),y=h>0,v=s||t.has("OES_texture_float");return{isWebGL2:s,drawBuffers:l,getMaxAnisotropy:function(){if(void 0!==n)return n;if(!0===t.has("EXT_texture_filter_anisotropic")){const i=t.get("EXT_texture_filter_anisotropic");n=e.getParameter(i.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else n=0;return n},getMaxPrecision:r,precision:a,logarithmicDepthBuffer:c,maxTextures:u,maxVertexTextures:h,maxTextureSize:d,maxCubemapSize:f,maxAttributes:m,maxVertexUniforms:p,maxVaryings:g,maxFragmentUniforms:_,vertexTextures:y,floatFragmentTextures:v,floatVertexTextures:y&&v,maxSamples:s?e.getParameter(36183):0}}function Kn(e){const t=this;let i=null,n=0,r=!1,s=!1;const a=new On,o=new He,l={value:null,needsUpdate:!1};function c(e,i,n,r){const s=null!==e?e.length:0;let c=null;if(0!==s){if(c=l.value,!0!==r||null===c){const t=n+4*s,r=i.matrixWorldInverse;o.getNormalMatrix(r),(null===c||c.length0);t.numPlanes=n,t.numIntersection=0}();else{const e=s?0:n,t=4*e;let r=m.clippingState||null;l.value=r,r=c(h,o,t,u);for(let e=0;e!==t;++e)r[e]=i[e];m.clippingState=r,this.numIntersection=d?this.numPlanes:0,this.numPlanes+=e}}}function Zn(e){let t=new WeakMap;function i(e,t){return 303===t?e.mapping=k:304===t&&(e.mapping=O),e}function n(e){const i=e.target;i.removeEventListener("dispose",n);const r=t.get(i);void 0!==r&&(t.delete(i),r.dispose())}return{get:function(r){if(r&&r.isTexture&&!1===r.isRenderTargetTexture){const s=r.mapping;if(303===s||304===s){if(t.has(r)){return i(t.get(r).texture,r.mapping)}{const s=r.image;if(s&&s.height>0){const a=new Dn(s.height/2);return a.fromEquirectangularTexture(e,r),t.set(r,a),r.addEventListener("dispose",n),i(a.texture,r.mapping)}return null}}}return r},dispose:function(){t=new WeakMap}}}class Qn extends Cn{constructor(e=-1,t=1,i=1,n=-1,r=.1,s=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=i,this.bottom=n,this.near=r,this.far=s,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=null===e.view?null:Object.assign({},e.view),this}setViewOffset(e,t,i,n,r,s){null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=i,this.view.offsetY=n,this.view.width=r,this.view.height=s,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,n=(this.top+this.bottom)/2;let r=i-e,s=i+e,a=n+t,o=n-t;if(null!==this.view&&this.view.enabled){const e=(this.right-this.left)/this.view.fullWidth/this.zoom,t=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=e*this.view.offsetX,s=r+e*this.view.width,a-=t*this.view.offsetY,o=a-t*this.view.height}this.projectionMatrix.makeOrthographic(r,s,a,o,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,null!==this.view&&(t.object.view=Object.assign({},this.view)),t}}const Jn=[.125,.215,.35,.446,.526,.582],er=20,tr=new Qn,ir=new Oi;let nr=null,rr=0,sr=0;const ar=(1+Math.sqrt(5))/2,or=1/ar,lr=[new _t(1,1,1),new _t(-1,1,1),new _t(1,1,-1),new _t(-1,1,-1),new _t(0,ar,or),new _t(0,ar,-or),new _t(or,0,ar),new _t(-or,0,ar),new _t(ar,or,0),new _t(-ar,or,0)];class cr{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(e,t=0,i=.1,n=100){nr=this._renderer.getRenderTarget(),rr=this._renderer.getActiveCubeFace(),sr=this._renderer.getActiveMipmapLevel(),this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(e,i,n,r),t>0&&this._blur(r,0,0,t),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=fr(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=dr(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose()}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?o=Jn[a-e+4-1]:0===a&&(o=0),n.push(o);const l=1/(s-2),c=-l,u=1+l,h=[c,c,u,c,u,u,c,c,u,u,c,u],d=6,f=6,m=3,p=2,g=1,_=new Float32Array(m*f*d),y=new Float32Array(p*f*d),v=new Float32Array(g*f*d);for(let e=0;e2?0:-1,n=[t,i,0,t+2/3,i,0,t+2/3,i+1,0,t,i,0,t+2/3,i+1,0,t,i+1,0];_.set(n,m*f*e),y.set(h,p*f*e);const r=[e,e,e,e,e,e];v.set(r,g*f*e)}const b=new Ji;b.setAttribute("position",new $i(_,m)),b.setAttribute("uv",new $i(y,p)),b.setAttribute("faceIndex",new $i(v,g)),t.push(b),r>4&&r--}return{lodPlanes:t,sizeLods:i,sigmas:n}}(n)),this._blurMaterial=function(e,t,i){const n=new Float32Array(er),r=new _t(0,1,0),s=new An({name:"SphericalGaussianBlur",defines:{n:er,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/i,CUBEUV_MAX_MIP:`${e}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:n},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:r}},vertexShader:mr(),fragmentShader:"precision mediump float;precision mediump int;varying vec3 vOutputDirection;uniform sampler2D envMap;uniform int samples;uniform float weights[n];uniform bool latitudinal;uniform float dTheta;uniform float mipInt;uniform vec3 poleAxis;\n#define ENVMAP_TYPE_CUBE_UV\n#include \nvec3 getSample(float theta,vec3 axis){float cosTheta=cos(theta);vec3 sampleDirection=vOutputDirection*cosTheta+cross(axis,vOutputDirection)*sin(theta)+axis*dot(axis,vOutputDirection)*(1.0-cosTheta);return bilinearCubeUV(envMap,sampleDirection,mipInt);}void main(){vec3 axis=latitudinal?poleAxis:cross(poleAxis,vOutputDirection);if(all(equal(axis,vec3(0.0)))){axis=vec3(vOutputDirection.z,0.0,-vOutputDirection.x);}axis=normalize(axis);gl_FragColor=vec4(0.0,0.0,0.0,1.0);gl_FragColor.rgb+=weights[0]*getSample(0.0,axis);for(int i=1;i=samples){break;}float theta=dTheta*float(i);gl_FragColor.rgb+=weights[i]*getSample(-1.0*theta,axis);gl_FragColor.rgb+=weights[i]*getSample(theta,axis);}}",blending:0,depthTest:!1,depthWrite:!1});return s}(n,e,t)}return n}_compileMaterial(e){const t=new yn(this._lodPlanes[0],e);this._renderer.compile(t,tr)}_sceneToCubeUV(e,t,i,n){const r=new Tn(90,1,t,i),a=[1,-1,1,1,1,1],o=[1,1,1,-1,-1,-1],l=this._renderer,c=l.autoClear,u=l.toneMapping;l.getClearColor(ir),l.toneMapping=P,l.autoClear=!1;const h=new zi({name:"PMREM.Background",side:s,depthWrite:!1,depthTest:!1}),d=new yn(new bn,h);let f=!1;const m=e.background;m?m.isColor&&(h.color.copy(m),e.background=null,f=!0):(h.color.copy(ir),f=!0);for(let t=0;t<6;t++){const i=t%3;0===i?(r.up.set(0,a[t],0),r.lookAt(o[t],0,0)):1===i?(r.up.set(0,0,a[t]),r.lookAt(0,o[t],0)):(r.up.set(0,a[t],0),r.lookAt(0,0,o[t]));const s=this._cubeSize;hr(n,i*s,t>2?s:0,s,s),l.setRenderTarget(n),f&&l.render(d,r),l.render(e,r)}d.geometry.dispose(),d.material.dispose(),l.toneMapping=u,l.autoClear=c,e.background=m}_textureToCubeUV(e,t){const i=this._renderer,n=e.mapping===k||e.mapping===O;n?(null===this._cubemapMaterial&&(this._cubemapMaterial=fr()),this._cubemapMaterial.uniforms.flipEnvMap.value=!1===e.isRenderTargetTexture?-1:1):null===this._equirectMaterial&&(this._equirectMaterial=dr());const r=n?this._cubemapMaterial:this._equirectMaterial,s=new yn(this._lodPlanes[0],r);r.uniforms.envMap.value=e;const a=this._cubeSize;hr(t,0,0,3*a,2*a),i.setRenderTarget(t),i.render(s,tr)}_applyPMREM(e){const t=this._renderer,i=t.autoClear;t.autoClear=!1;for(let t=1;ter&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const p=[];let g=0;for(let e=0;e_-4?n-_+4:0),4*(this._cubeSize-y),3*y,2*y),o.setRenderTarget(t),o.render(c,tr)}}function ur(e,t,i){const n=new ft(e,t,i);return n.texture.mapping=N,n.texture.name="PMREM.cubeUv",n.scissorTest=!0,n}function hr(e,t,i,n,r){e.viewport.set(t,i,n,r),e.scissor.set(t,i,n,r)}function dr(){return new An({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:mr(),fragmentShader:"precision mediump float;precision mediump int;varying vec3 vOutputDirection;uniform sampler2D envMap;\n#include \nvoid main(){vec3 outputDirection=normalize(vOutputDirection);vec2 uv=equirectUv(outputDirection);gl_FragColor=vec4(texture2D(envMap,uv).rgb,1.0);}",blending:0,depthTest:!1,depthWrite:!1})}function fr(){return new An({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:mr(),fragmentShader:"precision mediump float;precision mediump int;uniform float flipEnvMap;varying vec3 vOutputDirection;uniform samplerCube envMap;void main(){gl_FragColor=textureCube(envMap,vec3(flipEnvMap*vOutputDirection.x,vOutputDirection.yz));}",blending:0,depthTest:!1,depthWrite:!1})}function mr(){return"precision mediump float;precision mediump int;attribute float faceIndex;varying vec3 vOutputDirection;vec3 getDirection(vec2 uv,float face){uv=2.0*uv-1.0;vec3 direction=vec3(uv,1.0);if(face==0.0){direction=direction.zyx;}else if(face==1.0){direction=direction.xzy;direction.xz*=-1.0;}else if(face==2.0){direction.x*=-1.0;}else if(face==3.0){direction=direction.zyx;direction.xz*=-1.0;}else if(face==4.0){direction=direction.xzy;direction.xy*=-1.0;}else if(face==5.0){direction.z*=-1.0;}return direction;}void main(){vOutputDirection=getDirection(uv,faceIndex);gl_Position=vec4(position,1.0);}"}function pr(e){let t=new WeakMap,i=null;function n(e){const i=e.target;i.removeEventListener("dispose",n);const r=t.get(i);void 0!==r&&(t.delete(i),r.dispose())}return{get:function(r){if(r&&r.isTexture){const s=r.mapping,a=303===s||304===s,o=s===k||s===O;if(a||o){if(r.isRenderTargetTexture&&!0===r.needsPMREMUpdate){r.needsPMREMUpdate=!1;let n=t.get(r);return null===i&&(i=new cr(e)),n=a?i.fromEquirectangular(r,n):i.fromCubemap(r,n),t.set(r,n),n.texture}if(t.has(r))return t.get(r).texture;{const s=r.image;if(a&&s&&s.height>0||o&&s&&function(e){let t=0;const i=6;for(let n=0;nt.maxTextureSize&&(A=Math.ceil(M/t.maxTextureSize),M=t.maxTextureSize);const C=new Float32Array(M*A*4*f),T=new mt(C,M,A,f);T.type=K,T.needsUpdate=!0;const P=4*S;for(let I=0;I0)return e;const r=t*i;let s=Pr[r];if(void 0===s&&(s=new Float32Array(r),Pr[r]=s),0!==t){n.toArray(s,0);for(let n=1,r=0;n!==t;++n)r+=i,e[n].toArray(s,r)}return s}function kr(e,t){if(e.length!==t.length)return!1;for(let i=0,n=e.length;i":" "} ${r}: ${i[e]}`)}return n.join("\n")}(e.getShaderSource(t),n)}return r}function Rs(e,t){const i=function(e){const t=tt.getPrimaries(tt.workingColorSpace),i=tt.getPrimaries(e);let n;switch(t===i?n="":t===ge&&i===pe?n="LinearDisplayP3ToLinearSRGB":t===pe&&i===ge&&(n="LinearSRGBToLinearDisplayP3"),e){case ue:case de:return[n,"LinearTransferOETF"];case ce:case he:return[n,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space:",e),[n,"LinearTransferOETF"]}}(t);return`vec4 ${e}( vec4 value ) { return ${i[0]}( ${i[1]}( value ) ); }`}function Ls(e,t){let i;switch(t){case E:i="Linear";break;case I:i="Reinhard";break;case D:i="OptimizedCineon";break;case R:i="ACESFilmic";break;case L:i="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",t),i="Linear"}return"vec3 "+e+"( vec3 color ) { return "+i+"ToneMapping( color ); }"}function ks(e){return""!==e}function Os(e,t){const i=t.numSpotLightShadows+t.numSpotLightMaps-t.numSpotLightShadowsWithMaps;return e.replace(/NUM_DIR_LIGHTS/g,t.numDirLights).replace(/NUM_SPOT_LIGHTS/g,t.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,t.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,i).replace(/NUM_RECT_AREA_LIGHTS/g,t.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,t.numPointLights).replace(/NUM_HEMI_LIGHTS/g,t.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,t.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,t.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,t.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,t.numPointLightShadows)}function Ns(e,t){return e.replace(/NUM_CLIPPING_PLANES/g,t.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,t.numClippingPlanes-t.numClipIntersection)}const Fs=/^[ \t]*#include +<([\w\d./]+)>/gm;function Bs(e){return e.replace(Fs,Us)}const zs=new Map([["encodings_fragment","colorspace_fragment"],["encodings_pars_fragment","colorspace_pars_fragment"],["output_fragment","opaque_fragment"]]);function Us(e,t){let i=$n[t];if(void 0===i){const e=zs.get(t);if(void 0===e)throw new Error("Can not resolve #include <"+t+">");i=$n[e],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',t,e)}return Bs(i)}const Vs=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function $s(e){return e.replace(Vs,Gs)}function Gs(e,t,i,n){let r="";for(let e=parseInt(t);e0&&(v+="\n"),b=[g,"#define SHADER_TYPE "+s.shaderType,"#define SHADER_NAME "+s.shaderName,_].filter(ks).join("\n"),b.length>0&&(b+="\n")):(v=[Hs(s),"#define SHADER_TYPE "+s.shaderType,"#define SHADER_NAME "+s.shaderName,_,s.instancing?"#define USE_INSTANCING":"",s.instancingColor?"#define USE_INSTANCING_COLOR":"",s.useFog&&s.fog?"#define USE_FOG":"",s.useFog&&s.fogExp2?"#define FOG_EXP2":"",s.map?"#define USE_MAP":"",s.envMap?"#define USE_ENVMAP":"",s.envMap?"#define "+f:"",s.lightMap?"#define USE_LIGHTMAP":"",s.aoMap?"#define USE_AOMAP":"",s.bumpMap?"#define USE_BUMPMAP":"",s.normalMap?"#define USE_NORMALMAP":"",s.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",s.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",s.displacementMap?"#define USE_DISPLACEMENTMAP":"",s.emissiveMap?"#define USE_EMISSIVEMAP":"",s.anisotropy?"#define USE_ANISOTROPY":"",s.anisotropyMap?"#define USE_ANISOTROPYMAP":"",s.clearcoatMap?"#define USE_CLEARCOATMAP":"",s.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",s.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",s.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",s.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",s.specularMap?"#define USE_SPECULARMAP":"",s.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",s.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",s.roughnessMap?"#define USE_ROUGHNESSMAP":"",s.metalnessMap?"#define USE_METALNESSMAP":"",s.alphaMap?"#define USE_ALPHAMAP":"",s.alphaHash?"#define USE_ALPHAHASH":"",s.transmission?"#define USE_TRANSMISSION":"",s.transmissionMap?"#define USE_TRANSMISSIONMAP":"",s.thicknessMap?"#define USE_THICKNESSMAP":"",s.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",s.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",s.mapUv?"#define MAP_UV "+s.mapUv:"",s.alphaMapUv?"#define ALPHAMAP_UV "+s.alphaMapUv:"",s.lightMapUv?"#define LIGHTMAP_UV "+s.lightMapUv:"",s.aoMapUv?"#define AOMAP_UV "+s.aoMapUv:"",s.emissiveMapUv?"#define EMISSIVEMAP_UV "+s.emissiveMapUv:"",s.bumpMapUv?"#define BUMPMAP_UV "+s.bumpMapUv:"",s.normalMapUv?"#define NORMALMAP_UV "+s.normalMapUv:"",s.displacementMapUv?"#define DISPLACEMENTMAP_UV "+s.displacementMapUv:"",s.metalnessMapUv?"#define METALNESSMAP_UV "+s.metalnessMapUv:"",s.roughnessMapUv?"#define ROUGHNESSMAP_UV "+s.roughnessMapUv:"",s.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+s.anisotropyMapUv:"",s.clearcoatMapUv?"#define CLEARCOATMAP_UV "+s.clearcoatMapUv:"",s.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+s.clearcoatNormalMapUv:"",s.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+s.clearcoatRoughnessMapUv:"",s.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+s.iridescenceMapUv:"",s.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+s.iridescenceThicknessMapUv:"",s.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+s.sheenColorMapUv:"",s.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+s.sheenRoughnessMapUv:"",s.specularMapUv?"#define SPECULARMAP_UV "+s.specularMapUv:"",s.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+s.specularColorMapUv:"",s.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+s.specularIntensityMapUv:"",s.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+s.transmissionMapUv:"",s.thicknessMapUv?"#define THICKNESSMAP_UV "+s.thicknessMapUv:"",s.vertexTangents&&!1===s.flatShading?"#define USE_TANGENT":"",s.vertexColors?"#define USE_COLOR":"",s.vertexAlphas?"#define USE_COLOR_ALPHA":"",s.vertexUv1s?"#define USE_UV1":"",s.vertexUv2s?"#define USE_UV2":"",s.vertexUv3s?"#define USE_UV3":"",s.pointsUvs?"#define USE_POINTS_UV":"",s.flatShading?"#define FLAT_SHADED":"",s.skinning?"#define USE_SKINNING":"",s.morphTargets?"#define USE_MORPHTARGETS":"",s.morphNormals&&!1===s.flatShading?"#define USE_MORPHNORMALS":"",s.morphColors&&s.isWebGL2?"#define USE_MORPHCOLORS":"",s.morphTargetsCount>0&&s.isWebGL2?"#define MORPHTARGETS_TEXTURE":"",s.morphTargetsCount>0&&s.isWebGL2?"#define MORPHTARGETS_TEXTURE_STRIDE "+s.morphTextureStride:"",s.morphTargetsCount>0&&s.isWebGL2?"#define MORPHTARGETS_COUNT "+s.morphTargetsCount:"",s.doubleSided?"#define DOUBLE_SIDED":"",s.flipSided?"#define FLIP_SIDED":"",s.shadowMapEnabled?"#define USE_SHADOWMAP":"",s.shadowMapEnabled?"#define "+h:"",s.sizeAttenuation?"#define USE_SIZEATTENUATION":"",s.numLightProbes>0?"#define USE_LIGHT_PROBES":"",s.useLegacyLights?"#define LEGACY_LIGHTS":"",s.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",s.logarithmicDepthBuffer&&s.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING","\tattribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR","\tattribute vec3 instanceColor;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1","\tattribute vec2 uv1;","#endif","#ifdef USE_UV2","\tattribute vec2 uv2;","#endif","#ifdef USE_UV3","\tattribute vec2 uv3;","#endif","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )","\tattribute vec4 color;","#elif defined( USE_COLOR )","\tattribute vec3 color;","#endif","#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )","\tattribute vec3 morphTarget0;","\tattribute vec3 morphTarget1;","\tattribute vec3 morphTarget2;","\tattribute vec3 morphTarget3;","\t#ifdef USE_MORPHNORMALS","\t\tattribute vec3 morphNormal0;","\t\tattribute vec3 morphNormal1;","\t\tattribute vec3 morphNormal2;","\t\tattribute vec3 morphNormal3;","\t#else","\t\tattribute vec3 morphTarget4;","\t\tattribute vec3 morphTarget5;","\t\tattribute vec3 morphTarget6;","\t\tattribute vec3 morphTarget7;","\t#endif","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(ks).join("\n"),b=[g,Hs(s),"#define SHADER_TYPE "+s.shaderType,"#define SHADER_NAME "+s.shaderName,_,s.useFog&&s.fog?"#define USE_FOG":"",s.useFog&&s.fogExp2?"#define FOG_EXP2":"",s.map?"#define USE_MAP":"",s.matcap?"#define USE_MATCAP":"",s.envMap?"#define USE_ENVMAP":"",s.envMap?"#define "+d:"",s.envMap?"#define "+f:"",s.envMap?"#define "+m:"",p?"#define CUBEUV_TEXEL_WIDTH "+p.texelWidth:"",p?"#define CUBEUV_TEXEL_HEIGHT "+p.texelHeight:"",p?"#define CUBEUV_MAX_MIP "+p.maxMip+".0":"",s.lightMap?"#define USE_LIGHTMAP":"",s.aoMap?"#define USE_AOMAP":"",s.bumpMap?"#define USE_BUMPMAP":"",s.normalMap?"#define USE_NORMALMAP":"",s.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",s.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",s.emissiveMap?"#define USE_EMISSIVEMAP":"",s.anisotropy?"#define USE_ANISOTROPY":"",s.anisotropyMap?"#define USE_ANISOTROPYMAP":"",s.clearcoat?"#define USE_CLEARCOAT":"",s.clearcoatMap?"#define USE_CLEARCOATMAP":"",s.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",s.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",s.iridescence?"#define USE_IRIDESCENCE":"",s.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",s.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",s.specularMap?"#define USE_SPECULARMAP":"",s.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",s.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",s.roughnessMap?"#define USE_ROUGHNESSMAP":"",s.metalnessMap?"#define USE_METALNESSMAP":"",s.alphaMap?"#define USE_ALPHAMAP":"",s.alphaTest?"#define USE_ALPHATEST":"",s.alphaHash?"#define USE_ALPHAHASH":"",s.sheen?"#define USE_SHEEN":"",s.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",s.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",s.transmission?"#define USE_TRANSMISSION":"",s.transmissionMap?"#define USE_TRANSMISSIONMAP":"",s.thicknessMap?"#define USE_THICKNESSMAP":"",s.vertexTangents&&!1===s.flatShading?"#define USE_TANGENT":"",s.vertexColors||s.instancingColor?"#define USE_COLOR":"",s.vertexAlphas?"#define USE_COLOR_ALPHA":"",s.vertexUv1s?"#define USE_UV1":"",s.vertexUv2s?"#define USE_UV2":"",s.vertexUv3s?"#define USE_UV3":"",s.pointsUvs?"#define USE_POINTS_UV":"",s.gradientMap?"#define USE_GRADIENTMAP":"",s.flatShading?"#define FLAT_SHADED":"",s.doubleSided?"#define DOUBLE_SIDED":"",s.flipSided?"#define FLIP_SIDED":"",s.shadowMapEnabled?"#define USE_SHADOWMAP":"",s.shadowMapEnabled?"#define "+h:"",s.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",s.numLightProbes>0?"#define USE_LIGHT_PROBES":"",s.useLegacyLights?"#define LEGACY_LIGHTS":"",s.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",s.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",s.logarithmicDepthBuffer&&s.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",s.toneMapping!==P?"#define TONE_MAPPING":"",s.toneMapping!==P?$n.tonemapping_pars_fragment:"",s.toneMapping!==P?Ls("toneMapping",s.toneMapping):"",s.dithering?"#define DITHERING":"",s.opaque?"#define OPAQUE":"",$n.colorspace_pars_fragment,Rs("linearToOutputTexel",s.outputColorSpace),s.useDepthPacking?"#define DEPTH_PACKING "+s.depthPacking:"","\n"].filter(ks).join("\n")),c=Bs(c),c=Os(c,s),c=Ns(c,s),u=Bs(u),u=Os(u,s),u=Ns(u,s),c=$s(c),u=$s(u),s.isWebGL2&&!0!==s.isRawShaderMaterial&&(x="#version 300 es\n",v=["precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+v,b=["precision mediump sampler2DArray;","#define varying in",s.glslVersion===Pe?"":"layout(location = 0) out highp vec4 pc_fragColor;",s.glslVersion===Pe?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+b);const w=x+b+u,S=Ps(o,35633,x+v+c),M=Ps(o,35632,w);function E(t){if(e.debug.checkShaderErrors){const i=o.getProgramInfoLog(y).trim(),n=o.getShaderInfoLog(S).trim(),r=o.getShaderInfoLog(M).trim();let s=!0,a=!0;if(!1===o.getProgramParameter(y,35714))if(s=!1,"function"==typeof e.debug.onShaderError)e.debug.onShaderError(o,y,S,M);else{const e=Ds(o,S,"vertex"),t=Ds(o,M,"fragment");console.error("THREE.WebGLProgram: Shader Error "+o.getError()+" - VALIDATE_STATUS "+o.getProgramParameter(y,35715)+"\n\nProgram Info Log: "+i+"\n"+e+"\n"+t)}else""!==i?console.warn("THREE.WebGLProgram: Program Info Log:",i):""!==n&&""!==r||(a=!1);a&&(t.diagnostics={runnable:s,programLog:i,vertexShader:{log:n,prefix:v},fragmentShader:{log:r,prefix:b}})}o.deleteShader(S),o.deleteShader(M),I=new Ts(o,y),D=function(e,t){const i={},n=e.getProgramParameter(t,35721);for(let r=0;r0,X=a.clearcoat>0,Y=a.iridescence>0,K=a.sheen>0,Z=a.transmission>0,Q=q&&!!a.anisotropyMap,J=X&&!!a.clearcoatMap,ee=X&&!!a.clearcoatNormalMap,te=X&&!!a.clearcoatRoughnessMap,ie=Y&&!!a.iridescenceMap,ne=Y&&!!a.iridescenceThicknessMap,re=K&&!!a.sheenColorMap,se=K&&!!a.sheenRoughnessMap,ae=!!a.specularMap,oe=!!a.specularColorMap,le=!!a.specularIntensityMap,ce=Z&&!!a.transmissionMap,he=Z&&!!a.thicknessMap,de=!!a.gradientMap,fe=!!a.alphaMap,pe=a.alphaTest>0,ge=!!a.alphaHash,_e=!!a.extensions,ye=!!b.attributes.uv1,ve=!!b.attributes.uv2,be=!!b.attributes.uv3;let xe=P;return a.toneMapped&&(null!==L&&!0!==L.isXRRenderTarget||(xe=e.toneMapping)),{isWebGL2:h,shaderID:M,shaderType:a.type,shaderName:a.name,vertexShader:T,fragmentShader:E,defines:a.defines,customVertexShaderID:I,customFragmentShaderID:D,isRawShaderMaterial:!0===a.isRawShaderMaterial,glslVersion:a.glslVersion,precision:m,instancing:k,instancingColor:k&&null!==y.instanceColor,supportsVertexTextures:f,outputColorSpace:null===L?e.outputColorSpace:!0===L.isXRRenderTarget?L.texture.colorSpace:ue,map:O,matcap:F,envMap:B,envMapMode:B&&w.mapping,envMapCubeUVHeight:S,aoMap:z,lightMap:U,bumpMap:V,normalMap:$,displacementMap:f&&G,emissiveMap:H,normalMapObjectSpace:$&&1===a.normalMapType,normalMapTangentSpace:$&&0===a.normalMapType,metalnessMap:j,roughnessMap:W,anisotropy:q,anisotropyMap:Q,clearcoat:X,clearcoatMap:J,clearcoatNormalMap:ee,clearcoatRoughnessMap:te,iridescence:Y,iridescenceMap:ie,iridescenceThicknessMap:ne,sheen:K,sheenColorMap:re,sheenRoughnessMap:se,specularMap:ae,specularColorMap:oe,specularIntensityMap:le,transmission:Z,transmissionMap:ce,thicknessMap:he,gradientMap:de,opaque:!1===a.transparent&&1===a.blending,alphaMap:fe,alphaTest:pe,alphaHash:ge,combine:a.combine,mapUv:O&&g(a.map.channel),aoMapUv:z&&g(a.aoMap.channel),lightMapUv:U&&g(a.lightMap.channel),bumpMapUv:V&&g(a.bumpMap.channel),normalMapUv:$&&g(a.normalMap.channel),displacementMapUv:G&&g(a.displacementMap.channel),emissiveMapUv:H&&g(a.emissiveMap.channel),metalnessMapUv:j&&g(a.metalnessMap.channel),roughnessMapUv:W&&g(a.roughnessMap.channel),anisotropyMapUv:Q&&g(a.anisotropyMap.channel),clearcoatMapUv:J&&g(a.clearcoatMap.channel),clearcoatNormalMapUv:ee&&g(a.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:te&&g(a.clearcoatRoughnessMap.channel),iridescenceMapUv:ie&&g(a.iridescenceMap.channel),iridescenceThicknessMapUv:ne&&g(a.iridescenceThicknessMap.channel),sheenColorMapUv:re&&g(a.sheenColorMap.channel),sheenRoughnessMapUv:se&&g(a.sheenRoughnessMap.channel),specularMapUv:ae&&g(a.specularMap.channel),specularColorMapUv:oe&&g(a.specularColorMap.channel),specularIntensityMapUv:le&&g(a.specularIntensityMap.channel),transmissionMapUv:ce&&g(a.transmissionMap.channel),thicknessMapUv:he&&g(a.thicknessMap.channel),alphaMapUv:fe&&g(a.alphaMap.channel),vertexTangents:!!b.attributes.tangent&&($||q),vertexColors:a.vertexColors,vertexAlphas:!0===a.vertexColors&&!!b.attributes.color&&4===b.attributes.color.itemSize,vertexUv1s:ye,vertexUv2s:ve,vertexUv3s:be,pointsUvs:!0===y.isPoints&&!!b.attributes.uv&&(O||fe),fog:!!v,useFog:!0===a.fog,fogExp2:v&&v.isFogExp2,flatShading:!0===a.flatShading,sizeAttenuation:!0===a.sizeAttenuation,logarithmicDepthBuffer:d,skinning:!0===y.isSkinnedMesh,morphTargets:void 0!==b.morphAttributes.position,morphNormals:void 0!==b.morphAttributes.normal,morphColors:void 0!==b.morphAttributes.color,morphTargetsCount:C,morphTextureStride:R,numDirLights:l.directional.length,numPointLights:l.point.length,numSpotLights:l.spot.length,numSpotLightMaps:l.spotLightMap.length,numRectAreaLights:l.rectArea.length,numHemiLights:l.hemi.length,numDirLightShadows:l.directionalShadowMap.length,numPointLightShadows:l.pointShadowMap.length,numSpotLightShadows:l.spotShadowMap.length,numSpotLightShadowsWithMaps:l.numSpotLightShadowsWithMaps,numLightProbes:l.numLightProbes,numClippingPlanes:o.numPlanes,numClipIntersection:o.numIntersection,dithering:a.dithering,shadowMapEnabled:e.shadowMap.enabled&&u.length>0,shadowMapType:e.shadowMap.type,toneMapping:xe,useLegacyLights:e._useLegacyLights,decodeVideoTexture:O&&!0===a.map.isVideoTexture&&tt.getTransfer(a.map.colorSpace)===me,premultipliedAlpha:a.premultipliedAlpha,doubleSided:2===a.side,flipSided:a.side===s,useDepthPacking:a.depthPacking>=0,depthPacking:a.depthPacking||0,index0AttributeName:a.index0AttributeName,extensionDerivatives:_e&&!0===a.extensions.derivatives,extensionFragDepth:_e&&!0===a.extensions.fragDepth,extensionDrawBuffers:_e&&!0===a.extensions.drawBuffers,extensionShaderTextureLOD:_e&&!0===a.extensions.shaderTextureLOD,rendererExtensionFragDepth:h||n.has("EXT_frag_depth"),rendererExtensionDrawBuffers:h||n.has("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:h||n.has("EXT_shader_texture_lod"),rendererExtensionParallelShaderCompile:n.has("KHR_parallel_shader_compile"),customProgramCacheKey:a.customProgramCacheKey()}},getProgramCacheKey:function(t){const i=[];if(t.shaderID?i.push(t.shaderID):(i.push(t.customVertexShaderID),i.push(t.customFragmentShaderID)),void 0!==t.defines)for(const e in t.defines)i.push(e),i.push(t.defines[e]);return!1===t.isRawShaderMaterial&&(!function(e,t){e.push(t.precision),e.push(t.outputColorSpace),e.push(t.envMapMode),e.push(t.envMapCubeUVHeight),e.push(t.mapUv),e.push(t.alphaMapUv),e.push(t.lightMapUv),e.push(t.aoMapUv),e.push(t.bumpMapUv),e.push(t.normalMapUv),e.push(t.displacementMapUv),e.push(t.emissiveMapUv),e.push(t.metalnessMapUv),e.push(t.roughnessMapUv),e.push(t.anisotropyMapUv),e.push(t.clearcoatMapUv),e.push(t.clearcoatNormalMapUv),e.push(t.clearcoatRoughnessMapUv),e.push(t.iridescenceMapUv),e.push(t.iridescenceThicknessMapUv),e.push(t.sheenColorMapUv),e.push(t.sheenRoughnessMapUv),e.push(t.specularMapUv),e.push(t.specularColorMapUv),e.push(t.specularIntensityMapUv),e.push(t.transmissionMapUv),e.push(t.thicknessMapUv),e.push(t.combine),e.push(t.fogExp2),e.push(t.sizeAttenuation),e.push(t.morphTargetsCount),e.push(t.morphAttributeCount),e.push(t.numDirLights),e.push(t.numPointLights),e.push(t.numSpotLights),e.push(t.numSpotLightMaps),e.push(t.numHemiLights),e.push(t.numRectAreaLights),e.push(t.numDirLightShadows),e.push(t.numPointLightShadows),e.push(t.numSpotLightShadows),e.push(t.numSpotLightShadowsWithMaps),e.push(t.numLightProbes),e.push(t.shadowMapType),e.push(t.toneMapping),e.push(t.numClippingPlanes),e.push(t.numClipIntersection),e.push(t.depthPacking)}(i,t),function(e,t){l.disableAll(),t.isWebGL2&&l.enable(0);t.supportsVertexTextures&&l.enable(1);t.instancing&&l.enable(2);t.instancingColor&&l.enable(3);t.matcap&&l.enable(4);t.envMap&&l.enable(5);t.normalMapObjectSpace&&l.enable(6);t.normalMapTangentSpace&&l.enable(7);t.clearcoat&&l.enable(8);t.iridescence&&l.enable(9);t.alphaTest&&l.enable(10);t.vertexColors&&l.enable(11);t.vertexAlphas&&l.enable(12);t.vertexUv1s&&l.enable(13);t.vertexUv2s&&l.enable(14);t.vertexUv3s&&l.enable(15);t.vertexTangents&&l.enable(16);t.anisotropy&&l.enable(17);t.alphaHash&&l.enable(18);e.push(l.mask),l.disableAll(),t.fog&&l.enable(0);t.useFog&&l.enable(1);t.flatShading&&l.enable(2);t.logarithmicDepthBuffer&&l.enable(3);t.skinning&&l.enable(4);t.morphTargets&&l.enable(5);t.morphNormals&&l.enable(6);t.morphColors&&l.enable(7);t.premultipliedAlpha&&l.enable(8);t.shadowMapEnabled&&l.enable(9);t.useLegacyLights&&l.enable(10);t.doubleSided&&l.enable(11);t.flipSided&&l.enable(12);t.useDepthPacking&&l.enable(13);t.dithering&&l.enable(14);t.transmission&&l.enable(15);t.sheen&&l.enable(16);t.opaque&&l.enable(17);t.pointsUvs&&l.enable(18);t.decodeVideoTexture&&l.enable(19);e.push(l.mask)}(i,t),i.push(e.outputColorSpace)),i.push(t.customProgramCacheKey),i.join()},getUniforms:function(e){const t=p[e.type];let i;if(t){const e=Hn[t];i=Mn.clone(e.uniforms)}else i=e.uniforms;return i},acquireProgram:function(t,i){let n;for(let e=0,t=u.length;e0?n.push(u):!0===a.transparent?r.push(u):i.push(u)},unshift:function(e,t,a,o,l,c){const u=s(e,t,a,o,l,c);a.transmission>0?n.unshift(u):!0===a.transparent?r.unshift(u):i.unshift(u)},finish:function(){for(let i=t,n=e.length;i1&&i.sort(e||Zs),n.length>1&&n.sort(t||Qs),r.length>1&&r.sort(t||Qs)}}}function ea(){let e=new WeakMap;return{get:function(t,i){const n=e.get(t);let r;return void 0===n?(r=new Js,e.set(t,[r])):i>=n.length?(r=new Js,n.push(r)):r=n[i],r},dispose:function(){e=new WeakMap}}}function ta(){const e={};return{get:function(t){if(void 0!==e[t.id])return e[t.id];let i;switch(t.type){case"DirectionalLight":i={direction:new _t,color:new Oi};break;case"SpotLight":i={position:new _t,direction:new _t,color:new Oi,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new _t,color:new Oi,distance:0,decay:0};break;case"HemisphereLight":i={direction:new _t,skyColor:new Oi,groundColor:new Oi};break;case"RectAreaLight":i={color:new Oi,position:new _t,halfWidth:new _t,halfHeight:new _t}}return e[t.id]=i,i}}}let ia=0;function na(e,t){return(t.castShadow?2:0)-(e.castShadow?2:0)+(t.map?1:0)-(e.map?1:0)}function ra(e,t){const i=new ta,n=function(){const e={};return{get:function(t){if(void 0!==e[t.id])return e[t.id];let i;switch(t.type){case"DirectionalLight":case"SpotLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Ge};break;case"PointLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Ge,shadowCameraNear:1,shadowCameraFar:1e3}}return e[t.id]=i,i}}}(),r={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let e=0;e<9;e++)r.probe.push(new _t);const s=new _t,a=new qt,o=new qt;return{setup:function(s,a){let o=0,l=0,c=0;for(let e=0;e<9;e++)r.probe[e].set(0,0,0);let u=0,h=0,d=0,f=0,m=0,p=0,g=0,_=0,y=0,v=0,b=0;s.sort(na);const x=!0===a?Math.PI:1;for(let e=0,t=s.length;e0&&(t.isWebGL2||!0===e.has("OES_texture_float_linear")?(r.rectAreaLTC1=Gn.LTC_FLOAT_1,r.rectAreaLTC2=Gn.LTC_FLOAT_2):!0===e.has("OES_texture_half_float_linear")?(r.rectAreaLTC1=Gn.LTC_HALF_1,r.rectAreaLTC2=Gn.LTC_HALF_2):console.error("THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.")),r.ambient[0]=o,r.ambient[1]=l,r.ambient[2]=c;const w=r.hash;w.directionalLength===u&&w.pointLength===h&&w.spotLength===d&&w.rectAreaLength===f&&w.hemiLength===m&&w.numDirectionalShadows===p&&w.numPointShadows===g&&w.numSpotShadows===_&&w.numSpotMaps===y&&w.numLightProbes===b||(r.directional.length=u,r.spot.length=d,r.rectArea.length=f,r.point.length=h,r.hemi.length=m,r.directionalShadow.length=p,r.directionalShadowMap.length=p,r.pointShadow.length=g,r.pointShadowMap.length=g,r.spotShadow.length=_,r.spotShadowMap.length=_,r.directionalShadowMatrix.length=p,r.pointShadowMatrix.length=g,r.spotLightMatrix.length=_+y-v,r.spotLightMap.length=y,r.numSpotLightShadowsWithMaps=v,r.numLightProbes=b,w.directionalLength=u,w.pointLength=h,w.spotLength=d,w.rectAreaLength=f,w.hemiLength=m,w.numDirectionalShadows=p,w.numPointShadows=g,w.numSpotShadows=_,w.numSpotMaps=y,w.numLightProbes=b,r.version=ia++)},setupView:function(e,t){let i=0,n=0,l=0,c=0,u=0;const h=t.matrixWorldInverse;for(let t=0,d=e.length;t=s.length?(a=new sa(e,t),s.push(a)):a=s[r],a},dispose:function(){i=new WeakMap}}}class oa extends Bi{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}}class la extends Bi{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}}function ca(e,i,o){let l=new Bn;const c=new Ge,u=new Ge,h=new ht,d=new oa({depthPacking:3201}),f=new la,m={},p=o.maxTextureSize,g={[r]:s,[s]:r,[a]:2},_=new An({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new Ge},radius:{value:4}},vertexShader:"void main(){gl_Position=vec4(position,1.0);}",fragmentShader:"uniform sampler2D shadow_pass;uniform vec2 resolution;uniform float radius;\n#include \nvoid main(){const float samples=float(VSM_SAMPLES);float mean=0.0;float squared_mean=0.0;float uvStride=samples<=1.0?0.0:2.0/(samples-1.0);float uvStart=samples<=1.0?0.0:-1.0;for(float i=0.0;i0||i.map&&i.alphaTest>0){const e=a.uuid,t=i.uuid;let n=m[e];void 0===n&&(n={},m[e]=n);let r=n[t];void 0===r&&(r=a.clone(),n[t]=r),a=r}if(a.visible=i.visible,a.wireframe=i.wireframe,a.side=s===n?null!==i.shadowSide?i.shadowSide:i.side:null!==i.shadowSide?i.shadowSide:g[i.side],a.alphaMap=i.alphaMap,a.alphaTest=i.alphaTest,a.map=i.map,a.clipShadows=i.clipShadows,a.clippingPlanes=i.clippingPlanes,a.clipIntersection=i.clipIntersection,a.displacementMap=i.displacementMap,a.displacementScale=i.displacementScale,a.displacementBias=i.displacementBias,a.wireframeLinewidth=i.wireframeLinewidth,a.linewidth=i.linewidth,!0===r.isPointLight&&!0===a.isMeshDistanceMaterial){e.properties.get(a).light=r}return a}function A(t,r,s,a,o){if(!1===t.visible)return;if(t.layers.test(r.layers)&&(t.isMesh||t.isLine||t.isPoints)&&(t.castShadow||t.receiveShadow&&o===n)&&(!t.frustumCulled||l.intersectsObject(t))){t.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,t.matrixWorld);const n=i.update(t),r=t.material;if(Array.isArray(r)){const i=n.groups;for(let l=0,c=i.length;lp||c.y>p)&&(c.x>p&&(u.x=Math.floor(p/g.x),c.x=u.x*g.x,o.mapSize.x=u.x),c.y>p&&(u.y=Math.floor(p/g.y),c.y=u.y*g.y,o.mapSize.y=u.y)),null===o.map||!0===f||!0===m){const e=this.type!==n?{minFilter:U,magFilter:U}:{};null!==o.map&&o.map.dispose(),o.map=new ft(c.x,c.y,e),o.map.texture.name=a.name+".shadowMap",o.camera.updateProjectionMatrix()}e.setRenderTarget(o.map),e.clear();const _=o.getViewportCount();for(let e=0;e<_;e++){const t=o.getViewport(e);h.set(u.x*t.x,u.y*t.y,u.x*t.z,u.y*t.w),d.viewport(h),o.updateMatrices(a,e),l=o.getFrustum(),A(i,r,o.camera,a,this.type)}!0!==o.isPointLightShadow&&this.type===n&&S(o,r),o.needsUpdate=!1}w=this.type,x.needsUpdate=!1,e.setRenderTarget(s,a,o)}}function ua(e,t,i){const n=i.isWebGL2;const r=new function(){let t=!1;const i=new ht;let n=null;const r=new ht(0,0,0,0);return{setMask:function(i){n===i||t||(e.colorMask(i,i,i,i),n=i)},setLocked:function(e){t=e},setClear:function(t,n,s,a,o){!0===o&&(t*=a,n*=a,s*=a),i.set(t,n,s,a),!1===r.equals(i)&&(e.clearColor(t,n,s,a),r.copy(i))},reset:function(){t=!1,n=null,r.set(-1,0,0,0)}}},a=new function(){let t=!1,i=null,n=null,r=null;return{setTest:function(e){e?oe(2929):le(2929)},setMask:function(n){i===n||t||(e.depthMask(n),i=n)},setFunc:function(t){if(n!==t){switch(t){case 0:e.depthFunc(512);break;case 1:e.depthFunc(519);break;case 2:e.depthFunc(513);break;case 3:default:e.depthFunc(515);break;case 4:e.depthFunc(514);break;case 5:e.depthFunc(518);break;case 6:e.depthFunc(516);break;case 7:e.depthFunc(517)}n=t}},setLocked:function(e){t=e},setClear:function(t){r!==t&&(e.clearDepth(t),r=t)},reset:function(){t=!1,i=null,n=null,r=null}}},A=new function(){let t=!1,i=null,n=null,r=null,s=null,a=null,o=null,l=null,c=null;return{setTest:function(e){t||(e?oe(2960):le(2960))},setMask:function(n){i===n||t||(e.stencilMask(n),i=n)},setFunc:function(t,i,a){n===t&&r===i&&s===a||(e.stencilFunc(t,i,a),n=t,r=i,s=a)},setOp:function(t,i,n){a===t&&o===i&&l===n||(e.stencilOp(t,i,n),a=t,o=i,l=n)},setLocked:function(e){t=e},setClear:function(t){c!==t&&(e.clearStencil(t),c=t)},reset:function(){t=!1,i=null,n=null,r=null,s=null,a=null,o=null,l=null,c=null}}},C=new WeakMap,T=new WeakMap;let P={},E={},I=new WeakMap,D=[],R=null,L=!1,k=null,O=null,N=null,F=null,B=null,z=null,U=null,V=new Oi(0,0,0),$=0,G=!1,H=null,j=null,W=null,q=null,X=null;const Y=e.getParameter(35661);let K=!1,Z=0;const Q=e.getParameter(7938);-1!==Q.indexOf("WebGL")?(Z=parseFloat(/^WebGL (\d)/.exec(Q)[1]),K=Z>=1):-1!==Q.indexOf("OpenGL ES")&&(Z=parseFloat(/^OpenGL ES (\d)/.exec(Q)[1]),K=Z>=2);let J=null,ee={};const te=e.getParameter(3088),ie=e.getParameter(2978),ne=(new ht).fromArray(te),re=(new ht).fromArray(ie);function se(t,i,r,s){const a=new Uint8Array(4),o=e.createTexture();e.bindTexture(t,o),e.texParameteri(t,10241,9728),e.texParameteri(t,10240,9728);for(let o=0;on||e.height>n)&&(r=n/Math.max(e.width,e.height)),r<1||!0===t){if("undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap){const n=t?Ue:Math.floor,s=n(r*e.width),a=n(r*e.height);void 0===p&&(p=y(s,a));const o=i?y(s,a):p;o.width=s,o.height=a;return o.getContext("2d").drawImage(e,0,0,s,a),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+e.width+"x"+e.height+") to ("+s+"x"+a+")."),o}return"data"in e&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+e.width+"x"+e.height+")."),e}return e}function b(e){return ze(e.width)&&ze(e.height)}function x(e,t){return e.generateMipmaps&&t&&e.minFilter!==U&&e.minFilter!==G}function w(t){e.generateMipmap(t)}function S(i,n,r,s,a=!1){if(!1===o)return n;if(null!==i){if(void 0!==e[i])return e[i];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+i+"'")}let l=n;if(6403===n&&(5126===r&&(l=33326),5131===r&&(l=33325),5121===r&&(l=33321)),36244===n&&(5121===r&&(l=33330),5123===r&&(l=33332),5125===r&&(l=33334),5120===r&&(l=33329),5122===r&&(l=33331),5124===r&&(l=33333)),33319===n&&(5126===r&&(l=33328),5131===r&&(l=33327),5121===r&&(l=33323)),6408===n){const e=a?fe:tt.getTransfer(s);5126===r&&(l=34836),5131===r&&(l=34842),5121===r&&(l=e===me?35907:32856),32819===r&&(l=32854),32820===r&&(l=32855)}return 33325!==l&&33326!==l&&33327!==l&&33328!==l&&34842!==l&&34836!==l||t.get("EXT_color_buffer_float"),l}function M(e,t,i){return!0===x(e,i)||e.isFramebufferTexture&&e.minFilter!==U&&e.minFilter!==G?Math.log2(Math.max(t.width,t.height))+1:void 0!==e.mipmaps&&e.mipmaps.length>0?e.mipmaps.length:e.isCompressedTexture&&Array.isArray(e.image)?t.mipmaps.length:1}function A(e){return e===U||1004===e||e===$?9728:9729}function C(e){const t=e.target;t.removeEventListener("dispose",C),function(e){const t=n.get(e);if(void 0===t.__webglInit)return;const i=e.source,r=g.get(i);if(r){const n=r[t.__cacheKey];n.usedTimes--,0===n.usedTimes&&P(e),0===Object.keys(r).length&&g.delete(i)}n.remove(e)}(t),t.isVideoTexture&&m.delete(t)}function T(t){const i=t.target;i.removeEventListener("dispose",T),function(t){const i=t.texture,r=n.get(t),s=n.get(i);void 0!==s.__webglTexture&&(e.deleteTexture(s.__webglTexture),a.memory.textures--);t.depthTexture&&t.depthTexture.dispose();if(t.isWebGLCubeRenderTarget)for(let t=0;t<6;t++){if(Array.isArray(r.__webglFramebuffer[t]))for(let i=0;i0&&r.__version!==e.version){const i=e.image;if(null===i)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else{if(!1!==i.complete)return void N(r,e,t);console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete")}}i.bindTexture(3553,r.__webglTexture,33984+t)}const D={[F]:10497,[B]:33071,[z]:33648},R={[U]:9728,[V]:9984,[$]:9986,[G]:9729,[H]:9985,[j]:9987},L={[ye]:512,[Ae]:519,[ve]:513,[xe]:515,[be]:514,[Me]:518,[we]:516,[Se]:517};function k(i,s,a){if(a?(e.texParameteri(i,10242,D[s.wrapS]),e.texParameteri(i,10243,D[s.wrapT]),32879!==i&&35866!==i||e.texParameteri(i,32882,D[s.wrapR]),e.texParameteri(i,10240,R[s.magFilter]),e.texParameteri(i,10241,R[s.minFilter])):(e.texParameteri(i,10242,33071),e.texParameteri(i,10243,33071),32879!==i&&35866!==i||e.texParameteri(i,32882,33071),s.wrapS===B&&s.wrapT===B||console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping."),e.texParameteri(i,10240,A(s.magFilter)),e.texParameteri(i,10241,A(s.minFilter)),s.minFilter!==U&&s.minFilter!==G&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.")),s.compareFunction&&(e.texParameteri(i,34892,34894),e.texParameteri(i,34893,L[s.compareFunction])),!0===t.has("EXT_texture_filter_anisotropic")){const a=t.get("EXT_texture_filter_anisotropic");if(s.magFilter===U)return;if(s.minFilter!==$&&s.minFilter!==j)return;if(s.type===K&&!1===t.has("OES_texture_float_linear"))return;if(!1===o&&s.type===Z&&!1===t.has("OES_texture_half_float_linear"))return;(s.anisotropy>1||n.get(s).__currentAnisotropy)&&(e.texParameterf(i,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(s.anisotropy,r.getMaxAnisotropy())),n.get(s).__currentAnisotropy=s.anisotropy)}}function O(t,i){let n=!1;void 0===t.__webglInit&&(t.__webglInit=!0,i.addEventListener("dispose",C));const r=i.source;let s=g.get(r);void 0===s&&(s={},g.set(r,s));const o=function(e){const t=[];return t.push(e.wrapS),t.push(e.wrapT),t.push(e.wrapR||0),t.push(e.magFilter),t.push(e.minFilter),t.push(e.anisotropy),t.push(e.internalFormat),t.push(e.format),t.push(e.type),t.push(e.generateMipmaps),t.push(e.premultiplyAlpha),t.push(e.flipY),t.push(e.unpackAlignment),t.push(e.colorSpace),t.join()}(i);if(o!==t.__cacheKey){void 0===s[o]&&(s[o]={texture:e.createTexture(),usedTimes:0},a.memory.textures++,n=!0),s[o].usedTimes++;const r=s[t.__cacheKey];void 0!==r&&(s[t.__cacheKey].usedTimes--,0===r.usedTimes&&P(i)),t.__cacheKey=o,t.__webglTexture=s[o].texture}return n}function N(t,r,a){let l=3553;(r.isDataArrayTexture||r.isCompressedArrayTexture)&&(l=35866),r.isData3DTexture&&(l=32879);const c=O(t,r),h=r.source;i.bindTexture(l,t.__webglTexture,33984+a);const d=n.get(h);if(h.version!==d.__version||!0===c){i.activeTexture(33984+a);const t=tt.getPrimaries(tt.workingColorSpace),n=r.colorSpace===le?null:tt.getPrimaries(r.colorSpace),f=r.colorSpace===le||t===n?0:37444;e.pixelStorei(37440,r.flipY),e.pixelStorei(37441,r.premultiplyAlpha),e.pixelStorei(3317,r.unpackAlignment),e.pixelStorei(37443,f);const m=function(e){return!o&&(e.wrapS!==B||e.wrapT!==B||e.minFilter!==U&&e.minFilter!==G)}(r)&&!1===b(r.image);let p=v(r.image,m,!1,u);p=ae(r,p);const g=b(p)||o,_=s.convert(r.format,r.colorSpace);let y,A=s.convert(r.type),C=S(r.internalFormat,_,A,r.colorSpace,r.isVideoTexture);k(l,r,g);const T=r.mipmaps,P=o&&!0!==r.isVideoTexture,E=void 0===d.__version||!0===c,I=M(r,p,g);if(r.isDepthTexture)C=6402,o?C=r.type===K?36012:r.type===Y?33190:r.type===Q?35056:33189:r.type===K&&console.error("WebGLRenderer: Floating point depth texture requires WebGL2."),r.format===ee&&6402===C&&r.type!==q&&r.type!==Y&&(console.warn("THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture."),r.type=Y,A=s.convert(r.type)),r.format===te&&6402===C&&(C=34041,r.type!==Q&&(console.warn("THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture."),r.type=Q,A=s.convert(r.type))),E&&(P?i.texStorage2D(3553,1,C,p.width,p.height):i.texImage2D(3553,0,C,p.width,p.height,0,_,A,null));else if(r.isDataTexture)if(T.length>0&&g){P&&E&&i.texStorage2D(3553,I,C,T[0].width,T[0].height);for(let e=0,t=T.length;e>=1,t>>=1}}else if(T.length>0&&g){P&&E&&i.texStorage2D(3553,I,C,T[0].width,T[0].height);for(let e=0,t=T.length;e>c),t=Math.max(1,r.height>>c);32879===l||35866===l?i.texImage3D(l,c,f,e,t,r.depth,0,u,h,null):i.texImage2D(l,c,f,e,t,0,u,h,null)}i.bindFramebuffer(36160,t),se(r)?d.framebufferTexture2DMultisampleEXT(36160,o,l,n.get(a).__webglTexture,0,re(r)):(3553===l||l>=34069&&l<=34074)&&e.framebufferTexture2D(36160,o,l,n.get(a).__webglTexture,c),i.bindFramebuffer(36160,null)}function ie(t,i,n){if(e.bindRenderbuffer(36161,t),i.depthBuffer&&!i.stencilBuffer){let r=!0===o?33190:33189;if(n||se(i)){const t=i.depthTexture;t&&t.isDepthTexture&&(t.type===K?r=36012:t.type===Y&&(r=33190));const n=re(i);se(i)?d.renderbufferStorageMultisampleEXT(36161,n,r,i.width,i.height):e.renderbufferStorageMultisample(36161,n,r,i.width,i.height)}else e.renderbufferStorage(36161,r,i.width,i.height);e.framebufferRenderbuffer(36160,36096,36161,t)}else if(i.depthBuffer&&i.stencilBuffer){const r=re(i);n&&!1===se(i)?e.renderbufferStorageMultisample(36161,r,35056,i.width,i.height):se(i)?d.renderbufferStorageMultisampleEXT(36161,r,35056,i.width,i.height):e.renderbufferStorage(36161,34041,i.width,i.height),e.framebufferRenderbuffer(36160,33306,36161,t)}else{const t=!0===i.isWebGLMultipleRenderTargets?i.texture:[i.texture];for(let r=0;r0&&!0===t.has("WEBGL_multisampled_render_to_texture")&&!1!==i.__useRenderToTexture}function ae(e,i){const n=e.colorSpace,r=e.format,s=e.type;return!0===e.isCompressedTexture||!0===e.isVideoTexture||e.format===Ee||n!==ue&&n!==le&&(tt.getTransfer(n)===me?!1===o?!0===t.has("EXT_sRGB")&&r===J?(e.format=Ee,e.minFilter=G,e.generateMipmaps=!1):i=st.sRGBToLinear(i):r===J&&s===W||console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",n)),i}this.allocateTextureUnit=function(){const e=E;return e>=l&&console.warn("THREE.WebGLTextures: Trying to use "+e+" texture units while this GPU supports only "+l),E+=1,e},this.resetTextureUnits=function(){E=0},this.setTexture2D=I,this.setTexture2DArray=function(e,t){const r=n.get(e);e.version>0&&r.__version!==e.version?N(r,e,t):i.bindTexture(35866,r.__webglTexture,33984+t)},this.setTexture3D=function(e,t){const r=n.get(e);e.version>0&&r.__version!==e.version?N(r,e,t):i.bindTexture(32879,r.__webglTexture,33984+t)},this.setTextureCube=function(t,r){const a=n.get(t);t.version>0&&a.__version!==t.version?function(t,r,a){if(6!==r.image.length)return;const l=O(t,r),u=r.source;i.bindTexture(34067,t.__webglTexture,33984+a);const h=n.get(u);if(u.version!==h.__version||!0===l){i.activeTexture(33984+a);const t=tt.getPrimaries(tt.workingColorSpace),n=r.colorSpace===le?null:tt.getPrimaries(r.colorSpace),d=r.colorSpace===le||t===n?0:37444;e.pixelStorei(37440,r.flipY),e.pixelStorei(37441,r.premultiplyAlpha),e.pixelStorei(3317,r.unpackAlignment),e.pixelStorei(37443,d);const f=r.isCompressedTexture||r.image[0].isCompressedTexture,m=r.image[0]&&r.image[0].isDataTexture,p=[];for(let e=0;e<6;e++)p[e]=f||m?m?r.image[e].image:r.image[e]:v(r.image[e],!1,!0,c),p[e]=ae(r,p[e]);const g=p[0],_=b(g)||o,y=s.convert(r.format,r.colorSpace),A=s.convert(r.type),C=S(r.internalFormat,y,A,r.colorSpace),T=o&&!0!==r.isVideoTexture,P=void 0===h.__version||!0===l;let E,I=M(r,g,_);if(k(34067,r,_),f){T&&P&&i.texStorage2D(34067,I,C,g.width,g.height);for(let e=0;e<6;e++){E=p[e].mipmaps;for(let t=0;t0&&I++,i.texStorage2D(34067,I,C,p[0].width,p[0].height));for(let e=0;e<6;e++)if(m){T?i.texSubImage2D(34069+e,0,0,0,p[e].width,p[e].height,y,A,p[e].data):i.texImage2D(34069+e,0,C,p[e].width,p[e].height,0,y,A,p[e].data);for(let t=0;t0){c.__webglFramebuffer[t]=[];for(let i=0;i0){c.__webglFramebuffer=[];for(let t=0;t0&&!1===se(t)){const n=d?l:[l];c.__webglMultisampledFramebuffer=e.createFramebuffer(),c.__webglColorRenderbuffer=[],i.bindFramebuffer(36160,c.__webglMultisampledFramebuffer);for(let i=0;i0)for(let i=0;i0)for(let i=0;i0&&!1===se(t)){const r=t.isWebGLMultipleRenderTargets?t.texture:[t.texture],s=t.width,a=t.height;let o=16384;const l=[],c=t.stencilBuffer?33306:36096,u=n.get(t),h=!0===t.isWebGLMultipleRenderTargets;if(h)for(let t=0;to+c?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!l.inputState.pinching&&a<=o-c&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else null!==o&&e.gripSpace&&(r=t.getPose(e.gripSpace,i),null!==r&&(o.matrix.fromArray(r.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,r.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(r.linearVelocity)):o.hasLinearVelocity=!1,r.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(r.angularVelocity)):o.hasAngularVelocity=!1));null!==a&&(n=t.getPose(e.targetRaySpace,i),null===n&&null!==r&&(n=r),null!==n&&(a.matrix.fromArray(n.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,n.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(n.linearVelocity)):a.hasLinearVelocity=!1,n.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(n.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(pa)))}return null!==a&&(a.visible=null!==n),null!==o&&(o.visible=null!==r),null!==l&&(l.visible=null!==s),this}_getHandJoint(e,t){if(void 0===e.joints[t.jointName]){const i=new ma;i.matrixAutoUpdate=!1,i.visible=!1,e.joints[t.jointName]=i,e.add(i)}return e.joints[t.jointName]}}class _a extends ut{constructor(e,t,i,n,r,s,a,o,l,c){if((c=void 0!==c?c:ee)!==ee&&c!==te)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===i&&c===ee&&(i=Y),void 0===i&&c===te&&(i=Q),super(null,n,r,s,a,o,c,i,l),this.isDepthTexture=!0,this.image={width:e,height:t},this.magFilter=void 0!==a?a:U,this.minFilter=void 0!==o?o:U,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return null!==this.compareFunction&&(t.compareFunction=this.compareFunction),t}}class ya extends Re{constructor(e,t){super();const i=this;let n=null,r=1,s=null,a="local-floor",o=1,l=null,c=null,u=null,h=null,d=null,f=null;const m=t.getContextAttributes();let p=null,g=null;const _=[],y=[],v=new Tn;v.layers.enable(1),v.viewport=new ht;const b=new Tn;b.layers.enable(2),b.viewport=new ht;const x=[v,b],w=new fa;w.layers.enable(1),w.layers.enable(2);let S=null,M=null;function A(e){const t=y.indexOf(e.inputSource);if(-1===t)return;const i=_[t];void 0!==i&&(i.update(e.inputSource,e.frame,l||s),i.dispatchEvent({type:e.type,data:e.inputSource}))}function C(){n.removeEventListener("select",A),n.removeEventListener("selectstart",A),n.removeEventListener("selectend",A),n.removeEventListener("squeeze",A),n.removeEventListener("squeezestart",A),n.removeEventListener("squeezeend",A),n.removeEventListener("end",C),n.removeEventListener("inputsourceschange",T);for(let e=0;e<_.length;e++){const t=y[e];null!==t&&(y[e]=null,_[e].disconnect(t))}S=null,M=null,e.setRenderTarget(p),d=null,h=null,u=null,n=null,g=null,R.stop(),i.isPresenting=!1,i.dispatchEvent({type:"sessionend"})}function T(e){for(let t=0;t=0&&(y[n]=null,_[n].disconnect(i))}for(let t=0;t=y.length){y.push(i),n=e;break}if(null===y[e]){y[e]=i,n=e;break}}if(-1===n)break}const r=_[n];r&&r.connect(i)}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(e){let t=_[e];return void 0===t&&(t=new ga,_[e]=t),t.getTargetRaySpace()},this.getControllerGrip=function(e){let t=_[e];return void 0===t&&(t=new ga,_[e]=t),t.getGripSpace()},this.getHand=function(e){let t=_[e];return void 0===t&&(t=new ga,_[e]=t),t.getHandSpace()},this.setFramebufferScaleFactor=function(e){r=e,!0===i.isPresenting&&console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(e){a=e,!0===i.isPresenting&&console.warn("THREE.WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||s},this.setReferenceSpace=function(e){l=e},this.getBaseLayer=function(){return null!==h?h:d},this.getBinding=function(){return u},this.getFrame=function(){return f},this.getSession=function(){return n},this.setSession=async function(c){if(n=c,null!==n){if(p=e.getRenderTarget(),n.addEventListener("select",A),n.addEventListener("selectstart",A),n.addEventListener("selectend",A),n.addEventListener("squeeze",A),n.addEventListener("squeezestart",A),n.addEventListener("squeezeend",A),n.addEventListener("end",C),n.addEventListener("inputsourceschange",T),!0!==m.xrCompatible&&await t.makeXRCompatible(),void 0===n.renderState.layers||!1===e.capabilities.isWebGL2){const i={antialias:void 0!==n.renderState.layers||m.antialias,alpha:!0,depth:m.depth,stencil:m.stencil,framebufferScaleFactor:r};d=new XRWebGLLayer(n,t,i),n.updateRenderState({baseLayer:d}),g=new ft(d.framebufferWidth,d.framebufferHeight,{format:J,type:W,colorSpace:e.outputColorSpace,stencilBuffer:m.stencil})}else{let i=null,s=null,a=null;m.depth&&(a=m.stencil?35056:33190,i=m.stencil?te:ee,s=m.stencil?Q:Y);const o={colorFormat:32856,depthFormat:a,scaleFactor:r};u=new XRWebGLBinding(n,t),h=u.createProjectionLayer(o),n.updateRenderState({layers:[h]}),g=new ft(h.textureWidth,h.textureHeight,{format:J,type:W,depthTexture:new _a(h.textureWidth,h.textureHeight,s,void 0,void 0,void 0,void 0,void 0,void 0,i),stencilBuffer:m.stencil,colorSpace:e.outputColorSpace,samples:m.antialias?4:0});e.properties.get(g).__ignoreDepthValues=h.ignoreDepthValues}g.isXRRenderTarget=!0,this.setFoveation(o),l=null,s=await n.requestReferenceSpace(a),R.setContext(n),R.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(null!==n)return n.environmentBlendMode};const P=new _t,E=new _t;function I(e,t){null===t?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}this.updateCamera=function(e){if(null===n)return;w.near=b.near=v.near=e.near,w.far=b.far=v.far=e.far,S===w.near&&M===w.far||(n.updateRenderState({depthNear:w.near,depthFar:w.far}),S=w.near,M=w.far);const t=e.parent,i=w.cameras;I(w,t);for(let e=0;e0&&(n.alphaTest.value=r.alphaTest);const a=t.get(r).envMap;if(a&&(n.envMap.value=a,n.flipEnvMap.value=a.isCubeTexture&&!1===a.isRenderTargetTexture?-1:1,n.reflectivity.value=r.reflectivity,n.ior.value=r.ior,n.refractionRatio.value=r.refractionRatio),r.lightMap){n.lightMap.value=r.lightMap;const t=!0===e._useLegacyLights?Math.PI:1;n.lightMapIntensity.value=r.lightMapIntensity*t,i(r.lightMap,n.lightMapTransform)}r.aoMap&&(n.aoMap.value=r.aoMap,n.aoMapIntensity.value=r.aoMapIntensity,i(r.aoMap,n.aoMapTransform))}return{refreshFogUniforms:function(t,i){i.color.getRGB(t.fogColor.value,Sn(e)),i.isFog?(t.fogNear.value=i.near,t.fogFar.value=i.far):i.isFogExp2&&(t.fogDensity.value=i.density)},refreshMaterialUniforms:function(e,r,a,o,l){r.isMeshBasicMaterial||r.isMeshLambertMaterial?n(e,r):r.isMeshToonMaterial?(n(e,r),function(e,t){t.gradientMap&&(e.gradientMap.value=t.gradientMap)}(e,r)):r.isMeshPhongMaterial?(n(e,r),function(e,t){e.specular.value.copy(t.specular),e.shininess.value=Math.max(t.shininess,1e-4)}(e,r)):r.isMeshStandardMaterial?(n(e,r),function(e,n){e.metalness.value=n.metalness,n.metalnessMap&&(e.metalnessMap.value=n.metalnessMap,i(n.metalnessMap,e.metalnessMapTransform));e.roughness.value=n.roughness,n.roughnessMap&&(e.roughnessMap.value=n.roughnessMap,i(n.roughnessMap,e.roughnessMapTransform));const r=t.get(n).envMap;r&&(e.envMapIntensity.value=n.envMapIntensity)}(e,r),r.isMeshPhysicalMaterial&&function(e,t,n){e.ior.value=t.ior,t.sheen>0&&(e.sheenColor.value.copy(t.sheenColor).multiplyScalar(t.sheen),e.sheenRoughness.value=t.sheenRoughness,t.sheenColorMap&&(e.sheenColorMap.value=t.sheenColorMap,i(t.sheenColorMap,e.sheenColorMapTransform)),t.sheenRoughnessMap&&(e.sheenRoughnessMap.value=t.sheenRoughnessMap,i(t.sheenRoughnessMap,e.sheenRoughnessMapTransform)));t.clearcoat>0&&(e.clearcoat.value=t.clearcoat,e.clearcoatRoughness.value=t.clearcoatRoughness,t.clearcoatMap&&(e.clearcoatMap.value=t.clearcoatMap,i(t.clearcoatMap,e.clearcoatMapTransform)),t.clearcoatRoughnessMap&&(e.clearcoatRoughnessMap.value=t.clearcoatRoughnessMap,i(t.clearcoatRoughnessMap,e.clearcoatRoughnessMapTransform)),t.clearcoatNormalMap&&(e.clearcoatNormalMap.value=t.clearcoatNormalMap,i(t.clearcoatNormalMap,e.clearcoatNormalMapTransform),e.clearcoatNormalScale.value.copy(t.clearcoatNormalScale),t.side===s&&e.clearcoatNormalScale.value.negate()));t.iridescence>0&&(e.iridescence.value=t.iridescence,e.iridescenceIOR.value=t.iridescenceIOR,e.iridescenceThicknessMinimum.value=t.iridescenceThicknessRange[0],e.iridescenceThicknessMaximum.value=t.iridescenceThicknessRange[1],t.iridescenceMap&&(e.iridescenceMap.value=t.iridescenceMap,i(t.iridescenceMap,e.iridescenceMapTransform)),t.iridescenceThicknessMap&&(e.iridescenceThicknessMap.value=t.iridescenceThicknessMap,i(t.iridescenceThicknessMap,e.iridescenceThicknessMapTransform)));t.transmission>0&&(e.transmission.value=t.transmission,e.transmissionSamplerMap.value=n.texture,e.transmissionSamplerSize.value.set(n.width,n.height),t.transmissionMap&&(e.transmissionMap.value=t.transmissionMap,i(t.transmissionMap,e.transmissionMapTransform)),e.thickness.value=t.thickness,t.thicknessMap&&(e.thicknessMap.value=t.thicknessMap,i(t.thicknessMap,e.thicknessMapTransform)),e.attenuationDistance.value=t.attenuationDistance,e.attenuationColor.value.copy(t.attenuationColor));t.anisotropy>0&&(e.anisotropyVector.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation)),t.anisotropyMap&&(e.anisotropyMap.value=t.anisotropyMap,i(t.anisotropyMap,e.anisotropyMapTransform)));e.specularIntensity.value=t.specularIntensity,e.specularColor.value.copy(t.specularColor),t.specularColorMap&&(e.specularColorMap.value=t.specularColorMap,i(t.specularColorMap,e.specularColorMapTransform));t.specularIntensityMap&&(e.specularIntensityMap.value=t.specularIntensityMap,i(t.specularIntensityMap,e.specularIntensityMapTransform))}(e,r,l)):r.isMeshMatcapMaterial?(n(e,r),function(e,t){t.matcap&&(e.matcap.value=t.matcap)}(e,r)):r.isMeshDepthMaterial?n(e,r):r.isMeshDistanceMaterial?(n(e,r),function(e,i){const n=t.get(i).light;e.referencePosition.value.setFromMatrixPosition(n.matrixWorld),e.nearDistance.value=n.shadow.camera.near,e.farDistance.value=n.shadow.camera.far}(e,r)):r.isMeshNormalMaterial?n(e,r):r.isLineBasicMaterial?(function(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,t.map&&(e.map.value=t.map,i(t.map,e.mapTransform))}(e,r),r.isLineDashedMaterial&&function(e,t){e.dashSize.value=t.dashSize,e.totalSize.value=t.dashSize+t.gapSize,e.scale.value=t.scale}(e,r)):r.isPointsMaterial?function(e,t,n,r){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.size.value=t.size*n,e.scale.value=.5*r,t.map&&(e.map.value=t.map,i(t.map,e.uvTransform));t.alphaMap&&(e.alphaMap.value=t.alphaMap,i(t.alphaMap,e.alphaMapTransform));t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}(e,r,a,o):r.isSpriteMaterial?function(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.rotation.value=t.rotation,t.map&&(e.map.value=t.map,i(t.map,e.mapTransform));t.alphaMap&&(e.alphaMap.value=t.alphaMap,i(t.alphaMap,e.alphaMapTransform));t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}(e,r):r.isShadowMaterial?(e.color.value.copy(r.color),e.opacity.value=r.opacity):r.isShaderMaterial&&(r.uniformsNeedUpdate=!1)}}}function ba(e,t,i,n){let r={},s={},a=[];const o=i.isWebGL2?e.getParameter(35375):0;function l(e,t,i){const n=e.value;if(void 0===i[t]){if("number"==typeof n)i[t]=n;else{const e=Array.isArray(n)?n:[n],r=[];for(let t=0;t0){r=i%n;0!==r&&n-r-a.boundary<0&&(i+=n-r,s.__offset=i)}i+=a.storage}r=i%n,r>0&&(i+=n-r);e.__size=i,e.__cache={}}(i),d=function(t){const i=function(){for(let e=0;e0),h=!!i.morphAttributes.position,d=!!i.morphAttributes.normal,f=!!i.morphAttributes.color;let m=P;n.toneMapped&&(null!==M&&!0!==M.isXRRenderTarget||(m=b.toneMapping));const p=i.morphAttributes.position||i.morphAttributes.normal||i.morphAttributes.color,g=void 0!==p?p.length:0,y=le.get(n),v=_.state.lights;if(!0===$&&(!0===G||e!==C)){const t=e===C&&n.id===A;xe.setState(n,e,t)}let x=!1;n.version===y.__version?y.needsLights&&y.lightsStateVersion!==v.state.version||y.outputColorSpace!==o||r.isInstancedMesh&&!1===y.instancing?x=!0:r.isInstancedMesh||!0!==y.instancing?r.isSkinnedMesh&&!1===y.skinning?x=!0:r.isSkinnedMesh||!0!==y.skinning?r.isInstancedMesh&&!0===y.instancingColor&&null===r.instanceColor||r.isInstancedMesh&&!1===y.instancingColor&&null!==r.instanceColor||y.envMap!==l||!0===n.fog&&y.fog!==s?x=!0:void 0===y.numClippingPlanes||y.numClippingPlanes===xe.numPlanes&&y.numIntersection===xe.numIntersection?(y.vertexAlphas!==c||y.vertexTangents!==u||y.morphTargets!==h||y.morphNormals!==d||y.morphColors!==f||y.toneMapping!==m||!0===se.isWebGL2&&y.morphTargetsCount!==g)&&(x=!0):x=!0:x=!0:x=!0:(x=!0,y.__version=n.version);let w=y.currentProgram;!0===x&&(w=Ke(n,t,r));let S=!1,T=!1,E=!1;const I=w.getUniforms(),D=y.uniforms;ae.useProgram(w.program)&&(S=!0,T=!0,E=!0);n.id!==A&&(A=n.id,T=!0);if(S||C!==e){I.setValue(Ie,"projectionMatrix",e.projectionMatrix),I.setValue(Ie,"viewMatrix",e.matrixWorldInverse);const t=I.map.cameraPosition;void 0!==t&&t.setValue(Ie,te.setFromMatrixPosition(e.matrixWorld)),se.logarithmicDepthBuffer&&I.setValue(Ie,"logDepthBufFC",2/(Math.log(e.far+1)/Math.LN2)),(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial)&&I.setValue(Ie,"isOrthographic",!0===e.isOrthographicCamera),C!==e&&(C=e,T=!0,E=!0)}if(r.isSkinnedMesh){I.setOptional(Ie,r,"bindMatrix"),I.setOptional(Ie,r,"bindMatrixInverse");const e=r.skeleton;e&&(se.floatVertexTextures?(null===e.boneTexture&&e.computeBoneTexture(),I.setValue(Ie,"boneTexture",e.boneTexture,he),I.setValue(Ie,"boneTextureSize",e.boneTextureSize)):console.warn("THREE.WebGLRenderer: SkinnedMesh can only be used with WebGL 2. With WebGL 1 OES_texture_float and vertex textures support is required."))}const R=i.morphAttributes;(void 0!==R.position||void 0!==R.normal||void 0!==R.color&&!0===se.isWebGL2)&&Me.update(r,i,w);(T||y.receiveShadow!==r.receiveShadow)&&(y.receiveShadow=r.receiveShadow,I.setValue(Ie,"receiveShadow",r.receiveShadow));n.isMeshGouraudMaterial&&null!==n.envMap&&(D.envMap.value=l,D.flipEnvMap.value=l.isCubeTexture&&!1===l.isRenderTargetTexture?-1:1);T&&(I.setValue(Ie,"toneMappingExposure",b.toneMappingExposure),y.needsLights&&(N=E,(L=D).ambientLightColor.needsUpdate=N,L.lightProbe.needsUpdate=N,L.directionalLights.needsUpdate=N,L.directionalLightShadows.needsUpdate=N,L.pointLights.needsUpdate=N,L.pointLightShadows.needsUpdate=N,L.spotLights.needsUpdate=N,L.spotLightShadows.needsUpdate=N,L.rectAreaLights.needsUpdate=N,L.hemisphereLights.needsUpdate=N),s&&!0===n.fog&&ye.refreshFogUniforms(D,s),ye.refreshMaterialUniforms(D,n,O,k,H),Ts.upload(Ie,Ze(y),D,he));var L,N;n.isShaderMaterial&&!0===n.uniformsNeedUpdate&&(Ts.upload(Ie,Ze(y),D,he),n.uniformsNeedUpdate=!1);n.isSpriteMaterial&&I.setValue(Ie,"center",r.center);if(I.setValue(Ie,"modelViewMatrix",r.modelViewMatrix),I.setValue(Ie,"normalMatrix",r.normalMatrix),I.setValue(Ie,"modelMatrix",r.matrixWorld),n.isShaderMaterial||n.isRawShaderMaterial){const e=n.uniformsGroups;for(let t=0,i=e.length;t{function i(){n.forEach((function(e){le.get(e).currentProgram.isReady()&&n.delete(e)})),0!==n.size?setTimeout(i,10):t(e)}null!==re.get("KHR_parallel_shader_compile")?i():setTimeout(i,10)}))};let ze=null;function Ve(){He.stop()}function $e(){He.start()}const He=new zn;function je(e,t,i,n){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)i=e.renderOrder;else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)_.pushLight(e),e.castShadow&&_.pushShadow(e);else if(e.isSprite){if(!e.frustumCulled||V.intersectsSprite(e)){n&&te.setFromMatrixPosition(e.matrixWorld).applyMatrix4(X);const t=ge.update(e),r=e.material;r.visible&&g.push(e,t,r,i,te.z,null)}}else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||V.intersectsObject(e))){const t=ge.update(e),r=e.material;if(n&&(void 0!==e.boundingSphere?(null===e.boundingSphere&&e.computeBoundingSphere(),te.copy(e.boundingSphere.center)):(null===t.boundingSphere&&t.computeBoundingSphere(),te.copy(t.boundingSphere.center)),te.applyMatrix4(e.matrixWorld).applyMatrix4(X)),Array.isArray(r)){const n=t.groups;for(let s=0,a=n.length;s0&&function(e,t,i,n){const r=!0===i.isScene?i.overrideMaterial:null;if(null!==r)return;const a=se.isWebGL2;null===H&&(H=new ft(1,1,{generateMipmaps:!0,type:re.has("EXT_color_buffer_half_float")?Z:W,minFilter:j,samples:a?4:0}));b.getDrawingBufferSize(ee),a?H.setSize(ee.x,ee.y):H.setSize(Ue(ee.x),Ue(ee.y));const o=b.getRenderTarget();b.setRenderTarget(H),b.getClearColor(D),R=b.getClearAlpha(),R<1&&b.setClearColor(16777215,.5);b.clear();const l=b.toneMapping;b.toneMapping=P,qe(e,i,n),he.updateMultisampleRenderTarget(H),he.updateRenderTargetMipmap(H);let c=!1;for(let e=0,r=t.length;e0&&qe(r,t,i),a.length>0&&qe(a,t,i),o.length>0&&qe(o,t,i),ae.buffers.depth.setTest(!0),ae.buffers.depth.setMask(!0),ae.buffers.color.setMask(!0),ae.setPolygonOffset(!1)}function qe(e,t,i){const n=!0===t.isScene?t.overrideMaterial:null;for(let r=0,s=e.length;r0?v[v.length-1]:null,y.pop(),g=y.length>0?y[y.length-1]:null},this.getActiveCubeFace=function(){return w},this.getActiveMipmapLevel=function(){return S},this.getRenderTarget=function(){return M},this.setRenderTargetTextures=function(e,t,i){le.get(e.texture).__webglTexture=t,le.get(e.depthTexture).__webglTexture=i;const n=le.get(e);n.__hasExternalTextures=!0,n.__hasExternalTextures&&(n.__autoAllocateDepthBuffer=void 0===i,n.__autoAllocateDepthBuffer||!0===re.has("WEBGL_multisampled_render_to_texture")&&(console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"),n.__useRenderToTexture=!1))},this.setRenderTargetFramebuffer=function(e,t){const i=le.get(e);i.__webglFramebuffer=t,i.__useDefaultFramebuffer=void 0===t},this.setRenderTarget=function(e,t=0,i=0){M=e,w=t,S=i;let n=!0,r=null,s=!1,a=!1;if(e){const o=le.get(e);void 0!==o.__useDefaultFramebuffer?(ae.bindFramebuffer(36160,null),n=!1):void 0===o.__webglFramebuffer?he.setupRenderTarget(e):o.__hasExternalTextures&&he.rebindTextures(e,le.get(e.texture).__webglTexture,le.get(e.depthTexture).__webglTexture);const l=e.texture;(l.isData3DTexture||l.isDataArrayTexture||l.isCompressedArrayTexture)&&(a=!0);const c=le.get(e).__webglFramebuffer;e.isWebGLCubeRenderTarget?(r=Array.isArray(c[t])?c[t][i]:c[t],s=!0):r=se.isWebGL2&&e.samples>0&&!1===he.useMultisampledRTT(e)?le.get(e).__webglMultisampledFramebuffer:Array.isArray(c)?c[i]:c,T.copy(e.viewport),E.copy(e.scissor),I=e.scissorTest}else T.copy(B).multiplyScalar(O).floor(),E.copy(z).multiplyScalar(O).floor(),I=U;if(ae.bindFramebuffer(36160,r)&&se.drawBuffers&&n&&ae.drawBuffers(e,r),ae.viewport(T),ae.scissor(E),ae.setScissorTest(I),s){const n=le.get(e.texture);Ie.framebufferTexture2D(36160,36064,34069+t,n.__webglTexture,i)}else if(a){const n=le.get(e.texture),r=t||0;Ie.framebufferTextureLayer(36160,36064,n.__webglTexture,i||0,r)}A=-1},this.readRenderTargetPixels=function(e,t,i,n,r,s,a){if(!e||!e.isWebGLRenderTarget)return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let o=le.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){ae.bindFramebuffer(36160,o);try{const a=e.texture,o=a.format,l=a.type;if(o!==J&&Te.convert(o)!==Ie.getParameter(35739))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");const c=l===Z&&(re.has("EXT_color_buffer_half_float")||se.isWebGL2&&re.has("EXT_color_buffer_float"));if(!(l===W||Te.convert(l)===Ie.getParameter(35738)||l===K&&(se.isWebGL2||re.has("OES_texture_float")||re.has("WEBGL_color_buffer_float"))||c))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");t>=0&&t<=e.width-n&&i>=0&&i<=e.height-r&&Ie.readPixels(t,i,n,r,Te.convert(o),Te.convert(l),s)}finally{const e=null!==M?le.get(M).__webglFramebuffer:null;ae.bindFramebuffer(36160,e)}}},this.copyFramebufferToTexture=function(e,t,i=0){const n=Math.pow(2,-i),r=Math.floor(t.image.width*n),s=Math.floor(t.image.height*n);he.setTexture2D(t,0),Ie.copyTexSubImage2D(3553,i,0,0,e.x,e.y,r,s),ae.unbindTexture()},this.copyTextureToTexture=function(e,t,i,n=0){const r=t.image.width,s=t.image.height,a=Te.convert(i.format),o=Te.convert(i.type);he.setTexture2D(i,0),Ie.pixelStorei(37440,i.flipY),Ie.pixelStorei(37441,i.premultiplyAlpha),Ie.pixelStorei(3317,i.unpackAlignment),t.isDataTexture?Ie.texSubImage2D(3553,n,e.x,e.y,r,s,a,o,t.image.data):t.isCompressedTexture?Ie.compressedTexSubImage2D(3553,n,e.x,e.y,t.mipmaps[0].width,t.mipmaps[0].height,a,t.mipmaps[0].data):Ie.texSubImage2D(3553,n,e.x,e.y,a,o,t.image),0===n&&i.generateMipmaps&&Ie.generateMipmap(3553),ae.unbindTexture()},this.copyTextureToTexture3D=function(e,t,i,n,r=0){if(b.isWebGL1Renderer)return void console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.");const s=e.max.x-e.min.x+1,a=e.max.y-e.min.y+1,o=e.max.z-e.min.z+1,l=Te.convert(n.format),c=Te.convert(n.type);let u;if(n.isData3DTexture)he.setTexture3D(n,0),u=32879;else{if(!n.isDataArrayTexture)return void console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.");he.setTexture2DArray(n,0),u=35866}Ie.pixelStorei(37440,n.flipY),Ie.pixelStorei(37441,n.premultiplyAlpha),Ie.pixelStorei(3317,n.unpackAlignment);const h=Ie.getParameter(3314),d=Ie.getParameter(32878),f=Ie.getParameter(3316),m=Ie.getParameter(3315),p=Ie.getParameter(32877),g=i.isCompressedTexture?i.mipmaps[0]:i.image;Ie.pixelStorei(3314,g.width),Ie.pixelStorei(32878,g.height),Ie.pixelStorei(3316,e.min.x),Ie.pixelStorei(3315,e.min.y),Ie.pixelStorei(32877,e.min.z),i.isDataTexture||i.isData3DTexture?Ie.texSubImage3D(u,r,t.x,t.y,t.z,s,a,o,l,c,g.data):i.isCompressedArrayTexture?(console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture."),Ie.compressedTexSubImage3D(u,r,t.x,t.y,t.z,s,a,o,l,g.data)):Ie.texSubImage3D(u,r,t.x,t.y,t.z,s,a,o,l,c,g),Ie.pixelStorei(3314,h),Ie.pixelStorei(32878,d),Ie.pixelStorei(3316,f),Ie.pixelStorei(3315,m),Ie.pixelStorei(32877,p),0===r&&n.generateMipmaps&&Ie.generateMipmap(u),ae.unbindTexture()},this.initTexture=function(e){e.isCubeTexture?he.setTextureCube(e,0):e.isData3DTexture?he.setTexture3D(e,0):e.isDataArrayTexture||e.isCompressedArrayTexture?he.setTexture2DArray(e,0):he.setTexture2D(e,0),ae.unbindTexture()},this.resetState=function(){w=0,S=0,M=null,ae.reset(),Pe.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return Ie}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=e===he?"display-p3":"srgb",t.unpackColorSpace=tt.workingColorSpace===de?"display-p3":"srgb"}get physicallyCorrectLights(){return console.warn("THREE.WebGLRenderer: The property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead."),!this.useLegacyLights}set physicallyCorrectLights(e){console.warn("THREE.WebGLRenderer: The property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead."),this.useLegacyLights=!e}get outputEncoding(){return console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."),this.outputColorSpace===ce?oe:3e3}set outputEncoding(e){console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."),this.outputColorSpace=e===oe?ce:ue}get useLegacyLights(){return console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."),this._useLegacyLights}set useLegacyLights(e){console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."),this._useLegacyLights=e}}class wa{constructor(e,t=1,i=1e3){this.isFog=!0,this.name="",this.color=new Oi(e),this.near=t,this.far=i}clone(){return new wa(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class Sa extends yi{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.overrideMaterial=null,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),null!==e.background&&(this.background=e.background.clone()),null!==e.environment&&(this.environment=e.environment.clone()),null!==e.fog&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,null!==e.overrideMaterial&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return null!==this.fog&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(t.object.backgroundIntensity=this.backgroundIntensity),t}}class Ma extends ut{constructor(e=null,t=1,i=1,n,r,s,a,o,l=1003,c=1003,u,h){super(null,s,a,o,l,c,n,r,u,h),this.isDataTexture=!0,this.image={data:e,width:t,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Aa extends Bi{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new Oi(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}}const Ca=new _t,Ta=new _t,Pa=new qt,Ea=new Wt,Ia=new Bt;class Da extends yi{constructor(e=new Ji,t=new Aa){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){const e=this.geometry;if(null===e.index){const t=e.attributes.position,i=[0];for(let e=1,n=t.count;eo)continue;h.applyMatrix4(this.matrixWorld);const s=e.ray.origin.distanceTo(h);se.far||t.push({distance:s,point:u.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}}else{for(let i=Math.max(0,s.start),n=Math.min(m.count,s.start+s.count)-1;io)continue;h.applyMatrix4(this.matrixWorld);const n=e.ray.origin.distanceTo(h);ne.far||t.push({distance:n,point:u.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}}}updateMorphTargets(){const e=this.geometry.morphAttributes,t=Object.keys(e);if(t.length>0){const i=e[t[0]];if(void 0!==i){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=i.length;e0){const i=e[t[0]];if(void 0!==i){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=i.length;er.far)return;s.push({distance:l,distanceToRay:Math.sqrt(o),point:i,index:t,face:null,object:a})}}class $a extends ut{constructor(e,t,i,n,r,s,a,o,l){super(e,t,i,n,r,s,a,o,l),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Ga extends Ji{constructor(e=1,t=1,i=1,n=32,r=1,s=!1,a=0,o=2*Math.PI){super(),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:i,radialSegments:n,heightSegments:r,openEnded:s,thetaStart:a,thetaLength:o};const l=this;n=Math.floor(n),r=Math.floor(r);const c=[],u=[],h=[],d=[];let f=0;const m=[],p=i/2;let g=0;function _(i){const r=f,s=new Ge,m=new _t;let _=0;const y=!0===i?e:t,v=!0===i?1:-1;for(let e=1;e<=n;e++)u.push(0,p*v,0),h.push(0,v,0),d.push(.5,.5),f++;const b=f;for(let e=0;e<=n;e++){const t=e/n*o+a,i=Math.cos(t),r=Math.sin(t);m.x=y*r,m.y=p*v,m.z=y*i,u.push(m.x,m.y,m.z),h.push(0,v,0),s.x=.5*i+.5,s.y=.5*r*v+.5,d.push(s.x,s.y),f++}for(let e=0;e0&&_(!0),t>0&&_(!1)),this.setIndex(c),this.setAttribute("position",new ji(u,3)),this.setAttribute("normal",new ji(h,3)),this.setAttribute("uv",new ji(d,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Ga(e.radiusTop,e.radiusBottom,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class Ha extends Ga{constructor(e=1,t=1,i=32,n=1,r=!1,s=0,a=2*Math.PI){super(0,e,t,i,n,r,s,a),this.type="ConeGeometry",this.parameters={radius:e,height:t,radialSegments:i,heightSegments:n,openEnded:r,thetaStart:s,thetaLength:a}}static fromJSON(e){return new Ha(e.radius,e.height,e.radialSegments,e.heightSegments,e.openEnded,e.thetaStart,e.thetaLength)}}class ja extends Ji{constructor(e=[],t=[],i=1,n=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:e,indices:t,radius:i,detail:n};const r=[],s=[];function a(e,t,i,n){const r=n+1,s=[];for(let n=0;n<=r;n++){s[n]=[];const a=e.clone().lerp(i,n/r),o=t.clone().lerp(i,n/r),l=r-n;for(let e=0;e<=l;e++)s[n][e]=0===e&&n===r?a:a.clone().lerp(o,e/l)}for(let e=0;e.9&&a<.1&&(t<.2&&(s[e+0]+=1),i<.2&&(s[e+2]+=1),n<.2&&(s[e+4]+=1))}}()}(),this.setAttribute("position",new ji(r,3)),this.setAttribute("normal",new ji(r.slice(),3)),this.setAttribute("uv",new ji(s,2)),0===n?this.computeVertexNormals():this.normalizeNormals()}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new ja(e.vertices,e.indices,e.radius,e.details)}}class Wa extends ja{constructor(e=1,t=0){const i=(1+Math.sqrt(5))/2;super([-1,i,0,1,i,0,-1,-i,0,1,-i,0,0,-1,i,0,1,i,0,-1,-i,0,1,-i,i,0,-1,i,0,1,-i,0,-1,-i,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t),this.type="IcosahedronGeometry",this.parameters={radius:e,detail:t}}static fromJSON(e){return new Wa(e.radius,e.detail)}}class qa extends ja{constructor(e=1,t=0){super([1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],e,t),this.type="OctahedronGeometry",this.parameters={radius:e,detail:t}}static fromJSON(e){return new qa(e.radius,e.detail)}}class Xa extends ja{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t),this.type="TetrahedronGeometry",this.parameters={radius:e,detail:t}}static fromJSON(e){return new Xa(e.radius,e.detail)}}class Ya extends Ji{constructor(e=1,t=.4,i=12,n=48,r=2*Math.PI){super(),this.type="TorusGeometry",this.parameters={radius:e,tube:t,radialSegments:i,tubularSegments:n,arc:r},i=Math.floor(i),n=Math.floor(n);const s=[],a=[],o=[],l=[],c=new _t,u=new _t,h=new _t;for(let s=0;s<=i;s++)for(let d=0;d<=n;d++){const f=d/n*r,m=s/i*Math.PI*2;u.x=(e+t*Math.cos(m))*Math.cos(f),u.y=(e+t*Math.cos(m))*Math.sin(f),u.z=t*Math.sin(m),a.push(u.x,u.y,u.z),c.x=e*Math.cos(f),c.y=e*Math.sin(f),h.subVectors(u,c).normalize(),o.push(h.x,h.y,h.z),l.push(d/n),l.push(s/i)}for(let e=1;e<=i;e++)for(let t=1;t<=n;t++){const i=(n+1)*e+t-1,r=(n+1)*(e-1)+t-1,a=(n+1)*(e-1)+t,o=(n+1)*e+t;s.push(i,r,o),s.push(r,a,o)}this.setIndex(s),this.setAttribute("position",new ji(a,3)),this.setAttribute("normal",new ji(o,3)),this.setAttribute("uv",new ji(l,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Ya(e.radius,e.tube,e.radialSegments,e.tubularSegments,e.arc)}}class Ka extends yi{constructor(e,t=1){super(),this.isLight=!0,this.type="Light",this.color=new Oi(e),this.intensity=t}dispose(){}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){const t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,void 0!==this.groundColor&&(t.object.groundColor=this.groundColor.getHex()),void 0!==this.distance&&(t.object.distance=this.distance),void 0!==this.angle&&(t.object.angle=this.angle),void 0!==this.decay&&(t.object.decay=this.decay),void 0!==this.penumbra&&(t.object.penumbra=this.penumbra),void 0!==this.shadow&&(t.object.shadow=this.shadow.toJSON()),t}}const Za=new qt,Qa=new _t,Ja=new _t;class eo{constructor(e){this.camera=e,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Ge(512,512),this.map=null,this.mapPass=null,this.matrix=new qt,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Bn,this._frameExtents=new Ge(1,1),this._viewportCount=1,this._viewports=[new ht(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){const t=this.camera,i=this.matrix;Qa.setFromMatrixPosition(e.matrixWorld),t.position.copy(Qa),Ja.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(Ja),t.updateMatrixWorld(),Za.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Za),i.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),i.multiply(Za)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.bias=e.bias,this.radius=e.radius,this.mapSize.copy(e.mapSize),this}clone(){return(new this.constructor).copy(this)}toJSON(){const e={};return 0!==this.bias&&(e.bias=this.bias),0!==this.normalBias&&(e.normalBias=this.normalBias),1!==this.radius&&(e.radius=this.radius),512===this.mapSize.x&&512===this.mapSize.y||(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}}class to extends eo{constructor(){super(new Qn(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class io extends Ka{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(yi.DEFAULT_UP),this.updateMatrix(),this.target=new yi,this.shadow=new to}dispose(){this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}}class no extends Ka{constructor(e,t){super(e,t),this.isAmbientLight=!0,this.type="AmbientLight"}}const ro=new qt,so=new qt,ao=new qt;class oo{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Tn,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Tn,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(e){const t=this._cache;if(t.focus!==e.focus||t.fov!==e.fov||t.aspect!==e.aspect*this.aspect||t.near!==e.near||t.far!==e.far||t.zoom!==e.zoom||t.eyeSep!==this.eyeSep){t.focus=e.focus,t.fov=e.fov,t.aspect=e.aspect*this.aspect,t.near=e.near,t.far=e.far,t.zoom=e.zoom,t.eyeSep=this.eyeSep,ao.copy(e.projectionMatrix);const i=t.eyeSep/2,n=i*t.near/t.focus,r=t.near*Math.tan(ke*t.fov*.5)/t.zoom;let s,a;so.elements[12]=-i,ro.elements[12]=i,s=-r*t.aspect+n,a=r*t.aspect+n,ao.elements[0]=2*t.near/(a-s),ao.elements[8]=(a+s)/(a-s),this.cameraL.projectionMatrix.copy(ao),s=-r*t.aspect-n,a=r*t.aspect-n,ao.elements[0]=2*t.near/(a-s),ao.elements[8]=(a+s)/(a-s),this.cameraR.projectionMatrix.copy(ao)}this.cameraL.matrixWorld.copy(e.matrixWorld).multiply(so),this.cameraR.matrixWorld.copy(e.matrixWorld).multiply(ro)}}class lo{constructor(e){this.value=e}clone(){return new lo(void 0===this.value.clone?this.value:this.value.clone())}}function co(e){if("undefined"==typeof window)return;const t=new RegExp(`${e}=([^&#=]*)`).exec(window.location.search);return t?decodeURIComponent(t[1]):void 0}function uo(e,t){return void 0!==e?e:t}function ho(e,t){const i=Object.assign({},e);for(const n in t){void 0===e[n]&&(i[n]=t[n])}return i}function fo(e,t){for(const i in t){const n=t[i];void 0!==n&&(e[i]=n)}return e}function mo(){if("undefined"==typeof window)return!1;const e=window.navigator.userAgent;return/Opera|OPR/.test(e)?"Opera":/Chrome/i.test(e)?"Chrome":/Firefox/i.test(e)?"Firefox":/Mobile(\/.*)? Safari/i.test(e)?"Mobile Safari":/MSIE/i.test(e)?"Internet Explorer":!!/Safari/i.test(e)&&"Safari"}function po(e){window.open(e,"_blank")||(window.location.href=e)}function go(e,t="download"){if(!e)return;const i="Safari"===mo(),n=/CriOS\/[\d]+/.test(window.navigator.userAgent),r=document.createElement("a");function s(e){po(n?e:e.replace(/^data:[^;]*;/,"data:attachment/file;"))}if("undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob)navigator.msSaveOrOpenBlob(e,t);else if((i||n)&&FileReader)if(e instanceof Blob){var a=new FileReader;a.onloadend=function(){s(a.result)},a.readAsDataURL(e)}else s(e);else{let i=!1;e instanceof Blob&&(e=URL.createObjectURL(e),i=!0),"download"in r?(r.style.display="hidden",document.body.appendChild(r),r.href=e,r.download=t,r.target="_blank",r.click(),document.body.removeChild(r)):po(e),i&&window.URL.revokeObjectURL(e)}}function _o(e,t){return et?1:0}function yo(e,t,i=_o){let n=0,r=e.length-1;for(;n<=r;){const s=n+r>>1,a=i(t,e[s]);if(a>0)n=s+1;else{if(!(a<0))return s;r=s-1}}return-n-1}function vo(e,t,i){const n=function(e,t){let i=e.length-1;if(e[i]>1;e[r]>=t?i=r-1:n=r+1}return i+1}(e,t),r=function(e,t){if(e[0]>t)return-1;let i=0,n=e.length-1;for(;i<=n;){const r=i+n>>1;e[r]>t?n=r-1:i=r+1}return i-1}(e,i);return-1===n||-1===r||n>r?0:r-n+1}function bo(e){return e.sort().filter((function(e,t,i){return 0===t||e!==i[t-1]}))}function xo(e){const t=28672;if(e.length>t){const i=[];for(let n=0;n65535?Uint32Array:Uint16Array)(e)}function Mo(e){return e.buffer&&e.buffer instanceof ArrayBuffer?e.buffer:e}function Ao(e,t){return void 0===e?e=new t:Array.isArray(e)&&(e=(new t).fromArray(e)),e}function Co(e){return Ao(e,_t)}function To(e){return Ao(e,qt)}function Po(e){return Ao(e,gt)}function Eo(e){return t=e,i=Float32Array,t instanceof i?t:new i(t);var t,i}function Io(e){return uo(e,"").toString().toLowerCase()}class Do{constructor(e){this.name=e,this._dict={}}add(e,t){this._dict[Io(e)]=t}get(e){return this._dict[Io(e)]}get names(){return Object.keys(this._dict)}}function Ro(e){return.01745*e}const Lo="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),ko=new Array(36);function Oo(){let e,t=0;for(let i=0;i<36;i++)8===i||13===i||18===i||23===i?ko[i]="-":14===i?ko[i]="4":(t<=2&&(t=33554432+16777216*Math.random()|0),e=15&t,t>>=4,ko[i]=Lo[19===i?3&e|8:e]);return ko.join("")}function No(e,t,i){return Math.max(t,Math.min(i,e))}function Fo(e,t,i){return e+(t-e)*i}function Bo(e,t,i,n,r,s){const a=(i-e)*s,o=(n-t)*s,l=r*r;return(2*t-2*i+a+o)*(r*l)+(-3*t+3*i-2*a-o)*l+a*r+t}function zo(e,t,i){var n;return n=function(e,t,i){return(e-t)/(i-t)}(i,e,t),(i=No(n,0,1))*i*(3-2*i)}var Uo="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Vo(e){var t={exports:{}};return e(t,t.exports),t.exports}var $o=Vo((function(e,t){ /** * @license * * chroma.js - JavaScript library for color conversions * * Copyright (c) 2011-2017, Gregor Aisch * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The name Gregor Aisch may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL GREGOR AISCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ (function(){var i,n,r,s,a,o,l,c,u,h,d,f,m,p,g,_,y,v,b,x,w,S,M,A,C,T,P,E,I,D,R,L,k,O,N,F,B,z,U,V,$,G,H,j,W,q,X,Y,K,Z,Q,J,ee,te,ie,ne,re,se,ae,oe,le,ce,ue,he,de,fe,me,pe,ge,_e,ye,ve,be,xe,we,Se,Me,Ae,Ce,Te,Pe=[].slice;Se=function(){var e,t,i,n,r;for(e={},n=0,t=(r="Boolean Number String Function Array Date RegExp Undefined Null".split(" ")).length;ni&&(e=i),e},Me=function(e){return e.length>=3?Array.prototype.slice.call(e):e[0]},w=function(e){var t,i;for(e._clipped=!1,e._unclipped=e.slice(0),t=i=0;i<3;t=++i)t<3?((e[t]<0||e[t]>255)&&(e._clipped=!0),e[t]<0&&(e[t]=0),e[t]>255&&(e[t]=255)):3===t&&(e[t]<0&&(e[t]=0),e[t]>1&&(e[t]=1));return e._clipped||delete e._unclipped,e},s=Math.PI,ye=Math.round,M=Math.cos,E=Math.floor,ie=Math.pow,Y=Math.log,be=Math.sin,xe=Math.sqrt,p=Math.atan2,Q=Math.max,m=Math.abs,l=2*s,a=s/3,n=s/180,o=180/s,x=function(){return arguments[0]instanceof i?arguments[0]:function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,arguments,(function(){}))},x.default=x,f=[],null!==e&&null!=e.exports&&(e.exports=x),(null!==t?t:this).chroma=x,x.version="1.4.1",d={},u=[],h=!1,i=function(){function e(){var e,t,i,n,r,s,a,o,l;for(s=this,t=[],o=0,n=arguments.length;o1&&(a=t[t.length-1]),null!=d[a])s._rgb=w(d[a](Me(t.slice(0,-1))));else{for(h||(u=u.sort((function(e,t){return t.p-e.p})),h=!0),l=0,r=u.length;l3?t[3]:1]},Te=function(e){return 255*(e<=.00304?12.92*e:1.055*ie(e,1/2.4)-.055)},H=function(e){return e>r.t1?e*e*e:r.t2*(e-r.t0)},r={Kn:18,Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452},ue=function(){var e,t,i,n,r,s,a;return i=(n=Me(arguments))[0],t=n[1],e=n[2],s=(r=pe(i,t,e))[0],[116*(a=r[1])-16,500*(s-a),200*(a-r[2])]},ge=function(e){return(e/=255)<=.04045?e/12.92:ie((e+.055)/1.055,2.4)},Ce=function(e){return e>r.t3?ie(e,1/3):e/r.t2+r.t0},pe=function(){var e,t,i,n;return i=(n=Me(arguments))[0],t=n[1],e=n[2],i=ge(i),t=ge(t),e=ge(e),[Ce((.4124564*i+.3575761*t+.1804375*e)/r.Xn),Ce((.2126729*i+.7151522*t+.072175*e)/r.Yn),Ce((.0193339*i+.119192*t+.9503041*e)/r.Zn)]},x.lab=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["lab"]),(function(){}))},d.lab=G,i.prototype.lab=function(){return ue(this._rgb)},g=function(e){var t,i,n,r,s,a,o,l,c,u,h;return 2===(e=function(){var t,i,n;for(n=[],i=0,t=e.length;i=0&&t[3]<=1?"rgb":void 0}}),d.lrgb=d.rgb,z=function(e,t,n,r){var s,a;return s=e._rgb,a=t._rgb,new i(xe(ie(s[0],2)*(1-n)+ie(a[0],2)*n),xe(ie(s[1],2)*(1-n)+ie(a[1],2)*n),xe(ie(s[2],2)*(1-n)+ie(a[2],2)*n),r)},c=function(e){var t,n,r,s,a;for(t=1/e.length,a=[0,0,0,0],r=0,n=e.length;r1&&(a[3]=1),new i(w(a))},f.push(["lrgb",z]),x.average=function(e,t){var i,n,r,a,o,l,u,h,d,f,m,g,_;if(null==t&&(t="rgb"),d=e.length,e=e.map((function(e){return x(e)})),u=e.splice(0,1)[0],"lrgb"===t)return c(e);for(h in a=[],o=0,l=0,g=u.get(t))g[h]=g[h]||0,a.push(isNaN(g[h])?0:1),"h"!==t.charAt(h)||isNaN(g[h])||(i=g[h]/180*s,o+=M(i),l+=be(i));for(n=u.alpha(),m=0,f=e.length;m=360;)i-=360;g[h]=i}else g[h]=g[h]/a[h];return x(g,t).alpha(n/d)},D=function(e){var t,i;if(e.match(/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/))return 4!==e.length&&7!==e.length||(e=e.substr(1)),3===e.length&&(e=(e=e.split(""))[0]+e[0]+e[1]+e[1]+e[2]+e[2]),[(i=parseInt(e,16))>>16,i>>8&255,255&i,1];if(e.match(/^#?([A-Fa-f0-9]{8})$/))return 9===e.length&&(e=e.substr(1)),[(i=parseInt(e,16))>>24&255,i>>16&255,i>>8&255,ye((255&i)/255*100)/100];if(null!=d.css&&(t=d.css(e)))return t;throw"unknown color: "+e},ae=function(e,t){var i,n,r,s,a,o;return null==t&&(t="auto"),a=e[0],r=e[1],n=e[2],i=e[3],"auto"===t&&(t=i<1?"rgba":"rgb"),a=Math.round(a),r=Math.round(r),n=Math.round(n),o=(o="000000"+(a<<16|r<<8|n).toString(16)).substr(o.length-6),s=(s="0"+ye(255*i).toString(16)).substr(s.length-2),"#"+function(){switch(t.toLowerCase()){case"rgba":return o+s;case"argb":return s+o;default:return o}}()},d.hex=function(e){return D(e)},x.hex=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["hex"]),(function(){}))},i.prototype.hex=function(e){return null==e&&(e="auto"),ae(this._rgb,e)},u.push({p:4,test:function(e){if(1===arguments.length&&"string"===Se(e))return"hex"}}),k=function(){var e,t,i,n,r,s,a,o,l,c,u,h,d,f;if(r=(e=Me(arguments))[0],u=e[1],a=e[2],0===u)l=n=t=255*a;else{for(i=[0,0,0],h=2*a-(d=a<.5?a*(1+u):a+u-a*u),(f=[0,0,0])[0]=(r/=360)+1/3,f[1]=r,f[2]=r-1/3,s=o=0;o<=2;s=++o)f[s]<0&&(f[s]+=1),f[s]>1&&(f[s]-=1),6*f[s]<1?i[s]=h+6*(d-h)*f[s]:2*f[s]<1?i[s]=d:3*f[s]<2?i[s]=h+(d-h)*(2/3-f[s])*6:i[s]=h;l=(c=[ye(255*i[0]),ye(255*i[1]),ye(255*i[2])])[0],n=c[1],t=c[2]}return e.length>3?[l,n,t,e[3]]:[l,n,t]},le=function(e,t,i){var n,r,s,a,o;return void 0!==e&&e.length>=3&&(e=(a=e)[0],t=a[1],i=a[2]),e/=255,t/=255,i/=255,s=Math.min(e,t,i),r=((Q=Math.max(e,t,i))+s)/2,Q===s?(o=0,n=Number.NaN):o=r<.5?(Q-s)/(Q+s):(Q-s)/(2-Q-s),e===Q?n=(t-i)/(Q-s):t===Q?n=2+(i-e)/(Q-s):i===Q&&(n=4+(e-t)/(Q-s)),(n*=60)<0&&(n+=360),[n,o,r]},x.hsl=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["hsl"]),(function(){}))},d.hsl=k,i.prototype.hsl=function(){return le(this._rgb)},O=function(){var e,t,i,n,r,s,a,o,l,c,u,h,d,f,m,p,g,_;if(r=(e=Me(arguments))[0],p=e[1],_=e[2],_*=255,0===p)l=n=t=_;else switch(360===r&&(r=0),r>360&&(r-=360),r<0&&(r+=360),a=_*(1-p),o=_*(1-p*(i=(r/=60)-(s=E(r)))),g=_*(1-p*(1-i)),s){case 0:l=(c=[_,g,a])[0],n=c[1],t=c[2];break;case 1:l=(u=[o,_,a])[0],n=u[1],t=u[2];break;case 2:l=(h=[a,_,g])[0],n=h[1],t=h[2];break;case 3:l=(d=[a,o,_])[0],n=d[1],t=d[2];break;case 4:l=(f=[g,a,_])[0],n=f[1],t=f[2];break;case 5:l=(m=[_,a,o])[0],n=m[1],t=m[2]}return[l,n,t,e.length>3?e[3]:1]},ce=function(){var e,t,i,n,r,s,a,o,l;return s=(a=Me(arguments))[0],i=a[1],e=a[2],r=Math.min(s,i,e),t=(Q=Math.max(s,i,e))-r,l=Q/255,0===Q?(n=Number.NaN,o=0):(o=t/Q,s===Q&&(n=(i-e)/t),i===Q&&(n=2+(e-s)/t),e===Q&&(n=4+(s-i)/t),(n*=60)<0&&(n+=360)),[n,o,l]},x.hsv=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["hsv"]),(function(){}))},d.hsv=O,i.prototype.hsv=function(){return ce(this._rgb)},ee=function(e){return"number"===Se(e)&&e>=0&&e<=16777215?[e>>16,e>>8&255,255&e,1]:(console.warn("unknown num color: "+e),[0,0,0,1])},fe=function(){var e;return((e=Me(arguments))[0]<<16)+(e[1]<<8)+e[2]},x.num=function(e){return new i(e,"num")},i.prototype.num=function(e){return null==e&&(e="rgb"),fe(this._rgb,e)},d.num=ee,u.push({p:1,test:function(e){if(1===arguments.length&&"number"===Se(e)&&e>=0&&e<=16777215)return"num"}}),I=function(){var e,t,i,n,r,s,a,o,l,c,u,h,d,f,m,p,g,_,y,v;if(o=(i=Me(arguments))[0],r=i[1],t=i[2],a=a/100*255,e=255*(r/=100),0===r)h=a=n=t;else switch(360===o&&(o=0),o>360&&(o-=360),o<0&&(o+=360),u=(c=t*(1-r))+e*(1-(s=(o/=60)-(l=E(o)))),y=c+e*s,v=c+e,l){case 0:h=(d=[v,y,c])[0],a=d[1],n=d[2];break;case 1:h=(f=[u,v,c])[0],a=f[1],n=f[2];break;case 2:h=(m=[c,v,y])[0],a=m[1],n=m[2];break;case 3:h=(p=[c,u,v])[0],a=p[1],n=p[2];break;case 4:h=(g=[y,c,v])[0],a=g[1],n=g[2];break;case 5:h=(_=[v,c,u])[0],a=_[1],n=_[2]}return[h,a,n,i.length>3?i[3]:1]},se=function(){var e,t,i,n,r,s,a,o,l;return o=(l=Me(arguments))[0],r=l[1],t=l[2],a=Math.min(o,r,t),i=100*(n=(Q=Math.max(o,r,t))-a)/255,e=a/(255-n)*100,0===n?s=Number.NaN:(o===Q&&(s=(r-t)/n),r===Q&&(s=2+(t-o)/n),t===Q&&(s=4+(o-r)/n),(s*=60)<0&&(s+=360)),[s,i,e]},x.hcg=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["hcg"]),(function(){}))},d.hcg=I,i.prototype.hcg=function(){return se(this._rgb)},A=function(e){var t,i,n,r,s,a,o,l;if(e=e.toLowerCase(),null!=x.colors&&x.colors[e])return D(x.colors[e]);if(s=e.match(/rgb\(\s*(\-?\d+),\s*(\-?\d+)\s*,\s*(\-?\d+)\s*\)/)){for(o=s.slice(1,4),r=a=0;a<=2;r=++a)o[r]=+o[r];o[3]=1}else if(s=e.match(/rgba\(\s*(\-?\d+),\s*(\-?\d+)\s*,\s*(\-?\d+)\s*,\s*([01]|[01]?\.\d+)\)/))for(o=s.slice(1,5),r=l=0;l<=3;r=++l)o[r]=+o[r];else if(s=e.match(/rgb\(\s*(\-?\d+(?:\.\d+)?)%,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*\)/)){for(o=s.slice(1,4),r=t=0;t<=2;r=++t)o[r]=ye(2.55*o[r]);o[3]=1}else if(s=e.match(/rgba\(\s*(\-?\d+(?:\.\d+)?)%,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)/)){for(o=s.slice(1,5),r=i=0;i<=2;r=++i)o[r]=ye(2.55*o[r]);o[3]=+o[3]}else(s=e.match(/hsl\(\s*(\-?\d+(?:\.\d+)?),\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*\)/))?((n=s.slice(1,4))[1]*=.01,n[2]*=.01,(o=k(n))[3]=1):(s=e.match(/hsla\(\s*(\-?\d+(?:\.\d+)?),\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)/))&&((n=s.slice(1,4))[1]*=.01,n[2]*=.01,(o=k(n))[3]=+s[4]);return o},re=function(e){var t;return"rgb"===(t=e[3]<1?"rgba":"rgb")?t+"("+e.slice(0,3).map(ye).join(",")+")":"rgba"===t?t+"("+e.slice(0,3).map(ye).join(",")+","+e[3]+")":void 0},_e=function(e){return ye(100*e)/100},L=function(e,t){var i;return i=t<1?"hsla":"hsl",e[0]=_e(e[0]||0),e[1]=_e(100*e[1])+"%",e[2]=_e(100*e[2])+"%","hsla"===i&&(e[3]=t),i+"("+e.join(",")+")"},d.css=function(e){return A(e)},x.css=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["css"]),(function(){}))},i.prototype.css=function(e){return null==e&&(e="rgb"),"rgb"===e.slice(0,3)?re(this._rgb):"hsl"===e.slice(0,3)?L(this.hsl(),this.alpha()):void 0},d.named=function(e){return D(Ae[e])},u.push({p:5,test:function(e){if(1===arguments.length&&null!=Ae[e])return"named"}}),i.prototype.name=function(e){var t,i;for(i in arguments.length&&(Ae[e]&&(this._rgb=D(Ae[e])),this._rgb[3]=1),t=this.hex("rgb"),Ae)if(t===Ae[i])return i;return t},j=function(){var e,t,i,r;return i=(r=Me(arguments))[0],e=r[1],t=r[2],[i,M(t*=n)*e,be(t)*e]},W=function(){var e,t,i,n,r,s,a,o,l;return a=(i=Me(arguments))[0],r=i[1],s=i[2],e=(o=j(a,r,s))[0],t=o[1],n=o[2],[(l=G(e,t,n))[0],l[1],n=l[2],i.length>3?i[3]:1]},$=function(){var e,t,i,n,r,s;return r=(s=Me(arguments))[0],e=s[1],t=s[2],i=xe(e*e+t*t),n=(p(t,e)*o+360)%360,0===ye(1e4*i)&&(n=Number.NaN),[r,i,n]},he=function(){var e,t,i,n,r,s,a;return r=(s=Me(arguments))[0],i=s[1],t=s[2],n=(a=ue(r,i,t))[0],e=a[1],t=a[2],$(n,e,t)},x.lch=function(){var e;return e=Me(arguments),new i(e,"lch")},x.hcl=function(){var e;return e=Me(arguments),new i(e,"hcl")},d.lch=W,d.hcl=function(){var e,t,i,n;return t=(n=Me(arguments))[0],e=n[1],i=n[2],W([i,e,t])},i.prototype.lch=function(){return he(this._rgb)},i.prototype.hcl=function(){return he(this._rgb).reverse()},ne=function(e){var t,i,n,r,s,a;return null==e&&(e="rgb"),s=(a=Me(arguments))[0],n=a[1],t=a[2],n/=255,t/=255,[(1-(s/=255)-(r=1-Math.max(s,Math.max(n,t))))*(i=r<1?1/(1-r):0),(1-n-r)*i,(1-t-r)*i,r]},S=function(){var e,t,i,n,r,s;return i=(t=Me(arguments))[0],r=t[1],s=t[2],n=t[3],e=t.length>4?t[4]:1,1===n?[0,0,0,e]:[i>=1?0:255*(1-i)*(1-n),r>=1?0:255*(1-r)*(1-n),s>=1?0:255*(1-s)*(1-n),e]},d.cmyk=function(){return S(Me(arguments))},x.cmyk=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["cmyk"]),(function(){}))},i.prototype.cmyk=function(){return ne(this._rgb)},d.gl=function(){var e,t,i,n,r;for(n=function(){var e,i;for(t in i=[],e=Me(arguments))r=e[t],i.push(r);return i}.apply(this,arguments),e=i=0;i<=2;e=++i)n[e]*=255;return n},x.gl=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["gl"]),(function(){}))},i.prototype.gl=function(){var e;return[(e=this._rgb)[0]/255,e[1]/255,e[2]/255,e[3]]},de=function(e,t,i){var n;return e=(n=Me(arguments))[0],t=n[1],i=n[2],.2126*(e=K(e))+.7152*(t=K(t))+.0722*(i=K(i))},K=function(e){return(e/=255)<=.03928?e/12.92:ie((e+.055)/1.055,2.4)},V=function(e,t,n,r){var s,a;return s=e._rgb,a=t._rgb,new i(s[0]+n*(a[0]-s[0]),s[1]+n*(a[1]-s[1]),s[2]+n*(a[2]-s[2]),r)},f.push(["rgb",V]),i.prototype.luminance=function(e,t){var i,n,r,s;return null==t&&(t="rgb"),arguments.length?(r=this._rgb,0===e?r=[0,0,0,this._rgb[3]]:1===e?r=[255,255,255,this[3]]:(i=de(this._rgb),1e-7,n=20,s=function(i,r){var a,o;return a=(o=i.interpolate(r,.5,t)).luminance(),Math.abs(e-a)<1e-7||!n--?o:a>e?s(i,o):s(o,r)},r=i>e?s(x("black"),this).rgba():s(this,x("white")).rgba()),x(r).alpha(this.alpha())):de(this._rgb)},we=function(e){var t,i,n,r;return(r=e/100)<66?(n=255,i=-155.25485562709179-.44596950469579133*(i=r-2)+104.49216199393888*Y(i),t=r<20?0:.8274096064007395*(t=r-10)-254.76935184120902+115.67994401066147*Y(t)):(n=351.97690566805693+.114206453784165*(n=r-55)-40.25366309332127*Y(n),i=325.4494125711974+.07943456536662342*(i=r-50)-28.0852963507957*Y(i),t=255),[n,i,t]},me=function(){var e,t,i,n,r,s,a;for(n=(r=Me(arguments))[0],r[1],e=r[2],i=1e3,t=4e4,.4;t-i>.4;)(s=we(a=.5*(t+i)))[2]/s[0]>=e/n?t=a:i=a;return ye(a)},x.temperature=x.kelvin=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["temperature"]),(function(){}))},d.temperature=d.kelvin=d.K=we,i.prototype.temperature=function(){return me(this._rgb)},i.prototype.kelvin=i.prototype.temperature,x.contrast=function(e,t){var n,r,s,a;return"string"!==(s=Se(e))&&"number"!==s||(e=new i(e)),"string"!==(a=Se(t))&&"number"!==a||(t=new i(t)),(n=e.luminance())>(r=t.luminance())?(n+.05)/(r+.05):(r+.05)/(n+.05)},x.distance=function(e,t,n){var r,s,a,o,l,c,u;for(s in null==n&&(n="lab"),"string"!==(l=Se(e))&&"number"!==l||(e=new i(e)),"string"!==(c=Se(t))&&"number"!==c||(t=new i(t)),a=e.get(n),o=t.get(n),u=0,a)u+=(r=(a[s]||0)-(o[s]||0))*r;return Math.sqrt(u)},x.deltaE=function(e,t,n,r){var a,o,l,c,u,h,d,f,g,_,y,v,b,x,w,S,A,C,T,P,E,I,D,R;for(null==n&&(n=1),null==r&&(r=1),"string"!==(w=Se(e))&&"number"!==w||(e=new i(e)),"string"!==(S=Se(t))&&"number"!==S||(t=new i(t)),a=(A=e.lab())[0],l=A[1],u=A[2],o=(C=t.lab())[0],c=C[1],h=C[2],d=xe(l*l+u*u),f=xe(c*c+h*h),P=a<16?.511:.040975*a/(1+.01765*a),T=.0638*d/(1+.0131*d)+.638,x=d<1e-6?0:180*p(u,l)/s;x<0;)x+=360;for(;x>=360;)x-=360;return E=x>=164&&x<=345?.56+m(.2*M(s*(x+168)/180)):.36+m(.4*M(s*(x+35)/180)),b=xe((g=d*d*d*d)/(g+1900)),xe((I=(a-o)/(n*P))*I+(D=(v=d-f)/(r*T))*D+((_=l-c)*_+(y=u-h)*y-v*v)/((R=T*(b*E+1-b))*R))},i.prototype.get=function(e){var t,i,n,r,s;return this,n=(r=e.split("."))[0],t=r[1],s=this[n](),t?(i=n.indexOf(t))>-1?s[i]:console.warn("unknown channel "+t+" in mode "+n):s},i.prototype.set=function(e,t){var i,n,r,s,a;if(this,r=(s=e.split("."))[0],i=s[1])if(a=this[r](),(n=r.indexOf(i))>-1)if("string"===Se(t))switch(t.charAt(0)){case"+":case"-":a[n]+=+t;break;case"*":a[n]*=+t.substr(1);break;case"/":a[n]/=+t.substr(1);break;default:a[n]=+t}else a[n]=t;else console.warn("unknown channel "+i+" in mode "+r);else a=t;return x(a,r).alpha(this.alpha())},i.prototype.clipped=function(){return this._rgb._clipped||!1},i.prototype.alpha=function(e){return arguments.length?x.rgb([this._rgb[0],this._rgb[1],this._rgb[2],e]):this._rgb[3]},i.prototype.darken=function(e){var t;return null==e&&(e=1),this,(t=this.lab())[0]-=r.Kn*e,x.lab(t).alpha(this.alpha())},i.prototype.brighten=function(e){return null==e&&(e=1),this.darken(-e)},i.prototype.darker=i.prototype.darken,i.prototype.brighter=i.prototype.brighten,i.prototype.saturate=function(e){var t;return null==e&&(e=1),this,(t=this.lch())[1]+=e*r.Kn,t[1]<0&&(t[1]=0),x.lch(t).alpha(this.alpha())},i.prototype.desaturate=function(e){return null==e&&(e=1),this.saturate(-e)},i.prototype.premultiply=function(){var e,t;return t=this.rgb(),e=this.alpha(),x(t[0]*e,t[1]*e,t[2]*e,e)},J=function(e,t){return e*t/255},C=function(e,t){return e>t?t:e},q=function(e,t){return e>t?e:t},ve=function(e,t){return 255*(1-(1-e/255)*(1-t/255))},te=function(e,t){return t<128?2*e*t/255:255*(1-2*(1-e/255)*(1-t/255))},b=function(e,t){return 255*(1-(1-t/255)/(e/255))},T=function(e,t){return 255===e||(e=t/255*255/(1-e/255))>255?255:e},(_=function(e,t,i){if(!_[i])throw"unknown blend mode "+i;return _[i](e,t)}).normal=(y=function(e){return function(t,i){var n,r;return n=x(i).rgb(),r=x(t).rgb(),x(e(n,r),"rgb")}})((P=function(e){return function(t,i){var n,r,s;for(s=[],n=r=0;r<=3;n=++r)s[n]=e(t[n],i[n]);return s}})((function(e,t){return e}))),_.multiply=y(P(J)),_.screen=y(P(ve)),_.overlay=y(P(te)),_.darken=y(P(C)),_.lighten=y(P(q)),_.dodge=y(P(T)),_.burn=y(P(b)),x.blend=_,x.analyze=function(e){var t,i,n,r;for(n={min:Number.MAX_VALUE,max:-1*Number.MAX_VALUE,sum:0,values:[],count:0},i=0,t=e.length;in.max&&(n.max=r),n.count+=1);return n.domain=[n.min,n.max],n.limits=function(e,t){return x.limits(n,e,t)},n},x.scale=function(e,t){var i,n,r,s,a,o,l,c,u,h,d,f,m,p,g,_,y,v,b,w,S;return u="rgb",h=x("#ccc"),p=0,a=[0,1],m=[],f=[0,0],i=!1,r=[],d=!1,c=0,l=1,s=!1,n={},g=!0,o=1,w=function(e){var t,i,n,s,a,o;if(null==e&&(e=["#fff","#000"]),null!=e&&"string"===Se(e)&&null!=x.brewer&&(e=x.brewer[e]||x.brewer[e.toLowerCase()]||e),"array"===Se(e)){for(1===e.length&&(e=[e[0],e[0]]),t=n=0,s=(e=e.slice(0)).length-1;0<=s?n<=s:n>=s;t=0<=s?++n:--n)i=e[t],"string"===Se(i)&&(e[t]=x(i));for(m.length=0,t=o=0,a=e.length-1;0<=a?o<=a:o>=a;t=0<=a?++o:--o)m.push(t/(e.length-1))}return b(),r=e},y=function(e){var t,n;if(null!=i){for(n=i.length-1,t=0;t=i[t];)t++;return t-1}return 0},S=function(e){return e},v=function(e,t){var s,a,d,p,_,v,b;if(null==t&&(t=!1),isNaN(e)||null===e)return h;if(b=t?e:i&&i.length>2?y(e)/(i.length-2):l!==c?(e-c)/(l-c):1,t||(b=S(b)),1!==o&&(b=ie(b,o)),b=f[0]+b*(1-f[0]-f[1]),b=Math.min(1,Math.max(0,b)),d=Math.floor(1e4*b),g&&n[d])s=n[d];else{if("array"===Se(r))for(a=p=0,v=m.length-1;0<=v?p<=v:p>=v;a=0<=v?++p:--p){if(b<=(_=m[a])){s=r[a];break}if(b>=_&&a===m.length-1){s=r[a];break}if(b>_&&b=u;t=0<=u?++h:--h)m.push(t/(n-1));return a=[c,l],_},_.mode=function(e){return arguments.length?(u=e,b(),_):u},_.range=function(e,t){return w(e),_},_.out=function(e){return d=e,_},_.spread=function(e){return arguments.length?(p=e,_):p},_.correctLightness=function(e){return null==e&&(e=!0),s=e,b(),S=s?function(e){var t,i,n,r,s,a,o,l,c;for(t=v(0,!0).lab()[0],i=v(1,!0).lab()[0],o=t>i,n=v(e,!0).lab()[0],r=n-(s=t+(i-t)*e),l=0,c=1,a=20;Math.abs(r)>.01&&a-- >0;)o&&(r*=-1),r<0?(l=e,e+=.5*(c-e)):(c=e,e+=.5*(l-e)),n=v(e,!0).lab()[0],r=n-s;return e}:function(e){return e},_},_.padding=function(e){return null!=e?("number"===Se(e)&&(e=[e,e]),f=e,_):f},_.colors=function(t,n){var s,o,l,c,u,h,d,f;if(arguments.length<2&&(n="hex"),u=[],0===arguments.length)u=r.slice(0);else if(1===t)u=[_(.5)];else if(t>1)o=a[0],s=a[1]-o,u=function(){h=[];for(var e=0;0<=t?et;0<=t?e++:e--)h.push(e);return h}.apply(this).map((function(e){return _(o+e/(t-1)*s)}));else{if(e=[],d=[],i&&i.length>2)for(l=f=1,c=i.length;1<=c?fc;l=1<=c?++f:--f)d.push(.5*(i[l-1]+i[l]));else d=a;u=d.map((function(e){return _(e)}))}return x[n]&&(u=u.map((function(e){return e[n]()}))),u},_.cache=function(e){return null!=e?(g=e,_):g},_.gamma=function(e){return null!=e?(o=e,_):o},_.nodata=function(e){return null!=e?(h=x(e),_):h},_},null==x.scales&&(x.scales={}),x.scales.cool=function(){return x.scale([x.hsl(180,1,.9),x.hsl(250,.7,.4)])},x.scales.hot=function(){return x.scale(["#000","#f00","#ff0","#fff"],[0,.25,.75,1]).mode("rgb")},x.analyze=function(e,t,i){var n,r,s,a,o,l;if(o={min:Number.MAX_VALUE,max:-1*Number.MAX_VALUE,sum:0,values:[],count:0},null==i&&(i=function(){return!0}),n=function(e){null==e||isNaN(e)||(o.values.push(e),o.sum+=e,eo.max&&(o.max=e),o.count+=1)},l=function(e,r){if(i(e,r))return null!=t&&"function"===Se(t)?n(t(e)):null!=t&&"string"===Se(t)||"number"===Se(t)?n(e[t]):n(e)},"array"===Se(e))for(a=0,s=e.length;a=U;M=1<=U?++N:--N)T.push(I+M/i*(Q-I));T.push(Q)}else if("l"===t.substr(0,1)){if(I<=0)throw"Logarithmic scales are only possible for values > 0";for(D=Math.LOG10E*Y(I),P=Math.LOG10E*Y(Q),T.push(I),M=ce=1,V=i-1;1<=V?ce<=V:ce>=V;M=1<=V?++ce:--ce)T.push(ie(10,D+M/i*(P-D)));T.push(Q)}else if("q"===t.substr(0,1)){for(T.push(I),M=n=1,q=i-1;1<=q?n<=q:n>=q;M=1<=q?++n:--n)F=(le.length-1)*M/i,(B=E(F))===F?T.push(le[B]):(z=F-B,T.push(le[B]*(1-z)+le[B+1]*z));T.push(Q)}else if("k"===t.substr(0,1)){for(L=le.length,_=new Array(L),w=new Array(i),re=!0,k=0,v=null,(v=[]).push(I),M=r=1,X=i-1;1<=X?r<=X:r>=X;M=1<=X?++r:--r)v.push(I+M/i*(Q-I));for(v.push(Q);re;){for(A=s=0,K=i-1;0<=K?s<=K:s>=K;A=0<=K?++s:--s)w[A]=0;for(M=a=0,Z=L-1;0<=Z?a<=Z:a>=Z;M=0<=Z?++a:--a){for(oe=le[M],R=Number.MAX_VALUE,A=o=0,J=i-1;0<=J?o<=J:o>=J;A=0<=J?++o:--o)(S=m(v[A]-oe))=ee;A=0<=ee?++l:--l)O[A]=null;for(M=c=0,te=L-1;0<=te?c<=te:c>=te;M=0<=te?++c:--c)null===O[b=_[M]]?O[b]=le[M]:O[b]+=le[M];for(A=u=0,ne=i-1;0<=ne?u<=ne:u>=ne;A=0<=ne?++u:--u)O[A]*=1/w[A];for(re=!1,A=h=0,$=i-1;0<=$?h<=$:h>=$;A=0<=$?++h:--h)if(O[A]!==v[M]){re=!0;break}v=O,++k>200&&(re=!1)}for(C={},A=d=0,G=i-1;0<=G?d<=G:d>=G;A=0<=G?++d:--d)C[A]=[];for(M=f=0,H=L-1;0<=H?f<=H:f>=H;M=0<=H?++f:--f)C[b=_[M]].push(le[M]);for(se=[],A=p=0,j=i-1;0<=j?p<=j:p>=j;A=0<=j?++p:--p)se.push(C[A][0]),se.push(C[A][C[A].length-1]);for(se=se.sort((function(e,t){return e-t})),T.push(se[0]),M=g=1,W=se.length-1;g<=W;M=g+=2)ae=se[M],isNaN(ae)||-1!==T.indexOf(ae)||T.push(ae)}return T},R=function(e,t,i){var n,r,s,o;return e=(n=Me(arguments))[0],t=n[1],i=n[2],isNaN(e)&&(e=0),(e/=360)<1/3?s=1-((r=(1-t)/3)+(o=(1+t*M(l*e)/M(a-l*e))/3)):e<2/3?r=1-((o=(1-t)/3)+(s=(1+t*M(l*(e-=1/3))/M(a-l*e))/3)):o=1-((s=(1-t)/3)+(r=(1+t*M(l*(e-=2/3))/M(a-l*e))/3)),[255*(o=X(i*o*3)),255*(s=X(i*s*3)),255*(r=X(i*r*3)),n.length>3?n[3]:1]},oe=function(){var e,t,i,n,r,s,a;return r=(s=Me(arguments))[0],t=s[1],e=s[2],l=2*Math.PI,r/=255,t/=255,e/=255,0===(a=1-Math.min(r,t,e)/(n=(r+t+e)/3))?i=0:(i=(r-t+(r-e))/2,i/=Math.sqrt((r-t)*(r-t)+(r-e)*(t-e)),i=Math.acos(i),e>t&&(i=l-i),i/=l),[360*i,a,n]},x.hsi=function(){return function(e,t,i){i.prototype=e.prototype;var n=new i,r=e.apply(n,t);return Object(r)===r?r:n}(i,Pe.call(arguments).concat(["hsi"]),(function(){}))},d.hsi=R,i.prototype.hsi=function(){return oe(this._rgb)},F=function(e,t,i,n){var r,s,a,o,l,c,u,h,d,f;return"hsl"===n?(d=e.hsl(),f=t.hsl()):"hsv"===n?(d=e.hsv(),f=t.hsv()):"hcg"===n?(d=e.hcg(),f=t.hcg()):"hsi"===n?(d=e.hsi(),f=t.hsi()):"lch"!==n&&"hcl"!==n||(n="hcl",d=e.hcl(),f=t.hcl()),"h"===n.substr(0,1)&&(s=d[0],u=d[1],o=d[2],a=f[0],h=f[1],l=f[2]),isNaN(s)||isNaN(a)?isNaN(s)?isNaN(a)?r=Number.NaN:(r=a,1!==o&&0!==o||"hsv"===n||(c=h)):(r=s,1!==l&&0!==l||"hsv"===n||(c=u)):r=s+i*(a>s&&a-s>180?a-(s+360):a180?a+360-s:a-s),null==c&&(c=u+i*(h-u)),x[n](r,c,o+i*(l-o))},U=function(e,t,i,n){var r,s;return r=e.num(),s=t.num(),x.num(r+(s-r)*i,"num")},(f=f.concat(function(){var e,t,i,n;for(n=[],t=0,e=(i=["hsv","hsl","hsi","hcl","lch","hcg"]).length;t>16&255)/255,t[i+1]=(e>>8&255)/255,t[i+2]=(255&e)/255,t}atomColorToArray(e,t,i){return this.colorToArray(this.atomColor?this.atomColor(e):0,t,i)}bondColor(e,t){return this.atomProxy&&this.atomColor?(this.atomProxy.index=t?e.atomIndex1:e.atomIndex2,this.atomColor(this.atomProxy)):0}bondColorToArray(e,t,i,n){return this.colorToArray(this.bondColor(e,t),i,n)}volumeColorToArray(e,t,i){return this.colorToArray(this.volumeColor?this.volumeColor(e):0,t,i)}positionColorToArray(e,t,i){return this.colorToArray(this.positionColor?this.positionColor(e):0,t,i)}}var Xo,Yo=Vo((function(e){ /** @license * JS Signals * Released under the MIT license * Author: Miller Medeiros * Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM) */ !function(t){function i(e,t,i,n,r){this._listener=t,this._isOnce=i,this.context=n,this._signal=e,this._priority=r||0}function n(e,t){if("function"!=typeof e)throw new Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",t))}function r(){this._bindings=[],this._prevParams=null;var e=this;this.dispatch=function(){r.prototype.dispatch.apply(e,arguments)}}i.prototype={active:!0,params:null,execute:function(e){var t,i;return this.active&&this._listener&&(i=this.params?this.params.concat(e):e,t=this._listener.apply(this.context,i),this._isOnce&&this.detach()),t},detach:function(){return this.isBound()?this._signal.remove(this._listener,this.context):null},isBound:function(){return!!this._signal&&!!this._listener},isOnce:function(){return this._isOnce},getListener:function(){return this._listener},getSignal:function(){return this._signal},_destroy:function(){delete this._signal,delete this._listener,delete this.context},toString:function(){return"[SignalBinding isOnce:"+this._isOnce+", isBound:"+this.isBound()+", active:"+this.active+"]"}},r.prototype={VERSION:"1.0.0",memorize:!1,_shouldPropagate:!0,active:!0,_registerListener:function(e,t,n,r){var s,a=this._indexOfListener(e,n);if(-1!==a){if((s=this._bindings[a]).isOnce()!==t)throw new Error("You cannot add"+(t?"":"Once")+"() then add"+(t?"Once":"")+"() the same listener without removing the relationship first.")}else s=new i(this,e,t,n,r),this._addBinding(s);return this.memorize&&this._prevParams&&s.execute(this._prevParams),s},_addBinding:function(e){var t=this._bindings.length;do{--t}while(this._bindings[t]&&e._priority<=this._bindings[t]._priority);this._bindings.splice(t+1,0,e)},_indexOfListener:function(e,t){for(var i,n=this._bindings.length;n--;)if((i=this._bindings[n])._listener===e&&i.context===t)return n;return-1},has:function(e,t){return-1!==this._indexOfListener(e,t)},add:function(e,t,i){return n(e,"add"),this._registerListener(e,!1,t,i)},addOnce:function(e,t,i){return n(e,"addOnce"),this._registerListener(e,!0,t,i)},remove:function(e,t){n(e,"remove");var i=this._indexOfListener(e,t);return-1!==i&&(this._bindings[i]._destroy(),this._bindings.splice(i,1)),e},removeAll:function(){for(var e=this._bindings.length;e--;)this._bindings[e]._destroy();this._bindings.length=0},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},dispatch:function(e){if(this.active){var t,i=Array.prototype.slice.call(arguments),n=this._bindings.length;if(this.memorize&&(this._prevParams=i),n){t=this._bindings.slice(),this._shouldPropagate=!0;do{n--}while(t[n]&&this._shouldPropagate&&!1!==t[n].execute(i))}}},forget:function(){this._prevParams=null},dispose:function(){this.removeAll(),delete this._bindings,delete this._prevParams},toString:function(){return"[Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"}};var s=r;s.Signal=r,e.exports?e.exports=s:t.signals=s}(Uo)}));!function(e){e[e.PROTEIN=1]="PROTEIN",e[e.NUCLEIC=2]="NUCLEIC",e[e.RNA=3]="RNA",e[e.DNA=4]="DNA",e[e.POLYMER=5]="POLYMER",e[e.WATER=6]="WATER",e[e.HELIX=7]="HELIX",e[e.SHEET=8]="SHEET",e[e.TURN=9]="TURN",e[e.BACKBONE=10]="BACKBONE",e[e.SIDECHAIN=11]="SIDECHAIN",e[e.ALL=12]="ALL",e[e.HETERO=13]="HETERO",e[e.ION=14]="ION",e[e.SACCHARIDE=15]="SACCHARIDE",e[e.SUGAR=15]="SUGAR",e[e.BONDED=16]="BONDED",e[e.RING=17]="RING",e[e.AROMATICRING=18]="AROMATICRING",e[e.METAL=19]="METAL",e[e.POLARH=20]="POLARH",e[e.NONE=21]="NONE"}(Xo||(Xo={}));const Ko=["*","","ALL"],Zo=["NONE"],Qo=[Xo.BACKBONE,Xo.SIDECHAIN,Xo.BONDED,Xo.RING,Xo.AROMATICRING,Xo.METAL,Xo.POLARH],Jo=[Xo.POLYMER,Xo.WATER],el=["ALA","GLY","SER"],tl=["CYS","SER","THR"],il=["ALA","ILE","LEU","MET","PHE","PRO","TRP","VAL"],nl=["PHE","TRP","TYR","HIS"],rl=["ASN","GLN"],sl=["ASP","GLU"],al=["ARG","HIS","LYS"],ol=["ARG","ASP","GLU","HIS","LYS"],ll=["ASN","ARG","ASP","CYS","GLY","GLN","GLU","HIS","LYS","SER","THR","TYR"],cl=["ALA","ILE","LEU","MET","PHE","PRO","TRP","VAL"],ul=["HIS","PHE","PRO","TRP","TYR"],hl=["ALA","GLY","ILE","LEU","VAL"];function dl(e,t){if(void 0===t.atomname&&void 0===t.element&&void 0===t.altloc&&void 0===t.atomindex&&void 0===t.keyword&&void 0===t.inscode&&void 0===t.resname&&void 0===t.sstruc&&void 0===t.resno&&void 0===t.chainname&&void 0===t.model)return-1;if(void 0!==t.keyword){if(t.keyword===Xo.BACKBONE&&!e.isBackbone())return!1;if(t.keyword===Xo.SIDECHAIN&&!e.isSidechain())return!1;if(t.keyword===Xo.BONDED&&!e.isBonded())return!1;if(t.keyword===Xo.RING&&!e.isRing())return!1;if(t.keyword===Xo.AROMATICRING&&!e.isAromatic())return!1;if(t.keyword===Xo.HETERO&&!e.isHetero())return!1;if(t.keyword===Xo.PROTEIN&&!e.isProtein())return!1;if(t.keyword===Xo.NUCLEIC&&!e.isNucleic())return!1;if(t.keyword===Xo.RNA&&!e.isRna())return!1;if(t.keyword===Xo.DNA&&!e.isDna())return!1;if(t.keyword===Xo.POLYMER&&!e.isPolymer())return!1;if(t.keyword===Xo.WATER&&!e.isWater())return!1;if(t.keyword===Xo.HELIX&&!e.isHelix())return!1;if(t.keyword===Xo.SHEET&&!e.isSheet())return!1;if(t.keyword===Xo.TURN&&!e.isTurn())return!1;if(t.keyword===Xo.ION&&!e.isIon())return!1;if(t.keyword===Xo.SACCHARIDE&&!e.isSaccharide())return!1;if(t.keyword===Xo.METAL&&!e.isMetal())return!1;if(t.keyword===Xo.POLARH&&!e.isPolarHydrogen())return!1}if(void 0!==t.atomname&&t.atomname!==e.atomname)return!1;if(void 0!==t.element&&t.element!==e.element)return!1;if(void 0!==t.altloc&&t.altloc!==e.altloc)return!1;if(void 0!==t.atomindex&&yo(t.atomindex,e.index)<0)return!1;if(void 0!==t.resname)if(Array.isArray(t.resname)){if(!t.resname.includes(e.resname))return!1}else if(t.resname!==e.resname)return!1;if(void 0!==t.sstruc&&t.sstruc!==e.sstruc)return!1;if(void 0!==t.resno)if(Array.isArray(t.resno)&&2===t.resno.length){if(t.resno[0]>e.resno||t.resno[1]e.resno||t.resno[1]0?e:null}function yl(e,t=!1){let i=e;return t&&(i=_l(e,(function(e){return void 0!==e.keyword&&!Qo.includes(e.keyword)||(void 0!==e.model||(void 0!==e.chainname||(void 0!==e.resname||(void 0!==e.resno||void 0!==e.sstruc))))}))),gl(i,dl)}function vl(e,t=!1){let i=e;return t&&(i=_l(e,(function(e){return!(void 0===e.keyword||!Qo.includes(e.keyword))||(void 0!==e.model||(void 0!==e.chainname||(void 0!==e.atomname||(void 0!==e.element||void 0!==e.altloc))))}))),gl(i,fl)}function bl(e,t=!1){let i=e;return t&&(i=_l(e,(function(e){return void 0!==e.keyword&&!Jo.includes(e.keyword)||(void 0!==e.resname||(void 0!==e.resno||(void 0!==e.atomname||(void 0!==e.element||(void 0!==e.altloc||(void 0!==e.sstruc||void 0!==e.inscode))))))}))),gl(i,ml)}function xl(e,t=!1){let i=e;return t&&(i=_l(e,(function(e){return void 0!==e.keyword||(void 0!==e.chainname||(void 0!==e.resname||(void 0!==e.resno||(void 0!==e.atomname||(void 0!==e.element||(void 0!==e.altloc||(void 0!==e.sstruc||void 0!==e.inscode)))))))}))),gl(i,pl)}class wl{constructor(e){this.signals={stringChanged:new Yo.Signal},this.setString(e)}get type(){return"selection"}setString(e,t){if(void 0===e&&(e=this.string||""),e===this.string)return;try{this.selection=function(e){let t={operator:void 0,rules:[]};if(!e)return t;let i,n,r=t;const s=[];"("===(e=e.replace(/\(/g," ( ").replace(/\)/g," ) ").trim()).charAt(0)&&")"===e.substr(-1)&&(e=e.slice(1,-1).trim());const a=e.split(/\s+/),o=e=>{i={operator:e,rules:[]},void 0===r?(r=i,t=i):(r.rules.push(i),s.push(r),r=i)},l=function(e){n=r,r=s.pop(),void 0===r&&(o(e),c(n))},c=function(e){r.rules.push(e)};let u=!1;for(let e=0;e0)if("NOT"===i)u=1;else if(1===u)u=2;else{if(2!==u)throw new Error("something went wrong with 'not'");u=!1,l()}if("AND"===i){if("OR"===r.operator){const e=r.rules.pop();o("AND"),c(e)}else r.operator="AND";continue}if("OR"===i){"AND"===r.operator?l("OR"):r.operator="OR";continue}if("NOT"===t.toUpperCase()){u=1,o(),r.negate=!0;continue}if(+i!=+i){const e=Xo[i];if(void 0!==e){c({keyword:e});continue}}if("HYDROGEN"===i){c({operator:"OR",rules:[{element:"H"},{element:"D"}]});continue}if("SMALL"===i){c({resname:el});continue}if("NUCLEOPHILIC"===i){c({resname:tl});continue}if("HYDROPHOBIC"===i){c({resname:il});continue}if("AROMATIC"===i){c({resname:nl});continue}if("AMIDE"===i){c({resname:rl});continue}if("ACIDIC"===i){c({resname:sl});continue}if("BASIC"===i){c({resname:al});continue}if("CHARGED"===i){c({resname:ol});continue}if("POLAR"===i){c({resname:ll});continue}if("NONPOLAR"===i){c({resname:cl});continue}if("CYCLIC"===i){c({resname:ul});continue}if("ALIPHATIC"===i){c({resname:hl});continue}if("SIDECHAINATTACHED"===i){c({operator:"OR",rules:[{keyword:Xo.SIDECHAIN},{operator:"AND",negate:!1,rules:[{keyword:Xo.PROTEIN},{operator:"OR",negate:!1,rules:[{atomname:"CA"},{atomname:"BB"}]}]},{operator:"AND",negate:!1,rules:[{resname:"PRO"},{atomname:"N"}]},{operator:"AND",negate:!1,rules:[{keyword:Xo.NUCLEIC},{operator:"OR",negate:!0,rules:[{atomname:"P"},{atomname:"OP1"},{atomname:"OP2"},{atomname:"O3'"},{atomname:"O3*"},{atomname:"HO3'"},{atomname:"O5'"},{atomname:"O5*"},{atomname:"HO5'"},{atomname:"C5'"},{atomname:"C5*"},{atomname:"H5'"},{atomname:"H5''"}]}]}]});continue}if("APOLARH"===i){c({operator:"AND",negate:!1,rules:[{element:"H"},{negate:!0,operator:void 0,rules:[{keyword:Xo.POLARH}]}]});continue}if("LIGAND"===i){c({operator:"AND",rules:[{operator:"OR",rules:[{operator:"AND",rules:[{keyword:Xo.HETERO},{negate:!0,operator:void 0,rules:[{keyword:Xo.POLYMER}]}]},{negate:!0,operator:void 0,rules:[{keyword:Xo.POLYMER}]}]},{negate:!0,operator:void 0,rules:[{operator:"OR",rules:[{keyword:Xo.WATER},{keyword:Xo.ION}]}]}]});continue}if(-1!==Ko.indexOf(i)){c({keyword:Xo.ALL});continue}if("@"===t.charAt(0)){const e=t.substr(1).split(",").map((e=>parseInt(e)));e.sort((function(e,t){return e-t})),c({atomindex:e});continue}if("#"===t.charAt(0)){console.error("# for element selection deprecated, use _"),c({element:i.substr(1)});continue}if("_"===t.charAt(0)){c({element:i.substr(1)});continue}if("["===t[0]&&"]"===t[t.length-1]){const e=i.substr(1,t.length-2).split(","),n=e.length>1?e:e[0];c({resname:n});continue}if(t.length>=1&&t.length<=4&&"^"!==t[0]&&":"!==t[0]&&"."!==t[0]&&"%"!==t[0]&&"/"!==t[0]&&isNaN(parseInt(t))){c({resname:i});continue}const n={operator:"AND",rules:[]},s=t.split("/");if(s.length>1&&s[1]){if(isNaN(parseInt(s[1])))throw new Error("model must be an integer");n.rules.push({model:parseInt(s[1])})}const h=s[0].split("%");h.length>1&&n.rules.push({altloc:h[1]});const d=h[0].split(".");if(d.length>1&&d[1]){if(d[1].length>4)throw new Error("atomname must be one to four characters");n.rules.push({atomname:d[1].substring(0,4).toUpperCase()})}const f=d[0].split(":");f.length>1&&f[1]&&n.rules.push({chainname:f[1]});const m=f[0].split("^");if(m.length>1&&n.rules.push({inscode:m[1]}),m[0]){let e,t;"-"===m[0][0]&&(m[0]=m[0].substr(1),e=!0),m[0].includes("--")&&(m[0]=m[0].replace("--","-"),t=!0);let i=m[0].split("-");if(1===i.length){let t=parseInt(i[0]);if(isNaN(t))throw new Error("resi must be an integer");e&&(t*=-1),n.rules.push({resno:t})}else{if(2!==i.length)throw new Error("resi range must contain one '-'");{const r=i.map((e=>parseInt(e)));e&&(r[0]*=-1),t&&(r[1]*=-1),n.rules.push({resno:[r[0],r[1]]})}}}if(1===n.rules.length)c(n.rules[0]);else{if(!(n.rules.length>1))throw new Error("empty selection chunk");c(n)}}return void 0===t.operator&&1===t.rules.length&&t.rules[0].hasOwnProperty("operator")&&(t=t.rules[0]),t}(e)}catch(e){this.selection={error:e.message}}const i=this.selection;this.string=e,this.test=yl(i),this.residueTest=vl(i),this.chainTest=bl(i),this.modelTest=xl(i),this.atomOnlyTest=yl(i,!0),this.residueOnlyTest=vl(i,!0),this.chainOnlyTest=bl(i,!0),this.modelOnlyTest=xl(i,!0),t||this.signals.stringChanged.dispatch(this.string)}isAllSelection(){return Ko.includes(this.string.toUpperCase())}isNoneSelection(){return Zo.includes(this.string.toUpperCase())}}class Sl extends qo{constructor(e){super(e),this.colormakerList=[],this.selectionList=[];(e.dataList||[]).forEach((e=>{const[t,i,n={}]=e;$l.hasScheme(t)?Object.assign(n,{scheme:t,structure:this.parameters.structure}):Object.assign(n,{scheme:"uniform",value:new Oi(t).getHex()}),this.colormakerList.push($l.getScheme(n)),this.selectionList.push(new wl(i))}))}atomColor(e){for(let t=0,i=this.selectionList.length;t{}),e)}catch(e){}const Rl="undefined"!=typeof window&&void 0!==window.orientation;let Ll=!1;function kl(e){Ll=e}let Ol=!1;function Nl(e){Ol=e}const Fl={log:Function.prototype.bind.call(console.log,console),info:Function.prototype.bind.call(console.info,console),warn:Function.prototype.bind.call(console.warn,console),error:Function.prototype.bind.call(console.error,console),time:Function.prototype.bind.call(console.time,console),timeEnd:Function.prototype.bind.call(console.timeEnd,console)};let Bl={color:"green",labelColor:8421504,labelAttachment:"bottom-center",labelSize:.7,labelZOffset:.5,labelYOffset:.1,labelBorder:!0,labelBorderColor:13882323,labelBorderWidth:.25,lineOpacity:.8,linewidth:5,opacity:.6,labelUnit:"angstrom",arcVisible:!0,planeVisible:!1};var zl;e.Debug=!!(zl=co("debug"))&&("string"!=typeof zl||/^1|true|t|yes|y$/i.test(zl));const Ul=["ngl","js"],Vl=new class{constructor(){this.activeWorkerCount=0,this._funcDict={},this._depsDict={},this._blobDict={}}add(e,t,i){this._funcDict[e]=t,this._depsDict[e]=i}get(e){return this._blobDict[e]||(this._blobDict[e]=El(this._funcDict[e],this._depsDict[e])),this._blobDict[e]}},$l=new class{constructor(){this.schemes={},this.userSchemes={}}getScheme(e){const t=((e||{}).scheme||"").toLowerCase();let i;return i=t in this.schemes?this.schemes[t]:t in this.userSchemes?this.userSchemes[t]:qo,new i(e)}getSchemes(){const e={};return Object.keys(this.schemes).forEach((function(t){e[t]=t})),Object.keys(this.userSchemes).forEach((function(t){e[t]=t.split("|")[1]})),e}getScales(){return Ml}getModes(){return Al}add(e,t){e=e.toLowerCase(),this.schemes[e]=t}addScheme(e,t){return function(e){return e instanceof qo}(e)||(e=this._createScheme(e)),this._addUserScheme(e,t)}_addUserScheme(e,t){t=t||"";const i=`${Oo()}|${t}`.toLowerCase();return this.userSchemes[i]=e,i}removeScheme(e){e=e.toLowerCase(),delete this.userSchemes[e]}_createScheme(e){return class extends qo{constructor(t){super(t),e.call(this,t)}}}addSelectionScheme(e,t){return this._addUserScheme(class extends Sl{constructor(t){super(Object.assign({dataList:e},t))}},t)}hasScheme(e){return(e=e.toLowerCase())in this.schemes||e in this.userSchemes}},Gl=new Do("datasource"),Hl=new Do("representatation"),jl=new class extends Do{constructor(){super("parser")}__hasObjName(e,t){const i=this.get(e);return i&&i.prototype.__objName===t}isTrajectory(e){return this.__hasObjName(e,"frames")}isStructure(e){return this.__hasObjName(e,"structure")}isVolume(e){return this.__hasObjName(e,"volume")}isSurface(e){return this.__hasObjName(e,"surface")}isBinary(e){const t=this.get(e);return t&&t.prototype.isBinary}isXml(e){const t=this.get(e);return t&&t.prototype.isXml}isJson(e){const t=this.get(e);return t&&t.prototype.isJson}getTrajectoryExtensions(){return this.names.filter((e=>this.isTrajectory(e)))}getStructureExtensions(){return this.names.filter((e=>this.isStructure(e)))}getVolumeExtensions(){return this.names.filter((e=>this.isVolume(e)))}getSurfaceExtensions(){return this.names.filter((e=>this.isSurface(e)))}},Wl=new Do("shader"),ql=new Do("decompressor"),Xl=new Do("component"),Yl=new Do("buffer"),Kl=new Do("picker");e.ListingDatasource=void 0,e.TrajectoryDatasource=void 0;class Zl{constructor(e,t={}){this.chunkSize=10485760,this.newline="\n",this.__pointer=0,this.__partialLine="",this.compressed=uo(t.compressed,!1),this.binary=uo(t.binary,!1),this.json=uo(t.json,!1),this.xml=uo(t.xml,!1),this.src=e}isBinary(){return this.binary||this.compressed}read(){return this._read().then((e=>{const t=this.compressed?ql.get(this.compressed):void 0;return this.compressed&&t?this.data=t(e):((this.binary||this.compressed)&&e instanceof ArrayBuffer&&(e=new Uint8Array(e)),this.data=e),this.data}))}_chunk(e,t){return t=Math.min(this.data.length,t),0===e&&this.data.length===t?this.data:this.isBinary()?this.data.subarray(e,t):this.data.substring(e,t)}chunk(e){const t=e+this.chunkSize;return this._chunk(e,t)}peekLines(e){const t=this.data,i=t.length,n=this.isBinary()?this.newline.charCodeAt(0):this.newline;let r,s=0;for(r=0;ri).lines}chunkCount(){return Math.floor(this.data.length/this.chunkSize)+1}asText(){return this.isBinary()?xo(this.data):this.data}chunkToLines(e,t,i){const n=this.newline;if(!this.isBinary()&&e.length===this.data.length)return{lines:e.split(n),partialLine:""};let r=[];const s=this.isBinary()?xo(e):e,a=s.lastIndexOf(n);if(-1===a)t+=s;else{const e=t+s.substr(0,a);r=r.concat(e.split(n)),t=a===s.length-n.length?"":s.substr(a+n.length)}return i&&""!==t&&r.push(t),{lines:r,partialLine:t}}nextChunk(){const e=this.__pointer;if(!(e>this.data.length))return this.__pointer+=this.chunkSize,this.chunk(e)}nextChunkOfLines(){const e=this.nextChunk();if(void 0===e)return;const t=this.__pointer>this.data.length,i=this.chunkToLines(e,this.__partialLine,t);return this.__partialLine=i.partialLine,i.lines}eachChunk(e){const t=this.chunkSize,i=this.data.length,n=this.chunkCount();for(let r=0;r{const r=i===n+1,s=this.chunkToLines(t,this.__partialLine,r);this.__partialLine=s.partialLine,e(s.lines,i,n)}))}dispose(){delete this.src}}class Ql extends Zl{_read(){return new Promise(((e,t)=>{const i=this.src,n=new FileReader;n.onload=t=>{t.target&&e(t.target.result)},n.onerror=e=>t(e),this.binary||this.compressed?n.readAsArrayBuffer(i):n.readAsText(i)}))}}class Jl extends Zl{_read(){return new Promise(((e,t)=>{const i=this.src,n=new XMLHttpRequest;n.open("GET",i,!0),n.addEventListener("load",(()=>{if(200===n.status||304===n.status||0===n.status)try{e(n.response)}catch(e){t(e)}else t(n.statusText)}),!1),n.addEventListener("error",(e=>t("network error")),!1),this.isBinary()?n.responseType="arraybuffer":this.json?n.responseType="json":this.xml?n.responseType="document":n.responseType="text",n.send()}))}}class ec{constructor(e,t={}){this.parameters=ho(t,{ext:"",compressed:!1,binary:jl.isBinary(t.ext||""),name:"",dir:"",path:"",protocol:""});const i={compressed:this.parameters.compressed,binary:this.parameters.binary,json:jl.isJson(this.parameters.ext),xml:jl.isXml(this.parameters.ext)};"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob?this.streamer=new Ql(e,i):this.streamer=new Jl(e,i)}}class tc extends ec{constructor(e,t={}){super(e,t),this.parserParams={voxelSize:t.voxelSize,firstModelOnly:t.firstModelOnly,asTrajectory:t.asTrajectory,cAlphaOnly:t.cAlphaOnly,delimiter:t.delimiter,comment:t.comment,columnNames:t.columnNames,inferBonds:t.inferBonds,name:this.parameters.name,path:this.parameters.path}}load(){return new(jl.get(this.parameters.ext))(this.streamer,this.parserParams).parse()}}class ic{constructor(e,t,i){this.name=t,this.path=i,this.signals={elementAdded:new Yo.Signal,elementRemoved:new Yo.Signal,nameChanged:new Yo.Signal},this.type="Script",this.dir=i.substring(0,i.lastIndexOf("/")+1);try{this.fn=new Function("stage","__name","__path","__dir",e)}catch(e){Fl.error("Script compilation failed",e),this.fn=function(){}}}run(e){return new Promise(((t,i)=>{try{this.fn.apply(null,[e,this.name,this.path,this.dir]),t()}catch(e){Fl.error("Script.fn",e),i(e)}}))}}class nc extends ec{load(){return this.streamer.read().then((()=>new ic(this.streamer.asText(),this.parameters.name,this.parameters.path)))}}function rc(e){const t=ql.names;let i,n,r="";i=e instanceof File?e.name:e instanceof Blob?"":e;const s=i.lastIndexOf("?"),a=-1!==s?i.substring(s):"";i=i.substring(0,-1===s?i.length:s);const o=i.replace(/^.*[\\/]/,"");let l=o.substring(0,o.lastIndexOf("."));const c=o.split(".");let u=c.length>1?(c.pop()||"").toLowerCase():"";const h=i.match(/^(.+):\/\/(.+)$/);h&&(r=h[1].toLowerCase(),i=h[2]||"");const d=i.substring(0,i.lastIndexOf("/")+1);if(t.includes(u)){n=u;const e=i.length-u.length-1;u=(i.substr(0,e).split(".").pop()||"").toLowerCase();const t=l.length-u.length-1;l=l.substr(0,t)}else n=!1;return{path:i,name:o,ext:u,base:l,dir:d,compressed:n,protocol:r,query:a,src:e}}function sc(e){let t=rc(e);const i=Gl.get(t.protocol);return i&&(t=rc(i.getUrl(t.src)),!t.ext&&i.getExt&&(t.ext=i.getExt(e))),t}function ac(e,t={}){const i=Object.assign(sc(e),t);let n;return jl.names.includes(i.ext)?n=new tc(i.src,i):Ul.includes(i.ext)&&(n=new nc(i.src,i)),n?n.load():Promise.reject(new Error(`autoLoad: ext '${i.ext}' unknown`))}var oc=Vo((function(e,t){!function(){var e={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function i(t){return function(t,n){var r,s,a,o,l,c,u,h,d,f=1,m=t.length,p="";for(s=0;s=0),o.type){case"b":r=parseInt(r,10).toString(2);break;case"c":r=String.fromCharCode(parseInt(r,10));break;case"d":case"i":r=parseInt(r,10);break;case"j":r=JSON.stringify(r,null,o.width?parseInt(o.width):0);break;case"e":r=o.precision?parseFloat(r).toExponential(o.precision):parseFloat(r).toExponential();break;case"f":r=o.precision?parseFloat(r).toFixed(o.precision):parseFloat(r);break;case"g":r=o.precision?String(Number(r.toPrecision(o.precision))):parseFloat(r);break;case"o":r=(parseInt(r,10)>>>0).toString(8);break;case"s":r=String(r),r=o.precision?r.substring(0,o.precision):r;break;case"t":r=String(!!r),r=o.precision?r.substring(0,o.precision):r;break;case"T":r=Object.prototype.toString.call(r).slice(8,-1).toLowerCase(),r=o.precision?r.substring(0,o.precision):r;break;case"u":r=parseInt(r,10)>>>0;break;case"v":r=r.valueOf(),r=o.precision?r.substring(0,o.precision):r;break;case"x":r=(parseInt(r,10)>>>0).toString(16);break;case"X":r=(parseInt(r,10)>>>0).toString(16).toUpperCase()}e.json.test(o.type)?p+=r:(!e.number.test(o.type)||h&&!o.sign?d="":(d=h?"+":"-",r=r.toString().replace(e.sign,"")),c=o.pad_char?"0"===o.pad_char?"0":o.pad_char.charAt(1):" ",u=o.width-(d+r).length,l=o.width&&u>0?c.repeat(u):"",p+=o.align?d+r+l:"0"===c?d+l+r:l+d+r)}return p}(function(t){if(r[t])return r[t];var i,n=t,s=[],a=0;for(;n;){if(null!==(i=e.text.exec(n)))s.push(i[0]);else if(null!==(i=e.modulo.exec(n)))s.push("%");else{if(null===(i=e.placeholder.exec(n)))throw new SyntaxError("[sprintf] unexpected placeholder");if(i[2]){a|=1;var o=[],l=i[2],c=[];if(null===(c=e.key.exec(l)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(o.push(c[1]);""!==(l=l.substring(c[0].length));)if(null!==(c=e.key_access.exec(l)))o.push(c[1]);else{if(null===(c=e.index_access.exec(l)))throw new SyntaxError("[sprintf] failed to parse named argument key");o.push(c[1])}i[2]=o}else a|=2;if(3===a)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");s.push({placeholder:i[0],param_no:i[1],keys:i[2],sign:i[3],pad_char:i[4],align:i[5],width:i[6],precision:i[7],type:i[8]})}n=n.substring(i[0].length)}return r[t]=s}(t),arguments)}function n(e,t){return i.apply(null,[e].concat(t||[]))}var r=Object.create(null);t.sprintf=i,t.vsprintf=n,"undefined"!=typeof window&&(window.sprintf=i,window.vsprintf=n)}()}));class lc{getBlob(){return new Blob([this.getData()],{type:this.mimeType})}download(e,t){e=uo(e,this.defaultName),t=uo(t,this.defaultExt),go(this.getBlob(),`${e}.${t}`)}}const cc=[];class uc{constructor(e,t={}){this._mark=0,this._marks=[],this.offset=0,this.littleEndian=!0;let i=!1;void 0===e&&(e=8192),"number"==typeof e?e=new ArrayBuffer(e):i=!0;const n=t.offset?t.offset>>>0:0;let r=e.byteLength-n,s=n;e instanceof ArrayBuffer||(e.byteLength!==e.buffer.byteLength&&(s=e.byteOffset+n),e=e.buffer),this._lastWrittenByte=i?r:0,this.buffer=e,this.length=r,this.byteLength=r,this.byteOffset=s,this._data=new DataView(this.buffer,s,r)}available(e){return void 0===e&&(e=1),this.offset+e<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(e){return void 0===e&&(e=1),this.offset+=e,this}seek(e){return this.offset=e,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const e=this._marks.pop();if(void 0===e)throw new Error("Mark stack empty");return this.seek(e),this}rewind(){return this.offset=0,this}ensureAvailable(e){if(void 0===e&&(e=1),!this.available(e)){const t=2*(this.offset+e),i=new Uint8Array(t);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=this.byteLength=t,this._data=new DataView(this.buffer)}return this}readBoolean(){return 0!==this.readUint8()}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(e){void 0===e&&(e=1);for(var t=new Uint8Array(e),i=0;ithis._lastWrittenByte&&(this._lastWrittenByte=this.offset)}}class hc{constructor(){this.count=0,this.signals={countChanged:new Yo.Signal}}clear(){this.change(-this.count)}change(e){this.count+=e,this.signals.countChanged.dispatch(e,this.count),this.count<0&&Fl.warn("Counter.count below zero",this.count)}increment(){this.change(1)}decrement(){this.change(-1)}listen(e){this.change(e.count),e.signals.countChanged.add(this.change,this)}unlisten(e){const t=e.signals.countChanged;t.has(this.change,this)&&t.remove(this.change,this)}onZeroOnce(e,t){if(0===this.count)e.call(t);else{const i=()=>{0===this.count&&(this.signals.countChanged.remove(i,this),e.call(t))};this.signals.countChanged.add(i,this)}}dispose(){this.clear(),this.signals.countChanged.dispose()}}Wl.add("shader/BasicLine.vert","void main(){\n#include begin_vertex\n#include project_vertex\n}"),Wl.add("shader/BasicLine.frag","uniform vec3 uColor;\n#include common\n#include fog_pars_fragment\nvoid main(){\ngl_FragColor = vec4( uColor, 1.0 );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n}"),Wl.add("shader/Quad.vert","varying vec2 vUv;\nvoid main() {\nvUv = uv;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"),Wl.add("shader/Quad.frag","varying vec2 vUv;\nuniform sampler2D tForeground;\nuniform float scale;\nvoid main() {\nvec4 foreground = texture2D( tForeground, vUv );\ngl_FragColor = foreground * scale;\n}");class dc{constructor(){this.signals={updated:new Yo.Signal},this.maxDuration=-1/0,this.minDuration=1/0,this.avgDuration=14,this.lastDuration=1/0,this.prevFpsTime=0,this.lastFps=1/0,this.lastFrames=1,this.frames=0,this.count=0,this.begin()}update(){this.startTime=this.end(),this.currentTime=this.startTime,this.signals.updated.dispatch()}begin(){this.startTime=window.performance.now(),this.lastFrames=this.frames}end(){const e=window.performance.now();return this.count+=1,this.frames+=1,this.lastDuration=e-this.startTime,this.minDuration=Math.min(this.minDuration,this.lastDuration),this.maxDuration=Math.max(this.maxDuration,this.lastDuration),this.avgDuration-=this.avgDuration/30,this.avgDuration+=this.lastDuration/30,e>this.prevFpsTime+1e3&&(this.lastFps=this.frames,this.prevFpsTime=e,this.frames=0),e}}Wl.add("shader/chunk/fog_fragment.glsl","#ifdef USE_FOG\nfloat depth = length( vViewPosition );\n#ifdef FOG_EXP2\nfloat fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );\n#else\nfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n#endif\ngl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif"),Wl.add("shader/chunk/interior_fragment.glsl","if( gl_FrontFacing == false ){\n#ifdef USE_INTERIOR_COLOR\noutgoingLight.xyz = interiorColor;\n#else\n#ifdef DIFFUSE_INTERIOR\noutgoingLight.xyz = vColor;\n#endif\n#endif\noutgoingLight.xyz *= 1.0 - interiorDarkening;\n}"),Wl.add("shader/chunk/matrix_scale.glsl","float matrixScale( in mat4 m ){\nvec4 r = m[ 0 ];\nreturn sqrt( r[ 0 ] * r[ 0 ] + r[ 1 ] * r[ 1 ] + r[ 2 ] * r[ 2 ] );\n}"),Wl.add("shader/chunk/nearclip_vertex.glsl","#ifdef NEAR_CLIP\nif( vViewPosition.z < clipNear - 5.0 )\ngl_Position.z = 2.0 * gl_Position.w;\n#endif"),Wl.add("shader/chunk/nearclip_fragment.glsl","#ifdef NEAR_CLIP\nif( vViewPosition.z < clipNear )\ndiscard;\n#endif"),Wl.add("shader/chunk/opaque_back_fragment.glsl","#ifdef OPAQUE_BACK\n#ifdef FLIP_SIDED\nif( gl_FrontFacing == true ){\ngl_FragColor.a = 1.0;\n}\n#else\nif( gl_FrontFacing == false ){\ngl_FragColor.a = 1.0;\n}\n#endif\n#endif"),Wl.add("shader/chunk/radiusclip_vertex.glsl","#ifdef RADIUS_CLIP\nif( distance( vViewPosition, vClipCenter ) > clipRadius + 5.0 )\ngl_Position.z = 2.0 * gl_Position.w;\n#endif"),Wl.add("shader/chunk/radiusclip_fragment.glsl","#ifdef RADIUS_CLIP\nif( distance( vViewPosition, vClipCenter ) > clipRadius )\ndiscard;\n#endif"),Wl.add("shader/chunk/unpack_color.glsl","vec3 unpackColor(float f) {\nvec3 color;\ncolor.r = floor(f / 256.0 / 256.0);\ncolor.g = floor((f - color.r * 256.0 * 256.0) / 256.0);\ncolor.b = floor(f - color.r * 256.0 * 256.0 - color.g * 256.0);\nreturn color / 255.0;\n}");const fc=/^(?!\/\/)\s*#include\s+(\S+)/gim,mc={};function pc(e,t={}){let i=e+"|";for(const e in t)i+=e+":"+t[e];if(!mc[i]){const n=function(e){if(void 0===e)return"";const t=[];for(const i in e){const n=e[i];n&&t.push(`#define ${i} ${n}`)}return t.join("\n")+"\n"}(t);let r=Wl.get(`shader/${e}`);if(!r)throw new Error(`empty shader, '${e}'`);r=r.replace(fc,(function(e,t){const i=`shader/chunk/${t}.glsl`,n=Wl.get(i)||$n[t];if(!n)throw new Error(`empty chunk, '${t}'`);return n})),mc[i]=n+r}return mc[i]}if("undefined"!=typeof WebGLRenderingContext){const t=WebGLRenderingContext.prototype,i=t.getShaderParameter;t.getShaderParameter=function(){return!e.Debug||i.apply(this,arguments)};const n=t.getShaderInfoLog;t.getShaderInfoLog=function(){return e.Debug?n.apply(this,arguments):""};const r=t.getProgramParameter;t.getProgramParameter=function(i,n){return!e.Debug&&n===t.LINK_STATUS||r.apply(this,arguments)};const s=t.getProgramInfoLog;t.getProgramInfoLog=function(){return e.Debug?s.apply(this,arguments):""}}const gc=[[[0,0]],[[4,4],[-4,-4]],[[-2,-6],[6,-2],[-6,2],[2,6]],[[1,-3],[-1,3],[5,1],[-3,-5],[-5,5],[-7,-1],[3,7],[7,-7]],[[1,1],[-1,-3],[-3,2],[4,-1],[-5,-2],[2,5],[5,3],[3,-5],[-2,6],[0,-7],[-4,-6],[-6,4],[-8,0],[7,-4],[6,7],[-7,-8]],[[-4,-7],[-7,-5],[-3,-5],[-5,-4],[-1,-4],[-2,-2],[-6,-1],[-4,0],[-7,1],[-1,2],[-6,3],[-3,3],[-7,6],[-3,6],[-5,7],[-1,7],[5,-7],[1,-6],[6,-5],[4,-4],[2,-3],[7,-2],[1,-1],[4,-1],[2,1],[6,2],[0,4],[4,4],[2,5],[7,5],[5,6],[3,7]]];gc.forEach((e=>{e.forEach((e=>{e[0]*=.0625,e[1]*=.0625}))}));class _c{constructor(e,t,i,n){this.canvas=document.createElement("canvas"),this._viewer=i,this._factor=uo(n.factor,2),this._antialias=uo(n.antialias,!1),this._onProgress=n.onProgress,this._onFinish=n.onFinish,this._antialias&&(this._factor*=2),this._n=this._factor*this._factor,this._width=this._viewer.width,this._height=this._viewer.height,this._antialias?(this.canvas.width=this._width*this._factor/2,this.canvas.height=this._height*this._factor/2):(this.canvas.width=this._width*this._factor,this.canvas.height=this._height*this._factor),this._ctx=this.canvas.getContext("2d"),this._viewerSampleLevel=i.sampleLevel,this._viewer.setSampling(-1)}_renderTile(e){const t=this._viewer,i=this._width,n=this._height,r=this._factor,s=e%r*i,a=Math.floor(e/r)*n;if(t.camera.setViewOffset(i*r,n*r,s,a,i,n),t.render(),this._antialias){const e=Math.round((s+i)/2)-Math.round(s/2),r=Math.round((a+n)/2)-Math.round(a/2);this._ctx.drawImage(t.renderer.domElement,Math.round(s/2),Math.round(a/2),e,r)}else this._ctx.drawImage(t.renderer.domElement,Math.floor(s),Math.floor(a),Math.ceil(i),Math.ceil(n));"function"==typeof this._onProgress&&this._onProgress(e+1,this._n,!1)}_finalize(){this._viewer.setSampling(this._viewerSampleLevel),this._viewer.camera.view=null,"function"==typeof this._onFinish&&this._onFinish(this._n+1,this._n,!1)}render(){for(let e=0;e<=this._n;++e)e===this._n?this._finalize():this._renderTile(e)}renderAsync(){let e=0;const t=this._n,i=()=>{e===t?this._finalize():this._renderTile(e),e+=1};for(let e=0;e<=t;++e)setTimeout(i,0)}}const yc=2*Math.PI,vc=180/Math.PI;function bc(e,t,i=1,n=0,r){const s=r?r.length:e.length/i;let a=0,o=0;if(r)for(let l=0;lt&&(t=e[i]);return t}function Dc(e){let t=1/0;for(let i=0,n=e.length;i=0;c--){for(l=a-1;l>=0;l--)if(h=4*(c*a+l),o[h]!==t||o[h+1]!==i||o[h+2]!==n||o[h+3]!==r){u=!0;break}if(u)break}const m=c;for(u=!1,l=a-1;l>=0;l--){for(c=s-1;c>=0;c--)if(h=4*(c*a+l),o[h]!==t||o[h+1]!==i||o[h+2]!==n||o[h+3]!==r){u=!0;break}if(u)break}const p=l,g=document.createElement("canvas");return g.width=p-f,g.height=m-d,g.getContext("2d").drawImage(e,f,d,g.width,g.height,0,0,g.width,g.height),g}(e,s?0:255*t.r,s?0:255*t.g,s?0:255*t.b,s?0:255)}return e}function d(e,i,n){"function"==typeof t.onProgress&&t.onProgress(e,i,n)}return new Promise((function(t,i){const c=new _c(a,o,e,{factor:n,antialias:r,onProgress:d,onFinish:function(n,r){h(c.canvas).toBlob((function(n){a.setClearAlpha(l),u(!0),e.requestRender(),d(r,r,!0),n?t(n):i("error creating image")}),"image/png")}});a.setClearAlpha(s?0:1),u(),c.renderAsync()}))}const Nc=new _t,Fc=new qt,Bc=new qt;const zc=new Ge,Uc=new qt,Vc=new qt;function $c(e,t){Uc.copy(t.projectionMatrix).invert(),Vc.copy(t.projectionMatrix).transpose(),e.traverse((function(e){const t=e.material;if(!t)return;const i=t.uniforms;i&&(i.projectionMatrixInverse&&i.projectionMatrixInverse.value.copy(Uc),i.projectionMatrixTranspose&&i.projectionMatrixTranspose.value.copy(Vc))}))}function Gc(e,t,i){const n=e.createShader(i);if(!n)return void console.log(`error creating WebGL shader ${i}`);e.shaderSource(n,t),e.compileShader(n);return e.getShaderParameter(n,e.COMPILE_STATUS)?n:(console.log(`error compiling shader ${n}: ${e.getShaderInfoLog(n)}`),e.deleteShader(n),null)}function Hc(e,t){const i=e.getExtension(t);return i||console.log(`extension '${t}' not available`),i}const jc=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]);function Wc(e){const t=document.createElement("canvas");t.width=16,t.height=16,t.style.width="16px",t.style.height="16px";const i=t.getContext("webgl")||t.getContext("experimental-webgl");if(!i)return console.log(`error creating webgl context for ${e}`),!1;if(!(i instanceof WebGLRenderingContext))return console.log("Got unexpected type for WebGL rendering context"),!1;Hc(i,"OES_texture_float"),Hc(i,"OES_texture_half_float"),Hc(i,"WEBGL_color_buffer_float");const n=Gc(i,"\nattribute vec4 a_position;\n\nvoid main() {\n gl_Position = a_position;\n}",i.VERTEX_SHADER),r=Gc(i,"\nprecision mediump float;\nuniform vec4 u_color;\nuniform sampler2D u_texture;\n\nvoid main() {\n gl_FragColor = texture2D(u_texture, vec2(0.5, 0.5)) * u_color;\n}",i.FRAGMENT_SHADER);if(!n||!r)return!1;const s=function(e,t,i,n){const r=e.createProgram();return r?(t.forEach((t=>e.attachShader(r,t))),i&&i.forEach(((t,i)=>{e.bindAttribLocation(r,n?n[i]:i,t)})),e.linkProgram(r),e.getProgramParameter(r,e.LINK_STATUS)?r:(console.log(`error linking program: ${e.getProgramInfoLog(r)}`),e.deleteProgram(r),null)):void console.log("error creating WebGL program")}(i,[n,r]);if(!s)return console.log("error creating WebGL program"),!1;i.useProgram(s);const a=i.getAttribLocation(s,"a_position"),o=i.getUniformLocation(s,"u_color");if(!o)return console.log("error getting 'u_color' uniform location"),!1;const l=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,l),i.bufferData(i.ARRAY_BUFFER,jc,i.STATIC_DRAW),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0);const c=i.createTexture(),u=new Uint8Array([255,255,255,255]);i.bindTexture(i.TEXTURE_2D,c),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,1,1,0,i.RGBA,i.UNSIGNED_BYTE,u);const h=i.createTexture();i.bindTexture(i.TEXTURE_2D,h),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,1,1,0,i.RGBA,e,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.NEAREST),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.NEAREST);const d=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,d),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,h,0);if(i.checkFramebufferStatus(i.FRAMEBUFFER)!==i.FRAMEBUFFER_COMPLETE)return console.log(`error creating framebuffer for ${e}`),!1;i.bindTexture(i.TEXTURE_2D,c),i.uniform4fv(o,[0,10,20,1]),i.drawArrays(i.TRIANGLES,0,6),i.bindTexture(i.TEXTURE_2D,h),i.bindFramebuffer(i.FRAMEBUFFER,null),i.clearColor(1,0,0,1),i.clear(i.COLOR_BUFFER_BIT),i.uniform4fv(o,[0,.1,.05,1]),i.drawArrays(i.TRIANGLES,0,6);const f=new Uint8Array(4);if(i.readPixels(0,0,1,1,i.RGBA,i.UNSIGNED_BYTE,f),0!==f[0]||f[1]<248||f[2]<248||f[3]<254)return console.log(`not able to actually render to ${e} texture`),!1;if(e===i.FLOAT){i.bindFramebuffer(i.FRAMEBUFFER,d);const e=new Float32Array(4);i.readPixels(0,0,1,1,i.RGBA,i.FLOAT,e);const t=i.getError();if(t)return console.log(`error reading pixels as float: '${function(e,t){switch(t){case e.NO_ERROR:return"no error";case e.INVALID_ENUM:return"invalid enum";case e.INVALID_VALUE:return"invalid value";case e.INVALID_OPERATION:return"invalid operation";case e.INVALID_FRAMEBUFFER_OPERATION:return"invalid framebuffer operation";case e.OUT_OF_MEMORY:return"out of memory";case e.CONTEXT_LOST_WEBGL:return"context lost"}return"unknown error"}(i,t)}'`),!1}return!0}const qc=new Float32Array(100),Xc=new Uint8Array(100),Yc=[12,7,13,17,11,6,8,18,16,2,14,22,10,1,3,9,19,23,21,15,5,0,4,24,20],Kc=new qt;function Zc(e,t,i,n,r){const s=r.uniforms,a=[];if(s&&(s.objectId&&(s.objectId.value=Ll?this.id:this.id/255,a.push("objectId")),(s.modelViewMatrixInverse||s.modelViewMatrixInverseTranspose||s.modelViewProjectionMatrix||s.modelViewProjectionMatrixInverse)&&this.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,this.matrixWorld),s.modelViewMatrixInverse&&(s.modelViewMatrixInverse.value.copy(this.modelViewMatrix).invert(),a.push("modelViewMatrixInverse")),s.modelViewMatrixInverseTranspose&&(s.modelViewMatrixInverse?s.modelViewMatrixInverseTranspose.value.copy(s.modelViewMatrixInverse.value).transpose():s.modelViewMatrixInverseTranspose.value.copy(this.modelViewMatrix).invert().transpose(),a.push("modelViewMatrixInverseTranspose")),s.modelViewProjectionMatrix&&(s.modelViewProjectionMatrix.value.multiplyMatrices(i.projectionMatrix,this.modelViewMatrix),a.push("modelViewProjectionMatrix")),s.modelViewProjectionMatrixInverse&&(s.modelViewProjectionMatrix?(Kc.copy(s.modelViewProjectionMatrix.value),s.modelViewProjectionMatrixInverse.value.copy(Kc.invert())):(Kc.multiplyMatrices(i.projectionMatrix,this.modelViewMatrix),s.modelViewProjectionMatrixInverse.value.copy(Kc.invert())),a.push("modelViewProjectionMatrixInverse")),a.length)){const t=e.properties.get(r);if(t.program){const i=e.getContext(),n=t.program;i.useProgram(n.program);const r=n.getUniforms();a.forEach((function(e){r.setValue(i,e,s[e].value)}))}}}class Qc{constructor(e){if(this.boundingBox=new bt,this.boundingBoxSize=new _t,this.boundingBoxLength=0,this.info={memory:{programs:0,geometries:0,textures:0},render:{calls:0,vertices:0,faces:0,points:0}},this.distVector=new _t,this.signals={ticked:new Yo.Signal,rendered:new Yo.Signal},"string"==typeof e){const t=document.getElementById(e);this.container=null===t?document.createElement("div"):t}else e instanceof HTMLElement?this.container=e:this.container=document.createElement("div");if(this.container===document.body)this.width=window.innerWidth||1,this.height=window.innerHeight||1;else{const e=this.container.getBoundingClientRect();this.width=e.width||1,this.height=e.height||1,this.container.style.overflow="hidden"}this.wrapper=document.createElement("div"),this.wrapper.style.position="relative",this.container.appendChild(this.wrapper),this._initParams(),this._initStats(),this._initCamera(),this._initScene(),!1!==this._initRenderer()?(this._initHelper(),this.setBackground(),this.setFog(),this.animate=this.animate.bind(this)):Fl.error("Viewer: could not initialize renderer")}_initParams(){this.parameters={fogColor:new Oi(0),fogNear:50,fogFar:100,backgroundColor:new Oi(0),cameraType:"perspective",cameraFov:40,cameraEyeSep:.3,cameraZ:-80,clipNear:0,clipFar:100,clipDist:10,clipMode:"scene",clipScale:"relative",lightColor:new Oi(14540253),lightIntensity:1.2,ambientColor:new Oi(14540253),ambientIntensity:.3,sampleLevel:0,outputColorSpace:"srgb-linear"}}_initCamera(){const e=new _t(0,0,0),{width:t,height:i}=this;this.perspectiveCamera=new Tn(this.parameters.cameraFov,t/i),this.perspectiveCamera.position.z=this.parameters.cameraZ,this.perspectiveCamera.lookAt(e),this.orthographicCamera=new Qn(t/-2,t/2,i/2,i/-2),this.orthographicCamera.position.z=this.parameters.cameraZ,this.orthographicCamera.lookAt(e),this.stereoCamera=new oo,this.stereoCamera.aspect=.5,this.stereoCamera.eyeSep=this.parameters.cameraEyeSep;const n=this.parameters.cameraType;if("orthographic"===n)this.camera=this.orthographicCamera;else{if("perspective"!==n&&"stereo"!==n)throw new Error(`Unknown cameraType '${n}'`);this.camera=this.perspectiveCamera}this.camera.updateProjectionMatrix()}_initStats(){this.stats=new dc}_initScene(){this.scene||(this.scene=new Sa,this.scene.name="scene"),this.rotationGroup=new ma,this.rotationGroup.name="rotationGroup",this.scene.add(this.rotationGroup),this.translationGroup=new ma,this.translationGroup.name="translationGroup",this.rotationGroup.add(this.translationGroup),this.modelGroup=new ma,this.modelGroup.name="modelGroup",this.translationGroup.add(this.modelGroup),this.pickingGroup=new ma,this.pickingGroup.name="pickingGroup",this.translationGroup.add(this.pickingGroup),this.backgroundGroup=new ma,this.backgroundGroup.name="backgroundGroup",this.translationGroup.add(this.backgroundGroup),this.helperGroup=new ma,this.helperGroup.name="helperGroup",this.translationGroup.add(this.helperGroup),this.scene.fog=new wa(this.parameters.fogColor.getHex()),this.directionalLight=new io(this.parameters.lightColor.getHex(),this.parameters.lightIntensity),this.scene.add(this.directionalLight),this.ambientLight=new no(this.parameters.ambientColor.getHex(),this.parameters.ambientIntensity),this.scene.add(this.ambientLight)}_initRenderer(){const t=window.devicePixelRatio,{width:i,height:n}=this;try{this.renderer=new xa({preserveDrawingBuffer:!0,alpha:!0,antialias:!0})}catch(e){return this.wrapper.innerHTML='

Your browser/graphics card does not seem to support WebGL.

Find out how to get it here.

',!1}this.renderer.setPixelRatio(t),this.renderer.setSize(i,n),this.renderer.autoClear=!1,this.renderer.sortObjects=!0,this.renderer.outputColorSpace=this.parameters.outputColorSpace,this.renderer.useLegacyLights=!0;const r=this.renderer.getContext();this.renderer.capabilities.isWebGL2?(Nl(!0),kl(this.renderer.extensions.get("EXT_color_buffer_float")),this.supportsHalfFloat=!0):(Nl(this.renderer.extensions.get("EXT_frag_depth")),this.renderer.extensions.get("OES_element_index_uint"),kl(this.renderer.extensions.get("OES_texture_float")&&this.renderer.extensions.get("WEBGL_color_buffer_float")||this.renderer.extensions.get("OES_texture_float")&&Wc(r.FLOAT)),this.renderer.extensions.get("OES_texture_float"),this.supportsHalfFloat=this.renderer.extensions.get("OES_texture_half_float")&&Wc(36193)),this.wrapper.appendChild(this.renderer.domElement);const s=i*t,a=n*t;e.Debug&&console.log(JSON.stringify({Browser:Il,OES_texture_float:!!this.renderer.extensions.get("OES_texture_float"),OES_texture_half_float:!!this.renderer.extensions.get("OES_texture_half_float"),WEBGL_color_buffer_float:!!this.renderer.extensions.get("WEBGL_color_buffer_float"),"testTextureSupport Float":Wc(r.FLOAT),"testTextureSupport HalfFloat":Wc(36193),"this.supportsHalfFloat":this.supportsHalfFloat,SupportsReadPixelsFloat:Ll},null,2)),this.pickingTarget=new ft(s,a,{minFilter:U,magFilter:U,stencilBuffer:!1,format:J,type:Ll?K:W}),this.pickingTarget.texture.generateMipmaps=!1,this.pickingTarget.texture.colorSpace=this.parameters.outputColorSpace,this.renderer.setRenderTarget(this.pickingTarget),this.renderer.clear(),this.renderer.setRenderTarget(null),this.sampleTarget=new ft(s,a,{minFilter:G,magFilter:G,format:J,type:this.supportsHalfFloat?Z:Ll?K:W}),this.sampleTarget.texture.colorSpace=this.parameters.outputColorSpace,this.holdTarget=new ft(s,a,{minFilter:U,magFilter:U,format:J,type:this.supportsHalfFloat?Z:Ll?K:W}),this.holdTarget.texture.colorSpace=this.parameters.outputColorSpace,this.compositeUniforms={tForeground:new lo(this.sampleTarget.texture),scale:new lo(1)},this.compositeMaterial=new An({uniforms:this.compositeUniforms,vertexShader:pc("Quad.vert"),fragmentShader:pc("Quad.frag"),premultipliedAlpha:!0,transparent:!0,blending:2,depthTest:!1,depthWrite:!1}),this.compositeCamera=new Qn(-1,1,1,-1,0,1),this.compositeScene=new Sa,this.compositeScene.name="compositeScene",this.compositeScene.add(new yn(new Vn(2,2),this.compositeMaterial))}_initHelper(){const e=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),t=new Float32Array(24),i=new Ji;i.setIndex(new $i(e,1)),i.setAttribute("position",new $i(t,3));const n=new An({uniforms:{uColor:{value:new Oi("skyblue")}},vertexShader:pc("BasicLine.vert"),fragmentShader:pc("BasicLine.frag")});this.boundingBoxMesh=new ka(i,n),this.helperGroup.add(this.boundingBoxMesh)}updateHelper(){const e=this.boundingBoxMesh.geometry.attributes.position,t=e.array,{min:i,max:n}=this.boundingBox;t[0]=n.x,t[1]=n.y,t[2]=n.z,t[3]=i.x,t[4]=n.y,t[5]=n.z,t[6]=i.x,t[7]=i.y,t[8]=n.z,t[9]=n.x,t[10]=i.y,t[11]=n.z,t[12]=n.x,t[13]=n.y,t[14]=i.z,t[15]=i.x,t[16]=n.y,t[17]=i.z,t[18]=i.x,t[19]=i.y,t[20]=i.z,t[21]=n.x,t[22]=i.y,t[23]=i.z,e.needsUpdate=!0,this.boundingBox.isEmpty()||this.boundingBoxMesh.geometry.computeBoundingSphere()}get cameraDistance(){return Math.abs(this.camera.position.z)}set cameraDistance(e){this.camera.position.z=-e}add(t,i){i?i.forEach((e=>this.addBuffer(t,e))):this.addBuffer(t),t.group.name="meshGroup",t.wireframeGroup.name="wireframeGroup",t.parameters.background?(this.backgroundGroup.add(t.group),this.backgroundGroup.add(t.wireframeGroup)):(this.modelGroup.add(t.group),this.modelGroup.add(t.wireframeGroup)),t.pickable&&this.pickingGroup.add(t.pickingGroup),e.Debug&&this.updateHelper()}addBuffer(e,t){function i(n){n instanceof ma?n.children.forEach(i):(n.userData.buffer=e,n.userData.instance=t,n.onBeforeRender=Zc)}const n=e.getMesh();t&&n.applyMatrix4(t.matrix),i(n),e.group.add(n);const r=e.getWireframeMesh();if(t&&(r.matrix.copy(n.matrix),r.position.copy(n.position),r.quaternion.copy(n.quaternion),r.scale.copy(n.scale)),i(r),e.wireframeGroup.add(r),e.pickable){const r=e.getPickingMesh();t&&(r.matrix.copy(n.matrix),r.position.copy(n.position),r.quaternion.copy(n.quaternion),r.scale.copy(n.scale)),i(r),e.pickingGroup.add(r)}t?this._updateBoundingBox(e.geometry,e.matrix,t.matrix):this._updateBoundingBox(e.geometry,e.matrix)}remove(t){this.translationGroup.children.forEach((function(e){e.remove(t.group),e.remove(t.wireframeGroup)})),t.pickable&&this.pickingGroup.remove(t.pickingGroup),this.updateBoundingBox(),e.Debug&&this.updateHelper()}_updateBoundingBox(e,t,i){const n=this.boundingBox;function r(e,t,i){null==e.boundingBox&&e.computeBoundingBox();const r=e.boundingBox.clone();t&&r.applyMatrix4(t),i&&r.applyMatrix4(i),r.min.equals(r.max)&&r.expandByScalar(5),n.union(r)}function s(e){if(void 0!==e.geometry){let t,i;e.userData.buffer&&(t=e.userData.buffer.matrix),e.userData.instance&&(i=e.userData.instance.matrix),r(e.geometry,t,i)}}e?r(e,t,i):(n.makeEmpty(),this.modelGroup.traverse(s),this.backgroundGroup.traverse(s)),n.getSize(this.boundingBoxSize),this.boundingBoxLength=this.boundingBoxSize.length()}updateBoundingBox(){this._updateBoundingBox(),e.Debug&&this.updateHelper()}getPickingPixels(){const{width:e,height:t}=this,i=e*t*4,n=Ll?new Float32Array(i):new Uint8Array(i);return this.render(!0),this.renderer.readRenderTargetPixels(this.pickingTarget,0,0,e,t,n),n}getImage(e){return new Promise((t=>{if(e){const{width:e,height:i}=this,n=e*i*4;let r=this.getPickingPixels();if(Ll){const e=new Uint8Array(n);for(let t=0;t500&&!this.isStill&&this.sampleLevel<3&&-1!==this.sampleLevel){const t=this.sampleLevel;this.sampleLevel=3,this.renderPending=!0,this.render(),this.isStill=!0,this.sampleLevel=t,e.Debug&&Fl.log("rendered still frame")}this.frameRequest=window.requestAnimationFrame(this.animate)}pick(e,t){if("stereo"===this.parameters.cameraType)return{pid:0,instance:void 0,picker:void 0};e*=window.devicePixelRatio,t*=window.devicePixelRatio,e=Math.max(e-2,0),t=Math.max(t-2,0);let i,n,r=0;const s=Ll?qc:Xc;this.render(!0),this.renderer.readRenderTargetPixels(this.pickingTarget,e,t,5,5,s);for(let e=0;e22&&(this.stats.begin(),this.isStill=!1),this.renderPending=!0,window.requestAnimationFrame((()=>{this.render(),this.stats.update()})))}updateZoom(){const e=Ro(this.perspectiveCamera.fov),t=2*Math.tan(e/2)*this.cameraDistance;this.orthographicCamera.zoom=this.height/t}absoluteToRelative(e){return 50*(1-e/this.bRadius)}relativeToAbsolute(e){return this.bRadius*(1-e/50)}__updateClipping(){const e=this.parameters;this.bRadius=Math.max(10,.5*this.boundingBoxLength),isFinite(this.bRadius)||(this.bRadius=50),this.camera.getWorldPosition(this.distVector),this.cDist=this.distVector.length(),this.cDist||(this.cameraDistance=Math.abs(e.cameraZ),this.cDist=Math.abs(e.cameraZ));const t=this.scene.fog;if(t.color.set(e.fogColor),"camera"===e.clipMode)this.camera.near=e.clipNear,this.camera.far=e.clipFar,t.near=e.fogNear,t.far=e.fogFar;else if("absolute"===e.clipScale)this.camera.near=this.cDist-e.clipNear,this.camera.far=this.cDist+e.clipFar,t.near=this.cDist-e.fogNear,t.far=this.cDist+e.fogFar;else{const i=(50-e.clipNear)/50,n=-(50-e.clipFar)/50;this.camera.near=this.cDist-this.bRadius*i,this.camera.far=this.cDist+this.bRadius*n;const r=(50-e.fogNear)/50,s=-(50-e.fogFar)/50;t.near=this.cDist-this.bRadius*r,t.far=this.cDist+this.bRadius*s}"camera"!==e.clipMode&&("PerspectiveCamera"===this.camera.type?(this.camera.near=Math.max(.1,e.clipDist,this.camera.near),this.camera.far=Math.max(1,this.camera.far),t.near=Math.max(.1,t.near),t.far=Math.max(1,t.far)):"OrthographicCamera"===this.camera.type&&e.clipDist>0&&(this.camera.near=Math.max(e.clipDist,this.camera.near)))}__updateCamera(){const e=this.camera;e.updateMatrix(),e.updateMatrixWorld(!0),e.updateProjectionMatrix(),function(e,t,i,n,r){let s=new Ge;i.getSize(s);const a=s.height,o=i.getPixelRatio(),l="OrthographicCamera"===t.type;zc.set(s.width,s.height),Uc.copy(t.projectionMatrix).invert(),Vc.copy(t.projectionMatrix).transpose(),e.traverse((function(e){const t=e.material;if(!t)return;const i=t.uniforms;if(i){if(t.clipNear){const e=(50-t.clipNear)/50,s=n-r*e;i.clipNear.value=s}i.canvasHeight&&(i.canvasHeight.value=a),i.resolution&&i.resolution.value.copy(zc),i.pixelRatio&&(i.pixelRatio.value=o),i.projectionMatrixInverse&&i.projectionMatrixInverse.value.copy(Uc),i.projectionMatrixTranspose&&i.projectionMatrixTranspose.value.copy(Vc),i.ortho&&(i.ortho.value=l)}}))}(this.scene,e,this.renderer,this.cDist,this.bRadius),function(e,t){e.traverseVisible((function(e){if(!(e instanceof Ua&&e.userData.buffer.parameters.sortParticles))return;const i=e.geometry.attributes,n=i.position.count;if(0===n)return;let r,s,a,o,l,c,u,h;Fc.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld),Bc.multiplyMatrices(t.projectionMatrix,Fc),e.userData.sortData?(r=e.userData.sortData,a=r.__zArray,s=r.__sortArray,o=r.__cmpFn):(a=new Float32Array(n),s=new Uint32Array(n),o=function(e,t){const i=a[e],n=a[t];return i>n?1:it?1:e=c&&t(e[a],s)>0;)e[a+1]=e[a],--a;e[a+1]=s}if(-1===l)break;u=r[l--],c=r[l--]}else{for(a=c+1,o=u,h(c+u>>1,a),t(e[c],e[u])>0&&h(c,u),t(e[a],e[u])>0&&h(a,u),t(e[c],e[a])>0&&h(c,a),s=e[a];;){do{a++}while(t(e[a],s)<0);do{o--}while(t(e[o],s)>0);if(o=o-c?(r[++l]=a,r[++l]=u,u=o-1):(r[++l]=c,r[++l]=o-1,c=a)}}(s,o);for(let e in i){const t=i[e],a=t.array,o=t.itemSize;r[e]||(r[e]=new Float32Array(o*n)),h=r[e],r[e]=a;for(let e=0;e0&&"stereo"!==this.parameters.cameraType?this.__renderSuperSample(t,i):this.__renderModelGroup(t,i)}render(e=!1,t){if(this.rendering)Fl.warn("'tried to call 'render' from within 'render'");else{this.rendering=!0;try{this.__updateClipping(),this.__updateCamera(),this.__updateLights(),this.updateInfo(!0),"stereo"===this.parameters.cameraType?this.__renderStereo(e,t):this.__render(e,this.camera,t),this.lastRenderedPicking=e}finally{this.rendering=!1,this.renderPending=!1}this.signals.rendered.dispatch()}}clear(){Fl.log("scene cleared"),this.scene.remove(this.rotationGroup),this._initScene(),this.renderer.clear()}dispose(){this.renderer.dispose(),window.cancelAnimationFrame(this.frameRequest)}}function Jc(e){const t=e.touches[0].pageX-e.touches[1].pageX,i=e.touches[0].pageY-e.touches[1].pageY;return Math.sqrt(t*t+i*i)}class eu{constructor(e,t={}){this.domElement=e,this.signals={moved:new Yo.Signal,scrolled:new Yo.Signal,dragged:new Yo.Signal,dropped:new Yo.Signal,clicked:new Yo.Signal,hovered:new Yo.Signal,doubleClicked:new Yo.Signal},this.position=new Ge,this.prevPosition=new Ge,this.down=new Ge,this.canvasPosition=new Ge,this.prevClickCP=new Ge,this.moving=!1,this.hovering=!0,this.scrolled=!1,this.lastMoved=1/0,this.which=0,this.buttons=0,this.pressed=!1,this.altKey=!1,this.ctrlKey=!1,this.metaKey=!1,this.shiftKey=!1,this.domElement.style.touchAction="none",this.hoverTimeout=uo(t.hoverTimeout,50),this.handleScroll=uo(t.handleScroll,!0),this.doubleClickSpeed=uo(t.doubleClickSpeed,500),this._listen=this._listen.bind(this),this._onMousewheel=this._onMousewheel.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMousedown=this._onMousedown.bind(this),this._onMouseup=this._onMouseup.bind(this),this._onContextmenu=this._onContextmenu.bind(this),this._onTouchstart=this._onTouchstart.bind(this),this._onTouchend=this._onTouchend.bind(this),this._onTouchmove=this._onTouchmove.bind(this),this._listen();const i={passive:!1};document.addEventListener("mousewheel",this._onMousewheel,i),document.addEventListener("wheel",this._onMousewheel,i),document.addEventListener("MozMousePixelScroll",this._onMousewheel,i),document.addEventListener("mousemove",this._onMousemove,i),document.addEventListener("mousedown",this._onMousedown,i),document.addEventListener("mouseup",this._onMouseup,i),document.addEventListener("contextmenu",this._onContextmenu,i),document.addEventListener("touchstart",this._onTouchstart,i),document.addEventListener("touchend",this._onTouchend,i),document.addEventListener("touchmove",this._onTouchmove,i)}get key(){let e=0;return this.altKey&&(e+=1),this.ctrlKey&&(e+=2),this.metaKey&&(e+=4),this.shiftKey&&(e+=8),e}setParameters(e={}){this.hoverTimeout=uo(e.hoverTimeout,this.hoverTimeout)}_listen(){const e=window.performance.now(),t=this.canvasPosition;this.doubleClickPending&&e-this.lastClicked>this.doubleClickSpeed&&(this.doubleClickPending=!1),e-this.lastMoved>this.hoverTimeout&&(this.moving=!1),(this.scrolled||!this.moving&&!this.hovering)&&(this.scrolled=!1,-1!==this.hoverTimeout&&this.overElement&&(this.hovering=!0,this.signals.hovered.dispatch(t.x,t.y))),this.frameRequest=window.requestAnimationFrame(this._listen)}_onMousewheel(e){if(e.target!==this.domElement||!this.handleScroll)return;e.preventDefault(),this._setKeys(e);let t=0;"deltaY"in e&&"deltaMode"in e&&void 0!==e.deltaY&&void 0!==e.deltaMode?t=e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?.025*-e.deltaY:e.deltaMode===WheelEvent.DOM_DELTA_LINE?-e.deltaY*(2.5/3):2.5*-e.deltaY:"deltaY"in e&&!("detail"in e)?t=.025*-e.deltaY:void 0!==e.wheelDelta?t=.025*-e.wheelDelta:void 0!==e.wheelDeltaY?t=.025*-e.wheelDeltaY:void 0!==e.detail&&(t=-e.detail/3),this.signals.scrolled.dispatch(t),setTimeout((()=>{this.scrolled=!0}),this.hoverTimeout)}_onMousemove(e){e.target===this.domElement?(e.preventDefault(),this.overElement=!0):this.overElement=!1,this._setKeys(e),this.moving=!0,this.hovering=!1,this.lastMoved=window.performance.now(),this.prevPosition.copy(this.position),this.position.set(e.clientX,e.clientY),this._setCanvasPosition(e);const t=this.prevPosition.x-this.position.x,i=this.prevPosition.y-this.position.y;this.signals.moved.dispatch(t,i),this.pressed&&this.signals.dragged.dispatch(t,i)}_onMousedown(e){e.target===this.domElement&&(e.preventDefault(),this._setKeys(e),this.moving=!1,this.hovering=!1,this.down.set(e.clientX,e.clientY),this.position.set(e.clientX,e.clientY),this.which=e.which,this.buttons=function(e){if("object"==typeof e){if("buttons"in e)return e.buttons;if("which"in e){const t=e.which;if(2===t)return 4;if(3===t)return 2;if(t>0)return 1<=0)return 1<2&&this.handleScroll&&this.position.distanceTo(this.prevPosition)<2)this.which=0,this.buttons=0,this.signals.scrolled.dispatch(i/2);else{this.which=3,this.buttons=2;const e=this.prevPosition.x-this.position.x,t=this.prevPosition.y-this.position.y;this.signals.moved.dispatch(e,t),this.pressed&&this.signals.dragged.dispatch(e,t)}}}}_distance(){return this.position.distanceTo(this.down)}_setCanvasPosition(e){const t=this.domElement.getBoundingClientRect();let i,n;"clientX"in e&&"clientY"in e?(i=e.clientX-t.left,n=e.clientY-t.top):(i=e.offsetX,n=e.offsetY),this.canvasPosition.set(i,t.height-n)}_setKeys(e){this.altKey=e.altKey,this.ctrlKey=e.ctrlKey,this.metaKey=e.metaKey,this.shiftKey=e.shiftKey}dispose(){document.removeEventListener("mousewheel",this._onMousewheel),document.removeEventListener("wheel",this._onMousewheel),document.removeEventListener("MozMousePixelScroll",this._onMousewheel),document.removeEventListener("mousemove",this._onMousemove),document.removeEventListener("mousedown",this._onMousedown),document.removeEventListener("mouseup",this._onMouseup),document.removeEventListener("contextmenu",this._onContextmenu),document.removeEventListener("touchstart",this._onTouchstart),document.removeEventListener("touchend",this._onTouchend),document.removeEventListener("touchmove",this._onTouchmove),window.cancelAnimationFrame(this.frameRequest)}}const tu=new qt,iu=new qt,nu=new qt,ru=new qt,su=new qt,au=new _t,ou=new gt,lu=new gt,cu=new qt,uu=new _t,hu=new _t;class du{constructor(e,t={}){this.stage=e,this.rotateSpeed=uo(t.rotateSpeed,2),this.zoomSpeed=uo(t.zoomSpeed,1.2),this.panSpeed=uo(t.panSpeed,1),this.viewer=e.viewer,this.mouse=e.mouseObserver,this.controls=e.viewerControls}get component(){return this.stage.transformComponent}get atom(){return this.stage.transformAtom}_setPanVector(e,t,i=0){const n=this.controls.getCanvasScaleFactor(i);uu.set(e,t,0),uu.multiplyScalar(this.panSpeed*n)}_getRotateXY(e,t){return[this.rotateSpeed*-e*.01,this.rotateSpeed*t*.01]}_getCameraRotation(e){return e.extractRotation(this.viewer.camera.matrixWorld),e.multiply(iu.makeRotationY(Math.PI)),e}_transformPanVector(){this.component&&(cu.extractRotation(this.component.transform),cu.premultiply(this.viewer.rotationGroup.matrix),cu.invert(),cu.multiply(this._getCameraRotation(ru)),uu.applyMatrix4(cu))}zoom(e){this.controls.zoom(this.zoomSpeed*e*.02)}pan(e,t){this._setPanVector(e,t),cu.copy(this.viewer.rotationGroup.matrix).invert(),cu.multiply(this._getCameraRotation(ru)),uu.applyMatrix4(cu),this.controls.translate(uu)}panComponent(e,t){this.component&&(this._setPanVector(e,t),this._transformPanVector(),this.component.position.add(uu),this.component.updateMatrix())}panAtom(e,t){this.atom&&this.component&&(this.atom.positionToVector3(hu),hu.add(this.viewer.translationGroup.position),hu.applyMatrix4(this.viewer.rotationGroup.matrix),this._setPanVector(e,t,hu.z),this._transformPanVector(),this.atom.positionAdd(uu),this.component.updateRepresentations({position:!0}))}rotate(e,t){const[i,n]=this._getRotateXY(e,t);this._getCameraRotation(ru),au.set(1,0,0),au.applyMatrix4(ru),ou.setFromAxisAngle(au,n),au.set(0,1,0),au.applyMatrix4(ru),lu.setFromAxisAngle(au,i),ou.multiply(lu),ru.makeRotationFromQuaternion(ou),this.controls.applyMatrix(ru)}zRotate(e,t){const i=this.rotateSpeed*((-e+t)/-2)*.01;nu.makeRotationZ(i),this.controls.applyMatrix(nu)}rotateComponent(e,t){if(!this.component)return;const[i,n]=this._getRotateXY(e,t);this._getCameraRotation(su),ru.extractRotation(this.component.transform),ru.premultiply(this.viewer.rotationGroup.matrix),ru.invert(),ru.premultiply(su),au.set(1,0,0),au.applyMatrix4(ru),tu.makeRotationAxis(au,n),au.set(0,1,0),au.applyMatrix4(ru),iu.makeRotationAxis(au,i),tu.multiply(iu),ou.setFromRotationMatrix(tu),this.component.quaternion.premultiply(ou),this.component.quaternion.normalize(),this.component.updateMatrix()}}const fu=new _t;class mu{constructor(e,t){this.stage=t,this.pid=e.pid,this.picker=e.picker,this.instance=e.instance,this.stage=t,this.controls=t.viewerControls,this.mouse=t.mouseObserver}get type(){return this.picker.type}get altKey(){return this.mouse.altKey}get ctrlKey(){return this.mouse.ctrlKey}get metaKey(){return this.mouse.metaKey}get shiftKey(){return this.mouse.shiftKey}get canvasPosition(){return this.mouse.canvasPosition}get component(){return this.stage.getComponentsByObject(this.picker.data).list[0]}get object(){return this.picker.getObject(this.pid)}get position(){return this.picker.getPosition(this.pid,this.instance,this.component)}get closestBondAtom(){if("bond"!==this.type||!this.bond)return;const e=this.bond,t=this.controls,i=this.canvasPosition,n=e.atom1.positionToVector3(),r=e.atom2.positionToVector3();n.applyMatrix4(this.component.matrix),r.applyMatrix4(this.component.matrix);const s=t.getPositionOnCanvas(n),a=t.getPositionOnCanvas(r);return l=s,c=a,(o=i).distanceTo(l)=e.length))return new mu(i,this.stage);console.error("pid >= picker.array.length")}}}const gu=new gt,_u=new _t,yu=new _t,vu=new _t,bu=new _t,xu=new qt,wu=new _t,Su=new qt;class Mu{constructor(e){this.stage=e,this.signals={changed:new Yo.Signal},this.viewer=e.viewer}get position(){return this.viewer.translationGroup.position}get rotation(){return this.viewer.rotationGroup.quaternion}changed(){this.viewer.requestRender(),this.signals.changed.dispatch()}getPositionOnCanvas(e,t){const i=Ao(t,Ge);const n=this.viewer;return vu.copy(e).add(n.translationGroup.position).applyMatrix4(n.rotationGroup.matrix).project(n.camera),i.set((vu.x+1)*n.width/2,(vu.y+1)*n.height/2)}getCanvasScaleFactor(e=0){const t=this.viewer.camera;if(t instanceof Qn)return 1/t.zoom;{e=Math.abs(e),e+=this.getCameraDistance();const i=Ro(t.fov);return 2*e*Math.tan(i/2)/this.viewer.height}}getOrientation(e){const t=To(e);t.copy(this.viewer.rotationGroup.matrix);const i=this.getCameraDistance();return t.scale(bu.set(i,i,i)),t.setPosition(this.viewer.translationGroup.position),t}orient(e){To(e).decompose(_u,gu,yu);const t=this.viewer;t.rotationGroup.setRotationFromQuaternion(gu),t.translationGroup.position.copy(_u),t.cameraDistance=yu.z,t.updateZoom(),this.changed()}translate(e){this.viewer.translationGroup.position.add(Co(e)),this.changed()}center(e){this.viewer.translationGroup.position.copy(Co(e)).negate(),this.changed()}zoom(e){this.distance(this.getCameraDistance()*(1-e))}getCameraDistance(){return this.viewer.cameraDistance}distance(e){this.viewer.cameraDistance=Math.max(Math.abs(e),.2),this.viewer.updateZoom(),this.changed()}spin(e,t){xu.copy(this.viewer.rotationGroup.matrix).invert(),wu.copy(Co(e)).applyMatrix4(xu),this.viewer.rotationGroup.rotateOnAxis(wu,t),this.changed()}rotate(e){this.viewer.rotationGroup.setRotationFromQuaternion(Po(e)),this.changed()}align(e){Su.copy(To(e)).invert(),this.viewer.rotationGroup.setRotationFromMatrix(Su),this.changed()}applyMatrix(e){this.viewer.rotationGroup.applyMatrix4(To(e)),this.changed()}}class Au{constructor(e,t,...i){this.pausedTime=-1,this.elapsedDuration=0,this.pausedDuration=0,this.ignoreGlobalToggle=!1,this._paused=!1,this._resolveList=[],this.duration=uo(e,1e3),this.controls=t,this.startTime=window.performance.now(),this._init(...i)}get done(){return 1===this.alpha}get paused(){return this._paused}tick(e){if(!this._paused)return this.elapsedDuration=e.currentTime-this.startTime-this.pausedDuration,0===this.duration?this.alpha=1:this.alpha=zo(0,1,this.elapsedDuration/this.duration),this._tick(e),this.done&&this._resolveList.forEach((e=>e())),this.done}pause(e){e&&(this._hold=!0),-1===this.pausedTime&&(this.pausedTime=window.performance.now()),this._paused=!0}resume(e){!e&&this._hold||(this.pausedDuration+=window.performance.now()-this.pausedTime,this._paused=!1,this._hold=!1,this.pausedTime=-1)}toggle(){this._paused?this.resume():this.pause()}then(e){let t;return t=this.done?Promise.resolve():new Promise((e=>this._resolveList.push(e))),t.then(e)}}class Cu extends Au{constructor(e,t,...i){super(uo(e,1/0),t,...i)}_init(e,t){Array.isArray(e)?this.axis=(new _t).fromArray(e):this.axis=uo(e,new _t(0,1,0)),this.angle=uo(t,.01)}_tick(e){this.axis&&this.angle&&this.controls.spin(this.axis,this.angle*e.lastDuration/16)}}class Tu extends Au{constructor(e,t,...i){super(uo(e,1/0),t,...i),this.angleSum=0,this.direction=1}_init(e,t,i){Array.isArray(e)?this.axis=(new _t).fromArray(e):this.axis=uo(e,new _t(0,1,0)),this.angleStep=uo(t,.01),this.angleEnd=uo(i,.2)}_tick(e){if(!this.axis||!this.angleStep||!this.angleEnd)return;const t=zo(0,1,Math.abs(this.angleSum)/this.angleEnd),i=this.angleStep*this.direction*(1.1-t);this.controls.spin(this.axis,i*e.lastDuration/16),this.angleSum+=this.angleStep,this.angleSum>=this.angleEnd&&(this.direction*=-1,this.angleSum=-this.angleEnd)}}class Pu extends Au{_init(e,t){this.moveFrom=Co(uo(e,new _t)),this.moveTo=Co(uo(t,new _t))}_tick(){this.controls.position.lerpVectors(this.moveFrom,this.moveTo,this.alpha).negate(),this.controls.changed()}}class Eu extends Au{_init(e,t){this.zoomFrom=e,this.zoomTo=t}_tick(){this.controls.distance(Fo(this.zoomFrom,this.zoomTo,this.alpha))}}class Iu extends Au{constructor(){super(...arguments),this._currentRotation=new gt}_init(e,t){this.rotateFrom=Po(e),this.rotateTo=Po(t),this._currentRotation=new gt}_tick(){this._currentRotation.copy(this.rotateFrom).slerp(this.rotateTo,this.alpha),this.controls.rotate(this._currentRotation)}}class Du extends Au{_init(e,t,i){this.valueFrom=e,this.valueTo=t,this.callback=i}_tick(){this.callback(Fo(this.valueFrom,this.valueTo,this.alpha))}}class Ru extends Au{_init(e){this.callback=e}_tick(){1===this.alpha&&this.callback()}}class Lu{constructor(e=[]){this._resolveList=[],this._list=e}get done(){return this._list.every((e=>e.done))}then(e){let t;return t=this.done?Promise.resolve():new Promise((e=>{this._resolveList.push(e),this._list.forEach((e=>{e.then((()=>{this._resolveList.forEach((e=>{e()})),this._resolveList.length=0}))}))})),t.then(e)}}class ku{constructor(e){this.stage=e,this.animationList=[],this.finishedList=[],this.viewer=e.viewer,this.controls=e.viewerControls}get paused(){return this.animationList.every((e=>e.paused))}add(e){return 0===e.duration?e.tick(this.viewer.stats):this.animationList.push(e),e}remove(e){const t=this.animationList,i=t.indexOf(e);i>-1&&t.splice(i,1)}run(e){const t=this.finishedList,i=this.animationList,n=i.length;for(let r=0;re.pause()))}resume(){this.animationList.forEach((e=>e.resume()))}toggle(){this.paused?this.resume():this.pause()}clear(){this.animationList.length=0}dispose(){this.clear()}}class Ou{constructor(e,t){if(this.fn=e,this.queue=[],this.pending=!1,this.next=this.next.bind(this),t){for(let e=0,i=t.length;ethis.run(e)))):this.pending=!1}push(e){this.queue.push(e),this.pending||this.next()}kill(){this.queue.length=0}length(){return this.queue.length}}class Nu{constructor(e,t,i){this.type="",this.parameters={lazy:{type:"boolean"},clipNear:{type:"range",step:1,max:100,min:0,buffer:!0},clipRadius:{type:"number",precision:1,max:1e3,min:0,buffer:!0},clipCenter:{type:"vector3",precision:1,buffer:!0},flatShaded:{type:"boolean",buffer:!0},opacity:{type:"range",step:.01,max:1,min:0,buffer:!0},depthWrite:{type:"boolean",buffer:!0},side:{type:"select",buffer:!0,options:{front:"front",back:"back",double:"double"}},wireframe:{type:"boolean",buffer:!0},colorData:{type:"hidden",update:"color"},colorScheme:{type:"select",update:"color",options:{}},colorScale:{type:"select",update:"color",options:$l.getScales()},colorReverse:{type:"boolean",update:"color"},colorValue:{type:"color",update:"color"},colorDomain:{type:"hidden",update:"color"},colorMode:{type:"select",update:"color",options:$l.getModes()},roughness:{type:"range",step:.01,max:1,min:0,buffer:!0},metalness:{type:"range",step:.01,max:1,min:0,buffer:!0},diffuse:{type:"color",buffer:!0},diffuseInterior:{type:"boolean",buffer:!0},useInteriorColor:{type:"boolean",buffer:!0},interiorColor:{type:"color",buffer:!0},interiorDarkening:{type:"range",step:.01,max:1,min:0,buffer:!0},matrix:{type:"hidden",buffer:!0},disablePicking:{type:"boolean",rebuild:!0}},this.viewer=t,this.tasks=new hc,this.queue=new Ou(this.make.bind(this)),this.bufferList=[],this.parameters.colorScheme&&(this.parameters.colorScheme.options=$l.getSchemes()),this.toBePrepared=!1}init(e){const t=e||{};this.clipNear=uo(t.clipNear,0),this.clipRadius=uo(t.clipRadius,0),this.clipCenter=uo(t.clipCenter,new _t),this.flatShaded=uo(t.flatShaded,!1),this.side=uo(t.side,"double"),this.opacity=uo(t.opacity,1),this.depthWrite=uo(t.depthWrite,!0),this.wireframe=uo(t.wireframe,!1),this.setColor(t.color,t),this.colorData=uo(t.colorData,void 0),this.colorScheme=uo(t.colorScheme,"uniform"),this.colorScale=uo(t.colorScale,""),this.colorReverse=uo(t.colorReverse,!1),this.colorValue=uo(t.colorValue,9474192),this.colorDomain=uo(t.colorDomain,void 0),this.colorMode=uo(t.colorMode,"hcl"),this.visible=uo(t.visible,!0),this.quality=uo(t.quality,void 0),this.roughness=uo(t.roughness,.4),this.metalness=uo(t.metalness,0),this.diffuse=uo(t.diffuse,16777215),this.diffuseInterior=uo(t.diffuseInterior,!1),this.useInteriorColor=uo(t.useInteriorColor,!1),this.interiorColor=uo(t.interiorColor,2236962),this.interiorDarkening=uo(t.interiorDarkening,0),this.lazy=uo(t.lazy,!1),this.lazyProps={build:!1,bufferParams:{},what:{}},this.matrix=uo(t.matrix,new qt),this.disablePicking=uo(t.disablePicking,!1);const i=this.parameters;!0===i.sphereDetail&&(i.sphereDetail={type:"integer",max:3,min:0,rebuild:"impostor"}),!0===i.radialSegments&&(i.radialSegments={type:"integer",max:25,min:5,rebuild:"impostor"}),!0===i.openEnded&&(i.openEnded={type:"boolean",rebuild:"impostor",buffer:!0}),!0===i.disableImpostor&&(i.disableImpostor={type:"boolean",rebuild:!0}),"low"===t.quality?(i.sphereDetail&&(this.sphereDetail=0),i.radialSegments&&(this.radialSegments=5)):"medium"===t.quality?(i.sphereDetail&&(this.sphereDetail=1),i.radialSegments&&(this.radialSegments=10)):"high"===t.quality?(i.sphereDetail&&(this.sphereDetail=2),i.radialSegments&&(this.radialSegments=20)):(i.sphereDetail&&(this.sphereDetail=uo(t.sphereDetail,1)),i.radialSegments&&(this.radialSegments=uo(t.radialSegments,10))),i.openEnded&&(this.openEnded=uo(t.openEnded,!0)),i.disableImpostor&&(this.disableImpostor=uo(t.disableImpostor,!1))}getColorParams(e){return Object.assign({data:this.colorData,scheme:this.colorScheme,scale:this.colorScale,reverse:this.colorReverse,value:this.colorValue,domain:this.colorDomain,mode:this.colorMode,colorSpace:this.colorSpace},e)}getBufferParams(e={}){return Object.assign({clipNear:this.clipNear,clipRadius:this.clipRadius,clipCenter:this.clipCenter,flatShaded:this.flatShaded,opacity:this.opacity,depthWrite:this.depthWrite,side:this.side,wireframe:this.wireframe,roughness:this.roughness,metalness:this.metalness,diffuse:this.diffuse,diffuseInterior:this.diffuseInterior,useInteriorColor:this.useInteriorColor,interiorColor:this.interiorColor,interiorDarkening:this.interiorDarkening,matrix:this.matrix,disablePicking:this.disablePicking},e)}setColor(e,t){const i=Object.keys($l.getSchemes());if("string"==typeof e&&i.includes(e.toLowerCase()))t?t.colorScheme=e:this.setParameters({colorScheme:e});else if(void 0!==e){let i=new Oi(e).getHex();t?(t.colorScheme="uniform",t.colorValue=i):this.setParameters({colorScheme:"uniform",colorValue:i})}return this}prepare(e){}create(){}update(e){this.build()}build(e){if(!this.lazy||this.visible&&this.opacity){if(!this.toBePrepared)return this.tasks.increment(),void this.make();this.queue.length()>0?(this.tasks.change(1-this.queue.length()),this.queue.kill()):this.tasks.increment(),this.queue.push(e||!1)}else this.lazyProps.build=!0}make(t,i){e.Debug&&Fl.time("Representation.make "+this.type);const n=()=>{t?(this.update(t),this.viewer.requestRender(),this.tasks.decrement(),i&&i()):(this.clear(),this.create(),this.manualAttach||this.disposed||(e.Debug&&Fl.time("Representation.attach "+this.type),this.attach((()=>{e.Debug&&Fl.timeEnd("Representation.attach "+this.type),this.tasks.decrement(),i&&i()})))),e.Debug&&Fl.timeEnd("Representation.make "+this.type)};this.toBePrepared?this.prepare(n):n()}attach(e){this.setVisibility(this.visible),e()}setVisibility(e,t){if(this.visible=e,this.visible&&this.opacity){const e=this.lazyProps,t=e.bufferParams,i=e.what;if(e.build)return e.build=!1,this.build(),this;(Object.keys(t).length||Object.keys(i).length)&&(e.bufferParams={},e.what={},this.updateParameters(t,i))}return this.bufferList.forEach((function(t){t.setVisibility(e)})),t||this.viewer.requestRender(),this}setParameters(e,t={},i=!1){const n=e||{},r=this.parameters,s={};this.opacity||void 0===n.opacity||(this.lazyProps.build?(this.lazyProps.build=!1,i=!0):(Object.assign(s,this.lazyProps.bufferParams),Object.assign(t,this.lazyProps.what),this.lazyProps.bufferParams={},this.lazyProps.what={})),this.setColor(n.color,n);for(let e in n)if(void 0!==n[e]&&null!=r[e]&&(r[e].int&&(n[e]=parseInt(n[e])),r[e].float&&(n[e]=parseFloat(n[e])),n[e]!==this[e]||n[e].equals&&!n[e].equals(this[e]))){if(this[e]&&this[e].copy&&n[e].copy?this[e].copy(n[e]):this[e]&&this[e].set?this[e].set(n[e]):this[e]=n[e],r[e].buffer)if(!0===r[e].buffer)s[e]=n[e];else{s[r[e].buffer]=n[e]}r[e].update&&(t[r[e].update]=!0),!r[e].rebuild||"impostor"===r[e].rebuild&&Ol&&!this.disableImpostor||(i=!0)}return i?this.build():this.updateParameters(s,t),this}updateParameters(e={},t){if(this.lazy&&(!this.visible||!this.opacity)&&!1===e.hasOwnProperty("opacity"))return Object.assign(this.lazyProps.bufferParams,e),void Object.assign(this.lazyProps.what,t);this.bufferList.forEach((function(t){t.setParameters(e)})),Object.keys(t).length&&this.update(t),this.viewer.requestRender()}getParameters(){const e={lazy:this.lazy,visible:this.visible,quality:this.quality};return Object.keys(this.parameters).forEach((t=>{null!==this.parameters[t]&&(e[t]=this[t])})),e}clear(){this.bufferList.forEach((e=>{this.viewer.remove(e),e.dispose()})),this.bufferList.length=0,this.viewer.requestRender()}dispose(){this.disposed=!0,this.queue.kill(),this.tasks.dispose(),this.clear()}}class Fu{constructor(t){this.pending=0,this.postCount=0,this.onmessageDict={},this.onerrorDict={},this.name=t,this.blobUrl=window.URL.createObjectURL(Vl.get(t)),this.worker=new Worker(this.blobUrl),Vl.activeWorkerCount+=1,this.worker.onmessage=i=>{this.pending-=1;const n=i.data.__postId;e.Debug&&Fl.timeEnd("Worker.postMessage "+t+" #"+n);const r=this.onmessageDict[n];r&&r.call(this.worker,i),delete this.onmessageDict[n],delete this.onerrorDict[n]},this.worker.onerror=e=>{if(this.pending-=1,e.data){const i=e.data.__postId,n=this.onerrorDict[i];n?n.call(this.worker,e):Fl.error("Worker.onerror",i,t,e),delete this.onmessageDict[i],delete this.onerrorDict[i]}else Fl.error("Worker.onerror",t,e)}}post(t={},i,n,r){this.onmessageDict[this.postCount]=n,this.onerrorDict[this.postCount]=r,t.__name=this.name,t.__postId=this.postCount,t.__debug=e.Debug,e.Debug&&Fl.time(`Worker.postMessage ${this.name} #${this.postCount}`);try{this.worker.postMessage(t,i)}catch(e){Fl.error("worker.post:",e),this.worker.postMessage(t)}return this.pending+=1,this.postCount+=1,this}terminate(){this.worker?(this.worker.terminate(),window.URL.revokeObjectURL(this.blobUrl),Vl.activeWorkerCount-=1):Fl.log("no worker to terminate")}}class Bu{constructor(e,t=2){this.pool=[],this.count=0,this.maxCount=Math.min(8,t),this.name=e}post(e={},t,i,n){const r=this.getNextWorker();return r?r.post(e,t,i,n):console.error("unable to get worker from pool"),this}terminate(){this.pool.forEach((function(e){e.terminate()}))}getNextWorker(){let e,t=1/0;for(let i=0;i=this.count){e=new Fu(this.name),this.pool.push(e),this.count+=1;break}const n=this.pool[i];if(0===n.pending){e=n;break}n.pendingr&&(r=l),c>s&&(s=c),u>a&&(a=u)}return[ju([t,i,n]),ju([r,s,a])]}function $u(e,t){for(let i=0,n=t.length;i0){const a=1/Math.sqrt(s);e[t]=i*a,e[t+1]=n*a,e[t+2]=r*a}}}function ju(e){return new Float32Array(e||3)}function Wu(e,t,i){const n=t[0],r=t[1],s=t[2],a=i[0],o=i[1],l=i[2];e[0]=r*l-s*o,e[1]=s*a-n*l,e[2]=n*o-r*a}function qu(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function Xu(e,t,i){e[0]=t[0]-i[0],e[1]=t[1]-i[1],e[2]=t[2]-i[2]}function Yu(e,t,i){e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2]}function Ku(e,t,i=0){e[0]=t[i],e[1]=t[i+1],e[2]=t[i+2]}function Zu(e,t,i=0){t[i]=e[0],t[i+1]=e[1],t[i+2]=e[2]}function Qu(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function Ju(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function eh(e,t,i){th(e,t,1/i)}function th(e,t,i){e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i}function ih(e,t){const i=Qu(t);0==i?(e[0]=t[0],e[1]=t[1],e[2]=t[2]):th(e,t,1/Math.sqrt(i))}function nh(e,t,i){e[0]=t[0]-i,e[1]=t[1]-i,e[2]=t[2]-i}function rh(e,t,i){e[0]=t[0]+i,e[1]=t[1]+i,e[2]=t[2]+i}function sh(e,t){e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2])}function ah(e,t){e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2])}function oh(e,t){e[0]=-t[0],e[1]=-t[1],e[2]=-t[2]}function lh(e,t){const i=e[0],n=e[1],r=e[2],s=t[0],a=t[1],o=t[2],l=n*o-r*a,c=r*s-i*o,u=i*a-n*s,h=Math.sqrt(l*l+c*c+u*u),d=i*s+n*a+r*o;return Math.atan2(h,d)}function ch(e,t=9){const i=Math.floor(t/2),n=e.position1.length/3,r=3*(i*n),s=1/t,a=wc(e.position1,e.position2),o=new Float32Array(r),l=new Float32Array(r),c=new _t;for(let t=0;t0){const t=3*f;r[t]=e.position2[3*u-3],r[t+1]=e.position2[3*u-2],r[t+1]=e.position2[3*u-1]}const g=new Float32Array(n),_=new Float32Array(r),y=xc(g,_),v=new Float32Array(s),b={position:y,position1:g,position2:_,color:v,color2:v};return a&&(b.radius=new Float32Array(a)),o&&e.picking&&(e.picking.array=new Float32Array(o),b.picking=e.picking),l&&(b.primitiveId=new Float32Array(l)),b}Bu.prototype.constructor=Bu,Vu.__deps=[ju],eh.__deps=[th],ih.__deps=[th,Qu];const dh=new _t;class fh{static get Picker(){return Kl.get(this.type)}static get Buffer(){return Yl.get(this.type)}static getShapeKey(e){return this.type+e[0].toUpperCase()+e.substr(1)}static expandBoundingBox(e,t){}static valueToShape(e,t,i){const n=e._primitiveData[this.getShapeKey(t)];switch(this.fields[t]){case"v3":case"c":!function(e,t){void 0!==e.toArray?e=e.toArray():void 0!==e.x?e=[e.x,e.y,e.z]:void 0!==e.r&&(e=[e.r,e.g,e.b]),t.push.apply(t,e)}(i,n);break;default:n.push(i)}}static objectToShape(e,t){Object.keys(this.fields).forEach((i=>{this.valueToShape(e,i,t[i])})),this.valueToShape(e,"name",t.name),this.expandBoundingBox(e.boundingBox,t)}static valueFromShape(e,t,i){const n=e._primitiveData[this.getShapeKey(i)];switch(this.fields[i]){case"v3":return(new _t).fromArray(n,3*t);case"c":return(new Oi).fromArray(n,3*t);default:return n[t]}}static objectFromShape(e,t){let i=this.valueFromShape(e,t,"name");void 0===i&&(i=`${this.type}: ${t} (${e.name})`);const n={shape:e,name:i};return Object.keys(this.fields).forEach((i=>{n[i]=this.valueFromShape(e,t,i)})),n}static arrayFromShape(e,t){const i=e._primitiveData[this.getShapeKey(t)];return"s"===this.fields[t]?i:new Float32Array(i)}static dataFromShape(e){const t={};return this.Picker&&(t.picking=new this.Picker(e)),Object.keys(this.fields).forEach((i=>{t[i]=this.arrayFromShape(e,i)})),t}static bufferFromShape(e,t){return new this.Buffer(this.dataFromShape(e),t)}}fh.type="",fh.fields={};class mh extends fh{static positionFromShape(e,t){return this.valueFromShape(e,t,"position")}static expandBoundingBox(e,t){e.expandByPoint(dh.fromArray(t.position))}}mh.type="sphere",mh.fields={position:"v3",color:"c",radius:"f"};class ph extends fh{static positionFromShape(e,t){return this.valueFromShape(e,t,"position")}static expandBoundingBox(e,t){e.expandByPoint(dh.fromArray(t.position))}}ph.type="box",ph.fields={position:"v3",color:"c",size:"f",heightAxis:"v3",depthAxis:"v3"};class gh extends ph{}gh.type="octahedron";class _h extends ph{}_h.type="tetrahedron";class yh extends fh{static positionFromShape(e,t){const i=this.valueFromShape(e,t,"position1"),n=this.valueFromShape(e,t,"position2");return i.add(n).multiplyScalar(.5)}static expandBoundingBox(e,t){e.expandByPoint(dh.fromArray(t.position1)),e.expandByPoint(dh.fromArray(t.position2))}static bufferFromShape(e,t={}){let i=this.dataFromShape(e);return"cylinder"===this.type&&t.dashedCylinder&&(i=uh(i)),new this.Buffer(i,t)}}yh.type="cylinder",yh.fields={position1:"v3",position2:"v3",color:"c",radius:"f"};class vh extends yh{}vh.type="arrow";class bh extends yh{}bh.type="cone";class xh extends mh{}xh.type="ellipsoid",xh.fields={position:"v3",color:"c",radius:"f",majorAxis:"v3",minorAxis:"v3"};class wh extends xh{}wh.type="torus";class Sh extends fh{static positionFromShape(e,t){return this.valueFromShape(e,t,"position")}static expandBoundingBox(e,t){e.expandByPoint(dh.fromArray(t.position))}}Sh.type="text",Sh.fields={position:"v3",color:"c",size:"f",text:"s"};class Mh extends fh{static positionFromShape(e,t){return this.valueFromShape(e,t,"position")}static expandBoundingBox(e,t){e.expandByPoint(dh.fromArray(t.position))}}Mh.type="point",Mh.fields={position:"v3",color:"c"};class Ah extends fh{static positionFromShape(e,t){const i=this.valueFromShape(e,t,"position1"),n=this.valueFromShape(e,t,"position2");return i.add(n).multiplyScalar(.5)}static expandBoundingBox(e,t){e.expandByPoint(dh.fromArray(t.position1)),e.expandByPoint(dh.fromArray(t.position2))}}Ah.type="wideline",Ah.fields={position1:"v3",position2:"v3",color:"c"};class Ch{constructor(e,t){this.exp=3;const i=t||function(e){const{x:t,y:i,z:n}=e,r=new bt,s=t.length,{min:a,max:o}=r;for(let e=0;e>this.exp),this.boundY=1+(i.max.y-this.minY>>this.exp),this.boundZ=1+(i.max.z-this.minZ>>this.exp);const n=this.boundX*this.boundY*this.boundZ,r=void 0!==e.count?e.count:e.x.length,s=e.x,a=e.y,o=e.z;let l=0;const c=new Uint32Array(n),u=new Int32Array(r);for(let e=0;e>this.exp,i=a[e]-this.minY>>this.exp,n=o[e]-this.minZ>>this.exp,r=(t*this.boundY+i)*this.boundZ+n;1===(c[r]+=1)&&(l+=1),u[e]=r}const h=new Uint16Array(l);for(let e=0,t=0;e0&&(c[e]=t+1,h[t]=i,t+=1)}const d=new Uint32Array(l);for(let e=1;e0){const i=t-1;m[d[i]+f[i]]=e,f[i]+=1}}this.grid=c,this.bucketCount=h,this.bucketOffset=d,this.bucketArray=m,this.xArray=s,this.yArray=a,this.zArray=o}within(e,t,i,n){const r=[];return this.eachWithin(e,t,i,n,(e=>r.push(e))),r}eachWithin(e,t,i,n,r){const s=n*n,a=Math.max(0,e-n-this.minX>>this.exp),o=Math.max(0,t-n-this.minY>>this.exp),l=Math.max(0,i-n-this.minZ>>this.exp),c=Math.min(this.boundX,1+(e+n-this.minX>>this.exp)),u=Math.min(this.boundY,1+(t+n-this.minY>>this.exp)),h=Math.min(this.boundZ,1+(i+n-this.minZ>>this.exp));for(let n=a;n0){const n=c-1,a=this.bucketOffset[n],o=a+this.bucketCount[n];for(let n=a;nn?r.set(this[t].subarray(0,n)):r.set(this[t]),this[t]=r}}growIfFull(){if(this.count>=this.length){const e=Math.round(1.5*this.length);this.resize(Math.max(256,e))}}copyFrom(e,t,i,n){for(let r=0,s=this._fields.length;r0;)u-=1;c<=u&&(c===l?l=u:u===l&&(l=c),(a=c)!==(o=u)&&(i.copyFrom(t,0,a,1),t.copyWithin(a,o,1),t.copyFrom(i,o,0,1)),c+=1,u-=1)}while(c<=u);n(r,u),n(c,s)}var a,o}(0,this.count-1),Fl.timeEnd("Store.sort")}clear(){this.count=0}dispose(){for(let e=0,t=this._fields.length;e>>1&1431655765))+(e>>>2&858993459))+(e>>>4)&252645135)>>>24}class Ih{constructor(e,t){this.length=e,this._words=new Uint32Array(e+32>>>5),!0===t&&this.setAll()}get(e){return!!(this._words[e>>>5]&1<>>5]|=1<>>5]&=~(1<>>5]^=1<>>5,a=t>>>5;for(let e=s+1;e>>5]|=1<>>5]|=1<>>5]|=1<>>5]&=~(1<>>5]&=~(1<>>5]&=~(1<>>5]|=1<>>5]&=~(1<>>i,this}_isRangeValue(e,t,i){if(t>>5,a=t>>>5;for(let e=s+1;e>>5]&1<>>5]&1<>>5]&1<>>5]&1<>>5]&1<0){const{types:n,groups:r,centers:s,atomSets:a}=e;n.push(t.type),r.push(t.group),s.x.push(t.x/i),s.y.push(t.y/i),s.z.push(t.z/i),a.push(t.atomSet)}}const Oh=0,Nh=["D-BETA-PEPTIDE, C-GAMMA LINKING","D-GAMMA-PEPTIDE, C-DELTA LINKING","D-PEPTIDE COOH CARBOXY TERMINUS","D-PEPTIDE NH3 AMINO TERMINUS","D-PEPTIDE LINKING","L-BETA-PEPTIDE, C-GAMMA LINKING","L-GAMMA-PEPTIDE, C-DELTA LINKING","L-PEPTIDE COOH CARBOXY TERMINUS","L-PEPTIDE NH3 AMINO TERMINUS","L-PEPTIDE LINKING","PEPTIDE LINKING","PEPTIDE-LIKE"],Fh=["RNA OH 3 PRIME TERMINUS","RNA OH 5 PRIME TERMINUS","RNA LINKING"],Bh=["DNA OH 3 PRIME TERMINUS","DNA OH 5 PRIME TERMINUS","DNA LINKING","L-DNA LINKING","L-RNA LINKING"],zh=["D-SACCHARIDE","D-SACCHARIDE 1,4 AND 1,4 LINKING","D-SACCHARIDE 1,4 AND 1,6 LINKING","L-SACCHARIDE","L-SACCHARIDE 1,4 AND 1,4 LINKING","L-SACCHARIDE 1,4 AND 1,6 LINKING","SACCHARIDE"],Uh=["NON-POLYMER"].concat(["OTHER"],zh),Vh=["h","g","i"],$h=["e","b"],Gh=["s","t","l",""],Hh={H:1,D:1,T:1,HE:2,LI:3,BE:4,B:5,C:6,N:7,O:8,F:9,NE:10,NA:11,MG:12,AL:13,SI:14,P:15,S:16,CL:17,AR:18,K:19,CA:20,SC:21,TI:22,V:23,CR:24,MN:25,FE:26,CO:27,NI:28,CU:29,ZN:30,GA:31,GE:32,AS:33,SE:34,BR:35,KR:36,RB:37,SR:38,Y:39,ZR:40,NB:41,MO:42,TC:43,RU:44,RH:45,PD:46,AG:47,CD:48,IN:49,SN:50,SB:51,TE:52,I:53,XE:54,CS:55,BA:56,LA:57,CE:58,PR:59,ND:60,PM:61,SM:62,EU:63,GD:64,TB:65,DY:66,HO:67,ER:68,TM:69,YB:70,LU:71,HF:72,TA:73,W:74,RE:75,OS:76,IR:77,PT:78,AU:79,HG:80,TL:81,PB:82,BI:83,PO:84,AT:85,RN:86,FR:87,RA:88,AC:89,TH:90,PA:91,U:92,NP:93,PU:94,AM:95,CM:96,BK:97,CF:98,ES:99,FM:100,MD:101,NO:102,LR:103,RF:104,DB:105,SG:106,BH:107,HS:108,MT:109,DS:110,RG:111,CN:112,NH:113,FL:114,MC:115,LV:116,TS:117,OG:118},jh={1:1.1,2:1.4,3:1.81,4:1.53,5:1.92,6:1.7,7:1.55,8:1.52,9:1.47,10:1.54,11:2.27,12:1.73,13:1.84,14:2.1,15:1.8,16:1.8,17:1.75,18:1.88,19:2.75,20:2.31,21:2.3,22:2.15,23:2.05,24:2.05,25:2.05,26:2.05,27:2,28:2,29:2,30:2.1,31:1.87,32:2.11,33:1.85,34:1.9,35:1.83,36:2.02,37:3.03,38:2.49,39:2.4,40:2.3,41:2.15,42:2.1,43:2.05,44:2.05,45:2,46:2.05,47:2.1,48:2.2,49:2.2,50:1.93,51:2.17,52:2.06,53:1.98,54:2.16,55:3.43,56:2.68,57:2.5,58:2.48,59:2.47,60:2.45,61:2.43,62:2.42,63:2.4,64:2.38,65:2.37,66:2.35,67:2.33,68:2.32,69:2.3,70:2.28,71:2.27,72:2.25,73:2.2,74:2.1,75:2.05,76:2,77:2,78:2.05,79:2.1,80:2.05,81:1.96,82:2.02,83:2.07,84:1.97,85:2.02,86:2.2,87:3.48,88:2.83,89:2,90:2.4,91:2,92:2.3,93:2,94:2,95:2,96:2,97:2,98:2,99:2,100:2,101:2,102:2,103:2,104:2,105:2,106:2,107:2,108:2,109:2,110:2,111:2,112:2,113:2,114:2,115:2,116:2,117:2,118:2},Wh={1:.31,2:.28,3:1.28,4:.96,5:.84,6:.76,7:.71,8:.66,9:.57,10:.58,11:1.66,12:1.41,13:1.21,14:1.11,15:1.07,16:1.05,17:1.02,18:1.06,19:2.03,20:1.76,21:1.7,22:1.6,23:1.53,24:1.39,25:1.39,26:1.32,27:1.26,28:1.24,29:1.32,30:1.22,31:1.22,32:1.2,33:1.19,34:1.2,35:1.2,36:1.16,37:2.2,38:1.95,39:1.9,40:1.75,41:1.64,42:1.54,43:1.47,44:1.46,45:1.42,46:1.39,47:1.45,48:1.44,49:1.42,50:1.39,51:1.39,52:1.38,53:1.39,54:1.4,55:2.44,56:2.15,57:2.07,58:2.04,59:2.03,60:2.01,61:1.99,62:1.98,63:1.98,64:1.96,65:1.94,66:1.92,67:1.92,68:1.89,69:1.9,70:1.87,71:1.87,72:1.75,73:1.7,74:1.62,75:1.51,76:1.44,77:1.41,78:1.36,79:1.36,80:1.32,81:1.45,82:1.46,83:1.48,84:1.4,85:1.5,86:1.5,87:2.6,88:2.21,89:2.15,90:2.06,91:2,92:1.96,93:1.9,94:1.87,95:1.8,96:1.69,97:1.6,98:1.6,99:1.6,100:1.6,101:1.6,102:1.6,103:1.6,104:1.6,105:1.6,106:1.6,107:1.6,108:1.6,109:1.6,110:1.6,111:1.6,112:1.6,113:1.6,114:1.6,115:1.6,116:1.6,117:1.6,118:1.6},qh={1:[1],2:[0],3:[1],4:[2],5:[3],6:[4],7:[3],8:[2],9:[1],10:[0],11:[1],12:[2],13:[6],14:[6],15:[3,5,7],16:[2,4,6],17:[1],18:[0],19:[1],20:[2],31:[3],32:[4],33:[3,5],34:[2,4,6],35:[1],36:[0],37:[1],38:[2],49:[3],50:[4],51:[3,5],52:[2],53:[1,2,5],54:[0,2],55:[1],56:[2],81:[3],82:[4],83:[3],84:[2],85:[1],86:[0],87:[1],88:[2]},Xh={1:1,2:2,3:1,4:2,5:3,6:4,7:5,8:6,9:7,10:8,11:1,12:2,13:3,14:4,15:5,16:6,17:7,18:8,19:1,20:2,21:3,22:4,23:5,24:6,25:7,26:8,27:9,28:10,29:11,30:2,31:3,32:4,33:5,34:6,35:7,36:8,37:1,38:2,39:3,40:4,41:5,42:6,43:7,44:8,45:9,46:10,47:11,48:2,49:3,50:4,51:5,52:6,53:7,54:8,55:1,56:2,57:3,58:4,59:3,60:4,61:5,62:6,63:7,64:8,65:9,66:10,67:11,68:12,69:13,70:14,71:15,72:4,73:5,74:6,75:7,76:8,77:9,78:10,79:11,80:2,81:3,82:4,83:5,84:6,85:7,86:8,87:1,88:2,89:3,90:4,91:3,92:4,93:5,94:6,95:7,96:8,97:9,98:10,99:11,100:12,101:13,102:14,103:15,104:2,105:2,106:2,107:2,108:2,109:2,110:2,111:2,112:2,113:3,114:4,115:5,116:6,117:7,118:8},Yh={ALA:[.17,.5,.33],ARG:[.81,1.81,1],ASN:[.42,.85,.43],ASP:[1.23,3.64,2.41],ASH:[-.07,.43,.5],CYS:[-.24,-.02,.22],GLN:[.58,.77,.19],GLU:[2.02,3.63,1.61],GLH:[-.01,.11,.12],GLY:[.01,1.15,1.14],HIS:[.17,.11,-.06],ILE:[-.31,-1.12,-.81],LEU:[-.56,-1.25,-.69],LYS:[.99,2.8,1.81],MET:[-.23,-.67,-.44],PHE:[-1.13,-1.71,-.58],PRO:[.45,.14,-.31],SER:[.13,.46,.33],THR:[.14,.25,.11],TRP:[-1.85,-2.09,-.24],TYR:[-.94,-.71,.23],VAL:[.07,-.46,-.53]},Kh=[0,0,0],Zh={HIS:"H",ARG:"R",LYS:"K",ILE:"I",PHE:"F",LEU:"L",TRP:"W",ALA:"A",MET:"M",PRO:"P",CYS:"C",ASN:"N",VAL:"V",GLY:"G",SER:"S",GLN:"Q",TYR:"Y",ASP:"D",GLU:"E",THR:"T",SEC:"U",PYL:"O"},Qh=Object.keys(Zh),Jh=["A","C","T","G","U","I"],ed=["DA","DC","DT","DG","DU","DI"],td=["A","G","I","DA","DG","DI"],id=Jh.concat(ed),nd=["SOL","WAT","HOH","H2O","W","DOD","D3O","TIP3","TIP4","SPC"],rd=["118","119","1AL","1CU","2FK","2HP","2OF","3CO","3MT","3NI","3OF","3P8","4MO","4PU","543","6MO","ACT","AG","AL","ALF","AM","ATH","AU","AU3","AUC","AZI","BA","BCT","BEF","BF4","BO4","BR","BS3","BSY","CA","CAC","CD","CD1","CD3","CD5","CE","CHT","CL","CO","CO3","CO5","CON","CR","CS","CSB","CU","CU1","CU3","CUA","CUZ","CYN","DME","DMI","DSC","DTI","DY","E4N","EDR","EMC","ER3","EU","EU3","F","FE","FE2","FPO","GA","GD3","GEP","HAI","HG","HGC","IN","IOD","IR","IR3","IRI","IUM","K","KO4","LA","LCO","LCP","LI","LU","MAC","MG","MH2","MH3","MLI","MLT","MMC","MN","MN3","MN5","MN6","MO1","MO2","MO3","MO4","MO5","MO6","MOO","MOS","MOW","MW1","MW2","MW3","NA","NA2","NA5","NA6","NAO","NAW","NCO","NET","NH4","NI","NI1","NI2","NI3","NO2","NO3","NRU","O4M","OAA","OC1","OC2","OC3","OC4","OC5","OC6","OC7","OC8","OCL","OCM","OCN","OCO","OF1","OF2","OF3","OH","OS","OS4","OXL","PB","PBM","PD","PDV","PER","PI","PO3","PO4","PR","PT","PT4","PTN","RB","RH3","RHD","RU","SB","SCN","SE4","SEK","SM","SMO","SO3","SO4","SR","T1A","TB","TBA","TCN","TEA","TH","THE","TL","TMA","TRA","UNX","V","VN3","VO4","W","WO5","Y1","YB","YB2","YH","YT3","ZCM","ZN","ZN2","ZN3","ZNO","ZO3","OHX"],sd=["045","0AT","0BD","0MK","0NZ","0TS","0V4","0XY","0YT","10M","147","149","14T","15L","16G","18T","18Y","1AR","1BW","1GL","1GN","1JB","1LL","1NA","1S3","26M","26Q","26R","26V","26W","26Y","27C","289","291","293","2DG","2F8","2FG","2FL","2FP","2GL","2M4","2M5","32O","34V","3CM","3DO","3DY","3FM","3LR","3MF","3MG","3SA","3ZW","46D","46M","46Z","48Z","4CQ","4GC","4NN","50A","5DI","5GF","5MM","5RP","5SA","5SP","64K","6PG","6SA","7JZ","7SA","A1Q","A2G","AAB","AAL","AAO","ABC","ABD","ABE","ABF","ABL","ACG","ACI","ACR","ACX","ADA","ADG","ADR","AF1","AFD","AFL","AFO","AFP","AFR","AGC","AGH","AGL","AHR","AIG","ALL","ALX","AMU","AOG","AOS","ARA","ARB","ARE","ARI","ASG","ASO","AXP","AXR","B0D","B16","B2G","B4G","B6D","B8D","B9D","BBK","BCD","BDG","BDP","BDR","BEM","BFP","BGC","BGL","BGP","BGS","BHG","BMA","BMX","BNG","BNX","BOG","BRI","BXF","BXP","BXX","BXY","C3X","C4X","C5X","CAP","CBI","CBK","CBS","CDR","CEG","CGF","CHO","CR1","CR6","CRA","CT3","CTO","CTR","CTT","D6G","DAF","DAG","DDA","DDB","DDL","DEL","DFR","DFX","DG0","DGC","DGD","DGM","DGS","DIG","DLF","DLG","DMU","DNO","DOM","DP5","DQQ","DQR","DR2","DR3","DR4","DRI","DSR","DT6","DVC","E4P","E5G","EAG","EBG","EBQ","EGA","EJT","EPG","ERE","ERI","F1P","F1X","F6P","FBP","FCA","FCB","FCT","FDP","FDQ","FFC","FIX","FMO","FRU","FSI","FU4","FUB","FUC","FUD","FUL","FXP","G16","G1P","G2F","G3I","G4D","G4S","G6D","G6P","G6S","GAC","GAD","GAL","GC1","GC4","GCD","GCN","GCO","GCS","GCT","GCU","GCV","GCW","GCX","GE1","GFG","GFP","GIV","GL0","GL2","GL5","GL6","GL7","GL9","GLA","GLB","GLC","GLD","GLF","GLG","GLO","GLP","GLS","GLT","GLW","GMH","GN1","GNX","GP1","GP4","GPH","GPM","GQ1","GQ2","GQ4","GS1","GS4","GSA","GSD","GTE","GTH","GTK","GTR","GTZ","GU0","GU1","GU2","GU3","GU4","GU5","GU6","GU8","GU9","GUF","GUP","GUZ","GYP","GYV","H2P","HDL","HMS","HS2","HSD","HSG","HSH","HSJ","HSQ","HSR","HSU","HSX","HSY","HSZ","IAB","IDG","IDR","IDS","IDT","IDU","IDX","IDY","IMK","IN1","IPT","ISL","KBG","KD2","KDA","KDM","KDO","KFN","KO1","KO2","KTU","L6S","LAG","LAI","LAK","LAO","LAT","LB2","LBT","LCN","LDY","LGC","LGU","LM2","LMT","LMU","LOG","LOX","LPK","LSM","LTM","LVZ","LXB","LXZ","M1F","M3M","M6P","M8C","MA1","MA2","MA3","MAB","MAG","MAL","MAN","MAT","MAV","MAW","MBG","MCU","MDA","MDM","MDP","MFA","MFB","MFU","MG5","MGA","MGL","MLB","MMA","MMN","MN0","MRP","MTT","MUG","MVP","MXY","N1L","N9S","NAA","NAG","NBG","NDG","NED","NG1","NG6","NGA","NGB","NGC","NGE","NGF","NGL","NGS","NGY","NHF","NM6","NM9","NTF","NTO","NTP","NXD","NYT","OPG","OPM","ORP","OX2","P3M","P53","P6P","PA5","PNA","PNG","PNW","PRP","PSJ","PSV","PTQ","QDK","QPS","QV4","R1P","R1X","R2B","R5P","RAA","RAE","RAF","RAM","RAO","RAT","RB5","RBL","RCD","RDP","REL","RER","RF5","RG1","RGG","RHA","RIB","RIP","RNS","RNT","ROB","ROR","RPA","RST","RUB","RUU","RZM","S6P","S7P","SA0","SCR","SDD","SF6","SF9","SG4","SG5","SG6","SG7","SGA","SGC","SGD","SGN","SGS","SHB","SHG","SI3","SIO","SOE","SOL","SSG","SUC","SUP","SUS","T6P","T6T","TAG","TCB","TDG","TGK","TGY","TH1","TIA","TM5","TM6","TM9","TMR","TMX","TOA","TOC","TRE","TYV","UCD","UDC","VG1","X0X","X1X","X2F","X4S","X5S","X6X","XBP","XDN","XDP","XIF","XIM","XLF","XLS","XMM","XUL","XXR","XYP","XYS","YO5","Z3Q","Z6J","Z9M","ZDC","ZDM"],ad=["CA","C","N","O","O1","O2","OC1","OC2","OX1","OXT","OT1","OT2","H","H1","H2","H3","HA","HN","BB"],od=["P","OP1","OP2","HOP2","HOP3","O2'","O3'","O4'","O5'","C1'","C2'","C3'","C4'","C5'","H1'","H2'","H2''","HO2'","H3'","H4'","H5'","H5''","HO3'","HO5'","O2*","O3*","O4*","O5*","C1*","C2*","C3*","C4*","C5*"],ld={1:{trace:"CA",direction1:"C",direction2:["O","OC1","O1","OX1","OXT","OT1","OT2"],backboneStart:"N",backboneEnd:"C"},2:{trace:["C4'","C4*"],direction1:["C1'","C1*"],direction2:["C3'","C3*"],backboneStart:"P",backboneEnd:["O3'","O3*"]},3:{trace:["C3'","C3*"],direction1:["C2'","C2*"],direction2:["O4'","O4*"],backboneStart:"P",backboneEnd:["O3'","O3*"]},4:{trace:["CA","BB"],backboneStart:["CA","BB"],backboneEnd:["CA","BB"]},5:{trace:["C4'","C4*","P"],backboneStart:["C4'","C4*","P"],backboneEnd:["C4'","C4*","P"]},6:{trace:["C3'","C3*","C2'","P"],backboneStart:["C3'","C3*","C2'","P"],backboneEnd:["C3'","C3*","C2'","P"]}};ld[Oh]={};const cd={HD:"H",HS:"H",A:"C",NA:"N",NS:"N",OA:"O",OS:"O",SA:"S",G0:"C",G1:"C",G2:"C",G3:"C",CG0:"C",CG1:"C",CG2:"C",CG3:"C",W:"O"};function ud(e){switch(e){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;default:return 8}}const hd=new Map([[2,Ro(180)],[3,Ro(120)],[4,Ro(109.4721)],[6,Ro(90)]]);function dd(e,t){let i=[];const n=new _t,r=new _t;return n.subVectors(t,e),e.eachBondedAtom((t=>{1!==t.number&&(r.subVectors(t,e),i.push(n.angleTo(r)))})),i}function fd(e,t){const i=e.clone(),n=new _t;n.subVectors(t,e);const r=[new _t,new _t];let s=0;if(e.eachBondedAtom((t=>{s>1||1!==t.number&&(i.index=t.index,r[s++].subVectors(t,e))})),1===s&&i.eachBondedAtom((t=>{s>1||1!==t.number&&t.index!==e.index&&r[s++].subVectors(t,e)})),2!==s)return;const a=r[0].cross(r[1]);return Math.abs(Math.PI/2-a.angleTo(n))}function md(e,t){const i=e.structure,n=i.atomCount,r=new Int8Array(n),s=new Int8Array(n),a=new Int8Array(n),o=new Int8Array(n);return i.eachAtom((e=>{const i=e.index,[n,l,c,u]=function(e,t){const i=e.bondToElementCount(1);let n=e.formalCharge||0;const r="always"===t.assignCharge||"auto"===t.assignCharge&&0===n,s="always"===t.assignH||"auto"===t.assignH&&0===i,a=e.bondCount,o=function(e){let t=0;return e.eachBond((e=>t+=e.bondOrder)),t}(e),l=function(e){const t=e.structure.getBondProxy(),i=e.number,n=8===i||7===i;if(n&&4===e.bondCount)return!1;let r=!1;return e.eachBond((i=>{if(i.bondOrder>1)r=!0;else if(n){const n=i.getOtherAtom(e);n.eachBond((e=>{if(e.bondOrder>1){const t=n.number;if((15===t||16===t)&&8===e.getOtherAtom(n).number)return;r=!0}}),t)}})),r}(e),c=o-a>0;let u=0,h=8;switch(e.number){case 1:r&&(0===a?(n=1,h=0):1===a&&(n=0,h=1));break;case 6:r&&(n=0),s&&(u=Math.max(0,4-o-Math.abs(n))),h=ud(a+u+Math.max(0,-n));break;case 7:if(r)if(s)if(l&&o<4)n=a-i==1&&o-i==2?1:0;else{let t=!1;e.eachBondedAtom((e=>{(16===e.number||e.isMetal())&&(t=!0)})),n=t?0:1}else n=o-3;s&&(u=Math.max(0,3-o+n)),h=ud(l&&!c?a+u-n:a+u+1-n);break;case 8:r&&(s||(n=o-2),1===o&&e.eachBondedAtom((t=>{t.eachBond((i=>{const r=i.getOtherAtom(t);r.index!==e.index&&8===r.number&&2===i.bondOrder&&(n=-1)}))}))),s&&(u=Math.max(0,2-o+n)),h=ud(l&&!c?a+u-n+1:a+u-n+2);break;case 16:r&&(s||(n=o<=3&&!e.bondToElementCount(8)?o-2:0)),s&&o<2&&(u=Math.max(0,2-o+n)),o<=3&&(h=ud(a+u-n+2));break;case 9:case 17:case 35:case 53:case 85:r&&(n=o-1);break;case 3:case 11:case 19:case 37:case 55:case 87:r&&(n=1-o);break;case 4:case 12:case 20:case 38:case 56:case 88:r&&(n=2-o);break;default:console.warn("Requested charge, protonation for an unhandled element",e.element)}return[n,u,u+i,h]}(e,t);r[i]=n,s[i]=l,a[i]=c,o[i]=u})),{charge:r,implicitH:s,totalH:a,idealGeometry:o}}function pd(e){if(e["@valenceModel"])return e["@valenceModel"];const t=md(e,{assignCharge:"auto",assignH:"auto"});return e["@valenceModel"]=t,t}function gd(e){return 15===e.number&&e.bondToElementCount(8)===e.bondCount}const _d=["ARG","HIS","LYS"],yd=["GLU","ASP"];function vd(e,t){return 2===e&&1===t||1===e&&2===t}function bd(e,t){return 3===e&&3===t}function xd(e,t){return 3===e&&1===t||1===e&&3===t}function wd(e){return"HIS"===e.resname&&7==e.number&&e.isRing()}function Sd(e,t){return 5===e&&4===t||4===e&&5===t}function Md(e,t){return 9===e&&5===t||5===e&&9===t}const Ad=[3,11,19,37,55,12,20,38,56,13,31,49,81,21,50,82,83,51,80];function Cd(e,t){return 12===e?11===t||12===t:13===e?10===t:void 0}const Td=[17,35,53,85];const Pd=[7,8,16],Ed=[6,7,15,16];const Id=Ro(180),Dd=Ro(120);function Rd(e,t,i){return!kd(e,t,i)&&(e.modelIndex!==t.modelIndex||e.altloc&&t.altloc&&e.altloc!==t.altloc)}const Ld={maxHydrophobicDist:4,maxHbondDist:3.5,maxHbondSulfurDist:4.1,maxHbondAccAngle:45,maxHbondDonAngle:45,maxHbondAccPlaneAngle:90,maxHbondDonPlaneAngle:30,maxPiStackingDist:5.5,maxPiStackingOffset:2,maxPiStackingAngle:30,maxCationPiDist:6,maxCationPiOffset:2,maxIonicDist:5,maxHalogenBondDist:4,maxHalogenBondAngle:30,maxMetalDist:3,refineSaltBridges:!0,masterModelIndex:-1,lineOfSightDistFactor:1};function kd(e,t,i){return e.modelIndex===i&&t.modelIndex!==i||t.modelIndex===i&&e.modelIndex!==i}function Od(e,t,i){return!kd(e,t,i)&&(e.modelIndex!==t.modelIndex||e.residueIndex===t.residueIndex||e.altloc&&t.altloc&&e.altloc!==t.altloc)}function Nd(t){const i={types:[],groups:[],centers:{x:[],y:[],z:[]},atomSets:[]};return e.Debug&&Fl.time("calculateFeatures"),function(e,t){const{charge:i}=pd(e.data),n={};e.eachResidue((e=>{if(_d.includes(e.resname)){const i=Rh(1);e.eachAtom((e=>{7===e.number&&e.isSidechain()&&Lh(i,e)})),kh(t,i)}else Qh.includes(e.resname)||e.isNucleic()||(e.eachAtom((e=>{let i=!1;const r=Rh(1);!function(e){let t=0;return 6===e.number&&3===e.bondCount&&3===e.bondToElementCount(7)&&e.eachBondedAtom((e=>{e.bondCount-e.bondToElementCount(1)==1&&++t})),2===t}(e)?function(e){let t=0;return 6===e.number&&3===e.bondCount&&2===e.bondToElementCount(7)&&1===e.bondToElementCount(6)&&e.eachBondedAtom((e=>{e.bondCount-e.bondToElementCount(1)==1&&++t})),2===t}(e)&&(r.group=9,i=!0):(r.group=8,i=!0),i&&(e.eachBondedAtom((e=>{7===e.number&&(n[e.index]=!0,Lh(r,e))})),kh(t,r))})),e.eachAtom((e=>{const r=Rh(1);i[e.index]>0&&(n[e.index]||(Lh(r,e),kh(t,r)))})))}))}(t,i),function(e,t){const{charge:i}=pd(e.data),n={};e.eachResidue((e=>{if(yd.includes(e.resname)){const i=Rh(2);e.eachAtom((e=>{8===e.number&&e.isSidechain()&&Lh(i,e)})),kh(t,i)}else if(id.includes(e.resname)){const i=Rh(2);e.eachAtom((e=>{gd(e)&&(i.group=6,e.eachBondedAtom((e=>{8===e.number&&Lh(i,e)})),kh(t,i))}))}else Qh.includes(e.resname)||id.includes(e.resname)||(e.eachAtom((e=>{let i=!1;const r=Rh(2);!function(e){return 16===e.number&&3===e.bondToElementCount(8)}(e)?gd(e)?(r.group=6,i=!0):function(e){return 16===e.number&&4===e.bondToElementCount(8)}(e)?(r.group=5,i=!0):function(e){let t=0;return 6===e.number&&2===e.bondToElementCount(8)&&1===e.bondToElementCount(6)&&e.eachBondedAtom((e=>{8===e.number&&e.bondCount-e.bondToElementCount(1)==1&&++t})),2===t}(e)&&(r.group=10,i=!0):(r.group=4,i=!0),i&&(e.eachBondedAtom((e=>{8===e.number&&(n[e.index]=!0,Lh(r,e))})),kh(t,r))})),e.eachAtom((e=>{const r=Rh(2);i[e.index]<0&&(n[e.index]||(Lh(r,e),kh(t,r)))})))}))}(t,i),function(e,t){const i=e.getAtomProxy();e.eachResidue((e=>{const n=e.getAromaticRings();if(n){const r=e.atomOffset;n.forEach((e=>{const n=Rh(3);e.forEach((e=>{i.index=e+r,Lh(n,i)})),kh(t,n)}))}}))}(t,i),function(e,t){const{charge:i,implicitH:n,idealGeometry:r}=pd(e.data);e.eachAtom((e=>{const s=Rh(5),a=e.number;if(8===a)Lh(s,e),kh(t,s);else if(7===a){if(wd(e))Lh(s,e),kh(t,s);else if(i[e.index]<1){const i=e.bondCount+n[e.index],a=r[e.index];(4===a&&i<4||3===a&&i<3||2===a&&i<2)&&(Lh(s,e),kh(t,s))}}else 16===a&&("CYS"!==e.resname&&"MET"!==e.resname&&-1!==e.formalCharge||(Lh(s,e),kh(t,s)))}))}(t,i),function(e,t){const{totalH:i}=pd(e.data);e.eachAtom((e=>{const n=Rh(4),r=e.number;(wd(e)||i[e.index]>0&&(7===r||8===r||16===r))&&(Lh(n,e),kh(t,n))}))}(t,i),function(e,t){const{totalH:i}=pd(e.data);e.eachAtom((e=>{if(6===e.number&&i[e.index]>0&&(e.bondToElementCount(7)>0||e.bondToElementCount(8)>0||function(e){if(!e.isAromatic())return!1;const t=e.residueType.getRings();if(!t)return!1;let i=!1;return t.rings.forEach((t=>{i||t.some((t=>e.index-e.residueAtomOffset===t))&&(i=t.some((t=>{const i=e.residueType.atomTypeIdList[t],n=e.atomMap.get(i).number;return 7===n||8===n})))})),i}(e))){const i=Rh(9);Lh(i,e),kh(t,i)}}))}(t,i),function(e,t){e.eachAtom((e=>{let i=!1,n=!1;const r=Qh.includes(e.resname),s=id.includes(e.resname);if(r||s?r?8===e.number?(["ASP","GLU","SER","THR","TYR","ASN","GLN"].includes(e.resname)&&e.isSidechain()||e.isBackbone())&&(i=!0,n=!0):16===e.number&&"CYS"===e.resname?(i=!0,n=!0):7===e.number&&"HIS"===e.resname&&e.isSidechain()&&(i=!0):s&&(8===e.number&&e.isBackbone()?(i=!0,n=!0):["N3","N4","N7"].includes(e.atomname)?i=!0:["O2","O4","O6"].includes(e.atomname)&&(i=!0,n=!0)):e.isHalogen()||8===e.number||16===e.number?(i=!0,n=!0):7===e.number&&(i=!0),i){const i=Rh(11);Lh(i,e),kh(t,i)}if(n){const i=Rh(10);Lh(i,e),kh(t,i)}}))}(t,i),function(e,t){e.eachAtom((e=>{if(e.isTransitionMetal()||30===e.number||48===e.number){const i=Rh(12);Lh(i,e),kh(t,i)}else if(Ad.includes(e.number)){const i=Rh(13);Lh(i,e),kh(t,i)}}))}(t,i),function(e,t){e.eachAtom((e=>{const i=Rh(8);let n=!1;6===e.number?(n=!0,e.eachBondedAtom((e=>{const t=e.number;6!==t&&1!==t&&(n=!1)}))):9===e.number&&(n=!0),n&&(Lh(i,e),kh(t,i))}))}(t,i),function(e,t){e.eachAtom((e=>{if(Pd.includes(e.number)){let i=!1;if(e.eachBondedAtom((e=>{Ed.includes(e.number)&&(i=!0)})),i){const i=Rh(7);Lh(i,e),kh(t,i)}}}))}(t,i),function(e,t){e.eachAtom((e=>{if(Td.includes(e.number)&&1===e.bondToElementCount(6)){const i=Rh(6);Lh(i,e),kh(t,i)}}))}(t,i),e.Debug&&Fl.timeEnd("calculateFeatures"),i}function Fd(t,i=Ld){const n=function(e){const{types:t,centers:i}=e;return{features:e,spatialHash:new Ch(i),contactStore:new Ph,featureSet:new Ih(t.length,!1)}}(Nd(t));e.Debug&&Fl.time("calculateContacts"),function(e,t,i={}){const n=uo(i.maxIonicDist,Ld.maxIonicDist),r=uo(i.maxPiStackingDist,Ld.maxPiStackingDist),s=uo(i.maxPiStackingOffset,Ld.maxPiStackingOffset),a=uo(i.maxPiStackingAngle,Ld.maxPiStackingAngle),o=uo(i.maxCationPiDist,Ld.maxCationPiDist),l=uo(i.maxCationPiOffset,Ld.maxCationPiOffset),c=uo(i.masterModelIndex,Ld.masterModelIndex),u=Math.max(n+2,r,o),h=r*r,d=o*o,{features:f,spatialHash:m,contactStore:p,featureSet:g}=t,{types:_,centers:y,atomSets:v}=f,{x:b,y:x,z:w}=y,S=_.length,M=e.atomStore.x,A=e.atomStore.y,C=e.atomStore.z,T=e.getAtomProxy(),P=e.getAtomProxy(),E=function(e,t,i){const n=e.length,r=t.length;for(let s=0;s{if(t<=e)return;if(T.index=v[e][0],P.index=v[t][0],Od(T,P,c))return;const r=_[e],o=_[t];if(vd(r,o))E(v[e],v[t],n)&&z(e,t,1);else if(bd(r,o)){if(i<=h){F(v[e],O),F(v[t],N);const i=57.29578*O.angleTo(N);Math.min(B(e,t,N),B(t,e,O))<=s&&(i<=a||i>=180-a||i<=a+90&&i>=90-a)&&z(e,t,3)}}else if(xd(r,o)&&i<=d){const[i,n]=3===r?[e,t]:[t,e];F(v[i],O),B(n,i,O)<=l&&z(i,n,2)}}))}(t,n,i),function(e,t,i={}){const n=uo(i.maxHbondDist,Ld.maxHbondDist),r=uo(i.maxHbondSulfurDist,Ld.maxHbondSulfurDist),s=Ro(uo(i.maxHbondAccAngle,Ld.maxHbondAccAngle)),a=Ro(uo(i.maxHbondDonAngle,Ld.maxHbondDonAngle)),o=Ro(uo(i.maxHbondAccPlaneAngle,Ld.maxHbondAccPlaneAngle)),l=Ro(uo(i.maxHbondDonPlaneAngle,Ld.maxHbondDonPlaneAngle)),c=uo(i.masterModelIndex,Ld.masterModelIndex),u=Math.max(n,r),h=n*n,{features:d,spatialHash:f,contactStore:m,featureSet:p}=t,{types:g,centers:_,atomSets:y}=d,{x:v,y:b,z:x}=_,w=g.length,{idealGeometry:S}=pd(e.data),M=e.getAtomProxy(),A=e.getAtomProxy();for(let e=0;e{if(t<=e)return;const n=g[e],r=g[t],u=Md(n,r);if(!u&&!Sd(n,r))return;const[d,f]=5===r?[e,t]:[t,e];if(M.index=y[d][0],A.index=y[f][0],A.index===M.index)return;if(Od(M,A,c))return;if(16!==M.number&&16!==A.number&&i>h)return;if(M.connectedTo(A))return;const _=dd(M,A),v=hd.get(S[M.index])||Ro(120);if(_.some((e=>Math.abs(v-e)>a)))return;if(3===S[M.index]){const e=fd(M,A);if(void 0!==e&&e>l)return}const b=dd(A,M),x=hd.get(S[A.index])||Ro(120);if(b.some((e=>x-e>s)))return;if(3===S[A.index]){const e=fd(A,M);if(void 0!==e&&e>o)return}p.setBits(d,f);const w=u?8:function(e,t){return e.isWater()&&t.isWater()}(C=M,T=A)?9:function(e,t){return e.isBackbone()&&t.isBackbone()}(C,T)?10:4;var C,T;m.addContact(d,f,w)}))}(t,n,i),function(e,t,i={}){const n=uo(i.maxMetalDist,Ld.maxMetalDist),r=uo(i.masterModelIndex,Ld.masterModelIndex),{features:s,spatialHash:a,contactStore:o,featureSet:l}=t,{types:c,centers:u,atomSets:h}=s,{x:d,y:f,z:m}=u,p=c.length,g=e.getAtomProxy(),_=e.getAtomProxy();for(let e=0;e{if(t<=e)return;if(g.index=h[e][0],_.index=h[t][0],Od(g,_,r))return;const n=g.isMetal(),s=_.isMetal();if(!n&&!s)return;const[a,u]=n?[c[e],c[t]]:[c[t],c[e]];Cd(a,u)&&(l.setBits(e,t),o.addContact(e,t,7))}))}(t,n,i),function(e,t,i={}){const n=uo(i.maxHydrophobicDist,Ld.maxHydrophobicDist),r=uo(i.masterModelIndex,Ld.masterModelIndex),{features:s,spatialHash:a,contactStore:o,featureSet:l}=t,{types:c,centers:u,atomSets:h}=s,{x:d,y:f,z:m}=u,p=c.length,g=e.getAtomProxy(),_=e.getAtomProxy();for(let e=0;e{var n,s;t<=e||(g.index=h[e][0],_.index=h[t][0],Od(g,_,r)||9===g.number&&9===_.number||g.connectedTo(_)||(n=c[e],s=c[t],8===n&&8===s&&(l.setBits(e,t),o.addContact(e,t,6))))}))}(t,n,i),function(e,t,i={}){const n=uo(i.maxHalogenBondDist,Ld.maxHalogenBondDist),r=Ro(uo(i.maxHalogenBondAngle,Ld.maxHalogenBondAngle)),s=uo(i.masterModelIndex,Ld.masterModelIndex),{features:a,spatialHash:o,contactStore:l,featureSet:c}=t,{types:u,centers:h,atomSets:d}=a,{x:f,y:m,z:p}=h,g=u.length,_=e.getAtomProxy(),y=e.getAtomProxy();for(let e=0;e{if(t<=e)return;if(_.index=d[e][0],y.index=d[t][0],Od(_,y,s))return;if(n=u[e],a=u[t],!(7===n&&6===a||6===n&&7===a))return;var n,a;const[o,h]=6===u[e]?[_,y]:[y,_],f=dd(o,h);if(1!==f.length)return;if(Id-f[0]>r)return;const m=dd(h,o);0!==m.length&&(m.some((e=>Dd-e>r))||(c.setBits(e,t),l.addContact(e,t,5)))}))}(t,n,i);const r=function(e){const{index1:t,index2:i,count:n}=e.contactStore,r=Dh({nodeArray1:t,nodeArray2:i,edgeCount:n,nodeCount:e.featureSet.length}),s=new Ih(e.contactStore.count,!0);return Object.assign({adjacencyList:r,contactSet:s},e)}(n);return function(t,i,n={}){e.Debug&&Fl.time("refineLineOfSight");const r=uo(n.lineOfSightDistFactor,Ld.lineOfSightDistFactor),s=uo(n.masterModelIndex,Ld.masterModelIndex),a=t.spatialHash,{contactSet:o,contactStore:l,features:c}=i,{index1:u,index2:h}=l,{centers:d,atomSets:f}=c,{x:m,y:p,z:g}=d,_=t.getAtomProxy(),y=t.getAtomProxy(),v=t.getAtomProxy(),b=new _t,x=new _t,w=3*r,S=r*r;o.forEach((t=>{b.set(m[u[t]],p[u[t]],g[u[t]]),x.set(m[h[t]],p[h[t]],g[h[t]]);const i=(b.x+x.x)/2,n=(b.y+x.y)/2,r=(b.z+x.z)/2,l=f[u[t]],c=f[h[t]];_.index=l[0],y.index=c[0],a.eachWithin(i,n,r,w,((i,n)=>{v.index=i,1!==v.number&&v.vdw*v.vdw*S>n&&!Rd(_,v,s)&&!Rd(y,v,s)&&!l.includes(i)&&!c.includes(i)&&b.distanceToSquared(v)>1&&x.distanceToSquared(v)>1&&(o.clear(t),e.Debug&&Fl.log("removing",_.qualifiedName(),y.qualifiedName(),"because",v.qualifiedName()))}))})),e.Debug&&Fl.timeEnd("refineLineOfSight")}(t,r,i),function(e,t){const{contactSet:i,contactStore:n,features:r}=t,{type:s,index1:a,index2:o}=n,{atomSets:l}=r,c=e.getAtomProxy(),u=e.getAtomProxy(),h={},d=function(e,t,n){const[r,s]=h[n]||[1/0,-1];e{if(6!==s[e])return;c.index=l[a[e]][0],u.index=l[o[e]][0];const t=c.distanceTo(u);d(t,e,`${c.index}|${u.residueIndex}`),d(t,e,`${u.index}|${c.residueIndex}`)}))}(t,r),i.refineSaltBridges&&function(e,t){const{contactSet:i,contactStore:n,features:r}=t,{type:s,index1:a,index2:o}=n,{atomSets:l}=r,c={},u=function(e,t){c[e]||(c[e]=[]),c[e].push(t)};i.forEach((e=>{1===s[e]&&(l[a[e]].forEach((t=>u(t,e))),l[o[e]].forEach((t=>u(t,e))))})),i.forEach((e=>{if(!function(e){return 4===e||9===e||10===e}(s[e]))return;const t=c[l[a[e]][0]],n=c[l[o[e]][0]];if(!t||!n)return;const r=t.length;for(let s=0;s{3===s[e]&&(l[a[e]].forEach((t=>u(t,e))),l[o[e]].forEach((t=>u(t,e))))})),i.forEach((e=>{if(6!==s[e]&&2!==s[e])return;const t=c[l[a[e]][0]],n=c[l[o[e]][0]];if(!t||!n)return;const r=t.length;for(let s=0;s{1===s[e]&&(l[a[e]].forEach((t=>u(t,e))),l[o[e]].forEach((t=>u(t,e))))})),i.forEach((e=>{if(7!==s[e])return;const t=c[l[a[e]][0]],n=c[l[o[e]][0]];if(!t||!n)return;const r=t.length;for(let e=0;et.getAtomSet(new wl(e)))):t.getAtomSet(new wl(n.filterSele))),a.forEach((e=>{const t=p[e];if(!r.includes(t))return;if(x){const t=c[f[e]][0],i=c[m[e]][0];if(Array.isArray(x)){if(!(x[0].isSet(t)&&x[1].isSet(i)||x[1].isSet(t)&&x[0].isSet(i)))return}else if(!x.isSet(t)&&!x.isSet(i))return}const i=f[e],s=m[e];g.push(u[i],h[i],d[i]),_.push(u[s],h[s],d[s]),y.push(...function(e){switch(e){case 4:case 9:case 10:return Ud.setHex(2851770).toArray();case 6:return Ud.setHex(8421504).toArray();case 5:return Ud.setHex(4259775).toArray();case 1:return Ud.setHex(15779860).toArray();case 7:return Ud.setHex(9191577).toArray();case 2:return Ud.setHex(16744448).toArray();case 3:return Ud.setHex(9220966).toArray();case 8:return Ud.setHex(12967404).toArray();default:return Ud.setHex(13421772).toArray()}}(t)),v.push(n.radius),b.push(e)})),{position1:new Float32Array(g),position2:new Float32Array(_),color:new Float32Array(y),color2:new Float32Array(y),radius:new Float32Array(v),picking:new qd(b,e,t)}}class $d{constructor(e){this.array=e}get type(){return""}get data(){return{}}getIndex(e){return this.array?this.array[e]:e}getObject(e){return{}}_applyTransformations(e,t,i){return t&&e.applyMatrix4(t.matrix),i&&e.applyMatrix4(i.matrix),e}_getPosition(e){return new _t}getPosition(e,t,i){return this._applyTransformations(this._getPosition(e),t,i)}}class Gd extends $d{constructor(e){super(),this.shape=e}get primitive(){}get data(){return this.shape}get type(){return this.primitive.type}getObject(e){return this.primitive.objectFromShape(this.shape,this.getIndex(e))}_getPosition(e){return this.primitive.positionFromShape(this.shape,this.getIndex(e))}}class Hd extends $d{constructor(e,t){super(e),this.structure=t}get type(){return"atom"}get data(){return this.structure}getObject(e){return this.structure.getAtomProxy(this.getIndex(e))}_getPosition(e){return(new _t).copy(this.getObject(e))}}class jd extends $d{constructor(e){super(),this.axes=e}get type(){return"axes"}get data(){return this.axes}getObject(){return{axes:this.axes}}_getPosition(){return this.axes.center.clone()}}class Wd extends $d{constructor(e,t,i){super(e),this.structure=t,this.bondStore=i||t.bondStore}get type(){return"bond"}get data(){return this.structure}getObject(e){const t=this.structure.getBondProxy(this.getIndex(e));return t.bondStore=this.bondStore,t}_getPosition(e){const t=this.getObject(e);return(new _t).copy(t.atom1).add(t.atom2).multiplyScalar(.5)}}class qd extends $d{constructor(e,t,i){super(e),this.contacts=t,this.structure=i}get type(){return"contact"}get data(){return this.contacts}getObject(e){const t=this.getIndex(e),{features:i,contactStore:n}=this.contacts,{centers:r,atomSets:s}=i,{x:a,y:o,z:l}=r,{index1:c,index2:u,type:h}=n,d=c[t],f=u[t];return{center1:new _t(a[d],o[d],l[d]),center2:new _t(a[f],o[f],l[f]),atom1:this.structure.getAtomProxy(s[d][0]),atom2:this.structure.getAtomProxy(s[f][0]),type:Bd(h[t])}}_getPosition(e){const{center1:t,center2:i}=this.getObject(e);return(new _t).addVectors(t,i).multiplyScalar(.5)}}class Xd extends $d{constructor(e,t,i){super(e),this.validation=t,this.structure=i}get type(){return"clash"}get data(){return this.validation}getObject(e){const t=this.validation,i=this.getIndex(e);return{validation:t,index:i,clash:t.clashArray[i]}}_getAtomProxyFromSele(e){const t=new wl(e),i=this.structure.getAtomIndices(t)[0];return this.structure.getAtomProxy(i)}_getPosition(e){const t=this.getObject(e).clash,i=this._getAtomProxyFromSele(t.sele1),n=this._getAtomProxyFromSele(t.sele2);return(new _t).copy(i).add(n).multiplyScalar(.5)}}class Yd extends Wd{get type(){return"distance"}}class Kd extends $d{get type(){return"ignore"}}class Zd extends Gd{constructor(e,t){super(e),this.mesh=t}get type(){return"mesh"}getObject(){const e=this.mesh;return{shape:this.shape,name:e.name,serial:e.serial}}_getPosition(){return this.__position||(this.__position=zu(this.mesh.position)),this.__position}}class Qd extends $d{constructor(e,t){super(e),this.surface=t}get type(){return"surface"}get data(){return this.surface}getObject(e){return{surface:this.surface,index:this.getIndex(e)}}_getPosition(){return this.surface.center.clone()}}class Jd extends $d{constructor(e,t){super(),this.unitcell=e,this.structure=t}get type(){return"unitcell"}get data(){return this.unitcell}getObject(){return{unitcell:this.unitcell,structure:this.structure}}_getPosition(){return this.unitcell.getCenter(this.structure)}}class ef extends $d{constructor(e,t){super(e),this.volume=t}get type(){return"volume"}get data(){return this.volume}getObject(e){const t=this.volume,i=this.getIndex(e);return{volume:t,index:i,value:t.data[i]}}_getPosition(e){const t=this.volume.position,i=this.getIndex(e);return new _t(t[3*i],t[3*i+1],t[3*i+2])}}class tf extends ef{get type(){return"slice"}}function nf(){return new Uint32Array([0,265,515,778,1030,1295,1541,1804,2060,2309,2575,2822,3082,3331,3593,3840,400,153,915,666,1430,1183,1941,1692,2460,2197,2975,2710,3482,3219,3993,3728,560,825,51,314,1590,1855,1077,1340,2620,2869,2111,2358,3642,3891,3129,3376,928,681,419,170,1958,1711,1445,1196,2988,2725,2479,2214,4010,3747,3497,3232,1120,1385,1635,1898,102,367,613,876,3180,3429,3695,3942,2154,2403,2665,2912,1520,1273,2035,1786,502,255,1013,764,3580,3317,4095,3830,2554,2291,3065,2800,1616,1881,1107,1370,598,863,85,348,3676,3925,3167,3414,2650,2899,2137,2384,1984,1737,1475,1226,966,719,453,204,4044,3781,3535,3270,3018,2755,2505,2240,2240,2505,2755,3018,3270,3535,3781,4044,204,453,719,966,1226,1475,1737,1984,2384,2137,2899,2650,3414,3167,3925,3676,348,85,863,598,1370,1107,1881,1616,2800,3065,2291,2554,3830,4095,3317,3580,764,1013,255,502,1786,2035,1273,1520,2912,2665,2403,2154,3942,3695,3429,3180,876,613,367,102,1898,1635,1385,1120,3232,3497,3747,4010,2214,2479,2725,2988,1196,1445,1711,1958,170,419,681,928,3376,3129,3891,3642,2358,2111,2869,2620,1340,1077,1855,1590,314,51,825,560,3728,3993,3219,3482,2710,2975,2197,2460,1692,1941,1183,1430,666,915,153,400,3840,3593,3331,3082,2822,2575,2309,2060,1804,1541,1295,1030,778,515,265,0])}function rf(){return new Int32Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,9,8,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,2,10,0,2,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,8,3,2,10,8,10,9,8,-1,-1,-1,-1,-1,-1,-1,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,8,11,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,11,2,1,9,11,9,8,11,-1,-1,-1,-1,-1,-1,-1,3,10,1,11,10,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,10,1,0,8,10,8,11,10,-1,-1,-1,-1,-1,-1,-1,3,9,0,3,11,9,11,10,9,-1,-1,-1,-1,-1,-1,-1,9,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,7,3,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,1,9,4,7,1,7,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,8,4,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,4,7,3,0,4,1,2,10,-1,-1,-1,-1,-1,-1,-1,9,2,10,9,0,2,8,4,7,-1,-1,-1,-1,-1,-1,-1,2,10,9,2,9,7,2,7,3,7,9,4,-1,-1,-1,-1,8,4,7,3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,4,7,11,2,4,2,0,4,-1,-1,-1,-1,-1,-1,-1,9,0,1,8,4,7,2,3,11,-1,-1,-1,-1,-1,-1,-1,4,7,11,9,4,11,9,11,2,9,2,1,-1,-1,-1,-1,3,10,1,3,11,10,7,8,4,-1,-1,-1,-1,-1,-1,-1,1,11,10,1,4,11,1,0,4,7,11,4,-1,-1,-1,-1,4,7,8,9,0,11,9,11,10,11,0,3,-1,-1,-1,-1,4,7,11,4,11,9,9,11,10,-1,-1,-1,-1,-1,-1,-1,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,5,4,1,5,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,5,4,8,3,5,3,1,5,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,10,4,9,5,-1,-1,-1,-1,-1,-1,-1,5,2,10,5,4,2,4,0,2,-1,-1,-1,-1,-1,-1,-1,2,10,5,3,2,5,3,5,4,3,4,8,-1,-1,-1,-1,9,5,4,2,3,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,11,2,0,8,11,4,9,5,-1,-1,-1,-1,-1,-1,-1,0,5,4,0,1,5,2,3,11,-1,-1,-1,-1,-1,-1,-1,2,1,5,2,5,8,2,8,11,4,8,5,-1,-1,-1,-1,10,3,11,10,1,3,9,5,4,-1,-1,-1,-1,-1,-1,-1,4,9,5,0,8,1,8,10,1,8,11,10,-1,-1,-1,-1,5,4,0,5,0,11,5,11,10,11,0,3,-1,-1,-1,-1,5,4,8,5,8,10,10,8,11,-1,-1,-1,-1,-1,-1,-1,9,7,8,5,7,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,3,0,9,5,3,5,7,3,-1,-1,-1,-1,-1,-1,-1,0,7,8,0,1,7,1,5,7,-1,-1,-1,-1,-1,-1,-1,1,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,7,8,9,5,7,10,1,2,-1,-1,-1,-1,-1,-1,-1,10,1,2,9,5,0,5,3,0,5,7,3,-1,-1,-1,-1,8,0,2,8,2,5,8,5,7,10,5,2,-1,-1,-1,-1,2,10,5,2,5,3,3,5,7,-1,-1,-1,-1,-1,-1,-1,7,9,5,7,8,9,3,11,2,-1,-1,-1,-1,-1,-1,-1,9,5,7,9,7,2,9,2,0,2,7,11,-1,-1,-1,-1,2,3,11,0,1,8,1,7,8,1,5,7,-1,-1,-1,-1,11,2,1,11,1,7,7,1,5,-1,-1,-1,-1,-1,-1,-1,9,5,8,8,5,7,10,1,3,10,3,11,-1,-1,-1,-1,5,7,0,5,0,9,7,11,0,1,0,10,11,10,0,-1,11,10,0,11,0,3,10,5,0,8,0,7,5,7,0,-1,11,10,5,7,11,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,0,1,5,10,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,8,3,1,9,8,5,10,6,-1,-1,-1,-1,-1,-1,-1,1,6,5,2,6,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,6,5,1,2,6,3,0,8,-1,-1,-1,-1,-1,-1,-1,9,6,5,9,0,6,0,2,6,-1,-1,-1,-1,-1,-1,-1,5,9,8,5,8,2,5,2,6,3,2,8,-1,-1,-1,-1,2,3,11,10,6,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,0,8,11,2,0,10,6,5,-1,-1,-1,-1,-1,-1,-1,0,1,9,2,3,11,5,10,6,-1,-1,-1,-1,-1,-1,-1,5,10,6,1,9,2,9,11,2,9,8,11,-1,-1,-1,-1,6,3,11,6,5,3,5,1,3,-1,-1,-1,-1,-1,-1,-1,0,8,11,0,11,5,0,5,1,5,11,6,-1,-1,-1,-1,3,11,6,0,3,6,0,6,5,0,5,9,-1,-1,-1,-1,6,5,9,6,9,11,11,9,8,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,3,0,4,7,3,6,5,10,-1,-1,-1,-1,-1,-1,-1,1,9,0,5,10,6,8,4,7,-1,-1,-1,-1,-1,-1,-1,10,6,5,1,9,7,1,7,3,7,9,4,-1,-1,-1,-1,6,1,2,6,5,1,4,7,8,-1,-1,-1,-1,-1,-1,-1,1,2,5,5,2,6,3,0,4,3,4,7,-1,-1,-1,-1,8,4,7,9,0,5,0,6,5,0,2,6,-1,-1,-1,-1,7,3,9,7,9,4,3,2,9,5,9,6,2,6,9,-1,3,11,2,7,8,4,10,6,5,-1,-1,-1,-1,-1,-1,-1,5,10,6,4,7,2,4,2,0,2,7,11,-1,-1,-1,-1,0,1,9,4,7,8,2,3,11,5,10,6,-1,-1,-1,-1,9,2,1,9,11,2,9,4,11,7,11,4,5,10,6,-1,8,4,7,3,11,5,3,5,1,5,11,6,-1,-1,-1,-1,5,1,11,5,11,6,1,0,11,7,11,4,0,4,11,-1,0,5,9,0,6,5,0,3,6,11,6,3,8,4,7,-1,6,5,9,6,9,11,4,7,9,7,11,9,-1,-1,-1,-1,10,4,9,6,4,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,10,6,4,9,10,0,8,3,-1,-1,-1,-1,-1,-1,-1,10,0,1,10,6,0,6,4,0,-1,-1,-1,-1,-1,-1,-1,8,3,1,8,1,6,8,6,4,6,1,10,-1,-1,-1,-1,1,4,9,1,2,4,2,6,4,-1,-1,-1,-1,-1,-1,-1,3,0,8,1,2,9,2,4,9,2,6,4,-1,-1,-1,-1,0,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,3,2,8,2,4,4,2,6,-1,-1,-1,-1,-1,-1,-1,10,4,9,10,6,4,11,2,3,-1,-1,-1,-1,-1,-1,-1,0,8,2,2,8,11,4,9,10,4,10,6,-1,-1,-1,-1,3,11,2,0,1,6,0,6,4,6,1,10,-1,-1,-1,-1,6,4,1,6,1,10,4,8,1,2,1,11,8,11,1,-1,9,6,4,9,3,6,9,1,3,11,6,3,-1,-1,-1,-1,8,11,1,8,1,0,11,6,1,9,1,4,6,4,1,-1,3,11,6,3,6,0,0,6,4,-1,-1,-1,-1,-1,-1,-1,6,4,8,11,6,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,10,6,7,8,10,8,9,10,-1,-1,-1,-1,-1,-1,-1,0,7,3,0,10,7,0,9,10,6,7,10,-1,-1,-1,-1,10,6,7,1,10,7,1,7,8,1,8,0,-1,-1,-1,-1,10,6,7,10,7,1,1,7,3,-1,-1,-1,-1,-1,-1,-1,1,2,6,1,6,8,1,8,9,8,6,7,-1,-1,-1,-1,2,6,9,2,9,1,6,7,9,0,9,3,7,3,9,-1,7,8,0,7,0,6,6,0,2,-1,-1,-1,-1,-1,-1,-1,7,3,2,6,7,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,11,10,6,8,10,8,9,8,6,7,-1,-1,-1,-1,2,0,7,2,7,11,0,9,7,6,7,10,9,10,7,-1,1,8,0,1,7,8,1,10,7,6,7,10,2,3,11,-1,11,2,1,11,1,7,10,6,1,6,7,1,-1,-1,-1,-1,8,9,6,8,6,7,9,1,6,11,6,3,1,3,6,-1,0,9,1,11,6,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,8,0,7,0,6,3,11,0,11,6,0,-1,-1,-1,-1,7,11,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,8,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,9,11,7,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,1,9,8,3,1,11,7,6,-1,-1,-1,-1,-1,-1,-1,10,1,2,6,11,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,8,6,11,7,-1,-1,-1,-1,-1,-1,-1,2,9,0,2,10,9,6,11,7,-1,-1,-1,-1,-1,-1,-1,6,11,7,2,10,3,10,8,3,10,9,8,-1,-1,-1,-1,7,2,3,6,2,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,7,0,8,7,6,0,6,2,0,-1,-1,-1,-1,-1,-1,-1,2,7,6,2,3,7,0,1,9,-1,-1,-1,-1,-1,-1,-1,1,6,2,1,8,6,1,9,8,8,7,6,-1,-1,-1,-1,10,7,6,10,1,7,1,3,7,-1,-1,-1,-1,-1,-1,-1,10,7,6,1,7,10,1,8,7,1,0,8,-1,-1,-1,-1,0,3,7,0,7,10,0,10,9,6,10,7,-1,-1,-1,-1,7,6,10,7,10,8,8,10,9,-1,-1,-1,-1,-1,-1,-1,6,8,4,11,8,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,6,11,3,0,6,0,4,6,-1,-1,-1,-1,-1,-1,-1,8,6,11,8,4,6,9,0,1,-1,-1,-1,-1,-1,-1,-1,9,4,6,9,6,3,9,3,1,11,3,6,-1,-1,-1,-1,6,8,4,6,11,8,2,10,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,3,0,11,0,6,11,0,4,6,-1,-1,-1,-1,4,11,8,4,6,11,0,2,9,2,10,9,-1,-1,-1,-1,10,9,3,10,3,2,9,4,3,11,3,6,4,6,3,-1,8,2,3,8,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,0,4,2,4,6,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,9,0,2,3,4,2,4,6,4,3,8,-1,-1,-1,-1,1,9,4,1,4,2,2,4,6,-1,-1,-1,-1,-1,-1,-1,8,1,3,8,6,1,8,4,6,6,10,1,-1,-1,-1,-1,10,1,0,10,0,6,6,0,4,-1,-1,-1,-1,-1,-1,-1,4,6,3,4,3,8,6,10,3,0,3,9,10,9,3,-1,10,9,4,6,10,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,5,7,6,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,5,11,7,6,-1,-1,-1,-1,-1,-1,-1,5,0,1,5,4,0,7,6,11,-1,-1,-1,-1,-1,-1,-1,11,7,6,8,3,4,3,5,4,3,1,5,-1,-1,-1,-1,9,5,4,10,1,2,7,6,11,-1,-1,-1,-1,-1,-1,-1,6,11,7,1,2,10,0,8,3,4,9,5,-1,-1,-1,-1,7,6,11,5,4,10,4,2,10,4,0,2,-1,-1,-1,-1,3,4,8,3,5,4,3,2,5,10,5,2,11,7,6,-1,7,2,3,7,6,2,5,4,9,-1,-1,-1,-1,-1,-1,-1,9,5,4,0,8,6,0,6,2,6,8,7,-1,-1,-1,-1,3,6,2,3,7,6,1,5,0,5,4,0,-1,-1,-1,-1,6,2,8,6,8,7,2,1,8,4,8,5,1,5,8,-1,9,5,4,10,1,6,1,7,6,1,3,7,-1,-1,-1,-1,1,6,10,1,7,6,1,0,7,8,7,0,9,5,4,-1,4,0,10,4,10,5,0,3,10,6,10,7,3,7,10,-1,7,6,10,7,10,8,5,4,10,4,8,10,-1,-1,-1,-1,6,9,5,6,11,9,11,8,9,-1,-1,-1,-1,-1,-1,-1,3,6,11,0,6,3,0,5,6,0,9,5,-1,-1,-1,-1,0,11,8,0,5,11,0,1,5,5,6,11,-1,-1,-1,-1,6,11,3,6,3,5,5,3,1,-1,-1,-1,-1,-1,-1,-1,1,2,10,9,5,11,9,11,8,11,5,6,-1,-1,-1,-1,0,11,3,0,6,11,0,9,6,5,6,9,1,2,10,-1,11,8,5,11,5,6,8,0,5,10,5,2,0,2,5,-1,6,11,3,6,3,5,2,10,3,10,5,3,-1,-1,-1,-1,5,8,9,5,2,8,5,6,2,3,8,2,-1,-1,-1,-1,9,5,6,9,6,0,0,6,2,-1,-1,-1,-1,-1,-1,-1,1,5,8,1,8,0,5,6,8,3,8,2,6,2,8,-1,1,5,6,2,1,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,6,1,6,10,3,8,6,5,6,9,8,9,6,-1,10,1,0,10,0,6,9,5,0,5,6,0,-1,-1,-1,-1,0,3,8,5,6,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,5,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,7,5,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,11,5,10,11,7,5,8,3,0,-1,-1,-1,-1,-1,-1,-1,5,11,7,5,10,11,1,9,0,-1,-1,-1,-1,-1,-1,-1,10,7,5,10,11,7,9,8,1,8,3,1,-1,-1,-1,-1,11,1,2,11,7,1,7,5,1,-1,-1,-1,-1,-1,-1,-1,0,8,3,1,2,7,1,7,5,7,2,11,-1,-1,-1,-1,9,7,5,9,2,7,9,0,2,2,11,7,-1,-1,-1,-1,7,5,2,7,2,11,5,9,2,3,2,8,9,8,2,-1,2,5,10,2,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,8,2,0,8,5,2,8,7,5,10,2,5,-1,-1,-1,-1,9,0,1,5,10,3,5,3,7,3,10,2,-1,-1,-1,-1,9,8,2,9,2,1,8,7,2,10,2,5,7,5,2,-1,1,3,5,3,7,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,8,7,0,7,1,1,7,5,-1,-1,-1,-1,-1,-1,-1,9,0,3,9,3,5,5,3,7,-1,-1,-1,-1,-1,-1,-1,9,8,7,5,9,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,5,8,4,5,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,5,0,4,5,11,0,5,10,11,11,3,0,-1,-1,-1,-1,0,1,9,8,4,10,8,10,11,10,4,5,-1,-1,-1,-1,10,11,4,10,4,5,11,3,4,9,4,1,3,1,4,-1,2,5,1,2,8,5,2,11,8,4,5,8,-1,-1,-1,-1,0,4,11,0,11,3,4,5,11,2,11,1,5,1,11,-1,0,2,5,0,5,9,2,11,5,4,5,8,11,8,5,-1,9,4,5,2,11,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,5,10,3,5,2,3,4,5,3,8,4,-1,-1,-1,-1,5,10,2,5,2,4,4,2,0,-1,-1,-1,-1,-1,-1,-1,3,10,2,3,5,10,3,8,5,4,5,8,0,1,9,-1,5,10,2,5,2,4,1,9,2,9,4,2,-1,-1,-1,-1,8,4,5,8,5,3,3,5,1,-1,-1,-1,-1,-1,-1,-1,0,4,5,1,0,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,4,5,8,5,3,9,0,5,0,3,5,-1,-1,-1,-1,9,4,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,11,7,4,9,11,9,10,11,-1,-1,-1,-1,-1,-1,-1,0,8,3,4,9,7,9,11,7,9,10,11,-1,-1,-1,-1,1,10,11,1,11,4,1,4,0,7,4,11,-1,-1,-1,-1,3,1,4,3,4,8,1,10,4,7,4,11,10,11,4,-1,4,11,7,9,11,4,9,2,11,9,1,2,-1,-1,-1,-1,9,7,4,9,11,7,9,1,11,2,11,1,0,8,3,-1,11,7,4,11,4,2,2,4,0,-1,-1,-1,-1,-1,-1,-1,11,7,4,11,4,2,8,3,4,3,2,4,-1,-1,-1,-1,2,9,10,2,7,9,2,3,7,7,4,9,-1,-1,-1,-1,9,10,7,9,7,4,10,2,7,8,7,0,2,0,7,-1,3,7,10,3,10,2,7,4,10,1,10,0,4,0,10,-1,1,10,2,8,7,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,7,1,3,-1,-1,-1,-1,-1,-1,-1,4,9,1,4,1,7,0,8,1,8,7,1,-1,-1,-1,-1,4,0,3,7,4,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,4,8,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,9,10,8,10,11,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,11,9,10,-1,-1,-1,-1,-1,-1,-1,0,1,10,0,10,8,8,10,11,-1,-1,-1,-1,-1,-1,-1,3,1,10,11,3,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,2,11,1,11,9,9,11,8,-1,-1,-1,-1,-1,-1,-1,3,0,9,3,9,11,1,2,9,2,11,9,-1,-1,-1,-1,0,2,11,8,0,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,2,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,10,8,9,-1,-1,-1,-1,-1,-1,-1,9,10,2,0,9,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,3,8,2,8,10,0,1,8,1,10,8,-1,-1,-1,-1,1,10,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,3,8,9,1,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,9,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,3,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1])}function sf(e,t,i,n,r){var s,a,o,l,c,u,h,d=[[0,4,4,4,2,0,0,0,2,2,0,0],[4,0,4,4,0,8,0,0,0,8,8,0],[4,4,0,4,0,0,8,0,0,0,8,8],[4,4,4,0,0,0,0,1,1,0,0,1],[2,0,0,0,0,8,8,8,2,2,0,0],[0,8,0,0,8,0,8,8,0,8,8,0],[0,0,8,0,8,8,0,8,0,0,8,8],[0,0,0,1,8,8,8,0,1,0,0,1],[2,0,0,1,2,0,0,1,0,2,0,1],[2,8,0,0,2,8,0,0,2,0,8,0],[0,8,8,0,0,8,8,0,0,8,0,8],[0,0,8,1,0,0,8,1,1,0,8,0]],f=0,m=!1,p=!1,g=!1,_=!1,y=-1,v=t*i*n,b=t,x=t*i,w=new Int32Array(12),S=[],M=[],A=[],C=[],T=nf(),P=rf();function E(e,t,i){return e+(t-e)*i}function I(e,r,s){return x*(s=(s+h)%n)+b*(r=(r+u)%i)+(e=(e+c)%t)}function D(e,t,i,n,l,c,u){var h=3*e;if(a[h]<0){var d=(f-c)/(u-c),p=s,g=3*o;if(S[g]=i+d,S[g+1]=n,S[g+2]=l,!m){var _=3*e;M[g]=y*E(p[_],p[_+3],d),M[g+1]=y*E(p[_+1],p[_+4],d),M[g+2]=y*E(p[_+2],p[_+5],d)}r&&(C[o]=r[e+Math.round(d)]),a[h]=o,w[t]=o,o+=1}else w[t]=a[h]}function R(e,t,i,n,l,c,u){var h=3*e+1;if(a[h]<0){var d=(f-c)/(u-c),p=s,g=3*o;if(S[g]=i,S[g+1]=n+d,S[g+2]=l,!m){var _=3*e,v=_+3*b;M[g]=y*E(p[_],p[v],d),M[g+1]=y*E(p[_+1],p[v+1],d),M[g+2]=y*E(p[_+2],p[v+2],d)}r&&(C[o]=r[e+Math.round(d)*b]),a[h]=o,w[t]=o,o+=1}else w[t]=a[h]}function L(e,t,i,n,l,c,u){var h=3*e+2;if(a[h]<0){var d=(f-c)/(u-c),p=s,g=3*o;if(S[g]=i,S[g+1]=n,S[g+2]=l+d,!m){var _=3*e,v=_+3*x;M[g]=y*E(p[_],p[v],d),M[g+1]=y*E(p[_+1],p[v+1],d),M[g+2]=y*E(p[_+2],p[v+2],d)}r&&(C[o]=r[e+Math.round(d)*x]),a[h]=o,w[t]=o,o+=1}else w[t]=a[h]}function k(t){var i=3*t;0===s[i]&&(s[i]=e[(t-1+v)%v]-e[(t+1)%v],s[i+1]=e[(t-b+v)%v]-e[(t+b)%v],s[i+2]=e[(t-x+v)%v]-e[(t+x)%v])}function O(t,i,n,r,s){var a,o,c,u,h,y,v;g?(r=I(t,i,n),a=I(t+1,i,n),o=I(t,i+1,n),c=I(t,i,n+1),u=I(t+1,i+1,n),h=I(t+1,i,n+1),y=I(t,i+1,n+1),v=I(t+1,i+1,n+1)):(a=r+1,u=(o=r+b)+1,h=(c=r+x)+1,v=(y=o+x)+1);var S=0,M=e[r],C=e[a],E=e[o],O=e[u],N=e[c],F=e[h],B=e[y],z=e[v];M=f){L=y,E=!0;break}if(E)break}if(E)break}for(E=!1,_=s;_=f){R=_,E=!0;break}if(E)break}if(E)break}for(E=!1,p=r;p=f){D=p,E=!0;break}if(E)break}if(E)break}for(E=!1,y=u;y>=o;--y){for(_=c;_>=s;--_){for(p=l;p>=r;--p)if(h=t*i*y+t*_+p,e[h]>=f){F=y,E=!0;break}if(E)break}if(E)break}for(E=!1,_=c;_>=s;--_){for(y=F;y>=o;--y){for(p=l;p>=r;--p)if(h=t*i*y+t*_+p,e[h]>=f){N=_,E=!0;break}if(E)break}if(E)break}for(E=!1,p=l;p>=r;--p){for(_=N;_>=s;--_){for(y=F;y>=o;--y)if(h=t*i*y+t*_+p,e[h]>=f){k=p,E=!0;break}if(E)break}if(E)break}m?(r=Math.max(0,D-1),s=Math.max(0,R-1),o=Math.max(0,L-1),l=Math.min(t-1,k+1),c=Math.min(i-1,N+1),u=Math.min(n-1,F+1)):(r=Math.max(1,D-1),s=Math.max(1,R-1),o=Math.max(1,L-1),l=Math.min(t-2,k+1),c=Math.min(i-2,N+1),u=Math.min(n-2,F+1))}var B=15;for(y=o;y0?-1:1,s||(s=new Float32Array(3*v)));var T=3*v;if(a&&a.length===T||(a=new Int32Array(T)),o=0,l=0,void 0!==b){var P=b[0].map(Math.round),E=b[1].map(Math.round);c=t*Math.ceil(Math.abs(P[0])/t),u=i*Math.ceil(Math.abs(P[1])/i),h=n*Math.ceil(Math.abs(P[2])/n),N(P[0],P[1],P[2],E[0],E[1],E[2])}else c=u=h=0,N();return S.length=3*o,m||(M.length=3*o),A.length=l,r&&(C.length=o),{position:new Float32Array(S),normal:m?void 0:new Float32Array(M),index:So(A,S.length/3),atomindex:r?new Int32Array(C):void 0,contour:p}}}Kl.add("arrow",class extends Gd{get primitive(){return vh}}),Kl.add("box",class extends Gd{get primitive(){return ph}}),Kl.add("cone",class extends Gd{get primitive(){return bh}}),Kl.add("cylinder",class extends Gd{get primitive(){return yh}}),Kl.add("ellipsoid",class extends Gd{get primitive(){return xh}}),Kl.add("octahedron",class extends Gd{get primitive(){return gh}}),Kl.add("sphere",class extends Gd{get primitive(){return mh}}),Kl.add("tetrahedron",class extends Gd{get primitive(){return _h}}),Kl.add("torus",class extends Gd{get primitive(){return wh}}),Kl.add("point",class extends Gd{get primitive(){return Mh}}),Kl.add("wideline",class extends Gd{get primitive(){return Ah}}),Object.assign(sf,{__deps:[nf,rf,So]});class af{constructor(e,t){this.cols=e,this.rows=t,this.size=this.cols*this.rows,this.data=new Float32Array(this.size)}copyTo(e){e.data.set(this.data)}}function of(e,t){let i=0,n=0;const r=t.rows,s=t.cols;let a=0,o=0,l=0;const c=t.data,u=e.data;for(;i(t=Math.abs(t))?(t/=e,e*Math.sqrt(1+t*t)):t>0?(e/=t,t*Math.sqrt(1+e*e)):0}const mf=1.192092896e-7,pf=1e-37;function gf(e,t,i,n){let r=0,s=0;const a=e.rows,o=e.cols;let l=a,c=o;l>16?k:-k,e[u*t+d]=L;for(f=0;f<2;f++)for(h=0;h{const t=e.data.sd,i=e.data.p;a(this._makeSurface(t,i.isolevel,i.smooth))}),(o=>{console.warn("Volume.getSurfaceWorker error - trying without worker",o);const l=this.getSurface(e,t,i,n,r,s);a(l)}))}else{const o=this.getSurface(e,t,i,n,r,s);a(o)}}getValueForSigma(e){return this.mean+uo(e,2)*this.rms}getSigmaForValue(e){return(uo(e,0)-this.mean)/this.rms}get position(){if(!this._position){const e=this.nz,t=this.ny,i=this.nx,n=new Float32Array(i*t*e*3);let r=0;for(let s=0;si){const e=t;t=i,i=e}const n=e[t];return void 0===n?(e[t]=[i],!0):!n.includes(i)&&(n.push(i),!0)}const i=this.geometry,n=i.index;if(this.parameters.wireframe)if(n){const r=n.array;let s,a=r.length;if(i.drawRange.count!==1/0&&(a=i.drawRange.count),this.wireframeIndex&&this.wireframeIndex.length>2*a)s=this.wireframeIndex;else{s=So(2*a,i.attributes.position.count)}let o=0;e.length=0;for(let e=0;e2*e?this.wireframeIndex:So(2*e,e);for(let i=0,n=0;ithis.wireframeGeometry.index.array.length)this.wireframeGeometry.setIndex(new $i(this.wireframeIndex,1).setUsage(this.dynamic?Te:Ce));else{const e=this.wireframeGeometry.getIndex();if(!e)return void Fl.error("Index is null");e.set(this.wireframeIndex),e.needsUpdate=this.wireframeIndexCount>0,e.updateRange.count=this.wireframeIndexCount}this.wireframeGeometry.setDrawRange(0,this.wireframeIndexCount)}}getRenderOrder(){let e=0;return this.isText?e=1:this.transparent&&(e=this.isSurface?3:2),e}_getMesh(e){this.material||this.makeMaterial();const t=this.geometry,i=this[e];let n;return n=this.isLine?new ka(t,i):this.isPoint?new Ua(t,i):new yn(t,i),n.frustumCulled=!1,n.renderOrder=this.getRenderOrder(),n}getMesh(){return this._getMesh("material")}getWireframeMesh(){let e;return this.material||this.makeMaterial(),this.wireframeGeometry||this.makeWireframeGeometry(),e=new ka(this.wireframeGeometry,this.wireframeMaterial),e.frustumCulled=!1,e.renderOrder=this.getRenderOrder(),e}getPickingMesh(){return this._getMesh("pickingMaterial")}getShader(e,t){return pc(e,this.getDefines(t))}getVertexShader(e){return this.getShader(this.vertexShader,e)}getFragmentShader(e){return this.getShader(this.fragmentShader,e)}getDefines(e){const t={};return this.parameters.clipNear&&(t.NEAR_CLIP=1),this.parameters.clipRadius&&(t.RADIUS_CLIP=1),"picking"===e?t.PICKING=1:(("background"===e||this.parameters.background)&&(t.NOLIGHT=1),this.parameters.flatShaded&&(t.FLAT_SHADED=1),this.parameters.opaqueBack&&(t.OPAQUE_BACK=1),this.parameters.diffuseInterior&&(t.DIFFUSE_INTERIOR=1),this.parameters.useInteriorColor&&(t.USE_INTERIOR_COLOR=1)),t}getParameters(){return this.parameters}addUniforms(e){this.uniforms=Mn.merge([this.uniforms,e]),this.pickingUniforms=Mn.merge([this.pickingUniforms,e])}addAttributes(e){for(let t in e){let i;const n=e[t],r=this.attributeSize*Lf[n.type];n.value?(r!==n.value.length&&Fl.error("attribute value has wrong length",t),i=n.value):i=wo("float32",r),this.geometry.setAttribute(t,new $i(i,Lf[n.type]).setUsage(this.dynamic?Te:Ce))}}updateRenderOrder(){const e=this.getRenderOrder();function t(t){t.renderOrder=e}this.group.children.forEach(t),this.pickingGroup&&this.pickingGroup.children.forEach(t)}updateShader(){const e=this.material,t=this.wireframeMaterial,i=this.pickingMaterial;e.vertexShader=this.getVertexShader(),e.fragmentShader=this.getFragmentShader(),e.needsUpdate=!0,t.vertexShader=this.getShader("Line.vert"),t.fragmentShader=this.getShader("Line.frag"),t.needsUpdate=!0,i.vertexShader=this.getVertexShader("picking"),i.fragmentShader=this.getFragmentShader("picking"),i.needsUpdate=!0}setParameters(e){const t=e,i=this.parameterTypes,n=this.parameters,r={},s={};let a=!1,o=!1;for(const e in t){const l=t[e];void 0!==l&&(n[e]=l,void 0!==i[e]&&(i[e].property&&(!0!==i[e].property?r[i[e].property]=l:r[e]=l),i[e].uniform&&(!0!==i[e].uniform?s[i[e].uniform]=l:s[e]=l),i[e].updateShader&&(a=!0),i[e].updateVisibility&&(o=!0),this.dynamic&&"wireframe"===e&&!0===l&&this.updateWireframeIndex(),"forceTransparent"===e&&(r.transparent=this.transparent),"matrix"===e&&(this.matrix=l)))}this.setProperties(r),this.setUniforms(s),a&&this.updateShader(),o&&this.setVisibility(this.visible)}setAttributes(e){const t=this.geometry,i=t.attributes;for(const n in e){if("picking"===n)continue;const r=e[n],s=r.length;if("index"===n){const e=t.getIndex();if(!e){Fl.error("Index is null");continue}t.setDrawRange(0,1/0),s>e.array.length?t.setIndex(new $i(r,1).setUsage(this.dynamic?Te:Ce)):(e.set(r),e.needsUpdate=s>0,e.updateRange.count=s,t.setDrawRange(0,s)),this.indexVersion++,this.parameters.wireframe&&this.updateWireframeIndex()}else{const e=i[n];s>e.array.length?t.setAttribute(n,new $i(r,e.itemSize).setUsage(this.dynamic?Te:Ce)):(i[n].set(r),i[n].needsUpdate=s>0,i[n].updateRange.count=s)}}}setUniforms(e){if(!e)return;const t=this.material.uniforms,i=this.wireframeMaterial.uniforms,n=this.pickingMaterial.uniforms;for(let r in e)"opacity"===r&&this.setProperties({transparent:this.transparent}),void 0!==t[r]&&(t[r].value.isVector3?t[r].value.copy(e[r]):t[r].value.set?t[r].value.set(e[r]):t[r].value=e[r]),void 0!==i[r]&&(i[r].value.isVector3?i[r].value.copy(e[r]):i[r].value.set?i[r].value.set(e[r]):i[r].value=e[r]),void 0!==n[r]&&(n[r].value.isVector3?n[r].value.copy(e[r]):n[r].value.set?n[r].value.set(e[r]):n[r].value=e[r])}setProperties(e){if(!e)return;const t=this.material,i=this.wireframeMaterial,n=this.pickingMaterial;for(const r in e){const s=r;let a=e[s];"transparent"===s?this.updateRenderOrder():"side"===s&&(a=Rf(a)),t[s]=a,i[s]=a,n[s]=a}t.needsUpdate=!0,i.needsUpdate=!0,n.needsUpdate=!0}setVisibility(e){this.visible=e,this.parameters.wireframe?(this.group.visible=!1,this.wireframeGroup.visible=e,this.pickable&&(this.pickingGroup.visible=!1)):(this.group.visible=e,this.wireframeGroup.visible=!1,this.pickable&&(this.pickingGroup.visible=e))}dispose(){this.material&&this.material.dispose(),this.wireframeMaterial&&this.wireframeMaterial.dispose(),this.pickingMaterial&&this.pickingMaterial.dispose(),this.geometry.dispose(),this.wireframeGeometry&&this.wireframeGeometry.dispose()}toJSON(){var e={};for(var t in this)"group"!==t&&"wireframeGroup"!==t&&"pickingGroup"!=t&&"picking"!==t&&(e[t]=this[t]);return e}}class Bf extends Ff{constructor(e,t={}){super(e,t),this.vertexShader="Mesh.vert",this.fragmentShader="Mesh.frag",this.addAttributes({normal:{type:"v3",value:e.normal}}),void 0===e.normal&&this.geometry.computeVertexNormals()}}class zf extends Bf{constructor(){super(...arguments),this.isSurface=!0}}function Uf(e){e.visible=!0}function Vf(e){e.visible=!1}class $f{constructor(e){this.group=new ma,this.wireframeGroup=new ma,this.pickingGroup=new ma,this.frontMeshes=[],this.backMeshes=[],this.size=e.size,this.side=e.parameters.side,this.visible=e.visible,this.geometry=e.geometry,this.picking=e.picking,this.group=new ma,this.wireframeGroup=new ma,this.pickingGroup=new ma,this.matrix=e.matrix;const t=e,i=new e.constructor({position:new Float32Array(0)});t.makeMaterial(),i.makeMaterial(),i.picking=e.picking,i.geometry=e.geometry,i.wireframeGeometry=e.wireframeGeometry,i.setParameters(e.getParameters()),i.updateShader(),t.setParameters({side:"front"}),i.setParameters({side:"back",opacity:i.parameters.opacity}),this.buffer=e,this.frontBuffer=t,this.backBuffer=i}set matrix(e){Ff.prototype.setMatrix.call(this,e)}get matrix(){return this.group.matrix.clone()}get pickable(){return!!this.picking&&!this.parameters.disablePicking}get parameters(){return this.buffer.parameters}getParameters(){const e=Object.assign({},this.buffer.parameters);return e.side=this.side,e}getMesh(e){let t,i;return e?(i=this.backBuffer.getPickingMesh(),t=this.frontBuffer.getPickingMesh()):(i=this.backBuffer.getMesh(),t=this.frontBuffer.getMesh()),this.frontMeshes.push(t),this.backMeshes.push(i),this.setParameters({side:this.side}),(new ma).add(i,t)}getWireframeMesh(){return this.buffer.getWireframeMesh()}getPickingMesh(){return this.getMesh(!0)}setAttributes(e){this.buffer.setAttributes(e)}setParameters(e){"front"===(e=Object.assign({},e)).side?(this.frontMeshes.forEach(Uf),this.backMeshes.forEach(Vf)):"back"===e.side?(this.frontMeshes.forEach(Vf),this.backMeshes.forEach(Uf)):"double"===e.side&&(this.frontMeshes.forEach(Uf),this.backMeshes.forEach(Uf)),void 0!==e.side&&(this.side=e.side),delete e.side,void 0!==e.matrix&&(this.matrix=e.matrix),delete e.matrix,this.frontBuffer.setParameters(e),void 0!==e.wireframe&&(this.wireframe=e.wireframe,this.setVisibility(this.visible)),delete e.wireframe,this.backBuffer.setParameters(e)}setVisibility(e){this.visible=e,this.parameters.wireframe?(this.group.visible=!1,this.wireframeGroup.visible=e,this.pickable&&(this.pickingGroup.visible=!1)):(this.group.visible=e,this.wireframeGroup.visible=!1,this.pickable&&(this.pickingGroup.visible=e))}dispose(){this.frontBuffer.dispose(),this.backBuffer.dispose()}toJSON(){var e={};for(var t in this)["side","size","visible","matrix","parameters"].includes(t)&&(e[t]=this[t]);return e}}Wl.add("shader/Line.vert","uniform float clipNear;\nuniform vec3 clipCenter;\nvarying vec3 vViewPosition;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#include color_pars_vertex\nvoid main(){\n#include color_vertex\n#include begin_vertex\n#include project_vertex\nvViewPosition = -mvPosition.xyz;\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n#include nearclip_vertex\n}"),Wl.add("shader/Line.frag","uniform float opacity;\nuniform float clipNear;\nuniform float clipRadius;\nvarying vec3 vViewPosition;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#include common\n#include color_pars_fragment\n#include fog_pars_fragment\nvoid main(){\n#include nearclip_fragment\n#include radiusclip_fragment\ngl_FragColor = vec4( vColor, opacity );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n}");class Gf extends Ff{constructor(){super(...arguments),this.isLine=!0,this.vertexShader="Line.vert",this.fragmentShader="Line.frag"}}class Hf extends Nu{constructor(e,t,i){super(e,t,i),this.type="surface",this.parameters=Object.assign({isolevelType:{type:"select",options:{value:"value",sigma:"sigma"}},isolevel:{type:"number",precision:2,max:1e3,min:-1e3},negateIsolevel:{type:"boolean"},isolevelScroll:{type:"boolean"},smooth:{type:"integer",precision:1,max:10,min:0},background:{type:"boolean",rebuild:!0},opaqueBack:{type:"boolean",buffer:!0},boxSize:{type:"integer",precision:1,max:100,min:0},colorVolume:{type:"hidden"},contour:{type:"boolean",rebuild:!0},useWorker:{type:"boolean",rebuild:!0},wrap:{type:"boolean",rebuild:!0}},this.parameters),e instanceof Df?(this.surface=void 0,this.volume=e):(this.surface=e,this.volume=void 0),this.boxCenter=new _t,this.__boxCenter=new _t,this.box=new bt,this.__box=new bt,this._position=new _t,this.inverseMatrix=new qt,this.setBox=function(){this._position.copy(t.translationGroup.position).negate(),this._position.applyMatrix4(this.inverseMatrix),this._position.equals(this.boxCenter)||this.setParameters({boxCenter:this._position})},this.toBePrepared=!0,this.viewer.signals.ticked.add(this.setBox,this),this.init(i)}init(e){const t=e||{};t.colorScheme=uo(t.colorScheme,"uniform"),t.colorValue=uo(t.colorValue,14540253),this.isolevelType=uo(t.isolevelType,"sigma"),this.isolevel=uo(t.isolevel,2),this.negateIsolevel=uo(t.negateIsolevel,!1),this.isolevelScroll=uo(t.isolevelScroll,!1),this.smooth=uo(t.smooth,0),this.background=uo(t.background,!1),this.opaqueBack=uo(t.opaqueBack,!0),this.boxSize=uo(t.boxSize,0),this.colorVolume=uo(t.colorVolume,void 0),this.contour=uo(t.contour,!1),this.useWorker=uo(t.useWorker,!0),this.wrap=uo(t.wrap,!1),super.init(t),this.inverseMatrix.copy(this.matrix).invert(),this.build()}attach(e){this.bufferList.forEach((e=>{this.viewer.add(e)})),this.setVisibility(this.visible),e()}prepare(e){if(this.volume){let t;if(t="sigma"===this.isolevelType?this.volume.getValueForSigma(this.isolevel):this.isolevel,this.negateIsolevel&&(t*=-1),!this.surface||this.__isolevel!==t||this.__smooth!==this.smooth||this.__contour!==this.contour||this.__wrap!==this.wrap||this.__boxSize!==this.boxSize||this.boxSize>0&&!this.__boxCenter.equals(this.boxCenter)){this.__isolevel=t,this.__smooth=this.smooth,this.__contour=this.contour,this.__wrap=this.wrap,this.__boxSize=this.boxSize,this.__boxCenter.copy(this.boxCenter),this.__box.copy(this.box);const i=t=>{this.surface=t,e()};this.useWorker?this.volume.getSurfaceWorker(t,this.smooth,this.boxCenter,this.boxSize,this.contour,this.wrap,i):i(this.volume.getSurface(t,this.smooth,this.boxCenter,this.boxSize,this.contour,this.wrap))}else e()}else e()}create(){const e={position:this.surface.getPosition(),color:this.surface.getColor(this.getColorParams()),index:this.surface.getIndex()};let t;if(this.contour)t=new Gf(e,this.getBufferParams({wireframe:!1}));else{Object.assign(e,{normal:this.surface.getNormal(),picking:this.surface.getPicking()});const i=new zf(e,this.getBufferParams({background:this.background,opaqueBack:this.opaqueBack,dullInterior:!1}));t=new $f(i)}this.bufferList.push(t)}update(e){if(0===this.bufferList.length)return;const t={};(e=e||{}).position&&(t.position=this.surface.getPosition()),e.color&&(t.color=this.surface.getColor(this.getColorParams())),e.index&&(t.index=this.surface.getIndex()),e.normal&&(t.normal=this.surface.getNormal()),this.bufferList.forEach((function(e){e.setAttributes(t)}))}setParameters(e,t,i){return e&&void 0!==e.isolevelType&&this.volume&&("value"===this.isolevelType&&"sigma"===e.isolevelType?this.isolevel=this.volume.getSigmaForValue(this.isolevel):"sigma"===this.isolevelType&&"value"===e.isolevelType&&(this.isolevel=this.volume.getValueForSigma(this.isolevel)),this.isolevelType=e.isolevelType),e&&e.boxCenter&&(this.boxCenter.copy(e.boxCenter),delete e.boxCenter),e&&e.wireframe&&(e.contour||void 0===e.contour&&this.contour)&&(e.wireframe=!1),super.setParameters(e,t,i),e.matrix&&this.inverseMatrix.copy(e.matrix).invert(),this.volume&&this.volume.getBox(this.boxCenter,this.boxSize,this.box),e&&void 0!==e.colorVolume&&t&&(t.color=!0),this.surface&&(void 0!==e.isolevel||void 0!==e.negateIsolevel||void 0!==e.smooth||void 0!==e.wrap||void 0!==e.boxSize||this.boxSize>0&&!this.__box.equals(this.box))&&this.build({position:!0,color:!0,index:!0,normal:!this.contour}),this}getColorParams(){const e=super.getColorParams();return e.volume=this.colorVolume,e}dispose(){this.viewer.signals.ticked.remove(this.setBox,this),super.dispose()}}class jf{static zoomScroll(e,t){e.trackballControls.zoom(t)}static clipNearScroll(e,t){const i=e.getParameters();e.setParameters({clipNear:i.clipNear+t/10})}static focusScroll(e,t){const i=e.getFocus(),n=Math.sign(t)*function(e,t,i){if(e>t)return e;const n=e/t;return((2*i-t)*n+(2*t-3*i))*n*n+i}((100-i)/10,5,.2);e.setFocus(i+n)}static zoomFocusScroll(e,t){e.trackballControls.zoom(t);const i=e.viewer.camera.position.z;e.setFocus(100-Math.abs(i/8))}static isolevelScroll(e,t){const i=Math.sign(t)/10;e.eachRepresentation(((e,t)=>{if(e.repr instanceof Hf){const t=e.getParameters();t.isolevelScroll&&e.setParameters({isolevel:t.isolevel+i})}}))}static panDrag(e,t,i){e.trackballControls.pan(t,i)}static rotateDrag(e,t,i){e.trackballControls.rotate(t,i)}static zRotateDrag(e,t,i){e.trackballControls.zRotate(t,i)}static zoomDrag(e,t,i){e.trackballControls.zoom((t+i)/-2)}static zoomFocusDrag(e,t,i){e.trackballControls.zoom((t+i)/-2);const n=e.viewer.camera.position.z;e.setFocus(100-Math.abs(n/8))}static panComponentDrag(e,t,i){e.trackballControls.panComponent(t,i)}static panAtomDrag(e,t,i){e.trackballControls.panAtom(t,i)}static rotateComponentDrag(e,t,i){e.trackballControls.rotateComponent(t,i)}static movePick(e,t){t&&e.animationControls.move(t.position.clone())}static tooltipPick(e,t){const i=e.tooltip;if(e.getParameters().tooltip&&t){const e=t.mouse.position;i.innerText=t.getLabel(),i.style.bottom=window.innerHeight-e.y+3+"px",i.style.left=e.x+3+"px",i.style.display="block"}else i.style.display="none"}static measurePick(e,t){if(t&&(t.atom||t.bond)){const e=t.atom||t.closestBondAtom;t.component.measurePick(e)}else e.measureClear()}}const Wf={default:[["scroll",jf.zoomScroll],["scroll-shift",jf.focusScroll],["scroll-ctrl",jf.isolevelScroll],["scroll-shift-ctrl",jf.zoomFocusScroll],["drag-left",jf.rotateDrag],["drag-right",jf.panDrag],["drag-ctrl-left",jf.panDrag],["drag-ctrl-right",jf.zRotateDrag],["drag-shift-left",jf.zoomDrag],["drag-middle",jf.zoomFocusDrag],["drag-ctrl-shift-right",jf.panComponentDrag],["drag-ctrl-shift-left",jf.rotateComponentDrag],["clickPick-right",jf.measurePick],["clickPick-ctrl-left",jf.measurePick],["clickPick-middle",jf.movePick],["clickPick-left",jf.movePick],["hoverPick",jf.tooltipPick]],pymol:[["drag-left",jf.rotateDrag],["drag-middle",jf.panDrag],["drag-right",jf.zoomDrag],["scroll",jf.focusScroll],["drag-shift-right",jf.focusScroll],["clickPick-ctrl+shift-middle",jf.movePick],["hoverPick",jf.tooltipPick]],coot:[["scroll",jf.isolevelScroll],["drag-left",jf.rotateDrag],["drag-middle",jf.panDrag],["drag-ctrl-left",jf.panDrag],["drag-right",jf.zoomFocusDrag],["drag-ctrl-right",jf.focusScroll],["clickPick-middle",jf.movePick],["hoverPick",jf.tooltipPick]],astexviewer:[["drag-left",jf.rotateDrag],["drag-ctrl-left",jf.panDrag],["drag-shift-left",jf.zoomDrag],["scroll",jf.focusScroll],["clickPick-middle",jf.movePick],["hoverPick",jf.tooltipPick]]};function qf(e){const t=e.split(/[-+]/);let i="";t.includes("scroll")&&(i="scroll"),t.includes("drag")&&(i="drag"),t.includes("click")&&(i="click"),t.includes("doubleClick")&&(i="doubleClick"),t.includes("hover")&&(i="hover"),t.includes("clickPick")&&(i="clickPick"),t.includes("hoverPick")&&(i="hoverPick");let n=0;t.includes("alt")&&(n+=1),t.includes("ctrl")&&(n+=2),t.includes("meta")&&(n+=4),t.includes("shift")&&(n+=8);let r=0;return t.includes("left")&&(r+=1),t.includes("right")&&(r+=2),t.includes("middle")&&(r+=4),[i,n,r]}class Xf{constructor(e,t={}){this.stage=e,this.actionList=[],this.mouse=e.mouseObserver,this.disabled=t.disabled||!1,this.preset(t.preset||"default")}run(e,...t){if(this.disabled)return;const i=this.mouse.key||0,n=this.mouse.buttons||0;this.actionList.forEach((r=>{r.type===e&&r.key===i&&r.button===n&&r.callback(this.stage,...t)}))}add(e,t){const[i,n,r]=qf(e);this.actionList.push({type:i,key:n,button:r,callback:t})}remove(e,t){const i=e.includes("*"),[n,r,s]=qf(e),a=this.actionList.filter((function(e){return!((e.type===n||i&&""===n)&&(e.key===r||i&&0===r)&&(e.button===s||i&&0===s)&&(e.callback===t||void 0===t))}));this.actionList=a}preset(e){this.clear();(Wf[e]||[]).forEach((e=>this.add(e[0],e[1])))}clear(){this.actionList.length=0}}class Yf{static autoView(e){e.autoView(1e3)}static toggleAnimations(e){e.animationControls.toggle()}static toggleRock(e){e.toggleRock()}static toggleSpin(e){e.toggleSpin()}static toggleAntialiasing(e){const t=e.getParameters();e.setParameters({sampleLevel:-1===t.sampleLevel?0:-1})}}const Kf={default:[["i",Yf.toggleSpin],["k",Yf.toggleRock],["p",Yf.toggleAnimations],["a",Yf.toggleAntialiasing],["r",Yf.autoView]]};class Zf{constructor(e,t={}){this.stage=e,this.actionList=[],this.disabled=t.disabled||!1,this.preset(t.preset||"default")}run(e){this.disabled||this.actionList.forEach((t=>{t.key===e&&t.callback(this.stage)}))}add(e,t){this.actionList.push({key:e,callback:t})}remove(e,t){const i=this.actionList.filter((function(i){return!(i.key===e&&(i.callback===t||void 0===t))}));this.actionList=i}preset(e){this.clear();(Kf[e]||[]).forEach((e=>this.add(e[0],e[1])))}clear(){this.actionList.length=0}}class Qf{constructor(e){this.stage=e,this.stage=e,this.mouse=e.mouseObserver,this.controls=e.mouseControls,this.mouse.signals.clicked.add(this._onClick,this),this.mouse.signals.hovered.add(this._onHover,this)}_onClick(e,t){const i=this.stage.pickingControls.pick(e,t);this.stage.signals.clicked.dispatch(i),this.controls.run("clickPick",i)}_onHover(e,t){const i=this.stage.pickingControls.pick(e,t);i&&this.mouse.down.equals(this.mouse.position)&&(this.stage.transformComponent=i.component,this.stage.transformAtom=i.atom),this.stage.signals.hovered.dispatch(i),this.controls.run("hoverPick",i)}dispose(){this.mouse.signals.clicked.remove(this._onClick,this),this.mouse.signals.hovered.remove(this._onHover,this)}}class Jf{constructor(e){this.stage=e,this.stage=e,this.mouse=e.mouseObserver,this.controls=e.mouseControls,this.mouse.signals.moved.add(this._onMove,this),this.mouse.signals.scrolled.add(this._onScroll,this),this.mouse.signals.dragged.add(this._onDrag,this),this.mouse.signals.clicked.add(this._onClick,this),this.mouse.signals.hovered.add(this._onHover,this),this.mouse.signals.doubleClicked.add(this._onDblclick,this)}_onMove(){this.stage.tooltip.style.display="none"}_onScroll(e){this.controls.run("scroll",e)}_onDrag(e,t){this.controls.run("drag",e,t)}_onClick(e,t){this.controls.run("click",e,t)}_onDblclick(e,t){this.controls.run("doubleClick",e,t)}_onHover(e,t){this.controls.run("hover",e,t)}dispose(){this.mouse.signals.moved.remove(this._onMove,this),this.mouse.signals.scrolled.remove(this._onScroll,this),this.mouse.signals.dragged.remove(this._onDrag,this),this.mouse.signals.clicked.remove(this._onClick,this),this.mouse.signals.hovered.remove(this._onHover,this)}}class em{constructor(e){this.stage=e,this.viewer=e.viewer,this.animationControls=e.animationControls,this.viewer.signals.ticked.add(this._onTick,this)}_onTick(e){this.animationControls.run(e)}dispose(){this.viewer.signals.ticked.remove(this._onTick,this)}}const tm=!!Dl&&{passive:!0};class im{constructor(e){this.stage=e,this.stage=e,this.controls=e.keyControls,this.domElement=e.viewer.renderer.domElement,this.domElement.setAttribute("tabIndex","-1"),this.domElement.style.outline="none",this._focusDomElement=this._focusDomElement.bind(this),this._onKeydown=this._onKeydown.bind(this),this._onKeyup=this._onKeyup.bind(this),this._onKeypress=this._onKeypress.bind(this),this.domElement.addEventListener("mousedown",this._focusDomElement),this.domElement.addEventListener("touchstart",this._focusDomElement,tm),this.domElement.addEventListener("keydown",this._onKeydown),this.domElement.addEventListener("keyup",this._onKeyup),this.domElement.addEventListener("keypress",this._onKeypress)}_onKeydown(){}_onKeyup(){}_onKeypress(e){let t;t="key"in KeyboardEvent.prototype?e.key:String.fromCharCode(e.which||e.keyCode),this.controls.run(t)}_focusDomElement(){this.domElement.focus()}dispose(){this.domElement.removeEventListener("mousedown",this._focusDomElement),this.domElement.removeEventListener("touchstart",this._focusDomElement,tm),this.domElement.removeEventListener("keydown",this._onKeypress),this.domElement.removeEventListener("keyup",this._onKeypress),this.domElement.removeEventListener("keypress",this._onKeypress)}}class nm{constructor(e,t,i,n={}){this.component=e,this.position=t,this.offsetX=uo(n.offsetX,0),this.offsetY=uo(n.offsetY,0),this.visible=uo(n.visible,!0),this.stage=e.stage,this.viewer=e.stage.viewer,this._viewerPosition=new _t,this._updateViewerPosition(),this._canvasPosition=new Ge,this._cameraPosition=new _t,this.element=document.createElement("div"),Object.assign(this.element.style,{display:"block",position:"absolute",pointerEvents:"none",whiteSpace:"nowrap",left:"-10000px"}),this.viewer.wrapper.appendChild(this.element),this.setContent(i),this.updateVisibility(),this.viewer.signals.rendered.add(this._update,this),this.component.signals.matrixChanged.add(this._updateViewerPosition,this)}setContent(e){const t=this.element.style.display;if("none"===t&&(this.element.style.left="-10000px",this.element.style.display="block"),e instanceof HTMLElement)this.element.appendChild(e);else{const t=document.createElement("div");t.innerText=e,Object.assign(t.style,{backgroundColor:"rgba( 0, 0, 0, 0.6 )",color:"lightgrey",padding:"8px",fontFamily:"sans-serif"}),this.element.appendChild(t)}this._clientRect=this.element.getBoundingClientRect(),"none"===t&&(this.element.style.display=t)}setVisibility(e){this.visible=e,this.updateVisibility()}getVisibility(){return this.visible&&this.component.parameters.visible}updateVisibility(){this.element.style.display=this.getVisibility()?"block":"none"}_updateViewerPosition(){this._viewerPosition.copy(this.position).applyMatrix4(this.component.matrix)}_update(){if(!this.getVisibility())return;const e=this.element.style,t=this._canvasPosition,i=this._viewerPosition,n=this._clientRect;if(this._cameraPosition.copy(i).add(this.viewer.translationGroup.position).applyMatrix4(this.viewer.rotationGroup.matrix).sub(this.viewer.camera.position),this._cameraPosition.z<0)return void(e.display="none");e.display="block";const r=this._cameraPosition.length(),s=this.viewer.scene.fog;e.opacity=(1-zo(s.near,s.far,r)).toString(),e.zIndex=Math.round(100*(s.far-r)).toString(),this.stage.viewerControls.getPositionOnCanvas(i,t),e.bottom=this.offsetX+t.y+n.height/2+"px",e.left=this.offsetY+t.x-n.width/2+"px"}dispose(){this.viewer.wrapper.removeChild(this.element),this.viewer.signals.ticked.remove(this._update,this),this.component.signals.matrixChanged.remove(this._updateViewerPosition,this)}}const rm=new qt,sm=new _t,am=new gt;class om{constructor(e){this.component=e,this.signals={changed:new Yo.Signal},this.stage=e.stage,this.viewer=e.stage.viewer}get position(){return this.component.position}get rotation(){return this.component.quaternion}changed(){this.component.updateMatrix(),this.viewer.requestRender(),this.signals.changed.dispatch()}spin(e,t){rm.copy(this.viewer.rotationGroup.matrix).invert(),sm.copy(Co(e)).applyMatrix4(rm),rm.extractRotation(this.component.transform),rm.premultiply(this.viewer.rotationGroup.matrix),rm.invert(),sm.copy(Co(e)),sm.applyMatrix4(rm),rm.makeRotationAxis(sm,t),am.setFromRotationMatrix(rm),this.component.quaternion.premultiply(am),this.changed()}}const lm={"":"",vdw:"by vdW radius",covalent:"by covalent radius",sstruc:"by secondary structure",bfactor:"by bfactor",size:"size",data:"data",explicit:"explicit"};class cm{constructor(e={}){this.max=10,this.type=uo(e.type,"size"),this.scale=uo(e.scale,1),this.size=uo(e.size,1),this.data=uo(e.data,{})}atomRadius(e){let t;switch(this.type){case"vdw":t=e.vdw;break;case"covalent":t=e.covalent;break;case"bfactor":t=e.bfactor||1;break;case"sstruc":const i=e.sstruc;t="h"===i||"g"===i||"i"===i||"e"===i||"b"===i?.25:od.includes(e.atomname)?.4:.1;break;case"data":t=uo(this.data[e.index],1);break;case"explicit":t=e.radius,null===t&&(t=this.size);break;default:t=this.size}return Math.min(t*this.scale,this.max)}}cm.types=lm;const um=new _t(-1,-1,-1),hm=new qt;class dm{constructor(e){const t=e.rows,i=t/3,n=new af(t,3),r=new af(3,3),s=new af(1,3),a=new af(3,3),o=new af(3,3),l=uf(e);hf(e,l),of(n,e),lf(r,n,n),gf(r,s,a,o);const c=new _t(l[0],l[1],l[2]),u=new _t(a.data[0],a.data[3],a.data[6]),h=new _t(a.data[1],a.data[4],a.data[7]),d=new _t(a.data[2],a.data[5],a.data[8]),f=u.clone().multiplyScalar(Math.sqrt(s.data[0]/i)),m=h.clone().multiplyScalar(Math.sqrt(s.data[1]/i)),p=d.clone().multiplyScalar(Math.sqrt(s.data[2]/i));this.begA=c.clone().sub(f),this.endA=c.clone().add(f),this.begB=c.clone().sub(m),this.endB=c.clone().add(m),this.begC=c.clone().sub(p),this.endC=c.clone().add(p),this.center=c,this.vecA=f,this.vecB=m,this.vecC=p,this.normVecA=u,this.normVecB=h,this.normVecC=d}getBasisMatrix(e=new qt){const t=e;return t.makeBasis(this.normVecB,this.normVecA,this.normVecC),t.determinant()<0&&t.scale(um),t}getRotationQuaternion(e=new gt){const t=e;return t.setFromRotationMatrix(this.getBasisMatrix(hm)),t.invert()}getProjectedScaleForAtoms(e){let t=-1/0,i=-1/0,n=-1/0,r=-1/0,s=-1/0,a=-1/0;const o=new _t,l=new _t,c=this.center,u=this.normVecA,h=this.normVecB,d=this.normVecC;return e.eachAtom((function(e){Uu(o.copy(e),u,c);const f=l.subVectors(o,c).normalize().dot(u),m=o.distanceTo(c);f>0?m>t&&(t=m):m>i&&(i=m),Uu(o.copy(e),h,c);const p=l.subVectors(o,c).normalize().dot(h),g=o.distanceTo(c);p>0?g>n&&(n=g):g>r&&(r=g),Uu(o.copy(e),d,c);const _=l.subVectors(o,c).normalize().dot(d),y=o.distanceTo(c);_>0?y>s&&(s=y):y>a&&(a=y)})),{d1a:t,d2a:n,d3a:s,d1b:-i,d2b:-r,d3b:-a}}}class fm{constructor(e,t,i,n){this.volume=e,this.setFilter(t,i,n)}get header(){return this.volume.header}get matrix(){return this.volume.matrix}get normalMatrix(){return this.volume.normalMatrix}get inverseMatrix(){return this.volume.inverseMatrix}get center(){return this.volume.center}get boundingBox(){return this.volume.boundingBox}get min(){return this.volume.min}get max(){return this.volume.max}get mean(){return this.volume.mean}get rms(){return this.volume.rms}_getFilterHash(e,t,i){return JSON.stringify([e,t,i])}setFilter(e,t,i){isNaN(e)&&this.header&&(e=this.header.DMEAN+2*this.header.ARMS),e=void 0===e||isNaN(e)?-1/0:e,t=uo(t,1/0),i=uo(i,!1);const n=this.volume.data,r=this.volume.position,s=this.volume.atomindex,a=this._getFilterHash(e,t,i);if(a!==this._filterHash){if(e===-1/0&&t===1/0)this.data=n,this.position=r,this.atomindex=s;else{const a=n.length;this._dataBuffer||(this._dataBuffer=new ArrayBuffer(4*a),this._positionBuffer=new ArrayBuffer(3*a*4),s&&(this._atomindexBuffer=new ArrayBuffer(4*a)));const o=new Float32Array(this._dataBuffer),l=new Float32Array(this._positionBuffer);let c;s&&(c=new Uint32Array(this._atomindexBuffer));let u=0;for(let h=0;h=e&&d<=t||i&&(dt)){const e=3*u;o[u]=d,l[e+0]=r[a+0],l[e+1]=r[a+1],l[e+2]=r[a+2],s&&c&&(c[u]=s[h]),u+=1}}this.data=new Float32Array(this._dataBuffer,0,u),this.position=new Float32Array(this._positionBuffer,0,3*u),s&&(this.atomindex=new Int32Array(this._atomindexBuffer,0,u))}this._filterHash=a}}}fm.prototype.getValueForSigma=Df.prototype.getValueForSigma,fm.prototype.getSigmaForValue=Df.prototype.getSigmaForValue,fm.prototype.getDataAtomindex=Df.prototype.getDataAtomindex,fm.prototype.getDataPosition=Df.prototype.getDataPosition,fm.prototype.getDataColor=Df.prototype.getDataColor,fm.prototype.getDataPicking=Df.prototype.getDataPicking,fm.prototype.getDataSize=Df.prototype.getDataSize;class mm{constructor(e,t){const i=Dh({nodeArray1:e.atomIndex1,nodeArray2:e.atomIndex2,edgeCount:e.count,nodeCount:t});this.countArray=i.countArray,this.offsetArray=i.offsetArray,this.indexArray=i.indexArray}}class pm extends Th{get _defaultFields(){return[["atomIndex1",1,"int32"],["atomIndex2",1,"int32"],["bondOrder",1,"int8"]]}addBond(e,t,i){this.growIfFull();const n=this.count,r=e.index,s=t.index;r0&&(a[t]=v.angleTo(b));const n=Math.cos(m.angleTo(p));c[t]=180/Math.PI*Math.acos(n);const y=m.length(),P=p.length();o[t]=Math.sqrt(P*y)/Math.max(2,2*(1-n)),l[t]=Math.abs(d.dot(v)),g.copy(m).multiplyScalar(o[t]/y),_.copy(p).multiplyScalar(o[t]/P),g.subVectors(A,g),_.subVectors(C,_),g.toArray(r,i+3),_.toArray(r,i+6),x.subVectors(M,w),x.toArray(u,i),b.copy(v),w.copy(g)}g.fromArray(r,3),_.fromArray(r,6),v.subVectors(g,_).normalize(),M.index=e.getAtomIndexByType(0,S),w.copy(M),y.copy(M),Uu(y,v,g),y.toArray(r,0),x.subVectors(w,g),x.toArray(u,0),g.fromArray(r,3*i-6),_.fromArray(r,3*i-9),v.subVectors(g,_).normalize(),M.index=e.getAtomIndexByType(i-1,S),w.copy(M),y.copy(M),Uu(y,v,g),y.toArray(r,3*i-3);for(let t=i-3;tt||c.bending[n]>e)&&(O=!0)),O){if(n-f<4){f=n,O=!1;continue}R.index=I.traceAtomIndex,C=c.axis.subarray(3*f+3,3*n),T=c.center.subarray(3*f,3*n+3),M=zu(C).normalize(),A=zu(T),P.fromArray(T),Uu(P,M,A),E.fromArray(T,T.length-3),Uu(E,M,A),M.subVectors(E,P),M.toArray(p,m),A.toArray(g,m),P.toArray(_,m),E.toArray(y,m),h.atomColorToArray(R,v,m),b.push(R.index),x.push(d.atomRadius(R)),w.push(l+f),S.push(l+n+1-f),m+=3,f=n,O=!1}const N=new Float32Array(b);return{axis:new Float32Array(p),center:new Float32Array(g),begin:new Float32Array(_),end:new Float32Array(y),color:new Float32Array(v),picking:new Hd(N,a),size:new Float32Array(x),residueOffset:w,residueCount:S}}}class wm{constructor(e){this.scoreFunction=e,this.content=[],this.scoreFunction=e}push(e){this.content.push(e),this.bubbleUp(this.content.length-1)}pop(){const e=this.content[0],t=this.content.pop();return t&&this.content.length>0&&(this.content[0]=t,this.sinkDown(0)),e}peek(){return this.content[0]}remove(e){const t=this.content.length;for(let i=0;i0;){const i=Math.floor((e+1)/2)-1,n=this.content[i];if(!(this.scoreFunction(t), 2016 * @author Roman Bolzern , 2013 * @author I4DS http://www.fhnw.ch/i4ds, 2013 * @license MIT License * @description * k-d Tree for typed arrays of 3d points (e.g. for Float32Array), in-place * provides fast nearest neighbour search * * Based on https://github.com/ubilabs/kd-tree-javascript by Ubilabs * * Further information (including mathematical properties) * http://en.wikipedia.org/wiki/Binary_tree * http://en.wikipedia.org/wiki/K-d_tree * * @example * points: [x, y, z, x, y, z, x, y, z, ...] * metric: function(a, b){ * return Math.pow(a[0]-b[0], 2) + Math.pow(a[1]-b[1], 2) + Math.pow(a[2]-b[2], 2); * } * * @param {Float32Array} points - points * @param {Function} metric - metric */class Sm{constructor(e,t){this.points=e,this.metric=t,this.maxDepth=0,this.currentNode=0;const i=e.length/3,n=new Uint32Array(i);for(let e=0;ethis.maxDepth&&(this.maxDepth=e);const r=n-i;if(0===r)return-1;const s=4*this.currentNode,a=this.nodes;if(this.currentNode+=1,1===r)return a[s]=i,a[s+1]=-1,a[s+2]=-1,a[s+3]=t,s;const o=this.indices,l=this.points,c=i+Math.floor(r/2),u=e%3;let h,d,f,m,p,g=i,_=n-1;for(;_>g;){for(f=g+_>>1,m=l[3*o[f]+u],d=o[f],o[f]=o[_],o[_]=d,p=g,h=g;h<_;++h)l[3*o[h]+u]-e[1])),r=this.nodes,s=this.points,a=this.indices,o=l=>{let c,u;const h=this.getNodeDepth(l)%3,d=3*a[r[l]],f=[s[d+0],s[d+1],s[d+2]],m=this.metric(e,f);function p(e,i){n.push([e,i]),n.size()>t&&n.pop()}const g=r[l+1],_=r[l+2];if(-1===_&&-1===g)return void((n.size()s[3*a[r[e]]+n])throw new Error("left child is > parent!");i+=this.verify(o,t+1)}if(-1!==l){if(s[3*a[r[l]]+n]0}isBackbone(){const e=this.residueType.backboneIndexList;return e.length>0&&e.includes(this.index-this.residueAtomOffset)}isPolymer(){if(this.structure.entityList.length>0)return this.entity.isPolymer();{const e=this.residueType.moleculeType;return 3===e||4===e||5===e}}isSidechain(){return this.isPolymer()&&!this.isBackbone()}isCg(){const e=this.residueType.backboneType;return 4===e||5===e||6===e}isTrace(){return this.index===this.residueType.traceAtomIndex+this.residueAtomOffset}isHetero(){return 1===this.residueType.hetero}isProtein(){return 3===this.residueType.moleculeType}isNucleic(){const e=this.residueType.moleculeType;return 4===e||5===e}isRna(){return 4===this.residueType.moleculeType}isDna(){return 5===this.residueType.moleculeType}isWater(){return 1===this.residueType.moleculeType}isIon(){return 2===this.residueType.moleculeType}isSaccharide(){return 6===this.residueType.moleculeType}isHelix(){return Vh.includes(this.sstruc)}isSheet(){return $h.includes(this.sstruc)}isTurn(){return Gh.includes(this.sstruc)&&this.isProtein()}isBonded(){return 0!==this.bondHash.countArray[this.index]}isRing(){return void 0!==this.residueType.getRings().atomRings[this.index-this.residueAtomOffset]}isAromatic(){return 1===this.aromatic}isPolarHydrogen(){let e=!1;return 1!==this.number||(e=!this.hasBondToElement(6)),e}isMetal(){return this.atomType.isMetal()}isNonmetal(){return this.atomType.isNonmetal()}isMetalloid(){return this.atomType.isMetalloid()}isHalogen(){return this.atomType.isHalogen()}isDiatomicNonmetal(){return this.atomType.isDiatomicNonmetal()}isPolyatomicNonmetal(){return this.atomType.isPolyatomicNonmetal()}isAlkaliMetal(){return this.atomType.isAlkaliMetal()}isAlkalineEarthMetal(){return this.atomType.isAlkalineEarthMetal()}isNobleGas(){return this.atomType.isNobleGas()}isTransitionMetal(){return this.atomType.isTransitionMetal()}isPostTransitionMetal(){return this.atomType.isPostTransitionMetal()}isLanthanide(){return this.atomType.isLanthanide()}isActinide(){return this.atomType.isActinide()}getDefaultValence(){return this.atomType.getDefaultValence()}getValenceList(){return this.atomType.getValenceList()}getOuterShellElectronCount(){return this.atomType.getOuterShellElectronCount()}distanceTo(e){const t=this.atomStore,i=e.atomStore,n=this.index,r=e.index,s=t.x[n]-i.x[r],a=t.y[n]-i.y[r],o=t.z[n]-i.z[r],l=s*s+a*a+o*o;return Math.sqrt(l)}connectedTo(e){const t=this.atomStore,i=e.atomStore,n=this.index,r=e.index;if(t.altloc&&i.altloc){const e=t.altloc[n],s=i.altloc[r];if(0!==e&&0!==s&&32!==e&&32!==s&&e!==s)return!1}const s=t.x[n]-i.x[r],a=t.y[n]-i.y[r],o=t.z[n]-i.z[r],l=s*s+a*a+o*o;if(l<48&&this.isCg())return!0;if(isNaN(l))return!1;const c=this.covalent+e.covalent,u=c+.3,h=c-.5;return lh*h}positionFromArray(e,t=0){return this.x=e[t+0],this.y=e[t+1],this.z=e[t+2],this}positionToArray(e=[],t=0){const i=this.index,n=this.atomStore;return e[t+0]=n.x[i],e[t+1]=n.y[i],e[t+2]=n.z[i],e}positionToVector3(e){return void 0===e&&(e=new _t),e.x=this.x,e.y=this.y,e.z=this.z,e}positionFromVector3(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}positionAdd(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}positionSub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}getResidueBonds(e=!1){const t=this.residueAtomOffset,i=this.index-this.residueAtomOffset,n=this.residueType.getBonds(),r=n.atomIndices1,s=n.atomIndices2;let a,o,l,c;for(e||(c=[]),a=r.indexOf(i);-1!==a;){if(l=s[a]+t,!c)return l;c.push(l),a=r.indexOf(i,a+1)}for(o=s.indexOf(i);-1!==o;){if(l=r[o]+t,!c)return l;c.push(l),o=s.indexOf(i,o+1)}return c}qualifiedName(e=!1){var t="";return this.resname&&!e&&(t+="["+this.resname+"]"),void 0!==this.resno&&(t+=this.resno),this.inscode&&(t+="^"+this.inscode),this.chainname&&(t+=":"+this.chainname),this.atomname&&(t+="."+this.atomname),this.altloc&&(t+="%"+this.altloc),this.structure.modelStore.count>1&&(t+="/"+this.modelIndex),t}clone(){return new Mm(this.structure,this.index)}toObject(){return{index:this.index,residueIndex:this.residueIndex,resname:this.resname,x:this.x,y:this.y,z:this.z,element:this.element,chainname:this.chainname,resno:this.resno,serial:this.serial,vdw:this.vdw,covalent:this.covalent,hetero:this.hetero,bfactor:this.bfactor,altloc:this.altloc,atomname:this.atomname,modelIndex:this.modelIndex}}}function Am(e,t){const i=e[0]-t[0],n=e[1]-t[1],r=e[2]-t[2];return i*i+n*n+r*r}function Cm(e,t){return Math.sqrt(Am(e,t))}const Tm=new Float32Array(3);class Pm{constructor(t,i=!1){e.Debug&&Fl.time("Kdtree build");const n=i?Am:Cm,r=new Float32Array(3*t.atomCount),s=new Uint32Array(t.atomCount);let a=0;t.eachAtom((function(e){r[a+0]=e.x,r[a+1]=e.y,r[a+2]=e.z,s[a/3]=e.index,a+=3})),this.atomIndices=s,this.points=r,this.kdtree=new Sm(r,n),e.Debug&&Fl.timeEnd("Kdtree build")}nearest(e,t,i){e instanceof _t?e.toArray(Tm):e instanceof Mm&&e.positionToArray(Tm);const n=this.kdtree.nearest(Tm,t,i),r=this.kdtree.indices,s=this.kdtree.nodes,a=this.atomIndices,o=[];for(let e=0,t=n.length;e":"3/4-Z","?":"X-Y","@":"Y-X",A:"Z+1/3",B:"Z+2/3",C:"X+2/3",D:"Y+1/3",E:"-Y+2/3",F:"X-Y+1/3",G:"Y-X+2/3",H:"-X+1/3",I:"X+1/3",J:"Y+2/3",K:"-Y+1/3",L:"X-Y+2/3",M:"Y-X+1/3",N:"-X+2/3",O:"2/3+X",P:"1/3+Y",Q:"1/3+Z",R:"2/3-Y",S:"1/3+X-Y",T:"2/3+Y-X",U:"1/3-X",V:"2/3-X",W:"1/3-Y",X:"1/3-Z",Y:"2/3+Y",Z:"1/3+Y-X","[":"2/3+X-Y","]":"1/3+X","^":"2/3+Z",_:"2/3-Z","`":"5/6+Z",a:"1/6+Z",b:"5/6-Z",c:"1/6-Z",d:"Z+5/6",e:"Z+1/6",f:"Z+1/4",g:"+Y"},Im={"P 1":" !#","P -1":" !#$%&","P 1 2 1":" !#$!&","P 1 21 1":" !#$'&","C 1 2 1":" !#$!&()#*)&","P 1 m 1":" !# %#","P 1 c 1":" !# %+","C 1 m 1":" !# %#()#(,#","C 1 c 1":" !# %+()#(,+","P 1 2/m 1":" !# %#$!&$%&","P 1 21/m 1":" !#$)&$%& ,#","C 1 2/m 1":" !# %#$!&$%&()#(,#*)&*,&","P 1 2/c 1":" !#$!-$%& %+","P 1 21/c 1":" !#$%&$)- ,+","C 1 2/c 1":" !#$!-$%& %+()#*)-*,&(,+","P 2 2 2":" !#$%#$!& %&","P 2 2 21":" !#$%+$!- %&","P 21 21 2":" !#$%#*)&(,&","P 21 21 21":" !#*%+$)-(,&","C 2 2 21":" !#$%+$!- %&()#*,+*)-(,&","C 2 2 2":" !#$%#$!& %&()#*,#*)&(,&","F 2 2 2":" !#$%#$!& %& )+$,+$)- ,-(!+*%+*!-(%-()#*,#*)&(,&","I 2 2 2":" !#$%# %&$!&.'/01/.120'2","I 21 21 21":" !#*%+$)-(,&()+$,#*!& %-","P m m 2":" !#$%# %#$!#","P m c 21":" !#$%+ %+$!#","P c c 2":" !#$%# %+$!+","P m a 2":" !#$%#(%#*!#","P c a 21":" !#$%+(%#*!+","P n c 2":" !#$%# ,+$)+","P m n 21":" !#*%+(%+$!#","P b a 2":" !#$%#(,#*)#","P n a 21":" !#$%+(,#*)+","P n n 2":" !#$%#(,+*)+","C m m 2":" !#$%# %#$!#()#*,#(,#*)#","C m c 21":" !#$%+ %+$!#()#*,+(,+*)#","C c c 2":" !#$%# %+$!+()#*,#(,+*)+","A m m 2":" !#$%# %#$!# )+$,+ ,+$)+","A b m 2":" !#$%# ,#$)# )+$,+ %+$!+","A m a 2":" !#$%#(%#*!# )+$,+(,+*)+","A b a 2":" !#$%#(,#*)# )+$,+(%+*!+","F m m 2":" !#$%# %#$!# )+$,+ ,+$)+(!+*%+(%+*!+()#*,#(,#*)#","F d d 2":" !#$%#345675 )+$,+3896:9(!+*%+;49<79()#*,#;85<:5","I m m 2":" !#$%# %#$!#()+*,+(,+*)+","I b a 2":" !#$%#(,#*)#()+*,+ %+$!+","I m a 2":" !#$%#(%#*!#()+*,+ ,+$)+","P 2/m 2/m 2/m":" !#$%#$!& %&$%& !& %#$!#","P 2/n 2/n 2/n":" !#$%#$!& %&*,-()-(,+*)+","P 2/c 2/c 2/m":" !#$%#$!- %-$%& !& %+$!+","P 2/b 2/a 2/n":" !#$%#$!& %&*,&()&(,#*)#","P 21/m 2/m 2/a":" !#*%#$!&(%&$%&(!& %#*!#","P 2/n 21/n 2/a":" !#*%#*)- ,-$%&(!&(,+$)+","P 2/m 2/n 21/a":" !#*%+*!- %&$%&(!-(%+$!#","P 21/c 2/c 2/a":" !#*%#$!-(%-$%&(!& %+*!+","P 21/b 21/a 2/m":" !#$%#*)&(,&$%& !&(,#*)#","P 21/c 21/c 2/n":" !#*,#$)-(%-$%&()& ,+*!+","P 2/b 21/c 21/m":" !#$%+$)- ,&$%& !- ,+$)#","P 21/n 21/n 2/m":" !#$%#*)-(,-$%& !&(,+*)+","P 21/m 21/m 2/n":" !#$%#*'&.,&*,&.'& %#$!#","P 21/b 2/c 21/n":" !#*,+$!-(,&$%&()- %+*)#","P 21/b 21/c 21/a":" !#*%+$)-(,&$%&(!- ,+*)#","P 21/n 21/m 21/a":" !#0%/$'&.12$%&.!2 1#0'/","C 2/m 2/c 21/m":" !#$%+$!- %&$%& !- %+$!#()#*,+*)-(,&*,&()-(,+*)#","C 2/m 2/c 21/a":" !#$,+$)- %&$%& )- ,+$!#()#*%+*!-(,&*,&(!-(%+*)#","C 2/m 2/m 2/m":" !#$%#$!& %&$%& !& %#$!#()#*,#*)&(,&*,&()&(,#*)#","C 2/c 2/c 2/m":" !#$%#$!- %-$%& !& %+$!+()#*,#*)-(,-*,&()&(,+*)+","C 2/m 2/m 2/a":" !#$,#$)& %&$%& )& ,#$!#()#*%#*!&(,&*,&(!&(%#*)#","C 2/c 2/c 2/a":" !#*,#$!&(,&$,-(!- ,+*!+()#$%#*)& %&*%- )-(%+$)+","F 2/m 2/m 2/m":" !#$%#$!& %&$%& !& %#$!# )+$,+$)- ,-$,- )- ,+$)+(!+*%+*!-(%-*%-(!-(%+*!+()#*,#*)&(,&*,&()&(,#*)#","F 2/d 2/d 2/d":" !#$%#$!& %&64=37=345675 )+$,+$)- ,-68>3:>3896:9(!+*%+*!-(%-<4>;7>;49<79()#*,#*)&(,&<8=;:=;85<:5","I 2/m 2/m 2/m":" !#$%#$!& %&$%& !& %#$!#()+*,+*)-(,-*,-()-(,+*)+","I 2/b 2/a 2/m":" !#$%#*)&(,&$%& !&(,#*)#()+*,+$!- %-*,-()- %+$!+","I 21/b 21/c 21/a":" !#*%+$)-(,&$%&(!- ,+*)#()+$,#*!& %-*,- )&(%#$!+","I 21/m 21/m 21/a":" !#$,#$)& %&$%& )& ,#$!#()+*%+*!-(,-*,-(!-(%+*)+","P 4":" !#$%#% #!$#","P 41":" !#$%+% 5!$9","P 42":" !#$%#% +!$+","P 43":" !#$%+% 9!$5","I 4":" !#$%#% #!$#()+*,+,(+)*+","I 41":" !#*,+%(5)$9()+$%#, 9!*5","P -4":" !#$%#!$&% &","I -4":" !#$%#!$&% &()+*,+)*-,(-","P 4/m":" !#$%#% #!$#$%& !&!$&% &","P 42/m":" !#$%#% +!$+$%& !&!$-% -","P 4/n":" !#$%#,(#)*#*,&()&!$&% &","P 42/n":" !#$%#,(+)*+*,-()-!$&% &","I 4/m":" !#$%#% #!$#$%& !&!$&% &()+*,+,(+)*+*,-()-)*-,(-","I 41/a":" !#*,+%(5)$9$,=(!>!$&,(-()+$%#, 9!*5*%> )=)*-% &","P 4 2 2":" !#$%#% #!$#$!& %&! &%$&","P 4 21 2":" !#$%#,(#)*#*)&(,&! &%$&","P 41 2 2":" !#$%+% 5!$9$!& %-! >%$=","P 41 21 2":" !#$%+,(5)*9*)=(,>! &%$-","P 42 2 2":" !#$%#% +!$+$!& %&! -%$-","P 42 21 2":" !#$%#,(+)*+*)-(,-! &%$&","P 43 2 2":" !#$%+% 9!$5$!& %-! =%$>","P 43 21 2":" !#$%+,(9)*5*)>(,=! &%$-","I 4 2 2":" !#$%#% #!$#$!& %&! &%$&()+*,+,(+)*+*)-(,-)(-,*-","I 41 2 2":" !#*,+%(5)$9*!> ,=)(-%$&()+$%#, 9!*5$)=(%>! &,*-","P 4 m m":" !#$%#% #!$# %#$!#%$#! #","P 4 b m":" !#$%#% #!$#(,#*)#,*#)(#","P 42 c m":" !#$%#% +!$+ %+$!+%$#! #","P 42 n m":" !#$%#,(+)*+(,+*)+%$#! #","P 4 c c":" !#$%#% #!$# %+$!+%$+! +","P 4 n c":" !#$%#% #!$#(,+*)+,*+)(+","P 42 m c":" !#$%#% +!$+ %#$!#%$+! +","P 42 b c":" !#$%#% +!$+(,#*)#,*+)(+","I 4 m m":" !#$%#% #!$# %#$!#%$#! #()+*,+,(+)*+(,+*)+,*+)(+","I 4 c m":" !#$%#% #!$# %+$!+%$+! +()+*,+,(+)*+(,#*)#,*#)(#","I 41 m d":" !#*,+%(5)$9 %#*)+%*5) 9()+$%#, 9!*5(,+$!#,$9!(5","I 41 c d":" !#*,+%(5)$9 %+*)#%*9) 5()+$%#, 9!*5(,#$!+,$5!(9","P -4 2 m":" !#$%#% &!$&$!& %&%$#! #","P -4 2 c":" !#$%#% &!$&$!- %-%$+! +","P -4 21 m":" !#$%#% &!$&*)&(,&,*#)(#","P -4 21 c":" !#$%#% &!$&*)-(,-,*+)(+","P -4 m 2":" !#$%#!$&% & %#$!#! &%$&","P -4 c 2":" !#$%#% &!$& %+$!+! -%$-","P -4 b 2":" !#$%#% &!$&(,#*)#)(&,*&","P -4 n 2":" !#$%#% &!$&(,+*)+)(-,*-","I -4 m 2":" !#$%#% &!$& %#$!#! &%$&()+*,+,(-)*-(,+*)+)(-,*-","I -4 c 2":" !#$%#% &!$& %+$!+! -%$-()+*,+,(-)*-(,#*)#)(&,*&","I -4 2 m":" !#$%#% &!$&$!& %&%$#! #()+*,+,(-)*-*)-(,-,*+)(+","I -4 2 d":" !#$%#% &!$&*!>(%>,$9) 9()+*,+,(-)*-$)= ,=%*5!(5","P 4/m 2/m 2/m":" !#$%#% #!$#$!& %&! &%$&$%& !&!$&% & %#$!#%$#! #","P 4/m 2/c 2/c":" !#$%#% #!$#$!- %-! -%$-$%& !&!$&% & %+$!+%$+! +","P 4/n 2/b 2/m":" !#$%#% #!$#$!& %&! &%$&*,&()&)*&,(&(,#*)#,*#)(#","P 4/n 2/n 2/c":" !#$%#% #!$#$!& %&! &%$&*,-()-)*-,(-(,+*)+,*+)(+","P 4/m 21/b 2/m":" !#$%#% #!$#*)&(,&)(&,*&$%& !&!$&% &(,#*)#,*#)(#","P 4/m 21/n 2/c":" !#$%#% #!$#*)-(,-)(-,*-$%& !&!$&% &(,+*)+,*+)(+","P 4/n 21/m 2/m":" !#$%#,(#)*#*)&(,&! &%$&*,&()&!$&% & %#$!#,*#)(#","P 4/n 2/c 2/c":" !#$%#,(#)*#*)-(,-! -%$-*,&()&!$&% & %+$!+,*+)(+","P 42/m 2/m 2/c":" !#$%#% +!$+$!& %&! -%$-$%& !&!$-% - %#$!#%$+! +","P 42/m 2/c 2/m":" !#$%#% +!$+$!- %-! &%$&$%& !&!$-% - %+$!+%$#! #","P 42/n 2/b 2/c":" !#$%#,(+)*+$!- %-)(&,*&*,-()-!$&% &(,#*)#%$+! +","P 42/n 2/n 2/m":" !#$%#,(+)*+$!& %&)(-,*-*,-()-!$&% &(,+*)+%$#! #","P 42/m 21/b 2/c":" !#$%#% +!$+*)&(,&)(-,*-$%& !&!$-% -(,#*)#,*+)(+","P 42/m 21/n 2/m":" !#$%#,./'*/*'-.,-! &%$&$%& !&'*-,.-.,/*'/%$#! #","P 42/n 21/m 2/c":" !#$%#,(+)*+*)-(,-! &%$&*,-()-!$&% & %#$!#,*+)(+","P 42/n 21/c 2/m":" !#$%#,(+)*+*)&(,&! -%$-*,-()-!$&% & %+$!+,*#)(#","I 4/m 2/m 2/m":" !#$%#% #!$#$!& %&! &%$&$%& !&!$&% & %#$!#%$#! #()+*,+,(+)*+*)-(,-)(-,*-*,-()-)*-,(-(,+*)+,*+)(+","I 4/m 2/c 2/m":" !#$%#% #!$#$!- %-! -%$-$%& !&!$&% & %+$!+%$+! +()+*,+,(+)*+*)&(,&)(&,*&*,-()-)*-,(-(,#*)#,*#)(#","I 41/a 2/m 2/d":" !#*,+%(5)$9*!> ,=)(-%$&$,=(!>!$&,(-(,+$!#,$9!(5()+$%#, 9!*5$)=(%>! &,*-*%> )=)*-% & %#*)+%*5) 9","I 41/a 2/c 2/d":" !#*,+%(5)$9*!= ,>)(&%$-$,=(!>!$&,(-(,#$!+,$5!(9()+$%#, 9!*5$)>(%=! -,*&*%> )=)*-% & %+*)#%*9) 5","P 3":" !#%?#@$#","P 31":" !#%?A@$B","P 32":" !#%?B@$A","H 3":" !#%?#@$#CDAEFAGHAIJBKLBMNB","R 3":" !## !!# ","P -3":" !#%?#@$#$%&!@&? &","H -3":" !#%?#@$#$%&!@&? &OPQRSQTUQVWXYZX[]X]Y^W[^ZV^UR_PT_SO_","R -3":" !## !!# $%&&$%%&$","P 3 1 2":" !#%?#@$#%$&@!& ?&","P 3 2 1":" !#%?#@$#! &?%&$@&","P 31 1 2":" !#%?Q@$^%$_@!X ?&","P 31 2 1":" !#%?A@$B! &?%_$@X","P 32 1 2":" !#%?^@$Q%$X@!_ ?&","P 32 2 1":" !#%?B@$A! &?%X$@_","H 3 2":" !#%?#@$#! &?%&$@&OPQRSQTUQY]X[WXVZX]Y^W[^ZV^PO_SR_UT_","R 3 2":" !## !!# %$&$&%&%$","P 3 m 1":" !#%?#@$#%$#@!# ?#","P 3 1 m":" !#%?#@$#! #?%#$@#","P 3 c 1":" !#%?#@$#%$+@!+ ?+","P 3 1 c":" !#%?#@$#! +?%+$@+","H 3 m":" !#%?#@$#%$#@!# ?#OPQRSQTUQRUQTPQOSQ]Y^W[^ZV^WV^ZY^][^","R 3 m":" !## !!# ! # #!#! ","H 3 c":" !#%?#@$#%$+@!+ ?+OPQRSQTUQRU`TP`OS`]Y^W[^ZV^WVaZYa][a","R 3 c":" !## !!# '././'/'.","P -3 1 2/m":" !#%?#@$#%$&@!& ?&$%&!@&? &! #?%#$@#","P -3 1 2/c":" !#%?#@$#%$-@!- ?-$%&!@&? &! +?%+$@+","P -3 2/m 1":" !#%?#@$#! &?%&$@&$%&!@&? &%$#@!# ?#","P -3 2/c 1":" !#%?#@$#! -?%-$@-$%&!@&? &%$+@!+ ?+","H -3 2/m":" !#%?#@$#! &?%&$@&$%&!@&? &%$#@!# ?#OPQRSQTUQY]X[WXVZXVWXYZX[]XRUQTPQOSQ]Y^W[^ZV^PO_SR_UT_UR_PT_SO_WV^ZY^][^","R -3 2/m":" !## !!# %$&$&%&%$$%&&$%%&$! # #!#! ","H -3 2/c":" !#%?#@$#! -?%-$@-$%&!@&? &%$+@!+ ?+OPQRSQTUQY]b[WbVZbVWXYZX[]XRU`TP`OS`]Y^W[^ZV^POcSRcUTcUR_PT_SO_WVaZYa][a","R -3 2/c":" !## !!# 102021210$%&&$%%&$'././'/'.","P 6":" !#%?#@$#$%#!@#? #","P 61":" !#%?A@$B$%/!@d? e","P 65":" !#%?B@$A$%/!@e? d","P 62":" !#%?^@$Q$%#!@^? Q","P 64":" !#%?Q@$^$%#!@Q? ^","P 63":" !#%?#@$#$%+!@+? +","P -6":" !#%?#@$# !&%?&@$&","P 6/m":" !#%?#@$#$%#!@#? #$%&!@&? & !&%?&@$&","P 63/m":" !#%?#@$#$%+!@+? +$%&!@&? & !-%?-@$-","P 6 2 2":" !#%?#@$#$%#!@#? #! &?%&$@&%$&@!& ?&","P 61 2 2":" !#%?Q@$^$%+!@`? a! X?%&$@_%$b@!- ?c","P 65 2 2":" !#%?^@$Q$%+!@a? `! _?%&$@X%$c@!- ?b","P 62 2 2":" !#%?^@$Q$%#!@^? Q! _?%&$@X%$_@!& ?X","P 64 2 2":" !#%?Q@$^$%#!@Q? ^! X?%&$@_%$X@!& ?_","P 63 2 2":" !#%?#@$#$%+!@+? +! &?%&$@&%$-@!- ?-","P 6 m m":" !#%?#@$#$%#!@#? #%$#@!# ?#! #?%#$@#","P 6 c c":" !#%?#@$#$%#!@#? #%$+@!+ ?+! +?%+$@+","P 63 c m":" !#%?#@$#$%+!@+? +%$+@!+ ?+! #?%#$@#","P 63 m c":" !#%?#@$#$%+!@+? +%$#@!# ?#! +?%+$@+","P -6 m 2":" !#%?#@$# !&%?&@$&%$#@!# ?#%$&@!& ?&","P -6 c 2":" !#%?#@$# !-%?-@$-%$+@!+ ?+%$&@!& ?&","P -6 2 m":" !#%?#@$# !&%?&@$&! &?%&$@&! #?%#$@#","P -6 2 c":" !#%?#@$# !-%?-@$-! &?%&$@&! +?%+$@+","P 6/m 2/m 2/m":" !#%?#@$#$%#!@#? #! &?%&$@&%$&@!& ?&$%&!@&? & !&@$&%?&%$#@!# ?#! #?%#$@#","P 6/m 2/c 2/c":" !#%?#@$#$%#!@#? #! -?%-$@-%$-@!- ?-$%&!@&? & !&@$&%?&%$+@!+ ?+! +?%+$@+","P 63/m 2/c 2/m":" !#%?#@$#$%+!@+? +! -?%-$@-%$&@!& ?&$%&!@&? & !-@$-%?-%$+@!+ ?+! #?%#$@#","P 63/m 2/m 2/c":" !#%?#@$#$%+!@+? +! &?%&$@&%$-@!- ?-$%&!@&? & !-@$-%?-%$#@!# ?#! +?%+$@+","P 2 3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ","F 2 3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-((!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- ","I 2 3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-(","P 21 3":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(","I 21 3":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(()+$,#*!& %-+()#$,&*!- %)+(,#$!&*%- ","P 2/m -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& $%& !& %#$!#&$%& !# %#$!%&$!& %# !#$","P 2/n -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& *,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*","F 2/m -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& $%& !& %#$!#&$%& !# %#$!%&$!& %# !#$ )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-($,- )- ,+$)+&*,&()#(,#*)%-*!-(%+(!+*(!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(*%-(!-(%+*!+-$,- )+ ,+$),&*)&(,#()#*()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- *,&()&(,#*)#-*%-(!+(%+*!,-$)- ,+ )+$","F 2/d -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& 64=37=345675=64=375345674=67=3453756 )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-(68>3:>3896:9=<8=;:5;85<:4><7>;49;79<(!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(<4>;7>;49<79>68>3:93896:8=<:=;85;:5<()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- <8=;:=;8f<:f><4>;79;49<78>6:>3893:96","I 2/m -3":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& $%& !& %#$!#&$%& !# %#$!%&$!& %# !#$()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-(*,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*","P 21/a -3":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&($%&(!- ,+*)#&$%-(!+ ,#*)%&$!-(,+ )#*","I 21/a -3":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&($%&(!- ,+*)#&$%-(!+ ,#*)%&$!-(,+ )#*()+$,#*g& %-+()#$,&*!- %)+(,#$!&*%- *,- )&(%#$!+-*,& )#(%+$!,-*)& %#(!+$","P 4 3 2":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$","P 42 3 2":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,*","F 4 3 2":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$ )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-(!(-%*-!*+%(+ +,$+)$-, -)#)*#,(&)(&,*(!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&() -,$-)$+, +(#,*#)*&,(&)+!*+%(-!(-%*()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- )(&,*&)*#,(#(+%*+!*-%(-!+)$+, -) -,$","F 41 3 2":" !#$,+*)&(%-# !+$,&*)-(%!# ,+$)&*%-(:3>46=7<98;5;58<976=43>:97<58;>:3=46 )+$%#*!-(,&#()+*%&$!- ,!+(,#*)-$%& :;=4<>765839;94<5:6>83=79:6543>7;=8<(!+*,#$)- %&+ )#$%-*!&(,)#(%+*!&$,- 73=86>:<54;935469:<=8;>7576983=:;>4<()#*%+$!& ,-+(!#*,-$)& %)+ %#$!-*,&(7;>8<=:69435398657<>4;=:5:<94;=73>86","I 4 3 2":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-()(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,*","P 43 3 2":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(7;>46=:<5839398<5:6=4;>75:<983>7;=46","P 41 3 2":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(:3=8<>7694;5;54697<>83=:97654;=:3>8<","I 41 3 2":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(:3=8<>7694;5;54697<>83=:97654;=:3>8<()+$,#*!& %-+()#$,&*!- %)+(,#$!&*%- 7;>46=:<5839398<5:6=4;>75:<983>7;=46","P -4 3 m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! #%$#!$&% & #!$#%$&! &%#! #%$&!$&% ","F -4 3 m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! #%$#!$&% & #!$#%$&! &%#! #%$&!$&% )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-(!(+%*+!*-%(- +)$+,$-) -,#)(#,*&)*&,((!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&() +,$+)$-, -(#)*#,*&)(&,+!(+%*-!*-%(()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- )(#,*#)*&,(&(+!*+%*-!(-%+) +,$-)$-, ","I -4 3 m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! #%$#!$&% & #!$#%$&! &%#! #%$&!$&% ()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-()(+,*+)*-,(-(+)*+,*-)(-,+)(+,*-)*-,(","P -4 3 n":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(+,*+)*-,(-(+)*+,*-)(-,+)(+,*-)*-,(","F -4 3 c":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(+,*+)*-,(-(+)*+,*-)(-,+)(+,*-)*-,( )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-() #,$#)$&, &(#!*#%*&!(&%+! +%$-!$-% (!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(!(#%*#!*&%(& +!$+%$-! -%#) #,$&)$&, ()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- ! +%$+!$-% - #)$#,$&) &,#!(#%*&!*&%(","I -4 3 d":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(7354<9:6>8;=357<946>:;=857394<>:6=8;()+$,#*!& %-+()#$,&*!- %)+(,#$!&*%- :;98657<=43>;9:658<=73>49:;586=7<>43","P 4/m -3 2/m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$%$#! #% &!$&$&! &% #!$#%&% &!$#%$#! ","P 4/n -3 2/n":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$*,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*,*+)(+,(-)*-*-)(-,(+)*+,-,(-)*+,*+)(","P 42/m -3 2/n":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,*$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$,*+)(+,(-)*-*-)(-,(+)*+,-,(-)*+,*+)(","P 42/n -3 2/m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,**,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*%$#! #% &!$&$&! &% #!$#%&% &!$#%$#! ","F 4/m -3 2/m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$%$#! #% &!$&$&! &% #!$#%&% &!$#%$#! )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-(!(-%*-!*+%(+ +,$+)$-, -)#)*#,(&)(&,*$,- )- ,+$)+&*,&()#(,#*)%-*!-(%+(!+*%*+!(+%(-!*-$-) -, +)$+,&,(&)*#,*#)((!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&() -,$-)$+, +(#,*#)*&,(&)+!*+%(-!(-%**%-(!-(%+*!+-$,- )+ ,+$),&*)&(,#()#*,$+) +, -)$-*&)(&,(#)*#,-%(-!*+%*+!(()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- )(&,*&)*#,(#(+%*+!*-%(-!+)$+, -) -,$*,&()&(,#*)#-*%-(!+(%+*!,-$)- ,+ )+$,*#)(#,(&)*&*-!(-%(+!*+%-, -)$+,$+) ","F 4/m -3 2/c":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& )(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,*$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$,*+)(+,(-)*-*-)(-,(+)*+,-,(-)*+,*+)( )+$,+$)- ,-#()#*,&*)&(,!+(%+*!-*%-() &,$&)$#, #(#%*#!*&%(&!+!$+% -! -%$$,- )- ,+$)+&*,&()#(,#*)%-*!-(%+(!+*,$#) #, &)$&*&!(&%(#!*#%-% -!$+%$+! (!+*%+*!-(%-+ )+$,-$)- ,)#(,#*)&*,&(!(&%*&!*#%(# +%$+!$-% -!#)$#, &) &,$*%-(!-(%+*!+-$,- )+ ,+$),&*)&(,#()#*%*#!(#%(&!*&$-! -% +!$+%&, &)$#,$#) ()#*,#*)&(,&+(!+*%-*!-(%)+ ,+$)-$,- ! -%$-!$+% + #,$#)$&, &)#!*#%(&!(&%**,&()&(,#*)#-*%-(!+(%+*!,-$)- ,+ )+$%$+! +% -!$-$&) &, #)$#,&%(&!*#%*#!(","F 41/d -3 2/m":" !#$,+*)&(%-# !+$,&*)-(%!# ,+$)&*%-(:3>46=7<98;5;58<976=43>:97<58;>:3=4664=3:>;85<79=64>3:5;89<74=6:>385;79<,$+! #%(-)*&*&)(-% #!$+,-%(&)*+,$#! )+$%#*!-(,&#()+*%&$!- ,!+(,#*)-$%& :;=4<>765839;94<5:6>83=79:6543>7;=8<68>37=;49<:5=<8>;753496:4><:=;893756,*#!(+% &)$-*-!(&, +)$#%-, &!$+%*#)((!+*,#$)- %&+ )#$%-*!&(,)#(%+*!&$,- 73=86>:<54;935469:<=8;>7576983=:;>4<<4>;:=389675>68=379;45<:8=<7>;453:96%$#) +,(&!*-$&! -,(#)*+%&% -)$#,*+!(()#*%+$!& ,-+(!#*,-$)& %)+ %#$!-*,&(7;>8<=:69435398657<>4;=:5:<94;=73>86<8=;7>3456:9><4=;:9385678>67=349;:5<%*+)(#, -!$&$-) &%(+!*#,&,(-!*#%$+) ","F 41/d -3 2/c":" !#$,+*)&(%-# !+$,&*)-(%!# ,+$)&*%-(:3>46=7<98;5;58<976=43>:97<58;>:3=46<8>;7=3496:5><8=;793456:8><7=;493:56%*#)(+, &!$-$-! &,(+)*#%&, -!$#%*+)( )+$%#*!-(,&#()+*%&$!- ,!+(,#*)-$%& :;=4<>765839;94<5:6>83=79:6543>7;=8<<4=;:>385679>64=3:9;85<78=67>345;:9<%$+) #,(-!*&$&) -%(#!*+,&%(-)*#,$+! (!+*,#$)- %&+ )#$%-*!&(,)#(%+*!&$,- 73=86>:<54;935469:<=8;>7576983=:;>4<68=37>;45<:9=<4>;:5389674>6:=389;75<,*+!(#% -)$&*-)(&% +!$#,-,(&!*+%$#) ()#*%+$!& ,-+(!#*,-$)& %)+ %#$!-*,&(7;>8<=:69435398657<>4;=:5:<94;=73>8664>3:=;89<75=68>375;49<:4=<:>;853796,$#! +%(&)*-*&!(-, #)$+%-% &)$+,*#!(","I 4/m -3 2/m":" !#$%#$!& %&# !#$%&$!& %!# %#$!&$%& ! &%$&!$#% # #%$#!$&% &!#!$#% &! &%$$%& !& %#$!#&$%& !# %#$!%&$!& %# !#$%$#! #% &!$&$&! &% #!$#%&% &!$#%$#! ()+*,+*)-(,-+()+*,-*)-(,)+(,+*)-*,-()(-,*-)*+,(+(+,*+)*-,(-)+)*+,(-)(-,**,-()-(,+*)+-*,-()+(,+*),-*)-(,+()+*,*+)(+,(-)*-*-)(-,(+)*+,-,(-)*+,*+)(","I 41/a -3 2/d":" !#*%+$)-(,&# !+*%-$)&(,!# %+*)-$,&(:3=8<>7694;5;54697<>83=:97654;=:3>8<$%&(!- ,+*)#&$%-(!+ ,#*)%&$!-(,+ )#*4<97358;=:6>6>:;=8357<94=8;>:694<573()+$,#*!& %-+()#$,&*!- %)+(,#$!&*%- 7;>46=:<5839398<5:6=4;>75:<983>7;=46*,- )&(%#$!+-*,& )#(%+$!,-*)& %#(!+$865:;943>7<=<=73>4;9:658>43=7<5869:;","P 1 1 2":" !#$%#","P 1 1 21":" !#$%+","B 1 1 2":" !#$%#(g+*%+","A 1 2 1":" !#$!& )+$)-","C 1 21 1":" !#$)&()#*!&","I 1 2 1":" !#$!&.'/0'2","I 1 21 1":" !#$)&.'/0!-","P 1 1 m":" !# !&","P 1 1 b":" !# )&","B 1 1 m":" !# !&(!+(!-","B 1 1 b":" !# )&(!+()-","P 1 1 2/m":" !# !&$%#$%&","P 1 1 21/m":" !#$%+$%& !-","B 1 1 2/m":" !# !&$%#$%&(!+(!-*%+*%-","P 1 1 2/b":" !#$,#$%& )&","P 1 1 21/b":" !#$%&$,+ )-","B 1 1 2/b":" !#$,#$%& )&(!+*,+*%-()-","P 21 2 2":" !#$!&(%&*%#","P 2 21 2":" !# ,&$)&$%#","P 21 21 2 (a)":" !#*,#.%&$'&","P 21 2 21":" !#$!&(%-*%+","P 2 21 21":" !# %&$)-$,+","C 2 2 21a)":" !#*%+(,&$)-()#$,+ %&*!-","C 2 2 2a":" !#*,#.%&$'&()#$%# ,&*!&","F 2 2 2a":" !#*,#.%&$'& '/*%/.12$!2.!/$,/ %20'2.'#$%# 1&0!&","I 2 2 2a":" !#*,#.%&$'&()+$%+*!- ,-","P 21/m 21/m 2/n a":" !#*,#$)&(%&$%&.'& ,#*!#","P 42 21 2a":" !#*,#%.+'$+$'&.%&! -,*-","I 2 3a":" !#*,#.%&$'&!# ,- '&$%/$# !-*!/$%&.%()+$%+ ,-*!-)+(%&(!-*,#*+()&$)#*,- ,"},Dm=/^[1-9]$/;function Rm(e){let t="";return e.length>0&&(t=":"+bo(e).join(" OR :")),new wl(t)}class Lm{constructor(e=""){this.name=e,this.partList=[]}get type(){return"Assembly"}addPart(e,t){const i=new km(e,t);return this.partList.push(i),i}getAtomCount(e){return this.partList.reduce(((t,i)=>t+i.getAtomCount(e)),0)}getResidueCount(e){return this.partList.reduce(((t,i)=>t+i.getResidueCount(e)),0)}getInstanceCount(){let e=0;return this.partList.forEach((function(t){e+=t.matrixList.length})),e}isIdentity(e){if(1!==this.partList.length)return!1;const t=this.partList[0];if(1!==t.matrixList.length)return!1;if(!(new qt).equals(t.matrixList[0]))return!1;let i=[];return e.eachChain((function(e){i.push(e.chainname)})),i=bo(i),t.chainList.length===i.length}getBoundingBox(e){const t=new bt;return this.partList.forEach((function(i){const n=i.getBoundingBox(e);t.expandByPoint(n.min),t.expandByPoint(n.max)})),t}getCenter(e){return this.getBoundingBox(e).getCenter(new _t)}getSelection(){let e=[];return this.partList.forEach((function(t){e=e.concat(t.chainList)})),Rm(e)}}class km{constructor(e=[],t=[]){this.matrixList=e,this.chainList=t}get type(){return"AssemblyPart"}_getCount(e,t){let i=0;return e.eachChain((e=>{(0===this.chainList.length||this.chainList.includes(e.chainname))&&(i+=e[t])})),this.matrixList.length*i}getAtomCount(e){return this._getCount(e,"atomCount")}getResidueCount(e){return this._getCount(e,"residueCount")}getBoundingBox(e){const t=new bt,i=new bt,n=this.getSelection(),r=e.getBoundingBox(n);return this.matrixList.forEach((function(e){i.copy(r).applyMatrix4(e),t.expandByPoint(i.min),t.expandByPoint(i.max)})),t}getSelection(){return Rm(this.chainList)}getView(e){const t=this.getSelection();return t?e.getView(t):e}getInstanceList(){const e=[];for(let t=0,i=this.matrixList.length;t0&&this.addResidueType(this.ri-1),c.growIfFull(),c.resno[this.ri]=r,void 0!==a&&(c.sstruc[this.ri]=a.charCodeAt(0)),void 0!==o&&(c.inscode[this.ri]=o.charCodeAt(0)),c.atomOffset[this.ri]=this.ai,c.atomCount[this.ri]=0,c.count+=1,c.chainIndex[this.ri]=this.ci,u.residueCount[this.ci]+=1),l.count+=1,l.residueIndex[this.ai]=this.ri,c.atomCount[this.ri]+=1,this.currentModelindex=e,this.currentChainid=i,this.currentResname=n,this.currentResno=r,this.currentInscode=o,this.currentHetero=s}finalize(){this.previousResname=this.currentResname,this.previousHetero=this.currentHetero,this.ri>-1&&this.addResidueType(this.ri)}}function Nm(t,i){if(!i)return;e.Debug&&Fl.time("assignSecondaryStructure");const n=[];t.eachModel((function(e){e.eachChain((function(e){n.push(e.chainname)}))}));const r=n.slice().sort(),s=[];r.forEach((function(e){s.push(n.indexOf(e))}));const a=i.helices.filter((function(e){return yo(r,e[0])>=0}));a.sort((function(e,t){const i=e[0],n=t[0],a=e[1],o=t[1];if(i===n)return a===o?0:a=0}));l.sort((function(e,t){const i=e[0],n=t[0];if(i===n)return 0;const a=yo(r,i),o=yo(r,n);return s[a]=e.residueCount)continue;a.index=s+r,o.index=s+r+t,l.index=a.traceAtomIndex,c.index=o.traceAtomIndex;const u=l.distanceTo(c);if(Math.abs(u-i[t-2])>n)return!1}return!0},i=function(e,i){return t(e,i,[5.45,5.18,6.37],2.1)},n=function(e,i){return t(e,i,[6.1,10.4,13],1.42)};return function(t){e.Debug&&Fl.time("calculateSecondaryStructure"),t.eachPolymer((function(e){if(e.residueCount<4)return;if(e.isCg())!function(e){const t=e.residueStore,i=e.residueIndexStart,n=new xm(e).position,r=new _t,s=new _t;for(let a=0,o=e.residueCount;a1&&n.bending[a]<20&&(t.sstruc[i+a]="h".charCodeAt(0),t.sstruc[i+a+1]="h".charCodeAt(0))}}(e);else{if(!e.isProtein())return;!function(e){const t=e.residueStore,r=e.residueIndexStart;for(let s=0,a=e.residueCount;s=t;)i=Math.floor(i/t),r+=Bm[i%t],n+=1;return n>=5&&Fl.warn("chainname overflow"),r}function Um(t,i=!1){e.Debug&&Fl.time("calculateChainnames");let n=!0;if(t.eachChain((function(e){e.chainname&&(n=!1)})),n){const e=t.modelStore,n=t.chainStore,r=t.residueStore,s=function(t,i,s,a){const o=n.count;for(let e=0;e{h.add(t),e.forEach((e=>{h.add(e)}))}))),t.eachResidue((function(e){if(!i&&u){const t=e.atomCount,i=e.atomOffset;if(t>500)return void Fl.warn("more than 500 atoms, skip residue for auto-bonding",e.qualifiedName());if("auto"===n&&e.hetero)for(let t=e.atomOffset;t{h.forEach((i=>{e.push(t.clone().multiply(i))}))})),c.addPart(e)}else c.addPart(u);const d=new _t,f=new Lm("SUPERCELL"),m=Array.prototype.concat.call(l(d.set(1,0,0)),l(d.set(0,1,0)),l(d.set(0,0,1)),l(d.set(-1,0,0)),l(d.set(0,-1,0)),l(d.set(0,0,-1)),l(d.set(1,1,0)),l(d.set(1,0,1)),l(d.set(0,1,1)),l(d.set(-1,-1,0)),l(d.set(-1,0,-1)),l(d.set(0,-1,-1)),l(d.set(1,-1,-1)),l(d.set(1,1,-1)),l(d.set(1,-1,1)),l(d.set(-1,1,1)),l(d.set(-1,-1,1)),l(d.set(-1,1,-1)),l(d.set(0,1,-1)),l(d.set(0,-1,1)),l(d.set(1,0,-1)),l(d.set(-1,0,1)),l(d.set(1,-1,0)),l(d.set(-1,1,0)),l(),l(d.set(1,1,1)),l(d.set(-1,-1,-1)));if(t.biomolDict.NCS){const e=[];m.forEach((function(t){h.forEach((function(i){e.push(t.clone().multiply(i))}))})),f.addPart(e)}else f.addPart(m);t.biomolDict.UNITCELL=c,t.biomolDict.SUPERCELL=f,e.Debug&&Fl.timeEnd("buildUnitcellAssembly")}const qm=["H","C","O","N","S","P"],Xm=["NA","CL","FE"];function Ym(e){let t=e.toUpperCase(),i=0,n=0;for(let e=0;e0)break;++i}else n=e+1;(i>0||n=3&&-1!==qm.indexOf(t[0])?t[0]:""}function Km(e){const t=e.bondHash,i=t.countArray,n=t.offsetArray,r=t.indexArray,s=e.getBondProxy();e.eachResidue((function(e){const t=e.residueType;if(void 0!==t.bonds)return;var a=e.atomOffset,o=[],l=[],c=[],u={};const h=a+e.atomCount;e.eachAtom((function(e){const t=e.index,d=n[t];for(let e=0,n=i[t];e=h)continue;let i=s.atomIndex2;if(i=h)continue;if(t>i){const e=i;i=t,t=e}const n=t+"|"+i;void 0===u[n]&&(u[n]=!0,o.push(t-a),l.push(i-a),c.push(s.bondOrder))}})),t.bonds={atomIndices1:o,atomIndices2:l,bondOrders:c}}))}const Zm=[3,11,19,37,55,87],Qm=[4,12,20,38,56,88],Jm=[6,15,16,34],ep=[1,7,8,9,17,35,53],tp=[2,10,18,36,54,86],ip=[13,30,31,48,49,50,80,81,82,83,84,85,112],np=[5,14,32,33,51,52,85],rp=[9,17,35,53,85];class sp{constructor(e,t,i){this.structure=e,this.atomname=t,i=i||Ym(t),this.element=i,this.number=Hh[i]||0,this.vdw=jh[this.number]||2,this.covalent=Wh[this.number]||1.6}getDefaultValence(){const e=qh[this.number];return e?e[0]:-1}getValenceList(){return qh[this.number]||[]}getOuterShellElectronCount(){return Xh[this.number]||2}isMetal(){return this.isAlkaliMetal()||this.isAlkalineEarthMetal()||this.isLanthanide()||this.isActinide()||this.isTransitionMetal()||this.isPostTransitionMetal()}isNonmetal(){return this.isDiatomicNonmetal()||this.isPolyatomicNonmetal()||this.isNobleGas()}isMetalloid(){return np.includes(this.number)}isHalogen(){return rp.includes(this.number)}isDiatomicNonmetal(){return ep.includes(this.number)}isPolyatomicNonmetal(){return Jm.includes(this.number)}isAlkaliMetal(){return Zm.includes(this.number)}isAlkalineEarthMetal(){return Qm.includes(this.number)}isNobleGas(){return tp.includes(this.number)}isTransitionMetal(){const e=this.number;return e>=21&&e<=29||e>=39&&e<=47||e>=72&&e<=79||e>=104&&e<=108}isPostTransitionMetal(){return ip.includes(this.number)}isLanthanide(){return this.number>=57&&this.number<=71}isActinide(){return this.number>=89&&this.number<=103}}class ap{constructor(e){this.structure=e,this.dict={},this.list=[],this.structure=e}add(e,t){const i=function(e,t){return e+"|"+t}(e=e.toUpperCase(),t=t?t.toUpperCase():Ym(e));let n=this.dict[i];if(void 0===n){const r=new sp(this.structure,e,t);n=this.list.length,this.dict[i]=n,this.list.push(r)}return n}get(e){return this.list[e]}}class op{constructor(e,t,i,n,r,s){this.structure=e,this.bondReferenceAtomIndices=[],this.resname=t,this.atomTypeIdList=i,this.hetero=n?1:0,this.chemCompType=r,this.bonds=s,this.atomCount=i.length,this.moleculeType=this.getMoleculeType(),this.backboneType=this.getBackboneType(0),this.backboneEndType=this.getBackboneType(-1),this.backboneStartType=this.getBackboneType(1),this.backboneIndexList=this.getBackboneIndexList();const a=ld[this.backboneType],o=ld[this.backboneStartType],l=ld[this.backboneEndType],c=this.getAtomIndexByName(a.trace);this.traceAtomIndex=uo(c,-1);const u=this.getAtomIndexByName(a.direction1);this.direction1AtomIndex=uo(u,-1);const h=this.getAtomIndexByName(a.direction2);this.direction2AtomIndex=uo(h,-1);const d=this.getAtomIndexByName(o.backboneStart);this.backboneStartAtomIndex=uo(d,-1);const f=this.getAtomIndexByName(l.backboneEnd);let m;this.backboneEndAtomIndex=uo(f,-1),m=td.includes(t)?this.getAtomIndexByName("N1"):this.getAtomIndexByName("N3"),this.rungEndAtomIndex=uo(m,-1)}getBackboneIndexList(){const e=[];let t;switch(this.moleculeType){case 3:t=ad;break;case 4:case 5:t=od;break;default:return e}const i=this.structure.atomMap,n=this.atomTypeIdList;for(let r=0,s=this.atomCount;r500)e.Debug&&Fl.warn("more than 500 atoms, skip residue for auto-bonding",t.qualifiedName());else if(s>50){const e=new Pm(t,!0),i=t.isCg()?1.2:2.3;for(let t=a;t=0||hp(e,t);this.rings={atomRings:e.atomRings,rings:e.rings}}isAromatic(e){return this.aromaticAtoms=this.getAromatic(e),1===this.aromaticAtoms[e.index-e.residueAtomOffset]}calculateAromatic(e){const t=this.aromaticAtoms=new Uint8Array(this.atomCount),i=this.getRings().rings,n=i.map((t=>function(e){if(e.some((e=>!lp.includes(e.number))))return!1;let t=0;const i=new af(3,e.length),n=i.data;e.forEach((e=>{n[t+0]=e.x,n[t+1]=e.y,n[t+2]=e.z,t+=3}));return new dm(i).vecC.length()this.structure.getAtomProxy(t+e.atomOffset)))))),r=this.aromaticRings=[];i.forEach(((e,i)=>{n[i]&&(r.push(e),e.forEach((e=>t[e]=1)))}))}assignBondReferenceAtomIndices(){const e=this.getBondGraph(),t=this.getRings(),i=t.atomRings,n=t.rings,r=this.bonds,s=r.atomIndices1,a=r.atomIndices2,o=r.bondOrders,l=this.bondReferenceAtomIndices,c=r.atomIndices1.length;l.length=0;for(let t=0;t1)for(let i=0;i1)for(let i=0;i=0;e--)m[p++]=a[e];const g=e.rings.length;for(let t=0;t0?s[l]!==t&&s[t]!==l&&up(e,t,l):(n[l]=1,r[o++]=l,s[l]=t)}}}const dp=4;class fp{constructor(e){this.structure=e,this.dict={},this.list=[]}add(e,t,i,n="",r){const s=function(e,t,i,n=""){return e+"|"+t.join(",")+"|"+(i?1:0)+"|"+n}(e=e.toUpperCase(),t,i,n);let a=this.dict[s];if(void 0===a){const o=new op(this.structure,e,t,i,n,r);a=this.list.length,this.dict[s]=a,this.list.push(o)}return a}get(e){return this.list[e]}}class mp{constructor(e,t=0){this.structure=e,this.index=t,this.bondStore=e.bondStore,this._v12=new _t,this._v13=new _t,this._ap1=this.structure.getAtomProxy(),this._ap2=this.structure.getAtomProxy(),this._ap3=this.structure.getAtomProxy()}get atom1(){return this.structure.getAtomProxy(this.atomIndex1)}get atom2(){return this.structure.getAtomProxy(this.atomIndex2)}get atomIndex1(){return this.bondStore.atomIndex1[this.index]}set atomIndex1(e){this.bondStore.atomIndex1[this.index]=e}get atomIndex2(){return this.bondStore.atomIndex2[this.index]}set atomIndex2(e){this.bondStore.atomIndex2[this.index]=e}get bondOrder(){return this.bondStore.bondOrder[this.index]}set bondOrder(e){this.bondStore.bondOrder[this.index]=e}getOtherAtomIndex(e){return e===this.atomIndex1?this.atomIndex2:this.atomIndex1}getOtherAtom(e){return this.structure.getAtomProxy(this.getOtherAtomIndex(e.index))}getReferenceAtomIndex(){const e=this._ap1,t=this._ap2;if(e.index=this.atomIndex1,t.index=this.atomIndex2,e.residueIndex!==t.residueIndex)return;const i=e.index-e.residueAtomOffset,n=t.index-t.residueAtomOffset,r=e.residueType.getBondReferenceAtomIndex(i,n);if(void 0!==r)return r+e.residueAtomOffset;console.warn("No reference atom found",e.index,t.index)}calculateShiftDir(e=new _t){const t=this._ap1,i=this._ap2,n=this._ap3,r=this._v12,s=this._v13;t.index=this.atomIndex1,i.index=this.atomIndex2;const a=this.getReferenceAtomIndex();r.subVectors(t,i).normalize(),void 0!==a?(n.index=a,s.subVectors(t,n)):s.copy(t),s.normalize();let o=r.dot(s);return 1-Math.abs(o)<1e-5&&(s.set(1,0,0),o=r.dot(s),1-Math.abs(o)<1e-5&&(s.set(0,1,0),o=r.dot(s))),e.copy(s.sub(r.multiplyScalar(o))).normalize()}qualifiedName(){return this.atomIndex1+"="+this.atomIndex2}clone(){return new mp(this.structure,this.index)}toObject(){return{atomIndex1:this.atomIndex1,atomIndex2:this.atomIndex2,bondOrder:this.bondOrder}}}class pp{constructor(e,t=0){this.structure=e,this.index=t,this.chainStore=e.chainStore,this.residueStore=e.residueStore,this.atomStore=e.atomStore,this.residueMap=e.residueMap,this.atomMap=e.atomMap}get entity(){return this.structure.entityList[this.entityIndex]}get entityIndex(){return this.chainStore.entityIndex[this.chainIndex]}get chain(){return this.structure.getChainProxy(this.chainIndex)}get chainIndex(){return this.residueStore.chainIndex[this.index]}set chainIndex(e){this.residueStore.chainIndex[this.index]=e}get atomOffset(){return this.residueStore.atomOffset[this.index]}set atomOffset(e){this.residueStore.atomOffset[this.index]=e}get atomCount(){return this.residueStore.atomCount[this.index]}set atomCount(e){this.residueStore.atomCount[this.index]=e}get atomEnd(){return this.atomOffset+this.atomCount-1}get modelIndex(){return this.chainStore.modelIndex[this.chainIndex]}get chainname(){return this.chainStore.getChainname(this.chainIndex)}get chainid(){return this.chainStore.getChainid(this.chainIndex)}get resno(){return this.residueStore.resno[this.index]}set resno(e){this.residueStore.resno[this.index]=e}get sstruc(){return this.residueStore.getSstruc(this.index)}set sstruc(e){this.residueStore.setSstruc(this.index,e)}get inscode(){return this.residueStore.getInscode(this.index)}set inscode(e){this.residueStore.setInscode(this.index,e)}get residueType(){return this.residueMap.get(this.residueStore.residueTypeId[this.index])}get resname(){return this.residueType.resname}get hetero(){return this.residueType.hetero}get moleculeType(){return this.residueType.moleculeType}get backboneType(){return this.residueType.backboneType}get backboneStartType(){return this.residueType.backboneStartType}get backboneEndType(){return this.residueType.backboneEndType}get traceAtomIndex(){return this.residueType.traceAtomIndex+this.atomOffset}get direction1AtomIndex(){return this.residueType.direction1AtomIndex+this.atomOffset}get direction2AtomIndex(){return this.residueType.direction2AtomIndex+this.atomOffset}get backboneStartAtomIndex(){return this.residueType.backboneStartAtomIndex+this.atomOffset}get backboneEndAtomIndex(){return this.residueType.backboneEndAtomIndex+this.atomOffset}get rungEndAtomIndex(){return this.residueType.rungEndAtomIndex+this.atomOffset}get x(){let e=0;for(let t=this.atomOffset;t<=this.atomEnd;++t)e+=this.atomStore.x[t];return e/this.atomCount}get y(){let e=0;for(let t=this.atomOffset;t<=this.atomEnd;++t)e+=this.atomStore.y[t];return e/this.atomCount}get z(){let e=0;for(let t=this.atomOffset;t<=this.atomEnd;++t)e+=this.atomStore.z[t];return e/this.atomCount}eachAtom(e,t){const i=this.atomCount,n=this.atomOffset,r=this.structure._ap,s=n+i;if(t&&t.atomOnlyTest){const i=t.atomOnlyTest;for(let t=n;t0)return this.entity.isPolymer();{const e=this.residueType.moleculeType;return 3===e||4===e||5===e}}isHetero(){return 1===this.residueType.hetero}isWater(){return 1===this.residueType.moleculeType}isIon(){return 2===this.residueType.moleculeType}isSaccharide(){return 6===this.residueType.moleculeType}isStandardAminoacid(){return this.residueType.isStandardAminoacid()}isStandardBase(){return this.residueType.isStandardBase()}isHelix(){return Vh.includes(this.sstruc)}isSheet(){return $h.includes(this.sstruc)}isTurn(){return Gh.includes(this.sstruc)&&this.isProtein()}getAtomType(e){return this.atomMap.get(this.atomStore.atomTypeId[e])}getResname1(){return Zh[this.resname.toUpperCase()]||"X"}getBackboneType(e){switch(e){case-1:return this.residueType.backboneStartType;case 1:return this.residueType.backboneEndType;default:return this.residueType.backboneType}}getAtomIndexByName(e){let t=this.residueType.getAtomIndexByName(e);return void 0!==t&&(t+=this.atomOffset),t}hasAtomWithName(e){return this.residueType.hasAtomWithName(e)}getAtomnameList(){console.warn("getAtomnameList - might be expensive");const e=this.atomCount,t=this.atomOffset,i=new Array(e);for(let n=0;n=t){const t=uo(e,this.structure.getResidueProxy());if(t.index=i,t.connectedTo(this))return t}else if(i===t-1){const i=this.chainStore.residueCount[this.chainIndex],n=uo(e,this.structure.getResidueProxy());if(n.index=t+i-1,n.connectedTo(this))return n}}getBonds(){return this.residueType.getBonds(this)}getRings(){return this.residueType.getRings()}getAromaticRings(){return this.residueType.getAromaticRings(this)}qualifiedName(e=!1){let t="";return this.resname&&!e&&(t+="["+this.resname+"]"),void 0!==this.resno&&(t+=this.resno),this.inscode&&(t+="^"+this.inscode),this.chain&&(t+=":"+this.chainname),t+="/"+this.modelIndex,t}clone(){return new pp(this.structure,this.index)}toObject(){return{index:this.index,chainIndex:this.chainIndex,atomOffset:this.atomOffset,atomCount:this.atomCount,resno:this.resno,resname:this.resname,sstruc:this.sstruc}}}class gp{constructor(e,t,i){this.structure=e,this.residueIndexStart=t,this.residueIndexEnd=i,this.chainStore=e.chainStore,this.residueStore=e.residueStore,this.atomStore=e.atomStore,this.residueCount=i-t+1;const n=this.structure.getResidueProxy(this.residueIndexStart),r=this.structure.getResidueProxy(this.residueIndexEnd);this.isPrevConnected=void 0!==n.getPreviousConnectedResidue();const s=r.getNextConnectedResidue();this.isNextConnected=void 0!==s,this.isNextNextConnected=void 0!==s&&void 0!==s.getNextConnectedResidue(),this.isCyclic=r.connectedTo(n),this.__residueProxy=this.structure.getResidueProxy()}get chainIndex(){return this.residueStore.chainIndex[this.residueIndexStart]}get modelIndex(){return this.chainStore.modelIndex[this.chainIndex]}get chainname(){return this.chainStore.getChainname(this.chainIndex)}isProtein(){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.isProtein()}isCg(){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.isCg()}isNucleic(){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.isNucleic()}getMoleculeType(){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.moleculeType}getBackboneType(e){return this.__residueProxy.index=this.residueIndexStart,this.__residueProxy.getBackboneType(e)}getAtomIndexByType(e,t){this.isCyclic?-1===e?e=this.residueCount-1:e===this.residueCount&&(e=0):(-1!==e||this.isPrevConnected||(e+=1),e!==this.residueCount||this.isNextNextConnected||(e-=1));const i=this.__residueProxy;let n;switch(i.index=this.residueIndexStart+e,t){case"trace":n=i.traceAtomIndex;break;case"direction1":n=i.direction1AtomIndex;break;case"direction2":n=i.direction2AtomIndex;break;default:n=i.getAtomIndexByName(t)}return n}eachAtom(e,t){this.eachResidue((function(i){i.eachAtom(e,t)}))}eachAtomN(e,t,i){const n=this.residueCount,r=new Array(e);for(let t=0;t1&&e(new gp(s,i,c.index)),i=n)):(a!==Oh&&c.index-i>1&&e(new gp(s,i,c.index)),i=n)}n-i>1&&this.structure.getResidueProxy(i).backboneEndType&&e(new gp(s,i,n))}qualifiedName(){return":"+this.chainname+"/"+this.modelIndex}clone(){return new _p(this.structure,this.index)}toObject(){return{index:this.index,residueOffset:this.residueOffset,residueCount:this.residueCount,chainname:this.chainname}}}class yp{constructor(e,t=0){this.structure=e,this.index=t,this.modelStore=e.modelStore,this.chainStore=e.chainStore,this.residueStore=e.residueStore}get chainOffset(){return this.modelStore.chainOffset[this.index]}set chainOffset(e){this.modelStore.chainOffset[this.index]=e}get chainCount(){return this.modelStore.chainCount[this.index]}set chainCount(e){this.modelStore.chainCount[this.index]=e}get residueOffset(){return this.chainStore.residueOffset[this.chainOffset]}get atomOffset(){return this.residueStore.atomOffset[this.residueOffset]}get chainEnd(){return this.chainOffset+this.chainCount-1}get residueEnd(){return this.chainStore.residueOffset[this.chainEnd]+this.chainStore.residueCount[this.chainEnd]-1}get atomEnd(){return this.residueStore.atomOffset[this.residueEnd]+this.residueStore.atomCount[this.residueEnd]-1}get residueCount(){return 0===this.chainCount?0:this.residueEnd-this.residueOffset+1}get atomCount(){return 0===this.residueCount?0:this.atomEnd-this.atomOffset+1}eachAtom(e,t){this.eachChain((function(i){i.eachAtom(e,t)}),t)}eachResidue(e,t){this.eachChain((function(i){i.eachResidue(e,t)}),t)}eachPolymer(e,t){if(t&&t.chainOnlyTest){const i=t.chainOnlyTest;this.eachChain((function(n){i(n)&&n.eachPolymer(e,t)}))}else this.eachChain((function(i){i.eachPolymer(e,t)}))}eachChain(e,t){const i=this.chainCount,n=this.chainOffset,r=this.structure._cp,s=n+i;if(t&&t.test){const i=t.chainOnlyTest;if(i)for(let t=n;t{const i=3*t;o.index=e,c&&o.positionToArray(c,i),u&&s.atomColorToArray(o,u,i),h&&(h.array[t]=e),d&&(d[t]=r.atomRadius(o)),f&&(f[t]=e)})),a}getBondData(e){const t=Object.assign({},e);t.colorParams&&(t.colorParams.structure=this.getStructure());const i=t.what,n=uo(t.bondSet,this.bondSet),r=uo(t.multipleBond,"off"),s="off"!==r,a="offset"===r,o=uo(t.bondScale,.4),l=uo(t.bondSpacing,1);let c,u;const h={},d=this.getBondProxy();t.bondStore&&(d.bondStore=t.bondStore);const f=this.getAtomProxy(),m=this.getAtomProxy();let p;if(s){const e=d.bondStore.bondOrder;p=0,n.forEach((function(t){p+=e[t]}))}else p=n.getSize();i&&!i.position||(h.position1=new Float32Array(3*p),h.position2=new Float32Array(3*p)),i&&!i.color||!t.colorParams||(h.color=new Float32Array(3*p),h.color2=new Float32Array(3*p),u=$l.getScheme(t.colorParams)),i&&!i.picking||(h.picking=new Wd(new Float32Array(p),this.getStructure(),t.bondStore)),(!i||i.radius||s&&i.position)&&(c=new cm(t.radiusParams)),i&&!i.radius||(h.radius=new Float32Array(p),t.radius2&&(h.radius2=new Float32Array(p)));const{position1:g,position2:_,color:y,color2:v,picking:b,radius:x,radius2:w}=h;let S,M,A,C,T,P,E=0;const I=new _t,D=new _t,R=new _t;return n.forEach((e=>{if(M=3*E,d.index=e,f.index=d.atomIndex1,m.index=d.atomIndex2,C=d.bondOrder,g)if(s&&C>1){const e=c.atomRadius(f);P=e*o/(.5*C),d.calculateShiftDir(R),a?(T=2*l*e,R.multiplyScalar(T),R.negate(),D.subVectors(m,f).multiplyScalar(Math.max(.1,T/1.88)),f.positionToArray(g,M),m.positionToArray(_,M),C>=2&&(I.addVectors(f,R).add(D).toArray(g,M+3),I.addVectors(m,R).sub(D).toArray(_,M+3),C>=3&&(I.subVectors(f,R).add(D).toArray(g,M+6),I.subVectors(m,R).sub(D).toArray(_,M+6)))):(T=(l-o)*e,R.multiplyScalar(T),2===C?(I.addVectors(f,R).toArray(g,M),I.subVectors(f,R).toArray(g,M+3),I.addVectors(m,R).toArray(_,M),I.subVectors(m,R).toArray(_,M+3)):3===C?(f.positionToArray(g,M),I.addVectors(f,R).toArray(g,M+3),I.subVectors(f,R).toArray(g,M+6),m.positionToArray(_,M),I.addVectors(m,R).toArray(_,M+3),I.subVectors(m,R).toArray(_,M+6)):(f.positionToArray(g,M),m.positionToArray(_,M)))}else f.positionToArray(g,M),m.positionToArray(_,M);if(y&&v&&(u.bondColorToArray(d,1,y,M),u.bondColorToArray(d,0,v,M),s&&C>1))for(S=1;S1))for(S=1;S1))for(P=x[E]*o/(a?1:.5*C),S=a?1:0;S1))for(P=w[E]*o/(a?1:.5*C),S=a?1:0;S{const t=e.x,i=e.y,c=e.z;ta&&(a=t),i>o&&(o=i),c>l&&(l=c)}),t),i.min.set(n,r,s),i.max.set(a,o,l),e.Debug&&Fl.timeEnd("getBoundingBox"),i}getPrincipalAxes(t){e.Debug&&Fl.time("getPrincipalAxes");let i=0;const n=new af(3,this.atomCount),r=n.data;return this.eachAtom((e=>{r[i+0]=e.x,r[i+1]=e.y,r[i+2]=e.z,i+=3}),t),e.Debug&&Fl.timeEnd("getPrincipalAxes"),new dm(n)}atomCenter(e){return e?this.getBoundingBox(e).getCenter(new _t):this.center.clone()}hasCoords(){if(void 0===this._hasCoords){const e=this.atomStore;this._hasCoords=0!==Dc(e.x)||0!==Ic(e.x)||0!==Dc(e.y)||0!==Ic(e.y)||0!==Dc(e.z)||0!==Ic(e.z)||e.count/this.modelStore.count==1}return this._hasCoords}getSequence(e){const t=[],i=this.getResidueProxy();return this.eachAtom((function(e){i.index=e.residueIndex,e.index===i.traceAtomIndex&&t.push(i.getResname1())}),e),t}getAtomIndices(e){if(e&&e.string){const t=[];return this.eachAtom((function(e){t.push(e.index)}),e),new Uint32Array(t)}{const e={what:{index:!0}};return this.getAtomData(e).index}}getChainnameCount(e){const t=new Set;return this.eachChain((function(e){e.residueCount&&t.add(e.chainname)}),e),t.size}updatePosition(e,t=!0){let i=0;this.eachAtom((function(t){t.positionFromArray(e,i),i+=3}),void 0),this._hasCoords=void 0,t&&this.refreshPosition()}refreshPosition(){this.getBoundingBox(void 0,this.boundingBox),this.boundingBox.getCenter(this.center),this.spatialHash=new Ch(this.atomStore,this.boundingBox),this.signals.refreshed.dispatch(this)}dispose(){this.frames&&(this.frames.length=0),this.boxes&&(this.boxes.length=0),this.bondStore.dispose(),this.backboneBondStore.dispose(),this.rungBondStore.dispose(),this.atomStore.dispose(),this.residueStore.dispose(),this.chainStore.dispose(),this.modelStore.dispose(),delete this.bondSet,delete this.atomSet}}const bp=new bt,xp=[vh,ph,bh,yh,xh,gh,mh,_h,Sh,wh,Mh,Ah],wp={aspectRatio:1.5,sphereDetail:2,radialSegments:50,disableImpostor:!1,openEnded:!1,dashedCylinder:!1,labelParams:{},pointSize:2,sizeAttenuation:!1,useTexture:!0,linewidth:2};class Sp{constructor(e="shape",t={}){this.boundingBox=new bt,this.bufferList=[],this.meshCount=0,this._primitiveData={},this.name=e,this.parameters=ho(t,wp),xp.forEach((e=>{Object.keys(e.fields).forEach((t=>{this._primitiveData[e.getShapeKey(t)]=[]})),this._primitiveData[e.getShapeKey("name")]=[]}))}addBuffer(e){this.bufferList.push(e);const t=e.geometry;return t.boundingBox||t.computeBoundingBox(),this.boundingBox.union(t.boundingBox),this}addMesh(e,t,i,n,r){let s;e=Eo(e),t=Eo(t),Array.isArray(i)&&(i=So(i,e.length)),n&&(n=Eo(n)),s=void 0===n||0==n.length?{position:e,color:t,index:i}:{position:e,color:t,index:i,normal:n};const a=new Zd(this,Object.assign({serial:this.meshCount,name:r},s)),o=new Bf(Object.assign({picking:a},s));return this.bufferList.push(o),bp.setFromArray(e),this.boundingBox.union(bp),this.meshCount+=1,this}addSphere(e,t,i,n){return mh.objectToShape(this,{position:e,color:t,radius:i,name:n}),this}addEllipsoid(e,t,i,n,r,s){return xh.objectToShape(this,{position:e,color:t,radius:i,majorAxis:n,minorAxis:r,name:s}),this}addTorus(e,t,i,n,r,s){return wh.objectToShape(this,{position:e,color:t,radius:i,majorAxis:n,minorAxis:r,name:s}),this}addCylinder(e,t,i,n,r){return yh.objectToShape(this,{position1:e,position2:t,color:i,radius:n,name:r}),this}addCone(e,t,i,n,r){return bh.objectToShape(this,{position1:e,position2:t,color:i,radius:n,name:r}),this}addArrow(e,t,i,n,r){return vh.objectToShape(this,{position1:e,position2:t,color:i,radius:n,name:r}),this}addBox(e,t,i,n,r,s){return ph.objectToShape(this,{position:e,color:t,size:i,heightAxis:n,depthAxis:r,name:s}),this}addOctahedron(e,t,i,n,r,s){return gh.objectToShape(this,{position:e,color:t,size:i,heightAxis:n,depthAxis:r,name:s}),this}addTetrahedron(e,t,i,n,r,s){return _h.objectToShape(this,{position:e,color:t,size:i,heightAxis:n,depthAxis:r,name:s}),this}addText(e,t,i,n){return Sh.objectToShape(this,{position:e,color:t,size:i,text:n}),this}addPoint(e,t,i){return Mh.objectToShape(this,{position:e,color:t,name:i}),this}addWideline(e,t,i,n,r){return this.parameters.linewidth=n,Ah.objectToShape(this,{position1:e,position2:t,color:i,name:r}),this}addLabel(e,t,i,n){return console.warn("Shape.addLabel is deprecated, use .addText instead"),this.addText(e,t,i,n)}getBufferList(){const e=[];return xp.forEach((t=>{this._primitiveData[t.getShapeKey("color")].length&&e.push(t.bufferFromShape(this,this.parameters))})),this.bufferList.concat(e)}dispose(){this.bufferList.forEach((function(e){e.dispose()})),this.bufferList.length=0,xp.forEach((e=>{Object.keys(e.fields).forEach((t=>{this._primitiveData[e.getShapeKey(t)].length=0})),this._primitiveData[e.getShapeKey("name")].length=0}))}get center(){return this._center||(this._center=this.boundingBox.getCenter(new _t)),this._center}get type(){return"Shape"}}class Mp extends Nu{constructor(e,t,i){Array.isArray(e)||(e=[e]),super(e,t,i),this.type="buffer",this.parameters=Object.assign({},this.parameters,{colorScheme:null,colorScale:null,colorValue:null,colorDomain:null,colorMode:null}),this.buffer=e,this.init(i)}init(e){super.init(e),this.build()}create(){this.bufferList.push.apply(this.bufferList,this.buffer)}attach(e){this.bufferList.forEach((e=>{this.viewer.add(e),e.setParameters(this.getBufferParams())})),this.setVisibility(this.visible),e()}}const Ap=new qt,Cp=new He;class Tp extends Bf{constructor(e,t={},i){super(function(e,t){const i=t.attributes.position.array,n=t.index?t.index.array:void 0,r=e.position.length/3,s=i.length/3,a=r*s,o=new Float32Array(3*a),l=new Float32Array(3*a),c=new Float32Array(3*a);let u;return n&&(u=So(r*n.length,a)),{position:o,color:c,index:u,normal:l,primitiveId:e.primitiveId||Cc(r,s),picking:e.picking}}(e,i),t),this.updateNormals=!1;const n=i.attributes.position.array,r=i.attributes.normal.array,s=i.index?i.index.array:void 0;this.geoPosition=n,this.geoNormal=r,this.geoIndex=s,this.positionCount=e.position.length/3,this.geoPositionCount=n.length/3,this.transformedGeoPosition=new Float32Array(3*this.geoPositionCount),this.transformedGeoNormal=new Float32Array(3*this.geoPositionCount);const a=this.geometry.attributes;if(this.meshPosition=a.position.array,this.meshColor=a.color.array,this.meshNormal=a.normal.array,this.setAttributes(e),s){const e=this.geometry.getIndex();if(!e)return void Fl.error("Index is null");this.meshIndex=e.array,this.makeIndex()}}setAttributes(e={},t=!1){const i=this.geometry.attributes;let n,r,s,a,o,l,c,u,h;const d=this.updateNormals;e.position&&(n=e.position,s=this.geoPosition,c=this.meshPosition,o=this.transformedGeoPosition,i.position.needsUpdate=!0,(d||t)&&(a=this.geoNormal,h=this.meshNormal,l=this.transformedGeoNormal,i.normal.needsUpdate=!0)),e.color&&(r=e.color,u=this.meshColor,i.color.needsUpdate=!0);const f=this.positionCount,m=this.geoPositionCount;for(let e=0;e 0.0 ){\ncameraPos = rayDirection * posT + rayOrigin;\ninterior = true;\nflag2 = true;\n}\n#else\nif( calcDepth( cameraPos ) <= 0.0 ){\ncameraPos = rayDirection * posT + rayOrigin;\ninterior = true;\n}\n#endif\ncameraNormal = normalize( cameraPos - cameraSpherePos );\ncameraNormal *= float(!interior) * 2.0 - 1.0;\nreturn !interior;\n}\nvoid main(void){\nbool flag = Impostor( cameraPos, cameraNormal );\n#ifdef NEAR_CLIP\nif( calcClip( cameraPos ) > 0.0 )\ndiscard;\n#endif\ngl_FragDepthEXT = calcDepth( cameraPos );\nif( !flag ){\n#ifdef NEAR_CLIP\nif( flag2 ){\ngl_FragDepthEXT = max( 0.0, calcDepth( vec3( - ( clipNear - 0.5 ) ) ) + ( 0.0000001 / vRadius ) );\n}else if( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );\n}\n#else\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );\n}\n#endif\n}\nif (gl_FragDepthEXT < 0.0)\ndiscard;\nif (gl_FragDepthEXT > 1.0)\ndiscard;\n#ifdef PICKING\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\nvec3 vNormal = cameraNormal;\nvec3 vViewPosition = -cameraPos;\nvec4 diffuseColor = vec4( diffuse, opacity );\nReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\nvec3 totalEmissiveLight = emissive;\n#include color_fragment\n#include roughnessmap_fragment\n#include metalnessmap_fragment\n#include normal_fragment_begin\n#include lights_physical_fragment\n#include lights_fragment_begin\n#include lights_fragment_end\nvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;\nif( interior ){\n#ifdef USE_INTERIOR_COLOR\noutgoingLight.xyz = interiorColor;\n#else\n#ifdef DIFFUSE_INTERIOR\noutgoingLight.xyz = vColor;\n#endif\n#endif\noutgoingLight.xyz *= 1.0 - interiorDarkening;\n}\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");class Dp extends Ff{constructor(e,t,i={}){super(t,i),this.index=So(this.indexSize,this.attributeSize),this.makeIndex(),this.initIndex(this.index),this.addAttributes({mapping:{type:e,value:null}}),this.setAttributes({primitiveId:Ac(this.size)})}get attributeSize(){return this.size*this.mappingSize}get indexSize(){return this.size*this.mappingIndicesSize}addAttributes(e){const t={};for(const i in e){const n=e[i];t[i]={type:n.type,value:null}}super.addAttributes(t)}getAttributeIndex(e){return 3*e*this.mappingSize}setAttributes(e){e&&!e.position&&e.position1&&e.position2&&(e.position=xc(e.position1,e.position2));const t=this.size,i=this.mappingSize,n=this.geometry.attributes;let r,s,a,o,l,c,u;for(const h in e)if("index"!==h&&"picking"!==h){s=e[h],r=n[h],a=r.itemSize,o=r.array;for(let e=0;e0&&this.parameters.alphaTest<=1&&(t.USE_ALPHATEST=1),t}setUniforms(e){e&&void 0!==e.edgeBleach&&(this.makeTexture(),e.map=this.tex),super.setUniforms(e)}dispose(){super.dispose(),this.tex&&this.tex.dispose()}}Yl.add("point",Up);class Vp extends Nu{constructor(e,t,i){super(e,t,i),this.type="dot",this.parameters=Object.assign({thresholdType:{type:"select",rebuild:!0,options:{value:"value",sigma:"sigma"}},thresholdMin:{type:"number",precision:3,max:1/0,min:-1/0,rebuild:!0},thresholdMax:{type:"number",precision:3,max:1/0,min:-1/0,rebuild:!0},thresholdOut:{type:"boolean",rebuild:!0},dotType:{type:"select",rebuild:!0,options:{"":"",sphere:"sphere",point:"point"}},radiusType:{type:"select",options:{"":"",value:"value","abs-value":"abs-value","value-min":"value-min",deviation:"deviation",size:"size"}},radius:{type:"number",precision:3,max:10,min:.001,property:"size"},scale:{type:"number",precision:3,max:10,min:.001},sphereDetail:!0,disableImpostor:!0,pointSize:{type:"number",precision:1,max:100,min:0,buffer:!0},sizeAttenuation:{type:"boolean",buffer:!0},sortParticles:{type:"boolean",rebuild:!0},useTexture:{type:"boolean",buffer:!0},alphaTest:{type:"range",step:.001,max:1,min:0,buffer:!0},forceTransparent:{type:"boolean",buffer:!0},edgeBleach:{type:"range",step:.001,max:1,min:0,buffer:!0}},this.parameters,{colorScheme:{type:"select",update:"color",options:{"":"",value:"value",uniform:"uniform",random:"random"}}}),e instanceof Df?(this.surface=void 0,this.volume=new fm(e)):(this.surface=e,this.volume=void 0),this.init(i)}init(e){var t=e||{};t.colorScheme=uo(t.colorScheme,"uniform"),t.colorValue=uo(t.colorValue,14540253),this.thresholdType=uo(t.thresholdType,"sigma"),this.thresholdMin=uo(t.thresholdMin,2),this.thresholdMax=uo(t.thresholdMax,1/0),this.thresholdOut=uo(t.thresholdOut,!1),this.dotType=uo(t.dotType,"point"),this.radius=uo(t.radius,.1),this.scale=uo(t.scale,1),this.pointSize=uo(t.pointSize,1),this.sizeAttenuation=uo(t.sizeAttenuation,!0),this.sortParticles=uo(t.sortParticles,!1),this.useTexture=uo(t.useTexture,!1),this.alphaTest=uo(t.alphaTest,.5),this.forceTransparent=uo(t.forceTransparent,!1),this.edgeBleach=uo(t.edgeBleach,0),super.init(t),this.build()}attach(e){this.bufferList.forEach((e=>{this.viewer.add(e)})),this.setVisibility(this.visible),e()}create(){var e={};if(this.volume){var t,i,n=this.volume;"sigma"===this.thresholdType?(t=n.getValueForSigma(this.thresholdMin),i=n.getValueForSigma(this.thresholdMax)):(t=this.thresholdMin,i=this.thresholdMax),n.setFilter(t,i,this.thresholdOut),Object.assign(e,{position:n.getDataPosition(),color:n.getDataColor(this.getColorParams())}),"sphere"===this.dotType&&Object.assign(e,{radius:n.getDataSize(this.radius,this.scale),picking:n.getDataPicking()})}else{var r=this.surface;Object.assign(e,{position:r.getPosition(),color:r.getColor(this.getColorParams())}),"sphere"===this.dotType&&Object.assign(e,{radius:r.getSize(this.radius,this.scale),picking:r.getPicking()})}"sphere"===this.dotType?this.dotBuffer=new Np(e,this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!1})):this.dotBuffer=new Up(e,this.getBufferParams({pointSize:this.pointSize,sizeAttenuation:this.sizeAttenuation,sortParticles:this.sortParticles,useTexture:this.useTexture,alphaTest:this.alphaTest,forceTransparent:this.forceTransparent,edgeBleach:this.edgeBleach})),this.bufferList.push(this.dotBuffer)}update(e={}){if(0===this.bufferList.length)return;const t={};e.color&&(this.volume?Object.assign(t,{color:this.volume.getDataColor(this.getColorParams())}):Object.assign(t,{color:this.surface.getColor(this.getColorParams())})),"sphere"===this.dotType&&(e.radius||e.scale)&&(this.volume?Object.assign(t,{radius:this.volume.getDataSize(this.radius,this.scale)}):Object.assign(t,{radius:this.surface.getSize(this.radius,this.scale)})),this.dotBuffer.setAttributes(t)}setParameters(e,t={},i){return e&&void 0!==e.thresholdType&&this.volume instanceof Df&&("value"===this.thresholdType&&"sigma"===e.thresholdType?(this.thresholdMin=this.volume.getSigmaForValue(this.thresholdMin),this.thresholdMax=this.volume.getSigmaForValue(this.thresholdMax)):"sigma"===this.thresholdType&&"value"===e.thresholdType&&(this.thresholdMin=this.volume.getValueForSigma(this.thresholdMin),this.thresholdMax=this.volume.getValueForSigma(this.thresholdMax)),this.thresholdType=e.thresholdType),e&&void 0!==e.radiusType&&("radius"===e.radiusType?this.radius=.1:this.radius=parseFloat(e.radiusType),t.radius=!0,"sphere"!==this.dotType||Ol&&!this.disableImpostor||(i=!0)),e&&void 0!==e.radius&&(t.radius=!0,"sphere"!==this.dotType||Ol&&!this.disableImpostor||(i=!0)),e&&void 0!==e.scale&&(t.scale=!0,"sphere"!==this.dotType||Ol&&!this.disableImpostor||(i=!0)),super.setParameters(e,t,i),this}}Wl.add("shader/Image.vert","uniform float clipRadius;\nuniform vec3 clipCenter;\nvarying vec2 vUv;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvarying vec3 vViewPosition;\n#endif\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\nvoid main() {\n#include begin_vertex\n#include project_vertex\nvUv = uv;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvViewPosition = -mvPosition.xyz;\n#endif\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n}"),Wl.add("shader/Image.frag","uniform sampler2D map;\nuniform float opacity;\nuniform vec2 mapSize;\nuniform float clipNear;\nuniform float clipRadius;\nvarying vec2 vUv;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvarying vec3 vViewPosition;\n#endif\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#if defined( PICKING )\nuniform sampler2D pickingMap;\nuniform float objectId;\n#else\n#include fog_pars_fragment\n#endif\n#if defined( CUBIC_INTERPOLATION )\n#if defined( CATMULROM_FILTER ) || defined( MITCHELL_FILTER )\n#if defined( CATMULROM_FILTER )\nconst float B = 0.0;\nconst float C = 0.5;\n#elif defined( MITCHELL_FILTER )\nconst float B = 0.333;\nconst float C = 0.333;\n#endif\nfloat applyFilter( float x ){\nfloat f = x;\nif( f < 0.0 ){\nf = -f;\n}\nif( f < 1.0 ){\nreturn ( ( 12.0 - 9.0 * B - 6.0 * C ) * ( f * f * f ) +\n( -18.0 + 12.0 * B + 6.0 *C ) * ( f * f ) +\n( 6.0 - 2.0 * B ) ) / 6.0;\n}else if( f >= 1.0 && f < 2.0 ){\nreturn ( ( -B - 6.0 * C ) * ( f * f * f )\n+ ( 6.0 * B + 30.0 * C ) * ( f *f ) +\n( - ( 12.0 * B ) - 48.0 * C ) * f +\n8.0 * B + 24.0 * C ) / 6.0;\n}else{\nreturn 0.0;\n}\n}\n#elif defined( BSPLINE_FILTER )\nfloat applyFilter( float x ){\nfloat f = x;\nif( f < 0.0 ){\nf = -f;\n}\nif( f >= 0.0 && f <= 1.0 ){\nreturn ( 2.0 / 3.0 ) + ( 0.5 ) * ( f * f * f ) - ( f * f );\n}else if( f > 1.0 && f <= 2.0 ){\nreturn 1.0 / 6.0 * pow( ( 2.0 - f ), 3.0 );\n}\nreturn 1.0;\n}\n#else\nfloat applyFilter( float x ){\nreturn 1.0;\n}\n#endif\nvec4 biCubic( sampler2D tex, vec2 texCoord ){\nvec2 texelSize = 1.0 / mapSize;\ntexCoord -= texelSize / 2.0;\nvec4 nSum = vec4( 0.0 );\nfloat nDenom = 0.0;\nvec2 cell = fract( texCoord * mapSize );\nfor( float m = -1.0; m <= 2.0; ++m ){\nfor( float n = -1.0; n <= 2.0; ++n ){\nvec4 vecData = texture2D(\ntex, texCoord + texelSize * vec2( m, n )\n);\nfloat c = applyFilter( m - cell.x ) * applyFilter( -n + cell.y );\nnSum += vecData * c;\nnDenom += c;\n}\n}\nreturn nSum / nDenom;\n}\n#endif\nvoid main(){\n#include nearclip_fragment\n#include radiusclip_fragment\n#if defined( CUBIC_INTERPOLATION )\ngl_FragColor = biCubic( map, vUv );\n#else\ngl_FragColor = texture2D( map, vUv );\n#endif\n#if defined( PICKING )\nif( gl_FragColor.a < 0.3 )\ndiscard;\ngl_FragColor = vec4( texture2D( pickingMap, vUv ).xyz, objectId );\n#else\nif( gl_FragColor.a < 0.01 )\ndiscard;\ngl_FragColor.a *= opacity;\n#include fog_fragment\n#endif\n}");const $p=new Uint16Array([0,1,2,1,3,2]),Gp=new Float32Array([0,1,0,0,1,1,1,0]),Hp=Object.assign({filter:"nearest",forceTransparent:!0},Of),jp=Object.assign({filter:{updateShader:!0,uniform:!0}},Nf);class Wp extends Ff{constructor(e,t){super({position:e.position,index:$p,picking:e.picking},t),this.parameterTypes=jp,this.alwaysTransparent=!0,this.hasWireframe=!1,this.vertexShader="Image.vert",this.fragmentShader="Image.frag";const{imageData:i,width:n,height:r}=e,s=new Ma(i,n,r);s.flipY=!0,this.tex=s;const a=i.length,o=new Uint8Array(a);for(let e=0;e>16&255,o[e+1]=t>>8&255,o[e+2]=255&t}const l=new Ma(o,n,r);l.flipY=!0,l.minFilter=U,l.magFilter=U,this.pickingTex=l,this.addUniforms({map:{value:s},pickingMap:{value:l},mapSize:{value:new Ge(n,r)}}),this.geometry.setAttribute("uv",new $i(Gp,2))}get defaultParameters(){return Hp}getDefines(e){const t=super.getDefines(e),i=this.parameters.filter;return i.startsWith("cubic")&&(t.CUBIC_INTERPOLATION=1,i.endsWith("bspline")?t.BSPLINE_FILTER=1:i.endsWith("catmulrom")?t.CATMULROM_FILTER=1:i.endsWith("mitchell")&&(t.MITCHELL_FILTER=1)),t}updateTexture(){const e=this.tex,t=this.parameters.filter;t.startsWith("cubic")?(e.minFilter=U,e.magFilter=U):"linear"===t?(e.minFilter=G,e.magFilter=G):(e.minFilter=U,e.magFilter=U),e.needsUpdate=!0,this.pickingTex.needsUpdate=!0}makeMaterial(){super.makeMaterial(),this.updateTexture();const e=this.material;e.uniforms.map.value=this.tex,e.blending=1,e.needsUpdate=!0;const t=this.wireframeMaterial;t.uniforms.map.value=this.tex,t.blending=1,t.needsUpdate=!0;const i=this.pickingMaterial;i.uniforms.map.value=this.tex,i.uniforms.pickingMap.value=this.pickingTex,i.blending=1,i.needsUpdate=!0}setUniforms(e){e&&void 0!==e.filter&&(this.updateTexture(),e.map=this.tex),super.setUniforms(e)}}class qp{constructor(e,t){const i=t||{};this.dimension=uo(i.dimension,"x"),this.positionType=uo(i.positionType,"percent"),this.position=uo(i.position,30),this.thresholdType=uo(i.thresholdType,"sigma"),this.thresholdMin=uo(i.thresholdMin,-1/0),this.thresholdMax=uo(i.thresholdMax,1/0),this.normalize=uo(i.normalize,!1),this.volume=e}getPositionFromCoordinate(e){const t=this.dimension,i=this.volume,n=i.matrix,r=(new _t).setFromMatrixPosition(n)[t],s=(new _t).setFromMatrixScale(n)[t];let a;return a="x"===t?i.nx:"y"===t?i.ny:i.nz,Math.round(((e-r)/(a/100)+1)/s)}getData(e){e=e||{};const t=this.volume,i=t.data,n=t.matrix;let r;function s(e){return Math.round(e/100*(r-1))}function a(e,i,n,r){return 3*(n*t.ny*t.nx+i*t.nx+e)+r}r="coordinate"===this.positionType?this.getPositionFromCoordinate(this.position):this.position;const o=new Float32Array(12),l=new _t;let c,u,h,d,f,m=0,p=0,g=0,_=t.nx,y=t.ny,v=t.nz;function b(e,t,i,r){l.set(e,t,i).applyMatrix4(n).toArray(o,r)}"x"===this.dimension?(h=s(t.nx),d=t.ny-1,f=t.nz-1,c=t.nz,u=t.ny,m=h,_=m+1,b(h,0,0,0),b(h,d,0,3),b(h,0,f,6),b(h,d,f,9)):"y"===this.dimension?(h=t.nx-1,d=s(t.ny),f=t.nz-1,c=t.nz,u=t.nx,p=d,y=p+1,b(0,d,0,0),b(h,d,0,3),b(0,d,f,6),b(h,d,f,9)):"z"===this.dimension&&(h=t.nx-1,d=t.ny-1,f=s(t.nz),c=t.nx,u=t.ny,g=f,v=g+1,b(0,0,f,0),b(0,d,f,3),b(h,0,f,6),b(h,d,f,9));let x=0,w=0;const S=new Uint8Array(c*u*4),M=new Float32Array(c*u);let A,C;"sigma"===this.thresholdType?(A=t.getValueForSigma(this.thresholdMin),C=t.getValueForSigma(this.thresholdMax)):(A=this.thresholdMin,C=this.thresholdMax);const T=Object.assign({},e.colorParams,{volume:t});this.normalize&&(T.domain=[0,1]);const P=$l.getScheme(T),E=new Float32Array(3),I=P.getScale();let D,R=0,L=0;if(this.normalize){R=1/0,D=-1/0;for(let e=p;eD&&(D=r)}L=D-R}for(let e=p;eA&&s{this.viewer.add(e)})),this.setVisibility(this.visible),e()}create(){const e=new qp(this.volume,{positionType:this.positionType,position:this.position,dimension:this.dimension,thresholdType:this.thresholdType,thresholdMin:this.thresholdMin,thresholdMax:this.thresholdMax,normalize:this.normalize}),t=new Wp(e.getData({colorParams:this.getColorParams()}),this.getBufferParams({filter:this.filter}));this.bufferList.push(t)}}function Yp(e){Fl.error(`makeRepresentation: representation type ${e} unknown`)}const Kp={name:"some element",status:""};class Zp{constructor(e,t={}){this.stage=e,this.signals={statusChanged:new Yo.Signal,nameChanged:new Yo.Signal,disposed:new Yo.Signal},this.parameters=ho(t,this.defaultParameters),this.uuid=Oo()}get defaultParameters(){return Kp}get name(){return this.parameters.name}setStatus(e){return this.parameters.status=e,this.signals.statusChanged.dispatch(e),this}setName(e){return this.parameters.name=e,this.signals.nameChanged.dispatch(e),this}dispose(){this.signals.disposed.dispatch()}}const Qp=Object.assign({visible:!0},Kp);class Jp extends Zp{constructor(e,t,i={},n){super(e,Object.assign({name:t.type},i)),this.parent=n,this.signals=Object.assign({visibilityChanged:new Yo.Signal,parametersChanged:new Yo.Signal},this.signals),this.setRepresentation(t)}get defaultParameters(){return Qp}get visible(){return this.parameters.visible}get type(){return"representation"}getType(){return this.repr.type}setRepresentation(e){this._disposeRepresentation(),this.repr=e,this.stage.tasks.listen(this.repr.tasks),this.updateVisibility()}_disposeRepresentation(){this.repr&&(this.stage.tasks.unlisten(this.repr.tasks),this.repr.dispose())}dispose(){this.parent&&this.parent.hasRepresentation(this)?this.parent.removeRepresentation(this):(this._disposeRepresentation(),this.signals.disposed.dispatch())}setVisibility(e){return this.parameters.visible=e,this.updateVisibility(),this.signals.visibilityChanged.dispatch(this.parameters.visible),this}getVisibility(){return this.parent?this.parent.parameters.visible&&this.parameters.visible:this.parameters.visible}toggleVisibility(){return this.setVisibility(!this.parameters.visible)}updateVisibility(){this.repr.setVisibility(this.getVisibility())}update(e){return this.repr.update(e),this}build(e){return this.repr.build(e),this}setSelection(e){const t=this.repr;return t.setSelection&&t.setSelection(e),this}setParameters(e){return this.repr.setParameters(e),this.signals.parametersChanged.dispatch(this.repr.getParameters()),this}getParameters(){return this.repr.getParameters()}setColor(e){return this.repr.setColor(e),this}}const eg=new qt,tg=new _t,ig={name:"",status:"",visible:!0};class ng{constructor(e,t,i={}){this.stage=e,this.object=t,this.signals={representationAdded:new Yo.Signal,representationRemoved:new Yo.Signal,visibilityChanged:new Yo.Signal,matrixChanged:new Yo.Signal,statusChanged:new Yo.Signal,nameChanged:new Yo.Signal,disposed:new Yo.Signal},this.reprList=[],this.annotationList=[],this.matrix=new qt,this.position=new _t,this.quaternion=new gt,this.scale=new _t(1,1,1),this.transform=new qt,this.parameters=ho(i,this.defaultParameters),this.uuid=Oo(),this.viewer=e.viewer,this.controls=new om(this)}get defaultParameters(){return ig}get name(){return this.parameters.name}get status(){return this.parameters.status}get visible(){return this.parameters.visible}setPosition(e){return Array.isArray(e)?this.position.fromArray(e):this.position.copy(e),this.updateMatrix(),this}setRotation(e){if(Array.isArray(e))if(3===e.length){const t=(new ni).fromArray(e);this.quaternion.setFromEuler(t)}else this.quaternion.fromArray(e);else e instanceof ni?this.quaternion.setFromEuler(e):this.quaternion.copy(e);return this.updateMatrix(),this}setScale(e){return this.scale.set(e,e,e),this.updateMatrix(),this}setTransform(e){return this.transform.copy(e),this.updateMatrix(),this}updateMatrix(){const e=this.getCenterUntransformed(tg);this.matrix.makeTranslation(-e.x,-e.y,-e.z),eg.makeRotationFromQuaternion(this.quaternion),this.matrix.premultiply(eg),eg.makeScale(this.scale.x,this.scale.y,this.scale.z),this.matrix.premultiply(eg);const t=this.position;eg.makeTranslation(t.x+e.x,t.y+e.y,t.z+e.z),this.matrix.premultiply(eg),this.matrix.premultiply(this.transform),this.updateRepresentationMatrices(),this.stage.viewer.updateBoundingBox(),this.signals.matrixChanged.dispatch(this.matrix)}updateRepresentationMatrices(){this.reprList.forEach((e=>{e.setParameters({matrix:this.matrix})}))}addAnnotation(e,t,i){const n=new nm(this,e,t,i);return this.annotationList.push(n),n}eachAnnotation(e){this.annotationList.slice().forEach(e)}removeAnnotation(e){const t=this.annotationList.indexOf(e);-1!==t&&(this.annotationList.splice(t,1),e.dispose())}removeAllAnnotations(){this.eachAnnotation((e=>e.dispose())),this.annotationList.length=0}_addRepresentation(t,i,n,r=!1){const s=n||{},a=this.stage.getParameters();s.matrix=this.matrix.clone(),s.quality=s.quality||a.quality,s.disableImpostor=uo(s.disableImpostor,!a.impostor),s.useWorker=uo(s.useWorker,a.workerDefault),s.visible=uo(s.visible,!0);const o=Object.assign({},s,{visible:this.parameters.visible&&s.visible}),l=function(t,i,n,r){var s;if(e.Debug&&Fl.time("makeRepresentation "+t),i instanceof vp){if(!(s=Hl.get(t)))return void Yp(t)}else if(i instanceof Ef)if("surface"===t)s=Hf;else{if("dot"!==t)return void Yp(t);s=Vp}else if(i instanceof Df)if("surface"===t)s=Hf;else if("dot"===t)s=Vp;else{if("slice"!==t)return void Yp(t);s=Xp}else if(i instanceof Sp)s=Mp,i=i.getBufferList();else{if("buffer"!==t)return void Fl.error("makeRepresentation: object "+i+" unknown");s=Mp}const a=new s(i,n,r);return e.Debug&&Fl.timeEnd("makeRepresentation "+t),a}(t,i,this.viewer,o),c=new Jp(this.stage,l,s,this);return r||(this.reprList.push(c),this.signals.representationAdded.dispatch(c)),c}addBufferRepresentation(e,t){return this._addRepresentation.call(this,"buffer",e,t)}hasRepresentation(e){return-1!==this.reprList.indexOf(e)}eachRepresentation(e){this.reprList.slice().forEach(e)}removeRepresentation(e){const t=this.reprList.indexOf(e);-1!==t&&(this.reprList.splice(t,1),e.dispose(),this.signals.representationRemoved.dispatch(e))}updateRepresentations(e){this.reprList.forEach((t=>t.update(e))),this.stage.viewer.requestRender()}removeAllRepresentations(){this.eachRepresentation((e=>e.dispose()))}dispose(){this.removeAllAnnotations(),this.removeAllRepresentations(),this.reprList.length=0,this.signals.disposed.dispatch()}setVisibility(e){return this.parameters.visible=e,this.eachRepresentation((e=>e.updateVisibility())),this.eachAnnotation((e=>e.updateVisibility())),this.signals.visibilityChanged.dispatch(e),this}setStatus(e){return this.parameters.status=e,this.signals.statusChanged.dispatch(e),this}setName(e){return this.parameters.name=e,this.signals.nameChanged.dispatch(e),this}getBox(...e){return this.getBoxUntransformed(...e).clone().applyMatrix4(this.matrix)}getCenter(...e){return this.getCenterUntransformed(...e).clone().applyMatrix4(this.matrix)}getZoom(...e){return this.stage.getZoomForBox(this.getBox(...e))}getBoxUntransformed(...e){return new bt}getCenterUntransformed(...e){return this.getBoxUntransformed().getCenter(new _t)}autoView(e){this.stage.animationControls.zoomMove(this.getCenter(),this.getZoom(),uo(e,0))}}class rg{constructor(e=[]){this.list=e;const t=e.length;for(let i=0;i0?this.list[0]:void 0}forEach(e){return this.list.forEach(e),this}dispose(){return this.forEach((e=>e.dispose()))}}class sg extends rg{setParameters(e){return this.forEach((t=>t.setParameters(e)))}setVisibility(e){return this.forEach((t=>t.setVisibility(e)))}setSelection(e){return this.forEach((t=>t.setSelection(e)))}setColor(e){return this.forEach((t=>t.setColor(e)))}update(e){return this.forEach((t=>t.update(e)))}build(e){return this.forEach((t=>t.build(e)))}dispose(e){return this.forEach((e=>e.dispose()))}}const ag=Object.assign({defaultStep:1,defaultTimeout:50,defaultInterpolateType:"",defaultInterpolateStep:5,defaultMode:"loop",defaultDirection:"forward",initialFrame:0},Kp);class og extends Zp{constructor(e,t,i={}){super(e,Object.assign({name:t.name},i)),this.trajectory=t,this.signals=Object.assign(this.signals,{frameChanged:new Yo.Signal,playerChanged:new Yo.Signal,countChanged:new Yo.Signal,parametersChanged:new Yo.Signal}),t.signals.frameChanged.add((e=>{this.signals.frameChanged.dispatch(e)})),t.signals.playerChanged.add((e=>{this.signals.playerChanged.dispatch(e)})),t.signals.countChanged.add((e=>{this.signals.countChanged.dispatch(e)})),void 0!==i.initialFrame&&this.setFrame(i.initialFrame)}get defaultParameters(){return ag}get type(){return"trajectory"}setFrame(e){this.trajectory.setFrame(e)}setParameters(e={}){this.trajectory.setParameters(e),this.signals.parametersChanged.dispatch(e)}dispose(){this.trajectory.dispose(),super.dispose()}}class lg{constructor(e,t){this.name=e,this.path=t,this.coordinates=[],this.boxes=[],this.times=[],this.timeOffset=0,this.deltaTime=1}get type(){return"Frames"}}class cg{constructor(e,t){let i,n;if(this.A=new af(3,3),this.W=new af(1,3),this.U=new af(3,3),this.V=new af(3,3),this.VH=new af(3,3),this.R=new af(3,3),this.tmp=new af(3,3),this.c=new af(3,3),e instanceof vp)i=e.atomCount;else{if(!(e instanceof Float32Array))return;i=e.length/3}if(t instanceof vp)n=t.atomCount;else{if(!(t instanceof Float32Array))return;n=t.length/3}const r=Math.min(i,n),s=new af(3,r),a=new af(3,r);this.coords1t=new af(r,3),this.coords2t=new af(r,3),this.transformationMatrix=new qt,this.c.data.set([1,0,0,0,1,0,0,0,-1]),this.prepCoords(e,s,r,!1),this.prepCoords(t,a,r,!1),this._superpose(s,a)}_superpose(t,i){this.mean1=uf(t),this.mean2=uf(i),hf(t,this.mean1),hf(i,this.mean2),of(this.coords1t,t),of(this.coords2t,i),lf(this.A,this.coords2t,this.coords1t),gf(this.A,this.W,this.U,this.V),function(e,t){const i=e.data,n=t.data,r=i[4],s=i[8],a=i[5],o=i[7],l=i[0],c=l*r,u=l*a,h=i[3],d=i[1],f=h*d,m=i[2],p=h*m,g=i[6],_=g*d,y=g*m,v=1/(c*s-u*o-f*s+p*o+_*a-y*r);n[0]=(r*s-a*o)*v,n[1]=-(d*s-m*o)*v,n[2]=-(-d*a+m*r)*v,n[3]=-(h*s-a*g)*v,n[4]=(l*s-y)*v,n[5]=-(u-p)*v,n[6]=-(-h*o+r*g)*v,n[7]=-(l*o-_)*v,n[8]=(c-f)*v}(this.V,this.VH),cf(this.R,this.U,this.VH),function(e){const t=e.data;return t[0]*t[4]*t[8]-t[0]*t[5]*t[7]-t[3]*t[1]*t[8]+t[3]*t[2]*t[7]+t[6]*t[1]*t[5]-t[6]*t[2]*t[4]}(this.R)<0&&(e.Debug&&Fl.log("R not a right handed system"),cf(this.tmp,this.c,this.VH),cf(this.R,this.U,this.tmp));const n=new af(4,4),r=new af(4,4),s=new af(4,4),a=new af(4,4),o=new af(4,4),l=new af(4,4),c=this.R.data,u=this.mean1,h=this.mean2;a.data.set([1,0,0,-u[0],0,1,0,-u[1],0,0,1,-u[2],0,0,0,1]),o.data.set([c[0],c[1],c[2],0,c[3],c[4],c[5],0,c[6],c[7],c[8],0,0,0,0,1]),l.data.set([1,0,0,h[0],0,1,0,h[1],0,0,1,h[2],0,0,0,1]),of(r,a),lf(n,o,r),of(s,n),lf(r,l,s),of(n,r),this.transformationMatrix.elements=n.data}prepCoords(e,t,i,n){let r=0;const s=t.data;let a=3,o=3*i;if(n&&(o=4*i,a=4),e instanceof vp)e.eachAtom((function(e){r{e!==this&&this.pause()}),this);const i=uo(e.frameCount,1);this.traj=e,this.parameters=ho(t,ug),this.parameters.end=Math.min(uo(t.end,i-1),i-1),this.parameters.step=uo(t.step,Math.ceil((i+1)/100)),this._currentFrame=this.parameters.start,this._direction="bounce"===this.parameters.direction?"forward":this.parameters.direction,e.signals.countChanged.add((e=>{this.parameters.end=Math.min(uo(this.parameters.end,e-1),e-1)}),this),this._animate=this._animate.bind(this)}get isRunning(){return this._run}setParameters(e={}){fo(this.parameters,e),void 0!==e.direction&&"bounce"!==this.parameters.direction&&(this._direction=this.parameters.direction)}_animate(){if(!this._run)return;this._currentTime=window.performance.now();const e=this._currentTime-this._previousTime,t=this.parameters.interpolateType?this.parameters.interpolateStep:1,i=this.parameters.timeout/t,n=this.traj;if(n&&n.frameCount&&!n.inProgress&&e>=i)if(this.parameters.interpolateType)if(this._currentStep>this.parameters.interpolateStep&&(this._currentStep=1),1===this._currentStep&&(this._currentFrame=this._nextInterpolated()),n.hasFrame(this._currentFrame)){this._currentStep+=1;const e=this._currentStep/(this.parameters.interpolateStep+1),[t,i,r,s]=this._currentFrame;n.setFrameInterpolated(t,i,r,s,e,this.parameters.interpolateType),this._previousTime=this._currentTime}else n.loadFrame(this._currentFrame);else{const e=this._next();n.hasFrame(e)?(n.setFrame(e),this._previousTime=this._currentTime):n.loadFrame(e)}window.requestAnimationFrame(this._animate)}_next(){const e=this.parameters;let t;return t="forward"===this._direction?this.traj.currentFrame+e.step:this.traj.currentFrame-e.step,(t>e.end||t=e.end?i=e.start:"backward"===e.direction&&t<=e.start&&(i=e.end),this.traj.setFrame(i),this._run=!0,this._animate(),this.signals.startedRunning.dispatch()}}pause(){this._run=!1,this.signals.haltedRunning.dispatch()}stop(){this.pause(),this.traj.setFrame(this.parameters.start)}}class dg{constructor(e,t,i={}){this.signals={countChanged:new Yo.Signal,frameChanged:new Yo.Signal,playerChanged:new Yo.Signal},this.frameCache={},this.loadQueue={},this.boxCache={},this.pathCache={},this.frameCacheSize=0,this._frameCount=0,this._currentFrame=-1,this._disposed=!1,this.deltaTime=uo(i.deltaTime,0),this.timeOffset=uo(i.timeOffset,0),this.centerPbc=uo(i.centerPbc,!1),this.removePbc=uo(i.removePbc,!1),this.removePeriodicity=uo(i.removePeriodicity,!1),this.superpose=uo(i.superpose,!1),this.name=e.replace(/^.*[\\/]/,""),this.trajPath=e,this.selection=new wl(uo(i.sele,"backbone and not hydrogen")),this.selection.signals.stringChanged.add((()=>{this.selectionIndices=this.structure.getAtomIndices(this.selection),this._resetCache(),this._saveInitialCoords(),this.setFrame(this._currentFrame)}))}get frameCount(){return this._frameCount}get currentFrame(){return this._currentFrame}_init(e){this.setStructure(e),this._loadFrameCount(),this.setPlayer(new hg(this))}_loadFrameCount(){}setStructure(e){this.structure=e,this.atomCount=e.atomCount,this.backboneIndices=this._getIndices(new wl("backbone and not hydrogen")),this._makeAtomIndices(),this._saveStructureCoords(),this.selectionIndices=this._getIndices(this.selection),this._resetCache(),this._saveInitialCoords(),this.setFrame(this._currentFrame)}_saveInitialCoords(){this.structure.hasCoords()?(this.initialCoords=new Float32Array(this.structureCoords),this._makeSuperposeCoords()):this.frameCache[0]?(this.initialCoords=new Float32Array(this.frameCache[0]),this._makeSuperposeCoords()):this.loadFrame(0,(()=>this._saveInitialCoords()))}_saveStructureCoords(){this.structureCoords=this.structure.getAtomData({what:{position:!0}}).position}setSelection(e){return this.selection.setString(e),this}_getIndices(e){let t=0;const i=e.test,n=[];return i&&this.structure.eachAtom((e=>{i(e)&&n.push(t),t+=1})),n}_makeSuperposeCoords(){const e=3*this.selectionIndices.length;this.coords1=new Float32Array(e),this.coords2=new Float32Array(e);const t=this.initialCoords,i=this.coords2;for(let n=0;n!!this.frameCache[e])):!!this.frameCache[e]}setFrame(e,t){return void 0===e||(this.inProgress=!0,-1===e||this.frameCache[e]?(this._updateStructure(e),t&&t()):this.loadFrame(e,(()=>{this._updateStructure(e),t&&t()}))),this}_interpolate(e,t,i,n,r,s){const a=this.frameCache;let o;o="spline"===s?function(e,t,i,n,r){const s=e.length,a=new Float32Array(s);for(let o=0;o{this._interpolate(e,t,i,n,r,s),a&&a()})):(this._interpolate(e,t,i,n,r,s),a&&a()),this}loadFrame(e,t){Array.isArray(e)?e.forEach((e=>{this.loadQueue[e]||this.frameCache[e]||(this.loadQueue[e]=!0,this._loadFrame(e,(()=>{delete this.loadQueue[e]})))})):this.loadQueue[e]||this.frameCache[e]||(this.loadQueue[e]=!0,this._loadFrame(e,(()=>{delete this.loadQueue[e],t&&t()})))}_loadFrame(e,t){Fl.error("Trajectory._loadFrame not implemented",e,t)}_updateStructure(e){this._disposed?console.error("updateStructure: traj disposed"):(-1===e?this.structureCoords&&this.structure.updatePosition(this.structureCoords):this.structure.updatePosition(this.frameCache[e]),this.structure.trajectory={name:this.trajPath,frame:e},this._currentFrame=e,this.inProgress=!1,this.signals.frameChanged.dispatch(e))}_doSuperpose(e){const t=3*this.selectionIndices.length,i=this.coords1,n=this.coords2;for(let n=0;n0&&this.centerPbc){const e=[t[0],t[4],t[8]],n=function(e,t,i){return[bc(t,i[0],3,0,e),bc(t,i[1],3,1,e),bc(t,i[2],3,2,e)]}(this.backboneIndices,i,e);!function(e,t,i){if(0===i[0]||0===i[8]||0===i[4])return;const n=e.length,r=i[0],s=i[1],a=i[2],o=-t[0]+r+r/2,l=-t[1]+s+s/2,c=-t[2]+a+a/2;for(let t=0;t.5&&(e[r+n]-=t[3*n+n]*Math.round(s))}}(i,t,e)}this.removePbc&&function(e,t){if(0===t[0]||0===t[8]||0===t[4])return;const i=e.length;for(let n=3;n.9*t[3*i+i])if(r>0)for(let r=0;r<3;++r)e[n+r]-=t[3*i+r];else for(let r=0;r<3;++r)e[n+r]+=t[3*i+r]}}(i,t)}this.selectionIndices.length>0&&this.coords1&&this.superpose&&this._doSuperpose(i),this.frameCache[e]=i,this.boxCache[e]=t,this.frameCacheSize+=1}_setFrameCount(e){e!==this._frameCount&&(this._frameCount=e,this.signals.countChanged.dispatch(e))}dispose(){this._resetCache(),this._disposed=!0,this.player&&this.player.stop()}setPlayer(e){this.player=e,this.signals.playerChanged.dispatch(e)}getFrameTime(e){return this.timeOffset+e*this.deltaTime}}class fg extends dg{constructor(e,t,i){const n=i||{};n.timeOffset=uo(n.timeOffset,e.timeOffset),n.deltaTime=uo(n.deltaTime,e.deltaTime),super("",t,n),this.name=e.name,this.path=e.path,this.frames=e.coordinates,this.boxes=e.boxes,this._init(t)}get type(){return"frames"}_makeAtomIndices(){"StructureView"===this.structure.type?this.atomIndices=this.structure.getAtomIndices():this.atomIndices=void 0}_loadFrame(e,t){let i;const n=this.frames[e];if(this.atomIndices){const e=this.atomIndices,t=e.length;i=new Float32Array(3*t);for(let r=0;r{const e=n.response;if(!e)return void Fl.error(`empty arrayBuffer for '${r}'`);const s=new Int32Array(e,0,1)[0],a=new Float32Array(e,8,9),o=new Float32Array(e,44);this._process(t,a,o,s),"function"==typeof i&&i()}),!1),n.send(s)}_loadFrameCount(){const t=new XMLHttpRequest,i=e.TrajectoryDatasource.getCountUrl(this.trajPath);t.open("GET",i,!0),t.addEventListener("load",(()=>{this._setFrameCount(parseInt(t.response))}),!1),t.send()}}class gg extends dg{constructor(e,t,i){super("",t,i),this.requestCallback=e,this._init(t)}get type(){return"callback"}_makeAtomIndices(){const e=[];if("StructureView"===this.structure.type){const t=this.structure.getAtomIndices(),i=t.length;let n=t[0],r=t[0];for(let s=1;s{this._process(e,i,n,r),"function"==typeof t&&t()}),e,this.atomIndices)}_loadFrameCount(){this.requestCallback((e=>this._setFrameCount(e)))}}vp.prototype.getView=function(e){return new _g(this,e)};class _g extends vp{constructor(e,t){super(),this.structure=e,this.selection=t,this.center=new _t,this.boundingBox=new bt,this._bp=this.getBondProxy(),this._ap=this.getAtomProxy(),this._rp=this.getResidueProxy(),this._cp=this.getChainProxy(),this.selection&&this.selection.signals.stringChanged.add(this.refresh,this),this.structure.signals.refreshed.add(this.refresh,this),this.refresh()}init(){}get type(){return"StructureView"}get name(){return this.structure.name}get path(){return this.structure.path}get title(){return this.structure.title}get id(){return this.structure.id}get data(){return this.structure.data}get atomSetDict(){return this.structure.atomSetDict}get biomolDict(){return this.structure.biomolDict}get entityList(){return this.structure.entityList}get unitcell(){return this.structure.unitcell}get frames(){return this.structure.frames}get boxes(){return this.structure.boxes}get validation(){return this.structure.validation}get bondStore(){return this.structure.bondStore}get backboneBondStore(){return this.structure.backboneBondStore}get rungBondStore(){return this.structure.rungBondStore}get atomStore(){return this.structure.atomStore}get residueStore(){return this.structure.residueStore}get chainStore(){return this.structure.chainStore}get modelStore(){return this.structure.modelStore}get atomMap(){return this.structure.atomMap}get residueMap(){return this.structure.residueMap}get bondHash(){return this.structure.bondHash}get spatialHash(){return this.structure.spatialHash}get _hasCoords(){return this.structure._hasCoords}set _hasCoords(e){this.structure._hasCoords=e}refresh(){e.Debug&&Fl.time("StructureView.refresh"),this.atomSetCache={};const t=this.structure;if(this.selection.isAllSelection()&&t!==this&&t.atomSet&&t.bondSet){this.atomSet=t.atomSet.clone(),this.bondSet=t.bondSet.clone();for(let e in this.atomSetDict){const t=this.atomSetDict[e];this.atomSetCache["__"+e]=t.clone()}this.atomCount=t.atomCount,this.bondCount=t.bondCount,this.boundingBox.copy(t.boundingBox),this.center.copy(t.center)}else if(this.selection.isNoneSelection()&&t!==this&&t.atomSet&&t.bondSet){this.atomSet=new Ih(t.atomCount),this.bondSet=new Ih(t.bondCount);for(let e in this.atomSetDict)this.atomSetCache["__"+e]=new Ih(t.atomCount);this.atomCount=0,this.bondCount=0,this.boundingBox.makeEmpty(),this.center.set(0,0,0)}else{this.atomSet=this.getAtomSet(this.selection,!0),t.atomSet&&(this.atomSet=this.atomSet.intersection(t.atomSet)),this.bondSet=this.getBondSet();for(let e in this.atomSetDict){const t=this.atomSetDict[e];this.atomSetCache["__"+e]=t.makeIntersection(this.atomSet)}this.atomCount=this.atomSet.getSize(),this.bondCount=this.bondSet.getSize(),this.boundingBox=this.getBoundingBox(),this.center=this.boundingBox.getCenter(new _t)}e.Debug&&Fl.timeEnd("StructureView.refresh"),this.signals.refreshed.dispatch()}setSelection(e){this.selection=e,this.refresh()}getSelection(e){const t=[];e&&e.string&&t.push(e.string);const i=this.structure.getSelection();i&&i.string&&t.push(i.string),this.selection&&this.selection.string&&t.push(this.selection.string);let n="";return t.length>0&&(n=`( ${t.join(" ) AND ( ")} )`),new wl(n)}getStructure(){return this.structure.getStructure()}eachBond(e,t){this.structure.eachBond(e,this.getSelection(t))}eachAtom(e,t){const i=this.getAtomProxy(),n=this.getAtomSet(t),r=this.atomStore.count;if(n.getSize()=this.V[n][r]?(i="S",this.score=this.S[n][r]):this.V[n][r]>=this.H[n][r]?(i="V",this.score=this.V[n][r]):(i="H",this.score=this.H[n][r]),e.Debug&&Fl.log("Alignment: SCORE",this.score),e.Debug&&Fl.log("Alignment: S, V, H",this.S[n][r],this.V[n][r],this.H[n][r]);n>0&&r>0;)"S"===i?this.S[n][r]===this.S[n-1][r-1]+t(n-1,r-1)?(this.ali1=this.seq1[n-1]+this.ali1,this.ali2=this.seq2[r-1]+this.ali2,--n,--r,i="S"):this.S[n][r]===this.V[n][r]?i="V":this.S[n][r]===this.H[n][r]?i="H":(--n,--r):"V"===i?this.V[n][r]===this.V[n-1][r]+this.gapExtensionPenalty?(this.ali1=this.seq1[n-1]+this.ali1,this.ali2="-"+this.ali2,--n,i="V"):this.V[n][r]===this.S[n-1][r]+this.gap(0)?(this.ali1=this.seq1[n-1]+this.ali1,this.ali2="-"+this.ali2,--n,i="S"):--n:"H"===i?this.H[n][r]===this.H[n][r-1]+this.gapExtensionPenalty?(this.ali1="-"+this.ali1,this.ali2=this.seq2[r-1]+this.ali2,--r,i="H"):this.H[n][r]===this.S[n][r-1]+this.gap(0)?(this.ali1="-"+this.ali1,this.ali2=this.seq2[r-1]+this.ali2,--r,i="S"):--r:Fl.error("Alignment: no matrix");for(;n>0;)this.ali1=this.seq1[n-1]+this.ali1,this.ali2="-"+this.ali2,--n;for(;r>0;)this.ali1="-"+this.ali1,this.ali2=this.seq2[r-1]+this.ali2,--r;e.Debug&&Fl.timeEnd("Alignment.trace"),e.Debug&&Fl.log([this.ali1,this.ali2])}}function wg(e,t,i=!1,n="",r=""){let s,a,o,l,c;if(i){let i=e,u=t;n&&r&&(i=e.getView(new wl(n)),u=t.getView(new wl(r)));const h=i.getSequence(),d=u.getSequence(),f=new xg(h.join(""),d.join(""));let m,p;f.calc(),f.trace(),s=0,a=0,o=f.ali1.length;const g=[],_=[];for(let e=0;ee[t]))}}}(),this.spacefillRepresentation=this.addRepresentation("spacefill",{sele:"none",opacity:Bl.opacity,color:Bl.color,disablePicking:!0,radiusType:"data"},!0),this.distanceRepresentation=this.addRepresentation("distance",Bl,!0),this.angleRepresentation=this.addRepresentation("angle",Bl,!0),this.dihedralRepresentation=this.addRepresentation("dihedral",Bl,!0),this.measureRepresentations=new sg([this.spacefillRepresentation,this.distanceRepresentation,this.angleRepresentation,this.dihedralRepresentation]),this.setDefaultAssembly(this.parameters.defaultAssembly),this.structure.signals.refreshed.add((()=>{this.updateRepresentations({position:!0})}))}get defaultParameters(){return Sg}get type(){return"structure"}initSelection(e){this.selection=new wl(e),this.structureView=new _g(this.structure,this.selection),this.selection.signals.stringChanged.add((()=>{this.structureView.setSelection(this.selection),this.rebuildRepresentations(),this.rebuildTrajectories()}))}setSelection(e){return this.parameters.sele=e,this.selection.setString(e),this}setDefaultAssembly(e){if(void 0===this.structure.biomolDict[e]&&(e=""),this.parameters.defaultAssembly!==e){const t={defaultAssembly:e};this.reprList.forEach((e=>e.setParameters(t))),this.measureRepresentations.setParameters(t),this.parameters.defaultAssembly=e,this.signals.defaultAssemblyChanged.dispatch(e)}return this}rebuildRepresentations(){this.reprList.forEach((e=>{e.build()})),this.measureRepresentations.build()}rebuildTrajectories(){this.trajList.forEach((e=>{e.trajectory.setStructure(this.structureView)}))}updateRepresentations(e){super.updateRepresentations(e),this.measureRepresentations.update(e)}updateRepresentationMatrices(){super.updateRepresentationMatrices(),this.measureRepresentations.setParameters({matrix:this.matrix})}addRepresentation(e,t={},i=!1){t.defaultAssembly=this.parameters.defaultAssembly;const n=this._addRepresentation(e,this.structureView,t,i);return i||n.signals.parametersChanged.add((()=>this.measureUpdate())),n}addTrajectory(e="",t={}){const i=function(e,t,i){let n;return n=e&&e instanceof lg?new fg(e,t,i):!e&&t.frames?new mg(e,t,i):e&&"function"==typeof e?new gg(e,t,i):new pg(e,t,i),n}(e,this.structureView,t),n=new og(this.stage,i,t);return this.trajList.push(n),this.signals.trajectoryAdded.dispatch(n),n}removeTrajectory(e){const t=this.trajList.indexOf(e);-1!==t&&this.trajList.splice(t,1),e.dispose(),this.signals.trajectoryRemoved.dispatch(e)}dispose(){this.trajList.slice().forEach((e=>e.dispose())),this.trajList.length=0,this.structure.dispose(),this.measureRepresentations.dispose(),super.dispose()}autoView(e,t){"number"==typeof e&&(t=e,e=""),this.stage.animationControls.zoomMove(this.getCenter(e),this.getZoom(e),uo(t,0))}getBoxUntransformed(e){let t;return t=e?this.structureView.getBoundingBox(new wl(e)):this.structureView.boundingBox,t}getCenterUntransformed(e){return e&&"string"==typeof e?this.structure.atomCenter(new wl(e)):this.structure.center}superpose(e,t,i,n){return wg(this.structureView,e.structureView,t,i,n),this.updateRepresentations({position:!0}),this}getMaxRepresentationRadius(e){let t=0;const i=this.structure.getAtomProxy(e);return this.eachRepresentation((e=>{if(e.getVisibility()){const n=e.repr;t=Math.max(n.getAtomRadius(i),t)}})),t}measurePick(e){const t=this.pickBuffer.count;if(this.lastPick===e.index&&t>=1){if(t>1){const e=this.pickBuffer.data,i=this.pickBuffer.data.sort();this.pickDict.has(i)?this.pickDict.del(i):this.pickDict.add(i,e),2===t?this.distanceRepresentation.setParameters({atomPair:this.pickDict.values.filter((e=>2===e.length))}):3===t?this.angleRepresentation.setParameters({atomTriple:this.pickDict.values.filter((e=>3===e.length))}):4===t&&this.dihedralRepresentation.setParameters({atomQuad:this.pickDict.values.filter((e=>4===e.length))})}this.pickBuffer.clear(),this.lastPick=void 0}else this.pickBuffer.has(e.index)||this.pickBuffer.push(e.index),this.lastPick=e.index;this.measureUpdate()}measureClear(){this.pickBuffer.clear(),this.lastPick=void 0,this.spacefillRepresentation.setSelection("none")}measureBuild(){const e=this.measureData();this.distanceRepresentation.setParameters({atomPair:e.distance}),this.angleRepresentation.setParameters({atomTriple:e.angle}),this.dihedralRepresentation.setParameters({atomQuad:e.dihedral})}measureUpdate(){const e=this.pickBuffer.data,t={};e.forEach((e=>{const i=Math.max(.1,this.getMaxRepresentationRadius(e));t[e]=i*(2.3-zo(.1,2,i))})),this.spacefillRepresentation.setSelection(e.length?"@"+e.join(","):"none"),e.length&&this.spacefillRepresentation.setParameters({radiusData:t})}measureData(){const e=this.pickDict.values;return{distance:e.filter((e=>2===e.length)),angle:e.filter((e=>3===e.length)),dihedral:e.filter((e=>4===e.length))}}removeAllMeasurements(e){const t=this.pickDict,i=t.values,n=function(e){i.filter((t=>t.length===e)).forEach((e=>t.del(e.slice().sort())))};(!e||1&e)&&n(2),(!e||2&e)&&n(3),(!e||4&e)&&n(4),this.measureBuild()}removeMeasurement(e){this.pickDict.del(e.slice().sort()),this.measureBuild()}addMeasurement(e){if(e.length<2||e.length>4)return;const t=e.slice().sort();this.pickDict.has(t)||this.pickDict.add(t,e),this.measureBuild()}}Xl.add("structure",Mg),Xl.add("structureview",Mg);class Ag extends ng{constructor(e,t,i={}){super(e,t,Object.assign({name:t.name},i)),this.surface=t}get type(){return"surface"}addRepresentation(e,t={}){return this._addRepresentation(e,this.surface,t)}getBoxUntransformed(){return this.surface.boundingBox}getCenterUntransformed(){return this.surface.center}dispose(){this.surface.dispose(),super.dispose()}}Xl.add("surface",Ag);class Cg extends ng{constructor(e,t,i={}){super(e,t,Object.assign({name:t.name},i)),this.volume=t}get type(){return"volume"}addRepresentation(e,t={}){return this._addRepresentation(e,this.volume,t)}getBoxUntransformed(){return this.volume.boundingBox}getCenterUntransformed(){return this.volume.center}dispose(){this.volume.dispose(),super.dispose()}}Xl.add("volume",Cg);class Tg extends rg{addRepresentation(e,t){return this.forEach((i=>i.addRepresentation(e,t)))}autoView(e){return this.forEach((t=>t.autoView(e)))}}function Pg(e,t){return e instanceof RegExp?null!==t.name.match(e):t.name===e}const Eg=new _t,Ig={impostor:!0,quality:"medium",workerDefault:!0,sampleLevel:0,backgroundColor:"black",rotateSpeed:2,zoomSpeed:1.2,panSpeed:1,clipNear:0,clipFar:100,clipDist:10,clipMode:"scene",clipScale:"relative",fogNear:50,fogFar:100,cameraFov:40,cameraEyeSep:.3,cameraType:"perspective",lightColor:14540253,lightIntensity:1.2,ambientColor:14540253,ambientIntensity:.3,hoverTimeout:0,tooltip:!0,mousePreset:"default"};class Dg extends ng{constructor(e,t,i={}){super(e,t,Object.assign({name:t.name},i)),this.shape=t}get type(){return"shape"}addRepresentation(e,t={}){return this._addRepresentation(e,this.shape,t)}getBoxUntransformed(){return this.shape.boundingBox}getCenterUntransformed(){return this.shape.center}dispose(){this.shape.dispose(),super.dispose()}}function Rg(e,t,i,n){var r,s=arguments.length,a=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(a=(s<3?r(a):s>3?r(t,i,a):r(t,i))||a);return s>3&&a&&Object.defineProperty(t,i,a),a}function Lg(e,t,i,n){return new(i||(i=Promise))((function(r,s){function a(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){e.done?r(e.value):function(e){return e instanceof i?e:new i((function(t){t(e)}))}(e.value).then(a,o)}l((n=n.apply(e,t||[])).next())}))}Xl.add("shape",Dg),"function"==typeof SuppressedError&&SuppressedError;class kg extends qo{constructor(e){super(e),e.scale||(this.parameters.scale="rainbow",this.parameters.reverse=uo(e.reverse,!0)),this.scalePerModel={},e.structure.eachModel((e=>{this.parameters.domain=[e.atomOffset,e.atomEnd],this.scalePerModel[e.index]=this.getScale()}))}atomColor(e){return this.scalePerModel[e.modelIndex](e.index)}}Rg([Wo],kg.prototype,"atomColor",null),$l.add("atomindex",kg);class Og extends qo{constructor(e){if(super(e),e.scale||(this.parameters.scale="OrRd"),!e.domain){let t,i=1/0,n=-1/0;e.sele&&(t=new wl(e.sele)),e.structure.eachAtom((function(e){const t=e.bfactor;i=Math.min(i,t),n=Math.max(n,t)}),t),this.parameters.domain=[i,n]}this.bfactorScale=this.getScale()}atomColor(e){return this.bfactorScale(e.bfactor)}}Rg([Wo],Og.prototype,"atomColor",null),$l.add("bfactor",Og);class Ng extends qo{constructor(e){super(e),this.chainidDictPerModel={},this.scalePerModel={},e.scale||(this.parameters.scale="Spectral"),e.structure.eachModel((e=>{let t=0;const i={};e.eachChain((function(e){void 0===i[e.chainid]&&(i[e.chainid]=t,t+=1)})),this.parameters.domain=[0,t-1],this.chainidDictPerModel[e.index]=i,this.scalePerModel[e.index]=this.getScale()}))}atomColor(e){const t=this.chainidDictPerModel[e.modelIndex];return this.scalePerModel[e.modelIndex](t[e.chainid])}}Rg([Wo],Ng.prototype,"atomColor",null),$l.add("chainid",Ng);class Fg extends qo{constructor(e){super(e),this.scalePerModel={},e.scale||(this.parameters.scale="Spectral"),e.structure.eachModel((e=>{this.parameters.domain=[e.chainOffset,e.chainEnd],this.scalePerModel[e.index]=this.getScale()}))}atomColor(e){return this.scalePerModel[e.modelIndex](e.chainIndex)}}Rg([Wo],Fg.prototype,"atomColor",null),$l.add("chainindex",Fg);class Bg extends qo{constructor(e){super(e),this.chainnameDictPerModel={},this.scalePerModel={},e.scale||(this.parameters.scale="Spectral"),e.structure.eachModel((e=>{let t=0;const i={};e.eachChain((function(e){void 0===i[e.chainname]&&(i[e.chainname]=t,t+=1)})),this.parameters.domain=[0,t-1],this.chainnameDictPerModel[e.index]=i,this.scalePerModel[e.index]=this.getScale()}))}atomColor(e){const t=this.chainnameDictPerModel[e.modelIndex];return this.scalePerModel[e.modelIndex](t[e.chainname])}}Rg([Wo],Bg.prototype,"atomColor",null),$l.add("chainname",Bg);class zg extends qo{constructor(e){super(e),this.rsrzDict={},this.rsccDict={},e.scale||(this.parameters.scale="RdYlBu"),this.rsrzScale=this.getScale({domain:[2,0]}),this.rsccScale=this.getScale({domain:[.678,1]});const t=e.structure.validation;t&&(this.rsrzDict=t.rsrzDict,this.rsccDict=t.rsccDict)}atomColor(e){let t=e.resno+"";e.inscode&&(t+="^"+e.inscode),e.chainname&&(t+=":"+e.chainname),t+="/"+e.modelIndex;const i=this.rsrzDict[t];if(void 0!==i)return this.rsrzScale(i);const n=this.rsccDict[t];return void 0!==n?this.rsccScale(n):9474192}}Rg([Wo],zg.prototype,"atomColor",null),$l.add("densityfit",zg);const Ug={ARG:{CD:.1,CZ:.5,NE:-.1},ASN:{CG:.55,OD1:-.55},ASP:{CB:-.16,CG:.36,OD1:-.6,OD2:-.6},CYS:{CB:.19,SG:-.19},GLN:{CD:.55,OE1:-.55},GLU:{CD:.36,CG:-.16,OE1:-.6,OE2:-.6},HIS:{CB:.1,CD2:.2,CE1:.45,CG:.15,ND1:.05,NE2:.05},LYS:{CE:.25,NZ:.75},MET:{CE:.06,CG:.06,SD:-.12},PTR:{C:.55,CA:.1,CZ:.25,N:-.35,O:-.55,O1P:-.85,O2P:-.85,O3P:-.85,OG1:-1.1,P:1.4},SEP:{C:.55,CA:.1,CB:.25,N:-.35,O:-.55,O1P:-.85,O2P:-.85,O3P:-.85,OG1:-1.1,P:1.4},SER:{CB:.25,OG:-.25},THR:{CB:.25,OG1:-.25},TPO:{C:.55,CA:.1,CB:.25,N:-.35,O:-.55,OG1:-1.1,O1P:-.85,O2P:-.85,O3P:-.85,P:1.4},TRP:{CD1:.06,CD2:.1,CE2:-.04,CE3:-.03,CG:-.03,NE1:-.06},TYR:{CZ:.25,OH:-.25},backbone:{C:.55,O:-.55,N:-.35,CA:.1}};class Vg extends qo{constructor(e){super(e),this.delta=new _t,this.hCharges=[],e.scale||(this.parameters.scale="rwb"),e.domain||(this.parameters.domain=[-50,50]),this.scale=this.getScale(),this.charges=new Float32Array(e.structure.atomCount);const t=[];e.structure.eachAtom((e=>{var i;if(this.charges[e.index]=(null!==(i=e).partialCharge?i.partialCharge:i.isProtein()&&(Ug[i.resname]&&Ug[i.resname][i.atomname]||Ug.backbone[i.atomname])||0)*e.occupancy,"N"===e.atomname){if(e.bondCount>=3)return;if(e.bondToElementCount(1))return;const i=function(e,t=new _t){let i=!1,n=!1,r=!1;return t.set(2*e.x,2*e.y,2*e.z),e.eachBondedAtom((function(e){if(!i)return"H"===e.atomname?(t.set(e.x,e.y,e.z),void(i=!0)):void(n||"CA"!==e.atomname?r||"C"!==e.atomname||(r=!0,t.sub(e)):(t.sub(e),n=!0))})),i?t:n&&r?(t.normalize(),t.multiplyScalar(1.04),t.add(e),t):void 0}(e);void 0!==i&&(t.push(i),this.hCharges.push(.25*e.occupancy))}}));const i=e.structure.getBoundingBox();i.expandByScalar(1.04),this.hStore=function(e){const t=e.length,i=new Float32Array(t),n=new Float32Array(t),r=new Float32Array(t);for(let t=0;t{const r=t[e];0!==r&&(n+=r/i)})),this.hHash.eachWithin(e.x,e.y,e.z,12,((e,t)=>{const r=i[e];0!==r&&(n+=r/t)})),this.scale(332*n)}}Rg([Wo],Vg.prototype,"positionColor",null),$l.add("electrostatic",Vg);const $g={H:16777215,HE:14286847,LI:13402367,BE:12779264,B:16758197,C:9474192,N:3166456,O:16715021,F:9494608,NE:11789301,NA:11230450,MG:9109248,AL:12560038,SI:1578e4,P:16744448,S:16777008,CL:2093087,AR:8442339,K:9388244,CA:4062976,SC:15132390,TI:12567239,V:10921643,CR:9083335,MN:10255047,FE:14706227,CO:15765664,NI:5296208,CU:13140019,ZN:8224944,GA:12750735,GE:6721423,AS:12419299,SE:16752896,BR:10889513,KR:6076625,RB:7351984,SR:65280,Y:9764863,ZR:9756896,NB:7586505,MO:5551541,TC:3907230,RU:2396047,RH:687500,PD:27013,AG:12632256,CD:16767375,IN:10909043,SN:6717568,SB:10380213,TE:13924864,I:9699476,XE:9699476,CS:5707663,BA:51456,LA:7394559,CE:16777159,PR:14286791,ND:13107143,PM:10747847,SM:9437127,EU:6422471,GD:4587463,TB:3211207,DY:2097095,HO:65436,ER:58997,TM:54354,YB:48952,LU:43812,HF:5096191,TA:5089023,W:2200790,RE:2522539,OS:2516630,IR:1528967,PT:13684960,AU:16765219,HG:12105936,TL:10900557,PB:5724513,BI:10375093,PO:11230208,AT:7688005,RN:4358806,FR:4325478,RA:32e3,AC:7384058,TH:47871,PA:41471,U:36863,NP:33023,PU:27647,AM:5528818,CM:7888099,BK:9064419,CF:10565332,ES:11739092,FM:11739066,MD:11734438,NO:12389767,LR:13041766,RF:13369433,DB:13697103,SG:14221381,BH:14680120,HS:15073326,MT:15400998,DS:16777215,RG:16777215,CN:16777215,UUT:16777215,FL:16777215,UUP:16777215,LV:16777215,UUH:16777215,D:16777152,T:16777120};class Gg extends qo{constructor(e){e.value=uo(e.value,$g.C),super(e)}atomColor(e){const t=e.element;return"C"===t?this.parameters.value:$g[t]||16777215}}Rg([Wo],Gg.prototype,"atomColor",null),$l.add("element",Gg);class Hg extends qo{constructor(e){super(e),e.scale||(this.parameters.scale="Spectral"),e.domain||(this.parameters.domain=[0,e.structure.entityList.length-1]),this.entityindexScale=this.getScale()}atomColor(e){return this.entityindexScale(e.entityIndex)}}Rg([Wo],Hg.prototype,"atomColor",null),$l.add("entityindex",Hg);class jg extends qo{atomColor(e){const t=e.entity;switch(t?t.entityType:void 0){case 1:return 8374655;case 2:return 16629894;case 3:return 12496596;case 4:return 3697840;default:return 16777113}}}Rg([Wo],jg.prototype,"atomColor",null),$l.add("entitytype",jg);class Wg extends qo{constructor(e){super(e),this.geoAtomDict={},this.geoDict={};const t=e.structure.validation;t&&(this.geoAtomDict=t.geoAtomDict,this.geoDict=t.geoDict)}atomColor(e){let t,i=e.resno+"";e.inscode&&(i+="^"+e.inscode),e.chainname&&(i+=":"+e.chainname),i+="/"+e.modelIndex;const n=this.geoAtomDict[i];if(void 0!==n){const i=n[e.atomname]||0;r=i,t=16843009*((r=(858993459&(r-=r>>1&1431655765))+(r>>2&858993459))+(r>>4)&252645135)>>24}else t=this.geoDict[i]||0;var r;return 0===t?2188972:1===t?16703627:2===t?16018755:t>=3?10813478:9474192}}Rg([Wo],Wg.prototype,"atomColor",null),$l.add("geoquality",Wg);class qg extends qo{constructor(e){super(e),this.resHF={},e.scale||(this.parameters.scale="RdYlGn");for(const e in Yh)this.resHF[e]=Yh[e][0];if(this.defaultResidueHydrophobicity=Kh[0],!e.domain){let e=1/0,t=-1/0;for(const i in this.resHF){const n=this.resHF[i];e=Math.min(e,n),t=Math.max(t,n)}this.parameters.domain=[e,0,t]}this.hfScale=this.getScale()}atomColor(e){return this.hfScale(this.resHF[e.resname]||this.defaultResidueHydrophobicity)}}Rg([Wo],qg.prototype,"atomColor",null),$l.add("hydrophobicity",qg);class Xg extends qo{constructor(e){super(e),e.scale||(this.parameters.scale="rainbow"),e.domain||(this.parameters.domain=[0,e.structure.modelStore.count]),this.modelindexScale=this.getScale()}atomColor(e){return this.modelindexScale(e.modelIndex)}}Rg([Wo],Xg.prototype,"atomColor",null),$l.add("modelindex",Xg);class Yg extends qo{atomColor(e){switch(e.residueType.moleculeType){case 1:return 3697840;case 2:return 15729279;case 3:return 12496596;case 4:return 16629894;case 5:return 12540695;case 6:return 8374655;default:return 16777113}}}Rg([Wo],Yg.prototype,"atomColor",null),$l.add("moleculetype",Yg);class Kg extends qo{constructor(e){super(e),e.scale||(this.parameters.scale="PuBu"),e.domain||(this.parameters.domain=[0,1]),this.occupancyScale=this.getScale()}atomColor(e){return this.occupancyScale(e.occupancy)}}Rg([Wo],Kg.prototype,"atomColor",null),$l.add("occupancy",Kg);class Zg extends qo{constructor(e){super(e),e.scale||(this.parameters.scale="rwb"),e.domain||(this.parameters.domain=[-1,1]),this.partialchargeScale=this.getScale()}atomColor(e){return this.partialchargeScale(e.partialCharge||0)}}function Qg(){return 16777215*Math.random()}Rg([Wo],Zg.prototype,"atomColor",null),$l.add("partialcharge",Zg);class Jg extends qo{atomColor(){return Qg()}volumeColor(){return Qg()}positionColor(){return Qg()}}Rg([Wo],Jg.prototype,"atomColor",null),Rg([Wo],Jg.prototype,"volumeColor",null),Rg([Wo],Jg.prototype,"positionColor",null),$l.add("random",Jg);class e_ extends qo{constructor(e){super(e),this.rciDict={},e.scale||(this.parameters.scale="RdYlBu"),this.rciScale=this.getScale({domain:[.6,0]});const t=e.structure.validation;t&&(this.rciDict=t.rciDict)}atomColor(e){let t=`[${e.resname}]${e.resno}`;e.chainname&&(t+=":"+e.chainname);const i=this.rciDict[t];return void 0!==i?this.rciScale(i):9474192}}Rg([Wo],e_.prototype,"atomColor",null),$l.add("randomcoilindex",e_);class t_ extends qo{constructor(e){super(e),this.scalePerChain={},e.scale||(this.parameters.scale="rainbow",this.parameters.reverse=uo(e.reverse,!0)),e.structure.eachChain((e=>{this.parameters.domain=[e.residueOffset,e.residueEnd],this.scalePerChain[e.index]=this.getScale()}))}atomColor(e){return this.scalePerChain[e.chainIndex](e.residueIndex)}}Rg([Wo],t_.prototype,"atomColor",null),$l.add("residueindex",t_);const i_={ALA:9240460,ARG:124,ASN:16743536,ASP:10485826,CYS:16777072,GLN:16731212,GLU:6684672,GLY:16777215,HIS:7368959,ILE:19456,LEU:4546117,LYS:4671416,MET:12099650,PHE:5459026,PRO:5395026,SER:16740418,THR:12078080,TRP:5195264,TYR:9203788,VAL:16747775,ASX:16711935,GLX:16711935,ASH:16711935,GLH:16711935,A:14423100,G:3329330,I:10145074,X:8190976,C:16766720,T:4286945,U:4251856,D:35723,DA:14423100,DG:3329330,DI:10145074,DX:8190976,DC:16766720,DT:4286945,DU:4251856,DD:35723};class n_ extends qo{atomColor(e){return i_[e.resname]||16711935}}Rg([Wo],n_.prototype,"atomColor",null),$l.add("resname",n_);const r_=16711808,s_=10485888,a_=6291584,o_=16762880,l_=6324479,c_=16777215,u_=11403518,h_=16580962,d_=10921722;class f_ extends qo{constructor(e){super(e),this.residueProxy=e.structure.getResidueProxy()}atomColor(e){const t=e.sstruc,i=this.residueProxy;return"h"===t?r_:"g"===t?s_:"i"===t?a_:"e"===t||"b"===t?o_:"t"===t?l_:(i.index=e.residueIndex,i.isDna()?u_:i.isRna()?h_:i.isSaccharide()?d_:i.isProtein()||"s"===t||"l"===t?c_:8421504)}}Rg([Wo],f_.prototype,"atomColor",null),$l.add("sstruc",f_);class m_ extends qo{constructor(e){var t,i;super(e),e.scale||(this.parameters.scale="rwb"),this.atomData=null===(t=this.parameters.data)||void 0===t?void 0:t.atomData,this.bondData=null===(i=this.parameters.data)||void 0===i?void 0:i.bondData,this.scale=this.getScale(this.parameters)}atomColor(e){var t;const i=null===(t=this.atomData)||void 0===t?void 0:t[e.index];return void 0!==i?this.scale(i):this.parameters.value}bondColor(e,t){var i;const n=null===(i=this.bondData)||void 0===i?void 0:i[e.index];return void 0!==n?this.scale(n):this.atomProxy?(this.atomProxy.index=t?e.atomIndex1:e.atomIndex2,this.atomColor(this.atomProxy)):this.parameters.value}}Rg([Wo],m_.prototype,"atomColor",null),Rg([Wo],m_.prototype,"bondColor",null),$l.add("structuredata",m_);class p_ extends qo{atomColor(){return this.parameters.value}bondColor(){return this.parameters.value}valueColor(){return this.parameters.value}volumeColor(){return this.parameters.value}}Rg([Wo],p_.prototype,"atomColor",null),Rg([Wo],p_.prototype,"bondColor",null),Rg([Wo],p_.prototype,"valueColor",null),Rg([Wo],p_.prototype,"volumeColor",null),$l.add("uniform",p_);class g_ extends qo{constructor(e){super(e),this.valueScale=this.getScale()}volumeColor(e){return this.valueScale(this.parameters.volume.data[e])}}Rg([Wo],g_.prototype,"volumeColor",null),$l.add("value",g_);class __ extends qo{constructor(e){super(e),this.vec=new _t,this.valueScale=this.getScale()}positionColor(e){const t=this.parameters.volume;if(!t||!t.inverseMatrix)return this.parameters.value;const i=this.vec,n=t.data,r=t.nx,s=t.ny,a=r*s;i.copy(e),i.applyMatrix4(t.inverseMatrix);const o=Math.floor(i.x),l=Math.floor(i.y),c=Math.floor(i.z),u=(c*s+l)*r+o,h=u+1,d=u+r,f=u+a,m=d+1,p=f+1,g=d+a,_=g+1,y=n[u],v=n[h],b=n[d],x=n[f],w=n[m],S=n[p],M=n[g],A=n[_],C=i.x-o,T=i.y-l,P=i.z-c,E=Fo(y,v,C),I=Fo(x,S,C),D=Fo(b,w,C),R=Fo(M,A,C),L=Fo(E,D,T),k=Fo(I,R,T),O=Fo(L,k,P);return this.valueScale(O)}}Rg([Wo],__.prototype,"positionColor",null),$l.add("volume",__);class y_ extends Nu{constructor(e,t,i){const n=i||{};if(super(e,t,n),this.type="structure",this.parameters=Object.assign({radiusType:{type:"select",options:cm.types},radiusData:{type:"hidden"},radiusSize:{type:"number",precision:3,max:10,min:.001},radiusScale:{type:"number",precision:3,max:10,min:.001},assembly:null,defaultAssembly:{type:"hidden"}},this.parameters),this.selection=new wl(n.sele),this.dataList=[],this.structure=e,this.structureView=this.structure.getView(this.selection),e.biomolDict){const t={default:"default","":e.unitcell?"AU":"FULL"};Object.keys(e.biomolDict).forEach((function(e){t[e]=e})),this.parameters.assembly={type:"select",options:t,rebuild:!0}}else this.parameters.assembly=null}get defaultScale(){return{vdw:1,covalent:1,bfactor:.01,sstruc:1}}init(e){const t=e||{};t.colorScheme=uo(t.colorScheme,"element"),this.setRadius(t.radius,t),this.radiusType=uo(t.radiusType,"vdw"),this.radiusData=uo(t.radiusData,{}),this.radiusSize=uo(t.radiusSize,1),this.radiusScale=uo(t.radiusScale,1),this.assembly=uo(t.assembly,"default"),this.defaultAssembly=uo(t.defaultAssembly,""),"auto"===t.quality&&(t.quality=this.getQuality()),super.init(t),this.selection.signals.stringChanged.add((()=>{this.build()})),this.build()}setRadius(e,t){const i=Object.keys(lm);return"string"==typeof e&&i.includes(e.toLowerCase())?t.radiusType=e:void 0!==e&&(t.radiusType="size",t.radiusSize=e),this}getAssembly(){const e="default"===this.assembly?this.defaultAssembly:this.assembly;return this.structure.biomolDict[e]}getQuality(){let e;const t=this.structureView,i=this.getAssembly();e=i?i.getAtomCount(t):t.atomCount,Rl&&(e*=4);return t.atomStore.count/t.residueStore.count<2&&(e*=10),e<15e3?"high":e<8e4?"medium":"low"}create(){if(0===this.structureView.atomCount)return;if(!this.structureView.hasCoords())return void(this.needsBuild=!0);this.needsBuild=!1;const e=this.getAssembly();if(e)e.partList.forEach(((e,t)=>{const i=e.getView(this.structureView);if(0===i.atomCount)return;const n=this.createData(i,t);n&&(n.sview=i,n.instanceList=e.getInstanceList(),this.dataList.push(n))}));else{const e=this.createData(this.structureView,0);e&&(e.sview=this.structureView,this.dataList.push(e))}}update(e){!this.lazy||this.visible?this.needsBuild?this.build():this.dataList.forEach((t=>{t.bufferList.length>0&&this.updateData(e,t)}),this):Object.assign(this.lazyProps.what,e)}updateData(e,t){this.build()}getColorParams(){return Object.assign(Object.assign({},super.getColorParams()),{structure:this.structure})}getRadiusParams(e){return{type:this.radiusType,scale:this.radiusScale,size:this.radiusSize,data:this.radiusData}}getAtomParams(e,t){return Object.assign({what:e,colorParams:this.getColorParams(),radiusParams:this.getRadiusParams()},t)}getBondParams(e,t){return Object.assign({what:e,colorParams:this.getColorParams(),radiusParams:this.getRadiusParams()},t)}getAtomRadius(e){if(this.structureView.atomSet.isSet(e.index)){return new cm(this.getRadiusParams()).atomRadius(e)}return 0}setSelection(e,t){return this.selection.setString(e,t),this}setParameters(e,t={},i=!1){const n=e||{};return this.setRadius(n.radius,n),void 0===n.radiusType&&void 0===n.radiusData&&void 0===n.radiusSize&&void 0===n.radiusScale||(t.radius=!0,Ol&&!this.disableImpostor||(i=!0)),void 0!==n.defaultAssembly&&n.defaultAssembly!==this.defaultAssembly&&("default"===this.assembly&&void 0===n.assembly||"default"===n.assembly)&&(i=!0),super.setParameters(n,t,i),this}getParameters(){return Object.assign(super.getParameters(),{sele:this.selection?this.selection.string:void 0,defaultAssembly:this.defaultAssembly})}attach(e){const t=this.viewer,i=this.bufferList;this.dataList.forEach((function(e){e.bufferList.forEach((function(n){i.push(n),t.add(n,e.instanceList)}))})),this.setVisibility(this.visible),e()}clear(){this.dataList.length=0,super.clear()}dispose(){this.structureView.dispose(),super.dispose()}}class v_ extends y_{constructor(e,t,i){super(e,t,i),this.n=0,this.parameters=Object.assign({labelVisible:{type:"boolean"},labelSize:{type:"number",precision:3,max:10,min:.001},labelColor:{type:"color"},labelFontFamily:{type:"select",options:{"sans-serif":"sans-serif",monospace:"monospace",serif:"serif"},buffer:"fontFamily"},labelFontStyle:{type:"select",options:{normal:"normal",italic:"italic"},buffer:"fontStyle"},labelFontWeight:{type:"select",options:{normal:"normal",bold:"bold"},buffer:"fontWeight"},labelsdf:{type:"boolean",buffer:"sdf"},labelXOffset:{type:"number",precision:1,max:20,min:-20,buffer:"xOffset"},labelYOffset:{type:"number",precision:1,max:20,min:-20,buffer:"yOffset"},labelZOffset:{type:"number",precision:1,max:20,min:-20,buffer:"zOffset"},labelAttachment:{type:"select",options:{"bottom-left":"bottom-left","bottom-center":"bottom-center","bottom-right":"bottom-right","middle-left":"middle-left","middle-center":"middle-center","middle-right":"middle-right","top-left":"top-left","top-center":"top-center","top-right":"top-right"},rebuild:!0},labelBorder:{type:"boolean",buffer:"showBorder"},labelBorderColor:{type:"color",buffer:"borderColor"},labelBorderWidth:{type:"number",precision:2,max:.3,min:0,buffer:"borderWidth"},labelBackground:{type:"boolean",rebuild:!0},labelBackgroundColor:{type:"color",buffer:"backgroundColor"},labelBackgroundMargin:{type:"number",precision:2,max:2,min:0,rebuild:!0},labelBackgroundOpacity:{type:"range",step:.01,max:1,min:0,buffer:"backgroundOpacity"},labelFixedSize:{type:"boolean",buffer:"fixedSize"},lineOpacity:{type:"range",min:0,max:1,step:.01},linewidth:{type:"integer",max:50,min:1,buffer:!0}},this.parameters,{flatShaded:null})}init(e){const t=e||{};this.labelVisible=uo(t.labelVisible,!0),this.labelSize=uo(t.labelSize,2),this.labelColor=uo(t.labelColor,16777215),this.labelFontFamily=uo(t.labelFontFamily,"sans-serif"),this.labelFontStyle=uo(t.labelFontstyle,"normal"),this.labelFontWeight=uo(t.labelFontWeight,"bold"),this.labelsdf=uo(t.labelsdf,"Chrome"===Il),this.labelXOffset=uo(t.labelXOffset,0),this.labelYOffset=uo(t.labelYOffset,0),this.labelZOffset=uo(t.labelZOffset,.5),this.labelAttachment=uo(t.labelAttachment,"bottom-left"),this.labelBorder=uo(t.labelBorder,!1),this.labelBorderColor=uo(t.labelBorderColor,"lightgrey"),this.labelBorderWidth=uo(t.labelBorderWidth,.15),this.labelBackground=uo(t.labelBackground,!1),this.labelBackgroundColor=uo(t.labelBackgroundColor,"lightgrey"),this.labelBackgroundMargin=uo(t.labelBackgroundMargin,.5),this.labelBackgroundOpacity=uo(t.labelBackgroundOpacity,1),this.labelFixedSize=uo(t.labelFixedSize,!1),this.lineOpacity=uo(t.lineOpacity,1),this.linewidth=uo(t.linewidth,2),super.init(t)}update(e){e.position?this.build():super.update(e)}updateData(e,t){const i={};if(e&&!e.labelSize||Object.assign(i,{size:Sc(this.n,this.labelSize)}),!e||e.labelColor){const e=new Oi(this.labelColor);Object.assign(i,{color:Mc(this.n,e.r,e.g,e.b)})}this.textBuffer.setAttributes(i)}setParameters(e,t={},i=!1){return e&&e.labelSize&&(t.labelSize=!0),e&&(e.labelColor||0===e.labelColor)&&(t.labelColor=!0,i=!0),super.setParameters(e,t,i),e&&void 0!==e.opacity&&this.textBuffer.setParameters({opacity:1}),e&&void 0!==e.labelVisible&&this.setVisibility(this.visible),this}setVisibility(e,t){return super.setVisibility(e,!0),this.textBuffer&&this.textBuffer.setVisibility(this.labelVisible&&this.visible),t||this.viewer.requestRender(),this}getLabelBufferParams(e={}){return super.getBufferParams(Object.assign({fontFamily:this.labelFontFamily,fontStyle:this.labelFontStyle,fontWeight:this.labelFontWeight,sdf:this.labelsdf,xOffset:this.labelXOffset,yOffset:this.labelYOffset,zOffset:this.labelZOffset,attachment:this.labelAttachment,showBorder:this.labelBorder,borderColor:this.labelBorderColor,borderWidth:this.labelBorderWidth,showBackground:this.labelBackground,backgroundColor:this.labelBackgroundColor,backgroundMargin:this.labelBackgroundMargin,backgroundOpacity:this.labelBackgroundOpacity,fixedSize:this.labelFixedSize,disablePicking:!0,visible:this.labelVisible},e,{opacity:1}))}getAtomRadius(){return 0}}function b_(e,t){const i=e.getAtomProxy(),n=new wl,r=t.length;if(0===r)return new Float32Array(0);const s=t[0].length,a=e.getAtomSet(),o=new Float32Array(r*s*3);let l=0;return t.forEach((function(t){let r=!1;for(let c=0;c 1.0 ){\ngl_FragColor = vec4( backgroundColor, backgroundOpacity );\n}else{\nfloat sdf = texture2D( fontTexture, texCoord ).a;\nif( showBorder ) sdf += borderWidth;\nfloat a = smoothstep(padding - gamma, padding + gamma, sdf);\nif( a < 0.2 ) discard;\na *= opacity;\nvec3 outgoingLight = vColor;\nif( showBorder && sdf < ( padding + borderWidth ) ){\noutgoingLight = borderColor;\n}\ngl_FragColor = vec4( outgoingLight, a );\n}\n#if defined( PICKING )\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");const M_={};const A_={font:"sans-serif",size:36,style:"normal",variant:"normal",weight:"normal",outline:3,width:1024,height:1024};class C_{constructor(e={}){this.gamma=1,this.mapped={},this.scratchW=0,this.scratchH=0,this.currentX=0,this.currentY=0,this.cutoff=.25,this.parameters=ho(e,A_);const t=this.parameters;this.radius=t.size/8,this.padding=t.size/3;const i=this.lineHeight=t.size+2*t.outline+Math.round(t.size/4),n=this.maxWidth=t.width/4,r=this.canvas=document.createElement("canvas");r.width=n,r.height=i;const s=this.context=this.canvas.getContext("2d",{willReadFrequently:!0});s.font=`${t.style} ${t.variant} ${t.weight} ${t.size}px ${t.font}`,s.fillStyle="black",s.textAlign="left",s.textBaseline="bottom",s.lineJoin="round",this.gridOuter=new Float64Array(i*n),this.gridInner=new Float64Array(i*n),this.f=new Float64Array(Math.max(i,n)),this.d=new Float64Array(Math.max(i,n)),this.z=new Float64Array(Math.max(i,n)+1),this.v=new Int16Array(Math.max(i,n)),this.data=new Uint8Array(t.width*t.height*4),this.canvas2=document.createElement("canvas"),this.canvas2.width=t.width,this.canvas2.height=t.height,this.context2=this.canvas2.getContext("2d"),this.placeholder=this.map(String.fromCharCode(65533));for(let e=32;e<=126;++e)this.map(String.fromCharCode(e));this.map(String.fromCharCode(176)),this.map(String.fromCharCode(8491)),this.texture=new $a(this.canvas2),this.texture.flipY=!1,this.texture.needsUpdate=!0}map(e){const t=this.parameters;return void 0===this.mapped[e]&&(this.draw(e),this.currentX+this.scratchW>t.width&&(this.currentX=0,this.currentY+=this.scratchH),this.currentY+this.scratchH>t.height&&console.warn("canvas to small"),this.mapped[e]={x:this.currentX,y:this.currentY,w:this.scratchW,h:this.scratchH},this.context2.drawImage(this.canvas,0,0,this.scratchW,this.scratchH,this.currentX,this.currentY,this.scratchW,this.scratchH),this.currentX+=this.scratchW),this.mapped[e]}get(e){return this.mapped[e]||this.placeholder}draw(e){const t=this.parameters,i=this.lineHeight,n=t.outline,r=this.context,s=this.maxWidth,a=n,o=i-t.outline,l=r.measureText(e),c=Math.min(s,Math.ceil(l.width+2*a+1)),u=c*i;r.clearRect(0,0,c,i),r.fillText(e,a,o);const h=r.getImageData(0,0,c,i),d=h.data;for(let e=0;e= 0.0 ) {\ntrimSegment( start, end );\n} else if ( end.z < 0.0 && start.z >= 0.0 ) {\ntrimSegment( end, start );\n}\n}\nvec4 clipStart = projectionMatrix * start;\nvec4 clipEnd = projectionMatrix * end;\nvec2 ndcStart = clipStart.xy / clipStart.w;\nvec2 ndcEnd = clipEnd.xy / clipEnd.w;\nvec2 dir = ndcEnd - ndcStart;\ndir.x *= aspect;\ndir = normalize( dir );\nvec2 offset = vec2( dir.y, - dir.x );\ndir.x /= aspect;\noffset.x /= aspect;\nif ( mapping.x < 0.0 ) offset *= - 1.0;\noffset *= linewidth;\noffset /= resolution.y;\nvec4 clip = ( mapping.y < 0.5 ) ? clipStart : clipEnd;\noffset *= clip.w;\nclip.xy += offset;\ngl_Position = clip;\n#ifndef PICKING\nvViewPosition = ( projectionMatrixInverse * clip ).xyz;\n#endif\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n#include nearclip_vertex\n}"),Wl.add("shader/WideLine.frag","uniform vec3 diffuse;\nuniform float opacity;\nuniform float clipNear;\nuniform float clipRadius;\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\n#ifdef PICKING\nuniform float objectId;\nvarying vec3 vPickingColor;\n#else\n#include common\n#include fog_pars_fragment\nvarying vec3 vViewPosition;\nvarying vec3 vColor;\nvarying vec3 vColor2;\nvarying float flag;\n#endif\nvoid main() {\n#include nearclip_fragment\n#include radiusclip_fragment\n#if defined( PICKING )\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\nvec3 outgoingLight = vec3( 0.0 );\nvec4 diffuseColor = vec4( diffuse, 1.0 );\nif ( flag < 0.0 ) {\ndiffuseColor.rgb *= vColor;\n} else {\ndiffuseColor.rgb *= vColor2;\n}\n#include alphatest_fragment\noutgoingLight = diffuseColor.rgb;\ngl_FragColor = vec4( outgoingLight, diffuseColor.a * opacity );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");const D_=Object.assign({linewidth:2},Of),R_=Object.assign({linewidth:{uniform:!0}},Nf);class L_ extends kp{constructor(e,t={}){super(e,t),this.parameterTypes=R_,this.vertexShader="WideLine.vert",this.fragmentShader="WideLine.frag",!e.color2&&e.color&&(e.color2=e.color),this.addUniforms({linewidth:{value:this.parameters.linewidth},resolution:{value:new Ge},projectionMatrixInverse:{value:new qt}}),this.addAttributes({position1:{type:"v3",value:null},position2:{type:"v3",value:null},color2:{type:"c",value:null}}),this.setAttributes(e),this.makeMapping()}get defaultParameters(){return D_}setParameters(e){super.setParameters(e)}}Yl.add("wideline",L_);class k_ extends v_{constructor(e,t,i){super(e,t,i),this.type="angle",this.parameters=Object.assign({atomTriple:{type:"hidden",rebuild:!0},vectorVisible:{type:"boolean",default:!0},arcVisible:{type:"boolean",default:!0},sectorVisible:{type:"boolean",default:!0}},this.parameters),this.init(i)}init(e){const t=e||{};t.side=uo(t.side,"double"),t.opacity=uo(t.opacity,.5),this.atomTriple=uo(t.atomTriple,[]),this.arcVisible=uo(t.arcVisible,!0),this.sectorVisible=uo(t.sectorVisible,!0),this.vectorVisible=uo(t.vectorVisible,!0),super.init(t)}createData(e){if(!e.atomCount||!this.atomTriple.length)return;const t=function(e,t){return function(e){const t=[],i=e.length/9;for(let n=0;n radius2) {\ndiscard;\n}\n#ifdef CAP\nsurface_point = front_point;\n_normal = axis;\n#else\nsurface_point = ray_target + ( (-a1 - sqrt(d)) / a2 ) * ray_direction;\ndNV = dot(-axis, ray_direction);\nnear = dot(axis, end) / dNV;\nnew_point2 = ray_direction * near + ray_origin;\nif (dot(new_point2 - end, new_point2-base) < radius2) {\ndiscard;\n}\ninterior = true;\n#endif\n}\nif( end_cap_test > 0.0 )\n{\nfloat dNV;\nfloat near;\nvec3 end_point;\nif ( ortho == 1.0 ) {\nend_point = ray_target;\n} else {\ndNV = dot(axis, ray_direction);\nif (dNV < 0.0) {\ndiscard;\n}\nnear = dot(axis, end) / dNV;\nend_point = ray_direction * near + ray_origin;\n}\nif( dot(end_point - end, end_point-base) > radius2 ) {\ndiscard;\n}\n#ifdef CAP\nsurface_point = end_point;\n_normal = axis;\n#else\nsurface_point = ray_target + ( (-a1 - sqrt(d)) / a2 ) * ray_direction;\ndNV = dot(-axis, ray_direction);\nnear = dot(-axis, (base)) / dNV;\nnew_point2 = ray_direction * near + ray_origin;\nif (dot(new_point2 - base, new_point2-base) < radius2) {\ndiscard;\n}\ninterior = true;\n#endif\n}\ngl_FragDepthEXT = calcDepth( surface_point );\n#ifdef NEAR_CLIP\nif( calcClip( surface_point ) > 0.0 ){\ndist = (-a1 - sqrt(d)) / a2;\nsurface_point = ray_target + dist * ray_direction;\nif( calcClip( surface_point ) > 0.0 ) {\ndiscard;\n}\ninterior = true;\ngl_FragDepthEXT = calcDepth( surface_point );\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = max( 0.0, calcDepth( vec3( - ( clipNear - 0.5 ) ) ) + ( 0.0000001 / vRadius ) );\n}\n}else if( gl_FragDepthEXT <= 0.0 ){\ndist = (-a1 - sqrt(d)) / a2;\nsurface_point = ray_target + dist * ray_direction;\ninterior = true;\ngl_FragDepthEXT = calcDepth( surface_point );\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );\n}\n}\n#else\nif( gl_FragDepthEXT <= 0.0 ){\ndist = (-a1 - sqrt(d)) / a2;\nsurface_point = ray_target + dist * ray_direction;\ninterior = true;\ngl_FragDepthEXT = calcDepth( surface_point );\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / vRadius );\n}\n}\n#endif\nif (gl_FragDepthEXT < 0.0) {\ndiscard;\n}\nif (gl_FragDepthEXT > 1.0) {\ndiscard;\n}\n#ifdef PICKING\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\nvec3 vViewPosition = -surface_point;\nvec3 vNormal = _normal;\nvec3 vColor;\nif( distSq3( surface_point, end ) < distSq3( surface_point, base ) ){\nif( b < 0.0 ){\nvColor = vColor1;\n}else{\nvColor = vColor2;\n}\n}else{\nif( b > 0.0 ){\nvColor = vColor1;\n}else{\nvColor = vColor2;\n}\n}\nvec4 diffuseColor = vec4( diffuse, opacity );\nReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\nvec3 totalEmissiveLight = emissive;\n#include color_fragment\n#include roughnessmap_fragment\n#include metalnessmap_fragment\nvec3 normal = normalize( vNormal );\nvec3 nonPerturbedNormal = normal;\n#include lights_physical_fragment\n#include lights_fragment_begin\n#include lights_fragment_end\nvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;\nif( interior ){\n#ifdef USE_INTERIOR_COLOR\noutgoingLight.xyz = interiorColor;\n#else\n#ifdef DIFFUSE_INTERIOR\noutgoingLight.xyz = vColor;\n#endif\n#endif\noutgoingLight.xyz *= 1.0 - interiorDarkening;\n}\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");const $_=new Float32Array([-1,1,-1,-1,-1,-1,1,1,-1,1,1,1,1,-1,-1,1,-1,1]),G_=new Uint16Array([0,1,2,1,4,2,2,4,3,4,5,3]);class H_ extends Dp{constructor(e,t={}){super("v3",e,t)}get mapping(){return $_}get mappingIndices(){return G_}get mappingIndicesSize(){return 12}get mappingSize(){return 6}get mappingItemSize(){return 3}}const j_=Object.assign({openEnded:!1},Of),W_=Object.assign({openEnded:{updateShader:!0}},Nf);class q_ extends H_{constructor(e,t={}){super(e,t),this.parameterTypes=W_,this.isImpostor=!0,this.vertexShader="CylinderImpostor.vert",this.fragmentShader="CylinderImpostor.frag",this.addUniforms({modelViewMatrixInverse:{value:new qt},ortho:{value:0}}),this.addAttributes({position1:{type:"v3",value:null},position2:{type:"v3",value:null},color2:{type:"c",value:null},radius:{type:"f",value:null}}),this.setAttributes(e),this.makeMapping()}get defaultParameters(){return j_}getDefines(e){const t=H_.prototype.getDefines.call(this,e);return this.parameters.openEnded||(t.CAP=1),t}}Object.assign({disableImpostor:!1},z_,j_);const X_=class{constructor(e,t={}){return!e.color2&&e.color&&(e.color2=e.color),!Ol||t&&t.disableImpostor?new V_(e,t):new q_(e,t)}};Yl.add("cylinder",X_);class Y_ extends y_{constructor(e,t,i){super(e,t,i),this.type="axes",this.parameters=Object.assign({radiusSize:{type:"number",precision:3,max:10,min:.001},sphereDetail:!0,radialSegments:!0,disableImpostor:!0,showAxes:{type:"boolean",rebuild:!0},showBox:{type:"boolean",rebuild:!0}},this.parameters,{assembly:null}),this.init(i)}init(e){const t=e||{};t.radiusSize=uo(t.radiusSize,.5),t.colorValue=uo(t.colorValue,"lightgreen"),t.useInteriorColor=uo(t.useInteriorColor,!0),this.showAxes=uo(t.showAxes,!0),this.showBox=uo(t.showBox,!1),super.init(t)}getPrincipalAxes(){let e;const t=this.getAssembly();return t&&(e=t.partList[0].getSelection()),this.structureView.getPrincipalAxes(e)}getAxesData(e){const t=this.getPrincipalAxes(),i=new Oi(this.colorValue);let n=0,r=0;this.showAxes&&(n+=6,r+=3),this.showBox&&(n+=8,r+=12);const s=new Float32Array(3*n),a=Mc(n,i.r,i.g,i.b),o=Sc(n,this.radiusSize),l=new Float32Array(3*r),c=new Float32Array(3*r),u=Mc(r,i.r,i.g,i.b),h=Sc(r,this.radiusSize);let d=0;if(this.showAxes){const e=function(e,t){e.toArray(s,2*d),t.toArray(s,2*d+3),e.toArray(l,d),t.toArray(c,d),d+=3};e(t.begA,t.endA),e(t.begB,t.endB),e(t.begC,t.endC)}if(this.showBox){const i=new _t,{d1a:n,d2a:r,d3a:a,d1b:o,d2b:u,d3b:h}=t.getProjectedScaleForAtoms(e);let f=2*d;const m=function(e,n,r){i.copy(t.center).addScaledVector(t.normVecA,e).addScaledVector(t.normVecB,n).addScaledVector(t.normVecC,r),i.toArray(s,f),f+=3};m(n,r,a),m(n,r,h),m(n,u,h),m(n,u,a),m(o,u,h),m(o,u,a),m(o,r,a),m(o,r,h);let p=d;const g=function(e,t){i.fromArray(s,2*d+3*e).toArray(l,p),i.fromArray(s,2*d+3*t).toArray(c,p),p+=3};g(0,1),g(0,3),g(0,6),g(1,2),g(1,7),g(2,3),g(2,4),g(3,5),g(4,5),g(4,7),g(5,6),g(6,7)}const f=new jd(t);return{vertex:{position:s,color:a,radius:o,picking:f},edge:{position1:l,position2:c,color:u,color2:u,radius:h,picking:f}}}create(){const e=this.getAxesData(this.structureView);this.sphereBuffer=new Np(e.vertex,this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0})),this.cylinderBuffer=new X_(e.edge,this.getBufferParams({openEnded:!0,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0})),this.dataList.push({sview:this.structureView,bufferList:[this.sphereBuffer,this.cylinderBuffer]})}createData(e){}updateData(e,t){const i=this.getAxesData(t.sview),n={},r={};e&&!e.position||(Object.assign(n,{position:i.vertex.position}),Object.assign(r,{position1:i.edge.position1,position2:i.edge.position2})),e&&!e.color||(Object.assign(n,{color:i.vertex.color}),Object.assign(r,{color:i.edge.color,color2:i.edge.color})),e&&!e.radius||(Object.assign(n,{radius:i.vertex.radius}),Object.assign(r,{radius:i.edge.radius})),this.sphereBuffer.setAttributes(n),this.cylinderBuffer.setAttributes(r)}}Hl.add("axes",Y_);class K_ extends y_{constructor(e,t,i){super(e,t,i),this.type="ball+stick",this.parameters=Object.assign({sphereDetail:!0,radialSegments:!0,openEnded:!0,disableImpostor:!0,aspectRatio:{type:"number",precision:1,max:10,min:1},lineOnly:{type:"boolean",rebuild:!0},cylinderOnly:{type:"boolean",rebuild:!0},multipleBond:{type:"select",rebuild:!0,options:{off:"off",symmetric:"symmetric",offset:"offset"}},bondScale:{type:"number",precision:2,max:1,min:.01},bondSpacing:{type:"number",precision:2,max:2,min:.5},linewidth:{type:"integer",max:50,min:1,buffer:!0}},this.parameters),this.init(i)}init(e){var t=e||{};t.radiusType=uo(t.radiusType,"size"),t.radiusSize=uo(t.radiusSize,.15),t.useInteriorColor=uo(t.useInteriorColor,!0),this.aspectRatio=uo(t.aspectRatio,2),this.lineOnly=uo(t.lineOnly,!1),this.cylinderOnly=uo(t.cylinderOnly,!1),this.multipleBond=uo(t.multipleBond,"off"),this.bondSpacing=uo(t.bondSpacing,1),this.bondScale=uo(t.bondScale,.4),this.linewidth=uo(t.linewidth,2),super.init(t)}getAtomRadius(e){return this.aspectRatio*super.getAtomRadius(e)}getAtomParams(e,t){var i=super.getAtomParams(e,t);return i.radiusParams.scale*=this.aspectRatio,i}getAtomData(e,t,i){return e.getAtomData(this.getAtomParams(t,i))}getBondParams(e,t){return t=Object.assign({multipleBond:this.multipleBond,bondSpacing:this.bondSpacing,bondScale:this.bondScale},t),super.getBondParams(e,t)}getBondData(e,t,i){return e.getBondData(this.getBondParams(t,i))}createData(e){const t=[];if(this.lineOnly)this.lineBuffer=new L_(this.getBondData(e,{position:!0,color:!0,picking:!0}),this.getBufferParams({linewidth:this.linewidth})),t.push(this.lineBuffer);else{const i=new X_(this.getBondData(e),this.getBufferParams({openEnded:this.openEnded,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0}));if(t.push(i),!this.cylinderOnly){const i=new Np(this.getAtomData(e),this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0}));t.push(i)}}return{bufferList:t}}updateData(e,t){"off"!==this.multipleBond&&e&&e.radius&&(e.position=!0);const i=this.getBondData(t.sview,e);if(this.lineOnly){const n={};e&&!e.position||Object.assign(n,{position1:i.position1,position2:i.position2}),e&&!e.color||Object.assign(n,{color:i.color,color2:i.color2}),t.bufferList[0].setAttributes(n)}else{var n={};if(e&&!e.position||Object.assign(n,{position1:i.position1,position2:i.position2}),e&&!e.color||Object.assign(n,{color:i.color,color2:i.color2}),e&&!e.radius||Object.assign(n,{radius:i.radius}),t.bufferList[0].setAttributes(n),!this.cylinderOnly){var r=this.getAtomData(t.sview,e),s={};e&&!e.position||Object.assign(s,{position:r.position}),e&&!e.color||Object.assign(s,{color:r.color}),e&&!e.radius||Object.assign(s,{radius:r.radius}),t.bufferList[1].setAttributes(s)}}}setParameters(e={}){let t=!1;const i={};return(e.aspectRatio||e.bondSpacing||e.bondScale)&&(Object.assign(i,{radius:!0}),Ol&&!this.disableImpostor||(t=!0)),super.setParameters(e,i,t),this}}Hl.add("ball+stick",K_);class Z_ extends K_{constructor(e,t,i){super(e,t,i),this.type="backbone",this.parameters=Object.assign({},this.parameters,{multipleBond:null,bondSpacing:null}),this.init(i)}init(e){var t=e||{};t.aspectRatio=uo(t.aspectRatio,1),t.radiusSize=uo(t.radiusSize,.25),super.init(t)}getAtomRadius(e){return e.isTrace()?super.getAtomRadius(e):0}getAtomData(e,t,i){return e.getBackboneAtomData(this.getAtomParams(t,i))}getBondData(e,t,i){return e.getBackboneBondData(this.getBondParams(t,i))}}Hl.add("backbone",Z_);class Q_ extends K_{constructor(e,t,i){super(e,t,i),this.type="base",this.parameters=Object.assign({},this.parameters,{multipleBond:null,bondSpacing:null})}init(e){let t=e||{};t.aspectRatio=uo(t.aspectRatio,1),t.radiusSize=uo(t.radiusSize,.3),super.init(t)}getAtomData(e,t,i){return e.getRungAtomData(this.getAtomParams(t,i))}getBondData(e,t,i){let n=this.getBondParams(t,i);return Object.assign(n.colorParams,{rung:!0}),e.getRungBondData(n)}}Hl.add("base",Q_);class J_{constructor(e,t){this.m=e,this.tension=t,this.dt=1/this.m,this.delta=1e-4,this.vec1=new _t,this.vec2=new _t,this.vDir=new _t,this.vTan=new _t,this.vNorm=new _t,this.vBin=new _t,this.m2=Math.ceil(this.m/2)}interpolateToArr(e,t,i,n,r,s,a){s[a+0]=Bo(e.x,t.x,i.x,n.x,r,this.tension),s[a+1]=Bo(e.y,t.y,i.y,n.y,r,this.tension),s[a+2]=Bo(e.z,t.z,i.z,n.z,r,this.tension)}interpolateToVec(e,t,i,n,r,s){s.x=Bo(e.x,t.x,i.x,n.x,r,this.tension),s.y=Bo(e.y,t.y,i.y,n.y,r,this.tension),s.z=Bo(e.z,t.z,i.z,n.z,r,this.tension)}interpolatePosition(e,t,i,n,r,s){for(var a=0;a1&&(c=1),this.interpolateToVec(e,t,i,n,l,this.vec1),this.interpolateToVec(e,t,i,n,c,this.vec2),this.vec2.sub(this.vec1).normalize(),this.vec2.toArray(r,u)}}vectorSubdivide(e,t,i,n,r){let s,a=t.next(),o=t.next(),l=t.next();const c=t.size,u=c-1;let h=n||0;for(let n=0;n0&&n{if(e.residueCount<4)return;i.push(e);const n=this.getSpline(e),r=this.getAspectRatio(e),s=n.getSubdividedPosition(),a=n.getSubdividedOrientation(),o=n.getSubdividedColor(this.getColorParams()),l=n.getSubdividedPicking(),c=n.getSubdividedSize(this.getRadiusParams());t.push(new ry(Object.assign({},s,a,o,l,c),this.getBufferParams({radialSegments:this.radialSegments,aspectRatio:r,capped:this.capped})))}),e.getSelection()),{bufferList:t,polymerList:i}}updateData(t,i){e.Debug&&Fl.time(this.type+" repr update"),t=t||{};for(var n=0,r=i.polymerList.length;n0;Xu(w,y,S);const r=qu(w,b)<0;if(th(w,b,qu(b,v)),Xu(M,v,w),th(w,b,qu(b,x)),Xu(A,x,w),0===Ju(M)||0===Ju(A))continue;ih(M,M),ih(A,A);const R=s[I]=lh(M,A);o[I]=(vc*R).toFixed(1)+String.fromCharCode(176),Wu(P,M,b),ih(P,P),qu(P,A)<0&&oh(P,P),x_(w,S,M,P,R/2),Zu(w,a,3*I);const L=Math.ceil(R/i),k=L+(t.extendLine?4:2),O=t.extendLine?36:0,N=new Float32Array(3*k),F=new Float32Array(3*k),B=new Float32Array(9*L),z=new Float32Array(O);l[I]=N,c[I]=F,u[I]=B,h[I]=z,t.extendLine&&(n?(Xu(w,p,_),ih(w,w),th(C,w,1/qu(M,w)),Yu(C,C,_)):(th(C,v,1/qu(M,v)),Yu(C,C,g)),r?(Xu(w,y,g),ih(w,w),th(T,w,1/qu(A,w)),Yu(T,T,g)):(th(T,x,1/qu(A,x)),Yu(T,T,_))),Yu(E,S,M);let U=0;t.extendLine?(Zu(p,N,U),Zu(C,F,U),U+=3,Zu(C,N,U),Zu(E,F,U),U+=3,Zu(C,z,0),Zu(E,z,3),Zu(n?_:g,z,6),Zu(n?_:g,z,9),Zu(E,z,12),Zu(S,z,15)):(Zu(S,N,U),Zu(E,F,U),U+=3);const V=function(e,t){const i=9*t;Zu(S,B,i),Zu(E,B,i+3),Zu(E,N,U),x_(E,S,M,P,e),Zu(E,B,i+6),Zu(E,F,U),U+=3};let $=0;for(let e=i;e{const t=ly(i,e);Object.assign(e,t)})),t.side=uo(t.side,"double"),t.opacity=uo(t.opacity,.5),t.radiusType=uo(t.radiusType,"size"),t.radiusSize=uo(t.radiusSize,.15),super.init(t)}getHistogramBinBorderBufferParameters(){return this.getBufferParams({linewidth:this.histogramBinBorderWidth,visible:this.histogramBinBorderVisible,opacity:this.histogramBinBorderOpacity})}getBondArrowsBufferParameters(){return this.getBufferParams({linewidth:this.bondArrowWidth,visible:this.bondArrowVisible,opacity:this.bondArrowOpacity})}getOpaqueMiddleDiscBufferParameters(){return this.getBufferParams({visible:this.opaqueMiddleDiscVisible,opacity:this.opaqueMiddleDiscOpacity})}getHistogramBufferParameters(){return this.getBufferParams({visible:!0,opacity:this.histogramOpacity,side:"double"})}createData(e){if(!e.atomCount||!this.histogramsData.length)return;this.histogramsData.forEach((t=>t.atomPositions=b_(e,[t.atomQuad])));const t=this.scaleBinToSectorArea?function(e){return Math.sqrt(e)}:function(e){return e};function i(e){const t=e.map((e=>e.length)),i=new Float32Array(Rc(t));let n=0;for(let t=0;te.startPoints))),position2:i(e.map((e=>e.endPoints))),color:i(e.map((e=>e.startColors))),color2:i(e.map((e=>e.endColors)))},t)}function r(e,t){return new Bf({position:i(e.map((e=>e.triangles))),color:i(e.map((e=>e.triangleColors)))},t)}this.histogramsData.forEach((e=>e.histogram360Scaled=e.histogram360.map(t)));const s=[];for(let e=0;e=3&&(t=hy(i)),void 0!==t&&s.push(t)}return this.frontHistogramBinBordersBuffer=n(s.map((e=>e.frontHistogramBinBorders)),this.getHistogramBinBorderBufferParameters()),this.backHistogramBinBordersBuffer=n(s.map((e=>e.backHistogramBinBorders)),this.getHistogramBinBorderBufferParameters()),this.adjacentBondArrowsBuffer=n(s.map((e=>e.adjacentBondArrows)),this.getBondArrowsBufferParameters()),this.distantBondArrowsBuffer=n(s.map((e=>e.distantBondArrows)),this.getBondArrowsBufferParameters()),this.opaqueMiddleDiscBuffer=r(s.map((e=>e.opaqueMiddleDisc)),this.getOpaqueMiddleDiscBufferParameters()),this.frontHistogramBuffer=r(s.map((e=>e.frontHistogram)),this.getHistogramBufferParameters()),this.backHistogramBuffer=r(s.map((e=>e.backHistogram)),this.getHistogramBufferParameters()),{bufferList:[].concat(this.frontHistogramBinBordersBuffer,this.backHistogramBinBordersBuffer,this.adjacentBondArrowsBuffer,this.distantBondArrowsBuffer,this.opaqueMiddleDiscBuffer,this.frontHistogramBuffer,this.backHistogramBuffer)}}setParameters(e){return super.setParameters(e,{},!1),e&&void 0!==e.histogramBinBorderVisible&&this.setVisibility(this.visible),this}setVisibility(e,t){return super.setVisibility(e,!0),this.frontHistogramBinBordersBuffer&&this.frontHistogramBinBordersBuffer.setVisibility(this.histogramBinBorderVisible),this.backHistogramBinBordersBuffer&&this.backHistogramBinBordersBuffer.setVisibility(this.histogramBinBorderVisible),t||this.viewer.requestRender(),this}}function hy(e){const t=e.atomPositions,i=e.histogram360Scaled,n=i.length<=180?360:2*i.length,r={triangles:new Float32Array(3*n*3),triangleColors:cy(e.opaqueMiddleDiscColor,3*n)},s={triangles:new Float32Array(3*i.length*3),triangleColors:cy(e.frontHistogramColor,3*i.length)},a={triangles:new Float32Array(3*i.length*3),triangleColors:cy(e.backHistogramColor,3*i.length)},o={startPoints:new Float32Array(3*i.length),endPoints:new Float32Array(3*i.length),startColors:cy(e.histogramBinBorderColor,i.length),endColors:cy(e.histogramBinBorderColor,i.length)},l={startPoints:new Float32Array(3*i.length),endPoints:new Float32Array(3*i.length),startColors:cy(e.histogramBinBorderColor,i.length),endColors:cy(e.histogramBinBorderColor,i.length)},c={startPoints:new Float32Array(6),endPoints:new Float32Array(6),startColors:cy(e.adjacentBondArrowColor,i.length),endColors:cy(e.adjacentBondArrowColor,i.length)},u={startPoints:new Float32Array(6),endPoints:new Float32Array(6),startColors:cy(e.distantBondArrowColor,i.length),endColors:cy(e.distantBondArrowColor,i.length)},h=ju(),d=ju(),f=ju(),m=ju(),p=ju(),g=ju(),_=ju(),y=ju(),v=ju(),b=ju(),x=ju(),w=ju(),S=ju(),M=ju(),A=ju(),C=ju(),T=[h,d,f,m];for(let e=0;e{let d=t[0],f=t[1];if("number"==typeof d&&Number.isInteger(d)&&"number"==typeof f&&Number.isInteger(f)){if(!h.get(d)||!h.get(f))return void(u+=1);l.index=d,c.index=f}else{s.setString(d),a.setString(f);var m=e.getAtomIndices(s),p=e.getAtomIndices(a);if(!m.length||!p.length)return void(u+=1);l.index=m[0],c.index=p[0]}o.addBond(l,c,1),i-=u;var g=l.distanceTo(c);switch(this.labelUnit){case"angstrom":n[i]=g.toFixed(2)+" "+String.fromCharCode(8491);break;case"nm":n[i]=(g/10).toFixed(2)+" nm";break;default:n[i]=g.toFixed(2)}var _=3*i;r[_+0]=(l.x+c.x)/2,r[_+1]=(l.y+c.y)/2,r[_+2]=(l.z+c.z)/2})),u>0&&(i-=u,r=r.subarray(0,3*i));var d=new Ih(o.count,!0);return{text:n,position:r,bondSet:d,bondStore:o}}getBondData(e,t,i){const n=e.getBondData(this.getBondParams(t,i));return n.picking&&(n.picking=new Yd(n.picking.array,n.picking.structure,i.bondStore)),n}createData(e){if(!e.atomCount||!this.atomPair.length)return;const t=this.atomPair.length,i=new Oi(this.labelColor),n=this.getDistanceData(e,this.atomPair);this.textBuffer=new I_({position:n.position,size:Sc(t,this.labelSize),color:Mc(t,i.r,i.g,i.b),text:n.text},this.getLabelBufferParams());const r={bondSet:n.bondSet,bondStore:n.bondStore},s=this.getBondData(e,{position:!0,color:!0,picking:!0,radius:this.useCylinder},r);return this.useCylinder?this.distanceBuffer=new X_(s,this.getBufferParams({openEnded:this.openEnded,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0})):this.distanceBuffer=new L_(uh(s),this.getBufferParams({linewidth:this.linewidth,visible:this.lineVisible,opacity:this.lineOpacity})),{bondSet:n.bondSet,bondStore:n.bondStore,position:n.position,bufferList:[this.textBuffer,this.distanceBuffer]}}updateData(e,t){super.updateData(e,t);const i={bondSet:t.bondSet,bondStore:t.bondStore},n=this.getBondData(t.sview,e,i),r={};e&&!e.color||Object.assign(r,{color:n.color,color2:n.color2}),e&&!e.radius||Object.assign(r,{radius:n.radius}),this.distanceBuffer.setAttributes(r)}setParameters(e){return super.setParameters(e,{},!1),this.useCylinder||(e&&e.lineOpacity&&this.distanceBuffer.setParameters({opacity:e.lineOpacity}),e&&void 0!==e.opacity&&this.distanceBuffer.setParameters({opacity:this.lineOpacity}),e&&e.linewidth&&this.distanceBuffer.setParameters({linewidth:e.linewidth})),this}}function fy(e){return 2*(e.position.length/3)*3}Hl.add("distance",dy);const my=Object.assign({scale:1,color:"grey"},Of);class py extends Ff{constructor(e,t={}){super({position:new Float32Array(fy(e)),color:new Float32Array(fy(e))},t),this.isLine=!0,this.vertexShader="Line.vert",this.fragmentShader="Line.frag";const i=new Oi(this.parameters.color),n=this.geometry.attributes;Mc(fy(e)/3,i.r,i.g,i.b,n.color.array),this.setAttributes(e)}get defaultParameters(){return my}setAttributes(e={}){const t=this.geometry.attributes;let i,n,r;e.position&&e.vector&&(i=e.position,n=e.vector,r=t.position.array,t.position.needsUpdate=!0);const s=this.size/2,a=this.parameters.scale;if(i&&n)for(let e=0;e{if(e.residueCount<4)return;i.push(e);const n=new bm(e),r=n.getPosition(),s=n.getColor(this.getColorParams()),a=n.getSize(this.getRadiusParams()),o=n.getPicking();t.push(new Np({position:r.center,color:s.color,radius:a.size,picking:o.picking},this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0})),new py({position:r.center,vector:r.axis},this.getBufferParams({color:"skyblue",scale:1})),new py({position:r.center,vector:r.resdir},this.getBufferParams({color:"lightgreen",scale:1})))}),e.getSelection()),{bufferList:t,polymerList:i}}updateData(t,i){e.Debug&&Fl.time(this.type+" repr update"),t=t||{};for(let e=0,n=i.polymerList.length;e radius2) {\nspaceposition.y = mapping.y * 1.5 * radius1;\nspaceposition.x = mapping.x * 1.5 * radius1;\n} else {\nspaceposition.y = mapping.y * 1.5 * radius2;\nspaceposition.x = mapping.x * 1.5 * radius2;\n}\nspaceposition.w = 1.0;\nvec4 e3 = vec4( 1.0 );\nvec3 e1, e1_temp, e2, e2_temp;\ne3.xyz = normalize(position_atom1-position_atom2);\nif (e3.z == 0.0) { e3.z = 0.0000000000001;}\nif ( (position_atom1.x - position_atom2.x) == 0.0) { position_atom1.x += 0.001;}\nif ( (position_atom1.y - position_atom2.y) == 0.0) { position_atom1.y += 0.001;}\nif ( (position_atom1.z - position_atom2.z) == 0.0) { position_atom1.z += 0.001;}\nvec4 focus = vec4( 1.0 );\nfocus.x = ( position_atom1.x*position_atom1.x - position_atom2.x*position_atom2.x +\n( radius2*radius2 - radius1*radius1 )*e3.x*e3.x/shrink )/(2.0*(position_atom1.x - position_atom2.x));\nfocus.y = ( position_atom1.y*position_atom1.y - position_atom2.y*position_atom2.y +\n( radius2*radius2 - radius1*radius1 )*e3.y*e3.y/shrink )/(2.0*(position_atom1.y - position_atom2.y));\nfocus.z = ( position_atom1.z*position_atom1.z - position_atom2.z*position_atom2.z +\n( radius2*radius2 - radius1*radius1 )*e3.z*e3.z/shrink )/(2.0*(position_atom1.z - position_atom2.z));\ne1.x = 1.0;\ne1.y = 1.0;\ne1.z = ( (e3.x*focus.x + e3.y*focus.y + e3.z*focus.z) - e1.x*e3.x - e1.y*e3.y)/e3.z;\ne1_temp = e1 - focus.xyz;\ne1 = normalize(e1_temp);\ne2_temp = e1.yzx * e3.zxy - e1.zxy * e3.yzx;\ne2 = normalize(e2_temp);\nmat3 R= mat3( e1.xyz, e2.xyz, e3.xyz );\nvertex_position.xyz = R * spaceposition.xyz;\nvertex_position.w = 1.0;\nvertex_position.x += (position_atom1.x+position_atom2.x) / 2.0;\nvertex_position.y += (position_atom1.y+position_atom2.y) / 2.0;\nvertex_position.z += (position_atom1.z+position_atom2.z) / 2.0;\ngl_Position = modelViewProjectionMatrix * vertex_position;\nvec4 i_near, i_far;\nvec4 near = gl_Position;\nnear.z = 0.0 ;\nnear = modelViewProjectionMatrixInverse * near;\ni_near = near;\nvec4 far = gl_Position;\nfar.z = far.w ;\ni_far = modelViewProjectionMatrixInverse * far;\nprime1 = vec4( position_atom1 - (position_atom1 - focus.xyz)*shrink, 1.0 );\nprime2 = vec4( position_atom2 - (position_atom2 - focus.xyz)*shrink, 1.0 );\nfloat Rsquare = (radius1*radius1/shrink) - (\n(position_atom1.x - focus.x)*(position_atom1.x - focus.x) +\n(position_atom1.y - focus.y)*(position_atom1.y - focus.y) +\n(position_atom1.z - focus.z)*(position_atom1.z - focus.z)\n);\nfocus.w = Rsquare;\nmatrix_near = mat4( i_near, i_far, focus, e3 );\ngl_Position.z = 1.0;\n}"),Wl.add("shader/HyperballStickImpostor.frag","#define STANDARD\n#define IMPOSTOR\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 interiorColor;\nuniform float interiorDarkening;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\nuniform float clipNear;\nuniform float shrink;\nuniform mat4 modelViewMatrix;\nuniform mat4 modelViewProjectionMatrix;\nuniform mat4 modelViewMatrixInverseTranspose;\nuniform mat4 projectionMatrix;\nvarying mat4 matrix_near;\nvarying vec4 prime1;\nvarying vec4 prime2;\nvarying float vRadius;\nvarying float vRadius2;\n#ifdef PICKING\nuniform float objectId;\nvarying vec3 vPickingColor;\n#else\nvarying vec3 vColor1;\nvarying vec3 vColor2;\n#include common\n#include fog_pars_fragment\n#include bsdfs\n#include lights_pars_begin\n#include lights_physical_pars_fragment\n#endif\nbool interior = false;\nfloat calcClip( vec4 cameraPos ){\nreturn dot( cameraPos, vec4( 0.0, 0.0, 1.0, clipNear - 0.5 ) );\n}\nfloat calcClip( vec3 cameraPos ){\nreturn calcClip( vec4( cameraPos, 1.0 ) );\n}\nfloat calcDepth( in vec3 cameraPos ){\nvec2 clipZW = cameraPos.z * projectionMatrix[2].zw + projectionMatrix[3].zw;\nreturn 0.5 + 0.5 * clipZW.x / clipZW.y;\n}\nstruct Ray {\nvec3 origin ;\nvec3 direction ;\n};\nbool cutoff_plane (vec3 M, vec3 cutoff, vec3 x3){\nfloat a = x3.x;\nfloat b = x3.y;\nfloat c = x3.z;\nfloat d = -x3.x*cutoff.x-x3.y*cutoff.y-x3.z*cutoff.z;\nfloat l = a*M.x+b*M.y+c*M.z+d;\nif (l<0.0) {return true;}\nelse{return false;}\n}\nvec3 isect_surf(Ray r, mat4 matrix_coef){\nvec4 direction = vec4(r.direction, 0.0);\nvec4 origin = vec4(r.origin, 1.0);\nfloat a = dot(direction,(matrix_coef*direction));\nfloat b = dot(origin,(matrix_coef*direction));\nfloat c = dot(origin,(matrix_coef*origin));\nfloat delta =b*b-a*c;\ngl_FragColor.a = 1.0;\nif (delta<0.0){\ndiscard;\n}\nfloat t1 =(-b-sqrt(delta))/a;\nreturn r.origin+t1*r.direction;\n}\nvec3 isect_surf2(Ray r, mat4 matrix_coef){\nvec4 direction = vec4(r.direction, 0.0);\nvec4 origin = vec4(r.origin, 1.0);\nfloat a = dot(direction,(matrix_coef*direction));\nfloat b = dot(origin,(matrix_coef*direction));\nfloat c = dot(origin,(matrix_coef*origin));\nfloat delta =b*b-a*c;\ngl_FragColor.a = 1.0;\nif (delta<0.0){\ndiscard;\n}\nfloat t2 =(-b+sqrt(delta))/a;\nreturn r.origin+t2*r.direction;\n}\nRay primary_ray(vec4 near1, vec4 far1){\nvec3 near=near1.xyz/near1.w;\nvec3 far=far1.xyz/far1.w;\nreturn Ray(near,far-near);\n}\nfloat update_z_buffer(vec3 M, mat4 ModelViewP){\nfloat depth1;\nvec4 Ms=(ModelViewP*vec4(M,1.0));\nreturn depth1=(1.0+Ms.z/Ms.w)/2.0;\n}\nvoid main(){\nfloat radius = max( vRadius, vRadius2 );\nvec4 i_near, i_far, focus;\nvec3 e3, e1, e1_temp, e2;\ni_near = vec4(matrix_near[0][0],matrix_near[0][1],matrix_near[0][2],matrix_near[0][3]);\ni_far = vec4(matrix_near[1][0],matrix_near[1][1],matrix_near[1][2],matrix_near[1][3]);\nfocus = vec4(matrix_near[2][0],matrix_near[2][1],matrix_near[2][2],matrix_near[2][3]);\ne3 = vec3(matrix_near[3][0],matrix_near[3][1],matrix_near[3][2]);\ne1.x = 1.0;\ne1.y = 1.0;\ne1.z = ( (e3.x*focus.x + e3.y*focus.y + e3.z*focus.z) - e1.x*e3.x - e1.y*e3.y)/e3.z;\ne1_temp = e1 - focus.xyz;\ne1 = normalize(e1_temp);\ne2 = normalize(cross(e1,e3));\nvec4 equation = focus;\nfloat shrinkfactor = shrink;\nfloat t1 = -1.0/(1.0-shrinkfactor);\nfloat t2 = 1.0/(shrinkfactor);\nvec4 colonne1, colonne2, colonne3, colonne4;\nmat4 mat;\nvec3 equation1 = vec3(t2,t2,t1);\nfloat A1 = - e1.x*equation.x - e1.y*equation.y - e1.z*equation.z;\nfloat A2 = - e2.x*equation.x - e2.y*equation.y - e2.z*equation.z;\nfloat A3 = - e3.x*equation.x - e3.y*equation.y - e3.z*equation.z;\nfloat A11 = equation1.x*e1.x*e1.x + equation1.y*e2.x*e2.x + equation1.z*e3.x*e3.x;\nfloat A21 = equation1.x*e1.x*e1.y + equation1.y*e2.x*e2.y + equation1.z*e3.x*e3.y;\nfloat A31 = equation1.x*e1.x*e1.z + equation1.y*e2.x*e2.z + equation1.z*e3.x*e3.z;\nfloat A41 = equation1.x*e1.x*A1 + equation1.y*e2.x*A2 + equation1.z*e3.x*A3;\nfloat A22 = equation1.x*e1.y*e1.y + equation1.y*e2.y*e2.y + equation1.z*e3.y*e3.y;\nfloat A32 = equation1.x*e1.y*e1.z + equation1.y*e2.y*e2.z + equation1.z*e3.y*e3.z;\nfloat A42 = equation1.x*e1.y*A1 + equation1.y*e2.y*A2 + equation1.z*e3.y*A3;\nfloat A33 = equation1.x*e1.z*e1.z + equation1.y*e2.z*e2.z + equation1.z*e3.z*e3.z;\nfloat A43 = equation1.x*e1.z*A1 + equation1.y*e2.z*A2 + equation1.z*e3.z*A3;\nfloat A44 = equation1.x*A1*A1 + equation1.y*A2*A2 + equation1.z*A3*A3 - equation.w;\ncolonne1 = vec4(A11,A21,A31,A41);\ncolonne2 = vec4(A21,A22,A32,A42);\ncolonne3 = vec4(A31,A32,A33,A43);\ncolonne4 = vec4(A41,A42,A43,A44);\nmat = mat4(colonne1,colonne2,colonne3,colonne4);\nRay ray = primary_ray(i_near,i_far) ;\nvec3 M;\nM = isect_surf(ray, mat);\nif (cutoff_plane(M, prime1.xyz, -e3) || cutoff_plane(M, prime2.xyz, e3)){ discard; }\nvec4 M1 = vec4(M,1.0);\nvec4 M2 = mat*M1;\nvec3 _normal = ( modelViewMatrixInverseTranspose * M2 ).xyz;\ngl_FragDepthEXT = update_z_buffer(M, modelViewProjectionMatrix) ;\n#ifdef NEAR_CLIP\nif( calcClip( modelViewMatrix * vec4( M, 1.0 ) ) > 0.0 ){\nM = isect_surf2(ray, mat);\nif( calcClip( modelViewMatrix * vec4( M, 1.0 ) ) > 0.0 )\ndiscard;\ninterior = true;\ngl_FragDepthEXT = update_z_buffer(M, modelViewProjectionMatrix) ;\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = max( 0.0, calcDepth( vec3( - ( clipNear - 0.5 ) ) ) + ( 0.0000001 / radius ) );\n}\n}else if( gl_FragDepthEXT <= 0.0 ){\nM = isect_surf2(ray, mat);\ninterior = true;\ngl_FragDepthEXT = update_z_buffer(M, modelViewProjectionMatrix);\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / radius );\n}\n}\n#else\nif( gl_FragDepthEXT <= 0.0 ){\nM = isect_surf2(ray, mat);\ninterior = true;\ngl_FragDepthEXT = update_z_buffer(M, modelViewProjectionMatrix) ;\nif( gl_FragDepthEXT >= 0.0 ){\ngl_FragDepthEXT = 0.0 + ( 0.0000001 / radius );\n}\n}\n#endif\nif (cutoff_plane(M, prime1.xyz, -e3) || cutoff_plane(M, prime2.xyz, e3)){ discard; }\nif (gl_FragDepthEXT < 0.0)\ndiscard;\nif (gl_FragDepthEXT > 1.0)\ndiscard;\nfloat distance_ratio = ((M.x-prime2.x)*e3.x + (M.y-prime2.y)*e3.y +(M.z-prime2.z)*e3.z) /\ndistance(prime2.xyz,prime1.xyz);\n#ifdef PICKING\nif( opacity < 0.3 )\ndiscard;\ngl_FragColor = vec4( vPickingColor, objectId );\n#else\nvec3 vViewPosition = -( modelViewMatrix * vec4( M, 1.0 ) ).xyz;\nvec3 vNormal = _normal;\nvec3 vColor;\nif( distance_ratio>0.5 ){\nvColor = vColor1;\n}else{\nvColor = vColor2;\n}\nvec4 diffuseColor = vec4( diffuse, opacity );\nReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\nvec3 totalEmissiveLight = emissive;\n#include color_fragment\n#include roughnessmap_fragment\n#include metalnessmap_fragment\nvec3 normal = normalize( vNormal );\nvec3 nonPerturbedNormal = normal;\n#include lights_physical_fragment\n#include lights_fragment_begin\n#include lights_fragment_end\nvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;\nif( interior ){\n#ifdef USE_INTERIOR_COLOR\noutgoingLight.xyz = interiorColor;\n#else\n#ifdef DIFFUSE_INTERIOR\noutgoingLight.xyz = vColor;\n#endif\n#endif\noutgoingLight.xyz *= 1.0 - interiorDarkening;\n}\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );\n#include premultiplied_alpha_fragment\n#include tonemapping_fragment\n#include colorspace_fragment\n#include fog_fragment\n#endif\n}");const yy=new Float32Array([-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,-1,1,-1,1,1,-1,1,1,1,-1,1,1]),vy=new Uint16Array([0,1,2,0,2,3,1,5,6,1,6,2,4,6,5,4,7,6,0,7,4,0,3,7,0,5,1,0,4,5,3,2,6,3,6,7]);class by extends Dp{constructor(e,t={}){super("v3",e,t)}get mapping(){return yy}get mappingIndices(){return vy}get mappingIndicesSize(){return 36}get mappingSize(){return 8}get mappingItemSize(){return 3}}const xy=Object.assign({shrink:.14},Of),wy=Object.assign({shrink:{uniform:!0}},Nf);class Sy extends by{constructor(e,t={}){super(e,t),this.parameterTypes=wy,this.isImpostor=!0,this.vertexShader="HyperballStickImpostor.vert",this.fragmentShader="HyperballStickImpostor.frag",this.addUniforms({modelViewProjectionMatrix:{value:new qt},modelViewProjectionMatrixInverse:{value:new qt},modelViewMatrixInverseTranspose:{value:new qt},shrink:{value:this.parameters.shrink}}),this.addAttributes({position1:{type:"v3",value:null},position2:{type:"v3",value:null},color2:{type:"c",value:null},radius:{type:"f",value:null},radius2:{type:"f",value:null}}),this.setAttributes(e),this.makeMapping()}get defaultParameters(){return xy}}Object.assign({disableImpostor:!1},z_,xy);const My=class{constructor(e,t={}){return!Ol||t&&t.disableImpostor?(e.radius=function(e,t){const i=e.length,n=new Float32Array(i);for(let r=0;ro.push(n.atomLabel(e)))))}else if("residue"===this.labelGrouping){t&&!t.position||(l=[]),t&&!t.color||(u=[]),t&&!t.radius||(c=[]),t&&!t.text||(o=[]),i.colorParams&&(i.colorParams.structure=e.getStructure());const h=$l.getScheme(i.colorParams),d=new cm(i.radiusParams),f=e.getAtomProxy();let m=0;e.eachResidue((e=>{const i=3*m;e.isProtein()||e.isNucleic()?(f.index=e.traceAtomIndex,t&&!t.position||f.positionToArray(l,i)):(f.index=e.atomOffset,t&&!t.position||e.positionToArray(l,i)),t&&!t.color||h.atomColorToArray(f,u,i),t&&!t.radius||(c[m]=d.atomRadius(f)),t&&!t.text||o.push(n.atomLabel(f)),++m})),t&&!t.position||(r=new Float32Array(l)),t&&!t.color||(a=new Float32Array(u)),t&&!t.radius||(s=new Float32Array(c))}return{position:r,size:s,color:a,text:o}}createData(e){return{bufferList:[new I_(this.getTextData(e,{position:!0,color:!0,radius:!0,text:!0}),this.getBufferParams({fontFamily:this.fontFamily,fontStyle:this.fontStyle,fontWeight:this.fontWeight,xOffset:this.xOffset,yOffset:this.yOffset,zOffset:this.zOffset,attachment:this.attachment,showBorder:this.showBorder,borderColor:this.borderColor,borderWidth:this.borderWidth,showBackground:this.showBackground,backgroundColor:this.backgroundColor,backgroundMargin:this.backgroundMargin,backgroundOpacity:this.backgroundOpacity,fixedSize:this.fixedSize}))]}}updateData(e,t){t.bufferList[0].setAttributes(this.getTextData(t.sview,e))}getAtomRadius(){return 0}}function Py(e){const t=e.getAtomSet(),i=e.getBondSet(),n=e.getBondProxy();return i.forEach((function(e){n.index=e,t.clear(n.atomIndex1),t.clear(n.atomIndex2)})),t}Hl.add("label",Ty);class Ey extends y_{constructor(e,t,i){super(e,t,i),this.type="line",this.parameters=Object.assign({multipleBond:{type:"select",rebuild:!0,options:{off:"off",symmetric:"symmetric",offset:"offset"}},bondSpacing:{type:"number",precision:2,max:2,min:.5},linewidth:{type:"integer",max:50,min:1,buffer:!0},lines:{type:"boolean",rebuild:!0},crosses:{type:"select",rebuild:!0,options:{off:"off",lone:"lone",all:"all"}},crossSize:{type:"number",precision:2,max:2,min:.1}},this.parameters,{flatShaded:null,side:null,wireframe:null,roughness:null,metalness:null}),this.init(i)}init(e){var t=e||{};this.multipleBond=uo(t.multipleBond,"off"),this.bondSpacing=uo(t.bondSpacing,1),this.linewidth=uo(t.linewidth,2),this.lines=uo(t.lines,!0),this.crosses=uo(t.crosses,"lone"),this.crossSize=uo(t.crossSize,.4),super.init(t)}getAtomRadius(e){return.1}getBondParams(e,t){return t=Object.assign({multipleBond:this.multipleBond,bondSpacing:this.bondSpacing,radiusParams:{type:"size",size:.1,scale:1}},t),super.getBondParams(e,t)}_crossData(e,t){if(e&&!e.position&&!e.color)return;const i={};"lone"===this.crosses&&Object.assign(i,{atomSet:Py(t)});const n=t.getAtomData(this.getAtomParams(e,i)),r={},s=n.position,a=n.color,o=n.picking,l=(s||a).length,c=3*l;let u=new Float32Array(0),h=new Float32Array(0),d=new Float32Array(0),f=new Float32Array(0),m=0,p=new Float32Array(0);e&&!e.position||(u=r.position1=new Float32Array(c),h=r.position2=new Float32Array(c),m=this.crossSize/2),e&&!e.color||(d=r.color=new Float32Array(c),f=r.color2=new Float32Array(c)),e&&!e.picking||(p=new Float32Array(3*n.picking.array.length));for(let t=0;tc?d[p]=-1:(l=Math.sqrt(c-o),d[p]=Math.floor(l)),++p;m[g]=h,f[g]=d}}function P(i){var n,r,s,o,h,p,y,b,x,w,M,A,C,T,P,E,I,D,R=3*i,L=i;n=Math.floor(.5+a*(e[R]+d[0])),r=Math.floor(.5+a*(e[R+1]+d[1])),s=Math.floor(.5+a*(e[R+2]+d[2]));var k,O=t[L],N=f[O],F=0,B=c*u,z=m[O];for(w=0;w=l||T>=c||P>=u)){var U=C*B+T*u+P;if(g)if(_[U]&S){if(_[U]&S){var V=v[U];V!==R&&y*y+b*b+x*x<(o=n+y-Math.floor(.5+a*(e[V]+d[0])))*o+(h=r+b-Math.floor(.5+a*(e[V+1]+d[1])))*h+(p=s+x-Math.floor(.5+a*(e[V+2]+d[2])))*p&&(v[U]=i)}}else _[U]|=S,v[U]=i;else _[U]|=S}F++}}function E(t){var i,n;for(console.time("EDTSurface fillvoxels"),i=0,n=_.length;i=l||S>=c||A>=u)){var B=w*F+S*u+A;if(_[B]&M){if(g){var z=v[B];y*y+b*b+x*x<(o=Math.floor(.5+a*(e[z]+d[0])))*o+(h=Math.floor(.5+a*(e[z+1]+d[1])))*h+(p=Math.floor(.5+a*(e[z+2]+d[2])))*p&&(v[B]=i)}}else _[B]|=M,g&&(v[B]=i)}O++}}function D(){var e,t,i,n;console.time("EDTSurface fastdistancemap");var r,s=Iy(l,c,u,Uint16Array,3),a=c*u,h=p*p,d=0;for(e=0;e0);var w,C=o*o,T=new Uint16Array(3);for(e=0;e=C)||(_[r]|=A,g&&_[r]&M&&(s.toArray(e,t,i,T),w=T[0]*a+T[1]*u+T[2],v[r]=v[w])));console.timeEnd("EDTSurface fastdistancemap")}function R(e,t,i,n){var r,s,a,o,h,d,f,m,p,g,v,b,x=new Uint16Array(3),w=0;if(0===i)return w;var T=-1,P=-1,E=-1,I=c*u;for(f=0,p=i;f-1&&P-1&&E-1&&(_[v=T*I+u*P+E]&S&&!(_[v]&M)?(t.fromArray(T,P,E,x),g=(o=T-x[0])*o+(h=P-x[1])*h+(d=E-x[2])*d,y[v]=g,_[v]|=M,_[v]|=A,n[w]=T,n[w+1]=P,n[w+2]=E,w+=3):_[v]&S&&_[v]&M&&(g=(o=T-x[0])*o+(h=P-x[1])*h+(d=E-x[2])*d)-1&&P-1&&E-1&&(_[v=T*I+u*P+E]&S&&!(_[v]&M)?(t.fromArray(T,P,E,x),g=(o=T-x[0])*o+(h=P-x[1])*h+(d=E-x[2])*d,y[v]=g,_[v]|=M,_[v]|=A,n[w]=T,n[w+1]=P,n[w+2]=E,w+=3):_[v]&S&&_[v]&M&&(g=(o=T-x[0])*o+(h=P-x[1])*h+(d=E-x[2])*d)-1&&P-1&&E-1&&(_[v=T*I+u*P+E]&S&&!(_[v]&M)?(t.fromArray(T,P,E,x),g=(o=T-x[0])*o+(h=P-x[1])*h+(d=E-x[2])*d,y[v]=g,_[v]|=M,_[v]|=A,n[w]=T,n[w+1]=P,n[w+2]=E,w+=3):_[v]&S&&_[v]&M&&(g=(o=T-x[0])*o+(h=P-x[1])*h+(d=E-x[2])*d)-1&&a-1&&h-1&&oI&&(I=k)}return{neighbourListLength:27*I+1,withinRadii:function(r,s,a,o,h){for(var d=0,f=m(r,l),p=m(s,c),g=m(a,u),_=Math.max(0,f-1),x=Math.max(0,p-1),S=Math.max(0,g-1),M=Math.min(y,f+2),A=Math.min(v,p+2),E=Math.min(b,g+2),I=_;Id&&(d=u[e]);!function(){const e=Pf(l,c,d,m,0);m=e.scaleFactor,_=e.dim,y=e.matrix,L=Math.max(5,2+Math.floor(f*m)),v=Sc(_[0]*_[1]*_[2],-1001),b=new Int32Array(v.length),x=new Float32Array(_[0]),w=new Float32Array(_[1]),S=new Float32Array(_[2]),O(x,l[0],1/m),O(w,l[1],1/m),O(S,l[2],1/m)}(),function(){var e=0,t=2*Math.PI/g;A=new Float32Array(g),M=new Float32Array(g);for(var i=0;i=0;){if(s!==n&&s!==r&&F(s,e,t,i))return P=s,s;s=T[++a]}return P=-1,-1}function F(t,i,n,r){var s=3*t,a=h[t],o=e[s]-i,l=e[s+1]-n,c=e[s+2]-r;return o*o+l*l+c*c0&&d=0;)e{t(this._makeSurface(e.data.sd,i))}),(e=>{console.warn("MolecularSurface.getSurfaceWorker error - trying without worker",e),this.worker.terminate(),this.worker=void 0;const n=this.getSurface(i);t(n)}))}else{const e=this.getSurface(i);t(e)}}dispose(){this.worker&&this.worker.terminate()}}class Oy extends y_{constructor(e,t,i){super(e,t,i),this.type="surface",this.parameters=Object.assign({surfaceType:{type:"select",rebuild:!0,options:{vws:"vws",sas:"sas",ms:"ms",ses:"ses",av:"av"}},probeRadius:{type:"number",precision:1,max:20,min:0,rebuild:!0},smooth:{type:"integer",precision:1,max:10,min:0,rebuild:!0},scaleFactor:{type:"number",precision:1,max:5,min:0,rebuild:!0},cutoff:{type:"number",precision:2,max:50,min:0,rebuild:!0},contour:{type:"boolean",rebuild:!0},background:{type:"boolean",rebuild:!0},opaqueBack:{type:"boolean",buffer:!0},filterSele:{type:"text",rebuild:!0},colorVolume:{type:"hidden"},useWorker:{type:"boolean",rebuild:!0}},this.parameters,{radius:null,scale:null}),this.__infoList=[],this.structure.signals.refreshed.add((()=>{this.__forceNewMolsurf=!0})),this.toBePrepared=!0,this.init(i)}init(e){const t=e||{};t.colorScheme=uo(t.colorScheme,"uniform"),t.colorValue=uo(t.colorValue,14540253),t.disablePicking=uo(t.disablePicking,!0),this.surfaceType=uo(t.surfaceType,"ms"),this.probeRadius=uo(t.probeRadius,1.4),this.smooth=uo(t.smooth,2),this.scaleFactor=uo(t.scaleFactor,2),this.cutoff=uo(t.cutoff,0),this.contour=uo(t.contour,!1),this.background=uo(t.background,!1),this.opaqueBack=uo(t.opaqueBack,!0),this.filterSele=uo(t.filterSele,""),this.colorVolume=uo(t.colorVolume,void 0),this.useWorker=uo(t.useWorker,!0),super.init(e)}prepareData(e,t,i){let n=this.__infoList[t];if(n||(n={},this.__infoList[t]=n),n.molsurf&&n.sele===e.selection.string)i(t);else{if(this.filterSele){const n=e.structure.getView(new wl(this.filterSele)),r=n.boundingBox.getSize(new _t),s=Math.max(r.x,r.y,r.z),a=e.getAtomSetWithinPoint(n.center,s/2+6);if(0===(e=e.getView(new wl(e.getAtomSetWithinSelection(a,3).toSeleString()))).atomCount)return void i(t)}n.sele=e.selection.string,n.molsurf=new ky(e);const r=this.getSurfaceParams(),s=e=>{n.surface=e,i(t)};this.useWorker?n.molsurf.getSurfaceWorker(r,s):s(n.molsurf.getSurface(r))}}prepare(e){if((this.__forceNewMolsurf||this.__sele!==this.selection.string||this.__surfaceParams!==JSON.stringify(this.getSurfaceParams()))&&(this.__infoList.forEach((e=>{e&&e.molsurf&&e.molsurf.dispose()})),this.__infoList.length=0),0===this.structureView.atomCount)return void e();const t=()=>{this.__sele=this.selection.string,this.__surfaceParams=JSON.stringify(this.getSurfaceParams()),this.__forceNewMolsurf=!1,e()},i="default"===this.assembly?this.defaultAssembly:this.assembly,n=this.structure.biomolDict[i];n?n.partList.forEach(((e,i)=>{const r=e.getView(this.structureView);this.prepareData(r,i,(e=>{e===n.partList.length-1&&t()}))})):this.prepareData(this.structureView,0,t)}createData(e,t){const i=this.__infoList[t],n=i.surface;if(!n)return;const r={position:n.getPosition(),color:n.getColor(this.getColorParams()),index:n.getFilteredIndex(this.filterSele,e)},s=[];if(n.contour){const e=new Gf(r,this.getBufferParams({wireframe:!1}));s.push(e)}else{Object.assign(r,{normal:n.getNormal(),picking:n.getPicking(e.getStructure())});const t=new zf(r,this.getBufferParams({background:this.background,opaqueBack:this.opaqueBack,dullInterior:!1}));if("double"==this.getBufferParams().side){const e=new $f(t);s.push(e)}else s.push(t)}return{bufferList:s,info:i}}updateData(e,t){const i={};if(e.position||e.radius)return this.__forceNewMolsurf=!0,void this.build();e.color&&(i.color=t.info.surface.getColor(this.getColorParams())),e.index&&(i.index=t.info.surface.getFilteredIndex(this.filterSele,t.sview)),t.bufferList[0].setAttributes(i)}setParameters(e,t={},i){return e&&e.filterSele&&(t.index=!0),e&&void 0!==e.colorVolume&&(t.color=!0),e&&e.wireframe&&(e.contour||void 0===e.contour&&this.contour)&&(e.wireframe=!1),super.setParameters(e,t,i),this}getSurfaceParams(e={}){return Object.assign({type:this.surfaceType,probeRadius:this.probeRadius,scaleFactor:this.scaleFactor,smooth:this.smooth&&!this.contour,cutoff:this.cutoff,contour:this.contour,useWorker:this.useWorker,radiusParams:this.getRadiusParams()},e)}getColorParams(){const e=super.getColorParams();return e.volume=this.colorVolume,e}getAtomRadius(){return 0}clear(){super.clear()}dispose(){this.__infoList.forEach((e=>{e&&e.molsurf&&e.molsurf.dispose()})),this.__infoList.length=0,super.dispose()}}Hl.add("surface",Oy);class Ny extends y_{constructor(e,t,i){super(e,t,i),this.type="point",this.parameters=Object.assign({pointSize:{type:"number",precision:1,max:100,min:0,buffer:!0},sizeAttenuation:{type:"boolean",buffer:!0},sortParticles:{type:"boolean",rebuild:!0},useTexture:{type:"boolean",buffer:!0},alphaTest:{type:"range",step:.001,max:1,min:0,buffer:!0},forceTransparent:{type:"boolean",buffer:!0},edgeBleach:{type:"range",step:.001,max:1,min:0,buffer:!0}},this.parameters,{flatShaded:null,wireframe:null,linewidth:null,side:null,roughness:null,metalness:null}),this.init(i)}init(e){var t=e||{};this.pointSize=uo(t.pointSize,1),this.sizeAttenuation=uo(t.sizeAttenuation,!0),this.sortParticles=uo(t.sortParticles,!1),this.useTexture=uo(t.useTexture,!1),this.alphaTest=uo(t.alphaTest,.5),this.forceTransparent=uo(t.forceTransparent,!1),this.edgeBleach=uo(t.edgeBleach,0),super.init(t)}createData(e){var t=e.getAtomData(this.getAtomParams({position:!0,color:!0,picking:!0}));return{bufferList:[new Up(t,this.getBufferParams({pointSize:this.pointSize,sizeAttenuation:this.sizeAttenuation,sortParticles:this.sortParticles,useTexture:this.useTexture,alphaTest:this.alphaTest,forceTransparent:this.forceTransparent,edgeBleach:this.edgeBleach}))]}}updateData(e,t){var i=t.sview.getAtomData(this.getAtomParams(e)),n={};e&&!e.position||Object.assign(n,{position:i.position}),e&&!e.color||Object.assign(n,{color:i.color}),t.bufferList[0].setAttributes(n)}getAtomRadius(){return.1}}Hl.add("point",Ny),Wl.add("shader/Ribbon.vert","#define STANDARD\nuniform float clipNear;\nuniform vec3 clipCenter;\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvarying vec3 vViewPosition;\n#endif\n#if defined( RADIUS_CLIP )\nvarying vec3 vClipCenter;\n#endif\nattribute vec3 dir;\nattribute float size;\n#ifdef PICKING\n#include unpack_color\nattribute float primitiveId;\nvarying vec3 vPickingColor;\n#else\n#include color_pars_vertex\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#endif\n#endif\n#include common\nvoid main(void){\n#ifdef PICKING\nvPickingColor = unpackColor( primitiveId );\n#else\n#include color_vertex\n#include beginnormal_vertex\n#include defaultnormal_vertex\n#ifndef FLAT_SHADED\nvNormal = normalize( transformedNormal );\n#endif\n#endif\n#include begin_vertex\ntransformed += normalize( dir ) * size;\n#include project_vertex\n#if defined( NEAR_CLIP ) || defined( RADIUS_CLIP ) || !defined( PICKING )\nvViewPosition = -mvPosition.xyz;\n#endif\n#if defined( RADIUS_CLIP )\nvClipCenter = -( modelViewMatrix * vec4( clipCenter, 1.0 ) ).xyz;\n#endif\n#include nearclip_vertex\n}");const Fy=new Uint16Array([0,1,2,1,3,2]);function By(e){return 3*(4*(e.position.length/3-1))}class zy extends Bf{constructor(e,t={}){super({position:new Float32Array(By(e)),color:new Float32Array(By(e)),index:So(By(e),By(e)/3),normal:new Float32Array(By(e)),picking:e.picking},t),this.vertexShader="Ribbon.vert";const i=e.position.length/3-1,n=4*i,r=3*n;this.addAttributes({dir:{type:"v3",value:new Float32Array(r)}}),this.addAttributes({size:{type:"f",value:new Float32Array(n)}}),e.primitiveId=Ac(i),this.setAttributes(e),this.makeIndex()}setAttributes(e={}){const t=this.size/4,i=this.geometry.attributes;let n,r,s,a,o,l,c,u,h,d,f,m,p,g,_,y,v,b,x;e.position&&(n=e.position,c=i.position.array,i.position.needsUpdate=!0),e.normal&&(r=e.normal,u=i.normal.array,i.normal.needsUpdate=!0),e.size&&(s=e.size,h=i.size.array,i.size.needsUpdate=!0),e.dir&&(a=e.dir,d=i.dir.array,i.dir.needsUpdate=!0),e.color&&(o=e.color,f=i.color.array,i.color.needsUpdate=!0),e.primitiveId&&(l=e.primitiveId,m=i.primitiveId.array,i.primitiveId.needsUpdate=!0);let w=s?s[0]:null;for(p=0;p{if(!(e.residueCount<4)){i.push(e);var n=new ey(e,this.getSplineParams()),r=n.getSubdividedPosition(),s=n.getSubdividedOrientation(),a=n.getSubdividedColor(this.getColorParams()),o=n.getSubdividedPicking(),l=n.getSubdividedSize(this.getRadiusParams());t.push(new zy({position:r.position,normal:s.binormal,dir:s.normal,color:a.color,size:l.size,picking:o.picking},this.getBufferParams()))}}),e.getSelection()),{bufferList:t,polymerList:i}}updateData(e,t){e=e||{};var i=0,n=t.polymerList.length;for(i=0;i{if(e.residueCount<4||e.isNucleic())return;const r=new xm(e),s=r.getAxis(this.localAngle,this.centerDist,this.ssBorder,this.getColorParams(),this.getRadiusParams());t+=s.size.length,i.push(s),n.push(r)}),e.getSelection());const r={begin:new Float32Array(3*t),end:new Float32Array(3*t),size:new Float32Array(t),color:new Float32Array(3*t),picking:{}};let s=new Float32Array(t),a=0;i.forEach((function(e){r.begin.set(e.begin,3*a),r.end.set(e.end,3*a),r.size.set(e.size,a),r.color.set(e.color,3*a),s.set(e.picking.array,a),a+=e.size.length})),t&&(r.picking=new Hd(s,e.getStructure()));return{bufferList:[new X_({position1:r.begin,position2:r.end,color:r.color,color2:r.color,radius:r.size,picking:r.picking},this.getBufferParams({openEnded:this.openEnded,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0}))],axisList:i,helixbundleList:n,axisData:r}}updateData(e,t){if((e=e||{}).position)this.build();else{var i={};if(e.color||e.radius){var n=0;t.helixbundleList.forEach((i=>{var r=i.getAxis(this.localAngle,this.centerDist,this.ssBorder,this.getColorParams(),this.getRadiusParams());e.color&&t.axisData.color.set(r.color,3*n),(e.radius||e.scale)&&t.axisData.size.set(r.size,n),n+=r.size.length})),e.color&&Object.assign(i,{color:t.axisData.color,color2:t.axisData.color}),(e.radius||e.scale)&&Object.assign(i,{radius:t.axisData.size})}t.bufferList[0].setAttributes(i)}}}Hl.add("rocket",Vy);class $y extends sy{constructor(e,t,i){super(e,t,i),this.type="rope",this.parameters=Object.assign({smooth:{type:"integer",max:15,min:0,rebuild:!0}},this.parameters,{aspectRatio:null,smoothSheet:null})}init(e){var t=e||{};t.aspectRatio=1,t.tension=uo(t.tension,.5),t.radiusScale=uo(t.radiusScale,5),t.smoothSheet=!1,this.smooth=uo(t.smooth,2),super.init(t)}getSpline(e){var t=new bm(e);return new ey(e,this.getSplineParams({directional:!1,positionIterator:t.getCenterIterator(this.smooth)}))}}Hl.add("rope",$y);class Gy extends y_{constructor(e,t,i){super(e,t,i),this.type="spacefill",this.parameters=Object.assign({sphereDetail:!0,disableImpostor:!0},this.parameters),this.init(i)}init(e){var t=e||{};t.useInteriorColor=uo(t.useInteriorColor,!0),super.init(t)}createData(e){return{bufferList:[new Np(e.getAtomData(this.getAtomParams()),this.getBufferParams({sphereDetail:this.sphereDetail,dullInterior:!0,disableImpostor:this.disableImpostor}))]}}updateData(e,t){var i=t.sview.getAtomData(this.getAtomParams(e)),n={};e&&!e.position||Object.assign(n,{position:i.position}),e&&!e.color||Object.assign(n,{color:i.color}),e&&!e.radius||Object.assign(n,{radius:i.radius}),t.bufferList[0].setAttributes(n)}}function Hy(e){return 3*(e.position.length/3-1)*2}Hl.add("spacefill",Gy);class jy extends Ff{constructor(e,t={}){super({position:new Float32Array(Hy(e)),color:new Float32Array(Hy(e))},t),this.isLine=!0,this.vertexShader="Line.vert",this.fragmentShader="Line.frag",this.setAttributes(e)}setAttributes(e){let t,i,n,r;const s=this.geometry.attributes;if(e.position&&(t=e.position,n=s.position.array,s.position.needsUpdate=!0),e.color&&(i=e.color,r=s.color.array,s.color.needsUpdate=!0),!t&&!i)return void Fl.warn("TraceBuffer.prototype.setAttributes no data");let a,o;const l=this.size-1;for(let e=0;e{if(!(e.residueCount<4)){i.push(e);var n=new ey(e,this.getSplineParams()),r=n.getSubdividedPosition(),s=n.getSubdividedColor(this.getColorParams());t.push(new jy(Object.assign({},r,s),this.getBufferParams()))}}),e.getSelection()),{bufferList:t,polymerList:i}}updateData(e,t){e=e||{};var i=0,n=t.polymerList.length;for(i=0;i{e.boundingBox||e.computeBoundingBox(),this.boundingBox.union(e.boundingBox)}))}}const nv=Object.assign({aspectRatio:1.5,radialSegments:50,openEnded:!1,disableImpostor:!1},Of);class rv{constructor(e,t={}){this.group=new ma,this.wireframeGroup=new ma,this.pickingGroup=new ma,this.visible=!0,this.parameters=ho(t,this.defaultParameters),this.splitPosition=new Float32Array(e.position1.length),this.cylinderRadius=new Float32Array(e.radius.length);const i=this.makeAttributes(e),n={radialSegments:this.parameters.radialSegments,openEnded:this.parameters.openEnded,disableImpostor:this.parameters.disableImpostor};this.cylinderBuffer=new X_(i.cylinder,n),this.coneBuffer=new tv(i.cone,n),this.geometry=new iv([this.cylinderBuffer.geometry,this.coneBuffer.geometry]),this.matrix=uo(t.matrix,new qt),this.picking=e.picking}get defaultParameters(){return nv}set matrix(e){Ff.prototype.setMatrix.call(this,e)}get matrix(){return this.group.matrix.clone()}get pickable(){return!!this.picking}makeAttributes(e={}){const t=this.splitPosition,i=this.cylinderRadius,n=this.parameters.aspectRatio;let r,s;const a={},o={};if(e.radius){for(r=0,s=i.length;r0&&(s=1/Math.sqrt(s),e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s),e}function h(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function d(e,t,i){const n=t[0],r=t[1],s=t[2],a=i[0],o=i[1],l=i[2];return e[0]=r*l-s*o,e[1]=s*a-n*l,e[2]=n*o-r*a,e}e.zero=t,e.clone=function(e){const i=t();return i[0]=e[0],i[1]=e[1],i[2]=e[2],i},e.isFinite=function(e){return $v(e[0])&&$v(e[1])&&$v(e[2])},e.hasNaN=function(e){return isNaN(e[0])||isNaN(e[1])||isNaN(e[2])},e.setNaN=function(e){return e[0]=NaN,e[1]=NaN,e[2]=NaN,e},e.fromObj=function(e){return i(e.x,e.y,e.z)},e.toObj=function(e){return{x:e[0],y:e[1],z:e[2]}},e.fromArray=function(e,t,i){return e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2],e},e.toArray=function(e,t,i){return t[i+0]=e[0],t[i+1]=e[1],t[i+2]=e[2],t},e.create=i,e.ofArray=function(e){const i=t();return i[0]=e[0],i[1]=e[1],i[2]=e[2],i},e.set=function(e,t,i,n){return e[0]=t,e[1]=i,e[2]=n,e},e.copy=n,e.add=r,e.sub=s,e.mul=function(e,t,i){return e[0]=t[0]*i[0],e[1]=t[1]*i[1],e[2]=t[2]*i[2],e},e.div=function(e,t,i){return e[0]=t[0]/i[0],e[1]=t[1]/i[1],e[2]=t[2]/i[2],e},e.scale=a,e.scaleAndAdd=o,e.scaleAndSub=function(e,t,i,n){return e[0]=t[0]-i[0]*n,e[1]=t[1]-i[1]*n,e[2]=t[2]-i[2]*n,e},e.addScalar=function(e,t,i){return e[0]=t[0]+i,e[1]=t[1]+i,e[2]=t[2]+i,e},e.subScalar=function(e,t,i){return e[0]=t[0]-i,e[1]=t[1]-i,e[2]=t[2]-i,e},e.round=function(e,t){return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e[2]=Math.round(t[2]),e},e.ceil=function(e,t){return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2]),e},e.floor=function(e,t){return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2]),e},e.trunc=function(e,t){return e[0]=Math.trunc(t[0]),e[1]=Math.trunc(t[1]),e[2]=Math.trunc(t[2]),e},e.abs=function(e,t){return e[0]=Math.abs(t[0]),e[1]=Math.abs(t[1]),e[2]=Math.abs(t[2]),e},e.min=function(e,t,i){return e[0]=Math.min(t[0],i[0]),e[1]=Math.min(t[1],i[1]),e[2]=Math.min(t[2],i[2]),e},e.max=function(e,t,i){return e[0]=Math.max(t[0],i[0]),e[1]=Math.max(t[1],i[1]),e[2]=Math.max(t[2],i[2]),e},e.clamp=function(e,t,i,n){return e[0]=Math.max(i[0],Math.min(n[0],t[0])),e[1]=Math.max(i[1],Math.min(n[1],t[1])),e[2]=Math.max(i[2],Math.min(n[2],t[2])),e},e.distance=function(e,t){const i=t[0]-e[0],n=t[1]-e[1],r=t[2]-e[2];return Math.sqrt(i*i+n*n+r*r)},e.squaredDistance=function(e,t){const i=t[0]-e[0],n=t[1]-e[1],r=t[2]-e[2];return i*i+n*n+r*r},e.magnitude=function(e){const t=e[0],i=e[1],n=e[2];return Math.sqrt(t*t+i*i+n*n)},e.squaredMagnitude=l,e.setMagnitude=function(e,t,i){return a(e,u(e,t),i)},e.negate=c,e.inverse=function(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e},e.normalize=u,e.dot=h,e.cross=d,e.lerp=function(e,t,i,n){const r=t[0],s=t[1],a=t[2];return e[0]=r+n*(i[0]-r),e[1]=s+n*(i[1]-s),e[2]=a+n*(i[2]-a),e};const f=t();function m(e,t){const i=Math.sqrt(l(e)*l(t));if(0===i)return Math.PI/2;const n=h(e,t)/i;return Math.acos(zv(n,-1,1))}e.slerp=function(e,t,i,n){const s=zv(h(t,i),-1,1),l=Math.acos(s)*n;return o(f,i,t,-s),u(f,f),r(e,a(e,t,Math.cos(l)),a(f,f,Math.sin(l)))},e.hermite=function(e,t,i,n,r,s){const a=s*s,o=a*(2*s-3)+1,l=a*(s-2)+s,c=a*(s-1),u=a*(3-2*s);return e[0]=t[0]*o+i[0]*l+n[0]*c+r[0]*u,e[1]=t[1]*o+i[1]*l+n[1]*c+r[1]*u,e[2]=t[2]*o+i[2]*l+n[2]*c+r[2]*u,e},e.bezier=function(e,t,i,n,r,s){const a=1-s,o=a*a,l=s*s,c=o*a,u=3*s*o,h=3*l*a,d=l*s;return e[0]=t[0]*c+i[0]*u+n[0]*h+r[0]*d,e[1]=t[1]*c+i[1]*u+n[1]*h+r[1]*d,e[2]=t[2]*c+i[2]*u+n[2]*h+r[2]*d,e},e.quadraticBezier=function(e,t,i,n,r){return e[0]=Vv(t[0],i[0],n[0],r),e[1]=Vv(t[1],i[1],n[1],r),e[2]=Vv(t[2],i[2],n[2],r),e},e.spline=function(e,t,i,n,r,s,a){return e[0]=Uv(t[0],i[0],n[0],r[0],s,a),e[1]=Uv(t[1],i[1],n[1],r[1],s,a),e[2]=Uv(t[2],i[2],n[2],r[2],s,a),e},e.random=function(e,t){const i=2*Math.random()*Math.PI,n=2*Math.random()-1,r=Math.sqrt(1-n*n)*t;return e[0]=Math.cos(i)*r,e[1]=Math.sin(i)*r,e[2]=n*t,e},e.transformMat4=function(e,t,i){const n=t[0],r=t[1],s=t[2],a=1/(i[3]*n+i[7]*r+i[11]*s+i[15]||1);return e[0]=(i[0]*n+i[4]*r+i[8]*s+i[12])*a,e[1]=(i[1]*n+i[5]*r+i[9]*s+i[13])*a,e[2]=(i[2]*n+i[6]*r+i[10]*s+i[14])*a,e},e.transformDirection=function(e,t,i){const n=t[0],r=t[1],s=t[2];return e[0]=i[0]*n+i[4]*r+i[8]*s,e[1]=i[1]*n+i[5]*r+i[9]*s,e[2]=i[2]*n+i[6]*r+i[10]*s,u(e,e)},e.transformMat4Offset=function(e,t,i,n,r,s){const a=t[0+r],o=t[1+r],l=t[2+r],c=1/(i[3+s]*a+i[7+s]*o+i[11+s]*l+i[15+s]||1);return e[0+n]=(i[0+s]*a+i[4+s]*o+i[8+s]*l+i[12+s])*c,e[1+n]=(i[1+s]*a+i[5+s]*o+i[9+s]*l+i[13+s])*c,e[2+n]=(i[2+s]*a+i[6+s]*o+i[10+s]*l+i[14+s])*c,e},e.transformDirectionOffset=function(e,t,i,n,r,s){const a=t[0+r],o=t[1+r],l=t[2+r];e[0+n]=i[0+s]*a+i[4+s]*o+i[8+s]*l,e[1+n]=i[1+s]*a+i[5+s]*o+i[9+s]*l,e[2+n]=i[2+s]*a+i[6+s]*o+i[10+s]*l;const c=Math.hypot(e[0+n],e[1+n],e[2+n]);return c>0&&(e[0+n]/=c,e[1+n]/=c,e[2+n]/=c),e},e.transformMat3=function(e,t,i){const n=t[0],r=t[1],s=t[2];return e[0]=n*i[0]+r*i[3]+s*i[6],e[1]=n*i[1]+r*i[4]+s*i[7],e[2]=n*i[2]+r*i[5]+s*i[8],e},e.transformQuat=function(e,t,i){const n=t[0],r=t[1],s=t[2],a=i[0],o=i[1],l=i[2],c=i[3],u=c*n+o*s-l*r,h=c*r+l*n-a*s,d=c*s+a*r-o*n,f=-a*n-o*r-l*s;return e[0]=u*c+f*-a+h*-l-d*-o,e[1]=h*c+f*-o+d*-a-u*-l,e[2]=d*c+f*-l+u*-o-h*-a,e},e.angle=m;const p=t(),g=t(),_=t(),y=t(),v=t(),b=t(),x=t();e.dihedralAngle=function(e,t,i,n){s(p,e,t),s(g,i,t),s(_,t,i),s(y,n,i),d(v,p,g),d(b,_,y);const r=m(v,b);return d(x,v,b),h(g,x)>0?r:-r},e.directionFromSpherical=function(t,i,n,r){return e.set(t,r*Math.cos(n)*Math.sin(i),r*Math.sin(n)*Math.sin(i),r*Math.cos(i))},e.exactEquals=function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]},e.equals=function(e,t){const i=e[0],n=e[1],r=e[2],s=t[0],a=t[1],o=t[2];return Math.abs(i-s)<=Fv*Math.max(1,Math.abs(i),Math.abs(s))&&Math.abs(n-a)<=Fv*Math.max(1,Math.abs(n),Math.abs(a))&&Math.abs(r-o)<=Fv*Math.max(1,Math.abs(r),Math.abs(o))};const w=t();e.makeRotation=function(t,i,n){const r=m(i,n);if(Math.abs(r)<1e-4)return Wv.setIdentity(t);if(Math.abs(r-Math.PI)0?n(e,t):c(e,n(e,t)),e};const C=t(),T=t();e.triangleNormal=function(e,t,i,n){return s(C,i,t),s(T,n,t),u(e,d(e,C,T))},e.toString=function(e,t){return`[${e[0].toPrecision(t)} ${e[1].toPrecision(t)} ${e[2].toPrecision(t)}]`},e.origin=i(0,0,0),e.unit=i(1,1,1),e.negUnit=i(-1,-1,-1),e.unitX=i(1,0,0),e.unitY=i(0,1,0),e.unitZ=i(0,0,1),e.negUnitX=i(-1,0,0),e.negUnitY=i(0,-1,0),e.negUnitZ=i(0,0,-1)}(Gv||(Gv={}));const Hv=Math.PI/180;function jv(e){return e*Hv}function Wv(){return Wv.zero()}function qv(){return qv.zero()}function Xv(){return Xv.zero()}function Yv(){return Yv.zero()}function Kv(e){throw new Error("unreachable")}function Zv(){return Zv.zero()}var Qv,Jv,eb,tb;function ib(e,t,i){let n=t,r=0,s=1;for(45===e.charCodeAt(n)?(s=-1,++n):43===e.charCodeAt(n)&&++n;n9||t<0)return s*r|0;r=10*r+t|0}return s*r}function nb(e,t,i,n){return 43===t.charCodeAt(i)&&i++,e*Math.pow(10,ib(t,i,n))}function rb(e,t,i){let n=t,r=1,s=0,a=0,o=1;for(45===e.charCodeAt(n)?(r=-1,++n):43===e.charCodeAt(n)&&++n;n=0&&t<10)){if(-2===t){for(++n;n=0&&t<10))return 53===t||21===t?nb(r*(s+a/o),e,n+1,i):r*(s+a/o);a=10*a+t,o*=10,++n}return r*(s+a/o)}if(53===t||21===t)return nb(r*s,e,n+1,i);break}s=10*s+t,++n}return r*s}function sb(e,t,i,n){return{schema:i,__array:void 0,isDefined:0===n,rowCount:t,value:t=>e,valueKind:e=>n,toArray:i=>{const{array:n}=Lv(t,i);for(let t=0,i=n.length;t!0}}function ab({value:e,valueKind:t,areValuesEqual:i,rowCount:n,schema:r}){return{schema:r,__array:void 0,isDefined:!0,rowCount:n,value:e,valueKind:t||(e=>0),toArray:t=>{const{array:i,start:r}=Lv(n,t);for(let t=0,n=i.length;te(t)===e(i))}}function ob({array:e,schema:t,valueKind:i}){const n=e.length,r=t.T,s="str"===t.valueType?"lowercase"===t.transform?t=>{const i=e[t];return"string"==typeof i?i.toLowerCase():`${null!=i?i:r}`.toLowerCase()}:"uppercase"===t.transform?t=>{const i=e[t];return"string"==typeof i?i.toUpperCase():`${null!=i?i:r}`.toUpperCase()}:t=>{const i=e[t];return"string"==typeof i?i:`${null!=i?i:r}`}:t=>e[t],a=Ov(e);return{schema:t,__array:e,isDefined:!0,rowCount:n,value:s,valueKind:i||(e=>0),toArray:"str"===t.valueType?"lowercase"===t.transform?t=>{const{start:i,end:s}=Rv(n,t),a=new(t&&void 0!==t.array?t.array:e.constructor)(s-i);for(let t=0,n=s-i;t{const{start:i,end:s}=Rv(n,t),a=new(t&&void 0!==t.array?t.array:e.constructor)(s-i);for(let t=0,n=s-i;t{const{start:i,end:s}=Rv(n,t),a=new(t&&void 0!==t.array?t.array:e.constructor)(s-i);for(let t=0,n=s-i;tNv(e,t):t=>{const{start:i,end:r}=Rv(n,t);if(0===i&&r===e.length)return e;const s=new(t&&void 0!==t.array?t.array:e.constructor)(r-i);for(let t=0,n=r-i;te[t]===e[i]}}function lb(e,t,i){return e.isDefined?0===t&&i===e.rowCount?e:e.__array&&Ov(e.__array)?function(e,t,i){const n=Nv(e.__array,{start:t,end:i}),r=e.valueKind;return ob({array:n,schema:e.schema,valueKind:e=>r(t+e)})}(e,t,i):function(e,t,i){const n=e.value,r=e.valueKind,s=e.areValuesEqual,a=0===t?n:e=>n(e+t),o=i-t;return{schema:e.schema,__array:void 0,isDefined:e.isDefined,rowCount:o,value:a,valueKind:0===t?r:e=>r(e+t),toArray:e=>{const{array:i}=Lv(o,e);for(let e=0,r=i.length;es(e+t,i+t)}}(e,t,i):Jv.Undefined(i-t,e.schema)}function cb(e,t,i){return 0===e.rowCount||i&&function(e,t){if(e.length!==t)return!1;for(let t=0,i=e.length;tr(t[e])})}(e,t):function(e,t){const i=e.value,n=e.valueKind,r=e.areValuesEqual,s=e=>i(t[e]),a=t.length;return{schema:e.schema,__array:void 0,isDefined:e.isDefined,rowCount:a,value:s,valueKind:e=>n(t[e]),toArray:e=>{const{array:n}=Lv(a,e);for(let e=0,r=n.length;er(t[e],t[i])}}(e,t)}function ub(e,t,i){return e[t]-e[i]}function hb(e,t,i){const n=e[t];e[t]=e[i],e[i]=n}function db(e,t,i,n){const r=i+n>>1;return t(e,i,n)>0?t(e,i,r)>0?t(e,r,n)>0?r:n:i:t(e,n,r)>0?t(e,r,i)>0?r:i:n}function fb(e,t,i){const{cmp:n,swap:r,data:s,parts:a}=e;let o=t+1,l=i;for(r(s,t,db(s,n,t,i));n(s,l,t)>0;)--l;for(let e=t+1;e<=l;e++){const i=n(s,e,t);if(i>0){for(r(s,e,l),--l;n(s,l,t)>0;)--l;e--}else 0===i&&(r(s,e,o),o++)}for(let e=t;e=n&&t(e,r,r+1)>0;)i(e,r,r+1),r-=1}}function pb(e,t,i){const{parts:n}=e;for(;ta;)--s;for(let t=i+1;t<=s;t++){const i=e[t];if(i>a){for(hb(e,t,s),--s;e[s]>a;)--s;t--}else i===a&&(hb(e,t,r),++r)}for(let t=i;t=t&&e[r]>i;)e[r+1]=e[r],r-=1;e[r+1]=i}}function yb(e,t,i,n){for(;ii)return!1;return!0}function o(e,t,i,n){e[4*i+t]=n}function l(e,t){return 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],e}function c(e,t){const i=t[0]+t[5]+t[10];let n=0;return i>0?(n=2*Math.sqrt(i+1),e[3]=.25*n,e[0]=(t[6]-t[9])/n,e[1]=(t[8]-t[2])/n,e[2]=(t[1]-t[4])/n):t[0]>t[5]&&t[0]>t[10]?(n=2*Math.sqrt(1+t[0]-t[5]-t[10]),e[3]=(t[6]-t[9])/n,e[0]=.25*n,e[1]=(t[1]+t[4])/n,e[2]=(t[8]+t[2])/n):t[5]>t[10]?(n=2*Math.sqrt(1+t[5]-t[0]-t[10]),e[3]=(t[8]-t[2])/n,e[0]=(t[1]+t[4])/n,e[1]=.25*n,e[2]=(t[6]+t[9])/n):(n=2*Math.sqrt(1+t[10]-t[0]-t[5]),e[3]=(t[1]-t[4])/n,e[0]=(t[8]+t[2])/n,e[1]=(t[6]+t[9])/n,e[2]=.25*n),e}function u(e,t){const i=t[0],n=t[1],r=t[2],s=t[3],a=t[4],o=t[5],l=t[6],c=t[7],u=t[8],h=t[9],d=t[10],f=t[11],m=t[12],p=t[13],g=t[14],_=t[15],y=i*o-n*a,v=i*l-r*a,b=i*c-s*a,x=n*l-r*o,w=n*c-s*o,S=r*c-s*l,M=u*p-h*m,A=u*g-d*m,C=u*_-f*m,T=h*g-d*p,P=h*_-f*p,E=d*_-f*g;let I=y*E-v*P+b*T+x*C-w*A+S*M;return!!I&&(I=1/I,e[0]=(o*E-l*P+c*T)*I,e[1]=(r*P-n*E-s*T)*I,e[2]=(p*S-g*w+_*x)*I,e[3]=(d*w-h*S-f*x)*I,e[4]=(l*C-a*E-c*A)*I,e[5]=(i*E-r*C+s*A)*I,e[6]=(g*b-m*S-_*v)*I,e[7]=(u*S-d*b+f*v)*I,e[8]=(a*P-o*C+c*M)*I,e[9]=(n*C-i*P-s*M)*I,e[10]=(m*w-p*b+_*y)*I,e[11]=(h*b-u*w-f*y)*I,e[12]=(o*A-a*T-l*M)*I,e[13]=(i*T-n*A+r*M)*I,e[14]=(p*v-m*x-g*y)*I,e[15]=(u*x-h*v+d*y)*I,!0)}function h(e,t,i){const n=t[0],r=t[1],s=t[2],a=t[3],o=t[4],l=t[5],c=t[6],u=t[7],h=t[8],d=t[9],f=t[10],m=t[11],p=t[12],g=t[13],_=t[14],y=t[15];let v=i[0],b=i[1],x=i[2],w=i[3];return e[0]=v*n+b*o+x*h+w*p,e[1]=v*r+b*l+x*d+w*g,e[2]=v*s+b*c+x*f+w*_,e[3]=v*a+b*u+x*m+w*y,v=i[4],b=i[5],x=i[6],w=i[7],e[4]=v*n+b*o+x*h+w*p,e[5]=v*r+b*l+x*d+w*g,e[6]=v*s+b*c+x*f+w*_,e[7]=v*a+b*u+x*m+w*y,v=i[8],b=i[9],x=i[10],w=i[11],e[8]=v*n+b*o+x*h+w*p,e[9]=v*r+b*l+x*d+w*g,e[10]=v*s+b*c+x*f+w*_,e[11]=v*a+b*u+x*m+w*y,v=i[12],b=i[13],x=i[14],w=i[15],e[12]=v*n+b*o+x*h+w*p,e[13]=v*r+b*l+x*d+w*g,e[14]=v*s+b*c+x*f+w*_,e[15]=v*a+b*u+x*m+w*y,e}function d(e,t,i){let r=i[0],s=i[1],a=i[2],o=Math.sqrt(r*r+s*s+a*a);if(Math.abs(o)0&&(f=1/Math.sqrt(f),u*=f,h*=f,d*=f);let m=l*d-c*h,p=c*u-o*d,g=o*h-l*u;return f=m*m+p*p+g*g,f>0&&(f=1/Math.sqrt(f),m*=f,p*=f,g*=f),e[0]=m,e[1]=p,e[2]=g,e[3]=0,e[4]=h*g-d*p,e[5]=d*m-u*g,e[6]=u*p-h*m,e[7]=0,e[8]=u,e[9]=h,e[10]=d,e[11]=0,e[12]=r,e[13]=s,e[14]=a,e[15]=1,e},e.fromPermutation=function(e,t){r(e);for(let i=0;i<4;i++){o(e,i,t[i],1)}return e},e.getMaxScaleOnAxis=function(e){const t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],n=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,i,n))};const g=[1,0,0],_=[0,1,0],y=[0,0,1];e.rotX90=d(t(),jv(90),g),e.rotX180=d(t(),jv(180),g),e.rotY90=d(t(),jv(90),_),e.rotY180=d(t(),jv(180),_),e.rotY270=d(t(),jv(270),_),e.rotZ90=d(t(),jv(90),y),e.rotZ180=d(t(),jv(180),y),e.rotXY90=h(t(),e.rotX90,e.rotY90),e.rotZY90=h(t(),e.rotZ90,e.rotY90),e.rotZYZ90=h(t(),e.rotZY90,e.rotZ90),e.rotZ90X180=h(t(),e.rotZ90,e.rotX180),e.rotY90Z180=h(t(),e.rotY90,e.rotZ180),e.id=i()}(Wv||(Wv={})),function(e){function t(){const e=[.1,0,0,0,0,0,0,0,0];return e[0]=0,e}function i(){const e=t();return 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}function n(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}e.zero=t,e.identity=i,e.setIdentity=function(e){return 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},e.toArray=function(e,t,i){return t[i+0]=e[0],t[i+1]=e[1],t[i+2]=e[2],t[i+3]=e[3],t[i+4]=e[4],t[i+5]=e[5],t[i+6]=e[6],t[i+7]=e[7],t[i+8]=e[8],t},e.fromArray=function(e,t,i){return e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2],e[3]=t[i+3],e[4]=t[i+4],e[5]=t[i+5],e[6]=t[i+6],e[7]=t[i+7],e[8]=t[i+8],e},e.fromColumns=function(e,t,i,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=i[0],e[4]=i[1],e[5]=i[2],e[6]=n[0],e[7]=n[1],e[8]=n[2],e},e.fromMat4=n;const r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];e.fromEuler=function(e,t,i){return Wv.fromEuler(r,t,i),n(e,r)},e.create=function(e,i,n,r,s,a,o,l,c){const u=t();return u[0]=e,u[1]=i,u[2]=n,u[3]=r,u[4]=s,u[5]=a,u[6]=o,u[7]=l,u[8]=c,u};const s=i();function a(e,t,i){for(let n=0;n<9;n++)if(Math.abs(e[n]-t[n])>i)return!1;return!0}function o(e,t){return 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}function l(e,t){if(e===t){const i=t[1],n=t[2],r=t[5];e[1]=t[3],e[2]=t[6],e[3]=i,e[5]=t[7],e[6]=n,e[7]=r}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8];return e}function c(e,t){const i=t[0],n=t[1],r=t[2],s=t[3],a=t[4],o=t[5],l=t[6],c=t[7],u=t[8],h=u*a-o*c,d=-u*s+o*l,f=c*s-a*l;let m=i*h+n*d+r*f;return m?(m=1/m,e[0]=h*m,e[1]=(-u*n+r*c)*m,e[2]=(o*n-r*a)*m,e[3]=d*m,e[4]=(u*i-r*l)*m,e[5]=(-o*i+r*s)*m,e[6]=f*m,e[7]=(-c*i+n*l)*m,e[8]=(a*i-n*s)*m,e):(console.warn("non-invertible matrix.",t),e)}function u(e){const t=e[0],i=e[1],n=e[2],r=e[3],s=e[4],a=e[5],o=e[6],l=e[7],c=e[8];return t*(c*s-a*l)+i*(-c*r+a*o)+n*(l*r-s*o)}function h(e){return e[0]+e[4]+e[8]}function d(e,t,i){return e[0]=t[0]-i[0],e[1]=t[1]-i[1],e[2]=t[2]-i[2],e[3]=t[3]-i[3],e[4]=t[4]-i[4],e[5]=t[5]-i[5],e[6]=t[6]-i[6],e[7]=t[7]-i[7],e[8]=t[8]-i[8],e}function f(e,t,i){return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e[4]=t[4]*i,e[5]=t[5]*i,e[6]=t[6]*i,e[7]=t[7]*i,e[8]=t[8]*i,e}e.isIdentity=function(e,t){return a(e,s,void 0===t?Fv:t)},e.hasNaN=function(e){for(let t=0;t<9;t++)if(isNaN(e[t]))return!0;return!1},e.clone=function(e){return o(t(),e)},e.areEqual=a,e.setValue=function(e,t,i,n){e[3*i+t]=n},e.getValue=function(e,t,i){return e[3*i+t]},e.copy=o,e.transpose=l,e.invert=c,e.symmtricFromUpper=function(e,t){return e===t?(e[3]=t[1],e[6]=t[2],e[7]=t[5]):(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[1],e[4]=t[4],e[5]=t[5],e[6]=t[2],e[7]=t[5],e[8]=t[8]),e},e.symmtricFromLower=function(e,t){return e===t?(e[1]=t[3],e[2]=t[6],e[5]=t[7]):(e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[3],e[4]=t[4],e[5]=t[7],e[6]=t[6],e[7]=t[7],e[8]=t[8]),e},e.determinant=u,e.trace=h,e.sub=d,e.add=function(e,t,i){return e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2],e[3]=t[3]+i[3],e[4]=t[4]+i[4],e[5]=t[5]+i[5],e[6]=t[6]+i[6],e[7]=t[7]+i[7],e[8]=t[8]+i[8],e},e.mul=function(e,t,i){const n=t[0],r=t[1],s=t[2],a=t[3],o=t[4],l=t[5],c=t[6],u=t[7],h=t[8],d=i[0],f=i[1],m=i[2],p=i[3],g=i[4],_=i[5],y=i[6],v=i[7],b=i[8];return e[0]=d*n+f*a+m*c,e[1]=d*r+f*o+m*u,e[2]=d*s+f*l+m*h,e[3]=p*n+g*a+_*c,e[4]=p*r+g*o+_*u,e[5]=p*s+g*l+_*h,e[6]=y*n+v*a+b*c,e[7]=y*r+v*o+b*u,e[8]=y*s+v*l+b*h,e},e.subScalar=function(e,t,i){return e[0]=t[0]-i,e[1]=t[1]-i,e[2]=t[2]-i,e[3]=t[3]-i,e[4]=t[4]-i,e[5]=t[5]-i,e[6]=t[6]-i,e[7]=t[7]-i,e[8]=t[8]-i,e},e.addScalar=function(e,t,i){return e[0]=t[0]+i,e[1]=t[1]+i,e[2]=t[2]+i,e[3]=t[3]+i,e[4]=t[4]+i,e[5]=t[5]+i,e[6]=t[6]+i,e[7]=t[7]+i,e[8]=t[8]+i,e},e.mulScalar=f;const m=Math.PI/3,p=t();e.symmetricEigenvalues=function(t,i){const n=i[1]*i[1]+i[2]*i[2]+i[5]*i[5];if(0===n)t[0]=i[0],t[1]=i[4],t[2]=i[8];else{const r=h(i)/3,s=i[0]-r,a=i[4]-r,o=i[8]-r,l=s*s+a*a+o*o+2*n,c=Math.sqrt(l/6);f(p,e.Identity,r),d(p,i,p),f(p,p,1/c);const g=u(p)/2,_=g<=-1?m:g>=1?0:Math.acos(g)/3;t[0]=r+2*c*Math.cos(_),t[2]=r+2*c*Math.cos(_+2*m),t[1]=3*r-t[0]-t[2]}return t};const g=[.1,0,0],_=[.1,0,0],y=[.1,0,0],v=[.1,0,0],b=[.1,0,0],x=[.1,0,0];e.eigenvector=function(e,t,i){Gv.set(g,t[0]-i,t[1],t[2]),Gv.set(_,t[1],t[4]-i,t[5]),Gv.set(y,t[2],t[5],t[8]-i),Gv.cross(v,g,_),Gv.cross(b,g,y),Gv.cross(x,_,y);const n=Gv.dot(v,v),r=Gv.dot(b,b),s=Gv.dot(x,x);let a=n,o=0;return r>a&&(a=r,o=1),s>a&&(o=2),0===o?Gv.scale(e,v,1/Math.sqrt(n)):1===o?Gv.scale(e,b,1/Math.sqrt(r)):Gv.scale(e,x,1/Math.sqrt(s)),e},e.directionTransform=function(e,t){return n(e,t),c(e,e),l(e,e),e},e.Identity=i(),e.innerProduct=function(e,t){return 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]}}(qv||(qv={})),function(e){function t(){const e=[.1,0];return e[0]=0,e}e.zero=t,e.clone=function(e){const i=t();return i[0]=e[0],i[1]=e[1],i},e.create=function(e,i){const n=t();return n[0]=e,n[1]=i,n},e.hasNaN=function(e){return isNaN(e[0])||isNaN(e[1])},e.toArray=function(e,t,i){return t[i+0]=e[0],t[i+1]=e[1],t},e.fromArray=function(e,t,i){return e[0]=t[i+0],e[1]=t[i+1],e},e.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e},e.set=function(e,t,i){return e[0]=t,e[1]=i,e},e.add=function(e,t,i){return e[0]=t[0]+i[0],e[1]=t[1]+i[1],e},e.sub=function(e,t,i){return e[0]=t[0]-i[0],e[1]=t[1]-i[1],e},e.mul=function(e,t,i){return e[0]=t[0]*i[0],e[1]=t[1]*i[1],e},e.div=function(e,t,i){return e[0]=t[0]/i[0],e[1]=t[1]/i[1],e},e.scale=function(e,t,i){return e[0]=t[0]*i,e[1]=t[1]*i,e},e.round=function(e,t){return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e},e.ceil=function(e,t){return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e},e.floor=function(e,t){return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e},e.distance=function(e,t){const i=t[0]-e[0],n=t[1]-e[1];return Math.sqrt(i*i+n*n)},e.squaredDistance=function(e,t){const i=t[0]-e[0],n=t[1]-e[1];return i*i+n*n},e.magnitude=function(e){const t=e[0],i=e[1];return Math.sqrt(t*t+i*i)},e.squaredMagnitude=function(e){const t=e[0],i=e[1];return t*t+i*i},e.inverse=function(e,t){return e[0]=1/t[0],e[1]=1/t[1],e},e.areEqual=function(e,t){return e[0]===t[0]&&e[1]===t[1]},e.toString=function(e,t){return`[${e[0].toPrecision(t)} ${e[1].toPrecision(t)}}]`}}(Xv||(Xv={})),function(e){function t(){const e=[.1,0,0,0];return e[0]=0,e}function i(e,t){return e[0]=t.center[0],e[1]=t.center[1],e[2]=t.center[2],e[3]=t.radius,e}e.zero=t,e.clone=function(e){const i=t();return i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=e[3],i},e.create=function(e,i,n,r){const s=t();return s[0]=e,s[1]=i,s[2]=n,s[3]=r,s},e.fromSphere=i,e.ofSphere=function(e){return i(t(),e)},e.hasNaN=function(e){return isNaN(e[0])||isNaN(e[1])||isNaN(e[2])||isNaN(e[3])},e.toArray=function(e,t,i){return t[i+0]=e[0],t[i+1]=e[1],t[i+2]=e[2],t[i+3]=e[3],t},e.fromArray=function(e,t,i){return e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2],e[3]=t[i+3],e},e.toVec3Array=function(e,t,i){t[i+0]=e[0],t[i+1]=e[1],t[i+2]=e[2]},e.fromVec3Array=function(e,t,i){return e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2],e[3]=0,e},e.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},e.set=function(e,t,i,n,r){return e[0]=t,e[1]=i,e[2]=n,e[3]=r,e},e.add=function(e,t,i){return e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2],e[3]=t[3]+i[3],e},e.distance=function(e,t){const i=t[0]-e[0],n=t[1]-e[1],r=t[2]-e[2],s=t[3]-e[3];return Math.sqrt(i*i+n*n+r*r+s*s)},e.scale=function(e,t,i){return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[4]=t[4]*i,e},e.round=function(e,t){return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e[2]=Math.round(t[2]),e[3]=Math.round(t[3]),e},e.ceil=function(e,t){return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2]),e[3]=Math.ceil(t[3]),e},e.floor=function(e,t){return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2]),e[3]=Math.floor(t[3]),e},e.squaredDistance=function(e,t){const i=t[0]-e[0],n=t[1]-e[1],r=t[2]-e[2],s=t[3]-e[3];return i*i+n*n+r*r+s*s},e.norm=function(e){const t=e[0],i=e[1],n=e[2],r=e[3];return Math.sqrt(t*t+i*i+n*n+r*r)},e.squaredNorm=function(e){const t=e[0],i=e[1],n=e[2],r=e[3];return t*t+i*i+n*n+r*r},e.transformMat4=function(e,t,i){const n=t[0],r=t[1],s=t[2],a=t[3];return e[0]=i[0]*n+i[4]*r+i[8]*s+i[12]*a,e[1]=i[1]*n+i[5]*r+i[9]*s+i[13]*a,e[2]=i[2]*n+i[6]*r+i[10]*s+i[14]*a,e[3]=i[3]*n+i[7]*r+i[11]*s+i[15]*a,e},e.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},e.inverse=function(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e[3]=1/t[3],e},e.exactEquals=function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]},e.equals=function(e,t){const i=e[0],n=e[1],r=e[2],s=e[3],a=t[0],o=t[1],l=t[2],c=t[3];return Math.abs(i-a)<=Fv*Math.max(1,Math.abs(i),Math.abs(a))&&Math.abs(n-o)<=Fv*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(r-l)<=Fv*Math.max(1,Math.abs(r),Math.abs(l))&&Math.abs(s-c)<=Fv*Math.max(1,Math.abs(s),Math.abs(c))},e.toString=function(e,t){return`[${e[0].toPrecision(t)} ${e[1].toPrecision(t)} ${e[2].toPrecision(t)} ${e[3].toPrecision(t)}]`}}(Yv||(Yv={})),function(e){function t(){const e=[.1,0,0,0];return e[0]=0,e}function i(){const e=t();return e[3]=1,e}function n(e,t,i){i*=.5;const n=Math.sin(i);return e[0]=n*t[0],e[1]=n*t[1],e[2]=n*t[2],e[3]=Math.cos(i),e}function r(e,t,i,n){const r=t[0],s=t[1],a=t[2],o=t[3];let l,c,u,h,d,f=i[0],m=i[1],p=i[2],g=i[3];return c=r*f+s*m+a*p+o*g,c<0&&(c=-c,f=-f,m=-m,p=-p,g=-g),1-c>1e-6?(l=Math.acos(c),u=Math.sin(l),h=Math.sin((1-n)*l)/u,d=Math.sin(n*l)/u):(h=1-n,d=n),e[0]=h*r+d*f,e[1]=h*s+d*m,e[2]=h*a+d*p,e[3]=h*o+d*g,e}function s(e,t){const i=t[0]+t[4]+t[8];let n;if(i>0)n=Math.sqrt(i+1),e[3]=.5*n,n=.5/n,e[0]=(t[5]-t[7])*n,e[1]=(t[6]-t[2])*n,e[2]=(t[1]-t[3])*n;else{let i=0;t[4]>t[0]&&(i=1),t[8]>t[3*i+i]&&(i=2);const r=(i+1)%3,s=(i+2)%3;n=Math.sqrt(t[3*i+i]-t[3*r+r]-t[3*s+s]+1),e[i]=.5*n,n=.5/n,e[3]=(t[3*r+s]-t[3*s+r])*n,e[r]=(t[3*r+i]+t[3*i+r])*n,e[s]=(t[3*s+i]+t[3*i+s])*n}return e}e.zero=t,e.identity=i,e.setIdentity=function(e){e[0]=0,e[1]=0,e[2]=0,e[3]=1},e.hasNaN=function(e){return isNaN(e[0])||isNaN(e[1])||isNaN(e[2])||isNaN(e[3])},e.create=function(e,t,n,r){const s=i();return s[0]=e,s[1]=t,s[2]=n,s[3]=r,s},e.setAxisAngle=n,e.getAxisAngle=function(e,t){const i=2*Math.acos(t[3]),n=Math.sin(i/2);return 0!==n?(e[0]=t[0]/n,e[1]=t[1]/n,e[2]=t[2]/n):(e[0]=1,e[1]=0,e[2]=0),i},e.multiply=function(e,t,i){const n=t[0],r=t[1],s=t[2],a=t[3],o=i[0],l=i[1],c=i[2],u=i[3];return e[0]=n*u+a*o+r*c-s*l,e[1]=r*u+a*l+s*o-n*c,e[2]=s*u+a*c+n*l-r*o,e[3]=a*u-n*o-r*l-s*c,e},e.rotateX=function(e,t,i){i*=.5;const n=t[0],r=t[1],s=t[2],a=t[3],o=Math.sin(i),l=Math.cos(i);return e[0]=n*l+a*o,e[1]=r*l+s*o,e[2]=s*l-r*o,e[3]=a*l-n*o,e},e.rotateY=function(e,t,i){i*=.5;const n=t[0],r=t[1],s=t[2],a=t[3],o=Math.sin(i),l=Math.cos(i);return e[0]=n*l-s*o,e[1]=r*l+a*o,e[2]=s*l+n*o,e[3]=a*l-r*o,e},e.rotateZ=function(e,t,i){i*=.5;const n=t[0],r=t[1],s=t[2],a=t[3],o=Math.sin(i),l=Math.cos(i);return e[0]=n*l+r*o,e[1]=r*l-n*o,e[2]=s*l+a*o,e[3]=a*l-s*o,e},e.calculateW=function(e,t){const i=t[0],n=t[1],r=t[2];return e[0]=i,e[1]=n,e[2]=r,e[3]=Math.sqrt(Math.abs(1-i*i-n*n-r*r)),e},e.slerp=r,e.invert=function(e,t){const i=t[0],n=t[1],r=t[2],s=t[3],a=i*i+n*n+r*r+s*s,o=a?1/a:0;return e[0]=-i*o,e[1]=-n*o,e[2]=-r*o,e[3]=s*o,e},e.conjugate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e},e.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},e.fromMat3=s,e.fromEuler=function(e,t,i){const[n,r,s]=t,a=Math.cos(n/2),o=Math.cos(r/2),l=Math.cos(s/2),c=Math.sin(n/2),u=Math.sin(r/2),h=Math.sin(s/2);switch(i){case"XYZ":e[0]=c*o*l+a*u*h,e[1]=a*u*l-c*o*h,e[2]=a*o*h+c*u*l,e[3]=a*o*l-c*u*h;break;case"YXZ":e[0]=c*o*l+a*u*h,e[1]=a*u*l-c*o*h,e[2]=a*o*h-c*u*l,e[3]=a*o*l+c*u*h;break;case"ZXY":e[0]=c*o*l-a*u*h,e[1]=a*u*l+c*o*h,e[2]=a*o*h+c*u*l,e[3]=a*o*l-c*u*h;break;case"ZYX":e[0]=c*o*l-a*u*h,e[1]=a*u*l+c*o*h,e[2]=a*o*h-c*u*l,e[3]=a*o*l+c*u*h;break;case"YZX":e[0]=c*o*l+a*u*h,e[1]=a*u*l+c*o*h,e[2]=a*o*h-c*u*l,e[3]=a*o*l-c*u*h;break;case"XZY":e[0]=c*o*l-a*u*h,e[1]=a*u*l-c*o*h,e[2]=a*o*h+c*u*l,e[3]=a*o*l+c*u*h;break;default:Kv()}return e};const a=[0,0,0];function o(e,t){const i=t[0],n=t[1],r=t[2],s=t[3];let a=i*i+n*n+r*r+s*s;return a>0&&(a=1/Math.sqrt(a),e[0]=i*a,e[1]=n*a,e[2]=r*a,e[3]=s*a),e}e.fromUnitVec3=function(e,t,i){let n=Gv.dot(t,i)+1;return nMath.abs(t[2])?Gv.set(a,-t[1],t[0],0):Gv.set(a,0,-t[2],t[1])):Gv.cross(a,t,i),e[0]=a[0],e[1]=a[1],e[2]=a[2],e[3]=n,o(e,e),e},e.clone=function(e){const i=t();return i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=e[3],i},e.toArray=function(e,t,i){return t[i+0]=e[0],t[i+1]=e[1],t[i+2]=e[2],t[i+3]=e[3],t},e.fromArray=function(e,t,i){return e[0]=t[i+0],e[1]=t[i+1],e[2]=t[i+2],e[3]=t[i+3],e},e.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},e.set=function(e,t,i,n,r){return e[0]=t,e[1]=i,e[2]=n,e[3]=r,e},e.exactEquals=function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]},e.equals=function(e,t){const i=e[0],n=e[1],r=e[2],s=e[3],a=t[0],o=t[1],l=t[2],c=t[3];return Math.abs(i-a)<=Fv*Math.max(1,Math.abs(i),Math.abs(a))&&Math.abs(n-o)<=Fv*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(r-l)<=Fv*Math.max(1,Math.abs(r),Math.abs(l))&&Math.abs(s-c)<=Fv*Math.max(1,Math.abs(s),Math.abs(c))},e.add=function(e,t,i){return e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2],e[3]=t[3]+i[3],e},e.normalize=o;const l=[0,0,0],c=[1,0,0],u=[0,1,0];e.rotationTo=function(e,t,i){const r=Gv.dot(t,i);return r<-.999999?(Gv.cross(l,c,t),Gv.magnitude(l)<1e-6&&Gv.cross(l,u,t),Gv.normalize(l,l),n(e,l,Math.PI),e):r>.999999?(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e):(Gv.cross(l,t,i),e[0]=l[0],e[1]=l[1],e[2]=l[2],e[3]=1+r,o(e,e))};const h=t(),d=t();e.sqlerp=function(e,t,i,n,s,a){return r(h,t,s,a),r(d,i,n,a),r(e,h,d,2*a*(1-a)),e};const f=[0,0,0,0,0,0,0,0,0];e.setAxes=function(e,t,i,n){return f[0]=i[0],f[3]=i[1],f[6]=i[2],f[1]=n[0],f[4]=n[1],f[7]=n[2],f[2]=-t[0],f[5]=-t[1],f[8]=-t[2],o(e,s(e,f))},e.toString=function(e,t){return`[${e[0].toPrecision(t)} ${e[1].toPrecision(t)} ${e[2].toPrecision(t)} ${e[3].toPrecision(t)}]`},e.Identity=i()}(Zv||(Zv={})),function(e){function t(e,t,r){const s=function(e,t,i){const n=[];for(let e=0;ee[t],set:(e,t,i)=>e[t]=i,add:(e,t,i)=>e[t]+=i,dataOffset:e=>e,getCoords:(e,t)=>(t[0]=e,t)};case 2:if(0===i[0]&&1===i[1]){const e=t[0];return{get:(t,i,n)=>t[n*e+i],set:(t,i,n,r)=>t[n*e+i]=r,add:(t,i,n,r)=>t[n*e+i]+=r,dataOffset:(t,i)=>i*e+t,getCoords:(t,i)=>(i[0]=t%e,i[1]=Math.floor(t/e),i)}}if(1===i[0]&&0===i[1]){const e=t[1];return{get:(t,i,n)=>t[i*e+n],set:(t,i,n,r)=>t[i*e+n]=r,add:(t,i,n,r)=>t[i*e+n]+=r,dataOffset:(t,i)=>t*e+i,getCoords:(t,i)=>(i[0]=Math.floor(t/e),i[1]=t%e,i)}}throw new Error("bad axis order");case 3:if(0===i[0]&&1===i[1]&&2===i[2]){const e=t[0],i=t[1],n=e*i;return{get:(t,i,r,s)=>t[i+r*e+s*n],set:(t,i,r,s,a)=>t[i+r*e+s*n]=a,add:(t,i,r,s,a)=>t[i+r*e+s*n]+=a,dataOffset:(t,i,r)=>t+i*e+r*n,getCoords:(t,n)=>{const r=Math.floor(t/e);return n[0]=t%e,n[1]=r%i,n[2]=Math.floor(r/i),n}}}if(0===i[0]&&2===i[1]&&1===i[2]){const e=t[0],i=t[2],n=e*i;return{get:(t,i,r,s)=>t[i+s*e+r*n],set:(t,i,r,s,a)=>t[i+s*e+r*n]=a,add:(t,i,r,s,a)=>t[i+s*e+r*n]+=a,dataOffset:(t,i,r)=>t+r*e+i*n,getCoords:(t,n)=>{const r=Math.floor(t/e);return n[0]=t%e,n[1]=Math.floor(r/i),n[2]=r%i,n}}}if(1===i[0]&&0===i[1]&&2===i[2]){const e=t[1],i=t[0],n=e*i;return{get:(t,i,r,s)=>t[r+i*e+s*n],set:(t,i,r,s,a)=>t[r+i*e+s*n]=a,add:(t,i,r,s,a)=>t[r+i*e+s*n]+=a,dataOffset:(t,i,r)=>i+t*e+r*n,getCoords:(t,n)=>{const r=Math.floor(t/e);return n[0]=r%i,n[1]=t%e,n[2]=Math.floor(r/i),n}}}if(1===i[0]&&2===i[1]&&0===i[2]){const e=t[1],i=t[2],n=e*i;return{get:(t,i,r,s)=>t[r+s*e+i*n],set:(t,i,r,s,a)=>t[r+s*e+i*n]=a,add:(t,i,r,s,a)=>t[r+s*e+i*n]+=a,dataOffset:(t,i,r)=>i+r*e+t*n,getCoords:(t,n)=>{const r=Math.floor(t/e);return n[0]=Math.floor(r/i),n[1]=t%e,n[2]=r%i,n}}}if(2===i[0]&&0===i[1]&&1===i[2]){const e=t[2],i=t[0],n=e*i;return{get:(t,i,r,s)=>t[s+i*e+r*n],set:(t,i,r,s,a)=>t[s+i*e+r*n]=a,add:(t,i,r,s,a)=>t[s+i*e+r*n]+=a,dataOffset:(t,i,r)=>r+t*e+i*n,getCoords:(t,n)=>{const r=Math.floor(t/e);return n[0]=r%i,n[1]=Math.floor(r/i),n[2]=t%e,n}}}if(2===i[0]&&1===i[1]&&0===i[2]){const e=t[2],i=t[1],n=e*i;return{get:(t,i,r,s)=>t[s+r*e+i*n],set:(t,i,r,s,a)=>t[s+r*e+i*n]=a,add:(t,i,r,s,a)=>t[s+r*e+i*n]+=a,dataOffset:(t,i,r)=>r+i*e+t*n,getCoords:(t,n)=>{const r=Math.floor(t/e);return n[0]=Math.floor(r/i),n[1]=r%i,n[2]=t%e,n}}}throw new Error("bad axis order");default:return{get:(t,...i)=>t[r(e,i)],set:(t,...i)=>t[r(e,i)]=i[i.length-1],add:(t,...i)=>t[r(e,i)]+=i[i.length-1],dataOffset:(...t)=>r(e,t),getCoords:(t,i)=>function(e,t,i){const{dimensions:n,axisOrderFastToSlow:r}=e,s=n.length;let a=t;for(let e=0;enew(t||e.defaultCtor)(i)}function r(e,t){const{accessDimensions:i,axisOrderFastToSlow:n}=e,r=i.length-1;let s=i[r]*t[n[r]];for(let e=r-1;e>=0;e--)s=(s+t[n[e]])*i[e];return s}function s(e,t){const i=[];for(let n=0;ns(e,t)},e.convertToCanonicalAxisIndicesSlowToFast=function(e){const t=new Int32Array(e.length);for(let i=0;is(e,t)}}(Qv||(Qv={})),function(e){let t;function i(e,t){return sb(t.T,e,t,1)}function n(e){return ab(e)}!function(e){function t(t,i=e.float){return{"@type":"tensor",T:t.create(),space:t,valueType:"tensor",baseType:i}}e.str={"@type":"str",T:"",valueType:"str"},e.ustr={"@type":"str",T:"",valueType:"str",transform:"uppercase"},e.lstr={"@type":"str",T:"",valueType:"str",transform:"lowercase"},e.int={"@type":"int",T:0,valueType:"int"},e.coord={"@type":"coord",T:0,valueType:"float"},e.float={"@type":"float",T:0,valueType:"float"},e.Str=function(e){var t;return{"@type":"str",T:null!==(t=null==e?void 0:e.defaultValue)&&void 0!==t?t:"",transform:null==e?void 0:e.transform,valueType:"str"}},e.Int=function(e=0){return{"@type":"int",T:e,valueType:"int"}},e.Float=function(e=0){return{"@type":"float",T:e,valueType:"float"}},e.Tensor=t,e.Vector=function(i,n=e.float){return t(Qv.Vector(i,"int"===n["@type"]?Int32Array:Float64Array),n)},e.Matrix=function(i,n,r=e.float){return t(Qv.ColumnMajorMatrix(i,n,"int"===r["@type"]?Int32Array:Float64Array),r)},e.Aliased=function(e){return e},e.List=function(e,t,i=[]){return{"@type":"list",T:i,separator:e,itemParse:t,valueType:"list"}}}(t=e.Schema||(e.Schema={})),e.is=function(e){return!!e&&!!e.schema&&!!e.value},e.ValueKind={Present:0,NotPresent:1,Unknown:2},e.Undefined=i,e.ofConst=function(e,t,i){return sb(e,t,i,0)},e.ofLambda=n,e.range=function(e,i){return n({value:t=>t+e,rowCount:Math.max(i-e+1,0),schema:t.int})},e.ofArray=function(e){return ob(e)},e.ofIntArray=function(e){return ob({array:e,schema:t.int})},e.ofFloatArray=function(e){return ob({array:e,schema:t.float})},e.ofStringArray=function(e){return ob({array:e,schema:t.str})},e.ofStringAliasArray=function(e){return ob({array:e,schema:t.Aliased(t.str)})},e.ofStringListArray=function(e,i=","){return ob({array:e,schema:t.List(i,(e=>e))})},e.ofIntTokens=function(e){const{count:i,data:n,indices:r}=e;return ab({value:e=>ib(n,r[2*e],r[2*e+1])||0,rowCount:i,schema:t.int})},e.ofFloatTokens=function(e){const{count:i,data:n,indices:r}=e;return ab({value:e=>rb(n,r[2*e],r[2*e+1])||0,rowCount:i,schema:t.float})},e.ofStringTokens=function(e){const{count:i,data:n,indices:r}=e;return ab({value:e=>{const t=n.substring(r[2*e],r[2*e+1]);return"."===t||"?"===t?"":t},rowCount:i,schema:t.str})},e.window=function(e,t,i){return lb(e,t,i)},e.view=function(e,t,i=!0){return cb(e,t,i)},e.createFirstIndexMap=function(e){return function(e){const t=new Map;for(let i=0,n=e.rowCount;it.has(e)?t.get(e):-1}(e)},e.mapToArray=function(e,t,i){return function(e,t,i){const n=new i(e.rowCount);for(let i=0,r=e.rowCount;i0&&(e.chunks[e.chunks.length]=e.current.length===e.offset?e.current.join(""):e.current.slice(0,e.offset).join("")),e.chunks.join("")):e.current.length===e.offset?e.current.join(""):e.current.splice(0,e.offset).join("")},e.getSize=function(e){let t=0;for(const i of e.chunks)t+=i.length;for(let i=0;i0&&(e.current.length===e.offset?e.chunks[e.chunks.length]=e.current.join(""):e.chunks[e.chunks.length]=e.current.slice(0,e.offset).join(""),e.offset=0),e.chunks};const t=[];function i(e,i){i>0&&n(e,t[i])}function n(e,t){e.offset===e.capacity&&(e.chunks[e.chunks.length]=e.current.join(""),e.offset=0),e.current[e.offset++]=t}!function(){let e="";for(let i=0;i<512;i++)t[i]=e,e+=" "}(),e.newline=function(e){n(e,"\n")},e.whitespace=i,e.whitespace1=function(e){n(e," ")},e.write=function(e,t){t&&(e.offset===e.capacity&&(e.chunks[e.chunks.length]=e.current.join(""),e.offset=0),e.current[e.offset++]=t)},e.writeSafe=n,e.writePadLeft=function(e,t,r){if(!t)return void i(e,r);i(e,r-t.length),n(e,t)},e.writePadRight=function(e,t,r){if(!t)return void i(e,r);const s=r-t.length;n(e,t),i(e,s)},e.writeInteger=function(e,t){n(e,""+t)},e.writeIntegerAndSpace=function(e,t){n(e,t+" ")},e.writeIntegerPadLeft=function(e,t,r){const s=""+t;i(e,r-s.length),n(e,s)},e.writeIntegerPadRight=function(e,t,r){const s=""+t,a=r-s.length;n(e,s),i(e,a)},e.writeFloat=function(e,t,i){n(e,""+Math.round(i*t)/i)},e.writeFloatPadLeft=function(e,t,r,s){const a=""+Math.round(r*t)/r;i(e,s-a.length),n(e,a)},e.writeFloatPadRight=function(e,t,r,s){const a=""+Math.round(r*t)/r,o=s-a.length;n(e,a),i(e,o)}}(tb||(tb={}));const bb=function(){if("undefined"!=typeof window&&window.performance){const e=window.performance;return()=>e.now()}return"undefined"!=typeof process&&"undefined"!==process.hrtime&&"function"==typeof process.hrtime?()=>{const e=process.hrtime();return 1e3*e[0]+e[1]/1e6}:Date.now?()=>Date.now():()=>+new Date}();var xb,wb,Sb;function Mb(e,t){return e-t}function Ab(e=0,t=Number.MAX_SAFE_INTEGER){let i=e;return()=>{const e=i;return i=(i+1)%t,e}}!function(e){const t="undefined"!=typeof btoa?btoa:e=>Buffer.from(e).toString("base64"),i=[];e.create22=function(){let e=+new Date+bb();for(let t=0;t<16;t++)i[t]=String.fromCharCode((e+255*Math.random())%255|0),e=Math.floor(e/255);return t(i.join("")).replace(/\+/g,"-").replace(/\//g,"_").substr(0,22)},e.createv4=function(){let e=+new Date+bb();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){const i=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?i:3&i|8).toString(16)}))},e.is=function(e){return"string"==typeof e}}(xb||(xb={})),function(e){class t{has(e){return!1}forEach(e,t){return t}constructor(){this.size=0}}class i{has(e){return e===this.idx}forEach(e,t){return e(this.idx,t),t}constructor(e){this.idx=e,this.size=1}}class n{has(e){return ee[t++]=i)),function(e){Array.prototype.sort.call(e,Mb)}(e),this._flat=e,this._flat}forEach(e,t){return this._forEach(e,t),t}constructor(e){this.set=e,this._flat=void 0,this.size=e.size}}function a(e){return new s(e)}function o(e,t){return new n(e,t)}e.always=function(e){return new r(e)},e.never=new t,e.ofSet=a,e.singleton=function(e){return new i(e)},e.ofUniqueIndices=function(e){const a=e.length;if(0===a)return new t;if(1===a)return new i(e[0]);let o=0;for(const t of e)t>o&&(o=t);if(a===o)return new r(a);if(a/o<1/12){const t=new Set;for(const i of e)t.add(i);return new s(t)}const l=new Int8Array(o+1);for(const t of e)l[t]=1;return new n(l,e.length)},e.ofMask=o,e.hasAny=function(e,t){for(const i of t)if(e.has(i))return!0;return!1},e.complement=function(e,t){let i=0,n=0;if(t.forEach((t=>{e.has(t)||(i++,t>n&&(n=t))})),i/n<1/12){const i=new Set;return t.forEach((t=>{e.has(t)||i.add(t)})),a(i)}{const r=new Uint8Array(n+1);return t.forEach((t=>{e.has(t)||(r[t]=1)})),o(r,i)}}}(wb||(wb={})),function(e){e.create=function(e){return{ref:e}},e.set=function(e,t){return e.ref=t,e}}(Sb||(Sb={}));const Cb=Ab(0,2147483647);var Tb,Pb,Eb,Ib,Db;function Rb(e){const{data:t,indices:i}=e;return function(e,n){const r=i[2*e],s=i[2*n],a=i[2*e+1]-r;if(a!==i[2*n+1]-s)return!1;for(let e=0;en[e]}}!function(e){e.create=function(e,t){return{id:Cb(),version:0,value:e,metadata:t}},e.withValue=function(e,t){return{id:e.id,version:e.version+1,value:t,metadata:e.metadata}}}(Tb||(Tb={})),function(e){function t(e,t){return Sb.set(e,Tb.withValue(e.ref,t))}e.create=function(e,t){return Sb.create(Tb.create(e,t))},e.update=t,e.set=function(e,t){return Sb.set(e,t)},e.updateIfChanged=function(e,i){return e.ref.value!==i?t(e,i):e}}(Pb||(Pb={})),function(e){function t(e,t,i){const n=Object.create(null),r=Object.keys(t);n._rowCount=i.length,n._columns=r,n._schema=t;for(const t of r)n[t]=Jv.view(e[t],i);return n}function i(e,t){const i=Object.create(null),{_columns:n}=e;for(let r=0;rt[e][s],valueKind:e=>void 0===t[e][s]?1:0});return i},e.ofArrays=function(e,t){var i;const n=Object.create(null),r=Object.keys(e);n._rowCount=0,n._columns=r,n._schema=e;for(const s of r)void 0!==t[s]?(n[s]=Jv.ofArray({array:t[s],schema:e[s]}),n._rowCount=null===(i=t[s])||void 0===i?void 0:i.length):n[s]=Jv.Undefined(n._rowCount,e[s]);return n},e.view=t,e.pick=function(e,i,n){const r=[];for(let t=0,i=e._rowCount;tt(i,n)));let n=!0;for(let e=0,t=i.length;e0?t[i[0]].rowCount:0,name:e,fieldNames:i,getField:e=>t[e]}}e.empty=function(e){return{rowCount:0,name:e,fieldNames:[],getField(e){}}},e.ofFields=t,e.ofTable=function(e,i){const n={};for(const e of i._columns)n[e]=Db.ofColumn(i[e]);return t(e,n)}}(Ob||(Ob={})),function(e){function t(e){const t=e.length,i=t=>{const i=e[t];return i&&"."!==i&&"?"!==i?i:""},n=t=>{const i=e[t];return ib(i,0,i.length)||0},r=t=>{const i=e[t];return rb(i,0,i.length)||0};return{__array:void 0,binaryEncoding:void 0,isDefined:!0,rowCount:t,str:i,int:n,float:r,valueKind:t=>{const i=e[t],n=i.length;if(n>1)return 0;if(0===n)return 1;const r=i.charCodeAt(0);return 46===r?1:63===r?2:0},areValuesEqual:(t,i)=>e[t]===e[i],toStringArray:n=>n?kv(t,i,n):e,toIntArray:e=>kv(t,n,e),toFloatArray:e=>kv(t,r,e)}}function i(e){const{rowCount:t,valueKind:i,areValuesEqual:n,isDefined:r}=e;let s,a,o;switch(e.schema.valueType){case"float":case"int":s=t=>""+e.value(t),a=e.value,o=e.value;break;case"str":s=e.value,a=t=>{const i=e.value(t);return ib(i,0,i.length)||0},o=t=>{const i=e.value(t);return rb(i,0,i.length)||0};break;case"list":const{separator:t}=e.schema;s=i=>e.value(i).join(t),a=e=>NaN,o=e=>NaN;break;default:throw new Error(`unsupported valueType '${e.schema.valueType}'`)}return{__array:void 0,binaryEncoding:void 0,isDefined:r,rowCount:t,str:s,int:a,float:o,valueKind:i,areValuesEqual:n,toStringArray:e=>kv(t,s,e),toIntArray:e=>kv(t,a,e),toFloatArray:e=>kv(t,o,e)}}e.ofString=function(e){return t([e])},e.ofStrings=t,e.ofNumbers=function(e){const t=e.length,i=t=>""+e[t],n=t=>e[t],r=i=>!i||i.array&&e instanceof i.array?e:kv(t,n,i);return{__array:void 0,binaryEncoding:void 0,isDefined:!0,rowCount:t,str:i,int:n,float:n,valueKind:e=>0,areValuesEqual:(t,i)=>e[t]===e[i],toStringArray:e=>kv(t,i,e),toIntArray:r,toFloatArray:r}},e.ofTokens=function(e){const{data:t,indices:i,count:n}=e,r=e=>{const n=t.substring(i[2*e],i[2*e+1]);return"."===n||"?"===n?"":n},s=e=>ib(t,i[2*e],i[2*e+1])||0,a=e=>rb(t,i[2*e],i[2*e+1])||0;return{__array:void 0,binaryEncoding:void 0,isDefined:!0,rowCount:n,str:r,int:s,float:a,valueKind:e=>{const n=i[2*e],r=i[2*e+1]-n;if(r>1)return 0;if(0===r)return 1;const s=t.charCodeAt(n);return 46===s?1:63===s?2:0},areValuesEqual:Rb(e),toStringArray:e=>kv(n,r,e),toIntArray:e=>kv(n,s,e),toFloatArray:e=>kv(n,a,e)}},e.ofColumn=i,e.ofUndefined=function(e,t){return i(Jv.Undefined(e,t))}}(Db||(Db={}));const Nb="undefined"!=typeof setImmediate?"undefined"!=typeof window?{setImmediate:(e,...t)=>window.setImmediate(e,...t),clearImmediate:e=>window.clearImmediate(e)}:{setImmediate:setImmediate,clearImmediate:clearImmediate}:function(){const e=function(){const e="undefined"!=typeof window&&window,t="undefined"!=typeof self&&"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&self,i="undefined"!=typeof global&&global;return e||i||t}(),t={},i="undefined"!=typeof document?document:void 0;let n,r=1;function s(e){delete t[e]}function a(e){const i=t[e];s(e),function(e){const t=e.callback,i=e.args;switch(i.length){case 0:t();break;case 1:t(i[0]);break;case 2:t(i[0],i[1]);break;case 3:t(i[0],i[1],i[2]);break;default:t.apply(void 0,i)}}(i)}return"undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?n=function(e){process.nextTick((function(){a(e)}))}:function(){if(e&&e.postMessage&&!e.importScripts){let t=!0;const i=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=i,t}}()?function(){const t="setImmediate$"+Math.random()+"$",i=function(i){i.source===e&&"string"==typeof i.data&&0===i.data.indexOf(t)&&a(+i.data.slice(t.length))};window.addEventListener?window.addEventListener("message",i,!1):window.attachEvent("onmessage",i),n=function(e){window.postMessage(t+e,"*")}}():"undefined"!=typeof MessageChannel?function(){const e=new MessageChannel;e.port1.onmessage=function(e){a(e.data)},n=function(t){e.port2.postMessage(t)}}():i&&"onreadystatechange"in i.createElement("script")?function(){const e=i.documentElement;n=function(t){let n=i.createElement("script");n.onreadystatechange=function(){a(t),n.onreadystatechange=null,e.removeChild(n),n=null},e.appendChild(n)}}():n=function(e){setTimeout(a,0,e)},{setImmediate:function(e,...i){"function"!=typeof e&&(e=new Function(""+e));const s={callback:e,args:i};return t[r]=s,n(r),r++},clearImmediate:s}}();function Fb(e){Nb.setImmediate(e)}const Bb={setImmediate:Nb.setImmediate,clearImmediate:Nb.clearImmediate,immediatePromise:()=>new Promise(Fb),delay:(e,t=void 0)=>new Promise((i=>setTimeout(i,e,t)))};!function(){try{return"production"===process.env.NODE_ENV}catch(e){return!1}}(),function(){try{const e=process.env.DEBUG;return"*"===e||"molstar"===e}catch(e){return!1}}();const zb="undefined"!=typeof performance&&!!performance.mark&&performance.measure&&!1;var Ub;function Vb(e,t,i=250){const n=function(e,t,i){const n={abortRequested:!1,treeAborted:!1,reason:""};return{updateRateMs:i,lastNotified:bb(),observer:t,abortToken:n,taskId:e.id,root:{progress:$b(e),children:[]},tryAbort:Gb(n)}}(e,t,i);return Wb(e,new Kb(n,n.root))}function $b(e){return{taskId:e.id,taskName:e.name,message:"",startedTime:0,canAbort:!0,isIndeterminate:!0,current:0,max:0}}function Gb(e){return t=>{e.abortRequested=!0,e.reason=t||e.reason}}function Hb(e){return{progress:{...e.progress},children:e.children.map(Hb)}}function jb(e){return e.progress.canAbort&&e.children.every(jb)}async function Wb(e,t){Ub.markStart(e),t.node.progress.startedTime=bb();try{const i=await e.f(t);return Ub.markEnd(e),Ub.measure(e),t.info.abortToken.abortRequested&&qb(t.info),i}catch(i){throw Qb.isAbort(i)&&(t.isAborted=!0,t.node.children.length>0&&await new Promise((e=>{t.onChildrenFinished=e})),e.onAbort&&e.onAbort()),i}}function qb(e){throw e.abortToken.treeAborted||(e.abortToken.treeAborted=!0,Xb(e.root),Yb(e,bb())),Qb.Aborted(e.abortToken.reason)}function Xb(e){const t=e.progress;t.isIndeterminate=!0,t.canAbort=!1,t.message="Aborting...";for(const t of e.children)Xb(t)}function Yb(e,t){e.lastNotified=t;const i=function(e){return{root:Hb(e.root),canAbort:jb(e.root),requestAbort:e.tryAbort}}(e);e.observer(i)}!function(e){function t(e){return`startTask${e.id}`}function i(e){return`endTask${e.id}`}e.markStart=function(e){zb&&performance.mark(t(e))},e.markEnd=function(e){zb&&performance.mark(i(e))},e.measure=function(e){zb&&performance.measure(`✳️ ${e.name}`,t(e),i(e))}}(Ub||(Ub={}));class Kb{checkAborted(){this.info.abortToken.abortRequested&&(this.isAborted=!0,qb(this.info))}get shouldUpdate(){return this.checkAborted(),bb()-this.lastUpdatedTime>this.info.updateRateMs}updateProgress(e){if(this.checkAborted(),!e)return;const t=this.node.progress;"string"==typeof e?(t.message=e,t.isIndeterminate=!0):(void 0!==e.canAbort&&(t.canAbort=e.canAbort),void 0!==e.message&&(t.message=e.message),void 0!==e.current&&(t.current=e.current),void 0!==e.max&&(t.max=e.max),t.isIndeterminate=void 0===t.current||void 0===t.max,void 0!==e.isIndeterminate&&(t.isIndeterminate=e.isIndeterminate))}update(e,t){if(this.lastUpdatedTime=bb(),this.updateProgress(e),!t)return Yb(this.info,this.lastUpdatedTime),this.checkAborted(),Bb.immediatePromise()}async runChild(e,t){this.updateProgress(t);const i={progress:$b(e),children:[]},n=this.node.children;n.push(i);const r=new Kb(this.info,i);try{return await Wb(e,r)}catch(e){if(Qb.isAbort(e)&&this.isAborted)return;throw e}finally{const e=n.indexOf(i);if(e>=0){for(let t=e,i=n.length-1;t0;){a+=c;const t=bb()-l;u+=t,o+=t,e.shouldUpdate&&(await r(e,i,a),s=Math.round(u*a/o)+1,l=bb(),u=0)}return e.shouldUpdate&&await r(e,i,a),i}function sx(e){return{data:e,position:0,length:e.length,lineNumber:1,tokenStart:0,tokenEnd:0}}function ax(e){for(;e.position=e.length)return void(e.tokenType=6);e.tokenStart=e.position,e.tokenEnd=e.position,e.isEscaped=!1;const i=e.data.charCodeAt(e.position);switch(i){case 35:!function(e){for(;e.position=5&&95===e.data.charCodeAt(e.tokenStart+4)?!function(e){let t=e.data.charCodeAt(e.tokenStart);return!(68!==t&&100!==t||(t=e.data.charCodeAt(e.tokenStart+1),65!==t&&97!==t||(t=e.data.charCodeAt(e.tokenStart+2),84!==t&&116!==t||(t=e.data.charCodeAt(e.tokenStart+3),65!==t&&97!==t))))}(e)?!function(e){let t=e.data.charCodeAt(e.tokenStart);return!(83!==t&&115!==t||(t=e.data.charCodeAt(e.tokenStart+1),65!==t&&97!==t||(t=e.data.charCodeAt(e.tokenStart+2),86!==t&&118!==t||(t=e.data.charCodeAt(e.tokenStart+3),69!==t&&101!==t))))}(e)?!function(e){if(e.tokenEnd-e.tokenStart!=5)return!1;let t=e.data.charCodeAt(e.tokenStart);return!(76!==t&&108!==t||(t=e.data.charCodeAt(e.tokenStart+1),79!==t&&111!==t||(t=e.data.charCodeAt(e.tokenStart+2),79!==t&&111!==t||(t=e.data.charCodeAt(e.tokenStart+3),80!==t&&112!==t))))}(e)?e.tokenType=3:e.tokenType=2:e.tokenType=1:e.tokenType=0:e.tokenType=3}}function fx(e){for(dx(e);5===e.tokenType;)dx(e)}function mx(){return{categoryNames:[],categoryData:Object.create(null)}}function px(e,t){const i=Object.create(null);for(const n of e){const e=t[n];i[n]=Ob(e.name,e.rowCount,e.fieldNames,e.fields)}return i}function gx(e,t,i){return kb(e.categoryNames,px(e.categoryNames,e.categoryData),t,i)}function _x(e,t){return kb(e.categoryNames,px(e.categoryNames,e.categoryData),t)}function yx(e,t,i,n,r){if(t in e.categoryData){const i=e.categoryData[t];i.fieldNames.push(...n),Object.assign(i.fields,r)}else e.categoryData[t]={name:t,rowCount:i,fieldNames:n,fields:r},e.categoryNames.push(t)}function vx(e,t){const i=e.tokenStart,n=cx(e),r=ux(e,n),s=Object.create(null),a=[];let o=!0;for(;o;){if(4!==e.tokenType||!lx(e,i,n)){o=!1;break}const t=hx(e).substring(r.length+1);if(fx(e),3!==e.tokenType)return{hasError:!0,errorLine:e.lineNumber,errorMessage:"Expected value."};s[t]=Db.ofTokens({data:e.data,indices:[e.tokenStart,e.tokenEnd],count:1}),a[a.length]=t,fx(e)}return yx(t,r.substr(1),1,a,s),{hasError:!1,errorLine:0,errorMessage:""}}function bx(e,t){const{tokenizer:i,tokens:n,fieldCount:r}=t;let s=t.tokenCount,a=0;for(;3===i.tokenType&&a0&&i.push(gx(s,r,a)),r=e.substring(n.tokenStart+5,n.tokenEnd),s=mx(),a=[],fx(n)}else if(1===t){if(n.tokenEnd-n.tokenStart==5)o.categoryNames.length>0&&(a[a.length]=_x(o,c)),n.inSaveFrame=!1;else{if(n.inSaveFrame)return Sx(n.lineNumber,"Save frames cannot be nested.");n.inSaveFrame=!0,c=e.substring(n.tokenStart+5,n.tokenEnd),o=mx()}fx(n)}else if(2===t){const e=await wx(n,n.inSaveFrame?o:s);if(e.hasError)return Sx(e.errorLine,e.errorMessage)}else{if(4!==t)return console.log(n.tokenType,sx.getTokenString(n)),Sx(n.lineNumber,"Unexpected token. Expected data_, loop_, or data name.");{const e=vx(n,n.inSaveFrame?o:s);if(e.hasError)return Sx(e.errorLine,e.errorMessage)}}}return n.inSaveFrame?Sx(n.lineNumber,`Unfinished save frame (${l.header}).`):((s.categoryNames.length>0||a.length>0)&&i.push(gx(s,r,a)),function(e){return ix.success(e)}(Lb(i)))}function Ax(e){return Qb.create("Parse CIF",(async t=>await Mx(e,t)))}!function(e){class t{run(e,t=250){return e?Vb(this,e,t):this.f(Zb)}runAsChild(e,t){return e.isSynchronous?this.f(Zb):function(e,t,i){return e.runChild(t,i)}(e,this,t)}runInContext(e){return e.isSynchronous?this.f(Zb):function(e,t){return Wb(t,e)}(e,this)}constructor(e,t,i){this.name=e,this.f=t,this.onAbort=i,this.id=r()}}function i(e){const t=e;return!!e&&"number"==typeof t.id&&"string"==typeof t.name&&!!t.run}function n(e,i,n){return new t(e,i,n)}e.is=i,e.isAbort=function(e){return!!e&&!!e.isAborted},e.Aborted=function(e){return{isAborted:!0,reason:e,toString:()=>"Aborted"+(e?": "+e:"")}},e.create=n,e.constant=function(e,t){return n(e,(async e=>t))},e.empty=function(){return n("",(async e=>{}))},e.fail=function(e,t){return n(e,(async e=>{throw new Error(t)}))},e.resolveInContext=function(e,t){return i(e)?t?e.runInContext(t):e.run():e};const r=Ab(0,1073741823)}(Qb||(Qb={})),function(e){e.Synchronous=Zb}(Jb||(Jb={})),function(e){function t(e,i=""){const n=e.progress;if(!e.children.length)return n.isIndeterminate?`${i}${n.taskName}: ${n.message}`:`${i}${n.taskName}: [${n.current}/${n.max}] ${n.message}`;const r=i+" |_ ",s=e.children.map((e=>t(e,r)));return n.isIndeterminate?`${i}${n.taskName}: ${n.message}\n${s.join("\n")}`:`${i}${n.taskName}: [${n.current}/${n.max}] ${n.message}\n${s.join("\n")}`}e.format=function(e){return t(e.root)}}(ex||(ex={})),function(e){function t(e){return e.data.substring(e.tokenStart,e.tokenEnd)}function i(e){const{data:t}=e;for(;e.position=r;)a=n.charCodeAt(--s);return e.tokenStart=r,e.tokenEnd=s+1,e.position=i,e}e.getTokenString=t,e.reset=function(e){e.position=0,e.lineNumber=1,e.tokenStart=0,e.tokenEnd=0},e.eatLine=i,e.markStart=function(e){e.tokenStart=e.position},e.markLine=n,e.readLine=function(e){return n(e),t(e)},e.readLineTrim=function(e){n(e);const i=e.position;return s(e,e.tokenStart,e.tokenEnd),e.position=i,t(e)},e.markLines=function(e,t){const i=tx.create(e.data,2*t);return r(e,t,i),i},e.readLines=function(t,i){const n=[];for(let r=0;r{const n=Math.min(t-a,e);return r(i,n,s),a+=n,n}),((e,t)=>e.update({message:"Parsing...",current:t.position,max:t.length}))),s},e.readAllLines=function(t){const i=e(t),r=tx.create(i.data,Math.max(t.length/80,2));for(;n(i);)tx.add(r,i.tokenStart,i.tokenEnd);return r},e.readAllLinesAsync=async function(t,i,r=1e5){const s=e(t),a=tx.create(s.data,Math.max(t.length/80,2));return await rx(i,r,s,((e,t)=>(function(e,t,i){let r=0;for(let s=0;se.update({message:"Parsing...",current:t.position,max:t.length}))),a},e.eatValue=function(e){for(;e.positionn.indicesLenMinus2&&function(e){const t=new Uint32Array(1.61*e.indices.length|0);t.set(e.indices),e.indices=t,e.indicesLenMinus2=t.length-2|0}(n),n.indices[n.offset++]=t,n.indices[n.offset++]=i,e.count++}e.add=t,e.addToken=function(e,i){t(e,i.tokenStart,i.tokenEnd)},e.addUnchecked=function(e,t,i){e.indices[e.offset++]=t,e.indices[e.offset++]=i,e.count++},e.create=function(e,t){return{data:e,indicesLenMinus2:(t=Math.max(10,t))-2|0,count:0,offset:0,indices:new Uint32Array(t)}}}(tx||(tx={})),function(e){e.error=function(e,i=-1){return new t(e,i)},e.success=function(e,t=[]){return new i(e,t)};class t{toString(){return this.line>=0?`[Line ${this.line}] ${this.message}`:this.message}constructor(e,t){this.message=e,this.line=t,this.isError=!0}}e.Error=t;class i{constructor(e,t){this.result=e,this.warnings=t,this.isError=!1}}e.Success=i}(ix||(ix={})),function(e){var t,i;(t=e.IntDataType||(e.IntDataType={}))[t.Int8=1]="Int8",t[t.Int16=2]="Int16",t[t.Int32=3]="Int32",t[t.Uint8=4]="Uint8",t[t.Uint16=5]="Uint16",t[t.Uint32=6]="Uint32",(i=e.FloatDataType||(e.FloatDataType={}))[i.Float32=32]="Float32",i[i.Float64=33]="Float64",e.getDataType=function(t){let i;return i=t instanceof Int8Array?e.IntDataType.Int8:t instanceof Int16Array?e.IntDataType.Int16:t instanceof Int32Array?e.IntDataType.Int32:t instanceof Uint8Array?e.IntDataType.Uint8:t instanceof Uint16Array?e.IntDataType.Uint16:t instanceof Uint32Array?e.IntDataType.Uint32:t instanceof Float32Array?e.FloatDataType.Float32:t instanceof Float64Array?e.FloatDataType.Float64:e.IntDataType.Int32,i},e.isSignedIntegerDataType=function(e){if(e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array)return!0;for(let t=0,i=e.length;t=0;i--)t=Px(t,e.encoding[i]);return t}function Px(e,t){switch(t.kind){case"ByteArray":switch(t.type){case nx.IntDataType.Uint8:return e;case nx.IntDataType.Int8:return function(e){return new Int8Array(e.buffer,e.byteOffset)}(e);case nx.IntDataType.Int16:return function(e){return Dx(e,2,Int16Array)}(e);case nx.IntDataType.Uint16:return function(e){return Dx(e,2,Uint16Array)}(e);case nx.IntDataType.Int32:return function(e){return Dx(e,4,Int32Array)}(e);case nx.IntDataType.Uint32:return function(e){return Dx(e,4,Uint32Array)}(e);case nx.FloatDataType.Float32:return function(e){return Dx(e,4,Float32Array)}(e);case nx.FloatDataType.Float64:return function(e){return Dx(e,8,Float64Array)}(e);default:Kv(t.type)}case"FixedPoint":return function(e,t){const i=e.length,n=Ix(t.srcType,i),r=1/t.factor;for(let t=0;t=e.currentSize)a.set(l,o);else for(let e=0,t=l.length;e=e.currentSize&&t(e);const a=e.currentChunk,o=e.currentIndex;return a[o]=i,a[o+1]=n,a[o+2]=r,a[o+3]=s,e.currentIndex+=4,e.elementCount++},e.add3=function(e,i,n,r){e.currentIndex>=e.currentSize&&t(e);const s=e.currentChunk,a=e.currentIndex;return s[a]=i,s[a+1]=n,s[a+2]=r,e.currentIndex+=3,e.elementCount++},e.add2=function(e,i,n){e.currentIndex>=e.currentSize&&t(e);const r=e.currentChunk,s=e.currentIndex;return r[s]=i,r[s+1]=n,e.currentIndex+=2,e.elementCount++},e.add=function(e,i){return e.currentIndex>=e.currentSize&&t(e),e.currentChunk[e.currentIndex]=i,e.currentIndex+=1,e.elementCount++},e.addRepeat=function(e,i,n){for(let r=0;r=e.currentSize&&t(e),e.currentChunk[e.currentIndex++]=n,e.elementCount++;return e.elementCount},e.addMany=function(e,i){const{elementSize:n}=e;for(let r=0,s=i.length;r=e.currentSize&&t(e);const{currentChunk:s}=e;for(let t=0;t=0?Math.ceil((e+1)/t):Math.ceil((e+1)/(-t-1))}function i({limit8:e,limit16:i},n,r){n.pack8+=t(r,e),n.pack16+=t(r,i),n.count+=1}function n(e,i){e.pack8+=t(i,127),e.pack16+=t(i,32767),e.count+=1}function r(e){return 4*e.count<2*e.pack16?{length:4*e.count,elem:4}:2*e.pack16e.length-t.length)),i}e.getSize=c,e.classify=function(e){if(e.length<2)return Nx.by(Nx.byteArray);switch(c(e)[0].kind){case"pack":return Nx.by(Nx.integerPacking);case"rle":return Nx.by(Nx.runLength).and(Nx.integerPacking);case"delta":return Nx.by(Nx.delta).and(Nx.integerPacking);case"delta-rle":return Nx.by(Nx.delta).and(Nx.runLength).and(Nx.integerPacking);default:Kv()}}}(Lx||(Lx={})),function(e){e.classify=function(e){const{mantissaDigits:t,integerDigits:i}=function(e,t,i){let n=1,r=0;for(let s=0,a=e.length;s=0){const r=Fx(e[s],t,i);r<0?n=-1:r>n&&(n=r)}const a=Math.abs(e[s]);if(a>i){const e=Math.floor(Math.log10(Math.abs(a)))+1;e>r&&(r=e)}}return{mantissaDigits:n,integerDigits:r}}(e,4,1e-6);if(t<0||t+i>10)return Nx.by(Nx.byteArray);if(0===t)return Lx.classify(e);const n=function(e){let t=1;for(let i=0;i=0?s/t|0:s/i|0}return n+=e.length,n}e.byteArray=n,e.fixedPoint=function(e){return t=>function(e,t){const i=nx.getDataType(e),n=new Int32Array(e.length);for(let i=0,r=e.length;ifunction(e,t,i,n,r){const s=nx.getDataType(e);if(!e.length)return{encodings:[{kind:"IntervalQuantization",min:t,max:i,numSteps:n,srcType:s}],data:new Int32Array(0)};if(i=i?n-1:0|Math.round((s-t)/a)}return{encodings:[{kind:"IntervalQuantization",min:t,max:i,numSteps:n,srcType:s}],data:o}}(r,e,t,i,n)},e.runLength=function(e){let t=nx.getDataType(e);if(void 0===t&&(e=new Int32Array(e),t=nx.IntDataType.Int32),!e.length)return{encodings:[{kind:"RunLength",srcType:t,srcSize:0}],data:new Int32Array(0)};let i=2;for(let t=1,n=e.length;t=0)for(;n>=i;)a[o]=i,++o,n-=i;else for(;n<=r;)a[o]=r,++o,n-=r;a[o]=n,++o}const l=n(a);return{encodings:[{kind:"IntegerPacking",byteCount:t.bytesPerElement,isUnsigned:!t.isSigned,srcSize:s},l.encodings[0]],data:l.data}}(e,t)},e.stringArray=function(e){const t=Object.create(null),i=[],n=new Int32Array(e.length),r=Rx.create(Int32Array,1,Math.min(1024,e.length<32?e.length+1:Math.round(e.length/8)+1));Rx.add(r,0);let s=0,a=0;for(const o of e){if(null==o){n[a++]=-1;continue}let e=t[o];void 0===e&&(s+=o.length,e=i.length,i[e]=o,t[o]=e,Rx.add(r,s)),n[a++]=e}const o=Rx.compact(r),l=Bx(o).encode(o),c=Bx(n).encode(n);return{encodings:[{kind:"StringArray",dataEncoding:c.encoding,stringData:i.join(""),offsetEncoding:l.encoding,offsets:l.data}],data:c.data}}}(Nx||(Nx={}));const Ux=function(){const e=[];for(let t=0;t<1024;t++)e[t]=String.fromCharCode(t);return e}();function Vx(e){throw new Error(e)}const $x="undefined"!=typeof TextDecoder?new TextDecoder:void 0;function Gx(e,t,i){if($x){const n=t||i!==e.length?e.subarray(t,t+i):e;return $x.decode(n)}return function(e,t,i){const n=Ux;let r,s=0;const a=[];for(let o=t,l=t+i;o0&&(r[r.length]=a.slice(0,s).join("")),r.join("")):a.slice(0,s).join("")}(e,t,i)}function Hx(e,t){const i={};for(let n=0;ne.name)),getField(e){const n=t[e];if(n)return i[e]||(i[e]=function(e){const t=e.mask?Tx(e.mask):void 0,i=Tx(e.data),n=Ov(i),r=n?t?e=>0===t[e]?""+i[e]:"":e=>""+i[e]:t?e=>0===t[e]?i[e]:"":e=>i[e],s=n?e=>i[e]:e=>{const t=i[e];return ib(t,0,t.length)},a=n?e=>i[e]:e=>{const t=i[e];return rb(t,0,t.length)},o=t?e=>t[e]:e=>0,l=i.length;return{__array:i,binaryEncoding:e.data.encoding,isDefined:!0,rowCount:l,str:r,int:s,float:a,valueKind:o,areValuesEqual:(e,t)=>i[e]===i[t],toStringArray:e=>kv(l,r,e),toIntArray:n?e=>Nv(i,e):e=>kv(l,s,e),toFloatArray:n?e=>Nv(i,e):e=>kv(l,a,e)}}(n)),i[e]}}}function Kx(e){return Qb.create("Parse BinaryCIF",(async t=>{const i=[0,3];try{const t=Xx({buffer:n=e,offset:0,dataView:new DataView(n.buffer)});if(!function(e,t){for(let i=0;i<2;i++)if(e[i]>t[i])return!1;return!0}(i,t.version.match(/(\d)\.(\d)\.\d/).slice(1).map((e=>+e))))return ix.error(`Unsupported format version. Current ${t.version}, required ${i.join(".")}.`);const r=Lb(t.dataBlocks.map((e=>{const t=Object.create(null);for(const i of e.categories)t[i.name.substr(1)]=Yx(i);return kb(e.categories.map((e=>e.name.substr(1))),t,e.header)})));return ix.success(r)}catch(e){return ix.error(""+e)}var n}))}var Zx;function Qx(e,t,i){return function(e,t,i){const n=Object.create(null);for(const r of Object.keys(e))n[r]=sw(r,e[r],t,i);return Ib.ofTables(t.header,e,n)}(e,t,i)}function Jx(e){switch(e.valueType){case"str":return(t,i,n)=>function(e,t,i,n){return{schema:e,__array:t.__array,isDefined:t.isDefined,rowCount:t.rowCount,value:"lowercase"===e.transform?e=>i(e).toLowerCase():"uppercase"===e.transform?e=>i(e).toUpperCase():i,valueKind:t.valueKind,areValuesEqual:t.areValuesEqual,toArray:"lowercase"===e.transform?e=>Array.from(n(e)).map((e=>e.toLowerCase())):"uppercase"===e.transform?e=>Array.from(n(e)).map((e=>e.toUpperCase())):n}}(e,t,t.str,t.toStringArray);case"int":return(t,i,n)=>ew(e,t,t.int,t.toIntArray);case"float":return(t,i,n)=>ew(e,t,t.float,t.toFloatArray);case"list":throw new Error("Use createListColumn instead.");case"tensor":throw new Error("Use createTensorColumn instead.")}}function ew(e,t,i,n){return{schema:e,__array:t.__array,isDefined:t.isDefined,rowCount:t.rowCount,value:i,valueKind:t.valueKind,areValuesEqual:t.areValuesEqual,toArray:n}}function tw(e,t,i){const n=e.separator,r=e.itemParse,s=t.getField(i),a=s?e=>s.str(e).split(n).map((e=>r(e.trim()))).filter((e=>!!e)):e=>[];return{schema:e,__array:void 0,isDefined:!!s,rowCount:t.rowCount,value:a,valueKind:s?s.valueKind:()=>1,areValuesEqual:(e,t)=>function(e,t){const i=e.length;if(i!==t.length)return!1;for(let n=0;nkv(t.rowCount,a,e)}}function iw(e,t,i){const n=e.space,r=t.fieldNames.includes(`${i}[0]`)||t.fieldNames.includes(`${i}[0][0]`)||t.fieldNames.includes(`${i}[0][0][0]`),s=r?0:1,a=t.fieldNames.includes(`${i}_1`)||t.fieldNames.includes(`${i}_11`)||t.fieldNames.includes(`${i}_111`)?"underscore":"brackets",o=function(e,t,i,n){const r=i?0:1;switch(t){case 1:return"brackets"===n?t=>`${e}[${t+r}]`:t=>`${e}_${t+r}`;case 2:return"brackets"===n?(t,i)=>`${e}[${t+r}][${i+r}]`:(t,i)=>`${e}_${t+r}${i+r}`;case 3:return"brackets"===n?(t,i,n)=>`${e}[${t+r}][${i+r}][${n+r}]`:(t,i,n)=>`${e}_${t+r}${i+r}${n+r}`;default:throw new Error("Tensors with rank > 3 or rank 0 are currently not supported.")}}(i,n.rank,r,a),l=t.getField(o(s,s,s))||Jv.Undefined(t.rowCount,e),c=e=>function(e,t,i,n){const r=t.create();if(1===t.rank){const s=t.dimensions[0];for(let a=0;a 3 or rank 0 are currently not supported.");{const s=t.dimensions[0],a=t.dimensions[1],o=t.dimensions[2];for(let l=0;lQv.areEqualExact(c(e),c(t)),toArray:e=>kv(t.rowCount,c,e)}}!function(e){function t(e){return e.replace(".","_").replace(/\[/,"_").replace(/(\[|\])/g,"")}e.canonical=t,e.equal=function(e,i){return t(e)===t(i)},e.create=function(e,i,n=!1){const r=`${e}${i?`.${i}`:""}`;return n?t(r):r}}(Zx||(Zx={}));class nw{constructor(e,t,i){this._isDefined=i;const n=Object.keys(t);this._rowCount=e.rowCount,this._columns=n,this._schema=t;const r=Object.create(null);for(const i of n)Object.defineProperty(this,i,{get:function(){if(r[i])return r[i];const n=t[i];if("list"===n.valueType)r[i]=tw(n,e,i);else if("tensor"===n.valueType)r[i]=iw(n,e,i);else{const t=Jx(n),s=e.getField(i);r[i]=s?t(s,e,i):Jv.Undefined(e.rowCount,n)}return r[i]},enumerable:!0,configurable:!1})}}function rw(e,t,i,n){const r=Zx.create(t,e),s=Zx.canonical(r);if(s in i)return i[s];if(n&&r in n)for(const e of n[r]){const t=Zx.canonical(e);if(t in i)return i[t]}}function sw(e,t,i,n){let r=i.categories[e];if(n){const s=function(e){const t=Object.create(null);for(const i of Object.keys(e.categories))for(const n of e.categories[i].fieldNames)t[Zx.create(i,n,!0)]=e.categories[i].getField(n);return t}(i),a=Object.create(null),o=[];let l=0;for(const i of Object.keys(t)){const t=rw(i,e,s,n);t&&(a[i]=t,o.push(i),l=t.rowCount)}r={rowCount:l,name:e,fieldNames:[...o],getField:e=>a[e]}}return new nw(r||Ob.empty(e),t,!!r)}var aw=Jv.Schema;const ow=aw.str,lw=aw.int,cw=aw.float,uw=aw.coord,hw=aw.Aliased,dw=aw.Matrix,fw=aw.Vector,mw=aw.lstr,pw=aw.List,gw={atom_site:{auth_asym_id:ow,auth_atom_id:ow,auth_comp_id:ow,auth_seq_id:lw,B_iso_or_equiv:cw,Cartn_x:uw,Cartn_y:uw,Cartn_z:uw,group_PDB:hw(ow),id:lw,label_alt_id:ow,label_asym_id:ow,label_atom_id:ow,label_comp_id:ow,label_entity_id:ow,label_seq_id:lw,occupancy:cw,type_symbol:ow,pdbx_PDB_ins_code:ow,pdbx_PDB_model_num:lw,pdbx_formal_charge:lw,pdbx_label_index:lw,pdbx_sifts_xref_db_name:ow,pdbx_sifts_xref_db_acc:ow,pdbx_sifts_xref_db_num:ow,pdbx_sifts_xref_db_res:ow,ihm_model_id:lw},atom_site_anisotrop:{id:lw,type_symbol:ow,U:dw(3,3),U_esd:dw(3,3),pdbx_auth_seq_id:ow,pdbx_auth_asym_id:ow,pdbx_auth_atom_id:ow,pdbx_auth_comp_id:ow,pdbx_label_seq_id:lw,pdbx_label_alt_id:ow,pdbx_label_asym_id:ow,pdbx_label_atom_id:ow,pdbx_label_comp_id:ow,pdbx_PDB_ins_code:ow},atom_sites:{entry_id:ow,fract_transf_matrix:dw(3,3),fract_transf_vector:fw(3)},audit_author:{name:ow,pdbx_ordinal:lw,identifier_ORCID:ow},audit_conform:{dict_location:ow,dict_name:ow,dict_version:ow},cell:{angle_alpha:cw,angle_beta:cw,angle_gamma:cw,entry_id:ow,length_a:cw,length_b:cw,length_c:cw,Z_PDB:lw,pdbx_unique_axis:ow},chem_comp:{formula:ow,formula_weight:cw,id:ow,mon_nstd_flag:hw(mw),name:ow,type:hw(mw),pdbx_synonyms:pw(";",(e=>e))},chem_comp_bond:{atom_id_1:ow,atom_id_2:ow,comp_id:ow,value_order:hw(mw),pdbx_ordinal:lw,pdbx_stereo_config:hw(mw),pdbx_aromatic_flag:hw(mw)},citation:{book_publisher:ow,country:ow,id:ow,journal_abbrev:ow,journal_id_ASTM:ow,journal_id_CSD:ow,journal_id_ISSN:ow,journal_volume:ow,page_first:ow,page_last:ow,title:ow,year:lw,pdbx_database_id_DOI:ow,pdbx_database_id_PubMed:lw},citation_author:{citation_id:ow,name:ow,ordinal:lw},database_2:{database_id:hw(mw),database_code:ow},entity:{details:ow,formula_weight:cw,id:ow,src_method:hw(mw),type:hw(mw),pdbx_description:pw(",",(e=>e)),pdbx_number_of_molecules:lw,pdbx_mutation:ow,pdbx_fragment:ow,pdbx_ec:pw(",",(e=>e))},entity_poly:{entity_id:ow,nstd_linkage:hw(mw),nstd_monomer:hw(mw),type:hw(ow),pdbx_strand_id:pw(",",(e=>e)),pdbx_seq_one_letter_code:ow,pdbx_seq_one_letter_code_can:ow,pdbx_target_identifier:ow},entity_poly_seq:{entity_id:ow,hetero:hw(mw),mon_id:ow,num:lw},entry:{id:ow},exptl:{entry_id:ow,method:hw(ow)},software:{classification:ow,date:ow,description:ow,name:ow,type:hw(mw),version:ow,pdbx_ordinal:lw},struct:{entry_id:ow,title:ow,pdbx_descriptor:ow},struct_asym:{details:ow,entity_id:ow,id:ow,pdbx_modified:ow,pdbx_blank_PDB_chainid_flag:hw(ow)},struct_conf:{beg_label_asym_id:ow,beg_label_comp_id:ow,beg_label_seq_id:lw,beg_auth_asym_id:ow,beg_auth_comp_id:ow,beg_auth_seq_id:lw,conf_type_id:hw(mw),details:ow,end_label_asym_id:ow,end_label_comp_id:ow,end_label_seq_id:lw,end_auth_asym_id:ow,end_auth_comp_id:ow,end_auth_seq_id:lw,id:ow,pdbx_beg_PDB_ins_code:ow,pdbx_end_PDB_ins_code:ow,pdbx_PDB_helix_class:ow,pdbx_PDB_helix_length:lw,pdbx_PDB_helix_id:ow},struct_conn:{conn_type_id:hw(mw),details:ow,id:ow,ptnr1_label_asym_id:ow,ptnr1_label_atom_id:ow,ptnr1_label_comp_id:ow,ptnr1_label_seq_id:lw,ptnr1_auth_asym_id:ow,ptnr1_auth_comp_id:ow,ptnr1_auth_seq_id:lw,ptnr1_symmetry:ow,ptnr2_label_asym_id:ow,ptnr2_label_atom_id:ow,ptnr2_label_comp_id:ow,ptnr2_label_seq_id:lw,ptnr2_auth_asym_id:ow,ptnr2_auth_comp_id:ow,ptnr2_auth_seq_id:lw,ptnr2_symmetry:ow,pdbx_ptnr1_PDB_ins_code:ow,pdbx_ptnr1_label_alt_id:ow,pdbx_ptnr1_standard_comp_id:ow,pdbx_ptnr2_PDB_ins_code:ow,pdbx_ptnr2_label_alt_id:ow,pdbx_ptnr3_PDB_ins_code:ow,pdbx_ptnr3_label_alt_id:ow,pdbx_ptnr3_label_asym_id:ow,pdbx_ptnr3_label_atom_id:ow,pdbx_ptnr3_label_comp_id:ow,pdbx_ptnr3_label_seq_id:lw,pdbx_PDB_id:ow,pdbx_dist_value:cw,pdbx_value_order:hw(mw)},struct_conn_type:{criteria:ow,id:hw(mw),reference:ow},struct_keywords:{entry_id:ow,text:pw(",",(e=>e)),pdbx_keywords:ow},struct_ncs_oper:{code:hw(ow),details:ow,id:lw,matrix:dw(3,3),vector:fw(3)},struct_sheet_range:{beg_label_asym_id:ow,beg_label_comp_id:ow,beg_label_seq_id:lw,end_label_asym_id:ow,end_label_comp_id:ow,end_label_seq_id:lw,beg_auth_asym_id:ow,beg_auth_comp_id:ow,beg_auth_seq_id:lw,end_auth_asym_id:ow,end_auth_comp_id:ow,end_auth_seq_id:lw,id:ow,sheet_id:ow,pdbx_beg_PDB_ins_code:ow,pdbx_end_PDB_ins_code:ow},struct_site:{details:ow,id:ow,pdbx_num_residues:lw,pdbx_evidence_code:ow,pdbx_auth_asym_id:ow,pdbx_auth_comp_id:ow,pdbx_auth_seq_id:ow,pdbx_auth_ins_code:ow},struct_site_gen:{details:ow,id:ow,label_alt_id:ow,label_asym_id:ow,label_atom_id:ow,label_comp_id:ow,label_seq_id:lw,auth_asym_id:ow,auth_comp_id:ow,auth_seq_id:ow,site_id:ow,symmetry:ow,pdbx_auth_ins_code:ow,pdbx_num_res:lw},symmetry:{entry_id:ow,cell_setting:hw(mw),Int_Tables_number:lw,space_group_name_Hall:ow,"space_group_name_H-M":ow},pdbx_database_status:{status_code:hw(ow),status_code_sf:hw(ow),status_code_mr:hw(ow),entry_id:ow,recvd_initial_deposition_date:ow,SG_entry:hw(mw),deposit_site:hw(ow),process_site:hw(ow),status_code_cs:hw(ow),methods_development_category:hw(ow),pdb_format_compatible:hw(mw)},pdbx_nonpoly_scheme:{asym_id:ow,entity_id:ow,mon_id:ow,pdb_strand_id:ow,ndb_seq_num:ow,pdb_seq_num:ow,auth_seq_num:ow,pdb_mon_id:ow,auth_mon_id:ow,pdb_ins_code:ow},pdbx_database_related:{db_name:ow,details:ow,db_id:ow,content_type:hw(ow)},pdbx_entity_nonpoly:{entity_id:ow,comp_id:ow,name:ow},pdbx_chem_comp_synonyms:{name:ow,comp_id:ow,provenance:hw(ow)},pdbx_chem_comp_identifier:{comp_id:ow,identifier:ow,type:hw(ow),program:ow,program_version:ow},pdbx_unobs_or_zero_occ_residues:{id:lw,polymer_flag:hw(mw),occupancy_flag:hw(lw),PDB_model_num:lw,auth_asym_id:ow,auth_comp_id:ow,auth_seq_id:ow,PDB_ins_code:ow,label_asym_id:ow,label_comp_id:ow,label_seq_id:lw},pdbx_struct_mod_residue:{id:lw,auth_asym_id:ow,auth_comp_id:ow,auth_seq_id:lw,PDB_ins_code:ow,label_asym_id:ow,label_comp_id:ow,label_seq_id:lw,parent_comp_id:ow,details:ow},pdbx_struct_oper_list:{id:ow,type:hw(ow),name:ow,symmetry_operation:ow,matrix:dw(3,3),vector:fw(3)},pdbx_struct_assembly:{method_details:ow,oligomeric_details:ow,oligomeric_count:lw,details:ow,id:ow},pdbx_struct_assembly_gen:{asym_id_list:pw(",",(e=>e)),assembly_id:ow,oper_expression:ow},pdbx_reference_entity_list:{prd_id:ow,ref_entity_id:ow,type:hw(mw),details:ow,component_id:lw},pdbx_reference_entity_link:{link_id:lw,prd_id:ow,details:ow,ref_entity_id_1:ow,ref_entity_id_2:ow,entity_seq_num_1:lw,entity_seq_num_2:lw,comp_id_1:ow,comp_id_2:ow,atom_id_1:ow,atom_id_2:ow,value_order:hw(mw),component_1:lw,component_2:lw,link_class:hw(ow)},pdbx_reference_entity_poly_link:{link_id:lw,prd_id:ow,ref_entity_id:ow,component_id:lw,entity_seq_num_1:lw,entity_seq_num_2:lw,comp_id_1:ow,comp_id_2:ow,atom_id_1:ow,atom_id_2:ow,value_order:hw(mw)},pdbx_molecule:{prd_id:ow,instance_id:lw,asym_id:ow},pdbx_molecule_features:{prd_id:ow,class:hw(mw),type:hw(mw),name:ow,details:ow},entity_src_nat:{entity_id:ow,pdbx_organism_scientific:ow,pdbx_plasmid_name:ow,pdbx_src_id:lw,pdbx_beg_seq_num:lw,pdbx_end_seq_num:lw},entity_src_gen:{entity_id:ow,pdbx_gene_src_gene:pw(",",(e=>e)),pdbx_gene_src_scientific_name:ow,plasmid_name:ow,pdbx_src_id:lw,pdbx_beg_seq_num:lw,pdbx_end_seq_num:lw},pdbx_entity_src_syn:{organism_scientific:ow,entity_id:ow,pdbx_src_id:lw,pdbx_beg_seq_num:lw,pdbx_end_seq_num:lw},pdbx_entity_branch_descriptor:{entity_id:ow,descriptor:ow,type:hw(mw),program:ow,program_version:ow,ordinal:lw},pdbx_entity_instance_feature:{details:ow,feature_type:hw(ow),auth_asym_id:ow,asym_id:ow,auth_seq_num:ow,seq_num:lw,comp_id:ow,auth_comp_id:ow,ordinal:lw},pdbx_entity_branch_list:{entity_id:ow,hetero:hw(mw),comp_id:ow,num:lw},pdbx_entity_branch_link:{link_id:lw,details:ow,entity_id:ow,entity_branch_list_num_1:lw,entity_branch_list_num_2:lw,comp_id_1:ow,comp_id_2:ow,atom_id_1:ow,leaving_atom_id_1:ow,atom_stereo_config_1:hw(mw),atom_id_2:ow,leaving_atom_id_2:ow,atom_stereo_config_2:hw(mw),value_order:hw(mw)},pdbx_entity_branch:{entity_id:ow,type:hw(ow)},pdbx_branch_scheme:{entity_id:ow,hetero:hw(mw),asym_id:ow,mon_id:ow,num:lw,pdb_asym_id:ow,pdb_seq_num:ow,pdb_mon_id:ow,auth_asym_id:ow,auth_seq_num:ow,auth_mon_id:ow},pdbx_chem_comp_related:{comp_id:ow,related_comp_id:ow,relationship_type:hw(ow),details:ow},ihm_starting_model_details:{starting_model_id:ow,entity_id:ow,entity_description:ow,asym_id:ow,entity_poly_segment_id:lw,starting_model_source:hw(ow),starting_model_auth_asym_id:ow,starting_model_sequence_offset:lw,dataset_list_id:lw},ihm_starting_comparative_models:{id:lw,starting_model_id:ow,starting_model_auth_asym_id:ow,starting_model_seq_id_begin:lw,starting_model_seq_id_end:lw,template_auth_asym_id:ow,template_seq_id_begin:lw,template_seq_id_end:lw,template_sequence_identity:cw,template_sequence_identity_denominator:hw(lw),template_dataset_list_id:lw,alignment_file_id:lw},ihm_starting_model_seq_dif:{id:lw,entity_id:ow,asym_id:ow,seq_id:lw,comp_id:ow,starting_model_id:ow,db_asym_id:ow,db_seq_id:lw,db_comp_id:ow,details:ow},ihm_model_representation:{id:lw,name:ow,details:ow},ihm_model_representation_details:{id:lw,representation_id:lw,entity_poly_segment_id:lw,entity_id:ow,entity_description:ow,entity_asym_id:ow,model_object_primitive:hw(ow),starting_model_id:ow,model_mode:hw(ow),model_granularity:hw(ow),model_object_count:lw},ihm_struct_assembly_details:{id:lw,assembly_id:lw,parent_assembly_id:lw,entity_description:ow,entity_id:ow,asym_id:ow,entity_poly_segment_id:lw},ihm_struct_assembly:{id:lw,name:ow,description:ow},ihm_modeling_protocol:{id:lw,num_steps:lw,protocol_name:ow},ihm_modeling_protocol_details:{id:lw,protocol_id:lw,step_id:lw,struct_assembly_id:lw,dataset_group_id:lw,struct_assembly_description:ow,step_name:ow,step_method:ow,num_models_begin:lw,num_models_end:lw,multi_scale_flag:hw(mw),multi_state_flag:hw(mw),ordered_flag:hw(mw),script_file_id:lw,software_id:lw},ihm_multi_state_modeling:{state_id:lw,state_group_id:lw,population_fraction:cw,population_fraction_sd:cw,state_type:ow,state_name:ow,experiment_type:hw(ow),details:ow},ihm_modeling_post_process:{id:lw,protocol_id:lw,analysis_id:lw,step_id:lw,type:hw(ow),feature:hw(ow),num_models_begin:lw,num_models_end:lw},ihm_ensemble_info:{ensemble_id:lw,ensemble_name:ow,post_process_id:lw,model_group_id:lw,ensemble_clustering_method:hw(ow),ensemble_clustering_feature:hw(ow),num_ensemble_models:lw,num_ensemble_models_deposited:lw,ensemble_precision_value:cw,ensemble_file_id:lw},ihm_model_list:{model_id:lw,model_name:ow,assembly_id:lw,protocol_id:lw,representation_id:lw},ihm_model_group:{id:lw,name:ow,details:ow},ihm_model_group_link:{model_id:lw,group_id:lw},ihm_model_representative:{id:lw,model_group_id:lw,model_id:lw,selection_criteria:hw(ow)},ihm_dataset_list:{id:lw,data_type:hw(ow),database_hosted:hw(mw)},ihm_dataset_group:{id:lw,name:ow,application:hw(ow),details:ow},ihm_dataset_group_link:{dataset_list_id:lw,group_id:lw},ihm_related_datasets:{dataset_list_id_derived:lw,dataset_list_id_primary:lw},ihm_dataset_related_db_reference:{id:lw,dataset_list_id:lw,db_name:hw(ow),accession_code:ow,version:ow,details:ow},ihm_external_reference_info:{reference_id:lw,reference_provider:ow,reference_type:hw(ow),reference:ow,refers_to:hw(ow),associated_url:ow},ihm_external_files:{id:lw,reference_id:lw,file_path:ow,content_type:hw(ow),file_size_bytes:cw,details:ow},ihm_dataset_external_reference:{id:lw,dataset_list_id:lw,file_id:lw},ihm_localization_density_files:{id:lw,file_id:lw,ensemble_id:lw,entity_id:ow,entity_poly_segment_id:lw,asym_id:ow},ihm_predicted_contact_restraint:{id:lw,group_id:lw,entity_id_1:ow,entity_id_2:ow,asym_id_1:ow,asym_id_2:ow,comp_id_1:ow,comp_id_2:ow,seq_id_1:lw,seq_id_2:lw,rep_atom_1:hw(ow),rep_atom_2:hw(ow),distance_lower_limit:cw,distance_upper_limit:cw,probability:cw,restraint_type:hw(ow),model_granularity:hw(ow),dataset_list_id:lw,software_id:lw},ihm_cross_link_list:{id:lw,group_id:lw,entity_description_1:ow,entity_description_2:ow,entity_id_1:ow,entity_id_2:ow,comp_id_1:ow,comp_id_2:ow,seq_id_1:lw,seq_id_2:lw,linker_type:hw(ow),dataset_list_id:lw},ihm_cross_link_restraint:{id:lw,group_id:lw,entity_id_1:ow,entity_id_2:ow,asym_id_1:ow,asym_id_2:ow,comp_id_1:ow,comp_id_2:ow,seq_id_1:lw,seq_id_2:lw,atom_id_1:ow,atom_id_2:ow,restraint_type:hw(ow),conditional_crosslink_flag:hw(ow),model_granularity:hw(ow),distance_threshold:cw,psi:cw,sigma_1:cw,sigma_2:cw},ihm_cross_link_result_parameters:{id:lw,restraint_id:lw,model_id:lw,psi:cw,sigma_1:cw,sigma_2:cw},ihm_2dem_class_average_restraint:{id:lw,dataset_list_id:lw,number_raw_micrographs:lw,pixel_size_width:cw,pixel_size_height:cw,image_resolution:cw,image_segment_flag:hw(mw),number_of_projections:lw,struct_assembly_id:lw,details:ow},ihm_2dem_class_average_fitting:{id:lw,restraint_id:lw,model_id:lw,cross_correlation_coefficient:cw,rot_matrix:dw(3,3),tr_vector:fw(3)},ihm_3dem_restraint:{id:lw,dataset_list_id:lw,model_id:lw,struct_assembly_id:lw,fitting_method:ow,number_of_gaussians:lw,cross_correlation_coefficient:cw},ihm_sas_restraint:{id:lw,dataset_list_id:lw,model_id:lw,struct_assembly_id:lw,profile_segment_flag:hw(mw),fitting_atom_type:ow,fitting_method:ow,fitting_state:hw(ow),radius_of_gyration:cw,chi_value:cw,details:ow},ihm_starting_model_coord:{ordinal_id:lw,starting_model_id:ow,group_PDB:hw(ow),id:lw,type_symbol:ow,entity_id:ow,atom_id:ow,comp_id:ow,seq_id:lw,asym_id:ow,Cartn_x:cw,Cartn_y:cw,Cartn_z:cw,B_iso_or_equiv:cw},ihm_sphere_obj_site:{id:lw,entity_id:ow,seq_id_begin:lw,seq_id_end:lw,asym_id:ow,Cartn_x:cw,Cartn_y:cw,Cartn_z:cw,object_radius:cw,rmsf:cw,model_id:lw},ihm_gaussian_obj_site:{id:lw,entity_id:ow,seq_id_begin:lw,seq_id_end:lw,asym_id:ow,mean_Cartn_x:cw,mean_Cartn_y:cw,mean_Cartn_z:cw,weight:cw,covariance_matrix:dw(3,3),model_id:lw},ihm_gaussian_obj_ensemble:{id:lw,entity_id:ow,seq_id_begin:lw,seq_id_end:lw,asym_id:ow,mean_Cartn_x:cw,mean_Cartn_y:cw,mean_Cartn_z:cw,weight:cw,covariance_matrix:dw(3,3),ensemble_id:lw},ihm_feature_list:{feature_id:lw,feature_type:hw(ow),entity_type:hw(ow)},ihm_poly_residue_feature:{ordinal_id:lw,feature_id:lw,entity_id:ow,asym_id:ow,comp_id_begin:ow,comp_id_end:ow,seq_id_begin:lw,seq_id_end:lw},ihm_derived_distance_restraint:{id:lw,group_id:lw,feature_id_1:lw,feature_id_2:lw,group_conditionality:hw(ow),random_exclusion_fraction:cw,distance_upper_limit:cw,restraint_type:hw(ow),dataset_list_id:lw},ma_model_list:{ordinal_id:lw,model_id:lw,model_group_id:lw,model_name:ow,model_group_name:ow,model_type:hw(ow),data_id:lw},ma_target_entity:{entity_id:ow,data_id:lw,origin:hw(ow)},ma_target_entity_instance:{asym_id:ow,entity_id:ow,details:ow},ma_target_ref_db_details:{target_entity_id:ow,db_name:hw(ow),db_code:ow,db_accession:ow,seq_db_isoform:ow,seq_db_align_begin:ow,seq_db_align_end:ow,ncbi_taxonomy_id:ow,organism_scientific:ow},ma_data:{id:lw,content_type:hw(ow),content_type_other_details:ow,name:ow},ma_software_group:{ordinal_id:lw,group_id:lw,software_id:lw},ma_qa_metric:{id:lw,name:ow,type:hw(ow),mode:hw(ow),software_group_id:lw},ma_qa_metric_global:{ordinal_id:lw,model_id:lw,metric_id:lw,metric_value:cw},ma_qa_metric_local:{ordinal_id:lw,model_id:lw,label_asym_id:ow,label_seq_id:lw,label_comp_id:ow,metric_id:lw,metric_value:cw}};var _w=Jv.Schema;const yw=_w.str,vw=_w.float,bw=_w.List,xw=_w.lstr,ww=_w.Aliased,Sw=_w.int,Mw=_w.coord,Aw={chem_comp:{formula:yw,formula_weight:vw,id:yw,mon_nstd_parent_comp_id:bw(",",(e=>e)),name:yw,one_letter_code:yw,three_letter_code:yw,type:ww(xw),pdbx_synonyms:bw(";",(e=>e)),pdbx_type:yw,pdbx_ambiguous_flag:yw,pdbx_replaced_by:yw,pdbx_replaces:yw,pdbx_formal_charge:Sw,pdbx_model_coordinates_details:yw,pdbx_model_coordinates_db_code:yw,pdbx_ideal_coordinates_details:yw,pdbx_ideal_coordinates_missing_flag:ww(xw),pdbx_model_coordinates_missing_flag:ww(xw),pdbx_initial_date:yw,pdbx_modified_date:yw,pdbx_release_status:ww(yw),pdbx_processing_site:ww(yw)},chem_comp_atom:{alt_atom_id:yw,atom_id:yw,charge:Sw,model_Cartn_x:Mw,model_Cartn_y:Mw,model_Cartn_z:Mw,comp_id:yw,type_symbol:yw,pdbx_align:Sw,pdbx_ordinal:Sw,pdbx_model_Cartn_x_ideal:Mw,pdbx_model_Cartn_y_ideal:Mw,pdbx_model_Cartn_z_ideal:Mw,pdbx_stereo_config:ww(xw),pdbx_aromatic_flag:ww(xw),pdbx_leaving_atom_flag:ww(xw)},chem_comp_bond:{atom_id_1:yw,atom_id_2:yw,comp_id:yw,value_order:ww(xw),pdbx_ordinal:Sw,pdbx_stereo_config:ww(xw),pdbx_aromatic_flag:ww(xw)},pdbx_chem_comp_descriptor:{comp_id:yw,descriptor:yw,type:ww(xw),program:yw,program_version:yw},pdbx_chem_comp_identifier:{comp_id:yw,identifier:yw,type:ww(yw),program:yw,program_version:yw}};var Cw=Jv.Schema;const Tw=Cw.str,Pw=Cw.float,Ew=Cw.lstr,Iw=Cw.Aliased,Dw=Cw.int,Rw={pdbx_reference_molecule:{prd_id:Tw,formula_weight:Pw,formula:Tw,type:Iw(Ew),type_evidence_code:Tw,class:Iw(Ew),class_evidence_code:Tw,name:Tw,represent_as:Iw(Ew),chem_comp_id:Tw,compound_details:Tw,description:Tw,representative_PDB_id_code:Tw,release_status:Iw(Ew),replaces:Tw,replaced_by:Tw},pdbx_reference_entity_list:{prd_id:Tw,ref_entity_id:Tw,type:Iw(Ew),details:Tw,component_id:Dw},pdbx_reference_entity_nonpoly:{prd_id:Tw,ref_entity_id:Tw,name:Tw,chem_comp_id:Tw},pdbx_reference_entity_link:{link_id:Dw,prd_id:Tw,details:Tw,ref_entity_id_1:Tw,ref_entity_id_2:Tw,entity_seq_num_1:Dw,entity_seq_num_2:Dw,comp_id_1:Tw,comp_id_2:Tw,atom_id_1:Tw,atom_id_2:Tw,value_order:Iw(Ew),component_1:Dw,component_2:Dw,link_class:Iw(Tw)},pdbx_reference_entity_poly_link:{link_id:Dw,prd_id:Tw,ref_entity_id:Tw,component_id:Dw,entity_seq_num_1:Dw,entity_seq_num_2:Dw,comp_id_1:Tw,comp_id_2:Tw,atom_id_1:Tw,atom_id_2:Tw,value_order:Iw(Ew)},pdbx_reference_entity_poly:{prd_id:Tw,ref_entity_id:Tw,type:Iw(Tw),db_code:Tw,db_name:Tw},pdbx_reference_entity_poly_seq:{prd_id:Tw,ref_entity_id:Tw,mon_id:Tw,parent_mon_id:Tw,num:Dw,observed:Iw(Ew),hetero:Iw(Ew)},pdbx_reference_entity_sequence:{prd_id:Tw,ref_entity_id:Tw,type:Iw(Tw),NRP_flag:Iw(Tw),one_letter_codes:Tw},pdbx_reference_entity_src_nat:{prd_id:Tw,ref_entity_id:Tw,ordinal:Dw,organism_scientific:Tw,taxid:Tw,db_code:Tw,db_name:Tw},pdbx_prd_audit:{prd_id:Tw,date:Tw,processing_site:Iw(Tw),action_type:Iw(Tw)}};var Lw=Jv.Schema;const kw=Lw.str,Ow={datablock:{id:kw,description:kw},dictionary:{title:kw,datablock_id:kw,version:kw},dictionary_history:{version:kw,update:kw,revision:kw},sub_category:{id:kw,description:kw},category_group_list:{id:kw,parent_id:kw,description:kw},item_type_list:{code:kw,primitive_code:kw,construct:kw,detail:kw},item_units_list:{code:kw,detail:kw},item_units_conversion:{from_code:kw,to_code:kw,operator:kw,factor:Lw.float}};var Nw=Jv.Schema;const Fw=Nw.str,Bw=Nw.int,zw=Nw.float,Uw=Nw.Aliased,Vw=Nw.Vector;Uw(Fw),Uw(Fw),Uw(Fw),Uw(Fw),Vw(3),Vw(3);const $w={volume_data_3d_info:{name:Fw,axis_order:Vw(3,Bw),origin:Vw(3),dimensions:Vw(3),sample_rate:Bw,sample_count:Vw(3,Bw),spacegroup_number:Bw,spacegroup_cell_size:Vw(3),spacegroup_cell_angles:Vw(3),mean_source:zw,mean_sampled:zw,sigma_source:zw,sigma_sampled:zw,min_source:zw,min_sampled:zw,max_source:zw,max_sampled:zw},volume_data_3d:{values:zw}};var Gw=Jv.Schema;const Hw=Gw.float,jw=Gw.int,Ww=Gw.str,qw={cell:{angle_alpha:Hw,angle_beta:Hw,angle_gamma:Hw,formula_units_z:jw,length_a:Hw,length_b:Hw,length_c:Hw,volume:Hw},chemical:{melting_point:Hw,name_common:Ww,name_systematic:Ww},chemical_formula:{moiety:Ww,sum:Ww,weight:Hw},space_group:{crystal_system:Ww,it_number:jw,"name_h-m_full":Ww},space_group_symop:{operation_xyz:Ww},geom_bond:{atom_site_label_1:Ww,atom_site_label_2:Ww,distance:Hw,publ_flag:Ww,site_symmetry_1:Ww,site_symmetry_2:Ww,valence:Hw},audit:{block_doi:Ww},database_code:{cod:Ww,csd:Ww,depnum_ccdc_archive:Ww,depnum_ccdc_fiz:Ww,icsd:Ww,mdf:Ww,nbs:Ww},atom_site:{adp_type:Ww,calc_flag:Ww,disorder_assembly:Ww,disorder_group:Ww,fract_x:Hw,fract_y:Hw,fract_z:Hw,label:Ww,occupancy:Hw,refinement_flags:Ww,site_symmetry_multiplicity:jw,type_symbol:Ww,u_iso_or_equiv:Hw},atom_site_aniso:{label:Ww,u_11:Hw,u:(0,Gw.Matrix)(3,3),u_12:Hw,u_13:Hw,u_22:Hw,u_23:Hw,u_33:Hw},atom_type:{description:Ww,symbol:Ww},atom_type_scat:{dispersion_imag:Hw,dispersion_real:Hw,source:Ww}},Xw={"cell.formula_units_z":["cell_formula_units_Z"],"space_group.it_number":["space_group_IT_number","symmetry_Int_Tables_number"],"space_group.name_h-m_full":["symmetry_space_group_name_H-M"],"space_group_symop.operation_xyz":["symmetry_equiv_pos_as_xyz"],"geom_bond.atom_site_label_1":["geom_bond_atom_site_id_1"],"geom_bond.atom_site_label_2":["geom_bond_atom_site_id_2"],"geom_bond.distance":["geom_bond_dist"],"audit.block_doi":["audit_block_DOI"],"database_code.cod":["database_code_COD"],"database_code.csd":["database_code_CSD"],"database_code.depnum_ccdc_archive":["database_code_depnum_CCDC_archive"],"database_code.depnum_ccdc_fiz":["database_code_depnum_CCDC_fiz"],"database_code.icsd":["database_code_ICSD"],"database_code.mdf":["database_code_MDF"],"database_code.nbs":["database_code_NBS"],"atom_site.adp_type":["atom_site_ADP_type","atom_site_thermal_displace_type"],"atom_site.label":["atom_site_id"],"atom_site.site_symmetry_multiplicity":["atom_site_symmetry_multiplicity"],"atom_site.u_iso_or_equiv":["atom_site_U_iso_or_equiv"],"atom_site_aniso.label":["atom_site_anisotrop_id"],"atom_site_aniso.u_11":["atom_site_aniso_U_11","atom_site_anisotrop_U_11"],"atom_site_aniso.u_12":["atom_site_aniso_U_12","atom_site_anisotrop_U_12"],"atom_site_aniso.u_13":["atom_site_aniso_U_13","atom_site_anisotrop_U_13"],"atom_site_aniso.u_22":["atom_site_aniso_U_22","atom_site_anisotrop_U_22"],"atom_site_aniso.u_23":["atom_site_aniso_U_23","atom_site_anisotrop_U_23"],"atom_site_aniso.u_33":["atom_site_aniso_U_33","atom_site_anisotrop_U_33"]};const Yw=Jv.Schema.int,Kw={volume_data_3d_info:$w.volume_data_3d_info,segmentation_data_table:{set_id:Yw,segment_id:Yw},segmentation_data_3d:{values:Yw}},Zw={parse:e=>"string"==typeof e?Ax(e):Kx(e),parseText:Ax,parseBinary:Kx,toDatabaseCollection:function(e,t,i){const n={};for(const r of t.blocks)n[r.header]=Qx(e,r,i);return n},toDatabase:Qx,schema:{mmCIF:e=>Qx(gw,e),CCD:e=>Qx(Aw,e),BIRD:e=>Qx(Rw,e),dic:e=>Qx(Ow,e),cifCore:e=>Qx(qw,e,Xw),densityServer:e=>Qx($w,e),segmentation:e=>Qx(Kw,e)}};class Qw{constructor(e,t){var i=t||{};this.streamer=e,this.name=uo(i.name,""),this.path=uo(i.path,"")}get type(){return""}get __objName(){return""}get isBinary(){return!1}get isJson(){return!1}get isXml(){return!1}parse(){return this.streamer.read().then((()=>Lg(this,void 0,void 0,(function*(){return yield this._beforeParse(),yield this._parse(),yield this._afterParse(),this[this.__objName]}))))}_parse(){}_beforeParse(){}_afterParse(){e.Debug&&Fl.log(this[this.__objName])}}class Jw extends Qw{constructor(e,t){var i=t||{};super(e,i),this.firstModelOnly=uo(i.firstModelOnly,!1),this.asTrajectory=uo(i.asTrajectory,!1),this.cAlphaOnly=uo(i.cAlphaOnly,!1),this.structure=new vp(this.name,this.path),this.structureBuilder=new Om(this.structure)}get type(){return"structure"}get __objName(){return"structure"}}class eS{constructor(e,t,i="",n,r=[]){this.structure=e,this.index=t,this.description=i,this.entityType=function(e){switch(e=e.toLowerCase()){case"polymer":return 1;case"non-polymer":return 2;case"macrolide":return 3;case"water":return 4;default:return 0}}(n||""),this.chainIndexList=r,r.forEach((function(i){e.chainStore.entityIndex[i]=t}))}get type(){return function(e){switch(e){case 1:return"polymer";case 2:return"non-polymer";case 3:return"macrolide";case 4:return"water";default:return}}(this.entityType)}getEntityType(){return this.entityType}isPolymer(){return 1===this.entityType}isNonPolymer(){return 2===this.entityType}isMacrolide(){return 3===this.entityType}isWater(){return 4===this.entityType}eachChain(e){const t=this.structure.getChainProxy();this.chainIndexList.forEach((function(i){t.index=i,e(t)}))}}const tS={a:1,b:1,c:1,alpha:90,beta:90,gamma:90,spacegroup:"P 1"};class iS{constructor(e=tS){this.cartToFrac=new qt,this.fracToCart=new qt,this.a=e.a,this.b=e.b,this.c=e.c,this.alpha=e.alpha,this.beta=e.beta,this.gamma=e.gamma,this.spacegroup=e.spacegroup;const t=Ro(this.alpha),i=Ro(this.beta),n=Ro(this.gamma),r=Math.cos(t),s=Math.cos(i),a=Math.cos(n),o=Math.sin(i),l=Math.sin(n);if(this.volume=this.a*this.b*this.c*Math.sqrt(1-r*r-s*s-a*a+2*r*s*a),void 0===e.cartToFrac){const e=this.a*this.b*l/this.volume,t=(s*a-r)/(o*l);this.fracToCart.set(this.a,0,0,0,this.b*a,this.b*l,0,0,this.c*s,-this.c*o*t,1/e,0,0,0,0,1).transpose(),this.cartToFrac.copy(this.fracToCart).invert()}else this.cartToFrac.copy(e.cartToFrac),this.fracToCart.copy(this.cartToFrac).invert()}getPosition(e){const t=new Float32Array(24);if(e.unitcell){const i=e.unitcell,n=e.center.clone().applyMatrix4(i.cartToFrac).floor(),r=new _t;let s=0;const a=function(e,a,o){r.set(e,a,o).add(n).applyMatrix4(i.fracToCart).toArray(t,s),s+=3};a(0,0,0),a(1,0,0),a(0,1,0),a(0,0,1),a(1,1,0),a(1,0,1),a(0,1,1),a(1,1,1)}return t}getCenter(e){return function(e,t=new _t){const i=e.length;for(let n=0;n0)continue;let e,i,n,r,o,g=0;if(s){if(r=M.split(aS),g=10===r.length?1:0,R=r[2],m&&"CA"!==R)continue;e=parseFloat(r[6-g]),i=parseFloat(r[7-g]),n=parseFloat(r[8-g])}else{if(R=M.substr(12,4).trim(),m&&"CA"!==R)continue;e=parseFloat(M.substr(30,8)),i=parseFloat(M.substr(38,8)),n=parseFloat(M.substr(46,8))}if(f){const t=3*y;if(_[t+0]=e,_[t+1]=i,_[t+2]=n,y+=1,v)continue}s?(C=parseInt(r[1]),o="",L="H"===M[0],T=g?"":r[4],P=parseInt(r[5-g]),D="",E=r[3],O="",I=1):(C=parseInt(M.substr(6,5),u),c&&99999===C&&(u=16),L="H"===M[0],T=M[21].trim(),P=parseInt(M.substr(22,4),h),c&&9999===P&&(h=16),D=M[26].trim(),E=M.substr(17,4).trim()||"MOL",k=parseFloat(M.substr(60,6)),O=M[16].trim(),I=parseFloat(M.substr(54,6)),t||(a?(o=M.substr(76,3).trim(),o in cd&&(o=cd[o])):(o=M.substr(76,2).trim(),T||(T=M.substr(72,4).trim())),N=parseInt((M.substr(79,1)+M.substr(78,1)).trim()))),he.growIfFull(),he.atomTypeId[me]=ue.add(R,o),he.x[me]=e,he.y[me]=i,he.z[me]=n,he.serial[me]=C,he.altloc[me]=O.charCodeAt(0),he.occupancy[me]=isNaN(I)?0:I,s?(he.partialCharge[me]=parseFloat(r[9-g]),he.radius[me]=parseFloat(r[10-g])):(he.bfactor[me]=isNaN(k)?0:k,a&&(he.partialCharge[me]=parseFloat(M.substr(70,6))),isFinite(N)&&(he.formalCharge||he.addField("formalCharge",1,"int8"),he.formalCharge[me]=N));const b=oS(P,T,D);!L||K[b]||rS.includes(E)?ee||te===T||(Q+=1,J=Q.toString()):te===T&&ne===E&&(nd.includes(E)||ie===P&&re===D)||(Q+=1,J=Q.toString(),ie=P,ne=E,re=D),l.addAtom(pe,T,J,E,P,L,void 0,D),G[C]=me,me+=1,ee=!1,te=T}else if("CONECT"===A){const e=G[parseInt(M.substr(6,5))],t=[11,16,21,26],i={};if(void 0===e)continue;for(let n=0;n<4;++n){let r=parseInt(M.substr(t[n],5));if(!Number.isNaN(r)&&(r=G[r],void 0!==r))if(e{var i;return[null===(i=r.get(e))||void 0===i?void 0:i.atomname,t]}))),a=[],o=[],l=[];let c,u;for(let e=0;e{var y;const v=l.getField(m),b=l.getField(p),x=l.getField(g),w=_*a;for(let l=0;ll*l)return s.growIfFull(),s.atomTypeId[b]=s.atomTypeId[e],s.x[b]=_.x,s.y[b]=_.y,s.z[b]=_.z,s.occupancy[b]=s.occupancy[e],s.serial[b]=b,s.altloc[b]="A".charCodeAt(0),i.addAtom(0,"","","HET",1,!0),void(b+=1)}}}))}}(D,w,S),S.finalize(),w.finalizeAtoms(),Vm(w),w.finalizeBonds();else{const E={},I={},R=w.atomMap,L=w.atomStore,k=D.categories.atom_site;let O=k.rowCount;const N=k.getField("pdbx_PDB_model_num");if(!(null===(t=null==N?void 0:N.areValuesEqual(0,O-1))||void 0===t||t)&&(A||M)){const e=N.int(0);for(let t=0;te){O=t;break}}w.chemCompMap=new cS(w);const F=D.categories.chem_comp;let B=F.getField("id");const z=F.getField("type");for(let e=0;e{const n=e.getField(t);return n?n.toFloatArray({array:Float32Array,start:0,end:i}):new Float32Array(i)};L.resize(O),L.x=U(k,"Cartn_x",O),L.y=U(k,"Cartn_y",O),L.z=U(k,"Cartn_z",O),L.serial=k.getField("id").toIntArray({start:0,end:O}),L.bfactor=U(k,"B_iso_or_equiv",O),L.occupancy=U(k,"occupancy",O);const V=k.getField("label_alt_id");(null==V?void 0:V.isDefined)&&(L.altloc=Uint8Array.from(V.toStringArray(),(e=>e.charCodeAt(0))));const $=k.getField("label_atom_id"),G=k.getField("type_symbol");B=k.getField("label_comp_id");const H=null!==(i=k.getField("auth_seq_id"))&&void 0!==i?i:k.getField("label_seq_id"),j=k.getField("pdbx_PDB_ins_code"),W=k.getField("auth_asym_id"),q=k.getField("label_asym_id"),X=k.getField("group_PDB"),Y=k.getField("label_entity_id");for(let e=0;e0){const[e,t]=c.split("(").filter((e=>!!e)),i=s(e),r=s(t);Object.keys(i).forEach((function(e){Object.keys(r).forEach((function(t){const s=new qt;s.multiplyMatrices(i[e],r[t]),n[e+"x"+t]=s}))}))}else n=s(c);const u=[];for(let e in n)u.push(n[e]);let h=""+t;/^(0|[1-9][0-9]*)$/.test(h)&&(h="BU"+h);const d=l.str(e).split(",").map((e=>i[e]));void 0===r[h]&&(r[h]=new Lm(h)),r[h].addPart(u,d)}}if(e.struct_ncs_oper){const t=e.struct_ncs_oper,i="NCS";r[i]=new Lm(i);const n=r[i].addPart(),s=t.getField("code"),a=t.getField("matrix[1][1]"),o=t.getField("matrix[1][2]"),l=t.getField("matrix[1][3]"),c=t.getField("matrix[2][1]"),u=t.getField("matrix[2][2]"),h=t.getField("matrix[2][3]"),d=t.getField("matrix[3][1]"),f=t.getField("matrix[3][2]"),m=t.getField("matrix[3][3]"),p=t.getField("vector[1]"),g=t.getField("vector[2]"),_=t.getField("vector[3]");for(let e=0;ea&&([s,a]=[a,s],[T,D]=[D,T]),0!==s&&0!==a)for(let e=0;ev)continue}d=T.substr(5,5).trim(),f=parseInt(T.substr(0,5)),m=parseInt(T.substr(15,5)),x.growIfFull(),x.atomTypeId[w]=b.add(h),x.x[w]=I,x.y[w]=D,x.z[w]=R,x.serial[w]=m,r.addAtom(S,"","",d,f,!1,"l"),w+=1}}}(0,e.length,e)})),r.finalize(),n.finalizeAtoms(),Um(n),Vm(n),n.finalizeBonds(),Fm(n),e.Debug&&Fl.timeEnd("GroParser._parse "+this.name)}});var pS=["mmtfVersion","mmtfProducer","unitCell","spaceGroup","structureId","title","depositionDate","releaseDate","experimentalMethods","resolution","rFree","rWork","bioAssemblyList","ncsOperatorList","entityList","groupList","numBonds","numAtoms","numGroups","numChains","numModels","groupsPerChain","chainsPerModel"].concat(["xCoordList","yCoordList","zCoordList","groupIdList","groupTypeList","chainIdList","bFactorList","atomIdList","altLocList","occupancyList","secStructList","insCodeList","sequenceIndexList","chainNameList","bondAtomList","bondOrderList"]);function gS(e,t,i){return t?new e(t.buffer,t.byteOffset,t.byteLength/(i||1)):void 0}function _S(e){return gS(DataView,e)}function yS(e){return gS(Int8Array,e)}function vS(e){return gS(Int32Array,e,4)}function bS(e,t){var i=e.length/2;t||(t=new Int16Array(i));for(var n=0,r=0;ns&&++o;t=new Int32Array(o)}for(i=0,n=0;ir){for(var s=[],a=0;a0&&(a.biomolDict[e]=t)}const k=o.unitCell;k&&Array.isArray(k)&&k[0]?a.unitcell=new iS({a:k[0],b:k[1],c:k[2],alpha:k[3],beta:k[4],gamma:k[5],spacegroup:o.spaceGroup}):a.unitcell=void 0,jm(a,!0),Hm(a,!0),a.finalizeAtoms(),a.finalizeBonds(),Wm(a),e.Debug&&Fl.timeEnd("MmtfParser._parse "+this.name)}});const RS=/\s+/,LS={1:1,2:2,3:3,am:1,ar:1,du:1,un:1,nc:0};jl.add("mol2",class extends Jw{get type(){return"mol2"}_parse(){e.Debug&&Fl.time("Mol2Parser._parse "+this.name);const t=this.structure,i=this.structureBuilder,n=this.firstModelOnly,r=this.asTrajectory,s=t.frames;let a,o,l=!1;const c=t.atomMap,u=t.atomStore;u.resize(Math.round(this.streamer.data.length/60)),u.addField("partialCharge",1,"float32");let h=0,d=0,f=0,m=-1,p=0,g=0;const _=t.getAtomProxy(),y=t.getAtomProxy();this.streamer.eachChunkOfLines((function(e){!function(e,v,b){for(let x=e;xMOLECULE"===e?(g=1,d=0,++m):"@ATOM"===e?(g=2,f=u.count,r&&(o=0,a=new Float32Array(3*p),s.push(a),m>0&&(l=!0))):g="@BOND"===e?3:0;else if(1===g){if(0===d)t.title=e,t.id=e;else if(1===d){const t=e.split(RS);p=parseInt(t[0])}++d}else if(2===g){const t=e.split(RS);if(n&&m>0)continue;const s=parseFloat(t[2]),d=parseFloat(t[3]),f=parseFloat(t[4]);if(r){const e=3*o;if(a[e+0]=s,a[e+1]=d,a[e+2]=f,o+=1,l)continue}const p=t[0],g=t[1],_=t[5].split(".")[0],y=t[6]?parseInt(t[6]):1,v=t[7]?t[7]:"",b=t[8]?parseFloat(t[8]):0;u.growIfFull(),u.atomTypeId[h]=c.add(g,_),u.x[h]=s,u.y[h]=d,u.z[h]=f,u.serial[h]=+p,u.partialCharge[h]=b,i.addAtom(m,"","",v,y,!0),h+=1}else if(3===g){if(n&&m>0)continue;if(r&&m>0)continue;const i=e.split(RS);_.index=parseInt(i[1])-1+f,y.index=parseInt(i[2])-1+f;const s=LS[i[3]];t.bondStore.addBond(_,y,s)}}}(0,e.length,e)})),i.finalize(),t.finalizeAtoms(),Um(t),Hm(t,!0),jm(t,!0),t.finalizeBonds(),Km(t),Fm(t),e.Debug&&Fl.timeEnd("Mol2Parser._parse "+this.name)}});jl.add("pdbqt",class extends lS{get type(){return"pdbqt"}});jl.add("pqr",class extends lS{get type(){return"pqr"}});const kS=/> +<(.+)>/;class OS extends Jw{get type(){return"sdf"}_parse(){e.Debug&&Fl.time("SdfParser._parse "+this.name);const t=this.structure,i=this.structureBuilder,n=this.firstModelOnly,r=this.asTrajectory,s=this.streamer.peekLines(2);t.id=s[0].trim(),t.title=s[1].trim();const a=t.frames;let o,l,c=!1;const u=t.atomMap,h=t.atomStore;h.resize(Math.round(this.streamer.data.length/50)),h.addField("formalCharge",1,"int8");const d=t.getAtomProxy(),f=t.getAtomProxy();let m=0,p=0,g=0,_=0;const y=[];let v,b,x,w,S,M,A,C,T,P,E,I,D,R,L=!1,k={};t.extraData.sdf=y;let O=!1,N=!1,F=!1,B=[],z=[];const U=new Map;this.streamer.eachChunkOfLines((function(e){!function(e,s,V){for(let $=e;$-1,O?U.clear():(b=parseInt(e.substr(0,3)),x=parseInt(e.substr(3,3)),w=4,S=w+b,M=S,A=M+x,r&&(l=0,o=new Float32Array(3*b),a.push(o),g>0&&(c=!0)));else if(O&&"COUNTS"===B[0])b=parseInt(B[1]),r&&(l=0,o=new Float32Array(3*b),a.push(o),g>0&&(c=!0));else if(O&&2==B.length)"ATOM"===B[1]?"BEGIN"===B[0]?N=!0:"END"===B[0]&&(N=!1):"BOND"===B[1]&&("BEGIN"===B[0]?F=!0:"END"===B[0]&&(F=!1));else if(N||!O&&p>=w&&p0)continue;let t=0;if(O){if(C=parseFloat(B[2]),T=parseFloat(B[3]),P=parseFloat(B[4]),I=B[1],D=parseInt(B[0]),U.set(D,m),E=I+D,B.length>6){let e=B.slice(6).find((e=>0===e.indexOf("CHG=")));e&&(t=parseInt(e.substring(4)))}}else C=parseFloat(e.substr(0,10)),T=parseFloat(e.substr(10,10)),P=parseFloat(e.substr(20,10)),I=e.substr(31,3).trim(),E=I+(m-_+1);if(r){const e=3*l;if(o[e+0]=C,o[e+1]=T,o[e+2]=P,l+=1,c)continue}h.growIfFull(),h.atomTypeId[m]=u.add(E,I),h.x[m]=C,h.y[m]=T,h.z[m]=P,h.serial[m]=O?D:m,h.formalCharge[m]=t,i.addAtom(g,"","","HET",1,!0),m+=1}else if(F||!O&&p>=M&&p0)continue;if(r&&g>0)continue;O?(d.index=U.get(parseInt(B[2])),f.index=U.get(parseInt(B[3])),R=parseInt(B[1])):(d.index=parseInt(e.substr(0,3))-1+_,f.index=parseInt(e.substr(3,3))-1+_,R=parseInt(e.substr(6,3))),t.bondStore.addBond(d,f,R)}else if("M CHG"===e.substr(0,6)){const t=parseInt(e.substr(6,3));for(let i=0,n=10;i"===e.charAt(0)&&(v=e.match(kS))?(L=v[1],k[L]=[]):!1!==L&&e&&k[L].push(e);++p}}}(0,e.length,e)})),i.finalize(),t.finalizeAtoms(),t.finalizeBonds(),Km(t),e.Debug&&Fl.timeEnd("SdfParser._parse "+this.name)}_postProcess(){Km(this.structure)}}jl.add("sdf",OS),jl.add("sd",OS),jl.add("mol",OS);function NS(e,t,i){return parseInt(e.substr(t,i).trim())}class FS extends Jw{get type(){return"prmtop"}_parse(){e.Debug&&Fl.time("PrmtopParser._parse "+this.name);const t=this.structure,i=this.structureBuilder,n=t.atomMap,r=t.atomStore;r.addField("partialCharge",1,"float32"),r.addField("radius",1,"float32");const s=[],a={},o=["NATOM","NTYPES","NBONH","MBONA","NTHETH","MTHETA","NPHIH","MPHIA","NHPARM","NPARM","NNB","NRES","NBONA","NTHETA","NPHIA","NUMBND","NUMANG","NPTRA","NATYP","NPHB","IFPERT","NBPER","NGPER","NDPER","MBPER","MGPER","MDPER","IFBOX","NMXRS","IFCAP","NUMEXTRA","NCOPY"];let l,c,u,h,d;o.forEach((e=>{a[e]=0}));let f,m,p,g,_,y=new Uint8Array(0);this.streamer.eachChunkOfLines((function(e){!function(e,t,i){for(let n=e;n0)return void Fl.error("dcd format with fixed atoms unsupported, aborting");const p=a.NATOM,g=4*p;for(let e=0,n=a.NSET;e=1&&(n.timeOffset=(a.ISTART-1)*n.deltaTime),e.Debug&&Fl.timeEnd("DcdParser._parse "+this.name)}});const WS={BYTE:1,CHAR:2,SHORT:3,INT:4,FLOAT:5,DOUBLE:6};function qS(e){switch(Number(e)){case WS.BYTE:return"byte";case WS.CHAR:return"char";case WS.SHORT:return"short";case WS.INT:return"int";case WS.FLOAT:return"float";case WS.DOUBLE:return"double";default:return"undefined"}}function XS(e){switch(Number(e)){case WS.BYTE:case WS.CHAR:return 1;case WS.SHORT:return 2;case WS.INT:case WS.FLOAT:return 4;case WS.DOUBLE:return 8;default:return-1}}function YS(e){switch(String(e)){case"byte":return WS.BYTE;case"char":return WS.CHAR;case"short":return WS.SHORT;case"int":return WS.INT;case"float":return WS.FLOAT;case"double":return WS.DOUBLE;default:return-1}}function KS(e,t){if(1!==e){const i=new Array(e);for(let n=0;n6,"non valid type "+u);const h=e.readUint32();let d=e.readUint32();2===i&&(GS(d>0,"offsets larger than 4GB not supported"),d=e.readUint32()),l[0]===t&&(s+=h),r[n]={name:a,dimensions:l,attributes:c,type:qS(u),size:h,offset:d,record:l[0]===t}}}return{variables:r,recordStep:s}}(e,n.recordId,t);return i.variables=r.variables,i.recordDimension.recordStep=r.recordStep,i}function nM(e){let t;const i=e.readUint32();if(i===QS)return GS(e.readUint32()!==QS,"wrong empty tag for list of attributes"),[];{GS(i!==tM,"wrong tag for list of attributes");const n=e.readUint32();t=new Array(n);for(let i=0;i6,"non valid type "+r);const s=e.readUint32(),a=ZS(e,r,s);HS(e),t[i]={name:n,type:qS(r),value:a}}}return t}class rM{constructor(e){const t=new uc(e);t.setBigEndian(),GS("CDF"!==t.readChars(3),"should start with CDF");const i=t.readByte();GS(i>2,"unknown version"),this.header=iM(t,i),this.buffer=t}get version(){return 1===this.header.version?"classic format":"64-bit offset format"}get recordDimension(){return this.header.recordDimension}get dimensions(){return this.header.dimensions}get globalAttributes(){return this.header.globalAttributes}get variables(){return this.header.variables}hasDataVariable(e){return-1!==this.header.variables.findIndex((function(t){return t.name===e}))}getDataVariable(e){let t;return t="string"==typeof e?this.header.variables.find((function(t){return t.name===e})):e,GS(void 0===t,"variable not found"),this.buffer.seek(t.offset),t.record?function(e,t,i){const n=YS(t.type),r=t.size?t.size/XS(n):1,s=i.length,a=new Array(s),o=i.recordStep;for(let t=0;t=1&&(i.timeOffset=s[0]),s.length>=2&&(i.deltaTime=s[1]-s[0]),e.Debug&&Fl.timeEnd("NctrajParser._parse "+this.name)}}jl.add("nctraj",sM),jl.add("ncdf",sM),jl.add("nc",sM);jl.add("trr",class extends $S{get type(){return"trr"}get isBinary(){return!0}_parse(){e.Debug&&Fl.time("TrrParser._parse "+this.name);const t=Mo(this.streamer.data),i=new DataView(t),n=this.frames,r=n.coordinates,s=n.boxes,a=n.times;let o=0;for(;;){o+=8;const e=i.getInt32(o);o+=4,o+=e;const n=i.getInt32(o+8),l=i.getInt32(o+12),c=i.getInt32(o+16),u=i.getInt32(o+28),h=i.getInt32(o+32),d=i.getInt32(o+36),f=i.getInt32(o+40);o+=52;const m=n/9,p=3*f;if(8===m?a.push(i.getFloat64(o)):a.push(i.getFloat32(o)),o+=2*m,n){const e=new Float32Array(9);if(8===m)for(let t=0;t<9;++t)e[t]=10*i.getFloat64(o),o+=8;else for(let t=0;t<9;++t)e[t]=10*i.getFloat32(o),o+=4;s.push(e)}if(o+=l,o+=c,u){let e;if(8===m){e=new Float32Array(p);for(let t=0;t>8&65280|t>>24&255}e=new Float32Array(t,o,p);for(let t=0;t=t.byteLength)break}a.length>=1&&(n.timeOffset=a[0]),a.length>=2&&(n.deltaTime=a[1]-a[0]),e.Debug&&Fl.timeEnd("TrrParser._parse "+this.name)}});const aM=new Uint32Array([0,0,0,0,0,0,0,0,0,8,10,12,16,20,25,32,40,50,64,80,101,128,161,203,256,322,406,512,645,812,1024,1290,1625,2048,2580,3250,4096,5060,6501,8192,10321,13003,16384,20642,26007,32768,41285,52015,65536,82570,104031,131072,165140,208063,262144,330280,416127,524287,660561,832255,1048576,1321122,1664510,2097152,2642245,3329021,4194304,5284491,6658042,8388607,10568983,13316085,16777216]);function oM(e){let t=1,i=0;for(;e>=t&&i<32;)i++,t<<=1;return i}const lM=new Uint8Array(32);function cM(e,t){let i=1,n=0;lM[0]=1;for(let n=0;n>=8;for(;0!==r;)lM[e++]=255&r,r>>=8;i=e}let r=1;for(i--;lM[i]>=r;)n++,r*=2;return n+8*i}function uM(e,t,i,n){const r=(1<=8;)a=a<<8|t[o++],l|=a>>s<0&&(s>s&(1<8;)hM[o++]=uM(e,t,8,a),n-=8;n>0&&(hM[o++]=uM(e,t,n,a));for(let e=i-1;e>0;e--){let t=0;for(let i=o-1;i>=0;i--){t=t<<8|hM[i];const n=t/r[e]|0;hM[i]=n,t-=n*r[e]}s[e]=t}s[0]=hM[0]|hM[1]<<8|hM[2]<<16|hM[3]<<24}jl.add("xtc",class extends $S{get type(){return"xtc"}get isBinary(){return!0}_parse(){e.Debug&&Fl.time("XtcParser._parse "+this.name);const t=Mo(this.streamer.data),i=new DataView(t),n=this.frames,r=n.coordinates,s=n.boxes,a=n.times,o=new Int32Array(6),l=new Int32Array(3),c=new Int32Array(3),u=new Uint32Array(3),h=new Float32Array(3),d=new Float32Array(3);let f=0;const m=new Int32Array(3),p=new Uint32Array(m.buffer);for(;;){let e;const n=i.getInt32(f+4);f+=12;const g=3*n;a.push(i.getFloat32(f)),f+=4;const _=new Float32Array(9);for(let e=0;e<9;++e)_[e]=10*i.getFloat32(f),f+=4;if(s.push(_),n<=9){e=new Float32Array(n);for(let t=0;t16777215?(c[0]=oM(l[0]),c[1]=oM(l[1]),c[2]=oM(l[2]),a=0):a=cM(3,l);let _=i.getInt32(f);f+=4;let y=_-1;y=9>y?9:y;let v=aM[y]/2|0,b=aM[_]/2|0;u[0]=u[1]=u[2]=aM[_];let x=4*Math.ceil(i.getInt32(f)/4);f+=4;const w=1/s;let S=0,M=0;const A=new Uint8Array(t,f);for(h[0]=h[1]=h[2]=0;M0){h[0]=h[1]=h[2]=0;for(let t=0;t9?aM[_-1]/2|0:0):t>0&&(v=b,b=aM[_]/2|0),u[0]=u[1]=u[2]=aM[_],0===u[0]||0===u[1]||0===u[2])return void console.error("(xdrfile error) Undefined error.")}f+=x}for(let t=0;t=t.byteLength)break}a.length>=1&&(n.timeOffset=a[0]),a.length>=2&&(n.deltaTime=a[1]-a[0]),e.Debug&&Fl.timeEnd("XtcParser._parse "+this.name)}});class fM extends Qw{constructor(e,t){const i=t||{};super(e,i),this.volume=new Df(this.name,this.path),this.voxelSize=uo(i.voxelSize,1)}get type(){return"volume"}get __objName(){return"volume"}_afterParse(){this.volume.setMatrix(this.getMatrix()),super._afterParse()}getMatrix(){return new qt}}const mM=/\s+/,pM=/-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/g,gM=.529177210859;class _M extends fM{get type(){return"cube"}_parse(){e.Debug&&Fl.time("CubeParser._parse "+this.name);const t=this.volume,i=this.streamer.peekLines(6),n={},r=gM*this.voxelSize;function s(e,t){var n=i[e].trim().split(mM)[t];return parseFloat(n)}n.atomCount=Math.abs(s(2,0)),n.originX=s(2,1)*gM,n.originY=s(2,2)*gM,n.originZ=s(2,3)*gM,n.NVX=s(3,0),n.NVY=s(4,0),n.NVZ=s(5,0),n.basisX=new _t(s(3,1),s(3,2),s(3,3)).multiplyScalar(r),n.basisY=new _t(s(4,1),s(4,2),s(4,3)).multiplyScalar(r),n.basisZ=new _t(s(5,1),s(5,2),s(5,3)).multiplyScalar(r);const a=new Float32Array(n.NVX*n.NVY*n.NVZ);let o=0,l=0;const c=s(2,0)>0?0:1;this.streamer.eachChunkOfLines((function(e){!function(e,t,i){for(let r=e;r=n.atomCount+6+c){const t=e.match(pM);for(let e=0,i=t.length;e>8&255}i.xStart=a[0],i.yStart=a[1],i.zStart=a[2],i.xExtent=a[3],i.yExtent=a[4],i.zExtent=a[5],i.xRate=a[6],i.yRate=a[7],i.zRate=a[8];const e=1/a[17],t=e*this.voxelSize;i.xlen=a[9]*t,i.ylen=a[10]*t,i.zlen=a[11]*t,i.alpha=a[12]*e,i.beta=a[13]*e,i.gamma=a[14]*e,n=a[15]/100,r=a[16],i.gamma=a[14]*e}t.header=i,e.Debug&&Fl.log(i,n,r);const c=new Float32Array(i.xExtent*i.yExtent*i.zExtent);let u=512;const h=Math.ceil(i.xExtent/8),d=Math.ceil(i.yExtent/8),f=Math.ceil(i.zExtent/8);for(var m=0;ms){const e=i[n].trim();if(""!==e){const t=e.split(vM);for(let e=0,i=t.length;e=s&&(p-s)%f!=0&&m=0?i-1:i+t/3)},parseNormalIndex:function(e,t){var i=parseInt(e,10);return 3*(i>=0?i-1:i+t/3)},addVertex:function(e,t,i){var n=this.vertices,r=this.object.geometry.vertices;r.push(n[e+0]),r.push(n[e+1]),r.push(n[e+2]),r.push(n[t+0]),r.push(n[t+1]),r.push(n[t+2]),r.push(n[i+0]),r.push(n[i+1]),r.push(n[i+2])},addVertexLine:function(e){var t=this.vertices,i=this.object.geometry.vertices;i.push(t[e+0]),i.push(t[e+1]),i.push(t[e+2])},addNormal:function(e,t,i){var n=this.normals,r=this.object.geometry.normals;r.push(n[e+0]),r.push(n[e+1]),r.push(n[e+2]),r.push(n[t+0]),r.push(n[t+1]),r.push(n[t+2]),r.push(n[i+0]),r.push(n[i+1]),r.push(n[i+2])},addFace:function(e,t,i,n,r,s,a,o){var l,c=this.vertices.length,u=this.parseVertexIndex(e,c),h=this.parseVertexIndex(t,c),d=this.parseVertexIndex(i,c);if(void 0===n?this.addVertex(u,h,d):(l=this.parseVertexIndex(n,c),this.addVertex(u,h,l),this.addVertex(h,d,l)),void 0!==r){var f=this.normals.length;u=this.parseNormalIndex(r,f),h=r===s?u:this.parseNormalIndex(s,f),d=r===a?u:this.parseNormalIndex(a,f),void 0===n?this.addNormal(u,h,d):(l=this.parseNormalIndex(o,f),this.addNormal(u,h,l),this.addNormal(h,d,l))}},addLineGeometry:function(e){this.object.geometry.type="Line";for(var t=this.vertices.length,i=0,n=e.length;i0?v.setAttribute("normal",new $i(new Float32Array(y.normals),3)):v.computeVertexNormals(),_.push(v)}}return _}};jl.add("obj",class extends FM{get type(){return"obj"}getLoader(){return new BM}});const zM=["int8","char","uint8","uchar","int16","short","uint16","ushort","int32","int","uint32","uint","float32","float","float64","double"];function UM(e){if(function(e){return zM.includes(e)}(e))return e;throw new Error(`Unsupported data type: ${e}`)}function VM(e){if("object"!=typeof e||null===e)throw new Error("Expected element to be an object");if("string"!=typeof e.name)throw new Error("Expected element.name to be a string");if("number"!=typeof e.count)throw new Error("Expected element.count to be a number");if(!Array.isArray(e.properties))throw new Error("Expected element.properties to be an array")}function $M(e,t,i){switch(t){case"int8":case"char":return{read:t=>e.getInt8(t),size:1};case"uint8":case"uchar":return{read:t=>e.getUint8(t),size:1};case"int16":case"short":return{read:t=>e.getInt16(t,i),size:2};case"uint16":case"ushort":return{read:t=>e.getUint16(t,i),size:2};case"int32":case"int":return{read:t=>e.getInt32(t,i),size:4};case"uint32":case"uint":return{read:t=>e.getUint32(t,i),size:4};case"float32":case"float":return{read:t=>e.getFloat32(t,i),size:4};case"float64":case"double":return{read:t=>e.getFloat64(t,i),size:8};default:throw new Error(`Unsupported data type: ${t}`)}}function GM(e,t){const i={};let n=0;for(let r=0;r0&&t.setIndex(e.indices),t.setAttribute("position",new ji(e.vertices,3)),e.normals.length>0&&t.setAttribute("normal",new ji(e.normals,3)),e.uvs.length>0&&t.setAttribute("uv",new ji(e.uvs,2)),e.colors.length>0&&t.setAttribute("color",new ji(e.colors,3)),(e.faceVertexUvs.length>0||e.faceVertexColors.length>0)&&(t=t.toNonIndexed(),e.faceVertexUvs.length>0&&t.setAttribute("uv",new ji(e.faceVertexUvs,2)),e.faceVertexColors.length>0&&t.setAttribute("color",new ji(e.faceVertexColors,3)));for(const i of Object.keys(this.customPropertyMapping))e[i].length>0&&t.setAttribute(i,new ji(e[i],this.customPropertyMapping[i].length));return t.computeBoundingSphere(),t}makeBinaryProperties(e,t,i){const n=[];for(let r=0,s=e.length;re.name));function i(e){for(let i=0,n=e.length;i=this.arr.length}next(){return this.arr[this.i++]}}jl.add("ply",class extends FM{get type(){return"ply"}getLoader(){return new HM}});jl.add("csv",class extends Qw{constructor(e,t){const i=t||{};super(e,i),this.delimiter=uo(i.delimiter,","),this.comment=uo(i.comment,"#"),this.columnNames=uo(i.columnNames,!1),this.table={name:this.name,path:this.path,columnNames:[],data:[]}}get type(){return"csv"}get __objName(){return"table"}_parse(){const e=this.table.data,t=new RegExp("\\s*"+this.delimiter+"\\s*");let i=0;this.streamer.eachChunkOfLines((n=>{const r=n.length;for(let s=0;s/g,""),{declaration:t(),root:i()};function t(){if(!r(/^<\?xml\s*/))return;const e={attributes:{}};for(;!s()&&!a("?>");){const t=n();if(!t)return e;e.attributes[t.name]=t.value}return r(/\?>\s*/),e}function i(){const e=r(QM);if(!e)return;const t={name:e[1],attributes:{},children:[]};for(;!(s()||a(">")||a("?>")||a("/>"));){const e=n();if(!e)return t;t.attributes[e.name]=e.value}if(r(/^\s*\/>\s*/))return t;let o;for(r(/\??>\s*/),t.content=function(){const e=r(JM);return e?e[1]:""}();o=i();)t.children.push(o);return r(/^<\/[\w-:.]+>\s*/),t}function n(){const e=r(eA);var t;if(e)return{name:e[1],value:(t=e[2],t.replace(ZM,""))}}function r(t){const i=e.match(t);if(i)return e=e.slice(i[0].length),i}function s(){return 0===e.length}function a(t){return 0===e.indexOf(t)}}class iA extends Qw{constructor(e,t){const i=t||{};super(e,i),this.useDomParser=uo(i.useDomParser,!1),this.xml={name:this.name,path:this.path,data:{}}}get type(){return"xml"}get __objName(){return"xml"}get isXml(){return!0}__xmlParser(e){return tA(e)}__domParser(e){return(new window.DOMParser).parseFromString(e,"text/xml")}_parse(){e.Debug&&Fl.time("XmlParser._parse "+this.name),this.useDomParser?this.streamer.data instanceof Document?this.xml.data=this.streamer.data:this.xml.data=this.__domParser(this.streamer.asText()):this.xml.data=this.__xmlParser(this.streamer.asText()),e.Debug&&Fl.timeEnd("XmlParser._parse "+this.name)}}function nA(e,t){const i=e.getNamedItem(t);return null!==i?i.value:""}function rA(e,t,i=!1){const n=nA(e,"icode").trim(),r=nA(e,"chain").trim(),s=nA(e,"altcode");let a=nA(e,"resnum");return n&&(a+="^"+n),r&&(a+=":"+r),t&&(a+="."+t),i&&s.trim()&&(a+="%"+s),a+="/"+(parseInt(nA(e,"model"))-1),a}function sA(e){const t=nA(e,"chain").trim();let i=`[${nA(e,"rescode")}]${nA(e,"resnum")}`;return t&&(i+=`:${t}`),i}function aA(e,t,i){void 0===e[t]?e[t]=i:e[t]|=i}function oA(e,t){return null!==e&&e.value===t}function lA(e,t,i){let n=0;const r=t.getElementsByTagName("clash");for(let t=0,i=r.length;t0&&(n+=1);t.getElementsByTagName("bond-outlier").length>0&&(n+=1);return t.getElementsByTagName("plane-outlier").length>0&&(n+=1),oA(i.getNamedItem("rota"),"OUTLIER")&&(n+=1),oA(i.getNamedItem("rama"),"OUTLIER")&&(n+=1),oA(i.getNamedItem("RNApucker"),"outlier")&&(n+=1),n}jl.add("xml",iA);class cA{constructor(e,t){this.name=e,this.path=t,this.rsrzDict={},this.rsccDict={},this.rciDict={},this.clashDict={},this.clashArray=[],this.geoDict={},this.geoAtomDict={},this.atomDict={},this.clashSele="NONE"}get type(){return"validation"}fromXml(t){e.Debug&&Fl.time("Validation.fromXml");const i=this.rsrzDict,n=this.rsccDict,r=this.rciDict,s=this.clashDict,a=this.clashArray,o=this.geoDict,l=this.geoAtomDict,c=this.atomDict,u=t.getElementsByTagName("Entry");if(1===u.length){const e=u[0].getElementsByTagName("chemical_shift_list");if(1===e.length){const t=e[0].getElementsByTagName("random_coil_index");for(let e=0,i=t.length;e0&&(o[n]=e)}else{const e=t.getElementsByTagName("clash"),i=t.getElementsByTagName("mog-bond-outlier"),r=t.getElementsByTagName("mog-angle-outlier");if(i.length>0||r.length>0||e.length>0){const t={};l[n]=t;for(let i=0,n=e.length;i>>16&65535,a=0;0!==i;){i-=a=i>2e3?2e3:i;do{s=s+(r=r+t[n++]|0)|0}while(--a);r%=65521,s%=65521}return r|s<<16}jl.add("validation",class extends iA{constructor(e,t){super(e,t||{}),this.useDomParser=!0,this.validation=new cA(this.name,this.path)}get __objName(){return"validation"}get isXml(){return!0}_parse(){super._parse(),e.Debug&&Fl.time("ValidationParser._parse "+this.name),this.validation.fromXml(this.xml.data),e.Debug&&Fl.timeEnd("ValidationParser._parse "+this.name)}});var fA=function(){for(var e,t=[],i=0;i<256;i++){e=i;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t}();function mA(e,t,i,n){var r=fA,s=n+i;e^=-1;for(var a=n;a>>8^r[255&(e^t[a])];return~e}var pA=30,gA=12;function _A(e,t){var i,n,r,s,a,o,l,c,u,h,d,f,m,p,g,_,y,v,b,x,w,S,M,A,C;i=e.state,n=e.next_in,A=e.input,r=n+(e.avail_in-5),s=e.next_out,C=e.output,a=s-(t-e.avail_out),o=s+(e.avail_out-257),l=i.dmax,c=i.wsize,u=i.whave,h=i.wnext,d=i.window,f=i.hold,m=i.bits,p=i.lencode,g=i.distcode,_=(1<>>=b=v>>>24,m-=b,0===(b=v>>>16&255))C[s++]=65535&v;else{if(!(16&b)){if(64&b){if(32&b){i.mode=gA;break e}e.msg="invalid literal/length code",i.mode=pA;break e}v=p[(65535&v)+(f&(1<>>=b,m-=b),m<15&&(f+=A[n++]<>>=b=v>>>24,m-=b,16&(b=v>>>16&255)){if(w=65535&v,m<(b&=15)&&(f+=A[n++]<l){e.msg="invalid distance too far back",i.mode=pA;break e}if(f>>>=b,m-=b,w>(b=s-a)){if((b=w-b)>u&&i.sane){e.msg="invalid distance too far back",i.mode=pA;break e}if(S=0,M=d,0===h){if(S+=c-b,b2;)C[s++]=M[S++],C[s++]=M[S++],C[s++]=M[S++],x-=3;x&&(C[s++]=M[S++],x>1&&(C[s++]=M[S++]))}else{S=s-w;do{C[s++]=C[S++],C[s++]=C[S++],C[s++]=C[S++],x-=3}while(x>2);x&&(C[s++]=C[S++],x>1&&(C[s++]=C[S++]))}break}if(64&b){e.msg="invalid distance code",i.mode=pA;break e}v=g[(65535&v)+(f&(1<>3,f&=(1<<(m-=x<<3))-1,e.next_in=n,e.next_out=s,e.avail_in=n=1&&0===I[x];x--);if(w>x&&(w=x),0===x)return r[s++]=20971520,r[s++]=20971520,o.bits=1,0;for(b=1;b0&&(e===xA||1!==x))return-1;for(D[1]=0,y=1;yvA||e===SA&&C>bA)return 1;for(;;){m=y-M,a[v]f?(p=R[L+a[v]],g=P[E+a[v]]):(p=96,g=0),l=1<>M)+(c-=l)]=m<<24|p<<16|g}while(0!==c);for(l=1<>=1;if(0!==l?(T&=l-1,T+=l):T=0,v++,0==--I[y]){if(y===x)break;y=t[i+a[v]]}if(y>w&&(T&h)!==u){for(0===M&&(M=w),d+=b,A=1<<(S=y-M);S+MvA||e===SA&&C>bA)return 1;r[u=T&h]=w<<24|S<<16|d-s}}return 0!==T&&(r[d+T]=y-M<<24|64<<16),o.bits=w,0}var EA=1,IA=2,DA=0,RA=-2,LA=1,kA=12,OA=30,NA=852,FA=592;function BA(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function zA(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function UA(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,function(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=LA,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(NA),t.distcode=t.distdyn=new Int32Array(FA),t.sane=1,t.back=-1,DA):RA}(e)):RA}function VA(e,t){var i,n;return e?(n=new zA,e.state=n,n.window=null,i=function(e,t){var i,n;return e&&e.state?(n=e.state,t<0?(i=0,t=-t):(i=1+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?RA:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,UA(e))):RA}(e,t),i!==DA&&(e.state=null),i):RA}var $A,GA,HA=!0;function jA(e){if(HA){var t;for($A=new Int32Array(512),GA=new Int32Array(32),t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(PA(EA,e.lens,0,288,$A,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;PA(IA,e.lens,0,32,GA,0,e.work,{bits:5}),HA=!1}e.lencode=$A,e.lenbits=9,e.distcode=GA,e.distbits=5}function WA(e,t,i,n){var r,s=e.state;return null===s.window&&(s.wsize=1<=s.wsize?(hA(s.window,t,i-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):((r=s.wsize-s.wnext)>n&&(r=n),hA(s.window,t,i-n,r,s.wnext),(n-=r)?(hA(s.window,t,i-n,n,0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave>>8&255,i.check=mA(i.check,T,2,0),c=0,u=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg="incorrect header check",i.mode=OA;break}if(8!=(15&c)){e.msg="unknown compression method",i.mode=OA;break}if(u-=4,w=8+(15&(c>>>=4)),0===i.wbits)i.wbits=w;else if(w>i.wbits){e.msg="invalid window size",i.mode=OA;break}i.dmax=1<>8&1),512&i.flags&&(T[0]=255&c,T[1]=c>>>8&255,i.check=mA(i.check,T,2,0)),c=0,u=0,i.mode=3;case 3:for(;u<32;){if(0===o)break e;o--,c+=n[s++]<>>8&255,T[2]=c>>>16&255,T[3]=c>>>24&255,i.check=mA(i.check,T,4,0)),c=0,u=0,i.mode=4;case 4:for(;u<16;){if(0===o)break e;o--,c+=n[s++]<>8),512&i.flags&&(T[0]=255&c,T[1]=c>>>8&255,i.check=mA(i.check,T,2,0)),c=0,u=0,i.mode=5;case 5:if(1024&i.flags){for(;u<16;){if(0===o)break e;o--,c+=n[s++]<>>8&255,i.check=mA(i.check,T,2,0)),c=0,u=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&((f=i.length)>o&&(f=o),f&&(i.head&&(w=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),hA(i.head.extra,n,s,f,w)),512&i.flags&&(i.check=mA(i.check,n,f,s)),o-=f,s+=f,i.length-=f),i.length))break e;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===o)break e;f=0;do{w=n[s+f++],i.head&&w&&i.length<65536&&(i.head.name+=String.fromCharCode(w))}while(w&&f>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=kA;break;case 10:for(;u<32;){if(0===o)break e;o--,c+=n[s++]<>>=7&u,u-=7&u,i.mode=27;break}for(;u<3;){if(0===o)break e;o--,c+=n[s++]<>>=1)){case 0:i.mode=14;break;case 1:if(jA(i),i.mode=20,6===t){c>>>=2,u-=2;break e}break;case 2:i.mode=17;break;case 3:e.msg="invalid block type",i.mode=OA}c>>>=2,u-=2;break;case 14:for(c>>>=7&u,u-=7&u;u<32;){if(0===o)break e;o--,c+=n[s++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=OA;break}if(i.length=65535&c,c=0,u=0,i.mode=15,6===t)break e;case 15:i.mode=16;case 16:if(f=i.length){if(f>o&&(f=o),f>l&&(f=l),0===f)break e;hA(r,n,s,f,a),o-=f,s+=f,l-=f,a+=f,i.length-=f;break}i.mode=kA;break;case 17:for(;u<14;){if(0===o)break e;o--,c+=n[s++]<>>=5,u-=5,i.ndist=1+(31&c),c>>>=5,u-=5,i.ncode=4+(15&c),c>>>=4,u-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=OA;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,u-=3}for(;i.have<19;)i.lens[P[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,M={bits:i.lenbits},S=PA(0,i.lens,0,19,i.lencode,0,i.work,M),i.lenbits=M.bits,S){e.msg="invalid code lengths set",i.mode=OA;break}i.have=0,i.mode=19;case 19:for(;i.have>>16&255,y=65535&C,!((g=C>>>24)<=u);){if(0===o)break e;o--,c+=n[s++]<>>=g,u-=g,i.lens[i.have++]=y;else{if(16===y){for(A=g+2;u>>=g,u-=g,0===i.have){e.msg="invalid bit length repeat",i.mode=OA;break}w=i.lens[i.have-1],f=3+(3&c),c>>>=2,u-=2}else if(17===y){for(A=g+3;u>>=g)),c>>>=3,u-=3}else{for(A=g+7;u>>=g)),c>>>=7,u-=7}if(i.have+f>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=OA;break}for(;f--;)i.lens[i.have++]=w}}if(i.mode===OA)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=OA;break}if(i.lenbits=9,M={bits:i.lenbits},S=PA(EA,i.lens,0,i.nlen,i.lencode,0,i.work,M),i.lenbits=M.bits,S){e.msg="invalid literal/lengths set",i.mode=OA;break}if(i.distbits=6,i.distcode=i.distdyn,M={bits:i.distbits},S=PA(IA,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,M),i.distbits=M.bits,S){e.msg="invalid distances set",i.mode=OA;break}if(i.mode=20,6===t)break e;case 20:i.mode=21;case 21:if(o>=6&&l>=258){e.next_out=a,e.avail_out=l,e.next_in=s,e.avail_in=o,i.hold=c,i.bits=u,_A(e,d),a=e.next_out,r=e.output,l=e.avail_out,s=e.next_in,n=e.input,o=e.avail_in,c=i.hold,u=i.bits,i.mode===kA&&(i.back=-1);break}for(i.back=0;_=(C=i.lencode[c&(1<>>16&255,y=65535&C,!((g=C>>>24)<=u);){if(0===o)break e;o--,c+=n[s++]<>v)])>>>16&255,y=65535&C,!(v+(g=C>>>24)<=u);){if(0===o)break e;o--,c+=n[s++]<>>=v,u-=v,i.back+=v}if(c>>>=g,u-=g,i.back+=g,i.length=y,0===_){i.mode=26;break}if(32&_){i.back=-1,i.mode=kA;break}if(64&_){e.msg="invalid literal/length code",i.mode=OA;break}i.extra=15&_,i.mode=22;case 22:if(i.extra){for(A=i.extra;u>>=i.extra,u-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;_=(C=i.distcode[c&(1<>>16&255,y=65535&C,!((g=C>>>24)<=u);){if(0===o)break e;o--,c+=n[s++]<>v)])>>>16&255,y=65535&C,!(v+(g=C>>>24)<=u);){if(0===o)break e;o--,c+=n[s++]<>>=v,u-=v,i.back+=v}if(c>>>=g,u-=g,i.back+=g,64&_){e.msg="invalid distance code",i.mode=OA;break}i.offset=y,i.extra=15&_,i.mode=24;case 24:if(i.extra){for(A=i.extra;u>>=i.extra,u-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=OA;break}i.mode=25;case 25:if(0===l)break e;if(f=d-l,i.offset>f){if((f=i.offset-f)>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=OA;break}f>i.wnext?(f-=i.wnext,m=i.wsize-f):m=i.wnext-f,f>i.length&&(f=i.length),p=i.window}else p=r,m=a-i.offset,f=i.length;f>l&&(f=l),l-=f,i.length-=f;do{r[a++]=p[m++]}while(--f);0===i.length&&(i.mode=21);break;case 26:if(0===l)break e;r[a++]=i.length,l--,i.mode=21;break;case 27:if(i.wrap){for(;u<32;){if(0===o)break e;o--,c|=n[s++]<=252?6:QA>=248?5:QA>=240?4:QA>=224?3:QA>=192?2:1;function JA(e){var t,i,n,r,s,a=e.length,o=0;for(r=0;r>>6,t[s++]=128|63&i):i<65536?(t[s++]=224|i>>>12,t[s++]=128|i>>>6&63,t[s++]=128|63&i):(t[s++]=240|i>>>18,t[s++]=128|i>>>12&63,t[s++]=128|i>>>6&63,t[s++]=128|63&i);return t}function eC(e,t){var i,n,r,s,a=t||e.length,o=new Array(2*a);for(n=0,i=0;i4)o[n++]=65533,i+=s-1;else{for(r&=2===s?31:3===s?15:7;s>1&&i1?o[n++]=65533:r<65536?o[n++]=r:(r-=65536,o[n++]=55296|r>>10&1023,o[n++]=56320|1023&r)}return function(e,t){if(t<65537&&(e.subarray&&KA||!e.subarray&&YA))return String.fromCharCode.apply(null,uA(e,t));for(var i="",n=0;ne.length&&(t=e.length),i=t-1;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+ZA[e[i]]>t?i:t}ZA[254]=ZA[254]=1;var iC=0,nC={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};function rC(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}function sC(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var aC=Object.prototype.toString;function oC(e){if(!(this instanceof oC))return new oC(e);this.options=function(e){for(var t=Array.prototype.slice.call(arguments,1);t.length;){var i=t.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(var n in i)i.hasOwnProperty(n)&&(e[n]=i[n])}}return e}({chunkSize:16384,windowBits:0,to:""},e||{});var t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(15&t.windowBits||(t.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new rC,this.strm.avail_out=0;var i,n,r,s=VA(this.strm,t.windowBits);if(s!==iC)throw new Error(nC[s]);this.header=new sC,i=this.strm,n=this.header,i&&i.state&&2&(r=i.state).wrap&&(r.head=n,n.done=!1)}oC.prototype.push=function(e,t){var i,n,r,s,a,o,l=this.strm,c=this.options.chunkSize,u=this.options.dictionary,h=!1;if(this.ended)return!1;n=t===~~t?t:!0===t?4:0,"string"==typeof e?l.input=function(e){for(var t=new Uint8Array(e.length),i=0,n=t.length;i0||0===l.avail_out)&&1!==i);return 1===i&&(n=4),4===n?(i=function(e){if(!e||!e.state)return RA;var t=e.state;return t.window&&(t.window=null),e.state=null,DA}(this.strm),this.onEnd(i),this.ended=!0,i===iC):2!==n||(this.onEnd(iC),l.avail_out=0,!0)},oC.prototype.onData=function(e){this.chunks.push(e)},oC.prototype.onEnd=function(e){e===iC&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=function(e){var t,i,n,r,s,a;for(n=0,t=0,i=e.length;t-1?t.name:t.name.substring(0,4);return!["pdb","cif"].includes(t.ext)||!1!==t.compressed&&"gz"!==t.compressed?("mmtf"===t.ext&&(Fl.warn("MMTF files distribution has been discontinued by RCSB PDB as of July 2024.\n Defaulting to bcif format instead. See https://www.rcsb.org/news/65a1af31c76ca3abcc925d0c for the deprecation notice"),t.base.endsWith(".bb")&&Fl.warn("Backbone only files are not available from RCSB PDB anymore."),t.ext=""),t.ext?Fl.warn("unsupported ext",t.ext):Fl.warn('mmCif files available from RCSB PDB lack connectivity information.\n Consider using PDBe as the data provider for using "Updated mmCif files" that contain residues connectivity records.'),cC+"//models.rcsb.org/"+i+".bcif.gz"):cC+"//files.rcsb.org/download/"+t.path}getExt(e){const t=rc(e).ext;return t||"bcif"}});const uC="//www.ebi.ac.uk/pdbe/entry-files/download/";Gl.add("pdbe",new class extends lC{getUrl(e){const t=rc(e);let i,n=t.name.indexOf("_")>-1?t.name:t.name.substring(0,4);switch(t.ext){case"cif":i=uC+n+"_updated.cif";break;case"pdb":case"ent":n.startsWith("pdb")||(n="pdb"+n),i=uC+n+".ent";break;case"bcif":i=uC+t.path;break;case"":i=uC+n+".bcif";break;default:Fl.warn("unsupported ext",t.ext),i=uC+n+".bcif"}return"https://"+i}getExt(e){const t=rc(e).ext;return t||"bcif"}});const hC="//pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/",dC="/SDF?record_type=3d";Gl.add("pubchem",new class extends lC{getUrl(e){const t=rc(e),i=t.name;let n;return t.ext&&"sdf"!==t.ext?(Fl.warn("unsupported ext",t.ext),n=hC+i+dC):n=hC+i+dC,function(){const e=window.location.protocol;return null===e.match(/http(s)?:/gi)?"http:":e}()+n}getExt(e){const t=rc(e).ext;return t||"sdf"}});class fC extends lC{getUrl(e){return e}getExt(e){return rc(e).ext}}Gl.add("ftp",new fC),Gl.add("http",new fC),Gl.add("https",new fC);const mC="//alphafold.ebi.ac.uk/files/AF-",pC="-F1-model_v4.pdb";Gl.add("alphafold",new class extends lC{getUrl(e){const t=rc(e),i=t.name;let n;return t.ext&&"pdb"!==t.ext?(Fl.warn("unsupported AF ext",t.ext),n=mC+i+pC):n=mC+i+pC,"https://"+n}getExt(e){const t=rc(e).ext;return t||"pdb"}});const gC=/^((http|https|ftp):)*\/\//;function _C(e,t){return{type:"integer",max:e,min:t}}function yC(e,t,i){return{type:"number",precision:e,max:t,min:i}}function vC(e,t,i){return{type:"range",step:e,max:t,min:i}}function bC(...e){return{type:"select",options:e.reduce(((e,t)=>Object.assign(Object.assign({},e),{[t]:t})),{})}}const xC={backgroundColor:{type:"color"},quality:bC("auto","low","medium","high"),sampleLevel:vC(1,5,-1),impostor:{type:"boolean"},workerDefault:{type:"boolean"},rotateSpeed:yC(1,10,0),zoomSpeed:yC(1,10,0),panSpeed:yC(1,10,0),clipNear:vC(1,100,0),clipFar:vC(1,100,0),clipDist:_C(200,0),clipMode:bC("scene","camera"),clipScale:bC("relative","absolute"),fogNear:vC(1,100,0),fogFar:vC(1,100,0),cameraType:bC("perspective","orthographic","stereo"),cameraEyeSep:yC(3,1,.01),cameraFov:vC(1,120,15),lightColor:{type:"color"},lightIntensity:yC(2,10,0),ambientColor:{type:"color"},ambientIntensity:yC(2,10,0),hoverTimeout:_C(1e4,-1),tooltip:{type:"boolean"},mousePreset:bC(...Object.keys(Wf))};e.AngleRepresentation=k_,e.ArrowBuffer=rv,e.Assembly=Lm,e.AxesRepresentation=Y_,e.BackboneRepresentation=Z_,e.BallAndStickRepresentation=K_,e.BaseRepresentation=Q_,e.Box3=bt,e.BoxBuffer=cv,e.BufferRepresentation=Mp,e.CartoonRepresentation=sy,e.Collection=rg,e.Color=Oi,e.Colormaker=qo,e.ColormakerRegistry=$l,e.Component=ng,e.ComponentCollection=Tg,e.ConeBuffer=tv,e.ContactRepresentation=ay,e.Counter=hc,e.CylinderBuffer=X_,e.DatasourceRegistry=Gl,e.DecompressorRegistry=ql,e.DihedralHistogramRepresentation=uy,e.DihedralRepresentation=oy,e.DistanceRepresentation=dy,e.EllipsoidBuffer=pv,e.Euler=ni,e.Frames=lg,e.HelixorientRepresentation=gy,e.HyperballRepresentation=Ay,e.Kdtree=Pm,e.KeyActions=Yf,e.LabelRepresentation=Ty,e.LeftMouseButton=1,e.LicoriceRepresentation=_y,e.LineRepresentation=Ey,e.Matrix3=He,e.Matrix4=qt,e.MdsrvDatasource=class extends lC{constructor(e=""){super(),this.baseUrl=e}getListing(e=""){let t=`${this.baseUrl}dir/${e}`;return"/"!==t[t.length-1]&&(t+="/"),ac(t,{ext:"json"}).then((t=>({path:e,data:t.data})))}getUrl(e){const t=rc(e);return`${this.baseUrl}file/${t.path}${t.query}`}getCountUrl(e){const t=rc(e);return`${this.baseUrl}traj/numframes/${t.path}${t.query}`}getFrameUrl(e,t){const i=rc(e);return`${this.baseUrl}traj/frame/${t}/${i.path}${i.query}`}getFrameParams(e,t){return`atomIndices=${t.join(";")}`}getPathUrl(e,t){const i=rc(e);return`${this.baseUrl}traj/path/${t}/${i.path}${i.query}`}getExt(e){return rc(e).ext}},e.MeasurementDefaultParams=Bl,e.MeshBuffer=Bf,e.MiddleMouseButton=2,e.MolecularSurface=ky,e.MolecularSurfaceRepresentation=Oy,e.MouseActions=jf,e.OctahedronBuffer=bv,e.ParserRegistry=jl,e.PdbWriter=class extends lc{constructor(e,t){super(),this.mimeType="text/plain",this.defaultName="structure",this.defaultExt="pdb";const i=Object.assign({},t);this.renumberSerial=uo(i.renumberSerial,!0),this.remarks=function(e){return Array.isArray(e)?e:[e]}(uo(i.remarks,[])),this.structure=e,this._records=[]}_writeRecords(){this._records.length=0,this._writeTitle(),this._writeRemarks(),this._writeAtoms()}_writeTitle(){this._records.push(oc.sprintf("TITLE %-74s",this.structure.name))}_writeRemarks(){this.remarks.forEach((e=>{this._records.push(oc.sprintf("REMARK %-73s",e))})),this.structure.trajectory&&(this._records.push(oc.sprintf("REMARK %-73s","Trajectory '"+this.structure.trajectory.name+"'")),this._records.push(oc.sprintf("REMARK %-73s",`Frame ${this.structure.trajectory.frame}`)))}_writeAtoms(){let e=1,t=1,i=" ",n=" ";const r=this.structure.modelStore.count>1;this.structure.eachModel((s=>{r&&this._records.push(oc.sprintf("MODEL %4d%-66s",t++,"")),s.eachAtom((t=>{const r=t.hetero?"HETATM%5d %-4s %3s %1s%4d %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%1s%1s":"ATOM %5d %-4s %3s %1s%4d %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%1s%1s",s=this.renumberSerial?e:t.serial;let a=t.atomname;(1===a.length||a.length<4&&1===t.element.length&&a[0]===t.element)&&(a=" "+a),t.formalCharge?(i=Math.abs(t.formalCharge).toPrecision(1),n=t.formalCharge>0?"+":"-"):(i=" ",n=" "),this._records.push(oc.sprintf(r,s,a,t.resname,uo(t.chainname," "),t.resno,t.x,t.y,t.z,uo(t.occupancy,1),uo(t.bfactor,0),"",uo(t.element,""),i,n)),e+=1}),this.structure.getSelection()),r&&this._records.push(oc.sprintf("%-80s","ENDMDL"))})),this._records.push(oc.sprintf("%-80s","END"))}getString(){return console.warn("PdbWriter.getString() is deprecated, use .getData instead"),this.getData()}getData(){return this._writeRecords(),this._records.join("\n")}},e.PickingProxy=mu,e.Plane=On,e.PointBuffer=Up,e.PointRepresentation=Ny,e.Quaternion=gt,e.Queue=Ou,e.RepresentationCollection=sg,e.RepresentationElement=Jp,e.RepresentationRegistry=Hl,e.RibbonRepresentation=Uy,e.RightMouseButton=3,e.RocketRepresentation=Vy,e.RopeRepresentation=$y,e.ScriptExtensions=Ul,e.SdfWriter=class extends lc{constructor(e){super(),this.mimeType="text/plain",this.defaultName="structure",this.defaultExt="sdf",this.structure=e,this._records=[]}get idString(){return this.structure.id}get titleString(){return" "+this.structure.title}get countsString(){return oc.sprintf("%3i%3i 0 0 0 0 0 0 0 0999 V2000",this.structure.atomCount,this.structure.bondCount)}get chargeLines(){const e=[];this.structure.eachAtom((t=>{null!=t.formalCharge&&0!==t.formalCharge&&e.push([t.index,t.formalCharge])}));const t=[];for(let i=0;i{this._records.push(this.formatAtom(e))})),this.structure.eachBond((e=>{this._records.push(this.formatBond(e))})),this.chargeLines.forEach((e=>{this._records.push(e)})),this._records.push("M END")}_writeFooter(){this._records.push("$$$$")}getData(){return this._writeRecords(),this._records.join("\n")}},e.Selection=wl,e.Shape=Sp,e.ShapeComponent=Dg,e.Signal=Yo.Signal,e.SpacefillRepresentation=Gy,e.SpatialHash=Ch,e.SphereBuffer=Np,e.Stage=class{constructor(e,t={}){this.signals={parametersChanged:new Yo.Signal,fullscreenChanged:new Yo.Signal,componentAdded:new Yo.Signal,componentRemoved:new Yo.Signal,clicked:new Yo.Signal,hovered:new Yo.Signal},this.tasks=new hc,this.compList=[],this.defaultFileParams={},this.logList=[],this.viewer=new Qc(e),this.viewer.renderer&&(this.tooltip=document.createElement("div"),Object.assign(this.tooltip.style,{display:"none",position:"fixed",zIndex:"1000000",pointerEvents:"none",backgroundColor:"rgba( 0, 0, 0, 0.6 )",color:"lightgrey",padding:"8px",fontFamily:"sans-serif"}),this.viewer.container.appendChild(this.tooltip),this.mouseObserver=new eu(this.viewer.renderer.domElement),this.viewerControls=new Mu(this),this.trackballControls=new du(this),this.pickingControls=new pu(this),this.animationControls=new ku(this),this.mouseControls=new Xf(this),this.keyControls=new Zf(this),this.pickingBehavior=new Qf(this),this.mouseBehavior=new Jf(this),this.animationBehavior=new em(this),this.keyBehavior=new im(this),this.spinAnimation=this.animationControls.spin([0,1,0],.005),this.spinAnimation.pause(!0),this.rockAnimation=this.animationControls.rock([0,1,0],.005),this.rockAnimation.pause(!0),this.parameters=ho(t,Ig),this.setParameters(this.parameters),this.viewer.animate())}setParameters(e={}){fo(this.parameters,e);const t=e,i=this.parameters,n=this.viewer,r=this.trackballControls;return void 0!==t.quality&&this.setQuality(i.quality),void 0!==t.impostor&&this.setImpostor(i.impostor),void 0!==t.rotateSpeed&&(r.rotateSpeed=i.rotateSpeed),void 0!==t.zoomSpeed&&(r.zoomSpeed=i.zoomSpeed),void 0!==t.panSpeed&&(r.panSpeed=i.panSpeed),void 0!==t.mousePreset&&this.mouseControls.preset(i.mousePreset),this.mouseObserver.setParameters({hoverTimeout:i.hoverTimeout}),n.setClip(i.clipNear,i.clipFar,i.clipDist,i.clipMode,i.clipScale),n.setFog(void 0,i.fogNear,i.fogFar),n.setCamera(i.cameraType,i.cameraFov,i.cameraEyeSep),n.setSampling(i.sampleLevel),n.setBackground(i.backgroundColor),n.setLight(i.lightColor,i.lightIntensity,i.ambientColor,i.ambientIntensity),this.signals.parametersChanged.dispatch(this.getParameters()),this}log(e){console.log("STAGE LOG",e),this.logList.push(e)}getParameters(){return Object.assign({},this.parameters)}defaultFileRepresentation(t){if(t instanceof Mg){let i,n,r;t.setSelection("/0");const s=t.structure;if(s.biomolDict.BU1){const e=s.biomolDict.BU1;i=e.getAtomCount(s),n=e.getResidueCount(s),r=e.getInstanceCount(),t.setDefaultAssembly("BU1")}else i=s.getModelProxy(0).atomCount,n=s.getModelProxy(0).residueCount,r=1;let a=i;Rl&&(a*=4);const o=s.atomStore.count/s.residueStore.count<2;o&&(a*=10);let l="chainname",c="RdYlBu",u=!1;if(1===s.getChainnameCount(new wl("polymer and /0"))&&(l="residueindex",c="Spectral",u=!0),e.Debug&&console.log(a,i,r,o),n/r<4)t.addRepresentation("ball+stick",{colorScheme:"element",radiusScale:2,aspectRatio:1.5,bondScale:.3,bondSpacing:.75,quality:"auto"});else if(r>5&&a>15e3||a>7e5){let e=Math.min(2,Math.max(.1,6e3/(a/r)));o&&(e=Math.min(e,.5)),t.addRepresentation("surface",{colorScheme:l,colorScale:c,colorReverse:u,sele:"polymer",surfaceType:"av",probeRadius:1.4,scaleFactor:e,useWorker:!1})}else a>25e4?t.addRepresentation("backbone",{colorScheme:l,colorScale:c,colorReverse:u,lineOnly:!0}):a>1e5?t.addRepresentation("backbone",{colorScheme:l,colorScale:c,colorReverse:u,quality:"low",disableImpostor:!0,radiusScale:2}):a>8e4?t.addRepresentation("backbone",{colorScheme:l,colorScale:c,colorReverse:u,radiusScale:2}):(t.addRepresentation("cartoon",{colorScheme:l,colorScale:c,colorReverse:u,radiusScale:.7,aspectRatio:5,quality:"auto"}),a<5e4&&t.addRepresentation("base",{colorScheme:l,colorScale:c,colorReverse:u,quality:"auto"}),t.addRepresentation("ball+stick",{sele:"ligand",colorScheme:"element",radiusScale:2,aspectRatio:1.5,bondScale:.3,bondSpacing:.75,quality:"auto"}));t.structure.frames.length&&t.addTrajectory()}else(t instanceof Ag||t instanceof Cg)&&t.addRepresentation("surface");this.tasks.onZeroOnce(this.autoView,this)}loadFile(e,t={}){const i=Object.assign({},this.defaultFileParams,t),n=rc(e).name;this.tasks.increment(),this.log(`loading file '${n}'`);const r=uo(i.ext,rc(e).ext);let s;return s=jl.isTrajectory(r)?Promise.reject(new Error(`loadFile: ext '${r}' is a trajectory and must be loaded into a structure component`)):ac(e,i),s.then((e=>{this.log(`loaded '${n}'`);const t=this.addComponentFromObject(e,i);return i.defaultRepresentation&&this.defaultFileRepresentation(t),this.tasks.decrement(),t}),(e=>{this.tasks.decrement();const t=`error loading file: '${e}'`;throw this.log(t),t}))}loadScript(e){const t=rc(e).name;return this.log(`loading script '${t}'`),ac(e).then((e=>{this.tasks.increment(),this.log(`running script '${t}'`),e.run(this).then((()=>{this.tasks.decrement(),this.log(`finished script '${t}'`)})),this.log(`called script '${t}'`)}),(e=>{this.tasks.decrement();const i=`errored script '${t}' "${e}"`;throw this.log(i),i}))}addComponent(e){e?(this.compList.push(e),this.signals.componentAdded.dispatch(e)):Fl.warn("Stage.addComponent: no component given")}addComponentFromObject(e,t={}){const i=Xl.get(e.type);if(i){const n=new i(this,e,t);return this.addComponent(n),n}Fl.warn("no component for object type",e.type)}removeComponent(e){const t=this.compList.indexOf(e);-1!==t&&(this.compList.splice(t,1),e.dispose(),this.signals.componentRemoved.dispatch(e))}removeAllComponents(){this.compList.slice().forEach((e=>this.removeComponent(e)))}handleResize(){this.viewer.handleResize()}setSize(e,t){const i=this.viewer.container;i!==document.body&&(void 0!==e&&(i.style.width=e),void 0!==t&&(i.style.height=t),this.handleResize())}toggleFullscreen(e){if(!(document.fullscreenEnabled||document.mozFullScreenEnabled||document.webkitFullscreenEnabled||document.msFullscreenEnabled))return void Fl.log("fullscreen mode (currently) not possible");const t=this;function i(){return document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.msFullscreenElement}function n(){if(!i()&&t.lastFullscreenElement){const e=t.lastFullscreenElement;e.style.width=e.dataset.normalWidth||"",e.style.height=e.dataset.normalHeight||"",document.removeEventListener("fullscreenchange",n),document.removeEventListener("mozfullscreenchange",n),document.removeEventListener("webkitfullscreenchange",n),document.removeEventListener("MSFullscreenChange",n),t.handleResize(),t.signals.fullscreenChanged.dispatch(!1)}}e=e||this.viewer.container,this.lastFullscreenElement=e,i()?document.exitFullscreen?document.exitFullscreen():document.msExitFullscreen?document.msExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen():(e.dataset.normalWidth=e.style.width||"",e.dataset.normalHeight=e.style.height||"",e.style.width=window.screen.width+"px",e.style.height=window.screen.height+"px",e.requestFullscreen?e.requestFullscreen():e.msRequestFullscreen?e.msRequestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen(),document.addEventListener("fullscreenchange",n),document.addEventListener("mozfullscreenchange",n),document.addEventListener("webkitfullscreenchange",n),document.addEventListener("MSFullscreenChange",n),this.handleResize(),this.signals.fullscreenChanged.dispatch(!0),setTimeout((function(){t.handleResize()}),100))}setSpin(e){e?(this.spinAnimation.resume(!0),this.rockAnimation.pause(!0)):this.spinAnimation.pause(!0)}setRock(e){e?(this.rockAnimation.resume(!0),this.spinAnimation.pause(!0)):this.rockAnimation.pause(!0)}toggleSpin(){this.setSpin(this.spinAnimation.paused)}toggleRock(){this.setRock(this.rockAnimation.paused)}getFocus(){const e=this.parameters;if("scene"!==e.clipMode)return 0;let t=e.clipNear;return"absolute"===e.clipScale&&(t=this.viewer.absoluteToRelative(t)),2*t}setFocus(e){if("scene"!==this.parameters.clipMode)return;let t,i,n,r;"relative"===this.parameters.clipScale?(t=No(e/2,0,49.9),i=100-t,n=50,r=function(e){return No(e,0,100)}(2*i-50)):(t=this.viewer.relativeToAbsolute(e/2),i=t,n=0,r=2*i),this.setParameters({clipNear:t,clipFar:i,fogNear:n,fogFar:r})}getZoomForBox(e){const t=e.getSize(Eg),i=Math.max(t.x,t.y,t.z),n=Math.min(t.x,t.y,t.z);let r=i+Math.sqrt(n);const s=Ro(this.viewer.perspectiveCamera.fov),a=this.viewer.width,o=this.viewer.height,l=o{this.tasks.onZeroOnce((()=>{this.tasks.increment(),this.viewer.makeImage(e).then((e=>{this.tasks.decrement(),t(e)})).catch((e=>{this.tasks.decrement(),i(e)}))}))}))}setImpostor(e){this.parameters.impostor=e;const t=["spacefill","ball+stick","licorice","hyperball","backbone","rocket","helixorient","contact","distance","dot"];this.eachRepresentation((function(i){if(!t.includes(i.getType()))return;const n=i.getParameters();n.disableImpostor=!e,i.build(n)}))}setQuality(e){this.parameters.quality=e;const t=["tube","cartoon","ribbon","trace","rope"],i=["spacefill","ball+stick","licorice","hyperball","backbone","rocket","helixorient","contact","distance","dot"];this.eachRepresentation((function(n){const r=n.getParameters();if(!t.includes(n.getType())){if(!i.includes(n.getType()))return;if(!r.disableImpostor)return void(n.repr.quality=e)}r.quality=e,n.build(r)}))}eachComponent(e,t){this.compList.slice().forEach((i=>{void 0!==t&&t!==i.type||e(i)}))}eachRepresentation(e,t){this.eachComponent((i=>{i.reprList.slice().forEach((n=>{void 0!==t&&t!==n.getType()||e(n,i)}))}))}getComponentsByName(e){const t=[];return this.eachComponent((i=>{(void 0===e||Pg(e,i))&&t.push(i)})),new Tg(t)}getComponentsByObject(e){const t=[];return this.eachComponent((i=>{i.object===e&&t.push(i)})),new Tg(t)}getRepresentationsByName(e){const t=[];return this.eachRepresentation(((i,n)=>{(void 0===e||Pg(e,i))&&t.push(i)})),new sg(t)}measureClear(){this.eachComponent((e=>e.measureClear()),"structure")}measureUpdate(){this.eachComponent((e=>e.measureUpdate()),"structure")}dispose(){this.tasks.dispose(),this.viewer.dispose(),this.mouseObserver.dispose()}},e.StaticDatasource=class extends lC{constructor(e=""){super(),this.baseUrl=e}getUrl(e){const t=rc(e);let i=this.baseUrl+t.path;return gC.test(this.baseUrl)||(i=function(e){const t=window.location,i=t.pathname,n=i.substring(0,i.lastIndexOf("/")+1);return t.origin+n+e}(i)),i}getExt(e){return rc(e).ext}},e.StlWriter=class extends lc{constructor(e){super(),this.mimeType="application/vnd.ms-pki.stl",this.defaultName="surface",this.defaultExt="stl",this.surface=e}getData(){const e=this.surface.index.length/3,t=new uc(2*e+3*e*4*4+80+4);t.skip(80),t.writeUint32(e);const i=new _t,n=new _t,r=new _t,s=new _t;for(let a=0;a{e.eachAtom((e=>{s.growIfFull(),s.atomTypeId[l]=a.add(e.atomname,e.element),s.x[l]=e.x,s.y[l]=e.y,s.z[l]=e.z,s.serial[l]=e.serial,s.formalCharge[l]=e.formalCharge,s.partialCharge[l]=e.partialCharge,s.altloc[l]=e.altloc,s.occupancy[l]=e.occupancy,s.bfactor[l]=e.bfactor,r.addAtom(e.modelIndex+u,e.chainname,e.chainid,e.resname,e.resno,1===e.hetero,e.sstruc,e.inscode),o[e.index+c]=l,l+=1})),c+=e.atomStore.count,u+=e.modelStore.count}));const h=n.bondStore,d=n.getAtomProxy(),f=n.getAtomProxy();return c=0,i.forEach((e=>{e.eachBond((e=>{d.index=o[e.atomIndex1+c],f.index=o[e.atomIndex2+c],h.addBond(d,f,e.bondOrder)})),c+=e.atomStore.count})),r.finalize(),jm(n,!0),Hm(n,!0),n.finalizeAtoms(),n.finalizeBonds(),Km(n),e.Debug&&Fl.timeEnd("concatStructures"),n},e.download=go,e.flatten=function e(t,i){i=uo(i,[]);for(let n=0;nt?(a&&(clearTimeout(a),a=null),o=c,s=e.apply(n,r),a||(n=r=null)):a||!1===i.trailing||(a=setTimeout(l,u)),s}},e.uniqueArray=bo,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ngl.js.map