4208 lines
894 KiB
JavaScript
4208 lines
894 KiB
JavaScript
var qp=Object.defineProperty;var $p=(n,e,t)=>e in n?qp(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Vt=(n,e,t)=>$p(n,typeof e!="symbol"?e+"":e,t);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))i(s);new MutationObserver(s=>{for(const r of s)if(r.type==="childList")for(const a of r.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&i(a)}).observe(document,{childList:!0,subtree:!0});function t(s){const r={};return s.integrity&&(r.integrity=s.integrity),s.referrerPolicy&&(r.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?r.credentials="include":s.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(s){if(s.ep)return;s.ep=!0;const r=t(s);fetch(s.href,r)}})();/**
|
|
* @license
|
|
* Copyright 2010-2026 Three.js Authors
|
|
* SPDX-License-Identifier: MIT
|
|
*/const Cc="185",ui={ROTATE:0,DOLLY:1,PAN:2},Li={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},Zp=0,fu=1,Kp=2,Ia=1,Jp=2,mr=3,Ni=0,un=1,zt=2,hi=0,ks=1,du=2,pu=3,mu=4,jp=5,$i=100,Qp=101,em=102,tm=103,nm=104,im=200,sm=201,rm=202,am=203,Sl=204,Ml=205,om=206,lm=207,cm=208,um=209,hm=210,fm=211,dm=212,pm=213,mm=214,El=0,Tl=1,Al=2,Gs=3,wl=4,Cl=5,Rl=6,Pl=7,Df=0,gm=1,xm=2,Kn=0,If=1,Uf=2,Of=3,Ff=4,Nf=5,kf=6,Bf=7,Hf=300,es=301,Vs=302,Mo=303,Eo=304,mo=306,Ll=1e3,li=1001,Dl=1002,Ft=1003,vm=1004,Wr=1005,Xt=1006,To=1007,Di=1008,Sn=1009,zf=1010,Gf=1011,Tr=1012,Rc=1013,Qn=1014,Ln=1015,mi=1016,Pc=1017,Lc=1018,Ar=1020,Vf=35902,Wf=35899,Xf=1021,Yf=1022,En=1023,gi=1026,ji=1027,qf=1028,Dc=1029,ts=1030,Ic=1031,Uc=1033,Ua=33776,Oa=33777,Fa=33778,Na=33779,Il=35840,Ul=35841,Ol=35842,Fl=35843,Nl=36196,kl=37492,Bl=37496,Hl=37488,zl=37489,Wa=37490,Gl=37491,Vl=37808,Wl=37809,Xl=37810,Yl=37811,ql=37812,$l=37813,Zl=37814,Kl=37815,Jl=37816,jl=37817,Ql=37818,ec=37819,tc=37820,nc=37821,ic=36492,sc=36494,rc=36495,ac=36283,oc=36284,Xa=36285,lc=36286,ym=3200,gu=0,_m=1,oi="",mn="srgb",Ya="srgb-linear",qa="linear",ft="srgb",ms=7680,xu=519,bm=512,Sm=513,Mm=514,Oc=515,Em=516,Tm=517,Fc=518,Am=519,cc=35044,uc="300 es",$n=2e3,$a=2001;function wm(n){for(let e=n.length-1;e>=0;--e)if(n[e]>=65535)return!0;return!1}function Za(n){return document.createElementNS("http://www.w3.org/1999/xhtml",n)}function Cm(){const n=Za("canvas");return n.style.display="block",n}const vu={};function Ka(...n){const e="THREE."+n.shift();console.log(e,...n)}function $f(n){const e=n[0];if(typeof e=="string"&&e.startsWith("TSL:")){const t=n[1];t&&t.isStackTrace?n[0]+=" "+t.getLocation():n[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return n}function We(...n){n=$f(n);const e="THREE."+n.shift();{const t=n[0];t&&t.isStackTrace?console.warn(t.getError(e)):console.warn(e,...n)}}function st(...n){n=$f(n);const e="THREE."+n.shift();{const t=n[0];t&&t.isStackTrace?console.error(t.getError(e)):console.error(e,...n)}}function Bs(...n){const e=n.join(" ");e in vu||(vu[e]=!0,We(...n))}function Rm(n,e,t){return new Promise(function(i,s){function r(){switch(n.clientWaitSync(e,n.SYNC_FLUSH_COMMANDS_BIT,0)){case n.WAIT_FAILED:s();break;case n.TIMEOUT_EXPIRED:setTimeout(r,t);break;default:i()}}setTimeout(r,t)})}const Pm={[El]:Tl,[Al]:Rl,[wl]:Pl,[Gs]:Cl,[Tl]:El,[Rl]:Al,[Pl]:wl,[Cl]:Gs};class zi{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[e]===void 0&&(i[e]=[]),i[e].indexOf(t)===-1&&i[e].push(t)}hasEventListener(e,t){const i=this._listeners;return i===void 0?!1:i[e]!==void 0&&i[e].indexOf(t)!==-1}removeEventListener(e,t){const i=this._listeners;if(i===void 0)return;const s=i[e];if(s!==void 0){const r=s.indexOf(t);r!==-1&&s.splice(r,1)}}dispatchEvent(e){const t=this._listeners;if(t===void 0)return;const i=t[e.type];if(i!==void 0){e.target=this;const s=i.slice(0);for(let r=0,a=s.length;r<a;r++)s[r].call(this,e);e.target=null}}}const Zt=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"],ka=Math.PI/180,hc=180/Math.PI;function fi(){const n=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Zt[n&255]+Zt[n>>8&255]+Zt[n>>16&255]+Zt[n>>24&255]+"-"+Zt[e&255]+Zt[e>>8&255]+"-"+Zt[e>>16&15|64]+Zt[e>>24&255]+"-"+Zt[t&63|128]+Zt[t>>8&255]+"-"+Zt[t>>16&255]+Zt[t>>24&255]+Zt[i&255]+Zt[i>>8&255]+Zt[i>>16&255]+Zt[i>>24&255]).toLowerCase()}function Qe(n,e,t){return Math.max(e,Math.min(t,n))}function Lm(n,e){return(n%e+e)%e}function Ao(n,e,t){return(1-t)*n+t*e}function qn(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return n/4294967295;case Uint16Array:return n/65535;case Uint8Array:return n/255;case Int32Array:return Math.max(n/2147483647,-1);case Int16Array:return Math.max(n/32767,-1);case Int8Array:return Math.max(n/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function gt(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return Math.round(n*4294967295);case Uint16Array:return Math.round(n*65535);case Uint8Array:return Math.round(n*255);case Int32Array:return Math.round(n*2147483647);case Int16Array:return Math.round(n*32767);case Int8Array:return Math.round(n*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const Dm={DEG2RAD:ka},au=class au{constructor(e=0,t=0){this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("THREE.Vector2: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("THREE.Vector2: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,i=this.y,s=e.elements;return this.x=s[0]*t+s[3]*i+s[6],this.y=s[1]*t+s[4]*i+s[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Qe(this.x,e.x,t.x),this.y=Qe(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=Qe(this.x,e,t),this.y=Qe(this.y,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Qe(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(Qe(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const i=Math.cos(t),s=Math.sin(t),r=this.x-e.x,a=this.y-e.y;return this.x=r*i-a*s+e.x,this.y=r*s+a*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};au.prototype.isVector2=!0;let Ee=au;class ki{constructor(e=0,t=0,i=0,s=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=i,this._w=s}static slerpFlat(e,t,i,s,r,a,o){let l=i[s+0],c=i[s+1],u=i[s+2],f=i[s+3],h=r[a+0],d=r[a+1],p=r[a+2],x=r[a+3];if(f!==x||l!==h||c!==d||u!==p){let m=l*h+c*d+u*p+f*x;m<0&&(h=-h,d=-d,p=-p,x=-x,m=-m);let g=1-o;if(m<.9995){const M=Math.acos(m),E=Math.sin(M);g=Math.sin(g*M)/E,o=Math.sin(o*M)/E,l=l*g+h*o,c=c*g+d*o,u=u*g+p*o,f=f*g+x*o}else{l=l*g+h*o,c=c*g+d*o,u=u*g+p*o,f=f*g+x*o;const M=1/Math.sqrt(l*l+c*c+u*u+f*f);l*=M,c*=M,u*=M,f*=M}}e[t]=l,e[t+1]=c,e[t+2]=u,e[t+3]=f}static multiplyQuaternionsFlat(e,t,i,s,r,a){const o=i[s],l=i[s+1],c=i[s+2],u=i[s+3],f=r[a],h=r[a+1],d=r[a+2],p=r[a+3];return e[t]=o*p+u*f+l*d-c*h,e[t+1]=l*p+u*h+c*f-o*d,e[t+2]=c*p+u*d+o*h-l*f,e[t+3]=u*p-o*f-l*h-c*d,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,i,s){return this._x=e,this._y=t,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const i=e._x,s=e._y,r=e._z,a=e._order,o=Math.cos,l=Math.sin,c=o(i/2),u=o(s/2),f=o(r/2),h=l(i/2),d=l(s/2),p=l(r/2);switch(a){case"XYZ":this._x=h*u*f+c*d*p,this._y=c*d*f-h*u*p,this._z=c*u*p+h*d*f,this._w=c*u*f-h*d*p;break;case"YXZ":this._x=h*u*f+c*d*p,this._y=c*d*f-h*u*p,this._z=c*u*p-h*d*f,this._w=c*u*f+h*d*p;break;case"ZXY":this._x=h*u*f-c*d*p,this._y=c*d*f+h*u*p,this._z=c*u*p+h*d*f,this._w=c*u*f-h*d*p;break;case"ZYX":this._x=h*u*f-c*d*p,this._y=c*d*f+h*u*p,this._z=c*u*p-h*d*f,this._w=c*u*f+h*d*p;break;case"YZX":this._x=h*u*f+c*d*p,this._y=c*d*f+h*u*p,this._z=c*u*p-h*d*f,this._w=c*u*f-h*d*p;break;case"XZY":this._x=h*u*f-c*d*p,this._y=c*d*f-h*u*p,this._z=c*u*p+h*d*f,this._w=c*u*f+h*d*p;break;default:We("Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const i=t/2,s=Math.sin(i);return this._x=e.x*s,this._y=e.y*s,this._z=e.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,i=t[0],s=t[4],r=t[8],a=t[1],o=t[5],l=t[9],c=t[2],u=t[6],f=t[10],h=i+o+f;if(h>0){const d=.5/Math.sqrt(h+1);this._w=.25/d,this._x=(u-l)*d,this._y=(r-c)*d,this._z=(a-s)*d}else if(i>o&&i>f){const d=2*Math.sqrt(1+i-o-f);this._w=(u-l)/d,this._x=.25*d,this._y=(s+a)/d,this._z=(r+c)/d}else if(o>f){const d=2*Math.sqrt(1+o-i-f);this._w=(r-c)/d,this._x=(s+a)/d,this._y=.25*d,this._z=(l+u)/d}else{const d=2*Math.sqrt(1+f-i-o);this._w=(a-s)/d,this._x=(r+c)/d,this._y=(l+u)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let i=e.dot(t)+1;return i<1e-8?(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(e){return 2*Math.acos(Math.abs(Qe(this.dot(e),-1,1)))}rotateTowards(e,t){const i=this.angleTo(e);if(i===0)return this;const s=Math.min(1,t/i);return this.slerp(e,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const i=e._x,s=e._y,r=e._z,a=e._w,o=t._x,l=t._y,c=t._z,u=t._w;return this._x=i*u+a*o+s*c-r*l,this._y=s*u+a*l+r*o-i*c,this._z=r*u+a*c+i*l-s*o,this._w=a*u-i*o-s*l-r*c,this._onChangeCallback(),this}slerp(e,t){let i=e._x,s=e._y,r=e._z,a=e._w,o=this.dot(e);o<0&&(i=-i,s=-s,r=-r,a=-a,o=-o);let l=1-t;if(o<.9995){const c=Math.acos(o),u=Math.sin(c);l=Math.sin(l*c)/u,t=Math.sin(t*c)/u,this._x=this._x*l+i*t,this._y=this._y*l+s*t,this._z=this._z*l+r*t,this._w=this._w*l+a*t,this._onChangeCallback()}else this._x=this._x*l+i*t,this._y=this._y*l+s*t,this._z=this._z*l+r*t,this._w=this._w*l+a*t,this.normalize();return this}slerpQuaternions(e,t,i){return this.copy(e).slerp(t,i)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),r=Math.sqrt(i);return this.set(s*Math.sin(e),s*Math.cos(e),r*Math.sin(t),r*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}const ou=class ou{constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}set(e,t,i){return i===void 0&&(i=this.z),this.x=e,this.y=t,this.z=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("THREE.Vector3: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("THREE.Vector3: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(yu.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(yu.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,i=this.y,s=this.z,r=e.elements;return this.x=r[0]*t+r[3]*i+r[6]*s,this.y=r[1]*t+r[4]*i+r[7]*s,this.z=r[2]*t+r[5]*i+r[8]*s,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,i=this.y,s=this.z,r=e.elements,a=1/(r[3]*t+r[7]*i+r[11]*s+r[15]);return this.x=(r[0]*t+r[4]*i+r[8]*s+r[12])*a,this.y=(r[1]*t+r[5]*i+r[9]*s+r[13])*a,this.z=(r[2]*t+r[6]*i+r[10]*s+r[14])*a,this}applyQuaternion(e){const t=this.x,i=this.y,s=this.z,r=e.x,a=e.y,o=e.z,l=e.w,c=2*(a*s-o*i),u=2*(o*t-r*s),f=2*(r*i-a*t);return this.x=t+l*c+a*f-o*u,this.y=i+l*u+o*c-r*f,this.z=s+l*f+r*u-a*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,i=this.y,s=this.z,r=e.elements;return this.x=r[0]*t+r[4]*i+r[8]*s,this.y=r[1]*t+r[5]*i+r[9]*s,this.z=r[2]*t+r[6]*i+r[10]*s,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Qe(this.x,e.x,t.x),this.y=Qe(this.y,e.y,t.y),this.z=Qe(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=Qe(this.x,e,t),this.y=Qe(this.y,e,t),this.z=Qe(this.z,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Qe(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const i=e.x,s=e.y,r=e.z,a=t.x,o=t.y,l=t.z;return this.x=s*l-r*o,this.y=r*a-i*l,this.z=i*o-s*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}projectOnPlane(e){return wo.copy(this).projectOnVector(e),this.sub(wo)}reflect(e){return this.sub(wo.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(Qe(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return t*t+i*i+s*s}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,i){const s=Math.sin(t)*e;return this.x=s*Math.sin(i),this.y=Math.cos(t)*e,this.z=s*Math.cos(i),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),s=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=s,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,i=Math.sqrt(1-t*t);return this.x=i*Math.cos(e),this.y=t,this.z=i*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};ou.prototype.isVector3=!0;let B=ou;const wo=new B,yu=new ki,lu=class lu{constructor(e,t,i,s,r,a,o,l,c){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,i,s,r,a,o,l,c)}set(e,t,i,s,r,a,o,l,c){const u=this.elements;return u[0]=e,u[1]=s,u[2]=o,u[3]=t,u[4]=r,u[5]=l,u[6]=i,u[7]=a,u[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,s=t.elements,r=this.elements,a=i[0],o=i[3],l=i[6],c=i[1],u=i[4],f=i[7],h=i[2],d=i[5],p=i[8],x=s[0],m=s[3],g=s[6],M=s[1],E=s[4],_=s[7],T=s[2],b=s[5],S=s[8];return r[0]=a*x+o*M+l*T,r[3]=a*m+o*E+l*b,r[6]=a*g+o*_+l*S,r[1]=c*x+u*M+f*T,r[4]=c*m+u*E+f*b,r[7]=c*g+u*_+f*S,r[2]=h*x+d*M+p*T,r[5]=h*m+d*E+p*b,r[8]=h*g+d*_+p*S,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[1],s=e[2],r=e[3],a=e[4],o=e[5],l=e[6],c=e[7],u=e[8];return t*a*u-t*o*c-i*r*u+i*o*l+s*r*c-s*a*l}invert(){const e=this.elements,t=e[0],i=e[1],s=e[2],r=e[3],a=e[4],o=e[5],l=e[6],c=e[7],u=e[8],f=u*a-o*c,h=o*l-u*r,d=c*r-a*l,p=t*f+i*h+s*d;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const x=1/p;return e[0]=f*x,e[1]=(s*c-u*i)*x,e[2]=(o*i-s*a)*x,e[3]=h*x,e[4]=(u*t-s*l)*x,e[5]=(s*r-o*t)*x,e[6]=d*x,e[7]=(i*l-c*t)*x,e[8]=(a*t-i*r)*x,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,s,r,a,o){const l=Math.cos(r),c=Math.sin(r);return this.set(i*l,i*c,-i*(l*a+c*o)+a+e,-s*c,s*l,-s*(-c*a+l*o)+o+t,0,0,1),this}scale(e,t){return Bs("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(Co.makeScale(e,t)),this}rotate(e){return Bs("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(Co.makeRotation(-e)),this}translate(e,t){return Bs("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(Co.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,i,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,i=e.elements;for(let s=0;s<9;s++)if(t[s]!==i[s])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return new this.constructor().fromArray(this.elements)}};lu.prototype.isMatrix3=!0;let $e=lu;const Co=new $e,_u=new $e().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),bu=new $e().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function Im(){const n={enabled:!0,workingColorSpace:Ya,spaces:{},convert:function(s,r,a){return this.enabled===!1||r===a||!r||!a||(this.spaces[r].transfer===ft&&(s.r=di(s.r),s.g=di(s.g),s.b=di(s.b)),this.spaces[r].primaries!==this.spaces[a].primaries&&(s.applyMatrix3(this.spaces[r].toXYZ),s.applyMatrix3(this.spaces[a].fromXYZ)),this.spaces[a].transfer===ft&&(s.r=Hs(s.r),s.g=Hs(s.g),s.b=Hs(s.b))),s},workingToColorSpace:function(s,r){return this.convert(s,this.workingColorSpace,r)},colorSpaceToWorking:function(s,r){return this.convert(s,r,this.workingColorSpace)},getPrimaries:function(s){return this.spaces[s].primaries},getTransfer:function(s){return s===oi?qa:this.spaces[s].transfer},getToneMappingMode:function(s){return this.spaces[s].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(s,r=this.workingColorSpace){return s.fromArray(this.spaces[r].luminanceCoefficients)},define:function(s){Object.assign(this.spaces,s)},_getMatrix:function(s,r,a){return s.copy(this.spaces[r].toXYZ).multiply(this.spaces[a].fromXYZ)},_getDrawingBufferColorSpace:function(s){return this.spaces[s].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(s=this.workingColorSpace){return this.spaces[s].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(s,r){return Bs("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),n.workingToColorSpace(s,r)},toWorkingColorSpace:function(s,r){return Bs("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),n.colorSpaceToWorking(s,r)}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],i=[.3127,.329];return n.define({[Ya]:{primaries:e,whitePoint:i,transfer:qa,toXYZ:_u,fromXYZ:bu,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:mn},outputColorSpaceConfig:{drawingBufferColorSpace:mn}},[mn]:{primaries:e,whitePoint:i,transfer:ft,toXYZ:_u,fromXYZ:bu,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:mn}}}),n}const nt=Im();function di(n){return n<.04045?n*.0773993808:Math.pow(n*.9478672986+.0521327014,2.4)}function Hs(n){return n<.0031308?n*12.92:1.055*Math.pow(n,.41666)-.055}let gs;class Um{static getDataURL(e,t="image/png"){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let i;if(e instanceof HTMLCanvasElement)i=e;else{gs===void 0&&(gs=Za("canvas")),gs.width=e.width,gs.height=e.height;const s=gs.getContext("2d");e instanceof ImageData?s.putImageData(e,0,0):s.drawImage(e,0,0,e.width,e.height),i=gs}return i.toDataURL(t)}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=Za("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");i.drawImage(e,0,0,e.width,e.height);const s=i.getImageData(0,0,e.width,e.height),r=s.data;for(let a=0;a<r.length;a++)r[a]=di(r[a]/255)*255;return i.putImageData(s,0,0),t}else if(e.data){const t=e.data.slice(0);for(let i=0;i<t.length;i++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[i]=Math.floor(di(t[i]/255)*255):t[i]=di(t[i]);return{data:t,width:e.width,height:e.height}}else return We("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),e}}let Om=0;class Nc{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Om++}),this.uuid=fi(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){const t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayWidth,t.displayHeight,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];const i={uuid:this.uuid,url:""},s=this.data;if(s!==null){let r;if(Array.isArray(s)){r=[];for(let a=0,o=s.length;a<o;a++)s[a].isDataTexture?r.push(Ro(s[a].image)):r.push(Ro(s[a]))}else r=Ro(s);i.url=r}return t||(e.images[this.uuid]=i),i}}function Ro(n){return typeof HTMLImageElement<"u"&&n instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&n instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&n instanceof ImageBitmap?Um.getDataURL(n):n.data?{data:Array.from(n.data),width:n.width,height:n.height,type:n.data.constructor.name}:(We("Texture: Unable to serialize Texture."),{})}let Fm=0;const Po=new B;class Qt extends zi{constructor(e=Qt.DEFAULT_IMAGE,t=Qt.DEFAULT_MAPPING,i=li,s=li,r=Xt,a=Di,o=En,l=Sn,c=Qt.DEFAULT_ANISOTROPY,u=oi){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Fm++}),this.uuid=fi(),this.name="",this.source=new Nc(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=r,this.minFilter=a,this.anisotropy=c,this.format=o,this.internalFormat=null,this.type=l,this.offset=new Ee(0,0),this.repeat=new Ee(1,1),this.center=new Ee(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new $e,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(e&&e.depth&&e.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(Po).x}get height(){return this.source.getSize(Po).y}get depth(){return this.source.getSize(Po).z}get image(){return this.source.data}set image(e){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,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.normalized=e.normalized,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.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){for(const t in e){const i=e[t];if(i===void 0){We(`Texture.setValues(): parameter '${t}' has value of undefined.`);continue}const s=this[t];if(s===void 0){We(`Texture.setValues(): property '${t}' does not exist.`);continue}s&&i&&s.isVector2&&i.isVector2||s&&i&&s.isVector3&&i.isVector3||s&&i&&s.isMatrix3&&i.isMatrix3?s.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,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,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),t||(e.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Hf)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case Ll:e.x=e.x-Math.floor(e.x);break;case li:e.x=e.x<0?0:1;break;case Dl:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case Ll:e.y=e.y-Math.floor(e.y);break;case li:e.y=e.y<0?0:1;break;case Dl:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}}Qt.DEFAULT_IMAGE=null;Qt.DEFAULT_MAPPING=Hf;Qt.DEFAULT_ANISOTROPY=1;const cu=class cu{constructor(e=0,t=0,i=0,s=1){this.x=e,this.y=t,this.z=i,this.w=s}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("THREE.Vector4: index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("THREE.Vector4: index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,i=this.y,s=this.z,r=this.w,a=e.elements;return this.x=a[0]*t+a[4]*i+a[8]*s+a[12]*r,this.y=a[1]*t+a[5]*i+a[9]*s+a[13]*r,this.z=a[2]*t+a[6]*i+a[10]*s+a[14]*r,this.w=a[3]*t+a[7]*i+a[11]*s+a[15]*r,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,i,s,r;const l=e.elements,c=l[0],u=l[4],f=l[8],h=l[1],d=l[5],p=l[9],x=l[2],m=l[6],g=l[10];if(Math.abs(u-h)<.01&&Math.abs(f-x)<.01&&Math.abs(p-m)<.01){if(Math.abs(u+h)<.1&&Math.abs(f+x)<.1&&Math.abs(p+m)<.1&&Math.abs(c+d+g-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const E=(c+1)/2,_=(d+1)/2,T=(g+1)/2,b=(u+h)/4,S=(f+x)/4,v=(p+m)/4;return E>_&&E>T?E<.01?(i=0,s=.707106781,r=.707106781):(i=Math.sqrt(E),s=b/i,r=S/i):_>T?_<.01?(i=.707106781,s=0,r=.707106781):(s=Math.sqrt(_),i=b/s,r=v/s):T<.01?(i=.707106781,s=.707106781,r=0):(r=Math.sqrt(T),i=S/r,s=v/r),this.set(i,s,r,t),this}let M=Math.sqrt((m-p)*(m-p)+(f-x)*(f-x)+(h-u)*(h-u));return Math.abs(M)<.001&&(M=1),this.x=(m-p)/M,this.y=(f-x)/M,this.z=(h-u)/M,this.w=Math.acos((c+d+g-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Qe(this.x,e.x,t.x),this.y=Qe(this.y,e.y,t.y),this.z=Qe(this.z,e.z,t.z),this.w=Qe(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=Qe(this.x,e,t),this.y=Qe(this.y,e,t),this.z=Qe(this.z,e,t),this.w=Qe(this.w,e,t),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Qe(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this.w=e.w+(t.w-e.w)*i,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}};cu.prototype.isVector4=!0;let Ct=cu;class Nm extends zi{constructor(e=1,t=1,i={}){super(),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Xt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1,useArrayDepthTexture:!1},i),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=i.depth,this.scissor=new Ct(0,0,e,t),this.scissorTest=!1,this.viewport=new Ct(0,0,e,t),this.textures=[];const s={width:e,height:t,depth:i.depth},r=new Qt(s),a=i.count;for(let o=0;o<a;o++)this.textures[o]=r.clone(),this.textures[o].isRenderTargetTexture=!0,this.textures[o].renderTarget=this;this._setTextureOptions(i),this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.resolveDepthBuffer=i.resolveDepthBuffer,this.resolveStencilBuffer=i.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=i.depthTexture,this.samples=i.samples,this.multiview=i.multiview,this.useArrayDepthTexture=i.useArrayDepthTexture}_setTextureOptions(e={}){const t={minFilter:Xt,generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let i=0;i<this.textures.length;i++)this.textures[i].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,i=1){if(this.width!==e||this.height!==t||this.depth!==i){this.width=e,this.height=t,this.depth=i;for(let s=0,r=this.textures.length;s<r;s++)this.textures[s].image.width=e,this.textures[s].image.height=t,this.textures[s].image.depth=i,this.textures[s].isData3DTexture!==!0&&(this.textures[s].isArrayTexture=this.textures[s].image.depth>1);this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,i=e.textures.length;t<i;t++){this.textures[t]=e.textures[t].clone(),this.textures[t].isRenderTargetTexture=!0,this.textures[t].renderTarget=this;const s=Object.assign({},e.textures[t].image);this.textures[t].source=new Nc(s)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this.multiview=e.multiview,this.useArrayDepthTexture=e.useArrayDepthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Jn extends Nm{constructor(e=1,t=1,i={}){super(e,t,i),this.isWebGLRenderTarget=!0}}class Zf extends Qt{constructor(e=null,t=1,i=1,s=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:i,depth:s},this.magFilter=Ft,this.minFilter=Ft,this.wrapR=li,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class km extends Qt{constructor(e=null,t=1,i=1,s=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:i,depth:s},this.magFilter=Ft,this.minFilter=Ft,this.wrapR=li,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const po=class po{constructor(e,t,i,s,r,a,o,l,c,u,f,h,d,p,x,m){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,i,s,r,a,o,l,c,u,f,h,d,p,x,m)}set(e,t,i,s,r,a,o,l,c,u,f,h,d,p,x,m){const g=this.elements;return g[0]=e,g[4]=t,g[8]=i,g[12]=s,g[1]=r,g[5]=a,g[9]=o,g[13]=l,g[2]=c,g[6]=u,g[10]=f,g[14]=h,g[3]=d,g[7]=p,g[11]=x,g[15]=m,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new po().fromArray(this.elements)}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],this}copyPosition(e){const t=this.elements,i=e.elements;return t[12]=i[12],t[13]=i[13],t[14]=i[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,i){return this.determinantAffine()===0?(e.set(1,0,0),t.set(0,1,0),i.set(0,0,1),this):(e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(e,t,i){return this.set(e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1),this}extractRotation(e){if(e.determinantAffine()===0)return this.identity();const t=this.elements,i=e.elements,s=1/xs.setFromMatrixColumn(e,0).length(),r=1/xs.setFromMatrixColumn(e,1).length(),a=1/xs.setFromMatrixColumn(e,2).length();return t[0]=i[0]*s,t[1]=i[1]*s,t[2]=i[2]*s,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]*a,t[9]=i[9]*a,t[10]=i[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,i=e.x,s=e.y,r=e.z,a=Math.cos(i),o=Math.sin(i),l=Math.cos(s),c=Math.sin(s),u=Math.cos(r),f=Math.sin(r);if(e.order==="XYZ"){const h=a*u,d=a*f,p=o*u,x=o*f;t[0]=l*u,t[4]=-l*f,t[8]=c,t[1]=d+p*c,t[5]=h-x*c,t[9]=-o*l,t[2]=x-h*c,t[6]=p+d*c,t[10]=a*l}else if(e.order==="YXZ"){const h=l*u,d=l*f,p=c*u,x=c*f;t[0]=h+x*o,t[4]=p*o-d,t[8]=a*c,t[1]=a*f,t[5]=a*u,t[9]=-o,t[2]=d*o-p,t[6]=x+h*o,t[10]=a*l}else if(e.order==="ZXY"){const h=l*u,d=l*f,p=c*u,x=c*f;t[0]=h-x*o,t[4]=-a*f,t[8]=p+d*o,t[1]=d+p*o,t[5]=a*u,t[9]=x-h*o,t[2]=-a*c,t[6]=o,t[10]=a*l}else if(e.order==="ZYX"){const h=a*u,d=a*f,p=o*u,x=o*f;t[0]=l*u,t[4]=p*c-d,t[8]=h*c+x,t[1]=l*f,t[5]=x*c+h,t[9]=d*c-p,t[2]=-c,t[6]=o*l,t[10]=a*l}else if(e.order==="YZX"){const h=a*l,d=a*c,p=o*l,x=o*c;t[0]=l*u,t[4]=x-h*f,t[8]=p*f+d,t[1]=f,t[5]=a*u,t[9]=-o*u,t[2]=-c*u,t[6]=d*f+p,t[10]=h-x*f}else if(e.order==="XZY"){const h=a*l,d=a*c,p=o*l,x=o*c;t[0]=l*u,t[4]=-f,t[8]=c*u,t[1]=h*f+x,t[5]=a*u,t[9]=d*f-p,t[2]=p*f-d,t[6]=o*u,t[10]=x*f+h}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(Bm,e,Hm)}lookAt(e,t,i){const s=this.elements;return dn.subVectors(e,t),dn.lengthSq()===0&&(dn.z=1),dn.normalize(),bi.crossVectors(i,dn),bi.lengthSq()===0&&(Math.abs(i.z)===1?dn.x+=1e-4:dn.z+=1e-4,dn.normalize(),bi.crossVectors(i,dn)),bi.normalize(),Xr.crossVectors(dn,bi),s[0]=bi.x,s[4]=Xr.x,s[8]=dn.x,s[1]=bi.y,s[5]=Xr.y,s[9]=dn.y,s[2]=bi.z,s[6]=Xr.z,s[10]=dn.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,s=t.elements,r=this.elements,a=i[0],o=i[4],l=i[8],c=i[12],u=i[1],f=i[5],h=i[9],d=i[13],p=i[2],x=i[6],m=i[10],g=i[14],M=i[3],E=i[7],_=i[11],T=i[15],b=s[0],S=s[4],v=s[8],w=s[12],I=s[1],L=s[5],C=s[9],O=s[13],N=s[2],U=s[6],Z=s[10],k=s[14],$=s[3],D=s[7],ae=s[11],re=s[15];return r[0]=a*b+o*I+l*N+c*$,r[4]=a*S+o*L+l*U+c*D,r[8]=a*v+o*C+l*Z+c*ae,r[12]=a*w+o*O+l*k+c*re,r[1]=u*b+f*I+h*N+d*$,r[5]=u*S+f*L+h*U+d*D,r[9]=u*v+f*C+h*Z+d*ae,r[13]=u*w+f*O+h*k+d*re,r[2]=p*b+x*I+m*N+g*$,r[6]=p*S+x*L+m*U+g*D,r[10]=p*v+x*C+m*Z+g*ae,r[14]=p*w+x*O+m*k+g*re,r[3]=M*b+E*I+_*N+T*$,r[7]=M*S+E*L+_*U+T*D,r[11]=M*v+E*C+_*Z+T*ae,r[15]=M*w+E*O+_*k+T*re,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[4],s=e[8],r=e[12],a=e[1],o=e[5],l=e[9],c=e[13],u=e[2],f=e[6],h=e[10],d=e[14],p=e[3],x=e[7],m=e[11],g=e[15],M=l*d-c*h,E=o*d-c*f,_=o*h-l*f,T=a*d-c*u,b=a*h-l*u,S=a*f-o*u;return t*(x*M-m*E+g*_)-i*(p*M-m*T+g*b)+s*(p*E-x*T+g*S)-r*(p*_-x*b+m*S)}determinantAffine(){const e=this.elements,t=e[0],i=e[4],s=e[8],r=e[1],a=e[5],o=e[9],l=e[2],c=e[6],u=e[10];return t*(a*u-o*c)-i*(r*u-o*l)+s*(r*c-a*l)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,i){const s=this.elements;return e.isVector3?(s[12]=e.x,s[13]=e.y,s[14]=e.z):(s[12]=e,s[13]=t,s[14]=i),this}invert(){const e=this.elements,t=e[0],i=e[1],s=e[2],r=e[3],a=e[4],o=e[5],l=e[6],c=e[7],u=e[8],f=e[9],h=e[10],d=e[11],p=e[12],x=e[13],m=e[14],g=e[15],M=t*o-i*a,E=t*l-s*a,_=t*c-r*a,T=i*l-s*o,b=i*c-r*o,S=s*c-r*l,v=u*x-f*p,w=u*m-h*p,I=u*g-d*p,L=f*m-h*x,C=f*g-d*x,O=h*g-d*m,N=M*O-E*C+_*L+T*I-b*w+S*v;if(N===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const U=1/N;return e[0]=(o*O-l*C+c*L)*U,e[1]=(s*C-i*O-r*L)*U,e[2]=(x*S-m*b+g*T)*U,e[3]=(h*b-f*S-d*T)*U,e[4]=(l*I-a*O-c*w)*U,e[5]=(t*O-s*I+r*w)*U,e[6]=(m*_-p*S-g*E)*U,e[7]=(u*S-h*_+d*E)*U,e[8]=(a*C-o*I+c*v)*U,e[9]=(i*I-t*C-r*v)*U,e[10]=(p*b-x*_+g*M)*U,e[11]=(f*_-u*b-d*M)*U,e[12]=(o*w-a*L-l*v)*U,e[13]=(t*L-i*w+s*v)*U,e[14]=(x*E-p*T-m*M)*U,e[15]=(u*T-f*E+h*M)*U,this}scale(e){const t=this.elements,i=e.x,s=e.y,r=e.z;return t[0]*=i,t[4]*=s,t[8]*=r,t[1]*=i,t[5]*=s,t[9]*=r,t[2]*=i,t[6]*=s,t[10]*=r,t[3]*=i,t[7]*=s,t[11]*=r,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],s=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,i,s))}makeTranslation(e,t,i){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,i,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),i=Math.sin(e);return this.set(1,0,0,0,0,t,-i,0,0,i,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,0,i,0,0,1,0,0,-i,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,0,i,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const i=Math.cos(t),s=Math.sin(t),r=1-i,a=e.x,o=e.y,l=e.z,c=r*a,u=r*o;return this.set(c*a+i,c*o-s*l,c*l+s*o,0,c*o+s*l,u*o+i,u*l-s*a,0,c*l-s*o,u*l+s*a,r*l*l+i,0,0,0,0,1),this}makeScale(e,t,i){return this.set(e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1),this}makeShear(e,t,i,s,r,a){return this.set(1,i,r,0,e,1,a,0,t,s,1,0,0,0,0,1),this}compose(e,t,i){const s=this.elements,r=t._x,a=t._y,o=t._z,l=t._w,c=r+r,u=a+a,f=o+o,h=r*c,d=r*u,p=r*f,x=a*u,m=a*f,g=o*f,M=l*c,E=l*u,_=l*f,T=i.x,b=i.y,S=i.z;return s[0]=(1-(x+g))*T,s[1]=(d+_)*T,s[2]=(p-E)*T,s[3]=0,s[4]=(d-_)*b,s[5]=(1-(h+g))*b,s[6]=(m+M)*b,s[7]=0,s[8]=(p+E)*S,s[9]=(m-M)*S,s[10]=(1-(h+x))*S,s[11]=0,s[12]=e.x,s[13]=e.y,s[14]=e.z,s[15]=1,this}decompose(e,t,i){const s=this.elements;e.x=s[12],e.y=s[13],e.z=s[14];const r=this.determinantAffine();if(r===0)return i.set(1,1,1),t.identity(),this;let a=xs.set(s[0],s[1],s[2]).length();const o=xs.set(s[4],s[5],s[6]).length(),l=xs.set(s[8],s[9],s[10]).length();r<0&&(a=-a),An.copy(this);const c=1/a,u=1/o,f=1/l;return An.elements[0]*=c,An.elements[1]*=c,An.elements[2]*=c,An.elements[4]*=u,An.elements[5]*=u,An.elements[6]*=u,An.elements[8]*=f,An.elements[9]*=f,An.elements[10]*=f,t.setFromRotationMatrix(An),i.x=a,i.y=o,i.z=l,this}makePerspective(e,t,i,s,r,a,o=$n,l=!1){const c=this.elements,u=2*r/(t-e),f=2*r/(i-s),h=(t+e)/(t-e),d=(i+s)/(i-s);let p,x;if(l)p=r/(a-r),x=a*r/(a-r);else if(o===$n)p=-(a+r)/(a-r),x=-2*a*r/(a-r);else if(o===$a)p=-a/(a-r),x=-a*r/(a-r);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);return c[0]=u,c[4]=0,c[8]=h,c[12]=0,c[1]=0,c[5]=f,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=x,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,i,s,r,a,o=$n,l=!1){const c=this.elements,u=2/(t-e),f=2/(i-s),h=-(t+e)/(t-e),d=-(i+s)/(i-s);let p,x;if(l)p=1/(a-r),x=a/(a-r);else if(o===$n)p=-2/(a-r),x=-(a+r)/(a-r);else if(o===$a)p=-1/(a-r),x=-r/(a-r);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=u,c[4]=0,c[8]=0,c[12]=h,c[1]=0,c[5]=f,c[9]=0,c[13]=d,c[2]=0,c[6]=0,c[10]=p,c[14]=x,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,i=e.elements;for(let s=0;s<16;s++)if(t[s]!==i[s])return!1;return!0}fromArray(e,t=0){for(let i=0;i<16;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e[t+9]=i[9],e[t+10]=i[10],e[t+11]=i[11],e[t+12]=i[12],e[t+13]=i[13],e[t+14]=i[14],e[t+15]=i[15],e}};po.prototype.isMatrix4=!0;let Tt=po;const xs=new B,An=new Tt,Bm=new B(0,0,0),Hm=new B(1,1,1),bi=new B,Xr=new B,dn=new B,Su=new Tt,Mu=new ki;class ns{constructor(e=0,t=0,i=0,s=ns.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=i,this._order=s}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,i,s=this._order){return this._x=e,this._y=t,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,i=!0){const s=e.elements,r=s[0],a=s[4],o=s[8],l=s[1],c=s[5],u=s[9],f=s[2],h=s[6],d=s[10];switch(t){case"XYZ":this._y=Math.asin(Qe(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,d),this._z=Math.atan2(-a,r)):(this._x=Math.atan2(h,c),this._z=0);break;case"YXZ":this._x=Math.asin(-Qe(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-f,r),this._z=0);break;case"ZXY":this._x=Math.asin(Qe(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(-f,d),this._z=Math.atan2(-a,c)):(this._y=0,this._z=Math.atan2(l,r));break;case"ZYX":this._y=Math.asin(-Qe(f,-1,1)),Math.abs(f)<.9999999?(this._x=Math.atan2(h,d),this._z=Math.atan2(l,r)):(this._x=0,this._z=Math.atan2(-a,c));break;case"YZX":this._z=Math.asin(Qe(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-u,c),this._y=Math.atan2(-f,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-Qe(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(h,c),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-u,d),this._y=0);break;default:We("Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,i===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,i){return Su.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Su,t,i)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return Mu.setFromEuler(this),this.setFromQuaternion(Mu,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}ns.DEFAULT_ORDER="XYZ";class Kf{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}}let zm=0;const Eu=new B,vs=new ki,ni=new Tt,Yr=new B,ir=new B,Gm=new B,Vm=new ki,Tu=new B(1,0,0),Au=new B(0,1,0),wu=new B(0,0,1),Cu={type:"added"},Wm={type:"removed"},ys={type:"childadded",child:null},Lo={type:"childremoved",child:null};class sn extends zi{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:zm++}),this.uuid=fi(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=sn.DEFAULT_UP.clone();const e=new B,t=new ns,i=new ki,s=new B(1,1,1);function r(){i.setFromEuler(t,!1)}function a(){t.setFromQuaternion(i,void 0,!1)}t._onChange(r),i._onChange(a),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new Tt},normalMatrix:{value:new $e}}),this.matrix=new Tt,this.matrixWorld=new Tt,this.matrixAutoUpdate=sn.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=sn.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Kf,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return vs.setFromAxisAngle(e,t),this.quaternion.multiply(vs),this}rotateOnWorldAxis(e,t){return vs.setFromAxisAngle(e,t),this.quaternion.premultiply(vs),this}rotateX(e){return this.rotateOnAxis(Tu,e)}rotateY(e){return this.rotateOnAxis(Au,e)}rotateZ(e){return this.rotateOnAxis(wu,e)}translateOnAxis(e,t){return Eu.copy(e).applyQuaternion(this.quaternion),this.position.add(Eu.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Tu,e)}translateY(e){return this.translateOnAxis(Au,e)}translateZ(e){return this.translateOnAxis(wu,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(ni.copy(this.matrixWorld).invert())}lookAt(e,t,i){e.isVector3?Yr.copy(e):Yr.set(e,t,i);const s=this.parent;this.updateWorldMatrix(!0,!1),ir.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?ni.lookAt(ir,Yr,this.up):ni.lookAt(Yr,ir,this.up),this.quaternion.setFromRotationMatrix(ni),s&&(ni.extractRotation(s.matrixWorld),vs.setFromRotationMatrix(ni),this.quaternion.premultiply(vs.invert()))}add(e){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return e===this?(st("Object3D.add: object can't be added as a child of itself.",e),this):(e&&e.isObject3D?(e.removeFromParent(),e.parent=this,this.children.push(e),e.dispatchEvent(Cu),ys.child=e,this.dispatchEvent(ys),ys.child=null):st("Object3D.add: object not an instance of THREE.Object3D.",e),this)}remove(e){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(Wm),Lo.child=e,this.dispatchEvent(Lo),Lo.child=null),this}removeFromParent(){const e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),ni.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),ni.multiply(e.parent.matrixWorld)),e.applyMatrix4(ni),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(Cu),ys.child=e,this.dispatchEvent(ys),ys.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let i=0,s=this.children.length;i<s;i++){const a=this.children[i].getObjectByProperty(e,t);if(a!==void 0)return a}}getObjectsByProperty(e,t,i=[]){this[e]===t&&i.push(this);const s=this.children;for(let r=0,a=s.length;r<a;r++)s[r].getObjectsByProperty(e,t,i);return i}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ir,e,Gm),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ir,Vm,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);const t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);const t=this.children;for(let i=0,s=t.length;i<s;i++)t[i].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);const t=this.children;for(let i=0,s=t.length;i<s;i++)t[i].traverseVisible(e)}traverseAncestors(e){const t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const e=this.pivot;if(e!==null){const t=e.x,i=e.y,s=e.z,r=this.matrix.elements;r[12]+=t-r[0]*t-r[4]*i-r[8]*s,r[13]+=i-r[1]*t-r[5]*i-r[9]*s,r[14]+=s-r[2]*t-r[6]*i-r[10]*s}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);const t=this.children;for(let i=0,s=t.length;i<s;i++)t[i].updateMatrixWorld(e)}updateWorldMatrix(e,t,i=!1){const s=this.parent;if(e===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),t===!0){const r=this.children;for(let a=0,o=r.length;a<o;a++)r[a].updateWorldMatrix(!1,!0,i)}}toJSON(e){const t=e===void 0||typeof e=="string",i={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,this.name!==""&&(s.name=this.name),this.castShadow===!0&&(s.castShadow=!0),this.receiveShadow===!0&&(s.receiveShadow=!0),this.visible===!1&&(s.visible=!1),this.frustumCulled===!1&&(s.frustumCulled=!1),this.renderOrder!==0&&(s.renderOrder=this.renderOrder),this.static!==!1&&(s.static=this.static),Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.pivot!==null&&(s.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(s.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(s.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(s.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.geometryInfo=this._geometryInfo.map(o=>({...o,boundingBox:o.boundingBox?o.boundingBox.toJSON():void 0,boundingSphere:o.boundingSphere?o.boundingSphere.toJSON():void 0})),s.instanceInfo=this._instanceInfo.map(o=>({...o})),s.availableInstanceIds=this._availableInstanceIds.slice(),s.availableGeometryIds=this._availableGeometryIds.slice(),s.nextIndexStart=this._nextIndexStart,s.nextVertexStart=this._nextVertexStart,s.geometryCount=this._geometryCount,s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.matricesTexture=this._matricesTexture.toJSON(e),s.indirectTexture=this._indirectTexture.toJSON(e),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(e)),this.boundingSphere!==null&&(s.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(s.boundingBox=this.boundingBox.toJSON()));function r(o,l){return o[l.uuid]===void 0&&(o[l.uuid]=l.toJSON(e)),l.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=r(e.geometries,this.geometry);const o=this.geometry.parameters;if(o!==void 0&&o.shapes!==void 0){const l=o.shapes;if(Array.isArray(l))for(let c=0,u=l.length;c<u;c++){const f=l[c];r(e.shapes,f)}else r(e.shapes,l)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(r(e.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const o=[];for(let l=0,c=this.material.length;l<c;l++)o.push(r(e.materials,this.material[l]));s.material=o}else s.material=r(e.materials,this.material);if(this.children.length>0){s.children=[];for(let o=0;o<this.children.length;o++)s.children.push(this.children[o].toJSON(e).object)}if(this.animations.length>0){s.animations=[];for(let o=0;o<this.animations.length;o++){const l=this.animations[o];s.animations.push(r(e.animations,l))}}if(t){const o=a(e.geometries),l=a(e.materials),c=a(e.textures),u=a(e.images),f=a(e.shapes),h=a(e.skeletons),d=a(e.animations),p=a(e.nodes);o.length>0&&(i.geometries=o),l.length>0&&(i.materials=l),c.length>0&&(i.textures=c),u.length>0&&(i.images=u),f.length>0&&(i.shapes=f),h.length>0&&(i.skeletons=h),d.length>0&&(i.animations=d),p.length>0&&(i.nodes=p)}return i.object=s,i;function a(o){const l=[];for(const c in o){const u=o[c];delete u.metadata,l.push(u)}return l}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.pivot=e.pivot!==null?e.pivot.clone():null,this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,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.static=e.static,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let i=0;i<e.children.length;i++){const s=e.children[i];this.add(s.clone())}return this}}sn.DEFAULT_UP=new B(0,1,0);sn.DEFAULT_MATRIX_AUTO_UPDATE=!0;sn.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;class gr extends sn{constructor(){super(),this.isGroup=!0,this.type="Group"}}const Xm={type:"move"};class Do{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new gr,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new gr,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new B,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new B),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new gr,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new B,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new B,this._grip.eventsEnabled=!1),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){const t=this._hand;if(t)for(const i of e.hand.values())this._getHandJoint(t,i)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,i){let s=null,r=null,a=null;const o=this._targetRay,l=this._grip,c=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(c&&e.hand){a=!0;for(const x of e.hand.values()){const m=t.getJointPose(x,i),g=this._getHandJoint(c,x);m!==null&&(g.matrix.fromArray(m.transform.matrix),g.matrix.decompose(g.position,g.rotation,g.scale),g.matrixWorldNeedsUpdate=!0,g.jointRadius=m.radius),g.visible=m!==null}const u=c.joints["index-finger-tip"],f=c.joints["thumb-tip"],h=u.position.distanceTo(f.position),d=.02,p=.005;c.inputState.pinching&&h>d+p?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!c.inputState.pinching&&h<=d-p&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else l!==null&&e.gripSpace&&(r=t.getPose(e.gripSpace,i),r!==null&&(l.matrix.fromArray(r.transform.matrix),l.matrix.decompose(l.position,l.rotation,l.scale),l.matrixWorldNeedsUpdate=!0,r.linearVelocity?(l.hasLinearVelocity=!0,l.linearVelocity.copy(r.linearVelocity)):l.hasLinearVelocity=!1,r.angularVelocity?(l.hasAngularVelocity=!0,l.angularVelocity.copy(r.angularVelocity)):l.hasAngularVelocity=!1,l.eventsEnabled&&l.dispatchEvent({type:"gripUpdated",data:e,target:this})));o!==null&&(s=t.getPose(e.targetRaySpace,i),s===null&&r!==null&&(s=r),s!==null&&(o.matrix.fromArray(s.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,s.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(s.linearVelocity)):o.hasLinearVelocity=!1,s.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(s.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(Xm)))}return o!==null&&(o.visible=s!==null),l!==null&&(l.visible=r!==null),c!==null&&(c.visible=a!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){const i=new gr;i.matrixAutoUpdate=!1,i.visible=!1,e.joints[t.jointName]=i,e.add(i)}return e.joints[t.jointName]}}const Jf={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},Si={h:0,s:0,l:0},qr={h:0,s:0,l:0};function Io(n,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?n+(e-n)*6*t:t<1/2?e:t<2/3?n+(e-n)*6*(2/3-t):n}class et{constructor(e,t,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,i)}set(e,t,i){if(t===void 0&&i===void 0){const s=e;s&&s.isColor?this.copy(s):typeof s=="number"?this.setHex(s):typeof s=="string"&&this.setStyle(s)}else this.setRGB(e,t,i);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=mn){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,nt.colorSpaceToWorking(this,t),this}setRGB(e,t,i,s=nt.workingColorSpace){return this.r=e,this.g=t,this.b=i,nt.colorSpaceToWorking(this,s),this}setHSL(e,t,i,s=nt.workingColorSpace){if(e=Lm(e,1),t=Qe(t,0,1),i=Qe(i,0,1),t===0)this.r=this.g=this.b=i;else{const r=i<=.5?i*(1+t):i+t-i*t,a=2*i-r;this.r=Io(a,r,e+1/3),this.g=Io(a,r,e),this.b=Io(a,r,e-1/3)}return nt.colorSpaceToWorking(this,s),this}setStyle(e,t=mn){function i(r){r!==void 0&&parseFloat(r)<1&&We("Color: Alpha component of "+e+" will be ignored.")}let s;if(s=/^(\w+)\(([^\)]*)\)/.exec(e)){let r;const a=s[1],o=s[2];switch(a){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,t);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,t);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return i(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,t);break;default:We("Color: Unknown color model "+e)}}else if(s=/^\#([A-Fa-f\d]+)$/.exec(e)){const r=s[1],a=r.length;if(a===3)return this.setRGB(parseInt(r.charAt(0),16)/15,parseInt(r.charAt(1),16)/15,parseInt(r.charAt(2),16)/15,t);if(a===6)return this.setHex(parseInt(r,16),t);We("Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=mn){const i=Jf[e.toLowerCase()];return i!==void 0?this.setHex(i,t):We("Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=di(e.r),this.g=di(e.g),this.b=di(e.b),this}copyLinearToSRGB(e){return this.r=Hs(e.r),this.g=Hs(e.g),this.b=Hs(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=mn){return nt.workingToColorSpace(Kt.copy(this),e),Math.round(Qe(Kt.r*255,0,255))*65536+Math.round(Qe(Kt.g*255,0,255))*256+Math.round(Qe(Kt.b*255,0,255))}getHexString(e=mn){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=nt.workingColorSpace){nt.workingToColorSpace(Kt.copy(this),t);const i=Kt.r,s=Kt.g,r=Kt.b,a=Math.max(i,s,r),o=Math.min(i,s,r);let l,c;const u=(o+a)/2;if(o===a)l=0,c=0;else{const f=a-o;switch(c=u<=.5?f/(a+o):f/(2-a-o),a){case i:l=(s-r)/f+(s<r?6:0);break;case s:l=(r-i)/f+2;break;case r:l=(i-s)/f+4;break}l/=6}return e.h=l,e.s=c,e.l=u,e}getRGB(e,t=nt.workingColorSpace){return nt.workingToColorSpace(Kt.copy(this),t),e.r=Kt.r,e.g=Kt.g,e.b=Kt.b,e}getStyle(e=mn){nt.workingToColorSpace(Kt.copy(this),e);const t=Kt.r,i=Kt.g,s=Kt.b;return e!==mn?`color(${e} ${t.toFixed(3)} ${i.toFixed(3)} ${s.toFixed(3)})`:`rgb(${Math.round(t*255)},${Math.round(i*255)},${Math.round(s*255)})`}offsetHSL(e,t,i){return this.getHSL(Si),this.setHSL(Si.h+e,Si.s+t,Si.l+i)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,i){return this.r=e.r+(t.r-e.r)*i,this.g=e.g+(t.g-e.g)*i,this.b=e.b+(t.b-e.b)*i,this}lerpHSL(e,t){this.getHSL(Si),e.getHSL(qr);const i=Ao(Si.h,qr.h,t),s=Ao(Si.s,qr.s,t),r=Ao(Si.l,qr.l,t);return this.setHSL(i,s,r),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){const t=this.r,i=this.g,s=this.b,r=e.elements;return this.r=r[0]*t+r[3]*i+r[6]*s,this.g=r[1]*t+r[4]*i+r[7]*s,this.b=r[2]*t+r[5]*i+r[8]*s,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const Kt=new et;et.NAMES=Jf;class Ym extends sn{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new ns,this.environmentIntensity=1,this.environmentRotation=new ns,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(t.object.environmentIntensity=this.environmentIntensity),t.object.environmentRotation=this.environmentRotation.toArray(),t}}const wn=new B,ii=new B,Uo=new B,si=new B,_s=new B,bs=new B,Ru=new B,Oo=new B,Fo=new B,No=new B,ko=new Ct,Bo=new Ct,Ho=new Ct;class Mn{constructor(e=new B,t=new B,i=new B){this.a=e,this.b=t,this.c=i}static getNormal(e,t,i,s){s.subVectors(i,t),wn.subVectors(e,t),s.cross(wn);const r=s.lengthSq();return r>0?s.multiplyScalar(1/Math.sqrt(r)):s.set(0,0,0)}static getBarycoord(e,t,i,s,r){wn.subVectors(s,t),ii.subVectors(i,t),Uo.subVectors(e,t);const a=wn.dot(wn),o=wn.dot(ii),l=wn.dot(Uo),c=ii.dot(ii),u=ii.dot(Uo),f=a*c-o*o;if(f===0)return r.set(0,0,0),null;const h=1/f,d=(c*l-o*u)*h,p=(a*u-o*l)*h;return r.set(1-d-p,p,d)}static containsPoint(e,t,i,s){return this.getBarycoord(e,t,i,s,si)===null?!1:si.x>=0&&si.y>=0&&si.x+si.y<=1}static getInterpolation(e,t,i,s,r,a,o,l){return this.getBarycoord(e,t,i,s,si)===null?(l.x=0,l.y=0,"z"in l&&(l.z=0),"w"in l&&(l.w=0),null):(l.setScalar(0),l.addScaledVector(r,si.x),l.addScaledVector(a,si.y),l.addScaledVector(o,si.z),l)}static getInterpolatedAttribute(e,t,i,s,r,a){return ko.setScalar(0),Bo.setScalar(0),Ho.setScalar(0),ko.fromBufferAttribute(e,t),Bo.fromBufferAttribute(e,i),Ho.fromBufferAttribute(e,s),a.setScalar(0),a.addScaledVector(ko,r.x),a.addScaledVector(Bo,r.y),a.addScaledVector(Ho,r.z),a}static isFrontFacing(e,t,i,s){return wn.subVectors(i,t),ii.subVectors(e,t),wn.cross(ii).dot(s)<0}set(e,t,i){return this.a.copy(e),this.b.copy(t),this.c.copy(i),this}setFromPointsAndIndices(e,t,i,s){return this.a.copy(e[t]),this.b.copy(e[i]),this.c.copy(e[s]),this}setFromAttributeAndIndices(e,t,i,s){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,i),this.c.fromBufferAttribute(e,s),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return wn.subVectors(this.c,this.b),ii.subVectors(this.a,this.b),wn.cross(ii).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return Mn.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return Mn.getBarycoord(e,this.a,this.b,this.c,t)}getInterpolation(e,t,i,s,r){return Mn.getInterpolation(e,this.a,this.b,this.c,t,i,s,r)}containsPoint(e){return Mn.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return Mn.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const i=this.a,s=this.b,r=this.c;let a,o;_s.subVectors(s,i),bs.subVectors(r,i),Oo.subVectors(e,i);const l=_s.dot(Oo),c=bs.dot(Oo);if(l<=0&&c<=0)return t.copy(i);Fo.subVectors(e,s);const u=_s.dot(Fo),f=bs.dot(Fo);if(u>=0&&f<=u)return t.copy(s);const h=l*f-u*c;if(h<=0&&l>=0&&u<=0)return a=l/(l-u),t.copy(i).addScaledVector(_s,a);No.subVectors(e,r);const d=_s.dot(No),p=bs.dot(No);if(p>=0&&d<=p)return t.copy(r);const x=d*c-l*p;if(x<=0&&c>=0&&p<=0)return o=c/(c-p),t.copy(i).addScaledVector(bs,o);const m=u*p-d*f;if(m<=0&&f-u>=0&&d-p>=0)return Ru.subVectors(r,s),o=(f-u)/(f-u+(d-p)),t.copy(s).addScaledVector(Ru,o);const g=1/(m+x+h);return a=x*g,o=h*g,t.copy(i).addScaledVector(_s,a).addScaledVector(bs,o)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}class Oi{constructor(e=new B(1/0,1/0,1/0),t=new B(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t+=3)this.expandByPoint(Cn.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,i=e.count;t<i;t++)this.expandByPoint(Cn.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,i=e.length;t<i;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){const i=Cn.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(i),this.max.copy(e).add(i),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);const i=e.geometry;if(i!==void 0){const r=i.getAttribute("position");if(t===!0&&r!==void 0&&e.isInstancedMesh!==!0)for(let a=0,o=r.count;a<o;a++)e.isMesh===!0?e.getVertexPosition(a,Cn):Cn.fromBufferAttribute(r,a),Cn.applyMatrix4(e.matrixWorld),this.expandByPoint(Cn);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),$r.copy(e.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),$r.copy(i.boundingBox)),$r.applyMatrix4(e.matrixWorld),this.union($r)}const s=e.children;for(let r=0,a=s.length;r<a;r++)this.expandByObject(s[r],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,Cn),Cn.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,i;return e.normal.x>0?(t=e.normal.x*this.min.x,i=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,i=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,i+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,i+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,i+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,i+=e.normal.z*this.min.z),t<=-e.constant&&i>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(sr),Zr.subVectors(this.max,sr),Ss.subVectors(e.a,sr),Ms.subVectors(e.b,sr),Es.subVectors(e.c,sr),Mi.subVectors(Ms,Ss),Ei.subVectors(Es,Ms),Gi.subVectors(Ss,Es);let t=[0,-Mi.z,Mi.y,0,-Ei.z,Ei.y,0,-Gi.z,Gi.y,Mi.z,0,-Mi.x,Ei.z,0,-Ei.x,Gi.z,0,-Gi.x,-Mi.y,Mi.x,0,-Ei.y,Ei.x,0,-Gi.y,Gi.x,0];return!zo(t,Ss,Ms,Es,Zr)||(t=[1,0,0,0,1,0,0,0,1],!zo(t,Ss,Ms,Es,Zr))?!1:(Kr.crossVectors(Mi,Ei),t=[Kr.x,Kr.y,Kr.z],zo(t,Ss,Ms,Es,Zr))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Cn).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Cn).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(ri[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),ri[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),ri[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),ri[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),ri[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),ri[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),ri[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),ri[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(ri),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}}const ri=[new B,new B,new B,new B,new B,new B,new B,new B],Cn=new B,$r=new Oi,Ss=new B,Ms=new B,Es=new B,Mi=new B,Ei=new B,Gi=new B,sr=new B,Zr=new B,Kr=new B,Vi=new B;function zo(n,e,t,i,s){for(let r=0,a=n.length-3;r<=a;r+=3){Vi.fromArray(n,r);const o=s.x*Math.abs(Vi.x)+s.y*Math.abs(Vi.y)+s.z*Math.abs(Vi.z),l=e.dot(Vi),c=t.dot(Vi),u=i.dot(Vi);if(Math.max(-Math.max(l,c,u),Math.min(l,c,u))>o)return!1}return!0}const It=new B,Jr=new Ee;let qm=0;class Dn extends zi{constructor(e,t,i=!1){if(super(),Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:qm++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=i,this.usage=cc,this.updateRanges=[],this.gpuType=Ln,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,i){e*=this.itemSize,i*=t.itemSize;for(let s=0,r=this.itemSize;s<r;s++)this.array[e+s]=t.array[i+s];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,i=this.count;t<i;t++)Jr.fromBufferAttribute(this,t),Jr.applyMatrix3(e),this.setXY(t,Jr.x,Jr.y);else if(this.itemSize===3)for(let t=0,i=this.count;t<i;t++)It.fromBufferAttribute(this,t),It.applyMatrix3(e),this.setXYZ(t,It.x,It.y,It.z);return this}applyMatrix4(e){for(let t=0,i=this.count;t<i;t++)It.fromBufferAttribute(this,t),It.applyMatrix4(e),this.setXYZ(t,It.x,It.y,It.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)It.fromBufferAttribute(this,t),It.applyNormalMatrix(e),this.setXYZ(t,It.x,It.y,It.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)It.fromBufferAttribute(this,t),It.transformDirection(e),this.setXYZ(t,It.x,It.y,It.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let i=this.array[e*this.itemSize+t];return this.normalized&&(i=qn(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=gt(i,this.array)),this.array[e*this.itemSize+t]=i,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=qn(t,this.array)),t}setX(e,t){return this.normalized&&(t=gt(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=qn(t,this.array)),t}setY(e,t){return this.normalized&&(t=gt(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=qn(t,this.array)),t}setZ(e,t){return this.normalized&&(t=gt(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=qn(t,this.array)),t}setW(e,t){return this.normalized&&(t=gt(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,i){return e*=this.itemSize,this.normalized&&(t=gt(t,this.array),i=gt(i,this.array)),this.array[e+0]=t,this.array[e+1]=i,this}setXYZ(e,t,i,s){return e*=this.itemSize,this.normalized&&(t=gt(t,this.array),i=gt(i,this.array),s=gt(s,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=s,this}setXYZW(e,t,i,s,r){return e*=this.itemSize,this.normalized&&(t=gt(t,this.array),i=gt(i,this.array),s=gt(s,this.array),r=gt(r,this.array)),this.array[e+0]=t,this.array[e+1]=i,this.array[e+2]=s,this.array[e+3]=r,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(e.name=this.name),this.usage!==cc&&(e.usage=this.usage),e}dispose(){this.dispatchEvent({type:"dispose"})}}class jf extends Dn{constructor(e,t,i){super(new Uint16Array(e),t,i)}}class Qf extends Dn{constructor(e,t,i){super(new Uint32Array(e),t,i)}}class ht extends Dn{constructor(e,t,i){super(new Float32Array(e),t,i)}}const $m=new Oi,rr=new B,Go=new B;class go{constructor(e=new B,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const i=this.center;t!==void 0?i.copy(t):$m.setFromPoints(e).getCenter(i);let s=0;for(let r=0,a=e.length;r<a;r++)s=Math.max(s,i.distanceToSquared(e[r]));return this.radius=Math.sqrt(s),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){const t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){const i=this.center.distanceToSquared(e);return t.copy(e),i>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;rr.subVectors(e,this.center);const t=rr.lengthSq();if(t>this.radius*this.radius){const i=Math.sqrt(t),s=(i-this.radius)*.5;this.center.addScaledVector(rr,s/i),this.radius+=s}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Go.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(rr.copy(e.center).add(Go)),this.expandByPoint(rr.copy(e.center).sub(Go))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}}let Zm=0;const bn=new Tt,Vo=new sn,Ts=new B,pn=new Oi,ar=new Oi,Ht=new B;class wt extends zi{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:Zm++}),this.uuid=fi(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(e){return Array.isArray(e)?this.index=new(wm(e)?Qf:jf)(e,1):this.index=e,this}setIndirect(e,t=0){return this.indirect=e,this.indirectOffset=t,this}getIndirect(){return this.indirect}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,i=0){this.groups.push({start:e,count:t,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){const t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const r=new $e().getNormalMatrix(e);i.applyNormalMatrix(r),i.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(e),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(e){return bn.makeRotationFromQuaternion(e),this.applyMatrix4(bn),this}rotateX(e){return bn.makeRotationX(e),this.applyMatrix4(bn),this}rotateY(e){return bn.makeRotationY(e),this.applyMatrix4(bn),this}rotateZ(e){return bn.makeRotationZ(e),this.applyMatrix4(bn),this}translate(e,t,i){return bn.makeTranslation(e,t,i),this.applyMatrix4(bn),this}scale(e,t,i){return bn.makeScale(e,t,i),this.applyMatrix4(bn),this}lookAt(e){return Vo.lookAt(e),Vo.updateMatrix(),this.applyMatrix4(Vo.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Ts).negate(),this.translate(Ts.x,Ts.y,Ts.z),this}setFromPoints(e){const t=this.getAttribute("position");if(t===void 0){const i=[];for(let s=0,r=e.length;s<r;s++){const a=e[s];i.push(a.x,a.y,a.z||0)}this.setAttribute("position",new ht(i,3))}else{const i=Math.min(e.length,t.count);for(let s=0;s<i;s++){const r=e[s];t.setXYZ(s,r.x,r.y,r.z||0)}e.length>t.count&&We("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Oi);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){st("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new B(-1/0,-1/0,-1/0),new B(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let i=0,s=t.length;i<s;i++){const r=t[i];pn.setFromBufferAttribute(r),this.morphTargetsRelative?(Ht.addVectors(this.boundingBox.min,pn.min),this.boundingBox.expandByPoint(Ht),Ht.addVectors(this.boundingBox.max,pn.max),this.boundingBox.expandByPoint(Ht)):(this.boundingBox.expandByPoint(pn.min),this.boundingBox.expandByPoint(pn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&st('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new go);const e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){st("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new B,1/0);return}if(e){const i=this.boundingSphere.center;if(pn.setFromBufferAttribute(e),t)for(let r=0,a=t.length;r<a;r++){const o=t[r];ar.setFromBufferAttribute(o),this.morphTargetsRelative?(Ht.addVectors(pn.min,ar.min),pn.expandByPoint(Ht),Ht.addVectors(pn.max,ar.max),pn.expandByPoint(Ht)):(pn.expandByPoint(ar.min),pn.expandByPoint(ar.max))}pn.getCenter(i);let s=0;for(let r=0,a=e.count;r<a;r++)Ht.fromBufferAttribute(e,r),s=Math.max(s,i.distanceToSquared(Ht));if(t)for(let r=0,a=t.length;r<a;r++){const o=t[r],l=this.morphTargetsRelative;for(let c=0,u=o.count;c<u;c++)Ht.fromBufferAttribute(o,c),l&&(Ts.fromBufferAttribute(e,c),Ht.add(Ts)),s=Math.max(s,i.distanceToSquared(Ht))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&st('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){st("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=t.position,s=t.normal,r=t.uv;let a=this.getAttribute("tangent");(a===void 0||a.count!==i.count)&&(a=new Dn(new Float32Array(4*i.count),4),this.setAttribute("tangent",a));const o=[],l=[];for(let v=0;v<i.count;v++)o[v]=new B,l[v]=new B;const c=new B,u=new B,f=new B,h=new Ee,d=new Ee,p=new Ee,x=new B,m=new B;function g(v,w,I){c.fromBufferAttribute(i,v),u.fromBufferAttribute(i,w),f.fromBufferAttribute(i,I),h.fromBufferAttribute(r,v),d.fromBufferAttribute(r,w),p.fromBufferAttribute(r,I),u.sub(c),f.sub(c),d.sub(h),p.sub(h);const L=1/(d.x*p.y-p.x*d.y);isFinite(L)&&(x.copy(u).multiplyScalar(p.y).addScaledVector(f,-d.y).multiplyScalar(L),m.copy(f).multiplyScalar(d.x).addScaledVector(u,-p.x).multiplyScalar(L),o[v].add(x),o[w].add(x),o[I].add(x),l[v].add(m),l[w].add(m),l[I].add(m))}let M=this.groups;M.length===0&&(M=[{start:0,count:e.count}]);for(let v=0,w=M.length;v<w;++v){const I=M[v],L=I.start,C=I.count;for(let O=L,N=L+C;O<N;O+=3)g(e.getX(O+0),e.getX(O+1),e.getX(O+2))}const E=new B,_=new B,T=new B,b=new B;function S(v){T.fromBufferAttribute(s,v),b.copy(T);const w=o[v];E.copy(w),E.sub(T.multiplyScalar(T.dot(w))).normalize(),_.crossVectors(b,w);const L=_.dot(l[v])<0?-1:1;a.setXYZW(v,E.x,E.y,E.z,L)}for(let v=0,w=M.length;v<w;++v){const I=M[v],L=I.start,C=I.count;for(let O=L,N=L+C;O<N;O+=3)S(e.getX(O+0)),S(e.getX(O+1)),S(e.getX(O+2))}this._transformed=!0}computeVertexNormals(){const e=this.index,t=this.getAttribute("position");if(t!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==t.count)i=new Dn(new Float32Array(t.count*3),3),this.setAttribute("normal",i);else for(let h=0,d=i.count;h<d;h++)i.setXYZ(h,0,0,0);const s=new B,r=new B,a=new B,o=new B,l=new B,c=new B,u=new B,f=new B;if(e)for(let h=0,d=e.count;h<d;h+=3){const p=e.getX(h+0),x=e.getX(h+1),m=e.getX(h+2);s.fromBufferAttribute(t,p),r.fromBufferAttribute(t,x),a.fromBufferAttribute(t,m),u.subVectors(a,r),f.subVectors(s,r),u.cross(f),o.fromBufferAttribute(i,p),l.fromBufferAttribute(i,x),c.fromBufferAttribute(i,m),o.add(u),l.add(u),c.add(u),i.setXYZ(p,o.x,o.y,o.z),i.setXYZ(x,l.x,l.y,l.z),i.setXYZ(m,c.x,c.y,c.z)}else for(let h=0,d=t.count;h<d;h+=3)s.fromBufferAttribute(t,h+0),r.fromBufferAttribute(t,h+1),a.fromBufferAttribute(t,h+2),u.subVectors(a,r),f.subVectors(s,r),u.cross(f),i.setXYZ(h+0,u.x,u.y,u.z),i.setXYZ(h+1,u.x,u.y,u.z),i.setXYZ(h+2,u.x,u.y,u.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const e=this.attributes.normal;for(let t=0,i=e.count;t<i;t++)Ht.fromBufferAttribute(e,t),Ht.normalize(),e.setXYZ(t,Ht.x,Ht.y,Ht.z)}toNonIndexed(){function e(o,l){const c=o.array,u=o.itemSize,f=o.normalized,h=new c.constructor(l.length*u);let d=0,p=0;for(let x=0,m=l.length;x<m;x++){o.isInterleavedBufferAttribute?d=l[x]*o.data.stride+o.offset:d=l[x]*u;for(let g=0;g<u;g++)h[p++]=c[d++]}return new Dn(h,u,f)}if(this.index===null)return We("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const t=new wt,i=this.index.array,s=this.attributes;for(const o in s){const l=s[o],c=e(l,i);t.setAttribute(o,c)}const r=this.morphAttributes;for(const o in r){const l=[],c=r[o];for(let u=0,f=c.length;u<f;u++){const h=c[u],d=e(h,i);l.push(d)}t.morphAttributes[o]=l}t.morphTargetsRelative=this.morphTargetsRelative;const a=this.groups;for(let o=0,l=a.length;o<l;o++){const c=a[o];t.addGroup(c.start,c.count,c.materialIndex)}return t}toJSON(){const e={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(e.uuid=this.uuid,e.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,this.name!==""&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const l=this.parameters;for(const c in l)l[c]!==void 0&&(e[c]=l[c]);return e}e.data={attributes:{}};const t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const i=this.attributes;for(const l in i){const c=i[l];e.data.attributes[l]=c.toJSON(e.data)}const s={};let r=!1;for(const l in this.morphAttributes){const c=this.morphAttributes[l],u=[];for(let f=0,h=c.length;f<h;f++){const d=c[f];u.push(d.toJSON(e.data))}u.length>0&&(s[l]=u,r=!0)}r&&(e.data.morphAttributes=s,e.data.morphTargetsRelative=this.morphTargetsRelative);const a=this.groups;a.length>0&&(e.data.groups=JSON.parse(JSON.stringify(a)));const o=this.boundingSphere;return o!==null&&(e.data.boundingSphere=o.toJSON()),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const i=e.index;i!==null&&this.setIndex(i.clone());const s=e.attributes;for(const c in s){const u=s[c];this.setAttribute(c,u.clone(t))}const r=e.morphAttributes;for(const c in r){const u=[],f=r[c];for(let h=0,d=f.length;h<d;h++)u.push(f[h].clone(t));this.morphAttributes[c]=u}this.morphTargetsRelative=e.morphTargetsRelative;const a=e.groups;for(let c=0,u=a.length;c<u;c++){const f=a[c];this.addGroup(f.start,f.count,f.materialIndex)}const o=e.boundingBox;o!==null&&(this.boundingBox=o.clone());const l=e.boundingSphere;return l!==null&&(this.boundingSphere=l.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this._transformed=e._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Km{constructor(e,t){this.isInterleavedBuffer=!0,this.array=e,this.stride=t,this.count=e!==void 0?e.length/t:0,this.usage=cc,this.updateRanges=[],this.version=0,this.uuid=fi()}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.array=new e.array.constructor(e.array),this.count=e.count,this.stride=e.stride,this.usage=e.usage,this}copyAt(e,t,i){e*=this.stride,i*=t.stride;for(let s=0,r=this.stride;s<r;s++)this.array[e+s]=t.array[i+s];return this}set(e,t=0){return this.array.set(e,t),this}clone(e){e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=fi()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const t=new this.array.constructor(e.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(t,this.stride);return i.setUsage(this.usage),i}onUpload(e){return this.onUploadCallback=e,this}toJSON(e){return e.arrayBuffers===void 0&&(e.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=fi()),e.arrayBuffers[this.array.buffer._uuid]===void 0&&(e.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const tn=new B;class Ja{constructor(e,t,i,s=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=e,this.itemSize=t,this.offset=i,this.normalized=s}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(e){this.data.needsUpdate=e}applyMatrix4(e){for(let t=0,i=this.data.count;t<i;t++)tn.fromBufferAttribute(this,t),tn.applyMatrix4(e),this.setXYZ(t,tn.x,tn.y,tn.z);return this}applyNormalMatrix(e){for(let t=0,i=this.count;t<i;t++)tn.fromBufferAttribute(this,t),tn.applyNormalMatrix(e),this.setXYZ(t,tn.x,tn.y,tn.z);return this}transformDirection(e){for(let t=0,i=this.count;t<i;t++)tn.fromBufferAttribute(this,t),tn.transformDirection(e),this.setXYZ(t,tn.x,tn.y,tn.z);return this}getComponent(e,t){let i=this.array[e*this.data.stride+this.offset+t];return this.normalized&&(i=qn(i,this.array)),i}setComponent(e,t,i){return this.normalized&&(i=gt(i,this.array)),this.data.array[e*this.data.stride+this.offset+t]=i,this}setX(e,t){return this.normalized&&(t=gt(t,this.array)),this.data.array[e*this.data.stride+this.offset]=t,this}setY(e,t){return this.normalized&&(t=gt(t,this.array)),this.data.array[e*this.data.stride+this.offset+1]=t,this}setZ(e,t){return this.normalized&&(t=gt(t,this.array)),this.data.array[e*this.data.stride+this.offset+2]=t,this}setW(e,t){return this.normalized&&(t=gt(t,this.array)),this.data.array[e*this.data.stride+this.offset+3]=t,this}getX(e){let t=this.data.array[e*this.data.stride+this.offset];return this.normalized&&(t=qn(t,this.array)),t}getY(e){let t=this.data.array[e*this.data.stride+this.offset+1];return this.normalized&&(t=qn(t,this.array)),t}getZ(e){let t=this.data.array[e*this.data.stride+this.offset+2];return this.normalized&&(t=qn(t,this.array)),t}getW(e){let t=this.data.array[e*this.data.stride+this.offset+3];return this.normalized&&(t=qn(t,this.array)),t}setXY(e,t,i){return e=e*this.data.stride+this.offset,this.normalized&&(t=gt(t,this.array),i=gt(i,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this}setXYZ(e,t,i,s){return e=e*this.data.stride+this.offset,this.normalized&&(t=gt(t,this.array),i=gt(i,this.array),s=gt(s,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=s,this}setXYZW(e,t,i,s,r){return e=e*this.data.stride+this.offset,this.normalized&&(t=gt(t,this.array),i=gt(i,this.array),s=gt(s,this.array),r=gt(r,this.array)),this.data.array[e+0]=t,this.data.array[e+1]=i,this.data.array[e+2]=s,this.data.array[e+3]=r,this}clone(e){if(e===void 0){Ka("InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const s=i*this.data.stride+this.offset;for(let r=0;r<this.itemSize;r++)t.push(this.data.array[s+r])}return new Dn(new this.array.constructor(t),this.itemSize,this.normalized)}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.clone(e)),new Ja(e.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(e){if(e===void 0){Ka("InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let i=0;i<this.count;i++){const s=i*this.data.stride+this.offset;for(let r=0;r<this.itemSize;r++)t.push(this.data.array[s+r])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}else return e.interleavedBuffers===void 0&&(e.interleavedBuffers={}),e.interleavedBuffers[this.data.uuid]===void 0&&(e.interleavedBuffers[this.data.uuid]=this.data.toJSON(e)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}let Jm=0;class js extends zi{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:Jm++}),this.uuid=fi(),this.name="",this.type="Material",this.blending=ks,this.side=Ni,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=Sl,this.blendDst=Ml,this.blendEquation=$i,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new et(0,0,0),this.blendAlpha=0,this.depthFunc=Gs,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=xu,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=ms,this.stencilZFail=ms,this.stencilZPass=ms,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const t in e){const i=e[t];if(i===void 0){We(`Material: parameter '${t}' has value of undefined.`);continue}const s=this[t];if(s===void 0){We(`Material: '${t}' is not a property of THREE.${this.type}.`);continue}s&&s.isColor?s.set(i):s&&s.isVector2&&i&&i.isVector2||s&&s.isEuler&&i&&i.isEuler||s&&s.isVector3&&i&&i.isVector3?s.copy(i):this[t]=i}}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});const i={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),this.roughness!==void 0&&(i.roughness=this.roughness),this.metalness!==void 0&&(i.metalness=this.metalness),this.sheen!==void 0&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(i.shininess=this.shininess),this.clearcoat!==void 0&&(i.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(i.sheenColorMap=this.sheenColorMap.toJSON(e).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(i.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(e).uuid),this.dispersion!==void 0&&(i.dispersion=this.dispersion),this.iridescence!==void 0&&(i.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(i.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(i.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(e).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(e).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(e).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(e).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(e).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(i.combine=this.combine)),this.envMapRotation!==void 0&&(i.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(i.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(i.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(i.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(i.size=this.size),this.shadowSide!==null&&(i.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==ks&&(i.blending=this.blending),this.side!==Ni&&(i.side=this.side),this.vertexColors===!0&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),this.transparent===!0&&(i.transparent=!0),this.blendSrc!==Sl&&(i.blendSrc=this.blendSrc),this.blendDst!==Ml&&(i.blendDst=this.blendDst),this.blendEquation!==$i&&(i.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(i.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(i.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(i.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(i.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(i.blendAlpha=this.blendAlpha),this.depthFunc!==Gs&&(i.depthFunc=this.depthFunc),this.depthTest===!1&&(i.depthTest=this.depthTest),this.depthWrite===!1&&(i.depthWrite=this.depthWrite),this.colorWrite===!1&&(i.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(i.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==xu&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==ms&&(i.stencilFail=this.stencilFail),this.stencilZFail!==ms&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==ms&&(i.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(i.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(i.rotation=this.rotation),this.polygonOffset===!0&&(i.polygonOffset=!0),this.polygonOffsetFactor!==0&&(i.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(i.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(i.linewidth=this.linewidth),this.dashSize!==void 0&&(i.dashSize=this.dashSize),this.gapSize!==void 0&&(i.gapSize=this.gapSize),this.scale!==void 0&&(i.scale=this.scale),this.dithering===!0&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),this.alphaHash===!0&&(i.alphaHash=!0),this.alphaToCoverage===!0&&(i.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(i.premultipliedAlpha=!0),this.forceSinglePass===!0&&(i.forceSinglePass=!0),this.allowOverride===!1&&(i.allowOverride=!1),this.wireframe===!0&&(i.wireframe=!0),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(i.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(i.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(i.flatShading=!0),this.visible===!1&&(i.visible=!1),this.toneMapped===!1&&(i.toneMapped=!1),this.fog===!1&&(i.fog=!1),Object.keys(this.userData).length>0&&(i.userData=this.userData);function s(r){const a=[];for(const o in r){const l=r[o];delete l.metadata,a.push(l)}return a}if(t){const r=s(e.textures),a=s(e.images);r.length>0&&(i.textures=r),a.length>0&&(i.images=a)}return i}fromJSON(e,t){if(e.uuid!==void 0&&(this.uuid=e.uuid),e.name!==void 0&&(this.name=e.name),e.color!==void 0&&this.color!==void 0&&this.color.setHex(e.color),e.roughness!==void 0&&(this.roughness=e.roughness),e.metalness!==void 0&&(this.metalness=e.metalness),e.sheen!==void 0&&(this.sheen=e.sheen),e.sheenColor!==void 0&&(this.sheenColor=new et().setHex(e.sheenColor)),e.sheenRoughness!==void 0&&(this.sheenRoughness=e.sheenRoughness),e.emissive!==void 0&&this.emissive!==void 0&&this.emissive.setHex(e.emissive),e.specular!==void 0&&this.specular!==void 0&&this.specular.setHex(e.specular),e.specularIntensity!==void 0&&(this.specularIntensity=e.specularIntensity),e.specularColor!==void 0&&this.specularColor!==void 0&&this.specularColor.setHex(e.specularColor),e.shininess!==void 0&&(this.shininess=e.shininess),e.clearcoat!==void 0&&(this.clearcoat=e.clearcoat),e.clearcoatRoughness!==void 0&&(this.clearcoatRoughness=e.clearcoatRoughness),e.dispersion!==void 0&&(this.dispersion=e.dispersion),e.iridescence!==void 0&&(this.iridescence=e.iridescence),e.iridescenceIOR!==void 0&&(this.iridescenceIOR=e.iridescenceIOR),e.iridescenceThicknessRange!==void 0&&(this.iridescenceThicknessRange=e.iridescenceThicknessRange),e.transmission!==void 0&&(this.transmission=e.transmission),e.thickness!==void 0&&(this.thickness=e.thickness),e.attenuationDistance!==void 0&&(this.attenuationDistance=e.attenuationDistance),e.attenuationColor!==void 0&&this.attenuationColor!==void 0&&this.attenuationColor.setHex(e.attenuationColor),e.anisotropy!==void 0&&(this.anisotropy=e.anisotropy),e.anisotropyRotation!==void 0&&(this.anisotropyRotation=e.anisotropyRotation),e.fog!==void 0&&(this.fog=e.fog),e.flatShading!==void 0&&(this.flatShading=e.flatShading),e.blending!==void 0&&(this.blending=e.blending),e.combine!==void 0&&(this.combine=e.combine),e.side!==void 0&&(this.side=e.side),e.shadowSide!==void 0&&(this.shadowSide=e.shadowSide),e.opacity!==void 0&&(this.opacity=e.opacity),e.transparent!==void 0&&(this.transparent=e.transparent),e.alphaTest!==void 0&&(this.alphaTest=e.alphaTest),e.alphaHash!==void 0&&(this.alphaHash=e.alphaHash),e.depthFunc!==void 0&&(this.depthFunc=e.depthFunc),e.depthTest!==void 0&&(this.depthTest=e.depthTest),e.depthWrite!==void 0&&(this.depthWrite=e.depthWrite),e.colorWrite!==void 0&&(this.colorWrite=e.colorWrite),e.blendSrc!==void 0&&(this.blendSrc=e.blendSrc),e.blendDst!==void 0&&(this.blendDst=e.blendDst),e.blendEquation!==void 0&&(this.blendEquation=e.blendEquation),e.blendSrcAlpha!==void 0&&(this.blendSrcAlpha=e.blendSrcAlpha),e.blendDstAlpha!==void 0&&(this.blendDstAlpha=e.blendDstAlpha),e.blendEquationAlpha!==void 0&&(this.blendEquationAlpha=e.blendEquationAlpha),e.blendColor!==void 0&&this.blendColor!==void 0&&this.blendColor.setHex(e.blendColor),e.blendAlpha!==void 0&&(this.blendAlpha=e.blendAlpha),e.stencilWriteMask!==void 0&&(this.stencilWriteMask=e.stencilWriteMask),e.stencilFunc!==void 0&&(this.stencilFunc=e.stencilFunc),e.stencilRef!==void 0&&(this.stencilRef=e.stencilRef),e.stencilFuncMask!==void 0&&(this.stencilFuncMask=e.stencilFuncMask),e.stencilFail!==void 0&&(this.stencilFail=e.stencilFail),e.stencilZFail!==void 0&&(this.stencilZFail=e.stencilZFail),e.stencilZPass!==void 0&&(this.stencilZPass=e.stencilZPass),e.stencilWrite!==void 0&&(this.stencilWrite=e.stencilWrite),e.wireframe!==void 0&&(this.wireframe=e.wireframe),e.wireframeLinewidth!==void 0&&(this.wireframeLinewidth=e.wireframeLinewidth),e.wireframeLinecap!==void 0&&(this.wireframeLinecap=e.wireframeLinecap),e.wireframeLinejoin!==void 0&&(this.wireframeLinejoin=e.wireframeLinejoin),e.rotation!==void 0&&(this.rotation=e.rotation),e.linewidth!==void 0&&(this.linewidth=e.linewidth),e.dashSize!==void 0&&(this.dashSize=e.dashSize),e.gapSize!==void 0&&(this.gapSize=e.gapSize),e.scale!==void 0&&(this.scale=e.scale),e.polygonOffset!==void 0&&(this.polygonOffset=e.polygonOffset),e.polygonOffsetFactor!==void 0&&(this.polygonOffsetFactor=e.polygonOffsetFactor),e.polygonOffsetUnits!==void 0&&(this.polygonOffsetUnits=e.polygonOffsetUnits),e.dithering!==void 0&&(this.dithering=e.dithering),e.alphaToCoverage!==void 0&&(this.alphaToCoverage=e.alphaToCoverage),e.premultipliedAlpha!==void 0&&(this.premultipliedAlpha=e.premultipliedAlpha),e.forceSinglePass!==void 0&&(this.forceSinglePass=e.forceSinglePass),e.allowOverride!==void 0&&(this.allowOverride=e.allowOverride),e.visible!==void 0&&(this.visible=e.visible),e.toneMapped!==void 0&&(this.toneMapped=e.toneMapped),e.userData!==void 0&&(this.userData=e.userData),e.vertexColors!==void 0&&(typeof e.vertexColors=="number"?this.vertexColors=e.vertexColors>0:this.vertexColors=e.vertexColors),e.size!==void 0&&(this.size=e.size),e.sizeAttenuation!==void 0&&(this.sizeAttenuation=e.sizeAttenuation),e.map!==void 0&&(this.map=t[e.map]||null),e.matcap!==void 0&&(this.matcap=t[e.matcap]||null),e.alphaMap!==void 0&&(this.alphaMap=t[e.alphaMap]||null),e.bumpMap!==void 0&&(this.bumpMap=t[e.bumpMap]||null),e.bumpScale!==void 0&&(this.bumpScale=e.bumpScale),e.normalMap!==void 0&&(this.normalMap=t[e.normalMap]||null),e.normalMapType!==void 0&&(this.normalMapType=e.normalMapType),e.normalScale!==void 0){let i=e.normalScale;Array.isArray(i)===!1&&(i=[i,i]),this.normalScale=new Ee().fromArray(i)}return e.displacementMap!==void 0&&(this.displacementMap=t[e.displacementMap]||null),e.displacementScale!==void 0&&(this.displacementScale=e.displacementScale),e.displacementBias!==void 0&&(this.displacementBias=e.displacementBias),e.roughnessMap!==void 0&&(this.roughnessMap=t[e.roughnessMap]||null),e.metalnessMap!==void 0&&(this.metalnessMap=t[e.metalnessMap]||null),e.emissiveMap!==void 0&&(this.emissiveMap=t[e.emissiveMap]||null),e.emissiveIntensity!==void 0&&(this.emissiveIntensity=e.emissiveIntensity),e.specularMap!==void 0&&(this.specularMap=t[e.specularMap]||null),e.specularIntensityMap!==void 0&&(this.specularIntensityMap=t[e.specularIntensityMap]||null),e.specularColorMap!==void 0&&(this.specularColorMap=t[e.specularColorMap]||null),e.envMap!==void 0&&(this.envMap=t[e.envMap]||null),e.envMapRotation!==void 0&&this.envMapRotation.fromArray(e.envMapRotation),e.envMapIntensity!==void 0&&(this.envMapIntensity=e.envMapIntensity),e.reflectivity!==void 0&&(this.reflectivity=e.reflectivity),e.refractionRatio!==void 0&&(this.refractionRatio=e.refractionRatio),e.lightMap!==void 0&&(this.lightMap=t[e.lightMap]||null),e.lightMapIntensity!==void 0&&(this.lightMapIntensity=e.lightMapIntensity),e.aoMap!==void 0&&(this.aoMap=t[e.aoMap]||null),e.aoMapIntensity!==void 0&&(this.aoMapIntensity=e.aoMapIntensity),e.gradientMap!==void 0&&(this.gradientMap=t[e.gradientMap]||null),e.clearcoatMap!==void 0&&(this.clearcoatMap=t[e.clearcoatMap]||null),e.clearcoatRoughnessMap!==void 0&&(this.clearcoatRoughnessMap=t[e.clearcoatRoughnessMap]||null),e.clearcoatNormalMap!==void 0&&(this.clearcoatNormalMap=t[e.clearcoatNormalMap]||null),e.clearcoatNormalScale!==void 0&&(this.clearcoatNormalScale=new Ee().fromArray(e.clearcoatNormalScale)),e.iridescenceMap!==void 0&&(this.iridescenceMap=t[e.iridescenceMap]||null),e.iridescenceThicknessMap!==void 0&&(this.iridescenceThicknessMap=t[e.iridescenceThicknessMap]||null),e.transmissionMap!==void 0&&(this.transmissionMap=t[e.transmissionMap]||null),e.thicknessMap!==void 0&&(this.thicknessMap=t[e.thicknessMap]||null),e.anisotropyMap!==void 0&&(this.anisotropyMap=t[e.anisotropyMap]||null),e.sheenColorMap!==void 0&&(this.sheenColorMap=t[e.sheenColorMap]||null),e.sheenRoughnessMap!==void 0&&(this.sheenRoughnessMap=t[e.sheenRoughnessMap]||null),this}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let i=null;if(t!==null){const s=t.length;i=new Array(s);for(let r=0;r!==s;++r)i[r]=t[r].clone()}return this.clippingPlanes=i,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.allowOverride=e.allowOverride,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}}class fc extends js{constructor(e){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new et(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}}let As;const or=new B,ws=new B,Cs=new B,Rs=new Ee,lr=new Ee,ed=new Tt,jr=new B,cr=new B,Qr=new B,Pu=new Ee,Wo=new Ee,Lu=new Ee;class Du extends sn{constructor(e=new fc){if(super(),this.isSprite=!0,this.type="Sprite",As===void 0){As=new wt;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new Km(t,5);As.setIndex([0,1,2,0,2,3]),As.setAttribute("position",new Ja(i,3,0,!1)),As.setAttribute("uv",new Ja(i,2,3,!1))}this.geometry=As,this.material=e,this.center=new Ee(.5,.5),this.count=1}raycast(e,t){e.camera===null&&st('Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),ws.setFromMatrixScale(this.matrixWorld),ed.copy(e.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(e.camera.matrixWorldInverse,this.matrixWorld),Cs.setFromMatrixPosition(this.modelViewMatrix),e.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&ws.multiplyScalar(-Cs.z);const i=this.material.rotation;let s,r;i!==0&&(r=Math.cos(i),s=Math.sin(i));const a=this.center;ea(jr.set(-.5,-.5,0),Cs,a,ws,s,r),ea(cr.set(.5,-.5,0),Cs,a,ws,s,r),ea(Qr.set(.5,.5,0),Cs,a,ws,s,r),Pu.set(0,0),Wo.set(1,0),Lu.set(1,1);let o=e.ray.intersectTriangle(jr,cr,Qr,!1,or);if(o===null&&(ea(cr.set(-.5,.5,0),Cs,a,ws,s,r),Wo.set(0,1),o=e.ray.intersectTriangle(jr,Qr,cr,!1,or),o===null))return;const l=e.ray.origin.distanceTo(or);l<e.near||l>e.far||t.push({distance:l,point:or.clone(),uv:Mn.getInterpolation(or,jr,cr,Qr,Pu,Wo,Lu,new Ee),face:null,object:this})}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}}function ea(n,e,t,i,s,r){Rs.subVectors(n,t).addScalar(.5).multiply(i),s!==void 0?(lr.x=r*Rs.x-s*Rs.y,lr.y=s*Rs.x+r*Rs.y):lr.copy(Rs),n.copy(e),n.x+=lr.x,n.y+=lr.y,n.applyMatrix4(ed)}const ai=new B,Xo=new B,ta=new B,Ti=new B,Yo=new B,na=new B,qo=new B;class kc{constructor(e=new B,t=new B(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,ai)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const i=t.dot(this.direction);return i<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=ai.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(ai.copy(this.origin).addScaledVector(this.direction,t),ai.distanceToSquared(e))}distanceSqToSegment(e,t,i,s){Xo.copy(e).add(t).multiplyScalar(.5),ta.copy(t).sub(e).normalize(),Ti.copy(this.origin).sub(Xo);const r=e.distanceTo(t)*.5,a=-this.direction.dot(ta),o=Ti.dot(this.direction),l=-Ti.dot(ta),c=Ti.lengthSq(),u=Math.abs(1-a*a);let f,h,d,p;if(u>0)if(f=a*l-o,h=a*o-l,p=r*u,f>=0)if(h>=-p)if(h<=p){const x=1/u;f*=x,h*=x,d=f*(f+a*h+2*o)+h*(a*f+h+2*l)+c}else h=r,f=Math.max(0,-(a*h+o)),d=-f*f+h*(h+2*l)+c;else h=-r,f=Math.max(0,-(a*h+o)),d=-f*f+h*(h+2*l)+c;else h<=-p?(f=Math.max(0,-(-a*r+o)),h=f>0?-r:Math.min(Math.max(-r,-l),r),d=-f*f+h*(h+2*l)+c):h<=p?(f=0,h=Math.min(Math.max(-r,-l),r),d=h*(h+2*l)+c):(f=Math.max(0,-(a*r+o)),h=f>0?r:Math.min(Math.max(-r,-l),r),d=-f*f+h*(h+2*l)+c);else h=a>0?-r:r,f=Math.max(0,-(a*h+o)),d=-f*f+h*(h+2*l)+c;return i&&i.copy(this.origin).addScaledVector(this.direction,f),s&&s.copy(Xo).addScaledVector(ta,h),d}intersectSphere(e,t){ai.subVectors(e.center,this.origin);const i=ai.dot(this.direction),s=ai.dot(ai)-i*i,r=e.radius*e.radius;if(s>r)return null;const a=Math.sqrt(r-s),o=i-a,l=i+a;return l<0?null:o<0?this.at(l,t):this.at(o,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(e.normal)+e.constant)/t;return i>=0?i:null}intersectPlane(e,t){const i=this.distanceToPlane(e);return i===null?null:this.at(i,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let i,s,r,a,o,l;const c=1/this.direction.x,u=1/this.direction.y,f=1/this.direction.z,h=this.origin;return c>=0?(i=(e.min.x-h.x)*c,s=(e.max.x-h.x)*c):(i=(e.max.x-h.x)*c,s=(e.min.x-h.x)*c),u>=0?(r=(e.min.y-h.y)*u,a=(e.max.y-h.y)*u):(r=(e.max.y-h.y)*u,a=(e.min.y-h.y)*u),i>a||r>s||((r>i||isNaN(i))&&(i=r),(a<s||isNaN(s))&&(s=a),f>=0?(o=(e.min.z-h.z)*f,l=(e.max.z-h.z)*f):(o=(e.max.z-h.z)*f,l=(e.min.z-h.z)*f),i>l||o>s)||((o>i||i!==i)&&(i=o),(l<s||s!==s)&&(s=l),s<0)?null:this.at(i>=0?i:s,t)}intersectsBox(e){return this.intersectBox(e,ai)!==null}intersectTriangle(e,t,i,s,r){Yo.subVectors(t,e),na.subVectors(i,e),qo.crossVectors(Yo,na);let a=this.direction.dot(qo),o;if(a>0){if(s)return null;o=1}else if(a<0)o=-1,a=-a;else return null;Ti.subVectors(this.origin,e);const l=o*this.direction.dot(na.crossVectors(Ti,na));if(l<0)return null;const c=o*this.direction.dot(Yo.cross(Ti));if(c<0||l+c>a)return null;const u=-o*Ti.dot(qo);return u<0?null:this.at(u/a,r)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class Vn extends js{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new et(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new ns,this.combine=Df,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const Iu=new Tt,Wi=new kc,ia=new go,Uu=new B,sa=new B,ra=new B,aa=new B,$o=new B,oa=new B,Ou=new B,la=new B;class Gt extends sn{constructor(e=new wt,t=new Vn){super(),this.isMesh=!0,this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const s=t[i[0]];if(s!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let r=0,a=s.length;r<a;r++){const o=s[r].name||String(r);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=r}}}}getVertexPosition(e,t){const i=this.geometry,s=i.attributes.position,r=i.morphAttributes.position,a=i.morphTargetsRelative;t.fromBufferAttribute(s,e);const o=this.morphTargetInfluences;if(r&&o){oa.set(0,0,0);for(let l=0,c=r.length;l<c;l++){const u=o[l],f=r[l];u!==0&&($o.fromBufferAttribute(f,e),a?oa.addScaledVector($o,u):oa.addScaledVector($o.sub(t),u))}t.add(oa)}return t}raycast(e,t){const i=this.geometry,s=this.material,r=this.matrixWorld;s!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),ia.copy(i.boundingSphere),ia.applyMatrix4(r),Wi.copy(e.ray).recast(e.near),!(ia.containsPoint(Wi.origin)===!1&&(Wi.intersectSphere(ia,Uu)===null||Wi.origin.distanceToSquared(Uu)>(e.far-e.near)**2))&&(Iu.copy(r).invert(),Wi.copy(e.ray).applyMatrix4(Iu),!(i.boundingBox!==null&&Wi.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(e,t,Wi)))}_computeIntersections(e,t,i){let s;const r=this.geometry,a=this.material,o=r.index,l=r.attributes.position,c=r.attributes.uv,u=r.attributes.uv1,f=r.attributes.normal,h=r.groups,d=r.drawRange;if(o!==null)if(Array.isArray(a))for(let p=0,x=h.length;p<x;p++){const m=h[p],g=a[m.materialIndex],M=Math.max(m.start,d.start),E=Math.min(o.count,Math.min(m.start+m.count,d.start+d.count));for(let _=M,T=E;_<T;_+=3){const b=o.getX(_),S=o.getX(_+1),v=o.getX(_+2);s=ca(this,g,e,i,c,u,f,b,S,v),s&&(s.faceIndex=Math.floor(_/3),s.face.materialIndex=m.materialIndex,t.push(s))}}else{const p=Math.max(0,d.start),x=Math.min(o.count,d.start+d.count);for(let m=p,g=x;m<g;m+=3){const M=o.getX(m),E=o.getX(m+1),_=o.getX(m+2);s=ca(this,a,e,i,c,u,f,M,E,_),s&&(s.faceIndex=Math.floor(m/3),t.push(s))}}else if(l!==void 0)if(Array.isArray(a))for(let p=0,x=h.length;p<x;p++){const m=h[p],g=a[m.materialIndex],M=Math.max(m.start,d.start),E=Math.min(l.count,Math.min(m.start+m.count,d.start+d.count));for(let _=M,T=E;_<T;_+=3){const b=_,S=_+1,v=_+2;s=ca(this,g,e,i,c,u,f,b,S,v),s&&(s.faceIndex=Math.floor(_/3),s.face.materialIndex=m.materialIndex,t.push(s))}}else{const p=Math.max(0,d.start),x=Math.min(l.count,d.start+d.count);for(let m=p,g=x;m<g;m+=3){const M=m,E=m+1,_=m+2;s=ca(this,a,e,i,c,u,f,M,E,_),s&&(s.faceIndex=Math.floor(m/3),t.push(s))}}}}function jm(n,e,t,i,s,r,a,o){let l;if(e.side===un?l=i.intersectTriangle(a,r,s,!0,o):l=i.intersectTriangle(s,r,a,e.side===Ni,o),l===null)return null;la.copy(o),la.applyMatrix4(n.matrixWorld);const c=t.ray.origin.distanceTo(la);return c<t.near||c>t.far?null:{distance:c,point:la.clone(),object:n}}function ca(n,e,t,i,s,r,a,o,l,c){n.getVertexPosition(o,sa),n.getVertexPosition(l,ra),n.getVertexPosition(c,aa);const u=jm(n,e,t,i,sa,ra,aa,Ou);if(u){const f=new B;Mn.getBarycoord(Ou,sa,ra,aa,f),s&&(u.uv=Mn.getInterpolatedAttribute(s,o,l,c,f,new Ee)),r&&(u.uv1=Mn.getInterpolatedAttribute(r,o,l,c,f,new Ee)),a&&(u.normal=Mn.getInterpolatedAttribute(a,o,l,c,f,new B),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const h={a:o,b:l,c,normal:new B,materialIndex:0};Mn.getNormal(sa,ra,aa,h.normal),u.face=h,u.barycoord=f}return u}class td extends Qt{constructor(e=null,t=1,i=1,s,r,a,o,l,c=Ft,u=Ft,f,h){super(null,a,o,l,c,u,s,r,f,h),this.isDataTexture=!0,this.image={data:e,width:t,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Zo=new B,Qm=new B,eg=new $e;class Ri{constructor(e=new B(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,i,s){return this.normal.set(e,t,i),this.constant=s,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,i){const s=Zo.subVectors(i,t).cross(Qm.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(s,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t,i=!0){const s=e.delta(Zo),r=this.normal.dot(s);if(r===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;const a=-(e.start.dot(this.normal)+this.constant)/r;return i===!0&&(a<0||a>1)?null:t.copy(e.start).addScaledVector(s,a)}intersectsLine(e){const t=this.distanceToPoint(e.start),i=this.distanceToPoint(e.end);return t<0&&i>0||i<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const i=t||eg.getNormalMatrix(e),s=this.coplanarPoint(Zo).applyMatrix4(e),r=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(r),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}}const Xi=new go,tg=new Ee(.5,.5),ua=new B;class nd{constructor(e=new Ri,t=new Ri,i=new Ri,s=new Ri,r=new Ri,a=new Ri){this.planes=[e,t,i,s,r,a]}set(e,t,i,s,r,a){const o=this.planes;return o[0].copy(e),o[1].copy(t),o[2].copy(i),o[3].copy(s),o[4].copy(r),o[5].copy(a),this}copy(e){const t=this.planes;for(let i=0;i<6;i++)t[i].copy(e.planes[i]);return this}setFromProjectionMatrix(e,t=$n,i=!1){const s=this.planes,r=e.elements,a=r[0],o=r[1],l=r[2],c=r[3],u=r[4],f=r[5],h=r[6],d=r[7],p=r[8],x=r[9],m=r[10],g=r[11],M=r[12],E=r[13],_=r[14],T=r[15];if(s[0].setComponents(c-a,d-u,g-p,T-M).normalize(),s[1].setComponents(c+a,d+u,g+p,T+M).normalize(),s[2].setComponents(c+o,d+f,g+x,T+E).normalize(),s[3].setComponents(c-o,d-f,g-x,T-E).normalize(),i)s[4].setComponents(l,h,m,_).normalize(),s[5].setComponents(c-l,d-h,g-m,T-_).normalize();else if(s[4].setComponents(c-l,d-h,g-m,T-_).normalize(),t===$n)s[5].setComponents(c+l,d+h,g+m,T+_).normalize();else if(t===$a)s[5].setComponents(l,h,m,_).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),Xi.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),Xi.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(Xi)}intersectsSprite(e){Xi.center.set(0,0,0);const t=tg.distanceTo(e.center);return Xi.radius=.7071067811865476+t,Xi.applyMatrix4(e.matrixWorld),this.intersectsSphere(Xi)}intersectsSphere(e){const t=this.planes,i=e.center,s=-e.radius;for(let r=0;r<6;r++)if(t[r].distanceToPoint(i)<s)return!1;return!0}intersectsBox(e){const t=this.planes;for(let i=0;i<6;i++){const s=t[i];if(ua.x=s.normal.x>0?e.max.x:e.min.x,ua.y=s.normal.y>0?e.max.y:e.min.y,ua.z=s.normal.z>0?e.max.z:e.min.z,s.distanceToPoint(ua)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let i=0;i<6;i++)if(t[i].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}class Ns extends js{constructor(e){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new et(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}}const ja=new B,Qa=new B,Fu=new Tt,ur=new kc,ha=new go,Ko=new B,Nu=new B;let id=class extends sn{constructor(e=new wt,t=new Ns){super(),this.isLine=!0,this.type="Line",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[0];for(let s=1,r=t.count;s<r;s++)ja.fromBufferAttribute(t,s-1),Qa.fromBufferAttribute(t,s),i[s]=i[s-1],i[s]+=ja.distanceTo(Qa);e.setAttribute("lineDistance",new ht(i,1))}else We("Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(e,t){const i=this.geometry,s=this.matrixWorld,r=e.params.Line.threshold,a=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),ha.copy(i.boundingSphere),ha.applyMatrix4(s),ha.radius+=r,e.ray.intersectsSphere(ha)===!1)return;Fu.copy(s).invert(),ur.copy(e.ray).applyMatrix4(Fu);const o=r/((this.scale.x+this.scale.y+this.scale.z)/3),l=o*o,c=this.isLineSegments?2:1,u=i.index,h=i.attributes.position;if(u!==null){const d=Math.max(0,a.start),p=Math.min(u.count,a.start+a.count);for(let x=d,m=p-1;x<m;x+=c){const g=u.getX(x),M=u.getX(x+1),E=fa(this,e,ur,l,g,M,x);E&&t.push(E)}if(this.isLineLoop){const x=u.getX(p-1),m=u.getX(d),g=fa(this,e,ur,l,x,m,p-1);g&&t.push(g)}}else{const d=Math.max(0,a.start),p=Math.min(h.count,a.start+a.count);for(let x=d,m=p-1;x<m;x+=c){const g=fa(this,e,ur,l,x,x+1,x);g&&t.push(g)}if(this.isLineLoop){const x=fa(this,e,ur,l,p-1,d,p-1);x&&t.push(x)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,i=Object.keys(t);if(i.length>0){const s=t[i[0]];if(s!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let r=0,a=s.length;r<a;r++){const o=s[r].name||String(r);this.morphTargetInfluences.push(0),this.morphTargetDictionary[o]=r}}}}};function fa(n,e,t,i,s,r,a){const o=n.geometry.attributes.position;if(ja.fromBufferAttribute(o,s),Qa.fromBufferAttribute(o,r),t.distanceSqToSegment(ja,Qa,Ko,Nu)>i)return;Ko.applyMatrix4(n.matrixWorld);const c=e.ray.origin.distanceTo(Ko);if(!(c<e.near||c>e.far))return{distance:c,point:Nu.clone().applyMatrix4(n.matrixWorld),index:a,face:null,faceIndex:null,barycoord:null,object:n}}const ku=new B,Bu=new B;class da extends id{constructor(e,t){super(e,t),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const e=this.geometry;if(e.index===null){const t=e.attributes.position,i=[];for(let s=0,r=t.count;s<r;s+=2)ku.fromBufferAttribute(t,s),Bu.fromBufferAttribute(t,s+1),i[s]=s===0?0:i[s-1],i[s+1]=i[s]+ku.distanceTo(Bu);e.setAttribute("lineDistance",new ht(i,1))}else We("LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class sd extends Qt{constructor(e=[],t=es,i,s,r,a,o,l,c,u){super(e,t,i,s,r,a,o,l,c,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class pa extends Qt{constructor(e,t,i,s,r,a,o,l,c){super(e,t,i,s,r,a,o,l,c),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Ws extends Qt{constructor(e,t,i=Qn,s,r,a,o=Ft,l=Ft,c,u=gi,f=1){if(u!==gi&&u!==ji)throw new Error("THREE.DepthTexture: format must be either THREE.DepthFormat or THREE.DepthStencilFormat");const h={width:e,height:t,depth:f};super(h,s,r,a,o,l,u,i,c),this.isDepthTexture=!0,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new Nc(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}toJSON(e){const t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}}class ng extends Ws{constructor(e,t=Qn,i=es,s,r,a=Ft,o=Ft,l,c=gi){const u={width:e,height:e,depth:1},f=[u,u,u,u,u,u];super(e,e,t,i,s,r,a,o,l,c),this.image=f,this.isCubeDepthTexture=!0,this.isCubeTexture=!0}get images(){return this.image}set images(e){this.image=e}}class rd extends Qt{constructor(e=null){super(),this.sourceTexture=e,this.isExternalTexture=!0}copy(e){return super.copy(e),this.sourceTexture=e.sourceTexture,this}}class Ur extends wt{constructor(e=1,t=1,i=1,s=1,r=1,a=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:i,widthSegments:s,heightSegments:r,depthSegments:a};const o=this;s=Math.floor(s),r=Math.floor(r),a=Math.floor(a);const l=[],c=[],u=[],f=[];let h=0,d=0;p("z","y","x",-1,-1,i,t,e,a,r,0),p("z","y","x",1,-1,i,t,-e,a,r,1),p("x","z","y",1,1,e,i,t,s,a,2),p("x","z","y",1,-1,e,i,-t,s,a,3),p("x","y","z",1,-1,e,t,i,s,r,4),p("x","y","z",-1,-1,e,t,-i,s,r,5),this.setIndex(l),this.setAttribute("position",new ht(c,3)),this.setAttribute("normal",new ht(u,3)),this.setAttribute("uv",new ht(f,2));function p(x,m,g,M,E,_,T,b,S,v,w){const I=_/S,L=T/v,C=_/2,O=T/2,N=b/2,U=S+1,Z=v+1;let k=0,$=0;const D=new B;for(let ae=0;ae<Z;ae++){const re=ae*L-O;for(let ee=0;ee<U;ee++){const ce=ee*I-C;D[x]=ce*M,D[m]=re*E,D[g]=N,c.push(D.x,D.y,D.z),D[x]=0,D[m]=0,D[g]=b>0?1:-1,u.push(D.x,D.y,D.z),f.push(ee/S),f.push(1-ae/v),k+=1}}for(let ae=0;ae<v;ae++)for(let re=0;re<S;re++){const ee=h+re+U*ae,ce=h+re+U*(ae+1),he=h+(re+1)+U*(ae+1),fe=h+(re+1)+U*ae;l.push(ee,ce,fe),l.push(ce,he,fe),$+=6}o.addGroup(d,$,w),d+=$,h+=k}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Ur(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}}class ei{constructor(){this.type="Curve",this.arcLengthDivisions=200,this.needsUpdate=!1,this.cacheArcLengths=null}getPoint(){We("Curve: .getPoint() not implemented.")}getPointAt(e,t){const i=this.getUtoTmapping(e);return this.getPoint(i,t)}getPoints(e=5){const t=[];for(let i=0;i<=e;i++)t.push(this.getPoint(i/e));return t}getSpacedPoints(e=5){const t=[];for(let i=0;i<=e;i++)t.push(this.getPointAt(i/e));return t}getLength(){const e=this.getLengths();return e[e.length-1]}getLengths(e=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const t=[];let i,s=this.getPoint(0),r=0;t.push(0);for(let a=1;a<=e;a++)i=this.getPoint(a/e),r+=i.distanceTo(s),t.push(r),s=i;return this.cacheArcLengths=t,t}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(e,t=null){const i=this.getLengths();let s=0;const r=i.length;let a;t?a=t:a=e*i[r-1];let o=0,l=r-1,c;for(;o<=l;)if(s=Math.floor(o+(l-o)/2),c=i[s]-a,c<0)o=s+1;else if(c>0)l=s-1;else{l=s;break}if(s=l,i[s]===a)return s/(r-1);const u=i[s],h=i[s+1]-u,d=(a-u)/h;return(s+d)/(r-1)}getTangent(e,t){let s=e-1e-4,r=e+1e-4;s<0&&(s=0),r>1&&(r=1);const a=this.getPoint(s),o=this.getPoint(r),l=t||(a.isVector2?new Ee:new B);return l.copy(o).sub(a).normalize(),l}getTangentAt(e,t){const i=this.getUtoTmapping(e);return this.getTangent(i,t)}computeFrenetFrames(e,t=!1){const i=new B,s=[],r=[],a=[],o=new B,l=new Tt;for(let d=0;d<=e;d++){const p=d/e;s[d]=this.getTangentAt(p,new B)}r[0]=new B,a[0]=new B;let c=Number.MAX_VALUE;const u=Math.abs(s[0].x),f=Math.abs(s[0].y),h=Math.abs(s[0].z);u<=c&&(c=u,i.set(1,0,0)),f<=c&&(c=f,i.set(0,1,0)),h<=c&&i.set(0,0,1),o.crossVectors(s[0],i).normalize(),r[0].crossVectors(s[0],o),a[0].crossVectors(s[0],r[0]);for(let d=1;d<=e;d++){if(r[d]=r[d-1].clone(),a[d]=a[d-1].clone(),o.crossVectors(s[d-1],s[d]),o.length()>Number.EPSILON){o.normalize();const p=Math.acos(Qe(s[d-1].dot(s[d]),-1,1));r[d].applyMatrix4(l.makeRotationAxis(o,p))}a[d].crossVectors(s[d],r[d])}if(t===!0){let d=Math.acos(Qe(r[0].dot(r[e]),-1,1));d/=e,s[0].dot(o.crossVectors(r[0],r[e]))>0&&(d=-d);for(let p=1;p<=e;p++)r[p].applyMatrix4(l.makeRotationAxis(s[p],d*p)),a[p].crossVectors(s[p],r[p])}return{tangents:s,normals:r,binormals:a}}clone(){return new this.constructor().copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}toJSON(){const e={metadata:{version:4.7,type:"Curve",generator:"Curve.toJSON"}};return e.arcLengthDivisions=this.arcLengthDivisions,e.type=this.type,e}fromJSON(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}}class Bc extends ei{constructor(e=0,t=0,i=1,s=1,r=0,a=Math.PI*2,o=!1,l=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=e,this.aY=t,this.xRadius=i,this.yRadius=s,this.aStartAngle=r,this.aEndAngle=a,this.aClockwise=o,this.aRotation=l}getPoint(e,t=new Ee){const i=t,s=Math.PI*2;let r=this.aEndAngle-this.aStartAngle;const a=Math.abs(r)<Number.EPSILON;for(;r<0;)r+=s;for(;r>s;)r-=s;r<Number.EPSILON&&(a?r=0:r=s),this.aClockwise===!0&&!a&&(r===s?r=-s:r=r-s);const o=this.aStartAngle+e*r;let l=this.aX+this.xRadius*Math.cos(o),c=this.aY+this.yRadius*Math.sin(o);if(this.aRotation!==0){const u=Math.cos(this.aRotation),f=Math.sin(this.aRotation),h=l-this.aX,d=c-this.aY;l=h*u-d*f+this.aX,c=h*f+d*u+this.aY}return i.set(l,c)}copy(e){return super.copy(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}toJSON(){const e=super.toJSON();return e.aX=this.aX,e.aY=this.aY,e.xRadius=this.xRadius,e.yRadius=this.yRadius,e.aStartAngle=this.aStartAngle,e.aEndAngle=this.aEndAngle,e.aClockwise=this.aClockwise,e.aRotation=this.aRotation,e}fromJSON(e){return super.fromJSON(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}}class ig extends Bc{constructor(e,t,i,s,r,a){super(e,t,i,i,s,r,a),this.isArcCurve=!0,this.type="ArcCurve"}}function Hc(){let n=0,e=0,t=0,i=0;function s(r,a,o,l){n=r,e=o,t=-3*r+3*a-2*o-l,i=2*r-2*a+o+l}return{initCatmullRom:function(r,a,o,l,c){s(a,o,c*(o-r),c*(l-a))},initNonuniformCatmullRom:function(r,a,o,l,c,u,f){let h=(a-r)/c-(o-r)/(c+u)+(o-a)/u,d=(o-a)/u-(l-a)/(u+f)+(l-o)/f;h*=u,d*=u,s(a,o,h,d)},calc:function(r){const a=r*r,o=a*r;return n+e*r+t*a+i*o}}}const Hu=new B,zu=new B,Jo=new Hc,jo=new Hc,Qo=new Hc;class sg extends ei{constructor(e=[],t=!1,i="centripetal",s=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=e,this.closed=t,this.curveType=i,this.tension=s}getPoint(e,t=new B){const i=t,s=this.points,r=s.length,a=(r-(this.closed?0:1))*e;let o=Math.floor(a),l=a-o;this.closed?o+=o>0?0:(Math.floor(Math.abs(o)/r)+1)*r:l===0&&o===r-1&&(o=r-2,l=1);let c,u;this.closed||o>0?c=s[(o-1)%r]:(zu.subVectors(s[0],s[1]).add(s[0]),c=zu);const f=s[o%r],h=s[(o+1)%r];if(this.closed||o+2<r?u=s[(o+2)%r]:(Hu.subVectors(s[r-1],s[r-2]).add(s[r-1]),u=Hu),this.curveType==="centripetal"||this.curveType==="chordal"){const d=this.curveType==="chordal"?.5:.25;let p=Math.pow(c.distanceToSquared(f),d),x=Math.pow(f.distanceToSquared(h),d),m=Math.pow(h.distanceToSquared(u),d);x<1e-4&&(x=1),p<1e-4&&(p=x),m<1e-4&&(m=x),Jo.initNonuniformCatmullRom(c.x,f.x,h.x,u.x,p,x,m),jo.initNonuniformCatmullRom(c.y,f.y,h.y,u.y,p,x,m),Qo.initNonuniformCatmullRom(c.z,f.z,h.z,u.z,p,x,m)}else this.curveType==="catmullrom"&&(Jo.initCatmullRom(c.x,f.x,h.x,u.x,this.tension),jo.initCatmullRom(c.y,f.y,h.y,u.y,this.tension),Qo.initCatmullRom(c.z,f.z,h.z,u.z,this.tension));return i.set(Jo.calc(l),jo.calc(l),Qo.calc(l)),i}copy(e){super.copy(e),this.points=[];for(let t=0,i=e.points.length;t<i;t++){const s=e.points[t];this.points.push(s.clone())}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}toJSON(){const e=super.toJSON();e.points=[];for(let t=0,i=this.points.length;t<i;t++){const s=this.points[t];e.points.push(s.toArray())}return e.closed=this.closed,e.curveType=this.curveType,e.tension=this.tension,e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,i=e.points.length;t<i;t++){const s=e.points[t];this.points.push(new B().fromArray(s))}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}}function Gu(n,e,t,i,s){const r=(i-e)*.5,a=(s-t)*.5,o=n*n,l=n*o;return(2*t-2*i+r+a)*l+(-3*t+3*i-2*r-a)*o+r*n+t}function rg(n,e){const t=1-n;return t*t*e}function ag(n,e){return 2*(1-n)*n*e}function og(n,e){return n*n*e}function yr(n,e,t,i){return rg(n,e)+ag(n,t)+og(n,i)}function lg(n,e){const t=1-n;return t*t*t*e}function cg(n,e){const t=1-n;return 3*t*t*n*e}function ug(n,e){return 3*(1-n)*n*n*e}function hg(n,e){return n*n*n*e}function _r(n,e,t,i,s){return lg(n,e)+cg(n,t)+ug(n,i)+hg(n,s)}class ad extends ei{constructor(e=new Ee,t=new Ee,i=new Ee,s=new Ee){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=e,this.v1=t,this.v2=i,this.v3=s}getPoint(e,t=new Ee){const i=t,s=this.v0,r=this.v1,a=this.v2,o=this.v3;return i.set(_r(e,s.x,r.x,a.x,o.x),_r(e,s.y,r.y,a.y,o.y)),i}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}}class fg extends ei{constructor(e=new B,t=new B,i=new B,s=new B){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=e,this.v1=t,this.v2=i,this.v3=s}getPoint(e,t=new B){const i=t,s=this.v0,r=this.v1,a=this.v2,o=this.v3;return i.set(_r(e,s.x,r.x,a.x,o.x),_r(e,s.y,r.y,a.y,o.y),_r(e,s.z,r.z,a.z,o.z)),i}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}}class od extends ei{constructor(e=new Ee,t=new Ee){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=e,this.v2=t}getPoint(e,t=new Ee){const i=t;return e===1?i.copy(this.v2):(i.copy(this.v2).sub(this.v1),i.multiplyScalar(e).add(this.v1)),i}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new Ee){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class dg extends ei{constructor(e=new B,t=new B){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=e,this.v2=t}getPoint(e,t=new B){const i=t;return e===1?i.copy(this.v2):(i.copy(this.v2).sub(this.v1),i.multiplyScalar(e).add(this.v1)),i}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new B){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class ld extends ei{constructor(e=new Ee,t=new Ee,i=new Ee){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new Ee){const i=t,s=this.v0,r=this.v1,a=this.v2;return i.set(yr(e,s.x,r.x,a.x),yr(e,s.y,r.y,a.y)),i}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class pg extends ei{constructor(e=new B,t=new B,i=new B){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new B){const i=t,s=this.v0,r=this.v1,a=this.v2;return i.set(yr(e,s.x,r.x,a.x),yr(e,s.y,r.y,a.y),yr(e,s.z,r.z,a.z)),i}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){const e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}}class cd extends ei{constructor(e=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=e}getPoint(e,t=new Ee){const i=t,s=this.points,r=(s.length-1)*e,a=Math.floor(r),o=r-a,l=s[a===0?a:a-1],c=s[a],u=s[a>s.length-2?s.length-1:a+1],f=s[a>s.length-3?s.length-1:a+2];return i.set(Gu(o,l.x,c.x,u.x,f.x),Gu(o,l.y,c.y,u.y,f.y)),i}copy(e){super.copy(e),this.points=[];for(let t=0,i=e.points.length;t<i;t++){const s=e.points[t];this.points.push(s.clone())}return this}toJSON(){const e=super.toJSON();e.points=[];for(let t=0,i=this.points.length;t<i;t++){const s=this.points[t];e.points.push(s.toArray())}return e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,i=e.points.length;t<i;t++){const s=e.points[t];this.points.push(new Ee().fromArray(s))}return this}}var Vu=Object.freeze({__proto__:null,ArcCurve:ig,CatmullRomCurve3:sg,CubicBezierCurve:ad,CubicBezierCurve3:fg,EllipseCurve:Bc,LineCurve:od,LineCurve3:dg,QuadraticBezierCurve:ld,QuadraticBezierCurve3:pg,SplineCurve:cd});class mg extends ei{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(e){this.curves.push(e)}closePath(){const e=this.curves[0].getPoint(0),t=this.curves[this.curves.length-1].getPoint(1);if(!e.equals(t)){const i=e.isVector2===!0?"LineCurve":"LineCurve3";this.curves.push(new Vu[i](t,e))}return this}getPoint(e,t){const i=e*this.getLength(),s=this.getCurveLengths();let r=0;for(;r<s.length;){if(s[r]>=i){const a=s[r]-i,o=this.curves[r],l=o.getLength(),c=l===0?0:1-a/l;return o.getPointAt(c,t)}r++}return null}getLength(){const e=this.getCurveLengths();return e[e.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const e=[];let t=0;for(let i=0,s=this.curves.length;i<s;i++)t+=this.curves[i].getLength(),e.push(t);return this.cacheLengths=e,e}getSpacedPoints(e=40){const t=[];for(let i=0;i<=e;i++)t.push(this.getPoint(i/e));return this.autoClose&&t.push(t[0]),t}getPoints(e=12){const t=[];let i;for(let s=0,r=this.curves;s<r.length;s++){const a=r[s],o=a.isEllipseCurve?e*2:a.isLineCurve||a.isLineCurve3?1:a.isSplineCurve?e*a.points.length:e,l=a.getPoints(o);for(let c=0;c<l.length;c++){const u=l[c];i&&i.equals(u)||(t.push(u),i=u)}}return this.autoClose&&t.length>1&&!t[t.length-1].equals(t[0])&&t.push(t[0]),t}copy(e){super.copy(e),this.curves=[];for(let t=0,i=e.curves.length;t<i;t++){const s=e.curves[t];this.curves.push(s.clone())}return this.autoClose=e.autoClose,this}toJSON(){const e=super.toJSON();e.autoClose=this.autoClose,e.curves=[];for(let t=0,i=this.curves.length;t<i;t++){const s=this.curves[t];e.curves.push(s.toJSON())}return e}fromJSON(e){super.fromJSON(e),this.autoClose=e.autoClose,this.curves=[];for(let t=0,i=e.curves.length;t<i;t++){const s=e.curves[t];this.curves.push(new Vu[s.type]().fromJSON(s))}return this}}let Wu=class extends mg{constructor(e){super(),this.type="Path",this.currentPoint=new Ee,e&&this.setFromPoints(e)}setFromPoints(e){this.moveTo(e[0].x,e[0].y);for(let t=1,i=e.length;t<i;t++)this.lineTo(e[t].x,e[t].y);return this}moveTo(e,t){return this.currentPoint.set(e,t),this}lineTo(e,t){const i=new od(this.currentPoint.clone(),new Ee(e,t));return this.curves.push(i),this.currentPoint.set(e,t),this}quadraticCurveTo(e,t,i,s){const r=new ld(this.currentPoint.clone(),new Ee(e,t),new Ee(i,s));return this.curves.push(r),this.currentPoint.set(i,s),this}bezierCurveTo(e,t,i,s,r,a){const o=new ad(this.currentPoint.clone(),new Ee(e,t),new Ee(i,s),new Ee(r,a));return this.curves.push(o),this.currentPoint.set(r,a),this}splineThru(e){const t=[this.currentPoint.clone()].concat(e),i=new cd(t);return this.curves.push(i),this.currentPoint.copy(e[e.length-1]),this}arc(e,t,i,s,r,a){const o=this.currentPoint.x,l=this.currentPoint.y;return this.absarc(e+o,t+l,i,s,r,a),this}absarc(e,t,i,s,r,a){return this.absellipse(e,t,i,i,s,r,a),this}ellipse(e,t,i,s,r,a,o,l){const c=this.currentPoint.x,u=this.currentPoint.y;return this.absellipse(e+c,t+u,i,s,r,a,o,l),this}absellipse(e,t,i,s,r,a,o,l){const c=new Bc(e,t,i,s,r,a,o,l);if(this.curves.length>0){const f=c.getPoint(0);f.equals(this.currentPoint)||this.lineTo(f.x,f.y)}this.curves.push(c);const u=c.getPoint(1);return this.currentPoint.copy(u),this}copy(e){return super.copy(e),this.currentPoint.copy(e.currentPoint),this}toJSON(){const e=super.toJSON();return e.currentPoint=this.currentPoint.toArray(),e}fromJSON(e){return super.fromJSON(e),this.currentPoint.fromArray(e.currentPoint),this}};class ud extends Wu{constructor(e){super(e),this.uuid=fi(),this.type="Shape",this.holes=[]}getPointsHoles(e){const t=[];for(let i=0,s=this.holes.length;i<s;i++)t[i]=this.holes[i].getPoints(e);return t}extractPoints(e){return{shape:this.getPoints(e),holes:this.getPointsHoles(e)}}copy(e){super.copy(e),this.holes=[];for(let t=0,i=e.holes.length;t<i;t++){const s=e.holes[t];this.holes.push(s.clone())}return this}toJSON(){const e=super.toJSON();e.uuid=this.uuid,e.holes=[];for(let t=0,i=this.holes.length;t<i;t++){const s=this.holes[t];e.holes.push(s.toJSON())}return e}fromJSON(e){super.fromJSON(e),this.uuid=e.uuid,this.holes=[];for(let t=0,i=e.holes.length;t<i;t++){const s=e.holes[t];this.holes.push(new Wu().fromJSON(s))}return this}}function gg(n,e,t=2){const i=e&&e.length,s=i?e[0]*t:n.length;let r=hd(n,0,s,t,!0);const a=[];if(!r||r.next===r.prev)return a;let o,l,c;if(i&&(r=bg(n,e,r,t)),n.length>80*t){o=n[0],l=n[1];let u=o,f=l;for(let h=t;h<s;h+=t){const d=n[h],p=n[h+1];d<o&&(o=d),p<l&&(l=p),d>u&&(u=d),p>f&&(f=p)}c=Math.max(u-o,f-l),c=c!==0?32767/c:0}return wr(r,a,t,o,l,c,0),a}function hd(n,e,t,i,s){let r;if(s===Dg(n,e,t,i)>0)for(let a=e;a<t;a+=i)r=Xu(a/i|0,n[a],n[a+1],r);else for(let a=t-i;a>=e;a-=i)r=Xu(a/i|0,n[a],n[a+1],r);return r&&Xs(r,r.next)&&(Rr(r),r=r.next),r}function is(n,e){if(!n)return n;e||(e=n);let t=n,i;do if(i=!1,!t.steiner&&(Xs(t,t.next)||Et(t.prev,t,t.next)===0)){if(Rr(t),t=e=t.prev,t===t.next)break;i=!0}else t=t.next;while(i||t!==e);return e}function wr(n,e,t,i,s,r,a){if(!n)return;!a&&r&&Ag(n,i,s,r);let o=n;for(;n.prev!==n.next;){const l=n.prev,c=n.next;if(r?vg(n,i,s,r):xg(n)){e.push(l.i,n.i,c.i),Rr(n),n=c.next,o=c.next;continue}if(n=c,n===o){a?a===1?(n=yg(is(n),e),wr(n,e,t,i,s,r,2)):a===2&&_g(n,e,t,i,s,r):wr(is(n),e,t,i,s,r,1);break}}}function xg(n){const e=n.prev,t=n,i=n.next;if(Et(e,t,i)>=0)return!1;const s=e.x,r=t.x,a=i.x,o=e.y,l=t.y,c=i.y,u=Math.min(s,r,a),f=Math.min(o,l,c),h=Math.max(s,r,a),d=Math.max(o,l,c);let p=i.next;for(;p!==e;){if(p.x>=u&&p.x<=h&&p.y>=f&&p.y<=d&&xr(s,o,r,l,a,c,p.x,p.y)&&Et(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function vg(n,e,t,i){const s=n.prev,r=n,a=n.next;if(Et(s,r,a)>=0)return!1;const o=s.x,l=r.x,c=a.x,u=s.y,f=r.y,h=a.y,d=Math.min(o,l,c),p=Math.min(u,f,h),x=Math.max(o,l,c),m=Math.max(u,f,h),g=dc(d,p,e,t,i),M=dc(x,m,e,t,i);let E=n.prevZ,_=n.nextZ;for(;E&&E.z>=g&&_&&_.z<=M;){if(E.x>=d&&E.x<=x&&E.y>=p&&E.y<=m&&E!==s&&E!==a&&xr(o,u,l,f,c,h,E.x,E.y)&&Et(E.prev,E,E.next)>=0||(E=E.prevZ,_.x>=d&&_.x<=x&&_.y>=p&&_.y<=m&&_!==s&&_!==a&&xr(o,u,l,f,c,h,_.x,_.y)&&Et(_.prev,_,_.next)>=0))return!1;_=_.nextZ}for(;E&&E.z>=g;){if(E.x>=d&&E.x<=x&&E.y>=p&&E.y<=m&&E!==s&&E!==a&&xr(o,u,l,f,c,h,E.x,E.y)&&Et(E.prev,E,E.next)>=0)return!1;E=E.prevZ}for(;_&&_.z<=M;){if(_.x>=d&&_.x<=x&&_.y>=p&&_.y<=m&&_!==s&&_!==a&&xr(o,u,l,f,c,h,_.x,_.y)&&Et(_.prev,_,_.next)>=0)return!1;_=_.nextZ}return!0}function yg(n,e){let t=n;do{const i=t.prev,s=t.next.next;!Xs(i,s)&&dd(i,t,t.next,s)&&Cr(i,s)&&Cr(s,i)&&(e.push(i.i,t.i,s.i),Rr(t),Rr(t.next),t=n=s),t=t.next}while(t!==n);return is(t)}function _g(n,e,t,i,s,r){let a=n;do{let o=a.next.next;for(;o!==a.prev;){if(a.i!==o.i&&Rg(a,o)){let l=pd(a,o);a=is(a,a.next),l=is(l,l.next),wr(a,e,t,i,s,r,0),wr(l,e,t,i,s,r,0);return}o=o.next}a=a.next}while(a!==n)}function bg(n,e,t,i){const s=[];for(let r=0,a=e.length;r<a;r++){const o=e[r]*i,l=r<a-1?e[r+1]*i:n.length,c=hd(n,o,l,i,!1);c===c.next&&(c.steiner=!0),s.push(Cg(c))}s.sort(Sg);for(let r=0;r<s.length;r++)t=Mg(s[r],t);return t}function Sg(n,e){let t=n.x-e.x;if(t===0&&(t=n.y-e.y,t===0)){const i=(n.next.y-n.y)/(n.next.x-n.x),s=(e.next.y-e.y)/(e.next.x-e.x);t=i-s}return t}function Mg(n,e){const t=Eg(n,e);if(!t)return e;const i=pd(t,n);return is(i,i.next),is(t,t.next)}function Eg(n,e){let t=e;const i=n.x,s=n.y;let r=-1/0,a;if(Xs(n,t))return t;do{if(Xs(n,t.next))return t.next;if(s<=t.y&&s>=t.next.y&&t.next.y!==t.y){const f=t.x+(s-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(f<=i&&f>r&&(r=f,a=t.x<t.next.x?t:t.next,f===i))return a}t=t.next}while(t!==e);if(!a)return null;const o=a,l=a.x,c=a.y;let u=1/0;t=a;do{if(i>=t.x&&t.x>=l&&i!==t.x&&fd(s<c?i:r,s,l,c,s<c?r:i,s,t.x,t.y)){const f=Math.abs(s-t.y)/(i-t.x);Cr(t,n)&&(f<u||f===u&&(t.x>a.x||t.x===a.x&&Tg(a,t)))&&(a=t,u=f)}t=t.next}while(t!==o);return a}function Tg(n,e){return Et(n.prev,n,e.prev)<0&&Et(e.next,n,n.next)<0}function Ag(n,e,t,i){let s=n;do s.z===0&&(s.z=dc(s.x,s.y,e,t,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==n);s.prevZ.nextZ=null,s.prevZ=null,wg(s)}function wg(n){let e,t=1;do{let i=n,s;n=null;let r=null;for(e=0;i;){e++;let a=i,o=0;for(let c=0;c<t&&(o++,a=a.nextZ,!!a);c++);let l=t;for(;o>0||l>0&&a;)o!==0&&(l===0||!a||i.z<=a.z)?(s=i,i=i.nextZ,o--):(s=a,a=a.nextZ,l--),r?r.nextZ=s:n=s,s.prevZ=r,r=s;i=a}r.nextZ=null,t*=2}while(e>1);return n}function dc(n,e,t,i,s){return n=(n-t)*s|0,e=(e-i)*s|0,n=(n|n<<8)&16711935,n=(n|n<<4)&252645135,n=(n|n<<2)&858993459,n=(n|n<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,n|e<<1}function Cg(n){let e=n,t=n;do(e.x<t.x||e.x===t.x&&e.y<t.y)&&(t=e),e=e.next;while(e!==n);return t}function fd(n,e,t,i,s,r,a,o){return(s-a)*(e-o)>=(n-a)*(r-o)&&(n-a)*(i-o)>=(t-a)*(e-o)&&(t-a)*(r-o)>=(s-a)*(i-o)}function xr(n,e,t,i,s,r,a,o){return!(n===a&&e===o)&&fd(n,e,t,i,s,r,a,o)}function Rg(n,e){return n.next.i!==e.i&&n.prev.i!==e.i&&!Pg(n,e)&&(Cr(n,e)&&Cr(e,n)&&Lg(n,e)&&(Et(n.prev,n,e.prev)||Et(n,e.prev,e))||Xs(n,e)&&Et(n.prev,n,n.next)>0&&Et(e.prev,e,e.next)>0)}function Et(n,e,t){return(e.y-n.y)*(t.x-e.x)-(e.x-n.x)*(t.y-e.y)}function Xs(n,e){return n.x===e.x&&n.y===e.y}function dd(n,e,t,i){const s=ga(Et(n,e,t)),r=ga(Et(n,e,i)),a=ga(Et(t,i,n)),o=ga(Et(t,i,e));return!!(s!==r&&a!==o||s===0&&ma(n,t,e)||r===0&&ma(n,i,e)||a===0&&ma(t,n,i)||o===0&&ma(t,e,i))}function ma(n,e,t){return e.x<=Math.max(n.x,t.x)&&e.x>=Math.min(n.x,t.x)&&e.y<=Math.max(n.y,t.y)&&e.y>=Math.min(n.y,t.y)}function ga(n){return n>0?1:n<0?-1:0}function Pg(n,e){let t=n;do{if(t.i!==n.i&&t.next.i!==n.i&&t.i!==e.i&&t.next.i!==e.i&&dd(t,t.next,n,e))return!0;t=t.next}while(t!==n);return!1}function Cr(n,e){return Et(n.prev,n,n.next)<0?Et(n,e,n.next)>=0&&Et(n,n.prev,e)>=0:Et(n,e,n.prev)<0||Et(n,n.next,e)<0}function Lg(n,e){let t=n,i=!1;const s=(n.x+e.x)/2,r=(n.y+e.y)/2;do t.y>r!=t.next.y>r&&t.next.y!==t.y&&s<(t.next.x-t.x)*(r-t.y)/(t.next.y-t.y)+t.x&&(i=!i),t=t.next;while(t!==n);return i}function pd(n,e){const t=pc(n.i,n.x,n.y),i=pc(e.i,e.x,e.y),s=n.next,r=e.prev;return n.next=e,e.prev=n,t.next=s,s.prev=t,i.next=t,t.prev=i,r.next=i,i.prev=r,i}function Xu(n,e,t,i){const s=pc(n,e,t);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function Rr(n){n.next.prev=n.prev,n.prev.next=n.next,n.prevZ&&(n.prevZ.nextZ=n.nextZ),n.nextZ&&(n.nextZ.prevZ=n.prevZ)}function pc(n,e,t){return{i:n,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Dg(n,e,t,i){let s=0;for(let r=e,a=t-i;r<t;r+=i)s+=(n[a]-n[r])*(n[r+1]+n[a+1]),a=r;return s}class Ig{static triangulate(e,t,i=2){return gg(e,t,i)}}class br{static area(e){const t=e.length;let i=0;for(let s=t-1,r=0;r<t;s=r++)i+=e[s].x*e[r].y-e[r].x*e[s].y;return i*.5}static isClockWise(e){return br.area(e)<0}static triangulateShape(e,t){const i=[],s=[],r=[];Yu(e),qu(i,e);let a=e.length;t.forEach(Yu);for(let l=0;l<t.length;l++)s.push(a),a+=t[l].length,qu(i,t[l]);const o=Ig.triangulate(i,s);for(let l=0;l<o.length;l+=3)r.push(o.slice(l,l+3));return r}}function Yu(n){const e=n.length;e>2&&n[e-1].equals(n[0])&&n.pop()}function qu(n,e){for(let t=0;t<e.length;t++)n.push(e[t].x),n.push(e[t].y)}class Qi extends wt{constructor(e=1,t=1,i=1,s=1){super(),this.type="PlaneGeometry",this.parameters={width:e,height:t,widthSegments:i,heightSegments:s};const r=e/2,a=t/2,o=Math.floor(i),l=Math.floor(s),c=o+1,u=l+1,f=e/o,h=t/l,d=[],p=[],x=[],m=[];for(let g=0;g<u;g++){const M=g*h-a;for(let E=0;E<c;E++){const _=E*f-r;p.push(_,-M,0),x.push(0,0,1),m.push(E/o),m.push(1-g/l)}}for(let g=0;g<l;g++)for(let M=0;M<o;M++){const E=M+c*g,_=M+c*(g+1),T=M+1+c*(g+1),b=M+1+c*g;d.push(E,_,b),d.push(_,T,b)}this.setIndex(d),this.setAttribute("position",new ht(p,3)),this.setAttribute("normal",new ht(x,3)),this.setAttribute("uv",new ht(m,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(e){return new Qi(e.width,e.height,e.widthSegments,e.heightSegments)}}class zc extends wt{constructor(e=new ud([new Ee(0,.5),new Ee(-.5,-.5),new Ee(.5,-.5)]),t=12){super(),this.type="ShapeGeometry",this.parameters={shapes:e,curveSegments:t};const i=[],s=[],r=[],a=[];let o=0,l=0;if(Array.isArray(e)===!1)c(e);else for(let u=0;u<e.length;u++)c(e[u]),this.addGroup(o,l,u),o+=l,l=0;this.setIndex(i),this.setAttribute("position",new ht(s,3)),this.setAttribute("normal",new ht(r,3)),this.setAttribute("uv",new ht(a,2));function c(u){const f=s.length/3,h=u.extractPoints(t);let d=h.shape;const p=h.holes;br.isClockWise(d)===!1&&(d=d.reverse());for(let m=0,g=p.length;m<g;m++){const M=p[m];br.isClockWise(M)===!0&&(p[m]=M.reverse())}const x=br.triangulateShape(d,p);for(let m=0,g=p.length;m<g;m++){const M=p[m];d=d.concat(M)}for(let m=0,g=d.length;m<g;m++){const M=d[m];s.push(M.x,M.y,0),r.push(0,0,1),a.push(M.x,M.y)}for(let m=0,g=x.length;m<g;m++){const M=x[m],E=M[0]+f,_=M[1]+f,T=M[2]+f;i.push(E,_,T),l+=3}}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON(),t=this.parameters.shapes;return Ug(t,e)}static fromJSON(e,t){const i=[];for(let s=0,r=e.shapes.length;s<r;s++){const a=t[e.shapes[s]];i.push(a)}return new zc(i,e.curveSegments)}}function Ug(n,e){if(e.shapes=[],Array.isArray(n))for(let t=0,i=n.length;t<i;t++){const s=n[t];e.shapes.push(s.uuid)}else e.shapes.push(n.uuid);return e}function Ys(n){const e={};for(const t in n){e[t]={};for(const i in n[t]){const s=n[t][i];if($u(s))s.isRenderTargetTexture?(We("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[t][i]=null):e[t][i]=s.clone();else if(Array.isArray(s))if($u(s[0])){const r=[];for(let a=0,o=s.length;a<o;a++)r[a]=s[a].clone();e[t][i]=r}else e[t][i]=s.slice();else e[t][i]=s}}return e}function nn(n){const e={};for(let t=0;t<n.length;t++){const i=Ys(n[t]);for(const s in i)e[s]=i[s]}return e}function $u(n){return n&&(n.isColor||n.isMatrix3||n.isMatrix4||n.isVector2||n.isVector3||n.isVector4||n.isTexture||n.isQuaternion)}function Og(n){const e=[];for(let t=0;t<n.length;t++)e.push(n[t].clone());return e}function md(n){const e=n.getRenderTarget();return e===null?n.outputColorSpace:e.isXRRenderTarget===!0?e.texture.colorSpace:nt.workingColorSpace}const Fg={clone:Ys,merge:nn};var Ng=`void main() {
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
}`,kg=`void main() {
|
|
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
|
|
}`;class In extends js{constructor(e){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=Ng,this.fragmentShader=kg,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=Ys(e.uniforms),this.uniformsGroups=Og(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this.defaultAttributeValues=Object.assign({},e.defaultAttributeValues),this.index0AttributeName=e.index0AttributeName,this.uniformsNeedUpdate=e.uniformsNeedUpdate,this}toJSON(e){const t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(const s in this.uniforms){const a=this.uniforms[s].value;a&&a.isTexture?t.uniforms[s]={type:"t",value:a.toJSON(e).uuid}:a&&a.isColor?t.uniforms[s]={type:"c",value:a.getHex()}:a&&a.isVector2?t.uniforms[s]={type:"v2",value:a.toArray()}:a&&a.isVector3?t.uniforms[s]={type:"v3",value:a.toArray()}:a&&a.isVector4?t.uniforms[s]={type:"v4",value:a.toArray()}:a&&a.isMatrix3?t.uniforms[s]={type:"m3",value:a.toArray()}:a&&a.isMatrix4?t.uniforms[s]={type:"m4",value:a.toArray()}:t.uniforms[s]={value:a}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;const i={};for(const s in this.extensions)this.extensions[s]===!0&&(i[s]=!0);return Object.keys(i).length>0&&(t.extensions=i),t}fromJSON(e,t){if(super.fromJSON(e,t),e.uniforms!==void 0)for(const i in e.uniforms){const s=e.uniforms[i];switch(this.uniforms[i]={},s.type){case"t":this.uniforms[i].value=t[s.value]||null;break;case"c":this.uniforms[i].value=new et().setHex(s.value);break;case"v2":this.uniforms[i].value=new Ee().fromArray(s.value);break;case"v3":this.uniforms[i].value=new B().fromArray(s.value);break;case"v4":this.uniforms[i].value=new Ct().fromArray(s.value);break;case"m3":this.uniforms[i].value=new $e().fromArray(s.value);break;case"m4":this.uniforms[i].value=new Tt().fromArray(s.value);break;default:this.uniforms[i].value=s.value}}if(e.defines!==void 0&&(this.defines=e.defines),e.vertexShader!==void 0&&(this.vertexShader=e.vertexShader),e.fragmentShader!==void 0&&(this.fragmentShader=e.fragmentShader),e.glslVersion!==void 0&&(this.glslVersion=e.glslVersion),e.extensions!==void 0)for(const i in e.extensions)this.extensions[i]=e.extensions[i];return e.lights!==void 0&&(this.lights=e.lights),e.clipping!==void 0&&(this.clipping=e.clipping),this}}class Bg extends In{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class Hg extends js{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=ym,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}}class zg extends js{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}}class Gg extends Ns{constructor(e){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(e)}copy(e){return super.copy(e),this.scale=e.scale,this.dashSize=e.dashSize,this.gapSize=e.gapSize,this}}const xa=new B,va=new ki,Bn=new B;class gd extends sn{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Tt,this.projectionMatrix=new Tt,this.projectionMatrixInverse=new Tt,this.coordinateSystem=$n,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorld.decompose(xa,va,Bn),Bn.x===1&&Bn.y===1&&Bn.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(xa,va,Bn.set(1,1,1)).invert()}updateWorldMatrix(e,t,i=!1){super.updateWorldMatrix(e,t,i),this.matrixWorld.decompose(xa,va,Bn),Bn.x===1&&Bn.y===1&&Bn.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(xa,va,Bn.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}}const Ai=new B,Zu=new Ee,Ku=new Ee;class Pn extends gd{constructor(e=50,t=1,i=.1,s=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=i,this.far=s,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){const t=.5*this.getFilmHeight()/e;this.fov=hc*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){const e=Math.tan(ka*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return hc*2*Math.atan(Math.tan(ka*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,i){Ai.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(Ai.x,Ai.y).multiplyScalar(-e/Ai.z),Ai.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),i.set(Ai.x,Ai.y).multiplyScalar(-e/Ai.z)}getViewSize(e,t){return this.getViewBounds(e,Zu,Ku),t.subVectors(Ku,Zu)}setViewOffset(e,t,i,s,r,a){this.aspect=e/t,this.view===null&&(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=s,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=this.near;let t=e*Math.tan(ka*.5*this.fov)/this.zoom,i=2*t,s=this.aspect*i,r=-.5*s;const a=this.view;if(this.view!==null&&this.view.enabled){const l=a.fullWidth,c=a.fullHeight;r+=a.offsetX*s/l,t-=a.offsetY*i/c,s*=a.width/l,i*=a.height/c}const o=this.filmOffset;o!==0&&(r+=e*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+s,t,t-i,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}}class Gc extends gd{constructor(e=-1,t=1,i=1,s=-1,r=.1,a=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=i,this.bottom=s,this.near=r,this.far=a,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,i,s,r,a){this.view===null&&(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=s,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,s=(this.top+this.bottom)/2;let r=i-e,a=i+e,o=s+t,l=s-t;if(this.view!==null&&this.view.enabled){const c=(this.right-this.left)/this.view.fullWidth/this.zoom,u=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=c*this.view.offsetX,a=r+c*this.view.width,o-=u*this.view.offsetY,l=o-u*this.view.height}this.projectionMatrix.makeOrthographic(r,a,o,l,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}}const Ps=-90,Ls=1;class Vg extends sn{constructor(e,t,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const s=new Pn(Ps,Ls,e,t);s.layers=this.layers,this.add(s);const r=new Pn(Ps,Ls,e,t);r.layers=this.layers,this.add(r);const a=new Pn(Ps,Ls,e,t);a.layers=this.layers,this.add(a);const o=new Pn(Ps,Ls,e,t);o.layers=this.layers,this.add(o);const l=new Pn(Ps,Ls,e,t);l.layers=this.layers,this.add(l);const c=new Pn(Ps,Ls,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){const e=this.coordinateSystem,t=this.children.concat(),[i,s,r,a,o,l]=t;for(const c of t)this.remove(c);if(e===$n)i.up.set(0,1,0),i.lookAt(1,0,0),s.up.set(0,1,0),s.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),a.up.set(0,0,1),a.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),l.up.set(0,1,0),l.lookAt(0,0,-1);else if(e===$a)i.up.set(0,-1,0),i.lookAt(-1,0,0),s.up.set(0,-1,0),s.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),a.up.set(0,0,-1),a.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),l.up.set(0,-1,0),l.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(const c of t)this.add(c),c.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:s}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());const[r,a,o,l,c,u]=this.children,f=e.getRenderTarget(),h=e.getActiveCubeFace(),d=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;const x=i.texture.generateMipmaps;i.texture.generateMipmaps=!1;let m=!1;e.isWebGLRenderer===!0?m=e.state.buffers.depth.getReversed():m=e.reversedDepthBuffer,e.setRenderTarget(i,0,s),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,r),e.setRenderTarget(i,1,s),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(i,2,s),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,o),e.setRenderTarget(i,3,s),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(i,4,s),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),i.texture.generateMipmaps=x,e.setRenderTarget(i,5,s),m&&e.autoClear===!1&&e.clearDepth(),e.render(t,u),e.setRenderTarget(f,h,d),e.xr.enabled=p,i.texture.needsPMREMUpdate=!0}}class Wg extends Pn{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}}class Ju{constructor(e=1,t=0,i=0){this.radius=e,this.phi=t,this.theta=i}set(e,t,i){return this.radius=e,this.phi=t,this.theta=i,this}copy(e){return this.radius=e.radius,this.phi=e.phi,this.theta=e.theta,this}makeSafe(){return this.phi=Qe(this.phi,1e-6,Math.PI-1e-6),this}setFromVector3(e){return this.setFromCartesianCoords(e.x,e.y,e.z)}setFromCartesianCoords(e,t,i){return this.radius=Math.sqrt(e*e+t*t+i*i),this.radius===0?(this.theta=0,this.phi=0):(this.theta=Math.atan2(e,i),this.phi=Math.acos(Qe(t/this.radius,-1,1))),this}clone(){return new this.constructor().copy(this)}}const uu=class uu{constructor(e,t,i,s){this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,i,s)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let i=0;i<4;i++)this.elements[i]=e[i+t];return this}set(e,t,i,s){const r=this.elements;return r[0]=e,r[2]=t,r[1]=i,r[3]=s,this}};uu.prototype.isMatrix2=!0;let ju=uu;class Xg extends zi{constructor(e,t=null){super(),this.object=e,this.domElement=t,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(e){if(e===void 0){We("Controls: connect() now requires an element.");return}this.domElement!==null&&this.disconnect(),this.domElement=e}disconnect(){}dispose(){}update(){}}function Qu(n,e,t,i){const s=Yg(i);switch(t){case Xf:return n*e;case qf:return n*e/s.components*s.byteLength;case Dc:return n*e/s.components*s.byteLength;case ts:return n*e*2/s.components*s.byteLength;case Ic:return n*e*2/s.components*s.byteLength;case Yf:return n*e*3/s.components*s.byteLength;case En:return n*e*4/s.components*s.byteLength;case Uc:return n*e*4/s.components*s.byteLength;case Ua:case Oa:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*8;case Fa:case Na:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*16;case Ul:case Fl:return Math.max(n,16)*Math.max(e,8)/4;case Il:case Ol:return Math.max(n,8)*Math.max(e,8)/2;case Nl:case kl:case Hl:case zl:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*8;case Bl:case Wa:case Gl:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*16;case Vl:return Math.floor((n+3)/4)*Math.floor((e+3)/4)*16;case Wl:return Math.floor((n+4)/5)*Math.floor((e+3)/4)*16;case Xl:return Math.floor((n+4)/5)*Math.floor((e+4)/5)*16;case Yl:return Math.floor((n+5)/6)*Math.floor((e+4)/5)*16;case ql:return Math.floor((n+5)/6)*Math.floor((e+5)/6)*16;case $l:return Math.floor((n+7)/8)*Math.floor((e+4)/5)*16;case Zl:return Math.floor((n+7)/8)*Math.floor((e+5)/6)*16;case Kl:return Math.floor((n+7)/8)*Math.floor((e+7)/8)*16;case Jl:return Math.floor((n+9)/10)*Math.floor((e+4)/5)*16;case jl:return Math.floor((n+9)/10)*Math.floor((e+5)/6)*16;case Ql:return Math.floor((n+9)/10)*Math.floor((e+7)/8)*16;case ec:return Math.floor((n+9)/10)*Math.floor((e+9)/10)*16;case tc:return Math.floor((n+11)/12)*Math.floor((e+9)/10)*16;case nc:return Math.floor((n+11)/12)*Math.floor((e+11)/12)*16;case ic:case sc:case rc:return Math.ceil(n/4)*Math.ceil(e/4)*16;case ac:case oc:return Math.ceil(n/4)*Math.ceil(e/4)*8;case Xa:case lc:return Math.ceil(n/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${t} format.`)}function Yg(n){switch(n){case Sn:case zf:return{byteLength:1,components:1};case Tr:case Gf:case mi:return{byteLength:2,components:1};case Pc:case Lc:return{byteLength:2,components:4};case Qn:case Rc:case Ln:return{byteLength:4,components:1};case Vf:case Wf:return{byteLength:4,components:3}}throw new Error(`THREE.TextureUtils: Unknown texture type ${n}.`)}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:Cc}}));typeof window<"u"&&(window.__THREE__?We("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=Cc);/**
|
|
* @license
|
|
* Copyright 2010-2026 Three.js Authors
|
|
* SPDX-License-Identifier: MIT
|
|
*/function xd(){let n=null,e=!1,t=null,i=null;function s(r,a){t(r,a),i=n.requestAnimationFrame(s)}return{start:function(){e!==!0&&t!==null&&n!==null&&(i=n.requestAnimationFrame(s),e=!0)},stop:function(){n!==null&&n.cancelAnimationFrame(i),e=!1},setAnimationLoop:function(r){t=r},setContext:function(r){n=r}}}function qg(n){const e=new WeakMap;function t(o,l){const c=o.array,u=o.usage,f=c.byteLength,h=n.createBuffer();n.bindBuffer(l,h),n.bufferData(l,c,u),o.onUploadCallback();let d;if(c instanceof Float32Array)d=n.FLOAT;else if(typeof Float16Array<"u"&&c instanceof Float16Array)d=n.HALF_FLOAT;else if(c instanceof Uint16Array)o.isFloat16BufferAttribute?d=n.HALF_FLOAT:d=n.UNSIGNED_SHORT;else if(c instanceof Int16Array)d=n.SHORT;else if(c instanceof Uint32Array)d=n.UNSIGNED_INT;else if(c instanceof Int32Array)d=n.INT;else if(c instanceof Int8Array)d=n.BYTE;else if(c instanceof Uint8Array)d=n.UNSIGNED_BYTE;else if(c instanceof Uint8ClampedArray)d=n.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+c);return{buffer:h,type:d,bytesPerElement:c.BYTES_PER_ELEMENT,version:o.version,size:f}}function i(o,l,c){const u=l.array,f=l.updateRanges;if(n.bindBuffer(c,o),f.length===0)n.bufferSubData(c,0,u);else{f.sort((d,p)=>d.start-p.start);let h=0;for(let d=1;d<f.length;d++){const p=f[h],x=f[d];x.start<=p.start+p.count+1?p.count=Math.max(p.count,x.start+x.count-p.start):(++h,f[h]=x)}f.length=h+1;for(let d=0,p=f.length;d<p;d++){const x=f[d];n.bufferSubData(c,x.start*u.BYTES_PER_ELEMENT,u,x.start,x.count)}l.clearUpdateRanges()}l.onUploadCallback()}function s(o){return o.isInterleavedBufferAttribute&&(o=o.data),e.get(o)}function r(o){o.isInterleavedBufferAttribute&&(o=o.data);const l=e.get(o);l&&(n.deleteBuffer(l.buffer),e.delete(o))}function a(o,l){if(o.isInterleavedBufferAttribute&&(o=o.data),o.isGLBufferAttribute){const u=e.get(o);(!u||u.version<o.version)&&e.set(o,{buffer:o.buffer,type:o.type,bytesPerElement:o.elementSize,version:o.version});return}const c=e.get(o);if(c===void 0)e.set(o,t(o,l));else if(c.version<o.version){if(c.size!==o.array.byteLength)throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");i(c.buffer,o,l),c.version=o.version}}return{get:s,remove:r,update:a}}var $g=`#ifdef USE_ALPHAHASH
|
|
if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
|
|
#endif`,Zg=`#ifdef USE_ALPHAHASH
|
|
const float ALPHA_HASH_SCALE = 0.05;
|
|
float hash2D( vec2 value ) {
|
|
return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
|
|
}
|
|
float hash3D( vec3 value ) {
|
|
return hash2D( vec2( hash2D( value.xy ), value.z ) );
|
|
}
|
|
float getAlphaHashThreshold( vec3 position ) {
|
|
float maxDeriv = max(
|
|
length( dFdx( position.xyz ) ),
|
|
length( dFdy( position.xyz ) )
|
|
);
|
|
float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
|
|
vec2 pixScales = vec2(
|
|
exp2( floor( log2( pixScale ) ) ),
|
|
exp2( ceil( log2( pixScale ) ) )
|
|
);
|
|
vec2 alpha = vec2(
|
|
hash3D( floor( pixScales.x * position.xyz ) ),
|
|
hash3D( floor( pixScales.y * position.xyz ) )
|
|
);
|
|
float lerpFactor = fract( log2( pixScale ) );
|
|
float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;
|
|
float a = min( lerpFactor, 1.0 - lerpFactor );
|
|
vec3 cases = vec3(
|
|
x * x / ( 2.0 * a * ( 1.0 - a ) ),
|
|
( x - 0.5 * a ) / ( 1.0 - a ),
|
|
1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
|
|
);
|
|
float threshold = ( x < ( 1.0 - a ) )
|
|
? ( ( x < a ) ? cases.x : cases.y )
|
|
: cases.z;
|
|
return clamp( threshold , 1.0e-6, 1.0 );
|
|
}
|
|
#endif`,Kg=`#ifdef USE_ALPHAMAP
|
|
diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
|
|
#endif`,Jg=`#ifdef USE_ALPHAMAP
|
|
uniform sampler2D alphaMap;
|
|
#endif`,jg=`#ifdef USE_ALPHATEST
|
|
#ifdef ALPHA_TO_COVERAGE
|
|
diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );
|
|
if ( diffuseColor.a == 0.0 ) discard;
|
|
#else
|
|
if ( diffuseColor.a < alphaTest ) discard;
|
|
#endif
|
|
#endif`,Qg=`#ifdef USE_ALPHATEST
|
|
uniform float alphaTest;
|
|
#endif`,e0=`#ifdef USE_AOMAP
|
|
float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
|
|
reflectedLight.indirectDiffuse *= ambientOcclusion;
|
|
#if defined( USE_CLEARCOAT )
|
|
clearcoatSpecularIndirect *= ambientOcclusion;
|
|
#endif
|
|
#if defined( USE_SHEEN )
|
|
sheenSpecularIndirect *= ambientOcclusion;
|
|
#endif
|
|
#if defined( USE_ENVMAP ) && defined( STANDARD )
|
|
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
|
|
#endif
|
|
#endif`,t0=`#ifdef USE_AOMAP
|
|
uniform sampler2D aoMap;
|
|
uniform float aoMapIntensity;
|
|
#endif`,n0=`#ifdef USE_BATCHING
|
|
#if ! defined( GL_ANGLE_multi_draw )
|
|
#define gl_DrawID _gl_DrawID
|
|
uniform int _gl_DrawID;
|
|
#endif
|
|
uniform highp sampler2D batchingTexture;
|
|
uniform highp usampler2D batchingIdTexture;
|
|
mat4 getBatchingMatrix( const in float i ) {
|
|
int size = textureSize( batchingTexture, 0 ).x;
|
|
int j = int( i ) * 4;
|
|
int x = j % size;
|
|
int y = j / size;
|
|
vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
|
|
vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
|
|
vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
|
|
vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
|
|
return mat4( v1, v2, v3, v4 );
|
|
}
|
|
float getIndirectIndex( const in int i ) {
|
|
int size = textureSize( batchingIdTexture, 0 ).x;
|
|
int x = i % size;
|
|
int y = i / size;
|
|
return float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );
|
|
}
|
|
#endif
|
|
#ifdef USE_BATCHING_COLOR
|
|
uniform sampler2D batchingColorTexture;
|
|
vec4 getBatchingColor( const in float i ) {
|
|
int size = textureSize( batchingColorTexture, 0 ).x;
|
|
int j = int( i );
|
|
int x = j % size;
|
|
int y = j / size;
|
|
return texelFetch( batchingColorTexture, ivec2( x, y ), 0 );
|
|
}
|
|
#endif`,i0=`#ifdef USE_BATCHING
|
|
mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
|
|
#endif`,s0=`vec3 transformed = vec3( position );
|
|
#ifdef USE_ALPHAHASH
|
|
vPosition = vec3( position );
|
|
#endif`,r0=`vec3 objectNormal = vec3( normal );
|
|
#ifdef USE_TANGENT
|
|
vec3 objectTangent = vec3( tangent.xyz );
|
|
#endif`,a0=`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_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
|
|
vec3 halfDir = normalize( lightDir + viewDir );
|
|
float dotNH = saturate( dot( normal, halfDir ) );
|
|
float dotVH = saturate( dot( viewDir, halfDir ) );
|
|
vec3 F = F_Schlick( specularColor, 1.0, dotVH );
|
|
float G = G_BlinnPhong_Implicit( );
|
|
float D = D_BlinnPhong( shininess, dotNH );
|
|
return F * ( G * D );
|
|
} // validated`,o0=`#ifdef USE_IRIDESCENCE
|
|
const mat3 XYZ_TO_REC709 = mat3(
|
|
3.2404542, -0.9692660, 0.0556434,
|
|
-1.5371385, 1.8760108, -0.2040259,
|
|
-0.4985314, 0.0415560, 1.0572252
|
|
);
|
|
vec3 Fresnel0ToIor( vec3 fresnel0 ) {
|
|
vec3 sqrtF0 = sqrt( fresnel0 );
|
|
return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
|
|
}
|
|
vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {
|
|
return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
|
|
}
|
|
float IorToFresnel0( float transmittedIor, float incidentIor ) {
|
|
return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));
|
|
}
|
|
vec3 evalSensitivity( float OPD, vec3 shift ) {
|
|
float phase = 2.0 * PI * OPD * 1.0e-9;
|
|
vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
|
|
vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
|
|
vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
|
|
vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );
|
|
xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );
|
|
xyz /= 1.0685e-7;
|
|
vec3 rgb = XYZ_TO_REC709 * xyz;
|
|
return rgb;
|
|
}
|
|
vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
|
|
vec3 I;
|
|
float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
|
|
float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );
|
|
float cosTheta2Sq = 1.0 - sinTheta2Sq;
|
|
if ( cosTheta2Sq < 0.0 ) {
|
|
return vec3( 1.0 );
|
|
}
|
|
float cosTheta2 = sqrt( cosTheta2Sq );
|
|
float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
|
|
float R12 = F_Schlick( R0, 1.0, cosTheta1 );
|
|
float T121 = 1.0 - R12;
|
|
float phi12 = 0.0;
|
|
if ( iridescenceIOR < outsideIOR ) phi12 = PI;
|
|
float phi21 = PI - phi12;
|
|
vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );
|
|
vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );
|
|
vec3 phi23 = vec3( 0.0 );
|
|
if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;
|
|
if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;
|
|
if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;
|
|
float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;
|
|
vec3 phi = vec3( phi21 ) + phi23;
|
|
vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
|
|
vec3 r123 = sqrt( R123 );
|
|
vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
|
|
vec3 C0 = R12 + Rs;
|
|
I = C0;
|
|
vec3 Cm = Rs - T121;
|
|
for ( int m = 1; m <= 2; ++ m ) {
|
|
Cm *= r123;
|
|
vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
|
|
I += Cm * Sm;
|
|
}
|
|
return max( I, vec3( 0.0 ) );
|
|
}
|
|
#endif`,l0=`#ifdef USE_BUMPMAP
|
|
uniform sampler2D bumpMap;
|
|
uniform float bumpScale;
|
|
vec2 dHdxy_fwd() {
|
|
vec2 dSTdx = dFdx( vBumpMapUv );
|
|
vec2 dSTdy = dFdy( vBumpMapUv );
|
|
float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;
|
|
float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;
|
|
float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;
|
|
return vec2( dBx, dBy );
|
|
}
|
|
vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
|
|
vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
|
|
vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
|
|
vec3 vN = surf_norm;
|
|
vec3 R1 = cross( vSigmaY, vN );
|
|
vec3 R2 = cross( vN, vSigmaX );
|
|
float fDet = dot( vSigmaX, R1 ) * faceDirection;
|
|
vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
|
|
return normalize( abs( fDet ) * surf_norm - vGrad );
|
|
}
|
|
#endif`,c0=`#if NUM_CLIPPING_PLANES > 0
|
|
vec4 plane;
|
|
#ifdef ALPHA_TO_COVERAGE
|
|
float distanceToPlane, distanceGradient;
|
|
float clipOpacity = 1.0;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
|
|
plane = clippingPlanes[ i ];
|
|
distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
|
|
distanceGradient = fwidth( distanceToPlane ) / 2.0;
|
|
clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
|
|
if ( clipOpacity == 0.0 ) discard;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
|
|
float unionClipOpacity = 1.0;
|
|
#pragma unroll_loop_start
|
|
for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
|
|
plane = clippingPlanes[ i ];
|
|
distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
|
|
distanceGradient = fwidth( distanceToPlane ) / 2.0;
|
|
unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
|
|
}
|
|
#pragma unroll_loop_end
|
|
clipOpacity *= 1.0 - unionClipOpacity;
|
|
#endif
|
|
diffuseColor.a *= clipOpacity;
|
|
if ( diffuseColor.a == 0.0 ) discard;
|
|
#else
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
|
|
plane = clippingPlanes[ i ];
|
|
if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
|
|
bool clipped = true;
|
|
#pragma unroll_loop_start
|
|
for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
|
|
plane = clippingPlanes[ i ];
|
|
clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
|
|
}
|
|
#pragma unroll_loop_end
|
|
if ( clipped ) discard;
|
|
#endif
|
|
#endif
|
|
#endif`,u0=`#if NUM_CLIPPING_PLANES > 0
|
|
varying vec3 vClipPosition;
|
|
uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
|
|
#endif`,h0=`#if NUM_CLIPPING_PLANES > 0
|
|
varying vec3 vClipPosition;
|
|
#endif`,f0=`#if NUM_CLIPPING_PLANES > 0
|
|
vClipPosition = - mvPosition.xyz;
|
|
#endif`,d0=`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
|
|
diffuseColor *= vColor;
|
|
#endif`,p0=`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
|
|
varying vec4 vColor;
|
|
#endif`,m0=`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
|
|
varying vec4 vColor;
|
|
#endif`,g0=`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
|
|
vColor = vec4( 1.0 );
|
|
#endif
|
|
#ifdef USE_COLOR_ALPHA
|
|
vColor *= color;
|
|
#elif defined( USE_COLOR )
|
|
vColor.rgb *= color;
|
|
#endif
|
|
#ifdef USE_INSTANCING_COLOR
|
|
vColor.rgb *= instanceColor.rgb;
|
|
#endif
|
|
#ifdef USE_BATCHING_COLOR
|
|
vColor *= getBatchingColor( getIndirectIndex( gl_DrawID ) );
|
|
#endif`,x0=`#define PI 3.141592653589793
|
|
#define PI2 6.283185307179586
|
|
#define PI_HALF 1.5707963267948966
|
|
#define RECIPROCAL_PI 0.3183098861837907
|
|
#define RECIPROCAL_PI2 0.15915494309189535
|
|
#define EPSILON 1e-6
|
|
#ifndef saturate
|
|
#define saturate( a ) clamp( a, 0.0, 1.0 )
|
|
#endif
|
|
#define whiteComplement( a ) ( 1.0 - saturate( a ) )
|
|
float pow2( const in float x ) { return x*x; }
|
|
vec3 pow2( const in vec3 x ) { return x*x; }
|
|
float pow3( const in float x ) { return x*x*x; }
|
|
float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
|
|
float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
|
|
float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
|
|
highp float rand( const in vec2 uv ) {
|
|
const highp float a = 12.9898, b = 78.233, c = 43758.5453;
|
|
highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
|
|
return fract( sin( sn ) * c );
|
|
}
|
|
#ifdef HIGH_PRECISION
|
|
float precisionSafeLength( vec3 v ) { return length( v ); }
|
|
#else
|
|
float precisionSafeLength( vec3 v ) {
|
|
float maxComponent = max3( abs( v ) );
|
|
return length( v / maxComponent ) * maxComponent;
|
|
}
|
|
#endif
|
|
struct IncidentLight {
|
|
vec3 color;
|
|
vec3 direction;
|
|
bool visible;
|
|
};
|
|
struct ReflectedLight {
|
|
vec3 directDiffuse;
|
|
vec3 directSpecular;
|
|
vec3 indirectDiffuse;
|
|
vec3 indirectSpecular;
|
|
};
|
|
#ifdef USE_ALPHAHASH
|
|
varying vec3 vPosition;
|
|
#endif
|
|
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
|
|
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
|
|
}
|
|
#define inverseTransformDirection transformDirectionByInverseViewMatrix
|
|
vec3 transformNormalByInverseViewMatrix( in vec3 normal, in mat4 viewMatrix ) {
|
|
return normalize( ( vec4( normal, 0.0 ) * viewMatrix ).xyz );
|
|
}
|
|
vec3 transformDirectionByInverseViewMatrix( in vec3 dir, in mat4 viewMatrix ) {
|
|
return normalize( ( vec4( dir, 0.0 ) * viewMatrix ).xyz );
|
|
}
|
|
bool isPerspectiveMatrix( mat4 m ) {
|
|
return m[ 2 ][ 3 ] == - 1.0;
|
|
}
|
|
vec2 equirectUv( in vec3 dir ) {
|
|
float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
|
|
float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
|
|
return vec2( u, v );
|
|
}
|
|
vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
|
|
return RECIPROCAL_PI * diffuseColor;
|
|
}
|
|
vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
|
|
float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
|
|
return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
|
|
}
|
|
float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
|
|
float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
|
|
return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
|
|
} // validated`,v0=`#ifdef ENVMAP_TYPE_CUBE_UV
|
|
#define cubeUV_minMipLevel 4.0
|
|
#define cubeUV_minTileSize 16.0
|
|
float getFace( vec3 direction ) {
|
|
vec3 absDirection = abs( direction );
|
|
float face = - 1.0;
|
|
if ( absDirection.x > absDirection.z ) {
|
|
if ( absDirection.x > absDirection.y )
|
|
face = direction.x > 0.0 ? 0.0 : 3.0;
|
|
else
|
|
face = direction.y > 0.0 ? 1.0 : 4.0;
|
|
} else {
|
|
if ( absDirection.z > absDirection.y )
|
|
face = direction.z > 0.0 ? 2.0 : 5.0;
|
|
else
|
|
face = direction.y > 0.0 ? 1.0 : 4.0;
|
|
}
|
|
return face;
|
|
}
|
|
vec2 getUV( vec3 direction, float face ) {
|
|
vec2 uv;
|
|
if ( face == 0.0 ) {
|
|
uv = vec2( direction.z, direction.y ) / abs( direction.x );
|
|
} else if ( face == 1.0 ) {
|
|
uv = vec2( - direction.x, - direction.z ) / abs( direction.y );
|
|
} else if ( face == 2.0 ) {
|
|
uv = vec2( - direction.x, direction.y ) / abs( direction.z );
|
|
} else if ( face == 3.0 ) {
|
|
uv = vec2( - direction.z, direction.y ) / abs( direction.x );
|
|
} else if ( face == 4.0 ) {
|
|
uv = vec2( - direction.x, direction.z ) / abs( direction.y );
|
|
} else {
|
|
uv = vec2( direction.x, direction.y ) / abs( direction.z );
|
|
}
|
|
return 0.5 * ( uv + 1.0 );
|
|
}
|
|
vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {
|
|
float face = getFace( direction );
|
|
float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );
|
|
mipInt = max( mipInt, cubeUV_minMipLevel );
|
|
float faceSize = exp2( mipInt );
|
|
highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;
|
|
if ( face > 2.0 ) {
|
|
uv.y += faceSize;
|
|
face -= 3.0;
|
|
}
|
|
uv.x += face * faceSize;
|
|
uv.x += filterInt * 3.0 * cubeUV_minTileSize;
|
|
uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );
|
|
uv.x *= CUBEUV_TEXEL_WIDTH;
|
|
uv.y *= CUBEUV_TEXEL_HEIGHT;
|
|
#ifdef texture2DGradEXT
|
|
return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;
|
|
#else
|
|
return texture2D( envMap, uv ).rgb;
|
|
#endif
|
|
}
|
|
#define cubeUV_r0 1.0
|
|
#define cubeUV_m0 - 2.0
|
|
#define cubeUV_r1 0.8
|
|
#define cubeUV_m1 - 1.0
|
|
#define cubeUV_r4 0.4
|
|
#define cubeUV_m4 2.0
|
|
#define cubeUV_r5 0.305
|
|
#define cubeUV_m5 3.0
|
|
#define cubeUV_r6 0.21
|
|
#define cubeUV_m6 4.0
|
|
float roughnessToMip( float roughness ) {
|
|
float mip = 0.0;
|
|
if ( roughness >= cubeUV_r1 ) {
|
|
mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;
|
|
} else if ( roughness >= cubeUV_r4 ) {
|
|
mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;
|
|
} else if ( roughness >= cubeUV_r5 ) {
|
|
mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;
|
|
} else if ( roughness >= cubeUV_r6 ) {
|
|
mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;
|
|
} else {
|
|
mip = - 2.0 * log2( 1.16 * roughness ); }
|
|
return mip;
|
|
}
|
|
vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {
|
|
float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );
|
|
float mipF = fract( mip );
|
|
float mipInt = floor( mip );
|
|
vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );
|
|
if ( mipF == 0.0 ) {
|
|
return vec4( color0, 1.0 );
|
|
} else {
|
|
vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );
|
|
return vec4( mix( color0, color1, mipF ), 1.0 );
|
|
}
|
|
}
|
|
#endif`,y0=`vec3 transformedNormal = objectNormal;
|
|
#ifdef USE_TANGENT
|
|
vec3 transformedTangent = objectTangent;
|
|
#endif
|
|
#ifdef USE_BATCHING
|
|
mat3 bm = mat3( batchingMatrix );
|
|
transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );
|
|
transformedNormal = bm * transformedNormal;
|
|
#ifdef USE_TANGENT
|
|
transformedTangent = bm * transformedTangent;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_INSTANCING
|
|
mat3 im = mat3( instanceMatrix );
|
|
transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );
|
|
transformedNormal = im * transformedNormal;
|
|
#ifdef USE_TANGENT
|
|
transformedTangent = im * transformedTangent;
|
|
#endif
|
|
#endif
|
|
transformedNormal = normalMatrix * transformedNormal;
|
|
#ifdef FLIP_SIDED
|
|
transformedNormal = - transformedNormal;
|
|
#endif
|
|
#ifdef USE_TANGENT
|
|
transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;
|
|
#endif`,_0=`#ifdef USE_DISPLACEMENTMAP
|
|
uniform sampler2D displacementMap;
|
|
uniform float displacementScale;
|
|
uniform float displacementBias;
|
|
#endif`,b0=`#ifdef USE_DISPLACEMENTMAP
|
|
transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
|
|
#endif`,S0=`#ifdef USE_EMISSIVEMAP
|
|
vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
|
|
#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
|
|
emissiveColor = sRGBTransferEOTF( emissiveColor );
|
|
#endif
|
|
totalEmissiveRadiance *= emissiveColor.rgb;
|
|
#endif`,M0=`#ifdef USE_EMISSIVEMAP
|
|
uniform sampler2D emissiveMap;
|
|
#endif`,E0="gl_FragColor = linearToOutputTexel( gl_FragColor );",T0=`vec4 LinearTransferOETF( in vec4 value ) {
|
|
return value;
|
|
}
|
|
vec4 sRGBTransferEOTF( 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 sRGBTransferOETF( in vec4 value ) {
|
|
return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );
|
|
}`,A0=`#ifdef USE_ENVMAP
|
|
#ifdef ENV_WORLDPOS
|
|
vec3 cameraToFrag;
|
|
if ( isOrthographic ) {
|
|
cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
|
|
} else {
|
|
cameraToFrag = normalize( vWorldPosition - cameraPosition );
|
|
}
|
|
vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
|
|
#ifdef ENVMAP_MODE_REFLECTION
|
|
vec3 reflectVec = reflect( cameraToFrag, worldNormal );
|
|
#else
|
|
vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
|
|
#endif
|
|
#else
|
|
vec3 reflectVec = vReflect;
|
|
#endif
|
|
#ifdef ENVMAP_TYPE_CUBE
|
|
vec4 envColor = textureCube( envMap, envMapRotation * reflectVec );
|
|
#ifdef ENVMAP_BLENDING_MULTIPLY
|
|
outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
|
|
#elif defined( ENVMAP_BLENDING_MIX )
|
|
outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
|
|
#elif defined( ENVMAP_BLENDING_ADD )
|
|
outgoingLight += envColor.xyz * specularStrength * reflectivity;
|
|
#endif
|
|
#endif
|
|
#endif`,w0=`#ifdef USE_ENVMAP
|
|
uniform float envMapIntensity;
|
|
uniform mat3 envMapRotation;
|
|
#ifdef ENVMAP_TYPE_CUBE
|
|
uniform samplerCube envMap;
|
|
#else
|
|
uniform sampler2D envMap;
|
|
#endif
|
|
#endif`,C0=`#ifdef USE_ENVMAP
|
|
uniform float reflectivity;
|
|
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
|
|
#define ENV_WORLDPOS
|
|
#endif
|
|
#ifdef ENV_WORLDPOS
|
|
varying vec3 vWorldPosition;
|
|
uniform float refractionRatio;
|
|
#else
|
|
varying vec3 vReflect;
|
|
#endif
|
|
#endif`,R0=`#ifdef USE_ENVMAP
|
|
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
|
|
#define ENV_WORLDPOS
|
|
#endif
|
|
#ifdef ENV_WORLDPOS
|
|
|
|
varying vec3 vWorldPosition;
|
|
#else
|
|
varying vec3 vReflect;
|
|
uniform float refractionRatio;
|
|
#endif
|
|
#endif`,P0=`#ifdef USE_ENVMAP
|
|
#ifdef ENV_WORLDPOS
|
|
vWorldPosition = worldPosition.xyz;
|
|
#else
|
|
vec3 cameraToVertex;
|
|
if ( isOrthographic ) {
|
|
cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
|
|
} else {
|
|
cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
|
|
}
|
|
vec3 worldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );
|
|
#ifdef ENVMAP_MODE_REFLECTION
|
|
vReflect = reflect( cameraToVertex, worldNormal );
|
|
#else
|
|
vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
|
|
#endif
|
|
#endif
|
|
#endif`,L0=`#ifdef USE_FOG
|
|
vFogDepth = - mvPosition.z;
|
|
#endif`,D0=`#ifdef USE_FOG
|
|
varying float vFogDepth;
|
|
#endif`,I0=`#ifdef USE_FOG
|
|
#ifdef FOG_EXP2
|
|
float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
|
|
#else
|
|
float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
|
|
#endif
|
|
gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
|
|
#endif`,U0=`#ifdef USE_FOG
|
|
uniform vec3 fogColor;
|
|
varying float vFogDepth;
|
|
#ifdef FOG_EXP2
|
|
uniform float fogDensity;
|
|
#else
|
|
uniform float fogNear;
|
|
uniform float fogFar;
|
|
#endif
|
|
#endif`,O0=`#ifdef USE_GRADIENTMAP
|
|
uniform sampler2D gradientMap;
|
|
#endif
|
|
vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
|
|
float dotNL = dot( normal, lightDirection );
|
|
vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
|
|
#ifdef USE_GRADIENTMAP
|
|
return vec3( texture2D( gradientMap, coord ).r );
|
|
#else
|
|
vec2 fw = fwidth( coord ) * 0.5;
|
|
return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
|
|
#endif
|
|
}`,F0=`#ifdef USE_LIGHTMAP
|
|
uniform sampler2D lightMap;
|
|
uniform float lightMapIntensity;
|
|
#endif`,N0=`LambertMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;
|
|
material.specularStrength = specularStrength;`,k0=`varying vec3 vViewPosition;
|
|
struct LambertMaterial {
|
|
vec3 diffuseColor;
|
|
float specularStrength;
|
|
};
|
|
void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
|
|
float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
|
|
vec3 irradiance = dotNL * directLight.color;
|
|
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
|
|
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
#define RE_Direct RE_Direct_Lambert
|
|
#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,B0=`uniform bool receiveShadow;
|
|
uniform vec3 ambientLightColor;
|
|
#if defined( USE_LIGHT_PROBES )
|
|
uniform vec3 lightProbe[ 9 ];
|
|
#endif
|
|
vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
|
|
float x = normal.x, y = normal.y, z = normal.z;
|
|
vec3 result = shCoefficients[ 0 ] * 0.886227;
|
|
result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
|
|
result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
|
|
result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
|
|
result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
|
|
result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
|
|
result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
|
|
result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
|
|
result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
|
|
return result;
|
|
}
|
|
vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
|
|
vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
|
|
vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
|
|
return irradiance;
|
|
}
|
|
vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
|
|
vec3 irradiance = ambientLightColor;
|
|
return irradiance;
|
|
}
|
|
float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
|
|
float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
|
|
if ( cutoffDistance > 0.0 ) {
|
|
distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
|
|
}
|
|
return distanceFalloff;
|
|
}
|
|
float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
|
|
return smoothstep( coneCosine, penumbraCosine, angleCosine );
|
|
}
|
|
#if NUM_DIR_LIGHTS > 0
|
|
struct DirectionalLight {
|
|
vec3 direction;
|
|
vec3 color;
|
|
};
|
|
uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
|
|
void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {
|
|
light.color = directionalLight.color;
|
|
light.direction = directionalLight.direction;
|
|
light.visible = true;
|
|
}
|
|
#endif
|
|
#if NUM_POINT_LIGHTS > 0
|
|
struct PointLight {
|
|
vec3 position;
|
|
vec3 color;
|
|
float distance;
|
|
float decay;
|
|
};
|
|
uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
|
|
void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {
|
|
vec3 lVector = pointLight.position - geometryPosition;
|
|
light.direction = normalize( lVector );
|
|
float lightDistance = length( lVector );
|
|
light.color = pointLight.color;
|
|
light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
|
|
light.visible = ( light.color != vec3( 0.0 ) );
|
|
}
|
|
#endif
|
|
#if NUM_SPOT_LIGHTS > 0
|
|
struct SpotLight {
|
|
vec3 position;
|
|
vec3 direction;
|
|
vec3 color;
|
|
float distance;
|
|
float decay;
|
|
float coneCos;
|
|
float penumbraCos;
|
|
};
|
|
uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
|
|
void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {
|
|
vec3 lVector = spotLight.position - geometryPosition;
|
|
light.direction = normalize( lVector );
|
|
float angleCos = dot( light.direction, spotLight.direction );
|
|
float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
|
|
if ( spotAttenuation > 0.0 ) {
|
|
float lightDistance = length( lVector );
|
|
light.color = spotLight.color * spotAttenuation;
|
|
light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
|
|
light.visible = ( light.color != vec3( 0.0 ) );
|
|
} else {
|
|
light.color = vec3( 0.0 );
|
|
light.visible = false;
|
|
}
|
|
}
|
|
#endif
|
|
#if NUM_RECT_AREA_LIGHTS > 0
|
|
struct RectAreaLight {
|
|
vec3 color;
|
|
vec3 position;
|
|
vec3 halfWidth;
|
|
vec3 halfHeight;
|
|
};
|
|
uniform sampler2D ltc_1; uniform sampler2D ltc_2;
|
|
uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
|
|
#endif
|
|
#if NUM_HEMI_LIGHTS > 0
|
|
struct HemisphereLight {
|
|
vec3 direction;
|
|
vec3 skyColor;
|
|
vec3 groundColor;
|
|
};
|
|
uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
|
|
vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {
|
|
float dotNL = dot( normal, hemiLight.direction );
|
|
float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
|
|
vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
|
|
return irradiance;
|
|
}
|
|
#endif
|
|
#include <lightprobes_pars_fragment>`,H0=`#ifdef USE_ENVMAP
|
|
vec3 getIBLIrradiance( const in vec3 normal ) {
|
|
#ifdef ENVMAP_TYPE_CUBE_UV
|
|
vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
|
|
vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );
|
|
return PI * envMapColor.rgb * envMapIntensity;
|
|
#else
|
|
return vec3( 0.0 );
|
|
#endif
|
|
}
|
|
vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
|
|
#ifdef ENVMAP_TYPE_CUBE_UV
|
|
vec3 reflectVec = reflect( - viewDir, normal );
|
|
reflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );
|
|
reflectVec = transformDirectionByInverseViewMatrix( reflectVec, viewMatrix );
|
|
vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );
|
|
return envMapColor.rgb * envMapIntensity;
|
|
#else
|
|
return vec3( 0.0 );
|
|
#endif
|
|
}
|
|
#ifdef USE_ANISOTROPY
|
|
vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
|
|
#ifdef ENVMAP_TYPE_CUBE_UV
|
|
vec3 bentNormal = cross( bitangent, viewDir );
|
|
bentNormal = normalize( cross( bentNormal, bitangent ) );
|
|
bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
|
|
return getIBLRadiance( viewDir, bentNormal, roughness );
|
|
#else
|
|
return vec3( 0.0 );
|
|
#endif
|
|
}
|
|
#endif
|
|
#endif`,z0=`ToonMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;`,G0=`varying vec3 vViewPosition;
|
|
struct ToonMaterial {
|
|
vec3 diffuseColor;
|
|
};
|
|
void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
|
|
vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;
|
|
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
|
|
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
#define RE_Direct RE_Direct_Toon
|
|
#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,V0=`BlinnPhongMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;
|
|
material.specularColor = specular;
|
|
material.specularShininess = shininess;
|
|
material.specularStrength = specularStrength;`,W0=`varying vec3 vViewPosition;
|
|
struct BlinnPhongMaterial {
|
|
vec3 diffuseColor;
|
|
vec3 specularColor;
|
|
float specularShininess;
|
|
float specularStrength;
|
|
};
|
|
void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
|
|
float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
|
|
vec3 irradiance = dotNL * directLight.color;
|
|
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;
|
|
}
|
|
void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
|
|
reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
|
|
}
|
|
#define RE_Direct RE_Direct_BlinnPhong
|
|
#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,X0=`PhysicalMaterial material;
|
|
material.diffuseColor = diffuseColor.rgb;
|
|
material.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor );
|
|
material.metalness = metalnessFactor;
|
|
vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
|
|
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
|
|
material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;
|
|
material.roughness = min( material.roughness, 1.0 );
|
|
#ifdef IOR
|
|
material.ior = ior;
|
|
#ifdef USE_SPECULAR
|
|
float specularIntensityFactor = specularIntensity;
|
|
vec3 specularColorFactor = specularColor;
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;
|
|
#endif
|
|
material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
|
|
#else
|
|
float specularIntensityFactor = 1.0;
|
|
vec3 specularColorFactor = vec3( 1.0 );
|
|
material.specularF90 = 1.0;
|
|
#endif
|
|
material.specularColor = min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor;
|
|
material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );
|
|
#else
|
|
material.specularColor = vec3( 0.04 );
|
|
material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );
|
|
material.specularF90 = 1.0;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
material.clearcoat = clearcoat;
|
|
material.clearcoatRoughness = clearcoatRoughness;
|
|
material.clearcoatF0 = vec3( 0.04 );
|
|
material.clearcoatF90 = 1.0;
|
|
#ifdef USE_CLEARCOATMAP
|
|
material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;
|
|
#endif
|
|
material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
|
|
material.clearcoatRoughness += geometryRoughness;
|
|
material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
|
|
#endif
|
|
#ifdef USE_DISPERSION
|
|
material.dispersion = dispersion;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE
|
|
material.iridescence = iridescence;
|
|
material.iridescenceIOR = iridescenceIOR;
|
|
#ifdef USE_IRIDESCENCEMAP
|
|
material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;
|
|
#else
|
|
material.iridescenceThickness = iridescenceThicknessMaximum;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
material.sheenColor = sheenColor;
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;
|
|
#endif
|
|
material.sheenRoughness = clamp( sheenRoughness, 0.0001, 1.0 );
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_ANISOTROPY
|
|
#ifdef USE_ANISOTROPYMAP
|
|
mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );
|
|
vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;
|
|
vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;
|
|
#else
|
|
vec2 anisotropyV = anisotropyVector;
|
|
#endif
|
|
material.anisotropy = length( anisotropyV );
|
|
if( material.anisotropy == 0.0 ) {
|
|
anisotropyV = vec2( 1.0, 0.0 );
|
|
} else {
|
|
anisotropyV /= material.anisotropy;
|
|
material.anisotropy = saturate( material.anisotropy );
|
|
}
|
|
material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
|
|
material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
|
|
material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
|
|
#endif`,Y0=`uniform sampler2D dfgLUT;
|
|
struct PhysicalMaterial {
|
|
vec3 diffuseColor;
|
|
vec3 diffuseContribution;
|
|
vec3 specularColor;
|
|
vec3 specularColorBlended;
|
|
float roughness;
|
|
float metalness;
|
|
float specularF90;
|
|
float dispersion;
|
|
#ifdef USE_CLEARCOAT
|
|
float clearcoat;
|
|
float clearcoatRoughness;
|
|
vec3 clearcoatF0;
|
|
float clearcoatF90;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE
|
|
float iridescence;
|
|
float iridescenceIOR;
|
|
float iridescenceThickness;
|
|
vec3 iridescenceFresnel;
|
|
vec3 iridescenceF0;
|
|
vec3 iridescenceFresnelDielectric;
|
|
vec3 iridescenceFresnelMetallic;
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
vec3 sheenColor;
|
|
float sheenRoughness;
|
|
#endif
|
|
#ifdef IOR
|
|
float ior;
|
|
#endif
|
|
#ifdef USE_TRANSMISSION
|
|
float transmission;
|
|
float transmissionAlpha;
|
|
float thickness;
|
|
float attenuationDistance;
|
|
vec3 attenuationColor;
|
|
#endif
|
|
#ifdef USE_ANISOTROPY
|
|
float anisotropy;
|
|
float alphaT;
|
|
vec3 anisotropyT;
|
|
vec3 anisotropyB;
|
|
#endif
|
|
};
|
|
vec3 clearcoatSpecularDirect = vec3( 0.0 );
|
|
vec3 clearcoatSpecularIndirect = vec3( 0.0 );
|
|
vec3 sheenSpecularDirect = vec3( 0.0 );
|
|
vec3 sheenSpecularIndirect = vec3(0.0 );
|
|
vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {
|
|
float x = clamp( 1.0 - dotVH, 0.0, 1.0 );
|
|
float x2 = x * x;
|
|
float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );
|
|
return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
|
|
}
|
|
float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
|
|
float a2 = pow2( alpha );
|
|
float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
|
|
float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
|
|
return 0.5 / max( gv + gl, EPSILON );
|
|
}
|
|
float D_GGX( const in float alpha, const in float dotNH ) {
|
|
float a2 = pow2( alpha );
|
|
float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
|
|
return RECIPROCAL_PI * a2 / pow2( denom );
|
|
}
|
|
#ifdef USE_ANISOTROPY
|
|
float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {
|
|
float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );
|
|
float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
|
|
return 0.5 / max( gv + gl, EPSILON );
|
|
}
|
|
float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {
|
|
float a2 = alphaT * alphaB;
|
|
highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );
|
|
highp float v2 = dot( v, v );
|
|
float w2 = a2 / v2;
|
|
return RECIPROCAL_PI * a2 * pow2 ( w2 );
|
|
}
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {
|
|
vec3 f0 = material.clearcoatF0;
|
|
float f90 = material.clearcoatF90;
|
|
float roughness = material.clearcoatRoughness;
|
|
float alpha = pow2( roughness );
|
|
vec3 halfDir = normalize( lightDir + viewDir );
|
|
float dotNL = saturate( dot( normal, lightDir ) );
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
float dotNH = saturate( dot( normal, halfDir ) );
|
|
float dotVH = saturate( dot( viewDir, halfDir ) );
|
|
vec3 F = F_Schlick( f0, f90, dotVH );
|
|
float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
|
|
float D = D_GGX( alpha, dotNH );
|
|
return F * ( V * D );
|
|
}
|
|
#endif
|
|
vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
|
|
vec3 f0 = material.specularColorBlended;
|
|
float f90 = material.specularF90;
|
|
float roughness = material.roughness;
|
|
float alpha = pow2( roughness );
|
|
vec3 halfDir = normalize( lightDir + viewDir );
|
|
float dotNL = saturate( dot( normal, lightDir ) );
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
float dotNH = saturate( dot( normal, halfDir ) );
|
|
float dotVH = saturate( dot( viewDir, halfDir ) );
|
|
vec3 F = F_Schlick( f0, f90, dotVH );
|
|
#ifdef USE_IRIDESCENCE
|
|
F = mix( F, material.iridescenceFresnel, material.iridescence );
|
|
#endif
|
|
#ifdef USE_ANISOTROPY
|
|
float dotTL = dot( material.anisotropyT, lightDir );
|
|
float dotTV = dot( material.anisotropyT, viewDir );
|
|
float dotTH = dot( material.anisotropyT, halfDir );
|
|
float dotBL = dot( material.anisotropyB, lightDir );
|
|
float dotBV = dot( material.anisotropyB, viewDir );
|
|
float dotBH = dot( material.anisotropyB, halfDir );
|
|
float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
|
|
float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );
|
|
#else
|
|
float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
|
|
float D = D_GGX( alpha, dotNH );
|
|
#endif
|
|
return F * ( V * D );
|
|
}
|
|
vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
|
|
const float LUT_SIZE = 64.0;
|
|
const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
|
|
const float LUT_BIAS = 0.5 / LUT_SIZE;
|
|
float dotNV = saturate( dot( N, V ) );
|
|
vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
|
|
uv = uv * LUT_SCALE + LUT_BIAS;
|
|
return uv;
|
|
}
|
|
float LTC_ClippedSphereFormFactor( const in vec3 f ) {
|
|
float l = length( f );
|
|
return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
|
|
}
|
|
vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
|
|
float x = dot( v1, v2 );
|
|
float y = abs( x );
|
|
float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
|
|
float b = 3.4175940 + ( 4.1616724 + y ) * y;
|
|
float v = a / b;
|
|
float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
|
|
return cross( v1, v2 ) * theta_sintheta;
|
|
}
|
|
vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
|
|
vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
|
|
vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
|
|
vec3 lightNormal = cross( v1, v2 );
|
|
if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
|
|
vec3 T1, T2;
|
|
T1 = normalize( V - N * dot( V, N ) );
|
|
T2 = - cross( N, T1 );
|
|
mat3 mat = mInv * transpose( 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 );
|
|
}
|
|
#if defined( USE_SHEEN )
|
|
float D_Charlie( float roughness, float dotNH ) {
|
|
float alpha = pow2( roughness );
|
|
float invAlpha = 1.0 / alpha;
|
|
float cos2h = dotNH * dotNH;
|
|
float sin2h = max( 1.0 - cos2h, 0.0078125 );
|
|
return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
|
|
}
|
|
float V_Neubelt( float dotNV, float dotNL ) {
|
|
return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
|
|
}
|
|
vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
|
|
vec3 halfDir = normalize( lightDir + viewDir );
|
|
float dotNL = saturate( dot( normal, lightDir ) );
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
float dotNH = saturate( dot( normal, halfDir ) );
|
|
float D = D_Charlie( sheenRoughness, dotNH );
|
|
float V = V_Neubelt( dotNV, dotNL );
|
|
return sheenColor * ( D * V );
|
|
}
|
|
#endif
|
|
float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
float r2 = roughness * roughness;
|
|
float rInv = 1.0 / ( roughness + 0.1 );
|
|
float a = -1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv;
|
|
float b = -0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv;
|
|
float DG = exp( a * dotNV + b );
|
|
return saturate( DG );
|
|
}
|
|
vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
vec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;
|
|
return specularColor * fab.x + specularF90 * fab.y;
|
|
}
|
|
#ifdef USE_IRIDESCENCE
|
|
void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
|
|
#else
|
|
void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
|
|
#endif
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
vec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;
|
|
#ifdef USE_IRIDESCENCE
|
|
vec3 Fr = mix( specularColor, iridescenceF0, iridescence );
|
|
#else
|
|
vec3 Fr = specularColor;
|
|
#endif
|
|
vec3 FssEss = Fr * fab.x + specularF90 * fab.y;
|
|
float Ess = fab.x + fab.y;
|
|
float Ems = 1.0 - Ess;
|
|
vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
|
|
singleScatter += FssEss;
|
|
multiScatter += Fms * Ems;
|
|
}
|
|
vec3 BRDF_GGX_Multiscatter( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
|
|
vec3 singleScatter = BRDF_GGX( lightDir, viewDir, normal, material );
|
|
float dotNL = saturate( dot( normal, lightDir ) );
|
|
float dotNV = saturate( dot( normal, viewDir ) );
|
|
vec2 dfgV = texture2D( dfgLUT, vec2( material.roughness, dotNV ) ).rg;
|
|
vec2 dfgL = texture2D( dfgLUT, vec2( material.roughness, dotNL ) ).rg;
|
|
vec3 FssEss_V = material.specularColorBlended * dfgV.x + material.specularF90 * dfgV.y;
|
|
vec3 FssEss_L = material.specularColorBlended * dfgL.x + material.specularF90 * dfgL.y;
|
|
float Ess_V = dfgV.x + dfgV.y;
|
|
float Ess_L = dfgL.x + dfgL.y;
|
|
float Ems_V = 1.0 - Ess_V;
|
|
float Ems_L = 1.0 - Ess_L;
|
|
vec3 Favg = material.specularColorBlended + ( 1.0 - material.specularColorBlended ) * 0.047619;
|
|
vec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg + EPSILON );
|
|
float compensationFactor = Ems_V * Ems_L;
|
|
vec3 multiScatter = Fms * compensationFactor;
|
|
return singleScatter + multiScatter;
|
|
}
|
|
#if NUM_RECT_AREA_LIGHTS > 0
|
|
void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
|
|
vec3 normal = geometryNormal;
|
|
vec3 viewDir = geometryViewDir;
|
|
vec3 position = geometryPosition;
|
|
vec3 lightPos = rectAreaLight.position;
|
|
vec3 halfWidth = rectAreaLight.halfWidth;
|
|
vec3 halfHeight = rectAreaLight.halfHeight;
|
|
vec3 lightColor = rectAreaLight.color;
|
|
float roughness = material.roughness;
|
|
vec3 rectCoords[ 4 ];
|
|
rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
|
|
rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
|
|
rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
|
|
vec2 uv = LTC_Uv( normal, viewDir, roughness );
|
|
vec4 t1 = texture2D( ltc_1, uv );
|
|
vec4 t2 = texture2D( ltc_2, uv );
|
|
mat3 mInv = mat3(
|
|
vec3( t1.x, 0, t1.y ),
|
|
vec3( 0, 1, 0 ),
|
|
vec3( t1.z, 0, t1.w )
|
|
);
|
|
vec3 fresnel = ( material.specularColorBlended * t2.x + ( material.specularF90 - material.specularColorBlended ) * t2.y );
|
|
reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
|
|
reflectedLight.directDiffuse += lightColor * material.diffuseContribution * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
|
|
#ifdef USE_CLEARCOAT
|
|
vec3 Ncc = geometryClearcoatNormal;
|
|
vec2 uvClearcoat = LTC_Uv( Ncc, viewDir, material.clearcoatRoughness );
|
|
vec4 t1Clearcoat = texture2D( ltc_1, uvClearcoat );
|
|
vec4 t2Clearcoat = texture2D( ltc_2, uvClearcoat );
|
|
mat3 mInvClearcoat = mat3(
|
|
vec3( t1Clearcoat.x, 0, t1Clearcoat.y ),
|
|
vec3( 0, 1, 0 ),
|
|
vec3( t1Clearcoat.z, 0, t1Clearcoat.w )
|
|
);
|
|
vec3 fresnelClearcoat = material.clearcoatF0 * t2Clearcoat.x + ( material.clearcoatF90 - material.clearcoatF0 ) * t2Clearcoat.y;
|
|
clearcoatSpecularDirect += lightColor * fresnelClearcoat * LTC_Evaluate( Ncc, viewDir, position, mInvClearcoat, rectCoords );
|
|
#endif
|
|
}
|
|
#endif
|
|
void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
|
|
float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
|
|
vec3 irradiance = dotNL * directLight.color;
|
|
#ifdef USE_CLEARCOAT
|
|
float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );
|
|
vec3 ccIrradiance = dotNLcc * directLight.color;
|
|
clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
|
|
sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );
|
|
|
|
float sheenAlbedoV = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
|
|
float sheenAlbedoL = IBLSheenBRDF( geometryNormal, directLight.direction, material.sheenRoughness );
|
|
|
|
float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * max( sheenAlbedoV, sheenAlbedoL );
|
|
|
|
irradiance *= sheenEnergyComp;
|
|
|
|
#endif
|
|
reflectedLight.directSpecular += irradiance * BRDF_GGX_Multiscatter( directLight.direction, geometryViewDir, geometryNormal, material );
|
|
reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseContribution );
|
|
}
|
|
void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
|
|
vec3 diffuse = irradiance * BRDF_Lambert( material.diffuseContribution );
|
|
#ifdef USE_SHEEN
|
|
float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
|
|
float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;
|
|
diffuse *= sheenEnergyComp;
|
|
#endif
|
|
reflectedLight.indirectDiffuse += diffuse;
|
|
}
|
|
void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
|
|
#ifdef USE_CLEARCOAT
|
|
clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ) * RECIPROCAL_PI;
|
|
#endif
|
|
vec3 singleScatteringDielectric = vec3( 0.0 );
|
|
vec3 multiScatteringDielectric = vec3( 0.0 );
|
|
vec3 singleScatteringMetallic = vec3( 0.0 );
|
|
vec3 multiScatteringMetallic = vec3( 0.0 );
|
|
#ifdef USE_IRIDESCENCE
|
|
computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnelDielectric, material.roughness, singleScatteringDielectric, multiScatteringDielectric );
|
|
computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.iridescence, material.iridescenceFresnelMetallic, material.roughness, singleScatteringMetallic, multiScatteringMetallic );
|
|
#else
|
|
computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScatteringDielectric, multiScatteringDielectric );
|
|
computeMultiscattering( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.roughness, singleScatteringMetallic, multiScatteringMetallic );
|
|
#endif
|
|
vec3 singleScattering = mix( singleScatteringDielectric, singleScatteringMetallic, material.metalness );
|
|
vec3 multiScattering = mix( multiScatteringDielectric, multiScatteringMetallic, material.metalness );
|
|
vec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric;
|
|
vec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric );
|
|
vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
|
|
vec3 indirectSpecular = radiance * singleScattering;
|
|
indirectSpecular += multiScattering * cosineWeightedIrradiance;
|
|
vec3 indirectDiffuse = diffuse * cosineWeightedIrradiance;
|
|
#ifdef USE_SHEEN
|
|
float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
|
|
float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;
|
|
indirectSpecular *= sheenEnergyComp;
|
|
indirectDiffuse *= sheenEnergyComp;
|
|
#endif
|
|
reflectedLight.indirectSpecular += indirectSpecular;
|
|
reflectedLight.indirectDiffuse += indirectDiffuse;
|
|
}
|
|
#define RE_Direct RE_Direct_Physical
|
|
#define RE_Direct_RectArea RE_Direct_RectArea_Physical
|
|
#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
|
|
#define RE_IndirectSpecular RE_IndirectSpecular_Physical
|
|
float 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 );
|
|
}`,q0=`
|
|
vec3 geometryPosition = - vViewPosition;
|
|
vec3 geometryNormal = normal;
|
|
vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
|
|
vec3 geometryClearcoatNormal = vec3( 0.0 );
|
|
#ifdef USE_CLEARCOAT
|
|
geometryClearcoatNormal = clearcoatNormal;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE
|
|
float dotNVi = saturate( dot( normal, geometryViewDir ) );
|
|
if ( material.iridescenceThickness == 0.0 ) {
|
|
material.iridescence = 0.0;
|
|
} else {
|
|
material.iridescence = saturate( material.iridescence );
|
|
}
|
|
if ( material.iridescence > 0.0 ) {
|
|
material.iridescenceFresnelDielectric = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
|
|
material.iridescenceFresnelMetallic = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.diffuseColor );
|
|
material.iridescenceFresnel = mix( material.iridescenceFresnelDielectric, material.iridescenceFresnelMetallic, material.metalness );
|
|
material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );
|
|
}
|
|
#endif
|
|
IncidentLight directLight;
|
|
#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
|
|
PointLight pointLight;
|
|
#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
|
|
PointLightShadow pointLightShadow;
|
|
#endif
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
|
|
pointLight = pointLights[ i ];
|
|
getPointLightInfo( pointLight, geometryPosition, directLight );
|
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )
|
|
pointLightShadow = pointLightShadows[ i ];
|
|
directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
|
|
#endif
|
|
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
|
|
SpotLight spotLight;
|
|
vec4 spotColor;
|
|
vec3 spotLightCoord;
|
|
bool inSpotLightMap;
|
|
#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
|
|
SpotLightShadow spotLightShadow;
|
|
#endif
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
|
|
spotLight = spotLights[ i ];
|
|
getSpotLightInfo( spotLight, geometryPosition, directLight );
|
|
#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
|
|
#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX
|
|
#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
|
#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS
|
|
#else
|
|
#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
|
|
#endif
|
|
#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )
|
|
spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;
|
|
inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );
|
|
spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );
|
|
directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;
|
|
#endif
|
|
#undef SPOT_LIGHT_MAP_INDEX
|
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
|
spotLightShadow = spotLightShadows[ i ];
|
|
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
|
|
#endif
|
|
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
|
|
DirectionalLight directionalLight;
|
|
#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
|
|
DirectionalLightShadow directionalLightShadow;
|
|
#endif
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
|
|
directionalLight = directionalLights[ i ];
|
|
getDirectionalLightInfo( directionalLight, directLight );
|
|
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
|
|
directionalLightShadow = directionalLightShadows[ i ];
|
|
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
#endif
|
|
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
|
|
RectAreaLight rectAreaLight;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
|
|
rectAreaLight = rectAreaLights[ i ];
|
|
RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if defined( RE_IndirectDiffuse )
|
|
vec3 iblIrradiance = vec3( 0.0 );
|
|
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
|
|
#if defined( USE_LIGHT_PROBES )
|
|
irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
|
|
#endif
|
|
#if ( NUM_HEMI_LIGHTS > 0 )
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
|
|
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#ifdef USE_LIGHT_PROBES_GRID
|
|
vec3 probeWorldPos = ( ( vec4( geometryPosition, 1.0 ) - viewMatrix[ 3 ] ) * viewMatrix ).xyz;
|
|
vec3 probeWorldNormal = transformNormalByInverseViewMatrix( geometryNormal, viewMatrix );
|
|
irradiance += getLightProbeGridIrradiance( probeWorldPos, probeWorldNormal );
|
|
#endif
|
|
#endif
|
|
#if defined( RE_IndirectSpecular )
|
|
vec3 radiance = vec3( 0.0 );
|
|
vec3 clearcoatRadiance = vec3( 0.0 );
|
|
#endif`,$0=`#if defined( RE_IndirectDiffuse )
|
|
#ifdef USE_LIGHTMAP
|
|
vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
|
|
vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
|
|
irradiance += lightMapIrradiance;
|
|
#endif
|
|
#if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_CUBE_UV )
|
|
#if defined( STANDARD ) || defined( LAMBERT ) || defined( PHONG )
|
|
iblIrradiance += getIBLIrradiance( geometryNormal );
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
|
|
#ifdef USE_ANISOTROPY
|
|
radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
|
|
#else
|
|
radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
|
|
#endif
|
|
#endif`,Z0=`#if defined( RE_IndirectDiffuse )
|
|
#if defined( LAMBERT ) || defined( PHONG )
|
|
irradiance += iblIrradiance;
|
|
#endif
|
|
RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
#endif
|
|
#if defined( RE_IndirectSpecular )
|
|
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
|
|
#endif`,K0=`#ifdef USE_LIGHT_PROBES_GRID
|
|
uniform highp sampler3D probesSH;
|
|
uniform vec3 probesMin;
|
|
uniform vec3 probesMax;
|
|
uniform vec3 probesResolution;
|
|
vec3 getLightProbeGridIrradiance( vec3 worldPos, vec3 worldNormal ) {
|
|
vec3 res = probesResolution;
|
|
vec3 gridRange = probesMax - probesMin;
|
|
vec3 resMinusOne = res - 1.0;
|
|
vec3 probeSpacing = gridRange / resMinusOne;
|
|
vec3 samplePos = worldPos + worldNormal * probeSpacing * 0.5;
|
|
vec3 uvw = clamp( ( samplePos - probesMin ) / gridRange, 0.0, 1.0 );
|
|
uvw = uvw * resMinusOne / res + 0.5 / res;
|
|
float nz = res.z;
|
|
float paddedSlices = nz + 2.0;
|
|
float atlasDepth = 7.0 * paddedSlices;
|
|
float uvZBase = uvw.z * nz + 1.0;
|
|
vec4 s0 = texture( probesSH, vec3( uvw.xy, ( uvZBase ) / atlasDepth ) );
|
|
vec4 s1 = texture( probesSH, vec3( uvw.xy, ( uvZBase + paddedSlices ) / atlasDepth ) );
|
|
vec4 s2 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 2.0 * paddedSlices ) / atlasDepth ) );
|
|
vec4 s3 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 3.0 * paddedSlices ) / atlasDepth ) );
|
|
vec4 s4 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 4.0 * paddedSlices ) / atlasDepth ) );
|
|
vec4 s5 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 5.0 * paddedSlices ) / atlasDepth ) );
|
|
vec4 s6 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 6.0 * paddedSlices ) / atlasDepth ) );
|
|
vec3 c0 = s0.xyz;
|
|
vec3 c1 = vec3( s0.w, s1.xy );
|
|
vec3 c2 = vec3( s1.zw, s2.x );
|
|
vec3 c3 = s2.yzw;
|
|
vec3 c4 = s3.xyz;
|
|
vec3 c5 = vec3( s3.w, s4.xy );
|
|
vec3 c6 = vec3( s4.zw, s5.x );
|
|
vec3 c7 = s5.yzw;
|
|
vec3 c8 = s6.xyz;
|
|
float x = worldNormal.x, y = worldNormal.y, z = worldNormal.z;
|
|
vec3 result = c0 * 0.886227;
|
|
result += c1 * 2.0 * 0.511664 * y;
|
|
result += c2 * 2.0 * 0.511664 * z;
|
|
result += c3 * 2.0 * 0.511664 * x;
|
|
result += c4 * 2.0 * 0.429043 * x * y;
|
|
result += c5 * 2.0 * 0.429043 * y * z;
|
|
result += c6 * ( 0.743125 * z * z - 0.247708 );
|
|
result += c7 * 2.0 * 0.429043 * x * z;
|
|
result += c8 * 0.429043 * ( x * x - y * y );
|
|
return max( result, vec3( 0.0 ) );
|
|
}
|
|
#endif`,J0=`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
|
|
gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
|
|
#endif`,j0=`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
|
|
uniform float logDepthBufFC;
|
|
varying float vFragDepth;
|
|
varying float vIsPerspective;
|
|
#endif`,Q0=`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER
|
|
varying float vFragDepth;
|
|
varying float vIsPerspective;
|
|
#endif`,ex=`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER
|
|
vFragDepth = 1.0 + gl_Position.w;
|
|
vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
|
|
#endif`,tx=`#ifdef USE_MAP
|
|
vec4 sampledDiffuseColor = texture2D( map, vMapUv );
|
|
#ifdef DECODE_VIDEO_TEXTURE
|
|
sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
|
|
#endif
|
|
diffuseColor *= sampledDiffuseColor;
|
|
#endif`,nx=`#ifdef USE_MAP
|
|
uniform sampler2D map;
|
|
#endif`,ix=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
|
|
#if defined( USE_POINTS_UV )
|
|
vec2 uv = vUv;
|
|
#else
|
|
vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_MAP
|
|
diffuseColor *= texture2D( map, uv );
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
diffuseColor.a *= texture2D( alphaMap, uv ).g;
|
|
#endif`,sx=`#if defined( USE_POINTS_UV )
|
|
varying vec2 vUv;
|
|
#else
|
|
#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
|
|
uniform mat3 uvTransform;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_MAP
|
|
uniform sampler2D map;
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
uniform sampler2D alphaMap;
|
|
#endif`,rx=`float metalnessFactor = metalness;
|
|
#ifdef USE_METALNESSMAP
|
|
vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
|
|
metalnessFactor *= texelMetalness.b;
|
|
#endif`,ax=`#ifdef USE_METALNESSMAP
|
|
uniform sampler2D metalnessMap;
|
|
#endif`,ox=`#ifdef USE_INSTANCING_MORPH
|
|
float morphTargetInfluences[ MORPHTARGETS_COUNT ];
|
|
float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;
|
|
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
|
|
morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;
|
|
}
|
|
#endif`,lx=`#if defined( USE_MORPHCOLORS )
|
|
vColor *= morphTargetBaseInfluence;
|
|
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
|
|
#if defined( USE_COLOR_ALPHA )
|
|
if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
|
|
#elif defined( USE_COLOR )
|
|
if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
|
|
#endif
|
|
}
|
|
#endif`,cx=`#ifdef USE_MORPHNORMALS
|
|
objectNormal *= morphTargetBaseInfluence;
|
|
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
|
|
if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
|
|
}
|
|
#endif`,ux=`#ifdef USE_MORPHTARGETS
|
|
#ifndef USE_INSTANCING_MORPH
|
|
uniform float morphTargetBaseInfluence;
|
|
uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
|
|
#endif
|
|
uniform sampler2DArray morphTargetsTexture;
|
|
uniform ivec2 morphTargetsTextureSize;
|
|
vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {
|
|
int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;
|
|
int y = texelIndex / morphTargetsTextureSize.x;
|
|
int x = texelIndex - y * morphTargetsTextureSize.x;
|
|
ivec3 morphUV = ivec3( x, y, morphTargetIndex );
|
|
return texelFetch( morphTargetsTexture, morphUV, 0 );
|
|
}
|
|
#endif`,hx=`#ifdef USE_MORPHTARGETS
|
|
transformed *= morphTargetBaseInfluence;
|
|
for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
|
|
if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
|
|
}
|
|
#endif`,fx=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
|
|
#ifdef FLAT_SHADED
|
|
vec3 fdx = dFdx( vViewPosition );
|
|
vec3 fdy = dFdy( vViewPosition );
|
|
vec3 normal = normalize( cross( fdx, fdy ) );
|
|
#else
|
|
vec3 normal = normalize( vNormal );
|
|
#ifdef DOUBLE_SIDED
|
|
normal *= faceDirection;
|
|
#endif
|
|
#endif
|
|
#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )
|
|
#ifdef USE_TANGENT
|
|
mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
|
|
#else
|
|
mat3 tbn = getTangentFrame( - vViewPosition, normal,
|
|
#if defined( USE_NORMALMAP )
|
|
vNormalMapUv
|
|
#elif defined( USE_CLEARCOAT_NORMALMAP )
|
|
vClearcoatNormalMapUv
|
|
#else
|
|
vUv
|
|
#endif
|
|
);
|
|
#endif
|
|
#ifdef DOUBLE_SIDED
|
|
tbn[0] *= faceDirection;
|
|
tbn[1] *= faceDirection;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
#ifdef USE_TANGENT
|
|
mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
|
|
#else
|
|
mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
|
|
#endif
|
|
#ifdef DOUBLE_SIDED
|
|
tbn2[0] *= faceDirection;
|
|
tbn2[1] *= faceDirection;
|
|
#endif
|
|
#endif
|
|
vec3 nonPerturbedNormal = normal;`,dx=`#ifdef USE_NORMALMAP_OBJECTSPACE
|
|
normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
|
|
#ifdef FLIP_SIDED
|
|
normal = - normal;
|
|
#endif
|
|
#ifdef DOUBLE_SIDED
|
|
normal = normal * faceDirection;
|
|
#endif
|
|
normal = normalize( normalMatrix * normal );
|
|
#elif defined( USE_NORMALMAP_TANGENTSPACE )
|
|
vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
|
|
#if defined( USE_PACKED_NORMALMAP )
|
|
mapN = vec3( mapN.xy, sqrt( saturate( 1.0 - dot( mapN.xy, mapN.xy ) ) ) );
|
|
#endif
|
|
mapN.xy *= normalScale;
|
|
normal = normalize( tbn * mapN );
|
|
#elif defined( USE_BUMPMAP )
|
|
normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
|
|
#endif`,px=`#ifndef FLAT_SHADED
|
|
varying vec3 vNormal;
|
|
#ifdef USE_TANGENT
|
|
varying vec3 vTangent;
|
|
varying vec3 vBitangent;
|
|
#endif
|
|
#endif`,mx=`#ifndef FLAT_SHADED
|
|
varying vec3 vNormal;
|
|
#ifdef USE_TANGENT
|
|
varying vec3 vTangent;
|
|
varying vec3 vBitangent;
|
|
#endif
|
|
#endif`,gx=`#ifndef FLAT_SHADED
|
|
vNormal = normalize( transformedNormal );
|
|
#ifdef USE_TANGENT
|
|
vTangent = normalize( transformedTangent );
|
|
vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
|
|
#ifdef FLIP_SIDED
|
|
vBitangent = - vBitangent;
|
|
#endif
|
|
#endif
|
|
#endif`,xx=`#ifdef USE_NORMALMAP
|
|
uniform sampler2D normalMap;
|
|
uniform vec2 normalScale;
|
|
#endif
|
|
#ifdef USE_NORMALMAP_OBJECTSPACE
|
|
uniform mat3 normalMatrix;
|
|
#endif
|
|
#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )
|
|
mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {
|
|
vec3 q0 = dFdx( eye_pos.xyz );
|
|
vec3 q1 = dFdy( eye_pos.xyz );
|
|
vec2 st0 = dFdx( uv.st );
|
|
vec2 st1 = dFdy( uv.st );
|
|
vec3 N = surf_norm;
|
|
vec3 q1perp = cross( q1, N );
|
|
vec3 q0perp = cross( N, q0 );
|
|
vec3 T = q1perp * st0.x + q0perp * st1.x;
|
|
vec3 B = q1perp * st0.y + q0perp * st1.y;
|
|
float det = max( dot( T, T ), dot( B, B ) );
|
|
float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
|
|
return mat3( T * scale, B * scale, N );
|
|
}
|
|
#endif`,vx=`#ifdef USE_CLEARCOAT
|
|
vec3 clearcoatNormal = nonPerturbedNormal;
|
|
#endif`,yx=`#ifdef USE_CLEARCOAT_NORMALMAP
|
|
vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
|
|
clearcoatMapN.xy *= clearcoatNormalScale;
|
|
clearcoatNormal = normalize( tbn2 * clearcoatMapN );
|
|
#endif`,_x=`#ifdef USE_CLEARCOATMAP
|
|
uniform sampler2D clearcoatMap;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
uniform sampler2D clearcoatNormalMap;
|
|
uniform vec2 clearcoatNormalScale;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
uniform sampler2D clearcoatRoughnessMap;
|
|
#endif`,bx=`#ifdef USE_IRIDESCENCEMAP
|
|
uniform sampler2D iridescenceMap;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
uniform sampler2D iridescenceThicknessMap;
|
|
#endif`,Sx=`#ifdef OPAQUE
|
|
diffuseColor.a = 1.0;
|
|
#endif
|
|
#ifdef USE_TRANSMISSION
|
|
diffuseColor.a *= material.transmissionAlpha;
|
|
#endif
|
|
gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,Mx=`vec3 packNormalToRGB( const in vec3 normal ) {
|
|
return normalize( normal ) * 0.5 + 0.5;
|
|
}
|
|
vec3 unpackRGBToNormal( const in vec3 rgb ) {
|
|
return 2.0 * rgb.xyz - 1.0;
|
|
}
|
|
const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;
|
|
const float Inv255 = 1. / 255.;
|
|
const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );
|
|
const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );
|
|
const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );
|
|
const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );
|
|
vec4 packDepthToRGBA( const in float v ) {
|
|
if( v <= 0.0 )
|
|
return vec4( 0., 0., 0., 0. );
|
|
if( v >= 1.0 )
|
|
return vec4( 1., 1., 1., 1. );
|
|
float vuf;
|
|
float af = modf( v * PackFactors.a, vuf );
|
|
float bf = modf( vuf * ShiftRight8, vuf );
|
|
float gf = modf( vuf * ShiftRight8, vuf );
|
|
return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );
|
|
}
|
|
vec3 packDepthToRGB( const in float v ) {
|
|
if( v <= 0.0 )
|
|
return vec3( 0., 0., 0. );
|
|
if( v >= 1.0 )
|
|
return vec3( 1., 1., 1. );
|
|
float vuf;
|
|
float bf = modf( v * PackFactors.b, vuf );
|
|
float gf = modf( vuf * ShiftRight8, vuf );
|
|
return vec3( vuf * Inv255, gf * PackUpscale, bf );
|
|
}
|
|
vec2 packDepthToRG( const in float v ) {
|
|
if( v <= 0.0 )
|
|
return vec2( 0., 0. );
|
|
if( v >= 1.0 )
|
|
return vec2( 1., 1. );
|
|
float vuf;
|
|
float gf = modf( v * 256., vuf );
|
|
return vec2( vuf * Inv255, gf );
|
|
}
|
|
float unpackRGBAToDepth( const in vec4 v ) {
|
|
return dot( v, UnpackFactors4 );
|
|
}
|
|
float unpackRGBToDepth( const in vec3 v ) {
|
|
return dot( v, UnpackFactors3 );
|
|
}
|
|
float unpackRGToDepth( const in vec2 v ) {
|
|
return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;
|
|
}
|
|
vec4 pack2HalfToRGBA( const in vec2 v ) {
|
|
vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
|
|
return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
|
|
}
|
|
vec2 unpackRGBATo2Half( const in vec4 v ) {
|
|
return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
|
|
}
|
|
float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
|
|
return ( viewZ + near ) / ( near - far );
|
|
}
|
|
float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
|
|
return depth * ( far - near ) - far;
|
|
#else
|
|
return depth * ( near - far ) - near;
|
|
#endif
|
|
}
|
|
float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
|
|
return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
|
|
}
|
|
float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
|
|
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
return ( near * far ) / ( ( near - far ) * depth - near );
|
|
#else
|
|
return ( near * far ) / ( ( far - near ) * depth - far );
|
|
#endif
|
|
}`,Ex=`#ifdef PREMULTIPLIED_ALPHA
|
|
gl_FragColor.rgb *= gl_FragColor.a;
|
|
#endif`,Tx=`vec4 mvPosition = vec4( transformed, 1.0 );
|
|
#ifdef USE_BATCHING
|
|
mvPosition = batchingMatrix * mvPosition;
|
|
#endif
|
|
#ifdef USE_INSTANCING
|
|
mvPosition = instanceMatrix * mvPosition;
|
|
#endif
|
|
mvPosition = modelViewMatrix * mvPosition;
|
|
gl_Position = projectionMatrix * mvPosition;`,Ax=`#ifdef DITHERING
|
|
gl_FragColor.rgb = dithering( gl_FragColor.rgb );
|
|
#endif`,wx=`#ifdef DITHERING
|
|
vec3 dithering( vec3 color ) {
|
|
float grid_position = rand( gl_FragCoord.xy );
|
|
vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
|
|
dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
|
|
return color + dither_shift_RGB;
|
|
}
|
|
#endif`,Cx=`float roughnessFactor = roughness;
|
|
#ifdef USE_ROUGHNESSMAP
|
|
vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
|
|
roughnessFactor *= texelRoughness.g;
|
|
#endif`,Rx=`#ifdef USE_ROUGHNESSMAP
|
|
uniform sampler2D roughnessMap;
|
|
#endif`,Px=`#if NUM_SPOT_LIGHT_COORDS > 0
|
|
varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_MAPS > 0
|
|
uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];
|
|
#endif
|
|
#ifdef USE_SHADOWMAP
|
|
#if NUM_DIR_LIGHT_SHADOWS > 0
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
uniform sampler2DShadow directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
|
|
#else
|
|
uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
|
|
#endif
|
|
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
|
|
struct DirectionalLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
};
|
|
uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_SHADOWS > 0
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
uniform sampler2DShadow spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
|
|
#else
|
|
uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
|
|
#endif
|
|
struct SpotLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
};
|
|
uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
uniform samplerCubeShadow pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
|
|
#elif defined( SHADOWMAP_TYPE_BASIC )
|
|
uniform samplerCube pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
|
|
#endif
|
|
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
|
|
struct PointLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
float shadowCameraNear;
|
|
float shadowCameraFar;
|
|
};
|
|
uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
float interleavedGradientNoise( vec2 position ) {
|
|
return fract( 52.9829189 * fract( dot( position, vec2( 0.06711056, 0.00583715 ) ) ) );
|
|
}
|
|
vec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) {
|
|
const float goldenAngle = 2.399963229728653;
|
|
float r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) );
|
|
float theta = float( sampleIndex ) * goldenAngle + phi;
|
|
return vec2( cos( theta ), sin( theta ) ) * r;
|
|
}
|
|
#endif
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
float getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
|
|
float shadow = 1.0;
|
|
shadowCoord.xyz /= shadowCoord.w;
|
|
shadowCoord.z += shadowBias;
|
|
bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
|
|
bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
|
|
if ( frustumTest ) {
|
|
vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
|
|
float radius = shadowRadius * texelSize.x;
|
|
float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;
|
|
shadow = (
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 0, 5, phi ) * radius, shadowCoord.z ) ) +
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 1, 5, phi ) * radius, shadowCoord.z ) ) +
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 2, 5, phi ) * radius, shadowCoord.z ) ) +
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 3, 5, phi ) * radius, shadowCoord.z ) ) +
|
|
texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 4, 5, phi ) * radius, shadowCoord.z ) )
|
|
) * 0.2;
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#elif defined( SHADOWMAP_TYPE_VSM )
|
|
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
|
|
float shadow = 1.0;
|
|
shadowCoord.xyz /= shadowCoord.w;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
shadowCoord.z -= shadowBias;
|
|
#else
|
|
shadowCoord.z += shadowBias;
|
|
#endif
|
|
bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
|
|
bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
|
|
if ( frustumTest ) {
|
|
vec2 distribution = texture2D( shadowMap, shadowCoord.xy ).rg;
|
|
float mean = distribution.x;
|
|
float variance = distribution.y * distribution.y;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
float hard_shadow = step( mean, shadowCoord.z );
|
|
#else
|
|
float hard_shadow = step( shadowCoord.z, mean );
|
|
#endif
|
|
|
|
if ( hard_shadow == 1.0 ) {
|
|
shadow = 1.0;
|
|
} else {
|
|
variance = max( variance, 0.0000001 );
|
|
float d = shadowCoord.z - mean;
|
|
float p_max = variance / ( variance + d * d );
|
|
p_max = clamp( ( p_max - 0.3 ) / 0.65, 0.0, 1.0 );
|
|
shadow = max( hard_shadow, p_max );
|
|
}
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#else
|
|
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
|
|
float shadow = 1.0;
|
|
shadowCoord.xyz /= shadowCoord.w;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
shadowCoord.z -= shadowBias;
|
|
#else
|
|
shadowCoord.z += shadowBias;
|
|
#endif
|
|
bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
|
|
bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
|
|
if ( frustumTest ) {
|
|
float depth = texture2D( shadowMap, shadowCoord.xy ).r;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
shadow = step( depth, shadowCoord.z );
|
|
#else
|
|
shadow = step( shadowCoord.z, depth );
|
|
#endif
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0
|
|
#if defined( SHADOWMAP_TYPE_PCF )
|
|
float getPointShadow( samplerCubeShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
|
|
float shadow = 1.0;
|
|
vec3 lightToPosition = shadowCoord.xyz;
|
|
vec3 bd3D = normalize( lightToPosition );
|
|
vec3 absVec = abs( lightToPosition );
|
|
float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );
|
|
if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
float dp = ( shadowCameraNear * ( shadowCameraFar - viewSpaceZ ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );
|
|
dp -= shadowBias;
|
|
#else
|
|
float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );
|
|
dp += shadowBias;
|
|
#endif
|
|
float texelSize = shadowRadius / shadowMapSize.x;
|
|
vec3 absDir = abs( bd3D );
|
|
vec3 tangent = absDir.x > absDir.z ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 );
|
|
tangent = normalize( cross( bd3D, tangent ) );
|
|
vec3 bitangent = cross( bd3D, tangent );
|
|
float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;
|
|
vec2 sample0 = vogelDiskSample( 0, 5, phi );
|
|
vec2 sample1 = vogelDiskSample( 1, 5, phi );
|
|
vec2 sample2 = vogelDiskSample( 2, 5, phi );
|
|
vec2 sample3 = vogelDiskSample( 3, 5, phi );
|
|
vec2 sample4 = vogelDiskSample( 4, 5, phi );
|
|
shadow = (
|
|
texture( shadowMap, vec4( bd3D + ( tangent * sample0.x + bitangent * sample0.y ) * texelSize, dp ) ) +
|
|
texture( shadowMap, vec4( bd3D + ( tangent * sample1.x + bitangent * sample1.y ) * texelSize, dp ) ) +
|
|
texture( shadowMap, vec4( bd3D + ( tangent * sample2.x + bitangent * sample2.y ) * texelSize, dp ) ) +
|
|
texture( shadowMap, vec4( bd3D + ( tangent * sample3.x + bitangent * sample3.y ) * texelSize, dp ) ) +
|
|
texture( shadowMap, vec4( bd3D + ( tangent * sample4.x + bitangent * sample4.y ) * texelSize, dp ) )
|
|
) * 0.2;
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#elif defined( SHADOWMAP_TYPE_BASIC )
|
|
float getPointShadow( samplerCube shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
|
|
float shadow = 1.0;
|
|
vec3 lightToPosition = shadowCoord.xyz;
|
|
vec3 absVec = abs( lightToPosition );
|
|
float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );
|
|
if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
|
|
float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );
|
|
dp += shadowBias;
|
|
vec3 bd3D = normalize( lightToPosition );
|
|
float depth = textureCube( shadowMap, bd3D ).r;
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
depth = 1.0 - depth;
|
|
#endif
|
|
shadow = step( dp, depth );
|
|
}
|
|
return mix( 1.0, shadow, shadowIntensity );
|
|
}
|
|
#endif
|
|
#endif
|
|
#endif`,Lx=`#if NUM_SPOT_LIGHT_COORDS > 0
|
|
uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
|
|
varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
|
|
#endif
|
|
#ifdef USE_SHADOWMAP
|
|
#if NUM_DIR_LIGHT_SHADOWS > 0
|
|
uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
|
|
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
|
|
struct DirectionalLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
};
|
|
uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_SHADOWS > 0
|
|
struct SpotLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
};
|
|
uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0
|
|
uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
|
|
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
|
|
struct PointLightShadow {
|
|
float shadowIntensity;
|
|
float shadowBias;
|
|
float shadowNormalBias;
|
|
float shadowRadius;
|
|
vec2 shadowMapSize;
|
|
float shadowCameraNear;
|
|
float shadowCameraFar;
|
|
};
|
|
uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
|
|
#endif
|
|
#endif`,Dx=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
|
|
#ifdef HAS_NORMAL
|
|
vec3 shadowWorldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );
|
|
#else
|
|
vec3 shadowWorldNormal = vec3( 0.0 );
|
|
#endif
|
|
vec4 shadowWorldPosition;
|
|
#endif
|
|
#if defined( USE_SHADOWMAP )
|
|
#if NUM_DIR_LIGHT_SHADOWS > 0
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
|
|
shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
|
|
vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
|
|
shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
|
|
vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_COORDS > 0
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {
|
|
shadowWorldPosition = worldPosition;
|
|
#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
|
|
shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;
|
|
#endif
|
|
vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif`,Ix=`float getShadowMask() {
|
|
float shadow = 1.0;
|
|
#ifdef USE_SHADOWMAP
|
|
#if NUM_DIR_LIGHT_SHADOWS > 0
|
|
DirectionalLightShadow directionalLight;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
|
|
directionalLight = directionalLightShadows[ i ];
|
|
shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if NUM_SPOT_LIGHT_SHADOWS > 0
|
|
SpotLightShadow spotLight;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
|
|
spotLight = spotLightShadows[ i ];
|
|
shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#if NUM_POINT_LIGHT_SHADOWS > 0 && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )
|
|
PointLightShadow pointLight;
|
|
#pragma unroll_loop_start
|
|
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
|
|
pointLight = pointLightShadows[ i ];
|
|
shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
|
|
}
|
|
#pragma unroll_loop_end
|
|
#endif
|
|
#endif
|
|
return shadow;
|
|
}`,Ux=`#ifdef USE_SKINNING
|
|
mat4 boneMatX = getBoneMatrix( skinIndex.x );
|
|
mat4 boneMatY = getBoneMatrix( skinIndex.y );
|
|
mat4 boneMatZ = getBoneMatrix( skinIndex.z );
|
|
mat4 boneMatW = getBoneMatrix( skinIndex.w );
|
|
#endif`,Ox=`#ifdef USE_SKINNING
|
|
uniform mat4 bindMatrix;
|
|
uniform mat4 bindMatrixInverse;
|
|
uniform highp sampler2D boneTexture;
|
|
mat4 getBoneMatrix( const in float i ) {
|
|
int size = textureSize( boneTexture, 0 ).x;
|
|
int j = int( i ) * 4;
|
|
int x = j % size;
|
|
int y = j / size;
|
|
vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );
|
|
vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );
|
|
vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );
|
|
vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
|
|
return mat4( v1, v2, v3, v4 );
|
|
}
|
|
#endif`,Fx=`#ifdef USE_SKINNING
|
|
vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
|
|
vec4 skinned = vec4( 0.0 );
|
|
skinned += boneMatX * skinVertex * skinWeight.x;
|
|
skinned += boneMatY * skinVertex * skinWeight.y;
|
|
skinned += boneMatZ * skinVertex * skinWeight.z;
|
|
skinned += boneMatW * skinVertex * skinWeight.w;
|
|
transformed = ( bindMatrixInverse * skinned ).xyz;
|
|
#endif`,Nx=`#ifdef USE_SKINNING
|
|
mat4 skinMatrix = mat4( 0.0 );
|
|
skinMatrix += skinWeight.x * boneMatX;
|
|
skinMatrix += skinWeight.y * boneMatY;
|
|
skinMatrix += skinWeight.z * boneMatZ;
|
|
skinMatrix += skinWeight.w * boneMatW;
|
|
skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
|
|
objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
|
|
#ifdef USE_TANGENT
|
|
objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
|
|
#endif
|
|
#endif`,kx=`float specularStrength;
|
|
#ifdef USE_SPECULARMAP
|
|
vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
|
|
specularStrength = texelSpecular.r;
|
|
#else
|
|
specularStrength = 1.0;
|
|
#endif`,Bx=`#ifdef USE_SPECULARMAP
|
|
uniform sampler2D specularMap;
|
|
#endif`,Hx=`#if defined( TONE_MAPPING )
|
|
gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
|
|
#endif`,zx=`#ifndef saturate
|
|
#define saturate( a ) clamp( a, 0.0, 1.0 )
|
|
#endif
|
|
uniform float toneMappingExposure;
|
|
vec3 LinearToneMapping( vec3 color ) {
|
|
return saturate( toneMappingExposure * color );
|
|
}
|
|
vec3 ReinhardToneMapping( vec3 color ) {
|
|
color *= toneMappingExposure;
|
|
return saturate( color / ( vec3( 1.0 ) + color ) );
|
|
}
|
|
vec3 CineonToneMapping( vec3 color ) {
|
|
color *= toneMappingExposure;
|
|
color = max( vec3( 0.0 ), color - 0.004 );
|
|
return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
|
|
}
|
|
vec3 RRTAndODTFit( vec3 v ) {
|
|
vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
|
|
vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
|
|
return a / b;
|
|
}
|
|
vec3 ACESFilmicToneMapping( vec3 color ) {
|
|
const mat3 ACESInputMat = mat3(
|
|
vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ),
|
|
vec3( 0.04823, 0.01566, 0.83777 )
|
|
);
|
|
const mat3 ACESOutputMat = mat3(
|
|
vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ),
|
|
vec3( -0.07367, -0.00605, 1.07602 )
|
|
);
|
|
color *= toneMappingExposure / 0.6;
|
|
color = ACESInputMat * color;
|
|
color = RRTAndODTFit( color );
|
|
color = ACESOutputMat * color;
|
|
return saturate( color );
|
|
}
|
|
const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
|
|
vec3( 1.6605, - 0.1246, - 0.0182 ),
|
|
vec3( - 0.5876, 1.1329, - 0.1006 ),
|
|
vec3( - 0.0728, - 0.0083, 1.1187 )
|
|
);
|
|
const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
|
|
vec3( 0.6274, 0.0691, 0.0164 ),
|
|
vec3( 0.3293, 0.9195, 0.0880 ),
|
|
vec3( 0.0433, 0.0113, 0.8956 )
|
|
);
|
|
vec3 agxDefaultContrastApprox( vec3 x ) {
|
|
vec3 x2 = x * x;
|
|
vec3 x4 = x2 * x2;
|
|
return + 15.5 * x4 * x2
|
|
- 40.14 * x4 * x
|
|
+ 31.96 * x4
|
|
- 6.868 * x2 * x
|
|
+ 0.4298 * x2
|
|
+ 0.1191 * x
|
|
- 0.00232;
|
|
}
|
|
vec3 AgXToneMapping( vec3 color ) {
|
|
const mat3 AgXInsetMatrix = mat3(
|
|
vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),
|
|
vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),
|
|
vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )
|
|
);
|
|
const mat3 AgXOutsetMatrix = mat3(
|
|
vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),
|
|
vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),
|
|
vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
|
|
);
|
|
const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069;
|
|
color *= toneMappingExposure;
|
|
color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
|
|
color = AgXInsetMatrix * color;
|
|
color = max( color, 1e-10 ); color = log2( color );
|
|
color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );
|
|
color = clamp( color, 0.0, 1.0 );
|
|
color = agxDefaultContrastApprox( color );
|
|
color = AgXOutsetMatrix * color;
|
|
color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );
|
|
color = LINEAR_REC2020_TO_LINEAR_SRGB * color;
|
|
color = clamp( color, 0.0, 1.0 );
|
|
return color;
|
|
}
|
|
vec3 NeutralToneMapping( vec3 color ) {
|
|
const float StartCompression = 0.8 - 0.04;
|
|
const float Desaturation = 0.15;
|
|
color *= toneMappingExposure;
|
|
float x = min( color.r, min( color.g, color.b ) );
|
|
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
|
|
color -= offset;
|
|
float peak = max( color.r, max( color.g, color.b ) );
|
|
if ( peak < StartCompression ) return color;
|
|
float d = 1. - StartCompression;
|
|
float newPeak = 1. - d * d / ( peak + d - StartCompression );
|
|
color *= newPeak / peak;
|
|
float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
|
|
return mix( color, vec3( newPeak ), g );
|
|
}
|
|
vec3 CustomToneMapping( vec3 color ) { return color; }`,Gx=`#ifdef USE_TRANSMISSION
|
|
material.transmission = transmission;
|
|
material.transmissionAlpha = 1.0;
|
|
material.thickness = thickness;
|
|
material.attenuationDistance = attenuationDistance;
|
|
material.attenuationColor = attenuationColor;
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;
|
|
#endif
|
|
vec3 pos = vWorldPosition;
|
|
vec3 v = normalize( cameraPosition - pos );
|
|
vec3 n = transformNormalByInverseViewMatrix( normal, viewMatrix );
|
|
vec4 transmitted = getIBLVolumeRefraction(
|
|
n, v, material.roughness, material.diffuseContribution, material.specularColorBlended, material.specularF90,
|
|
pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,
|
|
material.attenuationColor, material.attenuationDistance );
|
|
material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
|
|
totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
|
|
#endif`,Vx=`#ifdef USE_TRANSMISSION
|
|
uniform float transmission;
|
|
uniform float thickness;
|
|
uniform float attenuationDistance;
|
|
uniform vec3 attenuationColor;
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
uniform sampler2D transmissionMap;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
uniform sampler2D thicknessMap;
|
|
#endif
|
|
uniform vec2 transmissionSamplerSize;
|
|
uniform sampler2D transmissionSamplerMap;
|
|
uniform mat4 modelMatrix;
|
|
uniform mat4 projectionMatrix;
|
|
varying vec3 vWorldPosition;
|
|
float w0( float a ) {
|
|
return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
|
|
}
|
|
float w1( float a ) {
|
|
return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );
|
|
}
|
|
float w2( float a ){
|
|
return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );
|
|
}
|
|
float w3( float a ) {
|
|
return ( 1.0 / 6.0 ) * ( a * a * a );
|
|
}
|
|
float g0( float a ) {
|
|
return w0( a ) + w1( a );
|
|
}
|
|
float g1( float a ) {
|
|
return w2( a ) + w3( a );
|
|
}
|
|
float h0( float a ) {
|
|
return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );
|
|
}
|
|
float h1( float a ) {
|
|
return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );
|
|
}
|
|
vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {
|
|
uv = uv * texelSize.zw + 0.5;
|
|
vec2 iuv = floor( uv );
|
|
vec2 fuv = fract( uv );
|
|
float g0x = g0( fuv.x );
|
|
float g1x = g1( fuv.x );
|
|
float h0x = h0( fuv.x );
|
|
float h1x = h1( fuv.x );
|
|
float h0y = h0( fuv.y );
|
|
float h1y = h1( fuv.y );
|
|
vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
|
|
vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
|
|
vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
|
|
vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
|
|
return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +
|
|
g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );
|
|
}
|
|
vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {
|
|
vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );
|
|
vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );
|
|
vec2 fLodSizeInv = 1.0 / fLodSize;
|
|
vec2 cLodSizeInv = 1.0 / cLodSize;
|
|
vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
|
|
vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
|
|
return mix( fSample, cSample, fract( lod ) );
|
|
}
|
|
vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
|
|
vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
|
|
vec3 modelScale;
|
|
modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
|
|
modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
|
|
modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
|
|
return normalize( refractionVector ) * thickness * modelScale;
|
|
}
|
|
float applyIorToRoughness( const in float roughness, const in float ior ) {
|
|
return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
|
|
}
|
|
vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
|
|
float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
|
|
return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );
|
|
}
|
|
vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
|
|
if ( isinf( attenuationDistance ) ) {
|
|
return vec3( 1.0 );
|
|
} else {
|
|
vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
|
|
vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance;
|
|
}
|
|
}
|
|
vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
|
|
const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
|
|
const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,
|
|
const in vec3 attenuationColor, const in float attenuationDistance ) {
|
|
vec4 transmittedLight;
|
|
vec3 transmittance;
|
|
#ifdef USE_DISPERSION
|
|
float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;
|
|
vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );
|
|
for ( int i = 0; i < 3; i ++ ) {
|
|
vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );
|
|
vec3 refractedRayExit = position + transmissionRay;
|
|
vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
|
|
vec2 refractionCoords = ndcPos.xy / ndcPos.w;
|
|
refractionCoords += 1.0;
|
|
refractionCoords /= 2.0;
|
|
vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );
|
|
transmittedLight[ i ] = transmissionSample[ i ];
|
|
transmittedLight.a += transmissionSample.a;
|
|
transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];
|
|
}
|
|
transmittedLight.a /= 3.0;
|
|
#else
|
|
vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
|
|
vec3 refractedRayExit = position + transmissionRay;
|
|
vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
|
|
vec2 refractionCoords = ndcPos.xy / ndcPos.w;
|
|
refractionCoords += 1.0;
|
|
refractionCoords /= 2.0;
|
|
transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
|
|
transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
|
|
#endif
|
|
vec3 attenuatedColor = transmittance * transmittedLight.rgb;
|
|
vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
|
|
float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
|
|
return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
|
|
}
|
|
#endif`,Wx=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
varying vec2 vUv;
|
|
#endif
|
|
#ifdef USE_MAP
|
|
varying vec2 vMapUv;
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
varying vec2 vAlphaMapUv;
|
|
#endif
|
|
#ifdef USE_LIGHTMAP
|
|
varying vec2 vLightMapUv;
|
|
#endif
|
|
#ifdef USE_AOMAP
|
|
varying vec2 vAoMapUv;
|
|
#endif
|
|
#ifdef USE_BUMPMAP
|
|
varying vec2 vBumpMapUv;
|
|
#endif
|
|
#ifdef USE_NORMALMAP
|
|
varying vec2 vNormalMapUv;
|
|
#endif
|
|
#ifdef USE_EMISSIVEMAP
|
|
varying vec2 vEmissiveMapUv;
|
|
#endif
|
|
#ifdef USE_METALNESSMAP
|
|
varying vec2 vMetalnessMapUv;
|
|
#endif
|
|
#ifdef USE_ROUGHNESSMAP
|
|
varying vec2 vRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_ANISOTROPYMAP
|
|
varying vec2 vAnisotropyMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOATMAP
|
|
varying vec2 vClearcoatMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
varying vec2 vClearcoatNormalMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
varying vec2 vClearcoatRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCEMAP
|
|
varying vec2 vIridescenceMapUv;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
varying vec2 vIridescenceThicknessMapUv;
|
|
#endif
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
varying vec2 vSheenColorMapUv;
|
|
#endif
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
varying vec2 vSheenRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULARMAP
|
|
varying vec2 vSpecularMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
varying vec2 vSpecularColorMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
varying vec2 vSpecularIntensityMapUv;
|
|
#endif
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
uniform mat3 transmissionMapTransform;
|
|
varying vec2 vTransmissionMapUv;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
uniform mat3 thicknessMapTransform;
|
|
varying vec2 vThicknessMapUv;
|
|
#endif`,Xx=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
varying vec2 vUv;
|
|
#endif
|
|
#ifdef USE_MAP
|
|
uniform mat3 mapTransform;
|
|
varying vec2 vMapUv;
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
uniform mat3 alphaMapTransform;
|
|
varying vec2 vAlphaMapUv;
|
|
#endif
|
|
#ifdef USE_LIGHTMAP
|
|
uniform mat3 lightMapTransform;
|
|
varying vec2 vLightMapUv;
|
|
#endif
|
|
#ifdef USE_AOMAP
|
|
uniform mat3 aoMapTransform;
|
|
varying vec2 vAoMapUv;
|
|
#endif
|
|
#ifdef USE_BUMPMAP
|
|
uniform mat3 bumpMapTransform;
|
|
varying vec2 vBumpMapUv;
|
|
#endif
|
|
#ifdef USE_NORMALMAP
|
|
uniform mat3 normalMapTransform;
|
|
varying vec2 vNormalMapUv;
|
|
#endif
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
uniform mat3 displacementMapTransform;
|
|
varying vec2 vDisplacementMapUv;
|
|
#endif
|
|
#ifdef USE_EMISSIVEMAP
|
|
uniform mat3 emissiveMapTransform;
|
|
varying vec2 vEmissiveMapUv;
|
|
#endif
|
|
#ifdef USE_METALNESSMAP
|
|
uniform mat3 metalnessMapTransform;
|
|
varying vec2 vMetalnessMapUv;
|
|
#endif
|
|
#ifdef USE_ROUGHNESSMAP
|
|
uniform mat3 roughnessMapTransform;
|
|
varying vec2 vRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_ANISOTROPYMAP
|
|
uniform mat3 anisotropyMapTransform;
|
|
varying vec2 vAnisotropyMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOATMAP
|
|
uniform mat3 clearcoatMapTransform;
|
|
varying vec2 vClearcoatMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
uniform mat3 clearcoatNormalMapTransform;
|
|
varying vec2 vClearcoatNormalMapUv;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
uniform mat3 clearcoatRoughnessMapTransform;
|
|
varying vec2 vClearcoatRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
uniform mat3 sheenColorMapTransform;
|
|
varying vec2 vSheenColorMapUv;
|
|
#endif
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
uniform mat3 sheenRoughnessMapTransform;
|
|
varying vec2 vSheenRoughnessMapUv;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCEMAP
|
|
uniform mat3 iridescenceMapTransform;
|
|
varying vec2 vIridescenceMapUv;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
uniform mat3 iridescenceThicknessMapTransform;
|
|
varying vec2 vIridescenceThicknessMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULARMAP
|
|
uniform mat3 specularMapTransform;
|
|
varying vec2 vSpecularMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
uniform mat3 specularColorMapTransform;
|
|
varying vec2 vSpecularColorMapUv;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
uniform mat3 specularIntensityMapTransform;
|
|
varying vec2 vSpecularIntensityMapUv;
|
|
#endif
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
uniform mat3 transmissionMapTransform;
|
|
varying vec2 vTransmissionMapUv;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
uniform mat3 thicknessMapTransform;
|
|
varying vec2 vThicknessMapUv;
|
|
#endif`,Yx=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
vUv = vec3( uv, 1 ).xy;
|
|
#endif
|
|
#ifdef USE_MAP
|
|
vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_ALPHAMAP
|
|
vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_LIGHTMAP
|
|
vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_AOMAP
|
|
vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_BUMPMAP
|
|
vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_NORMALMAP
|
|
vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_EMISSIVEMAP
|
|
vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_METALNESSMAP
|
|
vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_ROUGHNESSMAP
|
|
vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_ANISOTROPYMAP
|
|
vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_CLEARCOATMAP
|
|
vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_NORMALMAP
|
|
vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_CLEARCOAT_ROUGHNESSMAP
|
|
vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCEMAP
|
|
vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE_THICKNESSMAP
|
|
vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SPECULARMAP
|
|
vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_TRANSMISSIONMAP
|
|
vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;
|
|
#endif
|
|
#ifdef USE_THICKNESSMAP
|
|
vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
|
|
#endif`,qx=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
|
|
vec4 worldPosition = vec4( transformed, 1.0 );
|
|
#ifdef USE_BATCHING
|
|
worldPosition = batchingMatrix * worldPosition;
|
|
#endif
|
|
#ifdef USE_INSTANCING
|
|
worldPosition = instanceMatrix * worldPosition;
|
|
#endif
|
|
worldPosition = modelMatrix * worldPosition;
|
|
#endif`;const $x=`varying vec2 vUv;
|
|
uniform mat3 uvTransform;
|
|
void main() {
|
|
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
|
|
gl_Position = vec4( position.xy, 1.0, 1.0 );
|
|
}`,Zx=`uniform sampler2D t2D;
|
|
uniform float backgroundIntensity;
|
|
varying vec2 vUv;
|
|
void main() {
|
|
vec4 texColor = texture2D( t2D, vUv );
|
|
#ifdef DECODE_VIDEO_TEXTURE
|
|
texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
|
|
#endif
|
|
texColor.rgb *= backgroundIntensity;
|
|
gl_FragColor = texColor;
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`,Kx=`varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
gl_Position.z = gl_Position.w;
|
|
}`,Jx=`#ifdef ENVMAP_TYPE_CUBE
|
|
uniform samplerCube envMap;
|
|
#elif defined( ENVMAP_TYPE_CUBE_UV )
|
|
uniform sampler2D envMap;
|
|
#endif
|
|
uniform float backgroundBlurriness;
|
|
uniform float backgroundIntensity;
|
|
uniform mat3 backgroundRotation;
|
|
varying vec3 vWorldDirection;
|
|
#include <cube_uv_reflection_fragment>
|
|
void main() {
|
|
#ifdef ENVMAP_TYPE_CUBE
|
|
vec4 texColor = textureCube( envMap, backgroundRotation * vWorldDirection );
|
|
#elif defined( ENVMAP_TYPE_CUBE_UV )
|
|
vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );
|
|
#else
|
|
vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );
|
|
#endif
|
|
texColor.rgb *= backgroundIntensity;
|
|
gl_FragColor = texColor;
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`,jx=`varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
gl_Position.z = gl_Position.w;
|
|
}`,Qx=`uniform samplerCube tCube;
|
|
uniform float tFlip;
|
|
uniform float opacity;
|
|
varying vec3 vWorldDirection;
|
|
void main() {
|
|
vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
|
|
gl_FragColor = texColor;
|
|
gl_FragColor.a *= opacity;
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`,ev=`#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
varying vec2 vHighPrecisionZW;
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <batching_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <morphinstance_vertex>
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinnormal_vertex>
|
|
#endif
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vHighPrecisionZW = gl_Position.zw;
|
|
}`,tv=`#if DEPTH_PACKING == 3200
|
|
uniform float opacity;
|
|
#endif
|
|
#include <common>
|
|
#include <packing>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
varying vec2 vHighPrecisionZW;
|
|
void main() {
|
|
vec4 diffuseColor = vec4( 1.0 );
|
|
#include <clipping_planes_fragment>
|
|
#if DEPTH_PACKING == 3200
|
|
diffuseColor.a = opacity;
|
|
#endif
|
|
#include <map_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
float fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ];
|
|
#else
|
|
float fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5;
|
|
#endif
|
|
#if DEPTH_PACKING == 3200
|
|
gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
|
|
#elif DEPTH_PACKING == 3201
|
|
gl_FragColor = packDepthToRGBA( fragCoordZ );
|
|
#elif DEPTH_PACKING == 3202
|
|
gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );
|
|
#elif DEPTH_PACKING == 3203
|
|
gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
|
|
#endif
|
|
}`,nv=`#define DISTANCE
|
|
varying vec3 vWorldPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <batching_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <morphinstance_vertex>
|
|
#ifdef USE_DISPLACEMENTMAP
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinnormal_vertex>
|
|
#endif
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vWorldPosition = worldPosition.xyz;
|
|
}`,iv=`#define DISTANCE
|
|
uniform vec3 referencePosition;
|
|
uniform float nearDistance;
|
|
uniform float farDistance;
|
|
varying vec3 vWorldPosition;
|
|
#include <common>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( 1.0 );
|
|
#include <clipping_planes_fragment>
|
|
#include <map_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
float dist = length( vWorldPosition - referencePosition );
|
|
dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
|
|
dist = saturate( dist );
|
|
gl_FragColor = vec4( dist, 0.0, 0.0, 1.0 );
|
|
}`,sv=`varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
}`,rv=`uniform sampler2D tEquirect;
|
|
varying vec3 vWorldDirection;
|
|
#include <common>
|
|
void main() {
|
|
vec3 direction = normalize( vWorldDirection );
|
|
vec2 sampleUV = equirectUv( direction );
|
|
gl_FragColor = texture2D( tEquirect, sampleUV );
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
}`,av=`uniform float scale;
|
|
attribute float lineDistance;
|
|
varying float vLineDistance;
|
|
#include <common>
|
|
#include <uv_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
vLineDistance = scale * lineDistance;
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <fog_vertex>
|
|
}`,ov=`uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
uniform float dashSize;
|
|
uniform float totalSize;
|
|
varying float vLineDistance;
|
|
#include <common>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
if ( mod( vLineDistance, totalSize ) > dashSize ) {
|
|
discard;
|
|
}
|
|
vec3 outgoingLight = vec3( 0.0 );
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
outgoingLight = diffuseColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
}`,lv=`#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <envmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#endif
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <envmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,cv=`uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
#ifndef FLAT_SHADED
|
|
varying vec3 vNormal;
|
|
#endif
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <specularmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <specularmap_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
#ifdef USE_LIGHTMAP
|
|
vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
|
|
reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
|
|
#else
|
|
reflectedLight.indirectDiffuse += vec3( 1.0 );
|
|
#endif
|
|
#include <aomap_fragment>
|
|
reflectedLight.indirectDiffuse *= diffuseColor.rgb;
|
|
vec3 outgoingLight = reflectedLight.indirectDiffuse;
|
|
#include <envmap_fragment>
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,uv=`#define LAMBERT
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <envmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <envmap_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,hv=`#define LAMBERT
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <cube_uv_reflection_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_pars_fragment>
|
|
#include <envmap_physical_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_lambert_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <specularmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <specularmap_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_lambert_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
|
|
#include <envmap_fragment>
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,fv=`#define MATCAP
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <fog_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
}`,dv=`#define MATCAP
|
|
uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
uniform sampler2D matcap;
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <normal_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
vec3 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;
|
|
#ifdef USE_MATCAP
|
|
vec4 matcapColor = texture2D( matcap, uv );
|
|
#else
|
|
vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );
|
|
#endif
|
|
vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,pv=`#define NORMAL
|
|
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
|
|
varying vec3 vViewPosition;
|
|
#endif
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
|
|
vViewPosition = - mvPosition.xyz;
|
|
#endif
|
|
}`,mv=`#define NORMAL
|
|
uniform float opacity;
|
|
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
|
|
varying vec3 vViewPosition;
|
|
#endif
|
|
#include <uv_pars_fragment>
|
|
#include <normal_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );
|
|
#include <clipping_planes_fragment>
|
|
#include <logdepthbuf_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
gl_FragColor = vec4( normalize( normal ) * 0.5 + 0.5, diffuseColor.a );
|
|
#ifdef OPAQUE
|
|
gl_FragColor.a = 1.0;
|
|
#endif
|
|
}`,gv=`#define PHONG
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <envmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <envmap_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,xv=`#define PHONG
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform vec3 specular;
|
|
uniform float shininess;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <cube_uv_reflection_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_pars_fragment>
|
|
#include <envmap_physical_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_phong_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <specularmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <specularmap_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_phong_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
|
|
#include <envmap_fragment>
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,vv=`#define STANDARD
|
|
varying vec3 vViewPosition;
|
|
#ifdef USE_TRANSMISSION
|
|
varying vec3 vWorldPosition;
|
|
#endif
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
#ifdef USE_TRANSMISSION
|
|
vWorldPosition = worldPosition.xyz;
|
|
#endif
|
|
}`,yv=`#define STANDARD
|
|
#ifdef PHYSICAL
|
|
#define IOR
|
|
#define USE_SPECULAR
|
|
#endif
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform float roughness;
|
|
uniform float metalness;
|
|
uniform float opacity;
|
|
#ifdef IOR
|
|
uniform float ior;
|
|
#endif
|
|
#ifdef USE_SPECULAR
|
|
uniform float specularIntensity;
|
|
uniform vec3 specularColor;
|
|
#ifdef USE_SPECULAR_COLORMAP
|
|
uniform sampler2D specularColorMap;
|
|
#endif
|
|
#ifdef USE_SPECULAR_INTENSITYMAP
|
|
uniform sampler2D specularIntensityMap;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
uniform float clearcoat;
|
|
uniform float clearcoatRoughness;
|
|
#endif
|
|
#ifdef USE_DISPERSION
|
|
uniform float dispersion;
|
|
#endif
|
|
#ifdef USE_IRIDESCENCE
|
|
uniform float iridescence;
|
|
uniform float iridescenceIOR;
|
|
uniform float iridescenceThicknessMinimum;
|
|
uniform float iridescenceThicknessMaximum;
|
|
#endif
|
|
#ifdef USE_SHEEN
|
|
uniform vec3 sheenColor;
|
|
uniform float sheenRoughness;
|
|
#ifdef USE_SHEEN_COLORMAP
|
|
uniform sampler2D sheenColorMap;
|
|
#endif
|
|
#ifdef USE_SHEEN_ROUGHNESSMAP
|
|
uniform sampler2D sheenRoughnessMap;
|
|
#endif
|
|
#endif
|
|
#ifdef USE_ANISOTROPY
|
|
uniform vec2 anisotropyVector;
|
|
#ifdef USE_ANISOTROPYMAP
|
|
uniform sampler2D anisotropyMap;
|
|
#endif
|
|
#endif
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <iridescence_fragment>
|
|
#include <cube_uv_reflection_fragment>
|
|
#include <envmap_common_pars_fragment>
|
|
#include <envmap_physical_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_physical_pars_fragment>
|
|
#include <transmission_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <clearcoat_pars_fragment>
|
|
#include <iridescence_pars_fragment>
|
|
#include <roughnessmap_pars_fragment>
|
|
#include <metalnessmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <roughnessmap_fragment>
|
|
#include <metalnessmap_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <clearcoat_normal_fragment_begin>
|
|
#include <clearcoat_normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_physical_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
|
|
vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
|
|
#include <transmission_fragment>
|
|
vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
|
|
#ifdef USE_SHEEN
|
|
|
|
outgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;
|
|
|
|
#endif
|
|
#ifdef USE_CLEARCOAT
|
|
float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
|
|
vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
|
|
outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
|
|
#endif
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,_v=`#define TOON
|
|
varying vec3 vViewPosition;
|
|
#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <uv_pars_vertex>
|
|
#include <displacementmap_pars_vertex>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <normal_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <normal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <displacementmap_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
vViewPosition = - mvPosition.xyz;
|
|
#include <worldpos_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,bv=`#define TOON
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <dithering_pars_fragment>
|
|
#include <color_pars_fragment>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <aomap_pars_fragment>
|
|
#include <lightmap_pars_fragment>
|
|
#include <emissivemap_pars_fragment>
|
|
#include <gradientmap_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <normal_pars_fragment>
|
|
#include <lights_toon_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <bumpmap_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
|
|
vec3 totalEmissiveRadiance = emissive;
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <color_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
#include <normal_fragment_begin>
|
|
#include <normal_fragment_maps>
|
|
#include <emissivemap_fragment>
|
|
#include <lights_toon_fragment>
|
|
#include <lights_fragment_begin>
|
|
#include <lights_fragment_maps>
|
|
#include <lights_fragment_end>
|
|
#include <aomap_fragment>
|
|
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
#include <dithering_fragment>
|
|
}`,Sv=`uniform float size;
|
|
uniform float scale;
|
|
#include <common>
|
|
#include <color_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
#ifdef USE_POINTS_UV
|
|
varying vec2 vUv;
|
|
uniform mat3 uvTransform;
|
|
#endif
|
|
void main() {
|
|
#ifdef USE_POINTS_UV
|
|
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
|
|
#endif
|
|
#include <color_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphcolor_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <project_vertex>
|
|
gl_PointSize = size;
|
|
#ifdef USE_SIZEATTENUATION
|
|
bool isPerspective = isPerspectiveMatrix( projectionMatrix );
|
|
if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
|
|
#endif
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <fog_vertex>
|
|
}`,Mv=`uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <color_pars_fragment>
|
|
#include <map_particle_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
vec3 outgoingLight = vec3( 0.0 );
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_particle_fragment>
|
|
#include <color_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
outgoingLight = diffuseColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
}`,Ev=`#include <common>
|
|
#include <batching_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <morphtarget_pars_vertex>
|
|
#include <skinning_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <shadowmap_pars_vertex>
|
|
void main() {
|
|
#include <batching_vertex>
|
|
#include <beginnormal_vertex>
|
|
#include <morphinstance_vertex>
|
|
#include <morphnormal_vertex>
|
|
#include <skinbase_vertex>
|
|
#include <skinnormal_vertex>
|
|
#include <defaultnormal_vertex>
|
|
#include <begin_vertex>
|
|
#include <morphtarget_vertex>
|
|
#include <skinning_vertex>
|
|
#include <project_vertex>
|
|
#include <logdepthbuf_vertex>
|
|
#include <worldpos_vertex>
|
|
#include <shadowmap_vertex>
|
|
#include <fog_vertex>
|
|
}`,Tv=`uniform vec3 color;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <fog_pars_fragment>
|
|
#include <bsdfs>
|
|
#include <lights_pars_begin>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <shadowmap_pars_fragment>
|
|
#include <shadowmask_pars_fragment>
|
|
void main() {
|
|
#include <logdepthbuf_fragment>
|
|
gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
#include <premultiplied_alpha_fragment>
|
|
}`,Av=`uniform float rotation;
|
|
uniform vec2 center;
|
|
#include <common>
|
|
#include <uv_pars_vertex>
|
|
#include <fog_pars_vertex>
|
|
#include <logdepthbuf_pars_vertex>
|
|
#include <clipping_planes_pars_vertex>
|
|
void main() {
|
|
#include <uv_vertex>
|
|
vec4 mvPosition = modelViewMatrix[ 3 ];
|
|
vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );
|
|
#ifndef USE_SIZEATTENUATION
|
|
bool isPerspective = isPerspectiveMatrix( projectionMatrix );
|
|
if ( isPerspective ) scale *= - mvPosition.z;
|
|
#endif
|
|
vec2 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;
|
|
#include <logdepthbuf_vertex>
|
|
#include <clipping_planes_vertex>
|
|
#include <fog_vertex>
|
|
}`,wv=`uniform vec3 diffuse;
|
|
uniform float opacity;
|
|
#include <common>
|
|
#include <uv_pars_fragment>
|
|
#include <map_pars_fragment>
|
|
#include <alphamap_pars_fragment>
|
|
#include <alphatest_pars_fragment>
|
|
#include <alphahash_pars_fragment>
|
|
#include <fog_pars_fragment>
|
|
#include <logdepthbuf_pars_fragment>
|
|
#include <clipping_planes_pars_fragment>
|
|
void main() {
|
|
vec4 diffuseColor = vec4( diffuse, opacity );
|
|
#include <clipping_planes_fragment>
|
|
vec3 outgoingLight = vec3( 0.0 );
|
|
#include <logdepthbuf_fragment>
|
|
#include <map_fragment>
|
|
#include <alphamap_fragment>
|
|
#include <alphatest_fragment>
|
|
#include <alphahash_fragment>
|
|
outgoingLight = diffuseColor.rgb;
|
|
#include <opaque_fragment>
|
|
#include <tonemapping_fragment>
|
|
#include <colorspace_fragment>
|
|
#include <fog_fragment>
|
|
}`,Je={alphahash_fragment:$g,alphahash_pars_fragment:Zg,alphamap_fragment:Kg,alphamap_pars_fragment:Jg,alphatest_fragment:jg,alphatest_pars_fragment:Qg,aomap_fragment:e0,aomap_pars_fragment:t0,batching_pars_vertex:n0,batching_vertex:i0,begin_vertex:s0,beginnormal_vertex:r0,bsdfs:a0,iridescence_fragment:o0,bumpmap_pars_fragment:l0,clipping_planes_fragment:c0,clipping_planes_pars_fragment:u0,clipping_planes_pars_vertex:h0,clipping_planes_vertex:f0,color_fragment:d0,color_pars_fragment:p0,color_pars_vertex:m0,color_vertex:g0,common:x0,cube_uv_reflection_fragment:v0,defaultnormal_vertex:y0,displacementmap_pars_vertex:_0,displacementmap_vertex:b0,emissivemap_fragment:S0,emissivemap_pars_fragment:M0,colorspace_fragment:E0,colorspace_pars_fragment:T0,envmap_fragment:A0,envmap_common_pars_fragment:w0,envmap_pars_fragment:C0,envmap_pars_vertex:R0,envmap_physical_pars_fragment:H0,envmap_vertex:P0,fog_vertex:L0,fog_pars_vertex:D0,fog_fragment:I0,fog_pars_fragment:U0,gradientmap_pars_fragment:O0,lightmap_pars_fragment:F0,lights_lambert_fragment:N0,lights_lambert_pars_fragment:k0,lights_pars_begin:B0,lights_toon_fragment:z0,lights_toon_pars_fragment:G0,lights_phong_fragment:V0,lights_phong_pars_fragment:W0,lights_physical_fragment:X0,lights_physical_pars_fragment:Y0,lights_fragment_begin:q0,lights_fragment_maps:$0,lights_fragment_end:Z0,lightprobes_pars_fragment:K0,logdepthbuf_fragment:J0,logdepthbuf_pars_fragment:j0,logdepthbuf_pars_vertex:Q0,logdepthbuf_vertex:ex,map_fragment:tx,map_pars_fragment:nx,map_particle_fragment:ix,map_particle_pars_fragment:sx,metalnessmap_fragment:rx,metalnessmap_pars_fragment:ax,morphinstance_vertex:ox,morphcolor_vertex:lx,morphnormal_vertex:cx,morphtarget_pars_vertex:ux,morphtarget_vertex:hx,normal_fragment_begin:fx,normal_fragment_maps:dx,normal_pars_fragment:px,normal_pars_vertex:mx,normal_vertex:gx,normalmap_pars_fragment:xx,clearcoat_normal_fragment_begin:vx,clearcoat_normal_fragment_maps:yx,clearcoat_pars_fragment:_x,iridescence_pars_fragment:bx,opaque_fragment:Sx,packing:Mx,premultiplied_alpha_fragment:Ex,project_vertex:Tx,dithering_fragment:Ax,dithering_pars_fragment:wx,roughnessmap_fragment:Cx,roughnessmap_pars_fragment:Rx,shadowmap_pars_fragment:Px,shadowmap_pars_vertex:Lx,shadowmap_vertex:Dx,shadowmask_pars_fragment:Ix,skinbase_vertex:Ux,skinning_pars_vertex:Ox,skinning_vertex:Fx,skinnormal_vertex:Nx,specularmap_fragment:kx,specularmap_pars_fragment:Bx,tonemapping_fragment:Hx,tonemapping_pars_fragment:zx,transmission_fragment:Gx,transmission_pars_fragment:Vx,uv_pars_fragment:Wx,uv_pars_vertex:Xx,uv_vertex:Yx,worldpos_vertex:qx,background_vert:$x,background_frag:Zx,backgroundCube_vert:Kx,backgroundCube_frag:Jx,cube_vert:jx,cube_frag:Qx,depth_vert:ev,depth_frag:tv,distance_vert:nv,distance_frag:iv,equirect_vert:sv,equirect_frag:rv,linedashed_vert:av,linedashed_frag:ov,meshbasic_vert:lv,meshbasic_frag:cv,meshlambert_vert:uv,meshlambert_frag:hv,meshmatcap_vert:fv,meshmatcap_frag:dv,meshnormal_vert:pv,meshnormal_frag:mv,meshphong_vert:gv,meshphong_frag:xv,meshphysical_vert:vv,meshphysical_frag:yv,meshtoon_vert:_v,meshtoon_frag:bv,points_vert:Sv,points_frag:Mv,shadow_vert:Ev,shadow_frag:Tv,sprite_vert:Av,sprite_frag:wv},we={common:{diffuse:{value:new et(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new $e},alphaMap:{value:null},alphaMapTransform:{value:new $e},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new $e}},envmap:{envMap:{value:null},envMapRotation:{value:new $e},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new $e}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new $e}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new $e},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new $e},normalScale:{value:new Ee(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new $e},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new $e}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new $e}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new $e}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new et(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null},probesSH:{value:null},probesMin:{value:new B},probesMax:{value:new B},probesResolution:{value:new B}},points:{diffuse:{value:new et(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new $e},alphaTest:{value:0},uvTransform:{value:new $e}},sprite:{diffuse:{value:new et(16777215)},opacity:{value:1},center:{value:new Ee(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new $e},alphaMap:{value:null},alphaMapTransform:{value:new $e},alphaTest:{value:0}}},Yn={basic:{uniforms:nn([we.common,we.specularmap,we.envmap,we.aomap,we.lightmap,we.fog]),vertexShader:Je.meshbasic_vert,fragmentShader:Je.meshbasic_frag},lambert:{uniforms:nn([we.common,we.specularmap,we.envmap,we.aomap,we.lightmap,we.emissivemap,we.bumpmap,we.normalmap,we.displacementmap,we.fog,we.lights,{emissive:{value:new et(0)},envMapIntensity:{value:1}}]),vertexShader:Je.meshlambert_vert,fragmentShader:Je.meshlambert_frag},phong:{uniforms:nn([we.common,we.specularmap,we.envmap,we.aomap,we.lightmap,we.emissivemap,we.bumpmap,we.normalmap,we.displacementmap,we.fog,we.lights,{emissive:{value:new et(0)},specular:{value:new et(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:Je.meshphong_vert,fragmentShader:Je.meshphong_frag},standard:{uniforms:nn([we.common,we.envmap,we.aomap,we.lightmap,we.emissivemap,we.bumpmap,we.normalmap,we.displacementmap,we.roughnessmap,we.metalnessmap,we.fog,we.lights,{emissive:{value:new et(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Je.meshphysical_vert,fragmentShader:Je.meshphysical_frag},toon:{uniforms:nn([we.common,we.aomap,we.lightmap,we.emissivemap,we.bumpmap,we.normalmap,we.displacementmap,we.gradientmap,we.fog,we.lights,{emissive:{value:new et(0)}}]),vertexShader:Je.meshtoon_vert,fragmentShader:Je.meshtoon_frag},matcap:{uniforms:nn([we.common,we.bumpmap,we.normalmap,we.displacementmap,we.fog,{matcap:{value:null}}]),vertexShader:Je.meshmatcap_vert,fragmentShader:Je.meshmatcap_frag},points:{uniforms:nn([we.points,we.fog]),vertexShader:Je.points_vert,fragmentShader:Je.points_frag},dashed:{uniforms:nn([we.common,we.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Je.linedashed_vert,fragmentShader:Je.linedashed_frag},depth:{uniforms:nn([we.common,we.displacementmap]),vertexShader:Je.depth_vert,fragmentShader:Je.depth_frag},normal:{uniforms:nn([we.common,we.bumpmap,we.normalmap,we.displacementmap,{opacity:{value:1}}]),vertexShader:Je.meshnormal_vert,fragmentShader:Je.meshnormal_frag},sprite:{uniforms:nn([we.sprite,we.fog]),vertexShader:Je.sprite_vert,fragmentShader:Je.sprite_frag},background:{uniforms:{uvTransform:{value:new $e},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Je.background_vert,fragmentShader:Je.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new $e}},vertexShader:Je.backgroundCube_vert,fragmentShader:Je.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Je.cube_vert,fragmentShader:Je.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Je.equirect_vert,fragmentShader:Je.equirect_frag},distance:{uniforms:nn([we.common,we.displacementmap,{referencePosition:{value:new B},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Je.distance_vert,fragmentShader:Je.distance_frag},shadow:{uniforms:nn([we.lights,we.fog,{color:{value:new et(0)},opacity:{value:1}}]),vertexShader:Je.shadow_vert,fragmentShader:Je.shadow_frag}};Yn.physical={uniforms:nn([Yn.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new $e},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new $e},clearcoatNormalScale:{value:new Ee(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new $e},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new $e},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new $e},sheen:{value:0},sheenColor:{value:new et(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new $e},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new $e},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new $e},transmissionSamplerSize:{value:new Ee},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new $e},attenuationDistance:{value:0},attenuationColor:{value:new et(0)},specularColor:{value:new et(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new $e},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new $e},anisotropyVector:{value:new Ee},anisotropyMap:{value:null},anisotropyMapTransform:{value:new $e}}]),vertexShader:Je.meshphysical_vert,fragmentShader:Je.meshphysical_frag};const ya={r:0,b:0,g:0},Cv=new Tt,vd=new $e;vd.set(-1,0,0,0,1,0,0,0,1);function Rv(n,e,t,i,s,r){const a=new et(0);let o=s===!0?0:1,l,c,u=null,f=0,h=null;function d(M){let E=M.isScene===!0?M.background:null;if(E&&E.isTexture){const _=M.backgroundBlurriness>0;E=e.get(E,_)}return E}function p(M){let E=!1;const _=d(M);_===null?m(a,o):_&&_.isColor&&(m(_,1),E=!0);const T=n.xr.getEnvironmentBlendMode();T==="additive"?t.buffers.color.setClear(0,0,0,1,r):T==="alpha-blend"&&t.buffers.color.setClear(0,0,0,0,r),(n.autoClear||E)&&(t.buffers.depth.setTest(!0),t.buffers.depth.setMask(!0),t.buffers.color.setMask(!0),n.clear(n.autoClearColor,n.autoClearDepth,n.autoClearStencil))}function x(M,E){const _=d(E);_&&(_.isCubeTexture||_.mapping===mo)?(c===void 0&&(c=new Gt(new Ur(1,1,1),new In({name:"BackgroundCubeMaterial",uniforms:Ys(Yn.backgroundCube.uniforms),vertexShader:Yn.backgroundCube.vertexShader,fragmentShader:Yn.backgroundCube.fragmentShader,side:un,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute("normal"),c.geometry.deleteAttribute("uv"),c.onBeforeRender=function(T,b,S){this.matrixWorld.copyPosition(S.matrixWorld)},Object.defineProperty(c.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(c)),c.material.uniforms.envMap.value=_,c.material.uniforms.backgroundBlurriness.value=E.backgroundBlurriness,c.material.uniforms.backgroundIntensity.value=E.backgroundIntensity,c.material.uniforms.backgroundRotation.value.setFromMatrix4(Cv.makeRotationFromEuler(E.backgroundRotation)).transpose(),_.isCubeTexture&&_.isRenderTargetTexture===!1&&c.material.uniforms.backgroundRotation.value.premultiply(vd),c.material.toneMapped=nt.getTransfer(_.colorSpace)!==ft,(u!==_||f!==_.version||h!==n.toneMapping)&&(c.material.needsUpdate=!0,u=_,f=_.version,h=n.toneMapping),c.layers.enableAll(),M.unshift(c,c.geometry,c.material,0,0,null)):_&&_.isTexture&&(l===void 0&&(l=new Gt(new Qi(2,2),new In({name:"BackgroundMaterial",uniforms:Ys(Yn.background.uniforms),vertexShader:Yn.background.vertexShader,fragmentShader:Yn.background.fragmentShader,side:Ni,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(l)),l.material.uniforms.t2D.value=_,l.material.uniforms.backgroundIntensity.value=E.backgroundIntensity,l.material.toneMapped=nt.getTransfer(_.colorSpace)!==ft,_.matrixAutoUpdate===!0&&_.updateMatrix(),l.material.uniforms.uvTransform.value.copy(_.matrix),(u!==_||f!==_.version||h!==n.toneMapping)&&(l.material.needsUpdate=!0,u=_,f=_.version,h=n.toneMapping),l.layers.enableAll(),M.unshift(l,l.geometry,l.material,0,0,null))}function m(M,E){M.getRGB(ya,md(n)),t.buffers.color.setClear(ya.r,ya.g,ya.b,E,r)}function g(){c!==void 0&&(c.geometry.dispose(),c.material.dispose(),c=void 0),l!==void 0&&(l.geometry.dispose(),l.material.dispose(),l=void 0)}return{getClearColor:function(){return a},setClearColor:function(M,E=1){a.set(M),o=E,m(a,o)},getClearAlpha:function(){return o},setClearAlpha:function(M){o=M,m(a,o)},render:p,addToRenderList:x,dispose:g}}function Pv(n,e){const t=n.getParameter(n.MAX_VERTEX_ATTRIBS),i={},s=h(null);let r=s,a=!1;function o(L,C,O,N,U){let Z=!1;const k=f(L,N,O,C);r!==k&&(r=k,c(r.object)),Z=d(L,N,O,U),Z&&p(L,N,O,U),U!==null&&e.update(U,n.ELEMENT_ARRAY_BUFFER),(Z||a)&&(a=!1,_(L,C,O,N),U!==null&&n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,e.get(U).buffer))}function l(){return n.createVertexArray()}function c(L){return n.bindVertexArray(L)}function u(L){return n.deleteVertexArray(L)}function f(L,C,O,N){const U=N.wireframe===!0;let Z=i[C.id];Z===void 0&&(Z={},i[C.id]=Z);const k=L.isInstancedMesh===!0?L.id:0;let $=Z[k];$===void 0&&($={},Z[k]=$);let D=$[O.id];D===void 0&&(D={},$[O.id]=D);let ae=D[U];return ae===void 0&&(ae=h(l()),D[U]=ae),ae}function h(L){const C=[],O=[],N=[];for(let U=0;U<t;U++)C[U]=0,O[U]=0,N[U]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:C,enabledAttributes:O,attributeDivisors:N,object:L,attributes:{},index:null}}function d(L,C,O,N){const U=r.attributes,Z=C.attributes;let k=0;const $=O.getAttributes();for(const D in $)if($[D].location>=0){const re=U[D];let ee=Z[D];if(ee===void 0&&(D==="instanceMatrix"&&L.instanceMatrix&&(ee=L.instanceMatrix),D==="instanceColor"&&L.instanceColor&&(ee=L.instanceColor)),re===void 0||re.attribute!==ee||ee&&re.data!==ee.data)return!0;k++}return r.attributesNum!==k||r.index!==N}function p(L,C,O,N){const U={},Z=C.attributes;let k=0;const $=O.getAttributes();for(const D in $)if($[D].location>=0){let re=Z[D];re===void 0&&(D==="instanceMatrix"&&L.instanceMatrix&&(re=L.instanceMatrix),D==="instanceColor"&&L.instanceColor&&(re=L.instanceColor));const ee={};ee.attribute=re,re&&re.data&&(ee.data=re.data),U[D]=ee,k++}r.attributes=U,r.attributesNum=k,r.index=N}function x(){const L=r.newAttributes;for(let C=0,O=L.length;C<O;C++)L[C]=0}function m(L){g(L,0)}function g(L,C){const O=r.newAttributes,N=r.enabledAttributes,U=r.attributeDivisors;O[L]=1,N[L]===0&&(n.enableVertexAttribArray(L),N[L]=1),U[L]!==C&&(n.vertexAttribDivisor(L,C),U[L]=C)}function M(){const L=r.newAttributes,C=r.enabledAttributes;for(let O=0,N=C.length;O<N;O++)C[O]!==L[O]&&(n.disableVertexAttribArray(O),C[O]=0)}function E(L,C,O,N,U,Z,k){k===!0?n.vertexAttribIPointer(L,C,O,U,Z):n.vertexAttribPointer(L,C,O,N,U,Z)}function _(L,C,O,N){x();const U=N.attributes,Z=O.getAttributes(),k=C.defaultAttributeValues;for(const $ in Z){const D=Z[$];if(D.location>=0){let ae=U[$];if(ae===void 0&&($==="instanceMatrix"&&L.instanceMatrix&&(ae=L.instanceMatrix),$==="instanceColor"&&L.instanceColor&&(ae=L.instanceColor)),ae!==void 0){const re=ae.normalized,ee=ae.itemSize,ce=e.get(ae);if(ce===void 0)continue;const he=ce.buffer,fe=ce.type,X=ce.bytesPerElement,se=fe===n.INT||fe===n.UNSIGNED_INT||ae.gpuType===Rc;if(ae.isInterleavedBufferAttribute){const Q=ae.data,ye=Q.stride,ve=ae.offset;if(Q.isInstancedInterleavedBuffer){for(let _e=0;_e<D.locationSize;_e++)g(D.location+_e,Q.meshPerAttribute);L.isInstancedMesh!==!0&&N._maxInstanceCount===void 0&&(N._maxInstanceCount=Q.meshPerAttribute*Q.count)}else for(let _e=0;_e<D.locationSize;_e++)m(D.location+_e);n.bindBuffer(n.ARRAY_BUFFER,he);for(let _e=0;_e<D.locationSize;_e++)E(D.location+_e,ee/D.locationSize,fe,re,ye*X,(ve+ee/D.locationSize*_e)*X,se)}else{if(ae.isInstancedBufferAttribute){for(let Q=0;Q<D.locationSize;Q++)g(D.location+Q,ae.meshPerAttribute);L.isInstancedMesh!==!0&&N._maxInstanceCount===void 0&&(N._maxInstanceCount=ae.meshPerAttribute*ae.count)}else for(let Q=0;Q<D.locationSize;Q++)m(D.location+Q);n.bindBuffer(n.ARRAY_BUFFER,he);for(let Q=0;Q<D.locationSize;Q++)E(D.location+Q,ee/D.locationSize,fe,re,ee*X,ee/D.locationSize*Q*X,se)}}else if(k!==void 0){const re=k[$];if(re!==void 0)switch(re.length){case 2:n.vertexAttrib2fv(D.location,re);break;case 3:n.vertexAttrib3fv(D.location,re);break;case 4:n.vertexAttrib4fv(D.location,re);break;default:n.vertexAttrib1fv(D.location,re)}}}}M()}function T(){w();for(const L in i){const C=i[L];for(const O in C){const N=C[O];for(const U in N){const Z=N[U];for(const k in Z)u(Z[k].object),delete Z[k];delete N[U]}}delete i[L]}}function b(L){if(i[L.id]===void 0)return;const C=i[L.id];for(const O in C){const N=C[O];for(const U in N){const Z=N[U];for(const k in Z)u(Z[k].object),delete Z[k];delete N[U]}}delete i[L.id]}function S(L){for(const C in i){const O=i[C];for(const N in O){const U=O[N];if(U[L.id]===void 0)continue;const Z=U[L.id];for(const k in Z)u(Z[k].object),delete Z[k];delete U[L.id]}}}function v(L){for(const C in i){const O=i[C],N=L.isInstancedMesh===!0?L.id:0,U=O[N];if(U!==void 0){for(const Z in U){const k=U[Z];for(const $ in k)u(k[$].object),delete k[$];delete U[Z]}delete O[N],Object.keys(O).length===0&&delete i[C]}}}function w(){I(),a=!0,r!==s&&(r=s,c(r.object))}function I(){s.geometry=null,s.program=null,s.wireframe=!1}return{setup:o,reset:w,resetDefaultState:I,dispose:T,releaseStatesOfGeometry:b,releaseStatesOfObject:v,releaseStatesOfProgram:S,initAttributes:x,enableAttribute:m,disableUnusedAttributes:M}}function Lv(n,e,t){let i;function s(l){i=l}function r(l,c){n.drawArrays(i,l,c),t.update(c,i,1)}function a(l,c,u){u!==0&&(n.drawArraysInstanced(i,l,c,u),t.update(c,i,u))}function o(l,c,u){if(u===0)return;e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(i,l,0,c,0,u);let h=0;for(let d=0;d<u;d++)h+=c[d];t.update(h,i,1)}this.setMode=s,this.render=r,this.renderInstances=a,this.renderMultiDraw=o}function Dv(n,e,t,i){let s;function r(){if(s!==void 0)return s;if(e.has("EXT_texture_filter_anisotropic")===!0){const S=e.get("EXT_texture_filter_anisotropic");s=n.getParameter(S.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else s=0;return s}function a(S){return!(S!==En&&i.convert(S)!==n.getParameter(n.IMPLEMENTATION_COLOR_READ_FORMAT))}function o(S){const v=S===mi&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(S!==Sn&&i.convert(S)!==n.getParameter(n.IMPLEMENTATION_COLOR_READ_TYPE)&&S!==Ln&&!v)}function l(S){if(S==="highp"){if(n.getShaderPrecisionFormat(n.VERTEX_SHADER,n.HIGH_FLOAT).precision>0&&n.getShaderPrecisionFormat(n.FRAGMENT_SHADER,n.HIGH_FLOAT).precision>0)return"highp";S="mediump"}return S==="mediump"&&n.getShaderPrecisionFormat(n.VERTEX_SHADER,n.MEDIUM_FLOAT).precision>0&&n.getShaderPrecisionFormat(n.FRAGMENT_SHADER,n.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let c=t.precision!==void 0?t.precision:"highp";const u=l(c);u!==c&&(We("WebGLRenderer:",c,"not supported, using",u,"instead."),c=u);const f=t.logarithmicDepthBuffer===!0,h=t.reversedDepthBuffer===!0&&e.has("EXT_clip_control");t.reversedDepthBuffer===!0&&h===!1&&We("WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.");const d=n.getParameter(n.MAX_TEXTURE_IMAGE_UNITS),p=n.getParameter(n.MAX_VERTEX_TEXTURE_IMAGE_UNITS),x=n.getParameter(n.MAX_TEXTURE_SIZE),m=n.getParameter(n.MAX_CUBE_MAP_TEXTURE_SIZE),g=n.getParameter(n.MAX_VERTEX_ATTRIBS),M=n.getParameter(n.MAX_VERTEX_UNIFORM_VECTORS),E=n.getParameter(n.MAX_VARYING_VECTORS),_=n.getParameter(n.MAX_FRAGMENT_UNIFORM_VECTORS),T=n.getParameter(n.MAX_SAMPLES),b=n.getParameter(n.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:r,getMaxPrecision:l,textureFormatReadable:a,textureTypeReadable:o,precision:c,logarithmicDepthBuffer:f,reversedDepthBuffer:h,maxTextures:d,maxVertexTextures:p,maxTextureSize:x,maxCubemapSize:m,maxAttributes:g,maxVertexUniforms:M,maxVaryings:E,maxFragmentUniforms:_,maxSamples:T,samples:b}}function Iv(n){const e=this;let t=null,i=0,s=!1,r=!1;const a=new Ri,o=new $e,l={value:null,needsUpdate:!1};this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(f,h){const d=f.length!==0||h||i!==0||s;return s=h,i=f.length,d},this.beginShadows=function(){r=!0,u(null)},this.endShadows=function(){r=!1},this.setGlobalState=function(f,h){t=u(f,h,0)},this.setState=function(f,h,d){const p=f.clippingPlanes,x=f.clipIntersection,m=f.clipShadows,g=n.get(f);if(!s||p===null||p.length===0||r&&!m)r?u(null):c();else{const M=r?0:i,E=M*4;let _=g.clippingState||null;l.value=_,_=u(p,h,E,d);for(let T=0;T!==E;++T)_[T]=t[T];g.clippingState=_,this.numIntersection=x?this.numPlanes:0,this.numPlanes+=M}};function c(){l.value!==t&&(l.value=t,l.needsUpdate=i>0),e.numPlanes=i,e.numIntersection=0}function u(f,h,d,p){const x=f!==null?f.length:0;let m=null;if(x!==0){if(m=l.value,p!==!0||m===null){const g=d+x*4,M=h.matrixWorldInverse;o.getNormalMatrix(M),(m===null||m.length<g)&&(m=new Float32Array(g));for(let E=0,_=d;E!==x;++E,_+=4)a.copy(f[E]).applyMatrix4(M,o),a.normal.toArray(m,_),m[_+3]=a.constant}l.value=m,l.needsUpdate=!0}return e.numPlanes=x,e.numIntersection=0,m}}const Ii=4,eh=[.125,.215,.35,.446,.526,.582],Zi=20,Uv=256,hr=new Gc,th=new et;let el=null,tl=0,nl=0,il=!1;const Ov=new B;class nh{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._backgroundBox=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null}fromScene(e,t=0,i=.1,s=100,r={}){const{size:a=256,position:o=Ov}=r;el=this._renderer.getRenderTarget(),tl=this._renderer.getActiveCubeFace(),nl=this._renderer.getActiveMipmapLevel(),il=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(a);const l=this._allocateTargets();return l.depthBuffer=!0,this._sceneToCubeUV(e,i,s,l,o),t>0&&this._blur(l,0,0,t),this._applyPMREM(l),this._cleanup(l),l}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=rh(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=sh(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._backgroundBox!==null&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodMeshes.length;e++)this._lodMeshes[e].geometry.dispose()}_cleanup(e){this._renderer.setRenderTarget(el,tl,nl),this._renderer.xr.enabled=il,e.scissorTest=!1,Ds(e,0,0,e.width,e.height)}_fromTexture(e,t){e.mapping===es||e.mapping===Vs?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4),el=this._renderer.getRenderTarget(),tl=this._renderer.getActiveCubeFace(),nl=this._renderer.getActiveMipmapLevel(),il=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const i=t||this._allocateTargets();return this._textureToCubeUV(e,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize,i={magFilter:Xt,minFilter:Xt,generateMipmaps:!1,type:mi,format:En,colorSpace:Ya,depthBuffer:!1},s=ih(e,t,i);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=ih(e,t,i);const{_lodMax:r}=this;({lodMeshes:this._lodMeshes,sizeLods:this._sizeLods,sigmas:this._sigmas}=Fv(r)),this._blurMaterial=kv(r,e,t),this._ggxMaterial=Nv(r,e,t)}return s}_compileMaterial(e){const t=new Gt(new wt,e);this._renderer.compile(t,hr)}_sceneToCubeUV(e,t,i,s,r){const l=new Pn(90,1,t,i),c=[1,-1,1,1,1,1],u=[1,1,1,-1,-1,-1],f=this._renderer,h=f.autoClear,d=f.toneMapping;f.getClearColor(th),f.toneMapping=Kn,f.autoClear=!1,f.state.buffers.depth.getReversed()&&(f.setRenderTarget(s),f.clearDepth(),f.setRenderTarget(null)),this._backgroundBox===null&&(this._backgroundBox=new Gt(new Ur,new Vn({name:"PMREM.Background",side:un,depthWrite:!1,depthTest:!1})));const x=this._backgroundBox,m=x.material;let g=!1;const M=e.background;M?M.isColor&&(m.color.copy(M),e.background=null,g=!0):(m.color.copy(th),g=!0);for(let E=0;E<6;E++){const _=E%3;_===0?(l.up.set(0,c[E],0),l.position.set(r.x,r.y,r.z),l.lookAt(r.x+u[E],r.y,r.z)):_===1?(l.up.set(0,0,c[E]),l.position.set(r.x,r.y,r.z),l.lookAt(r.x,r.y+u[E],r.z)):(l.up.set(0,c[E],0),l.position.set(r.x,r.y,r.z),l.lookAt(r.x,r.y,r.z+u[E]));const T=this._cubeSize;Ds(s,_*T,E>2?T:0,T,T),f.setRenderTarget(s),g&&f.render(x,l),f.render(e,l)}f.toneMapping=d,f.autoClear=h,e.background=M}_textureToCubeUV(e,t){const i=this._renderer,s=e.mapping===es||e.mapping===Vs;s?(this._cubemapMaterial===null&&(this._cubemapMaterial=rh()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=sh());const r=s?this._cubemapMaterial:this._equirectMaterial,a=this._lodMeshes[0];a.material=r;const o=r.uniforms;o.envMap.value=e;const l=this._cubeSize;Ds(t,0,0,3*l,2*l),i.setRenderTarget(t),i.render(a,hr)}_applyPMREM(e){const t=this._renderer,i=t.autoClear;t.autoClear=!1;const s=this._lodMeshes.length;for(let r=1;r<s;r++)this._applyGGXFilter(e,r-1,r);t.autoClear=i}_applyGGXFilter(e,t,i){const s=this._renderer,r=this._pingPongRenderTarget,a=this._ggxMaterial,o=this._lodMeshes[i];o.material=a;const l=a.uniforms,c=i/(this._lodMeshes.length-1),u=t/(this._lodMeshes.length-1),f=Math.sqrt(c*c-u*u),h=0+c*1.25,d=f*h,{_lodMax:p}=this,x=this._sizeLods[i],m=3*x*(i>p-Ii?i-p+Ii:0),g=4*(this._cubeSize-x);l.envMap.value=e.texture,l.roughness.value=d,l.mipInt.value=p-t,Ds(r,m,g,3*x,2*x),s.setRenderTarget(r),s.render(o,hr),l.envMap.value=r.texture,l.roughness.value=0,l.mipInt.value=p-i,Ds(e,m,g,3*x,2*x),s.setRenderTarget(e),s.render(o,hr)}_blur(e,t,i,s,r){const a=this._pingPongRenderTarget;this._halfBlur(e,a,t,i,s,"latitudinal",r),this._halfBlur(a,e,i,i,s,"longitudinal",r)}_halfBlur(e,t,i,s,r,a,o){const l=this._renderer,c=this._blurMaterial;a!=="latitudinal"&&a!=="longitudinal"&&st("blur direction must be either latitudinal or longitudinal!");const u=3,f=this._lodMeshes[s];f.material=c;const h=c.uniforms,d=this._sizeLods[i]-1,p=isFinite(r)?Math.PI/(2*d):2*Math.PI/(2*Zi-1),x=r/p,m=isFinite(r)?1+Math.floor(u*x):Zi;m>Zi&&We(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${Zi}`);const g=[];let M=0;for(let S=0;S<Zi;++S){const v=S/x,w=Math.exp(-v*v/2);g.push(w),S===0?M+=w:S<m&&(M+=2*w)}for(let S=0;S<g.length;S++)g[S]=g[S]/M;h.envMap.value=e.texture,h.samples.value=m,h.weights.value=g,h.latitudinal.value=a==="latitudinal",o&&(h.poleAxis.value=o);const{_lodMax:E}=this;h.dTheta.value=p,h.mipInt.value=E-i;const _=this._sizeLods[s],T=3*_*(s>E-Ii?s-E+Ii:0),b=4*(this._cubeSize-_);Ds(t,T,b,3*_,2*_),l.setRenderTarget(t),l.render(f,hr)}}function Fv(n){const e=[],t=[],i=[];let s=n;const r=n-Ii+1+eh.length;for(let a=0;a<r;a++){const o=Math.pow(2,s);e.push(o);let l=1/o;a>n-Ii?l=eh[a-n+Ii-1]:a===0&&(l=0),t.push(l);const c=1/(o-2),u=-c,f=1+c,h=[u,u,f,u,f,f,u,u,f,f,u,f],d=6,p=6,x=3,m=2,g=1,M=new Float32Array(x*p*d),E=new Float32Array(m*p*d),_=new Float32Array(g*p*d);for(let b=0;b<d;b++){const S=b%3*2/3-1,v=b>2?0:-1,w=[S,v,0,S+2/3,v,0,S+2/3,v+1,0,S,v,0,S+2/3,v+1,0,S,v+1,0];M.set(w,x*p*b),E.set(h,m*p*b);const I=[b,b,b,b,b,b];_.set(I,g*p*b)}const T=new wt;T.setAttribute("position",new Dn(M,x)),T.setAttribute("uv",new Dn(E,m)),T.setAttribute("faceIndex",new Dn(_,g)),i.push(new Gt(T,null)),s>Ii&&s--}return{lodMeshes:i,sizeLods:e,sigmas:t}}function ih(n,e,t){const i=new Jn(n,e,t);return i.texture.mapping=mo,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function Ds(n,e,t,i,s){n.viewport.set(e,t,i,s),n.scissor.set(e,t,i,s)}function Nv(n,e,t){return new In({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:Uv,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/t,CUBEUV_MAX_MIP:`${n}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:xo(),fragmentShader:`
|
|
|
|
precision highp float;
|
|
precision highp int;
|
|
|
|
varying vec3 vOutputDirection;
|
|
|
|
uniform sampler2D envMap;
|
|
uniform float roughness;
|
|
uniform float mipInt;
|
|
|
|
#define ENVMAP_TYPE_CUBE_UV
|
|
#include <cube_uv_reflection_fragment>
|
|
|
|
#define PI 3.14159265359
|
|
|
|
// Van der Corput radical inverse
|
|
float radicalInverse_VdC(uint bits) {
|
|
bits = (bits << 16u) | (bits >> 16u);
|
|
bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
|
|
bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
|
|
bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
|
|
bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
|
|
return float(bits) * 2.3283064365386963e-10; // / 0x100000000
|
|
}
|
|
|
|
// Hammersley sequence
|
|
vec2 hammersley(uint i, uint N) {
|
|
return vec2(float(i) / float(N), radicalInverse_VdC(i));
|
|
}
|
|
|
|
// GGX VNDF importance sampling (Eric Heitz 2018)
|
|
// "Sampling the GGX Distribution of Visible Normals"
|
|
// https://jcgt.org/published/0007/04/01/
|
|
vec3 importanceSampleGGX_VNDF(vec2 Xi, vec3 V, float roughness) {
|
|
float alpha = roughness * roughness;
|
|
|
|
// Section 4.1: Orthonormal basis
|
|
vec3 T1 = vec3(1.0, 0.0, 0.0);
|
|
vec3 T2 = cross(V, T1);
|
|
|
|
// Section 4.2: Parameterization of projected area
|
|
float r = sqrt(Xi.x);
|
|
float phi = 2.0 * PI * Xi.y;
|
|
float t1 = r * cos(phi);
|
|
float t2 = r * sin(phi);
|
|
float s = 0.5 * (1.0 + V.z);
|
|
t2 = (1.0 - s) * sqrt(1.0 - t1 * t1) + s * t2;
|
|
|
|
// Section 4.3: Reprojection onto hemisphere
|
|
vec3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * V;
|
|
|
|
// Section 3.4: Transform back to ellipsoid configuration
|
|
return normalize(vec3(alpha * Nh.x, alpha * Nh.y, max(0.0, Nh.z)));
|
|
}
|
|
|
|
void main() {
|
|
vec3 N = normalize(vOutputDirection);
|
|
vec3 V = N; // Assume view direction equals normal for pre-filtering
|
|
|
|
vec3 prefilteredColor = vec3(0.0);
|
|
float totalWeight = 0.0;
|
|
|
|
// For very low roughness, just sample the environment directly
|
|
if (roughness < 0.001) {
|
|
gl_FragColor = vec4(bilinearCubeUV(envMap, N, mipInt), 1.0);
|
|
return;
|
|
}
|
|
|
|
// Tangent space basis for VNDF sampling
|
|
vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
|
vec3 tangent = normalize(cross(up, N));
|
|
vec3 bitangent = cross(N, tangent);
|
|
|
|
for(uint i = 0u; i < uint(GGX_SAMPLES); i++) {
|
|
vec2 Xi = hammersley(i, uint(GGX_SAMPLES));
|
|
|
|
// For PMREM, V = N, so in tangent space V is always (0, 0, 1)
|
|
vec3 H_tangent = importanceSampleGGX_VNDF(Xi, vec3(0.0, 0.0, 1.0), roughness);
|
|
|
|
// Transform H back to world space
|
|
vec3 H = normalize(tangent * H_tangent.x + bitangent * H_tangent.y + N * H_tangent.z);
|
|
vec3 L = normalize(2.0 * dot(V, H) * H - V);
|
|
|
|
float NdotL = max(dot(N, L), 0.0);
|
|
|
|
if(NdotL > 0.0) {
|
|
// Sample environment at fixed mip level
|
|
// VNDF importance sampling handles the distribution filtering
|
|
vec3 sampleColor = bilinearCubeUV(envMap, L, mipInt);
|
|
|
|
// Weight by NdotL for the split-sum approximation
|
|
// VNDF PDF naturally accounts for the visible microfacet distribution
|
|
prefilteredColor += sampleColor * NdotL;
|
|
totalWeight += NdotL;
|
|
}
|
|
}
|
|
|
|
if (totalWeight > 0.0) {
|
|
prefilteredColor = prefilteredColor / totalWeight;
|
|
}
|
|
|
|
gl_FragColor = vec4(prefilteredColor, 1.0);
|
|
}
|
|
`,blending:hi,depthTest:!1,depthWrite:!1})}function kv(n,e,t){const i=new Float32Array(Zi),s=new B(0,1,0);return new In({name:"SphericalGaussianBlur",defines:{n:Zi,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/t,CUBEUV_MAX_MIP:`${n}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:i},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:s}},vertexShader:xo(),fragmentShader:`
|
|
|
|
precision mediump float;
|
|
precision mediump int;
|
|
|
|
varying vec3 vOutputDirection;
|
|
|
|
uniform sampler2D envMap;
|
|
uniform int samples;
|
|
uniform float weights[ n ];
|
|
uniform bool latitudinal;
|
|
uniform float dTheta;
|
|
uniform float mipInt;
|
|
uniform vec3 poleAxis;
|
|
|
|
#define ENVMAP_TYPE_CUBE_UV
|
|
#include <cube_uv_reflection_fragment>
|
|
|
|
vec3 getSample( float theta, vec3 axis ) {
|
|
|
|
float cosTheta = cos( theta );
|
|
// Rodrigues' axis-angle rotation
|
|
vec3 sampleDirection = vOutputDirection * cosTheta
|
|
+ cross( axis, vOutputDirection ) * sin( theta )
|
|
+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
|
|
|
|
return bilinearCubeUV( envMap, sampleDirection, mipInt );
|
|
|
|
}
|
|
|
|
void main() {
|
|
|
|
vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
|
|
|
|
if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
|
|
|
|
axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
|
|
|
|
}
|
|
|
|
axis = normalize( axis );
|
|
|
|
gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
|
|
gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
|
|
|
|
for ( int i = 1; i < n; i++ ) {
|
|
|
|
if ( i >= samples ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
float theta = dTheta * float( i );
|
|
gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
|
|
gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
|
|
|
|
}
|
|
|
|
}
|
|
`,blending:hi,depthTest:!1,depthWrite:!1})}function sh(){return new In({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:xo(),fragmentShader:`
|
|
|
|
precision mediump float;
|
|
precision mediump int;
|
|
|
|
varying vec3 vOutputDirection;
|
|
|
|
uniform sampler2D envMap;
|
|
|
|
#include <common>
|
|
|
|
void main() {
|
|
|
|
vec3 outputDirection = normalize( vOutputDirection );
|
|
vec2 uv = equirectUv( outputDirection );
|
|
|
|
gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );
|
|
|
|
}
|
|
`,blending:hi,depthTest:!1,depthWrite:!1})}function rh(){return new In({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:xo(),fragmentShader:`
|
|
|
|
precision mediump float;
|
|
precision mediump int;
|
|
|
|
uniform float flipEnvMap;
|
|
|
|
varying vec3 vOutputDirection;
|
|
|
|
uniform samplerCube envMap;
|
|
|
|
void main() {
|
|
|
|
gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );
|
|
|
|
}
|
|
`,blending:hi,depthTest:!1,depthWrite:!1})}function xo(){return`
|
|
|
|
precision mediump float;
|
|
precision mediump int;
|
|
|
|
attribute float faceIndex;
|
|
|
|
varying vec3 vOutputDirection;
|
|
|
|
// RH coordinate system; PMREM face-indexing convention
|
|
vec3 getDirection( vec2 uv, float face ) {
|
|
|
|
uv = 2.0 * uv - 1.0;
|
|
|
|
vec3 direction = vec3( uv, 1.0 );
|
|
|
|
if ( face == 0.0 ) {
|
|
|
|
direction = direction.zyx; // ( 1, v, u ) pos x
|
|
|
|
} else if ( face == 1.0 ) {
|
|
|
|
direction = direction.xzy;
|
|
direction.xz *= -1.0; // ( -u, 1, -v ) pos y
|
|
|
|
} else if ( face == 2.0 ) {
|
|
|
|
direction.x *= -1.0; // ( -u, v, 1 ) pos z
|
|
|
|
} else if ( face == 3.0 ) {
|
|
|
|
direction = direction.zyx;
|
|
direction.xz *= -1.0; // ( -1, v, -u ) neg x
|
|
|
|
} else if ( face == 4.0 ) {
|
|
|
|
direction = direction.xzy;
|
|
direction.xy *= -1.0; // ( -u, -1, v ) neg y
|
|
|
|
} else if ( face == 5.0 ) {
|
|
|
|
direction.z *= -1.0; // ( u, v, -1 ) neg z
|
|
|
|
}
|
|
|
|
return direction;
|
|
|
|
}
|
|
|
|
void main() {
|
|
|
|
vOutputDirection = getDirection( uv, faceIndex );
|
|
gl_Position = vec4( position, 1.0 );
|
|
|
|
}
|
|
`}class yd extends Jn{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;const i={width:e,height:e,depth:1},s=[i,i,i,i,i,i];this.texture=new sd(s),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const i={uniforms:{tEquirect:{value:null}},vertexShader:`
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
|
|
|
|
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
|
|
|
|
}
|
|
|
|
void main() {
|
|
|
|
vWorldDirection = transformDirection( position, modelMatrix );
|
|
|
|
#include <begin_vertex>
|
|
#include <project_vertex>
|
|
|
|
}
|
|
`,fragmentShader:`
|
|
|
|
uniform sampler2D tEquirect;
|
|
|
|
varying vec3 vWorldDirection;
|
|
|
|
#include <common>
|
|
|
|
void main() {
|
|
|
|
vec3 direction = normalize( vWorldDirection );
|
|
|
|
vec2 sampleUV = equirectUv( direction );
|
|
|
|
gl_FragColor = texture2D( tEquirect, sampleUV );
|
|
|
|
}
|
|
`},s=new Ur(5,5,5),r=new In({name:"CubemapFromEquirect",uniforms:Ys(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:un,blending:hi});r.uniforms.tEquirect.value=t;const a=new Gt(s,r),o=t.minFilter;return t.minFilter===Di&&(t.minFilter=Xt),new Vg(1,10,this).update(e,a),t.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(e,t=!0,i=!0,s=!0){const r=e.getRenderTarget();for(let a=0;a<6;a++)e.setRenderTarget(this,a),e.clear(t,i,s);e.setRenderTarget(r)}}function Bv(n){let e=new WeakMap,t=new WeakMap,i=null;function s(h,d=!1){return h==null?null:d?a(h):r(h)}function r(h){if(h&&h.isTexture){const d=h.mapping;if(d===Mo||d===Eo)if(e.has(h)){const p=e.get(h).texture;return o(p,h.mapping)}else{const p=h.image;if(p&&p.height>0){const x=new yd(p.height);return x.fromEquirectangularTexture(n,h),e.set(h,x),h.addEventListener("dispose",c),o(x.texture,h.mapping)}else return null}}return h}function a(h){if(h&&h.isTexture){const d=h.mapping,p=d===Mo||d===Eo,x=d===es||d===Vs;if(p||x){let m=t.get(h);const g=m!==void 0?m.texture.pmremVersion:0;if(h.isRenderTargetTexture&&h.pmremVersion!==g)return i===null&&(i=new nh(n)),m=p?i.fromEquirectangular(h,m):i.fromCubemap(h,m),m.texture.pmremVersion=h.pmremVersion,t.set(h,m),m.texture;if(m!==void 0)return m.texture;{const M=h.image;return p&&M&&M.height>0||x&&M&&l(M)?(i===null&&(i=new nh(n)),m=p?i.fromEquirectangular(h):i.fromCubemap(h),m.texture.pmremVersion=h.pmremVersion,t.set(h,m),h.addEventListener("dispose",u),m.texture):null}}}return h}function o(h,d){return d===Mo?h.mapping=es:d===Eo&&(h.mapping=Vs),h}function l(h){let d=0;const p=6;for(let x=0;x<p;x++)h[x]!==void 0&&d++;return d===p}function c(h){const d=h.target;d.removeEventListener("dispose",c);const p=e.get(d);p!==void 0&&(e.delete(d),p.dispose())}function u(h){const d=h.target;d.removeEventListener("dispose",u);const p=t.get(d);p!==void 0&&(t.delete(d),p.dispose())}function f(){e=new WeakMap,t=new WeakMap,i!==null&&(i.dispose(),i=null)}return{get:s,dispose:f}}function Hv(n){const e={};function t(i){if(e[i]!==void 0)return e[i];const s=n.getExtension(i);return e[i]=s,s}return{has:function(i){return t(i)!==null},init:function(){t("EXT_color_buffer_float"),t("WEBGL_clip_cull_distance"),t("OES_texture_float_linear"),t("EXT_color_buffer_half_float"),t("WEBGL_multisampled_render_to_texture"),t("WEBGL_render_shared_exponent")},get:function(i){const s=t(i);return s===null&&Bs("WebGLRenderer: "+i+" extension not supported."),s}}}function zv(n,e,t,i){const s={},r=new WeakMap;function a(f){const h=f.target;h.index!==null&&e.remove(h.index);for(const p in h.attributes)e.remove(h.attributes[p]);h.removeEventListener("dispose",a),delete s[h.id];const d=r.get(h);d&&(e.remove(d),r.delete(h)),i.releaseStatesOfGeometry(h),h.isInstancedBufferGeometry===!0&&delete h._maxInstanceCount,t.memory.geometries--}function o(f,h){return s[h.id]===!0||(h.addEventListener("dispose",a),s[h.id]=!0,t.memory.geometries++),h}function l(f){const h=f.attributes;for(const d in h)e.update(h[d],n.ARRAY_BUFFER)}function c(f){const h=[],d=f.index,p=f.attributes.position;let x=0;if(p===void 0)return;if(d!==null){const M=d.array;x=d.version;for(let E=0,_=M.length;E<_;E+=3){const T=M[E+0],b=M[E+1],S=M[E+2];h.push(T,b,b,S,S,T)}}else{const M=p.array;x=p.version;for(let E=0,_=M.length/3-1;E<_;E+=3){const T=E+0,b=E+1,S=E+2;h.push(T,b,b,S,S,T)}}const m=new(p.count>=65535?Qf:jf)(h,1);m.version=x;const g=r.get(f);g&&e.remove(g),r.set(f,m)}function u(f){const h=r.get(f);if(h){const d=f.index;d!==null&&h.version<d.version&&c(f)}else c(f);return r.get(f)}return{get:o,update:l,getWireframeAttribute:u}}function Gv(n,e,t){let i;function s(f){i=f}let r,a;function o(f){r=f.type,a=f.bytesPerElement}function l(f,h){n.drawElements(i,h,r,f*a),t.update(h,i,1)}function c(f,h,d){d!==0&&(n.drawElementsInstanced(i,h,r,f*a,d),t.update(h,i,d))}function u(f,h,d){if(d===0)return;e.get("WEBGL_multi_draw").multiDrawElementsWEBGL(i,h,0,r,f,0,d);let x=0;for(let m=0;m<d;m++)x+=h[m];t.update(x,i,1)}this.setMode=s,this.setIndex=o,this.render=l,this.renderInstances=c,this.renderMultiDraw=u}function Vv(n){const e={geometries:0,textures:0},t={frame:0,calls:0,triangles:0,points:0,lines:0};function i(r,a,o){switch(t.calls++,a){case n.TRIANGLES:t.triangles+=o*(r/3);break;case n.LINES:t.lines+=o*(r/2);break;case n.LINE_STRIP:t.lines+=o*(r-1);break;case n.LINE_LOOP:t.lines+=o*r;break;case n.POINTS:t.points+=o*r;break;default:st("WebGLInfo: Unknown draw mode:",a);break}}function s(){t.calls=0,t.triangles=0,t.points=0,t.lines=0}return{memory:e,render:t,programs:null,autoReset:!0,reset:s,update:i}}function Wv(n,e,t){const i=new WeakMap,s=new Ct;function r(a,o,l){const c=a.morphTargetInfluences,u=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,f=u!==void 0?u.length:0;let h=i.get(o);if(h===void 0||h.count!==f){let I=function(){v.dispose(),i.delete(o),o.removeEventListener("dispose",I)};var d=I;h!==void 0&&h.texture.dispose();const p=o.morphAttributes.position!==void 0,x=o.morphAttributes.normal!==void 0,m=o.morphAttributes.color!==void 0,g=o.morphAttributes.position||[],M=o.morphAttributes.normal||[],E=o.morphAttributes.color||[];let _=0;p===!0&&(_=1),x===!0&&(_=2),m===!0&&(_=3);let T=o.attributes.position.count*_,b=1;T>e.maxTextureSize&&(b=Math.ceil(T/e.maxTextureSize),T=e.maxTextureSize);const S=new Float32Array(T*b*4*f),v=new Zf(S,T,b,f);v.type=Ln,v.needsUpdate=!0;const w=_*4;for(let L=0;L<f;L++){const C=g[L],O=M[L],N=E[L],U=T*b*4*L;for(let Z=0;Z<C.count;Z++){const k=Z*w;p===!0&&(s.fromBufferAttribute(C,Z),S[U+k+0]=s.x,S[U+k+1]=s.y,S[U+k+2]=s.z,S[U+k+3]=0),x===!0&&(s.fromBufferAttribute(O,Z),S[U+k+4]=s.x,S[U+k+5]=s.y,S[U+k+6]=s.z,S[U+k+7]=0),m===!0&&(s.fromBufferAttribute(N,Z),S[U+k+8]=s.x,S[U+k+9]=s.y,S[U+k+10]=s.z,S[U+k+11]=N.itemSize===4?s.w:1)}}h={count:f,texture:v,size:new Ee(T,b)},i.set(o,h),o.addEventListener("dispose",I)}if(a.isInstancedMesh===!0&&a.morphTexture!==null)l.getUniforms().setValue(n,"morphTexture",a.morphTexture,t);else{let p=0;for(let m=0;m<c.length;m++)p+=c[m];const x=o.morphTargetsRelative?1:1-p;l.getUniforms().setValue(n,"morphTargetBaseInfluence",x),l.getUniforms().setValue(n,"morphTargetInfluences",c)}l.getUniforms().setValue(n,"morphTargetsTexture",h.texture,t),l.getUniforms().setValue(n,"morphTargetsTextureSize",h.size)}return{update:r}}function Xv(n,e,t,i,s){let r=new WeakMap;function a(c){const u=s.render.frame,f=c.geometry,h=e.get(c,f);if(r.get(h)!==u&&(e.update(h),r.set(h,u)),c.isInstancedMesh&&(c.hasEventListener("dispose",l)===!1&&c.addEventListener("dispose",l),r.get(c)!==u&&(t.update(c.instanceMatrix,n.ARRAY_BUFFER),c.instanceColor!==null&&t.update(c.instanceColor,n.ARRAY_BUFFER),r.set(c,u))),c.isSkinnedMesh){const d=c.skeleton;r.get(d)!==u&&(d.update(),r.set(d,u))}return h}function o(){r=new WeakMap}function l(c){const u=c.target;u.removeEventListener("dispose",l),i.releaseStatesOfObject(u),t.remove(u.instanceMatrix),u.instanceColor!==null&&t.remove(u.instanceColor)}return{update:a,dispose:o}}const Yv={[If]:"LINEAR_TONE_MAPPING",[Uf]:"REINHARD_TONE_MAPPING",[Of]:"CINEON_TONE_MAPPING",[Ff]:"ACES_FILMIC_TONE_MAPPING",[kf]:"AGX_TONE_MAPPING",[Bf]:"NEUTRAL_TONE_MAPPING",[Nf]:"CUSTOM_TONE_MAPPING"};function qv(n,e,t,i,s,r){const a=new Jn(e,t,{type:n,depthBuffer:s,stencilBuffer:r,samples:i?4:0,depthTexture:s?new Ws(e,t):void 0}),o=new Jn(e,t,{type:mi,depthBuffer:!1,stencilBuffer:!1}),l=new wt;l.setAttribute("position",new ht([-1,3,0,-1,-1,0,3,-1,0],3)),l.setAttribute("uv",new ht([0,2,0,0,2,0],2));const c=new Bg({uniforms:{tDiffuse:{value:null}},vertexShader:`
|
|
precision highp float;
|
|
|
|
uniform mat4 modelViewMatrix;
|
|
uniform mat4 projectionMatrix;
|
|
|
|
attribute vec3 position;
|
|
attribute vec2 uv;
|
|
|
|
varying vec2 vUv;
|
|
|
|
void main() {
|
|
vUv = uv;
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
}`,fragmentShader:`
|
|
precision highp float;
|
|
|
|
uniform sampler2D tDiffuse;
|
|
|
|
varying vec2 vUv;
|
|
|
|
#include <tonemapping_pars_fragment>
|
|
#include <colorspace_pars_fragment>
|
|
|
|
void main() {
|
|
gl_FragColor = texture2D( tDiffuse, vUv );
|
|
|
|
#ifdef LINEAR_TONE_MAPPING
|
|
gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
|
|
#elif defined( REINHARD_TONE_MAPPING )
|
|
gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
|
|
#elif defined( CINEON_TONE_MAPPING )
|
|
gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );
|
|
#elif defined( ACES_FILMIC_TONE_MAPPING )
|
|
gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
|
|
#elif defined( AGX_TONE_MAPPING )
|
|
gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
|
|
#elif defined( NEUTRAL_TONE_MAPPING )
|
|
gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
|
|
#elif defined( CUSTOM_TONE_MAPPING )
|
|
gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
|
|
#endif
|
|
|
|
#ifdef SRGB_TRANSFER
|
|
gl_FragColor = sRGBTransferOETF( gl_FragColor );
|
|
#endif
|
|
}`,depthTest:!1,depthWrite:!1}),u=new Gt(l,c),f=new Gc(-1,1,1,-1,0,1);let h=null,d=null,p=!1,x,m=null,g=[],M=!1;this.setSize=function(E,_){a.setSize(E,_),o.setSize(E,_);for(let T=0;T<g.length;T++){const b=g[T];b.setSize&&b.setSize(E,_)}},this.setEffects=function(E){g=E,M=g.length>0&&g[0].isRenderPass===!0;const _=a.width,T=a.height;for(let b=0;b<g.length;b++){const S=g[b];S.setSize&&S.setSize(_,T)}},this.begin=function(E,_){if(p||E.toneMapping===Kn&&g.length===0)return!1;if(m=_,_!==null){const T=_.width,b=_.height;(a.width!==T||a.height!==b)&&this.setSize(T,b)}return M===!1&&E.setRenderTarget(a),x=E.toneMapping,E.toneMapping=Kn,!0},this.hasRenderPass=function(){return M},this.end=function(E,_){E.toneMapping=x,p=!0;let T=a,b=o;for(let S=0;S<g.length;S++){const v=g[S];if(v.enabled!==!1&&(v.render(E,b,T,_),v.needsSwap!==!1)){const w=T;T=b,b=w}}if(h!==E.outputColorSpace||d!==E.toneMapping){h=E.outputColorSpace,d=E.toneMapping,c.defines={},nt.getTransfer(h)===ft&&(c.defines.SRGB_TRANSFER="");const S=Yv[d];S&&(c.defines[S]=""),c.needsUpdate=!0}c.uniforms.tDiffuse.value=T.texture,E.setRenderTarget(m),E.render(u,f),m=null,p=!1},this.isCompositing=function(){return p},this.dispose=function(){a.depthTexture&&a.depthTexture.dispose(),a.dispose(),o.dispose(),l.dispose(),c.dispose()}}const _d=new Qt,mc=new Ws(1,1),bd=new Zf,Sd=new km,Md=new sd,ah=[],oh=[],lh=new Float32Array(16),ch=new Float32Array(9),uh=new Float32Array(4);function Qs(n,e,t){const i=n[0];if(i<=0||i>0)return n;const s=e*t;let r=ah[s];if(r===void 0&&(r=new Float32Array(s),ah[s]=r),e!==0){i.toArray(r,0);for(let a=1,o=0;a!==e;++a)o+=t,n[a].toArray(r,o)}return r}function Nt(n,e){if(n.length!==e.length)return!1;for(let t=0,i=n.length;t<i;t++)if(n[t]!==e[t])return!1;return!0}function kt(n,e){for(let t=0,i=e.length;t<i;t++)n[t]=e[t]}function vo(n,e){let t=oh[e];t===void 0&&(t=new Int32Array(e),oh[e]=t);for(let i=0;i!==e;++i)t[i]=n.allocateTextureUnit();return t}function $v(n,e){const t=this.cache;t[0]!==e&&(n.uniform1f(this.addr,e),t[0]=e)}function Zv(n,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(n.uniform2f(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(Nt(t,e))return;n.uniform2fv(this.addr,e),kt(t,e)}}function Kv(n,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(n.uniform3f(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else if(e.r!==void 0)(t[0]!==e.r||t[1]!==e.g||t[2]!==e.b)&&(n.uniform3f(this.addr,e.r,e.g,e.b),t[0]=e.r,t[1]=e.g,t[2]=e.b);else{if(Nt(t,e))return;n.uniform3fv(this.addr,e),kt(t,e)}}function Jv(n,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(n.uniform4f(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(Nt(t,e))return;n.uniform4fv(this.addr,e),kt(t,e)}}function jv(n,e){const t=this.cache,i=e.elements;if(i===void 0){if(Nt(t,e))return;n.uniformMatrix2fv(this.addr,!1,e),kt(t,e)}else{if(Nt(t,i))return;uh.set(i),n.uniformMatrix2fv(this.addr,!1,uh),kt(t,i)}}function Qv(n,e){const t=this.cache,i=e.elements;if(i===void 0){if(Nt(t,e))return;n.uniformMatrix3fv(this.addr,!1,e),kt(t,e)}else{if(Nt(t,i))return;ch.set(i),n.uniformMatrix3fv(this.addr,!1,ch),kt(t,i)}}function ey(n,e){const t=this.cache,i=e.elements;if(i===void 0){if(Nt(t,e))return;n.uniformMatrix4fv(this.addr,!1,e),kt(t,e)}else{if(Nt(t,i))return;lh.set(i),n.uniformMatrix4fv(this.addr,!1,lh),kt(t,i)}}function ty(n,e){const t=this.cache;t[0]!==e&&(n.uniform1i(this.addr,e),t[0]=e)}function ny(n,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(n.uniform2i(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(Nt(t,e))return;n.uniform2iv(this.addr,e),kt(t,e)}}function iy(n,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(n.uniform3i(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else{if(Nt(t,e))return;n.uniform3iv(this.addr,e),kt(t,e)}}function sy(n,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(n.uniform4i(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(Nt(t,e))return;n.uniform4iv(this.addr,e),kt(t,e)}}function ry(n,e){const t=this.cache;t[0]!==e&&(n.uniform1ui(this.addr,e),t[0]=e)}function ay(n,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(n.uniform2ui(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(Nt(t,e))return;n.uniform2uiv(this.addr,e),kt(t,e)}}function oy(n,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(n.uniform3ui(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else{if(Nt(t,e))return;n.uniform3uiv(this.addr,e),kt(t,e)}}function ly(n,e){const t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(n.uniform4ui(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(Nt(t,e))return;n.uniform4uiv(this.addr,e),kt(t,e)}}function cy(n,e,t){const i=this.cache,s=t.allocateTextureUnit();i[0]!==s&&(n.uniform1i(this.addr,s),i[0]=s);let r;this.type===n.SAMPLER_2D_SHADOW?(mc.compareFunction=t.isReversedDepthBuffer()?Fc:Oc,r=mc):r=_d,t.setTexture2D(e||r,s)}function uy(n,e,t){const i=this.cache,s=t.allocateTextureUnit();i[0]!==s&&(n.uniform1i(this.addr,s),i[0]=s),t.setTexture3D(e||Sd,s)}function hy(n,e,t){const i=this.cache,s=t.allocateTextureUnit();i[0]!==s&&(n.uniform1i(this.addr,s),i[0]=s),t.setTextureCube(e||Md,s)}function fy(n,e,t){const i=this.cache,s=t.allocateTextureUnit();i[0]!==s&&(n.uniform1i(this.addr,s),i[0]=s),t.setTexture2DArray(e||bd,s)}function dy(n){switch(n){case 5126:return $v;case 35664:return Zv;case 35665:return Kv;case 35666:return Jv;case 35674:return jv;case 35675:return Qv;case 35676:return ey;case 5124:case 35670:return ty;case 35667:case 35671:return ny;case 35668:case 35672:return iy;case 35669:case 35673:return sy;case 5125:return ry;case 36294:return ay;case 36295:return oy;case 36296:return ly;case 35678:case 36198:case 36298:case 36306:case 35682:return cy;case 35679:case 36299:case 36307:return uy;case 35680:case 36300:case 36308:case 36293:return hy;case 36289:case 36303:case 36311:case 36292:return fy}}function py(n,e){n.uniform1fv(this.addr,e)}function my(n,e){const t=Qs(e,this.size,2);n.uniform2fv(this.addr,t)}function gy(n,e){const t=Qs(e,this.size,3);n.uniform3fv(this.addr,t)}function xy(n,e){const t=Qs(e,this.size,4);n.uniform4fv(this.addr,t)}function vy(n,e){const t=Qs(e,this.size,4);n.uniformMatrix2fv(this.addr,!1,t)}function yy(n,e){const t=Qs(e,this.size,9);n.uniformMatrix3fv(this.addr,!1,t)}function _y(n,e){const t=Qs(e,this.size,16);n.uniformMatrix4fv(this.addr,!1,t)}function by(n,e){n.uniform1iv(this.addr,e)}function Sy(n,e){n.uniform2iv(this.addr,e)}function My(n,e){n.uniform3iv(this.addr,e)}function Ey(n,e){n.uniform4iv(this.addr,e)}function Ty(n,e){n.uniform1uiv(this.addr,e)}function Ay(n,e){n.uniform2uiv(this.addr,e)}function wy(n,e){n.uniform3uiv(this.addr,e)}function Cy(n,e){n.uniform4uiv(this.addr,e)}function Ry(n,e,t){const i=this.cache,s=e.length,r=vo(t,s);Nt(i,r)||(n.uniform1iv(this.addr,r),kt(i,r));let a;this.type===n.SAMPLER_2D_SHADOW?a=mc:a=_d;for(let o=0;o!==s;++o)t.setTexture2D(e[o]||a,r[o])}function Py(n,e,t){const i=this.cache,s=e.length,r=vo(t,s);Nt(i,r)||(n.uniform1iv(this.addr,r),kt(i,r));for(let a=0;a!==s;++a)t.setTexture3D(e[a]||Sd,r[a])}function Ly(n,e,t){const i=this.cache,s=e.length,r=vo(t,s);Nt(i,r)||(n.uniform1iv(this.addr,r),kt(i,r));for(let a=0;a!==s;++a)t.setTextureCube(e[a]||Md,r[a])}function Dy(n,e,t){const i=this.cache,s=e.length,r=vo(t,s);Nt(i,r)||(n.uniform1iv(this.addr,r),kt(i,r));for(let a=0;a!==s;++a)t.setTexture2DArray(e[a]||bd,r[a])}function Iy(n){switch(n){case 5126:return py;case 35664:return my;case 35665:return gy;case 35666:return xy;case 35674:return vy;case 35675:return yy;case 35676:return _y;case 5124:case 35670:return by;case 35667:case 35671:return Sy;case 35668:case 35672:return My;case 35669:case 35673:return Ey;case 5125:return Ty;case 36294:return Ay;case 36295:return wy;case 36296:return Cy;case 35678:case 36198:case 36298:case 36306:case 35682:return Ry;case 35679:case 36299:case 36307:return Py;case 35680:case 36300:case 36308:case 36293:return Ly;case 36289:case 36303:case 36311:case 36292:return Dy}}class Uy{constructor(e,t,i){this.id=e,this.addr=i,this.cache=[],this.type=t.type,this.setValue=dy(t.type)}}class Oy{constructor(e,t,i){this.id=e,this.addr=i,this.cache=[],this.type=t.type,this.size=t.size,this.setValue=Iy(t.type)}}class Fy{constructor(e){this.id=e,this.seq=[],this.map={}}setValue(e,t,i){const s=this.seq;for(let r=0,a=s.length;r!==a;++r){const o=s[r];o.setValue(e,t[o.id],i)}}}const sl=/(\w+)(\])?(\[|\.)?/g;function hh(n,e){n.seq.push(e),n.map[e.id]=e}function Ny(n,e,t){const i=n.name,s=i.length;for(sl.lastIndex=0;;){const r=sl.exec(i),a=sl.lastIndex;let o=r[1];const l=r[2]==="]",c=r[3];if(l&&(o=o|0),c===void 0||c==="["&&a+2===s){hh(t,c===void 0?new Uy(o,n,e):new Oy(o,n,e));break}else{let f=t.map[o];f===void 0&&(f=new Fy(o),hh(t,f)),t=f}}}class Ba{constructor(e,t){this.seq=[],this.map={};const i=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let a=0;a<i;++a){const o=e.getActiveUniform(t,a),l=e.getUniformLocation(t,o.name);Ny(o,l,this)}const s=[],r=[];for(const a of this.seq)a.type===e.SAMPLER_2D_SHADOW||a.type===e.SAMPLER_CUBE_SHADOW||a.type===e.SAMPLER_2D_ARRAY_SHADOW?s.push(a):r.push(a);s.length>0&&(this.seq=s.concat(r))}setValue(e,t,i,s){const r=this.map[t];r!==void 0&&r.setValue(e,i,s)}setOptional(e,t,i){const s=t[i];s!==void 0&&this.setValue(e,i,s)}static upload(e,t,i,s){for(let r=0,a=t.length;r!==a;++r){const o=t[r],l=i[o.id];l.needsUpdate!==!1&&o.setValue(e,l.value,s)}}static seqWithValue(e,t){const i=[];for(let s=0,r=e.length;s!==r;++s){const a=e[s];a.id in t&&i.push(a)}return i}}function fh(n,e,t){const i=n.createShader(e);return n.shaderSource(i,t),n.compileShader(i),i}const ky=37297;let By=0;function Hy(n,e){const t=n.split(`
|
|
`),i=[],s=Math.max(e-6,0),r=Math.min(e+6,t.length);for(let a=s;a<r;a++){const o=a+1;i.push(`${o===e?">":" "} ${o}: ${t[a]}`)}return i.join(`
|
|
`)}const dh=new $e;function zy(n){nt._getMatrix(dh,nt.workingColorSpace,n);const e=`mat3( ${dh.elements.map(t=>t.toFixed(4))} )`;switch(nt.getTransfer(n)){case qa:return[e,"LinearTransferOETF"];case ft:return[e,"sRGBTransferOETF"];default:return We("WebGLProgram: Unsupported color space: ",n),[e,"LinearTransferOETF"]}}function ph(n,e,t){const i=n.getShaderParameter(e,n.COMPILE_STATUS),r=(n.getShaderInfoLog(e)||"").trim();if(i&&r==="")return"";const a=/ERROR: 0:(\d+)/.exec(r);if(a){const o=parseInt(a[1]);return t.toUpperCase()+`
|
|
|
|
`+r+`
|
|
|
|
`+Hy(n.getShaderSource(e),o)}else return r}function Gy(n,e){const t=zy(e);return[`vec4 ${n}( vec4 value ) {`,` return ${t[1]}( vec4( value.rgb * ${t[0]}, value.a ) );`,"}"].join(`
|
|
`)}const Vy={[If]:"Linear",[Uf]:"Reinhard",[Of]:"Cineon",[Ff]:"ACESFilmic",[kf]:"AgX",[Bf]:"Neutral",[Nf]:"Custom"};function Wy(n,e){const t=Vy[e];return t===void 0?(We("WebGLProgram: Unsupported toneMapping:",e),"vec3 "+n+"( vec3 color ) { return LinearToneMapping( color ); }"):"vec3 "+n+"( vec3 color ) { return "+t+"ToneMapping( color ); }"}const _a=new B;function Xy(){nt.getLuminanceCoefficients(_a);const n=_a.x.toFixed(4),e=_a.y.toFixed(4),t=_a.z.toFixed(4);return["float luminance( const in vec3 rgb ) {",` const vec3 weights = vec3( ${n}, ${e}, ${t} );`," return dot( weights, rgb );","}"].join(`
|
|
`)}function Yy(n){return[n.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",n.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(vr).join(`
|
|
`)}function qy(n){const e=[];for(const t in n){const i=n[t];i!==!1&&e.push("#define "+t+" "+i)}return e.join(`
|
|
`)}function $y(n,e){const t={},i=n.getProgramParameter(e,n.ACTIVE_ATTRIBUTES);for(let s=0;s<i;s++){const r=n.getActiveAttrib(e,s),a=r.name;let o=1;r.type===n.FLOAT_MAT2&&(o=2),r.type===n.FLOAT_MAT3&&(o=3),r.type===n.FLOAT_MAT4&&(o=4),t[a]={type:r.type,location:n.getAttribLocation(e,a),locationSize:o}}return t}function vr(n){return n!==""}function mh(n,e){const t=e.numSpotLightShadows+e.numSpotLightMaps-e.numSpotLightShadowsWithMaps;return n.replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,e.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,t).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,e.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows)}function gh(n,e){return n.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const Zy=/^[ \t]*#include +<([\w\d./]+)>/gm;function gc(n){return n.replace(Zy,Jy)}const Ky=new Map;function Jy(n,e){let t=Je[e];if(t===void 0){const i=Ky.get(e);if(i!==void 0)t=Je[i],We('WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,i);else throw new Error("THREE.WebGLProgram: Can not resolve #include <"+e+">")}return gc(t)}const jy=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function xh(n){return n.replace(jy,Qy)}function Qy(n,e,t,i){let s="";for(let r=parseInt(e);r<parseInt(t);r++)s+=i.replace(/\[\s*i\s*\]/g,"[ "+r+" ]").replace(/UNROLLED_LOOP_INDEX/g,r);return s}function vh(n){let e=`precision ${n.precision} float;
|
|
precision ${n.precision} int;
|
|
precision ${n.precision} sampler2D;
|
|
precision ${n.precision} samplerCube;
|
|
precision ${n.precision} sampler3D;
|
|
precision ${n.precision} sampler2DArray;
|
|
precision ${n.precision} sampler2DShadow;
|
|
precision ${n.precision} samplerCubeShadow;
|
|
precision ${n.precision} sampler2DArrayShadow;
|
|
precision ${n.precision} isampler2D;
|
|
precision ${n.precision} isampler3D;
|
|
precision ${n.precision} isamplerCube;
|
|
precision ${n.precision} isampler2DArray;
|
|
precision ${n.precision} usampler2D;
|
|
precision ${n.precision} usampler3D;
|
|
precision ${n.precision} usamplerCube;
|
|
precision ${n.precision} usampler2DArray;
|
|
`;return n.precision==="highp"?e+=`
|
|
#define HIGH_PRECISION`:n.precision==="mediump"?e+=`
|
|
#define MEDIUM_PRECISION`:n.precision==="lowp"&&(e+=`
|
|
#define LOW_PRECISION`),e}const e_={[Ia]:"SHADOWMAP_TYPE_PCF",[mr]:"SHADOWMAP_TYPE_VSM"};function t_(n){return e_[n.shadowMapType]||"SHADOWMAP_TYPE_BASIC"}const n_={[es]:"ENVMAP_TYPE_CUBE",[Vs]:"ENVMAP_TYPE_CUBE",[mo]:"ENVMAP_TYPE_CUBE_UV"};function i_(n){return n.envMap===!1?"ENVMAP_TYPE_CUBE":n_[n.envMapMode]||"ENVMAP_TYPE_CUBE"}const s_={[Vs]:"ENVMAP_MODE_REFRACTION"};function r_(n){return n.envMap===!1?"ENVMAP_MODE_REFLECTION":s_[n.envMapMode]||"ENVMAP_MODE_REFLECTION"}const a_={[Df]:"ENVMAP_BLENDING_MULTIPLY",[gm]:"ENVMAP_BLENDING_MIX",[xm]:"ENVMAP_BLENDING_ADD"};function o_(n){return n.envMap===!1?"ENVMAP_BLENDING_NONE":a_[n.combine]||"ENVMAP_BLENDING_NONE"}function l_(n){const e=n.envMapCubeUVHeight;if(e===null)return null;const t=Math.log2(e)-2,i=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),7*16)),texelHeight:i,maxMip:t}}function c_(n,e,t,i){const s=n.getContext(),r=t.defines;let a=t.vertexShader,o=t.fragmentShader;const l=t_(t),c=i_(t),u=r_(t),f=o_(t),h=l_(t),d=Yy(t),p=qy(r),x=s.createProgram();let m,g,M=t.glslVersion?"#version "+t.glslVersion+`
|
|
`:"";t.isRawShaderMaterial?(m=["#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,p].filter(vr).join(`
|
|
`),m.length>0&&(m+=`
|
|
`),g=["#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,p].filter(vr).join(`
|
|
`),g.length>0&&(g+=`
|
|
`)):(m=[vh(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,p,t.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",t.batching?"#define USE_BATCHING":"",t.batchingColor?"#define USE_BATCHING_COLOR":"",t.instancing?"#define USE_INSTANCING":"",t.instancingColor?"#define USE_INSTANCING_COLOR":"",t.instancingMorph?"#define USE_INSTANCING_MORPH":"",t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.map?"#define USE_MAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+u:"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.displacementMap?"#define USE_DISPLACEMENTMAP":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.mapUv?"#define MAP_UV "+t.mapUv:"",t.alphaMapUv?"#define ALPHAMAP_UV "+t.alphaMapUv:"",t.lightMapUv?"#define LIGHTMAP_UV "+t.lightMapUv:"",t.aoMapUv?"#define AOMAP_UV "+t.aoMapUv:"",t.emissiveMapUv?"#define EMISSIVEMAP_UV "+t.emissiveMapUv:"",t.bumpMapUv?"#define BUMPMAP_UV "+t.bumpMapUv:"",t.normalMapUv?"#define NORMALMAP_UV "+t.normalMapUv:"",t.displacementMapUv?"#define DISPLACEMENTMAP_UV "+t.displacementMapUv:"",t.metalnessMapUv?"#define METALNESSMAP_UV "+t.metalnessMapUv:"",t.roughnessMapUv?"#define ROUGHNESSMAP_UV "+t.roughnessMapUv:"",t.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+t.anisotropyMapUv:"",t.clearcoatMapUv?"#define CLEARCOATMAP_UV "+t.clearcoatMapUv:"",t.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+t.clearcoatNormalMapUv:"",t.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+t.clearcoatRoughnessMapUv:"",t.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+t.iridescenceMapUv:"",t.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+t.iridescenceThicknessMapUv:"",t.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+t.sheenColorMapUv:"",t.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+t.sheenRoughnessMapUv:"",t.specularMapUv?"#define SPECULARMAP_UV "+t.specularMapUv:"",t.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+t.specularColorMapUv:"",t.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+t.specularIntensityMapUv:"",t.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+t.transmissionMapUv:"",t.thicknessMapUv?"#define THICKNESSMAP_UV "+t.thicknessMapUv:"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexNormals?"#define HAS_NORMAL":"",t.vertexColors?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.flatShading?"#define FLAT_SHADED":"",t.skinning?"#define USE_SKINNING":"",t.morphTargets?"#define USE_MORPHTARGETS":"",t.morphNormals&&t.flatShading===!1?"#define USE_MORPHNORMALS":"",t.morphColors?"#define USE_MORPHCOLORS":"",t.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+t.morphTextureStride:"",t.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+t.morphTargetsCount:"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.sizeAttenuation?"#define USE_SIZEATTENUATION":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",t.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","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","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH"," uniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1"," attribute vec2 uv1;","#endif","#ifdef USE_UV2"," attribute vec2 uv2;","#endif","#ifdef USE_UV3"," attribute vec2 uv3;","#endif","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif",`
|
|
`].filter(vr).join(`
|
|
`),g=[vh(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,p,t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",t.map?"#define USE_MAP":"",t.matcap?"#define USE_MATCAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+c:"",t.envMap?"#define "+u:"",t.envMap?"#define "+f:"",h?"#define CUBEUV_TEXEL_WIDTH "+h.texelWidth:"",h?"#define CUBEUV_TEXEL_HEIGHT "+h.texelHeight:"",h?"#define CUBEUV_MAX_MIP "+h.maxMip+".0":"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.packedNormalMap?"#define USE_PACKED_NORMALMAP":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoat?"#define USE_CLEARCOAT":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.dispersion?"#define USE_DISPERSION":"",t.iridescence?"#define USE_IRIDESCENCE":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaTest?"#define USE_ALPHATEST":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.sheen?"#define USE_SHEEN":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexColors||t.instancingColor?"#define USE_COLOR":"",t.vertexAlphas||t.batchingColor?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.gradientMap?"#define USE_GRADIENTMAP":"",t.flatShading?"#define FLAT_SHADED":"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.numLightProbeGrids>0?"#define USE_LIGHT_PROBES_GRID":"",t.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",t.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",t.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",t.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",t.toneMapping!==Kn?"#define TONE_MAPPING":"",t.toneMapping!==Kn?Je.tonemapping_pars_fragment:"",t.toneMapping!==Kn?Wy("toneMapping",t.toneMapping):"",t.dithering?"#define DITHERING":"",t.opaque?"#define OPAQUE":"",Je.colorspace_pars_fragment,Gy("linearToOutputTexel",t.outputColorSpace),Xy(),t.useDepthPacking?"#define DEPTH_PACKING "+t.depthPacking:"",`
|
|
`].filter(vr).join(`
|
|
`)),a=gc(a),a=mh(a,t),a=gh(a,t),o=gc(o),o=mh(o,t),o=gh(o,t),a=xh(a),o=xh(o),t.isRawShaderMaterial!==!0&&(M=`#version 300 es
|
|
`,m=[d,"#define attribute in","#define varying out","#define texture2D texture"].join(`
|
|
`)+`
|
|
`+m,g=["#define varying in",t.glslVersion===uc?"":"layout(location = 0) out highp vec4 pc_fragColor;",t.glslVersion===uc?"":"#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(`
|
|
`)+`
|
|
`+g);const E=M+m+a,_=M+g+o,T=fh(s,s.VERTEX_SHADER,E),b=fh(s,s.FRAGMENT_SHADER,_);s.attachShader(x,T),s.attachShader(x,b),t.index0AttributeName!==void 0?s.bindAttribLocation(x,0,t.index0AttributeName):t.hasPositionAttribute===!0&&s.bindAttribLocation(x,0,"position"),s.linkProgram(x);function S(L){if(n.debug.checkShaderErrors){const C=s.getProgramInfoLog(x)||"",O=s.getShaderInfoLog(T)||"",N=s.getShaderInfoLog(b)||"",U=C.trim(),Z=O.trim(),k=N.trim();let $=!0,D=!0;if(s.getProgramParameter(x,s.LINK_STATUS)===!1)if($=!1,typeof n.debug.onShaderError=="function")n.debug.onShaderError(s,x,T,b);else{const ae=ph(s,T,"vertex"),re=ph(s,b,"fragment");st("WebGLProgram: Shader Error "+s.getError()+" - VALIDATE_STATUS "+s.getProgramParameter(x,s.VALIDATE_STATUS)+`
|
|
|
|
Material Name: `+L.name+`
|
|
Material Type: `+L.type+`
|
|
|
|
Program Info Log: `+U+`
|
|
`+ae+`
|
|
`+re)}else U!==""?We("WebGLProgram: Program Info Log:",U):(Z===""||k==="")&&(D=!1);D&&(L.diagnostics={runnable:$,programLog:U,vertexShader:{log:Z,prefix:m},fragmentShader:{log:k,prefix:g}})}s.deleteShader(T),s.deleteShader(b),v=new Ba(s,x),w=$y(s,x)}let v;this.getUniforms=function(){return v===void 0&&S(this),v};let w;this.getAttributes=function(){return w===void 0&&S(this),w};let I=t.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return I===!1&&(I=s.getProgramParameter(x,ky)),I},this.destroy=function(){i.releaseStatesOfProgram(this),s.deleteProgram(x),this.program=void 0},this.type=t.shaderType,this.name=t.shaderName,this.id=By++,this.cacheKey=e,this.usedTimes=1,this.program=x,this.vertexShader=T,this.fragmentShader=b,this}let u_=0;class h_{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e,t,i){const s=this._getShaderCacheForMaterial(e);return s.has(t)===!1&&(s.add(t),t.usedTimes++),s.has(i)===!1&&(s.add(i),i.usedTimes++),this}remove(e){const t=this.materialCache.get(e);for(const i of t)i.usedTimes--,i.usedTimes===0&&this.shaderCache.delete(i.code);return this.materialCache.delete(e),this}getVertexShaderStage(e){return this._getShaderStage(e.vertexShader)}getFragmentShaderStage(e){return this._getShaderStage(e.fragmentShader)}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){const t=this.materialCache;let i=t.get(e);return i===void 0&&(i=new Set,t.set(e,i)),i}_getShaderStage(e){const t=this.shaderCache;let i=t.get(e);return i===void 0&&(i=new f_(e),t.set(e,i)),i}}class f_{constructor(e){this.id=u_++,this.code=e,this.usedTimes=0}}function d_(n){return n===ts||n===Wa||n===Xa}function p_(n,e,t,i,s,r){const a=new Kf,o=new h_,l=new Set,c=[],u=new Map,f=i.logarithmicDepthBuffer;let h=i.precision;const d={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distance",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function p(v){return l.add(v),v===0?"uv":`uv${v}`}function x(v,w,I,L,C,O){const N=L.fog,U=C.geometry,Z=v.isMeshStandardMaterial||v.isMeshLambertMaterial||v.isMeshPhongMaterial?L.environment:null,k=v.isMeshStandardMaterial||v.isMeshLambertMaterial&&!v.envMap||v.isMeshPhongMaterial&&!v.envMap,$=e.get(v.envMap||Z,k),D=$&&$.mapping===mo?$.image.height:null,ae=d[v.type];v.precision!==null&&(h=i.getMaxPrecision(v.precision),h!==v.precision&&We("WebGLProgram.getParameters:",v.precision,"not supported, using",h,"instead."));const re=U.morphAttributes.position||U.morphAttributes.normal||U.morphAttributes.color,ee=re!==void 0?re.length:0;let ce=0;U.morphAttributes.position!==void 0&&(ce=1),U.morphAttributes.normal!==void 0&&(ce=2),U.morphAttributes.color!==void 0&&(ce=3);let he,fe,X,se;if(ae){const Le=Yn[ae];he=Le.vertexShader,fe=Le.fragmentShader}else{he=v.vertexShader,fe=v.fragmentShader;const Le=o.getVertexShaderStage(v),yt=o.getFragmentShaderStage(v);o.update(v,Le,yt),X=Le.id,se=yt.id}const Q=n.getRenderTarget(),ye=n.state.buffers.depth.getReversed(),ve=C.isInstancedMesh===!0,_e=C.isBatchedMesh===!0,Ze=!!v.map,Ye=!!v.matcap,Oe=!!$,Fe=!!v.aoMap,Ve=!!v.lightMap,at=!!v.bumpMap&&v.wireframe===!1,ot=!!v.normalMap,pt=!!v.displacementMap,vt=!!v.emissiveMap,ct=!!v.metalnessMap,ut=!!v.roughnessMap,R=v.anisotropy>0,Ae=v.clearcoat>0,W=v.dispersion>0,P=v.iridescence>0,y=v.sheen>0,H=v.transmission>0,F=R&&!!v.anisotropyMap,G=Ae&&!!v.clearcoatMap,te=Ae&&!!v.clearcoatNormalMap,oe=Ae&&!!v.clearcoatRoughnessMap,V=P&&!!v.iridescenceMap,K=P&&!!v.iridescenceThicknessMap,ie=y&&!!v.sheenColorMap,de=y&&!!v.sheenRoughnessMap,pe=!!v.specularMap,ge=!!v.specularColorMap,Me=!!v.specularIntensityMap,He=H&&!!v.transmissionMap,qe=H&&!!v.thicknessMap,z=!!v.gradientMap,xe=!!v.alphaMap,le=v.alphaTest>0,be=!!v.alphaHash,Ce=!!v.extensions;let ue=Kn;v.toneMapped&&(Q===null||Q.isXRRenderTarget===!0)&&(ue=n.toneMapping);const ke={shaderID:ae,shaderType:v.type,shaderName:v.name,vertexShader:he,fragmentShader:fe,defines:v.defines,customVertexShaderID:X,customFragmentShaderID:se,isRawShaderMaterial:v.isRawShaderMaterial===!0,glslVersion:v.glslVersion,precision:h,batching:_e,batchingColor:_e&&C._colorsTexture!==null,instancing:ve,instancingColor:ve&&C.instanceColor!==null,instancingMorph:ve&&C.morphTexture!==null,outputColorSpace:Q===null?n.outputColorSpace:Q.isXRRenderTarget===!0?Q.texture.colorSpace:nt.workingColorSpace,alphaToCoverage:!!v.alphaToCoverage,map:Ze,matcap:Ye,envMap:Oe,envMapMode:Oe&&$.mapping,envMapCubeUVHeight:D,aoMap:Fe,lightMap:Ve,bumpMap:at,normalMap:ot,displacementMap:pt,emissiveMap:vt,normalMapObjectSpace:ot&&v.normalMapType===_m,normalMapTangentSpace:ot&&v.normalMapType===gu,packedNormalMap:ot&&v.normalMapType===gu&&d_(v.normalMap.format),metalnessMap:ct,roughnessMap:ut,anisotropy:R,anisotropyMap:F,clearcoat:Ae,clearcoatMap:G,clearcoatNormalMap:te,clearcoatRoughnessMap:oe,dispersion:W,iridescence:P,iridescenceMap:V,iridescenceThicknessMap:K,sheen:y,sheenColorMap:ie,sheenRoughnessMap:de,specularMap:pe,specularColorMap:ge,specularIntensityMap:Me,transmission:H,transmissionMap:He,thicknessMap:qe,gradientMap:z,opaque:v.transparent===!1&&v.blending===ks&&v.alphaToCoverage===!1,alphaMap:xe,alphaTest:le,alphaHash:be,combine:v.combine,mapUv:Ze&&p(v.map.channel),aoMapUv:Fe&&p(v.aoMap.channel),lightMapUv:Ve&&p(v.lightMap.channel),bumpMapUv:at&&p(v.bumpMap.channel),normalMapUv:ot&&p(v.normalMap.channel),displacementMapUv:pt&&p(v.displacementMap.channel),emissiveMapUv:vt&&p(v.emissiveMap.channel),metalnessMapUv:ct&&p(v.metalnessMap.channel),roughnessMapUv:ut&&p(v.roughnessMap.channel),anisotropyMapUv:F&&p(v.anisotropyMap.channel),clearcoatMapUv:G&&p(v.clearcoatMap.channel),clearcoatNormalMapUv:te&&p(v.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:oe&&p(v.clearcoatRoughnessMap.channel),iridescenceMapUv:V&&p(v.iridescenceMap.channel),iridescenceThicknessMapUv:K&&p(v.iridescenceThicknessMap.channel),sheenColorMapUv:ie&&p(v.sheenColorMap.channel),sheenRoughnessMapUv:de&&p(v.sheenRoughnessMap.channel),specularMapUv:pe&&p(v.specularMap.channel),specularColorMapUv:ge&&p(v.specularColorMap.channel),specularIntensityMapUv:Me&&p(v.specularIntensityMap.channel),transmissionMapUv:He&&p(v.transmissionMap.channel),thicknessMapUv:qe&&p(v.thicknessMap.channel),alphaMapUv:xe&&p(v.alphaMap.channel),vertexTangents:!!U.attributes.tangent&&(ot||R),vertexNormals:!!U.attributes.normal,vertexColors:v.vertexColors,vertexAlphas:v.vertexColors===!0&&!!U.attributes.color&&U.attributes.color.itemSize===4,pointsUvs:C.isPoints===!0&&!!U.attributes.uv&&(Ze||xe),fog:!!N,useFog:v.fog===!0,fogExp2:!!N&&N.isFogExp2,flatShading:v.wireframe===!1&&(v.flatShading===!0||U.attributes.normal===void 0&&ot===!1&&(v.isMeshLambertMaterial||v.isMeshPhongMaterial||v.isMeshStandardMaterial||v.isMeshPhysicalMaterial)),sizeAttenuation:v.sizeAttenuation===!0,logarithmicDepthBuffer:f,reversedDepthBuffer:ye,skinning:C.isSkinnedMesh===!0,hasPositionAttribute:U.attributes.position!==void 0,morphTargets:U.morphAttributes.position!==void 0,morphNormals:U.morphAttributes.normal!==void 0,morphColors:U.morphAttributes.color!==void 0,morphTargetsCount:ee,morphTextureStride:ce,numDirLights:w.directional.length,numPointLights:w.point.length,numSpotLights:w.spot.length,numSpotLightMaps:w.spotLightMap.length,numRectAreaLights:w.rectArea.length,numHemiLights:w.hemi.length,numDirLightShadows:w.directionalShadowMap.length,numPointLightShadows:w.pointShadowMap.length,numSpotLightShadows:w.spotShadowMap.length,numSpotLightShadowsWithMaps:w.numSpotLightShadowsWithMaps,numLightProbes:w.numLightProbes,numLightProbeGrids:O.length,numClippingPlanes:r.numPlanes,numClipIntersection:r.numIntersection,dithering:v.dithering,shadowMapEnabled:n.shadowMap.enabled&&I.length>0,shadowMapType:n.shadowMap.type,toneMapping:ue,decodeVideoTexture:Ze&&v.map.isVideoTexture===!0&&nt.getTransfer(v.map.colorSpace)===ft,decodeVideoTextureEmissive:vt&&v.emissiveMap.isVideoTexture===!0&&nt.getTransfer(v.emissiveMap.colorSpace)===ft,premultipliedAlpha:v.premultipliedAlpha,doubleSided:v.side===zt,flipSided:v.side===un,useDepthPacking:v.depthPacking>=0,depthPacking:v.depthPacking||0,index0AttributeName:v.index0AttributeName,extensionClipCullDistance:Ce&&v.extensions.clipCullDistance===!0&&t.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(Ce&&v.extensions.multiDraw===!0||_e)&&t.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:t.has("KHR_parallel_shader_compile"),customProgramCacheKey:v.customProgramCacheKey()};return ke.vertexUv1s=l.has(1),ke.vertexUv2s=l.has(2),ke.vertexUv3s=l.has(3),l.clear(),ke}function m(v){const w=[];if(v.shaderID?w.push(v.shaderID):(w.push(v.customVertexShaderID),w.push(v.customFragmentShaderID)),v.defines!==void 0)for(const I in v.defines)w.push(I),w.push(v.defines[I]);return v.isRawShaderMaterial===!1&&(g(w,v),M(w,v),w.push(n.outputColorSpace)),w.push(v.customProgramCacheKey),w.join()}function g(v,w){v.push(w.precision),v.push(w.outputColorSpace),v.push(w.envMapMode),v.push(w.envMapCubeUVHeight),v.push(w.mapUv),v.push(w.alphaMapUv),v.push(w.lightMapUv),v.push(w.aoMapUv),v.push(w.bumpMapUv),v.push(w.normalMapUv),v.push(w.displacementMapUv),v.push(w.emissiveMapUv),v.push(w.metalnessMapUv),v.push(w.roughnessMapUv),v.push(w.anisotropyMapUv),v.push(w.clearcoatMapUv),v.push(w.clearcoatNormalMapUv),v.push(w.clearcoatRoughnessMapUv),v.push(w.iridescenceMapUv),v.push(w.iridescenceThicknessMapUv),v.push(w.sheenColorMapUv),v.push(w.sheenRoughnessMapUv),v.push(w.specularMapUv),v.push(w.specularColorMapUv),v.push(w.specularIntensityMapUv),v.push(w.transmissionMapUv),v.push(w.thicknessMapUv),v.push(w.combine),v.push(w.fogExp2),v.push(w.sizeAttenuation),v.push(w.morphTargetsCount),v.push(w.morphAttributeCount),v.push(w.numDirLights),v.push(w.numPointLights),v.push(w.numSpotLights),v.push(w.numSpotLightMaps),v.push(w.numHemiLights),v.push(w.numRectAreaLights),v.push(w.numDirLightShadows),v.push(w.numPointLightShadows),v.push(w.numSpotLightShadows),v.push(w.numSpotLightShadowsWithMaps),v.push(w.numLightProbes),v.push(w.shadowMapType),v.push(w.toneMapping),v.push(w.numClippingPlanes),v.push(w.numClipIntersection),v.push(w.depthPacking)}function M(v,w){a.disableAll(),w.instancing&&a.enable(0),w.instancingColor&&a.enable(1),w.instancingMorph&&a.enable(2),w.matcap&&a.enable(3),w.envMap&&a.enable(4),w.normalMapObjectSpace&&a.enable(5),w.normalMapTangentSpace&&a.enable(6),w.clearcoat&&a.enable(7),w.iridescence&&a.enable(8),w.alphaTest&&a.enable(9),w.vertexColors&&a.enable(10),w.vertexAlphas&&a.enable(11),w.vertexUv1s&&a.enable(12),w.vertexUv2s&&a.enable(13),w.vertexUv3s&&a.enable(14),w.vertexTangents&&a.enable(15),w.anisotropy&&a.enable(16),w.alphaHash&&a.enable(17),w.batching&&a.enable(18),w.dispersion&&a.enable(19),w.batchingColor&&a.enable(20),w.gradientMap&&a.enable(21),w.packedNormalMap&&a.enable(22),w.vertexNormals&&a.enable(23),v.push(a.mask),a.disableAll(),w.fog&&a.enable(0),w.useFog&&a.enable(1),w.flatShading&&a.enable(2),w.logarithmicDepthBuffer&&a.enable(3),w.reversedDepthBuffer&&a.enable(4),w.skinning&&a.enable(5),w.morphTargets&&a.enable(6),w.morphNormals&&a.enable(7),w.morphColors&&a.enable(8),w.premultipliedAlpha&&a.enable(9),w.shadowMapEnabled&&a.enable(10),w.doubleSided&&a.enable(11),w.flipSided&&a.enable(12),w.useDepthPacking&&a.enable(13),w.dithering&&a.enable(14),w.transmission&&a.enable(15),w.sheen&&a.enable(16),w.opaque&&a.enable(17),w.pointsUvs&&a.enable(18),w.decodeVideoTexture&&a.enable(19),w.decodeVideoTextureEmissive&&a.enable(20),w.alphaToCoverage&&a.enable(21),w.numLightProbeGrids>0&&a.enable(22),w.hasPositionAttribute&&a.enable(23),v.push(a.mask)}function E(v){const w=d[v.type];let I;if(w){const L=Yn[w];I=Fg.clone(L.uniforms)}else I=v.uniforms;return I}function _(v,w){let I=u.get(w);return I!==void 0?++I.usedTimes:(I=new c_(n,w,v,s),c.push(I),u.set(w,I)),I}function T(v){if(--v.usedTimes===0){const w=c.indexOf(v);c[w]=c[c.length-1],c.pop(),u.delete(v.cacheKey),v.destroy()}}function b(v){o.remove(v)}function S(){o.dispose()}return{getParameters:x,getProgramCacheKey:m,getUniforms:E,acquireProgram:_,releaseProgram:T,releaseShaderCache:b,programs:c,dispose:S}}function m_(){let n=new WeakMap;function e(a){return n.has(a)}function t(a){let o=n.get(a);return o===void 0&&(o={},n.set(a,o)),o}function i(a){n.delete(a)}function s(a,o,l){n.get(a)[o]=l}function r(){n=new WeakMap}return{has:e,get:t,remove:i,update:s,dispose:r}}function g_(n,e){return n.groupOrder!==e.groupOrder?n.groupOrder-e.groupOrder:n.renderOrder!==e.renderOrder?n.renderOrder-e.renderOrder:n.material.id!==e.material.id?n.material.id-e.material.id:n.materialVariant!==e.materialVariant?n.materialVariant-e.materialVariant:n.z!==e.z?n.z-e.z:n.id-e.id}function yh(n,e){return n.groupOrder!==e.groupOrder?n.groupOrder-e.groupOrder:n.renderOrder!==e.renderOrder?n.renderOrder-e.renderOrder:n.z!==e.z?e.z-n.z:n.id-e.id}function _h(){const n=[];let e=0;const t=[],i=[],s=[];function r(){e=0,t.length=0,i.length=0,s.length=0}function a(h){let d=0;return h.isInstancedMesh&&(d+=2),h.isSkinnedMesh&&(d+=1),d}function o(h,d,p,x,m,g){let M=n[e];return M===void 0?(M={id:h.id,object:h,geometry:d,material:p,materialVariant:a(h),groupOrder:x,renderOrder:h.renderOrder,z:m,group:g},n[e]=M):(M.id=h.id,M.object=h,M.geometry=d,M.material=p,M.materialVariant=a(h),M.groupOrder=x,M.renderOrder=h.renderOrder,M.z=m,M.group=g),e++,M}function l(h,d,p,x,m,g){const M=o(h,d,p,x,m,g);p.transmission>0?i.push(M):p.transparent===!0?s.push(M):t.push(M)}function c(h,d,p,x,m,g){const M=o(h,d,p,x,m,g);p.transmission>0?i.unshift(M):p.transparent===!0?s.unshift(M):t.unshift(M)}function u(h,d,p){t.length>1&&t.sort(h||g_),i.length>1&&i.sort(d||yh),s.length>1&&s.sort(d||yh),p&&(t.reverse(),i.reverse(),s.reverse())}function f(){for(let h=e,d=n.length;h<d;h++){const p=n[h];if(p.id===null)break;p.id=null,p.object=null,p.geometry=null,p.material=null,p.group=null}}return{opaque:t,transmissive:i,transparent:s,init:r,push:l,unshift:c,finish:f,sort:u}}function x_(){let n=new WeakMap;function e(i,s){const r=n.get(i);let a;return r===void 0?(a=new _h,n.set(i,[a])):s>=r.length?(a=new _h,r.push(a)):a=r[s],a}function t(){n=new WeakMap}return{get:e,dispose:t}}function v_(){const n={};return{get:function(e){if(n[e.id]!==void 0)return n[e.id];let t;switch(e.type){case"DirectionalLight":t={direction:new B,color:new et};break;case"SpotLight":t={position:new B,direction:new B,color:new et,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":t={position:new B,color:new et,distance:0,decay:0};break;case"HemisphereLight":t={direction:new B,skyColor:new et,groundColor:new et};break;case"RectAreaLight":t={color:new et,position:new B,halfWidth:new B,halfHeight:new B};break}return n[e.id]=t,t}}}function y_(){const n={};return{get:function(e){if(n[e.id]!==void 0)return n[e.id];let t;switch(e.type){case"DirectionalLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Ee};break;case"SpotLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Ee};break;case"PointLight":t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Ee,shadowCameraNear:1,shadowCameraFar:1e3};break}return n[e.id]=t,t}}}let __=0;function b_(n,e){return(e.castShadow?2:0)-(n.castShadow?2:0)+(e.map?1:0)-(n.map?1:0)}function S_(n){const e=new v_,t=y_(),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let c=0;c<9;c++)i.probe.push(new B);const s=new B,r=new Tt,a=new Tt;function o(c){let u=0,f=0,h=0;for(let w=0;w<9;w++)i.probe[w].set(0,0,0);let d=0,p=0,x=0,m=0,g=0,M=0,E=0,_=0,T=0,b=0,S=0;c.sort(b_);for(let w=0,I=c.length;w<I;w++){const L=c[w],C=L.color,O=L.intensity,N=L.distance;let U=null;if(L.shadow&&L.shadow.map&&(L.shadow.map.texture.format===ts?U=L.shadow.map.texture:U=L.shadow.map.depthTexture||L.shadow.map.texture),L.isAmbientLight)u+=C.r*O,f+=C.g*O,h+=C.b*O;else if(L.isLightProbe){for(let Z=0;Z<9;Z++)i.probe[Z].addScaledVector(L.sh.coefficients[Z],O);S++}else if(L.isDirectionalLight){const Z=e.get(L);if(Z.color.copy(L.color).multiplyScalar(L.intensity),L.castShadow){const k=L.shadow,$=t.get(L);$.shadowIntensity=k.intensity,$.shadowBias=k.bias,$.shadowNormalBias=k.normalBias,$.shadowRadius=k.radius,$.shadowMapSize=k.mapSize,i.directionalShadow[d]=$,i.directionalShadowMap[d]=U,i.directionalShadowMatrix[d]=L.shadow.matrix,M++}i.directional[d]=Z,d++}else if(L.isSpotLight){const Z=e.get(L);Z.position.setFromMatrixPosition(L.matrixWorld),Z.color.copy(C).multiplyScalar(O),Z.distance=N,Z.coneCos=Math.cos(L.angle),Z.penumbraCos=Math.cos(L.angle*(1-L.penumbra)),Z.decay=L.decay,i.spot[x]=Z;const k=L.shadow;if(L.map&&(i.spotLightMap[T]=L.map,T++,k.updateMatrices(L),L.castShadow&&b++),i.spotLightMatrix[x]=k.matrix,L.castShadow){const $=t.get(L);$.shadowIntensity=k.intensity,$.shadowBias=k.bias,$.shadowNormalBias=k.normalBias,$.shadowRadius=k.radius,$.shadowMapSize=k.mapSize,i.spotShadow[x]=$,i.spotShadowMap[x]=U,_++}x++}else if(L.isRectAreaLight){const Z=e.get(L);Z.color.copy(C).multiplyScalar(O),Z.halfWidth.set(L.width*.5,0,0),Z.halfHeight.set(0,L.height*.5,0),i.rectArea[m]=Z,m++}else if(L.isPointLight){const Z=e.get(L);if(Z.color.copy(L.color).multiplyScalar(L.intensity),Z.distance=L.distance,Z.decay=L.decay,L.castShadow){const k=L.shadow,$=t.get(L);$.shadowIntensity=k.intensity,$.shadowBias=k.bias,$.shadowNormalBias=k.normalBias,$.shadowRadius=k.radius,$.shadowMapSize=k.mapSize,$.shadowCameraNear=k.camera.near,$.shadowCameraFar=k.camera.far,i.pointShadow[p]=$,i.pointShadowMap[p]=U,i.pointShadowMatrix[p]=L.shadow.matrix,E++}i.point[p]=Z,p++}else if(L.isHemisphereLight){const Z=e.get(L);Z.skyColor.copy(L.color).multiplyScalar(O),Z.groundColor.copy(L.groundColor).multiplyScalar(O),i.hemi[g]=Z,g++}}m>0&&(n.has("OES_texture_float_linear")===!0?(i.rectAreaLTC1=we.LTC_FLOAT_1,i.rectAreaLTC2=we.LTC_FLOAT_2):(i.rectAreaLTC1=we.LTC_HALF_1,i.rectAreaLTC2=we.LTC_HALF_2)),i.ambient[0]=u,i.ambient[1]=f,i.ambient[2]=h;const v=i.hash;(v.directionalLength!==d||v.pointLength!==p||v.spotLength!==x||v.rectAreaLength!==m||v.hemiLength!==g||v.numDirectionalShadows!==M||v.numPointShadows!==E||v.numSpotShadows!==_||v.numSpotMaps!==T||v.numLightProbes!==S)&&(i.directional.length=d,i.spot.length=x,i.rectArea.length=m,i.point.length=p,i.hemi.length=g,i.directionalShadow.length=M,i.directionalShadowMap.length=M,i.pointShadow.length=E,i.pointShadowMap.length=E,i.spotShadow.length=_,i.spotShadowMap.length=_,i.directionalShadowMatrix.length=M,i.pointShadowMatrix.length=E,i.spotLightMatrix.length=_+T-b,i.spotLightMap.length=T,i.numSpotLightShadowsWithMaps=b,i.numLightProbes=S,v.directionalLength=d,v.pointLength=p,v.spotLength=x,v.rectAreaLength=m,v.hemiLength=g,v.numDirectionalShadows=M,v.numPointShadows=E,v.numSpotShadows=_,v.numSpotMaps=T,v.numLightProbes=S,i.version=__++)}function l(c,u){let f=0,h=0,d=0,p=0,x=0;const m=u.matrixWorldInverse;for(let g=0,M=c.length;g<M;g++){const E=c[g];if(E.isDirectionalLight){const _=i.directional[f];_.direction.setFromMatrixPosition(E.matrixWorld),s.setFromMatrixPosition(E.target.matrixWorld),_.direction.sub(s),_.direction.transformDirection(m),f++}else if(E.isSpotLight){const _=i.spot[d];_.position.setFromMatrixPosition(E.matrixWorld),_.position.applyMatrix4(m),_.direction.setFromMatrixPosition(E.matrixWorld),s.setFromMatrixPosition(E.target.matrixWorld),_.direction.sub(s),_.direction.transformDirection(m),d++}else if(E.isRectAreaLight){const _=i.rectArea[p];_.position.setFromMatrixPosition(E.matrixWorld),_.position.applyMatrix4(m),a.identity(),r.copy(E.matrixWorld),r.premultiply(m),a.extractRotation(r),_.halfWidth.set(E.width*.5,0,0),_.halfHeight.set(0,E.height*.5,0),_.halfWidth.applyMatrix4(a),_.halfHeight.applyMatrix4(a),p++}else if(E.isPointLight){const _=i.point[h];_.position.setFromMatrixPosition(E.matrixWorld),_.position.applyMatrix4(m),h++}else if(E.isHemisphereLight){const _=i.hemi[x];_.direction.setFromMatrixPosition(E.matrixWorld),_.direction.transformDirection(m),x++}}}return{setup:o,setupView:l,state:i}}function bh(n){const e=new S_(n),t=[],i=[],s=[];function r(h){f.camera=h,t.length=0,i.length=0,s.length=0}function a(h){t.push(h)}function o(h){i.push(h)}function l(h){s.push(h)}function c(){e.setup(t)}function u(h){e.setupView(t,h)}const f={lightsArray:t,shadowsArray:i,lightProbeGridArray:s,camera:null,lights:e,transmissionRenderTarget:{},textureUnits:0};return{init:r,state:f,setupLights:c,setupLightsView:u,pushLight:a,pushShadow:o,pushLightProbeGrid:l}}function M_(n){let e=new WeakMap;function t(s,r=0){const a=e.get(s);let o;return a===void 0?(o=new bh(n),e.set(s,[o])):r>=a.length?(o=new bh(n),a.push(o)):o=a[r],o}function i(){e=new WeakMap}return{get:t,dispose:i}}const E_=`void main() {
|
|
gl_Position = vec4( position, 1.0 );
|
|
}`,T_=`uniform sampler2D shadow_pass;
|
|
uniform vec2 resolution;
|
|
uniform float radius;
|
|
void main() {
|
|
const float samples = float( VSM_SAMPLES );
|
|
float mean = 0.0;
|
|
float squared_mean = 0.0;
|
|
float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );
|
|
float uvStart = samples <= 1.0 ? 0.0 : - 1.0;
|
|
for ( float i = 0.0; i < samples; i ++ ) {
|
|
float uvOffset = uvStart + i * uvStride;
|
|
#ifdef HORIZONTAL_PASS
|
|
vec2 distribution = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg;
|
|
mean += distribution.x;
|
|
squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
|
|
#else
|
|
float depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;
|
|
mean += depth;
|
|
squared_mean += depth * depth;
|
|
#endif
|
|
}
|
|
mean = mean / samples;
|
|
squared_mean = squared_mean / samples;
|
|
float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
|
|
gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
|
|
}`,A_=[new B(1,0,0),new B(-1,0,0),new B(0,1,0),new B(0,-1,0),new B(0,0,1),new B(0,0,-1)],w_=[new B(0,-1,0),new B(0,-1,0),new B(0,0,1),new B(0,0,-1),new B(0,-1,0),new B(0,-1,0)],Sh=new Tt,fr=new B,rl=new B;function C_(n,e,t){let i=new nd;const s=new Ee,r=new Ee,a=new Ct,o=new Hg,l=new zg,c={},u=t.maxTextureSize,f={[Ni]:un,[un]:Ni,[zt]:zt},h=new In({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new Ee},radius:{value:4}},vertexShader:E_,fragmentShader:T_}),d=h.clone();d.defines.HORIZONTAL_PASS=1;const p=new wt;p.setAttribute("position",new Dn(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const x=new Gt(p,h),m=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=Ia;let g=this.type;this.render=function(b,S,v){if(m.enabled===!1||m.autoUpdate===!1&&m.needsUpdate===!1||b.length===0)return;this.type===Jp&&(We("WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead."),this.type=Ia);const w=n.getRenderTarget(),I=n.getActiveCubeFace(),L=n.getActiveMipmapLevel(),C=n.state;C.setBlending(hi),C.buffers.depth.getReversed()===!0?C.buffers.color.setClear(0,0,0,0):C.buffers.color.setClear(1,1,1,1),C.buffers.depth.setTest(!0),C.setScissorTest(!1);const O=g!==this.type;O&&S.traverse(function(N){N.material&&(Array.isArray(N.material)?N.material.forEach(U=>U.needsUpdate=!0):N.material.needsUpdate=!0)});for(let N=0,U=b.length;N<U;N++){const Z=b[N],k=Z.shadow;if(k===void 0){We("WebGLShadowMap:",Z,"has no shadow.");continue}if(k.autoUpdate===!1&&k.needsUpdate===!1)continue;s.copy(k.mapSize);const $=k.getFrameExtents();s.multiply($),r.copy(k.mapSize),(s.x>u||s.y>u)&&(s.x>u&&(r.x=Math.floor(u/$.x),s.x=r.x*$.x,k.mapSize.x=r.x),s.y>u&&(r.y=Math.floor(u/$.y),s.y=r.y*$.y,k.mapSize.y=r.y));const D=n.state.buffers.depth.getReversed();if(k.camera._reversedDepth=D,k.map===null||O===!0){if(k.map!==null&&(k.map.depthTexture!==null&&(k.map.depthTexture.dispose(),k.map.depthTexture=null),k.map.dispose()),this.type===mr){if(Z.isPointLight){We("WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.");continue}k.map=new Jn(s.x,s.y,{format:ts,type:mi,minFilter:Xt,magFilter:Xt,generateMipmaps:!1}),k.map.texture.name=Z.name+".shadowMap",k.map.depthTexture=new Ws(s.x,s.y,Ln),k.map.depthTexture.name=Z.name+".shadowMapDepth",k.map.depthTexture.format=gi,k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=Ft,k.map.depthTexture.magFilter=Ft}else Z.isPointLight?(k.map=new yd(s.x),k.map.depthTexture=new ng(s.x,Qn)):(k.map=new Jn(s.x,s.y),k.map.depthTexture=new Ws(s.x,s.y,Qn)),k.map.depthTexture.name=Z.name+".shadowMap",k.map.depthTexture.format=gi,this.type===Ia?(k.map.depthTexture.compareFunction=D?Fc:Oc,k.map.depthTexture.minFilter=Xt,k.map.depthTexture.magFilter=Xt):(k.map.depthTexture.compareFunction=null,k.map.depthTexture.minFilter=Ft,k.map.depthTexture.magFilter=Ft);k.camera.updateProjectionMatrix()}const ae=k.map.isWebGLCubeRenderTarget?6:1;for(let re=0;re<ae;re++){if(k.map.isWebGLCubeRenderTarget)n.setRenderTarget(k.map,re),n.clear();else{re===0&&(n.setRenderTarget(k.map),n.clear());const ee=k.getViewport(re);a.set(r.x*ee.x,r.y*ee.y,r.x*ee.z,r.y*ee.w),C.viewport(a)}if(Z.isPointLight){const ee=k.camera,ce=k.matrix,he=Z.distance||ee.far;he!==ee.far&&(ee.far=he,ee.updateProjectionMatrix()),fr.setFromMatrixPosition(Z.matrixWorld),ee.position.copy(fr),rl.copy(ee.position),rl.add(A_[re]),ee.up.copy(w_[re]),ee.lookAt(rl),ee.updateMatrixWorld(),ce.makeTranslation(-fr.x,-fr.y,-fr.z),Sh.multiplyMatrices(ee.projectionMatrix,ee.matrixWorldInverse),k._frustum.setFromProjectionMatrix(Sh,ee.coordinateSystem,ee.reversedDepth)}else k.updateMatrices(Z);i=k.getFrustum(),_(S,v,k.camera,Z,this.type)}k.isPointLightShadow!==!0&&this.type===mr&&M(k,v),k.needsUpdate=!1}g=this.type,m.needsUpdate=!1,n.setRenderTarget(w,I,L)};function M(b,S){const v=e.update(x);h.defines.VSM_SAMPLES!==b.blurSamples&&(h.defines.VSM_SAMPLES=b.blurSamples,d.defines.VSM_SAMPLES=b.blurSamples,h.needsUpdate=!0,d.needsUpdate=!0),b.mapPass===null&&(b.mapPass=new Jn(s.x,s.y,{format:ts,type:mi})),h.uniforms.shadow_pass.value=b.map.depthTexture,h.uniforms.resolution.value=b.mapSize,h.uniforms.radius.value=b.radius,n.setRenderTarget(b.mapPass),n.clear(),n.renderBufferDirect(S,null,v,h,x,null),d.uniforms.shadow_pass.value=b.mapPass.texture,d.uniforms.resolution.value=b.mapSize,d.uniforms.radius.value=b.radius,n.setRenderTarget(b.map),n.clear(),n.renderBufferDirect(S,null,v,d,x,null)}function E(b,S,v,w){let I=null;const L=v.isPointLight===!0?b.customDistanceMaterial:b.customDepthMaterial;if(L!==void 0)I=L;else if(I=v.isPointLight===!0?l:o,n.localClippingEnabled&&S.clipShadows===!0&&Array.isArray(S.clippingPlanes)&&S.clippingPlanes.length!==0||S.displacementMap&&S.displacementScale!==0||S.alphaMap&&S.alphaTest>0||S.map&&S.alphaTest>0||S.alphaToCoverage===!0){const C=I.uuid,O=S.uuid;let N=c[C];N===void 0&&(N={},c[C]=N);let U=N[O];U===void 0&&(U=I.clone(),N[O]=U,S.addEventListener("dispose",T)),I=U}if(I.visible=S.visible,I.wireframe=S.wireframe,w===mr?I.side=S.shadowSide!==null?S.shadowSide:S.side:I.side=S.shadowSide!==null?S.shadowSide:f[S.side],I.alphaMap=S.alphaMap,I.alphaTest=S.alphaToCoverage===!0?.5:S.alphaTest,I.map=S.map,I.clipShadows=S.clipShadows,I.clippingPlanes=S.clippingPlanes,I.clipIntersection=S.clipIntersection,I.displacementMap=S.displacementMap,I.displacementScale=S.displacementScale,I.displacementBias=S.displacementBias,I.wireframeLinewidth=S.wireframeLinewidth,I.linewidth=S.linewidth,v.isPointLight===!0&&I.isMeshDistanceMaterial===!0){const C=n.properties.get(I);C.light=v}return I}function _(b,S,v,w,I){if(b.visible===!1)return;if(b.layers.test(S.layers)&&(b.isMesh||b.isLine||b.isPoints)&&(b.castShadow||b.receiveShadow&&I===mr)&&(!b.frustumCulled||i.intersectsObject(b))){b.modelViewMatrix.multiplyMatrices(v.matrixWorldInverse,b.matrixWorld);const O=e.update(b),N=b.material;if(Array.isArray(N)){const U=O.groups;for(let Z=0,k=U.length;Z<k;Z++){const $=U[Z],D=N[$.materialIndex];if(D&&D.visible){const ae=E(b,D,w,I);b.onBeforeShadow(n,b,S,v,O,ae,$),n.renderBufferDirect(v,null,O,ae,b,$),b.onAfterShadow(n,b,S,v,O,ae,$)}}}else if(N.visible){const U=E(b,N,w,I);b.onBeforeShadow(n,b,S,v,O,U,null),n.renderBufferDirect(v,null,O,U,b,null),b.onAfterShadow(n,b,S,v,O,U,null)}}const C=b.children;for(let O=0,N=C.length;O<N;O++)_(C[O],S,v,w,I)}function T(b){b.target.removeEventListener("dispose",T);for(const v in c){const w=c[v],I=b.target.uuid;I in w&&(w[I].dispose(),delete w[I])}}}function R_(n,e){function t(){let z=!1;const xe=new Ct;let le=null;const be=new Ct(0,0,0,0);return{setMask:function(Ce){le!==Ce&&!z&&(n.colorMask(Ce,Ce,Ce,Ce),le=Ce)},setLocked:function(Ce){z=Ce},setClear:function(Ce,ue,ke,Le,yt){yt===!0&&(Ce*=Le,ue*=Le,ke*=Le),xe.set(Ce,ue,ke,Le),be.equals(xe)===!1&&(n.clearColor(Ce,ue,ke,Le),be.copy(xe))},reset:function(){z=!1,le=null,be.set(-1,0,0,0)}}}function i(){let z=!1,xe=!1,le=null,be=null,Ce=null;return{setReversed:function(ue){if(xe!==ue){const ke=e.get("EXT_clip_control");ue?ke.clipControlEXT(ke.LOWER_LEFT_EXT,ke.ZERO_TO_ONE_EXT):ke.clipControlEXT(ke.LOWER_LEFT_EXT,ke.NEGATIVE_ONE_TO_ONE_EXT),xe=ue;const Le=Ce;Ce=null,this.setClear(Le)}},getReversed:function(){return xe},setTest:function(ue){ue?Q(n.DEPTH_TEST):ye(n.DEPTH_TEST)},setMask:function(ue){le!==ue&&!z&&(n.depthMask(ue),le=ue)},setFunc:function(ue){if(xe&&(ue=Pm[ue]),be!==ue){switch(ue){case El:n.depthFunc(n.NEVER);break;case Tl:n.depthFunc(n.ALWAYS);break;case Al:n.depthFunc(n.LESS);break;case Gs:n.depthFunc(n.LEQUAL);break;case wl:n.depthFunc(n.EQUAL);break;case Cl:n.depthFunc(n.GEQUAL);break;case Rl:n.depthFunc(n.GREATER);break;case Pl:n.depthFunc(n.NOTEQUAL);break;default:n.depthFunc(n.LEQUAL)}be=ue}},setLocked:function(ue){z=ue},setClear:function(ue){Ce!==ue&&(Ce=ue,xe&&(ue=1-ue),n.clearDepth(ue))},reset:function(){z=!1,le=null,be=null,Ce=null,xe=!1}}}function s(){let z=!1,xe=null,le=null,be=null,Ce=null,ue=null,ke=null,Le=null,yt=null;return{setTest:function(_t){z||(_t?Q(n.STENCIL_TEST):ye(n.STENCIL_TEST))},setMask:function(_t){xe!==_t&&!z&&(n.stencilMask(_t),xe=_t)},setFunc:function(_t,hn,Ut){(le!==_t||be!==hn||Ce!==Ut)&&(n.stencilFunc(_t,hn,Ut),le=_t,be=hn,Ce=Ut)},setOp:function(_t,hn,Ut){(ue!==_t||ke!==hn||Le!==Ut)&&(n.stencilOp(_t,hn,Ut),ue=_t,ke=hn,Le=Ut)},setLocked:function(_t){z=_t},setClear:function(_t){yt!==_t&&(n.clearStencil(_t),yt=_t)},reset:function(){z=!1,xe=null,le=null,be=null,Ce=null,ue=null,ke=null,Le=null,yt=null}}}const r=new t,a=new i,o=new s,l=new WeakMap,c=new WeakMap;let u={},f={},h={},d=new WeakMap,p=[],x=null,m=!1,g=null,M=null,E=null,_=null,T=null,b=null,S=null,v=new et(0,0,0),w=0,I=!1,L=null,C=null,O=null,N=null,U=null;const Z=n.getParameter(n.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let k=!1,$=0;const D=n.getParameter(n.VERSION);D.indexOf("WebGL")!==-1?($=parseFloat(/^WebGL (\d)/.exec(D)[1]),k=$>=1):D.indexOf("OpenGL ES")!==-1&&($=parseFloat(/^OpenGL ES (\d)/.exec(D)[1]),k=$>=2);let ae=null,re={};const ee=n.getParameter(n.SCISSOR_BOX),ce=n.getParameter(n.VIEWPORT),he=new Ct().fromArray(ee),fe=new Ct().fromArray(ce);function X(z,xe,le,be){const Ce=new Uint8Array(4),ue=n.createTexture();n.bindTexture(z,ue),n.texParameteri(z,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(z,n.TEXTURE_MAG_FILTER,n.NEAREST);for(let ke=0;ke<le;ke++)z===n.TEXTURE_3D||z===n.TEXTURE_2D_ARRAY?n.texImage3D(xe,0,n.RGBA,1,1,be,0,n.RGBA,n.UNSIGNED_BYTE,Ce):n.texImage2D(xe+ke,0,n.RGBA,1,1,0,n.RGBA,n.UNSIGNED_BYTE,Ce);return ue}const se={};se[n.TEXTURE_2D]=X(n.TEXTURE_2D,n.TEXTURE_2D,1),se[n.TEXTURE_CUBE_MAP]=X(n.TEXTURE_CUBE_MAP,n.TEXTURE_CUBE_MAP_POSITIVE_X,6),se[n.TEXTURE_2D_ARRAY]=X(n.TEXTURE_2D_ARRAY,n.TEXTURE_2D_ARRAY,1,1),se[n.TEXTURE_3D]=X(n.TEXTURE_3D,n.TEXTURE_3D,1,1),r.setClear(0,0,0,1),a.setClear(1),o.setClear(0),Q(n.DEPTH_TEST),a.setFunc(Gs),at(!1),ot(fu),Q(n.CULL_FACE),Fe(hi);function Q(z){u[z]!==!0&&(n.enable(z),u[z]=!0)}function ye(z){u[z]!==!1&&(n.disable(z),u[z]=!1)}function ve(z,xe){return h[z]!==xe?(n.bindFramebuffer(z,xe),h[z]=xe,z===n.DRAW_FRAMEBUFFER&&(h[n.FRAMEBUFFER]=xe),z===n.FRAMEBUFFER&&(h[n.DRAW_FRAMEBUFFER]=xe),!0):!1}function _e(z,xe){let le=p,be=!1;if(z){le=d.get(xe),le===void 0&&(le=[],d.set(xe,le));const Ce=z.textures;if(le.length!==Ce.length||le[0]!==n.COLOR_ATTACHMENT0){for(let ue=0,ke=Ce.length;ue<ke;ue++)le[ue]=n.COLOR_ATTACHMENT0+ue;le.length=Ce.length,be=!0}}else le[0]!==n.BACK&&(le[0]=n.BACK,be=!0);be&&n.drawBuffers(le)}function Ze(z){return x!==z?(n.useProgram(z),x=z,!0):!1}const Ye={[$i]:n.FUNC_ADD,[Qp]:n.FUNC_SUBTRACT,[em]:n.FUNC_REVERSE_SUBTRACT};Ye[tm]=n.MIN,Ye[nm]=n.MAX;const Oe={[im]:n.ZERO,[sm]:n.ONE,[rm]:n.SRC_COLOR,[Sl]:n.SRC_ALPHA,[hm]:n.SRC_ALPHA_SATURATE,[cm]:n.DST_COLOR,[om]:n.DST_ALPHA,[am]:n.ONE_MINUS_SRC_COLOR,[Ml]:n.ONE_MINUS_SRC_ALPHA,[um]:n.ONE_MINUS_DST_COLOR,[lm]:n.ONE_MINUS_DST_ALPHA,[fm]:n.CONSTANT_COLOR,[dm]:n.ONE_MINUS_CONSTANT_COLOR,[pm]:n.CONSTANT_ALPHA,[mm]:n.ONE_MINUS_CONSTANT_ALPHA};function Fe(z,xe,le,be,Ce,ue,ke,Le,yt,_t){if(z===hi){m===!0&&(ye(n.BLEND),m=!1);return}if(m===!1&&(Q(n.BLEND),m=!0),z!==jp){if(z!==g||_t!==I){if((M!==$i||T!==$i)&&(n.blendEquation(n.FUNC_ADD),M=$i,T=$i),_t)switch(z){case ks:n.blendFuncSeparate(n.ONE,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break;case du:n.blendFunc(n.ONE,n.ONE);break;case pu:n.blendFuncSeparate(n.ZERO,n.ONE_MINUS_SRC_COLOR,n.ZERO,n.ONE);break;case mu:n.blendFuncSeparate(n.DST_COLOR,n.ONE_MINUS_SRC_ALPHA,n.ZERO,n.ONE);break;default:st("WebGLState: Invalid blending: ",z);break}else switch(z){case ks:n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA);break;case du:n.blendFuncSeparate(n.SRC_ALPHA,n.ONE,n.ONE,n.ONE);break;case pu:st("WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true");break;case mu:st("WebGLState: MultiplyBlending requires material.premultipliedAlpha = true");break;default:st("WebGLState: Invalid blending: ",z);break}E=null,_=null,b=null,S=null,v.set(0,0,0),w=0,g=z,I=_t}return}Ce=Ce||xe,ue=ue||le,ke=ke||be,(xe!==M||Ce!==T)&&(n.blendEquationSeparate(Ye[xe],Ye[Ce]),M=xe,T=Ce),(le!==E||be!==_||ue!==b||ke!==S)&&(n.blendFuncSeparate(Oe[le],Oe[be],Oe[ue],Oe[ke]),E=le,_=be,b=ue,S=ke),(Le.equals(v)===!1||yt!==w)&&(n.blendColor(Le.r,Le.g,Le.b,yt),v.copy(Le),w=yt),g=z,I=!1}function Ve(z,xe){z.side===zt?ye(n.CULL_FACE):Q(n.CULL_FACE);let le=z.side===un;xe&&(le=!le),at(le),z.blending===ks&&z.transparent===!1?Fe(hi):Fe(z.blending,z.blendEquation,z.blendSrc,z.blendDst,z.blendEquationAlpha,z.blendSrcAlpha,z.blendDstAlpha,z.blendColor,z.blendAlpha,z.premultipliedAlpha),a.setFunc(z.depthFunc),a.setTest(z.depthTest),a.setMask(z.depthWrite),r.setMask(z.colorWrite);const be=z.stencilWrite;o.setTest(be),be&&(o.setMask(z.stencilWriteMask),o.setFunc(z.stencilFunc,z.stencilRef,z.stencilFuncMask),o.setOp(z.stencilFail,z.stencilZFail,z.stencilZPass)),vt(z.polygonOffset,z.polygonOffsetFactor,z.polygonOffsetUnits),z.alphaToCoverage===!0?Q(n.SAMPLE_ALPHA_TO_COVERAGE):ye(n.SAMPLE_ALPHA_TO_COVERAGE)}function at(z){L!==z&&(z?n.frontFace(n.CW):n.frontFace(n.CCW),L=z)}function ot(z){z!==Zp?(Q(n.CULL_FACE),z!==C&&(z===fu?n.cullFace(n.BACK):z===Kp?n.cullFace(n.FRONT):n.cullFace(n.FRONT_AND_BACK))):ye(n.CULL_FACE),C=z}function pt(z){z!==O&&(k&&n.lineWidth(z),O=z)}function vt(z,xe,le){z?(Q(n.POLYGON_OFFSET_FILL),(N!==xe||U!==le)&&(N=xe,U=le,a.getReversed()&&(xe=-xe),n.polygonOffset(xe,le))):ye(n.POLYGON_OFFSET_FILL)}function ct(z){z?Q(n.SCISSOR_TEST):ye(n.SCISSOR_TEST)}function ut(z){z===void 0&&(z=n.TEXTURE0+Z-1),ae!==z&&(n.activeTexture(z),ae=z)}function R(z,xe,le){le===void 0&&(ae===null?le=n.TEXTURE0+Z-1:le=ae);let be=re[le];be===void 0&&(be={type:void 0,texture:void 0},re[le]=be),(be.type!==z||be.texture!==xe)&&(ae!==le&&(n.activeTexture(le),ae=le),n.bindTexture(z,xe||se[z]),be.type=z,be.texture=xe)}function Ae(){const z=re[ae];z!==void 0&&z.type!==void 0&&(n.bindTexture(z.type,null),z.type=void 0,z.texture=void 0)}function W(){try{n.compressedTexImage2D(...arguments)}catch(z){st("WebGLState:",z)}}function P(){try{n.compressedTexImage3D(...arguments)}catch(z){st("WebGLState:",z)}}function y(){try{n.texSubImage2D(...arguments)}catch(z){st("WebGLState:",z)}}function H(){try{n.texSubImage3D(...arguments)}catch(z){st("WebGLState:",z)}}function F(){try{n.compressedTexSubImage2D(...arguments)}catch(z){st("WebGLState:",z)}}function G(){try{n.compressedTexSubImage3D(...arguments)}catch(z){st("WebGLState:",z)}}function te(){try{n.texStorage2D(...arguments)}catch(z){st("WebGLState:",z)}}function oe(){try{n.texStorage3D(...arguments)}catch(z){st("WebGLState:",z)}}function V(){try{n.texImage2D(...arguments)}catch(z){st("WebGLState:",z)}}function K(){try{n.texImage3D(...arguments)}catch(z){st("WebGLState:",z)}}function ie(z){return f[z]!==void 0?f[z]:n.getParameter(z)}function de(z,xe){f[z]!==xe&&(n.pixelStorei(z,xe),f[z]=xe)}function pe(z){he.equals(z)===!1&&(n.scissor(z.x,z.y,z.z,z.w),he.copy(z))}function ge(z){fe.equals(z)===!1&&(n.viewport(z.x,z.y,z.z,z.w),fe.copy(z))}function Me(z,xe){let le=c.get(xe);le===void 0&&(le=new WeakMap,c.set(xe,le));let be=le.get(z);be===void 0&&(be=n.getUniformBlockIndex(xe,z.name),le.set(z,be))}function He(z,xe){const be=c.get(xe).get(z);l.get(xe)!==be&&(n.uniformBlockBinding(xe,be,z.__bindingPointIndex),l.set(xe,be))}function qe(){n.disable(n.BLEND),n.disable(n.CULL_FACE),n.disable(n.DEPTH_TEST),n.disable(n.POLYGON_OFFSET_FILL),n.disable(n.SCISSOR_TEST),n.disable(n.STENCIL_TEST),n.disable(n.SAMPLE_ALPHA_TO_COVERAGE),n.blendEquation(n.FUNC_ADD),n.blendFunc(n.ONE,n.ZERO),n.blendFuncSeparate(n.ONE,n.ZERO,n.ONE,n.ZERO),n.blendColor(0,0,0,0),n.colorMask(!0,!0,!0,!0),n.clearColor(0,0,0,0),n.depthMask(!0),n.depthFunc(n.LESS),a.setReversed(!1),n.clearDepth(1),n.stencilMask(4294967295),n.stencilFunc(n.ALWAYS,0,4294967295),n.stencilOp(n.KEEP,n.KEEP,n.KEEP),n.clearStencil(0),n.cullFace(n.BACK),n.frontFace(n.CCW),n.polygonOffset(0,0),n.activeTexture(n.TEXTURE0),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.bindFramebuffer(n.READ_FRAMEBUFFER,null),n.useProgram(null),n.lineWidth(1),n.scissor(0,0,n.canvas.width,n.canvas.height),n.viewport(0,0,n.canvas.width,n.canvas.height),n.pixelStorei(n.PACK_ALIGNMENT,4),n.pixelStorei(n.UNPACK_ALIGNMENT,4),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,n.BROWSER_DEFAULT_WEBGL),n.pixelStorei(n.PACK_ROW_LENGTH,0),n.pixelStorei(n.PACK_SKIP_PIXELS,0),n.pixelStorei(n.PACK_SKIP_ROWS,0),n.pixelStorei(n.UNPACK_ROW_LENGTH,0),n.pixelStorei(n.UNPACK_IMAGE_HEIGHT,0),n.pixelStorei(n.UNPACK_SKIP_PIXELS,0),n.pixelStorei(n.UNPACK_SKIP_ROWS,0),n.pixelStorei(n.UNPACK_SKIP_IMAGES,0),u={},f={},ae=null,re={},h={},d=new WeakMap,p=[],x=null,m=!1,g=null,M=null,E=null,_=null,T=null,b=null,S=null,v=new et(0,0,0),w=0,I=!1,L=null,C=null,O=null,N=null,U=null,he.set(0,0,n.canvas.width,n.canvas.height),fe.set(0,0,n.canvas.width,n.canvas.height),r.reset(),a.reset(),o.reset()}return{buffers:{color:r,depth:a,stencil:o},enable:Q,disable:ye,bindFramebuffer:ve,drawBuffers:_e,useProgram:Ze,setBlending:Fe,setMaterial:Ve,setFlipSided:at,setCullFace:ot,setLineWidth:pt,setPolygonOffset:vt,setScissorTest:ct,activeTexture:ut,bindTexture:R,unbindTexture:Ae,compressedTexImage2D:W,compressedTexImage3D:P,texImage2D:V,texImage3D:K,pixelStorei:de,getParameter:ie,updateUBOMapping:Me,uniformBlockBinding:He,texStorage2D:te,texStorage3D:oe,texSubImage2D:y,texSubImage3D:H,compressedTexSubImage2D:F,compressedTexSubImage3D:G,scissor:pe,viewport:ge,reset:qe}}function P_(n,e,t,i,s,r,a){const o=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new Ee,u=new WeakMap,f=new Set;let h;const d=new WeakMap;let p=!1;try{p=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function x(P,y){return p?new OffscreenCanvas(P,y):Za("canvas")}function m(P,y,H){let F=1;const G=W(P);if((G.width>H||G.height>H)&&(F=H/Math.max(G.width,G.height)),F<1)if(typeof HTMLImageElement<"u"&&P instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&P instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&P instanceof ImageBitmap||typeof VideoFrame<"u"&&P instanceof VideoFrame){const te=Math.floor(F*G.width),oe=Math.floor(F*G.height);h===void 0&&(h=x(te,oe));const V=y?x(te,oe):h;return V.width=te,V.height=oe,V.getContext("2d").drawImage(P,0,0,te,oe),We("WebGLRenderer: Texture has been resized from ("+G.width+"x"+G.height+") to ("+te+"x"+oe+")."),V}else return"data"in P&&We("WebGLRenderer: Image in DataTexture is too big ("+G.width+"x"+G.height+")."),P;return P}function g(P){return P.generateMipmaps}function M(P){n.generateMipmap(P)}function E(P){return P.isWebGLCubeRenderTarget?n.TEXTURE_CUBE_MAP:P.isWebGL3DRenderTarget?n.TEXTURE_3D:P.isWebGLArrayRenderTarget||P.isCompressedArrayTexture?n.TEXTURE_2D_ARRAY:n.TEXTURE_2D}function _(P,y,H,F,G,te=!1){if(P!==null){if(n[P]!==void 0)return n[P];We("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+P+"'")}let oe;F&&(oe=e.get("EXT_texture_norm16"),oe||We("WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension"));let V=y;if(y===n.RED&&(H===n.FLOAT&&(V=n.R32F),H===n.HALF_FLOAT&&(V=n.R16F),H===n.UNSIGNED_BYTE&&(V=n.R8),H===n.UNSIGNED_SHORT&&oe&&(V=oe.R16_EXT),H===n.SHORT&&oe&&(V=oe.R16_SNORM_EXT)),y===n.RED_INTEGER&&(H===n.UNSIGNED_BYTE&&(V=n.R8UI),H===n.UNSIGNED_SHORT&&(V=n.R16UI),H===n.UNSIGNED_INT&&(V=n.R32UI),H===n.BYTE&&(V=n.R8I),H===n.SHORT&&(V=n.R16I),H===n.INT&&(V=n.R32I)),y===n.RG&&(H===n.FLOAT&&(V=n.RG32F),H===n.HALF_FLOAT&&(V=n.RG16F),H===n.UNSIGNED_BYTE&&(V=n.RG8),H===n.UNSIGNED_SHORT&&oe&&(V=oe.RG16_EXT),H===n.SHORT&&oe&&(V=oe.RG16_SNORM_EXT)),y===n.RG_INTEGER&&(H===n.UNSIGNED_BYTE&&(V=n.RG8UI),H===n.UNSIGNED_SHORT&&(V=n.RG16UI),H===n.UNSIGNED_INT&&(V=n.RG32UI),H===n.BYTE&&(V=n.RG8I),H===n.SHORT&&(V=n.RG16I),H===n.INT&&(V=n.RG32I)),y===n.RGB_INTEGER&&(H===n.UNSIGNED_BYTE&&(V=n.RGB8UI),H===n.UNSIGNED_SHORT&&(V=n.RGB16UI),H===n.UNSIGNED_INT&&(V=n.RGB32UI),H===n.BYTE&&(V=n.RGB8I),H===n.SHORT&&(V=n.RGB16I),H===n.INT&&(V=n.RGB32I)),y===n.RGBA_INTEGER&&(H===n.UNSIGNED_BYTE&&(V=n.RGBA8UI),H===n.UNSIGNED_SHORT&&(V=n.RGBA16UI),H===n.UNSIGNED_INT&&(V=n.RGBA32UI),H===n.BYTE&&(V=n.RGBA8I),H===n.SHORT&&(V=n.RGBA16I),H===n.INT&&(V=n.RGBA32I)),y===n.RGB&&(H===n.UNSIGNED_SHORT&&oe&&(V=oe.RGB16_EXT),H===n.SHORT&&oe&&(V=oe.RGB16_SNORM_EXT),H===n.UNSIGNED_INT_5_9_9_9_REV&&(V=n.RGB9_E5),H===n.UNSIGNED_INT_10F_11F_11F_REV&&(V=n.R11F_G11F_B10F)),y===n.RGBA){const K=te?qa:nt.getTransfer(G);H===n.FLOAT&&(V=n.RGBA32F),H===n.HALF_FLOAT&&(V=n.RGBA16F),H===n.UNSIGNED_BYTE&&(V=K===ft?n.SRGB8_ALPHA8:n.RGBA8),H===n.UNSIGNED_SHORT&&oe&&(V=oe.RGBA16_EXT),H===n.SHORT&&oe&&(V=oe.RGBA16_SNORM_EXT),H===n.UNSIGNED_SHORT_4_4_4_4&&(V=n.RGBA4),H===n.UNSIGNED_SHORT_5_5_5_1&&(V=n.RGB5_A1)}return(V===n.R16F||V===n.R32F||V===n.RG16F||V===n.RG32F||V===n.RGBA16F||V===n.RGBA32F)&&e.get("EXT_color_buffer_float"),V}function T(P,y){let H;return P?y===null||y===Qn||y===Ar?H=n.DEPTH24_STENCIL8:y===Ln?H=n.DEPTH32F_STENCIL8:y===Tr&&(H=n.DEPTH24_STENCIL8,We("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):y===null||y===Qn||y===Ar?H=n.DEPTH_COMPONENT24:y===Ln?H=n.DEPTH_COMPONENT32F:y===Tr&&(H=n.DEPTH_COMPONENT16),H}function b(P,y){return g(P)===!0||P.isFramebufferTexture&&P.minFilter!==Ft&&P.minFilter!==Xt?Math.log2(Math.max(y.width,y.height))+1:P.mipmaps!==void 0&&P.mipmaps.length>0?P.mipmaps.length:P.isCompressedTexture&&Array.isArray(P.image)?y.mipmaps.length:1}function S(P){const y=P.target;y.removeEventListener("dispose",S),w(y),y.isVideoTexture&&u.delete(y),y.isHTMLTexture&&f.delete(y)}function v(P){const y=P.target;y.removeEventListener("dispose",v),L(y)}function w(P){const y=i.get(P);if(y.__webglInit===void 0)return;const H=P.source,F=d.get(H);if(F){const G=F[y.__cacheKey];G.usedTimes--,G.usedTimes===0&&I(P),Object.keys(F).length===0&&d.delete(H)}i.remove(P)}function I(P){const y=i.get(P);n.deleteTexture(y.__webglTexture);const H=P.source,F=d.get(H);delete F[y.__cacheKey],a.memory.textures--}function L(P){const y=i.get(P);if(P.depthTexture&&(P.depthTexture.dispose(),i.remove(P.depthTexture)),P.isWebGLCubeRenderTarget)for(let F=0;F<6;F++){if(Array.isArray(y.__webglFramebuffer[F]))for(let G=0;G<y.__webglFramebuffer[F].length;G++)n.deleteFramebuffer(y.__webglFramebuffer[F][G]);else n.deleteFramebuffer(y.__webglFramebuffer[F]);y.__webglDepthbuffer&&n.deleteRenderbuffer(y.__webglDepthbuffer[F])}else{if(Array.isArray(y.__webglFramebuffer))for(let F=0;F<y.__webglFramebuffer.length;F++)n.deleteFramebuffer(y.__webglFramebuffer[F]);else n.deleteFramebuffer(y.__webglFramebuffer);if(y.__webglDepthbuffer&&n.deleteRenderbuffer(y.__webglDepthbuffer),y.__webglMultisampledFramebuffer&&n.deleteFramebuffer(y.__webglMultisampledFramebuffer),y.__webglColorRenderbuffer)for(let F=0;F<y.__webglColorRenderbuffer.length;F++)y.__webglColorRenderbuffer[F]&&n.deleteRenderbuffer(y.__webglColorRenderbuffer[F]);y.__webglDepthRenderbuffer&&n.deleteRenderbuffer(y.__webglDepthRenderbuffer)}const H=P.textures;for(let F=0,G=H.length;F<G;F++){const te=i.get(H[F]);te.__webglTexture&&(n.deleteTexture(te.__webglTexture),a.memory.textures--),i.remove(H[F])}i.remove(P)}let C=0;function O(){C=0}function N(){return C}function U(P){C=P}function Z(){const P=C;return P>=s.maxTextures&&We("WebGLTextures: Trying to use "+P+" texture units while this GPU supports only "+s.maxTextures),C+=1,P}function k(P){const y=[];return y.push(P.wrapS),y.push(P.wrapT),y.push(P.wrapR||0),y.push(P.magFilter),y.push(P.minFilter),y.push(P.anisotropy),y.push(P.internalFormat),y.push(P.format),y.push(P.type),y.push(P.generateMipmaps),y.push(P.premultiplyAlpha),y.push(P.flipY),y.push(P.unpackAlignment),y.push(P.colorSpace),y.join()}function $(P,y){const H=i.get(P);if(P.isVideoTexture&&R(P),P.isRenderTargetTexture===!1&&P.isExternalTexture!==!0&&P.version>0&&H.__version!==P.version){const F=P.image;if(F===null)We("WebGLRenderer: Texture marked for update but no image data found.");else if(F.complete===!1)We("WebGLRenderer: Texture marked for update but image is incomplete");else{ye(H,P,y);return}}else P.isExternalTexture&&(H.__webglTexture=P.sourceTexture?P.sourceTexture:null);t.bindTexture(n.TEXTURE_2D,H.__webglTexture,n.TEXTURE0+y)}function D(P,y){const H=i.get(P);if(P.isRenderTargetTexture===!1&&P.version>0&&H.__version!==P.version){ye(H,P,y);return}else P.isExternalTexture&&(H.__webglTexture=P.sourceTexture?P.sourceTexture:null);t.bindTexture(n.TEXTURE_2D_ARRAY,H.__webglTexture,n.TEXTURE0+y)}function ae(P,y){const H=i.get(P);if(P.isRenderTargetTexture===!1&&P.version>0&&H.__version!==P.version){ye(H,P,y);return}t.bindTexture(n.TEXTURE_3D,H.__webglTexture,n.TEXTURE0+y)}function re(P,y){const H=i.get(P);if(P.isCubeDepthTexture!==!0&&P.version>0&&H.__version!==P.version){ve(H,P,y);return}t.bindTexture(n.TEXTURE_CUBE_MAP,H.__webglTexture,n.TEXTURE0+y)}const ee={[Ll]:n.REPEAT,[li]:n.CLAMP_TO_EDGE,[Dl]:n.MIRRORED_REPEAT},ce={[Ft]:n.NEAREST,[vm]:n.NEAREST_MIPMAP_NEAREST,[Wr]:n.NEAREST_MIPMAP_LINEAR,[Xt]:n.LINEAR,[To]:n.LINEAR_MIPMAP_NEAREST,[Di]:n.LINEAR_MIPMAP_LINEAR},he={[bm]:n.NEVER,[Am]:n.ALWAYS,[Sm]:n.LESS,[Oc]:n.LEQUAL,[Mm]:n.EQUAL,[Fc]:n.GEQUAL,[Em]:n.GREATER,[Tm]:n.NOTEQUAL};function fe(P,y){if(y.type===Ln&&e.has("OES_texture_float_linear")===!1&&(y.magFilter===Xt||y.magFilter===To||y.magFilter===Wr||y.magFilter===Di||y.minFilter===Xt||y.minFilter===To||y.minFilter===Wr||y.minFilter===Di)&&We("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),n.texParameteri(P,n.TEXTURE_WRAP_S,ee[y.wrapS]),n.texParameteri(P,n.TEXTURE_WRAP_T,ee[y.wrapT]),(P===n.TEXTURE_3D||P===n.TEXTURE_2D_ARRAY)&&n.texParameteri(P,n.TEXTURE_WRAP_R,ee[y.wrapR]),n.texParameteri(P,n.TEXTURE_MAG_FILTER,ce[y.magFilter]),n.texParameteri(P,n.TEXTURE_MIN_FILTER,ce[y.minFilter]),y.compareFunction&&(n.texParameteri(P,n.TEXTURE_COMPARE_MODE,n.COMPARE_REF_TO_TEXTURE),n.texParameteri(P,n.TEXTURE_COMPARE_FUNC,he[y.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(y.magFilter===Ft||y.minFilter!==Wr&&y.minFilter!==Di||y.type===Ln&&e.has("OES_texture_float_linear")===!1)return;if(y.anisotropy>1||i.get(y).__currentAnisotropy){const H=e.get("EXT_texture_filter_anisotropic");n.texParameterf(P,H.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(y.anisotropy,s.getMaxAnisotropy())),i.get(y).__currentAnisotropy=y.anisotropy}}}function X(P,y){let H=!1;P.__webglInit===void 0&&(P.__webglInit=!0,y.addEventListener("dispose",S));const F=y.source;let G=d.get(F);G===void 0&&(G={},d.set(F,G));const te=k(y);if(te!==P.__cacheKey){G[te]===void 0&&(G[te]={texture:n.createTexture(),usedTimes:0},a.memory.textures++,H=!0),G[te].usedTimes++;const oe=G[P.__cacheKey];oe!==void 0&&(G[P.__cacheKey].usedTimes--,oe.usedTimes===0&&I(y)),P.__cacheKey=te,P.__webglTexture=G[te].texture}return H}function se(P,y,H){return Math.floor(Math.floor(P/H)/y)}function Q(P,y,H,F){const te=P.updateRanges;if(te.length===0)t.texSubImage2D(n.TEXTURE_2D,0,0,0,y.width,y.height,H,F,y.data);else{te.sort((de,pe)=>de.start-pe.start);let oe=0;for(let de=1;de<te.length;de++){const pe=te[oe],ge=te[de],Me=pe.start+pe.count,He=se(ge.start,y.width,4),qe=se(pe.start,y.width,4);ge.start<=Me+1&&He===qe&&se(ge.start+ge.count-1,y.width,4)===He?pe.count=Math.max(pe.count,ge.start+ge.count-pe.start):(++oe,te[oe]=ge)}te.length=oe+1;const V=t.getParameter(n.UNPACK_ROW_LENGTH),K=t.getParameter(n.UNPACK_SKIP_PIXELS),ie=t.getParameter(n.UNPACK_SKIP_ROWS);t.pixelStorei(n.UNPACK_ROW_LENGTH,y.width);for(let de=0,pe=te.length;de<pe;de++){const ge=te[de],Me=Math.floor(ge.start/4),He=Math.ceil(ge.count/4),qe=Me%y.width,z=Math.floor(Me/y.width),xe=He,le=1;t.pixelStorei(n.UNPACK_SKIP_PIXELS,qe),t.pixelStorei(n.UNPACK_SKIP_ROWS,z),t.texSubImage2D(n.TEXTURE_2D,0,qe,z,xe,le,H,F,y.data)}P.clearUpdateRanges(),t.pixelStorei(n.UNPACK_ROW_LENGTH,V),t.pixelStorei(n.UNPACK_SKIP_PIXELS,K),t.pixelStorei(n.UNPACK_SKIP_ROWS,ie)}}function ye(P,y,H){let F=n.TEXTURE_2D;(y.isDataArrayTexture||y.isCompressedArrayTexture)&&(F=n.TEXTURE_2D_ARRAY),y.isData3DTexture&&(F=n.TEXTURE_3D);const G=X(P,y),te=y.source;t.bindTexture(F,P.__webglTexture,n.TEXTURE0+H);const oe=i.get(te);if(te.version!==oe.__version||G===!0){if(t.activeTexture(n.TEXTURE0+H),(typeof ImageBitmap<"u"&&y.image instanceof ImageBitmap)===!1){const le=nt.getPrimaries(nt.workingColorSpace),be=y.colorSpace===oi?null:nt.getPrimaries(y.colorSpace),Ce=y.colorSpace===oi||le===be?n.NONE:n.BROWSER_DEFAULT_WEBGL;t.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,y.flipY),t.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,y.premultiplyAlpha),t.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,Ce)}t.pixelStorei(n.UNPACK_ALIGNMENT,y.unpackAlignment);let K=m(y.image,!1,s.maxTextureSize);K=Ae(y,K);const ie=r.convert(y.format,y.colorSpace),de=r.convert(y.type);let pe=_(y.internalFormat,ie,de,y.normalized,y.colorSpace,y.isVideoTexture);fe(F,y);let ge;const Me=y.mipmaps,He=y.isVideoTexture!==!0,qe=oe.__version===void 0||G===!0,z=te.dataReady,xe=b(y,K);if(y.isDepthTexture)pe=T(y.format===ji,y.type),qe&&(He?t.texStorage2D(n.TEXTURE_2D,1,pe,K.width,K.height):t.texImage2D(n.TEXTURE_2D,0,pe,K.width,K.height,0,ie,de,null));else if(y.isDataTexture)if(Me.length>0){He&&qe&&t.texStorage2D(n.TEXTURE_2D,xe,pe,Me[0].width,Me[0].height);for(let le=0,be=Me.length;le<be;le++)ge=Me[le],He?z&&t.texSubImage2D(n.TEXTURE_2D,le,0,0,ge.width,ge.height,ie,de,ge.data):t.texImage2D(n.TEXTURE_2D,le,pe,ge.width,ge.height,0,ie,de,ge.data);y.generateMipmaps=!1}else He?(qe&&t.texStorage2D(n.TEXTURE_2D,xe,pe,K.width,K.height),z&&Q(y,K,ie,de)):t.texImage2D(n.TEXTURE_2D,0,pe,K.width,K.height,0,ie,de,K.data);else if(y.isCompressedTexture)if(y.isCompressedArrayTexture){He&&qe&&t.texStorage3D(n.TEXTURE_2D_ARRAY,xe,pe,Me[0].width,Me[0].height,K.depth);for(let le=0,be=Me.length;le<be;le++)if(ge=Me[le],y.format!==En)if(ie!==null)if(He){if(z)if(y.layerUpdates.size>0){const Ce=Qu(ge.width,ge.height,y.format,y.type);for(const ue of y.layerUpdates){const ke=ge.data.subarray(ue*Ce/ge.data.BYTES_PER_ELEMENT,(ue+1)*Ce/ge.data.BYTES_PER_ELEMENT);t.compressedTexSubImage3D(n.TEXTURE_2D_ARRAY,le,0,0,ue,ge.width,ge.height,1,ie,ke)}y.clearLayerUpdates()}else t.compressedTexSubImage3D(n.TEXTURE_2D_ARRAY,le,0,0,0,ge.width,ge.height,K.depth,ie,ge.data)}else t.compressedTexImage3D(n.TEXTURE_2D_ARRAY,le,pe,ge.width,ge.height,K.depth,0,ge.data,0,0);else We("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else He?z&&t.texSubImage3D(n.TEXTURE_2D_ARRAY,le,0,0,0,ge.width,ge.height,K.depth,ie,de,ge.data):t.texImage3D(n.TEXTURE_2D_ARRAY,le,pe,ge.width,ge.height,K.depth,0,ie,de,ge.data)}else{He&&qe&&t.texStorage2D(n.TEXTURE_2D,xe,pe,Me[0].width,Me[0].height);for(let le=0,be=Me.length;le<be;le++)ge=Me[le],y.format!==En?ie!==null?He?z&&t.compressedTexSubImage2D(n.TEXTURE_2D,le,0,0,ge.width,ge.height,ie,ge.data):t.compressedTexImage2D(n.TEXTURE_2D,le,pe,ge.width,ge.height,0,ge.data):We("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):He?z&&t.texSubImage2D(n.TEXTURE_2D,le,0,0,ge.width,ge.height,ie,de,ge.data):t.texImage2D(n.TEXTURE_2D,le,pe,ge.width,ge.height,0,ie,de,ge.data)}else if(y.isDataArrayTexture)if(He){if(qe&&t.texStorage3D(n.TEXTURE_2D_ARRAY,xe,pe,K.width,K.height,K.depth),z)if(y.layerUpdates.size>0){const le=Qu(K.width,K.height,y.format,y.type);for(const be of y.layerUpdates){const Ce=K.data.subarray(be*le/K.data.BYTES_PER_ELEMENT,(be+1)*le/K.data.BYTES_PER_ELEMENT);t.texSubImage3D(n.TEXTURE_2D_ARRAY,0,0,0,be,K.width,K.height,1,ie,de,Ce)}y.clearLayerUpdates()}else t.texSubImage3D(n.TEXTURE_2D_ARRAY,0,0,0,0,K.width,K.height,K.depth,ie,de,K.data)}else t.texImage3D(n.TEXTURE_2D_ARRAY,0,pe,K.width,K.height,K.depth,0,ie,de,K.data);else if(y.isData3DTexture)He?(qe&&t.texStorage3D(n.TEXTURE_3D,xe,pe,K.width,K.height,K.depth),z&&t.texSubImage3D(n.TEXTURE_3D,0,0,0,0,K.width,K.height,K.depth,ie,de,K.data)):t.texImage3D(n.TEXTURE_3D,0,pe,K.width,K.height,K.depth,0,ie,de,K.data);else if(y.isFramebufferTexture){if(qe)if(He)t.texStorage2D(n.TEXTURE_2D,xe,pe,K.width,K.height);else{let le=K.width,be=K.height;for(let Ce=0;Ce<xe;Ce++)t.texImage2D(n.TEXTURE_2D,Ce,pe,le,be,0,ie,de,null),le>>=1,be>>=1}}else if(y.isHTMLTexture){if("texElementImage2D"in n){const le=n.canvas;if(le.hasAttribute("layoutsubtree")||le.setAttribute("layoutsubtree","true"),K.parentNode!==le){le.appendChild(K),f.add(y),le.onpaint=be=>{const Ce=be.changedElements;for(const ue of f)Ce.includes(ue.image)&&(ue.needsUpdate=!0)},le.requestPaint();return}if(n.texElementImage2D.length===3)n.texElementImage2D(n.TEXTURE_2D,n.RGBA8,K);else{const Ce=n.RGBA,ue=n.RGBA,ke=n.UNSIGNED_BYTE;n.texElementImage2D(n.TEXTURE_2D,0,Ce,ue,ke,K)}n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE)}}else if(Me.length>0){if(He&&qe){const le=W(Me[0]);t.texStorage2D(n.TEXTURE_2D,xe,pe,le.width,le.height)}for(let le=0,be=Me.length;le<be;le++)ge=Me[le],He?z&&t.texSubImage2D(n.TEXTURE_2D,le,0,0,ie,de,ge):t.texImage2D(n.TEXTURE_2D,le,pe,ie,de,ge);y.generateMipmaps=!1}else if(He){if(qe){const le=W(K);t.texStorage2D(n.TEXTURE_2D,xe,pe,le.width,le.height)}z&&t.texSubImage2D(n.TEXTURE_2D,0,0,0,ie,de,K)}else t.texImage2D(n.TEXTURE_2D,0,pe,ie,de,K);g(y)&&M(F),oe.__version=te.version,y.onUpdate&&y.onUpdate(y)}P.__version=y.version}function ve(P,y,H){if(y.image.length!==6)return;const F=X(P,y),G=y.source;t.bindTexture(n.TEXTURE_CUBE_MAP,P.__webglTexture,n.TEXTURE0+H);const te=i.get(G);if(G.version!==te.__version||F===!0){t.activeTexture(n.TEXTURE0+H);const oe=nt.getPrimaries(nt.workingColorSpace),V=y.colorSpace===oi?null:nt.getPrimaries(y.colorSpace),K=y.colorSpace===oi||oe===V?n.NONE:n.BROWSER_DEFAULT_WEBGL;t.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,y.flipY),t.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,y.premultiplyAlpha),t.pixelStorei(n.UNPACK_ALIGNMENT,y.unpackAlignment),t.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,K);const ie=y.isCompressedTexture||y.image[0].isCompressedTexture,de=y.image[0]&&y.image[0].isDataTexture,pe=[];for(let ue=0;ue<6;ue++)!ie&&!de?pe[ue]=m(y.image[ue],!0,s.maxCubemapSize):pe[ue]=de?y.image[ue].image:y.image[ue],pe[ue]=Ae(y,pe[ue]);const ge=pe[0],Me=r.convert(y.format,y.colorSpace),He=r.convert(y.type),qe=_(y.internalFormat,Me,He,y.normalized,y.colorSpace),z=y.isVideoTexture!==!0,xe=te.__version===void 0||F===!0,le=G.dataReady;let be=b(y,ge);fe(n.TEXTURE_CUBE_MAP,y);let Ce;if(ie){z&&xe&&t.texStorage2D(n.TEXTURE_CUBE_MAP,be,qe,ge.width,ge.height);for(let ue=0;ue<6;ue++){Ce=pe[ue].mipmaps;for(let ke=0;ke<Ce.length;ke++){const Le=Ce[ke];y.format!==En?Me!==null?z?le&&t.compressedTexSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,ke,0,0,Le.width,Le.height,Me,Le.data):t.compressedTexImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,ke,qe,Le.width,Le.height,0,Le.data):We("WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):z?le&&t.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,ke,0,0,Le.width,Le.height,Me,He,Le.data):t.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,ke,qe,Le.width,Le.height,0,Me,He,Le.data)}}}else{if(Ce=y.mipmaps,z&&xe){Ce.length>0&&be++;const ue=W(pe[0]);t.texStorage2D(n.TEXTURE_CUBE_MAP,be,qe,ue.width,ue.height)}for(let ue=0;ue<6;ue++)if(de){z?le&&t.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,0,0,0,pe[ue].width,pe[ue].height,Me,He,pe[ue].data):t.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,0,qe,pe[ue].width,pe[ue].height,0,Me,He,pe[ue].data);for(let ke=0;ke<Ce.length;ke++){const yt=Ce[ke].image[ue].image;z?le&&t.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,ke+1,0,0,yt.width,yt.height,Me,He,yt.data):t.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,ke+1,qe,yt.width,yt.height,0,Me,He,yt.data)}}else{z?le&&t.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,0,0,0,Me,He,pe[ue]):t.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,0,qe,Me,He,pe[ue]);for(let ke=0;ke<Ce.length;ke++){const Le=Ce[ke];z?le&&t.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,ke+1,0,0,Me,He,Le.image[ue]):t.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ue,ke+1,qe,Me,He,Le.image[ue])}}}g(y)&&M(n.TEXTURE_CUBE_MAP),te.__version=G.version,y.onUpdate&&y.onUpdate(y)}P.__version=y.version}function _e(P,y,H,F,G,te){const oe=r.convert(H.format,H.colorSpace),V=r.convert(H.type),K=_(H.internalFormat,oe,V,H.normalized,H.colorSpace),ie=i.get(y),de=i.get(H);if(de.__renderTarget=y,!ie.__hasExternalTextures){const pe=Math.max(1,y.width>>te),ge=Math.max(1,y.height>>te);G===n.TEXTURE_3D||G===n.TEXTURE_2D_ARRAY?t.texImage3D(G,te,K,pe,ge,y.depth,0,oe,V,null):t.texImage2D(G,te,K,pe,ge,0,oe,V,null)}t.bindFramebuffer(n.FRAMEBUFFER,P),ut(y)?o.framebufferTexture2DMultisampleEXT(n.FRAMEBUFFER,F,G,de.__webglTexture,0,ct(y)):(G===n.TEXTURE_2D||G>=n.TEXTURE_CUBE_MAP_POSITIVE_X&&G<=n.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&n.framebufferTexture2D(n.FRAMEBUFFER,F,G,de.__webglTexture,te),t.bindFramebuffer(n.FRAMEBUFFER,null)}function Ze(P,y,H){if(n.bindRenderbuffer(n.RENDERBUFFER,P),y.depthBuffer){const F=y.depthTexture,G=F&&F.isDepthTexture?F.type:null,te=T(y.stencilBuffer,G),oe=y.stencilBuffer?n.DEPTH_STENCIL_ATTACHMENT:n.DEPTH_ATTACHMENT;ut(y)?o.renderbufferStorageMultisampleEXT(n.RENDERBUFFER,ct(y),te,y.width,y.height):H?n.renderbufferStorageMultisample(n.RENDERBUFFER,ct(y),te,y.width,y.height):n.renderbufferStorage(n.RENDERBUFFER,te,y.width,y.height),n.framebufferRenderbuffer(n.FRAMEBUFFER,oe,n.RENDERBUFFER,P)}else{const F=y.textures;for(let G=0;G<F.length;G++){const te=F[G],oe=r.convert(te.format,te.colorSpace),V=r.convert(te.type),K=_(te.internalFormat,oe,V,te.normalized,te.colorSpace);ut(y)?o.renderbufferStorageMultisampleEXT(n.RENDERBUFFER,ct(y),K,y.width,y.height):H?n.renderbufferStorageMultisample(n.RENDERBUFFER,ct(y),K,y.width,y.height):n.renderbufferStorage(n.RENDERBUFFER,K,y.width,y.height)}}n.bindRenderbuffer(n.RENDERBUFFER,null)}function Ye(P,y,H){const F=y.isWebGLCubeRenderTarget===!0;if(t.bindFramebuffer(n.FRAMEBUFFER,P),!(y.depthTexture&&y.depthTexture.isDepthTexture))throw new Error("THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.");const G=i.get(y.depthTexture);if(G.__renderTarget=y,(!G.__webglTexture||y.depthTexture.image.width!==y.width||y.depthTexture.image.height!==y.height)&&(y.depthTexture.image.width=y.width,y.depthTexture.image.height=y.height,y.depthTexture.needsUpdate=!0),F){if(G.__webglInit===void 0&&(G.__webglInit=!0,y.depthTexture.addEventListener("dispose",S)),G.__webglTexture===void 0){G.__webglTexture=n.createTexture(),t.bindTexture(n.TEXTURE_CUBE_MAP,G.__webglTexture),fe(n.TEXTURE_CUBE_MAP,y.depthTexture);const ie=r.convert(y.depthTexture.format),de=r.convert(y.depthTexture.type);let pe;y.depthTexture.format===gi?pe=n.DEPTH_COMPONENT24:y.depthTexture.format===ji&&(pe=n.DEPTH24_STENCIL8);for(let ge=0;ge<6;ge++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+ge,0,pe,y.width,y.height,0,ie,de,null)}}else $(y.depthTexture,0);const te=G.__webglTexture,oe=ct(y),V=F?n.TEXTURE_CUBE_MAP_POSITIVE_X+H:n.TEXTURE_2D,K=y.depthTexture.format===ji?n.DEPTH_STENCIL_ATTACHMENT:n.DEPTH_ATTACHMENT;if(y.depthTexture.format===gi)ut(y)?o.framebufferTexture2DMultisampleEXT(n.FRAMEBUFFER,K,V,te,0,oe):n.framebufferTexture2D(n.FRAMEBUFFER,K,V,te,0);else if(y.depthTexture.format===ji)ut(y)?o.framebufferTexture2DMultisampleEXT(n.FRAMEBUFFER,K,V,te,0,oe):n.framebufferTexture2D(n.FRAMEBUFFER,K,V,te,0);else throw new Error("THREE.WebGLTextures: Unknown depthTexture format.")}function Oe(P){const y=i.get(P),H=P.isWebGLCubeRenderTarget===!0;if(y.__boundDepthTexture!==P.depthTexture){const F=P.depthTexture;if(y.__depthDisposeCallback&&y.__depthDisposeCallback(),F){const G=()=>{delete y.__boundDepthTexture,delete y.__depthDisposeCallback,F.removeEventListener("dispose",G)};F.addEventListener("dispose",G),y.__depthDisposeCallback=G}y.__boundDepthTexture=F}if(P.depthTexture&&!y.__autoAllocateDepthBuffer)if(H)for(let F=0;F<6;F++)Ye(y.__webglFramebuffer[F],P,F);else{const F=P.texture.mipmaps;F&&F.length>0?Ye(y.__webglFramebuffer[0],P,0):Ye(y.__webglFramebuffer,P,0)}else if(H){y.__webglDepthbuffer=[];for(let F=0;F<6;F++)if(t.bindFramebuffer(n.FRAMEBUFFER,y.__webglFramebuffer[F]),y.__webglDepthbuffer[F]===void 0)y.__webglDepthbuffer[F]=n.createRenderbuffer(),Ze(y.__webglDepthbuffer[F],P,!1);else{const G=P.stencilBuffer?n.DEPTH_STENCIL_ATTACHMENT:n.DEPTH_ATTACHMENT,te=y.__webglDepthbuffer[F];n.bindRenderbuffer(n.RENDERBUFFER,te),n.framebufferRenderbuffer(n.FRAMEBUFFER,G,n.RENDERBUFFER,te)}}else{const F=P.texture.mipmaps;if(F&&F.length>0?t.bindFramebuffer(n.FRAMEBUFFER,y.__webglFramebuffer[0]):t.bindFramebuffer(n.FRAMEBUFFER,y.__webglFramebuffer),y.__webglDepthbuffer===void 0)y.__webglDepthbuffer=n.createRenderbuffer(),Ze(y.__webglDepthbuffer,P,!1);else{const G=P.stencilBuffer?n.DEPTH_STENCIL_ATTACHMENT:n.DEPTH_ATTACHMENT,te=y.__webglDepthbuffer;n.bindRenderbuffer(n.RENDERBUFFER,te),n.framebufferRenderbuffer(n.FRAMEBUFFER,G,n.RENDERBUFFER,te)}}t.bindFramebuffer(n.FRAMEBUFFER,null)}function Fe(P,y,H){const F=i.get(P);y!==void 0&&_e(F.__webglFramebuffer,P,P.texture,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,0),H!==void 0&&Oe(P)}function Ve(P){const y=P.texture,H=i.get(P),F=i.get(y);P.addEventListener("dispose",v);const G=P.textures,te=P.isWebGLCubeRenderTarget===!0,oe=G.length>1;if(oe||(F.__webglTexture===void 0&&(F.__webglTexture=n.createTexture()),F.__version=y.version,a.memory.textures++),te){H.__webglFramebuffer=[];for(let V=0;V<6;V++)if(y.mipmaps&&y.mipmaps.length>0){H.__webglFramebuffer[V]=[];for(let K=0;K<y.mipmaps.length;K++)H.__webglFramebuffer[V][K]=n.createFramebuffer()}else H.__webglFramebuffer[V]=n.createFramebuffer()}else{if(y.mipmaps&&y.mipmaps.length>0){H.__webglFramebuffer=[];for(let V=0;V<y.mipmaps.length;V++)H.__webglFramebuffer[V]=n.createFramebuffer()}else H.__webglFramebuffer=n.createFramebuffer();if(oe)for(let V=0,K=G.length;V<K;V++){const ie=i.get(G[V]);ie.__webglTexture===void 0&&(ie.__webglTexture=n.createTexture(),a.memory.textures++)}if(P.samples>0&&ut(P)===!1){H.__webglMultisampledFramebuffer=n.createFramebuffer(),H.__webglColorRenderbuffer=[],t.bindFramebuffer(n.FRAMEBUFFER,H.__webglMultisampledFramebuffer);for(let V=0;V<G.length;V++){const K=G[V];H.__webglColorRenderbuffer[V]=n.createRenderbuffer(),n.bindRenderbuffer(n.RENDERBUFFER,H.__webglColorRenderbuffer[V]);const ie=r.convert(K.format,K.colorSpace),de=r.convert(K.type),pe=_(K.internalFormat,ie,de,K.normalized,K.colorSpace,P.isXRRenderTarget===!0),ge=ct(P);n.renderbufferStorageMultisample(n.RENDERBUFFER,ge,pe,P.width,P.height),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0+V,n.RENDERBUFFER,H.__webglColorRenderbuffer[V])}n.bindRenderbuffer(n.RENDERBUFFER,null),P.depthBuffer&&(H.__webglDepthRenderbuffer=n.createRenderbuffer(),Ze(H.__webglDepthRenderbuffer,P,!0)),t.bindFramebuffer(n.FRAMEBUFFER,null)}}if(te){t.bindTexture(n.TEXTURE_CUBE_MAP,F.__webglTexture),fe(n.TEXTURE_CUBE_MAP,y);for(let V=0;V<6;V++)if(y.mipmaps&&y.mipmaps.length>0)for(let K=0;K<y.mipmaps.length;K++)_e(H.__webglFramebuffer[V][K],P,y,n.COLOR_ATTACHMENT0,n.TEXTURE_CUBE_MAP_POSITIVE_X+V,K);else _e(H.__webglFramebuffer[V],P,y,n.COLOR_ATTACHMENT0,n.TEXTURE_CUBE_MAP_POSITIVE_X+V,0);g(y)&&M(n.TEXTURE_CUBE_MAP),t.unbindTexture()}else if(oe){for(let V=0,K=G.length;V<K;V++){const ie=G[V],de=i.get(ie);let pe=n.TEXTURE_2D;(P.isWebGL3DRenderTarget||P.isWebGLArrayRenderTarget)&&(pe=P.isWebGL3DRenderTarget?n.TEXTURE_3D:n.TEXTURE_2D_ARRAY),t.bindTexture(pe,de.__webglTexture),fe(pe,ie),_e(H.__webglFramebuffer,P,ie,n.COLOR_ATTACHMENT0+V,pe,0),g(ie)&&M(pe)}t.unbindTexture()}else{let V=n.TEXTURE_2D;if((P.isWebGL3DRenderTarget||P.isWebGLArrayRenderTarget)&&(V=P.isWebGL3DRenderTarget?n.TEXTURE_3D:n.TEXTURE_2D_ARRAY),t.bindTexture(V,F.__webglTexture),fe(V,y),y.mipmaps&&y.mipmaps.length>0)for(let K=0;K<y.mipmaps.length;K++)_e(H.__webglFramebuffer[K],P,y,n.COLOR_ATTACHMENT0,V,K);else _e(H.__webglFramebuffer,P,y,n.COLOR_ATTACHMENT0,V,0);g(y)&&M(V),t.unbindTexture()}P.depthBuffer&&Oe(P)}function at(P){const y=P.textures;for(let H=0,F=y.length;H<F;H++){const G=y[H];if(g(G)){const te=E(P),oe=i.get(G).__webglTexture;t.bindTexture(te,oe),M(te),t.unbindTexture()}}}const ot=[],pt=[];function vt(P){if(P.samples>0){if(ut(P)===!1){const y=P.textures,H=P.width,F=P.height;let G=n.COLOR_BUFFER_BIT;const te=P.stencilBuffer?n.DEPTH_STENCIL_ATTACHMENT:n.DEPTH_ATTACHMENT,oe=i.get(P),V=y.length>1;if(V)for(let ie=0;ie<y.length;ie++)t.bindFramebuffer(n.FRAMEBUFFER,oe.__webglMultisampledFramebuffer),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0+ie,n.RENDERBUFFER,null),t.bindFramebuffer(n.FRAMEBUFFER,oe.__webglFramebuffer),n.framebufferTexture2D(n.DRAW_FRAMEBUFFER,n.COLOR_ATTACHMENT0+ie,n.TEXTURE_2D,null,0);t.bindFramebuffer(n.READ_FRAMEBUFFER,oe.__webglMultisampledFramebuffer);const K=P.texture.mipmaps;K&&K.length>0?t.bindFramebuffer(n.DRAW_FRAMEBUFFER,oe.__webglFramebuffer[0]):t.bindFramebuffer(n.DRAW_FRAMEBUFFER,oe.__webglFramebuffer);for(let ie=0;ie<y.length;ie++){if(P.resolveDepthBuffer&&(P.depthBuffer&&(G|=n.DEPTH_BUFFER_BIT),P.stencilBuffer&&P.resolveStencilBuffer&&(G|=n.STENCIL_BUFFER_BIT)),V){n.framebufferRenderbuffer(n.READ_FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,oe.__webglColorRenderbuffer[ie]);const de=i.get(y[ie]).__webglTexture;n.framebufferTexture2D(n.DRAW_FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,de,0)}n.blitFramebuffer(0,0,H,F,0,0,H,F,G,n.NEAREST),l===!0&&(ot.length=0,pt.length=0,ot.push(n.COLOR_ATTACHMENT0+ie),P.depthBuffer&&P.resolveDepthBuffer===!1&&(ot.push(te),pt.push(te),n.invalidateFramebuffer(n.DRAW_FRAMEBUFFER,pt)),n.invalidateFramebuffer(n.READ_FRAMEBUFFER,ot))}if(t.bindFramebuffer(n.READ_FRAMEBUFFER,null),t.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),V)for(let ie=0;ie<y.length;ie++){t.bindFramebuffer(n.FRAMEBUFFER,oe.__webglMultisampledFramebuffer),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0+ie,n.RENDERBUFFER,oe.__webglColorRenderbuffer[ie]);const de=i.get(y[ie]).__webglTexture;t.bindFramebuffer(n.FRAMEBUFFER,oe.__webglFramebuffer),n.framebufferTexture2D(n.DRAW_FRAMEBUFFER,n.COLOR_ATTACHMENT0+ie,n.TEXTURE_2D,de,0)}t.bindFramebuffer(n.DRAW_FRAMEBUFFER,oe.__webglMultisampledFramebuffer)}else if(P.depthBuffer&&P.resolveDepthBuffer===!1&&l){const y=P.stencilBuffer?n.DEPTH_STENCIL_ATTACHMENT:n.DEPTH_ATTACHMENT;n.invalidateFramebuffer(n.DRAW_FRAMEBUFFER,[y])}}}function ct(P){return Math.min(s.maxSamples,P.samples)}function ut(P){const y=i.get(P);return P.samples>0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&y.__useRenderToTexture!==!1}function R(P){const y=a.render.frame;u.get(P)!==y&&(u.set(P,y),P.update())}function Ae(P,y){const H=P.colorSpace,F=P.format,G=P.type;return P.isCompressedTexture===!0||P.isVideoTexture===!0||H!==Ya&&H!==oi&&(nt.getTransfer(H)===ft?(F!==En||G!==Sn)&&We("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):st("WebGLTextures: Unsupported texture color space:",H)),y}function W(P){return typeof HTMLImageElement<"u"&&P instanceof HTMLImageElement?(c.width=P.naturalWidth||P.width,c.height=P.naturalHeight||P.height):typeof VideoFrame<"u"&&P instanceof VideoFrame?(c.width=P.displayWidth,c.height=P.displayHeight):(c.width=P.width,c.height=P.height),c}this.allocateTextureUnit=Z,this.resetTextureUnits=O,this.getTextureUnits=N,this.setTextureUnits=U,this.setTexture2D=$,this.setTexture2DArray=D,this.setTexture3D=ae,this.setTextureCube=re,this.rebindTextures=Fe,this.setupRenderTarget=Ve,this.updateRenderTargetMipmap=at,this.updateMultisampleRenderTarget=vt,this.setupDepthRenderbuffer=Oe,this.setupFrameBufferTexture=_e,this.useMultisampledRTT=ut,this.isReversedDepthBuffer=function(){return t.buffers.depth.getReversed()}}function L_(n,e){function t(i,s=oi){let r;const a=nt.getTransfer(s);if(i===Sn)return n.UNSIGNED_BYTE;if(i===Pc)return n.UNSIGNED_SHORT_4_4_4_4;if(i===Lc)return n.UNSIGNED_SHORT_5_5_5_1;if(i===Vf)return n.UNSIGNED_INT_5_9_9_9_REV;if(i===Wf)return n.UNSIGNED_INT_10F_11F_11F_REV;if(i===zf)return n.BYTE;if(i===Gf)return n.SHORT;if(i===Tr)return n.UNSIGNED_SHORT;if(i===Rc)return n.INT;if(i===Qn)return n.UNSIGNED_INT;if(i===Ln)return n.FLOAT;if(i===mi)return n.HALF_FLOAT;if(i===Xf)return n.ALPHA;if(i===Yf)return n.RGB;if(i===En)return n.RGBA;if(i===gi)return n.DEPTH_COMPONENT;if(i===ji)return n.DEPTH_STENCIL;if(i===qf)return n.RED;if(i===Dc)return n.RED_INTEGER;if(i===ts)return n.RG;if(i===Ic)return n.RG_INTEGER;if(i===Uc)return n.RGBA_INTEGER;if(i===Ua||i===Oa||i===Fa||i===Na)if(a===ft)if(r=e.get("WEBGL_compressed_texture_s3tc_srgb"),r!==null){if(i===Ua)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===Oa)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===Fa)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===Na)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(r=e.get("WEBGL_compressed_texture_s3tc"),r!==null){if(i===Ua)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===Oa)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===Fa)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===Na)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(i===Il||i===Ul||i===Ol||i===Fl)if(r=e.get("WEBGL_compressed_texture_pvrtc"),r!==null){if(i===Il)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(i===Ul)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(i===Ol)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(i===Fl)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(i===Nl||i===kl||i===Bl||i===Hl||i===zl||i===Wa||i===Gl)if(r=e.get("WEBGL_compressed_texture_etc"),r!==null){if(i===Nl||i===kl)return a===ft?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(i===Bl)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC;if(i===Hl)return r.COMPRESSED_R11_EAC;if(i===zl)return r.COMPRESSED_SIGNED_R11_EAC;if(i===Wa)return r.COMPRESSED_RG11_EAC;if(i===Gl)return r.COMPRESSED_SIGNED_RG11_EAC}else return null;if(i===Vl||i===Wl||i===Xl||i===Yl||i===ql||i===$l||i===Zl||i===Kl||i===Jl||i===jl||i===Ql||i===ec||i===tc||i===nc)if(r=e.get("WEBGL_compressed_texture_astc"),r!==null){if(i===Vl)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(i===Wl)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(i===Xl)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(i===Yl)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(i===ql)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(i===$l)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(i===Zl)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(i===Kl)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(i===Jl)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(i===jl)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(i===Ql)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(i===ec)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(i===tc)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(i===nc)return a===ft?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(i===ic||i===sc||i===rc)if(r=e.get("EXT_texture_compression_bptc"),r!==null){if(i===ic)return a===ft?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(i===sc)return r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(i===rc)return r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(i===ac||i===oc||i===Xa||i===lc)if(r=e.get("EXT_texture_compression_rgtc"),r!==null){if(i===ac)return r.COMPRESSED_RED_RGTC1_EXT;if(i===oc)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(i===Xa)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(i===lc)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return i===Ar?n.UNSIGNED_INT_24_8:n[i]!==void 0?n[i]:null}return{convert:t}}const D_=`
|
|
void main() {
|
|
|
|
gl_Position = vec4( position, 1.0 );
|
|
|
|
}`,I_=`
|
|
uniform sampler2DArray depthColor;
|
|
uniform float depthWidth;
|
|
uniform float depthHeight;
|
|
|
|
void main() {
|
|
|
|
vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );
|
|
|
|
if ( coord.x >= 1.0 ) {
|
|
|
|
gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;
|
|
|
|
} else {
|
|
|
|
gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;
|
|
|
|
}
|
|
|
|
}`;class U_{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){const i=new rd(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=i}}getMesh(e){if(this.texture!==null&&this.mesh===null){const t=e.cameras[0].viewport,i=new In({vertexShader:D_,fragmentShader:I_,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new Gt(new Qi(20,20),i)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class O_ extends zi{constructor(e,t){super();const i=this;let s=null,r=1,a=null,o="local-floor",l=1,c=null,u=null,f=null,h=null,d=null,p=null;const x=typeof XRWebGLBinding<"u",m=new U_,g={},M=t.getContextAttributes();let E=null,_=null;const T=[],b=[],S=new Ee;let v=null;const w=new Pn;w.viewport=new Ct;const I=new Pn;I.viewport=new Ct;const L=[w,I],C=new Wg;let O=null,N=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(X){let se=T[X];return se===void 0&&(se=new Do,T[X]=se),se.getTargetRaySpace()},this.getControllerGrip=function(X){let se=T[X];return se===void 0&&(se=new Do,T[X]=se),se.getGripSpace()},this.getHand=function(X){let se=T[X];return se===void 0&&(se=new Do,T[X]=se),se.getHandSpace()};function U(X){const se=b.indexOf(X.inputSource);if(se===-1)return;const Q=T[se];Q!==void 0&&(Q.update(X.inputSource,X.frame,c||a),Q.dispatchEvent({type:X.type,data:X.inputSource}))}function Z(){s.removeEventListener("select",U),s.removeEventListener("selectstart",U),s.removeEventListener("selectend",U),s.removeEventListener("squeeze",U),s.removeEventListener("squeezestart",U),s.removeEventListener("squeezeend",U),s.removeEventListener("end",Z),s.removeEventListener("inputsourceschange",k);for(let X=0;X<T.length;X++){const se=b[X];se!==null&&(b[X]=null,T[X].disconnect(se))}O=null,N=null,m.reset();for(const X in g)delete g[X];e.setRenderTarget(E),d=null,h=null,f=null,s=null,_=null,fe.stop(),i.isPresenting=!1,e.setPixelRatio(v),e.setSize(S.width,S.height,!1),i.dispatchEvent({type:"sessionend"})}this.setFramebufferScaleFactor=function(X){r=X,i.isPresenting===!0&&We("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(X){o=X,i.isPresenting===!0&&We("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return c||a},this.setReferenceSpace=function(X){c=X},this.getBaseLayer=function(){return h!==null?h:d},this.getBinding=function(){return f===null&&x&&(f=new XRWebGLBinding(s,t)),f},this.getFrame=function(){return p},this.getSession=function(){return s},this.setSession=async function(X){if(s=X,s!==null){if(E=e.getRenderTarget(),s.addEventListener("select",U),s.addEventListener("selectstart",U),s.addEventListener("selectend",U),s.addEventListener("squeeze",U),s.addEventListener("squeezestart",U),s.addEventListener("squeezeend",U),s.addEventListener("end",Z),s.addEventListener("inputsourceschange",k),M.xrCompatible!==!0&&await t.makeXRCompatible(),v=e.getPixelRatio(),e.getSize(S),x&&"createProjectionLayer"in XRWebGLBinding.prototype){let Q=null,ye=null,ve=null;M.depth&&(ve=M.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,Q=M.stencil?ji:gi,ye=M.stencil?Ar:Qn);const _e={colorFormat:t.RGBA8,depthFormat:ve,scaleFactor:r};f=this.getBinding(),h=f.createProjectionLayer(_e),s.updateRenderState({layers:[h]}),e.setPixelRatio(1),e.setSize(h.textureWidth,h.textureHeight,!1),_=new Jn(h.textureWidth,h.textureHeight,{format:En,type:Sn,depthTexture:new Ws(h.textureWidth,h.textureHeight,ye,void 0,void 0,void 0,void 0,void 0,void 0,Q),stencilBuffer:M.stencil,colorSpace:e.outputColorSpace,samples:M.antialias?4:0,resolveDepthBuffer:h.ignoreDepthValues===!1,resolveStencilBuffer:h.ignoreDepthValues===!1})}else{const Q={antialias:M.antialias,alpha:!0,depth:M.depth,stencil:M.stencil,framebufferScaleFactor:r};d=new XRWebGLLayer(s,t,Q),s.updateRenderState({baseLayer:d}),e.setPixelRatio(1),e.setSize(d.framebufferWidth,d.framebufferHeight,!1),_=new Jn(d.framebufferWidth,d.framebufferHeight,{format:En,type:Sn,colorSpace:e.outputColorSpace,stencilBuffer:M.stencil,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1})}_.isXRRenderTarget=!0,this.setFoveation(l),c=null,a=await s.requestReferenceSpace(o),fe.setContext(s),fe.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(s!==null)return s.environmentBlendMode},this.getDepthTexture=function(){return m.getDepthTexture()};function k(X){for(let se=0;se<X.removed.length;se++){const Q=X.removed[se],ye=b.indexOf(Q);ye>=0&&(b[ye]=null,T[ye].disconnect(Q))}for(let se=0;se<X.added.length;se++){const Q=X.added[se];let ye=b.indexOf(Q);if(ye===-1){for(let _e=0;_e<T.length;_e++)if(_e>=b.length){b.push(Q),ye=_e;break}else if(b[_e]===null){b[_e]=Q,ye=_e;break}if(ye===-1)break}const ve=T[ye];ve&&ve.connect(Q)}}const $=new B,D=new B;function ae(X,se,Q){$.setFromMatrixPosition(se.matrixWorld),D.setFromMatrixPosition(Q.matrixWorld);const ye=$.distanceTo(D),ve=se.projectionMatrix.elements,_e=Q.projectionMatrix.elements,Ze=ve[14]/(ve[10]-1),Ye=ve[14]/(ve[10]+1),Oe=(ve[9]+1)/ve[5],Fe=(ve[9]-1)/ve[5],Ve=(ve[8]-1)/ve[0],at=(_e[8]+1)/_e[0],ot=Ze*Ve,pt=Ze*at,vt=ye/(-Ve+at),ct=vt*-Ve;if(se.matrixWorld.decompose(X.position,X.quaternion,X.scale),X.translateX(ct),X.translateZ(vt),X.matrixWorld.compose(X.position,X.quaternion,X.scale),X.matrixWorldInverse.copy(X.matrixWorld).invert(),ve[10]===-1)X.projectionMatrix.copy(se.projectionMatrix),X.projectionMatrixInverse.copy(se.projectionMatrixInverse);else{const ut=Ze+vt,R=Ye+vt,Ae=ot-ct,W=pt+(ye-ct),P=Oe*Ye/R*ut,y=Fe*Ye/R*ut;X.projectionMatrix.makePerspective(Ae,W,P,y,ut,R),X.projectionMatrixInverse.copy(X.projectionMatrix).invert()}}function re(X,se){se===null?X.matrixWorld.copy(X.matrix):X.matrixWorld.multiplyMatrices(se.matrixWorld,X.matrix),X.matrixWorldInverse.copy(X.matrixWorld).invert()}this.updateCamera=function(X){if(s===null)return;let se=X.near,Q=X.far;m.texture!==null&&(m.depthNear>0&&(se=m.depthNear),m.depthFar>0&&(Q=m.depthFar)),C.near=I.near=w.near=se,C.far=I.far=w.far=Q,(O!==C.near||N!==C.far)&&(s.updateRenderState({depthNear:C.near,depthFar:C.far}),O=C.near,N=C.far),C.layers.mask=X.layers.mask|6,w.layers.mask=C.layers.mask&-5,I.layers.mask=C.layers.mask&-3;const ye=X.parent,ve=C.cameras;re(C,ye);for(let _e=0;_e<ve.length;_e++)re(ve[_e],ye);ve.length===2?ae(C,w,I):C.projectionMatrix.copy(w.projectionMatrix),ee(X,C,ye)};function ee(X,se,Q){Q===null?X.matrix.copy(se.matrixWorld):(X.matrix.copy(Q.matrixWorld),X.matrix.invert(),X.matrix.multiply(se.matrixWorld)),X.matrix.decompose(X.position,X.quaternion,X.scale),X.updateMatrixWorld(!0),X.projectionMatrix.copy(se.projectionMatrix),X.projectionMatrixInverse.copy(se.projectionMatrixInverse),X.isPerspectiveCamera&&(X.fov=hc*2*Math.atan(1/X.projectionMatrix.elements[5]),X.zoom=1)}this.getCamera=function(){return C},this.getFoveation=function(){if(!(h===null&&d===null))return l},this.setFoveation=function(X){l=X,h!==null&&(h.fixedFoveation=X),d!==null&&d.fixedFoveation!==void 0&&(d.fixedFoveation=X)},this.hasDepthSensing=function(){return m.texture!==null},this.getDepthSensingMesh=function(){return m.getMesh(C)},this.getCameraTexture=function(X){return g[X]};let ce=null;function he(X,se){if(u=se.getViewerPose(c||a),p=se,u!==null){const Q=u.views;d!==null&&(e.setRenderTargetFramebuffer(_,d.framebuffer),e.setRenderTarget(_));let ye=!1;Q.length!==C.cameras.length&&(C.cameras.length=0,ye=!0);for(let Ye=0;Ye<Q.length;Ye++){const Oe=Q[Ye];let Fe=null;if(d!==null)Fe=d.getViewport(Oe);else{const at=f.getViewSubImage(h,Oe);Fe=at.viewport,Ye===0&&(e.setRenderTargetTextures(_,at.colorTexture,at.depthStencilTexture),e.setRenderTarget(_))}let Ve=L[Ye];Ve===void 0&&(Ve=new Pn,Ve.layers.enable(Ye),Ve.viewport=new Ct,L[Ye]=Ve),Ve.matrix.fromArray(Oe.transform.matrix),Ve.matrix.decompose(Ve.position,Ve.quaternion,Ve.scale),Ve.projectionMatrix.fromArray(Oe.projectionMatrix),Ve.projectionMatrixInverse.copy(Ve.projectionMatrix).invert(),Ve.viewport.set(Fe.x,Fe.y,Fe.width,Fe.height),Ye===0&&(C.matrix.copy(Ve.matrix),C.matrix.decompose(C.position,C.quaternion,C.scale)),ye===!0&&C.cameras.push(Ve)}const ve=s.enabledFeatures;if(ve&&ve.includes("depth-sensing")&&s.depthUsage=="gpu-optimized"&&x){f=i.getBinding();const Ye=f.getDepthInformation(Q[0]);Ye&&Ye.isValid&&Ye.texture&&m.init(Ye,s.renderState)}if(ve&&ve.includes("camera-access")&&x){e.state.unbindTexture(),f=i.getBinding();for(let Ye=0;Ye<Q.length;Ye++){const Oe=Q[Ye].camera;if(Oe){let Fe=g[Oe];Fe||(Fe=new rd,g[Oe]=Fe);const Ve=f.getCameraImage(Oe);Fe.sourceTexture=Ve}}}}for(let Q=0;Q<T.length;Q++){const ye=b[Q],ve=T[Q];ye!==null&&ve!==void 0&&ve.update(ye,se,c||a)}ce&&ce(X,se),se.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:se}),p=null}const fe=new xd;fe.setAnimationLoop(he),this.setAnimationLoop=function(X){ce=X},this.dispose=function(){}}}const F_=new Tt,Ed=new $e;Ed.set(-1,0,0,0,1,0,0,0,1);function N_(n,e){function t(m,g){m.matrixAutoUpdate===!0&&m.updateMatrix(),g.value.copy(m.matrix)}function i(m,g){g.color.getRGB(m.fogColor.value,md(n)),g.isFog?(m.fogNear.value=g.near,m.fogFar.value=g.far):g.isFogExp2&&(m.fogDensity.value=g.density)}function s(m,g,M,E,_){g.isNodeMaterial?g.uniformsNeedUpdate=!1:g.isMeshBasicMaterial?r(m,g):g.isMeshLambertMaterial?(r(m,g),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)):g.isMeshToonMaterial?(r(m,g),f(m,g)):g.isMeshPhongMaterial?(r(m,g),u(m,g),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)):g.isMeshStandardMaterial?(r(m,g),h(m,g),g.isMeshPhysicalMaterial&&d(m,g,_)):g.isMeshMatcapMaterial?(r(m,g),p(m,g)):g.isMeshDepthMaterial?r(m,g):g.isMeshDistanceMaterial?(r(m,g),x(m,g)):g.isMeshNormalMaterial?r(m,g):g.isLineBasicMaterial?(a(m,g),g.isLineDashedMaterial&&o(m,g)):g.isPointsMaterial?l(m,g,M,E):g.isSpriteMaterial?c(m,g):g.isShadowMaterial?(m.color.value.copy(g.color),m.opacity.value=g.opacity):g.isShaderMaterial&&(g.uniformsNeedUpdate=!1)}function r(m,g){m.opacity.value=g.opacity,g.color&&m.diffuse.value.copy(g.color),g.emissive&&m.emissive.value.copy(g.emissive).multiplyScalar(g.emissiveIntensity),g.map&&(m.map.value=g.map,t(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,t(g.alphaMap,m.alphaMapTransform)),g.bumpMap&&(m.bumpMap.value=g.bumpMap,t(g.bumpMap,m.bumpMapTransform),m.bumpScale.value=g.bumpScale,g.side===un&&(m.bumpScale.value*=-1)),g.normalMap&&(m.normalMap.value=g.normalMap,t(g.normalMap,m.normalMapTransform),m.normalScale.value.copy(g.normalScale),g.side===un&&m.normalScale.value.negate()),g.displacementMap&&(m.displacementMap.value=g.displacementMap,t(g.displacementMap,m.displacementMapTransform),m.displacementScale.value=g.displacementScale,m.displacementBias.value=g.displacementBias),g.emissiveMap&&(m.emissiveMap.value=g.emissiveMap,t(g.emissiveMap,m.emissiveMapTransform)),g.specularMap&&(m.specularMap.value=g.specularMap,t(g.specularMap,m.specularMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest);const M=e.get(g),E=M.envMap,_=M.envMapRotation;E&&(m.envMap.value=E,m.envMapRotation.value.setFromMatrix4(F_.makeRotationFromEuler(_)).transpose(),E.isCubeTexture&&E.isRenderTargetTexture===!1&&m.envMapRotation.value.premultiply(Ed),m.reflectivity.value=g.reflectivity,m.ior.value=g.ior,m.refractionRatio.value=g.refractionRatio),g.lightMap&&(m.lightMap.value=g.lightMap,m.lightMapIntensity.value=g.lightMapIntensity,t(g.lightMap,m.lightMapTransform)),g.aoMap&&(m.aoMap.value=g.aoMap,m.aoMapIntensity.value=g.aoMapIntensity,t(g.aoMap,m.aoMapTransform))}function a(m,g){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,g.map&&(m.map.value=g.map,t(g.map,m.mapTransform))}function o(m,g){m.dashSize.value=g.dashSize,m.totalSize.value=g.dashSize+g.gapSize,m.scale.value=g.scale}function l(m,g,M,E){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,m.size.value=g.size*M,m.scale.value=E*.5,g.map&&(m.map.value=g.map,t(g.map,m.uvTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,t(g.alphaMap,m.alphaMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest)}function c(m,g){m.diffuse.value.copy(g.color),m.opacity.value=g.opacity,m.rotation.value=g.rotation,g.map&&(m.map.value=g.map,t(g.map,m.mapTransform)),g.alphaMap&&(m.alphaMap.value=g.alphaMap,t(g.alphaMap,m.alphaMapTransform)),g.alphaTest>0&&(m.alphaTest.value=g.alphaTest)}function u(m,g){m.specular.value.copy(g.specular),m.shininess.value=Math.max(g.shininess,1e-4)}function f(m,g){g.gradientMap&&(m.gradientMap.value=g.gradientMap)}function h(m,g){m.metalness.value=g.metalness,g.metalnessMap&&(m.metalnessMap.value=g.metalnessMap,t(g.metalnessMap,m.metalnessMapTransform)),m.roughness.value=g.roughness,g.roughnessMap&&(m.roughnessMap.value=g.roughnessMap,t(g.roughnessMap,m.roughnessMapTransform)),g.envMap&&(m.envMapIntensity.value=g.envMapIntensity)}function d(m,g,M){m.ior.value=g.ior,g.sheen>0&&(m.sheenColor.value.copy(g.sheenColor).multiplyScalar(g.sheen),m.sheenRoughness.value=g.sheenRoughness,g.sheenColorMap&&(m.sheenColorMap.value=g.sheenColorMap,t(g.sheenColorMap,m.sheenColorMapTransform)),g.sheenRoughnessMap&&(m.sheenRoughnessMap.value=g.sheenRoughnessMap,t(g.sheenRoughnessMap,m.sheenRoughnessMapTransform))),g.clearcoat>0&&(m.clearcoat.value=g.clearcoat,m.clearcoatRoughness.value=g.clearcoatRoughness,g.clearcoatMap&&(m.clearcoatMap.value=g.clearcoatMap,t(g.clearcoatMap,m.clearcoatMapTransform)),g.clearcoatRoughnessMap&&(m.clearcoatRoughnessMap.value=g.clearcoatRoughnessMap,t(g.clearcoatRoughnessMap,m.clearcoatRoughnessMapTransform)),g.clearcoatNormalMap&&(m.clearcoatNormalMap.value=g.clearcoatNormalMap,t(g.clearcoatNormalMap,m.clearcoatNormalMapTransform),m.clearcoatNormalScale.value.copy(g.clearcoatNormalScale),g.side===un&&m.clearcoatNormalScale.value.negate())),g.dispersion>0&&(m.dispersion.value=g.dispersion),g.iridescence>0&&(m.iridescence.value=g.iridescence,m.iridescenceIOR.value=g.iridescenceIOR,m.iridescenceThicknessMinimum.value=g.iridescenceThicknessRange[0],m.iridescenceThicknessMaximum.value=g.iridescenceThicknessRange[1],g.iridescenceMap&&(m.iridescenceMap.value=g.iridescenceMap,t(g.iridescenceMap,m.iridescenceMapTransform)),g.iridescenceThicknessMap&&(m.iridescenceThicknessMap.value=g.iridescenceThicknessMap,t(g.iridescenceThicknessMap,m.iridescenceThicknessMapTransform))),g.transmission>0&&(m.transmission.value=g.transmission,m.transmissionSamplerMap.value=M.texture,m.transmissionSamplerSize.value.set(M.width,M.height),g.transmissionMap&&(m.transmissionMap.value=g.transmissionMap,t(g.transmissionMap,m.transmissionMapTransform)),m.thickness.value=g.thickness,g.thicknessMap&&(m.thicknessMap.value=g.thicknessMap,t(g.thicknessMap,m.thicknessMapTransform)),m.attenuationDistance.value=g.attenuationDistance,m.attenuationColor.value.copy(g.attenuationColor)),g.anisotropy>0&&(m.anisotropyVector.value.set(g.anisotropy*Math.cos(g.anisotropyRotation),g.anisotropy*Math.sin(g.anisotropyRotation)),g.anisotropyMap&&(m.anisotropyMap.value=g.anisotropyMap,t(g.anisotropyMap,m.anisotropyMapTransform))),m.specularIntensity.value=g.specularIntensity,m.specularColor.value.copy(g.specularColor),g.specularColorMap&&(m.specularColorMap.value=g.specularColorMap,t(g.specularColorMap,m.specularColorMapTransform)),g.specularIntensityMap&&(m.specularIntensityMap.value=g.specularIntensityMap,t(g.specularIntensityMap,m.specularIntensityMapTransform))}function p(m,g){g.matcap&&(m.matcap.value=g.matcap)}function x(m,g){const M=e.get(g).light;m.referencePosition.value.setFromMatrixPosition(M.matrixWorld),m.nearDistance.value=M.shadow.camera.near,m.farDistance.value=M.shadow.camera.far}return{refreshFogUniforms:i,refreshMaterialUniforms:s}}function k_(n,e,t,i){let s={},r={},a=[];const o=n.getParameter(n.MAX_UNIFORM_BUFFER_BINDINGS);function l(_,T){const b=T.program;i.uniformBlockBinding(_,b)}function c(_,T){let b=s[_.id];b===void 0&&(m(_),b=u(_),s[_.id]=b,_.addEventListener("dispose",M));const S=T.program;i.updateUBOMapping(_,S);const v=e.render.frame;r[_.id]!==v&&(h(_),r[_.id]=v)}function u(_){const T=f();_.__bindingPointIndex=T;const b=n.createBuffer(),S=_.__size,v=_.usage;return n.bindBuffer(n.UNIFORM_BUFFER,b),n.bufferData(n.UNIFORM_BUFFER,S,v),n.bindBuffer(n.UNIFORM_BUFFER,null),n.bindBufferBase(n.UNIFORM_BUFFER,T,b),b}function f(){for(let _=0;_<o;_++)if(a.indexOf(_)===-1)return a.push(_),_;return st("WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}function h(_){const T=s[_.id],b=_.uniforms,S=_.__cache;n.bindBuffer(n.UNIFORM_BUFFER,T);for(let v=0,w=b.length;v<w;v++){const I=b[v];if(Array.isArray(I))for(let L=0,C=I.length;L<C;L++)d(I[L],v,L,S);else d(I,v,0,S)}n.bindBuffer(n.UNIFORM_BUFFER,null)}function d(_,T,b,S){if(x(_,T,b,S)===!0){const v=_.__offset,w=_.value;if(Array.isArray(w)){let I=0;for(let L=0;L<w.length;L++){const C=w[L],O=g(C);p(C,_.__data,I),typeof C!="number"&&typeof C!="boolean"&&!C.isMatrix3&&!ArrayBuffer.isView(C)&&(I+=O.storage/Float32Array.BYTES_PER_ELEMENT)}}else p(w,_.__data,0);n.bufferSubData(n.UNIFORM_BUFFER,v,_.__data)}}function p(_,T,b){typeof _=="number"||typeof _=="boolean"?T[0]=_:_.isMatrix3?(T[0]=_.elements[0],T[1]=_.elements[1],T[2]=_.elements[2],T[3]=0,T[4]=_.elements[3],T[5]=_.elements[4],T[6]=_.elements[5],T[7]=0,T[8]=_.elements[6],T[9]=_.elements[7],T[10]=_.elements[8],T[11]=0):ArrayBuffer.isView(_)?T.set(new _.constructor(_.buffer,_.byteOffset,T.length)):_.toArray(T,b)}function x(_,T,b,S){const v=_.value,w=T+"_"+b;if(S[w]===void 0)return typeof v=="number"||typeof v=="boolean"?S[w]=v:ArrayBuffer.isView(v)?S[w]=v.slice():S[w]=v.clone(),!0;{const I=S[w];if(typeof v=="number"||typeof v=="boolean"){if(I!==v)return S[w]=v,!0}else{if(ArrayBuffer.isView(v))return!0;if(I.equals(v)===!1)return I.copy(v),!0}}return!1}function m(_){const T=_.uniforms;let b=0;const S=16;for(let w=0,I=T.length;w<I;w++){const L=Array.isArray(T[w])?T[w]:[T[w]];for(let C=0,O=L.length;C<O;C++){const N=L[C],U=Array.isArray(N.value)?N.value:[N.value];for(let Z=0,k=U.length;Z<k;Z++){const $=U[Z],D=g($),ae=b%S,re=ae%D.boundary,ee=ae+re;b+=re,ee!==0&&S-ee<D.storage&&(b+=S-ee),N.__data=new Float32Array(D.storage/Float32Array.BYTES_PER_ELEMENT),N.__offset=b,b+=D.storage}}}const v=b%S;return v>0&&(b+=S-v),_.__size=b,_.__cache={},this}function g(_){const T={boundary:0,storage:0};return typeof _=="number"||typeof _=="boolean"?(T.boundary=4,T.storage=4):_.isVector2?(T.boundary=8,T.storage=8):_.isVector3||_.isColor?(T.boundary=16,T.storage=12):_.isVector4?(T.boundary=16,T.storage=16):_.isMatrix3?(T.boundary=48,T.storage=48):_.isMatrix4?(T.boundary=64,T.storage=64):_.isTexture?We("WebGLRenderer: Texture samplers can not be part of an uniforms group."):ArrayBuffer.isView(_)?(T.boundary=16,T.storage=_.byteLength):We("WebGLRenderer: Unsupported uniform value type.",_),T}function M(_){const T=_.target;T.removeEventListener("dispose",M);const b=a.indexOf(T.__bindingPointIndex);a.splice(b,1),n.deleteBuffer(s[T.id]),delete s[T.id],delete r[T.id]}function E(){for(const _ in s)n.deleteBuffer(s[_]);a=[],s={},r={}}return{bind:l,update:c,dispose:E}}const B_=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]);let Hn=null;function H_(){return Hn===null&&(Hn=new td(B_,16,16,ts,mi),Hn.name="DFG_LUT",Hn.minFilter=Xt,Hn.magFilter=Xt,Hn.wrapS=li,Hn.wrapT=li,Hn.generateMipmaps=!1,Hn.needsUpdate=!0),Hn}class z_{constructor(e={}){const{canvas:t=Cm(),context:i=null,depth:s=!0,stencil:r=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:c=!1,powerPreference:u="default",failIfMajorPerformanceCaveat:f=!1,reversedDepthBuffer:h=!1,outputBufferType:d=Sn}=e;this.isWebGLRenderer=!0;let p;if(i!==null){if(typeof WebGLRenderingContext<"u"&&i instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=i.getContextAttributes().alpha}else p=a;const x=d,m=new Set([Uc,Ic,Dc]),g=new Set([Sn,Qn,Tr,Ar,Pc,Lc]),M=new Uint32Array(4),E=new Int32Array(4),_=new B;let T=null,b=null;const S=[],v=[];let w=null;this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=Kn,this.toneMappingExposure=1,this.transmissionResolutionScale=1;const I=this;let L=!1,C=null,O=null,N=null,U=null;this._outputColorSpace=mn;let Z=0,k=0,$=null,D=-1,ae=null;const re=new Ct,ee=new Ct;let ce=null;const he=new et(0);let fe=0,X=t.width,se=t.height,Q=1,ye=null,ve=null;const _e=new Ct(0,0,X,se),Ze=new Ct(0,0,X,se);let Ye=!1;const Oe=new nd;let Fe=!1,Ve=!1;const at=new Tt,ot=new B,pt=new Ct,vt={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let ct=!1;function ut(){return $===null?Q:1}let R=i;function Ae(A,Y){return t.getContext(A,Y)}try{const A={alpha:!0,depth:s,stencil:r,antialias:o,premultipliedAlpha:l,preserveDrawingBuffer:c,powerPreference:u,failIfMajorPerformanceCaveat:f};if("setAttribute"in t&&t.setAttribute("data-engine",`three.js r${Cc}`),t.addEventListener("webglcontextlost",yt,!1),t.addEventListener("webglcontextrestored",_t,!1),t.addEventListener("webglcontextcreationerror",hn,!1),R===null){const Y="webgl2";if(R=Ae(Y,A),R===null)throw Ae(Y)?new Error("THREE.WebGLRenderer: Error creating WebGL context with your selected attributes."):new Error("THREE.WebGLRenderer: Error creating WebGL context.")}}catch(A){throw st("WebGLRenderer: "+A.message),A}let W,P,y,H,F,G,te,oe,V,K,ie,de,pe,ge,Me,He,qe,z,xe,le,be,Ce,ue;function ke(){W=new Hv(R),W.init(),be=new L_(R,W),P=new Dv(R,W,e,be),y=new R_(R,W),P.reversedDepthBuffer&&h&&y.buffers.depth.setReversed(!0),O=R.createFramebuffer(),N=R.createFramebuffer(),U=R.createFramebuffer(),H=new Vv(R),F=new m_,G=new P_(R,W,y,F,P,be,H),te=new Bv(I),oe=new qg(R),Ce=new Pv(R,oe),V=new zv(R,oe,H,Ce),K=new Xv(R,V,oe,Ce,H),z=new Wv(R,P,G),Me=new Iv(F),ie=new p_(I,te,W,P,Ce,Me),de=new N_(I,F),pe=new x_,ge=new M_(W),qe=new Rv(I,te,y,K,p,l),He=new C_(I,K,P),ue=new k_(R,H,P,y),xe=new Lv(R,W,H),le=new Gv(R,W,H),H.programs=ie.programs,I.capabilities=P,I.extensions=W,I.properties=F,I.renderLists=pe,I.shadowMap=He,I.state=y,I.info=H}ke(),x!==Sn&&(w=new qv(x,t.width,t.height,o,s,r));const Le=new O_(I,R);this.xr=Le,this.getContext=function(){return R},this.getContextAttributes=function(){return R.getContextAttributes()},this.forceContextLoss=function(){const A=W.get("WEBGL_lose_context");A&&A.loseContext()},this.forceContextRestore=function(){const A=W.get("WEBGL_lose_context");A&&A.restoreContext()},this.getPixelRatio=function(){return Q},this.setPixelRatio=function(A){A!==void 0&&(Q=A,this.setSize(X,se,!1))},this.getSize=function(A){return A.set(X,se)},this.setSize=function(A,Y,ne=!0){if(Le.isPresenting){We("WebGLRenderer: Can't change size while VR device is presenting.");return}X=A,se=Y,t.width=Math.floor(A*Q),t.height=Math.floor(Y*Q),ne===!0&&(t.style.width=A+"px",t.style.height=Y+"px"),w!==null&&w.setSize(t.width,t.height),this.setViewport(0,0,A,Y)},this.getDrawingBufferSize=function(A){return A.set(X*Q,se*Q).floor()},this.setDrawingBufferSize=function(A,Y,ne){X=A,se=Y,Q=ne,t.width=Math.floor(A*ne),t.height=Math.floor(Y*ne),this.setViewport(0,0,A,Y)},this.setEffects=function(A){if(x===Sn){st("WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.");return}if(A){for(let Y=0;Y<A.length;Y++)if(A[Y].isOutputPass===!0){We("WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.");break}}w.setEffects(A||[])},this.getCurrentViewport=function(A){return A.copy(re)},this.getViewport=function(A){return A.copy(_e)},this.setViewport=function(A,Y,ne,J){A.isVector4?_e.set(A.x,A.y,A.z,A.w):_e.set(A,Y,ne,J),y.viewport(re.copy(_e).multiplyScalar(Q).round())},this.getScissor=function(A){return A.copy(Ze)},this.setScissor=function(A,Y,ne,J){A.isVector4?Ze.set(A.x,A.y,A.z,A.w):Ze.set(A,Y,ne,J),y.scissor(ee.copy(Ze).multiplyScalar(Q).round())},this.getScissorTest=function(){return Ye},this.setScissorTest=function(A){y.setScissorTest(Ye=A)},this.setOpaqueSort=function(A){ye=A},this.setTransparentSort=function(A){ve=A},this.getClearColor=function(A){return A.copy(qe.getClearColor())},this.setClearColor=function(){qe.setClearColor(...arguments)},this.getClearAlpha=function(){return qe.getClearAlpha()},this.setClearAlpha=function(){qe.setClearAlpha(...arguments)},this.clear=function(A=!0,Y=!0,ne=!0){let J=0;if(A){let j=!1;if($!==null){const Pe=$.texture.format;j=m.has(Pe)}if(j){const Pe=$.texture.type,Ie=g.has(Pe),Re=qe.getClearColor(),Be=qe.getClearAlpha(),ze=Re.r,Ke=Re.g,je=Re.b;Ie?(M[0]=ze,M[1]=Ke,M[2]=je,M[3]=Be,R.clearBufferuiv(R.COLOR,0,M)):(E[0]=ze,E[1]=Ke,E[2]=je,E[3]=Be,R.clearBufferiv(R.COLOR,0,E))}else J|=R.COLOR_BUFFER_BIT}Y&&(J|=R.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),ne&&(J|=R.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),J!==0&&R.clear(J)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.setNodesHandler=function(A){A.setRenderer(this),C=A},this.dispose=function(){t.removeEventListener("webglcontextlost",yt,!1),t.removeEventListener("webglcontextrestored",_t,!1),t.removeEventListener("webglcontextcreationerror",hn,!1),qe.dispose(),pe.dispose(),ge.dispose(),F.dispose(),te.dispose(),K.dispose(),Ce.dispose(),ue.dispose(),ie.dispose(),Le.dispose(),Le.removeEventListener("sessionstart",tr),Le.removeEventListener("sessionend",nr),qt.stop()};function yt(A){A.preventDefault(),Ka("WebGLRenderer: Context Lost."),L=!0}function _t(){Ka("WebGLRenderer: Context Restored."),L=!1;const A=H.autoReset,Y=He.enabled,ne=He.autoUpdate,J=He.needsUpdate,j=He.type;ke(),H.autoReset=A,He.enabled=Y,He.autoUpdate=ne,He.needsUpdate=J,He.type=j}function hn(A){st("WebGLRenderer: A WebGL context could not be created. Reason: ",A.statusMessage)}function Ut(A){const Y=A.target;Y.removeEventListener("dispose",Ut),Gr(Y)}function Gr(A){Vr(A),F.remove(A)}function Vr(A){const Y=F.get(A).programs;Y!==void 0&&(Y.forEach(function(ne){ie.releaseProgram(ne)}),A.isShaderMaterial&&ie.releaseShaderCache(A))}this.renderBufferDirect=function(A,Y,ne,J,j,Pe){Y===null&&(Y=vt);const Ie=j.isMesh&&j.matrixWorld.determinantAffine()<0,Re=Wp(A,Y,ne,J,j);y.setMaterial(J,Ie);let Be=ne.index,ze=1;if(J.wireframe===!0){if(Be=V.getWireframeAttribute(ne),Be===void 0)return;ze=2}const Ke=ne.drawRange,je=ne.attributes.position;let Ge=Ke.start*ze,mt=(Ke.start+Ke.count)*ze;Pe!==null&&(Ge=Math.max(Ge,Pe.start*ze),mt=Math.min(mt,(Pe.start+Pe.count)*ze)),Be!==null?(Ge=Math.max(Ge,0),mt=Math.min(mt,Be.count)):je!=null&&(Ge=Math.max(Ge,0),mt=Math.min(mt,je.count));const Pt=mt-Ge;if(Pt<0||Pt===1/0)return;Ce.setup(j,J,Re,ne,Be);let At,bt=xe;if(Be!==null&&(At=oe.get(Be),bt=le,bt.setIndex(At)),j.isMesh)J.wireframe===!0?(y.setLineWidth(J.wireframeLinewidth*ut()),bt.setMode(R.LINES)):bt.setMode(R.TRIANGLES);else if(j.isLine){let $t=J.linewidth;$t===void 0&&($t=1),y.setLineWidth($t*ut()),j.isLineSegments?bt.setMode(R.LINES):j.isLineLoop?bt.setMode(R.LINE_LOOP):bt.setMode(R.LINE_STRIP)}else j.isPoints?bt.setMode(R.POINTS):j.isSprite&&bt.setMode(R.TRIANGLES);if(j.isBatchedMesh)if(W.get("WEBGL_multi_draw"))bt.renderMultiDraw(j._multiDrawStarts,j._multiDrawCounts,j._multiDrawCount);else{const $t=j._multiDrawStarts,De=j._multiDrawCounts,fn=j._multiDrawCount,rt=Be?oe.get(Be).bytesPerElement:1,_n=F.get(J).currentProgram.getUniforms();for(let kn=0;kn<fn;kn++)_n.setValue(R,"_gl_DrawID",kn),bt.render($t[kn]/rt,De[kn])}else if(j.isInstancedMesh)bt.renderInstances(Ge,Pt,j.count);else if(ne.isInstancedBufferGeometry){const $t=ne._maxInstanceCount!==void 0?ne._maxInstanceCount:1/0,De=Math.min(ne.instanceCount,$t);bt.renderInstances(Ge,Pt,De)}else bt.render(Ge,Pt)};function ti(A,Y,ne){A.transparent===!0&&A.side===zt&&A.forceSinglePass===!1?(A.side=un,A.needsUpdate=!0,on(A,Y,ne),A.side=Ni,A.needsUpdate=!0,on(A,Y,ne),A.side=zt):on(A,Y,ne)}this.compile=function(A,Y,ne=null){ne===null&&(ne=A),b=ge.get(ne),b.init(Y),v.push(b),ne.traverseVisible(function(j){j.isLight&&j.layers.test(Y.layers)&&(b.pushLight(j),j.castShadow&&b.pushShadow(j))}),A!==ne&&A.traverseVisible(function(j){j.isLight&&j.layers.test(Y.layers)&&(b.pushLight(j),j.castShadow&&b.pushShadow(j))}),b.setupLights();const J=new Set;return A.traverse(function(j){if(!(j.isMesh||j.isPoints||j.isLine||j.isSprite))return;const Pe=j.material;if(Pe)if(Array.isArray(Pe))for(let Ie=0;Ie<Pe.length;Ie++){const Re=Pe[Ie];ti(Re,ne,j),J.add(Re)}else ti(Pe,ne,j),J.add(Pe)}),b=v.pop(),J},this.compileAsync=function(A,Y,ne=null){const J=this.compile(A,Y,ne);return new Promise(j=>{function Pe(){if(J.forEach(function(Ie){F.get(Ie).currentProgram.isReady()&&J.delete(Ie)}),J.size===0){j(A);return}setTimeout(Pe,10)}W.get("KHR_parallel_shader_compile")!==null?Pe():setTimeout(Pe,10)})};let cs=null;function us(A){cs&&cs(A)}function tr(){qt.stop()}function nr(){qt.start()}const qt=new xd;qt.setAnimationLoop(us),typeof self<"u"&&qt.setContext(self),this.setAnimationLoop=function(A){cs=A,Le.setAnimationLoop(A),A===null?qt.stop():qt.start()},Le.addEventListener("sessionstart",tr),Le.addEventListener("sessionend",nr),this.render=function(A,Y){if(Y!==void 0&&Y.isCamera!==!0){st("WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(L===!0)return;C!==null&&C.renderStart(A,Y);const ne=Le.enabled===!0&&Le.isPresenting===!0,J=w!==null&&($===null||ne)&&w.begin(I,$);if(A.matrixWorldAutoUpdate===!0&&A.updateMatrixWorld(),Y.parent===null&&Y.matrixWorldAutoUpdate===!0&&Y.updateMatrixWorld(),Le.enabled===!0&&Le.isPresenting===!0&&(w===null||w.isCompositing()===!1)&&(Le.cameraAutoUpdate===!0&&Le.updateCamera(Y),Y=Le.getCamera()),A.isScene===!0&&A.onBeforeRender(I,A,Y,$),b=ge.get(A,v.length),b.init(Y),b.state.textureUnits=G.getTextureUnits(),v.push(b),at.multiplyMatrices(Y.projectionMatrix,Y.matrixWorldInverse),Oe.setFromProjectionMatrix(at,$n,Y.reversedDepth),Ve=this.localClippingEnabled,Fe=Me.init(this.clippingPlanes,Ve),T=pe.get(A,S.length),T.init(),S.push(T),Le.enabled===!0&&Le.isPresenting===!0){const Ie=I.xr.getDepthSensingMesh();Ie!==null&&vn(Ie,Y,-1/0,I.sortObjects)}vn(A,Y,0,I.sortObjects),T.finish(),I.sortObjects===!0&&T.sort(ye,ve,Y.reversedDepth),ct=Le.enabled===!1||Le.isPresenting===!1||Le.hasDepthSensing()===!1,ct&&qe.addToRenderList(T,A),this.info.render.frame++,this.info.autoReset===!0&&this.info.reset(),Fe===!0&&Me.beginShadows();const j=b.state.shadowsArray;if(He.render(j,A,Y),Fe===!0&&Me.endShadows(),(J&&w.hasRenderPass())===!1){const Ie=T.opaque,Re=T.transmissive;if(b.setupLights(),Y.isArrayCamera){const Be=Y.cameras;if(Re.length>0)for(let ze=0,Ke=Be.length;ze<Ke;ze++){const je=Be[ze];hs(Ie,Re,A,je)}ct&&qe.render(A);for(let ze=0,Ke=Be.length;ze<Ke;ze++){const je=Be[ze];an(T,A,je,je.viewport)}}else Re.length>0&&hs(Ie,Re,A,Y),ct&&qe.render(A),an(T,A,Y)}$!==null&&k===0&&(G.updateMultisampleRenderTarget($),G.updateRenderTargetMipmap($)),J&&w.end(I),A.isScene===!0&&A.onAfterRender(I,A,Y),Ce.resetDefaultState(),D=-1,ae=null,v.pop(),v.length>0?(b=v[v.length-1],G.setTextureUnits(b.state.textureUnits),Fe===!0&&Me.setGlobalState(I.clippingPlanes,b.state.camera)):b=null,S.pop(),S.length>0?T=S[S.length-1]:T=null,C!==null&&C.renderEnd()};function vn(A,Y,ne,J){if(A.visible===!1)return;if(A.layers.test(Y.layers)){if(A.isGroup)ne=A.renderOrder;else if(A.isLOD)A.autoUpdate===!0&&A.update(Y);else if(A.isLightProbeGrid)b.pushLightProbeGrid(A);else if(A.isLight)b.pushLight(A),A.castShadow&&b.pushShadow(A);else if(A.isSprite){if(!A.frustumCulled||Oe.intersectsSprite(A)){J&&pt.setFromMatrixPosition(A.matrixWorld).applyMatrix4(at);const Ie=K.update(A),Re=A.material;Re.visible&&T.push(A,Ie,Re,ne,pt.z,null)}}else if((A.isMesh||A.isLine||A.isPoints)&&(!A.frustumCulled||Oe.intersectsObject(A))){const Ie=K.update(A),Re=A.material;if(J&&(A.boundingSphere!==void 0?(A.boundingSphere===null&&A.computeBoundingSphere(),pt.copy(A.boundingSphere.center)):(Ie.boundingSphere===null&&Ie.computeBoundingSphere(),pt.copy(Ie.boundingSphere.center)),pt.applyMatrix4(A.matrixWorld).applyMatrix4(at)),Array.isArray(Re)){const Be=Ie.groups;for(let ze=0,Ke=Be.length;ze<Ke;ze++){const je=Be[ze],Ge=Re[je.materialIndex];Ge&&Ge.visible&&T.push(A,Ie,Ge,ne,pt.z,je)}}else Re.visible&&T.push(A,Ie,Re,ne,pt.z,null)}}const Pe=A.children;for(let Ie=0,Re=Pe.length;Ie<Re;Ie++)vn(Pe[Ie],Y,ne,J)}function an(A,Y,ne,J){const{opaque:j,transmissive:Pe,transparent:Ie}=A;b.setupLightsView(ne),Fe===!0&&Me.setGlobalState(I.clippingPlanes,ne),J&&y.viewport(re.copy(J)),j.length>0&&xi(j,Y,ne),Pe.length>0&&xi(Pe,Y,ne),Ie.length>0&&xi(Ie,Y,ne),y.buffers.depth.setTest(!0),y.buffers.depth.setMask(!0),y.buffers.color.setMask(!0),y.setPolygonOffset(!1)}function hs(A,Y,ne,J){if((ne.isScene===!0?ne.overrideMaterial:null)!==null)return;if(b.state.transmissionRenderTarget[J.id]===void 0){const Ge=W.has("EXT_color_buffer_half_float")||W.has("EXT_color_buffer_float");b.state.transmissionRenderTarget[J.id]=new Jn(1,1,{generateMipmaps:!0,type:Ge?mi:Sn,minFilter:Di,samples:Math.max(4,P.samples),stencilBuffer:r,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:nt.workingColorSpace})}const Pe=b.state.transmissionRenderTarget[J.id],Ie=J.viewport||re;Pe.setSize(Ie.z*I.transmissionResolutionScale,Ie.w*I.transmissionResolutionScale);const Re=I.getRenderTarget(),Be=I.getActiveCubeFace(),ze=I.getActiveMipmapLevel();I.setRenderTarget(Pe),I.getClearColor(he),fe=I.getClearAlpha(),fe<1&&I.setClearColor(16777215,.5),I.clear(),ct&&qe.render(ne);const Ke=I.toneMapping;I.toneMapping=Kn;const je=J.viewport;if(J.viewport!==void 0&&(J.viewport=void 0),b.setupLightsView(J),Fe===!0&&Me.setGlobalState(I.clippingPlanes,J),xi(A,ne,J),G.updateMultisampleRenderTarget(Pe),G.updateRenderTargetMipmap(Pe),W.has("WEBGL_multisampled_render_to_texture")===!1){let Ge=!1;for(let mt=0,Pt=Y.length;mt<Pt;mt++){const At=Y[mt],{object:bt,geometry:$t,material:De,group:fn}=At;if(De.side===zt&&bt.layers.test(J.layers)){const rt=De.side;De.side=un,De.needsUpdate=!0,fs(bt,ne,J,$t,De,fn),De.side=rt,De.needsUpdate=!0,Ge=!0}}Ge===!0&&(G.updateMultisampleRenderTarget(Pe),G.updateRenderTargetMipmap(Pe))}I.setRenderTarget(Re,Be,ze),I.setClearColor(he,fe),je!==void 0&&(J.viewport=je),I.toneMapping=Ke}function xi(A,Y,ne){const J=Y.isScene===!0?Y.overrideMaterial:null;for(let j=0,Pe=A.length;j<Pe;j++){const Ie=A[j],{object:Re,geometry:Be,group:ze}=Ie;let Ke=Ie.material;Ke.allowOverride===!0&&J!==null&&(Ke=J),Re.layers.test(ne.layers)&&fs(Re,Y,ne,Be,Ke,ze)}}function fs(A,Y,ne,J,j,Pe){A.onBeforeRender(I,Y,ne,J,j,Pe),A.modelViewMatrix.multiplyMatrices(ne.matrixWorldInverse,A.matrixWorld),A.normalMatrix.getNormalMatrix(A.modelViewMatrix),j.onBeforeRender(I,Y,ne,J,A,Pe),j.transparent===!0&&j.side===zt&&j.forceSinglePass===!1?(j.side=un,j.needsUpdate=!0,I.renderBufferDirect(ne,Y,J,j,A,Pe),j.side=Ni,j.needsUpdate=!0,I.renderBufferDirect(ne,Y,J,j,A,Pe),j.side=zt):I.renderBufferDirect(ne,Y,J,j,A,Pe),A.onAfterRender(I,Y,ne,J,j,Pe)}function on(A,Y,ne){Y.isScene!==!0&&(Y=vt);const J=F.get(A),j=b.state.lights,Pe=b.state.shadowsArray,Ie=j.state.version,Re=ie.getParameters(A,j.state,Pe,Y,ne,b.state.lightProbeGridArray),Be=ie.getProgramCacheKey(Re);let ze=J.programs;J.environment=A.isMeshStandardMaterial||A.isMeshLambertMaterial||A.isMeshPhongMaterial?Y.environment:null,J.fog=Y.fog;const Ke=A.isMeshStandardMaterial||A.isMeshLambertMaterial&&!A.envMap||A.isMeshPhongMaterial&&!A.envMap;J.envMap=te.get(A.envMap||J.environment,Ke),J.envMapRotation=J.environment!==null&&A.envMap===null?Y.environmentRotation:A.envMapRotation,ze===void 0&&(A.addEventListener("dispose",Ut),ze=new Map,J.programs=ze);let je=ze.get(Be);if(je!==void 0){if(J.currentProgram===je&&J.lightsStateVersion===Ie)return yn(A,Re),je}else Re.uniforms=ie.getUniforms(A),C!==null&&A.isNodeMaterial&&C.build(A,ne,Re),A.onBeforeCompile(Re,I),je=ie.acquireProgram(Re,Be),ze.set(Be,je),J.uniforms=Re.uniforms;const Ge=J.uniforms;return(!A.isShaderMaterial&&!A.isRawShaderMaterial||A.clipping===!0)&&(Ge.clippingPlanes=Me.uniform),yn(A,Re),J.needsLights=Yp(A),J.lightsStateVersion=Ie,J.needsLights&&(Ge.ambientLightColor.value=j.state.ambient,Ge.lightProbe.value=j.state.probe,Ge.directionalLights.value=j.state.directional,Ge.directionalLightShadows.value=j.state.directionalShadow,Ge.spotLights.value=j.state.spot,Ge.spotLightShadows.value=j.state.spotShadow,Ge.rectAreaLights.value=j.state.rectArea,Ge.ltc_1.value=j.state.rectAreaLTC1,Ge.ltc_2.value=j.state.rectAreaLTC2,Ge.pointLights.value=j.state.point,Ge.pointLightShadows.value=j.state.pointShadow,Ge.hemisphereLights.value=j.state.hemi,Ge.directionalShadowMatrix.value=j.state.directionalShadowMatrix,Ge.spotLightMatrix.value=j.state.spotLightMatrix,Ge.spotLightMap.value=j.state.spotLightMap,Ge.pointShadowMatrix.value=j.state.pointShadowMatrix),J.lightProbeGrid=b.state.lightProbeGridArray.length>0,J.currentProgram=je,J.uniformsList=null,je}function Nn(A){if(A.uniformsList===null){const Y=A.currentProgram.getUniforms();A.uniformsList=Ba.seqWithValue(Y.seq,A.uniforms)}return A.uniformsList}function yn(A,Y){const ne=F.get(A);ne.outputColorSpace=Y.outputColorSpace,ne.batching=Y.batching,ne.batchingColor=Y.batchingColor,ne.instancing=Y.instancing,ne.instancingColor=Y.instancingColor,ne.instancingMorph=Y.instancingMorph,ne.skinning=Y.skinning,ne.morphTargets=Y.morphTargets,ne.morphNormals=Y.morphNormals,ne.morphColors=Y.morphColors,ne.morphTargetsCount=Y.morphTargetsCount,ne.numClippingPlanes=Y.numClippingPlanes,ne.numIntersection=Y.numClipIntersection,ne.vertexAlphas=Y.vertexAlphas,ne.vertexTangents=Y.vertexTangents,ne.toneMapping=Y.toneMapping}function Vp(A,Y){if(A.length===0)return null;if(A.length===1)return A[0].texture!==null?A[0]:null;_.setFromMatrixPosition(Y.matrixWorld);for(let ne=0,J=A.length;ne<J;ne++){const j=A[ne];if(j.texture!==null&&j.boundingBox.containsPoint(_))return j}return null}function Wp(A,Y,ne,J,j){Y.isScene!==!0&&(Y=vt),G.resetTextureUnits();const Pe=Y.fog,Ie=J.isMeshStandardMaterial||J.isMeshLambertMaterial||J.isMeshPhongMaterial?Y.environment:null,Re=$===null?I.outputColorSpace:$.isXRRenderTarget===!0?$.texture.colorSpace:nt.workingColorSpace,Be=J.isMeshStandardMaterial||J.isMeshLambertMaterial&&!J.envMap||J.isMeshPhongMaterial&&!J.envMap,ze=te.get(J.envMap||Ie,Be),Ke=J.vertexColors===!0&&!!ne.attributes.color&&ne.attributes.color.itemSize===4,je=!!ne.attributes.tangent&&(!!J.normalMap||J.anisotropy>0),Ge=!!ne.morphAttributes.position,mt=!!ne.morphAttributes.normal,Pt=!!ne.morphAttributes.color;let At=Kn;J.toneMapped&&($===null||$.isXRRenderTarget===!0)&&(At=I.toneMapping);const bt=ne.morphAttributes.position||ne.morphAttributes.normal||ne.morphAttributes.color,$t=bt!==void 0?bt.length:0,De=F.get(J),fn=b.state.lights;if(Fe===!0&&(Ve===!0||A!==ae)){const Mt=A===ae&&J.id===D;Me.setState(J,A,Mt)}let rt=!1;J.version===De.__version?(De.needsLights&&De.lightsStateVersion!==fn.state.version||De.outputColorSpace!==Re||j.isBatchedMesh&&De.batching===!1||!j.isBatchedMesh&&De.batching===!0||j.isBatchedMesh&&De.batchingColor===!0&&j.colorTexture===null||j.isBatchedMesh&&De.batchingColor===!1&&j.colorTexture!==null||j.isInstancedMesh&&De.instancing===!1||!j.isInstancedMesh&&De.instancing===!0||j.isSkinnedMesh&&De.skinning===!1||!j.isSkinnedMesh&&De.skinning===!0||j.isInstancedMesh&&De.instancingColor===!0&&j.instanceColor===null||j.isInstancedMesh&&De.instancingColor===!1&&j.instanceColor!==null||j.isInstancedMesh&&De.instancingMorph===!0&&j.morphTexture===null||j.isInstancedMesh&&De.instancingMorph===!1&&j.morphTexture!==null||De.envMap!==ze||J.fog===!0&&De.fog!==Pe||De.numClippingPlanes!==void 0&&(De.numClippingPlanes!==Me.numPlanes||De.numIntersection!==Me.numIntersection)||De.vertexAlphas!==Ke||De.vertexTangents!==je||De.morphTargets!==Ge||De.morphNormals!==mt||De.morphColors!==Pt||De.toneMapping!==At||De.morphTargetsCount!==$t||!!De.lightProbeGrid!=b.state.lightProbeGridArray.length>0)&&(rt=!0):(rt=!0,De.__version=J.version);let _n=De.currentProgram;rt===!0&&(_n=on(J,Y,j),C&&J.isNodeMaterial&&C.onUpdateProgram(J,_n,De));let kn=!1,vi=!1,ds=!1;const St=_n.getUniforms(),Lt=De.uniforms;if(y.useProgram(_n.program)&&(kn=!0,vi=!0,ds=!0),J.id!==D&&(D=J.id,vi=!0),De.needsLights){const Mt=Vp(b.state.lightProbeGridArray,j);De.lightProbeGrid!==Mt&&(De.lightProbeGrid=Mt,vi=!0)}if(kn||ae!==A){y.buffers.depth.getReversed()&&A.reversedDepth!==!0&&(A._reversedDepth=!0,A.updateProjectionMatrix()),St.setValue(R,"projectionMatrix",A.projectionMatrix),St.setValue(R,"viewMatrix",A.matrixWorldInverse);const _i=St.map.cameraPosition;_i!==void 0&&_i.setValue(R,ot.setFromMatrixPosition(A.matrixWorld)),P.logarithmicDepthBuffer&&St.setValue(R,"logDepthBufFC",2/(Math.log(A.far+1)/Math.LN2)),(J.isMeshPhongMaterial||J.isMeshToonMaterial||J.isMeshLambertMaterial||J.isMeshBasicMaterial||J.isMeshStandardMaterial||J.isShaderMaterial)&&St.setValue(R,"isOrthographic",A.isOrthographicCamera===!0),ae!==A&&(ae=A,vi=!0,ds=!0)}if(De.needsLights&&(fn.state.directionalShadowMap.length>0&&St.setValue(R,"directionalShadowMap",fn.state.directionalShadowMap,G),fn.state.spotShadowMap.length>0&&St.setValue(R,"spotShadowMap",fn.state.spotShadowMap,G),fn.state.pointShadowMap.length>0&&St.setValue(R,"pointShadowMap",fn.state.pointShadowMap,G)),j.isSkinnedMesh){St.setOptional(R,j,"bindMatrix"),St.setOptional(R,j,"bindMatrixInverse");const Mt=j.skeleton;Mt&&(Mt.boneTexture===null&&Mt.computeBoneTexture(),St.setValue(R,"boneTexture",Mt.boneTexture,G))}j.isBatchedMesh&&(St.setOptional(R,j,"batchingTexture"),St.setValue(R,"batchingTexture",j._matricesTexture,G),St.setOptional(R,j,"batchingIdTexture"),St.setValue(R,"batchingIdTexture",j._indirectTexture,G),St.setOptional(R,j,"batchingColorTexture"),j._colorsTexture!==null&&St.setValue(R,"batchingColorTexture",j._colorsTexture,G));const yi=ne.morphAttributes;if((yi.position!==void 0||yi.normal!==void 0||yi.color!==void 0)&&z.update(j,ne,_n),(vi||De.receiveShadow!==j.receiveShadow)&&(De.receiveShadow=j.receiveShadow,St.setValue(R,"receiveShadow",j.receiveShadow)),(J.isMeshStandardMaterial||J.isMeshLambertMaterial||J.isMeshPhongMaterial)&&J.envMap===null&&Y.environment!==null&&(Lt.envMapIntensity.value=Y.environmentIntensity),Lt.dfgLUT!==void 0&&(Lt.dfgLUT.value=H_()),vi){if(St.setValue(R,"toneMappingExposure",I.toneMappingExposure),De.needsLights&&Xp(Lt,ds),Pe&&J.fog===!0&&de.refreshFogUniforms(Lt,Pe),de.refreshMaterialUniforms(Lt,J,Q,se,b.state.transmissionRenderTarget[A.id]),De.needsLights&&De.lightProbeGrid){const Mt=De.lightProbeGrid;Lt.probesSH.value=Mt.texture,Lt.probesMin.value.copy(Mt.boundingBox.min),Lt.probesMax.value.copy(Mt.boundingBox.max),Lt.probesResolution.value.copy(Mt.resolution)}Ba.upload(R,Nn(De),Lt,G)}if(J.isShaderMaterial&&J.uniformsNeedUpdate===!0&&(Ba.upload(R,Nn(De),Lt,G),J.uniformsNeedUpdate=!1),J.isSpriteMaterial&&St.setValue(R,"center",j.center),St.setValue(R,"modelViewMatrix",j.modelViewMatrix),St.setValue(R,"normalMatrix",j.normalMatrix),St.setValue(R,"modelMatrix",j.matrixWorld),J.uniformsGroups!==void 0){const Mt=J.uniformsGroups;for(let _i=0,ps=Mt.length;_i<ps;_i++){const hu=Mt[_i];ue.update(hu,_n),ue.bind(hu,_n)}}return _n}function Xp(A,Y){A.ambientLightColor.needsUpdate=Y,A.lightProbe.needsUpdate=Y,A.directionalLights.needsUpdate=Y,A.directionalLightShadows.needsUpdate=Y,A.pointLights.needsUpdate=Y,A.pointLightShadows.needsUpdate=Y,A.spotLights.needsUpdate=Y,A.spotLightShadows.needsUpdate=Y,A.rectAreaLights.needsUpdate=Y,A.hemisphereLights.needsUpdate=Y}function Yp(A){return A.isMeshLambertMaterial||A.isMeshToonMaterial||A.isMeshPhongMaterial||A.isMeshStandardMaterial||A.isShadowMaterial||A.isShaderMaterial&&A.lights===!0}this.getActiveCubeFace=function(){return Z},this.getActiveMipmapLevel=function(){return k},this.getRenderTarget=function(){return $},this.setRenderTargetTextures=function(A,Y,ne){const J=F.get(A);J.__autoAllocateDepthBuffer=A.resolveDepthBuffer===!1,J.__autoAllocateDepthBuffer===!1&&(J.__useRenderToTexture=!1),F.get(A.texture).__webglTexture=Y,F.get(A.depthTexture).__webglTexture=J.__autoAllocateDepthBuffer?void 0:ne,J.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(A,Y){const ne=F.get(A);ne.__webglFramebuffer=Y,ne.__useDefaultFramebuffer=Y===void 0},this.setRenderTarget=function(A,Y=0,ne=0){$=A,Z=Y,k=ne;let J=null,j=!1,Pe=!1;if(A){const Re=F.get(A);if(Re.__useDefaultFramebuffer!==void 0){y.bindFramebuffer(R.FRAMEBUFFER,Re.__webglFramebuffer),re.copy(A.viewport),ee.copy(A.scissor),ce=A.scissorTest,y.viewport(re),y.scissor(ee),y.setScissorTest(ce),D=-1;return}else if(Re.__webglFramebuffer===void 0)G.setupRenderTarget(A);else if(Re.__hasExternalTextures)G.rebindTextures(A,F.get(A.texture).__webglTexture,F.get(A.depthTexture).__webglTexture);else if(A.depthBuffer){const Ke=A.depthTexture;if(Re.__boundDepthTexture!==Ke){if(Ke!==null&&F.has(Ke)&&(A.width!==Ke.image.width||A.height!==Ke.image.height))throw new Error("THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.");G.setupDepthRenderbuffer(A)}}const Be=A.texture;(Be.isData3DTexture||Be.isDataArrayTexture||Be.isCompressedArrayTexture)&&(Pe=!0);const ze=F.get(A).__webglFramebuffer;A.isWebGLCubeRenderTarget?(Array.isArray(ze[Y])?J=ze[Y][ne]:J=ze[Y],j=!0):A.samples>0&&G.useMultisampledRTT(A)===!1?J=F.get(A).__webglMultisampledFramebuffer:Array.isArray(ze)?J=ze[ne]:J=ze,re.copy(A.viewport),ee.copy(A.scissor),ce=A.scissorTest}else re.copy(_e).multiplyScalar(Q).floor(),ee.copy(Ze).multiplyScalar(Q).floor(),ce=Ye;if(ne!==0&&(J=O),y.bindFramebuffer(R.FRAMEBUFFER,J)&&y.drawBuffers(A,J),y.viewport(re),y.scissor(ee),y.setScissorTest(ce),j){const Re=F.get(A.texture);R.framebufferTexture2D(R.FRAMEBUFFER,R.COLOR_ATTACHMENT0,R.TEXTURE_CUBE_MAP_POSITIVE_X+Y,Re.__webglTexture,ne)}else if(Pe){const Re=Y;for(let Be=0;Be<A.textures.length;Be++){const ze=F.get(A.textures[Be]);R.framebufferTextureLayer(R.FRAMEBUFFER,R.COLOR_ATTACHMENT0+Be,ze.__webglTexture,ne,Re)}}else if(A!==null&&ne!==0){const Re=F.get(A.texture);R.framebufferTexture2D(R.FRAMEBUFFER,R.COLOR_ATTACHMENT0,R.TEXTURE_2D,Re.__webglTexture,ne)}D=-1},this.readRenderTargetPixels=function(A,Y,ne,J,j,Pe,Ie,Re=0){if(!(A&&A.isWebGLRenderTarget)){st("WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let Be=F.get(A).__webglFramebuffer;if(A.isWebGLCubeRenderTarget&&Ie!==void 0&&(Be=Be[Ie]),Be){y.bindFramebuffer(R.FRAMEBUFFER,Be);try{const ze=A.textures[Re],Ke=ze.format,je=ze.type;if(A.textures.length>1&&R.readBuffer(R.COLOR_ATTACHMENT0+Re),!P.textureFormatReadable(Ke)){st("WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!P.textureTypeReadable(je)){st("WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}Y>=0&&Y<=A.width-J&&ne>=0&&ne<=A.height-j&&R.readPixels(Y,ne,J,j,be.convert(Ke),be.convert(je),Pe)}finally{const ze=$!==null?F.get($).__webglFramebuffer:null;y.bindFramebuffer(R.FRAMEBUFFER,ze)}}},this.readRenderTargetPixelsAsync=async function(A,Y,ne,J,j,Pe,Ie,Re=0){if(!(A&&A.isWebGLRenderTarget))throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let Be=F.get(A).__webglFramebuffer;if(A.isWebGLCubeRenderTarget&&Ie!==void 0&&(Be=Be[Ie]),Be)if(Y>=0&&Y<=A.width-J&&ne>=0&&ne<=A.height-j){y.bindFramebuffer(R.FRAMEBUFFER,Be);const ze=A.textures[Re],Ke=ze.format,je=ze.type;if(A.textures.length>1&&R.readBuffer(R.COLOR_ATTACHMENT0+Re),!P.textureFormatReadable(Ke))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!P.textureTypeReadable(je))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const Ge=R.createBuffer();R.bindBuffer(R.PIXEL_PACK_BUFFER,Ge),R.bufferData(R.PIXEL_PACK_BUFFER,Pe.byteLength,R.STREAM_READ),R.readPixels(Y,ne,J,j,be.convert(Ke),be.convert(je),0);const mt=$!==null?F.get($).__webglFramebuffer:null;y.bindFramebuffer(R.FRAMEBUFFER,mt);const Pt=R.fenceSync(R.SYNC_GPU_COMMANDS_COMPLETE,0);return R.flush(),await Rm(R,Pt,4),R.bindBuffer(R.PIXEL_PACK_BUFFER,Ge),R.getBufferSubData(R.PIXEL_PACK_BUFFER,0,Pe),R.deleteBuffer(Ge),R.deleteSync(Pt),Pe}else throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")},this.copyFramebufferToTexture=function(A,Y=null,ne=0){const J=Math.pow(2,-ne),j=Math.floor(A.image.width*J),Pe=Math.floor(A.image.height*J),Ie=Y!==null?Y.x:0,Re=Y!==null?Y.y:0;G.setTexture2D(A,0),R.copyTexSubImage2D(R.TEXTURE_2D,ne,0,0,Ie,Re,j,Pe),y.unbindTexture()},this.copyTextureToTexture=function(A,Y,ne=null,J=null,j=0,Pe=0){let Ie,Re,Be,ze,Ke,je,Ge,mt,Pt;const At=A.isCompressedTexture?A.mipmaps[Pe]:A.image;if(ne!==null)Ie=ne.max.x-ne.min.x,Re=ne.max.y-ne.min.y,Be=ne.isBox3?ne.max.z-ne.min.z:1,ze=ne.min.x,Ke=ne.min.y,je=ne.isBox3?ne.min.z:0;else{const Lt=Math.pow(2,-j);Ie=Math.floor(At.width*Lt),Re=Math.floor(At.height*Lt),A.isDataArrayTexture?Be=At.depth:A.isData3DTexture?Be=Math.floor(At.depth*Lt):Be=1,ze=0,Ke=0,je=0}J!==null?(Ge=J.x,mt=J.y,Pt=J.z):(Ge=0,mt=0,Pt=0);const bt=be.convert(Y.format),$t=be.convert(Y.type);let De;Y.isData3DTexture?(G.setTexture3D(Y,0),De=R.TEXTURE_3D):Y.isDataArrayTexture||Y.isCompressedArrayTexture?(G.setTexture2DArray(Y,0),De=R.TEXTURE_2D_ARRAY):(G.setTexture2D(Y,0),De=R.TEXTURE_2D),y.activeTexture(R.TEXTURE0),y.pixelStorei(R.UNPACK_FLIP_Y_WEBGL,Y.flipY),y.pixelStorei(R.UNPACK_PREMULTIPLY_ALPHA_WEBGL,Y.premultiplyAlpha),y.pixelStorei(R.UNPACK_ALIGNMENT,Y.unpackAlignment);const fn=y.getParameter(R.UNPACK_ROW_LENGTH),rt=y.getParameter(R.UNPACK_IMAGE_HEIGHT),_n=y.getParameter(R.UNPACK_SKIP_PIXELS),kn=y.getParameter(R.UNPACK_SKIP_ROWS),vi=y.getParameter(R.UNPACK_SKIP_IMAGES);y.pixelStorei(R.UNPACK_ROW_LENGTH,At.width),y.pixelStorei(R.UNPACK_IMAGE_HEIGHT,At.height),y.pixelStorei(R.UNPACK_SKIP_PIXELS,ze),y.pixelStorei(R.UNPACK_SKIP_ROWS,Ke),y.pixelStorei(R.UNPACK_SKIP_IMAGES,je);const ds=A.isDataArrayTexture||A.isData3DTexture,St=Y.isDataArrayTexture||Y.isData3DTexture;if(A.isDepthTexture){const Lt=F.get(A),yi=F.get(Y),Mt=F.get(Lt.__renderTarget),_i=F.get(yi.__renderTarget);y.bindFramebuffer(R.READ_FRAMEBUFFER,Mt.__webglFramebuffer),y.bindFramebuffer(R.DRAW_FRAMEBUFFER,_i.__webglFramebuffer);for(let ps=0;ps<Be;ps++)ds&&(R.framebufferTextureLayer(R.READ_FRAMEBUFFER,R.COLOR_ATTACHMENT0,F.get(A).__webglTexture,j,je+ps),R.framebufferTextureLayer(R.DRAW_FRAMEBUFFER,R.COLOR_ATTACHMENT0,F.get(Y).__webglTexture,Pe,Pt+ps)),R.blitFramebuffer(ze,Ke,Ie,Re,Ge,mt,Ie,Re,R.DEPTH_BUFFER_BIT,R.NEAREST);y.bindFramebuffer(R.READ_FRAMEBUFFER,null),y.bindFramebuffer(R.DRAW_FRAMEBUFFER,null)}else if(j!==0||A.isRenderTargetTexture||F.has(A)){const Lt=F.get(A),yi=F.get(Y);y.bindFramebuffer(R.READ_FRAMEBUFFER,N),y.bindFramebuffer(R.DRAW_FRAMEBUFFER,U);for(let Mt=0;Mt<Be;Mt++)ds?R.framebufferTextureLayer(R.READ_FRAMEBUFFER,R.COLOR_ATTACHMENT0,Lt.__webglTexture,j,je+Mt):R.framebufferTexture2D(R.READ_FRAMEBUFFER,R.COLOR_ATTACHMENT0,R.TEXTURE_2D,Lt.__webglTexture,j),St?R.framebufferTextureLayer(R.DRAW_FRAMEBUFFER,R.COLOR_ATTACHMENT0,yi.__webglTexture,Pe,Pt+Mt):R.framebufferTexture2D(R.DRAW_FRAMEBUFFER,R.COLOR_ATTACHMENT0,R.TEXTURE_2D,yi.__webglTexture,Pe),j!==0?R.blitFramebuffer(ze,Ke,Ie,Re,Ge,mt,Ie,Re,R.COLOR_BUFFER_BIT,R.NEAREST):St?R.copyTexSubImage3D(De,Pe,Ge,mt,Pt+Mt,ze,Ke,Ie,Re):R.copyTexSubImage2D(De,Pe,Ge,mt,ze,Ke,Ie,Re);y.bindFramebuffer(R.READ_FRAMEBUFFER,null),y.bindFramebuffer(R.DRAW_FRAMEBUFFER,null)}else St?A.isDataTexture||A.isData3DTexture?R.texSubImage3D(De,Pe,Ge,mt,Pt,Ie,Re,Be,bt,$t,At.data):Y.isCompressedArrayTexture?R.compressedTexSubImage3D(De,Pe,Ge,mt,Pt,Ie,Re,Be,bt,At.data):R.texSubImage3D(De,Pe,Ge,mt,Pt,Ie,Re,Be,bt,$t,At):A.isDataTexture?R.texSubImage2D(R.TEXTURE_2D,Pe,Ge,mt,Ie,Re,bt,$t,At.data):A.isCompressedTexture?R.compressedTexSubImage2D(R.TEXTURE_2D,Pe,Ge,mt,At.width,At.height,bt,At.data):R.texSubImage2D(R.TEXTURE_2D,Pe,Ge,mt,Ie,Re,bt,$t,At);y.pixelStorei(R.UNPACK_ROW_LENGTH,fn),y.pixelStorei(R.UNPACK_IMAGE_HEIGHT,rt),y.pixelStorei(R.UNPACK_SKIP_PIXELS,_n),y.pixelStorei(R.UNPACK_SKIP_ROWS,kn),y.pixelStorei(R.UNPACK_SKIP_IMAGES,vi),Pe===0&&Y.generateMipmaps&&R.generateMipmap(De),y.unbindTexture()},this.initRenderTarget=function(A){F.get(A).__webglFramebuffer===void 0&&G.setupRenderTarget(A)},this.initTexture=function(A){A.isCubeTexture?G.setTextureCube(A,0):A.isData3DTexture?G.setTexture3D(A,0):A.isDataArrayTexture||A.isCompressedArrayTexture?G.setTexture2DArray(A,0):G.setTexture2D(A,0),y.unbindTexture()},this.resetState=function(){Z=0,k=0,$=null,y.reset(),Ce.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return $n}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=nt._getDrawingBufferColorSpace(e),t.unpackColorSpace=nt._getUnpackColorSpace()}}const Mh={type:"change"},Vc={type:"start"},Td={type:"end"},ba=new kc,Eh=new Ri,G_=Math.cos(70*Dm.DEG2RAD),Ot=new B,ln=2*Math.PI,xt={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},al=1e-6;class V_ extends Xg{constructor(e,t=null){super(e,t),this.state=xt.NONE,this.target=new B,this.cursor=new B,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:ui.ROTATE,MIDDLE:ui.DOLLY,RIGHT:ui.PAN},this.touches={ONE:Li.ROTATE,TWO:Li.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle="auto",this._domElementKeyEvents=null,this._lastPosition=new B,this._lastQuaternion=new ki,this._lastTargetPosition=new B,this._quat=new ki().setFromUnitVectors(e.up,new B(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Ju,this._sphericalDelta=new Ju,this._scale=1,this._panOffset=new B,this._rotateStart=new Ee,this._rotateEnd=new Ee,this._rotateDelta=new Ee,this._panStart=new Ee,this._panEnd=new Ee,this._panDelta=new Ee,this._dollyStart=new Ee,this._dollyEnd=new Ee,this._dollyDelta=new Ee,this._dollyDirection=new B,this._mouse=new Ee,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=X_.bind(this),this._onPointerDown=W_.bind(this),this._onPointerUp=Y_.bind(this),this._onContextMenu=Q_.bind(this),this._onMouseWheel=Z_.bind(this),this._onKeyDown=K_.bind(this),this._onTouchStart=J_.bind(this),this._onTouchMove=j_.bind(this),this._onMouseDown=q_.bind(this),this._onMouseMove=$_.bind(this),this._interceptControlDown=eb.bind(this),this._interceptControlUp=tb.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e==="grab"?this.domElement.style.cursor="grab":this.domElement.style.cursor="auto"}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=""}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(Mh),this.update(),this.state=xt.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(e=null){const t=this.object.position;Ot.copy(t).sub(this.target),Ot.applyQuaternion(this._quat),this._spherical.setFromVector3(Ot),this.autoRotate&&this.state===xt.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let i=this.minAzimuthAngle,s=this.maxAzimuthAngle;isFinite(i)&&isFinite(s)&&(i<-Math.PI?i+=ln:i>Math.PI&&(i-=ln),s<-Math.PI?s+=ln:s>Math.PI&&(s-=ln),i<=s?this._spherical.theta=Math.max(i,Math.min(s,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(i+s)/2?Math.max(i,this._spherical.theta):Math.min(s,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let r=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const a=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),r=a!=this._spherical.radius}if(Ot.setFromSpherical(this._spherical),Ot.applyQuaternion(this._quatInverse),t.copy(this.target).add(Ot),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let a=null;if(this.object.isPerspectiveCamera){const o=Ot.length();a=this._clampDistance(o*this._scale);const l=o-a;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),r=!!l}else if(this.object.isOrthographicCamera){const o=new B(this._mouse.x,this._mouse.y,0);o.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),r=l!==this.object.zoom;const c=new B(this._mouse.x,this._mouse.y,0);c.unproject(this.object),this.object.position.sub(c).add(o),this.object.updateMatrixWorld(),a=Ot.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;a!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(a).add(this.object.position):(ba.origin.copy(this.object.position),ba.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(ba.direction))<G_?this.object.lookAt(this.target):(Eh.setFromNormalAndCoplanarPoint(this.object.up,this.target),ba.intersectPlane(Eh,this.target))))}else if(this.object.isOrthographicCamera){const a=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),a!==this.object.zoom&&(this.object.updateProjectionMatrix(),r=!0)}return this._scale=1,this._performCursorZoom=!1,r||this._lastPosition.distanceToSquared(this.object.position)>al||8*(1-this._lastQuaternion.dot(this.object.quaternion))>al||this._lastTargetPosition.distanceToSquared(this.target)>al?(this.dispatchEvent(Mh),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?ln/60*this.autoRotateSpeed*e:ln/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){Ot.setFromMatrixColumn(t,0),Ot.multiplyScalar(-e),this._panOffset.add(Ot)}_panUp(e,t){this.screenSpacePanning===!0?Ot.setFromMatrixColumn(t,1):(Ot.setFromMatrixColumn(t,0),Ot.crossVectors(this.object.up,Ot)),Ot.multiplyScalar(e),this._panOffset.add(Ot)}_pan(e,t){const i=this.domElement;if(this.object.isPerspectiveCamera){const s=this.object.position;Ot.copy(s).sub(this.target);let r=Ot.length();r*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*r/i.clientHeight,this.object.matrix),this._panUp(2*t*r/i.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/i.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/i.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const i=this.domElement.getBoundingClientRect(),s=e-i.left,r=t-i.top,a=i.width,o=i.height;this._mouse.x=s/a*2-1,this._mouse.y=-(r/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(ln*this._rotateDelta.x/t.clientHeight),this._rotateUp(ln*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(ln*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-ln*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(ln*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-ln*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),i=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._rotateStart.set(i,s)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),i=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panStart.set(i,s)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),i=e.pageX-t.x,s=e.pageY-t.y,r=Math.sqrt(i*i+s*s);this._dollyStart.set(0,r)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const i=this._getSecondPointerPosition(e),s=.5*(e.pageX+i.x),r=.5*(e.pageY+i.y);this._rotateEnd.set(s,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(ln*this._rotateDelta.x/t.clientHeight),this._rotateUp(ln*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),i=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panEnd.set(i,s)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),i=e.pageX-t.x,s=e.pageY-t.y,r=Math.sqrt(i*i+s*s);this._dollyEnd.set(0,r),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const a=(e.pageX+t.x)*.5,o=(e.pageY+t.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new Ee,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,i={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:i.deltaY*=16;break;case 2:i.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(i.deltaY*=10),i}}function W_(n){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(n.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(n)&&(this._addPointer(n),n.pointerType==="touch"?this._onTouchStart(n):this._onMouseDown(n),this._cursorStyle==="grab"&&(this.domElement.style.cursor="grabbing")))}function X_(n){this.enabled!==!1&&(n.pointerType==="touch"?this._onTouchMove(n):this._onMouseMove(n))}function Y_(n){switch(this._removePointer(n),this._pointers.length){case 0:this.domElement.releasePointerCapture(n.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Td),this.state=xt.NONE,this._cursorStyle==="grab"&&(this.domElement.style.cursor="grab");break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function q_(n){let e;switch(n.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case ui.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(n),this.state=xt.DOLLY;break;case ui.ROTATE:if(n.ctrlKey||n.metaKey||n.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(n),this.state=xt.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(n),this.state=xt.ROTATE}break;case ui.PAN:if(n.ctrlKey||n.metaKey||n.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(n),this.state=xt.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(n),this.state=xt.PAN}break;default:this.state=xt.NONE}this.state!==xt.NONE&&this.dispatchEvent(Vc)}function $_(n){switch(this.state){case xt.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(n);break;case xt.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(n);break;case xt.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(n);break}}function Z_(n){this.enabled===!1||this.enableZoom===!1||this.state!==xt.NONE||(n.preventDefault(),this.dispatchEvent(Vc),this._handleMouseWheel(this._customWheelEvent(n)),this.dispatchEvent(Td))}function K_(n){this.enabled!==!1&&this._handleKeyDown(n)}function J_(n){switch(this._trackPointer(n),this._pointers.length){case 1:switch(this.touches.ONE){case Li.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(n),this.state=xt.TOUCH_ROTATE;break;case Li.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(n),this.state=xt.TOUCH_PAN;break;default:this.state=xt.NONE}break;case 2:switch(this.touches.TWO){case Li.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(n),this.state=xt.TOUCH_DOLLY_PAN;break;case Li.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(n),this.state=xt.TOUCH_DOLLY_ROTATE;break;default:this.state=xt.NONE}break;default:this.state=xt.NONE}this.state!==xt.NONE&&this.dispatchEvent(Vc)}function j_(n){switch(this._trackPointer(n),this.state){case xt.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(n),this.update();break;case xt.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(n),this.update();break;case xt.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(n),this.update();break;case xt.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(n),this.update();break;default:this.state=xt.NONE}}function Q_(n){this.enabled!==!1&&n.preventDefault()}function eb(n){n.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function tb(n){n.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function nb(n,e,t){const i=(1-Math.abs(2*t-1))*e,s=i*(1-Math.abs(n/60%2-1)),r=t-i/2;let a,o,l;return n<60?(a=i,o=s,l=0):n<120?(a=s,o=i,l=0):n<180?(a=0,o=i,l=s):n<240?(a=0,o=s,l=i):n<300?(a=s,o=0,l=i):(a=i,o=0,l=s),Math.round((a+r)*255)*65536+Math.round((o+r)*255)*256+Math.round((l+r)*255)}const ib=[null,16711680,16776960,65280,65535,255,16711935,16777215,4276545,8421504],sb=[[1,.5],[1,.28],[.65,.65],[.65,.38],[.35,.8],[.35,.48],[.18,.68],[.18,.38],[0,.55],[0,.3]];function Sa(n){if(n==null||n===0||n===256)return null;if(n<=9)return ib[n]??null;if(n>=250&&n<=255){const e=Math.round(40+(n-250)*43);return e*65536+e*256+e}if(n>=10&&n<=249){const e=n-10,[t,i]=sb[e%10];return nb(Math.floor(e/10)*15,t,i)}return 13226457}function Wc(n){if(n==null)return null;if(typeof n=="object"&&n!==null&&"value"in n){const e=n.value;if(typeof e=="number"&&Number.isFinite(e))return e.toString(16);if(typeof e=="string"&&e.length){const t=Number(e);return Number.isFinite(t)?t.toString(16):e.toLowerCase()}return null}if(typeof n=="number"&&Number.isFinite(n))return n.toString(16);if(typeof n=="string"&&n.length){const e=Number(n);return Number.isFinite(e)?e.toString(16):n.toLowerCase()}return null}function Ad(n){return Wc(n.ownerHandle)}function rb(n){const e=n.toLowerCase().replace(/\*/g,"").trim();return e?e==="model_space"||e==="ms"||e.startsWith("model")?"model":e==="paper_space"||e==="ps"||e.startsWith("paper")?"paper":null:null}function ab(n,e,t){return n==="model"?"Model":n==="paper"?t<=1?"Layout":`Layout (${e.replace(/^\*/,"")})`:e}function Sr(n){var a;const e=((a=n==null?void 0:n.tables)==null?void 0:a.blocks)??[],t=(n==null?void 0:n.entities)??[],i=new Map;for(const o of t){const l=Ad(o);l&&i.set(l,(i.get(l)||0)+1)}const s=[];let r=0;for(const o of e){const l=rb(o.name??"");if(!l)continue;const c=Wc(o.handle);if(!c)continue;l==="paper"&&(r+=1);const u=typeof o.handle=="number"?o.handle:typeof o.handle=="object"&&o.handle&&"value"in o.handle?Number(o.handle.value):null;s.push({id:c,label:ab(l,o.name??"",r),name:o.name??"",handle:Number.isFinite(u)?u:null,handleHex:c,kind:l,entityCount:i.get(c)||0})}return s.sort((o,l)=>{if(o.kind!==l.kind){if(o.kind==="model")return-1;if(l.kind==="model")return 1}return 0}),s}function ob(n){if(!n.length)return null;const e=n.find(i=>i.kind==="paper"&&i.entityCount>0);if(e)return e;const t=n.find(i=>i.kind==="model");return t||(n[0]??null)}function ol(n,e,t=3){const i=new Set([e]);for(let s=0;s<t;s++){let r=!1;for(const a of n){const o=Ad(a);if(!o||!i.has(o))continue;const l=Wc(a.handle);l&&!i.has(l)&&(i.add(l),r=!0)}if(!r)break}return i}var Xc=0,wd=-3;function Pr(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function lb(n,e){this.source=n,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=e,this.destLen=0,this.ltree=new Pr,this.dtree=new Pr}var Cd=new Pr,Rd=new Pr,Yc=new Uint8Array(30),qc=new Uint16Array(30),Pd=new Uint8Array(30),Ld=new Uint16Array(30),cb=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Th=new Pr,zn=new Uint8Array(320);function Dd(n,e,t,i){var s,r;for(s=0;s<t;++s)n[s]=0;for(s=0;s<30-t;++s)n[s+t]=s/t|0;for(r=i,s=0;s<30;++s)e[s]=r,r+=1<<n[s]}function ub(n,e){var t;for(t=0;t<7;++t)n.table[t]=0;for(n.table[7]=24,n.table[8]=152,n.table[9]=112,t=0;t<24;++t)n.trans[t]=256+t;for(t=0;t<144;++t)n.trans[24+t]=t;for(t=0;t<8;++t)n.trans[168+t]=280+t;for(t=0;t<112;++t)n.trans[176+t]=144+t;for(t=0;t<5;++t)e.table[t]=0;for(e.table[5]=32,t=0;t<32;++t)e.trans[t]=t}var Ah=new Uint16Array(16);function ll(n,e,t,i){var s,r;for(s=0;s<16;++s)n.table[s]=0;for(s=0;s<i;++s)n.table[e[t+s]]++;for(n.table[0]=0,r=0,s=0;s<16;++s)Ah[s]=r,r+=n.table[s];for(s=0;s<i;++s)e[t+s]&&(n.trans[Ah[e[t+s]]++]=s)}function hb(n){n.bitcount--||(n.tag=n.source[n.sourceIndex++],n.bitcount=7);var e=n.tag&1;return n.tag>>>=1,e}function Xn(n,e,t){if(!e)return t;for(;n.bitcount<24;)n.tag|=n.source[n.sourceIndex++]<<n.bitcount,n.bitcount+=8;var i=n.tag&65535>>>16-e;return n.tag>>>=e,n.bitcount-=e,i+t}function xc(n,e){for(;n.bitcount<24;)n.tag|=n.source[n.sourceIndex++]<<n.bitcount,n.bitcount+=8;var t=0,i=0,s=0,r=n.tag;do i=2*i+(r&1),r>>>=1,++s,t+=e.table[s],i-=e.table[s];while(i>=0);return n.tag=r,n.bitcount-=s,e.trans[t+i]}function fb(n,e,t){var i,s,r,a,o,l;for(i=Xn(n,5,257),s=Xn(n,5,1),r=Xn(n,4,4),a=0;a<19;++a)zn[a]=0;for(a=0;a<r;++a){var c=Xn(n,3,0);zn[cb[a]]=c}for(ll(Th,zn,0,19),o=0;o<i+s;){var u=xc(n,Th);switch(u){case 16:var f=zn[o-1];for(l=Xn(n,2,3);l;--l)zn[o++]=f;break;case 17:for(l=Xn(n,3,3);l;--l)zn[o++]=0;break;case 18:for(l=Xn(n,7,11);l;--l)zn[o++]=0;break;default:zn[o++]=u;break}}ll(e,zn,0,i),ll(t,zn,i,s)}function wh(n,e,t){for(;;){var i=xc(n,e);if(i===256)return Xc;if(i<256)n.dest[n.destLen++]=i;else{var s,r,a,o;for(i-=257,s=Xn(n,Yc[i],qc[i]),r=xc(n,t),a=n.destLen-Xn(n,Pd[r],Ld[r]),o=a;o<a+s;++o)n.dest[n.destLen++]=n.dest[o]}}}function db(n){for(var e,t,i;n.bitcount>8;)n.sourceIndex--,n.bitcount-=8;if(e=n.source[n.sourceIndex+1],e=256*e+n.source[n.sourceIndex],t=n.source[n.sourceIndex+3],t=256*t+n.source[n.sourceIndex+2],e!==(~t&65535))return wd;for(n.sourceIndex+=4,i=e;i;--i)n.dest[n.destLen++]=n.source[n.sourceIndex++];return n.bitcount=0,Xc}function Id(n,e){var t=new lb(n,e),i,s,r;do{switch(i=hb(t),s=Xn(t,2,0),s){case 0:r=db(t);break;case 1:r=wh(t,Cd,Rd);break;case 2:fb(t,t.ltree,t.dtree),r=wh(t,t.ltree,t.dtree);break;default:r=wd}if(r!==Xc)throw new Error("Data error")}while(!i);return t.destLen<t.dest.length?typeof t.dest.slice=="function"?t.dest.slice(0,t.destLen):t.dest.subarray(0,t.destLen):t.dest}ub(Cd,Rd);Dd(Yc,qc,4,3);Dd(Pd,Ld,2,1);Yc[28]=0;qc[28]=258;function Is(n,e,t,i,s){return Math.pow(1-s,3)*n+3*Math.pow(1-s,2)*s*e+3*(1-s)*Math.pow(s,2)*t+Math.pow(s,3)*i}function as(){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN}as.prototype.isEmpty=function(){return isNaN(this.x1)||isNaN(this.y1)||isNaN(this.x2)||isNaN(this.y2)};as.prototype.addPoint=function(n,e){typeof n=="number"&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=n,this.x2=n),n<this.x1&&(this.x1=n),n>this.x2&&(this.x2=n)),typeof e=="number"&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))};as.prototype.addX=function(n){this.addPoint(n,null)};as.prototype.addY=function(n){this.addPoint(null,n)};as.prototype.addBezier=function(n,e,t,i,s,r,a,o){const l=[n,e],c=[t,i],u=[s,r],f=[a,o];this.addPoint(n,e),this.addPoint(a,o);for(let h=0;h<=1;h++){const d=6*l[h]-12*c[h]+6*u[h],p=-3*l[h]+9*c[h]-9*u[h]+3*f[h],x=3*c[h]-3*l[h];if(p===0){if(d===0)continue;const E=-x/d;0<E&&E<1&&(h===0&&this.addX(Is(l[h],c[h],u[h],f[h],E)),h===1&&this.addY(Is(l[h],c[h],u[h],f[h],E)));continue}const m=Math.pow(d,2)-4*x*p;if(m<0)continue;const g=(-d+Math.sqrt(m))/(2*p);0<g&&g<1&&(h===0&&this.addX(Is(l[h],c[h],u[h],f[h],g)),h===1&&this.addY(Is(l[h],c[h],u[h],f[h],g)));const M=(-d-Math.sqrt(m))/(2*p);0<M&&M<1&&(h===0&&this.addX(Is(l[h],c[h],u[h],f[h],M)),h===1&&this.addY(Is(l[h],c[h],u[h],f[h],M)))}};as.prototype.addQuad=function(n,e,t,i,s,r){const a=n+.6666666666666666*(t-n),o=e+2/3*(i-e),l=a+1/3*(s-n),c=o+1/3*(r-e);this.addBezier(n,e,a,o,l,c,s,r)};var Ud=as;function Bt(){this.commands=[],this.fill="black",this.stroke=null,this.strokeWidth=1}var dr={};function Od(n,e){const t=Math.floor(n),i=n-t;if(dr[e]||(dr[e]={}),dr[e][i]!==void 0){const r=dr[e][i];return t+r}const s=+(Math.round(i+"e+"+e)+"e-"+e);return dr[e][i]=s,t+s}function Fd(n){let e=[[]],t=0,i=0;for(let s=0;s<n.length;s+=1){const r=e[e.length-1],a=n[s],o=r[0],l=r[1],c=r[r.length-1],u=n[s+1];r.push(a),a.type==="M"?(t=a.x,i=a.y):a.type==="L"&&(!u||u.type==="Z")?Math.abs(a.x-t)>1||Math.abs(a.y-i)>1||r.pop():a.type==="L"&&c&&c.x===a.x&&c.y===a.y?r.pop():a.type==="Z"&&(o&&l&&c&&o.type==="M"&&l.type==="L"&&c.type==="L"&&c.x===o.x&&c.y===o.y&&(r.shift(),r[0].type="M"),s+1<n.length&&e.push([]))}return n=[].concat.apply([],e),n}function pb(n){return Object.assign({},{decimalPlaces:2,optimize:!0,flipY:!0,flipYBase:void 0,scale:1,x:0,y:0},n)}function mb(n){return parseInt(n)===n&&(n={decimalPlaces:n,flipY:!1}),Object.assign({},{decimalPlaces:2,optimize:!0,flipY:!0,flipYBase:void 0},n)}Bt.prototype.fromSVG=function(n,e={}){typeof SVGPathElement<"u"&&n instanceof SVGPathElement&&(n=n.getAttribute("d")),e=pb(e),this.commands=[];const t="0123456789",i="MmLlQqCcZzHhVv",s="SsTtAa",r="-+";let a={},o=[""],l=!1;function c(p){return p.filter(x=>x.length).map(x=>{let m=parseFloat(x);return(e.decimalPlaces||e.decimalPlaces===0)&&(m=Od(m,e.decimalPlaces)),m})}function u(p){if(!this.commands.length)return p;const x=this.commands[this.commands.length-1];for(let m=0;m<p.length;m++)p[m]+=x[m&1?"y":"x"];return p}function f(){if(a.type===void 0)return;const p=a.type.toUpperCase(),x=p!=="Z"&&a.type.toUpperCase()!==a.type;let m=c(o);if(o=[""],!m.length&&p!=="Z")return;x&&p!=="H"&&p!=="V"&&(m=u.apply(this,[m]));const g=this.commands.length&&this.commands[this.commands.length-1].x||0,M=this.commands.length&&this.commands[this.commands.length-1].y||0;switch(p){case"M":this.moveTo(...m);break;case"L":this.lineTo(...m);break;case"V":for(let E=0;E<m.length;E++){let _=0;x&&(_=this.commands.length&&this.commands[this.commands.length-1].y||0),this.lineTo(g,m[E]+_)}break;case"H":for(let E=0;E<m.length;E++){let _=0;x&&(_=this.commands.length&&this.commands[this.commands.length-1].x||0),this.lineTo(m[E]+_,M)}break;case"C":this.bezierCurveTo(...m);break;case"Q":this.quadraticCurveTo(...m);break;case"Z":(this.commands.length<1||this.commands[this.commands.length-1].type!=="Z")&&this.close();break}if(this.commands.length)for(const E in this.commands[this.commands.length-1])this.commands[this.commands.length-1][E]===void 0&&(this.commands[this.commands.length-1][E]=0)}for(let p=0;p<n.length;p++){const x=n.charAt(p),m=o[o.length-1];if(t.indexOf(x)>-1)o[o.length-1]+=x;else if(r.indexOf(x)>-1)if(!a.type&&!this.commands.length&&(a.type="L"),x==="-")!a.type||m.indexOf("-")>0?l=!0:m.length?o.push("-"):o[o.length-1]=x;else if(!a.type||m.length>0)l=!0;else continue;else if(i.indexOf(x)>-1)a.type?(f.apply(this),a={type:x}):a.type=x;else{if(s.indexOf(x)>-1)throw new Error("Unsupported path command: "+x+". Currently supported commands are "+i.split("").join(", ")+".");` ,
|
|
\r\f\v`.indexOf(x)>-1?o.push(""):x==="."?!a.type||m.indexOf(x)>-1?l=!0:o[o.length-1]+=x:l=!0}if(l)throw new Error("Unexpected character: "+x+" at offset "+p)}f.apply(this),e.optimize&&(this.commands=Fd(this.commands));const h=e.flipY;let d=e.flipYBase;if(h===!0&&e.flipYBase===void 0){const p=this.getBoundingBox();d=p.y1+p.y2}for(const p in this.commands){const x=this.commands[p];for(const m in x)["x","x1","x2"].includes(m)?this.commands[p][m]=e.x+x[m]*e.scale:["y","y1","y2"].includes(m)&&(this.commands[p][m]=e.y+(h?d-x[m]:x[m])*e.scale)}return this};Bt.fromSVG=function(n,e){return new Bt().fromSVG(n,e)};Bt.prototype.moveTo=function(n,e){this.commands.push({type:"M",x:n,y:e})};Bt.prototype.lineTo=function(n,e){this.commands.push({type:"L",x:n,y:e})};Bt.prototype.curveTo=Bt.prototype.bezierCurveTo=function(n,e,t,i,s,r){this.commands.push({type:"C",x1:n,y1:e,x2:t,y2:i,x:s,y:r})};Bt.prototype.quadTo=Bt.prototype.quadraticCurveTo=function(n,e,t,i){this.commands.push({type:"Q",x1:n,y1:e,x:t,y:i})};Bt.prototype.close=Bt.prototype.closePath=function(){this.commands.push({type:"Z"})};Bt.prototype.extend=function(n){if(n.commands)n=n.commands;else if(n instanceof Ud){const e=n;this.moveTo(e.x1,e.y1),this.lineTo(e.x2,e.y1),this.lineTo(e.x2,e.y2),this.lineTo(e.x1,e.y2),this.close();return}Array.prototype.push.apply(this.commands,n)};Bt.prototype.getBoundingBox=function(){const n=new Ud;let e=0,t=0,i=0,s=0;for(let r=0;r<this.commands.length;r++){const a=this.commands[r];switch(a.type){case"M":n.addPoint(a.x,a.y),e=i=a.x,t=s=a.y;break;case"L":n.addPoint(a.x,a.y),i=a.x,s=a.y;break;case"Q":n.addQuad(i,s,a.x1,a.y1,a.x,a.y),i=a.x,s=a.y;break;case"C":n.addBezier(i,s,a.x1,a.y1,a.x2,a.y2,a.x,a.y),i=a.x,s=a.y;break;case"Z":i=e,s=t;break;default:throw new Error("Unexpected path command "+a.type)}}return n.isEmpty()&&n.addPoint(0,0),n};Bt.prototype.draw=function(n){const e=this._layers;if(e&&e.length){for(let i=0;i<e.length;i++)this.draw.call(e[i],n);return}const t=this._image;if(t){n.drawImage(t.image,t.x,t.y,t.width,t.height);return}n.beginPath();for(let i=0;i<this.commands.length;i+=1){const s=this.commands[i];s.type==="M"?n.moveTo(s.x,s.y):s.type==="L"?n.lineTo(s.x,s.y):s.type==="C"?n.bezierCurveTo(s.x1,s.y1,s.x2,s.y2,s.x,s.y):s.type==="Q"?n.quadraticCurveTo(s.x1,s.y1,s.x,s.y):s.type==="Z"&&this.stroke&&this.strokeWidth&&n.closePath()}this.fill&&(n.fillStyle=this.fill,n.fill()),this.stroke&&(n.strokeStyle=this.stroke,n.lineWidth=this.strokeWidth,n.stroke())};Bt.prototype.toPathData=function(n){n=mb(n);function e(o){const l=Od(o,n.decimalPlaces);return Math.round(o)===l?""+l:l.toFixed(n.decimalPlaces)}function t(){let o="";for(let l=0;l<arguments.length;l+=1){const c=arguments[l];c>=0&&l>0&&(o+=" "),o+=e(c)}return o}let i=this.commands;n.optimize&&(i=JSON.parse(JSON.stringify(this.commands)),i=Fd(i));const s=n.flipY;let r=n.flipYBase;if(s===!0&&r===void 0){const o=new Bt;o.extend(i);const l=o.getBoundingBox();r=l.y1+l.y2}let a="";for(let o=0;o<i.length;o+=1){const l=i[o];l.type==="M"?a+="M"+t(l.x,s?r-l.y:l.y):l.type==="L"?a+="L"+t(l.x,s?r-l.y:l.y):l.type==="C"?a+="C"+t(l.x1,s?r-l.y1:l.y1,l.x2,s?r-l.y2:l.y2,l.x,s?r-l.y:l.y):l.type==="Q"?a+="Q"+t(l.x1,s?r-l.y1:l.y1,l.x,s?r-l.y:l.y):l.type==="Z"&&(a+="Z")}return a};Bt.prototype.toSVG=function(n,e){this._layers&&this._layers.length&&console.warn("toSVG() does not support colr font layers yet"),this._image&&console.warn("toSVG() does not support SVG glyphs yet"),e||(e=this.toPathData(n));let t='<path d="';return t+=e,t+='"',this.fill!==void 0&&this.fill!=="black"&&(this.fill===null?t+=' fill="none"':t+=' fill="'+this.fill+'"'),this.stroke&&(t+=' stroke="'+this.stroke+'" stroke-width="'+this.strokeWidth+'"'),t+="/>",t};Bt.prototype.toDOMElement=function(n,e){this._layers&&this._layers.length&&console.warn("toDOMElement() does not support colr font layers yet"),e||(e=this.toPathData(n));const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",e),this.fill!==void 0&&this.fill!=="black"&&(this.fill===null?t.setAttribute("fill","none"):t.setAttribute("fill",this.fill)),this.stroke&&(t.setAttribute("stroke",this.stroke),t.setAttribute("stroke-width",this.strokeWidth)),t};var qs=Bt;function Nd(n){throw new Error(n)}function Ch(n,e){n||Nd(e)}var Ne={fail:Nd,argument:Ch,assert:Ch},Rh=32768,Ph=2147483648,gb=-32768,xb=32767+1/65536,$s={},Se={},Xe={};function Fn(n){return function(){return n}}Se.BYTE=function(n){return Ne.argument(n>=0&&n<=255,"Byte value should be between 0 and 255."),[n]};Xe.BYTE=Fn(1);Se.CHAR=function(n){return[n.charCodeAt(0)]};Xe.CHAR=Fn(1);Se.CHARARRAY=function(n){(n===null||typeof n>"u")&&(n="",console.warn("CHARARRAY with undefined or null value encountered and treated as an empty string. This is probably caused by a missing glyph name."));const e=[];for(let t=0;t<n.length;t+=1)e[t]=n.charCodeAt(t);return e};Xe.CHARARRAY=function(n){return typeof n>"u"?0:n.length};Se.USHORT=function(n){return[n>>8&255,n&255]};Xe.USHORT=Fn(2);Se.SHORT=function(n){return n>=Rh&&(n=-(2*Rh-n)),[n>>8&255,n&255]};Xe.SHORT=Fn(2);Se.UINT24=function(n){return[n>>16&255,n>>8&255,n&255]};Xe.UINT24=Fn(3);Se.ULONG=function(n){return[n>>24&255,n>>16&255,n>>8&255,n&255]};Xe.ULONG=Fn(4);Se.LONG=function(n){return n>=Ph&&(n=-(2*Ph-n)),[n>>24&255,n>>16&255,n>>8&255,n&255]};Xe.LONG=Fn(4);Se.FLOAT=function(n){if(n>xb||n<gb)throw new Error(`Value ${n} is outside the range of representable values in 16.16 format`);const e=Math.round(n*65536)<<0;return Se.ULONG(e)};Xe.FLOAT=Xe.ULONG;Se.FIXED=Se.ULONG;Xe.FIXED=Xe.ULONG;Se.FWORD=Se.SHORT;Xe.FWORD=Xe.SHORT;Se.UFWORD=Se.USHORT;Xe.UFWORD=Xe.USHORT;Se.F2DOT14=function(n){return Se.USHORT(n*16384)};Xe.F2DOT14=Xe.USHORT;Se.LONGDATETIME=function(n){return[0,0,0,0,n>>24&255,n>>16&255,n>>8&255,n&255]};Xe.LONGDATETIME=Fn(8);Se.TAG=function(n){return Ne.argument(n.length===4,"Tag should be exactly 4 ASCII characters."),[n.charCodeAt(0),n.charCodeAt(1),n.charCodeAt(2),n.charCodeAt(3)]};Xe.TAG=Fn(4);Se.Card8=Se.BYTE;Xe.Card8=Xe.BYTE;Se.Card16=Se.USHORT;Xe.Card16=Xe.USHORT;Se.OffSize=Se.BYTE;Xe.OffSize=Xe.BYTE;Se.SID=Se.USHORT;Xe.SID=Xe.USHORT;Se.NUMBER=function(n){return n>=-107&&n<=107?[n+139]:n>=108&&n<=1131?(n=n-108,[(n>>8)+247,n&255]):n>=-1131&&n<=-108?(n=-n-108,[(n>>8)+251,n&255]):n>=-32768&&n<=32767?Se.NUMBER16(n):Se.NUMBER32(n)};Xe.NUMBER=function(n){return Se.NUMBER(n).length};Se.NUMBER16=function(n){return[28,n>>8&255,n&255]};Xe.NUMBER16=Fn(3);Se.NUMBER32=function(n){return[29,n>>24&255,n>>16&255,n>>8&255,n&255]};Xe.NUMBER32=Fn(5);Se.REAL=function(n){let e=n.toString();const t=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(e);if(t){const r=parseFloat("1e"+((t[2]?+t[2]:0)+t[1].length));e=(Math.round(n*r)/r).toString()}let i="";for(let r=0,a=e.length;r<a;r+=1){const o=e[r];o==="e"?i+=e[++r]==="-"?"c":"b":o==="."?i+="a":o==="-"?i+="e":i+=o}i+=i.length&1?"f":"ff";const s=[30];for(let r=0,a=i.length;r<a;r+=2)s.push(parseInt(i.substr(r,2),16));return s};Xe.REAL=function(n){return Se.REAL(n).length};Se.NAME=Se.CHARARRAY;Xe.NAME=Xe.CHARARRAY;Se.STRING=Se.CHARARRAY;Xe.STRING=Xe.CHARARRAY;$s.UTF8=function(n,e,t){const i=[],s=t;for(let r=0;r<s;r++,e+=1)i[r]=n.getUint8(e);return String.fromCharCode.apply(null,i)};$s.UTF16=function(n,e,t){const i=[],s=t/2;for(let r=0;r<s;r++,e+=2)i[r]=n.getUint16(e);return String.fromCharCode.apply(null,i)};Se.UTF16=function(n){const e=[];for(let t=0;t<n.length;t+=1){const i=n.charCodeAt(t);e[e.length]=i>>8&255,e[e.length]=i&255}return e};Xe.UTF16=function(n){return n.length*2};var eo={"x-mac-croatian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø¿¡¬√ƒ≈ƫȅ ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ","x-mac-cyrillic":"АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю","x-mac-gaelic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæøṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ","x-mac-greek":"Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ","x-mac-icelandic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüݰ¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-inuit":"ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł","x-mac-ce":"ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ",macintosh:"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-romanian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-turkish":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ"};$s.MACSTRING=function(n,e,t,i){const s=eo[i];if(s===void 0)return;let r="";for(let a=0;a<t;a++){const o=n.getUint8(e+a);o<=127?r+=String.fromCharCode(o):r+=s[o&127]}return r};var Ma=typeof WeakMap=="function"&&new WeakMap,Ea,vb=function(n){if(!Ea){Ea={};for(let s in eo)Ea[s]=new String(s)}const e=Ea[n];if(e===void 0)return;if(Ma){const s=Ma.get(e);if(s!==void 0)return s}const t=eo[n];if(t===void 0)return;const i={};for(let s=0;s<t.length;s++)i[t.charCodeAt(s)]=s+128;return Ma&&Ma.set(e,i),i};Se.MACSTRING=function(n,e){const t=vb(e);if(t===void 0)return;const i=[];for(let s=0;s<n.length;s++){let r=n.charCodeAt(s);if(r>=128&&(r=t[r],r===void 0))return;i[s]=r}return i};Xe.MACSTRING=function(n,e){const t=Se.MACSTRING(n,e);return t!==void 0?t.length:0};function vc(n){return n>=-128&&n<=127}function yb(n,e,t){let i=0;const s=n.length;for(;e<s&&i<64&&n[e]===0;)++e,++i;return t.push(128|i-1),e}function _b(n,e,t){let i=0;const s=n.length;let r=e;for(;r<s&&i<64;){const a=n[r];if(!vc(a)||a===0&&r+1<s&&n[r+1]===0)break;++r,++i}t.push(i-1);for(let a=e;a<r;++a)t.push(n[a]+256&255);return r}function bb(n,e,t){let i=0;const s=n.length;let r=e;for(;r<s&&i<64;){const a=n[r];if(a===0||vc(a)&&r+1<s&&vc(n[r+1]))break;++r,++i}t.push(64|i-1);for(let a=e;a<r;++a){const o=n[a];t.push(o+65536>>8&255,o+256&255)}return r}Se.VARDELTAS=function(n){let e=0;const t=[];for(;e<n.length;){const i=n[e];i===0?e=yb(n,e,t):i>=-128&&i<=127?e=_b(n,e,t):e=bb(n,e,t)}return t};Se.INDEX=function(n){let e=1;const t=[e],i=[];for(let o=0;o<n.length;o+=1){const l=Se.OBJECT(n[o]);Array.prototype.push.apply(i,l),e+=l.length,t.push(e)}if(i.length===0)return[0,0];const s=[],r=1+Math.floor(Math.log(e)/Math.log(2))/8|0,a=[void 0,Se.BYTE,Se.USHORT,Se.UINT24,Se.ULONG][r];for(let o=0;o<t.length;o+=1){const l=a(t[o]);Array.prototype.push.apply(s,l)}return Array.prototype.concat(Se.Card16(n.length),Se.OffSize(r),s,i)};Xe.INDEX=function(n){return Se.INDEX(n).length};Se.DICT=function(n){let e=[];const t=Object.keys(n),i=t.length;for(let s=0;s<i;s+=1){const r=parseInt(t[s],0),a=n[r],o=Se.OPERAND(a.value,a.type),l=Se.OPERATOR(r);for(let c=0;c<o.length;c++)e.push(o[c]);for(let c=0;c<l.length;c++)e.push(l[c])}return e};Xe.DICT=function(n){return Se.DICT(n).length};Se.OPERATOR=function(n){return n<1200?[n]:[12,n-1200]};Se.OPERAND=function(n,e){let t=[];if(Array.isArray(e))for(let i=0;i<e.length;i+=1){Ne.argument(n.length===e.length,"Not enough arguments given for type"+e);const s=Se.OPERAND(n[i],e[i]);for(let r=0;r<s.length;r++)t.push(s[r])}else if(e==="SID"){const i=Se.NUMBER(n);for(let s=0;s<i.length;s++)t.push(i[s])}else if(e==="offset"){const i=Se.NUMBER32(n);for(let s=0;s<i.length;s++)t.push(i[s])}else if(e==="number"){const i=Se.NUMBER(n);for(let s=0;s<i.length;s++)t.push(i[s])}else if(e==="real"){const i=Se.REAL(n);for(let s=0;s<i.length;s++)t.push(i[s])}else throw new Error("Unknown operand type "+e);return t};Se.OP=Se.BYTE;Xe.OP=Xe.BYTE;var Ta=typeof WeakMap=="function"&&new WeakMap;Se.CHARSTRING=function(n){if(Ta){const i=Ta.get(n);if(i!==void 0)return i}let e=[];const t=n.length;for(let i=0;i<t;i+=1){const s=n[i],r=Se[s.type](s.value);for(let a=0;a<r.length;a++)e.push(r[a])}return Ta&&Ta.set(n,e),e};Xe.CHARSTRING=function(n){return Se.CHARSTRING(n).length};Se.OBJECT=function(n){const e=Se[n.type];return Ne.argument(e!==void 0,"No encoding function for type "+n.type),e(n.value)};Xe.OBJECT=function(n){const e=Xe[n.type];return Ne.argument(e!==void 0,"No sizeOf function for type "+n.type),e(n.value)};Se.TABLE=function(n){let e=[];const t=(n.fields||[]).length,i=[],s=[];for(let r=0;r<t;r+=1){const a=n.fields[r],o=Se[a.type];Ne.argument(o!==void 0,"No encoding function for field type "+a.type+" ("+a.name+")");let l=n[a.name];l===void 0&&(l=a.value);const c=o(l);if(a.type==="TABLE")l.fields!==null&&(s.push(e.length),i.push(c)),e.push(0,0);else for(let u=0;u<c.length;u++)e.push(c[u])}for(let r=0;r<i.length;r+=1){const a=s[r],o=e.length;Ne.argument(o<65536,"Table "+n.tableName+" too big."),e[a]=o>>8,e[a+1]=o&255;for(let l=0;l<i[r].length;l++)e.push(i[r][l])}return e};Xe.TABLE=function(n){let e=0;const t=(n.fields||[]).length;for(let i=0;i<t;i+=1){const s=n.fields[i],r=Xe[s.type];Ne.argument(r!==void 0,"No sizeOf function for field type "+s.type+" ("+s.name+")");let a=n[s.name];a===void 0&&(a=s.value),e+=r(a),s.type==="TABLE"&&(e+=2)}return e};Se.RECORD=Se.TABLE;Xe.RECORD=Xe.TABLE;Se.LITERAL=function(n){return n};Xe.LITERAL=function(n){return n.length};function Dt(n,e,t){if(e&&e.length)for(let i=0;i<e.length;i+=1){const s=e[i];this[s.name]=s.value}if(this.tableName=n,this.fields=e,t){const i=Object.keys(t);for(let s=0;s<i.length;s+=1){const r=i[s],a=t[r];this[r]!==void 0&&(this[r]=a)}}}Dt.prototype.encode=function(){return Se.TABLE(this)};Dt.prototype.sizeOf=function(){return Xe.TABLE(this)};function Zs(n,e,t){t===void 0&&(t=e.length);const i=new Array(e.length+1);i[0]={name:n+"Count",type:"USHORT",value:t};for(let s=0;s<e.length;s++)i[s+1]={name:n+s,type:"USHORT",value:e[s]};return i}function yc(n,e,t){const i=e.length,s=new Array(i+1);s[0]={name:n+"Count",type:"USHORT",value:i};for(let r=0;r<i;r++)s[r+1]={name:n+r,type:"TABLE",value:t(e[r],r)};return s}function Ks(n,e,t){const i=e.length;let s=[];s[0]={name:n+"Count",type:"USHORT",value:i};for(let r=0;r<i;r++)s=s.concat(t(e[r],r));return s}function to(n){n.format===1?Dt.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:1}].concat(Zs("glyph",n.glyphs))):n.format===2?Dt.call(this,"coverageTable",[{name:"coverageFormat",type:"USHORT",value:2}].concat(Ks("rangeRecord",n.ranges,function(e,t){return[{name:"startGlyphID"+t,type:"USHORT",value:e.start},{name:"endGlyphID"+t,type:"USHORT",value:e.end},{name:"startCoverageIndex"+t,type:"USHORT",value:e.index}]}))):Ne.assert(!1,"Coverage format must be 1 or 2.")}to.prototype=Object.create(Dt.prototype);to.prototype.constructor=to;function no(n){Dt.call(this,"scriptListTable",Ks("scriptRecord",n,function(e,t){const i=e.script;let s=i.defaultLangSys;return Ne.assert(!!s,"Unable to write GSUB: script "+e.tag+" has no default language system."),[{name:"scriptTag"+t,type:"TAG",value:e.tag},{name:"script"+t,type:"TABLE",value:new Dt("scriptTable",[{name:"defaultLangSys",type:"TABLE",value:new Dt("defaultLangSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:s.reqFeatureIndex}].concat(Zs("featureIndex",s.featureIndexes)))}].concat(Ks("langSys",i.langSysRecords,function(r,a){const o=r.langSys;return[{name:"langSysTag"+a,type:"TAG",value:r.tag},{name:"langSys"+a,type:"TABLE",value:new Dt("langSys",[{name:"lookupOrder",type:"USHORT",value:0},{name:"reqFeatureIndex",type:"USHORT",value:o.reqFeatureIndex}].concat(Zs("featureIndex",o.featureIndexes)))}]})))}]}))}no.prototype=Object.create(Dt.prototype);no.prototype.constructor=no;function io(n){Dt.call(this,"featureListTable",Ks("featureRecord",n,function(e,t){const i=e.feature;return[{name:"featureTag"+t,type:"TAG",value:e.tag},{name:"feature"+t,type:"TABLE",value:new Dt("featureTable",[{name:"featureParams",type:"USHORT",value:i.featureParams}].concat(Zs("lookupListIndex",i.lookupListIndexes)))}]}))}io.prototype=Object.create(Dt.prototype);io.prototype.constructor=io;function so(n,e){Dt.call(this,"lookupListTable",yc("lookup",n,function(t){let i=e[t.lookupType];return Ne.assert(!!i,"Unable to write GSUB lookup type "+t.lookupType+" tables."),new Dt("lookupTable",[{name:"lookupType",type:"USHORT",value:t.lookupType},{name:"lookupFlag",type:"USHORT",value:t.lookupFlag}].concat(yc("subtable",t.subtables,i)))}))}so.prototype=Object.create(Dt.prototype);so.prototype.constructor=so;function ro(n){n.format===1?Dt.call(this,"classDefTable",[{name:"classFormat",type:"USHORT",value:1},{name:"startGlyphID",type:"USHORT",value:n.startGlyph}].concat(Zs("glyph",n.classes))):n.format===2?Dt.call(this,"classDefTable",[{name:"classFormat",type:"USHORT",value:2}].concat(Ks("rangeRecord",n.ranges,function(e,t){return[{name:"startGlyphID"+t,type:"USHORT",value:e.start},{name:"endGlyphID"+t,type:"USHORT",value:e.end},{name:"class"+t,type:"USHORT",value:e.classId}]}))):Ne.assert(!1,"Class format must be 1 or 2.")}ro.prototype=Object.create(Dt.prototype);ro.prototype.constructor=ro;var me={Table:Dt,Record:Dt,Coverage:to,ClassDef:ro,ScriptList:no,FeatureList:io,LookupList:so,ushortList:Zs,tableList:yc,recordList:Ks};function Lh(n,e){return n.getUint8(e)}function ao(n,e){return n.getUint16(e,!1)}function Sb(n,e){return n.getInt16(e,!1)}function kd(n,e){return(n.getUint16(e)<<8)+n.getUint8(e+2)}function $c(n,e){return n.getUint32(e,!1)}function Mb(n,e){return n.getInt32(e,!1)}function Bd(n,e){const t=n.getInt16(e,!1),i=n.getUint16(e+2,!1);return t+i/65535}function Eb(n,e){let t="";for(let i=e;i<e+4;i+=1)t+=String.fromCharCode(n.getInt8(i));return t}function Tb(n,e,t){let i=0;for(let s=0;s<t;s+=1)i<<=8,i+=n.getUint8(e+s);return i}function Ab(n,e,t){const i=[];for(let s=e;s<t;s+=1)i.push(n.getUint8(s));return i}function wb(n){let e="";for(let t=0;t<n.length;t+=1)e+=String.fromCharCode(n[t]);return e}var Cb={byte:1,uShort:2,f2dot14:2,short:2,uInt24:3,uLong:4,fixed:4,longDateTime:8,tag:4},jt={LONG_WORDS:32768,WORD_DELTA_COUNT_MASK:32767,SHARED_POINT_NUMBERS:32768,COUNT_MASK:4095,EMBEDDED_PEAK_TUPLE:32768,INTERMEDIATE_REGION:16384,PRIVATE_POINT_NUMBERS:8192,TUPLE_INDEX_MASK:4095,POINTS_ARE_WORDS:128,POINT_RUN_COUNT_MASK:127,DELTAS_ARE_ZERO:128,DELTAS_ARE_WORDS:64,DELTA_RUN_COUNT_MASK:63,INNER_INDEX_BIT_COUNT_MASK:15,MAP_ENTRY_SIZE_MASK:48};function q(n,e){this.data=n,this.offset=e,this.relativeOffset=0}q.prototype.parseByte=function(){const n=this.data.getUint8(this.offset+this.relativeOffset);return this.relativeOffset+=1,n};q.prototype.parseChar=function(){const n=this.data.getInt8(this.offset+this.relativeOffset);return this.relativeOffset+=1,n};q.prototype.parseCard8=q.prototype.parseByte;q.prototype.parseUShort=function(){const n=this.data.getUint16(this.offset+this.relativeOffset);return this.relativeOffset+=2,n};q.prototype.parseCard16=q.prototype.parseUShort;q.prototype.parseSID=q.prototype.parseUShort;q.prototype.parseOffset16=q.prototype.parseUShort;q.prototype.parseShort=function(){const n=this.data.getInt16(this.offset+this.relativeOffset);return this.relativeOffset+=2,n};q.prototype.parseF2Dot14=function(){const n=this.data.getInt16(this.offset+this.relativeOffset)/16384;return this.relativeOffset+=2,n};q.prototype.parseUInt24=function(){const n=kd(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=3,n};q.prototype.parseULong=function(){const n=$c(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,n};q.prototype.parseLong=function(){const n=Mb(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,n};q.prototype.parseOffset32=q.prototype.parseULong;q.prototype.parseFixed=function(){const n=Bd(this.data,this.offset+this.relativeOffset);return this.relativeOffset+=4,n};q.prototype.parseString=function(n){const e=this.data,t=this.offset+this.relativeOffset;let i="";this.relativeOffset+=n;for(let s=0;s<n;s++)i+=String.fromCharCode(e.getUint8(t+s));return i};q.prototype.parseTag=function(){return this.parseString(4)};q.prototype.parseLongDateTime=function(){let n=$c(this.data,this.offset+this.relativeOffset+4);return n-=2082844800,this.relativeOffset+=8,n};q.prototype.parseVersion=function(n){const e=ao(this.data,this.offset+this.relativeOffset),t=ao(this.data,this.offset+this.relativeOffset+2);return this.relativeOffset+=4,n===void 0&&(n=4096),e+t/n/10};q.prototype.skip=function(n,e){e===void 0&&(e=1),this.relativeOffset+=Cb[n]*e};q.prototype.parseULongList=function(n){n===void 0&&(n=this.parseULong());const e=new Array(n),t=this.data;let i=this.offset+this.relativeOffset;for(let s=0;s<n;s++)e[s]=t.getUint32(i),i+=4;return this.relativeOffset+=n*4,e};q.prototype.parseOffset16List=q.prototype.parseUShortList=function(n){n===void 0&&(n=this.parseUShort());const e=new Array(n),t=this.data;let i=this.offset+this.relativeOffset;for(let s=0;s<n;s++)e[s]=t.getUint16(i),i+=2;return this.relativeOffset+=n*2,e};q.prototype.parseShortList=function(n){const e=new Array(n),t=this.data;let i=this.offset+this.relativeOffset;for(let s=0;s<n;s++)e[s]=t.getInt16(i),i+=2;return this.relativeOffset+=n*2,e};q.prototype.parseByteList=function(n){const e=new Array(n),t=this.data;let i=this.offset+this.relativeOffset;for(let s=0;s<n;s++)e[s]=t.getUint8(i++);return this.relativeOffset+=n,e};q.prototype.parseList=function(n,e){e||(e=n,n=this.parseUShort());const t=new Array(n);for(let i=0;i<n;i++)t[i]=e.call(this);return t};q.prototype.parseList32=function(n,e){e||(e=n,n=this.parseULong());const t=new Array(n);for(let i=0;i<n;i++)t[i]=e.call(this);return t};q.prototype.parseRecordList=function(n,e){e||(e=n,n=this.parseUShort());const t=new Array(n),i=Object.keys(e);for(let s=0;s<n;s++){const r={};for(let a=0;a<i.length;a++){const o=i[a],l=e[o];r[o]=l.call(this)}t[s]=r}return t};q.prototype.parseRecordList32=function(n,e){e||(e=n,n=this.parseULong());const t=new Array(n),i=Object.keys(e);for(let s=0;s<n;s++){const r={};for(let a=0;a<i.length;a++){const o=i[a],l=e[o];r[o]=l.call(this)}t[s]=r}return t};q.prototype.parseTupleRecords=function(n,e){let t=[];for(let i=0;i<n;i++){let s=[];for(let r=0;r<e;r++)s.push(this.parseF2Dot14());t.push(s)}return t};q.prototype.parseStruct=function(n){if(typeof n=="function")return n.call(this);{const e=Object.keys(n),t={};for(let i=0;i<e.length;i++){const s=e[i],r=n[s];t[s]=r.call(this)}return t}};q.prototype.parseValueRecord=function(n){if(n===void 0&&(n=this.parseUShort()),n===0)return;const e={};return n&1&&(e.xPlacement=this.parseShort()),n&2&&(e.yPlacement=this.parseShort()),n&4&&(e.xAdvance=this.parseShort()),n&8&&(e.yAdvance=this.parseShort()),n&16&&(e.xPlaDevice=void 0,this.parseShort()),n&32&&(e.yPlaDevice=void 0,this.parseShort()),n&64&&(e.xAdvDevice=void 0,this.parseShort()),n&128&&(e.yAdvDevice=void 0,this.parseShort()),e};q.prototype.parseValueRecordList=function(){const n=this.parseUShort(),e=this.parseUShort(),t=new Array(e);for(let i=0;i<e;i++)t[i]=this.parseValueRecord(n);return t};q.prototype.parsePointer=function(n){const e=this.parseOffset16();if(e>0)return new q(this.data,this.offset+e).parseStruct(n)};q.prototype.parsePointer32=function(n){const e=this.parseOffset32();if(e>0)return new q(this.data,this.offset+e).parseStruct(n)};q.prototype.parseListOfLists=function(n){const e=this.parseOffset16List(),t=e.length,i=this.relativeOffset,s=new Array(t);for(let r=0;r<t;r++){const a=e[r];if(a===0){s[r]=void 0;continue}if(this.relativeOffset=a,n){const o=this.parseOffset16List(),l=new Array(o.length);for(let c=0;c<o.length;c++)this.relativeOffset=a+o[c],l[c]=n.call(this);s[r]=l}else s[r]=this.parseUShortList()}return this.relativeOffset=i,s};q.prototype.parseCoverage=function(){const n=this.offset+this.relativeOffset,e=this.parseUShort(),t=this.parseUShort();if(e===1)return{format:1,glyphs:this.parseUShortList(t)};if(e===2){const i=new Array(t);for(let s=0;s<t;s++)i[s]={start:this.parseUShort(),end:this.parseUShort(),index:this.parseUShort()};return{format:2,ranges:i}}throw new Error("0x"+n.toString(16)+": Coverage format must be 1 or 2.")};q.prototype.parseClassDef=function(){const n=this.offset+this.relativeOffset,e=this.parseUShort();return e===1?{format:1,startGlyph:this.parseUShort(),classes:this.parseUShortList()}:e===2?{format:2,ranges:this.parseRecordList({start:q.uShort,end:q.uShort,classId:q.uShort})}:(console.warn(`0x${n.toString(16)}: This font file uses an invalid ClassDef format of ${e}. It might be corrupted and should be reacquired if it doesn't display as intended.`),{format:e})};q.list=function(n,e){return function(){return this.parseList(n,e)}};q.list32=function(n,e){return function(){return this.parseList32(n,e)}};q.recordList=function(n,e){return function(){return this.parseRecordList(n,e)}};q.recordList32=function(n,e){return function(){return this.parseRecordList32(n,e)}};q.pointer=function(n){return function(){return this.parsePointer(n)}};q.pointer32=function(n){return function(){return this.parsePointer32(n)}};q.tag=q.prototype.parseTag;q.byte=q.prototype.parseByte;q.uShort=q.offset16=q.prototype.parseUShort;q.uShortList=q.prototype.parseUShortList;q.uInt24=q.prototype.parseUInt24;q.uLong=q.offset32=q.prototype.parseULong;q.uLongList=q.prototype.parseULongList;q.fixed=q.prototype.parseFixed;q.f2Dot14=q.prototype.parseF2Dot14;q.struct=q.prototype.parseStruct;q.coverage=q.prototype.parseCoverage;q.classDef=q.prototype.parseClassDef;var Dh={reserved:q.uShort,reqFeatureIndex:q.uShort,featureIndexes:q.uShortList};q.prototype.parseScriptList=function(){return this.parsePointer(q.recordList({tag:q.tag,script:q.pointer({defaultLangSys:q.pointer(Dh),langSysRecords:q.recordList({tag:q.tag,langSys:q.pointer(Dh)})})}))||[]};q.prototype.parseFeatureList=function(){return this.parsePointer(q.recordList({tag:q.tag,feature:q.pointer({featureParams:q.offset16,lookupListIndexes:q.uShortList})}))||[]};q.prototype.parseLookupList=function(n){return this.parsePointer(q.list(q.pointer(function(){const e=this.parseUShort();Ne.argument(1<=e&&e<=9,"GPOS/GSUB lookup type "+e+" unknown.");const t=this.parseUShort(),i=t&16;return{lookupType:e,lookupFlag:t,subtables:this.parseList(q.pointer(n[e])),markFilteringSet:i?this.parseUShort():void 0}})))||[]};q.prototype.parseFeatureVariationsList=function(){return this.parsePointer32(function(){const n=this.parseUShort(),e=this.parseUShort();return Ne.argument(n===1&&e<1,"GPOS/GSUB feature variations table unknown."),this.parseRecordList32({conditionSetOffset:q.offset32,featureTableSubstitutionOffset:q.offset32})})||[]};q.prototype.parseVariationStore=function(){const n=this.relativeOffset,e=this.parseUShort(),t={itemVariationStore:this.parseItemVariationStore()};return this.relativeOffset=n+e+2,t};q.prototype.parseItemVariationStore=function(){const n=this.relativeOffset,e={format:this.parseUShort(),variationRegions:[],itemVariationSubtables:[]},t=this.parseOffset32(),i=this.parseUShort(),s=this.parseULongList(i);this.relativeOffset=n+t,e.variationRegions=this.parseVariationRegionList();for(let r=0;r<i;r++){const a=s[r];this.relativeOffset=n+a,e.itemVariationSubtables.push(this.parseItemVariationSubtable())}return e};q.prototype.parseVariationRegionList=function(){const n=this.parseUShort(),e=this.parseUShort();return this.parseRecordList(e,{regionAxes:q.recordList(n,{startCoord:q.f2Dot14,peakCoord:q.f2Dot14,endCoord:q.f2Dot14})})};q.prototype.parseItemVariationSubtable=function(){const n=this.parseUShort(),e=this.parseUShort(),t=this.parseUShortList(),i=t.length;return{regionIndexes:t,deltaSets:n&&i?this.parseDeltaSets(n,e,i):[]}};q.prototype.parseDeltaSetIndexMap=function(){const n=this.parseByte(),e=this.parseByte(),t=[];let i=0;switch(n){case 0:i=this.parseUShort();break;case 1:i=this.parseULong();break;default:console.error(`unsupported DeltaSetIndexMap format ${n}`)}if(!i)return{format:n,entryFormat:e};const s=(e&jt.INNER_INDEX_BIT_COUNT_MASK)+1,r=((e&jt.MAP_ENTRY_SIZE_MASK)>>4)+1;for(let a=0;a<i;a++){let o;if(r===1)o=this.parseByte();else if(r===2)o=this.parseUShort();else if(r===3)o=this.parseUInt24();else if(r===4)o=this.parseULong();else throw new Error(`Invalid entry size of ${r}`);const l=o>>s,c=o&(1<<s)-1;t.push({outerIndex:l,innerIndex:c})}return{format:n,entryFormat:e,map:t}};q.prototype.parseDeltaSets=function(n,e,t){const i=Array.from({length:n},()=>[]),s=e&jt.LONG_WORDS,r=e&jt.WORD_DELTA_COUNT_MASK;if(r>t)throw Error("wordCount must be less than or equal to regionIndexCount");const a=(s?this.parseLong:this.parseShort).bind(this),o=(s?this.parseShort:this.parseChar).bind(this);for(let l=0;l<n;l++)for(let c=0;c<t;c++)c<r?i[l].push(a()):i[l].push(o());return i};q.prototype.parseTupleVariationStoreList=function(n,e,t){const i=this.parseUShort(),r=this.parseUShort()&1,a=this.parseOffset32(),o=(r?this.parseULong:this.parseUShort).bind(this),l={};let c=o();r||(c*=2);let u;for(let f=0;f<i;f++){u=o(),r||(u*=2);const h=u-c;l[f]=h?this.parseTupleVariationStore(a+c,n,e,t,f):void 0,c=u}return l};q.prototype.parseTupleVariationStore=function(n,e,t,i,s){const r=this.relativeOffset;this.relativeOffset=n,t==="cvar"&&(this.relativeOffset+=4);const a=this.parseUShort(),o=!!(a&jt.SHARED_POINT_NUMBERS),l=a&jt.COUNT_MASK;let c=this.parseOffset16();const u=[];let f=[];for(let p=0;p<l;p++){const x=this.parseTupleVariationHeader(e,t);u.push(x)}this.relativeOffset!==n+c&&(console.warn(`Unexpected offset after parsing tuple variation headers! Expected ${n+c}, actually ${this.relativeOffset}`),this.relativeOffset=n+c),o&&(f=this.parsePackedPointNumbers());let h=this.relativeOffset;for(let p=0;p<l;p++){const x=u[p];x.privatePoints=[],this.relativeOffset=h,t==="cvar"&&!x.peakTuple&&console.warn("An embedded peak tuple is required in TupleVariationHeaders for the cvar table."),x.flags.privatePointNumbers&&(x.privatePoints=this.parsePackedPointNumbers()),delete x.flags;const m=this.offset,g=this.relativeOffset,M=E=>{let _,T;const b=()=>{let S=0;if(t==="gvar"){if(S=x.privatePoints.length||f.length,!S){const v=i.get(s);v.path,S=v.points.length,S+=4}}else t==="cvar"&&(S=i.length);this.offset=m,this.relativeOffset=g,_=this.parsePackedDeltas(S),t==="gvar"&&(T=this.parsePackedDeltas(S))};return{configurable:!0,get:function(){return _===void 0&&b(),E==="deltasY"?T:_},set:function(S){_===void 0&&b(),E==="deltasY"?T=S:_=S}}};Object.defineProperty(x,"deltas",M.call(this,"deltas")),t==="gvar"&&Object.defineProperty(x,"deltasY",M.call(this,"deltasY")),h+=x.variationDataSize,delete x.variationDataSize}this.relativeOffset=r;const d={headers:u};return d.sharedPoints=f,d};q.prototype.parseTupleVariationHeader=function(n,e){const t=this.parseUShort(),i=this.parseUShort(),s=!!(i&jt.EMBEDDED_PEAK_TUPLE),r=!!(i&jt.INTERMEDIATE_REGION),a=!!(i&jt.PRIVATE_POINT_NUMBERS),o=s?void 0:i&jt.TUPLE_INDEX_MASK,l=s?this.parseTupleRecords(1,n)[0]:void 0,c=r?this.parseTupleRecords(1,n)[0]:void 0,u=r?this.parseTupleRecords(1,n)[0]:void 0,f={variationDataSize:t,peakTuple:l,intermediateStartTuple:c,intermediateEndTuple:u,flags:{embeddedPeakTuple:s,intermediateRegion:r,privatePointNumbers:a}};return e==="gvar"&&(f.sharedTupleRecordsIndex=o),f};q.prototype.parsePackedPointNumbers=function(){const n=this.parseByte(),e=[];let t=n;if(n>=128){const s=this.parseByte();t=(n&jt.POINT_RUN_COUNT_MASK)<<8|s}let i=0;for(;e.length<t;){const s=this.parseByte(),r=!!(s&jt.POINTS_ARE_WORDS);let a=(s&jt.POINT_RUN_COUNT_MASK)+1;for(let o=0;o<a&&e.length<t;o++){let l;r?l=this.parseUShort():l=this.parseByte(),i=i+l,e.push(i)}}return e};q.prototype.parsePackedDeltas=function(n){const e=[];for(;e.length<n;){const t=this.parseByte(),i=!!(t&jt.DELTAS_ARE_ZERO),s=!!(t&jt.DELTAS_ARE_WORDS),r=(t&jt.DELTA_RUN_COUNT_MASK)+1;for(let a=0;a<r&&e.length<n;a++)i?e.push(0):s?e.push(this.parseShort()):e.push(this.parseChar())}return e};var Te={getByte:Lh,getCard8:Lh,getUShort:ao,getCard16:ao,getShort:Sb,getUInt24:kd,getULong:$c,getFixed:Bd,getTag:Eb,getOffset:Tb,getBytes:Ab,bytesToString:wb,Parser:q},oo=["copyright","fontFamily","fontSubfamily","uniqueID","fullName","version","postScriptName","trademark","manufacturer","designer","description","manufacturerURL","designerURL","license","licenseURL","reserved","preferredFamily","preferredSubfamily","compatibleFullName","sampleText","postScriptFindFontName","wwsFamily","wwsSubfamily"],Hd={0:"en",1:"fr",2:"de",3:"it",4:"nl",5:"sv",6:"es",7:"da",8:"pt",9:"no",10:"he",11:"ja",12:"ar",13:"fi",14:"el",15:"is",16:"mt",17:"tr",18:"hr",19:"zh-Hant",20:"ur",21:"hi",22:"th",23:"ko",24:"lt",25:"pl",26:"hu",27:"es",28:"lv",29:"se",30:"fo",31:"fa",32:"ru",33:"zh",34:"nl-BE",35:"ga",36:"sq",37:"ro",38:"cz",39:"sk",40:"si",41:"yi",42:"sr",43:"mk",44:"bg",45:"uk",46:"be",47:"uz",48:"kk",49:"az-Cyrl",50:"az-Arab",51:"hy",52:"ka",53:"mo",54:"ky",55:"tg",56:"tk",57:"mn-CN",58:"mn",59:"ps",60:"ks",61:"ku",62:"sd",63:"bo",64:"ne",65:"sa",66:"mr",67:"bn",68:"as",69:"gu",70:"pa",71:"or",72:"ml",73:"kn",74:"ta",75:"te",76:"si",77:"my",78:"km",79:"lo",80:"vi",81:"id",82:"tl",83:"ms",84:"ms-Arab",85:"am",86:"ti",87:"om",88:"so",89:"sw",90:"rw",91:"rn",92:"ny",93:"mg",94:"eo",128:"cy",129:"eu",130:"ca",131:"la",132:"qu",133:"gn",134:"ay",135:"tt",136:"ug",137:"dz",138:"jv",139:"su",140:"gl",141:"af",142:"br",143:"iu",144:"gd",145:"gv",146:"ga",147:"to",148:"el-polyton",149:"kl",150:"az",151:"nn"},Rb={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:5,11:1,12:4,13:0,14:6,15:0,16:0,17:0,18:0,19:2,20:4,21:9,22:21,23:3,24:29,25:29,26:29,27:29,28:29,29:0,30:0,31:4,32:7,33:25,34:0,35:0,36:0,37:0,38:29,39:29,40:0,41:5,42:7,43:7,44:7,45:7,46:7,47:7,48:7,49:7,50:4,51:24,52:23,53:7,54:7,55:7,56:7,57:27,58:7,59:4,60:4,61:4,62:4,63:26,64:9,65:9,66:9,67:13,68:13,69:11,70:10,71:12,72:17,73:16,74:14,75:15,76:18,77:19,78:20,79:22,80:30,81:0,82:0,83:0,84:4,85:28,86:28,87:28,88:0,89:0,90:0,91:0,92:0,93:0,94:0,128:0,129:0,130:0,131:0,132:0,133:0,134:0,135:7,136:4,137:26,138:0,139:0,140:0,141:0,142:0,143:28,144:0,145:0,146:0,147:0,148:6,149:0,150:0,151:0},zd={1078:"af",1052:"sq",1156:"gsw",1118:"am",5121:"ar-DZ",15361:"ar-BH",3073:"ar",2049:"ar-IQ",11265:"ar-JO",13313:"ar-KW",12289:"ar-LB",4097:"ar-LY",6145:"ary",8193:"ar-OM",16385:"ar-QA",1025:"ar-SA",10241:"ar-SY",7169:"aeb",14337:"ar-AE",9217:"ar-YE",1067:"hy",1101:"as",2092:"az-Cyrl",1068:"az",1133:"ba",1069:"eu",1059:"be",2117:"bn",1093:"bn-IN",8218:"bs-Cyrl",5146:"bs",1150:"br",1026:"bg",1027:"ca",3076:"zh-HK",5124:"zh-MO",2052:"zh",4100:"zh-SG",1028:"zh-TW",1155:"co",1050:"hr",4122:"hr-BA",1029:"cs",1030:"da",1164:"prs",1125:"dv",2067:"nl-BE",1043:"nl",3081:"en-AU",10249:"en-BZ",4105:"en-CA",9225:"en-029",16393:"en-IN",6153:"en-IE",8201:"en-JM",17417:"en-MY",5129:"en-NZ",13321:"en-PH",18441:"en-SG",7177:"en-ZA",11273:"en-TT",2057:"en-GB",1033:"en",12297:"en-ZW",1061:"et",1080:"fo",1124:"fil",1035:"fi",2060:"fr-BE",3084:"fr-CA",1036:"fr",5132:"fr-LU",6156:"fr-MC",4108:"fr-CH",1122:"fy",1110:"gl",1079:"ka",3079:"de-AT",1031:"de",5127:"de-LI",4103:"de-LU",2055:"de-CH",1032:"el",1135:"kl",1095:"gu",1128:"ha",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig",1057:"id",1117:"iu",2141:"iu-Latn",2108:"ga",1076:"xh",1077:"zu",1040:"it",2064:"it-CH",1041:"ja",1099:"kn",1087:"kk",1107:"km",1158:"quc",1159:"rw",1089:"sw",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1062:"lv",1063:"lt",2094:"dsb",1134:"lb",1071:"mk",2110:"ms-BN",1086:"ms",1100:"ml",1082:"mt",1153:"mi",1146:"arn",1102:"mr",1148:"moh",1104:"mn",2128:"mn-CN",1121:"ne",1044:"nb",2068:"nn",1154:"oc",1096:"or",1123:"ps",1045:"pl",1046:"pt",2070:"pt-PT",1094:"pa",1131:"qu-BO",2155:"qu-EC",3179:"qu",1048:"ro",1047:"rm",1049:"ru",9275:"smn",4155:"smj-NO",5179:"smj",3131:"se-FI",1083:"se",2107:"se-SE",8251:"sms",6203:"sma-NO",7227:"sms",1103:"sa",7194:"sr-Cyrl-BA",3098:"sr",6170:"sr-Latn-BA",2074:"sr-Latn",1132:"nso",1074:"tn",1115:"si",1051:"sk",1060:"sl",11274:"es-AR",16394:"es-BO",13322:"es-CL",9226:"es-CO",5130:"es-CR",7178:"es-DO",12298:"es-EC",17418:"es-SV",4106:"es-GT",18442:"es-HN",2058:"es-MX",19466:"es-NI",6154:"es-PA",15370:"es-PY",10250:"es-PE",20490:"es-PR",3082:"es",1034:"es",21514:"es-US",14346:"es-UY",8202:"es-VE",2077:"sv-FI",1053:"sv",1114:"syr",1064:"tg",2143:"tzm",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1055:"tr",1090:"tk",1152:"ug",1058:"uk",1070:"hsb",1056:"ur",2115:"uz-Cyrl",1091:"uz",1066:"vi",1106:"cy",1160:"wo",1157:"sah",1144:"ii",1130:"yo"};function Pb(n,e,t){switch(n){case 0:if(e===65535)return"und";if(t)return t[e];break;case 1:return Hd[e];case 3:return zd[e]}}var _c="utf-16",Lb={0:"macintosh",1:"x-mac-japanese",2:"x-mac-chinesetrad",3:"x-mac-korean",6:"x-mac-greek",7:"x-mac-cyrillic",9:"x-mac-devanagai",10:"x-mac-gurmukhi",11:"x-mac-gujarati",12:"x-mac-oriya",13:"x-mac-bengali",14:"x-mac-tamil",15:"x-mac-telugu",16:"x-mac-kannada",17:"x-mac-malayalam",18:"x-mac-sinhalese",19:"x-mac-burmese",20:"x-mac-khmer",21:"x-mac-thai",22:"x-mac-lao",23:"x-mac-georgian",24:"x-mac-armenian",25:"x-mac-chinesesimp",26:"x-mac-tibetan",27:"x-mac-mongolian",28:"x-mac-ethiopic",29:"x-mac-ce",30:"x-mac-vietnamese",31:"x-mac-extarabic"},Db={15:"x-mac-icelandic",17:"x-mac-turkish",18:"x-mac-croatian",24:"x-mac-ce",25:"x-mac-ce",26:"x-mac-ce",27:"x-mac-ce",28:"x-mac-ce",30:"x-mac-icelandic",37:"x-mac-romanian",38:"x-mac-ce",39:"x-mac-ce",40:"x-mac-ce",143:"x-mac-inuit",146:"x-mac-gaelic"};function Zc(n,e,t){switch(n){case 0:return _c;case 1:return Db[t]||Lb[e];case 3:if(e===1||e===10)return _c;break}}var Gd={0:"unicode",1:"macintosh",2:"reserved",3:"windows"};function Ib(n){return Gd[n]}function Ub(n,e,t){const i={},s=new Te.Parser(n,e),r=s.parseUShort(),a=s.parseUShort(),o=s.offset+s.parseUShort();for(let l=0;l<a;l++){const c=s.parseUShort(),u=s.parseUShort(),f=s.parseUShort(),h=s.parseUShort(),d=oo[h]||h,p=s.parseUShort(),x=s.parseUShort(),m=Pb(c,f,t),g=Zc(c,u,f),M=Ib(c);if(g!==void 0&&m!==void 0&&M!==void 0){let E;if(g===_c?E=$s.UTF16(n,o+x,p):E=$s.MACSTRING(n,o+x,p,g),E){let _=i[M];_===void 0&&(_=i[M]={});let T=_[d];T===void 0&&(T=_[d]={}),T[m]=E}}}return r===1&&s.parseUShort(),i}function Aa(n){const e={};for(let t in n)e[n[t]]=parseInt(t);return e}function Ih(n,e,t,i,s,r){return new me.Record("NameRecord",[{name:"platformID",type:"USHORT",value:n},{name:"encodingID",type:"USHORT",value:e},{name:"languageID",type:"USHORT",value:t},{name:"nameID",type:"USHORT",value:i},{name:"length",type:"USHORT",value:s},{name:"offset",type:"USHORT",value:r}])}function Ob(n,e){const t=n.length,i=e.length-t+1;e:for(let s=0;s<i;s++)for(;s<i;s++){for(let r=0;r<t;r++)if(e[s+r]!==n[r])continue e;return s}return-1}function Uh(n,e){let t=Ob(n,e);if(t<0){t=e.length;let i=0;const s=n.length;for(;i<s;++i)e.push(n[i])}return t}function Fb(n,e){const t=Aa(Gd),i=Aa(Hd),s=Aa(zd),r=[],a=[];for(let l in n){let c;const u=[],f={},h=Aa(oo),d=t[l];for(let p in n[l]){let x=h[p];if(x===void 0&&(x=p),c=parseInt(x),isNaN(c))throw new Error('Name table entry "'+p+'" does not exist, see nameTableNames for complete list.');f[c]=n[l][p],u.push(c)}for(let p=0;p<u.length;p++){c=u[p];const x=f[c];for(let m in x){const g=x[m];if(d===1||d===0){let M=i[m],E=Rb[M];const _=Zc(d,E,M);let T=Se.MACSTRING(g,_);if(d===0&&(M=e.indexOf(m),M<0&&(M=e.length,e.push(m)),E=4,T=Se.UTF16(g)),T!==void 0){const b=Uh(T,a);r.push(Ih(d,E,M,c,T.length,b))}}if(d===3){const M=s[m];if(M!==void 0){const E=Se.UTF16(g),_=Uh(E,a);r.push(Ih(3,1,M,c,E.length,_))}}}}}r.sort(function(l,c){return l.platformID-c.platformID||l.encodingID-c.encodingID||l.languageID-c.languageID||l.nameID-c.nameID});const o=new me.Table("name",[{name:"format",type:"USHORT",value:0},{name:"count",type:"USHORT",value:r.length},{name:"stringOffset",type:"USHORT",value:6+r.length*12}]);for(let l=0;l<r.length;l++)o.fields.push({name:"record_"+l,type:"RECORD",value:r[l]});return o.fields.push({name:"strings",type:"LITERAL",value:a}),o}function lo(n,e,t=[]){if(e<256&&e in oo){if(t.length&&!t.includes(parseInt(e)))return;e=oo[e]}for(let i in n)for(let s in n[i])if(s===e||parseInt(s)===e)return n[i][s]}var Vd={parse:Ub,make:Fb,getNameByID:lo};function Nb(n,e,t,i){n.length=e.parseUShort(),n.language=e.parseUShort()-1;const s=e.parseByteList(n.length),r=Object.assign({},s),a=Zc(t,i,n.language),o=eo[a];for(let l=0;l<o.length;l++)r[o.charCodeAt(l)]=s[128+l];n.glyphIndexMap=r}function kb(n,e,t){e.parseUShort(),n.length=e.parseULong(),n.language=e.parseULong();let i;n.groupCount=i=e.parseULong(),n.glyphIndexMap={};for(let s=0;s<i;s+=1){const r=e.parseULong(),a=e.parseULong();let o=e.parseULong();for(let l=r;l<=a;l+=1)n.glyphIndexMap[l]=o,t===12&&o++}}function Bb(n,e,t,i,s){n.length=e.parseUShort(),n.language=e.parseUShort();let r;n.segCount=r=e.parseUShort()>>1,e.skip("uShort",3),n.glyphIndexMap={};const a=new Te.Parser(t,i+s+14),o=new Te.Parser(t,i+s+16+r*2),l=new Te.Parser(t,i+s+16+r*4),c=new Te.Parser(t,i+s+16+r*6);let u=i+s+16+r*8;for(let f=0;f<r-1;f+=1){let h;const d=a.parseUShort(),p=o.parseUShort(),x=l.parseShort(),m=c.parseUShort();for(let g=p;g<=d;g+=1)m!==0?(u=c.offset+c.relativeOffset-2,u+=m,u+=(g-p)*2,h=Te.getUShort(t,u),h!==0&&(h=h+x&65535)):h=g+x&65535,n.glyphIndexMap[g]=h}}function Hb(n,e){const t={};e.skip("uLong");const i=e.parseULong();for(let s=0;s<i;s+=1){const r=e.parseUInt24(),a={varSelector:r},o=e.parseOffset32(),l=e.parseOffset32(),c=e.relativeOffset;o&&(e.relativeOffset=o,a.defaultUVS=e.parseStruct({ranges:function(){return e.parseRecordList32({startUnicodeValue:e.parseUInt24,additionalCount:e.parseByte})}})),l&&(e.relativeOffset=l,a.nonDefaultUVS=e.parseStruct({uvsMappings:function(){const u={},f=e.parseRecordList32({unicodeValue:e.parseUInt24,glyphID:e.parseUShort});for(let h=0;h<f.length;h+=1)u[f[h].unicodeValue]=f[h];return u}})),t[r]=a,e.relativeOffset=c}n.varSelectorList=t}function zb(n,e){const t={};t.version=Te.getUShort(n,e),Ne.argument(t.version===0,"cmap table version should be 0."),t.numTables=Te.getUShort(n,e+2);let i=null,s=-1,r=-1,a=null,o=null;const l=[0,1,2,3,4,6],c=[0,1,10];for(let f=t.numTables-1;f>=0;f-=1)if(a=Te.getUShort(n,e+4+f*8),o=Te.getUShort(n,e+4+f*8+2),a===3&&c.includes(o)||a===0&&l.includes(o)||a===1&&o===0){if(r>0)continue;if(r=Te.getULong(n,e+4+f*8+4),i)break}else if(a===0&&o===5){if(s=Te.getULong(n,e+4+f*8+4),i=new Te.Parser(n,e+s),i.parseUShort()!==14)s=-1,i=null;else if(r>0)break}if(r===-1)throw new Error("No valid cmap sub-tables found.");const u=new Te.Parser(n,e+r);if(t.format=u.parseUShort(),t.format===0)Nb(t,u,a,o);else if(t.format===12||t.format===13)kb(t,u,t.format);else if(t.format===4)Bb(t,u,n,e,r);else throw new Error("Only format 0 (platformId 1, encodingId 0), 4, 12 and 14 cmap tables are supported (found format "+t.format+", platformId "+a+", encodingId "+o+").");return i&&Hb(t,i),t}function Gb(n,e,t){n.segments.push({end:e,start:e,delta:-(e-t),offset:0,glyphIndex:t})}function Vb(n){n.segments.push({end:65535,start:65535,delta:1,offset:0})}function Wb(n){if(n.length===0)return n;const e=[n[0]];for(let t=1;t<n.length;t++){const i=e[e.length-1],s=n[t];i.end+1===s.start&&i.delta===s.delta&&s.end!==65535?i.end=s.end:e.push(s)}return e}function Xb(n){let e=!0,t;for(t=n.length-1;t>0;t-=1)if(n.get(t).unicode>65535){e=!1;break}let i=[{name:"version",type:"USHORT",value:0},{name:"numTables",type:"USHORT",value:e?1:2},{name:"platformID",type:"USHORT",value:3},{name:"encodingID",type:"USHORT",value:1},{name:"offset",type:"ULONG",value:e?12:20}];e||i.push({name:"cmap12PlatformID",type:"USHORT",value:3},{name:"cmap12EncodingID",type:"USHORT",value:10},{name:"cmap12Offset",type:"ULONG",value:0}),i.push({name:"format",type:"USHORT",value:4},{name:"cmap4Length",type:"USHORT",value:0},{name:"language",type:"USHORT",value:0},{name:"segCountX2",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0});const s=new me.Table("cmap",i);for(s.segments=[],t=0;t<n.length;t+=1){const d=n.get(t);for(let p=0;p<d.unicodes.length;p+=1)Gb(s,d.unicodes[p],t)}s.segments.sort(function(d,p){return d.start-p.start}),s.segments=Wb(s.segments),Vb(s);const r=s.segments.length;let a=0,o=[],l=[],c=[],u=[],f=[],h=[];for(t=0;t<r;t+=1){const d=s.segments[t];d.end<=65535&&d.start<=65535?(o.push({name:"end_"+t,type:"USHORT",value:d.end}),l.push({name:"start_"+t,type:"USHORT",value:d.start}),c.push({name:"idDelta_"+t,type:"SHORT",value:d.delta}),u.push({name:"idRangeOffset_"+t,type:"USHORT",value:d.offset}),d.glyphId!==void 0&&f.push({name:"glyph_"+t,type:"USHORT",value:d.glyphId})):a+=1,!e&&d.glyphIndex!==void 0&&(h.push({name:"cmap12Start_"+t,type:"ULONG",value:d.start}),h.push({name:"cmap12End_"+t,type:"ULONG",value:d.end}),h.push({name:"cmap12Glyph_"+t,type:"ULONG",value:d.glyphIndex}))}s.segCountX2=(r-a)*2,s.searchRange=Math.pow(2,Math.floor(Math.log(r-a)/Math.log(2)))*2,s.entrySelector=Math.log(s.searchRange/2)/Math.log(2),s.rangeShift=s.segCountX2-s.searchRange;for(let d=0;d<o.length;d++)s.fields.push(o[d]);s.fields.push({name:"reservedPad",type:"USHORT",value:0});for(let d=0;d<l.length;d++)s.fields.push(l[d]);for(let d=0;d<c.length;d++)s.fields.push(c[d]);for(let d=0;d<u.length;d++)s.fields.push(u[d]);for(let d=0;d<f.length;d++)s.fields.push(f[d]);if(s.cmap4Length=14+o.length*2+2+l.length*2+c.length*2+u.length*2+f.length*2,!e){const d=16+h.length*4;s.cmap12Offset=12+2*2+4+s.cmap4Length,s.fields.push({name:"cmap12Format",type:"USHORT",value:12},{name:"cmap12Reserved",type:"USHORT",value:0},{name:"cmap12Length",type:"ULONG",value:d},{name:"cmap12Language",type:"ULONG",value:0},{name:"cmap12nGroups",type:"ULONG",value:h.length/3});for(let p=0;p<h.length;p++)s.fields.push(h[p])}return s}var Wd={parse:zb,make:Xb},Ha=[".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","questiondown","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi","lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree","thorn","threequarters","twosuperior","registered","minus","eth","multiply","threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring","Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde","ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve","otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute","ydieresis","zcaron","exclamsmall","Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","266 ff","onedotenleader","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior","threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","ffi","ffl","parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash","hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall","001.000","001.001","001.002","001.003","Black","Bold","Book","Light","Medium","Regular","Roman","Semibold"],Yb=[".notdef","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","endash","dagger","daggerdbl","periodcentered","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","questiondown","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash","AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae","dotlessi","lslash","oslash","oe","germandbls","onesuperior","logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn","onequarter","divide","brokenbar","degree","thorn","threequarters","twosuperior","registered","minus","eth","multiply","threesuperior","copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring","Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute","Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute","Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron","aacute","acircumflex","adieresis","agrave","aring","atilde","ccedilla","eacute","ecircumflex","edieresis","egrave","iacute","icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex","odieresis","ograve","otilde","scaron","uacute","ucircumflex","udieresis","ugrave","yacute","ydieresis","zcaron"],qb=[".notdef","space","exclamsmall","Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","questionsmall","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","fi","fl","ffi","ffl","parenleftinferior","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","Dotaccentsmall","Macronsmall","figuredash","hypheninferior","Ogoneksmall","Ringsmall","Cedillasmall","onequarter","onehalf","threequarters","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall"],$b=[".notdef","space","dollaroldstyle","dollarsuperior","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","asuperior","bsuperior","centsuperior","dsuperior","esuperior","isuperior","lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior","tsuperior","ff","fi","fl","ffi","ffl","parenleftinferior","parenrightinferior","hyphensuperior","colonmonetary","onefitted","rupiah","centoldstyle","figuredash","hypheninferior","onequarter","onehalf","threequarters","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior"],bc=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quoteright","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","quoteleft","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdown","cent","sterling","fraction","yen","florin","section","currency","quotesingle","quotedblleft","guillemotleft","guilsinglleft","guilsinglright","fi","fl","","endash","dagger","daggerdbl","periodcentered","","paragraph","bullet","quotesinglbase","quotedblbase","quotedblright","guillemotright","ellipsis","perthousand","","questiondown","","grave","acute","circumflex","tilde","macron","breve","dotaccent","dieresis","","ring","cedilla","","hungarumlaut","ogonek","caron","emdash","","","","","","","","","","","","","","","","","AE","","ordfeminine","","","","","Lslash","Oslash","OE","ordmasculine","","","","","","ae","","","","dotlessi","","","lslash","oslash","oe","germandbls"],Zb=["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","space","exclamsmall","Hungarumlautsmall","","dollaroldstyle","dollarsuperior","ampersandsmall","Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader","onedotenleader","comma","hyphen","period","fraction","zerooldstyle","oneoldstyle","twooldstyle","threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle","sevenoldstyle","eightoldstyle","nineoldstyle","colon","semicolon","commasuperior","threequartersemdash","periodsuperior","questionsmall","","asuperior","bsuperior","centsuperior","dsuperior","esuperior","","","isuperior","","","lsuperior","msuperior","nsuperior","osuperior","","","rsuperior","ssuperior","tsuperior","","ff","fi","fl","ffi","ffl","parenleftinferior","","parenrightinferior","Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall","Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall","Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall","Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall","Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah","Tildesmall","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","exclamdownsmall","centoldstyle","Lslashsmall","","","Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall","","Dotaccentsmall","","","Macronsmall","","","figuredash","hypheninferior","","","Ogoneksmall","Ringsmall","Cedillasmall","","","","onequarter","onehalf","threequarters","questiondownsmall","oneeighth","threeeighths","fiveeighths","seveneighths","onethird","twothirds","","","zerosuperior","onesuperior","twosuperior","threesuperior","foursuperior","fivesuperior","sixsuperior","sevensuperior","eightsuperior","ninesuperior","zeroinferior","oneinferior","twoinferior","threeinferior","fourinferior","fiveinferior","sixinferior","seveninferior","eightinferior","nineinferior","centinferior","dollarinferior","periodinferior","commainferior","Agravesmall","Aacutesmall","Acircumflexsmall","Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall","Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall","Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall","Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall","Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall","Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall","Thornsmall","Ydieresissmall"],Ki=[".notdef",".null","nonmarkingreturn","space","exclam","quotedbl","numbersign","dollar","percent","ampersand","quotesingle","parenleft","parenright","asterisk","plus","comma","hyphen","period","slash","zero","one","two","three","four","five","six","seven","eight","nine","colon","semicolon","less","equal","greater","question","at","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft","backslash","bracketright","asciicircum","underscore","grave","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","braceleft","bar","braceright","asciitilde","Adieresis","Aring","Ccedilla","Eacute","Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex","adieresis","atilde","aring","ccedilla","eacute","egrave","ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis","ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute","ugrave","ucircumflex","udieresis","dagger","degree","cent","sterling","section","bullet","paragraph","germandbls","registered","copyright","trademark","acute","dieresis","notequal","AE","Oslash","infinity","plusminus","lessequal","greaterequal","yen","mu","partialdiff","summation","product","pi","integral","ordfeminine","ordmasculine","Omega","ae","oslash","questiondown","exclamdown","logicalnot","radical","florin","approxequal","Delta","guillemotleft","guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde","Otilde","OE","oe","endash","emdash","quotedblleft","quotedblright","quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis","fraction","currency","guilsinglleft","guilsinglright","fi","fl","daggerdbl","periodcentered","quotesinglbase","quotedblbase","perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave","Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex","apple","Ograve","Uacute","Ucircumflex","Ugrave","dotlessi","circumflex","tilde","macron","breve","dotaccent","ring","cedilla","hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron","Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn","thorn","minus","multiply","onesuperior","twosuperior","threesuperior","onehalf","onequarter","threequarters","franc","Gbreve","gbreve","Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron","dcroat"];function Xd(n){this.font=n}Xd.prototype.charToGlyphIndex=function(n){const e=n.codePointAt(0),t=this.font.glyphs;if(t)for(let i=0;i<t.length;i+=1){const s=t.get(i);for(let r=0;r<s.unicodes.length;r+=1)if(s.unicodes[r]===e)return i}return null};function Yd(n){this.cmap=n}Yd.prototype.charToGlyphIndex=function(n){return this.cmap.glyphIndexMap[n.codePointAt(0)]||0};function qd(n,e){this.encoding=n,this.charset=e}qd.prototype.charToGlyphIndex=function(n){const e=n.codePointAt(0),t=this.encoding[e];return this.charset.indexOf(t)};function Kc(n){switch(n.version){case 1:this.names=Ki.slice();break;case 2:this.names=new Array(n.numberOfGlyphs);for(let e=0;e<n.numberOfGlyphs;e++)n.glyphNameIndex[e]<Ki.length?this.names[e]=Ki[n.glyphNameIndex[e]]:this.names[e]=n.names[n.glyphNameIndex[e]-Ki.length];break;case 2.5:this.names=new Array(n.numberOfGlyphs);for(let e=0;e<n.numberOfGlyphs;e++)this.names[e]=Ki[e+n.glyphNameIndex[e]];break;case 3:this.names=[];break;default:this.names=[];break}}Kc.prototype.nameToGlyphIndex=function(n){return this.names.indexOf(n)};Kc.prototype.glyphIndexToName=function(n){return this.names[n]};function Kb(n){let e;const t=n.tables.cmap.glyphIndexMap,i=Object.keys(t);for(let s=0;s<i.length;s+=1){const r=i[s],a=t[r];e=n.glyphs.get(a),e.addUnicode(parseInt(r))}for(let s=0;s<n.glyphs.length;s+=1)e=n.glyphs.get(s),n.cffEncoding?e.name=n.cffEncoding.charset[s]:n.glyphNames.names&&(e.name=n.glyphNames.glyphIndexToName(s))}function Jb(n){n._IndexToUnicodeMap={};const e=n.tables.cmap.glyphIndexMap,t=Object.keys(e);for(let i=0;i<t.length;i+=1){const s=t[i];let r=e[s];n._IndexToUnicodeMap[r]===void 0?n._IndexToUnicodeMap[r]={unicodes:[parseInt(s)]}:n._IndexToUnicodeMap[r].unicodes.push(parseInt(s))}}function jb(n,e){e.lowMemory?Jb(n):Kb(n)}function Qb(n,e,t,i,s){n.beginPath(),n.moveTo(e,t),n.lineTo(i,s),n.stroke()}var Yi={line:Qb};function e1(n,e){const t=new q(n,e),i=t.parseShort();i!==0&&console.warn("Only CPALv0 is currently fully supported.");const s=t.parseShort(),r=t.parseShort(),a=t.parseShort(),o=t.parseOffset32(),l=t.parseUShortList(r);t.relativeOffset=o;const c=t.parseULongList(a);return t.relativeOffset=o,{version:i,numPaletteEntries:s,colorRecords:c,colorRecordIndices:l}}function t1({version:n=0,numPaletteEntries:e=0,colorRecords:t=[],colorRecordIndices:i=[0]}){return Ne.argument(n===0,"Only CPALv0 are supported."),Ne.argument(t.length,"No colorRecords given."),Ne.argument(i.length,"No colorRecordIndices given."),i.length>1&&Ne.argument(e,"Can't infer numPaletteEntries on multiple colorRecordIndices"),new me.Table("CPAL",[{name:"version",type:"USHORT",value:n},{name:"numPaletteEntries",type:"USHORT",value:e||t.length},{name:"numPalettes",type:"USHORT",value:i.length},{name:"numColorRecords",type:"USHORT",value:t.length},{name:"colorRecordsArrayOffset",type:"ULONG",value:12+2*i.length},...i.map((s,r)=>({name:"colorRecordIndices_"+r,type:"USHORT",value:s})),...t.map((s,r)=>({name:"colorRecords_"+r,type:"ULONG",value:s}))])}function $d(n){var e=(n&4278190080)>>24,t=(n&16711680)>>16,i=(n&65280)>>8,s=n&255;return e=e+256&255,t=t+256&255,i=i+256&255,s=(s+256&255)/255,{b:e,g:t,r:i,a:s}}function Jc(n,e,t=0,i="hexa"){if(e==65535)return"currentColor";const s=n&&n.tables&&n.tables.cpal;if(!s)return"currentColor";if(t>s.colorRecordIndices.length-1)throw new Error(`Palette index out of range (colorRecordIndices.length: ${s.colorRecordIndices.length}, index: ${e})`);if(e>s.numPaletteEntries)throw new Error(`Color index out of range (numPaletteEntries: ${s.numPaletteEntries}, index: ${e})`);const r=s.colorRecordIndices[t]+e;if(r>s.colorRecords)throw new Error(`Color index out of range (colorRecords.length: ${s.colorRecords.length}, lookupIndex: ${r})`);const a=$d(s.colorRecords[r]);return i==="bgra"?a:Js(a,i)}function Rn(n){return("0"+parseInt(n).toString(16)).slice(-2)}function n1(n){const e=n.r/255,t=n.g/255,i=n.b/255,s=Math.max(e,t,i),r=Math.min(e,t,i);let a,o,l=(s+r)/2;if(s===r)a=o=0;else{const c=s-r;switch(o=l>.5?c/(2-s-r):c/(s+r),s){case e:a=(t-i)/c+(t<i?6:0);break;case t:a=(i-e)/c+2;break;case i:a=(e-t)/c+4;break}a/=6}return{h:a*360,s:o*100,l:l*100}}function i1(n){let{h:e,s:t,l:i,a:s}=n;e=e%360,t/=100,i/=100;const r=(1-Math.abs(2*i-1))*t,a=r*(1-Math.abs(e/60%2-1)),o=i-r/2;let l=0,c=0,u=0;return 0<=e&&e<60?(l=r,c=a,u=0):60<=e&&e<120?(l=a,c=r,u=0):120<=e&&e<180?(l=0,c=r,u=a):180<=e&&e<240?(l=0,c=a,u=r):240<=e&&e<300?(l=a,c=0,u=r):300<=e&&e<=360&&(l=r,c=0,u=a),{r:Math.round((l+o)*255),g:Math.round((c+o)*255),b:Math.round((u+o)*255),a:s}}function Zd(n){return parseInt(`0x${Rn(n.b)}${Rn(n.g)}${Rn(n.r)}${Rn(n.a*255)}`,16)}function co(n,e="hexa"){const t=e=="raw"||e=="cpal",i=Number.isInteger(n);let s=!0;if(i&&t||n==="currentColor")return n;if(typeof n=="object"){if(e=="bgra")return n;if(t)return Zd(n)}else if(!i&&/^#([a-f0-9]{3}|[a-f0-9]{4}|[a-f0-9]{6}|[a-f0-9]{8})$/i.test(n.trim())){switch(n=n.trim().substring(1),n.length){case 3:n={r:parseInt(n[0].repeat(2),16),g:parseInt(n[1].repeat(2),16),b:parseInt(n[2].repeat(2),16),a:1};break;case 4:n={r:parseInt(n[0].repeat(2),16),g:parseInt(n[1].repeat(2),16),b:parseInt(n[2].repeat(2),16),a:parseInt(n[3].repeat(2),16)/255};break;case 6:n={r:parseInt(n[0]+n[1],16),g:parseInt(n[2]+n[3],16),b:parseInt(n[4]+n[5],16),a:1};break;case 8:n={r:parseInt(n[0]+n[1],16),g:parseInt(n[2]+n[3],16),b:parseInt(n[4]+n[5],16),a:parseInt(n[6]+n[7],16)/255};break}if(e=="bgra")return n}else if(typeof document<"u"&&/^[a-z]+$/i.test(n)){const r=document.createElement("canvas").getContext("2d");r.fillStyle=n;const a=Js(r.fillStyle,"hexa");a==="#000000ff"&&n.toLowerCase()!=="black"?s=!1:n=a}else{n=n.trim();const r=/rgba?\(\s*(?:(\d*\.\d+)(%?)|(\d+)(%?))\s*(?:,|\s*)\s*(?:(\d*\.\d+)(%?)|(\d+)(%?))\s*(?:,|\s*)\s*(?:(\d*\.\d+)(%?)|(\d+)(%?))\s*(?:(?:,|\s|\/)\s*(?:(0*(?:\.\d+)?()|0*1(?:\.0+)?())|(?:\.\d+)|(\d+)(%)|(\d*\.\d+)(%)))?\s*\)/;if(r.test(n)){const a=n.match(r).filter(o=>typeof o<"u");n={r:Math.round(parseFloat(a[1])/(a[2]?100/255:1)),g:Math.round(parseFloat(a[3])/(a[4]?100/255:1)),b:Math.round(parseFloat(a[5])/(a[6]?100/255:1)),a:a[7]?parseFloat(a[7])/(a[8]?100:1):1}}else{const a=/hsla?\(\s*(?:(\d*\.\d+|\d+)(deg|turn|))\s*(?:,|\s*)\s*(?:(\d*\.\d+)%?|(\d+)%?)\s*(?:,|\s*)\s*(?:(\d*\.\d+)%?|(\d+)%?)\s*(?:(?:,|\s|\/)\s*(?:(0*(?:\.\d+)?()|0*1(?:\.0+)?())|(?:\.\d+)|(\d+)(%)|(\d*\.\d+)(%)))?\s*\)/;if(a.test(n)){const o=n.match(a).filter(l=>typeof l<"u");n=i1({h:parseFloat(o[1])*(o[2]==="turn"?360:1),s:parseFloat(o[3]),l:parseFloat(o[4]),a:o[5]?parseFloat(o[5])/(o[6]?100:1):1})}else s=!1}}if(!s)throw new Error(`Invalid color format: ${n}`);return Js(n,e)}function Js(n,e="hexa"){if(n==="currentColor")return n;if(Number.isInteger(n)){if(e=="raw"||e=="cpal")return n;n=$d(n)}else typeof n!="object"&&(n=co(n,"bgra"));let t=["hsl","hsla"].includes(e)?n1(n):null;switch(e){case"rgba":return`rgba(${n.r}, ${n.g}, ${n.b}, ${parseFloat(n.a.toFixed(3))})`;case"rgb":return`rgb(${n.r}, ${n.g}, ${n.b})`;case"hex":case"hex6":case"hex-6":return`#${Rn(n.r)}${Rn(n.g)}${Rn(n.b)}`;case"hexa":case"hex8":case"hex-8":return`#${Rn(n.r)}${Rn(n.g)}${Rn(n.b)}${Rn(n.a*255)}`;case"hsl":return`hsl(${t.h.toFixed(2)}, ${t.s.toFixed(2)}%, ${t.l.toFixed(2)}%)`;case"hsla":return`hsla(${t.h.toFixed(2)}, ${t.s.toFixed(2)}%, ${t.l.toFixed(2)}%, ${parseFloat(n.a.toFixed(3))})`;case"bgra":return n;case"raw":case"cpal":return Zd(n);default:throw new Error("Unknown color format: "+e)}}var Kd={parse:e1,make:t1,getPaletteColor:Jc,parseColor:co,formatColor:Js};function s1(n,e){let t=e||new qs;return{configurable:!0,get:function(){return typeof t=="function"&&(t=t()),t},set:function(i){t=i}}}function en(n){this.bindConstructorValues(n)}en.prototype.bindConstructorValues=function(n){if(this.index=n.index||0,n.name===".notdef"?n.unicode=void 0:n.name===".null"&&(n.unicode=0),n.unicode===0&&n.name!==".null")throw new Error('The unicode value "0" is reserved for the glyph name ".null" and cannot be used by any other glyph.');this.name=n.name||null,this.unicode=n.unicode,this.unicodes=n.unicodes||(n.unicode!==void 0?[n.unicode]:[]),"xMin"in n&&(this.xMin=n.xMin),"yMin"in n&&(this.yMin=n.yMin),"xMax"in n&&(this.xMax=n.xMax),"yMax"in n&&(this.yMax=n.yMax),"advanceWidth"in n&&(this.advanceWidth=n.advanceWidth),"leftSideBearing"in n&&(this.leftSideBearing=n.leftSideBearing),"points"in n&&(this.points=n.points),Object.defineProperty(this,"path",s1(this,n.path))};en.prototype.addUnicode=function(n){this.unicodes.length===0&&(this.unicode=n),this.unicodes.push(n)};en.prototype.getBoundingBox=function(){return this.path.getBoundingBox()};en.prototype.getPath=function(n,e,t,i,s){n=n!==void 0?n:0,e=e!==void 0?e:0,t=t!==void 0?t:72,i=Object.assign({},s&&s.defaultRenderOptions,i);let r,a,o=i.xScale,l=i.yScale;const c=1/(this.path.unitsPerEm||1e3)*t;let u=this;s&&s.variation&&(u=s.variation.getTransform(this,i.variation),r=u.path.commands),i.hinting&&s&&s.hinting&&(a=u.path&&s.hinting.exec(u,t,i)),a?(r=s.hinting.getCommands(a),n=Math.round(n),e=Math.round(e),o=l=1):(r=u.path.commands,o===void 0&&(o=c),l===void 0&&(l=c));const f=new qs;if(i.drawSVG){const h=this.getSvgImage(s);if(h){const d=new qs;return d._image={image:h.image,x:n+h.leftSideBearing*c,y:e-h.baseline*c,width:h.image.width*c,height:h.image.height*c},f._layers=[d],f}}if(i.drawLayers){const h=this.getLayers(s);if(h&&h.length){f._layers=[];for(let d=0;d<h.length;d+=1){const p=h[d];let x=Jc(s,p.paletteIndex,i.usePalette);x==="currentColor"?x=i.fill||"black":x=Js(x,i.colorFormat||"rgba"),i=Object.assign({},i,{fill:x}),f._layers.push(this.getPath.call(p.glyph,n,e,t,i,s))}return f}}f.fill=i.fill||this.path.fill,f.stroke=this.path.stroke,f.strokeWidth=this.path.strokeWidth*c;for(let h=0;h<r.length;h+=1){const d=r[h];d.type==="M"?f.moveTo(n+d.x*o,e+-d.y*l):d.type==="L"?f.lineTo(n+d.x*o,e+-d.y*l):d.type==="Q"?f.quadraticCurveTo(n+d.x1*o,e+-d.y1*l,n+d.x*o,e+-d.y*l):d.type==="C"?f.curveTo(n+d.x1*o,e+-d.y1*l,n+d.x2*o,e+-d.y2*l,n+d.x*o,e+-d.y*l):d.type==="Z"&&f.stroke&&f.strokeWidth&&f.closePath()}return f};en.prototype.getLayers=function(n){if(!n)throw new Error("The font object is required to read the colr/cpal tables in order to get the layers.");return n.layers.get(this.index)};en.prototype.getSvgImage=function(n){if(!n)throw new Error("The font object is required to read the svg table in order to get the image.");return n.svgImages.get(this.index)};en.prototype.getContours=function(n=null){if(this.points===void 0&&!n)return[];const e=[];let t=[],i=n||this.points;for(let s=0;s<i.length;s+=1){const r=i[s];t.push(r),r.lastPointOfContour&&(e.push(t),t=[])}return Ne.argument(t.length===0,"There are still points left in the current contour."),e};en.prototype.getMetrics=function(){const n=this.path.commands,e=[],t=[];for(let s=0;s<n.length;s+=1){const r=n[s];r.type!=="Z"&&(e.push(r.x),t.push(r.y)),(r.type==="Q"||r.type==="C")&&(e.push(r.x1),t.push(r.y1)),r.type==="C"&&(e.push(r.x2),t.push(r.y2))}const i={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,e),yMax:Math.max.apply(null,t),leftSideBearing:this.leftSideBearing};return isFinite(i.xMin)||(i.xMin=0),isFinite(i.xMax)||(i.xMax=this.advanceWidth),isFinite(i.yMin)||(i.yMin=0),isFinite(i.yMax)||(i.yMax=0),i.rightSideBearing=this.advanceWidth-i.leftSideBearing-(i.xMax-i.xMin),i};en.prototype.draw=function(n,e,t,i,s,r){s=Object.assign({},r&&r.defaultRenderOptions,s),this.getPath(e,t,i,s,r).draw(n)};en.prototype.drawPoints=function(n,e,t,i,s,r){if(s=Object.assign({},r&&r.defaultRenderOptions,s),s.drawLayers){const h=this.getLayers(r);if(h&&h.length){for(let d=0;d<h.length;d+=1)h[d].glyph.index!==this.index&&this.drawPoints.call(h[d].glyph,n,e,t,i);return}}function a(h,d,p,x){n.beginPath();for(let m=0;m<h.length;m+=1)n.moveTo(d+h[m].x*x,p+h[m].y*x),n.arc(d+h[m].x*x,p+h[m].y*x,2,0,Math.PI*2,!1);n.fill()}e=e!==void 0?e:0,t=t!==void 0?t:0,i=i!==void 0?i:24;const o=1/this.path.unitsPerEm*i,l=[],c=[];let f=this.path.commands;r&&r.variation&&(f=r.variation.getTransform(this,s.variation).path.commands);for(let h=0;h<f.length;h+=1){const d=f[h];d.x!==void 0&&l.push({x:d.x,y:-d.y}),d.x1!==void 0&&c.push({x:d.x1,y:-d.y1}),d.x2!==void 0&&c.push({x:d.x2,y:-d.y2})}n.fillStyle="blue",a(l,e,t,o),n.fillStyle="red",a(c,e,t,o)};en.prototype.drawMetrics=function(n,e,t,i){let s;e=e!==void 0?e:0,t=t!==void 0?t:0,i=i!==void 0?i:24,s=1/this.path.unitsPerEm*i,n.lineWidth=1,n.strokeStyle="black",Yi.line(n,e,-1e4,e,1e4),Yi.line(n,-1e4,t,1e4,t);const r=this.xMin||0;let a=this.yMin||0;const o=this.xMax||0;let l=this.yMax||0;const c=this.advanceWidth||0;n.strokeStyle="blue",Yi.line(n,e+r*s,-1e4,e+r*s,1e4),Yi.line(n,e+o*s,-1e4,e+o*s,1e4),Yi.line(n,-1e4,t+-a*s,1e4,t+-a*s),Yi.line(n,-1e4,t+-l*s,1e4,t+-l*s),n.strokeStyle="green",Yi.line(n,e+c*s,-1e4,e+c*s,1e4)};en.prototype.toPathData=function(n,e){n=Object.assign({},{variation:e&&e.defaultRenderOptions.variation},n);let t=this;e&&e.variation&&(t=e.variation.getTransform(this,n.variation));let i=t.points&&n.pointsTransform?n.pointsTransform(t.points):t.path;return n.pathTransform&&(i=n.pathTransform(i)),i.toPathData(n)};en.prototype.fromSVG=function(n,e={}){return this.path.fromSVG(n,e)};en.prototype.toSVG=function(n,e){const t=this.toPathData.apply(this,[n,e]);return this.path.toSVG(n,t)};en.prototype.toDOMElement=function(n,e){n=Object.assign({},{variation:e&&e.defaultRenderOptions.variation},n);let t=this.path;return e&&e.variation&&(t=e.variation.getTransform(this,n.variation).path),t.toDOMElement(n)};var Lr=en;function Us(n,e,t){Object.defineProperty(n,e,{get:function(){return typeof n[t]>"u"&&n.path,n[t]},set:function(i){n[t]=i},enumerable:!0,configurable:!0})}function yo(n,e){if(this.font=n,this.glyphs={},Array.isArray(e))for(let t=0;t<e.length;t++){const i=e[t];i.path.unitsPerEm=n.unitsPerEm,this.glyphs[t]=i}this.length=e&&e.length||0}typeof Symbol<"u"&&Symbol.iterator&&(yo.prototype[Symbol.iterator]=function(){let n=-1;return{next:(function(){n++;const e=n>=this.length-1;return{value:this.get(n),done:e}}).bind(this)}});yo.prototype.get=function(n){if(this.font._push&&this.glyphs[n]===void 0){this.font._push(n),typeof this.glyphs[n]=="function"&&(this.glyphs[n]=this.glyphs[n]());let e=this.glyphs[n],t=this.font._IndexToUnicodeMap[n];if(t)for(let i=0;i<t.unicodes.length;i++)e.addUnicode(t.unicodes[i]);this.font.cffEncoding?e.name=this.font.cffEncoding.charset[n]:this.font.glyphNames.names&&(e.name=this.font.glyphNames.glyphIndexToName(n)),this.glyphs[n].advanceWidth=this.font._hmtxTableData[n].advanceWidth,this.glyphs[n].leftSideBearing=this.font._hmtxTableData[n].leftSideBearing}else typeof this.glyphs[n]=="function"&&(this.glyphs[n]=this.glyphs[n]());return this.glyphs[n]};yo.prototype.push=function(n,e){this.glyphs[n]=e,this.length++};function r1(n,e){return new Lr({index:e,font:n})}function a1(n,e,t,i,s,r){return function(){const a=new Lr({index:e,font:n});return a.path=function(){t(a,i,s);const o=r(n.glyphs,a);return o.unitsPerEm=n.unitsPerEm,o},Us(a,"numberOfContours","_numberOfContours"),Us(a,"xMin","_xMin"),Us(a,"xMax","_xMax"),Us(a,"yMin","_yMin"),Us(a,"yMax","_yMax"),Us(a,"points","_points"),a}}function o1(n,e,t,i,s){return function(){const r=new Lr({index:e,font:n});return r.path=function(){const a=t(n,r,i,s);return a.unitsPerEm=n.unitsPerEm,a},r}}var jn={GlyphSet:yo,glyphLoader:r1,ttfGlyphLoader:a1,cffGlyphLoader:o1};function Jd(n,e){if(n===e)return!0;if(Array.isArray(n)&&Array.isArray(e)){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t+=1)if(!Jd(n[t],e[t]))return!1;return!0}else return!1}var Oh=10;function uo(n){let e;return n.length<1240?e=107:n.length<33900?e=1131:e=32768,e}function Wn(n,e,t,i){const s=[],r=[],a=i>1?Te.getULong(n,e):Te.getCard16(n,e),o=i>1?4:2;let l,c;if(a!==0){const u=Te.getByte(n,e+o);l=e+(a+1)*u+o;let f=e+o+1;for(let h=0;h<a+1;h+=1)s.push(Te.getOffset(n,f,u)),f+=u;c=l+s[a]}else c=e+o;for(let u=0;u<s.length-1;u+=1){let f=Te.getBytes(n,l+s[u],l+s[u+1]);t&&(f=t(f,n,e,i)),r.push(f)}return{objects:r,startOffset:e,endOffset:c}}function l1(n,e,t){const i=[],s=t>1?Te.getULong(n,e):Te.getCard16(n,e),r=t>1?4:2;let a,o;if(s!==0){const l=Te.getByte(n,e+r);a=e+(s+1)*l+r;let c=e+r+1;for(let u=0;u<s+1;u+=1)i.push(Te.getOffset(n,c,l)),c+=l;o=a+i[s]}else o=e+r;return{offsets:i,startOffset:e,endOffset:o}}function c1(n,e,t,i,s,r){const a=r>1?Te.getULong(t,i):Te.getCard16(t,i),o=r>1?4:2;let l=0;if(a!==0){const u=Te.getByte(t,i+o);l=i+(a+1)*u+o}return Te.getBytes(t,l+e[n],l+e[n+1])}function u1(n){let e="";const i=["0","1","2","3","4","5","6","7","8","9",".","E","E-",null,"-"];for(;;){const s=n.parseByte(),r=s>>4,a=s&15;if(r===15||(e+=i[r],a===15))break;e+=i[a]}return parseFloat(e)}function h1(n,e){let t,i,s,r;if(e===28)return t=n.parseByte(),i=n.parseByte(),t<<8|i;if(e===29)return t=n.parseByte(),i=n.parseByte(),s=n.parseByte(),r=n.parseByte(),t<<24|i<<16|s<<8|r;if(e===30)return u1(n);if(e>=32&&e<=246)return e-139;if(e>=247&&e<=250)return t=n.parseByte(),(e-247)*256+t+108;if(e>=251&&e<=254)return t=n.parseByte(),-(e-251)*256-t-108;throw new Error("Invalid b0 "+e)}function f1(n){const e={};for(let t=0;t<n.length;t+=1){const i=n[t][0],s=n[t][1];let r;if(s.length===1?r=s[0]:r=s,Object.prototype.hasOwnProperty.call(e,i)&&!isNaN(e[i]))throw new Error("Object "+e+" already has key "+i);e[i]=r}return e}function jc(n,e,t,i){e=e!==void 0?e:0;const s=new Te.Parser(n,e),r=[];let a=[];t=t!==void 0?t:n.byteLength;let o=i<2?22:28;for(;s.relativeOffset<t;){let l=s.parseByte();if(l<o){if(l===12&&(l=1200+s.parseByte()),i>1&&l===23){S1(a);continue}r.push([l,a]),a=[]}else a.push(h1(s,l))}return f1(r)}function Mr(n,e){return e<=390?e=Ha[e]:n?e=n[e-391]:e=void 0,e}function Qc(n,e,t){const i={};let s;for(let r=0;r<e.length;r+=1){const a=e[r];if(Array.isArray(a.type)){const o=[];o.length=a.type.length;for(let l=0;l<a.type.length;l++)s=n[a.op]!==void 0?n[a.op][l]:void 0,s===void 0&&(s=a.value!==void 0&&a.value[l]!==void 0?a.value[l]:null),a.type[l]==="SID"&&(s=Mr(t,s)),o[l]=s;i[a.name]=o}else s=n[a.op],s===void 0&&(s=a.value!==void 0?a.value:null),a.type==="SID"&&(s=Mr(t,s)),i[a.name]=s}return i}function d1(n,e){const t={};if(t.formatMajor=Te.getCard8(n,e),t.formatMinor=Te.getCard8(n,e+1),t.formatMajor>2)throw new Error(`Unsupported CFF table version ${t.formatMajor}.${t.formatMinor}`);return t.size=Te.getCard8(n,e+2),t.formatMajor<2?(t.offsetSize=Te.getCard8(n,e+3),t.startOffset=e,t.endOffset=e+4):(t.topDictLength=Te.getCard16(n,e+3),t.endOffset=e+8),t}var jd=[{name:"version",op:0,type:"SID"},{name:"notice",op:1,type:"SID"},{name:"copyright",op:1200,type:"SID"},{name:"fullName",op:2,type:"SID"},{name:"familyName",op:3,type:"SID"},{name:"weight",op:4,type:"SID"},{name:"isFixedPitch",op:1201,type:"number",value:0},{name:"italicAngle",op:1202,type:"number",value:0},{name:"underlinePosition",op:1203,type:"number",value:-100},{name:"underlineThickness",op:1204,type:"number",value:50},{name:"paintType",op:1205,type:"number",value:0},{name:"charstringType",op:1206,type:"number",value:2},{name:"fontMatrix",op:1207,type:["real","real","real","real","real","real"],value:[.001,0,0,.001,0,0]},{name:"uniqueId",op:13,type:"number"},{name:"fontBBox",op:5,type:["number","number","number","number"],value:[0,0,0,0]},{name:"strokeWidth",op:1208,type:"number",value:0},{name:"xuid",op:14,type:[],value:null},{name:"charset",op:15,type:"offset",value:0},{name:"encoding",op:16,type:"offset",value:0},{name:"charStrings",op:17,type:"offset",value:0},{name:"private",op:18,type:["number","offset"],value:[0,0]},{name:"ros",op:1230,type:["SID","SID","number"]},{name:"cidFontVersion",op:1231,type:"number",value:0},{name:"cidFontRevision",op:1232,type:"number",value:0},{name:"cidFontType",op:1233,type:"number",value:0},{name:"cidCount",op:1234,type:"number",value:8720},{name:"uidBase",op:1235,type:"number"},{name:"fdArray",op:1236,type:"offset"},{name:"fdSelect",op:1237,type:"offset"},{name:"fontName",op:1238,type:"SID"}],p1=[{name:"fontMatrix",op:1207,type:["real","real","real","real","real","real"],value:[.001,0,0,.001,0,0]},{name:"charStrings",op:17,type:"offset"},{name:"fdArray",op:1236,type:"offset"},{name:"fdSelect",op:1237,type:"offset"},{name:"vstore",op:24,type:"offset"}],Qd=[{name:"subrs",op:19,type:"offset",value:0},{name:"defaultWidthX",op:20,type:"number",value:0},{name:"nominalWidthX",op:21,type:"number",value:0}],m1=[{name:"blueValues",op:6,type:"delta"},{name:"otherBlues",op:7,type:"delta"},{name:"familyBlues",op:7,type:"delta"},{name:"familyBlues",op:8,type:"delta"},{name:"familyOtherBlues",op:9,type:"delta"},{name:"blueScale",op:1209,type:"number",value:.039625},{name:"blueShift",op:1210,type:"number",value:7},{name:"blueFuzz",op:1211,type:"number",value:1},{name:"stdHW",op:10,type:"number"},{name:"stdVW",op:11,type:"number"},{name:"stemSnapH",op:1212,type:"number"},{name:"stemSnapV",op:1213,type:"number"},{name:"languageGroup",op:1217,type:"number",value:0},{name:"expansionFactor",op:1218,type:"number",value:.06},{name:"vsindex",op:22,type:"number",value:0},{name:"subrs",op:19,type:"offset"}],g1=[{name:"private",op:18,type:["number","offset"],value:[0,0]}];function x1(n,e,t,i){const s=jc(n,e,n.byteLength,i);return Qc(s,i>1?p1:jd,t)}function eu(n,e,t,i,s){const r=jc(n,e,t,s);return Qc(r,s>1?m1:Qd,i)}function v1(n,e,t){const i=jc(n,e,void 0,t);return Qc(i,g1)}function y1(n,e,t){const i=[];for(let s=0;s<t.length;s++){const r=new DataView(new Uint8Array(t[s]).buffer),a=v1(r,0,2),o=a.private[0],l=a.private[1];if(o!==0&&l!==0){const c=eu(n,l+e,o,[],2);if(c.subrs){const u=l+c.subrs,f=Wn(n,u+e,void 0,2);a._subrs=f.objects,a._subrsBias=uo(a._subrs)}a._privateDict=c}i.push(a)}return i}function cl(n,e,t,i,s){const r=[];for(let a=0;a<t.length;a+=1){const o=new DataView(new Uint8Array(t[a]).buffer),l=x1(o,0,i,s);l._subrs=[],l._subrsBias=0,l._defaultWidthX=0,l._nominalWidthX=0;const c=s<2?l.private[0]:0,u=s<2?l.private[1]:0;if(c!==0&&u!==0){const f=eu(n,u+e,c,i,s);if(l._defaultWidthX=f.defaultWidthX,l._nominalWidthX=f.nominalWidthX,f.subrs!==0){const h=u+f.subrs,d=Wn(n,h+e,void 0,s);l._subrs=d.objects,l._subrsBias=uo(l._subrs)}l._privateDict=f}r.push(l)}return r}function _1(n,e,t,i,s){let r,a;const o=new Te.Parser(n,e);t-=1;const l=[".notdef"],c=o.parseCard8();if(c===0)for(let u=0;u<t;u+=1)r=o.parseSID(),s?l.push(r):l.push(Mr(i,r)||r);else if(c===1)for(;l.length<=t;){r=o.parseSID(),a=o.parseCard8();for(let u=0;u<=a;u+=1)s?l.push("cid"+("00000"+r).slice(-5)):l.push(Mr(i,r)||r),r+=1}else if(c===2)for(;l.length<=t;){r=o.parseSID(),a=o.parseCard16();for(let u=0;u<=a;u+=1)s?l.push("cid"+("00000"+r).slice(-5)):l.push(Mr(i,r)||r),r+=1}else throw new Error("Unknown charset format "+c);return l}function b1(n,e){let t;const i={},s=new Te.Parser(n,e),r=s.parseCard8();if(r===0){const a=s.parseCard8();for(let o=0;o<a;o+=1)t=s.parseCard8(),i[t]=o}else if(r===1){const a=s.parseCard8();t=1;for(let o=0;o<a;o+=1){const l=s.parseCard8(),c=s.parseCard8();for(let u=l;u<=l+c;u+=1)i[u]=t,t+=1}}else throw new Error("Unknown encoding format "+r);return i}function S1(n){let e=n.pop();for(;n.length>e;)n.pop()}function ep(n,e){const t=n.tables.cff&&n.tables.cff.topDict&&n.tables.cff.topDict.paintType||0;return t===2&&(e.fill=null,e.stroke="black",e.strokeWidth=n.tables.cff.topDict.strokeWidth||0),t}function Sc(n,e,t,i,s){let r,a,o,l;const c=new qs,u=[];let f=0,h=!1,d=!1,p=0,x=0,m,g,M,E,_=0,T=[],b,S=0;const v=n.tables.cff2||n.tables.cff;if(M=v.topDict._defaultWidthX,E=v.topDict._nominalWidthX,s=s||n.variation&&n.variation.get(),e.getBlendPath||(e.getBlendPath=function(N){return Sc(n,e,t,i,N)}),n.isCIDFont||i>1){const N=v.topDict._fdSelect?v.topDict._fdSelect[e.index]:0,U=v.topDict._fdArray[N];m=U._subrs,g=U._subrsBias,i>1?(T=v.topDict._vstore.itemVariationStore,_=U._privateDict.vsindex):(M=U._defaultWidthX,E=U._nominalWidthX)}else m=v.topDict._subrs,g=v.topDict._subrsBias;const w=ep(n,c);let I=M;function L(N,U){d&&w!==2&&c.closePath(),c.moveTo(N,U),d=!0}function C(){let N;N=(u.length&1)!==0,N&&!h&&(I=u.shift()+E),f+=u.length>>1,u.length=0,h=!0}function O(N){let U,Z,k,$,D,ae,re,ee,ce,he,fe,X,se=0;for(;se<N.length;){let Oe=N[se];switch(se+=1,Oe){case 1:C();break;case 3:C();break;case 4:u.length>1&&!h&&(I=u.shift()+E,h=!0),x+=u.pop(),L(p,x);break;case 5:for(;u.length>0;)p+=u.shift(),x+=u.shift(),c.lineTo(p,x);break;case 6:for(;u.length>0&&(p+=u.shift(),c.lineTo(p,x),u.length!==0);)x+=u.shift(),c.lineTo(p,x);break;case 7:for(;u.length>0&&(x+=u.shift(),c.lineTo(p,x),u.length!==0);)p+=u.shift(),c.lineTo(p,x);break;case 8:for(;u.length>0;)r=p+u.shift(),a=x+u.shift(),o=r+u.shift(),l=a+u.shift(),p=o+u.shift(),x=l+u.shift(),c.curveTo(r,a,o,l,p,x);break;case 10:if(D=u.pop()+g,ae=m[D],ae){if(S>=Oh){console.warn("CFF charstring subroutine call depth exceeded, skipping callsubr");break}S++,O(ae),S--}break;case 11:if(i>1){console.error("CFF CharString operator return (11) is not supported in CFF2");break}return;case 12:switch(Oe=N[se],se+=1,Oe){case 35:r=p+u.shift(),a=x+u.shift(),o=r+u.shift(),l=a+u.shift(),re=o+u.shift(),ee=l+u.shift(),ce=re+u.shift(),he=ee+u.shift(),fe=ce+u.shift(),X=he+u.shift(),p=fe+u.shift(),x=X+u.shift(),u.shift(),c.curveTo(r,a,o,l,re,ee),c.curveTo(ce,he,fe,X,p,x);break;case 34:r=p+u.shift(),a=x,o=r+u.shift(),l=a+u.shift(),re=o+u.shift(),ee=l,ce=re+u.shift(),he=l,fe=ce+u.shift(),X=x,p=fe+u.shift(),c.curveTo(r,a,o,l,re,ee),c.curveTo(ce,he,fe,X,p,x);break;case 36:r=p+u.shift(),a=x+u.shift(),o=r+u.shift(),l=a+u.shift(),re=o+u.shift(),ee=l,ce=re+u.shift(),he=l,fe=ce+u.shift(),X=he+u.shift(),p=fe+u.shift(),c.curveTo(r,a,o,l,re,ee),c.curveTo(ce,he,fe,X,p,x);break;case 37:r=p+u.shift(),a=x+u.shift(),o=r+u.shift(),l=a+u.shift(),re=o+u.shift(),ee=l+u.shift(),ce=re+u.shift(),he=ee+u.shift(),fe=ce+u.shift(),X=he+u.shift(),Math.abs(fe-p)>Math.abs(X-x)?p=fe+u.shift():x=X+u.shift(),c.curveTo(r,a,o,l,re,ee),c.curveTo(ce,he,fe,X,p,x);break;default:console.log("Glyph "+e.index+": unknown operator 1200"+Oe),u.length=0}break;case 14:if(i>1){console.error("CFF CharString operator endchar (14) is not supported in CFF2");break}if(u.length>=4){const Fe=bc[u.pop()],Ve=bc[u.pop()],at=u.pop(),ot=u.pop();if(Fe&&Ve){e.isComposite=!0,e.components=[];const pt=n.cffEncoding.charset.indexOf(Fe),vt=n.cffEncoding.charset.indexOf(Ve);e.components.push({glyphIndex:vt,dx:0,dy:0}),e.components.push({glyphIndex:pt,dx:ot,dy:at}),c.extend(n.glyphs.get(vt).path);const ct=n.glyphs.get(pt),ut=JSON.parse(JSON.stringify(ct.path.commands));for(let R=0;R<ut.length;R+=1){const Ae=ut[R];Ae.type!=="Z"&&(Ae.x+=ot,Ae.y+=at),(Ae.type==="Q"||Ae.type==="C")&&(Ae.x1+=ot,Ae.y1+=at),Ae.type==="C"&&(Ae.x2+=ot,Ae.y2+=at)}c.extend(ut)}}else u.length>0&&!h&&(I=u.shift()+E,h=!0);d&&w!==2&&(c.closePath(),d=!1);break;case 15:if(i<2){console.error("CFF2 CharString operator vsindex (15) is not supported in CFF");break}_=u.pop();break;case 16:if(i<2){console.error("CFF2 CharString operator blend (16) is not supported in CFF");break}b||(b=n.variation&&s&&n.variation.process.getBlendVector(T,_,s));var Q=u.pop(),ye=b?b.length:T.itemVariationSubtables[_].regionIndexes.length,ve=Q*ye,_e=u.length-ve,Ze=_e-Q;if(b)for(let Fe=0;Fe<Q;Fe++){var Ye=u[Ze+Fe];for(let Ve=0;Ve<ye;Ve++)Ye+=b[Ve]*u[_e++];u[Ze+Fe]=Ye}for(;ve--;)u.pop();break;case 18:C();break;case 19:case 20:C(),se+=f+7>>3;break;case 21:u.length>2&&!h&&(I=u.shift()+E,h=!0),x+=u.pop(),p+=u.pop(),L(p,x);break;case 22:u.length>1&&!h&&(I=u.shift()+E,h=!0),p+=u.pop(),L(p,x);break;case 23:C();break;case 24:for(;u.length>2;)r=p+u.shift(),a=x+u.shift(),o=r+u.shift(),l=a+u.shift(),p=o+u.shift(),x=l+u.shift(),c.curveTo(r,a,o,l,p,x);p+=u.shift(),x+=u.shift(),c.lineTo(p,x);break;case 25:for(;u.length>6;)p+=u.shift(),x+=u.shift(),c.lineTo(p,x);r=p+u.shift(),a=x+u.shift(),o=r+u.shift(),l=a+u.shift(),p=o+u.shift(),x=l+u.shift(),c.curveTo(r,a,o,l,p,x);break;case 26:for(u.length&1&&(p+=u.shift());u.length>0;)r=p,a=x+u.shift(),o=r+u.shift(),l=a+u.shift(),p=o,x=l+u.shift(),c.curveTo(r,a,o,l,p,x);break;case 27:for(u.length&1&&(x+=u.shift());u.length>0;)r=p+u.shift(),a=x,o=r+u.shift(),l=a+u.shift(),p=o+u.shift(),x=l,c.curveTo(r,a,o,l,p,x);break;case 28:U=N[se],Z=N[se+1],u.push((U<<24|Z<<16)>>16),se+=2;break;case 29:if(D=u.pop()+n.gsubrsBias,ae=n.gsubrs[D],ae){if(S>=Oh){console.warn("CFF charstring subroutine call depth exceeded, skipping callgsubr");break}S++,O(ae),S--}break;case 30:for(;u.length>0&&(r=p,a=x+u.shift(),o=r+u.shift(),l=a+u.shift(),p=o+u.shift(),x=l+(u.length===1?u.shift():0),c.curveTo(r,a,o,l,p,x),u.length!==0);)r=p+u.shift(),a=x,o=r+u.shift(),l=a+u.shift(),x=l+u.shift(),p=o+(u.length===1?u.shift():0),c.curveTo(r,a,o,l,p,x);break;case 31:for(;u.length>0&&(r=p+u.shift(),a=x,o=r+u.shift(),l=a+u.shift(),x=l+u.shift(),p=o+(u.length===1?u.shift():0),c.curveTo(r,a,o,l,p,x),u.length!==0);)r=p,a=x+u.shift(),o=r+u.shift(),l=a+u.shift(),p=o+u.shift(),x=l+(u.length===1?u.shift():0),c.curveTo(r,a,o,l,p,x);break;default:Oe<32?console.log("Glyph "+e.index+": unknown operator "+Oe):Oe<247?u.push(Oe-139):Oe<251?(U=N[se],se+=1,u.push((Oe-247)*256+U+108)):Oe<255?(U=N[se],se+=1,u.push(-(Oe-251)*256-U-108)):(U=N[se],Z=N[se+1],k=N[se+2],$=N[se+3],se+=4,u.push((U<<24|Z<<16|k<<8|$)/65536))}}}return O(t),n.variation&&s&&(c.commands=c.commands.map(N=>{const U=Object.keys(N);for(let Z=0;Z<U.length;Z++){const k=U[Z];k!=="type"&&(N[k]=Math.round(N[k]))}return N})),h&&(e.advanceWidth=I),c}function Fh(n,e,t,i,s){const r=[];let a;const o=new Te.Parser(n,e),l=o.parseCard8();if(l===0)for(let c=0;c<t;c++){if(a=o.parseCard8(),a>=i)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+i+")");r.push(a)}else if(l===3||s>1&&l===4){const c=l===4?o.parseULong():o.parseCard16();let u=l===4?o.parseULong():o.parseCard16();if(u!==0)throw new Error(`CFF Table CID Font FDSelect format ${l} range has bad initial GID ${u}`);let f;for(let h=0;h<c;h++){if(a=l===4?o.parseUShort():o.parseCard8(),f=l===4?o.parseULong():o.parseCard16(),a>=i)throw new Error("CFF table CID Font FDSelect has bad FD index value "+a+" (FD count "+i+")");if(f>t)throw new Error(`CFF Table CID Font FDSelect format ${s} range has bad GID ${f}`);for(;u<f;u++)r.push(a);u=f}if(f!==t)throw new Error("CFF Table CID Font FDSelect format 3 range has bad final (Sentinal) GID "+f)}else throw new Error("CFF Table CID Font FDSelect table has unsupported format "+l);return r}function M1(n,e,t,i){let s;const r=d1(n,e);r.formatMajor===2?s=t.tables.cff2={}:s=t.tables.cff={};const a=r.formatMajor>1?null:Wn(n,r.endOffset,Te.bytesToString),o=r.formatMajor>1?null:Wn(n,a.endOffset),l=r.formatMajor>1?null:Wn(n,o.endOffset,Te.bytesToString),c=Wn(n,r.formatMajor>1?e+r.size+r.topDictLength:l.endOffset,void 0,r.formatMajor);t.gsubrs=c.objects,t.gsubrsBias=uo(t.gsubrs);let u;if(r.formatMajor>1){const h=e+r.size,d=Te.getBytes(n,h,h+r.topDictLength);u=cl(n,0,[d],void 0,r.formatMajor)[0]}else{const h=cl(n,e,o.objects,l.objects,r.formatMajor);if(h.length!==1)throw new Error("CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = "+h.length);u=h[0]}if(s.topDict=u,u._privateDict&&(t.defaultWidthX=u._privateDict.defaultWidthX,t.nominalWidthX=u._privateDict.nominalWidthX),r.formatMajor<2&&u.ros[0]!==void 0&&u.ros[1]!==void 0&&(t.isCIDFont=!0),r.formatMajor>1){let h=u.fdArray,d=u.fdSelect;if(!h)throw new Error("This is a CFF2 font, but FDArray information is missing");const p=Wn(n,e+h,null,r.formatMajor),x=y1(n,e,p.objects);u._fdArray=x,d&&(u._fdSelect=Fh(n,e+d,t.numGlyphs,x.length,r.formatMajor))}else if(t.isCIDFont){let h=u.fdArray,d=u.fdSelect;if(h===0||d===0)throw new Error("Font is marked as a CID font, but FDArray and/or FDSelect information is missing");h+=e;const p=Wn(n,h),x=cl(n,e,p.objects,l.objects,r.formatMajor);u._fdArray=x,d+=e,u._fdSelect=Fh(n,d,t.numGlyphs,x.length,r.formatMajor)}if(r.formatMajor<2){const h=e+u.private[1],d=eu(n,h,u.private[0],l.objects,r.formatMajor);if(t.defaultWidthX=d.defaultWidthX,t.nominalWidthX=d.nominalWidthX,d.subrs!==0){const p=h+d.subrs,x=Wn(n,p);t.subrs=x.objects,t.subrsBias=uo(t.subrs)}else t.subrs=[],t.subrsBias=0}let f;if(i.lowMemory?(f=l1(n,e+u.charStrings,r.formatMajor),t.nGlyphs=f.offsets.length-(r.formatMajor>1?1:0)):(f=Wn(n,e+u.charStrings,null,r.formatMajor),t.nGlyphs=f.objects.length),r.formatMajor>1&&t.tables.maxp&&t.nGlyphs!==t.tables.maxp.numGlyphs&&console.error(`Glyph count in the CFF2 table (${t.nGlyphs}) must correspond to the glyph count in the maxp table (${t.tables.maxp.numGlyphs})`),r.formatMajor<2){let h=[],d=[];u.charset===0?h=Yb:u.charset===1?h=qb:u.charset===2?h=$b:h=_1(n,e+u.charset,t.nGlyphs,l.objects,t.isCIDFont),u.encoding===0?d=bc:u.encoding===1?d=Zb:d=b1(n,e+u.encoding),t.cffEncoding=new qd(d,h),t.encoding=t.encoding||t.cffEncoding}if(t.glyphs=new jn.GlyphSet(t),i.lowMemory)t._push=function(h){const d=c1(h,f.offsets,n,e+u.charStrings,void 0,r.formatMajor);t.glyphs.push(h,jn.cffGlyphLoader(t,h,Sc,d,r.formatMajor))};else for(let h=0;h<t.nGlyphs;h+=1){const d=f.objects[h];t.glyphs.push(h,jn.cffGlyphLoader(t,h,Sc,d,r.formatMajor))}if(u.vstore){const h=new Te.Parser(n,e+u.vstore);u._vstore=h.parseVariationStore()}}function tp(n,e){let t,i=Ha.indexOf(n);return i>=0&&(t=i),i=e.indexOf(n),i>=0?t=i+Ha.length:(t=Ha.length+e.length,e.push(n)),t}function E1(){return new me.Record("Header",[{name:"major",type:"Card8",value:1},{name:"minor",type:"Card8",value:0},{name:"hdrSize",type:"Card8",value:4},{name:"major",type:"Card8",value:1}])}function T1(n){const e=new me.Record("Name INDEX",[{name:"names",type:"INDEX",value:[]}]);e.names=[];for(let t=0;t<n.length;t+=1)e.names.push({name:"name_"+t,type:"NAME",value:n[t]});return e}function np(n,e,t){const i={};for(let s=0;s<n.length;s+=1){const r=n[s];let a=e[r.name];a!==void 0&&!Jd(a,r.value)&&(r.type==="SID"&&(a=tp(a,t)),i[r.op]={name:r.name,type:r.type,value:a})}return i}function Nh(n,e,t){const i=new me.Record("Top DICT",[{name:"dict",type:"DICT",value:{}}]);return i.dict=np(jd,n,e),i}function kh(n){const e=new me.Record("Top DICT INDEX",[{name:"topDicts",type:"INDEX",value:[]}]);return e.topDicts=[{name:"topDict_0",type:"TABLE",value:n}],e}function A1(n){const e=new me.Record("String INDEX",[{name:"strings",type:"INDEX",value:[]}]);e.strings=[];for(let t=0;t<n.length;t+=1)e.strings.push({name:"string_"+t,type:"STRING",value:n[t]});return e}function w1(){return new me.Record("Global Subr INDEX",[{name:"subrs",type:"INDEX",value:[]}])}function C1(n,e){const t=new me.Record("Charsets",[{name:"format",type:"Card8",value:0}]);for(let i=0;i<n.length;i+=1){const s=n[i],r=tp(s,e);t.fields.push({name:"glyph_"+i,type:"SID",value:r})}return t}function R1(n,e){const t=[],i=n.path;t.push({name:"width",type:"NUMBER",value:n.advanceWidth});let s=0,r=0;for(let a=0;a<i.commands.length;a+=1){let o,l,c=i.commands[a];if(c.type==="Q"){const u=.3333333333333333,f=2/3;c={type:"C",x:c.x,y:c.y,x1:Math.round(u*s+f*c.x1),y1:Math.round(u*r+f*c.y1),x2:Math.round(u*c.x+f*c.x1),y2:Math.round(u*c.y+f*c.y1)}}if(c.type==="M")o=Math.round(c.x-s),l=Math.round(c.y-r),t.push({name:"dx",type:"NUMBER",value:o}),t.push({name:"dy",type:"NUMBER",value:l}),t.push({name:"rmoveto",type:"OP",value:21}),s=Math.round(c.x),r=Math.round(c.y);else if(c.type==="L")o=Math.round(c.x-s),l=Math.round(c.y-r),t.push({name:"dx",type:"NUMBER",value:o}),t.push({name:"dy",type:"NUMBER",value:l}),t.push({name:"rlineto",type:"OP",value:5}),s=Math.round(c.x),r=Math.round(c.y);else if(c.type==="C"){const u=Math.round(c.x1-s),f=Math.round(c.y1-r),h=Math.round(c.x2-c.x1),d=Math.round(c.y2-c.y1);o=Math.round(c.x-c.x2),l=Math.round(c.y-c.y2),t.push({name:"dx1",type:"NUMBER",value:u}),t.push({name:"dy1",type:"NUMBER",value:f}),t.push({name:"dx2",type:"NUMBER",value:h}),t.push({name:"dy2",type:"NUMBER",value:d}),t.push({name:"dx",type:"NUMBER",value:o}),t.push({name:"dy",type:"NUMBER",value:l}),t.push({name:"rrcurveto",type:"OP",value:8}),s=Math.round(c.x),r=Math.round(c.y)}}return t.push({name:"endchar",type:"OP",value:14}),t}function P1(n,e){const t=new me.Record("CharStrings INDEX",[{name:"charStrings",type:"INDEX",value:[]}]);for(let i=0;i<n.length;i+=1){const s=n.get(i),r=R1(s);t.charStrings.push({name:s.name,type:"CHARSTRING",value:r})}return t}function L1(n,e,t){const i=new me.Record("Private DICT",[{name:"dict",type:"DICT",value:{}}]);return i.dict=np(Qd,n,e),i}function D1(n,e){const t=new me.Table("CFF ",[{name:"header",type:"RECORD"},{name:"nameIndex",type:"RECORD"},{name:"topDictIndex",type:"RECORD"},{name:"stringIndex",type:"RECORD"},{name:"globalSubrIndex",type:"RECORD"},{name:"charsets",type:"RECORD"},{name:"charStringsIndex",type:"RECORD"},{name:"privateDict",type:"RECORD"}]),i=1/e.unitsPerEm,s={version:e.version,fullName:e.fullName,familyName:e.familyName,weight:e.weightName,fontBBox:e.fontBBox||[0,0,0,0],fontMatrix:[i,0,0,i,0,0],charset:999,encoding:0,charStrings:999,private:[0,999]},r=e&&e.topDict||{};r.paintType&&(s.paintType=r.paintType,s.strokeWidth=r.strokeWidth||0);const a={},o=[];let l;for(let h=1;h<n.length;h+=1)l=n.get(h),o.push(l.name);const c=[];t.header=E1(),t.nameIndex=T1([e.postScriptName]);let u=Nh(s,c);t.topDictIndex=kh(u),t.globalSubrIndex=w1(),t.charsets=C1(o,c),t.charStringsIndex=P1(n),t.privateDict=L1(a,c),t.stringIndex=A1(c);const f=t.header.sizeOf()+t.nameIndex.sizeOf()+t.topDictIndex.sizeOf()+t.stringIndex.sizeOf()+t.globalSubrIndex.sizeOf();return s.charset=f,s.encoding=0,s.charStrings=s.charset+t.charsets.sizeOf(),s.private[1]=s.charStrings+t.charStringsIndex.sizeOf(),u=Nh(s,c),t.topDictIndex=kh(u),t}var Mc={parse:M1,make:D1};function I1(n,e){const t={},i=new Te.Parser(n,e);return t.version=i.parseVersion(),t.fontRevision=Math.round(i.parseFixed()*1e3)/1e3,t.checkSumAdjustment=i.parseULong(),t.magicNumber=i.parseULong(),Ne.argument(t.magicNumber===1594834165,"Font header has wrong magic number."),t.flags=i.parseUShort(),t.unitsPerEm=i.parseUShort(),t.created=i.parseLongDateTime(),t.modified=i.parseLongDateTime(),t.xMin=i.parseShort(),t.yMin=i.parseShort(),t.xMax=i.parseShort(),t.yMax=i.parseShort(),t.macStyle=i.parseUShort(),t.lowestRecPPEM=i.parseUShort(),t.fontDirectionHint=i.parseShort(),t.indexToLocFormat=i.parseShort(),t.glyphDataFormat=i.parseShort(),t}function U1(n){const e=Math.round(new Date().getTime()/1e3)+2082844800;let t=e,i=n.macStyle||0;return n.createdTimestamp&&(t=n.createdTimestamp+2082844800),new me.Table("head",[{name:"version",type:"FIXED",value:65536},{name:"fontRevision",type:"FIXED",value:65536},{name:"checkSumAdjustment",type:"ULONG",value:0},{name:"magicNumber",type:"ULONG",value:1594834165},{name:"flags",type:"USHORT",value:0},{name:"unitsPerEm",type:"USHORT",value:1e3},{name:"created",type:"LONGDATETIME",value:t},{name:"modified",type:"LONGDATETIME",value:e},{name:"xMin",type:"SHORT",value:0},{name:"yMin",type:"SHORT",value:0},{name:"xMax",type:"SHORT",value:0},{name:"yMax",type:"SHORT",value:0},{name:"macStyle",type:"USHORT",value:i},{name:"lowestRecPPEM",type:"USHORT",value:0},{name:"fontDirectionHint",type:"SHORT",value:2},{name:"indexToLocFormat",type:"SHORT",value:0},{name:"glyphDataFormat",type:"SHORT",value:0}],n)}var ip={parse:I1,make:U1};function O1(n,e){const t={},i=new Te.Parser(n,e);return t.version=i.parseVersion(),t.ascender=i.parseShort(),t.descender=i.parseShort(),t.lineGap=i.parseShort(),t.advanceWidthMax=i.parseUShort(),t.minLeftSideBearing=i.parseShort(),t.minRightSideBearing=i.parseShort(),t.xMaxExtent=i.parseShort(),t.caretSlopeRise=i.parseShort(),t.caretSlopeRun=i.parseShort(),t.caretOffset=i.parseShort(),i.relativeOffset+=8,t.metricDataFormat=i.parseShort(),t.numberOfHMetrics=i.parseUShort(),t}function F1(n){return new me.Table("hhea",[{name:"version",type:"FIXED",value:65536},{name:"ascender",type:"FWORD",value:0},{name:"descender",type:"FWORD",value:0},{name:"lineGap",type:"FWORD",value:0},{name:"advanceWidthMax",type:"UFWORD",value:0},{name:"minLeftSideBearing",type:"FWORD",value:0},{name:"minRightSideBearing",type:"FWORD",value:0},{name:"xMaxExtent",type:"FWORD",value:0},{name:"caretSlopeRise",type:"SHORT",value:1},{name:"caretSlopeRun",type:"SHORT",value:0},{name:"caretOffset",type:"SHORT",value:0},{name:"reserved1",type:"SHORT",value:0},{name:"reserved2",type:"SHORT",value:0},{name:"reserved3",type:"SHORT",value:0},{name:"reserved4",type:"SHORT",value:0},{name:"metricDataFormat",type:"SHORT",value:0},{name:"numberOfHMetrics",type:"USHORT",value:0}],n)}var sp={parse:O1,make:F1};function N1(n,e,t,i,s){let r,a;const o=new Te.Parser(n,e);for(let l=0;l<i;l+=1){l<t&&(r=o.parseUShort(),a=o.parseShort());const c=s.get(l);c.advanceWidth=r,c.leftSideBearing=a}}function k1(n,e,t,i,s){n._hmtxTableData={};let r,a;const o=new Te.Parser(e,t);for(let l=0;l<s;l+=1)l<i&&(r=o.parseUShort(),a=o.parseShort()),n._hmtxTableData[l]={advanceWidth:r,leftSideBearing:a}}function B1(n,e,t,i,s,r,a){a.lowMemory?k1(n,e,t,i,s):N1(e,t,i,s,r)}function H1(n){const e=new me.Table("hmtx",[]);for(let t=0;t<n.length;t+=1){const i=n.get(t),s=i.advanceWidth||0,r=i.leftSideBearing||0;e.fields.push({name:"advanceWidth_"+t,type:"USHORT",value:s}),e.fields.push({name:"leftSideBearing_"+t,type:"SHORT",value:r})}return e}var rp={parse:B1,make:H1};function z1(n){const e=new me.Table("ltag",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"numTags",type:"ULONG",value:n.length}]);let t="";const i=12+n.length*4;for(let s=0;s<n.length;++s){let r=t.indexOf(n[s]);r<0&&(r=t.length,t+=n[s]),e.fields.push({name:"offset "+s,type:"USHORT",value:i+r}),e.fields.push({name:"length "+s,type:"USHORT",value:n[s].length})}return e.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),e}function G1(n,e){const t=new Te.Parser(n,e),i=t.parseULong();Ne.argument(i===1,"Unsupported ltag table version."),t.skip("uLong",1);const s=t.parseULong(),r=[];for(let a=0;a<s;a++){let o="";const l=e+t.parseUShort(),c=t.parseUShort();for(let u=l;u<l+c;++u)o+=String.fromCharCode(n.getInt8(u));r.push(o)}return r}var ap={make:z1,parse:G1};function V1(n,e){const t={},i=new Te.Parser(n,e);return t.version=i.parseVersion(),t.numGlyphs=i.parseUShort(),t.version===1&&(t.maxPoints=i.parseUShort(),t.maxContours=i.parseUShort(),t.maxCompositePoints=i.parseUShort(),t.maxCompositeContours=i.parseUShort(),t.maxZones=i.parseUShort(),t.maxTwilightPoints=i.parseUShort(),t.maxStorage=i.parseUShort(),t.maxFunctionDefs=i.parseUShort(),t.maxInstructionDefs=i.parseUShort(),t.maxStackElements=i.parseUShort(),t.maxSizeOfInstructions=i.parseUShort(),t.maxComponentElements=i.parseUShort(),t.maxComponentDepth=i.parseUShort()),t}function W1(n){return new me.Table("maxp",[{name:"version",type:"FIXED",value:20480},{name:"numGlyphs",type:"USHORT",value:n}])}var op={parse:V1,make:W1},Ec=[{begin:0,end:127},{begin:128,end:255},{begin:256,end:383},{begin:384,end:591},{begin:592,end:687},{begin:688,end:767},{begin:768,end:879},{begin:880,end:1023},{begin:11392,end:11519},{begin:1024,end:1279},{begin:1328,end:1423},{begin:1424,end:1535},{begin:42240,end:42559},{begin:1536,end:1791},{begin:1984,end:2047},{begin:2304,end:2431},{begin:2432,end:2559},{begin:2560,end:2687},{begin:2688,end:2815},{begin:2816,end:2943},{begin:2944,end:3071},{begin:3072,end:3199},{begin:3200,end:3327},{begin:3328,end:3455},{begin:3584,end:3711},{begin:3712,end:3839},{begin:4256,end:4351},{begin:6912,end:7039},{begin:4352,end:4607},{begin:7680,end:7935},{begin:7936,end:8191},{begin:8192,end:8303},{begin:8304,end:8351},{begin:8352,end:8399},{begin:8400,end:8447},{begin:8448,end:8527},{begin:8528,end:8591},{begin:8592,end:8703},{begin:8704,end:8959},{begin:8960,end:9215},{begin:9216,end:9279},{begin:9280,end:9311},{begin:9312,end:9471},{begin:9472,end:9599},{begin:9600,end:9631},{begin:9632,end:9727},{begin:9728,end:9983},{begin:9984,end:10175},{begin:12288,end:12351},{begin:12352,end:12447},{begin:12448,end:12543},{begin:12544,end:12591},{begin:12592,end:12687},{begin:43072,end:43135},{begin:12800,end:13055},{begin:13056,end:13311},{begin:44032,end:55215},{begin:55296,end:57343},{begin:67840,end:67871},{begin:19968,end:40959},{begin:57344,end:63743},{begin:12736,end:12783},{begin:64256,end:64335},{begin:64336,end:65023},{begin:65056,end:65071},{begin:65040,end:65055},{begin:65104,end:65135},{begin:65136,end:65279},{begin:65280,end:65519},{begin:65520,end:65535},{begin:3840,end:4095},{begin:1792,end:1871},{begin:1920,end:1983},{begin:3456,end:3583},{begin:4096,end:4255},{begin:4608,end:4991},{begin:5024,end:5119},{begin:5120,end:5759},{begin:5760,end:5791},{begin:5792,end:5887},{begin:6016,end:6143},{begin:6144,end:6319},{begin:10240,end:10495},{begin:40960,end:42127},{begin:5888,end:5919},{begin:66304,end:66351},{begin:66352,end:66383},{begin:66560,end:66639},{begin:118784,end:119039},{begin:119808,end:120831},{begin:1044480,end:1048573},{begin:65024,end:65039},{begin:917504,end:917631},{begin:6400,end:6479},{begin:6480,end:6527},{begin:6528,end:6623},{begin:6656,end:6687},{begin:11264,end:11359},{begin:11568,end:11647},{begin:19904,end:19967},{begin:43008,end:43055},{begin:65536,end:65663},{begin:65856,end:65935},{begin:66432,end:66463},{begin:66464,end:66527},{begin:66640,end:66687},{begin:66688,end:66735},{begin:67584,end:67647},{begin:68096,end:68191},{begin:119552,end:119647},{begin:73728,end:74751},{begin:119648,end:119679},{begin:7040,end:7103},{begin:7168,end:7247},{begin:7248,end:7295},{begin:43136,end:43231},{begin:43264,end:43311},{begin:43312,end:43359},{begin:43520,end:43615},{begin:65936,end:65999},{begin:66e3,end:66047},{begin:66208,end:66271},{begin:127024,end:127135}];function X1(n){for(let e=0;e<Ec.length;e+=1){const t=Ec[e];if(n>=t.begin&&n<t.end)return e}return-1}function Y1(n,e){const t={},i=new Te.Parser(n,e);t.version=i.parseUShort(),t.xAvgCharWidth=i.parseShort(),t.usWeightClass=i.parseUShort(),t.usWidthClass=i.parseUShort(),t.fsType=i.parseUShort(),t.ySubscriptXSize=i.parseShort(),t.ySubscriptYSize=i.parseShort(),t.ySubscriptXOffset=i.parseShort(),t.ySubscriptYOffset=i.parseShort(),t.ySuperscriptXSize=i.parseShort(),t.ySuperscriptYSize=i.parseShort(),t.ySuperscriptXOffset=i.parseShort(),t.ySuperscriptYOffset=i.parseShort(),t.yStrikeoutSize=i.parseShort(),t.yStrikeoutPosition=i.parseShort(),t.sFamilyClass=i.parseShort(),t.panose=[];for(let s=0;s<10;s++)t.panose[s]=i.parseByte();return t.ulUnicodeRange1=i.parseULong(),t.ulUnicodeRange2=i.parseULong(),t.ulUnicodeRange3=i.parseULong(),t.ulUnicodeRange4=i.parseULong(),t.achVendID=String.fromCharCode(i.parseByte(),i.parseByte(),i.parseByte(),i.parseByte()),t.fsSelection=i.parseUShort(),t.usFirstCharIndex=i.parseUShort(),t.usLastCharIndex=i.parseUShort(),t.sTypoAscender=i.parseShort(),t.sTypoDescender=i.parseShort(),t.sTypoLineGap=i.parseShort(),t.usWinAscent=i.parseUShort(),t.usWinDescent=i.parseUShort(),t.version>=1&&(t.ulCodePageRange1=i.parseULong(),t.ulCodePageRange2=i.parseULong()),t.version>=2&&(t.sxHeight=i.parseShort(),t.sCapHeight=i.parseShort(),t.usDefaultChar=i.parseUShort(),t.usBreakChar=i.parseUShort(),t.usMaxContent=i.parseUShort()),t}function q1(n){return new me.Table("OS/2",[{name:"version",type:"USHORT",value:3},{name:"xAvgCharWidth",type:"SHORT",value:0},{name:"usWeightClass",type:"USHORT",value:0},{name:"usWidthClass",type:"USHORT",value:0},{name:"fsType",type:"USHORT",value:0},{name:"ySubscriptXSize",type:"SHORT",value:650},{name:"ySubscriptYSize",type:"SHORT",value:699},{name:"ySubscriptXOffset",type:"SHORT",value:0},{name:"ySubscriptYOffset",type:"SHORT",value:140},{name:"ySuperscriptXSize",type:"SHORT",value:650},{name:"ySuperscriptYSize",type:"SHORT",value:699},{name:"ySuperscriptXOffset",type:"SHORT",value:0},{name:"ySuperscriptYOffset",type:"SHORT",value:479},{name:"yStrikeoutSize",type:"SHORT",value:49},{name:"yStrikeoutPosition",type:"SHORT",value:258},{name:"sFamilyClass",type:"SHORT",value:0},{name:"bFamilyType",type:"BYTE",value:0},{name:"bSerifStyle",type:"BYTE",value:0},{name:"bWeight",type:"BYTE",value:0},{name:"bProportion",type:"BYTE",value:0},{name:"bContrast",type:"BYTE",value:0},{name:"bStrokeVariation",type:"BYTE",value:0},{name:"bArmStyle",type:"BYTE",value:0},{name:"bLetterform",type:"BYTE",value:0},{name:"bMidline",type:"BYTE",value:0},{name:"bXHeight",type:"BYTE",value:0},{name:"ulUnicodeRange1",type:"ULONG",value:0},{name:"ulUnicodeRange2",type:"ULONG",value:0},{name:"ulUnicodeRange3",type:"ULONG",value:0},{name:"ulUnicodeRange4",type:"ULONG",value:0},{name:"achVendID",type:"CHARARRAY",value:"XXXX"},{name:"fsSelection",type:"USHORT",value:0},{name:"usFirstCharIndex",type:"USHORT",value:0},{name:"usLastCharIndex",type:"USHORT",value:0},{name:"sTypoAscender",type:"SHORT",value:0},{name:"sTypoDescender",type:"SHORT",value:0},{name:"sTypoLineGap",type:"SHORT",value:0},{name:"usWinAscent",type:"USHORT",value:0},{name:"usWinDescent",type:"USHORT",value:0},{name:"ulCodePageRange1",type:"ULONG",value:0},{name:"ulCodePageRange2",type:"ULONG",value:0},{name:"sxHeight",type:"SHORT",value:0},{name:"sCapHeight",type:"SHORT",value:0},{name:"usDefaultChar",type:"USHORT",value:0},{name:"usBreakChar",type:"USHORT",value:0},{name:"usMaxContext",type:"USHORT",value:0}],n)}var Tc={parse:Y1,make:q1,unicodeRanges:Ec,getUnicodeRange:X1};function $1(n,e){const t={},i=new Te.Parser(n,e);switch(t.version=i.parseVersion(),t.italicAngle=i.parseFixed(),t.underlinePosition=i.parseShort(),t.underlineThickness=i.parseShort(),t.isFixedPitch=i.parseULong(),t.minMemType42=i.parseULong(),t.maxMemType42=i.parseULong(),t.minMemType1=i.parseULong(),t.maxMemType1=i.parseULong(),t.version){case 1:t.names=Ki.slice();break;case 2:t.numberOfGlyphs=i.parseUShort(),t.glyphNameIndex=new Array(t.numberOfGlyphs);for(let s=0;s<t.numberOfGlyphs;s++)t.glyphNameIndex[s]=i.parseUShort();t.names=[];for(let s=0;s<t.numberOfGlyphs;s++)if(t.glyphNameIndex[s]>=Ki.length){const r=i.parseChar();t.names.push(i.parseString(r))}break;case 2.5:t.numberOfGlyphs=i.parseUShort(),t.offset=new Array(t.numberOfGlyphs);for(let s=0;s<t.numberOfGlyphs;s++)t.offset[s]=i.parseChar();break}return t}function Z1(n){const{italicAngle:e=Math.round((n.italicAngle||0)*65536),underlinePosition:t=0,underlineThickness:i=0,isFixedPitch:s=0,minMemType42:r=0,maxMemType42:a=0,minMemType1:o=0,maxMemType1:l=0}=n.tables.post||{};return new me.Table("post",[{name:"version",type:"FIXED",value:196608},{name:"italicAngle",type:"FIXED",value:e},{name:"underlinePosition",type:"FWORD",value:t},{name:"underlineThickness",type:"FWORD",value:i},{name:"isFixedPitch",type:"ULONG",value:s},{name:"minMemType42",type:"ULONG",value:r},{name:"maxMemType42",type:"ULONG",value:a},{name:"minMemType1",type:"ULONG",value:o},{name:"maxMemType1",type:"ULONG",value:l}])}var lp={parse:$1,make:Z1},Un=new Array(9);Un[1]=function(){const e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(q.coverage),deltaGlyphId:this.parseShort()};if(t===2)return{substFormat:2,coverage:this.parsePointer(q.coverage),substitute:this.parseOffset16List()};Ne.assert(!1,"0x"+e.toString(16)+": lookup type 1 format must be 1 or 2.")};Un[2]=function(){const e=this.parseUShort();return Ne.argument(e===1,"GSUB Multiple Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(q.coverage),sequences:this.parseListOfLists()}};Un[3]=function(){const e=this.parseUShort();return Ne.argument(e===1,"GSUB Alternate Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(q.coverage),alternateSets:this.parseListOfLists()}};Un[4]=function(){const e=this.parseUShort();return Ne.argument(e===1,"GSUB ligature table identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(q.coverage),ligatureSets:this.parseListOfLists(function(){return{ligGlyph:this.parseUShort(),components:this.parseUShortList(this.parseUShort()-1)}})}};var zs={sequenceIndex:q.uShort,lookupListIndex:q.uShort};Un[5]=function(){const e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:t,coverage:this.parsePointer(q.coverage),ruleSets:this.parseListOfLists(function(){const i=this.parseUShort(),s=this.parseUShort();return{input:this.parseUShortList(i-1),lookupRecords:this.parseRecordList(s,zs)}})};if(t===2)return{substFormat:t,coverage:this.parsePointer(q.coverage),classDef:this.parsePointer(q.classDef),classSets:this.parseListOfLists(function(){const i=this.parseUShort(),s=this.parseUShort();return{classes:this.parseUShortList(i-1),lookupRecords:this.parseRecordList(s,zs)}})};if(t===3){const i=this.parseUShort(),s=this.parseUShort();return{substFormat:t,coverages:this.parseList(i,q.pointer(q.coverage)),lookupRecords:this.parseRecordList(s,zs)}}Ne.assert(!1,"0x"+e.toString(16)+": lookup type 5 format must be 1, 2 or 3.")};Un[6]=function(){const e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{substFormat:1,coverage:this.parsePointer(q.coverage),chainRuleSets:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(zs)}})};if(t===2)return{substFormat:2,coverage:this.parsePointer(q.coverage),backtrackClassDef:this.parsePointer(q.classDef),inputClassDef:this.parsePointer(q.classDef),lookaheadClassDef:this.parsePointer(q.classDef),chainClassSet:this.parseListOfLists(function(){return{backtrack:this.parseUShortList(),input:this.parseUShortList(this.parseShort()-1),lookahead:this.parseUShortList(),lookupRecords:this.parseRecordList(zs)}})};if(t===3)return{substFormat:3,backtrackCoverage:this.parseList(q.pointer(q.coverage)),inputCoverage:this.parseList(q.pointer(q.coverage)),lookaheadCoverage:this.parseList(q.pointer(q.coverage)),lookupRecords:this.parseRecordList(zs)};Ne.assert(!1,"0x"+e.toString(16)+": lookup type 6 format must be 1, 2 or 3.")};Un[7]=function(){const e=this.parseUShort();Ne.argument(e===1,"GSUB Extension Substitution subtable identifier-format must be 1");const t=this.parseUShort(),i=new q(this.data,this.offset+this.parseULong());return{substFormat:1,lookupType:t,extension:Un[t].call(i)}};Un[8]=function(){const e=this.parseUShort();return Ne.argument(e===1,"GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1"),{substFormat:e,coverage:this.parsePointer(q.coverage),backtrackCoverage:this.parseList(q.pointer(q.coverage)),lookaheadCoverage:this.parseList(q.pointer(q.coverage)),substitutes:this.parseUShortList()}};function K1(n,e){e=e||0;const t=new q(n,e),i=t.parseVersion(1);return Ne.argument(i===1||i===1.1,"Unsupported GSUB table version."),i===1?{version:i,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(Un)}:{version:i,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(Un),variations:t.parseFeatureVariationsList()}}var os=new Array(9);os[1]=function(e){if(e.substFormat===1)return new me.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new me.Coverage(e.coverage)},{name:"deltaGlyphID",type:"SHORT",value:e.deltaGlyphId}]);if(e.substFormat===2)return new me.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:2},{name:"coverage",type:"TABLE",value:new me.Coverage(e.coverage)}].concat(me.ushortList("substitute",e.substitute)));Ne.fail("Lookup type 1 substFormat must be 1 or 2.")};os[2]=function(e){return Ne.assert(e.substFormat===1,"Lookup type 2 substFormat must be 1."),new me.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new me.Coverage(e.coverage)}].concat(me.tableList("seqSet",e.sequences,function(t){return new me.Table("sequenceSetTable",me.ushortList("sequence",t))})))};os[3]=function(e){return Ne.assert(e.substFormat===1,"Lookup type 3 substFormat must be 1."),new me.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new me.Coverage(e.coverage)}].concat(me.tableList("altSet",e.alternateSets,function(t){return new me.Table("alternateSetTable",me.ushortList("alternate",t))})))};os[4]=function(e){return Ne.assert(e.substFormat===1,"Lookup type 4 substFormat must be 1."),new me.Table("substitutionTable",[{name:"substFormat",type:"USHORT",value:1},{name:"coverage",type:"TABLE",value:new me.Coverage(e.coverage)}].concat(me.tableList("ligSet",e.ligatureSets,function(t){return new me.Table("ligatureSetTable",me.tableList("ligature",t,function(i){return new me.Table("ligatureTable",[{name:"ligGlyph",type:"USHORT",value:i.ligGlyph}].concat(me.ushortList("component",i.components,i.components.length+1)))}))})))};os[5]=function(e){if(e.substFormat===1)return new me.Table("contextualSubstitutionTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new me.Coverage(e.coverage)}].concat(me.tableList("sequenceRuleSet",e.ruleSets,function(t){return t?new me.Table("sequenceRuleSetTable",me.tableList("sequenceRule",t,function(i){let s=me.ushortList("seqLookup",[],i.lookupRecords.length).concat(me.ushortList("inputSequence",i.input,i.input.length+1));[s[0],s[1]]=[s[1],s[0]];for(let r=0;r<i.lookupRecords.length;r++){const a=i.lookupRecords[r];s=s.concat({name:"sequenceIndex"+r,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+r,type:"USHORT",value:a.lookupListIndex})}return new me.Table("sequenceRuleTable",s)})):new me.Table("NULL",null)})));if(e.substFormat===2)return new me.Table("contextualSubstitutionTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new me.Coverage(e.coverage)},{name:"classDef",type:"TABLE",value:new me.ClassDef(e.classDef)}].concat(me.tableList("classSeqRuleSet",e.classSets,function(t){return t?new me.Table("classSeqRuleSetTable",me.tableList("classSeqRule",t,function(i){let s=me.ushortList("classes",i.classes,i.classes.length+1).concat(me.ushortList("seqLookupCount",[],i.lookupRecords.length));for(let r=0;r<i.lookupRecords.length;r++){const a=i.lookupRecords[r];s=s.concat({name:"sequenceIndex"+r,type:"USHORT",value:a.sequenceIndex}).concat({name:"lookupListIndex"+r,type:"USHORT",value:a.lookupListIndex})}return new me.Table("classSeqRuleTable",s)})):new me.Table("NULL",null)})));if(e.substFormat===3){let t=[{name:"substFormat",type:"USHORT",value:e.substFormat}];t.push({name:"inputGlyphCount",type:"USHORT",value:e.coverages.length}),t.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length});for(let s=0;s<e.coverages.length;s++){const r=e.coverages[s];t.push({name:"inputCoverage"+s,type:"TABLE",value:new me.Coverage(r)})}for(let s=0;s<e.lookupRecords.length;s++){const r=e.lookupRecords[s];t=t.concat({name:"sequenceIndex"+s,type:"USHORT",value:r.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:r.lookupListIndex})}return new me.Table("contextualSubstitutionTable",t)}Ne.assert(!1,"lookup type 5 format must be 1, 2 or 3.")};os[6]=function(e){if(e.substFormat===1)return new me.Table("chainContextTable",[{name:"substFormat",type:"USHORT",value:e.substFormat},{name:"coverage",type:"TABLE",value:new me.Coverage(e.coverage)}].concat(me.tableList("chainRuleSet",e.chainRuleSets,function(i){return new me.Table("chainRuleSetTable",me.tableList("chainRule",i,function(s){let r=me.ushortList("backtrackGlyph",s.backtrack,s.backtrack.length).concat(me.ushortList("inputGlyph",s.input,s.input.length+1)).concat(me.ushortList("lookaheadGlyph",s.lookahead,s.lookahead.length)).concat(me.ushortList("substitution",[],s.lookupRecords.length));for(let a=0;a<s.lookupRecords.length;a++){const o=s.lookupRecords[a];r=r.concat({name:"sequenceIndex"+a,type:"USHORT",value:o.sequenceIndex}).concat({name:"lookupListIndex"+a,type:"USHORT",value:o.lookupListIndex})}return new me.Table("chainRuleTable",r)}))})));if(e.substFormat===2)Ne.assert(!1,"lookup type 6 format 2 is not yet supported.");else if(e.substFormat===3){let t=[{name:"substFormat",type:"USHORT",value:e.substFormat}];t.push({name:"backtrackGlyphCount",type:"USHORT",value:e.backtrackCoverage.length});for(let s=0;s<e.backtrackCoverage.length;s++){const r=e.backtrackCoverage[s];t.push({name:"backtrackCoverage"+s,type:"TABLE",value:new me.Coverage(r)})}t.push({name:"inputGlyphCount",type:"USHORT",value:e.inputCoverage.length});for(let s=0;s<e.inputCoverage.length;s++){const r=e.inputCoverage[s];t.push({name:"inputCoverage"+s,type:"TABLE",value:new me.Coverage(r)})}t.push({name:"lookaheadGlyphCount",type:"USHORT",value:e.lookaheadCoverage.length});for(let s=0;s<e.lookaheadCoverage.length;s++){const r=e.lookaheadCoverage[s];t.push({name:"lookaheadCoverage"+s,type:"TABLE",value:new me.Coverage(r)})}t.push({name:"substitutionCount",type:"USHORT",value:e.lookupRecords.length});for(let s=0;s<e.lookupRecords.length;s++){const r=e.lookupRecords[s];t=t.concat({name:"sequenceIndex"+s,type:"USHORT",value:r.sequenceIndex}).concat({name:"lookupListIndex"+s,type:"USHORT",value:r.lookupListIndex})}return new me.Table("chainContextTable",t)}Ne.assert(!1,"lookup type 6 format must be 1, 2 or 3.")};function J1(n){return new me.Table("GSUB",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new me.ScriptList(n.scripts)},{name:"features",type:"TABLE",value:new me.FeatureList(n.features)},{name:"lookups",type:"TABLE",value:new me.LookupList(n.lookups,os)}])}var cp={parse:K1,make:J1};function j1(n,e){const t=new Te.Parser(n,e),i=t.parseULong();Ne.argument(i===1,"Unsupported META table version."),t.parseULong(),t.parseULong();const s=t.parseULong(),r={};for(let a=0;a<s;a++){const o=t.parseTag(),l=t.parseULong(),c=t.parseULong();if(o==="appl"||o==="bild")continue;const u=$s.UTF8(n,e+l,c);r[o]=u}return r}function Q1(n){const e=Object.keys(n).length;let t="";const i=16+e*12,s=new me.Table("meta",[{name:"version",type:"ULONG",value:1},{name:"flags",type:"ULONG",value:0},{name:"offset",type:"ULONG",value:i},{name:"numTags",type:"ULONG",value:e}]);for(let r in n){const a=t.length;t+=n[r],s.fields.push({name:"tag "+r,type:"TAG",value:r}),s.fields.push({name:"offset "+r,type:"ULONG",value:i+a}),s.fields.push({name:"length "+r,type:"ULONG",value:n[r].length})}return s.fields.push({name:"stringPool",type:"CHARARRAY",value:t}),s}var up={parse:j1,make:Q1};function eS(n,e){const t=new q(n,e),i=t.parseUShort();i!==0&&console.warn("Only COLRv0 is currently fully supported. A subset of color glyphs might be available in this font if provided in the v0 format.");const s=t.parseUShort(),r=t.parseOffset32(),a=t.parseOffset32(),o=t.parseUShort();t.relativeOffset=r;const l=t.parseRecordList(s,{glyphID:q.uShort,firstLayerIndex:q.uShort,numLayers:q.uShort});t.relativeOffset=a;const c=t.parseRecordList(o,{glyphID:q.uShort,paletteIndex:q.uShort});return{version:i,baseGlyphRecords:l,layerRecords:c}}function tS({version:n=0,baseGlyphRecords:e=[],layerRecords:t=[]}){Ne.argument(n===0,"Only COLRv0 supported.");const i=14,s=i+e.length*6;return new me.Table("COLR",[{name:"version",type:"USHORT",value:n},{name:"numBaseGlyphRecords",type:"USHORT",value:e.length},{name:"baseGlyphRecordsOffset",type:"ULONG",value:i},{name:"layerRecordsOffset",type:"ULONG",value:s},{name:"numLayerRecords",type:"USHORT",value:t.length},...e.map((r,a)=>[{name:"glyphID_"+a,type:"USHORT",value:r.glyphID},{name:"firstLayerIndex_"+a,type:"USHORT",value:r.firstLayerIndex},{name:"numLayers_"+a,type:"USHORT",value:r.numLayers}]).flat(),...t.map((r,a)=>[{name:"LayerGlyphID_"+a,type:"USHORT",value:r.glyphID},{name:"paletteIndex_"+a,type:"USHORT",value:r.paletteIndex}]).flat()])}var hp={parse:eS,make:tS};function nS(n,e){return[{name:"tag_"+n,type:"TAG",value:e.tag},{name:"minValue_"+n,type:"FIXED",value:e.minValue<<16},{name:"defaultValue_"+n,type:"FIXED",value:e.defaultValue<<16},{name:"maxValue_"+n,type:"FIXED",value:e.maxValue<<16},{name:"flags_"+n,type:"USHORT",value:0},{name:"nameID_"+n,type:"USHORT",value:e.axisNameID}]}function iS(n,e,t){const i={},s=new Te.Parser(n,e);i.tag=s.parseTag(),i.minValue=s.parseFixed(),i.defaultValue=s.parseFixed(),i.maxValue=s.parseFixed(),s.skip("uShort",1);const r=s.parseUShort();return i.axisNameID=r,i.name=lo(t,r),i}function sS(n,e,t,i={}){const s=[{name:"nameID_"+n,type:"USHORT",value:e.subfamilyNameID},{name:"flags_"+n,type:"USHORT",value:0}];for(let r=0;r<t.length;++r){const a=t[r].tag;s.push({name:"axis_"+n+" "+a,type:"FIXED",value:e.coordinates[a]<<16})}return i&&i.postScriptNameID&&s.push({name:"postScriptNameID_",type:"USHORT",value:e.postScriptNameID!==void 0?e.postScriptNameID:65535}),s}function rS(n,e,t,i,s){const r={},a=new Te.Parser(n,e),o=a.parseUShort();r.subfamilyNameID=o,r.name=lo(i,o,[2,17]),a.skip("uShort",1),r.coordinates={};for(let c=0;c<t.length;++c)r.coordinates[t[c].tag]=a.parseFixed();if(a.relativeOffset===s)return r.postScriptNameID=void 0,r.postScriptName=void 0,r;const l=a.parseUShort();return r.postScriptNameID=l==65535?void 0:l,r.postScriptName=r.postScriptNameID!==void 0?lo(i,l,[6]):"",r}function aS(n,e){const t=new me.Table("fvar",[{name:"version",type:"ULONG",value:65536},{name:"offsetToData",type:"USHORT",value:0},{name:"countSizePairs",type:"USHORT",value:2},{name:"axisCount",type:"USHORT",value:n.axes.length},{name:"axisSize",type:"USHORT",value:20},{name:"instanceCount",type:"USHORT",value:n.instances.length},{name:"instanceSize",type:"USHORT",value:4+n.axes.length*4}]);t.offsetToData=t.sizeOf();for(let s=0;s<n.axes.length;s++)t.fields=t.fields.concat(nS(s,n.axes[s]));const i={};for(let s=0;s<n.instances.length;s++)if(n.instances[s].postScriptNameID!==void 0){t.instanceSize+=2,i.postScriptNameID=!0;break}for(let s=0;s<n.instances.length;s++)t.fields=t.fields.concat(sS(s,n.instances[s],n.axes,i));return t}function oS(n,e,t){const i=new Te.Parser(n,e),s=i.parseULong();Ne.argument(s===65536,"Unsupported fvar table version.");const r=i.parseOffset16();i.skip("uShort",1);const a=i.parseUShort(),o=i.parseUShort(),l=i.parseUShort(),c=i.parseUShort(),u=[];for(let d=0;d<a;d++)u.push(iS(n,e+r+d*o,t));const f=[],h=e+r+a*o;for(let d=0;d<l;d++)f.push(rS(n,h+d*c,u,t,c));return{axes:u,instances:f}}var fp={make:aS,parse:oS},lS={tag:q.tag,nameID:q.uShort,ordering:q.uShort},Or=new Array(5);Or[1]=function(){return{axisIndex:this.parseUShort(),flags:this.parseUShort(),valueNameID:this.parseUShort(),value:this.parseFixed()}};Or[2]=function(){return{axisIndex:this.parseUShort(),flags:this.parseUShort(),valueNameID:this.parseUShort(),nominalValue:this.parseFixed(),rangeMinValue:this.parseFixed(),rangeMaxValue:this.parseFixed()}};Or[3]=function(){return{axisIndex:this.parseUShort(),flags:this.parseUShort(),valueNameID:this.parseUShort(),value:this.parseFixed(),linkedValue:this.parseFixed()}};Or[4]=function(){const e=this.parseUShort();return{flags:this.parseUShort(),valueNameID:this.parseUShort(),axisValues:this.parseList(e,function(){return{axisIndex:this.parseUShort(),value:this.parseFixed()}})}};function cS(){const n=this.parseUShort(),e=Or[n],t={format:n};return e===void 0?(console.warn(`Unknown axis value table format ${n}`),t):Object.assign(t,this.parseStruct(e.bind(this)))}function uS(n,e,t){e||(e=0);const i=new Te.Parser(n,e),s=i.parseUShort(),r=i.parseUShort();s!==1&&console.warn(`Unsupported STAT table version ${s}.${r}`);const a=[s,r],o=i.parseUShort(),l=i.parseUShort(),c=i.parseOffset32(),u=i.parseUShort(),f=i.parseOffset32(),h=s>1||r>0?i.parseUShort():void 0;t!==void 0&&Ne.argument(l>=t.axes.length,"STAT axis count must be greater than or equal to fvar axis count"),u>0&&Ne.argument(l>=0,"STAT axis count must be greater than 0 if STAT axis value count is greater than 0");const d=[];for(let m=0;m<l;m++)i.offset=e+c,i.relativeOffset=m*o,d.push(i.parseStruct(lS));i.offset=e,i.relativeOffset=f;const p=i.parseUShortList(u),x=[];for(let m=0;m<u;m++)i.offset=e+f,i.relativeOffset=p[m],x.push(cS.apply(i));return{version:a,axes:d,values:x,elidedFallbackNameID:h}}var Fr=new Array(5);Fr[1]=function(e,t){return[{name:`format${e}`,type:"USHORT",value:1},{name:`axisIndex${e}`,type:"USHORT",value:t.axisIndex},{name:`flags${e}`,type:"USHORT",value:t.flags},{name:`valueNameID${e}`,type:"USHORT",value:t.valueNameID},{name:`value${e}`,type:"FLOAT",value:t.value}]};Fr[2]=function(e,t){return[{name:`format${e}`,type:"USHORT",value:2},{name:`axisIndex${e}`,type:"USHORT",value:t.axisIndex},{name:`flags${e}`,type:"USHORT",value:t.flags},{name:`valueNameID${e}`,type:"USHORT",value:t.valueNameID},{name:`nominalValue${e}`,type:"FLOAT",value:t.nominalValue},{name:`rangeMinValue${e}`,type:"FLOAT",value:t.rangeMinValue},{name:`rangeMaxValue${e}`,type:"FLOAT",value:t.rangeMaxValue}]};Fr[3]=function(e,t){return[{name:`format${e}`,type:"USHORT",value:3},{name:`axisIndex${e}`,type:"USHORT",value:t.axisIndex},{name:`flags${e}`,type:"USHORT",value:t.flags},{name:`valueNameID${e}`,type:"USHORT",value:t.valueNameID},{name:`value${e}`,type:"FLOAT",value:t.value},{name:`linkedValue${e}`,type:"FLOAT",value:t.linkedValue}]};Fr[4]=function(e,t){let i=[{name:`format${e}`,type:"USHORT",value:4},{name:`axisCount${e}`,type:"USHORT",value:t.axisValues.length},{name:`flags${e}`,type:"USHORT",value:t.flags},{name:`valueNameID${e}`,type:"USHORT",value:t.valueNameID}];for(let s=0;s<t.axisValues.length;s++)i=i.concat([{name:`format${e}axisIndex${s}`,type:"USHORT",value:t.axisValues[s].axisIndex},{name:`format${e}value${s}`,type:"FLOAT",value:t.axisValues[s].value}]);return i};function hS(n,e){return new me.Record("axisRecord_"+n,[{name:"axisTag_"+n,type:"TAG",value:e.tag},{name:"axisNameID_"+n,type:"USHORT",value:e.nameID},{name:"axisOrdering_"+n,type:"USHORT",value:e.ordering}])}function fS(n,e){const t=e.format,i=Fr[t];Ne.argument(i!==void 0,`Unknown axis value table format ${t}`);const s=i(n,e);return new me.Table("axisValueTable_"+n,s)}function dS(n){const e=new me.Table("STAT",[{name:"majorVersion",type:"USHORT",value:1},{name:"minorVersion",type:"USHORT",value:2},{name:"designAxisSize",type:"USHORT",value:8},{name:"designAxisCount",type:"USHORT",value:n.axes.length},{name:"designAxesOffset",type:"ULONG",value:0},{name:"axisValueCount",type:"USHORT",value:n.values.length},{name:"offsetToAxisValueOffsets",type:"ULONG",value:0},{name:"elidedFallbackNameID",type:"USHORT",value:n.elidedFallbackNameID}]);e.designAxesOffset=e.offsetToAxisValueOffsets=e.sizeOf();for(let r=0;r<n.axes.length;r++){const a=hS(r,n.axes[r]);e.offsetToAxisValueOffsets+=a.sizeOf(),e.fields=e.fields.concat(a.fields)}const t=[];let i=[],s=n.values.length*2;for(let r=0;r<n.values.length;r++){const a=fS(r,n.values[r]);t.push({name:"offset_"+r,type:"USHORT",value:s}),s+=a.sizeOf(),i=i.concat(a.fields)}return e.fields=e.fields.concat(t),e.fields=e.fields.concat(i),e}var dp={make:dS,parse:uS};function pS(n,e){return new me.Record("axisValueMap_"+n,[{name:"fromCoordinate_"+n,type:"F2DOT14",value:e.fromCoordinate},{name:"toCoordinate_"+n,type:"F2DOT14",value:e.toCoordinate}])}function mS(n,e){const t=new me.Record("segmentMap_"+n,[{name:"positionMapCount_"+n,type:"USHORT",value:e.axisValueMaps.length}]);let i=[];for(let s=0;s<e.axisValueMaps.length;s++){const r=pS(`${n}_${s}`,e.axisValueMaps[s]);i=i.concat(r.fields)}return t.fields=t.fields.concat(i),t}function gS(n,e){Ne.argument(n.axisSegmentMaps.length===e.axes.length,"avar axis count must correspond to fvar axis count");const t=new me.Table("avar",[{name:"majorVersion",type:"USHORT",value:1},{name:"minorVersion",type:"USHORT",value:0},{name:"reserved",type:"USHORT",value:0},{name:"axisCount",type:"USHORT",value:n.axisSegmentMaps.length}]);for(let i=0;i<n.axisSegmentMaps.length;i++){const s=mS(i,n.axisSegmentMaps[i]);t.fields=t.fields.concat(s.fields)}return t}function xS(n,e,t){e||(e=0);const i=new q(n,e),s=i.parseUShort(),r=i.parseUShort();s!==1&&console.warn(`Unsupported avar table version ${s}.${r}`),i.skip("uShort",1);const a=i.parseUShort();Ne.argument(a===t.axes.length,"avar axis count must correspond to fvar axis count");const o=[];for(let l=0;l<a;l++){const c=[],u=i.parseUShort();for(let f=0;f<u;f++){const h=i.parseF2Dot14(),d=i.parseF2Dot14();c.push({fromCoordinate:h,toCoordinate:d})}o.push({axisValueMaps:c})}return{version:[s,r],axisSegmentMaps:o}}var pp={make:gS,parse:xS};function vS(n,e,t,i){const s=new Te.Parser(n,e),r=s.parseTupleVariationStore(s.relativeOffset,t.axes.length,"cvar",i),a=s.parseUShort(),o=s.parseUShort();return a!==1&&console.warn(`Unsupported cvar table version ${a}.${o}`),{version:[a,o],...r}}function yS(){console.warn("Writing of cvar tables is not yet supported.")}var mp={make:yS,parse:vS};function _S(n,e,t,i){const s=new Te.Parser(n,e),r=s.parseUShort(),a=s.parseUShort();r!==1&&console.warn(`Unsupported gvar table version ${r}.${a}`);const o=s.parseUShort();o!==t.axes.length&&console.warn(`axisCount ${o} in gvar table does not match the number of axes ${t.axes.length} in the fvar table!`);const l=s.parseUShort(),c=s.parsePointer32(function(){return this.parseTupleRecords(l,o)}),u=s.parseTupleVariationStoreList(o,"gvar",i);return{version:[r,a],sharedTuples:c,glyphVariations:u}}function bS(){console.warn("Writing of gvar tables is not yet supported.")}var gp={make:bS,parse:_S};function SS(n,e){const t={},i=new Te.Parser(n,e);t.version=i.parseUShort(),Ne.argument(t.version<=1,"Unsupported gasp table version."),t.numRanges=i.parseUShort(),t.gaspRanges=[];for(let s=0;s<t.numRanges;s++)t.gaspRanges[s]={rangeMaxPPEM:i.parseUShort(),rangeGaspBehavior:i.parseUShort()};return t}function MS(n){const e=new me.Table("gasp",[{name:"version",type:"USHORT",value:1},{name:"numRanges",type:"USHORT",value:n.numRanges}]);for(let t in n.gaspRanges)e.fields.push({name:"rangeMaxPPEM",type:"USHORT",value:n.gaspRanges[t].rangeMaxPPEM}),e.fields.push({name:"rangeGaspBehavior",type:"USHORT",value:n.gaspRanges[t].rangeGaspBehavior});return e}var xp={parse:SS,make:MS};function ES(n,e){const t=new Map,i=n.buffer,s=new q(n,e);if(s.parseUShort()!==0)return t;s.relativeOffset=s.parseOffset32();const a=n.byteOffset+e+s.relativeOffset,o=s.parseUShort(),l=new Map;for(let c=0;c<o;c++){const u=s.parseUShort(),f=s.parseUShort(),h=a+s.parseOffset32(),d=s.parseULong();let p=l.get(h);p===void 0&&(p=new Uint8Array(i,h,d),l.set(h,p));for(let x=u;x<=f;x++)t.set(x,p)}return t}function TS(n){const e=Array.from(n.keys()).sort(),t=[],i=[],s=new Map;let r=0,a={endGlyphID:null};for(let h=0,d=e.length;h<d;h++){const p=e[h],x=n.get(p);let m=s.get(x);m===void 0&&(m=r,i.push(x),s.set(x,m),r+=x.byteLength),p-1===a.endGlyphID&&m===a.svgDocOffset?a.endGlyphID=p:(a={startGlyphID:p,endGlyphID:p,svgDocOffset:m,svgDocLength:x.byteLength},t.push(a))}const o=t.length,l=i.length,c=2+o*12,u=new Array(4+o*4+l);let f=0;u[f++]={name:"version",type:"USHORT",value:0},u[f++]={name:"svgDocumentListOffset",type:"ULONG",value:10},u[f++]={name:"reserved",type:"ULONG",value:0},u[f++]={name:"numEntries",type:"USHORT",value:o};for(let h=0;h<o;h++){const d="documentRecord_"+h,{startGlyphID:p,endGlyphID:x,svgDocOffset:m,svgDocLength:g}=t[h];u[f++]={name:d+"_startGlyphID",type:"USHORT",value:p},u[f++]={name:d+"_endGlyphID",type:"USHORT",value:x},u[f++]={name:d+"_svgDocOffset",type:"ULONG",value:c+m},u[f++]={name:d+"_svgDocLength",type:"ULONG",value:g}}for(let h=0;h<l;h++)u[f++]={name:"svgDoc_"+h,type:"LITERAL",value:i[h]};return new me.Table("SVG ",u)}var vp={make:TS,parse:ES};function Bh(n){return Math.log(n)/Math.log(2)|0}function tu(n){for(;n.length%4!==0;)n.push(0);let e=0;for(let t=0;t<n.length;t+=4)e+=(n[t]<<24)+(n[t+1]<<16)+(n[t+2]<<8)+n[t+3];return e%=Math.pow(2,32),e}function Hh(n,e,t,i){return new me.Record("Table Record",[{name:"tag",type:"TAG",value:n!==void 0?n:""},{name:"checkSum",type:"ULONG",value:e!==void 0?e:0},{name:"offset",type:"ULONG",value:t!==void 0?t:0},{name:"length",type:"ULONG",value:i!==void 0?i:0}])}function yp(n){const e=new me.Table("sfnt",[{name:"version",type:"TAG",value:"OTTO"},{name:"numTables",type:"USHORT",value:0},{name:"searchRange",type:"USHORT",value:0},{name:"entrySelector",type:"USHORT",value:0},{name:"rangeShift",type:"USHORT",value:0}]);e.tables=n,e.numTables=n.length;const t=Math.pow(2,Bh(e.numTables));e.searchRange=16*t,e.entrySelector=Bh(t),e.rangeShift=e.numTables*16-e.searchRange;const i=[],s=[];let r=e.sizeOf()+Hh().sizeOf()*e.numTables;for(;r%4!==0;)r+=1,s.push({name:"padding",type:"BYTE",value:0});for(let a=0;a<n.length;a+=1){const o=n[a];Ne.argument(o.tableName.length===4,"Table name"+o.tableName+" is invalid.");const l=o.sizeOf(),c=Hh(o.tableName,tu(o.encode()),r,l);for(i.push({name:c.tag+" Table Record",type:"RECORD",value:c}),s.push({name:o.tableName+" table",type:"RECORD",value:o}),r+=l,Ne.argument(!isNaN(r),"Something went wrong calculating the offset.");r%4!==0;)r+=1,s.push({name:"padding",type:"BYTE",value:0})}return i.sort(function(a,o){return a.value.tag>o.value.tag?1:-1}),e.fields=e.fields.concat(i),e.fields=e.fields.concat(s),e}function zh(n,e,t){for(let i=0;i<e.length;i+=1){const s=n.charToGlyphIndex(e[i]);if(s>0)return n.glyphs.get(s).getMetrics()}return t}function AS(n){let e=0;for(let t=0;t<n.length;t+=1)e+=n[t];return e/n.length}function wS(n){const e=[],t=[],i=[],s=[],r=[],a=[],o=[];let l,c=0,u=0,f=0,h=0,d=0;for(let Q=0;Q<n.glyphs.length;Q+=1){const ye=n.glyphs.get(Q),ve=ye.unicode|0;if(isNaN(ye.advanceWidth))throw new Error("Glyph "+ye.name+" ("+Q+"): advanceWidth is not a number.");(l>ve||l===void 0)&&ve>0&&(l=ve),c<ve&&(c=ve);const _e=Tc.getUnicodeRange(ve);if(_e<32)u|=1<<_e;else if(_e<64)f|=1<<_e-32;else if(_e<96)h|=1<<_e-64;else if(_e<123)d|=1<<_e-96;else throw new Error("Unicode ranges bits > 123 are reserved for internal usage");if(ye.name===".notdef")continue;const Ze=ye.getMetrics();e.push(Ze.xMin),t.push(Ze.yMin),i.push(Ze.xMax),s.push(Ze.yMax),a.push(Ze.leftSideBearing),o.push(Ze.rightSideBearing),r.push(ye.advanceWidth)}const p={xMin:Math.min.apply(null,e),yMin:Math.min.apply(null,t),xMax:Math.max.apply(null,i),yMax:Math.max.apply(null,s),advanceWidthMax:Math.max.apply(null,r),advanceWidthAvg:AS(r),minLeftSideBearing:Math.min.apply(null,a),maxLeftSideBearing:Math.max.apply(null,a),minRightSideBearing:Math.min.apply(null,o)};p.ascender=n.ascender,p.descender=n.descender;let x=0;n.weightClass>=600&&(x|=n.macStyleValues.BOLD),n.italicAngle<0&&(x|=n.macStyleValues.ITALIC);const m=ip.make({flags:3,unitsPerEm:n.unitsPerEm,xMin:p.xMin,yMin:p.yMin,xMax:p.xMax,yMax:p.yMax,lowestRecPPEM:3,macStyle:x,createdTimestamp:n.createdTimestamp}),g=sp.make({ascender:p.ascender,descender:p.descender,advanceWidthMax:p.advanceWidthMax,minLeftSideBearing:p.minLeftSideBearing,minRightSideBearing:p.minRightSideBearing,xMaxExtent:p.maxLeftSideBearing+(p.xMax-p.xMin),numberOfHMetrics:n.glyphs.length}),M=op.make(n.glyphs.length),E=Tc.make(Object.assign({xAvgCharWidth:Math.round(p.advanceWidthAvg),usFirstCharIndex:l,usLastCharIndex:c,ulUnicodeRange1:u,ulUnicodeRange2:f,ulUnicodeRange3:h,ulUnicodeRange4:d,sTypoAscender:p.ascender,sTypoDescender:p.descender,sTypoLineGap:0,usWinAscent:p.yMax,usWinDescent:Math.abs(p.yMin),ulCodePageRange1:1,sxHeight:zh(n,"xyvw",{yMax:Math.round(p.ascender/2)}).yMax,sCapHeight:zh(n,"HIKLEFJMNTZBDPRAGOQSUVWXY",p).yMax,usDefaultChar:n.hasChar(" ")?32:0,usBreakChar:n.hasChar(" ")?32:0},n.tables.os2)),_=rp.make(n.glyphs),T=Wd.make(n.glyphs),b=n.getEnglishName("fontFamily"),S=n.getEnglishName("fontSubfamily"),v=b+" "+S;let w=n.getEnglishName("postScriptName");w||(w=b.replace(/\s/g,"")+"-"+S);const I={};for(let Q in n.names)I[Q]=n.names[Q];I.unicode=I.unicode||{},I.macintosh=I.macintosh||{},I.windows=I.windows||{};const L=n.names.unicode||{},C=n.names.macintosh||{},O=n.names.windows||{};for(const Q in I){if(I[Q]=I[Q]||{},!I[Q].uniqueID){const ye=n.getEnglishName("manufacturer")||"";I[Q].uniqueID={en:`${ye}: ${v}`}}I[Q].postScriptName||(I[Q].postScriptName={en:w})}I.unicode.preferredFamily||(I.unicode.preferredFamily=L.fontFamily||C.fontFamily||O.fontFamily),I.macintosh.preferredFamily||(I.macintosh.preferredFamily=C.fontFamily||L.fontFamily||O.fontFamily),I.windows.preferredFamily||(I.windows.preferredFamily=O.fontFamily||L.fontFamily||C.fontFamily),I.unicode.preferredSubfamily||(I.unicode.preferredSubfamily=L.fontSubfamily||C.fontSubfamily||O.fontSubfamily),I.macintosh.preferredSubfamily||(I.macintosh.preferredSubfamily=C.fontSubfamily||L.fontSubfamily||O.fontSubfamily),I.windows.preferredSubfamily||(I.windows.preferredSubfamily=O.fontSubfamily||L.fontSubfamily||C.fontSubfamily);const N=[],U=Vd.make(I,N),Z=N.length>0?ap.make(N):void 0,k=lp.make(n),$=Mc.make(n.glyphs,{version:n.getEnglishName("version"),fullName:v,familyName:b,weightName:S,postScriptName:w,unitsPerEm:n.unitsPerEm,fontBBox:[0,p.yMin,p.ascender,p.advanceWidthMax],topDict:n.tables.cff&&n.tables.cff.topDict||{}}),D=n.metas&&Object.keys(n.metas).length>0?up.make(n.metas):void 0,ae=[m,g,M,E,U,T,k,$,_];Z&&ae.push(Z);const re={gsub:cp,cpal:Kd,colr:hp,stat:dp,avar:pp,cvar:mp,fvar:fp,gvar:gp,gasp:xp,svg:vp},ee={avar:[n.tables.fvar],fvar:[n.names]};for(let Q in re){const ye=n.tables[Q];if(ye){const ve=re[Q].make.call(n,ye,...ee[Q]||[]);ve&&ae.push(ve)}}D&&ae.push(D);const ce=yp(ae),he=ce.encode(),fe=tu(he),X=ce.fields;let se=!1;for(let Q=0;Q<X.length;Q+=1)if(X[Q].name==="head table"){X[Q].value.checkSumAdjustment=2981146554-fe,se=!0;break}if(!se)throw new Error("Could not find head table with checkSum to adjust.");return ce}var CS={make:yp,fontToTable:wS,computeCheckSum:tu};function ul(n,e){let t=0,i=n.length-1;for(;t<=i;){const s=t+i>>>1,r=n[s].tag;if(r===e)return s;r<e?t=s+1:i=s-1}return-t-1}function Gh(n,e){let t=0,i=n.length-1;for(;t<=i;){const s=t+i>>>1,r=n[s];if(r===e)return s;r<e?t=s+1:i=s-1}return-t-1}function Vh(n,e){let t,i=0,s=n.length-1;for(;i<=s;){const r=i+s>>>1;t=n[r];const a=t.start;if(a===e)return t;a<e?i=r+1:s=r-1}if(i>0)return t=n[i-1],e>t.end?0:t}function _p(n,e){this.font=n,this.tableName=e}_p.prototype={searchTag:ul,binSearch:Gh,getTable:function(n){let e=this.font.tables[this.tableName];return!e&&n&&(e=this.font.tables[this.tableName]=this.createDefaultTable()),e},getScriptNames:function(){let n=this.getTable();return n?n.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){let n=this.getTable();if(!n)return;let e=!1;for(let t=0;t<n.scripts.length;t++){const i=n.scripts[t].tag;if(i==="DFLT")return i;i==="latn"&&(e=!0)}if(e)return"latn"},getScriptTable:function(n,e){const t=this.getTable(e);if(t){n=n||"DFLT";const i=t.scripts,s=ul(t.scripts,n);if(s>=0)return i[s].script;if(e){const r={tag:n,script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}};return i.splice(-1-s,0,r),r.script}}},getLangSysTable:function(n,e,t){const i=this.getScriptTable(n,t);if(i){if(!e||e==="dflt"||e==="DFLT")return i.defaultLangSys;const s=ul(i.langSysRecords,e);if(s>=0)return i.langSysRecords[s].langSys;if(t){const r={tag:e,langSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]}};return i.langSysRecords.splice(-1-s,0,r),r.langSys}}},getFeatureTable:function(n,e,t,i){const s=this.getLangSysTable(n,e,i);if(s){let r;const a=s.featureIndexes,o=this.font.tables[this.tableName].features;for(let l=0;l<a.length;l++)if(r=o[a[l]],r.tag===t)return r.feature;if(i){const l=o.length;return Ne.assert(l===0||t>=o[l-1].tag,"Features must be added in alphabetical order."),r={tag:t,feature:{params:0,lookupListIndexes:[]}},o.push(r),a.push(l),r.feature}}},getLookupTables:function(n,e,t,i,s){const r=this.getFeatureTable(n,e,t,s),a=[];if(r){let o;const l=r.lookupListIndexes,c=this.font.tables[this.tableName].lookups;for(let u=0;u<l.length;u++)o=c[l[u]],o.lookupType===i&&a.push(o);if(a.length===0&&s){o={lookupType:i,lookupFlag:0,subtables:[],markFilteringSet:void 0};const u=c.length;return c.push(o),l.push(u),[o]}}return a},getGlyphClass:function(n,e){switch(n.format){case 1:return n.startGlyph<=e&&e<n.startGlyph+n.classes.length?n.classes[e-n.startGlyph]:0;case 2:{const t=Vh(n.ranges,e);return t?t.classId:0}}},getCoverageIndex:function(n,e){switch(n.format){case 1:{const t=Gh(n.glyphs,e);return t>=0?t:-1}case 2:{const t=Vh(n.ranges,e);return t?t.index+e-t.start:-1}}},expandCoverage:function(n){if(n.format===1)return n.glyphs;{const e=[],t=n.ranges;for(let i=0;i<t.length;i++){const s=t[i],r=s.start,a=s.end;for(let o=r;o<=a;o++)e.push(o)}return e}}};var _o=_p;function Nr(n){_o.call(this,n,"gpos")}Nr.prototype=_o.prototype;Nr.prototype.init=function(){const n=this.getDefaultScriptName();this.defaultKerningTables=this.getKerningTables(n)};Nr.prototype.getKerningValue=function(n,e,t){for(let i=0;i<n.length;i++){const s=n[i].subtables;for(let r=0;r<s.length;r++){const a=s[r],o=this.getCoverageIndex(a.coverage,e);if(!(o<0))switch(a.posFormat){case 1:{let l=a.pairSets[o];for(let c=0;c<l.length;c++){let u=l[c];if(u.secondGlyph===t)return u.value1&&u.value1.xAdvance||0}break}case 2:{const l=this.getGlyphClass(a.classDef1,e),c=this.getGlyphClass(a.classDef2,t),u=a.classRecords[l][c];return u.value1&&u.value1.xAdvance||0}}}}return 0};Nr.prototype.getKerningTables=function(n,e){if(this.font.tables.gpos)return this.getLookupTables(n,e,"kern",2)};var RS=Nr;function PS(n,e){const t=n.length;if(t!==e.length)return!1;for(let i=0;i<t;i++)if(n[i]!==e[i])return!1;return!0}function LS(n,e,t){let i=0,s=n.length-1,r=null;for(;i<=s;){const a=Math.floor((i+s)/2),o=n[a],l=o[e];if(l<t)i=a+1;else if(l>t)s=a-1;else{r=o;break}}return r}function DS(n,e,t){let i=0,s=n.length-1;for(;i<=s;){const r=Math.floor((i+s)/2),a=n[r];if(a[e]<t)i=r+1;else if(a[e]>t)s=r-1;else return r}return-1}function IS(n,e,t){let i=0,s=n.length;const r=(a,o)=>a[e]-o[e];for(;i<s;){const a=i+s>>>1;r(n[a],t)<0?i=a+1:s=a}return n.splice(i,0,t),i}function bp(n){return n[0]===31&&n[1]===139&&n[2]===8}function US(n){const e=new DataView(n.buffer,n.byteOffset,n.byteLength);let t=10;const i=n.byteLength-8,s=e.getInt8(3);if(s&4&&(t+=2+e.getUint16(t,!0)),s&8)for(;t<i&&n[t++]!==0;);if(s&16)for(;t<i&&n[t++]!==0;);if(s&2&&(t+=2),t>=i)throw new Error("Can't find compressed blocks");const r=e.getUint32(e.byteLength-4,!0);return Id(n.subarray(t,i),new Uint8Array(r))}function Wh(n){return{x:n.x,y:n.y,onCurve:n.onCurve,lastPointOfContour:n.lastPointOfContour}}function OS(n){return{glyphIndex:n.glyphIndex,xScale:n.xScale,scale01:n.scale01,scale10:n.scale10,yScale:n.yScale,dx:n.dx,dy:n.dy}}function gn(n){_o.call(this,n,"gsub")}function nu(n,e,t){const i=n.subtables;for(let s=0;s<i.length;s++){const r=i[s];if(r.substFormat===e)return r}if(t)return i.push(t),t}gn.prototype=_o.prototype;gn.prototype.createDefaultTable=function(){return{version:1,scripts:[{tag:"DFLT",script:{defaultLangSys:{reserved:0,reqFeatureIndex:65535,featureIndexes:[]},langSysRecords:[]}}],features:[],lookups:[]}};gn.prototype.getSingle=function(n,e,t){const i=[],s=this.getLookupTables(e,t,n,1);for(let r=0;r<s.length;r++){const a=s[r].subtables;for(let o=0;o<a.length;o++){const l=a[o],c=this.expandCoverage(l.coverage);let u;if(l.substFormat===1){const f=l.deltaGlyphId;for(u=0;u<c.length;u++){const h=c[u];i.push({sub:h,by:h+f})}}else{const f=l.substitute;for(u=0;u<c.length;u++)i.push({sub:c[u],by:f[u]})}}}return i};gn.prototype.getMultiple=function(n,e,t){const i=[],s=this.getLookupTables(e,t,n,2);for(let r=0;r<s.length;r++){const a=s[r].subtables;for(let o=0;o<a.length;o++){const l=a[o],c=this.expandCoverage(l.coverage);let u;for(u=0;u<c.length;u++){const f=c[u],h=l.sequences[u];i.push({sub:f,by:h})}}}return i};gn.prototype.getAlternates=function(n,e,t){const i=[],s=this.getLookupTables(e,t,n,3);for(let r=0;r<s.length;r++){const a=s[r].subtables;for(let o=0;o<a.length;o++){const l=a[o],c=this.expandCoverage(l.coverage),u=l.alternateSets;for(let f=0;f<c.length;f++)i.push({sub:c[f],by:u[f]})}}return i};gn.prototype.getLigatures=function(n,e,t){const i=[],s=this.getLookupTables(e,t,n,4);for(let r=0;r<s.length;r++){const a=s[r].subtables;for(let o=0;o<a.length;o++){const l=a[o],c=this.expandCoverage(l.coverage),u=l.ligatureSets;for(let f=0;f<c.length;f++){const h=c[f],d=u[f];for(let p=0;p<d.length;p++){const x=d[p];i.push({sub:[h].concat(x.components),by:x.ligGlyph})}}}}return i};gn.prototype.addSingle=function(n,e,t,i){const s=this.getLookupTables(t,i,n,1,!0)[0],r=nu(s,2,{substFormat:2,coverage:{format:1,glyphs:[]},substitute:[]});Ne.assert(r.coverage.format===1,"Single: unable to modify coverage table format "+r.coverage.format);const a=e.sub;let o=this.binSearch(r.coverage.glyphs,a);o<0&&(o=-1-o,r.coverage.glyphs.splice(o,0,a),r.substitute.splice(o,0,0)),r.substitute[o]=e.by};gn.prototype.addMultiple=function(n,e,t,i){Ne.assert(e.by instanceof Array&&e.by.length>1,'Multiple: "by" must be an array of two or more ids');const s=this.getLookupTables(t,i,n,2,!0)[0],r=nu(s,1,{substFormat:1,coverage:{format:1,glyphs:[]},sequences:[]});Ne.assert(r.coverage.format===1,"Multiple: unable to modify coverage table format "+r.coverage.format);const a=e.sub;let o=this.binSearch(r.coverage.glyphs,a);o<0&&(o=-1-o,r.coverage.glyphs.splice(o,0,a),r.sequences.splice(o,0,0)),r.sequences[o]=e.by};gn.prototype.addAlternate=function(n,e,t,i){const s=this.getLookupTables(t,i,n,3,!0)[0],r=nu(s,1,{substFormat:1,coverage:{format:1,glyphs:[]},alternateSets:[]});Ne.assert(r.coverage.format===1,"Alternate: unable to modify coverage table format "+r.coverage.format);const a=e.sub;let o=this.binSearch(r.coverage.glyphs,a);o<0&&(o=-1-o,r.coverage.glyphs.splice(o,0,a),r.alternateSets.splice(o,0,0)),r.alternateSets[o]=e.by};gn.prototype.addLigature=function(n,e,t,i){const s=this.getLookupTables(t,i,n,4,!0)[0];let r=s.subtables[0];r||(r={substFormat:1,coverage:{format:1,glyphs:[]},ligatureSets:[]},s.subtables[0]=r),Ne.assert(r.coverage.format===1,"Ligature: unable to modify coverage table format "+r.coverage.format);const a=e.sub[0],o=e.sub.slice(1),l={ligGlyph:e.by,components:o};let c=this.binSearch(r.coverage.glyphs,a);if(c>=0){const u=r.ligatureSets[c];for(let f=0;f<u.length;f++)if(PS(u[f].components,o))return;u.push(l)}else c=-1-c,r.coverage.glyphs.splice(c,0,a),r.ligatureSets.splice(c,0,[l])};gn.prototype.getFeature=function(n,e,t){if(/ss\d\d/.test(n))return this.getSingle(n,e,t);switch(n){case"aalt":case"salt":return this.getSingle(n,e,t).concat(this.getAlternates(n,e,t));case"dlig":case"liga":case"rlig":return this.getLigatures(n,e,t);case"ccmp":return this.getMultiple(n,e,t).concat(this.getLigatures(n,e,t));case"stch":return this.getMultiple(n,e,t)}};gn.prototype.add=function(n,e,t,i){if(/ss\d\d/.test(n))return this.addSingle(n,e,t,i);switch(n){case"aalt":case"salt":return typeof e.by=="number"?this.addSingle(n,e,t,i):this.addAlternate(n,e,t,i);case"dlig":case"liga":case"rlig":return this.addLigature(n,e,t,i);case"ccmp":return e.by instanceof Array?this.addMultiple(n,e,t,i):this.addLigature(n,e,t,i)}};var FS=gn,Sp=class{constructor(n){this.defaultValue=255,this.font=n}cpal(){return this.font.tables&&this.font.tables.cpal?this.font.tables.cpal:!1}getAll(n){const e=[],t=this.cpal();if(!t)return e;for(let i=0;i<t.colorRecordIndices.length;i++){const s=t.colorRecordIndices[i],r=[];for(let a=s;a<s+t.numPaletteEntries;a++)r.push(Js(t.colorRecords[a],n||"hexa"));e.push(r)}return e}toCPALcolor(n){return Array.isArray(n)?n.map(e=>co(e,"raw")):co(n,"raw")}fillPalette(n,e=[],t=this.cpal().numPaletteEntries){return n=Number.isInteger(n)?this.get(n,"raw"):n,Object.assign(Array(t).fill(this.defaultValue),this.toCPALcolor(n).concat(this.toCPALcolor(e)))}extend(n){if(this.ensureCPAL(Array(n).fill(this.defaultValue)))return;const e=this.cpal(),t=e.numPaletteEntries+n,i=this.getAll().map(s=>this.fillPalette(s,[],t));e.numPaletteEntries=t,e.colorRecords=this.toCPALcolor(i.flat()),this.updateIndices()}get(n,e="hexa"){return this.getAll(e)[n]||null}getColor(n,e=0,t="hexa"){return Jc(this.font,n,e,t)}setColor(n,e,t=0){n=parseInt(n),t=parseInt(t);let i=this.getAll("raw"),s=i[t];if(!s)throw Error(`paletteIndex ${t} out of range`);const r=this.cpal(),a=r.numPaletteEntries;Array.isArray(e)||(e=[e]),e.length+n>a&&(this.extend(e.length+n-a),i=this.getAll("raw"),s=i[t]);for(let o=0;o<e.length;o++)s[o+n]=this.toCPALcolor(e[o]);r.colorRecords=i.flat(),this.updateIndices()}add(n){if(this.ensureCPAL(n))return;const e=this.cpal(),t=e.numPaletteEntries;n&&n.length?(n=this.toCPALcolor(n),n.length>t?this.extend(n.length-t):n.length<t&&(n=this.fillPalette(n)),e.colorRecordIndices.push(e.colorRecords.length),e.colorRecords.push(...n)):(e.colorRecordIndices.push(e.colorRecords.length),e.colorRecords.push(...Array(t).fill(this.defaultValue)))}delete(n){const e=this.getAll("raw");delete e[n];const t=this.cpal();t.colorRecordIndices.pop(),t.colorRecords=e.flat()}deleteColor(n,e){if(n===e)throw Error("replacementIndex cannot be the same as colorIndex");const t=this.cpal(),i=this.getAll("raw"),s=[];if(e>t.numPaletteEntries-1)throw Error(`Replacement index out of range: numPaletteEntries after deletion: ${t.numPaletteEntries-1}, replacementIndex: ${e})`);for(let o=0;o<i.length;o++){const c=i[o].filter((u,f)=>f!==n);s.push(c)}const r=this.font.tables.colr;if(r){const o=r.layerRecords;for(let l=0;l<o.length;l++){const c=o[l].paletteIndex;if(c>n)o[l].paletteIndex-=1;else if(c===n){let u=0;for(let f=0;f<i.length;f++)if(e>n&&e<=n+i[f].length){u++;break}o[l].paletteIndex=e-u}}this.font.tables.colr={...r,layerRecords:o}}const a=s.flat();for(let o=0;o<i.length;o++)t.colorRecordIndices[o]-=o;t.numPaletteEntries=Math.max(0,t.numPaletteEntries-1),t.colorRecords=this.toCPALcolor(a)}ensureCPAL(n){return this.cpal()?!1:(!n||!n.length?n=[this.defaultValue]:n=this.toCPALcolor(n),this.font.tables.cpal={version:0,numPaletteEntries:n.length,colorRecords:n,colorRecordIndices:[0]},!0)}updateIndices(){const n=this.cpal(),e=Math.ceil(n.colorRecords.length/n.numPaletteEntries);n.colorRecordIndices=[];for(let t=0;t<e;t++)n.colorRecordIndices.push(t*n.numPaletteEntries)}},NS=class{constructor(n){this.font=n}ensureCOLR(){return this.font.tables.colr||(this.font.tables.colr={version:0,baseGlyphRecords:[],layerRecords:[]}),this.font}get(n){const e=this.font,t=[],i=e.tables.colr,s=e.tables.cpal;if(!i||!s)return t;const r=LS(i.baseGlyphRecords,"glyphID",n);if(!r)return t;const a=r.firstLayerIndex,o=r.numLayers;for(let l=0;l<o;l++){const c=i.layerRecords[a+l];t.push({glyph:e.glyphs.get(c.glyphID),paletteIndex:c.paletteIndex})}return t}add(n,e,t){const i=this.get(n);e=Array.isArray(e)?e:[e],t===void 0||t===1/0||t>i.length?t=i.length:t<0&&(t=i.length+1+t%(i.length+1),t>=i.length+1&&(t-=i.length+1));const s=[];for(let r=0;r<t;r++){const a=Number.isInteger(i[r].glyph)?i[r].glyph:i[r].glyph.index;s.push({glyphID:a,paletteIndex:i[r].paletteIndex})}for(const r of e){const a=Number.isInteger(r.glyph)?r.glyph:r.glyph.index;s.push({glyphID:a,paletteIndex:r.paletteIndex})}for(let r=t;r<i.length;r++){const a=Number.isInteger(i[r].glyph)?i[r].glyph:i[r].glyph.index;s.push({glyphID:a,paletteIndex:i[r].paletteIndex})}this.updateColrTable(n,s)}setPaletteIndex(n,e,t){let i=this.get(n);i[e]?(i=i.map((s,r)=>({glyphID:s.glyph.index,paletteIndex:r===e?t:s.paletteIndex})),this.updateColrTable(n,i)):console.error("Invalid layer index")}remove(n,e,t=e){let i=this.get(n);i=i.map(s=>({glyphID:s.glyph.index,paletteIndex:s.paletteIndex})),i.splice(e,t-e+1),this.updateColrTable(n,i)}updateColrTable(n,e){this.ensureCOLR();const i=this.font.tables.colr;let s=DS(i.baseGlyphRecords,"glyphID",n);if(s===-1){const u={glyphID:n,firstLayerIndex:i.layerRecords.length,numLayers:0};s=IS(i.baseGlyphRecords,"glyphID",u)}const a=i.baseGlyphRecords[s],o=a.numLayers,l=e.length,c=l-o;if(c>0){const u=e.slice(o).map(f=>({glyphID:f.glyphID,paletteIndex:f.paletteIndex}));i.layerRecords.splice(a.firstLayerIndex+o,0,...u)}else c<0&&i.layerRecords.splice(a.firstLayerIndex+l,-c);for(let u=0;u<Math.min(o,l);u++)i.layerRecords[a.firstLayerIndex+u]={glyphID:e[u].glyphID,paletteIndex:e[u].paletteIndex};if(a.numLayers=l,c!==0)for(let u=0;u<i.baseGlyphRecords.length;u++){const f=i.baseGlyphRecords[u];u===s||f.firstLayerIndex<a.firstLayerIndex||(i.baseGlyphRecords[u].firstLayerIndex+=c)}}},kS=class{constructor(n){this.font=n,this.cache=new WeakMap}get(n){const e=this.getOrCreateSvgImageCacheEntry(n);return e&&e.image}getAsync(n){const e=this.getOrCreateSvgImageCacheEntry(n);return e&&e.promise}getOrCreateSvgImageCacheEntry(n){const e=this.font.tables.svg;if(e===void 0)return;const t=e.get(n);if(t===void 0)return;let i=this.cache.get(t);i===void 0&&(i=BS(t),this.cache.set(t,i));let s=i.images.get(n);return s===void 0&&(s=HS(this.font,i.template,n),s.promise.then(r=>{if(s.image=r,typeof this.font.onGlyphUpdated=="function")try{this.font.onGlyphUpdated(n)}catch(a){console.error("font.onGlyphUpdated",n,a)}}),i.images.set(n,s)),s}};function BS(n){return{template:zS(n).then(WS),images:new Map}}function HS(n,e,t){return{promise:e.then(i=>{let s;typeof i=="string"?s=i:(i[4]=t,s=i.join(""));const r=XS(s,n.unitsPerEm);return r.image.decode().then(()=>r)}),image:void 0}}var zS=typeof DecompressionStream=="function"?VS:GS;function GS(n){try{return Promise.resolve(new TextDecoder().decode(bp(n)?US(n):n))}catch(e){return Promise.reject(e)}}function VS(n){if(bp(n))return new Response(new Response(n).body.pipeThrough(new DecompressionStream("gzip"))).text();try{return Promise.resolve(new TextDecoder().decode(n))}catch(e){return Promise.reject(e)}}function WS(n){const e=n.indexOf("<svg"),t=n.indexOf(">",e+4)+1;if(/ id=['"]glyph\d+['"]/.test(n.substring(e,t)))return n;const i=n.lastIndexOf("</svg>");return[n.substring(0,t),"<defs>",n.substring(t,i),'</defs><use href="#glyph',"",'"/>',n.substring(i)]}function XS(n,e){const i=new DOMParser().parseFromString(n,"image/svg+xml").documentElement,s=i.viewBox.baseVal,r=i.width.baseVal,a=i.height.baseVal;let o=1,l=1;s.width>0&&s.height>0&&(r.unitType===1?(o=r.valueInSpecifiedUnits/s.width,l=a.unitType===1?a.valueInSpecifiedUnits/s.height:o):a.unitType===1?(l=a.valueInSpecifiedUnits/s.height,o=l):e&&(o=e/s.width,l=e/s.height));const c=document.createElement("div");c.style.position="fixed",c.style.visibility="hidden",c.appendChild(i),document.body.appendChild(c);const u=i.getBBox();document.body.removeChild(c);const f=(u.x-s.x)*o,h=(s.y-u.y)*l,d=u.width*o,p=u.height*l;i.setAttribute("viewBox",[u.x,u.y,u.width,u.height].join(" ")),o!==1&&i.setAttribute("width",d),l!==1&&i.setAttribute("height",p);const x=new Image(d,p);return x.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(i.outerHTML),{leftSideBearing:f,baseline:h,image:x}}var hl=new WeakMap;function Xh(n,e,t,i,s){let r;return(e&i)>0?(r=n.parseByte(),e&s||(r=-r),r=t+r):(e&s)>0?r=t:r=t+n.parseShort(),r}function Mp(n,e,t){const i=new Te.Parser(e,t);n._numberOfContours=i.parseShort(),n._xMin=i.parseShort(),n._yMin=i.parseShort(),n._xMax=i.parseShort(),n._yMax=i.parseShort();let s,r;if(n._numberOfContours>0){const a=n.endPointIndices=[];for(let l=0;l<n._numberOfContours;l+=1)a.push(i.parseUShort());n.instructionLength=i.parseUShort(),n.instructions=[];for(let l=0;l<n.instructionLength;l+=1)n.instructions.push(i.parseByte());const o=a[a.length-1]+1;s=[];for(let l=0;l<o;l+=1)if(r=i.parseByte(),s.push(r),(r&8)>0){const c=i.parseByte();for(let u=0;u<c;u+=1)s.push(r),l+=1}if(Ne.argument(s.length===o,"Bad flags."),a.length>0){const l=[];let c;if(o>0){for(let h=0;h<o;h+=1)r=s[h],c={},c.onCurve=!!(r&1),c.lastPointOfContour=a.indexOf(h)>=0,l.push(c);let u=0;for(let h=0;h<o;h+=1)r=s[h],c=l[h],c.x=Xh(i,r,u,2,16),u=c.x;let f=0;for(let h=0;h<o;h+=1)r=s[h],c=l[h],c.y=Xh(i,r,f,4,32),f=c.y}n.points=l}else n.points=[]}else if(n._numberOfContours===0)n.points=[];else{n.isComposite=!0,n.points=[],n.components=[];let a=!0;for(;a;){s=i.parseUShort();const o={glyphIndex:i.parseUShort(),xScale:1,scale01:0,scale10:0,yScale:1,dx:0,dy:0};(s&1)>0?(s&2)>0?(o.dx=i.parseShort(),o.dy=i.parseShort()):o.matchedPoints=[i.parseUShort(),i.parseUShort()]:(s&2)>0?(o.dx=i.parseChar(),o.dy=i.parseChar()):o.matchedPoints=[i.parseByte(),i.parseByte()],(s&8)>0?o.xScale=o.yScale=i.parseF2Dot14():(s&64)>0?(o.xScale=i.parseF2Dot14(),o.yScale=i.parseF2Dot14()):(s&128)>0&&(o.xScale=i.parseF2Dot14(),o.scale01=i.parseF2Dot14(),o.scale10=i.parseF2Dot14(),o.yScale=i.parseF2Dot14()),n.components.push(o),a=!!(s&32)}if(s&256){n.instructionLength=i.parseUShort(),n.instructions=[];for(let o=0;o<n.instructionLength;o+=1)n.instructions.push(i.parseByte())}}}function za(n,e){const t=[];for(let i=0;i<n.length;i+=1){const s=n[i],r={x:e.xScale*s.x+e.scale10*s.y+e.dx,y:e.scale01*s.x+e.yScale*s.y+e.dy,onCurve:s.onCurve,lastPointOfContour:s.lastPointOfContour};t.push(r)}return t}function YS(n){const e=[];let t=[];for(let i=0;i<n.length;i+=1){const s=n[i];t.push(s),s.lastPointOfContour&&(e.push(t),t=[])}return Ne.argument(t.length===0,"There are still points left in the current contour."),e}function iu(n){const e=new qs;if(!n)return e;const t=YS(n);for(let i=0;i<t.length;++i){const s=t[i];let r=s[s.length-1],a=s[0];if(r.onCurve)e.moveTo(r.x,r.y);else if(a.onCurve)e.moveTo(a.x,a.y);else{const o={x:(r.x+a.x)*.5,y:(r.y+a.y)*.5};e.moveTo(o.x,o.y)}for(let o=0;o<s.length;++o)if(r=a,a=s[(o+1)%s.length],r.onCurve)e.lineTo(r.x,r.y);else{let l=a;a.onCurve||(l={x:(r.x+a.x)*.5,y:(r.y+a.y)*.5}),e.quadraticCurveTo(r.x,r.y,l.x,l.y)}e.closePath()}return e}function Ep(n,e){if(e.isComposite){hl.has(n)||hl.set(n,new Set);const t=hl.get(n);t.add(e.index);try{for(let i=0;i<e.components.length;i+=1){const s=e.components[i];if(t.has(s.glyphIndex))continue;const r=n.get(s.glyphIndex);if(r.getPath(),r.points){let a;if(s.matchedPoints===void 0)a=za(r.points,s);else{if(s.matchedPoints[0]>e.points.length-1||s.matchedPoints[1]>r.points.length-1)throw Error("Matched points out of range in "+e.name);const o=e.points[s.matchedPoints[0]];let l=r.points[s.matchedPoints[1]];const c={xScale:s.xScale,scale01:s.scale01,scale10:s.scale10,yScale:s.yScale,dx:0,dy:0};l=za([l],c)[0],c.dx=o.x-l.x,c.dy=o.y-l.y,a=za(r.points,c)}e.points=e.points.concat(a)}}}finally{t.delete(e.index)}}return iu(e.points)}function qS(n,e,t,i){const s=new jn.GlyphSet(i);for(let r=0;r<t.length-1;r+=1){const a=t[r],o=t[r+1];a!==o?s.push(r,jn.ttfGlyphLoader(i,r,Mp,n,e+a,Ep)):s.push(r,jn.glyphLoader(i,r))}return s}function $S(n,e,t,i){const s=new jn.GlyphSet(i);return i._push=function(r){const a=t[r],o=t[r+1];a!==o?s.push(r,jn.ttfGlyphLoader(i,r,Mp,n,e+a,Ep)):s.push(r,jn.glyphLoader(i,r))},s}function ZS(n,e,t,i,s){return s.lowMemory?$S(n,e,t,i):qS(n,e,t,i)}var Tp={getPath:iu,parse:ZS},KS=class{constructor(n){this.font=n}normalizeCoordTags(n){for(const e in n)if(e.length<4){const t=e.padEnd(4," ");n[t]===void 0&&(n[t]=n[e]),delete n[e]}}getNormalizedCoords(n){n||(n=this.font.variation.get());let e=[];this.normalizeCoordTags(n);for(let t=0;t<this.fvar().axes.length;t++){const i=this.fvar().axes[t];let s=n[i.tag];s===void 0&&(s=i.defaultValue),s<i.defaultValue?e.push((s-i.defaultValue+Number.EPSILON)/(i.defaultValue-i.minValue+Number.EPSILON)):e.push((s-i.defaultValue+Number.EPSILON)/(i.maxValue-i.defaultValue+Number.EPSILON))}if(this.avar())for(let t=0;t<this.avar().axisSegmentMaps.length;t++){let i=this.avar().axisSegmentMaps[t];for(let s=0;s<i.axisValueMaps.length;s++){let r=i.axisValueMaps[s];if(s>=1&&e[t]<r.fromCoordinate){let a=i.axisValueMaps[s-1];e[t]=((e[t]-a.fromCoordinate)*(r.toCoordinate-a.toCoordinate)+Number.EPSILON)/(r.fromCoordinate-a.fromCoordinate+Number.EPSILON)+a.toCoordinate;break}}}return e}interpolatePoints(n,e,t){if(n.length===0)return;let i=0;for(;i<n.length;){let s=i,r=i,a=n[r];for(;!a.lastPointOfContour;)a=n[++r];for(;i<=r&&!t[i];)i++;if(i>r)continue;let o=i,l=i;for(i++;i<=r;)t[i]&&(this.deltaInterpolate(l+1,i-1,l,i,e,n),l=i),i++;l===o?this.deltaShift(s,r,l,e,n):(this.deltaInterpolate(l+1,r,l,o,e,n),o>0&&this.deltaInterpolate(s,o-1,l,o,e,n)),i=r+1}}deltaInterpolate(n,e,t,i,s,r){if(n>e)return;let a=["x","y"];for(let l=0;l<a.length;l++){let c=a[l];if(s[t][c]>s[i][c]){var o=t;t=i,i=o}let u=s[t][c],f=s[i][c],h=r[t][c],d=r[i][c];if(u!==f||h===d){let p=u===f?0:(d-h)/(f-u);for(let x=n;x<=e;x++){let m=s[x][c];m<=u?m+=h-u:m>=f?m+=d-f:m=h+(m-u)*p,r[x][c]=m}}}}deltaShift(n,e,t,i,s){let r=s[t].x-i[t].x,a=s[t].y-i[t].y;if(!(r===0&&a===0))for(let o=n;o<=e;o++)o!==t&&(s[o].x+=r,s[o].y+=a)}transformComponents(n,e,t,i,s,r){let a=0;for(let o=0;o<n.components.length;o++){const l=n.components[o],c=this.font.glyphs.get(l.glyphIndex),u=OS(l),f=i.indexOf(o);f>-1&&(u.dx+=Math.round(s.deltas[f]*r),u.dy+=Math.round(s.deltasY[f]*r));const h=za(this.getTransform(c,t).points,u);e.splice(a,h.length,...h),a+=c.points.length}}applyTupleVariationStore(n,e,t,i="gvar",s={}){t||(t=this.font.variation.get());const r=this.getNormalizedCoords(t),{headers:a,sharedPoints:o}=n,l=this.fvar().axes.length;let c;i==="gvar"?c=e.map(Wh):i==="cvar"&&(c=[...e]);for(let u=0;u<a.length;u++){const f=a[u];let h=1;for(let p=0;p<l;p++){let x=[0];switch(i){case"gvar":x=f.peakTuple?f.peakTuple:this.gvar().sharedTuples[f.sharedTupleRecordsIndex];break;case"cvar":x=f.peakTuple;break}if(x[p]!==0){if(r[p]===0){h=0;break}if(f.intermediateStartTuple)if(r[p]<f.intermediateStartTuple[p]||r[p]>f.intermediateEndTuple[p]){h=0;break}else r[p]<x[p]?h=h*(r[p]-f.intermediateStartTuple[p]+Number.EPSILON)/(x[p]-f.intermediateStartTuple[p]+Number.EPSILON):h=h*(f.intermediateEndTuple[p]-r[p]+Number.EPSILON)/(f.intermediateEndTuple[p]-x[p]+Number.EPSILON);else{if(r[p]<Math.min(0,x[p])||r[p]>Math.max(0,x[p])){h=0;break}h=(h*r[p]+Number.EPSILON)/(x[p]+Number.EPSILON)}}}if(h===0)continue;const d=f.privatePoints.length?f.privatePoints:o;if(i==="gvar"&&s.glyph&&s.glyph.isComposite)this.transformComponents(s.glyph,c,t,d,f,h);else if(d.length===0)for(let p=0;p<c.length;p++){const x=c[p];i==="gvar"?c[p]={x:Math.round(x.x+f.deltas[p]*h),y:Math.round(x.y+f.deltasY[p]*h),onCurve:x.onCurve,lastPointOfContour:x.lastPointOfContour}:i==="cvar"&&(c[p]=Math.round(x+f.deltas[p]*h))}else{let p;i==="gvar"?p=c.map(Wh):i==="cvar"&&(p=c);const x=Array(e.length).fill(!1);for(let m=0;m<d.length;m++){let g=d[m];if(g<e.length){let M=p[g];i==="gvar"?(x[g]=!0,M.x+=f.deltas[m]*h,M.y+=f.deltasY[m]*h):i==="cvar"&&(c[g]=Math.round(M+f.deltas[m]*h))}}if(i==="gvar"){this.interpolatePoints(p,c,x);for(let m=0;m<e.length;m++){let g=p[m].x-c[m].x,M=p[m].y-c[m].y;c[m].x=Math.round(c[m].x+g),c[m].y=Math.round(c[m].y+M)}}}}return c}getTransform(n,e){Number.isInteger(n)&&(n=this.font.glyphs.get(n));const t=n.getBlendPath,i=!!(n.points&&n.points.length);let s=n;if(t||i){if(e||(e=this.font.variation.get()),i){const r=this.gvar()&&this.gvar().glyphVariations[n.index];if(r){const a=n.points;let o=this.applyTupleVariationStore(r,a,e,"gvar",{glyph:n});s=new Lr(Object.assign({},n,{points:o,path:iu(o)}))}}else if(t){const r=n.getBlendPath(e);s=new Lr(Object.assign({},n,{path:r}))}}return this.font.tables.hvar&&(n._advanceWidth=typeof n._advanceWidth<"u"?n._advanceWidth:n.advanceWidth,n.advanceWidth=s.advanceWidth=Math.round(n._advanceWidth+this.getVariableAdjustment(s.index,"hvar","advanceWidth",e)),n._leftSideBearing=typeof n._leftSideBearing<"u"?n._leftSideBearing:n.leftSideBearing,n.leftSideBearing=s.leftSideBearing=Math.round(n._leftSideBearing+this.getVariableAdjustment(s.index,"hvar","lsb",e))),s}getCvarTransform(n){const e=this.font.tables.cvt,t=this.cvar();return!e||!e.length||!t||!t.headers.length?e:this.applyTupleVariationStore(t,e,n,"cvar")}getVariableAdjustment(n,e,t,i){i=i||this.font.variation.get();let s,r;const a=this.font.tables[e];if(!a)throw Error(`trying to get variation adjustment from non-existent table "${a}"`);if(!a.itemVariationStore)throw Error(`trying to get variation adjustment from table "${a}" which does not have an itemVariationStore`);const o=a[t]&&a[t].map.length;if(o){let l=n;l>=o&&(l=o-1),{outerIndex:s,innerIndex:r}=a[t].map[l]}else s=0,r=n;return this.getDelta(a.itemVariationStore,s,r,i)}getDelta(n,e,t,i){if(e>=n.itemVariationSubtables.length)return 0;let s=n.itemVariationSubtables[e];if(t>=s.deltaSets.length)return 0;let r=s.deltaSets[t],a=this.getBlendVector(n,e,i),o=0;for(let l=0;l<s.regionIndexes.length;l++)o+=r[l]*a[l];return o}getBlendVector(n,e,t){t||(t=this.font.variation.get());let i=n.itemVariationSubtables[e];const s=this.getNormalizedCoords(t);let r=[];for(let a=0;a<i.regionIndexes.length;a++){let o=1,l=i.regionIndexes[a],c=n.variationRegions[l].regionAxes;for(let u=0;u<c.length;u++){let f=c[u],h;f.startCoord>f.peakCoord||f.peakCoord>f.endCoord||f.startCoord<0&&f.endCoord>0&&f.peakCoord!==0||f.peakCoord===0?h=1:s[u]<f.startCoord||s[u]>f.endCoord?h=0:s[u]===f.peakCoord?h=1:s[u]<f.peakCoord?h=(s[u]-f.startCoord+Number.EPSILON)/(f.peakCoord-f.startCoord+Number.EPSILON):h=(f.endCoord-s[u]+Number.EPSILON)/(f.endCoord-f.peakCoord+Number.EPSILON),o*=h}r[a]=o}return r}avar(){return this.font.tables.avar}cvar(){return this.font.tables.cvar}fvar(){return this.font.tables.fvar}gvar(){return this.font.tables.gvar}hvar(){return this.font.tables.hvar}},JS=class{constructor(n){this.font=n,this.process=new KS(this.font),this.activateDefaultVariation(),this.getTransform=this.process.getTransform.bind(this.process)}activateDefaultVariation(){const n=this.getDefaultInstanceIndex();n>-1?this.set(n):this.set(this.getDefaultCoordinates())}getDefaultCoordinates(){return this.fvar().axes.reduce((n,e)=>(n[e.tag]=e.defaultValue,n),{})}getDefaultInstanceIndex(){const n=this.getDefaultCoordinates();let e=this.getInstanceIndex(n);return e<0&&(e=this.fvar().instances.findIndex(t=>t.name&&t.name.en==="Regular")),e}getInstanceIndex(n){return this.fvar().instances.findIndex(e=>Object.keys(n).every(t=>e.coordinates[t]===n[t]))}getInstance(n){return this.fvar().instances&&this.fvar().instances[n]}set(n){let e;if(Number.isInteger(n)){const t=this.getInstance(n);if(!t)throw Error(`Invalid instance index ${n}`);e={...t.coordinates}}else e=n,this.process.normalizeCoordTags(e);e=Object.assign({},this.font.defaultRenderOptions.variation,e),this.font.defaultRenderOptions=Object.assign({},this.font.defaultRenderOptions,{variation:e})}get(){return Object.assign({},this.font.defaultRenderOptions.variation)}avar(){return this.font.tables.avar}cvar(){return this.font.tables.cvar}fvar(){return this.font.tables.fvar}gvar(){return this.font.tables.gvar}hvar(){return this.font.tables.hvar}},Yh=1e6,ho=64,fo=1e4,Ap,ss,wp,Ac;function Cp(n){this.font=n,this.getCommands=function(e){return Tp.getPath(e).commands},this._fpgmState=this._prepState=void 0,this._errorState=0}function jS(n){return n}function Rp(n){return Math.sign(n)*Math.round(Math.abs(n))}function QS(n){return Math.sign(n)*Math.round(Math.abs(n*2))/2}function eM(n){return Math.sign(n)*(Math.round(Math.abs(n)+.5)-.5)}function tM(n){return Math.sign(n)*Math.ceil(Math.abs(n))}function nM(n){return Math.sign(n)*Math.floor(Math.abs(n))}var Pp=function(n){const e=this.srPeriod;let t=this.srPhase;const i=this.srThreshold;let s=1;return n<0&&(n=-n,s=-1),n+=i-t,n=Math.trunc(n/e)*e,n+=t,n<0?t*s:n*s},Zn={x:1,y:0,axis:"x",distance:function(n,e,t,i){return(t?n.xo:n.x)-(i?e.xo:e.x)},interpolate:function(n,e,t,i){let s,r,a,o,l,c,u;if(!i||i===this){if(s=n.xo-e.xo,r=n.xo-t.xo,l=e.x-e.xo,c=t.x-t.xo,a=Math.abs(s),o=Math.abs(r),u=a+o,u===0){n.x=n.xo+(l+c)/2;return}n.x=n.xo+(l*o+c*a)/u;return}if(s=i.distance(n,e,!0,!0),r=i.distance(n,t,!0,!0),l=i.distance(e,e,!1,!0),c=i.distance(t,t,!1,!0),a=Math.abs(s),o=Math.abs(r),u=a+o,u===0){Zn.setRelative(n,n,(l+c)/2,i,!0);return}Zn.setRelative(n,n,(l*o+c*a)/u,i,!0)},normalSlope:Number.NEGATIVE_INFINITY,setRelative:function(n,e,t,i,s){if(!i||i===this){n.x=(s?e.xo:e.x)+t;return}const r=s?e.xo:e.x,a=s?e.yo:e.y,o=r+t*i.x,l=a+t*i.y;n.x=o+(n.y-l)/i.normalSlope},slope:0,touch:function(n){n.xTouched=!0},touched:function(n){return n.xTouched},untouch:function(n){n.xTouched=!1}},ci={x:0,y:1,axis:"y",distance:function(n,e,t,i){return(t?n.yo:n.y)-(i?e.yo:e.y)},interpolate:function(n,e,t,i){let s,r,a,o,l,c,u;if(!i||i===this){if(s=n.yo-e.yo,r=n.yo-t.yo,l=e.y-e.yo,c=t.y-t.yo,a=Math.abs(s),o=Math.abs(r),u=a+o,u===0){n.y=n.yo+(l+c)/2;return}n.y=n.yo+(l*o+c*a)/u;return}if(s=i.distance(n,e,!0,!0),r=i.distance(n,t,!0,!0),l=i.distance(e,e,!1,!0),c=i.distance(t,t,!1,!0),a=Math.abs(s),o=Math.abs(r),u=a+o,u===0){ci.setRelative(n,n,(l+c)/2,i,!0);return}ci.setRelative(n,n,(l*o+c*a)/u,i,!0)},normalSlope:0,setRelative:function(n,e,t,i,s){if(!i||i===this){n.y=(s?e.yo:e.y)+t;return}const r=s?e.xo:e.x,a=s?e.yo:e.y,o=r+t*i.x,l=a+t*i.y;n.y=l+i.normalSlope*(n.x-o)},slope:Number.POSITIVE_INFINITY,touch:function(n){n.yTouched=!0},touched:function(n){return n.yTouched},untouch:function(n){n.yTouched=!1}};Object.freeze(Zn);Object.freeze(ci);function kr(n,e){this.x=n,this.y=e,this.axis=void 0,this.slope=e/n,this.normalSlope=-n/e,Object.freeze(this)}kr.prototype.distance=function(n,e,t,i){return this.x*Zn.distance(n,e,t,i)+this.y*ci.distance(n,e,t,i)};kr.prototype.interpolate=function(n,e,t,i){let s,r,a,o,l,c,u;if(a=i.distance(n,e,!0,!0),o=i.distance(n,t,!0,!0),s=i.distance(e,e,!1,!0),r=i.distance(t,t,!1,!0),l=Math.abs(a),c=Math.abs(o),u=l+c,u===0){this.setRelative(n,n,(s+r)/2,i,!0);return}this.setRelative(n,n,(s*c+r*l)/u,i,!0)};kr.prototype.setRelative=function(n,e,t,i,s){i=i||this;const r=s?e.xo:e.x,a=s?e.yo:e.y,o=r+t*i.x,l=a+t*i.y,c=i.normalSlope,u=this.slope,f=n.x,h=n.y;n.x=(u*f-c*o+l-h)/(u-c),n.y=u*(n.x-f)+h};kr.prototype.touch=function(n){n.xTouched=!0,n.yTouched=!0};function Br(n,e){const t=Math.sqrt(n*n+e*e);return n/=t,e/=t,n===1&&e===0?Zn:n===0&&e===1?ci:new kr(n,e)}function pi(n,e,t,i){this.x=this.xo=Math.round(n*64)/64,this.y=this.yo=Math.round(e*64)/64,this.lastPointOfContour=t,this.onCurve=i,this.prevPointOnContour=void 0,this.nextPointOnContour=void 0,this.xTouched=!1,this.yTouched=!1,Object.preventExtensions(this)}pi.prototype.nextTouched=function(n){let e=this.nextPointOnContour;for(;!n.touched(e)&&e!==this;)e=e.nextPointOnContour;return e};pi.prototype.prevTouched=function(n){let e=this.prevPointOnContour;for(;!n.touched(e)&&e!==this;)e=e.prevPointOnContour;return e};var Dr=Object.freeze(new pi(0,0)),iM={cvCutIn:17/16,deltaBase:9,deltaShift:.125,loop:1,minDis:1,autoFlip:!0};function Ui(n,e){switch(this.env=n,this.stack=[],this.prog=e,n){case"glyf":this.zp0=this.zp1=this.zp2=1,this.rp0=this.rp1=this.rp2=0;case"prep":this.fv=this.pv=this.dpv=Zn,this.round=Rp}}Cp.prototype.exec=function(n,e){if(typeof e!="number")throw new Error("Point size is not a number!");if(this._errorState>2)return;const t=this.font;let i=this._prepState;if(!i||i.ppem!==e){let s=this._fpgmState;if(!s){Ui.prototype=iM,s=this._fpgmState=new Ui("fpgm",t.tables.fpgm),s.funcs=[],s.font=t,s.instructionCount=0,s.callDepth=0;try{ss(s)}catch(a){console.log("Hinting error in FPGM:"+a),this._errorState=3;return}}Ui.prototype=s,i=this._prepState=new Ui("prep",t.tables.prep),i.ppem=e,i.instructionCount=0,i.callDepth=0;const r=t.variation&&t.variation.process.getCvarTransform()||t.tables.cvt;if(r){const a=i.cvt=new Array(r.length),o=e/t.unitsPerEm;for(let l=0;l<r.length;l++)a[l]=r[l]*o}else i.cvt=[];try{ss(i)}catch(a){this._errorState<2&&console.log("Hinting error in PREP:"+a),this._errorState=2}}if(!(this._errorState>1))try{return wp(n,i)}catch(s){this._errorState<1&&(console.log("Hinting error:"+s),console.log("Note: further hinting errors are silenced")),this._errorState=1;return}};wp=function(n,e){const t=e.ppem/e.font.unitsPerEm,i=t;let s=n.components,r,a,o;if(Ui.prototype=e,!s)o=new Ui("glyf",n.instructions),o.instructionCount=0,o.callDepth=0,Ac(n,o,t,i),a=o.gZone;else{const l=e.font;a=[],r=[];for(let c=0;c<s.length;c++){const u=s[c],f=l.glyphs.get(u.glyphIndex);o=new Ui("glyf",f.instructions),o.instructionCount=0,o.callDepth=0,Ac(f,o,t,i);const h=Math.round(u.dx*t),d=Math.round(u.dy*i),p=o.gZone,x=o.contours;for(let g=0;g<p.length;g++){const M=p[g];M.xTouched=M.yTouched=!1,M.xo=M.x=M.x+h,M.yo=M.y=M.y+d}const m=a.length;a.push.apply(a,p);for(let g=0;g<x.length;g++)r.push(x[g]+m)}n.instructions&&!o.inhibitGridFit&&(o=new Ui("glyf",n.instructions),o.gZone=o.z0=o.z1=o.z2=a,o.contours=r,a.push(new pi(0,0),new pi(Math.round(n.advanceWidth*t),0)),ss(o),a.length-=2)}return a};Ac=function(n,e,t,i){const s=n.points||[],r=s.length,a=e.gZone=e.z0=e.z1=e.z2=[],o=e.contours=[];let l;for(let f=0;f<r;f++)l=s[f],a[f]=new pi(l.x*t,l.y*i,l.lastPointOfContour,l.onCurve);let c,u;for(let f=0;f<r;f++)l=a[f],c||(c=l,o.push(f)),l.lastPointOfContour?(l.nextPointOnContour=c,c.prevPointOnContour=l,c=void 0):(u=a[f+1],l.nextPointOnContour=u,u.prevPointOnContour=l);e.inhibitGridFit||(a.push(new pi(0,0),new pi(Math.round(n.advanceWidth*t),0)),ss(e),a.length-=2)};ss=function(n){let e=n.prog;if(!e)return;const t=e.length;let i;for(n.ip=0;n.ip<t;n.ip++){if(++n.instructionCount>Yh)throw new Error("Hinting instructions exceeded maximum of "+Yh);if(i=Ap[e[n.ip]],!i)throw new Error("unknown instruction: 0x"+Number(e[n.ip]).toString(16));i(n)}};function bo(n){const e=n.tZone=new Array(n.gZone.length);for(let t=0;t<e.length;t++)e[t]=new pi(0,0)}function Lp(n,e){const t=n.prog;let i=n.ip,s=1,r;do if(r=t[++i],r===88)s++;else if(r===89)s--;else if(r===64)i+=t[i+1]+1;else if(r===65)i+=2*t[i+1]+1;else if(r>=176&&r<=183)i+=r-176+1;else if(r>=184&&r<=191)i+=(r-184+1)*2;else if(e&&s===1&&r===27)break;while(s>0);n.ip=i}function qh(n,e){e.fv=e.pv=e.dpv=n}function $h(n,e){e.pv=e.dpv=n}function Zh(n,e){e.fv=n}function Kh(n,e){const t=e.stack,i=t.pop(),s=t.pop(),r=e.z2[i],a=e.z1[s];let o,l;n?(o=r.y-a.y,l=a.x-r.x):(o=a.x-r.x,l=a.y-r.y),e.pv=e.dpv=Br(o,l)}function Jh(n,e){const t=e.stack,i=t.pop(),s=t.pop(),r=e.z2[i],a=e.z1[s];let o,l;n?(o=r.y-a.y,l=a.x-r.x):(o=a.x-r.x,l=a.y-r.y),e.fv=Br(o,l)}function sM(n){const e=n.stack,t=e.pop(),i=e.pop();n.pv=n.dpv=Br(i,t)}function rM(n){const e=n.stack,t=e.pop(),i=e.pop();n.fv=Br(i,t)}function aM(n){const e=n.stack,t=n.pv;e.push(t.x*16384),e.push(t.y*16384)}function oM(n){const e=n.stack,t=n.fv;e.push(t.x*16384),e.push(t.y*16384)}function lM(n){n.fv=n.pv}function cM(n){const e=n.stack,t=e.pop(),i=e.pop(),s=e.pop(),r=e.pop(),a=e.pop(),o=n.z0,l=n.z1,c=o[t],u=o[i],f=l[s],h=l[r],d=n.z2[a],p=c.x,x=c.y,m=u.x,g=u.y,M=f.x,E=f.y,_=h.x,T=h.y,b=(p-m)*(E-T)-(x-g)*(M-_),S=p*g-x*m,v=M*T-E*_;d.x=(S*(M-_)-v*(p-m))/b,d.y=(S*(E-T)-v*(x-g))/b}function uM(n){n.rp0=n.stack.pop()}function hM(n){n.rp1=n.stack.pop()}function fM(n){n.rp2=n.stack.pop()}function dM(n){const e=n.stack.pop();switch(n.zp0=e,e){case 0:n.tZone||bo(n),n.z0=n.tZone;break;case 1:n.z0=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function pM(n){const e=n.stack.pop();switch(n.zp1=e,e){case 0:n.tZone||bo(n),n.z1=n.tZone;break;case 1:n.z1=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function mM(n){const e=n.stack.pop();switch(n.zp2=e,e){case 0:n.tZone||bo(n),n.z2=n.tZone;break;case 1:n.z2=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function gM(n){const e=n.stack.pop();switch(n.zp0=n.zp1=n.zp2=e,e){case 0:n.tZone||bo(n),n.z0=n.z1=n.z2=n.tZone;break;case 1:n.z0=n.z1=n.z2=n.gZone;break;default:throw new Error("Invalid zone pointer")}}function xM(n){n.loop=n.stack.pop(),n.loop>fo&&(n.loop=fo)}function vM(n){n.round=Rp}function yM(n){n.round=eM}function _M(n){const e=n.stack.pop();n.minDis=e/64}function bM(n){Lp(n,!1)}function SM(n){const e=n.stack.pop();n.ip+=e-1}function MM(n){const e=n.stack.pop();n.cvCutIn=e/64}function EM(n){const e=n.stack;e.push(e[e.length-1])}function fl(n){n.stack.pop()}function TM(n){n.stack.length=0}function AM(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(t),e.push(i)}function wM(n){const e=n.stack;e.push(e.length)}function CM(n){const e=n.stack,t=e.pop();let i=e.pop();if(i>fo&&(i=fo),++n.callDepth>ho)throw new Error("Hinting call depth exceeded maximum of "+ho);const s=n.ip,r=n.prog;n.prog=n.funcs[t];for(let a=0;a<i;a++)ss(n);n.ip=s,n.prog=r,n.callDepth--}function RM(n){const e=n.stack.pop();if(++n.callDepth>ho)throw new Error("Hinting call depth exceeded maximum of "+ho);const t=n.ip,i=n.prog;n.prog=n.funcs[e],ss(n),n.ip=t,n.prog=i,n.callDepth--}function PM(n){const e=n.stack,t=e.pop();e.push(e[e.length-t])}function LM(n){const e=n.stack,t=e.pop();e.push(e.splice(e.length-t,1)[0])}function DM(n){if(n.env!=="fpgm")throw new Error("FDEF not allowed here");const e=n.stack,t=n.prog;let i=n.ip;const s=e.pop(),r=i;for(;t[++i]!==45;);n.ip=i,n.funcs[s]=t.slice(r+1,i)}function jh(n,e){const t=e.stack.pop(),i=e.z0[t],s=e.fv,r=e.pv;let a=r.distance(i,Dr);n&&(a=e.round(a)),s.setRelative(i,Dr,a,r),s.touch(i),e.rp0=e.rp1=t}function Qh(n,e){const t=e.z2,i=t.length-2;let s,r,a;for(let o=0;o<i;o++)s=t[o],!n.touched(s)&&(r=s.prevTouched(n),r!==s&&(a=s.nextTouched(n),r===a&&n.setRelative(s,s,n.distance(r,r,!1,!0),n,!0),n.interpolate(s,r,a,n)))}function ef(n,e){const t=e.stack,i=n?e.rp1:e.rp2,s=(n?e.z0:e.z1)[i],r=e.fv,a=e.pv;let o=e.loop;const l=e.z2;for(;o--;){const c=t.pop(),u=l[c],f=a.distance(s,s,!1,!0);r.setRelative(u,u,f,a),r.touch(u)}e.loop=1}function tf(n,e){const t=e.stack,i=n?e.rp1:e.rp2,s=(n?e.z0:e.z1)[i],r=e.fv,a=e.pv,o=t.pop(),l=e.z2[e.contours[o]];let c=l;const u=a.distance(s,s,!1,!0);do c!==s&&r.setRelative(c,c,u,a),c=c.nextPointOnContour;while(c!==l)}function nf(n,e){const t=e.stack,i=n?e.rp1:e.rp2,s=(n?e.z0:e.z1)[i],r=e.fv,a=e.pv,o=t.pop();let l;switch(o){case 0:l=e.tZone;break;case 1:l=e.gZone;break;default:throw new Error("Invalid zone")}let c;const u=a.distance(s,s,!1,!0),f=l.length-2;for(let h=0;h<f;h++)c=l[h],r.setRelative(c,c,u,a)}function IM(n){const e=n.stack;let t=n.loop;const i=n.fv,s=e.pop()/64,r=n.z2;for(;t--;){const a=e.pop(),o=r[a];i.setRelative(o,o,s),i.touch(o)}n.loop=1}function UM(n){const e=n.stack,t=n.rp1,i=n.rp2;let s=n.loop;const r=n.z0[t],a=n.z1[i],o=n.fv,l=n.dpv,c=n.z2;for(;s--;){const u=e.pop(),f=c[u];o.interpolate(f,r,a,l),o.touch(f)}n.loop=1}function sf(n,e){const t=e.stack,i=t.pop()/64,s=t.pop(),r=e.z1[s],a=e.z0[e.rp0],o=e.fv,l=e.pv;o.setRelative(r,a,i,l),o.touch(r),e.rp1=e.rp0,e.rp2=s,n&&(e.rp0=s)}function OM(n){const e=n.stack,t=n.rp0,i=n.z0[t];let s=n.loop;const r=n.fv,a=n.pv,o=n.z1;for(;s--;){const l=e.pop(),c=o[l];r.setRelative(c,i,0,a),r.touch(c)}n.loop=1}function FM(n){n.round=QS}function rf(n,e){const t=e.stack,i=t.pop(),s=t.pop(),r=e.z0[s],a=e.fv,o=e.pv;let l=e.cvt[i],c=o.distance(r,Dr);n&&(Math.abs(c-l)<e.cvCutIn&&(c=l),c=e.round(c)),a.setRelative(r,Dr,c,o),e.zp0===0&&(r.xo=r.x,r.yo=r.y),a.touch(r),e.rp0=e.rp1=s}function NM(n){const e=n.prog;let t=n.ip;const i=n.stack,s=e[++t];for(let r=0;r<s;r++)i.push(e[++t]);n.ip=t}function kM(n){let e=n.ip;const t=n.prog,i=n.stack,s=t[++e];for(let r=0;r<s;r++){let a=t[++e]<<8|t[++e];a&32768&&(a=-((a^65535)+1)),i.push(a)}n.ip=e}function BM(n){const e=n.stack;let t=n.store;t||(t=n.store=[]);const i=e.pop(),s=e.pop();t[s]=i}function HM(n){const e=n.stack,t=n.store,i=e.pop(),s=t&&t[i]||0;e.push(s)}function zM(n){const e=n.stack,t=e.pop(),i=e.pop();n.cvt[i]=t/64}function GM(n){const e=n.stack,t=e.pop();e.push(n.cvt[t]*64)}function af(n,e){const t=e.stack,i=t.pop(),s=e.z2[i];t.push(e.dpv.distance(s,Dr,n,!1)*64)}function of(n,e){const t=e.stack,i=t.pop(),s=t.pop(),r=e.z1[i],a=e.z0[s],o=e.dpv.distance(a,r,n,n);e.stack.push(Math.round(o*64))}function VM(n){n.stack.push(n.ppem)}function WM(n){n.autoFlip=!0}function XM(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(i<t?1:0)}function YM(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(i<=t?1:0)}function qM(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(i>t?1:0)}function $M(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(i>=t?1:0)}function ZM(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(t===i?1:0)}function KM(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(t!==i?1:0)}function JM(n){const e=n.stack,t=e.pop();e.push(Math.trunc(t)&1?1:0)}function jM(n){const e=n.stack,t=e.pop();e.push(Math.trunc(t)&1?0:1)}function QM(n){n.stack.pop()||Lp(n,!0)}function eE(n){}function tE(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(t&&i?1:0)}function nE(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(t||i?1:0)}function iE(n){const e=n.stack,t=e.pop();e.push(t?0:1)}function dl(n,e){const t=e.stack,i=t.pop(),s=e.fv,r=e.pv,a=e.ppem,o=e.deltaBase+(n-1)*16,l=e.deltaShift,c=e.z0;for(let u=0;u<i;u++){const f=t.pop(),h=t.pop();if(o+((h&240)>>4)!==a)continue;let p=(h&15)-8;p>=0&&p++;const x=c[f];s.setRelative(x,x,p*l,r)}}function sE(n){const t=n.stack.pop();n.deltaBase=t}function rE(n){const t=n.stack.pop();n.deltaShift=Math.pow(.5,t)}function aE(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(i+t)}function oE(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(i-t)}function lE(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(i*64/t)}function cE(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(i*t/64)}function uE(n){const e=n.stack,t=e.pop();e.push(Math.abs(t))}function hE(n){const e=n.stack;let t=e.pop();e.push(-t)}function fE(n){const e=n.stack,t=e.pop();e.push(Math.floor(t/64)*64)}function dE(n){const e=n.stack,t=e.pop();e.push(Math.ceil(t/64)*64)}function wa(n,e){const t=e.stack,i=t.pop();t.push(e.round(i/64)*64)}function pE(n){const e=n.stack,t=e.pop(),i=e.pop();n.cvt[i]=t*n.ppem/n.font.unitsPerEm}function pl(n,e){const t=e.stack,i=t.pop(),s=e.ppem,r=e.deltaBase+(n-1)*16,a=e.deltaShift;for(let o=0;o<i;o++){const l=t.pop(),c=t.pop();if(r+((c&240)>>4)!==s)continue;let f=(c&15)-8;f>=0&&f++;const h=f*a;e.cvt[l]+=h}}function mE(n){let e=n.stack.pop();n.round=Pp;let t;switch(e&192){case 0:t=.5;break;case 64:t=1;break;case 128:t=2;break;default:throw new Error("invalid SROUND value")}switch(n.srPeriod=t,e&48){case 0:n.srPhase=0;break;case 16:n.srPhase=.25*t;break;case 32:n.srPhase=.5*t;break;case 48:n.srPhase=.75*t;break;default:throw new Error("invalid SROUND value")}e&=15,e===0?n.srThreshold=0:n.srThreshold=(e/8-.5)*t}function gE(n){let e=n.stack.pop();n.round=Pp;let t;switch(e&192){case 0:t=Math.sqrt(2)/2;break;case 64:t=Math.sqrt(2);break;case 128:t=2*Math.sqrt(2);break;default:throw new Error("invalid S45ROUND value")}switch(n.srPeriod=t,e&48){case 0:n.srPhase=0;break;case 16:n.srPhase=.25*t;break;case 32:n.srPhase=.5*t;break;case 48:n.srPhase=.75*t;break;default:throw new Error("invalid S45ROUND value")}e&=15,e===0?n.srThreshold=0:n.srThreshold=(e/8-.5)*t}function xE(n){n.round=jS}function vE(n){n.round=tM}function yE(n){n.round=nM}function _E(n){n.stack.pop()}function lf(n,e){const t=e.stack,i=t.pop(),s=t.pop(),r=e.z2[i],a=e.z1[s];let o,l;n?(o=r.y-a.y,l=a.x-r.x):(o=a.x-r.x,l=a.y-r.y),e.dpv=Br(o,l)}function bE(n){const e=n.stack,t=e.pop();let i=0;t&1&&(i=35),t&32&&(i|=4096),e.push(i)}function SE(n){const e=n.stack,t=e.pop(),i=e.pop(),s=e.pop();e.push(i),e.push(t),e.push(s)}function ME(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(Math.max(i,t))}function EE(n){const e=n.stack,t=e.pop(),i=e.pop();e.push(Math.min(i,t))}function TE(n){n.stack.pop()}function AE(n){const e=n.stack.pop();let t=n.stack.pop();switch(e){case 1:n.inhibitGridFit=!!t;return;case 2:n.ignoreCvt=!!t;return;default:throw new Error("invalid INSTCTRL[] selector")}}function wi(n,e){const t=e.stack,i=e.prog;let s=e.ip;for(let r=0;r<n;r++)t.push(i[++s]);e.ip=s}function Ci(n,e){let t=e.ip;const i=e.prog,s=e.stack;for(let r=0;r<n;r++){let a=i[++t]<<8|i[++t];a&32768&&(a=-((a^65535)+1)),s.push(a)}e.ip=t}function Ue(n,e,t,i,s,r){const a=r.stack,o=n&&a.pop(),l=a.pop(),c=r.rp0,u=r.z0[c],f=r.z1[l],h=r.minDis,d=r.fv,p=r.dpv;let x,m,g;x=p.distance(f,u,!0,!0),m=x>=0?1:-1,x=Math.abs(x),n&&(g=r.cvt[o],i&&Math.abs(x-g)<r.cvCutIn&&(x=g)),t&&x<h&&(x=h),i&&(x=r.round(x)),d.setRelative(f,u,m*x,p),d.touch(f),r.rp1=r.rp0,r.rp2=l,e&&(r.rp0=l)}Ap=[qh.bind(void 0,ci),qh.bind(void 0,Zn),$h.bind(void 0,ci),$h.bind(void 0,Zn),Zh.bind(void 0,ci),Zh.bind(void 0,Zn),Kh.bind(void 0,0),Kh.bind(void 0,1),Jh.bind(void 0,0),Jh.bind(void 0,1),sM,rM,aM,oM,lM,cM,uM,hM,fM,dM,pM,mM,gM,xM,vM,yM,_M,bM,SM,MM,void 0,void 0,EM,fl,TM,AM,wM,PM,LM,void 0,void 0,void 0,CM,RM,DM,void 0,jh.bind(void 0,0),jh.bind(void 0,1),Qh.bind(void 0,ci),Qh.bind(void 0,Zn),ef.bind(void 0,0),ef.bind(void 0,1),tf.bind(void 0,0),tf.bind(void 0,1),nf.bind(void 0,0),nf.bind(void 0,1),IM,UM,sf.bind(void 0,0),sf.bind(void 0,1),OM,FM,rf.bind(void 0,0),rf.bind(void 0,1),NM,kM,BM,HM,zM,GM,af.bind(void 0,0),af.bind(void 0,1),void 0,of.bind(void 0,0),of.bind(void 0,1),VM,void 0,WM,void 0,void 0,XM,YM,qM,$M,ZM,KM,JM,jM,QM,eE,tE,nE,iE,dl.bind(void 0,1),sE,rE,aE,oE,lE,cE,uE,hE,fE,dE,wa.bind(void 0,0),wa.bind(void 0,1),wa.bind(void 0,2),wa.bind(void 0,3),void 0,void 0,void 0,void 0,pE,dl.bind(void 0,2),dl.bind(void 0,3),pl.bind(void 0,1),pl.bind(void 0,2),pl.bind(void 0,3),mE,gE,void 0,void 0,xE,void 0,vE,yE,fl,fl,void 0,void 0,void 0,void 0,void 0,_E,lf.bind(void 0,0),lf.bind(void 0,1),bE,void 0,SE,ME,EE,TE,AE,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,wi.bind(void 0,1),wi.bind(void 0,2),wi.bind(void 0,3),wi.bind(void 0,4),wi.bind(void 0,5),wi.bind(void 0,6),wi.bind(void 0,7),wi.bind(void 0,8),Ci.bind(void 0,1),Ci.bind(void 0,2),Ci.bind(void 0,3),Ci.bind(void 0,4),Ci.bind(void 0,5),Ci.bind(void 0,6),Ci.bind(void 0,7),Ci.bind(void 0,8),Ue.bind(void 0,0,0,0,0,0),Ue.bind(void 0,0,0,0,0,1),Ue.bind(void 0,0,0,0,0,2),Ue.bind(void 0,0,0,0,0,3),Ue.bind(void 0,0,0,0,1,0),Ue.bind(void 0,0,0,0,1,1),Ue.bind(void 0,0,0,0,1,2),Ue.bind(void 0,0,0,0,1,3),Ue.bind(void 0,0,0,1,0,0),Ue.bind(void 0,0,0,1,0,1),Ue.bind(void 0,0,0,1,0,2),Ue.bind(void 0,0,0,1,0,3),Ue.bind(void 0,0,0,1,1,0),Ue.bind(void 0,0,0,1,1,1),Ue.bind(void 0,0,0,1,1,2),Ue.bind(void 0,0,0,1,1,3),Ue.bind(void 0,0,1,0,0,0),Ue.bind(void 0,0,1,0,0,1),Ue.bind(void 0,0,1,0,0,2),Ue.bind(void 0,0,1,0,0,3),Ue.bind(void 0,0,1,0,1,0),Ue.bind(void 0,0,1,0,1,1),Ue.bind(void 0,0,1,0,1,2),Ue.bind(void 0,0,1,0,1,3),Ue.bind(void 0,0,1,1,0,0),Ue.bind(void 0,0,1,1,0,1),Ue.bind(void 0,0,1,1,0,2),Ue.bind(void 0,0,1,1,0,3),Ue.bind(void 0,0,1,1,1,0),Ue.bind(void 0,0,1,1,1,1),Ue.bind(void 0,0,1,1,1,2),Ue.bind(void 0,0,1,1,1,3),Ue.bind(void 0,1,0,0,0,0),Ue.bind(void 0,1,0,0,0,1),Ue.bind(void 0,1,0,0,0,2),Ue.bind(void 0,1,0,0,0,3),Ue.bind(void 0,1,0,0,1,0),Ue.bind(void 0,1,0,0,1,1),Ue.bind(void 0,1,0,0,1,2),Ue.bind(void 0,1,0,0,1,3),Ue.bind(void 0,1,0,1,0,0),Ue.bind(void 0,1,0,1,0,1),Ue.bind(void 0,1,0,1,0,2),Ue.bind(void 0,1,0,1,0,3),Ue.bind(void 0,1,0,1,1,0),Ue.bind(void 0,1,0,1,1,1),Ue.bind(void 0,1,0,1,1,2),Ue.bind(void 0,1,0,1,1,3),Ue.bind(void 0,1,1,0,0,0),Ue.bind(void 0,1,1,0,0,1),Ue.bind(void 0,1,1,0,0,2),Ue.bind(void 0,1,1,0,0,3),Ue.bind(void 0,1,1,0,1,0),Ue.bind(void 0,1,1,0,1,1),Ue.bind(void 0,1,1,0,1,2),Ue.bind(void 0,1,1,0,1,3),Ue.bind(void 0,1,1,1,0,0),Ue.bind(void 0,1,1,1,0,1),Ue.bind(void 0,1,1,1,0,2),Ue.bind(void 0,1,1,1,0,3),Ue.bind(void 0,1,1,1,1,0),Ue.bind(void 0,1,1,1,1,1),Ue.bind(void 0,1,1,1,1,2),Ue.bind(void 0,1,1,1,1,3)];var wE=Cp;function er(n){this.char=n,this.state={},this.activeState=null}function su(n,e,t){this.contextName=t,this.startIndex=n,this.endOffset=e}function CE(n,e,t){this.contextName=n,this.openRange=null,this.ranges=[],this.checkStart=e,this.checkEnd=t}function rn(n,e){this.context=n,this.index=e,this.length=n.length,this.current=n[e],this.backtrack=n.slice(0,e),this.lookahead=n.slice(e+1)}function So(n){this.eventId=n,this.subscribers=[]}function RE(n){const e=["start","end","next","newToken","contextStart","contextEnd","insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD","updateContextsRanges"];for(let i=0;i<e.length;i++){const s=e[i];Object.defineProperty(this.events,s,{value:new So(s)})}if(n)for(let i=0;i<e.length;i++){const s=e[i],r=n[s];typeof r=="function"&&this.events[s].subscribe(r)}const t=["insertToken","removeToken","removeRange","replaceToken","replaceRange","composeRUD"];for(let i=0;i<t.length;i++){const s=t[i];this.events[s].subscribe(this.updateContextsRanges)}}function Rt(n){this.tokens=[],this.registeredContexts={},this.contextCheckers=[],this.events={},this.registeredModifiers=[],RE.call(this,n)}er.prototype.setState=function(n,e){return this.state[n]=e,this.activeState={key:n,value:this.state[n]},this.activeState};er.prototype.getState=function(n){return this.state[n]||null};Rt.prototype.inboundIndex=function(n){return n>=0&&n<this.tokens.length};Rt.prototype.composeRUD=function(n){const t=n.map(s=>this[s[0]].apply(this,s.slice(1).concat(!0))),i=s=>typeof s=="object"&&Object.prototype.hasOwnProperty.call(s,"FAIL");if(t.every(i))return{FAIL:"composeRUD: one or more operations hasn't completed successfully",report:t.filter(i)};this.dispatch("composeRUD",[t.filter(s=>!i(s))])};Rt.prototype.replaceRange=function(n,e,t,i){e=e!==null?e:this.tokens.length;const s=t.every(r=>r instanceof er);if(!isNaN(n)&&this.inboundIndex(n)&&s){const r=this.tokens.splice.apply(this.tokens,[n,e].concat(t));return i||this.dispatch("replaceToken",[n,e,t]),[r,t]}else return{FAIL:"replaceRange: invalid tokens or startIndex."}};Rt.prototype.replaceToken=function(n,e,t){if(!isNaN(n)&&this.inboundIndex(n)&&e instanceof er){const i=this.tokens.splice(n,1,e);return t||this.dispatch("replaceToken",[n,e]),[i[0],e]}else return{FAIL:"replaceToken: invalid token or index."}};Rt.prototype.removeRange=function(n,e,t){e=isNaN(e)?this.tokens.length:e;const i=this.tokens.splice(n,e);return t||this.dispatch("removeRange",[i,n,e]),i};Rt.prototype.removeToken=function(n,e){if(!isNaN(n)&&this.inboundIndex(n)){const t=this.tokens.splice(n,1);return e||this.dispatch("removeToken",[t,n]),t}else return{FAIL:"removeToken: invalid token index."}};Rt.prototype.insertToken=function(n,e,t){return n.every(s=>s instanceof er)?(this.tokens.splice.apply(this.tokens,[e,0].concat(n)),t||this.dispatch("insertToken",[n,e]),n):{FAIL:"insertToken: invalid token(s)."}};Rt.prototype.registerModifier=function(n,e,t){this.events.newToken.subscribe(function(i,s){const r=[i,s],a=e===null||e.apply(this,r)===!0,o=[i,s];if(a){let l=t.apply(this,o);i.setState(n,l)}}),this.registeredModifiers.push(n)};So.prototype.subscribe=function(n){return typeof n=="function"?this.subscribers.push(n)-1:{FAIL:`invalid '${this.eventId}' event handler`}};So.prototype.unsubscribe=function(n){this.subscribers.splice(n,1)};rn.prototype.setCurrentIndex=function(n){this.index=n,this.current=this.context[n],this.backtrack=this.context.slice(0,n),this.lookahead=this.context.slice(n+1)};rn.prototype.get=function(n){switch(!0){case n===0:return this.current;case(n<0&&Math.abs(n)<=this.backtrack.length):return this.backtrack.slice(n)[0];case(n>0&&n<=this.lookahead.length):return this.lookahead[n-1];default:return null}};Rt.prototype.rangeToText=function(n){if(n instanceof su)return this.getRangeTokens(n).map(e=>e.char).join("")};Rt.prototype.getText=function(){return this.tokens.map(n=>n.char).join("")};Rt.prototype.getContext=function(n){let e=this.registeredContexts[n];return e||null};Rt.prototype.on=function(n,e){const t=this.events[n];return t?t.subscribe(e):null};Rt.prototype.dispatch=function(n,e){const t=this.events[n];if(t instanceof So)for(let i=0;i<t.subscribers.length;i++)t.subscribers[i].apply(this,e||[])};Rt.prototype.registerContextChecker=function(n,e,t){if(this.getContext(n))return{FAIL:`context name '${n}' is already registered.`};if(typeof e!="function")return{FAIL:"missing context start check."};if(typeof t!="function")return{FAIL:"missing context end check."};const i=new CE(n,e,t);return this.registeredContexts[n]=i,this.contextCheckers.push(i),i};Rt.prototype.getRangeTokens=function(n){const e=n.startIndex+n.endOffset;return[].concat(this.tokens.slice(n.startIndex,e))};Rt.prototype.getContextRanges=function(n){const e=this.getContext(n);return e?e.ranges:{FAIL:`context checker '${n}' is not registered.`}};Rt.prototype.resetContextsRanges=function(){const n=this.registeredContexts;for(const e in n)if(Object.prototype.hasOwnProperty.call(n,e)){const t=n[e];t.ranges=[]}};Rt.prototype.updateContextsRanges=function(){this.resetContextsRanges();const n=this.tokens.map(e=>e.char);for(let e=0;e<n.length;e++){const t=new rn(n,e);this.runContextCheck(t)}this.dispatch("updateContextsRanges",[this.registeredContexts])};Rt.prototype.setEndOffset=function(n,e){const t=this.getContext(e).openRange.startIndex;let i=new su(t,n,e);const s=this.getContext(e).ranges;return i.rangeId=`${e}.${s.length}`,s.push(i),this.getContext(e).openRange=null,i};Rt.prototype.runContextCheck=function(n){const e=n.index;for(let t=0;t<this.contextCheckers.length;t++){const i=this.contextCheckers[t];let s=i.contextName,r=this.getContext(s).openRange;if(!r&&i.checkStart(n)&&(r=new su(e,null,s),this.getContext(s).openRange=r,this.dispatch("contextStart",[s,e])),r&&i.checkEnd(n)){const a=e-r.startIndex+1,o=this.setEndOffset(a,s);this.dispatch("contextEnd",[s,o])}}};Rt.prototype.tokenize=function(n){this.tokens=[],this.resetContextsRanges();let e=Array.from(n);this.dispatch("start");for(let t=0;t<e.length;t++){const i=e[t],s=new rn(e,t);this.dispatch("next",[s]),this.runContextCheck(s);let r=new er(i);this.tokens.push(r),this.dispatch("newToken",[r,s])}return this.dispatch("end",[this.tokens]),this.tokens};var PE=Rt;function Fi(n){return/[\u0600-\u065F\u066A-\u06D2\u06FA-\u06FF]/.test(n)}function Dp(n){return/[\u0630\u0690\u0621\u0631\u0661\u0671\u0622\u0632\u0672\u0692\u06C2\u0623\u0673\u0693\u06C3\u0624\u0694\u06C4\u0625\u0675\u0695\u06C5\u06E5\u0676\u0696\u06C6\u0627\u0677\u0697\u06C7\u0648\u0688\u0698\u06C8\u0689\u0699\u06C9\u068A\u06CA\u066B\u068B\u06CB\u068C\u068D\u06CD\u06FD\u068E\u06EE\u06FE\u062F\u068F\u06CF\u06EF]/.test(n)}function Bi(n){return/[\u0600-\u0605\u060C-\u060E\u0610-\u061B\u061E\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED]/.test(n)}function Ga(n){return/[\u0E00-\u0E7F]/.test(n)}function Va(n){return/[A-z]/.test(n)}function LE(n){return/\s/.test(n)}function xn(n){this.font=n,this.features={}}function Pi(n){this.id=n.id,this.tag=n.tag,this.substitution=n.substitution}function Hi(n,e){if(!n)return-1;switch(e.format){case 1:return e.glyphs.indexOf(n);case 2:{let t=e.ranges;for(let i=0;i<t.length;i++){const s=t[i];if(n>=s.start&&n<=s.end){let r=n-s.start;return s.index+r}}break}default:return-1}return-1}function DE(n,e){return Hi(n,e.coverage)===-1?null:n+e.deltaGlyphId}function IE(n,e){let t=Hi(n,e.coverage);return t===-1?null:e.substitute[t]}function ml(n,e){let t=[];for(let i=0;i<n.length;i++){const s=n[i];let r=e.current;r=Array.isArray(r)?r[0]:r;const a=Hi(r,s);a!==-1&&t.push(a)}return t.length!==n.length?-1:t}function UE(n,e){const t=e.inputCoverage.length+e.lookaheadCoverage.length+e.backtrackCoverage.length;if(n.context.length<t)return[];let i=ml(e.inputCoverage,n);if(i===-1)return[];const s=e.inputCoverage.length-1;if(n.lookahead.length<e.lookaheadCoverage.length)return[];let r=n.lookahead.slice(s);for(;r.length&&Bi(r[0].char);)r.shift();const a=new rn(r,0);let o=ml(e.lookaheadCoverage,a),l=[].concat(n.backtrack);for(l.reverse();l.length&&Bi(l[0].char);)l.shift();if(l.length<e.backtrackCoverage.length)return[];const c=new rn(l,0);let u=ml(e.backtrackCoverage,c);const f=i.length===e.inputCoverage.length&&o.length===e.lookaheadCoverage.length&&u.length===e.backtrackCoverage.length;let h=[];if(f)for(let d=0;d<e.lookupRecords.length;d++){const p=e.lookupRecords[d],x=p.lookupListIndex,m=this.getLookupByIndex(x);for(let g=0;g<m.subtables.length;g++){let M=m.subtables[g],E,_=this.getSubstitutionType(m,M);if(_==="71"?(_=this.getSubstitutionType(M,M.extension),E=this.getLookupMethod(M,M.extension),M=M.extension):E=this.getLookupMethod(m,M),_==="12"){const T=n.get(p.sequenceIndex),b=E(T);b&&h.push(b)}else if(_==="21"){const T=n.get(p.sequenceIndex),b=E(T);b&&h.push(b)}else throw new Error(`Substitution type ${_} is not supported in chaining substitution`)}}return h}function OE(n,e){let t=n.current,i=Hi(t,e.coverage);if(i===-1)return null;let s,r=e.ligatureSets[i];for(let a=0;a<r.length;a++){s=r[a];for(let o=0;o<s.components.length;o++){const l=n.lookahead[o],c=s.components[o];if(l!==c)break;if(o===s.components.length-1)return s}}return null}function FE(n,e){let t=n.current;if(Hi(t,e.coverage)===-1)return null;for(const s of e.ruleSets)for(const r of s){let a=!0;for(let o=0;o<r.input.length;o++)if(n.lookahead[o]!==r.input[o]){a=!1;break}if(a){let o=[];o.push(t);for(let c=0;c<r.input.length;c++)o.push(r.input[c]);const l=(c,u)=>{const{lookupListIndex:f,sequenceIndex:h}=u,{subtables:d}=this.getLookupByIndex(f);for(const p of d)Hi(c[h],p.coverage)!==-1&&(c[h]=p.deltaGlyphId)};for(let c=0;c<r.lookupRecords.length;c++){const u=r.lookupRecords[c];l(o,u)}return o}}return null}function NE(n,e){if(n.context.length<e.coverages.length)return[];for(let i=0;i<e.coverages.length;i++){let s=n.get(i);if(s=Array.isArray(s)?s[0]:s,Hi(s,e.coverages[i])===-1)return[]}let t=[];for(let i=0;i<e.lookupRecords.length;i++){const s=e.lookupRecords[i],r=s.lookupListIndex,a=this.getLookupByIndex(r);for(let o=0;o<a.subtables.length;o++){let l=a.subtables[o],c,u=this.getSubstitutionType(a,l);if(u==="71"?(u=this.getSubstitutionType(l,l.extension),c=this.getLookupMethod(l,l.extension),l=l.extension):c=this.getLookupMethod(a,l),u==="12"){const f=n.get(s.sequenceIndex),h=c(f);h&&t.push(h)}else if(u==="21"){const f=n.get(s.sequenceIndex),h=c(f);h&&t.push(h)}}}return t}function kE(n,e){let t=Hi(n,e.coverage);return t===-1?null:e.sequences[t]}xn.prototype.getDefaultScriptFeaturesIndexes=function(){const n=this.font.tables.gsub.scripts;for(let e=0;e<n.length;e++){const t=n[e];if(t.tag==="DFLT")return t.script.defaultLangSys.featureIndexes}return[]};xn.prototype.getScriptFeaturesIndexes=function(n){if(!this.font.tables.gsub)return[];if(!n)return this.getDefaultScriptFeaturesIndexes();const t=this.font.tables.gsub.scripts;for(let i=0;i<t.length;i++){const s=t[i];if(s.tag===n&&s.script.defaultLangSys)return s.script.defaultLangSys.featureIndexes;{let r=s.langSysRecords;if(r)for(let a=0;a<r.length;a++){const o=r[a];if(o.tag===n)return o.langSys.featureIndexes}}}return this.getDefaultScriptFeaturesIndexes()};xn.prototype.mapTagsToFeatures=function(n,e){let t={};for(let i=0;i<n.length;i++){const s=n[i].tag,r=n[i].feature;t[s]=r}this.features[e].tags=t};xn.prototype.getScriptFeatures=function(n){let e=this.features[n];if(Object.prototype.hasOwnProperty.call(this.features,n))return e;const t=this.getScriptFeaturesIndexes(n);if(!t)return null;const i=this.font.tables.gsub;return e=t.map(s=>i.features[s]),this.features[n]=e,this.mapTagsToFeatures(e,n),e};xn.prototype.getSubstitutionType=function(n,e){const t=n.lookupType.toString(),i=e.substFormat.toString();return t+i};xn.prototype.getLookupMethod=function(n,e){let t=this.getSubstitutionType(n,e);switch(t){case"11":return i=>DE.apply(this,[i,e]);case"12":return i=>IE.apply(this,[i,e]);case"63":return i=>UE.apply(this,[i,e]);case"41":return i=>OE.apply(this,[i,e]);case"21":return i=>kE.apply(this,[i,e]);case"51":return i=>FE.apply(this,[i,e]);case"53":return i=>NE.apply(this,[i,e]);default:throw new Error(`substitutionType : ${t} lookupType: ${n.lookupType} - substFormat: ${e.substFormat} is not yet supported`)}};xn.prototype.lookupFeature=function(n){let e=n.contextParams,t=e.index;const i=this.getFeature({tag:n.tag,script:n.script});if(!i)return new Error(`font '${(this.font.names.unicode||this.font.names.windows||this.font.names.macintosh).fullName.en}' doesn't support feature '${n.tag}' for script '${n.script}'.`);const s=this.getFeatureLookups(i),r=[].concat(e.context);for(let a=0;a<s.length;a++){const o=s[a],l=this.getLookupSubtables(o);for(let c=0;c<l.length;c++){let u=l[c],f=this.getSubstitutionType(o,u),h;f==="71"?(f=this.getSubstitutionType(u,u.extension),h=this.getLookupMethod(u,u.extension),u=u.extension):h=this.getLookupMethod(o,u);let d;switch(f){case"11":d=h(e.current),d&&r.splice(t,1,new Pi({id:11,tag:n.tag,substitution:d}));break;case"12":d=h(e.current),d&&r.splice(t,1,new Pi({id:12,tag:n.tag,substitution:d}));break;case"63":d=h(e),Array.isArray(d)&&d.length&&r.splice(t,1,new Pi({id:63,tag:n.tag,substitution:d}));break;case"41":d=h(e),d&&r.splice(t,1,new Pi({id:41,tag:n.tag,substitution:d}));break;case"21":d=h(e.current),d&&r.splice(t,1,new Pi({id:21,tag:n.tag,substitution:d}));break;case"51":case"53":d=h(e),Array.isArray(d)&&d.length&&r.splice(t,1,new Pi({id:parseInt(f),tag:n.tag,substitution:d}));break}e=new rn(r,t),!(Array.isArray(d)&&!d.length)&&(d=null)}}return r.length?r:null};xn.prototype.supports=function(n){if(!n.script)return!1;this.getScriptFeatures(n.script);const e=Object.prototype.hasOwnProperty.call(this.features,n.script);if(!n.tag)return e;const t=this.features[n.script].some(i=>i.tag===n.tag);return e&&t};xn.prototype.getLookupSubtables=function(n){return n.subtables||null};xn.prototype.getLookupByIndex=function(n){return this.font.tables.gsub.lookups[n]||null};xn.prototype.getFeatureLookups=function(n){return n.lookupListIndexes.map(this.getLookupByIndex.bind(this))};xn.prototype.getFeature=function(e){if(!this.font)return{FAIL:"No font was found"};Object.prototype.hasOwnProperty.call(this.features,e.script)||this.getScriptFeatures(e.script);const t=this.features[e.script];return t?t.tags[e.tag]?this.features[e.script].tags[e.tag]:null:{FAIL:`No feature for script ${e.script}`}};var BE=xn;function HE(n){const e=n.current,t=n.get(-1);return t===null&&Fi(e)||!Fi(t)&&Fi(e)}function zE(n){const e=n.get(1);return e===null||!Fi(e)}var GE={startCheck:HE,endCheck:zE};function VE(n){const e=n.current,t=n.get(-1);return(Fi(e)||Bi(e))&&!Fi(t)}function WE(n){const e=n.get(1);switch(!0){case e===null:return!0;case(!Fi(e)&&!Bi(e)):{const t=LE(e);if(!t)return!0;if(t){let i=!1;if(i=n.lookahead.some(s=>Fi(s)||Bi(s)),!i)return!0}break}default:return!1}}var XE={startCheck:VE,endCheck:WE};function YE(n,e,t){e[t].setState(n.tag,n.substitution)}function qE(n,e,t){e[t].setState(n.tag,n.substitution)}function gl(n,e,t){for(let i=0;i<n.substitution.length;i++){const s=n.substitution[i],r=e[t+i];if(Array.isArray(s)){s.length?r.setState(n.tag,s[0]):r.setState("deleted",!0);continue}r.setState(n.tag,s)}}function $E(n,e,t){let i=e[t];i.setState(n.tag,n.substitution.ligGlyph);const s=n.substitution.components.length;for(let r=0;r<s;r++)i=e[t+r+1],i.setState("deleted",!0)}var cf={11:YE,12:qE,63:gl,41:$E,51:gl,53:gl};function ZE(n,e,t){n instanceof Pi&&cf[n.id]&&cf[n.id](n,e,t)}var ls=ZE;function KE(n){let e=[].concat(n.backtrack);for(let t=e.length-1;t>=0;t--){const i=e[t],s=Dp(i),r=Bi(i);if(!s&&!r)return!0;if(s)return!1}return!1}function JE(n){if(Dp(n.current))return!1;for(let e=0;e<n.lookahead.length;e++){const t=n.lookahead[e];if(!Bi(t))return!0}return!1}function jE(n){const e="arab",t=this.featuresTags[e],i=this.tokenizer.getRangeTokens(n);if(i.length===1)return;let s=new rn(i.map(a=>a.getState("glyphIndex")),0);const r=new rn(i.map(a=>a.char),0);for(let a=0;a<i.length;a++){const o=i[a];if(Bi(o.char))continue;s.setCurrentIndex(a),r.setCurrentIndex(a);let l=0;KE(r)&&(l|=1),JE(r)&&(l|=2);let c;switch(l){case 1:c="fina";break;case 2:c="init";break;case 3:c="medi";break}if(t.indexOf(c)===-1)continue;let u=this.query.lookupFeature({tag:c,script:e,contextParams:s});if(u instanceof Error){console.info(u.message);continue}for(let f=0;f<u.length;f++){const h=u[f];h instanceof Pi&&(ls(h,i,f),s.context[f]=h.substitution)}}}var QE=jE;function uf(n,e){const t=n.map(i=>i.activeState.value);return new rn(t,0)}function eT(n){const e="arab";let t=this.tokenizer.getRangeTokens(n),i=uf(t);for(let s=0;s<i.context.length;s++){i.setCurrentIndex(s);let r=this.query.lookupFeature({tag:"rlig",script:e,contextParams:i});if(r.length){for(let a=0;a<r.length;a++){const o=r[a];ls(o,t,s)}i=uf(t)}}}var tT=eT;function nT(n){return n.index===0&&n.context.length>1}function iT(n){return n.index===n.context.length-1}var sT={startCheck:nT,endCheck:iT};function hf(n,e){const t=n.map(i=>i.activeState.value);return new rn(t,0)}function rT(n){const e="delf",t="ccmp";let i=this.tokenizer.getRangeTokens(n),s=hf(i);for(let r=0;r<s.context.length;r++){if(!this.query.getFeature({tag:t,script:e,contextParams:s}))continue;s.setCurrentIndex(r);let a=this.query.lookupFeature({tag:t,script:e,contextParams:s});if(a.length){for(let o=0;o<a.length;o++){const l=a[o];ls(l,i,r)}s=hf(i)}}}var aT=rT;function oT(n){const e=n.current,t=n.get(-1);return t===null&&Va(e)||!Va(t)&&Va(e)}function lT(n){const e=n.get(1);return e===null||!Va(e)}var cT={startCheck:oT,endCheck:lT};function ff(n,e){const t=n.map(i=>i.activeState.value);return new rn(t,0)}function uT(n){const e="latn";let t=this.tokenizer.getRangeTokens(n),i=ff(t);for(let s=0;s<i.context.length;s++){i.setCurrentIndex(s);let r=this.query.lookupFeature({tag:"liga",script:e,contextParams:i});if(r.length){for(let a=0;a<r.length;a++){const o=r[a];ls(o,t,s)}i=ff(t)}}}var hT=uT;function fT(n){const e=n.current,t=n.get(-1);return t===null&&Ga(e)||!Ga(t)&&Ga(e)}function dT(n){const e=n.get(1);return e===null||!Ga(e)}var pT={startCheck:fT,endCheck:dT};function df(n,e){const t=n.map(i=>i.activeState.value);return new rn(t,e||0)}function mT(n){const e="thai";let t=this.tokenizer.getRangeTokens(n),i=df(t,0);for(let s=0;s<i.context.length;s++){i.setCurrentIndex(s);let r=this.query.lookupFeature({tag:"ccmp",script:e,contextParams:i});if(r.length){for(let a=0;a<r.length;a++){const o=r[a];ls(o,t,s)}i=df(t,s)}}}var gT=mT;function pf(n,e){const t=n.map(i=>i.activeState.value);return new rn(t,e||0)}function xT(n){const e="thai";let t=this.tokenizer.getRangeTokens(n),i=pf(t,0);for(let s=0;s<i.context.length;s++){i.setCurrentIndex(s);let r=this.query.lookupFeature({tag:"liga",script:e,contextParams:i});if(r.length){for(let a=0;a<r.length;a++){const o=r[a];ls(o,t,s)}i=pf(t,s)}}}var vT=xT;function mf(n,e){const t=n.map(i=>i.activeState.value);return new rn(t,e||0)}function yT(n){const e="thai";let t=this.tokenizer.getRangeTokens(n),i=mf(t,0);for(let s=0;s<i.context.length;s++){i.setCurrentIndex(s);let r=this.query.lookupFeature({tag:"rlig",script:e,contextParams:i});if(r.length){for(let a=0;a<r.length;a++){const o=r[a];ls(o,t,s)}i=mf(t,s)}}}var _T=yT;function wc(n){if(n===null)return!1;const e=n.codePointAt(0);return e>=6155&&e<=6157||e>=65024&&e<=65039||e>=917760&&e<=917999}function bT(n){const e=n.current,t=n.get(1);return t===null&&wc(e)||wc(t)}function ST(n){const e=n.get(1);return e===null||!wc(e)}var MT={startCheck:bT,endCheck:ST};function ET(n){const e=this.query.font,t=this.tokenizer.getRangeTokens(n);if(t[1].setState("deleted",!0),e.tables.cmap&&e.tables.cmap.varSelectorList){const i=t[0].char.codePointAt(0),s=t[1].char.codePointAt(0),r=e.tables.cmap.varSelectorList[s];if(r!==void 0&&r.nonDefaultUVS){const a=r.nonDefaultUVS.uvsMappings;if(a[i]){const o=a[i].glyphID;e.glyphs.glyphs[o]!==void 0&&t[0].setState("glyphIndex",o)}}}}var TT=ET;function Tn(n){this.baseDir=n||"ltr",this.tokenizer=new PE,this.featuresTags={}}Tn.prototype.setText=function(n){this.text=n};Tn.prototype.contextChecks={ccmpReplacementCheck:sT,latinWordCheck:cT,arabicWordCheck:GE,arabicSentenceCheck:XE,thaiWordCheck:pT,unicodeVariationSequenceCheck:MT};function Os(n){const e=this.contextChecks[`${n}Check`];return this.tokenizer.registerContextChecker(n,e.startCheck,e.endCheck)}function AT(){return Os.call(this,"ccmpReplacement"),Os.call(this,"latinWord"),Os.call(this,"arabicWord"),Os.call(this,"arabicSentence"),Os.call(this,"thaiWord"),Os.call(this,"unicodeVariationSequence"),this.tokenizer.tokenize(this.text)}function wT(){const n=this.tokenizer.getContextRanges("arabicSentence");for(let e=0;e<n.length;e++){const t=n[e];let i=this.tokenizer.getRangeTokens(t);this.tokenizer.replaceRange(t.startIndex,t.endOffset,i.reverse())}}Tn.prototype.registerFeatures=function(n,e){const t=e.filter(i=>this.query.supports({script:n,tag:i}));Object.prototype.hasOwnProperty.call(this.featuresTags,n)?this.featuresTags[n]=this.featuresTags[n].concat(t):this.featuresTags[n]=t};Tn.prototype.applyFeatures=function(n,e){if(!n)throw new Error("No valid font was provided to apply features");this.query||(this.query=new BE(n));for(let t=0;t<e.length;t++){const i=e[t];this.query.supports({script:i.script})&&this.registerFeatures(i.script,i.tags)}};Tn.prototype.registerModifier=function(n,e,t){this.tokenizer.registerModifier(n,e,t)};function Hr(){if(this.tokenizer.registeredModifiers.indexOf("glyphIndex")===-1)throw new Error("glyphIndex modifier is required to apply arabic presentation features.")}function CT(){if(!Object.prototype.hasOwnProperty.call(this.featuresTags,"arab"))return;Hr.call(this);const e=this.tokenizer.getContextRanges("arabicWord");for(let t=0;t<e.length;t++){const i=e[t];QE.call(this,i)}}function RT(){Hr.call(this);const n=this.tokenizer.getContextRanges("ccmpReplacement");for(let e=0;e<n.length;e++){const t=n[e];aT.call(this,t)}}function PT(){if(!this.hasFeatureEnabled("arab","rlig"))return;Hr.call(this);const n=this.tokenizer.getContextRanges("arabicWord");for(let e=0;e<n.length;e++){const t=n[e];tT.call(this,t)}}function LT(){if(!this.hasFeatureEnabled("latn","liga"))return;Hr.call(this);const n=this.tokenizer.getContextRanges("latinWord");for(let e=0;e<n.length;e++){const t=n[e];hT.call(this,t)}}function DT(){const n=this.tokenizer.getContextRanges("unicodeVariationSequence");for(let e=0;e<n.length;e++){const t=n[e];TT.call(this,t)}}function IT(){Hr.call(this);const n=this.tokenizer.getContextRanges("thaiWord");for(let e=0;e<n.length;e++){const t=n[e];this.hasFeatureEnabled("thai","liga")&&vT.call(this,t),this.hasFeatureEnabled("thai","rlig")&&_T.call(this,t),this.hasFeatureEnabled("thai","ccmp")&&gT.call(this,t)}}Tn.prototype.checkContextReady=function(n){return!!this.tokenizer.getContext(n)};Tn.prototype.applyFeaturesToContexts=function(){this.checkContextReady("ccmpReplacement")&&RT.call(this),this.checkContextReady("arabicWord")&&(CT.call(this),PT.call(this)),this.checkContextReady("latinWord")&<.call(this),this.checkContextReady("arabicSentence")&&wT.call(this),this.checkContextReady("thaiWord")&&IT.call(this),this.checkContextReady("unicodeVariationSequence")&&DT.call(this)};Tn.prototype.hasFeatureEnabled=function(n,e){return(this.featuresTags[n]||[]).indexOf(e)!==-1};Tn.prototype.processText=function(n){(!this.text||this.text!==n)&&(this.setText(n),AT.call(this),this.applyFeaturesToContexts())};Tn.prototype.getBidiText=function(n){return this.processText(n),this.tokenizer.getText()};Tn.prototype.getTextGlyphs=function(n){this.processText(n);let e=[];for(let t=0;t<this.tokenizer.tokens.length;t++){const i=this.tokenizer.tokens[t];if(i.state.deleted)continue;const s=i.activeState.value;e.push(Array.isArray(s)?s[0]:s)}return e};var UT=Tn;function xl(n){return{fontFamily:{en:n.familyName||" "},fontSubfamily:{en:n.styleName||" "},fullName:{en:n.fullName||n.familyName+" "+n.styleName},postScriptName:{en:n.postScriptName||(n.familyName+n.styleName).replace(/\s/g,"")},designer:{en:n.designer||" "},designerURL:{en:n.designerURL||" "},manufacturer:{en:n.manufacturer||" "},manufacturerURL:{en:n.manufacturerURL||" "},license:{en:n.license||" "},licenseURL:{en:n.licenseURL||" "},version:{en:n.version||"Version 0.1"},description:{en:n.description||" "},copyright:{en:n.copyright||" "},trademark:{en:n.trademark||" "}}}function dt(n){if(n=n||{},n.tables=n.tables||{},!n.empty){if(!n.familyName)throw new Error("When creating a new Font object, familyName is required.");if(!n.styleName)throw new Error("When creating a new Font object, styleName is required.");if(!n.unitsPerEm)throw new Error("When creating a new Font object, unitsPerEm is required.");if(!n.ascender)throw new Error("When creating a new Font object, ascender is required.");if(n.descender>0)throw new Error("When creating a new Font object, negative descender value is required.");this.names={},this.names.unicode=xl(n),this.names.macintosh=xl(n),this.names.windows=xl(n),this.unitsPerEm=n.unitsPerEm||1e3,this.ascender=n.ascender,this.descender=n.descender,this.createdTimestamp=n.createdTimestamp,this.italicAngle=n.italicAngle||0,this.weightClass=n.weightClass||0;let e=0;n.fsSelection?e=n.fsSelection:(this.italicAngle<0?e|=this.fsSelectionValues.ITALIC:this.italicAngle>0&&(e|=this.fsSelectionValues.OBLIQUE),this.weightClass>=600&&(e|=this.fsSelectionValues.BOLD),e===0&&(e=this.fsSelectionValues.REGULAR)),(!n.panose||!Array.isArray(n.panose))&&(n.panose=[0,0,0,0,0,0,0,0,0]),this.tables=Object.assign(n.tables,{os2:Object.assign({usWeightClass:n.weightClass||this.usWeightClasses.MEDIUM,usWidthClass:n.widthClass||this.usWidthClasses.MEDIUM,bFamilyType:n.panose[0]||0,bSerifStyle:n.panose[1]||0,bWeight:n.panose[2]||0,bProportion:n.panose[3]||0,bContrast:n.panose[4]||0,bStrokeVariation:n.panose[5]||0,bArmStyle:n.panose[6]||0,bLetterform:n.panose[7]||0,bMidline:n.panose[8]||0,bXHeight:n.panose[9]||0,fsSelection:e},n.tables.os2)})}this.supported=!0,this.glyphs=new jn.GlyphSet(this,n.glyphs||[]),this.encoding=new Xd(this),this.position=new RS(this),this.substitution=new FS(this),this.tables=this.tables||{},this.tables=new Proxy(this.tables,{set:(e,t,i)=>(e[t]=i,e.fvar&&(e.gvar||e.cff2)&&!this.variation&&(this.variation=new JS(this)),!0)}),this.palettes=new Sp(this),this.layers=new NS(this),this.svgImages=new kS(this),this._push=null,this._hmtxTableData={},Object.defineProperty(this,"hinting",{get:function(){return this._hinting?this._hinting:this.outlinesFormat==="truetype"?this._hinting=new wE(this):null}})}dt.prototype.hasChar=function(n){return this.encoding.charToGlyphIndex(n)>0};dt.prototype.charToGlyphIndex=function(n){return this.encoding.charToGlyphIndex(n)};dt.prototype.charToGlyph=function(n){const e=this.charToGlyphIndex(n);let t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t};dt.prototype.updateFeatures=function(n){return this.defaultRenderOptions.features.map(e=>e.script==="latn"?{script:"latn",tags:e.tags.filter(t=>n[t])}:e)};dt.prototype.stringToGlyphIndexes=function(n,e){const t=new UT,i=r=>this.charToGlyphIndex(r.char);t.registerModifier("glyphIndex",null,i);let s=e?this.updateFeatures(e.features):this.defaultRenderOptions.features;return t.applyFeatures(this,s),t.getTextGlyphs(n)};dt.prototype.stringToGlyphs=function(n,e){const t=this.stringToGlyphIndexes(n,e);let i=t.length;const s=new Array(i),r=this.glyphs.get(0);for(let a=0;a<i;a+=1)s[a]=this.glyphs.get(t[a])||r;return s};dt.prototype.nameToGlyphIndex=function(n){return this.glyphNames.nameToGlyphIndex(n)};dt.prototype.nameToGlyph=function(n){const e=this.nameToGlyphIndex(n);let t=this.glyphs.get(e);return t||(t=this.glyphs.get(0)),t};dt.prototype.glyphIndexToName=function(n){return this.glyphNames.glyphIndexToName?this.glyphNames.glyphIndexToName(n):""};dt.prototype.getKerningValue=function(n,e){n=n.index||n,e=e.index||e;const t=this.position.defaultKerningTables;return t?this.position.getKerningValue(t,n,e):this.kerningPairs[n+","+e]||0};dt.prototype.defaultRenderOptions={kerning:!0,features:[{script:"arab",tags:["init","medi","fina","rlig"]},{script:"latn",tags:["liga","rlig"]},{script:"thai",tags:["liga","rlig","ccmp"]}],hinting:!1,usePalette:0,drawLayers:!0,drawSVG:!0};dt.prototype.forEachGlyph=function(n,e,t,i,s,r){e=e!==void 0?e:0,t=t!==void 0?t:0,i=i!==void 0?i:72,s=Object.assign({},this.defaultRenderOptions,s);const a=1/this.unitsPerEm*i,o=this.stringToGlyphs(n,s);let l;if(s.kerning){const c=s.script||this.position.getDefaultScriptName();l=this.position.getKerningTables(c,s.language)}for(let c=0;c<o.length;c+=1){const u=o[c];if(r.call(this,u,e,t,i,s),u.advanceWidth&&(e+=u.advanceWidth*a),s.kerning&&c<o.length-1){const f=l?this.position.getKerningValue(l,u.index,o[c+1].index):this.getKerningValue(u,o[c+1]);e+=f*a}s.letterSpacing?e+=s.letterSpacing*i:s.tracking&&(e+=s.tracking/1e3*i)}return e};dt.prototype.getPath=function(n,e,t,i,s){s=Object.assign({},this.defaultRenderOptions,s);const r=new qs;if(r._layers=[],ep(this,r),r.stroke){const a=1/(r.unitsPerEm||1e3)*i;r.strokeWidth*=a}return this.forEachGlyph(n,e,t,i,s,(a,o,l,c)=>{const u=a.getPath(o,l,c,s,this);if(s.drawSVG||s.drawLayers){const f=u._layers;if(f&&f.length){for(let h=0;h<f.length;h++){const d=f[h];r._layers.push(d)}return}}r.extend(u)}),r};dt.prototype.getPaths=function(n,e,t,i,s){s=Object.assign({},this.defaultRenderOptions,s);const r=[];return this.forEachGlyph(n,e,t,i,s,function(a,o,l,c){const u=a.getPath(o,l,c,s,this);r.push(u)}),r};dt.prototype.getAdvanceWidth=function(n,e,t){return t=Object.assign({},this.defaultRenderOptions,t),this.forEachGlyph(n,0,0,e,t,function(){})};dt.prototype.draw=function(n,e,t,i,s,r){this.getPath(e,t,i,s,r).draw(n)};dt.prototype.drawPoints=function(n,e,t,i,s,r){r=Object.assign({},this.defaultRenderOptions,r),this.forEachGlyph(e,t,i,s,r,function(a,o,l,c){a.drawPoints(n,o,l,c,r,this)})};dt.prototype.drawMetrics=function(n,e,t,i,s,r){r=Object.assign({},this.defaultRenderOptions,r),this.forEachGlyph(e,t,i,s,r,function(a,o,l,c){a.drawMetrics(n,o,l,c)})};dt.prototype.getEnglishName=function(n){const e=(this.names.unicode||this.names.macintosh||this.names.windows)[n];if(e)return e.en};dt.prototype.validate=function(){const n=[],e=this;function t(s,r){s||(console.warn(`[opentype.js] ${r}`),n.push(r))}function i(s){const r=e.getEnglishName(s);t(r&&r.trim().length>0,"No English "+s+" specified.")}if(i("fontFamily"),i("weightName"),i("manufacturer"),i("copyright"),i("version"),t(this.unitsPerEm>0,"No unitsPerEm specified."),this.tables.colr){const s=this.tables.colr.baseGlyphRecords;let r=-1;for(let a=0;a<s.length;a++){const o=s[a].glyphID;if(t(r<s[a].glyphID,`baseGlyphs must be sorted by GlyphID in ascending order, but glyphID ${o} comes after ${r}`),r>s[a].glyphID)break;r=o}}return n};dt.prototype.toTables=function(){return CS.fontToTable(this)};dt.prototype.toBuffer=function(){return console.warn("Font.toBuffer is deprecated. Use Font.toArrayBuffer instead."),this.toArrayBuffer()};dt.prototype.toArrayBuffer=function(){const e=this.toTables().encode(),t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<e.length;s++)i[s]=e[s];return t};dt.prototype.download=function(){console.error("DEPRECATED: platform-specific actions are to be implemented on user-side")};dt.prototype.fsSelectionValues={ITALIC:1,UNDERSCORE:2,NEGATIVE:4,OUTLINED:8,STRIKEOUT:16,BOLD:32,REGULAR:64,USER_TYPO_METRICS:128,WWS:256,OBLIQUE:512};dt.prototype.macStyleValues={BOLD:1,ITALIC:2,UNDERLINE:4,OUTLINED:8,SHADOW:16,CONDENSED:32,EXTENDED:64};dt.prototype.usWidthClasses={ULTRA_CONDENSED:1,EXTRA_CONDENSED:2,CONDENSED:3,SEMI_CONDENSED:4,MEDIUM:5,SEMI_EXPANDED:6,EXPANDED:7,EXTRA_EXPANDED:8,ULTRA_EXPANDED:9};dt.prototype.usWeightClasses={THIN:100,EXTRA_LIGHT:200,LIGHT:300,NORMAL:400,MEDIUM:500,SEMI_BOLD:600,BOLD:700,EXTRA_BOLD:800,BLACK:900};var OT=dt;function FT(n,e){const t=new Te.Parser(n,e),i=t.parseUShort(),s=t.parseUShort();i!==1&&console.warn(`Unsupported hvar table version ${i}.${s}`);const r=[i,s],a=t.parsePointer32(function(){return this.parseItemVariationStore()}),o=t.parsePointer32(function(){return this.parseDeltaSetIndexMap()}),l=t.parsePointer32(function(){return this.parseDeltaSetIndexMap()}),c=t.parsePointer32(function(){return this.parseDeltaSetIndexMap()});return{version:r,itemVariationStore:a,advanceWidth:o,lsb:l,rsb:c}}function NT(){console.warn("Writing of hvar tables is not yet supported.")}var kT={make:NT,parse:FT},BT=function(){return{coverage:this.parsePointer(q.coverage),attachPoints:this.parseList(q.pointer(q.uShortList))}},HT=function(){var n=this.parseUShort();if(Ne.argument(n===1||n===2||n===3,"Unsupported CaretValue table version."),n===1)return{coordinate:this.parseShort()};if(n===2)return{pointindex:this.parseShort()};if(n===3)return{coordinate:this.parseShort()}},zT=function(){return this.parseList(q.pointer(HT))},GT=function(){return{coverage:this.parsePointer(q.coverage),ligGlyphs:this.parseList(q.pointer(zT))}},VT=function(){return this.parseUShort(),this.parseList(q.pointer(q.coverage))};function WT(n,e){e=e||0;const t=new q(n,e),i=t.parseVersion(1);Ne.argument(i===1||i===1.2||i===1.3,"Unsupported GDEF table version.");var s={version:i,classDef:t.parsePointer(q.classDef),attachList:t.parsePointer(BT),ligCaretList:t.parsePointer(GT),markAttachClassDef:t.parsePointer(q.classDef)};return i>=1.2&&(s.markGlyphSets=t.parsePointer(VT)),s}var XT={parse:WT},On=new Array(10);On[1]=function(){const e=this.offset+this.relativeOffset,t=this.parseUShort();if(t===1)return{posFormat:1,coverage:this.parsePointer(q.coverage),value:this.parseValueRecord()};if(t===2)return{posFormat:2,coverage:this.parsePointer(q.coverage),values:this.parseValueRecordList()};Ne.assert(!1,"0x"+e.toString(16)+": GPOS lookup type 1 format must be 1 or 2.")};On[2]=function(){const e=this.offset+this.relativeOffset,t=this.parseUShort();Ne.assert(t===1||t===2,"0x"+e.toString(16)+": GPOS lookup type 2 format must be 1 or 2.");const i=this.parsePointer(q.coverage),s=this.parseUShort(),r=this.parseUShort();if(t===1)return{posFormat:t,coverage:i,valueFormat1:s,valueFormat2:r,pairSets:this.parseList(q.pointer(q.list(function(){return{secondGlyph:this.parseUShort(),value1:this.parseValueRecord(s),value2:this.parseValueRecord(r)}})))};if(t===2){const a=this.parsePointer(q.classDef),o=this.parsePointer(q.classDef),l=this.parseUShort(),c=this.parseUShort();return{posFormat:t,coverage:i,valueFormat1:s,valueFormat2:r,classDef1:a,classDef2:o,class1Count:l,class2Count:c,classRecords:this.parseList(l,q.list(c,function(){return{value1:this.parseValueRecord(s),value2:this.parseValueRecord(r)}}))}}};On[3]=function(){return{error:"GPOS Lookup 3 not supported"}};On[4]=function(){return{error:"GPOS Lookup 4 not supported"}};On[5]=function(){return{error:"GPOS Lookup 5 not supported"}};On[6]=function(){return{error:"GPOS Lookup 6 not supported"}};On[7]=function(){return{error:"GPOS Lookup 7 not supported"}};On[8]=function(){return{error:"GPOS Lookup 8 not supported"}};On[9]=function(){return{error:"GPOS Lookup 9 not supported"}};function YT(n,e){e=e||0;const t=new q(n,e),i=t.parseVersion(1);return Ne.argument(i===1||i===1.1,"Unsupported GPOS table version "+i),i===1?{version:i,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(On)}:{version:i,scripts:t.parseScriptList(),features:t.parseFeatureList(),lookups:t.parseLookupList(On),variations:t.parseFeatureVariationsList()}}var qT=new Array(10);function $T(n){return new me.Table("GPOS",[{name:"version",type:"ULONG",value:65536},{name:"scripts",type:"TABLE",value:new me.ScriptList(n.scripts)},{name:"features",type:"TABLE",value:new me.FeatureList(n.features)},{name:"lookups",type:"TABLE",value:new me.LookupList(n.lookups,qT)}])}var ZT={parse:YT,make:$T};function KT(n){const e={};n.skip("uShort");const t=n.parseUShort();Ne.argument(t===0,"Unsupported kern sub-table version."),n.skip("uShort",2);const i=n.parseUShort();n.skip("uShort",3);for(let s=0;s<i;s+=1){const r=n.parseUShort(),a=n.parseUShort(),o=n.parseShort();e[r+","+a]=o}return e}function JT(n){const e={};n.skip("uShort"),n.parseULong()>1&&console.warn("Only the first kern subtable is supported."),n.skip("uLong");const s=n.parseUShort()&255;if(n.skip("uShort"),s===0){const r=n.parseUShort();n.skip("uShort",3);for(let a=0;a<r;a+=1){const o=n.parseUShort(),l=n.parseUShort(),c=n.parseShort();e[o+","+l]=c}}return e}function jT(n,e){const t=new Te.Parser(n,e),i=t.parseUShort();if(i===0)return KT(t);if(i===1)return JT(t);throw new Error("Unsupported kern table version ("+i+").")}var QT={parse:jT};function e2(n,e,t,i){const s=new Te.Parser(n,e),r=i?s.parseUShort:s.parseULong,a=[];for(let o=0;o<t+1;o+=1){let l=r.call(s);i&&(l*=2),a.push(l)}return a}var t2={parse:e2};function gf(n,e){const t=[];let i=12;for(let s=0;s<e;s+=1){const r=Te.getTag(n,i),a=Te.getULong(n,i+4),o=Te.getULong(n,i+8),l=Te.getULong(n,i+12);t.push({tag:r,checksum:a,offset:o,length:l,compression:!1}),i+=16}return t}function n2(n,e){const t=[];let i=44;for(let s=0;s<e;s+=1){const r=Te.getTag(n,i),a=Te.getULong(n,i+4),o=Te.getULong(n,i+8),l=Te.getULong(n,i+12);let c;o<l?c="WOFF":c=!1,t.push({tag:r,offset:a,compression:c,compressedLength:o,length:l}),i+=20}return t}function lt(n,e){if(e.compression==="WOFF"){const t=new Uint8Array(n.buffer,e.offset+2,e.compressedLength-2),i=new Uint8Array(e.length);if(Id(t,i),i.byteLength!==e.length)throw new Error("Decompression error: "+e.tag+" decompressed length doesn't match recorded length");return{data:new DataView(i.buffer,0),offset:0}}else return{data:n,offset:e.offset}}function i2(n,e={}){let t,i;const s=new OT({empty:!0});n.constructor!==ArrayBuffer&&(n=new Uint8Array(n).buffer);const r=new DataView(n,0);let a,o=[];const l=Te.getTag(r,0);if(l==="\0\0\0"||l==="true"||l==="typ1")s.outlinesFormat="truetype",a=Te.getUShort(r,4),o=gf(r,a);else if(l==="OTTO")s.outlinesFormat="cff",a=Te.getUShort(r,4),o=gf(r,a);else if(l==="wOFF"){const O=Te.getTag(r,4);if(O==="\0\0\0")s.outlinesFormat="truetype";else if(O==="OTTO")s.outlinesFormat="cff";else throw new Error("Unsupported OpenType flavor "+l);a=Te.getUShort(r,12),o=n2(r,a)}else if(l==="wOF2"){const O="https://github.com/opentypejs/opentype.js/issues/183#issuecomment-1147228025";throw new Error("WOFF2 require an external decompressor library, see examples at: "+O)}else throw new Error("Unsupported OpenType signature "+l);let c,u,f,h,d,p,x,m,g,M,E,_,T,b,S,v,w,I;for(let O=0;O<a;O+=1){const N=o[O];let U;switch(N.tag){case"avar":x=N;break;case"cmap":U=lt(r,N),s.tables.cmap=Wd.parse(U.data,U.offset),s.encoding=new Yd(s.tables.cmap);break;case"cvt ":U=lt(r,N),I=new Te.Parser(U.data,U.offset),s.tables.cvt=I.parseShortList(N.length/2);break;case"fvar":f=N;break;case"STAT":h=N;break;case"gvar":d=N;break;case"cvar":p=N;break;case"fpgm":U=lt(r,N),I=new Te.Parser(U.data,U.offset),s.tables.fpgm=I.parseByteList(N.length);break;case"head":U=lt(r,N),s.tables.head=ip.parse(U.data,U.offset),s.unitsPerEm=s.tables.head.unitsPerEm,t=s.tables.head.indexToLocFormat;break;case"hhea":U=lt(r,N),s.tables.hhea=sp.parse(U.data,U.offset),s.ascender=s.tables.hhea.ascender,s.descender=s.tables.hhea.descender,s.numberOfHMetrics=s.tables.hhea.numberOfHMetrics;break;case"HVAR":T=N;break;case"hmtx":_=N;break;case"ltag":U=lt(r,N),i=ap.parse(U.data,U.offset);break;case"COLR":U=lt(r,N),s.tables.colr=hp.parse(U.data,U.offset);break;case"CPAL":U=lt(r,N),s.tables.cpal=Kd.parse(U.data,U.offset);break;case"maxp":U=lt(r,N),s.tables.maxp=op.parse(U.data,U.offset),s.numGlyphs=s.tables.maxp.numGlyphs;break;case"name":v=N;break;case"OS/2":U=lt(r,N),s.tables.os2=Tc.parse(U.data,U.offset);break;case"post":U=lt(r,N),s.tables.post=lp.parse(U.data,U.offset),s.glyphNames=new Kc(s.tables.post);break;case"prep":U=lt(r,N),I=new Te.Parser(U.data,U.offset),s.tables.prep=I.parseByteList(N.length);break;case"glyf":m=N;break;case"loca":S=N;break;case"CFF ":c=N;break;case"CFF2":u=N;break;case"kern":b=N;break;case"GDEF":g=N;break;case"GPOS":M=N;break;case"GSUB":E=N;break;case"meta":w=N;break;case"gasp":try{U=lt(r,N),s.tables.gasp=xp.parse(U.data,U.offset)}catch(Z){console.warn("Failed to parse gasp table, skipping."),console.warn(Z)}break;case"SVG ":U=lt(r,N),s.tables.svg=vp.parse(U.data,U.offset);break}}const L=lt(r,v);if(s.tables.name=Vd.parse(L.data,L.offset,i),s.names=s.tables.name,m&&S){const O=t===0,N=lt(r,S),U=t2.parse(N.data,N.offset,s.numGlyphs,O),Z=lt(r,m);s.glyphs=Tp.parse(Z.data,Z.offset,U,s,e)}else if(c){const O=lt(r,c);Mc.parse(O.data,O.offset,s,e)}else if(u){const O=lt(r,u);Mc.parse(O.data,O.offset,s,e)}else throw new Error("Font doesn't contain TrueType, CFF or CFF2 outlines.");const C=lt(r,_);if(rp.parse(s,C.data,C.offset,s.numberOfHMetrics,s.numGlyphs,s.glyphs,e),jb(s,e),b){const O=lt(r,b);s.kerningPairs=QT.parse(O.data,O.offset)}else s.kerningPairs={};if(g){const O=lt(r,g);s.tables.gdef=XT.parse(O.data,O.offset)}if(M){const O=lt(r,M);s.tables.gpos=ZT.parse(O.data,O.offset),s.position.init()}if(E){const O=lt(r,E);s.tables.gsub=cp.parse(O.data,O.offset)}if(f){const O=lt(r,f);s.tables.fvar=fp.parse(O.data,O.offset,s.names)}if(h){const O=lt(r,h);s.tables.stat=dp.parse(O.data,O.offset,s.tables.fvar)}if(d){f||console.warn("This font provides a gvar table, but no fvar table, which is required for variable fonts."),m||console.warn("This font provides a gvar table, but no glyf table. Glyph variation only works with TrueType outlines.");const O=lt(r,d);s.tables.gvar=gp.parse(O.data,O.offset,s.tables.fvar,s.glyphs)}if(p){f||console.warn("This font provides a cvar table, but no fvar table, which is required for variable fonts."),s.tables.cvt||console.warn("This font provides a cvar table, but no cvt table which could be made variable."),m||console.warn("This font provides a gvar table, but no glyf table. Glyph variation only works with TrueType outlines.");const O=lt(r,p);s.tables.cvar=mp.parse(O.data,O.offset,s.tables.fvar,s.tables.cvt||[])}if(x){f||console.warn("This font provides an avar table, but no fvar table, which is required for variable fonts.");const O=lt(r,x);s.tables.avar=pp.parse(O.data,O.offset,s.tables.fvar)}if(T){f||console.warn("This font provides an HVAR table, but no fvar table, which is required for variable fonts."),_||console.warn("This font provides an HVAR table, but no hmtx table to vary.");const O=lt(r,T);s.tables.hvar=kT.parse(O.data,O.offset,s.tables.fvar)}if(w){const O=lt(r,w);s.tables.meta=up.parse(O.data,O.offset),s.metas=s.tables.meta}return s.palettes=new Sp(s),s}const Ji=1024,cn=8,Ca=.08;let Ip="/fonts/NanumGothic-Regular.ttf";function s2(n){Ip=n,Ir._shared=null}const Er=class Er{constructor(e){Vt(this,"capHeightEm");Vt(this,"ascentEm");Vt(this,"descentEm");Vt(this,"font");Vt(this,"upem");Vt(this,"glyphs",new Map);Vt(this,"data",new Float32Array(Ji*4*64));Vt(this,"used",0);Vt(this,"_texture",null);Vt(this,"_texelsUploaded",0);var t,i;this.font=e,this.upem=e.unitsPerEm,this.capHeightEm=(((i=(t=e.tables)==null?void 0:t.os2)==null?void 0:i.sCapHeight)||e.ascender*.88)/this.upem,this.ascentEm=e.ascender/this.upem,this.descentEm=e.descender/this.upem}static shared(e=Ip){return this._shared||(this._shared=(async()=>{const t=await(await fetch(e)).arrayBuffer();return new Er(i2(t))})(),this._shared.catch(()=>{Er._shared=null})),this._shared}measureEm(e){let t=0;for(const i of e)t+=this.ensureGlyph(i.codePointAt(0)).advance;return t}ensureGlyph(e){let t=this.glyphs.get(e);if(t)return t;const i=this.font.charToGlyph(String.fromCodePoint(e)),s=(i.advanceWidth??this.upem*.5)/this.upem,r=i.getPath(0,0,1),a=[];let o=0,l=0,c=0,u=0;for(const C of r.commands)switch(C.type){case"M":c=o=C.x,u=l=-C.y;break;case"L":a.push(xf(c,u,C.x,-C.y)),c=C.x,u=-C.y;break;case"Q":a.push({x0:c,y0:u,cx:C.x1,cy:-C.y1,x1:C.x,y1:-C.y}),c=C.x,u=-C.y;break;case"C":{const O=(C.x1+C.x2)/2,N=(-C.y1+-C.y2)/2;a.push({x0:c,y0:u,cx:O,cy:N,x1:C.x,y1:-C.y}),c=C.x,u=-C.y;break}case"Z":(c!==o||u!==l)&&a.push(xf(c,u,o,l)),c=o,u=l;break}if(!a.length)return t={base:-1,advance:s},this.glyphs.set(e,t),t;let f=1/0,h=1/0,d=-1/0,p=-1/0;for(const C of a)f=Math.min(f,C.x0,C.cx,C.x1),d=Math.max(d,C.x0,C.cx,C.x1),h=Math.min(h,C.y0,C.cy,C.y1),p=Math.max(p,C.y0,C.cy,C.y1);const x=Math.max(d-f,1e-6),m=Math.max(p-h,1e-6),g=Array.from({length:cn},()=>[]),M=Array.from({length:cn},()=>[]);a.forEach((C,O)=>{const N=Math.min(C.y0,C.cy,C.y1),U=Math.max(C.y0,C.cy,C.y1),Z=Math.min(C.x0,C.cx,C.x1),k=Math.max(C.x0,C.cx,C.x1),$=Ra((N-h)/m),D=Ra((U-h)/m);for(let ee=$;ee<=D;ee++)g[ee].push(O);const ae=Ra((Z-f)/x),re=Ra((k-f)/x);for(let ee=ae;ee<=re;ee++)M[ee].push(O)});const E=C=>Math.ceil(C.length/4),_=g.reduce((C,O)=>C+E(O),0)+M.reduce((C,O)=>C+E(O),0),T=2+cn*2+_+a.length*2,b=this.alloc(T),S=this.data,v=(C,O,N,U,Z)=>{S[C*4]=O,S[C*4+1]=N,S[C*4+2]=U,S[C*4+3]=Z},w=b+2+cn*2+_;v(b,f,h,d,p),v(b+1,b+2,b+2+cn,0,0);let I=b+2+cn*2;const L=(C,O)=>{for(let N=0;N<cn;N++){v(O+N,I,C[N].length,0,0);const U=C[N];for(let Z=0;Z<U.length;Z+=4)v(I++,w+U[Z]*2,Z+1<U.length?w+U[Z+1]*2:0,Z+2<U.length?w+U[Z+2]*2:0,Z+3<U.length?w+U[Z+3]*2:0)}};return L(g,b+2),L(M,b+2+cn),a.forEach((C,O)=>{v(w+O*2,C.x0,C.y0,C.cx,C.cy),v(w+O*2+1,C.x1,C.y1,0,0)}),t={base:b,advance:s},this.glyphs.set(e,t),t}bboxOf(e){const t=e.base*4;return[this.data[t],this.data[t+1],this.data[t+2],this.data[t+3]]}alloc(e){const t=(this.used+e)*4;if(t>this.data.length){let s=this.data.length;for(;s<t;)s*=2;const r=new Float32Array(s);r.set(this.data),this.data=r}const i=this.used;return this.used+=e,i}texture(){var t;const e=Math.max(1,Math.ceil(this.used/Ji));if(!this._texture||this._texelsUploaded<this.used){(t=this._texture)==null||t.dispose();const i=new Float32Array(Ji*e*4);i.set(this.data.subarray(0,Math.min(this.data.length,Ji*e*4)));const s=new td(i,Ji,e,En,Ln);s.minFilter=Ft,s.magFilter=Ft,s.generateMipmaps=!1,s.needsUpdate=!0,this._texture=s,this._texelsUploaded=this.used}return this._texture}};Vt(Er,"_shared",null);let Ir=Er;function xf(n,e,t,i){return{x0:n,y0:e,cx:(n+t)/2,cy:(e+i)/2,x1:t,y1:i}}function Ra(n){return Math.min(cn-1,Math.max(0,Math.floor(n*cn)))}const r2=`
|
|
attribute vec2 emuv;
|
|
attribute float gbase;
|
|
attribute vec3 tcolor;
|
|
varying vec2 vEm;
|
|
flat varying int vBase;
|
|
varying vec3 vColor;
|
|
void main() {
|
|
vEm = emuv;
|
|
vBase = int(gbase);
|
|
vColor = tcolor;
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
}
|
|
`,a2=`
|
|
precision highp float;
|
|
uniform sampler2D dataTex;
|
|
varying vec2 vEm;
|
|
flat varying int vBase;
|
|
varying vec3 vColor;
|
|
layout(location = 0) out vec4 fragOut;
|
|
|
|
vec4 T(int i) { return texelFetch(dataTex, ivec2(i % ${Ji}, i / ${Ji}), 0); }
|
|
|
|
// Lengyel's banded winding-number coverage for one ray along +x from p.
|
|
// Curves are fetched via the band's index list; 'swap' mirrors x/y for the
|
|
// vertical (+y) ray, whose winding sign flips (handedness reversal).
|
|
float rayCoverage(vec2 p, float ppem, int bandTexel, bool swap) {
|
|
vec4 band = T(bandTexel);
|
|
int count = int(band.y);
|
|
float cov = 0.0;
|
|
for (int j = 0; j < 256; j++) {
|
|
if (j >= count) break;
|
|
vec4 idx4 = T(int(band.x) + (j >> 2));
|
|
int cb = int(j % 4 == 0 ? idx4.x : j % 4 == 1 ? idx4.y : j % 4 == 2 ? idx4.z : idx4.w);
|
|
vec4 A = T(cb);
|
|
vec2 e = T(cb + 1).xy;
|
|
// Swap the CURVE points before subtracting: p is already in swapped
|
|
// coordinates for the vertical ray ((A.xy - p).yx would be wrong).
|
|
vec2 p1 = (swap ? A.yx : A.xy) - p;
|
|
vec2 p2 = (swap ? A.wz : A.zw) - p;
|
|
vec2 p3 = (swap ? e.yx : e.xy) - p;
|
|
|
|
uint code = (0x2E74u >> ((p1.y > 0.0 ? 2u : 0u) + (p2.y > 0.0 ? 4u : 0u) + (p3.y > 0.0 ? 8u : 0u))) & 3u;
|
|
if (code != 0u) {
|
|
vec2 a = p1 - p2 * 2.0 + p3;
|
|
vec2 b = p1 - p2;
|
|
float t1, t2;
|
|
if (abs(a.y) < 1e-6) {
|
|
float t = p1.y / (2.0 * b.y);
|
|
t1 = t; t2 = t;
|
|
} else {
|
|
float d = sqrt(max(b.y * b.y - a.y * p1.y, 0.0));
|
|
t1 = (b.y - d) / a.y;
|
|
t2 = (b.y + d) / a.y;
|
|
}
|
|
if ((code & 1u) != 0u) {
|
|
float x = (a.x * t1 - b.x * 2.0) * t1 + p1.x;
|
|
cov += clamp(x * ppem + 0.5, 0.0, 1.0);
|
|
}
|
|
if (code > 1u) {
|
|
float x = (a.x * t2 - b.x * 2.0) * t2 + p1.x;
|
|
cov -= clamp(x * ppem + 0.5, 0.0, 1.0);
|
|
}
|
|
}
|
|
}
|
|
return cov;
|
|
}
|
|
|
|
void main() {
|
|
vec4 bbox = T(vBase);
|
|
vec4 bases = T(vBase + 1);
|
|
vec2 fw = fwidth(vEm);
|
|
|
|
vec2 span = max(bbox.zw - bbox.xy, vec2(1e-6));
|
|
int hb = clamp(int((vEm.y - bbox.y) / span.y * float(${cn})), 0, ${cn-1});
|
|
int vb = clamp(int((vEm.x - bbox.x) / span.x * float(${cn})), 0, ${cn-1});
|
|
|
|
float covH = rayCoverage(vEm, 1.0 / max(fw.x, 1e-9), int(bases.x) + hb, false);
|
|
float covV = -rayCoverage(vEm.yx, 1.0 / max(fw.y, 1e-9), int(bases.y) + vb, true);
|
|
float alpha = clamp((covH + covV) * 0.5, 0.0, 1.0);
|
|
if (alpha < 0.004) discard;
|
|
fragOut = vec4(vColor, alpha);
|
|
}
|
|
`;class o2{constructor(e){Vt(this,"pos",[]);Vt(this,"emuv",[]);Vt(this,"gbase",[]);Vt(this,"color",[]);Vt(this,"index",[]);this.engine=e}add(e,t,i,s,r,a,o){const l=this.engine,c=String(e).split(`
|
|
`),u=i/l.capHeightEm,f=i*5/3,h=(c.length-1)*f+i;a===4&&(o=2);let d;o===3?d=-i:o===2?d=h/2-i:d=(c.length-1)*f;const p=Math.cos(s),x=Math.sin(s),m=(r>>16&255)/255,g=(r>>8&255)/255,M=(r&255)/255;for(let E=0;E<c.length;E++){const _=c[E];if(!_)continue;const T=l.measureEm(_),b=a===1||a===4?-T*u/2:a===2?-T*u:0,S=d-E*f;let v=0;for(const w of _){const I=l.ensureGlyph(w.codePointAt(0));if(I.base>=0){const[L,C,O,N]=this.engine.bboxOf(I),U=L-Ca,Z=C-Ca,k=O+Ca,$=N+Ca,D=this.pos.length/3;for(const[ae,re]of[[U,Z],[k,Z],[k,$],[U,$]]){const ee=b+(v+ae)*u,ce=S+re*u;this.pos.push(t.x+ee*p-ce*x,t.y+ee*x+ce*p,1),this.emuv.push(ae,re),this.gbase.push(I.base),this.color.push(m,g,M)}this.index.push(D,D+1,D+2,D,D+2,D+3)}v+=I.advance}}}build(){if(!this.index.length)return null;const e=new wt;e.setAttribute("position",new ht(this.pos,3)),e.setAttribute("emuv",new ht(this.emuv,2)),e.setAttribute("gbase",new ht(this.gbase,1)),e.setAttribute("tcolor",new ht(this.color,3)),e.setIndex(this.index);const t=new In({glslVersion:uc,vertexShader:r2,fragmentShader:a2,uniforms:{dataTex:{value:this.engine.texture()}},transparent:!0,depthTest:!1,depthWrite:!1,side:zt}),i=new Gt(e,t);return i.frustumCulled=!0,i}}const vl=13226457,l2=64,vf=72,c2=14;function Fs(n){return n?n.replace(/\\A\d+;/g,"").replace(/\\p[^;]*;/g,"").replace(/\\P/g,`
|
|
`).replace(/\\[a-zA-Z][^;]*;/g,"").replace(/\{[^{}]*\}/g,e=>Fs(e.slice(1,-1))).replace(/%%d/gi,"°").replace(/%%p/gi,"±").replace(/%%c/gi,"Ø").replace(/[{}]/g,"").replace(/[ \t]{2,}/g," ").replace(/^[ \t]+|[ \t]+$/gm,"").replace(/\n{3,}/g,`
|
|
|
|
`).replace(/^\n+|\n+$/g,""):""}class u2{constructor(e){this._container=e,this._entityMeta=[],this._layerByHandle=new Map,this._layerByName=new Map,this._onSelectCb=null,this._measureActive=!1,this._measureCb=null,this._measurePtA=null,this._measureMarkers=[],this._textGen=0,Ir.shared().catch(()=>{}),this._scene=new Ym,this._scene.background=new et(856343);const t=e.clientWidth||800,i=e.clientHeight||600;this._camera=new Gc(-t/2,t/2,i/2,-i/2,-1e4,1e4),this._camera.position.set(0,0,100),this._renderer=new z_({antialias:!0,preserveDrawingBuffer:!0}),this._renderer.setPixelRatio(window.devicePixelRatio),this._renderer.setSize(t,i),e.appendChild(this._renderer.domElement),this._controls=new V_(this._camera,this._renderer.domElement),this._controls.enableRotate=!1,this._controls.screenSpacePanning=!0,this._controls.zoomToCursor=!0,this._controls.mouseButtons={LEFT:ui.PAN,MIDDLE:ui.PAN,RIGHT:ui.PAN},this._controls.touches={ONE:Li.PAN,TWO:Li.DOLLY_PAN};const s=localStorage.getItem("hmw:zoom-speed");if(s){const r=parseFloat(s);isNaN(r)||(this._controls.zoomSpeed=r)}window.addEventListener("keydown",r=>{(r.key==="f"||r.key==="F")&&this.fit()}),this._group=new gr,this._scene.add(this._group),window.addEventListener("resize",()=>this._onResize()),this._renderer.domElement.addEventListener("pointerdown",r=>{r.button===1&&r.preventDefault()}),this._renderer.domElement.addEventListener("mousedown",r=>{this._downXY=[r.clientX,r.clientY],r.button===1&&r.preventDefault()}),this._renderer.domElement.addEventListener("click",r=>this._onClick(r)),this._renderer.domElement.addEventListener("pointermove",r=>this._onPointerMove(r)),this._renderer.domElement.addEventListener("pointerleave",()=>{this._onPointerWorldCb&&this._onPointerWorldCb(null)}),this._selColor={r:216/255,g:58/255,b:47/255},this._gridVisible=!1,this._gridMesh=null,this._activeSpaceHex=null,this._onPointerWorldCb=null,this._ptrWorldTmp=new B,this._coordOrigin={x:0,y:0,z:0},this._coordXAxis={x:1,y:0,z:0},this._coordYAxis={x:0,y:1,z:0},this._controls.addEventListener("change",()=>{this._gridVisible&&this._rebuildGrid()}),this._animate()}onSelect(e){this._onSelectCb=e}resize(){this._onResize()}setZoomSpeed(e){this._controls&&(this._controls.zoomSpeed=e)}getZoomSpeed(){return this._controls?this._controls.zoomSpeed:1}onPointerWorld(e){this._onPointerWorldCb=e||null}screenToWorld(e,t){const i=this._screenToWcs(e,t);return i?this._wcsToCad(i.x,i.y):null}_screenToWcs(e,t){var M,E,_,T,b;const i=(M=this._renderer)==null?void 0:M.domElement,s=this._camera;if(!i||!s)return null;const r=i.getBoundingClientRect();if(r.width<1||r.height<1)return null;s.updateMatrixWorld(!0);const a=(e-r.left)/r.width*2-1,o=-((t-r.top)/r.height)*2+1,l=s.zoom||1,c=(s.right-s.left)*.5/l,u=(s.top-s.bottom)*.5/l,f=s.matrixWorld.elements,h=f[0],d=f[1],p=f[4],x=f[5],m=((_=(E=this._controls)==null?void 0:E.target)==null?void 0:_.x)??s.position.x,g=((b=(T=this._controls)==null?void 0:T.target)==null?void 0:b.y)??s.position.y;return{x:m+a*c*h+o*u*p,y:g+a*c*d+o*u*x,z:0}}_wcsToCad(e,t){const i=this._coordOrigin||{x:0,y:0},s=this._coordXAxis||{x:1,y:0},r=this._coordYAxis||{x:0,y:1},a=e-(i.x||0),o=t-(i.y||0);return{x:a*(s.x||0)+o*(s.y||0),y:a*(r.x||0)+o*(r.y||0),z:0}}_setCoordFrame(e){const i=Sr(e).find(r=>r.handleHex===this._activeSpaceHex),s=(e==null?void 0:e.vars)||{};(i==null?void 0:i.kind)==="model"&&s.ucsOrigin?(this._coordOrigin={x:s.ucsOrigin.x||0,y:s.ucsOrigin.y||0,z:s.ucsOrigin.z||0},this._coordXAxis=s.ucsXAxis||{x:1,y:0,z:0},this._coordYAxis=s.ucsYAxis||{x:0,y:1,z:0}):(this._coordOrigin={x:0,y:0,z:0},this._coordXAxis={x:1,y:0,z:0},this._coordYAxis={x:0,y:1,z:0})}_onPointerMove(e){if(!this._onPointerWorldCb)return;const t=this.screenToWorld(e.clientX,e.clientY);this._onPointerWorldCb(t)}fit(){if(this._contentBox&&!this._contentBox.isEmpty()){this._fit(this._contentBox);return}const e=new Oi,t=[];if(this._group.traverse(s=>{var l;if(!s.geometry)return;e.expandByObject(s);const r=(l=s.geometry.attributes)==null?void 0:l.position;if(!(r!=null&&r.array))return;const a=r.array,o=Math.max(3,Math.floor(a.length/3/4e3)*3);for(let c=0;c+1<a.length;c+=o)Number.isFinite(a[c])&&Number.isFinite(a[c+1])&&t.push(a[c],a[c+1])}),e.isEmpty())return;const i=this._trimmedContentBox(t,e)||e;this._contentBox=i.clone(),this._fit(i)}load(e,t={}){var I,L,C,O,N,U,Z,k,$,D,ae,re,ee,ce,he,fe,X,se,Q,ye,ve,_e,Ze,Ye,Oe,Fe,Ve,at,ot,pt,vt,ct,ut;if(this._lastResult=e,this._selMeta=null,this._clear(),this._entityMeta=[],this._buildLayerMap((I=e==null?void 0:e.tables)==null?void 0:I.layers),this._buildLinetypeMap(e),this._viewTwist=this._readViewTwist(e),this._pickSegs=[],this._pickSegMeta=[],this._pickFills=[],this._pickCurIdx=-1,Object.prototype.hasOwnProperty.call(t,"spaceHandle")){const R=t.spaceHandle;R==null||R===""?this._activeSpaceHex=null:this._activeSpaceHex=typeof R=="number"?R.toString(16):String(R).toLowerCase()}const i=(e==null?void 0:e.entities)||[],s=[],r=[],a=new Map;let o=null;const l=new Oi,c=new B,u=[],f=new Set,h=new Set,d=new Map,p=new Map;for(const R of((L=e==null?void 0:e.tables)==null?void 0:L.blocks)??[]){const Ae=(R.name??"").toLowerCase().replace(/\*/g,"").trim(),W=typeof R.handle=="object"?(O=(C=R.handle)==null?void 0:C.value)==null?void 0:O.toString(16):(N=R.handle)==null?void 0:N.toString(16);W&&(R.basePoint&&d.set(W,R.basePoint),p.set(W,(R.name??"").toLowerCase()),Ae==="model_space"||Ae==="paper_space"||Ae==="ms"||Ae==="ps"||Ae.startsWith("model")||Ae.startsWith("paper")||Ae===""?h.add(W):f.add(W))}const x=h.size>0;this._blockCount=f.size,this._activeSpaceHex&&h.size&&!h.has(this._activeSpaceHex)&&(this._activeSpaceHex=null);const m=this._activeSpaceHex?ol(i,this._activeSpaceHex):null,g=new Map;for(const R of i){const Ae=(Z=(U=R.ownerHandle)==null?void 0:U.value)==null?void 0:Z.toString(16);Ae!=null&&(g.has(Ae)||g.set(Ae,[]),g.get(Ae).push(R))}const M=[];let E=0;const _=(R,Ae,W=0)=>{!Number.isFinite(R)||!Number.isFinite(Ae)||(l.expandByPoint(c.set(R,Ae,W)),E++,!(E&7)&&M.length<1e5&&M.push(R,Ae))},T=(R,Ae,W,P,y,H)=>{const F=(H>>16&255)/255,G=(H>>8&255)/255,te=(H&255)/255;if(o){let oe=a.get(o.key);oe||(oe={dash:o.dash,gap:o.gap,verts:[],colors:[]},a.set(o.key,oe)),oe.verts.push(R,Ae,y,W,P,y),oe.colors.push(F,G,te,F,G,te)}else s.push(R,Ae,y,W,P,y),r.push(F,G,te,F,G,te);this._pickCurIdx>=0&&(this._pickSegs.push(R,Ae,W,P),this._pickSegMeta.push(this._pickCurIdx)),_(R,Ae,y),_(W,P,y)},b=-1,S=Sr(e),v=S.find(R=>R.handleHex===this._activeSpaceHex);if((v==null?void 0:v.kind)==="paper"){const R=S.find(Ae=>Ae.kind==="model");if(R){const Ae=ol(i,R.handleHex),W=i.filter(H=>{var G,te;return(H.type||H.typeName||"").toUpperCase()!=="VIEWPORT"?!1:((te=(G=H.ownerHandle)==null?void 0:G.value)==null?void 0:te.toString(16))===this._activeSpaceHex&&this._isModelViewport(H)}),P=(H,F,G,te,oe,V)=>{T(H,F,G,te,b,V)},y=(H,F,G=0)=>_(H,F,b);for(const H of W)this._emitModelThroughViewport(H,{entities:i,modelAllowed:Ae,blockDefHandles:f,entsByOwner:g,blockBaseByHex:d,blockNameByHex:p,pushSeg:P,expand:y,pendingTexts:u,box:l,_tmp:c,underlay:!0})}}for(const R of i){const Ae=($=(k=R.ownerHandle)==null?void 0:k.value)==null?void 0:$.toString(16);if(x&&Ae&&f.has(Ae)||m&&Ae&&!m.has(Ae))continue;if((D=this._hiddenLayers)!=null&&D.size){const F=((ae=R.layerHandle)==null?void 0:ae.value)??R.layerHandle,G=(F!=null&&this._layerNameByHandle.get(String(F)))??R.layer??R.layerName;if(G&&this._hiddenLayers.has(G))continue}const W=R.data||R,P=(R.type||R.typeName||"").toUpperCase(),y=this._entityColor(R);o=this._resolveDash(R);const H={entity:R,type:P,bounds:null,colStart:r.length};this._entityMeta.push(H),this._pickCurIdx=this._entityMeta.length-1;try{switch(P){case"LINE":W.start&&W.end&&(T(W.start.x,W.start.y,W.end.x,W.end.y,W.start.z||0,y),H.bounds={type:"line",x1:W.start.x,y1:W.start.y,x2:W.end.x,y2:W.end.y});break;case"CIRCLE":W.center&&W.radius!=null&&(this._arcSegs(W.center,W.radius,0,Math.PI*2,W.center.z||0,y,T),H.bounds={type:"circle",cx:W.center.x,cy:W.center.y,r:W.radius});break;case"ARC":W.center&&W.radius!=null&&(this._arcSegs(W.center,W.radius,W.startAngle??0,W.endAngle??Math.PI*2,W.center.z||0,y,T),H.bounds={type:"circle",cx:W.center.x,cy:W.center.y,r:W.radius});break;case"LWPOLYLINE":if((re=W.points)!=null&&re.length){const F=(ee=W.bulges)==null?void 0:ee.some(oe=>Math.abs(oe)>=1e-6),G=!!(W.closed||W.flags&1),te=G?W.points.length:W.points.length-1;this._polyHasWidth(R,te,1)?this._widePolyMesh(W.points,W.bulges,G,R,y,1,_):F?this._bulgePolySegs(W.points,W.bulges,G,y,T,_):(this._polylineSegs(W.points,G,W.elevation||0,y,T),W.points.forEach(oe=>_(oe.x,oe.y,W.elevation||0))),H.bounds={type:"point",cx:W.points[0].x,cy:W.points[0].y}}break;case"POLYLINE":this._polylineSegs(W.vertices||W.points,W.closed||W.flags&1,0,y,T);break;case"POLYLINE_2D":{const F=(g.get((he=(ce=R.handle)==null?void 0:ce.value)==null?void 0:he.toString(16))??[]).filter(G=>(G.type||"").toUpperCase().startsWith("VERTEX")&&G.point);if(F.length>=2){const G=F.map(K=>K.point),te=F.map(K=>K.bulge||0),oe=(W.flags&1)===1,V=W.elevation||0;te.some(K=>Math.abs(K)>=1e-6)?this._bulgePolySegs(G,te,oe,y,T,_):(this._polylineSegs(G,oe,V,y,T),G.forEach(K=>_(K.x,K.y,V))),H.bounds={type:"point",cx:G[0].x,cy:G[0].y}}break}case"POINT":{const F=W.position||W;typeof F.x=="number"&&(T(F.x-1,F.y,F.x+1,F.y,F.z||0,y),T(F.x,F.y-1,F.x,F.y+1,F.z||0,y),H.bounds={type:"point",cx:F.x,cy:F.y});break}case"ELLIPSE":W.center&&(this._ellipseSegs(W,y,T),H.bounds={type:"point",cx:W.center.x,cy:W.center.y});break;case"SPLINE":{const F=W.controlPoints??W.fitPoints;if((F==null?void 0:F.length)>=2){const G=F.length>=3?(()=>{const te=F.length*10,oe=[];for(let V=0;V<=te;V++){const K=V/te;oe.push(this._catmullRom(F,K))}return oe})():F;this._polylineSegs(G,!1,0,y,T),G.forEach(te=>_(te.x,te.y,te.z||0)),H.bounds={type:"point",cx:G[0].x,cy:G[0].y}}break}case"ATTRIB":case"ATTDEF":{if((W.flags??0)&1)break;const F=R.text??W.text??W.textValue??W.defaultValue??"",G=Fs(F),te=R.textHeight??R.height??W.textHeight??W.height??2.5,oe=R.rotationAngle??W.rotationAngle??0,V=R.horizAlignment??W.horizAlignment??0,K=R.vertAlignment??W.vertAlignment??0,de=V!==0||K!==0?R.alignmentPt??W.alignmentPt??R.insertionPt??W.insertionPt??W.insertionPoint??{x:0,y:0}:R.insertionPt??W.insertionPt??W.insertionPoint??{x:0,y:0};G&&(u.push({text:G,pos:de,height:te,rotation:oe,color:y,alignH:V,alignV:2}),H.bounds={type:"point",cx:de.x,cy:de.y},this._addTextPick(G,de,te,V,2),_(de.x,de.y,0));break}case"XLINE":case"RAY":{const F=W.basePoint??W.point??W.startPoint,G=W.direction??W.unitDir??W.vector;if(F&&G){const oe=F.x+G.x*1e6,V=F.y+G.y*1e6;P==="XLINE"?T(F.x-G.x*1e6,F.y-G.y*1e6,oe,V,0,y):T(F.x,F.y,oe,V,0,y),H.bounds={type:"point",cx:F.x,cy:F.y},_(F.x,F.y)}break}case"SOLID":{const F=[W.corner1||W.pt1||W.point1,W.corner2||W.pt2||W.point2,W.corner3||W.pt3||W.point3,W.corner4||W.pt4||W.point4].filter(Boolean);F.length>=3&&(this._solidMesh(F,y),H.bounds={type:"point",cx:F[0].x,cy:F[0].y});break}case"TEXT":case"MTEXT":{const F=R.text??W.text??"",G=Fs(F),te=R.textHeight??R.height??W.textHeight??W.height??2.5;let oe=0,V=0,K=0,ie;if(P==="TEXT")oe=R.rotationAngle??W.rotationAngle??0,V=R.horizAlignment??W.horizAlignment??0,K=R.vertAlignment??W.vertAlignment??0,V===4&&(K=2),ie=V!==0||K!==0?R.alignmentPt??W.alignmentPt??R.insertionPt??W.insertionPt??{x:0,y:0}:R.insertionPt??W.insertionPt??W.insertionPoint??{x:0,y:0};else{const de=R.xAxisDir??W.xAxisDir;de&&(oe=Math.atan2(de.y,de.x));const pe=R.attachment??W.attachment??R.attachmentPoint??W.attachmentPoint??5;V=[1,4,7].includes(pe)?0:[3,6,9].includes(pe)?2:1,K=[1,2,3].includes(pe)?3:[7,8,9].includes(pe)?1:2,ie=R.insertionPt??W.insertionPt??W.insertionPoint??{x:0,y:0}}if(G){const de={text:G,pos:ie,height:te,rotation:oe,color:y,alignH:V,alignV:K};P==="MTEXT"&&(de.linespacingFactor=R.linespacingFactor??W.linespacingFactor??1,de.rectWidth=R.rectWidth??W.rectWidth??0,de.rectHeight=R.rectHeight??W.rectHeight??0,de.bgFillFlags=R.bgFillFlags??W.bgFillFlags??0,de.bgScale=R.bgScale??W.bgScale??1.5,de.bgColorIndex=R.bgColorIndex??W.bgColorIndex,de.bgColorRgb=R.bgColorRgb??W.bgColorRgb),u.push(de),H.bounds={type:"point",cx:ie.x,cy:ie.y},this._addTextPick(G,ie,te,V,K),_(ie.x,ie.y,0)}break}case"INSERT":{const F=R.insertionPt??W.insertionPt??W.insertionPoint,G=W.scaleX??((fe=W.scale)==null?void 0:fe.x)??((X=R.scale)==null?void 0:X.x)??1,te=W.scaleY??((se=W.scale)==null?void 0:se.y)??((Q=R.scale)==null?void 0:Q.y)??1,oe=W.rotation??R.rotation??0,V=((ye=R.blockHeaderHandle)==null?void 0:ye.value)??((ve=W.blockHeaderHandle)==null?void 0:ve.value);if(V!=null){const K=V.toString(16),ie=g.get(K)??[];if(ie.length>0){const de=(Ze=(_e=e==null?void 0:e.tables)==null?void 0:_e.blocks)==null?void 0:Ze.find(pe=>{var Me;return(typeof pe.handle=="object"?(Me=pe.handle)==null?void 0:Me.value:pe.handle)===V});this._insertEntities(ie,{insertionPoint:F??{x:0,y:0,z:0},xScale:G,yScale:te,rotation:oe,basePoint:de==null?void 0:de.basePoint},y,T,u,{entsByOwner:g,blockBase:d})}}F&&(H.bounds={type:"point",cx:F.x,cy:F.y},_(F.x,F.y,0));break}case"HATCH":{const F=W.paths??R.paths,G=W.solidFill??R.solidFill??!1;if(!(F!=null&&F.length))break;let te=null;for(const oe of F){if(!((Ye=oe.points)!=null&&Ye.length)||oe.points.length<2)continue;te||(te=oe.points[0]),((Oe=oe.bulges)==null?void 0:Oe.some(K=>Math.abs(K)>=1e-6))?this._bulgePolySegs(oe.points,oe.bulges,!0,y,T,_):(this._polylineSegs(oe.points,!0,0,y,T),oe.points.forEach(K=>_(K.x,K.y,0)))}G&&this._hatchFill(F,y),te&&(H.bounds={type:"point",cx:te.x,cy:te.y});break}case"DIMENSION":case"DIMENSION_LINEAR":case"DIMENSION_ALIGNED":case"DIMENSION_RADIUS":case"DIMENSION_DIAMETER":case"DIMENSION_ANG_3PT":case"DIMENSION_ANG_2LN":case"DIMENSION_ORDINATE":{const F=((Fe=R.blockHeaderHandle)==null?void 0:Fe.value)??((Ve=W.blockHeaderHandle)==null?void 0:Ve.value);let G=[];if(F!=null){const te=F.toString(16);G=g.get(te)??[]}if(G.length>0){for(const V of G){const K=(V.type||V.typeName||"").toUpperCase(),ie=V.data||V,de=this._entityColor(V)||y;if(K==="LINE"&&ie.start&&ie.end)T(ie.start.x,ie.start.y,ie.end.x,ie.end.y,0,de),_(ie.start.x,ie.start.y),_(ie.end.x,ie.end.y);else if(K==="SOLID"){const pe=[ie.corner1||ie.pt1,ie.corner2||ie.pt2,ie.corner3||ie.pt3,ie.corner4||ie.pt4].filter(Boolean);pe.length>=3&&(this._solidMesh(pe,de),pe.forEach(ge=>_(ge.x,ge.y)))}else if(K==="ARC"&&ie.center&&ie.radius!=null)this._arcSegs(ie.center,ie.radius,ie.startAngle??0,ie.endAngle??Math.PI*2,0,de,T);else if(K==="TEXT"||K==="MTEXT"){const pe=V.text??ie.text??ie.textValue??"",ge=Fs(pe),Me=V.insertionPt??ie.insertionPt??ie.insertionPoint??{x:0,y:0},He=ie.textHeight??ie.height??V.textHeight??2.5;ge&&(u.push({text:ge,pos:Me,height:He,rotation:ie.rotationAngle??0,color:de,alignH:1,alignV:2}),_(Me.x,Me.y))}else if(K==="INSERT"){const pe=V.insertionPt??ie.insertionPt??ie.insertionPoint??{x:0,y:0},ge=ie.rotation??V.rotation??0,Me=ie.scaleX??((at=ie.scale)==null?void 0:at.x)??((ot=V.scale)==null?void 0:ot.x)??1,He=ie.scaleY??((pt=ie.scale)==null?void 0:pt.y)??((vt=V.scale)==null?void 0:vt.y)??Me,qe=((ct=V.blockHeaderHandle)==null?void 0:ct.value)??((ut=ie.blockHeaderHandle)==null?void 0:ut.value),z=qe==null?void 0:qe.toString(16),xe=p.get(z)??"",le=z?g.get(z)??[]:[];xe.includes("dot")?this._dotMesh(pe,this._arrowDotRadius(le)*Math.abs(Me)||Math.abs(Me)*.5,de):le.length?this._insertEntities(le,{insertionPoint:pe,xScale:Me,yScale:He,rotation:ge,basePoint:d.get(z)},de,T,u,{entsByOwner:g,blockBase:d}):this._defaultArrow(xe,pe,ge,Math.abs(Me)||1,de,T),_(pe.x,pe.y)}}const te=G.find(V=>(V.type||V.typeName||"").toUpperCase()==="LINE"),oe=(te==null?void 0:te.data)||te;oe!=null&&oe.start&&(H.bounds={type:"point",cx:oe.start.x,cy:oe.start.y})}else{this._renderDimFallback(R,W,P,y,T,u,_);const te=R.pt10??W.pt10;te&&(H.bounds={type:"point",cx:te.x,cy:te.y},_(te.x,te.y))}break}case"LEADER":{const F=W.points??R.points;if((F==null?void 0:F.length)>=2){if(this._polylineSegs(F,!1,0,y,T),F.forEach(G=>_(G.x,G.y,G.z||0)),W.arrowheadOn??R.arrowheadOn??!0){const G=F[0],te=F[1],oe=Math.atan2(te.y-G.y,te.x-G.x),V=W.arrowSize??R.arrowSize??2.5;this._arrowMesh(G,oe,V,y)}H.bounds={type:"point",cx:F[0].x,cy:F[0].y}}break}case"OLE2FRAME":{const F=R.upperLeft??W.upperLeft??{x:0,y:0,z:0},G=R.lowerRight??W.lowerRight??{x:0,y:0,z:0},te=R.sourceApp??W.sourceApp??R.source_application??"",oe=R.imageDataUrl??W.imageDataUrl;let V=Math.min(F.x,G.x),K=Math.max(F.x,G.x),ie=Math.min(F.y,G.y),de=Math.max(F.y,G.y),pe=K-V,ge=de-ie;const Me=F.z||0;if(T(V,ie,K,ie,Me,y),T(K,ie,K,de,Me,y),T(K,de,V,de,Me,y),T(V,de,V,ie,Me,y),oe)try{const qe=(Ce=>{const ue=Ce.split(",")[1],ke=atob(ue),Le=new Uint8Array(ke.length);for(let vn=0;vn<ke.length;vn++)Le[vn]=ke.charCodeAt(vn);const yt=new DataView(Le.buffer);if(String.fromCharCode(Le[0],Le[1])!=="BM")throw new Error("Not a BMP file");const hn=yt.getUint32(10,!0),Ut=yt.getInt32(18,!0),Gr=yt.getInt32(22,!0),Vr=yt.getUint16(28,!0),ti=Math.abs(Gr),cs=Gr>0,us=document.createElement("canvas");us.width=Ut,us.height=ti;const tr=us.getContext("2d"),nr=tr.createImageData(Ut,ti),qt=nr.data;if(Vr===32){const vn=Ut*4;for(let an=0;an<ti;an++){const hs=cs?ti-1-an:an,xi=hn+hs*vn,fs=an*Ut*4;for(let on=0;on<Ut;on++){const Nn=xi+on*4,yn=fs+on*4;qt[yn]=Le[Nn+2],qt[yn+1]=Le[Nn+1],qt[yn+2]=Le[Nn],qt[yn+3]=255}}}else if(Vr===24){const vn=Math.ceil(Ut*3/4)*4;for(let an=0;an<ti;an++){const hs=cs?ti-1-an:an,xi=hn+hs*vn,fs=an*Ut*4;for(let on=0;on<Ut;on++){const Nn=xi+on*3,yn=fs+on*4;qt[yn]=Le[Nn+2],qt[yn+1]=Le[Nn+1],qt[yn+2]=Le[Nn],qt[yn+3]=255}}}return tr.putImageData(nr,0,0),us})(oe),z=new pa(qe);z.colorSpace=mn,z.needsUpdate=!0;const xe=new Qi(pe,Math.abs(ge)),le=new Vn({map:z,side:zt,transparent:!1}),be=new Gt(xe,le);be.position.set(V+pe/2,ie+Math.abs(ge)/2,Me+10),this._group.add(be),this._renderer.render(this._scene,this._camera)}catch(He){console.error("Failed rendering CanvasTexture for OLE image:",He)}else{T(V,ie,K,de,Me,y),T(V,de,K,ie,Me,y);const He=Math.abs(ge),qe=Math.max(Math.min(He*.05,300),40),z=te?`[OLE: ${te}]`:"[OLE2Frame]",xe={x:(V+K)/2,y:(ie+de)/2,z:Me};u.push({text:z,pos:xe,height:qe,rotation:0,color:y,alignH:1,alignV:2})}_(V,ie,Me),_(K,de,Me),H.bounds={type:"point",cx:(V+K)/2,cy:(ie+de)/2};break}case"VIEWPORT":break;default:break}}catch{}H.colEnd=r.length}if(u.length){const R=l.isEmpty()?new B(1,1,0):l.getSize(new B),Ae=Math.hypot(Math.max(R.x,1),Math.max(R.y,1)),W=[];for(const V of u){const K=V.height;K>0&&Number.isFinite(K)&&W.push(K)}W.sort((V,K)=>V-K);const P=W.length?W[W.length>>1]:2.5,y=Math.min(Ae*2e-4,P),H=2e4,F=u.filter(V=>V.underlay),G=u.filter(V=>!V.underlay),te=F.concat(G),oe=te.length>H?(console.warn(`텍스트 ${te.length}개 → ${H}개로 제한`),G.concat(F).sort((V,K)=>K.height-V.height).slice(0,H)):te;this._drawTexts(oe,y)}if(this._lineColorAttr=null,this._origColors=null,s.length){const R=new wt;R.setAttribute("position",new ht(s,3));const Ae=new ht(r,3);R.setAttribute("color",Ae),this._group.add(new da(R,new Ns({vertexColors:!0}))),this._lineColorAttr=Ae,this._origColors=Float32Array.from(Ae.array)}for(const R of a.values()){if(!R.verts.length)continue;const Ae=new wt;Ae.setAttribute("position",new ht(R.verts,3)),Ae.setAttribute("color",new ht(R.colors,3));const W=new da(Ae,new Gg({vertexColors:!0,dashSize:R.dash,gapSize:R.gap}));W.computeLineDistances(),this._group.add(W)}this._setCoordFrame(e);const w=l.isEmpty()?null:this._trimmedContentBox(M,l)||l;this._contentBox=w?w.clone():null,!t.keepView&&w&&!w.isEmpty()&&this._fit(w)}setTheme(e){this._scene.background=new et(e?658189:16250611),this._gridVisible&&this._rebuildGrid()}setGrid(e){this._gridVisible=e,e?this._rebuildGrid():this._gridMesh&&(this._scene.remove(this._gridMesh),this._gridMesh.geometry.dispose(),this._gridMesh.material.dispose(),this._gridMesh=null)}_rebuildGrid(){this._gridMesh&&(this._scene.remove(this._gridMesh),this._gridMesh.geometry.dispose(),this._gridMesh.material.dispose(),this._gridMesh=null);const e=this._camera.zoom||1,t=this._camera.position.x,i=this._camera.position.y,s=(this._camera.right-this._camera.left)/e/2,r=(this._camera.top-this._camera.bottom)/e/2,a=Math.max(s,r)*3,o=this._niceSpacing(Math.max(s,r)*2/20),[l,c,u,f]=[t-a,t+a,i-a,i+a],d=this._scene.background.r<.5?2829099:12303291,p=[];for(let m=Math.ceil(l/o)*o;m<=c;m+=o)p.push(m,u,-.5,m,f,-.5);for(let m=Math.ceil(u/o)*o;m<=f;m+=o)p.push(l,m,-.5,c,m,-.5);const x=new wt;x.setAttribute("position",new ht(p,3)),this._gridMesh=new da(x,new Ns({color:d})),this._scene.add(this._gridMesh)}_niceSpacing(e){if(e<=0)return 1;const t=Math.pow(10,Math.floor(Math.log10(e))),i=e/t;return(i<2?1:i<5?2:5)*t}getZoomPercent(){var e;return Math.round((((e=this._camera)==null?void 0:e.zoom)??1)*100)}onViewChange(e){var t;(t=this._controls)==null||t.addEventListener("change",e)}setHiddenLayers(e){this._hiddenLayers=e||new Set,this._lastResult&&this.load(this._lastResult,{keepView:!0})}getSpaces(){return Sr(this._lastResult)}getActiveSpace(){return this._activeSpaceHex}setSpace(e,t={}){e==null||e===""?this._activeSpaceHex=null:typeof e=="number"?this._activeSpaceHex=e.toString(16):this._activeSpaceHex=String(e).toLowerCase(),this._lastResult&&this.load(this._lastResult,{keepView:!!t.keepView,spaceHandle:this._activeSpaceHex})}_isModelViewport(e){if(!e||e.status&&e.status.isOn===!1||(e.id??0)===1)return!1;const i=Number(e.height)||0,s=Number(e.viewHeight)||0;if(i<=0||s<=0)return!1;const r=i/s,a=e.center||{},o=e.viewCenter||{},l=e.viewTarget||{},c=Math.hypot(l.x||0,l.y||0)<.001,u=Math.hypot((o.x||0)-(a.x||0),(o.y||0)-(a.y||0))<Math.max(i,1)*.05;return!(Math.abs(r-1)<.03&&c&&u)}_viewportModelToPaper(e){const t=e.center||{x:0,y:0},i=e.viewCenter||{x:0,y:0},s=e.viewTarget||{x:0,y:0},r=Number(e.height)||1,a=Number(e.viewHeight)>1e-12?Number(e.viewHeight):r,o=r/a,l=Number(e.twistAngle)||0,c=Math.cos(l),u=Math.sin(l),f=(h,d)=>{const p=h-(s.x||0),x=d-(s.y||0),m=c*p-u*x,g=u*p+c*x;return{x:(t.x||0)+(m-(i.x||0))*o,y:(t.y||0)+(g-(i.y||0))*o}};return f.scale=o,f.twist=l,f}_viewportPaperClip(e){const t=e.center||{x:0,y:0},i=(Number(e.width)||0)/2,s=(Number(e.height)||0)/2,r=Math.max(i,s)*1e-6;return{minX:(t.x||0)-i-r,maxX:(t.x||0)+i+r,minY:(t.y||0)-s-r,maxY:(t.y||0)+s+r}}_clipSegToRect(e,t,i,s,r,a){const h=(x,m)=>{let g=0;return x<r.minX?g|=1:x>r.maxX&&(g|=2),m<r.minY?g|=4:m>r.maxY&&(g|=8),g};let d=h(e,t),p=h(i,s);for(;;){if(!(d|p)){a(e,t,i,s);return}if(d&p)return;const x=d||p;let m=0,g=0;x&8?(m=e+(i-e)*(r.maxY-t)/(s-t||1e-30),g=r.maxY):x&4?(m=e+(i-e)*(r.minY-t)/(s-t||1e-30),g=r.minY):x&2?(g=t+(s-t)*(r.maxX-e)/(i-e||1e-30),m=r.maxX):(g=t+(s-t)*(r.minX-e)/(i-e||1e-30),m=r.minX),x===d?(e=m,t=g,d=h(e,t)):(i=m,s=g,p=h(i,s))}}_emitModelThroughViewport(e,t){var E,_,T,b,S,v,w,I,L,C,O,N,U,Z;const{entities:i,modelAllowed:s,blockDefHandles:r,entsByOwner:a,blockBaseByHex:o,pushSeg:l,expand:c,pendingTexts:u,underlay:f=!1}=t,h=this._viewportModelToPaper(e),d=this._viewportPaperClip(e),p=h.scale||1,x=new Set((e.frozenLayers||[]).map(k=>String(k))),m=(k,$,D,ae,re,ee)=>{const ce=h(k,$),he=h(D,ae);this._clipSegToRect(ce.x,ce.y,he.x,he.y,d,(fe,X,se,Q)=>{l(fe,X,se,Q,re||0,ee)})},g=(k,$,D=0)=>{const ae=h(k,$);ae.x>=d.minX&&ae.x<=d.maxX&&ae.y>=d.minY&&ae.y<=d.maxY&&c(ae.x,ae.y,D)},M=(k,$)=>k>=d.minX&&k<=d.maxX&&$>=d.minY&&$<=d.maxY;for(const k of i){const $=(_=(E=k.ownerHandle)==null?void 0:E.value)==null?void 0:_.toString(16);if(!$||!s.has($)||r.has($))continue;if((T=this._hiddenLayers)!=null&&T.size){const ee=((b=k.layerHandle)==null?void 0:b.value)??k.layerHandle,ce=(ee!=null&&this._layerNameByHandle.get(String(ee)))??k.layer??k.layerName;if(ce&&this._hiddenLayers.has(ce))continue}if(x.size){const ee=(S=k.layerHandle)==null?void 0:S.value;if(ee!=null&&x.has(String(ee)))continue}const D=k.data||k,ae=(k.type||k.typeName||"").toUpperCase(),re=this._entityColor(k);try{switch(ae){case"LINE":D.start&&D.end&&m(D.start.x,D.start.y,D.end.x,D.end.y,D.start.z||0,re);break;case"CIRCLE":D.center&&D.radius!=null&&this._arcSegs(D.center,D.radius,0,Math.PI*2,D.center.z||0,re,m);break;case"ARC":D.center&&D.radius!=null&&this._arcSegs(D.center,D.radius,D.startAngle??0,D.endAngle??Math.PI*2,D.center.z||0,re,m);break;case"LWPOLYLINE":if((v=D.points)!=null&&v.length){const ee=(w=D.bulges)==null?void 0:w.some(he=>Math.abs(he)>=1e-6),ce=!!(D.closed||D.flags&1);ee?this._bulgePolySegs(D.points,D.bulges,ce,re,m,g):(this._polylineSegs(D.points,ce,D.elevation||0,re,m),D.points.forEach(he=>g(he.x,he.y,D.elevation||0)))}break;case"POLYLINE":this._polylineSegs(D.vertices||D.points,D.closed||D.flags&1,0,re,m);break;case"ELLIPSE":if(D.center)if(typeof this._ellipseSegs=="function")this._ellipseSegs(D,re,m);else{const ee=D.center.x,ce=D.center.y,he=D.smAxis||D.majorAxis||{x:D.radius||1,y:0},fe=D.axisRatio??D.minorAxisRatio??.5,X=D.startAngle??D.startParameter??0,se=D.endAngle??D.endParameter??Math.PI*2,Q=64;let ye,ve;for(let _e=0;_e<=Q;_e++){const Ze=X+(se-X)*(_e/Q),Ye=Math.cos(Ze),Oe=Math.sin(Ze),Fe=ee+he.x*Ye-he.y*fe*Oe,Ve=ce+he.y*Ye+he.x*fe*Oe;_e>0&&m(ye,ve,Fe,Ve,0,re),ye=Fe,ve=Ve}}break;case"SOLID":{const ee=[D.corner1||D.pt1,D.corner2||D.pt2,D.corner3||D.pt3,D.corner4||D.pt4].filter(Boolean);if(ee.length>=2)for(let ce=0;ce<ee.length;ce++){const he=ee[ce],fe=ee[(ce+1)%ee.length];he&&fe&&m(he.x,he.y,fe.x,fe.y,0,re)}break}case"HATCH":{const ee=D.paths||k.paths||[];for(const ce of ee){const he=ce.points||ce.vertices;if(!(he!=null&&he.length))continue;const fe=ce.closed!==!1,X=ce.bulges;X!=null&&X.some(se=>Math.abs(se)>=1e-6)?this._bulgePolySegs(he,X,fe,re,m,g):(this._polylineSegs(he,fe,0,re,m),he.forEach(se=>g(se.x,se.y)))}break}case"SPLINE":{const ee=(I=D.fitPoints)!=null&&I.length?D.fitPoints:D.controlPoints;(ee==null?void 0:ee.length)>=2&&this._polylineSegs(ee,!!D.closed,0,re,m);break}case"TEXT":case"MTEXT":{const ee=k.text??D.text??"",ce=Fs(ee);if(!ce)break;const he=(k.textHeight??k.height??D.textHeight??D.height??2.5)*p;let fe=(k.rotationAngle??D.rotationAngle??0)+(h.twist||0),X=0,se=0,Q;if(ae==="TEXT")X=k.horizAlignment??D.horizAlignment??0,se=k.vertAlignment??D.vertAlignment??0,X===4&&(se=2),Q=X!==0||se!==0?k.alignmentPt??D.alignmentPt??k.insertionPt??D.insertionPt??{x:0,y:0}:k.insertionPt??D.insertionPt??D.insertionPoint??{x:0,y:0};else{const ve=k.xAxisDir??D.xAxisDir;ve&&(fe=Math.atan2(ve.y,ve.x)+(h.twist||0));const _e=k.attachment??D.attachment??k.attachmentPoint??D.attachmentPoint??5;X=[1,4,7].includes(_e)?0:[3,6,9].includes(_e)?2:1,se=[1,2,3].includes(_e)?3:[7,8,9].includes(_e)?1:2,Q=k.insertionPt??D.insertionPt??D.insertionPoint??{x:0,y:0}}const ye=h(Q.x,Q.y);if(!M(ye.x,ye.y))break;u.push({text:ce,pos:ye,height:he,rotation:fe,color:re,alignH:X,alignV:se,underlay:!!f}),g(Q.x,Q.y);break}case"INSERT":{const ee=k.insertionPt??D.insertionPt??D.insertionPoint;if(!ee)break;const ce=D.scaleX??((L=D.scale)==null?void 0:L.x)??((C=k.scale)==null?void 0:C.x)??1,he=D.scaleY??((O=D.scale)==null?void 0:O.y)??((N=k.scale)==null?void 0:N.y)??1,fe=((U=k.blockHeaderHandle)==null?void 0:U.value)??((Z=D.blockHeaderHandle)==null?void 0:Z.value),X=fe!=null?fe.toString(16):null,se=X?a.get(X)??[]:[];if(se.length){const Q=u.length;this._insertEntities(se,{insertionPoint:ee,xScale:ce,yScale:he,rotation:D.rotation??k.rotation??0,basePoint:o.get(X)},re,m,u,{entsByOwner:a,blockBase:o});for(let ye=Q;ye<u.length;ye++){const ve=u[ye];if(!(ve!=null&&ve.pos))continue;const _e=h(ve.pos.x,ve.pos.y);ve.pos=_e,ve.height=(ve.height||2.5)*p,ve.rotation=(ve.rotation||0)+(h.twist||0),ve.underlay=!!f}}g(ee.x,ee.y);break}default:break}}catch{}}}getStats(){return{entities:this._entityMeta.length,blocks:this._blockCount??0}}snapshotWebPBlob(){return new Promise(e=>{this._renderer.render(this._scene,this._camera),this._renderer.domElement.toBlob(t=>e(t),"image/webp",.75)})}getLayerInfo(){var r,a,o,l,c;const e=this._lastResult;if(!e)return[];const t=new Map,i=this._activeSpaceHex?ol(e.entities||[],this._activeSpaceHex):null;for(const u of e.entities||[]){const f=(a=(r=u.ownerHandle)==null?void 0:r.value)==null?void 0:a.toString(16);if(i&&f&&!i.has(f))continue;const h=((o=u.layerHandle)==null?void 0:o.value)??u.layerHandle,d=(h!=null&&((l=this._layerNameByHandle)==null?void 0:l.get(String(h))))??u.layer??u.layerName??"0";t.set(d,(t.get(d)||0)+1)}const s=this._hiddenLayers||new Set;return(((c=e.tables)==null?void 0:c.layers)||[]).map(u=>{const f=u.name??u.layerName??"0",h=Math.abs(u.colorIndex??u.color??u.colorNumber??7);return{name:f,colorHex:"#"+(Sa(h)??vl).toString(16).padStart(6,"0"),count:t.get(f)||0,visible:!s.has(f)}}).filter(u=>u.count>0||!u.name.startsWith("*"))}_buildLayerMap(e){var t;if(this._layerByHandle.clear(),this._layerByName.clear(),this._layerNameByHandle=new Map,this._layer0Handle=null,!!e)for(const i of e){const s=((t=i.handle)==null?void 0:t.value)??i.handle,r=i.name??i.layerName,a=Math.abs(i.colorIndex??i.color??i.colorNumber??7),o=Sa(a)??vl;s!=null&&this._layerByHandle.set(String(s),o),r&&this._layerByName.set(r,o),s!=null&&r&&this._layerNameByHandle.set(String(s),r),r==="0"&&s!=null&&(this._layer0Handle=String(s))}}_readViewTwist(e){var r;const t=(r=e==null?void 0:e.tables)==null?void 0:r.vports;if(!Array.isArray(t)||!t.length)return 0;const i=t.find(a=>/active/i.test(a.name||""))||t[0],s=i==null?void 0:i.viewTwist;return typeof s=="number"&&isFinite(s)?s:0}_buildLinetypeMap(e){var t,i,s,r;this._ltPatterns=new Map,this._layerLtByName=new Map,this._layerLtByHandle=new Map,this._globalLtscale=((t=e==null?void 0:e.vars)==null?void 0:t.ltscale)>0?e.vars.ltscale:1;for(const a of((i=e==null?void 0:e.tables)==null?void 0:i.lineTypes)??[])a!=null&&a.name&&this._ltPatterns.set(a.name,Array.isArray(a.pattern)?a.pattern:[]);for(const a of((s=e==null?void 0:e.tables)==null?void 0:s.layers)??[]){const o=a.name??a.layerName,l=((r=a.handle)==null?void 0:r.value)??a.handle,c=a.lineType??a.linetype;o&&c&&this._layerLtByName.set(o,c),l!=null&&c&&this._layerLtByHandle.set(String(l),c)}}_resolveDash(e){var l,c;if(!this._ltPatterns||this._ltPatterns.size===0)return null;let t=e.lineType??e.linetype;if(!t||t==="ByLayer"||t==="BYLAYER"||t==="ByBlock"||t==="BYBLOCK"){const u=((l=e.layerHandle)==null?void 0:l.value)??e.layerHandle;t=u!=null&&this._layerLtByHandle.get(String(u))||this._layerLtByName.get(e.layer??e.layerName)||null}if(!t||t==="Continuous"||t==="ByLayer"||t==="ByBlock")return null;const i=this._ltPatterns.get(t);if(!i||i.length===0)return null;const s=((c=e.entityHeader)==null?void 0:c.linetypeScale)>0?e.entityHeader.linetypeScale:1,r=this._globalLtscale*s;let a=0,o=0;for(const u of i){const f=Math.abs(u)*r;u>1e-6?a+=f:u<-1e-6?o+=f:a+=Math.max(f,.01*r)}return a<1e-4||o<1e-4?null:{key:`${a.toFixed(3)}|${o.toFixed(3)}`,dash:a,gap:o}}_resolveBlockColor(e,t){var r,a;const i=((r=e.entityHeader)==null?void 0:r.colorIndex)??e.color??e.colorIndex??e.colorNumber??256;if(i===0)return t;const s=String(((a=e.layerHandle)==null?void 0:a.value)??e.layerHandle??"");return i===256&&this._layer0Handle&&s===this._layer0Handle?t:this._entityColor(e)}_entityColor(e){var r,a;const t=((r=e.entityHeader)==null?void 0:r.colorIndex)??e.color??e.colorIndex??e.colorNumber??256;if(t!=null){const o=Sa(t);if(o!==null)return o}const i=((a=e.layerHandle)==null?void 0:a.value)??e.layerHandle;if(i!=null){const o=this._layerByHandle.get(String(i));if(o!==void 0)return o}const s=e.layer??e.layerName;if(s){const o=this._layerByName.get(s);if(o!==void 0)return o}return vl}_arrowMesh(e,t,i,s){if(!e||i<1e-4)return;const r=i*.166,a=(s>>16&255)/255,o=(s>>8&255)/255,l=(s&255)/255,c=new wt;c.setAttribute("position",new ht([0,0,0,-i,r,0,-i,-r,0],3)),c.setAttribute("color",new ht([a,o,l,a,o,l,a,o,l],3));const u=new Gt(c,new Vn({vertexColors:!0,side:zt}));u.position.set(e.x,e.y,(e.z||0)+.5),u.rotation.z=t,this._group.add(u)}_defaultArrow(e,t,i,s,r,a){if(!t||s<1e-4)return;const o=(e||"").replace(/^[_*]+/,""),l=Math.cos(i),c=Math.sin(i),u=(f,h)=>({x:t.x+f*l-h*c,y:t.y+f*c+h*l});if(!(o==="none"||o==="small"||o==="integral")){if(o==="dot"||o==="dotsmall"||o==="dotblank"||o==="dotsmallblank"||o==="origin"||o==="origin2"){this._dotMesh(t,s*(o==="dotsmall"?.12:.5),r);return}if(o==="oblique"||o==="archtick"){const f=u(s*.5,s*.5),h=u(-s*.5,-s*.5);a(f.x,f.y,h.x,h.y,(t.z||0)+.5,r);return}if(o==="open"||o==="open30"||o==="open90"){const f=o==="open90"?s:s*.42,h=u(0,0),d=u(-s,f),p=u(-s,-f);a(d.x,d.y,h.x,h.y,(t.z||0)+.5,r),a(p.x,p.y,h.x,h.y,(t.z||0)+.5,r);return}this._arrowMesh(t,i,s,r)}}_dotMesh(e,t,i){if(!e||!(t>1e-5))return;const s=(i>>16&255)/255,r=(i>>8&255)/255,a=(i&255)/255,o=20,l=[],c=[],u=(e.z||0)+.5;for(let h=0;h<o;h++){const d=h/o*Math.PI*2,p=(h+1)/o*Math.PI*2;l.push(e.x,e.y,u,e.x+t*Math.cos(d),e.y+t*Math.sin(d),u,e.x+t*Math.cos(p),e.y+t*Math.sin(p),u),c.push(s,r,a,s,r,a,s,r,a)}const f=new wt;f.setAttribute("position",new ht(l,3)),f.setAttribute("color",new ht(c,3)),this._group.add(new Gt(f,new Vn({vertexColors:!0,side:zt})))}_arrowDotRadius(e){let t=0;for(const i of e||[]){const s=i.data||i;(i.type||"").toUpperCase()==="CIRCLE"&&s.radius&&(t=Math.max(t,s.radius));const r=s.points??s.vertices;if(r!=null&&r.length){let a=0,o=0;r.forEach(l=>{a+=l.x,o+=l.y}),a/=r.length,o/=r.length,r.forEach(l=>{t=Math.max(t,Math.hypot(l.x-a,l.y-o))})}}return t}_arcSegs(e,t,i,s,r,a,o){let l=s-i;l<=0&&(l+=Math.PI*2);const c=Math.max(8,Math.ceil(l/(Math.PI*2)*l2));let u=null;for(let f=0;f<=c;f++){const h=i+l*f/c,d=e.x+t*Math.cos(h),p=e.y+t*Math.sin(h);u&&o(u.x,u.y,d,p,r,a),u={x:d,y:p}}}_catmullRom(e,t){const i=e.length,s=t*(i-1),r=Math.min(Math.floor(s),i-2),a=s-r,o=e[Math.max(r-1,0)],l=e[r],c=e[r+1],u=e[Math.min(r+2,i-1)],f=a*a,h=f*a;return{x:.5*(2*l.x+(-o.x+c.x)*a+(2*o.x-5*l.x+4*c.x-u.x)*f+(-o.x+3*l.x-3*c.x+u.x)*h),y:.5*(2*l.y+(-o.y+c.y)*a+(2*o.y-5*l.y+4*c.y-u.y)*f+(-o.y+3*l.y-3*c.y+u.y)*h),z:.5*(2*(l.z||0)+(-(o.z||0)+(c.z||0))*a+(2*(o.z||0)-5*(l.z||0)+4*(c.z||0)-(u.z||0))*f+(-(o.z||0)+3*(l.z||0)-3*(c.z||0)+(u.z||0))*h)}}_ellipseSegs(e,t,i){const s=e.majorAxis??e.smAxis??{x:1,y:0},r=e.center,a=e.ratio??e.axisRatio??1,o=e.startParam??0,l=e.endParam??Math.PI*2,c=(s==null?void 0:s.x)??1,u=(s==null?void 0:s.y)??0,f=Math.sqrt(c*c+u*u),h=f*a,d=Math.atan2(u,c);let p=l-o;p<=0&&(p+=Math.PI*2);let x=null;for(let m=0;m<=vf;m++){const g=o+p*m/vf,M=f*Math.cos(g),E=h*Math.sin(g),_=r.x+M*Math.cos(d)-E*Math.sin(d),T=r.y+M*Math.sin(d)+E*Math.cos(d);x&&i(x.x,x.y,_,T,r.z||0,t),x={x:_,y:T}}}_polylineSegs(e,t,i,s,r){if(!(!e||e.length<2)){for(let a=0;a<e.length-1;a++)r(e[a].x,e[a].y,e[a+1].x,e[a+1].y,i,s);if(t){const a=e[e.length-1],o=e[0];r(a.x,a.y,o.x,o.y,i,s)}}}_segWidths(e,t,i=1){var h,d;const s=(e==null?void 0:e.data)||e||{},r=(s.constantWidth??s.constWidth??0)*i,a=(s.defaultStartWidth??0)*i,o=(s.defaultEndWidth??0)*i,l=(((h=s.startWidths)==null?void 0:h[t])??0)*i,c=(((d=s.endWidths)==null?void 0:d[t])??0)*i,u=Math.abs(l)>1e-12?l:Math.abs(r)>1e-12?r:a,f=Math.abs(c)>1e-12?c:Math.abs(r)>1e-12?r:o;return{sw:Math.abs(u),ew:Math.abs(f)}}_polyHasWidth(e,t,i=1){for(let s=0;s<t;s++){const{sw:r,ew:a}=this._segWidths(e,s,i);if(r>1e-9||a>1e-9)return!0}return!1}_pushWideSeg(e,t,i,s,r){const a=i.x-t.x,o=i.y-t.y,l=Math.hypot(a,o);if(l<1e-12)return;const c=-o/l,u=a/l,f=s*.5,h=r*.5,d={x:t.x+c*f,y:t.y+u*f},p={x:t.x-c*f,y:t.y-u*f},x={x:i.x-c*h,y:i.y-u*h},m={x:i.x+c*h,y:i.y+u*h};e.push(d.x,d.y,0,p.x,p.y,0,x.x,x.y,0),e.push(d.x,d.y,0,x.x,x.y,0,m.x,m.y,0)}_widePolyMesh(e,t,i,s,r,a=1,o=null){if(!e||e.length<2)return;const l=e.length,c=i?l:l-1,u=[];for(let d=0;d<c;d++){const p=e[d],x=e[(d+1)%l],{sw:m,ew:g}=this._segWidths(s,d,a);if(m<1e-9&&g<1e-9){this._pushWideSeg(u,p,x,.01*a,.01*a),o&&(o(p.x,p.y),o(x.x,x.y));continue}const M=(t==null?void 0:t[d])||0;if(Math.abs(M)<1e-6)this._pushWideSeg(u,p,x,m,g),o&&(o(p.x,p.y),o(x.x,x.y));else{const E=x.x-p.x,_=x.y-p.y,T=Math.hypot(E,_);if(T<1e-9)continue;const b=4*Math.atan(M),S=Math.abs(b)/2,v=T/2/Math.sin(S),w=v*Math.cos(S),I=(p.x+x.x)/2,L=(p.y+x.y)/2,C=-_/T,O=E/T,N=M>0?1:-1,U=I+N*C*w,Z=L+N*O*w,k=Math.atan2(p.y-Z,p.x-U),$=Math.max(2,Math.ceil(Math.abs(b)/(Math.PI/16)));let D={x:p.x,y:p.y},ae=m;for(let re=1;re<=$;re++){const ee=re/$,ce=k+b*re/$,he={x:U+v*Math.cos(ce),y:Z+v*Math.sin(ce)},fe=m+(g-m)*ee;this._pushWideSeg(u,D,he,ae,fe),D=he,ae=fe}o&&(o(p.x,p.y),o(x.x,x.y))}}if(u.length<9)return;const f=new wt;f.setAttribute("position",new ht(u,3)),f.computeVertexNormals();const h=new Vn({color:new et(r),side:zt,depthWrite:!1});if(this._group.add(new Gt(f,h)),this._pickCurIdx>=0&&this._pickSegs)for(let d=0;d<c;d++){const p=e[d],x=e[(d+1)%l];this._pickSegs.push(p.x,p.y,x.x,x.y),this._pickSegMeta.push(this._pickCurIdx)}}_bulgePolySegs(e,t,i,s,r,a){const o=e.length,l=i?o:o-1;for(let c=0;c<l;c++){const u=e[c],f=e[(c+1)%o],h=(t==null?void 0:t[c])||0;if(Math.abs(h)<1e-6)r(u.x,u.y,f.x,f.y,0,s),a&&(a(u.x,u.y),a(f.x,f.y));else{const d=f.x-u.x,p=f.y-u.y,x=Math.sqrt(d*d+p*p);if(x<1e-9)continue;const m=4*Math.atan(h),g=Math.abs(m)/2,M=x/2/Math.sin(g),E=M*Math.cos(g),_=(u.x+f.x)/2,T=(u.y+f.y)/2,b=-p/x,S=d/x,v=h>0?1:-1,w=_+v*b*E,I=T+v*S*E,L=Math.atan2(u.y-I,u.x-w),C=Math.max(2,Math.ceil(Math.abs(m)/(Math.PI/16)));let O=u;for(let N=1;N<=C;N++){const U=L+m*N/C,Z=w+M*Math.cos(U),k=I+M*Math.sin(U);r(O.x,O.y,Z,k,0,s),O={x:Z,y:k}}a&&(a(u.x,u.y),a(f.x,f.y))}}}_solidMesh(e,t){const i=(t>>16&255)/255,s=(t>>8&255)/255,r=(t&255)/255,a=[],o=[],l=(...u)=>{for(const f of u)a.push(f.x,f.y,f.z||0),o.push(i,s,r)};e.length>=4?(l(e[0],e[1],e[3]),l(e[0],e[3],e[2])):l(e[0],e[1],e[2]);const c=new wt;if(c.setAttribute("position",new ht(a,3)),c.setAttribute("color",new ht(o,3)),this._group.add(new Gt(c,new Vn({vertexColors:!0,side:zt}))),this._pickCurIdx>=0&&e.length>=3){const u=e.length>=4?[e[0],e[1],e[3],e[2]]:e.slice(0,3);this._pickFills.push({metaIdx:this._pickCurIdx,loops:[u]})}}_addTextPick(e,t,i,s=0,r=0){if(this._pickCurIdx<0||!t)return;const a=String(e).split(`
|
|
`),l=a.reduce((h,d)=>Math.max(h,d.length),1)*i*.62,c=a.length*i*1.2;let u=t.x;s===2?u=t.x-l:(s===1||s===4)&&(u=t.x-l/2);let f=t.y;r===3?f=t.y-c:r===2&&(f=t.y-c/2),this._pickFills.push({metaIdx:this._pickCurIdx,loops:[[{x:u,y:f},{x:u+l,y:f},{x:u+l,y:f+c},{x:u,y:f+c}]]})}_fillHit(e,t,i){let s=!1;for(const r of e)for(let a=0,o=r.length-1;a<r.length;o=a++){const l=r[a].x,c=r[a].y,u=r[o].x,f=r[o].y;c>i!=f>i&&t<(u-l)*(i-c)/(f-c)+l&&(s=!s)}return s}_pointInAnyLoop(e,t,i){for(const s of e){if(!(s!=null&&s.length))continue;let r=!1;for(let a=0,o=s.length-1;a<s.length;o=a++){const l=s[a],c=s[o];l.y>i!=c.y>i&&t<(c.x-l.x)*(i-l.y)/(c.y-l.y)+l.x&&(r=!r)}if(r)return!0}return!1}_loopArea(e){let t=0;for(let i=0;i<e.length;i++){const s=e[i],r=e[(i+1)%e.length];t+=s.x*r.y-r.x*s.y}return Math.abs(t)/2}_fillClosedPolyIfUncovered(e,t,i){if(!e||e.length<3)return;const s=e[0],r=e[e.length-1],a=Math.hypot(s.x-r.x,s.y-r.y);let o=1/0,l=1/0,c=-1/0,u=-1/0;for(const m of e)m.x<o&&(o=m.x),m.y<l&&(l=m.y),m.x>c&&(c=m.x),m.y>u&&(u=m.y);const f=Math.hypot(c-o,u-l)||1;if(a>f*1e-4&&a>1e-6)return;let h=0;for(let m=0;m<e.length;m++){const g=e[m],M=e[(m+1)%e.length];h+=g.x*M.y-M.x*g.y}const d=Math.abs(h)/2;if(d<1e-6||d>5e3)return;let p=0,x=0;for(const m of e)p+=m.x,x+=m.y;p/=e.length,x/=e.length;for(const m of this._pickFills)if(this._pointInAnyLoop(m.loops,p,x))return;this._hatchFill([{points:e,bulges:t||null,closed:!0}],i)}_pathPoints(e){const t=e.points;if(!(t!=null&&t.length))return null;const i=e.bulges,s=t.length;if(!(i!=null&&i.some(a=>Math.abs(a)>=1e-6)))return t.map(a=>({x:a.x,y:a.y}));const r=[];for(let a=0;a<s;a++){const o=t[a],l=t[(a+1)%s],c=i[a]||0;if(r.push({x:o.x,y:o.y}),Math.abs(c)<1e-6)continue;const u=l.x-o.x,f=l.y-o.y,h=Math.hypot(u,f);if(h<1e-9)continue;const d=4*Math.atan(c),p=Math.abs(d)/2,x=h/2/Math.sin(p),m=x*Math.cos(p),g=(o.x+l.x)/2,M=(o.y+l.y)/2,E=-f/h,_=u/h,T=c>0?1:-1,b=g+T*E*m,S=M+T*_*m,v=Math.atan2(o.y-S,o.x-b),w=Math.max(6,Math.ceil(Math.abs(d)/(Math.PI/16)));for(let I=1;I<w;I++){const L=v+d*I/w;r.push({x:b+x*Math.cos(L),y:S+x*Math.sin(L)})}}return r}_hatchFill(e,t){if(e.reduce((l,c)=>{var u;return l+(((u=c.points)==null?void 0:u.length)??0)},0)>8e3)return;let s=[];for(const l of e){const c=this._pathPoints(l);c&&c.length>=3&&s.push(c)}if(!s.length)return;const r=l=>{let c=0;for(let u=0;u<l.length;u++){const f=l[u],h=l[(u+1)%l.length];c+=f.x*h.y-h.x*f.y}return Math.abs(c)/2};if(e.some(l=>{var c;return!((c=l.points)!=null&&c.length)})&&s.length>=3||s.length>=5){const l=s.map(r).sort((u,f)=>u-f),c=l[Math.floor(l.length/2)]||0;if(c>0&&(s=s.filter(u=>r(u)<=c*10)),!s.length)return}if(this._pickCurIdx>=0&&s.length&&this._pickFills.push({metaIdx:this._pickCurIdx,loops:s}),s.length>=5||s.some(l=>this._polySelfIntersects(l))||this._hatchHasNestedLoop(s)){this._hatchFillEvenOddCanvas(s,t);return}const o=new Vn({color:new et(t),side:zt});for(const l of s)try{const c=new ud;c.moveTo(l[0].x,l[0].y);for(let u=1;u<l.length;u++)c.lineTo(l[u].x,l[u].y);c.closePath(),this._group.add(new Gt(new zc(c),o))}catch{}}_hatchHasNestedLoop(e){if(e.length<2)return!1;const t=o=>{let l=0;for(let c=0;c<o.length;c++){const u=o[c],f=o[(c+1)%o.length];l+=u.x*f.y-f.x*u.y}return Math.abs(l)/2},i=o=>{let l=1/0,c=1/0,u=-1/0,f=-1/0;for(const h of o)h.x<l&&(l=h.x),h.y<c&&(c=h.y),h.x>u&&(u=h.x),h.y>f&&(f=h.y);return{minX:l,minY:c,maxX:u,maxY:f}},s=(o,l)=>{let c=!1;for(let u=0,f=o.length-1;u<o.length;f=u++){const h=o[u],d=o[f];h.y>l.y!=d.y>l.y&&l.x<(d.x-h.x)*(l.y-h.y)/(d.y-h.y)+h.x&&(c=!c)}return c},r=e.map(t),a=e.map(i);for(let o=0;o<e.length;o++){let l=0,c=0;for(const u of e[o])l+=u.x,c+=u.y;l/=e[o].length,c/=e[o].length;for(let u=0;u<e.length;u++){if(o===u||r[u]<=r[o])continue;const f=a[u],h=a[o];if(f.minX<=h.minX&&f.minY<=h.minY&&f.maxX>=h.maxX&&f.maxY>=h.maxY||s(e[u],{x:l,y:c}))return!0}}return!1}_polySelfIntersects(e){const t=e.length;if(t<4)return!1;const i=(a,o,l)=>(o.x-a.x)*(l.y-a.y)-(o.y-a.y)*(l.x-a.x),s=(a,o,l,c)=>{const u=i(a,o,l),f=i(a,o,c),h=i(l,c,a),d=i(l,c,o);return(u>0&&f<0||u<0&&f>0)&&(h>0&&d<0||h<0&&d>0)},r=Math.min(t,80);for(let a=0;a<r;a++){const o=e[a],l=e[(a+1)%t];for(let c=a+2;c<r;c++)if(!(a===0&&c===t-1)&&c!==(a+t-1)%t&&s(o,l,e[c],e[(c+1)%t]))return!0}return!1}_isDiameterInflatedPath(e){if(!e||e.length<8)return!1;let t=1/0,i=1/0,s=-1/0,r=-1/0;for(const M of e)M.x<t&&(t=M.x),M.y<i&&(i=M.y),M.x>s&&(s=M.x),M.y>r&&(r=M.y);const a=s-t,o=r-i,l=Math.min(a,o);if(!(l>1e-9))return!1;const c=(t+s)/2,u=(i+r)/2,f=.55*l,h=.22*l;let d=0;for(let M=0;M<e.length;M++){const E=e[M],_=e[(M+1)%e.length];if(Math.hypot(_.x-E.x,_.y-E.y)<f)continue;const b=(E.x+_.x)/2,S=(E.y+_.y)/2;Math.hypot(b-c,S-u)<=h&&d++}if(!d)return!1;let p=0;for(let M=0;M<e.length;M++){const E=e[M],_=e[(M+1)%e.length];p+=E.x*_.y-_.x*E.y}const x=Math.abs(p)/2,m=this._convexHull(e);if(m.length<3)return!1;let g=0;for(let M=0;M<m.length;M++){const E=m[M],_=m[(M+1)%m.length];g+=E.x*_.y-_.x*E.y}return g=Math.abs(g)/2,g>1e-9&&x>g*1.15}_convexHull(e){const t=e.map(a=>({x:a.x,y:a.y})).sort((a,o)=>a.x-o.x||a.y-o.y);if(t.length<=2)return t;const i=(a,o,l)=>(o.x-a.x)*(l.y-a.y)-(o.y-a.y)*(l.x-a.x),s=[];for(const a of t){for(;s.length>=2&&i(s[s.length-2],s[s.length-1],a)<=0;)s.pop();s.push(a)}const r=[];for(let a=t.length-1;a>=0;a--){const o=t[a];for(;r.length>=2&&i(r[r.length-2],r[r.length-1],o)<=0;)r.pop();r.push(o)}return s.pop(),r.pop(),s.concat(r)}_polyCentroid(e){let t=0,i=0;for(const s of e)t+=s.x,i+=s.y;return{x:t/e.length,y:i/e.length}}_pointInPoly(e,t){let i=!1;for(let s=0,r=e.length-1;s<e.length;r=s++){const a=e[s],o=e[r];a.y>t.y!=o.y>t.y&&t.x<(o.x-a.x)*(t.y-a.y)/(o.y-a.y)+a.x&&(i=!i)}return i}_hatchFillEvenOddCanvas(e,t){let i=1/0,s=1/0,r=-1/0,a=-1/0;for(const C of e)for(const O of C)O.x<i&&(i=O.x),O.y<s&&(s=O.y),O.x>r&&(r=O.x),O.y>a&&(a=O.y);const o=r-i,l=a-s;if(!(o>1e-12)||!(l>1e-12))return;const c=2048,u=Math.min(c/o,c/l,64),f=Math.max(2,Math.ceil(o*u)+2),h=Math.max(2,Math.ceil(l*u)+2),d=(f-2)/o,p=(h-2)/l,x=document.createElement("canvas");x.width=f,x.height=h;const m=x.getContext("2d");if(!m)return;m.clearRect(0,0,f,h);const g=C=>({x:1+(C.x-i)*d,y:1+(a-C.y)*p}),M=C=>{if(C.length<3)return;const O=g(C[0]);m.moveTo(O.x,O.y);for(let N=1;N<C.length;N++){const U=g(C[N]);m.lineTo(U.x,U.y)}m.closePath()},E=[],_=[];for(const C of e)this._isDiameterInflatedPath(C)?E.push(C):_.push(C);const T=E.map(C=>this._convexHull(C)),b=C=>{if(C.length<3||!T.length)return!1;const O=this._polyCentroid(C);for(const N of T)if(N.length>=3&&this._pointInPoly(N,O))return!0;return!1};if(E.length){m.fillStyle="#ffffff",m.beginPath();for(const O of E)M(O);m.fill("nonzero");const C=_.filter(b);if(C.length){m.globalCompositeOperation="destination-out",m.beginPath();for(const O of C)M(O);m.fill("nonzero"),m.globalCompositeOperation="source-over"}}const S=_.filter(C=>!b(C));if(S.length){m.fillStyle="#ffffff",m.beginPath();for(const C of S)M(C);m.fill("evenodd")}const v=new pa(x);v.colorSpace=oi,v.magFilter=Xt,v.minFilter=Di,v.generateMipmaps=!0,v.needsUpdate=!0;const w=new Vn({map:v,color:new et(t),transparent:!0,alphaTest:.4,side:zt,depthWrite:!1}),I=new Qi(o,l),L=new Gt(I,w);L.position.set((i+r)/2,(s+a)/2,0),this._group.add(L)}_multilineSprite(e,t,i,s,r,a,o,l=0){const u="96px 'Malgun Gothic', 'Apple SD Gothic Neo', monospace",f=document.createElement("canvas"),h=f.getContext("2d");h.font=u;let d=1,p=96*.7,x=96*.2;for(const N of e){const U=h.measureText(N||" ");d=Math.max(d,Math.ceil(U.width)),p=Math.max(p,U.actualBoundingBoxAscent||96*.7),x=Math.max(x,U.actualBoundingBoxDescent||96*.2)}const m=Math.ceil(96*.15),g=Math.ceil(p+x+96*.35);f.width=d+m*2,f.height=g*e.length+m*2,h.font=u;const M=r>>16&255,E=r>>8&255,_=r&255;h.fillStyle=`rgb(${M},${E},${_})`,h.textBaseline="alphabetic";let T=m;a===1||a===4?(h.textAlign="center",T=f.width/2):a===2?(h.textAlign="right",T=f.width-m):(h.textAlign="left",T=m);for(let N=0;N<e.length;N++)h.fillText(e[N],T,m+p+N*g);const b=new pa(f),S=i/p,v=f.width*S,w=f.height*S;let I=0,L=0;a===0||a===3||a===5?I=v/2:a===2&&(I=-v/2),o===3?L=-w/2:(o===0||o===1)&&(L=w/2);const C=new fc({map:b,transparent:!0,depthTest:!1});s&&(C.rotation=s);const O=new Du(C);O.scale.set(v,w,1),O.position.set(t.x+I,t.y+L,1),O.renderOrder=l,this._group.add(O)}_drawMTextBackground(e,t,i){var L,C;const s=e.bgFillFlags|0;if(!s)return;const r=!!(s&1)||!!(s&2),a=!!(s&16);if(!r&&!a)return;const o=Math.max(e.height||2.5,i||0),l=String(e.text||"").split(`
|
|
`),c=e.linespacingFactor>0?e.linespacingFactor:1,u=o*(5/3)*c;let f=0;if(t!=null&&t.measureEm)for(const O of l)f=Math.max(f,t.measureEm(O||" "));else for(const O of l)f=Math.max(f,(O||" ").length*.9);let h=Math.max(f*o,o*.5),d=l.length<=1?o:o+(l.length-1)*u;e.rectWidth>0&&(h=Math.max(h,e.rectWidth)),e.rectHeight>0&&(d=Math.max(d,e.rectHeight));const p=e.bgScale>0?e.bgScale:1.5,x=h*p,m=d*p,g=e.alignH??1,M=e.alignV??2;let E=0,_=0;g===0||g===3||g===5?E=h/2:g===2&&(E=-h/2),M===3?_=-d/2:(M===0||M===1)&&(_=d/2);const T=e.rotation||0,b=Math.cos(T),S=Math.sin(T),v=e.pos.x+E*b-_*S,w=e.pos.y+E*S+_*b;let I=16776960;if(s&2)I=((C=(L=this._scene)==null?void 0:L.background)==null?void 0:C.r)<.5?658189:16250611;else if(e.bgColorRgb&&e.bgColorRgb.r!=null)I=(e.bgColorRgb.r&255)<<16|(e.bgColorRgb.g&255)<<8|e.bgColorRgb.b&255;else if(e.bgColorIndex!=null){const O=Sa(e.bgColorIndex);O!=null&&(I=O)}if(r){const O=new Qi(x,m),N=new Vn({color:new et(I),side:zt,depthWrite:!1,transparent:!1}),U=new Gt(O,N);U.position.set(v,w,.4),U.rotation.z=T,this._group.add(U)}if(a&&!r){const O=x/2,N=m/2,Z=[[-O,-N],[O,-N],[O,N],[-O,N],[-O,-N]].map(([k,$])=>({x:v+k*b-$*S,y:w+k*S+$*b}));for(let k=0;k<4;k++){const $=Z[k],D=Z[k+1];this._widePolyMesh([$,D],null,!1,{constantWidth:Math.max(o*.05,.01)},I,1,null)}}}async _drawTexts(e,t){const i=this._textGen,s=e.filter(o=>o.underlay),r=e.filter(o=>!o.underlay),a=[{list:s,order:0},{list:r,order:1}];try{const o=await Ir.shared();if(i!==this._textGen)return;for(const{list:l,order:c}of a){if(!l.length)continue;for(const h of l)h.bgFillFlags|0&&this._drawMTextBackground(h,o,t);const u=new o2(o);for(const h of l)u.add(h.text,h.pos,Math.max(h.height,t),h.rotation||0,h.color,h.alignH??0,h.alignV??0);const f=u.build();f&&(f.renderOrder=c,f.material&&(f.material.depthWrite=!1,f.material.transparent=!0),this._group.add(f))}}catch(o){if(console.warn("[Viewer2D] Slug text unavailable, falling back to canvas sprites:",(o==null?void 0:o.message)??o),i!==this._textGen)return;for(const{list:l,order:c}of a)for(const u of l)u.bgFillFlags|0&&this._drawMTextBackground(u,null,t),this._textSprite(u.text,u.pos,Math.max(u.height,t),u.rotation,u.color,u.alignH??0,u.alignV??0,c)}}_textSprite(e,t,i,s,r,a=0,o=0,l=0){const c=String(e).split(`
|
|
`);if(c.length>1){this._multilineSprite(c,t,i,s,r,a,o,l);return}const u=e+"\0"+r;let f=(this._texCache??(this._texCache=new Map)).get(u);if(!f){const v="96px 'Malgun Gothic', 'Apple SD Gothic Neo', monospace",w=document.createElement("canvas"),I=w.getContext("2d");I.font=v;const L=I.measureText(e),C=Math.max(1,Math.ceil(L.width)),O=L.actualBoundingBoxAscent||96*.7,N=L.actualBoundingBoxDescent||96*.2,U=Math.ceil(96*.15);w.width=C+U*2,w.height=Math.ceil(O+N)+U*2,I.font=v;const Z=r>>16&255,k=r>>8&255,$=r&255;I.fillStyle=`rgb(${Z},${k},${$})`,I.textBaseline="alphabetic",I.fillText(e,U,U+O),f={texture:new pa(w),w:w.width,h:w.height,asc:O,pad:U},this._texCache.set(u,f)}const{texture:h,asc:d,pad:p}=f,x=i*f.h/d,m=x*(f.w/f.h),g=x/f.h,M=f.h/2;let E=0;a===0||a===3||a===5?E=m/2:a===1||a===4?E=0:a===2&&(E=-m/2);let _=0;a!==4&&(o===0||o===1?_=(p+d-M)*g:o===3&&(_=(p-M)*g));const T=new fc({map:h,transparent:!0,depthTest:!1});s&&(T.rotation=s);const b=new Du(T);b.scale.set(m,x,1),b.position.set(t.x+E,t.y+_,1),b.renderOrder=l,this._group.add(b)}_insertEntities(e,t,i,s,r,a){var v,w,I,L,C,O,N,U,Z,k;const o=a==null?void 0:a.entsByOwner,l=a==null?void 0:a.blockBase,c=(a==null?void 0:a.parentXf)??null,u=(a==null?void 0:a.scale)??1,f=(a==null?void 0:a.rot)??0,h=(a==null?void 0:a.depth)??0,d=t.insertionPoint??{x:0,y:0},p=t.basePoint,x=t.xScale??1,m=t.yScale??1,g=t.rotation??0,M=Math.cos(g),E=Math.sin(g),_=($,D)=>{const ae=p?$-p.x:$,re=p?D-p.y:D;return[d.x+ae*x*M-re*m*E,d.y+ae*x*E+re*m*M]},T=c?($,D)=>c(..._($,D)):_,b=u*Math.max(Math.abs(x),Math.abs(m)),S=f+g;for(const $ of e){const D=$.data||$,ae=($.type||$.typeName||"").toUpperCase();if(ae==="ATTDEF")continue;const re=this._resolveBlockColor($,i);try{if(ae==="LINE"&&D.start&&D.end){const[ee,ce]=T(D.start.x,D.start.y),[he,fe]=T(D.end.x,D.end.y);s(ee,ce,he,fe,0,re)}else if((ae==="CIRCLE"||ae==="ARC")&&D.center&&D.radius!=null){const[ee,ce]=T(D.center.x,D.center.y),he=D.radius*b,fe=ae==="ARC"?(D.startAngle??0)+S:0,X=ae==="ARC"?(D.endAngle??Math.PI*2)+S:Math.PI*2;this._arcSegs({x:ee,y:ce,z:0},he,fe,X,0,re,s)}else if(ae==="ELLIPSE"&&D.center){const[ee,ce]=T(D.center.x,D.center.y),he=D.majorAxis??D.smAxis??{x:1,y:0},fe=Math.hypot(he.x??0,he.y??0)*b,X=Math.atan2(he.y??0,he.x??1)+S;this._ellipseSegs({center:{x:ee,y:ce,z:0},majorAxis:{x:fe*Math.cos(X),y:fe*Math.sin(X)},ratio:D.ratio??D.axisRatio??1,startParam:D.startParam??0,endParam:D.endParam??Math.PI*2},re,s)}else if((ae==="LWPOLYLINE"||ae==="POLYLINE")&&(D.points||D.vertices)){const ce=(D.points??D.vertices).map(se=>{const[Q,ye]=T(se.x,se.y);return{x:Q,y:ye}}),he=D.bulges??null,fe=!!(D.closed||D.flags&1);let X=!1;if(ce.length>=2&&this._pickFills.length){let se=0,Q=0,ye=1/0,ve=1/0,_e=-1/0,Ze=-1/0;for(const Fe of ce)se+=Fe.x,Q+=Fe.y,Fe.x<ye&&(ye=Fe.x),Fe.y<ve&&(ve=Fe.y),Fe.x>_e&&(_e=Fe.x),Fe.y>Ze&&(Ze=Fe.y);se/=ce.length,Q/=ce.length;const Ye=Math.max(_e-ye,1e-9),Oe=Math.max(Ze-ve,1e-9);for(const Fe of this._pickFills)if(this._pointInAnyLoop(Fe.loops,se,Q)){for(const Ve of Fe.loops){if(!(Ve!=null&&Ve.length))continue;let at=1/0,ot=1/0,pt=-1/0,vt=-1/0;for(const Ae of Ve)Ae.x<at&&(at=Ae.x),Ae.y<ot&&(ot=Ae.y),Ae.x>pt&&(pt=Ae.x),Ae.y>vt&&(vt=Ae.y);const ct=Math.max(pt-at,1e-9),ut=Math.max(vt-ot,1e-9);if(Ye<=ct*1.5&&Oe<=ut*1.5&&ct<=Ye*1.5&&ut<=Oe*1.5){X=!0;break}}if(X)break}}if(!X){const se=fe?ce.length:ce.length-1;this._polyHasWidth($,se,b)?this._widePolyMesh(ce,he,fe,$,re,b,null):(he!=null&&he.some(Q=>Math.abs(Q)>=1e-6)?this._bulgePolySegs(ce,he,fe,re,s):this._polylineSegs(ce,fe,0,re,s),this._fillClosedPolyIfUncovered(ce,he,re))}}else if(ae==="POLYLINE_2D"&&o){const ee=(o.get((w=(v=$.handle)==null?void 0:v.value)==null?void 0:w.toString(16))??[]).filter(ce=>(ce.type||"").toUpperCase().startsWith("VERTEX")&&ce.point);if(ee.length>=2){const ce=ee.map(X=>{const[se,Q]=T(X.point.x,X.point.y);return{x:se,y:Q}}),he=ee.map(X=>X.bulge||0),fe=(D.flags&1)===1;he.some(X=>Math.abs(X)>=1e-6)?this._bulgePolySegs(ce,he,fe,re,s):this._polylineSegs(ce,fe,0,re,s)}}else if(ae==="HATCH"){const ee=D.paths??$.paths;if(ee!=null&&ee.length){const ce=D.solidFill??$.solidFill??!1,he=ee.map(fe=>({...fe,points:(fe.points??[]).map(X=>{const[se,Q]=T(X.x,X.y);return{x:se,y:Q}})}));if(ce)this._hatchFill(he,re);else for(const fe of he)(((I=fe.points)==null?void 0:I.length)??0)<2||((L=fe.bulges)!=null&&L.some(X=>Math.abs(X)>=1e-6)?this._bulgePolySegs(fe.points,fe.bulges,!0,re,s):this._polylineSegs(fe.points,!0,0,re,s))}}else if(ae==="SOLID"){const ee=[D.corner1||D.pt1,D.corner2||D.pt2,D.corner3||D.pt3,D.corner4||D.pt4].filter(Boolean);if(ee.length>=3){const ce=ee.map(he=>{const[fe,X]=T(he.x,he.y);return{x:fe,y:X,z:he.z||0}});this._solidMesh(ce,re)}}else if(ae==="INSERT"&&o&&h<8){const ee=((C=$.blockHeaderHandle)==null?void 0:C.value)??((O=D.blockHeaderHandle)==null?void 0:O.value);if(ee!=null){const ce=ee.toString(16),he=o.get(ce)??[];if(he.length){const fe=$.insertionPt??D.insertionPt??D.insertionPoint??{x:0,y:0},X=D.scaleX??((N=D.scale)==null?void 0:N.x)??((U=$.scale)==null?void 0:U.x)??1,se=D.scaleY??((Z=D.scale)==null?void 0:Z.y)??((k=$.scale)==null?void 0:k.y)??1,Q=D.rotation??$.rotation??0;this._insertEntities(he,{insertionPoint:fe,xScale:X,yScale:se,rotation:Q,basePoint:l==null?void 0:l.get(ce)},re,s,r,{entsByOwner:o,blockBase:l,parentXf:T,scale:b,rot:S,depth:h+1})}}}else if((ae==="TEXT"||ae==="MTEXT"||ae==="ATTRIB"||ae==="ATTDEF")&&r){if((ae==="ATTRIB"||ae==="ATTDEF")&&(D.flags??0)&1)continue;const ee=$.text??D.text??D.textValue??D.defaultValue??"",ce=Fs(ee);let he,fe,X=(D.rotationAngle??0)+S;if(ae==="MTEXT"){const Oe=$.attachment??D.attachment??$.attachmentPoint??D.attachmentPoint??5;he=[1,4,7].includes(Oe)?0:[3,6,9].includes(Oe)?2:1,fe=[1,2,3].includes(Oe)?3:[7,8,9].includes(Oe)?1:2;const Fe=$.xAxisDir??D.xAxisDir;Fe&&(X=Math.atan2(Fe.y,Fe.x)+S)}else he=D.horizAlignment??$.horizAlignment??0,fe=D.vertAlignment??$.vertAlignment??0;const se=ae!=="MTEXT"&&(he!==0||fe!==0),Q=$.alignmentPt??D.alignmentPt,ye=$.insertionPt??D.insertionPt??D.insertionPoint,ve=se?Q??ye??{x:0,y:0}:ye??{x:0,y:0},[_e,Ze]=T(ve.x,ve.y),Ye=(D.textHeight??D.height??$.textHeight??2.5)*b;if(ce){const Oe={text:ce,pos:{x:_e,y:Ze},height:Ye,rotation:X,color:re,alignH:he,alignV:fe};ae==="MTEXT"&&(Oe.linespacingFactor=$.linespacingFactor??D.linespacingFactor??1,Oe.rectWidth=($.rectWidth??D.rectWidth??0)*b,Oe.rectHeight=($.rectHeight??D.rectHeight??0)*b,Oe.bgFillFlags=$.bgFillFlags??D.bgFillFlags??0,Oe.bgScale=$.bgScale??D.bgScale??1.5,Oe.bgColorIndex=$.bgColorIndex??D.bgColorIndex,Oe.bgColorRgb=$.bgColorRgb??D.bgColorRgb),r.push(Oe)}}}catch{}}}_renderDimFallback(e,t,i,s,r,a,o){const l=e.pt10??t.pt10,c=e.pt13??t.pt13,u=e.pt14??t.pt14,f=e.pt15??t.pt15,h=e.textMidPt??t.textMidPt,d=e.actualMeasurement??t.actualMeasurement??0,p=e.textRot??t.textRot??0,x=e.dimRot??t.dimRot??0,m=e.userText??t.userText??"",g=b=>Math.abs(b)<1?b.toFixed(3):b.toFixed(2),M=(b,S)=>{!b||!S||(r(b.x,b.y,S.x,S.y,0,s),o(b.x,b.y),o(S.x,S.y))},E=(b,S,v,w,I)=>{this._arcSegs({x:b,y:S},v,w,I,0,s,r)},_=(b,S,v)=>this._arrowMesh(b,S,v,s),T=(b,S,v,w)=>{S&&b&&a.push({text:S,pos:b,height:v,rotation:w??0,color:s,alignH:1,alignV:2})};switch(i){case"DIMENSION":case"DIMENSION_LINEAR":case"DIMENSION_ALIGNED":{if(!c||!u||!l)return;let b,S,v,w;if(i==="DIMENSION_ALIGNED"){const L=u.x-c.x,C=u.y-c.y,O=Math.hypot(L,C);if(O<1e-9)return;const N=L/O,U=C/O,Z=d/2;b=l.x-N*Z,S=l.y-U*Z,v=l.x+N*Z,w=l.y+U*Z}else{const L=Math.abs(Math.sin(x))>.5,C=d/2;b=l.x-(L?0:C),S=l.y-(L?C:0),v=l.x+(L?0:C),w=l.y+(L?C:0)}const I=Math.max(d*.04,1);M({x:b,y:S},{x:v,y:w}),M(c,{x:b,y:S}),M(u,{x:v,y:w}),_({x:b,y:S,z:0},Math.atan2(S-w,b-v),I),_({x:v,y:w,z:0},Math.atan2(w-S,v-b),I),T(h??{x:(b+v)/2,y:(S+w)/2},m||g(d),Math.max(I*1.5,1),p);break}case"DIMENSION_RADIUS":{if(!l||!f)return;const b=Math.max(d*.05,.5);M(l,f),_({x:f.x,y:f.y,z:0},Math.atan2(f.y-l.y,f.x-l.x),b),T(h??{x:(l.x+f.x)/2,y:(l.y+f.y)/2},m||`R${g(d)}`,Math.max(b*2,1));break}case"DIMENSION_DIAMETER":{if(!l||!f)return;const b={x:2*l.x-f.x,y:2*l.y-f.y},S=Math.max(d/2*.05,.5);M(f,b),_({x:f.x,y:f.y,z:0},Math.atan2(f.y-l.y,f.x-l.x),S),_({x:b.x,y:b.y,z:0},Math.atan2(b.y-l.y,b.x-l.x),S),T(h??l,m||`Ø${g(d)}`,Math.max(S*2,1));break}case"DIMENSION_ANG_3PT":case"DIMENSION_ANG_2LN":{if(!l||!c||!u)return;const b=l.x,S=l.y,v=Math.hypot(c.x-b,c.y-S);if(v<1e-9)return;let w=Math.atan2(c.y-S,c.x-b),I=Math.atan2(u.y-S,u.x-b),L=I-w;for(;L<0;)L+=Math.PI*2;L>Math.PI&&([w,I]=[I,w],L=Math.PI*2-L),E(b,S,v,w,w+L);const C=Math.max(v*.05,.5);_({x:b+Math.cos(w)*v,y:S+Math.sin(w)*v,z:0},w-Math.PI/2,C),_({x:b+Math.cos(w+L)*v,y:S+Math.sin(w+L)*v,z:0},w+L+Math.PI/2,C);const O=w+L/2;T(h??{x:b+Math.cos(O)*v*1.2,y:S+Math.sin(O)*v*1.2},m||`${(d*180/Math.PI).toFixed(1)}°`,Math.max(v*.1,1));break}case"DIMENSION_ORDINATE":{if(!l||!c)return;M(l,c),T(h??c,m||((d==null?void 0:d.toFixed(2))??""),2.5);break}}}_onClick(e){var d;if(this._downXY){const p=e.clientX-this._downXY[0],x=e.clientY-this._downXY[1];if(Math.hypot(p,x)>5)return}const t=this._camera,i=this._renderer.domElement.getBoundingClientRect(),s=this._screenToWcs(e.clientX,e.clientY);if(!s)return;const r=s.x,a=s.y;if(this._measureActive){this._doMeasure2D(r,a);return}const o=c2*(t.right-t.left)/(i.width*(t.zoom||1));let l=-1,c=o;const u=this._pickSegs,f=this._pickSegMeta;for(let p=0,x=0;p<u.length;p+=4,x++){const m=this._segDist(r,a,u[p],u[p+1],u[p+2],u[p+3]);m<c&&(c=m,l=f[x])}if(l<0){let p=1/0;for(const x of this._pickFills)if(this._fillHit(x.loops,r,a)){const m=this._loopArea(x.loops[0]||[]);m<p&&(p=m,l=x.metaIdx)}}const h=l>=0?this._entityMeta[l]:null;this._highlight(h),(d=this._onSelectCb)==null||d.call(this,h?h.entity:null)}_segDist(e,t,i,s,r,a){const o=r-i,l=a-s,c=o*o+l*l;if(!c)return Math.hypot(e-i,t-s);const u=Math.max(0,Math.min(1,((e-i)*o+(t-s)*l)/c));return Math.hypot(e-(i+u*o),t-(s+u*l))}startMeasure(e){this.stopMeasure(),this._measureCb=e,this._measureActive=!0}stopMeasure(){var e,t;this._measureActive=!1,this._measureCb=null,this._measurePtA=null;for(const i of this._measureMarkers)this._group.remove(i),(e=i.geometry)==null||e.dispose(),(t=i.material)==null||t.dispose();this._measureMarkers=[]}_doMeasure2D(e,t){var i,s;if(this._measurePtA){const r=this._measurePtA,a=Math.hypot(e-r.x,t-r.y),o=this._mkMeasureMarker(e,t),l=this._mkMeasureLine(r.x,r.y,e,t);this._measureMarkers.push(o,l),this._group.add(o,l),(s=this._measureCb)==null||s.call(this,{phase:"done",ax:r.x,ay:r.y,az:0,bx:e,by:t,bz:0,d:a}),this._measurePtA=null}else{this._measurePtA={x:e,y:t};const r=this._mkMeasureMarker(e,t);this._measureMarkers.push(r),this._group.add(r),(i=this._measureCb)==null||i.call(this,{phase:"a",ax:e,ay:t,az:0,bx:e,by:t,bz:0,d:0})}}_mkMeasureMarker(e,t){const i=this._camera,s=this._renderer.domElement.getBoundingClientRect(),r=(i.right-i.left)/(s.width*(i.zoom||1))*8,a=[new B(e-r,t,0),new B(e+r,t,0),new B(e,t-r,0),new B(e,t+r,0)],o=new wt().setFromPoints(a);o.setIndex([0,1,2,3]);const l=new Ns({color:15085616,depthTest:!1}),c=new da(o,l);return c.renderOrder=100,c}_mkMeasureLine(e,t,i,s){const r=new wt().setFromPoints([new B(e,t,0),new B(i,s,0)]),a=new Ns({color:15085616,depthTest:!1}),o=new id(r,a);return o.renderOrder=100,o}_highlight(e){const t=this._lineColorAttr,i=this._origColors;if(this._selMeta&&t&&i){const s=this._selMeta;for(let r=s.colStart;r<s.colEnd&&r<i.length;r++)t.array[r]=i[r]}if(this._selMeta=e||null,e&&t&&e.colEnd>e.colStart){const s=this._selColor;for(let r=e.colStart;r<e.colEnd;r+=3)t.array[r]=s.r,t.array[r+1]=s.g,t.array[r+2]=s.b}t&&(t.needsUpdate=!0)}setAccent(e){if(this._selColor={r:parseInt(e.slice(1,3),16)/255,g:parseInt(e.slice(3,5),16)/255,b:parseInt(e.slice(5,7),16)/255},this._selMeta){const t=this._selMeta;this._selMeta=null,this._highlight(t)}}_distToBounds(e,t,i){if(i.type==="point")return Math.hypot(e-i.cx,t-i.cy);if(i.type==="circle")return Math.abs(Math.hypot(e-i.cx,t-i.cy)-i.r);if(i.type==="line"){const s=i.x2-i.x1,r=i.y2-i.y1,a=s*s+r*r;if(!a)return Math.hypot(e-i.x1,t-i.y1);const o=Math.max(0,Math.min(1,((e-i.x1)*s+(t-i.y1)*r)/a));return Math.hypot(e-(i.x1+o*s),t-(i.y1+o*r))}return 1/0}_trimmedContentBox(e,t){if(!t||t.isEmpty())return null;const i=e?e.length>>1:0;if(i<32)return t.clone();const s=new Float64Array(i),r=new Float64Array(i);let a=0;for(let M=0;M+1<e.length;M+=2){const E=e[M],_=e[M+1];!Number.isFinite(E)||!Number.isFinite(_)||(s[a]=E,r[a]=_,a++)}if(a<32)return t.clone();const o=s.subarray(0,a),l=r.subarray(0,a);o.sort(),l.sort();const c=Math.max(0,Math.floor(a*.005)),u=Math.min(a-1,Math.floor(a*.995));let f=o[c],h=o[u],d=l[c],p=l[u];if(!(h>f)||!(p>d))return t.clone();const x=Math.max((h-f)*.02,1),m=Math.max((p-d)*.02,1),g=new Oi(new B(f-x,d-m,0),new B(h+x,p+m,0));return g.min.max(t.min),g.max.min(t.max),g}_fit(e){if(!e||e.isEmpty())return;const t=e.getCenter(new B),i=e.getSize(new B),s=this._container.clientWidth||800,r=this._container.clientHeight||600,a=s/Math.max(r,1),o=1.12,l=Math.max(i.x,1e-9),c=Math.max(i.y,1e-9),u=l/c;let f,h;u>a*8?(h=c*o,f=h*a):u<a/8?(f=l*o,h=f/a):(f=l*o,h=c*o,f/h>a?h=f/a:f=h*a),this._camera.zoom=1,this._camera.left=-f/2,this._camera.right=f/2,this._camera.top=h/2,this._camera.bottom=-h/2;const d=Math.max(f,h,1e3);this._camera.near=-d,this._camera.far=d,this._camera.position.set(t.x,t.y,100);const p=-(this._viewTwist||0);this._camera.up.set(-Math.sin(p),Math.cos(p),0),this._controls.target.set(t.x,t.y,0),this._camera.lookAt(this._controls.target),this._camera.updateProjectionMatrix(),this._camera.updateMatrixWorld(!0),this._controls.update()}_clear(){var e,t,i;for(let s=this._group.children.length-1;s>=0;s--){const r=this._group.children[s];(e=r.geometry)==null||e.dispose(),r.material&&((t=r.material.map)==null||t.dispose(),r.material.dispose()),this._group.remove(r)}(i=this._texCache)==null||i.clear(),this._textGen++,this._contentBox=null}_onResize(){const e=this._container.clientWidth,t=this._container.clientHeight;if(!e||!t)return;this._renderer.setSize(e,t);const i=(this._camera.right-this._camera.left)/2,s=i/(e/t);this._camera.left=-i,this._camera.right=i,this._camera.top=s,this._camera.bottom=-s,this._camera.updateProjectionMatrix()}_animate(){requestAnimationFrame(()=>this._animate()),this._controls.update(),this._renderer.render(this._scene,this._camera)}}const h2="modulepreload",f2=function(n){return"/"+n},yf={},d2=function(e,t,i){let s=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),o=(a==null?void 0:a.nonce)||(a==null?void 0:a.getAttribute("nonce"));s=Promise.allSettled(t.map(l=>{if(l=f2(l),l in yf)return;yf[l]=!0;const c=l.endsWith(".css"),u=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${u}`))return;const f=document.createElement("link");if(f.rel=c?"stylesheet":h2,c||(f.as="script"),f.crossOrigin="",f.href=l,o&&f.setAttribute("nonce",o),document.head.appendChild(f),c)return new Promise((h,d)=>{f.addEventListener("load",h),f.addEventListener("error",()=>d(new Error(`Unable to preload CSS for ${l}`)))})}))}function r(a){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=a,window.dispatchEvent(o),!o.defaultPrevented)throw a}return s.then(a=>{for(const o of a||[])o.status==="rejected"&&r(o.reason);return e().catch(r)})},_f=/[\uAC00-\uD7A3]/,bf=/[\u1100-\u11FF\u3130-\u318F]/,p2=["cp949","windows-949","euc-kr"];let pr;function m2(){if(pr!==void 0)return pr;for(const n of p2)try{return pr=new TextDecoder(n),pr}catch{}return pr=null,null}function Sf(n){if(!n||_f.test(n)||bf.test(n))return n;let e=!1;const t=new Uint8Array(n.length);for(let r=0;r<n.length;r++){const a=n.charCodeAt(r);if(a>255)return n;a>127&&(e=!0),t[r]=a}if(!e)return n;const i=m2();if(!i)return n;let s;try{s=i.decode(t)}catch{return n}return(_f.test(s)||bf.test(s))&&!s.includes("�")?s:n}function g2(n){if(n==null||typeof n!="object")return n;const e=new WeakSet,t=i=>{if(i==null||typeof i!="object"||e.has(i))return;if(e.add(i),Array.isArray(i)){for(let r=0;r<i.length;r++){const a=i[r];typeof a=="string"?i[r]=Sf(a):t(a)}return}const s=i;for(const r of Object.keys(s)){if(r==="imageDataUrl")continue;const a=s[r];typeof a=="string"?s[r]=Sf(a):t(a)}};return t(n),n}async function Mf(n){const{initAcadrustParser:e,parseDwgAcadrust:t}=await d2(async()=>{const{initAcadrustParser:i,parseDwgAcadrust:s}=await import("./acadrustParser-BLUkSD4E.js");return{initAcadrustParser:i,parseDwgAcadrust:s}},[]);return await e(),g2(t(n))}class x2{constructor(e){this._pointer=0,this._eof=!1,this._data=e}next(){if(!this.hasNext())throw this._eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file. Ended on code "+this._data[this._pointer]);const e={code:parseInt(this._data[this._pointer])};return this._pointer++,e.value=Ef(e.code,this._data[this._pointer].trim()),this._pointer++,e.code===0&&e.value==="EOF"&&(this._eof=!0),this.lastReadGroup=e,e}peek(){if(!this.hasNext())throw this._eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file. Ended on code "+this._data[this._pointer]);const e={code:parseInt(this._data[this._pointer])};return e.value=Ef(e.code,this._data[this._pointer+1].trim()),e}rewind(e=1){this._pointer=this._pointer-e*2}hasNext(){return!(this._eof||this._pointer>this._data.length-2)}isEOF(){return this._eof}}function Ef(n,e){return n<=9?e:n>=10&&n<=59?parseFloat(e):n>=60&&n<=99?parseInt(e):n>=100&&n<=109?e:n>=110&&n<=149?parseFloat(e):n>=160&&n<=179?parseInt(e):n>=210&&n<=239?parseFloat(e):n>=270&&n<=289?parseInt(e):n>=290&&n<=299?v2(e):n>=300&&n<=369?e:n>=370&&n<=389?parseInt(e):n>=390&&n<=399?e:n>=400&&n<=409?parseInt(e):n>=410&&n<=419?e:n>=420&&n<=429?parseInt(e):n>=430&&n<=439?e:n>=440&&n<=459?parseInt(e):n>=460&&n<=469?parseFloat(e):n>=470&&n<=481||n===999||n>=1e3&&n<=1009?e:n>=1010&&n<=1059?parseFloat(e):n>=1060&&n<=1071?parseInt(e):(console.log("WARNING: Group code does not have a defined type: %j",{code:n,value:e}),e)}function v2(n){if(n==="0")return!1;if(n==="1")return!0;throw TypeError("String '"+n+"' cannot be cast to Boolean type")}const Up=[0,16711680,16776960,65280,65535,255,16711935,16777215,8421504,12632256,16711680,16744319,13369344,13395558,10027008,10046540,8323072,8339263,4980736,4990502,16727808,16752511,13382400,13401958,10036736,10051404,8331008,8343359,4985600,4992806,16744192,16760703,13395456,13408614,10046464,10056268,8339200,8347455,4990464,4995366,16760576,16768895,13408512,13415014,10056192,10061132,8347392,8351551,4995328,4997670,16776960,16777087,13421568,13421670,10000384,10000460,8355584,8355647,5000192,5000230,12582656,14679935,10079232,11717734,7510016,8755276,6258432,7307071,3755008,4344870,8388352,12582783,6736896,10079334,5019648,7510092,4161280,6258495,2509824,3755046,4194048,10485631,3394560,8375398,2529280,6264908,2064128,5209919,1264640,3099686,65280,8388479,52224,6736998,38912,5019724,32512,4161343,19456,2509862,65343,8388511,52275,6737023,38950,5019743,32543,4161359,19475,2509871,65407,8388543,52326,6737049,38988,5019762,32575,4161375,19494,2509881,65471,8388575,52377,6737074,39026,5019781,32607,4161391,19513,2509890,65535,8388607,52428,6737100,39064,5019800,32639,4161407,19532,2509900,49151,8380415,39372,6730444,29336,5014936,24447,4157311,14668,2507340,32767,8372223,26316,6724044,19608,5010072,16255,4153215,9804,2505036,16383,8364031,13260,6717388,9880,5005208,8063,4149119,4940,2502476,255,8355839,204,6710988,152,5000344,127,4145023,76,2500172,4129023,10452991,3342540,8349388,2490520,6245528,2031743,5193599,1245260,3089996,8323327,12550143,6684876,10053324,4980888,7490712,4128895,6242175,2490444,3745356,12517631,14647295,10027212,11691724,7471256,8735896,6226047,7290751,3735628,4335180,16711935,16744447,13369548,13395660,9961624,9981080,8323199,8339327,4980812,4990540,16711871,16744415,13369497,13395634,9961586,9981061,8323167,8339311,4980793,4990530,16711807,16744383,13369446,13395609,9961548,9981042,8323135,8339295,4980774,4990521,16711743,16744351,13369395,13395583,9961510,9981023,8323103,8339279,4980755,4990511,3355443,5987163,8684676,11382189,14079702,16777215];function y2(n){return Up[n]}function it(n){const e={};n.rewind();let t=n.next(),i=t.code;if(e.x=t.value,i+=10,t=n.next(),t.code!=i)throw new Error("Expected code for point value to be "+i+" but got "+t.code+".");return e.y=t.value,i+=10,t=n.next(),t.code!=i?(n.rewind(),e):(e.z=t.value,e)}function Yt(n,e,t){switch(e.code){case 0:n.type=e.value;break;case 5:n.handle=e.value;break;case 6:n.lineType=e.value;break;case 8:n.layer=e.value;break;case 48:n.lineTypeScale=e.value;break;case 60:n.visible=e.value===0;break;case 62:n.colorIndex=e.value,n.color=y2(Math.abs(e.value));break;case 67:n.inPaperSpace=e.value!==0;break;case 100:break;case 101:for(;e.code!=0;)e=t.next();t.rewind();break;case 330:n.ownerHandle=e.value;break;case 347:n.materialObjectHandle=e.value;break;case 370:n.lineweight=e.value;break;case 420:n.color=e.value;break;case 1e3:n.extendedData=n.extendedData||{},n.extendedData.customStrings=n.extendedData.customStrings||[],n.extendedData.customStrings.push(e.value);break;case 1001:n.extendedData=n.extendedData||{},n.extendedData.applicationName=e.value;break;default:return!1}return!0}class _2{constructor(){this.ForEntityName="3DFACE"}parseEntity(e,t){const i={type:t.value,vertices:[]};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 70:i.shape=(t.value&1)===1,i.hasContinuousLinetypePattern=(t.value&128)===128;break;case 10:i.vertices=b2(e,t),t=e.lastReadGroup;break;default:Yt(i,t,e);break}t=e.next()}return i}}function b2(n,e){var t=[],i=!1,s=!1,r=4;for(let o=0;o<=r;o++){for(var a={};!n.isEOF()&&!(e.code===0||s);){switch(e.code){case 10:case 11:case 12:case 13:if(i){s=!0;continue}a.x=e.value,i=!0;break;case 20:case 21:case 22:case 23:a.y=e.value;break;case 30:case 31:case 32:case 33:a.z=e.value;break;default:return t}e=n.next()}t.push(a),i=!1,s=!1}return n.rewind(),t}class S2{constructor(){this.ForEntityName="ARC"}parseEntity(e,t){const i={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:i.center=it(e);break;case 40:i.radius=t.value;break;case 50:i.startAngle=Math.PI/180*t.value;break;case 51:i.endAngle=Math.PI/180*t.value,i.angleLength=i.endAngle-i.startAngle;break;case 210:i.extrusionDirectionX=t.value;break;case 220:i.extrusionDirectionY=t.value;break;case 230:i.extrusionDirectionZ=t.value;break;default:Yt(i,t,e);break}t=e.next()}return i}}class M2{constructor(){this.ForEntityName="ATTDEF"}parseEntity(e,t){var i={type:t.value,scale:1,textStyle:"STANDARD"};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 1:i.text=t.value;break;case 2:i.tag=t.value;break;case 3:i.prompt=t.value;break;case 7:i.textStyle=t.value;break;case 10:i.startPoint=it(e);break;case 11:i.endPoint=it(e);break;case 39:i.thickness=t.value;break;case 40:i.textHeight=t.value;break;case 41:i.scale=t.value;break;case 50:i.rotation=t.value;break;case 51:i.obliqueAngle=t.value;break;case 70:i.invisible=!!(t.value&1),i.constant=!!(t.value&2),i.verificationRequired=!!(t.value&4),i.preset=!!(t.value&8);break;case 71:i.backwards=!!(t.value&2),i.mirrored=!!(t.value&4);break;case 72:i.horizontalJustification=t.value;break;case 73:i.fieldLength=t.value;break;case 74:i.verticalJustification=t.value;break;case 100:break;case 210:i.extrusionDirectionX=t.value;break;case 220:i.extrusionDirectionY=t.value;break;case 230:i.extrusionDirectionZ=t.value;break;default:Yt(i,t,e);break}t=e.next()}return i}}class E2{constructor(){this.ForEntityName="CIRCLE"}parseEntity(e,t){const i={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:i.center=it(e);break;case 40:i.radius=t.value;break;case 50:i.startAngle=Math.PI/180*t.value;break;case 51:const s=Math.PI/180*t.value;s<i.startAngle?i.angleLength=s+2*Math.PI-i.startAngle:i.angleLength=s-i.startAngle,i.endAngle=s;break;default:Yt(i,t,e);break}t=e.next()}return i}}class T2{constructor(){this.ForEntityName="DIMENSION"}parseEntity(e,t){const i={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 2:i.block=t.value;break;case 10:i.anchorPoint=it(e);break;case 11:i.middleOfText=it(e);break;case 12:i.insertionPoint=it(e);break;case 13:i.linearOrAngularPoint1=it(e);break;case 14:i.linearOrAngularPoint2=it(e);break;case 15:i.diameterOrRadiusPoint=it(e);break;case 16:i.arcPoint=it(e);break;case 70:i.dimensionType=t.value;break;case 71:i.attachmentPoint=t.value;break;case 42:i.actualMeasurement=t.value;break;case 1:i.text=t.value;break;case 50:i.angle=t.value;break;default:Yt(i,t,e);break}t=e.next()}return i}}class A2{constructor(){this.ForEntityName="ELLIPSE"}parseEntity(e,t){const i={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:i.center=it(e);break;case 11:i.majorAxisEndPoint=it(e);break;case 40:i.axisRatio=t.value;break;case 41:i.startAngle=t.value;break;case 42:i.endAngle=t.value;break;case 2:i.name=t.value;break;default:Yt(i,t,e);break}t=e.next()}return i}}class w2{constructor(){this.ForEntityName="INSERT"}parseEntity(e,t){const i={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 2:i.name=t.value;break;case 41:i.xScale=t.value;break;case 42:i.yScale=t.value;break;case 43:i.zScale=t.value;break;case 10:i.position=it(e);break;case 50:i.rotation=t.value;break;case 70:i.columnCount=t.value;break;case 71:i.rowCount=t.value;break;case 44:i.columnSpacing=t.value;break;case 45:i.rowSpacing=t.value;break;case 210:i.extrusionDirection=it(e);break;default:Yt(i,t,e);break}t=e.next()}return i}}class C2{constructor(){this.ForEntityName="LINE"}parseEntity(e,t){const i={type:t.value,vertices:[]};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:i.vertices.unshift(it(e));break;case 11:i.vertices.push(it(e));break;case 210:i.extrusionDirection=it(e);break;case 100:break;default:Yt(i,t,e);break}t=e.next()}return i}}class R2{constructor(){this.ForEntityName="LWPOLYLINE"}parseEntity(e,t){const i={type:t.value,vertices:[]};let s=0;for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 38:i.elevation=t.value;break;case 39:i.depth=t.value;break;case 70:i.shape=(t.value&1)===1,i.hasContinuousLinetypePattern=(t.value&128)===128;break;case 90:s=t.value;break;case 10:i.vertices=P2(s,e);break;case 43:t.value!==0&&(i.width=t.value);break;case 210:i.extrusionDirectionX=t.value;break;case 220:i.extrusionDirectionY=t.value;break;case 230:i.extrusionDirectionZ=t.value;break;default:Yt(i,t,e);break}t=e.next()}return i}}function P2(n,e){if(!n||n<=0)throw Error("n must be greater than 0 verticies");const t=[];let i=!1,s=!1,r=e.lastReadGroup;for(let a=0;a<n;a++){const o={};for(;!e.isEOF()&&!(r.code===0||s);){switch(r.code){case 10:if(i){s=!0;continue}o.x=r.value,i=!0;break;case 20:o.y=r.value;break;case 30:o.z=r.value;break;case 40:o.startWidth=r.value;break;case 41:o.endWidth=r.value;break;case 42:r.value!=0&&(o.bulge=r.value);break;default:return e.rewind(),i&&t.push(o),e.rewind(),t}r=e.next()}t.push(o),i=!1,s=!1}return e.rewind(),t}class L2{constructor(){this.ForEntityName="MTEXT"}parseEntity(e,t){const i={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 3:i.text?i.text+=t.value:i.text=t.value;break;case 1:i.text?i.text+=t.value:i.text=t.value;break;case 10:i.position=it(e);break;case 11:i.directionVector=it(e);break;case 40:i.height=t.value;break;case 41:i.width=t.value;break;case 50:i.rotation=t.value;break;case 71:i.attachmentPoint=t.value;break;case 72:i.drawingDirection=t.value;break;default:Yt(i,t,e);break}t=e.next()}return i}}class D2{constructor(){this.ForEntityName="POINT"}parseEntity(e,t){const s={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:s.position=it(e);break;case 39:s.thickness=t.value;break;case 210:s.extrusionDirection=it(e);break;case 100:break;default:Yt(s,t,e);break}t=e.next()}return s}}class I2{constructor(){this.ForEntityName="VERTEX"}parseEntity(e,t){var i={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:i.x=t.value;break;case 20:i.y=t.value;break;case 30:i.z=t.value;break;case 40:break;case 41:break;case 42:t.value!=0&&(i.bulge=t.value);break;case 70:i.curveFittingVertex=(t.value&1)!==0,i.curveFitTangent=(t.value&2)!==0,i.splineVertex=(t.value&8)!==0,i.splineControlPoint=(t.value&16)!==0,i.threeDPolylineVertex=(t.value&32)!==0,i.threeDPolylineMesh=(t.value&64)!==0,i.polyfaceMeshVertex=(t.value&128)!==0;break;case 50:break;case 71:i.faceA=t.value;break;case 72:i.faceB=t.value;break;case 73:i.faceC=t.value;break;case 74:i.faceD=t.value;break;default:Yt(i,t,e);break}t=e.next()}return i}}class U2{constructor(){this.ForEntityName="POLYLINE"}parseEntity(e,t){var i={type:t.value,vertices:[]};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:break;case 20:break;case 30:break;case 39:i.thickness=t.value;break;case 40:break;case 41:break;case 70:i.shape=(t.value&1)!==0,i.includesCurveFitVertices=(t.value&2)!==0,i.includesSplineFitVertices=(t.value&4)!==0,i.is3dPolyline=(t.value&8)!==0,i.is3dPolygonMesh=(t.value&16)!==0,i.is3dPolygonMeshClosed=(t.value&32)!==0,i.isPolyfaceMesh=(t.value&64)!==0,i.hasContinuousLinetypePattern=(t.value&128)!==0;break;case 71:break;case 72:break;case 73:break;case 74:break;case 75:break;case 210:i.extrusionDirection=it(e);break;default:Yt(i,t,e);break}t=e.next()}return i.vertices=O2(e,t),i}}function O2(n,e){const t=new I2,i=[];for(;!n.isEOF();)if(e.code===0){if(e.value==="VERTEX")i.push(t.parseEntity(n,e)),e=n.lastReadGroup;else if(e.value==="SEQEND"){F2(n,e);break}}return i}function F2(n,e){const t={type:e.value};for(e=n.next();!n.isEOF()&&e.code!=0;)Yt(t,e,n),e=n.next();return t}class N2{constructor(){this.ForEntityName="SOLID"}parseEntity(e,t){const i={type:t.value,points:[]};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:i.points[0]=it(e);break;case 11:i.points[1]=it(e);break;case 12:i.points[2]=it(e);break;case 13:i.points[3]=it(e);break;case 210:i.extrusionDirection=it(e);break;default:Yt(i,t,e);break}t=e.next()}return i}}class k2{constructor(){this.ForEntityName="SPLINE"}parseEntity(e,t){const i={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:i.controlPoints||(i.controlPoints=[]),i.controlPoints.push(it(e));break;case 11:i.fitPoints||(i.fitPoints=[]),i.fitPoints.push(it(e));break;case 12:i.startTangent=it(e);break;case 13:i.endTangent=it(e);break;case 40:i.knotValues||(i.knotValues=[]),i.knotValues.push(t.value);break;case 70:t.value&1&&(i.closed=!0),t.value&2&&(i.periodic=!0),t.value&4&&(i.rational=!0),t.value&8&&(i.planar=!0),t.value&16&&(i.planar=!0,i.linear=!0);break;case 71:i.degreeOfSplineCurve=t.value;break;case 72:i.numberOfKnots=t.value;break;case 73:i.numberOfControlPoints=t.value;break;case 74:i.numberOfFitPoints=t.value;break;case 210:i.normalVector=it(e);break;default:Yt(i,t,e);break}t=e.next()}return i}}class B2{constructor(){this.ForEntityName="TEXT"}parseEntity(e,t){const i={type:t.value};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 10:i.startPoint=it(e);break;case 11:i.endPoint=it(e);break;case 40:i.textHeight=t.value;break;case 41:i.xScale=t.value;break;case 50:i.rotation=t.value;break;case 1:i.text=t.value;break;case 72:i.halign=t.value;break;case 73:i.valign=t.value;break;default:Yt(i,t,e);break}t=e.next()}return i}}var H2=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function z2(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var Op={exports:{}};(function(n){(function(e,t){n.exports?n.exports=t():e.log=t()})(H2,function(){var e=function(){},t="undefined",i=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),s=["trace","debug","info","warn","error"],r={},a=null;function o(x,m){var g=x[m];if(typeof g.bind=="function")return g.bind(x);try{return Function.prototype.bind.call(g,x)}catch{return function(){return Function.prototype.apply.apply(g,[x,arguments])}}}function l(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(x){return x==="debug"&&(x="log"),typeof console===t?!1:x==="trace"&&i?l:console[x]!==void 0?o(console,x):console.log!==void 0?o(console,"log"):e}function u(){for(var x=this.getLevel(),m=0;m<s.length;m++){var g=s[m];this[g]=m<x?e:this.methodFactory(g,x,this.name)}if(this.log=this.debug,typeof console===t&&x<this.levels.SILENT)return"No console available for logging"}function f(x){return function(){typeof console!==t&&(u.call(this),this[x].apply(this,arguments))}}function h(x,m,g){return c(x)||f.apply(this,arguments)}function d(x,m){var g=this,M,E,_,T="loglevel";typeof x=="string"?T+=":"+x:typeof x=="symbol"&&(T=void 0);function b(L){var C=(s[L]||"silent").toUpperCase();if(!(typeof window===t||!T)){try{window.localStorage[T]=C;return}catch{}try{window.document.cookie=encodeURIComponent(T)+"="+C+";"}catch{}}}function S(){var L;if(!(typeof window===t||!T)){try{L=window.localStorage[T]}catch{}if(typeof L===t)try{var C=window.document.cookie,O=encodeURIComponent(T),N=C.indexOf(O+"=");N!==-1&&(L=/^([^;]+)/.exec(C.slice(N+O.length+1))[1])}catch{}return g.levels[L]===void 0&&(L=void 0),L}}function v(){if(!(typeof window===t||!T)){try{window.localStorage.removeItem(T)}catch{}try{window.document.cookie=encodeURIComponent(T)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch{}}}function w(L){var C=L;if(typeof C=="string"&&g.levels[C.toUpperCase()]!==void 0&&(C=g.levels[C.toUpperCase()]),typeof C=="number"&&C>=0&&C<=g.levels.SILENT)return C;throw new TypeError("log.setLevel() called with invalid level: "+L)}g.name=x,g.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},g.methodFactory=m||h,g.getLevel=function(){return _??E??M},g.setLevel=function(L,C){return _=w(L),C!==!1&&b(_),u.call(g)},g.setDefaultLevel=function(L){E=w(L),S()||g.setLevel(L,!1)},g.resetLevel=function(){_=null,v(),u.call(g)},g.enableAll=function(L){g.setLevel(g.levels.TRACE,L)},g.disableAll=function(L){g.setLevel(g.levels.SILENT,L)},g.rebuild=function(){if(a!==g&&(M=w(a.getLevel())),u.call(g),a===g)for(var L in r)r[L].rebuild()},M=w(a?a.getLevel():"WARN");var I=S();I!=null&&(_=w(I)),u.call(g)}a=new d,a.getLogger=function(m){if(typeof m!="symbol"&&typeof m!="string"||m==="")throw new TypeError("You must supply a name when creating a logger.");var g=r[m];return g||(g=r[m]=new d(m,a.methodFactory)),g};var p=typeof window!==t?window.log:void 0;return a.noConflict=function(){return typeof window!==t&&window.log===a&&(window.log=p),a},a.getLoggers=function(){return r},a.default=a,a})})(Op);var G2=Op.exports;const tt=z2(G2);tt.setLevel("error");function V2(n){n.registerEntityHandler(_2),n.registerEntityHandler(S2),n.registerEntityHandler(M2),n.registerEntityHandler(E2),n.registerEntityHandler(T2),n.registerEntityHandler(A2),n.registerEntityHandler(w2),n.registerEntityHandler(C2),n.registerEntityHandler(R2),n.registerEntityHandler(L2),n.registerEntityHandler(D2),n.registerEntityHandler(U2),n.registerEntityHandler(N2),n.registerEntityHandler(k2),n.registerEntityHandler(B2)}class W2{constructor(){this._entityHandlers={},V2(this)}parse(e){return typeof e=="string"?this._parse(e):(console.error("Cannot read dxf source of type `"+typeof e),null)}registerEntityHandler(e){const t=new e;this._entityHandlers[t.ForEntityName]=t}parseSync(e){return this.parse(e)}parseStream(e){let t="";const i=this;return new Promise((s,r)=>{e.on("data",a=>{t+=a}),e.on("end",()=>{try{s(i._parse(t))}catch(a){r(a)}}),e.on("error",a=>{r(a)})})}_parse(e){const t={};let i=0;const s=e.split(/\r\n|\r|\n/g),r=new x2(s);if(!r.hasNext())throw Error("Empty file");const a=this;let o;function l(){for(o=r.next();!r.isEOF();)if(o.code===0&&o.value==="SECTION"){if(o=r.next(),o.code!==2){console.error("Unexpected code %s after 0:SECTION",Fp(o)),o=r.next();continue}o.value==="HEADER"?(tt.debug("> HEADER"),t.header=c(),tt.debug("<")):o.value==="BLOCKS"?(tt.debug("> BLOCKS"),t.blocks=u(),tt.debug("<")):o.value==="ENTITIES"?(tt.debug("> ENTITIES"),t.entities=E(!1),tt.debug("<")):o.value==="TABLES"?(tt.debug("> TABLES"),t.tables=h(),tt.debug("<")):o.value==="EOF"?tt.debug("EOF"):tt.warn("Skipping section '%s'",o.value)}else o=r.next()}function c(){let b=null,S=null;const v={};for(o=r.next();;){if(Gn(o,0,"ENDSEC")){b&&(v[b]=S);break}else o.code===9?(b&&(v[b]=S),b=o.value):o.code===10?S={x:o.value}:o.code===20?S.y=o.value:o.code===30?S.z=o.value:S=o.value;o=r.next()}return o=r.next(),v}function u(){const b={};for(o=r.next();o.value!=="EOF"&&!Gn(o,0,"ENDSEC");)if(Gn(o,0,"BLOCK")){tt.debug("block {");const S=f();tt.debug("}"),T(S),S.name?b[S.name]=S:tt.error('block with handle "'+S.handle+'" is missing a name.')}else qi(o),o=r.next();return b}function f(){const b={};for(o=r.next();o.value!=="EOF";){switch(o.code){case 1:b.xrefPath=o.value,o=r.next();break;case 2:b.name=o.value,o=r.next();break;case 3:b.name2=o.value,o=r.next();break;case 5:b.handle=o.value,o=r.next();break;case 8:b.layer=o.value,o=r.next();break;case 10:b.position=_(o),o=r.next();break;case 67:b.paperSpace=!!(o.value&&o.value==1),o=r.next();break;case 70:o.value!=0&&(b.type=o.value),o=r.next();break;case 100:o=r.next();break;case 330:b.ownerHandle=o.value,o=r.next();break;case 0:if(o.value=="ENDBLK")break;b.entities=E(!0);break;default:qi(o),o=r.next()}if(Gn(o,0,"ENDBLK")){o=r.next();break}}return b}function h(){const b={};for(o=r.next();o.value!=="EOF"&&!Gn(o,0,"ENDSEC");)Gn(o,0,"TABLE")?(o=r.next(),M[o.value]?(tt.debug(o.value+" Table {"),b[M[o.value].tableName]=p(o),tt.debug("}")):tt.debug("Unhandled Table "+o.value)):o=r.next();return o=r.next(),b}const d="ENDTAB";function p(b){const S=M[b.value],v={};let w=0;for(o=r.next();!Gn(o,0,d);)switch(o.code){case 5:v.handle=o.value,o=r.next();break;case 330:v.ownerHandle=o.value,o=r.next();break;case 100:o.value==="AcDbSymbolTable"||qi(o),o=r.next();break;case 70:w=o.value,o=r.next();break;case 0:o.value===S.dxfSymbolName?v[S.tableRecordsProperty]=S.parseTableRecords():(qi(o),o=r.next());break;default:qi(o),o=r.next()}const I=v[S.tableRecordsProperty];if(I){let L=(()=>{if(I.constructor===Array)return I.length;if(typeof I=="object")return Object.keys(I).length})();w!==L&&tt.warn("Parsed "+L+" "+S.dxfSymbolName+"'s but expected "+w)}return o=r.next(),v}function x(){const b=[];let S={};for(tt.debug("ViewPort {"),o=r.next();!Gn(o,0,d);)switch(o.code){case 2:S.name=o.value,o=r.next();break;case 10:S.lowerLeftCorner=_(o),o=r.next();break;case 11:S.upperRightCorner=_(o),o=r.next();break;case 12:S.center=_(o),o=r.next();break;case 13:S.snapBasePoint=_(o),o=r.next();break;case 14:S.snapSpacing=_(o),o=r.next();break;case 15:S.gridSpacing=_(o),o=r.next();break;case 16:S.viewDirectionFromTarget=_(o),o=r.next();break;case 17:S.viewTarget=_(o),o=r.next();break;case 42:S.lensLength=o.value,o=r.next();break;case 43:S.frontClippingPlane=o.value,o=r.next();break;case 44:S.backClippingPlane=o.value,o=r.next();break;case 45:S.viewHeight=o.value,o=r.next();break;case 50:S.snapRotationAngle=o.value,o=r.next();break;case 51:S.viewTwistAngle=o.value,o=r.next();break;case 79:S.orthographicType=o.value,o=r.next();break;case 110:S.ucsOrigin=_(o),o=r.next();break;case 111:S.ucsXAxis=_(o),o=r.next();break;case 112:S.ucsYAxis=_(o),o=r.next();break;case 110:S.ucsOrigin=_(o),o=r.next();break;case 281:S.renderMode=o.value,o=r.next();break;case 281:S.defaultLightingType=o.value,o=r.next();break;case 292:S.defaultLightingOn=o.value,o=r.next();break;case 330:S.ownerHandle=o.value,o=r.next();break;case 63:case 421:case 431:S.ambientColor=o.value,o=r.next();break;case 0:o.value==="VPORT"&&(tt.debug("}"),b.push(S),tt.debug("ViewPort {"),S={},o=r.next());break;default:qi(o),o=r.next();break}return tt.debug("}"),b.push(S),b}function m(){const b={};let S={},v=0,w;for(tt.debug("LType {"),o=r.next();!Gn(o,0,"ENDTAB");)switch(o.code){case 2:S.name=o.value,w=o.value,o=r.next();break;case 3:S.description=o.value,o=r.next();break;case 73:v=o.value,v>0&&(S.pattern=[]),o=r.next();break;case 40:S.patternLength=o.value,o=r.next();break;case 49:S.pattern.push(o.value),o=r.next();break;case 0:tt.debug("}"),v>0&&v!==S.pattern.length&&tt.warn("lengths do not match on LTYPE pattern"),b[w]=S,S={},tt.debug("LType {"),o=r.next();break;default:o=r.next()}return tt.debug("}"),b[w]=S,b}function g(){const b={};let S={},v;for(tt.debug("Layer {"),o=r.next();!Gn(o,0,"ENDTAB");)switch(o.code){case 2:S.name=o.value,v=o.value,o=r.next();break;case 62:S.visible=o.value>=0,S.colorIndex=Math.abs(o.value),S.color=X2(S.colorIndex),o=r.next();break;case 70:S.frozen=(o.value&1)!=0||(o.value&2)!=0,o=r.next();break;case 0:o.value==="LAYER"&&(tt.debug("}"),b[v]=S,tt.debug("Layer {"),S={},v=void 0,o=r.next());break;default:qi(o),o=r.next();break}return tt.debug("}"),b[v]=S,b}const M={VPORT:{tableRecordsProperty:"viewPorts",tableName:"viewPort",dxfSymbolName:"VPORT",parseTableRecords:x},LTYPE:{tableRecordsProperty:"lineTypes",tableName:"lineType",dxfSymbolName:"LTYPE",parseTableRecords:m},LAYER:{tableRecordsProperty:"layers",tableName:"layer",dxfSymbolName:"LAYER",parseTableRecords:g}};function E(b){const S=[],v=b?"ENDBLK":"ENDSEC";for(b||(o=r.next());;)if(o.code===0){if(o.value===v)break;const w=a._entityHandlers[o.value];if(w!=null){tt.debug(o.value+" {");const I=w.parseEntity(r,o);o=r.lastReadGroup,tt.debug("}"),T(I),S.push(I)}else{tt.warn("Unhandled entity "+o.value),o=r.next();continue}}else o=r.next();return v=="ENDSEC"&&(o=r.next()),S}function _(b){const S={};let v=b.code;if(S.x=b.value,v+=10,b=r.next(),b.code!=v)throw new Error("Expected code for point value to be "+v+" but got "+b.code+".");return S.y=b.value,v+=10,b=r.next(),b.code!=v?(r.rewind(),S):(S.z=b.value,S)}function T(b){if(!b)throw new TypeError("entity cannot be undefined or null");b.handle||(b.handle=i++)}return l(),t}}function Gn(n,e,t){return n.code===e&&n.value===t}function qi(n){tt.debug("unhandled group "+Fp(n))}function Fp(n){return n.code+":"+n.value}function X2(n){return Up[n]}const Pa=Math.PI/180,Y2=48;function q2(n,e,t,i,s,r,a){let o=s-i;if(r)for(;o<=0;)o+=Math.PI*2;else for(;o>=0;)o-=Math.PI*2;const l=Math.max(2,Math.ceil(Math.abs(o)/(Math.PI*2)*Y2));for(let c=0;c<=l;c++){const u=i+o*c/l;a.push({x:n+t*Math.cos(u),y:e+t*Math.sin(u)})}}class $2{constructor(){this.ForEntityName="HATCH"}parseEntity(e,t){const i={type:t.value,paths:[],solidFill:!1};for(t=e.next();!e.isEOF()&&t.code!==0;){switch(t.code){case 70:i.solidFill=t.value!==0;break;case 2:i.patternName=t.value;break;case 8:i.layer=t.value;break;case 62:i.colorIndex=t.value;break;case 91:{const s=t.value;let r=e.next();for(let a=0;a<s&&!e.isEOF();a++)r=this._readPath(e,i,r);t=r;continue}}t=e.next()}return i}_readPath(e,t,i){for(;!e.isEOF()&&i.code!==92;)i=e.next();const r=((i.value|0)&2)!==0,a={points:[],bulges:[]};let o=e.next();if(r){let l=!1;for(;o.code===72||o.code===73;)o.code===72&&(l=o.value!==0),o=e.next();let c=0;o.code===93&&(c=o.value,o=e.next());for(let u=0;u<c&&!e.isEOF();u++){let f=0,h=0,d=0;o.code===10&&(f=o.value,o=e.next()),o.code===20&&(h=o.value,o=e.next()),l&&o.code===42&&(d=o.value,o=e.next()),a.points.push({x:f,y:h}),a.bulges.push(d)}}else{let l=0;o.code===93&&(l=o.value,o=e.next());for(let c=0;c<l&&!e.isEOF();c++){let u=0;o.code===72&&(u=o.value,o=e.next()),o=this._readEdge(e,a,u,o)}}if(o.code===97){const l=o.value|0;o=e.next();for(let c=0;c<l&&!e.isEOF()&&o.code===330;c++)o=e.next()}return a.points.length>=2&&t.paths.push(a),o}_readEdge(e,t,i,s){if(i===1){let r=0,a=0,o=0,l=0;s.code===10&&(r=s.value,s=e.next()),s.code===20&&(a=s.value,s=e.next()),s.code===11&&(o=s.value,s=e.next()),s.code===21&&(l=s.value,s=e.next()),t.points.push({x:r,y:a}),t.points.push({x:o,y:l})}else if(i===2){let r=0,a=0,o=0,l=0,c=0,u=1;s.code===10&&(r=s.value,s=e.next()),s.code===20&&(a=s.value,s=e.next()),s.code===40&&(o=s.value,s=e.next()),s.code===50&&(l=s.value*Pa,s=e.next()),s.code===51&&(c=s.value*Pa,s=e.next()),s.code===73&&(u=s.value,s=e.next()),q2(r,a,o,l,c,u!==0,t.points)}else if(i===3){let r=0,a=0,o=1,l=0,c=1,u=0,f=Math.PI*2,h=1;s.code===10&&(r=s.value,s=e.next()),s.code===20&&(a=s.value,s=e.next()),s.code===11&&(o=s.value,s=e.next()),s.code===21&&(l=s.value,s=e.next()),s.code===40&&(c=s.value,s=e.next()),s.code===50&&(u=s.value*Pa,s=e.next()),s.code===51&&(f=s.value*Pa,s=e.next()),s.code===73&&(h=s.value,s=e.next());const d=Math.hypot(o,l),p=d*c,x=Math.atan2(l,o);let m=f-u;if(h!==0)for(;m<=0;)m+=Math.PI*2;else for(;m>=0;)m-=Math.PI*2;const g=Math.max(4,Math.ceil(Math.abs(m)/(Math.PI*2)*72));for(let M=0;M<=g;M++){const E=u+m*M/g,_=d*Math.cos(E),T=p*Math.sin(E);t.points.push({x:r+_*Math.cos(x)-T*Math.sin(x),y:a+_*Math.sin(x)+T*Math.cos(x)})}}else if(i===4){let r=0,a=0;const o=()=>{const l=s.value|0;return s=e.next(),l};for(;!e.isEOF();)if(s.code===95)r=o();else if(s.code===96)a=o();else if(s.code===94||s.code===73||s.code===74)s=e.next();else break;for(let l=0;l<r&&s.code===40&&!e.isEOF();l++)s=e.next();for(let l=0;l<a&&!e.isEOF();l++){let c=0,u=0;s.code===10&&(c=s.value,s=e.next()),s.code===20&&(u=s.value,s=e.next()),s.code===42&&(s=e.next()),t.points.push({x:c,y:u})}}else s=e.next();return s}}const La=Math.PI/180,Wt=n=>n&&{x:n.x,y:n.y,z:n.z||0};function Tf(n,e){var s;const t={...n};switch(delete t.color,(n.type||"").toUpperCase()){case"LINE":((s=n.vertices)==null?void 0:s.length)>=2&&(t.start=Wt(n.vertices[0]),t.end=Wt(n.vertices[1]));break;case"POLYLINE":case"LWPOLYLINE":t.type="LWPOLYLINE",t.points=(n.vertices||[]).map(Wt),t.bulges=(n.vertices||[]).map(r=>r.bulge||0),t.closed=!!n.shape||((n.flags||0)&1)===1;break;case"ARC":case"CIRCLE":t.center=Wt(n.center);break;case"ELLIPSE":t.center=Wt(n.center),t.majorAxis=Wt(n.majorAxisEndPoint),t.ratio=n.axisRatio,t.startParam=n.startAngle,t.endParam=n.endAngle;break;case"POINT":t.position=Wt(n.position);break;case"SOLID":case"3DFACE":{const r=n.points||[];r[0]&&(t.corner1=Wt(r[0])),r[1]&&(t.corner2=Wt(r[1])),r[2]&&(t.corner3=Wt(r[2])),r[3]&&(t.corner4=Wt(r[3])),t.type="SOLID";break}case"TEXT":case"ATTRIB":case"ATTDEF":t.insertionPoint=Wt(n.startPoint||n.position),t.alignmentPt=Wt(n.endPoint),t.rotationAngle=(n.rotation||0)*La,t.horizAlignment=n.halign||0,t.vertAlignment=n.valign||0,t.textHeight=n.textHeight??n.height;break;case"MTEXT":t.insertionPoint=Wt(n.position),t.textHeight=n.height??n.textHeight,n.directionVector?t.xAxisDir=Wt(n.directionVector):n.rotation!=null&&(t.xAxisDir={x:Math.cos(n.rotation*La),y:Math.sin(n.rotation*La)});break;case"INSERT":{t.insertionPoint=Wt(n.position),t.scaleX=n.xScale??1,t.scaleY=n.yScale??1,t.rotation=(n.rotation||0)*La;const r=e.get(n.name);r!=null&&(t.blockHeaderHandle={value:r});break}case"DIMENSION":{const r=e.get(n.block);r!=null&&(t.blockHeaderHandle={value:r});break}}return t}function Z2(n){var u,f;const e=n.blocks||{},t=Object.keys(e),i=new Map;t.forEach((h,d)=>i.set(h,d+1));const s=t.find(h=>/model_space/i.test(h))??t.find(h=>/model/i.test(h)),r=s!=null?i.get(s):0,a=[];for(const h of n.entities||[]){const d=Tf(h,i);d.ownerHandle={value:r},a.push(d)}for(const h of t){const d=i.get(h);for(const p of e[h].entities||[]){const x=Tf(p,i);x.ownerHandle={value:d},a.push(x)}}const o=t.map(h=>({name:h,handle:{value:i.get(h)},basePoint:Wt(e[h].position)||{x:0,y:0,z:0}})),l=((f=(u=n.tables)==null?void 0:u.layer)==null?void 0:f.layers)||{},c=Object.values(l).map(h=>({name:h.name,colorIndex:h.colorIndex}));return{version:"dxf",vars:n.header||{},entities:a,tables:{blocks:o,layers:c}}}function K2(n){var s,r;try{return new TextDecoder("utf-8",{fatal:!0}).decode(n)}catch{}const t=(r=(s=new TextDecoder("latin1").decode(new Uint8Array(n,0,Math.min(n.byteLength,4096))).match(/\$DWGCODEPAGE[\s\S]*?\n\s*3\s*\n\s*([^\r\n]+)/i))==null?void 0:s[1])==null?void 0:r.trim().toLowerCase();let i="windows-1252";t&&(/949/.test(t)?i="euc-kr":/932/.test(t)?i="shift_jis":/936/.test(t)?i="gbk":/950/.test(t)&&(i="big5"));try{return new TextDecoder(i).decode(n)}catch{return new TextDecoder("utf-8").decode(n)}}function Af(n){return J2(K2(n))}function J2(n){const e=new W2;e.registerEntityHandler($2);const t=e.parseSync(n);return Z2(t)}const Np=/\.dwg$/i,kp=/\.dxf$/i;function j2(n){return Np.test(n)}function Q2(n){return kp.test(n)}function eA(n){return Np.test(n)||kp.test(n)}s2("/fonts/NanumGothic-Regular.ttf");const tA=document.getElementById("app"),wf=document.getElementById("status"),yl=document.getElementById("layerList"),Cf=document.getElementById("layers"),Da=document.getElementById("spaces");function rs(n,e=!1){wf.textContent=n,wf.classList.toggle("err",e)}const Jt=new u2(tA);Jt.onSelect(n=>{var t;if(!n){rs("deselected");return}const e=n;rs(`select ${e.type??"?"} · layer=${e.layer??"-"} · h=${((t=e.handle)==null?void 0:t.value)??"-"}`)});const Rf=document.getElementById("coordX"),Pf=document.getElementById("coordY");function Lf(n){const e=Math.abs(n);return e>=1e6?n.toFixed(1):e>=1e3?n.toFixed(2):e>=1?n.toFixed(3):n.toFixed(4)}Jt.onPointerWorld(n=>{if(!n){Rf.textContent="—",Pf.textContent="—";return}Rf.textContent=Lf(n.x),Pf.textContent=Lf(n.y)});function Bp(){var t;const n=Jt.getSpaces(),e=Jt.getActiveSpace();if(Da.innerHTML="",n.length<2&&!((t=n[0])!=null&&t.entityCount)){Da.style.display="none";return}Da.style.display="flex";for(const i of n){const s=document.createElement("button");s.type="button",s.textContent=`${i.label}${i.entityCount?` (${i.entityCount})`:""}`,s.title=`${i.name} · handle ${i.handleHex}`,i.handleHex===e&&s.classList.add("active"),s.addEventListener("click",()=>{i.handleHex!==Jt.getActiveSpace()&&(Jt.setSpace(i.handleHex),Bp(),Gp(),Jt.fit(),rs(`space ${i.label} · ${i.entityCount} entities`))}),Da.append(s)}}async function nA(n,e){return Q2(e)?Af(n):j2(e)?Mf(new Uint8Array(n)):new TextDecoder("latin1").decode(new Uint8Array(n,0,Math.min(6,n.byteLength))).startsWith("AC")?Mf(new Uint8Array(n)):Af(n)}async function Hp(n,e){const t=await nA(n,e),i=Sr(t),s=ob(i);return Jt.load(t,{spaceHandle:(s==null?void 0:s.handleHex)??null}),Jt.resize(),t}async function ru(n,e){const t=e??n.split("?")[0].split("/").pop()??n,i=await fetch(n);if(!i.ok)throw new Error(`HTTP ${i.status}`);return Hp(await i.arrayBuffer(),t)}async function zp(n){if(!eA(n.name))throw new Error(`not .dwg/.dxf: ${n.name}`);return Hp(await n.arrayBuffer(),n.name)}function Gp(){yl.innerHTML="";for(const n of Jt.getLayerInfo()){const e=document.createElement("label");e.dataset.name=n.name;const t=document.createElement("span");t.className="swatch",t.style.background=n.colorHex||"#888";const i=document.createElement("input");i.type="checkbox",i.checked=n.visible,i.addEventListener("change",()=>{const r=new Set;yl.querySelectorAll("label").forEach(a=>{a.querySelector("input").checked||r.add(a.dataset.name)}),Jt.setHiddenLayers(r)});const s=document.createElement("span");s.textContent=`${n.name} (${n.count})`,e.append(t,i,s),yl.append(e)}}async function iA(n,e){var r;const i=Sr(e).find(a=>a.handleHex===Jt.getActiveSpace()),s=i?` · ${i.label}`:"";rs(`✓ ${n} · ${((r=e.entities)==null?void 0:r.length)??0} entities${s}`),Bp(),Gp(),Jt.fit()}async function zr(n,e){rs(`loading ${n}…`);try{await iA(n,await e())}catch(t){rs(`${n}: ${t.message}`,!0),console.error(t)}}document.getElementById("sample").addEventListener("click",()=>{zr("BasicSample.dwg",()=>ru("/samples/BasicSample.dwg","BasicSample.dwg"))});document.getElementById("sampleDxf").addEventListener("click",()=>{zr("simple.dxf",()=>ru("/samples/simple.dxf","simple.dxf"))});document.getElementById("file").addEventListener("change",n=>{var t;const e=(t=n.target.files)==null?void 0:t[0];e&&(zr(e.name,()=>zp(e)),n.target.value="")});document.getElementById("fit").addEventListener("click",()=>Jt.fit());let _l=!0;document.getElementById("theme").addEventListener("click",()=>{_l=!_l,Jt.setTheme(_l)});document.getElementById("layersBtn").addEventListener("click",()=>{Cf.style.display=Cf.style.display==="block"?"none":"block"});window.addEventListener("dragover",n=>n.preventDefault());window.addEventListener("drop",n=>{var t,i;n.preventDefault();const e=(i=(t=n.dataTransfer)==null?void 0:t.files)==null?void 0:i[0];e&&zr(e.name,()=>zp(e))});const bl=new URLSearchParams(location.search).get("model");bl?zr(bl,()=>ru(bl)):rs("ready · Sample DWG / DXF 또는 파일 드롭");window.addEventListener("resize",()=>Jt.resize());
|