generateMeshBVH.worker.js 296 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843
  1. "use strict";(()=>{var rn="169";var li=0,ps=1,ms=2;var Fi=0,Bi=1,Oi=2,zi=3,ki=4,Vi=5,Hi=6,Gi=7;var gs=300;var Wi=1e3,Ge=1001,Xi=1002;var cr=1006;var lr=1008;var hr=1009;var ur=1015;var fr=1023;var tn=2300,Xn=2301,Tn=2302,qi=2400,Yi=2401,Zi=2402;var _s="",Dt="srgb",hi="srgb-linear",dr="display-p3",xs="display-p3-linear",qn="linear",Ji="srgb",$i="rec709",Ki="p3";var Qi=35044;var We=2e3,ji=2001,Te=class{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});let n=this._listeners;n[t]===void 0&&(n[t]=[]),n[t].indexOf(e)===-1&&n[t].push(e)}hasEventListener(t,e){if(this._listeners===void 0)return!1;let n=this._listeners;return n[t]!==void 0&&n[t].indexOf(e)!==-1}removeEventListener(t,e){if(this._listeners===void 0)return;let i=this._listeners[t];if(i!==void 0){let s=i.indexOf(e);s!==-1&&i.splice(s,1)}}dispatchEvent(t){if(this._listeners===void 0)return;let n=this._listeners[t.type];if(n!==void 0){t.target=this;let i=n.slice(0);for(let s=0,r=i.length;s<r;s++)i[s].call(this,t);t.target=null}}},tt=["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"];var qc=Math.PI/180,Yc=180/Math.PI;function on(){let c=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(tt[c&255]+tt[c>>8&255]+tt[c>>16&255]+tt[c>>24&255]+"-"+tt[t&255]+tt[t>>8&255]+"-"+tt[t>>16&15|64]+tt[t>>24&255]+"-"+tt[e&63|128]+tt[e>>8&255]+"-"+tt[e>>16&255]+tt[e>>24&255]+tt[n&255]+tt[n>>8&255]+tt[n>>16&255]+tt[n>>24&255]).toLowerCase()}function nt(c,t,e){return Math.max(t,Math.min(e,c))}function pr(c,t){return(c%t+t)%t}function En(c,t,e){return(1-e)*c+e*t}function ve(c,t){switch(t.constructor){case Float32Array:return c;case Uint32Array:return c/4294967295;case Uint16Array:return c/65535;case Uint8Array:return c/255;case Int32Array:return Math.max(c/2147483647,-1);case Int16Array:return Math.max(c/32767,-1);case Int8Array:return Math.max(c/127,-1);default:throw new Error("Invalid component type.")}}function rt(c,t){switch(t.constructor){case Float32Array:return c;case Uint32Array:return Math.round(c*4294967295);case Uint16Array:return Math.round(c*65535);case Uint8Array:return Math.round(c*255);case Int32Array:return Math.round(c*2147483647);case Int16Array:return Math.round(c*32767);case Int8Array:return Math.round(c*127);default:throw new Error("Invalid component type.")}}var H=class c{constructor(t=0,e=0){c.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){let e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}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(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.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(t){let e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;let n=this.dot(t)/e;return Math.acos(nt(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){let e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){let n=Math.cos(e),i=Math.sin(e),s=this.x-t.x,r=this.y-t.y;return this.x=s*n-r*i+t.x,this.y=s*i+r*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},D=class c{constructor(t,e,n,i,s,r,a,o,h){c.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,n,i,s,r,a,o,h)}set(t,e,n,i,s,r,a,o,h){let l=this.elements;return l[0]=t,l[1]=i,l[2]=a,l[3]=e,l[4]=s,l[5]=o,l[6]=n,l[7]=r,l[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){let e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){let e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){let n=t.elements,i=e.elements,s=this.elements,r=n[0],a=n[3],o=n[6],h=n[1],l=n[4],f=n[7],u=n[2],d=n[5],p=n[8],m=i[0],_=i[3],g=i[6],x=i[1],v=i[4],S=i[7],y=i[2],w=i[5],b=i[8];return s[0]=r*m+a*x+o*y,s[3]=r*_+a*v+o*w,s[6]=r*g+a*S+o*b,s[1]=h*m+l*x+f*y,s[4]=h*_+l*v+f*w,s[7]=h*g+l*S+f*b,s[2]=u*m+d*x+p*y,s[5]=u*_+d*v+p*w,s[8]=u*g+d*S+p*b,this}multiplyScalar(t){let e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){let t=this.elements,e=t[0],n=t[1],i=t[2],s=t[3],r=t[4],a=t[5],o=t[6],h=t[7],l=t[8];return e*r*l-e*a*h-n*s*l+n*a*o+i*s*h-i*r*o}invert(){let t=this.elements,e=t[0],n=t[1],i=t[2],s=t[3],r=t[4],a=t[5],o=t[6],h=t[7],l=t[8],f=l*r-a*h,u=a*o-l*s,d=h*s-r*o,p=e*f+n*u+i*d;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);let m=1/p;return t[0]=f*m,t[1]=(i*h-l*n)*m,t[2]=(a*n-i*r)*m,t[3]=u*m,t[4]=(l*e-i*o)*m,t[5]=(i*s-a*e)*m,t[6]=d*m,t[7]=(n*o-h*e)*m,t[8]=(r*e-n*s)*m,this}transpose(){let t,e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){let e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,i,s,r,a){let o=Math.cos(s),h=Math.sin(s);return this.set(n*o,n*h,-n*(o*r+h*a)+r+t,-i*h,i*o,-i*(-h*r+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(Cn.makeScale(t,e)),this}rotate(t){return this.premultiply(Cn.makeRotation(-t)),this}translate(t,e){return this.premultiply(Cn.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){let e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){let e=this.elements,n=t.elements;for(let i=0;i<9;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){let n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return new this.constructor().fromArray(this.elements)}},Cn=new D;function mr(c){for(let t=c.length-1;t>=0;--t)if(c[t]>=65535)return!0;return!1}function ts(c){return document.createElementNS("http://www.w3.org/1999/xhtml",c)}var es=new D().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),ns=new D().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),Me={[hi]:{transfer:qn,primaries:$i,luminanceCoefficients:[.2126,.7152,.0722],toReference:c=>c,fromReference:c=>c},[Dt]:{transfer:Ji,primaries:$i,luminanceCoefficients:[.2126,.7152,.0722],toReference:c=>c.convertSRGBToLinear(),fromReference:c=>c.convertLinearToSRGB()},[xs]:{transfer:qn,primaries:Ki,luminanceCoefficients:[.2289,.6917,.0793],toReference:c=>c.applyMatrix3(ns),fromReference:c=>c.applyMatrix3(es)},[dr]:{transfer:Ji,primaries:Ki,luminanceCoefficients:[.2289,.6917,.0793],toReference:c=>c.convertSRGBToLinear().applyMatrix3(ns),fromReference:c=>c.applyMatrix3(es).convertLinearToSRGB()}},gr=new Set([hi,xs]),pt={enabled:!0,_workingColorSpace:hi,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(c){if(!gr.has(c))throw new Error(`Unsupported working color space, "${c}".`);this._workingColorSpace=c},convert:function(c,t,e){if(this.enabled===!1||t===e||!t||!e)return c;let n=Me[t].toReference,i=Me[e].fromReference;return i(n(c))},fromWorkingColorSpace:function(c,t){return this.convert(c,this._workingColorSpace,t)},toWorkingColorSpace:function(c,t){return this.convert(c,t,this._workingColorSpace)},getPrimaries:function(c){return Me[c].primaries},getTransfer:function(c){return c===_s?qn:Me[c].transfer},getLuminanceCoefficients:function(c,t=this._workingColorSpace){return c.fromArray(Me[t].luminanceCoefficients)}};function se(c){return c<.04045?c*.0773993808:Math.pow(c*.9478672986+.0521327014,2.4)}function Rn(c){return c<.0031308?c*12.92:1.055*Math.pow(c,.41666)-.055}var Yt,Yn=class{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{Yt===void 0&&(Yt=ts("canvas")),Yt.width=t.width,Yt.height=t.height;let n=Yt.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),e=Yt}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){let e=ts("canvas");e.width=t.width,e.height=t.height;let n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);let i=n.getImageData(0,0,t.width,t.height),s=i.data;for(let r=0;r<s.length;r++)s[r]=se(s[r]/255)*255;return n.putImageData(i,0,0),e}else if(t.data){let e=t.data.slice(0);for(let n=0;n<e.length;n++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[n]=Math.floor(se(e[n]/255)*255):e[n]=se(e[n]);return{data:e,width:t.width,height:t.height}}else return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}},_r=0,Zn=class{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:_r++}),this.uuid=on(),this.data=t,this.dataReady=!0,this.version=0}set needsUpdate(t){t===!0&&this.version++}toJSON(t){let e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];let n={uuid:this.uuid,url:""},i=this.data;if(i!==null){let s;if(Array.isArray(i)){s=[];for(let r=0,a=i.length;r<a;r++)i[r].isDataTexture?s.push(Pn(i[r].image)):s.push(Pn(i[r]))}else s=Pn(i);n.url=s}return e||(t.images[this.uuid]=n),n}};function Pn(c){return typeof HTMLImageElement<"u"&&c instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&c instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&c instanceof ImageBitmap?Yn.getDataURL(c):c.data?{data:Array.from(c.data),width:c.width,height:c.height,type:c.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}var xr=0,Ee=class c extends Te{constructor(t=c.DEFAULT_IMAGE,e=c.DEFAULT_MAPPING,n=Ge,i=Ge,s=cr,r=lr,a=fr,o=hr,h=c.DEFAULT_ANISOTROPY,l=_s){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:xr++}),this.uuid=on(),this.name="",this.source=new Zn(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=n,this.wrapT=i,this.magFilter=s,this.minFilter=r,this.anisotropy=h,this.format=a,this.internalFormat=null,this.type=o,this.offset=new H(0,0),this.repeat=new H(1,1),this.center=new H(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new D,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=l,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}toJSON(t){let e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];let n={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).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,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&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==gs)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Wi:t.x=t.x-Math.floor(t.x);break;case Ge:t.x=t.x<0?0:1;break;case Xi:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case Wi:t.y=t.y-Math.floor(t.y);break;case Ge:t.y=t.y<0?0:1;break;case Xi:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}};Ee.DEFAULT_IMAGE=null;Ee.DEFAULT_MAPPING=gs;Ee.DEFAULT_ANISOTROPY=1;var Ce=class c{constructor(t=0,e=0,n=0,i=1){c.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){let e=this.x,n=this.y,i=this.z,s=this.w,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i+r[12]*s,this.y=r[1]*e+r[5]*n+r[9]*i+r[13]*s,this.z=r[2]*e+r[6]*n+r[10]*i+r[14]*s,this.w=r[3]*e+r[7]*n+r[11]*i+r[15]*s,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);let e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,i,s,o=t.elements,h=o[0],l=o[4],f=o[8],u=o[1],d=o[5],p=o[9],m=o[2],_=o[6],g=o[10];if(Math.abs(l-u)<.01&&Math.abs(f-m)<.01&&Math.abs(p-_)<.01){if(Math.abs(l+u)<.1&&Math.abs(f+m)<.1&&Math.abs(p+_)<.1&&Math.abs(h+d+g-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;let v=(h+1)/2,S=(d+1)/2,y=(g+1)/2,w=(l+u)/4,b=(f+m)/4,A=(p+_)/4;return v>S&&v>y?v<.01?(n=0,i=.707106781,s=.707106781):(n=Math.sqrt(v),i=w/n,s=b/n):S>y?S<.01?(n=.707106781,i=0,s=.707106781):(i=Math.sqrt(S),n=w/i,s=A/i):y<.01?(n=.707106781,i=.707106781,s=0):(s=Math.sqrt(y),n=b/s,i=A/s),this.set(n,i,s,e),this}let x=Math.sqrt((_-p)*(_-p)+(f-m)*(f-m)+(u-l)*(u-l));return Math.abs(x)<.001&&(x=1),this.x=(_-p)/x,this.y=(f-m)/x,this.z=(u-l)/x,this.w=Math.acos((h+d+g-1)/2),this}setFromMatrixPosition(t){let e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}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(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.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(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),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}};var Ut=class{constructor(t=0,e=0,n=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=i}static slerpFlat(t,e,n,i,s,r,a){let o=n[i+0],h=n[i+1],l=n[i+2],f=n[i+3],u=s[r+0],d=s[r+1],p=s[r+2],m=s[r+3];if(a===0){t[e+0]=o,t[e+1]=h,t[e+2]=l,t[e+3]=f;return}if(a===1){t[e+0]=u,t[e+1]=d,t[e+2]=p,t[e+3]=m;return}if(f!==m||o!==u||h!==d||l!==p){let _=1-a,g=o*u+h*d+l*p+f*m,x=g>=0?1:-1,v=1-g*g;if(v>Number.EPSILON){let y=Math.sqrt(v),w=Math.atan2(y,g*x);_=Math.sin(_*w)/y,a=Math.sin(a*w)/y}let S=a*x;if(o=o*_+u*S,h=h*_+d*S,l=l*_+p*S,f=f*_+m*S,_===1-a){let y=1/Math.sqrt(o*o+h*h+l*l+f*f);o*=y,h*=y,l*=y,f*=y}}t[e]=o,t[e+1]=h,t[e+2]=l,t[e+3]=f}static multiplyQuaternionsFlat(t,e,n,i,s,r){let a=n[i],o=n[i+1],h=n[i+2],l=n[i+3],f=s[r],u=s[r+1],d=s[r+2],p=s[r+3];return t[e]=a*p+l*f+o*d-h*u,t[e+1]=o*p+l*u+h*f-a*d,t[e+2]=h*p+l*d+a*u-o*f,t[e+3]=l*p-a*f-o*u-h*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,i){return this._x=t,this._y=e,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){let n=t._x,i=t._y,s=t._z,r=t._order,a=Math.cos,o=Math.sin,h=a(n/2),l=a(i/2),f=a(s/2),u=o(n/2),d=o(i/2),p=o(s/2);switch(r){case"XYZ":this._x=u*l*f+h*d*p,this._y=h*d*f-u*l*p,this._z=h*l*p+u*d*f,this._w=h*l*f-u*d*p;break;case"YXZ":this._x=u*l*f+h*d*p,this._y=h*d*f-u*l*p,this._z=h*l*p-u*d*f,this._w=h*l*f+u*d*p;break;case"ZXY":this._x=u*l*f-h*d*p,this._y=h*d*f+u*l*p,this._z=h*l*p+u*d*f,this._w=h*l*f-u*d*p;break;case"ZYX":this._x=u*l*f-h*d*p,this._y=h*d*f+u*l*p,this._z=h*l*p-u*d*f,this._w=h*l*f+u*d*p;break;case"YZX":this._x=u*l*f+h*d*p,this._y=h*d*f+u*l*p,this._z=h*l*p-u*d*f,this._w=h*l*f-u*d*p;break;case"XZY":this._x=u*l*f-h*d*p,this._y=h*d*f-u*l*p,this._z=h*l*p+u*d*f,this._w=h*l*f+u*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){let n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){let e=t.elements,n=e[0],i=e[4],s=e[8],r=e[1],a=e[5],o=e[9],h=e[2],l=e[6],f=e[10],u=n+a+f;if(u>0){let d=.5/Math.sqrt(u+1);this._w=.25/d,this._x=(l-o)*d,this._y=(s-h)*d,this._z=(r-i)*d}else if(n>a&&n>f){let d=2*Math.sqrt(1+n-a-f);this._w=(l-o)/d,this._x=.25*d,this._y=(i+r)/d,this._z=(s+h)/d}else if(a>f){let d=2*Math.sqrt(1+a-n-f);this._w=(s-h)/d,this._x=(i+r)/d,this._y=.25*d,this._z=(o+l)/d}else{let d=2*Math.sqrt(1+f-n-a);this._w=(r-i)/d,this._x=(s+h)/d,this._y=(o+l)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return n<Number.EPSILON?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(nt(this.dot(t),-1,1)))}rotateTowards(t,e){let n=this.angleTo(t);if(n===0)return this;let i=Math.min(1,e/n);return this.slerp(t,i),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(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._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 t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){let n=t._x,i=t._y,s=t._z,r=t._w,a=e._x,o=e._y,h=e._z,l=e._w;return this._x=n*l+r*a+i*h-s*o,this._y=i*l+r*o+s*a-n*h,this._z=s*l+r*h+n*o-i*a,this._w=r*l-n*a-i*o-s*h,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);let n=this._x,i=this._y,s=this._z,r=this._w,a=r*t._w+n*t._x+i*t._y+s*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=n,this._y=i,this._z=s,this;let o=1-a*a;if(o<=Number.EPSILON){let d=1-e;return this._w=d*r+e*this._w,this._x=d*n+e*this._x,this._y=d*i+e*this._y,this._z=d*s+e*this._z,this.normalize(),this}let h=Math.sqrt(o),l=Math.atan2(h,a),f=Math.sin((1-e)*l)/h,u=Math.sin(e*l)/h;return this._w=r*f+this._w*u,this._x=n*f+this._x*u,this._y=i*f+this._y*u,this._z=s*f+this._z*u,this._onChangeCallback(),this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){let t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(t),i*Math.cos(t),s*Math.sin(e),s*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},M=class c{constructor(t=0,e=0,n=0){c.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return n===void 0&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(is.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(is.setFromAxisAngle(t,e))}applyMatrix3(t){let e=this.x,n=this.y,i=this.z,s=t.elements;return this.x=s[0]*e+s[3]*n+s[6]*i,this.y=s[1]*e+s[4]*n+s[7]*i,this.z=s[2]*e+s[5]*n+s[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){let e=this.x,n=this.y,i=this.z,s=t.elements,r=1/(s[3]*e+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*e+s[4]*n+s[8]*i+s[12])*r,this.y=(s[1]*e+s[5]*n+s[9]*i+s[13])*r,this.z=(s[2]*e+s[6]*n+s[10]*i+s[14])*r,this}applyQuaternion(t){let e=this.x,n=this.y,i=this.z,s=t.x,r=t.y,a=t.z,o=t.w,h=2*(r*i-a*n),l=2*(a*e-s*i),f=2*(s*n-r*e);return this.x=e+o*h+r*f-a*l,this.y=n+o*l+a*h-s*f,this.z=i+o*f+s*l-r*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){let e=this.x,n=this.y,i=this.z,s=t.elements;return this.x=s[0]*e+s[4]*n+s[8]*i,this.y=s[1]*e+s[5]*n+s[9]*i,this.z=s[2]*e+s[6]*n+s[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}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(t){return this.x*t.x+this.y*t.y+this.z*t.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(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){let n=t.x,i=t.y,s=t.z,r=e.x,a=e.y,o=e.z;return this.x=i*o-s*a,this.y=s*r-n*o,this.z=n*a-i*r,this}projectOnVector(t){let e=t.lengthSq();if(e===0)return this.set(0,0,0);let n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return In.copy(this).projectOnVector(t),this.sub(In)}reflect(t){return this.sub(In.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){let e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;let n=this.dot(t)/e;return Math.acos(nt(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){let e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){let i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){let e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){let e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let t=Math.random()*Math.PI*2,e=Math.random()*2-1,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},In=new M,is=new Ut,W=class{constructor(t=new M(1/0,1/0,1/0),e=new M(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e+=3)this.expandByPoint(mt.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,n=t.count;e<n;e++)this.expandByPoint(mt.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){let n=mt.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(n),this.max.copy(t).add(n),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.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(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);let n=t.geometry;if(n!==void 0){let s=n.getAttribute("position");if(e===!0&&s!==void 0&&t.isInstancedMesh!==!0)for(let r=0,a=s.count;r<a;r++)t.isMesh===!0?t.getVertexPosition(r,mt):mt.fromBufferAttribute(s,r),mt.applyMatrix4(t.matrixWorld),this.expandByPoint(mt);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Xe.copy(t.boundingBox)):(n.boundingBox===null&&n.computeBoundingBox(),Xe.copy(n.boundingBox)),Xe.applyMatrix4(t.matrixWorld),this.union(Xe)}let i=t.children;for(let s=0,r=i.length;s<r;s++)this.expandByObject(i[s],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,mt),mt.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Se),qe.subVectors(this.max,Se),Zt.subVectors(t.a,Se),Jt.subVectors(t.b,Se),$t.subVectors(t.c,Se),Rt.subVectors(Jt,Zt),Pt.subVectors($t,Jt),zt.subVectors(Zt,$t);let e=[0,-Rt.z,Rt.y,0,-Pt.z,Pt.y,0,-zt.z,zt.y,Rt.z,0,-Rt.x,Pt.z,0,-Pt.x,zt.z,0,-zt.x,-Rt.y,Rt.x,0,-Pt.y,Pt.x,0,-zt.y,zt.x,0];return!Ln(e,Zt,Jt,$t,qe)||(e=[1,0,0,0,1,0,0,0,1],!Ln(e,Zt,Jt,$t,qe))?!1:(Ye.crossVectors(Rt,Pt),e=[Ye.x,Ye.y,Ye.z],Ln(e,Zt,Jt,$t,qe))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,mt).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(mt).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(wt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),wt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),wt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),wt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),wt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),wt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),wt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),wt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(wt),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}},wt=[new M,new M,new M,new M,new M,new M,new M,new M],mt=new M,Xe=new W,Zt=new M,Jt=new M,$t=new M,Rt=new M,Pt=new M,zt=new M,Se=new M,qe=new M,Ye=new M,kt=new M;function Ln(c,t,e,n,i){for(let s=0,r=c.length-3;s<=r;s+=3){kt.fromArray(c,s);let a=i.x*Math.abs(kt.x)+i.y*Math.abs(kt.y)+i.z*Math.abs(kt.z),o=t.dot(kt),h=e.dot(kt),l=n.dot(kt);if(Math.max(-Math.max(o,h,l),Math.min(o,h,l))>a)return!1}return!0}var yr=new W,be=new M,Dn=new M,Re=class{constructor(t=new M,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){let n=this.center;e!==void 0?n.copy(e):yr.setFromPoints(t).getCenter(n);let i=0;for(let s=0,r=t.length;s<r;s++)i=Math.max(i,n.distanceToSquared(t[s]));return this.radius=Math.sqrt(i),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){let e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){let n=this.center.distanceToSquared(t);return e.copy(t),n>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;be.subVectors(t,this.center);let e=be.lengthSq();if(e>this.radius*this.radius){let n=Math.sqrt(e),i=(n-this.radius)*.5;this.center.addScaledVector(be,i/n),this.radius+=i}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(Dn.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(be.copy(t.center).add(Dn)),this.expandByPoint(be.copy(t.center).sub(Dn))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}};var G=class c{constructor(t,e,n,i,s,r,a,o,h,l,f,u,d,p,m,_){c.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,n,i,s,r,a,o,h,l,f,u,d,p,m,_)}set(t,e,n,i,s,r,a,o,h,l,f,u,d,p,m,_){let g=this.elements;return g[0]=t,g[4]=e,g[8]=n,g[12]=i,g[1]=s,g[5]=r,g[9]=a,g[13]=o,g[2]=h,g[6]=l,g[10]=f,g[14]=u,g[3]=d,g[7]=p,g[11]=m,g[15]=_,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 c().fromArray(this.elements)}copy(t){let e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){let e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){let e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){let e=this.elements,n=t.elements,i=1/Kt.setFromMatrixColumn(t,0).length(),s=1/Kt.setFromMatrixColumn(t,1).length(),r=1/Kt.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*s,e[5]=n[5]*s,e[6]=n[6]*s,e[7]=0,e[8]=n[8]*r,e[9]=n[9]*r,e[10]=n[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){let e=this.elements,n=t.x,i=t.y,s=t.z,r=Math.cos(n),a=Math.sin(n),o=Math.cos(i),h=Math.sin(i),l=Math.cos(s),f=Math.sin(s);if(t.order==="XYZ"){let u=r*l,d=r*f,p=a*l,m=a*f;e[0]=o*l,e[4]=-o*f,e[8]=h,e[1]=d+p*h,e[5]=u-m*h,e[9]=-a*o,e[2]=m-u*h,e[6]=p+d*h,e[10]=r*o}else if(t.order==="YXZ"){let u=o*l,d=o*f,p=h*l,m=h*f;e[0]=u+m*a,e[4]=p*a-d,e[8]=r*h,e[1]=r*f,e[5]=r*l,e[9]=-a,e[2]=d*a-p,e[6]=m+u*a,e[10]=r*o}else if(t.order==="ZXY"){let u=o*l,d=o*f,p=h*l,m=h*f;e[0]=u-m*a,e[4]=-r*f,e[8]=p+d*a,e[1]=d+p*a,e[5]=r*l,e[9]=m-u*a,e[2]=-r*h,e[6]=a,e[10]=r*o}else if(t.order==="ZYX"){let u=r*l,d=r*f,p=a*l,m=a*f;e[0]=o*l,e[4]=p*h-d,e[8]=u*h+m,e[1]=o*f,e[5]=m*h+u,e[9]=d*h-p,e[2]=-h,e[6]=a*o,e[10]=r*o}else if(t.order==="YZX"){let u=r*o,d=r*h,p=a*o,m=a*h;e[0]=o*l,e[4]=m-u*f,e[8]=p*f+d,e[1]=f,e[5]=r*l,e[9]=-a*l,e[2]=-h*l,e[6]=d*f+p,e[10]=u-m*f}else if(t.order==="XZY"){let u=r*o,d=r*h,p=a*o,m=a*h;e[0]=o*l,e[4]=-f,e[8]=h*l,e[1]=u*f+m,e[5]=r*l,e[9]=d*f-p,e[2]=p*f-d,e[6]=a*l,e[10]=m*f+u}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(vr,t,Mr)}lookAt(t,e,n){let i=this.elements;return ht.subVectors(t,e),ht.lengthSq()===0&&(ht.z=1),ht.normalize(),It.crossVectors(n,ht),It.lengthSq()===0&&(Math.abs(n.z)===1?ht.x+=1e-4:ht.z+=1e-4,ht.normalize(),It.crossVectors(n,ht)),It.normalize(),Ze.crossVectors(ht,It),i[0]=It.x,i[4]=Ze.x,i[8]=ht.x,i[1]=It.y,i[5]=Ze.y,i[9]=ht.y,i[2]=It.z,i[6]=Ze.z,i[10]=ht.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){let n=t.elements,i=e.elements,s=this.elements,r=n[0],a=n[4],o=n[8],h=n[12],l=n[1],f=n[5],u=n[9],d=n[13],p=n[2],m=n[6],_=n[10],g=n[14],x=n[3],v=n[7],S=n[11],y=n[15],w=i[0],b=i[4],A=i[8],T=i[12],E=i[1],R=i[5],C=i[9],P=i[13],L=i[2],U=i[6],z=i[10],lt=i[14],vt=i[3],Mt=i[7],Ve=i[11],He=i[15];return s[0]=r*w+a*E+o*L+h*vt,s[4]=r*b+a*R+o*U+h*Mt,s[8]=r*A+a*C+o*z+h*Ve,s[12]=r*T+a*P+o*lt+h*He,s[1]=l*w+f*E+u*L+d*vt,s[5]=l*b+f*R+u*U+d*Mt,s[9]=l*A+f*C+u*z+d*Ve,s[13]=l*T+f*P+u*lt+d*He,s[2]=p*w+m*E+_*L+g*vt,s[6]=p*b+m*R+_*U+g*Mt,s[10]=p*A+m*C+_*z+g*Ve,s[14]=p*T+m*P+_*lt+g*He,s[3]=x*w+v*E+S*L+y*vt,s[7]=x*b+v*R+S*U+y*Mt,s[11]=x*A+v*C+S*z+y*Ve,s[15]=x*T+v*P+S*lt+y*He,this}multiplyScalar(t){let e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){let t=this.elements,e=t[0],n=t[4],i=t[8],s=t[12],r=t[1],a=t[5],o=t[9],h=t[13],l=t[2],f=t[6],u=t[10],d=t[14],p=t[3],m=t[7],_=t[11],g=t[15];return p*(+s*o*f-i*h*f-s*a*u+n*h*u+i*a*d-n*o*d)+m*(+e*o*d-e*h*u+s*r*u-i*r*d+i*h*l-s*o*l)+_*(+e*h*f-e*a*d-s*r*f+n*r*d+s*a*l-n*h*l)+g*(-i*a*l-e*o*f+e*a*u+i*r*f-n*r*u+n*o*l)}transpose(){let t=this.elements,e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){let i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=n),this}invert(){let t=this.elements,e=t[0],n=t[1],i=t[2],s=t[3],r=t[4],a=t[5],o=t[6],h=t[7],l=t[8],f=t[9],u=t[10],d=t[11],p=t[12],m=t[13],_=t[14],g=t[15],x=f*_*h-m*u*h+m*o*d-a*_*d-f*o*g+a*u*g,v=p*u*h-l*_*h-p*o*d+r*_*d+l*o*g-r*u*g,S=l*m*h-p*f*h+p*a*d-r*m*d-l*a*g+r*f*g,y=p*f*o-l*m*o-p*a*u+r*m*u+l*a*_-r*f*_,w=e*x+n*v+i*S+s*y;if(w===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let b=1/w;return t[0]=x*b,t[1]=(m*u*s-f*_*s-m*i*d+n*_*d+f*i*g-n*u*g)*b,t[2]=(a*_*s-m*o*s+m*i*h-n*_*h-a*i*g+n*o*g)*b,t[3]=(f*o*s-a*u*s-f*i*h+n*u*h+a*i*d-n*o*d)*b,t[4]=v*b,t[5]=(l*_*s-p*u*s+p*i*d-e*_*d-l*i*g+e*u*g)*b,t[6]=(p*o*s-r*_*s-p*i*h+e*_*h+r*i*g-e*o*g)*b,t[7]=(r*u*s-l*o*s+l*i*h-e*u*h-r*i*d+e*o*d)*b,t[8]=S*b,t[9]=(p*f*s-l*m*s-p*n*d+e*m*d+l*n*g-e*f*g)*b,t[10]=(r*m*s-p*a*s+p*n*h-e*m*h-r*n*g+e*a*g)*b,t[11]=(l*a*s-r*f*s-l*n*h+e*f*h+r*n*d-e*a*d)*b,t[12]=y*b,t[13]=(l*m*i-p*f*i+p*n*u-e*m*u-l*n*_+e*f*_)*b,t[14]=(p*a*i-r*m*i-p*n*o+e*m*o+r*n*_-e*a*_)*b,t[15]=(r*f*i-l*a*i+l*n*o-e*f*o-r*n*u+e*a*u)*b,this}scale(t){let e=this.elements,n=t.x,i=t.y,s=t.z;return e[0]*=n,e[4]*=i,e[8]*=s,e[1]*=n,e[5]*=i,e[9]*=s,e[2]*=n,e[6]*=i,e[10]*=s,e[3]*=n,e[7]*=i,e[11]*=s,this}getMaxScaleOnAxis(){let t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,i))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){let e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){let e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){let e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){let n=Math.cos(e),i=Math.sin(e),s=1-n,r=t.x,a=t.y,o=t.z,h=s*r,l=s*a;return this.set(h*r+n,h*a-i*o,h*o+i*a,0,h*a+i*o,l*a+n,l*o-i*r,0,h*o-i*a,l*o+i*r,s*o*o+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,i,s,r){return this.set(1,n,s,0,t,1,r,0,e,i,1,0,0,0,0,1),this}compose(t,e,n){let i=this.elements,s=e._x,r=e._y,a=e._z,o=e._w,h=s+s,l=r+r,f=a+a,u=s*h,d=s*l,p=s*f,m=r*l,_=r*f,g=a*f,x=o*h,v=o*l,S=o*f,y=n.x,w=n.y,b=n.z;return i[0]=(1-(m+g))*y,i[1]=(d+S)*y,i[2]=(p-v)*y,i[3]=0,i[4]=(d-S)*w,i[5]=(1-(u+g))*w,i[6]=(_+x)*w,i[7]=0,i[8]=(p+v)*b,i[9]=(_-x)*b,i[10]=(1-(u+m))*b,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,n){let i=this.elements,s=Kt.set(i[0],i[1],i[2]).length(),r=Kt.set(i[4],i[5],i[6]).length(),a=Kt.set(i[8],i[9],i[10]).length();this.determinant()<0&&(s=-s),t.x=i[12],t.y=i[13],t.z=i[14],gt.copy(this);let h=1/s,l=1/r,f=1/a;return gt.elements[0]*=h,gt.elements[1]*=h,gt.elements[2]*=h,gt.elements[4]*=l,gt.elements[5]*=l,gt.elements[6]*=l,gt.elements[8]*=f,gt.elements[9]*=f,gt.elements[10]*=f,e.setFromRotationMatrix(gt),n.x=s,n.y=r,n.z=a,this}makePerspective(t,e,n,i,s,r,a=We){let o=this.elements,h=2*s/(e-t),l=2*s/(n-i),f=(e+t)/(e-t),u=(n+i)/(n-i),d,p;if(a===We)d=-(r+s)/(r-s),p=-2*r*s/(r-s);else if(a===ji)d=-r/(r-s),p=-r*s/(r-s);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return o[0]=h,o[4]=0,o[8]=f,o[12]=0,o[1]=0,o[5]=l,o[9]=u,o[13]=0,o[2]=0,o[6]=0,o[10]=d,o[14]=p,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,e,n,i,s,r,a=We){let o=this.elements,h=1/(e-t),l=1/(n-i),f=1/(r-s),u=(e+t)*h,d=(n+i)*l,p,m;if(a===We)p=(r+s)*f,m=-2*f;else if(a===ji)p=s*f,m=-1*f;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return o[0]=2*h,o[4]=0,o[8]=0,o[12]=-u,o[1]=0,o[5]=2*l,o[9]=0,o[13]=-d,o[2]=0,o[6]=0,o[10]=m,o[14]=-p,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){let e=this.elements,n=t.elements;for(let i=0;i<16;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){let n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}},Kt=new M,gt=new G,vr=new M(0,0,0),Mr=new M(1,1,1),It=new M,Ze=new M,ht=new M,ss=new G,rs=new Ut,en=class c{constructor(t=0,e=0,n=0,i=c.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,i=this._order){return this._x=t,this._y=e,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){let i=t.elements,s=i[0],r=i[4],a=i[8],o=i[1],h=i[5],l=i[9],f=i[2],u=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(nt(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-l,d),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(u,h),this._z=0);break;case"YXZ":this._x=Math.asin(-nt(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,h)):(this._y=Math.atan2(-f,s),this._z=0);break;case"ZXY":this._x=Math.asin(nt(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-f,d),this._z=Math.atan2(-r,h)):(this._y=0,this._z=Math.atan2(o,s));break;case"ZYX":this._y=Math.asin(-nt(f,-1,1)),Math.abs(f)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(o,s)):(this._x=0,this._z=Math.atan2(-r,h));break;case"YZX":this._z=Math.asin(nt(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-f,s)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-nt(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(u,h),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-l,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,n===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return ss.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ss,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return rs.setFromEuler(this),this.setFromQuaternion(rs,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};en.DEFAULT_ORDER="XYZ";var Jn=class{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}},Sr=0,os=new M,Qt=new Ut,At=new G,Je=new M,we=new M,br=new M,wr=new Ut,as=new M(1,0,0),cs=new M(0,1,0),ls=new M(0,0,1),hs={type:"added"},Ar={type:"removed"},jt={type:"childadded",child:null},Un={type:"childremoved",child:null},re=class c extends Te{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Sr++}),this.uuid=on(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=c.DEFAULT_UP.clone();let t=new M,e=new en,n=new Ut,i=new M(1,1,1);function s(){n.setFromEuler(e,!1)}function r(){e.setFromQuaternion(n,void 0,!1)}e._onChange(s),n._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:n},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new G},normalMatrix:{value:new D}}),this.matrix=new G,this.matrixWorld=new G,this.matrixAutoUpdate=c.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=c.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Jn,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Qt.setFromAxisAngle(t,e),this.quaternion.multiply(Qt),this}rotateOnWorldAxis(t,e){return Qt.setFromAxisAngle(t,e),this.quaternion.premultiply(Qt),this}rotateX(t){return this.rotateOnAxis(as,t)}rotateY(t){return this.rotateOnAxis(cs,t)}rotateZ(t){return this.rotateOnAxis(ls,t)}translateOnAxis(t,e){return os.copy(t).applyQuaternion(this.quaternion),this.position.add(os.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(as,t)}translateY(t){return this.translateOnAxis(cs,t)}translateZ(t){return this.translateOnAxis(ls,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(At.copy(this.matrixWorld).invert())}lookAt(t,e,n){t.isVector3?Je.copy(t):Je.set(t,e,n);let i=this.parent;this.updateWorldMatrix(!0,!1),we.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?At.lookAt(we,Je,this.up):At.lookAt(Je,we,this.up),this.quaternion.setFromRotationMatrix(At),i&&(At.extractRotation(i.matrixWorld),Qt.setFromRotationMatrix(At),this.quaternion.premultiply(Qt.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(hs),jt.child=t,this.dispatchEvent(jt),jt.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let n=0;n<arguments.length;n++)this.remove(arguments[n]);return this}let e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Ar),Un.child=t,this.dispatchEvent(Un),Un.child=null),this}removeFromParent(){let t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),At.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),At.multiply(t.parent.matrixWorld)),t.applyMatrix4(At),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(hs),jt.child=t,this.dispatchEvent(jt),jt.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let n=0,i=this.children.length;n<i;n++){let r=this.children[n].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,n=[]){this[t]===e&&n.push(this);let i=this.children;for(let s=0,r=i.length;s<r;s++)i[s].getObjectsByProperty(t,e,n);return n}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(we,t,br),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(we,wr,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);let e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);let e=this.children;for(let n=0,i=e.length;n<i;n++)e[n].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);let e=this.children;for(let n=0,i=e.length;n<i;n++)e[n].traverseVisible(t)}traverseAncestors(t){let e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);let e=this.children;for(let n=0,i=e.length;n<i;n++)e[n].updateMatrixWorld(t)}updateWorldMatrix(t,e){let n=this.parent;if(t===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){let i=this.children;for(let s=0,r=i.length;s<r;s++)i[s].updateWorldMatrix(!1,!0)}}toJSON(t){let e=t===void 0||typeof t=="string",n={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});let i={};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.castShadow===!0&&(i.castShadow=!0),this.receiveShadow===!0&&(i.receiveShadow=!0),this.visible===!1&&(i.visible=!1),this.frustumCulled===!1&&(i.frustumCulled=!1),this.renderOrder!==0&&(i.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.visibility=this._visibility,i.active=this._active,i.bounds=this._bounds.map(a=>({boxInitialized:a.boxInitialized,boxMin:a.box.min.toArray(),boxMax:a.box.max.toArray(),sphereInitialized:a.sphereInitialized,sphereRadius:a.sphere.radius,sphereCenter:a.sphere.center.toArray()})),i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.geometryCount=this._geometryCount,i.matricesTexture=this._matricesTexture.toJSON(t),this._colorsTexture!==null&&(i.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(i.boundingSphere={center:i.boundingSphere.center.toArray(),radius:i.boundingSphere.radius}),this.boundingBox!==null&&(i.boundingBox={min:i.boundingBox.min.toArray(),max:i.boundingBox.max.toArray()}));function s(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=s(t.geometries,this.geometry);let a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){let o=a.shapes;if(Array.isArray(o))for(let h=0,l=o.length;h<l;h++){let f=o[h];s(t.shapes,f)}else s(t.shapes,o)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(s(t.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){let a=[];for(let o=0,h=this.material.length;o<h;o++)a.push(s(t.materials,this.material[o]));i.material=a}else i.material=s(t.materials,this.material);if(this.children.length>0){i.children=[];for(let a=0;a<this.children.length;a++)i.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){i.animations=[];for(let a=0;a<this.animations.length;a++){let o=this.animations[a];i.animations.push(s(t.animations,o))}}if(e){let a=r(t.geometries),o=r(t.materials),h=r(t.textures),l=r(t.images),f=r(t.shapes),u=r(t.skeletons),d=r(t.animations),p=r(t.nodes);a.length>0&&(n.geometries=a),o.length>0&&(n.materials=o),h.length>0&&(n.textures=h),l.length>0&&(n.images=l),f.length>0&&(n.shapes=f),u.length>0&&(n.skeletons=u),d.length>0&&(n.animations=d),p.length>0&&(n.nodes=p)}return n.object=i,n;function r(a){let o=[];for(let h in a){let l=a[h];delete l.metadata,o.push(l)}return o}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let n=0;n<t.children.length;n++){let i=t.children[n];this.add(i.clone())}return this}};re.DEFAULT_UP=new M(0,1,0);re.DEFAULT_MATRIX_AUTO_UPDATE=!0;re.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;var _t=new M,Tt=new M,Nn=new M,Et=new M,te=new M,ee=new M,us=new M,Fn=new M,Bn=new M,On=new M,zn=new Ce,kn=new Ce,Vn=new Ce,St=class c{constructor(t=new M,e=new M,n=new M){this.a=t,this.b=e,this.c=n}static getNormal(t,e,n,i){i.subVectors(n,e),_t.subVectors(t,e),i.cross(_t);let s=i.lengthSq();return s>0?i.multiplyScalar(1/Math.sqrt(s)):i.set(0,0,0)}static getBarycoord(t,e,n,i,s){_t.subVectors(i,e),Tt.subVectors(n,e),Nn.subVectors(t,e);let r=_t.dot(_t),a=_t.dot(Tt),o=_t.dot(Nn),h=Tt.dot(Tt),l=Tt.dot(Nn),f=r*h-a*a;if(f===0)return s.set(0,0,0),null;let u=1/f,d=(h*o-a*l)*u,p=(r*l-a*o)*u;return s.set(1-d-p,p,d)}static containsPoint(t,e,n,i){return this.getBarycoord(t,e,n,i,Et)===null?!1:Et.x>=0&&Et.y>=0&&Et.x+Et.y<=1}static getInterpolation(t,e,n,i,s,r,a,o){return this.getBarycoord(t,e,n,i,Et)===null?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(s,Et.x),o.addScaledVector(r,Et.y),o.addScaledVector(a,Et.z),o)}static getInterpolatedAttribute(t,e,n,i,s,r){return zn.setScalar(0),kn.setScalar(0),Vn.setScalar(0),zn.fromBufferAttribute(t,e),kn.fromBufferAttribute(t,n),Vn.fromBufferAttribute(t,i),r.setScalar(0),r.addScaledVector(zn,s.x),r.addScaledVector(kn,s.y),r.addScaledVector(Vn,s.z),r}static isFrontFacing(t,e,n,i){return _t.subVectors(n,e),Tt.subVectors(t,e),_t.cross(Tt).dot(i)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,n,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,i),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return _t.subVectors(this.c,this.b),Tt.subVectors(this.a,this.b),_t.cross(Tt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return c.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return c.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,s){return c.getInterpolation(t,this.a,this.b,this.c,e,n,i,s)}containsPoint(t){return c.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return c.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){let n=this.a,i=this.b,s=this.c,r,a;te.subVectors(i,n),ee.subVectors(s,n),Fn.subVectors(t,n);let o=te.dot(Fn),h=ee.dot(Fn);if(o<=0&&h<=0)return e.copy(n);Bn.subVectors(t,i);let l=te.dot(Bn),f=ee.dot(Bn);if(l>=0&&f<=l)return e.copy(i);let u=o*f-l*h;if(u<=0&&o>=0&&l<=0)return r=o/(o-l),e.copy(n).addScaledVector(te,r);On.subVectors(t,s);let d=te.dot(On),p=ee.dot(On);if(p>=0&&d<=p)return e.copy(s);let m=d*h-o*p;if(m<=0&&h>=0&&p<=0)return a=h/(h-p),e.copy(n).addScaledVector(ee,a);let _=l*p-d*f;if(_<=0&&f-l>=0&&d-p>=0)return us.subVectors(s,i),a=(f-l)/(f-l+(d-p)),e.copy(i).addScaledVector(us,a);let g=1/(_+m+u);return r=m*g,a=u*g,e.copy(n).addScaledVector(te,r).addScaledVector(ee,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}},ys={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},Lt={h:0,s:0,l:0},$e={h:0,s:0,l:0};function Hn(c,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?c+(t-c)*6*e:e<1/2?t:e<2/3?c+(t-c)*6*(2/3-e):c}var Q=class{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(e===void 0&&n===void 0){let i=t;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Dt){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,pt.toWorkingColorSpace(this,e),this}setRGB(t,e,n,i=pt.workingColorSpace){return this.r=t,this.g=e,this.b=n,pt.toWorkingColorSpace(this,i),this}setHSL(t,e,n,i=pt.workingColorSpace){if(t=pr(t,1),e=nt(e,0,1),n=nt(n,0,1),e===0)this.r=this.g=this.b=n;else{let s=n<=.5?n*(1+e):n+e-n*e,r=2*n-s;this.r=Hn(r,s,t+1/3),this.g=Hn(r,s,t),this.b=Hn(r,s,t-1/3)}return pt.toWorkingColorSpace(this,i),this}setStyle(t,e=Dt){function n(s){s!==void 0&&parseFloat(s)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let s,r=i[1],a=i[2];switch(r){case"rgb":case"rgba":if(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,e);if(s=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setRGB(Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,e);break;case"hsl":case"hsla":if(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(s[4]),this.setHSL(parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){let s=i[1],r=s.length;if(r===3)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(r===6)return this.setHex(parseInt(s,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Dt){let n=ys[t.toLowerCase()];return n!==void 0?this.setHex(n,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=se(t.r),this.g=se(t.g),this.b=se(t.b),this}copyLinearToSRGB(t){return this.r=Rn(t.r),this.g=Rn(t.g),this.b=Rn(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Dt){return pt.fromWorkingColorSpace(et.copy(this),t),Math.round(nt(et.r*255,0,255))*65536+Math.round(nt(et.g*255,0,255))*256+Math.round(nt(et.b*255,0,255))}getHexString(t=Dt){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=pt.workingColorSpace){pt.fromWorkingColorSpace(et.copy(this),e);let n=et.r,i=et.g,s=et.b,r=Math.max(n,i,s),a=Math.min(n,i,s),o,h,l=(a+r)/2;if(a===r)o=0,h=0;else{let f=r-a;switch(h=l<=.5?f/(r+a):f/(2-r-a),r){case n:o=(i-s)/f+(i<s?6:0);break;case i:o=(s-n)/f+2;break;case s:o=(n-i)/f+4;break}o/=6}return t.h=o,t.s=h,t.l=l,t}getRGB(t,e=pt.workingColorSpace){return pt.fromWorkingColorSpace(et.copy(this),e),t.r=et.r,t.g=et.g,t.b=et.b,t}getStyle(t=Dt){pt.fromWorkingColorSpace(et.copy(this),t);let e=et.r,n=et.g,i=et.b;return t!==Dt?`color(${t} ${e.toFixed(3)} ${n.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(n*255)},${Math.round(i*255)})`}offsetHSL(t,e,n){return this.getHSL(Lt),this.setHSL(Lt.h+t,Lt.s+e,Lt.l+n)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,n){return this.r=t.r+(e.r-t.r)*n,this.g=t.g+(e.g-t.g)*n,this.b=t.b+(e.b-t.b)*n,this}lerpHSL(t,e){this.getHSL(Lt),t.getHSL($e);let n=En(Lt.h,$e.h,e),i=En(Lt.s,$e.s,e),s=En(Lt.l,$e.l,e);return this.setHSL(n,i,s),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){let e=this.r,n=this.g,i=this.b,s=t.elements;return this.r=s[0]*e+s[3]*n+s[6]*i,this.g=s[1]*e+s[4]*n+s[7]*i,this.b=s[2]*e+s[5]*n+s[8]*i,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}},et=new Q;Q.NAMES=ys;var Y=new M,Ke=new H,it=class{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=n,this.usage=Qi,this.updateRanges=[],this.gpuType=ur,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let i=0,s=this.itemSize;i<s;i++)this.array[t+i]=e.array[n+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,n=this.count;e<n;e++)Ke.fromBufferAttribute(this,e),Ke.applyMatrix3(t),this.setXY(e,Ke.x,Ke.y);else if(this.itemSize===3)for(let e=0,n=this.count;e<n;e++)Y.fromBufferAttribute(this,e),Y.applyMatrix3(t),this.setXYZ(e,Y.x,Y.y,Y.z);return this}applyMatrix4(t){for(let e=0,n=this.count;e<n;e++)Y.fromBufferAttribute(this,e),Y.applyMatrix4(t),this.setXYZ(e,Y.x,Y.y,Y.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)Y.fromBufferAttribute(this,e),Y.applyNormalMatrix(t),this.setXYZ(e,Y.x,Y.y,Y.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)Y.fromBufferAttribute(this,e),Y.transformDirection(t),this.setXYZ(e,Y.x,Y.y,Y.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let n=this.array[t*this.itemSize+e];return this.normalized&&(n=ve(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=rt(n,this.array)),this.array[t*this.itemSize+e]=n,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=ve(e,this.array)),e}setX(t,e){return this.normalized&&(e=rt(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=ve(e,this.array)),e}setY(t,e){return this.normalized&&(e=rt(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=ve(e,this.array)),e}setZ(t,e){return this.normalized&&(e=rt(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=ve(e,this.array)),e}setW(t,e){return this.normalized&&(e=rt(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=rt(e,this.array),n=rt(n,this.array)),this.array[t+0]=e,this.array[t+1]=n,this}setXYZ(t,e,n,i){return t*=this.itemSize,this.normalized&&(e=rt(e,this.array),n=rt(n,this.array),i=rt(i,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=i,this}setXYZW(t,e,n,i,s){return t*=this.itemSize,this.normalized&&(e=rt(e,this.array),n=rt(n,this.array),i=rt(i,this.array),s=rt(s,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=i,this.array[t+3]=s,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){let t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==Qi&&(t.usage=this.usage),t}};var $n=class extends it{constructor(t,e,n){super(new Uint16Array(t),e,n)}};var Kn=class extends it{constructor(t,e,n){super(new Uint32Array(t),e,n)}};var Qn=class extends it{constructor(t,e,n){super(new Float32Array(t),e,n)}},Tr=0,ft=new G,Gn=new re,ne=new M,ut=new W,Ae=new W,J=new M,nn=class c extends Te{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:Tr++}),this.uuid=on(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(mr(t)?Kn:$n)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,n=0){this.groups.push({start:t,count:e,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){let e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);let n=this.attributes.normal;if(n!==void 0){let s=new D().getNormalMatrix(t);n.applyNormalMatrix(s),n.needsUpdate=!0}let i=this.attributes.tangent;return i!==void 0&&(i.transformDirection(t),i.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return ft.makeRotationFromQuaternion(t),this.applyMatrix4(ft),this}rotateX(t){return ft.makeRotationX(t),this.applyMatrix4(ft),this}rotateY(t){return ft.makeRotationY(t),this.applyMatrix4(ft),this}rotateZ(t){return ft.makeRotationZ(t),this.applyMatrix4(ft),this}translate(t,e,n){return ft.makeTranslation(t,e,n),this.applyMatrix4(ft),this}scale(t,e,n){return ft.makeScale(t,e,n),this.applyMatrix4(ft),this}lookAt(t){return Gn.lookAt(t),Gn.updateMatrix(),this.applyMatrix4(Gn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ne).negate(),this.translate(ne.x,ne.y,ne.z),this}setFromPoints(t){let e=[];for(let n=0,i=t.length;n<i;n++){let s=t[n];e.push(s.x,s.y,s.z||0)}return this.setAttribute("position",new Qn(e,3)),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new W);let t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new M(-1/0,-1/0,-1/0),new M(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let n=0,i=e.length;n<i;n++){let s=e[n];ut.setFromBufferAttribute(s),this.morphTargetsRelative?(J.addVectors(this.boundingBox.min,ut.min),this.boundingBox.expandByPoint(J),J.addVectors(this.boundingBox.max,ut.max),this.boundingBox.expandByPoint(J)):(this.boundingBox.expandByPoint(ut.min),this.boundingBox.expandByPoint(ut.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.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 Re);let t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new M,1/0);return}if(t){let n=this.boundingSphere.center;if(ut.setFromBufferAttribute(t),e)for(let s=0,r=e.length;s<r;s++){let a=e[s];Ae.setFromBufferAttribute(a),this.morphTargetsRelative?(J.addVectors(ut.min,Ae.min),ut.expandByPoint(J),J.addVectors(ut.max,Ae.max),ut.expandByPoint(J)):(ut.expandByPoint(Ae.min),ut.expandByPoint(Ae.max))}ut.getCenter(n);let i=0;for(let s=0,r=t.count;s<r;s++)J.fromBufferAttribute(t,s),i=Math.max(i,n.distanceToSquared(J));if(e)for(let s=0,r=e.length;s<r;s++){let a=e[s],o=this.morphTargetsRelative;for(let h=0,l=a.count;h<l;h++)J.fromBufferAttribute(a,h),o&&(ne.fromBufferAttribute(t,h),J.add(ne)),i=Math.max(i,n.distanceToSquared(J))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){let t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}let n=e.position,i=e.normal,s=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new it(new Float32Array(4*n.count),4));let r=this.getAttribute("tangent"),a=[],o=[];for(let A=0;A<n.count;A++)a[A]=new M,o[A]=new M;let h=new M,l=new M,f=new M,u=new H,d=new H,p=new H,m=new M,_=new M;function g(A,T,E){h.fromBufferAttribute(n,A),l.fromBufferAttribute(n,T),f.fromBufferAttribute(n,E),u.fromBufferAttribute(s,A),d.fromBufferAttribute(s,T),p.fromBufferAttribute(s,E),l.sub(h),f.sub(h),d.sub(u),p.sub(u);let R=1/(d.x*p.y-p.x*d.y);isFinite(R)&&(m.copy(l).multiplyScalar(p.y).addScaledVector(f,-d.y).multiplyScalar(R),_.copy(f).multiplyScalar(d.x).addScaledVector(l,-p.x).multiplyScalar(R),a[A].add(m),a[T].add(m),a[E].add(m),o[A].add(_),o[T].add(_),o[E].add(_))}let x=this.groups;x.length===0&&(x=[{start:0,count:t.count}]);for(let A=0,T=x.length;A<T;++A){let E=x[A],R=E.start,C=E.count;for(let P=R,L=R+C;P<L;P+=3)g(t.getX(P+0),t.getX(P+1),t.getX(P+2))}let v=new M,S=new M,y=new M,w=new M;function b(A){y.fromBufferAttribute(i,A),w.copy(y);let T=a[A];v.copy(T),v.sub(y.multiplyScalar(y.dot(T))).normalize(),S.crossVectors(w,T);let R=S.dot(o[A])<0?-1:1;r.setXYZW(A,v.x,v.y,v.z,R)}for(let A=0,T=x.length;A<T;++A){let E=x[A],R=E.start,C=E.count;for(let P=R,L=R+C;P<L;P+=3)b(t.getX(P+0)),b(t.getX(P+1)),b(t.getX(P+2))}}computeVertexNormals(){let t=this.index,e=this.getAttribute("position");if(e!==void 0){let n=this.getAttribute("normal");if(n===void 0)n=new it(new Float32Array(e.count*3),3),this.setAttribute("normal",n);else for(let u=0,d=n.count;u<d;u++)n.setXYZ(u,0,0,0);let i=new M,s=new M,r=new M,a=new M,o=new M,h=new M,l=new M,f=new M;if(t)for(let u=0,d=t.count;u<d;u+=3){let p=t.getX(u+0),m=t.getX(u+1),_=t.getX(u+2);i.fromBufferAttribute(e,p),s.fromBufferAttribute(e,m),r.fromBufferAttribute(e,_),l.subVectors(r,s),f.subVectors(i,s),l.cross(f),a.fromBufferAttribute(n,p),o.fromBufferAttribute(n,m),h.fromBufferAttribute(n,_),a.add(l),o.add(l),h.add(l),n.setXYZ(p,a.x,a.y,a.z),n.setXYZ(m,o.x,o.y,o.z),n.setXYZ(_,h.x,h.y,h.z)}else for(let u=0,d=e.count;u<d;u+=3)i.fromBufferAttribute(e,u+0),s.fromBufferAttribute(e,u+1),r.fromBufferAttribute(e,u+2),l.subVectors(r,s),f.subVectors(i,s),l.cross(f),n.setXYZ(u+0,l.x,l.y,l.z),n.setXYZ(u+1,l.x,l.y,l.z),n.setXYZ(u+2,l.x,l.y,l.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){let t=this.attributes.normal;for(let e=0,n=t.count;e<n;e++)J.fromBufferAttribute(t,e),J.normalize(),t.setXYZ(e,J.x,J.y,J.z)}toNonIndexed(){function t(a,o){let h=a.array,l=a.itemSize,f=a.normalized,u=new h.constructor(o.length*l),d=0,p=0;for(let m=0,_=o.length;m<_;m++){a.isInterleavedBufferAttribute?d=o[m]*a.data.stride+a.offset:d=o[m]*l;for(let g=0;g<l;g++)u[p++]=h[d++]}return new it(u,l,f)}if(this.index===null)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;let e=new c,n=this.index.array,i=this.attributes;for(let a in i){let o=i[a],h=t(o,n);e.setAttribute(a,h)}let s=this.morphAttributes;for(let a in s){let o=[],h=s[a];for(let l=0,f=h.length;l<f;l++){let u=h[l],d=t(u,n);o.push(d)}e.morphAttributes[a]=o}e.morphTargetsRelative=this.morphTargetsRelative;let r=this.groups;for(let a=0,o=r.length;a<o;a++){let h=r[a];e.addGroup(h.start,h.count,h.materialIndex)}return e}toJSON(){let t={metadata:{version:4.6,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0){let o=this.parameters;for(let h in o)o[h]!==void 0&&(t[h]=o[h]);return t}t.data={attributes:{}};let e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});let n=this.attributes;for(let o in n){let h=n[o];t.data.attributes[o]=h.toJSON(t.data)}let i={},s=!1;for(let o in this.morphAttributes){let h=this.morphAttributes[o],l=[];for(let f=0,u=h.length;f<u;f++){let d=h[f];l.push(d.toJSON(t.data))}l.length>0&&(i[o]=l,s=!0)}s&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);let r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));let a=this.boundingSphere;return a!==null&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;let e={};this.name=t.name;let n=t.index;n!==null&&this.setIndex(n.clone(e));let i=t.attributes;for(let h in i){let l=i[h];this.setAttribute(h,l.clone(e))}let s=t.morphAttributes;for(let h in s){let l=[],f=s[h];for(let u=0,d=f.length;u<d;u++)l.push(f[u].clone(e));this.morphAttributes[h]=l}this.morphTargetsRelative=t.morphTargetsRelative;let r=t.groups;for(let h=0,l=r.length;h<l;h++){let f=r[h];this.addGroup(f.start,f.count,f.materialIndex)}let a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());let o=t.boundingSphere;return o!==null&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}};function Er(c){let t={};for(let e in c){t[e]={};for(let n in c[e]){let i=c[e][n];i&&(i.isColor||i.isMatrix3||i.isMatrix4||i.isVector2||i.isVector3||i.isVector4||i.isTexture||i.isQuaternion)?i.isRenderTargetTexture?(console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),t[e][n]=null):t[e][n]=i.clone():Array.isArray(i)?t[e][n]=i.slice():t[e][n]=i}}return t}function ot(c){let t={};for(let e=0;e<c.length;e++){let n=Er(c[e]);for(let i in n)t[i]=n[i]}return t}var Wn=new M,Cr=new M,Rr=new D,oe=class{constructor(t=new M(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,n,i){return this.normal.set(t,e,n),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){let i=Wn.subVectors(n,e).cross(Cr.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){let t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){let n=t.delta(Wn),i=this.normal.dot(n);if(i===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;let s=-(t.start.dot(this.normal)+this.constant)/i;return s<0||s>1?null:e.copy(t.start).addScaledVector(n,s)}intersectsLine(t){let e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){let n=e||Rr.getNormalMatrix(t),i=this.coplanarPoint(Wn).applyMatrix4(t),s=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(s),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}};var Pr=`#ifdef USE_ALPHAHASH
  2. if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
  3. #endif`,Ir=`#ifdef USE_ALPHAHASH
  4. const float ALPHA_HASH_SCALE = 0.05;
  5. float hash2D( vec2 value ) {
  6. return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
  7. }
  8. float hash3D( vec3 value ) {
  9. return hash2D( vec2( hash2D( value.xy ), value.z ) );
  10. }
  11. float getAlphaHashThreshold( vec3 position ) {
  12. float maxDeriv = max(
  13. length( dFdx( position.xyz ) ),
  14. length( dFdy( position.xyz ) )
  15. );
  16. float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
  17. vec2 pixScales = vec2(
  18. exp2( floor( log2( pixScale ) ) ),
  19. exp2( ceil( log2( pixScale ) ) )
  20. );
  21. vec2 alpha = vec2(
  22. hash3D( floor( pixScales.x * position.xyz ) ),
  23. hash3D( floor( pixScales.y * position.xyz ) )
  24. );
  25. float lerpFactor = fract( log2( pixScale ) );
  26. float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;
  27. float a = min( lerpFactor, 1.0 - lerpFactor );
  28. vec3 cases = vec3(
  29. x * x / ( 2.0 * a * ( 1.0 - a ) ),
  30. ( x - 0.5 * a ) / ( 1.0 - a ),
  31. 1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
  32. );
  33. float threshold = ( x < ( 1.0 - a ) )
  34. ? ( ( x < a ) ? cases.x : cases.y )
  35. : cases.z;
  36. return clamp( threshold , 1.0e-6, 1.0 );
  37. }
  38. #endif`,Lr=`#ifdef USE_ALPHAMAP
  39. diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
  40. #endif`,Dr=`#ifdef USE_ALPHAMAP
  41. uniform sampler2D alphaMap;
  42. #endif`,Ur=`#ifdef USE_ALPHATEST
  43. #ifdef ALPHA_TO_COVERAGE
  44. diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );
  45. if ( diffuseColor.a == 0.0 ) discard;
  46. #else
  47. if ( diffuseColor.a < alphaTest ) discard;
  48. #endif
  49. #endif`,Nr=`#ifdef USE_ALPHATEST
  50. uniform float alphaTest;
  51. #endif`,Fr=`#ifdef USE_AOMAP
  52. float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
  53. reflectedLight.indirectDiffuse *= ambientOcclusion;
  54. #if defined( USE_CLEARCOAT )
  55. clearcoatSpecularIndirect *= ambientOcclusion;
  56. #endif
  57. #if defined( USE_SHEEN )
  58. sheenSpecularIndirect *= ambientOcclusion;
  59. #endif
  60. #if defined( USE_ENVMAP ) && defined( STANDARD )
  61. float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
  62. reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
  63. #endif
  64. #endif`,Br=`#ifdef USE_AOMAP
  65. uniform sampler2D aoMap;
  66. uniform float aoMapIntensity;
  67. #endif`,Or=`#ifdef USE_BATCHING
  68. #if ! defined( GL_ANGLE_multi_draw )
  69. #define gl_DrawID _gl_DrawID
  70. uniform int _gl_DrawID;
  71. #endif
  72. uniform highp sampler2D batchingTexture;
  73. uniform highp usampler2D batchingIdTexture;
  74. mat4 getBatchingMatrix( const in float i ) {
  75. int size = textureSize( batchingTexture, 0 ).x;
  76. int j = int( i ) * 4;
  77. int x = j % size;
  78. int y = j / size;
  79. vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
  80. vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
  81. vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
  82. vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
  83. return mat4( v1, v2, v3, v4 );
  84. }
  85. float getIndirectIndex( const in int i ) {
  86. int size = textureSize( batchingIdTexture, 0 ).x;
  87. int x = i % size;
  88. int y = i / size;
  89. return float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );
  90. }
  91. #endif
  92. #ifdef USE_BATCHING_COLOR
  93. uniform sampler2D batchingColorTexture;
  94. vec3 getBatchingColor( const in float i ) {
  95. int size = textureSize( batchingColorTexture, 0 ).x;
  96. int j = int( i );
  97. int x = j % size;
  98. int y = j / size;
  99. return texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;
  100. }
  101. #endif`,zr=`#ifdef USE_BATCHING
  102. mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
  103. #endif`,kr=`vec3 transformed = vec3( position );
  104. #ifdef USE_ALPHAHASH
  105. vPosition = vec3( position );
  106. #endif`,Vr=`vec3 objectNormal = vec3( normal );
  107. #ifdef USE_TANGENT
  108. vec3 objectTangent = vec3( tangent.xyz );
  109. #endif`,Hr=`float G_BlinnPhong_Implicit( ) {
  110. return 0.25;
  111. }
  112. float D_BlinnPhong( const in float shininess, const in float dotNH ) {
  113. return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
  114. }
  115. vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
  116. vec3 halfDir = normalize( lightDir + viewDir );
  117. float dotNH = saturate( dot( normal, halfDir ) );
  118. float dotVH = saturate( dot( viewDir, halfDir ) );
  119. vec3 F = F_Schlick( specularColor, 1.0, dotVH );
  120. float G = G_BlinnPhong_Implicit( );
  121. float D = D_BlinnPhong( shininess, dotNH );
  122. return F * ( G * D );
  123. } // validated`,Gr=`#ifdef USE_IRIDESCENCE
  124. const mat3 XYZ_TO_REC709 = mat3(
  125. 3.2404542, -0.9692660, 0.0556434,
  126. -1.5371385, 1.8760108, -0.2040259,
  127. -0.4985314, 0.0415560, 1.0572252
  128. );
  129. vec3 Fresnel0ToIor( vec3 fresnel0 ) {
  130. vec3 sqrtF0 = sqrt( fresnel0 );
  131. return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
  132. }
  133. vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {
  134. return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
  135. }
  136. float IorToFresnel0( float transmittedIor, float incidentIor ) {
  137. return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));
  138. }
  139. vec3 evalSensitivity( float OPD, vec3 shift ) {
  140. float phase = 2.0 * PI * OPD * 1.0e-9;
  141. vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
  142. vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
  143. vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
  144. vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );
  145. 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 ) );
  146. xyz /= 1.0685e-7;
  147. vec3 rgb = XYZ_TO_REC709 * xyz;
  148. return rgb;
  149. }
  150. vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
  151. vec3 I;
  152. float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
  153. float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );
  154. float cosTheta2Sq = 1.0 - sinTheta2Sq;
  155. if ( cosTheta2Sq < 0.0 ) {
  156. return vec3( 1.0 );
  157. }
  158. float cosTheta2 = sqrt( cosTheta2Sq );
  159. float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
  160. float R12 = F_Schlick( R0, 1.0, cosTheta1 );
  161. float T121 = 1.0 - R12;
  162. float phi12 = 0.0;
  163. if ( iridescenceIOR < outsideIOR ) phi12 = PI;
  164. float phi21 = PI - phi12;
  165. vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );
  166. vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );
  167. vec3 phi23 = vec3( 0.0 );
  168. if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;
  169. if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;
  170. if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;
  171. float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;
  172. vec3 phi = vec3( phi21 ) + phi23;
  173. vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
  174. vec3 r123 = sqrt( R123 );
  175. vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
  176. vec3 C0 = R12 + Rs;
  177. I = C0;
  178. vec3 Cm = Rs - T121;
  179. for ( int m = 1; m <= 2; ++ m ) {
  180. Cm *= r123;
  181. vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
  182. I += Cm * Sm;
  183. }
  184. return max( I, vec3( 0.0 ) );
  185. }
  186. #endif`,Wr=`#ifdef USE_BUMPMAP
  187. uniform sampler2D bumpMap;
  188. uniform float bumpScale;
  189. vec2 dHdxy_fwd() {
  190. vec2 dSTdx = dFdx( vBumpMapUv );
  191. vec2 dSTdy = dFdy( vBumpMapUv );
  192. float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;
  193. float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;
  194. float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;
  195. return vec2( dBx, dBy );
  196. }
  197. vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
  198. vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
  199. vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
  200. vec3 vN = surf_norm;
  201. vec3 R1 = cross( vSigmaY, vN );
  202. vec3 R2 = cross( vN, vSigmaX );
  203. float fDet = dot( vSigmaX, R1 ) * faceDirection;
  204. vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
  205. return normalize( abs( fDet ) * surf_norm - vGrad );
  206. }
  207. #endif`,Xr=`#if NUM_CLIPPING_PLANES > 0
  208. vec4 plane;
  209. #ifdef ALPHA_TO_COVERAGE
  210. float distanceToPlane, distanceGradient;
  211. float clipOpacity = 1.0;
  212. #pragma unroll_loop_start
  213. for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
  214. plane = clippingPlanes[ i ];
  215. distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
  216. distanceGradient = fwidth( distanceToPlane ) / 2.0;
  217. clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
  218. if ( clipOpacity == 0.0 ) discard;
  219. }
  220. #pragma unroll_loop_end
  221. #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
  222. float unionClipOpacity = 1.0;
  223. #pragma unroll_loop_start
  224. for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
  225. plane = clippingPlanes[ i ];
  226. distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
  227. distanceGradient = fwidth( distanceToPlane ) / 2.0;
  228. unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
  229. }
  230. #pragma unroll_loop_end
  231. clipOpacity *= 1.0 - unionClipOpacity;
  232. #endif
  233. diffuseColor.a *= clipOpacity;
  234. if ( diffuseColor.a == 0.0 ) discard;
  235. #else
  236. #pragma unroll_loop_start
  237. for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
  238. plane = clippingPlanes[ i ];
  239. if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
  240. }
  241. #pragma unroll_loop_end
  242. #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
  243. bool clipped = true;
  244. #pragma unroll_loop_start
  245. for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
  246. plane = clippingPlanes[ i ];
  247. clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
  248. }
  249. #pragma unroll_loop_end
  250. if ( clipped ) discard;
  251. #endif
  252. #endif
  253. #endif`,qr=`#if NUM_CLIPPING_PLANES > 0
  254. varying vec3 vClipPosition;
  255. uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
  256. #endif`,Yr=`#if NUM_CLIPPING_PLANES > 0
  257. varying vec3 vClipPosition;
  258. #endif`,Zr=`#if NUM_CLIPPING_PLANES > 0
  259. vClipPosition = - mvPosition.xyz;
  260. #endif`,Jr=`#if defined( USE_COLOR_ALPHA )
  261. diffuseColor *= vColor;
  262. #elif defined( USE_COLOR )
  263. diffuseColor.rgb *= vColor;
  264. #endif`,$r=`#if defined( USE_COLOR_ALPHA )
  265. varying vec4 vColor;
  266. #elif defined( USE_COLOR )
  267. varying vec3 vColor;
  268. #endif`,Kr=`#if defined( USE_COLOR_ALPHA )
  269. varying vec4 vColor;
  270. #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
  271. varying vec3 vColor;
  272. #endif`,Qr=`#if defined( USE_COLOR_ALPHA )
  273. vColor = vec4( 1.0 );
  274. #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
  275. vColor = vec3( 1.0 );
  276. #endif
  277. #ifdef USE_COLOR
  278. vColor *= color;
  279. #endif
  280. #ifdef USE_INSTANCING_COLOR
  281. vColor.xyz *= instanceColor.xyz;
  282. #endif
  283. #ifdef USE_BATCHING_COLOR
  284. vec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );
  285. vColor.xyz *= batchingColor.xyz;
  286. #endif`,jr=`#define PI 3.141592653589793
  287. #define PI2 6.283185307179586
  288. #define PI_HALF 1.5707963267948966
  289. #define RECIPROCAL_PI 0.3183098861837907
  290. #define RECIPROCAL_PI2 0.15915494309189535
  291. #define EPSILON 1e-6
  292. #ifndef saturate
  293. #define saturate( a ) clamp( a, 0.0, 1.0 )
  294. #endif
  295. #define whiteComplement( a ) ( 1.0 - saturate( a ) )
  296. float pow2( const in float x ) { return x*x; }
  297. vec3 pow2( const in vec3 x ) { return x*x; }
  298. float pow3( const in float x ) { return x*x*x; }
  299. float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
  300. float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
  301. float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
  302. highp float rand( const in vec2 uv ) {
  303. const highp float a = 12.9898, b = 78.233, c = 43758.5453;
  304. highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
  305. return fract( sin( sn ) * c );
  306. }
  307. #ifdef HIGH_PRECISION
  308. float precisionSafeLength( vec3 v ) { return length( v ); }
  309. #else
  310. float precisionSafeLength( vec3 v ) {
  311. float maxComponent = max3( abs( v ) );
  312. return length( v / maxComponent ) * maxComponent;
  313. }
  314. #endif
  315. struct IncidentLight {
  316. vec3 color;
  317. vec3 direction;
  318. bool visible;
  319. };
  320. struct ReflectedLight {
  321. vec3 directDiffuse;
  322. vec3 directSpecular;
  323. vec3 indirectDiffuse;
  324. vec3 indirectSpecular;
  325. };
  326. #ifdef USE_ALPHAHASH
  327. varying vec3 vPosition;
  328. #endif
  329. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  330. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  331. }
  332. vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
  333. return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
  334. }
  335. mat3 transposeMat3( const in mat3 m ) {
  336. mat3 tmp;
  337. tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
  338. tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
  339. tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
  340. return tmp;
  341. }
  342. bool isPerspectiveMatrix( mat4 m ) {
  343. return m[ 2 ][ 3 ] == - 1.0;
  344. }
  345. vec2 equirectUv( in vec3 dir ) {
  346. float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
  347. float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
  348. return vec2( u, v );
  349. }
  350. vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
  351. return RECIPROCAL_PI * diffuseColor;
  352. }
  353. vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
  354. float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
  355. return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
  356. }
  357. float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
  358. float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
  359. return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
  360. } // validated`,to=`#ifdef ENVMAP_TYPE_CUBE_UV
  361. #define cubeUV_minMipLevel 4.0
  362. #define cubeUV_minTileSize 16.0
  363. float getFace( vec3 direction ) {
  364. vec3 absDirection = abs( direction );
  365. float face = - 1.0;
  366. if ( absDirection.x > absDirection.z ) {
  367. if ( absDirection.x > absDirection.y )
  368. face = direction.x > 0.0 ? 0.0 : 3.0;
  369. else
  370. face = direction.y > 0.0 ? 1.0 : 4.0;
  371. } else {
  372. if ( absDirection.z > absDirection.y )
  373. face = direction.z > 0.0 ? 2.0 : 5.0;
  374. else
  375. face = direction.y > 0.0 ? 1.0 : 4.0;
  376. }
  377. return face;
  378. }
  379. vec2 getUV( vec3 direction, float face ) {
  380. vec2 uv;
  381. if ( face == 0.0 ) {
  382. uv = vec2( direction.z, direction.y ) / abs( direction.x );
  383. } else if ( face == 1.0 ) {
  384. uv = vec2( - direction.x, - direction.z ) / abs( direction.y );
  385. } else if ( face == 2.0 ) {
  386. uv = vec2( - direction.x, direction.y ) / abs( direction.z );
  387. } else if ( face == 3.0 ) {
  388. uv = vec2( - direction.z, direction.y ) / abs( direction.x );
  389. } else if ( face == 4.0 ) {
  390. uv = vec2( - direction.x, direction.z ) / abs( direction.y );
  391. } else {
  392. uv = vec2( direction.x, direction.y ) / abs( direction.z );
  393. }
  394. return 0.5 * ( uv + 1.0 );
  395. }
  396. vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {
  397. float face = getFace( direction );
  398. float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );
  399. mipInt = max( mipInt, cubeUV_minMipLevel );
  400. float faceSize = exp2( mipInt );
  401. highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;
  402. if ( face > 2.0 ) {
  403. uv.y += faceSize;
  404. face -= 3.0;
  405. }
  406. uv.x += face * faceSize;
  407. uv.x += filterInt * 3.0 * cubeUV_minTileSize;
  408. uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );
  409. uv.x *= CUBEUV_TEXEL_WIDTH;
  410. uv.y *= CUBEUV_TEXEL_HEIGHT;
  411. #ifdef texture2DGradEXT
  412. return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;
  413. #else
  414. return texture2D( envMap, uv ).rgb;
  415. #endif
  416. }
  417. #define cubeUV_r0 1.0
  418. #define cubeUV_m0 - 2.0
  419. #define cubeUV_r1 0.8
  420. #define cubeUV_m1 - 1.0
  421. #define cubeUV_r4 0.4
  422. #define cubeUV_m4 2.0
  423. #define cubeUV_r5 0.305
  424. #define cubeUV_m5 3.0
  425. #define cubeUV_r6 0.21
  426. #define cubeUV_m6 4.0
  427. float roughnessToMip( float roughness ) {
  428. float mip = 0.0;
  429. if ( roughness >= cubeUV_r1 ) {
  430. mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;
  431. } else if ( roughness >= cubeUV_r4 ) {
  432. mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;
  433. } else if ( roughness >= cubeUV_r5 ) {
  434. mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;
  435. } else if ( roughness >= cubeUV_r6 ) {
  436. mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;
  437. } else {
  438. mip = - 2.0 * log2( 1.16 * roughness ); }
  439. return mip;
  440. }
  441. vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {
  442. float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );
  443. float mipF = fract( mip );
  444. float mipInt = floor( mip );
  445. vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );
  446. if ( mipF == 0.0 ) {
  447. return vec4( color0, 1.0 );
  448. } else {
  449. vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );
  450. return vec4( mix( color0, color1, mipF ), 1.0 );
  451. }
  452. }
  453. #endif`,eo=`vec3 transformedNormal = objectNormal;
  454. #ifdef USE_TANGENT
  455. vec3 transformedTangent = objectTangent;
  456. #endif
  457. #ifdef USE_BATCHING
  458. mat3 bm = mat3( batchingMatrix );
  459. transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );
  460. transformedNormal = bm * transformedNormal;
  461. #ifdef USE_TANGENT
  462. transformedTangent = bm * transformedTangent;
  463. #endif
  464. #endif
  465. #ifdef USE_INSTANCING
  466. mat3 im = mat3( instanceMatrix );
  467. transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );
  468. transformedNormal = im * transformedNormal;
  469. #ifdef USE_TANGENT
  470. transformedTangent = im * transformedTangent;
  471. #endif
  472. #endif
  473. transformedNormal = normalMatrix * transformedNormal;
  474. #ifdef FLIP_SIDED
  475. transformedNormal = - transformedNormal;
  476. #endif
  477. #ifdef USE_TANGENT
  478. transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;
  479. #ifdef FLIP_SIDED
  480. transformedTangent = - transformedTangent;
  481. #endif
  482. #endif`,no=`#ifdef USE_DISPLACEMENTMAP
  483. uniform sampler2D displacementMap;
  484. uniform float displacementScale;
  485. uniform float displacementBias;
  486. #endif`,io=`#ifdef USE_DISPLACEMENTMAP
  487. transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
  488. #endif`,so=`#ifdef USE_EMISSIVEMAP
  489. vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
  490. totalEmissiveRadiance *= emissiveColor.rgb;
  491. #endif`,ro=`#ifdef USE_EMISSIVEMAP
  492. uniform sampler2D emissiveMap;
  493. #endif`,oo="gl_FragColor = linearToOutputTexel( gl_FragColor );",ao=`
  494. const mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(
  495. vec3( 0.8224621, 0.177538, 0.0 ),
  496. vec3( 0.0331941, 0.9668058, 0.0 ),
  497. vec3( 0.0170827, 0.0723974, 0.9105199 )
  498. );
  499. const mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(
  500. vec3( 1.2249401, - 0.2249404, 0.0 ),
  501. vec3( - 0.0420569, 1.0420571, 0.0 ),
  502. vec3( - 0.0196376, - 0.0786361, 1.0982735 )
  503. );
  504. vec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {
  505. return vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );
  506. }
  507. vec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {
  508. return vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );
  509. }
  510. vec4 LinearTransferOETF( in vec4 value ) {
  511. return value;
  512. }
  513. vec4 sRGBTransferOETF( in vec4 value ) {
  514. 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 );
  515. }`,co=`#ifdef USE_ENVMAP
  516. #ifdef ENV_WORLDPOS
  517. vec3 cameraToFrag;
  518. if ( isOrthographic ) {
  519. cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
  520. } else {
  521. cameraToFrag = normalize( vWorldPosition - cameraPosition );
  522. }
  523. vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
  524. #ifdef ENVMAP_MODE_REFLECTION
  525. vec3 reflectVec = reflect( cameraToFrag, worldNormal );
  526. #else
  527. vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
  528. #endif
  529. #else
  530. vec3 reflectVec = vReflect;
  531. #endif
  532. #ifdef ENVMAP_TYPE_CUBE
  533. vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
  534. #else
  535. vec4 envColor = vec4( 0.0 );
  536. #endif
  537. #ifdef ENVMAP_BLENDING_MULTIPLY
  538. outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
  539. #elif defined( ENVMAP_BLENDING_MIX )
  540. outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
  541. #elif defined( ENVMAP_BLENDING_ADD )
  542. outgoingLight += envColor.xyz * specularStrength * reflectivity;
  543. #endif
  544. #endif`,lo=`#ifdef USE_ENVMAP
  545. uniform float envMapIntensity;
  546. uniform float flipEnvMap;
  547. uniform mat3 envMapRotation;
  548. #ifdef ENVMAP_TYPE_CUBE
  549. uniform samplerCube envMap;
  550. #else
  551. uniform sampler2D envMap;
  552. #endif
  553. #endif`,ho=`#ifdef USE_ENVMAP
  554. uniform float reflectivity;
  555. #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
  556. #define ENV_WORLDPOS
  557. #endif
  558. #ifdef ENV_WORLDPOS
  559. varying vec3 vWorldPosition;
  560. uniform float refractionRatio;
  561. #else
  562. varying vec3 vReflect;
  563. #endif
  564. #endif`,uo=`#ifdef USE_ENVMAP
  565. #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
  566. #define ENV_WORLDPOS
  567. #endif
  568. #ifdef ENV_WORLDPOS
  569. varying vec3 vWorldPosition;
  570. #else
  571. varying vec3 vReflect;
  572. uniform float refractionRatio;
  573. #endif
  574. #endif`,fo=`#ifdef USE_ENVMAP
  575. #ifdef ENV_WORLDPOS
  576. vWorldPosition = worldPosition.xyz;
  577. #else
  578. vec3 cameraToVertex;
  579. if ( isOrthographic ) {
  580. cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
  581. } else {
  582. cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
  583. }
  584. vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
  585. #ifdef ENVMAP_MODE_REFLECTION
  586. vReflect = reflect( cameraToVertex, worldNormal );
  587. #else
  588. vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
  589. #endif
  590. #endif
  591. #endif`,po=`#ifdef USE_FOG
  592. vFogDepth = - mvPosition.z;
  593. #endif`,mo=`#ifdef USE_FOG
  594. varying float vFogDepth;
  595. #endif`,go=`#ifdef USE_FOG
  596. #ifdef FOG_EXP2
  597. float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
  598. #else
  599. float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
  600. #endif
  601. gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
  602. #endif`,_o=`#ifdef USE_FOG
  603. uniform vec3 fogColor;
  604. varying float vFogDepth;
  605. #ifdef FOG_EXP2
  606. uniform float fogDensity;
  607. #else
  608. uniform float fogNear;
  609. uniform float fogFar;
  610. #endif
  611. #endif`,xo=`#ifdef USE_GRADIENTMAP
  612. uniform sampler2D gradientMap;
  613. #endif
  614. vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
  615. float dotNL = dot( normal, lightDirection );
  616. vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
  617. #ifdef USE_GRADIENTMAP
  618. return vec3( texture2D( gradientMap, coord ).r );
  619. #else
  620. vec2 fw = fwidth( coord ) * 0.5;
  621. return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
  622. #endif
  623. }`,yo=`#ifdef USE_LIGHTMAP
  624. uniform sampler2D lightMap;
  625. uniform float lightMapIntensity;
  626. #endif`,vo=`LambertMaterial material;
  627. material.diffuseColor = diffuseColor.rgb;
  628. material.specularStrength = specularStrength;`,Mo=`varying vec3 vViewPosition;
  629. struct LambertMaterial {
  630. vec3 diffuseColor;
  631. float specularStrength;
  632. };
  633. 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 ) {
  634. float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
  635. vec3 irradiance = dotNL * directLight.color;
  636. reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
  637. }
  638. 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 ) {
  639. reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
  640. }
  641. #define RE_Direct RE_Direct_Lambert
  642. #define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,So=`uniform bool receiveShadow;
  643. uniform vec3 ambientLightColor;
  644. #if defined( USE_LIGHT_PROBES )
  645. uniform vec3 lightProbe[ 9 ];
  646. #endif
  647. vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
  648. float x = normal.x, y = normal.y, z = normal.z;
  649. vec3 result = shCoefficients[ 0 ] * 0.886227;
  650. result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
  651. result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
  652. result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
  653. result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
  654. result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
  655. result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
  656. result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
  657. result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
  658. return result;
  659. }
  660. vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
  661. vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
  662. vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
  663. return irradiance;
  664. }
  665. vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
  666. vec3 irradiance = ambientLightColor;
  667. return irradiance;
  668. }
  669. float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
  670. float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
  671. if ( cutoffDistance > 0.0 ) {
  672. distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
  673. }
  674. return distanceFalloff;
  675. }
  676. float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
  677. return smoothstep( coneCosine, penumbraCosine, angleCosine );
  678. }
  679. #if NUM_DIR_LIGHTS > 0
  680. struct DirectionalLight {
  681. vec3 direction;
  682. vec3 color;
  683. };
  684. uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
  685. void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {
  686. light.color = directionalLight.color;
  687. light.direction = directionalLight.direction;
  688. light.visible = true;
  689. }
  690. #endif
  691. #if NUM_POINT_LIGHTS > 0
  692. struct PointLight {
  693. vec3 position;
  694. vec3 color;
  695. float distance;
  696. float decay;
  697. };
  698. uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
  699. void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {
  700. vec3 lVector = pointLight.position - geometryPosition;
  701. light.direction = normalize( lVector );
  702. float lightDistance = length( lVector );
  703. light.color = pointLight.color;
  704. light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
  705. light.visible = ( light.color != vec3( 0.0 ) );
  706. }
  707. #endif
  708. #if NUM_SPOT_LIGHTS > 0
  709. struct SpotLight {
  710. vec3 position;
  711. vec3 direction;
  712. vec3 color;
  713. float distance;
  714. float decay;
  715. float coneCos;
  716. float penumbraCos;
  717. };
  718. uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
  719. void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {
  720. vec3 lVector = spotLight.position - geometryPosition;
  721. light.direction = normalize( lVector );
  722. float angleCos = dot( light.direction, spotLight.direction );
  723. float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
  724. if ( spotAttenuation > 0.0 ) {
  725. float lightDistance = length( lVector );
  726. light.color = spotLight.color * spotAttenuation;
  727. light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
  728. light.visible = ( light.color != vec3( 0.0 ) );
  729. } else {
  730. light.color = vec3( 0.0 );
  731. light.visible = false;
  732. }
  733. }
  734. #endif
  735. #if NUM_RECT_AREA_LIGHTS > 0
  736. struct RectAreaLight {
  737. vec3 color;
  738. vec3 position;
  739. vec3 halfWidth;
  740. vec3 halfHeight;
  741. };
  742. uniform sampler2D ltc_1; uniform sampler2D ltc_2;
  743. uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
  744. #endif
  745. #if NUM_HEMI_LIGHTS > 0
  746. struct HemisphereLight {
  747. vec3 direction;
  748. vec3 skyColor;
  749. vec3 groundColor;
  750. };
  751. uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
  752. vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {
  753. float dotNL = dot( normal, hemiLight.direction );
  754. float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
  755. vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
  756. return irradiance;
  757. }
  758. #endif`,bo=`#ifdef USE_ENVMAP
  759. vec3 getIBLIrradiance( const in vec3 normal ) {
  760. #ifdef ENVMAP_TYPE_CUBE_UV
  761. vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
  762. vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );
  763. return PI * envMapColor.rgb * envMapIntensity;
  764. #else
  765. return vec3( 0.0 );
  766. #endif
  767. }
  768. vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
  769. #ifdef ENVMAP_TYPE_CUBE_UV
  770. vec3 reflectVec = reflect( - viewDir, normal );
  771. reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
  772. reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
  773. vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );
  774. return envMapColor.rgb * envMapIntensity;
  775. #else
  776. return vec3( 0.0 );
  777. #endif
  778. }
  779. #ifdef USE_ANISOTROPY
  780. vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
  781. #ifdef ENVMAP_TYPE_CUBE_UV
  782. vec3 bentNormal = cross( bitangent, viewDir );
  783. bentNormal = normalize( cross( bentNormal, bitangent ) );
  784. bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
  785. return getIBLRadiance( viewDir, bentNormal, roughness );
  786. #else
  787. return vec3( 0.0 );
  788. #endif
  789. }
  790. #endif
  791. #endif`,wo=`ToonMaterial material;
  792. material.diffuseColor = diffuseColor.rgb;`,Ao=`varying vec3 vViewPosition;
  793. struct ToonMaterial {
  794. vec3 diffuseColor;
  795. };
  796. 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 ) {
  797. vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;
  798. reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
  799. }
  800. 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 ) {
  801. reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
  802. }
  803. #define RE_Direct RE_Direct_Toon
  804. #define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,To=`BlinnPhongMaterial material;
  805. material.diffuseColor = diffuseColor.rgb;
  806. material.specularColor = specular;
  807. material.specularShininess = shininess;
  808. material.specularStrength = specularStrength;`,Eo=`varying vec3 vViewPosition;
  809. struct BlinnPhongMaterial {
  810. vec3 diffuseColor;
  811. vec3 specularColor;
  812. float specularShininess;
  813. float specularStrength;
  814. };
  815. 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 ) {
  816. float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
  817. vec3 irradiance = dotNL * directLight.color;
  818. reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
  819. reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;
  820. }
  821. 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 ) {
  822. reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
  823. }
  824. #define RE_Direct RE_Direct_BlinnPhong
  825. #define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,Co=`PhysicalMaterial material;
  826. material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
  827. vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
  828. float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
  829. material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;
  830. material.roughness = min( material.roughness, 1.0 );
  831. #ifdef IOR
  832. material.ior = ior;
  833. #ifdef USE_SPECULAR
  834. float specularIntensityFactor = specularIntensity;
  835. vec3 specularColorFactor = specularColor;
  836. #ifdef USE_SPECULAR_COLORMAP
  837. specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;
  838. #endif
  839. #ifdef USE_SPECULAR_INTENSITYMAP
  840. specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;
  841. #endif
  842. material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
  843. #else
  844. float specularIntensityFactor = 1.0;
  845. vec3 specularColorFactor = vec3( 1.0 );
  846. material.specularF90 = 1.0;
  847. #endif
  848. material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );
  849. #else
  850. material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
  851. material.specularF90 = 1.0;
  852. #endif
  853. #ifdef USE_CLEARCOAT
  854. material.clearcoat = clearcoat;
  855. material.clearcoatRoughness = clearcoatRoughness;
  856. material.clearcoatF0 = vec3( 0.04 );
  857. material.clearcoatF90 = 1.0;
  858. #ifdef USE_CLEARCOATMAP
  859. material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;
  860. #endif
  861. #ifdef USE_CLEARCOAT_ROUGHNESSMAP
  862. material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;
  863. #endif
  864. material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
  865. material.clearcoatRoughness += geometryRoughness;
  866. material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
  867. #endif
  868. #ifdef USE_DISPERSION
  869. material.dispersion = dispersion;
  870. #endif
  871. #ifdef USE_IRIDESCENCE
  872. material.iridescence = iridescence;
  873. material.iridescenceIOR = iridescenceIOR;
  874. #ifdef USE_IRIDESCENCEMAP
  875. material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;
  876. #endif
  877. #ifdef USE_IRIDESCENCE_THICKNESSMAP
  878. material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;
  879. #else
  880. material.iridescenceThickness = iridescenceThicknessMaximum;
  881. #endif
  882. #endif
  883. #ifdef USE_SHEEN
  884. material.sheenColor = sheenColor;
  885. #ifdef USE_SHEEN_COLORMAP
  886. material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;
  887. #endif
  888. material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );
  889. #ifdef USE_SHEEN_ROUGHNESSMAP
  890. material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;
  891. #endif
  892. #endif
  893. #ifdef USE_ANISOTROPY
  894. #ifdef USE_ANISOTROPYMAP
  895. mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );
  896. vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;
  897. vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;
  898. #else
  899. vec2 anisotropyV = anisotropyVector;
  900. #endif
  901. material.anisotropy = length( anisotropyV );
  902. if( material.anisotropy == 0.0 ) {
  903. anisotropyV = vec2( 1.0, 0.0 );
  904. } else {
  905. anisotropyV /= material.anisotropy;
  906. material.anisotropy = saturate( material.anisotropy );
  907. }
  908. material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
  909. material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
  910. material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
  911. #endif`,Ro=`struct PhysicalMaterial {
  912. vec3 diffuseColor;
  913. float roughness;
  914. vec3 specularColor;
  915. float specularF90;
  916. float dispersion;
  917. #ifdef USE_CLEARCOAT
  918. float clearcoat;
  919. float clearcoatRoughness;
  920. vec3 clearcoatF0;
  921. float clearcoatF90;
  922. #endif
  923. #ifdef USE_IRIDESCENCE
  924. float iridescence;
  925. float iridescenceIOR;
  926. float iridescenceThickness;
  927. vec3 iridescenceFresnel;
  928. vec3 iridescenceF0;
  929. #endif
  930. #ifdef USE_SHEEN
  931. vec3 sheenColor;
  932. float sheenRoughness;
  933. #endif
  934. #ifdef IOR
  935. float ior;
  936. #endif
  937. #ifdef USE_TRANSMISSION
  938. float transmission;
  939. float transmissionAlpha;
  940. float thickness;
  941. float attenuationDistance;
  942. vec3 attenuationColor;
  943. #endif
  944. #ifdef USE_ANISOTROPY
  945. float anisotropy;
  946. float alphaT;
  947. vec3 anisotropyT;
  948. vec3 anisotropyB;
  949. #endif
  950. };
  951. vec3 clearcoatSpecularDirect = vec3( 0.0 );
  952. vec3 clearcoatSpecularIndirect = vec3( 0.0 );
  953. vec3 sheenSpecularDirect = vec3( 0.0 );
  954. vec3 sheenSpecularIndirect = vec3(0.0 );
  955. vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {
  956. float x = clamp( 1.0 - dotVH, 0.0, 1.0 );
  957. float x2 = x * x;
  958. float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );
  959. return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
  960. }
  961. float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
  962. float a2 = pow2( alpha );
  963. float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
  964. float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
  965. return 0.5 / max( gv + gl, EPSILON );
  966. }
  967. float D_GGX( const in float alpha, const in float dotNH ) {
  968. float a2 = pow2( alpha );
  969. float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
  970. return RECIPROCAL_PI * a2 / pow2( denom );
  971. }
  972. #ifdef USE_ANISOTROPY
  973. 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 ) {
  974. float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );
  975. float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
  976. float v = 0.5 / ( gv + gl );
  977. return saturate(v);
  978. }
  979. float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {
  980. float a2 = alphaT * alphaB;
  981. highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );
  982. highp float v2 = dot( v, v );
  983. float w2 = a2 / v2;
  984. return RECIPROCAL_PI * a2 * pow2 ( w2 );
  985. }
  986. #endif
  987. #ifdef USE_CLEARCOAT
  988. vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {
  989. vec3 f0 = material.clearcoatF0;
  990. float f90 = material.clearcoatF90;
  991. float roughness = material.clearcoatRoughness;
  992. float alpha = pow2( roughness );
  993. vec3 halfDir = normalize( lightDir + viewDir );
  994. float dotNL = saturate( dot( normal, lightDir ) );
  995. float dotNV = saturate( dot( normal, viewDir ) );
  996. float dotNH = saturate( dot( normal, halfDir ) );
  997. float dotVH = saturate( dot( viewDir, halfDir ) );
  998. vec3 F = F_Schlick( f0, f90, dotVH );
  999. float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
  1000. float D = D_GGX( alpha, dotNH );
  1001. return F * ( V * D );
  1002. }
  1003. #endif
  1004. vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
  1005. vec3 f0 = material.specularColor;
  1006. float f90 = material.specularF90;
  1007. float roughness = material.roughness;
  1008. float alpha = pow2( roughness );
  1009. vec3 halfDir = normalize( lightDir + viewDir );
  1010. float dotNL = saturate( dot( normal, lightDir ) );
  1011. float dotNV = saturate( dot( normal, viewDir ) );
  1012. float dotNH = saturate( dot( normal, halfDir ) );
  1013. float dotVH = saturate( dot( viewDir, halfDir ) );
  1014. vec3 F = F_Schlick( f0, f90, dotVH );
  1015. #ifdef USE_IRIDESCENCE
  1016. F = mix( F, material.iridescenceFresnel, material.iridescence );
  1017. #endif
  1018. #ifdef USE_ANISOTROPY
  1019. float dotTL = dot( material.anisotropyT, lightDir );
  1020. float dotTV = dot( material.anisotropyT, viewDir );
  1021. float dotTH = dot( material.anisotropyT, halfDir );
  1022. float dotBL = dot( material.anisotropyB, lightDir );
  1023. float dotBV = dot( material.anisotropyB, viewDir );
  1024. float dotBH = dot( material.anisotropyB, halfDir );
  1025. float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
  1026. float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );
  1027. #else
  1028. float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
  1029. float D = D_GGX( alpha, dotNH );
  1030. #endif
  1031. return F * ( V * D );
  1032. }
  1033. vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
  1034. const float LUT_SIZE = 64.0;
  1035. const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
  1036. const float LUT_BIAS = 0.5 / LUT_SIZE;
  1037. float dotNV = saturate( dot( N, V ) );
  1038. vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
  1039. uv = uv * LUT_SCALE + LUT_BIAS;
  1040. return uv;
  1041. }
  1042. float LTC_ClippedSphereFormFactor( const in vec3 f ) {
  1043. float l = length( f );
  1044. return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
  1045. }
  1046. vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
  1047. float x = dot( v1, v2 );
  1048. float y = abs( x );
  1049. float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
  1050. float b = 3.4175940 + ( 4.1616724 + y ) * y;
  1051. float v = a / b;
  1052. float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
  1053. return cross( v1, v2 ) * theta_sintheta;
  1054. }
  1055. vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
  1056. vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
  1057. vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
  1058. vec3 lightNormal = cross( v1, v2 );
  1059. if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
  1060. vec3 T1, T2;
  1061. T1 = normalize( V - N * dot( V, N ) );
  1062. T2 = - cross( N, T1 );
  1063. mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );
  1064. vec3 coords[ 4 ];
  1065. coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
  1066. coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
  1067. coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
  1068. coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
  1069. coords[ 0 ] = normalize( coords[ 0 ] );
  1070. coords[ 1 ] = normalize( coords[ 1 ] );
  1071. coords[ 2 ] = normalize( coords[ 2 ] );
  1072. coords[ 3 ] = normalize( coords[ 3 ] );
  1073. vec3 vectorFormFactor = vec3( 0.0 );
  1074. vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
  1075. vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
  1076. vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
  1077. vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
  1078. float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
  1079. return vec3( result );
  1080. }
  1081. #if defined( USE_SHEEN )
  1082. float D_Charlie( float roughness, float dotNH ) {
  1083. float alpha = pow2( roughness );
  1084. float invAlpha = 1.0 / alpha;
  1085. float cos2h = dotNH * dotNH;
  1086. float sin2h = max( 1.0 - cos2h, 0.0078125 );
  1087. return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
  1088. }
  1089. float V_Neubelt( float dotNV, float dotNL ) {
  1090. return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
  1091. }
  1092. vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
  1093. vec3 halfDir = normalize( lightDir + viewDir );
  1094. float dotNL = saturate( dot( normal, lightDir ) );
  1095. float dotNV = saturate( dot( normal, viewDir ) );
  1096. float dotNH = saturate( dot( normal, halfDir ) );
  1097. float D = D_Charlie( sheenRoughness, dotNH );
  1098. float V = V_Neubelt( dotNV, dotNL );
  1099. return sheenColor * ( D * V );
  1100. }
  1101. #endif
  1102. float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
  1103. float dotNV = saturate( dot( normal, viewDir ) );
  1104. float r2 = roughness * roughness;
  1105. float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;
  1106. float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;
  1107. float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );
  1108. return saturate( DG * RECIPROCAL_PI );
  1109. }
  1110. vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
  1111. float dotNV = saturate( dot( normal, viewDir ) );
  1112. const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
  1113. const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
  1114. vec4 r = roughness * c0 + c1;
  1115. float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
  1116. vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;
  1117. return fab;
  1118. }
  1119. vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
  1120. vec2 fab = DFGApprox( normal, viewDir, roughness );
  1121. return specularColor * fab.x + specularF90 * fab.y;
  1122. }
  1123. #ifdef USE_IRIDESCENCE
  1124. 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 ) {
  1125. #else
  1126. 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 ) {
  1127. #endif
  1128. vec2 fab = DFGApprox( normal, viewDir, roughness );
  1129. #ifdef USE_IRIDESCENCE
  1130. vec3 Fr = mix( specularColor, iridescenceF0, iridescence );
  1131. #else
  1132. vec3 Fr = specularColor;
  1133. #endif
  1134. vec3 FssEss = Fr * fab.x + specularF90 * fab.y;
  1135. float Ess = fab.x + fab.y;
  1136. float Ems = 1.0 - Ess;
  1137. vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
  1138. singleScatter += FssEss;
  1139. multiScatter += Fms * Ems;
  1140. }
  1141. #if NUM_RECT_AREA_LIGHTS > 0
  1142. 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 ) {
  1143. vec3 normal = geometryNormal;
  1144. vec3 viewDir = geometryViewDir;
  1145. vec3 position = geometryPosition;
  1146. vec3 lightPos = rectAreaLight.position;
  1147. vec3 halfWidth = rectAreaLight.halfWidth;
  1148. vec3 halfHeight = rectAreaLight.halfHeight;
  1149. vec3 lightColor = rectAreaLight.color;
  1150. float roughness = material.roughness;
  1151. vec3 rectCoords[ 4 ];
  1152. rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
  1153. rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
  1154. rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
  1155. vec2 uv = LTC_Uv( normal, viewDir, roughness );
  1156. vec4 t1 = texture2D( ltc_1, uv );
  1157. vec4 t2 = texture2D( ltc_2, uv );
  1158. mat3 mInv = mat3(
  1159. vec3( t1.x, 0, t1.y ),
  1160. vec3( 0, 1, 0 ),
  1161. vec3( t1.z, 0, t1.w )
  1162. );
  1163. vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );
  1164. reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
  1165. reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
  1166. }
  1167. #endif
  1168. 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 ) {
  1169. float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
  1170. vec3 irradiance = dotNL * directLight.color;
  1171. #ifdef USE_CLEARCOAT
  1172. float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );
  1173. vec3 ccIrradiance = dotNLcc * directLight.color;
  1174. clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );
  1175. #endif
  1176. #ifdef USE_SHEEN
  1177. sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );
  1178. #endif
  1179. reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );
  1180. reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
  1181. }
  1182. 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 ) {
  1183. reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
  1184. }
  1185. 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) {
  1186. #ifdef USE_CLEARCOAT
  1187. clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
  1188. #endif
  1189. #ifdef USE_SHEEN
  1190. sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
  1191. #endif
  1192. vec3 singleScattering = vec3( 0.0 );
  1193. vec3 multiScattering = vec3( 0.0 );
  1194. vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
  1195. #ifdef USE_IRIDESCENCE
  1196. computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );
  1197. #else
  1198. computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );
  1199. #endif
  1200. vec3 totalScattering = singleScattering + multiScattering;
  1201. vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
  1202. reflectedLight.indirectSpecular += radiance * singleScattering;
  1203. reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;
  1204. reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;
  1205. }
  1206. #define RE_Direct RE_Direct_Physical
  1207. #define RE_Direct_RectArea RE_Direct_RectArea_Physical
  1208. #define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
  1209. #define RE_IndirectSpecular RE_IndirectSpecular_Physical
  1210. float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
  1211. return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
  1212. }`,Po=`
  1213. vec3 geometryPosition = - vViewPosition;
  1214. vec3 geometryNormal = normal;
  1215. vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
  1216. vec3 geometryClearcoatNormal = vec3( 0.0 );
  1217. #ifdef USE_CLEARCOAT
  1218. geometryClearcoatNormal = clearcoatNormal;
  1219. #endif
  1220. #ifdef USE_IRIDESCENCE
  1221. float dotNVi = saturate( dot( normal, geometryViewDir ) );
  1222. if ( material.iridescenceThickness == 0.0 ) {
  1223. material.iridescence = 0.0;
  1224. } else {
  1225. material.iridescence = saturate( material.iridescence );
  1226. }
  1227. if ( material.iridescence > 0.0 ) {
  1228. material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
  1229. material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );
  1230. }
  1231. #endif
  1232. IncidentLight directLight;
  1233. #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
  1234. PointLight pointLight;
  1235. #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
  1236. PointLightShadow pointLightShadow;
  1237. #endif
  1238. #pragma unroll_loop_start
  1239. for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
  1240. pointLight = pointLights[ i ];
  1241. getPointLightInfo( pointLight, geometryPosition, directLight );
  1242. #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
  1243. pointLightShadow = pointLightShadows[ i ];
  1244. directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
  1245. #endif
  1246. RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
  1247. }
  1248. #pragma unroll_loop_end
  1249. #endif
  1250. #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
  1251. SpotLight spotLight;
  1252. vec4 spotColor;
  1253. vec3 spotLightCoord;
  1254. bool inSpotLightMap;
  1255. #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
  1256. SpotLightShadow spotLightShadow;
  1257. #endif
  1258. #pragma unroll_loop_start
  1259. for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
  1260. spotLight = spotLights[ i ];
  1261. getSpotLightInfo( spotLight, geometryPosition, directLight );
  1262. #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
  1263. #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX
  1264. #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
  1265. #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS
  1266. #else
  1267. #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
  1268. #endif
  1269. #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )
  1270. spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;
  1271. inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );
  1272. spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );
  1273. directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;
  1274. #endif
  1275. #undef SPOT_LIGHT_MAP_INDEX
  1276. #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
  1277. spotLightShadow = spotLightShadows[ i ];
  1278. directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
  1279. #endif
  1280. RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
  1281. }
  1282. #pragma unroll_loop_end
  1283. #endif
  1284. #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
  1285. DirectionalLight directionalLight;
  1286. #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
  1287. DirectionalLightShadow directionalLightShadow;
  1288. #endif
  1289. #pragma unroll_loop_start
  1290. for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
  1291. directionalLight = directionalLights[ i ];
  1292. getDirectionalLightInfo( directionalLight, directLight );
  1293. #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
  1294. directionalLightShadow = directionalLightShadows[ i ];
  1295. directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
  1296. #endif
  1297. RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
  1298. }
  1299. #pragma unroll_loop_end
  1300. #endif
  1301. #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
  1302. RectAreaLight rectAreaLight;
  1303. #pragma unroll_loop_start
  1304. for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
  1305. rectAreaLight = rectAreaLights[ i ];
  1306. RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
  1307. }
  1308. #pragma unroll_loop_end
  1309. #endif
  1310. #if defined( RE_IndirectDiffuse )
  1311. vec3 iblIrradiance = vec3( 0.0 );
  1312. vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
  1313. #if defined( USE_LIGHT_PROBES )
  1314. irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
  1315. #endif
  1316. #if ( NUM_HEMI_LIGHTS > 0 )
  1317. #pragma unroll_loop_start
  1318. for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
  1319. irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
  1320. }
  1321. #pragma unroll_loop_end
  1322. #endif
  1323. #endif
  1324. #if defined( RE_IndirectSpecular )
  1325. vec3 radiance = vec3( 0.0 );
  1326. vec3 clearcoatRadiance = vec3( 0.0 );
  1327. #endif`,Io=`#if defined( RE_IndirectDiffuse )
  1328. #ifdef USE_LIGHTMAP
  1329. vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
  1330. vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
  1331. irradiance += lightMapIrradiance;
  1332. #endif
  1333. #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
  1334. iblIrradiance += getIBLIrradiance( geometryNormal );
  1335. #endif
  1336. #endif
  1337. #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
  1338. #ifdef USE_ANISOTROPY
  1339. radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
  1340. #else
  1341. radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
  1342. #endif
  1343. #ifdef USE_CLEARCOAT
  1344. clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
  1345. #endif
  1346. #endif`,Lo=`#if defined( RE_IndirectDiffuse )
  1347. RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
  1348. #endif
  1349. #if defined( RE_IndirectSpecular )
  1350. RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
  1351. #endif`,Do=`#if defined( USE_LOGDEPTHBUF )
  1352. gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
  1353. #endif`,Uo=`#if defined( USE_LOGDEPTHBUF )
  1354. uniform float logDepthBufFC;
  1355. varying float vFragDepth;
  1356. varying float vIsPerspective;
  1357. #endif`,No=`#ifdef USE_LOGDEPTHBUF
  1358. varying float vFragDepth;
  1359. varying float vIsPerspective;
  1360. #endif`,Fo=`#ifdef USE_LOGDEPTHBUF
  1361. vFragDepth = 1.0 + gl_Position.w;
  1362. vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
  1363. #endif`,Bo=`#ifdef USE_MAP
  1364. vec4 sampledDiffuseColor = texture2D( map, vMapUv );
  1365. #ifdef DECODE_VIDEO_TEXTURE
  1366. sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );
  1367. #endif
  1368. diffuseColor *= sampledDiffuseColor;
  1369. #endif`,Oo=`#ifdef USE_MAP
  1370. uniform sampler2D map;
  1371. #endif`,zo=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
  1372. #if defined( USE_POINTS_UV )
  1373. vec2 uv = vUv;
  1374. #else
  1375. vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
  1376. #endif
  1377. #endif
  1378. #ifdef USE_MAP
  1379. diffuseColor *= texture2D( map, uv );
  1380. #endif
  1381. #ifdef USE_ALPHAMAP
  1382. diffuseColor.a *= texture2D( alphaMap, uv ).g;
  1383. #endif`,ko=`#if defined( USE_POINTS_UV )
  1384. varying vec2 vUv;
  1385. #else
  1386. #if defined( USE_MAP ) || defined( USE_ALPHAMAP )
  1387. uniform mat3 uvTransform;
  1388. #endif
  1389. #endif
  1390. #ifdef USE_MAP
  1391. uniform sampler2D map;
  1392. #endif
  1393. #ifdef USE_ALPHAMAP
  1394. uniform sampler2D alphaMap;
  1395. #endif`,Vo=`float metalnessFactor = metalness;
  1396. #ifdef USE_METALNESSMAP
  1397. vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
  1398. metalnessFactor *= texelMetalness.b;
  1399. #endif`,Ho=`#ifdef USE_METALNESSMAP
  1400. uniform sampler2D metalnessMap;
  1401. #endif`,Go=`#ifdef USE_INSTANCING_MORPH
  1402. float morphTargetInfluences[ MORPHTARGETS_COUNT ];
  1403. float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;
  1404. for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
  1405. morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;
  1406. }
  1407. #endif`,Wo=`#if defined( USE_MORPHCOLORS )
  1408. vColor *= morphTargetBaseInfluence;
  1409. for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
  1410. #if defined( USE_COLOR_ALPHA )
  1411. if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
  1412. #elif defined( USE_COLOR )
  1413. if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
  1414. #endif
  1415. }
  1416. #endif`,Xo=`#ifdef USE_MORPHNORMALS
  1417. objectNormal *= morphTargetBaseInfluence;
  1418. for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
  1419. if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
  1420. }
  1421. #endif`,qo=`#ifdef USE_MORPHTARGETS
  1422. #ifndef USE_INSTANCING_MORPH
  1423. uniform float morphTargetBaseInfluence;
  1424. uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
  1425. #endif
  1426. uniform sampler2DArray morphTargetsTexture;
  1427. uniform ivec2 morphTargetsTextureSize;
  1428. vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {
  1429. int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;
  1430. int y = texelIndex / morphTargetsTextureSize.x;
  1431. int x = texelIndex - y * morphTargetsTextureSize.x;
  1432. ivec3 morphUV = ivec3( x, y, morphTargetIndex );
  1433. return texelFetch( morphTargetsTexture, morphUV, 0 );
  1434. }
  1435. #endif`,Yo=`#ifdef USE_MORPHTARGETS
  1436. transformed *= morphTargetBaseInfluence;
  1437. for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
  1438. if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
  1439. }
  1440. #endif`,Zo=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
  1441. #ifdef FLAT_SHADED
  1442. vec3 fdx = dFdx( vViewPosition );
  1443. vec3 fdy = dFdy( vViewPosition );
  1444. vec3 normal = normalize( cross( fdx, fdy ) );
  1445. #else
  1446. vec3 normal = normalize( vNormal );
  1447. #ifdef DOUBLE_SIDED
  1448. normal *= faceDirection;
  1449. #endif
  1450. #endif
  1451. #if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )
  1452. #ifdef USE_TANGENT
  1453. mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
  1454. #else
  1455. mat3 tbn = getTangentFrame( - vViewPosition, normal,
  1456. #if defined( USE_NORMALMAP )
  1457. vNormalMapUv
  1458. #elif defined( USE_CLEARCOAT_NORMALMAP )
  1459. vClearcoatNormalMapUv
  1460. #else
  1461. vUv
  1462. #endif
  1463. );
  1464. #endif
  1465. #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
  1466. tbn[0] *= faceDirection;
  1467. tbn[1] *= faceDirection;
  1468. #endif
  1469. #endif
  1470. #ifdef USE_CLEARCOAT_NORMALMAP
  1471. #ifdef USE_TANGENT
  1472. mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
  1473. #else
  1474. mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
  1475. #endif
  1476. #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
  1477. tbn2[0] *= faceDirection;
  1478. tbn2[1] *= faceDirection;
  1479. #endif
  1480. #endif
  1481. vec3 nonPerturbedNormal = normal;`,Jo=`#ifdef USE_NORMALMAP_OBJECTSPACE
  1482. normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
  1483. #ifdef FLIP_SIDED
  1484. normal = - normal;
  1485. #endif
  1486. #ifdef DOUBLE_SIDED
  1487. normal = normal * faceDirection;
  1488. #endif
  1489. normal = normalize( normalMatrix * normal );
  1490. #elif defined( USE_NORMALMAP_TANGENTSPACE )
  1491. vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
  1492. mapN.xy *= normalScale;
  1493. normal = normalize( tbn * mapN );
  1494. #elif defined( USE_BUMPMAP )
  1495. normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
  1496. #endif`,$o=`#ifndef FLAT_SHADED
  1497. varying vec3 vNormal;
  1498. #ifdef USE_TANGENT
  1499. varying vec3 vTangent;
  1500. varying vec3 vBitangent;
  1501. #endif
  1502. #endif`,Ko=`#ifndef FLAT_SHADED
  1503. varying vec3 vNormal;
  1504. #ifdef USE_TANGENT
  1505. varying vec3 vTangent;
  1506. varying vec3 vBitangent;
  1507. #endif
  1508. #endif`,Qo=`#ifndef FLAT_SHADED
  1509. vNormal = normalize( transformedNormal );
  1510. #ifdef USE_TANGENT
  1511. vTangent = normalize( transformedTangent );
  1512. vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
  1513. #endif
  1514. #endif`,jo=`#ifdef USE_NORMALMAP
  1515. uniform sampler2D normalMap;
  1516. uniform vec2 normalScale;
  1517. #endif
  1518. #ifdef USE_NORMALMAP_OBJECTSPACE
  1519. uniform mat3 normalMatrix;
  1520. #endif
  1521. #if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )
  1522. mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {
  1523. vec3 q0 = dFdx( eye_pos.xyz );
  1524. vec3 q1 = dFdy( eye_pos.xyz );
  1525. vec2 st0 = dFdx( uv.st );
  1526. vec2 st1 = dFdy( uv.st );
  1527. vec3 N = surf_norm;
  1528. vec3 q1perp = cross( q1, N );
  1529. vec3 q0perp = cross( N, q0 );
  1530. vec3 T = q1perp * st0.x + q0perp * st1.x;
  1531. vec3 B = q1perp * st0.y + q0perp * st1.y;
  1532. float det = max( dot( T, T ), dot( B, B ) );
  1533. float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
  1534. return mat3( T * scale, B * scale, N );
  1535. }
  1536. #endif`,ta=`#ifdef USE_CLEARCOAT
  1537. vec3 clearcoatNormal = nonPerturbedNormal;
  1538. #endif`,ea=`#ifdef USE_CLEARCOAT_NORMALMAP
  1539. vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
  1540. clearcoatMapN.xy *= clearcoatNormalScale;
  1541. clearcoatNormal = normalize( tbn2 * clearcoatMapN );
  1542. #endif`,na=`#ifdef USE_CLEARCOATMAP
  1543. uniform sampler2D clearcoatMap;
  1544. #endif
  1545. #ifdef USE_CLEARCOAT_NORMALMAP
  1546. uniform sampler2D clearcoatNormalMap;
  1547. uniform vec2 clearcoatNormalScale;
  1548. #endif
  1549. #ifdef USE_CLEARCOAT_ROUGHNESSMAP
  1550. uniform sampler2D clearcoatRoughnessMap;
  1551. #endif`,ia=`#ifdef USE_IRIDESCENCEMAP
  1552. uniform sampler2D iridescenceMap;
  1553. #endif
  1554. #ifdef USE_IRIDESCENCE_THICKNESSMAP
  1555. uniform sampler2D iridescenceThicknessMap;
  1556. #endif`,sa=`#ifdef OPAQUE
  1557. diffuseColor.a = 1.0;
  1558. #endif
  1559. #ifdef USE_TRANSMISSION
  1560. diffuseColor.a *= material.transmissionAlpha;
  1561. #endif
  1562. gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,ra=`vec3 packNormalToRGB( const in vec3 normal ) {
  1563. return normalize( normal ) * 0.5 + 0.5;
  1564. }
  1565. vec3 unpackRGBToNormal( const in vec3 rgb ) {
  1566. return 2.0 * rgb.xyz - 1.0;
  1567. }
  1568. const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;
  1569. const float Inv255 = 1. / 255.;
  1570. const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );
  1571. const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );
  1572. const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );
  1573. const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );
  1574. vec4 packDepthToRGBA( const in float v ) {
  1575. if( v <= 0.0 )
  1576. return vec4( 0., 0., 0., 0. );
  1577. if( v >= 1.0 )
  1578. return vec4( 1., 1., 1., 1. );
  1579. float vuf;
  1580. float af = modf( v * PackFactors.a, vuf );
  1581. float bf = modf( vuf * ShiftRight8, vuf );
  1582. float gf = modf( vuf * ShiftRight8, vuf );
  1583. return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );
  1584. }
  1585. vec3 packDepthToRGB( const in float v ) {
  1586. if( v <= 0.0 )
  1587. return vec3( 0., 0., 0. );
  1588. if( v >= 1.0 )
  1589. return vec3( 1., 1., 1. );
  1590. float vuf;
  1591. float bf = modf( v * PackFactors.b, vuf );
  1592. float gf = modf( vuf * ShiftRight8, vuf );
  1593. return vec3( vuf * Inv255, gf * PackUpscale, bf );
  1594. }
  1595. vec2 packDepthToRG( const in float v ) {
  1596. if( v <= 0.0 )
  1597. return vec2( 0., 0. );
  1598. if( v >= 1.0 )
  1599. return vec2( 1., 1. );
  1600. float vuf;
  1601. float gf = modf( v * 256., vuf );
  1602. return vec2( vuf * Inv255, gf );
  1603. }
  1604. float unpackRGBAToDepth( const in vec4 v ) {
  1605. return dot( v, UnpackFactors4 );
  1606. }
  1607. float unpackRGBToDepth( const in vec3 v ) {
  1608. return dot( v, UnpackFactors3 );
  1609. }
  1610. float unpackRGToDepth( const in vec2 v ) {
  1611. return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;
  1612. }
  1613. vec4 pack2HalfToRGBA( const in vec2 v ) {
  1614. vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
  1615. return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
  1616. }
  1617. vec2 unpackRGBATo2Half( const in vec4 v ) {
  1618. return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
  1619. }
  1620. float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
  1621. return ( viewZ + near ) / ( near - far );
  1622. }
  1623. float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {
  1624. return depth * ( near - far ) - near;
  1625. }
  1626. float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
  1627. return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
  1628. }
  1629. float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
  1630. return ( near * far ) / ( ( far - near ) * depth - far );
  1631. }`,oa=`#ifdef PREMULTIPLIED_ALPHA
  1632. gl_FragColor.rgb *= gl_FragColor.a;
  1633. #endif`,aa=`vec4 mvPosition = vec4( transformed, 1.0 );
  1634. #ifdef USE_BATCHING
  1635. mvPosition = batchingMatrix * mvPosition;
  1636. #endif
  1637. #ifdef USE_INSTANCING
  1638. mvPosition = instanceMatrix * mvPosition;
  1639. #endif
  1640. mvPosition = modelViewMatrix * mvPosition;
  1641. gl_Position = projectionMatrix * mvPosition;`,ca=`#ifdef DITHERING
  1642. gl_FragColor.rgb = dithering( gl_FragColor.rgb );
  1643. #endif`,la=`#ifdef DITHERING
  1644. vec3 dithering( vec3 color ) {
  1645. float grid_position = rand( gl_FragCoord.xy );
  1646. vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
  1647. dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
  1648. return color + dither_shift_RGB;
  1649. }
  1650. #endif`,ha=`float roughnessFactor = roughness;
  1651. #ifdef USE_ROUGHNESSMAP
  1652. vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
  1653. roughnessFactor *= texelRoughness.g;
  1654. #endif`,ua=`#ifdef USE_ROUGHNESSMAP
  1655. uniform sampler2D roughnessMap;
  1656. #endif`,fa=`#if NUM_SPOT_LIGHT_COORDS > 0
  1657. varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
  1658. #endif
  1659. #if NUM_SPOT_LIGHT_MAPS > 0
  1660. uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];
  1661. #endif
  1662. #ifdef USE_SHADOWMAP
  1663. #if NUM_DIR_LIGHT_SHADOWS > 0
  1664. uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
  1665. varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
  1666. struct DirectionalLightShadow {
  1667. float shadowIntensity;
  1668. float shadowBias;
  1669. float shadowNormalBias;
  1670. float shadowRadius;
  1671. vec2 shadowMapSize;
  1672. };
  1673. uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
  1674. #endif
  1675. #if NUM_SPOT_LIGHT_SHADOWS > 0
  1676. uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
  1677. struct SpotLightShadow {
  1678. float shadowIntensity;
  1679. float shadowBias;
  1680. float shadowNormalBias;
  1681. float shadowRadius;
  1682. vec2 shadowMapSize;
  1683. };
  1684. uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
  1685. #endif
  1686. #if NUM_POINT_LIGHT_SHADOWS > 0
  1687. uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
  1688. varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
  1689. struct PointLightShadow {
  1690. float shadowIntensity;
  1691. float shadowBias;
  1692. float shadowNormalBias;
  1693. float shadowRadius;
  1694. vec2 shadowMapSize;
  1695. float shadowCameraNear;
  1696. float shadowCameraFar;
  1697. };
  1698. uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
  1699. #endif
  1700. float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
  1701. return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
  1702. }
  1703. vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
  1704. return unpackRGBATo2Half( texture2D( shadow, uv ) );
  1705. }
  1706. float VSMShadow (sampler2D shadow, vec2 uv, float compare ){
  1707. float occlusion = 1.0;
  1708. vec2 distribution = texture2DDistribution( shadow, uv );
  1709. float hard_shadow = step( compare , distribution.x );
  1710. if (hard_shadow != 1.0 ) {
  1711. float distance = compare - distribution.x ;
  1712. float variance = max( 0.00000, distribution.y * distribution.y );
  1713. float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );
  1714. }
  1715. return occlusion;
  1716. }
  1717. float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
  1718. float shadow = 1.0;
  1719. shadowCoord.xyz /= shadowCoord.w;
  1720. shadowCoord.z += shadowBias;
  1721. bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
  1722. bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
  1723. if ( frustumTest ) {
  1724. #if defined( SHADOWMAP_TYPE_PCF )
  1725. vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
  1726. float dx0 = - texelSize.x * shadowRadius;
  1727. float dy0 = - texelSize.y * shadowRadius;
  1728. float dx1 = + texelSize.x * shadowRadius;
  1729. float dy1 = + texelSize.y * shadowRadius;
  1730. float dx2 = dx0 / 2.0;
  1731. float dy2 = dy0 / 2.0;
  1732. float dx3 = dx1 / 2.0;
  1733. float dy3 = dy1 / 2.0;
  1734. shadow = (
  1735. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
  1736. texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
  1737. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
  1738. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +
  1739. texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +
  1740. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +
  1741. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
  1742. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +
  1743. texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +
  1744. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +
  1745. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
  1746. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +
  1747. texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +
  1748. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +
  1749. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
  1750. texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
  1751. texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
  1752. ) * ( 1.0 / 17.0 );
  1753. #elif defined( SHADOWMAP_TYPE_PCF_SOFT )
  1754. vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
  1755. float dx = texelSize.x;
  1756. float dy = texelSize.y;
  1757. vec2 uv = shadowCoord.xy;
  1758. vec2 f = fract( uv * shadowMapSize + 0.5 );
  1759. uv -= f * texelSize;
  1760. shadow = (
  1761. texture2DCompare( shadowMap, uv, shadowCoord.z ) +
  1762. texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
  1763. texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
  1764. texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
  1765. mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
  1766. texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
  1767. f.x ) +
  1768. mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
  1769. texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
  1770. f.x ) +
  1771. mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
  1772. texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
  1773. f.y ) +
  1774. mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
  1775. texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
  1776. f.y ) +
  1777. mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
  1778. texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
  1779. f.x ),
  1780. mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
  1781. texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
  1782. f.x ),
  1783. f.y )
  1784. ) * ( 1.0 / 9.0 );
  1785. #elif defined( SHADOWMAP_TYPE_VSM )
  1786. shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
  1787. #else
  1788. shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );
  1789. #endif
  1790. }
  1791. return mix( 1.0, shadow, shadowIntensity );
  1792. }
  1793. vec2 cubeToUV( vec3 v, float texelSizeY ) {
  1794. vec3 absV = abs( v );
  1795. float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );
  1796. absV *= scaleToCube;
  1797. v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );
  1798. vec2 planar = v.xy;
  1799. float almostATexel = 1.5 * texelSizeY;
  1800. float almostOne = 1.0 - almostATexel;
  1801. if ( absV.z >= almostOne ) {
  1802. if ( v.z > 0.0 )
  1803. planar.x = 4.0 - v.x;
  1804. } else if ( absV.x >= almostOne ) {
  1805. float signX = sign( v.x );
  1806. planar.x = v.z * signX + 2.0 * signX;
  1807. } else if ( absV.y >= almostOne ) {
  1808. float signY = sign( v.y );
  1809. planar.x = v.x + 2.0 * signY + 2.0;
  1810. planar.y = v.z * signY - 2.0;
  1811. }
  1812. return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );
  1813. }
  1814. float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
  1815. float shadow = 1.0;
  1816. vec3 lightToPosition = shadowCoord.xyz;
  1817. float lightToPositionLength = length( lightToPosition );
  1818. if ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {
  1819. float dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias;
  1820. vec3 bd3D = normalize( lightToPosition );
  1821. vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
  1822. #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
  1823. vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
  1824. shadow = (
  1825. texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
  1826. texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
  1827. texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
  1828. texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
  1829. texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
  1830. texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
  1831. texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
  1832. texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
  1833. texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
  1834. ) * ( 1.0 / 9.0 );
  1835. #else
  1836. shadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
  1837. #endif
  1838. }
  1839. return mix( 1.0, shadow, shadowIntensity );
  1840. }
  1841. #endif`,da=`#if NUM_SPOT_LIGHT_COORDS > 0
  1842. uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
  1843. varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
  1844. #endif
  1845. #ifdef USE_SHADOWMAP
  1846. #if NUM_DIR_LIGHT_SHADOWS > 0
  1847. uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
  1848. varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
  1849. struct DirectionalLightShadow {
  1850. float shadowIntensity;
  1851. float shadowBias;
  1852. float shadowNormalBias;
  1853. float shadowRadius;
  1854. vec2 shadowMapSize;
  1855. };
  1856. uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
  1857. #endif
  1858. #if NUM_SPOT_LIGHT_SHADOWS > 0
  1859. struct SpotLightShadow {
  1860. float shadowIntensity;
  1861. float shadowBias;
  1862. float shadowNormalBias;
  1863. float shadowRadius;
  1864. vec2 shadowMapSize;
  1865. };
  1866. uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
  1867. #endif
  1868. #if NUM_POINT_LIGHT_SHADOWS > 0
  1869. uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
  1870. varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
  1871. struct PointLightShadow {
  1872. float shadowIntensity;
  1873. float shadowBias;
  1874. float shadowNormalBias;
  1875. float shadowRadius;
  1876. vec2 shadowMapSize;
  1877. float shadowCameraNear;
  1878. float shadowCameraFar;
  1879. };
  1880. uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
  1881. #endif
  1882. #endif`,pa=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
  1883. vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
  1884. vec4 shadowWorldPosition;
  1885. #endif
  1886. #if defined( USE_SHADOWMAP )
  1887. #if NUM_DIR_LIGHT_SHADOWS > 0
  1888. #pragma unroll_loop_start
  1889. for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
  1890. shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
  1891. vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
  1892. }
  1893. #pragma unroll_loop_end
  1894. #endif
  1895. #if NUM_POINT_LIGHT_SHADOWS > 0
  1896. #pragma unroll_loop_start
  1897. for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
  1898. shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
  1899. vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
  1900. }
  1901. #pragma unroll_loop_end
  1902. #endif
  1903. #endif
  1904. #if NUM_SPOT_LIGHT_COORDS > 0
  1905. #pragma unroll_loop_start
  1906. for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {
  1907. shadowWorldPosition = worldPosition;
  1908. #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
  1909. shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;
  1910. #endif
  1911. vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
  1912. }
  1913. #pragma unroll_loop_end
  1914. #endif`,ma=`float getShadowMask() {
  1915. float shadow = 1.0;
  1916. #ifdef USE_SHADOWMAP
  1917. #if NUM_DIR_LIGHT_SHADOWS > 0
  1918. DirectionalLightShadow directionalLight;
  1919. #pragma unroll_loop_start
  1920. for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
  1921. directionalLight = directionalLightShadows[ i ];
  1922. shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
  1923. }
  1924. #pragma unroll_loop_end
  1925. #endif
  1926. #if NUM_SPOT_LIGHT_SHADOWS > 0
  1927. SpotLightShadow spotLight;
  1928. #pragma unroll_loop_start
  1929. for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
  1930. spotLight = spotLightShadows[ i ];
  1931. shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
  1932. }
  1933. #pragma unroll_loop_end
  1934. #endif
  1935. #if NUM_POINT_LIGHT_SHADOWS > 0
  1936. PointLightShadow pointLight;
  1937. #pragma unroll_loop_start
  1938. for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
  1939. pointLight = pointLightShadows[ i ];
  1940. shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
  1941. }
  1942. #pragma unroll_loop_end
  1943. #endif
  1944. #endif
  1945. return shadow;
  1946. }`,ga=`#ifdef USE_SKINNING
  1947. mat4 boneMatX = getBoneMatrix( skinIndex.x );
  1948. mat4 boneMatY = getBoneMatrix( skinIndex.y );
  1949. mat4 boneMatZ = getBoneMatrix( skinIndex.z );
  1950. mat4 boneMatW = getBoneMatrix( skinIndex.w );
  1951. #endif`,_a=`#ifdef USE_SKINNING
  1952. uniform mat4 bindMatrix;
  1953. uniform mat4 bindMatrixInverse;
  1954. uniform highp sampler2D boneTexture;
  1955. mat4 getBoneMatrix( const in float i ) {
  1956. int size = textureSize( boneTexture, 0 ).x;
  1957. int j = int( i ) * 4;
  1958. int x = j % size;
  1959. int y = j / size;
  1960. vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );
  1961. vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );
  1962. vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );
  1963. vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
  1964. return mat4( v1, v2, v3, v4 );
  1965. }
  1966. #endif`,xa=`#ifdef USE_SKINNING
  1967. vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
  1968. vec4 skinned = vec4( 0.0 );
  1969. skinned += boneMatX * skinVertex * skinWeight.x;
  1970. skinned += boneMatY * skinVertex * skinWeight.y;
  1971. skinned += boneMatZ * skinVertex * skinWeight.z;
  1972. skinned += boneMatW * skinVertex * skinWeight.w;
  1973. transformed = ( bindMatrixInverse * skinned ).xyz;
  1974. #endif`,ya=`#ifdef USE_SKINNING
  1975. mat4 skinMatrix = mat4( 0.0 );
  1976. skinMatrix += skinWeight.x * boneMatX;
  1977. skinMatrix += skinWeight.y * boneMatY;
  1978. skinMatrix += skinWeight.z * boneMatZ;
  1979. skinMatrix += skinWeight.w * boneMatW;
  1980. skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
  1981. objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
  1982. #ifdef USE_TANGENT
  1983. objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
  1984. #endif
  1985. #endif`,va=`float specularStrength;
  1986. #ifdef USE_SPECULARMAP
  1987. vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
  1988. specularStrength = texelSpecular.r;
  1989. #else
  1990. specularStrength = 1.0;
  1991. #endif`,Ma=`#ifdef USE_SPECULARMAP
  1992. uniform sampler2D specularMap;
  1993. #endif`,Sa=`#if defined( TONE_MAPPING )
  1994. gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
  1995. #endif`,ba=`#ifndef saturate
  1996. #define saturate( a ) clamp( a, 0.0, 1.0 )
  1997. #endif
  1998. uniform float toneMappingExposure;
  1999. vec3 LinearToneMapping( vec3 color ) {
  2000. return saturate( toneMappingExposure * color );
  2001. }
  2002. vec3 ReinhardToneMapping( vec3 color ) {
  2003. color *= toneMappingExposure;
  2004. return saturate( color / ( vec3( 1.0 ) + color ) );
  2005. }
  2006. vec3 CineonToneMapping( vec3 color ) {
  2007. color *= toneMappingExposure;
  2008. color = max( vec3( 0.0 ), color - 0.004 );
  2009. return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
  2010. }
  2011. vec3 RRTAndODTFit( vec3 v ) {
  2012. vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
  2013. vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
  2014. return a / b;
  2015. }
  2016. vec3 ACESFilmicToneMapping( vec3 color ) {
  2017. const mat3 ACESInputMat = mat3(
  2018. vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ),
  2019. vec3( 0.04823, 0.01566, 0.83777 )
  2020. );
  2021. const mat3 ACESOutputMat = mat3(
  2022. vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ),
  2023. vec3( -0.07367, -0.00605, 1.07602 )
  2024. );
  2025. color *= toneMappingExposure / 0.6;
  2026. color = ACESInputMat * color;
  2027. color = RRTAndODTFit( color );
  2028. color = ACESOutputMat * color;
  2029. return saturate( color );
  2030. }
  2031. const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
  2032. vec3( 1.6605, - 0.1246, - 0.0182 ),
  2033. vec3( - 0.5876, 1.1329, - 0.1006 ),
  2034. vec3( - 0.0728, - 0.0083, 1.1187 )
  2035. );
  2036. const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
  2037. vec3( 0.6274, 0.0691, 0.0164 ),
  2038. vec3( 0.3293, 0.9195, 0.0880 ),
  2039. vec3( 0.0433, 0.0113, 0.8956 )
  2040. );
  2041. vec3 agxDefaultContrastApprox( vec3 x ) {
  2042. vec3 x2 = x * x;
  2043. vec3 x4 = x2 * x2;
  2044. return + 15.5 * x4 * x2
  2045. - 40.14 * x4 * x
  2046. + 31.96 * x4
  2047. - 6.868 * x2 * x
  2048. + 0.4298 * x2
  2049. + 0.1191 * x
  2050. - 0.00232;
  2051. }
  2052. vec3 AgXToneMapping( vec3 color ) {
  2053. const mat3 AgXInsetMatrix = mat3(
  2054. vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),
  2055. vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),
  2056. vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )
  2057. );
  2058. const mat3 AgXOutsetMatrix = mat3(
  2059. vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),
  2060. vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),
  2061. vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
  2062. );
  2063. const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069;
  2064. color *= toneMappingExposure;
  2065. color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
  2066. color = AgXInsetMatrix * color;
  2067. color = max( color, 1e-10 ); color = log2( color );
  2068. color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );
  2069. color = clamp( color, 0.0, 1.0 );
  2070. color = agxDefaultContrastApprox( color );
  2071. color = AgXOutsetMatrix * color;
  2072. color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );
  2073. color = LINEAR_REC2020_TO_LINEAR_SRGB * color;
  2074. color = clamp( color, 0.0, 1.0 );
  2075. return color;
  2076. }
  2077. vec3 NeutralToneMapping( vec3 color ) {
  2078. const float StartCompression = 0.8 - 0.04;
  2079. const float Desaturation = 0.15;
  2080. color *= toneMappingExposure;
  2081. float x = min( color.r, min( color.g, color.b ) );
  2082. float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
  2083. color -= offset;
  2084. float peak = max( color.r, max( color.g, color.b ) );
  2085. if ( peak < StartCompression ) return color;
  2086. float d = 1. - StartCompression;
  2087. float newPeak = 1. - d * d / ( peak + d - StartCompression );
  2088. color *= newPeak / peak;
  2089. float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
  2090. return mix( color, vec3( newPeak ), g );
  2091. }
  2092. vec3 CustomToneMapping( vec3 color ) { return color; }`,wa=`#ifdef USE_TRANSMISSION
  2093. material.transmission = transmission;
  2094. material.transmissionAlpha = 1.0;
  2095. material.thickness = thickness;
  2096. material.attenuationDistance = attenuationDistance;
  2097. material.attenuationColor = attenuationColor;
  2098. #ifdef USE_TRANSMISSIONMAP
  2099. material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;
  2100. #endif
  2101. #ifdef USE_THICKNESSMAP
  2102. material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;
  2103. #endif
  2104. vec3 pos = vWorldPosition;
  2105. vec3 v = normalize( cameraPosition - pos );
  2106. vec3 n = inverseTransformDirection( normal, viewMatrix );
  2107. vec4 transmitted = getIBLVolumeRefraction(
  2108. n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
  2109. pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,
  2110. material.attenuationColor, material.attenuationDistance );
  2111. material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
  2112. totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
  2113. #endif`,Aa=`#ifdef USE_TRANSMISSION
  2114. uniform float transmission;
  2115. uniform float thickness;
  2116. uniform float attenuationDistance;
  2117. uniform vec3 attenuationColor;
  2118. #ifdef USE_TRANSMISSIONMAP
  2119. uniform sampler2D transmissionMap;
  2120. #endif
  2121. #ifdef USE_THICKNESSMAP
  2122. uniform sampler2D thicknessMap;
  2123. #endif
  2124. uniform vec2 transmissionSamplerSize;
  2125. uniform sampler2D transmissionSamplerMap;
  2126. uniform mat4 modelMatrix;
  2127. uniform mat4 projectionMatrix;
  2128. varying vec3 vWorldPosition;
  2129. float w0( float a ) {
  2130. return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
  2131. }
  2132. float w1( float a ) {
  2133. return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );
  2134. }
  2135. float w2( float a ){
  2136. return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );
  2137. }
  2138. float w3( float a ) {
  2139. return ( 1.0 / 6.0 ) * ( a * a * a );
  2140. }
  2141. float g0( float a ) {
  2142. return w0( a ) + w1( a );
  2143. }
  2144. float g1( float a ) {
  2145. return w2( a ) + w3( a );
  2146. }
  2147. float h0( float a ) {
  2148. return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );
  2149. }
  2150. float h1( float a ) {
  2151. return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );
  2152. }
  2153. vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {
  2154. uv = uv * texelSize.zw + 0.5;
  2155. vec2 iuv = floor( uv );
  2156. vec2 fuv = fract( uv );
  2157. float g0x = g0( fuv.x );
  2158. float g1x = g1( fuv.x );
  2159. float h0x = h0( fuv.x );
  2160. float h1x = h1( fuv.x );
  2161. float h0y = h0( fuv.y );
  2162. float h1y = h1( fuv.y );
  2163. vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
  2164. vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
  2165. vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
  2166. vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
  2167. return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +
  2168. g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );
  2169. }
  2170. vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {
  2171. vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );
  2172. vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );
  2173. vec2 fLodSizeInv = 1.0 / fLodSize;
  2174. vec2 cLodSizeInv = 1.0 / cLodSize;
  2175. vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
  2176. vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
  2177. return mix( fSample, cSample, fract( lod ) );
  2178. }
  2179. vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
  2180. vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
  2181. vec3 modelScale;
  2182. modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
  2183. modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
  2184. modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
  2185. return normalize( refractionVector ) * thickness * modelScale;
  2186. }
  2187. float applyIorToRoughness( const in float roughness, const in float ior ) {
  2188. return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
  2189. }
  2190. vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
  2191. float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
  2192. return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );
  2193. }
  2194. vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
  2195. if ( isinf( attenuationDistance ) ) {
  2196. return vec3( 1.0 );
  2197. } else {
  2198. vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
  2199. vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance;
  2200. }
  2201. }
  2202. vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
  2203. const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
  2204. const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,
  2205. const in vec3 attenuationColor, const in float attenuationDistance ) {
  2206. vec4 transmittedLight;
  2207. vec3 transmittance;
  2208. #ifdef USE_DISPERSION
  2209. float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;
  2210. vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );
  2211. for ( int i = 0; i < 3; i ++ ) {
  2212. vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );
  2213. vec3 refractedRayExit = position + transmissionRay;
  2214. vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
  2215. vec2 refractionCoords = ndcPos.xy / ndcPos.w;
  2216. refractionCoords += 1.0;
  2217. refractionCoords /= 2.0;
  2218. vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );
  2219. transmittedLight[ i ] = transmissionSample[ i ];
  2220. transmittedLight.a += transmissionSample.a;
  2221. transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];
  2222. }
  2223. transmittedLight.a /= 3.0;
  2224. #else
  2225. vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
  2226. vec3 refractedRayExit = position + transmissionRay;
  2227. vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
  2228. vec2 refractionCoords = ndcPos.xy / ndcPos.w;
  2229. refractionCoords += 1.0;
  2230. refractionCoords /= 2.0;
  2231. transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
  2232. transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
  2233. #endif
  2234. vec3 attenuatedColor = transmittance * transmittedLight.rgb;
  2235. vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
  2236. float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
  2237. return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
  2238. }
  2239. #endif`,Ta=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
  2240. varying vec2 vUv;
  2241. #endif
  2242. #ifdef USE_MAP
  2243. varying vec2 vMapUv;
  2244. #endif
  2245. #ifdef USE_ALPHAMAP
  2246. varying vec2 vAlphaMapUv;
  2247. #endif
  2248. #ifdef USE_LIGHTMAP
  2249. varying vec2 vLightMapUv;
  2250. #endif
  2251. #ifdef USE_AOMAP
  2252. varying vec2 vAoMapUv;
  2253. #endif
  2254. #ifdef USE_BUMPMAP
  2255. varying vec2 vBumpMapUv;
  2256. #endif
  2257. #ifdef USE_NORMALMAP
  2258. varying vec2 vNormalMapUv;
  2259. #endif
  2260. #ifdef USE_EMISSIVEMAP
  2261. varying vec2 vEmissiveMapUv;
  2262. #endif
  2263. #ifdef USE_METALNESSMAP
  2264. varying vec2 vMetalnessMapUv;
  2265. #endif
  2266. #ifdef USE_ROUGHNESSMAP
  2267. varying vec2 vRoughnessMapUv;
  2268. #endif
  2269. #ifdef USE_ANISOTROPYMAP
  2270. varying vec2 vAnisotropyMapUv;
  2271. #endif
  2272. #ifdef USE_CLEARCOATMAP
  2273. varying vec2 vClearcoatMapUv;
  2274. #endif
  2275. #ifdef USE_CLEARCOAT_NORMALMAP
  2276. varying vec2 vClearcoatNormalMapUv;
  2277. #endif
  2278. #ifdef USE_CLEARCOAT_ROUGHNESSMAP
  2279. varying vec2 vClearcoatRoughnessMapUv;
  2280. #endif
  2281. #ifdef USE_IRIDESCENCEMAP
  2282. varying vec2 vIridescenceMapUv;
  2283. #endif
  2284. #ifdef USE_IRIDESCENCE_THICKNESSMAP
  2285. varying vec2 vIridescenceThicknessMapUv;
  2286. #endif
  2287. #ifdef USE_SHEEN_COLORMAP
  2288. varying vec2 vSheenColorMapUv;
  2289. #endif
  2290. #ifdef USE_SHEEN_ROUGHNESSMAP
  2291. varying vec2 vSheenRoughnessMapUv;
  2292. #endif
  2293. #ifdef USE_SPECULARMAP
  2294. varying vec2 vSpecularMapUv;
  2295. #endif
  2296. #ifdef USE_SPECULAR_COLORMAP
  2297. varying vec2 vSpecularColorMapUv;
  2298. #endif
  2299. #ifdef USE_SPECULAR_INTENSITYMAP
  2300. varying vec2 vSpecularIntensityMapUv;
  2301. #endif
  2302. #ifdef USE_TRANSMISSIONMAP
  2303. uniform mat3 transmissionMapTransform;
  2304. varying vec2 vTransmissionMapUv;
  2305. #endif
  2306. #ifdef USE_THICKNESSMAP
  2307. uniform mat3 thicknessMapTransform;
  2308. varying vec2 vThicknessMapUv;
  2309. #endif`,Ea=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
  2310. varying vec2 vUv;
  2311. #endif
  2312. #ifdef USE_MAP
  2313. uniform mat3 mapTransform;
  2314. varying vec2 vMapUv;
  2315. #endif
  2316. #ifdef USE_ALPHAMAP
  2317. uniform mat3 alphaMapTransform;
  2318. varying vec2 vAlphaMapUv;
  2319. #endif
  2320. #ifdef USE_LIGHTMAP
  2321. uniform mat3 lightMapTransform;
  2322. varying vec2 vLightMapUv;
  2323. #endif
  2324. #ifdef USE_AOMAP
  2325. uniform mat3 aoMapTransform;
  2326. varying vec2 vAoMapUv;
  2327. #endif
  2328. #ifdef USE_BUMPMAP
  2329. uniform mat3 bumpMapTransform;
  2330. varying vec2 vBumpMapUv;
  2331. #endif
  2332. #ifdef USE_NORMALMAP
  2333. uniform mat3 normalMapTransform;
  2334. varying vec2 vNormalMapUv;
  2335. #endif
  2336. #ifdef USE_DISPLACEMENTMAP
  2337. uniform mat3 displacementMapTransform;
  2338. varying vec2 vDisplacementMapUv;
  2339. #endif
  2340. #ifdef USE_EMISSIVEMAP
  2341. uniform mat3 emissiveMapTransform;
  2342. varying vec2 vEmissiveMapUv;
  2343. #endif
  2344. #ifdef USE_METALNESSMAP
  2345. uniform mat3 metalnessMapTransform;
  2346. varying vec2 vMetalnessMapUv;
  2347. #endif
  2348. #ifdef USE_ROUGHNESSMAP
  2349. uniform mat3 roughnessMapTransform;
  2350. varying vec2 vRoughnessMapUv;
  2351. #endif
  2352. #ifdef USE_ANISOTROPYMAP
  2353. uniform mat3 anisotropyMapTransform;
  2354. varying vec2 vAnisotropyMapUv;
  2355. #endif
  2356. #ifdef USE_CLEARCOATMAP
  2357. uniform mat3 clearcoatMapTransform;
  2358. varying vec2 vClearcoatMapUv;
  2359. #endif
  2360. #ifdef USE_CLEARCOAT_NORMALMAP
  2361. uniform mat3 clearcoatNormalMapTransform;
  2362. varying vec2 vClearcoatNormalMapUv;
  2363. #endif
  2364. #ifdef USE_CLEARCOAT_ROUGHNESSMAP
  2365. uniform mat3 clearcoatRoughnessMapTransform;
  2366. varying vec2 vClearcoatRoughnessMapUv;
  2367. #endif
  2368. #ifdef USE_SHEEN_COLORMAP
  2369. uniform mat3 sheenColorMapTransform;
  2370. varying vec2 vSheenColorMapUv;
  2371. #endif
  2372. #ifdef USE_SHEEN_ROUGHNESSMAP
  2373. uniform mat3 sheenRoughnessMapTransform;
  2374. varying vec2 vSheenRoughnessMapUv;
  2375. #endif
  2376. #ifdef USE_IRIDESCENCEMAP
  2377. uniform mat3 iridescenceMapTransform;
  2378. varying vec2 vIridescenceMapUv;
  2379. #endif
  2380. #ifdef USE_IRIDESCENCE_THICKNESSMAP
  2381. uniform mat3 iridescenceThicknessMapTransform;
  2382. varying vec2 vIridescenceThicknessMapUv;
  2383. #endif
  2384. #ifdef USE_SPECULARMAP
  2385. uniform mat3 specularMapTransform;
  2386. varying vec2 vSpecularMapUv;
  2387. #endif
  2388. #ifdef USE_SPECULAR_COLORMAP
  2389. uniform mat3 specularColorMapTransform;
  2390. varying vec2 vSpecularColorMapUv;
  2391. #endif
  2392. #ifdef USE_SPECULAR_INTENSITYMAP
  2393. uniform mat3 specularIntensityMapTransform;
  2394. varying vec2 vSpecularIntensityMapUv;
  2395. #endif
  2396. #ifdef USE_TRANSMISSIONMAP
  2397. uniform mat3 transmissionMapTransform;
  2398. varying vec2 vTransmissionMapUv;
  2399. #endif
  2400. #ifdef USE_THICKNESSMAP
  2401. uniform mat3 thicknessMapTransform;
  2402. varying vec2 vThicknessMapUv;
  2403. #endif`,Ca=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
  2404. vUv = vec3( uv, 1 ).xy;
  2405. #endif
  2406. #ifdef USE_MAP
  2407. vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;
  2408. #endif
  2409. #ifdef USE_ALPHAMAP
  2410. vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;
  2411. #endif
  2412. #ifdef USE_LIGHTMAP
  2413. vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;
  2414. #endif
  2415. #ifdef USE_AOMAP
  2416. vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;
  2417. #endif
  2418. #ifdef USE_BUMPMAP
  2419. vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;
  2420. #endif
  2421. #ifdef USE_NORMALMAP
  2422. vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;
  2423. #endif
  2424. #ifdef USE_DISPLACEMENTMAP
  2425. vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;
  2426. #endif
  2427. #ifdef USE_EMISSIVEMAP
  2428. vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;
  2429. #endif
  2430. #ifdef USE_METALNESSMAP
  2431. vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;
  2432. #endif
  2433. #ifdef USE_ROUGHNESSMAP
  2434. vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;
  2435. #endif
  2436. #ifdef USE_ANISOTROPYMAP
  2437. vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;
  2438. #endif
  2439. #ifdef USE_CLEARCOATMAP
  2440. vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;
  2441. #endif
  2442. #ifdef USE_CLEARCOAT_NORMALMAP
  2443. vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;
  2444. #endif
  2445. #ifdef USE_CLEARCOAT_ROUGHNESSMAP
  2446. vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;
  2447. #endif
  2448. #ifdef USE_IRIDESCENCEMAP
  2449. vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;
  2450. #endif
  2451. #ifdef USE_IRIDESCENCE_THICKNESSMAP
  2452. vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;
  2453. #endif
  2454. #ifdef USE_SHEEN_COLORMAP
  2455. vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;
  2456. #endif
  2457. #ifdef USE_SHEEN_ROUGHNESSMAP
  2458. vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;
  2459. #endif
  2460. #ifdef USE_SPECULARMAP
  2461. vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;
  2462. #endif
  2463. #ifdef USE_SPECULAR_COLORMAP
  2464. vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;
  2465. #endif
  2466. #ifdef USE_SPECULAR_INTENSITYMAP
  2467. vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;
  2468. #endif
  2469. #ifdef USE_TRANSMISSIONMAP
  2470. vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;
  2471. #endif
  2472. #ifdef USE_THICKNESSMAP
  2473. vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
  2474. #endif`,Ra=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
  2475. vec4 worldPosition = vec4( transformed, 1.0 );
  2476. #ifdef USE_BATCHING
  2477. worldPosition = batchingMatrix * worldPosition;
  2478. #endif
  2479. #ifdef USE_INSTANCING
  2480. worldPosition = instanceMatrix * worldPosition;
  2481. #endif
  2482. worldPosition = modelMatrix * worldPosition;
  2483. #endif`,Pa=`varying vec2 vUv;
  2484. uniform mat3 uvTransform;
  2485. void main() {
  2486. vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
  2487. gl_Position = vec4( position.xy, 1.0, 1.0 );
  2488. }`,Ia=`uniform sampler2D t2D;
  2489. uniform float backgroundIntensity;
  2490. varying vec2 vUv;
  2491. void main() {
  2492. vec4 texColor = texture2D( t2D, vUv );
  2493. #ifdef DECODE_VIDEO_TEXTURE
  2494. 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 );
  2495. #endif
  2496. texColor.rgb *= backgroundIntensity;
  2497. gl_FragColor = texColor;
  2498. #include <tonemapping_fragment>
  2499. #include <colorspace_fragment>
  2500. }`,La=`varying vec3 vWorldDirection;
  2501. #include <common>
  2502. void main() {
  2503. vWorldDirection = transformDirection( position, modelMatrix );
  2504. #include <begin_vertex>
  2505. #include <project_vertex>
  2506. gl_Position.z = gl_Position.w;
  2507. }`,Da=`#ifdef ENVMAP_TYPE_CUBE
  2508. uniform samplerCube envMap;
  2509. #elif defined( ENVMAP_TYPE_CUBE_UV )
  2510. uniform sampler2D envMap;
  2511. #endif
  2512. uniform float flipEnvMap;
  2513. uniform float backgroundBlurriness;
  2514. uniform float backgroundIntensity;
  2515. uniform mat3 backgroundRotation;
  2516. varying vec3 vWorldDirection;
  2517. #include <cube_uv_reflection_fragment>
  2518. void main() {
  2519. #ifdef ENVMAP_TYPE_CUBE
  2520. vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );
  2521. #elif defined( ENVMAP_TYPE_CUBE_UV )
  2522. vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );
  2523. #else
  2524. vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  2525. #endif
  2526. texColor.rgb *= backgroundIntensity;
  2527. gl_FragColor = texColor;
  2528. #include <tonemapping_fragment>
  2529. #include <colorspace_fragment>
  2530. }`,Ua=`varying vec3 vWorldDirection;
  2531. #include <common>
  2532. void main() {
  2533. vWorldDirection = transformDirection( position, modelMatrix );
  2534. #include <begin_vertex>
  2535. #include <project_vertex>
  2536. gl_Position.z = gl_Position.w;
  2537. }`,Na=`uniform samplerCube tCube;
  2538. uniform float tFlip;
  2539. uniform float opacity;
  2540. varying vec3 vWorldDirection;
  2541. void main() {
  2542. vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
  2543. gl_FragColor = texColor;
  2544. gl_FragColor.a *= opacity;
  2545. #include <tonemapping_fragment>
  2546. #include <colorspace_fragment>
  2547. }`,Fa=`#include <common>
  2548. #include <batching_pars_vertex>
  2549. #include <uv_pars_vertex>
  2550. #include <displacementmap_pars_vertex>
  2551. #include <morphtarget_pars_vertex>
  2552. #include <skinning_pars_vertex>
  2553. #include <logdepthbuf_pars_vertex>
  2554. #include <clipping_planes_pars_vertex>
  2555. varying vec2 vHighPrecisionZW;
  2556. void main() {
  2557. #include <uv_vertex>
  2558. #include <batching_vertex>
  2559. #include <skinbase_vertex>
  2560. #include <morphinstance_vertex>
  2561. #ifdef USE_DISPLACEMENTMAP
  2562. #include <beginnormal_vertex>
  2563. #include <morphnormal_vertex>
  2564. #include <skinnormal_vertex>
  2565. #endif
  2566. #include <begin_vertex>
  2567. #include <morphtarget_vertex>
  2568. #include <skinning_vertex>
  2569. #include <displacementmap_vertex>
  2570. #include <project_vertex>
  2571. #include <logdepthbuf_vertex>
  2572. #include <clipping_planes_vertex>
  2573. vHighPrecisionZW = gl_Position.zw;
  2574. }`,Ba=`#if DEPTH_PACKING == 3200
  2575. uniform float opacity;
  2576. #endif
  2577. #include <common>
  2578. #include <packing>
  2579. #include <uv_pars_fragment>
  2580. #include <map_pars_fragment>
  2581. #include <alphamap_pars_fragment>
  2582. #include <alphatest_pars_fragment>
  2583. #include <alphahash_pars_fragment>
  2584. #include <logdepthbuf_pars_fragment>
  2585. #include <clipping_planes_pars_fragment>
  2586. varying vec2 vHighPrecisionZW;
  2587. void main() {
  2588. vec4 diffuseColor = vec4( 1.0 );
  2589. #include <clipping_planes_fragment>
  2590. #if DEPTH_PACKING == 3200
  2591. diffuseColor.a = opacity;
  2592. #endif
  2593. #include <map_fragment>
  2594. #include <alphamap_fragment>
  2595. #include <alphatest_fragment>
  2596. #include <alphahash_fragment>
  2597. #include <logdepthbuf_fragment>
  2598. float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
  2599. #if DEPTH_PACKING == 3200
  2600. gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
  2601. #elif DEPTH_PACKING == 3201
  2602. gl_FragColor = packDepthToRGBA( fragCoordZ );
  2603. #elif DEPTH_PACKING == 3202
  2604. gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );
  2605. #elif DEPTH_PACKING == 3203
  2606. gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
  2607. #endif
  2608. }`,Oa=`#define DISTANCE
  2609. varying vec3 vWorldPosition;
  2610. #include <common>
  2611. #include <batching_pars_vertex>
  2612. #include <uv_pars_vertex>
  2613. #include <displacementmap_pars_vertex>
  2614. #include <morphtarget_pars_vertex>
  2615. #include <skinning_pars_vertex>
  2616. #include <clipping_planes_pars_vertex>
  2617. void main() {
  2618. #include <uv_vertex>
  2619. #include <batching_vertex>
  2620. #include <skinbase_vertex>
  2621. #include <morphinstance_vertex>
  2622. #ifdef USE_DISPLACEMENTMAP
  2623. #include <beginnormal_vertex>
  2624. #include <morphnormal_vertex>
  2625. #include <skinnormal_vertex>
  2626. #endif
  2627. #include <begin_vertex>
  2628. #include <morphtarget_vertex>
  2629. #include <skinning_vertex>
  2630. #include <displacementmap_vertex>
  2631. #include <project_vertex>
  2632. #include <worldpos_vertex>
  2633. #include <clipping_planes_vertex>
  2634. vWorldPosition = worldPosition.xyz;
  2635. }`,za=`#define DISTANCE
  2636. uniform vec3 referencePosition;
  2637. uniform float nearDistance;
  2638. uniform float farDistance;
  2639. varying vec3 vWorldPosition;
  2640. #include <common>
  2641. #include <packing>
  2642. #include <uv_pars_fragment>
  2643. #include <map_pars_fragment>
  2644. #include <alphamap_pars_fragment>
  2645. #include <alphatest_pars_fragment>
  2646. #include <alphahash_pars_fragment>
  2647. #include <clipping_planes_pars_fragment>
  2648. void main () {
  2649. vec4 diffuseColor = vec4( 1.0 );
  2650. #include <clipping_planes_fragment>
  2651. #include <map_fragment>
  2652. #include <alphamap_fragment>
  2653. #include <alphatest_fragment>
  2654. #include <alphahash_fragment>
  2655. float dist = length( vWorldPosition - referencePosition );
  2656. dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
  2657. dist = saturate( dist );
  2658. gl_FragColor = packDepthToRGBA( dist );
  2659. }`,ka=`varying vec3 vWorldDirection;
  2660. #include <common>
  2661. void main() {
  2662. vWorldDirection = transformDirection( position, modelMatrix );
  2663. #include <begin_vertex>
  2664. #include <project_vertex>
  2665. }`,Va=`uniform sampler2D tEquirect;
  2666. varying vec3 vWorldDirection;
  2667. #include <common>
  2668. void main() {
  2669. vec3 direction = normalize( vWorldDirection );
  2670. vec2 sampleUV = equirectUv( direction );
  2671. gl_FragColor = texture2D( tEquirect, sampleUV );
  2672. #include <tonemapping_fragment>
  2673. #include <colorspace_fragment>
  2674. }`,Ha=`uniform float scale;
  2675. attribute float lineDistance;
  2676. varying float vLineDistance;
  2677. #include <common>
  2678. #include <uv_pars_vertex>
  2679. #include <color_pars_vertex>
  2680. #include <fog_pars_vertex>
  2681. #include <morphtarget_pars_vertex>
  2682. #include <logdepthbuf_pars_vertex>
  2683. #include <clipping_planes_pars_vertex>
  2684. void main() {
  2685. vLineDistance = scale * lineDistance;
  2686. #include <uv_vertex>
  2687. #include <color_vertex>
  2688. #include <morphinstance_vertex>
  2689. #include <morphcolor_vertex>
  2690. #include <begin_vertex>
  2691. #include <morphtarget_vertex>
  2692. #include <project_vertex>
  2693. #include <logdepthbuf_vertex>
  2694. #include <clipping_planes_vertex>
  2695. #include <fog_vertex>
  2696. }`,Ga=`uniform vec3 diffuse;
  2697. uniform float opacity;
  2698. uniform float dashSize;
  2699. uniform float totalSize;
  2700. varying float vLineDistance;
  2701. #include <common>
  2702. #include <color_pars_fragment>
  2703. #include <uv_pars_fragment>
  2704. #include <map_pars_fragment>
  2705. #include <fog_pars_fragment>
  2706. #include <logdepthbuf_pars_fragment>
  2707. #include <clipping_planes_pars_fragment>
  2708. void main() {
  2709. vec4 diffuseColor = vec4( diffuse, opacity );
  2710. #include <clipping_planes_fragment>
  2711. if ( mod( vLineDistance, totalSize ) > dashSize ) {
  2712. discard;
  2713. }
  2714. vec3 outgoingLight = vec3( 0.0 );
  2715. #include <logdepthbuf_fragment>
  2716. #include <map_fragment>
  2717. #include <color_fragment>
  2718. outgoingLight = diffuseColor.rgb;
  2719. #include <opaque_fragment>
  2720. #include <tonemapping_fragment>
  2721. #include <colorspace_fragment>
  2722. #include <fog_fragment>
  2723. #include <premultiplied_alpha_fragment>
  2724. }`,Wa=`#include <common>
  2725. #include <batching_pars_vertex>
  2726. #include <uv_pars_vertex>
  2727. #include <envmap_pars_vertex>
  2728. #include <color_pars_vertex>
  2729. #include <fog_pars_vertex>
  2730. #include <morphtarget_pars_vertex>
  2731. #include <skinning_pars_vertex>
  2732. #include <logdepthbuf_pars_vertex>
  2733. #include <clipping_planes_pars_vertex>
  2734. void main() {
  2735. #include <uv_vertex>
  2736. #include <color_vertex>
  2737. #include <morphinstance_vertex>
  2738. #include <morphcolor_vertex>
  2739. #include <batching_vertex>
  2740. #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
  2741. #include <beginnormal_vertex>
  2742. #include <morphnormal_vertex>
  2743. #include <skinbase_vertex>
  2744. #include <skinnormal_vertex>
  2745. #include <defaultnormal_vertex>
  2746. #endif
  2747. #include <begin_vertex>
  2748. #include <morphtarget_vertex>
  2749. #include <skinning_vertex>
  2750. #include <project_vertex>
  2751. #include <logdepthbuf_vertex>
  2752. #include <clipping_planes_vertex>
  2753. #include <worldpos_vertex>
  2754. #include <envmap_vertex>
  2755. #include <fog_vertex>
  2756. }`,Xa=`uniform vec3 diffuse;
  2757. uniform float opacity;
  2758. #ifndef FLAT_SHADED
  2759. varying vec3 vNormal;
  2760. #endif
  2761. #include <common>
  2762. #include <dithering_pars_fragment>
  2763. #include <color_pars_fragment>
  2764. #include <uv_pars_fragment>
  2765. #include <map_pars_fragment>
  2766. #include <alphamap_pars_fragment>
  2767. #include <alphatest_pars_fragment>
  2768. #include <alphahash_pars_fragment>
  2769. #include <aomap_pars_fragment>
  2770. #include <lightmap_pars_fragment>
  2771. #include <envmap_common_pars_fragment>
  2772. #include <envmap_pars_fragment>
  2773. #include <fog_pars_fragment>
  2774. #include <specularmap_pars_fragment>
  2775. #include <logdepthbuf_pars_fragment>
  2776. #include <clipping_planes_pars_fragment>
  2777. void main() {
  2778. vec4 diffuseColor = vec4( diffuse, opacity );
  2779. #include <clipping_planes_fragment>
  2780. #include <logdepthbuf_fragment>
  2781. #include <map_fragment>
  2782. #include <color_fragment>
  2783. #include <alphamap_fragment>
  2784. #include <alphatest_fragment>
  2785. #include <alphahash_fragment>
  2786. #include <specularmap_fragment>
  2787. ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
  2788. #ifdef USE_LIGHTMAP
  2789. vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
  2790. reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
  2791. #else
  2792. reflectedLight.indirectDiffuse += vec3( 1.0 );
  2793. #endif
  2794. #include <aomap_fragment>
  2795. reflectedLight.indirectDiffuse *= diffuseColor.rgb;
  2796. vec3 outgoingLight = reflectedLight.indirectDiffuse;
  2797. #include <envmap_fragment>
  2798. #include <opaque_fragment>
  2799. #include <tonemapping_fragment>
  2800. #include <colorspace_fragment>
  2801. #include <fog_fragment>
  2802. #include <premultiplied_alpha_fragment>
  2803. #include <dithering_fragment>
  2804. }`,qa=`#define LAMBERT
  2805. varying vec3 vViewPosition;
  2806. #include <common>
  2807. #include <batching_pars_vertex>
  2808. #include <uv_pars_vertex>
  2809. #include <displacementmap_pars_vertex>
  2810. #include <envmap_pars_vertex>
  2811. #include <color_pars_vertex>
  2812. #include <fog_pars_vertex>
  2813. #include <normal_pars_vertex>
  2814. #include <morphtarget_pars_vertex>
  2815. #include <skinning_pars_vertex>
  2816. #include <shadowmap_pars_vertex>
  2817. #include <logdepthbuf_pars_vertex>
  2818. #include <clipping_planes_pars_vertex>
  2819. void main() {
  2820. #include <uv_vertex>
  2821. #include <color_vertex>
  2822. #include <morphinstance_vertex>
  2823. #include <morphcolor_vertex>
  2824. #include <batching_vertex>
  2825. #include <beginnormal_vertex>
  2826. #include <morphnormal_vertex>
  2827. #include <skinbase_vertex>
  2828. #include <skinnormal_vertex>
  2829. #include <defaultnormal_vertex>
  2830. #include <normal_vertex>
  2831. #include <begin_vertex>
  2832. #include <morphtarget_vertex>
  2833. #include <skinning_vertex>
  2834. #include <displacementmap_vertex>
  2835. #include <project_vertex>
  2836. #include <logdepthbuf_vertex>
  2837. #include <clipping_planes_vertex>
  2838. vViewPosition = - mvPosition.xyz;
  2839. #include <worldpos_vertex>
  2840. #include <envmap_vertex>
  2841. #include <shadowmap_vertex>
  2842. #include <fog_vertex>
  2843. }`,Ya=`#define LAMBERT
  2844. uniform vec3 diffuse;
  2845. uniform vec3 emissive;
  2846. uniform float opacity;
  2847. #include <common>
  2848. #include <packing>
  2849. #include <dithering_pars_fragment>
  2850. #include <color_pars_fragment>
  2851. #include <uv_pars_fragment>
  2852. #include <map_pars_fragment>
  2853. #include <alphamap_pars_fragment>
  2854. #include <alphatest_pars_fragment>
  2855. #include <alphahash_pars_fragment>
  2856. #include <aomap_pars_fragment>
  2857. #include <lightmap_pars_fragment>
  2858. #include <emissivemap_pars_fragment>
  2859. #include <envmap_common_pars_fragment>
  2860. #include <envmap_pars_fragment>
  2861. #include <fog_pars_fragment>
  2862. #include <bsdfs>
  2863. #include <lights_pars_begin>
  2864. #include <normal_pars_fragment>
  2865. #include <lights_lambert_pars_fragment>
  2866. #include <shadowmap_pars_fragment>
  2867. #include <bumpmap_pars_fragment>
  2868. #include <normalmap_pars_fragment>
  2869. #include <specularmap_pars_fragment>
  2870. #include <logdepthbuf_pars_fragment>
  2871. #include <clipping_planes_pars_fragment>
  2872. void main() {
  2873. vec4 diffuseColor = vec4( diffuse, opacity );
  2874. #include <clipping_planes_fragment>
  2875. ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
  2876. vec3 totalEmissiveRadiance = emissive;
  2877. #include <logdepthbuf_fragment>
  2878. #include <map_fragment>
  2879. #include <color_fragment>
  2880. #include <alphamap_fragment>
  2881. #include <alphatest_fragment>
  2882. #include <alphahash_fragment>
  2883. #include <specularmap_fragment>
  2884. #include <normal_fragment_begin>
  2885. #include <normal_fragment_maps>
  2886. #include <emissivemap_fragment>
  2887. #include <lights_lambert_fragment>
  2888. #include <lights_fragment_begin>
  2889. #include <lights_fragment_maps>
  2890. #include <lights_fragment_end>
  2891. #include <aomap_fragment>
  2892. vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
  2893. #include <envmap_fragment>
  2894. #include <opaque_fragment>
  2895. #include <tonemapping_fragment>
  2896. #include <colorspace_fragment>
  2897. #include <fog_fragment>
  2898. #include <premultiplied_alpha_fragment>
  2899. #include <dithering_fragment>
  2900. }`,Za=`#define MATCAP
  2901. varying vec3 vViewPosition;
  2902. #include <common>
  2903. #include <batching_pars_vertex>
  2904. #include <uv_pars_vertex>
  2905. #include <color_pars_vertex>
  2906. #include <displacementmap_pars_vertex>
  2907. #include <fog_pars_vertex>
  2908. #include <normal_pars_vertex>
  2909. #include <morphtarget_pars_vertex>
  2910. #include <skinning_pars_vertex>
  2911. #include <logdepthbuf_pars_vertex>
  2912. #include <clipping_planes_pars_vertex>
  2913. void main() {
  2914. #include <uv_vertex>
  2915. #include <color_vertex>
  2916. #include <morphinstance_vertex>
  2917. #include <morphcolor_vertex>
  2918. #include <batching_vertex>
  2919. #include <beginnormal_vertex>
  2920. #include <morphnormal_vertex>
  2921. #include <skinbase_vertex>
  2922. #include <skinnormal_vertex>
  2923. #include <defaultnormal_vertex>
  2924. #include <normal_vertex>
  2925. #include <begin_vertex>
  2926. #include <morphtarget_vertex>
  2927. #include <skinning_vertex>
  2928. #include <displacementmap_vertex>
  2929. #include <project_vertex>
  2930. #include <logdepthbuf_vertex>
  2931. #include <clipping_planes_vertex>
  2932. #include <fog_vertex>
  2933. vViewPosition = - mvPosition.xyz;
  2934. }`,Ja=`#define MATCAP
  2935. uniform vec3 diffuse;
  2936. uniform float opacity;
  2937. uniform sampler2D matcap;
  2938. varying vec3 vViewPosition;
  2939. #include <common>
  2940. #include <dithering_pars_fragment>
  2941. #include <color_pars_fragment>
  2942. #include <uv_pars_fragment>
  2943. #include <map_pars_fragment>
  2944. #include <alphamap_pars_fragment>
  2945. #include <alphatest_pars_fragment>
  2946. #include <alphahash_pars_fragment>
  2947. #include <fog_pars_fragment>
  2948. #include <normal_pars_fragment>
  2949. #include <bumpmap_pars_fragment>
  2950. #include <normalmap_pars_fragment>
  2951. #include <logdepthbuf_pars_fragment>
  2952. #include <clipping_planes_pars_fragment>
  2953. void main() {
  2954. vec4 diffuseColor = vec4( diffuse, opacity );
  2955. #include <clipping_planes_fragment>
  2956. #include <logdepthbuf_fragment>
  2957. #include <map_fragment>
  2958. #include <color_fragment>
  2959. #include <alphamap_fragment>
  2960. #include <alphatest_fragment>
  2961. #include <alphahash_fragment>
  2962. #include <normal_fragment_begin>
  2963. #include <normal_fragment_maps>
  2964. vec3 viewDir = normalize( vViewPosition );
  2965. vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );
  2966. vec3 y = cross( viewDir, x );
  2967. vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;
  2968. #ifdef USE_MATCAP
  2969. vec4 matcapColor = texture2D( matcap, uv );
  2970. #else
  2971. vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );
  2972. #endif
  2973. vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
  2974. #include <opaque_fragment>
  2975. #include <tonemapping_fragment>
  2976. #include <colorspace_fragment>
  2977. #include <fog_fragment>
  2978. #include <premultiplied_alpha_fragment>
  2979. #include <dithering_fragment>
  2980. }`,$a=`#define NORMAL
  2981. #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
  2982. varying vec3 vViewPosition;
  2983. #endif
  2984. #include <common>
  2985. #include <batching_pars_vertex>
  2986. #include <uv_pars_vertex>
  2987. #include <displacementmap_pars_vertex>
  2988. #include <normal_pars_vertex>
  2989. #include <morphtarget_pars_vertex>
  2990. #include <skinning_pars_vertex>
  2991. #include <logdepthbuf_pars_vertex>
  2992. #include <clipping_planes_pars_vertex>
  2993. void main() {
  2994. #include <uv_vertex>
  2995. #include <batching_vertex>
  2996. #include <beginnormal_vertex>
  2997. #include <morphinstance_vertex>
  2998. #include <morphnormal_vertex>
  2999. #include <skinbase_vertex>
  3000. #include <skinnormal_vertex>
  3001. #include <defaultnormal_vertex>
  3002. #include <normal_vertex>
  3003. #include <begin_vertex>
  3004. #include <morphtarget_vertex>
  3005. #include <skinning_vertex>
  3006. #include <displacementmap_vertex>
  3007. #include <project_vertex>
  3008. #include <logdepthbuf_vertex>
  3009. #include <clipping_planes_vertex>
  3010. #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
  3011. vViewPosition = - mvPosition.xyz;
  3012. #endif
  3013. }`,Ka=`#define NORMAL
  3014. uniform float opacity;
  3015. #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
  3016. varying vec3 vViewPosition;
  3017. #endif
  3018. #include <packing>
  3019. #include <uv_pars_fragment>
  3020. #include <normal_pars_fragment>
  3021. #include <bumpmap_pars_fragment>
  3022. #include <normalmap_pars_fragment>
  3023. #include <logdepthbuf_pars_fragment>
  3024. #include <clipping_planes_pars_fragment>
  3025. void main() {
  3026. vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );
  3027. #include <clipping_planes_fragment>
  3028. #include <logdepthbuf_fragment>
  3029. #include <normal_fragment_begin>
  3030. #include <normal_fragment_maps>
  3031. gl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );
  3032. #ifdef OPAQUE
  3033. gl_FragColor.a = 1.0;
  3034. #endif
  3035. }`,Qa=`#define PHONG
  3036. varying vec3 vViewPosition;
  3037. #include <common>
  3038. #include <batching_pars_vertex>
  3039. #include <uv_pars_vertex>
  3040. #include <displacementmap_pars_vertex>
  3041. #include <envmap_pars_vertex>
  3042. #include <color_pars_vertex>
  3043. #include <fog_pars_vertex>
  3044. #include <normal_pars_vertex>
  3045. #include <morphtarget_pars_vertex>
  3046. #include <skinning_pars_vertex>
  3047. #include <shadowmap_pars_vertex>
  3048. #include <logdepthbuf_pars_vertex>
  3049. #include <clipping_planes_pars_vertex>
  3050. void main() {
  3051. #include <uv_vertex>
  3052. #include <color_vertex>
  3053. #include <morphcolor_vertex>
  3054. #include <batching_vertex>
  3055. #include <beginnormal_vertex>
  3056. #include <morphinstance_vertex>
  3057. #include <morphnormal_vertex>
  3058. #include <skinbase_vertex>
  3059. #include <skinnormal_vertex>
  3060. #include <defaultnormal_vertex>
  3061. #include <normal_vertex>
  3062. #include <begin_vertex>
  3063. #include <morphtarget_vertex>
  3064. #include <skinning_vertex>
  3065. #include <displacementmap_vertex>
  3066. #include <project_vertex>
  3067. #include <logdepthbuf_vertex>
  3068. #include <clipping_planes_vertex>
  3069. vViewPosition = - mvPosition.xyz;
  3070. #include <worldpos_vertex>
  3071. #include <envmap_vertex>
  3072. #include <shadowmap_vertex>
  3073. #include <fog_vertex>
  3074. }`,ja=`#define PHONG
  3075. uniform vec3 diffuse;
  3076. uniform vec3 emissive;
  3077. uniform vec3 specular;
  3078. uniform float shininess;
  3079. uniform float opacity;
  3080. #include <common>
  3081. #include <packing>
  3082. #include <dithering_pars_fragment>
  3083. #include <color_pars_fragment>
  3084. #include <uv_pars_fragment>
  3085. #include <map_pars_fragment>
  3086. #include <alphamap_pars_fragment>
  3087. #include <alphatest_pars_fragment>
  3088. #include <alphahash_pars_fragment>
  3089. #include <aomap_pars_fragment>
  3090. #include <lightmap_pars_fragment>
  3091. #include <emissivemap_pars_fragment>
  3092. #include <envmap_common_pars_fragment>
  3093. #include <envmap_pars_fragment>
  3094. #include <fog_pars_fragment>
  3095. #include <bsdfs>
  3096. #include <lights_pars_begin>
  3097. #include <normal_pars_fragment>
  3098. #include <lights_phong_pars_fragment>
  3099. #include <shadowmap_pars_fragment>
  3100. #include <bumpmap_pars_fragment>
  3101. #include <normalmap_pars_fragment>
  3102. #include <specularmap_pars_fragment>
  3103. #include <logdepthbuf_pars_fragment>
  3104. #include <clipping_planes_pars_fragment>
  3105. void main() {
  3106. vec4 diffuseColor = vec4( diffuse, opacity );
  3107. #include <clipping_planes_fragment>
  3108. ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
  3109. vec3 totalEmissiveRadiance = emissive;
  3110. #include <logdepthbuf_fragment>
  3111. #include <map_fragment>
  3112. #include <color_fragment>
  3113. #include <alphamap_fragment>
  3114. #include <alphatest_fragment>
  3115. #include <alphahash_fragment>
  3116. #include <specularmap_fragment>
  3117. #include <normal_fragment_begin>
  3118. #include <normal_fragment_maps>
  3119. #include <emissivemap_fragment>
  3120. #include <lights_phong_fragment>
  3121. #include <lights_fragment_begin>
  3122. #include <lights_fragment_maps>
  3123. #include <lights_fragment_end>
  3124. #include <aomap_fragment>
  3125. vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
  3126. #include <envmap_fragment>
  3127. #include <opaque_fragment>
  3128. #include <tonemapping_fragment>
  3129. #include <colorspace_fragment>
  3130. #include <fog_fragment>
  3131. #include <premultiplied_alpha_fragment>
  3132. #include <dithering_fragment>
  3133. }`,tc=`#define STANDARD
  3134. varying vec3 vViewPosition;
  3135. #ifdef USE_TRANSMISSION
  3136. varying vec3 vWorldPosition;
  3137. #endif
  3138. #include <common>
  3139. #include <batching_pars_vertex>
  3140. #include <uv_pars_vertex>
  3141. #include <displacementmap_pars_vertex>
  3142. #include <color_pars_vertex>
  3143. #include <fog_pars_vertex>
  3144. #include <normal_pars_vertex>
  3145. #include <morphtarget_pars_vertex>
  3146. #include <skinning_pars_vertex>
  3147. #include <shadowmap_pars_vertex>
  3148. #include <logdepthbuf_pars_vertex>
  3149. #include <clipping_planes_pars_vertex>
  3150. void main() {
  3151. #include <uv_vertex>
  3152. #include <color_vertex>
  3153. #include <morphinstance_vertex>
  3154. #include <morphcolor_vertex>
  3155. #include <batching_vertex>
  3156. #include <beginnormal_vertex>
  3157. #include <morphnormal_vertex>
  3158. #include <skinbase_vertex>
  3159. #include <skinnormal_vertex>
  3160. #include <defaultnormal_vertex>
  3161. #include <normal_vertex>
  3162. #include <begin_vertex>
  3163. #include <morphtarget_vertex>
  3164. #include <skinning_vertex>
  3165. #include <displacementmap_vertex>
  3166. #include <project_vertex>
  3167. #include <logdepthbuf_vertex>
  3168. #include <clipping_planes_vertex>
  3169. vViewPosition = - mvPosition.xyz;
  3170. #include <worldpos_vertex>
  3171. #include <shadowmap_vertex>
  3172. #include <fog_vertex>
  3173. #ifdef USE_TRANSMISSION
  3174. vWorldPosition = worldPosition.xyz;
  3175. #endif
  3176. }`,ec=`#define STANDARD
  3177. #ifdef PHYSICAL
  3178. #define IOR
  3179. #define USE_SPECULAR
  3180. #endif
  3181. uniform vec3 diffuse;
  3182. uniform vec3 emissive;
  3183. uniform float roughness;
  3184. uniform float metalness;
  3185. uniform float opacity;
  3186. #ifdef IOR
  3187. uniform float ior;
  3188. #endif
  3189. #ifdef USE_SPECULAR
  3190. uniform float specularIntensity;
  3191. uniform vec3 specularColor;
  3192. #ifdef USE_SPECULAR_COLORMAP
  3193. uniform sampler2D specularColorMap;
  3194. #endif
  3195. #ifdef USE_SPECULAR_INTENSITYMAP
  3196. uniform sampler2D specularIntensityMap;
  3197. #endif
  3198. #endif
  3199. #ifdef USE_CLEARCOAT
  3200. uniform float clearcoat;
  3201. uniform float clearcoatRoughness;
  3202. #endif
  3203. #ifdef USE_DISPERSION
  3204. uniform float dispersion;
  3205. #endif
  3206. #ifdef USE_IRIDESCENCE
  3207. uniform float iridescence;
  3208. uniform float iridescenceIOR;
  3209. uniform float iridescenceThicknessMinimum;
  3210. uniform float iridescenceThicknessMaximum;
  3211. #endif
  3212. #ifdef USE_SHEEN
  3213. uniform vec3 sheenColor;
  3214. uniform float sheenRoughness;
  3215. #ifdef USE_SHEEN_COLORMAP
  3216. uniform sampler2D sheenColorMap;
  3217. #endif
  3218. #ifdef USE_SHEEN_ROUGHNESSMAP
  3219. uniform sampler2D sheenRoughnessMap;
  3220. #endif
  3221. #endif
  3222. #ifdef USE_ANISOTROPY
  3223. uniform vec2 anisotropyVector;
  3224. #ifdef USE_ANISOTROPYMAP
  3225. uniform sampler2D anisotropyMap;
  3226. #endif
  3227. #endif
  3228. varying vec3 vViewPosition;
  3229. #include <common>
  3230. #include <packing>
  3231. #include <dithering_pars_fragment>
  3232. #include <color_pars_fragment>
  3233. #include <uv_pars_fragment>
  3234. #include <map_pars_fragment>
  3235. #include <alphamap_pars_fragment>
  3236. #include <alphatest_pars_fragment>
  3237. #include <alphahash_pars_fragment>
  3238. #include <aomap_pars_fragment>
  3239. #include <lightmap_pars_fragment>
  3240. #include <emissivemap_pars_fragment>
  3241. #include <iridescence_fragment>
  3242. #include <cube_uv_reflection_fragment>
  3243. #include <envmap_common_pars_fragment>
  3244. #include <envmap_physical_pars_fragment>
  3245. #include <fog_pars_fragment>
  3246. #include <lights_pars_begin>
  3247. #include <normal_pars_fragment>
  3248. #include <lights_physical_pars_fragment>
  3249. #include <transmission_pars_fragment>
  3250. #include <shadowmap_pars_fragment>
  3251. #include <bumpmap_pars_fragment>
  3252. #include <normalmap_pars_fragment>
  3253. #include <clearcoat_pars_fragment>
  3254. #include <iridescence_pars_fragment>
  3255. #include <roughnessmap_pars_fragment>
  3256. #include <metalnessmap_pars_fragment>
  3257. #include <logdepthbuf_pars_fragment>
  3258. #include <clipping_planes_pars_fragment>
  3259. void main() {
  3260. vec4 diffuseColor = vec4( diffuse, opacity );
  3261. #include <clipping_planes_fragment>
  3262. ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
  3263. vec3 totalEmissiveRadiance = emissive;
  3264. #include <logdepthbuf_fragment>
  3265. #include <map_fragment>
  3266. #include <color_fragment>
  3267. #include <alphamap_fragment>
  3268. #include <alphatest_fragment>
  3269. #include <alphahash_fragment>
  3270. #include <roughnessmap_fragment>
  3271. #include <metalnessmap_fragment>
  3272. #include <normal_fragment_begin>
  3273. #include <normal_fragment_maps>
  3274. #include <clearcoat_normal_fragment_begin>
  3275. #include <clearcoat_normal_fragment_maps>
  3276. #include <emissivemap_fragment>
  3277. #include <lights_physical_fragment>
  3278. #include <lights_fragment_begin>
  3279. #include <lights_fragment_maps>
  3280. #include <lights_fragment_end>
  3281. #include <aomap_fragment>
  3282. vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
  3283. vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
  3284. #include <transmission_fragment>
  3285. vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
  3286. #ifdef USE_SHEEN
  3287. float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
  3288. outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;
  3289. #endif
  3290. #ifdef USE_CLEARCOAT
  3291. float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
  3292. vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
  3293. outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
  3294. #endif
  3295. #include <opaque_fragment>
  3296. #include <tonemapping_fragment>
  3297. #include <colorspace_fragment>
  3298. #include <fog_fragment>
  3299. #include <premultiplied_alpha_fragment>
  3300. #include <dithering_fragment>
  3301. }`,nc=`#define TOON
  3302. varying vec3 vViewPosition;
  3303. #include <common>
  3304. #include <batching_pars_vertex>
  3305. #include <uv_pars_vertex>
  3306. #include <displacementmap_pars_vertex>
  3307. #include <color_pars_vertex>
  3308. #include <fog_pars_vertex>
  3309. #include <normal_pars_vertex>
  3310. #include <morphtarget_pars_vertex>
  3311. #include <skinning_pars_vertex>
  3312. #include <shadowmap_pars_vertex>
  3313. #include <logdepthbuf_pars_vertex>
  3314. #include <clipping_planes_pars_vertex>
  3315. void main() {
  3316. #include <uv_vertex>
  3317. #include <color_vertex>
  3318. #include <morphinstance_vertex>
  3319. #include <morphcolor_vertex>
  3320. #include <batching_vertex>
  3321. #include <beginnormal_vertex>
  3322. #include <morphnormal_vertex>
  3323. #include <skinbase_vertex>
  3324. #include <skinnormal_vertex>
  3325. #include <defaultnormal_vertex>
  3326. #include <normal_vertex>
  3327. #include <begin_vertex>
  3328. #include <morphtarget_vertex>
  3329. #include <skinning_vertex>
  3330. #include <displacementmap_vertex>
  3331. #include <project_vertex>
  3332. #include <logdepthbuf_vertex>
  3333. #include <clipping_planes_vertex>
  3334. vViewPosition = - mvPosition.xyz;
  3335. #include <worldpos_vertex>
  3336. #include <shadowmap_vertex>
  3337. #include <fog_vertex>
  3338. }`,ic=`#define TOON
  3339. uniform vec3 diffuse;
  3340. uniform vec3 emissive;
  3341. uniform float opacity;
  3342. #include <common>
  3343. #include <packing>
  3344. #include <dithering_pars_fragment>
  3345. #include <color_pars_fragment>
  3346. #include <uv_pars_fragment>
  3347. #include <map_pars_fragment>
  3348. #include <alphamap_pars_fragment>
  3349. #include <alphatest_pars_fragment>
  3350. #include <alphahash_pars_fragment>
  3351. #include <aomap_pars_fragment>
  3352. #include <lightmap_pars_fragment>
  3353. #include <emissivemap_pars_fragment>
  3354. #include <gradientmap_pars_fragment>
  3355. #include <fog_pars_fragment>
  3356. #include <bsdfs>
  3357. #include <lights_pars_begin>
  3358. #include <normal_pars_fragment>
  3359. #include <lights_toon_pars_fragment>
  3360. #include <shadowmap_pars_fragment>
  3361. #include <bumpmap_pars_fragment>
  3362. #include <normalmap_pars_fragment>
  3363. #include <logdepthbuf_pars_fragment>
  3364. #include <clipping_planes_pars_fragment>
  3365. void main() {
  3366. vec4 diffuseColor = vec4( diffuse, opacity );
  3367. #include <clipping_planes_fragment>
  3368. ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
  3369. vec3 totalEmissiveRadiance = emissive;
  3370. #include <logdepthbuf_fragment>
  3371. #include <map_fragment>
  3372. #include <color_fragment>
  3373. #include <alphamap_fragment>
  3374. #include <alphatest_fragment>
  3375. #include <alphahash_fragment>
  3376. #include <normal_fragment_begin>
  3377. #include <normal_fragment_maps>
  3378. #include <emissivemap_fragment>
  3379. #include <lights_toon_fragment>
  3380. #include <lights_fragment_begin>
  3381. #include <lights_fragment_maps>
  3382. #include <lights_fragment_end>
  3383. #include <aomap_fragment>
  3384. vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
  3385. #include <opaque_fragment>
  3386. #include <tonemapping_fragment>
  3387. #include <colorspace_fragment>
  3388. #include <fog_fragment>
  3389. #include <premultiplied_alpha_fragment>
  3390. #include <dithering_fragment>
  3391. }`,sc=`uniform float size;
  3392. uniform float scale;
  3393. #include <common>
  3394. #include <color_pars_vertex>
  3395. #include <fog_pars_vertex>
  3396. #include <morphtarget_pars_vertex>
  3397. #include <logdepthbuf_pars_vertex>
  3398. #include <clipping_planes_pars_vertex>
  3399. #ifdef USE_POINTS_UV
  3400. varying vec2 vUv;
  3401. uniform mat3 uvTransform;
  3402. #endif
  3403. void main() {
  3404. #ifdef USE_POINTS_UV
  3405. vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
  3406. #endif
  3407. #include <color_vertex>
  3408. #include <morphinstance_vertex>
  3409. #include <morphcolor_vertex>
  3410. #include <begin_vertex>
  3411. #include <morphtarget_vertex>
  3412. #include <project_vertex>
  3413. gl_PointSize = size;
  3414. #ifdef USE_SIZEATTENUATION
  3415. bool isPerspective = isPerspectiveMatrix( projectionMatrix );
  3416. if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
  3417. #endif
  3418. #include <logdepthbuf_vertex>
  3419. #include <clipping_planes_vertex>
  3420. #include <worldpos_vertex>
  3421. #include <fog_vertex>
  3422. }`,rc=`uniform vec3 diffuse;
  3423. uniform float opacity;
  3424. #include <common>
  3425. #include <color_pars_fragment>
  3426. #include <map_particle_pars_fragment>
  3427. #include <alphatest_pars_fragment>
  3428. #include <alphahash_pars_fragment>
  3429. #include <fog_pars_fragment>
  3430. #include <logdepthbuf_pars_fragment>
  3431. #include <clipping_planes_pars_fragment>
  3432. void main() {
  3433. vec4 diffuseColor = vec4( diffuse, opacity );
  3434. #include <clipping_planes_fragment>
  3435. vec3 outgoingLight = vec3( 0.0 );
  3436. #include <logdepthbuf_fragment>
  3437. #include <map_particle_fragment>
  3438. #include <color_fragment>
  3439. #include <alphatest_fragment>
  3440. #include <alphahash_fragment>
  3441. outgoingLight = diffuseColor.rgb;
  3442. #include <opaque_fragment>
  3443. #include <tonemapping_fragment>
  3444. #include <colorspace_fragment>
  3445. #include <fog_fragment>
  3446. #include <premultiplied_alpha_fragment>
  3447. }`,oc=`#include <common>
  3448. #include <batching_pars_vertex>
  3449. #include <fog_pars_vertex>
  3450. #include <morphtarget_pars_vertex>
  3451. #include <skinning_pars_vertex>
  3452. #include <logdepthbuf_pars_vertex>
  3453. #include <shadowmap_pars_vertex>
  3454. void main() {
  3455. #include <batching_vertex>
  3456. #include <beginnormal_vertex>
  3457. #include <morphinstance_vertex>
  3458. #include <morphnormal_vertex>
  3459. #include <skinbase_vertex>
  3460. #include <skinnormal_vertex>
  3461. #include <defaultnormal_vertex>
  3462. #include <begin_vertex>
  3463. #include <morphtarget_vertex>
  3464. #include <skinning_vertex>
  3465. #include <project_vertex>
  3466. #include <logdepthbuf_vertex>
  3467. #include <worldpos_vertex>
  3468. #include <shadowmap_vertex>
  3469. #include <fog_vertex>
  3470. }`,ac=`uniform vec3 color;
  3471. uniform float opacity;
  3472. #include <common>
  3473. #include <packing>
  3474. #include <fog_pars_fragment>
  3475. #include <bsdfs>
  3476. #include <lights_pars_begin>
  3477. #include <logdepthbuf_pars_fragment>
  3478. #include <shadowmap_pars_fragment>
  3479. #include <shadowmask_pars_fragment>
  3480. void main() {
  3481. #include <logdepthbuf_fragment>
  3482. gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
  3483. #include <tonemapping_fragment>
  3484. #include <colorspace_fragment>
  3485. #include <fog_fragment>
  3486. }`,cc=`uniform float rotation;
  3487. uniform vec2 center;
  3488. #include <common>
  3489. #include <uv_pars_vertex>
  3490. #include <fog_pars_vertex>
  3491. #include <logdepthbuf_pars_vertex>
  3492. #include <clipping_planes_pars_vertex>
  3493. void main() {
  3494. #include <uv_vertex>
  3495. vec4 mvPosition = modelViewMatrix[ 3 ];
  3496. vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );
  3497. #ifndef USE_SIZEATTENUATION
  3498. bool isPerspective = isPerspectiveMatrix( projectionMatrix );
  3499. if ( isPerspective ) scale *= - mvPosition.z;
  3500. #endif
  3501. vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;
  3502. vec2 rotatedPosition;
  3503. rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
  3504. rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
  3505. mvPosition.xy += rotatedPosition;
  3506. gl_Position = projectionMatrix * mvPosition;
  3507. #include <logdepthbuf_vertex>
  3508. #include <clipping_planes_vertex>
  3509. #include <fog_vertex>
  3510. }`,lc=`uniform vec3 diffuse;
  3511. uniform float opacity;
  3512. #include <common>
  3513. #include <uv_pars_fragment>
  3514. #include <map_pars_fragment>
  3515. #include <alphamap_pars_fragment>
  3516. #include <alphatest_pars_fragment>
  3517. #include <alphahash_pars_fragment>
  3518. #include <fog_pars_fragment>
  3519. #include <logdepthbuf_pars_fragment>
  3520. #include <clipping_planes_pars_fragment>
  3521. void main() {
  3522. vec4 diffuseColor = vec4( diffuse, opacity );
  3523. #include <clipping_planes_fragment>
  3524. vec3 outgoingLight = vec3( 0.0 );
  3525. #include <logdepthbuf_fragment>
  3526. #include <map_fragment>
  3527. #include <alphamap_fragment>
  3528. #include <alphatest_fragment>
  3529. #include <alphahash_fragment>
  3530. outgoingLight = diffuseColor.rgb;
  3531. #include <opaque_fragment>
  3532. #include <tonemapping_fragment>
  3533. #include <colorspace_fragment>
  3534. #include <fog_fragment>
  3535. }`,N={alphahash_fragment:Pr,alphahash_pars_fragment:Ir,alphamap_fragment:Lr,alphamap_pars_fragment:Dr,alphatest_fragment:Ur,alphatest_pars_fragment:Nr,aomap_fragment:Fr,aomap_pars_fragment:Br,batching_pars_vertex:Or,batching_vertex:zr,begin_vertex:kr,beginnormal_vertex:Vr,bsdfs:Hr,iridescence_fragment:Gr,bumpmap_pars_fragment:Wr,clipping_planes_fragment:Xr,clipping_planes_pars_fragment:qr,clipping_planes_pars_vertex:Yr,clipping_planes_vertex:Zr,color_fragment:Jr,color_pars_fragment:$r,color_pars_vertex:Kr,color_vertex:Qr,common:jr,cube_uv_reflection_fragment:to,defaultnormal_vertex:eo,displacementmap_pars_vertex:no,displacementmap_vertex:io,emissivemap_fragment:so,emissivemap_pars_fragment:ro,colorspace_fragment:oo,colorspace_pars_fragment:ao,envmap_fragment:co,envmap_common_pars_fragment:lo,envmap_pars_fragment:ho,envmap_pars_vertex:uo,envmap_physical_pars_fragment:bo,envmap_vertex:fo,fog_vertex:po,fog_pars_vertex:mo,fog_fragment:go,fog_pars_fragment:_o,gradientmap_pars_fragment:xo,lightmap_pars_fragment:yo,lights_lambert_fragment:vo,lights_lambert_pars_fragment:Mo,lights_pars_begin:So,lights_toon_fragment:wo,lights_toon_pars_fragment:Ao,lights_phong_fragment:To,lights_phong_pars_fragment:Eo,lights_physical_fragment:Co,lights_physical_pars_fragment:Ro,lights_fragment_begin:Po,lights_fragment_maps:Io,lights_fragment_end:Lo,logdepthbuf_fragment:Do,logdepthbuf_pars_fragment:Uo,logdepthbuf_pars_vertex:No,logdepthbuf_vertex:Fo,map_fragment:Bo,map_pars_fragment:Oo,map_particle_fragment:zo,map_particle_pars_fragment:ko,metalnessmap_fragment:Vo,metalnessmap_pars_fragment:Ho,morphinstance_vertex:Go,morphcolor_vertex:Wo,morphnormal_vertex:Xo,morphtarget_pars_vertex:qo,morphtarget_vertex:Yo,normal_fragment_begin:Zo,normal_fragment_maps:Jo,normal_pars_fragment:$o,normal_pars_vertex:Ko,normal_vertex:Qo,normalmap_pars_fragment:jo,clearcoat_normal_fragment_begin:ta,clearcoat_normal_fragment_maps:ea,clearcoat_pars_fragment:na,iridescence_pars_fragment:ia,opaque_fragment:sa,packing:ra,premultiplied_alpha_fragment:oa,project_vertex:aa,dithering_fragment:ca,dithering_pars_fragment:la,roughnessmap_fragment:ha,roughnessmap_pars_fragment:ua,shadowmap_pars_fragment:fa,shadowmap_pars_vertex:da,shadowmap_vertex:pa,shadowmask_pars_fragment:ma,skinbase_vertex:ga,skinning_pars_vertex:_a,skinning_vertex:xa,skinnormal_vertex:ya,specularmap_fragment:va,specularmap_pars_fragment:Ma,tonemapping_fragment:Sa,tonemapping_pars_fragment:ba,transmission_fragment:wa,transmission_pars_fragment:Aa,uv_pars_fragment:Ta,uv_pars_vertex:Ea,uv_vertex:Ca,worldpos_vertex:Ra,background_vert:Pa,background_frag:Ia,backgroundCube_vert:La,backgroundCube_frag:Da,cube_vert:Ua,cube_frag:Na,depth_vert:Fa,depth_frag:Ba,distanceRGBA_vert:Oa,distanceRGBA_frag:za,equirect_vert:ka,equirect_frag:Va,linedashed_vert:Ha,linedashed_frag:Ga,meshbasic_vert:Wa,meshbasic_frag:Xa,meshlambert_vert:qa,meshlambert_frag:Ya,meshmatcap_vert:Za,meshmatcap_frag:Ja,meshnormal_vert:$a,meshnormal_frag:Ka,meshphong_vert:Qa,meshphong_frag:ja,meshphysical_vert:tc,meshphysical_frag:ec,meshtoon_vert:nc,meshtoon_frag:ic,points_vert:sc,points_frag:rc,shadow_vert:oc,shadow_frag:ac,sprite_vert:cc,sprite_frag:lc},I={common:{diffuse:{value:new Q(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new D},alphaMap:{value:null},alphaMapTransform:{value:new D},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new D}},envmap:{envMap:{value:null},envMapRotation:{value:new D},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new D}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new D}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new D},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new D},normalScale:{value:new H(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new D},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new D}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new D}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new D}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Q(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Q(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new D},alphaTest:{value:0},uvTransform:{value:new D}},sprite:{diffuse:{value:new Q(16777215)},opacity:{value:1},center:{value:new H(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new D},alphaMap:{value:null},alphaMapTransform:{value:new D},alphaTest:{value:0}}},fs={basic:{uniforms:ot([I.common,I.specularmap,I.envmap,I.aomap,I.lightmap,I.fog]),vertexShader:N.meshbasic_vert,fragmentShader:N.meshbasic_frag},lambert:{uniforms:ot([I.common,I.specularmap,I.envmap,I.aomap,I.lightmap,I.emissivemap,I.bumpmap,I.normalmap,I.displacementmap,I.fog,I.lights,{emissive:{value:new Q(0)}}]),vertexShader:N.meshlambert_vert,fragmentShader:N.meshlambert_frag},phong:{uniforms:ot([I.common,I.specularmap,I.envmap,I.aomap,I.lightmap,I.emissivemap,I.bumpmap,I.normalmap,I.displacementmap,I.fog,I.lights,{emissive:{value:new Q(0)},specular:{value:new Q(1118481)},shininess:{value:30}}]),vertexShader:N.meshphong_vert,fragmentShader:N.meshphong_frag},standard:{uniforms:ot([I.common,I.envmap,I.aomap,I.lightmap,I.emissivemap,I.bumpmap,I.normalmap,I.displacementmap,I.roughnessmap,I.metalnessmap,I.fog,I.lights,{emissive:{value:new Q(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:N.meshphysical_vert,fragmentShader:N.meshphysical_frag},toon:{uniforms:ot([I.common,I.aomap,I.lightmap,I.emissivemap,I.bumpmap,I.normalmap,I.displacementmap,I.gradientmap,I.fog,I.lights,{emissive:{value:new Q(0)}}]),vertexShader:N.meshtoon_vert,fragmentShader:N.meshtoon_frag},matcap:{uniforms:ot([I.common,I.bumpmap,I.normalmap,I.displacementmap,I.fog,{matcap:{value:null}}]),vertexShader:N.meshmatcap_vert,fragmentShader:N.meshmatcap_frag},points:{uniforms:ot([I.points,I.fog]),vertexShader:N.points_vert,fragmentShader:N.points_frag},dashed:{uniforms:ot([I.common,I.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:N.linedashed_vert,fragmentShader:N.linedashed_frag},depth:{uniforms:ot([I.common,I.displacementmap]),vertexShader:N.depth_vert,fragmentShader:N.depth_frag},normal:{uniforms:ot([I.common,I.bumpmap,I.normalmap,I.displacementmap,{opacity:{value:1}}]),vertexShader:N.meshnormal_vert,fragmentShader:N.meshnormal_frag},sprite:{uniforms:ot([I.sprite,I.fog]),vertexShader:N.sprite_vert,fragmentShader:N.sprite_frag},background:{uniforms:{uvTransform:{value:new D},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:N.background_vert,fragmentShader:N.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new D}},vertexShader:N.backgroundCube_vert,fragmentShader:N.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:N.cube_vert,fragmentShader:N.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:N.equirect_vert,fragmentShader:N.equirect_frag},distanceRGBA:{uniforms:ot([I.common,I.displacementmap,{referencePosition:{value:new M},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:N.distanceRGBA_vert,fragmentShader:N.distanceRGBA_frag},shadow:{uniforms:ot([I.lights,I.fog,{color:{value:new Q(0)},opacity:{value:1}}]),vertexShader:N.shadow_vert,fragmentShader:N.shadow_frag}};fs.physical={uniforms:ot([fs.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new D},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new D},clearcoatNormalScale:{value:new H(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new D},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new D},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new D},sheen:{value:0},sheenColor:{value:new Q(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new D},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new D},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new D},transmissionSamplerSize:{value:new H},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new D},attenuationDistance:{value:0},attenuationColor:{value:new Q(0)},specularColor:{value:new Q(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new D},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new D},anisotropyVector:{value:new H},anisotropyMap:{value:null},anisotropyMapTransform:{value:new D}}]),vertexShader:N.meshphysical_vert,fragmentShader:N.meshphysical_frag};var Vt=(1+Math.sqrt(5))/2,ie=1/Vt,Zc=[new M(-Vt,ie,0),new M(Vt,ie,0),new M(-ie,0,Vt),new M(ie,0,Vt),new M(0,Vt,-ie),new M(0,Vt,ie),new M(-1,1,-1),new M(1,1,-1),new M(-1,1,1),new M(1,1,1)];var Jc=new Float32Array(16),$c=new Float32Array(9),Kc=new Float32Array(4);var Qc={[Fi]:Bi,[Oi]:Hi,[ki]:Gi,[zi]:Vi,[Bi]:Fi,[Hi]:Oi,[Gi]:ki,[Vi]:zi};function Qe(c,t,e){return!c||!e&&c.constructor===t?c:typeof t.BYTES_PER_ELEMENT=="number"?new t(c):Array.prototype.slice.call(c)}function hc(c){return ArrayBuffer.isView(c)&&!(c instanceof DataView)}var ae=class{constructor(t,e,n,i){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=i!==void 0?i:new e.constructor(n),this.sampleValues=e,this.valueSize=n,this.settings=null,this.DefaultSettings_={}}evaluate(t){let e=this.parameterPositions,n=this._cachedIndex,i=e[n],s=e[n-1];n:{t:{let r;e:{i:if(!(t<i)){for(let a=n+2;;){if(i===void 0){if(t<s)break i;return n=e.length,this._cachedIndex=n,this.copySampleValue_(n-1)}if(n===a)break;if(s=i,i=e[++n],t<i)break t}r=e.length;break e}if(!(t>=s)){let a=e[1];t<a&&(n=2,s=a);for(let o=n-2;;){if(s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(n===o)break;if(i=s,s=e[--n-1],t>=s)break t}r=n,n=0;break e}break n}for(;n<r;){let a=n+r>>>1;t<e[a]?r=a:n=a+1}if(i=e[n],s=e[n-1],s===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(i===void 0)return n=e.length,this._cachedIndex=n,this.copySampleValue_(n-1)}this._cachedIndex=n,this.intervalChanged_(n,s,i)}return this.interpolate_(n,s,t,i)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(t){let e=this.resultBuffer,n=this.sampleValues,i=this.valueSize,s=t*i;for(let r=0;r!==i;++r)e[r]=n[s+r];return e}interpolate_(){throw new Error("call to abstract method")}intervalChanged_(){}},jn=class extends ae{constructor(t,e,n,i){super(t,e,n,i),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:qi,endingEnd:qi}}intervalChanged_(t,e,n){let i=this.parameterPositions,s=t-2,r=t+1,a=i[s],o=i[r];if(a===void 0)switch(this.getSettings_().endingStart){case Yi:s=t,a=2*e-n;break;case Zi:s=i.length-2,a=e+i[s]-i[s+1];break;default:s=t,a=n}if(o===void 0)switch(this.getSettings_().endingEnd){case Yi:r=t,o=2*n-e;break;case Zi:r=1,o=n+i[1]-i[0];break;default:r=t-1,o=e}let h=(n-e)*.5,l=this.valueSize;this._weightPrev=h/(e-a),this._weightNext=h/(o-n),this._offsetPrev=s*l,this._offsetNext=r*l}interpolate_(t,e,n,i){let s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=t*a,h=o-a,l=this._offsetPrev,f=this._offsetNext,u=this._weightPrev,d=this._weightNext,p=(n-e)/(i-e),m=p*p,_=m*p,g=-u*_+2*u*m-u*p,x=(1+u)*_+(-1.5-2*u)*m+(-.5+u)*p+1,v=(-1-d)*_+(1.5+d)*m+.5*p,S=d*_-d*m;for(let y=0;y!==a;++y)s[y]=g*r[l+y]+x*r[h+y]+v*r[o+y]+S*r[f+y];return s}},ti=class extends ae{constructor(t,e,n,i){super(t,e,n,i)}interpolate_(t,e,n,i){let s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=t*a,h=o-a,l=(n-e)/(i-e),f=1-l;for(let u=0;u!==a;++u)s[u]=r[h+u]*f+r[o+u]*l;return s}},ei=class extends ae{constructor(t,e,n,i){super(t,e,n,i)}interpolate_(t){return this.copySampleValue_(t-1)}},xt=class{constructor(t,e,n,i){if(t===void 0)throw new Error("THREE.KeyframeTrack: track name is undefined");if(e===void 0||e.length===0)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+t);this.name=t,this.times=Qe(e,this.TimeBufferType),this.values=Qe(n,this.ValueBufferType),this.setInterpolation(i||this.DefaultInterpolation)}static toJSON(t){let e=t.constructor,n;if(e.toJSON!==this.toJSON)n=e.toJSON(t);else{n={name:t.name,times:Qe(t.times,Array),values:Qe(t.values,Array)};let i=t.getInterpolation();i!==t.DefaultInterpolation&&(n.interpolation=i)}return n.type=t.ValueTypeName,n}InterpolantFactoryMethodDiscrete(t){return new ei(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new ti(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new jn(this.times,this.values,this.getValueSize(),t)}setInterpolation(t){let e;switch(t){case tn:e=this.InterpolantFactoryMethodDiscrete;break;case Xn:e=this.InterpolantFactoryMethodLinear;break;case Tn:e=this.InterpolantFactoryMethodSmooth;break}if(e===void 0){let n="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(this.createInterpolant===void 0)if(t!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw new Error(n);return console.warn("THREE.KeyframeTrack:",n),this}return this.createInterpolant=e,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return tn;case this.InterpolantFactoryMethodLinear:return Xn;case this.InterpolantFactoryMethodSmooth:return Tn}}getValueSize(){return this.values.length/this.times.length}shift(t){if(t!==0){let e=this.times;for(let n=0,i=e.length;n!==i;++n)e[n]+=t}return this}scale(t){if(t!==1){let e=this.times;for(let n=0,i=e.length;n!==i;++n)e[n]*=t}return this}trim(t,e){let n=this.times,i=n.length,s=0,r=i-1;for(;s!==i&&n[s]<t;)++s;for(;r!==-1&&n[r]>e;)--r;if(++r,s!==0||r!==i){s>=r&&(r=Math.max(r,1),s=r-1);let a=this.getValueSize();this.times=n.slice(s,r),this.values=this.values.slice(s*a,r*a)}return this}validate(){let t=!0,e=this.getValueSize();e-Math.floor(e)!==0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);let n=this.times,i=this.values,s=n.length;s===0&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let r=null;for(let a=0;a!==s;a++){let o=n[a];if(typeof o=="number"&&isNaN(o)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,a,o),t=!1;break}if(r!==null&&r>o){console.error("THREE.KeyframeTrack: Out of order keys.",this,a,o,r),t=!1;break}r=o}if(i!==void 0&&hc(i))for(let a=0,o=i.length;a!==o;++a){let h=i[a];if(isNaN(h)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,a,h),t=!1;break}}return t}optimize(){let t=this.times.slice(),e=this.values.slice(),n=this.getValueSize(),i=this.getInterpolation()===Tn,s=t.length-1,r=1;for(let a=1;a<s;++a){let o=!1,h=t[a],l=t[a+1];if(h!==l&&(a!==1||h!==t[0]))if(i)o=!0;else{let f=a*n,u=f-n,d=f+n;for(let p=0;p!==n;++p){let m=e[f+p];if(m!==e[u+p]||m!==e[d+p]){o=!0;break}}}if(o){if(a!==r){t[r]=t[a];let f=a*n,u=r*n;for(let d=0;d!==n;++d)e[u+d]=e[f+d]}++r}}if(s>0){t[r]=t[s];for(let a=s*n,o=r*n,h=0;h!==n;++h)e[o+h]=e[a+h];++r}return r!==t.length?(this.times=t.slice(0,r),this.values=e.slice(0,r*n)):(this.times=t,this.values=e),this}clone(){let t=this.times.slice(),e=this.values.slice(),n=this.constructor,i=new n(this.name,t,e);return i.createInterpolant=this.createInterpolant,i}};xt.prototype.TimeBufferType=Float32Array;xt.prototype.ValueBufferType=Float32Array;xt.prototype.DefaultInterpolation=Xn;var Ht=class extends xt{constructor(t,e,n){super(t,e,n)}};Ht.prototype.ValueTypeName="bool";Ht.prototype.ValueBufferType=Array;Ht.prototype.DefaultInterpolation=tn;Ht.prototype.InterpolantFactoryMethodLinear=void 0;Ht.prototype.InterpolantFactoryMethodSmooth=void 0;var ni=class extends xt{};ni.prototype.ValueTypeName="color";var ii=class extends xt{};ii.prototype.ValueTypeName="number";var si=class extends ae{constructor(t,e,n,i){super(t,e,n,i)}interpolate_(t,e,n,i){let s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=(n-e)/(i-e),h=t*a;for(let l=h+a;h!==l;h+=4)Ut.slerpFlat(s,0,r,h-a,r,h,o);return s}},sn=class extends xt{InterpolantFactoryMethodLinear(t){return new si(this.times,this.values,this.getValueSize(),t)}};sn.prototype.ValueTypeName="quaternion";sn.prototype.InterpolantFactoryMethodSmooth=void 0;var Gt=class extends xt{constructor(t,e,n){super(t,e,n)}};Gt.prototype.ValueTypeName="string";Gt.prototype.ValueBufferType=Array;Gt.prototype.DefaultInterpolation=tn;Gt.prototype.InterpolantFactoryMethodLinear=void 0;Gt.prototype.InterpolantFactoryMethodSmooth=void 0;var ri=class extends xt{};ri.prototype.ValueTypeName="vector";var oi=class{constructor(t,e,n){let i=this,s=!1,r=0,a=0,o,h=[];this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=n,this.itemStart=function(l){a++,s===!1&&i.onStart!==void 0&&i.onStart(l,r,a),s=!0},this.itemEnd=function(l){r++,i.onProgress!==void 0&&i.onProgress(l,r,a),r===a&&(s=!1,i.onLoad!==void 0&&i.onLoad())},this.itemError=function(l){i.onError!==void 0&&i.onError(l)},this.resolveURL=function(l){return o?o(l):l},this.setURLModifier=function(l){return o=l,this},this.addHandler=function(l,f){return h.push(l,f),this},this.removeHandler=function(l){let f=h.indexOf(l);return f!==-1&&h.splice(f,2),this},this.getHandler=function(l){for(let f=0,u=h.length;f<u;f+=2){let d=h[f],p=h[f+1];if(d.global&&(d.lastIndex=0),d.test(l))return p}return null}}},uc=new oi,ai=class{constructor(t){this.manager=t!==void 0?t:uc,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(t,e){let n=this;return new Promise(function(i,s){n.load(t,i,e,s)})}parse(){}setCrossOrigin(t){return this.crossOrigin=t,this}setWithCredentials(t){return this.withCredentials=t,this}setPath(t){return this.path=t,this}setResourcePath(t){return this.resourcePath=t,this}setRequestHeader(t){return this.requestHeader=t,this}};ai.DEFAULT_MATERIAL_NAME="__DEFAULT";var ui="\\[\\]\\.:\\/",fc=new RegExp("["+ui+"]","g"),fi="[^"+ui+"]",dc="[^"+ui.replace("\\.","")+"]",pc=/((?:WC+[\/:])*)/.source.replace("WC",fi),mc=/(WCOD+)?/.source.replace("WCOD",dc),gc=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",fi),_c=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",fi),xc=new RegExp("^"+pc+mc+gc+_c+"$"),yc=["material","materials","bones","map"],ci=class{constructor(t,e,n){let i=n||k.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,i)}getValue(t,e){this.bind();let n=this._targetGroup.nCachedObjects_,i=this._bindings[n];i!==void 0&&i.getValue(t,e)}setValue(t,e){let n=this._bindings;for(let i=this._targetGroup.nCachedObjects_,s=n.length;i!==s;++i)n[i].setValue(t,e)}bind(){let t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,n=t.length;e!==n;++e)t[e].bind()}unbind(){let t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,n=t.length;e!==n;++e)t[e].unbind()}},k=class c{constructor(t,e,n){this.path=e,this.parsedPath=n||c.parseTrackName(e),this.node=c.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,n){return t&&t.isAnimationObjectGroup?new c.Composite(t,e,n):new c(t,e,n)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(fc,"")}static parseTrackName(t){let e=xc.exec(t);if(e===null)throw new Error("PropertyBinding: Cannot parse trackName: "+t);let n={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=n.nodeName&&n.nodeName.lastIndexOf(".");if(i!==void 0&&i!==-1){let s=n.nodeName.substring(i+1);yc.indexOf(s)!==-1&&(n.nodeName=n.nodeName.substring(0,i),n.objectName=s)}if(n.propertyName===null||n.propertyName.length===0)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return n}static findNode(t,e){if(e===void 0||e===""||e==="."||e===-1||e===t.name||e===t.uuid)return t;if(t.skeleton){let n=t.skeleton.getBoneByName(e);if(n!==void 0)return n}if(t.children){let n=function(s){for(let r=0;r<s.length;r++){let a=s[r];if(a.name===e||a.uuid===e)return a;let o=n(a.children);if(o)return o}return null},i=n(t.children);if(i)return i}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(t,e){t[e]=this.targetObject[this.propertyName]}_getValue_array(t,e){let n=this.resolvedProperty;for(let i=0,s=n.length;i!==s;++i)t[e++]=n[i]}_getValue_arrayElement(t,e){t[e]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(t,e){this.resolvedProperty.toArray(t,e)}_setValue_direct(t,e){this.targetObject[this.propertyName]=t[e]}_setValue_direct_setNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(t,e){let n=this.resolvedProperty;for(let i=0,s=n.length;i!==s;++i)n[i]=t[e++]}_setValue_array_setNeedsUpdate(t,e){let n=this.resolvedProperty;for(let i=0,s=n.length;i!==s;++i)n[i]=t[e++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(t,e){let n=this.resolvedProperty;for(let i=0,s=n.length;i!==s;++i)n[i]=t[e++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(t,e){this.resolvedProperty[this.propertyIndex]=t[e]}_setValue_arrayElement_setNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(t,e){this.resolvedProperty.fromArray(t,e)}_setValue_fromArray_setNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(t,e){this.bind(),this.getValue(t,e)}_setValue_unbound(t,e){this.bind(),this.setValue(t,e)}bind(){let t=this.node,e=this.parsedPath,n=e.objectName,i=e.propertyName,s=e.propertyIndex;if(t||(t=c.findNode(this.rootNode,e.nodeName),this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t){console.warn("THREE.PropertyBinding: No target node found for track: "+this.path+".");return}if(n){let h=e.objectIndex;switch(n){case"materials":if(!t.material){console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!t.material.materials){console.error("THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);return}t=t.material.materials;break;case"bones":if(!t.skeleton){console.error("THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);return}t=t.skeleton.bones;for(let l=0;l<t.length;l++)if(t[l].name===h){h=l;break}break;case"map":if("map"in t){t=t.map;break}if(!t.material){console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!t.material.map){console.error("THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);return}t=t.material.map;break;default:if(t[n]===void 0){console.error("THREE.PropertyBinding: Can not bind to objectName of node undefined.",this);return}t=t[n]}if(h!==void 0){if(t[h]===void 0){console.error("THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,t);return}t=t[h]}}let r=t[i];if(r===void 0){let h=e.nodeName;console.error("THREE.PropertyBinding: Trying to update property for track: "+h+"."+i+" but it wasn't found.",t);return}let a=this.Versioning.None;this.targetObject=t,t.needsUpdate!==void 0?a=this.Versioning.NeedsUpdate:t.matrixWorldNeedsUpdate!==void 0&&(a=this.Versioning.MatrixWorldNeedsUpdate);let o=this.BindingType.Direct;if(s!==void 0){if(i==="morphTargetInfluences"){if(!t.geometry){console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);return}if(!t.geometry.morphAttributes){console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);return}t.morphTargetDictionary[s]!==void 0&&(s=t.morphTargetDictionary[s])}o=this.BindingType.ArrayElement,this.resolvedProperty=r,this.propertyIndex=s}else r.fromArray!==void 0&&r.toArray!==void 0?(o=this.BindingType.HasFromToArray,this.resolvedProperty=r):Array.isArray(r)?(o=this.BindingType.EntireArray,this.resolvedProperty=r):this.propertyName=i;this.getValue=this.GetterByBindingType[o],this.setValue=this.SetterByBindingTypeAndVersioning[o][a]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}};k.Composite=ci;k.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3};k.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2};k.prototype.GetterByBindingType=[k.prototype._getValue_direct,k.prototype._getValue_array,k.prototype._getValue_arrayElement,k.prototype._getValue_toArray];k.prototype.SetterByBindingTypeAndVersioning=[[k.prototype._setValue_direct,k.prototype._setValue_direct_setNeedsUpdate,k.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[k.prototype._setValue_array,k.prototype._setValue_array_setNeedsUpdate,k.prototype._setValue_array_setMatrixWorldNeedsUpdate],[k.prototype._setValue_arrayElement,k.prototype._setValue_arrayElement_setNeedsUpdate,k.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[k.prototype._setValue_fromArray,k.prototype._setValue_fromArray_setNeedsUpdate,k.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];var jc=new Float32Array(1);var ds=new M,je=new M,at=class{constructor(t=new M,e=new M){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){ds.subVectors(t,this.start),je.subVectors(this.end,this.start);let n=je.dot(je),s=je.dot(ds)/n;return e&&(s=nt(s,0,1)),s}closestPointToPoint(t,e,n){let i=this.closestPointToPointParameter(t,e);return this.delta(n).multiplyScalar(i).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}};typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:rn}}));typeof window<"u"&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=rn);var vs=Math.pow(2,-24),an=Symbol("SKIP_GENERATION");function vc(c){return c.index?c.index.count:c.attributes.position.count}function bt(c){return vc(c)/3}function Mc(c,t=ArrayBuffer){return c>65535?new Uint32Array(new t(4*c)):new Uint16Array(new t(2*c))}function Ms(c,t){if(!c.index){let e=c.attributes.position.count,n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Mc(e,n);c.setIndex(new it(i,1));for(let s=0;s<e;s++)i[s]=s}}function di(c,t){let e=bt(c),n=t||c.drawRange,i=n.start/3,s=(n.start+n.count)/3,r=Math.max(0,i),a=Math.min(e,s)-r;return[{offset:Math.floor(r),count:Math.floor(a)}]}function pi(c,t){if(!c.groups||!c.groups.length)return di(c,t);let e=[],n=new Set,i=t||c.drawRange,s=i.start/3,r=(i.start+i.count)/3;for(let o of c.groups){let h=o.start/3,l=(o.start+o.count)/3;n.add(Math.max(s,h)),n.add(Math.min(r,l))}let a=Array.from(n.values()).sort((o,h)=>o-h);for(let o=0;o<a.length-1;o++){let h=a[o],l=a[o+1];e.push({offset:Math.floor(h),count:Math.floor(l-h)})}return e}function Ss(c,t){let e=bt(c),n=pi(c,t).sort((r,a)=>r.offset-a.offset),i=n[n.length-1];i.count=Math.min(e-i.offset,i.count);let s=0;return n.forEach(({count:r})=>s+=r),e!==s}function cn(c,t,e,n,i){let s=1/0,r=1/0,a=1/0,o=-1/0,h=-1/0,l=-1/0,f=1/0,u=1/0,d=1/0,p=-1/0,m=-1/0,_=-1/0;for(let g=t*6,x=(t+e)*6;g<x;g+=6){let v=c[g+0],S=c[g+1],y=v-S,w=v+S;y<s&&(s=y),w>o&&(o=w),v<f&&(f=v),v>p&&(p=v);let b=c[g+2],A=c[g+3],T=b-A,E=b+A;T<r&&(r=T),E>h&&(h=E),b<u&&(u=b),b>m&&(m=b);let R=c[g+4],C=c[g+5],P=R-C,L=R+C;P<a&&(a=P),L>l&&(l=L),R<d&&(d=R),R>_&&(_=R)}n[0]=s,n[1]=r,n[2]=a,n[3]=o,n[4]=h,n[5]=l,i[0]=f,i[1]=u,i[2]=d,i[3]=p,i[4]=m,i[5]=_}function bs(c,t=null,e=null,n=null){let i=c.attributes.position,s=c.index?c.index.array:null,r=bt(c),a=i.normalized,o;t===null?(o=new Float32Array(r*6),e=0,n=r):(o=t,e=e||0,n=n||r);let h=i.array,l=i.offset||0,f=3;i.isInterleavedBufferAttribute&&(f=i.data.stride);let u=["getX","getY","getZ"];for(let d=e;d<e+n;d++){let p=d*3,m=d*6,_=p+0,g=p+1,x=p+2;s&&(_=s[_],g=s[g],x=s[x]),a||(_=_*f+l,g=g*f+l,x=x*f+l);for(let v=0;v<3;v++){let S,y,w;a?(S=i[u[v]](_),y=i[u[v]](g),w=i[u[v]](x)):(S=h[_+v],y=h[g+v],w=h[x+v]);let b=S;y<b&&(b=y),w<b&&(b=w);let A=S;y>A&&(A=y),w>A&&(A=w);let T=(A-b)/2,E=v*2;o[m+E+0]=b+T,o[m+E+1]=T+(Math.abs(b)+T)*vs}}return o}function B(c,t,e){return e.min.x=t[c],e.min.y=t[c+1],e.min.z=t[c+2],e.max.x=t[c+3],e.max.y=t[c+4],e.max.z=t[c+5],e}function mi(c){let t=-1,e=-1/0;for(let n=0;n<3;n++){let i=c[n+3]-c[n];i>e&&(e=i,t=n)}return t}function gi(c,t){t.set(c)}function _i(c,t,e){let n,i;for(let s=0;s<3;s++){let r=s+3;n=c[s],i=t[s],e[s]=n<i?n:i,n=c[r],i=t[r],e[r]=n>i?n:i}}function Pe(c,t,e){for(let n=0;n<3;n++){let i=t[c+2*n],s=t[c+2*n+1],r=i-s,a=i+s;r<e[n]&&(e[n]=r),a>e[n+3]&&(e[n+3]=a)}}function ce(c){let t=c[3]-c[0],e=c[4]-c[1],n=c[5]-c[2];return 2*(t*e+e*n+n*t)}var Ct=32,bc=(c,t)=>c.candidate-t.candidate,Nt=new Array(Ct).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ln=new Float32Array(6);function Ts(c,t,e,n,i,s){let r=-1,a=0;if(s===0)r=mi(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(s===1)r=mi(c),r!==-1&&(a=wc(e,n,i,r));else if(s===2){let o=ce(c),h=1.25*i,l=n*6,f=(n+i)*6;for(let u=0;u<3;u++){let d=t[u],_=(t[u+3]-d)/Ct;if(i<Ct/4){let g=[...Nt];g.length=i;let x=0;for(let S=l;S<f;S+=6,x++){let y=g[x];y.candidate=e[S+2*u],y.count=0;let{bounds:w,leftCacheBounds:b,rightCacheBounds:A}=y;for(let T=0;T<3;T++)A[T]=1/0,A[T+3]=-1/0,b[T]=1/0,b[T+3]=-1/0,w[T]=1/0,w[T+3]=-1/0;Pe(S,e,w)}g.sort(bc);let v=i;for(let S=0;S<v;S++){let y=g[S];for(;S+1<v&&g[S+1].candidate===y.candidate;)g.splice(S+1,1),v--}for(let S=l;S<f;S+=6){let y=e[S+2*u];for(let w=0;w<v;w++){let b=g[w];y>=b.candidate?Pe(S,e,b.rightCacheBounds):(Pe(S,e,b.leftCacheBounds),b.count++)}}for(let S=0;S<v;S++){let y=g[S],w=y.count,b=i-y.count,A=y.leftCacheBounds,T=y.rightCacheBounds,E=0;w!==0&&(E=ce(A)/o);let R=0;b!==0&&(R=ce(T)/o);let C=1+1.25*(E*w+R*b);C<h&&(r=u,h=C,a=y.candidate)}}else{for(let v=0;v<Ct;v++){let S=Nt[v];S.count=0,S.candidate=d+_+v*_;let y=S.bounds;for(let w=0;w<3;w++)y[w]=1/0,y[w+3]=-1/0}for(let v=l;v<f;v+=6){let w=~~((e[v+2*u]-d)/_);w>=Ct&&(w=Ct-1);let b=Nt[w];b.count++,Pe(v,e,b.bounds)}let g=Nt[Ct-1];gi(g.bounds,g.rightCacheBounds);for(let v=Ct-2;v>=0;v--){let S=Nt[v],y=Nt[v+1];_i(S.bounds,y.rightCacheBounds,S.rightCacheBounds)}let x=0;for(let v=0;v<Ct-1;v++){let S=Nt[v],y=S.count,w=S.bounds,A=Nt[v+1].rightCacheBounds;y!==0&&(x===0?gi(w,ln):_i(w,ln,ln)),x+=y;let T=0,E=0;x!==0&&(T=ce(ln)/o);let R=i-x;R!==0&&(E=ce(A)/o);let C=1+1.25*(T*x+E*R);C<h&&(r=u,h=C,a=S.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:r,pos:a}}function wc(c,t,e,n){let i=0;for(let s=t,r=t+e;s<r;s++)i+=c[s*6+n*2];return i/e}var le=class{constructor(){this.boundingData=new Float32Array(6)}};function Es(c,t,e,n,i,s){let r=n,a=n+i-1,o=s.pos,h=s.axis*2;for(;;){for(;r<=a&&e[r*6+h]<o;)r++;for(;r<=a&&e[a*6+h]>=o;)a--;if(r<a){for(let l=0;l<3;l++){let f=t[r*3+l];t[r*3+l]=t[a*3+l],t[a*3+l]=f}for(let l=0;l<6;l++){let f=e[r*6+l];e[r*6+l]=e[a*6+l],e[a*6+l]=f}r++,a--}else return r}}function Cs(c,t,e,n,i,s){let r=n,a=n+i-1,o=s.pos,h=s.axis*2;for(;;){for(;r<=a&&e[r*6+h]<o;)r++;for(;r<=a&&e[a*6+h]>=o;)a--;if(r<a){let l=c[r];c[r]=c[a],c[a]=l;for(let f=0;f<6;f++){let u=e[r*6+f];e[r*6+f]=e[a*6+f],e[a*6+f]=u}r++,a--}else return r}}function V(c,t){return t[c+15]===65535}function q(c,t){return t[c+6]}function Z(c,t){return t[c+14]}function $(c){return c+8}function K(c,t){return t[c+6]}function hn(c,t){return t[c+7]}var Rs,Ie,un,Ps,Ac=Math.pow(2,32);function fn(c){return"count"in c?1:1+fn(c.left)+fn(c.right)}function Is(c,t,e){return Rs=new Float32Array(e),Ie=new Uint32Array(e),un=new Uint16Array(e),Ps=new Uint8Array(e),xi(c,t)}function xi(c,t){let e=c/4,n=c/2,i="count"in t,s=t.boundingData;for(let r=0;r<6;r++)Rs[e+r]=s[r];if(i)if(t.buffer){let r=t.buffer;Ps.set(new Uint8Array(r),c);for(let a=c,o=c+r.byteLength;a<o;a+=32){let h=a/2;V(h,un)||(Ie[a/4+6]+=e)}return c+r.byteLength}else{let r=t.offset,a=t.count;return Ie[e+6]=r,un[n+14]=a,un[n+15]=65535,c+32}else{let r=t.left,a=t.right,o=t.splitAxis,h;if(h=xi(c+32,r),h/4>Ac)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Ie[e+6]=h/4,h=xi(h,a),Ie[e+7]=o,h}}function Tc(c,t){let e=(c.index?c.index.count:c.attributes.position.count)/3,n=e>2**16,i=n?4:2,s=t?new SharedArrayBuffer(e*i):new ArrayBuffer(e*i),r=n?new Uint32Array(s):new Uint16Array(s);for(let a=0,o=r.length;a<o;a++)r[a]=a;return r}function Ec(c,t,e,n,i){let{maxDepth:s,verbose:r,maxLeafTris:a,strategy:o,onProgress:h,indirect:l}=i,f=c._indirectBuffer,u=c.geometry,d=u.index?u.index.array:null,p=l?Cs:Es,m=bt(u),_=new Float32Array(6),g=!1,x=new le;return cn(t,e,n,x.boundingData,_),S(x,e,n,_),x;function v(y){h&&h(y/m)}function S(y,w,b,A=null,T=0){if(!g&&T>=s&&(g=!0,r&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(u))),b<=a||T>=s)return v(w+b),y.offset=w,y.count=b,y;let E=Ts(y.boundingData,A,t,w,b,o);if(E.axis===-1)return v(w+b),y.offset=w,y.count=b,y;let R=p(f,d,t,w,b,E);if(R===w||R===w+b)v(w+b),y.offset=w,y.count=b;else{y.splitAxis=E.axis;let C=new le,P=w,L=R-w;y.left=C,cn(t,P,L,C.boundingData,_),S(C,P,L,_,T+1);let U=new le,z=R,lt=b-L;y.right=U,cn(t,z,lt,U.boundingData,_),S(U,z,lt,_,T+1)}return y}}function Ls(c,t){let e=c.geometry;t.indirect&&(c._indirectBuffer=Tc(e,t.useSharedArrayBuffer),Ss(e,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),c._indirectBuffer||Ms(e,t);let n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=bs(e),s=t.indirect?di(e,t.range):pi(e,t.range);c._roots=s.map(r=>{let a=Ec(c,i,r.offset,r.count,t),o=fn(a),h=new n(32*o);return Is(0,a,h),h})}var ct=class{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let n=1/0,i=-1/0;for(let s=0,r=t.length;s<r;s++){let o=t[s][e];n=o<n?o:n,i=o>i?o:i}this.min=n,this.max=i}setFromPoints(t,e){let n=1/0,i=-1/0;for(let s=0,r=e.length;s<r;s++){let a=e[s],o=t.dot(a);n=o<n?o:n,i=o>i?o:i}this.min=n,this.max=i}isSeparated(t){return this.min>t.max||t.min>this.max}};ct.prototype.setFromBox=function(){let c=new M;return function(e,n){let i=n.min,s=n.max,r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let h=0;h<=1;h++)for(let l=0;l<=1;l++){c.x=i.x*o+s.x*(1-o),c.y=i.y*h+s.y*(1-h),c.z=i.z*l+s.z*(1-l);let f=e.dot(c);r=Math.min(f,r),a=Math.max(f,a)}this.min=r,this.max=a}}();var El=function(){let c=new ct;return function(e,n){let i=e.points,s=e.satAxes,r=e.satBounds,a=n.points,o=n.satAxes,h=n.satBounds;for(let l=0;l<3;l++){let f=r[l],u=s[l];if(c.setFromPoints(u,a),f.isSeparated(c))return!1}for(let l=0;l<3;l++){let f=h[l],u=o[l];if(c.setFromPoints(u,i),f.isSeparated(c))return!1}}}();var Cc=function(){let c=new M,t=new M,e=new M;return function(i,s,r){let a=i.start,o=c,h=s.start,l=t;e.subVectors(a,h),c.subVectors(i.end,i.start),t.subVectors(s.end,s.start);let f=e.dot(l),u=l.dot(o),d=l.dot(l),p=e.dot(o),_=o.dot(o)*d-u*u,g,x;_!==0?g=(f*u-p*d)/_:g=0,x=(f+g*u)/d,r.x=g,r.y=x}}(),De=function(){let c=new H,t=new M,e=new M;return function(i,s,r,a){Cc(i,s,c);let o=c.x,h=c.y;if(o>=0&&o<=1&&h>=0&&h<=1){i.at(o,r),s.at(h,a);return}else if(o>=0&&o<=1){h<0?s.at(0,a):s.at(1,a),i.closestPointToPoint(a,!0,r);return}else if(h>=0&&h<=1){o<0?i.at(0,r):i.at(1,r),s.closestPointToPoint(r,!0,a);return}else{let l;o<0?l=i.start:l=i.end;let f;h<0?f=s.start:f=s.end;let u=t,d=e;if(i.closestPointToPoint(f,!0,t),s.closestPointToPoint(l,!0,e),u.distanceToSquared(f)<=d.distanceToSquared(l)){r.copy(u),a.copy(f);return}else{r.copy(l),a.copy(d);return}}}}(),Ds=function(){let c=new M,t=new M,e=new oe,n=new at;return function(s,r){let{radius:a,center:o}=s,{a:h,b:l,c:f}=r;if(n.start=h,n.end=l,n.closestPointToPoint(o,!0,c).distanceTo(o)<=a||(n.start=h,n.end=f,n.closestPointToPoint(o,!0,c).distanceTo(o)<=a)||(n.start=l,n.end=f,n.closestPointToPoint(o,!0,c).distanceTo(o)<=a))return!0;let m=r.getPlane(e);if(Math.abs(m.distanceToPoint(o))<=a){let g=m.projectPoint(o,t);if(r.containsPoint(g))return!0}return!1}}();var Rc=1e-15;function yi(c){return Math.abs(c)<Rc}var j=class extends St{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new M),this.satBounds=new Array(4).fill().map(()=>new ct),this.points=[this.a,this.b,this.c],this.sphere=new Re,this.plane=new oe,this.needsUpdate=!0}intersectsSphere(t){return Ds(t,this)}update(){let t=this.a,e=this.b,n=this.c,i=this.points,s=this.satAxes,r=this.satBounds,a=s[0],o=r[0];this.getNormal(a),o.setFromPoints(a,i);let h=s[1],l=r[1];h.subVectors(t,e),l.setFromPoints(h,i);let f=s[2],u=r[2];f.subVectors(e,n),u.setFromPoints(f,i);let d=s[3],p=r[3];d.subVectors(n,t),p.setFromPoints(d,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}};j.prototype.closestPointToSegment=function(){let c=new M,t=new M,e=new at;return function(i,s=null,r=null){let{start:a,end:o}=i,h=this.points,l,f=1/0;for(let u=0;u<3;u++){let d=(u+1)%3;e.start.copy(h[u]),e.end.copy(h[d]),De(e,i,c,t),l=c.distanceToSquared(t),l<f&&(f=l,s&&s.copy(c),r&&r.copy(t))}return this.closestPointToPoint(a,c),l=a.distanceToSquared(c),l<f&&(f=l,s&&s.copy(c),r&&r.copy(a)),this.closestPointToPoint(o,c),l=o.distanceToSquared(c),l<f&&(f=l,s&&s.copy(c),r&&r.copy(o)),Math.sqrt(f)}}();j.prototype.intersectsTriangle=function(){let c=new j,t=new Array(3),e=new Array(3),n=new ct,i=new ct,s=new M,r=new M,a=new M,o=new M,h=new M,l=new at,f=new at,u=new at,d=new M;function p(m,_,g){let x=m.points,v=0,S=-1;for(let y=0;y<3;y++){let{start:w,end:b}=l;w.copy(x[y]),b.copy(x[(y+1)%3]),l.delta(r);let A=yi(_.distanceToPoint(w));if(yi(_.normal.dot(r))&&A){g.copy(l),v=2;break}let T=_.intersectLine(l,d);if(!T&&A&&d.copy(w),(T||A)&&!yi(d.distanceTo(b))){if(v<=1)(v===1?g.start:g.end).copy(d),A&&(S=v);else if(v>=2){(S===1?g.start:g.end).copy(d),v=2;break}if(v++,v===2&&S===-1)break}}return v}return function(_,g=null,x=!1){this.needsUpdate&&this.update(),_.isExtendedTriangle?_.needsUpdate&&_.update():(c.copy(_),c.update(),_=c);let v=this.plane,S=_.plane;if(Math.abs(v.normal.dot(S.normal))>1-1e-10){let y=this.satBounds,w=this.satAxes;e[0]=_.a,e[1]=_.b,e[2]=_.c;for(let T=0;T<4;T++){let E=y[T],R=w[T];if(n.setFromPoints(R,e),E.isSeparated(n))return!1}let b=_.satBounds,A=_.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let T=0;T<4;T++){let E=b[T],R=A[T];if(n.setFromPoints(R,t),E.isSeparated(n))return!1}for(let T=0;T<4;T++){let E=w[T];for(let R=0;R<4;R++){let C=A[R];if(s.crossVectors(E,C),n.setFromPoints(s,t),i.setFromPoints(s,e),n.isSeparated(i))return!1}}return g&&(x||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),g.start.set(0,0,0),g.end.set(0,0,0)),!0}else{let y=p(this,S,f);if(y===1&&_.containsPoint(f.end))return g&&(g.start.copy(f.end),g.end.copy(f.end)),!0;if(y!==2)return!1;let w=p(_,v,u);if(w===1&&this.containsPoint(u.end))return g&&(g.start.copy(u.end),g.end.copy(u.end)),!0;if(w!==2)return!1;if(f.delta(a),u.delta(o),a.dot(o)<0){let P=u.start;u.start=u.end,u.end=P}let b=f.start.dot(a),A=f.end.dot(a),T=u.start.dot(a),E=u.end.dot(a),R=A<T,C=b<E;return b!==E&&T!==A&&R===C?!1:(g&&(h.subVectors(f.start,u.start),h.dot(a)>0?g.start.copy(f.start):g.start.copy(u.start),h.subVectors(f.end,u.end),h.dot(a)<0?g.end.copy(f.end):g.end.copy(u.end)),!0)}}}();j.prototype.distanceToPoint=function(){let c=new M;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}}();j.prototype.distanceToTriangle=function(){let c=new M,t=new M,e=["a","b","c"],n=new at,i=new at;return function(r,a=null,o=null){let h=a||o?n:null;if(this.intersectsTriangle(r,h))return(a||o)&&(a&&h.getCenter(a),o&&h.getCenter(o)),0;let l=1/0;for(let f=0;f<3;f++){let u,d=e[f],p=r[d];this.closestPointToPoint(p,c),u=p.distanceToSquared(c),u<l&&(l=u,a&&a.copy(c),o&&o.copy(p));let m=this[d];r.closestPointToPoint(m,c),u=m.distanceToSquared(c),u<l&&(l=u,a&&a.copy(m),o&&o.copy(c))}for(let f=0;f<3;f++){let u=e[f],d=e[(f+1)%3];n.set(this[u],this[d]);for(let p=0;p<3;p++){let m=e[p],_=e[(p+1)%3];i.set(r[m],r[_]),De(n,i,c,t);let g=c.distanceToSquared(t);g<l&&(l=g,a&&a.copy(c),o&&o.copy(t))}}return Math.sqrt(l)}}();var X=class{constructor(t,e,n){this.isOrientedBox=!0,this.min=new M,this.max=new M,this.matrix=new G,this.invMatrix=new G,this.points=new Array(8).fill().map(()=>new M),this.satAxes=new Array(3).fill().map(()=>new M),this.satBounds=new Array(3).fill().map(()=>new ct),this.alignedSatBounds=new Array(3).fill().map(()=>new ct),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),n&&this.matrix.copy(n)}set(t,e,n){this.min.copy(t),this.max.copy(e),this.matrix.copy(n),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}};X.prototype.update=function(){return function(){let t=this.matrix,e=this.min,n=this.max,i=this.points;for(let h=0;h<=1;h++)for(let l=0;l<=1;l++)for(let f=0;f<=1;f++){let u=1*h|2*l|4*f,d=i[u];d.x=h?n.x:e.x,d.y=l?n.y:e.y,d.z=f?n.z:e.z,d.applyMatrix4(t)}let s=this.satBounds,r=this.satAxes,a=i[0];for(let h=0;h<3;h++){let l=r[h],f=s[h],u=1<<h,d=i[u];l.subVectors(a,d),f.setFromPoints(l,i)}let o=this.alignedSatBounds;o[0].setFromPointsField(i,"x"),o[1].setFromPointsField(i,"y"),o[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}();X.prototype.intersectsBox=function(){let c=new ct;return function(e){this.needsUpdate&&this.update();let n=e.min,i=e.max,s=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(c.min=n.x,c.max=i.x,a[0].isSeparated(c)||(c.min=n.y,c.max=i.y,a[1].isSeparated(c))||(c.min=n.z,c.max=i.z,a[2].isSeparated(c)))return!1;for(let o=0;o<3;o++){let h=r[o],l=s[o];if(c.setFromBox(h,e),l.isSeparated(c))return!1}return!0}}();X.prototype.intersectsTriangle=function(){let c=new j,t=new Array(3),e=new ct,n=new ct,i=new M;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(c.copy(r),c.update(),r=c);let a=this.satBounds,o=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let u=0;u<3;u++){let d=a[u],p=o[u];if(e.setFromPoints(p,t),d.isSeparated(e))return!1}let h=r.satBounds,l=r.satAxes,f=this.points;for(let u=0;u<3;u++){let d=h[u],p=l[u];if(e.setFromPoints(p,f),d.isSeparated(e))return!1}for(let u=0;u<3;u++){let d=o[u];for(let p=0;p<4;p++){let m=l[p];if(i.crossVectors(d,m),e.setFromPoints(i,t),n.setFromPoints(i,f),e.isSeparated(n))return!1}}return!0}}();X.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}();X.prototype.distanceToPoint=function(){let c=new M;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}}();X.prototype.distanceToBox=function(){let c=["x","y","z"],t=new Array(12).fill().map(()=>new at),e=new Array(12).fill().map(()=>new at),n=new M,i=new M;return function(r,a=0,o=null,h=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||h)&&(r.getCenter(i),this.closestPointToPoint(i,n),r.closestPointToPoint(n,i),o&&o.copy(n),h&&h.copy(i)),0;let l=a*a,f=r.min,u=r.max,d=this.points,p=1/0;for(let _=0;_<8;_++){let g=d[_];i.copy(g).clamp(f,u);let x=g.distanceToSquared(i);if(x<p&&(p=x,o&&o.copy(g),h&&h.copy(i),x<l))return Math.sqrt(x)}let m=0;for(let _=0;_<3;_++)for(let g=0;g<=1;g++)for(let x=0;x<=1;x++){let v=(_+1)%3,S=(_+2)%3,y=g<<v|x<<S,w=1<<_|g<<v|x<<S,b=d[y],A=d[w];t[m].set(b,A);let E=c[_],R=c[v],C=c[S],P=e[m],L=P.start,U=P.end;L[E]=f[E],L[R]=g?f[R]:u[R],L[C]=x?f[C]:u[R],U[E]=u[E],U[R]=g?f[R]:u[R],U[C]=x?f[C]:u[R],m++}for(let _=0;_<=1;_++)for(let g=0;g<=1;g++)for(let x=0;x<=1;x++){i.x=_?u.x:f.x,i.y=g?u.y:f.y,i.z=x?u.z:f.z,this.closestPointToPoint(i,n);let v=i.distanceToSquared(n);if(v<p&&(p=v,o&&o.copy(n),h&&h.copy(i),v<l))return Math.sqrt(v)}for(let _=0;_<12;_++){let g=t[_];for(let x=0;x<12;x++){let v=e[x];De(g,v,n,i);let S=n.distanceToSquared(i);if(S<p&&(p=S,o&&o.copy(n),h&&h.copy(i),S<l))return Math.sqrt(S)}}return Math.sqrt(p)}}();var Ft=class{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){let t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}};var vi=class extends Ft{constructor(){super(()=>new j)}},st=new vi;var Mi=class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;let t=[],e=null;this.setBuffer=n=>{e&&t.push(e),e=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}},F=new Mi;var Bt,ue,he=[],pn=new Ft(()=>new W);function Us(c,t,e,n,i,s){Bt=pn.getPrimitive(),ue=pn.getPrimitive(),he.push(Bt,ue),F.setBuffer(c._roots[t]);let r=Si(0,c.geometry,e,n,i,s);F.clearBuffer(),pn.releasePrimitive(Bt),pn.releasePrimitive(ue),he.pop(),he.pop();let a=he.length;return a>0&&(ue=he[a-1],Bt=he[a-2]),r}function Si(c,t,e,n,i=null,s=0,r=0){let{float32Array:a,uint16Array:o,uint32Array:h}=F,l=c*2;if(V(l,o)){let u=q(c,h),d=Z(l,o);return B(c,a,Bt),n(u,d,!1,r,s+c,Bt)}else{let E=function(C){let{uint16Array:P,uint32Array:L}=F,U=C*2;for(;!V(U,P);)C=$(C),U=C*2;return q(C,L)},R=function(C){let{uint16Array:P,uint32Array:L}=F,U=C*2;for(;!V(U,P);)C=K(C,L),U=C*2;return q(C,L)+Z(U,P)},u=$(c),d=K(c,h),p=u,m=d,_,g,x,v;if(i&&(x=Bt,v=ue,B(p,a,x),B(m,a,v),_=i(x),g=i(v),g<_)){p=d,m=u;let C=_;_=g,g=C,x=v}x||(x=Bt,B(p,a,x));let S=V(p*2,o),y=e(x,S,_,r+1,s+p),w;if(y===2){let C=E(p),L=R(p)-C;w=n(C,L,!0,r+1,s+p,x)}else w=y&&Si(p,t,e,n,i,s,r+1);if(w)return!0;v=ue,B(m,a,v);let b=V(m*2,o),A=e(v,b,g,r+1,s+m),T;if(A===2){let C=E(m),L=R(m)-C;T=n(C,L,!0,r+1,s+m,v)}else T=A&&Si(m,t,e,n,i,s,r+1);return!!T}}var Ue=new M,wi=new M;function Ns(c,t,e={},n=0,i=1/0){let s=n*n,r=i*i,a=1/0,o=null;if(c.shapecast({boundsTraverseOrder:l=>(Ue.copy(t).clamp(l.min,l.max),Ue.distanceToSquared(t)),intersectsBounds:(l,f,u)=>u<a&&u<r,intersectsTriangle:(l,f)=>{l.closestPointToPoint(t,Ue);let u=t.distanceToSquared(Ue);return u<a&&(wi.copy(Ue),a=u,o=f),u<s}}),a===1/0)return null;let h=Math.sqrt(a);return e.point?e.point.copy(wi):e.point=wi.clone(),e.distance=h,e.faceIndex=o,e}var Ic=parseInt(rn)>=169,Wt=new M,Xt=new M,qt=new M,mn=new H,gn=new H,_n=new H,Fs=new M,Bs=new M,Os=new M,Ne=new M;function Lc(c,t,e,n,i,s,r,a){let o;if(s===ps?o=c.intersectTriangle(n,e,t,!0,i):o=c.intersectTriangle(t,e,n,s!==ms,i),o===null)return null;let h=c.origin.distanceTo(i);return h<r||h>a?null:{distance:h,point:i.clone()}}function Dc(c,t,e,n,i,s,r,a,o,h,l){Wt.fromBufferAttribute(t,s),Xt.fromBufferAttribute(t,r),qt.fromBufferAttribute(t,a);let f=Lc(c,Wt,Xt,qt,Ne,o,h,l);if(f){let u=new M;St.getBarycoord(Ne,Wt,Xt,qt,u),n&&(mn.fromBufferAttribute(n,s),gn.fromBufferAttribute(n,r),_n.fromBufferAttribute(n,a),f.uv=St.getInterpolation(Ne,Wt,Xt,qt,mn,gn,_n,new H)),i&&(mn.fromBufferAttribute(i,s),gn.fromBufferAttribute(i,r),_n.fromBufferAttribute(i,a),f.uv1=St.getInterpolation(Ne,Wt,Xt,qt,mn,gn,_n,new H)),e&&(Fs.fromBufferAttribute(e,s),Bs.fromBufferAttribute(e,r),Os.fromBufferAttribute(e,a),f.normal=St.getInterpolation(Ne,Wt,Xt,qt,Fs,Bs,Os,new M),f.normal.dot(c.direction)>0&&f.normal.multiplyScalar(-1));let d={a:s,b:r,c:a,normal:new M,materialIndex:0};St.getNormal(Wt,Xt,qt,d.normal),f.face=d,f.faceIndex=s,Ic&&(f.barycoord=u)}return f}function fe(c,t,e,n,i,s,r){let a=n*3,o=a+0,h=a+1,l=a+2,f=c.index;c.index&&(o=f.getX(o),h=f.getX(h),l=f.getX(l));let{position:u,normal:d,uv:p,uv1:m}=c.attributes,_=Dc(e,u,d,p,m,o,h,l,t,s,r);return _?(_.faceIndex=n,i&&i.push(_),_):null}function O(c,t,e,n){let i=c.a,s=c.b,r=c.c,a=t,o=t+1,h=t+2;e&&(a=e.getX(a),o=e.getX(o),h=e.getX(h)),i.x=n.getX(a),i.y=n.getY(a),i.z=n.getZ(a),s.x=n.getX(o),s.y=n.getY(o),s.z=n.getZ(o),r.x=n.getX(h),r.y=n.getY(h),r.z=n.getZ(h)}function zs(c,t,e,n,i,s,r,a){let{geometry:o,_indirectBuffer:h}=c;for(let l=n,f=n+i;l<f;l++)fe(o,t,e,l,s,r,a)}function ks(c,t,e,n,i,s,r){let{geometry:a,_indirectBuffer:o}=c,h=1/0,l=null;for(let f=n,u=n+i;f<u;f++){let d;d=fe(a,t,e,f,null,s,r),d&&d.distance<h&&(l=d,h=d.distance)}return l}function Vs(c,t,e,n,i,s,r){let{geometry:a}=e,{index:o}=a,h=a.attributes.position;for(let l=c,f=t+c;l<f;l++){let u;if(u=l,O(r,u*3,o,h),r.needsUpdate=!0,n(r,u,i,s))return!0}return!1}function Hs(c,t=null){t&&Array.isArray(t)&&(t=new Set(t));let e=c.geometry,n=e.index?e.index.array:null,i=e.attributes.position,s,r,a,o,h=0,l=c._roots;for(let u=0,d=l.length;u<d;u++)s=l[u],r=new Uint32Array(s),a=new Uint16Array(s),o=new Float32Array(s),f(0,h),h+=s.byteLength;function f(u,d,p=!1){let m=u*2;if(a[m+15]===65535){let g=r[u+6],x=a[m+14],v=1/0,S=1/0,y=1/0,w=-1/0,b=-1/0,A=-1/0;for(let T=3*g,E=3*(g+x);T<E;T++){let R=n[T],C=i.getX(R),P=i.getY(R),L=i.getZ(R);C<v&&(v=C),C>w&&(w=C),P<S&&(S=P),P>b&&(b=P),L<y&&(y=L),L>A&&(A=L)}return o[u+0]!==v||o[u+1]!==S||o[u+2]!==y||o[u+3]!==w||o[u+4]!==b||o[u+5]!==A?(o[u+0]=v,o[u+1]=S,o[u+2]=y,o[u+3]=w,o[u+4]=b,o[u+5]=A,!0):!1}else{let g=u+8,x=r[u+6],v=g+d,S=x+d,y=p,w=!1,b=!1;t?y||(w=t.has(v),b=t.has(S),y=!w&&!b):(w=!0,b=!0);let A=y||w,T=y||b,E=!1;A&&(E=f(g,d,y));let R=!1;T&&(R=f(x,d,y));let C=E||R;if(C)for(let P=0;P<3;P++){let L=g+P,U=x+P,z=o[L],lt=o[L+3],vt=o[U],Mt=o[U+3];o[u+P]=z<vt?z:vt,o[u+P+3]=lt>Mt?lt:Mt}return C}}}function dt(c,t,e,n,i){let s,r,a,o,h,l,f=1/e.direction.x,u=1/e.direction.y,d=1/e.direction.z,p=e.origin.x,m=e.origin.y,_=e.origin.z,g=t[c],x=t[c+3],v=t[c+1],S=t[c+3+1],y=t[c+2],w=t[c+3+2];return f>=0?(s=(g-p)*f,r=(x-p)*f):(s=(x-p)*f,r=(g-p)*f),u>=0?(a=(v-m)*u,o=(S-m)*u):(a=(S-m)*u,o=(v-m)*u),s>o||a>r||((a>s||isNaN(s))&&(s=a),(o<r||isNaN(r))&&(r=o),d>=0?(h=(y-_)*d,l=(w-_)*d):(h=(w-_)*d,l=(y-_)*d),s>l||h>r)?!1:((h>s||s!==s)&&(s=h),(l<r||r!==r)&&(r=l),s<=i&&r>=n)}function Gs(c,t,e,n,i,s,r,a){let{geometry:o,_indirectBuffer:h}=c;for(let l=n,f=n+i;l<f;l++){let u=h?h[l]:l;fe(o,t,e,u,s,r,a)}}function Ws(c,t,e,n,i,s,r){let{geometry:a,_indirectBuffer:o}=c,h=1/0,l=null;for(let f=n,u=n+i;f<u;f++){let d;d=fe(a,t,e,o?o[f]:f,null,s,r),d&&d.distance<h&&(l=d,h=d.distance)}return l}function Xs(c,t,e,n,i,s,r){let{geometry:a}=e,{index:o}=a,h=a.attributes.position;for(let l=c,f=t+c;l<f;l++){let u;if(u=e.resolveTriangleIndex(l),O(r,u*3,o,h),r.needsUpdate=!0,n(r,u,i,s))return!0}return!1}function qs(c,t,e,n,i,s,r){F.setBuffer(c._roots[t]),Ai(0,c,e,n,i,s,r),F.clearBuffer()}function Ai(c,t,e,n,i,s,r){let{float32Array:a,uint16Array:o,uint32Array:h}=F,l=c*2;if(V(l,o)){let u=q(c,h),d=Z(l,o);zs(t,e,n,u,d,i,s,r)}else{let u=$(c);dt(u,a,n,s,r)&&Ai(u,t,e,n,i,s,r);let d=K(c,h);dt(d,a,n,s,r)&&Ai(d,t,e,n,i,s,r)}}var Uc=["x","y","z"];function Ys(c,t,e,n,i,s){F.setBuffer(c._roots[t]);let r=Ti(0,c,e,n,i,s);return F.clearBuffer(),r}function Ti(c,t,e,n,i,s){let{float32Array:r,uint16Array:a,uint32Array:o}=F,h=c*2;if(V(h,a)){let f=q(c,o),u=Z(h,a);return ks(t,e,n,f,u,i,s)}else{let f=hn(c,o),u=Uc[f],p=n.direction[u]>=0,m,_;p?(m=$(c),_=K(c,o)):(m=K(c,o),_=$(c));let x=dt(m,r,n,i,s)?Ti(m,t,e,n,i,s):null;if(x){let y=x.point[u];if(p?y<=r[_+f]:y>=r[_+f+3])return x}let S=dt(_,r,n,i,s)?Ti(_,t,e,n,i,s):null;return x&&S?x.distance<=S.distance?x:S:x||S||null}}var xn=new W,de=new j,pe=new j,Fe=new G,Zs=new X,yn=new X;function Js(c,t,e,n){F.setBuffer(c._roots[t]);let i=Ei(0,c,e,n);return F.clearBuffer(),i}function Ei(c,t,e,n,i=null){let{float32Array:s,uint16Array:r,uint32Array:a}=F,o=c*2;if(i===null&&(e.boundingBox||e.computeBoundingBox(),Zs.set(e.boundingBox.min,e.boundingBox.max,n),i=Zs),V(o,r)){let l=t.geometry,f=l.index,u=l.attributes.position,d=e.index,p=e.attributes.position,m=q(c,a),_=Z(o,r);if(Fe.copy(n).invert(),e.boundsTree)return B(c,s,yn),yn.matrix.copy(Fe),yn.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:x=>yn.intersectsBox(x),intersectsTriangle:x=>{x.a.applyMatrix4(n),x.b.applyMatrix4(n),x.c.applyMatrix4(n),x.needsUpdate=!0;for(let v=m*3,S=(_+m)*3;v<S;v+=3)if(O(pe,v,f,u),pe.needsUpdate=!0,x.intersectsTriangle(pe))return!0;return!1}});for(let g=m*3,x=(_+m)*3;g<x;g+=3){O(de,g,f,u),de.a.applyMatrix4(Fe),de.b.applyMatrix4(Fe),de.c.applyMatrix4(Fe),de.needsUpdate=!0;for(let v=0,S=d.count;v<S;v+=3)if(O(pe,v,d,p),pe.needsUpdate=!0,de.intersectsTriangle(pe))return!0}}else{let l=c+8,f=a[c+6];return B(l,s,xn),!!(i.intersectsBox(xn)&&Ei(l,t,e,n,i)||(B(f,s,xn),i.intersectsBox(xn)&&Ei(f,t,e,n,i)))}}var vn=new G,Ci=new X,Be=new X,Nc=new M,Fc=new M,Bc=new M,Oc=new M;function $s(c,t,e,n={},i={},s=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Ci.set(t.boundingBox.min,t.boundingBox.max,e),Ci.needsUpdate=!0;let a=c.geometry,o=a.attributes.position,h=a.index,l=t.attributes.position,f=t.index,u=st.getPrimitive(),d=st.getPrimitive(),p=Nc,m=Fc,_=null,g=null;i&&(_=Bc,g=Oc);let x=1/0,v=null,S=null;return vn.copy(e).invert(),Be.matrix.copy(vn),c.shapecast({boundsTraverseOrder:y=>Ci.distanceToBox(y),intersectsBounds:(y,w,b)=>b<x&&b<r?(w&&(Be.min.copy(y.min),Be.max.copy(y.max),Be.needsUpdate=!0),!0):!1,intersectsRange:(y,w)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:A=>Be.distanceToBox(A),intersectsBounds:(A,T,E)=>E<x&&E<r,intersectsRange:(A,T)=>{for(let E=A,R=A+T;E<R;E++){O(d,3*E,f,l),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let C=y,P=y+w;C<P;C++){O(u,3*C,h,o),u.needsUpdate=!0;let L=u.distanceToTriangle(d,p,_);if(L<x&&(m.copy(p),g&&g.copy(_),x=L,v=C,S=E),L<s)return!0}}}});{let b=bt(t);for(let A=0,T=b;A<T;A++){O(d,3*A,f,l),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=y,R=y+w;E<R;E++){O(u,3*E,h,o),u.needsUpdate=!0;let C=u.distanceToTriangle(d,p,_);if(C<x&&(m.copy(p),g&&g.copy(_),x=C,v=E,S=A),C<s)return!0}}}}}),st.releasePrimitive(u),st.releasePrimitive(d),x===1/0?null:(n.point?n.point.copy(m):n.point=m.clone(),n.distance=x,n.faceIndex=v,i&&(i.point?i.point.copy(g):i.point=g.clone(),i.point.applyMatrix4(vn),m.applyMatrix4(vn),i.distance=m.sub(i.point).length(),i.faceIndex=S),n)}function Ks(c,t=null){t&&Array.isArray(t)&&(t=new Set(t));let e=c.geometry,n=e.index?e.index.array:null,i=e.attributes.position,s,r,a,o,h=0,l=c._roots;for(let u=0,d=l.length;u<d;u++)s=l[u],r=new Uint32Array(s),a=new Uint16Array(s),o=new Float32Array(s),f(0,h),h+=s.byteLength;function f(u,d,p=!1){let m=u*2;if(a[m+15]===65535){let g=r[u+6],x=a[m+14],v=1/0,S=1/0,y=1/0,w=-1/0,b=-1/0,A=-1/0;for(let T=g,E=g+x;T<E;T++){let R=3*c.resolveTriangleIndex(T);for(let C=0;C<3;C++){let P=R+C;P=n?n[P]:P;let L=i.getX(P),U=i.getY(P),z=i.getZ(P);L<v&&(v=L),L>w&&(w=L),U<S&&(S=U),U>b&&(b=U),z<y&&(y=z),z>A&&(A=z)}}return o[u+0]!==v||o[u+1]!==S||o[u+2]!==y||o[u+3]!==w||o[u+4]!==b||o[u+5]!==A?(o[u+0]=v,o[u+1]=S,o[u+2]=y,o[u+3]=w,o[u+4]=b,o[u+5]=A,!0):!1}else{let g=u+8,x=r[u+6],v=g+d,S=x+d,y=p,w=!1,b=!1;t?y||(w=t.has(v),b=t.has(S),y=!w&&!b):(w=!0,b=!0);let A=y||w,T=y||b,E=!1;A&&(E=f(g,d,y));let R=!1;T&&(R=f(x,d,y));let C=E||R;if(C)for(let P=0;P<3;P++){let L=g+P,U=x+P,z=o[L],lt=o[L+3],vt=o[U],Mt=o[U+3];o[u+P]=z<vt?z:vt,o[u+P+3]=lt>Mt?lt:Mt}return C}}}function Qs(c,t,e,n,i,s,r){F.setBuffer(c._roots[t]),Ri(0,c,e,n,i,s,r),F.clearBuffer()}function Ri(c,t,e,n,i,s,r){let{float32Array:a,uint16Array:o,uint32Array:h}=F,l=c*2;if(V(l,o)){let u=q(c,h),d=Z(l,o);Gs(t,e,n,u,d,i,s,r)}else{let u=$(c);dt(u,a,n,s,r)&&Ri(u,t,e,n,i,s,r);let d=K(c,h);dt(d,a,n,s,r)&&Ri(d,t,e,n,i,s,r)}}var zc=["x","y","z"];function js(c,t,e,n,i,s){F.setBuffer(c._roots[t]);let r=Pi(0,c,e,n,i,s);return F.clearBuffer(),r}function Pi(c,t,e,n,i,s){let{float32Array:r,uint16Array:a,uint32Array:o}=F,h=c*2;if(V(h,a)){let f=q(c,o),u=Z(h,a);return Ws(t,e,n,f,u,i,s)}else{let f=hn(c,o),u=zc[f],p=n.direction[u]>=0,m,_;p?(m=$(c),_=K(c,o)):(m=K(c,o),_=$(c));let x=dt(m,r,n,i,s)?Pi(m,t,e,n,i,s):null;if(x){let y=x.point[u];if(p?y<=r[_+f]:y>=r[_+f+3])return x}let S=dt(_,r,n,i,s)?Pi(_,t,e,n,i,s):null;return x&&S?x.distance<=S.distance?x:S:x||S||null}}var Mn=new W,me=new j,ge=new j,Oe=new G,tr=new X,Sn=new X;function er(c,t,e,n){F.setBuffer(c._roots[t]);let i=Ii(0,c,e,n);return F.clearBuffer(),i}function Ii(c,t,e,n,i=null){let{float32Array:s,uint16Array:r,uint32Array:a}=F,o=c*2;if(i===null&&(e.boundingBox||e.computeBoundingBox(),tr.set(e.boundingBox.min,e.boundingBox.max,n),i=tr),V(o,r)){let l=t.geometry,f=l.index,u=l.attributes.position,d=e.index,p=e.attributes.position,m=q(c,a),_=Z(o,r);if(Oe.copy(n).invert(),e.boundsTree)return B(c,s,Sn),Sn.matrix.copy(Oe),Sn.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:x=>Sn.intersectsBox(x),intersectsTriangle:x=>{x.a.applyMatrix4(n),x.b.applyMatrix4(n),x.c.applyMatrix4(n),x.needsUpdate=!0;for(let v=m,S=_+m;v<S;v++)if(O(ge,3*t.resolveTriangleIndex(v),f,u),ge.needsUpdate=!0,x.intersectsTriangle(ge))return!0;return!1}});for(let g=m,x=_+m;g<x;g++){let v=t.resolveTriangleIndex(g);O(me,3*v,f,u),me.a.applyMatrix4(Oe),me.b.applyMatrix4(Oe),me.c.applyMatrix4(Oe),me.needsUpdate=!0;for(let S=0,y=d.count;S<y;S+=3)if(O(ge,S,d,p),ge.needsUpdate=!0,me.intersectsTriangle(ge))return!0}}else{let l=c+8,f=a[c+6];return B(l,s,Mn),!!(i.intersectsBox(Mn)&&Ii(l,t,e,n,i)||(B(f,s,Mn),i.intersectsBox(Mn)&&Ii(f,t,e,n,i)))}}var bn=new G,Li=new X,ze=new X,kc=new M,Vc=new M,Hc=new M,Gc=new M;function nr(c,t,e,n={},i={},s=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Li.set(t.boundingBox.min,t.boundingBox.max,e),Li.needsUpdate=!0;let a=c.geometry,o=a.attributes.position,h=a.index,l=t.attributes.position,f=t.index,u=st.getPrimitive(),d=st.getPrimitive(),p=kc,m=Vc,_=null,g=null;i&&(_=Hc,g=Gc);let x=1/0,v=null,S=null;return bn.copy(e).invert(),ze.matrix.copy(bn),c.shapecast({boundsTraverseOrder:y=>Li.distanceToBox(y),intersectsBounds:(y,w,b)=>b<x&&b<r?(w&&(ze.min.copy(y.min),ze.max.copy(y.max),ze.needsUpdate=!0),!0):!1,intersectsRange:(y,w)=>{if(t.boundsTree){let b=t.boundsTree;return b.shapecast({boundsTraverseOrder:A=>ze.distanceToBox(A),intersectsBounds:(A,T,E)=>E<x&&E<r,intersectsRange:(A,T)=>{for(let E=A,R=A+T;E<R;E++){let C=b.resolveTriangleIndex(E);O(d,3*C,f,l),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let P=y,L=y+w;P<L;P++){let U=c.resolveTriangleIndex(P);O(u,3*U,h,o),u.needsUpdate=!0;let z=u.distanceToTriangle(d,p,_);if(z<x&&(m.copy(p),g&&g.copy(_),x=z,v=P,S=E),z<s)return!0}}}})}else{let b=bt(t);for(let A=0,T=b;A<T;A++){O(d,3*A,f,l),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=y,R=y+w;E<R;E++){let C=c.resolveTriangleIndex(E);O(u,3*C,h,o),u.needsUpdate=!0;let P=u.distanceToTriangle(d,p,_);if(P<x&&(m.copy(p),g&&g.copy(_),x=P,v=E,S=A),P<s)return!0}}}}}),st.releasePrimitive(u),st.releasePrimitive(d),x===1/0?null:(n.point?n.point.copy(m):n.point=m.clone(),n.distance=x,n.faceIndex=v,i&&(i.point?i.point.copy(g):i.point=g.clone(),i.point.applyMatrix4(bn),m.applyMatrix4(bn),i.distance=m.sub(i.point).length(),i.faceIndex=S),n)}function ir(){return typeof SharedArrayBuffer<"u"}var ke=new F.constructor,wn=new F.constructor,Ot=new Ft(()=>new W),_e=new W,xe=new W,Di=new W,Ui=new W,Ni=!1;function sr(c,t,e,n){if(Ni)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Ni=!0;let i=c._roots,s=t._roots,r,a=0,o=0,h=new G().copy(e).invert();for(let l=0,f=i.length;l<f;l++){ke.setBuffer(i[l]),o=0;let u=Ot.getPrimitive();B(0,ke.float32Array,u),u.applyMatrix4(h);for(let d=0,p=s.length;d<p&&(wn.setBuffer(s[d]),r=yt(0,0,e,h,n,a,o,0,0,u),wn.clearBuffer(),o+=s[d].length,!r);d++);if(Ot.releasePrimitive(u),ke.clearBuffer(),a+=i[l].length,r)break}return Ni=!1,r}function yt(c,t,e,n,i,s=0,r=0,a=0,o=0,h=null,l=!1){let f,u;l?(f=wn,u=ke):(f=ke,u=wn);let d=f.float32Array,p=f.uint32Array,m=f.uint16Array,_=u.float32Array,g=u.uint32Array,x=u.uint16Array,v=c*2,S=t*2,y=V(v,m),w=V(S,x),b=!1;if(w&&y)l?b=i(q(t,g),Z(t*2,x),q(c,p),Z(c*2,m),o,r+t,a,s+c):b=i(q(c,p),Z(c*2,m),q(t,g),Z(t*2,x),a,s+c,o,r+t);else if(w){let A=Ot.getPrimitive();B(t,_,A),A.applyMatrix4(e);let T=$(c),E=K(c,p);B(T,d,_e),B(E,d,xe);let R=A.intersectsBox(_e),C=A.intersectsBox(xe);b=R&&yt(t,T,n,e,i,r,s,o,a+1,A,!l)||C&&yt(t,E,n,e,i,r,s,o,a+1,A,!l),Ot.releasePrimitive(A)}else{let A=$(t),T=K(t,g);B(A,_,Di),B(T,_,Ui);let E=h.intersectsBox(Di),R=h.intersectsBox(Ui);if(E&&R)b=yt(c,A,e,n,i,s,r,a,o+1,h,l)||yt(c,T,e,n,i,s,r,a,o+1,h,l);else if(E)if(y)b=yt(c,A,e,n,i,s,r,a,o+1,h,l);else{let C=Ot.getPrimitive();C.copy(Di).applyMatrix4(e);let P=$(c),L=K(c,p);B(P,d,_e),B(L,d,xe);let U=C.intersectsBox(_e),z=C.intersectsBox(xe);b=U&&yt(A,P,n,e,i,r,s,o,a+1,C,!l)||z&&yt(A,L,n,e,i,r,s,o,a+1,C,!l),Ot.releasePrimitive(C)}else if(R)if(y)b=yt(c,T,e,n,i,s,r,a,o+1,h,l);else{let C=Ot.getPrimitive();C.copy(Ui).applyMatrix4(e);let P=$(c),L=K(c,p);B(P,d,_e),B(L,d,xe);let U=C.intersectsBox(_e),z=C.intersectsBox(xe);b=U&&yt(T,P,n,e,i,r,s,o,a+1,C,!l)||z&&yt(T,L,n,e,i,r,s,o,a+1,C,!l),Ot.releasePrimitive(C)}}return b}var An=new X,rr=new W,Wc={strategy:0,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null},ye=class c{static serialize(t,e={}){e={cloneBuffers:!0,...e};let n=t.geometry,i=t._roots,s=t._indirectBuffer,r=n.getIndex(),a;return e.cloneBuffers?a={roots:i.map(o=>o.slice()),index:r?r.array.slice():null,indirectBuffer:s?s.slice():null}:a={roots:i,index:r?r.array:null,indirectBuffer:s},a}static deserialize(t,e,n={}){n={setIndex:!0,indirect:!!t.indirectBuffer,...n};let{index:i,roots:s,indirectBuffer:r}=t,a=new c(e,{...n,[an]:!0});if(a._roots=s,a._indirectBuffer=r||null,n.setIndex){let o=e.getIndex();if(o===null){let h=new it(t.index,1,!1);e.setIndex(h)}else o.array!==i&&(o.array.set(i),o.needsUpdate=!0)}return a}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({...Wc,[an]:!1},e),e.useSharedArrayBuffer&&!ir())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[an]||(Ls(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new W))),this.resolveTriangleIndex=e.indirect?n=>this._indirectBuffer[n]:n=>n}refit(t=null){return(this.indirect?Ks:Hs)(this,t)}traverse(t,e=0){let n=this._roots[e],i=new Uint32Array(n),s=new Uint16Array(n);r(0);function r(a,o=0){let h=a*2,l=s[h+15]===65535;if(l){let f=i[a+6],u=s[h+14];t(o,l,new Float32Array(n,a*4,6),f,u)}else{let f=a+32/4,u=i[a+6],d=i[a+7];t(o,l,new Float32Array(n,a*4,6),d)||(r(f,o+1),r(u,o+1))}}}raycast(t,e=li,n=0,i=1/0){let s=this._roots,r=this.geometry,a=[],o=e.isMaterial,h=Array.isArray(e),l=r.groups,f=o?e.side:e,u=this.indirect?Qs:qs;for(let d=0,p=s.length;d<p;d++){let m=h?e[l[d].materialIndex].side:f,_=a.length;if(u(this,d,m,t,a,n,i),h){let g=l[d].materialIndex;for(let x=_,v=a.length;x<v;x++)a[x].face.materialIndex=g}}return a}raycastFirst(t,e=li,n=0,i=1/0){let s=this._roots,r=this.geometry,a=e.isMaterial,o=Array.isArray(e),h=null,l=r.groups,f=a?e.side:e,u=this.indirect?js:Ys;for(let d=0,p=s.length;d<p;d++){let m=o?e[l[d].materialIndex].side:f,_=u(this,d,m,t,n,i);_!=null&&(h==null||_.distance<h.distance)&&(h=_,o&&(_.face.materialIndex=l[d].materialIndex))}return h}intersectsGeometry(t,e){let n=!1,i=this._roots,s=this.indirect?er:Js;for(let r=0,a=i.length;r<a&&(n=s(this,r,t,e),!n);r++);return n}shapecast(t){let e=st.getPrimitive(),n=this.indirect?Xs:Vs,{boundsTraverseOrder:i,intersectsBounds:s,intersectsRange:r,intersectsTriangle:a}=t;if(r&&a){let f=r;r=(u,d,p,m,_)=>f(u,d,p,m,_)?!0:n(u,d,this,a,p,m,e)}else r||(a?r=(f,u,d,p)=>n(f,u,this,a,d,p,e):r=(f,u,d)=>d);let o=!1,h=0,l=this._roots;for(let f=0,u=l.length;f<u;f++){let d=l[f];if(o=Us(this,f,s,r,i,h),o)break;h+=d.byteLength}return st.releasePrimitive(e),o}bvhcast(t,e,n){let{intersectsRanges:i,intersectsTriangles:s}=n,r=st.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,h=this.indirect?p=>{let m=this.resolveTriangleIndex(p);O(r,m*3,a,o)}:p=>{O(r,p*3,a,o)},l=st.getPrimitive(),f=t.geometry.index,u=t.geometry.attributes.position,d=t.indirect?p=>{let m=t.resolveTriangleIndex(p);O(l,m*3,f,u)}:p=>{O(l,p*3,f,u)};if(s){let p=(m,_,g,x,v,S,y,w)=>{for(let b=g,A=g+x;b<A;b++){d(b),l.a.applyMatrix4(e),l.b.applyMatrix4(e),l.c.applyMatrix4(e),l.needsUpdate=!0;for(let T=m,E=m+_;T<E;T++)if(h(T),r.needsUpdate=!0,s(r,l,T,b,v,S,y,w))return!0}return!1};if(i){let m=i;i=function(_,g,x,v,S,y,w,b){return m(_,g,x,v,S,y,w,b)?!0:p(_,g,x,v,S,y,w,b)}}else i=p}return sr(this,t,e,i)}intersectsBox(t,e){return An.set(t.min,t.max,e),An.needsUpdate=!0,this.shapecast({intersectsBounds:n=>An.intersectsBox(n),intersectsTriangle:n=>An.intersectsTriangle(n)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,n={},i={},s=0,r=1/0){return(this.indirect?nr:$s)(this,t,e,n,i,s,r)}closestPointToPoint(t,e={},n=0,i=1/0){return Ns(this,t,e,n,i)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(n=>{B(0,new Float32Array(n),rr),t.union(rr)}),t}};var or=`
  3536. // A stack of uint32 indices can can store the indices for
  3537. // a perfectly balanced tree with a depth up to 31. Lower stack
  3538. // depth gets higher performance.
  3539. //
  3540. // However not all trees are balanced. Best value to set this to
  3541. // is the trees max depth.
  3542. #ifndef BVH_STACK_DEPTH
  3543. #define BVH_STACK_DEPTH 60
  3544. #endif
  3545. #ifndef INFINITY
  3546. #define INFINITY 1e20
  3547. #endif
  3548. // Utilities
  3549. uvec4 uTexelFetch1D( usampler2D tex, uint index ) {
  3550. uint width = uint( textureSize( tex, 0 ).x );
  3551. uvec2 uv;
  3552. uv.x = index % width;
  3553. uv.y = index / width;
  3554. return texelFetch( tex, ivec2( uv ), 0 );
  3555. }
  3556. ivec4 iTexelFetch1D( isampler2D tex, uint index ) {
  3557. uint width = uint( textureSize( tex, 0 ).x );
  3558. uvec2 uv;
  3559. uv.x = index % width;
  3560. uv.y = index / width;
  3561. return texelFetch( tex, ivec2( uv ), 0 );
  3562. }
  3563. vec4 texelFetch1D( sampler2D tex, uint index ) {
  3564. uint width = uint( textureSize( tex, 0 ).x );
  3565. uvec2 uv;
  3566. uv.x = index % width;
  3567. uv.y = index / width;
  3568. return texelFetch( tex, ivec2( uv ), 0 );
  3569. }
  3570. vec4 textureSampleBarycoord( sampler2D tex, vec3 barycoord, uvec3 faceIndices ) {
  3571. return
  3572. barycoord.x * texelFetch1D( tex, faceIndices.x ) +
  3573. barycoord.y * texelFetch1D( tex, faceIndices.y ) +
  3574. barycoord.z * texelFetch1D( tex, faceIndices.z );
  3575. }
  3576. void ndcToCameraRay(
  3577. vec2 coord, mat4 cameraWorld, mat4 invProjectionMatrix,
  3578. out vec3 rayOrigin, out vec3 rayDirection
  3579. ) {
  3580. // get camera look direction and near plane for camera clipping
  3581. vec4 lookDirection = cameraWorld * vec4( 0.0, 0.0, - 1.0, 0.0 );
  3582. vec4 nearVector = invProjectionMatrix * vec4( 0.0, 0.0, - 1.0, 1.0 );
  3583. float near = abs( nearVector.z / nearVector.w );
  3584. // get the camera direction and position from camera matrices
  3585. vec4 origin = cameraWorld * vec4( 0.0, 0.0, 0.0, 1.0 );
  3586. vec4 direction = invProjectionMatrix * vec4( coord, 0.5, 1.0 );
  3587. direction /= direction.w;
  3588. direction = cameraWorld * direction - origin;
  3589. // slide the origin along the ray until it sits at the near clip plane position
  3590. origin.xyz += direction.xyz * near / dot( direction, lookDirection );
  3591. rayOrigin = origin.xyz;
  3592. rayDirection = direction.xyz;
  3593. }
  3594. `;var ar=`
  3595. #ifndef TRI_INTERSECT_EPSILON
  3596. #define TRI_INTERSECT_EPSILON 1e-5
  3597. #endif
  3598. // Raycasting
  3599. bool intersectsBounds( vec3 rayOrigin, vec3 rayDirection, vec3 boundsMin, vec3 boundsMax, out float dist ) {
  3600. // https://www.reddit.com/r/opengl/comments/8ntzz5/fast_glsl_ray_box_intersection/
  3601. // https://tavianator.com/2011/ray_box.html
  3602. vec3 invDir = 1.0 / rayDirection;
  3603. // find intersection distances for each plane
  3604. vec3 tMinPlane = invDir * ( boundsMin - rayOrigin );
  3605. vec3 tMaxPlane = invDir * ( boundsMax - rayOrigin );
  3606. // get the min and max distances from each intersection
  3607. vec3 tMinHit = min( tMaxPlane, tMinPlane );
  3608. vec3 tMaxHit = max( tMaxPlane, tMinPlane );
  3609. // get the furthest hit distance
  3610. vec2 t = max( tMinHit.xx, tMinHit.yz );
  3611. float t0 = max( t.x, t.y );
  3612. // get the minimum hit distance
  3613. t = min( tMaxHit.xx, tMaxHit.yz );
  3614. float t1 = min( t.x, t.y );
  3615. // set distance to 0.0 if the ray starts inside the box
  3616. dist = max( t0, 0.0 );
  3617. return t1 >= dist;
  3618. }
  3619. bool intersectsTriangle(
  3620. vec3 rayOrigin, vec3 rayDirection, vec3 a, vec3 b, vec3 c,
  3621. out vec3 barycoord, out vec3 norm, out float dist, out float side
  3622. ) {
  3623. // https://stackoverflow.com/questions/42740765/intersection-between-line-and-triangle-in-3d
  3624. vec3 edge1 = b - a;
  3625. vec3 edge2 = c - a;
  3626. norm = cross( edge1, edge2 );
  3627. float det = - dot( rayDirection, norm );
  3628. float invdet = 1.0 / det;
  3629. vec3 AO = rayOrigin - a;
  3630. vec3 DAO = cross( AO, rayDirection );
  3631. vec4 uvt;
  3632. uvt.x = dot( edge2, DAO ) * invdet;
  3633. uvt.y = - dot( edge1, DAO ) * invdet;
  3634. uvt.z = dot( AO, norm ) * invdet;
  3635. uvt.w = 1.0 - uvt.x - uvt.y;
  3636. // set the hit information
  3637. barycoord = uvt.wxy; // arranged in A, B, C order
  3638. dist = uvt.z;
  3639. side = sign( det );
  3640. norm = side * normalize( norm );
  3641. // add an epsilon to avoid misses between triangles
  3642. uvt += vec4( TRI_INTERSECT_EPSILON );
  3643. return all( greaterThanEqual( uvt, vec4( 0.0 ) ) );
  3644. }
  3645. bool intersectTriangles(
  3646. // geometry info and triangle range
  3647. sampler2D positionAttr, usampler2D indexAttr, uint offset, uint count,
  3648. // ray
  3649. vec3 rayOrigin, vec3 rayDirection,
  3650. // outputs
  3651. inout float minDistance, inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord,
  3652. inout float side, inout float dist
  3653. ) {
  3654. bool found = false;
  3655. vec3 localBarycoord, localNormal;
  3656. float localDist, localSide;
  3657. for ( uint i = offset, l = offset + count; i < l; i ++ ) {
  3658. uvec3 indices = uTexelFetch1D( indexAttr, i ).xyz;
  3659. vec3 a = texelFetch1D( positionAttr, indices.x ).rgb;
  3660. vec3 b = texelFetch1D( positionAttr, indices.y ).rgb;
  3661. vec3 c = texelFetch1D( positionAttr, indices.z ).rgb;
  3662. if (
  3663. intersectsTriangle( rayOrigin, rayDirection, a, b, c, localBarycoord, localNormal, localDist, localSide )
  3664. && localDist < minDistance
  3665. ) {
  3666. found = true;
  3667. minDistance = localDist;
  3668. faceIndices = uvec4( indices.xyz, i );
  3669. faceNormal = localNormal;
  3670. side = localSide;
  3671. barycoord = localBarycoord;
  3672. dist = localDist;
  3673. }
  3674. }
  3675. return found;
  3676. }
  3677. bool intersectsBVHNodeBounds( vec3 rayOrigin, vec3 rayDirection, sampler2D bvhBounds, uint currNodeIndex, out float dist ) {
  3678. uint cni2 = currNodeIndex * 2u;
  3679. vec3 boundsMin = texelFetch1D( bvhBounds, cni2 ).xyz;
  3680. vec3 boundsMax = texelFetch1D( bvhBounds, cni2 + 1u ).xyz;
  3681. return intersectsBounds( rayOrigin, rayDirection, boundsMin, boundsMax, dist );
  3682. }
  3683. // use a macro to hide the fact that we need to expand the struct into separate fields
  3684. #define bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist ) _bvhIntersectFirstHit( bvh.position, bvh.index, bvh.bvhBounds, bvh.bvhContents, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist )
  3685. bool _bvhIntersectFirstHit(
  3686. // bvh info
  3687. sampler2D bvh_position, usampler2D bvh_index, sampler2D bvh_bvhBounds, usampler2D bvh_bvhContents,
  3688. // ray
  3689. vec3 rayOrigin, vec3 rayDirection,
  3690. // output variables split into separate variables due to output precision
  3691. inout uvec4 faceIndices, inout vec3 faceNormal, inout vec3 barycoord,
  3692. inout float side, inout float dist
  3693. ) {
  3694. // stack needs to be twice as long as the deepest tree we expect because
  3695. // we push both the left and right child onto the stack every traversal
  3696. int ptr = 0;
  3697. uint stack[ BVH_STACK_DEPTH ];
  3698. stack[ 0 ] = 0u;
  3699. float triangleDistance = INFINITY;
  3700. bool found = false;
  3701. while ( ptr > - 1 && ptr < BVH_STACK_DEPTH ) {
  3702. uint currNodeIndex = stack[ ptr ];
  3703. ptr --;
  3704. // check if we intersect the current bounds
  3705. float boundsHitDistance;
  3706. if (
  3707. ! intersectsBVHNodeBounds( rayOrigin, rayDirection, bvh_bvhBounds, currNodeIndex, boundsHitDistance )
  3708. || boundsHitDistance > triangleDistance
  3709. ) {
  3710. continue;
  3711. }
  3712. uvec2 boundsInfo = uTexelFetch1D( bvh_bvhContents, currNodeIndex ).xy;
  3713. bool isLeaf = bool( boundsInfo.x & 0xffff0000u );
  3714. if ( isLeaf ) {
  3715. uint count = boundsInfo.x & 0x0000ffffu;
  3716. uint offset = boundsInfo.y;
  3717. found = intersectTriangles(
  3718. bvh_position, bvh_index, offset, count,
  3719. rayOrigin, rayDirection, triangleDistance,
  3720. faceIndices, faceNormal, barycoord, side, dist
  3721. ) || found;
  3722. } else {
  3723. uint leftIndex = currNodeIndex + 1u;
  3724. uint splitAxis = boundsInfo.x & 0x0000ffffu;
  3725. uint rightIndex = boundsInfo.y;
  3726. bool leftToRight = rayDirection[ splitAxis ] >= 0.0;
  3727. uint c1 = leftToRight ? leftIndex : rightIndex;
  3728. uint c2 = leftToRight ? rightIndex : leftIndex;
  3729. // set c2 in the stack so we traverse it later. We need to keep track of a pointer in
  3730. // the stack while we traverse. The second pointer added is the one that will be
  3731. // traversed first
  3732. ptr ++;
  3733. stack[ ptr ] = c2;
  3734. ptr ++;
  3735. stack[ ptr ] = c1;
  3736. }
  3737. }
  3738. return found;
  3739. }
  3740. `;var ku=`
  3741. ${or}
  3742. ${ar}
  3743. `;onmessage=({data:c})=>{let t=performance.now();function e(r){r=Math.min(r,1);let a=performance.now();a-t>=10&&r!==1&&(postMessage({error:null,serialized:null,position:null,progress:r}),t=a)}let{index:n,position:i,options:s}=c;try{let r=new nn;if(r.setAttribute("position",new it(i,3,!1)),n&&r.setIndex(new it(n,1,!1)),s.includedProgressCallback&&(s.onProgress=e),s.groups){let l=s.groups;for(let f in l){let u=l[f];r.addGroup(u.start,u.count,u.materialIndex)}}let a=new ye(r,s),o=ye.serialize(a,{copyIndexBuffer:!1}),h=[i.buffer,...o.roots];o.index&&h.push(o.index.buffer),h=h.filter(l=>typeof SharedArrayBuffer>"u"||!(l instanceof SharedArrayBuffer)),a._indirectBuffer&&h.push(o.indirectBuffer.buffer),postMessage({error:null,serialized:o,position:i,progress:1},h)}catch(r){postMessage({error:r,serialized:null,position:null,progress:1})}};})();
  3744. /*! Bundled license information:
  3745. three/build/three.module.js:
  3746. (**
  3747. * @license
  3748. * Copyright 2010-2024 Three.js Authors
  3749. * SPDX-License-Identifier: MIT
  3750. *)
  3751. */
  3752. //# sourceMappingURL=generateMeshBVH.worker.js.map