!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=0,i=1,n=2,r=1,s=2,o=3,a=0,c=1,l=2,h=0,u=1,d=2,f=3,m=4,p=5,g=100,v=101,y=102,x=103,b=104,_=200,w=201,S=202,A=203,M=204,C=205,P=206,T=207,I=208,E=209,D=210,L=0,R=1,k=2,O=3,B=4,N=5,F=6,z=7,U=0,$=1,G=2,V=0,H=1,j=2,W=3,q=4,X=5,Y=301,Z=302,K=303,Q=304,J=306,ee=307,te=1e3,ie=1001,ne=1002,re=1003,se=1004,oe=1005,ae=1006,ce=1007,le=1008,he=1009,ue=1010,de=1011,fe=1012,me=1013,pe=1014,ge=1015,ve=1016,ye=1017,xe=1018,be=1019,_e=1020,we=1021,Se=1022,Ae=1023,Me=1024,Ce=1025,Pe=1026,Te=1027,Ie=1028,Ee=1029,De=1030,Le=1031,Re=1032,ke=1033,Oe=33776,Be=33777,Ne=33778,Fe=33779,ze=35840,Ue=35841,$e=35842,Ge=35843,Ve=36196,He=37492,je=37496,We=37808,qe=37809,Xe=37810,Ye=37811,Ze=37812,Ke=37813,Qe=37814,Je=37815,et=37816,tt=37817,it=37818,nt=37819,rt=37820,st=37821,ot=36492,at=37840,ct=37841,lt=37842,ht=37843,ut=37844,dt=37845,ft=37846,mt=37847,pt=37848,gt=37849,vt=37850,yt=37851,xt=37852,bt=37853,_t=3e3,wt=3001,St=3007,At=3002,Mt=3003,Ct=3004,Pt=3005,Tt=3006,It=3200,Et=3201,Dt=0,Lt=1,Rt=7680,kt=519,Ot=35044;function Bt(){}Object.assign(Bt.prototype,{addEventListener:function(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:function(e,t){if(void 0===this._listeners)return!1;const i=this._listeners;return void 0!==i[e]&&-1!==i[e].indexOf(t)},removeEventListener:function(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:function(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]+Nt[e>>16&255]+Nt[e>>24&255]+"-"+Nt[255&t]+Nt[t>>8&255]+"-"+Nt[t>>16&15|64]+Nt[t>>24&255]+"-"+Nt[63&i|128]+Nt[i>>8&255]+"-"+Nt[i>>16&255]+Nt[i>>24&255]+Nt[255&n]+Nt[n>>8&255]+Nt[n>>16&255]+Nt[n>>24&255]).toUpperCase()},clamp:function(e,t,i){return Math.max(t,Math.min(i,e))},euclideanModulo:function(e,t){return(e%t+t)%t},mapLinear:function(e,t,i,n,r){return n+(e-t)*(r-n)/(i-t)},lerp:function(e,t,i){return(1-i)*e+i*t},smoothstep:function(e,t,i){return e<=t?0:e>=i?1:(e=(e-t)/(i-t))*e*(3-2*e)},smootherstep:function(e,t,i){return e<=t?0:e>=i?1:(e=(e-t)/(i-t))*e*e*(e*(6*e-15)+10)},randInt:function(e,t){return e+Math.floor(Math.random()*(t-e+1))},randFloat:function(e,t){return e+Math.random()*(t-e)},randFloatSpread:function(e){return e*(.5-Math.random())},degToRad:function(e){return e*Ft.DEG2RAD},radToDeg:function(e){return e*Ft.RAD2DEG},isPowerOfTwo:function(e){return 0==(e&e-1)&&0!==e},ceilPowerOfTwo:function(e){return Math.pow(2,Math.ceil(Math.log(e)/Math.LN2))},floorPowerOfTwo:function(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))},setQuaternionFromProperEuler:function(e,t,i,n,r){const s=Math.cos,o=Math.sin,a=s(i/2),c=o(i/2),l=s((t+n)/2),h=o((t+n)/2),u=s((t-n)/2),d=o((t-n)/2),f=s((n-t)/2),m=o((n-t)/2);switch(r){case"XYX":e.set(a*h,c*u,c*d,a*l);break;case"YZY":e.set(c*d,a*h,c*u,a*l);break;case"ZXZ":e.set(c*u,c*d,a*h,a*l);break;case"XZX":e.set(a*h,c*m,c*f,a*l);break;case"YXY":e.set(c*f,a*h,c*m,a*l);break;case"ZYZ":e.set(c*m,c*f,a*h,a*l);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}}};function zt(e=0,t=0){this.x=e,this.y=t}function Ut(){this.elements=[1,0,0,0,1,0,0,0,1],arguments.length>0&&console.error("THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.")}let $t;Object.defineProperties(zt.prototype,{width:{get:function(){return this.x},set:function(e){this.x=e}},height:{get:function(){return this.y},set:function(e){this.y=e}}}),Object.assign(zt.prototype,{isVector2:!0,set:function(e,t){return this.x=e,this.y=t,this},setScalar:function(e){return this.x=e,this.y=e,this},setX:function(e){return this.x=e,this},setY:function(e){return this.y=e,this},setComponent:function(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:function(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}},clone:function(){return new this.constructor(this.x,this.y)},copy:function(e){return this.x=e.x,this.y=e.y,this},add:function(e,t){return void 0!==t?(console.warn("THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(e,t)):(this.x+=e.x,this.y+=e.y,this)},addScalar:function(e){return this.x+=e,this.y+=e,this},addVectors:function(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this},addScaledVector:function(e,t){return this.x+=e.x*t,this.y+=e.y*t,this},sub:function(e,t){return void 0!==t?(console.warn("THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(e,t)):(this.x-=e.x,this.y-=e.y,this)},subScalar:function(e){return this.x-=e,this.y-=e,this},subVectors:function(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this},multiply:function(e){return this.x*=e.x,this.y*=e.y,this},multiplyScalar:function(e){return this.x*=e,this.y*=e,this},divide:function(e){return this.x/=e.x,this.y/=e.y,this},divideScalar:function(e){return this.multiplyScalar(1/e)},applyMatrix3:function(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:function(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this},max:function(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this},clamp:function(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:function(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:function(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))},floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this},negate:function(){return this.x=-this.x,this.y=-this.y,this},dot:function(e){return this.x*e.x+this.y*e.y},cross:function(e){return this.x*e.y-this.y*e.x},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},manhattanLength:function(){return Math.abs(this.x)+Math.abs(this.y)},normalize:function(){return this.divideScalar(this.length()||1)},angle:function(){return Math.atan2(-this.y,-this.x)+Math.PI},distanceTo:function(e){return Math.sqrt(this.distanceToSquared(e))},distanceToSquared:function(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i},manhattanDistanceTo:function(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)},setLength:function(e){return this.normalize().multiplyScalar(e)},lerp:function(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this},lerpVectors:function(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this},equals:function(e){return e.x===this.x&&e.y===this.y},fromArray:function(e,t){return void 0===t&&(t=0),this.x=e[t],this.y=e[t+1],this},toArray:function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e},fromBufferAttribute:function(e,t,i){return void 0!==i&&console.warn("THREE.Vector2: offset has been removed from .fromBufferAttribute()."),this.x=e.getX(t),this.y=e.getY(t),this},rotateAround:function(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:function(){return this.x=Math.random(),this.y=Math.random(),this}}),Object.assign(Ut.prototype,{isMatrix3:!0,set:function(e,t,i,n,r,s,o,a,c){const l=this.elements;return l[0]=e,l[1]=n,l[2]=o,l[3]=t,l[4]=r,l[5]=a,l[6]=i,l[7]=s,l[8]=c,this},identity:function(){return this.set(1,0,0,0,1,0,0,0,1),this},clone:function(){return(new this.constructor).fromArray(this.elements)},copy:function(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:function(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this},setFromMatrix4:function(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:function(e){return this.multiplyMatrices(this,e)},premultiply:function(e){return this.multiplyMatrices(e,this)},multiplyMatrices:function(e,t){const i=e.elements,n=t.elements,r=this.elements,s=i[0],o=i[3],a=i[6],c=i[1],l=i[4],h=i[7],u=i[2],d=i[5],f=i[8],m=n[0],p=n[3],g=n[6],v=n[1],y=n[4],x=n[7],b=n[2],_=n[5],w=n[8];return r[0]=s*m+o*v+a*b,r[3]=s*p+o*y+a*_,r[6]=s*g+o*x+a*w,r[1]=c*m+l*v+h*b,r[4]=c*p+l*y+h*_,r[7]=c*g+l*x+h*w,r[2]=u*m+d*v+f*b,r[5]=u*p+d*y+f*_,r[8]=u*g+d*x+f*w,this},multiplyScalar:function(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:function(){const e=this.elements,t=e[0],i=e[1],n=e[2],r=e[3],s=e[4],o=e[5],a=e[6],c=e[7],l=e[8];return t*s*l-t*o*c-i*r*l+i*o*a+n*r*c-n*s*a},getInverse:function(e,t){void 0!==t&&console.warn("THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate.");const i=e.elements,n=this.elements,r=i[0],s=i[1],o=i[2],a=i[3],c=i[4],l=i[5],h=i[6],u=i[7],d=i[8],f=d*c-l*u,m=l*h-d*a,p=u*a-c*h,g=r*f+s*m+o*p;if(0===g)return this.set(0,0,0,0,0,0,0,0,0);const v=1/g;return n[0]=f*v,n[1]=(o*u-d*s)*v,n[2]=(l*s-o*c)*v,n[3]=m*v,n[4]=(d*r-o*h)*v,n[5]=(o*a-l*r)*v,n[6]=p*v,n[7]=(s*h-u*r)*v,n[8]=(c*r-s*a)*v,this},transpose:function(){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:function(e){return this.setFromMatrix4(e).getInverse(this).transpose()},transposeIntoArray:function(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:function(e,t,i,n,r,s,o){const a=Math.cos(r),c=Math.sin(r);this.set(i*a,i*c,-i*(a*s+c*o)+s+e,-n*c,n*a,-n*(-c*s+a*o)+o+t,0,0,1)},scale:function(e,t){const i=this.elements;return i[0]*=e,i[3]*=e,i[6]*=e,i[1]*=t,i[4]*=t,i[7]*=t,this},rotate:function(e){const t=Math.cos(e),i=Math.sin(e),n=this.elements,r=n[0],s=n[3],o=n[6],a=n[1],c=n[4],l=n[7];return n[0]=t*r+i*a,n[3]=t*s+i*c,n[6]=t*o+i*l,n[1]=-i*r+t*a,n[4]=-i*s+t*c,n[7]=-i*o+t*l,this},translate:function(e,t){const i=this.elements;return i[0]+=e*i[2],i[3]+=e*i[5],i[6]+=e*i[8],i[1]+=t*i[2],i[4]+=t*i[5],i[7]+=t*i[8],this},equals:function(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:function(e,t){void 0===t&&(t=0);for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this},toArray:function(e,t){void 0===e&&(e=[]),void 0===t&&(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}});const Gt=function(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===$t&&($t=document.createElementNS("http://www.w3.org/1999/xhtml","canvas")),$t.width=e.width,$t.height=e.height;const i=$t.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),t=$t}return t.width>2048||t.height>2048?t.toDataURL("image/jpeg",.6):t.toDataURL("image/png")};let Vt=0;function Ht(e,t,i,n,r,s,o,a,c,l){Object.defineProperty(this,"id",{value:Vt++}),this.uuid=Ft.generateUUID(),this.name="",this.image=void 0!==e?e:Ht.DEFAULT_IMAGE,this.mipmaps=[],this.mapping=void 0!==t?t:Ht.DEFAULT_MAPPING,this.wrapS=void 0!==i?i:ie,this.wrapT=void 0!==n?n:ie,this.magFilter=void 0!==r?r:ae,this.minFilter=void 0!==s?s:le,this.anisotropy=void 0!==c?c:1,this.format=void 0!==o?o:Ae,this.internalFormat=null,this.type=void 0!==a?a:he,this.offset=new zt(0,0),this.repeat=new zt(1,1),this.center=new zt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Ut,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.encoding=void 0!==l?l:_t,this.version=0,this.onUpdate=null}function jt(e=0,t=0,i=0,n=1){this.x=e,this.y=t,this.z=i,this.w=n}function Wt(e,t,i){this.width=e,this.height=t,this.scissor=new jt(0,0,e,t),this.scissorTest=!1,this.viewport=new jt(0,0,e,t),i=i||{},this.texture=new Ht(void 0,i.mapping,i.wrapS,i.wrapT,i.magFilter,i.minFilter,i.format,i.type,i.anisotropy,i.encoding),this.texture.image={},this.texture.image.width=e,this.texture.image.height=t,this.texture.generateMipmaps=void 0!==i.generateMipmaps&&i.generateMipmaps,this.texture.minFilter=void 0!==i.minFilter?i.minFilter:ae,this.depthBuffer=void 0===i.depthBuffer||i.depthBuffer,this.stencilBuffer=void 0===i.stencilBuffer||i.stencilBuffer,this.depthTexture=void 0!==i.depthTexture?i.depthTexture:null}function qt(e=0,t=0,i=0,n=1){this._x=e,this._y=t,this._z=i,this._w=n}Ht.DEFAULT_IMAGE=void 0,Ht.DEFAULT_MAPPING=300,Ht.prototype=Object.assign(Object.create(Bt.prototype),{constructor:Ht,isTexture:!0,updateMatrix:function(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)},clone:function(){return(new this.constructor).copy(this)},copy:function(e){return this.name=e.name,this.image=e.image,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.encoding=e.encoding,this},toJSON:function(e){const t=void 0===e||"string"==typeof e;if(!t&&void 0!==e.textures[this.uuid])return e.textures[this.uuid];const i={metadata:{version:4.5,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,mapping:this.mapping,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,type:this.type,encoding:this.encoding,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};if(void 0!==this.image){const n=this.image;if(void 0===n.uuid&&(n.uuid=Ft.generateUUID()),!t&&void 0===e.images[n.uuid]){let t;if(Array.isArray(n)){t=[];for(let e=0,i=n.length;e1)switch(this.wrapS){case te:e.x=e.x-Math.floor(e.x);break;case ie:e.x=e.x<0?0:1;break;case ne: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 te:e.y=e.y-Math.floor(e.y);break;case ie:e.y=e.y<0?0:1;break;case ne: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}}),Object.defineProperty(Ht.prototype,"needsUpdate",{set:function(e){!0===e&&this.version++}}),Object.defineProperties(jt.prototype,{width:{get:function(){return this.z},set:function(e){this.z=e}},height:{get:function(){return this.w},set:function(e){this.w=e}}}),Object.assign(jt.prototype,{isVector4:!0,set:function(e,t,i,n){return this.x=e,this.y=t,this.z=i,this.w=n,this},setScalar:function(e){return this.x=e,this.y=e,this.z=e,this.w=e,this},setX:function(e){return this.x=e,this},setY:function(e){return this.y=e,this},setZ:function(e){return this.z=e,this},setW:function(e){return this.w=e,this},setComponent:function(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:function(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:function(){return new this.constructor(this.x,this.y,this.z,this.w)},copy:function(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:function(e,t){return void 0!==t?(console.warn("THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(e,t)):(this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this)},addScalar:function(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this},addVectors:function(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:function(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:function(e,t){return void 0!==t?(console.warn("THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(e,t)):(this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this)},subScalar:function(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this},subVectors:function(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},multiplyScalar:function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},applyMatrix4:function(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:function(e){return this.multiplyScalar(1/e)},setAxisAngleFromQuaternion:function(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:function(e){let t,i,n,r;const s=.01,o=.1,a=e.elements,c=a[0],l=a[4],h=a[8],u=a[1],d=a[5],f=a[9],m=a[2],p=a[6],g=a[10];if(Math.abs(l-u)a&&e>v?ev?a=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,o=Math.sin(o*s)/r}const r=o*i;if(a=a*e+u*r,c=c*e+d*r,l=l*e+f*r,h=h*e+m*r,e===1-o){const e=1/Math.sqrt(a*a+c*c+l*l+h*h);a*=e,c*=e,l*=e,h*=e}}e[t]=a,e[t+1]=c,e[t+2]=l,e[t+3]=h},multiplyQuaternionsFlat:function(e,t,i,n,r,s){const o=i[n],a=i[n+1],c=i[n+2],l=i[n+3],h=r[s],u=r[s+1],d=r[s+2],f=r[s+3];return e[t]=o*f+l*h+a*d-c*u,e[t+1]=a*f+l*u+c*h-o*d,e[t+2]=c*f+l*d+o*u-a*h,e[t+3]=l*f-o*h-a*u-c*d,e}}),Object.defineProperties(qt.prototype,{x:{get:function(){return this._x},set:function(e){this._x=e,this._onChangeCallback()}},y:{get:function(){return this._y},set:function(e){this._y=e,this._onChangeCallback()}},z:{get:function(){return this._z},set:function(e){this._z=e,this._onChangeCallback()}},w:{get:function(){return this._w},set:function(e){this._w=e,this._onChangeCallback()}}}),Object.assign(qt.prototype,{isQuaternion:!0,set:function(e,t,i,n){return this._x=e,this._y=t,this._z=i,this._w=n,this._onChangeCallback(),this},clone:function(){return new this.constructor(this._x,this._y,this._z,this._w)},copy:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this},setFromEuler:function(e,t){if(!e||!e.isEuler)throw new Error("THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.");const i=e._x,n=e._y,r=e._z,s=e.order,o=Math.cos,a=Math.sin,c=o(i/2),l=o(n/2),h=o(r/2),u=a(i/2),d=a(n/2),f=a(r/2);switch(s){case"XYZ":this._x=u*l*h+c*d*f,this._y=c*d*h-u*l*f,this._z=c*l*f+u*d*h,this._w=c*l*h-u*d*f;break;case"YXZ":this._x=u*l*h+c*d*f,this._y=c*d*h-u*l*f,this._z=c*l*f-u*d*h,this._w=c*l*h+u*d*f;break;case"ZXY":this._x=u*l*h-c*d*f,this._y=c*d*h+u*l*f,this._z=c*l*f+u*d*h,this._w=c*l*h-u*d*f;break;case"ZYX":this._x=u*l*h-c*d*f,this._y=c*d*h+u*l*f,this._z=c*l*f-u*d*h,this._w=c*l*h+u*d*f;break;case"YZX":this._x=u*l*h+c*d*f,this._y=c*d*h+u*l*f,this._z=c*l*f-u*d*h,this._w=c*l*h-u*d*f;break;case"XZY":this._x=u*l*h-c*d*f,this._y=c*d*h-u*l*f,this._z=c*l*f+u*d*h,this._w=c*l*h+u*d*f;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+s)}return!1!==t&&this._onChangeCallback(),this},setFromAxisAngle:function(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:function(e){const t=e.elements,i=t[0],n=t[4],r=t[8],s=t[1],o=t[5],a=t[9],c=t[2],l=t[6],h=t[10],u=i+o+h;if(u>0){const e=.5/Math.sqrt(u+1);this._w=.25/e,this._x=(l-a)*e,this._y=(r-c)*e,this._z=(s-n)*e}else if(i>o&&i>h){const e=2*Math.sqrt(1+i-o-h);this._w=(l-a)/e,this._x=.25*e,this._y=(n+s)/e,this._z=(r+c)/e}else if(o>h){const e=2*Math.sqrt(1+o-i-h);this._w=(r-c)/e,this._x=(n+s)/e,this._y=.25*e,this._z=(a+l)/e}else{const e=2*Math.sqrt(1+h-i-o);this._w=(s-n)/e,this._x=(r+c)/e,this._y=(a+l)/e,this._z=.25*e}return this._onChangeCallback(),this},setFromUnitVectors:function(e,t){let i=e.dot(t)+1;return i<1e-6?(i=0,Math.abs(e.x)>Math.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:function(e){return 2*Math.acos(Math.abs(Ft.clamp(this.dot(e),-1,1)))},rotateTowards:function(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},inverse:function(){return this.conjugate()},conjugate:function(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this},dot:function(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w},lengthSq:function(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w},length:function(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)},normalize:function(){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:function(e,t){return void 0!==t?(console.warn("THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead."),this.multiplyQuaternions(e,t)):this.multiplyQuaternions(this,e)},premultiply:function(e){return this.multiplyQuaternions(e,this)},multiplyQuaternions:function(e,t){const i=e._x,n=e._y,r=e._z,s=e._w,o=t._x,a=t._y,c=t._z,l=t._w;return this._x=i*l+s*o+n*c-r*a,this._y=n*l+s*a+r*o-i*c,this._z=r*l+s*c+i*a-n*o,this._w=s*l-i*o-n*a-r*c,this._onChangeCallback(),this},slerp:function(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 o=s*e._w+i*e._x+n*e._y+r*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),o>=1)return this._w=s,this._x=i,this._y=n,this._z=r,this;const a=1-o*o;if(a<=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 c=Math.sqrt(a),l=Math.atan2(c,o),h=Math.sin((1-t)*l)/c,u=Math.sin(t*l)/c;return this._w=s*h+this._w*u,this._x=i*h+this._x*u,this._y=n*h+this._y*u,this._z=r*h+this._z*u,this._onChangeCallback(),this},equals:function(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w},fromArray:function(e,t){return void 0===t&&(t=0),this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this},toArray:function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=0),e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e},fromBufferAttribute:function(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this},_onChange:function(e){return this._onChangeCallback=e,this},_onChangeCallback:function(){}});const Xt=new Zt,Yt=new qt;function Zt(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}Object.assign(Zt.prototype,{isVector3:!0,set:function(e,t,i){return this.x=e,this.y=t,this.z=i,this},setScalar:function(e){return this.x=e,this.y=e,this.z=e,this},setX:function(e){return this.x=e,this},setY:function(e){return this.y=e,this},setZ:function(e){return this.z=e,this},setComponent:function(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:function(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:function(){return new this.constructor(this.x,this.y,this.z)},copy:function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},add:function(e,t){return void 0!==t?(console.warn("THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(e,t)):(this.x+=e.x,this.y+=e.y,this.z+=e.z,this)},addScalar:function(e){return this.x+=e,this.y+=e,this.z+=e,this},addVectors:function(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this},addScaledVector:function(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this},sub:function(e,t){return void 0!==t?(console.warn("THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(e,t)):(this.x-=e.x,this.y-=e.y,this.z-=e.z,this)},subScalar:function(e){return this.x-=e,this.y-=e,this.z-=e,this},subVectors:function(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this},multiply:function(e,t){return void 0!==t?(console.warn("THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead."),this.multiplyVectors(e,t)):(this.x*=e.x,this.y*=e.y,this.z*=e.z,this)},multiplyScalar:function(e){return this.x*=e,this.y*=e,this.z*=e,this},multiplyVectors:function(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this},applyEuler:function(e){return e&&e.isEuler||console.error("THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order."),this.applyQuaternion(Yt.setFromEuler(e))},applyAxisAngle:function(e,t){return this.applyQuaternion(Yt.setFromAxisAngle(e,t))},applyMatrix3:function(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:function(e){return this.applyMatrix3(e).normalize()},applyMatrix4:function(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:function(e){const t=this.x,i=this.y,n=this.z,r=e.x,s=e.y,o=e.z,a=e.w,c=a*t+s*n-o*i,l=a*i+o*t-r*n,h=a*n+r*i-s*t,u=-r*t-s*i-o*n;return this.x=c*a+u*-r+l*-o-h*-s,this.y=l*a+u*-s+h*-r-c*-o,this.z=h*a+u*-o+c*-s-l*-r,this},project:function(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)},unproject:function(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)},transformDirection:function(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:function(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this},divideScalar:function(e){return this.multiplyScalar(1/e)},min:function(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:function(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:function(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:function(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:function(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))},floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this},negate:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},dot:function(e){return this.x*e.x+this.y*e.y+this.z*e.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},manhattanLength:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length()||1)},setLength:function(e){return this.normalize().multiplyScalar(e)},lerp:function(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:function(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:function(e,t){return void 0!==t?(console.warn("THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead."),this.crossVectors(e,t)):this.crossVectors(this,e)},crossVectors:function(e,t){const i=e.x,n=e.y,r=e.z,s=t.x,o=t.y,a=t.z;return this.x=n*a-r*o,this.y=r*s-i*a,this.z=i*o-n*s,this},projectOnVector:function(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:function(e){return Xt.copy(this).projectOnVector(e),this.sub(Xt)},reflect:function(e){return this.sub(Xt.copy(e).multiplyScalar(2*this.dot(e)))},angleTo:function(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(Ft.clamp(i,-1,1))},distanceTo:function(e){return Math.sqrt(this.distanceToSquared(e))},distanceToSquared:function(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:function(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)},setFromSpherical:function(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)},setFromSphericalCoords:function(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:function(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)},setFromCylindricalCoords:function(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this},setFromMatrixPosition:function(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this},setFromMatrixScale:function(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:function(e,t){return this.fromArray(e.elements,4*t)},setFromMatrix3Column:function(e,t){return this.fromArray(e.elements,3*t)},equals:function(e){return e.x===this.x&&e.y===this.y&&e.z===this.z},fromArray:function(e,t){return void 0===t&&(t=0),this.x=e[t],this.y=e[t+1],this.z=e[t+2],this},toArray:function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e},fromBufferAttribute:function(e,t,i){return void 0!==i&&console.warn("THREE.Vector3: offset has been removed from .fromBufferAttribute()."),this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this},random:function(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}});const Kt=new Zt,Qt=new ri,Jt=new Zt(0,0,0),ei=new Zt(1,1,1),ti=new Zt,ii=new Zt,ni=new Zt;function ri(){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],arguments.length>0&&console.error("THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.")}Object.assign(ri.prototype,{isMatrix4:!0,set:function(e,t,i,n,r,s,o,a,c,l,h,u,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]=o,g[13]=a,g[2]=c,g[6]=l,g[10]=h,g[14]=u,g[3]=d,g[7]=f,g[11]=m,g[15]=p,this},identity:function(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this},clone:function(){return(new ri).fromArray(this.elements)},copy:function(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:function(e){const t=this.elements,i=e.elements;return t[12]=i[12],t[13]=i[13],t[14]=i[14],this},extractBasis:function(e,t,i){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this},makeBasis:function(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:function(e){const t=this.elements,i=e.elements,n=1/Kt.setFromMatrixColumn(e,0).length(),r=1/Kt.setFromMatrixColumn(e,1).length(),s=1/Kt.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:function(e){e&&e.isEuler||console.error("THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.");const t=this.elements,i=e.x,n=e.y,r=e.z,s=Math.cos(i),o=Math.sin(i),a=Math.cos(n),c=Math.sin(n),l=Math.cos(r),h=Math.sin(r);if("XYZ"===e.order){const e=s*l,i=s*h,n=o*l,r=o*h;t[0]=a*l,t[4]=-a*h,t[8]=c,t[1]=i+n*c,t[5]=e-r*c,t[9]=-o*a,t[2]=r-e*c,t[6]=n+i*c,t[10]=s*a}else if("YXZ"===e.order){const e=a*l,i=a*h,n=c*l,r=c*h;t[0]=e+r*o,t[4]=n*o-i,t[8]=s*c,t[1]=s*h,t[5]=s*l,t[9]=-o,t[2]=i*o-n,t[6]=r+e*o,t[10]=s*a}else if("ZXY"===e.order){const e=a*l,i=a*h,n=c*l,r=c*h;t[0]=e-r*o,t[4]=-s*h,t[8]=n+i*o,t[1]=i+n*o,t[5]=s*l,t[9]=r-e*o,t[2]=-s*c,t[6]=o,t[10]=s*a}else if("ZYX"===e.order){const e=s*l,i=s*h,n=o*l,r=o*h;t[0]=a*l,t[4]=n*c-i,t[8]=e*c+r,t[1]=a*h,t[5]=r*c+e,t[9]=i*c-n,t[2]=-c,t[6]=o*a,t[10]=s*a}else if("YZX"===e.order){const e=s*a,i=s*c,n=o*a,r=o*c;t[0]=a*l,t[4]=r-e*h,t[8]=n*h+i,t[1]=h,t[5]=s*l,t[9]=-o*l,t[2]=-c*l,t[6]=i*h+n,t[10]=e-r*h}else if("XZY"===e.order){const e=s*a,i=s*c,n=o*a,r=o*c;t[0]=a*l,t[4]=-h,t[8]=c*l,t[1]=e*h+r,t[5]=s*l,t[9]=i*h-n,t[2]=n*h-i,t[6]=o*l,t[10]=r*h+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:function(e){return this.compose(Jt,e,ei)},lookAt:function(e,t,i){const n=this.elements;return ni.subVectors(e,t),0===ni.lengthSq()&&(ni.z=1),ni.normalize(),ti.crossVectors(i,ni),0===ti.lengthSq()&&(1===Math.abs(i.z)?ni.x+=1e-4:ni.z+=1e-4,ni.normalize(),ti.crossVectors(i,ni)),ti.normalize(),ii.crossVectors(ni,ti),n[0]=ti.x,n[4]=ii.x,n[8]=ni.x,n[1]=ti.y,n[5]=ii.y,n[9]=ni.y,n[2]=ti.z,n[6]=ii.z,n[10]=ni.z,this},multiply:function(e,t){return void 0!==t?(console.warn("THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead."),this.multiplyMatrices(e,t)):this.multiplyMatrices(this,e)},premultiply:function(e){return this.multiplyMatrices(e,this)},multiplyMatrices:function(e,t){const i=e.elements,n=t.elements,r=this.elements,s=i[0],o=i[4],a=i[8],c=i[12],l=i[1],h=i[5],u=i[9],d=i[13],f=i[2],m=i[6],p=i[10],g=i[14],v=i[3],y=i[7],x=i[11],b=i[15],_=n[0],w=n[4],S=n[8],A=n[12],M=n[1],C=n[5],P=n[9],T=n[13],I=n[2],E=n[6],D=n[10],L=n[14],R=n[3],k=n[7],O=n[11],B=n[15];return r[0]=s*_+o*M+a*I+c*R,r[4]=s*w+o*C+a*E+c*k,r[8]=s*S+o*P+a*D+c*O,r[12]=s*A+o*T+a*L+c*B,r[1]=l*_+h*M+u*I+d*R,r[5]=l*w+h*C+u*E+d*k,r[9]=l*S+h*P+u*D+d*O,r[13]=l*A+h*T+u*L+d*B,r[2]=f*_+m*M+p*I+g*R,r[6]=f*w+m*C+p*E+g*k,r[10]=f*S+m*P+p*D+g*O,r[14]=f*A+m*T+p*L+g*B,r[3]=v*_+y*M+x*I+b*R,r[7]=v*w+y*C+x*E+b*k,r[11]=v*S+y*P+x*D+b*O,r[15]=v*A+y*T+x*L+b*B,this},multiplyScalar:function(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:function(){const e=this.elements,t=e[0],i=e[4],n=e[8],r=e[12],s=e[1],o=e[5],a=e[9],c=e[13],l=e[2],h=e[6],u=e[10],d=e[14];return e[3]*(+r*a*h-n*c*h-r*o*u+i*c*u+n*o*d-i*a*d)+e[7]*(+t*a*d-t*c*u+r*s*u-n*s*d+n*c*l-r*a*l)+e[11]*(+t*c*h-t*o*d-r*s*h+i*s*d+r*o*l-i*c*l)+e[15]*(-n*o*l-t*a*h+t*o*u+n*s*h-i*s*u+i*a*l)},transpose:function(){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:function(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},getInverse:function(e,t){void 0!==t&&console.warn("THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate.");const i=this.elements,n=e.elements,r=n[0],s=n[1],o=n[2],a=n[3],c=n[4],l=n[5],h=n[6],u=n[7],d=n[8],f=n[9],m=n[10],p=n[11],g=n[12],v=n[13],y=n[14],x=n[15],b=f*y*u-v*m*u+v*h*p-l*y*p-f*h*x+l*m*x,_=g*m*u-d*y*u-g*h*p+c*y*p+d*h*x-c*m*x,w=d*v*u-g*f*u+g*l*p-c*v*p-d*l*x+c*f*x,S=g*f*h-d*v*h-g*l*m+c*v*m+d*l*y-c*f*y,A=r*b+s*_+o*w+a*S;if(0===A)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const M=1/A;return i[0]=b*M,i[1]=(v*m*a-f*y*a-v*o*p+s*y*p+f*o*x-s*m*x)*M,i[2]=(l*y*a-v*h*a+v*o*u-s*y*u-l*o*x+s*h*x)*M,i[3]=(f*h*a-l*m*a-f*o*u+s*m*u+l*o*p-s*h*p)*M,i[4]=_*M,i[5]=(d*y*a-g*m*a+g*o*p-r*y*p-d*o*x+r*m*x)*M,i[6]=(g*h*a-c*y*a-g*o*u+r*y*u+c*o*x-r*h*x)*M,i[7]=(c*m*a-d*h*a+d*o*u-r*m*u-c*o*p+r*h*p)*M,i[8]=w*M,i[9]=(g*f*a-d*v*a-g*s*p+r*v*p+d*s*x-r*f*x)*M,i[10]=(c*v*a-g*l*a+g*s*u-r*v*u-c*s*x+r*l*x)*M,i[11]=(d*l*a-c*f*a-d*s*u+r*f*u+c*s*p-r*l*p)*M,i[12]=S*M,i[13]=(d*v*o-g*f*o+g*s*m-r*v*m-d*s*y+r*f*y)*M,i[14]=(g*l*o-c*v*o-g*s*h+r*v*h+c*s*y-r*l*y)*M,i[15]=(c*f*o-d*l*o+d*s*h-r*f*h-c*s*m+r*l*m)*M,this},scale:function(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:function(){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:function(e,t,i){return this.set(1,0,0,e,0,1,0,t,0,0,1,i,0,0,0,1),this},makeRotationX:function(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:function(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:function(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:function(e,t){const i=Math.cos(t),n=Math.sin(t),r=1-i,s=e.x,o=e.y,a=e.z,c=r*s,l=r*o;return this.set(c*s+i,c*o-n*a,c*a+n*o,0,c*o+n*a,l*o+i,l*a-n*s,0,c*a-n*o,l*a+n*s,r*a*a+i,0,0,0,0,1),this},makeScale:function(e,t,i){return this.set(e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1),this},makeShear:function(e,t,i){return this.set(1,t,i,0,e,1,i,0,e,t,1,0,0,0,0,1),this},compose:function(e,t,i){const n=this.elements,r=t._x,s=t._y,o=t._z,a=t._w,c=r+r,l=s+s,h=o+o,u=r*c,d=r*l,f=r*h,m=s*l,p=s*h,g=o*h,v=a*c,y=a*l,x=a*h,b=i.x,_=i.y,w=i.z;return n[0]=(1-(m+g))*b,n[1]=(d+x)*b,n[2]=(f-y)*b,n[3]=0,n[4]=(d-x)*_,n[5]=(1-(u+g))*_,n[6]=(p+v)*_,n[7]=0,n[8]=(f+y)*w,n[9]=(p-v)*w,n[10]=(1-(u+m))*w,n[11]=0,n[12]=e.x,n[13]=e.y,n[14]=e.z,n[15]=1,this},decompose:function(e,t,i){const n=this.elements;let r=Kt.set(n[0],n[1],n[2]).length(),s=Kt.set(n[4],n[5],n[6]).length(),o=Kt.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],Qt.copy(this);const a=1/r,c=1/s,l=1/o;return Qt.elements[0]*=a,Qt.elements[1]*=a,Qt.elements[2]*=a,Qt.elements[4]*=c,Qt.elements[5]*=c,Qt.elements[6]*=c,Qt.elements[8]*=l,Qt.elements[9]*=l,Qt.elements[10]*=l,t.setFromRotationMatrix(Qt),i.x=r,i.y=s,i.z=o,this},makePerspective:function(e,t,i,n,r,s){void 0===s&&console.warn("THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.");const o=this.elements,a=2*r/(t-e),c=2*r/(i-n),l=(t+e)/(t-e),h=(i+n)/(i-n),u=-(s+r)/(s-r),d=-2*s*r/(s-r);return o[0]=a,o[4]=0,o[8]=l,o[12]=0,o[1]=0,o[5]=c,o[9]=h,o[13]=0,o[2]=0,o[6]=0,o[10]=u,o[14]=d,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this},makeOrthographic:function(e,t,i,n,r,s){const o=this.elements,a=1/(t-e),c=1/(i-n),l=1/(s-r),h=(t+e)*a,u=(i+n)*c,d=(s+r)*l;return o[0]=2*a,o[4]=0,o[8]=0,o[12]=-h,o[1]=0,o[5]=2*c,o[9]=0,o[13]=-u,o[2]=0,o[6]=0,o[10]=-2*l,o[14]=-d,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this},equals:function(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:function(e,t){void 0===t&&(t=0);for(let i=0;i<16;i++)this.elements[i]=e[i+t];return this},toArray:function(e,t){void 0===e&&(e=[]),void 0===t&&(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 si=new ri,oi=new qt;function ai(e=0,t=0,i=0,n=ai.DefaultOrder){this._x=e,this._y=t,this._z=i,this._order=n}function ci(){this.mask=1}ai.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"],ai.DefaultOrder="XYZ",Object.defineProperties(ai.prototype,{x:{get:function(){return this._x},set:function(e){this._x=e,this._onChangeCallback()}},y:{get:function(){return this._y},set:function(e){this._y=e,this._onChangeCallback()}},z:{get:function(){return this._z},set:function(e){this._z=e,this._onChangeCallback()}},order:{get:function(){return this._order},set:function(e){this._order=e,this._onChangeCallback()}}}),Object.assign(ai.prototype,{isEuler:!0,set:function(e,t,i,n){return this._x=e,this._y=t,this._z=i,this._order=n||this._order,this._onChangeCallback(),this},clone:function(){return new this.constructor(this._x,this._y,this._z,this._order)},copy:function(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this},setFromRotationMatrix:function(e,t,i){const n=Ft.clamp,r=e.elements,s=r[0],o=r[4],a=r[8],c=r[1],l=r[5],h=r[9],u=r[2],d=r[6],f=r[10];switch(t=t||this._order){case"XYZ":this._y=Math.asin(n(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,f),this._z=Math.atan2(-o,s)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-n(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,f),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-u,s),this._z=0);break;case"ZXY":this._x=Math.asin(n(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-o,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-n(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-o,l));break;case"YZX":this._z=Math.asin(n(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,s)):(this._x=0,this._y=Math.atan2(a,f));break;case"XZY":this._z=Math.asin(-n(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-h,f),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,!1!==i&&this._onChangeCallback(),this},setFromQuaternion:function(e,t,i){return si.makeRotationFromQuaternion(e),this.setFromRotationMatrix(si,t,i)},setFromVector3:function(e,t){return this.set(e.x,e.y,e.z,t||this._order)},reorder:function(e){return oi.setFromEuler(this),this.setFromQuaternion(oi,e)},equals:function(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order},fromArray:function(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:function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=0),e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e},toVector3:function(e){return e?e.set(this._x,this._y,this._z):new Zt(this._x,this._y,this._z)},_onChange:function(e){return this._onChangeCallback=e,this},_onChangeCallback:function(){}}),Object.assign(ci.prototype,{set:function(e){this.mask=1<1){for(let e=0;e1){for(let e=0;e0){n.children=[];for(let t=0;t0&&(i.geometries=t),n.length>0&&(i.materials=n),r.length>0&&(i.textures=r),o.length>0&&(i.images=o),a.length>0&&(i.shapes=a)}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:function(e){return(new this.constructor).copy(this,e)},copy:function(e,t){if(void 0===t&&(t=!0),this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),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.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.userData=JSON.parse(JSON.stringify(e.userData)),!0===t)for(let t=0;to)return!1}return!0}Object.assign(Ni.prototype,{isBox3:!0,set:function(e,t){return this.min.copy(e),this.max.copy(t),this},setFromArray:function(e){let t=1/0,i=1/0,n=1/0,r=-1/0,s=-1/0,o=-1/0;for(let a=0,c=e.length;ar&&(r=c),l>s&&(s=l),h>o&&(o=h)}return this.min.set(t,i,n),this.max.set(r,s,o),this},setFromBufferAttribute:function(e){let t=1/0,i=1/0,n=1/0,r=-1/0,s=-1/0,o=-1/0;for(let a=0,c=e.count;ar&&(r=c),l>s&&(s=l),h>o&&(o=h)}return this.min.set(t,i,n),this.max.set(r,s,o),this},setFromPoints:function(e){this.makeEmpty();for(let t=0,i=e.length;tthis.max.x||e.ythis.max.y||e.zthis.max.z)},containsBox:function(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:function(e,t){return void 0===t&&(console.warn("THREE.Box3: .getParameter() target is now required"),t=new Zt),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:function(e){return!(e.max.xthis.max.x||e.max.ythis.max.y||e.max.zthis.max.z)},intersectsSphere:function(e){return this.clampPoint(e.center,Mi),Mi.distanceToSquared(e.center)<=e.radius*e.radius},intersectsPlane:function(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:function(e){if(this.isEmpty())return!1;this.getCenter(Ri),ki.subVectors(this.max,Ri),Pi.subVectors(e.a,Ri),Ti.subVectors(e.b,Ri),Ii.subVectors(e.c,Ri),Ei.subVectors(Ti,Pi),Di.subVectors(Ii,Ti),Li.subVectors(Pi,Ii);let t=[0,-Ei.z,Ei.y,0,-Di.z,Di.y,0,-Li.z,Li.y,Ei.z,0,-Ei.x,Di.z,0,-Di.x,Li.z,0,-Li.x,-Ei.y,Ei.x,0,-Di.y,Di.x,0,-Li.y,Li.x,0];return!!Fi(t,Pi,Ti,Ii,ki)&&(t=[1,0,0,0,1,0,0,0,1],!!Fi(t,Pi,Ti,Ii,ki)&&(Oi.crossVectors(Ei,Di),t=[Oi.x,Oi.y,Oi.z],Fi(t,Pi,Ti,Ii,ki)))},clampPoint:function(e,t){return void 0===t&&(console.warn("THREE.Box3: .clampPoint() target is now required"),t=new Zt),t.copy(e).clamp(this.min,this.max)},distanceToPoint:function(e){return Mi.copy(e).clamp(this.min,this.max).sub(e).length()},getBoundingSphere:function(e){return void 0===e&&console.error("THREE.Box3: .getBoundingSphere() target is now required"),this.getCenter(e.center),e.radius=.5*this.getSize(Mi).length(),e},intersect:function(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this},union:function(e){return this.min.min(e.min),this.max.max(e.max),this},applyMatrix4:function(e){return this.isEmpty()||(Ai[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Ai[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Ai[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Ai[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Ai[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Ai[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Ai[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Ai[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Ai)),this},translate:function(e){return this.min.add(e),this.max.add(e),this},equals:function(e){return e.min.equals(this.min)&&e.max.equals(this.max)}});const zi=new Ni;function Ui(e,t){this.center=void 0!==e?e:new Zt,this.radius=void 0!==t?t:-1}Object.assign(Ui.prototype,{set:function(e,t){return this.center.copy(e),this.radius=t,this},setFromPoints:function(e,t){const i=this.center;void 0!==t?i.copy(t):zi.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:function(e){return void 0===e&&(console.warn("THREE.Sphere: .getBoundingBox() target is now required"),e=new Ni),this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)},applyMatrix4:function(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this},translate:function(e){return this.center.add(e),this},equals:function(e){return e.center.equals(this.center)&&e.radius===this.radius}});const $i=new Zt,Gi=new Zt,Vi=new Zt,Hi=new Zt,ji=new Zt,Wi=new Zt,qi=new Zt;function Xi(e,t){this.origin=void 0!==e?e:new Zt,this.direction=void 0!==t?t:new Zt(0,0,-1)}Object.assign(Xi.prototype,{set:function(e,t){return this.origin.copy(e),this.direction.copy(t),this},clone:function(){return(new this.constructor).copy(this)},copy:function(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this},at:function(e,t){return void 0===t&&(console.warn("THREE.Ray: .at() target is now required"),t=new Zt),t.copy(this.direction).multiplyScalar(e).add(this.origin)},lookAt:function(e){return this.direction.copy(e).sub(this.origin).normalize(),this},recast:function(e){return this.origin.copy(this.at(e,$i)),this},closestPointToPoint:function(e,t){void 0===t&&(console.warn("THREE.Ray: .closestPointToPoint() target is now required"),t=new Zt),t.subVectors(e,this.origin);const i=t.dot(this.direction);return i<0?t.copy(this.origin):t.copy(this.direction).multiplyScalar(i).add(this.origin)},distanceToPoint:function(e){return Math.sqrt(this.distanceSqToPoint(e))},distanceSqToPoint:function(e){const t=$i.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):($i.copy(this.direction).multiplyScalar(t).add(this.origin),$i.distanceToSquared(e))},distanceSqToSegment:function(e,t,i,n){Gi.copy(e).add(t).multiplyScalar(.5),Vi.copy(t).sub(e).normalize(),Hi.copy(this.origin).sub(Gi);const r=.5*e.distanceTo(t),s=-this.direction.dot(Vi),o=Hi.dot(this.direction),a=-Hi.dot(Vi),c=Hi.lengthSq(),l=Math.abs(1-s*s);let h,u,d,f;if(l>0)if(h=s*a-o,u=s*o-a,f=r*l,h>=0)if(u>=-f)if(u<=f){const e=1/l;h*=e,u*=e,d=h*(h+s*u+2*o)+u*(s*h+u+2*a)+c}else u=r,h=Math.max(0,-(s*u+o)),d=-h*h+u*(u+2*a)+c;else u=-r,h=Math.max(0,-(s*u+o)),d=-h*h+u*(u+2*a)+c;else u<=-f?(h=Math.max(0,-(-s*r+o)),u=h>0?-r:Math.min(Math.max(-r,-a),r),d=-h*h+u*(u+2*a)+c):u<=f?(h=0,u=Math.min(Math.max(-r,-a),r),d=u*(u+2*a)+c):(h=Math.max(0,-(s*r+o)),u=h>0?r:Math.min(Math.max(-r,-a),r),d=-h*h+u*(u+2*a)+c);else u=s>0?-r:r,h=Math.max(0,-(s*u+o)),d=-h*h+u*(u+2*a)+c;return i&&i.copy(this.direction).multiplyScalar(h).add(this.origin),n&&n.copy(Vi).multiplyScalar(u).add(Gi),d},intersectSphere:function(e,t){$i.subVectors(e.center,this.origin);const i=$i.dot(this.direction),n=$i.dot($i)-i*i,r=e.radius*e.radius;if(n>r)return null;const s=Math.sqrt(r-n),o=i-s,a=i+s;return o<0&&a<0?null:o<0?this.at(a,t):this.at(o,t)},intersectsSphere:function(e){return this.distanceSqToPoint(e.center)<=e.radius*e.radius},distanceToPlane:function(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:function(e,t){const i=this.distanceToPlane(e);return null===i?null:this.at(i,t)},intersectsPlane:function(e){const t=e.distanceToPoint(this.origin);if(0===t)return!0;return e.normal.dot(this.direction)*t<0},intersectBox:function(e,t){let i,n,r,s,o,a;const c=1/this.direction.x,l=1/this.direction.y,h=1/this.direction.z,u=this.origin;return c>=0?(i=(e.min.x-u.x)*c,n=(e.max.x-u.x)*c):(i=(e.max.x-u.x)*c,n=(e.min.x-u.x)*c),l>=0?(r=(e.min.y-u.y)*l,s=(e.max.y-u.y)*l):(r=(e.max.y-u.y)*l,s=(e.min.y-u.y)*l),i>s||r>n?null:((r>i||i!=i)&&(i=r),(s=0?(o=(e.min.z-u.z)*h,a=(e.max.z-u.z)*h):(o=(e.max.z-u.z)*h,a=(e.min.z-u.z)*h),i>a||o>n?null:((o>i||i!=i)&&(i=o),(a=0?i:n,t)))},intersectsBox:function(e){return null!==this.intersectBox(e,$i)},intersectTriangle:function(e,t,i,n,r){ji.subVectors(t,e),Wi.subVectors(i,e),qi.crossVectors(ji,Wi);let s,o=this.direction.dot(qi);if(o>0){if(n)return null;s=1}else{if(!(o<0))return null;s=-1,o=-o}Hi.subVectors(this.origin,e);const a=s*this.direction.dot(Wi.crossVectors(Hi,Wi));if(a<0)return null;const c=s*this.direction.dot(ji.cross(Hi));if(c<0)return null;if(a+c>o)return null;const l=-s*Hi.dot(qi);return l<0?null:this.at(l/o,r)},applyMatrix4:function(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this},equals:function(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}});const Yi=new Zt,Zi=new Zt,Ki=new Ut;function Qi(e,t){this.normal=void 0!==e?e:new Zt(1,0,0),this.constant=void 0!==t?t:0}Object.assign(Qi.prototype,{isPlane:!0,set:function(e,t){return this.normal.copy(e),this.constant=t,this},setComponents:function(e,t,i,n){return this.normal.set(e,t,i),this.constant=n,this},setFromNormalAndCoplanarPoint:function(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this},setFromCoplanarPoints:function(e,t,i){const n=Yi.subVectors(i,t).cross(Zi.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(n,e),this},clone:function(){return(new this.constructor).copy(this)},copy:function(e){return this.normal.copy(e.normal),this.constant=e.constant,this},normalize:function(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this},negate:function(){return this.constant*=-1,this.normal.negate(),this},distanceToPoint:function(e){return this.normal.dot(e)+this.constant},distanceToSphere:function(e){return this.distanceToPoint(e.center)-e.radius},projectPoint:function(e,t){return void 0===t&&(console.warn("THREE.Plane: .projectPoint() target is now required"),t=new Zt),t.copy(this.normal).multiplyScalar(-this.distanceToPoint(e)).add(e)},intersectLine:function(e,t){void 0===t&&(console.warn("THREE.Plane: .intersectLine() target is now required"),t=new Zt);const i=e.delta(Yi),n=this.normal.dot(i);if(0===n)return 0===this.distanceToPoint(e.start)?t.copy(e.start):void 0;const r=-(e.start.dot(this.normal)+this.constant)/n;return r<0||r>1?void 0:t.copy(i).multiplyScalar(r).add(e.start)},intersectsLine:function(e){const t=this.distanceToPoint(e.start),i=this.distanceToPoint(e.end);return t<0&&i>0||i<0&&t>0},intersectsBox:function(e){return e.intersectsPlane(this)},intersectsSphere:function(e){return e.intersectsPlane(this)},coplanarPoint:function(e){return void 0===e&&(console.warn("THREE.Plane: .coplanarPoint() target is now required"),e=new Zt),e.copy(this.normal).multiplyScalar(-this.constant)},applyMatrix4:function(e,t){const i=t||Ki.getNormalMatrix(e),n=this.coplanarPoint(Yi).applyMatrix4(e),r=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(r),this},translate:function(e){return this.constant-=e.dot(this.normal),this},equals:function(e){return e.normal.equals(this.normal)&&e.constant===this.constant}});const Ji=new Zt,en=new Zt,tn=new Zt,nn=new Zt,rn=new Zt,sn=new Zt,on=new Zt,an=new Zt,cn=new Zt,ln=new Zt;function hn(e,t,i){this.a=void 0!==e?e:new Zt,this.b=void 0!==t?t:new Zt,this.c=void 0!==i?i:new Zt}Object.assign(hn,{getNormal:function(e,t,i,n){void 0===n&&(console.warn("THREE.Triangle: .getNormal() target is now required"),n=new Zt),n.subVectors(i,t),Ji.subVectors(e,t),n.cross(Ji);const r=n.lengthSq();return r>0?n.multiplyScalar(1/Math.sqrt(r)):n.set(0,0,0)},getBarycoord:function(e,t,i,n,r){Ji.subVectors(n,t),en.subVectors(i,t),tn.subVectors(e,t);const s=Ji.dot(Ji),o=Ji.dot(en),a=Ji.dot(tn),c=en.dot(en),l=en.dot(tn),h=s*c-o*o;if(void 0===r&&(console.warn("THREE.Triangle: .getBarycoord() target is now required"),r=new Zt),0===h)return r.set(-2,-1,-1);const u=1/h,d=(c*a-o*l)*u,f=(s*l-o*a)*u;return r.set(1-d-f,f,d)},containsPoint:function(e,t,i,n){return hn.getBarycoord(e,t,i,n,nn),nn.x>=0&&nn.y>=0&&nn.x+nn.y<=1},getUV:function(e,t,i,n,r,s,o,a){return this.getBarycoord(e,t,i,n,nn),a.set(0,0),a.addScaledVector(r,nn.x),a.addScaledVector(s,nn.y),a.addScaledVector(o,nn.z),a},isFrontFacing:function(e,t,i,n){return Ji.subVectors(i,t),en.subVectors(e,t),Ji.cross(en).dot(n)<0}}),Object.assign(hn.prototype,{set:function(e,t,i){return this.a.copy(e),this.b.copy(t),this.c.copy(i),this},setFromPointsAndIndices:function(e,t,i,n){return this.a.copy(e[t]),this.b.copy(e[i]),this.c.copy(e[n]),this},clone:function(){return(new this.constructor).copy(this)},copy:function(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this},getArea:function(){return Ji.subVectors(this.c,this.b),en.subVectors(this.a,this.b),.5*Ji.cross(en).length()},getMidpoint:function(e){return void 0===e&&(console.warn("THREE.Triangle: .getMidpoint() target is now required"),e=new Zt),e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)},getNormal:function(e){return hn.getNormal(this.a,this.b,this.c,e)},getPlane:function(e){return void 0===e&&(console.warn("THREE.Triangle: .getPlane() target is now required"),e=new Qi),e.setFromCoplanarPoints(this.a,this.b,this.c)},getBarycoord:function(e,t){return hn.getBarycoord(e,this.a,this.b,this.c,t)},getUV:function(e,t,i,n,r){return hn.getUV(e,this.a,this.b,this.c,t,i,n,r)},containsPoint:function(e){return hn.containsPoint(e,this.a,this.b,this.c)},isFrontFacing:function(e){return hn.isFrontFacing(this.a,this.b,this.c,e)},intersectsBox:function(e){return e.intersectsTriangle(this)},closestPointToPoint:function(e,t){void 0===t&&(console.warn("THREE.Triangle: .closestPointToPoint() target is now required"),t=new Zt);const i=this.a,n=this.b,r=this.c;let s,o;rn.subVectors(n,i),sn.subVectors(r,i),an.subVectors(e,i);const a=rn.dot(an),c=sn.dot(an);if(a<=0&&c<=0)return t.copy(i);cn.subVectors(e,n);const l=rn.dot(cn),h=sn.dot(cn);if(l>=0&&h<=l)return t.copy(n);const u=a*h-l*c;if(u<=0&&a>=0&&l<=0)return s=a/(a-l),t.copy(i).addScaledVector(rn,s);ln.subVectors(e,r);const d=rn.dot(ln),f=sn.dot(ln);if(f>=0&&d<=f)return t.copy(r);const m=d*c-a*f;if(m<=0&&c>=0&&f<=0)return o=c/(c-f),t.copy(i).addScaledVector(sn,o);const p=l*f-d*h;if(p<=0&&h-l>=0&&d-f>=0)return on.subVectors(r,n),o=(h-l)/(h-l+(d-f)),t.copy(n).addScaledVector(on,o);const g=1/(p+m+u);return s=m*g,o=u*g,t.copy(i).addScaledVector(rn,s).addScaledVector(sn,o)},equals:function(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}});const un={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},dn={h:0,s:0,l:0},fn={h:0,s:0,l:0};function mn(e,t,i){return void 0===t&&void 0===i?this.set(e):this.setRGB(e,t,i)}function pn(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}function gn(e){return e<.04045?.0773993808*e:Math.pow(.9478672986*e+.0521327014,2.4)}function vn(e){return e<.0031308?12.92*e:1.055*Math.pow(e,.41666)-.055}function yn(e,t,i,n,r,s){this.a=e,this.b=t,this.c=i,this.normal=n&&n.isVector3?n:new Zt,this.vertexNormals=Array.isArray(n)?n:[],this.color=r&&r.isColor?r:new mn,this.vertexColors=Array.isArray(r)?r:[],this.materialIndex=void 0!==s?s:0}Object.assign(mn.prototype,{isColor:!0,r:1,g:1,b:1,set:function(e){return e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e),this},setScalar:function(e){return this.r=e,this.g=e,this.b=e,this},setHex:function(e){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(255&e)/255,this},setRGB:function(e,t,i){return this.r=e,this.g=t,this.b=i,this},setHSL:function(e,t,i){if(e=Ft.euclideanModulo(e,1),t=Ft.clamp(t,0,1),i=Ft.clamp(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=pn(r,n,e+1/3),this.g=pn(r,n,e),this.b=pn(r,n,e-1/3)}return this},setStyle:function(e){function t(t){void 0!==t&&parseFloat(t)<1&&console.warn("THREE.Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(e)){let e;const n=i[1],r=i[2];switch(n){case"rgb":case"rgba":if(e=/^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(r))return this.r=Math.min(255,parseInt(e[1],10))/255,this.g=Math.min(255,parseInt(e[2],10))/255,this.b=Math.min(255,parseInt(e[3],10))/255,t(e[5]),this;if(e=/^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(r))return this.r=Math.min(100,parseInt(e[1],10))/100,this.g=Math.min(100,parseInt(e[2],10))/100,this.b=Math.min(100,parseInt(e[3],10))/100,t(e[5]),this;break;case"hsl":case"hsla":if(e=/^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(r)){const i=parseFloat(e[1])/360,n=parseInt(e[2],10)/100,r=parseInt(e[3],10)/100;return t(e[5]),this.setHSL(i,n,r)}}}else if(i=/^\#([A-Fa-f0-9]+)$/.exec(e)){const e=i[1],t=e.length;if(3===t)return this.r=parseInt(e.charAt(0)+e.charAt(0),16)/255,this.g=parseInt(e.charAt(1)+e.charAt(1),16)/255,this.b=parseInt(e.charAt(2)+e.charAt(2),16)/255,this;if(6===t)return this.r=parseInt(e.charAt(0)+e.charAt(1),16)/255,this.g=parseInt(e.charAt(2)+e.charAt(3),16)/255,this.b=parseInt(e.charAt(4)+e.charAt(5),16)/255,this}return e&&e.length>0?this.setColorName(e):this},setColorName:function(e){const t=un[e];return void 0!==t?this.setHex(t):console.warn("THREE.Color: Unknown color "+e),this},clone:function(){return new this.constructor(this.r,this.g,this.b)},copy:function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this},copyGammaToLinear:function(e,t){return void 0===t&&(t=2),this.r=Math.pow(e.r,t),this.g=Math.pow(e.g,t),this.b=Math.pow(e.b,t),this},copyLinearToGamma:function(e,t){void 0===t&&(t=2);const i=t>0?1/t:1;return this.r=Math.pow(e.r,i),this.g=Math.pow(e.g,i),this.b=Math.pow(e.b,i),this},convertGammaToLinear:function(e){return this.copyGammaToLinear(this,e),this},convertLinearToGamma:function(e){return this.copyLinearToGamma(this,e),this},copySRGBToLinear:function(e){return this.r=gn(e.r),this.g=gn(e.g),this.b=gn(e.b),this},copyLinearToSRGB:function(e){return this.r=vn(e.r),this.g=vn(e.g),this.b=vn(e.b),this},convertSRGBToLinear:function(){return this.copySRGBToLinear(this),this},convertLinearToSRGB:function(){return this.copyLinearToSRGB(this),this},getHex:function(){return 255*this.r<<16^255*this.g<<8^255*this.b<<0},getHexString:function(){return("000000"+this.getHex().toString(16)).slice(-6)},getHSL:function(e){void 0===e&&(console.warn("THREE.Color: .getHSL() target is now required"),e={h:0,s:0,l:0});const t=this.r,i=this.g,n=this.b,r=Math.max(t,i,n),s=Math.min(t,i,n);let o,a;const c=(s+r)/2;if(s===r)o=0,a=0;else{const e=r-s;switch(a=c<=.5?e/(r+s):e/(2-r-s),r){case t:o=(i-n)/e+(i0&&(i.alphaTest=this.alphaTest),!0===this.premultipliedAlpha&&(i.premultipliedAlpha=this.premultipliedAlpha),!0===this.wireframe&&(i.wireframe=this.wireframe),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(i.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(i.wireframeLinejoin=this.wireframeLinejoin),!0===this.morphTargets&&(i.morphTargets=!0),!0===this.morphNormals&&(i.morphNormals=!0),!0===this.skinning&&(i.skinning=!0),!1===this.visible&&(i.visible=!1),!1===this.toneMapped&&(i.toneMapped=!1),"{}"!==JSON.stringify(this.userData)&&(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:function(){return(new this.constructor).copy(this)},copy:function(e){this.name=e.name,this.fog=e.fog,this.blending=e.blending,this.side=e.side,this.flatShading=e.flatShading,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.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.premultipliedAlpha=e.premultipliedAlpha,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this},dispose:function(){this.dispatchEvent({type:"dispose"})}}),Object.defineProperty(bn.prototype,"needsUpdate",{set:function(e){!0===e&&this.version++}}),_n.prototype=Object.create(bn.prototype),_n.prototype.constructor=_n,_n.prototype.isMeshBasicMaterial=!0,_n.prototype.copy=function(e){return bn.prototype.copy.call(this,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.skinning=e.skinning,this.morphTargets=e.morphTargets,this};const wn=new Zt,Sn=new zt;function An(e,t,i){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.name="",this.array=e,this.itemSize=t,this.count=void 0!==e?e.length/t:0,this.normalized=!0===i,this.usage=Ot,this.updateRange={offset:0,count:-1},this.version=0}function Mn(e,t,i){An.call(this,new Int8Array(e),t,i)}function Cn(e,t,i){An.call(this,new Uint8Array(e),t,i)}function Pn(e,t,i){An.call(this,new Uint8ClampedArray(e),t,i)}function Tn(e,t,i){An.call(this,new Int16Array(e),t,i)}function In(e,t,i){An.call(this,new Uint16Array(e),t,i)}function En(e,t,i){An.call(this,new Int32Array(e),t,i)}function Dn(e,t,i){An.call(this,new Uint32Array(e),t,i)}function Ln(e,t,i){An.call(this,new Float32Array(e),t,i)}function Rn(e,t,i){An.call(this,new Float64Array(e),t,i)}function kn(){this.vertices=[],this.normals=[],this.colors=[],this.uvs=[],this.uvs2=[],this.groups=[],this.morphTargets={},this.skinWeights=[],this.skinIndices=[],this.boundingBox=null,this.boundingSphere=null,this.verticesNeedUpdate=!1,this.normalsNeedUpdate=!1,this.colorsNeedUpdate=!1,this.uvsNeedUpdate=!1,this.groupsNeedUpdate=!1}function On(e){if(0===e.length)return-1/0;let t=e[0];for(let i=1,n=e.length;it&&(t=e[i]);return t}Object.defineProperty(An.prototype,"needsUpdate",{set:function(e){!0===e&&this.version++}}),Object.assign(An.prototype,{isBufferAttribute:!0,onUploadCallback:function(){},setUsage:function(e){return this.usage=e,this},copy:function(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},copyAt:function(e,t,i){e*=this.itemSize,i*=t.itemSize;for(let n=0,r=this.itemSize;n0,s=n[1]&&n[1].length>0,o=e.morphTargets,a=o.length;let c;if(a>0){c=[];for(let e=0;e0){u=[];for(let e=0;e0&&0===t.length&&console.error("THREE.DirectGeometry: Faceless geometries are not supported.");for(let e=0;e65535?Dn:In)(e,1):this.index=e},getAttribute:function(e){return this.attributes[e]},setAttribute:function(e,t){return this.attributes[e]=t,this},deleteAttribute:function(e){return delete this.attributes[e],this},addGroup:function(e,t,i){this.groups.push({start:e,count:t,materialIndex:void 0!==i?i:0})},clearGroups:function(){this.groups=[]},setDrawRange:function(e,t){this.drawRange.start=e,this.drawRange.count=t},applyMatrix4:function(e){const t=this.attributes.position;void 0!==t&&(t.applyMatrix4(e),t.needsUpdate=!0);const i=this.attributes.normal;if(void 0!==i){const t=(new Ut).getNormalMatrix(e);i.applyNormalMatrix(t),i.needsUpdate=!0}const n=this.attributes.tangent;return void 0!==n&&(n.transformDirection(e),n.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this},rotateX:function(e){return Nn.makeRotationX(e),this.applyMatrix4(Nn),this},rotateY:function(e){return Nn.makeRotationY(e),this.applyMatrix4(Nn),this},rotateZ:function(e){return Nn.makeRotationZ(e),this.applyMatrix4(Nn),this},translate:function(e,t,i){return Nn.makeTranslation(e,t,i),this.applyMatrix4(Nn),this},scale:function(e,t,i){return Nn.makeScale(e,t,i),this.applyMatrix4(Nn),this},lookAt:function(e){return Fn.lookAt(e),Fn.updateMatrix(),this.applyMatrix4(Fn.matrix),this},center:function(){return this.computeBoundingBox(),this.boundingBox.getCenter(zn).negate(),this.translate(zn.x,zn.y,zn.z),this},setFromObject:function(e){const t=e.geometry;if(e.isPoints||e.isLine){const e=new Ln(3*t.vertices.length,3),i=new Ln(3*t.colors.length,3);if(this.setAttribute("position",e.copyVector3sArray(t.vertices)),this.setAttribute("color",i.copyColorsArray(t.colors)),t.lineDistances&&t.lineDistances.length===t.vertices.length){const e=new Ln(t.lineDistances.length,1);this.setAttribute("lineDistance",e.copyArray(t.lineDistances))}null!==t.boundingSphere&&(this.boundingSphere=t.boundingSphere.clone()),null!==t.boundingBox&&(this.boundingBox=t.boundingBox.clone())}else e.isMesh&&t&&t.isGeometry&&this.fromGeometry(t);return this},setFromPoints:function(e){const t=[];for(let i=0,n=e.length;i0){const t=new Float32Array(3*e.normals.length);this.setAttribute("normal",new An(t,3).copyVector3sArray(e.normals))}if(e.colors.length>0){const t=new Float32Array(3*e.colors.length);this.setAttribute("color",new An(t,3).copyColorsArray(e.colors))}if(e.uvs.length>0){const t=new Float32Array(2*e.uvs.length);this.setAttribute("uv",new An(t,2).copyVector2sArray(e.uvs))}if(e.uvs2.length>0){const t=new Float32Array(2*e.uvs2.length);this.setAttribute("uv2",new An(t,2).copyVector2sArray(e.uvs2))}this.groups=e.groups;for(const t in e.morphTargets){const i=[],n=e.morphTargets[t];for(let e=0,t=n.length;e0){const t=new Ln(4*e.skinIndices.length,4);this.setAttribute("skinIndex",t.copyVector4sArray(e.skinIndices))}if(e.skinWeights.length>0){const t=new Ln(4*e.skinWeights.length,4);this.setAttribute("skinWeight",t.copyVector4sArray(e.skinWeights))}return null!==e.boundingSphere&&(this.boundingSphere=e.boundingSphere.clone()),null!==e.boundingBox&&(this.boundingBox=e.boundingBox.clone()),this},computeBoundingBox:function(){null===this.boundingBox&&(this.boundingBox=new Ni);const e=this.attributes.position,t=this.morphAttributes.position;if(void 0!==e){if(this.boundingBox.setFromBufferAttribute(e),t)for(let e=0,i=t.length;e0&&(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],r=n.toJSON(e.data);""!==n.name&&(r.name=n.name),e.data.attributes[t]=r}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 o=this.boundingSphere;return null!==o&&(e.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),e},clone:function(){return(new Vn).copy(this)},copy:function(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;ei.far?null:{distance:u,point:or.clone(),object:e}}function lr(e,t,i,n,r,s,o,a,c,l,h,u){qn.fromBufferAttribute(r,l),Xn.fromBufferAttribute(r,h),Yn.fromBufferAttribute(r,u);const d=e.morphTargetInfluences;if(t.morphTargets&&s&&d){Jn.set(0,0,0),er.set(0,0,0),tr.set(0,0,0);for(let e=0,t=s.length;e0){const e=t[i[0]];if(void 0!==e){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,i=e.length;t0&&console.error("THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.")}},raycast:function(e,t){const i=this.geometry,n=this.material,r=this.matrixWorld;if(void 0===n)return;if(null===i.boundingSphere&&i.computeBoundingSphere(),Wn.copy(i.boundingSphere),Wn.applyMatrix4(r),!1===e.ray.intersectsSphere(Wn))return;if(Hn.getInverse(r),jn.copy(e.ray).applyMatrix4(Hn),null!==i.boundingBox&&!1===jn.intersectsBox(i.boundingBox))return;let s;if(i.isBufferGeometry){const r=i.index,o=i.attributes.position,a=i.morphAttributes.position,c=i.morphTargetsRelative,l=i.attributes.uv,h=i.attributes.uv2,u=i.groups,d=i.drawRange;if(null!==r)if(Array.isArray(n))for(let i=0,f=u.length;i0&&(c=l);for(let i=0,l=a.length;i0)for(let e=0;e0&&(this.normalsNeedUpdate=!0)},computeFlatVertexNormals:function(){this.computeFaceNormals();for(let e=0,t=this.faces.length;e0&&(this.normalsNeedUpdate=!0)},computeMorphNormals:function(){for(let e=0,t=this.faces.length;e=0;e--){const t=r[e];this.faces.splice(t,1);for(let e=0,i=this.faceVertexUvs.length;e0,a=t.vertexNormals.length>0,c=1!==t.color.r||1!==t.color.g||1!==t.color.b,f=t.vertexColors.length>0;let m=0;if(m=l(m,0,0),m=l(m,1,n),m=l(m,2,r),m=l(m,3,s),m=l(m,4,o),m=l(m,5,a),m=l(m,6,c),m=l(m,7,f),i.push(m),i.push(t.a,t.b,t.c),i.push(t.materialIndex),s){const t=this.faceVertexUvs[0][e];i.push(d(t[0]),d(t[1]),d(t[2]))}if(o&&i.push(h(t.normal)),a){const e=t.vertexNormals;i.push(h(e[0]),h(e[1]),h(e[2]))}if(c&&i.push(u(t.color)),f){const e=t.vertexColors;i.push(u(e[0]),u(e[1]),u(e[2]))}}function l(e,t,i){return i?e|1<0&&(e.data.colors=s),a.length>0&&(e.data.uvs=[a]),e.data.faces=i,e},clone:function(){return(new mr).copy(this)},copy:function(e){this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.name=e.name;const t=e.vertices;for(let e=0,i=t.length;e0?1:-1,l.push(P.x,P.y,P.z),h.push(a/p),h.push(1-s/g),M+=1}}for(let e=0;e0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader;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},wr.prototype=Object.assign(Object.create(wi.prototype),{constructor:wr,isCamera:!0,copy:function(e,t){return wi.prototype.copy.call(this,e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this},getWorldDirection:function(e){void 0===e&&(console.warn("THREE.Camera: .getWorldDirection() target is now required"),e=new Zt),this.updateMatrixWorld(!0);const t=this.matrixWorld.elements;return e.set(-t[8],-t[9],-t[10]).normalize()},updateMatrixWorld:function(e){wi.prototype.updateMatrixWorld.call(this,e),this.matrixWorldInverse.getInverse(this.matrixWorld)},updateWorldMatrix:function(e,t){wi.prototype.updateWorldMatrix.call(this,e,t),this.matrixWorldInverse.getInverse(this.matrixWorld)},clone:function(){return(new this.constructor).copy(this)}}),Sr.prototype=Object.assign(Object.create(wr.prototype),{constructor:Sr,isPerspectiveCamera:!0,copy:function(e,t){return wr.prototype.copy.call(this,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:function(e){const t=.5*this.getFilmHeight()/e;this.fov=2*Ft.RAD2DEG*Math.atan(t),this.updateProjectionMatrix()},getFocalLength:function(){const e=Math.tan(.5*Ft.DEG2RAD*this.fov);return.5*this.getFilmHeight()/e},getEffectiveFOV:function(){return 2*Ft.RAD2DEG*Math.atan(Math.tan(.5*Ft.DEG2RAD*this.fov)/this.zoom)},getFilmWidth:function(){return this.filmGauge*Math.min(this.aspect,1)},getFilmHeight:function(){return this.filmGauge/Math.max(this.aspect,1)},setViewOffset:function(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:function(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()},updateProjectionMatrix:function(){let e=this.near,t=e*Math.tan(.5*Ft.DEG2RAD*this.fov)/this.zoom,i=2*t,n=this.aspect*i,r=-.5*n,s=this.view;if(null!==this.view&&this.view.enabled){const e=s.fullWidth,o=s.fullHeight;r+=s.offsetX*n/e,t-=s.offsetY*i/o,n*=s.width/e,i*=s.height/o}const o=this.filmOffset;0!==o&&(r+=e*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+n,t,t-i,e,this.far),this.projectionMatrixInverse.getInverse(this.projectionMatrix)},toJSON:function(e){const t=wi.prototype.toJSON.call(this,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}}),Ar.prototype=Object.create(Ht.prototype),Ar.prototype.constructor=Ar,Ar.prototype.isDataTexture=!0;const Mr=new Ui,Cr=new Zt;function Pr(e,t,i,n,r,s){this.planes=[void 0!==e?e:new Qi,void 0!==t?t:new Qi,void 0!==i?i:new Qi,void 0!==n?n:new Qi,void 0!==r?r:new Qi,void 0!==s?s:new Qi]}Object.assign(Pr.prototype,{set:function(e,t,i,n,r,s){const o=this.planes;return o[0].copy(e),o[1].copy(t),o[2].copy(i),o[3].copy(n),o[4].copy(r),o[5].copy(s),this},clone:function(){return(new this.constructor).copy(this)},copy:function(e){const t=this.planes;for(let i=0;i<6;i++)t[i].copy(e.planes[i]);return this},setFromProjectionMatrix:function(e){const t=this.planes,i=e.elements,n=i[0],r=i[1],s=i[2],o=i[3],a=i[4],c=i[5],l=i[6],h=i[7],u=i[8],d=i[9],f=i[10],m=i[11],p=i[12],g=i[13],v=i[14],y=i[15];return t[0].setComponents(o-n,h-a,m-u,y-p).normalize(),t[1].setComponents(o+n,h+a,m+u,y+p).normalize(),t[2].setComponents(o+r,h+c,m+d,y+g).normalize(),t[3].setComponents(o-r,h-c,m-d,y-g).normalize(),t[4].setComponents(o-s,h-l,m-f,y-v).normalize(),t[5].setComponents(o+s,h+l,m+f,y+v).normalize(),this},intersectsObject:function(e){const t=e.geometry;return null===t.boundingSphere&&t.computeBoundingSphere(),Mr.copy(t.boundingSphere).applyMatrix4(e.matrixWorld),this.intersectsSphere(Mr)},intersectsSprite:function(e){return Mr.center.set(0,0,0),Mr.radius=.7071067811865476,Mr.applyMatrix4(e.matrixWorld),this.intersectsSphere(Mr)},intersectsSphere:function(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,Cr.y=n.normal.y>0?e.max.y:e.min.y,Cr.z=n.normal.z>0?e.max.z:e.min.z,n.distanceToPoint(Cr)<0)return!1}return!0},containsPoint:function(e){const t=this.planes;for(let i=0;i<6;i++)if(t[i].distanceToPoint(e)<0)return!1;return!0}});const Tr={common:{diffuse:{value:new mn(15658734)},opacity:{value:1},map:{value:null},uvTransform:{value:new Ut},uv2Transform:{value:new Ut},alphaMap:{value:null}},specularmap:{specularMap:{value:null}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},refractionRatio:{value:.98},maxMipLevel:{value:0}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1}},emissivemap:{emissiveMap:{value:null}},bumpmap:{bumpMap:{value:null},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalScale:{value:new zt(1,1)}},displacementmap:{displacementMap:{value:null},displacementScale:{value:1},displacementBias:{value:0}},roughnessmap:{roughnessMap:{value:null}},metalnessmap:{metalnessMap:{value:null}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new mn(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:{}}},spotShadowMap:{value:[]},spotShadowMatrix:{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:{}}}},points:{diffuse:{value:new mn(15658734)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},uvTransform:{value:new Ut}},sprite:{diffuse:{value:new mn(15658734)},opacity:{value:1},center:{value:new zt(.5,.5)},rotation:{value:0},map:{value:null},alphaMap:{value:null},uvTransform:{value:new Ut}}};function Ir(){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 Er(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){t.isInterleavedBufferAttribute&&(t=t.data);const s=n.get(t);void 0===s?n.set(t,function(t,i){const n=t.array,r=t.usage,s=e.createBuffer();e.bindBuffer(i,s),e.bufferData(i,n,r),t.onUploadCallback();let o=5126;return n instanceof Float32Array?o=5126:n instanceof Float64Array?console.warn("THREE.WebGLAttributes: Unsupported data buffer format: Float64Array."):n instanceof Uint16Array?o=5123:n instanceof Int16Array?o=5122:n instanceof Uint32Array?o=5125:n instanceof Int32Array?o=5124:n instanceof Int8Array?o=5120:n instanceof Uint8Array&&(o=5121),{buffer:s,type:o,bytesPerElement:n.BYTES_PER_ELEMENT,version:t.version}}(t,r)):s.version0.0){distanceFalloff*=pow2(saturate(1.0-pow4(lightDistance/cutoffDistance)));}return distanceFalloff;\n#else\nif(cutoffDistance>0.0&&decayExponent>0.0){return pow(saturate(-lightDistance/cutoffDistance+1.0),decayExponent);}return 1.0;\n#endif\n}vec3 BRDF_Diffuse_Lambert(const in vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}vec3 F_Schlick(const in vec3 specularColor,const in float dotLH){float fresnel=exp2((-5.55473*dotLH-6.98316)*dotLH);return(1.0-specularColor)*fresnel+specularColor;}vec3 F_Schlick_RoughnessDependent(const in vec3 F0,const in float dotNV,const in float roughness){float fresnel=exp2((-5.55473*dotNV-6.98316)*dotNV);vec3 Fr=max(vec3(1.0-roughness),F0)-F0;return Fr*fresnel+F0;}float G_GGX_Smith(const in float alpha,const in float dotNL,const in float dotNV){float a2=pow2(alpha);float gl=dotNL+sqrt(a2+(1.0-a2)*pow2(dotNL));float gv=dotNV+sqrt(a2+(1.0-a2)*pow2(dotNV));return 1.0/(gl*gv);}float G_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);}vec3 BRDF_Specular_GGX(const in IncidentLight incidentLight,const in vec3 viewDir,const in vec3 normal,const in vec3 specularColor,const in float roughness){float alpha=pow2(roughness);vec3 halfDir=normalize(incidentLight.direction+viewDir);float dotNL=saturate(dot(normal,incidentLight.direction));float dotNV=saturate(dot(normal,viewDir));float dotNH=saturate(dot(normal,halfDir));float dotLH=saturate(dot(incidentLight.direction,halfDir));vec3 F=F_Schlick(specularColor,dotLH);float G=G_GGX_SmithCorrelated(alpha,dotNL,dotNV);float D=D_GGX(alpha,dotNH);return F*(G*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);}vec3 BRDF_Specular_GGX_Environment(const in vec3 viewDir,const in vec3 normal,const in vec3 specularColor,const in float roughness){float dotNV=saturate(dot(normal,viewDir));vec2 brdf=integrateSpecularBRDF(dotNV,roughness);return specularColor*brdf.x+brdf.y;}void BRDF_Specular_Multiscattering_Environment(const in GeometricContext geometry,const in vec3 specularColor,const in float roughness,inout vec3 singleScatter,inout vec3 multiScatter){float dotNV=saturate(dot(geometry.normal,geometry.viewDir));vec3 F=F_Schlick_RoughnessDependent(specularColor,dotNV,roughness);vec2 brdf=integrateSpecularBRDF(dotNV,roughness);vec3 FssEss=F*brdf.x+brdf.y;float Ess=brdf.x+brdf.y;float Ems=1.0-Ess;vec3 Favg=specularColor+(1.0-specularColor)*0.047619;vec3 Fms=FssEss*Favg/(1.0-Ems*Favg);singleScatter+=FssEss;multiScatter+=Fms*Ems;}float G_BlinnPhong_Implicit(){return 0.25;}float D_BlinnPhong(const in float shininess,const in float dotNH){return RECIPROCAL_PI*(shininess*0.5+1.0)*pow(dotNH,shininess);}vec3 BRDF_Specular_BlinnPhong(const in IncidentLight incidentLight,const in GeometricContext geometry,const in vec3 specularColor,const in float shininess){vec3 halfDir=normalize(incidentLight.direction+geometry.viewDir);float dotNH=saturate(dot(geometry.normal,halfDir));float dotLH=saturate(dot(incidentLight.direction,halfDir));vec3 F=F_Schlick(specularColor,dotLH);float G=G_BlinnPhong_Implicit();float D=D_BlinnPhong(shininess,dotNH);return F*(G*D);}float GGXRoughnessToBlinnExponent(const in float ggxRoughness){return(2.0/pow2(ggxRoughness+0.0001)-2.0);}float BlinnExponentToGGXRoughness(const in float blinnExponent){return sqrt(2.0/(blinnExponent+2.0));}\n#if defined(USE_SHEEN)\nfloat D_Charlie(float roughness,float NoH){float invAlpha=1.0/roughness;float cos2h=NoH*NoH;float sin2h=max(1.0-cos2h,0.0078125);return(2.0+invAlpha)*pow(sin2h,invAlpha*0.5)/(2.0*PI);}float V_Neubelt(float NoV,float NoL){return saturate(1.0/(4.0*(NoL+NoV-NoL*NoV)));}vec3 BRDF_Specular_Sheen(const in float roughness,const in vec3 L,const in GeometricContext geometry,vec3 specularColor){vec3 N=geometry.normal;vec3 V=geometry.viewDir;vec3 H=normalize(V+L);float dotNH=saturate(dot(N,H));return specularColor*D_Charlie(roughness,dotNH)*V_Neubelt(dot(N,V),dot(N,L));}\n#endif",bumpmap_pars_fragment:"#ifdef USE_BUMPMAP\nuniform sampler2D bumpMap;uniform float bumpScale;vec2 dHdxy_fwd(){vec2 dSTdx=dFdx(vUv);vec2 dSTdy=dFdy(vUv);float Hll=bumpScale*texture2D(bumpMap,vUv).x;float dBx=bumpScale*texture2D(bumpMap,vUv+dSTdx).x-Hll;float dBy=bumpScale*texture2D(bumpMap,vUv+dSTdy).x-Hll;return vec2(dBx,dBy);}vec3 perturbNormalArb(vec3 surf_pos,vec3 surf_norm,vec2 dHdxy){vec3 vSigmaX=vec3(dFdx(surf_pos.x),dFdx(surf_pos.y),dFdx(surf_pos.z));vec3 vSigmaY=vec3(dFdy(surf_pos.x),dFdy(surf_pos.y),dFdy(surf_pos.z));vec3 vN=surf_norm;vec3 R1=cross(vSigmaY,vN);vec3 R2=cross(vN,vSigmaX);float fDet=dot(vSigmaX,R1);fDet*=(float(gl_FrontFacing)*2.0-1.0);vec3 vGrad=sign(fDet)*(dHdxy.x*R1+dHdxy.y*R2);return normalize(abs(fDet)*surf_norm-vGrad);}\n#endif",clipping_planes_fragment:"#if NUM_CLIPPING_PLANES>0\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:"#ifdef USE_COLOR\ndiffuseColor.rgb*=vColor;\n#endif",color_pars_fragment:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_pars_vertex:"#ifdef USE_COLOR\nvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\nvColor.xyz=color.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;}float pow3(const in float x){return x*x*x;}float pow4(const in float x){float x2=x*x;return x2*x2;}float average(const in vec3 color){return dot(color,vec3(0.3333));}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 max3(vec3 v){return max(max(v.x,v.y),v.z);}float 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;};struct GeometricContext{vec3 position;vec3 normal;vec3 viewDir;\n#ifdef CLEARCOAT\nvec3 clearcoatNormal;\n#endif\n};vec3 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);}vec3 projectOnPlane(in vec3 point,in vec3 pointOnPlane,in vec3 planeNormal){float distance=dot(planeNormal,point-pointOnPlane);return-distance*planeNormal+point;}float sideOfPlane(in vec3 point,in vec3 pointOnPlane,in vec3 planeNormal){return sign(dot(point-pointOnPlane,planeNormal));}vec3 linePlaneIntersect(in vec3 pointOnLine,in vec3 lineDirection,in vec3 pointOnPlane,in vec3 planeNormal){return lineDirection*(dot(planeNormal,pointOnPlane-pointOnLine)/dot(planeNormal,lineDirection))+pointOnLine;}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 linearToRelativeLuminance(const in vec3 color){vec3 weights=vec3(0.2126,0.7152,0.0722);return dot(weights,color.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);}",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_maxMipLevel 8.0\n#define cubeUV_minMipLevel 4.0\n#define cubeUV_maxTileSize 256.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);float texelSize=1.0/(3.0*cubeUV_maxTileSize);vec2 uv=getUV(direction,face)*(faceSize-1.0);vec2 f=fract(uv);uv+=0.5-f;if(face>2.0){uv.y+=faceSize;face-=3.0;}uv.x+=face*faceSize;if(mipInt=r1){mip=(r0-roughness)*(m1-m0)/(r0-r1)+m0;}else if(roughness>=r4){mip=(r1-roughness)*(m4-m1)/(r1-r4)+m1;}else if(roughness>=r5){mip=(r4-roughness)*(m5-m4)/(r4-r5)+m4;}else if(roughness>=r6){mip=(r5-roughness)*(m6-m5)/(r5-r6)+m5;}else{mip=-2.0*log2(1.16*roughness);}return mip;}vec4 textureCubeUV(sampler2D envMap,vec3 sampleDir,float roughness){float mip=clamp(roughnessToMip(roughness),m0,cubeUV_maxMipLevel);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,vUv).x*displacementScale+displacementBias);\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\nvec4 emissiveColor=texture2D(emissiveMap,vUv);emissiveColor.rgb=emissiveMapTexelToLinear(emissiveColor).rgb;totalEmissiveRadiance*=emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\nuniform sampler2D emissiveMap;\n#endif",encodings_fragment:"gl_FragColor=linearToOutputTexel(gl_FragColor);",encodings_pars_fragment:"vec4 LinearToLinear(in vec4 value){return value;}vec4 GammaToLinear(in vec4 value,in float gammaFactor){return vec4(pow(value.rgb,vec3(gammaFactor)),value.a);}vec4 LinearToGamma(in vec4 value,in float gammaFactor){return vec4(pow(value.rgb,vec3(1.0/gammaFactor)),value.a);}vec4 sRGBToLinear(in vec4 value){return vec4(mix(pow(value.rgb*0.9478672986+vec3(0.0521327014),vec3(2.4)),value.rgb*0.0773993808,vec3(lessThanEqual(value.rgb,vec3(0.04045)))),value.a);}vec4 LinearTosRGB(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 RGBEToLinear(in vec4 value){return vec4(value.rgb*exp2(value.a*255.0-128.0),1.0);}vec4 LinearToRGBE(in vec4 value){float maxComponent=max(max(value.r,value.g),value.b);float fExp=clamp(ceil(log2(maxComponent)),-128.0,127.0);return vec4(value.rgb/exp2(fExp),(fExp+128.0)/255.0);}vec4 RGBMToLinear(in vec4 value,in float maxRange){return vec4(value.rgb*value.a*maxRange,1.0);}vec4 LinearToRGBM(in vec4 value,in float maxRange){float maxRGB=max(value.r,max(value.g,value.b));float M=clamp(maxRGB/maxRange,0.0,1.0);M=ceil(M*255.0)/255.0;return vec4(value.rgb/(M*maxRange),M);}vec4 RGBDToLinear(in vec4 value,in float maxRange){return vec4(value.rgb*((maxRange/255.0)/value.a),1.0);}vec4 LinearToRGBD(in vec4 value,in float maxRange){float maxRGB=max(value.r,max(value.g,value.b));float D=max(maxRange/maxRGB,1.0);D=clamp(floor(D)/255.0,0.0,1.0);return vec4(value.rgb*(D*(255.0/maxRange)),D);}const mat3 cLogLuvM=mat3(0.2209,0.3390,0.4184,0.1138,0.6780,0.7319,0.0102,0.1130,0.2969);vec4 LinearToLogLuv(in vec4 value){vec3 Xp_Y_XYZp=cLogLuvM*value.rgb;Xp_Y_XYZp=max(Xp_Y_XYZp,vec3(1e-6,1e-6,1e-6));vec4 vResult;vResult.xy=Xp_Y_XYZp.xy/Xp_Y_XYZp.z;float Le=2.0*log2(Xp_Y_XYZp.y)+127.0;vResult.w=fract(Le);vResult.z=(Le-(floor(vResult.w*255.0))/255.0)/255.0;return vResult;}const mat3 cLogLuvInverseM=mat3(6.0014,-2.7008,-1.7996,-1.3320,3.1029,-5.7721,0.3008,-1.0882,5.6268);vec4 LogLuvToLinear(in vec4 value){float Le=value.z*255.0+value.w;vec3 Xp_Y_XYZp;Xp_Y_XYZp.y=exp2((Le-127.0)/2.0);Xp_Y_XYZp.z=Xp_Y_XYZp.y/value.y;Xp_Y_XYZp.x=value.x*Xp_Y_XYZp.z;vec3 vRGB=cLogLuvInverseM*Xp_Y_XYZp.rgb;return vec4(max(vRGB,0.0),1.0);}",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#elif defined(ENVMAP_TYPE_CUBE_UV)\nvec4 envColor=textureCubeUV(envMap,reflectVec,0.0);\n#elif defined(ENVMAP_TYPE_EQUIREC)\nreflectVec=normalize(reflectVec);vec2 sampleUV=equirectUv(reflectVec);vec4 envColor=texture2D(envMap,sampleUV);\n#else\nvec4 envColor=vec4(0.0);\n#endif\n#ifndef ENVMAP_TYPE_CUBE_UV\nenvColor=envMapTexelToLinear(envColor);\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;uniform int maxMipLevel;\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)\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)\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:"#if defined(USE_ENVMAP)\n#ifdef ENVMAP_MODE_REFRACTION\nuniform float refractionRatio;\n#endif\nvec3 getLightProbeIndirectIrradiance(const in GeometricContext geometry,const in int maxMIPLevel){vec3 worldNormal=inverseTransformDirection(geometry.normal,viewMatrix);\n#ifdef ENVMAP_TYPE_CUBE\nvec3 queryVec=vec3(flipEnvMap*worldNormal.x,worldNormal.yz);\n#ifdef TEXTURE_LOD_EXT\nvec4 envMapColor=textureCubeLodEXT(envMap,queryVec,float(maxMIPLevel));\n#else\nvec4 envMapColor=textureCube(envMap,queryVec,float(maxMIPLevel));\n#endif\nenvMapColor.rgb=envMapTexelToLinear(envMapColor).rgb;\n#elif defined(ENVMAP_TYPE_CUBE_UV)\nvec4 envMapColor=textureCubeUV(envMap,worldNormal,1.0);\n#else\nvec4 envMapColor=vec4(0.0);\n#endif\nreturn PI*envMapColor.rgb*envMapIntensity;}float getSpecularMIPLevel(const in float roughness,const in int maxMIPLevel){float maxMIPLevelScalar=float(maxMIPLevel);float sigma=PI*roughness*roughness/(1.0+roughness);float desiredMIPLevel=maxMIPLevelScalar+log2(sigma);return clamp(desiredMIPLevel,0.0,maxMIPLevelScalar);}vec3 getLightProbeIndirectRadiance(const in vec3 viewDir,const in vec3 normal,const in float roughness,const in int maxMIPLevel){\n#ifdef ENVMAP_MODE_REFLECTION\nvec3 reflectVec=reflect(-viewDir,normal);reflectVec=normalize(mix(reflectVec,normal,roughness*roughness));\n#else\nvec3 reflectVec=refract(-viewDir,normal,refractionRatio);\n#endif\nreflectVec=inverseTransformDirection(reflectVec,viewMatrix);float specularMIPLevel=getSpecularMIPLevel(roughness,maxMIPLevel);\n#ifdef ENVMAP_TYPE_CUBE\nvec3 queryReflectVec=vec3(flipEnvMap*reflectVec.x,reflectVec.yz);\n#ifdef TEXTURE_LOD_EXT\nvec4 envMapColor=textureCubeLodEXT(envMap,queryReflectVec,specularMIPLevel);\n#else\nvec4 envMapColor=textureCube(envMap,queryReflectVec,specularMIPLevel);\n#endif\nenvMapColor.rgb=envMapTexelToLinear(envMapColor).rgb;\n#elif defined(ENVMAP_TYPE_CUBE_UV)\nvec4 envMapColor=textureCubeUV(envMap,reflectVec,roughness);\n#elif defined(ENVMAP_TYPE_EQUIREC)\nvec2 sampleUV=equirectUv(reflectVec);\n#ifdef TEXTURE_LOD_EXT\nvec4 envMapColor=texture2DLodEXT(envMap,sampleUV,specularMIPLevel);\n#else\nvec4 envMapColor=texture2D(envMap,sampleUV,specularMIPLevel);\n#endif\nenvMapColor.rgb=envMapTexelToLinear(envMapColor).rgb;\n#endif\nreturn envMapColor.rgb*envMapIntensity;}\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\nfogDepth=-mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\nvarying float fogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n#ifdef FOG_EXP2\nfloat fogFactor=1.0-exp(-fogDensity*fogDensity*fogDepth*fogDepth);\n#else\nfloat fogFactor=smoothstep(fogNear,fogFar,fogDepth);\n#endif\ngl_FragColor.rgb=mix(gl_FragColor.rgb,fogColor,fogFactor);\n#endif",fog_pars_fragment:"#ifdef USE_FOG\nuniform vec3 fogColor;varying float fogDepth;\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 texture2D(gradientMap,coord).rgb;\n#else\nreturn(coord.x<0.7)?vec3(0.7):vec3(1.0);\n#endif\n}",lightmap_fragment:"#ifdef USE_LIGHTMAP\nvec4 lightMapTexel=texture2D(lightMap,vUv2);reflectedLight.indirectDiffuse+=PI*lightMapTexelToLinear(lightMapTexel).rgb*lightMapIntensity;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\nuniform sampler2D lightMap;uniform float lightMapIntensity;\n#endif",lights_lambert_vertex:"vec3 diffuse=vec3(1.0);GeometricContext geometry;geometry.position=mvPosition.xyz;geometry.normal=normalize(transformedNormal);geometry.viewDir=(isOrthographic)?vec3(0,0,1):normalize(-mvPosition.xyz);GeometricContext backGeometry;backGeometry.position=geometry.position;backGeometry.normal=-geometry.normal;backGeometry.viewDir=geometry.viewDir;vLightFront=vec3(0.0);vIndirectFront=vec3(0.0);\n#ifdef DOUBLE_SIDED\nvLightBack=vec3(0.0);vIndirectBack=vec3(0.0);\n#endif\nIncidentLight directLight;float dotNL;vec3 directLightColor_Diffuse;vIndirectFront+=getAmbientLightIrradiance(ambientLightColor);vIndirectFront+=getLightProbeIrradiance(lightProbe,geometry);\n#ifdef DOUBLE_SIDED\nvIndirectBack+=getAmbientLightIrradiance(ambientLightColor);vIndirectBack+=getLightProbeIrradiance(lightProbe,backGeometry);\n#endif\n#if NUM_POINT_LIGHTS>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\n#pragma unroll_loop_start\nfor(int i=0;i0\nstruct DirectionalLight{vec3 direction;vec3 color;};uniform DirectionalLight directionalLights[NUM_DIR_LIGHTS];void getDirectionalDirectLightIrradiance(const in DirectionalLight directionalLight,const in GeometricContext geometry,out IncidentLight directLight){directLight.color=directionalLight.color;directLight.direction=directionalLight.direction;directLight.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 getPointDirectLightIrradiance(const in PointLight pointLight,const in GeometricContext geometry,out IncidentLight directLight){vec3 lVector=pointLight.position-geometry.position;directLight.direction=normalize(lVector);float lightDistance=length(lVector);directLight.color=pointLight.color;directLight.color*=punctualLightIntensityToIrradianceFactor(lightDistance,pointLight.distance,pointLight.decay);directLight.visible=(directLight.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 getSpotDirectLightIrradiance(const in SpotLight spotLight,const in GeometricContext geometry,out IncidentLight directLight){vec3 lVector=spotLight.position-geometry.position;directLight.direction=normalize(lVector);float lightDistance=length(lVector);float angleCos=dot(directLight.direction,spotLight.direction);if(angleCos>spotLight.coneCos){float spotEffect=smoothstep(spotLight.coneCos,spotLight.penumbraCos,angleCos);directLight.color=spotLight.color;directLight.color*=spotEffect*punctualLightIntensityToIrradianceFactor(lightDistance,spotLight.distance,spotLight.decay);directLight.visible=true;}else{directLight.color=vec3(0.0);directLight.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 GeometricContext geometry){float dotNL=dot(geometry.normal,hemiLight.direction);float hemiDiffuseWeight=0.5*dotNL+0.5;vec3 irradiance=mix(hemiLight.groundColor,hemiLight.skyColor,hemiDiffuseWeight);\n#ifndef PHYSICALLY_CORRECT_LIGHTS\nirradiance*=PI;\n#endif\nreturn irradiance;}\n#endif",lights_toon_fragment:"ToonMaterial material;material.diffuseColor=diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#endif\nstruct ToonMaterial{vec3 diffuseColor;};void RE_Direct_Toon(const in IncidentLight directLight,const in GeometricContext geometry,const in ToonMaterial material,inout ReflectedLight reflectedLight){vec3 irradiance=getGradientIrradiance(geometry.normal,directLight.direction)*directLight.color;\n#ifndef PHYSICALLY_CORRECT_LIGHTS\nirradiance*=PI;\n#endif\nreflectedLight.directDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}void RE_IndirectDiffuse_Toon(const in vec3 irradiance,const in GeometricContext geometry,const in ToonMaterial material,inout ReflectedLight reflectedLight){reflectedLight.indirectDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#define RE_Direct RE_Direct_Toon\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD(material)(0)",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;\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial{vec3 diffuseColor;vec3 specularColor;float specularShininess;float specularStrength;};void RE_Direct_BlinnPhong(const in IncidentLight directLight,const in GeometricContext geometry,const in BlinnPhongMaterial material,inout ReflectedLight reflectedLight){float dotNL=saturate(dot(geometry.normal,directLight.direction));vec3 irradiance=dotNL*directLight.color;\n#ifndef PHYSICALLY_CORRECT_LIGHTS\nirradiance*=PI;\n#endif\nreflectedLight.directDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);reflectedLight.directSpecular+=irradiance*BRDF_Specular_BlinnPhong(directLight,geometry,material.specularColor,material.specularShininess)*material.specularStrength;}void RE_IndirectDiffuse_BlinnPhong(const in vec3 irradiance,const in GeometricContext geometry,const in BlinnPhongMaterial material,inout ReflectedLight reflectedLight){reflectedLight.indirectDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD(material)(0)",lights_physical_fragment:"PhysicalMaterial material;material.diffuseColor=diffuseColor.rgb*(1.0-metalnessFactor);vec3 dxy=max(abs(dFdx(geometryNormal)),abs(dFdy(geometryNormal)));float geometryRoughness=max(max(dxy.x,dxy.y),dxy.z);material.specularRoughness=max(roughnessFactor,0.0525);material.specularRoughness+=geometryRoughness;material.specularRoughness=min(material.specularRoughness,1.0);\n#ifdef REFLECTIVITY\nmaterial.specularColor=mix(vec3(MAXIMUM_SPECULAR_COEFFICIENT*pow2(reflectivity)),diffuseColor.rgb,metalnessFactor);\n#else\nmaterial.specularColor=mix(vec3(DEFAULT_SPECULAR_COEFFICIENT),diffuseColor.rgb,metalnessFactor);\n#endif\n#ifdef CLEARCOAT\nmaterial.clearcoat=clearcoat;material.clearcoatRoughness=clearcoatRoughness;\n#ifdef USE_CLEARCOATMAP\nmaterial.clearcoat*=texture2D(clearcoatMap,vUv).x;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\nmaterial.clearcoatRoughness*=texture2D(clearcoatRoughnessMap,vUv).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_SHEEN\nmaterial.sheenColor=sheen;\n#endif",lights_physical_pars_fragment:"struct PhysicalMaterial{vec3 diffuseColor;float specularRoughness;vec3 specularColor;\n#ifdef CLEARCOAT\nfloat clearcoat;float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\nvec3 sheenColor;\n#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearcoatDHRApprox(const in float roughness,const in float dotNL){return DEFAULT_SPECULAR_COEFFICIENT+(1.0-DEFAULT_SPECULAR_COEFFICIENT)*(pow(1.0-dotNL,5.0)*pow(1.0-roughness,2.0));}\n#if NUM_RECT_AREA_LIGHTS>0\nvoid RE_Direct_RectArea_Physical(const in RectAreaLight rectAreaLight,const in GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight){vec3 normal=geometry.normal;vec3 viewDir=geometry.viewDir;vec3 position=geometry.position;vec3 lightPos=rectAreaLight.position;vec3 halfWidth=rectAreaLight.halfWidth;vec3 halfHeight=rectAreaLight.halfHeight;vec3 lightColor=rectAreaLight.color;float roughness=material.specularRoughness;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 GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight){float dotNL=saturate(dot(geometry.normal,directLight.direction));vec3 irradiance=dotNL*directLight.color;\n#ifndef PHYSICALLY_CORRECT_LIGHTS\nirradiance*=PI;\n#endif\n#ifdef CLEARCOAT\nfloat ccDotNL=saturate(dot(geometry.clearcoatNormal,directLight.direction));vec3 ccIrradiance=ccDotNL*directLight.color;\n#ifndef PHYSICALLY_CORRECT_LIGHTS\nccIrradiance*=PI;\n#endif\nfloat clearcoatDHR=material.clearcoat*clearcoatDHRApprox(material.clearcoatRoughness,ccDotNL);reflectedLight.directSpecular+=ccIrradiance*material.clearcoat*BRDF_Specular_GGX(directLight,geometry.viewDir,geometry.clearcoatNormal,vec3(DEFAULT_SPECULAR_COEFFICIENT),material.clearcoatRoughness);\n#else\nfloat clearcoatDHR=0.0;\n#endif\n#ifdef USE_SHEEN\nreflectedLight.directSpecular+=(1.0-clearcoatDHR)*irradiance*BRDF_Specular_Sheen(material.specularRoughness,directLight.direction,geometry,material.sheenColor);\n#else\nreflectedLight.directSpecular+=(1.0-clearcoatDHR)*irradiance*BRDF_Specular_GGX(directLight,geometry.viewDir,geometry.normal,material.specularColor,material.specularRoughness);\n#endif\nreflectedLight.directDiffuse+=(1.0-clearcoatDHR)*irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}void RE_IndirectDiffuse_Physical(const in vec3 irradiance,const in GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight){reflectedLight.indirectDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}void RE_IndirectSpecular_Physical(const in vec3 radiance,const in vec3 irradiance,const in vec3 clearcoatRadiance,const in GeometricContext geometry,const in PhysicalMaterial material,inout ReflectedLight reflectedLight){\n#ifdef CLEARCOAT\nfloat ccDotNV=saturate(dot(geometry.clearcoatNormal,geometry.viewDir));reflectedLight.indirectSpecular+=clearcoatRadiance*material.clearcoat*BRDF_Specular_GGX_Environment(geometry.viewDir,geometry.clearcoatNormal,vec3(DEFAULT_SPECULAR_COEFFICIENT),material.clearcoatRoughness);float ccDotNL=ccDotNV;float clearcoatDHR=material.clearcoat*clearcoatDHRApprox(material.clearcoatRoughness,ccDotNL);\n#else\nfloat clearcoatDHR=0.0;\n#endif\nfloat clearcoatInv=1.0-clearcoatDHR;vec3 singleScattering=vec3(0.0);vec3 multiScattering=vec3(0.0);vec3 cosineWeightedIrradiance=irradiance*RECIPROCAL_PI;BRDF_Specular_Multiscattering_Environment(geometry,material.specularColor,material.specularRoughness,singleScattering,multiScattering);vec3 diffuse=material.diffuseColor*(1.0-(singleScattering+multiScattering));reflectedLight.indirectSpecular+=clearcoatInv*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:"GeometricContext geometry;geometry.position=-vViewPosition;geometry.normal=normal;geometry.viewDir=(isOrthographic)?vec3(0,0,1):normalize(vViewPosition);\n#ifdef CLEARCOAT\ngeometry.clearcoatNormal=clearcoatNormal;\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;\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\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];varying vec4 vSpotShadowCoord[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;bvec4 inFrustumVec=bvec4(shadowCoord.x>=0.0,shadowCoord.x<=1.0,shadowCoord.y>=0.0,shadowCoord.y<=1.0);bool inFrustum=all(inFrustumVec);bvec2 frustumTestVec=bvec2(inFrustum,shadowCoord.z<=1.0);bool frustumTest=all(frustumTestVec);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:"#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\nuniform mat4 spotShadowMatrix[NUM_SPOT_LIGHT_SHADOWS];varying vec4 vSpotShadowCoord[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 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:"#ifdef USE_SHADOWMAP\n#if NUM_DIR_LIGHT_SHADOWS>0||NUM_SPOT_LIGHT_SHADOWS>0||NUM_POINT_LIGHT_SHADOWS>0\nvec3 shadowWorldNormal=inverseTransformDirection(transformedNormal,viewMatrix);vec4 shadowWorldPosition;\n#endif\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;i\n#include \n}",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);}",cube_frag:"#include \nuniform float opacity;varying vec3 vWorldDirection;\n#include \nvoid main(){vec3 vReflect=vWorldDirection;\n#include \ngl_FragColor=envColor;gl_FragColor.a*=opacity;\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;}",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 \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 \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}",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;}",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 \nvoid main(){\n#include \nvec4 diffuseColor=vec4(1.0);\n#include \n#include \n#include \nfloat dist=length(vWorldPosition-referencePosition);dist=(dist-nearDistance)/(farDistance-nearDistance);dist=saturate(dist);gl_FragColor=packDepthToRGBA(dist);}",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;}",equirect_frag:"uniform sampler2D tEquirect;varying vec3 vWorldDirection;\n#include \nvoid main(){vec3 direction=normalize(vWorldDirection);vec2 sampleUV=equirectUv(direction);vec4 texColor=texture2D(tEquirect,sampleUV);gl_FragColor=mapTexelToLinear(texColor);\n#include \n#include \n}",equirect_vert:"varying vec3 vWorldDirection;\n#include \nvoid main(){vWorldDirection=transformDirection(position,modelMatrix);\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 \nvoid main(){\n#include \nif(mod(vLineDistance,totalSize)>dashSize){discard;}vec3 outgoingLight=vec3(0.0);vec4 diffuseColor=vec4(diffuse,opacity);\n#include \n#include \noutgoingLight=diffuseColor.rgb;gl_FragColor=vec4(outgoingLight,diffuseColor.a);\n#include \n#include \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 \nvoid main(){vLineDistance=scale*lineDistance;\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 \nReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));\n#ifdef USE_LIGHTMAP\nvec4 lightMapTexel=texture2D(lightMap,vUv2);reflectedLight.indirectDiffuse+=lightMapTexelToLinear(lightMapTexel).rgb*lightMapIntensity;\n#else\nreflectedLight.indirectDiffuse+=vec3(1.0);\n#endif\n#include \nreflectedLight.indirectDiffuse*=diffuseColor.rgb;vec3 outgoingLight=reflectedLight.indirectDiffuse;\n#include \ngl_FragColor=vec4(outgoingLight,diffuseColor.a);\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 \n#include \nvoid main(){\n#include \n#include \n#include \n#include \n#ifdef USE_ENVMAP\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}",meshlambert_frag:"uniform vec3 diffuse;uniform vec3 emissive;uniform float opacity;varying vec3 vLightFront;varying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\nvarying vec3 vLightBack;varying vec3 vIndirectBack;\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 \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#ifdef DOUBLE_SIDED\nreflectedLight.indirectDiffuse+=(gl_FrontFacing)?vIndirectFront:vIndirectBack;\n#else\nreflectedLight.indirectDiffuse+=vIndirectFront;\n#endif\n#include \nreflectedLight.indirectDiffuse*=BRDF_Diffuse_Lambert(diffuseColor.rgb);\n#ifdef DOUBLE_SIDED\nreflectedLight.directDiffuse=(gl_FrontFacing)?vLightFront:vLightBack;\n#else\nreflectedLight.directDiffuse=vLightFront;\n#endif\nreflectedLight.directDiffuse*=BRDF_Diffuse_Lambert(diffuseColor.rgb)*getShadowMask();\n#include \nvec3 outgoingLight=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+totalEmissiveRadiance;\n#include \ngl_FragColor=vec4(outgoingLight,diffuseColor.a);\n#include \n#include \n#include \n#include \n#include \n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vLightFront;varying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\nvarying vec3 vLightBack;varying vec3 vIndirectBack;\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 \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 \n#include \n#include \n}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;uniform float opacity;uniform sampler2D matcap;varying vec3 vViewPosition;\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 \nvoid main(){\n#include \nvec4 diffuseColor=vec4(diffuse,opacity);\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);matcapColor=matcapTexelToLinear(matcapColor);\n#else\nvec4 matcapColor=vec4(1.0);\n#endif\nvec3 outgoingLight=diffuseColor.rgb*matcapColor.rgb;gl_FragColor=vec4(outgoingLight,diffuseColor.a);\n#include \n#include \n#include \n#include \n#include \n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\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 \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#ifndef FLAT_SHADED\nvNormal=normalize(transformedNormal);\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvViewPosition=-mvPosition.xyz;}",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 \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 \nvec3 outgoingLight=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+totalEmissiveRadiance;gl_FragColor=vec4(outgoingLight,diffuseColor.a);\n#include \n#include \n#include \n#include \n#include \n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\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 \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#ifndef FLAT_SHADED\nvNormal=normalize(transformedNormal);\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvViewPosition=-mvPosition.xyz;\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 \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+reflectedLight.directSpecular+reflectedLight.indirectSpecular+totalEmissiveRadiance;\n#include \ngl_FragColor=vec4(outgoingLight,diffuseColor.a);\n#include \n#include \n#include \n#include \n#include \n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\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 \nvoid main(){\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#ifndef FLAT_SHADED\nvNormal=normalize(transformedNormal);\n#endif\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}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n#define REFLECTIVITY\n#define CLEARCOAT\n#define TRANSPARENCY\n#endif\nuniform vec3 diffuse;uniform vec3 emissive;uniform float roughness;uniform float metalness;uniform float opacity;\n#ifdef TRANSPARENCY\nuniform float transparency;\n#endif\n#ifdef REFLECTIVITY\nuniform float reflectivity;\n#endif\n#ifdef CLEARCOAT\nuniform float clearcoat;uniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\nuniform vec3 sheen;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#ifdef USE_TANGENT\nvarying vec3 vTangent;varying vec3 vBitangent;\n#endif\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 \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 \nvec3 outgoingLight=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+reflectedLight.directSpecular+reflectedLight.indirectSpecular+totalEmissiveRadiance;\n#ifdef TRANSPARENCY\ndiffuseColor.a*=saturate(1.-transparency+linearToRelativeLuminance(reflectedLight.directSpecular+reflectedLight.indirectSpecular));\n#endif\ngl_FragColor=vec4(outgoingLight,diffuseColor.a);\n#include \n#include \n#include \n#include \n#include \n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#ifdef USE_TANGENT\nvarying vec3 vTangent;varying vec3 vBitangent;\n#endif\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#ifndef FLAT_SHADED\nvNormal=normalize(transformedNormal);\n#ifdef USE_TANGENT\nvTangent=normalize(transformedTangent);vBitangent=normalize(cross(vNormal,vTangent)*tangent.w);\n#endif\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvViewPosition=-mvPosition.xyz;\n#include \n#include \n#include \n}",normal_frag:"#define NORMAL\nuniform float opacity;\n#if defined(FLAT_SHADED)||defined(USE_BUMPMAP)||defined(TANGENTSPACE_NORMALMAP)\nvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#ifdef USE_TANGENT\nvarying vec3 vTangent;varying vec3 vBitangent;\n#endif\n#endif\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);}",normal_vert:"#define NORMAL\n#if defined(FLAT_SHADED)||defined(USE_BUMPMAP)||defined(TANGENTSPACE_NORMALMAP)\nvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\nvarying vec3 vNormal;\n#ifdef USE_TANGENT\nvarying vec3 vTangent;varying vec3 vBitangent;\n#endif\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 \n#include \n#include \n#ifndef FLAT_SHADED\nvNormal=normalize(transformedNormal);\n#ifdef USE_TANGENT\nvTangent=normalize(transformedTangent);vBitangent=normalize(cross(vNormal,vTangent)*tangent.w);\n#endif\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#if defined(FLAT_SHADED)||defined(USE_BUMPMAP)||defined(TANGENTSPACE_NORMALMAP)\nvViewPosition=-mvPosition.xyz;\n#endif\n}",points_frag:"uniform vec3 diffuse;uniform float opacity;\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 \noutgoingLight=diffuseColor.rgb;gl_FragColor=vec4(outgoingLight,diffuseColor.a);\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 \nvoid main(){\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}",shadow_frag:"uniform vec3 color;uniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main(){gl_FragColor=vec4(color,opacity*(1.0-getShadowMask()));\n#include \n#include \n#include \n}",shadow_vert:"#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}",sprite_frag:"uniform vec3 diffuse;uniform float opacity;\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 \noutgoingLight=diffuseColor.rgb;gl_FragColor=vec4(outgoingLight,diffuseColor.a);\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}"},kr={basic:{uniforms:vr([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.fog]),vertexShader:Rr.meshbasic_vert,fragmentShader:Rr.meshbasic_frag},lambert:{uniforms:vr([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.fog,Tr.lights,{emissive:{value:new mn(0)}}]),vertexShader:Rr.meshlambert_vert,fragmentShader:Rr.meshlambert_frag},phong:{uniforms:vr([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.fog,Tr.lights,{emissive:{value:new mn(0)},specular:{value:new mn(1118481)},shininess:{value:30}}]),vertexShader:Rr.meshphong_vert,fragmentShader:Rr.meshphong_frag},standard:{uniforms:vr([Tr.common,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.roughnessmap,Tr.metalnessmap,Tr.fog,Tr.lights,{emissive:{value:new mn(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Rr.meshphysical_vert,fragmentShader:Rr.meshphysical_frag},toon:{uniforms:vr([Tr.common,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.gradientmap,Tr.fog,Tr.lights,{emissive:{value:new mn(0)}}]),vertexShader:Rr.meshtoon_vert,fragmentShader:Rr.meshtoon_frag},matcap:{uniforms:vr([Tr.common,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.fog,{matcap:{value:null}}]),vertexShader:Rr.meshmatcap_vert,fragmentShader:Rr.meshmatcap_frag},points:{uniforms:vr([Tr.points,Tr.fog]),vertexShader:Rr.points_vert,fragmentShader:Rr.points_frag},dashed:{uniforms:vr([Tr.common,Tr.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Rr.linedashed_vert,fragmentShader:Rr.linedashed_frag},depth:{uniforms:vr([Tr.common,Tr.displacementmap]),vertexShader:Rr.depth_vert,fragmentShader:Rr.depth_frag},normal:{uniforms:vr([Tr.common,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,{opacity:{value:1}}]),vertexShader:Rr.normal_vert,fragmentShader:Rr.normal_frag},sprite:{uniforms:vr([Tr.sprite,Tr.fog]),vertexShader:Rr.sprite_vert,fragmentShader:Rr.sprite_frag},background:{uniforms:{uvTransform:{value:new Ut},t2D:{value:null}},vertexShader:Rr.background_vert,fragmentShader:Rr.background_frag},cube:{uniforms:vr([Tr.envmap,{opacity:{value:1}}]),vertexShader:Rr.cube_vert,fragmentShader:Rr.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Rr.equirect_vert,fragmentShader:Rr.equirect_frag},distanceRGBA:{uniforms:vr([Tr.common,Tr.displacementmap,{referencePosition:{value:new Zt},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Rr.distanceRGBA_vert,fragmentShader:Rr.distanceRGBA_frag},shadow:{uniforms:vr([Tr.lights,Tr.fog,{color:{value:new mn(0)},opacity:{value:1}}]),vertexShader:Rr.shadow_vert,fragmentShader:Rr.shadow_frag}};function Or(e,t,i,n){const r=new mn(0);let s,o,l=0,h=null,u=0,d=null;function f(e,i){t.buffers.color.setClear(e.r,e.g,e.b,i,n)}return{getClearColor:function(){return r},setClearColor:function(e,t){r.set(e),l=void 0!==t?t:1,f(r,l)},getClearAlpha:function(){return l},setClearAlpha:function(e){l=e,f(r,l)},render:function(t,n,m,p){let g=!0===n.isScene?n.background:null;const v=e.xr,y=v.getSession&&v.getSession();if(y&&"additive"===y.environmentBlendMode&&(g=null),null===g?f(r,l):g&&g.isColor&&(f(g,1),p=!0),(e.autoClear||p)&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),g&&(g.isCubeTexture||g.isWebGLCubeRenderTarget||g.mapping===J)){void 0===o&&(o=new ar(new pr(1,1,1),new _r({name:"BackgroundCubeMaterial",uniforms:gr(kr.cube.uniforms),vertexShader:kr.cube.vertexShader,fragmentShader:kr.cube.fragmentShader,side:c,depthTest:!1,depthWrite:!1,fog:!1})),o.geometry.deleteAttribute("normal"),o.geometry.deleteAttribute("uv"),o.onBeforeRender=function(e,t,i){this.matrixWorld.copyPosition(i.matrixWorld)},Object.defineProperty(o.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(o));const n=g.isWebGLCubeRenderTarget?g.texture:g;o.material.uniforms.envMap.value=n,o.material.uniforms.flipEnvMap.value=n.isCubeTexture?-1:1,h===g&&u===n.version&&d===e.toneMapping||(o.material.needsUpdate=!0,h=g,u=n.version,d=e.toneMapping),t.unshift(o,o.geometry,o.material,0,0,null)}else g&&g.isTexture&&(void 0===s&&(s=new ar(new Lr(2,2),new _r({name:"BackgroundMaterial",uniforms:gr(kr.background.uniforms),vertexShader:kr.background.vertexShader,fragmentShader:kr.background.fragmentShader,side:a,depthTest:!1,depthWrite:!1,fog:!1})),s.geometry.deleteAttribute("normal"),Object.defineProperty(s.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(s)),s.material.uniforms.t2D.value=g,!0===g.matrixAutoUpdate&&g.updateMatrix(),s.material.uniforms.uvTransform.value.copy(g.matrix),h===g&&u===g.version&&d===e.toneMapping||(s.material.needsUpdate=!0,h=g,u=g.version,d=e.toneMapping),t.unshift(s,s.geometry,s.material,0,0,null))}}}function Br(e,t,i,n){const r=e.getParameter(34921),s=n.isWebGL2?null:t.get("OES_vertex_array_object"),o=n.isWebGL2||null!==s,a={},c=d(null);let l=c;function h(t){return n.isWebGL2?e.bindVertexArray(t):s.bindVertexArrayOES(t)}function u(t){return n.isWebGL2?e.deleteVertexArray(t):s.deleteVertexArrayOES(t)}function d(e){const t=[],i=[],n=[];for(let e=0;e=0){const s=c[t];if(void 0!==s){const t=s.normalized,r=s.itemSize,o=i.get(s);if(void 0===o)continue;const c=o.buffer,l=o.type,h=o.bytesPerElement;if(s.isInterleavedBufferAttribute){const i=s.data,o=i.stride,u=s.offset;i&&i.isInstancedInterleavedBuffer?(p(n,i.meshPerAttribute),void 0===a._maxInstanceCount&&(a._maxInstanceCount=i.meshPerAttribute*i.count)):m(n),e.bindBuffer(34962,c),v(n,r,l,t,o*h,u*h)}else s.isInstancedBufferAttribute?(p(n,s.meshPerAttribute),void 0===a._maxInstanceCount&&(a._maxInstanceCount=s.meshPerAttribute*s.count)):m(n),e.bindBuffer(34962,c),v(n,r,l,t,0,0)}else if("instanceMatrix"===t){const t=i.get(r.instanceMatrix);if(void 0===t)continue;const s=t.buffer,o=t.type;p(n+0,1),p(n+1,1),p(n+2,1),p(n+3,1),e.bindBuffer(34962,s),e.vertexAttribPointer(n+0,4,o,!1,64,0),e.vertexAttribPointer(n+1,4,o,!1,64,16),e.vertexAttribPointer(n+2,4,o,!1,64,32),e.vertexAttribPointer(n+3,4,o,!1,64,48)}else if(void 0!==h){const i=h[t];if(void 0!==i)switch(i.length){case 2:e.vertexAttrib2fv(n,i);break;case 3:e.vertexAttrib3fv(n,i);break;case 4:e.vertexAttrib4fv(n,i);break;default:e.vertexAttrib1fv(n,i)}}}}g()}(r,c,u,y),null!==x&&e.bindBuffer(34963,i.get(x).buffer))},reset:y,resetDefaultState:x,dispose:function(){y();for(const e in a){const t=a[e];for(const e in t){const i=t[e];for(const e in i)u(i[e].object),delete i[e];delete t[e]}delete a[e]}},releaseStatesOfGeometry:function(e){if(void 0===a[e.id])return;const t=a[e.id];for(const e in t){const i=t[e];for(const e in i)u(i[e].object),delete i[e];delete t[e]}delete a[e.id]},releaseStatesOfProgram:function(e){for(const t in a){const i=a[t];if(void 0===i[e.id])continue;const n=i[e.id];for(const e in n)u(n[e].object),delete n[e];delete i[e.id]}},initAttributes:f,enableAttribute:m,disableUnusedAttributes:g}}function Nr(e,t,i,n){const r=n.isWebGL2;let s;this.setMode=function(e){s=e},this.render=function(t,n){e.drawArrays(s,t,n),i.update(n,s)},this.renderInstances=function(n,o,a,c){if(0===c)return;let l,h;if(r)l=e,h="drawArraysInstanced";else if(l=t.get("ANGLE_instanced_arrays"),h="drawArraysInstancedANGLE",null===l)return void console.error("THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.");l[h](s,o,a,c),i.update(a,s,c)}}function Fr(e,t,i){let n;function r(t){if("highp"===t){if(e.getShaderPrecisionFormat(35633,36338).precision>0&&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&&e instanceof WebGL2RenderingContext||"undefined"!=typeof WebGL2ComputeRenderingContext&&e instanceof WebGL2ComputeRenderingContext;let o=void 0!==i.precision?i.precision:"highp";const a=r(o);a!==o&&(console.warn("THREE.WebGLRenderer:",o,"not supported, using",a,"instead."),o=a);const c=!0===i.logarithmicDepthBuffer,l=e.getParameter(34930),h=e.getParameter(35660),u=e.getParameter(3379),d=e.getParameter(34076),f=e.getParameter(34921),m=e.getParameter(36347),p=e.getParameter(36348),g=e.getParameter(36349),v=h>0,y=s||!!t.get("OES_texture_float");return{isWebGL2:s,getMaxAnisotropy:function(){if(void 0!==n)return n;const i=t.get("EXT_texture_filter_anisotropic");return n=null!==i?e.getParameter(i.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0,n},getMaxPrecision:r,precision:o,logarithmicDepthBuffer:c,maxTextures:l,maxVertexTextures:h,maxTextureSize:u,maxCubemapSize:d,maxAttributes:f,maxVertexUniforms:m,maxVaryings:p,maxFragmentUniforms:g,vertexTextures:v,floatFragmentTextures:y,floatVertexTextures:v&&y,maxSamples:s?e.getParameter(36183):0}}function zr(){const e=this;let t=null,i=0,n=!1,r=!1;const s=new Qi,o=new Ut,a={value:null,needsUpdate:!1};function c(){a.value!==t&&(a.value=t,a.needsUpdate=i>0),e.numPlanes=i,e.numIntersection=0}function l(t,i,n,r){let c=null!==t?t.length:0,l=null;if(0!==c){if(l=a.value,!0!==r||null===l){const e=n+4*c,r=i.matrixWorldInverse;o.getNormalMatrix(r),(null===l||l.length65535?Dn:In)(i,1);a.version=o;const c=s.get(e);c&&t.remove(c),s.set(e,a)}return{get:function(e,t){let n=r.get(t);return n||(t.addEventListener("dispose",o),t.isBufferGeometry?n=t:t.isGeometry&&(void 0===t._bufferGeometry&&(t._bufferGeometry=(new Vn).setFromObject(e)),n=t._bufferGeometry),r.set(t,n),i.memory.geometries++,n)},update:function(e){const i=e.attributes;for(const e in i)t.update(i[e],34962);const n=e.morphAttributes;for(const e in n){const i=n[e];for(let e=0,n=i.length;e0)return e;let r=t*i,s=ts[r];if(void 0===s&&(s=new Float32Array(r),ts[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 as(e,t){if(e.length!==t.length)return!1;for(let i=0,n=e.length;i/gm;function no(e){return e.replace(io,ro)}function ro(e,t){const i=Rr[t];if(void 0===i)throw new Error("Can not resolve #include <"+t+">");return no(i)}const so=/#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g,oo=/#pragma unroll_loop_start[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g;function ao(e){return e.replace(oo,lo).replace(so,co)}function co(e,t,i,n){return console.warn("WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead."),lo(e,t,i,n)}function lo(e,t,i,n){let r="";for(let e=parseInt(t);e0?e.gammaFactor:1,g=i.isWebGL2?"":function(e){return[e.extensionDerivatives||e.envMapCubeUV||e.bumpMap||e.tangentSpaceNormalMap||e.clearcoatNormalMap||e.flatShading||"physical"===e.shaderID?"#extension GL_OES_standard_derivatives : enable":"",(e.extensionFragDepth||e.logarithmicDepthBuffer)&&e.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",e.extensionDrawBuffers&&e.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(e.extensionShaderTextureLOD||e.envMap)&&e.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter(Js).join("\n")}(i),v=function(e){const t=[];for(const i in e){const n=e[i];!1!==n&&t.push("#define "+i+" "+n)}return t.join("\n")}(c),y=a.createProgram();let x,b;if(i.isRawShaderMaterial?(x=[v].filter(Js).join("\n"),x.length>0&&(x+="\n"),b=[g,v].filter(Js).join("\n"),b.length>0&&(b+="\n")):(x=[ho(i),"#define SHADER_NAME "+i.shaderName,v,i.instancing?"#define USE_INSTANCING":"",i.supportsVertexTextures?"#define VERTEX_TEXTURES":"","#define GAMMA_FACTOR "+p,"#define MAX_BONES "+i.maxBones,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+f:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMap&&i.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",i.normalMap&&i.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.displacementMap&&i.supportsVertexTextures?"#define USE_DISPLACEMENTMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.vertexTangents?"#define USE_TANGENT":"",i.vertexColors?"#define USE_COLOR":"",i.vertexUvs?"#define USE_UV":"",i.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",i.flatShading?"#define FLAT_SHADED":"",i.skinning?"#define USE_SKINNING":"",i.useVertexTexture?"#define BONE_TEXTURE":"",i.morphTargets?"#define USE_MORPHTARGETS":"",i.morphNormals&&!1===i.flatShading?"#define USE_MORPHNORMALS":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+u:"",i.sizeAttenuation?"#define USE_SIZEATTENUATION":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.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"," attribute mat4 instanceMatrix;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#ifdef USE_COLOR","\tattribute vec3 color;","#endif","#ifdef USE_MORPHTARGETS","\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(Js).join("\n"),b=[g,ho(i),"#define SHADER_NAME "+i.shaderName,v,i.alphaTest?"#define ALPHATEST "+i.alphaTest+(i.alphaTest%1?"":".0"):"","#define GAMMA_FACTOR "+p,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.matcap?"#define USE_MATCAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+d:"",i.envMap?"#define "+f:"",i.envMap?"#define "+m:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMap&&i.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",i.normalMap&&i.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.sheen?"#define USE_SHEEN":"",i.vertexTangents?"#define USE_TANGENT":"",i.vertexColors?"#define USE_COLOR":"",i.vertexUvs?"#define USE_UV":"",i.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",i.gradientMap?"#define USE_GRADIENTMAP":"",i.flatShading?"#define FLAT_SHADED":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+u:"",i.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",i.physicallyCorrectLights?"#define PHYSICALLY_CORRECT_LIGHTS":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"",(i.extensionShaderTextureLOD||i.envMap)&&i.rendererExtensionShaderTextureLod?"#define TEXTURE_LOD_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",i.toneMapping!==V?"#define TONE_MAPPING":"",i.toneMapping!==V?Rr.tonemapping_pars_fragment:"",i.toneMapping!==V?Qs("toneMapping",i.toneMapping):"",i.dithering?"#define DITHERING":"",Rr.encodings_pars_fragment,i.map?Zs("mapTexelToLinear",i.mapEncoding):"",i.matcap?Zs("matcapTexelToLinear",i.matcapEncoding):"",i.envMap?Zs("envMapTexelToLinear",i.envMapEncoding):"",i.emissiveMap?Zs("emissiveMapTexelToLinear",i.emissiveMapEncoding):"",i.lightMap?Zs("lightMapTexelToLinear",i.lightMapEncoding):"",Ks("linearToOutputTexel",i.outputEncoding),i.depthPacking?"#define DEPTH_PACKING "+i.depthPacking:"","\n"].filter(Js).join("\n")),l=no(l),l=eo(l,i),l=to(l,i),h=no(h),h=eo(h,i),h=to(h,i),l=ao(l),h=ao(h),i.isWebGL2&&!i.isRawShaderMaterial){let e=!1;const t=/^\s*#version\s+300\s+es\s*\n/;i.isShaderMaterial&&null!==l.match(t)&&null!==h.match(t)&&(e=!0,l=l.replace(t,""),h=h.replace(t,"")),x=["#version 300 es\n","#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+x,b=["#version 300 es\n","#define varying in",e?"":"out highp vec4 pc_fragColor;",e?"":"#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 _=b+h,w=Ws(a,35633,x+l),S=Ws(a,35632,_);if(a.attachShader(y,w),a.attachShader(y,S),void 0!==i.index0AttributeName?a.bindAttribLocation(y,0,i.index0AttributeName):!0===i.morphTargets&&a.bindAttribLocation(y,0,"position"),a.linkProgram(y),e.debug.checkShaderErrors){const e=a.getProgramInfoLog(y).trim(),t=a.getShaderInfoLog(w).trim(),i=a.getShaderInfoLog(S).trim();let n=!0,r=!0;if(!1===a.getProgramParameter(y,35714)){n=!1;const t=Ys(a,w,"vertex"),i=Ys(a,S,"fragment");console.error("THREE.WebGLProgram: shader error: ",a.getError(),"gl.VALIDATE_STATUS",a.getProgramParameter(y,35715),"gl.getProgramInfoLog",e,t,i)}else""!==e?console.warn("THREE.WebGLProgram: gl.getProgramInfoLog()",e):""!==t&&""!==i||(r=!1);r&&(this.diagnostics={runnable:n,programLog:e,vertexShader:{log:t,prefix:x},fragmentShader:{log:i,prefix:b}})}let A,M;return a.deleteShader(w),a.deleteShader(S),this.getUniforms=function(){return void 0===A&&(A=new js(a,y)),A},this.getAttributes=function(){return void 0===M&&(M=function(e,t){const i={},n=e.getProgramParameter(t,35721);for(let r=0;r0,maxBones:A,useVertexTexture:a,morphTargets:n.morphTargets,morphNormals:n.morphNormals,maxMorphTargets:e.maxMorphTargets,maxMorphNormals:e.maxMorphNormals,numDirLights:r.directional.length,numPointLights:r.point.length,numSpotLights:r.spot.length,numRectAreaLights:r.rectArea.length,numHemiLights:r.hemi.length,numDirLightShadows:r.directionalShadowMap.length,numPointLightShadows:r.pointShadowMap.length,numSpotLightShadows:r.spotShadowMap.length,numClippingPlanes:v,numClipIntersection:y,dithering:n.dithering,shadowMapEnabled:e.shadowMap.enabled&&m.length>0,shadowMapType:e.shadowMap.type,toneMapping:n.toneMapped?e.toneMapping:V,physicallyCorrectLights:e.physicallyCorrectLights,premultipliedAlpha:n.premultipliedAlpha,alphaTest:n.alphaTest,doubleSided:n.side===l,flipSided:n.side===c,depthPacking:void 0!==n.depthPacking&&n.depthPacking,index0AttributeName:n.index0AttributeName,extensionDerivatives:n.extensions&&n.extensions.derivatives,extensionFragDepth:n.extensions&&n.extensions.fragDepth,extensionDrawBuffers:n.extensions&&n.extensions.drawBuffers,extensionShaderTextureLOD:n.extensions&&n.extensions.shaderTextureLOD,rendererExtensionFragDepth:s||null!==t.get("EXT_frag_depth"),rendererExtensionDrawBuffers:s||null!==t.get("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:s||null!==t.get("EXT_shader_texture_lod"),customProgramCacheKey:n.customProgramCacheKey()}},getProgramCacheKey:function(t){const i=[];if(t.shaderID?i.push(t.shaderID):(i.push(t.fragmentShader),i.push(t.vertexShader)),void 0!==t.defines)for(const e in t.defines)i.push(e),i.push(t.defines[e]);if(void 0===t.isRawShaderMaterial){for(let e=0;e1&&i.sort(e||po),n.length>1&&n.sort(t||go)}}}function yo(){let e=new WeakMap;function t(i){const n=i.target;n.removeEventListener("dispose",t),e.delete(n)}return{get:function(i,n){const r=e.get(i);let s;return void 0===r?(s=new vo,e.set(i,new WeakMap),e.get(i).set(n,s),i.addEventListener("dispose",t)):(s=r.get(n),void 0===s&&(s=new vo,r.set(n,s))),s},dispose:function(){e=new WeakMap}}}function xo(){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 Zt,color:new mn};break;case"SpotLight":i={position:new Zt,direction:new Zt,color:new mn,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new Zt,color:new mn,distance:0,decay:0};break;case"HemisphereLight":i={direction:new Zt,skyColor:new mn,groundColor:new mn};break;case"RectAreaLight":i={color:new mn,position:new Zt,halfWidth:new Zt,halfHeight:new Zt}}return e[t.id]=i,i}}}let bo=0;function _o(e,t){return(t.castShadow?1:0)-(e.castShadow?1:0)}function wo(){const e=new xo,t=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 zt};break;case"PointLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new zt,shadowCameraNear:1,shadowCameraFar:1e3}}return e[t.id]=i,i}}}(),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotShadow:[],spotShadowMap:[],spotShadowMatrix:[],rectArea:[],point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[]};for(let e=0;e<9;e++)i.probe.push(new Zt);const n=new Zt,r=new ri,s=new ri;return{setup:function(o,a,c){let l=0,h=0,u=0;for(let e=0;e<9;e++)i.probe[e].set(0,0,0);let d=0,f=0,m=0,p=0,g=0,v=0,y=0,x=0;const b=c.matrixWorldInverse;o.sort(_o);for(let a=0,c=o.length;a0);let r=!1;!0===t.isSkinnedMesh&&(!0===n.skinning?r=!0:console.warn("THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:",t));l=h(e,r,!0===t.isInstancedMesh)}else l=u;if(e.localClippingEnabled&&!0===n.clipShadows&&0!==n.clippingPlanes.length){const e=l.uuid,t=n.uuid;let i=p[e];void 0===i&&(i={},p[e]=i);let r=i[t];void 0===r&&(r=l.clone(),i[t]=r),l=r}return l.visible=n.visible,l.wireframe=n.wireframe,l.side=c===o?null!==n.shadowSide?n.shadowSide:n.side:null!==n.shadowSide?n.shadowSide:g[n.side],l.clipShadows=n.clipShadows,l.clippingPlanes=n.clippingPlanes,l.clipIntersection=n.clipIntersection,l.wireframeLinewidth=n.wireframeLinewidth,l.linewidth=n.linewidth,!0===r.isPointLight&&!0===l.isMeshDistanceMaterial&&(l.referencePosition.setFromMatrixPosition(r.matrixWorld),l.nearDistance=s,l.farDistance=a),l}function C(i,r,s,a,c){if(!1===i.visible)return;if(i.layers.test(r.layers)&&(i.isMesh||i.isLine||i.isPoints)&&(i.castShadow||i.receiveShadow&&c===o)&&(!i.frustumCulled||n.intersectsObject(i))){i.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,i.matrixWorld);const n=t.update(i),r=i.material;if(Array.isArray(r)){const t=n.groups;for(let o=0,l=t.length;oi||s.y>i)&&(s.x>i&&(u.x=Math.floor(i/f.x),s.x=u.x*f.x,h.mapSize.x=u.x),s.y>i&&(u.y=Math.floor(i/f.y),s.y=u.y*f.y,h.mapSize.y=u.y)),null===h.map&&!h.isPointLightShadow&&this.type===o){const e={minFilter:ae,magFilter:ae,format:Ae};h.map=new Wt(s.x,s.y,e),h.map.texture.name=l.name+".shadowMap",h.mapPass=new Wt(s.x,s.y,e),h.camera.updateProjectionMatrix()}if(null===h.map){const e={minFilter:re,magFilter:re,format:Ae};h.map=new Wt(s.x,s.y,e),h.map.texture.name=l.name+".shadowMap",h.camera.updateProjectionMatrix()}e.setRenderTarget(h.map),e.clear();const p=h.getViewportCount();for(let e=0;e=1):-1!==ae.indexOf("OpenGL ES")&&(oe=parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(ae)[1]),se=oe>=2);let ce=null,le={};const he=new jt,ue=new jt;function de(t,i,n){const r=new Uint8Array(4),s=e.createTexture();e.bindTexture(t,s),e.texParameteri(t,10241,9728),e.texParameteri(t,10240,9728);for(let t=0;tn||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?Ft.floorPowerOfTwo:Math.floor,s=n(r*e.width),o=n(r*e.height);void 0===f&&(f=p(s,o));const a=i?p(s,o):f;a.width=s,a.height=o;return a.getContext("2d").drawImage(e,0,0,s,o),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+e.width+"x"+e.height+") to ("+s+"x"+o+")."),a}return"data"in e&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+e.width+"x"+e.height+")."),e}return e}function v(e){return Ft.isPowerOfTwo(e.width)&&Ft.isPowerOfTwo(e.height)}function y(e,t){return e.generateMipmaps&&t&&e.minFilter!==re&&e.minFilter!==ae}function x(t,i,r,s){e.generateMipmap(t);n.get(i).__maxMipLevel=Math.log(Math.max(r,s))*Math.LOG2E}function b(i,n,r){if(!1===a)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 s=n;return 6403===n&&(5126===r&&(s=33326),5131===r&&(s=33325),5121===r&&(s=33321)),6407===n&&(5126===r&&(s=34837),5131===r&&(s=34843),5121===r&&(s=32849)),6408===n&&(5126===r&&(s=34836),5131===r&&(s=34842),5121===r&&(s=32856)),33325!==s&&33326!==s&&34842!==s&&34836!==s||t.get("EXT_color_buffer_float"),s}function _(e){return e===re||e===se||e===oe?9728:9729}function w(t){const i=t.target;i.removeEventListener("dispose",w),function(t){const i=n.get(t);if(void 0===i.__webglInit)return;e.deleteTexture(i.__webglTexture),n.remove(t)}(i),i.isVideoTexture&&d.delete(i),o.memory.textures--}function S(t){const i=t.target;i.removeEventListener("dispose",S),function(t){const i=n.get(t),r=n.get(t.texture);if(!t)return;void 0!==r.__webglTexture&&e.deleteTexture(r.__webglTexture);t.depthTexture&&t.depthTexture.dispose();if(t.isWebGLCubeRenderTarget)for(let t=0;t<6;t++)e.deleteFramebuffer(i.__webglFramebuffer[t]),i.__webglDepthbuffer&&e.deleteRenderbuffer(i.__webglDepthbuffer[t]);else e.deleteFramebuffer(i.__webglFramebuffer),i.__webglDepthbuffer&&e.deleteRenderbuffer(i.__webglDepthbuffer),i.__webglMultisampledFramebuffer&&e.deleteFramebuffer(i.__webglMultisampledFramebuffer),i.__webglColorRenderbuffer&&e.deleteRenderbuffer(i.__webglColorRenderbuffer),i.__webglDepthRenderbuffer&&e.deleteRenderbuffer(i.__webglDepthRenderbuffer);n.remove(t.texture),n.remove(t)}(i),o.memory.textures--}let A=0;function M(e,t){const r=n.get(e);if(e.isVideoTexture&&function(e){const t=o.render.frame;d.get(e)!==t&&(d.set(e,t),e.update())}(e),e.version>0&&r.__version!==e.version){const i=e.image;if(void 0===i)console.warn("THREE.WebGLRenderer: Texture marked for update but image is undefined");else{if(!1!==i.complete)return void L(r,e,t);console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete")}}i.activeTexture(33984+t),i.bindTexture(3553,r.__webglTexture)}function C(t,r){if(6!==t.image.length)return;const o=n.get(t);if(t.version>0&&o.__version!==t.version){D(o,t),i.activeTexture(33984+r),i.bindTexture(34067,o.__webglTexture),e.pixelStorei(37440,t.flipY);const n=t&&(t.isCompressedTexture||t.image[0].isCompressedTexture),c=t.image[0]&&t.image[0].isDataTexture,h=[];for(let e=0;e<6;e++)h[e]=n||c?c?t.image[e].image:t.image[e]:g(t.image[e],!1,!0,l);const u=h[0],d=v(u)||a,f=s.convert(t.format),m=s.convert(t.type),p=b(t.internalFormat,f,m);let _;if(E(34067,t,d),n){for(let e=0;e<6;e++){_=h[e].mipmaps;for(let n=0;n<_.length;n++){const r=_[n];t.format!==Ae&&t.format!==Se?null!==f?i.compressedTexImage2D(34069+e,n,p,r.width,r.height,0,r.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):i.texImage2D(34069+e,n,p,r.width,r.height,0,f,m,r.data)}}o.__maxMipLevel=_.length-1}else{_=t.mipmaps;for(let e=0;e<6;e++)if(c){i.texImage2D(34069+e,0,p,h[e].width,h[e].height,0,f,m,h[e].data);for(let t=0;t<_.length;t++){const n=_[t].image[e].image;i.texImage2D(34069+e,t+1,p,n.width,n.height,0,f,m,n.data)}}else{i.texImage2D(34069+e,0,p,f,m,h[e]);for(let t=0;t<_.length;t++){const n=_[t];i.texImage2D(34069+e,t+1,p,f,m,n.image[e])}}o.__maxMipLevel=_.length}y(t,d)&&x(34067,t,u.width,u.height),o.__version=t.version,t.onUpdate&&t.onUpdate(t)}else i.activeTexture(33984+r),i.bindTexture(34067,o.__webglTexture)}function P(e,t){i.activeTexture(33984+t),i.bindTexture(34067,n.get(e).__webglTexture)}const T={[te]:10497,[ie]:33071,[ne]:33648},I={[re]:9728,[se]:9984,[oe]:9986,[ae]:9729,[ce]:9985,[le]:9987};function E(i,s,o){o?(e.texParameteri(i,10242,T[s.wrapS]),e.texParameteri(i,10243,T[s.wrapT]),32879!==i&&35866!==i||e.texParameteri(i,32882,T[s.wrapR]),e.texParameteri(i,10240,I[s.magFilter]),e.texParameteri(i,10241,I[s.minFilter])):(e.texParameteri(i,10242,33071),e.texParameteri(i,10243,33071),32879!==i&&35866!==i||e.texParameteri(i,32882,33071),s.wrapS===ie&&s.wrapT===ie||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,_(s.magFilter)),e.texParameteri(i,10241,_(s.minFilter)),s.minFilter!==re&&s.minFilter!==ae&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter."));const c=t.get("EXT_texture_filter_anisotropic");if(c){if(s.type===ge&&null===t.get("OES_texture_float_linear"))return;if(s.type===ve&&null===(a||t.get("OES_texture_half_float_linear")))return;(s.anisotropy>1||n.get(s).__currentAnisotropy)&&(e.texParameterf(i,c.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(s.anisotropy,r.getMaxAnisotropy())),n.get(s).__currentAnisotropy=s.anisotropy)}}function D(t,i){void 0===t.__webglInit&&(t.__webglInit=!0,i.addEventListener("dispose",w),t.__webglTexture=e.createTexture(),o.memory.textures++)}function L(t,n,r){let o=3553;n.isDataTexture2DArray&&(o=35866),n.isDataTexture3D&&(o=32879),D(t,n),i.activeTexture(33984+r),i.bindTexture(o,t.__webglTexture),e.pixelStorei(37440,n.flipY),e.pixelStorei(37441,n.premultiplyAlpha),e.pixelStorei(3317,n.unpackAlignment);const c=function(e){return!a&&(e.wrapS!==ie||e.wrapT!==ie||e.minFilter!==re&&e.minFilter!==ae)}(n)&&!1===v(n.image),l=g(n.image,c,!1,h),u=v(l)||a,d=s.convert(n.format);let f,m=s.convert(n.type),p=b(n.internalFormat,d,m);E(o,n,u);const _=n.mipmaps;if(n.isDepthTexture)p=6402,a?p=n.type===ge?36012:n.type===pe?33190:n.type===_e?35056:33189:n.type===ge&&console.error("WebGLRenderer: Floating point depth texture requires WebGL2."),n.format===Pe&&6402===p&&n.type!==fe&&n.type!==pe&&(console.warn("THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture."),n.type=fe,m=s.convert(n.type)),n.format===Te&&6402===p&&(p=34041,n.type!==_e&&(console.warn("THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture."),n.type=_e,m=s.convert(n.type))),i.texImage2D(3553,0,p,l.width,l.height,0,d,m,null);else if(n.isDataTexture)if(_.length>0&&u){for(let e=0,t=_.length;e0&&u){for(let e=0,t=_.length;e=c&&console.warn("THREE.WebGLTextures: Trying to use "+e+" texture units while this GPU supports only "+c),A+=1,e},this.resetTextureUnits=function(){A=0},this.setTexture2D=M,this.setTexture2DArray=function(e,t){const r=n.get(e);e.version>0&&r.__version!==e.version?L(r,e,t):(i.activeTexture(33984+t),i.bindTexture(35866,r.__webglTexture))},this.setTexture3D=function(e,t){const r=n.get(e);e.version>0&&r.__version!==e.version?L(r,e,t):(i.activeTexture(33984+t),i.bindTexture(32879,r.__webglTexture))},this.setTextureCube=C,this.setTextureCubeDynamic=P,this.setupRenderTarget=function(t){const r=n.get(t),c=n.get(t.texture);t.addEventListener("dispose",S),c.__webglTexture=e.createTexture(),o.memory.textures++;const l=!0===t.isWebGLCubeRenderTarget,h=!0===t.isWebGLMultisampleRenderTarget,u=v(t)||a;if(!a||t.texture.format!==Se||t.texture.type!==ge&&t.texture.type!==ve||(t.texture.format=Ae,console.warn("THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.")),l){r.__webglFramebuffer=[];for(let t=0;t<6;t++)r.__webglFramebuffer[t]=e.createFramebuffer()}else if(r.__webglFramebuffer=e.createFramebuffer(),h)if(a){r.__webglMultisampledFramebuffer=e.createFramebuffer(),r.__webglColorRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(36161,r.__webglColorRenderbuffer);const i=s.convert(t.texture.format),n=s.convert(t.texture.type),o=b(t.texture.internalFormat,i,n),a=B(t);e.renderbufferStorageMultisample(36161,a,o,t.width,t.height),e.bindFramebuffer(36160,r.__webglMultisampledFramebuffer),e.framebufferRenderbuffer(36160,36064,36161,r.__webglColorRenderbuffer),e.bindRenderbuffer(36161,null),t.depthBuffer&&(r.__webglDepthRenderbuffer=e.createRenderbuffer(),k(r.__webglDepthRenderbuffer,t,!0)),e.bindFramebuffer(36160,null)}else console.warn("THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.");if(l){i.bindTexture(34067,c.__webglTexture),E(34067,t.texture,u);for(let e=0;e<6;e++)R(r.__webglFramebuffer[e],t,36064,34069+e);y(t.texture,u)&&x(34067,t.texture,t.width,t.height),i.bindTexture(34067,null)}else i.bindTexture(3553,c.__webglTexture),E(3553,t.texture,u),R(r.__webglFramebuffer,t,36064,3553),y(t.texture,u)&&x(3553,t.texture,t.width,t.height),i.bindTexture(3553,null);t.depthBuffer&&O(t)},this.updateRenderTargetMipmap=function(e){const t=e.texture;if(y(t,v(e)||a)){const r=e.isWebGLCubeRenderTarget?34067:3553,s=n.get(t).__webglTexture;i.bindTexture(r,s),x(r,t,e.width,e.height),i.bindTexture(r,null)}},this.updateMultisampleRenderTarget=function(t){if(t.isWebGLMultisampleRenderTarget)if(a){const i=n.get(t);e.bindFramebuffer(36008,i.__webglMultisampledFramebuffer),e.bindFramebuffer(36009,i.__webglFramebuffer);const r=t.width,s=t.height;let o=16384;t.depthBuffer&&(o|=256),t.stencilBuffer&&(o|=1024),e.blitFramebuffer(0,0,r,s,0,0,r,s,o,9728),e.bindFramebuffer(36160,i.__webglMultisampledFramebuffer)}else console.warn("THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.")},this.safeSetTexture2D=function(e,t){e&&e.isWebGLRenderTarget&&(!1===N&&(console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead."),N=!0),e=e.texture),M(e,t)},this.safeSetTextureCube=function(e,t){e&&e.isWebGLCubeRenderTarget&&(!1===F&&(console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead."),F=!0),e=e.texture),e&&e.isCubeTexture||Array.isArray(e.image)&&6===e.image.length?C(e,t):P(e,t)}}function Lo(e,t,i){const n=i.isWebGL2;return{convert:function(e){let i;if(e===he)return 5121;if(e===ye)return 32819;if(e===xe)return 32820;if(e===be)return 33635;if(e===ue)return 5120;if(e===de)return 5122;if(e===fe)return 5123;if(e===me)return 5124;if(e===pe)return 5125;if(e===ge)return 5126;if(e===ve)return n?5131:(i=t.get("OES_texture_half_float"),null!==i?i.HALF_FLOAT_OES:null);if(e===we)return 6406;if(e===Se)return 6407;if(e===Ae)return 6408;if(e===Me)return 6409;if(e===Ce)return 6410;if(e===Pe)return 6402;if(e===Te)return 34041;if(e===Ie)return 6403;if(e===Ee)return 36244;if(e===De)return 33319;if(e===Le)return 33320;if(e===Re)return 36248;if(e===ke)return 36249;if(e===Oe||e===Be||e===Ne||e===Fe){if(i=t.get("WEBGL_compressed_texture_s3tc"),null===i)return null;if(e===Oe)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(e===Be)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(e===Ne)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(e===Fe)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(e===ze||e===Ue||e===$e||e===Ge){if(i=t.get("WEBGL_compressed_texture_pvrtc"),null===i)return null;if(e===ze)return i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(e===Ue)return i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(e===$e)return i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(e===Ge)return i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(e===Ve)return i=t.get("WEBGL_compressed_texture_etc1"),null!==i?i.COMPRESSED_RGB_ETC1_WEBGL:null;if((e===He||e===je)&&(i=t.get("WEBGL_compressed_texture_etc"),null!==i)){if(e===He)return i.COMPRESSED_RGB8_ETC2;if(e===je)return i.COMPRESSED_RGBA8_ETC2_EAC}return e===We||e===qe||e===Xe||e===Ye||e===Ze||e===Ke||e===Qe||e===Je||e===et||e===tt||e===it||e===nt||e===rt||e===st||e===at||e===ct||e===lt||e===ht||e===ut||e===dt||e===ft||e===mt||e===pt||e===gt||e===vt||e===yt||e===xt||e===bt?(i=t.get("WEBGL_compressed_texture_astc"),null!==i?e:null):e===ot?(i=t.get("EXT_texture_compression_bptc"),null!==i?e:null):e===_e?n?34042:(i=t.get("WEBGL_depth_texture"),null!==i?i.UNSIGNED_INT_24_8_WEBGL:null):void 0}}}function Ro(e){Sr.call(this),this.cameras=e||[]}function ko(){wi.call(this),this.type="Group"}function Oo(){this._targetRay=null,this._grip=null}function Bo(e,t){const i=this;let n=null,r=1,s=null,o="local-floor",a=null;const c=[],l=new Map,h=new Sr;h.layers.enable(1),h.viewport=new jt;const u=new Sr;u.layers.enable(2),u.viewport=new jt;const d=[h,u],f=new Ro;f.layers.enable(1),f.layers.enable(2);let m=null,p=null;function g(e){const t=l.get(e.inputSource);t&&t.dispatchEvent({type:e.type})}function v(){l.forEach((function(e,t){e.disconnect(t)})),l.clear(),e.setFramebuffer(null),e.setRenderTarget(e.getRenderTarget()),A.stop(),i.isPresenting=!1,i.dispatchEvent({type:"sessionend"})}function y(e){s=e,A.setContext(n),A.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}function x(e){const t=n.inputSources;for(let e=0;e=0&&e.numSupportedMorphTargets++}if(e.morphNormals){e.numSupportedMorphNormals=0;for(let t=0;t=0&&e.numSupportedMorphNormals++}const m=n.uniforms;(e.isShaderMaterial||e.isRawShaderMaterial)&&!0!==e.clipping||(n.numClippingPlanes=O.numPlanes,n.numIntersection=O.numIntersection,m.clippingPlanes=O.uniform),n.environment=e.isMeshStandardMaterial?t.environment:null,n.fog=t.fog,n.needsLights=function(e){return e.isMeshLambertMaterial||e.isMeshToonMaterial||e.isMeshPhongMaterial||e.isMeshStandardMaterial||e.isShadowMaterial||e.isShaderMaterial&&!0===e.lights}(e),n.lightsStateVersion=o,n.needsLights&&(m.ambientLightColor.value=r.state.ambient,m.lightProbe.value=r.state.probe,m.directionalLights.value=r.state.directional,m.directionalLightShadows.value=r.state.directionalShadow,m.spotLights.value=r.state.spot,m.spotLightShadows.value=r.state.spotShadow,m.rectAreaLights.value=r.state.rectArea,m.pointLights.value=r.state.point,m.pointLightShadows.value=r.state.pointShadow,m.hemisphereLights.value=r.state.hemi,m.directionalShadowMap.value=r.state.directionalShadowMap,m.directionalShadowMatrix.value=r.state.directionalShadowMatrix,m.spotShadowMap.value=r.state.spotShadowMap,m.spotShadowMatrix.value=r.state.spotShadowMatrix,m.pointShadowMap.value=r.state.pointShadowMap,m.pointShadowMatrix.value=r.state.pointShadowMatrix);const p=n.program.getUniforms(),g=js.seqWithValue(p.seq,m);n.uniformsList=g}function Pe(e,t,i,n){!0!==t.isScene&&(t=U),X.resetTextureUnits();const r=t.fog,s=i.isMeshStandardMaterial?t.environment:null,o=null===y?f.outputEncoding:y.texture.encoding,a=q.get(i),c=d.state.lights;if(!0===B&&(!0===N||e!==_)){const t=e===_&&i.id===b;O.setState(i.clippingPlanes,i.clipIntersection,i.clipShadows,e,a,t)}i.version===a.__version?void 0===a.program||i.fog&&a.fog!==r||a.environment!==s||a.needsLights&&a.lightsStateVersion!==c.state.version?Ce(i,t,n):void 0===a.numClippingPlanes||a.numClippingPlanes===O.numPlanes&&a.numIntersection===O.numIntersection?a.outputEncoding!==o&&Ce(i,t,n):Ce(i,t,n):(Ce(i,t,n),a.__version=i.version);let l=!1,h=!1,u=!1;const m=a.program,p=m.getUniforms(),g=a.uniforms;if(j.useProgram(m.program)&&(l=!0,h=!0,u=!0),i.id!==b&&(b=i.id,h=!0),l||_!==e){if(p.setValue(ce,"projectionMatrix",e.projectionMatrix),H.logarithmicDepthBuffer&&p.setValue(ce,"logDepthBufFC",2/(Math.log(e.far+1)/Math.LN2)),_!==e&&(_=e,h=!0,u=!0),i.isShaderMaterial||i.isMeshPhongMaterial||i.isMeshToonMaterial||i.isMeshStandardMaterial||i.envMap){const t=p.map.cameraPosition;void 0!==t&&t.setValue(ce,z.setFromMatrixPosition(e.matrixWorld))}(i.isMeshPhongMaterial||i.isMeshToonMaterial||i.isMeshLambertMaterial||i.isMeshBasicMaterial||i.isMeshStandardMaterial||i.isShaderMaterial)&&p.setValue(ce,"isOrthographic",!0===e.isOrthographicCamera),(i.isMeshPhongMaterial||i.isMeshToonMaterial||i.isMeshLambertMaterial||i.isMeshBasicMaterial||i.isMeshStandardMaterial||i.isShaderMaterial||i.isShadowMaterial||i.skinning)&&p.setValue(ce,"viewMatrix",e.matrixWorldInverse)}if(i.skinning){p.setOptional(ce,n,"bindMatrix"),p.setOptional(ce,n,"bindMatrixInverse");const e=n.skeleton;if(e){const t=e.bones;if(H.floatVertexTextures){if(void 0===e.boneTexture){let i=Math.sqrt(4*t.length);i=Ft.ceilPowerOfTwo(i),i=Math.max(i,4);const n=new Float32Array(i*i*4);n.set(e.boneMatrices);const r=new Ar(n,i,i,Ae,ge);e.boneMatrices=n,e.boneTexture=r,e.boneTextureSize=i}p.setValue(ce,"boneTexture",e.boneTexture,X),p.setValue(ce,"boneTextureSize",e.boneTextureSize)}else p.setOptional(ce,e,"boneMatrices")}}var v,x;return(h||a.receiveShadow!==n.receiveShadow)&&(a.receiveShadow=n.receiveShadow,p.setValue(ce,"receiveShadow",n.receiveShadow)),h&&(p.setValue(ce,"toneMappingExposure",f.toneMappingExposure),a.needsLights&&(x=u,(v=g).ambientLightColor.needsUpdate=x,v.lightProbe.needsUpdate=x,v.directionalLights.needsUpdate=x,v.directionalLightShadows.needsUpdate=x,v.pointLights.needsUpdate=x,v.pointLightShadows.needsUpdate=x,v.spotLights.needsUpdate=x,v.spotLightShadows.needsUpdate=x,v.rectAreaLights.needsUpdate=x,v.hemisphereLights.needsUpdate=x),r&&i.fog&&J.refreshFogUniforms(g,r),J.refreshMaterialUniforms(g,i,s,T,P),void 0!==g.ltc_1&&(g.ltc_1.value=Tr.LTC_1),void 0!==g.ltc_2&&(g.ltc_2.value=Tr.LTC_2),js.upload(ce,a.uniformsList,g,X)),i.isShaderMaterial&&!0===i.uniformsNeedUpdate&&(js.upload(ce,a.uniformsList,g,X),i.uniformsNeedUpdate=!1),i.isSpriteMaterial&&p.setValue(ce,"center",n.center),p.setValue(ce,"modelViewMatrix",n.modelViewMatrix),p.setValue(ce,"normalMatrix",n.normalMatrix),p.setValue(ce,"modelMatrix",n.matrixWorld),m}_e.setAnimationLoop((function(e){de.isPresenting||be&&be(e)})),"undefined"!=typeof window&&_e.setContext(window),this.setAnimationLoop=function(e){be=e,de.setAnimationLoop(e),null===e?_e.stop():_e.start()},this.render=function(e,t){let i,n;if(void 0!==arguments[2]&&(console.warn("THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead."),i=arguments[2]),void 0!==arguments[3]&&(console.warn("THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead."),n=arguments[3]),void 0!==t&&!0!==t.isCamera)return void console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");if(!0===m)return;ae.resetDefaultState(),b=-1,_=null,!0===e.autoUpdate&&e.updateMatrixWorld(),null===t.parent&&t.updateMatrixWorld(),!0===de.enabled&&!0===de.isPresenting&&(t=de.getCamera(t)),!0===e.isScene&&e.onBeforeRender(f,e,t,i||y),d=te.get(e,t),d.init(),F.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),k.setFromProjectionMatrix(F),N=this.localClippingEnabled,B=O.init(this.clippingPlanes,N,t),u=ee.get(e,t),u.init(),we(e,t,0,f.sortObjects),u.finish(),!0===f.sortObjects&&u.sort(I,E),!0===B&&O.beginShadows();const r=d.state.shadowsArray;fe.render(r,e,t),d.setupLights(t),!0===B&&O.endShadows(),!0===this.info.autoReset&&this.info.reset(),void 0!==i&&this.setRenderTarget(i),ie.render(u,e,t,n);const s=u.opaque,o=u.transparent;s.length>0&&Se(s,e,t),o.length>0&&Se(o,e,t),!0===e.isScene&&e.onAfterRender(f,e,t),null!==y&&(X.updateRenderTargetMipmap(y),X.updateMultisampleRenderTarget(y)),j.buffers.depth.setTest(!0),j.buffers.depth.setMask(!0),j.buffers.color.setMask(!0),j.setPolygonOffset(!1),u=null,d=null},this.setFramebuffer=function(e){p!==e&&null===y&&ce.bindFramebuffer(36160,e),p=e},this.getActiveCubeFace=function(){return g},this.getActiveMipmapLevel=function(){return v},this.getRenderTarget=function(){return y},this.setRenderTarget=function(e,t,i){y=e,g=t,v=i,e&&void 0===q.get(e).__webglFramebuffer&&X.setupRenderTarget(e);let n=p,r=!1;if(e){const i=q.get(e).__webglFramebuffer;e.isWebGLCubeRenderTarget?(n=i[t||0],r=!0):n=e.isWebGLMultisampleRenderTarget?q.get(e).__webglMultisampledFramebuffer:i,S.copy(e.viewport),A.copy(e.scissor),M=e.scissorTest}else S.copy(D).multiplyScalar(T).floor(),A.copy(L).multiplyScalar(T).floor(),M=R;if(x!==n&&(ce.bindFramebuffer(36160,n),x=n),j.viewport(S),j.scissor(A),j.setScissorTest(M),r){const n=q.get(e.texture);ce.framebufferTexture2D(36160,36064,34069+(t||0),n.__webglTexture,i||0)}},this.readRenderTargetPixels=function(e,t,i,n,r,s,o){if(!e||!e.isWebGLRenderTarget)return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let a=q.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&void 0!==o&&(a=a[o]),a){let o=!1;a!==x&&(ce.bindFramebuffer(36160,a),o=!0);try{const o=e.texture,a=o.format,c=o.type;if(a!==Ae&&oe.convert(a)!==ce.getParameter(35739))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");if(!(c===he||oe.convert(c)===ce.getParameter(35738)||c===ge&&(H.isWebGL2||G.get("OES_texture_float")||G.get("WEBGL_color_buffer_float"))||c===ve&&(H.isWebGL2?G.get("EXT_color_buffer_float"):G.get("EXT_color_buffer_half_float"))))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");36053===ce.checkFramebufferStatus(36160)?t>=0&&t<=e.width-n&&i>=0&&i<=e.height-r&&ce.readPixels(t,i,n,r,oe.convert(a),oe.convert(c),s):console.error("THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.")}finally{o&&ce.bindFramebuffer(36160,x)}}},this.copyFramebufferToTexture=function(e,t,i){void 0===i&&(i=0);const n=Math.pow(2,-i),r=Math.floor(t.image.width*n),s=Math.floor(t.image.height*n),o=oe.convert(t.format);X.setTexture2D(t,0),ce.copyTexImage2D(3553,i,o,e.x,e.y,r,s,0),j.unbindTexture()},this.copyTextureToTexture=function(e,t,i,n){void 0===n&&(n=0);const r=t.image.width,s=t.image.height,o=oe.convert(i.format),a=oe.convert(i.type);X.setTexture2D(i,0),ce.pixelStorei(37440,i.flipY),ce.pixelStorei(37441,i.premultiplyAlpha),ce.pixelStorei(3317,i.unpackAlignment),t.isDataTexture?ce.texSubImage2D(3553,n,e.x,e.y,r,s,o,a,t.image.data):t.isCompressedTexture?ce.compressedTexSubImage2D(3553,n,e.x,e.y,t.mipmaps[0].width,t.mipmaps[0].height,o,t.mipmaps[0].data):ce.texSubImage2D(3553,n,e.x,e.y,o,a,t.image),0===n&&i.generateMipmaps&&ce.generateMipmap(3553),j.unbindTexture()},this.initTexture=function(e){X.setTexture2D(e,0),j.unbindTexture()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}function zo(e,t,i){this.name="",this.color=new mn(e),this.near=void 0!==t?t:1,this.far=void 0!==i?i:1e3}function Uo(e){bn.call(this),this.type="LineBasicMaterial",this.color=new mn(16777215),this.linewidth=1,this.linecap="round",this.linejoin="round",this.morphTargets=!1,this.setValues(e)}Ro.prototype=Object.assign(Object.create(Sr.prototype),{constructor:Ro,isArrayCamera:!0}),ko.prototype=Object.assign(Object.create(wi.prototype),{constructor:ko,isGroup:!0}),Object.assign(Oo.prototype,{constructor:Oo,getTargetRaySpace:function(){return null===this._targetRay&&(this._targetRay=new ko,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1),this._targetRay},getGripSpace:function(){return null===this._grip&&(this._grip=new ko,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1),this._grip},dispatchEvent:function(e){return null!==this._targetRay&&this._targetRay.dispatchEvent(e),null!==this._grip&&this._grip.dispatchEvent(e),this},disconnect:function(e){return this.dispatchEvent({type:"disconnected",data:e}),null!==this._targetRay&&(this._targetRay.visible=!1),null!==this._grip&&(this._grip.visible=!1),this},update:function(e,t,i){let n=null,r=null;const s=this._targetRay,o=this._grip;return e&&(null!==s&&(n=t.getPose(e.targetRaySpace,i),null!==n&&(s.matrix.fromArray(n.transform.matrix),s.matrix.decompose(s.position,s.rotation,s.scale))),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)))),null!==s&&(s.visible=null!==n),null!==o&&(o.visible=null!==r),this}}),Object.assign(Bo.prototype,Bt.prototype),Object.assign(zo.prototype,{isFog:!0,clone:function(){return new zo(this.color,this.near,this.far)},toJSON:function(){return{type:"Fog",color:this.color.getHex(),near:this.near,far:this.far}}}),Uo.prototype=Object.create(bn.prototype),Uo.prototype.constructor=Uo,Uo.prototype.isLineBasicMaterial=!0,Uo.prototype.copy=function(e){return bn.prototype.copy.call(this,e),this.color.copy(e.color),this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.morphTargets=e.morphTargets,this};const $o=new Zt,Go=new Zt,Vo=new ri,Ho=new Xi,jo=new Ui;function Wo(e,t,i){1===i&&console.error("THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead."),wi.call(this),this.type="Line",this.geometry=void 0!==e?e:new Vn,this.material=void 0!==t?t:new Uo,this.updateMorphTargets()}Wo.prototype=Object.assign(Object.create(wi.prototype),{constructor:Wo,isLine:!0,copy:function(e){return wi.prototype.copy.call(this,e),this.material=e.material,this.geometry=e.geometry,this},computeLineDistances:function(){const e=this.geometry;if(e.isBufferGeometry)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 d=e.ray.origin.distanceTo(h);de.far||t.push({distance:d,point:l.clone().applyMatrix4(this.matrixWorld),index:n,face:null,faceIndex:null,object:this})}}else for(let i=0,n=r.length/3-1;io)continue;h.applyMatrix4(this.matrixWorld);const n=e.ray.origin.distanceTo(h);ne.far||t.push({distance:n,point:l.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}}else if(i.isGeometry){const n=i.vertices,r=n.length;for(let i=0;io)continue;h.applyMatrix4(this.matrixWorld);const r=e.ray.origin.distanceTo(h);re.far||t.push({distance:r,point:l.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}}},updateMorphTargets:function(){const e=this.geometry;if(e.isBufferGeometry){const t=e.morphAttributes,i=Object.keys(t);if(i.length>0){const e=t[i[0]];if(void 0!==e){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,i=e.length;t0&&console.error("THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.")}}});const qo=new Zt,Xo=new Zt;function Yo(e,t){Wo.call(this,e,t),this.type="LineSegments"}function Zo(e){bn.call(this),this.type="PointsMaterial",this.color=new mn(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.morphTargets=!1,this.setValues(e)}Yo.prototype=Object.assign(Object.create(Wo.prototype),{constructor:Yo,isLineSegments:!0,computeLineDistances:function(){const e=this.geometry;if(e.isBufferGeometry)if(null===e.index){const t=e.attributes.position,i=[];for(let e=0,n=t.count;er.far)return;s.push({distance:c,distanceToRay:Math.sqrt(a),point:i,index:t,face:null,object:o})}}function na(e,t,i,n,r,s,o,a,c){Ht.call(this,e,t,i,n,r,s,o,a,c),this.needsUpdate=!0}function ra(e,t,i,n){mr.call(this),this.type="PolyhedronGeometry",this.parameters={vertices:e,indices:t,radius:i,detail:n},this.fromBufferGeometry(new sa(e,t,i,n)),this.mergeVertices()}function sa(e,t,i,n){Vn.call(this),this.type="PolyhedronBufferGeometry",this.parameters={vertices:e,indices:t,radius:i,detail:n},i=i||1;const r=[],s=[];function o(e,t,i,n){const r=Math.pow(2,n),s=[];for(let n=0;n<=r;n++){s[n]=[];const o=e.clone().lerp(i,n/r),a=t.clone().lerp(i,n/r),c=r-n;for(let e=0;e<=c;e++)s[n][e]=0===e&&n===r?o:o.clone().lerp(a,e/c)}for(let e=0;e.9&&o<.1&&(t<.2&&(s[e+0]+=1),i<.2&&(s[e+2]+=1),n<.2&&(s[e+4]+=1))}}()}(),this.setAttribute("position",new Ln(r,3)),this.setAttribute("normal",new Ln(r.slice(),3)),this.setAttribute("uv",new Ln(s,2)),0===n?this.computeVertexNormals():this.normalizeNormals()}function oa(e,t){mr.call(this),this.type="TetrahedronGeometry",this.parameters={radius:e,detail:t},this.fromBufferGeometry(new aa(e,t)),this.mergeVertices()}function aa(e,t){sa.call(this,[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="TetrahedronBufferGeometry",this.parameters={radius:e,detail:t}}function ca(e,t){mr.call(this),this.type="OctahedronGeometry",this.parameters={radius:e,detail:t},this.fromBufferGeometry(new la(e,t)),this.mergeVertices()}function la(e,t){sa.call(this,[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="OctahedronBufferGeometry",this.parameters={radius:e,detail:t}}function ha(e,t){mr.call(this),this.type="IcosahedronGeometry",this.parameters={radius:e,detail:t},this.fromBufferGeometry(new ua(e,t)),this.mergeVertices()}function ua(e,t){const i=(1+Math.sqrt(5))/2,n=[-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];sa.call(this,n,[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="IcosahedronBufferGeometry",this.parameters={radius:e,detail:t}}function da(e,t,i,n,r){mr.call(this),this.type="TorusGeometry",this.parameters={radius:e,tube:t,radialSegments:i,tubularSegments:n,arc:r},this.fromBufferGeometry(new fa(e,t,i,n,r)),this.mergeVertices()}function fa(e,t,i,n,r){Vn.call(this),this.type="TorusBufferGeometry",this.parameters={radius:e,tube:t,radialSegments:i,tubularSegments:n,arc:r},e=e||1,t=t||.4,i=Math.floor(i)||8,n=Math.floor(n)||6,r=r||2*Math.PI;const s=[],o=[],a=[],c=[],l=new Zt,h=new Zt,u=new Zt;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;h.x=(e+t*Math.cos(m))*Math.cos(f),h.y=(e+t*Math.cos(m))*Math.sin(f),h.z=t*Math.sin(m),o.push(h.x,h.y,h.z),l.x=e*Math.cos(f),l.y=e*Math.sin(f),u.subVectors(h,l).normalize(),a.push(u.x,u.y,u.z),c.push(d/n),c.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,o=(n+1)*(e-1)+t,a=(n+1)*e+t;s.push(i,r,a),s.push(r,o,a)}this.setIndex(s),this.setAttribute("position",new Ln(o,3)),this.setAttribute("normal",new Ln(a,3)),this.setAttribute("uv",new Ln(c,2))}function ma(e,t,i,n,r,s,o,a){mr.call(this),this.type="CylinderGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:i,radialSegments:n,heightSegments:r,openEnded:s,thetaStart:o,thetaLength:a},this.fromBufferGeometry(new pa(e,t,i,n,r,s,o,a)),this.mergeVertices()}function pa(e,t,i,n,r,s,o,a){Vn.call(this),this.type="CylinderBufferGeometry",this.parameters={radiusTop:e,radiusBottom:t,height:i,radialSegments:n,heightSegments:r,openEnded:s,thetaStart:o,thetaLength:a};const c=this;e=void 0!==e?e:1,t=void 0!==t?t:1,i=i||1,n=Math.floor(n)||8,r=Math.floor(r)||1,s=void 0!==s&&s,o=void 0!==o?o:0,a=void 0!==a?a:2*Math.PI;const l=[],h=[],u=[],d=[];let f=0;const m=[],p=i/2;let g=0;function v(i){let r,s;const m=new zt,v=new Zt;let y=0;const x=!0===i?e:t,b=!0===i?1:-1;r=f;for(let e=1;e<=n;e++)h.push(0,p*b,0),u.push(0,b,0),d.push(.5,.5),f++;s=f;for(let e=0;e<=n;e++){const t=e/n*a+o,i=Math.cos(t),r=Math.sin(t);v.x=x*r,v.y=p*b,v.z=x*i,h.push(v.x,v.y,v.z),u.push(0,b,0),m.x=.5*i+.5,m.y=.5*r*b+.5,d.push(m.x,m.y),f++}for(let e=0;e0&&v(!0),t>0&&v(!1)),this.setIndex(l),this.setAttribute("position",new Ln(h,3)),this.setAttribute("normal",new Ln(u,3)),this.setAttribute("uv",new Ln(d,2))}function ga(e,t,i,n,r,s,o){ma.call(this,0,e,t,i,n,r,s,o),this.type="ConeGeometry",this.parameters={radius:e,height:t,radialSegments:i,heightSegments:n,openEnded:r,thetaStart:s,thetaLength:o}}function va(e,t,i,n,r,s,o){pa.call(this,0,e,t,i,n,r,s,o),this.type="ConeBufferGeometry",this.parameters={radius:e,height:t,radialSegments:i,heightSegments:n,openEnded:r,thetaStart:s,thetaLength:o}}function ya(e,t){wi.call(this),this.type="Light",this.color=new mn(e),this.intensity=void 0!==t?t:1,this.receiveShadow=void 0}function xa(e){this.camera=e,this.bias=0,this.normalBias=0,this.radius=1,this.mapSize=new zt(512,512),this.map=null,this.mapPass=null,this.matrix=new ri,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Pr,this._frameExtents=new zt(1,1),this._viewportCount=1,this._viewports=[new jt(0,0,1,1)]}function ba(){xa.call(this,new Sr(50,1,.5,500))}function _a(e,t,i,n,r,s){ya.call(this,e,t),this.type="SpotLight",this.position.copy(wi.DefaultUp),this.updateMatrix(),this.target=new wi,Object.defineProperty(this,"power",{get:function(){return this.intensity*Math.PI},set:function(e){this.intensity=e/Math.PI}}),this.distance=void 0!==i?i:0,this.angle=void 0!==n?n:Math.PI/3,this.penumbra=void 0!==r?r:0,this.decay=void 0!==s?s:1,this.shadow=new ba}function wa(e,t,i,n,r,s){wr.call(this),this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=void 0!==e?e:-1,this.right=void 0!==t?t:1,this.top=void 0!==i?i:1,this.bottom=void 0!==n?n:-1,this.near=void 0!==r?r:.1,this.far=void 0!==s?s:2e3,this.updateProjectionMatrix()}function Sa(e,t){ya.call(this,e,t),this.type="AmbientLight",this.castShadow=void 0}ta.prototype=Object.assign(Object.create(wi.prototype),{constructor:ta,isPoints:!0,copy:function(e){return wi.prototype.copy.call(this,e),this.material=e.material,this.geometry=e.geometry,this},raycast:function(e,t){const i=this.geometry,n=this.matrixWorld,r=e.params.Points.threshold;if(null===i.boundingSphere&&i.computeBoundingSphere(),Jo.copy(i.boundingSphere),Jo.applyMatrix4(n),Jo.radius+=r,!1===e.ray.intersectsSphere(Jo))return;Ko.getInverse(n),Qo.copy(e.ray).applyMatrix4(Ko);const s=r/((this.scale.x+this.scale.y+this.scale.z)/3),o=s*s;if(i.isBufferGeometry){const r=i.index,s=i.attributes.position.array;if(null!==r){const i=r.array;for(let r=0,a=i.length;r0){const e=t[i[0]];if(void 0!==e){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,i=e.length;t0&&console.error("THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.")}}}),na.prototype=Object.create(Ht.prototype),na.prototype.constructor=na,na.prototype.isCanvasTexture=!0,ra.prototype=Object.create(mr.prototype),ra.prototype.constructor=ra,sa.prototype=Object.create(Vn.prototype),sa.prototype.constructor=sa,oa.prototype=Object.create(mr.prototype),oa.prototype.constructor=oa,aa.prototype=Object.create(sa.prototype),aa.prototype.constructor=aa,ca.prototype=Object.create(mr.prototype),ca.prototype.constructor=ca,la.prototype=Object.create(sa.prototype),la.prototype.constructor=la,ha.prototype=Object.create(mr.prototype),ha.prototype.constructor=ha,ua.prototype=Object.create(sa.prototype),ua.prototype.constructor=ua,da.prototype=Object.create(mr.prototype),da.prototype.constructor=da,fa.prototype=Object.create(Vn.prototype),fa.prototype.constructor=fa,ma.prototype=Object.create(mr.prototype),ma.prototype.constructor=ma,pa.prototype=Object.create(Vn.prototype),pa.prototype.constructor=pa,ga.prototype=Object.create(ma.prototype),ga.prototype.constructor=ga,va.prototype=Object.create(pa.prototype),va.prototype.constructor=va,ya.prototype=Object.assign(Object.create(wi.prototype),{constructor:ya,isLight:!0,copy:function(e){return wi.prototype.copy.call(this,e),this.color.copy(e.color),this.intensity=e.intensity,this},toJSON:function(e){const t=wi.prototype.toJSON.call(this,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}}),Object.assign(xa.prototype,{_projScreenMatrix:new ri,_lightPositionWorld:new Zt,_lookTarget:new Zt,getViewportCount:function(){return this._viewportCount},getFrustum:function(){return this._frustum},updateMatrices:function(e){const t=this.camera,i=this.matrix,n=this._projScreenMatrix,r=this._lookTarget,s=this._lightPositionWorld;s.setFromMatrixPosition(e.matrixWorld),t.position.copy(s),r.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(r),t.updateMatrixWorld(),n.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(n),i.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),i.multiply(t.projectionMatrix),i.multiply(t.matrixWorldInverse)},getViewport:function(e){return this._viewports[e]},getFrameExtents:function(){return this._frameExtents},copy:function(e){return this.camera=e.camera.clone(),this.bias=e.bias,this.radius=e.radius,this.mapSize.copy(e.mapSize),this},clone:function(){return(new this.constructor).copy(this)},toJSON:function(){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}}),ba.prototype=Object.assign(Object.create(xa.prototype),{constructor:ba,isSpotLightShadow:!0,updateMatrices:function(e){const t=this.camera,i=2*Ft.RAD2DEG*e.angle,n=this.mapSize.width/this.mapSize.height,r=e.distance||t.far;i===t.fov&&n===t.aspect&&r===t.far||(t.fov=i,t.aspect=n,t.far=r,t.updateProjectionMatrix()),xa.prototype.updateMatrices.call(this,e)}}),_a.prototype=Object.assign(Object.create(ya.prototype),{constructor:_a,isSpotLight:!0,copy:function(e){return ya.prototype.copy.call(this,e),this.distance=e.distance,this.angle=e.angle,this.penumbra=e.penumbra,this.decay=e.decay,this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}}),wa.prototype=Object.assign(Object.create(wr.prototype),{constructor:wa,isOrthographicCamera:!0,copy:function(e,t){return wr.prototype.copy.call(this,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:function(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:function(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()},updateProjectionMatrix:function(){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,o=n+t,a=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,o-=t*this.view.offsetY,a=o-t*this.view.height}this.projectionMatrix.makeOrthographic(r,s,o,a,this.near,this.far),this.projectionMatrixInverse.getInverse(this.projectionMatrix)},toJSON:function(e){const t=wi.prototype.toJSON.call(this,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}}),Sa.prototype=Object.assign(Object.create(ya.prototype),{constructor:Sa,isAmbientLight:!0});const Aa=new ri,Ma=new ri;function Ca(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Sr,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Sr,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}}function Pa(e){"string"==typeof e&&(console.warn("THREE.Uniform: Type parameter is no longer needed."),e=arguments[1]),this.value=e}function Ta(e){if("undefined"==typeof window)return;const t=new RegExp(`${e}=([^&#=]*)`).exec(window.location.search);return t?decodeURIComponent(t[1]):void 0}function Ia(e,t){return void 0!==e?e:t}function Ea(e,t){const i=Object.assign({},e);for(const n in t){void 0===e[n]&&(i[n]=t[n])}return i}function Da(e,t){for(const i in t){const n=t[i];void 0!==n&&(e[i]=n)}return e}function La(){const e=window.location.protocol;return null===e.match(/http(s)?:/gi)?"http:":e}function Ra(){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 ka(e){window.open(e,"_blank")||(window.location.href=e)}function Oa(e,t="download"){if(!e)return;const i="Safari"===Ra(),n=/CriOS\/[\d]+/.test(window.navigator.userAgent),r=document.createElement("a");function s(e){ka(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 o=new FileReader;o.onloadend=function(){s(o.result)},o.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)):ka(e),i&&window.URL.revokeObjectURL(e)}}function Ba(e,t){return et?1:0}function Na(e,t,i=Ba){let n=0,r=e.length-1;for(;n<=r;){const s=n+r>>1,o=i(t,e[s]);if(o>0)n=s+1;else{if(!(o<0))return s;r=s-1}}return-n-1}function Fa(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 za(e){return e.sort().filter((function(e,t,i){return 0===t||e!==i[t-1]}))}function Ua(e){const t=28672;if(e.length>t){const i=[];for(let n=0;n65535?Uint32Array:Uint16Array)(e)}function Va(e){return e.buffer&&e.buffer instanceof ArrayBuffer?e.buffer:e}function Ha(e,t){return void 0===e?e=new t:Array.isArray(e)&&(e=(new t).fromArray(e)),e}function ja(e){return Ha(e,Zt)}function Wa(e){return Ha(e,ri)}function qa(e){return Ha(e,qt)}function Xa(e){return t=e,i=Float32Array,t instanceof i?t:new i(t);var t,i}function Ya(e){return Ia(e,"").toString().toLowerCase()}Object.assign(Ca.prototype,{update:function(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;const i=e.projectionMatrix.clone(),n=t.eyeSep/2,r=n*t.near/t.focus,s=t.near*Math.tan(Ft.DEG2RAD*t.fov*.5)/t.zoom;let o,a;Ma.elements[12]=-n,Aa.elements[12]=n,o=-s*t.aspect+r,a=s*t.aspect+r,i.elements[0]=2*t.near/(a-o),i.elements[8]=(a+o)/(a-o),this.cameraL.projectionMatrix.copy(i),o=-s*t.aspect-r,a=s*t.aspect-r,i.elements[0]=2*t.near/(a-o),i.elements[8]=(a+o)/(a-o),this.cameraR.projectionMatrix.copy(i)}this.cameraL.matrixWorld.copy(e.matrixWorld).multiply(Ma),this.cameraR.matrixWorld.copy(e.matrixWorld).multiply(Aa)}}),Pa.prototype.clone=function(){return new Pa(void 0===this.value.clone?this.value:this.value.clone())};class Za{constructor(e){this.name=e,this._dict={}}add(e,t){this._dict[Ya(e)]=t}get(e){return this._dict[Ya(e)]}get names(){return Object.keys(this._dict)}}function Ka(e){return.01745*e}const Qa="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),Ja=new Array(36);function ec(){let e,t=0;for(let i=0;i<36;i++)8===i||13===i||18===i||23===i?Ja[i]="-":14===i?Ja[i]="4":(t<=2&&(t=33554432+16777216*Math.random()|0),e=15&t,t>>=4,Ja[i]=Qa[19===i?3&e|8:e]);return Ja.join("")}function tc(e,t,i){return Math.max(t,Math.min(i,e))}function ic(e,t,i){return e+(t-e)*i}function nc(e,t,i,n,r,s){const o=(i-e)*s,a=(n-t)*s,c=r*r;return(2*t-2*i+o+a)*(r*c)+(-3*t+3*i-2*o-a)*c+o*r+t}function rc(e,t,i){var n;return n=function(e,t,i){return(e-t)/(i-t)}(i,e,t),(i=tc(n,0,1))*i*(3-2*i)}var sc="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function oc(e){var t={exports:{}};return e(t,t.exports),t.exports}var ac=oc((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,o,a,c,l,h,u,d,f,m,p,g,v,y,x,b,_,w,S,A,M,C,P,T,I,E,D,L,R,k,O,B,N,F,z,U,$,G,V,H,j,W,q,X,Y,Z,K,Q,J,ee,te,ie,ne,re,se,oe,ae,ce,le,he,ue,de,fe,me,pe,ge,ve,ye,xe,be,_e,we,Se,Ae,Me,Ce,Pe,Te=[].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},Ae=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,A=Math.cos,I=Math.floor,ie=Math.pow,Y=Math.log,be=Math.sin,_e=Math.sqrt,p=Math.atan2,Q=Math.max,m=Math.abs,c=2*s,o=s/3,n=s/180,a=180/s,_=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(){}))},_.default=_,f=[],null!==e&&null!=e.exports&&(e.exports=_),(null!==t?t:this).chroma=_,_.version="1.4.1",d={},h=[],u=!1,i=function(){function e(){var e,t,i,n,r,s,o,a,c;for(s=this,t=[],a=0,n=arguments.length;a1&&(o=t[t.length-1]),null!=d[o])s._rgb=w(d[o](Ae(t.slice(0,-1))));else{for(u||(h=h.sort((function(e,t){return t.p-e.p})),u=!0),c=0,r=h.length;c3?t[3]:1]},Pe=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},he=function(){var e,t,i,n,r,s,o;return i=(n=Ae(arguments))[0],t=n[1],e=n[2],s=(r=pe(i,t,e))[0],[116*(o=r[1])-16,500*(s-o),200*(o-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=Ae(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)]},_.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,Te.call(arguments).concat(["lab"]),(function(){}))},d.lab=V,i.prototype.lab=function(){return he(this._rgb)},g=function(e){var t,i,n,r,s,o,a,c,l,h,u;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,o;return s=e._rgb,o=t._rgb,new i(_e(ie(s[0],2)*(1-n)+ie(o[0],2)*n),_e(ie(s[1],2)*(1-n)+ie(o[1],2)*n),_e(ie(s[2],2)*(1-n)+ie(o[2],2)*n),r)},l=function(e){var t,n,r,s,o;for(t=1/e.length,o=[0,0,0,0],r=0,n=e.length;r1&&(o[3]=1),new i(w(o))},f.push(["lrgb",z]),_.average=function(e,t){var i,n,r,o,a,c,h,u,d,f,m,g,v;if(null==t&&(t="rgb"),d=e.length,e=e.map((function(e){return _(e)})),h=e.splice(0,1)[0],"lrgb"===t)return l(e);for(u in o=[],a=0,c=0,g=h.get(t))g[u]=g[u]||0,o.push(isNaN(g[u])?0:1),"h"!==t.charAt(u)||isNaN(g[u])||(i=g[u]/180*s,a+=A(i),c+=be(i));for(n=h.alpha(),m=0,f=e.length;m=360;)i-=360;g[u]=i}else g[u]=g[u]/o[u];return _(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},oe=function(e,t){var i,n,r,s,o,a;return null==t&&(t="auto"),o=e[0],r=e[1],n=e[2],i=e[3],"auto"===t&&(t=i<1?"rgba":"rgb"),o=Math.round(o),r=Math.round(r),n=Math.round(n),a=(a="000000"+(o<<16|r<<8|n).toString(16)).substr(a.length-6),s=(s="0"+ye(255*i).toString(16)).substr(s.length-2),"#"+function(){switch(t.toLowerCase()){case"rgba":return a+s;case"argb":return s+a;default:return a}}()},d.hex=function(e){return D(e)},_.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,Te.call(arguments).concat(["hex"]),(function(){}))},i.prototype.hex=function(e){return null==e&&(e="auto"),oe(this._rgb,e)},h.push({p:4,test:function(e){if(1===arguments.length&&"string"===Se(e))return"hex"}}),k=function(){var e,t,i,n,r,s,o,a,c,l,h,u,d,f;if(r=(e=Ae(arguments))[0],h=e[1],o=e[2],0===h)c=n=t=255*o;else{for(i=[0,0,0],u=2*o-(d=o<.5?o*(1+h):o+h-o*h),(f=[0,0,0])[0]=(r/=360)+1/3,f[1]=r,f[2]=r-1/3,s=a=0;a<=2;s=++a)f[s]<0&&(f[s]+=1),f[s]>1&&(f[s]-=1),6*f[s]<1?i[s]=u+6*(d-u)*f[s]:2*f[s]<1?i[s]=d:3*f[s]<2?i[s]=u+(d-u)*(2/3-f[s])*6:i[s]=u;c=(l=[ye(255*i[0]),ye(255*i[1]),ye(255*i[2])])[0],n=l[1],t=l[2]}return e.length>3?[c,n,t,e[3]]:[c,n,t]},ce=function(e,t,i){var n,r,s,o,a;return void 0!==e&&e.length>=3&&(e=(o=e)[0],t=o[1],i=o[2]),e/=255,t/=255,i/=255,s=Math.min(e,t,i),r=((Q=Math.max(e,t,i))+s)/2,Q===s?(a=0,n=Number.NaN):a=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,a,r]},_.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,Te.call(arguments).concat(["hsl"]),(function(){}))},d.hsl=k,i.prototype.hsl=function(){return ce(this._rgb)},O=function(){var e,t,i,n,r,s,o,a,c,l,h,u,d,f,m,p,g,v;if(r=(e=Ae(arguments))[0],p=e[1],v=e[2],v*=255,0===p)c=n=t=v;else switch(360===r&&(r=0),r>360&&(r-=360),r<0&&(r+=360),o=v*(1-p),a=v*(1-p*(i=(r/=60)-(s=I(r)))),g=v*(1-p*(1-i)),s){case 0:c=(l=[v,g,o])[0],n=l[1],t=l[2];break;case 1:c=(h=[a,v,o])[0],n=h[1],t=h[2];break;case 2:c=(u=[o,v,g])[0],n=u[1],t=u[2];break;case 3:c=(d=[o,a,v])[0],n=d[1],t=d[2];break;case 4:c=(f=[g,o,v])[0],n=f[1],t=f[2];break;case 5:c=(m=[v,o,a])[0],n=m[1],t=m[2]}return[c,n,t,e.length>3?e[3]:1]},le=function(){var e,t,i,n,r,s,o,a,c;return s=(o=Ae(arguments))[0],i=o[1],e=o[2],r=Math.min(s,i,e),t=(Q=Math.max(s,i,e))-r,c=Q/255,0===Q?(n=Number.NaN,a=0):(a=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,a,c]},_.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,Te.call(arguments).concat(["hsv"]),(function(){}))},d.hsv=O,i.prototype.hsv=function(){return le(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=Ae(arguments))[0]<<16)+(e[1]<<8)+e[2]},_.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,h.push({p:1,test:function(e){if(1===arguments.length&&"number"===Se(e)&&e>=0&&e<=16777215)return"num"}}),E=function(){var e,t,i,n,r,s,o,a,c,l,h,u,d,f,m,p,g,v,y,x;if(a=(i=Ae(arguments))[0],r=i[1],t=i[2],o=o/100*255,e=255*(r/=100),0===r)u=o=n=t;else switch(360===a&&(a=0),a>360&&(a-=360),a<0&&(a+=360),h=(l=t*(1-r))+e*(1-(s=(a/=60)-(c=I(a)))),y=l+e*s,x=l+e,c){case 0:u=(d=[x,y,l])[0],o=d[1],n=d[2];break;case 1:u=(f=[h,x,l])[0],o=f[1],n=f[2];break;case 2:u=(m=[l,x,y])[0],o=m[1],n=m[2];break;case 3:u=(p=[l,h,x])[0],o=p[1],n=p[2];break;case 4:u=(g=[y,l,x])[0],o=g[1],n=g[2];break;case 5:u=(v=[x,l,h])[0],o=v[1],n=v[2]}return[u,o,n,i.length>3?i[3]:1]},se=function(){var e,t,i,n,r,s,o,a,c;return a=(c=Ae(arguments))[0],r=c[1],t=c[2],o=Math.min(a,r,t),i=100*(n=(Q=Math.max(a,r,t))-o)/255,e=o/(255-n)*100,0===n?s=Number.NaN:(a===Q&&(s=(r-t)/n),r===Q&&(s=2+(t-a)/n),t===Q&&(s=4+(a-r)/n),(s*=60)<0&&(s+=360)),[s,i,e]},_.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,Te.call(arguments).concat(["hcg"]),(function(){}))},d.hcg=E,i.prototype.hcg=function(){return se(this._rgb)},M=function(e){var t,i,n,r,s,o,a,c;if(e=e.toLowerCase(),null!=_.colors&&_.colors[e])return D(_.colors[e]);if(s=e.match(/rgb\(\s*(\-?\d+),\s*(\-?\d+)\s*,\s*(\-?\d+)\s*\)/)){for(a=s.slice(1,4),r=o=0;o<=2;r=++o)a[r]=+a[r];a[3]=1}else if(s=e.match(/rgba\(\s*(\-?\d+),\s*(\-?\d+)\s*,\s*(\-?\d+)\s*,\s*([01]|[01]?\.\d+)\)/))for(a=s.slice(1,5),r=c=0;c<=3;r=++c)a[r]=+a[r];else if(s=e.match(/rgb\(\s*(\-?\d+(?:\.\d+)?)%,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*\)/)){for(a=s.slice(1,4),r=t=0;t<=2;r=++t)a[r]=ye(2.55*a[r]);a[3]=1}else if(s=e.match(/rgba\(\s*(\-?\d+(?:\.\d+)?)%,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)/)){for(a=s.slice(1,5),r=i=0;i<=2;r=++i)a[r]=ye(2.55*a[r]);a[3]=+a[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,(a=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,(a=k(n))[3]=+s[4]);return a},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},ve=function(e){return ye(100*e)/100},R=function(e,t){var i;return i=t<1?"hsla":"hsl",e[0]=ve(e[0]||0),e[1]=ve(100*e[1])+"%",e[2]=ve(100*e[2])+"%","hsla"===i&&(e[3]=t),i+"("+e.join(",")+")"},d.css=function(e){return M(e)},_.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,Te.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)?R(this.hsl(),this.alpha()):void 0},d.named=function(e){return D(Me[e])},h.push({p:5,test:function(e){if(1===arguments.length&&null!=Me[e])return"named"}}),i.prototype.name=function(e){var t,i;for(i in arguments.length&&(Me[e]&&(this._rgb=D(Me[e])),this._rgb[3]=1),t=this.hex("rgb"),Me)if(t===Me[i])return i;return t},j=function(){var e,t,i,r;return i=(r=Ae(arguments))[0],e=r[1],t=r[2],[i,A(t*=n)*e,be(t)*e]},W=function(){var e,t,i,n,r,s,o,a,c;return o=(i=Ae(arguments))[0],r=i[1],s=i[2],e=(a=j(o,r,s))[0],t=a[1],n=a[2],[(c=V(e,t,n))[0],c[1],n=c[2],i.length>3?i[3]:1]},G=function(){var e,t,i,n,r,s;return r=(s=Ae(arguments))[0],e=s[1],t=s[2],i=_e(e*e+t*t),n=(p(t,e)*a+360)%360,0===ye(1e4*i)&&(n=Number.NaN),[r,i,n]},ue=function(){var e,t,i,n,r,s,o;return r=(s=Ae(arguments))[0],i=s[1],t=s[2],n=(o=he(r,i,t))[0],e=o[1],t=o[2],G(n,e,t)},_.lch=function(){var e;return e=Ae(arguments),new i(e,"lch")},_.hcl=function(){var e;return e=Ae(arguments),new i(e,"hcl")},d.lch=W,d.hcl=function(){var e,t,i,n;return t=(n=Ae(arguments))[0],e=n[1],i=n[2],W([i,e,t])},i.prototype.lch=function(){return ue(this._rgb)},i.prototype.hcl=function(){return ue(this._rgb).reverse()},ne=function(e){var t,i,n,r,s,o;return null==e&&(e="rgb"),s=(o=Ae(arguments))[0],n=o[1],t=o[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=Ae(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(Ae(arguments))},_.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,Te.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=Ae(arguments))r=e[t],i.push(r);return i}.apply(this,arguments),e=i=0;i<=2;e=++i)n[e]*=255;return n},_.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,Te.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=Ae(arguments))[0],t=n[1],i=n[2],.2126*(e=Z(e))+.7152*(t=Z(t))+.0722*(i=Z(i))},Z=function(e){return(e/=255)<=.03928?e/12.92:ie((e+.055)/1.055,2.4)},$=function(e,t,n,r){var s,o;return s=e._rgb,o=t._rgb,new i(s[0]+n*(o[0]-s[0]),s[1]+n*(o[1]-s[1]),s[2]+n*(o[2]-s[2]),r)},f.push(["rgb",$]),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 o,a;return o=(a=i.interpolate(r,.5,t)).luminance(),Math.abs(e-o)<1e-7||!n--?a:o>e?s(i,a):s(a,r)},r=i>e?s(_("black"),this).rgba():s(this,_("white")).rgba()),_(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,o;for(n=(r=Ae(arguments))[0],e=r[2],i=1e3,t=4e4,.4;t-i>.4;)(s=we(o=.5*(t+i)))[2]/s[0]>=e/n?t=o:i=o;return ye(o)},_.temperature=_.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,Te.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,_.contrast=function(e,t){var n,r,s,o;return"string"!==(s=Se(e))&&"number"!==s||(e=new i(e)),"string"!==(o=Se(t))&&"number"!==o||(t=new i(t)),(n=e.luminance())>(r=t.luminance())?(n+.05)/(r+.05):(r+.05)/(n+.05)},_.distance=function(e,t,n){var r,s,o,a,c,l,h;for(s in null==n&&(n="lab"),"string"!==(c=Se(e))&&"number"!==c||(e=new i(e)),"string"!==(l=Se(t))&&"number"!==l||(t=new i(t)),o=e.get(n),a=t.get(n),h=0,o)h+=(r=(o[s]||0)-(a[s]||0))*r;return Math.sqrt(h)},_.deltaE=function(e,t,n,r){var o,a,c,l,h,u,d,f,g,v,y,x,b,_,w,S,M,C,P,T,I,E,D,L;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)),o=(M=e.lab())[0],c=M[1],h=M[2],a=(C=t.lab())[0],l=C[1],u=C[2],d=_e(c*c+h*h),f=_e(l*l+u*u),T=o<16?.511:.040975*o/(1+.01765*o),P=.0638*d/(1+.0131*d)+.638,_=d<1e-6?0:180*p(h,c)/s;_<0;)_+=360;for(;_>=360;)_-=360;return I=_>=164&&_<=345?.56+m(.2*A(s*(_+168)/180)):.36+m(.4*A(s*(_+35)/180)),b=_e((g=d*d*d*d)/(g+1900)),_e((E=(o-a)/(n*T))*E+(D=(x=d-f)/(r*P))*D+((v=c-l)*v+(y=h-u)*y-x*x)/((L=P*(b*I+1-b))*L))},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,o;if(this,r=(s=e.split("."))[0],i=s[1])if(o=this[r](),(n=r.indexOf(i))>-1)if("string"===Se(t))switch(t.charAt(0)){case"+":case"-":o[n]+=+t;break;case"*":o[n]*=+t.substr(1);break;case"/":o[n]/=+t.substr(1);break;default:o[n]=+t}else o[n]=t;else console.warn("unknown channel "+i+" in mode "+r);else o=t;return _(o,r).alpha(this.alpha())},i.prototype.clipped=function(){return this._rgb._clipped||!1},i.prototype.alpha=function(e){return arguments.length?_.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,_.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),_.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(),_(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},xe=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))},P=function(e,t){return 255===e||(e=t/255*255/(1-e/255))>255?255:e},(v=function(e,t,i){if(!v[i])throw"unknown blend mode "+i;return v[i](e,t)}).normal=(y=function(e){return function(t,i){var n,r;return n=_(i).rgb(),r=_(t).rgb(),_(e(n,r),"rgb")}})((T=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}))),v.multiply=y(T(J)),v.screen=y(T(xe)),v.overlay=y(T(te)),v.darken=y(T(C)),v.lighten=y(T(q)),v.dodge=y(T(P)),v.burn=y(T(b)),_.blend=v,_.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 _.limits(n,e,t)},n},_.scale=function(e,t){var i,n,r,s,o,a,c,l,h,u,d,f,m,p,g,v,y,x,b,w,S;return h="rgb",u=_("#ccc"),p=0,o=[0,1],m=[],f=[0,0],i=!1,r=[],d=!1,l=0,c=1,s=!1,n={},g=!0,a=1,w=function(e){var t,i,n,s,o,a;if(null==e&&(e=["#fff","#000"]),null!=e&&"string"===Se(e)&&null!=_.brewer&&(e=_.brewer[e]||_.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]=_(i));for(m.length=0,t=a=0,o=e.length-1;0<=o?a<=o:a>=o;t=0<=o?++a:--a)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},x=function(e,t){var s,o,d,p,v,x,b;if(null==t&&(t=!1),isNaN(e)||null===e)return u;if(b=t?e:i&&i.length>2?y(e)/(i.length-2):c!==l?(e-l)/(c-l):1,t||(b=S(b)),1!==a&&(b=ie(b,a)),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(o=p=0,x=m.length-1;0<=x?p<=x:p>=x;o=0<=x?++p:--p){if(b<=(v=m[o])){s=r[o];break}if(b>=v&&o===m.length-1){s=r[o];break}if(b>v&&b=h;t=0<=h?++u:--u)m.push(t/(n-1));return o=[l,c],v},v.mode=function(e){return arguments.length?(h=e,b(),v):h},v.range=function(e,t){return w(e),v},v.out=function(e){return d=e,v},v.spread=function(e){return arguments.length?(p=e,v):p},v.correctLightness=function(e){return null==e&&(e=!0),s=e,b(),S=s?function(e){var t,i,n,r,s,o,a,c,l;for(t=x(0,!0).lab()[0],i=x(1,!0).lab()[0],a=t>i,n=x(e,!0).lab()[0],r=n-(s=t+(i-t)*e),c=0,l=1,o=20;Math.abs(r)>.01&&o-- >0;)a&&(r*=-1),r<0?(c=e,e+=.5*(l-e)):(l=e,e+=.5*(c-e)),n=x(e,!0).lab()[0],r=n-s;return e}:function(e){return e},v},v.padding=function(e){return null!=e?("number"===Se(e)&&(e=[e,e]),f=e,v):f},v.colors=function(t,n){var s,a,c,l,h,u,d,f;if(arguments.length<2&&(n="hex"),h=[],0===arguments.length)h=r.slice(0);else if(1===t)h=[v(.5)];else if(t>1)a=o[0],s=o[1]-a,h=function(){u=[];for(var e=0;0<=t?et;0<=t?e++:e--)u.push(e);return u}.apply(this).map((function(e){return v(a+e/(t-1)*s)}));else{if(e=[],d=[],i&&i.length>2)for(c=f=1,l=i.length;1<=l?fl;c=1<=l?++f:--f)d.push(.5*(i[c-1]+i[c]));else d=o;h=d.map((function(e){return v(e)}))}return _[n]&&(h=h.map((function(e){return e[n]()}))),h},v.cache=function(e){return null!=e?(g=e,v):g},v.gamma=function(e){return null!=e?(a=e,v):a},v.nodata=function(e){return null!=e?(u=_(e),v):u},v},null==_.scales&&(_.scales={}),_.scales.cool=function(){return _.scale([_.hsl(180,1,.9),_.hsl(250,.7,.4)])},_.scales.hot=function(){return _.scale(["#000","#f00","#ff0","#fff"],[0,.25,.75,1]).mode("rgb")},_.analyze=function(e,t,i){var n,r,s,o,a,c;if(a={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)||(a.values.push(e),a.sum+=e,ea.max&&(a.max=e),a.count+=1)},c=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(o=0,s=e.length;o=U;A=1<=U?++B:--B)P.push(E+A/i*(Q-E));P.push(Q)}else if("l"===t.substr(0,1)){if(E<=0)throw"Logarithmic scales are only possible for values > 0";for(D=Math.LOG10E*Y(E),T=Math.LOG10E*Y(Q),P.push(E),A=le=1,$=i-1;1<=$?le<=$:le>=$;A=1<=$?++le:--le)P.push(ie(10,D+A/i*(T-D)));P.push(Q)}else if("q"===t.substr(0,1)){for(P.push(E),A=n=1,q=i-1;1<=q?n<=q:n>=q;A=1<=q?++n:--n)N=(ce.length-1)*A/i,(F=I(N))===N?P.push(ce[F]):(z=N-F,P.push(ce[F]*(1-z)+ce[F+1]*z));P.push(Q)}else if("k"===t.substr(0,1)){for(R=ce.length,v=new Array(R),w=new Array(i),re=!0,k=0,x=null,(x=[]).push(E),A=r=1,X=i-1;1<=X?r<=X:r>=X;A=1<=X?++r:--r)x.push(E+A/i*(Q-E));for(x.push(Q);re;){for(M=s=0,Z=i-1;0<=Z?s<=Z:s>=Z;M=0<=Z?++s:--s)w[M]=0;for(A=o=0,K=R-1;0<=K?o<=K:o>=K;A=0<=K?++o:--o){for(ae=ce[A],L=Number.MAX_VALUE,M=a=0,J=i-1;0<=J?a<=J:a>=J;M=0<=J?++a:--a)(S=m(x[M]-ae))=ee;M=0<=ee?++c:--c)O[M]=null;for(A=l=0,te=R-1;0<=te?l<=te:l>=te;A=0<=te?++l:--l)null===O[b=v[A]]?O[b]=ce[A]:O[b]+=ce[A];for(M=h=0,ne=i-1;0<=ne?h<=ne:h>=ne;M=0<=ne?++h:--h)O[M]*=1/w[M];for(re=!1,M=u=0,G=i-1;0<=G?u<=G:u>=G;M=0<=G?++u:--u)if(O[M]!==x[A]){re=!0;break}x=O,++k>200&&(re=!1)}for(C={},M=d=0,V=i-1;0<=V?d<=V:d>=V;M=0<=V?++d:--d)C[M]=[];for(A=f=0,H=R-1;0<=H?f<=H:f>=H;A=0<=H?++f:--f)C[b=v[A]].push(ce[A]);for(se=[],M=p=0,j=i-1;0<=j?p<=j:p>=j;M=0<=j?++p:--p)se.push(C[M][0]),se.push(C[M][C[M].length-1]);for(se=se.sort((function(e,t){return e-t})),P.push(se[0]),A=g=1,W=se.length-1;g<=W;A=g+=2)oe=se[A],isNaN(oe)||-1!==P.indexOf(oe)||P.push(oe)}return P},L=function(e,t,i){var n,r,s,a;return e=(n=Ae(arguments))[0],t=n[1],i=n[2],isNaN(e)&&(e=0),(e/=360)<1/3?s=1-((r=(1-t)/3)+(a=(1+t*A(c*e)/A(o-c*e))/3)):e<2/3?r=1-((a=(1-t)/3)+(s=(1+t*A(c*(e-=1/3))/A(o-c*e))/3)):a=1-((s=(1-t)/3)+(r=(1+t*A(c*(e-=2/3))/A(o-c*e))/3)),[255*(a=X(i*a*3)),255*(s=X(i*s*3)),255*(r=X(i*r*3)),n.length>3?n[3]:1]},ae=function(){var e,t,i,n,r,s,o;return r=(s=Ae(arguments))[0],t=s[1],e=s[2],c=2*Math.PI,r/=255,t/=255,e/=255,0===(o=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=c-i),i/=c),[360*i,o,n]},_.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,Te.call(arguments).concat(["hsi"]),(function(){}))},d.hsi=L,i.prototype.hsi=function(){return ae(this._rgb)},N=function(e,t,i,n){var r,s,o,a,c,l,h,u,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],h=d[1],a=d[2],o=f[0],u=f[1],c=f[2]),isNaN(s)||isNaN(o)?isNaN(s)?isNaN(o)?r=Number.NaN:(r=o,1!==a&&0!==a||"hsv"===n||(l=u)):(r=s,1!==c&&0!==c||"hsv"===n||(l=h)):r=s+i*(o>s&&o-s>180?o-(s+360):o180?o+360-s:o-s),null==l&&(l=h+i*(u-h)),_[n](r,l,a+i*(c-a))},U=function(e,t,i,n){var r,s;return r=e.num(),s=t.num(),_.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 fc,mc=oc((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,o=this._indexOfListener(e,n);if(-1!==o){if((s=this._bindings[o]).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}(sc)}));!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"}(fc||(fc={}));const pc=["*","","ALL"],gc=["NONE"],vc=[fc.BACKBONE,fc.SIDECHAIN,fc.BONDED,fc.RING,fc.AROMATICRING,fc.METAL,fc.POLARH],yc=[fc.POLYMER,fc.WATER],xc=["ALA","GLY","SER"],bc=["CYS","SER","THR"],_c=["ALA","ILE","LEU","MET","PHE","PRO","TRP","VAL"],wc=["PHE","TRP","TYR","HIS"],Sc=["ASN","GLN"],Ac=["ASP","GLU"],Mc=["ARG","HIS","LYS"],Cc=["ARG","ASP","GLU","HIS","LYS"],Pc=["ASN","ARG","ASP","CYS","GLY","GLN","GLU","HIS","LYS","SER","THR","TYR"],Tc=["ALA","ILE","LEU","MET","PHE","PRO","TRP","VAL"],Ic=["HIS","PHE","PRO","TRP","TYR"],Ec=["ALA","GLY","ILE","LEU","VAL"];function Dc(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===fc.BACKBONE&&!e.isBackbone())return!1;if(t.keyword===fc.SIDECHAIN&&!e.isSidechain())return!1;if(t.keyword===fc.BONDED&&!e.isBonded())return!1;if(t.keyword===fc.RING&&!e.isRing())return!1;if(t.keyword===fc.AROMATICRING&&!e.isAromatic())return!1;if(t.keyword===fc.HETERO&&!e.isHetero())return!1;if(t.keyword===fc.PROTEIN&&!e.isProtein())return!1;if(t.keyword===fc.NUCLEIC&&!e.isNucleic())return!1;if(t.keyword===fc.RNA&&!e.isRna())return!1;if(t.keyword===fc.DNA&&!e.isDna())return!1;if(t.keyword===fc.POLYMER&&!e.isPolymer())return!1;if(t.keyword===fc.WATER&&!e.isWater())return!1;if(t.keyword===fc.HELIX&&!e.isHelix())return!1;if(t.keyword===fc.SHEET&&!e.isSheet())return!1;if(t.keyword===fc.TURN&&!e.isTurn())return!1;if(t.keyword===fc.ION&&!e.isIon())return!1;if(t.keyword===fc.SACCHARIDE&&!e.isSaccharide())return!1;if(t.keyword===fc.METAL&&!e.isMetal())return!1;if(t.keyword===fc.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&&Na(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 Nc(e,t=!1){let i=e;return t&&(i=Bc(e,(function(e){return void 0!==e.keyword&&!vc.includes(e.keyword)||(void 0!==e.model||(void 0!==e.chainname||(void 0!==e.resname||(void 0!==e.resno||void 0!==e.sstruc))))}))),Oc(i,Dc)}function Fc(e,t=!1){let i=e;return t&&(i=Bc(e,(function(e){return!(void 0===e.keyword||!vc.includes(e.keyword))||(void 0!==e.model||(void 0!==e.chainname||(void 0!==e.atomname||(void 0!==e.element||void 0!==e.altloc))))}))),Oc(i,Lc)}function zc(e,t=!1){let i=e;return t&&(i=Bc(e,(function(e){return void 0!==e.keyword&&!yc.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))))))}))),Oc(i,Rc)}function Uc(e,t=!1){let i=e;return t&&(i=Bc(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)))))))}))),Oc(i,kc)}class $c{constructor(e){this.signals={stringChanged:new mc.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 o=e.split(/\s+/),a=e=>{i={operator:e,rules:[]},void 0===r?(r=i,t=i):(r.rules.push(i),s.push(r),r=i)},c=function(e){n=r,r=s.pop(),void 0===r&&(a(e),l(n))},l=function(e){r.rules.push(e)};let h=!1;for(let e=0;e0)if("NOT"===i)h=1;else if(1===h)h=2;else{if(2!==h)throw new Error("something went wrong with 'not'");h=!1,c()}if("AND"===i){if("OR"===r.operator){const e=r.rules.pop();a("AND"),l(e)}else r.operator="AND";continue}if("OR"===i){"AND"===r.operator?c("OR"):r.operator="OR";continue}if("NOT"===t.toUpperCase()){h=1,a(),r.negate=!0;continue}if(+i!=+i){const e=fc[i];if(void 0!==e){l({keyword:e});continue}}if("HYDROGEN"===i){l({operator:"OR",rules:[{element:"H"},{element:"D"}]});continue}if("SMALL"===i){l({resname:xc});continue}if("NUCLEOPHILIC"===i){l({resname:bc});continue}if("HYDROPHOBIC"===i){l({resname:_c});continue}if("AROMATIC"===i){l({resname:wc});continue}if("AMIDE"===i){l({resname:Sc});continue}if("ACIDIC"===i){l({resname:Ac});continue}if("BASIC"===i){l({resname:Mc});continue}if("CHARGED"===i){l({resname:Cc});continue}if("POLAR"===i){l({resname:Pc});continue}if("NONPOLAR"===i){l({resname:Tc});continue}if("CYCLIC"===i){l({resname:Ic});continue}if("ALIPHATIC"===i){l({resname:Ec});continue}if("SIDECHAINATTACHED"===i){l({operator:"OR",rules:[{keyword:fc.SIDECHAIN},{operator:"AND",negate:!1,rules:[{keyword:fc.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:fc.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){l({operator:"AND",negate:!1,rules:[{element:"H"},{negate:!0,operator:void 0,rules:[{keyword:fc.POLARH}]}]});continue}if("LIGAND"===i){l({operator:"AND",rules:[{operator:"OR",rules:[{operator:"AND",rules:[{keyword:fc.HETERO},{negate:!0,operator:void 0,rules:[{keyword:fc.POLYMER}]}]},{negate:!0,operator:void 0,rules:[{keyword:fc.POLYMER}]}]},{negate:!0,operator:void 0,rules:[{operator:"OR",rules:[{keyword:fc.WATER},{keyword:fc.ION}]}]}]});continue}if(-1!==pc.indexOf(i)){l({keyword:fc.ALL});continue}if("@"===t.charAt(0)){const e=t.substr(1).split(",").map((e=>parseInt(e)));e.sort((function(e,t){return e-t})),l({atomindex:e});continue}if("#"===t.charAt(0)){console.error("# for element selection deprecated, use _"),l({element:i.substr(1)});continue}if("_"===t.charAt(0)){l({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];l({resname:n});continue}if(t.length>=1&&t.length<=4&&"^"!==t[0]&&":"!==t[0]&&"."!==t[0]&&"%"!==t[0]&&"/"!==t[0]&&isNaN(parseInt(t))){l({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 u=s[0].split("%");u.length>1&&n.rules.push({altloc:u[1]});const d=u[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)l(n.rules[0]);else{if(!(n.rules.length>1))throw new Error("empty selection chunk");l(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=Nc(i),this.residueTest=Fc(i),this.chainTest=zc(i),this.modelTest=Uc(i),this.atomOnlyTest=Nc(i,!0),this.residueOnlyTest=Fc(i,!0),this.chainOnlyTest=zc(i,!0),this.modelOnlyTest=Uc(i,!0),t||this.signals.stringChanged.dispatch(this.string)}isAllSelection(){return pc.includes(this.string.toUpperCase())}isNoneSelection(){return gc.includes(this.string.toUpperCase())}}class Gc extends dc{constructor(e){super(e),this.colormakerList=[],this.selectionList=[];(e.dataList||[]).forEach((e=>{const[t,i,n={}]=e;al.hasScheme(t)?Object.assign(n,{scheme:t,structure:this.parameters.structure}):Object.assign(n,{scheme:"uniform",value:new mn(t).getHex()}),this.colormakerList.push(al.getScheme(n)),this.selectionList.push(new $c(i))}))}atomColor(e){for(let t=0,i=this.selectionList.length;t{}),e)}catch(e){}const Kc="undefined"!=typeof window&&void 0!==window.orientation;let Qc=!1;function Jc(e){Qc=e}let el=!1;function tl(e){el=e}const il={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 nl={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 rl;e.Debug=!!(rl=Ta("debug"))&&("string"!=typeof rl||/^1|true|t|yes|y$/i.test(rl));const sl=["ngl","js"],ol=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]=Xc(this._funcDict[e],this._depsDict[e])),this._blobDict[e]}},al=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]:dc,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 Vc}getModes(){return Hc}add(e,t){e=e.toLowerCase(),this.schemes[e]=t}addScheme(e,t){return function(e){return e instanceof dc}(e)||(e=this._createScheme(e)),this._addUserScheme(e,t)}_addUserScheme(e,t){t=t||"";const i=`${ec()}|${t}`.toLowerCase();return this.userSchemes[i]=e,i}removeScheme(e){e=e.toLowerCase(),delete this.userSchemes[e]}_createScheme(e){return class extends dc{constructor(t){super(t),e.call(this,t)}}}addSelectionScheme(e,t){return this._addUserScheme(class extends Gc{constructor(t){super(Object.assign({dataList:e},t))}},t)}hasScheme(e){return(e=e.toLowerCase())in this.schemes||e in this.userSchemes}},cl=new Za("datasource"),ll=new Za("representatation"),hl=new class extends Za{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)))}},ul=new Za("shader"),dl=new Za("decompressor"),fl=new Za("component"),ml=new Za("buffer"),pl=new Za("picker");e.ListingDatasource=void 0,e.TrajectoryDatasource=void 0;class gl{constructor(e,t={}){this.chunkSize=10485760,this.newline="\n",this.__pointer=0,this.__partialLine="",this.compressed=Ia(t.compressed,!1),this.binary=Ia(t.binary,!1),this.json=Ia(t.json,!1),this.xml=Ia(t.xml,!1),this.src=e}isBinary(){return this.binary||this.compressed}read(){return this._read().then((e=>{const t=this.compressed?dl.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()?Ua(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()?Ua(e):e,o=s.lastIndexOf(n);if(-1===o)t+=s;else{const e=t+s.substr(0,o);r=r.concat(e.split(n)),t=o===s.length-n.length?"":s.substr(o+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 vl extends gl{_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 yl extends gl{_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 xl{constructor(e,t={}){this.parameters=Ea(t,{ext:"",compressed:!1,binary:hl.isBinary(t.ext||""),name:"",dir:"",path:"",protocol:""});const i={compressed:this.parameters.compressed,binary:this.parameters.binary,json:hl.isJson(this.parameters.ext),xml:hl.isXml(this.parameters.ext)};"undefined"!=typeof File&&e instanceof File||"undefined"!=typeof Blob&&e instanceof Blob?this.streamer=new vl(e,i):this.streamer=new yl(e,i)}}class bl extends xl{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(hl.get(this.parameters.ext))(this.streamer,this.parserParams).parse()}}class _l{constructor(e,t,i){this.name=t,this.path=i,this.signals={elementAdded:new mc.Signal,elementRemoved:new mc.Signal,nameChanged:new mc.Signal},this.type="Script",this.dir=i.substring(0,i.lastIndexOf("/")+1);try{this.fn=new Function("stage","__name","__path","__dir",e)}catch(e){il.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){il.error("Script.fn",e),i(e)}}))}}class wl extends xl{load(){return this.streamer.read().then((()=>new _l(this.streamer.asText(),this.parameters.name,this.parameters.path)))}}function Sl(e){const t=dl.names;let i,n,r="";i=e instanceof File?e.name:e instanceof Blob?"":e;const s=i.lastIndexOf("?"),o=-1!==s?i.substring(s):"";i=i.substring(0,-1===s?i.length:s);const a=i.replace(/^.*[\\/]/,"");let c=a.substring(0,a.lastIndexOf("."));const l=a.split(".");let h=l.length>1?(l.pop()||"").toLowerCase():"";const u=i.match(/^(.+):\/\/(.+)$/);u&&(r=u[1].toLowerCase(),i=u[2]||"");const d=i.substring(0,i.lastIndexOf("/")+1);if(t.includes(h)){n=h;const e=i.length-h.length-1;h=(i.substr(0,e).split(".").pop()||"").toLowerCase();const t=c.length-h.length-1;c=c.substr(0,t)}else n=!1;return{path:i,name:a,ext:h,base:c,dir:d,compressed:n,protocol:r,query:o,src:e}}function Al(e){let t=Sl(e);const i=cl.get(t.protocol);return i&&(t=Sl(i.getUrl(t.src)),!t.ext&&i.getExt&&(t.ext=i.getExt(e))),t}function Ml(e,t={}){const i=Object.assign(Al(e),t);let n;return hl.names.includes(i.ext)?n=new bl(i.src,i):sl.includes(i.ext)&&(n=new wl(i.src,i)),n?n.load():Promise.reject(new Error(`autoLoad: ext '${i.ext}' unknown`))}var Cl=oc((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,o,a,c,l,h,u,d,f=1,m=t.length,p="";for(s=0;s=0),a.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,a.width?parseInt(a.width):0);break;case"e":r=a.precision?parseFloat(r).toExponential(a.precision):parseFloat(r).toExponential();break;case"f":r=a.precision?parseFloat(r).toFixed(a.precision):parseFloat(r);break;case"g":r=a.precision?String(Number(r.toPrecision(a.precision))):parseFloat(r);break;case"o":r=(parseInt(r,10)>>>0).toString(8);break;case"s":r=String(r),r=a.precision?r.substring(0,a.precision):r;break;case"t":r=String(!!r),r=a.precision?r.substring(0,a.precision):r;break;case"T":r=Object.prototype.toString.call(r).slice(8,-1).toLowerCase(),r=a.precision?r.substring(0,a.precision):r;break;case"u":r=parseInt(r,10)>>>0;break;case"v":r=r.valueOf(),r=a.precision?r.substring(0,a.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(a.type)?p+=r:(!e.number.test(a.type)||u&&!a.sign?d="":(d=u?"+":"-",r=r.toString().replace(e.sign,"")),l=a.pad_char?"0"===a.pad_char?"0":a.pad_char.charAt(1):" ",h=a.width-(d+r).length,c=a.width&&h>0?l.repeat(h):"",p+=a.align?d+r+c:"0"===l?d+c+r:c+d+r)}return p}(function(t){if(r[t])return r[t];var i,n=t,s=[],o=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]){o|=1;var a=[],c=i[2],l=[];if(null===(l=e.key.exec(c)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(a.push(l[1]);""!==(c=c.substring(l[0].length));)if(null!==(l=e.key_access.exec(c)))a.push(l[1]);else{if(null===(l=e.index_access.exec(c)))throw new SyntaxError("[sprintf] failed to parse named argument key");a.push(l[1])}i[2]=a}else o|=2;if(3===o)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 Pl{getBlob(){return new Blob([this.getData()],{type:this.mimeType})}download(e,t){e=Ia(e,this.defaultName),t=Ia(t,this.defaultExt),Oa(this.getBlob(),`${e}.${t}`)}}const Tl=[];class Il{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 El{constructor(){this.count=0,this.signals={countChanged:new mc.Signal}}clear(){this.change(-this.count)}change(e){this.count+=e,this.signals.countChanged.dispatch(e,this.count),this.count<0&&il.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()}}ul.add("shader/BasicLine.vert","void main(){\n#include begin_vertex\n#include project_vertex\n}"),ul.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 encodings_fragment\n#include fog_fragment\n}"),ul.add("shader/Quad.vert","varying vec2 vUv;\nvoid main() {\nvUv = uv;\ngl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"),ul.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 Dl{constructor(){this.signals={updated:new mc.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}}ul.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"),ul.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}"),ul.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}"),ul.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"),ul.add("shader/chunk/nearclip_fragment.glsl","#ifdef NEAR_CLIP\nif( vViewPosition.z < clipNear )\ndiscard;\n#endif"),ul.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"),ul.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"),ul.add("shader/chunk/radiusclip_fragment.glsl","#ifdef RADIUS_CLIP\nif( distance( vViewPosition, vClipCenter ) > clipRadius )\ndiscard;\n#endif"),ul.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 Ll=/^(?!\/\/)\s*#include\s+(\S+)/gim,Rl={};function kl(e,t={}){let i=e+"|";for(const e in t)i+=e+":"+t[e];if(!Rl[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=ul.get(`shader/${e}`);if(!r)throw new Error(`empty shader, '${e}'`);r=r.replace(Ll,(function(e,t){const i=`shader/chunk/${t}.glsl`,n=ul.get(i)||Rr[t];if(!n)throw new Error(`empty chunk, '${t}'`);return n})),Rl[i]=n+r}return Rl[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 Ol=[[[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]]];Ol.forEach((e=>{e.forEach((e=>{e[0]*=.0625,e[1]*=.0625}))}));class Bl{constructor(e,t,i,n){this.canvas=document.createElement("canvas"),this._viewer=i,this._factor=Ia(n.factor,2),this._antialias=Ia(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,o=Math.floor(e/r)*n;if(t.camera.setViewOffset(i*r,n*r,s,o,i,n),t.render(),this._antialias){const e=Math.round((s+i)/2)-Math.round(s/2),r=Math.round((o+n)/2)-Math.round(o/2);this._ctx.drawImage(t.renderer.domElement,Math.round(s/2),Math.round(o/2),e,r)}else this._ctx.drawImage(t.renderer.domElement,Math.floor(s),Math.floor(o),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 Nl=2*Math.PI,Fl=180/Math.PI;function zl(e,t,i=1,n=0,r){const s=r?r.length:e.length/i;let o=0,a=0;if(r)for(let c=0;ct&&(t=e[i]);return t}function Zl(e){let t=1/0;for(let i=0,n=e.length;i=0;l--){for(c=o-1;c>=0;c--)if(u=4*(l*o+c),a[u]!==t||a[u+1]!==i||a[u+2]!==n||a[u+3]!==r){h=!0;break}if(h)break}const m=l;for(h=!1,c=o-1;c>=0;c--){for(l=s-1;l>=0;l--)if(u=4*(l*o+c),a[u]!==t||a[u+1]!==i||a[u+2]!==n||a[u+3]!==r){h=!0;break}if(h)break}const p=c,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 l=new Bl(o,a,e,{factor:n,antialias:r,onProgress:d,onFinish:function(n,r){u(l.canvas).toBlob((function(n){o.setClearAlpha(c),h(!0),e.requestRender(),d(r,r,!0),n?t(n):i("error creating image")}),"image/png")}});o.setClearAlpha(s?0:1),h(),l.renderAsync()}))}const th=new Zt,ih=new ri,nh=new ri;const rh=new zt,sh=new ri,oh=new ri;function ah(e,t){sh.getInverse(t.projectionMatrix),oh.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(sh),i.projectionMatrixTranspose&&i.projectionMatrixTranspose.value.copy(oh))}))}function ch(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 lh(e,t){const i=e.getExtension(t);return i||console.log(`extension '${t}' not available`),i}const hh=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]);function uh(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;lh(i,"OES_texture_float"),lh(i,"OES_texture_half_float"),lh(i,"WEBGL_color_buffer_float");const n=ch(i,"\nattribute vec4 a_position;\n\nvoid main() {\n gl_Position = a_position;\n}",i.VERTEX_SHADER),r=ch(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 o=i.getAttribLocation(s,"a_position"),a=i.getUniformLocation(s,"u_color");if(!a)return console.log("error getting 'u_color' uniform location"),!1;const c=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,c),i.bufferData(i.ARRAY_BUFFER,hh,i.STATIC_DRAW),i.enableVertexAttribArray(o),i.vertexAttribPointer(o,2,i.FLOAT,!1,0,0);const l=i.createTexture(),h=new Uint8Array([255,255,255,255]);i.bindTexture(i.TEXTURE_2D,l),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,1,1,0,i.RGBA,i.UNSIGNED_BYTE,h);const u=i.createTexture();i.bindTexture(i.TEXTURE_2D,u),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,u,0);if(i.checkFramebufferStatus(i.FRAMEBUFFER)!==i.FRAMEBUFFER_COMPLETE)return console.log(`error creating framebuffer for ${e}`),!1;i.bindTexture(i.TEXTURE_2D,l),i.uniform4fv(a,[0,10,20,1]),i.drawArrays(i.TRIANGLES,0,6),i.bindTexture(i.TEXTURE_2D,u),i.bindFramebuffer(i.FRAMEBUFFER,null),i.clearColor(1,0,0,1),i.clear(i.COLOR_BUFFER_BIT),i.uniform4fv(a,[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 dh=new Float32Array(100),fh=new Uint8Array(100),mh=[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],ph=new ri;function gh(e,t,i,n,r){const s=r.uniforms,o=[];if(s&&(s.objectId&&(s.objectId.value=Qc?this.id:this.id/255,o.push("objectId")),(s.modelViewMatrixInverse||s.modelViewMatrixInverseTranspose||s.modelViewProjectionMatrix||s.modelViewProjectionMatrixInverse)&&this.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,this.matrixWorld),s.modelViewMatrixInverse&&(s.modelViewMatrixInverse.value.getInverse(this.modelViewMatrix),o.push("modelViewMatrixInverse")),s.modelViewMatrixInverseTranspose&&(s.modelViewMatrixInverse?s.modelViewMatrixInverseTranspose.value.copy(s.modelViewMatrixInverse.value).transpose():s.modelViewMatrixInverseTranspose.value.getInverse(this.modelViewMatrix).transpose(),o.push("modelViewMatrixInverseTranspose")),s.modelViewProjectionMatrix&&(s.modelViewProjectionMatrix.value.multiplyMatrices(i.projectionMatrix,this.modelViewMatrix),o.push("modelViewProjectionMatrix")),s.modelViewProjectionMatrixInverse&&(s.modelViewProjectionMatrix?(ph.copy(s.modelViewProjectionMatrix.value),s.modelViewProjectionMatrixInverse.value.getInverse(ph)):(ph.multiplyMatrices(i.projectionMatrix,this.modelViewMatrix),s.modelViewProjectionMatrixInverse.value.getInverse(ph)),o.push("modelViewProjectionMatrixInverse")),o.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();o.forEach((function(e){r.setValue(i,e,s[e].value)}))}}}class vh{constructor(e){if(this.boundingBox=new Ni,this.boundingBoxSize=new Zt,this.boundingBoxLength=0,this.info={memory:{programs:0,geometries:0,textures:0},render:{calls:0,vertices:0,faces:0,points:0}},this.distVector=new Zt,this.signals={ticked:new mc.Signal,rendered:new mc.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)):il.error("Viewer: could not initialize renderer")}_initParams(){this.parameters={fogColor:new mn(0),fogNear:50,fogFar:100,backgroundColor:new mn(0),cameraType:"perspective",cameraFov:40,cameraEyeSep:.3,cameraZ:-80,clipNear:0,clipFar:100,clipDist:10,clipMode:"scene",clipScale:"relative",lightColor:new mn(14540253),lightIntensity:1,ambientColor:new mn(14540253),ambientIntensity:.2,sampleLevel:0,rendererEncoding:_t}}_initCamera(){const e=new Zt(0,0,0),{width:t,height:i}=this;this.perspectiveCamera=new Sr(this.parameters.cameraFov,t/i),this.perspectiveCamera.position.z=this.parameters.cameraZ,this.perspectiveCamera.lookAt(e),this.orthographicCamera=new wa(t/-2,t/2,i/2,i/-2),this.orthographicCamera.position.z=this.parameters.cameraZ,this.orthographicCamera.lookAt(e),this.stereoCamera=new Ca,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 Dl}_initScene(){this.scene||(this.scene=new Si,this.scene.name="scene"),this.rotationGroup=new ko,this.rotationGroup.name="rotationGroup",this.scene.add(this.rotationGroup),this.translationGroup=new ko,this.translationGroup.name="translationGroup",this.rotationGroup.add(this.translationGroup),this.modelGroup=new ko,this.modelGroup.name="modelGroup",this.translationGroup.add(this.modelGroup),this.pickingGroup=new ko,this.pickingGroup.name="pickingGroup",this.translationGroup.add(this.pickingGroup),this.backgroundGroup=new ko,this.backgroundGroup.name="backgroundGroup",this.translationGroup.add(this.backgroundGroup),this.helperGroup=new ko,this.helperGroup.name="helperGroup",this.translationGroup.add(this.helperGroup),this.scene.fog=new zo(this.parameters.fogColor.getHex()),this.spotLight=new _a(this.parameters.lightColor.getHex(),this.parameters.lightIntensity),this.scene.add(this.spotLight),this.ambientLight=new Sa(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 Fo({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.outputEncoding=this.parameters.rendererEncoding;const r=this.renderer.getContext();this.renderer.capabilities.isWebGL2?(tl(!0),Jc(this.renderer.extensions.get("EXT_color_buffer_float")),this.supportsHalfFloat=!0):(tl(this.renderer.extensions.get("EXT_frag_depth")),this.renderer.extensions.get("OES_element_index_uint"),Jc(this.renderer.extensions.get("OES_texture_float")&&this.renderer.extensions.get("WEBGL_color_buffer_float")||this.renderer.extensions.get("OES_texture_float")&&uh(r.FLOAT)),this.renderer.extensions.get("OES_texture_float"),this.supportsHalfFloat=this.renderer.extensions.get("OES_texture_half_float")&&uh(36193)),this.wrapper.appendChild(this.renderer.domElement);const s=i*t,o=n*t;e.Debug&&console.log(JSON.stringify({Browser:Yc,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":uh(r.FLOAT),"testTextureSupport HalfFloat":uh(36193),"this.supportsHalfFloat":this.supportsHalfFloat,SupportsReadPixelsFloat:Qc},null,2)),this.pickingTarget=new Wt(s,o,{minFilter:re,magFilter:re,stencilBuffer:!1,format:Ae,type:Qc?ge:he}),this.pickingTarget.texture.generateMipmaps=!1,this.pickingTarget.texture.encoding=this.parameters.rendererEncoding,this.renderer.setRenderTarget(this.pickingTarget),this.renderer.clear(),this.renderer.setRenderTarget(null),this.sampleTarget=new Wt(s,o,{minFilter:ae,magFilter:ae,format:Ae}),this.sampleTarget.texture.encoding=this.parameters.rendererEncoding,this.holdTarget=new Wt(s,o,{minFilter:re,magFilter:re,format:Ae,type:he}),this.holdTarget.texture.encoding=this.parameters.rendererEncoding,this.compositeUniforms={tForeground:new Pa(this.sampleTarget.texture),scale:new Pa(1)},this.compositeMaterial=new _r({uniforms:this.compositeUniforms,vertexShader:kl("Quad.vert"),fragmentShader:kl("Quad.frag"),premultipliedAlpha:!0,transparent:!0,blending:d,depthTest:!1,depthWrite:!1}),this.compositeCamera=new wa(-1,1,1,-1,0,1),this.compositeScene=new Si,this.compositeScene.name="compositeScene",this.compositeScene.add(new ar(new Dr(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 Vn;i.setIndex(new An(e,1)),i.setAttribute("position",new An(t,3));const n=new _r({uniforms:{uColor:{value:new mn("skyblue")}},vertexShader:kl("BasicLine.vert"),fragmentShader:kl("BasicLine.frag")});this.boundingBoxMesh=new Yo(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 ko?n.children.forEach(i):(n.userData.buffer=e,n.userData.instance=t,n.onBeforeRender=gh)}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=Qc?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(Qc){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&&il.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=Qc?dh:fh;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=Ka(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 zt;i.getSize(s);const o=s.height,a=i.getPixelRatio(),c="OrthographicCamera"===t.type;rh.set(s.width,s.height),sh.getInverse(t.projectionMatrix),oh.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=o),i.resolution&&i.resolution.value.copy(rh),i.pixelRatio&&(i.pixelRatio.value=a),i.projectionMatrixInverse&&i.projectionMatrixInverse.value.copy(sh),i.projectionMatrixTranspose&&i.projectionMatrixTranspose.value.copy(oh),i.ortho&&(i.ortho.value=c)}}))}(this.scene,e,this.renderer,this.cDist,this.bRadius),function(e,t){e.traverseVisible((function(e){if(!(e instanceof ta&&e.userData.buffer.parameters.sortParticles))return;const i=e.geometry.attributes,n=i.position.count;if(0===n)return;let r,s,o,a,c,l,h,u;ih.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld),nh.multiplyMatrices(t.projectionMatrix,ih),e.userData.sortData?(r=e.userData.sortData,o=r.__zArray,s=r.__sortArray,a=r.__cmpFn):(o=new Float32Array(n),s=new Uint32Array(n),a=function(e,t){const i=o[e],n=o[t];return i>n?1:it?1:e=l&&t(e[o],s)>0;)e[o+1]=e[o],--o;e[o+1]=s}if(-1===c)break;h=r[c--],l=r[c--]}else{for(o=l+1,a=h,u(l+h>>1,o),t(e[l],e[h])>0&&u(l,h),t(e[o],e[h])>0&&u(o,h),t(e[l],e[o])>0&&u(l,o),s=e[o];;){do{o++}while(t(e[o],s)<0);do{a--}while(t(e[a],s)>0);if(a=a-l?(r[++c]=o,r[++c]=h,h=a-1):(r[++c]=l,r[++c]=a-1,l=o)}}(s,a);for(let e in i){const t=i[e],o=t.array,a=t.itemSize;r[e]||(r[e]=new Float32Array(a*n)),u=r[e],r[e]=o;for(let e=0;e0&&"stereo"!==this.parameters.cameraType?this.__renderSuperSample(t,i):this.__renderModelGroup(t,i)}render(e=!1,t){if(this.rendering)il.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(){il.log("scene cleared"),this.scene.remove(this.rotationGroup),this._initScene(),this.renderer.clear()}dispose(){this.renderer.dispose(),window.cancelAnimationFrame(this.frameRequest)}}function yh(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 xh{constructor(e,t={}){this.domElement=e,this.signals={moved:new mc.Signal,scrolled:new mc.Signal,dragged:new mc.Signal,dropped:new mc.Signal,clicked:new mc.Signal,hovered:new mc.Signal,doubleClicked:new mc.Signal},this.position=new zt,this.prevPosition=new zt,this.down=new zt,this.canvasPosition=new zt,this.prevClickCP=new zt,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=Ia(t.hoverTimeout,50),this.handleScroll=Ia(t.handleScroll,!0),this.doubleClickSpeed=Ia(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=Ia(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 bh=new ri,_h=new ri,wh=new ri,Sh=new ri,Ah=new ri,Mh=new Zt,Ch=new qt,Ph=new qt,Th=new ri,Ih=new Zt,Eh=new Zt;class Dh{constructor(e,t={}){this.stage=e,this.rotateSpeed=Ia(t.rotateSpeed,2),this.zoomSpeed=Ia(t.zoomSpeed,1.2),this.panSpeed=Ia(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);Ih.set(e,t,0),Ih.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(_h.makeRotationY(Math.PI)),e}_transformPanVector(){this.component&&(Th.extractRotation(this.component.transform),Th.premultiply(this.viewer.rotationGroup.matrix),Th.getInverse(Th),Th.multiply(this._getCameraRotation(Sh)),Ih.applyMatrix4(Th))}zoom(e){this.controls.zoom(this.zoomSpeed*e*.02)}pan(e,t){this._setPanVector(e,t),Th.getInverse(this.viewer.rotationGroup.matrix),Th.multiply(this._getCameraRotation(Sh)),Ih.applyMatrix4(Th),this.controls.translate(Ih)}panComponent(e,t){this.component&&(this._setPanVector(e,t),this._transformPanVector(),this.component.position.add(Ih),this.component.updateMatrix())}panAtom(e,t){this.atom&&this.component&&(this.atom.positionToVector3(Eh),Eh.add(this.viewer.translationGroup.position),Eh.applyMatrix4(this.viewer.rotationGroup.matrix),this._setPanVector(e,t,Eh.z),this._transformPanVector(),this.atom.positionAdd(Ih),this.component.updateRepresentations({position:!0}))}rotate(e,t){const[i,n]=this._getRotateXY(e,t);this._getCameraRotation(Sh),Mh.set(1,0,0),Mh.applyMatrix4(Sh),Ch.setFromAxisAngle(Mh,n),Mh.set(0,1,0),Mh.applyMatrix4(Sh),Ph.setFromAxisAngle(Mh,i),Ch.multiply(Ph),Sh.makeRotationFromQuaternion(Ch),this.controls.applyMatrix(Sh)}zRotate(e,t){const i=this.rotateSpeed*((-e+t)/-2)*.01;wh.makeRotationZ(i),this.controls.applyMatrix(wh)}rotateComponent(e,t){if(!this.component)return;const[i,n]=this._getRotateXY(e,t);this._getCameraRotation(Ah),Sh.extractRotation(this.component.transform),Sh.premultiply(this.viewer.rotationGroup.matrix),Sh.getInverse(Sh),Sh.premultiply(Ah),Mh.set(1,0,0),Mh.applyMatrix4(Sh),bh.makeRotationAxis(Mh,n),Mh.set(0,1,0),Mh.applyMatrix4(Sh),_h.makeRotationAxis(Mh,i),bh.multiply(_h),Ch.setFromRotationMatrix(bh),this.component.quaternion.premultiply(Ch),this.component.quaternion.normalize(),this.component.updateMatrix()}}const Lh=new Zt;class Rh{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),o=t.getPositionOnCanvas(r);return c=s,l=o,(a=i).distanceTo(c)=e.length))return new Rh(i,this.stage);console.error("pid >= picker.array.length")}}}const Oh=new qt,Bh=new Zt,Nh=new Zt,Fh=new Zt,zh=new Zt,Uh=new ri,$h=new Zt,Gh=new ri;class Vh{constructor(e){this.stage=e,this.signals={changed:new mc.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=Ha(t,zt);const n=this.viewer;return Fh.copy(e).add(n.translationGroup.position).applyMatrix4(n.rotationGroup.matrix).project(n.camera),i.set((Fh.x+1)*n.width/2,(Fh.y+1)*n.height/2)}getCanvasScaleFactor(e=0){const t=this.viewer.camera;if(t instanceof wa)return 1/t.zoom;{e=Math.abs(e),e+=this.getCameraDistance();const i=Ka(t.fov);return 2*e*Math.tan(i/2)/this.viewer.height}}getOrientation(e){const t=Wa(e);t.copy(this.viewer.rotationGroup.matrix);const i=this.getCameraDistance();return t.scale(zh.set(i,i,i)),t.setPosition(this.viewer.translationGroup.position),t}orient(e){Wa(e).decompose(Bh,Oh,Nh);const t=this.viewer;t.rotationGroup.setRotationFromQuaternion(Oh),t.translationGroup.position.copy(Bh),t.cameraDistance=Nh.z,t.updateZoom(),this.changed()}translate(e){this.viewer.translationGroup.position.add(ja(e)),this.changed()}center(e){this.viewer.translationGroup.position.copy(ja(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){Uh.getInverse(this.viewer.rotationGroup.matrix),$h.copy(ja(e)).applyMatrix4(Uh),this.viewer.rotationGroup.rotateOnAxis($h,t),this.changed()}rotate(e){this.viewer.rotationGroup.setRotationFromQuaternion(qa(e)),this.changed()}align(e){Gh.getInverse(Wa(e)),this.viewer.rotationGroup.setRotationFromMatrix(Gh),this.changed()}applyMatrix(e){this.viewer.rotationGroup.applyMatrix4(Wa(e)),this.changed()}}class Hh{constructor(e,t,...i){this.pausedTime=-1,this.elapsedDuration=0,this.pausedDuration=0,this.ignoreGlobalToggle=!1,this._paused=!1,this._resolveList=[],this.duration=Ia(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=rc(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 jh extends Hh{constructor(e,t,...i){super(Ia(e,1/0),t,...i)}_init(e,t){Array.isArray(e)?this.axis=(new Zt).fromArray(e):this.axis=Ia(e,new Zt(0,1,0)),this.angle=Ia(t,.01)}_tick(e){this.axis&&this.angle&&this.controls.spin(this.axis,this.angle*e.lastDuration/16)}}class Wh extends Hh{constructor(e,t,...i){super(Ia(e,1/0),t,...i),this.angleSum=0,this.direction=1}_init(e,t,i){Array.isArray(e)?this.axis=(new Zt).fromArray(e):this.axis=Ia(e,new Zt(0,1,0)),this.angleStep=Ia(t,.01),this.angleEnd=Ia(i,.2)}_tick(e){if(!this.axis||!this.angleStep||!this.angleEnd)return;const t=rc(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 qh extends Hh{_init(e,t){this.moveFrom=ja(Ia(e,new Zt)),this.moveTo=ja(Ia(t,new Zt))}_tick(){this.controls.position.lerpVectors(this.moveFrom,this.moveTo,this.alpha).negate(),this.controls.changed()}}class Xh extends Hh{_init(e,t){this.zoomFrom=e,this.zoomTo=t}_tick(){this.controls.distance(ic(this.zoomFrom,this.zoomTo,this.alpha))}}class Yh extends Hh{constructor(){super(...arguments),this._currentRotation=new qt}_init(e,t){this.rotateFrom=qa(e),this.rotateTo=qa(t),this._currentRotation=new qt}_tick(){this._currentRotation.copy(this.rotateFrom).slerp(this.rotateTo,this.alpha),this.controls.rotate(this._currentRotation)}}class Zh extends Hh{_init(e,t,i){this.valueFrom=e,this.valueTo=t,this.callback=i}_tick(){this.callback(ic(this.valueFrom,this.valueTo,this.alpha))}}class Kh extends Hh{_init(e){this.callback=e}_tick(){1===this.alpha&&this.callback()}}class Qh{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 Jh{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 eu{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 tu{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:al.getScales()},colorReverse:{type:"boolean",update:"color"},colorValue:{type:"color",update:"color"},colorDomain:{type:"hidden",update:"color"},colorMode:{type:"select",update:"color",options:al.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 El,this.queue=new eu(this.make.bind(this)),this.bufferList=[],this.parameters.colorScheme&&(this.parameters.colorScheme.options=al.getSchemes()),this.toBePrepared=!1}init(e){const t=e||{};this.clipNear=Ia(t.clipNear,0),this.clipRadius=Ia(t.clipRadius,0),this.clipCenter=Ia(t.clipCenter,new Zt),this.flatShaded=Ia(t.flatShaded,!1),this.side=Ia(t.side,"double"),this.opacity=Ia(t.opacity,1),this.depthWrite=Ia(t.depthWrite,!0),this.wireframe=Ia(t.wireframe,!1),this.setColor(t.color,t),this.colorData=Ia(t.colorData,void 0),this.colorScheme=Ia(t.colorScheme,"uniform"),this.colorScale=Ia(t.colorScale,""),this.colorReverse=Ia(t.colorReverse,!1),this.colorValue=Ia(t.colorValue,9474192),this.colorDomain=Ia(t.colorDomain,void 0),this.colorMode=Ia(t.colorMode,"hcl"),this.visible=Ia(t.visible,!0),this.quality=Ia(t.quality,void 0),this.roughness=Ia(t.roughness,.4),this.metalness=Ia(t.metalness,0),this.diffuse=Ia(t.diffuse,16777215),this.diffuseInterior=Ia(t.diffuseInterior,!1),this.useInteriorColor=Ia(t.useInteriorColor,!1),this.interiorColor=Ia(t.interiorColor,2236962),this.interiorDarkening=Ia(t.interiorDarkening,0),this.lazy=Ia(t.lazy,!1),this.lazyProps={build:!1,bufferParams:{},what:{}},this.matrix=Ia(t.matrix,new ri),this.disablePicking=Ia(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=Ia(t.sphereDetail,1)),i.radialSegments&&(this.radialSegments=Ia(t.radialSegments,10))),i.openEnded&&(this.openEnded=Ia(t.openEnded,!0)),i.disableImpostor&&(this.disableImpostor=Ia(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(al.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 mn(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&&il.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&&il.time("Representation.attach "+this.type),this.attach((()=>{e.Debug&&il.timeEnd("Representation.attach "+this.type),this.tasks.decrement(),i&&i()})))),e.Debug&&il.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&&el&&!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 iu{constructor(t){this.pending=0,this.postCount=0,this.onmessageDict={},this.onerrorDict={},this.name=t,this.blobUrl=window.URL.createObjectURL(ol.get(t)),this.worker=new Worker(this.blobUrl),ol.activeWorkerCount+=1,this.worker.onmessage=i=>{this.pending-=1;const n=i.data.__postId;e.Debug&&il.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):il.error("Worker.onerror",i,t,e),delete this.onmessageDict[i],delete this.onerrorDict[i]}else il.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&&il.time(`Worker.postMessage ${this.name} #${this.postCount}`);try{this.worker.postMessage(t,i)}catch(e){il.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),ol.activeWorkerCount-=1):il.log("no worker to terminate")}}class nu{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 iu(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=c),l>s&&(s=l),h>o&&(o=h)}return[hu([t,i,n]),hu([r,s,o])]}function au(e,t){for(let i=0,n=t.length;i0){const o=1/Math.sqrt(s);e[t]=i*o,e[t+1]=n*o,e[t+2]=r*o}}}function hu(e){return new Float32Array(e||3)}function uu(e,t,i){const n=t[0],r=t[1],s=t[2],o=i[0],a=i[1],c=i[2];e[0]=r*c-s*a,e[1]=s*o-n*c,e[2]=n*a-r*o}function du(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function fu(e,t,i){e[0]=t[0]-i[0],e[1]=t[1]-i[1],e[2]=t[2]-i[2]}function mu(e,t,i){e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2]}function pu(e,t,i=0){e[0]=t[i],e[1]=t[i+1],e[2]=t[i+2]}function gu(e,t,i=0){t[i]=e[0],t[i+1]=e[1],t[i+2]=e[2]}function vu(e){return e[0]*e[0]+e[1]*e[1]+e[2]*e[2]}function yu(e){return Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2])}function xu(e,t,i){bu(e,t,1/i)}function bu(e,t,i){e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i}function _u(e,t){const i=vu(t);0==i?(e[0]=t[0],e[1]=t[1],e[2]=t[2]):bu(e,t,1/Math.sqrt(i))}function wu(e,t,i){e[0]=t[0]-i,e[1]=t[1]-i,e[2]=t[2]-i}function Su(e,t,i){e[0]=t[0]+i,e[1]=t[1]+i,e[2]=t[2]+i}function Au(e,t){e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2])}function Mu(e,t){e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2])}function Cu(e,t){e[0]=-t[0],e[1]=-t[1],e[2]=-t[2]}function Pu(e,t){const i=e[0],n=e[1],r=e[2],s=t[0],o=t[1],a=t[2],c=n*a-r*o,l=r*s-i*a,h=i*o-n*s,u=Math.sqrt(c*c+l*l+h*h),d=i*s+n*o+r*a;return Math.atan2(u,d)}function Tu(e,t=9){const i=Math.floor(t/2),n=e.position1.length/3,r=3*(i*n),s=1/t,o=$l(e.position1,e.position2),a=new Float32Array(r),c=new Float32Array(r),l=new Zt;for(let t=0;t0){const t=3*f;r[t]=e.position2[3*h-3],r[t+1]=e.position2[3*h-2],r[t+1]=e.position2[3*h-1]}const g=new Float32Array(n),v=new Float32Array(r),y=Ul(g,v),x=new Float32Array(s),b={position:y,position1:g,position2:v,color:x,color2:x};return o&&(b.radius=new Float32Array(o)),a&&e.picking&&(e.picking.array=new Float32Array(a),b.picking=e.picking),c&&(b.primitiveId=new Float32Array(c)),b}nu.prototype.constructor=nu,ou.__deps=[hu],xu.__deps=[bu],_u.__deps=[bu,vu];const Du=new Zt;class Lu{static get Picker(){return pl.get(this.type)}static get Buffer(){return ml.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":s=n,void 0!==(r=i).toArray?r=r.toArray():void 0!==r.x?r=[r.x,r.y,r.z]:void 0!==r.r&&(r=[r.r,r.g,r.b]),s.push.apply(s,r);break;default:n.push(i)}var r,s}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 Zt).fromArray(n,3*t);case"c":return(new mn).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)}}Lu.type="",Lu.fields={};class Ru extends Lu{static positionFromShape(e,t){return this.valueFromShape(e,t,"position")}static expandBoundingBox(e,t){e.expandByPoint(Du.fromArray(t.position))}}Ru.type="sphere",Ru.fields={position:"v3",color:"c",radius:"f"};class ku extends Lu{static positionFromShape(e,t){return this.valueFromShape(e,t,"position")}static expandBoundingBox(e,t){e.expandByPoint(Du.fromArray(t.position))}}ku.type="box",ku.fields={position:"v3",color:"c",size:"f",heightAxis:"v3",depthAxis:"v3"};class Ou extends ku{}Ou.type="octahedron";class Bu extends ku{}Bu.type="tetrahedron";class Nu extends Lu{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(Du.fromArray(t.position1)),e.expandByPoint(Du.fromArray(t.position2))}static bufferFromShape(e,t={}){let i=this.dataFromShape(e);return"cylinder"===this.type&&t.dashedCylinder&&(i=Iu(i)),new this.Buffer(i,t)}}Nu.type="cylinder",Nu.fields={position1:"v3",position2:"v3",color:"c",radius:"f"};class Fu extends Nu{}Fu.type="arrow";class zu extends Nu{}zu.type="cone";class Uu extends Ru{}Uu.type="ellipsoid",Uu.fields={position:"v3",color:"c",radius:"f",majorAxis:"v3",minorAxis:"v3"};class $u extends Uu{}$u.type="torus";class Gu extends Lu{static positionFromShape(e,t){return this.valueFromShape(e,t,"position")}static expandBoundingBox(e,t){e.expandByPoint(Du.fromArray(t.position))}}Gu.type="text",Gu.fields={position:"v3",color:"c",size:"f",text:"s"};class Vu extends Lu{static positionFromShape(e,t){return this.valueFromShape(e,t,"position")}static expandBoundingBox(e,t){e.expandByPoint(Du.fromArray(t.position))}}Vu.type="point",Vu.fields={position:"v3",color:"c"};class Hu extends Lu{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(Du.fromArray(t.position1)),e.expandByPoint(Du.fromArray(t.position2))}}Hu.type="wideline",Hu.fields={position1:"v3",position2:"v3",color:"c"};class ju{constructor(e,t){this.exp=3;const i=t||function(e){const{x:t,y:i,z:n}=e,r=new Ni,s=t.length,{min:o,max:a}=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,o=e.y,a=e.z;let c=0;const l=new Uint32Array(n),h=new Int32Array(r);for(let e=0;e>this.exp,i=o[e]-this.minY>>this.exp,n=a[e]-this.minZ>>this.exp,r=(t*this.boundY+i)*this.boundZ+n;1===(l[r]+=1)&&(c+=1),h[e]=r}const u=new Uint16Array(c);for(let e=0,t=0;e0&&(l[e]=t+1,u[t]=i,t+=1)}const d=new Uint32Array(c);for(let e=1;e0){const i=t-1;m[d[i]+f[i]]=e,f[i]+=1}}this.grid=l,this.bucketCount=u,this.bucketOffset=d,this.bucketArray=m,this.xArray=s,this.yArray=o,this.zArray=a}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,o=Math.max(0,e-n-this.minX>>this.exp),a=Math.max(0,t-n-this.minY>>this.exp),c=Math.max(0,i-n-this.minZ>>this.exp),l=Math.min(this.boundX,1+(e+n-this.minX>>this.exp)),h=Math.min(this.boundY,1+(t+n-this.minY>>this.exp)),u=Math.min(this.boundZ,1+(i+n-this.minZ>>this.exp));for(let n=o;n0){const n=l-1,o=this.bucketOffset[n],a=o+this.bucketCount[n];for(let n=o;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;)h-=1;l<=h&&(l===c?c=h:h===c&&(c=l),(o=l)!==(a=h)&&(i.copyFrom(t,0,o,1),t.copyWithin(o,a,1),t.copyFrom(i,a,0,1)),l+=1,h-=1)}while(l<=h);n(r,h),n(l,s)}var o,a}(0,this.count-1),il.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 Yu{constructor(e,t){this.length=e,this._words=new Uint32Array(e+32>>>5),!0===t&&this.setAll()}get(e){return 0!=(this._words[e>>>5]&1<>>5]|=1<>>5]&=~(1<>>5]^=1<>>5,o=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,o=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:o}=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),o.push(t.atomSet)}}const ed=0,td=["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"],id=["RNA OH 3 PRIME TERMINUS","RNA OH 5 PRIME TERMINUS","RNA LINKING"],nd=["DNA OH 3 PRIME TERMINUS","DNA OH 5 PRIME TERMINUS","DNA LINKING","L-DNA LINKING","L-RNA LINKING"],rd=["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"],sd=["NON-POLYMER"].concat(["OTHER"],rd),od=["h","g","i"],ad=["e","b"],cd=["s","t","l",""],ld={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},hd={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},ud={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},dd={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]},fd={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},md={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]},pd=[0,0,0],gd={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"},vd=Object.keys(gd),yd=["A","C","T","G","U","I"],xd=["DA","DC","DT","DG","DU","DI"],bd=["A","G","I","DA","DG","DI"],_d=yd.concat(xd),wd=["SOL","WAT","HOH","H2O","W","DOD","D3O","TIP3","TIP4","SPC"],Sd=["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"],Ad=["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"],Md=["CA","C","N","O","O1","O2","OC1","OC2","OX1","OXT","OT1","OT2","H","H1","H2","H3","HA","HN","BB"],Cd=["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*"],Pd={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"]}};Pd[ed]={};const Td={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 Id(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 Ed=new Map([[2,Ka(180)],[3,Ka(120)],[4,Ka(109.4721)],[6,Ka(90)]]);function Dd(e,t){let i=[];const n=new Zt,r=new Zt;return n.subVectors(t,e),e.eachBondedAtom((t=>{1!==t.number&&(r.subVectors(t,e),i.push(n.angleTo(r)))})),i}function Ld(e,t){const i=e.clone(),n=new Zt;n.subVectors(t,e);const r=[new Zt,new Zt];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 o=r[0].cross(r[1]);return Math.abs(Math.PI/2-o.angleTo(n))}function Rd(e,t){const i=e.structure,n=i.atomCount,r=new Int8Array(n),s=new Int8Array(n),o=new Int8Array(n),a=new Int8Array(n);return i.eachAtom((e=>{const i=e.index,[n,c,l,h]=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,o=e.bondCount,a=function(e){let t=0;return e.eachBond((e=>t+=e.bondOrder)),t}(e),c=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),l=a-o>0;let h=0,u=8;switch(e.number){case 1:r&&(0===o?(n=1,u=0):1===o&&(n=0,u=1));break;case 6:r&&(n=0),s&&(h=Math.max(0,4-a-Math.abs(n))),u=Id(o+h+Math.max(0,-n));break;case 7:if(r)if(s)if(c&&a<4)n=o-i==1&&a-i==2?1:0;else{let t=!1;e.eachBondedAtom((e=>{(16===e.number||e.isMetal())&&(t=!0)})),n=t?0:1}else n=a-3;s&&(h=Math.max(0,3-a+n)),u=Id(c&&!l?o+h-n:o+h+1-n);break;case 8:r&&(s||(n=a-2),1===a&&e.eachBondedAtom((t=>{t.eachBond((i=>{const r=i.getOtherAtom(t);r.index!==e.index&&8===r.number&&2===i.bondOrder&&(n=-1)}))}))),s&&(h=Math.max(0,2-a+n)),u=Id(c&&!l?o+h-n+1:o+h-n+2);break;case 16:r&&(s||(n=a<=3&&!e.bondToElementCount(8)?a-2:0)),s&&a<2&&(h=Math.max(0,2-a+n)),a<=3&&(u=Id(o+h-n+2));break;case 9:case 17:case 35:case 53:case 85:r&&(n=a-1);break;case 3:case 11:case 19:case 37:case 55:case 87:r&&(n=1-a);break;case 4:case 12:case 20:case 38:case 56:case 88:r&&(n=2-a);break;default:console.warn("Requested charge, protonation for an unhandled element",e.element)}return[n,h,h+i,u]}(e,t);r[i]=n,s[i]=c,o[i]=l,a[i]=h})),{charge:r,implicitH:s,totalH:o,idealGeometry:a}}function kd(e){if(e["@valenceModel"])return e["@valenceModel"];const t=Rd(e,{assignCharge:"auto",assignH:"auto"});return e["@valenceModel"]=t,t}function Od(e){return 15===e.number&&e.bondToElementCount(8)===e.bondCount}const Bd=["ARG","HIS","LYS"],Nd=["GLU","ASP"];function Fd(e,t){return 2===e&&1===t||1===e&&2===t}function zd(e,t){return 3===e&&3===t}function Ud(e,t){return 3===e&&1===t||1===e&&3===t}function $d(e){return"HIS"===e.resname&&7==e.number&&e.isRing()}function Gd(e,t){return 5===e&&4===t||4===e&&5===t}function Vd(e,t){return 9===e&&5===t||5===e&&9===t}const Hd=[3,11,19,37,55,12,20,38,56,13,31,49,81,21,50,82,83,51,80];function jd(e,t){return 12===e?11===t||12===t:13===e?10===t:void 0}const Wd=[17,35,53,85];const qd=[7,8,16],Xd=[6,7,15,16];const Yd=Ka(180),Zd=Ka(120);function Kd(e,t,i){return!Jd(e,t,i)&&(e.modelIndex!==t.modelIndex||e.altloc&&t.altloc&&e.altloc!==t.altloc)}const Qd={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 Jd(e,t,i){return e.modelIndex===i&&t.modelIndex!==i||t.modelIndex===i&&e.modelIndex!==i}function ef(e,t,i){return!Jd(e,t,i)&&(e.modelIndex!==t.modelIndex||e.residueIndex===t.residueIndex||e.altloc&&t.altloc&&e.altloc!==t.altloc)}function tf(t){const i={types:[],groups:[],centers:{x:[],y:[],z:[]},atomSets:[]};return e.Debug&&il.time("calculateFeatures"),function(e,t){const{charge:i}=kd(e.data),n={};e.eachResidue((e=>{if(Bd.includes(e.resname)){const i=Ku(1);e.eachAtom((e=>{7===e.number&&e.isSidechain()&&Qu(i,e)})),Ju(t,i)}else vd.includes(e.resname)||e.isNucleic()||(e.eachAtom((e=>{let i=!1;const r=Ku(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,Qu(r,e))})),Ju(t,r))})),e.eachAtom((e=>{const r=Ku(1);i[e.index]>0&&(n[e.index]||(Qu(r,e),Ju(t,r)))})))}))}(t,i),function(e,t){const{charge:i}=kd(e.data),n={};e.eachResidue((e=>{if(Nd.includes(e.resname)){const i=Ku(2);e.eachAtom((e=>{8===e.number&&e.isSidechain()&&Qu(i,e)})),Ju(t,i)}else if(_d.includes(e.resname)){const i=Ku(2);e.eachAtom((e=>{Od(e)&&(i.group=6,e.eachBondedAtom((e=>{8===e.number&&Qu(i,e)})),Ju(t,i))}))}else vd.includes(e.resname)||_d.includes(e.resname)||(e.eachAtom((e=>{let i=!1;const r=Ku(2);!function(e){return 16===e.number&&3===e.bondToElementCount(8)}(e)?Od(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,Qu(r,e))})),Ju(t,r))})),e.eachAtom((e=>{const r=Ku(2);i[e.index]<0&&(n[e.index]||(Qu(r,e),Ju(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=Ku(3);e.forEach((e=>{i.index=e+r,Qu(n,i)})),Ju(t,n)}))}}))}(t,i),function(e,t){const{charge:i,implicitH:n,idealGeometry:r}=kd(e.data);e.eachAtom((e=>{const s=Ku(5),o=e.number;if(8===o)Qu(s,e),Ju(t,s);else if(7===o){if($d(e))Qu(s,e),Ju(t,s);else if(i[e.index]<1){const i=e.bondCount+n[e.index],o=r[e.index];(4===o&&i<4||3===o&&i<3||2===o&&i<2)&&(Qu(s,e),Ju(t,s))}}else 16===o&&("CYS"!==e.resname&&"MET"!==e.resname&&-1!==e.formalCharge||(Qu(s,e),Ju(t,s)))}))}(t,i),function(e,t){const{totalH:i}=kd(e.data);e.eachAtom((e=>{const n=Ku(4),r=e.number;($d(e)||i[e.index]>0&&(7===r||8===r||16===r))&&(Qu(n,e),Ju(t,n))}))}(t,i),function(e,t){const{totalH:i}=kd(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=Ku(9);Qu(i,e),Ju(t,i)}}))}(t,i),function(e,t){e.eachAtom((e=>{let i=!1,n=!1;const r=vd.includes(e.resname),s=_d.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=Ku(11);Qu(i,e),Ju(t,i)}if(n){const i=Ku(10);Qu(i,e),Ju(t,i)}}))}(t,i),function(e,t){e.eachAtom((e=>{if(e.isTransitionMetal()||30===e.number||48===e.number){const i=Ku(12);Qu(i,e),Ju(t,i)}else if(Hd.includes(e.number)){const i=Ku(13);Qu(i,e),Ju(t,i)}}))}(t,i),function(e,t){e.eachAtom((e=>{const i=Ku(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&&(Qu(i,e),Ju(t,i))}))}(t,i),function(e,t){e.eachAtom((e=>{if(qd.includes(e.number)){let i=!1;if(e.eachBondedAtom((e=>{Xd.includes(e.number)&&(i=!0)})),i){const i=Ku(7);Qu(i,e),Ju(t,i)}}}))}(t,i),function(e,t){e.eachAtom((e=>{if(Wd.includes(e.number)&&1===e.bondToElementCount(6)){const i=Ku(6);Qu(i,e),Ju(t,i)}}))}(t,i),e.Debug&&il.timeEnd("calculateFeatures"),i}function nf(t,i=Qd){const n=function(e){const{types:t,centers:i}=e;return{features:e,spatialHash:new ju(i),contactStore:new qu,featureSet:new Yu(t.length,!1)}}(tf(t));e.Debug&&il.time("calculateContacts"),function(e,t,i={}){const n=Ia(i.maxIonicDist,Qd.maxIonicDist),r=Ia(i.maxPiStackingDist,Qd.maxPiStackingDist),s=Ia(i.maxPiStackingOffset,Qd.maxPiStackingOffset),o=Ia(i.maxPiStackingAngle,Qd.maxPiStackingAngle),a=Ia(i.maxCationPiDist,Qd.maxCationPiDist),c=Ia(i.maxCationPiOffset,Qd.maxCationPiOffset),l=Ia(i.masterModelIndex,Qd.masterModelIndex),h=Math.max(n+2,r,a),u=r*r,d=a*a,{features:f,spatialHash:m,contactStore:p,featureSet:g}=t,{types:v,centers:y,atomSets:x}=f,{x:b,y:_,z:w}=y,S=v.length,A=e.atomStore.x,M=e.atomStore.y,C=e.atomStore.z,P=e.getAtomProxy(),T=e.getAtomProxy(),I=function(e,t,i){const n=e.length,r=t.length;for(let s=0;s{if(t<=e)return;if(P.index=x[e][0],T.index=x[t][0],ef(P,T,l))return;const r=v[e],a=v[t];if(Fd(r,a))I(x[e],x[t],n)&&z(e,t,1);else if(zd(r,a)){if(i<=u){N(x[e],O),N(x[t],B);const i=57.29578*O.angleTo(B);Math.min(F(e,t,B),F(t,e,O))<=s&&(i<=o||i>=180-o||i<=o+90&&i>=90-o)&&z(e,t,3)}}else if(Ud(r,a)&&i<=d){const[i,n]=3===r?[e,t]:[t,e];N(x[i],O),F(n,i,O)<=c&&z(i,n,2)}}))}(t,n,i),function(e,t,i={}){const n=Ia(i.maxHbondDist,Qd.maxHbondDist),r=Ia(i.maxHbondSulfurDist,Qd.maxHbondSulfurDist),s=Ka(Ia(i.maxHbondAccAngle,Qd.maxHbondAccAngle)),o=Ka(Ia(i.maxHbondDonAngle,Qd.maxHbondDonAngle)),a=Ka(Ia(i.maxHbondAccPlaneAngle,Qd.maxHbondAccPlaneAngle)),c=Ka(Ia(i.maxHbondDonPlaneAngle,Qd.maxHbondDonPlaneAngle)),l=Ia(i.masterModelIndex,Qd.masterModelIndex),h=Math.max(n,r),u=n*n,{features:d,spatialHash:f,contactStore:m,featureSet:p}=t,{types:g,centers:v,atomSets:y}=d,{x:x,y:b,z:_}=v,w=g.length,{idealGeometry:S}=kd(e.data),A=e.getAtomProxy(),M=e.getAtomProxy();for(let e=0;e{if(t<=e)return;const n=g[e],r=g[t],h=Vd(n,r);if(!h&&!Gd(n,r))return;const[d,f]=5===r?[e,t]:[t,e];if(A.index=y[d][0],M.index=y[f][0],M.index===A.index)return;if(ef(A,M,l))return;if(16!==A.number&&16!==M.number&&i>u)return;if(A.connectedTo(M))return;const v=Dd(A,M),x=Ed.get(S[A.index])||Ka(120);if(v.some((e=>Math.abs(x-e)>o)))return;if(3===S[A.index]){const e=Ld(A,M);if(void 0!==e&&e>c)return}const b=Dd(M,A),_=Ed.get(S[M.index])||Ka(120);if(b.some((e=>_-e>s)))return;if(3===S[M.index]){const e=Ld(M,A);if(void 0!==e&&e>a)return}p.setBits(d,f);const w=h?8:function(e,t){return e.isWater()&&t.isWater()}(C=A,P=M)?9:function(e,t){return e.isBackbone()&&t.isBackbone()}(C,P)?10:4;var C,P;m.addContact(d,f,w)}))}(t,n,i),function(e,t,i={}){const n=Ia(i.maxMetalDist,Qd.maxMetalDist),r=Ia(i.masterModelIndex,Qd.masterModelIndex),{features:s,spatialHash:o,contactStore:a,featureSet:c}=t,{types:l,centers:h,atomSets:u}=s,{x:d,y:f,z:m}=h,p=l.length,g=e.getAtomProxy(),v=e.getAtomProxy();for(let e=0;e{if(t<=e)return;if(g.index=u[e][0],v.index=u[t][0],ef(g,v,r))return;const n=g.isMetal(),s=v.isMetal();if(!n&&!s)return;const[o,h]=n?[l[e],l[t]]:[l[t],l[e]];jd(o,h)&&(c.setBits(e,t),a.addContact(e,t,7))}))}(t,n,i),function(e,t,i={}){const n=Ia(i.maxHydrophobicDist,Qd.maxHydrophobicDist),r=Ia(i.masterModelIndex,Qd.masterModelIndex),{features:s,spatialHash:o,contactStore:a,featureSet:c}=t,{types:l,centers:h,atomSets:u}=s,{x:d,y:f,z:m}=h,p=l.length,g=e.getAtomProxy(),v=e.getAtomProxy();for(let e=0;e{var n,s;t<=e||(g.index=u[e][0],v.index=u[t][0],ef(g,v,r)||9===g.number&&9===v.number||g.connectedTo(v)||(n=l[e],s=l[t],8===n&&8===s&&(c.setBits(e,t),a.addContact(e,t,6))))}))}(t,n,i),function(e,t,i={}){const n=Ia(i.maxHalogenBondDist,Qd.maxHalogenBondDist),r=Ka(Ia(i.maxHalogenBondAngle,Qd.maxHalogenBondAngle)),s=Ia(i.masterModelIndex,Qd.masterModelIndex),{features:o,spatialHash:a,contactStore:c,featureSet:l}=t,{types:h,centers:u,atomSets:d}=o,{x:f,y:m,z:p}=u,g=h.length,v=e.getAtomProxy(),y=e.getAtomProxy();for(let e=0;e{if(t<=e)return;if(v.index=d[e][0],y.index=d[t][0],ef(v,y,s))return;if(n=h[e],o=h[t],!(7===n&&6===o||6===n&&7===o))return;var n,o;const[a,u]=6===h[e]?[v,y]:[y,v],f=Dd(a,u);if(1!==f.length)return;if(Yd-f[0]>r)return;const m=Dd(u,a);0!==m.length&&(m.some((e=>Zd-e>r))||(l.setBits(e,t),c.addContact(e,t,5)))}))}(t,n,i);const r=function(e){const{index1:t,index2:i,count:n}=e.contactStore,r=Zu({nodeArray1:t,nodeArray2:i,edgeCount:n,nodeCount:e.featureSet.length}),s=new Yu(e.contactStore.count,!0);return Object.assign({adjacencyList:r,contactSet:s},e)}(n);return function(t,i,n={}){e.Debug&&il.time("refineLineOfSight");const r=Ia(n.lineOfSightDistFactor,Qd.lineOfSightDistFactor),s=Ia(n.masterModelIndex,Qd.masterModelIndex),o=t.spatialHash,{contactSet:a,contactStore:c,features:l}=i,{index1:h,index2:u}=c,{centers:d,atomSets:f}=l,{x:m,y:p,z:g}=d,v=t.getAtomProxy(),y=t.getAtomProxy(),x=t.getAtomProxy(),b=new Zt,_=new Zt,w=3*r,S=r*r;a.forEach((t=>{b.set(m[h[t]],p[h[t]],g[h[t]]),_.set(m[u[t]],p[u[t]],g[u[t]]);const i=(b.x+_.x)/2,n=(b.y+_.y)/2,r=(b.z+_.z)/2,c=f[h[t]],l=f[u[t]];v.index=c[0],y.index=l[0],o.eachWithin(i,n,r,w,((i,n)=>{x.index=i,1!==x.number&&x.vdw*x.vdw*S>n&&!Kd(v,x,s)&&!Kd(y,x,s)&&!c.includes(i)&&!l.includes(i)&&b.distanceToSquared(x)>1&&_.distanceToSquared(x)>1&&(a.clear(t),e.Debug&&il.log("removing",v.qualifiedName(),y.qualifiedName(),"because",x.qualifiedName()))}))})),e.Debug&&il.timeEnd("refineLineOfSight")}(t,r,i),function(e,t){const{contactSet:i,contactStore:n,features:r}=t,{type:s,index1:o,index2:a}=n,{atomSets:c}=r,l=e.getAtomProxy(),h=e.getAtomProxy(),u={},d=function(e,t,n){const[r,s]=u[n]||[1/0,-1];e{if(6!==s[e])return;l.index=c[o[e]][0],h.index=c[a[e]][0];const t=l.distanceTo(h);d(t,e,`${l.index}|${h.residueIndex}`),d(t,e,`${h.index}|${l.residueIndex}`)}))}(t,r),i.refineSaltBridges&&function(e,t){const{contactSet:i,contactStore:n,features:r}=t,{type:s,index1:o,index2:a}=n,{atomSets:c}=r,l={},h=function(e,t){l[e]||(l[e]=[]),l[e].push(t)};i.forEach((e=>{1===s[e]&&(c[o[e]].forEach((t=>h(t,e))),c[a[e]].forEach((t=>h(t,e))))})),i.forEach((e=>{if(!function(e){return 4===e||9===e||10===e}(s[e]))return;const t=l[c[o[e]][0]],n=l[c[a[e]][0]];if(!t||!n)return;const r=t.length;for(let s=0;s{3===s[e]&&(c[o[e]].forEach((t=>h(t,e))),c[a[e]].forEach((t=>h(t,e))))})),i.forEach((e=>{if(6!==s[e]&&2!==s[e])return;const t=l[c[o[e]][0]],n=l[c[a[e]][0]];if(!t||!n)return;const r=t.length;for(let s=0;s{1===s[e]&&(c[o[e]].forEach((t=>h(t,e))),c[a[e]].forEach((t=>h(t,e))))})),i.forEach((e=>{if(7!==s[e])return;const t=l[c[o[e]][0]],n=l[c[a[e]][0]];if(!t||!n)return;const r=t.length;for(let e=0;et.getAtomSet(new $c(e)))):t.getAtomSet(new $c(n.filterSele))),o.forEach((e=>{const t=p[e];if(!r.includes(t))return;if(_){const t=l[f[e]][0],i=l[m[e]][0];if(Array.isArray(_)){if(!(_[0].isSet(t)&&_[1].isSet(i)||_[1].isSet(t)&&_[0].isSet(i)))return}else if(!_.isSet(t)&&!_.isSet(i))return}const i=f[e],s=m[e];g.push(h[i],u[i],d[i]),v.push(h[s],u[s],d[s]),y.push(...function(e){switch(e){case 4:case 9:case 10:return of.setHex(2851770).toArray();case 6:return of.setHex(8421504).toArray();case 5:return of.setHex(4259775).toArray();case 1:return of.setHex(15779860).toArray();case 7:return of.setHex(9191577).toArray();case 2:return of.setHex(16744448).toArray();case 3:return of.setHex(9220966).toArray();case 8:return of.setHex(12967404).toArray();default:return of.setHex(13421772).toArray()}}(t)),x.push(n.radius),b.push(e)})),{position1:new Float32Array(g),position2:new Float32Array(v),color:new Float32Array(y),color2:new Float32Array(y),radius:new Float32Array(x),picking:new ff(b,e,t)}}class cf{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 Zt}getPosition(e,t,i){return this._applyTransformations(this._getPosition(e),t,i)}}class lf extends cf{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 hf extends cf{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 Zt).copy(this.getObject(e))}}class uf extends cf{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 df extends cf{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 Zt).copy(t.atom1).add(t.atom2).multiplyScalar(.5)}}class ff extends cf{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:o,y:a,z:c}=r,{index1:l,index2:h,type:u}=n,d=l[t],f=h[t];return{center1:new Zt(o[d],a[d],c[d]),center2:new Zt(o[f],a[f],c[f]),atom1:this.structure.getAtomProxy(s[d][0]),atom2:this.structure.getAtomProxy(s[f][0]),type:rf(u[t])}}_getPosition(e){const{center1:t,center2:i}=this.getObject(e);return(new Zt).addVectors(t,i).multiplyScalar(.5)}}class mf extends cf{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 $c(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 Zt).copy(i).add(n).multiplyScalar(.5)}}class pf extends df{get type(){return"distance"}}class gf extends cf{get type(){return"ignore"}}class vf extends lf{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=ru(this.mesh.position)),this.__position}}class yf extends cf{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 xf extends cf{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 bf extends cf{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 Zt(t[3*i],t[3*i+1],t[3*i+2])}}class _f extends bf{get type(){return"slice"}}function wf(){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 Sf(){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 Af(e,t,i,n,r){var s,o,a,c,l,h,u,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,v=!1,y=-1,x=t*i*n,b=t,_=t*i,w=new Int32Array(12),S=[],A=[],M=[],C=[],P=wf(),T=Sf();function I(e,t,i){return e+(t-e)*i}function E(e,r,s){return _*(s=(s+u)%n)+b*(r=(r+h)%i)+(e=(e+l)%t)}function D(e,t,i,n,c,l,h){var u=3*e;if(o[u]<0){var d=(f-l)/(h-l),p=s,g=3*a;if(S[g]=i+d,S[g+1]=n,S[g+2]=c,!m){var v=3*e;A[g]=y*I(p[v],p[v+3],d),A[g+1]=y*I(p[v+1],p[v+4],d),A[g+2]=y*I(p[v+2],p[v+5],d)}r&&(C[a]=r[e+Math.round(d)]),o[u]=a,w[t]=a,a+=1}else w[t]=o[u]}function L(e,t,i,n,c,l,h){var u=3*e+1;if(o[u]<0){var d=(f-l)/(h-l),p=s,g=3*a;if(S[g]=i,S[g+1]=n+d,S[g+2]=c,!m){var v=3*e,x=v+3*b;A[g]=y*I(p[v],p[x],d),A[g+1]=y*I(p[v+1],p[x+1],d),A[g+2]=y*I(p[v+2],p[x+2],d)}r&&(C[a]=r[e+Math.round(d)*b]),o[u]=a,w[t]=a,a+=1}else w[t]=o[u]}function R(e,t,i,n,c,l,h){var u=3*e+2;if(o[u]<0){var d=(f-l)/(h-l),p=s,g=3*a;if(S[g]=i,S[g+1]=n,S[g+2]=c+d,!m){var v=3*e,x=v+3*_;A[g]=y*I(p[v],p[x],d),A[g+1]=y*I(p[v+1],p[x+1],d),A[g+2]=y*I(p[v+2],p[x+2],d)}r&&(C[a]=r[e+Math.round(d)*_]),o[u]=a,w[t]=a,a+=1}else w[t]=o[u]}function k(t){var i=3*t;0===s[i]&&(s[i]=e[(t-1+x)%x]-e[(t+1)%x],s[i+1]=e[(t-b+x)%x]-e[(t+b)%x],s[i+2]=e[(t-_+x)%x]-e[(t+_)%x])}function O(t,i,n,r,s){var o,a,l,h,u,y,x;g?(r=E(t,i,n),o=E(t+1,i,n),a=E(t,i+1,n),l=E(t,i,n+1),h=E(t+1,i+1,n),u=E(t+1,i,n+1),y=E(t,i+1,n+1),x=E(t+1,i+1,n+1)):(o=r+1,h=(a=r+b)+1,u=(l=r+_)+1,x=(y=a+_)+1);var S=0,A=e[r],C=e[o],I=e[a],O=e[h],B=e[l],N=e[u],F=e[y],z=e[x];A=f){R=y,I=!0;break}if(I)break}if(I)break}for(I=!1,v=s;v=f){L=v,I=!0;break}if(I)break}if(I)break}for(I=!1,p=r;p=f){D=p,I=!0;break}if(I)break}if(I)break}for(I=!1,y=h;y>=a;--y){for(v=l;v>=s;--v){for(p=c;p>=r;--p)if(u=t*i*y+t*v+p,e[u]>=f){N=y,I=!0;break}if(I)break}if(I)break}for(I=!1,v=l;v>=s;--v){for(y=N;y>=a;--y){for(p=c;p>=r;--p)if(u=t*i*y+t*v+p,e[u]>=f){B=v,I=!0;break}if(I)break}if(I)break}for(I=!1,p=c;p>=r;--p){for(v=B;v>=s;--v){for(y=N;y>=a;--y)if(u=t*i*y+t*v+p,e[u]>=f){k=p,I=!0;break}if(I)break}if(I)break}m?(r=Math.max(0,D-1),s=Math.max(0,L-1),a=Math.max(0,R-1),c=Math.min(t-1,k+1),l=Math.min(i-1,B+1),h=Math.min(n-1,N+1)):(r=Math.max(1,D-1),s=Math.max(1,L-1),a=Math.max(1,R-1),c=Math.min(t-2,k+1),l=Math.min(i-2,B+1),h=Math.min(n-2,N+1))}var F=15;for(y=a;y0?-1:1,s||(s=new Float32Array(3*x)));var P=3*x;if(o&&o.length===P||(o=new Int32Array(P)),a=0,c=0,void 0!==b){var T=b[0].map(Math.round),I=b[1].map(Math.round);l=t*Math.ceil(Math.abs(T[0])/t),h=i*Math.ceil(Math.abs(T[1])/i),u=n*Math.ceil(Math.abs(T[2])/n),B(T[0],T[1],T[2],I[0],I[1],I[2])}else l=h=u=0,B();return S.length=3*a,m||(A.length=3*a),M.length=c,r&&(C.length=a),{position:new Float32Array(S),normal:m?void 0:new Float32Array(A),index:Ga(M,S.length/3),atomindex:r?new Int32Array(C):void 0,contour:p}}}pl.add("arrow",class extends lf{get primitive(){return Fu}}),pl.add("box",class extends lf{get primitive(){return ku}}),pl.add("cone",class extends lf{get primitive(){return zu}}),pl.add("cylinder",class extends lf{get primitive(){return Nu}}),pl.add("ellipsoid",class extends lf{get primitive(){return Uu}}),pl.add("octahedron",class extends lf{get primitive(){return Ou}}),pl.add("sphere",class extends lf{get primitive(){return Ru}}),pl.add("tetrahedron",class extends lf{get primitive(){return Bu}}),pl.add("torus",class extends lf{get primitive(){return $u}}),pl.add("point",class extends lf{get primitive(){return Vu}}),pl.add("wideline",class extends lf{get primitive(){return Hu}}),Object.assign(Af,{__deps:[wf,Sf,Ga]});class Mf{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 Cf(e,t){let i=0,n=0;const r=t.rows,s=t.cols;let o=0,a=0,c=0;const l=t.data,h=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 Rf=1.192092896e-7,kf=1e-37;function Of(e,t,i,n){let r=0,s=0;const o=e.rows,a=e.cols;let c=o,l=a;c>16)?k:-k,e[h*t+d]=R;for(f=0;f<2;f++)for(u=0;u{const t=e.data.sd,i=e.data.p;o(this._makeSurface(t,i.isolevel,i.smooth))}),(a=>{console.warn("Volume.getSurfaceWorker error - trying without worker",a);const c=this.getSurface(e,t,i,n,r,s);o(c)}))}else{const a=this.getSurface(e,t,i,n,r,s);o(a)}}getValueForSigma(e){return this.mean+Ia(e,2)*this.rms}getSigmaForValue(e){return(Ia(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,o=r.length;if(i.drawRange.count!==1/0&&(o=i.drawRange.count),this.wireframeIndex&&this.wireframeIndex.length>2*o)s=this.wireframeIndex;else{s=Ga(2*o,i.attributes.position.count)}let a=0;e.length=0;for(let e=0;e2*e?this.wireframeIndex:Ga(2*e,e);for(let i=0,n=0;ithis.wireframeGeometry.index.array.length)this.wireframeGeometry.setIndex(new An(this.wireframeIndex,1).setUsage(this.dynamic?WebGLRenderingContext.DYNAMIC_DRAW:0));else{const e=this.wireframeGeometry.getIndex();if(!e)return void il.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 Yo(t,i):this.isPoint?new ta(t,i):new ar(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 Yo(this.wireframeGeometry,this.wireframeMaterial),e.frustumCulled=!1,e.renderOrder=this.getRenderOrder(),e}getPickingMesh(){return this._getMesh("pickingMaterial")}getShader(e,t){return kl(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=yr.merge([this.uniforms,e]),this.pickingUniforms=yr.merge([this.pickingUniforms,e])}addAttributes(e){for(let t in e){let i;const n=e[t],r=this.attributeSize*Qf[n.type];n.value?(r!==n.value.length&&il.error("attribute value has wrong length",t),i=n.value):i=$a("float32",r),this.geometry.setAttribute(t,new An(i,Qf[n.type]).setUsage(this.dynamic?WebGLRenderingContext.DYNAMIC_DRAW:0))}}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 o=!1,a=!1;for(const e in t){const c=t[e];void 0!==c&&(n[e]=c,void 0!==i[e]&&(i[e].property&&(!0!==i[e].property?r[i[e].property]=c:r[e]=c),i[e].uniform&&(!0!==i[e].uniform?s[i[e].uniform]=c:s[e]=c),i[e].updateShader&&(o=!0),i[e].updateVisibility&&(a=!0),this.dynamic&&"wireframe"===e&&!0===c&&this.updateWireframeIndex(),"forceTransparent"===e&&(r.transparent=this.transparent),"matrix"===e&&(this.matrix=c)))}this.setProperties(r),this.setUniforms(s),o&&this.updateShader(),a&&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){il.error("Index is null");continue}t.setDrawRange(0,1/0),s>e.array.length?t.setIndex(new An(r,1).setUsage(this.dynamic?WebGLRenderingContext.DYNAMIC_DRAW:0)):(e.set(r),e.count=s,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 An(r,e.itemSize).setUsage(this.dynamic?WebGLRenderingContext.DYNAMIC_DRAW:0)):(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 o=e[s];"transparent"===s?this.updateRenderOrder():"side"===s&&(o=Kf(o)),t[s]=o,i[s]=o,n[s]=o}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 nm extends im{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 rm extends nm{constructor(){super(...arguments),this.isSurface=!0}}function sm(e){e.visible=!0}function om(e){e.visible=!1}class am{constructor(e){this.group=new ko,this.wireframeGroup=new ko,this.pickingGroup=new ko,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 ko,this.wireframeGroup=new ko,this.pickingGroup=new ko,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){im.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 ko).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(sm),this.backMeshes.forEach(om)):"back"===e.side?(this.frontMeshes.forEach(om),this.backMeshes.forEach(sm)):"double"===e.side&&(this.frontMeshes.forEach(sm),this.backMeshes.forEach(sm)),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}}ul.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}"),ul.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 encodings_fragment\n#include fog_fragment\n}");class cm extends im{constructor(){super(...arguments),this.isLine=!0,this.vertexShader="Line.vert",this.fragmentShader="Line.frag"}}class lm extends tu{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 Zf?(this.surface=void 0,this.volume=e):(this.surface=e,this.volume=void 0),this.boxCenter=new Zt,this.__boxCenter=new Zt,this.box=new Ni,this.__box=new Ni,this._position=new Zt,this.inverseMatrix=new ri,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=Ia(t.colorScheme,"uniform"),t.colorValue=Ia(t.colorValue,14540253),this.isolevelType=Ia(t.isolevelType,"sigma"),this.isolevel=Ia(t.isolevel,2),this.negateIsolevel=Ia(t.negateIsolevel,!1),this.isolevelScroll=Ia(t.isolevelScroll,!1),this.smooth=Ia(t.smooth,0),this.background=Ia(t.background,!1),this.opaqueBack=Ia(t.opaqueBack,!0),this.boxSize=Ia(t.boxSize,0),this.colorVolume=Ia(t.colorVolume,void 0),this.contour=Ia(t.contour,!1),this.useWorker=Ia(t.useWorker,!0),this.wrap=Ia(t.wrap,!1),super.init(t),this.inverseMatrix.getInverse(this.matrix),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 cm(e,this.getBufferParams({wireframe:!1}));else{Object.assign(e,{normal:this.surface.getNormal(),picking:this.surface.getPicking()});const i=new rm(e,this.getBufferParams({background:this.background,opaqueBack:this.opaqueBack,dullInterior:!1}));t=new am(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.getInverse(e.matrix),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 hm{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 lm){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 um={default:[["scroll",hm.zoomScroll],["scroll-shift",hm.focusScroll],["scroll-ctrl",hm.isolevelScroll],["scroll-shift-ctrl",hm.zoomFocusScroll],["drag-left",hm.rotateDrag],["drag-right",hm.panDrag],["drag-ctrl-left",hm.panDrag],["drag-ctrl-right",hm.zRotateDrag],["drag-shift-left",hm.zoomDrag],["drag-middle",hm.zoomFocusDrag],["drag-ctrl-shift-right",hm.panComponentDrag],["drag-ctrl-shift-left",hm.rotateComponentDrag],["clickPick-right",hm.measurePick],["clickPick-ctrl-left",hm.measurePick],["clickPick-middle",hm.movePick],["clickPick-left",hm.movePick],["hoverPick",hm.tooltipPick]],pymol:[["drag-left",hm.rotateDrag],["drag-middle",hm.panDrag],["drag-right",hm.zoomDrag],["scroll",hm.focusScroll],["drag-shift-right",hm.focusScroll],["clickPick-ctrl+shift-middle",hm.movePick],["hoverPick",hm.tooltipPick]],coot:[["scroll",hm.isolevelScroll],["drag-left",hm.rotateDrag],["drag-middle",hm.panDrag],["drag-ctrl-left",hm.panDrag],["drag-right",hm.zoomFocusDrag],["drag-ctrl-right",hm.focusScroll],["clickPick-middle",hm.movePick],["hoverPick",hm.tooltipPick]],astexviewer:[["drag-left",hm.rotateDrag],["drag-ctrl-left",hm.panDrag],["drag-shift-left",hm.zoomDrag],["scroll",hm.focusScroll],["clickPick-middle",hm.movePick],["hoverPick",hm.tooltipPick]]};function dm(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 fm{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]=dm(e);this.actionList.push({type:i,key:n,button:r,callback:t})}remove(e,t){const i=e.includes("*"),[n,r,s]=dm(e),o=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=o}preset(e){this.clear();(um[e]||[]).forEach((e=>this.add(e[0],e[1])))}clear(){this.actionList.length=0}}class mm{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 pm={default:[["i",mm.toggleSpin],["k",mm.toggleRock],["p",mm.toggleAnimations],["a",mm.toggleAntialiasing],["r",mm.autoView]]};class gm{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();(pm[e]||[]).forEach((e=>this.add(e[0],e[1])))}clear(){this.actionList.length=0}}class vm{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 ym{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 xm{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 bm=!!Zc&&{passive:!0};class _m{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,bm),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,bm),this.domElement.removeEventListener("keydown",this._onKeypress),this.domElement.removeEventListener("keyup",this._onKeypress),this.domElement.removeEventListener("keypress",this._onKeypress)}}class wm{constructor(e,t,i,n={}){this.component=e,this.position=t,this.offsetX=Ia(n.offsetX,0),this.offsetY=Ia(n.offsetY,0),this.visible=Ia(n.visible,!0),this.stage=e.stage,this.viewer=e.stage.viewer,this._viewerPosition=new Zt,this._updateViewerPosition(),this._canvasPosition=new zt,this._cameraPosition=new Zt,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-rc(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 Sm=new ri,Am=new Zt,Mm=new qt;class Cm{constructor(e){this.component=e,this.signals={changed:new mc.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){Sm.getInverse(this.viewer.rotationGroup.matrix),Am.copy(ja(e)).applyMatrix4(Sm),Sm.extractRotation(this.component.transform),Sm.premultiply(this.viewer.rotationGroup.matrix),Sm.getInverse(Sm),Am.copy(ja(e)),Am.applyMatrix4(Sm),Sm.makeRotationAxis(Am,t),Mm.setFromRotationMatrix(Sm),this.component.quaternion.premultiply(Mm),this.changed()}}const Pm={"":"",vdw:"by vdW radius",covalent:"by covalent radius",sstruc:"by secondary structure",bfactor:"by bfactor",size:"size",data:"data",explicit:"explicit"};class Tm{constructor(e={}){this.max=10,this.type=Ia(e.type,"size"),this.scale=Ia(e.scale,1),this.size=Ia(e.size,1),this.data=Ia(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:Cd.includes(e.atomname)?.4:.1;break;case"data":t=Ia(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)}}Tm.types=Pm;const Im=new Zt(-1,-1,-1),Em=new ri;class Dm{constructor(e){const t=e.rows,i=t/3,n=new Mf(t,3),r=new Mf(3,3),s=new Mf(1,3),o=new Mf(3,3),a=new Mf(3,3),c=If(e);Ef(e,c),Cf(n,e),Pf(r,n,n),Of(r,s,o,a);const l=new Zt(c[0],c[1],c[2]),h=new Zt(o.data[0],o.data[3],o.data[6]),u=new Zt(o.data[1],o.data[4],o.data[7]),d=new Zt(o.data[2],o.data[5],o.data[8]),f=h.clone().multiplyScalar(Math.sqrt(s.data[0]/i)),m=u.clone().multiplyScalar(Math.sqrt(s.data[1]/i)),p=d.clone().multiplyScalar(Math.sqrt(s.data[2]/i));this.begA=l.clone().sub(f),this.endA=l.clone().add(f),this.begB=l.clone().sub(m),this.endB=l.clone().add(m),this.begC=l.clone().sub(p),this.endC=l.clone().add(p),this.center=l,this.vecA=f,this.vecB=m,this.vecC=p,this.normVecA=h,this.normVecB=u,this.normVecC=d}getBasisMatrix(e=new ri){const t=e;return t.makeBasis(this.normVecB,this.normVecA,this.normVecC),t.determinant()<0&&t.scale(Im),t}getRotationQuaternion(e=new qt){const t=e;return t.setFromRotationMatrix(this.getBasisMatrix(Em)),t.inverse()}getProjectedScaleForAtoms(e){let t=-1/0,i=-1/0,n=-1/0,r=-1/0,s=-1/0,o=-1/0;const a=new Zt,c=new Zt,l=this.center,h=this.normVecA,u=this.normVecB,d=this.normVecC;return e.eachAtom((function(e){su(a.copy(e),h,l);const f=c.subVectors(a,l).normalize().dot(h),m=a.distanceTo(l);f>0?m>t&&(t=m):m>i&&(i=m),su(a.copy(e),u,l);const p=c.subVectors(a,l).normalize().dot(u),g=a.distanceTo(l);p>0?g>n&&(n=g):g>r&&(r=g),su(a.copy(e),d,l);const v=c.subVectors(a,l).normalize().dot(d),y=a.distanceTo(l);v>0?y>s&&(s=y):y>o&&(o=y)})),{d1a:t,d2a:n,d3a:s,d1b:-i,d2b:-r,d3b:-o}}}class Lm{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=Ia(t,1/0),i=Ia(i,!1);const n=this.volume.data,r=this.volume.position,s=this.volume.atomindex,o=this._getFilterHash(e,t,i);if(o!==this._filterHash){if(e===-1/0&&t===1/0)this.data=n,this.position=r,this.atomindex=s;else{const o=n.length;this._dataBuffer||(this._dataBuffer=new ArrayBuffer(4*o),this._positionBuffer=new ArrayBuffer(3*o*4),s&&(this._atomindexBuffer=new ArrayBuffer(4*o)));const a=new Float32Array(this._dataBuffer),c=new Float32Array(this._positionBuffer);let l;s&&(l=new Uint32Array(this._atomindexBuffer));let h=0;for(let u=0;u=e&&d<=t||i&&(dt)){const e=3*h;a[h]=d,c[e+0]=r[o+0],c[e+1]=r[o+1],c[e+2]=r[o+2],s&&l&&(l[h]=s[u]),h+=1}}this.data=new Float32Array(this._dataBuffer,0,h),this.position=new Float32Array(this._positionBuffer,0,3*h),s&&(this.atomindex=new Int32Array(this._atomindexBuffer,0,h))}this._filterHash=o}}}Lm.prototype.getValueForSigma=Zf.prototype.getValueForSigma,Lm.prototype.getSigmaForValue=Zf.prototype.getSigmaForValue,Lm.prototype.getDataAtomindex=Zf.prototype.getDataAtomindex,Lm.prototype.getDataPosition=Zf.prototype.getDataPosition,Lm.prototype.getDataColor=Zf.prototype.getDataColor,Lm.prototype.getDataPicking=Zf.prototype.getDataPicking,Lm.prototype.getDataSize=Zf.prototype.getDataSize;class Rm{constructor(e,t){const i=Zu({nodeArray1:e.atomIndex1,nodeArray2:e.atomIndex2,edgeCount:e.count,nodeCount:t});this.countArray=i.countArray,this.offsetArray=i.offsetArray,this.indexArray=i.indexArray}}class km extends Wu{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&&(o[t]=x.angleTo(b));const n=Math.cos(m.angleTo(p));l[t]=180/Math.PI*Math.acos(n);const y=m.length(),T=p.length();a[t]=Math.sqrt(T*y)/Math.max(2,2*(1-n)),c[t]=Math.abs(d.dot(x)),g.copy(m).multiplyScalar(a[t]/y),v.copy(p).multiplyScalar(a[t]/T),g.subVectors(M,g),v.subVectors(C,v),g.toArray(r,i+3),v.toArray(r,i+6),_.subVectors(A,w),_.toArray(h,i),b.copy(x),w.copy(g)}g.fromArray(r,3),v.fromArray(r,6),x.subVectors(g,v).normalize(),A.index=e.getAtomIndexByType(0,S),w.copy(A),y.copy(A),su(y,x,g),y.toArray(r,0),_.subVectors(w,g),_.toArray(h,0),g.fromArray(r,3*i-6),v.fromArray(r,3*i-9),x.subVectors(g,v).normalize(),A.index=e.getAtomIndexByType(i-1,S),w.copy(A),y.copy(A),su(y,x,g),y.toArray(r,3*i-3);for(let t=i-3;tt||l.bending[n]>e)&&(O=!0)),O){if(n-f<4){f=n,O=!1;continue}L.index=E.traceAtomIndex,C=l.axis.subarray(3*f+3,3*n),P=l.center.subarray(3*f,3*n+3),A=ru(C).normalize(),M=ru(P),T.fromArray(P),su(T,A,M),I.fromArray(P,P.length-3),su(I,A,M),A.subVectors(I,T),A.toArray(p,m),M.toArray(g,m),T.toArray(v,m),I.toArray(y,m),u.atomColorToArray(L,x,m),b.push(L.index),_.push(d.atomRadius(L)),w.push(c+f),S.push(c+n+1-f),m+=3,f=n,O=!1}const B=new Float32Array(b);return{axis:new Float32Array(p),center:new Float32Array(g),begin:new Float32Array(v),end:new Float32Array(y),color:new Float32Array(x),picking:new hf(B,o),size:new Float32Array(_),residueOffset:w,residueCount:S}}}class $m{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 Gm{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,o=this.nodes;if(this.currentNode+=1,1===r)return o[s]=i,o[s+1]=-1,o[s+2]=-1,o[s+3]=t,s;const a=this.indices,c=this.points,l=i+Math.floor(r/2),h=e%3;let u,d,f,m,p,g=i,v=n-1;for(;v>g;){for(f=g+v>>1,m=c[3*a[f]+h],d=a[f],a[f]=a[v],a[v]=d,p=g,u=g;u-e[1])),r=this.nodes,s=this.points,o=this.indices,a=c=>{let l,h;const u=this.getNodeDepth(c)%3,d=3*o[r[c]],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[c+1],v=r[c+2];if(-1===v&&-1===g)return void((n.size()s[3*o[r[e]]+n])throw new Error("left child is > parent!");i+=this.verify(a,t+1)}if(-1!==c){if(s[3*o[r[c]]+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 od.includes(this.sstruc)}isSheet(){return ad.includes(this.sstruc)}isTurn(){return cd.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],o=t.y[n]-i.y[r],a=t.z[n]-i.z[r],c=s*s+o*o+a*a;return Math.sqrt(c)}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],o=t.y[n]-i.y[r],a=t.z[n]-i.z[r],c=s*s+o*o+a*a;if(c<48&&this.isCg())return!0;if(isNaN(c))return!1;const l=this.covalent+e.covalent,h=l+.3,u=l-.5;return cu*u}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 Zt),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 o,a,c,l;for(e||(l=[]),o=r.indexOf(i);-1!==o;){if(c=s[o]+t,!l)return c;l.push(c),o=r.indexOf(i,o+1)}for(a=s.indexOf(i);-1!==a;){if(c=r[a]+t,!l)return c;l.push(c),a=s.indexOf(i,a+1)}return l}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 Vm(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 Hm(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 jm(e,t){return Math.sqrt(Hm(e,t))}const Wm=new Float32Array(3);class qm{constructor(t,i=!1){e.Debug&&il.time("Kdtree build");const n=i?Hm:jm,r=new Float32Array(3*t.atomCount),s=new Uint32Array(t.atomCount);let o=0;t.eachAtom((function(e){r[o+0]=e.x,r[o+1]=e.y,r[o+2]=e.z,s[o/3]=e.index,o+=3})),this.atomIndices=s,this.points=r,this.kdtree=new Gm(r,n),e.Debug&&il.timeEnd("Kdtree build")}nearest(e,t,i){e instanceof Zt?e.toArray(Wm):e instanceof Vm&&e.positionToArray(Wm);const n=this.kdtree.nearest(Wm,t,i),r=this.kdtree.indices,s=this.kdtree.nodes,o=this.atomIndices,a=[];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"},Ym={"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":" !#*,#.%&$'&!# ,- '&$%/$# !-*!/$%&.%()+$%+ ,-*!-)+(%&(!-*,#*+()&$)#*,- ,"},Zm=/^[1-9]$/;function Km(e){let t="";return e.length>0&&(t=":"+za(e).join(" OR :")),new $c(t)}class Qm{constructor(e=""){this.name=e,this.partList=[]}get type(){return"Assembly"}addPart(e,t){const i=new Jm(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 ri).equals(t.matrixList[0]))return!1;let i=[];return e.eachChain((function(e){i.push(e.chainname)})),i=za(i),t.chainList.length===i.length}getBoundingBox(e){const t=new Ni;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 Zt)}getSelection(){let e=[];return this.partList.forEach((function(t){e=e.concat(t.chainList)})),Km(e)}}class Jm{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 Ni,i=new Ni,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 Km(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),l.growIfFull(),l.resno[this.ri]=r,void 0!==o&&(l.sstruc[this.ri]=o.charCodeAt(0)),void 0!==a&&(l.inscode[this.ri]=a.charCodeAt(0)),l.atomOffset[this.ri]=this.ai,l.atomCount[this.ri]=0,l.count+=1,l.chainIndex[this.ri]=this.ci,h.residueCount[this.ci]+=1),c.count+=1,c.residueIndex[this.ai]=this.ri,l.atomCount[this.ri]+=1,this.currentModelindex=e,this.currentChainid=i,this.currentResname=n,this.currentResno=r,this.currentInscode=a,this.currentHetero=s}finalize(){this.previousResname=this.currentResname,this.previousHetero=this.currentHetero,this.ri>-1&&this.addResidueType(this.ri)}}function tp(t,i){if(!i)return;e.Debug&&il.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 o=i.helices.filter((function(e){return Na(r,e[0])>=0}));o.sort((function(e,t){const i=e[0],n=t[0],o=e[1],a=t[1];if(i===n)return o===a?0:o=0}));c.sort((function(e,t){const i=e[0],n=t[0];if(i===n)return 0;const o=Na(r,i),a=Na(r,n);return s[o]=e.residueCount)continue;o.index=s+r,a.index=s+r+t,c.index=o.traceAtomIndex,l.index=a.traceAtomIndex;const h=c.distanceTo(l);if(Math.abs(h-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&&il.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 Um(e).position,r=new Zt,s=new Zt;for(let o=0,a=e.residueCount;o1&&n.bending[o]<20&&(t.sstruc[i+o]="h".charCodeAt(0),t.sstruc[i+o+1]="h".charCodeAt(0))}}(e);else{if(!e.isProtein())return;!function(e){const t=e.residueStore,r=e.residueIndexStart;for(let s=0,o=e.residueCount;s=t;)i=Math.floor(i/t),r+=np[i%t],n+=1;return n>=5&&il.warn("chainname overflow"),r}function sp(t,i=!1){e.Debug&&il.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,o){const a=n.count;for(let e=0;e{u.add(t),e.forEach((e=>{u.add(e)}))}))),t.eachResidue((function(e){if(!i&&h){const t=e.atomCount,i=e.atomOffset;if(t>500)return void il.warn("more than 500 atoms, skip residue for auto-bonding",e.qualifiedName());if("auto"===n&&e.hetero)for(let t=e.atomOffset;t{u.forEach((i=>{e.push(t.clone().multiply(i))}))})),l.addPart(e)}else l.addPart(h);const d=new Zt,f=new Qm("SUPERCELL"),m=Array.prototype.concat.call(c(d.set(1,0,0)),c(d.set(0,1,0)),c(d.set(0,0,1)),c(d.set(-1,0,0)),c(d.set(0,-1,0)),c(d.set(0,0,-1)),c(d.set(1,1,0)),c(d.set(1,0,1)),c(d.set(0,1,1)),c(d.set(-1,-1,0)),c(d.set(-1,0,-1)),c(d.set(0,-1,-1)),c(d.set(1,-1,-1)),c(d.set(1,1,-1)),c(d.set(1,-1,1)),c(d.set(-1,1,1)),c(d.set(-1,-1,1)),c(d.set(-1,1,-1)),c(d.set(0,1,-1)),c(d.set(0,-1,1)),c(d.set(1,0,-1)),c(d.set(-1,0,1)),c(d.set(1,-1,0)),c(d.set(-1,1,0)),c(),c(d.set(1,1,1)),c(d.set(-1,-1,-1)));if(t.biomolDict.NCS){const e=[];m.forEach((function(t){u.forEach((function(i){e.push(t.clone().multiply(i))}))})),f.addPart(e)}else f.addPart(m);t.biomolDict.UNITCELL=l,t.biomolDict.SUPERCELL=f,e.Debug&&il.timeEnd("buildUnitcellAssembly")}const dp=["H","C","O","N","S","P"],fp=["NA","CL","FE"];function mp(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!==dp.indexOf(t[0])?t[0]:""}function pp(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 o=e.atomOffset,a=[],c=[],l=[],h={};const u=o+e.atomCount;e.eachAtom((function(e){const t=e.index,d=n[t];for(let e=0,n=i[t];e=u)continue;let i=s.atomIndex2;if(i=u)continue;if(t>i){const e=i;i=t,t=e}const n=t+"|"+i;void 0===h[n]&&(h[n]=!0,a.push(t-o),c.push(i-o),l.push(s.bondOrder))}})),t.bonds={atomIndices1:a,atomIndices2:c,bondOrders:l}}))}const gp=[3,11,19,37,55,87],vp=[4,12,20,38,56,88],yp=[6,15,16,34],xp=[1,7,8,9,17,35,53],bp=[2,10,18,36,54,86],_p=[13,30,31,48,49,50,80,81,82,83,84,85,112],wp=[5,14,32,33,51,52,85],Sp=[9,17,35,53,85];class Ap{constructor(e,t,i){this.structure=e,this.atomname=t,i=i||mp(t),this.element=i,this.number=ld[i]||0,this.vdw=hd[this.number]||2,this.covalent=ud[this.number]||1.6}getDefaultValence(){const e=dd[this.number];return e?e[0]:-1}getValenceList(){return dd[this.number]||[]}getOuterShellElectronCount(){return fd[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 wp.includes(this.number)}isHalogen(){return Sp.includes(this.number)}isDiatomicNonmetal(){return xp.includes(this.number)}isPolyatomicNonmetal(){return yp.includes(this.number)}isAlkaliMetal(){return gp.includes(this.number)}isAlkalineEarthMetal(){return vp.includes(this.number)}isNobleGas(){return bp.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 _p.includes(this.number)}isLanthanide(){return this.number>=57&&this.number<=71}isActinide(){return this.number>=89&&this.number<=103}}class Mp{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():mp(e));let n=this.dict[i];if(void 0===n){const r=new Ap(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 Cp{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 o=Pd[this.backboneType],a=Pd[this.backboneStartType],c=Pd[this.backboneEndType],l=this.getAtomIndexByName(o.trace);this.traceAtomIndex=Ia(l,-1);const h=this.getAtomIndexByName(o.direction1);this.direction1AtomIndex=Ia(h,-1);const u=this.getAtomIndexByName(o.direction2);this.direction2AtomIndex=Ia(u,-1);const d=this.getAtomIndexByName(a.backboneStart);this.backboneStartAtomIndex=Ia(d,-1);const f=this.getAtomIndexByName(c.backboneEnd);let m;this.backboneEndAtomIndex=Ia(f,-1),m=bd.includes(t)?this.getAtomIndexByName("N1"):this.getAtomIndexByName("N3"),this.rungEndAtomIndex=Ia(m,-1)}getBackboneIndexList(){const e=[];let t;switch(this.moleculeType){case 3:t=Md;break;case 4:case 5:t=Cd;break;default:return e}const i=this.structure.atomMap,n=this.atomTypeIdList;for(let r=0,s=this.atomCount;r500)e.Debug&&il.warn("more than 500 atoms, skip residue for auto-bonding",t.qualifiedName());else if(s>50){const e=new qm(t,!0),i=t.isCg()?1.2:2.3;for(let t=o;t=0||Ep(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=>!Pp.includes(e.number))))return!1;let t=0;const i=new Mf(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,o=r.atomIndices2,a=r.bondOrders,c=this.bondReferenceAtomIndices,l=r.atomIndices1.length;c.length=0;for(let t=0;t1)for(let i=0;i1)for(let i=0;i=0;e--)m[p++]=o[e];const g=e.rings.length;for(let t=0;t0?s[c]!==t&&s[t]!==c&&Ip(e,t,c):(n[c]=1,r[a++]=c,s[c]=t)}}}const Dp=4;class Lp{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 o=this.dict[s];if(void 0===o){const a=new Cp(this.structure,e,t,i,n,r);o=this.list.length,this.dict[s]=o,this.list.push(a)}return o}get(e){return this.list[e]}}class Rp{constructor(e,t=0){this.structure=e,this.index=t,this.bondStore=e.bondStore,this._v12=new Zt,this._v13=new Zt,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 Zt){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 o=this.getReferenceAtomIndex();r.subVectors(t,i).normalize(),void 0!==o?(n.index=o,s.subVectors(t,n)):s.copy(t),s.normalize();let a=r.dot(s);return 1-Math.abs(a)<1e-5&&(s.set(1,0,0),a=r.dot(s),1-Math.abs(a)<1e-5&&(s.set(0,1,0),a=r.dot(s))),e.copy(s.sub(r.multiplyScalar(a))).normalize()}qualifiedName(){return this.atomIndex1+"="+this.atomIndex2}clone(){return new Rp(this.structure,this.index)}toObject(){return{atomIndex1:this.atomIndex1,atomIndex2:this.atomIndex2,bondOrder:this.bondOrder}}}class kp{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 od.includes(this.sstruc)}isSheet(){return ad.includes(this.sstruc)}isTurn(){return cd.includes(this.sstruc)&&this.isProtein()}getAtomType(e){return this.atomMap.get(this.atomStore.atomTypeId[e])}getResname1(){return gd[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=Ia(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=Ia(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 kp(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 Op{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 Op(s,i,l.index)),i=n)):(o!==ed&&l.index-i>1&&e(new Op(s,i,l.index)),i=n)}n-i>1&&this.structure.getResidueProxy(i).backboneEndType&&e(new Op(s,i,n))}qualifiedName(){return":"+this.chainname+"/"+this.modelIndex}clone(){return new Bp(this.structure,this.index)}toObject(){return{index:this.index,residueOffset:this.residueOffset,residueCount:this.residueCount,chainname:this.chainname}}}class Np{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;a.index=e,l&&a.positionToArray(l,i),h&&s.atomColorToArray(a,h,i),u&&(u.array[t]=e),d&&(d[t]=r.atomRadius(a)),f&&(f[t]=e)})),o}getBondData(e){const t=Object.assign({},e);t.colorParams&&(t.colorParams.structure=this.getStructure());const i=t.what,n=Ia(t.bondSet,this.bondSet),r=Ia(t.multipleBond,"off"),s="off"!==r,o="offset"===r,a=Ia(t.bondScale,.4),c=Ia(t.bondSpacing,1);let l,h;const u={},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||(u.position1=new Float32Array(3*p),u.position2=new Float32Array(3*p)),i&&!i.color||!t.colorParams||(u.color=new Float32Array(3*p),u.color2=new Float32Array(3*p),h=al.getScheme(t.colorParams)),i&&!i.picking||(u.picking=new df(new Float32Array(p),this.getStructure(),t.bondStore)),(!i||i.radius||s&&i.position)&&(l=new Tm(t.radiusParams)),i&&!i.radius||(u.radius=new Float32Array(p),t.radius2&&(u.radius2=new Float32Array(p)));const{position1:g,position2:v,color:y,color2:x,picking:b,radius:_,radius2:w}=u;let S,A,M,C,P,T,I=0;const E=new Zt,D=new Zt,L=new Zt;return n.forEach((e=>{if(A=3*I,d.index=e,f.index=d.atomIndex1,m.index=d.atomIndex2,C=d.bondOrder,g)if(s&&C>1){const e=l.atomRadius(f);T=e*a/(.5*C),d.calculateShiftDir(L),o?(P=2*c*e,L.multiplyScalar(P),L.negate(),D.subVectors(m,f).multiplyScalar(Math.max(.1,P/1.88)),f.positionToArray(g,A),m.positionToArray(v,A),C>=2&&(E.addVectors(f,L).add(D).toArray(g,A+3),E.addVectors(m,L).sub(D).toArray(v,A+3),C>=3&&(E.subVectors(f,L).add(D).toArray(g,A+6),E.subVectors(m,L).sub(D).toArray(v,A+6)))):(P=(c-a)*e,L.multiplyScalar(P),2===C?(E.addVectors(f,L).toArray(g,A),E.subVectors(f,L).toArray(g,A+3),E.addVectors(m,L).toArray(v,A),E.subVectors(m,L).toArray(v,A+3)):3===C?(f.positionToArray(g,A),E.addVectors(f,L).toArray(g,A+3),E.subVectors(f,L).toArray(g,A+6),m.positionToArray(v,A),E.addVectors(m,L).toArray(v,A+3),E.subVectors(m,L).toArray(v,A+6)):(f.positionToArray(g,A),m.positionToArray(v,A)))}else f.positionToArray(g,A),m.positionToArray(v,A);if(y&&x&&(h.bondColorToArray(d,1,y,A),h.bondColorToArray(d,0,x,A),s&&C>1))for(S=1;S1))for(S=1;S1))for(T=_[I]*a/(o?1:.5*C),S=o?1:0;S1))for(T=w[I]*a/(o?1:.5*C),S=o?1:0;S{const t=e.x,i=e.y,l=e.z;to&&(o=t),i>a&&(a=i),l>c&&(c=l)}),t),i.min.set(n,r,s),i.max.set(o,a,c),e.Debug&&il.timeEnd("getBoundingBox"),i}getPrincipalAxes(t){e.Debug&&il.time("getPrincipalAxes");let i=0;const n=new Mf(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&&il.timeEnd("getPrincipalAxes"),new Dm(n)}atomCenter(e){return e?this.getBoundingBox(e).getCenter(new Zt):this.center.clone()}hasCoords(){if(void 0===this._hasCoords){const e=this.atomStore;this._hasCoords=0!==Zl(e.x)||0!==Yl(e.x)||0!==Zl(e.y)||0!==Yl(e.y)||0!==Zl(e.z)||0!==Yl(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 ju(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 zp=new Ni,Up=[Fu,ku,zu,Nu,Uu,Ou,Ru,Bu,Gu,$u,Vu,Hu],$p={aspectRatio:1.5,sphereDetail:2,radialSegments:50,disableImpostor:!1,openEnded:!1,dashedCylinder:!1,labelParams:{},pointSize:2,sizeAttenuation:!1,useTexture:!0,linewidth:2};class Gp{constructor(e="shape",t={}){this.boundingBox=new Ni,this.bufferList=[],this.meshCount=0,this._primitiveData={},this.name=e,this.parameters=Ea(t,$p),Up.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=Xa(e),t=Xa(t),Array.isArray(i)&&(i=Ga(i,e.length)),n&&(n=Xa(n)),s=void 0===n||0==n.length?{position:e,color:t,index:i}:{position:e,color:t,index:i,normal:n};const o=new vf(this,Object.assign({serial:this.meshCount,name:r},s)),a=new nm(Object.assign({picking:o},s));return this.bufferList.push(a),zp.setFromArray(e),this.boundingBox.union(zp),this.meshCount+=1,this}addSphere(e,t,i,n){return Ru.objectToShape(this,{position:e,color:t,radius:i,name:n}),this}addEllipsoid(e,t,i,n,r,s){return Uu.objectToShape(this,{position:e,color:t,radius:i,majorAxis:n,minorAxis:r,name:s}),this}addTorus(e,t,i,n,r,s){return $u.objectToShape(this,{position:e,color:t,radius:i,majorAxis:n,minorAxis:r,name:s}),this}addCylinder(e,t,i,n,r){return Nu.objectToShape(this,{position1:e,position2:t,color:i,radius:n,name:r}),this}addCone(e,t,i,n,r){return zu.objectToShape(this,{position1:e,position2:t,color:i,radius:n,name:r}),this}addArrow(e,t,i,n,r){return Fu.objectToShape(this,{position1:e,position2:t,color:i,radius:n,name:r}),this}addBox(e,t,i,n,r,s){return ku.objectToShape(this,{position:e,color:t,size:i,heightAxis:n,depthAxis:r,name:s}),this}addOctahedron(e,t,i,n,r,s){return Ou.objectToShape(this,{position:e,color:t,size:i,heightAxis:n,depthAxis:r,name:s}),this}addTetrahedron(e,t,i,n,r,s){return Bu.objectToShape(this,{position:e,color:t,size:i,heightAxis:n,depthAxis:r,name:s}),this}addText(e,t,i,n){return Gu.objectToShape(this,{position:e,color:t,size:i,text:n}),this}addPoint(e,t,i){return Vu.objectToShape(this,{position:e,color:t,name:i}),this}addWideline(e,t,i,n,r){return this.parameters.linewidth=n,Hu.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 Up.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,Up.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 Zt)),this._center}get type(){return"Shape"}}class Vp extends tu{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 Hp=new ri,jp=new Ut;class Wp extends nm{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,o=r*s,a=new Float32Array(3*o),c=new Float32Array(3*o),l=new Float32Array(3*o);let h;return n&&(h=Ga(r*n.length,o)),{position:a,color:l,index:h,normal:c,primitiveId:e.primitiveId||jl(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 o=this.geometry.attributes;if(this.meshPosition=o.position.array,this.meshColor=o.color.array,this.meshNormal=o.normal.array,this.setAttributes(e),s){const e=this.geometry.getIndex();if(!e)return void il.error("Index is null");this.meshIndex=e.array,this.makeIndex()}}setAttributes(e={},t=!1){const i=this.geometry.attributes;let n,r,s,o,a,c,l,h,u;const d=this.updateNormals;e.position&&(n=e.position,s=this.geoPosition,l=this.meshPosition,a=this.transformedGeoPosition,i.position.needsUpdate=!0,(d||t)&&(o=this.geoNormal,u=this.meshNormal,c=this.transformedGeoNormal,i.normal.needsUpdate=!0)),e.color&&(r=e.color,h=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 encodings_fragment\n#include fog_fragment\n#endif\n}");class Zp extends im{constructor(e,t,i={}){super(t,i),this.index=Ga(this.indexSize,this.attributeSize),this.makeIndex(),this.initIndex(this.index),this.addAttributes({mapping:{type:e,value:null}}),this.setAttributes({primitiveId:Hl(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=Ul(e.position1,e.position2));const t=this.size,i=this.mappingSize,n=this.geometry.attributes;let r,s,o,a,c,l,h;for(const u in e)if("index"!==u&&"picking"!==u){s=e[u],r=n[u],o=r.itemSize,a=r.array;for(let e=0;e0&&this.parameters.alphaTest<=1&&(t.ALPHATEST=this.parameters.alphaTest.toPrecision(2)),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()}}ml.add("point",sg);class og extends tu{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 Zf?(this.surface=void 0,this.volume=new Lm(e)):(this.surface=e,this.volume=void 0),this.init(i)}init(e){var t=e||{};t.colorScheme=Ia(t.colorScheme,"uniform"),t.colorValue=Ia(t.colorValue,14540253),this.thresholdType=Ia(t.thresholdType,"sigma"),this.thresholdMin=Ia(t.thresholdMin,2),this.thresholdMax=Ia(t.thresholdMax,1/0),this.thresholdOut=Ia(t.thresholdOut,!1),this.dotType=Ia(t.dotType,"point"),this.radius=Ia(t.radius,.1),this.scale=Ia(t.scale,1),this.pointSize=Ia(t.pointSize,1),this.sizeAttenuation=Ia(t.sizeAttenuation,!0),this.sortParticles=Ia(t.sortParticles,!1),this.useTexture=Ia(t.useTexture,!1),this.alphaTest=Ia(t.alphaTest,.5),this.forceTransparent=Ia(t.forceTransparent,!1),this.edgeBleach=Ia(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 tg(e,this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!1})):this.dotBuffer=new sg(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 Zf&&("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||el&&!this.disableImpostor||(i=!0)),e&&void 0!==e.radius&&(t.radius=!0,"sphere"!==this.dotType||el&&!this.disableImpostor||(i=!0)),e&&void 0!==e.scale&&(t.scale=!0,"sphere"!==this.dotType||el&&!this.disableImpostor||(i=!0)),super.setParameters(e,t,i),this}}ul.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}"),ul.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 filter( 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 filter( 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 filter( 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 = filter( m - cell.x ) * filter( -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 ag=new Uint16Array([0,1,2,1,3,2]),cg=new Float32Array([0,1,0,0,1,1,1,0]),lg=Object.assign({filter:"nearest",forceTransparent:!0},em),hg=Object.assign({filter:{updateShader:!0,uniform:!0}},tm);class ug extends im{constructor(e,t){super({position:e.position,index:ag,picking:e.picking},t),this.parameterTypes=hg,this.alwaysTransparent=!0,this.hasWireframe=!1,this.vertexShader="Image.vert",this.fragmentShader="Image.frag";const{imageData:i,width:n,height:r}=e,s=new Ar(i,n,r);s.flipY=!0,this.tex=s;const o=i.length,a=new Uint8Array(o);for(let e=0;e>16&255,a[e+1]=t>>8&255,a[e+2]=255&t}const c=new Ar(a,n,r);c.flipY=!0,c.minFilter=re,c.magFilter=re,this.pickingTex=c,this.addUniforms({map:{value:s},pickingMap:{value:c},mapSize:{value:new zt(n,r)}}),this.geometry.setAttribute("uv",new An(cg,2))}get defaultParameters(){return lg}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=re,e.magFilter=re):"linear"===t?(e.minFilter=ae,e.magFilter=ae):(e.minFilter=re,e.magFilter=re),e.needsUpdate=!0,this.pickingTex.needsUpdate=!0}makeMaterial(){super.makeMaterial(),this.updateTexture();const e=this.material;e.uniforms.map.value=this.tex,e.blending=u,e.needsUpdate=!0;const t=this.wireframeMaterial;t.uniforms.map.value=this.tex,t.blending=u,t.needsUpdate=!0;const i=this.pickingMaterial;i.uniforms.map.value=this.tex,i.uniforms.pickingMap.value=this.pickingTex,i.blending=u,i.needsUpdate=!0}setUniforms(e){e&&void 0!==e.filter&&(this.updateTexture(),e.map=this.tex),super.setUniforms(e)}}class dg{constructor(e,t){const i=t||{};this.dimension=Ia(i.dimension,"x"),this.positionType=Ia(i.positionType,"percent"),this.position=Ia(i.position,30),this.thresholdType=Ia(i.thresholdType,"sigma"),this.thresholdMin=Ia(i.thresholdMin,-1/0),this.thresholdMax=Ia(i.thresholdMax,1/0),this.normalize=Ia(i.normalize,!1),this.volume=e}getPositionFromCoordinate(e){const t=this.dimension,i=this.volume,n=i.matrix,r=(new Zt).setFromMatrixPosition(n)[t],s=(new Zt).setFromMatrixScale(n)[t];let o;return o="x"===t?i.nx:"y"===t?i.ny:i.nz,Math.round(((e-r)/(o/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 o(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 a=new Float32Array(12),c=new Zt;let l,h,u,d,f,m=0,p=0,g=0,v=t.nx,y=t.ny,x=t.nz;function b(e,t,i,r){c.set(e,t,i).applyMatrix4(n).toArray(a,r)}"x"===this.dimension?(u=s(t.nx),d=t.ny-1,f=t.nz-1,l=t.nz,h=t.ny,m=u,v=m+1,b(u,0,0,0),b(u,d,0,3),b(u,0,f,6),b(u,d,f,9)):"y"===this.dimension?(u=t.nx-1,d=s(t.ny),f=t.nz-1,l=t.nz,h=t.nx,p=d,y=p+1,b(0,d,0,0),b(u,d,0,3),b(0,d,f,6),b(u,d,f,9)):"z"===this.dimension&&(u=t.nx-1,d=t.ny-1,f=s(t.nz),l=t.nx,h=t.ny,g=f,x=g+1,b(0,0,f,0),b(0,d,f,3),b(u,0,f,6),b(u,d,f,9));let _=0,w=0;const S=new Uint8Array(l*h*4),A=new Float32Array(l*h);let M,C;"sigma"===this.thresholdType?(M=t.getValueForSigma(this.thresholdMin),C=t.getValueForSigma(this.thresholdMax)):(M=this.thresholdMin,C=this.thresholdMax);const P=Object.assign({},e.colorParams,{volume:t});this.normalize&&(P.domain=[0,1]);const T=al.getScheme(P),I=new Float32Array(3),E=T.getScale();let D,L=0,R=0;if(this.normalize){L=1/0,D=-1/0;for(let e=p;eD&&(D=r)}R=D-L}for(let e=p;eM&&s{this.viewer.add(e)})),this.setVisibility(this.visible),e()}create(){const e=new dg(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 ug(e.getData({colorParams:this.getColorParams()}),this.getBufferParams({filter:this.filter}));this.bufferList.push(t)}}function mg(e){il.error(`makeRepresentation: representation type ${e} unknown`)}const pg={name:"some element",status:""};class gg{constructor(e,t={}){this.stage=e,this.signals={statusChanged:new mc.Signal,nameChanged:new mc.Signal,disposed:new mc.Signal},this.parameters=Ea(t,this.defaultParameters),this.uuid=ec()}get defaultParameters(){return pg}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 vg=Object.assign({visible:!0},pg);class yg extends gg{constructor(e,t,i={},n){super(e,Object.assign({name:t.type},i)),this.parent=n,this.signals=Object.assign({visibilityChanged:new mc.Signal,parametersChanged:new mc.Signal},this.signals),this.setRepresentation(t)}get defaultParameters(){return vg}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 xg=new ri,bg=new Zt,_g={name:"",status:"",visible:!0};class wg{constructor(e,t,i={}){this.stage=e,this.object=t,this.signals={representationAdded:new mc.Signal,representationRemoved:new mc.Signal,visibilityChanged:new mc.Signal,matrixChanged:new mc.Signal,statusChanged:new mc.Signal,nameChanged:new mc.Signal,disposed:new mc.Signal},this.reprList=[],this.annotationList=[],this.matrix=new ri,this.position=new Zt,this.quaternion=new qt,this.scale=new Zt(1,1,1),this.transform=new ri,this.parameters=Ea(i,this.defaultParameters),this.uuid=ec(),this.viewer=e.viewer,this.controls=new Cm(this)}get defaultParameters(){return _g}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 ai).fromArray(e);this.quaternion.setFromEuler(t)}else this.quaternion.fromArray(e);else e instanceof ai?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(bg);this.matrix.makeTranslation(-e.x,-e.y,-e.z),xg.makeRotationFromQuaternion(this.quaternion),this.matrix.premultiply(xg),xg.makeScale(this.scale.x,this.scale.y,this.scale.z),this.matrix.premultiply(xg);const t=this.position;xg.makeTranslation(t.x+e.x,t.y+e.y,t.z+e.z),this.matrix.premultiply(xg),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 wm(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||{},o=this.stage.getParameters();s.matrix=this.matrix.clone(),s.quality=s.quality||o.quality,s.disableImpostor=Ia(s.disableImpostor,!o.impostor),s.useWorker=Ia(s.useWorker,o.workerDefault),s.visible=Ia(s.visible,!0);const a=Object.assign({},s,{visible:this.parameters.visible&&s.visible}),c=function(t,i,n,r){var s;if(e.Debug&&il.time("makeRepresentation "+t),i instanceof Fp){if(!(s=ll.get(t)))return void mg(t)}else if(i instanceof Xf)if("surface"===t)s=lm;else{if("dot"!==t)return void mg(t);s=og}else if(i instanceof Zf)if("surface"===t)s=lm;else if("dot"===t)s=og;else{if("slice"!==t)return void mg(t);s=fg}else if(i instanceof Gp)s=Vp,i=i.getBufferList();else{if("buffer"!==t)return void il.error("makeRepresentation: object "+i+" unknown");s=Vp}const o=new s(i,n,r);return e.Debug&&il.timeEnd("makeRepresentation "+t),o}(t,i,this.viewer,a),l=new yg(this.stage,c,s,this);return r||(this.reprList.push(l),this.signals.representationAdded.dispatch(l)),l}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 Ni}getCenterUntransformed(...e){return this.getBoxUntransformed().getCenter(new Zt)}autoView(e){this.stage.animationControls.zoomMove(this.getCenter(),this.getZoom(),Ia(e,0))}}class Sg{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 Ag extends Sg{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 Mg=Object.assign({defaultStep:1,defaultTimeout:50,defaultInterpolateType:"",defaultInterpolateStep:5,defaultMode:"loop",defaultDirection:"forward",initialFrame:0},pg);class Cg extends gg{constructor(e,t,i={}){super(e,Object.assign({name:t.name},i)),this.trajectory=t,this.signals=Object.assign(this.signals,{frameChanged:new mc.Signal,playerChanged:new mc.Signal,countChanged:new mc.Signal,parametersChanged:new mc.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 Mg}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 Pg{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 Tg{constructor(e,t){let i,n;if(this.A=new Mf(3,3),this.W=new Mf(1,3),this.U=new Mf(3,3),this.V=new Mf(3,3),this.VH=new Mf(3,3),this.R=new Mf(3,3),this.tmp=new Mf(3,3),this.c=new Mf(3,3),e instanceof Fp)i=e.atomCount;else{if(!(e instanceof Float32Array))return;i=e.length/3}if(t instanceof Fp)n=t.atomCount;else{if(!(t instanceof Float32Array))return;n=t.length/3}const r=Math.min(i,n),s=new Mf(3,r),o=new Mf(3,r);this.coords1t=new Mf(r,3),this.coords2t=new Mf(r,3),this.transformationMatrix=new ri,this.c.data.set([1,0,0,0,1,0,0,0,-1]),this.prepCoords(e,s,r,!1),this.prepCoords(t,o,r,!1),this._superpose(s,o)}_superpose(t,i){this.mean1=If(t),this.mean2=If(i),Ef(t,this.mean1),Ef(i,this.mean2),Cf(this.coords1t,t),Cf(this.coords2t,i),Pf(this.A,this.coords2t,this.coords1t),Of(this.A,this.W,this.U,this.V),function(e,t){const i=e.data,n=t.data,r=i[4],s=i[8],o=i[5],a=i[7],c=i[0],l=c*r,h=c*o,u=i[3],d=i[1],f=u*d,m=i[2],p=u*m,g=i[6],v=g*d,y=g*m,x=1/(l*s-h*a-f*s+p*a+v*o-y*r);n[0]=(r*s-o*a)*x,n[1]=-(d*s-m*a)*x,n[2]=-(-d*o+m*r)*x,n[3]=-(u*s-o*g)*x,n[4]=(c*s-y)*x,n[5]=-(h-p)*x,n[6]=-(-u*a+r*g)*x,n[7]=-(c*a-v)*x,n[8]=(l-f)*x}(this.V,this.VH),Tf(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&&il.log("R not a right handed system"),Tf(this.tmp,this.c,this.VH),Tf(this.R,this.U,this.tmp));const n=new Mf(4,4),r=new Mf(4,4),s=new Mf(4,4),o=new Mf(4,4),a=new Mf(4,4),c=new Mf(4,4),l=this.R.data,h=this.mean1,u=this.mean2;o.data.set([1,0,0,-h[0],0,1,0,-h[1],0,0,1,-h[2],0,0,0,1]),a.data.set([l[0],l[1],l[2],0,l[3],l[4],l[5],0,l[6],l[7],l[8],0,0,0,0,1]),c.data.set([1,0,0,u[0],0,1,0,u[1],0,0,1,u[2],0,0,0,1]),Cf(r,o),Pf(n,a,r),Cf(s,n),Pf(r,c,s),Cf(n,r),this.transformationMatrix.elements=n.data}prepCoords(e,t,i,n){let r=0;const s=t.data;let o=3,a=3*i;if(n&&(a=4*i,o=4),e instanceof Fp)e.eachAtom((function(e){r{e!==this&&this.pause()}),this);const i=Ia(e.frameCount,1);this.traj=e,this.parameters=Ea(t,Ig),this.parameters.end=Math.min(Ia(t.end,i-1),i-1),this.parameters.step=Ia(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(Ia(this.parameters.end,e-1),e-1)}),this),this._animate=this._animate.bind(this)}get isRunning(){return this._run}setParameters(e={}){Da(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 mc.Signal,frameChanged:new mc.Signal,playerChanged:new mc.Signal},this.frameCache={},this.loadQueue={},this.boxCache={},this.pathCache={},this.frameCacheSize=0,this._frameCount=0,this._currentFrame=-1,this._disposed=!1,this.deltaTime=Ia(i.deltaTime,0),this.timeOffset=Ia(i.timeOffset,0),this.centerPbc=Ia(i.centerPbc,!1),this.removePbc=Ia(i.removePbc,!1),this.removePeriodicity=Ia(i.removePeriodicity,!1),this.superpose=Ia(i.superpose,!1),this.name=e.replace(/^.*[\\/]/,""),this.trajPath=e,this.selection=new $c(Ia(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 Eg(this))}_loadFrameCount(){}setStructure(e){this.structure=e,this.atomCount=e.atomCount,this.backboneIndices=this._getIndices(new $c("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 o=this.frameCache;let a;a="spline"===s?function(e,t,i,n,r){const s=e.length,o=new Float32Array(s);for(let a=0;a{this._interpolate(e,t,i,n,r,s),o&&o()})):(this._interpolate(e,t,i,n,r,s),o&&o()),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){il.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[zl(t,i[0],3,0,e),zl(t,i[1],3,1,e),zl(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],o=i[2],a=-t[0]+r+r/2,c=-t[1]+s+s/2,l=-t[2]+o+o/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 Lg extends Dg{constructor(e,t,i){const n=i||{};n.timeOffset=Ia(n.timeOffset,e.timeOffset),n.deltaTime=Ia(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 il.error(`empty arrayBuffer for '${r}'`);const s=new Int32Array(e,0,1)[0],o=new Float32Array(e,8,9),a=new Float32Array(e,44);this._process(t,o,a,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 Og 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)))}}Fp.prototype.getView=function(e){return new Bg(this,e)};class Bg extends Fp{constructor(e,t){super(),this.structure=e,this.selection=t,this.center=new Zt,this.boundingBox=new Ni,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&&il.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 Yu(t.atomCount),this.bondSet=new Yu(t.bondCount);for(let e in this.atomSetDict)this.atomSetCache["__"+e]=new Yu(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 Zt)}e.Debug&&il.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 $c(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&&il.log("Alignment: SCORE",this.score),e.Debug&&il.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:il.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&&il.timeEnd("Alignment.trace"),e.Debug&&il.log([this.ali1,this.ali2])}}function $g(e,t,i=!1,n="",r=""){let s,o,a,c,l;if(i){let i=e,h=t;n&&r&&(i=e.getView(new $c(n)),h=t.getView(new $c(r)));const u=i.getSequence(),d=h.getSequence(),f=new Ug(u.join(""),d.join(""));let m,p;f.calc(),f.trace(),s=0,o=0,a=f.ali1.length;const g=[],v=[];for(let e=0;ee[t]))}}}(),this.spacefillRepresentation=this.addRepresentation("spacefill",{sele:"none",opacity:nl.opacity,color:nl.color,disablePicking:!0,radiusType:"data"},!0),this.distanceRepresentation=this.addRepresentation("distance",nl,!0),this.angleRepresentation=this.addRepresentation("angle",nl,!0),this.dihedralRepresentation=this.addRepresentation("dihedral",nl,!0),this.measureRepresentations=new Ag([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 Gg}get type(){return"structure"}initSelection(e){this.selection=new $c(e),this.structureView=new Bg(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 Pg?new Lg(e,t,i):!e&&t.frames?new Rg(e,t,i):e&&"function"==typeof e?new Og(e,t,i):new kg(e,t,i),n}(e,this.structureView,t),n=new Cg(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),Ia(t,0))}getBoxUntransformed(e){let t;return t=e?this.structureView.getBoundingBox(new $c(e)):this.structureView.boundingBox,t}getCenterUntransformed(e){return e&&"string"==typeof e?this.structure.atomCenter(new $c(e)):this.structure.center}superpose(e,t,i,n){return $g(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-rc(.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()}}fl.add("structure",Vg),fl.add("structureview",Vg);class Hg extends wg{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()}}fl.add("surface",Hg);class jg extends wg{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()}}fl.add("volume",jg);class Wg extends Sg{addRepresentation(e,t){return this.forEach((i=>i.addRepresentation(e,t)))}autoView(e){return this.forEach((t=>t.autoView(e)))}}function qg(e,t){return e instanceof RegExp?null!==t.name.match(e):t.name===e}const Xg=new Zt,Yg={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,ambientColor:14540253,ambientIntensity:.2,hoverTimeout:0,tooltip:!0,mousePreset:"default"};class Zg extends wg{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 Kg(e,t,i,n){var r,s=arguments.length,o=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(o=(s<3?r(o):s>3?r(t,i,o):r(t,i))||o);return s>3&&o&&Object.defineProperty(t,i,o),o}fl.add("shape",Zg);class Qg extends dc{constructor(e){super(e),e.scale||(this.parameters.scale="rainbow",this.parameters.reverse=Ia(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)}}Kg([uc],Qg.prototype,"atomColor",null),al.add("atomindex",Qg);class Jg extends dc{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 $c(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)}}Kg([uc],Jg.prototype,"atomColor",null),al.add("bfactor",Jg);class ev extends dc{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])}}Kg([uc],ev.prototype,"atomColor",null),al.add("chainid",ev);class tv extends dc{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)}}Kg([uc],tv.prototype,"atomColor",null),al.add("chainindex",tv);class iv extends dc{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])}}Kg([uc],iv.prototype,"atomColor",null),al.add("chainname",iv);class nv extends dc{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}}Kg([uc],nv.prototype,"atomColor",null),al.add("densityfit",nv);const rv={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 sv extends dc{constructor(e){super(e),this.delta=new Zt,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()&&(rv[i.resname]&&rv[i.resname][i.atomname]||rv.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 Zt){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)}}Kg([uc],sv.prototype,"positionColor",null),al.add("electrostatic",sv);const ov={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 av extends dc{constructor(e){e.value=Ia(e.value,ov.C),super(e)}atomColor(e){const t=e.element;return"C"===t?this.parameters.value:ov[t]||16777215}}Kg([uc],av.prototype,"atomColor",null),al.add("element",av);class cv extends dc{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)}}Kg([uc],cv.prototype,"atomColor",null),al.add("entityindex",cv);class lv extends dc{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}}}Kg([uc],lv.prototype,"atomColor",null),al.add("entitytype",lv);class hv extends dc{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}}Kg([uc],hv.prototype,"atomColor",null),al.add("geoquality",hv);class uv extends dc{constructor(e){super(e),this.resHF={},e.scale||(this.parameters.scale="RdYlGn");for(const e in md)this.resHF[e]=md[e][0];if(this.defaultResidueHydrophobicity=pd[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)}}Kg([uc],uv.prototype,"atomColor",null),al.add("hydrophobicity",uv);class dv extends dc{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)}}Kg([uc],dv.prototype,"atomColor",null),al.add("modelindex",dv);class fv extends dc{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}}}Kg([uc],fv.prototype,"atomColor",null),al.add("moleculetype",fv);class mv extends dc{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)}}Kg([uc],mv.prototype,"atomColor",null),al.add("occupancy",mv);class pv extends dc{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 gv(){return 16777215*Math.random()}Kg([uc],pv.prototype,"atomColor",null),al.add("partialcharge",pv);class vv extends dc{atomColor(){return gv()}volumeColor(){return gv()}positionColor(){return gv()}}Kg([uc],vv.prototype,"atomColor",null),Kg([uc],vv.prototype,"volumeColor",null),Kg([uc],vv.prototype,"positionColor",null),al.add("random",vv);class yv extends dc{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}}Kg([uc],yv.prototype,"atomColor",null),al.add("randomcoilindex",yv);class xv extends dc{constructor(e){super(e),this.scalePerChain={},e.scale||(this.parameters.scale="rainbow",this.parameters.reverse=Ia(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)}}Kg([uc],xv.prototype,"atomColor",null),al.add("residueindex",xv);const bv={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 _v extends dc{atomColor(e){return bv[e.resname]||16711935}}Kg([uc],_v.prototype,"atomColor",null),al.add("resname",_v);const wv=16711808,Sv=10485888,Av=6291584,Mv=16762880,Cv=6324479,Pv=16777215,Tv=11403518,Iv=16580962,Ev=10921722;class Dv extends dc{constructor(e){super(e),this.residueProxy=e.structure.getResidueProxy()}atomColor(e){const t=e.sstruc,i=this.residueProxy;return"h"===t?wv:"g"===t?Sv:"i"===t?Av:"e"===t||"b"===t?Mv:"t"===t?Cv:(i.index=e.residueIndex,i.isDna()?Tv:i.isRna()?Iv:i.isSaccharide()?Ev:i.isProtein()||"s"===t||"l"===t?Pv:8421504)}}Kg([uc],Dv.prototype,"atomColor",null),al.add("sstruc",Dv);class Lv extends dc{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}}Kg([uc],Lv.prototype,"atomColor",null),Kg([uc],Lv.prototype,"bondColor",null),al.add("structuredata",Lv);class Rv extends dc{atomColor(){return this.parameters.value}bondColor(){return this.parameters.value}valueColor(){return this.parameters.value}volumeColor(){return this.parameters.value}}Kg([uc],Rv.prototype,"atomColor",null),Kg([uc],Rv.prototype,"bondColor",null),Kg([uc],Rv.prototype,"valueColor",null),Kg([uc],Rv.prototype,"volumeColor",null),al.add("uniform",Rv);class kv extends dc{constructor(e){super(e),this.valueScale=this.getScale()}volumeColor(e){return this.valueScale(this.parameters.volume.data[e])}}Kg([uc],kv.prototype,"volumeColor",null),al.add("value",kv);class Ov extends dc{constructor(e){super(e),this.vec=new Zt,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,o=r*s;i.copy(e),i.applyMatrix4(t.inverseMatrix);const a=Math.floor(i.x),c=Math.floor(i.y),l=Math.floor(i.z),h=(l*s+c)*r+a,u=h+1,d=h+r,f=h+o,m=d+1,p=f+1,g=d+o,v=g+1,y=n[h],x=n[u],b=n[d],_=n[f],w=n[m],S=n[p],A=n[g],M=n[v],C=i.x-a,P=i.y-c,T=i.z-l,I=ic(y,x,C),E=ic(_,S,C),D=ic(b,w,C),L=ic(A,M,C),R=ic(I,D,P),k=ic(E,L,P),O=ic(R,k,T);return this.valueScale(O)}}Kg([uc],Ov.prototype,"positionColor",null),al.add("volume",Ov);class Bv extends tu{constructor(e,t,i){const n=i||{};if(super(e,t,n),this.type="structure",this.parameters=Object.assign({radiusType:{type:"select",options:Tm.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 $c(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=Ia(t.colorScheme,"element"),this.setRadius(t.radius,t),this.radiusType=Ia(t.radiusType,"vdw"),this.radiusData=Ia(t.radiusData,{}),this.radiusSize=Ia(t.radiusSize,1),this.radiusScale=Ia(t.radiusScale,1),this.assembly=Ia(t.assembly,"default"),this.defaultAssembly=Ia(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(Pm);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,Kc&&(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 Tm(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,el&&!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 Nv extends Bv{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=Ia(t.labelVisible,!0),this.labelSize=Ia(t.labelSize,2),this.labelColor=Ia(t.labelColor,16777215),this.labelFontFamily=Ia(t.labelFontFamily,"sans-serif"),this.labelFontStyle=Ia(t.labelFontstyle,"normal"),this.labelFontWeight=Ia(t.labelFontWeight,"bold"),this.labelsdf=Ia(t.labelsdf,"Chrome"===Yc),this.labelXOffset=Ia(t.labelXOffset,0),this.labelYOffset=Ia(t.labelYOffset,0),this.labelZOffset=Ia(t.labelZOffset,.5),this.labelAttachment=Ia(t.labelAttachment,"bottom-left"),this.labelBorder=Ia(t.labelBorder,!1),this.labelBorderColor=Ia(t.labelBorderColor,"lightgrey"),this.labelBorderWidth=Ia(t.labelBorderWidth,.15),this.labelBackground=Ia(t.labelBackground,!1),this.labelBackgroundColor=Ia(t.labelBackgroundColor,"lightgrey"),this.labelBackgroundMargin=Ia(t.labelBackgroundMargin,.5),this.labelBackgroundOpacity=Ia(t.labelBackgroundOpacity,1),this.labelFixedSize=Ia(t.labelFixedSize,!1),this.lineOpacity=Ia(t.lineOpacity,1),this.linewidth=Ia(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:Gl(this.n,this.labelSize)}),!e||e.labelColor){const e=new mn(this.labelColor);Object.assign(i,{color:Vl(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 Fv(e,t){const i=e.getAtomProxy(),n=new $c,r=t.length;if(0===r)return new Float32Array(0);const s=t[0].length,o=e.getAtomSet(),a=new Float32Array(r*s*3);let c=0;return t.forEach((function(t){let r=!1;for(let l=0;l 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 encodings_fragment\n#include fog_fragment\n#endif\n}");const Gv={};const Vv={font:"sans-serif",size:36,style:"normal",variant:"normal",weight:"normal",outline:3,width:1024,height:1024};class Hv{constructor(e={}){this.gamma=1,this.mapped={},this.scratchW=0,this.scratchH=0,this.currentX=0,this.currentY=0,this.cutoff=.25,this.parameters=Ea(e,Vv);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");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 na(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,o=n,a=i-t.outline,c=r.measureText(e),l=Math.min(s,Math.ceil(c.width+2*o+1)),h=l*i;r.clearRect(0,0,l,i),r.fillText(e,o,a);const u=r.getImageData(0,0,l,i),d=u.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}"),ul.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 encodings_fragment\n#include fog_fragment\n#endif\n}");const Yv=Object.assign({linewidth:2},em),Zv=Object.assign({linewidth:{uniform:!0}},tm);class Kv extends Jp{constructor(e,t={}){super(e,t),this.parameterTypes=Zv,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 zt},projectionMatrixInverse:{value:new ri}}),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 Yv}setParameters(e){super.setParameters(e)}}ml.add("wideline",Kv);class Qv extends Nv{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=Ia(t.side,"double"),t.opacity=Ia(t.opacity,.5),this.atomTriple=Ia(t.atomTriple,[]),this.arcVisible=Ia(t.arcVisible,!0),this.sectorVisible=Ia(t.sectorVisible,!0),this.vectorVisible=Ia(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}\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\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 geometryNormal = 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 encodings_fragment\n#include fog_fragment\n#endif\n}");const oy=new Float32Array([-1,1,-1,-1,-1,-1,1,1,-1,1,1,1,1,-1,-1,1,-1,1]),ay=new Uint16Array([0,1,2,1,4,2,2,4,3,4,5,3]);class cy extends Zp{constructor(e,t={}){super("v3",e,t)}get mapping(){return oy}get mappingIndices(){return ay}get mappingIndicesSize(){return 12}get mappingSize(){return 6}get mappingItemSize(){return 3}}const ly=Object.assign({openEnded:!1},em),hy=Object.assign({openEnded:{updateShader:!0}},tm);class uy extends cy{constructor(e,t={}){super(e,t),this.parameterTypes=hy,this.isImpostor=!0,this.vertexShader="CylinderImpostor.vert",this.fragmentShader="CylinderImpostor.frag",this.addUniforms({modelViewMatrixInverse:{value:new ri},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 ly}getDefines(e){const t=cy.prototype.getDefines.call(this,e);return this.parameters.openEnded||(t.CAP=1),t}}Object.assign({disableImpostor:!1},ny,ly);const dy=class{constructor(e,t={}){return!e.color2&&e.color&&(e.color2=e.color),!el||t&&t.disableImpostor?new sy(e,t):new uy(e,t)}};ml.add("cylinder",dy);class fy extends Bv{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=Ia(t.radiusSize,.5),t.colorValue=Ia(t.colorValue,"lightgreen"),t.useInteriorColor=Ia(t.useInteriorColor,!0),this.showAxes=Ia(t.showAxes,!0),this.showBox=Ia(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 mn(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),o=Vl(n,i.r,i.g,i.b),a=Gl(n,this.radiusSize),c=new Float32Array(3*r),l=new Float32Array(3*r),h=Vl(r,i.r,i.g,i.b),u=Gl(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(c,d),t.toArray(l,d),d+=3};e(t.begA,t.endA),e(t.begB,t.endB),e(t.begC,t.endC)}if(this.showBox){const i=new Zt,{d1a:n,d2a:r,d3a:o,d1b:a,d2b:h,d3b:u}=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,o),m(n,r,u),m(n,h,u),m(n,h,o),m(a,h,u),m(a,h,o),m(a,r,o),m(a,r,u);let p=d;const g=function(e,t){i.fromArray(s,2*d+3*e).toArray(c,p),i.fromArray(s,2*d+3*t).toArray(l,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 uf(t);return{vertex:{position:s,color:o,radius:a,picking:f},edge:{position1:c,position2:l,color:h,color2:h,radius:u,picking:f}}}create(){const e=this.getAxesData(this.structureView);this.sphereBuffer=new tg(e.vertex,this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0})),this.cylinderBuffer=new dy(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)}}ll.add("axes",fy);class my extends Bv{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=Ia(t.radiusType,"size"),t.radiusSize=Ia(t.radiusSize,.15),t.useInteriorColor=Ia(t.useInteriorColor,!0),this.aspectRatio=Ia(t.aspectRatio,2),this.lineOnly=Ia(t.lineOnly,!1),this.cylinderOnly=Ia(t.cylinderOnly,!1),this.multipleBond=Ia(t.multipleBond,"off"),this.bondSpacing=Ia(t.bondSpacing,1),this.bondScale=Ia(t.bondScale,.4),this.linewidth=Ia(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 Kv(this.getBondData(e,{position:!0,color:!0,picking:!0}),this.getBufferParams({linewidth:this.linewidth})),t.push(this.lineBuffer);else{const i=new dy(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 tg(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}),el&&!this.disableImpostor||(t=!0)),super.setParameters(e,i,t),this}}ll.add("ball+stick",my);class py extends my{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=Ia(t.aspectRatio,1),t.radiusSize=Ia(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))}}ll.add("backbone",py);class gy extends my{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=Ia(t.aspectRatio,1),t.radiusSize=Ia(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)}}ll.add("base",gy);class vy{constructor(e,t){this.m=e,this.tension=t,this.dt=1/this.m,this.delta=1e-4,this.vec1=new Zt,this.vec2=new Zt,this.vDir=new Zt,this.vTan=new Zt,this.vNorm=new Zt,this.vBin=new Zt,this.m2=Math.ceil(this.m/2)}interpolateToArr(e,t,i,n,r,s,o){s[o+0]=nc(e.x,t.x,i.x,n.x,r,this.tension),s[o+1]=nc(e.y,t.y,i.y,n.y,r,this.tension),s[o+2]=nc(e.z,t.z,i.z,n.z,r,this.tension)}interpolateToVec(e,t,i,n,r,s){s.x=nc(e.x,t.x,i.x,n.x,r,this.tension),s.y=nc(e.y,t.y,i.y,n.y,r,this.tension),s.z=nc(e.z,t.z,i.z,n.z,r,this.tension)}interpolatePosition(e,t,i,n,r,s){for(var o=0;o1&&(l=1),this.interpolateToVec(e,t,i,n,c,this.vec1),this.interpolateToVec(e,t,i,n,l,this.vec2),this.vec2.sub(this.vec1).normalize(),this.vec2.toArray(r,h)}}vectorSubdivide(e,t,i,n,r){let s,o=t.next(),a=t.next(),c=t.next();const l=t.size,h=l-1;let u=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(),o=n.getSubdividedOrientation(),a=n.getSubdividedColor(this.getColorParams()),c=n.getSubdividedPicking(),l=n.getSubdividedSize(this.getRadiusParams());t.push(new wy(Object.assign({},s,o,a,c,l),this.getBufferParams({radialSegments:this.radialSegments,aspectRatio:r,capped:this.capped})))}),e.getSelection()),{bufferList:t,polymerList:i}}updateData(t,i){e.Debug&&il.time(this.type+" repr update"),t=t||{};for(var n=0,r=i.polymerList.length;n0;fu(w,y,S);const r=du(w,b)<0;if(bu(w,b,du(b,x)),fu(A,x,w),bu(w,b,du(b,_)),fu(M,_,w),0===yu(A)||0===yu(M))continue;_u(A,A),_u(M,M);const L=s[E]=Pu(A,M);a[E]=(Fl*L).toFixed(1)+String.fromCharCode(176),uu(T,A,b),_u(T,T),du(T,M)<0&&Cu(T,T),zv(w,S,A,T,L/2),gu(w,o,3*E);const R=Math.ceil(L/i),k=R+(t.extendLine?4:2),O=t.extendLine?36:0,B=new Float32Array(3*k),N=new Float32Array(3*k),F=new Float32Array(9*R),z=new Float32Array(O);c[E]=B,l[E]=N,h[E]=F,u[E]=z,t.extendLine&&(n?(fu(w,p,v),_u(w,w),bu(C,w,1/du(A,w)),mu(C,C,v)):(bu(C,x,1/du(A,x)),mu(C,C,g)),r?(fu(w,y,g),_u(w,w),bu(P,w,1/du(M,w)),mu(P,P,g)):(bu(P,_,1/du(M,_)),mu(P,P,v))),mu(I,S,A);let U=0;t.extendLine?(gu(p,B,U),gu(C,N,U),U+=3,gu(C,B,U),gu(I,N,U),U+=3,gu(C,z,0),gu(I,z,3),gu(n?v:g,z,6),gu(n?v:g,z,9),gu(I,z,12),gu(S,z,15)):(gu(S,B,U),gu(I,N,U),U+=3);const $=function(e,t){const i=9*t;gu(S,F,i),gu(I,F,i+3),gu(I,B,U),zv(I,S,A,T,e),gu(I,F,i+6),gu(I,N,U),U+=3};let G=0;for(let e=i;e{const t=Cy(i,e);Object.assign(e,t)})),t.side=Ia(t.side,"double"),t.opacity=Ia(t.opacity,.5),t.radiusType=Ia(t.radiusType,"size"),t.radiusSize=Ia(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=Fv(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(Kl(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 nm({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=Iy(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 Iy(e){const t=e.atomPositions,i=e.histogram360Scaled,n=i.length<=180?360:2*i.length,r={triangles:new Float32Array(3*n*3),triangleColors:Py(e.opaqueMiddleDiscColor,3*n)},s={triangles:new Float32Array(3*i.length*3),triangleColors:Py(e.frontHistogramColor,3*i.length)},o={triangles:new Float32Array(3*i.length*3),triangleColors:Py(e.backHistogramColor,3*i.length)},a={startPoints:new Float32Array(3*i.length),endPoints:new Float32Array(3*i.length),startColors:Py(e.histogramBinBorderColor,i.length),endColors:Py(e.histogramBinBorderColor,i.length)},c={startPoints:new Float32Array(3*i.length),endPoints:new Float32Array(3*i.length),startColors:Py(e.histogramBinBorderColor,i.length),endColors:Py(e.histogramBinBorderColor,i.length)},l={startPoints:new Float32Array(6),endPoints:new Float32Array(6),startColors:Py(e.adjacentBondArrowColor,i.length),endColors:Py(e.adjacentBondArrowColor,i.length)},h={startPoints:new Float32Array(6),endPoints:new Float32Array(6),startColors:Py(e.distantBondArrowColor,i.length),endColors:Py(e.distantBondArrowColor,i.length)},u=hu(),d=hu(),f=hu(),m=hu(),p=hu(),g=hu(),v=hu(),y=hu(),x=hu(),b=hu(),_=hu(),w=hu(),S=hu(),A=hu(),M=hu(),C=hu(),P=[u,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(!u.get(d)||!u.get(f))return void(h+=1);c.index=d,l.index=f}else{s.setString(d),o.setString(f);var m=e.getAtomIndices(s),p=e.getAtomIndices(o);if(!m.length||!p.length)return void(h+=1);c.index=m[0],l.index=p[0]}a.addBond(c,l,1),i-=h;var g=c.distanceTo(l);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 v=3*i;r[v+0]=(c.x+l.x)/2,r[v+1]=(c.y+l.y)/2,r[v+2]=(c.z+l.z)/2})),h>0&&(i-=h,r=r.subarray(0,3*i));var d=new Yu(a.count,!0);return{text:n,position:r,bondSet:d,bondStore:a}}getBondData(e,t,i){const n=e.getBondData(this.getBondParams(t,i));return n.picking&&(n.picking=new pf(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 mn(this.labelColor),n=this.getDistanceData(e,this.atomPair);this.textBuffer=new Xv({position:n.position,size:Gl(t,this.labelSize),color:Vl(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 dy(s,this.getBufferParams({openEnded:this.openEnded,radialSegments:this.radialSegments,disableImpostor:this.disableImpostor,dullInterior:!0})):this.distanceBuffer=new Kv(Iu(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 Dy(e){return 2*(e.position.length/3)*3}ll.add("distance",Ey);const Ly=Object.assign({scale:1,color:"grey"},em);class Ry extends im{constructor(e,t={}){super({position:new Float32Array(Dy(e)),color:new Float32Array(Dy(e))},t),this.isLine=!0,this.vertexShader="Line.vert",this.fragmentShader="Line.frag";const i=new mn(this.parameters.color),n=this.geometry.attributes;Vl(Dy(e)/3,i.r,i.g,i.b,n.color.array),this.setAttributes(e)}get defaultParameters(){return Ly}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,o=this.parameters.scale;if(i&&n)for(let e=0;e{if(e.residueCount<4)return;i.push(e);const n=new zm(e),r=n.getPosition(),s=n.getColor(this.getColorParams()),o=n.getSize(this.getRadiusParams()),a=n.getPicking();t.push(new tg({position:r.center,color:s.color,radius:o.size,picking:a.picking},this.getBufferParams({sphereDetail:this.sphereDetail,disableImpostor:this.disableImpostor,dullInterior:!0})),new Ry({position:r.center,vector:r.axis},this.getBufferParams({color:"skyblue",scale:1})),new Ry({position:r.center,vector:r.resdir},this.getBufferParams({color:"lightgreen",scale:1})))}),e.getSelection()),{bufferList:t,polymerList:i}}updateData(t,i){e.Debug&&il.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}"),ul.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 geometryNormal = 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 encodings_fragment\n#include fog_fragment\n#endif\n}");const By=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]),Ny=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 Fy extends Zp{constructor(e,t={}){super("v3",e,t)}get mapping(){return By}get mappingIndices(){return Ny}get mappingIndicesSize(){return 36}get mappingSize(){return 8}get mappingItemSize(){return 3}}const zy=Object.assign({shrink:.14},em),Uy=Object.assign({shrink:{uniform:!0}},tm);class $y extends Fy{constructor(e,t={}){super(e,t),this.parameterTypes=Uy,this.isImpostor=!0,this.vertexShader="HyperballStickImpostor.vert",this.fragmentShader="HyperballStickImpostor.frag",this.addUniforms({modelViewProjectionMatrix:{value:new ri},modelViewProjectionMatrixInverse:{value:new ri},modelViewMatrixInverseTranspose:{value:new ri},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 zy}}Object.assign({disableImpostor:!1},ny,zy);const Gy=class{constructor(e,t={}){return!el||t&&t.disableImpostor?(e.radius=function(e,t){const i=e.length,n=new Float32Array(i);for(let r=0;ra.push(n.atomLabel(e)))))}else if("residue"===this.labelGrouping){t&&!t.position||(c=[]),t&&!t.color||(h=[]),t&&!t.radius||(l=[]),t&&!t.text||(a=[]),i.colorParams&&(i.colorParams.structure=e.getStructure());const u=al.getScheme(i.colorParams),d=new Tm(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(c,i)):(f.index=e.atomOffset,t&&!t.position||e.positionToArray(c,i)),t&&!t.color||u.atomColorToArray(f,h,i),t&&!t.radius||(l[m]=d.atomRadius(f)),t&&!t.text||a.push(n.atomLabel(f)),++m})),t&&!t.position||(r=new Float32Array(c)),t&&!t.color||(o=new Float32Array(h)),t&&!t.radius||(s=new Float32Array(l))}return{position:r,size:s,color:o,text:a}}createData(e){return{bufferList:[new Xv(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 Wy(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}ll.add("label",jy);class qy extends Bv{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=Ia(t.multipleBond,"off"),this.bondSpacing=Ia(t.bondSpacing,1),this.linewidth=Ia(t.linewidth,2),this.lines=Ia(t.lines,!0),this.crosses=Ia(t.crosses,"lone"),this.crossSize=Ia(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:Wy(t)});const n=t.getAtomData(this.getAtomParams(e,i)),r={},s=n.position,o=n.color,a=n.picking,c=(s||o).length,l=3*c;let h=new Float32Array(0),u=new Float32Array(0),d=new Float32Array(0),f=new Float32Array(0),m=0,p=new Float32Array(0);e&&!e.position||(h=r.position1=new Float32Array(l),u=r.position2=new Float32Array(l),m=this.crossSize/2),e&&!e.color||(d=r.color=new Float32Array(l),f=r.color2=new Float32Array(l)),e&&!e.picking||(p=new Float32Array(3*n.picking.array.length));for(let t=0;tl?d[p]=-1:(c=Math.sqrt(l-a),d[p]=Math.floor(c)),++p;m[g]=u,f[g]=d}}function T(i){var n,r,s,a,u,p,y,b,_,w,A,M,C,P,T,I,E,D,L=3*i,R=i;n=Math.floor(.5+o*(e[L]+d[0])),r=Math.floor(.5+o*(e[L+1]+d[1])),s=Math.floor(.5+o*(e[L+2]+d[2]));var k,O=t[R],B=f[O],N=0,F=l*h,z=m[O];for(w=0;w=c||P>=l||T>=h)){var U=C*F+P*h+T;if(g)if(v[U]&S){if(v[U]&S){var $=x[U];$!==L&&y*y+b*b+_*_<(a=n+y-Math.floor(.5+o*(e[$]+d[0])))*a+(u=r+b-Math.floor(.5+o*(e[$+1]+d[1])))*u+(p=s+_-Math.floor(.5+o*(e[$+2]+d[2])))*p&&(x[U]=i)}}else v[U]|=S,x[U]=i;else v[U]|=S}N++}}function I(t){var i,n;for(console.time("EDTSurface fillvoxels"),i=0,n=v.length;i=c||S>=l||M>=h)){var F=w*N+S*h+M;if(v[F]&A){if(g){var z=x[F];y*y+b*b+_*_<(a=Math.floor(.5+o*(e[z]+d[0])))*a+(u=Math.floor(.5+o*(e[z+1]+d[1])))*u+(p=Math.floor(.5+o*(e[z+2]+d[2])))*p&&(x[F]=i)}}else v[F]|=A,g&&(x[F]=i)}O++}}function D(){var e,t,i,n;console.time("EDTSurface fastdistancemap");var r,s=Xy(c,l,h,Uint16Array,3),o=l*h,u=p*p,d=0;for(e=0;e0);var w,C=a*a,P=new Uint16Array(3);for(e=0;e=C)||(v[r]|=M,g&&v[r]&A&&(s.toArray(e,t,i,P),w=P[0]*o+P[1]*h+P[2],x[r]=x[w])));console.timeEnd("EDTSurface fastdistancemap")}function L(e,t,i,n){var r,s,o,a,u,d,f,m,p,g,x,b,_=new Uint16Array(3),w=0;if(0===i)return w;var P=-1,T=-1,I=-1,E=l*h;for(f=0,p=i;f-1&&T-1&&I-1&&(v[x=P*E+h*T+I]&S&&!(v[x]&A)?(t.fromArray(P,T,I,_),g=(a=P-_[0])*a+(u=T-_[1])*u+(d=I-_[2])*d,y[x]=g,v[x]|=A,v[x]|=M,n[w]=P,n[w+1]=T,n[w+2]=I,w+=3):v[x]&S&&v[x]&A&&(g=(a=P-_[0])*a+(u=T-_[1])*u+(d=I-_[2])*d)-1&&T-1&&I-1&&(v[x=P*E+h*T+I]&S&&!(v[x]&A)?(t.fromArray(P,T,I,_),g=(a=P-_[0])*a+(u=T-_[1])*u+(d=I-_[2])*d,y[x]=g,v[x]|=A,v[x]|=M,n[w]=P,n[w+1]=T,n[w+2]=I,w+=3):v[x]&S&&v[x]&A&&(g=(a=P-_[0])*a+(u=T-_[1])*u+(d=I-_[2])*d)-1&&T-1&&I-1&&(v[x=P*E+h*T+I]&S&&!(v[x]&A)?(t.fromArray(P,T,I,_),g=(a=P-_[0])*a+(u=T-_[1])*u+(d=I-_[2])*d,y[x]=g,v[x]|=A,v[x]|=M,n[w]=P,n[w+1]=T,n[w+2]=I,w+=3):v[x]&S&&v[x]&A&&(g=(a=P-_[0])*a+(u=T-_[1])*u+(d=I-_[2])*d)-1&&o-1&&u-1&&aE&&(E=k)}return{neighbourListLength:27*E+1,withinRadii:function(r,s,o,a,u){for(var d=0,f=m(r,c),p=m(s,l),g=m(o,h),v=Math.max(0,f-1),_=Math.max(0,p-1),S=Math.max(0,g-1),A=Math.min(y,f+2),M=Math.min(x,p+2),I=Math.min(b,g+2),E=v;Ed&&(d=h[e]);!function(){const e=qf(c,l,d,m,0);m=e.scaleFactor,v=e.dim,y=e.matrix,R=Math.max(5,2+Math.floor(f*m)),x=Gl(v[0]*v[1]*v[2],-1001),b=new Int32Array(x.length),_=new Float32Array(v[0]),w=new Float32Array(v[1]),S=new Float32Array(v[2]),O(_,c[0],1/m),O(w,c[1],1/m),O(S,c[2],1/m)}(),function(){var e=0,t=2*Math.PI/g;M=new Float32Array(g),A=new Float32Array(g);for(var i=0;i=0;){if(s!==n&&s!==r&&N(s,e,t,i))return T=s,s;s=P[++o]}return T=-1,-1}function N(t,i,n,r){var s=3*t,o=u[t],a=e[s]-i,c=e[s+1]-n,l=e[s+2]-r;return a*a+c*c+l*l0&&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 Jy extends Bv{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=Ia(t.colorScheme,"uniform"),t.colorValue=Ia(t.colorValue,14540253),t.disablePicking=Ia(t.disablePicking,!0),this.surfaceType=Ia(t.surfaceType,"ms"),this.probeRadius=Ia(t.probeRadius,1.4),this.smooth=Ia(t.smooth,2),this.scaleFactor=Ia(t.scaleFactor,2),this.cutoff=Ia(t.cutoff,0),this.contour=Ia(t.contour,!1),this.background=Ia(t.background,!1),this.opaqueBack=Ia(t.opaqueBack,!0),this.filterSele=Ia(t.filterSele,""),this.colorVolume=Ia(t.colorVolume,void 0),this.useWorker=Ia(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 $c(this.filterSele)),r=n.boundingBox.getSize(new Zt),s=Math.max(r.x,r.y,r.z),o=e.getAtomSetWithinPoint(n.center,s/2+6);if(0===(e=e.getView(new $c(e.getAtomSetWithinSelection(o,3).toSeleString()))).atomCount)return void i(t)}n.sele=e.selection.string,n.molsurf=new Qy(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 cm(r,this.getBufferParams({wireframe:!1}));s.push(e)}else{Object.assign(r,{normal:n.getNormal(),picking:n.getPicking(e.getStructure())});const t=new rm(r,this.getBufferParams({background:this.background,opaqueBack:this.opaqueBack,dullInterior:!1}));if("double"==this.getBufferParams().side){const e=new am(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()}}ll.add("surface",Jy);class ex extends Bv{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=Ia(t.pointSize,1),this.sizeAttenuation=Ia(t.sizeAttenuation,!0),this.sortParticles=Ia(t.sortParticles,!1),this.useTexture=Ia(t.useTexture,!1),this.alphaTest=Ia(t.alphaTest,.5),this.forceTransparent=Ia(t.forceTransparent,!1),this.edgeBleach=Ia(t.edgeBleach,0),super.init(t)}createData(e){var t=e.getAtomData(this.getAtomParams({position:!0,color:!0,picking:!0}));return{bufferList:[new sg(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}}ll.add("point",ex),ul.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 tx=new Uint16Array([0,1,2,1,3,2]);function ix(e){return 3*(4*(e.position.length/3-1))}class nx extends nm{constructor(e,t={}){super({position:new Float32Array(ix(e)),color:new Float32Array(ix(e)),index:Ga(ix(e),ix(e)/3),normal:new Float32Array(ix(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=Hl(i),this.setAttributes(e),this.makeIndex()}setAttributes(e={}){const t=this.size/4,i=this.geometry.attributes;let n,r,s,o,a,c,l,h,u,d,f,m,p,g,v,y,x,b,_;e.position&&(n=e.position,l=i.position.array,i.position.needsUpdate=!0),e.normal&&(r=e.normal,h=i.normal.array,i.normal.needsUpdate=!0),e.size&&(s=e.size,u=i.size.array,i.size.needsUpdate=!0),e.dir&&(o=e.dir,d=i.dir.array,i.dir.needsUpdate=!0),e.color&&(a=e.color,f=i.color.array,i.color.needsUpdate=!0),e.primitiveId&&(c=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 yy(e,this.getSplineParams()),r=n.getSubdividedPosition(),s=n.getSubdividedOrientation(),o=n.getSubdividedColor(this.getColorParams()),a=n.getSubdividedPicking(),c=n.getSubdividedSize(this.getRadiusParams());t.push(new nx({position:r.position,normal:s.binormal,dir:s.normal,color:o.color,size:c.size,picking:a.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 Um(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),o=0;i.forEach((function(e){r.begin.set(e.begin,3*o),r.end.set(e.end,3*o),r.size.set(e.size,o),r.color.set(e.color,3*o),s.set(e.picking.array,o),o+=e.size.length})),t&&(r.picking=new hf(s,e.getStructure()));return{bufferList:[new dy({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)}}}ll.add("rocket",sx);class ox 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=Ia(t.tension,.5),t.radiusScale=Ia(t.radiusScale,5),t.smoothSheet=!1,this.smooth=Ia(t.smooth,2),super.init(t)}getSpline(e){var t=new zm(e);return new yy(e,this.getSplineParams({directional:!1,positionIterator:t.getCenterIterator(this.smooth)}))}}ll.add("rope",ox);class ax extends Bv{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=Ia(t.useInteriorColor,!0),super.init(t)}createData(e){return{bufferList:[new tg(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 cx(e){return 3*(e.position.length/3-1)*2}ll.add("spacefill",ax);class lx extends im{constructor(e,t={}){super({position:new Float32Array(cx(e)),color:new Float32Array(cx(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 il.warn("TraceBuffer.prototype.setAttributes no data");let o,a;const c=this.size-1;for(let e=0;e{if(!(e.residueCount<4)){i.push(e);var n=new yy(e,this.getSplineParams()),r=n.getSubdividedPosition(),s=n.getSubdividedColor(this.getColorParams());t.push(new lx(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 _x=Object.assign({aspectRatio:1.5,radialSegments:50,openEnded:!1,disableImpostor:!1},em);class wx{constructor(e,t={}){this.group=new ko,this.wireframeGroup=new ko,this.pickingGroup=new ko,this.visible=!0,this.parameters=Ea(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 dy(i.cylinder,n),this.coneBuffer=new xx(i.cone,n),this.geometry=new bx([this.cylinderBuffer.geometry,this.coneBuffer.geometry]),this.matrix=Ia(t.matrix,new ri),this.picking=e.picking}get defaultParameters(){return _x}set matrix(e){im.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 o={},a={};if(e.radius){for(r=0,s=i.length;r(this._beforeParse(),this._parse(),this._afterParse(),this[this.__objName])))}_parse(){}_beforeParse(){}_afterParse(){e.Debug&&il.log(this[this.__objName])}}class Kx extends Zx{constructor(e,t){var i=t||{};super(e,i),this.firstModelOnly=Ia(i.firstModelOnly,!1),this.asTrajectory=Ia(i.asTrajectory,!1),this.cAlphaOnly=Ia(i.cAlphaOnly,!1),this.structure=new Fp(this.name,this.path),this.structureBuilder=new ep(this.structure)}get type(){return"structure"}get __objName(){return"structure"}}class Qx{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 Jx={a:1,b:1,c:1,alpha:90,beta:90,gamma:90,spacegroup:"P 1"};class eb{constructor(e=Jx){this.cartToFrac=new ri,this.fracToCart=new ri,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=Ka(this.alpha),i=Ka(this.beta),n=Ka(this.gamma),r=Math.cos(t),s=Math.cos(i),o=Math.cos(n),a=Math.sin(i),c=Math.sin(n);if(this.volume=this.a*this.b*this.c*Math.sqrt(1-r*r-s*s-o*o+2*r*s*o),void 0===e.cartToFrac){const e=this.a*this.b*c/this.volume,t=(s*o-r)/(a*c);this.fracToCart.set(this.a,0,0,0,this.b*o,this.b*c,0,0,this.c*s,-this.c*a*t,1/e,0,0,0,0,1).transpose(),this.cartToFrac.getInverse(this.fracToCart)}else this.cartToFrac.copy(e.cartToFrac),this.fracToCart.getInverse(this.cartToFrac)}getPosition(e){const t=new Float32Array(24);if(e.unitcell){const i=e.unitcell,n=e.center.clone().applyMatrix4(i.cartToFrac).floor(),r=new Zt;let s=0;const o=function(e,o,a){r.set(e,o,a).add(n).applyMatrix4(i.fracToCart).toArray(t,s),s+=3};o(0,0,0),o(1,0,0),o(0,1,0),o(0,0,1),o(1,1,0),o(1,0,1),o(0,1,1),o(1,1,1)}return t}getCenter(e){return function(e,t=new Zt){const i=e.length;for(let n=0;n0)continue;let e,i,n,r,a,g=0;if(s){if(r=A.split(rb),g=10===r.length?1:0,L=r[2],m&&"CA"!==L)continue;e=parseFloat(r[6-g]),i=parseFloat(r[7-g]),n=parseFloat(r[8-g])}else{if(L=A.substr(12,4).trim(),m&&"CA"!==L)continue;e=parseFloat(A.substr(30,8)),i=parseFloat(A.substr(38,8)),n=parseFloat(A.substr(46,8))}if(f){const t=3*y;if(v[t+0]=e,v[t+1]=i,v[t+2]=n,y+=1,x)continue}s?(C=parseInt(r[1]),a="",R="H"===A[0],P=g?"":r[4],T=parseInt(r[5-g]),D="",I=r[3],O="",E=1):(C=parseInt(A.substr(6,5),h),l&&99999===C&&(h=16),R="H"===A[0],P=A[21].trim(),T=parseInt(A.substr(22,4),u),l&&9999===T&&(u=16),D=A[26].trim(),I=A.substr(17,4).trim()||"MOL",k=parseFloat(A.substr(60,6)),O=A[16].trim(),E=parseFloat(A.substr(54,6)),t||(o?(a=A.substr(76,3).trim(),a in Td&&(a=Td[a])):(a=A.substr(76,2).trim(),P||(P=A.substr(72,4).trim())),B=parseInt((A.substr(79,1)+A.substr(78,1)).trim()))),ue.growIfFull(),ue.atomTypeId[me]=he.add(L,a),ue.x[me]=e,ue.y[me]=i,ue.z[me]=n,ue.serial[me]=C,ue.altloc[me]=O.charCodeAt(0),ue.occupancy[me]=isNaN(E)?0:E,s?(ue.partialCharge[me]=parseFloat(r[9-g]),ue.radius[me]=parseFloat(r[10-g])):(ue.bfactor[me]=isNaN(k)?0:k,o&&(ue.partialCharge[me]=parseFloat(A.substr(70,6))),isFinite(B)&&(ue.formalCharge||ue.addField("formalCharge",1,"int8"),ue.formalCharge[me]=B));const b=sb(T,P,D);!R||Z[b]||ib.includes(I)?ee||te===P||(Q+=1,J=Q.toString()):te===P&&ne===I&&(wd.includes(I)||ie===T&&re===D)||(Q+=1,J=Q.toString(),ie=T,ne=I,re=D),c.addAtom(pe,P,J,I,T,R,void 0,D),V[C]=me,me+=1,ee=!1,te=P}else if("CONECT"===M){const e=V[parseInt(A.substr(6,5))],t=[11,16,21,26],i={};if(void 0===e)continue;for(let n=0;n<4;++n){let r=parseInt(A.substr(t[n],5));if(!Number.isNaN(r)&&(r=V[r],void 0!==r))if(e0)continue;const L=n[c].replace(lb,"");if(P&&"CA"!==L)continue;const R=parseFloat(n[y]),k=parseFloat(n[x]),O=parseFloat(n[b]);if(C){const e=3*i;if(t[e+0]=R,t[e+1]=k,t[e+2]=O,i+=1,q>0)continue}const B=n[l],N=parseInt(n[-1!==o?o:a]);let F=n[v];F="?"===F?"":F;const z=n[s],U=n[h],X="H"===n[f][0],Y=n[p],Z=parseFloat(n[_]),K=parseFloat(n[w]);let Q=n[d];if(Q="."===Q?"":Q,H.growIfFull(),H.atomTypeId[W]=V.add(L,Y),H.x[W]=R,H.y[W]=k,H.z[W]=O,H.serial[W]=parseInt(n[m]),H.bfactor[W]=isNaN(Z)?0:Z,H.occupancy[W]=isNaN(K)?0:K,H.altloc[W]=Q.charCodeAt(0),A.addAtom(q,z,U,B,N,X,void 0,F),e.Debug){const t=E[U];void 0!==t&&t!==z&&e.Debug&&il.warn(t,z)}E[U]=z;const J=n[u];D[J]||(D[J]=new Set),D[J].add(S.chainStore.count-1),W+=1}else{const e=r.match(cb),t=e.length;F===N.length&&(F=0);for(let i=0;ic*c)return r.growIfFull(),r.atomTypeId[f]=r.atomTypeId[e],r.x[f]=h.x,r.y[f]=h.y,r.z[f]=h.z,r.occupancy[f]=r.occupancy[e],r.serial[f]=f,r.altloc[f]="A".charCodeAt(0),i.addAtom(0,"","","HET",1,!0),void(f+=1)}}}))}}(I,S,A),A.finalize(),S.finalizeAtoms(),op(S),S.finalizeBonds();else{var X=function(e,t,i){var n,r,s,o,a=[],c=[],l=e.struct_conf;if(null==l?void 0:l.pdbx_PDB_helix_class)for(fb(l,"id"),n=0,r=l.beg_auth_seq_id.length;n0){s=s.split("(");var c=a(s[0]),l=a(s[1]);Object.keys(c).forEach((function(e){Object.keys(l).forEach((function(t){var i=new ri;i.multiplyMatrices(c[e],l[t]),n[e+"x"+t]=i}))}))}else n=a(s);var h=[];for(var u in n)h.push(n[u]);var d=e;/^(0|[1-9][0-9]*)$/.test(d)&&(d="BU"+d);for(var f=o.asym_id_list[t].split(","),m=0,p=f.length;mS){var A=w;w=S,S=A;var M=p;p=b,b=M}if(0!==w&&0!==S)for(var C=0;Cx)continue}d=P.substr(5,5).trim(),f=parseInt(P.substr(0,5)),m=parseInt(P.substr(15,5)),_.growIfFull(),_.atomTypeId[w]=b.add(u),_.x[w]=E,_.y[w]=D,_.z[w]=L,_.serial[w]=m,r.addAtom(S,"","",d,f,!1,"l"),w+=1}}}(0,e.length,e)})),r.finalize(),n.finalizeAtoms(),sp(n),op(n),n.finalizeBonds(),ip(n),e.Debug&&il.timeEnd("GroParser._parse "+this.name)}});var yb=["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 xb(e,t,i){return t?new e(t.buffer,t.byteOffset,t.byteLength/(i||1)):void 0}function bb(e){return xb(DataView,e)}function _b(e){return xb(Int8Array,e)}function wb(e){return xb(Int32Array,e,4)}function Sb(e,t){var i=e.length/2;t||(t=new Int16Array(i));for(var n=0,r=0;ns&&++a;t=new Int32Array(a)}for(i=0,n=0;ir){for(var s=[],o=0;o0&&(o.biomolDict[e]=t)}const k=a.unitCell;k&&Array.isArray(k)&&k[0]?o.unitcell=new eb({a:k[0],b:k[1],c:k[2],alpha:k[3],beta:k[4],gamma:k[5],spacegroup:a.spaceGroup}):o.unitcell=void 0,hp(o,!0),lp(o,!0),o.finalizeAtoms(),o.finalizeBonds(),up(o),e.Debug&&il.timeEnd("MmtfParser._parse "+this.name)}});const Ob=/\s+/,Bb={1:1,2:2,3:3,am:1,ar:1,du:1,un:1,nc:0};hl.add("mol2",class extends Kx{get type(){return"mol2"}_parse(){e.Debug&&il.time("Mol2Parser._parse "+this.name);const t=this.structure,i=this.structureBuilder,n=this.firstModelOnly,r=this.asTrajectory,s=t.frames;let o,a,c=!1;const l=t.atomMap,h=t.atomStore;h.resize(Math.round(this.streamer.data.length/60)),h.addField("partialCharge",1,"float32");let u=0,d=0,f=0,m=-1,p=0,g=0;const v=t.getAtomProxy(),y=t.getAtomProxy();this.streamer.eachChunkOfLines((function(e){!function(e,x,b){for(let _=e;_MOLECULE"===e?(g=1,d=0,++m):"@ATOM"===e?(g=2,f=h.count,r&&(a=0,o=new Float32Array(3*p),s.push(o),m>0&&(c=!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(Ob);p=parseInt(t[0])}++d}else if(2===g){const t=e.split(Ob);if(n&&m>0)continue;const s=parseFloat(t[2]),d=parseFloat(t[3]),f=parseFloat(t[4]);if(r){const e=3*a;if(o[e+0]=s,o[e+1]=d,o[e+2]=f,a+=1,c)continue}const p=t[0],g=t[1],v=t[5].split(".")[0],y=t[6]?parseInt(t[6]):1,x=t[7]?t[7]:"",b=t[8]?parseFloat(t[8]):0;h.growIfFull(),h.atomTypeId[u]=l.add(g,v),h.x[u]=s,h.y[u]=d,h.z[u]=f,h.serial[u]=p,h.partialCharge[u]=b,i.addAtom(m,"","",x,y,!0),u+=1}else if(3===g){if(n&&m>0)continue;if(r&&m>0)continue;const i=e.split(Ob);v.index=parseInt(i[1])-1+f,y.index=parseInt(i[2])-1+f;const s=Bb[i[3]];t.bondStore.addBond(v,y,s)}}}(0,e.length,e)})),i.finalize(),t.finalizeAtoms(),sp(t),lp(t,!0),hp(t,!0),t.finalizeBonds(),pp(t),ip(t),e.Debug&&il.timeEnd("Mol2Parser._parse "+this.name)}});hl.add("pdbqt",class extends ob{get type(){return"pdbqt"}});hl.add("pqr",class extends ob{get type(){return"pqr"}});const Nb=/> +<(.+)>/;class Fb extends Kx{get type(){return"sdf"}_parse(){e.Debug&&il.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 o=t.frames;let a,c,l=!1;const h=t.atomMap,u=t.atomStore;u.resize(Math.round(this.streamer.data.length/50)),u.addField("formalCharge",1,"int8");const d=t.getAtomProxy(),f=t.getAtomProxy();let m=0,p=0,g=0,v=0;const y=[];let x,b,_,w,S,A,M,C,P,T,I,E,D,L,R=!1,k={};t.extraData.sdf=y;let O=!1,B=!1,N=!1,F=[],z=[];const U=new Map;this.streamer.eachChunkOfLines((function(e){!function(e,s,$){for(let G=e;G-1,O?U.clear():(b=parseInt(e.substr(0,3)),_=parseInt(e.substr(3,3)),w=4,S=w+b,A=S,M=A+_,r&&(c=0,a=new Float32Array(3*b),o.push(a),g>0&&(l=!0)));else if(O&&"COUNTS"===F[0])b=parseInt(F[1]),r&&(c=0,a=new Float32Array(3*b),o.push(a),g>0&&(l=!0));else if(O&&2==F.length)"ATOM"===F[1]?"BEGIN"===F[0]?B=!0:"END"===F[0]&&(B=!1):"BOND"===F[1]&&("BEGIN"===F[0]?N=!0:"END"===F[0]&&(N=!1));else if(B||!O&&p>=w&&p0)continue;let t=0;if(O){if(C=parseFloat(F[2]),P=parseFloat(F[3]),T=parseFloat(F[4]),E=F[1],D=parseInt(F[0]),U.set(D,m),I=E+D,F.length>6){let e=F.slice(6).find((e=>0===e.indexOf("CHG=")));e&&(t=parseInt(e.substring(4)))}}else C=parseFloat(e.substr(0,10)),P=parseFloat(e.substr(10,10)),T=parseFloat(e.substr(20,10)),E=e.substr(31,3).trim(),I=E+(m-v+1);if(r){const e=3*c;if(a[e+0]=C,a[e+1]=P,a[e+2]=T,c+=1,l)continue}u.growIfFull(),u.atomTypeId[m]=h.add(I,E),u.x[m]=C,u.y[m]=P,u.z[m]=T,u.serial[m]=O?D:m,u.formalCharge[m]=t,i.addAtom(g,"","","HET",1,!0),m+=1}else if(N||!O&&p>=A&&p0)continue;if(r&&g>0)continue;O?(d.index=U.get(parseInt(F[2])),f.index=U.get(parseInt(F[3])),L=parseInt(F[1])):(d.index=parseInt(e.substr(0,3))-1+v,f.index=parseInt(e.substr(3,3))-1+v,L=parseInt(e.substr(6,3))),t.bondStore.addBond(d,f,L)}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)&&(x=e.match(Nb))?(R=x[1],k[R]=[]):!1!==R&&e&&k[R].push(e);++p}}}(0,e.length,e)})),i.finalize(),t.finalizeAtoms(),t.finalizeBonds(),pp(t),e.Debug&&il.timeEnd("SdfParser._parse "+this.name)}_postProcess(){pp(this.structure)}}hl.add("sdf",Fb),hl.add("sd",Fb),hl.add("mol",Fb);function zb(e,t,i){return parseInt(e.substr(t,i).trim())}class Ub extends Kx{get type(){return"prmtop"}_parse(){e.Debug&&il.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=[],o={},a=["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 c,l,h,u,d;a.forEach((e=>{o[e]=0}));let f,m,p,g,v,y=new Uint8Array(0);this.streamer.eachChunkOfLines((function(e){!function(e,t,i){for(let n=e;n0)return void il.error("dcd format with fixed atoms unsupported, aborting");const p=o.NATOM,g=4*p;for(let e=0,n=o.NSET;e=1&&(n.timeOffset=(o.ISTART-1)*n.deltaTime),e.Debug&&il.timeEnd("DcdParser._parse "+this.name)}});const Yb={BYTE:1,CHAR:2,SHORT:3,INT:4,FLOAT:5,DOUBLE:6};function Zb(e){switch(Number(e)){case Yb.BYTE:return"byte";case Yb.CHAR:return"char";case Yb.SHORT:return"short";case Yb.INT:return"int";case Yb.FLOAT:return"float";case Yb.DOUBLE:return"double";default:return"undefined"}}function Kb(e){switch(Number(e)){case Yb.BYTE:case Yb.CHAR:return 1;case Yb.SHORT:return 2;case Yb.INT:case Yb.FLOAT:return 4;case Yb.DOUBLE:return 8;default:return-1}}function Qb(e){switch(String(e)){case"byte":return Yb.BYTE;case"char":return Yb.CHAR;case"short":return Yb.SHORT;case"int":return Yb.INT;case"float":return Yb.FLOAT;case"double":return Yb.DOUBLE;default:return-1}}function Jb(e,t){if(1!==e){const i=new Array(e);for(let n=0;n6,"non valid type "+h);const u=e.readUint32();let d=e.readUint32();2===i&&(Wb(d>0,"offsets larger than 4GB not supported"),d=e.readUint32()),c[0]===t&&(s+=u),r[n]={name:o,dimensions:c,attributes:l,type:Zb(h),size:u,offset:d,record:c[0]===t}}}return{variables:r,recordStep:s}}(e,n.recordId,t);return i.variables=r.variables,i.recordDimension.recordStep=r.recordStep,i}function o_(e){let t;const i=e.readUint32();if(i===t_)return Wb(e.readUint32()!==t_,"wrong empty tag for list of attributes"),[];{Wb(i!==r_,"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(),o=e_(e,r,s);qb(e),t[i]={name:n,type:Zb(r),value:o}}}return t}class a_{constructor(e){const t=new Il(e);t.setBigEndian(),Wb("CDF"!==t.readChars(3),"should start with CDF");const i=t.readByte();Wb(i>2,"unknown version"),this.header=s_(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,Wb(void 0===t,"variable not found"),this.buffer.seek(t.offset),t.record?function(e,t,i){const n=Qb(t.type),r=t.size?t.size/Kb(n):1,s=i.length,o=new Array(s),a=i.recordStep;for(let t=0;t=1&&(i.timeOffset=s[0]),s.length>=2&&(i.deltaTime=s[1]-s[0]),e.Debug&&il.timeEnd("NctrajParser._parse "+this.name)}}hl.add("nctraj",c_),hl.add("ncdf",c_),hl.add("nc",c_);hl.add("trr",class extends jb{get type(){return"trr"}get isBinary(){return!0}_parse(){e.Debug&&il.time("TrrParser._parse "+this.name);const t=Va(this.streamer.data),i=new DataView(t),n=this.frames,r=n.coordinates,s=n.boxes,o=n.times;let a=0;for(;;){a+=8;const e=i.getInt32(a);a+=4,a+=e;const n=i.getInt32(a+8),c=i.getInt32(a+12),l=i.getInt32(a+16),h=i.getInt32(a+28),u=i.getInt32(a+32),d=i.getInt32(a+36),f=i.getInt32(a+40);a+=52;const m=n/9,p=3*f;if(8===m?o.push(i.getFloat64(a)):o.push(i.getFloat32(a)),a+=2*m,n){const e=new Float32Array(9);if(8===m)for(let t=0;t<9;++t)e[t]=10*i.getFloat64(a),a+=8;else for(let t=0;t<9;++t)e[t]=10*i.getFloat32(a),a+=4;s.push(e)}if(a+=c,a+=l,h){let e;if(8===m){e=new Float32Array(p);for(let t=0;t>8&65280|t>>24&255}e=new Float32Array(t,a,p);for(let t=0;t=t.byteLength)break}o.length>=1&&(n.timeOffset=o[0]),o.length>=2&&(n.deltaTime=o[1]-o[0]),e.Debug&&il.timeEnd("TrrParser._parse "+this.name)}});const l_=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 h_(e){let t=1,i=0;for(;e>=t&&i<32;)i++,t<<=1;return i}const u_=new Uint8Array(32);function d_(e,t){let i=1,n=0;u_[0]=1;for(let n=0;n>=8;for(;0!==r;)u_[e++]=255&r,r>>=8;i=e}let r=1;for(i--;u_[i]>=r;)n++,r*=2;return n+8*i}function f_(e,t,i,n){const r=(1<=8;)o=o<<8|t[a++],c|=o>>s<0&&(s>s&(1<8;)m_[a++]=f_(e,t,8,o),n-=8;n>0&&(m_[a++]=f_(e,t,n,o));for(let e=i-1;e>0;e--){let t=0;for(let i=a-1;i>=0;i--){t=t<<8|m_[i];const n=t/r[e]|0;m_[i]=n,t-=n*r[e]}s[e]=t}s[0]=m_[0]|m_[1]<<8|m_[2]<<16|m_[3]<<24}hl.add("xtc",class extends jb{get type(){return"xtc"}get isBinary(){return!0}_parse(){e.Debug&&il.time("XtcParser._parse "+this.name);const t=Va(this.streamer.data),i=new DataView(t),n=this.frames,r=n.coordinates,s=n.boxes,o=n.times,a=new Int32Array(6),c=new Int32Array(3),l=new Int32Array(3),h=new Uint32Array(3),u=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;o.push(i.getFloat32(f)),f+=4;const v=new Float32Array(9);for(let e=0;e<9;++e)v[e]=10*i.getFloat32(f),f+=4;if(s.push(v),n<=9){e=new Float32Array(n);for(let t=0;t16777215?(l[0]=h_(c[0]),l[1]=h_(c[1]),l[2]=h_(c[2]),o=0):o=d_(3,c);let v=i.getInt32(f);f+=4;let y=v-1;y=9>y?9:y;let x=l_[y]/2|0,b=l_[v]/2|0;h[0]=h[1]=h[2]=l_[v];let _=4*Math.ceil(i.getInt32(f)/4);f+=4;const w=1/s;let S=0,A=0;const M=new Uint8Array(t,f);for(u[0]=u[1]=u[2]=0;A0){u[0]=u[1]=u[2]=0;for(let t=0;t9?l_[v-1]/2|0:0):t>0&&(x=b,b=l_[v]/2|0),h[0]=h[1]=h[2]=l_[v],0===h[0]||0===h[1]||0===h[2])return void console.error("(xdrfile error) Undefined error.")}f+=_}for(let t=0;t=t.byteLength)break}o.length>=1&&(n.timeOffset=o[0]),o.length>=2&&(n.deltaTime=o[1]-o[0]),e.Debug&&il.timeEnd("XtcParser._parse "+this.name)}});class g_ extends Zx{constructor(e,t){const i=t||{};super(e,i),this.volume=new Zf(this.name,this.path),this.voxelSize=Ia(i.voxelSize,1)}get type(){return"volume"}get __objName(){return"volume"}_afterParse(){this.volume.setMatrix(this.getMatrix()),super._afterParse()}getMatrix(){return new ri}}const v_=/\s+/,y_=/-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?/g,x_=.529177210859;class b_ extends g_{get type(){return"cube"}_parse(){e.Debug&&il.time("CubeParser._parse "+this.name);const t=this.volume,i=this.streamer.peekLines(6),n={},r=x_*this.voxelSize;function s(e,t){var n=i[e].trim().split(v_)[t];return parseFloat(n)}n.atomCount=Math.abs(s(2,0)),n.originX=s(2,1)*x_,n.originY=s(2,2)*x_,n.originZ=s(2,3)*x_,n.NVX=s(3,0),n.NVY=s(4,0),n.NVZ=s(5,0),n.basisX=new Zt(s(3,1),s(3,2),s(3,3)).multiplyScalar(r),n.basisY=new Zt(s(4,1),s(4,2),s(4,3)).multiplyScalar(r),n.basisZ=new Zt(s(5,1),s(5,2),s(5,3)).multiplyScalar(r);const o=new Float32Array(n.NVX*n.NVY*n.NVZ);let a=0,c=0;const l=s(2,0)>0?0:1;this.streamer.eachChunkOfLines((function(e){!function(e,t,i){for(let r=e;r=n.atomCount+6+l){const t=e.match(y_);for(let e=0,i=t.length;e>8&255}i.xStart=o[0],i.yStart=o[1],i.zStart=o[2],i.xExtent=o[3],i.yExtent=o[4],i.zExtent=o[5],i.xRate=o[6],i.yRate=o[7],i.zRate=o[8];const e=1/o[17],t=e*this.voxelSize;i.xlen=o[9]*t,i.ylen=o[10]*t,i.zlen=o[11]*t,i.alpha=o[12]*e,i.beta=o[13]*e,i.gamma=o[14]*e,n=o[15]/100,r=o[16],i.gamma=o[14]*e}t.header=i,e.Debug&&il.log(i,n,r);const l=new Float32Array(i.xExtent*i.yExtent*i.zExtent);let h=512;const u=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(w_);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,o,a){var c,l=this.vertices.length,h=this.parseVertexIndex(e,l),u=this.parseVertexIndex(t,l),d=this.parseVertexIndex(i,l);if(void 0===n?this.addVertex(h,u,d):(c=this.parseVertexIndex(n,l),this.addVertex(h,u,c),this.addVertex(u,d,c)),void 0!==r){var f=this.normals.length;h=this.parseNormalIndex(r,f),u=r===s?h:this.parseNormalIndex(s,f),d=r===o?h:this.parseNormalIndex(o,f),void 0===n?this.addNormal(h,u,d):(c=this.parseNormalIndex(a,f),this.addNormal(h,u,c),this.addNormal(u,d,c))}},addLineGeometry:function(e){this.object.geometry.type="Line";for(var t=this.vertices.length,i=0,n=e.length;i0?x.setAttribute("normal",new An(new Float32Array(y.normals),3)):x.computeVertexNormals(),v.push(x)}}return v}};hl.add("obj",class extends U_{get type(){return"obj"}getLoader(){return new $_}});const G_=function(){this.propertyNameMapping={}};G_.prototype={constructor:G_,setPropertyNameMapping:function(e){this.propertyNameMapping=e},bin2str:function(e){for(var t=new Uint8Array(e),i="",n=0;n=n.elements[o].count&&(o++,a=0);var h=this.parseASCIIElement(n.elements[o].properties,l);this.handleElement(i,n.elements[o].name,h),a++}}return this.postProcess(i)},postProcess:function(e){if(e.useColor){for(var t=0;t{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()&&!o("?>");){const t=n();if(!t)return e;e.attributes[t.name]=t.value}return r(/\?>\s*/),e}function i(){const e=r(j_);if(!e)return;const t={name:e[1],attributes:{},children:[]};for(;!(s()||o(">")||o("?>")||o("/>"));){const e=n();if(!e)return t;t.attributes[e.name]=e.value}if(r(/^\s*\/>\s*/))return t;let a;for(r(/\??>\s*/),t.content=function(){const e=r(W_);return e?e[1]:""}();a=i();)t.children.push(a);return r(/^<\/[\w-:.]+>\s*/),t}function n(){const e=r(q_);var t;if(e)return{name:e[1],value:(t=e[2],t.replace(H_,""))}}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 o(t){return 0===e.indexOf(t)}}class Y_ extends Zx{constructor(e,t){const i=t||{};super(e,i),this.useDomParser=Ia(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 X_(e)}__domParser(e){return(new window.DOMParser).parseFromString(e,"text/xml")}_parse(){e.Debug&&il.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&&il.timeEnd("XmlParser._parse "+this.name)}}function Z_(e,t){const i=e.getNamedItem(t);return null!==i?i.value:""}function K_(e,t,i=!1){const n=Z_(e,"icode").trim(),r=Z_(e,"chain").trim(),s=Z_(e,"altcode");let o=Z_(e,"resnum");return n&&(o+="^"+n),r&&(o+=":"+r),t&&(o+="."+t),i&&s.trim()&&(o+="%"+s),o+="/"+(parseInt(Z_(e,"model"))-1),o}function Q_(e){const t=Z_(e,"chain").trim();let i=`[${Z_(e,"rescode")}]${Z_(e,"resnum")}`;return t&&(i+=`:${t}`),i}function J_(e,t,i){void 0===e[t]?e[t]=i:e[t]|=i}function ew(e,t){return null!==e&&e.value===t}function tw(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),ew(i.getNamedItem("rota"),"OUTLIER")&&(n+=1),ew(i.getNamedItem("rama"),"OUTLIER")&&(n+=1),ew(i.getNamedItem("RNApucker"),"outlier")&&(n+=1),n}hl.add("xml",Y_);class iw{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&&il.time("Validation.fromXml");const i=this.rsrzDict,n=this.rsccDict,r=this.rciDict,s=this.clashDict,o=this.clashArray,a=this.geoDict,c=this.geoAtomDict,l=this.atomDict,h=t.getElementsByTagName("Entry");if(1===h.length){const e=h[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&&(a[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={};c[n]=t;for(let i=0,n=e.length;i>>16&65535|0,o=0;0!==i;){i-=o=i>2e3?2e3:i;do{s=s+(r=r+t[n++]|0)|0}while(--o);r%=65521,s%=65521}return r|s<<16|0}hl.add("validation",class extends Y_{constructor(e,t){super(e,t||{}),this.useDomParser=!0,this.validation=new iw(this.name,this.path)}get __objName(){return"validation"}get isXml(){return!0}_parse(){super._parse(),e.Debug&&il.time("ValidationParser._parse "+this.name),this.validation.fromXml(this.xml.data),e.Debug&&il.timeEnd("ValidationParser._parse "+this.name)}});var ow=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 aw(e,t,i,n){var r=ow,s=n+i;e^=-1;for(var o=n;o>>8^r[255&(e^t[o])];return-1^e}var cw=30,lw=12;function hw(e,t){var i,n,r,s,o,a,c,l,h,u,d,f,m,p,g,v,y,x,b,_,w,S,A,M,C;i=e.state,n=e.next_in,M=e.input,r=n+(e.avail_in-5),s=e.next_out,C=e.output,o=s-(t-e.avail_out),a=s+(e.avail_out-257),c=i.dmax,l=i.wsize,h=i.whave,u=i.wnext,d=i.window,f=i.hold,m=i.bits,p=i.lencode,g=i.distcode,v=(1<>>=b=x>>>24,m-=b,0===(b=x>>>16&255))C[s++]=65535&x;else{if(!(16&b)){if(0==(64&b)){x=p[(65535&x)+(f&(1<>>=b,m-=b),m<15&&(f+=M[n++]<>>=b=x>>>24,m-=b,!(16&(b=x>>>16&255))){if(0==(64&b)){x=g[(65535&x)+(f&(1<c){e.msg="invalid distance too far back",i.mode=cw;break e}if(f>>>=b,m-=b,w>(b=s-o)){if((b=w-b)>h&&i.sane){e.msg="invalid distance too far back",i.mode=cw;break e}if(S=0,A=d,0===u){if(S+=l-b,b<_){_-=b;do{C[s++]=d[S++]}while(--b);S=s-w,A=C}}else if(u2;)C[s++]=A[S++],C[s++]=A[S++],C[s++]=A[S++],_-=3;_&&(C[s++]=A[S++],_>1&&(C[s++]=A[S++]))}else{S=s-w;do{C[s++]=C[S++],C[s++]=C[S++],C[s++]=C[S++],_-=3}while(_>2);_&&(C[s++]=C[S++],_>1&&(C[s++]=C[S++]))}break}}break}}while(n>3,f&=(1<<(m-=_<<3))-1,e.next_in=n,e.next_out=s,e.avail_in=n=1&&0===E[_];_--);if(w>_&&(w=_),0===_)return r[s++]=20971520,r[s++]=20971520,a.bits=1,0;for(b=1;b<_&&0===E[b];b++);for(w0&&(e===mw||1!==_))return-1;for(D[1]=0,y=1;ydw||e===gw&&C>fw)return 1;for(;;){m=y-A,o[x]f?(p=L[R+o[x]],g=T[I+o[x]]):(p=96,g=0),c=1<>A)+(l-=c)]=m<<24|p<<16|g|0}while(0!==l);for(c=1<>=1;if(0!==c?(P&=c-1,P+=c):P=0,x++,0==--E[y]){if(y===_)break;y=t[i+o[x]]}if(y>w&&(P&u)!==h){for(0===A&&(A=w),d+=b,M=1<<(S=y-A);S+A<_&&!((M-=E[S+A])<=0);)S++,M<<=1;if(C+=1<dw||e===gw&&C>fw)return 1;r[h=P&u]=w<<24|S<<16|d-s|0}}return 0!==P&&(r[d+P]=y-A<<24|64<<16|0),a.bits=w,0}var ww=1,Sw=2,Aw=0,Mw=-2,Cw=1,Pw=12,Tw=30,Iw=852,Ew=592;function Dw(e){return(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function Lw(){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 Rw(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=Cw,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(Iw),t.distcode=t.distdyn=new Int32Array(Ew),t.sane=1,t.back=-1,Aw):Mw}(e)):Mw}function kw(e,t){var i,n;return e?(n=new Lw,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)?Mw:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,Rw(e))):Mw}(e,t),i!==Aw&&(e.state=null),i):Mw}var Ow,Bw,Nw=!0;function Fw(e){if(Nw){var t;for(Ow=new Int32Array(512),Bw=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(_w(ww,e.lens,0,288,Ow,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;_w(Sw,e.lens,0,32,Bw,0,e.work,{bits:5}),Nw=!1}e.lencode=Ow,e.lenbits=9,e.distcode=Bw,e.distbits=5}function zw(e,t,i,n){var r,s=e.state;return null===s.window&&(s.wsize=1<=s.wsize?(rw(s.window,t,i-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):((r=s.wsize-s.wnext)>n&&(r=n),rw(s.window,t,i-n,r,s.wnext),(n-=r)?(rw(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=aw(i.check,P,2,0),l=0,h=0,i.mode=2;break}if(i.flags=0,i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){e.msg="incorrect header check",i.mode=Tw;break}if(8!=(15&l)){e.msg="unknown compression method",i.mode=Tw;break}if(h-=4,w=8+(15&(l>>>=4)),0===i.wbits)i.wbits=w;else if(w>i.wbits){e.msg="invalid window size",i.mode=Tw;break}i.dmax=1<>8&1),512&i.flags&&(P[0]=255&l,P[1]=l>>>8&255,i.check=aw(i.check,P,2,0)),l=0,h=0,i.mode=3;case 3:for(;h<32;){if(0===a)break e;a--,l+=n[s++]<>>8&255,P[2]=l>>>16&255,P[3]=l>>>24&255,i.check=aw(i.check,P,4,0)),l=0,h=0,i.mode=4;case 4:for(;h<16;){if(0===a)break e;a--,l+=n[s++]<>8),512&i.flags&&(P[0]=255&l,P[1]=l>>>8&255,i.check=aw(i.check,P,2,0)),l=0,h=0,i.mode=5;case 5:if(1024&i.flags){for(;h<16;){if(0===a)break e;a--,l+=n[s++]<>>8&255,i.check=aw(i.check,P,2,0)),l=0,h=0}else i.head&&(i.head.extra=null);i.mode=6;case 6:if(1024&i.flags&&((f=i.length)>a&&(f=a),f&&(i.head&&(w=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),rw(i.head.extra,n,s,f,w)),512&i.flags&&(i.check=aw(i.check,n,f,s)),a-=f,s+=f,i.length-=f),i.length))break e;i.length=0,i.mode=7;case 7:if(2048&i.flags){if(0===a)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=Pw;break;case 10:for(;h<32;){if(0===a)break e;a--,l+=n[s++]<>>=7&h,h-=7&h,i.mode=27;break}for(;h<3;){if(0===a)break e;a--,l+=n[s++]<>>=1)){case 0:i.mode=14;break;case 1:if(Fw(i),i.mode=20,6===t){l>>>=2,h-=2;break e}break;case 2:i.mode=17;break;case 3:e.msg="invalid block type",i.mode=Tw}l>>>=2,h-=2;break;case 14:for(l>>>=7&h,h-=7&h;h<32;){if(0===a)break e;a--,l+=n[s++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=Tw;break}if(i.length=65535&l,l=0,h=0,i.mode=15,6===t)break e;case 15:i.mode=16;case 16:if(f=i.length){if(f>a&&(f=a),f>c&&(f=c),0===f)break e;rw(r,n,s,f,o),a-=f,s+=f,c-=f,o+=f,i.length-=f;break}i.mode=Pw;break;case 17:for(;h<14;){if(0===a)break e;a--,l+=n[s++]<>>=5,h-=5,i.ndist=1+(31&l),l>>>=5,h-=5,i.ncode=4+(15&l),l>>>=4,h-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=Tw;break}i.have=0,i.mode=18;case 18:for(;i.have>>=3,h-=3}for(;i.have<19;)i.lens[T[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,A={bits:i.lenbits},S=_w(0,i.lens,0,19,i.lencode,0,i.work,A),i.lenbits=A.bits,S){e.msg="invalid code lengths set",i.mode=Tw;break}i.have=0,i.mode=19;case 19:for(;i.have>>16&255,y=65535&C,!((g=C>>>24)<=h);){if(0===a)break e;a--,l+=n[s++]<>>=g,h-=g,i.lens[i.have++]=y;else{if(16===y){for(M=g+2;h>>=g,h-=g,0===i.have){e.msg="invalid bit length repeat",i.mode=Tw;break}w=i.lens[i.have-1],f=3+(3&l),l>>>=2,h-=2}else if(17===y){for(M=g+3;h>>=g)),l>>>=3,h-=3}else{for(M=g+7;h>>=g)),l>>>=7,h-=7}if(i.have+f>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=Tw;break}for(;f--;)i.lens[i.have++]=w}}if(i.mode===Tw)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=Tw;break}if(i.lenbits=9,A={bits:i.lenbits},S=_w(ww,i.lens,0,i.nlen,i.lencode,0,i.work,A),i.lenbits=A.bits,S){e.msg="invalid literal/lengths set",i.mode=Tw;break}if(i.distbits=6,i.distcode=i.distdyn,A={bits:i.distbits},S=_w(Sw,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,A),i.distbits=A.bits,S){e.msg="invalid distances set",i.mode=Tw;break}if(i.mode=20,6===t)break e;case 20:i.mode=21;case 21:if(a>=6&&c>=258){e.next_out=o,e.avail_out=c,e.next_in=s,e.avail_in=a,i.hold=l,i.bits=h,hw(e,d),o=e.next_out,r=e.output,c=e.avail_out,s=e.next_in,n=e.input,a=e.avail_in,l=i.hold,h=i.bits,i.mode===Pw&&(i.back=-1);break}for(i.back=0;v=(C=i.lencode[l&(1<>>16&255,y=65535&C,!((g=C>>>24)<=h);){if(0===a)break e;a--,l+=n[s++]<>x)])>>>16&255,y=65535&C,!(x+(g=C>>>24)<=h);){if(0===a)break e;a--,l+=n[s++]<>>=x,h-=x,i.back+=x}if(l>>>=g,h-=g,i.back+=g,i.length=y,0===v){i.mode=26;break}if(32&v){i.back=-1,i.mode=Pw;break}if(64&v){e.msg="invalid literal/length code",i.mode=Tw;break}i.extra=15&v,i.mode=22;case 22:if(i.extra){for(M=i.extra;h>>=i.extra,h-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=23;case 23:for(;v=(C=i.distcode[l&(1<>>16&255,y=65535&C,!((g=C>>>24)<=h);){if(0===a)break e;a--,l+=n[s++]<>x)])>>>16&255,y=65535&C,!(x+(g=C>>>24)<=h);){if(0===a)break e;a--,l+=n[s++]<>>=x,h-=x,i.back+=x}if(l>>>=g,h-=g,i.back+=g,64&v){e.msg="invalid distance code",i.mode=Tw;break}i.offset=y,i.extra=15&v,i.mode=24;case 24:if(i.extra){for(M=i.extra;h>>=i.extra,h-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=Tw;break}i.mode=25;case 25:if(0===c)break e;if(f=d-c,i.offset>f){if((f=i.offset-f)>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=Tw;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=o-i.offset,f=i.length;f>c&&(f=c),c-=f,i.length-=f;do{r[o++]=p[m++]}while(--f);0===i.length&&(i.mode=21);break;case 26:if(0===c)break e;r[o++]=i.length,c--,i.mode=21;break;case 27:if(i.wrap){for(;h<32;){if(0===a)break e;a--,l|=n[s++]<=252?6:jw>=248?5:jw>=240?4:jw>=224?3:jw>=192?2:1;function Ww(e){var t,i,n,r,s,o=e.length,a=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 qw(e,t){var i,n,r,s,o=t||e.length,a=new Array(2*o);for(n=0,i=0;i4)a[n++]=65533,i+=s-1;else{for(r&=2===s?31:3===s?15:7;s>1&&i1?a[n++]=65533:r<65536?a[n++]=r:(r-=65536,a[n++]=55296|r>>10&1023,a[n++]=56320|1023&r)}return function(e,t){if(t<65537&&(e.subarray&&Vw||!e.subarray&&Gw))return String.fromCharCode.apply(null,nw(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+Hw[e[i]]>t?i:t}Hw[254]=Hw[254]=1;var Yw=0,Zw={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 Kw(){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 Qw(){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 Jw=Object.prototype.toString;function eS(e){if(!(this instanceof eS))return new eS(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&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Kw,this.strm.avail_out=0;var i,n,r,s=kw(this.strm,t.windowBits);if(s!==Yw)throw new Error(Zw[s]);this.header=new Qw,i=this.strm,n=this.header,i&&i.state&&(0==(2&(r=i.state).wrap)||(r.head=n,n.done=!1))}eS.prototype.push=function(e,t){var i,n,r,s,o,a,c=this.strm,l=this.options.chunkSize,h=this.options.dictionary,u=!1;if(this.ended)return!1;n=t===~~t?t:!0===t?4:0,"string"==typeof e?c.input=function(e){for(var t=new Uint8Array(e.length),i=0,n=t.length;i0||0===c.avail_out)&&1!==i);return 1===i&&(n=4),4===n?(i=function(e){if(!e||!e.state)return Mw;var t=e.state;return t.window&&(t.window=null),e.state=null,Aw}(this.strm),this.onEnd(i),this.ended=!0,i===Yw):2!==n||(this.onEnd(Yw),c.avail_out=0,!0)},eS.prototype.onData=function(e){this.chunks.push(e)},eS.prototype.onEnd=function(e){e===Yw&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=function(e){var t,i,n,r,s,o;for(n=0,t=0,i=e.length;tObject.assign(Object.assign({},e),{[t]:t})),{})}}const pS={backgroundColor:{type:"color"},quality:mS("auto","low","medium","high"),sampleLevel:fS(1,5,-1),impostor:{type:"boolean"},workerDefault:{type:"boolean"},rotateSpeed:dS(1,10,0),zoomSpeed:dS(1,10,0),panSpeed:dS(1,10,0),clipNear:fS(1,100,0),clipFar:fS(1,100,0),clipDist:uS(200,0),clipMode:mS("scene","camera"),clipScale:mS("relative","absolute"),fogNear:fS(1,100,0),fogFar:fS(1,100,0),cameraType:mS("perspective","orthographic","stereo"),cameraEyeSep:dS(3,1,.01),cameraFov:fS(1,120,15),lightColor:{type:"color"},lightIntensity:dS(2,10,0),ambientColor:{type:"color"},ambientIntensity:dS(2,10,0),hoverTimeout:uS(1e4,-1),tooltip:{type:"boolean"},mousePreset:mS(...Object.keys(um))};e.AngleRepresentation=Qv,e.ArrowBuffer=wx,e.Assembly=Qm,e.AxesRepresentation=fy,e.BackboneRepresentation=py,e.BallAndStickRepresentation=my,e.BaseRepresentation=gy,e.Box3=Ni,e.BoxBuffer=Px,e.BufferRepresentation=Vp,e.CartoonRepresentation=Sy,e.Collection=Sg,e.Color=mn,e.Colormaker=dc,e.ColormakerRegistry=al,e.Component=wg,e.ComponentCollection=Wg,e.ConeBuffer=xx,e.ContactRepresentation=Ay,e.Counter=El,e.CylinderBuffer=dy,e.DatasourceRegistry=cl,e.DecompressorRegistry=dl,e.DihedralHistogramRepresentation=Ty,e.DihedralRepresentation=My,e.DistanceRepresentation=Ey,e.EllipsoidBuffer=Rx,e.Euler=ai,e.Frames=Pg,e.HelixorientRepresentation=ky,e.HyperballRepresentation=Vy,e.Kdtree=qm,e.KeyActions=mm,e.LabelRepresentation=jy,e.LeftMouseButton=1,e.LicoriceRepresentation=Oy,e.LineRepresentation=qy,e.Matrix3=Ut,e.Matrix4=ri,e.MdsrvDatasource=class extends tS{constructor(e=""){super(),this.baseUrl=e}getListing(e=""){let t=`${this.baseUrl}dir/${e}`;return"/"!==t[t.length-1]&&(t+="/"),Ml(t,{ext:"json"}).then((t=>({path:e,data:t.data})))}getUrl(e){const t=Sl(e);return`${this.baseUrl}file/${t.path}${t.query}`}getCountUrl(e){const t=Sl(e);return`${this.baseUrl}traj/numframes/${t.path}${t.query}`}getFrameUrl(e,t){const i=Sl(e);return`${this.baseUrl}traj/frame/${t}/${i.path}${i.query}`}getFrameParams(e,t){return`atomIndices=${t.join(";")}`}getPathUrl(e,t){const i=Sl(e);return`${this.baseUrl}traj/path/${t}/${i.path}${i.query}`}getExt(e){return Sl(e).ext}},e.MeasurementDefaultParams=nl,e.MeshBuffer=nm,e.MiddleMouseButton=2,e.MolecularSurface=Qy,e.MolecularSurfaceRepresentation=Jy,e.MouseActions=hm,e.OctahedronBuffer=Fx,e.ParserRegistry=hl,e.PdbWriter=class extends Pl{constructor(e,t){super(),this.mimeType="text/plain",this.defaultName="structure",this.defaultExt="pdb";const i=Object.assign({},t);this.renumberSerial=Ia(i.renumberSerial,!0),this.remarks=function(e){return Array.isArray(e)?e:[e]}(Ia(i.remarks,[])),this.structure=e,this._records=[]}_writeRecords(){this._records.length=0,this._writeTitle(),this._writeRemarks(),this._writeAtoms()}_writeTitle(){this._records.push(Cl.sprintf("TITLE %-74s",this.structure.name))}_writeRemarks(){this.remarks.forEach((e=>{this._records.push(Cl.sprintf("REMARK %-73s",e))})),this.structure.trajectory&&(this._records.push(Cl.sprintf("REMARK %-73s","Trajectory '"+this.structure.trajectory.name+"'")),this._records.push(Cl.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(Cl.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 o=t.atomname;(1===o.length||o.length<4&&1===t.element.length&&o[0]===t.element)&&(o=" "+o),t.formalCharge?(i=Math.abs(t.formalCharge).toPrecision(1),n=t.formalCharge>0?"+":"-"):(i=" ",n=" "),this._records.push(Cl.sprintf(r,s,o,t.resname,Ia(t.chainname," "),t.resno,t.x,t.y,t.z,Ia(t.occupancy,1),Ia(t.bfactor,0),"",Ia(t.element,""),i,n)),e+=1}),this.structure.getSelection()),r&&this._records.push(Cl.sprintf("%-80s","ENDMDL"))})),this._records.push(Cl.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=Rh,e.Plane=Qi,e.PointBuffer=sg,e.PointRepresentation=ex,e.Quaternion=qt,e.Queue=eu,e.RepresentationCollection=Ag,e.RepresentationElement=yg,e.RepresentationRegistry=ll,e.RibbonRepresentation=rx,e.RightMouseButton=3,e.RocketRepresentation=sx,e.RopeRepresentation=ox,e.ScriptExtensions=sl,e.SdfWriter=class extends Pl{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 Cl.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=$c,e.Shape=Gp,e.ShapeComponent=Zg,e.Signal=mc.Signal,e.SpacefillRepresentation=ax,e.SpatialHash=ju,e.SphereBuffer=tg,e.Stage=class{constructor(e,t={}){this.signals={parametersChanged:new mc.Signal,fullscreenChanged:new mc.Signal,componentAdded:new mc.Signal,componentRemoved:new mc.Signal,clicked:new mc.Signal,hovered:new mc.Signal},this.tasks=new El,this.compList=[],this.defaultFileParams={},this.logList=[],this.viewer=new vh(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 xh(this.viewer.renderer.domElement),this.viewerControls=new Vh(this),this.trackballControls=new Dh(this),this.pickingControls=new kh(this),this.animationControls=new Jh(this),this.mouseControls=new fm(this),this.keyControls=new gm(this),this.pickingBehavior=new vm(this),this.mouseBehavior=new ym(this),this.animationBehavior=new xm(this),this.keyBehavior=new _m(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=Ea(t,Yg),this.setParameters(this.parameters),this.viewer.animate())}setParameters(e={}){Da(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 Vg){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 o=i;Kc&&(o*=4);const a=s.atomStore.count/s.residueStore.count<2;a&&(o*=10);let c="chainname",l="RdYlBu",h=!1;if(1===s.getChainnameCount(new $c("polymer and /0"))&&(c="residueindex",l="Spectral",h=!0),e.Debug&&console.log(o,i,r,a),n/r<4)t.addRepresentation("ball+stick",{colorScheme:"element",radiusScale:2,aspectRatio:1.5,bondScale:.3,bondSpacing:.75,quality:"auto"});else if(r>5&&o>15e3||o>7e5){let e=Math.min(2,Math.max(.1,6e3/(o/r)));a&&(e=Math.min(e,.5)),t.addRepresentation("surface",{colorScheme:c,colorScale:l,colorReverse:h,sele:"polymer",surfaceType:"av",probeRadius:1.4,scaleFactor:e,useWorker:!1})}else o>25e4?t.addRepresentation("backbone",{colorScheme:c,colorScale:l,colorReverse:h,lineOnly:!0}):o>1e5?t.addRepresentation("backbone",{colorScheme:c,colorScale:l,colorReverse:h,quality:"low",disableImpostor:!0,radiusScale:2}):o>8e4?t.addRepresentation("backbone",{colorScheme:c,colorScale:l,colorReverse:h,radiusScale:2}):(t.addRepresentation("cartoon",{colorScheme:c,colorScale:l,colorReverse:h,radiusScale:.7,aspectRatio:5,quality:"auto"}),o<5e4&&t.addRepresentation("base",{colorScheme:c,colorScale:l,colorReverse:h,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 Hg||t instanceof jg)&&t.addRepresentation("surface");this.tasks.onZeroOnce(this.autoView,this)}loadFile(e,t={}){const i=Object.assign({},this.defaultFileParams,t),n=Sl(e).name;this.tasks.increment(),this.log(`loading file '${n}'`);const r=Ia(i.ext,Sl(e).ext);let s;return s=hl.isTrajectory(r)?Promise.reject(new Error(`loadFile: ext '${r}' is a trajectory and must be loaded into a structure component`)):Ml(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=Sl(e).name;return this.log(`loading script '${t}'`),Ml(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)):il.warn("Stage.addComponent: no component given")}addComponentFromObject(e,t={}){const i=fl.get(e.type);if(i){const n=new i(this,e,t);return this.addComponent(n),n}il.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 il.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=tc(e/2,0,49.9),i=100-t,n=50,r=function(e){return tc(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(Xg),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=Ka(this.viewer.perspectiveCamera.fov),o=this.viewer.width,a=this.viewer.height,c=a{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||qg(e,i))&&t.push(i)})),new Wg(t)}getComponentsByObject(e){const t=[];return this.eachComponent((i=>{i.object===e&&t.push(i)})),new Wg(t)}getRepresentationsByName(e){const t=[];return this.eachRepresentation(((i,n)=>{(void 0===e||qg(e,i))&&t.push(i)})),new Ag(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 tS{constructor(e=""){super(),this.baseUrl=e}getUrl(e){const t=Sl(e);let i=this.baseUrl+t.path;return hS.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 Sl(e).ext}},e.StlWriter=class extends Pl{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 Il(2*e+3*e*4*4+80+4);t.skip(80),t.writeUint32(e);const i=new Zt,n=new Zt,r=new Zt,s=new Zt;for(let o=0;o{e.eachAtom((e=>{s.growIfFull(),s.atomTypeId[c]=o.add(e.atomname,e.element),s.x[c]=e.x,s.y[c]=e.y,s.z[c]=e.z,s.serial[c]=e.serial,s.formalCharge[c]=e.formalCharge,s.partialCharge[c]=e.partialCharge,s.altloc[c]=e.altloc,s.occupancy[c]=e.occupancy,s.bfactor[c]=e.bfactor,r.addAtom(e.modelIndex+h,e.chainname,e.chainid,e.resname,e.resno,1===e.hetero,e.sstruc,e.inscode),a[e.index+l]=c,c+=1})),l+=e.atomStore.count,h+=e.modelStore.count}));const u=n.bondStore,d=n.getAtomProxy(),f=n.getAtomProxy();return l=0,i.forEach((e=>{e.eachBond((e=>{d.index=a[e.atomIndex1+l],f.index=a[e.atomIndex2+l],u.addBond(d,f,e.bondOrder)})),l+=e.atomStore.count})),r.finalize(),hp(n,!0),lp(n,!0),n.finalizeAtoms(),n.finalizeBonds(),pp(n),e.Debug&&il.timeEnd("concatStructures"),n},e.download=Oa,e.flatten=function e(t,i){i=Ia(i,[]);for(let n=0;nt?(o&&(clearTimeout(o),o=null),a=l,s=e.apply(n,r),o||(n=r=null)):o||!1===i.trailing||(o=setTimeout(c,h)),s}},e.uniqueArray=za,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ngl.js.map