three.js 1.2 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464
  1. // threejs.org/license
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.THREE = {}));
  6. }(this, (function (exports) { 'use strict';
  7. /**
  8. * Copyright (c) 2014-present, Facebook, Inc.
  9. *
  10. * This source code is licensed under the MIT license found in the
  11. * LICENSE file in the root directory of this source tree.
  12. */
  13. var runtime = function (exports) {
  14. var Op = Object.prototype;
  15. var hasOwn = Op.hasOwnProperty;
  16. var undefined$1; // More compressible than void 0.
  17. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  18. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  19. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  20. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  21. function define(obj, key, value) {
  22. Object.defineProperty(obj, key, {
  23. value: value,
  24. enumerable: true,
  25. configurable: true,
  26. writable: true
  27. });
  28. return obj[key];
  29. }
  30. try {
  31. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  32. define({}, "");
  33. } catch (err) {
  34. define = function define(obj, key, value) {
  35. return obj[key] = value;
  36. };
  37. }
  38. function wrap(innerFn, outerFn, self, tryLocsList) {
  39. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  40. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  41. var generator = Object.create(protoGenerator.prototype);
  42. var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
  43. // .throw, and .return methods.
  44. generator._invoke = makeInvokeMethod(innerFn, self, context);
  45. return generator;
  46. }
  47. exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
  48. // record like context.tryEntries[i].completion. This interface could
  49. // have been (and was previously) designed to take a closure to be
  50. // invoked without arguments, but in all the cases we care about we
  51. // already have an existing method we want to call, so there's no need
  52. // to create a new function object. We can even get away with assuming
  53. // the method takes exactly one argument, since that happens to be true
  54. // in every case, so we don't have to touch the arguments object. The
  55. // only additional allocation required is the completion record, which
  56. // has a stable shape and so hopefully should be cheap to allocate.
  57. function tryCatch(fn, obj, arg) {
  58. try {
  59. return {
  60. type: "normal",
  61. arg: fn.call(obj, arg)
  62. };
  63. } catch (err) {
  64. return {
  65. type: "throw",
  66. arg: err
  67. };
  68. }
  69. }
  70. var GenStateSuspendedStart = "suspendedStart";
  71. var GenStateSuspendedYield = "suspendedYield";
  72. var GenStateExecuting = "executing";
  73. var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
  74. // breaking out of the dispatch switch statement.
  75. var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
  76. // .constructor.prototype properties for functions that return Generator
  77. // objects. For full spec compliance, you may wish to configure your
  78. // minifier not to mangle the names of these two functions.
  79. function Generator() {}
  80. function GeneratorFunction() {}
  81. function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
  82. // don't natively support it.
  83. var IteratorPrototype = {};
  84. IteratorPrototype[iteratorSymbol] = function () {
  85. return this;
  86. };
  87. var getProto = Object.getPrototypeOf;
  88. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  89. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  90. // This environment has a native %IteratorPrototype%; use it instead
  91. // of the polyfill.
  92. IteratorPrototype = NativeIteratorPrototype;
  93. }
  94. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  95. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  96. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  97. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
  98. // Iterator interface in terms of a single ._invoke method.
  99. function defineIteratorMethods(prototype) {
  100. ["next", "throw", "return"].forEach(function (method) {
  101. define(prototype, method, function (arg) {
  102. return this._invoke(method, arg);
  103. });
  104. });
  105. }
  106. exports.isGeneratorFunction = function (genFun) {
  107. var ctor = typeof genFun === "function" && genFun.constructor;
  108. return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
  109. // do is to check its .name property.
  110. (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  111. };
  112. exports.mark = function (genFun) {
  113. if (Object.setPrototypeOf) {
  114. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  115. } else {
  116. genFun.__proto__ = GeneratorFunctionPrototype;
  117. define(genFun, toStringTagSymbol, "GeneratorFunction");
  118. }
  119. genFun.prototype = Object.create(Gp);
  120. return genFun;
  121. }; // Within the body of any async function, `await x` is transformed to
  122. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  123. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  124. // meant to be awaited.
  125. exports.awrap = function (arg) {
  126. return {
  127. __await: arg
  128. };
  129. };
  130. function AsyncIterator(generator, PromiseImpl) {
  131. function invoke(method, arg, resolve, reject) {
  132. var record = tryCatch(generator[method], generator, arg);
  133. if (record.type === "throw") {
  134. reject(record.arg);
  135. } else {
  136. var result = record.arg;
  137. var value = result.value;
  138. if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
  139. return PromiseImpl.resolve(value.__await).then(function (value) {
  140. invoke("next", value, resolve, reject);
  141. }, function (err) {
  142. invoke("throw", err, resolve, reject);
  143. });
  144. }
  145. return PromiseImpl.resolve(value).then(function (unwrapped) {
  146. // When a yielded Promise is resolved, its final value becomes
  147. // the .value of the Promise<{value,done}> result for the
  148. // current iteration.
  149. result.value = unwrapped;
  150. resolve(result);
  151. }, function (error) {
  152. // If a rejected Promise was yielded, throw the rejection back
  153. // into the async generator function so it can be handled there.
  154. return invoke("throw", error, resolve, reject);
  155. });
  156. }
  157. }
  158. var previousPromise;
  159. function enqueue(method, arg) {
  160. function callInvokeWithMethodAndArg() {
  161. return new PromiseImpl(function (resolve, reject) {
  162. invoke(method, arg, resolve, reject);
  163. });
  164. }
  165. return previousPromise = // If enqueue has been called before, then we want to wait until
  166. // all previous Promises have been resolved before calling invoke,
  167. // so that results are always delivered in the correct order. If
  168. // enqueue has not been called before, then it is important to
  169. // call invoke immediately, without waiting on a callback to fire,
  170. // so that the async generator function has the opportunity to do
  171. // any necessary setup in a predictable way. This predictability
  172. // is why the Promise constructor synchronously invokes its
  173. // executor callback, and why async functions synchronously
  174. // execute code before the first await. Since we implement simple
  175. // async functions in terms of async generators, it is especially
  176. // important to get this right, even though it requires care.
  177. previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
  178. // invocations of the iterator.
  179. callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  180. } // Define the unified helper method that is used to implement .next,
  181. // .throw, and .return (see defineIteratorMethods).
  182. this._invoke = enqueue;
  183. }
  184. defineIteratorMethods(AsyncIterator.prototype);
  185. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  186. return this;
  187. };
  188. exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
  189. // AsyncIterator objects; they just return a Promise for the value of
  190. // the final result produced by the iterator.
  191. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  192. if (PromiseImpl === void 0) PromiseImpl = Promise;
  193. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  194. return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
  195. : iter.next().then(function (result) {
  196. return result.done ? result.value : iter.next();
  197. });
  198. };
  199. function makeInvokeMethod(innerFn, self, context) {
  200. var state = GenStateSuspendedStart;
  201. return function invoke(method, arg) {
  202. if (state === GenStateExecuting) {
  203. throw new Error("Generator is already running");
  204. }
  205. if (state === GenStateCompleted) {
  206. if (method === "throw") {
  207. throw arg;
  208. } // Be forgiving, per 25.3.3.3.3 of the spec:
  209. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  210. return doneResult();
  211. }
  212. context.method = method;
  213. context.arg = arg;
  214. while (true) {
  215. var delegate = context.delegate;
  216. if (delegate) {
  217. var delegateResult = maybeInvokeDelegate(delegate, context);
  218. if (delegateResult) {
  219. if (delegateResult === ContinueSentinel) continue;
  220. return delegateResult;
  221. }
  222. }
  223. if (context.method === "next") {
  224. // Setting context._sent for legacy support of Babel's
  225. // function.sent implementation.
  226. context.sent = context._sent = context.arg;
  227. } else if (context.method === "throw") {
  228. if (state === GenStateSuspendedStart) {
  229. state = GenStateCompleted;
  230. throw context.arg;
  231. }
  232. context.dispatchException(context.arg);
  233. } else if (context.method === "return") {
  234. context.abrupt("return", context.arg);
  235. }
  236. state = GenStateExecuting;
  237. var record = tryCatch(innerFn, self, context);
  238. if (record.type === "normal") {
  239. // If an exception is thrown from innerFn, we leave state ===
  240. // GenStateExecuting and loop back for another invocation.
  241. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  242. if (record.arg === ContinueSentinel) {
  243. continue;
  244. }
  245. return {
  246. value: record.arg,
  247. done: context.done
  248. };
  249. } else if (record.type === "throw") {
  250. state = GenStateCompleted; // Dispatch the exception by looping back around to the
  251. // context.dispatchException(context.arg) call above.
  252. context.method = "throw";
  253. context.arg = record.arg;
  254. }
  255. }
  256. };
  257. } // Call delegate.iterator[context.method](context.arg) and handle the
  258. // result, either by returning a { value, done } result from the
  259. // delegate iterator, or by modifying context.method and context.arg,
  260. // setting context.delegate to null, and returning the ContinueSentinel.
  261. function maybeInvokeDelegate(delegate, context) {
  262. var method = delegate.iterator[context.method];
  263. if (method === undefined$1) {
  264. // A .throw or .return when the delegate iterator has no .throw
  265. // method always terminates the yield* loop.
  266. context.delegate = null;
  267. if (context.method === "throw") {
  268. // Note: ["return"] must be used for ES3 parsing compatibility.
  269. if (delegate.iterator["return"]) {
  270. // If the delegate iterator has a return method, give it a
  271. // chance to clean up.
  272. context.method = "return";
  273. context.arg = undefined$1;
  274. maybeInvokeDelegate(delegate, context);
  275. if (context.method === "throw") {
  276. // If maybeInvokeDelegate(context) changed context.method from
  277. // "return" to "throw", let that override the TypeError below.
  278. return ContinueSentinel;
  279. }
  280. }
  281. context.method = "throw";
  282. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  283. }
  284. return ContinueSentinel;
  285. }
  286. var record = tryCatch(method, delegate.iterator, context.arg);
  287. if (record.type === "throw") {
  288. context.method = "throw";
  289. context.arg = record.arg;
  290. context.delegate = null;
  291. return ContinueSentinel;
  292. }
  293. var info = record.arg;
  294. if (!info) {
  295. context.method = "throw";
  296. context.arg = new TypeError("iterator result is not an object");
  297. context.delegate = null;
  298. return ContinueSentinel;
  299. }
  300. if (info.done) {
  301. // Assign the result of the finished delegate to the temporary
  302. // variable specified by delegate.resultName (see delegateYield).
  303. context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
  304. context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
  305. // exception, let the outer generator proceed normally. If
  306. // context.method was "next", forget context.arg since it has been
  307. // "consumed" by the delegate iterator. If context.method was
  308. // "return", allow the original .return call to continue in the
  309. // outer generator.
  310. if (context.method !== "return") {
  311. context.method = "next";
  312. context.arg = undefined$1;
  313. }
  314. } else {
  315. // Re-yield the result returned by the delegate method.
  316. return info;
  317. } // The delegate iterator is finished, so forget it and continue with
  318. // the outer generator.
  319. context.delegate = null;
  320. return ContinueSentinel;
  321. } // Define Generator.prototype.{next,throw,return} in terms of the
  322. // unified ._invoke helper method.
  323. defineIteratorMethods(Gp);
  324. define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
  325. // @@iterator function is called on it. Some browsers' implementations of the
  326. // iterator prototype chain incorrectly implement this, causing the Generator
  327. // object to not be returned from this call. This ensures that doesn't happen.
  328. // See https://github.com/facebook/regenerator/issues/274 for more details.
  329. Gp[iteratorSymbol] = function () {
  330. return this;
  331. };
  332. Gp.toString = function () {
  333. return "[object Generator]";
  334. };
  335. function pushTryEntry(locs) {
  336. var entry = {
  337. tryLoc: locs[0]
  338. };
  339. if (1 in locs) {
  340. entry.catchLoc = locs[1];
  341. }
  342. if (2 in locs) {
  343. entry.finallyLoc = locs[2];
  344. entry.afterLoc = locs[3];
  345. }
  346. this.tryEntries.push(entry);
  347. }
  348. function resetTryEntry(entry) {
  349. var record = entry.completion || {};
  350. record.type = "normal";
  351. delete record.arg;
  352. entry.completion = record;
  353. }
  354. function Context(tryLocsList) {
  355. // The root entry object (effectively a try statement without a catch
  356. // or a finally block) gives us a place to store values thrown from
  357. // locations where there is no enclosing try statement.
  358. this.tryEntries = [{
  359. tryLoc: "root"
  360. }];
  361. tryLocsList.forEach(pushTryEntry, this);
  362. this.reset(true);
  363. }
  364. exports.keys = function (object) {
  365. var keys = [];
  366. for (var key in object) {
  367. keys.push(key);
  368. }
  369. keys.reverse(); // Rather than returning an object with a next method, we keep
  370. // things simple and return the next function itself.
  371. return function next() {
  372. while (keys.length) {
  373. var key = keys.pop();
  374. if (key in object) {
  375. next.value = key;
  376. next.done = false;
  377. return next;
  378. }
  379. } // To avoid creating an additional object, we just hang the .value
  380. // and .done properties off the next function object itself. This
  381. // also ensures that the minifier will not anonymize the function.
  382. next.done = true;
  383. return next;
  384. };
  385. };
  386. function values(iterable) {
  387. if (iterable) {
  388. var iteratorMethod = iterable[iteratorSymbol];
  389. if (iteratorMethod) {
  390. return iteratorMethod.call(iterable);
  391. }
  392. if (typeof iterable.next === "function") {
  393. return iterable;
  394. }
  395. if (!isNaN(iterable.length)) {
  396. var i = -1,
  397. next = function next() {
  398. while (++i < iterable.length) {
  399. if (hasOwn.call(iterable, i)) {
  400. next.value = iterable[i];
  401. next.done = false;
  402. return next;
  403. }
  404. }
  405. next.value = undefined$1;
  406. next.done = true;
  407. return next;
  408. };
  409. return next.next = next;
  410. }
  411. } // Return an iterator with no values.
  412. return {
  413. next: doneResult
  414. };
  415. }
  416. exports.values = values;
  417. function doneResult() {
  418. return {
  419. value: undefined$1,
  420. done: true
  421. };
  422. }
  423. Context.prototype = {
  424. constructor: Context,
  425. reset: function reset(skipTempReset) {
  426. this.prev = 0;
  427. this.next = 0; // Resetting context._sent for legacy support of Babel's
  428. // function.sent implementation.
  429. this.sent = this._sent = undefined$1;
  430. this.done = false;
  431. this.delegate = null;
  432. this.method = "next";
  433. this.arg = undefined$1;
  434. this.tryEntries.forEach(resetTryEntry);
  435. if (!skipTempReset) {
  436. for (var name in this) {
  437. // Not sure about the optimal order of these conditions:
  438. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  439. this[name] = undefined$1;
  440. }
  441. }
  442. }
  443. },
  444. stop: function stop() {
  445. this.done = true;
  446. var rootEntry = this.tryEntries[0];
  447. var rootRecord = rootEntry.completion;
  448. if (rootRecord.type === "throw") {
  449. throw rootRecord.arg;
  450. }
  451. return this.rval;
  452. },
  453. dispatchException: function dispatchException(exception) {
  454. if (this.done) {
  455. throw exception;
  456. }
  457. var context = this;
  458. function handle(loc, caught) {
  459. record.type = "throw";
  460. record.arg = exception;
  461. context.next = loc;
  462. if (caught) {
  463. // If the dispatched exception was caught by a catch block,
  464. // then let that catch block handle the exception normally.
  465. context.method = "next";
  466. context.arg = undefined$1;
  467. }
  468. return !!caught;
  469. }
  470. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  471. var entry = this.tryEntries[i];
  472. var record = entry.completion;
  473. if (entry.tryLoc === "root") {
  474. // Exception thrown outside of any try block that could handle
  475. // it, so set the completion value of the entire function to
  476. // throw the exception.
  477. return handle("end");
  478. }
  479. if (entry.tryLoc <= this.prev) {
  480. var hasCatch = hasOwn.call(entry, "catchLoc");
  481. var hasFinally = hasOwn.call(entry, "finallyLoc");
  482. if (hasCatch && hasFinally) {
  483. if (this.prev < entry.catchLoc) {
  484. return handle(entry.catchLoc, true);
  485. } else if (this.prev < entry.finallyLoc) {
  486. return handle(entry.finallyLoc);
  487. }
  488. } else if (hasCatch) {
  489. if (this.prev < entry.catchLoc) {
  490. return handle(entry.catchLoc, true);
  491. }
  492. } else if (hasFinally) {
  493. if (this.prev < entry.finallyLoc) {
  494. return handle(entry.finallyLoc);
  495. }
  496. } else {
  497. throw new Error("try statement without catch or finally");
  498. }
  499. }
  500. }
  501. },
  502. abrupt: function abrupt(type, arg) {
  503. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  504. var entry = this.tryEntries[i];
  505. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  506. var finallyEntry = entry;
  507. break;
  508. }
  509. }
  510. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  511. // Ignore the finally entry if control is not jumping to a
  512. // location outside the try/catch block.
  513. finallyEntry = null;
  514. }
  515. var record = finallyEntry ? finallyEntry.completion : {};
  516. record.type = type;
  517. record.arg = arg;
  518. if (finallyEntry) {
  519. this.method = "next";
  520. this.next = finallyEntry.finallyLoc;
  521. return ContinueSentinel;
  522. }
  523. return this.complete(record);
  524. },
  525. complete: function complete(record, afterLoc) {
  526. if (record.type === "throw") {
  527. throw record.arg;
  528. }
  529. if (record.type === "break" || record.type === "continue") {
  530. this.next = record.arg;
  531. } else if (record.type === "return") {
  532. this.rval = this.arg = record.arg;
  533. this.method = "return";
  534. this.next = "end";
  535. } else if (record.type === "normal" && afterLoc) {
  536. this.next = afterLoc;
  537. }
  538. return ContinueSentinel;
  539. },
  540. finish: function finish(finallyLoc) {
  541. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  542. var entry = this.tryEntries[i];
  543. if (entry.finallyLoc === finallyLoc) {
  544. this.complete(entry.completion, entry.afterLoc);
  545. resetTryEntry(entry);
  546. return ContinueSentinel;
  547. }
  548. }
  549. },
  550. "catch": function _catch(tryLoc) {
  551. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  552. var entry = this.tryEntries[i];
  553. if (entry.tryLoc === tryLoc) {
  554. var record = entry.completion;
  555. if (record.type === "throw") {
  556. var thrown = record.arg;
  557. resetTryEntry(entry);
  558. }
  559. return thrown;
  560. }
  561. } // The context.catch method must only be called with a location
  562. // argument that corresponds to a known catch block.
  563. throw new Error("illegal catch attempt");
  564. },
  565. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  566. this.delegate = {
  567. iterator: values(iterable),
  568. resultName: resultName,
  569. nextLoc: nextLoc
  570. };
  571. if (this.method === "next") {
  572. // Deliberately forget the last sent value so that we don't
  573. // accidentally pass it on to the delegate.
  574. this.arg = undefined$1;
  575. }
  576. return ContinueSentinel;
  577. }
  578. }; // Regardless of whether this script is executing as a CommonJS module
  579. // or not, return the runtime object so that we can declare the variable
  580. // regeneratorRuntime in the outer scope, which allows this module to be
  581. // injected easily by `bin/regenerator --include-runtime script.js`.
  582. return exports;
  583. }( // If this script is executing as a CommonJS module, use module.exports
  584. // as the regeneratorRuntime namespace. Otherwise create a new empty
  585. // object. Either way, the resulting object will be used to initialize
  586. // the regeneratorRuntime variable at the top of this file.
  587. typeof module === "object" ? module.exports : {});
  588. try {
  589. regeneratorRuntime = runtime;
  590. } catch (accidentalStrictMode) {
  591. // This module should not be running in strict mode, so the above
  592. // assignment should always work unless something is misconfigured. Just
  593. // in case runtime.js accidentally runs in strict mode, we can escape
  594. // strict mode using a global Function call. This could conceivably fail
  595. // if a Content Security Policy forbids using Function, but in that case
  596. // the proper solution is to fix the accidental strict mode problem. If
  597. // you've misconfigured your bundler to force strict mode and applied a
  598. // CSP to forbid Function, and you're not willing to fix either of those
  599. // problems, please detail your unique predicament in a GitHub issue.
  600. Function("r", "regeneratorRuntime = r")(runtime);
  601. }
  602. var REVISION = '126dev';
  603. var MOUSE = {
  604. LEFT: 0,
  605. MIDDLE: 1,
  606. RIGHT: 2,
  607. ROTATE: 0,
  608. DOLLY: 1,
  609. PAN: 2
  610. };
  611. var TOUCH = {
  612. ROTATE: 0,
  613. PAN: 1,
  614. DOLLY_PAN: 2,
  615. DOLLY_ROTATE: 3
  616. };
  617. var CullFaceNone = 0;
  618. var CullFaceBack = 1;
  619. var CullFaceFront = 2;
  620. var CullFaceFrontBack = 3;
  621. var BasicShadowMap = 0;
  622. var PCFShadowMap = 1;
  623. var PCFSoftShadowMap = 2;
  624. var VSMShadowMap = 3;
  625. var FrontSide = 0;
  626. var BackSide = 1;
  627. var DoubleSide = 2;
  628. var FlatShading = 1;
  629. var SmoothShading = 2;
  630. var NoBlending = 0;
  631. var NormalBlending = 1;
  632. var AdditiveBlending = 2;
  633. var SubtractiveBlending = 3;
  634. var MultiplyBlending = 4;
  635. var CustomBlending = 5;
  636. var AddEquation = 100;
  637. var SubtractEquation = 101;
  638. var ReverseSubtractEquation = 102;
  639. var MinEquation = 103;
  640. var MaxEquation = 104;
  641. var ZeroFactor = 200;
  642. var OneFactor = 201;
  643. var SrcColorFactor = 202;
  644. var OneMinusSrcColorFactor = 203;
  645. var SrcAlphaFactor = 204;
  646. var OneMinusSrcAlphaFactor = 205;
  647. var DstAlphaFactor = 206;
  648. var OneMinusDstAlphaFactor = 207;
  649. var DstColorFactor = 208;
  650. var OneMinusDstColorFactor = 209;
  651. var SrcAlphaSaturateFactor = 210;
  652. var NeverDepth = 0;
  653. var AlwaysDepth = 1;
  654. var LessDepth = 2;
  655. var LessEqualDepth = 3;
  656. var EqualDepth = 4;
  657. var GreaterEqualDepth = 5;
  658. var GreaterDepth = 6;
  659. var NotEqualDepth = 7;
  660. var MultiplyOperation = 0;
  661. var MixOperation = 1;
  662. var AddOperation = 2;
  663. var NoToneMapping = 0;
  664. var LinearToneMapping = 1;
  665. var ReinhardToneMapping = 2;
  666. var CineonToneMapping = 3;
  667. var ACESFilmicToneMapping = 4;
  668. var CustomToneMapping = 5;
  669. var UVMapping = 300;
  670. var CubeReflectionMapping = 301;
  671. var CubeRefractionMapping = 302;
  672. var EquirectangularReflectionMapping = 303;
  673. var EquirectangularRefractionMapping = 304;
  674. var CubeUVReflectionMapping = 306;
  675. var CubeUVRefractionMapping = 307;
  676. var RepeatWrapping = 1000;
  677. var ClampToEdgeWrapping = 1001;
  678. var MirroredRepeatWrapping = 1002;
  679. var NearestFilter = 1003;
  680. var NearestMipmapNearestFilter = 1004;
  681. var NearestMipMapNearestFilter = 1004;
  682. var NearestMipmapLinearFilter = 1005;
  683. var NearestMipMapLinearFilter = 1005;
  684. var LinearFilter = 1006;
  685. var LinearMipmapNearestFilter = 1007;
  686. var LinearMipMapNearestFilter = 1007;
  687. var LinearMipmapLinearFilter = 1008;
  688. var LinearMipMapLinearFilter = 1008;
  689. var UnsignedByteType = 1009;
  690. var ByteType = 1010;
  691. var ShortType = 1011;
  692. var UnsignedShortType = 1012;
  693. var IntType = 1013;
  694. var UnsignedIntType = 1014;
  695. var FloatType = 1015;
  696. var HalfFloatType = 1016;
  697. var UnsignedShort4444Type = 1017;
  698. var UnsignedShort5551Type = 1018;
  699. var UnsignedShort565Type = 1019;
  700. var UnsignedInt248Type = 1020;
  701. var AlphaFormat = 1021;
  702. var RGBFormat = 1022;
  703. var RGBAFormat = 1023;
  704. var LuminanceFormat = 1024;
  705. var LuminanceAlphaFormat = 1025;
  706. var RGBEFormat = RGBAFormat;
  707. var DepthFormat = 1026;
  708. var DepthStencilFormat = 1027;
  709. var RedFormat = 1028;
  710. var RedIntegerFormat = 1029;
  711. var RGFormat = 1030;
  712. var RGIntegerFormat = 1031;
  713. var RGBIntegerFormat = 1032;
  714. var RGBAIntegerFormat = 1033;
  715. var RGB_S3TC_DXT1_Format = 33776;
  716. var RGBA_S3TC_DXT1_Format = 33777;
  717. var RGBA_S3TC_DXT3_Format = 33778;
  718. var RGBA_S3TC_DXT5_Format = 33779;
  719. var RGB_PVRTC_4BPPV1_Format = 35840;
  720. var RGB_PVRTC_2BPPV1_Format = 35841;
  721. var RGBA_PVRTC_4BPPV1_Format = 35842;
  722. var RGBA_PVRTC_2BPPV1_Format = 35843;
  723. var RGB_ETC1_Format = 36196;
  724. var RGB_ETC2_Format = 37492;
  725. var RGBA_ETC2_EAC_Format = 37496;
  726. var RGBA_ASTC_4x4_Format = 37808;
  727. var RGBA_ASTC_5x4_Format = 37809;
  728. var RGBA_ASTC_5x5_Format = 37810;
  729. var RGBA_ASTC_6x5_Format = 37811;
  730. var RGBA_ASTC_6x6_Format = 37812;
  731. var RGBA_ASTC_8x5_Format = 37813;
  732. var RGBA_ASTC_8x6_Format = 37814;
  733. var RGBA_ASTC_8x8_Format = 37815;
  734. var RGBA_ASTC_10x5_Format = 37816;
  735. var RGBA_ASTC_10x6_Format = 37817;
  736. var RGBA_ASTC_10x8_Format = 37818;
  737. var RGBA_ASTC_10x10_Format = 37819;
  738. var RGBA_ASTC_12x10_Format = 37820;
  739. var RGBA_ASTC_12x12_Format = 37821;
  740. var RGBA_BPTC_Format = 36492;
  741. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  742. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  743. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  744. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  745. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  746. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  747. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  748. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  749. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  750. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  751. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  752. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  753. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  754. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  755. var LoopOnce = 2200;
  756. var LoopRepeat = 2201;
  757. var LoopPingPong = 2202;
  758. var InterpolateDiscrete = 2300;
  759. var InterpolateLinear = 2301;
  760. var InterpolateSmooth = 2302;
  761. var ZeroCurvatureEnding = 2400;
  762. var ZeroSlopeEnding = 2401;
  763. var WrapAroundEnding = 2402;
  764. var NormalAnimationBlendMode = 2500;
  765. var AdditiveAnimationBlendMode = 2501;
  766. var TrianglesDrawMode = 0;
  767. var TriangleStripDrawMode = 1;
  768. var TriangleFanDrawMode = 2;
  769. var LinearEncoding = 3000;
  770. var sRGBEncoding = 3001;
  771. var GammaEncoding = 3007;
  772. var RGBEEncoding = 3002;
  773. var LogLuvEncoding = 3003;
  774. var RGBM7Encoding = 3004;
  775. var RGBM16Encoding = 3005;
  776. var RGBDEncoding = 3006;
  777. var BasicDepthPacking = 3200;
  778. var RGBADepthPacking = 3201;
  779. var TangentSpaceNormalMap = 0;
  780. var ObjectSpaceNormalMap = 1;
  781. var ZeroStencilOp = 0;
  782. var KeepStencilOp = 7680;
  783. var ReplaceStencilOp = 7681;
  784. var IncrementStencilOp = 7682;
  785. var DecrementStencilOp = 7683;
  786. var IncrementWrapStencilOp = 34055;
  787. var DecrementWrapStencilOp = 34056;
  788. var InvertStencilOp = 5386;
  789. var NeverStencilFunc = 512;
  790. var LessStencilFunc = 513;
  791. var EqualStencilFunc = 514;
  792. var LessEqualStencilFunc = 515;
  793. var GreaterStencilFunc = 516;
  794. var NotEqualStencilFunc = 517;
  795. var GreaterEqualStencilFunc = 518;
  796. var AlwaysStencilFunc = 519;
  797. var StaticDrawUsage = 35044;
  798. var DynamicDrawUsage = 35048;
  799. var StreamDrawUsage = 35040;
  800. var StaticReadUsage = 35045;
  801. var DynamicReadUsage = 35049;
  802. var StreamReadUsage = 35041;
  803. var StaticCopyUsage = 35046;
  804. var DynamicCopyUsage = 35050;
  805. var StreamCopyUsage = 35042;
  806. var GLSL1 = '100';
  807. var GLSL3 = '300 es';
  808. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  809. try {
  810. var info = gen[key](arg);
  811. var value = info.value;
  812. } catch (error) {
  813. reject(error);
  814. return;
  815. }
  816. if (info.done) {
  817. resolve(value);
  818. } else {
  819. Promise.resolve(value).then(_next, _throw);
  820. }
  821. }
  822. function _asyncToGenerator(fn) {
  823. return function () {
  824. var self = this,
  825. args = arguments;
  826. return new Promise(function (resolve, reject) {
  827. var gen = fn.apply(self, args);
  828. function _next(value) {
  829. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  830. }
  831. function _throw(err) {
  832. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  833. }
  834. _next(undefined);
  835. });
  836. };
  837. }
  838. function _defineProperties(target, props) {
  839. for (var i = 0; i < props.length; i++) {
  840. var descriptor = props[i];
  841. descriptor.enumerable = descriptor.enumerable || false;
  842. descriptor.configurable = true;
  843. if ("value" in descriptor) descriptor.writable = true;
  844. Object.defineProperty(target, descriptor.key, descriptor);
  845. }
  846. }
  847. function _createClass(Constructor, protoProps, staticProps) {
  848. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  849. if (staticProps) _defineProperties(Constructor, staticProps);
  850. return Constructor;
  851. }
  852. function _inheritsLoose(subClass, superClass) {
  853. subClass.prototype = Object.create(superClass.prototype);
  854. subClass.prototype.constructor = subClass;
  855. _setPrototypeOf(subClass, superClass);
  856. }
  857. function _setPrototypeOf(o, p) {
  858. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  859. o.__proto__ = p;
  860. return o;
  861. };
  862. return _setPrototypeOf(o, p);
  863. }
  864. function _assertThisInitialized(self) {
  865. if (self === void 0) {
  866. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  867. }
  868. return self;
  869. }
  870. function _unsupportedIterableToArray(o, minLen) {
  871. if (!o) return;
  872. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  873. var n = Object.prototype.toString.call(o).slice(8, -1);
  874. if (n === "Object" && o.constructor) n = o.constructor.name;
  875. if (n === "Map" || n === "Set") return Array.from(o);
  876. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  877. }
  878. function _arrayLikeToArray(arr, len) {
  879. if (len == null || len > arr.length) len = arr.length;
  880. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  881. return arr2;
  882. }
  883. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  884. var it;
  885. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  886. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  887. if (it) o = it;
  888. var i = 0;
  889. return function () {
  890. if (i >= o.length) return {
  891. done: true
  892. };
  893. return {
  894. done: false,
  895. value: o[i++]
  896. };
  897. };
  898. }
  899. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  900. }
  901. it = o[Symbol.iterator]();
  902. return it.next.bind(it);
  903. }
  904. /**
  905. * https://github.com/mrdoob/eventdispatcher.js/
  906. */
  907. function EventDispatcher() {}
  908. Object.assign(EventDispatcher.prototype, {
  909. addEventListener: function addEventListener(type, listener) {
  910. if (this._listeners === undefined) this._listeners = {};
  911. var listeners = this._listeners;
  912. if (listeners[type] === undefined) {
  913. listeners[type] = [];
  914. }
  915. if (listeners[type].indexOf(listener) === -1) {
  916. listeners[type].push(listener);
  917. }
  918. },
  919. hasEventListener: function hasEventListener(type, listener) {
  920. if (this._listeners === undefined) return false;
  921. var listeners = this._listeners;
  922. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  923. },
  924. removeEventListener: function removeEventListener(type, listener) {
  925. if (this._listeners === undefined) return;
  926. var listeners = this._listeners;
  927. var listenerArray = listeners[type];
  928. if (listenerArray !== undefined) {
  929. var index = listenerArray.indexOf(listener);
  930. if (index !== -1) {
  931. listenerArray.splice(index, 1);
  932. }
  933. }
  934. },
  935. dispatchEvent: function dispatchEvent(event) {
  936. if (this._listeners === undefined) return;
  937. var listeners = this._listeners;
  938. var listenerArray = listeners[event.type];
  939. if (listenerArray !== undefined) {
  940. event.target = this; // Make a copy, in case listeners are removed while iterating.
  941. var array = listenerArray.slice(0);
  942. for (var i = 0, l = array.length; i < l; i++) {
  943. array[i].call(this, event);
  944. }
  945. }
  946. }
  947. });
  948. var _lut = [];
  949. for (var i = 0; i < 256; i++) {
  950. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  951. }
  952. var _seed = 1234567;
  953. var MathUtils = {
  954. DEG2RAD: Math.PI / 180,
  955. RAD2DEG: 180 / Math.PI,
  956. generateUUID: function generateUUID() {
  957. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  958. var d0 = Math.random() * 0xffffffff | 0;
  959. var d1 = Math.random() * 0xffffffff | 0;
  960. var d2 = Math.random() * 0xffffffff | 0;
  961. var d3 = Math.random() * 0xffffffff | 0;
  962. var uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' + _lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' + _lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] + _lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff]; // .toUpperCase() here flattens concatenated strings to save heap memory space.
  963. return uuid.toUpperCase();
  964. },
  965. clamp: function clamp(value, min, max) {
  966. return Math.max(min, Math.min(max, value));
  967. },
  968. // compute euclidian modulo of m % n
  969. // https://en.wikipedia.org/wiki/Modulo_operation
  970. euclideanModulo: function euclideanModulo(n, m) {
  971. return (n % m + m) % m;
  972. },
  973. // Linear mapping from range <a1, a2> to range <b1, b2>
  974. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  975. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  976. },
  977. // https://en.wikipedia.org/wiki/Linear_interpolation
  978. lerp: function lerp(x, y, t) {
  979. return (1 - t) * x + t * y;
  980. },
  981. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  982. damp: function damp(x, y, lambda, dt) {
  983. return MathUtils.lerp(x, y, 1 - Math.exp(-lambda * dt));
  984. },
  985. // https://www.desmos.com/calculator/vcsjnyz7x4
  986. pingpong: function pingpong(x, length) {
  987. if (length === void 0) {
  988. length = 1;
  989. }
  990. return length - Math.abs(MathUtils.euclideanModulo(x, length * 2) - length);
  991. },
  992. // http://en.wikipedia.org/wiki/Smoothstep
  993. smoothstep: function smoothstep(x, min, max) {
  994. if (x <= min) return 0;
  995. if (x >= max) return 1;
  996. x = (x - min) / (max - min);
  997. return x * x * (3 - 2 * x);
  998. },
  999. smootherstep: function smootherstep(x, min, max) {
  1000. if (x <= min) return 0;
  1001. if (x >= max) return 1;
  1002. x = (x - min) / (max - min);
  1003. return x * x * x * (x * (x * 6 - 15) + 10);
  1004. },
  1005. // Random integer from <low, high> interval
  1006. randInt: function randInt(low, high) {
  1007. return low + Math.floor(Math.random() * (high - low + 1));
  1008. },
  1009. // Random float from <low, high> interval
  1010. randFloat: function randFloat(low, high) {
  1011. return low + Math.random() * (high - low);
  1012. },
  1013. // Random float from <-range/2, range/2> interval
  1014. randFloatSpread: function randFloatSpread(range) {
  1015. return range * (0.5 - Math.random());
  1016. },
  1017. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  1018. seededRandom: function seededRandom(s) {
  1019. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  1020. _seed = _seed * 16807 % 2147483647;
  1021. return (_seed - 1) / 2147483646;
  1022. },
  1023. degToRad: function degToRad(degrees) {
  1024. return degrees * MathUtils.DEG2RAD;
  1025. },
  1026. radToDeg: function radToDeg(radians) {
  1027. return radians * MathUtils.RAD2DEG;
  1028. },
  1029. isPowerOfTwo: function isPowerOfTwo(value) {
  1030. return (value & value - 1) === 0 && value !== 0;
  1031. },
  1032. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  1033. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  1034. },
  1035. floorPowerOfTwo: function floorPowerOfTwo(value) {
  1036. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  1037. },
  1038. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  1039. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  1040. // rotations are applied to the axes in the order specified by 'order'
  1041. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  1042. // angles are in radians
  1043. var cos = Math.cos;
  1044. var sin = Math.sin;
  1045. var c2 = cos(b / 2);
  1046. var s2 = sin(b / 2);
  1047. var c13 = cos((a + c) / 2);
  1048. var s13 = sin((a + c) / 2);
  1049. var c1_3 = cos((a - c) / 2);
  1050. var s1_3 = sin((a - c) / 2);
  1051. var c3_1 = cos((c - a) / 2);
  1052. var s3_1 = sin((c - a) / 2);
  1053. switch (order) {
  1054. case 'XYX':
  1055. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  1056. break;
  1057. case 'YZY':
  1058. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  1059. break;
  1060. case 'ZXZ':
  1061. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  1062. break;
  1063. case 'XZX':
  1064. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  1065. break;
  1066. case 'YXY':
  1067. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  1068. break;
  1069. case 'ZYZ':
  1070. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  1071. break;
  1072. default:
  1073. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  1074. }
  1075. }
  1076. };
  1077. var Vector2 = /*#__PURE__*/function () {
  1078. function Vector2(x, y) {
  1079. if (x === void 0) {
  1080. x = 0;
  1081. }
  1082. if (y === void 0) {
  1083. y = 0;
  1084. }
  1085. this.x = x;
  1086. this.y = y;
  1087. }
  1088. var _proto = Vector2.prototype;
  1089. _proto.set = function set(x, y) {
  1090. this.x = x;
  1091. this.y = y;
  1092. return this;
  1093. };
  1094. _proto.setScalar = function setScalar(scalar) {
  1095. this.x = scalar;
  1096. this.y = scalar;
  1097. return this;
  1098. };
  1099. _proto.setX = function setX(x) {
  1100. this.x = x;
  1101. return this;
  1102. };
  1103. _proto.setY = function setY(y) {
  1104. this.y = y;
  1105. return this;
  1106. };
  1107. _proto.setComponent = function setComponent(index, value) {
  1108. switch (index) {
  1109. case 0:
  1110. this.x = value;
  1111. break;
  1112. case 1:
  1113. this.y = value;
  1114. break;
  1115. default:
  1116. throw new Error('index is out of range: ' + index);
  1117. }
  1118. return this;
  1119. };
  1120. _proto.getComponent = function getComponent(index) {
  1121. switch (index) {
  1122. case 0:
  1123. return this.x;
  1124. case 1:
  1125. return this.y;
  1126. default:
  1127. throw new Error('index is out of range: ' + index);
  1128. }
  1129. };
  1130. _proto.clone = function clone() {
  1131. return new this.constructor(this.x, this.y);
  1132. };
  1133. _proto.copy = function copy(v) {
  1134. this.x = v.x;
  1135. this.y = v.y;
  1136. return this;
  1137. };
  1138. _proto.add = function add(v, w) {
  1139. if (w !== undefined) {
  1140. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1141. return this.addVectors(v, w);
  1142. }
  1143. this.x += v.x;
  1144. this.y += v.y;
  1145. return this;
  1146. };
  1147. _proto.addScalar = function addScalar(s) {
  1148. this.x += s;
  1149. this.y += s;
  1150. return this;
  1151. };
  1152. _proto.addVectors = function addVectors(a, b) {
  1153. this.x = a.x + b.x;
  1154. this.y = a.y + b.y;
  1155. return this;
  1156. };
  1157. _proto.addScaledVector = function addScaledVector(v, s) {
  1158. this.x += v.x * s;
  1159. this.y += v.y * s;
  1160. return this;
  1161. };
  1162. _proto.sub = function sub(v, w) {
  1163. if (w !== undefined) {
  1164. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1165. return this.subVectors(v, w);
  1166. }
  1167. this.x -= v.x;
  1168. this.y -= v.y;
  1169. return this;
  1170. };
  1171. _proto.subScalar = function subScalar(s) {
  1172. this.x -= s;
  1173. this.y -= s;
  1174. return this;
  1175. };
  1176. _proto.subVectors = function subVectors(a, b) {
  1177. this.x = a.x - b.x;
  1178. this.y = a.y - b.y;
  1179. return this;
  1180. };
  1181. _proto.multiply = function multiply(v) {
  1182. this.x *= v.x;
  1183. this.y *= v.y;
  1184. return this;
  1185. };
  1186. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1187. this.x *= scalar;
  1188. this.y *= scalar;
  1189. return this;
  1190. };
  1191. _proto.divide = function divide(v) {
  1192. this.x /= v.x;
  1193. this.y /= v.y;
  1194. return this;
  1195. };
  1196. _proto.divideScalar = function divideScalar(scalar) {
  1197. return this.multiplyScalar(1 / scalar);
  1198. };
  1199. _proto.applyMatrix3 = function applyMatrix3(m) {
  1200. var x = this.x,
  1201. y = this.y;
  1202. var e = m.elements;
  1203. this.x = e[0] * x + e[3] * y + e[6];
  1204. this.y = e[1] * x + e[4] * y + e[7];
  1205. return this;
  1206. };
  1207. _proto.min = function min(v) {
  1208. this.x = Math.min(this.x, v.x);
  1209. this.y = Math.min(this.y, v.y);
  1210. return this;
  1211. };
  1212. _proto.max = function max(v) {
  1213. this.x = Math.max(this.x, v.x);
  1214. this.y = Math.max(this.y, v.y);
  1215. return this;
  1216. };
  1217. _proto.clamp = function clamp(min, max) {
  1218. // assumes min < max, componentwise
  1219. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1220. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1221. return this;
  1222. };
  1223. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1224. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1225. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1226. return this;
  1227. };
  1228. _proto.clampLength = function clampLength(min, max) {
  1229. var length = this.length();
  1230. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1231. };
  1232. _proto.floor = function floor() {
  1233. this.x = Math.floor(this.x);
  1234. this.y = Math.floor(this.y);
  1235. return this;
  1236. };
  1237. _proto.ceil = function ceil() {
  1238. this.x = Math.ceil(this.x);
  1239. this.y = Math.ceil(this.y);
  1240. return this;
  1241. };
  1242. _proto.round = function round() {
  1243. this.x = Math.round(this.x);
  1244. this.y = Math.round(this.y);
  1245. return this;
  1246. };
  1247. _proto.roundToZero = function roundToZero() {
  1248. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1249. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1250. return this;
  1251. };
  1252. _proto.negate = function negate() {
  1253. this.x = -this.x;
  1254. this.y = -this.y;
  1255. return this;
  1256. };
  1257. _proto.dot = function dot(v) {
  1258. return this.x * v.x + this.y * v.y;
  1259. };
  1260. _proto.cross = function cross(v) {
  1261. return this.x * v.y - this.y * v.x;
  1262. };
  1263. _proto.lengthSq = function lengthSq() {
  1264. return this.x * this.x + this.y * this.y;
  1265. };
  1266. _proto.length = function length() {
  1267. return Math.sqrt(this.x * this.x + this.y * this.y);
  1268. };
  1269. _proto.manhattanLength = function manhattanLength() {
  1270. return Math.abs(this.x) + Math.abs(this.y);
  1271. };
  1272. _proto.normalize = function normalize() {
  1273. return this.divideScalar(this.length() || 1);
  1274. };
  1275. _proto.angle = function angle() {
  1276. // computes the angle in radians with respect to the positive x-axis
  1277. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  1278. return angle;
  1279. };
  1280. _proto.distanceTo = function distanceTo(v) {
  1281. return Math.sqrt(this.distanceToSquared(v));
  1282. };
  1283. _proto.distanceToSquared = function distanceToSquared(v) {
  1284. var dx = this.x - v.x,
  1285. dy = this.y - v.y;
  1286. return dx * dx + dy * dy;
  1287. };
  1288. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  1289. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  1290. };
  1291. _proto.setLength = function setLength(length) {
  1292. return this.normalize().multiplyScalar(length);
  1293. };
  1294. _proto.lerp = function lerp(v, alpha) {
  1295. this.x += (v.x - this.x) * alpha;
  1296. this.y += (v.y - this.y) * alpha;
  1297. return this;
  1298. };
  1299. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1300. this.x = v1.x + (v2.x - v1.x) * alpha;
  1301. this.y = v1.y + (v2.y - v1.y) * alpha;
  1302. return this;
  1303. };
  1304. _proto.equals = function equals(v) {
  1305. return v.x === this.x && v.y === this.y;
  1306. };
  1307. _proto.fromArray = function fromArray(array, offset) {
  1308. if (offset === void 0) {
  1309. offset = 0;
  1310. }
  1311. this.x = array[offset];
  1312. this.y = array[offset + 1];
  1313. return this;
  1314. };
  1315. _proto.toArray = function toArray(array, offset) {
  1316. if (array === void 0) {
  1317. array = [];
  1318. }
  1319. if (offset === void 0) {
  1320. offset = 0;
  1321. }
  1322. array[offset] = this.x;
  1323. array[offset + 1] = this.y;
  1324. return array;
  1325. };
  1326. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1327. if (offset !== undefined) {
  1328. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  1329. }
  1330. this.x = attribute.getX(index);
  1331. this.y = attribute.getY(index);
  1332. return this;
  1333. };
  1334. _proto.rotateAround = function rotateAround(center, angle) {
  1335. var c = Math.cos(angle),
  1336. s = Math.sin(angle);
  1337. var x = this.x - center.x;
  1338. var y = this.y - center.y;
  1339. this.x = x * c - y * s + center.x;
  1340. this.y = x * s + y * c + center.y;
  1341. return this;
  1342. };
  1343. _proto.random = function random() {
  1344. this.x = Math.random();
  1345. this.y = Math.random();
  1346. return this;
  1347. };
  1348. _createClass(Vector2, [{
  1349. key: "width",
  1350. get: function get() {
  1351. return this.x;
  1352. },
  1353. set: function set(value) {
  1354. this.x = value;
  1355. }
  1356. }, {
  1357. key: "height",
  1358. get: function get() {
  1359. return this.y;
  1360. },
  1361. set: function set(value) {
  1362. this.y = value;
  1363. }
  1364. }]);
  1365. return Vector2;
  1366. }();
  1367. Vector2.prototype.isVector2 = true;
  1368. var Matrix3 = /*#__PURE__*/function () {
  1369. function Matrix3() {
  1370. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  1371. if (arguments.length > 0) {
  1372. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  1373. }
  1374. }
  1375. var _proto = Matrix3.prototype;
  1376. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  1377. var te = this.elements;
  1378. te[0] = n11;
  1379. te[1] = n21;
  1380. te[2] = n31;
  1381. te[3] = n12;
  1382. te[4] = n22;
  1383. te[5] = n32;
  1384. te[6] = n13;
  1385. te[7] = n23;
  1386. te[8] = n33;
  1387. return this;
  1388. };
  1389. _proto.identity = function identity() {
  1390. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  1391. return this;
  1392. };
  1393. _proto.copy = function copy(m) {
  1394. var te = this.elements;
  1395. var me = m.elements;
  1396. te[0] = me[0];
  1397. te[1] = me[1];
  1398. te[2] = me[2];
  1399. te[3] = me[3];
  1400. te[4] = me[4];
  1401. te[5] = me[5];
  1402. te[6] = me[6];
  1403. te[7] = me[7];
  1404. te[8] = me[8];
  1405. return this;
  1406. };
  1407. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  1408. xAxis.setFromMatrix3Column(this, 0);
  1409. yAxis.setFromMatrix3Column(this, 1);
  1410. zAxis.setFromMatrix3Column(this, 2);
  1411. return this;
  1412. };
  1413. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  1414. var me = m.elements;
  1415. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  1416. return this;
  1417. };
  1418. _proto.multiply = function multiply(m) {
  1419. return this.multiplyMatrices(this, m);
  1420. };
  1421. _proto.premultiply = function premultiply(m) {
  1422. return this.multiplyMatrices(m, this);
  1423. };
  1424. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  1425. var ae = a.elements;
  1426. var be = b.elements;
  1427. var te = this.elements;
  1428. var a11 = ae[0],
  1429. a12 = ae[3],
  1430. a13 = ae[6];
  1431. var a21 = ae[1],
  1432. a22 = ae[4],
  1433. a23 = ae[7];
  1434. var a31 = ae[2],
  1435. a32 = ae[5],
  1436. a33 = ae[8];
  1437. var b11 = be[0],
  1438. b12 = be[3],
  1439. b13 = be[6];
  1440. var b21 = be[1],
  1441. b22 = be[4],
  1442. b23 = be[7];
  1443. var b31 = be[2],
  1444. b32 = be[5],
  1445. b33 = be[8];
  1446. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  1447. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  1448. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  1449. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  1450. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  1451. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  1452. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  1453. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  1454. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  1455. return this;
  1456. };
  1457. _proto.multiplyScalar = function multiplyScalar(s) {
  1458. var te = this.elements;
  1459. te[0] *= s;
  1460. te[3] *= s;
  1461. te[6] *= s;
  1462. te[1] *= s;
  1463. te[4] *= s;
  1464. te[7] *= s;
  1465. te[2] *= s;
  1466. te[5] *= s;
  1467. te[8] *= s;
  1468. return this;
  1469. };
  1470. _proto.determinant = function determinant() {
  1471. var te = this.elements;
  1472. var a = te[0],
  1473. b = te[1],
  1474. c = te[2],
  1475. d = te[3],
  1476. e = te[4],
  1477. f = te[5],
  1478. g = te[6],
  1479. h = te[7],
  1480. i = te[8];
  1481. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1482. };
  1483. _proto.invert = function invert() {
  1484. var te = this.elements,
  1485. n11 = te[0],
  1486. n21 = te[1],
  1487. n31 = te[2],
  1488. n12 = te[3],
  1489. n22 = te[4],
  1490. n32 = te[5],
  1491. n13 = te[6],
  1492. n23 = te[7],
  1493. n33 = te[8],
  1494. t11 = n33 * n22 - n32 * n23,
  1495. t12 = n32 * n13 - n33 * n12,
  1496. t13 = n23 * n12 - n22 * n13,
  1497. det = n11 * t11 + n21 * t12 + n31 * t13;
  1498. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  1499. var detInv = 1 / det;
  1500. te[0] = t11 * detInv;
  1501. te[1] = (n31 * n23 - n33 * n21) * detInv;
  1502. te[2] = (n32 * n21 - n31 * n22) * detInv;
  1503. te[3] = t12 * detInv;
  1504. te[4] = (n33 * n11 - n31 * n13) * detInv;
  1505. te[5] = (n31 * n12 - n32 * n11) * detInv;
  1506. te[6] = t13 * detInv;
  1507. te[7] = (n21 * n13 - n23 * n11) * detInv;
  1508. te[8] = (n22 * n11 - n21 * n12) * detInv;
  1509. return this;
  1510. };
  1511. _proto.transpose = function transpose() {
  1512. var tmp;
  1513. var m = this.elements;
  1514. tmp = m[1];
  1515. m[1] = m[3];
  1516. m[3] = tmp;
  1517. tmp = m[2];
  1518. m[2] = m[6];
  1519. m[6] = tmp;
  1520. tmp = m[5];
  1521. m[5] = m[7];
  1522. m[7] = tmp;
  1523. return this;
  1524. };
  1525. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  1526. return this.setFromMatrix4(matrix4).invert().transpose();
  1527. };
  1528. _proto.transposeIntoArray = function transposeIntoArray(r) {
  1529. var m = this.elements;
  1530. r[0] = m[0];
  1531. r[1] = m[3];
  1532. r[2] = m[6];
  1533. r[3] = m[1];
  1534. r[4] = m[4];
  1535. r[5] = m[7];
  1536. r[6] = m[2];
  1537. r[7] = m[5];
  1538. r[8] = m[8];
  1539. return this;
  1540. };
  1541. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  1542. var c = Math.cos(rotation);
  1543. var s = Math.sin(rotation);
  1544. this.set(sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx, -sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty, 0, 0, 1);
  1545. return this;
  1546. };
  1547. _proto.scale = function scale(sx, sy) {
  1548. var te = this.elements;
  1549. te[0] *= sx;
  1550. te[3] *= sx;
  1551. te[6] *= sx;
  1552. te[1] *= sy;
  1553. te[4] *= sy;
  1554. te[7] *= sy;
  1555. return this;
  1556. };
  1557. _proto.rotate = function rotate(theta) {
  1558. var c = Math.cos(theta);
  1559. var s = Math.sin(theta);
  1560. var te = this.elements;
  1561. var a11 = te[0],
  1562. a12 = te[3],
  1563. a13 = te[6];
  1564. var a21 = te[1],
  1565. a22 = te[4],
  1566. a23 = te[7];
  1567. te[0] = c * a11 + s * a21;
  1568. te[3] = c * a12 + s * a22;
  1569. te[6] = c * a13 + s * a23;
  1570. te[1] = -s * a11 + c * a21;
  1571. te[4] = -s * a12 + c * a22;
  1572. te[7] = -s * a13 + c * a23;
  1573. return this;
  1574. };
  1575. _proto.translate = function translate(tx, ty) {
  1576. var te = this.elements;
  1577. te[0] += tx * te[2];
  1578. te[3] += tx * te[5];
  1579. te[6] += tx * te[8];
  1580. te[1] += ty * te[2];
  1581. te[4] += ty * te[5];
  1582. te[7] += ty * te[8];
  1583. return this;
  1584. };
  1585. _proto.equals = function equals(matrix) {
  1586. var te = this.elements;
  1587. var me = matrix.elements;
  1588. for (var i = 0; i < 9; i++) {
  1589. if (te[i] !== me[i]) return false;
  1590. }
  1591. return true;
  1592. };
  1593. _proto.fromArray = function fromArray(array, offset) {
  1594. if (offset === void 0) {
  1595. offset = 0;
  1596. }
  1597. for (var i = 0; i < 9; i++) {
  1598. this.elements[i] = array[i + offset];
  1599. }
  1600. return this;
  1601. };
  1602. _proto.toArray = function toArray(array, offset) {
  1603. if (array === void 0) {
  1604. array = [];
  1605. }
  1606. if (offset === void 0) {
  1607. offset = 0;
  1608. }
  1609. var te = this.elements;
  1610. array[offset] = te[0];
  1611. array[offset + 1] = te[1];
  1612. array[offset + 2] = te[2];
  1613. array[offset + 3] = te[3];
  1614. array[offset + 4] = te[4];
  1615. array[offset + 5] = te[5];
  1616. array[offset + 6] = te[6];
  1617. array[offset + 7] = te[7];
  1618. array[offset + 8] = te[8];
  1619. return array;
  1620. };
  1621. _proto.clone = function clone() {
  1622. return new this.constructor().fromArray(this.elements);
  1623. };
  1624. return Matrix3;
  1625. }();
  1626. Matrix3.prototype.isMatrix3 = true;
  1627. var _canvas;
  1628. var ImageUtils = {
  1629. getDataURL: function getDataURL(image) {
  1630. if (/^data:/i.test(image.src)) {
  1631. return image.src;
  1632. }
  1633. if (typeof HTMLCanvasElement == 'undefined') {
  1634. return image.src;
  1635. }
  1636. var canvas;
  1637. if (image instanceof HTMLCanvasElement) {
  1638. canvas = image;
  1639. } else {
  1640. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1641. _canvas.width = image.width;
  1642. _canvas.height = image.height;
  1643. var context = _canvas.getContext('2d');
  1644. if (image instanceof ImageData) {
  1645. context.putImageData(image, 0, 0);
  1646. } else {
  1647. context.drawImage(image, 0, 0, image.width, image.height);
  1648. }
  1649. canvas = _canvas;
  1650. }
  1651. if (canvas.width > 2048 || canvas.height > 2048) {
  1652. return canvas.toDataURL('image/jpeg', 0.6);
  1653. } else {
  1654. return canvas.toDataURL('image/png');
  1655. }
  1656. }
  1657. };
  1658. var textureId = 0;
  1659. var Texture = /*#__PURE__*/function (_EventDispatcher) {
  1660. _inheritsLoose(Texture, _EventDispatcher);
  1661. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1662. var _this;
  1663. if (image === void 0) {
  1664. image = Texture.DEFAULT_IMAGE;
  1665. }
  1666. if (mapping === void 0) {
  1667. mapping = Texture.DEFAULT_MAPPING;
  1668. }
  1669. if (wrapS === void 0) {
  1670. wrapS = ClampToEdgeWrapping;
  1671. }
  1672. if (wrapT === void 0) {
  1673. wrapT = ClampToEdgeWrapping;
  1674. }
  1675. if (magFilter === void 0) {
  1676. magFilter = LinearFilter;
  1677. }
  1678. if (minFilter === void 0) {
  1679. minFilter = LinearMipmapLinearFilter;
  1680. }
  1681. if (format === void 0) {
  1682. format = RGBAFormat;
  1683. }
  1684. if (type === void 0) {
  1685. type = UnsignedByteType;
  1686. }
  1687. if (anisotropy === void 0) {
  1688. anisotropy = 1;
  1689. }
  1690. if (encoding === void 0) {
  1691. encoding = LinearEncoding;
  1692. }
  1693. _this = _EventDispatcher.call(this) || this;
  1694. Object.defineProperty(_assertThisInitialized(_this), 'id', {
  1695. value: textureId++
  1696. });
  1697. _this.uuid = MathUtils.generateUUID();
  1698. _this.name = '';
  1699. _this.image = image;
  1700. _this.mipmaps = [];
  1701. _this.mapping = mapping;
  1702. _this.wrapS = wrapS;
  1703. _this.wrapT = wrapT;
  1704. _this.magFilter = magFilter;
  1705. _this.minFilter = minFilter;
  1706. _this.anisotropy = anisotropy;
  1707. _this.format = format;
  1708. _this.internalFormat = null;
  1709. _this.type = type;
  1710. _this.offset = new Vector2(0, 0);
  1711. _this.repeat = new Vector2(1, 1);
  1712. _this.center = new Vector2(0, 0);
  1713. _this.rotation = 0;
  1714. _this.matrixAutoUpdate = true;
  1715. _this.matrix = new Matrix3();
  1716. _this.generateMipmaps = true;
  1717. _this.premultiplyAlpha = false;
  1718. _this.flipY = true;
  1719. _this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1720. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1721. //
  1722. // Also changing the encoding after already used by a Material will not automatically make the Material
  1723. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1724. _this.encoding = encoding;
  1725. _this.version = 0;
  1726. _this.onUpdate = null;
  1727. return _this;
  1728. }
  1729. var _proto = Texture.prototype;
  1730. _proto.updateMatrix = function updateMatrix() {
  1731. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1732. };
  1733. _proto.clone = function clone() {
  1734. return new this.constructor().copy(this);
  1735. };
  1736. _proto.copy = function copy(source) {
  1737. this.name = source.name;
  1738. this.image = source.image;
  1739. this.mipmaps = source.mipmaps.slice(0);
  1740. this.mapping = source.mapping;
  1741. this.wrapS = source.wrapS;
  1742. this.wrapT = source.wrapT;
  1743. this.magFilter = source.magFilter;
  1744. this.minFilter = source.minFilter;
  1745. this.anisotropy = source.anisotropy;
  1746. this.format = source.format;
  1747. this.internalFormat = source.internalFormat;
  1748. this.type = source.type;
  1749. this.offset.copy(source.offset);
  1750. this.repeat.copy(source.repeat);
  1751. this.center.copy(source.center);
  1752. this.rotation = source.rotation;
  1753. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1754. this.matrix.copy(source.matrix);
  1755. this.generateMipmaps = source.generateMipmaps;
  1756. this.premultiplyAlpha = source.premultiplyAlpha;
  1757. this.flipY = source.flipY;
  1758. this.unpackAlignment = source.unpackAlignment;
  1759. this.encoding = source.encoding;
  1760. return this;
  1761. };
  1762. _proto.toJSON = function toJSON(meta) {
  1763. var isRootObject = meta === undefined || typeof meta === 'string';
  1764. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1765. return meta.textures[this.uuid];
  1766. }
  1767. var output = {
  1768. metadata: {
  1769. version: 4.5,
  1770. type: 'Texture',
  1771. generator: 'Texture.toJSON'
  1772. },
  1773. uuid: this.uuid,
  1774. name: this.name,
  1775. mapping: this.mapping,
  1776. repeat: [this.repeat.x, this.repeat.y],
  1777. offset: [this.offset.x, this.offset.y],
  1778. center: [this.center.x, this.center.y],
  1779. rotation: this.rotation,
  1780. wrap: [this.wrapS, this.wrapT],
  1781. format: this.format,
  1782. type: this.type,
  1783. encoding: this.encoding,
  1784. minFilter: this.minFilter,
  1785. magFilter: this.magFilter,
  1786. anisotropy: this.anisotropy,
  1787. flipY: this.flipY,
  1788. premultiplyAlpha: this.premultiplyAlpha,
  1789. unpackAlignment: this.unpackAlignment
  1790. };
  1791. if (this.image !== undefined) {
  1792. // TODO: Move to THREE.Image
  1793. var image = this.image;
  1794. if (image.uuid === undefined) {
  1795. image.uuid = MathUtils.generateUUID(); // UGH
  1796. }
  1797. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1798. var url;
  1799. if (Array.isArray(image)) {
  1800. // process array of images e.g. CubeTexture
  1801. url = [];
  1802. for (var i = 0, l = image.length; i < l; i++) {
  1803. // check cube texture with data textures
  1804. if (image[i].isDataTexture) {
  1805. url.push(serializeImage(image[i].image));
  1806. } else {
  1807. url.push(serializeImage(image[i]));
  1808. }
  1809. }
  1810. } else {
  1811. // process single image
  1812. url = serializeImage(image);
  1813. }
  1814. meta.images[image.uuid] = {
  1815. uuid: image.uuid,
  1816. url: url
  1817. };
  1818. }
  1819. output.image = image.uuid;
  1820. }
  1821. if (!isRootObject) {
  1822. meta.textures[this.uuid] = output;
  1823. }
  1824. return output;
  1825. };
  1826. _proto.dispose = function dispose() {
  1827. this.dispatchEvent({
  1828. type: 'dispose'
  1829. });
  1830. };
  1831. _proto.transformUv = function transformUv(uv) {
  1832. if (this.mapping !== UVMapping) return uv;
  1833. uv.applyMatrix3(this.matrix);
  1834. if (uv.x < 0 || uv.x > 1) {
  1835. switch (this.wrapS) {
  1836. case RepeatWrapping:
  1837. uv.x = uv.x - Math.floor(uv.x);
  1838. break;
  1839. case ClampToEdgeWrapping:
  1840. uv.x = uv.x < 0 ? 0 : 1;
  1841. break;
  1842. case MirroredRepeatWrapping:
  1843. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1844. uv.x = Math.ceil(uv.x) - uv.x;
  1845. } else {
  1846. uv.x = uv.x - Math.floor(uv.x);
  1847. }
  1848. break;
  1849. }
  1850. }
  1851. if (uv.y < 0 || uv.y > 1) {
  1852. switch (this.wrapT) {
  1853. case RepeatWrapping:
  1854. uv.y = uv.y - Math.floor(uv.y);
  1855. break;
  1856. case ClampToEdgeWrapping:
  1857. uv.y = uv.y < 0 ? 0 : 1;
  1858. break;
  1859. case MirroredRepeatWrapping:
  1860. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1861. uv.y = Math.ceil(uv.y) - uv.y;
  1862. } else {
  1863. uv.y = uv.y - Math.floor(uv.y);
  1864. }
  1865. break;
  1866. }
  1867. }
  1868. if (this.flipY) {
  1869. uv.y = 1 - uv.y;
  1870. }
  1871. return uv;
  1872. };
  1873. _createClass(Texture, [{
  1874. key: "needsUpdate",
  1875. set: function set(value) {
  1876. if (value === true) this.version++;
  1877. }
  1878. }]);
  1879. return Texture;
  1880. }(EventDispatcher);
  1881. Texture.DEFAULT_IMAGE = undefined;
  1882. Texture.DEFAULT_MAPPING = UVMapping;
  1883. Texture.prototype.isTexture = true;
  1884. function serializeImage(image) {
  1885. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1886. // default images
  1887. return ImageUtils.getDataURL(image);
  1888. } else {
  1889. if (image.data) {
  1890. // images of DataTexture
  1891. return {
  1892. data: Array.prototype.slice.call(image.data),
  1893. width: image.width,
  1894. height: image.height,
  1895. type: image.data.constructor.name
  1896. };
  1897. } else {
  1898. console.warn('THREE.Texture: Unable to serialize Texture.');
  1899. return {};
  1900. }
  1901. }
  1902. }
  1903. var Vector4 = /*#__PURE__*/function () {
  1904. function Vector4(x, y, z, w) {
  1905. if (x === void 0) {
  1906. x = 0;
  1907. }
  1908. if (y === void 0) {
  1909. y = 0;
  1910. }
  1911. if (z === void 0) {
  1912. z = 0;
  1913. }
  1914. if (w === void 0) {
  1915. w = 1;
  1916. }
  1917. this.x = x;
  1918. this.y = y;
  1919. this.z = z;
  1920. this.w = w;
  1921. }
  1922. var _proto = Vector4.prototype;
  1923. _proto.set = function set(x, y, z, w) {
  1924. this.x = x;
  1925. this.y = y;
  1926. this.z = z;
  1927. this.w = w;
  1928. return this;
  1929. };
  1930. _proto.setScalar = function setScalar(scalar) {
  1931. this.x = scalar;
  1932. this.y = scalar;
  1933. this.z = scalar;
  1934. this.w = scalar;
  1935. return this;
  1936. };
  1937. _proto.setX = function setX(x) {
  1938. this.x = x;
  1939. return this;
  1940. };
  1941. _proto.setY = function setY(y) {
  1942. this.y = y;
  1943. return this;
  1944. };
  1945. _proto.setZ = function setZ(z) {
  1946. this.z = z;
  1947. return this;
  1948. };
  1949. _proto.setW = function setW(w) {
  1950. this.w = w;
  1951. return this;
  1952. };
  1953. _proto.setComponent = function setComponent(index, value) {
  1954. switch (index) {
  1955. case 0:
  1956. this.x = value;
  1957. break;
  1958. case 1:
  1959. this.y = value;
  1960. break;
  1961. case 2:
  1962. this.z = value;
  1963. break;
  1964. case 3:
  1965. this.w = value;
  1966. break;
  1967. default:
  1968. throw new Error('index is out of range: ' + index);
  1969. }
  1970. return this;
  1971. };
  1972. _proto.getComponent = function getComponent(index) {
  1973. switch (index) {
  1974. case 0:
  1975. return this.x;
  1976. case 1:
  1977. return this.y;
  1978. case 2:
  1979. return this.z;
  1980. case 3:
  1981. return this.w;
  1982. default:
  1983. throw new Error('index is out of range: ' + index);
  1984. }
  1985. };
  1986. _proto.clone = function clone() {
  1987. return new this.constructor(this.x, this.y, this.z, this.w);
  1988. };
  1989. _proto.copy = function copy(v) {
  1990. this.x = v.x;
  1991. this.y = v.y;
  1992. this.z = v.z;
  1993. this.w = v.w !== undefined ? v.w : 1;
  1994. return this;
  1995. };
  1996. _proto.add = function add(v, w) {
  1997. if (w !== undefined) {
  1998. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1999. return this.addVectors(v, w);
  2000. }
  2001. this.x += v.x;
  2002. this.y += v.y;
  2003. this.z += v.z;
  2004. this.w += v.w;
  2005. return this;
  2006. };
  2007. _proto.addScalar = function addScalar(s) {
  2008. this.x += s;
  2009. this.y += s;
  2010. this.z += s;
  2011. this.w += s;
  2012. return this;
  2013. };
  2014. _proto.addVectors = function addVectors(a, b) {
  2015. this.x = a.x + b.x;
  2016. this.y = a.y + b.y;
  2017. this.z = a.z + b.z;
  2018. this.w = a.w + b.w;
  2019. return this;
  2020. };
  2021. _proto.addScaledVector = function addScaledVector(v, s) {
  2022. this.x += v.x * s;
  2023. this.y += v.y * s;
  2024. this.z += v.z * s;
  2025. this.w += v.w * s;
  2026. return this;
  2027. };
  2028. _proto.sub = function sub(v, w) {
  2029. if (w !== undefined) {
  2030. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2031. return this.subVectors(v, w);
  2032. }
  2033. this.x -= v.x;
  2034. this.y -= v.y;
  2035. this.z -= v.z;
  2036. this.w -= v.w;
  2037. return this;
  2038. };
  2039. _proto.subScalar = function subScalar(s) {
  2040. this.x -= s;
  2041. this.y -= s;
  2042. this.z -= s;
  2043. this.w -= s;
  2044. return this;
  2045. };
  2046. _proto.subVectors = function subVectors(a, b) {
  2047. this.x = a.x - b.x;
  2048. this.y = a.y - b.y;
  2049. this.z = a.z - b.z;
  2050. this.w = a.w - b.w;
  2051. return this;
  2052. };
  2053. _proto.multiply = function multiply(v) {
  2054. this.x *= v.x;
  2055. this.y *= v.y;
  2056. this.z *= v.z;
  2057. this.w *= v.w;
  2058. return this;
  2059. };
  2060. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2061. this.x *= scalar;
  2062. this.y *= scalar;
  2063. this.z *= scalar;
  2064. this.w *= scalar;
  2065. return this;
  2066. };
  2067. _proto.applyMatrix4 = function applyMatrix4(m) {
  2068. var x = this.x,
  2069. y = this.y,
  2070. z = this.z,
  2071. w = this.w;
  2072. var e = m.elements;
  2073. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  2074. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  2075. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  2076. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  2077. return this;
  2078. };
  2079. _proto.divideScalar = function divideScalar(scalar) {
  2080. return this.multiplyScalar(1 / scalar);
  2081. };
  2082. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  2083. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2084. // q is assumed to be normalized
  2085. this.w = 2 * Math.acos(q.w);
  2086. var s = Math.sqrt(1 - q.w * q.w);
  2087. if (s < 0.0001) {
  2088. this.x = 1;
  2089. this.y = 0;
  2090. this.z = 0;
  2091. } else {
  2092. this.x = q.x / s;
  2093. this.y = q.y / s;
  2094. this.z = q.z / s;
  2095. }
  2096. return this;
  2097. };
  2098. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  2099. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2100. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2101. var angle, x, y, z; // variables for result
  2102. var epsilon = 0.01,
  2103. // margin to allow for rounding errors
  2104. epsilon2 = 0.1,
  2105. // margin to distinguish between 0 and 180 degrees
  2106. te = m.elements,
  2107. m11 = te[0],
  2108. m12 = te[4],
  2109. m13 = te[8],
  2110. m21 = te[1],
  2111. m22 = te[5],
  2112. m23 = te[9],
  2113. m31 = te[2],
  2114. m32 = te[6],
  2115. m33 = te[10];
  2116. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  2117. // singularity found
  2118. // first check for identity matrix which must have +1 for all terms
  2119. // in leading diagonal and zero in other terms
  2120. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  2121. // this singularity is identity matrix so angle = 0
  2122. this.set(1, 0, 0, 0);
  2123. return this; // zero angle, arbitrary axis
  2124. } // otherwise this singularity is angle = 180
  2125. angle = Math.PI;
  2126. var xx = (m11 + 1) / 2;
  2127. var yy = (m22 + 1) / 2;
  2128. var zz = (m33 + 1) / 2;
  2129. var xy = (m12 + m21) / 4;
  2130. var xz = (m13 + m31) / 4;
  2131. var yz = (m23 + m32) / 4;
  2132. if (xx > yy && xx > zz) {
  2133. // m11 is the largest diagonal term
  2134. if (xx < epsilon) {
  2135. x = 0;
  2136. y = 0.707106781;
  2137. z = 0.707106781;
  2138. } else {
  2139. x = Math.sqrt(xx);
  2140. y = xy / x;
  2141. z = xz / x;
  2142. }
  2143. } else if (yy > zz) {
  2144. // m22 is the largest diagonal term
  2145. if (yy < epsilon) {
  2146. x = 0.707106781;
  2147. y = 0;
  2148. z = 0.707106781;
  2149. } else {
  2150. y = Math.sqrt(yy);
  2151. x = xy / y;
  2152. z = yz / y;
  2153. }
  2154. } else {
  2155. // m33 is the largest diagonal term so base result on this
  2156. if (zz < epsilon) {
  2157. x = 0.707106781;
  2158. y = 0.707106781;
  2159. z = 0;
  2160. } else {
  2161. z = Math.sqrt(zz);
  2162. x = xz / z;
  2163. y = yz / z;
  2164. }
  2165. }
  2166. this.set(x, y, z, angle);
  2167. return this; // return 180 deg rotation
  2168. } // as we have reached here there are no singularities so we can handle normally
  2169. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  2170. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2171. // caught by singularity test above, but I've left it in just in case
  2172. this.x = (m32 - m23) / s;
  2173. this.y = (m13 - m31) / s;
  2174. this.z = (m21 - m12) / s;
  2175. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  2176. return this;
  2177. };
  2178. _proto.min = function min(v) {
  2179. this.x = Math.min(this.x, v.x);
  2180. this.y = Math.min(this.y, v.y);
  2181. this.z = Math.min(this.z, v.z);
  2182. this.w = Math.min(this.w, v.w);
  2183. return this;
  2184. };
  2185. _proto.max = function max(v) {
  2186. this.x = Math.max(this.x, v.x);
  2187. this.y = Math.max(this.y, v.y);
  2188. this.z = Math.max(this.z, v.z);
  2189. this.w = Math.max(this.w, v.w);
  2190. return this;
  2191. };
  2192. _proto.clamp = function clamp(min, max) {
  2193. // assumes min < max, componentwise
  2194. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2195. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2196. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2197. this.w = Math.max(min.w, Math.min(max.w, this.w));
  2198. return this;
  2199. };
  2200. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2201. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2202. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2203. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2204. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  2205. return this;
  2206. };
  2207. _proto.clampLength = function clampLength(min, max) {
  2208. var length = this.length();
  2209. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2210. };
  2211. _proto.floor = function floor() {
  2212. this.x = Math.floor(this.x);
  2213. this.y = Math.floor(this.y);
  2214. this.z = Math.floor(this.z);
  2215. this.w = Math.floor(this.w);
  2216. return this;
  2217. };
  2218. _proto.ceil = function ceil() {
  2219. this.x = Math.ceil(this.x);
  2220. this.y = Math.ceil(this.y);
  2221. this.z = Math.ceil(this.z);
  2222. this.w = Math.ceil(this.w);
  2223. return this;
  2224. };
  2225. _proto.round = function round() {
  2226. this.x = Math.round(this.x);
  2227. this.y = Math.round(this.y);
  2228. this.z = Math.round(this.z);
  2229. this.w = Math.round(this.w);
  2230. return this;
  2231. };
  2232. _proto.roundToZero = function roundToZero() {
  2233. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2234. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2235. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2236. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  2237. return this;
  2238. };
  2239. _proto.negate = function negate() {
  2240. this.x = -this.x;
  2241. this.y = -this.y;
  2242. this.z = -this.z;
  2243. this.w = -this.w;
  2244. return this;
  2245. };
  2246. _proto.dot = function dot(v) {
  2247. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2248. };
  2249. _proto.lengthSq = function lengthSq() {
  2250. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2251. };
  2252. _proto.length = function length() {
  2253. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  2254. };
  2255. _proto.manhattanLength = function manhattanLength() {
  2256. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  2257. };
  2258. _proto.normalize = function normalize() {
  2259. return this.divideScalar(this.length() || 1);
  2260. };
  2261. _proto.setLength = function setLength(length) {
  2262. return this.normalize().multiplyScalar(length);
  2263. };
  2264. _proto.lerp = function lerp(v, alpha) {
  2265. this.x += (v.x - this.x) * alpha;
  2266. this.y += (v.y - this.y) * alpha;
  2267. this.z += (v.z - this.z) * alpha;
  2268. this.w += (v.w - this.w) * alpha;
  2269. return this;
  2270. };
  2271. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2272. this.x = v1.x + (v2.x - v1.x) * alpha;
  2273. this.y = v1.y + (v2.y - v1.y) * alpha;
  2274. this.z = v1.z + (v2.z - v1.z) * alpha;
  2275. this.w = v1.w + (v2.w - v1.w) * alpha;
  2276. return this;
  2277. };
  2278. _proto.equals = function equals(v) {
  2279. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  2280. };
  2281. _proto.fromArray = function fromArray(array, offset) {
  2282. if (offset === void 0) {
  2283. offset = 0;
  2284. }
  2285. this.x = array[offset];
  2286. this.y = array[offset + 1];
  2287. this.z = array[offset + 2];
  2288. this.w = array[offset + 3];
  2289. return this;
  2290. };
  2291. _proto.toArray = function toArray(array, offset) {
  2292. if (array === void 0) {
  2293. array = [];
  2294. }
  2295. if (offset === void 0) {
  2296. offset = 0;
  2297. }
  2298. array[offset] = this.x;
  2299. array[offset + 1] = this.y;
  2300. array[offset + 2] = this.z;
  2301. array[offset + 3] = this.w;
  2302. return array;
  2303. };
  2304. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2305. if (offset !== undefined) {
  2306. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  2307. }
  2308. this.x = attribute.getX(index);
  2309. this.y = attribute.getY(index);
  2310. this.z = attribute.getZ(index);
  2311. this.w = attribute.getW(index);
  2312. return this;
  2313. };
  2314. _proto.random = function random() {
  2315. this.x = Math.random();
  2316. this.y = Math.random();
  2317. this.z = Math.random();
  2318. this.w = Math.random();
  2319. return this;
  2320. };
  2321. _createClass(Vector4, [{
  2322. key: "width",
  2323. get: function get() {
  2324. return this.z;
  2325. },
  2326. set: function set(value) {
  2327. this.z = value;
  2328. }
  2329. }, {
  2330. key: "height",
  2331. get: function get() {
  2332. return this.w;
  2333. },
  2334. set: function set(value) {
  2335. this.w = value;
  2336. }
  2337. }]);
  2338. return Vector4;
  2339. }();
  2340. Vector4.prototype.isVector4 = true;
  2341. /*
  2342. In options, we can specify:
  2343. * Texture parameters for an auto-generated target texture
  2344. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2345. */
  2346. var WebGLRenderTarget = /*#__PURE__*/function (_EventDispatcher) {
  2347. _inheritsLoose(WebGLRenderTarget, _EventDispatcher);
  2348. function WebGLRenderTarget(width, height, options) {
  2349. var _this;
  2350. _this = _EventDispatcher.call(this) || this;
  2351. _this.width = width;
  2352. _this.height = height;
  2353. _this.depth = 1;
  2354. _this.scissor = new Vector4(0, 0, width, height);
  2355. _this.scissorTest = false;
  2356. _this.viewport = new Vector4(0, 0, width, height);
  2357. options = options || {};
  2358. _this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  2359. _this.texture.image = {};
  2360. _this.texture.image.width = width;
  2361. _this.texture.image.height = height;
  2362. _this.texture.image.depth = 1;
  2363. _this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2364. _this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2365. _this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2366. _this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  2367. _this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2368. return _this;
  2369. }
  2370. var _proto = WebGLRenderTarget.prototype;
  2371. _proto.setTexture = function setTexture(texture) {
  2372. texture.image = {
  2373. width: this.width,
  2374. height: this.height,
  2375. depth: this.depth
  2376. };
  2377. this.texture = texture;
  2378. };
  2379. _proto.setSize = function setSize(width, height, depth) {
  2380. if (depth === void 0) {
  2381. depth = 1;
  2382. }
  2383. if (this.width !== width || this.height !== height || this.depth !== depth) {
  2384. this.width = width;
  2385. this.height = height;
  2386. this.depth = depth;
  2387. this.texture.image.width = width;
  2388. this.texture.image.height = height;
  2389. this.texture.image.depth = depth;
  2390. this.dispose();
  2391. }
  2392. this.viewport.set(0, 0, width, height);
  2393. this.scissor.set(0, 0, width, height);
  2394. };
  2395. _proto.clone = function clone() {
  2396. return new this.constructor().copy(this);
  2397. };
  2398. _proto.copy = function copy(source) {
  2399. this.width = source.width;
  2400. this.height = source.height;
  2401. this.depth = source.depth;
  2402. this.viewport.copy(source.viewport);
  2403. this.texture = source.texture.clone();
  2404. this.depthBuffer = source.depthBuffer;
  2405. this.stencilBuffer = source.stencilBuffer;
  2406. this.depthTexture = source.depthTexture;
  2407. return this;
  2408. };
  2409. _proto.dispose = function dispose() {
  2410. this.dispatchEvent({
  2411. type: 'dispose'
  2412. });
  2413. };
  2414. return WebGLRenderTarget;
  2415. }(EventDispatcher);
  2416. WebGLRenderTarget.prototype.isWebGLRenderTarget = true;
  2417. var WebGLMultisampleRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  2418. _inheritsLoose(WebGLMultisampleRenderTarget, _WebGLRenderTarget);
  2419. function WebGLMultisampleRenderTarget(width, height, options) {
  2420. var _this;
  2421. _this = _WebGLRenderTarget.call(this, width, height, options) || this;
  2422. _this.samples = 4;
  2423. return _this;
  2424. }
  2425. var _proto = WebGLMultisampleRenderTarget.prototype;
  2426. _proto.copy = function copy(source) {
  2427. _WebGLRenderTarget.prototype.copy.call(this, source);
  2428. this.samples = source.samples;
  2429. return this;
  2430. };
  2431. return WebGLMultisampleRenderTarget;
  2432. }(WebGLRenderTarget);
  2433. WebGLMultisampleRenderTarget.prototype.isWebGLMultisampleRenderTarget = true;
  2434. var Quaternion = /*#__PURE__*/function () {
  2435. function Quaternion(x, y, z, w) {
  2436. if (x === void 0) {
  2437. x = 0;
  2438. }
  2439. if (y === void 0) {
  2440. y = 0;
  2441. }
  2442. if (z === void 0) {
  2443. z = 0;
  2444. }
  2445. if (w === void 0) {
  2446. w = 1;
  2447. }
  2448. this._x = x;
  2449. this._y = y;
  2450. this._z = z;
  2451. this._w = w;
  2452. }
  2453. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  2454. return qm.copy(qa).slerp(qb, t);
  2455. };
  2456. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  2457. // fuzz-free, array-based Quaternion SLERP operation
  2458. var x0 = src0[srcOffset0 + 0],
  2459. y0 = src0[srcOffset0 + 1],
  2460. z0 = src0[srcOffset0 + 2],
  2461. w0 = src0[srcOffset0 + 3];
  2462. var x1 = src1[srcOffset1 + 0],
  2463. y1 = src1[srcOffset1 + 1],
  2464. z1 = src1[srcOffset1 + 2],
  2465. w1 = src1[srcOffset1 + 3];
  2466. if (t === 0) {
  2467. dst[dstOffset + 0] = x0;
  2468. dst[dstOffset + 1] = y0;
  2469. dst[dstOffset + 2] = z0;
  2470. dst[dstOffset + 3] = w0;
  2471. return;
  2472. }
  2473. if (t === 1) {
  2474. dst[dstOffset + 0] = x1;
  2475. dst[dstOffset + 1] = y1;
  2476. dst[dstOffset + 2] = z1;
  2477. dst[dstOffset + 3] = w1;
  2478. return;
  2479. }
  2480. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  2481. var s = 1 - t;
  2482. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2483. dir = cos >= 0 ? 1 : -1,
  2484. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  2485. if (sqrSin > Number.EPSILON) {
  2486. var sin = Math.sqrt(sqrSin),
  2487. len = Math.atan2(sin, cos * dir);
  2488. s = Math.sin(s * len) / sin;
  2489. t = Math.sin(t * len) / sin;
  2490. }
  2491. var tDir = t * dir;
  2492. x0 = x0 * s + x1 * tDir;
  2493. y0 = y0 * s + y1 * tDir;
  2494. z0 = z0 * s + z1 * tDir;
  2495. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  2496. if (s === 1 - t) {
  2497. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  2498. x0 *= f;
  2499. y0 *= f;
  2500. z0 *= f;
  2501. w0 *= f;
  2502. }
  2503. }
  2504. dst[dstOffset] = x0;
  2505. dst[dstOffset + 1] = y0;
  2506. dst[dstOffset + 2] = z0;
  2507. dst[dstOffset + 3] = w0;
  2508. };
  2509. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  2510. var x0 = src0[srcOffset0];
  2511. var y0 = src0[srcOffset0 + 1];
  2512. var z0 = src0[srcOffset0 + 2];
  2513. var w0 = src0[srcOffset0 + 3];
  2514. var x1 = src1[srcOffset1];
  2515. var y1 = src1[srcOffset1 + 1];
  2516. var z1 = src1[srcOffset1 + 2];
  2517. var w1 = src1[srcOffset1 + 3];
  2518. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2519. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2520. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2521. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2522. return dst;
  2523. };
  2524. var _proto = Quaternion.prototype;
  2525. _proto.set = function set(x, y, z, w) {
  2526. this._x = x;
  2527. this._y = y;
  2528. this._z = z;
  2529. this._w = w;
  2530. this._onChangeCallback();
  2531. return this;
  2532. };
  2533. _proto.clone = function clone() {
  2534. return new this.constructor(this._x, this._y, this._z, this._w);
  2535. };
  2536. _proto.copy = function copy(quaternion) {
  2537. this._x = quaternion.x;
  2538. this._y = quaternion.y;
  2539. this._z = quaternion.z;
  2540. this._w = quaternion.w;
  2541. this._onChangeCallback();
  2542. return this;
  2543. };
  2544. _proto.setFromEuler = function setFromEuler(euler, update) {
  2545. if (!(euler && euler.isEuler)) {
  2546. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2547. }
  2548. var x = euler._x,
  2549. y = euler._y,
  2550. z = euler._z,
  2551. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  2552. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2553. // content/SpinCalc.m
  2554. var cos = Math.cos;
  2555. var sin = Math.sin;
  2556. var c1 = cos(x / 2);
  2557. var c2 = cos(y / 2);
  2558. var c3 = cos(z / 2);
  2559. var s1 = sin(x / 2);
  2560. var s2 = sin(y / 2);
  2561. var s3 = sin(z / 2);
  2562. switch (order) {
  2563. case 'XYZ':
  2564. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2565. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2566. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2567. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2568. break;
  2569. case 'YXZ':
  2570. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2571. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2572. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2573. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2574. break;
  2575. case 'ZXY':
  2576. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2577. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2578. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2579. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2580. break;
  2581. case 'ZYX':
  2582. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2583. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2584. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2585. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2586. break;
  2587. case 'YZX':
  2588. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2589. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2590. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2591. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2592. break;
  2593. case 'XZY':
  2594. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2595. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2596. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2597. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2598. break;
  2599. default:
  2600. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  2601. }
  2602. if (update !== false) this._onChangeCallback();
  2603. return this;
  2604. };
  2605. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  2606. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2607. // assumes axis is normalized
  2608. var halfAngle = angle / 2,
  2609. s = Math.sin(halfAngle);
  2610. this._x = axis.x * s;
  2611. this._y = axis.y * s;
  2612. this._z = axis.z * s;
  2613. this._w = Math.cos(halfAngle);
  2614. this._onChangeCallback();
  2615. return this;
  2616. };
  2617. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  2618. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2619. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2620. var te = m.elements,
  2621. m11 = te[0],
  2622. m12 = te[4],
  2623. m13 = te[8],
  2624. m21 = te[1],
  2625. m22 = te[5],
  2626. m23 = te[9],
  2627. m31 = te[2],
  2628. m32 = te[6],
  2629. m33 = te[10],
  2630. trace = m11 + m22 + m33;
  2631. if (trace > 0) {
  2632. var s = 0.5 / Math.sqrt(trace + 1.0);
  2633. this._w = 0.25 / s;
  2634. this._x = (m32 - m23) * s;
  2635. this._y = (m13 - m31) * s;
  2636. this._z = (m21 - m12) * s;
  2637. } else if (m11 > m22 && m11 > m33) {
  2638. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  2639. this._w = (m32 - m23) / _s;
  2640. this._x = 0.25 * _s;
  2641. this._y = (m12 + m21) / _s;
  2642. this._z = (m13 + m31) / _s;
  2643. } else if (m22 > m33) {
  2644. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  2645. this._w = (m13 - m31) / _s2;
  2646. this._x = (m12 + m21) / _s2;
  2647. this._y = 0.25 * _s2;
  2648. this._z = (m23 + m32) / _s2;
  2649. } else {
  2650. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  2651. this._w = (m21 - m12) / _s3;
  2652. this._x = (m13 + m31) / _s3;
  2653. this._y = (m23 + m32) / _s3;
  2654. this._z = 0.25 * _s3;
  2655. }
  2656. this._onChangeCallback();
  2657. return this;
  2658. };
  2659. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  2660. // assumes direction vectors vFrom and vTo are normalized
  2661. var EPS = 0.000001;
  2662. var r = vFrom.dot(vTo) + 1;
  2663. if (r < EPS) {
  2664. r = 0;
  2665. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  2666. this._x = -vFrom.y;
  2667. this._y = vFrom.x;
  2668. this._z = 0;
  2669. this._w = r;
  2670. } else {
  2671. this._x = 0;
  2672. this._y = -vFrom.z;
  2673. this._z = vFrom.y;
  2674. this._w = r;
  2675. }
  2676. } else {
  2677. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2678. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2679. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2680. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2681. this._w = r;
  2682. }
  2683. return this.normalize();
  2684. };
  2685. _proto.angleTo = function angleTo(q) {
  2686. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2687. };
  2688. _proto.rotateTowards = function rotateTowards(q, step) {
  2689. var angle = this.angleTo(q);
  2690. if (angle === 0) return this;
  2691. var t = Math.min(1, step / angle);
  2692. this.slerp(q, t);
  2693. return this;
  2694. };
  2695. _proto.identity = function identity() {
  2696. return this.set(0, 0, 0, 1);
  2697. };
  2698. _proto.invert = function invert() {
  2699. // quaternion is assumed to have unit length
  2700. return this.conjugate();
  2701. };
  2702. _proto.conjugate = function conjugate() {
  2703. this._x *= -1;
  2704. this._y *= -1;
  2705. this._z *= -1;
  2706. this._onChangeCallback();
  2707. return this;
  2708. };
  2709. _proto.dot = function dot(v) {
  2710. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2711. };
  2712. _proto.lengthSq = function lengthSq() {
  2713. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2714. };
  2715. _proto.length = function length() {
  2716. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2717. };
  2718. _proto.normalize = function normalize() {
  2719. var l = this.length();
  2720. if (l === 0) {
  2721. this._x = 0;
  2722. this._y = 0;
  2723. this._z = 0;
  2724. this._w = 1;
  2725. } else {
  2726. l = 1 / l;
  2727. this._x = this._x * l;
  2728. this._y = this._y * l;
  2729. this._z = this._z * l;
  2730. this._w = this._w * l;
  2731. }
  2732. this._onChangeCallback();
  2733. return this;
  2734. };
  2735. _proto.multiply = function multiply(q, p) {
  2736. if (p !== undefined) {
  2737. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2738. return this.multiplyQuaternions(q, p);
  2739. }
  2740. return this.multiplyQuaternions(this, q);
  2741. };
  2742. _proto.premultiply = function premultiply(q) {
  2743. return this.multiplyQuaternions(q, this);
  2744. };
  2745. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2746. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2747. var qax = a._x,
  2748. qay = a._y,
  2749. qaz = a._z,
  2750. qaw = a._w;
  2751. var qbx = b._x,
  2752. qby = b._y,
  2753. qbz = b._z,
  2754. qbw = b._w;
  2755. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2756. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2757. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2758. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2759. this._onChangeCallback();
  2760. return this;
  2761. };
  2762. _proto.slerp = function slerp(qb, t) {
  2763. if (t === 0) return this;
  2764. if (t === 1) return this.copy(qb);
  2765. var x = this._x,
  2766. y = this._y,
  2767. z = this._z,
  2768. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2769. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2770. if (cosHalfTheta < 0) {
  2771. this._w = -qb._w;
  2772. this._x = -qb._x;
  2773. this._y = -qb._y;
  2774. this._z = -qb._z;
  2775. cosHalfTheta = -cosHalfTheta;
  2776. } else {
  2777. this.copy(qb);
  2778. }
  2779. if (cosHalfTheta >= 1.0) {
  2780. this._w = w;
  2781. this._x = x;
  2782. this._y = y;
  2783. this._z = z;
  2784. return this;
  2785. }
  2786. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2787. if (sqrSinHalfTheta <= Number.EPSILON) {
  2788. var s = 1 - t;
  2789. this._w = s * w + t * this._w;
  2790. this._x = s * x + t * this._x;
  2791. this._y = s * y + t * this._y;
  2792. this._z = s * z + t * this._z;
  2793. this.normalize();
  2794. this._onChangeCallback();
  2795. return this;
  2796. }
  2797. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2798. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2799. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2800. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2801. this._w = w * ratioA + this._w * ratioB;
  2802. this._x = x * ratioA + this._x * ratioB;
  2803. this._y = y * ratioA + this._y * ratioB;
  2804. this._z = z * ratioA + this._z * ratioB;
  2805. this._onChangeCallback();
  2806. return this;
  2807. };
  2808. _proto.equals = function equals(quaternion) {
  2809. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2810. };
  2811. _proto.fromArray = function fromArray(array, offset) {
  2812. if (offset === void 0) {
  2813. offset = 0;
  2814. }
  2815. this._x = array[offset];
  2816. this._y = array[offset + 1];
  2817. this._z = array[offset + 2];
  2818. this._w = array[offset + 3];
  2819. this._onChangeCallback();
  2820. return this;
  2821. };
  2822. _proto.toArray = function toArray(array, offset) {
  2823. if (array === void 0) {
  2824. array = [];
  2825. }
  2826. if (offset === void 0) {
  2827. offset = 0;
  2828. }
  2829. array[offset] = this._x;
  2830. array[offset + 1] = this._y;
  2831. array[offset + 2] = this._z;
  2832. array[offset + 3] = this._w;
  2833. return array;
  2834. };
  2835. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2836. this._x = attribute.getX(index);
  2837. this._y = attribute.getY(index);
  2838. this._z = attribute.getZ(index);
  2839. this._w = attribute.getW(index);
  2840. return this;
  2841. };
  2842. _proto._onChange = function _onChange(callback) {
  2843. this._onChangeCallback = callback;
  2844. return this;
  2845. };
  2846. _proto._onChangeCallback = function _onChangeCallback() {};
  2847. _createClass(Quaternion, [{
  2848. key: "x",
  2849. get: function get() {
  2850. return this._x;
  2851. },
  2852. set: function set(value) {
  2853. this._x = value;
  2854. this._onChangeCallback();
  2855. }
  2856. }, {
  2857. key: "y",
  2858. get: function get() {
  2859. return this._y;
  2860. },
  2861. set: function set(value) {
  2862. this._y = value;
  2863. this._onChangeCallback();
  2864. }
  2865. }, {
  2866. key: "z",
  2867. get: function get() {
  2868. return this._z;
  2869. },
  2870. set: function set(value) {
  2871. this._z = value;
  2872. this._onChangeCallback();
  2873. }
  2874. }, {
  2875. key: "w",
  2876. get: function get() {
  2877. return this._w;
  2878. },
  2879. set: function set(value) {
  2880. this._w = value;
  2881. this._onChangeCallback();
  2882. }
  2883. }]);
  2884. return Quaternion;
  2885. }();
  2886. Quaternion.prototype.isQuaternion = true;
  2887. var Vector3 = /*#__PURE__*/function () {
  2888. function Vector3(x, y, z) {
  2889. if (x === void 0) {
  2890. x = 0;
  2891. }
  2892. if (y === void 0) {
  2893. y = 0;
  2894. }
  2895. if (z === void 0) {
  2896. z = 0;
  2897. }
  2898. this.x = x;
  2899. this.y = y;
  2900. this.z = z;
  2901. }
  2902. var _proto = Vector3.prototype;
  2903. _proto.set = function set(x, y, z) {
  2904. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2905. this.x = x;
  2906. this.y = y;
  2907. this.z = z;
  2908. return this;
  2909. };
  2910. _proto.setScalar = function setScalar(scalar) {
  2911. this.x = scalar;
  2912. this.y = scalar;
  2913. this.z = scalar;
  2914. return this;
  2915. };
  2916. _proto.setX = function setX(x) {
  2917. this.x = x;
  2918. return this;
  2919. };
  2920. _proto.setY = function setY(y) {
  2921. this.y = y;
  2922. return this;
  2923. };
  2924. _proto.setZ = function setZ(z) {
  2925. this.z = z;
  2926. return this;
  2927. };
  2928. _proto.setComponent = function setComponent(index, value) {
  2929. switch (index) {
  2930. case 0:
  2931. this.x = value;
  2932. break;
  2933. case 1:
  2934. this.y = value;
  2935. break;
  2936. case 2:
  2937. this.z = value;
  2938. break;
  2939. default:
  2940. throw new Error('index is out of range: ' + index);
  2941. }
  2942. return this;
  2943. };
  2944. _proto.getComponent = function getComponent(index) {
  2945. switch (index) {
  2946. case 0:
  2947. return this.x;
  2948. case 1:
  2949. return this.y;
  2950. case 2:
  2951. return this.z;
  2952. default:
  2953. throw new Error('index is out of range: ' + index);
  2954. }
  2955. };
  2956. _proto.clone = function clone() {
  2957. return new this.constructor(this.x, this.y, this.z);
  2958. };
  2959. _proto.copy = function copy(v) {
  2960. this.x = v.x;
  2961. this.y = v.y;
  2962. this.z = v.z;
  2963. return this;
  2964. };
  2965. _proto.add = function add(v, w) {
  2966. if (w !== undefined) {
  2967. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2968. return this.addVectors(v, w);
  2969. }
  2970. this.x += v.x;
  2971. this.y += v.y;
  2972. this.z += v.z;
  2973. return this;
  2974. };
  2975. _proto.addScalar = function addScalar(s) {
  2976. this.x += s;
  2977. this.y += s;
  2978. this.z += s;
  2979. return this;
  2980. };
  2981. _proto.addVectors = function addVectors(a, b) {
  2982. this.x = a.x + b.x;
  2983. this.y = a.y + b.y;
  2984. this.z = a.z + b.z;
  2985. return this;
  2986. };
  2987. _proto.addScaledVector = function addScaledVector(v, s) {
  2988. this.x += v.x * s;
  2989. this.y += v.y * s;
  2990. this.z += v.z * s;
  2991. return this;
  2992. };
  2993. _proto.sub = function sub(v, w) {
  2994. if (w !== undefined) {
  2995. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2996. return this.subVectors(v, w);
  2997. }
  2998. this.x -= v.x;
  2999. this.y -= v.y;
  3000. this.z -= v.z;
  3001. return this;
  3002. };
  3003. _proto.subScalar = function subScalar(s) {
  3004. this.x -= s;
  3005. this.y -= s;
  3006. this.z -= s;
  3007. return this;
  3008. };
  3009. _proto.subVectors = function subVectors(a, b) {
  3010. this.x = a.x - b.x;
  3011. this.y = a.y - b.y;
  3012. this.z = a.z - b.z;
  3013. return this;
  3014. };
  3015. _proto.multiply = function multiply(v, w) {
  3016. if (w !== undefined) {
  3017. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  3018. return this.multiplyVectors(v, w);
  3019. }
  3020. this.x *= v.x;
  3021. this.y *= v.y;
  3022. this.z *= v.z;
  3023. return this;
  3024. };
  3025. _proto.multiplyScalar = function multiplyScalar(scalar) {
  3026. this.x *= scalar;
  3027. this.y *= scalar;
  3028. this.z *= scalar;
  3029. return this;
  3030. };
  3031. _proto.multiplyVectors = function multiplyVectors(a, b) {
  3032. this.x = a.x * b.x;
  3033. this.y = a.y * b.y;
  3034. this.z = a.z * b.z;
  3035. return this;
  3036. };
  3037. _proto.applyEuler = function applyEuler(euler) {
  3038. if (!(euler && euler.isEuler)) {
  3039. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  3040. }
  3041. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  3042. };
  3043. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  3044. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  3045. };
  3046. _proto.applyMatrix3 = function applyMatrix3(m) {
  3047. var x = this.x,
  3048. y = this.y,
  3049. z = this.z;
  3050. var e = m.elements;
  3051. this.x = e[0] * x + e[3] * y + e[6] * z;
  3052. this.y = e[1] * x + e[4] * y + e[7] * z;
  3053. this.z = e[2] * x + e[5] * y + e[8] * z;
  3054. return this;
  3055. };
  3056. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  3057. return this.applyMatrix3(m).normalize();
  3058. };
  3059. _proto.applyMatrix4 = function applyMatrix4(m) {
  3060. var x = this.x,
  3061. y = this.y,
  3062. z = this.z;
  3063. var e = m.elements;
  3064. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  3065. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  3066. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  3067. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  3068. return this;
  3069. };
  3070. _proto.applyQuaternion = function applyQuaternion(q) {
  3071. var x = this.x,
  3072. y = this.y,
  3073. z = this.z;
  3074. var qx = q.x,
  3075. qy = q.y,
  3076. qz = q.z,
  3077. qw = q.w; // calculate quat * vector
  3078. var ix = qw * x + qy * z - qz * y;
  3079. var iy = qw * y + qz * x - qx * z;
  3080. var iz = qw * z + qx * y - qy * x;
  3081. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  3082. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3083. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3084. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3085. return this;
  3086. };
  3087. _proto.project = function project(camera) {
  3088. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  3089. };
  3090. _proto.unproject = function unproject(camera) {
  3091. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  3092. };
  3093. _proto.transformDirection = function transformDirection(m) {
  3094. // input: THREE.Matrix4 affine matrix
  3095. // vector interpreted as a direction
  3096. var x = this.x,
  3097. y = this.y,
  3098. z = this.z;
  3099. var e = m.elements;
  3100. this.x = e[0] * x + e[4] * y + e[8] * z;
  3101. this.y = e[1] * x + e[5] * y + e[9] * z;
  3102. this.z = e[2] * x + e[6] * y + e[10] * z;
  3103. return this.normalize();
  3104. };
  3105. _proto.divide = function divide(v) {
  3106. this.x /= v.x;
  3107. this.y /= v.y;
  3108. this.z /= v.z;
  3109. return this;
  3110. };
  3111. _proto.divideScalar = function divideScalar(scalar) {
  3112. return this.multiplyScalar(1 / scalar);
  3113. };
  3114. _proto.min = function min(v) {
  3115. this.x = Math.min(this.x, v.x);
  3116. this.y = Math.min(this.y, v.y);
  3117. this.z = Math.min(this.z, v.z);
  3118. return this;
  3119. };
  3120. _proto.max = function max(v) {
  3121. this.x = Math.max(this.x, v.x);
  3122. this.y = Math.max(this.y, v.y);
  3123. this.z = Math.max(this.z, v.z);
  3124. return this;
  3125. };
  3126. _proto.clamp = function clamp(min, max) {
  3127. // assumes min < max, componentwise
  3128. this.x = Math.max(min.x, Math.min(max.x, this.x));
  3129. this.y = Math.max(min.y, Math.min(max.y, this.y));
  3130. this.z = Math.max(min.z, Math.min(max.z, this.z));
  3131. return this;
  3132. };
  3133. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  3134. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  3135. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  3136. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  3137. return this;
  3138. };
  3139. _proto.clampLength = function clampLength(min, max) {
  3140. var length = this.length();
  3141. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  3142. };
  3143. _proto.floor = function floor() {
  3144. this.x = Math.floor(this.x);
  3145. this.y = Math.floor(this.y);
  3146. this.z = Math.floor(this.z);
  3147. return this;
  3148. };
  3149. _proto.ceil = function ceil() {
  3150. this.x = Math.ceil(this.x);
  3151. this.y = Math.ceil(this.y);
  3152. this.z = Math.ceil(this.z);
  3153. return this;
  3154. };
  3155. _proto.round = function round() {
  3156. this.x = Math.round(this.x);
  3157. this.y = Math.round(this.y);
  3158. this.z = Math.round(this.z);
  3159. return this;
  3160. };
  3161. _proto.roundToZero = function roundToZero() {
  3162. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  3163. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  3164. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  3165. return this;
  3166. };
  3167. _proto.negate = function negate() {
  3168. this.x = -this.x;
  3169. this.y = -this.y;
  3170. this.z = -this.z;
  3171. return this;
  3172. };
  3173. _proto.dot = function dot(v) {
  3174. return this.x * v.x + this.y * v.y + this.z * v.z;
  3175. } // TODO lengthSquared?
  3176. ;
  3177. _proto.lengthSq = function lengthSq() {
  3178. return this.x * this.x + this.y * this.y + this.z * this.z;
  3179. };
  3180. _proto.length = function length() {
  3181. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3182. };
  3183. _proto.manhattanLength = function manhattanLength() {
  3184. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  3185. };
  3186. _proto.normalize = function normalize() {
  3187. return this.divideScalar(this.length() || 1);
  3188. };
  3189. _proto.setLength = function setLength(length) {
  3190. return this.normalize().multiplyScalar(length);
  3191. };
  3192. _proto.lerp = function lerp(v, alpha) {
  3193. this.x += (v.x - this.x) * alpha;
  3194. this.y += (v.y - this.y) * alpha;
  3195. this.z += (v.z - this.z) * alpha;
  3196. return this;
  3197. };
  3198. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  3199. this.x = v1.x + (v2.x - v1.x) * alpha;
  3200. this.y = v1.y + (v2.y - v1.y) * alpha;
  3201. this.z = v1.z + (v2.z - v1.z) * alpha;
  3202. return this;
  3203. };
  3204. _proto.cross = function cross(v, w) {
  3205. if (w !== undefined) {
  3206. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  3207. return this.crossVectors(v, w);
  3208. }
  3209. return this.crossVectors(this, v);
  3210. };
  3211. _proto.crossVectors = function crossVectors(a, b) {
  3212. var ax = a.x,
  3213. ay = a.y,
  3214. az = a.z;
  3215. var bx = b.x,
  3216. by = b.y,
  3217. bz = b.z;
  3218. this.x = ay * bz - az * by;
  3219. this.y = az * bx - ax * bz;
  3220. this.z = ax * by - ay * bx;
  3221. return this;
  3222. };
  3223. _proto.projectOnVector = function projectOnVector(v) {
  3224. var denominator = v.lengthSq();
  3225. if (denominator === 0) return this.set(0, 0, 0);
  3226. var scalar = v.dot(this) / denominator;
  3227. return this.copy(v).multiplyScalar(scalar);
  3228. };
  3229. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  3230. _vector.copy(this).projectOnVector(planeNormal);
  3231. return this.sub(_vector);
  3232. };
  3233. _proto.reflect = function reflect(normal) {
  3234. // reflect incident vector off plane orthogonal to normal
  3235. // normal is assumed to have unit length
  3236. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  3237. };
  3238. _proto.angleTo = function angleTo(v) {
  3239. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  3240. if (denominator === 0) return Math.PI / 2;
  3241. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  3242. return Math.acos(MathUtils.clamp(theta, -1, 1));
  3243. };
  3244. _proto.distanceTo = function distanceTo(v) {
  3245. return Math.sqrt(this.distanceToSquared(v));
  3246. };
  3247. _proto.distanceToSquared = function distanceToSquared(v) {
  3248. var dx = this.x - v.x,
  3249. dy = this.y - v.y,
  3250. dz = this.z - v.z;
  3251. return dx * dx + dy * dy + dz * dz;
  3252. };
  3253. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  3254. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  3255. };
  3256. _proto.setFromSpherical = function setFromSpherical(s) {
  3257. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  3258. };
  3259. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  3260. var sinPhiRadius = Math.sin(phi) * radius;
  3261. this.x = sinPhiRadius * Math.sin(theta);
  3262. this.y = Math.cos(phi) * radius;
  3263. this.z = sinPhiRadius * Math.cos(theta);
  3264. return this;
  3265. };
  3266. _proto.setFromCylindrical = function setFromCylindrical(c) {
  3267. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  3268. };
  3269. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  3270. this.x = radius * Math.sin(theta);
  3271. this.y = y;
  3272. this.z = radius * Math.cos(theta);
  3273. return this;
  3274. };
  3275. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  3276. var e = m.elements;
  3277. this.x = e[12];
  3278. this.y = e[13];
  3279. this.z = e[14];
  3280. return this;
  3281. };
  3282. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  3283. var sx = this.setFromMatrixColumn(m, 0).length();
  3284. var sy = this.setFromMatrixColumn(m, 1).length();
  3285. var sz = this.setFromMatrixColumn(m, 2).length();
  3286. this.x = sx;
  3287. this.y = sy;
  3288. this.z = sz;
  3289. return this;
  3290. };
  3291. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  3292. return this.fromArray(m.elements, index * 4);
  3293. };
  3294. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  3295. return this.fromArray(m.elements, index * 3);
  3296. };
  3297. _proto.equals = function equals(v) {
  3298. return v.x === this.x && v.y === this.y && v.z === this.z;
  3299. };
  3300. _proto.fromArray = function fromArray(array, offset) {
  3301. if (offset === void 0) {
  3302. offset = 0;
  3303. }
  3304. this.x = array[offset];
  3305. this.y = array[offset + 1];
  3306. this.z = array[offset + 2];
  3307. return this;
  3308. };
  3309. _proto.toArray = function toArray(array, offset) {
  3310. if (array === void 0) {
  3311. array = [];
  3312. }
  3313. if (offset === void 0) {
  3314. offset = 0;
  3315. }
  3316. array[offset] = this.x;
  3317. array[offset + 1] = this.y;
  3318. array[offset + 2] = this.z;
  3319. return array;
  3320. };
  3321. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  3322. if (offset !== undefined) {
  3323. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  3324. }
  3325. this.x = attribute.getX(index);
  3326. this.y = attribute.getY(index);
  3327. this.z = attribute.getZ(index);
  3328. return this;
  3329. };
  3330. _proto.random = function random() {
  3331. this.x = Math.random();
  3332. this.y = Math.random();
  3333. this.z = Math.random();
  3334. return this;
  3335. };
  3336. return Vector3;
  3337. }();
  3338. Vector3.prototype.isVector3 = true;
  3339. var _vector = /*@__PURE__*/new Vector3();
  3340. var _quaternion = /*@__PURE__*/new Quaternion();
  3341. var Box3 = /*#__PURE__*/function () {
  3342. function Box3(min, max) {
  3343. if (min === void 0) {
  3344. min = new Vector3(+Infinity, +Infinity, +Infinity);
  3345. }
  3346. if (max === void 0) {
  3347. max = new Vector3(-Infinity, -Infinity, -Infinity);
  3348. }
  3349. this.min = min;
  3350. this.max = max;
  3351. }
  3352. var _proto = Box3.prototype;
  3353. _proto.set = function set(min, max) {
  3354. this.min.copy(min);
  3355. this.max.copy(max);
  3356. return this;
  3357. };
  3358. _proto.setFromArray = function setFromArray(array) {
  3359. var minX = +Infinity;
  3360. var minY = +Infinity;
  3361. var minZ = +Infinity;
  3362. var maxX = -Infinity;
  3363. var maxY = -Infinity;
  3364. var maxZ = -Infinity;
  3365. for (var i = 0, l = array.length; i < l; i += 3) {
  3366. var x = array[i];
  3367. var y = array[i + 1];
  3368. var z = array[i + 2];
  3369. if (x < minX) minX = x;
  3370. if (y < minY) minY = y;
  3371. if (z < minZ) minZ = z;
  3372. if (x > maxX) maxX = x;
  3373. if (y > maxY) maxY = y;
  3374. if (z > maxZ) maxZ = z;
  3375. }
  3376. this.min.set(minX, minY, minZ);
  3377. this.max.set(maxX, maxY, maxZ);
  3378. return this;
  3379. };
  3380. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  3381. var minX = +Infinity;
  3382. var minY = +Infinity;
  3383. var minZ = +Infinity;
  3384. var maxX = -Infinity;
  3385. var maxY = -Infinity;
  3386. var maxZ = -Infinity;
  3387. for (var i = 0, l = attribute.count; i < l; i++) {
  3388. var x = attribute.getX(i);
  3389. var y = attribute.getY(i);
  3390. var z = attribute.getZ(i);
  3391. if (x < minX) minX = x;
  3392. if (y < minY) minY = y;
  3393. if (z < minZ) minZ = z;
  3394. if (x > maxX) maxX = x;
  3395. if (y > maxY) maxY = y;
  3396. if (z > maxZ) maxZ = z;
  3397. }
  3398. this.min.set(minX, minY, minZ);
  3399. this.max.set(maxX, maxY, maxZ);
  3400. return this;
  3401. };
  3402. _proto.setFromPoints = function setFromPoints(points) {
  3403. this.makeEmpty();
  3404. for (var i = 0, il = points.length; i < il; i++) {
  3405. this.expandByPoint(points[i]);
  3406. }
  3407. return this;
  3408. };
  3409. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  3410. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  3411. this.min.copy(center).sub(halfSize);
  3412. this.max.copy(center).add(halfSize);
  3413. return this;
  3414. };
  3415. _proto.setFromObject = function setFromObject(object) {
  3416. this.makeEmpty();
  3417. return this.expandByObject(object);
  3418. };
  3419. _proto.clone = function clone() {
  3420. return new this.constructor().copy(this);
  3421. };
  3422. _proto.copy = function copy(box) {
  3423. this.min.copy(box.min);
  3424. this.max.copy(box.max);
  3425. return this;
  3426. };
  3427. _proto.makeEmpty = function makeEmpty() {
  3428. this.min.x = this.min.y = this.min.z = +Infinity;
  3429. this.max.x = this.max.y = this.max.z = -Infinity;
  3430. return this;
  3431. };
  3432. _proto.isEmpty = function isEmpty() {
  3433. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3434. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  3435. };
  3436. _proto.getCenter = function getCenter(target) {
  3437. if (target === undefined) {
  3438. console.warn('THREE.Box3: .getCenter() target is now required');
  3439. target = new Vector3();
  3440. }
  3441. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  3442. };
  3443. _proto.getSize = function getSize(target) {
  3444. if (target === undefined) {
  3445. console.warn('THREE.Box3: .getSize() target is now required');
  3446. target = new Vector3();
  3447. }
  3448. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  3449. };
  3450. _proto.expandByPoint = function expandByPoint(point) {
  3451. this.min.min(point);
  3452. this.max.max(point);
  3453. return this;
  3454. };
  3455. _proto.expandByVector = function expandByVector(vector) {
  3456. this.min.sub(vector);
  3457. this.max.add(vector);
  3458. return this;
  3459. };
  3460. _proto.expandByScalar = function expandByScalar(scalar) {
  3461. this.min.addScalar(-scalar);
  3462. this.max.addScalar(scalar);
  3463. return this;
  3464. };
  3465. _proto.expandByObject = function expandByObject(object) {
  3466. // Computes the world-axis-aligned bounding box of an object (including its children),
  3467. // accounting for both the object's, and children's, world transforms
  3468. object.updateWorldMatrix(false, false);
  3469. var geometry = object.geometry;
  3470. if (geometry !== undefined) {
  3471. if (geometry.boundingBox === null) {
  3472. geometry.computeBoundingBox();
  3473. }
  3474. _box.copy(geometry.boundingBox);
  3475. _box.applyMatrix4(object.matrixWorld);
  3476. this.union(_box);
  3477. }
  3478. var children = object.children;
  3479. for (var i = 0, l = children.length; i < l; i++) {
  3480. this.expandByObject(children[i]);
  3481. }
  3482. return this;
  3483. };
  3484. _proto.containsPoint = function containsPoint(point) {
  3485. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true;
  3486. };
  3487. _proto.containsBox = function containsBox(box) {
  3488. return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z;
  3489. };
  3490. _proto.getParameter = function getParameter(point, target) {
  3491. // This can potentially have a divide by zero if the box
  3492. // has a size dimension of 0.
  3493. if (target === undefined) {
  3494. console.warn('THREE.Box3: .getParameter() target is now required');
  3495. target = new Vector3();
  3496. }
  3497. return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z));
  3498. };
  3499. _proto.intersectsBox = function intersectsBox(box) {
  3500. // using 6 splitting planes to rule out intersections.
  3501. return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3502. };
  3503. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3504. // Find the point on the AABB closest to the sphere center.
  3505. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  3506. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  3507. };
  3508. _proto.intersectsPlane = function intersectsPlane(plane) {
  3509. // We compute the minimum and maximum dot product values. If those values
  3510. // are on the same side (back or front) of the plane, then there is no intersection.
  3511. var min, max;
  3512. if (plane.normal.x > 0) {
  3513. min = plane.normal.x * this.min.x;
  3514. max = plane.normal.x * this.max.x;
  3515. } else {
  3516. min = plane.normal.x * this.max.x;
  3517. max = plane.normal.x * this.min.x;
  3518. }
  3519. if (plane.normal.y > 0) {
  3520. min += plane.normal.y * this.min.y;
  3521. max += plane.normal.y * this.max.y;
  3522. } else {
  3523. min += plane.normal.y * this.max.y;
  3524. max += plane.normal.y * this.min.y;
  3525. }
  3526. if (plane.normal.z > 0) {
  3527. min += plane.normal.z * this.min.z;
  3528. max += plane.normal.z * this.max.z;
  3529. } else {
  3530. min += plane.normal.z * this.max.z;
  3531. max += plane.normal.z * this.min.z;
  3532. }
  3533. return min <= -plane.constant && max >= -plane.constant;
  3534. };
  3535. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  3536. if (this.isEmpty()) {
  3537. return false;
  3538. } // compute box center and extents
  3539. this.getCenter(_center);
  3540. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  3541. _v0.subVectors(triangle.a, _center);
  3542. _v1.subVectors(triangle.b, _center);
  3543. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  3544. _f0.subVectors(_v1, _v0);
  3545. _f1.subVectors(_v2, _v1);
  3546. _f2.subVectors(_v0, _v2); // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3547. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  3548. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3549. var axes = [0, -_f0.z, _f0.y, 0, -_f1.z, _f1.y, 0, -_f2.z, _f2.y, _f0.z, 0, -_f0.x, _f1.z, 0, -_f1.x, _f2.z, 0, -_f2.x, -_f0.y, _f0.x, 0, -_f1.y, _f1.x, 0, -_f2.y, _f2.x, 0];
  3550. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3551. return false;
  3552. } // test 3 face normals from the aabb
  3553. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  3554. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3555. return false;
  3556. } // finally testing the face normal of the triangle
  3557. // use already existing triangle edge vectors here
  3558. _triangleNormal.crossVectors(_f0, _f1);
  3559. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  3560. return satForAxes(axes, _v0, _v1, _v2, _extents);
  3561. };
  3562. _proto.clampPoint = function clampPoint(point, target) {
  3563. if (target === undefined) {
  3564. console.warn('THREE.Box3: .clampPoint() target is now required');
  3565. target = new Vector3();
  3566. }
  3567. return target.copy(point).clamp(this.min, this.max);
  3568. };
  3569. _proto.distanceToPoint = function distanceToPoint(point) {
  3570. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  3571. return clampedPoint.sub(point).length();
  3572. };
  3573. _proto.getBoundingSphere = function getBoundingSphere(target) {
  3574. if (target === undefined) {
  3575. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  3576. }
  3577. this.getCenter(target.center);
  3578. target.radius = this.getSize(_vector$1).length() * 0.5;
  3579. return target;
  3580. };
  3581. _proto.intersect = function intersect(box) {
  3582. this.min.max(box.min);
  3583. this.max.min(box.max); // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  3584. if (this.isEmpty()) this.makeEmpty();
  3585. return this;
  3586. };
  3587. _proto.union = function union(box) {
  3588. this.min.min(box.min);
  3589. this.max.max(box.max);
  3590. return this;
  3591. };
  3592. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3593. // transform of empty box is an empty box.
  3594. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3595. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  3596. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  3597. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  3598. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  3599. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  3600. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  3601. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  3602. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  3603. this.setFromPoints(_points);
  3604. return this;
  3605. };
  3606. _proto.translate = function translate(offset) {
  3607. this.min.add(offset);
  3608. this.max.add(offset);
  3609. return this;
  3610. };
  3611. _proto.equals = function equals(box) {
  3612. return box.min.equals(this.min) && box.max.equals(this.max);
  3613. };
  3614. return Box3;
  3615. }();
  3616. Box3.prototype.isBox3 = true;
  3617. var _points = [/*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3(), /*@__PURE__*/new Vector3()];
  3618. var _vector$1 = /*@__PURE__*/new Vector3();
  3619. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  3620. var _v0 = /*@__PURE__*/new Vector3();
  3621. var _v1 = /*@__PURE__*/new Vector3();
  3622. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  3623. var _f0 = /*@__PURE__*/new Vector3();
  3624. var _f1 = /*@__PURE__*/new Vector3();
  3625. var _f2 = /*@__PURE__*/new Vector3();
  3626. var _center = /*@__PURE__*/new Vector3();
  3627. var _extents = /*@__PURE__*/new Vector3();
  3628. var _triangleNormal = /*@__PURE__*/new Vector3();
  3629. var _testAxis = /*@__PURE__*/new Vector3();
  3630. function satForAxes(axes, v0, v1, v2, extents) {
  3631. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  3632. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  3633. var r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z); // project all 3 vertices of the triangle onto the seperating axis
  3634. var p0 = v0.dot(_testAxis);
  3635. var p1 = v1.dot(_testAxis);
  3636. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  3637. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  3638. // points of the projected triangle are outside the projected half-length of the aabb
  3639. // the axis is seperating and we can exit
  3640. return false;
  3641. }
  3642. }
  3643. return true;
  3644. }
  3645. var _box$1 = /*@__PURE__*/new Box3();
  3646. var Sphere = /*#__PURE__*/function () {
  3647. function Sphere(center, radius) {
  3648. if (center === void 0) {
  3649. center = new Vector3();
  3650. }
  3651. if (radius === void 0) {
  3652. radius = -1;
  3653. }
  3654. this.center = center;
  3655. this.radius = radius;
  3656. }
  3657. var _proto = Sphere.prototype;
  3658. _proto.set = function set(center, radius) {
  3659. this.center.copy(center);
  3660. this.radius = radius;
  3661. return this;
  3662. };
  3663. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  3664. var center = this.center;
  3665. if (optionalCenter !== undefined) {
  3666. center.copy(optionalCenter);
  3667. } else {
  3668. _box$1.setFromPoints(points).getCenter(center);
  3669. }
  3670. var maxRadiusSq = 0;
  3671. for (var i = 0, il = points.length; i < il; i++) {
  3672. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  3673. }
  3674. this.radius = Math.sqrt(maxRadiusSq);
  3675. return this;
  3676. };
  3677. _proto.copy = function copy(sphere) {
  3678. this.center.copy(sphere.center);
  3679. this.radius = sphere.radius;
  3680. return this;
  3681. };
  3682. _proto.isEmpty = function isEmpty() {
  3683. return this.radius < 0;
  3684. };
  3685. _proto.makeEmpty = function makeEmpty() {
  3686. this.center.set(0, 0, 0);
  3687. this.radius = -1;
  3688. return this;
  3689. };
  3690. _proto.containsPoint = function containsPoint(point) {
  3691. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3692. };
  3693. _proto.distanceToPoint = function distanceToPoint(point) {
  3694. return point.distanceTo(this.center) - this.radius;
  3695. };
  3696. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3697. var radiusSum = this.radius + sphere.radius;
  3698. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3699. };
  3700. _proto.intersectsBox = function intersectsBox(box) {
  3701. return box.intersectsSphere(this);
  3702. };
  3703. _proto.intersectsPlane = function intersectsPlane(plane) {
  3704. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3705. };
  3706. _proto.clampPoint = function clampPoint(point, target) {
  3707. var deltaLengthSq = this.center.distanceToSquared(point);
  3708. if (target === undefined) {
  3709. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3710. target = new Vector3();
  3711. }
  3712. target.copy(point);
  3713. if (deltaLengthSq > this.radius * this.radius) {
  3714. target.sub(this.center).normalize();
  3715. target.multiplyScalar(this.radius).add(this.center);
  3716. }
  3717. return target;
  3718. };
  3719. _proto.getBoundingBox = function getBoundingBox(target) {
  3720. if (target === undefined) {
  3721. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3722. target = new Box3();
  3723. }
  3724. if (this.isEmpty()) {
  3725. // Empty sphere produces empty bounding box
  3726. target.makeEmpty();
  3727. return target;
  3728. }
  3729. target.set(this.center, this.center);
  3730. target.expandByScalar(this.radius);
  3731. return target;
  3732. };
  3733. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3734. this.center.applyMatrix4(matrix);
  3735. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3736. return this;
  3737. };
  3738. _proto.translate = function translate(offset) {
  3739. this.center.add(offset);
  3740. return this;
  3741. };
  3742. _proto.equals = function equals(sphere) {
  3743. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3744. };
  3745. _proto.clone = function clone() {
  3746. return new this.constructor().copy(this);
  3747. };
  3748. return Sphere;
  3749. }();
  3750. var _vector$2 = /*@__PURE__*/new Vector3();
  3751. var _segCenter = /*@__PURE__*/new Vector3();
  3752. var _segDir = /*@__PURE__*/new Vector3();
  3753. var _diff = /*@__PURE__*/new Vector3();
  3754. var _edge1 = /*@__PURE__*/new Vector3();
  3755. var _edge2 = /*@__PURE__*/new Vector3();
  3756. var _normal = /*@__PURE__*/new Vector3();
  3757. var Ray = /*#__PURE__*/function () {
  3758. function Ray(origin, direction) {
  3759. if (origin === void 0) {
  3760. origin = new Vector3();
  3761. }
  3762. if (direction === void 0) {
  3763. direction = new Vector3(0, 0, -1);
  3764. }
  3765. this.origin = origin;
  3766. this.direction = direction;
  3767. }
  3768. var _proto = Ray.prototype;
  3769. _proto.set = function set(origin, direction) {
  3770. this.origin.copy(origin);
  3771. this.direction.copy(direction);
  3772. return this;
  3773. };
  3774. _proto.copy = function copy(ray) {
  3775. this.origin.copy(ray.origin);
  3776. this.direction.copy(ray.direction);
  3777. return this;
  3778. };
  3779. _proto.at = function at(t, target) {
  3780. if (target === undefined) {
  3781. console.warn('THREE.Ray: .at() target is now required');
  3782. target = new Vector3();
  3783. }
  3784. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3785. };
  3786. _proto.lookAt = function lookAt(v) {
  3787. this.direction.copy(v).sub(this.origin).normalize();
  3788. return this;
  3789. };
  3790. _proto.recast = function recast(t) {
  3791. this.origin.copy(this.at(t, _vector$2));
  3792. return this;
  3793. };
  3794. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3795. if (target === undefined) {
  3796. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3797. target = new Vector3();
  3798. }
  3799. target.subVectors(point, this.origin);
  3800. var directionDistance = target.dot(this.direction);
  3801. if (directionDistance < 0) {
  3802. return target.copy(this.origin);
  3803. }
  3804. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3805. };
  3806. _proto.distanceToPoint = function distanceToPoint(point) {
  3807. return Math.sqrt(this.distanceSqToPoint(point));
  3808. };
  3809. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3810. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3811. if (directionDistance < 0) {
  3812. return this.origin.distanceToSquared(point);
  3813. }
  3814. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3815. return _vector$2.distanceToSquared(point);
  3816. };
  3817. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3818. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3819. // It returns the min distance between the ray and the segment
  3820. // defined by v0 and v1
  3821. // It can also set two optional targets :
  3822. // - The closest point on the ray
  3823. // - The closest point on the segment
  3824. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3825. _segDir.copy(v1).sub(v0).normalize();
  3826. _diff.copy(this.origin).sub(_segCenter);
  3827. var segExtent = v0.distanceTo(v1) * 0.5;
  3828. var a01 = -this.direction.dot(_segDir);
  3829. var b0 = _diff.dot(this.direction);
  3830. var b1 = -_diff.dot(_segDir);
  3831. var c = _diff.lengthSq();
  3832. var det = Math.abs(1 - a01 * a01);
  3833. var s0, s1, sqrDist, extDet;
  3834. if (det > 0) {
  3835. // The ray and segment are not parallel.
  3836. s0 = a01 * b1 - b0;
  3837. s1 = a01 * b0 - b1;
  3838. extDet = segExtent * det;
  3839. if (s0 >= 0) {
  3840. if (s1 >= -extDet) {
  3841. if (s1 <= extDet) {
  3842. // region 0
  3843. // Minimum at interior points of ray and segment.
  3844. var invDet = 1 / det;
  3845. s0 *= invDet;
  3846. s1 *= invDet;
  3847. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3848. } else {
  3849. // region 1
  3850. s1 = segExtent;
  3851. s0 = Math.max(0, -(a01 * s1 + b0));
  3852. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3853. }
  3854. } else {
  3855. // region 5
  3856. s1 = -segExtent;
  3857. s0 = Math.max(0, -(a01 * s1 + b0));
  3858. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3859. }
  3860. } else {
  3861. if (s1 <= -extDet) {
  3862. // region 4
  3863. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3864. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3865. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3866. } else if (s1 <= extDet) {
  3867. // region 3
  3868. s0 = 0;
  3869. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3870. sqrDist = s1 * (s1 + 2 * b1) + c;
  3871. } else {
  3872. // region 2
  3873. s0 = Math.max(0, -(a01 * segExtent + b0));
  3874. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3875. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3876. }
  3877. }
  3878. } else {
  3879. // Ray and segment are parallel.
  3880. s1 = a01 > 0 ? -segExtent : segExtent;
  3881. s0 = Math.max(0, -(a01 * s1 + b0));
  3882. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3883. }
  3884. if (optionalPointOnRay) {
  3885. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3886. }
  3887. if (optionalPointOnSegment) {
  3888. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3889. }
  3890. return sqrDist;
  3891. };
  3892. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3893. _vector$2.subVectors(sphere.center, this.origin);
  3894. var tca = _vector$2.dot(this.direction);
  3895. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3896. var radius2 = sphere.radius * sphere.radius;
  3897. if (d2 > radius2) return null;
  3898. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3899. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3900. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3901. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3902. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3903. // in order to always return an intersect point that is in front of the ray.
  3904. if (t0 < 0) return this.at(t1, target); // else t0 is in front of the ray, so return the first collision point scaled by t0
  3905. return this.at(t0, target);
  3906. };
  3907. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3908. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3909. };
  3910. _proto.distanceToPlane = function distanceToPlane(plane) {
  3911. var denominator = plane.normal.dot(this.direction);
  3912. if (denominator === 0) {
  3913. // line is coplanar, return origin
  3914. if (plane.distanceToPoint(this.origin) === 0) {
  3915. return 0;
  3916. } // Null is preferable to undefined since undefined means.... it is undefined
  3917. return null;
  3918. }
  3919. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3920. return t >= 0 ? t : null;
  3921. };
  3922. _proto.intersectPlane = function intersectPlane(plane, target) {
  3923. var t = this.distanceToPlane(plane);
  3924. if (t === null) {
  3925. return null;
  3926. }
  3927. return this.at(t, target);
  3928. };
  3929. _proto.intersectsPlane = function intersectsPlane(plane) {
  3930. // check if the ray lies on the plane first
  3931. var distToPoint = plane.distanceToPoint(this.origin);
  3932. if (distToPoint === 0) {
  3933. return true;
  3934. }
  3935. var denominator = plane.normal.dot(this.direction);
  3936. if (denominator * distToPoint < 0) {
  3937. return true;
  3938. } // ray origin is behind the plane (and is pointing behind it)
  3939. return false;
  3940. };
  3941. _proto.intersectBox = function intersectBox(box, target) {
  3942. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3943. var invdirx = 1 / this.direction.x,
  3944. invdiry = 1 / this.direction.y,
  3945. invdirz = 1 / this.direction.z;
  3946. var origin = this.origin;
  3947. if (invdirx >= 0) {
  3948. tmin = (box.min.x - origin.x) * invdirx;
  3949. tmax = (box.max.x - origin.x) * invdirx;
  3950. } else {
  3951. tmin = (box.max.x - origin.x) * invdirx;
  3952. tmax = (box.min.x - origin.x) * invdirx;
  3953. }
  3954. if (invdiry >= 0) {
  3955. tymin = (box.min.y - origin.y) * invdiry;
  3956. tymax = (box.max.y - origin.y) * invdiry;
  3957. } else {
  3958. tymin = (box.max.y - origin.y) * invdiry;
  3959. tymax = (box.min.y - origin.y) * invdiry;
  3960. }
  3961. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3962. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3963. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3964. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3965. if (invdirz >= 0) {
  3966. tzmin = (box.min.z - origin.z) * invdirz;
  3967. tzmax = (box.max.z - origin.z) * invdirz;
  3968. } else {
  3969. tzmin = (box.max.z - origin.z) * invdirz;
  3970. tzmax = (box.min.z - origin.z) * invdirz;
  3971. }
  3972. if (tmin > tzmax || tzmin > tmax) return null;
  3973. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3974. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3975. if (tmax < 0) return null;
  3976. return this.at(tmin >= 0 ? tmin : tmax, target);
  3977. };
  3978. _proto.intersectsBox = function intersectsBox(box) {
  3979. return this.intersectBox(box, _vector$2) !== null;
  3980. };
  3981. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3982. // Compute the offset origin, edges, and normal.
  3983. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3984. _edge1.subVectors(b, a);
  3985. _edge2.subVectors(c, a);
  3986. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3987. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3988. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3989. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3990. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3991. var DdN = this.direction.dot(_normal);
  3992. var sign;
  3993. if (DdN > 0) {
  3994. if (backfaceCulling) return null;
  3995. sign = 1;
  3996. } else if (DdN < 0) {
  3997. sign = -1;
  3998. DdN = -DdN;
  3999. } else {
  4000. return null;
  4001. }
  4002. _diff.subVectors(this.origin, a);
  4003. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  4004. if (DdQxE2 < 0) {
  4005. return null;
  4006. }
  4007. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  4008. if (DdE1xQ < 0) {
  4009. return null;
  4010. } // b1+b2 > 1, no intersection
  4011. if (DdQxE2 + DdE1xQ > DdN) {
  4012. return null;
  4013. } // Line intersects triangle, check if ray does.
  4014. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  4015. if (QdN < 0) {
  4016. return null;
  4017. } // Ray intersects triangle.
  4018. return this.at(QdN / DdN, target);
  4019. };
  4020. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  4021. this.origin.applyMatrix4(matrix4);
  4022. this.direction.transformDirection(matrix4);
  4023. return this;
  4024. };
  4025. _proto.equals = function equals(ray) {
  4026. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  4027. };
  4028. _proto.clone = function clone() {
  4029. return new this.constructor().copy(this);
  4030. };
  4031. return Ray;
  4032. }();
  4033. var Matrix4 = /*#__PURE__*/function () {
  4034. function Matrix4() {
  4035. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  4036. if (arguments.length > 0) {
  4037. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  4038. }
  4039. }
  4040. var _proto = Matrix4.prototype;
  4041. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  4042. var te = this.elements;
  4043. te[0] = n11;
  4044. te[4] = n12;
  4045. te[8] = n13;
  4046. te[12] = n14;
  4047. te[1] = n21;
  4048. te[5] = n22;
  4049. te[9] = n23;
  4050. te[13] = n24;
  4051. te[2] = n31;
  4052. te[6] = n32;
  4053. te[10] = n33;
  4054. te[14] = n34;
  4055. te[3] = n41;
  4056. te[7] = n42;
  4057. te[11] = n43;
  4058. te[15] = n44;
  4059. return this;
  4060. };
  4061. _proto.identity = function identity() {
  4062. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4063. return this;
  4064. };
  4065. _proto.clone = function clone() {
  4066. return new Matrix4().fromArray(this.elements);
  4067. };
  4068. _proto.copy = function copy(m) {
  4069. var te = this.elements;
  4070. var me = m.elements;
  4071. te[0] = me[0];
  4072. te[1] = me[1];
  4073. te[2] = me[2];
  4074. te[3] = me[3];
  4075. te[4] = me[4];
  4076. te[5] = me[5];
  4077. te[6] = me[6];
  4078. te[7] = me[7];
  4079. te[8] = me[8];
  4080. te[9] = me[9];
  4081. te[10] = me[10];
  4082. te[11] = me[11];
  4083. te[12] = me[12];
  4084. te[13] = me[13];
  4085. te[14] = me[14];
  4086. te[15] = me[15];
  4087. return this;
  4088. };
  4089. _proto.copyPosition = function copyPosition(m) {
  4090. var te = this.elements,
  4091. me = m.elements;
  4092. te[12] = me[12];
  4093. te[13] = me[13];
  4094. te[14] = me[14];
  4095. return this;
  4096. };
  4097. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  4098. var me = m.elements;
  4099. this.set(me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1);
  4100. return this;
  4101. };
  4102. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  4103. xAxis.setFromMatrixColumn(this, 0);
  4104. yAxis.setFromMatrixColumn(this, 1);
  4105. zAxis.setFromMatrixColumn(this, 2);
  4106. return this;
  4107. };
  4108. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  4109. this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
  4110. return this;
  4111. };
  4112. _proto.extractRotation = function extractRotation(m) {
  4113. // this method does not support reflection matrices
  4114. var te = this.elements;
  4115. var me = m.elements;
  4116. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  4117. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  4118. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  4119. te[0] = me[0] * scaleX;
  4120. te[1] = me[1] * scaleX;
  4121. te[2] = me[2] * scaleX;
  4122. te[3] = 0;
  4123. te[4] = me[4] * scaleY;
  4124. te[5] = me[5] * scaleY;
  4125. te[6] = me[6] * scaleY;
  4126. te[7] = 0;
  4127. te[8] = me[8] * scaleZ;
  4128. te[9] = me[9] * scaleZ;
  4129. te[10] = me[10] * scaleZ;
  4130. te[11] = 0;
  4131. te[12] = 0;
  4132. te[13] = 0;
  4133. te[14] = 0;
  4134. te[15] = 1;
  4135. return this;
  4136. };
  4137. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  4138. if (!(euler && euler.isEuler)) {
  4139. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  4140. }
  4141. var te = this.elements;
  4142. var x = euler.x,
  4143. y = euler.y,
  4144. z = euler.z;
  4145. var a = Math.cos(x),
  4146. b = Math.sin(x);
  4147. var c = Math.cos(y),
  4148. d = Math.sin(y);
  4149. var e = Math.cos(z),
  4150. f = Math.sin(z);
  4151. if (euler.order === 'XYZ') {
  4152. var ae = a * e,
  4153. af = a * f,
  4154. be = b * e,
  4155. bf = b * f;
  4156. te[0] = c * e;
  4157. te[4] = -c * f;
  4158. te[8] = d;
  4159. te[1] = af + be * d;
  4160. te[5] = ae - bf * d;
  4161. te[9] = -b * c;
  4162. te[2] = bf - ae * d;
  4163. te[6] = be + af * d;
  4164. te[10] = a * c;
  4165. } else if (euler.order === 'YXZ') {
  4166. var ce = c * e,
  4167. cf = c * f,
  4168. de = d * e,
  4169. df = d * f;
  4170. te[0] = ce + df * b;
  4171. te[4] = de * b - cf;
  4172. te[8] = a * d;
  4173. te[1] = a * f;
  4174. te[5] = a * e;
  4175. te[9] = -b;
  4176. te[2] = cf * b - de;
  4177. te[6] = df + ce * b;
  4178. te[10] = a * c;
  4179. } else if (euler.order === 'ZXY') {
  4180. var _ce = c * e,
  4181. _cf = c * f,
  4182. _de = d * e,
  4183. _df = d * f;
  4184. te[0] = _ce - _df * b;
  4185. te[4] = -a * f;
  4186. te[8] = _de + _cf * b;
  4187. te[1] = _cf + _de * b;
  4188. te[5] = a * e;
  4189. te[9] = _df - _ce * b;
  4190. te[2] = -a * d;
  4191. te[6] = b;
  4192. te[10] = a * c;
  4193. } else if (euler.order === 'ZYX') {
  4194. var _ae = a * e,
  4195. _af = a * f,
  4196. _be = b * e,
  4197. _bf = b * f;
  4198. te[0] = c * e;
  4199. te[4] = _be * d - _af;
  4200. te[8] = _ae * d + _bf;
  4201. te[1] = c * f;
  4202. te[5] = _bf * d + _ae;
  4203. te[9] = _af * d - _be;
  4204. te[2] = -d;
  4205. te[6] = b * c;
  4206. te[10] = a * c;
  4207. } else if (euler.order === 'YZX') {
  4208. var ac = a * c,
  4209. ad = a * d,
  4210. bc = b * c,
  4211. bd = b * d;
  4212. te[0] = c * e;
  4213. te[4] = bd - ac * f;
  4214. te[8] = bc * f + ad;
  4215. te[1] = f;
  4216. te[5] = a * e;
  4217. te[9] = -b * e;
  4218. te[2] = -d * e;
  4219. te[6] = ad * f + bc;
  4220. te[10] = ac - bd * f;
  4221. } else if (euler.order === 'XZY') {
  4222. var _ac = a * c,
  4223. _ad = a * d,
  4224. _bc = b * c,
  4225. _bd = b * d;
  4226. te[0] = c * e;
  4227. te[4] = -f;
  4228. te[8] = d * e;
  4229. te[1] = _ac * f + _bd;
  4230. te[5] = a * e;
  4231. te[9] = _ad * f - _bc;
  4232. te[2] = _bc * f - _ad;
  4233. te[6] = b * e;
  4234. te[10] = _bd * f + _ac;
  4235. } // bottom row
  4236. te[3] = 0;
  4237. te[7] = 0;
  4238. te[11] = 0; // last column
  4239. te[12] = 0;
  4240. te[13] = 0;
  4241. te[14] = 0;
  4242. te[15] = 1;
  4243. return this;
  4244. };
  4245. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  4246. return this.compose(_zero, q, _one);
  4247. };
  4248. _proto.lookAt = function lookAt(eye, target, up) {
  4249. var te = this.elements;
  4250. _z.subVectors(eye, target);
  4251. if (_z.lengthSq() === 0) {
  4252. // eye and target are in the same position
  4253. _z.z = 1;
  4254. }
  4255. _z.normalize();
  4256. _x.crossVectors(up, _z);
  4257. if (_x.lengthSq() === 0) {
  4258. // up and z are parallel
  4259. if (Math.abs(up.z) === 1) {
  4260. _z.x += 0.0001;
  4261. } else {
  4262. _z.z += 0.0001;
  4263. }
  4264. _z.normalize();
  4265. _x.crossVectors(up, _z);
  4266. }
  4267. _x.normalize();
  4268. _y.crossVectors(_z, _x);
  4269. te[0] = _x.x;
  4270. te[4] = _y.x;
  4271. te[8] = _z.x;
  4272. te[1] = _x.y;
  4273. te[5] = _y.y;
  4274. te[9] = _z.y;
  4275. te[2] = _x.z;
  4276. te[6] = _y.z;
  4277. te[10] = _z.z;
  4278. return this;
  4279. };
  4280. _proto.multiply = function multiply(m, n) {
  4281. if (n !== undefined) {
  4282. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  4283. return this.multiplyMatrices(m, n);
  4284. }
  4285. return this.multiplyMatrices(this, m);
  4286. };
  4287. _proto.premultiply = function premultiply(m) {
  4288. return this.multiplyMatrices(m, this);
  4289. };
  4290. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  4291. var ae = a.elements;
  4292. var be = b.elements;
  4293. var te = this.elements;
  4294. var a11 = ae[0],
  4295. a12 = ae[4],
  4296. a13 = ae[8],
  4297. a14 = ae[12];
  4298. var a21 = ae[1],
  4299. a22 = ae[5],
  4300. a23 = ae[9],
  4301. a24 = ae[13];
  4302. var a31 = ae[2],
  4303. a32 = ae[6],
  4304. a33 = ae[10],
  4305. a34 = ae[14];
  4306. var a41 = ae[3],
  4307. a42 = ae[7],
  4308. a43 = ae[11],
  4309. a44 = ae[15];
  4310. var b11 = be[0],
  4311. b12 = be[4],
  4312. b13 = be[8],
  4313. b14 = be[12];
  4314. var b21 = be[1],
  4315. b22 = be[5],
  4316. b23 = be[9],
  4317. b24 = be[13];
  4318. var b31 = be[2],
  4319. b32 = be[6],
  4320. b33 = be[10],
  4321. b34 = be[14];
  4322. var b41 = be[3],
  4323. b42 = be[7],
  4324. b43 = be[11],
  4325. b44 = be[15];
  4326. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  4327. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  4328. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  4329. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  4330. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  4331. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  4332. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  4333. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  4334. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  4335. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  4336. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  4337. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  4338. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  4339. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  4340. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  4341. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  4342. return this;
  4343. };
  4344. _proto.multiplyScalar = function multiplyScalar(s) {
  4345. var te = this.elements;
  4346. te[0] *= s;
  4347. te[4] *= s;
  4348. te[8] *= s;
  4349. te[12] *= s;
  4350. te[1] *= s;
  4351. te[5] *= s;
  4352. te[9] *= s;
  4353. te[13] *= s;
  4354. te[2] *= s;
  4355. te[6] *= s;
  4356. te[10] *= s;
  4357. te[14] *= s;
  4358. te[3] *= s;
  4359. te[7] *= s;
  4360. te[11] *= s;
  4361. te[15] *= s;
  4362. return this;
  4363. };
  4364. _proto.determinant = function determinant() {
  4365. var te = this.elements;
  4366. var n11 = te[0],
  4367. n12 = te[4],
  4368. n13 = te[8],
  4369. n14 = te[12];
  4370. var n21 = te[1],
  4371. n22 = te[5],
  4372. n23 = te[9],
  4373. n24 = te[13];
  4374. var n31 = te[2],
  4375. n32 = te[6],
  4376. n33 = te[10],
  4377. n34 = te[14];
  4378. var n41 = te[3],
  4379. n42 = te[7],
  4380. n43 = te[11],
  4381. n44 = te[15]; //TODO: make this more efficient
  4382. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  4383. return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31);
  4384. };
  4385. _proto.transpose = function transpose() {
  4386. var te = this.elements;
  4387. var tmp;
  4388. tmp = te[1];
  4389. te[1] = te[4];
  4390. te[4] = tmp;
  4391. tmp = te[2];
  4392. te[2] = te[8];
  4393. te[8] = tmp;
  4394. tmp = te[6];
  4395. te[6] = te[9];
  4396. te[9] = tmp;
  4397. tmp = te[3];
  4398. te[3] = te[12];
  4399. te[12] = tmp;
  4400. tmp = te[7];
  4401. te[7] = te[13];
  4402. te[13] = tmp;
  4403. tmp = te[11];
  4404. te[11] = te[14];
  4405. te[14] = tmp;
  4406. return this;
  4407. };
  4408. _proto.setPosition = function setPosition(x, y, z) {
  4409. var te = this.elements;
  4410. if (x.isVector3) {
  4411. te[12] = x.x;
  4412. te[13] = x.y;
  4413. te[14] = x.z;
  4414. } else {
  4415. te[12] = x;
  4416. te[13] = y;
  4417. te[14] = z;
  4418. }
  4419. return this;
  4420. };
  4421. _proto.invert = function invert() {
  4422. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  4423. var te = this.elements,
  4424. n11 = te[0],
  4425. n21 = te[1],
  4426. n31 = te[2],
  4427. n41 = te[3],
  4428. n12 = te[4],
  4429. n22 = te[5],
  4430. n32 = te[6],
  4431. n42 = te[7],
  4432. n13 = te[8],
  4433. n23 = te[9],
  4434. n33 = te[10],
  4435. n43 = te[11],
  4436. n14 = te[12],
  4437. n24 = te[13],
  4438. n34 = te[14],
  4439. n44 = te[15],
  4440. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  4441. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  4442. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  4443. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  4444. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  4445. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  4446. var detInv = 1 / det;
  4447. te[0] = t11 * detInv;
  4448. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  4449. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  4450. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  4451. te[4] = t12 * detInv;
  4452. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  4453. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  4454. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  4455. te[8] = t13 * detInv;
  4456. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  4457. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  4458. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  4459. te[12] = t14 * detInv;
  4460. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  4461. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  4462. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  4463. return this;
  4464. };
  4465. _proto.scale = function scale(v) {
  4466. var te = this.elements;
  4467. var x = v.x,
  4468. y = v.y,
  4469. z = v.z;
  4470. te[0] *= x;
  4471. te[4] *= y;
  4472. te[8] *= z;
  4473. te[1] *= x;
  4474. te[5] *= y;
  4475. te[9] *= z;
  4476. te[2] *= x;
  4477. te[6] *= y;
  4478. te[10] *= z;
  4479. te[3] *= x;
  4480. te[7] *= y;
  4481. te[11] *= z;
  4482. return this;
  4483. };
  4484. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  4485. var te = this.elements;
  4486. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  4487. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  4488. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  4489. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  4490. };
  4491. _proto.makeTranslation = function makeTranslation(x, y, z) {
  4492. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  4493. return this;
  4494. };
  4495. _proto.makeRotationX = function makeRotationX(theta) {
  4496. var c = Math.cos(theta),
  4497. s = Math.sin(theta);
  4498. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  4499. return this;
  4500. };
  4501. _proto.makeRotationY = function makeRotationY(theta) {
  4502. var c = Math.cos(theta),
  4503. s = Math.sin(theta);
  4504. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  4505. return this;
  4506. };
  4507. _proto.makeRotationZ = function makeRotationZ(theta) {
  4508. var c = Math.cos(theta),
  4509. s = Math.sin(theta);
  4510. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4511. return this;
  4512. };
  4513. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  4514. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4515. var c = Math.cos(angle);
  4516. var s = Math.sin(angle);
  4517. var t = 1 - c;
  4518. var x = axis.x,
  4519. y = axis.y,
  4520. z = axis.z;
  4521. var tx = t * x,
  4522. ty = t * y;
  4523. this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
  4524. return this;
  4525. };
  4526. _proto.makeScale = function makeScale(x, y, z) {
  4527. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  4528. return this;
  4529. };
  4530. _proto.makeShear = function makeShear(x, y, z) {
  4531. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  4532. return this;
  4533. };
  4534. _proto.compose = function compose(position, quaternion, scale) {
  4535. var te = this.elements;
  4536. var x = quaternion._x,
  4537. y = quaternion._y,
  4538. z = quaternion._z,
  4539. w = quaternion._w;
  4540. var x2 = x + x,
  4541. y2 = y + y,
  4542. z2 = z + z;
  4543. var xx = x * x2,
  4544. xy = x * y2,
  4545. xz = x * z2;
  4546. var yy = y * y2,
  4547. yz = y * z2,
  4548. zz = z * z2;
  4549. var wx = w * x2,
  4550. wy = w * y2,
  4551. wz = w * z2;
  4552. var sx = scale.x,
  4553. sy = scale.y,
  4554. sz = scale.z;
  4555. te[0] = (1 - (yy + zz)) * sx;
  4556. te[1] = (xy + wz) * sx;
  4557. te[2] = (xz - wy) * sx;
  4558. te[3] = 0;
  4559. te[4] = (xy - wz) * sy;
  4560. te[5] = (1 - (xx + zz)) * sy;
  4561. te[6] = (yz + wx) * sy;
  4562. te[7] = 0;
  4563. te[8] = (xz + wy) * sz;
  4564. te[9] = (yz - wx) * sz;
  4565. te[10] = (1 - (xx + yy)) * sz;
  4566. te[11] = 0;
  4567. te[12] = position.x;
  4568. te[13] = position.y;
  4569. te[14] = position.z;
  4570. te[15] = 1;
  4571. return this;
  4572. };
  4573. _proto.decompose = function decompose(position, quaternion, scale) {
  4574. var te = this.elements;
  4575. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  4576. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  4577. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  4578. var det = this.determinant();
  4579. if (det < 0) sx = -sx;
  4580. position.x = te[12];
  4581. position.y = te[13];
  4582. position.z = te[14]; // scale the rotation part
  4583. _m1.copy(this);
  4584. var invSX = 1 / sx;
  4585. var invSY = 1 / sy;
  4586. var invSZ = 1 / sz;
  4587. _m1.elements[0] *= invSX;
  4588. _m1.elements[1] *= invSX;
  4589. _m1.elements[2] *= invSX;
  4590. _m1.elements[4] *= invSY;
  4591. _m1.elements[5] *= invSY;
  4592. _m1.elements[6] *= invSY;
  4593. _m1.elements[8] *= invSZ;
  4594. _m1.elements[9] *= invSZ;
  4595. _m1.elements[10] *= invSZ;
  4596. quaternion.setFromRotationMatrix(_m1);
  4597. scale.x = sx;
  4598. scale.y = sy;
  4599. scale.z = sz;
  4600. return this;
  4601. };
  4602. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  4603. if (far === undefined) {
  4604. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  4605. }
  4606. var te = this.elements;
  4607. var x = 2 * near / (right - left);
  4608. var y = 2 * near / (top - bottom);
  4609. var a = (right + left) / (right - left);
  4610. var b = (top + bottom) / (top - bottom);
  4611. var c = -(far + near) / (far - near);
  4612. var d = -2 * far * near / (far - near);
  4613. te[0] = x;
  4614. te[4] = 0;
  4615. te[8] = a;
  4616. te[12] = 0;
  4617. te[1] = 0;
  4618. te[5] = y;
  4619. te[9] = b;
  4620. te[13] = 0;
  4621. te[2] = 0;
  4622. te[6] = 0;
  4623. te[10] = c;
  4624. te[14] = d;
  4625. te[3] = 0;
  4626. te[7] = 0;
  4627. te[11] = -1;
  4628. te[15] = 0;
  4629. return this;
  4630. };
  4631. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  4632. var te = this.elements;
  4633. var w = 1.0 / (right - left);
  4634. var h = 1.0 / (top - bottom);
  4635. var p = 1.0 / (far - near);
  4636. var x = (right + left) * w;
  4637. var y = (top + bottom) * h;
  4638. var z = (far + near) * p;
  4639. te[0] = 2 * w;
  4640. te[4] = 0;
  4641. te[8] = 0;
  4642. te[12] = -x;
  4643. te[1] = 0;
  4644. te[5] = 2 * h;
  4645. te[9] = 0;
  4646. te[13] = -y;
  4647. te[2] = 0;
  4648. te[6] = 0;
  4649. te[10] = -2 * p;
  4650. te[14] = -z;
  4651. te[3] = 0;
  4652. te[7] = 0;
  4653. te[11] = 0;
  4654. te[15] = 1;
  4655. return this;
  4656. };
  4657. _proto.equals = function equals(matrix) {
  4658. var te = this.elements;
  4659. var me = matrix.elements;
  4660. for (var i = 0; i < 16; i++) {
  4661. if (te[i] !== me[i]) return false;
  4662. }
  4663. return true;
  4664. };
  4665. _proto.fromArray = function fromArray(array, offset) {
  4666. if (offset === void 0) {
  4667. offset = 0;
  4668. }
  4669. for (var i = 0; i < 16; i++) {
  4670. this.elements[i] = array[i + offset];
  4671. }
  4672. return this;
  4673. };
  4674. _proto.toArray = function toArray(array, offset) {
  4675. if (array === void 0) {
  4676. array = [];
  4677. }
  4678. if (offset === void 0) {
  4679. offset = 0;
  4680. }
  4681. var te = this.elements;
  4682. array[offset] = te[0];
  4683. array[offset + 1] = te[1];
  4684. array[offset + 2] = te[2];
  4685. array[offset + 3] = te[3];
  4686. array[offset + 4] = te[4];
  4687. array[offset + 5] = te[5];
  4688. array[offset + 6] = te[6];
  4689. array[offset + 7] = te[7];
  4690. array[offset + 8] = te[8];
  4691. array[offset + 9] = te[9];
  4692. array[offset + 10] = te[10];
  4693. array[offset + 11] = te[11];
  4694. array[offset + 12] = te[12];
  4695. array[offset + 13] = te[13];
  4696. array[offset + 14] = te[14];
  4697. array[offset + 15] = te[15];
  4698. return array;
  4699. };
  4700. return Matrix4;
  4701. }();
  4702. Matrix4.prototype.isMatrix4 = true;
  4703. var _v1$1 = /*@__PURE__*/new Vector3();
  4704. var _m1 = /*@__PURE__*/new Matrix4();
  4705. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4706. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4707. var _x = /*@__PURE__*/new Vector3();
  4708. var _y = /*@__PURE__*/new Vector3();
  4709. var _z = /*@__PURE__*/new Vector3();
  4710. var _matrix = /*@__PURE__*/new Matrix4();
  4711. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4712. var Euler = /*#__PURE__*/function () {
  4713. function Euler(x, y, z, order) {
  4714. if (x === void 0) {
  4715. x = 0;
  4716. }
  4717. if (y === void 0) {
  4718. y = 0;
  4719. }
  4720. if (z === void 0) {
  4721. z = 0;
  4722. }
  4723. if (order === void 0) {
  4724. order = Euler.DefaultOrder;
  4725. }
  4726. this._x = x;
  4727. this._y = y;
  4728. this._z = z;
  4729. this._order = order;
  4730. }
  4731. var _proto = Euler.prototype;
  4732. _proto.set = function set(x, y, z, order) {
  4733. this._x = x;
  4734. this._y = y;
  4735. this._z = z;
  4736. this._order = order || this._order;
  4737. this._onChangeCallback();
  4738. return this;
  4739. };
  4740. _proto.clone = function clone() {
  4741. return new this.constructor(this._x, this._y, this._z, this._order);
  4742. };
  4743. _proto.copy = function copy(euler) {
  4744. this._x = euler._x;
  4745. this._y = euler._y;
  4746. this._z = euler._z;
  4747. this._order = euler._order;
  4748. this._onChangeCallback();
  4749. return this;
  4750. };
  4751. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4752. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4753. var te = m.elements;
  4754. var m11 = te[0],
  4755. m12 = te[4],
  4756. m13 = te[8];
  4757. var m21 = te[1],
  4758. m22 = te[5],
  4759. m23 = te[9];
  4760. var m31 = te[2],
  4761. m32 = te[6],
  4762. m33 = te[10];
  4763. order = order || this._order;
  4764. switch (order) {
  4765. case 'XYZ':
  4766. this._y = Math.asin(clamp(m13, -1, 1));
  4767. if (Math.abs(m13) < 0.9999999) {
  4768. this._x = Math.atan2(-m23, m33);
  4769. this._z = Math.atan2(-m12, m11);
  4770. } else {
  4771. this._x = Math.atan2(m32, m22);
  4772. this._z = 0;
  4773. }
  4774. break;
  4775. case 'YXZ':
  4776. this._x = Math.asin(-clamp(m23, -1, 1));
  4777. if (Math.abs(m23) < 0.9999999) {
  4778. this._y = Math.atan2(m13, m33);
  4779. this._z = Math.atan2(m21, m22);
  4780. } else {
  4781. this._y = Math.atan2(-m31, m11);
  4782. this._z = 0;
  4783. }
  4784. break;
  4785. case 'ZXY':
  4786. this._x = Math.asin(clamp(m32, -1, 1));
  4787. if (Math.abs(m32) < 0.9999999) {
  4788. this._y = Math.atan2(-m31, m33);
  4789. this._z = Math.atan2(-m12, m22);
  4790. } else {
  4791. this._y = 0;
  4792. this._z = Math.atan2(m21, m11);
  4793. }
  4794. break;
  4795. case 'ZYX':
  4796. this._y = Math.asin(-clamp(m31, -1, 1));
  4797. if (Math.abs(m31) < 0.9999999) {
  4798. this._x = Math.atan2(m32, m33);
  4799. this._z = Math.atan2(m21, m11);
  4800. } else {
  4801. this._x = 0;
  4802. this._z = Math.atan2(-m12, m22);
  4803. }
  4804. break;
  4805. case 'YZX':
  4806. this._z = Math.asin(clamp(m21, -1, 1));
  4807. if (Math.abs(m21) < 0.9999999) {
  4808. this._x = Math.atan2(-m23, m22);
  4809. this._y = Math.atan2(-m31, m11);
  4810. } else {
  4811. this._x = 0;
  4812. this._y = Math.atan2(m13, m33);
  4813. }
  4814. break;
  4815. case 'XZY':
  4816. this._z = Math.asin(-clamp(m12, -1, 1));
  4817. if (Math.abs(m12) < 0.9999999) {
  4818. this._x = Math.atan2(m32, m22);
  4819. this._y = Math.atan2(m13, m11);
  4820. } else {
  4821. this._x = Math.atan2(-m23, m33);
  4822. this._y = 0;
  4823. }
  4824. break;
  4825. default:
  4826. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4827. }
  4828. this._order = order;
  4829. if (update !== false) this._onChangeCallback();
  4830. return this;
  4831. };
  4832. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4833. _matrix.makeRotationFromQuaternion(q);
  4834. return this.setFromRotationMatrix(_matrix, order, update);
  4835. };
  4836. _proto.setFromVector3 = function setFromVector3(v, order) {
  4837. return this.set(v.x, v.y, v.z, order || this._order);
  4838. };
  4839. _proto.reorder = function reorder(newOrder) {
  4840. // WARNING: this discards revolution information -bhouston
  4841. _quaternion$1.setFromEuler(this);
  4842. return this.setFromQuaternion(_quaternion$1, newOrder);
  4843. };
  4844. _proto.equals = function equals(euler) {
  4845. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4846. };
  4847. _proto.fromArray = function fromArray(array) {
  4848. this._x = array[0];
  4849. this._y = array[1];
  4850. this._z = array[2];
  4851. if (array[3] !== undefined) this._order = array[3];
  4852. this._onChangeCallback();
  4853. return this;
  4854. };
  4855. _proto.toArray = function toArray(array, offset) {
  4856. if (array === void 0) {
  4857. array = [];
  4858. }
  4859. if (offset === void 0) {
  4860. offset = 0;
  4861. }
  4862. array[offset] = this._x;
  4863. array[offset + 1] = this._y;
  4864. array[offset + 2] = this._z;
  4865. array[offset + 3] = this._order;
  4866. return array;
  4867. };
  4868. _proto.toVector3 = function toVector3(optionalResult) {
  4869. if (optionalResult) {
  4870. return optionalResult.set(this._x, this._y, this._z);
  4871. } else {
  4872. return new Vector3(this._x, this._y, this._z);
  4873. }
  4874. };
  4875. _proto._onChange = function _onChange(callback) {
  4876. this._onChangeCallback = callback;
  4877. return this;
  4878. };
  4879. _proto._onChangeCallback = function _onChangeCallback() {};
  4880. _createClass(Euler, [{
  4881. key: "x",
  4882. get: function get() {
  4883. return this._x;
  4884. },
  4885. set: function set(value) {
  4886. this._x = value;
  4887. this._onChangeCallback();
  4888. }
  4889. }, {
  4890. key: "y",
  4891. get: function get() {
  4892. return this._y;
  4893. },
  4894. set: function set(value) {
  4895. this._y = value;
  4896. this._onChangeCallback();
  4897. }
  4898. }, {
  4899. key: "z",
  4900. get: function get() {
  4901. return this._z;
  4902. },
  4903. set: function set(value) {
  4904. this._z = value;
  4905. this._onChangeCallback();
  4906. }
  4907. }, {
  4908. key: "order",
  4909. get: function get() {
  4910. return this._order;
  4911. },
  4912. set: function set(value) {
  4913. this._order = value;
  4914. this._onChangeCallback();
  4915. }
  4916. }]);
  4917. return Euler;
  4918. }();
  4919. Euler.prototype.isEuler = true;
  4920. Euler.DefaultOrder = 'XYZ';
  4921. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4922. var Layers = /*#__PURE__*/function () {
  4923. function Layers() {
  4924. this.mask = 1 | 0;
  4925. }
  4926. var _proto = Layers.prototype;
  4927. _proto.set = function set(channel) {
  4928. this.mask = 1 << channel | 0;
  4929. };
  4930. _proto.enable = function enable(channel) {
  4931. this.mask |= 1 << channel | 0;
  4932. };
  4933. _proto.enableAll = function enableAll() {
  4934. this.mask = 0xffffffff | 0;
  4935. };
  4936. _proto.toggle = function toggle(channel) {
  4937. this.mask ^= 1 << channel | 0;
  4938. };
  4939. _proto.disable = function disable(channel) {
  4940. this.mask &= ~(1 << channel | 0);
  4941. };
  4942. _proto.disableAll = function disableAll() {
  4943. this.mask = 0;
  4944. };
  4945. _proto.test = function test(layers) {
  4946. return (this.mask & layers.mask) !== 0;
  4947. };
  4948. return Layers;
  4949. }();
  4950. var _object3DId = 0;
  4951. var _v1$2 = new Vector3();
  4952. var _q1 = new Quaternion();
  4953. var _m1$1 = new Matrix4();
  4954. var _target = new Vector3();
  4955. var _position = new Vector3();
  4956. var _scale = new Vector3();
  4957. var _quaternion$2 = new Quaternion();
  4958. var _xAxis = new Vector3(1, 0, 0);
  4959. var _yAxis = new Vector3(0, 1, 0);
  4960. var _zAxis = new Vector3(0, 0, 1);
  4961. var _addedEvent = {
  4962. type: 'added'
  4963. };
  4964. var _removedEvent = {
  4965. type: 'removed'
  4966. };
  4967. function Object3D() {
  4968. Object.defineProperty(this, 'id', {
  4969. value: _object3DId++
  4970. });
  4971. this.uuid = MathUtils.generateUUID();
  4972. this.name = '';
  4973. this.type = 'Object3D';
  4974. this.parent = null;
  4975. this.children = [];
  4976. this.up = Object3D.DefaultUp.clone();
  4977. var position = new Vector3();
  4978. var rotation = new Euler();
  4979. var quaternion = new Quaternion();
  4980. var scale = new Vector3(1, 1, 1);
  4981. function onRotationChange() {
  4982. quaternion.setFromEuler(rotation, false);
  4983. }
  4984. function onQuaternionChange() {
  4985. rotation.setFromQuaternion(quaternion, undefined, false);
  4986. }
  4987. rotation._onChange(onRotationChange);
  4988. quaternion._onChange(onQuaternionChange);
  4989. Object.defineProperties(this, {
  4990. position: {
  4991. configurable: true,
  4992. enumerable: true,
  4993. value: position
  4994. },
  4995. rotation: {
  4996. configurable: true,
  4997. enumerable: true,
  4998. value: rotation
  4999. },
  5000. quaternion: {
  5001. configurable: true,
  5002. enumerable: true,
  5003. value: quaternion
  5004. },
  5005. scale: {
  5006. configurable: true,
  5007. enumerable: true,
  5008. value: scale
  5009. },
  5010. modelViewMatrix: {
  5011. value: new Matrix4()
  5012. },
  5013. normalMatrix: {
  5014. value: new Matrix3()
  5015. }
  5016. });
  5017. this.matrix = new Matrix4();
  5018. this.matrixWorld = new Matrix4();
  5019. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5020. this.matrixWorldNeedsUpdate = false;
  5021. this.layers = new Layers();
  5022. this.visible = true;
  5023. this.castShadow = false;
  5024. this.receiveShadow = false;
  5025. this.frustumCulled = true;
  5026. this.renderOrder = 0;
  5027. this.animations = [];
  5028. this.userData = {};
  5029. }
  5030. Object3D.DefaultUp = new Vector3(0, 1, 0);
  5031. Object3D.DefaultMatrixAutoUpdate = true;
  5032. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5033. constructor: Object3D,
  5034. isObject3D: true,
  5035. onBeforeRender: function onBeforeRender() {},
  5036. onAfterRender: function onAfterRender() {},
  5037. applyMatrix4: function applyMatrix4(matrix) {
  5038. if (this.matrixAutoUpdate) this.updateMatrix();
  5039. this.matrix.premultiply(matrix);
  5040. this.matrix.decompose(this.position, this.quaternion, this.scale);
  5041. },
  5042. applyQuaternion: function applyQuaternion(q) {
  5043. this.quaternion.premultiply(q);
  5044. return this;
  5045. },
  5046. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  5047. // assumes axis is normalized
  5048. this.quaternion.setFromAxisAngle(axis, angle);
  5049. },
  5050. setRotationFromEuler: function setRotationFromEuler(euler) {
  5051. this.quaternion.setFromEuler(euler, true);
  5052. },
  5053. setRotationFromMatrix: function setRotationFromMatrix(m) {
  5054. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5055. this.quaternion.setFromRotationMatrix(m);
  5056. },
  5057. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  5058. // assumes q is normalized
  5059. this.quaternion.copy(q);
  5060. },
  5061. rotateOnAxis: function rotateOnAxis(axis, angle) {
  5062. // rotate object on axis in object space
  5063. // axis is assumed to be normalized
  5064. _q1.setFromAxisAngle(axis, angle);
  5065. this.quaternion.multiply(_q1);
  5066. return this;
  5067. },
  5068. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  5069. // rotate object on axis in world space
  5070. // axis is assumed to be normalized
  5071. // method assumes no rotated parent
  5072. _q1.setFromAxisAngle(axis, angle);
  5073. this.quaternion.premultiply(_q1);
  5074. return this;
  5075. },
  5076. rotateX: function rotateX(angle) {
  5077. return this.rotateOnAxis(_xAxis, angle);
  5078. },
  5079. rotateY: function rotateY(angle) {
  5080. return this.rotateOnAxis(_yAxis, angle);
  5081. },
  5082. rotateZ: function rotateZ(angle) {
  5083. return this.rotateOnAxis(_zAxis, angle);
  5084. },
  5085. translateOnAxis: function translateOnAxis(axis, distance) {
  5086. // translate object by distance along axis in object space
  5087. // axis is assumed to be normalized
  5088. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  5089. this.position.add(_v1$2.multiplyScalar(distance));
  5090. return this;
  5091. },
  5092. translateX: function translateX(distance) {
  5093. return this.translateOnAxis(_xAxis, distance);
  5094. },
  5095. translateY: function translateY(distance) {
  5096. return this.translateOnAxis(_yAxis, distance);
  5097. },
  5098. translateZ: function translateZ(distance) {
  5099. return this.translateOnAxis(_zAxis, distance);
  5100. },
  5101. localToWorld: function localToWorld(vector) {
  5102. return vector.applyMatrix4(this.matrixWorld);
  5103. },
  5104. worldToLocal: function worldToLocal(vector) {
  5105. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  5106. },
  5107. lookAt: function lookAt(x, y, z) {
  5108. // This method does not support objects having non-uniformly-scaled parent(s)
  5109. if (x.isVector3) {
  5110. _target.copy(x);
  5111. } else {
  5112. _target.set(x, y, z);
  5113. }
  5114. var parent = this.parent;
  5115. this.updateWorldMatrix(true, false);
  5116. _position.setFromMatrixPosition(this.matrixWorld);
  5117. if (this.isCamera || this.isLight) {
  5118. _m1$1.lookAt(_position, _target, this.up);
  5119. } else {
  5120. _m1$1.lookAt(_target, _position, this.up);
  5121. }
  5122. this.quaternion.setFromRotationMatrix(_m1$1);
  5123. if (parent) {
  5124. _m1$1.extractRotation(parent.matrixWorld);
  5125. _q1.setFromRotationMatrix(_m1$1);
  5126. this.quaternion.premultiply(_q1.invert());
  5127. }
  5128. },
  5129. add: function add(object) {
  5130. if (arguments.length > 1) {
  5131. for (var i = 0; i < arguments.length; i++) {
  5132. this.add(arguments[i]);
  5133. }
  5134. return this;
  5135. }
  5136. if (object === this) {
  5137. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  5138. return this;
  5139. }
  5140. if (object && object.isObject3D) {
  5141. if (object.parent !== null) {
  5142. object.parent.remove(object);
  5143. }
  5144. object.parent = this;
  5145. this.children.push(object);
  5146. object.dispatchEvent(_addedEvent);
  5147. } else {
  5148. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  5149. }
  5150. return this;
  5151. },
  5152. remove: function remove(object) {
  5153. if (arguments.length > 1) {
  5154. for (var i = 0; i < arguments.length; i++) {
  5155. this.remove(arguments[i]);
  5156. }
  5157. return this;
  5158. }
  5159. var index = this.children.indexOf(object);
  5160. if (index !== -1) {
  5161. object.parent = null;
  5162. this.children.splice(index, 1);
  5163. object.dispatchEvent(_removedEvent);
  5164. }
  5165. return this;
  5166. },
  5167. clear: function clear() {
  5168. for (var i = 0; i < this.children.length; i++) {
  5169. var object = this.children[i];
  5170. object.parent = null;
  5171. object.dispatchEvent(_removedEvent);
  5172. }
  5173. this.children.length = 0;
  5174. return this;
  5175. },
  5176. attach: function attach(object) {
  5177. // adds object as a child of this, while maintaining the object's world transform
  5178. this.updateWorldMatrix(true, false);
  5179. _m1$1.copy(this.matrixWorld).invert();
  5180. if (object.parent !== null) {
  5181. object.parent.updateWorldMatrix(true, false);
  5182. _m1$1.multiply(object.parent.matrixWorld);
  5183. }
  5184. object.applyMatrix4(_m1$1);
  5185. this.add(object);
  5186. object.updateWorldMatrix(false, true);
  5187. return this;
  5188. },
  5189. getObjectById: function getObjectById(id) {
  5190. return this.getObjectByProperty('id', id);
  5191. },
  5192. getObjectByName: function getObjectByName(name) {
  5193. return this.getObjectByProperty('name', name);
  5194. },
  5195. getObjectByProperty: function getObjectByProperty(name, value) {
  5196. if (this[name] === value) return this;
  5197. for (var i = 0, l = this.children.length; i < l; i++) {
  5198. var child = this.children[i];
  5199. var object = child.getObjectByProperty(name, value);
  5200. if (object !== undefined) {
  5201. return object;
  5202. }
  5203. }
  5204. return undefined;
  5205. },
  5206. getWorldPosition: function getWorldPosition(target) {
  5207. if (target === undefined) {
  5208. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  5209. target = new Vector3();
  5210. }
  5211. this.updateWorldMatrix(true, false);
  5212. return target.setFromMatrixPosition(this.matrixWorld);
  5213. },
  5214. getWorldQuaternion: function getWorldQuaternion(target) {
  5215. if (target === undefined) {
  5216. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  5217. target = new Quaternion();
  5218. }
  5219. this.updateWorldMatrix(true, false);
  5220. this.matrixWorld.decompose(_position, target, _scale);
  5221. return target;
  5222. },
  5223. getWorldScale: function getWorldScale(target) {
  5224. if (target === undefined) {
  5225. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  5226. target = new Vector3();
  5227. }
  5228. this.updateWorldMatrix(true, false);
  5229. this.matrixWorld.decompose(_position, _quaternion$2, target);
  5230. return target;
  5231. },
  5232. getWorldDirection: function getWorldDirection(target) {
  5233. if (target === undefined) {
  5234. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  5235. target = new Vector3();
  5236. }
  5237. this.updateWorldMatrix(true, false);
  5238. var e = this.matrixWorld.elements;
  5239. return target.set(e[8], e[9], e[10]).normalize();
  5240. },
  5241. raycast: function raycast() {},
  5242. traverse: function traverse(callback) {
  5243. callback(this);
  5244. var children = this.children;
  5245. for (var i = 0, l = children.length; i < l; i++) {
  5246. children[i].traverse(callback);
  5247. }
  5248. },
  5249. traverseVisible: function traverseVisible(callback) {
  5250. if (this.visible === false) return;
  5251. callback(this);
  5252. var children = this.children;
  5253. for (var i = 0, l = children.length; i < l; i++) {
  5254. children[i].traverseVisible(callback);
  5255. }
  5256. },
  5257. traverseAncestors: function traverseAncestors(callback) {
  5258. var parent = this.parent;
  5259. if (parent !== null) {
  5260. callback(parent);
  5261. parent.traverseAncestors(callback);
  5262. }
  5263. },
  5264. updateMatrix: function updateMatrix() {
  5265. this.matrix.compose(this.position, this.quaternion, this.scale);
  5266. this.matrixWorldNeedsUpdate = true;
  5267. },
  5268. updateMatrixWorld: function updateMatrixWorld(force) {
  5269. if (this.matrixAutoUpdate) this.updateMatrix();
  5270. if (this.matrixWorldNeedsUpdate || force) {
  5271. if (this.parent === null) {
  5272. this.matrixWorld.copy(this.matrix);
  5273. } else {
  5274. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5275. }
  5276. this.matrixWorldNeedsUpdate = false;
  5277. force = true;
  5278. } // update children
  5279. var children = this.children;
  5280. for (var i = 0, l = children.length; i < l; i++) {
  5281. children[i].updateMatrixWorld(force);
  5282. }
  5283. },
  5284. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  5285. var parent = this.parent;
  5286. if (updateParents === true && parent !== null) {
  5287. parent.updateWorldMatrix(true, false);
  5288. }
  5289. if (this.matrixAutoUpdate) this.updateMatrix();
  5290. if (this.parent === null) {
  5291. this.matrixWorld.copy(this.matrix);
  5292. } else {
  5293. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5294. } // update children
  5295. if (updateChildren === true) {
  5296. var children = this.children;
  5297. for (var i = 0, l = children.length; i < l; i++) {
  5298. children[i].updateWorldMatrix(false, true);
  5299. }
  5300. }
  5301. },
  5302. toJSON: function toJSON(meta) {
  5303. // meta is a string when called from JSON.stringify
  5304. var isRootObject = meta === undefined || typeof meta === 'string';
  5305. var output = {}; // meta is a hash used to collect geometries, materials.
  5306. // not providing it implies that this is the root object
  5307. // being serialized.
  5308. if (isRootObject) {
  5309. // initialize meta obj
  5310. meta = {
  5311. geometries: {},
  5312. materials: {},
  5313. textures: {},
  5314. images: {},
  5315. shapes: {},
  5316. skeletons: {},
  5317. animations: {}
  5318. };
  5319. output.metadata = {
  5320. version: 4.5,
  5321. type: 'Object',
  5322. generator: 'Object3D.toJSON'
  5323. };
  5324. } // standard Object3D serialization
  5325. var object = {};
  5326. object.uuid = this.uuid;
  5327. object.type = this.type;
  5328. if (this.name !== '') object.name = this.name;
  5329. if (this.castShadow === true) object.castShadow = true;
  5330. if (this.receiveShadow === true) object.receiveShadow = true;
  5331. if (this.visible === false) object.visible = false;
  5332. if (this.frustumCulled === false) object.frustumCulled = false;
  5333. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  5334. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  5335. object.layers = this.layers.mask;
  5336. object.matrix = this.matrix.toArray();
  5337. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  5338. if (this.isInstancedMesh) {
  5339. object.type = 'InstancedMesh';
  5340. object.count = this.count;
  5341. object.instanceMatrix = this.instanceMatrix.toJSON();
  5342. } //
  5343. function serialize(library, element) {
  5344. if (library[element.uuid] === undefined) {
  5345. library[element.uuid] = element.toJSON(meta);
  5346. }
  5347. return element.uuid;
  5348. }
  5349. if (this.isMesh || this.isLine || this.isPoints) {
  5350. object.geometry = serialize(meta.geometries, this.geometry);
  5351. var parameters = this.geometry.parameters;
  5352. if (parameters !== undefined && parameters.shapes !== undefined) {
  5353. var shapes = parameters.shapes;
  5354. if (Array.isArray(shapes)) {
  5355. for (var i = 0, l = shapes.length; i < l; i++) {
  5356. var shape = shapes[i];
  5357. serialize(meta.shapes, shape);
  5358. }
  5359. } else {
  5360. serialize(meta.shapes, shapes);
  5361. }
  5362. }
  5363. }
  5364. if (this.isSkinnedMesh) {
  5365. object.bindMode = this.bindMode;
  5366. object.bindMatrix = this.bindMatrix.toArray();
  5367. if (this.skeleton !== undefined) {
  5368. serialize(meta.skeletons, this.skeleton);
  5369. object.skeleton = this.skeleton.uuid;
  5370. }
  5371. }
  5372. if (this.material !== undefined) {
  5373. if (Array.isArray(this.material)) {
  5374. var uuids = [];
  5375. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  5376. uuids.push(serialize(meta.materials, this.material[_i]));
  5377. }
  5378. object.material = uuids;
  5379. } else {
  5380. object.material = serialize(meta.materials, this.material);
  5381. }
  5382. } //
  5383. if (this.children.length > 0) {
  5384. object.children = [];
  5385. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  5386. object.children.push(this.children[_i2].toJSON(meta).object);
  5387. }
  5388. } //
  5389. if (this.animations.length > 0) {
  5390. object.animations = [];
  5391. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  5392. var animation = this.animations[_i3];
  5393. object.animations.push(serialize(meta.animations, animation));
  5394. }
  5395. }
  5396. if (isRootObject) {
  5397. var geometries = extractFromCache(meta.geometries);
  5398. var materials = extractFromCache(meta.materials);
  5399. var textures = extractFromCache(meta.textures);
  5400. var images = extractFromCache(meta.images);
  5401. var _shapes = extractFromCache(meta.shapes);
  5402. var skeletons = extractFromCache(meta.skeletons);
  5403. var animations = extractFromCache(meta.animations);
  5404. if (geometries.length > 0) output.geometries = geometries;
  5405. if (materials.length > 0) output.materials = materials;
  5406. if (textures.length > 0) output.textures = textures;
  5407. if (images.length > 0) output.images = images;
  5408. if (_shapes.length > 0) output.shapes = _shapes;
  5409. if (skeletons.length > 0) output.skeletons = skeletons;
  5410. if (animations.length > 0) output.animations = animations;
  5411. }
  5412. output.object = object;
  5413. return output; // extract data from the cache hash
  5414. // remove metadata on each item
  5415. // and return as array
  5416. function extractFromCache(cache) {
  5417. var values = [];
  5418. for (var key in cache) {
  5419. var data = cache[key];
  5420. delete data.metadata;
  5421. values.push(data);
  5422. }
  5423. return values;
  5424. }
  5425. },
  5426. clone: function clone(recursive) {
  5427. return new this.constructor().copy(this, recursive);
  5428. },
  5429. copy: function copy(source, recursive) {
  5430. if (recursive === void 0) {
  5431. recursive = true;
  5432. }
  5433. this.name = source.name;
  5434. this.up.copy(source.up);
  5435. this.position.copy(source.position);
  5436. this.rotation.order = source.rotation.order;
  5437. this.quaternion.copy(source.quaternion);
  5438. this.scale.copy(source.scale);
  5439. this.matrix.copy(source.matrix);
  5440. this.matrixWorld.copy(source.matrixWorld);
  5441. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5442. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5443. this.layers.mask = source.layers.mask;
  5444. this.visible = source.visible;
  5445. this.castShadow = source.castShadow;
  5446. this.receiveShadow = source.receiveShadow;
  5447. this.frustumCulled = source.frustumCulled;
  5448. this.renderOrder = source.renderOrder;
  5449. this.userData = JSON.parse(JSON.stringify(source.userData));
  5450. if (recursive === true) {
  5451. for (var i = 0; i < source.children.length; i++) {
  5452. var child = source.children[i];
  5453. this.add(child.clone());
  5454. }
  5455. }
  5456. return this;
  5457. }
  5458. });
  5459. var _vector1 = /*@__PURE__*/new Vector3();
  5460. var _vector2 = /*@__PURE__*/new Vector3();
  5461. var _normalMatrix = /*@__PURE__*/new Matrix3();
  5462. var Plane = /*#__PURE__*/function () {
  5463. function Plane(normal, constant) {
  5464. if (normal === void 0) {
  5465. normal = new Vector3(1, 0, 0);
  5466. }
  5467. if (constant === void 0) {
  5468. constant = 0;
  5469. }
  5470. // normal is assumed to be normalized
  5471. this.normal = normal;
  5472. this.constant = constant;
  5473. }
  5474. var _proto = Plane.prototype;
  5475. _proto.set = function set(normal, constant) {
  5476. this.normal.copy(normal);
  5477. this.constant = constant;
  5478. return this;
  5479. };
  5480. _proto.setComponents = function setComponents(x, y, z, w) {
  5481. this.normal.set(x, y, z);
  5482. this.constant = w;
  5483. return this;
  5484. };
  5485. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  5486. this.normal.copy(normal);
  5487. this.constant = -point.dot(this.normal);
  5488. return this;
  5489. };
  5490. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  5491. var normal = _vector1.subVectors(c, b).cross(_vector2.subVectors(a, b)).normalize(); // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  5492. this.setFromNormalAndCoplanarPoint(normal, a);
  5493. return this;
  5494. };
  5495. _proto.copy = function copy(plane) {
  5496. this.normal.copy(plane.normal);
  5497. this.constant = plane.constant;
  5498. return this;
  5499. };
  5500. _proto.normalize = function normalize() {
  5501. // Note: will lead to a divide by zero if the plane is invalid.
  5502. var inverseNormalLength = 1.0 / this.normal.length();
  5503. this.normal.multiplyScalar(inverseNormalLength);
  5504. this.constant *= inverseNormalLength;
  5505. return this;
  5506. };
  5507. _proto.negate = function negate() {
  5508. this.constant *= -1;
  5509. this.normal.negate();
  5510. return this;
  5511. };
  5512. _proto.distanceToPoint = function distanceToPoint(point) {
  5513. return this.normal.dot(point) + this.constant;
  5514. };
  5515. _proto.distanceToSphere = function distanceToSphere(sphere) {
  5516. return this.distanceToPoint(sphere.center) - sphere.radius;
  5517. };
  5518. _proto.projectPoint = function projectPoint(point, target) {
  5519. if (target === undefined) {
  5520. console.warn('THREE.Plane: .projectPoint() target is now required');
  5521. target = new Vector3();
  5522. }
  5523. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  5524. };
  5525. _proto.intersectLine = function intersectLine(line, target) {
  5526. if (target === undefined) {
  5527. console.warn('THREE.Plane: .intersectLine() target is now required');
  5528. target = new Vector3();
  5529. }
  5530. var direction = line.delta(_vector1);
  5531. var denominator = this.normal.dot(direction);
  5532. if (denominator === 0) {
  5533. // line is coplanar, return origin
  5534. if (this.distanceToPoint(line.start) === 0) {
  5535. return target.copy(line.start);
  5536. } // Unsure if this is the correct method to handle this case.
  5537. return undefined;
  5538. }
  5539. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  5540. if (t < 0 || t > 1) {
  5541. return undefined;
  5542. }
  5543. return target.copy(direction).multiplyScalar(t).add(line.start);
  5544. };
  5545. _proto.intersectsLine = function intersectsLine(line) {
  5546. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5547. var startSign = this.distanceToPoint(line.start);
  5548. var endSign = this.distanceToPoint(line.end);
  5549. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  5550. };
  5551. _proto.intersectsBox = function intersectsBox(box) {
  5552. return box.intersectsPlane(this);
  5553. };
  5554. _proto.intersectsSphere = function intersectsSphere(sphere) {
  5555. return sphere.intersectsPlane(this);
  5556. };
  5557. _proto.coplanarPoint = function coplanarPoint(target) {
  5558. if (target === undefined) {
  5559. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  5560. target = new Vector3();
  5561. }
  5562. return target.copy(this.normal).multiplyScalar(-this.constant);
  5563. };
  5564. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  5565. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  5566. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  5567. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  5568. this.constant = -referencePoint.dot(normal);
  5569. return this;
  5570. };
  5571. _proto.translate = function translate(offset) {
  5572. this.constant -= offset.dot(this.normal);
  5573. return this;
  5574. };
  5575. _proto.equals = function equals(plane) {
  5576. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  5577. };
  5578. _proto.clone = function clone() {
  5579. return new this.constructor().copy(this);
  5580. };
  5581. return Plane;
  5582. }();
  5583. Plane.prototype.isPlane = true;
  5584. var _v0$1 = /*@__PURE__*/new Vector3();
  5585. var _v1$3 = /*@__PURE__*/new Vector3();
  5586. var _v2$1 = /*@__PURE__*/new Vector3();
  5587. var _v3 = /*@__PURE__*/new Vector3();
  5588. var _vab = /*@__PURE__*/new Vector3();
  5589. var _vac = /*@__PURE__*/new Vector3();
  5590. var _vbc = /*@__PURE__*/new Vector3();
  5591. var _vap = /*@__PURE__*/new Vector3();
  5592. var _vbp = /*@__PURE__*/new Vector3();
  5593. var _vcp = /*@__PURE__*/new Vector3();
  5594. var Triangle = /*#__PURE__*/function () {
  5595. function Triangle(a, b, c) {
  5596. if (a === void 0) {
  5597. a = new Vector3();
  5598. }
  5599. if (b === void 0) {
  5600. b = new Vector3();
  5601. }
  5602. if (c === void 0) {
  5603. c = new Vector3();
  5604. }
  5605. this.a = a;
  5606. this.b = b;
  5607. this.c = c;
  5608. }
  5609. Triangle.getNormal = function getNormal(a, b, c, target) {
  5610. if (target === undefined) {
  5611. console.warn('THREE.Triangle: .getNormal() target is now required');
  5612. target = new Vector3();
  5613. }
  5614. target.subVectors(c, b);
  5615. _v0$1.subVectors(a, b);
  5616. target.cross(_v0$1);
  5617. var targetLengthSq = target.lengthSq();
  5618. if (targetLengthSq > 0) {
  5619. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  5620. }
  5621. return target.set(0, 0, 0);
  5622. } // static/instance method to calculate barycentric coordinates
  5623. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  5624. ;
  5625. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  5626. _v0$1.subVectors(c, a);
  5627. _v1$3.subVectors(b, a);
  5628. _v2$1.subVectors(point, a);
  5629. var dot00 = _v0$1.dot(_v0$1);
  5630. var dot01 = _v0$1.dot(_v1$3);
  5631. var dot02 = _v0$1.dot(_v2$1);
  5632. var dot11 = _v1$3.dot(_v1$3);
  5633. var dot12 = _v1$3.dot(_v2$1);
  5634. var denom = dot00 * dot11 - dot01 * dot01;
  5635. if (target === undefined) {
  5636. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  5637. target = new Vector3();
  5638. } // collinear or singular triangle
  5639. if (denom === 0) {
  5640. // arbitrary location outside of triangle?
  5641. // not sure if this is the best idea, maybe should be returning undefined
  5642. return target.set(-2, -1, -1);
  5643. }
  5644. var invDenom = 1 / denom;
  5645. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  5646. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  5647. return target.set(1 - u - v, v, u);
  5648. };
  5649. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  5650. this.getBarycoord(point, a, b, c, _v3);
  5651. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  5652. };
  5653. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  5654. this.getBarycoord(point, p1, p2, p3, _v3);
  5655. target.set(0, 0);
  5656. target.addScaledVector(uv1, _v3.x);
  5657. target.addScaledVector(uv2, _v3.y);
  5658. target.addScaledVector(uv3, _v3.z);
  5659. return target;
  5660. };
  5661. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  5662. _v0$1.subVectors(c, b);
  5663. _v1$3.subVectors(a, b); // strictly front facing
  5664. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  5665. };
  5666. var _proto = Triangle.prototype;
  5667. _proto.set = function set(a, b, c) {
  5668. this.a.copy(a);
  5669. this.b.copy(b);
  5670. this.c.copy(c);
  5671. return this;
  5672. };
  5673. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  5674. this.a.copy(points[i0]);
  5675. this.b.copy(points[i1]);
  5676. this.c.copy(points[i2]);
  5677. return this;
  5678. };
  5679. _proto.clone = function clone() {
  5680. return new this.constructor().copy(this);
  5681. };
  5682. _proto.copy = function copy(triangle) {
  5683. this.a.copy(triangle.a);
  5684. this.b.copy(triangle.b);
  5685. this.c.copy(triangle.c);
  5686. return this;
  5687. };
  5688. _proto.getArea = function getArea() {
  5689. _v0$1.subVectors(this.c, this.b);
  5690. _v1$3.subVectors(this.a, this.b);
  5691. return _v0$1.cross(_v1$3).length() * 0.5;
  5692. };
  5693. _proto.getMidpoint = function getMidpoint(target) {
  5694. if (target === undefined) {
  5695. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  5696. target = new Vector3();
  5697. }
  5698. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5699. };
  5700. _proto.getNormal = function getNormal(target) {
  5701. return Triangle.getNormal(this.a, this.b, this.c, target);
  5702. };
  5703. _proto.getPlane = function getPlane(target) {
  5704. if (target === undefined) {
  5705. console.warn('THREE.Triangle: .getPlane() target is now required');
  5706. target = new Plane();
  5707. }
  5708. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5709. };
  5710. _proto.getBarycoord = function getBarycoord(point, target) {
  5711. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5712. };
  5713. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5714. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5715. };
  5716. _proto.containsPoint = function containsPoint(point) {
  5717. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5718. };
  5719. _proto.isFrontFacing = function isFrontFacing(direction) {
  5720. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5721. };
  5722. _proto.intersectsBox = function intersectsBox(box) {
  5723. return box.intersectsTriangle(this);
  5724. };
  5725. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5726. if (target === undefined) {
  5727. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5728. target = new Vector3();
  5729. }
  5730. var a = this.a,
  5731. b = this.b,
  5732. c = this.c;
  5733. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5734. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5735. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5736. // basically, we're distinguishing which of the voronoi regions of the triangle
  5737. // the point lies in with the minimum amount of redundant computation.
  5738. _vab.subVectors(b, a);
  5739. _vac.subVectors(c, a);
  5740. _vap.subVectors(p, a);
  5741. var d1 = _vab.dot(_vap);
  5742. var d2 = _vac.dot(_vap);
  5743. if (d1 <= 0 && d2 <= 0) {
  5744. // vertex region of A; barycentric coords (1, 0, 0)
  5745. return target.copy(a);
  5746. }
  5747. _vbp.subVectors(p, b);
  5748. var d3 = _vab.dot(_vbp);
  5749. var d4 = _vac.dot(_vbp);
  5750. if (d3 >= 0 && d4 <= d3) {
  5751. // vertex region of B; barycentric coords (0, 1, 0)
  5752. return target.copy(b);
  5753. }
  5754. var vc = d1 * d4 - d3 * d2;
  5755. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5756. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5757. return target.copy(a).addScaledVector(_vab, v);
  5758. }
  5759. _vcp.subVectors(p, c);
  5760. var d5 = _vab.dot(_vcp);
  5761. var d6 = _vac.dot(_vcp);
  5762. if (d6 >= 0 && d5 <= d6) {
  5763. // vertex region of C; barycentric coords (0, 0, 1)
  5764. return target.copy(c);
  5765. }
  5766. var vb = d5 * d2 - d1 * d6;
  5767. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5768. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5769. return target.copy(a).addScaledVector(_vac, w);
  5770. }
  5771. var va = d3 * d6 - d5 * d4;
  5772. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5773. _vbc.subVectors(c, b);
  5774. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5775. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5776. } // face region
  5777. var denom = 1 / (va + vb + vc); // u = va * denom
  5778. v = vb * denom;
  5779. w = vc * denom;
  5780. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5781. };
  5782. _proto.equals = function equals(triangle) {
  5783. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5784. };
  5785. return Triangle;
  5786. }();
  5787. var materialId = 0;
  5788. function Material() {
  5789. Object.defineProperty(this, 'id', {
  5790. value: materialId++
  5791. });
  5792. this.uuid = MathUtils.generateUUID();
  5793. this.name = '';
  5794. this.type = 'Material';
  5795. this.fog = true;
  5796. this.blending = NormalBlending;
  5797. this.side = FrontSide;
  5798. this.vertexColors = false;
  5799. this.opacity = 1;
  5800. this.transparent = false;
  5801. this.blendSrc = SrcAlphaFactor;
  5802. this.blendDst = OneMinusSrcAlphaFactor;
  5803. this.blendEquation = AddEquation;
  5804. this.blendSrcAlpha = null;
  5805. this.blendDstAlpha = null;
  5806. this.blendEquationAlpha = null;
  5807. this.depthFunc = LessEqualDepth;
  5808. this.depthTest = true;
  5809. this.depthWrite = true;
  5810. this.stencilWriteMask = 0xff;
  5811. this.stencilFunc = AlwaysStencilFunc;
  5812. this.stencilRef = 0;
  5813. this.stencilFuncMask = 0xff;
  5814. this.stencilFail = KeepStencilOp;
  5815. this.stencilZFail = KeepStencilOp;
  5816. this.stencilZPass = KeepStencilOp;
  5817. this.stencilWrite = false;
  5818. this.clippingPlanes = null;
  5819. this.clipIntersection = false;
  5820. this.clipShadows = false;
  5821. this.shadowSide = null;
  5822. this.colorWrite = true;
  5823. this.precision = null; // override the renderer's default precision for this material
  5824. this.polygonOffset = false;
  5825. this.polygonOffsetFactor = 0;
  5826. this.polygonOffsetUnits = 0;
  5827. this.dithering = false;
  5828. this.alphaTest = 0;
  5829. this.premultipliedAlpha = false;
  5830. this.visible = true;
  5831. this.toneMapped = true;
  5832. this.userData = {};
  5833. this.version = 0;
  5834. }
  5835. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5836. constructor: Material,
  5837. isMaterial: true,
  5838. onBeforeCompile: function onBeforeCompile()
  5839. /* shaderobject, renderer */
  5840. {},
  5841. customProgramCacheKey: function customProgramCacheKey() {
  5842. return this.onBeforeCompile.toString();
  5843. },
  5844. setValues: function setValues(values) {
  5845. if (values === undefined) return;
  5846. for (var key in values) {
  5847. var newValue = values[key];
  5848. if (newValue === undefined) {
  5849. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  5850. continue;
  5851. } // for backward compatability if shading is set in the constructor
  5852. if (key === 'shading') {
  5853. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5854. this.flatShading = newValue === FlatShading ? true : false;
  5855. continue;
  5856. }
  5857. var currentValue = this[key];
  5858. if (currentValue === undefined) {
  5859. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  5860. continue;
  5861. }
  5862. if (currentValue && currentValue.isColor) {
  5863. currentValue.set(newValue);
  5864. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5865. currentValue.copy(newValue);
  5866. } else {
  5867. this[key] = newValue;
  5868. }
  5869. }
  5870. },
  5871. toJSON: function toJSON(meta) {
  5872. var isRoot = meta === undefined || typeof meta === 'string';
  5873. if (isRoot) {
  5874. meta = {
  5875. textures: {},
  5876. images: {}
  5877. };
  5878. }
  5879. var data = {
  5880. metadata: {
  5881. version: 4.5,
  5882. type: 'Material',
  5883. generator: 'Material.toJSON'
  5884. }
  5885. }; // standard Material serialization
  5886. data.uuid = this.uuid;
  5887. data.type = this.type;
  5888. if (this.name !== '') data.name = this.name;
  5889. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5890. if (this.roughness !== undefined) data.roughness = this.roughness;
  5891. if (this.metalness !== undefined) data.metalness = this.metalness;
  5892. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5893. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5894. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5895. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5896. if (this.shininess !== undefined) data.shininess = this.shininess;
  5897. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5898. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5899. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5900. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5901. }
  5902. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5903. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5904. }
  5905. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5906. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5907. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5908. }
  5909. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5910. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5911. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5912. if (this.lightMap && this.lightMap.isTexture) {
  5913. data.lightMap = this.lightMap.toJSON(meta).uuid;
  5914. data.lightMapIntensity = this.lightMapIntensity;
  5915. }
  5916. if (this.aoMap && this.aoMap.isTexture) {
  5917. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5918. data.aoMapIntensity = this.aoMapIntensity;
  5919. }
  5920. if (this.bumpMap && this.bumpMap.isTexture) {
  5921. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5922. data.bumpScale = this.bumpScale;
  5923. }
  5924. if (this.normalMap && this.normalMap.isTexture) {
  5925. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5926. data.normalMapType = this.normalMapType;
  5927. data.normalScale = this.normalScale.toArray();
  5928. }
  5929. if (this.displacementMap && this.displacementMap.isTexture) {
  5930. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5931. data.displacementScale = this.displacementScale;
  5932. data.displacementBias = this.displacementBias;
  5933. }
  5934. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5935. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5936. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5937. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5938. if (this.envMap && this.envMap.isTexture) {
  5939. data.envMap = this.envMap.toJSON(meta).uuid;
  5940. data.reflectivity = this.reflectivity; // Scale behind envMap
  5941. data.refractionRatio = this.refractionRatio;
  5942. if (this.combine !== undefined) data.combine = this.combine;
  5943. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5944. }
  5945. if (this.gradientMap && this.gradientMap.isTexture) {
  5946. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5947. }
  5948. if (this.size !== undefined) data.size = this.size;
  5949. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5950. if (this.blending !== NormalBlending) data.blending = this.blending;
  5951. if (this.side !== FrontSide) data.side = this.side;
  5952. if (this.vertexColors) data.vertexColors = true;
  5953. if (this.opacity < 1) data.opacity = this.opacity;
  5954. if (this.transparent === true) data.transparent = this.transparent;
  5955. data.depthFunc = this.depthFunc;
  5956. data.depthTest = this.depthTest;
  5957. data.depthWrite = this.depthWrite;
  5958. data.stencilWrite = this.stencilWrite;
  5959. data.stencilWriteMask = this.stencilWriteMask;
  5960. data.stencilFunc = this.stencilFunc;
  5961. data.stencilRef = this.stencilRef;
  5962. data.stencilFuncMask = this.stencilFuncMask;
  5963. data.stencilFail = this.stencilFail;
  5964. data.stencilZFail = this.stencilZFail;
  5965. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5966. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5967. if (this.polygonOffset === true) data.polygonOffset = true;
  5968. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5969. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5970. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5971. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5972. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5973. if (this.scale !== undefined) data.scale = this.scale;
  5974. if (this.dithering === true) data.dithering = true;
  5975. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5976. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5977. if (this.wireframe === true) data.wireframe = this.wireframe;
  5978. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  5979. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  5980. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  5981. if (this.morphTargets === true) data.morphTargets = true;
  5982. if (this.morphNormals === true) data.morphNormals = true;
  5983. if (this.skinning === true) data.skinning = true;
  5984. if (this.flatShading === true) data.flatShading = this.flatShading;
  5985. if (this.visible === false) data.visible = false;
  5986. if (this.toneMapped === false) data.toneMapped = false;
  5987. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  5988. function extractFromCache(cache) {
  5989. var values = [];
  5990. for (var key in cache) {
  5991. var _data = cache[key];
  5992. delete _data.metadata;
  5993. values.push(_data);
  5994. }
  5995. return values;
  5996. }
  5997. if (isRoot) {
  5998. var textures = extractFromCache(meta.textures);
  5999. var images = extractFromCache(meta.images);
  6000. if (textures.length > 0) data.textures = textures;
  6001. if (images.length > 0) data.images = images;
  6002. }
  6003. return data;
  6004. },
  6005. clone: function clone() {
  6006. return new this.constructor().copy(this);
  6007. },
  6008. copy: function copy(source) {
  6009. this.name = source.name;
  6010. this.fog = source.fog;
  6011. this.blending = source.blending;
  6012. this.side = source.side;
  6013. this.vertexColors = source.vertexColors;
  6014. this.opacity = source.opacity;
  6015. this.transparent = source.transparent;
  6016. this.blendSrc = source.blendSrc;
  6017. this.blendDst = source.blendDst;
  6018. this.blendEquation = source.blendEquation;
  6019. this.blendSrcAlpha = source.blendSrcAlpha;
  6020. this.blendDstAlpha = source.blendDstAlpha;
  6021. this.blendEquationAlpha = source.blendEquationAlpha;
  6022. this.depthFunc = source.depthFunc;
  6023. this.depthTest = source.depthTest;
  6024. this.depthWrite = source.depthWrite;
  6025. this.stencilWriteMask = source.stencilWriteMask;
  6026. this.stencilFunc = source.stencilFunc;
  6027. this.stencilRef = source.stencilRef;
  6028. this.stencilFuncMask = source.stencilFuncMask;
  6029. this.stencilFail = source.stencilFail;
  6030. this.stencilZFail = source.stencilZFail;
  6031. this.stencilZPass = source.stencilZPass;
  6032. this.stencilWrite = source.stencilWrite;
  6033. var srcPlanes = source.clippingPlanes;
  6034. var dstPlanes = null;
  6035. if (srcPlanes !== null) {
  6036. var n = srcPlanes.length;
  6037. dstPlanes = new Array(n);
  6038. for (var i = 0; i !== n; ++i) {
  6039. dstPlanes[i] = srcPlanes[i].clone();
  6040. }
  6041. }
  6042. this.clippingPlanes = dstPlanes;
  6043. this.clipIntersection = source.clipIntersection;
  6044. this.clipShadows = source.clipShadows;
  6045. this.shadowSide = source.shadowSide;
  6046. this.colorWrite = source.colorWrite;
  6047. this.precision = source.precision;
  6048. this.polygonOffset = source.polygonOffset;
  6049. this.polygonOffsetFactor = source.polygonOffsetFactor;
  6050. this.polygonOffsetUnits = source.polygonOffsetUnits;
  6051. this.dithering = source.dithering;
  6052. this.alphaTest = source.alphaTest;
  6053. this.premultipliedAlpha = source.premultipliedAlpha;
  6054. this.visible = source.visible;
  6055. this.toneMapped = source.toneMapped;
  6056. this.userData = JSON.parse(JSON.stringify(source.userData));
  6057. return this;
  6058. },
  6059. dispose: function dispose() {
  6060. this.dispatchEvent({
  6061. type: 'dispose'
  6062. });
  6063. }
  6064. });
  6065. Object.defineProperty(Material.prototype, 'needsUpdate', {
  6066. set: function set(value) {
  6067. if (value === true) this.version++;
  6068. }
  6069. });
  6070. var _colorKeywords = {
  6071. 'aliceblue': 0xF0F8FF,
  6072. 'antiquewhite': 0xFAEBD7,
  6073. 'aqua': 0x00FFFF,
  6074. 'aquamarine': 0x7FFFD4,
  6075. 'azure': 0xF0FFFF,
  6076. 'beige': 0xF5F5DC,
  6077. 'bisque': 0xFFE4C4,
  6078. 'black': 0x000000,
  6079. 'blanchedalmond': 0xFFEBCD,
  6080. 'blue': 0x0000FF,
  6081. 'blueviolet': 0x8A2BE2,
  6082. 'brown': 0xA52A2A,
  6083. 'burlywood': 0xDEB887,
  6084. 'cadetblue': 0x5F9EA0,
  6085. 'chartreuse': 0x7FFF00,
  6086. 'chocolate': 0xD2691E,
  6087. 'coral': 0xFF7F50,
  6088. 'cornflowerblue': 0x6495ED,
  6089. 'cornsilk': 0xFFF8DC,
  6090. 'crimson': 0xDC143C,
  6091. 'cyan': 0x00FFFF,
  6092. 'darkblue': 0x00008B,
  6093. 'darkcyan': 0x008B8B,
  6094. 'darkgoldenrod': 0xB8860B,
  6095. 'darkgray': 0xA9A9A9,
  6096. 'darkgreen': 0x006400,
  6097. 'darkgrey': 0xA9A9A9,
  6098. 'darkkhaki': 0xBDB76B,
  6099. 'darkmagenta': 0x8B008B,
  6100. 'darkolivegreen': 0x556B2F,
  6101. 'darkorange': 0xFF8C00,
  6102. 'darkorchid': 0x9932CC,
  6103. 'darkred': 0x8B0000,
  6104. 'darksalmon': 0xE9967A,
  6105. 'darkseagreen': 0x8FBC8F,
  6106. 'darkslateblue': 0x483D8B,
  6107. 'darkslategray': 0x2F4F4F,
  6108. 'darkslategrey': 0x2F4F4F,
  6109. 'darkturquoise': 0x00CED1,
  6110. 'darkviolet': 0x9400D3,
  6111. 'deeppink': 0xFF1493,
  6112. 'deepskyblue': 0x00BFFF,
  6113. 'dimgray': 0x696969,
  6114. 'dimgrey': 0x696969,
  6115. 'dodgerblue': 0x1E90FF,
  6116. 'firebrick': 0xB22222,
  6117. 'floralwhite': 0xFFFAF0,
  6118. 'forestgreen': 0x228B22,
  6119. 'fuchsia': 0xFF00FF,
  6120. 'gainsboro': 0xDCDCDC,
  6121. 'ghostwhite': 0xF8F8FF,
  6122. 'gold': 0xFFD700,
  6123. 'goldenrod': 0xDAA520,
  6124. 'gray': 0x808080,
  6125. 'green': 0x008000,
  6126. 'greenyellow': 0xADFF2F,
  6127. 'grey': 0x808080,
  6128. 'honeydew': 0xF0FFF0,
  6129. 'hotpink': 0xFF69B4,
  6130. 'indianred': 0xCD5C5C,
  6131. 'indigo': 0x4B0082,
  6132. 'ivory': 0xFFFFF0,
  6133. 'khaki': 0xF0E68C,
  6134. 'lavender': 0xE6E6FA,
  6135. 'lavenderblush': 0xFFF0F5,
  6136. 'lawngreen': 0x7CFC00,
  6137. 'lemonchiffon': 0xFFFACD,
  6138. 'lightblue': 0xADD8E6,
  6139. 'lightcoral': 0xF08080,
  6140. 'lightcyan': 0xE0FFFF,
  6141. 'lightgoldenrodyellow': 0xFAFAD2,
  6142. 'lightgray': 0xD3D3D3,
  6143. 'lightgreen': 0x90EE90,
  6144. 'lightgrey': 0xD3D3D3,
  6145. 'lightpink': 0xFFB6C1,
  6146. 'lightsalmon': 0xFFA07A,
  6147. 'lightseagreen': 0x20B2AA,
  6148. 'lightskyblue': 0x87CEFA,
  6149. 'lightslategray': 0x778899,
  6150. 'lightslategrey': 0x778899,
  6151. 'lightsteelblue': 0xB0C4DE,
  6152. 'lightyellow': 0xFFFFE0,
  6153. 'lime': 0x00FF00,
  6154. 'limegreen': 0x32CD32,
  6155. 'linen': 0xFAF0E6,
  6156. 'magenta': 0xFF00FF,
  6157. 'maroon': 0x800000,
  6158. 'mediumaquamarine': 0x66CDAA,
  6159. 'mediumblue': 0x0000CD,
  6160. 'mediumorchid': 0xBA55D3,
  6161. 'mediumpurple': 0x9370DB,
  6162. 'mediumseagreen': 0x3CB371,
  6163. 'mediumslateblue': 0x7B68EE,
  6164. 'mediumspringgreen': 0x00FA9A,
  6165. 'mediumturquoise': 0x48D1CC,
  6166. 'mediumvioletred': 0xC71585,
  6167. 'midnightblue': 0x191970,
  6168. 'mintcream': 0xF5FFFA,
  6169. 'mistyrose': 0xFFE4E1,
  6170. 'moccasin': 0xFFE4B5,
  6171. 'navajowhite': 0xFFDEAD,
  6172. 'navy': 0x000080,
  6173. 'oldlace': 0xFDF5E6,
  6174. 'olive': 0x808000,
  6175. 'olivedrab': 0x6B8E23,
  6176. 'orange': 0xFFA500,
  6177. 'orangered': 0xFF4500,
  6178. 'orchid': 0xDA70D6,
  6179. 'palegoldenrod': 0xEEE8AA,
  6180. 'palegreen': 0x98FB98,
  6181. 'paleturquoise': 0xAFEEEE,
  6182. 'palevioletred': 0xDB7093,
  6183. 'papayawhip': 0xFFEFD5,
  6184. 'peachpuff': 0xFFDAB9,
  6185. 'peru': 0xCD853F,
  6186. 'pink': 0xFFC0CB,
  6187. 'plum': 0xDDA0DD,
  6188. 'powderblue': 0xB0E0E6,
  6189. 'purple': 0x800080,
  6190. 'rebeccapurple': 0x663399,
  6191. 'red': 0xFF0000,
  6192. 'rosybrown': 0xBC8F8F,
  6193. 'royalblue': 0x4169E1,
  6194. 'saddlebrown': 0x8B4513,
  6195. 'salmon': 0xFA8072,
  6196. 'sandybrown': 0xF4A460,
  6197. 'seagreen': 0x2E8B57,
  6198. 'seashell': 0xFFF5EE,
  6199. 'sienna': 0xA0522D,
  6200. 'silver': 0xC0C0C0,
  6201. 'skyblue': 0x87CEEB,
  6202. 'slateblue': 0x6A5ACD,
  6203. 'slategray': 0x708090,
  6204. 'slategrey': 0x708090,
  6205. 'snow': 0xFFFAFA,
  6206. 'springgreen': 0x00FF7F,
  6207. 'steelblue': 0x4682B4,
  6208. 'tan': 0xD2B48C,
  6209. 'teal': 0x008080,
  6210. 'thistle': 0xD8BFD8,
  6211. 'tomato': 0xFF6347,
  6212. 'turquoise': 0x40E0D0,
  6213. 'violet': 0xEE82EE,
  6214. 'wheat': 0xF5DEB3,
  6215. 'white': 0xFFFFFF,
  6216. 'whitesmoke': 0xF5F5F5,
  6217. 'yellow': 0xFFFF00,
  6218. 'yellowgreen': 0x9ACD32
  6219. };
  6220. var _hslA = {
  6221. h: 0,
  6222. s: 0,
  6223. l: 0
  6224. };
  6225. var _hslB = {
  6226. h: 0,
  6227. s: 0,
  6228. l: 0
  6229. };
  6230. function hue2rgb(p, q, t) {
  6231. if (t < 0) t += 1;
  6232. if (t > 1) t -= 1;
  6233. if (t < 1 / 6) return p + (q - p) * 6 * t;
  6234. if (t < 1 / 2) return q;
  6235. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  6236. return p;
  6237. }
  6238. function SRGBToLinear(c) {
  6239. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  6240. }
  6241. function LinearToSRGB(c) {
  6242. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  6243. }
  6244. var Color = /*#__PURE__*/function () {
  6245. function Color(r, g, b) {
  6246. if (g === undefined && b === undefined) {
  6247. // r is THREE.Color, hex or string
  6248. return this.set(r);
  6249. }
  6250. return this.setRGB(r, g, b);
  6251. }
  6252. var _proto = Color.prototype;
  6253. _proto.set = function set(value) {
  6254. if (value && value.isColor) {
  6255. this.copy(value);
  6256. } else if (typeof value === 'number') {
  6257. this.setHex(value);
  6258. } else if (typeof value === 'string') {
  6259. this.setStyle(value);
  6260. }
  6261. return this;
  6262. };
  6263. _proto.setScalar = function setScalar(scalar) {
  6264. this.r = scalar;
  6265. this.g = scalar;
  6266. this.b = scalar;
  6267. return this;
  6268. };
  6269. _proto.setHex = function setHex(hex) {
  6270. hex = Math.floor(hex);
  6271. this.r = (hex >> 16 & 255) / 255;
  6272. this.g = (hex >> 8 & 255) / 255;
  6273. this.b = (hex & 255) / 255;
  6274. return this;
  6275. };
  6276. _proto.setRGB = function setRGB(r, g, b) {
  6277. this.r = r;
  6278. this.g = g;
  6279. this.b = b;
  6280. return this;
  6281. };
  6282. _proto.setHSL = function setHSL(h, s, l) {
  6283. // h,s,l ranges are in 0.0 - 1.0
  6284. h = MathUtils.euclideanModulo(h, 1);
  6285. s = MathUtils.clamp(s, 0, 1);
  6286. l = MathUtils.clamp(l, 0, 1);
  6287. if (s === 0) {
  6288. this.r = this.g = this.b = l;
  6289. } else {
  6290. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  6291. var q = 2 * l - p;
  6292. this.r = hue2rgb(q, p, h + 1 / 3);
  6293. this.g = hue2rgb(q, p, h);
  6294. this.b = hue2rgb(q, p, h - 1 / 3);
  6295. }
  6296. return this;
  6297. };
  6298. _proto.setStyle = function setStyle(style) {
  6299. function handleAlpha(string) {
  6300. if (string === undefined) return;
  6301. if (parseFloat(string) < 1) {
  6302. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  6303. }
  6304. }
  6305. var m;
  6306. if (m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style)) {
  6307. // rgb / hsl
  6308. var color;
  6309. var name = m[1];
  6310. var components = m[2];
  6311. switch (name) {
  6312. case 'rgb':
  6313. case 'rgba':
  6314. if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6315. // rgb(255,0,0) rgba(255,0,0,0.5)
  6316. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  6317. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  6318. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  6319. handleAlpha(color[4]);
  6320. return this;
  6321. }
  6322. if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6323. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6324. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  6325. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  6326. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  6327. handleAlpha(color[4]);
  6328. return this;
  6329. }
  6330. break;
  6331. case 'hsl':
  6332. case 'hsla':
  6333. if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6334. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6335. var h = parseFloat(color[1]) / 360;
  6336. var s = parseInt(color[2], 10) / 100;
  6337. var l = parseInt(color[3], 10) / 100;
  6338. handleAlpha(color[4]);
  6339. return this.setHSL(h, s, l);
  6340. }
  6341. break;
  6342. }
  6343. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  6344. // hex color
  6345. var hex = m[1];
  6346. var size = hex.length;
  6347. if (size === 3) {
  6348. // #ff0
  6349. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  6350. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  6351. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  6352. return this;
  6353. } else if (size === 6) {
  6354. // #ff0000
  6355. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  6356. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  6357. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  6358. return this;
  6359. }
  6360. }
  6361. if (style && style.length > 0) {
  6362. return this.setColorName(style);
  6363. }
  6364. return this;
  6365. };
  6366. _proto.setColorName = function setColorName(style) {
  6367. // color keywords
  6368. var hex = _colorKeywords[style];
  6369. if (hex !== undefined) {
  6370. // red
  6371. this.setHex(hex);
  6372. } else {
  6373. // unknown color
  6374. console.warn('THREE.Color: Unknown color ' + style);
  6375. }
  6376. return this;
  6377. };
  6378. _proto.clone = function clone() {
  6379. return new this.constructor(this.r, this.g, this.b);
  6380. };
  6381. _proto.copy = function copy(color) {
  6382. this.r = color.r;
  6383. this.g = color.g;
  6384. this.b = color.b;
  6385. return this;
  6386. };
  6387. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  6388. if (gammaFactor === void 0) {
  6389. gammaFactor = 2.0;
  6390. }
  6391. this.r = Math.pow(color.r, gammaFactor);
  6392. this.g = Math.pow(color.g, gammaFactor);
  6393. this.b = Math.pow(color.b, gammaFactor);
  6394. return this;
  6395. };
  6396. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  6397. if (gammaFactor === void 0) {
  6398. gammaFactor = 2.0;
  6399. }
  6400. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  6401. this.r = Math.pow(color.r, safeInverse);
  6402. this.g = Math.pow(color.g, safeInverse);
  6403. this.b = Math.pow(color.b, safeInverse);
  6404. return this;
  6405. };
  6406. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  6407. this.copyGammaToLinear(this, gammaFactor);
  6408. return this;
  6409. };
  6410. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  6411. this.copyLinearToGamma(this, gammaFactor);
  6412. return this;
  6413. };
  6414. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  6415. this.r = SRGBToLinear(color.r);
  6416. this.g = SRGBToLinear(color.g);
  6417. this.b = SRGBToLinear(color.b);
  6418. return this;
  6419. };
  6420. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  6421. this.r = LinearToSRGB(color.r);
  6422. this.g = LinearToSRGB(color.g);
  6423. this.b = LinearToSRGB(color.b);
  6424. return this;
  6425. };
  6426. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  6427. this.copySRGBToLinear(this);
  6428. return this;
  6429. };
  6430. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  6431. this.copyLinearToSRGB(this);
  6432. return this;
  6433. };
  6434. _proto.getHex = function getHex() {
  6435. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  6436. };
  6437. _proto.getHexString = function getHexString() {
  6438. return ('000000' + this.getHex().toString(16)).slice(-6);
  6439. };
  6440. _proto.getHSL = function getHSL(target) {
  6441. // h,s,l ranges are in 0.0 - 1.0
  6442. if (target === undefined) {
  6443. console.warn('THREE.Color: .getHSL() target is now required');
  6444. target = {
  6445. h: 0,
  6446. s: 0,
  6447. l: 0
  6448. };
  6449. }
  6450. var r = this.r,
  6451. g = this.g,
  6452. b = this.b;
  6453. var max = Math.max(r, g, b);
  6454. var min = Math.min(r, g, b);
  6455. var hue, saturation;
  6456. var lightness = (min + max) / 2.0;
  6457. if (min === max) {
  6458. hue = 0;
  6459. saturation = 0;
  6460. } else {
  6461. var delta = max - min;
  6462. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  6463. switch (max) {
  6464. case r:
  6465. hue = (g - b) / delta + (g < b ? 6 : 0);
  6466. break;
  6467. case g:
  6468. hue = (b - r) / delta + 2;
  6469. break;
  6470. case b:
  6471. hue = (r - g) / delta + 4;
  6472. break;
  6473. }
  6474. hue /= 6;
  6475. }
  6476. target.h = hue;
  6477. target.s = saturation;
  6478. target.l = lightness;
  6479. return target;
  6480. };
  6481. _proto.getStyle = function getStyle() {
  6482. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  6483. };
  6484. _proto.offsetHSL = function offsetHSL(h, s, l) {
  6485. this.getHSL(_hslA);
  6486. _hslA.h += h;
  6487. _hslA.s += s;
  6488. _hslA.l += l;
  6489. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  6490. return this;
  6491. };
  6492. _proto.add = function add(color) {
  6493. this.r += color.r;
  6494. this.g += color.g;
  6495. this.b += color.b;
  6496. return this;
  6497. };
  6498. _proto.addColors = function addColors(color1, color2) {
  6499. this.r = color1.r + color2.r;
  6500. this.g = color1.g + color2.g;
  6501. this.b = color1.b + color2.b;
  6502. return this;
  6503. };
  6504. _proto.addScalar = function addScalar(s) {
  6505. this.r += s;
  6506. this.g += s;
  6507. this.b += s;
  6508. return this;
  6509. };
  6510. _proto.sub = function sub(color) {
  6511. this.r = Math.max(0, this.r - color.r);
  6512. this.g = Math.max(0, this.g - color.g);
  6513. this.b = Math.max(0, this.b - color.b);
  6514. return this;
  6515. };
  6516. _proto.multiply = function multiply(color) {
  6517. this.r *= color.r;
  6518. this.g *= color.g;
  6519. this.b *= color.b;
  6520. return this;
  6521. };
  6522. _proto.multiplyScalar = function multiplyScalar(s) {
  6523. this.r *= s;
  6524. this.g *= s;
  6525. this.b *= s;
  6526. return this;
  6527. };
  6528. _proto.lerp = function lerp(color, alpha) {
  6529. this.r += (color.r - this.r) * alpha;
  6530. this.g += (color.g - this.g) * alpha;
  6531. this.b += (color.b - this.b) * alpha;
  6532. return this;
  6533. };
  6534. _proto.lerpColors = function lerpColors(color1, color2, alpha) {
  6535. this.r = color1.r + (color2.r - color1.r) * alpha;
  6536. this.g = color1.g + (color2.g - color1.g) * alpha;
  6537. this.b = color1.b + (color2.b - color1.b) * alpha;
  6538. return this;
  6539. };
  6540. _proto.lerpHSL = function lerpHSL(color, alpha) {
  6541. this.getHSL(_hslA);
  6542. color.getHSL(_hslB);
  6543. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  6544. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  6545. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  6546. this.setHSL(h, s, l);
  6547. return this;
  6548. };
  6549. _proto.equals = function equals(c) {
  6550. return c.r === this.r && c.g === this.g && c.b === this.b;
  6551. };
  6552. _proto.fromArray = function fromArray(array, offset) {
  6553. if (offset === void 0) {
  6554. offset = 0;
  6555. }
  6556. this.r = array[offset];
  6557. this.g = array[offset + 1];
  6558. this.b = array[offset + 2];
  6559. return this;
  6560. };
  6561. _proto.toArray = function toArray(array, offset) {
  6562. if (array === void 0) {
  6563. array = [];
  6564. }
  6565. if (offset === void 0) {
  6566. offset = 0;
  6567. }
  6568. array[offset] = this.r;
  6569. array[offset + 1] = this.g;
  6570. array[offset + 2] = this.b;
  6571. return array;
  6572. };
  6573. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  6574. this.r = attribute.getX(index);
  6575. this.g = attribute.getY(index);
  6576. this.b = attribute.getZ(index);
  6577. if (attribute.normalized === true) {
  6578. // assuming Uint8Array
  6579. this.r /= 255;
  6580. this.g /= 255;
  6581. this.b /= 255;
  6582. }
  6583. return this;
  6584. };
  6585. _proto.toJSON = function toJSON() {
  6586. return this.getHex();
  6587. };
  6588. return Color;
  6589. }();
  6590. Color.NAMES = _colorKeywords;
  6591. Color.prototype.isColor = true;
  6592. Color.prototype.r = 1;
  6593. Color.prototype.g = 1;
  6594. Color.prototype.b = 1;
  6595. /**
  6596. * parameters = {
  6597. * color: <hex>,
  6598. * opacity: <float>,
  6599. * map: new THREE.Texture( <Image> ),
  6600. *
  6601. * lightMap: new THREE.Texture( <Image> ),
  6602. * lightMapIntensity: <float>
  6603. *
  6604. * aoMap: new THREE.Texture( <Image> ),
  6605. * aoMapIntensity: <float>
  6606. *
  6607. * specularMap: new THREE.Texture( <Image> ),
  6608. *
  6609. * alphaMap: new THREE.Texture( <Image> ),
  6610. *
  6611. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  6612. * combine: THREE.Multiply,
  6613. * reflectivity: <float>,
  6614. * refractionRatio: <float>,
  6615. *
  6616. * depthTest: <bool>,
  6617. * depthWrite: <bool>,
  6618. *
  6619. * wireframe: <boolean>,
  6620. * wireframeLinewidth: <float>,
  6621. *
  6622. * skinning: <bool>,
  6623. * morphTargets: <bool>
  6624. * }
  6625. */
  6626. var MeshBasicMaterial = /*#__PURE__*/function (_Material) {
  6627. _inheritsLoose(MeshBasicMaterial, _Material);
  6628. function MeshBasicMaterial(parameters) {
  6629. var _this;
  6630. _this = _Material.call(this) || this;
  6631. _this.type = 'MeshBasicMaterial';
  6632. _this.color = new Color(0xffffff); // emissive
  6633. _this.map = null;
  6634. _this.lightMap = null;
  6635. _this.lightMapIntensity = 1.0;
  6636. _this.aoMap = null;
  6637. _this.aoMapIntensity = 1.0;
  6638. _this.specularMap = null;
  6639. _this.alphaMap = null;
  6640. _this.envMap = null;
  6641. _this.combine = MultiplyOperation;
  6642. _this.reflectivity = 1;
  6643. _this.refractionRatio = 0.98;
  6644. _this.wireframe = false;
  6645. _this.wireframeLinewidth = 1;
  6646. _this.wireframeLinecap = 'round';
  6647. _this.wireframeLinejoin = 'round';
  6648. _this.skinning = false;
  6649. _this.morphTargets = false;
  6650. _this.setValues(parameters);
  6651. return _this;
  6652. }
  6653. var _proto = MeshBasicMaterial.prototype;
  6654. _proto.copy = function copy(source) {
  6655. _Material.prototype.copy.call(this, source);
  6656. this.color.copy(source.color);
  6657. this.map = source.map;
  6658. this.lightMap = source.lightMap;
  6659. this.lightMapIntensity = source.lightMapIntensity;
  6660. this.aoMap = source.aoMap;
  6661. this.aoMapIntensity = source.aoMapIntensity;
  6662. this.specularMap = source.specularMap;
  6663. this.alphaMap = source.alphaMap;
  6664. this.envMap = source.envMap;
  6665. this.combine = source.combine;
  6666. this.reflectivity = source.reflectivity;
  6667. this.refractionRatio = source.refractionRatio;
  6668. this.wireframe = source.wireframe;
  6669. this.wireframeLinewidth = source.wireframeLinewidth;
  6670. this.wireframeLinecap = source.wireframeLinecap;
  6671. this.wireframeLinejoin = source.wireframeLinejoin;
  6672. this.skinning = source.skinning;
  6673. this.morphTargets = source.morphTargets;
  6674. return this;
  6675. };
  6676. return MeshBasicMaterial;
  6677. }(Material);
  6678. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  6679. var _vector$3 = new Vector3();
  6680. var _vector2$1 = new Vector2();
  6681. function BufferAttribute(array, itemSize, normalized) {
  6682. if (Array.isArray(array)) {
  6683. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6684. }
  6685. this.name = '';
  6686. this.array = array;
  6687. this.itemSize = itemSize;
  6688. this.count = array !== undefined ? array.length / itemSize : 0;
  6689. this.normalized = normalized === true;
  6690. this.usage = StaticDrawUsage;
  6691. this.updateRange = {
  6692. offset: 0,
  6693. count: -1
  6694. };
  6695. this.version = 0;
  6696. }
  6697. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6698. set: function set(value) {
  6699. if (value === true) this.version++;
  6700. }
  6701. });
  6702. Object.assign(BufferAttribute.prototype, {
  6703. isBufferAttribute: true,
  6704. onUploadCallback: function onUploadCallback() {},
  6705. setUsage: function setUsage(value) {
  6706. this.usage = value;
  6707. return this;
  6708. },
  6709. copy: function copy(source) {
  6710. this.name = source.name;
  6711. this.array = new source.array.constructor(source.array);
  6712. this.itemSize = source.itemSize;
  6713. this.count = source.count;
  6714. this.normalized = source.normalized;
  6715. this.usage = source.usage;
  6716. return this;
  6717. },
  6718. copyAt: function copyAt(index1, attribute, index2) {
  6719. index1 *= this.itemSize;
  6720. index2 *= attribute.itemSize;
  6721. for (var i = 0, l = this.itemSize; i < l; i++) {
  6722. this.array[index1 + i] = attribute.array[index2 + i];
  6723. }
  6724. return this;
  6725. },
  6726. copyArray: function copyArray(array) {
  6727. this.array.set(array);
  6728. return this;
  6729. },
  6730. copyColorsArray: function copyColorsArray(colors) {
  6731. var array = this.array;
  6732. var offset = 0;
  6733. for (var i = 0, l = colors.length; i < l; i++) {
  6734. var color = colors[i];
  6735. if (color === undefined) {
  6736. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6737. color = new Color();
  6738. }
  6739. array[offset++] = color.r;
  6740. array[offset++] = color.g;
  6741. array[offset++] = color.b;
  6742. }
  6743. return this;
  6744. },
  6745. copyVector2sArray: function copyVector2sArray(vectors) {
  6746. var array = this.array;
  6747. var offset = 0;
  6748. for (var i = 0, l = vectors.length; i < l; i++) {
  6749. var vector = vectors[i];
  6750. if (vector === undefined) {
  6751. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6752. vector = new Vector2();
  6753. }
  6754. array[offset++] = vector.x;
  6755. array[offset++] = vector.y;
  6756. }
  6757. return this;
  6758. },
  6759. copyVector3sArray: function copyVector3sArray(vectors) {
  6760. var array = this.array;
  6761. var offset = 0;
  6762. for (var i = 0, l = vectors.length; i < l; i++) {
  6763. var vector = vectors[i];
  6764. if (vector === undefined) {
  6765. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6766. vector = new Vector3();
  6767. }
  6768. array[offset++] = vector.x;
  6769. array[offset++] = vector.y;
  6770. array[offset++] = vector.z;
  6771. }
  6772. return this;
  6773. },
  6774. copyVector4sArray: function copyVector4sArray(vectors) {
  6775. var array = this.array;
  6776. var offset = 0;
  6777. for (var i = 0, l = vectors.length; i < l; i++) {
  6778. var vector = vectors[i];
  6779. if (vector === undefined) {
  6780. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6781. vector = new Vector4();
  6782. }
  6783. array[offset++] = vector.x;
  6784. array[offset++] = vector.y;
  6785. array[offset++] = vector.z;
  6786. array[offset++] = vector.w;
  6787. }
  6788. return this;
  6789. },
  6790. applyMatrix3: function applyMatrix3(m) {
  6791. if (this.itemSize === 2) {
  6792. for (var i = 0, l = this.count; i < l; i++) {
  6793. _vector2$1.fromBufferAttribute(this, i);
  6794. _vector2$1.applyMatrix3(m);
  6795. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6796. }
  6797. } else if (this.itemSize === 3) {
  6798. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6799. _vector$3.fromBufferAttribute(this, _i);
  6800. _vector$3.applyMatrix3(m);
  6801. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6802. }
  6803. }
  6804. return this;
  6805. },
  6806. applyMatrix4: function applyMatrix4(m) {
  6807. for (var i = 0, l = this.count; i < l; i++) {
  6808. _vector$3.x = this.getX(i);
  6809. _vector$3.y = this.getY(i);
  6810. _vector$3.z = this.getZ(i);
  6811. _vector$3.applyMatrix4(m);
  6812. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6813. }
  6814. return this;
  6815. },
  6816. applyNormalMatrix: function applyNormalMatrix(m) {
  6817. for (var i = 0, l = this.count; i < l; i++) {
  6818. _vector$3.x = this.getX(i);
  6819. _vector$3.y = this.getY(i);
  6820. _vector$3.z = this.getZ(i);
  6821. _vector$3.applyNormalMatrix(m);
  6822. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6823. }
  6824. return this;
  6825. },
  6826. transformDirection: function transformDirection(m) {
  6827. for (var i = 0, l = this.count; i < l; i++) {
  6828. _vector$3.x = this.getX(i);
  6829. _vector$3.y = this.getY(i);
  6830. _vector$3.z = this.getZ(i);
  6831. _vector$3.transformDirection(m);
  6832. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6833. }
  6834. return this;
  6835. },
  6836. set: function set(value, offset) {
  6837. if (offset === void 0) {
  6838. offset = 0;
  6839. }
  6840. this.array.set(value, offset);
  6841. return this;
  6842. },
  6843. getX: function getX(index) {
  6844. return this.array[index * this.itemSize];
  6845. },
  6846. setX: function setX(index, x) {
  6847. this.array[index * this.itemSize] = x;
  6848. return this;
  6849. },
  6850. getY: function getY(index) {
  6851. return this.array[index * this.itemSize + 1];
  6852. },
  6853. setY: function setY(index, y) {
  6854. this.array[index * this.itemSize + 1] = y;
  6855. return this;
  6856. },
  6857. getZ: function getZ(index) {
  6858. return this.array[index * this.itemSize + 2];
  6859. },
  6860. setZ: function setZ(index, z) {
  6861. this.array[index * this.itemSize + 2] = z;
  6862. return this;
  6863. },
  6864. getW: function getW(index) {
  6865. return this.array[index * this.itemSize + 3];
  6866. },
  6867. setW: function setW(index, w) {
  6868. this.array[index * this.itemSize + 3] = w;
  6869. return this;
  6870. },
  6871. setXY: function setXY(index, x, y) {
  6872. index *= this.itemSize;
  6873. this.array[index + 0] = x;
  6874. this.array[index + 1] = y;
  6875. return this;
  6876. },
  6877. setXYZ: function setXYZ(index, x, y, z) {
  6878. index *= this.itemSize;
  6879. this.array[index + 0] = x;
  6880. this.array[index + 1] = y;
  6881. this.array[index + 2] = z;
  6882. return this;
  6883. },
  6884. setXYZW: function setXYZW(index, x, y, z, w) {
  6885. index *= this.itemSize;
  6886. this.array[index + 0] = x;
  6887. this.array[index + 1] = y;
  6888. this.array[index + 2] = z;
  6889. this.array[index + 3] = w;
  6890. return this;
  6891. },
  6892. onUpload: function onUpload(callback) {
  6893. this.onUploadCallback = callback;
  6894. return this;
  6895. },
  6896. clone: function clone() {
  6897. return new this.constructor(this.array, this.itemSize).copy(this);
  6898. },
  6899. toJSON: function toJSON() {
  6900. return {
  6901. itemSize: this.itemSize,
  6902. type: this.array.constructor.name,
  6903. array: Array.prototype.slice.call(this.array),
  6904. normalized: this.normalized
  6905. };
  6906. }
  6907. }); //
  6908. function Int8BufferAttribute(array, itemSize, normalized) {
  6909. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6910. }
  6911. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6912. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6913. function Uint8BufferAttribute(array, itemSize, normalized) {
  6914. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6915. }
  6916. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6917. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6918. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6919. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6920. }
  6921. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6922. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6923. function Int16BufferAttribute(array, itemSize, normalized) {
  6924. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6925. }
  6926. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6927. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6928. function Uint16BufferAttribute(array, itemSize, normalized) {
  6929. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6930. }
  6931. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6932. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6933. function Int32BufferAttribute(array, itemSize, normalized) {
  6934. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6935. }
  6936. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6937. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6938. function Uint32BufferAttribute(array, itemSize, normalized) {
  6939. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6940. }
  6941. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6942. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6943. function Float16BufferAttribute(array, itemSize, normalized) {
  6944. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6945. }
  6946. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6947. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6948. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6949. function Float32BufferAttribute(array, itemSize, normalized) {
  6950. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6951. }
  6952. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6953. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6954. function Float64BufferAttribute(array, itemSize, normalized) {
  6955. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6956. }
  6957. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6958. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6959. function arrayMax(array) {
  6960. if (array.length === 0) return -Infinity;
  6961. var max = array[0];
  6962. for (var i = 1, l = array.length; i < l; ++i) {
  6963. if (array[i] > max) max = array[i];
  6964. }
  6965. return max;
  6966. }
  6967. var TYPED_ARRAYS = {
  6968. Int8Array: Int8Array,
  6969. Uint8Array: Uint8Array,
  6970. Uint8ClampedArray: Uint8ClampedArray,
  6971. Int16Array: Int16Array,
  6972. Uint16Array: Uint16Array,
  6973. Int32Array: Int32Array,
  6974. Uint32Array: Uint32Array,
  6975. Float32Array: Float32Array,
  6976. Float64Array: Float64Array
  6977. };
  6978. function getTypedArray(type, buffer) {
  6979. return new TYPED_ARRAYS[type](buffer);
  6980. }
  6981. var _id = 0;
  6982. var _m1$2 = new Matrix4();
  6983. var _obj = new Object3D();
  6984. var _offset = new Vector3();
  6985. var _box$2 = new Box3();
  6986. var _boxMorphTargets = new Box3();
  6987. var _vector$4 = new Vector3();
  6988. function BufferGeometry() {
  6989. Object.defineProperty(this, 'id', {
  6990. value: _id++
  6991. });
  6992. this.uuid = MathUtils.generateUUID();
  6993. this.name = '';
  6994. this.type = 'BufferGeometry';
  6995. this.index = null;
  6996. this.attributes = {};
  6997. this.morphAttributes = {};
  6998. this.morphTargetsRelative = false;
  6999. this.groups = [];
  7000. this.boundingBox = null;
  7001. this.boundingSphere = null;
  7002. this.drawRange = {
  7003. start: 0,
  7004. count: Infinity
  7005. };
  7006. this.userData = {};
  7007. }
  7008. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  7009. constructor: BufferGeometry,
  7010. isBufferGeometry: true,
  7011. getIndex: function getIndex() {
  7012. return this.index;
  7013. },
  7014. setIndex: function setIndex(index) {
  7015. if (Array.isArray(index)) {
  7016. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  7017. } else {
  7018. this.index = index;
  7019. }
  7020. return this;
  7021. },
  7022. getAttribute: function getAttribute(name) {
  7023. return this.attributes[name];
  7024. },
  7025. setAttribute: function setAttribute(name, attribute) {
  7026. this.attributes[name] = attribute;
  7027. return this;
  7028. },
  7029. deleteAttribute: function deleteAttribute(name) {
  7030. delete this.attributes[name];
  7031. return this;
  7032. },
  7033. hasAttribute: function hasAttribute(name) {
  7034. return this.attributes[name] !== undefined;
  7035. },
  7036. addGroup: function addGroup(start, count, materialIndex) {
  7037. if (materialIndex === void 0) {
  7038. materialIndex = 0;
  7039. }
  7040. this.groups.push({
  7041. start: start,
  7042. count: count,
  7043. materialIndex: materialIndex
  7044. });
  7045. },
  7046. clearGroups: function clearGroups() {
  7047. this.groups = [];
  7048. },
  7049. setDrawRange: function setDrawRange(start, count) {
  7050. this.drawRange.start = start;
  7051. this.drawRange.count = count;
  7052. },
  7053. applyMatrix4: function applyMatrix4(matrix) {
  7054. var position = this.attributes.position;
  7055. if (position !== undefined) {
  7056. position.applyMatrix4(matrix);
  7057. position.needsUpdate = true;
  7058. }
  7059. var normal = this.attributes.normal;
  7060. if (normal !== undefined) {
  7061. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  7062. normal.applyNormalMatrix(normalMatrix);
  7063. normal.needsUpdate = true;
  7064. }
  7065. var tangent = this.attributes.tangent;
  7066. if (tangent !== undefined) {
  7067. tangent.transformDirection(matrix);
  7068. tangent.needsUpdate = true;
  7069. }
  7070. if (this.boundingBox !== null) {
  7071. this.computeBoundingBox();
  7072. }
  7073. if (this.boundingSphere !== null) {
  7074. this.computeBoundingSphere();
  7075. }
  7076. return this;
  7077. },
  7078. rotateX: function rotateX(angle) {
  7079. // rotate geometry around world x-axis
  7080. _m1$2.makeRotationX(angle);
  7081. this.applyMatrix4(_m1$2);
  7082. return this;
  7083. },
  7084. rotateY: function rotateY(angle) {
  7085. // rotate geometry around world y-axis
  7086. _m1$2.makeRotationY(angle);
  7087. this.applyMatrix4(_m1$2);
  7088. return this;
  7089. },
  7090. rotateZ: function rotateZ(angle) {
  7091. // rotate geometry around world z-axis
  7092. _m1$2.makeRotationZ(angle);
  7093. this.applyMatrix4(_m1$2);
  7094. return this;
  7095. },
  7096. translate: function translate(x, y, z) {
  7097. // translate geometry
  7098. _m1$2.makeTranslation(x, y, z);
  7099. this.applyMatrix4(_m1$2);
  7100. return this;
  7101. },
  7102. scale: function scale(x, y, z) {
  7103. // scale geometry
  7104. _m1$2.makeScale(x, y, z);
  7105. this.applyMatrix4(_m1$2);
  7106. return this;
  7107. },
  7108. lookAt: function lookAt(vector) {
  7109. _obj.lookAt(vector);
  7110. _obj.updateMatrix();
  7111. this.applyMatrix4(_obj.matrix);
  7112. return this;
  7113. },
  7114. center: function center() {
  7115. this.computeBoundingBox();
  7116. this.boundingBox.getCenter(_offset).negate();
  7117. this.translate(_offset.x, _offset.y, _offset.z);
  7118. return this;
  7119. },
  7120. setFromPoints: function setFromPoints(points) {
  7121. var position = [];
  7122. for (var i = 0, l = points.length; i < l; i++) {
  7123. var point = points[i];
  7124. position.push(point.x, point.y, point.z || 0);
  7125. }
  7126. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  7127. return this;
  7128. },
  7129. computeBoundingBox: function computeBoundingBox() {
  7130. if (this.boundingBox === null) {
  7131. this.boundingBox = new Box3();
  7132. }
  7133. var position = this.attributes.position;
  7134. var morphAttributesPosition = this.morphAttributes.position;
  7135. if (position && position.isGLBufferAttribute) {
  7136. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  7137. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  7138. return;
  7139. }
  7140. if (position !== undefined) {
  7141. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  7142. if (morphAttributesPosition) {
  7143. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7144. var morphAttribute = morphAttributesPosition[i];
  7145. _box$2.setFromBufferAttribute(morphAttribute);
  7146. if (this.morphTargetsRelative) {
  7147. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  7148. this.boundingBox.expandByPoint(_vector$4);
  7149. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  7150. this.boundingBox.expandByPoint(_vector$4);
  7151. } else {
  7152. this.boundingBox.expandByPoint(_box$2.min);
  7153. this.boundingBox.expandByPoint(_box$2.max);
  7154. }
  7155. }
  7156. }
  7157. } else {
  7158. this.boundingBox.makeEmpty();
  7159. }
  7160. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  7161. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  7162. }
  7163. },
  7164. computeBoundingSphere: function computeBoundingSphere() {
  7165. if (this.boundingSphere === null) {
  7166. this.boundingSphere = new Sphere();
  7167. }
  7168. var position = this.attributes.position;
  7169. var morphAttributesPosition = this.morphAttributes.position;
  7170. if (position && position.isGLBufferAttribute) {
  7171. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  7172. this.boundingSphere.set(new Vector3(), Infinity);
  7173. return;
  7174. }
  7175. if (position) {
  7176. // first, find the center of the bounding sphere
  7177. var center = this.boundingSphere.center;
  7178. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  7179. if (morphAttributesPosition) {
  7180. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7181. var morphAttribute = morphAttributesPosition[i];
  7182. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  7183. if (this.morphTargetsRelative) {
  7184. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  7185. _box$2.expandByPoint(_vector$4);
  7186. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  7187. _box$2.expandByPoint(_vector$4);
  7188. } else {
  7189. _box$2.expandByPoint(_boxMorphTargets.min);
  7190. _box$2.expandByPoint(_boxMorphTargets.max);
  7191. }
  7192. }
  7193. }
  7194. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  7195. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7196. var maxRadiusSq = 0;
  7197. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  7198. _vector$4.fromBufferAttribute(position, _i);
  7199. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7200. } // process morph attributes if present
  7201. if (morphAttributesPosition) {
  7202. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  7203. var _morphAttribute = morphAttributesPosition[_i2];
  7204. var morphTargetsRelative = this.morphTargetsRelative;
  7205. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  7206. _vector$4.fromBufferAttribute(_morphAttribute, j);
  7207. if (morphTargetsRelative) {
  7208. _offset.fromBufferAttribute(position, j);
  7209. _vector$4.add(_offset);
  7210. }
  7211. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7212. }
  7213. }
  7214. }
  7215. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  7216. if (isNaN(this.boundingSphere.radius)) {
  7217. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  7218. }
  7219. }
  7220. },
  7221. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  7222. },
  7223. computeTangents: function computeTangents() {
  7224. var index = this.index;
  7225. var attributes = this.attributes; // based on http://www.terathon.com/code/tangent.html
  7226. // (per vertex tangents)
  7227. if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
  7228. console.error('THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)');
  7229. return;
  7230. }
  7231. var indices = index.array;
  7232. var positions = attributes.position.array;
  7233. var normals = attributes.normal.array;
  7234. var uvs = attributes.uv.array;
  7235. var nVertices = positions.length / 3;
  7236. if (attributes.tangent === undefined) {
  7237. this.setAttribute('tangent', new BufferAttribute(new Float32Array(4 * nVertices), 4));
  7238. }
  7239. var tangents = attributes.tangent.array;
  7240. var tan1 = [],
  7241. tan2 = [];
  7242. for (var i = 0; i < nVertices; i++) {
  7243. tan1[i] = new Vector3();
  7244. tan2[i] = new Vector3();
  7245. }
  7246. var vA = new Vector3(),
  7247. vB = new Vector3(),
  7248. vC = new Vector3(),
  7249. uvA = new Vector2(),
  7250. uvB = new Vector2(),
  7251. uvC = new Vector2(),
  7252. sdir = new Vector3(),
  7253. tdir = new Vector3();
  7254. function handleTriangle(a, b, c) {
  7255. vA.fromArray(positions, a * 3);
  7256. vB.fromArray(positions, b * 3);
  7257. vC.fromArray(positions, c * 3);
  7258. uvA.fromArray(uvs, a * 2);
  7259. uvB.fromArray(uvs, b * 2);
  7260. uvC.fromArray(uvs, c * 2);
  7261. vB.sub(vA);
  7262. vC.sub(vA);
  7263. uvB.sub(uvA);
  7264. uvC.sub(uvA);
  7265. var r = 1.0 / (uvB.x * uvC.y - uvC.x * uvB.y); // silently ignore degenerate uv triangles having coincident or colinear vertices
  7266. if (!isFinite(r)) return;
  7267. sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
  7268. tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
  7269. tan1[a].add(sdir);
  7270. tan1[b].add(sdir);
  7271. tan1[c].add(sdir);
  7272. tan2[a].add(tdir);
  7273. tan2[b].add(tdir);
  7274. tan2[c].add(tdir);
  7275. }
  7276. var groups = this.groups;
  7277. if (groups.length === 0) {
  7278. groups = [{
  7279. start: 0,
  7280. count: indices.length
  7281. }];
  7282. }
  7283. for (var _i3 = 0, il = groups.length; _i3 < il; ++_i3) {
  7284. var group = groups[_i3];
  7285. var start = group.start;
  7286. var count = group.count;
  7287. for (var j = start, jl = start + count; j < jl; j += 3) {
  7288. handleTriangle(indices[j + 0], indices[j + 1], indices[j + 2]);
  7289. }
  7290. }
  7291. var tmp = new Vector3(),
  7292. tmp2 = new Vector3();
  7293. var n = new Vector3(),
  7294. n2 = new Vector3();
  7295. function handleVertex(v) {
  7296. n.fromArray(normals, v * 3);
  7297. n2.copy(n);
  7298. var t = tan1[v]; // Gram-Schmidt orthogonalize
  7299. tmp.copy(t);
  7300. tmp.sub(n.multiplyScalar(n.dot(t))).normalize(); // Calculate handedness
  7301. tmp2.crossVectors(n2, t);
  7302. var test = tmp2.dot(tan2[v]);
  7303. var w = test < 0.0 ? -1.0 : 1.0;
  7304. tangents[v * 4] = tmp.x;
  7305. tangents[v * 4 + 1] = tmp.y;
  7306. tangents[v * 4 + 2] = tmp.z;
  7307. tangents[v * 4 + 3] = w;
  7308. }
  7309. for (var _i4 = 0, _il3 = groups.length; _i4 < _il3; ++_i4) {
  7310. var _group = groups[_i4];
  7311. var _start = _group.start;
  7312. var _count = _group.count;
  7313. for (var _j = _start, _jl = _start + _count; _j < _jl; _j += 3) {
  7314. handleVertex(indices[_j + 0]);
  7315. handleVertex(indices[_j + 1]);
  7316. handleVertex(indices[_j + 2]);
  7317. }
  7318. }
  7319. },
  7320. computeVertexNormals: function computeVertexNormals() {
  7321. var index = this.index;
  7322. var positionAttribute = this.getAttribute('position');
  7323. if (positionAttribute !== undefined) {
  7324. var normalAttribute = this.getAttribute('normal');
  7325. if (normalAttribute === undefined) {
  7326. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  7327. this.setAttribute('normal', normalAttribute);
  7328. } else {
  7329. // reset existing normals to zero
  7330. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  7331. normalAttribute.setXYZ(i, 0, 0, 0);
  7332. }
  7333. }
  7334. var pA = new Vector3(),
  7335. pB = new Vector3(),
  7336. pC = new Vector3();
  7337. var nA = new Vector3(),
  7338. nB = new Vector3(),
  7339. nC = new Vector3();
  7340. var cb = new Vector3(),
  7341. ab = new Vector3(); // indexed elements
  7342. if (index) {
  7343. for (var _i5 = 0, _il4 = index.count; _i5 < _il4; _i5 += 3) {
  7344. var vA = index.getX(_i5 + 0);
  7345. var vB = index.getX(_i5 + 1);
  7346. var vC = index.getX(_i5 + 2);
  7347. pA.fromBufferAttribute(positionAttribute, vA);
  7348. pB.fromBufferAttribute(positionAttribute, vB);
  7349. pC.fromBufferAttribute(positionAttribute, vC);
  7350. cb.subVectors(pC, pB);
  7351. ab.subVectors(pA, pB);
  7352. cb.cross(ab);
  7353. nA.fromBufferAttribute(normalAttribute, vA);
  7354. nB.fromBufferAttribute(normalAttribute, vB);
  7355. nC.fromBufferAttribute(normalAttribute, vC);
  7356. nA.add(cb);
  7357. nB.add(cb);
  7358. nC.add(cb);
  7359. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  7360. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  7361. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  7362. }
  7363. } else {
  7364. // non-indexed elements (unconnected triangle soup)
  7365. for (var _i6 = 0, _il5 = positionAttribute.count; _i6 < _il5; _i6 += 3) {
  7366. pA.fromBufferAttribute(positionAttribute, _i6 + 0);
  7367. pB.fromBufferAttribute(positionAttribute, _i6 + 1);
  7368. pC.fromBufferAttribute(positionAttribute, _i6 + 2);
  7369. cb.subVectors(pC, pB);
  7370. ab.subVectors(pA, pB);
  7371. cb.cross(ab);
  7372. normalAttribute.setXYZ(_i6 + 0, cb.x, cb.y, cb.z);
  7373. normalAttribute.setXYZ(_i6 + 1, cb.x, cb.y, cb.z);
  7374. normalAttribute.setXYZ(_i6 + 2, cb.x, cb.y, cb.z);
  7375. }
  7376. }
  7377. this.normalizeNormals();
  7378. normalAttribute.needsUpdate = true;
  7379. }
  7380. },
  7381. merge: function merge(geometry, offset) {
  7382. if (!(geometry && geometry.isBufferGeometry)) {
  7383. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  7384. return;
  7385. }
  7386. if (offset === undefined) {
  7387. offset = 0;
  7388. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  7389. }
  7390. var attributes = this.attributes;
  7391. for (var key in attributes) {
  7392. if (geometry.attributes[key] === undefined) continue;
  7393. var attribute1 = attributes[key];
  7394. var attributeArray1 = attribute1.array;
  7395. var attribute2 = geometry.attributes[key];
  7396. var attributeArray2 = attribute2.array;
  7397. var attributeOffset = attribute2.itemSize * offset;
  7398. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  7399. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  7400. attributeArray1[j] = attributeArray2[i];
  7401. }
  7402. }
  7403. return this;
  7404. },
  7405. normalizeNormals: function normalizeNormals() {
  7406. var normals = this.attributes.normal;
  7407. for (var i = 0, il = normals.count; i < il; i++) {
  7408. _vector$4.fromBufferAttribute(normals, i);
  7409. _vector$4.normalize();
  7410. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  7411. }
  7412. },
  7413. toNonIndexed: function toNonIndexed() {
  7414. function convertBufferAttribute(attribute, indices) {
  7415. var array = attribute.array;
  7416. var itemSize = attribute.itemSize;
  7417. var normalized = attribute.normalized;
  7418. var array2 = new array.constructor(indices.length * itemSize);
  7419. var index = 0,
  7420. index2 = 0;
  7421. for (var i = 0, l = indices.length; i < l; i++) {
  7422. index = indices[i] * itemSize;
  7423. for (var j = 0; j < itemSize; j++) {
  7424. array2[index2++] = array[index++];
  7425. }
  7426. }
  7427. return new BufferAttribute(array2, itemSize, normalized);
  7428. } //
  7429. if (this.index === null) {
  7430. console.warn('THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.');
  7431. return this;
  7432. }
  7433. var geometry2 = new BufferGeometry();
  7434. var indices = this.index.array;
  7435. var attributes = this.attributes; // attributes
  7436. for (var name in attributes) {
  7437. var attribute = attributes[name];
  7438. var newAttribute = convertBufferAttribute(attribute, indices);
  7439. geometry2.setAttribute(name, newAttribute);
  7440. } // morph attributes
  7441. var morphAttributes = this.morphAttributes;
  7442. for (var _name in morphAttributes) {
  7443. var morphArray = [];
  7444. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  7445. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  7446. var _attribute = morphAttribute[i];
  7447. var _newAttribute = convertBufferAttribute(_attribute, indices);
  7448. morphArray.push(_newAttribute);
  7449. }
  7450. geometry2.morphAttributes[_name] = morphArray;
  7451. }
  7452. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  7453. var groups = this.groups;
  7454. for (var _i7 = 0, l = groups.length; _i7 < l; _i7++) {
  7455. var group = groups[_i7];
  7456. geometry2.addGroup(group.start, group.count, group.materialIndex);
  7457. }
  7458. return geometry2;
  7459. },
  7460. toJSON: function toJSON() {
  7461. var data = {
  7462. metadata: {
  7463. version: 4.5,
  7464. type: 'BufferGeometry',
  7465. generator: 'BufferGeometry.toJSON'
  7466. }
  7467. }; // standard BufferGeometry serialization
  7468. data.uuid = this.uuid;
  7469. data.type = this.type;
  7470. if (this.name !== '') data.name = this.name;
  7471. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  7472. if (this.parameters !== undefined) {
  7473. var parameters = this.parameters;
  7474. for (var key in parameters) {
  7475. if (parameters[key] !== undefined) data[key] = parameters[key];
  7476. }
  7477. return data;
  7478. }
  7479. data.data = {
  7480. attributes: {}
  7481. };
  7482. var index = this.index;
  7483. if (index !== null) {
  7484. data.data.index = {
  7485. type: index.array.constructor.name,
  7486. array: Array.prototype.slice.call(index.array)
  7487. };
  7488. }
  7489. var attributes = this.attributes;
  7490. for (var _key in attributes) {
  7491. var attribute = attributes[_key];
  7492. var attributeData = attribute.toJSON(data.data);
  7493. if (attribute.name !== '') attributeData.name = attribute.name;
  7494. data.data.attributes[_key] = attributeData;
  7495. }
  7496. var morphAttributes = {};
  7497. var hasMorphAttributes = false;
  7498. for (var _key2 in this.morphAttributes) {
  7499. var attributeArray = this.morphAttributes[_key2];
  7500. var array = [];
  7501. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7502. var _attribute2 = attributeArray[i];
  7503. var _attributeData = _attribute2.toJSON(data.data);
  7504. if (_attribute2.name !== '') _attributeData.name = _attribute2.name;
  7505. array.push(_attributeData);
  7506. }
  7507. if (array.length > 0) {
  7508. morphAttributes[_key2] = array;
  7509. hasMorphAttributes = true;
  7510. }
  7511. }
  7512. if (hasMorphAttributes) {
  7513. data.data.morphAttributes = morphAttributes;
  7514. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7515. }
  7516. var groups = this.groups;
  7517. if (groups.length > 0) {
  7518. data.data.groups = JSON.parse(JSON.stringify(groups));
  7519. }
  7520. var boundingSphere = this.boundingSphere;
  7521. if (boundingSphere !== null) {
  7522. data.data.boundingSphere = {
  7523. center: boundingSphere.center.toArray(),
  7524. radius: boundingSphere.radius
  7525. };
  7526. }
  7527. return data;
  7528. },
  7529. clone: function clone() {
  7530. /*
  7531. // Handle primitives
  7532. const parameters = this.parameters;
  7533. if ( parameters !== undefined ) {
  7534. const values = [];
  7535. for ( const key in parameters ) {
  7536. values.push( parameters[ key ] );
  7537. }
  7538. const geometry = Object.create( this.constructor.prototype );
  7539. this.constructor.apply( geometry, values );
  7540. return geometry;
  7541. }
  7542. return new this.constructor().copy( this );
  7543. */
  7544. return new BufferGeometry().copy(this);
  7545. },
  7546. copy: function copy(source) {
  7547. // reset
  7548. this.index = null;
  7549. this.attributes = {};
  7550. this.morphAttributes = {};
  7551. this.groups = [];
  7552. this.boundingBox = null;
  7553. this.boundingSphere = null; // used for storing cloned, shared data
  7554. var data = {}; // name
  7555. this.name = source.name; // index
  7556. var index = source.index;
  7557. if (index !== null) {
  7558. this.setIndex(index.clone(data));
  7559. } // attributes
  7560. var attributes = source.attributes;
  7561. for (var name in attributes) {
  7562. var attribute = attributes[name];
  7563. this.setAttribute(name, attribute.clone(data));
  7564. } // morph attributes
  7565. var morphAttributes = source.morphAttributes;
  7566. for (var _name2 in morphAttributes) {
  7567. var array = [];
  7568. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7569. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7570. array.push(morphAttribute[i].clone(data));
  7571. }
  7572. this.morphAttributes[_name2] = array;
  7573. }
  7574. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7575. var groups = source.groups;
  7576. for (var _i8 = 0, _l = groups.length; _i8 < _l; _i8++) {
  7577. var group = groups[_i8];
  7578. this.addGroup(group.start, group.count, group.materialIndex);
  7579. } // bounding box
  7580. var boundingBox = source.boundingBox;
  7581. if (boundingBox !== null) {
  7582. this.boundingBox = boundingBox.clone();
  7583. } // bounding sphere
  7584. var boundingSphere = source.boundingSphere;
  7585. if (boundingSphere !== null) {
  7586. this.boundingSphere = boundingSphere.clone();
  7587. } // draw range
  7588. this.drawRange.start = source.drawRange.start;
  7589. this.drawRange.count = source.drawRange.count; // user data
  7590. this.userData = source.userData;
  7591. return this;
  7592. },
  7593. dispose: function dispose() {
  7594. this.dispatchEvent({
  7595. type: 'dispose'
  7596. });
  7597. }
  7598. });
  7599. var _inverseMatrix = new Matrix4();
  7600. var _ray = new Ray();
  7601. var _sphere = new Sphere();
  7602. var _vA = new Vector3();
  7603. var _vB = new Vector3();
  7604. var _vC = new Vector3();
  7605. var _tempA = new Vector3();
  7606. var _tempB = new Vector3();
  7607. var _tempC = new Vector3();
  7608. var _morphA = new Vector3();
  7609. var _morphB = new Vector3();
  7610. var _morphC = new Vector3();
  7611. var _uvA = new Vector2();
  7612. var _uvB = new Vector2();
  7613. var _uvC = new Vector2();
  7614. var _intersectionPoint = new Vector3();
  7615. var _intersectionPointWorld = new Vector3();
  7616. function Mesh(geometry, material) {
  7617. if (geometry === void 0) {
  7618. geometry = new BufferGeometry();
  7619. }
  7620. if (material === void 0) {
  7621. material = new MeshBasicMaterial();
  7622. }
  7623. Object3D.call(this);
  7624. this.type = 'Mesh';
  7625. this.geometry = geometry;
  7626. this.material = material;
  7627. this.updateMorphTargets();
  7628. }
  7629. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7630. constructor: Mesh,
  7631. isMesh: true,
  7632. copy: function copy(source) {
  7633. Object3D.prototype.copy.call(this, source);
  7634. if (source.morphTargetInfluences !== undefined) {
  7635. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7636. }
  7637. if (source.morphTargetDictionary !== undefined) {
  7638. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7639. }
  7640. this.material = source.material;
  7641. this.geometry = source.geometry;
  7642. return this;
  7643. },
  7644. updateMorphTargets: function updateMorphTargets() {
  7645. var geometry = this.geometry;
  7646. if (geometry.isBufferGeometry) {
  7647. var morphAttributes = geometry.morphAttributes;
  7648. var keys = Object.keys(morphAttributes);
  7649. if (keys.length > 0) {
  7650. var morphAttribute = morphAttributes[keys[0]];
  7651. if (morphAttribute !== undefined) {
  7652. this.morphTargetInfluences = [];
  7653. this.morphTargetDictionary = {};
  7654. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7655. var name = morphAttribute[m].name || String(m);
  7656. this.morphTargetInfluences.push(0);
  7657. this.morphTargetDictionary[name] = m;
  7658. }
  7659. }
  7660. }
  7661. } else {
  7662. var morphTargets = geometry.morphTargets;
  7663. if (morphTargets !== undefined && morphTargets.length > 0) {
  7664. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7665. }
  7666. }
  7667. },
  7668. raycast: function raycast(raycaster, intersects) {
  7669. var geometry = this.geometry;
  7670. var material = this.material;
  7671. var matrixWorld = this.matrixWorld;
  7672. if (material === undefined) return; // Checking boundingSphere distance to ray
  7673. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7674. _sphere.copy(geometry.boundingSphere);
  7675. _sphere.applyMatrix4(matrixWorld);
  7676. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7677. _inverseMatrix.copy(matrixWorld).invert();
  7678. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7679. if (geometry.boundingBox !== null) {
  7680. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7681. }
  7682. var intersection;
  7683. if (geometry.isBufferGeometry) {
  7684. var index = geometry.index;
  7685. var position = geometry.attributes.position;
  7686. var morphPosition = geometry.morphAttributes.position;
  7687. var morphTargetsRelative = geometry.morphTargetsRelative;
  7688. var uv = geometry.attributes.uv;
  7689. var uv2 = geometry.attributes.uv2;
  7690. var groups = geometry.groups;
  7691. var drawRange = geometry.drawRange;
  7692. if (index !== null) {
  7693. // indexed buffer geometry
  7694. if (Array.isArray(material)) {
  7695. for (var i = 0, il = groups.length; i < il; i++) {
  7696. var group = groups[i];
  7697. var groupMaterial = material[group.materialIndex];
  7698. var start = Math.max(group.start, drawRange.start);
  7699. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7700. for (var j = start, jl = end; j < jl; j += 3) {
  7701. var a = index.getX(j);
  7702. var b = index.getX(j + 1);
  7703. var c = index.getX(j + 2);
  7704. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7705. if (intersection) {
  7706. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7707. intersection.face.materialIndex = group.materialIndex;
  7708. intersects.push(intersection);
  7709. }
  7710. }
  7711. }
  7712. } else {
  7713. var _start = Math.max(0, drawRange.start);
  7714. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7715. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7716. var _a = index.getX(_i);
  7717. var _b = index.getX(_i + 1);
  7718. var _c = index.getX(_i + 2);
  7719. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7720. if (intersection) {
  7721. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7722. intersects.push(intersection);
  7723. }
  7724. }
  7725. }
  7726. } else if (position !== undefined) {
  7727. // non-indexed buffer geometry
  7728. if (Array.isArray(material)) {
  7729. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7730. var _group = groups[_i2];
  7731. var _groupMaterial = material[_group.materialIndex];
  7732. var _start2 = Math.max(_group.start, drawRange.start);
  7733. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7734. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7735. var _a2 = _j;
  7736. var _b2 = _j + 1;
  7737. var _c2 = _j + 2;
  7738. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7739. if (intersection) {
  7740. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7741. intersection.face.materialIndex = _group.materialIndex;
  7742. intersects.push(intersection);
  7743. }
  7744. }
  7745. }
  7746. } else {
  7747. var _start3 = Math.max(0, drawRange.start);
  7748. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7749. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7750. var _a3 = _i3;
  7751. var _b3 = _i3 + 1;
  7752. var _c3 = _i3 + 2;
  7753. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7754. if (intersection) {
  7755. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7756. intersects.push(intersection);
  7757. }
  7758. }
  7759. }
  7760. }
  7761. } else if (geometry.isGeometry) {
  7762. console.error('THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7763. }
  7764. }
  7765. });
  7766. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7767. var intersect;
  7768. if (material.side === BackSide) {
  7769. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7770. } else {
  7771. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7772. }
  7773. if (intersect === null) return null;
  7774. _intersectionPointWorld.copy(point);
  7775. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7776. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7777. if (distance < raycaster.near || distance > raycaster.far) return null;
  7778. return {
  7779. distance: distance,
  7780. point: _intersectionPointWorld.clone(),
  7781. object: object
  7782. };
  7783. }
  7784. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7785. _vA.fromBufferAttribute(position, a);
  7786. _vB.fromBufferAttribute(position, b);
  7787. _vC.fromBufferAttribute(position, c);
  7788. var morphInfluences = object.morphTargetInfluences;
  7789. if (material.morphTargets && morphPosition && morphInfluences) {
  7790. _morphA.set(0, 0, 0);
  7791. _morphB.set(0, 0, 0);
  7792. _morphC.set(0, 0, 0);
  7793. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7794. var influence = morphInfluences[i];
  7795. var morphAttribute = morphPosition[i];
  7796. if (influence === 0) continue;
  7797. _tempA.fromBufferAttribute(morphAttribute, a);
  7798. _tempB.fromBufferAttribute(morphAttribute, b);
  7799. _tempC.fromBufferAttribute(morphAttribute, c);
  7800. if (morphTargetsRelative) {
  7801. _morphA.addScaledVector(_tempA, influence);
  7802. _morphB.addScaledVector(_tempB, influence);
  7803. _morphC.addScaledVector(_tempC, influence);
  7804. } else {
  7805. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7806. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7807. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7808. }
  7809. }
  7810. _vA.add(_morphA);
  7811. _vB.add(_morphB);
  7812. _vC.add(_morphC);
  7813. }
  7814. if (object.isSkinnedMesh && material.skinning) {
  7815. object.boneTransform(a, _vA);
  7816. object.boneTransform(b, _vB);
  7817. object.boneTransform(c, _vC);
  7818. }
  7819. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7820. if (intersection) {
  7821. if (uv) {
  7822. _uvA.fromBufferAttribute(uv, a);
  7823. _uvB.fromBufferAttribute(uv, b);
  7824. _uvC.fromBufferAttribute(uv, c);
  7825. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7826. }
  7827. if (uv2) {
  7828. _uvA.fromBufferAttribute(uv2, a);
  7829. _uvB.fromBufferAttribute(uv2, b);
  7830. _uvC.fromBufferAttribute(uv2, c);
  7831. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7832. }
  7833. var face = {
  7834. a: a,
  7835. b: a,
  7836. c: c,
  7837. normal: new Vector3(),
  7838. materialIndex: 0
  7839. };
  7840. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7841. intersection.face = face;
  7842. }
  7843. return intersection;
  7844. }
  7845. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7846. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7847. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7848. var _this;
  7849. if (width === void 0) {
  7850. width = 1;
  7851. }
  7852. if (height === void 0) {
  7853. height = 1;
  7854. }
  7855. if (depth === void 0) {
  7856. depth = 1;
  7857. }
  7858. if (widthSegments === void 0) {
  7859. widthSegments = 1;
  7860. }
  7861. if (heightSegments === void 0) {
  7862. heightSegments = 1;
  7863. }
  7864. if (depthSegments === void 0) {
  7865. depthSegments = 1;
  7866. }
  7867. _this = _BufferGeometry.call(this) || this;
  7868. _this.type = 'BoxGeometry';
  7869. _this.parameters = {
  7870. width: width,
  7871. height: height,
  7872. depth: depth,
  7873. widthSegments: widthSegments,
  7874. heightSegments: heightSegments,
  7875. depthSegments: depthSegments
  7876. };
  7877. var scope = _assertThisInitialized(_this); // segments
  7878. widthSegments = Math.floor(widthSegments);
  7879. heightSegments = Math.floor(heightSegments);
  7880. depthSegments = Math.floor(depthSegments); // buffers
  7881. var indices = [];
  7882. var vertices = [];
  7883. var normals = [];
  7884. var uvs = []; // helper variables
  7885. var numberOfVertices = 0;
  7886. var groupStart = 0; // build each side of the box geometry
  7887. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7888. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7889. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7890. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7891. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7892. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7893. // build geometry
  7894. _this.setIndex(indices);
  7895. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7896. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7897. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7898. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7899. var segmentWidth = width / gridX;
  7900. var segmentHeight = height / gridY;
  7901. var widthHalf = width / 2;
  7902. var heightHalf = height / 2;
  7903. var depthHalf = depth / 2;
  7904. var gridX1 = gridX + 1;
  7905. var gridY1 = gridY + 1;
  7906. var vertexCounter = 0;
  7907. var groupCount = 0;
  7908. var vector = new Vector3(); // generate vertices, normals and uvs
  7909. for (var iy = 0; iy < gridY1; iy++) {
  7910. var y = iy * segmentHeight - heightHalf;
  7911. for (var ix = 0; ix < gridX1; ix++) {
  7912. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7913. vector[u] = x * udir;
  7914. vector[v] = y * vdir;
  7915. vector[w] = depthHalf; // now apply vector to vertex buffer
  7916. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7917. vector[u] = 0;
  7918. vector[v] = 0;
  7919. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7920. normals.push(vector.x, vector.y, vector.z); // uvs
  7921. uvs.push(ix / gridX);
  7922. uvs.push(1 - iy / gridY); // counters
  7923. vertexCounter += 1;
  7924. }
  7925. } // indices
  7926. // 1. you need three indices to draw a single face
  7927. // 2. a single segment consists of two faces
  7928. // 3. so we need to generate six (2*3) indices per segment
  7929. for (var _iy = 0; _iy < gridY; _iy++) {
  7930. for (var _ix = 0; _ix < gridX; _ix++) {
  7931. var a = numberOfVertices + _ix + gridX1 * _iy;
  7932. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7933. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7934. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7935. indices.push(a, b, d);
  7936. indices.push(b, c, d); // increase counter
  7937. groupCount += 6;
  7938. }
  7939. } // add a group to the geometry. this will ensure multi material support
  7940. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7941. groupStart += groupCount; // update total number of vertices
  7942. numberOfVertices += vertexCounter;
  7943. }
  7944. return _this;
  7945. }
  7946. return BoxGeometry;
  7947. }(BufferGeometry);
  7948. /**
  7949. * Uniform Utilities
  7950. */
  7951. function cloneUniforms(src) {
  7952. var dst = {};
  7953. for (var u in src) {
  7954. dst[u] = {};
  7955. for (var p in src[u]) {
  7956. var property = src[u][p];
  7957. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture || property.isQuaternion)) {
  7958. dst[u][p] = property.clone();
  7959. } else if (Array.isArray(property)) {
  7960. dst[u][p] = property.slice();
  7961. } else {
  7962. dst[u][p] = property;
  7963. }
  7964. }
  7965. }
  7966. return dst;
  7967. }
  7968. function mergeUniforms(uniforms) {
  7969. var merged = {};
  7970. for (var u = 0; u < uniforms.length; u++) {
  7971. var tmp = cloneUniforms(uniforms[u]);
  7972. for (var p in tmp) {
  7973. merged[p] = tmp[p];
  7974. }
  7975. }
  7976. return merged;
  7977. } // Legacy
  7978. var UniformsUtils = {
  7979. clone: cloneUniforms,
  7980. merge: mergeUniforms
  7981. };
  7982. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7983. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7984. /**
  7985. * parameters = {
  7986. * defines: { "label" : "value" },
  7987. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7988. *
  7989. * fragmentShader: <string>,
  7990. * vertexShader: <string>,
  7991. *
  7992. * wireframe: <boolean>,
  7993. * wireframeLinewidth: <float>,
  7994. *
  7995. * lights: <bool>,
  7996. *
  7997. * skinning: <bool>,
  7998. * morphTargets: <bool>,
  7999. * morphNormals: <bool>
  8000. * }
  8001. */
  8002. function ShaderMaterial(parameters) {
  8003. Material.call(this);
  8004. this.type = 'ShaderMaterial';
  8005. this.defines = {};
  8006. this.uniforms = {};
  8007. this.vertexShader = default_vertex;
  8008. this.fragmentShader = default_fragment;
  8009. this.linewidth = 1;
  8010. this.wireframe = false;
  8011. this.wireframeLinewidth = 1;
  8012. this.fog = false; // set to use scene fog
  8013. this.lights = false; // set to use scene lights
  8014. this.clipping = false; // set to use user-defined clipping planes
  8015. this.skinning = false; // set to use skinning attribute streams
  8016. this.morphTargets = false; // set to use morph targets
  8017. this.morphNormals = false; // set to use morph normals
  8018. this.extensions = {
  8019. derivatives: false,
  8020. // set to use derivatives
  8021. fragDepth: false,
  8022. // set to use fragment depth values
  8023. drawBuffers: false,
  8024. // set to use draw buffers
  8025. shaderTextureLOD: false // set to use shader texture LOD
  8026. }; // When rendered geometry doesn't include these attributes but the material does,
  8027. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8028. this.defaultAttributeValues = {
  8029. 'color': [1, 1, 1],
  8030. 'uv': [0, 0],
  8031. 'uv2': [0, 0]
  8032. };
  8033. this.index0AttributeName = undefined;
  8034. this.uniformsNeedUpdate = false;
  8035. this.glslVersion = null;
  8036. if (parameters !== undefined) {
  8037. if (parameters.attributes !== undefined) {
  8038. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  8039. }
  8040. this.setValues(parameters);
  8041. }
  8042. }
  8043. ShaderMaterial.prototype = Object.create(Material.prototype);
  8044. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8045. ShaderMaterial.prototype.isShaderMaterial = true;
  8046. ShaderMaterial.prototype.copy = function (source) {
  8047. Material.prototype.copy.call(this, source);
  8048. this.fragmentShader = source.fragmentShader;
  8049. this.vertexShader = source.vertexShader;
  8050. this.uniforms = cloneUniforms(source.uniforms);
  8051. this.defines = Object.assign({}, source.defines);
  8052. this.wireframe = source.wireframe;
  8053. this.wireframeLinewidth = source.wireframeLinewidth;
  8054. this.lights = source.lights;
  8055. this.clipping = source.clipping;
  8056. this.skinning = source.skinning;
  8057. this.morphTargets = source.morphTargets;
  8058. this.morphNormals = source.morphNormals;
  8059. this.extensions = Object.assign({}, source.extensions);
  8060. this.glslVersion = source.glslVersion;
  8061. return this;
  8062. };
  8063. ShaderMaterial.prototype.toJSON = function (meta) {
  8064. var data = Material.prototype.toJSON.call(this, meta);
  8065. data.glslVersion = this.glslVersion;
  8066. data.uniforms = {};
  8067. for (var name in this.uniforms) {
  8068. var uniform = this.uniforms[name];
  8069. var value = uniform.value;
  8070. if (value && value.isTexture) {
  8071. data.uniforms[name] = {
  8072. type: 't',
  8073. value: value.toJSON(meta).uuid
  8074. };
  8075. } else if (value && value.isColor) {
  8076. data.uniforms[name] = {
  8077. type: 'c',
  8078. value: value.getHex()
  8079. };
  8080. } else if (value && value.isVector2) {
  8081. data.uniforms[name] = {
  8082. type: 'v2',
  8083. value: value.toArray()
  8084. };
  8085. } else if (value && value.isVector3) {
  8086. data.uniforms[name] = {
  8087. type: 'v3',
  8088. value: value.toArray()
  8089. };
  8090. } else if (value && value.isVector4) {
  8091. data.uniforms[name] = {
  8092. type: 'v4',
  8093. value: value.toArray()
  8094. };
  8095. } else if (value && value.isMatrix3) {
  8096. data.uniforms[name] = {
  8097. type: 'm3',
  8098. value: value.toArray()
  8099. };
  8100. } else if (value && value.isMatrix4) {
  8101. data.uniforms[name] = {
  8102. type: 'm4',
  8103. value: value.toArray()
  8104. };
  8105. } else {
  8106. data.uniforms[name] = {
  8107. value: value
  8108. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8109. }
  8110. }
  8111. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  8112. data.vertexShader = this.vertexShader;
  8113. data.fragmentShader = this.fragmentShader;
  8114. var extensions = {};
  8115. for (var key in this.extensions) {
  8116. if (this.extensions[key] === true) extensions[key] = true;
  8117. }
  8118. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  8119. return data;
  8120. };
  8121. function Camera() {
  8122. Object3D.call(this);
  8123. this.type = 'Camera';
  8124. this.matrixWorldInverse = new Matrix4();
  8125. this.projectionMatrix = new Matrix4();
  8126. this.projectionMatrixInverse = new Matrix4();
  8127. }
  8128. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  8129. constructor: Camera,
  8130. isCamera: true,
  8131. copy: function copy(source, recursive) {
  8132. Object3D.prototype.copy.call(this, source, recursive);
  8133. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  8134. this.projectionMatrix.copy(source.projectionMatrix);
  8135. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  8136. return this;
  8137. },
  8138. getWorldDirection: function getWorldDirection(target) {
  8139. if (target === undefined) {
  8140. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  8141. target = new Vector3();
  8142. }
  8143. this.updateWorldMatrix(true, false);
  8144. var e = this.matrixWorld.elements;
  8145. return target.set(-e[8], -e[9], -e[10]).normalize();
  8146. },
  8147. updateMatrixWorld: function updateMatrixWorld(force) {
  8148. Object3D.prototype.updateMatrixWorld.call(this, force);
  8149. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8150. },
  8151. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  8152. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  8153. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8154. },
  8155. clone: function clone() {
  8156. return new this.constructor().copy(this);
  8157. }
  8158. });
  8159. function PerspectiveCamera(fov, aspect, near, far) {
  8160. if (fov === void 0) {
  8161. fov = 50;
  8162. }
  8163. if (aspect === void 0) {
  8164. aspect = 1;
  8165. }
  8166. if (near === void 0) {
  8167. near = 0.1;
  8168. }
  8169. if (far === void 0) {
  8170. far = 2000;
  8171. }
  8172. Camera.call(this);
  8173. this.type = 'PerspectiveCamera';
  8174. this.fov = fov;
  8175. this.zoom = 1;
  8176. this.near = near;
  8177. this.far = far;
  8178. this.focus = 10;
  8179. this.aspect = aspect;
  8180. this.view = null;
  8181. this.filmGauge = 35; // width of the film (default in millimeters)
  8182. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8183. this.updateProjectionMatrix();
  8184. }
  8185. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  8186. constructor: PerspectiveCamera,
  8187. isPerspectiveCamera: true,
  8188. copy: function copy(source, recursive) {
  8189. Camera.prototype.copy.call(this, source, recursive);
  8190. this.fov = source.fov;
  8191. this.zoom = source.zoom;
  8192. this.near = source.near;
  8193. this.far = source.far;
  8194. this.focus = source.focus;
  8195. this.aspect = source.aspect;
  8196. this.view = source.view === null ? null : Object.assign({}, source.view);
  8197. this.filmGauge = source.filmGauge;
  8198. this.filmOffset = source.filmOffset;
  8199. return this;
  8200. },
  8201. /**
  8202. * Sets the FOV by focal length in respect to the current .filmGauge.
  8203. *
  8204. * The default film gauge is 35, so that the focal length can be specified for
  8205. * a 35mm (full frame) camera.
  8206. *
  8207. * Values for focal length and film gauge must have the same unit.
  8208. */
  8209. setFocalLength: function setFocalLength(focalLength) {
  8210. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  8211. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8212. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  8213. this.updateProjectionMatrix();
  8214. },
  8215. /**
  8216. * Calculates the focal length from the current .fov and .filmGauge.
  8217. */
  8218. getFocalLength: function getFocalLength() {
  8219. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  8220. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8221. },
  8222. getEffectiveFOV: function getEffectiveFOV() {
  8223. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  8224. },
  8225. getFilmWidth: function getFilmWidth() {
  8226. // film not completely covered in portrait format (aspect < 1)
  8227. return this.filmGauge * Math.min(this.aspect, 1);
  8228. },
  8229. getFilmHeight: function getFilmHeight() {
  8230. // film not completely covered in landscape format (aspect > 1)
  8231. return this.filmGauge / Math.max(this.aspect, 1);
  8232. },
  8233. /**
  8234. * Sets an offset in a larger frustum. This is useful for multi-window or
  8235. * multi-monitor/multi-machine setups.
  8236. *
  8237. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8238. * the monitors are in grid like this
  8239. *
  8240. * +---+---+---+
  8241. * | A | B | C |
  8242. * +---+---+---+
  8243. * | D | E | F |
  8244. * +---+---+---+
  8245. *
  8246. * then for each monitor you would call it like this
  8247. *
  8248. * const w = 1920;
  8249. * const h = 1080;
  8250. * const fullWidth = w * 3;
  8251. * const fullHeight = h * 2;
  8252. *
  8253. * --A--
  8254. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8255. * --B--
  8256. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8257. * --C--
  8258. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8259. * --D--
  8260. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8261. * --E--
  8262. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8263. * --F--
  8264. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8265. *
  8266. * Note there is no reason monitors have to be the same size or in a grid.
  8267. */
  8268. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  8269. this.aspect = fullWidth / fullHeight;
  8270. if (this.view === null) {
  8271. this.view = {
  8272. enabled: true,
  8273. fullWidth: 1,
  8274. fullHeight: 1,
  8275. offsetX: 0,
  8276. offsetY: 0,
  8277. width: 1,
  8278. height: 1
  8279. };
  8280. }
  8281. this.view.enabled = true;
  8282. this.view.fullWidth = fullWidth;
  8283. this.view.fullHeight = fullHeight;
  8284. this.view.offsetX = x;
  8285. this.view.offsetY = y;
  8286. this.view.width = width;
  8287. this.view.height = height;
  8288. this.updateProjectionMatrix();
  8289. },
  8290. clearViewOffset: function clearViewOffset() {
  8291. if (this.view !== null) {
  8292. this.view.enabled = false;
  8293. }
  8294. this.updateProjectionMatrix();
  8295. },
  8296. updateProjectionMatrix: function updateProjectionMatrix() {
  8297. var near = this.near;
  8298. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  8299. var height = 2 * top;
  8300. var width = this.aspect * height;
  8301. var left = -0.5 * width;
  8302. var view = this.view;
  8303. if (this.view !== null && this.view.enabled) {
  8304. var fullWidth = view.fullWidth,
  8305. fullHeight = view.fullHeight;
  8306. left += view.offsetX * width / fullWidth;
  8307. top -= view.offsetY * height / fullHeight;
  8308. width *= view.width / fullWidth;
  8309. height *= view.height / fullHeight;
  8310. }
  8311. var skew = this.filmOffset;
  8312. if (skew !== 0) left += near * skew / this.getFilmWidth();
  8313. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  8314. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  8315. },
  8316. toJSON: function toJSON(meta) {
  8317. var data = Object3D.prototype.toJSON.call(this, meta);
  8318. data.object.fov = this.fov;
  8319. data.object.zoom = this.zoom;
  8320. data.object.near = this.near;
  8321. data.object.far = this.far;
  8322. data.object.focus = this.focus;
  8323. data.object.aspect = this.aspect;
  8324. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  8325. data.object.filmGauge = this.filmGauge;
  8326. data.object.filmOffset = this.filmOffset;
  8327. return data;
  8328. }
  8329. });
  8330. var fov = 90,
  8331. aspect = 1;
  8332. var CubeCamera = /*#__PURE__*/function (_Object3D) {
  8333. _inheritsLoose(CubeCamera, _Object3D);
  8334. function CubeCamera(near, far, renderTarget) {
  8335. var _this;
  8336. _this = _Object3D.call(this) || this;
  8337. _this.type = 'CubeCamera';
  8338. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  8339. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  8340. return _assertThisInitialized(_this);
  8341. }
  8342. _this.renderTarget = renderTarget;
  8343. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  8344. cameraPX.layers = _this.layers;
  8345. cameraPX.up.set(0, -1, 0);
  8346. cameraPX.lookAt(new Vector3(1, 0, 0));
  8347. _this.add(cameraPX);
  8348. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  8349. cameraNX.layers = _this.layers;
  8350. cameraNX.up.set(0, -1, 0);
  8351. cameraNX.lookAt(new Vector3(-1, 0, 0));
  8352. _this.add(cameraNX);
  8353. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  8354. cameraPY.layers = _this.layers;
  8355. cameraPY.up.set(0, 0, 1);
  8356. cameraPY.lookAt(new Vector3(0, 1, 0));
  8357. _this.add(cameraPY);
  8358. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  8359. cameraNY.layers = _this.layers;
  8360. cameraNY.up.set(0, 0, -1);
  8361. cameraNY.lookAt(new Vector3(0, -1, 0));
  8362. _this.add(cameraNY);
  8363. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  8364. cameraPZ.layers = _this.layers;
  8365. cameraPZ.up.set(0, -1, 0);
  8366. cameraPZ.lookAt(new Vector3(0, 0, 1));
  8367. _this.add(cameraPZ);
  8368. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  8369. cameraNZ.layers = _this.layers;
  8370. cameraNZ.up.set(0, -1, 0);
  8371. cameraNZ.lookAt(new Vector3(0, 0, -1));
  8372. _this.add(cameraNZ);
  8373. return _this;
  8374. }
  8375. var _proto = CubeCamera.prototype;
  8376. _proto.update = function update(renderer, scene) {
  8377. if (this.parent === null) this.updateMatrixWorld();
  8378. var renderTarget = this.renderTarget;
  8379. var _this$children = this.children,
  8380. cameraPX = _this$children[0],
  8381. cameraNX = _this$children[1],
  8382. cameraPY = _this$children[2],
  8383. cameraNY = _this$children[3],
  8384. cameraPZ = _this$children[4],
  8385. cameraNZ = _this$children[5];
  8386. var currentXrEnabled = renderer.xr.enabled;
  8387. var currentRenderTarget = renderer.getRenderTarget();
  8388. renderer.xr.enabled = false;
  8389. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8390. renderTarget.texture.generateMipmaps = false;
  8391. renderer.setRenderTarget(renderTarget, 0);
  8392. renderer.render(scene, cameraPX);
  8393. renderer.setRenderTarget(renderTarget, 1);
  8394. renderer.render(scene, cameraNX);
  8395. renderer.setRenderTarget(renderTarget, 2);
  8396. renderer.render(scene, cameraPY);
  8397. renderer.setRenderTarget(renderTarget, 3);
  8398. renderer.render(scene, cameraNY);
  8399. renderer.setRenderTarget(renderTarget, 4);
  8400. renderer.render(scene, cameraPZ);
  8401. renderTarget.texture.generateMipmaps = generateMipmaps;
  8402. renderer.setRenderTarget(renderTarget, 5);
  8403. renderer.render(scene, cameraNZ);
  8404. renderer.setRenderTarget(currentRenderTarget);
  8405. renderer.xr.enabled = currentXrEnabled;
  8406. };
  8407. return CubeCamera;
  8408. }(Object3D);
  8409. var CubeTexture = /*#__PURE__*/function (_Texture) {
  8410. _inheritsLoose(CubeTexture, _Texture);
  8411. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  8412. var _this;
  8413. images = images !== undefined ? images : [];
  8414. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  8415. format = format !== undefined ? format : RGBFormat;
  8416. _this = _Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) || this; // Why CubeTexture._needsFlipEnvMap is necessary:
  8417. //
  8418. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  8419. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  8420. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  8421. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  8422. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  8423. // when using WebGLCubeRenderTarget.texture as a cube texture.
  8424. _this._needsFlipEnvMap = true;
  8425. _this.flipY = false;
  8426. return _this;
  8427. }
  8428. _createClass(CubeTexture, [{
  8429. key: "images",
  8430. get: function get() {
  8431. return this.image;
  8432. },
  8433. set: function set(value) {
  8434. this.image = value;
  8435. }
  8436. }]);
  8437. return CubeTexture;
  8438. }(Texture);
  8439. CubeTexture.prototype.isCubeTexture = true;
  8440. var WebGLCubeRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  8441. _inheritsLoose(WebGLCubeRenderTarget, _WebGLRenderTarget);
  8442. function WebGLCubeRenderTarget(size, options, dummy) {
  8443. var _this;
  8444. if (Number.isInteger(options)) {
  8445. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  8446. options = dummy;
  8447. }
  8448. _this = _WebGLRenderTarget.call(this, size, size, options) || this;
  8449. options = options || {};
  8450. _this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  8451. _this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  8452. _this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  8453. _this.texture._needsFlipEnvMap = false;
  8454. return _this;
  8455. }
  8456. var _proto = WebGLCubeRenderTarget.prototype;
  8457. _proto.fromEquirectangularTexture = function fromEquirectangularTexture(renderer, texture) {
  8458. this.texture.type = texture.type;
  8459. this.texture.format = RGBAFormat; // see #18859
  8460. this.texture.encoding = texture.encoding;
  8461. this.texture.generateMipmaps = texture.generateMipmaps;
  8462. this.texture.minFilter = texture.minFilter;
  8463. this.texture.magFilter = texture.magFilter;
  8464. var shader = {
  8465. uniforms: {
  8466. tEquirect: {
  8467. value: null
  8468. }
  8469. },
  8470. vertexShader:
  8471. /* glsl */
  8472. "\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\n\n\t\t\t\t}\n\t\t\t",
  8473. fragmentShader:
  8474. /* glsl */
  8475. "\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include <common>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"
  8476. };
  8477. var geometry = new BoxGeometry(5, 5, 5);
  8478. var material = new ShaderMaterial({
  8479. name: 'CubemapFromEquirect',
  8480. uniforms: cloneUniforms(shader.uniforms),
  8481. vertexShader: shader.vertexShader,
  8482. fragmentShader: shader.fragmentShader,
  8483. side: BackSide,
  8484. blending: NoBlending
  8485. });
  8486. material.uniforms.tEquirect.value = texture;
  8487. var mesh = new Mesh(geometry, material);
  8488. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8489. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8490. var camera = new CubeCamera(1, 10, this);
  8491. camera.update(renderer, mesh);
  8492. texture.minFilter = currentMinFilter;
  8493. mesh.geometry.dispose();
  8494. mesh.material.dispose();
  8495. return this;
  8496. };
  8497. _proto.clear = function clear(renderer, color, depth, stencil) {
  8498. var currentRenderTarget = renderer.getRenderTarget();
  8499. for (var i = 0; i < 6; i++) {
  8500. renderer.setRenderTarget(this, i);
  8501. renderer.clear(color, depth, stencil);
  8502. }
  8503. renderer.setRenderTarget(currentRenderTarget);
  8504. };
  8505. return WebGLCubeRenderTarget;
  8506. }(WebGLRenderTarget);
  8507. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  8508. var DataTexture = /*#__PURE__*/function (_Texture) {
  8509. _inheritsLoose(DataTexture, _Texture);
  8510. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8511. var _this;
  8512. _this = _Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) || this;
  8513. _this.image = {
  8514. data: data || null,
  8515. width: width || 1,
  8516. height: height || 1
  8517. };
  8518. _this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8519. _this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8520. _this.generateMipmaps = false;
  8521. _this.flipY = false;
  8522. _this.unpackAlignment = 1;
  8523. _this.needsUpdate = true;
  8524. return _this;
  8525. }
  8526. return DataTexture;
  8527. }(Texture);
  8528. DataTexture.prototype.isDataTexture = true;
  8529. var _sphere$1 = /*@__PURE__*/new Sphere();
  8530. var _vector$5 = /*@__PURE__*/new Vector3();
  8531. var Frustum = /*#__PURE__*/function () {
  8532. function Frustum(p0, p1, p2, p3, p4, p5) {
  8533. if (p0 === void 0) {
  8534. p0 = new Plane();
  8535. }
  8536. if (p1 === void 0) {
  8537. p1 = new Plane();
  8538. }
  8539. if (p2 === void 0) {
  8540. p2 = new Plane();
  8541. }
  8542. if (p3 === void 0) {
  8543. p3 = new Plane();
  8544. }
  8545. if (p4 === void 0) {
  8546. p4 = new Plane();
  8547. }
  8548. if (p5 === void 0) {
  8549. p5 = new Plane();
  8550. }
  8551. this.planes = [p0, p1, p2, p3, p4, p5];
  8552. }
  8553. var _proto = Frustum.prototype;
  8554. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8555. var planes = this.planes;
  8556. planes[0].copy(p0);
  8557. planes[1].copy(p1);
  8558. planes[2].copy(p2);
  8559. planes[3].copy(p3);
  8560. planes[4].copy(p4);
  8561. planes[5].copy(p5);
  8562. return this;
  8563. };
  8564. _proto.copy = function copy(frustum) {
  8565. var planes = this.planes;
  8566. for (var i = 0; i < 6; i++) {
  8567. planes[i].copy(frustum.planes[i]);
  8568. }
  8569. return this;
  8570. };
  8571. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8572. var planes = this.planes;
  8573. var me = m.elements;
  8574. var me0 = me[0],
  8575. me1 = me[1],
  8576. me2 = me[2],
  8577. me3 = me[3];
  8578. var me4 = me[4],
  8579. me5 = me[5],
  8580. me6 = me[6],
  8581. me7 = me[7];
  8582. var me8 = me[8],
  8583. me9 = me[9],
  8584. me10 = me[10],
  8585. me11 = me[11];
  8586. var me12 = me[12],
  8587. me13 = me[13],
  8588. me14 = me[14],
  8589. me15 = me[15];
  8590. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8591. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8592. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8593. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8594. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8595. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8596. return this;
  8597. };
  8598. _proto.intersectsObject = function intersectsObject(object) {
  8599. var geometry = object.geometry;
  8600. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8601. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8602. return this.intersectsSphere(_sphere$1);
  8603. };
  8604. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8605. _sphere$1.center.set(0, 0, 0);
  8606. _sphere$1.radius = 0.7071067811865476;
  8607. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8608. return this.intersectsSphere(_sphere$1);
  8609. };
  8610. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8611. var planes = this.planes;
  8612. var center = sphere.center;
  8613. var negRadius = -sphere.radius;
  8614. for (var i = 0; i < 6; i++) {
  8615. var distance = planes[i].distanceToPoint(center);
  8616. if (distance < negRadius) {
  8617. return false;
  8618. }
  8619. }
  8620. return true;
  8621. };
  8622. _proto.intersectsBox = function intersectsBox(box) {
  8623. var planes = this.planes;
  8624. for (var i = 0; i < 6; i++) {
  8625. var plane = planes[i]; // corner at max distance
  8626. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8627. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8628. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8629. if (plane.distanceToPoint(_vector$5) < 0) {
  8630. return false;
  8631. }
  8632. }
  8633. return true;
  8634. };
  8635. _proto.containsPoint = function containsPoint(point) {
  8636. var planes = this.planes;
  8637. for (var i = 0; i < 6; i++) {
  8638. if (planes[i].distanceToPoint(point) < 0) {
  8639. return false;
  8640. }
  8641. }
  8642. return true;
  8643. };
  8644. _proto.clone = function clone() {
  8645. return new this.constructor().copy(this);
  8646. };
  8647. return Frustum;
  8648. }();
  8649. function WebGLAnimation() {
  8650. var context = null;
  8651. var isAnimating = false;
  8652. var animationLoop = null;
  8653. var requestId = null;
  8654. function onAnimationFrame(time, frame) {
  8655. animationLoop(time, frame);
  8656. requestId = context.requestAnimationFrame(onAnimationFrame);
  8657. }
  8658. return {
  8659. start: function start() {
  8660. if (isAnimating === true) return;
  8661. if (animationLoop === null) return;
  8662. requestId = context.requestAnimationFrame(onAnimationFrame);
  8663. isAnimating = true;
  8664. },
  8665. stop: function stop() {
  8666. context.cancelAnimationFrame(requestId);
  8667. isAnimating = false;
  8668. },
  8669. setAnimationLoop: function setAnimationLoop(callback) {
  8670. animationLoop = callback;
  8671. },
  8672. setContext: function setContext(value) {
  8673. context = value;
  8674. }
  8675. };
  8676. }
  8677. function WebGLAttributes(gl, capabilities) {
  8678. var isWebGL2 = capabilities.isWebGL2;
  8679. var buffers = new WeakMap();
  8680. function createBuffer(attribute, bufferType) {
  8681. var array = attribute.array;
  8682. var usage = attribute.usage;
  8683. var buffer = gl.createBuffer();
  8684. gl.bindBuffer(bufferType, buffer);
  8685. gl.bufferData(bufferType, array, usage);
  8686. attribute.onUploadCallback();
  8687. var type = 5126;
  8688. if (array instanceof Float32Array) {
  8689. type = 5126;
  8690. } else if (array instanceof Float64Array) {
  8691. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8692. } else if (array instanceof Uint16Array) {
  8693. if (attribute.isFloat16BufferAttribute) {
  8694. if (isWebGL2) {
  8695. type = 5131;
  8696. } else {
  8697. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8698. }
  8699. } else {
  8700. type = 5123;
  8701. }
  8702. } else if (array instanceof Int16Array) {
  8703. type = 5122;
  8704. } else if (array instanceof Uint32Array) {
  8705. type = 5125;
  8706. } else if (array instanceof Int32Array) {
  8707. type = 5124;
  8708. } else if (array instanceof Int8Array) {
  8709. type = 5120;
  8710. } else if (array instanceof Uint8Array) {
  8711. type = 5121;
  8712. }
  8713. return {
  8714. buffer: buffer,
  8715. type: type,
  8716. bytesPerElement: array.BYTES_PER_ELEMENT,
  8717. version: attribute.version
  8718. };
  8719. }
  8720. function updateBuffer(buffer, attribute, bufferType) {
  8721. var array = attribute.array;
  8722. var updateRange = attribute.updateRange;
  8723. gl.bindBuffer(bufferType, buffer);
  8724. if (updateRange.count === -1) {
  8725. // Not using update ranges
  8726. gl.bufferSubData(bufferType, 0, array);
  8727. } else {
  8728. if (isWebGL2) {
  8729. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8730. } else {
  8731. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8732. }
  8733. updateRange.count = -1; // reset range
  8734. }
  8735. } //
  8736. function get(attribute) {
  8737. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8738. return buffers.get(attribute);
  8739. }
  8740. function remove(attribute) {
  8741. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8742. var data = buffers.get(attribute);
  8743. if (data) {
  8744. gl.deleteBuffer(data.buffer);
  8745. buffers.delete(attribute);
  8746. }
  8747. }
  8748. function update(attribute, bufferType) {
  8749. if (attribute.isGLBufferAttribute) {
  8750. var cached = buffers.get(attribute);
  8751. if (!cached || cached.version < attribute.version) {
  8752. buffers.set(attribute, {
  8753. buffer: attribute.buffer,
  8754. type: attribute.type,
  8755. bytesPerElement: attribute.elementSize,
  8756. version: attribute.version
  8757. });
  8758. }
  8759. return;
  8760. }
  8761. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8762. var data = buffers.get(attribute);
  8763. if (data === undefined) {
  8764. buffers.set(attribute, createBuffer(attribute, bufferType));
  8765. } else if (data.version < attribute.version) {
  8766. updateBuffer(data.buffer, attribute, bufferType);
  8767. data.version = attribute.version;
  8768. }
  8769. }
  8770. return {
  8771. get: get,
  8772. remove: remove,
  8773. update: update
  8774. };
  8775. }
  8776. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8777. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8778. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8779. var _this;
  8780. if (width === void 0) {
  8781. width = 1;
  8782. }
  8783. if (height === void 0) {
  8784. height = 1;
  8785. }
  8786. if (widthSegments === void 0) {
  8787. widthSegments = 1;
  8788. }
  8789. if (heightSegments === void 0) {
  8790. heightSegments = 1;
  8791. }
  8792. _this = _BufferGeometry.call(this) || this;
  8793. _this.type = 'PlaneGeometry';
  8794. _this.parameters = {
  8795. width: width,
  8796. height: height,
  8797. widthSegments: widthSegments,
  8798. heightSegments: heightSegments
  8799. };
  8800. var width_half = width / 2;
  8801. var height_half = height / 2;
  8802. var gridX = Math.floor(widthSegments);
  8803. var gridY = Math.floor(heightSegments);
  8804. var gridX1 = gridX + 1;
  8805. var gridY1 = gridY + 1;
  8806. var segment_width = width / gridX;
  8807. var segment_height = height / gridY; //
  8808. var indices = [];
  8809. var vertices = [];
  8810. var normals = [];
  8811. var uvs = [];
  8812. for (var iy = 0; iy < gridY1; iy++) {
  8813. var y = iy * segment_height - height_half;
  8814. for (var ix = 0; ix < gridX1; ix++) {
  8815. var x = ix * segment_width - width_half;
  8816. vertices.push(x, -y, 0);
  8817. normals.push(0, 0, 1);
  8818. uvs.push(ix / gridX);
  8819. uvs.push(1 - iy / gridY);
  8820. }
  8821. }
  8822. for (var _iy = 0; _iy < gridY; _iy++) {
  8823. for (var _ix = 0; _ix < gridX; _ix++) {
  8824. var a = _ix + gridX1 * _iy;
  8825. var b = _ix + gridX1 * (_iy + 1);
  8826. var c = _ix + 1 + gridX1 * (_iy + 1);
  8827. var d = _ix + 1 + gridX1 * _iy;
  8828. indices.push(a, b, d);
  8829. indices.push(b, c, d);
  8830. }
  8831. }
  8832. _this.setIndex(indices);
  8833. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8834. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8835. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8836. return _this;
  8837. }
  8838. return PlaneGeometry;
  8839. }(BufferGeometry);
  8840. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8841. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8842. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8843. var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif";
  8844. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8845. var begin_vertex = "vec3 transformed = vec3( position );";
  8846. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8847. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie(float roughness, float NoH) {\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125);\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\nfloat V_Neubelt(float NoV, float NoL) {\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif";
  8848. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  8849. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";
  8850. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8851. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8852. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8853. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8854. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8855. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8856. var color_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor.xyz *= color.xyz;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif";
  8857. var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}";
  8858. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_maxMipLevel 8.0\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_maxTileSize 256.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\tfloat texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );\n\t\tvec2 uv = getUV( direction, face ) * ( faceSize - 1.0 );\n\t\tvec2 f = fract( uv );\n\t\tuv += 0.5 - f;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tif ( mipInt < cubeUV_maxMipLevel ) {\n\t\t\tuv.y += 2.0 * cubeUV_maxTileSize;\n\t\t}\n\t\tuv.y += filterInt * 2.0 * cubeUV_minTileSize;\n\t\tuv.x += 3.0 * max( 0.0, cubeUV_maxTileSize - 2.0 * faceSize );\n\t\tuv *= texelSize;\n\t\tvec3 tl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x += texelSize;\n\t\tvec3 tr = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.y += texelSize;\n\t\tvec3 br = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x -= texelSize;\n\t\tvec3 bl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tvec3 tm = mix( tl, tr, f.x );\n\t\tvec3 bm = mix( bl, br, f.x );\n\t\treturn mix( tm, bm, f.y );\n\t}\n\t#define r0 1.0\n\t#define v0 0.339\n\t#define m0 - 2.0\n\t#define r1 0.8\n\t#define v1 0.276\n\t#define m1 - 1.0\n\t#define r4 0.4\n\t#define v4 0.046\n\t#define m4 2.0\n\t#define r5 0.305\n\t#define v5 0.016\n\t#define m5 3.0\n\t#define r6 0.21\n\t#define v6 0.0038\n\t#define m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= r1 ) {\n\t\t\tmip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;\n\t\t} else if ( roughness >= r4 ) {\n\t\t\tmip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;\n\t\t} else if ( roughness >= r5 ) {\n\t\t\tmip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;\n\t\t} else if ( roughness >= r6 ) {\n\t\t\tmip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), m0, cubeUV_maxMipLevel );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif";
  8859. var defaultnormal_vertex = "vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";
  8860. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8861. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8862. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8863. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8864. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8865. var encodings_pars_fragment = "\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn 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 );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = clamp( floor( D ) / 255.0, 0.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = cLogLuvM * value.rgb;\n\tXp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract( Le );\n\tvResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";
  8866. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
  8867. var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif";
  8868. var envmap_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
  8869. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";
  8870. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif";
  8871. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8872. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8873. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";
  8874. var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif";
  8875. var gradientmap_pars_fragment = "#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn texture2D( gradientMap, coord ).rgb;\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}";
  8876. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8877. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8878. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif";
  8879. var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {\n\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";
  8880. var envmap_physical_pars_fragment = "#if defined( USE_ENVMAP )\n\t#ifdef ENVMAP_MODE_REFRACTION\n\t\tuniform float refractionRatio;\n\t#endif\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat sigma = PI * roughness * roughness / ( 1.0 + roughness );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + log2( sigma );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -viewDir, normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";
  8881. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8882. var lights_toon_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD( material )\t(0)";
  8883. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8884. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)";
  8885. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.specularRoughness = max( roughnessFactor, 0.0525 );material.specularRoughness += geometryRoughness;\nmaterial.specularRoughness = min( material.specularRoughness, 1.0 );\n#ifdef REFLECTIVITY\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#endif\n#ifdef CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheen;\n#endif";
  8886. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat specularRoughness;\n\tvec3 specularColor;\n#ifdef CLEARCOAT\n\tfloat clearcoat;\n\tfloat clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tvec3 sheenColor;\n#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearcoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNL = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = ccDotNL * directLight.color;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tccIrradiance *= PI;\n\t\t#endif\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t\treflectedLight.directSpecular += ccIrradiance * material.clearcoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_Sheen(\n\t\t\tmaterial.specularRoughness,\n\t\t\tdirectLight.direction,\n\t\t\tgeometry,\n\t\t\tmaterial.sheenColor\n\t\t);\n\t#else\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness);\n\t#endif\n\treflectedLight.directDiffuse += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNV = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular += clearcoatRadiance * material.clearcoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t\tfloat ccDotNL = ccDotNV;\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\tfloat clearcoatInv = 1.0 - clearcoatDHR;\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += clearcoatInv * radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
  8887. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";
  8888. var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );\n\t#ifdef CLEARCOAT\n\t\tclearcoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness, maxMipLevel );\n\t#endif\n#endif";
  8889. var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif";
  8890. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  8891. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif";
  8892. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";
  8893. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif";
  8894. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8895. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8896. var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";
  8897. var map_particle_pars_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8898. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8899. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8900. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n#endif";
  8901. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifndef USE_MORPHNORMALS\n\t\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\t\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  8902. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
  8903. var normal_fragment_begin = "float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * faceDirection;\n\t\t\tbitangent = bitangent * faceDirection;\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";
  8904. var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN, faceDirection );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif";
  8905. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : faceDirection * inversesqrt( det );\n\t\treturn normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z );\n\t}\n#endif";
  8906. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8907. var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );\n\t#endif\n#endif";
  8908. var clearcoat_pars_fragment = "#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif";
  8909. var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}";
  8910. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8911. var project_vertex = "vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;";
  8912. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8913. var dithering_pars_fragment = "#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";
  8914. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8915. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8916. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";
  8917. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";
  8918. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\tvec4 shadowWorldPosition;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif";
  8919. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";
  8920. var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
  8921. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
  8922. var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";
  8923. var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";
  8924. var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";
  8925. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8926. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8927. var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }";
  8928. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8929. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8930. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8931. var uv_pars_vertex = "#ifdef USE_UV\n\t#ifdef UVS_VERTEX_ONLY\n\t\tvec2 vUv;\n\t#else\n\t\tvarying vec2 vUv;\n\t#endif\n\tuniform mat3 uvTransform;\n#endif";
  8932. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8933. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8934. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif";
  8935. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8936. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif";
  8937. var background_frag = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8938. var background_vert = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";
  8939. var cube_frag = "#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8940. var cube_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
  8941. var depth_frag = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#endif\n}";
  8942. var depth_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}";
  8943. var distanceRGBA_frag = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";
  8944. var distanceRGBA_vert = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";
  8945. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  8946. var equirect_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
  8947. var linedashed_frag = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  8948. var linedashed_vert = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  8949. var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8950. var meshbasic_vert = "#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";
  8951. var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8952. var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8953. var meshmatcap_frag = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8954. var meshmatcap_vert = "#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
  8955. var meshtoon_frag = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8956. var meshtoon_vert = "#define TOON\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8957. var meshphong_frag = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8958. var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8959. var meshphysical_frag = "#define STANDARD\n#ifdef PHYSICAL\n\t#define REFLECTIVITY\n\t#define CLEARCOAT\n\t#define TRANSMISSION\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef TRANSMISSION\n\tuniform float transmission;\n#endif\n#ifdef REFLECTIVITY\n\tuniform float reflectivity;\n#endif\n#ifdef CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheen;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <transmissionmap_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#ifdef TRANSMISSION\n\t\tfloat totalTransmission = transmission;\n\t#endif\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <transmissionmap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSMISSION\n\t\tdiffuseColor.a *= mix( saturate( 1. - totalTransmission + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) ), 1.0, metalness );\n\t#endif\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  8960. var meshphysical_vert = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8961. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
  8962. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  8963. var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
  8964. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";
  8965. var shadow_frag = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8966. var shadow_vert = "#include <common>\n#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  8967. var sprite_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  8968. var sprite_vert = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  8969. var ShaderChunk = {
  8970. alphamap_fragment: alphamap_fragment,
  8971. alphamap_pars_fragment: alphamap_pars_fragment,
  8972. alphatest_fragment: alphatest_fragment,
  8973. aomap_fragment: aomap_fragment,
  8974. aomap_pars_fragment: aomap_pars_fragment,
  8975. begin_vertex: begin_vertex,
  8976. beginnormal_vertex: beginnormal_vertex,
  8977. bsdfs: bsdfs,
  8978. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8979. clipping_planes_fragment: clipping_planes_fragment,
  8980. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8981. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8982. clipping_planes_vertex: clipping_planes_vertex,
  8983. color_fragment: color_fragment,
  8984. color_pars_fragment: color_pars_fragment,
  8985. color_pars_vertex: color_pars_vertex,
  8986. color_vertex: color_vertex,
  8987. common: common,
  8988. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8989. defaultnormal_vertex: defaultnormal_vertex,
  8990. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8991. displacementmap_vertex: displacementmap_vertex,
  8992. emissivemap_fragment: emissivemap_fragment,
  8993. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8994. encodings_fragment: encodings_fragment,
  8995. encodings_pars_fragment: encodings_pars_fragment,
  8996. envmap_fragment: envmap_fragment,
  8997. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8998. envmap_pars_fragment: envmap_pars_fragment,
  8999. envmap_pars_vertex: envmap_pars_vertex,
  9000. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  9001. envmap_vertex: envmap_vertex,
  9002. fog_vertex: fog_vertex,
  9003. fog_pars_vertex: fog_pars_vertex,
  9004. fog_fragment: fog_fragment,
  9005. fog_pars_fragment: fog_pars_fragment,
  9006. gradientmap_pars_fragment: gradientmap_pars_fragment,
  9007. lightmap_fragment: lightmap_fragment,
  9008. lightmap_pars_fragment: lightmap_pars_fragment,
  9009. lights_lambert_vertex: lights_lambert_vertex,
  9010. lights_pars_begin: lights_pars_begin,
  9011. lights_toon_fragment: lights_toon_fragment,
  9012. lights_toon_pars_fragment: lights_toon_pars_fragment,
  9013. lights_phong_fragment: lights_phong_fragment,
  9014. lights_phong_pars_fragment: lights_phong_pars_fragment,
  9015. lights_physical_fragment: lights_physical_fragment,
  9016. lights_physical_pars_fragment: lights_physical_pars_fragment,
  9017. lights_fragment_begin: lights_fragment_begin,
  9018. lights_fragment_maps: lights_fragment_maps,
  9019. lights_fragment_end: lights_fragment_end,
  9020. logdepthbuf_fragment: logdepthbuf_fragment,
  9021. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9022. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9023. logdepthbuf_vertex: logdepthbuf_vertex,
  9024. map_fragment: map_fragment,
  9025. map_pars_fragment: map_pars_fragment,
  9026. map_particle_fragment: map_particle_fragment,
  9027. map_particle_pars_fragment: map_particle_pars_fragment,
  9028. metalnessmap_fragment: metalnessmap_fragment,
  9029. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9030. morphnormal_vertex: morphnormal_vertex,
  9031. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9032. morphtarget_vertex: morphtarget_vertex,
  9033. normal_fragment_begin: normal_fragment_begin,
  9034. normal_fragment_maps: normal_fragment_maps,
  9035. normalmap_pars_fragment: normalmap_pars_fragment,
  9036. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9037. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9038. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9039. packing: packing,
  9040. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9041. project_vertex: project_vertex,
  9042. dithering_fragment: dithering_fragment,
  9043. dithering_pars_fragment: dithering_pars_fragment,
  9044. roughnessmap_fragment: roughnessmap_fragment,
  9045. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9046. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9047. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9048. shadowmap_vertex: shadowmap_vertex,
  9049. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9050. skinbase_vertex: skinbase_vertex,
  9051. skinning_pars_vertex: skinning_pars_vertex,
  9052. skinning_vertex: skinning_vertex,
  9053. skinnormal_vertex: skinnormal_vertex,
  9054. specularmap_fragment: specularmap_fragment,
  9055. specularmap_pars_fragment: specularmap_pars_fragment,
  9056. tonemapping_fragment: tonemapping_fragment,
  9057. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9058. transmissionmap_fragment: transmissionmap_fragment,
  9059. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  9060. uv_pars_fragment: uv_pars_fragment,
  9061. uv_pars_vertex: uv_pars_vertex,
  9062. uv_vertex: uv_vertex,
  9063. uv2_pars_fragment: uv2_pars_fragment,
  9064. uv2_pars_vertex: uv2_pars_vertex,
  9065. uv2_vertex: uv2_vertex,
  9066. worldpos_vertex: worldpos_vertex,
  9067. background_frag: background_frag,
  9068. background_vert: background_vert,
  9069. cube_frag: cube_frag,
  9070. cube_vert: cube_vert,
  9071. depth_frag: depth_frag,
  9072. depth_vert: depth_vert,
  9073. distanceRGBA_frag: distanceRGBA_frag,
  9074. distanceRGBA_vert: distanceRGBA_vert,
  9075. equirect_frag: equirect_frag,
  9076. equirect_vert: equirect_vert,
  9077. linedashed_frag: linedashed_frag,
  9078. linedashed_vert: linedashed_vert,
  9079. meshbasic_frag: meshbasic_frag,
  9080. meshbasic_vert: meshbasic_vert,
  9081. meshlambert_frag: meshlambert_frag,
  9082. meshlambert_vert: meshlambert_vert,
  9083. meshmatcap_frag: meshmatcap_frag,
  9084. meshmatcap_vert: meshmatcap_vert,
  9085. meshtoon_frag: meshtoon_frag,
  9086. meshtoon_vert: meshtoon_vert,
  9087. meshphong_frag: meshphong_frag,
  9088. meshphong_vert: meshphong_vert,
  9089. meshphysical_frag: meshphysical_frag,
  9090. meshphysical_vert: meshphysical_vert,
  9091. normal_frag: normal_frag,
  9092. normal_vert: normal_vert,
  9093. points_frag: points_frag,
  9094. points_vert: points_vert,
  9095. shadow_frag: shadow_frag,
  9096. shadow_vert: shadow_vert,
  9097. sprite_frag: sprite_frag,
  9098. sprite_vert: sprite_vert
  9099. };
  9100. /**
  9101. * Uniforms library for shared webgl shaders
  9102. */
  9103. var UniformsLib = {
  9104. common: {
  9105. diffuse: {
  9106. value: new Color(0xeeeeee)
  9107. },
  9108. opacity: {
  9109. value: 1.0
  9110. },
  9111. map: {
  9112. value: null
  9113. },
  9114. uvTransform: {
  9115. value: new Matrix3()
  9116. },
  9117. uv2Transform: {
  9118. value: new Matrix3()
  9119. },
  9120. alphaMap: {
  9121. value: null
  9122. }
  9123. },
  9124. specularmap: {
  9125. specularMap: {
  9126. value: null
  9127. }
  9128. },
  9129. envmap: {
  9130. envMap: {
  9131. value: null
  9132. },
  9133. flipEnvMap: {
  9134. value: -1
  9135. },
  9136. reflectivity: {
  9137. value: 1.0
  9138. },
  9139. refractionRatio: {
  9140. value: 0.98
  9141. },
  9142. maxMipLevel: {
  9143. value: 0
  9144. }
  9145. },
  9146. aomap: {
  9147. aoMap: {
  9148. value: null
  9149. },
  9150. aoMapIntensity: {
  9151. value: 1
  9152. }
  9153. },
  9154. lightmap: {
  9155. lightMap: {
  9156. value: null
  9157. },
  9158. lightMapIntensity: {
  9159. value: 1
  9160. }
  9161. },
  9162. emissivemap: {
  9163. emissiveMap: {
  9164. value: null
  9165. }
  9166. },
  9167. bumpmap: {
  9168. bumpMap: {
  9169. value: null
  9170. },
  9171. bumpScale: {
  9172. value: 1
  9173. }
  9174. },
  9175. normalmap: {
  9176. normalMap: {
  9177. value: null
  9178. },
  9179. normalScale: {
  9180. value: new Vector2(1, 1)
  9181. }
  9182. },
  9183. displacementmap: {
  9184. displacementMap: {
  9185. value: null
  9186. },
  9187. displacementScale: {
  9188. value: 1
  9189. },
  9190. displacementBias: {
  9191. value: 0
  9192. }
  9193. },
  9194. roughnessmap: {
  9195. roughnessMap: {
  9196. value: null
  9197. }
  9198. },
  9199. metalnessmap: {
  9200. metalnessMap: {
  9201. value: null
  9202. }
  9203. },
  9204. gradientmap: {
  9205. gradientMap: {
  9206. value: null
  9207. }
  9208. },
  9209. fog: {
  9210. fogDensity: {
  9211. value: 0.00025
  9212. },
  9213. fogNear: {
  9214. value: 1
  9215. },
  9216. fogFar: {
  9217. value: 2000
  9218. },
  9219. fogColor: {
  9220. value: new Color(0xffffff)
  9221. }
  9222. },
  9223. lights: {
  9224. ambientLightColor: {
  9225. value: []
  9226. },
  9227. lightProbe: {
  9228. value: []
  9229. },
  9230. directionalLights: {
  9231. value: [],
  9232. properties: {
  9233. direction: {},
  9234. color: {}
  9235. }
  9236. },
  9237. directionalLightShadows: {
  9238. value: [],
  9239. properties: {
  9240. shadowBias: {},
  9241. shadowNormalBias: {},
  9242. shadowRadius: {},
  9243. shadowMapSize: {}
  9244. }
  9245. },
  9246. directionalShadowMap: {
  9247. value: []
  9248. },
  9249. directionalShadowMatrix: {
  9250. value: []
  9251. },
  9252. spotLights: {
  9253. value: [],
  9254. properties: {
  9255. color: {},
  9256. position: {},
  9257. direction: {},
  9258. distance: {},
  9259. coneCos: {},
  9260. penumbraCos: {},
  9261. decay: {}
  9262. }
  9263. },
  9264. spotLightShadows: {
  9265. value: [],
  9266. properties: {
  9267. shadowBias: {},
  9268. shadowNormalBias: {},
  9269. shadowRadius: {},
  9270. shadowMapSize: {}
  9271. }
  9272. },
  9273. spotShadowMap: {
  9274. value: []
  9275. },
  9276. spotShadowMatrix: {
  9277. value: []
  9278. },
  9279. pointLights: {
  9280. value: [],
  9281. properties: {
  9282. color: {},
  9283. position: {},
  9284. decay: {},
  9285. distance: {}
  9286. }
  9287. },
  9288. pointLightShadows: {
  9289. value: [],
  9290. properties: {
  9291. shadowBias: {},
  9292. shadowNormalBias: {},
  9293. shadowRadius: {},
  9294. shadowMapSize: {},
  9295. shadowCameraNear: {},
  9296. shadowCameraFar: {}
  9297. }
  9298. },
  9299. pointShadowMap: {
  9300. value: []
  9301. },
  9302. pointShadowMatrix: {
  9303. value: []
  9304. },
  9305. hemisphereLights: {
  9306. value: [],
  9307. properties: {
  9308. direction: {},
  9309. skyColor: {},
  9310. groundColor: {}
  9311. }
  9312. },
  9313. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9314. rectAreaLights: {
  9315. value: [],
  9316. properties: {
  9317. color: {},
  9318. position: {},
  9319. width: {},
  9320. height: {}
  9321. }
  9322. },
  9323. ltc_1: {
  9324. value: null
  9325. },
  9326. ltc_2: {
  9327. value: null
  9328. }
  9329. },
  9330. points: {
  9331. diffuse: {
  9332. value: new Color(0xeeeeee)
  9333. },
  9334. opacity: {
  9335. value: 1.0
  9336. },
  9337. size: {
  9338. value: 1.0
  9339. },
  9340. scale: {
  9341. value: 1.0
  9342. },
  9343. map: {
  9344. value: null
  9345. },
  9346. alphaMap: {
  9347. value: null
  9348. },
  9349. uvTransform: {
  9350. value: new Matrix3()
  9351. }
  9352. },
  9353. sprite: {
  9354. diffuse: {
  9355. value: new Color(0xeeeeee)
  9356. },
  9357. opacity: {
  9358. value: 1.0
  9359. },
  9360. center: {
  9361. value: new Vector2(0.5, 0.5)
  9362. },
  9363. rotation: {
  9364. value: 0.0
  9365. },
  9366. map: {
  9367. value: null
  9368. },
  9369. alphaMap: {
  9370. value: null
  9371. },
  9372. uvTransform: {
  9373. value: new Matrix3()
  9374. }
  9375. }
  9376. };
  9377. var ShaderLib = {
  9378. basic: {
  9379. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  9380. vertexShader: ShaderChunk.meshbasic_vert,
  9381. fragmentShader: ShaderChunk.meshbasic_frag
  9382. },
  9383. lambert: {
  9384. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  9385. emissive: {
  9386. value: new Color(0x000000)
  9387. }
  9388. }]),
  9389. vertexShader: ShaderChunk.meshlambert_vert,
  9390. fragmentShader: ShaderChunk.meshlambert_frag
  9391. },
  9392. phong: {
  9393. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  9394. emissive: {
  9395. value: new Color(0x000000)
  9396. },
  9397. specular: {
  9398. value: new Color(0x111111)
  9399. },
  9400. shininess: {
  9401. value: 30
  9402. }
  9403. }]),
  9404. vertexShader: ShaderChunk.meshphong_vert,
  9405. fragmentShader: ShaderChunk.meshphong_frag
  9406. },
  9407. standard: {
  9408. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.roughnessmap, UniformsLib.metalnessmap, UniformsLib.fog, UniformsLib.lights, {
  9409. emissive: {
  9410. value: new Color(0x000000)
  9411. },
  9412. roughness: {
  9413. value: 1.0
  9414. },
  9415. metalness: {
  9416. value: 0.0
  9417. },
  9418. envMapIntensity: {
  9419. value: 1
  9420. } // temporary
  9421. }]),
  9422. vertexShader: ShaderChunk.meshphysical_vert,
  9423. fragmentShader: ShaderChunk.meshphysical_frag
  9424. },
  9425. toon: {
  9426. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  9427. emissive: {
  9428. value: new Color(0x000000)
  9429. }
  9430. }]),
  9431. vertexShader: ShaderChunk.meshtoon_vert,
  9432. fragmentShader: ShaderChunk.meshtoon_frag
  9433. },
  9434. matcap: {
  9435. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  9436. matcap: {
  9437. value: null
  9438. }
  9439. }]),
  9440. vertexShader: ShaderChunk.meshmatcap_vert,
  9441. fragmentShader: ShaderChunk.meshmatcap_frag
  9442. },
  9443. points: {
  9444. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  9445. vertexShader: ShaderChunk.points_vert,
  9446. fragmentShader: ShaderChunk.points_frag
  9447. },
  9448. dashed: {
  9449. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  9450. scale: {
  9451. value: 1
  9452. },
  9453. dashSize: {
  9454. value: 1
  9455. },
  9456. totalSize: {
  9457. value: 2
  9458. }
  9459. }]),
  9460. vertexShader: ShaderChunk.linedashed_vert,
  9461. fragmentShader: ShaderChunk.linedashed_frag
  9462. },
  9463. depth: {
  9464. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  9465. vertexShader: ShaderChunk.depth_vert,
  9466. fragmentShader: ShaderChunk.depth_frag
  9467. },
  9468. normal: {
  9469. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  9470. opacity: {
  9471. value: 1.0
  9472. }
  9473. }]),
  9474. vertexShader: ShaderChunk.normal_vert,
  9475. fragmentShader: ShaderChunk.normal_frag
  9476. },
  9477. sprite: {
  9478. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  9479. vertexShader: ShaderChunk.sprite_vert,
  9480. fragmentShader: ShaderChunk.sprite_frag
  9481. },
  9482. background: {
  9483. uniforms: {
  9484. uvTransform: {
  9485. value: new Matrix3()
  9486. },
  9487. t2D: {
  9488. value: null
  9489. }
  9490. },
  9491. vertexShader: ShaderChunk.background_vert,
  9492. fragmentShader: ShaderChunk.background_frag
  9493. },
  9494. /* -------------------------------------------------------------------------
  9495. // Cube map shader
  9496. ------------------------------------------------------------------------- */
  9497. cube: {
  9498. uniforms: mergeUniforms([UniformsLib.envmap, {
  9499. opacity: {
  9500. value: 1.0
  9501. }
  9502. }]),
  9503. vertexShader: ShaderChunk.cube_vert,
  9504. fragmentShader: ShaderChunk.cube_frag
  9505. },
  9506. equirect: {
  9507. uniforms: {
  9508. tEquirect: {
  9509. value: null
  9510. }
  9511. },
  9512. vertexShader: ShaderChunk.equirect_vert,
  9513. fragmentShader: ShaderChunk.equirect_frag
  9514. },
  9515. distanceRGBA: {
  9516. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9517. referencePosition: {
  9518. value: new Vector3()
  9519. },
  9520. nearDistance: {
  9521. value: 1
  9522. },
  9523. farDistance: {
  9524. value: 1000
  9525. }
  9526. }]),
  9527. vertexShader: ShaderChunk.distanceRGBA_vert,
  9528. fragmentShader: ShaderChunk.distanceRGBA_frag
  9529. },
  9530. shadow: {
  9531. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9532. color: {
  9533. value: new Color(0x00000)
  9534. },
  9535. opacity: {
  9536. value: 1.0
  9537. }
  9538. }]),
  9539. vertexShader: ShaderChunk.shadow_vert,
  9540. fragmentShader: ShaderChunk.shadow_frag
  9541. }
  9542. };
  9543. ShaderLib.physical = {
  9544. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9545. clearcoat: {
  9546. value: 0
  9547. },
  9548. clearcoatMap: {
  9549. value: null
  9550. },
  9551. clearcoatRoughness: {
  9552. value: 0
  9553. },
  9554. clearcoatRoughnessMap: {
  9555. value: null
  9556. },
  9557. clearcoatNormalScale: {
  9558. value: new Vector2(1, 1)
  9559. },
  9560. clearcoatNormalMap: {
  9561. value: null
  9562. },
  9563. sheen: {
  9564. value: new Color(0x000000)
  9565. },
  9566. transmission: {
  9567. value: 0
  9568. },
  9569. transmissionMap: {
  9570. value: null
  9571. }
  9572. }]),
  9573. vertexShader: ShaderChunk.meshphysical_vert,
  9574. fragmentShader: ShaderChunk.meshphysical_frag
  9575. };
  9576. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9577. var clearColor = new Color(0x000000);
  9578. var clearAlpha = 0;
  9579. var planeMesh;
  9580. var boxMesh;
  9581. var currentBackground = null;
  9582. var currentBackgroundVersion = 0;
  9583. var currentTonemapping = null;
  9584. function render(renderList, scene, camera, forceClear) {
  9585. var background = scene.isScene === true ? scene.background : null;
  9586. if (background && background.isTexture) {
  9587. background = cubemaps.get(background);
  9588. } // Ignore background in AR
  9589. // TODO: Reconsider this.
  9590. var xr = renderer.xr;
  9591. var session = xr.getSession && xr.getSession();
  9592. if (session && session.environmentBlendMode === 'additive') {
  9593. background = null;
  9594. }
  9595. if (background === null) {
  9596. setClear(clearColor, clearAlpha);
  9597. } else if (background && background.isColor) {
  9598. setClear(background, 1);
  9599. forceClear = true;
  9600. }
  9601. if (renderer.autoClear || forceClear) {
  9602. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9603. }
  9604. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9605. if (boxMesh === undefined) {
  9606. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9607. name: 'BackgroundCubeMaterial',
  9608. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9609. vertexShader: ShaderLib.cube.vertexShader,
  9610. fragmentShader: ShaderLib.cube.fragmentShader,
  9611. side: BackSide,
  9612. depthTest: false,
  9613. depthWrite: false,
  9614. fog: false
  9615. }));
  9616. boxMesh.geometry.deleteAttribute('normal');
  9617. boxMesh.geometry.deleteAttribute('uv');
  9618. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9619. this.matrixWorld.copyPosition(camera.matrixWorld);
  9620. }; // enable code injection for non-built-in material
  9621. Object.defineProperty(boxMesh.material, 'envMap', {
  9622. get: function get() {
  9623. return this.uniforms.envMap.value;
  9624. }
  9625. });
  9626. objects.update(boxMesh);
  9627. }
  9628. if (background.isWebGLCubeRenderTarget) {
  9629. // TODO Deprecate
  9630. background = background.texture;
  9631. }
  9632. boxMesh.material.uniforms.envMap.value = background;
  9633. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9634. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9635. boxMesh.material.needsUpdate = true;
  9636. currentBackground = background;
  9637. currentBackgroundVersion = background.version;
  9638. currentTonemapping = renderer.toneMapping;
  9639. } // push to the pre-sorted opaque render list
  9640. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9641. } else if (background && background.isTexture) {
  9642. if (planeMesh === undefined) {
  9643. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9644. name: 'BackgroundMaterial',
  9645. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9646. vertexShader: ShaderLib.background.vertexShader,
  9647. fragmentShader: ShaderLib.background.fragmentShader,
  9648. side: FrontSide,
  9649. depthTest: false,
  9650. depthWrite: false,
  9651. fog: false
  9652. }));
  9653. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9654. Object.defineProperty(planeMesh.material, 'map', {
  9655. get: function get() {
  9656. return this.uniforms.t2D.value;
  9657. }
  9658. });
  9659. objects.update(planeMesh);
  9660. }
  9661. planeMesh.material.uniforms.t2D.value = background;
  9662. if (background.matrixAutoUpdate === true) {
  9663. background.updateMatrix();
  9664. }
  9665. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9666. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9667. planeMesh.material.needsUpdate = true;
  9668. currentBackground = background;
  9669. currentBackgroundVersion = background.version;
  9670. currentTonemapping = renderer.toneMapping;
  9671. } // push to the pre-sorted opaque render list
  9672. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9673. }
  9674. }
  9675. function setClear(color, alpha) {
  9676. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9677. }
  9678. return {
  9679. getClearColor: function getClearColor() {
  9680. return clearColor;
  9681. },
  9682. setClearColor: function setClearColor(color, alpha) {
  9683. if (alpha === void 0) {
  9684. alpha = 1;
  9685. }
  9686. clearColor.set(color);
  9687. clearAlpha = alpha;
  9688. setClear(clearColor, clearAlpha);
  9689. },
  9690. getClearAlpha: function getClearAlpha() {
  9691. return clearAlpha;
  9692. },
  9693. setClearAlpha: function setClearAlpha(alpha) {
  9694. clearAlpha = alpha;
  9695. setClear(clearColor, clearAlpha);
  9696. },
  9697. render: render
  9698. };
  9699. }
  9700. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9701. var maxVertexAttributes = gl.getParameter(34921);
  9702. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9703. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9704. var bindingStates = {};
  9705. var defaultState = createBindingState(null);
  9706. var currentState = defaultState;
  9707. function setup(object, material, program, geometry, index) {
  9708. var updateBuffers = false;
  9709. if (vaoAvailable) {
  9710. var state = getBindingState(geometry, program, material);
  9711. if (currentState !== state) {
  9712. currentState = state;
  9713. bindVertexArrayObject(currentState.object);
  9714. }
  9715. updateBuffers = needsUpdate(geometry, index);
  9716. if (updateBuffers) saveCache(geometry, index);
  9717. } else {
  9718. var wireframe = material.wireframe === true;
  9719. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9720. currentState.geometry = geometry.id;
  9721. currentState.program = program.id;
  9722. currentState.wireframe = wireframe;
  9723. updateBuffers = true;
  9724. }
  9725. }
  9726. if (object.isInstancedMesh === true) {
  9727. updateBuffers = true;
  9728. }
  9729. if (index !== null) {
  9730. attributes.update(index, 34963);
  9731. }
  9732. if (updateBuffers) {
  9733. setupVertexAttributes(object, material, program, geometry);
  9734. if (index !== null) {
  9735. gl.bindBuffer(34963, attributes.get(index).buffer);
  9736. }
  9737. }
  9738. }
  9739. function createVertexArrayObject() {
  9740. if (capabilities.isWebGL2) return gl.createVertexArray();
  9741. return extension.createVertexArrayOES();
  9742. }
  9743. function bindVertexArrayObject(vao) {
  9744. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9745. return extension.bindVertexArrayOES(vao);
  9746. }
  9747. function deleteVertexArrayObject(vao) {
  9748. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9749. return extension.deleteVertexArrayOES(vao);
  9750. }
  9751. function getBindingState(geometry, program, material) {
  9752. var wireframe = material.wireframe === true;
  9753. var programMap = bindingStates[geometry.id];
  9754. if (programMap === undefined) {
  9755. programMap = {};
  9756. bindingStates[geometry.id] = programMap;
  9757. }
  9758. var stateMap = programMap[program.id];
  9759. if (stateMap === undefined) {
  9760. stateMap = {};
  9761. programMap[program.id] = stateMap;
  9762. }
  9763. var state = stateMap[wireframe];
  9764. if (state === undefined) {
  9765. state = createBindingState(createVertexArrayObject());
  9766. stateMap[wireframe] = state;
  9767. }
  9768. return state;
  9769. }
  9770. function createBindingState(vao) {
  9771. var newAttributes = [];
  9772. var enabledAttributes = [];
  9773. var attributeDivisors = [];
  9774. for (var i = 0; i < maxVertexAttributes; i++) {
  9775. newAttributes[i] = 0;
  9776. enabledAttributes[i] = 0;
  9777. attributeDivisors[i] = 0;
  9778. }
  9779. return {
  9780. // for backward compatibility on non-VAO support browser
  9781. geometry: null,
  9782. program: null,
  9783. wireframe: false,
  9784. newAttributes: newAttributes,
  9785. enabledAttributes: enabledAttributes,
  9786. attributeDivisors: attributeDivisors,
  9787. object: vao,
  9788. attributes: {},
  9789. index: null
  9790. };
  9791. }
  9792. function needsUpdate(geometry, index) {
  9793. var cachedAttributes = currentState.attributes;
  9794. var geometryAttributes = geometry.attributes;
  9795. var attributesNum = 0;
  9796. for (var key in geometryAttributes) {
  9797. var cachedAttribute = cachedAttributes[key];
  9798. var geometryAttribute = geometryAttributes[key];
  9799. if (cachedAttribute === undefined) return true;
  9800. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9801. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9802. attributesNum++;
  9803. }
  9804. if (currentState.attributesNum !== attributesNum) return true;
  9805. if (currentState.index !== index) return true;
  9806. return false;
  9807. }
  9808. function saveCache(geometry, index) {
  9809. var cache = {};
  9810. var attributes = geometry.attributes;
  9811. var attributesNum = 0;
  9812. for (var key in attributes) {
  9813. var attribute = attributes[key];
  9814. var data = {};
  9815. data.attribute = attribute;
  9816. if (attribute.data) {
  9817. data.data = attribute.data;
  9818. }
  9819. cache[key] = data;
  9820. attributesNum++;
  9821. }
  9822. currentState.attributes = cache;
  9823. currentState.attributesNum = attributesNum;
  9824. currentState.index = index;
  9825. }
  9826. function initAttributes() {
  9827. var newAttributes = currentState.newAttributes;
  9828. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9829. newAttributes[i] = 0;
  9830. }
  9831. }
  9832. function enableAttribute(attribute) {
  9833. enableAttributeAndDivisor(attribute, 0);
  9834. }
  9835. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9836. var newAttributes = currentState.newAttributes;
  9837. var enabledAttributes = currentState.enabledAttributes;
  9838. var attributeDivisors = currentState.attributeDivisors;
  9839. newAttributes[attribute] = 1;
  9840. if (enabledAttributes[attribute] === 0) {
  9841. gl.enableVertexAttribArray(attribute);
  9842. enabledAttributes[attribute] = 1;
  9843. }
  9844. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9845. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9846. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9847. attributeDivisors[attribute] = meshPerAttribute;
  9848. }
  9849. }
  9850. function disableUnusedAttributes() {
  9851. var newAttributes = currentState.newAttributes;
  9852. var enabledAttributes = currentState.enabledAttributes;
  9853. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9854. if (enabledAttributes[i] !== newAttributes[i]) {
  9855. gl.disableVertexAttribArray(i);
  9856. enabledAttributes[i] = 0;
  9857. }
  9858. }
  9859. }
  9860. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9861. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9862. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9863. } else {
  9864. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9865. }
  9866. }
  9867. function setupVertexAttributes(object, material, program, geometry) {
  9868. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9869. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9870. }
  9871. initAttributes();
  9872. var geometryAttributes = geometry.attributes;
  9873. var programAttributes = program.getAttributes();
  9874. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9875. for (var name in programAttributes) {
  9876. var programAttribute = programAttributes[name];
  9877. if (programAttribute >= 0) {
  9878. var geometryAttribute = geometryAttributes[name];
  9879. if (geometryAttribute !== undefined) {
  9880. var normalized = geometryAttribute.normalized;
  9881. var size = geometryAttribute.itemSize;
  9882. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9883. if (attribute === undefined) continue;
  9884. var buffer = attribute.buffer;
  9885. var type = attribute.type;
  9886. var bytesPerElement = attribute.bytesPerElement;
  9887. if (geometryAttribute.isInterleavedBufferAttribute) {
  9888. var data = geometryAttribute.data;
  9889. var stride = data.stride;
  9890. var offset = geometryAttribute.offset;
  9891. if (data && data.isInstancedInterleavedBuffer) {
  9892. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9893. if (geometry._maxInstanceCount === undefined) {
  9894. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9895. }
  9896. } else {
  9897. enableAttribute(programAttribute);
  9898. }
  9899. gl.bindBuffer(34962, buffer);
  9900. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9901. } else {
  9902. if (geometryAttribute.isInstancedBufferAttribute) {
  9903. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9904. if (geometry._maxInstanceCount === undefined) {
  9905. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9906. }
  9907. } else {
  9908. enableAttribute(programAttribute);
  9909. }
  9910. gl.bindBuffer(34962, buffer);
  9911. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9912. }
  9913. } else if (name === 'instanceMatrix') {
  9914. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9915. if (_attribute === undefined) continue;
  9916. var _buffer = _attribute.buffer;
  9917. var _type = _attribute.type;
  9918. enableAttributeAndDivisor(programAttribute + 0, 1);
  9919. enableAttributeAndDivisor(programAttribute + 1, 1);
  9920. enableAttributeAndDivisor(programAttribute + 2, 1);
  9921. enableAttributeAndDivisor(programAttribute + 3, 1);
  9922. gl.bindBuffer(34962, _buffer);
  9923. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9924. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9925. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9926. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9927. } else if (name === 'instanceColor') {
  9928. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9929. if (_attribute2 === undefined) continue;
  9930. var _buffer2 = _attribute2.buffer;
  9931. var _type2 = _attribute2.type;
  9932. enableAttributeAndDivisor(programAttribute, 1);
  9933. gl.bindBuffer(34962, _buffer2);
  9934. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9935. } else if (materialDefaultAttributeValues !== undefined) {
  9936. var value = materialDefaultAttributeValues[name];
  9937. if (value !== undefined) {
  9938. switch (value.length) {
  9939. case 2:
  9940. gl.vertexAttrib2fv(programAttribute, value);
  9941. break;
  9942. case 3:
  9943. gl.vertexAttrib3fv(programAttribute, value);
  9944. break;
  9945. case 4:
  9946. gl.vertexAttrib4fv(programAttribute, value);
  9947. break;
  9948. default:
  9949. gl.vertexAttrib1fv(programAttribute, value);
  9950. }
  9951. }
  9952. }
  9953. }
  9954. }
  9955. disableUnusedAttributes();
  9956. }
  9957. function dispose() {
  9958. reset();
  9959. for (var geometryId in bindingStates) {
  9960. var programMap = bindingStates[geometryId];
  9961. for (var programId in programMap) {
  9962. var stateMap = programMap[programId];
  9963. for (var wireframe in stateMap) {
  9964. deleteVertexArrayObject(stateMap[wireframe].object);
  9965. delete stateMap[wireframe];
  9966. }
  9967. delete programMap[programId];
  9968. }
  9969. delete bindingStates[geometryId];
  9970. }
  9971. }
  9972. function releaseStatesOfGeometry(geometry) {
  9973. if (bindingStates[geometry.id] === undefined) return;
  9974. var programMap = bindingStates[geometry.id];
  9975. for (var programId in programMap) {
  9976. var stateMap = programMap[programId];
  9977. for (var wireframe in stateMap) {
  9978. deleteVertexArrayObject(stateMap[wireframe].object);
  9979. delete stateMap[wireframe];
  9980. }
  9981. delete programMap[programId];
  9982. }
  9983. delete bindingStates[geometry.id];
  9984. }
  9985. function releaseStatesOfProgram(program) {
  9986. for (var geometryId in bindingStates) {
  9987. var programMap = bindingStates[geometryId];
  9988. if (programMap[program.id] === undefined) continue;
  9989. var stateMap = programMap[program.id];
  9990. for (var wireframe in stateMap) {
  9991. deleteVertexArrayObject(stateMap[wireframe].object);
  9992. delete stateMap[wireframe];
  9993. }
  9994. delete programMap[program.id];
  9995. }
  9996. }
  9997. function reset() {
  9998. resetDefaultState();
  9999. if (currentState === defaultState) return;
  10000. currentState = defaultState;
  10001. bindVertexArrayObject(currentState.object);
  10002. } // for backward-compatilibity
  10003. function resetDefaultState() {
  10004. defaultState.geometry = null;
  10005. defaultState.program = null;
  10006. defaultState.wireframe = false;
  10007. }
  10008. return {
  10009. setup: setup,
  10010. reset: reset,
  10011. resetDefaultState: resetDefaultState,
  10012. dispose: dispose,
  10013. releaseStatesOfGeometry: releaseStatesOfGeometry,
  10014. releaseStatesOfProgram: releaseStatesOfProgram,
  10015. initAttributes: initAttributes,
  10016. enableAttribute: enableAttribute,
  10017. disableUnusedAttributes: disableUnusedAttributes
  10018. };
  10019. }
  10020. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  10021. var isWebGL2 = capabilities.isWebGL2;
  10022. var mode;
  10023. function setMode(value) {
  10024. mode = value;
  10025. }
  10026. function render(start, count) {
  10027. gl.drawArrays(mode, start, count);
  10028. info.update(count, mode, 1);
  10029. }
  10030. function renderInstances(start, count, primcount) {
  10031. if (primcount === 0) return;
  10032. var extension, methodName;
  10033. if (isWebGL2) {
  10034. extension = gl;
  10035. methodName = 'drawArraysInstanced';
  10036. } else {
  10037. extension = extensions.get('ANGLE_instanced_arrays');
  10038. methodName = 'drawArraysInstancedANGLE';
  10039. if (extension === null) {
  10040. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10041. return;
  10042. }
  10043. }
  10044. extension[methodName](mode, start, count, primcount);
  10045. info.update(count, mode, primcount);
  10046. } //
  10047. this.setMode = setMode;
  10048. this.render = render;
  10049. this.renderInstances = renderInstances;
  10050. }
  10051. function WebGLCapabilities(gl, extensions, parameters) {
  10052. var maxAnisotropy;
  10053. function getMaxAnisotropy() {
  10054. if (maxAnisotropy !== undefined) return maxAnisotropy;
  10055. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  10056. var extension = extensions.get('EXT_texture_filter_anisotropic');
  10057. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  10058. } else {
  10059. maxAnisotropy = 0;
  10060. }
  10061. return maxAnisotropy;
  10062. }
  10063. function getMaxPrecision(precision) {
  10064. if (precision === 'highp') {
  10065. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  10066. return 'highp';
  10067. }
  10068. precision = 'mediump';
  10069. }
  10070. if (precision === 'mediump') {
  10071. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  10072. return 'mediump';
  10073. }
  10074. }
  10075. return 'lowp';
  10076. }
  10077. /* eslint-disable no-undef */
  10078. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  10079. /* eslint-enable no-undef */
  10080. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10081. var maxPrecision = getMaxPrecision(precision);
  10082. if (maxPrecision !== precision) {
  10083. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  10084. precision = maxPrecision;
  10085. }
  10086. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10087. var maxTextures = gl.getParameter(34930);
  10088. var maxVertexTextures = gl.getParameter(35660);
  10089. var maxTextureSize = gl.getParameter(3379);
  10090. var maxCubemapSize = gl.getParameter(34076);
  10091. var maxAttributes = gl.getParameter(34921);
  10092. var maxVertexUniforms = gl.getParameter(36347);
  10093. var maxVaryings = gl.getParameter(36348);
  10094. var maxFragmentUniforms = gl.getParameter(36349);
  10095. var vertexTextures = maxVertexTextures > 0;
  10096. var floatFragmentTextures = isWebGL2 || extensions.has('OES_texture_float');
  10097. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10098. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  10099. return {
  10100. isWebGL2: isWebGL2,
  10101. getMaxAnisotropy: getMaxAnisotropy,
  10102. getMaxPrecision: getMaxPrecision,
  10103. precision: precision,
  10104. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10105. maxTextures: maxTextures,
  10106. maxVertexTextures: maxVertexTextures,
  10107. maxTextureSize: maxTextureSize,
  10108. maxCubemapSize: maxCubemapSize,
  10109. maxAttributes: maxAttributes,
  10110. maxVertexUniforms: maxVertexUniforms,
  10111. maxVaryings: maxVaryings,
  10112. maxFragmentUniforms: maxFragmentUniforms,
  10113. vertexTextures: vertexTextures,
  10114. floatFragmentTextures: floatFragmentTextures,
  10115. floatVertexTextures: floatVertexTextures,
  10116. maxSamples: maxSamples
  10117. };
  10118. }
  10119. function WebGLClipping(properties) {
  10120. var scope = this;
  10121. var globalState = null,
  10122. numGlobalPlanes = 0,
  10123. localClippingEnabled = false,
  10124. renderingShadows = false;
  10125. var plane = new Plane(),
  10126. viewNormalMatrix = new Matrix3(),
  10127. uniform = {
  10128. value: null,
  10129. needsUpdate: false
  10130. };
  10131. this.uniform = uniform;
  10132. this.numPlanes = 0;
  10133. this.numIntersection = 0;
  10134. this.init = function (planes, enableLocalClipping, camera) {
  10135. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  10136. // run another frame in order to reset the state:
  10137. numGlobalPlanes !== 0 || localClippingEnabled;
  10138. localClippingEnabled = enableLocalClipping;
  10139. globalState = projectPlanes(planes, camera, 0);
  10140. numGlobalPlanes = planes.length;
  10141. return enabled;
  10142. };
  10143. this.beginShadows = function () {
  10144. renderingShadows = true;
  10145. projectPlanes(null);
  10146. };
  10147. this.endShadows = function () {
  10148. renderingShadows = false;
  10149. resetGlobalState();
  10150. };
  10151. this.setState = function (material, camera, useCache) {
  10152. var planes = material.clippingPlanes,
  10153. clipIntersection = material.clipIntersection,
  10154. clipShadows = material.clipShadows;
  10155. var materialProperties = properties.get(material);
  10156. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  10157. // there's no local clipping
  10158. if (renderingShadows) {
  10159. // there's no global clipping
  10160. projectPlanes(null);
  10161. } else {
  10162. resetGlobalState();
  10163. }
  10164. } else {
  10165. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10166. lGlobal = nGlobal * 4;
  10167. var dstArray = materialProperties.clippingState || null;
  10168. uniform.value = dstArray; // ensure unique state
  10169. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  10170. for (var i = 0; i !== lGlobal; ++i) {
  10171. dstArray[i] = globalState[i];
  10172. }
  10173. materialProperties.clippingState = dstArray;
  10174. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10175. this.numPlanes += nGlobal;
  10176. }
  10177. };
  10178. function resetGlobalState() {
  10179. if (uniform.value !== globalState) {
  10180. uniform.value = globalState;
  10181. uniform.needsUpdate = numGlobalPlanes > 0;
  10182. }
  10183. scope.numPlanes = numGlobalPlanes;
  10184. scope.numIntersection = 0;
  10185. }
  10186. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  10187. var nPlanes = planes !== null ? planes.length : 0;
  10188. var dstArray = null;
  10189. if (nPlanes !== 0) {
  10190. dstArray = uniform.value;
  10191. if (skipTransform !== true || dstArray === null) {
  10192. var flatSize = dstOffset + nPlanes * 4,
  10193. viewMatrix = camera.matrixWorldInverse;
  10194. viewNormalMatrix.getNormalMatrix(viewMatrix);
  10195. if (dstArray === null || dstArray.length < flatSize) {
  10196. dstArray = new Float32Array(flatSize);
  10197. }
  10198. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  10199. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  10200. plane.normal.toArray(dstArray, i4);
  10201. dstArray[i4 + 3] = plane.constant;
  10202. }
  10203. }
  10204. uniform.value = dstArray;
  10205. uniform.needsUpdate = true;
  10206. }
  10207. scope.numPlanes = nPlanes;
  10208. scope.numIntersection = 0;
  10209. return dstArray;
  10210. }
  10211. }
  10212. function WebGLCubeMaps(renderer) {
  10213. var cubemaps = new WeakMap();
  10214. function mapTextureMapping(texture, mapping) {
  10215. if (mapping === EquirectangularReflectionMapping) {
  10216. texture.mapping = CubeReflectionMapping;
  10217. } else if (mapping === EquirectangularRefractionMapping) {
  10218. texture.mapping = CubeRefractionMapping;
  10219. }
  10220. return texture;
  10221. }
  10222. function get(texture) {
  10223. if (texture && texture.isTexture) {
  10224. var mapping = texture.mapping;
  10225. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  10226. if (cubemaps.has(texture)) {
  10227. var cubemap = cubemaps.get(texture).texture;
  10228. return mapTextureMapping(cubemap, texture.mapping);
  10229. } else {
  10230. var image = texture.image;
  10231. if (image && image.height > 0) {
  10232. var currentRenderTarget = renderer.getRenderTarget();
  10233. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  10234. renderTarget.fromEquirectangularTexture(renderer, texture);
  10235. cubemaps.set(texture, renderTarget);
  10236. renderer.setRenderTarget(currentRenderTarget);
  10237. texture.addEventListener('dispose', onTextureDispose);
  10238. return mapTextureMapping(renderTarget.texture, texture.mapping);
  10239. } else {
  10240. // image not yet ready. try the conversion next frame
  10241. return null;
  10242. }
  10243. }
  10244. }
  10245. }
  10246. return texture;
  10247. }
  10248. function onTextureDispose(event) {
  10249. var texture = event.target;
  10250. texture.removeEventListener('dispose', onTextureDispose);
  10251. var cubemap = cubemaps.get(texture);
  10252. if (cubemap !== undefined) {
  10253. cubemaps.delete(texture);
  10254. cubemap.dispose();
  10255. }
  10256. }
  10257. function dispose() {
  10258. cubemaps = new WeakMap();
  10259. }
  10260. return {
  10261. get: get,
  10262. dispose: dispose
  10263. };
  10264. }
  10265. function WebGLExtensions(gl) {
  10266. var extensions = {};
  10267. function getExtension(name) {
  10268. if (extensions[name] !== undefined) {
  10269. return extensions[name];
  10270. }
  10271. var extension;
  10272. switch (name) {
  10273. case 'WEBGL_depth_texture':
  10274. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  10275. break;
  10276. case 'EXT_texture_filter_anisotropic':
  10277. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  10278. break;
  10279. case 'WEBGL_compressed_texture_s3tc':
  10280. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  10281. break;
  10282. case 'WEBGL_compressed_texture_pvrtc':
  10283. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  10284. break;
  10285. default:
  10286. extension = gl.getExtension(name);
  10287. }
  10288. extensions[name] = extension;
  10289. return extension;
  10290. }
  10291. return {
  10292. has: function has(name) {
  10293. return getExtension(name) !== null;
  10294. },
  10295. init: function init(capabilities) {
  10296. if (capabilities.isWebGL2) {
  10297. getExtension('EXT_color_buffer_float');
  10298. } else {
  10299. getExtension('WEBGL_depth_texture');
  10300. getExtension('OES_texture_float');
  10301. getExtension('OES_texture_half_float');
  10302. getExtension('OES_texture_half_float_linear');
  10303. getExtension('OES_standard_derivatives');
  10304. getExtension('OES_element_index_uint');
  10305. getExtension('OES_vertex_array_object');
  10306. getExtension('ANGLE_instanced_arrays');
  10307. }
  10308. getExtension('OES_texture_float_linear');
  10309. getExtension('EXT_color_buffer_half_float');
  10310. },
  10311. get: function get(name) {
  10312. var extension = getExtension(name);
  10313. if (extension === null) {
  10314. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  10315. }
  10316. return extension;
  10317. }
  10318. };
  10319. }
  10320. function WebGLGeometries(gl, attributes, info, bindingStates) {
  10321. var geometries = {};
  10322. var wireframeAttributes = new WeakMap();
  10323. function onGeometryDispose(event) {
  10324. var geometry = event.target;
  10325. if (geometry.index !== null) {
  10326. attributes.remove(geometry.index);
  10327. }
  10328. for (var name in geometry.attributes) {
  10329. attributes.remove(geometry.attributes[name]);
  10330. }
  10331. geometry.removeEventListener('dispose', onGeometryDispose);
  10332. delete geometries[geometry.id];
  10333. var attribute = wireframeAttributes.get(geometry);
  10334. if (attribute) {
  10335. attributes.remove(attribute);
  10336. wireframeAttributes.delete(geometry);
  10337. }
  10338. bindingStates.releaseStatesOfGeometry(geometry);
  10339. if (geometry.isInstancedBufferGeometry === true) {
  10340. delete geometry._maxInstanceCount;
  10341. } //
  10342. info.memory.geometries--;
  10343. }
  10344. function get(object, geometry) {
  10345. if (geometries[geometry.id] === true) return geometry;
  10346. geometry.addEventListener('dispose', onGeometryDispose);
  10347. geometries[geometry.id] = true;
  10348. info.memory.geometries++;
  10349. return geometry;
  10350. }
  10351. function update(geometry) {
  10352. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  10353. for (var name in geometryAttributes) {
  10354. attributes.update(geometryAttributes[name], 34962);
  10355. } // morph targets
  10356. var morphAttributes = geometry.morphAttributes;
  10357. for (var _name in morphAttributes) {
  10358. var array = morphAttributes[_name];
  10359. for (var i = 0, l = array.length; i < l; i++) {
  10360. attributes.update(array[i], 34962);
  10361. }
  10362. }
  10363. }
  10364. function updateWireframeAttribute(geometry) {
  10365. var indices = [];
  10366. var geometryIndex = geometry.index;
  10367. var geometryPosition = geometry.attributes.position;
  10368. var version = 0;
  10369. if (geometryIndex !== null) {
  10370. var array = geometryIndex.array;
  10371. version = geometryIndex.version;
  10372. for (var i = 0, l = array.length; i < l; i += 3) {
  10373. var a = array[i + 0];
  10374. var b = array[i + 1];
  10375. var c = array[i + 2];
  10376. indices.push(a, b, b, c, c, a);
  10377. }
  10378. } else {
  10379. var _array = geometryPosition.array;
  10380. version = geometryPosition.version;
  10381. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  10382. var _a = _i + 0;
  10383. var _b = _i + 1;
  10384. var _c = _i + 2;
  10385. indices.push(_a, _b, _b, _c, _c, _a);
  10386. }
  10387. }
  10388. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  10389. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  10390. //
  10391. var previousAttribute = wireframeAttributes.get(geometry);
  10392. if (previousAttribute) attributes.remove(previousAttribute); //
  10393. wireframeAttributes.set(geometry, attribute);
  10394. }
  10395. function getWireframeAttribute(geometry) {
  10396. var currentAttribute = wireframeAttributes.get(geometry);
  10397. if (currentAttribute) {
  10398. var geometryIndex = geometry.index;
  10399. if (geometryIndex !== null) {
  10400. // if the attribute is obsolete, create a new one
  10401. if (currentAttribute.version < geometryIndex.version) {
  10402. updateWireframeAttribute(geometry);
  10403. }
  10404. }
  10405. } else {
  10406. updateWireframeAttribute(geometry);
  10407. }
  10408. return wireframeAttributes.get(geometry);
  10409. }
  10410. return {
  10411. get: get,
  10412. update: update,
  10413. getWireframeAttribute: getWireframeAttribute
  10414. };
  10415. }
  10416. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  10417. var isWebGL2 = capabilities.isWebGL2;
  10418. var mode;
  10419. function setMode(value) {
  10420. mode = value;
  10421. }
  10422. var type, bytesPerElement;
  10423. function setIndex(value) {
  10424. type = value.type;
  10425. bytesPerElement = value.bytesPerElement;
  10426. }
  10427. function render(start, count) {
  10428. gl.drawElements(mode, count, type, start * bytesPerElement);
  10429. info.update(count, mode, 1);
  10430. }
  10431. function renderInstances(start, count, primcount) {
  10432. if (primcount === 0) return;
  10433. var extension, methodName;
  10434. if (isWebGL2) {
  10435. extension = gl;
  10436. methodName = 'drawElementsInstanced';
  10437. } else {
  10438. extension = extensions.get('ANGLE_instanced_arrays');
  10439. methodName = 'drawElementsInstancedANGLE';
  10440. if (extension === null) {
  10441. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10442. return;
  10443. }
  10444. }
  10445. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  10446. info.update(count, mode, primcount);
  10447. } //
  10448. this.setMode = setMode;
  10449. this.setIndex = setIndex;
  10450. this.render = render;
  10451. this.renderInstances = renderInstances;
  10452. }
  10453. function WebGLInfo(gl) {
  10454. var memory = {
  10455. geometries: 0,
  10456. textures: 0
  10457. };
  10458. var render = {
  10459. frame: 0,
  10460. calls: 0,
  10461. triangles: 0,
  10462. points: 0,
  10463. lines: 0
  10464. };
  10465. function update(count, mode, instanceCount) {
  10466. render.calls++;
  10467. switch (mode) {
  10468. case 4:
  10469. render.triangles += instanceCount * (count / 3);
  10470. break;
  10471. case 1:
  10472. render.lines += instanceCount * (count / 2);
  10473. break;
  10474. case 3:
  10475. render.lines += instanceCount * (count - 1);
  10476. break;
  10477. case 2:
  10478. render.lines += instanceCount * count;
  10479. break;
  10480. case 0:
  10481. render.points += instanceCount * count;
  10482. break;
  10483. default:
  10484. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  10485. break;
  10486. }
  10487. }
  10488. function reset() {
  10489. render.frame++;
  10490. render.calls = 0;
  10491. render.triangles = 0;
  10492. render.points = 0;
  10493. render.lines = 0;
  10494. }
  10495. return {
  10496. memory: memory,
  10497. render: render,
  10498. programs: null,
  10499. autoReset: true,
  10500. reset: reset,
  10501. update: update
  10502. };
  10503. }
  10504. function numericalSort(a, b) {
  10505. return a[0] - b[0];
  10506. }
  10507. function absNumericalSort(a, b) {
  10508. return Math.abs(b[1]) - Math.abs(a[1]);
  10509. }
  10510. function WebGLMorphtargets(gl) {
  10511. var influencesList = {};
  10512. var morphInfluences = new Float32Array(8);
  10513. var workInfluences = [];
  10514. for (var i = 0; i < 8; i++) {
  10515. workInfluences[i] = [i, 0];
  10516. }
  10517. function update(object, geometry, material, program) {
  10518. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10519. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10520. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10521. var influences = influencesList[geometry.id];
  10522. if (influences === undefined) {
  10523. // initialise list
  10524. influences = [];
  10525. for (var _i = 0; _i < length; _i++) {
  10526. influences[_i] = [_i, 0];
  10527. }
  10528. influencesList[geometry.id] = influences;
  10529. } // Collect influences
  10530. for (var _i2 = 0; _i2 < length; _i2++) {
  10531. var influence = influences[_i2];
  10532. influence[0] = _i2;
  10533. influence[1] = objectInfluences[_i2];
  10534. }
  10535. influences.sort(absNumericalSort);
  10536. for (var _i3 = 0; _i3 < 8; _i3++) {
  10537. if (_i3 < length && influences[_i3][1]) {
  10538. workInfluences[_i3][0] = influences[_i3][0];
  10539. workInfluences[_i3][1] = influences[_i3][1];
  10540. } else {
  10541. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10542. workInfluences[_i3][1] = 0;
  10543. }
  10544. }
  10545. workInfluences.sort(numericalSort);
  10546. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10547. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10548. var morphInfluencesSum = 0;
  10549. for (var _i4 = 0; _i4 < 8; _i4++) {
  10550. var _influence = workInfluences[_i4];
  10551. var index = _influence[0];
  10552. var value = _influence[1];
  10553. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10554. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10555. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10556. }
  10557. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10558. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10559. }
  10560. morphInfluences[_i4] = value;
  10561. morphInfluencesSum += value;
  10562. } else {
  10563. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10564. geometry.deleteAttribute('morphTarget' + _i4);
  10565. }
  10566. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10567. geometry.deleteAttribute('morphNormal' + _i4);
  10568. }
  10569. morphInfluences[_i4] = 0;
  10570. }
  10571. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10572. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10573. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10574. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10575. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10576. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10577. }
  10578. return {
  10579. update: update
  10580. };
  10581. }
  10582. function WebGLObjects(gl, geometries, attributes, info) {
  10583. var updateMap = new WeakMap();
  10584. function update(object) {
  10585. var frame = info.render.frame;
  10586. var geometry = object.geometry;
  10587. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10588. if (updateMap.get(buffergeometry) !== frame) {
  10589. geometries.update(buffergeometry);
  10590. updateMap.set(buffergeometry, frame);
  10591. }
  10592. if (object.isInstancedMesh) {
  10593. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10594. object.addEventListener('dispose', onInstancedMeshDispose);
  10595. }
  10596. attributes.update(object.instanceMatrix, 34962);
  10597. if (object.instanceColor !== null) {
  10598. attributes.update(object.instanceColor, 34962);
  10599. }
  10600. }
  10601. return buffergeometry;
  10602. }
  10603. function dispose() {
  10604. updateMap = new WeakMap();
  10605. }
  10606. function onInstancedMeshDispose(event) {
  10607. var instancedMesh = event.target;
  10608. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10609. attributes.remove(instancedMesh.instanceMatrix);
  10610. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10611. }
  10612. return {
  10613. update: update,
  10614. dispose: dispose
  10615. };
  10616. }
  10617. var DataTexture2DArray = /*#__PURE__*/function (_Texture) {
  10618. _inheritsLoose(DataTexture2DArray, _Texture);
  10619. function DataTexture2DArray(data, width, height, depth) {
  10620. var _this;
  10621. if (data === void 0) {
  10622. data = null;
  10623. }
  10624. if (width === void 0) {
  10625. width = 1;
  10626. }
  10627. if (height === void 0) {
  10628. height = 1;
  10629. }
  10630. if (depth === void 0) {
  10631. depth = 1;
  10632. }
  10633. _this = _Texture.call(this, null) || this;
  10634. _this.image = {
  10635. data: data,
  10636. width: width,
  10637. height: height,
  10638. depth: depth
  10639. };
  10640. _this.magFilter = NearestFilter;
  10641. _this.minFilter = NearestFilter;
  10642. _this.wrapR = ClampToEdgeWrapping;
  10643. _this.generateMipmaps = false;
  10644. _this.flipY = false;
  10645. _this.needsUpdate = true;
  10646. return _this;
  10647. }
  10648. return DataTexture2DArray;
  10649. }(Texture);
  10650. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10651. var DataTexture3D = /*#__PURE__*/function (_Texture) {
  10652. _inheritsLoose(DataTexture3D, _Texture);
  10653. function DataTexture3D(data, width, height, depth) {
  10654. var _this;
  10655. if (data === void 0) {
  10656. data = null;
  10657. }
  10658. if (width === void 0) {
  10659. width = 1;
  10660. }
  10661. if (height === void 0) {
  10662. height = 1;
  10663. }
  10664. if (depth === void 0) {
  10665. depth = 1;
  10666. }
  10667. // We're going to add .setXXX() methods for setting properties later.
  10668. // Users can still set in DataTexture3D directly.
  10669. //
  10670. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10671. // texture.anisotropy = 16;
  10672. //
  10673. // See #14839
  10674. _this = _Texture.call(this, null) || this;
  10675. _this.image = {
  10676. data: data,
  10677. width: width,
  10678. height: height,
  10679. depth: depth
  10680. };
  10681. _this.magFilter = NearestFilter;
  10682. _this.minFilter = NearestFilter;
  10683. _this.wrapR = ClampToEdgeWrapping;
  10684. _this.generateMipmaps = false;
  10685. _this.flipY = false;
  10686. _this.needsUpdate = true;
  10687. return _this;
  10688. }
  10689. return DataTexture3D;
  10690. }(Texture);
  10691. DataTexture3D.prototype.isDataTexture3D = true;
  10692. /**
  10693. * Uniforms of a program.
  10694. * Those form a tree structure with a special top-level container for the root,
  10695. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10696. *
  10697. *
  10698. * Properties of inner nodes including the top-level container:
  10699. *
  10700. * .seq - array of nested uniforms
  10701. * .map - nested uniforms by name
  10702. *
  10703. *
  10704. * Methods of all nodes except the top-level container:
  10705. *
  10706. * .setValue( gl, value, [textures] )
  10707. *
  10708. * uploads a uniform value(s)
  10709. * the 'textures' parameter is needed for sampler uniforms
  10710. *
  10711. *
  10712. * Static methods of the top-level container (textures factorizations):
  10713. *
  10714. * .upload( gl, seq, values, textures )
  10715. *
  10716. * sets uniforms in 'seq' to 'values[id].value'
  10717. *
  10718. * .seqWithValue( seq, values ) : filteredSeq
  10719. *
  10720. * filters 'seq' entries with corresponding entry in values
  10721. *
  10722. *
  10723. * Methods of the top-level container (textures factorizations):
  10724. *
  10725. * .setValue( gl, name, value, textures )
  10726. *
  10727. * sets uniform with name 'name' to 'value'
  10728. *
  10729. * .setOptional( gl, obj, prop )
  10730. *
  10731. * like .set for an optional property of the object
  10732. *
  10733. */
  10734. var emptyTexture = new Texture();
  10735. var emptyTexture2dArray = new DataTexture2DArray();
  10736. var emptyTexture3d = new DataTexture3D();
  10737. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10738. // Array Caches (provide typed arrays for temporary by size)
  10739. var arrayCacheF32 = [];
  10740. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10741. var mat4array = new Float32Array(16);
  10742. var mat3array = new Float32Array(9);
  10743. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10744. function flatten(array, nBlocks, blockSize) {
  10745. var firstElem = array[0];
  10746. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10747. // see http://jacksondunstan.com/articles/983
  10748. var n = nBlocks * blockSize;
  10749. var r = arrayCacheF32[n];
  10750. if (r === undefined) {
  10751. r = new Float32Array(n);
  10752. arrayCacheF32[n] = r;
  10753. }
  10754. if (nBlocks !== 0) {
  10755. firstElem.toArray(r, 0);
  10756. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10757. offset += blockSize;
  10758. array[i].toArray(r, offset);
  10759. }
  10760. }
  10761. return r;
  10762. }
  10763. function arraysEqual(a, b) {
  10764. if (a.length !== b.length) return false;
  10765. for (var i = 0, l = a.length; i < l; i++) {
  10766. if (a[i] !== b[i]) return false;
  10767. }
  10768. return true;
  10769. }
  10770. function copyArray(a, b) {
  10771. for (var i = 0, l = b.length; i < l; i++) {
  10772. a[i] = b[i];
  10773. }
  10774. } // Texture unit allocation
  10775. function allocTexUnits(textures, n) {
  10776. var r = arrayCacheI32[n];
  10777. if (r === undefined) {
  10778. r = new Int32Array(n);
  10779. arrayCacheI32[n] = r;
  10780. }
  10781. for (var i = 0; i !== n; ++i) {
  10782. r[i] = textures.allocateTextureUnit();
  10783. }
  10784. return r;
  10785. } // --- Setters ---
  10786. // Note: Defining these methods externally, because they come in a bunch
  10787. // and this way their names minify.
  10788. // Single scalar
  10789. function setValueV1f(gl, v) {
  10790. var cache = this.cache;
  10791. if (cache[0] === v) return;
  10792. gl.uniform1f(this.addr, v);
  10793. cache[0] = v;
  10794. } // Single float vector (from flat array or THREE.VectorN)
  10795. function setValueV2f(gl, v) {
  10796. var cache = this.cache;
  10797. if (v.x !== undefined) {
  10798. if (cache[0] !== v.x || cache[1] !== v.y) {
  10799. gl.uniform2f(this.addr, v.x, v.y);
  10800. cache[0] = v.x;
  10801. cache[1] = v.y;
  10802. }
  10803. } else {
  10804. if (arraysEqual(cache, v)) return;
  10805. gl.uniform2fv(this.addr, v);
  10806. copyArray(cache, v);
  10807. }
  10808. }
  10809. function setValueV3f(gl, v) {
  10810. var cache = this.cache;
  10811. if (v.x !== undefined) {
  10812. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10813. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10814. cache[0] = v.x;
  10815. cache[1] = v.y;
  10816. cache[2] = v.z;
  10817. }
  10818. } else if (v.r !== undefined) {
  10819. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10820. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10821. cache[0] = v.r;
  10822. cache[1] = v.g;
  10823. cache[2] = v.b;
  10824. }
  10825. } else {
  10826. if (arraysEqual(cache, v)) return;
  10827. gl.uniform3fv(this.addr, v);
  10828. copyArray(cache, v);
  10829. }
  10830. }
  10831. function setValueV4f(gl, v) {
  10832. var cache = this.cache;
  10833. if (v.x !== undefined) {
  10834. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10835. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10836. cache[0] = v.x;
  10837. cache[1] = v.y;
  10838. cache[2] = v.z;
  10839. cache[3] = v.w;
  10840. }
  10841. } else {
  10842. if (arraysEqual(cache, v)) return;
  10843. gl.uniform4fv(this.addr, v);
  10844. copyArray(cache, v);
  10845. }
  10846. } // Single matrix (from flat array or MatrixN)
  10847. function setValueM2(gl, v) {
  10848. var cache = this.cache;
  10849. var elements = v.elements;
  10850. if (elements === undefined) {
  10851. if (arraysEqual(cache, v)) return;
  10852. gl.uniformMatrix2fv(this.addr, false, v);
  10853. copyArray(cache, v);
  10854. } else {
  10855. if (arraysEqual(cache, elements)) return;
  10856. mat2array.set(elements);
  10857. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10858. copyArray(cache, elements);
  10859. }
  10860. }
  10861. function setValueM3(gl, v) {
  10862. var cache = this.cache;
  10863. var elements = v.elements;
  10864. if (elements === undefined) {
  10865. if (arraysEqual(cache, v)) return;
  10866. gl.uniformMatrix3fv(this.addr, false, v);
  10867. copyArray(cache, v);
  10868. } else {
  10869. if (arraysEqual(cache, elements)) return;
  10870. mat3array.set(elements);
  10871. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10872. copyArray(cache, elements);
  10873. }
  10874. }
  10875. function setValueM4(gl, v) {
  10876. var cache = this.cache;
  10877. var elements = v.elements;
  10878. if (elements === undefined) {
  10879. if (arraysEqual(cache, v)) return;
  10880. gl.uniformMatrix4fv(this.addr, false, v);
  10881. copyArray(cache, v);
  10882. } else {
  10883. if (arraysEqual(cache, elements)) return;
  10884. mat4array.set(elements);
  10885. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10886. copyArray(cache, elements);
  10887. }
  10888. } // Single texture (2D / Cube)
  10889. function setValueT1(gl, v, textures) {
  10890. var cache = this.cache;
  10891. var unit = textures.allocateTextureUnit();
  10892. if (cache[0] !== unit) {
  10893. gl.uniform1i(this.addr, unit);
  10894. cache[0] = unit;
  10895. }
  10896. textures.safeSetTexture2D(v || emptyTexture, unit);
  10897. }
  10898. function setValueT2DArray1(gl, v, textures) {
  10899. var cache = this.cache;
  10900. var unit = textures.allocateTextureUnit();
  10901. if (cache[0] !== unit) {
  10902. gl.uniform1i(this.addr, unit);
  10903. cache[0] = unit;
  10904. }
  10905. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10906. }
  10907. function setValueT3D1(gl, v, textures) {
  10908. var cache = this.cache;
  10909. var unit = textures.allocateTextureUnit();
  10910. if (cache[0] !== unit) {
  10911. gl.uniform1i(this.addr, unit);
  10912. cache[0] = unit;
  10913. }
  10914. textures.setTexture3D(v || emptyTexture3d, unit);
  10915. }
  10916. function setValueT6(gl, v, textures) {
  10917. var cache = this.cache;
  10918. var unit = textures.allocateTextureUnit();
  10919. if (cache[0] !== unit) {
  10920. gl.uniform1i(this.addr, unit);
  10921. cache[0] = unit;
  10922. }
  10923. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10924. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10925. function setValueV1i(gl, v) {
  10926. var cache = this.cache;
  10927. if (cache[0] === v) return;
  10928. gl.uniform1i(this.addr, v);
  10929. cache[0] = v;
  10930. }
  10931. function setValueV2i(gl, v) {
  10932. var cache = this.cache;
  10933. if (arraysEqual(cache, v)) return;
  10934. gl.uniform2iv(this.addr, v);
  10935. copyArray(cache, v);
  10936. }
  10937. function setValueV3i(gl, v) {
  10938. var cache = this.cache;
  10939. if (arraysEqual(cache, v)) return;
  10940. gl.uniform3iv(this.addr, v);
  10941. copyArray(cache, v);
  10942. }
  10943. function setValueV4i(gl, v) {
  10944. var cache = this.cache;
  10945. if (arraysEqual(cache, v)) return;
  10946. gl.uniform4iv(this.addr, v);
  10947. copyArray(cache, v);
  10948. } // uint
  10949. function setValueV1ui(gl, v) {
  10950. var cache = this.cache;
  10951. if (cache[0] === v) return;
  10952. gl.uniform1ui(this.addr, v);
  10953. cache[0] = v;
  10954. } // Helper to pick the right setter for the singular case
  10955. function getSingularSetter(type) {
  10956. switch (type) {
  10957. case 0x1406:
  10958. return setValueV1f;
  10959. // FLOAT
  10960. case 0x8b50:
  10961. return setValueV2f;
  10962. // _VEC2
  10963. case 0x8b51:
  10964. return setValueV3f;
  10965. // _VEC3
  10966. case 0x8b52:
  10967. return setValueV4f;
  10968. // _VEC4
  10969. case 0x8b5a:
  10970. return setValueM2;
  10971. // _MAT2
  10972. case 0x8b5b:
  10973. return setValueM3;
  10974. // _MAT3
  10975. case 0x8b5c:
  10976. return setValueM4;
  10977. // _MAT4
  10978. case 0x1404:
  10979. case 0x8b56:
  10980. return setValueV1i;
  10981. // INT, BOOL
  10982. case 0x8b53:
  10983. case 0x8b57:
  10984. return setValueV2i;
  10985. // _VEC2
  10986. case 0x8b54:
  10987. case 0x8b58:
  10988. return setValueV3i;
  10989. // _VEC3
  10990. case 0x8b55:
  10991. case 0x8b59:
  10992. return setValueV4i;
  10993. // _VEC4
  10994. case 0x1405:
  10995. return setValueV1ui;
  10996. // UINT
  10997. case 0x8b5e: // SAMPLER_2D
  10998. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10999. case 0x8dca: // INT_SAMPLER_2D
  11000. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11001. case 0x8b62:
  11002. // SAMPLER_2D_SHADOW
  11003. return setValueT1;
  11004. case 0x8b5f: // SAMPLER_3D
  11005. case 0x8dcb: // INT_SAMPLER_3D
  11006. case 0x8dd3:
  11007. // UNSIGNED_INT_SAMPLER_3D
  11008. return setValueT3D1;
  11009. case 0x8b60: // SAMPLER_CUBE
  11010. case 0x8dcc: // INT_SAMPLER_CUBE
  11011. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11012. case 0x8dc5:
  11013. // SAMPLER_CUBE_SHADOW
  11014. return setValueT6;
  11015. case 0x8dc1: // SAMPLER_2D_ARRAY
  11016. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  11017. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  11018. case 0x8dc4:
  11019. // SAMPLER_2D_ARRAY_SHADOW
  11020. return setValueT2DArray1;
  11021. }
  11022. } // Array of scalars
  11023. function setValueV1fArray(gl, v) {
  11024. gl.uniform1fv(this.addr, v);
  11025. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  11026. function setValueV1iArray(gl, v) {
  11027. gl.uniform1iv(this.addr, v);
  11028. }
  11029. function setValueV2iArray(gl, v) {
  11030. gl.uniform2iv(this.addr, v);
  11031. }
  11032. function setValueV3iArray(gl, v) {
  11033. gl.uniform3iv(this.addr, v);
  11034. }
  11035. function setValueV4iArray(gl, v) {
  11036. gl.uniform4iv(this.addr, v);
  11037. } // Array of vectors (flat or from THREE classes)
  11038. function setValueV2fArray(gl, v) {
  11039. var data = flatten(v, this.size, 2);
  11040. gl.uniform2fv(this.addr, data);
  11041. }
  11042. function setValueV3fArray(gl, v) {
  11043. var data = flatten(v, this.size, 3);
  11044. gl.uniform3fv(this.addr, data);
  11045. }
  11046. function setValueV4fArray(gl, v) {
  11047. var data = flatten(v, this.size, 4);
  11048. gl.uniform4fv(this.addr, data);
  11049. } // Array of matrices (flat or from THREE clases)
  11050. function setValueM2Array(gl, v) {
  11051. var data = flatten(v, this.size, 4);
  11052. gl.uniformMatrix2fv(this.addr, false, data);
  11053. }
  11054. function setValueM3Array(gl, v) {
  11055. var data = flatten(v, this.size, 9);
  11056. gl.uniformMatrix3fv(this.addr, false, data);
  11057. }
  11058. function setValueM4Array(gl, v) {
  11059. var data = flatten(v, this.size, 16);
  11060. gl.uniformMatrix4fv(this.addr, false, data);
  11061. } // Array of textures (2D / Cube)
  11062. function setValueT1Array(gl, v, textures) {
  11063. var n = v.length;
  11064. var units = allocTexUnits(textures, n);
  11065. gl.uniform1iv(this.addr, units);
  11066. for (var i = 0; i !== n; ++i) {
  11067. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  11068. }
  11069. }
  11070. function setValueT6Array(gl, v, textures) {
  11071. var n = v.length;
  11072. var units = allocTexUnits(textures, n);
  11073. gl.uniform1iv(this.addr, units);
  11074. for (var i = 0; i !== n; ++i) {
  11075. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  11076. }
  11077. } // Helper to pick the right setter for a pure (bottom-level) array
  11078. function getPureArraySetter(type) {
  11079. switch (type) {
  11080. case 0x1406:
  11081. return setValueV1fArray;
  11082. // FLOAT
  11083. case 0x8b50:
  11084. return setValueV2fArray;
  11085. // _VEC2
  11086. case 0x8b51:
  11087. return setValueV3fArray;
  11088. // _VEC3
  11089. case 0x8b52:
  11090. return setValueV4fArray;
  11091. // _VEC4
  11092. case 0x8b5a:
  11093. return setValueM2Array;
  11094. // _MAT2
  11095. case 0x8b5b:
  11096. return setValueM3Array;
  11097. // _MAT3
  11098. case 0x8b5c:
  11099. return setValueM4Array;
  11100. // _MAT4
  11101. case 0x1404:
  11102. case 0x8b56:
  11103. return setValueV1iArray;
  11104. // INT, BOOL
  11105. case 0x8b53:
  11106. case 0x8b57:
  11107. return setValueV2iArray;
  11108. // _VEC2
  11109. case 0x8b54:
  11110. case 0x8b58:
  11111. return setValueV3iArray;
  11112. // _VEC3
  11113. case 0x8b55:
  11114. case 0x8b59:
  11115. return setValueV4iArray;
  11116. // _VEC4
  11117. case 0x8b5e: // SAMPLER_2D
  11118. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11119. case 0x8dca: // INT_SAMPLER_2D
  11120. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11121. case 0x8b62:
  11122. // SAMPLER_2D_SHADOW
  11123. return setValueT1Array;
  11124. case 0x8b60: // SAMPLER_CUBE
  11125. case 0x8dcc: // INT_SAMPLER_CUBE
  11126. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11127. case 0x8dc5:
  11128. // SAMPLER_CUBE_SHADOW
  11129. return setValueT6Array;
  11130. }
  11131. } // --- Uniform Classes ---
  11132. function SingleUniform(id, activeInfo, addr) {
  11133. this.id = id;
  11134. this.addr = addr;
  11135. this.cache = [];
  11136. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11137. }
  11138. function PureArrayUniform(id, activeInfo, addr) {
  11139. this.id = id;
  11140. this.addr = addr;
  11141. this.cache = [];
  11142. this.size = activeInfo.size;
  11143. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11144. }
  11145. PureArrayUniform.prototype.updateCache = function (data) {
  11146. var cache = this.cache;
  11147. if (data instanceof Float32Array && cache.length !== data.length) {
  11148. this.cache = new Float32Array(data.length);
  11149. }
  11150. copyArray(cache, data);
  11151. };
  11152. function StructuredUniform(id) {
  11153. this.id = id;
  11154. this.seq = [];
  11155. this.map = {};
  11156. }
  11157. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  11158. var seq = this.seq;
  11159. for (var i = 0, n = seq.length; i !== n; ++i) {
  11160. var u = seq[i];
  11161. u.setValue(gl, value[u.id], textures);
  11162. }
  11163. }; // --- Top-level ---
  11164. // Parser - builds up the property tree from the path strings
  11165. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  11166. // - the identifier (member name or array index)
  11167. // - followed by an optional right bracket (found when array index)
  11168. // - followed by an optional left bracket or dot (type of subscript)
  11169. //
  11170. // Note: These portions can be read in a non-overlapping fashion and
  11171. // allow straightforward parsing of the hierarchy that WebGL encodes
  11172. // in the uniform names.
  11173. function addUniform(container, uniformObject) {
  11174. container.seq.push(uniformObject);
  11175. container.map[uniformObject.id] = uniformObject;
  11176. }
  11177. function parseUniform(activeInfo, addr, container) {
  11178. var path = activeInfo.name,
  11179. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  11180. RePathPart.lastIndex = 0;
  11181. while (true) {
  11182. var match = RePathPart.exec(path),
  11183. matchEnd = RePathPart.lastIndex;
  11184. var id = match[1];
  11185. var idIsIndex = match[2] === ']',
  11186. subscript = match[3];
  11187. if (idIsIndex) id = id | 0; // convert to integer
  11188. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  11189. // bare name or "pure" bottom-level array "[0]" suffix
  11190. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  11191. break;
  11192. } else {
  11193. // step into inner node / create it in case it doesn't exist
  11194. var map = container.map;
  11195. var next = map[id];
  11196. if (next === undefined) {
  11197. next = new StructuredUniform(id);
  11198. addUniform(container, next);
  11199. }
  11200. container = next;
  11201. }
  11202. }
  11203. } // Root Container
  11204. function WebGLUniforms(gl, program) {
  11205. this.seq = [];
  11206. this.map = {};
  11207. var n = gl.getProgramParameter(program, 35718);
  11208. for (var i = 0; i < n; ++i) {
  11209. var info = gl.getActiveUniform(program, i),
  11210. addr = gl.getUniformLocation(program, info.name);
  11211. parseUniform(info, addr, this);
  11212. }
  11213. }
  11214. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  11215. var u = this.map[name];
  11216. if (u !== undefined) u.setValue(gl, value, textures);
  11217. };
  11218. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  11219. var v = object[name];
  11220. if (v !== undefined) this.setValue(gl, name, v);
  11221. }; // Static interface
  11222. WebGLUniforms.upload = function (gl, seq, values, textures) {
  11223. for (var i = 0, n = seq.length; i !== n; ++i) {
  11224. var u = seq[i],
  11225. v = values[u.id];
  11226. if (v.needsUpdate !== false) {
  11227. // note: always updating when .needsUpdate is undefined
  11228. u.setValue(gl, v.value, textures);
  11229. }
  11230. }
  11231. };
  11232. WebGLUniforms.seqWithValue = function (seq, values) {
  11233. var r = [];
  11234. for (var i = 0, n = seq.length; i !== n; ++i) {
  11235. var u = seq[i];
  11236. if (u.id in values) r.push(u);
  11237. }
  11238. return r;
  11239. };
  11240. function WebGLShader(gl, type, string) {
  11241. var shader = gl.createShader(type);
  11242. gl.shaderSource(shader, string);
  11243. gl.compileShader(shader);
  11244. return shader;
  11245. }
  11246. var programIdCount = 0;
  11247. function addLineNumbers(string) {
  11248. var lines = string.split('\n');
  11249. for (var i = 0; i < lines.length; i++) {
  11250. lines[i] = i + 1 + ': ' + lines[i];
  11251. }
  11252. return lines.join('\n');
  11253. }
  11254. function getEncodingComponents(encoding) {
  11255. switch (encoding) {
  11256. case LinearEncoding:
  11257. return ['Linear', '( value )'];
  11258. case sRGBEncoding:
  11259. return ['sRGB', '( value )'];
  11260. case RGBEEncoding:
  11261. return ['RGBE', '( value )'];
  11262. case RGBM7Encoding:
  11263. return ['RGBM', '( value, 7.0 )'];
  11264. case RGBM16Encoding:
  11265. return ['RGBM', '( value, 16.0 )'];
  11266. case RGBDEncoding:
  11267. return ['RGBD', '( value, 256.0 )'];
  11268. case GammaEncoding:
  11269. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  11270. case LogLuvEncoding:
  11271. return ['LogLuv', '( value )'];
  11272. default:
  11273. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  11274. return ['Linear', '( value )'];
  11275. }
  11276. }
  11277. function getShaderErrors(gl, shader, type) {
  11278. var status = gl.getShaderParameter(shader, 35713);
  11279. var log = gl.getShaderInfoLog(shader).trim();
  11280. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  11281. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11282. var source = gl.getShaderSource(shader);
  11283. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  11284. }
  11285. function getTexelDecodingFunction(functionName, encoding) {
  11286. var components = getEncodingComponents(encoding);
  11287. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  11288. }
  11289. function getTexelEncodingFunction(functionName, encoding) {
  11290. var components = getEncodingComponents(encoding);
  11291. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  11292. }
  11293. function getToneMappingFunction(functionName, toneMapping) {
  11294. var toneMappingName;
  11295. switch (toneMapping) {
  11296. case LinearToneMapping:
  11297. toneMappingName = 'Linear';
  11298. break;
  11299. case ReinhardToneMapping:
  11300. toneMappingName = 'Reinhard';
  11301. break;
  11302. case CineonToneMapping:
  11303. toneMappingName = 'OptimizedCineon';
  11304. break;
  11305. case ACESFilmicToneMapping:
  11306. toneMappingName = 'ACESFilmic';
  11307. break;
  11308. case CustomToneMapping:
  11309. toneMappingName = 'Custom';
  11310. break;
  11311. default:
  11312. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  11313. toneMappingName = 'Linear';
  11314. }
  11315. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11316. }
  11317. function generateExtensions(parameters) {
  11318. var chunks = [parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ? '#extension GL_OES_standard_derivatives : enable' : '', (parameters.extensionFragDepth || parameters.logarithmicDepthBuffer) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '', parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ? '#extension GL_EXT_draw_buffers : require' : '', (parameters.extensionShaderTextureLOD || parameters.envMap) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''];
  11319. return chunks.filter(filterEmptyLine).join('\n');
  11320. }
  11321. function generateDefines(defines) {
  11322. var chunks = [];
  11323. for (var name in defines) {
  11324. var value = defines[name];
  11325. if (value === false) continue;
  11326. chunks.push('#define ' + name + ' ' + value);
  11327. }
  11328. return chunks.join('\n');
  11329. }
  11330. function fetchAttributeLocations(gl, program) {
  11331. var attributes = {};
  11332. var n = gl.getProgramParameter(program, 35721);
  11333. for (var i = 0; i < n; i++) {
  11334. var info = gl.getActiveAttrib(program, i);
  11335. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11336. attributes[name] = gl.getAttribLocation(program, name);
  11337. }
  11338. return attributes;
  11339. }
  11340. function filterEmptyLine(string) {
  11341. return string !== '';
  11342. }
  11343. function replaceLightNums(string, parameters) {
  11344. return string.replace(/NUM_DIR_LIGHTS/g, parameters.numDirLights).replace(/NUM_SPOT_LIGHTS/g, parameters.numSpotLights).replace(/NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g, parameters.numPointLights).replace(/NUM_HEMI_LIGHTS/g, parameters.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows);
  11345. }
  11346. function replaceClippingPlaneNums(string, parameters) {
  11347. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  11348. } // Resolve Includes
  11349. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11350. function resolveIncludes(string) {
  11351. return string.replace(includePattern, includeReplacer);
  11352. }
  11353. function includeReplacer(match, include) {
  11354. var string = ShaderChunk[include];
  11355. if (string === undefined) {
  11356. throw new Error('Can not resolve #include <' + include + '>');
  11357. }
  11358. return resolveIncludes(string);
  11359. } // Unroll Loops
  11360. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11361. var unrollLoopPattern = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;
  11362. function unrollLoops(string) {
  11363. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  11364. }
  11365. function deprecatedLoopReplacer(match, start, end, snippet) {
  11366. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  11367. return loopReplacer(match, start, end, snippet);
  11368. }
  11369. function loopReplacer(match, start, end, snippet) {
  11370. var string = '';
  11371. for (var i = parseInt(start); i < parseInt(end); i++) {
  11372. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  11373. }
  11374. return string;
  11375. } //
  11376. function generatePrecision(parameters) {
  11377. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  11378. if (parameters.precision === 'highp') {
  11379. precisionstring += '\n#define HIGH_PRECISION';
  11380. } else if (parameters.precision === 'mediump') {
  11381. precisionstring += '\n#define MEDIUM_PRECISION';
  11382. } else if (parameters.precision === 'lowp') {
  11383. precisionstring += '\n#define LOW_PRECISION';
  11384. }
  11385. return precisionstring;
  11386. }
  11387. function generateShadowMapTypeDefine(parameters) {
  11388. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11389. if (parameters.shadowMapType === PCFShadowMap) {
  11390. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11391. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  11392. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11393. } else if (parameters.shadowMapType === VSMShadowMap) {
  11394. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11395. }
  11396. return shadowMapTypeDefine;
  11397. }
  11398. function generateEnvMapTypeDefine(parameters) {
  11399. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11400. if (parameters.envMap) {
  11401. switch (parameters.envMapMode) {
  11402. case CubeReflectionMapping:
  11403. case CubeRefractionMapping:
  11404. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11405. break;
  11406. case CubeUVReflectionMapping:
  11407. case CubeUVRefractionMapping:
  11408. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11409. break;
  11410. }
  11411. }
  11412. return envMapTypeDefine;
  11413. }
  11414. function generateEnvMapModeDefine(parameters) {
  11415. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11416. if (parameters.envMap) {
  11417. switch (parameters.envMapMode) {
  11418. case CubeRefractionMapping:
  11419. case CubeUVRefractionMapping:
  11420. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11421. break;
  11422. }
  11423. }
  11424. return envMapModeDefine;
  11425. }
  11426. function generateEnvMapBlendingDefine(parameters) {
  11427. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11428. if (parameters.envMap) {
  11429. switch (parameters.combine) {
  11430. case MultiplyOperation:
  11431. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11432. break;
  11433. case MixOperation:
  11434. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11435. break;
  11436. case AddOperation:
  11437. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11438. break;
  11439. }
  11440. }
  11441. return envMapBlendingDefine;
  11442. }
  11443. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  11444. var gl = renderer.getContext();
  11445. var defines = parameters.defines;
  11446. var vertexShader = parameters.vertexShader;
  11447. var fragmentShader = parameters.fragmentShader;
  11448. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  11449. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  11450. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  11451. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  11452. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  11453. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  11454. var customDefines = generateDefines(defines);
  11455. var program = gl.createProgram();
  11456. var prefixVertex, prefixFragment;
  11457. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11458. if (parameters.isRawShaderMaterial) {
  11459. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  11460. if (prefixVertex.length > 0) {
  11461. prefixVertex += '\n';
  11462. }
  11463. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  11464. if (prefixFragment.length > 0) {
  11465. prefixFragment += '\n';
  11466. }
  11467. } else {
  11468. prefixVertex = [generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.instancing ? '#define USE_INSTANCING' : '', parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '', parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '', '#define GAMMA_FACTOR ' + gammaFactorDefine, '#define MAX_BONES ' + parameters.maxBones, parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', parameters.map ? '#define USE_MAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapModeDefine : '', parameters.lightMap ? '#define USE_LIGHTMAP' : '', parameters.aoMap ? '#define USE_AOMAP' : '', parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', parameters.bumpMap ? '#define USE_BUMPMAP' : '', parameters.normalMap ? '#define USE_NORMALMAP' : '', parameters.normalMap && parameters.objectSpaceNormalMap ? '#define OBJECTSPACE_NORMALMAP' : '', parameters.normalMap && parameters.tangentSpaceNormalMap ? '#define TANGENTSPACE_NORMALMAP' : '', parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '', parameters.specularMap ? '#define USE_SPECULARMAP' : '', parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', parameters.vertexTangents ? '#define USE_TANGENT' : '', parameters.vertexColors ? '#define USE_COLOR' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', parameters.skinning ? '#define USE_SKINNING' : '', parameters.useVertexTexture ? '#define BONE_TEXTURE' : '', parameters.morphTargets ? '#define USE_MORPHTARGETS' : '', parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '', parameters.doubleSided ? '#define DOUBLE_SIDED' : '', parameters.flipSided ? '#define FLIP_SIDED' : '', parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '', parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', 'uniform mat4 modelMatrix;', 'uniform mat4 modelViewMatrix;', 'uniform mat4 projectionMatrix;', 'uniform mat4 viewMatrix;', 'uniform mat3 normalMatrix;', 'uniform vec3 cameraPosition;', 'uniform bool isOrthographic;', '#ifdef USE_INSTANCING', ' attribute mat4 instanceMatrix;', '#endif', '#ifdef USE_INSTANCING_COLOR', ' attribute vec3 instanceColor;', '#endif', 'attribute vec3 position;', 'attribute vec3 normal;', 'attribute vec2 uv;', '#ifdef USE_TANGENT', ' attribute vec4 tangent;', '#endif', '#ifdef USE_COLOR', ' attribute vec3 color;', '#endif', '#ifdef USE_MORPHTARGETS', ' attribute vec3 morphTarget0;', ' attribute vec3 morphTarget1;', ' attribute vec3 morphTarget2;', ' attribute vec3 morphTarget3;', ' #ifdef USE_MORPHNORMALS', ' attribute vec3 morphNormal0;', ' attribute vec3 morphNormal1;', ' attribute vec3 morphNormal2;', ' attribute vec3 morphNormal3;', ' #else', ' attribute vec3 morphTarget4;', ' attribute vec3 morphTarget5;', ' attribute vec3 morphTarget6;', ' attribute vec3 morphTarget7;', ' #endif', '#endif', '#ifdef USE_SKINNING', ' attribute vec4 skinIndex;', ' attribute vec4 skinWeight;', '#endif', '\n'].filter(filterEmptyLine).join('\n');
  11469. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  11470. '#define GAMMA_FACTOR ' + gammaFactorDefine, parameters.useFog && parameters.fog ? '#define USE_FOG' : '', parameters.useFog && parameters.fogExp2 ? '#define FOG_EXP2' : '', parameters.map ? '#define USE_MAP' : '', parameters.matcap ? '#define USE_MATCAP' : '', parameters.envMap ? '#define USE_ENVMAP' : '', parameters.envMap ? '#define ' + envMapTypeDefine : '', parameters.envMap ? '#define ' + envMapModeDefine : '', parameters.envMap ? '#define ' + envMapBlendingDefine : '', parameters.lightMap ? '#define USE_LIGHTMAP' : '', parameters.aoMap ? '#define USE_AOMAP' : '', parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '', parameters.bumpMap ? '#define USE_BUMPMAP' : '', parameters.normalMap ? '#define USE_NORMALMAP' : '', parameters.normalMap && parameters.objectSpaceNormalMap ? '#define OBJECTSPACE_NORMALMAP' : '', parameters.normalMap && parameters.tangentSpaceNormalMap ? '#define TANGENTSPACE_NORMALMAP' : '', parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '', parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '', parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '', parameters.specularMap ? '#define USE_SPECULARMAP' : '', parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', parameters.sheen ? '#define USE_SHEEN' : '', parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '', parameters.vertexTangents ? '#define USE_TANGENT' : '', parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '', parameters.vertexUvs ? '#define USE_UV' : '', parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '', parameters.gradientMap ? '#define USE_GRADIENTMAP' : '', parameters.flatShading ? '#define FLAT_SHADED' : '', parameters.doubleSided ? '#define DOUBLE_SIDED' : '', parameters.flipSided ? '#define FLIP_SIDED' : '', parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '', parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '', parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '', parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '', parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? '#define USE_LOGDEPTHBUF_EXT' : '', (parameters.extensionShaderTextureLOD || parameters.envMap) && parameters.rendererExtensionShaderTextureLod ? '#define TEXTURE_LOD_EXT' : '', 'uniform mat4 viewMatrix;', 'uniform vec3 cameraPosition;', 'uniform bool isOrthographic;', parameters.toneMapping !== NoToneMapping ? '#define TONE_MAPPING' : '', parameters.toneMapping !== NoToneMapping ? ShaderChunk['tonemapping_pars_fragment'] : '', // this code is required here because it is used by the toneMapping() function defined below
  11471. parameters.toneMapping !== NoToneMapping ? getToneMappingFunction('toneMapping', parameters.toneMapping) : '', parameters.dithering ? '#define DITHERING' : '', ShaderChunk['encodings_pars_fragment'], // this code is required here because it is used by the various encoding/decoding function defined below
  11472. parameters.map ? getTexelDecodingFunction('mapTexelToLinear', parameters.mapEncoding) : '', parameters.matcap ? getTexelDecodingFunction('matcapTexelToLinear', parameters.matcapEncoding) : '', parameters.envMap ? getTexelDecodingFunction('envMapTexelToLinear', parameters.envMapEncoding) : '', parameters.emissiveMap ? getTexelDecodingFunction('emissiveMapTexelToLinear', parameters.emissiveMapEncoding) : '', parameters.lightMap ? getTexelDecodingFunction('lightMapTexelToLinear', parameters.lightMapEncoding) : '', getTexelEncodingFunction('linearToOutputTexel', parameters.outputEncoding), parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '', '\n'].filter(filterEmptyLine).join('\n');
  11473. }
  11474. vertexShader = resolveIncludes(vertexShader);
  11475. vertexShader = replaceLightNums(vertexShader, parameters);
  11476. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  11477. fragmentShader = resolveIncludes(fragmentShader);
  11478. fragmentShader = replaceLightNums(fragmentShader, parameters);
  11479. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  11480. vertexShader = unrollLoops(vertexShader);
  11481. fragmentShader = unrollLoops(fragmentShader);
  11482. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  11483. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11484. versionString = '#version 300 es\n';
  11485. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  11486. prefixFragment = ['#define varying in', parameters.glslVersion === GLSL3 ? '' : 'out highp vec4 pc_fragColor;', parameters.glslVersion === GLSL3 ? '' : '#define gl_FragColor pc_fragColor', '#define gl_FragDepthEXT gl_FragDepth', '#define texture2D texture', '#define textureCube texture', '#define texture2DProj textureProj', '#define texture2DLodEXT textureLod', '#define texture2DProjLodEXT textureProjLod', '#define textureCubeLodEXT textureLod', '#define texture2DGradEXT textureGrad', '#define texture2DProjGradEXT textureProjGrad', '#define textureCubeGradEXT textureGrad'].join('\n') + '\n' + prefixFragment;
  11487. }
  11488. var vertexGlsl = versionString + prefixVertex + vertexShader;
  11489. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  11490. // console.log( '*FRAGMENT*', fragmentGlsl );
  11491. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  11492. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  11493. gl.attachShader(program, glVertexShader);
  11494. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  11495. if (parameters.index0AttributeName !== undefined) {
  11496. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  11497. } else if (parameters.morphTargets === true) {
  11498. // programs with morphTargets displace position out of attribute 0
  11499. gl.bindAttribLocation(program, 0, 'position');
  11500. }
  11501. gl.linkProgram(program); // check for link errors
  11502. if (renderer.debug.checkShaderErrors) {
  11503. var programLog = gl.getProgramInfoLog(program).trim();
  11504. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  11505. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  11506. var runnable = true;
  11507. var haveDiagnostics = true;
  11508. if (gl.getProgramParameter(program, 35714) === false) {
  11509. runnable = false;
  11510. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  11511. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  11512. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11513. } else if (programLog !== '') {
  11514. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11515. } else if (vertexLog === '' || fragmentLog === '') {
  11516. haveDiagnostics = false;
  11517. }
  11518. if (haveDiagnostics) {
  11519. this.diagnostics = {
  11520. runnable: runnable,
  11521. programLog: programLog,
  11522. vertexShader: {
  11523. log: vertexLog,
  11524. prefix: prefixVertex
  11525. },
  11526. fragmentShader: {
  11527. log: fragmentLog,
  11528. prefix: prefixFragment
  11529. }
  11530. };
  11531. }
  11532. } // Clean up
  11533. // Crashes in iOS9 and iOS10. #18402
  11534. // gl.detachShader( program, glVertexShader );
  11535. // gl.detachShader( program, glFragmentShader );
  11536. gl.deleteShader(glVertexShader);
  11537. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11538. var cachedUniforms;
  11539. this.getUniforms = function () {
  11540. if (cachedUniforms === undefined) {
  11541. cachedUniforms = new WebGLUniforms(gl, program);
  11542. }
  11543. return cachedUniforms;
  11544. }; // set up caching for attribute locations
  11545. var cachedAttributes;
  11546. this.getAttributes = function () {
  11547. if (cachedAttributes === undefined) {
  11548. cachedAttributes = fetchAttributeLocations(gl, program);
  11549. }
  11550. return cachedAttributes;
  11551. }; // free resource
  11552. this.destroy = function () {
  11553. bindingStates.releaseStatesOfProgram(this);
  11554. gl.deleteProgram(program);
  11555. this.program = undefined;
  11556. }; //
  11557. this.name = parameters.shaderName;
  11558. this.id = programIdCount++;
  11559. this.cacheKey = cacheKey;
  11560. this.usedTimes = 1;
  11561. this.program = program;
  11562. this.vertexShader = glVertexShader;
  11563. this.fragmentShader = glFragmentShader;
  11564. return this;
  11565. }
  11566. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11567. var programs = [];
  11568. var isWebGL2 = capabilities.isWebGL2;
  11569. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11570. var floatVertexTextures = capabilities.floatVertexTextures;
  11571. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11572. var vertexTextures = capabilities.vertexTextures;
  11573. var precision = capabilities.precision;
  11574. var shaderIDs = {
  11575. MeshDepthMaterial: 'depth',
  11576. MeshDistanceMaterial: 'distanceRGBA',
  11577. MeshNormalMaterial: 'normal',
  11578. MeshBasicMaterial: 'basic',
  11579. MeshLambertMaterial: 'lambert',
  11580. MeshPhongMaterial: 'phong',
  11581. MeshToonMaterial: 'toon',
  11582. MeshStandardMaterial: 'physical',
  11583. MeshPhysicalMaterial: 'physical',
  11584. MeshMatcapMaterial: 'matcap',
  11585. LineBasicMaterial: 'basic',
  11586. LineDashedMaterial: 'dashed',
  11587. PointsMaterial: 'points',
  11588. ShadowMaterial: 'shadow',
  11589. SpriteMaterial: 'sprite'
  11590. };
  11591. var parameterNames = ['precision', 'isWebGL2', 'supportsVertexTextures', 'outputEncoding', 'instancing', 'instancingColor', 'map', 'mapEncoding', 'matcap', 'matcapEncoding', 'envMap', 'envMapMode', 'envMapEncoding', 'envMapCubeUV', 'lightMap', 'lightMapEncoding', 'aoMap', 'emissiveMap', 'emissiveMapEncoding', 'bumpMap', 'normalMap', 'objectSpaceNormalMap', 'tangentSpaceNormalMap', 'clearcoatMap', 'clearcoatRoughnessMap', 'clearcoatNormalMap', 'displacementMap', 'specularMap', 'roughnessMap', 'metalnessMap', 'gradientMap', 'alphaMap', 'combine', 'vertexColors', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2', 'flatShading', 'sizeAttenuation', 'logarithmicDepthBuffer', 'skinning', 'maxBones', 'useVertexTexture', 'morphTargets', 'morphNormals', 'maxMorphTargets', 'maxMorphNormals', 'premultipliedAlpha', 'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights', 'numDirLightShadows', 'numPointLightShadows', 'numSpotLightShadows', 'shadowMapEnabled', 'shadowMapType', 'toneMapping', 'physicallyCorrectLights', 'alphaTest', 'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering', 'sheen', 'transmissionMap'];
  11592. function getMaxBones(object) {
  11593. var skeleton = object.skeleton;
  11594. var bones = skeleton.bones;
  11595. if (floatVertexTextures) {
  11596. return 1024;
  11597. } else {
  11598. // default for when object is not specified
  11599. // ( for example when prebuilding shader to be used with multiple objects )
  11600. //
  11601. // - leave some extra space for other uniforms
  11602. // - limit here is ANGLE's 254 max uniform vectors
  11603. // (up to 54 should be safe)
  11604. var nVertexUniforms = maxVertexUniforms;
  11605. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11606. var maxBones = Math.min(nVertexMatrices, bones.length);
  11607. if (maxBones < bones.length) {
  11608. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11609. return 0;
  11610. }
  11611. return maxBones;
  11612. }
  11613. }
  11614. function getTextureEncodingFromMap(map) {
  11615. var encoding;
  11616. if (map && map.isTexture) {
  11617. encoding = map.encoding;
  11618. } else if (map && map.isWebGLRenderTarget) {
  11619. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11620. encoding = map.texture.encoding;
  11621. } else {
  11622. encoding = LinearEncoding;
  11623. }
  11624. return encoding;
  11625. }
  11626. function getParameters(material, lights, shadows, scene, object) {
  11627. var fog = scene.fog;
  11628. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11629. var envMap = cubemaps.get(material.envMap || environment);
  11630. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11631. // (not to blow over maxLights budget)
  11632. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11633. if (material.precision !== null) {
  11634. precision = capabilities.getMaxPrecision(material.precision);
  11635. if (precision !== material.precision) {
  11636. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11637. }
  11638. }
  11639. var vertexShader, fragmentShader;
  11640. if (shaderID) {
  11641. var shader = ShaderLib[shaderID];
  11642. vertexShader = shader.vertexShader;
  11643. fragmentShader = shader.fragmentShader;
  11644. } else {
  11645. vertexShader = material.vertexShader;
  11646. fragmentShader = material.fragmentShader;
  11647. }
  11648. var currentRenderTarget = renderer.getRenderTarget();
  11649. var parameters = {
  11650. isWebGL2: isWebGL2,
  11651. shaderID: shaderID,
  11652. shaderName: material.type,
  11653. vertexShader: vertexShader,
  11654. fragmentShader: fragmentShader,
  11655. defines: material.defines,
  11656. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11657. glslVersion: material.glslVersion,
  11658. precision: precision,
  11659. instancing: object.isInstancedMesh === true,
  11660. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11661. supportsVertexTextures: vertexTextures,
  11662. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11663. map: !!material.map,
  11664. mapEncoding: getTextureEncodingFromMap(material.map),
  11665. matcap: !!material.matcap,
  11666. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11667. envMap: !!envMap,
  11668. envMapMode: envMap && envMap.mapping,
  11669. envMapEncoding: getTextureEncodingFromMap(envMap),
  11670. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11671. lightMap: !!material.lightMap,
  11672. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11673. aoMap: !!material.aoMap,
  11674. emissiveMap: !!material.emissiveMap,
  11675. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11676. bumpMap: !!material.bumpMap,
  11677. normalMap: !!material.normalMap,
  11678. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11679. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11680. clearcoatMap: !!material.clearcoatMap,
  11681. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11682. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11683. displacementMap: !!material.displacementMap,
  11684. roughnessMap: !!material.roughnessMap,
  11685. metalnessMap: !!material.metalnessMap,
  11686. specularMap: !!material.specularMap,
  11687. alphaMap: !!material.alphaMap,
  11688. gradientMap: !!material.gradientMap,
  11689. sheen: !!material.sheen,
  11690. transmissionMap: !!material.transmissionMap,
  11691. combine: material.combine,
  11692. vertexTangents: material.normalMap && material.vertexTangents,
  11693. vertexColors: material.vertexColors,
  11694. vertexUvs: !!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatMap || !!material.clearcoatRoughnessMap || !!material.clearcoatNormalMap || !!material.displacementMap || !!material.transmissionMap,
  11695. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11696. fog: !!fog,
  11697. useFog: material.fog,
  11698. fogExp2: fog && fog.isFogExp2,
  11699. flatShading: !!material.flatShading,
  11700. sizeAttenuation: material.sizeAttenuation,
  11701. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11702. skinning: material.skinning && maxBones > 0,
  11703. maxBones: maxBones,
  11704. useVertexTexture: floatVertexTextures,
  11705. morphTargets: material.morphTargets,
  11706. morphNormals: material.morphNormals,
  11707. maxMorphTargets: renderer.maxMorphTargets,
  11708. maxMorphNormals: renderer.maxMorphNormals,
  11709. numDirLights: lights.directional.length,
  11710. numPointLights: lights.point.length,
  11711. numSpotLights: lights.spot.length,
  11712. numRectAreaLights: lights.rectArea.length,
  11713. numHemiLights: lights.hemi.length,
  11714. numDirLightShadows: lights.directionalShadowMap.length,
  11715. numPointLightShadows: lights.pointShadowMap.length,
  11716. numSpotLightShadows: lights.spotShadowMap.length,
  11717. numClippingPlanes: clipping.numPlanes,
  11718. numClipIntersection: clipping.numIntersection,
  11719. dithering: material.dithering,
  11720. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11721. shadowMapType: renderer.shadowMap.type,
  11722. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11723. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11724. premultipliedAlpha: material.premultipliedAlpha,
  11725. alphaTest: material.alphaTest,
  11726. doubleSided: material.side === DoubleSide,
  11727. flipSided: material.side === BackSide,
  11728. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11729. index0AttributeName: material.index0AttributeName,
  11730. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11731. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11732. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11733. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11734. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11735. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11736. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11737. customProgramCacheKey: material.customProgramCacheKey()
  11738. };
  11739. return parameters;
  11740. }
  11741. function getProgramCacheKey(parameters) {
  11742. var array = [];
  11743. if (parameters.shaderID) {
  11744. array.push(parameters.shaderID);
  11745. } else {
  11746. array.push(parameters.fragmentShader);
  11747. array.push(parameters.vertexShader);
  11748. }
  11749. if (parameters.defines !== undefined) {
  11750. for (var name in parameters.defines) {
  11751. array.push(name);
  11752. array.push(parameters.defines[name]);
  11753. }
  11754. }
  11755. if (parameters.isRawShaderMaterial === false) {
  11756. for (var i = 0; i < parameterNames.length; i++) {
  11757. array.push(parameters[parameterNames[i]]);
  11758. }
  11759. array.push(renderer.outputEncoding);
  11760. array.push(renderer.gammaFactor);
  11761. }
  11762. array.push(parameters.customProgramCacheKey);
  11763. return array.join();
  11764. }
  11765. function getUniforms(material) {
  11766. var shaderID = shaderIDs[material.type];
  11767. var uniforms;
  11768. if (shaderID) {
  11769. var shader = ShaderLib[shaderID];
  11770. uniforms = UniformsUtils.clone(shader.uniforms);
  11771. } else {
  11772. uniforms = material.uniforms;
  11773. }
  11774. return uniforms;
  11775. }
  11776. function acquireProgram(parameters, cacheKey) {
  11777. var program; // Check if code has been already compiled
  11778. for (var p = 0, pl = programs.length; p < pl; p++) {
  11779. var preexistingProgram = programs[p];
  11780. if (preexistingProgram.cacheKey === cacheKey) {
  11781. program = preexistingProgram;
  11782. ++program.usedTimes;
  11783. break;
  11784. }
  11785. }
  11786. if (program === undefined) {
  11787. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11788. programs.push(program);
  11789. }
  11790. return program;
  11791. }
  11792. function releaseProgram(program) {
  11793. if (--program.usedTimes === 0) {
  11794. // Remove from unordered set
  11795. var i = programs.indexOf(program);
  11796. programs[i] = programs[programs.length - 1];
  11797. programs.pop(); // Free WebGL resources
  11798. program.destroy();
  11799. }
  11800. }
  11801. return {
  11802. getParameters: getParameters,
  11803. getProgramCacheKey: getProgramCacheKey,
  11804. getUniforms: getUniforms,
  11805. acquireProgram: acquireProgram,
  11806. releaseProgram: releaseProgram,
  11807. // Exposed for resource monitoring & error feedback via renderer.info:
  11808. programs: programs
  11809. };
  11810. }
  11811. function WebGLProperties() {
  11812. var properties = new WeakMap();
  11813. function get(object) {
  11814. var map = properties.get(object);
  11815. if (map === undefined) {
  11816. map = {};
  11817. properties.set(object, map);
  11818. }
  11819. return map;
  11820. }
  11821. function remove(object) {
  11822. properties.delete(object);
  11823. }
  11824. function update(object, key, value) {
  11825. properties.get(object)[key] = value;
  11826. }
  11827. function dispose() {
  11828. properties = new WeakMap();
  11829. }
  11830. return {
  11831. get: get,
  11832. remove: remove,
  11833. update: update,
  11834. dispose: dispose
  11835. };
  11836. }
  11837. function painterSortStable(a, b) {
  11838. if (a.groupOrder !== b.groupOrder) {
  11839. return a.groupOrder - b.groupOrder;
  11840. } else if (a.renderOrder !== b.renderOrder) {
  11841. return a.renderOrder - b.renderOrder;
  11842. } else if (a.program !== b.program) {
  11843. return a.program.id - b.program.id;
  11844. } else if (a.material.id !== b.material.id) {
  11845. return a.material.id - b.material.id;
  11846. } else if (a.z !== b.z) {
  11847. return a.z - b.z;
  11848. } else {
  11849. return a.id - b.id;
  11850. }
  11851. }
  11852. function reversePainterSortStable(a, b) {
  11853. if (a.groupOrder !== b.groupOrder) {
  11854. return a.groupOrder - b.groupOrder;
  11855. } else if (a.renderOrder !== b.renderOrder) {
  11856. return a.renderOrder - b.renderOrder;
  11857. } else if (a.z !== b.z) {
  11858. return b.z - a.z;
  11859. } else {
  11860. return a.id - b.id;
  11861. }
  11862. }
  11863. function WebGLRenderList(properties) {
  11864. var renderItems = [];
  11865. var renderItemsIndex = 0;
  11866. var opaque = [];
  11867. var transparent = [];
  11868. var defaultProgram = {
  11869. id: -1
  11870. };
  11871. function init() {
  11872. renderItemsIndex = 0;
  11873. opaque.length = 0;
  11874. transparent.length = 0;
  11875. }
  11876. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11877. var renderItem = renderItems[renderItemsIndex];
  11878. var materialProperties = properties.get(material);
  11879. if (renderItem === undefined) {
  11880. renderItem = {
  11881. id: object.id,
  11882. object: object,
  11883. geometry: geometry,
  11884. material: material,
  11885. program: materialProperties.program || defaultProgram,
  11886. groupOrder: groupOrder,
  11887. renderOrder: object.renderOrder,
  11888. z: z,
  11889. group: group
  11890. };
  11891. renderItems[renderItemsIndex] = renderItem;
  11892. } else {
  11893. renderItem.id = object.id;
  11894. renderItem.object = object;
  11895. renderItem.geometry = geometry;
  11896. renderItem.material = material;
  11897. renderItem.program = materialProperties.program || defaultProgram;
  11898. renderItem.groupOrder = groupOrder;
  11899. renderItem.renderOrder = object.renderOrder;
  11900. renderItem.z = z;
  11901. renderItem.group = group;
  11902. }
  11903. renderItemsIndex++;
  11904. return renderItem;
  11905. }
  11906. function push(object, geometry, material, groupOrder, z, group) {
  11907. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11908. (material.transparent === true ? transparent : opaque).push(renderItem);
  11909. }
  11910. function unshift(object, geometry, material, groupOrder, z, group) {
  11911. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11912. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11913. }
  11914. function sort(customOpaqueSort, customTransparentSort) {
  11915. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11916. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11917. }
  11918. function finish() {
  11919. // Clear references from inactive renderItems in the list
  11920. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11921. var renderItem = renderItems[i];
  11922. if (renderItem.id === null) break;
  11923. renderItem.id = null;
  11924. renderItem.object = null;
  11925. renderItem.geometry = null;
  11926. renderItem.material = null;
  11927. renderItem.program = null;
  11928. renderItem.group = null;
  11929. }
  11930. }
  11931. return {
  11932. opaque: opaque,
  11933. transparent: transparent,
  11934. init: init,
  11935. push: push,
  11936. unshift: unshift,
  11937. finish: finish,
  11938. sort: sort
  11939. };
  11940. }
  11941. function WebGLRenderLists(properties) {
  11942. var lists = new WeakMap();
  11943. function get(scene, renderCallDepth) {
  11944. var list;
  11945. if (lists.has(scene) === false) {
  11946. list = new WebGLRenderList(properties);
  11947. lists.set(scene, [list]);
  11948. } else {
  11949. if (renderCallDepth >= lists.get(scene).length) {
  11950. list = new WebGLRenderList(properties);
  11951. lists.get(scene).push(list);
  11952. } else {
  11953. list = lists.get(scene)[renderCallDepth];
  11954. }
  11955. }
  11956. return list;
  11957. }
  11958. function dispose() {
  11959. lists = new WeakMap();
  11960. }
  11961. return {
  11962. get: get,
  11963. dispose: dispose
  11964. };
  11965. }
  11966. function UniformsCache() {
  11967. var lights = {};
  11968. return {
  11969. get: function get(light) {
  11970. if (lights[light.id] !== undefined) {
  11971. return lights[light.id];
  11972. }
  11973. var uniforms;
  11974. switch (light.type) {
  11975. case 'DirectionalLight':
  11976. uniforms = {
  11977. direction: new Vector3(),
  11978. color: new Color()
  11979. };
  11980. break;
  11981. case 'SpotLight':
  11982. uniforms = {
  11983. position: new Vector3(),
  11984. direction: new Vector3(),
  11985. color: new Color(),
  11986. distance: 0,
  11987. coneCos: 0,
  11988. penumbraCos: 0,
  11989. decay: 0
  11990. };
  11991. break;
  11992. case 'PointLight':
  11993. uniforms = {
  11994. position: new Vector3(),
  11995. color: new Color(),
  11996. distance: 0,
  11997. decay: 0
  11998. };
  11999. break;
  12000. case 'HemisphereLight':
  12001. uniforms = {
  12002. direction: new Vector3(),
  12003. skyColor: new Color(),
  12004. groundColor: new Color()
  12005. };
  12006. break;
  12007. case 'RectAreaLight':
  12008. uniforms = {
  12009. color: new Color(),
  12010. position: new Vector3(),
  12011. halfWidth: new Vector3(),
  12012. halfHeight: new Vector3()
  12013. };
  12014. break;
  12015. }
  12016. lights[light.id] = uniforms;
  12017. return uniforms;
  12018. }
  12019. };
  12020. }
  12021. function ShadowUniformsCache() {
  12022. var lights = {};
  12023. return {
  12024. get: function get(light) {
  12025. if (lights[light.id] !== undefined) {
  12026. return lights[light.id];
  12027. }
  12028. var uniforms;
  12029. switch (light.type) {
  12030. case 'DirectionalLight':
  12031. uniforms = {
  12032. shadowBias: 0,
  12033. shadowNormalBias: 0,
  12034. shadowRadius: 1,
  12035. shadowMapSize: new Vector2()
  12036. };
  12037. break;
  12038. case 'SpotLight':
  12039. uniforms = {
  12040. shadowBias: 0,
  12041. shadowNormalBias: 0,
  12042. shadowRadius: 1,
  12043. shadowMapSize: new Vector2()
  12044. };
  12045. break;
  12046. case 'PointLight':
  12047. uniforms = {
  12048. shadowBias: 0,
  12049. shadowNormalBias: 0,
  12050. shadowRadius: 1,
  12051. shadowMapSize: new Vector2(),
  12052. shadowCameraNear: 1,
  12053. shadowCameraFar: 1000
  12054. };
  12055. break;
  12056. // TODO (abelnation): set RectAreaLight shadow uniforms
  12057. }
  12058. lights[light.id] = uniforms;
  12059. return uniforms;
  12060. }
  12061. };
  12062. }
  12063. var nextVersion = 0;
  12064. function shadowCastingLightsFirst(lightA, lightB) {
  12065. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  12066. }
  12067. function WebGLLights(extensions, capabilities) {
  12068. var cache = new UniformsCache();
  12069. var shadowCache = ShadowUniformsCache();
  12070. var state = {
  12071. version: 0,
  12072. hash: {
  12073. directionalLength: -1,
  12074. pointLength: -1,
  12075. spotLength: -1,
  12076. rectAreaLength: -1,
  12077. hemiLength: -1,
  12078. numDirectionalShadows: -1,
  12079. numPointShadows: -1,
  12080. numSpotShadows: -1
  12081. },
  12082. ambient: [0, 0, 0],
  12083. probe: [],
  12084. directional: [],
  12085. directionalShadow: [],
  12086. directionalShadowMap: [],
  12087. directionalShadowMatrix: [],
  12088. spot: [],
  12089. spotShadow: [],
  12090. spotShadowMap: [],
  12091. spotShadowMatrix: [],
  12092. rectArea: [],
  12093. rectAreaLTC1: null,
  12094. rectAreaLTC2: null,
  12095. point: [],
  12096. pointShadow: [],
  12097. pointShadowMap: [],
  12098. pointShadowMatrix: [],
  12099. hemi: []
  12100. };
  12101. for (var i = 0; i < 9; i++) {
  12102. state.probe.push(new Vector3());
  12103. }
  12104. var vector3 = new Vector3();
  12105. var matrix4 = new Matrix4();
  12106. var matrix42 = new Matrix4();
  12107. function setup(lights) {
  12108. var r = 0,
  12109. g = 0,
  12110. b = 0;
  12111. for (var _i = 0; _i < 9; _i++) {
  12112. state.probe[_i].set(0, 0, 0);
  12113. }
  12114. var directionalLength = 0;
  12115. var pointLength = 0;
  12116. var spotLength = 0;
  12117. var rectAreaLength = 0;
  12118. var hemiLength = 0;
  12119. var numDirectionalShadows = 0;
  12120. var numPointShadows = 0;
  12121. var numSpotShadows = 0;
  12122. lights.sort(shadowCastingLightsFirst);
  12123. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  12124. var light = lights[_i2];
  12125. var color = light.color;
  12126. var intensity = light.intensity;
  12127. var distance = light.distance;
  12128. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  12129. if (light.isAmbientLight) {
  12130. r += color.r * intensity;
  12131. g += color.g * intensity;
  12132. b += color.b * intensity;
  12133. } else if (light.isLightProbe) {
  12134. for (var j = 0; j < 9; j++) {
  12135. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  12136. }
  12137. } else if (light.isDirectionalLight) {
  12138. var uniforms = cache.get(light);
  12139. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  12140. if (light.castShadow) {
  12141. var shadow = light.shadow;
  12142. var shadowUniforms = shadowCache.get(light);
  12143. shadowUniforms.shadowBias = shadow.bias;
  12144. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12145. shadowUniforms.shadowRadius = shadow.radius;
  12146. shadowUniforms.shadowMapSize = shadow.mapSize;
  12147. state.directionalShadow[directionalLength] = shadowUniforms;
  12148. state.directionalShadowMap[directionalLength] = shadowMap;
  12149. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  12150. numDirectionalShadows++;
  12151. }
  12152. state.directional[directionalLength] = uniforms;
  12153. directionalLength++;
  12154. } else if (light.isSpotLight) {
  12155. var _uniforms = cache.get(light);
  12156. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  12157. _uniforms.color.copy(color).multiplyScalar(intensity);
  12158. _uniforms.distance = distance;
  12159. _uniforms.coneCos = Math.cos(light.angle);
  12160. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  12161. _uniforms.decay = light.decay;
  12162. if (light.castShadow) {
  12163. var _shadow = light.shadow;
  12164. var _shadowUniforms = shadowCache.get(light);
  12165. _shadowUniforms.shadowBias = _shadow.bias;
  12166. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  12167. _shadowUniforms.shadowRadius = _shadow.radius;
  12168. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  12169. state.spotShadow[spotLength] = _shadowUniforms;
  12170. state.spotShadowMap[spotLength] = shadowMap;
  12171. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  12172. numSpotShadows++;
  12173. }
  12174. state.spot[spotLength] = _uniforms;
  12175. spotLength++;
  12176. } else if (light.isRectAreaLight) {
  12177. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  12178. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12179. // (b) intensity is the brightness of the light
  12180. _uniforms2.color.copy(color).multiplyScalar(intensity);
  12181. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12182. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12183. state.rectArea[rectAreaLength] = _uniforms2;
  12184. rectAreaLength++;
  12185. } else if (light.isPointLight) {
  12186. var _uniforms3 = cache.get(light);
  12187. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  12188. _uniforms3.distance = light.distance;
  12189. _uniforms3.decay = light.decay;
  12190. if (light.castShadow) {
  12191. var _shadow2 = light.shadow;
  12192. var _shadowUniforms2 = shadowCache.get(light);
  12193. _shadowUniforms2.shadowBias = _shadow2.bias;
  12194. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  12195. _shadowUniforms2.shadowRadius = _shadow2.radius;
  12196. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  12197. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  12198. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  12199. state.pointShadow[pointLength] = _shadowUniforms2;
  12200. state.pointShadowMap[pointLength] = shadowMap;
  12201. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  12202. numPointShadows++;
  12203. }
  12204. state.point[pointLength] = _uniforms3;
  12205. pointLength++;
  12206. } else if (light.isHemisphereLight) {
  12207. var _uniforms4 = cache.get(light);
  12208. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  12209. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  12210. state.hemi[hemiLength] = _uniforms4;
  12211. hemiLength++;
  12212. }
  12213. }
  12214. if (rectAreaLength > 0) {
  12215. if (capabilities.isWebGL2) {
  12216. // WebGL 2
  12217. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12218. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12219. } else {
  12220. // WebGL 1
  12221. if (extensions.has('OES_texture_float_linear') === true) {
  12222. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12223. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12224. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  12225. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12226. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12227. } else {
  12228. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  12229. }
  12230. }
  12231. }
  12232. state.ambient[0] = r;
  12233. state.ambient[1] = g;
  12234. state.ambient[2] = b;
  12235. var hash = state.hash;
  12236. if (hash.directionalLength !== directionalLength || hash.pointLength !== pointLength || hash.spotLength !== spotLength || hash.rectAreaLength !== rectAreaLength || hash.hemiLength !== hemiLength || hash.numDirectionalShadows !== numDirectionalShadows || hash.numPointShadows !== numPointShadows || hash.numSpotShadows !== numSpotShadows) {
  12237. state.directional.length = directionalLength;
  12238. state.spot.length = spotLength;
  12239. state.rectArea.length = rectAreaLength;
  12240. state.point.length = pointLength;
  12241. state.hemi.length = hemiLength;
  12242. state.directionalShadow.length = numDirectionalShadows;
  12243. state.directionalShadowMap.length = numDirectionalShadows;
  12244. state.pointShadow.length = numPointShadows;
  12245. state.pointShadowMap.length = numPointShadows;
  12246. state.spotShadow.length = numSpotShadows;
  12247. state.spotShadowMap.length = numSpotShadows;
  12248. state.directionalShadowMatrix.length = numDirectionalShadows;
  12249. state.pointShadowMatrix.length = numPointShadows;
  12250. state.spotShadowMatrix.length = numSpotShadows;
  12251. hash.directionalLength = directionalLength;
  12252. hash.pointLength = pointLength;
  12253. hash.spotLength = spotLength;
  12254. hash.rectAreaLength = rectAreaLength;
  12255. hash.hemiLength = hemiLength;
  12256. hash.numDirectionalShadows = numDirectionalShadows;
  12257. hash.numPointShadows = numPointShadows;
  12258. hash.numSpotShadows = numSpotShadows;
  12259. state.version = nextVersion++;
  12260. }
  12261. }
  12262. function setupView(lights, camera) {
  12263. var directionalLength = 0;
  12264. var pointLength = 0;
  12265. var spotLength = 0;
  12266. var rectAreaLength = 0;
  12267. var hemiLength = 0;
  12268. var viewMatrix = camera.matrixWorldInverse;
  12269. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  12270. var light = lights[_i3];
  12271. if (light.isDirectionalLight) {
  12272. var uniforms = state.directional[directionalLength];
  12273. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  12274. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12275. uniforms.direction.sub(vector3);
  12276. uniforms.direction.transformDirection(viewMatrix);
  12277. directionalLength++;
  12278. } else if (light.isSpotLight) {
  12279. var _uniforms5 = state.spot[spotLength];
  12280. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  12281. _uniforms5.position.applyMatrix4(viewMatrix);
  12282. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  12283. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12284. _uniforms5.direction.sub(vector3);
  12285. _uniforms5.direction.transformDirection(viewMatrix);
  12286. spotLength++;
  12287. } else if (light.isRectAreaLight) {
  12288. var _uniforms6 = state.rectArea[rectAreaLength];
  12289. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  12290. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  12291. matrix42.identity();
  12292. matrix4.copy(light.matrixWorld);
  12293. matrix4.premultiply(viewMatrix);
  12294. matrix42.extractRotation(matrix4);
  12295. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12296. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12297. _uniforms6.halfWidth.applyMatrix4(matrix42);
  12298. _uniforms6.halfHeight.applyMatrix4(matrix42);
  12299. rectAreaLength++;
  12300. } else if (light.isPointLight) {
  12301. var _uniforms7 = state.point[pointLength];
  12302. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  12303. _uniforms7.position.applyMatrix4(viewMatrix);
  12304. pointLength++;
  12305. } else if (light.isHemisphereLight) {
  12306. var _uniforms8 = state.hemi[hemiLength];
  12307. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  12308. _uniforms8.direction.transformDirection(viewMatrix);
  12309. _uniforms8.direction.normalize();
  12310. hemiLength++;
  12311. }
  12312. }
  12313. }
  12314. return {
  12315. setup: setup,
  12316. setupView: setupView,
  12317. state: state
  12318. };
  12319. }
  12320. function WebGLRenderState(extensions, capabilities) {
  12321. var lights = new WebGLLights(extensions, capabilities);
  12322. var lightsArray = [];
  12323. var shadowsArray = [];
  12324. function init() {
  12325. lightsArray.length = 0;
  12326. shadowsArray.length = 0;
  12327. }
  12328. function pushLight(light) {
  12329. lightsArray.push(light);
  12330. }
  12331. function pushShadow(shadowLight) {
  12332. shadowsArray.push(shadowLight);
  12333. }
  12334. function setupLights() {
  12335. lights.setup(lightsArray);
  12336. }
  12337. function setupLightsView(camera) {
  12338. lights.setupView(lightsArray, camera);
  12339. }
  12340. var state = {
  12341. lightsArray: lightsArray,
  12342. shadowsArray: shadowsArray,
  12343. lights: lights
  12344. };
  12345. return {
  12346. init: init,
  12347. state: state,
  12348. setupLights: setupLights,
  12349. setupLightsView: setupLightsView,
  12350. pushLight: pushLight,
  12351. pushShadow: pushShadow
  12352. };
  12353. }
  12354. function WebGLRenderStates(extensions, capabilities) {
  12355. var renderStates = new WeakMap();
  12356. function get(scene, renderCallDepth) {
  12357. if (renderCallDepth === void 0) {
  12358. renderCallDepth = 0;
  12359. }
  12360. var renderState;
  12361. if (renderStates.has(scene) === false) {
  12362. renderState = new WebGLRenderState(extensions, capabilities);
  12363. renderStates.set(scene, [renderState]);
  12364. } else {
  12365. if (renderCallDepth >= renderStates.get(scene).length) {
  12366. renderState = new WebGLRenderState(extensions, capabilities);
  12367. renderStates.get(scene).push(renderState);
  12368. } else {
  12369. renderState = renderStates.get(scene)[renderCallDepth];
  12370. }
  12371. }
  12372. return renderState;
  12373. }
  12374. function dispose() {
  12375. renderStates = new WeakMap();
  12376. }
  12377. return {
  12378. get: get,
  12379. dispose: dispose
  12380. };
  12381. }
  12382. /**
  12383. * parameters = {
  12384. *
  12385. * opacity: <float>,
  12386. *
  12387. * map: new THREE.Texture( <Image> ),
  12388. *
  12389. * alphaMap: new THREE.Texture( <Image> ),
  12390. *
  12391. * displacementMap: new THREE.Texture( <Image> ),
  12392. * displacementScale: <float>,
  12393. * displacementBias: <float>,
  12394. *
  12395. * wireframe: <boolean>,
  12396. * wireframeLinewidth: <float>
  12397. * }
  12398. */
  12399. var MeshDepthMaterial = /*#__PURE__*/function (_Material) {
  12400. _inheritsLoose(MeshDepthMaterial, _Material);
  12401. function MeshDepthMaterial(parameters) {
  12402. var _this;
  12403. _this = _Material.call(this) || this;
  12404. _this.type = 'MeshDepthMaterial';
  12405. _this.depthPacking = BasicDepthPacking;
  12406. _this.skinning = false;
  12407. _this.morphTargets = false;
  12408. _this.map = null;
  12409. _this.alphaMap = null;
  12410. _this.displacementMap = null;
  12411. _this.displacementScale = 1;
  12412. _this.displacementBias = 0;
  12413. _this.wireframe = false;
  12414. _this.wireframeLinewidth = 1;
  12415. _this.fog = false;
  12416. _this.setValues(parameters);
  12417. return _this;
  12418. }
  12419. var _proto = MeshDepthMaterial.prototype;
  12420. _proto.copy = function copy(source) {
  12421. _Material.prototype.copy.call(this, source);
  12422. this.depthPacking = source.depthPacking;
  12423. this.skinning = source.skinning;
  12424. this.morphTargets = source.morphTargets;
  12425. this.map = source.map;
  12426. this.alphaMap = source.alphaMap;
  12427. this.displacementMap = source.displacementMap;
  12428. this.displacementScale = source.displacementScale;
  12429. this.displacementBias = source.displacementBias;
  12430. this.wireframe = source.wireframe;
  12431. this.wireframeLinewidth = source.wireframeLinewidth;
  12432. return this;
  12433. };
  12434. return MeshDepthMaterial;
  12435. }(Material);
  12436. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12437. /**
  12438. * parameters = {
  12439. *
  12440. * referencePosition: <float>,
  12441. * nearDistance: <float>,
  12442. * farDistance: <float>,
  12443. *
  12444. * skinning: <bool>,
  12445. * morphTargets: <bool>,
  12446. *
  12447. * map: new THREE.Texture( <Image> ),
  12448. *
  12449. * alphaMap: new THREE.Texture( <Image> ),
  12450. *
  12451. * displacementMap: new THREE.Texture( <Image> ),
  12452. * displacementScale: <float>,
  12453. * displacementBias: <float>
  12454. *
  12455. * }
  12456. */
  12457. var MeshDistanceMaterial = /*#__PURE__*/function (_Material) {
  12458. _inheritsLoose(MeshDistanceMaterial, _Material);
  12459. function MeshDistanceMaterial(parameters) {
  12460. var _this;
  12461. _this = _Material.call(this) || this;
  12462. _this.type = 'MeshDistanceMaterial';
  12463. _this.referencePosition = new Vector3();
  12464. _this.nearDistance = 1;
  12465. _this.farDistance = 1000;
  12466. _this.skinning = false;
  12467. _this.morphTargets = false;
  12468. _this.map = null;
  12469. _this.alphaMap = null;
  12470. _this.displacementMap = null;
  12471. _this.displacementScale = 1;
  12472. _this.displacementBias = 0;
  12473. _this.fog = false;
  12474. _this.setValues(parameters);
  12475. return _this;
  12476. }
  12477. var _proto = MeshDistanceMaterial.prototype;
  12478. _proto.copy = function copy(source) {
  12479. _Material.prototype.copy.call(this, source);
  12480. this.referencePosition.copy(source.referencePosition);
  12481. this.nearDistance = source.nearDistance;
  12482. this.farDistance = source.farDistance;
  12483. this.skinning = source.skinning;
  12484. this.morphTargets = source.morphTargets;
  12485. this.map = source.map;
  12486. this.alphaMap = source.alphaMap;
  12487. this.displacementMap = source.displacementMap;
  12488. this.displacementScale = source.displacementScale;
  12489. this.displacementBias = source.displacementBias;
  12490. return this;
  12491. };
  12492. return MeshDistanceMaterial;
  12493. }(Material);
  12494. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12495. var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfor ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean * HALF_SAMPLE_RATE;\n\tsquared_mean = squared_mean * HALF_SAMPLE_RATE;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
  12496. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12497. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  12498. var _frustum = new Frustum();
  12499. var _shadowMapSize = new Vector2(),
  12500. _viewportSize = new Vector2(),
  12501. _viewport = new Vector4(),
  12502. _depthMaterials = [],
  12503. _distanceMaterials = [],
  12504. _materialCache = {};
  12505. var shadowSide = {
  12506. 0: BackSide,
  12507. 1: FrontSide,
  12508. 2: DoubleSide
  12509. };
  12510. var shadowMaterialVertical = new ShaderMaterial({
  12511. defines: {
  12512. SAMPLE_RATE: 2.0 / 8.0,
  12513. HALF_SAMPLE_RATE: 1.0 / 8.0
  12514. },
  12515. uniforms: {
  12516. shadow_pass: {
  12517. value: null
  12518. },
  12519. resolution: {
  12520. value: new Vector2()
  12521. },
  12522. radius: {
  12523. value: 4.0
  12524. }
  12525. },
  12526. vertexShader: vsm_vert,
  12527. fragmentShader: vsm_frag
  12528. });
  12529. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12530. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12531. var fullScreenTri = new BufferGeometry();
  12532. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12533. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12534. var scope = this;
  12535. this.enabled = false;
  12536. this.autoUpdate = true;
  12537. this.needsUpdate = false;
  12538. this.type = PCFShadowMap;
  12539. this.render = function (lights, scene, camera) {
  12540. if (scope.enabled === false) return;
  12541. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12542. if (lights.length === 0) return;
  12543. var currentRenderTarget = _renderer.getRenderTarget();
  12544. var activeCubeFace = _renderer.getActiveCubeFace();
  12545. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12546. var _state = _renderer.state; // Set GL state for depth map.
  12547. _state.setBlending(NoBlending);
  12548. _state.buffers.color.setClear(1, 1, 1, 1);
  12549. _state.buffers.depth.setTest(true);
  12550. _state.setScissorTest(false); // render depth map
  12551. for (var i = 0, il = lights.length; i < il; i++) {
  12552. var light = lights[i];
  12553. var shadow = light.shadow;
  12554. if (shadow === undefined) {
  12555. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12556. continue;
  12557. }
  12558. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12559. _shadowMapSize.copy(shadow.mapSize);
  12560. var shadowFrameExtents = shadow.getFrameExtents();
  12561. _shadowMapSize.multiply(shadowFrameExtents);
  12562. _viewportSize.copy(shadow.mapSize);
  12563. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12564. if (_shadowMapSize.x > maxTextureSize) {
  12565. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12566. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12567. shadow.mapSize.x = _viewportSize.x;
  12568. }
  12569. if (_shadowMapSize.y > maxTextureSize) {
  12570. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12571. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12572. shadow.mapSize.y = _viewportSize.y;
  12573. }
  12574. }
  12575. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12576. var pars = {
  12577. minFilter: LinearFilter,
  12578. magFilter: LinearFilter,
  12579. format: RGBAFormat
  12580. };
  12581. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12582. shadow.map.texture.name = light.name + '.shadowMap';
  12583. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12584. shadow.camera.updateProjectionMatrix();
  12585. }
  12586. if (shadow.map === null) {
  12587. var _pars = {
  12588. minFilter: NearestFilter,
  12589. magFilter: NearestFilter,
  12590. format: RGBAFormat
  12591. };
  12592. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12593. shadow.map.texture.name = light.name + '.shadowMap';
  12594. shadow.camera.updateProjectionMatrix();
  12595. }
  12596. _renderer.setRenderTarget(shadow.map);
  12597. _renderer.clear();
  12598. var viewportCount = shadow.getViewportCount();
  12599. for (var vp = 0; vp < viewportCount; vp++) {
  12600. var viewport = shadow.getViewport(vp);
  12601. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12602. _state.viewport(_viewport);
  12603. shadow.updateMatrices(light, vp);
  12604. _frustum = shadow.getFrustum();
  12605. renderObject(scene, camera, shadow.camera, light, this.type);
  12606. } // do blur pass for VSM
  12607. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12608. VSMPass(shadow, camera);
  12609. }
  12610. shadow.needsUpdate = false;
  12611. }
  12612. scope.needsUpdate = false;
  12613. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12614. };
  12615. function VSMPass(shadow, camera) {
  12616. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12617. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12618. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12619. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12620. _renderer.setRenderTarget(shadow.mapPass);
  12621. _renderer.clear();
  12622. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12623. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12624. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12625. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12626. _renderer.setRenderTarget(shadow.map);
  12627. _renderer.clear();
  12628. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12629. }
  12630. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12631. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12632. var material = _depthMaterials[index];
  12633. if (material === undefined) {
  12634. material = new MeshDepthMaterial({
  12635. depthPacking: RGBADepthPacking,
  12636. morphTargets: useMorphing,
  12637. skinning: useSkinning
  12638. });
  12639. _depthMaterials[index] = material;
  12640. }
  12641. return material;
  12642. }
  12643. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12644. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12645. var material = _distanceMaterials[index];
  12646. if (material === undefined) {
  12647. material = new MeshDistanceMaterial({
  12648. morphTargets: useMorphing,
  12649. skinning: useSkinning
  12650. });
  12651. _distanceMaterials[index] = material;
  12652. }
  12653. return material;
  12654. }
  12655. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12656. var result = null;
  12657. var getMaterialVariant = getDepthMaterialVariant;
  12658. var customMaterial = object.customDepthMaterial;
  12659. if (light.isPointLight === true) {
  12660. getMaterialVariant = getDistanceMaterialVariant;
  12661. customMaterial = object.customDistanceMaterial;
  12662. }
  12663. if (customMaterial === undefined) {
  12664. var useMorphing = false;
  12665. if (material.morphTargets === true) {
  12666. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12667. }
  12668. var useSkinning = false;
  12669. if (object.isSkinnedMesh === true) {
  12670. if (material.skinning === true) {
  12671. useSkinning = true;
  12672. } else {
  12673. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12674. }
  12675. }
  12676. var useInstancing = object.isInstancedMesh === true;
  12677. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12678. } else {
  12679. result = customMaterial;
  12680. }
  12681. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12682. // in this case we need a unique material instance reflecting the
  12683. // appropriate state
  12684. var keyA = result.uuid,
  12685. keyB = material.uuid;
  12686. var materialsForVariant = _materialCache[keyA];
  12687. if (materialsForVariant === undefined) {
  12688. materialsForVariant = {};
  12689. _materialCache[keyA] = materialsForVariant;
  12690. }
  12691. var cachedMaterial = materialsForVariant[keyB];
  12692. if (cachedMaterial === undefined) {
  12693. cachedMaterial = result.clone();
  12694. materialsForVariant[keyB] = cachedMaterial;
  12695. }
  12696. result = cachedMaterial;
  12697. }
  12698. result.visible = material.visible;
  12699. result.wireframe = material.wireframe;
  12700. if (type === VSMShadowMap) {
  12701. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12702. } else {
  12703. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12704. }
  12705. result.clipShadows = material.clipShadows;
  12706. result.clippingPlanes = material.clippingPlanes;
  12707. result.clipIntersection = material.clipIntersection;
  12708. result.wireframeLinewidth = material.wireframeLinewidth;
  12709. result.linewidth = material.linewidth;
  12710. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12711. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12712. result.nearDistance = shadowCameraNear;
  12713. result.farDistance = shadowCameraFar;
  12714. }
  12715. return result;
  12716. }
  12717. function renderObject(object, camera, shadowCamera, light, type) {
  12718. if (object.visible === false) return;
  12719. var visible = object.layers.test(camera.layers);
  12720. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12721. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12722. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12723. var geometry = _objects.update(object);
  12724. var material = object.material;
  12725. if (Array.isArray(material)) {
  12726. var groups = geometry.groups;
  12727. for (var k = 0, kl = groups.length; k < kl; k++) {
  12728. var group = groups[k];
  12729. var groupMaterial = material[group.materialIndex];
  12730. if (groupMaterial && groupMaterial.visible) {
  12731. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12732. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12733. }
  12734. }
  12735. } else if (material.visible) {
  12736. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12737. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12738. }
  12739. }
  12740. }
  12741. var children = object.children;
  12742. for (var i = 0, l = children.length; i < l; i++) {
  12743. renderObject(children[i], camera, shadowCamera, light, type);
  12744. }
  12745. }
  12746. }
  12747. function WebGLState(gl, extensions, capabilities) {
  12748. var _equationToGL, _factorToGL;
  12749. var isWebGL2 = capabilities.isWebGL2;
  12750. function ColorBuffer() {
  12751. var locked = false;
  12752. var color = new Vector4();
  12753. var currentColorMask = null;
  12754. var currentColorClear = new Vector4(0, 0, 0, 0);
  12755. return {
  12756. setMask: function setMask(colorMask) {
  12757. if (currentColorMask !== colorMask && !locked) {
  12758. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12759. currentColorMask = colorMask;
  12760. }
  12761. },
  12762. setLocked: function setLocked(lock) {
  12763. locked = lock;
  12764. },
  12765. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12766. if (premultipliedAlpha === true) {
  12767. r *= a;
  12768. g *= a;
  12769. b *= a;
  12770. }
  12771. color.set(r, g, b, a);
  12772. if (currentColorClear.equals(color) === false) {
  12773. gl.clearColor(r, g, b, a);
  12774. currentColorClear.copy(color);
  12775. }
  12776. },
  12777. reset: function reset() {
  12778. locked = false;
  12779. currentColorMask = null;
  12780. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12781. }
  12782. };
  12783. }
  12784. function DepthBuffer() {
  12785. var locked = false;
  12786. var currentDepthMask = null;
  12787. var currentDepthFunc = null;
  12788. var currentDepthClear = null;
  12789. return {
  12790. setTest: function setTest(depthTest) {
  12791. if (depthTest) {
  12792. enable(2929);
  12793. } else {
  12794. disable(2929);
  12795. }
  12796. },
  12797. setMask: function setMask(depthMask) {
  12798. if (currentDepthMask !== depthMask && !locked) {
  12799. gl.depthMask(depthMask);
  12800. currentDepthMask = depthMask;
  12801. }
  12802. },
  12803. setFunc: function setFunc(depthFunc) {
  12804. if (currentDepthFunc !== depthFunc) {
  12805. if (depthFunc) {
  12806. switch (depthFunc) {
  12807. case NeverDepth:
  12808. gl.depthFunc(512);
  12809. break;
  12810. case AlwaysDepth:
  12811. gl.depthFunc(519);
  12812. break;
  12813. case LessDepth:
  12814. gl.depthFunc(513);
  12815. break;
  12816. case LessEqualDepth:
  12817. gl.depthFunc(515);
  12818. break;
  12819. case EqualDepth:
  12820. gl.depthFunc(514);
  12821. break;
  12822. case GreaterEqualDepth:
  12823. gl.depthFunc(518);
  12824. break;
  12825. case GreaterDepth:
  12826. gl.depthFunc(516);
  12827. break;
  12828. case NotEqualDepth:
  12829. gl.depthFunc(517);
  12830. break;
  12831. default:
  12832. gl.depthFunc(515);
  12833. }
  12834. } else {
  12835. gl.depthFunc(515);
  12836. }
  12837. currentDepthFunc = depthFunc;
  12838. }
  12839. },
  12840. setLocked: function setLocked(lock) {
  12841. locked = lock;
  12842. },
  12843. setClear: function setClear(depth) {
  12844. if (currentDepthClear !== depth) {
  12845. gl.clearDepth(depth);
  12846. currentDepthClear = depth;
  12847. }
  12848. },
  12849. reset: function reset() {
  12850. locked = false;
  12851. currentDepthMask = null;
  12852. currentDepthFunc = null;
  12853. currentDepthClear = null;
  12854. }
  12855. };
  12856. }
  12857. function StencilBuffer() {
  12858. var locked = false;
  12859. var currentStencilMask = null;
  12860. var currentStencilFunc = null;
  12861. var currentStencilRef = null;
  12862. var currentStencilFuncMask = null;
  12863. var currentStencilFail = null;
  12864. var currentStencilZFail = null;
  12865. var currentStencilZPass = null;
  12866. var currentStencilClear = null;
  12867. return {
  12868. setTest: function setTest(stencilTest) {
  12869. if (!locked) {
  12870. if (stencilTest) {
  12871. enable(2960);
  12872. } else {
  12873. disable(2960);
  12874. }
  12875. }
  12876. },
  12877. setMask: function setMask(stencilMask) {
  12878. if (currentStencilMask !== stencilMask && !locked) {
  12879. gl.stencilMask(stencilMask);
  12880. currentStencilMask = stencilMask;
  12881. }
  12882. },
  12883. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12884. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12885. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12886. currentStencilFunc = stencilFunc;
  12887. currentStencilRef = stencilRef;
  12888. currentStencilFuncMask = stencilMask;
  12889. }
  12890. },
  12891. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12892. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12893. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12894. currentStencilFail = stencilFail;
  12895. currentStencilZFail = stencilZFail;
  12896. currentStencilZPass = stencilZPass;
  12897. }
  12898. },
  12899. setLocked: function setLocked(lock) {
  12900. locked = lock;
  12901. },
  12902. setClear: function setClear(stencil) {
  12903. if (currentStencilClear !== stencil) {
  12904. gl.clearStencil(stencil);
  12905. currentStencilClear = stencil;
  12906. }
  12907. },
  12908. reset: function reset() {
  12909. locked = false;
  12910. currentStencilMask = null;
  12911. currentStencilFunc = null;
  12912. currentStencilRef = null;
  12913. currentStencilFuncMask = null;
  12914. currentStencilFail = null;
  12915. currentStencilZFail = null;
  12916. currentStencilZPass = null;
  12917. currentStencilClear = null;
  12918. }
  12919. };
  12920. } //
  12921. var colorBuffer = new ColorBuffer();
  12922. var depthBuffer = new DepthBuffer();
  12923. var stencilBuffer = new StencilBuffer();
  12924. var enabledCapabilities = {};
  12925. var currentProgram = null;
  12926. var currentBlendingEnabled = false;
  12927. var currentBlending = null;
  12928. var currentBlendEquation = null;
  12929. var currentBlendSrc = null;
  12930. var currentBlendDst = null;
  12931. var currentBlendEquationAlpha = null;
  12932. var currentBlendSrcAlpha = null;
  12933. var currentBlendDstAlpha = null;
  12934. var currentPremultipledAlpha = false;
  12935. var currentFlipSided = null;
  12936. var currentCullFace = null;
  12937. var currentLineWidth = null;
  12938. var currentPolygonOffsetFactor = null;
  12939. var currentPolygonOffsetUnits = null;
  12940. var maxTextures = gl.getParameter(35661);
  12941. var lineWidthAvailable = false;
  12942. var version = 0;
  12943. var glVersion = gl.getParameter(7938);
  12944. if (glVersion.indexOf('WebGL') !== -1) {
  12945. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12946. lineWidthAvailable = version >= 1.0;
  12947. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12948. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12949. lineWidthAvailable = version >= 2.0;
  12950. }
  12951. var currentTextureSlot = null;
  12952. var currentBoundTextures = {};
  12953. var currentScissor = new Vector4();
  12954. var currentViewport = new Vector4();
  12955. function createTexture(type, target, count) {
  12956. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12957. var texture = gl.createTexture();
  12958. gl.bindTexture(type, texture);
  12959. gl.texParameteri(type, 10241, 9728);
  12960. gl.texParameteri(type, 10240, 9728);
  12961. for (var i = 0; i < count; i++) {
  12962. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12963. }
  12964. return texture;
  12965. }
  12966. var emptyTextures = {};
  12967. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12968. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12969. colorBuffer.setClear(0, 0, 0, 1);
  12970. depthBuffer.setClear(1);
  12971. stencilBuffer.setClear(0);
  12972. enable(2929);
  12973. depthBuffer.setFunc(LessEqualDepth);
  12974. setFlipSided(false);
  12975. setCullFace(CullFaceBack);
  12976. enable(2884);
  12977. setBlending(NoBlending); //
  12978. function enable(id) {
  12979. if (enabledCapabilities[id] !== true) {
  12980. gl.enable(id);
  12981. enabledCapabilities[id] = true;
  12982. }
  12983. }
  12984. function disable(id) {
  12985. if (enabledCapabilities[id] !== false) {
  12986. gl.disable(id);
  12987. enabledCapabilities[id] = false;
  12988. }
  12989. }
  12990. function useProgram(program) {
  12991. if (currentProgram !== program) {
  12992. gl.useProgram(program);
  12993. currentProgram = program;
  12994. return true;
  12995. }
  12996. return false;
  12997. }
  12998. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12999. if (isWebGL2) {
  13000. equationToGL[MinEquation] = 32775;
  13001. equationToGL[MaxEquation] = 32776;
  13002. } else {
  13003. var extension = extensions.get('EXT_blend_minmax');
  13004. if (extension !== null) {
  13005. equationToGL[MinEquation] = extension.MIN_EXT;
  13006. equationToGL[MaxEquation] = extension.MAX_EXT;
  13007. }
  13008. }
  13009. var factorToGL = (_factorToGL = {}, _factorToGL[ZeroFactor] = 0, _factorToGL[OneFactor] = 1, _factorToGL[SrcColorFactor] = 768, _factorToGL[SrcAlphaFactor] = 770, _factorToGL[SrcAlphaSaturateFactor] = 776, _factorToGL[DstColorFactor] = 774, _factorToGL[DstAlphaFactor] = 772, _factorToGL[OneMinusSrcColorFactor] = 769, _factorToGL[OneMinusSrcAlphaFactor] = 771, _factorToGL[OneMinusDstColorFactor] = 775, _factorToGL[OneMinusDstAlphaFactor] = 773, _factorToGL);
  13010. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  13011. if (blending === NoBlending) {
  13012. if (currentBlendingEnabled === true) {
  13013. disable(3042);
  13014. currentBlendingEnabled = false;
  13015. }
  13016. return;
  13017. }
  13018. if (currentBlendingEnabled === false) {
  13019. enable(3042);
  13020. currentBlendingEnabled = true;
  13021. }
  13022. if (blending !== CustomBlending) {
  13023. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  13024. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  13025. gl.blendEquation(32774);
  13026. currentBlendEquation = AddEquation;
  13027. currentBlendEquationAlpha = AddEquation;
  13028. }
  13029. if (premultipliedAlpha) {
  13030. switch (blending) {
  13031. case NormalBlending:
  13032. gl.blendFuncSeparate(1, 771, 1, 771);
  13033. break;
  13034. case AdditiveBlending:
  13035. gl.blendFunc(1, 1);
  13036. break;
  13037. case SubtractiveBlending:
  13038. gl.blendFuncSeparate(0, 0, 769, 771);
  13039. break;
  13040. case MultiplyBlending:
  13041. gl.blendFuncSeparate(0, 768, 0, 770);
  13042. break;
  13043. default:
  13044. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13045. break;
  13046. }
  13047. } else {
  13048. switch (blending) {
  13049. case NormalBlending:
  13050. gl.blendFuncSeparate(770, 771, 1, 771);
  13051. break;
  13052. case AdditiveBlending:
  13053. gl.blendFunc(770, 1);
  13054. break;
  13055. case SubtractiveBlending:
  13056. gl.blendFunc(0, 769);
  13057. break;
  13058. case MultiplyBlending:
  13059. gl.blendFunc(0, 768);
  13060. break;
  13061. default:
  13062. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13063. break;
  13064. }
  13065. }
  13066. currentBlendSrc = null;
  13067. currentBlendDst = null;
  13068. currentBlendSrcAlpha = null;
  13069. currentBlendDstAlpha = null;
  13070. currentBlending = blending;
  13071. currentPremultipledAlpha = premultipliedAlpha;
  13072. }
  13073. return;
  13074. } // custom blending
  13075. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13076. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13077. blendDstAlpha = blendDstAlpha || blendDst;
  13078. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  13079. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  13080. currentBlendEquation = blendEquation;
  13081. currentBlendEquationAlpha = blendEquationAlpha;
  13082. }
  13083. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  13084. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  13085. currentBlendSrc = blendSrc;
  13086. currentBlendDst = blendDst;
  13087. currentBlendSrcAlpha = blendSrcAlpha;
  13088. currentBlendDstAlpha = blendDstAlpha;
  13089. }
  13090. currentBlending = blending;
  13091. currentPremultipledAlpha = null;
  13092. }
  13093. function setMaterial(material, frontFaceCW) {
  13094. material.side === DoubleSide ? disable(2884) : enable(2884);
  13095. var flipSided = material.side === BackSide;
  13096. if (frontFaceCW) flipSided = !flipSided;
  13097. setFlipSided(flipSided);
  13098. material.blending === NormalBlending && material.transparent === false ? setBlending(NoBlending) : setBlending(material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha);
  13099. depthBuffer.setFunc(material.depthFunc);
  13100. depthBuffer.setTest(material.depthTest);
  13101. depthBuffer.setMask(material.depthWrite);
  13102. colorBuffer.setMask(material.colorWrite);
  13103. var stencilWrite = material.stencilWrite;
  13104. stencilBuffer.setTest(stencilWrite);
  13105. if (stencilWrite) {
  13106. stencilBuffer.setMask(material.stencilWriteMask);
  13107. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  13108. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  13109. }
  13110. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  13111. } //
  13112. function setFlipSided(flipSided) {
  13113. if (currentFlipSided !== flipSided) {
  13114. if (flipSided) {
  13115. gl.frontFace(2304);
  13116. } else {
  13117. gl.frontFace(2305);
  13118. }
  13119. currentFlipSided = flipSided;
  13120. }
  13121. }
  13122. function setCullFace(cullFace) {
  13123. if (cullFace !== CullFaceNone) {
  13124. enable(2884);
  13125. if (cullFace !== currentCullFace) {
  13126. if (cullFace === CullFaceBack) {
  13127. gl.cullFace(1029);
  13128. } else if (cullFace === CullFaceFront) {
  13129. gl.cullFace(1028);
  13130. } else {
  13131. gl.cullFace(1032);
  13132. }
  13133. }
  13134. } else {
  13135. disable(2884);
  13136. }
  13137. currentCullFace = cullFace;
  13138. }
  13139. function setLineWidth(width) {
  13140. if (width !== currentLineWidth) {
  13141. if (lineWidthAvailable) gl.lineWidth(width);
  13142. currentLineWidth = width;
  13143. }
  13144. }
  13145. function setPolygonOffset(polygonOffset, factor, units) {
  13146. if (polygonOffset) {
  13147. enable(32823);
  13148. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  13149. gl.polygonOffset(factor, units);
  13150. currentPolygonOffsetFactor = factor;
  13151. currentPolygonOffsetUnits = units;
  13152. }
  13153. } else {
  13154. disable(32823);
  13155. }
  13156. }
  13157. function setScissorTest(scissorTest) {
  13158. if (scissorTest) {
  13159. enable(3089);
  13160. } else {
  13161. disable(3089);
  13162. }
  13163. } // texture
  13164. function activeTexture(webglSlot) {
  13165. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  13166. if (currentTextureSlot !== webglSlot) {
  13167. gl.activeTexture(webglSlot);
  13168. currentTextureSlot = webglSlot;
  13169. }
  13170. }
  13171. function bindTexture(webglType, webglTexture) {
  13172. if (currentTextureSlot === null) {
  13173. activeTexture();
  13174. }
  13175. var boundTexture = currentBoundTextures[currentTextureSlot];
  13176. if (boundTexture === undefined) {
  13177. boundTexture = {
  13178. type: undefined,
  13179. texture: undefined
  13180. };
  13181. currentBoundTextures[currentTextureSlot] = boundTexture;
  13182. }
  13183. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  13184. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  13185. boundTexture.type = webglType;
  13186. boundTexture.texture = webglTexture;
  13187. }
  13188. }
  13189. function unbindTexture() {
  13190. var boundTexture = currentBoundTextures[currentTextureSlot];
  13191. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  13192. gl.bindTexture(boundTexture.type, null);
  13193. boundTexture.type = undefined;
  13194. boundTexture.texture = undefined;
  13195. }
  13196. }
  13197. function compressedTexImage2D() {
  13198. try {
  13199. gl.compressedTexImage2D.apply(gl, arguments);
  13200. } catch (error) {
  13201. console.error('THREE.WebGLState:', error);
  13202. }
  13203. }
  13204. function texImage2D() {
  13205. try {
  13206. gl.texImage2D.apply(gl, arguments);
  13207. } catch (error) {
  13208. console.error('THREE.WebGLState:', error);
  13209. }
  13210. }
  13211. function texImage3D() {
  13212. try {
  13213. gl.texImage3D.apply(gl, arguments);
  13214. } catch (error) {
  13215. console.error('THREE.WebGLState:', error);
  13216. }
  13217. } //
  13218. function scissor(scissor) {
  13219. if (currentScissor.equals(scissor) === false) {
  13220. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  13221. currentScissor.copy(scissor);
  13222. }
  13223. }
  13224. function viewport(viewport) {
  13225. if (currentViewport.equals(viewport) === false) {
  13226. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  13227. currentViewport.copy(viewport);
  13228. }
  13229. } //
  13230. function reset() {
  13231. // reset state
  13232. gl.disable(3042);
  13233. gl.disable(2884);
  13234. gl.disable(2929);
  13235. gl.disable(32823);
  13236. gl.disable(3089);
  13237. gl.disable(2960);
  13238. gl.blendEquation(32774);
  13239. gl.blendFunc(1, 0);
  13240. gl.blendFuncSeparate(1, 0, 1, 0);
  13241. gl.colorMask(true, true, true, true);
  13242. gl.clearColor(0, 0, 0, 0);
  13243. gl.depthMask(true);
  13244. gl.depthFunc(513);
  13245. gl.clearDepth(1);
  13246. gl.stencilMask(0xffffffff);
  13247. gl.stencilFunc(519, 0, 0xffffffff);
  13248. gl.stencilOp(7680, 7680, 7680);
  13249. gl.clearStencil(0);
  13250. gl.cullFace(1029);
  13251. gl.frontFace(2305);
  13252. gl.polygonOffset(0, 0);
  13253. gl.activeTexture(33984);
  13254. gl.useProgram(null);
  13255. gl.lineWidth(1);
  13256. gl.scissor(0, 0, gl.canvas.width, gl.canvas.height);
  13257. gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); // reset internals
  13258. enabledCapabilities = {};
  13259. currentTextureSlot = null;
  13260. currentBoundTextures = {};
  13261. currentProgram = null;
  13262. currentBlendingEnabled = false;
  13263. currentBlending = null;
  13264. currentBlendEquation = null;
  13265. currentBlendSrc = null;
  13266. currentBlendDst = null;
  13267. currentBlendEquationAlpha = null;
  13268. currentBlendSrcAlpha = null;
  13269. currentBlendDstAlpha = null;
  13270. currentPremultipledAlpha = false;
  13271. currentFlipSided = null;
  13272. currentCullFace = null;
  13273. currentLineWidth = null;
  13274. currentPolygonOffsetFactor = null;
  13275. currentPolygonOffsetUnits = null;
  13276. colorBuffer.reset();
  13277. depthBuffer.reset();
  13278. stencilBuffer.reset();
  13279. }
  13280. return {
  13281. buffers: {
  13282. color: colorBuffer,
  13283. depth: depthBuffer,
  13284. stencil: stencilBuffer
  13285. },
  13286. enable: enable,
  13287. disable: disable,
  13288. useProgram: useProgram,
  13289. setBlending: setBlending,
  13290. setMaterial: setMaterial,
  13291. setFlipSided: setFlipSided,
  13292. setCullFace: setCullFace,
  13293. setLineWidth: setLineWidth,
  13294. setPolygonOffset: setPolygonOffset,
  13295. setScissorTest: setScissorTest,
  13296. activeTexture: activeTexture,
  13297. bindTexture: bindTexture,
  13298. unbindTexture: unbindTexture,
  13299. compressedTexImage2D: compressedTexImage2D,
  13300. texImage2D: texImage2D,
  13301. texImage3D: texImage3D,
  13302. scissor: scissor,
  13303. viewport: viewport,
  13304. reset: reset
  13305. };
  13306. }
  13307. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  13308. var _wrappingToGL, _filterToGL;
  13309. var isWebGL2 = capabilities.isWebGL2;
  13310. var maxTextures = capabilities.maxTextures;
  13311. var maxCubemapSize = capabilities.maxCubemapSize;
  13312. var maxTextureSize = capabilities.maxTextureSize;
  13313. var maxSamples = capabilities.maxSamples;
  13314. var _videoTextures = new WeakMap();
  13315. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13316. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13317. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13318. var useOffscreenCanvas = false;
  13319. try {
  13320. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  13321. } catch (err) {// Ignore any errors
  13322. }
  13323. function createCanvas(width, height) {
  13324. // Use OffscreenCanvas when available. Specially needed in web workers
  13325. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  13326. }
  13327. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  13328. var scale = 1; // handle case if texture exceeds max size
  13329. if (image.width > maxSize || image.height > maxSize) {
  13330. scale = maxSize / Math.max(image.width, image.height);
  13331. } // only perform resize if necessary
  13332. if (scale < 1 || needsPowerOfTwo === true) {
  13333. // only perform resize for certain image types
  13334. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  13335. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13336. var width = floor(scale * image.width);
  13337. var height = floor(scale * image.height);
  13338. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  13339. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  13340. canvas.width = width;
  13341. canvas.height = height;
  13342. var context = canvas.getContext('2d');
  13343. context.drawImage(image, 0, 0, width, height);
  13344. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  13345. return canvas;
  13346. } else {
  13347. if ('data' in image) {
  13348. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  13349. }
  13350. return image;
  13351. }
  13352. }
  13353. return image;
  13354. }
  13355. function isPowerOfTwo(image) {
  13356. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  13357. }
  13358. function textureNeedsPowerOfTwo(texture) {
  13359. if (isWebGL2) return false;
  13360. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13361. }
  13362. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  13363. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13364. }
  13365. function generateMipmap(target, texture, width, height) {
  13366. _gl.generateMipmap(target);
  13367. var textureProperties = properties.get(texture);
  13368. textureProperties.__maxMipLevel = Math.log2(Math.max(width, height));
  13369. }
  13370. function getInternalFormat(internalFormatName, glFormat, glType) {
  13371. if (isWebGL2 === false) return glFormat;
  13372. if (internalFormatName !== null) {
  13373. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  13374. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  13375. }
  13376. var internalFormat = glFormat;
  13377. if (glFormat === 6403) {
  13378. if (glType === 5126) internalFormat = 33326;
  13379. if (glType === 5131) internalFormat = 33325;
  13380. if (glType === 5121) internalFormat = 33321;
  13381. }
  13382. if (glFormat === 6407) {
  13383. if (glType === 5126) internalFormat = 34837;
  13384. if (glType === 5131) internalFormat = 34843;
  13385. if (glType === 5121) internalFormat = 32849;
  13386. }
  13387. if (glFormat === 6408) {
  13388. if (glType === 5126) internalFormat = 34836;
  13389. if (glType === 5131) internalFormat = 34842;
  13390. if (glType === 5121) internalFormat = 32856;
  13391. }
  13392. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  13393. extensions.get('EXT_color_buffer_float');
  13394. }
  13395. return internalFormat;
  13396. } // Fallback filters for non-power-of-2 textures
  13397. function filterFallback(f) {
  13398. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  13399. return 9728;
  13400. }
  13401. return 9729;
  13402. } //
  13403. function onTextureDispose(event) {
  13404. var texture = event.target;
  13405. texture.removeEventListener('dispose', onTextureDispose);
  13406. deallocateTexture(texture);
  13407. if (texture.isVideoTexture) {
  13408. _videoTextures.delete(texture);
  13409. }
  13410. info.memory.textures--;
  13411. }
  13412. function onRenderTargetDispose(event) {
  13413. var renderTarget = event.target;
  13414. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  13415. deallocateRenderTarget(renderTarget);
  13416. info.memory.textures--;
  13417. } //
  13418. function deallocateTexture(texture) {
  13419. var textureProperties = properties.get(texture);
  13420. if (textureProperties.__webglInit === undefined) return;
  13421. _gl.deleteTexture(textureProperties.__webglTexture);
  13422. properties.remove(texture);
  13423. }
  13424. function deallocateRenderTarget(renderTarget) {
  13425. var texture = renderTarget.texture;
  13426. var renderTargetProperties = properties.get(renderTarget);
  13427. var textureProperties = properties.get(texture);
  13428. if (!renderTarget) return;
  13429. if (textureProperties.__webglTexture !== undefined) {
  13430. _gl.deleteTexture(textureProperties.__webglTexture);
  13431. }
  13432. if (renderTarget.depthTexture) {
  13433. renderTarget.depthTexture.dispose();
  13434. }
  13435. if (renderTarget.isWebGLCubeRenderTarget) {
  13436. for (var i = 0; i < 6; i++) {
  13437. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  13438. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  13439. }
  13440. } else {
  13441. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  13442. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  13443. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  13444. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  13445. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  13446. }
  13447. properties.remove(texture);
  13448. properties.remove(renderTarget);
  13449. } //
  13450. var textureUnits = 0;
  13451. function resetTextureUnits() {
  13452. textureUnits = 0;
  13453. }
  13454. function allocateTextureUnit() {
  13455. var textureUnit = textureUnits;
  13456. if (textureUnit >= maxTextures) {
  13457. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  13458. }
  13459. textureUnits += 1;
  13460. return textureUnit;
  13461. } //
  13462. function setTexture2D(texture, slot) {
  13463. var textureProperties = properties.get(texture);
  13464. if (texture.isVideoTexture) updateVideoTexture(texture);
  13465. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13466. var image = texture.image;
  13467. if (image === undefined) {
  13468. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  13469. } else if (image.complete === false) {
  13470. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  13471. } else {
  13472. uploadTexture(textureProperties, texture, slot);
  13473. return;
  13474. }
  13475. }
  13476. state.activeTexture(33984 + slot);
  13477. state.bindTexture(3553, textureProperties.__webglTexture);
  13478. }
  13479. function setTexture2DArray(texture, slot) {
  13480. var textureProperties = properties.get(texture);
  13481. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13482. uploadTexture(textureProperties, texture, slot);
  13483. return;
  13484. }
  13485. state.activeTexture(33984 + slot);
  13486. state.bindTexture(35866, textureProperties.__webglTexture);
  13487. }
  13488. function setTexture3D(texture, slot) {
  13489. var textureProperties = properties.get(texture);
  13490. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13491. uploadTexture(textureProperties, texture, slot);
  13492. return;
  13493. }
  13494. state.activeTexture(33984 + slot);
  13495. state.bindTexture(32879, textureProperties.__webglTexture);
  13496. }
  13497. function setTextureCube(texture, slot) {
  13498. var textureProperties = properties.get(texture);
  13499. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13500. uploadCubeTexture(textureProperties, texture, slot);
  13501. return;
  13502. }
  13503. state.activeTexture(33984 + slot);
  13504. state.bindTexture(34067, textureProperties.__webglTexture);
  13505. }
  13506. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  13507. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  13508. function setTextureParameters(textureType, texture, supportsMips) {
  13509. if (supportsMips) {
  13510. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  13511. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  13512. if (textureType === 32879 || textureType === 35866) {
  13513. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  13514. }
  13515. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  13516. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  13517. } else {
  13518. _gl.texParameteri(textureType, 10242, 33071);
  13519. _gl.texParameteri(textureType, 10243, 33071);
  13520. if (textureType === 32879 || textureType === 35866) {
  13521. _gl.texParameteri(textureType, 32882, 33071);
  13522. }
  13523. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  13524. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  13525. }
  13526. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  13527. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  13528. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  13529. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  13530. }
  13531. }
  13532. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  13533. var extension = extensions.get('EXT_texture_filter_anisotropic');
  13534. if (texture.type === FloatType && extensions.has('OES_texture_float_linear') === false) return; // verify extension for WebGL 1 and WebGL 2
  13535. if (isWebGL2 === false && texture.type === HalfFloatType && extensions.has('OES_texture_half_float_linear') === false) return; // verify extension for WebGL 1 only
  13536. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  13537. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  13538. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  13539. }
  13540. }
  13541. }
  13542. function initTexture(textureProperties, texture) {
  13543. if (textureProperties.__webglInit === undefined) {
  13544. textureProperties.__webglInit = true;
  13545. texture.addEventListener('dispose', onTextureDispose);
  13546. textureProperties.__webglTexture = _gl.createTexture();
  13547. info.memory.textures++;
  13548. }
  13549. }
  13550. function uploadTexture(textureProperties, texture, slot) {
  13551. var textureType = 3553;
  13552. if (texture.isDataTexture2DArray) textureType = 35866;
  13553. if (texture.isDataTexture3D) textureType = 32879;
  13554. initTexture(textureProperties, texture);
  13555. state.activeTexture(33984 + slot);
  13556. state.bindTexture(textureType, textureProperties.__webglTexture);
  13557. _gl.pixelStorei(37440, texture.flipY);
  13558. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13559. _gl.pixelStorei(3317, texture.unpackAlignment);
  13560. _gl.pixelStorei(37443, 0);
  13561. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13562. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13563. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13564. glFormat = utils.convert(texture.format);
  13565. var glType = utils.convert(texture.type),
  13566. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13567. setTextureParameters(textureType, texture, supportsMips);
  13568. var mipmap;
  13569. var mipmaps = texture.mipmaps;
  13570. if (texture.isDepthTexture) {
  13571. // populate depth texture with dummy data
  13572. glInternalFormat = 6402;
  13573. if (isWebGL2) {
  13574. if (texture.type === FloatType) {
  13575. glInternalFormat = 36012;
  13576. } else if (texture.type === UnsignedIntType) {
  13577. glInternalFormat = 33190;
  13578. } else if (texture.type === UnsignedInt248Type) {
  13579. glInternalFormat = 35056;
  13580. } else {
  13581. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13582. }
  13583. } else {
  13584. if (texture.type === FloatType) {
  13585. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13586. }
  13587. } // validation checks for WebGL 1
  13588. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13589. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13590. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13591. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13592. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13593. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13594. texture.type = UnsignedShortType;
  13595. glType = utils.convert(texture.type);
  13596. }
  13597. }
  13598. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13599. // Depth stencil textures need the DEPTH_STENCIL internal format
  13600. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13601. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13602. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13603. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13604. if (texture.type !== UnsignedInt248Type) {
  13605. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13606. texture.type = UnsignedInt248Type;
  13607. glType = utils.convert(texture.type);
  13608. }
  13609. } //
  13610. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13611. } else if (texture.isDataTexture) {
  13612. // use manually created mipmaps if available
  13613. // if there are no manual mipmaps
  13614. // set 0 level mipmap and then use GL to generate other mipmap levels
  13615. if (mipmaps.length > 0 && supportsMips) {
  13616. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13617. mipmap = mipmaps[i];
  13618. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13619. }
  13620. texture.generateMipmaps = false;
  13621. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13622. } else {
  13623. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13624. textureProperties.__maxMipLevel = 0;
  13625. }
  13626. } else if (texture.isCompressedTexture) {
  13627. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13628. mipmap = mipmaps[_i];
  13629. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13630. if (glFormat !== null) {
  13631. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13632. } else {
  13633. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13634. }
  13635. } else {
  13636. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13637. }
  13638. }
  13639. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13640. } else if (texture.isDataTexture2DArray) {
  13641. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13642. textureProperties.__maxMipLevel = 0;
  13643. } else if (texture.isDataTexture3D) {
  13644. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13645. textureProperties.__maxMipLevel = 0;
  13646. } else {
  13647. // regular Texture (image, video, canvas)
  13648. // use manually created mipmaps if available
  13649. // if there are no manual mipmaps
  13650. // set 0 level mipmap and then use GL to generate other mipmap levels
  13651. if (mipmaps.length > 0 && supportsMips) {
  13652. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13653. mipmap = mipmaps[_i2];
  13654. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13655. }
  13656. texture.generateMipmaps = false;
  13657. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13658. } else {
  13659. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13660. textureProperties.__maxMipLevel = 0;
  13661. }
  13662. }
  13663. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13664. generateMipmap(textureType, texture, image.width, image.height);
  13665. }
  13666. textureProperties.__version = texture.version;
  13667. if (texture.onUpdate) texture.onUpdate(texture);
  13668. }
  13669. function uploadCubeTexture(textureProperties, texture, slot) {
  13670. if (texture.image.length !== 6) return;
  13671. initTexture(textureProperties, texture);
  13672. state.activeTexture(33984 + slot);
  13673. state.bindTexture(34067, textureProperties.__webglTexture);
  13674. _gl.pixelStorei(37440, texture.flipY);
  13675. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13676. _gl.pixelStorei(3317, texture.unpackAlignment);
  13677. _gl.pixelStorei(37443, 0);
  13678. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13679. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13680. var cubeImage = [];
  13681. for (var i = 0; i < 6; i++) {
  13682. if (!isCompressed && !isDataTexture) {
  13683. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13684. } else {
  13685. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13686. }
  13687. }
  13688. var image = cubeImage[0],
  13689. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13690. glFormat = utils.convert(texture.format),
  13691. glType = utils.convert(texture.type),
  13692. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13693. setTextureParameters(34067, texture, supportsMips);
  13694. var mipmaps;
  13695. if (isCompressed) {
  13696. for (var _i3 = 0; _i3 < 6; _i3++) {
  13697. mipmaps = cubeImage[_i3].mipmaps;
  13698. for (var j = 0; j < mipmaps.length; j++) {
  13699. var mipmap = mipmaps[j];
  13700. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13701. if (glFormat !== null) {
  13702. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13703. } else {
  13704. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13705. }
  13706. } else {
  13707. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13708. }
  13709. }
  13710. }
  13711. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13712. } else {
  13713. mipmaps = texture.mipmaps;
  13714. for (var _i4 = 0; _i4 < 6; _i4++) {
  13715. if (isDataTexture) {
  13716. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13717. for (var _j = 0; _j < mipmaps.length; _j++) {
  13718. var _mipmap = mipmaps[_j];
  13719. var mipmapImage = _mipmap.image[_i4].image;
  13720. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13721. }
  13722. } else {
  13723. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13724. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13725. var _mipmap2 = mipmaps[_j2];
  13726. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13727. }
  13728. }
  13729. }
  13730. textureProperties.__maxMipLevel = mipmaps.length;
  13731. }
  13732. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13733. // We assume images for cube map have the same size.
  13734. generateMipmap(34067, texture, image.width, image.height);
  13735. }
  13736. textureProperties.__version = texture.version;
  13737. if (texture.onUpdate) texture.onUpdate(texture);
  13738. } // Render targets
  13739. // Setup storage for target texture and bind it to correct framebuffer
  13740. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13741. var texture = renderTarget.texture;
  13742. var glFormat = utils.convert(texture.format);
  13743. var glType = utils.convert(texture.type);
  13744. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13745. if (textureTarget === 32879 || textureTarget === 35866) {
  13746. state.texImage3D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null);
  13747. } else {
  13748. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13749. }
  13750. _gl.bindFramebuffer(36160, framebuffer);
  13751. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(texture).__webglTexture, 0);
  13752. _gl.bindFramebuffer(36160, null);
  13753. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13754. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13755. _gl.bindRenderbuffer(36161, renderbuffer);
  13756. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13757. var glInternalFormat = 33189;
  13758. if (isMultisample) {
  13759. var depthTexture = renderTarget.depthTexture;
  13760. if (depthTexture && depthTexture.isDepthTexture) {
  13761. if (depthTexture.type === FloatType) {
  13762. glInternalFormat = 36012;
  13763. } else if (depthTexture.type === UnsignedIntType) {
  13764. glInternalFormat = 33190;
  13765. }
  13766. }
  13767. var samples = getRenderTargetSamples(renderTarget);
  13768. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13769. } else {
  13770. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13771. }
  13772. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13773. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13774. if (isMultisample) {
  13775. var _samples = getRenderTargetSamples(renderTarget);
  13776. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13777. } else {
  13778. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13779. }
  13780. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13781. } else {
  13782. var texture = renderTarget.texture;
  13783. var glFormat = utils.convert(texture.format);
  13784. var glType = utils.convert(texture.type);
  13785. var _glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13786. if (isMultisample) {
  13787. var _samples2 = getRenderTargetSamples(renderTarget);
  13788. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13789. } else {
  13790. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13791. }
  13792. }
  13793. _gl.bindRenderbuffer(36161, null);
  13794. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13795. function setupDepthTexture(framebuffer, renderTarget) {
  13796. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13797. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13798. _gl.bindFramebuffer(36160, framebuffer);
  13799. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13800. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13801. } // upload an empty depth texture with framebuffer size
  13802. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13803. renderTarget.depthTexture.image.width = renderTarget.width;
  13804. renderTarget.depthTexture.image.height = renderTarget.height;
  13805. renderTarget.depthTexture.needsUpdate = true;
  13806. }
  13807. setTexture2D(renderTarget.depthTexture, 0);
  13808. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13809. if (renderTarget.depthTexture.format === DepthFormat) {
  13810. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13811. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13812. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13813. } else {
  13814. throw new Error('Unknown depthTexture format');
  13815. }
  13816. } // Setup GL resources for a non-texture depth buffer
  13817. function setupDepthRenderbuffer(renderTarget) {
  13818. var renderTargetProperties = properties.get(renderTarget);
  13819. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13820. if (renderTarget.depthTexture) {
  13821. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13822. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13823. } else {
  13824. if (isCube) {
  13825. renderTargetProperties.__webglDepthbuffer = [];
  13826. for (var i = 0; i < 6; i++) {
  13827. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13828. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13829. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13830. }
  13831. } else {
  13832. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13833. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13834. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13835. }
  13836. }
  13837. _gl.bindFramebuffer(36160, null);
  13838. } // Set up GL resources for the render target
  13839. function setupRenderTarget(renderTarget) {
  13840. var texture = renderTarget.texture;
  13841. var renderTargetProperties = properties.get(renderTarget);
  13842. var textureProperties = properties.get(texture);
  13843. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13844. textureProperties.__webglTexture = _gl.createTexture();
  13845. info.memory.textures++;
  13846. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13847. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13848. var isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
  13849. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13850. if (isWebGL2 && texture.format === RGBFormat && (texture.type === FloatType || texture.type === HalfFloatType)) {
  13851. texture.format = RGBAFormat;
  13852. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13853. } // Setup framebuffer
  13854. if (isCube) {
  13855. renderTargetProperties.__webglFramebuffer = [];
  13856. for (var i = 0; i < 6; i++) {
  13857. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13858. }
  13859. } else {
  13860. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13861. if (isMultisample) {
  13862. if (isWebGL2) {
  13863. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13864. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13865. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13866. var glFormat = utils.convert(texture.format);
  13867. var glType = utils.convert(texture.type);
  13868. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13869. var samples = getRenderTargetSamples(renderTarget);
  13870. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13871. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13872. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13873. _gl.bindRenderbuffer(36161, null);
  13874. if (renderTarget.depthBuffer) {
  13875. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13876. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13877. }
  13878. _gl.bindFramebuffer(36160, null);
  13879. } else {
  13880. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13881. }
  13882. }
  13883. } // Setup color buffer
  13884. if (isCube) {
  13885. state.bindTexture(34067, textureProperties.__webglTexture);
  13886. setTextureParameters(34067, texture, supportsMips);
  13887. for (var _i5 = 0; _i5 < 6; _i5++) {
  13888. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13889. }
  13890. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13891. generateMipmap(34067, texture, renderTarget.width, renderTarget.height);
  13892. }
  13893. state.bindTexture(34067, null);
  13894. } else {
  13895. var glTextureType = 3553;
  13896. if (isRenderTarget3D) {
  13897. // Render targets containing layers, i.e: Texture 3D and 2d arrays
  13898. if (isWebGL2) {
  13899. var isTexture3D = texture.isDataTexture3D;
  13900. glTextureType = isTexture3D ? 32879 : 35866;
  13901. } else {
  13902. console.warn('THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.');
  13903. }
  13904. }
  13905. state.bindTexture(glTextureType, textureProperties.__webglTexture);
  13906. setTextureParameters(glTextureType, texture, supportsMips);
  13907. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, glTextureType);
  13908. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13909. generateMipmap(3553, texture, renderTarget.width, renderTarget.height);
  13910. }
  13911. state.bindTexture(3553, null);
  13912. } // Setup depth and stencil buffers
  13913. if (renderTarget.depthBuffer) {
  13914. setupDepthRenderbuffer(renderTarget);
  13915. }
  13916. }
  13917. function updateRenderTargetMipmap(renderTarget) {
  13918. var texture = renderTarget.texture;
  13919. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13920. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13921. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13922. var webglTexture = properties.get(texture).__webglTexture;
  13923. state.bindTexture(target, webglTexture);
  13924. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13925. state.bindTexture(target, null);
  13926. }
  13927. }
  13928. function updateMultisampleRenderTarget(renderTarget) {
  13929. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13930. if (isWebGL2) {
  13931. var renderTargetProperties = properties.get(renderTarget);
  13932. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13933. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13934. var width = renderTarget.width;
  13935. var height = renderTarget.height;
  13936. var mask = 16384;
  13937. if (renderTarget.depthBuffer) mask |= 256;
  13938. if (renderTarget.stencilBuffer) mask |= 1024;
  13939. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13940. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13941. } else {
  13942. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13943. }
  13944. }
  13945. }
  13946. function getRenderTargetSamples(renderTarget) {
  13947. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13948. }
  13949. function updateVideoTexture(texture) {
  13950. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13951. if (_videoTextures.get(texture) !== frame) {
  13952. _videoTextures.set(texture, frame);
  13953. texture.update();
  13954. }
  13955. } // backwards compatibility
  13956. var warnedTexture2D = false;
  13957. var warnedTextureCube = false;
  13958. function safeSetTexture2D(texture, slot) {
  13959. if (texture && texture.isWebGLRenderTarget) {
  13960. if (warnedTexture2D === false) {
  13961. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13962. warnedTexture2D = true;
  13963. }
  13964. texture = texture.texture;
  13965. }
  13966. setTexture2D(texture, slot);
  13967. }
  13968. function safeSetTextureCube(texture, slot) {
  13969. if (texture && texture.isWebGLCubeRenderTarget) {
  13970. if (warnedTextureCube === false) {
  13971. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13972. warnedTextureCube = true;
  13973. }
  13974. texture = texture.texture;
  13975. }
  13976. setTextureCube(texture, slot);
  13977. } //
  13978. this.allocateTextureUnit = allocateTextureUnit;
  13979. this.resetTextureUnits = resetTextureUnits;
  13980. this.setTexture2D = setTexture2D;
  13981. this.setTexture2DArray = setTexture2DArray;
  13982. this.setTexture3D = setTexture3D;
  13983. this.setTextureCube = setTextureCube;
  13984. this.setupRenderTarget = setupRenderTarget;
  13985. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13986. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13987. this.safeSetTexture2D = safeSetTexture2D;
  13988. this.safeSetTextureCube = safeSetTextureCube;
  13989. }
  13990. function WebGLUtils(gl, extensions, capabilities) {
  13991. var isWebGL2 = capabilities.isWebGL2;
  13992. function convert(p) {
  13993. var extension;
  13994. if (p === UnsignedByteType) return 5121;
  13995. if (p === UnsignedShort4444Type) return 32819;
  13996. if (p === UnsignedShort5551Type) return 32820;
  13997. if (p === UnsignedShort565Type) return 33635;
  13998. if (p === ByteType) return 5120;
  13999. if (p === ShortType) return 5122;
  14000. if (p === UnsignedShortType) return 5123;
  14001. if (p === IntType) return 5124;
  14002. if (p === UnsignedIntType) return 5125;
  14003. if (p === FloatType) return 5126;
  14004. if (p === HalfFloatType) {
  14005. if (isWebGL2) return 5131;
  14006. extension = extensions.get('OES_texture_half_float');
  14007. if (extension !== null) {
  14008. return extension.HALF_FLOAT_OES;
  14009. } else {
  14010. return null;
  14011. }
  14012. }
  14013. if (p === AlphaFormat) return 6406;
  14014. if (p === RGBFormat) return 6407;
  14015. if (p === RGBAFormat) return 6408;
  14016. if (p === LuminanceFormat) return 6409;
  14017. if (p === LuminanceAlphaFormat) return 6410;
  14018. if (p === DepthFormat) return 6402;
  14019. if (p === DepthStencilFormat) return 34041;
  14020. if (p === RedFormat) return 6403; // WebGL2 formats.
  14021. if (p === RedIntegerFormat) return 36244;
  14022. if (p === RGFormat) return 33319;
  14023. if (p === RGIntegerFormat) return 33320;
  14024. if (p === RGBIntegerFormat) return 36248;
  14025. if (p === RGBAIntegerFormat) return 36249;
  14026. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  14027. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  14028. if (extension !== null) {
  14029. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  14030. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  14031. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  14032. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  14033. } else {
  14034. return null;
  14035. }
  14036. }
  14037. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  14038. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  14039. if (extension !== null) {
  14040. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  14041. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  14042. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  14043. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  14044. } else {
  14045. return null;
  14046. }
  14047. }
  14048. if (p === RGB_ETC1_Format) {
  14049. extension = extensions.get('WEBGL_compressed_texture_etc1');
  14050. if (extension !== null) {
  14051. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  14052. } else {
  14053. return null;
  14054. }
  14055. }
  14056. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  14057. extension = extensions.get('WEBGL_compressed_texture_etc');
  14058. if (extension !== null) {
  14059. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  14060. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  14061. }
  14062. }
  14063. if (p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format || p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format || p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format || p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format || p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format || p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format || p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format || p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format || p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format || p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format) {
  14064. extension = extensions.get('WEBGL_compressed_texture_astc');
  14065. if (extension !== null) {
  14066. // TODO Complete?
  14067. return p;
  14068. } else {
  14069. return null;
  14070. }
  14071. }
  14072. if (p === RGBA_BPTC_Format) {
  14073. extension = extensions.get('EXT_texture_compression_bptc');
  14074. if (extension !== null) {
  14075. // TODO Complete?
  14076. return p;
  14077. } else {
  14078. return null;
  14079. }
  14080. }
  14081. if (p === UnsignedInt248Type) {
  14082. if (isWebGL2) return 34042;
  14083. extension = extensions.get('WEBGL_depth_texture');
  14084. if (extension !== null) {
  14085. return extension.UNSIGNED_INT_24_8_WEBGL;
  14086. } else {
  14087. return null;
  14088. }
  14089. }
  14090. }
  14091. return {
  14092. convert: convert
  14093. };
  14094. }
  14095. function ArrayCamera(array) {
  14096. if (array === void 0) {
  14097. array = [];
  14098. }
  14099. PerspectiveCamera.call(this);
  14100. this.cameras = array;
  14101. }
  14102. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  14103. constructor: ArrayCamera,
  14104. isArrayCamera: true
  14105. });
  14106. var Group = /*#__PURE__*/function (_Object3D) {
  14107. _inheritsLoose(Group, _Object3D);
  14108. function Group() {
  14109. var _this;
  14110. _this = _Object3D.call(this) || this;
  14111. _this.type = 'Group';
  14112. return _this;
  14113. }
  14114. return Group;
  14115. }(Object3D);
  14116. Group.prototype.isGroup = true;
  14117. function WebXRController() {
  14118. this._targetRay = null;
  14119. this._grip = null;
  14120. this._hand = null;
  14121. }
  14122. Object.assign(WebXRController.prototype, {
  14123. constructor: WebXRController,
  14124. getHandSpace: function getHandSpace() {
  14125. if (this._hand === null) {
  14126. this._hand = new Group();
  14127. this._hand.matrixAutoUpdate = false;
  14128. this._hand.visible = false;
  14129. this._hand.joints = {};
  14130. this._hand.inputState = {
  14131. pinching: false
  14132. };
  14133. }
  14134. return this._hand;
  14135. },
  14136. getTargetRaySpace: function getTargetRaySpace() {
  14137. if (this._targetRay === null) {
  14138. this._targetRay = new Group();
  14139. this._targetRay.matrixAutoUpdate = false;
  14140. this._targetRay.visible = false;
  14141. }
  14142. return this._targetRay;
  14143. },
  14144. getGripSpace: function getGripSpace() {
  14145. if (this._grip === null) {
  14146. this._grip = new Group();
  14147. this._grip.matrixAutoUpdate = false;
  14148. this._grip.visible = false;
  14149. }
  14150. return this._grip;
  14151. },
  14152. dispatchEvent: function dispatchEvent(event) {
  14153. if (this._targetRay !== null) {
  14154. this._targetRay.dispatchEvent(event);
  14155. }
  14156. if (this._grip !== null) {
  14157. this._grip.dispatchEvent(event);
  14158. }
  14159. if (this._hand !== null) {
  14160. this._hand.dispatchEvent(event);
  14161. }
  14162. return this;
  14163. },
  14164. disconnect: function disconnect(inputSource) {
  14165. this.dispatchEvent({
  14166. type: 'disconnected',
  14167. data: inputSource
  14168. });
  14169. if (this._targetRay !== null) {
  14170. this._targetRay.visible = false;
  14171. }
  14172. if (this._grip !== null) {
  14173. this._grip.visible = false;
  14174. }
  14175. if (this._hand !== null) {
  14176. this._hand.visible = false;
  14177. }
  14178. return this;
  14179. },
  14180. update: function update(inputSource, frame, referenceSpace) {
  14181. var inputPose = null;
  14182. var gripPose = null;
  14183. var handPose = null;
  14184. var targetRay = this._targetRay;
  14185. var grip = this._grip;
  14186. var hand = this._hand;
  14187. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  14188. if (hand && inputSource.hand) {
  14189. handPose = true;
  14190. for (var _iterator = _createForOfIteratorHelperLoose(inputSource.hand.values()), _step; !(_step = _iterator()).done;) {
  14191. var inputjoint = _step.value;
  14192. // Update the joints groups with the XRJoint poses
  14193. var jointPose = frame.getJointPose(inputjoint, referenceSpace);
  14194. if (hand.joints[inputjoint.jointName] === undefined) {
  14195. // The transform of this joint will be updated with the joint pose on each frame
  14196. var _joint = new Group();
  14197. _joint.matrixAutoUpdate = false;
  14198. _joint.visible = false;
  14199. hand.joints[inputjoint.jointName] = _joint; // ??
  14200. hand.add(_joint);
  14201. }
  14202. var joint = hand.joints[inputjoint.jointName];
  14203. if (jointPose !== null) {
  14204. joint.matrix.fromArray(jointPose.transform.matrix);
  14205. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  14206. joint.jointRadius = jointPose.radius;
  14207. }
  14208. joint.visible = jointPose !== null;
  14209. } // Custom events
  14210. // Check pinchz
  14211. var indexTip = hand.joints['index-finger-tip'];
  14212. var thumbTip = hand.joints['thumb-tip'];
  14213. var distance = indexTip.position.distanceTo(thumbTip.position);
  14214. var distanceToPinch = 0.02;
  14215. var threshold = 0.005;
  14216. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  14217. hand.inputState.pinching = false;
  14218. this.dispatchEvent({
  14219. type: 'pinchend',
  14220. handedness: inputSource.handedness,
  14221. target: this
  14222. });
  14223. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  14224. hand.inputState.pinching = true;
  14225. this.dispatchEvent({
  14226. type: 'pinchstart',
  14227. handedness: inputSource.handedness,
  14228. target: this
  14229. });
  14230. }
  14231. } else {
  14232. if (targetRay !== null) {
  14233. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  14234. if (inputPose !== null) {
  14235. targetRay.matrix.fromArray(inputPose.transform.matrix);
  14236. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  14237. }
  14238. }
  14239. if (grip !== null && inputSource.gripSpace) {
  14240. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  14241. if (gripPose !== null) {
  14242. grip.matrix.fromArray(gripPose.transform.matrix);
  14243. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  14244. }
  14245. }
  14246. }
  14247. }
  14248. if (targetRay !== null) {
  14249. targetRay.visible = inputPose !== null;
  14250. }
  14251. if (grip !== null) {
  14252. grip.visible = gripPose !== null;
  14253. }
  14254. if (hand !== null) {
  14255. hand.visible = handPose !== null;
  14256. }
  14257. return this;
  14258. }
  14259. });
  14260. function WebXRManager(renderer, gl) {
  14261. var scope = this;
  14262. var session = null;
  14263. var framebufferScaleFactor = 1.0;
  14264. var referenceSpace = null;
  14265. var referenceSpaceType = 'local-floor';
  14266. var pose = null;
  14267. var controllers = [];
  14268. var inputSourcesMap = new Map(); //
  14269. var cameraL = new PerspectiveCamera();
  14270. cameraL.layers.enable(1);
  14271. cameraL.viewport = new Vector4();
  14272. var cameraR = new PerspectiveCamera();
  14273. cameraR.layers.enable(2);
  14274. cameraR.viewport = new Vector4();
  14275. var cameras = [cameraL, cameraR];
  14276. var cameraVR = new ArrayCamera();
  14277. cameraVR.layers.enable(1);
  14278. cameraVR.layers.enable(2);
  14279. var _currentDepthNear = null;
  14280. var _currentDepthFar = null; //
  14281. this.enabled = false;
  14282. this.isPresenting = false;
  14283. this.getController = function (index) {
  14284. var controller = controllers[index];
  14285. if (controller === undefined) {
  14286. controller = new WebXRController();
  14287. controllers[index] = controller;
  14288. }
  14289. return controller.getTargetRaySpace();
  14290. };
  14291. this.getControllerGrip = function (index) {
  14292. var controller = controllers[index];
  14293. if (controller === undefined) {
  14294. controller = new WebXRController();
  14295. controllers[index] = controller;
  14296. }
  14297. return controller.getGripSpace();
  14298. };
  14299. this.getHand = function (index) {
  14300. var controller = controllers[index];
  14301. if (controller === undefined) {
  14302. controller = new WebXRController();
  14303. controllers[index] = controller;
  14304. }
  14305. return controller.getHandSpace();
  14306. }; //
  14307. function onSessionEvent(event) {
  14308. var controller = inputSourcesMap.get(event.inputSource);
  14309. if (controller) {
  14310. controller.dispatchEvent({
  14311. type: event.type,
  14312. data: event.inputSource
  14313. });
  14314. }
  14315. }
  14316. function onSessionEnd() {
  14317. inputSourcesMap.forEach(function (controller, inputSource) {
  14318. controller.disconnect(inputSource);
  14319. });
  14320. inputSourcesMap.clear();
  14321. _currentDepthNear = null;
  14322. _currentDepthFar = null; //
  14323. renderer.setFramebuffer(null);
  14324. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  14325. animation.stop();
  14326. scope.isPresenting = false;
  14327. scope.dispatchEvent({
  14328. type: 'sessionend'
  14329. });
  14330. }
  14331. this.setFramebufferScaleFactor = function (value) {
  14332. framebufferScaleFactor = value;
  14333. if (scope.isPresenting === true) {
  14334. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  14335. }
  14336. };
  14337. this.setReferenceSpaceType = function (value) {
  14338. referenceSpaceType = value;
  14339. if (scope.isPresenting === true) {
  14340. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  14341. }
  14342. };
  14343. this.getReferenceSpace = function () {
  14344. return referenceSpace;
  14345. };
  14346. this.getSession = function () {
  14347. return session;
  14348. };
  14349. this.setSession = /*#__PURE__*/function () {
  14350. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
  14351. var attributes, layerInit, baseLayer;
  14352. return regeneratorRuntime.wrap(function _callee$(_context) {
  14353. while (1) {
  14354. switch (_context.prev = _context.next) {
  14355. case 0:
  14356. session = value;
  14357. if (!(session !== null)) {
  14358. _context.next = 24;
  14359. break;
  14360. }
  14361. session.addEventListener('select', onSessionEvent);
  14362. session.addEventListener('selectstart', onSessionEvent);
  14363. session.addEventListener('selectend', onSessionEvent);
  14364. session.addEventListener('squeeze', onSessionEvent);
  14365. session.addEventListener('squeezestart', onSessionEvent);
  14366. session.addEventListener('squeezeend', onSessionEvent);
  14367. session.addEventListener('end', onSessionEnd);
  14368. session.addEventListener('inputsourceschange', onInputSourcesChange);
  14369. attributes = gl.getContextAttributes();
  14370. if (!(attributes.xrCompatible !== true)) {
  14371. _context.next = 14;
  14372. break;
  14373. }
  14374. _context.next = 14;
  14375. return gl.makeXRCompatible();
  14376. case 14:
  14377. layerInit = {
  14378. antialias: attributes.antialias,
  14379. alpha: attributes.alpha,
  14380. depth: attributes.depth,
  14381. stencil: attributes.stencil,
  14382. framebufferScaleFactor: framebufferScaleFactor
  14383. }; // eslint-disable-next-line no-undef
  14384. baseLayer = new XRWebGLLayer(session, gl, layerInit);
  14385. session.updateRenderState({
  14386. baseLayer: baseLayer
  14387. });
  14388. _context.next = 19;
  14389. return session.requestReferenceSpace(referenceSpaceType);
  14390. case 19:
  14391. referenceSpace = _context.sent;
  14392. animation.setContext(session);
  14393. animation.start();
  14394. scope.isPresenting = true;
  14395. scope.dispatchEvent({
  14396. type: 'sessionstart'
  14397. });
  14398. case 24:
  14399. case "end":
  14400. return _context.stop();
  14401. }
  14402. }
  14403. }, _callee);
  14404. }));
  14405. return function (_x) {
  14406. return _ref.apply(this, arguments);
  14407. };
  14408. }();
  14409. function onInputSourcesChange(event) {
  14410. var inputSources = session.inputSources; // Assign inputSources to available controllers
  14411. for (var i = 0; i < controllers.length; i++) {
  14412. inputSourcesMap.set(inputSources[i], controllers[i]);
  14413. } // Notify disconnected
  14414. for (var _i = 0; _i < event.removed.length; _i++) {
  14415. var inputSource = event.removed[_i];
  14416. var controller = inputSourcesMap.get(inputSource);
  14417. if (controller) {
  14418. controller.dispatchEvent({
  14419. type: 'disconnected',
  14420. data: inputSource
  14421. });
  14422. inputSourcesMap.delete(inputSource);
  14423. }
  14424. } // Notify connected
  14425. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  14426. var _inputSource = event.added[_i2];
  14427. var _controller = inputSourcesMap.get(_inputSource);
  14428. if (_controller) {
  14429. _controller.dispatchEvent({
  14430. type: 'connected',
  14431. data: _inputSource
  14432. });
  14433. }
  14434. }
  14435. } //
  14436. var cameraLPos = new Vector3();
  14437. var cameraRPos = new Vector3();
  14438. /**
  14439. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14440. * the cameras' projection and world matrices have already been set.
  14441. * And that near and far planes are identical for both cameras.
  14442. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14443. */
  14444. function setProjectionFromUnion(camera, cameraL, cameraR) {
  14445. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  14446. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  14447. var ipd = cameraLPos.distanceTo(cameraRPos);
  14448. var projL = cameraL.projectionMatrix.elements;
  14449. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  14450. // most likely identical top and bottom frustum extents.
  14451. // Use the left camera for these values.
  14452. var near = projL[14] / (projL[10] - 1);
  14453. var far = projL[14] / (projL[10] + 1);
  14454. var topFov = (projL[9] + 1) / projL[5];
  14455. var bottomFov = (projL[9] - 1) / projL[5];
  14456. var leftFov = (projL[8] - 1) / projL[0];
  14457. var rightFov = (projR[8] + 1) / projR[0];
  14458. var left = near * leftFov;
  14459. var right = near * rightFov; // Calculate the new camera's position offset from the
  14460. // left camera. xOffset should be roughly half `ipd`.
  14461. var zOffset = ipd / (-leftFov + rightFov);
  14462. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  14463. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  14464. camera.translateX(xOffset);
  14465. camera.translateZ(zOffset);
  14466. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  14467. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  14468. // the values so that the near plane's position does not change in world space,
  14469. // although must now be relative to the new union camera.
  14470. var near2 = near + zOffset;
  14471. var far2 = far + zOffset;
  14472. var left2 = left - xOffset;
  14473. var right2 = right + (ipd - xOffset);
  14474. var top2 = topFov * far / far2 * near2;
  14475. var bottom2 = bottomFov * far / far2 * near2;
  14476. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  14477. }
  14478. function updateCamera(camera, parent) {
  14479. if (parent === null) {
  14480. camera.matrixWorld.copy(camera.matrix);
  14481. } else {
  14482. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  14483. }
  14484. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  14485. }
  14486. this.getCamera = function (camera) {
  14487. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14488. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14489. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  14490. // Note that the new renderState won't apply until the next frame. See #18320
  14491. session.updateRenderState({
  14492. depthNear: cameraVR.near,
  14493. depthFar: cameraVR.far
  14494. });
  14495. _currentDepthNear = cameraVR.near;
  14496. _currentDepthFar = cameraVR.far;
  14497. }
  14498. var parent = camera.parent;
  14499. var cameras = cameraVR.cameras;
  14500. updateCamera(cameraVR, parent);
  14501. for (var i = 0; i < cameras.length; i++) {
  14502. updateCamera(cameras[i], parent);
  14503. } // update camera and its children
  14504. camera.matrixWorld.copy(cameraVR.matrixWorld);
  14505. camera.matrix.copy(cameraVR.matrix);
  14506. camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
  14507. var children = camera.children;
  14508. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  14509. children[_i3].updateMatrixWorld(true);
  14510. } // update projection matrix for proper view frustum culling
  14511. if (cameras.length === 2) {
  14512. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  14513. } else {
  14514. // assume single camera setup (AR)
  14515. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  14516. }
  14517. return cameraVR;
  14518. }; // Animation Loop
  14519. var onAnimationFrameCallback = null;
  14520. function onAnimationFrame(time, frame) {
  14521. pose = frame.getViewerPose(referenceSpace);
  14522. if (pose !== null) {
  14523. var views = pose.views;
  14524. var baseLayer = session.renderState.baseLayer;
  14525. renderer.setFramebuffer(baseLayer.framebuffer);
  14526. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  14527. if (views.length !== cameraVR.cameras.length) {
  14528. cameraVR.cameras.length = 0;
  14529. cameraVRNeedsUpdate = true;
  14530. }
  14531. for (var i = 0; i < views.length; i++) {
  14532. var view = views[i];
  14533. var viewport = baseLayer.getViewport(view);
  14534. var camera = cameras[i];
  14535. camera.matrix.fromArray(view.transform.matrix);
  14536. camera.projectionMatrix.fromArray(view.projectionMatrix);
  14537. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  14538. if (i === 0) {
  14539. cameraVR.matrix.copy(camera.matrix);
  14540. }
  14541. if (cameraVRNeedsUpdate === true) {
  14542. cameraVR.cameras.push(camera);
  14543. }
  14544. }
  14545. } //
  14546. var inputSources = session.inputSources;
  14547. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  14548. var controller = controllers[_i4];
  14549. var inputSource = inputSources[_i4];
  14550. controller.update(inputSource, frame, referenceSpace);
  14551. }
  14552. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  14553. }
  14554. var animation = new WebGLAnimation();
  14555. animation.setAnimationLoop(onAnimationFrame);
  14556. this.setAnimationLoop = function (callback) {
  14557. onAnimationFrameCallback = callback;
  14558. };
  14559. this.dispose = function () {};
  14560. }
  14561. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  14562. function WebGLMaterials(properties) {
  14563. function refreshFogUniforms(uniforms, fog) {
  14564. uniforms.fogColor.value.copy(fog.color);
  14565. if (fog.isFog) {
  14566. uniforms.fogNear.value = fog.near;
  14567. uniforms.fogFar.value = fog.far;
  14568. } else if (fog.isFogExp2) {
  14569. uniforms.fogDensity.value = fog.density;
  14570. }
  14571. }
  14572. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  14573. if (material.isMeshBasicMaterial) {
  14574. refreshUniformsCommon(uniforms, material);
  14575. } else if (material.isMeshLambertMaterial) {
  14576. refreshUniformsCommon(uniforms, material);
  14577. refreshUniformsLambert(uniforms, material);
  14578. } else if (material.isMeshToonMaterial) {
  14579. refreshUniformsCommon(uniforms, material);
  14580. refreshUniformsToon(uniforms, material);
  14581. } else if (material.isMeshPhongMaterial) {
  14582. refreshUniformsCommon(uniforms, material);
  14583. refreshUniformsPhong(uniforms, material);
  14584. } else if (material.isMeshStandardMaterial) {
  14585. refreshUniformsCommon(uniforms, material);
  14586. if (material.isMeshPhysicalMaterial) {
  14587. refreshUniformsPhysical(uniforms, material);
  14588. } else {
  14589. refreshUniformsStandard(uniforms, material);
  14590. }
  14591. } else if (material.isMeshMatcapMaterial) {
  14592. refreshUniformsCommon(uniforms, material);
  14593. refreshUniformsMatcap(uniforms, material);
  14594. } else if (material.isMeshDepthMaterial) {
  14595. refreshUniformsCommon(uniforms, material);
  14596. refreshUniformsDepth(uniforms, material);
  14597. } else if (material.isMeshDistanceMaterial) {
  14598. refreshUniformsCommon(uniforms, material);
  14599. refreshUniformsDistance(uniforms, material);
  14600. } else if (material.isMeshNormalMaterial) {
  14601. refreshUniformsCommon(uniforms, material);
  14602. refreshUniformsNormal(uniforms, material);
  14603. } else if (material.isLineBasicMaterial) {
  14604. refreshUniformsLine(uniforms, material);
  14605. if (material.isLineDashedMaterial) {
  14606. refreshUniformsDash(uniforms, material);
  14607. }
  14608. } else if (material.isPointsMaterial) {
  14609. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14610. } else if (material.isSpriteMaterial) {
  14611. refreshUniformsSprites(uniforms, material);
  14612. } else if (material.isShadowMaterial) {
  14613. uniforms.color.value.copy(material.color);
  14614. uniforms.opacity.value = material.opacity;
  14615. } else if (material.isShaderMaterial) {
  14616. material.uniformsNeedUpdate = false; // #15581
  14617. }
  14618. }
  14619. function refreshUniformsCommon(uniforms, material) {
  14620. uniforms.opacity.value = material.opacity;
  14621. if (material.color) {
  14622. uniforms.diffuse.value.copy(material.color);
  14623. }
  14624. if (material.emissive) {
  14625. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14626. }
  14627. if (material.map) {
  14628. uniforms.map.value = material.map;
  14629. }
  14630. if (material.alphaMap) {
  14631. uniforms.alphaMap.value = material.alphaMap;
  14632. }
  14633. if (material.specularMap) {
  14634. uniforms.specularMap.value = material.specularMap;
  14635. }
  14636. var envMap = properties.get(material).envMap;
  14637. if (envMap) {
  14638. uniforms.envMap.value = envMap;
  14639. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14640. uniforms.reflectivity.value = material.reflectivity;
  14641. uniforms.refractionRatio.value = material.refractionRatio;
  14642. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14643. if (maxMipLevel !== undefined) {
  14644. uniforms.maxMipLevel.value = maxMipLevel;
  14645. }
  14646. }
  14647. if (material.lightMap) {
  14648. uniforms.lightMap.value = material.lightMap;
  14649. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14650. }
  14651. if (material.aoMap) {
  14652. uniforms.aoMap.value = material.aoMap;
  14653. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14654. } // uv repeat and offset setting priorities
  14655. // 1. color map
  14656. // 2. specular map
  14657. // 3. displacementMap map
  14658. // 4. normal map
  14659. // 5. bump map
  14660. // 6. roughnessMap map
  14661. // 7. metalnessMap map
  14662. // 8. alphaMap map
  14663. // 9. emissiveMap map
  14664. // 10. clearcoat map
  14665. // 11. clearcoat normal map
  14666. // 12. clearcoat roughnessMap map
  14667. var uvScaleMap;
  14668. if (material.map) {
  14669. uvScaleMap = material.map;
  14670. } else if (material.specularMap) {
  14671. uvScaleMap = material.specularMap;
  14672. } else if (material.displacementMap) {
  14673. uvScaleMap = material.displacementMap;
  14674. } else if (material.normalMap) {
  14675. uvScaleMap = material.normalMap;
  14676. } else if (material.bumpMap) {
  14677. uvScaleMap = material.bumpMap;
  14678. } else if (material.roughnessMap) {
  14679. uvScaleMap = material.roughnessMap;
  14680. } else if (material.metalnessMap) {
  14681. uvScaleMap = material.metalnessMap;
  14682. } else if (material.alphaMap) {
  14683. uvScaleMap = material.alphaMap;
  14684. } else if (material.emissiveMap) {
  14685. uvScaleMap = material.emissiveMap;
  14686. } else if (material.clearcoatMap) {
  14687. uvScaleMap = material.clearcoatMap;
  14688. } else if (material.clearcoatNormalMap) {
  14689. uvScaleMap = material.clearcoatNormalMap;
  14690. } else if (material.clearcoatRoughnessMap) {
  14691. uvScaleMap = material.clearcoatRoughnessMap;
  14692. }
  14693. if (uvScaleMap !== undefined) {
  14694. // backwards compatibility
  14695. if (uvScaleMap.isWebGLRenderTarget) {
  14696. uvScaleMap = uvScaleMap.texture;
  14697. }
  14698. if (uvScaleMap.matrixAutoUpdate === true) {
  14699. uvScaleMap.updateMatrix();
  14700. }
  14701. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14702. } // uv repeat and offset setting priorities for uv2
  14703. // 1. ao map
  14704. // 2. light map
  14705. var uv2ScaleMap;
  14706. if (material.aoMap) {
  14707. uv2ScaleMap = material.aoMap;
  14708. } else if (material.lightMap) {
  14709. uv2ScaleMap = material.lightMap;
  14710. }
  14711. if (uv2ScaleMap !== undefined) {
  14712. // backwards compatibility
  14713. if (uv2ScaleMap.isWebGLRenderTarget) {
  14714. uv2ScaleMap = uv2ScaleMap.texture;
  14715. }
  14716. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14717. uv2ScaleMap.updateMatrix();
  14718. }
  14719. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14720. }
  14721. }
  14722. function refreshUniformsLine(uniforms, material) {
  14723. uniforms.diffuse.value.copy(material.color);
  14724. uniforms.opacity.value = material.opacity;
  14725. }
  14726. function refreshUniformsDash(uniforms, material) {
  14727. uniforms.dashSize.value = material.dashSize;
  14728. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14729. uniforms.scale.value = material.scale;
  14730. }
  14731. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14732. uniforms.diffuse.value.copy(material.color);
  14733. uniforms.opacity.value = material.opacity;
  14734. uniforms.size.value = material.size * pixelRatio;
  14735. uniforms.scale.value = height * 0.5;
  14736. if (material.map) {
  14737. uniforms.map.value = material.map;
  14738. }
  14739. if (material.alphaMap) {
  14740. uniforms.alphaMap.value = material.alphaMap;
  14741. } // uv repeat and offset setting priorities
  14742. // 1. color map
  14743. // 2. alpha map
  14744. var uvScaleMap;
  14745. if (material.map) {
  14746. uvScaleMap = material.map;
  14747. } else if (material.alphaMap) {
  14748. uvScaleMap = material.alphaMap;
  14749. }
  14750. if (uvScaleMap !== undefined) {
  14751. if (uvScaleMap.matrixAutoUpdate === true) {
  14752. uvScaleMap.updateMatrix();
  14753. }
  14754. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14755. }
  14756. }
  14757. function refreshUniformsSprites(uniforms, material) {
  14758. uniforms.diffuse.value.copy(material.color);
  14759. uniforms.opacity.value = material.opacity;
  14760. uniforms.rotation.value = material.rotation;
  14761. if (material.map) {
  14762. uniforms.map.value = material.map;
  14763. }
  14764. if (material.alphaMap) {
  14765. uniforms.alphaMap.value = material.alphaMap;
  14766. } // uv repeat and offset setting priorities
  14767. // 1. color map
  14768. // 2. alpha map
  14769. var uvScaleMap;
  14770. if (material.map) {
  14771. uvScaleMap = material.map;
  14772. } else if (material.alphaMap) {
  14773. uvScaleMap = material.alphaMap;
  14774. }
  14775. if (uvScaleMap !== undefined) {
  14776. if (uvScaleMap.matrixAutoUpdate === true) {
  14777. uvScaleMap.updateMatrix();
  14778. }
  14779. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14780. }
  14781. }
  14782. function refreshUniformsLambert(uniforms, material) {
  14783. if (material.emissiveMap) {
  14784. uniforms.emissiveMap.value = material.emissiveMap;
  14785. }
  14786. }
  14787. function refreshUniformsPhong(uniforms, material) {
  14788. uniforms.specular.value.copy(material.specular);
  14789. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14790. if (material.emissiveMap) {
  14791. uniforms.emissiveMap.value = material.emissiveMap;
  14792. }
  14793. if (material.bumpMap) {
  14794. uniforms.bumpMap.value = material.bumpMap;
  14795. uniforms.bumpScale.value = material.bumpScale;
  14796. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14797. }
  14798. if (material.normalMap) {
  14799. uniforms.normalMap.value = material.normalMap;
  14800. uniforms.normalScale.value.copy(material.normalScale);
  14801. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14802. }
  14803. if (material.displacementMap) {
  14804. uniforms.displacementMap.value = material.displacementMap;
  14805. uniforms.displacementScale.value = material.displacementScale;
  14806. uniforms.displacementBias.value = material.displacementBias;
  14807. }
  14808. }
  14809. function refreshUniformsToon(uniforms, material) {
  14810. if (material.gradientMap) {
  14811. uniforms.gradientMap.value = material.gradientMap;
  14812. }
  14813. if (material.emissiveMap) {
  14814. uniforms.emissiveMap.value = material.emissiveMap;
  14815. }
  14816. if (material.bumpMap) {
  14817. uniforms.bumpMap.value = material.bumpMap;
  14818. uniforms.bumpScale.value = material.bumpScale;
  14819. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14820. }
  14821. if (material.normalMap) {
  14822. uniforms.normalMap.value = material.normalMap;
  14823. uniforms.normalScale.value.copy(material.normalScale);
  14824. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14825. }
  14826. if (material.displacementMap) {
  14827. uniforms.displacementMap.value = material.displacementMap;
  14828. uniforms.displacementScale.value = material.displacementScale;
  14829. uniforms.displacementBias.value = material.displacementBias;
  14830. }
  14831. }
  14832. function refreshUniformsStandard(uniforms, material) {
  14833. uniforms.roughness.value = material.roughness;
  14834. uniforms.metalness.value = material.metalness;
  14835. if (material.roughnessMap) {
  14836. uniforms.roughnessMap.value = material.roughnessMap;
  14837. }
  14838. if (material.metalnessMap) {
  14839. uniforms.metalnessMap.value = material.metalnessMap;
  14840. }
  14841. if (material.emissiveMap) {
  14842. uniforms.emissiveMap.value = material.emissiveMap;
  14843. }
  14844. if (material.bumpMap) {
  14845. uniforms.bumpMap.value = material.bumpMap;
  14846. uniforms.bumpScale.value = material.bumpScale;
  14847. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14848. }
  14849. if (material.normalMap) {
  14850. uniforms.normalMap.value = material.normalMap;
  14851. uniforms.normalScale.value.copy(material.normalScale);
  14852. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14853. }
  14854. if (material.displacementMap) {
  14855. uniforms.displacementMap.value = material.displacementMap;
  14856. uniforms.displacementScale.value = material.displacementScale;
  14857. uniforms.displacementBias.value = material.displacementBias;
  14858. }
  14859. var envMap = properties.get(material).envMap;
  14860. if (envMap) {
  14861. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14862. uniforms.envMapIntensity.value = material.envMapIntensity;
  14863. }
  14864. }
  14865. function refreshUniformsPhysical(uniforms, material) {
  14866. refreshUniformsStandard(uniforms, material);
  14867. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14868. uniforms.clearcoat.value = material.clearcoat;
  14869. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14870. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14871. if (material.clearcoatMap) {
  14872. uniforms.clearcoatMap.value = material.clearcoatMap;
  14873. }
  14874. if (material.clearcoatRoughnessMap) {
  14875. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14876. }
  14877. if (material.clearcoatNormalMap) {
  14878. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14879. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14880. if (material.side === BackSide) {
  14881. uniforms.clearcoatNormalScale.value.negate();
  14882. }
  14883. }
  14884. uniforms.transmission.value = material.transmission;
  14885. if (material.transmissionMap) {
  14886. uniforms.transmissionMap.value = material.transmissionMap;
  14887. }
  14888. }
  14889. function refreshUniformsMatcap(uniforms, material) {
  14890. if (material.matcap) {
  14891. uniforms.matcap.value = material.matcap;
  14892. }
  14893. if (material.bumpMap) {
  14894. uniforms.bumpMap.value = material.bumpMap;
  14895. uniforms.bumpScale.value = material.bumpScale;
  14896. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14897. }
  14898. if (material.normalMap) {
  14899. uniforms.normalMap.value = material.normalMap;
  14900. uniforms.normalScale.value.copy(material.normalScale);
  14901. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14902. }
  14903. if (material.displacementMap) {
  14904. uniforms.displacementMap.value = material.displacementMap;
  14905. uniforms.displacementScale.value = material.displacementScale;
  14906. uniforms.displacementBias.value = material.displacementBias;
  14907. }
  14908. }
  14909. function refreshUniformsDepth(uniforms, material) {
  14910. if (material.displacementMap) {
  14911. uniforms.displacementMap.value = material.displacementMap;
  14912. uniforms.displacementScale.value = material.displacementScale;
  14913. uniforms.displacementBias.value = material.displacementBias;
  14914. }
  14915. }
  14916. function refreshUniformsDistance(uniforms, material) {
  14917. if (material.displacementMap) {
  14918. uniforms.displacementMap.value = material.displacementMap;
  14919. uniforms.displacementScale.value = material.displacementScale;
  14920. uniforms.displacementBias.value = material.displacementBias;
  14921. }
  14922. uniforms.referencePosition.value.copy(material.referencePosition);
  14923. uniforms.nearDistance.value = material.nearDistance;
  14924. uniforms.farDistance.value = material.farDistance;
  14925. }
  14926. function refreshUniformsNormal(uniforms, material) {
  14927. if (material.bumpMap) {
  14928. uniforms.bumpMap.value = material.bumpMap;
  14929. uniforms.bumpScale.value = material.bumpScale;
  14930. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14931. }
  14932. if (material.normalMap) {
  14933. uniforms.normalMap.value = material.normalMap;
  14934. uniforms.normalScale.value.copy(material.normalScale);
  14935. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14936. }
  14937. if (material.displacementMap) {
  14938. uniforms.displacementMap.value = material.displacementMap;
  14939. uniforms.displacementScale.value = material.displacementScale;
  14940. uniforms.displacementBias.value = material.displacementBias;
  14941. }
  14942. }
  14943. return {
  14944. refreshFogUniforms: refreshFogUniforms,
  14945. refreshMaterialUniforms: refreshMaterialUniforms
  14946. };
  14947. }
  14948. function createCanvasElement() {
  14949. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14950. canvas.style.display = 'block';
  14951. return canvas;
  14952. }
  14953. function WebGLRenderer(parameters) {
  14954. parameters = parameters || {};
  14955. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14956. _context = parameters.context !== undefined ? parameters.context : null,
  14957. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14958. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14959. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14960. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14961. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14962. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14963. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14964. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14965. var currentRenderList = null;
  14966. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14967. // We track this so that the nested render call gets its list and state isolated from the parent render call.
  14968. var renderListStack = [];
  14969. var renderStateStack = []; // public properties
  14970. this.domElement = _canvas; // Debug configuration container
  14971. this.debug = {
  14972. /**
  14973. * Enables error checking and reporting when shader programs are being compiled
  14974. * @type {boolean}
  14975. */
  14976. checkShaderErrors: true
  14977. }; // clearing
  14978. this.autoClear = true;
  14979. this.autoClearColor = true;
  14980. this.autoClearDepth = true;
  14981. this.autoClearStencil = true; // scene graph
  14982. this.sortObjects = true; // user-defined clipping
  14983. this.clippingPlanes = [];
  14984. this.localClippingEnabled = false; // physically based shading
  14985. this.gammaFactor = 2.0; // for backwards compatibility
  14986. this.outputEncoding = LinearEncoding; // physical lights
  14987. this.physicallyCorrectLights = false; // tone mapping
  14988. this.toneMapping = NoToneMapping;
  14989. this.toneMappingExposure = 1.0; // morphs
  14990. this.maxMorphTargets = 8;
  14991. this.maxMorphNormals = 4; // internal properties
  14992. var _this = this;
  14993. var _isContextLost = false; // internal state cache
  14994. var _framebuffer = null;
  14995. var _currentActiveCubeFace = 0;
  14996. var _currentActiveMipmapLevel = 0;
  14997. var _currentRenderTarget = null;
  14998. var _currentFramebuffer = null;
  14999. var _currentMaterialId = -1;
  15000. var _currentCamera = null;
  15001. var _currentViewport = new Vector4();
  15002. var _currentScissor = new Vector4();
  15003. var _currentScissorTest = null; //
  15004. var _width = _canvas.width;
  15005. var _height = _canvas.height;
  15006. var _pixelRatio = 1;
  15007. var _opaqueSort = null;
  15008. var _transparentSort = null;
  15009. var _viewport = new Vector4(0, 0, _width, _height);
  15010. var _scissor = new Vector4(0, 0, _width, _height);
  15011. var _scissorTest = false; // frustum
  15012. var _frustum = new Frustum(); // clipping
  15013. var _clippingEnabled = false;
  15014. var _localClippingEnabled = false; // camera matrices cache
  15015. var _projScreenMatrix = new Matrix4();
  15016. var _vector3 = new Vector3();
  15017. var _emptyScene = {
  15018. background: null,
  15019. fog: null,
  15020. environment: null,
  15021. overrideMaterial: null,
  15022. isScene: true
  15023. };
  15024. function getTargetPixelRatio() {
  15025. return _currentRenderTarget === null ? _pixelRatio : 1;
  15026. } // initialize
  15027. var _gl = _context;
  15028. function getContext(contextNames, contextAttributes) {
  15029. for (var i = 0; i < contextNames.length; i++) {
  15030. var contextName = contextNames[i];
  15031. var context = _canvas.getContext(contextName, contextAttributes);
  15032. if (context !== null) return context;
  15033. }
  15034. return null;
  15035. }
  15036. try {
  15037. var contextAttributes = {
  15038. alpha: _alpha,
  15039. depth: _depth,
  15040. stencil: _stencil,
  15041. antialias: _antialias,
  15042. premultipliedAlpha: _premultipliedAlpha,
  15043. preserveDrawingBuffer: _preserveDrawingBuffer,
  15044. powerPreference: _powerPreference,
  15045. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  15046. }; // event listeners must be registered before WebGL context is created, see #12753
  15047. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  15048. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  15049. if (_gl === null) {
  15050. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  15051. if (_this.isWebGL1Renderer === true) {
  15052. contextNames.shift();
  15053. }
  15054. _gl = getContext(contextNames, contextAttributes);
  15055. if (_gl === null) {
  15056. if (getContext(contextNames)) {
  15057. throw new Error('Error creating WebGL context with your selected attributes.');
  15058. } else {
  15059. throw new Error('Error creating WebGL context.');
  15060. }
  15061. }
  15062. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  15063. if (_gl.getShaderPrecisionFormat === undefined) {
  15064. _gl.getShaderPrecisionFormat = function () {
  15065. return {
  15066. 'rangeMin': 1,
  15067. 'rangeMax': 1,
  15068. 'precision': 1
  15069. };
  15070. };
  15071. }
  15072. } catch (error) {
  15073. console.error('THREE.WebGLRenderer: ' + error.message);
  15074. throw error;
  15075. }
  15076. var extensions, capabilities, state, info;
  15077. var properties, textures, cubemaps, attributes, geometries, objects;
  15078. var programCache, materials, renderLists, renderStates, clipping;
  15079. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  15080. var utils, bindingStates;
  15081. function initGLContext() {
  15082. extensions = new WebGLExtensions(_gl);
  15083. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  15084. extensions.init(capabilities);
  15085. utils = new WebGLUtils(_gl, extensions, capabilities);
  15086. state = new WebGLState(_gl, extensions, capabilities);
  15087. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15088. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15089. info = new WebGLInfo(_gl);
  15090. properties = new WebGLProperties();
  15091. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  15092. cubemaps = new WebGLCubeMaps(_this);
  15093. attributes = new WebGLAttributes(_gl, capabilities);
  15094. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  15095. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  15096. objects = new WebGLObjects(_gl, geometries, attributes, info);
  15097. morphtargets = new WebGLMorphtargets(_gl);
  15098. clipping = new WebGLClipping(properties);
  15099. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  15100. materials = new WebGLMaterials(properties);
  15101. renderLists = new WebGLRenderLists(properties);
  15102. renderStates = new WebGLRenderStates(extensions, capabilities);
  15103. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  15104. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  15105. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  15106. info.programs = programCache.programs;
  15107. _this.capabilities = capabilities;
  15108. _this.extensions = extensions;
  15109. _this.properties = properties;
  15110. _this.renderLists = renderLists;
  15111. _this.state = state;
  15112. _this.info = info;
  15113. }
  15114. initGLContext(); // xr
  15115. var xr = new WebXRManager(_this, _gl);
  15116. this.xr = xr; // shadow map
  15117. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  15118. this.shadowMap = shadowMap; // API
  15119. this.getContext = function () {
  15120. return _gl;
  15121. };
  15122. this.getContextAttributes = function () {
  15123. return _gl.getContextAttributes();
  15124. };
  15125. this.forceContextLoss = function () {
  15126. var extension = extensions.get('WEBGL_lose_context');
  15127. if (extension) extension.loseContext();
  15128. };
  15129. this.forceContextRestore = function () {
  15130. var extension = extensions.get('WEBGL_lose_context');
  15131. if (extension) extension.restoreContext();
  15132. };
  15133. this.getPixelRatio = function () {
  15134. return _pixelRatio;
  15135. };
  15136. this.setPixelRatio = function (value) {
  15137. if (value === undefined) return;
  15138. _pixelRatio = value;
  15139. this.setSize(_width, _height, false);
  15140. };
  15141. this.getSize = function (target) {
  15142. if (target === undefined) {
  15143. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  15144. target = new Vector2();
  15145. }
  15146. return target.set(_width, _height);
  15147. };
  15148. this.setSize = function (width, height, updateStyle) {
  15149. if (xr.isPresenting) {
  15150. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  15151. return;
  15152. }
  15153. _width = width;
  15154. _height = height;
  15155. _canvas.width = Math.floor(width * _pixelRatio);
  15156. _canvas.height = Math.floor(height * _pixelRatio);
  15157. if (updateStyle !== false) {
  15158. _canvas.style.width = width + 'px';
  15159. _canvas.style.height = height + 'px';
  15160. }
  15161. this.setViewport(0, 0, width, height);
  15162. };
  15163. this.getDrawingBufferSize = function (target) {
  15164. if (target === undefined) {
  15165. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  15166. target = new Vector2();
  15167. }
  15168. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  15169. };
  15170. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  15171. _width = width;
  15172. _height = height;
  15173. _pixelRatio = pixelRatio;
  15174. _canvas.width = Math.floor(width * pixelRatio);
  15175. _canvas.height = Math.floor(height * pixelRatio);
  15176. this.setViewport(0, 0, width, height);
  15177. };
  15178. this.getCurrentViewport = function (target) {
  15179. if (target === undefined) {
  15180. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  15181. target = new Vector4();
  15182. }
  15183. return target.copy(_currentViewport);
  15184. };
  15185. this.getViewport = function (target) {
  15186. return target.copy(_viewport);
  15187. };
  15188. this.setViewport = function (x, y, width, height) {
  15189. if (x.isVector4) {
  15190. _viewport.set(x.x, x.y, x.z, x.w);
  15191. } else {
  15192. _viewport.set(x, y, width, height);
  15193. }
  15194. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15195. };
  15196. this.getScissor = function (target) {
  15197. return target.copy(_scissor);
  15198. };
  15199. this.setScissor = function (x, y, width, height) {
  15200. if (x.isVector4) {
  15201. _scissor.set(x.x, x.y, x.z, x.w);
  15202. } else {
  15203. _scissor.set(x, y, width, height);
  15204. }
  15205. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15206. };
  15207. this.getScissorTest = function () {
  15208. return _scissorTest;
  15209. };
  15210. this.setScissorTest = function (boolean) {
  15211. state.setScissorTest(_scissorTest = boolean);
  15212. };
  15213. this.setOpaqueSort = function (method) {
  15214. _opaqueSort = method;
  15215. };
  15216. this.setTransparentSort = function (method) {
  15217. _transparentSort = method;
  15218. }; // Clearing
  15219. this.getClearColor = function (target) {
  15220. if (target === undefined) {
  15221. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  15222. target = new Color();
  15223. }
  15224. return target.copy(background.getClearColor());
  15225. };
  15226. this.setClearColor = function () {
  15227. background.setClearColor.apply(background, arguments);
  15228. };
  15229. this.getClearAlpha = function () {
  15230. return background.getClearAlpha();
  15231. };
  15232. this.setClearAlpha = function () {
  15233. background.setClearAlpha.apply(background, arguments);
  15234. };
  15235. this.clear = function (color, depth, stencil) {
  15236. var bits = 0;
  15237. if (color === undefined || color) bits |= 16384;
  15238. if (depth === undefined || depth) bits |= 256;
  15239. if (stencil === undefined || stencil) bits |= 1024;
  15240. _gl.clear(bits);
  15241. };
  15242. this.clearColor = function () {
  15243. this.clear(true, false, false);
  15244. };
  15245. this.clearDepth = function () {
  15246. this.clear(false, true, false);
  15247. };
  15248. this.clearStencil = function () {
  15249. this.clear(false, false, true);
  15250. }; //
  15251. this.dispose = function () {
  15252. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  15253. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  15254. renderLists.dispose();
  15255. renderStates.dispose();
  15256. properties.dispose();
  15257. cubemaps.dispose();
  15258. objects.dispose();
  15259. bindingStates.dispose();
  15260. xr.dispose();
  15261. animation.stop();
  15262. }; // Events
  15263. function onContextLost(event) {
  15264. event.preventDefault();
  15265. console.log('THREE.WebGLRenderer: Context Lost.');
  15266. _isContextLost = true;
  15267. }
  15268. function onContextRestore()
  15269. /* event */
  15270. {
  15271. console.log('THREE.WebGLRenderer: Context Restored.');
  15272. _isContextLost = false;
  15273. initGLContext();
  15274. }
  15275. function onMaterialDispose(event) {
  15276. var material = event.target;
  15277. material.removeEventListener('dispose', onMaterialDispose);
  15278. deallocateMaterial(material);
  15279. } // Buffer deallocation
  15280. function deallocateMaterial(material) {
  15281. releaseMaterialProgramReference(material);
  15282. properties.remove(material);
  15283. }
  15284. function releaseMaterialProgramReference(material) {
  15285. var programInfo = properties.get(material).program;
  15286. if (programInfo !== undefined) {
  15287. programCache.releaseProgram(programInfo);
  15288. }
  15289. } // Buffer rendering
  15290. function renderObjectImmediate(object, program) {
  15291. object.render(function (object) {
  15292. _this.renderBufferImmediate(object, program);
  15293. });
  15294. }
  15295. this.renderBufferImmediate = function (object, program) {
  15296. bindingStates.initAttributes();
  15297. var buffers = properties.get(object);
  15298. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  15299. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  15300. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  15301. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  15302. var programAttributes = program.getAttributes();
  15303. if (object.hasPositions) {
  15304. _gl.bindBuffer(34962, buffers.position);
  15305. _gl.bufferData(34962, object.positionArray, 35048);
  15306. bindingStates.enableAttribute(programAttributes.position);
  15307. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  15308. }
  15309. if (object.hasNormals) {
  15310. _gl.bindBuffer(34962, buffers.normal);
  15311. _gl.bufferData(34962, object.normalArray, 35048);
  15312. bindingStates.enableAttribute(programAttributes.normal);
  15313. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  15314. }
  15315. if (object.hasUvs) {
  15316. _gl.bindBuffer(34962, buffers.uv);
  15317. _gl.bufferData(34962, object.uvArray, 35048);
  15318. bindingStates.enableAttribute(programAttributes.uv);
  15319. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  15320. }
  15321. if (object.hasColors) {
  15322. _gl.bindBuffer(34962, buffers.color);
  15323. _gl.bufferData(34962, object.colorArray, 35048);
  15324. bindingStates.enableAttribute(programAttributes.color);
  15325. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  15326. }
  15327. bindingStates.disableUnusedAttributes();
  15328. _gl.drawArrays(4, 0, object.count);
  15329. object.count = 0;
  15330. };
  15331. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  15332. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15333. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  15334. var program = setProgram(camera, scene, material, object);
  15335. state.setMaterial(material, frontFaceCW); //
  15336. var index = geometry.index;
  15337. var position = geometry.attributes.position; //
  15338. if (index === null) {
  15339. if (position === undefined || position.count === 0) return;
  15340. } else if (index.count === 0) {
  15341. return;
  15342. } //
  15343. var rangeFactor = 1;
  15344. if (material.wireframe === true) {
  15345. index = geometries.getWireframeAttribute(geometry);
  15346. rangeFactor = 2;
  15347. }
  15348. if (material.morphTargets || material.morphNormals) {
  15349. morphtargets.update(object, geometry, material, program);
  15350. }
  15351. bindingStates.setup(object, material, program, geometry, index);
  15352. var attribute;
  15353. var renderer = bufferRenderer;
  15354. if (index !== null) {
  15355. attribute = attributes.get(index);
  15356. renderer = indexedBufferRenderer;
  15357. renderer.setIndex(attribute);
  15358. } //
  15359. var dataCount = index !== null ? index.count : position.count;
  15360. var rangeStart = geometry.drawRange.start * rangeFactor;
  15361. var rangeCount = geometry.drawRange.count * rangeFactor;
  15362. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15363. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15364. var drawStart = Math.max(rangeStart, groupStart);
  15365. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  15366. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  15367. if (drawCount === 0) return; //
  15368. if (object.isMesh) {
  15369. if (material.wireframe === true) {
  15370. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  15371. renderer.setMode(1);
  15372. } else {
  15373. renderer.setMode(4);
  15374. }
  15375. } else if (object.isLine) {
  15376. var lineWidth = material.linewidth;
  15377. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  15378. state.setLineWidth(lineWidth * getTargetPixelRatio());
  15379. if (object.isLineSegments) {
  15380. renderer.setMode(1);
  15381. } else if (object.isLineLoop) {
  15382. renderer.setMode(2);
  15383. } else {
  15384. renderer.setMode(3);
  15385. }
  15386. } else if (object.isPoints) {
  15387. renderer.setMode(0);
  15388. } else if (object.isSprite) {
  15389. renderer.setMode(4);
  15390. }
  15391. if (object.isInstancedMesh) {
  15392. renderer.renderInstances(drawStart, drawCount, object.count);
  15393. } else if (geometry.isInstancedBufferGeometry) {
  15394. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  15395. renderer.renderInstances(drawStart, drawCount, instanceCount);
  15396. } else {
  15397. renderer.render(drawStart, drawCount);
  15398. }
  15399. }; // Compile
  15400. this.compile = function (scene, camera) {
  15401. currentRenderState = renderStates.get(scene);
  15402. currentRenderState.init();
  15403. scene.traverseVisible(function (object) {
  15404. if (object.isLight && object.layers.test(camera.layers)) {
  15405. currentRenderState.pushLight(object);
  15406. if (object.castShadow) {
  15407. currentRenderState.pushShadow(object);
  15408. }
  15409. }
  15410. });
  15411. currentRenderState.setupLights();
  15412. var compiled = new WeakMap();
  15413. scene.traverse(function (object) {
  15414. var material = object.material;
  15415. if (material) {
  15416. if (Array.isArray(material)) {
  15417. for (var i = 0; i < material.length; i++) {
  15418. var material2 = material[i];
  15419. if (compiled.has(material2) === false) {
  15420. initMaterial(material2, scene, object);
  15421. compiled.set(material2);
  15422. }
  15423. }
  15424. } else if (compiled.has(material) === false) {
  15425. initMaterial(material, scene, object);
  15426. compiled.set(material);
  15427. }
  15428. }
  15429. });
  15430. }; // Animation Loop
  15431. var onAnimationFrameCallback = null;
  15432. function onAnimationFrame(time) {
  15433. if (xr.isPresenting) return;
  15434. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  15435. }
  15436. var animation = new WebGLAnimation();
  15437. animation.setAnimationLoop(onAnimationFrame);
  15438. if (typeof window !== 'undefined') animation.setContext(window);
  15439. this.setAnimationLoop = function (callback) {
  15440. onAnimationFrameCallback = callback;
  15441. xr.setAnimationLoop(callback);
  15442. callback === null ? animation.stop() : animation.start();
  15443. }; // Rendering
  15444. this.render = function (scene, camera) {
  15445. var renderTarget, forceClear;
  15446. if (arguments[2] !== undefined) {
  15447. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  15448. renderTarget = arguments[2];
  15449. }
  15450. if (arguments[3] !== undefined) {
  15451. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  15452. forceClear = arguments[3];
  15453. }
  15454. if (camera !== undefined && camera.isCamera !== true) {
  15455. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  15456. return;
  15457. }
  15458. if (_isContextLost === true) return; // reset caching for this frame
  15459. bindingStates.resetDefaultState();
  15460. _currentMaterialId = -1;
  15461. _currentCamera = null; // update scene graph
  15462. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  15463. if (camera.parent === null) camera.updateMatrixWorld();
  15464. if (xr.enabled === true && xr.isPresenting === true) {
  15465. camera = xr.getCamera(camera);
  15466. } //
  15467. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  15468. currentRenderState = renderStates.get(scene, renderStateStack.length);
  15469. currentRenderState.init();
  15470. renderStateStack.push(currentRenderState);
  15471. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  15472. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  15473. _localClippingEnabled = this.localClippingEnabled;
  15474. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  15475. currentRenderList = renderLists.get(scene, renderListStack.length);
  15476. currentRenderList.init();
  15477. renderListStack.push(currentRenderList);
  15478. projectObject(scene, camera, 0, _this.sortObjects);
  15479. currentRenderList.finish();
  15480. if (_this.sortObjects === true) {
  15481. currentRenderList.sort(_opaqueSort, _transparentSort);
  15482. } //
  15483. if (_clippingEnabled === true) clipping.beginShadows();
  15484. var shadowsArray = currentRenderState.state.shadowsArray;
  15485. shadowMap.render(shadowsArray, scene, camera);
  15486. currentRenderState.setupLights();
  15487. currentRenderState.setupLightsView(camera);
  15488. if (_clippingEnabled === true) clipping.endShadows(); //
  15489. if (this.info.autoReset === true) this.info.reset();
  15490. if (renderTarget !== undefined) {
  15491. this.setRenderTarget(renderTarget);
  15492. } //
  15493. background.render(currentRenderList, scene, camera, forceClear); // render scene
  15494. var opaqueObjects = currentRenderList.opaque;
  15495. var transparentObjects = currentRenderList.transparent;
  15496. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  15497. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  15498. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  15499. if (_currentRenderTarget !== null) {
  15500. // Generate mipmap if we're using any kind of mipmap filtering
  15501. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  15502. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  15503. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  15504. state.buffers.depth.setTest(true);
  15505. state.buffers.depth.setMask(true);
  15506. state.buffers.color.setMask(true);
  15507. state.setPolygonOffset(false); // _gl.finish();
  15508. renderStateStack.pop();
  15509. if (renderStateStack.length > 0) {
  15510. currentRenderState = renderStateStack[renderStateStack.length - 1];
  15511. } else {
  15512. currentRenderState = null;
  15513. }
  15514. renderListStack.pop();
  15515. if (renderListStack.length > 0) {
  15516. currentRenderList = renderListStack[renderListStack.length - 1];
  15517. } else {
  15518. currentRenderList = null;
  15519. }
  15520. };
  15521. function projectObject(object, camera, groupOrder, sortObjects) {
  15522. if (object.visible === false) return;
  15523. var visible = object.layers.test(camera.layers);
  15524. if (visible) {
  15525. if (object.isGroup) {
  15526. groupOrder = object.renderOrder;
  15527. } else if (object.isLOD) {
  15528. if (object.autoUpdate === true) object.update(camera);
  15529. } else if (object.isLight) {
  15530. currentRenderState.pushLight(object);
  15531. if (object.castShadow) {
  15532. currentRenderState.pushShadow(object);
  15533. }
  15534. } else if (object.isSprite) {
  15535. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  15536. if (sortObjects) {
  15537. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15538. }
  15539. var geometry = objects.update(object);
  15540. var material = object.material;
  15541. if (material.visible) {
  15542. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  15543. }
  15544. }
  15545. } else if (object.isImmediateRenderObject) {
  15546. if (sortObjects) {
  15547. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15548. }
  15549. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  15550. } else if (object.isMesh || object.isLine || object.isPoints) {
  15551. if (object.isSkinnedMesh) {
  15552. // update skeleton only once in a frame
  15553. if (object.skeleton.frame !== info.render.frame) {
  15554. object.skeleton.update();
  15555. object.skeleton.frame = info.render.frame;
  15556. }
  15557. }
  15558. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  15559. if (sortObjects) {
  15560. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15561. }
  15562. var _geometry = objects.update(object);
  15563. var _material = object.material;
  15564. if (Array.isArray(_material)) {
  15565. var groups = _geometry.groups;
  15566. for (var i = 0, l = groups.length; i < l; i++) {
  15567. var group = groups[i];
  15568. var groupMaterial = _material[group.materialIndex];
  15569. if (groupMaterial && groupMaterial.visible) {
  15570. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  15571. }
  15572. }
  15573. } else if (_material.visible) {
  15574. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  15575. }
  15576. }
  15577. }
  15578. }
  15579. var children = object.children;
  15580. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  15581. projectObject(children[_i], camera, groupOrder, sortObjects);
  15582. }
  15583. }
  15584. function renderObjects(renderList, scene, camera) {
  15585. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15586. for (var i = 0, l = renderList.length; i < l; i++) {
  15587. var renderItem = renderList[i];
  15588. var object = renderItem.object;
  15589. var geometry = renderItem.geometry;
  15590. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15591. var group = renderItem.group;
  15592. if (camera.isArrayCamera) {
  15593. var cameras = camera.cameras;
  15594. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15595. var camera2 = cameras[j];
  15596. if (object.layers.test(camera2.layers)) {
  15597. state.viewport(_currentViewport.copy(camera2.viewport));
  15598. currentRenderState.setupLightsView(camera2);
  15599. renderObject(object, scene, camera2, geometry, material, group);
  15600. }
  15601. }
  15602. } else {
  15603. renderObject(object, scene, camera, geometry, material, group);
  15604. }
  15605. }
  15606. }
  15607. function renderObject(object, scene, camera, geometry, material, group) {
  15608. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15609. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15610. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15611. if (object.isImmediateRenderObject) {
  15612. var program = setProgram(camera, scene, material, object);
  15613. state.setMaterial(material);
  15614. bindingStates.reset();
  15615. renderObjectImmediate(object, program);
  15616. } else {
  15617. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15618. }
  15619. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15620. }
  15621. function initMaterial(material, scene, object) {
  15622. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15623. var materialProperties = properties.get(material);
  15624. var lights = currentRenderState.state.lights;
  15625. var shadowsArray = currentRenderState.state.shadowsArray;
  15626. var lightsStateVersion = lights.state.version;
  15627. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15628. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15629. var program = materialProperties.program;
  15630. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15631. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15632. materialProperties.fog = scene.fog;
  15633. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15634. if (program === undefined) {
  15635. // new material
  15636. material.addEventListener('dispose', onMaterialDispose);
  15637. } else if (program.cacheKey !== programCacheKey) {
  15638. // changed glsl or parameters
  15639. releaseMaterialProgramReference(material);
  15640. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15641. programChange = false;
  15642. } else if (parameters.shaderID !== undefined) {
  15643. // same glsl and uniform list
  15644. return;
  15645. } else {
  15646. // only rebuild uniform list
  15647. programChange = false;
  15648. }
  15649. if (programChange) {
  15650. parameters.uniforms = programCache.getUniforms(material);
  15651. material.onBeforeCompile(parameters, _this);
  15652. program = programCache.acquireProgram(parameters, programCacheKey);
  15653. materialProperties.program = program;
  15654. materialProperties.uniforms = parameters.uniforms;
  15655. materialProperties.outputEncoding = parameters.outputEncoding;
  15656. }
  15657. var uniforms = materialProperties.uniforms;
  15658. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15659. materialProperties.numClippingPlanes = clipping.numPlanes;
  15660. materialProperties.numIntersection = clipping.numIntersection;
  15661. uniforms.clippingPlanes = clipping.uniform;
  15662. } // store the light setup it was created for
  15663. materialProperties.needsLights = materialNeedsLights(material);
  15664. materialProperties.lightsStateVersion = lightsStateVersion;
  15665. if (materialProperties.needsLights) {
  15666. // wire up the material to this renderer's lighting state
  15667. uniforms.ambientLightColor.value = lights.state.ambient;
  15668. uniforms.lightProbe.value = lights.state.probe;
  15669. uniforms.directionalLights.value = lights.state.directional;
  15670. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15671. uniforms.spotLights.value = lights.state.spot;
  15672. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15673. uniforms.rectAreaLights.value = lights.state.rectArea;
  15674. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15675. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15676. uniforms.pointLights.value = lights.state.point;
  15677. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15678. uniforms.hemisphereLights.value = lights.state.hemi;
  15679. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15680. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15681. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15682. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15683. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15684. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15685. }
  15686. var progUniforms = materialProperties.program.getUniforms();
  15687. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15688. materialProperties.uniformsList = uniformsList;
  15689. }
  15690. function setProgram(camera, scene, material, object) {
  15691. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15692. textures.resetTextureUnits();
  15693. var fog = scene.fog;
  15694. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15695. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15696. var envMap = cubemaps.get(material.envMap || environment);
  15697. var materialProperties = properties.get(material);
  15698. var lights = currentRenderState.state.lights;
  15699. if (_clippingEnabled === true) {
  15700. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15701. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15702. // object instead of the material, once it becomes feasible
  15703. // (#8465, #8379)
  15704. clipping.setState(material, camera, useCache);
  15705. }
  15706. }
  15707. if (material.version === materialProperties.__version) {
  15708. if (material.fog && materialProperties.fog !== fog) {
  15709. initMaterial(material, scene, object);
  15710. } else if (materialProperties.environment !== environment) {
  15711. initMaterial(material, scene, object);
  15712. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15713. initMaterial(material, scene, object);
  15714. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15715. initMaterial(material, scene, object);
  15716. } else if (materialProperties.outputEncoding !== encoding) {
  15717. initMaterial(material, scene, object);
  15718. } else if (materialProperties.envMap !== envMap) {
  15719. initMaterial(material, scene, object);
  15720. }
  15721. } else {
  15722. initMaterial(material, scene, object);
  15723. materialProperties.__version = material.version;
  15724. }
  15725. var refreshProgram = false;
  15726. var refreshMaterial = false;
  15727. var refreshLights = false;
  15728. var program = materialProperties.program,
  15729. p_uniforms = program.getUniforms(),
  15730. m_uniforms = materialProperties.uniforms;
  15731. if (state.useProgram(program.program)) {
  15732. refreshProgram = true;
  15733. refreshMaterial = true;
  15734. refreshLights = true;
  15735. }
  15736. if (material.id !== _currentMaterialId) {
  15737. _currentMaterialId = material.id;
  15738. refreshMaterial = true;
  15739. }
  15740. if (refreshProgram || _currentCamera !== camera) {
  15741. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15742. if (capabilities.logarithmicDepthBuffer) {
  15743. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15744. }
  15745. if (_currentCamera !== camera) {
  15746. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15747. // now, in case this material supports lights - or later, when
  15748. // the next material that does gets activated:
  15749. refreshMaterial = true; // set to true on material change
  15750. refreshLights = true; // remains set until update done
  15751. } // load material specific uniforms
  15752. // (shader material also gets them for the sake of genericity)
  15753. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15754. var uCamPos = p_uniforms.map.cameraPosition;
  15755. if (uCamPos !== undefined) {
  15756. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15757. }
  15758. }
  15759. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15760. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15761. }
  15762. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15763. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15764. }
  15765. } // skinning uniforms must be set even if material didn't change
  15766. // auto-setting of texture unit for bone texture must go before other textures
  15767. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15768. if (material.skinning) {
  15769. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15770. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15771. var skeleton = object.skeleton;
  15772. if (skeleton) {
  15773. var bones = skeleton.bones;
  15774. if (capabilities.floatVertexTextures) {
  15775. if (skeleton.boneTexture === null) {
  15776. // layout (1 matrix = 4 pixels)
  15777. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15778. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15779. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15780. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15781. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15782. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15783. size = MathUtils.ceilPowerOfTwo(size);
  15784. size = Math.max(size, 4);
  15785. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15786. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15787. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15788. skeleton.boneMatrices = boneMatrices;
  15789. skeleton.boneTexture = boneTexture;
  15790. skeleton.boneTextureSize = size;
  15791. }
  15792. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15793. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15794. } else {
  15795. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15796. }
  15797. }
  15798. }
  15799. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15800. materialProperties.receiveShadow = object.receiveShadow;
  15801. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15802. }
  15803. if (refreshMaterial) {
  15804. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15805. if (materialProperties.needsLights) {
  15806. // the current material requires lighting info
  15807. // note: all lighting uniforms are always set correctly
  15808. // they simply reference the renderer's state for their
  15809. // values
  15810. //
  15811. // use the current material's .needsUpdate flags to set
  15812. // the GL state when required
  15813. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15814. } // refresh uniforms common to several materials
  15815. if (fog && material.fog) {
  15816. materials.refreshFogUniforms(m_uniforms, fog);
  15817. }
  15818. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15819. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15820. }
  15821. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15822. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15823. material.uniformsNeedUpdate = false;
  15824. }
  15825. if (material.isSpriteMaterial) {
  15826. p_uniforms.setValue(_gl, 'center', object.center);
  15827. } // common matrices
  15828. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15829. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15830. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15831. return program;
  15832. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15833. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15834. uniforms.ambientLightColor.needsUpdate = value;
  15835. uniforms.lightProbe.needsUpdate = value;
  15836. uniforms.directionalLights.needsUpdate = value;
  15837. uniforms.directionalLightShadows.needsUpdate = value;
  15838. uniforms.pointLights.needsUpdate = value;
  15839. uniforms.pointLightShadows.needsUpdate = value;
  15840. uniforms.spotLights.needsUpdate = value;
  15841. uniforms.spotLightShadows.needsUpdate = value;
  15842. uniforms.rectAreaLights.needsUpdate = value;
  15843. uniforms.hemisphereLights.needsUpdate = value;
  15844. }
  15845. function materialNeedsLights(material) {
  15846. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15847. } //
  15848. this.setFramebuffer = function (value) {
  15849. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15850. _framebuffer = value;
  15851. };
  15852. this.getActiveCubeFace = function () {
  15853. return _currentActiveCubeFace;
  15854. };
  15855. this.getActiveMipmapLevel = function () {
  15856. return _currentActiveMipmapLevel;
  15857. };
  15858. this.getRenderTarget = function () {
  15859. return _currentRenderTarget;
  15860. };
  15861. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15862. if (activeCubeFace === void 0) {
  15863. activeCubeFace = 0;
  15864. }
  15865. if (activeMipmapLevel === void 0) {
  15866. activeMipmapLevel = 0;
  15867. }
  15868. _currentRenderTarget = renderTarget;
  15869. _currentActiveCubeFace = activeCubeFace;
  15870. _currentActiveMipmapLevel = activeMipmapLevel;
  15871. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15872. textures.setupRenderTarget(renderTarget);
  15873. }
  15874. var framebuffer = _framebuffer;
  15875. var isCube = false;
  15876. var isRenderTarget3D = false;
  15877. if (renderTarget) {
  15878. var texture = renderTarget.texture;
  15879. if (texture.isDataTexture3D || texture.isDataTexture2DArray) {
  15880. isRenderTarget3D = true;
  15881. }
  15882. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15883. if (renderTarget.isWebGLCubeRenderTarget) {
  15884. framebuffer = __webglFramebuffer[activeCubeFace];
  15885. isCube = true;
  15886. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15887. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15888. } else {
  15889. framebuffer = __webglFramebuffer;
  15890. }
  15891. _currentViewport.copy(renderTarget.viewport);
  15892. _currentScissor.copy(renderTarget.scissor);
  15893. _currentScissorTest = renderTarget.scissorTest;
  15894. } else {
  15895. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15896. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15897. _currentScissorTest = _scissorTest;
  15898. }
  15899. if (_currentFramebuffer !== framebuffer) {
  15900. _gl.bindFramebuffer(36160, framebuffer);
  15901. _currentFramebuffer = framebuffer;
  15902. }
  15903. state.viewport(_currentViewport);
  15904. state.scissor(_currentScissor);
  15905. state.setScissorTest(_currentScissorTest);
  15906. if (isCube) {
  15907. var textureProperties = properties.get(renderTarget.texture);
  15908. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15909. } else if (isRenderTarget3D) {
  15910. var _textureProperties = properties.get(renderTarget.texture);
  15911. var layer = activeCubeFace || 0;
  15912. _gl.framebufferTextureLayer(36160, 36064, _textureProperties.__webglTexture, activeMipmapLevel || 0, layer);
  15913. }
  15914. };
  15915. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15916. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15917. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15918. return;
  15919. }
  15920. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15921. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15922. framebuffer = framebuffer[activeCubeFaceIndex];
  15923. }
  15924. if (framebuffer) {
  15925. var restore = false;
  15926. if (framebuffer !== _currentFramebuffer) {
  15927. _gl.bindFramebuffer(36160, framebuffer);
  15928. restore = true;
  15929. }
  15930. try {
  15931. var texture = renderTarget.texture;
  15932. var textureFormat = texture.format;
  15933. var textureType = texture.type;
  15934. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15935. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15936. return;
  15937. }
  15938. var halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has('EXT_color_buffer_half_float') || capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float'));
  15939. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // Edge and Chrome Mac < 52 (#9513)
  15940. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has('OES_texture_float') || extensions.has('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15941. !halfFloatSupportedByExt) {
  15942. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15943. return;
  15944. }
  15945. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15946. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15947. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15948. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15949. }
  15950. } else {
  15951. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15952. }
  15953. } finally {
  15954. if (restore) {
  15955. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15956. }
  15957. }
  15958. }
  15959. };
  15960. this.copyFramebufferToTexture = function (position, texture, level) {
  15961. if (level === void 0) {
  15962. level = 0;
  15963. }
  15964. var levelScale = Math.pow(2, -level);
  15965. var width = Math.floor(texture.image.width * levelScale);
  15966. var height = Math.floor(texture.image.height * levelScale);
  15967. var glFormat = utils.convert(texture.format);
  15968. textures.setTexture2D(texture, 0);
  15969. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15970. state.unbindTexture();
  15971. };
  15972. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15973. if (level === void 0) {
  15974. level = 0;
  15975. }
  15976. var width = srcTexture.image.width;
  15977. var height = srcTexture.image.height;
  15978. var glFormat = utils.convert(dstTexture.format);
  15979. var glType = utils.convert(dstTexture.type);
  15980. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15981. // parameters, make sure they are correct for the dstTexture
  15982. _gl.pixelStorei(37440, dstTexture.flipY);
  15983. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15984. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15985. if (srcTexture.isDataTexture) {
  15986. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15987. } else {
  15988. if (srcTexture.isCompressedTexture) {
  15989. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15990. } else {
  15991. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15992. }
  15993. } // Generate mipmaps only when copying level 0
  15994. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15995. state.unbindTexture();
  15996. };
  15997. this.copyTextureToTexture3D = function (sourceBox, position, srcTexture, dstTexture, level) {
  15998. if (level === void 0) {
  15999. level = 0;
  16000. }
  16001. if (_this.isWebGL1Renderer) {
  16002. console.warn('THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.');
  16003. return;
  16004. }
  16005. var _srcTexture$image = srcTexture.image,
  16006. width = _srcTexture$image.width,
  16007. height = _srcTexture$image.height,
  16008. data = _srcTexture$image.data;
  16009. var glFormat = utils.convert(dstTexture.format);
  16010. var glType = utils.convert(dstTexture.type);
  16011. var glTarget;
  16012. if (dstTexture.isDataTexture3D) {
  16013. textures.setTexture3D(dstTexture, 0);
  16014. glTarget = 32879;
  16015. } else if (dstTexture.isDataTexture2DArray) {
  16016. textures.setTexture2DArray(dstTexture, 0);
  16017. glTarget = 35866;
  16018. } else {
  16019. console.warn('THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.');
  16020. return;
  16021. }
  16022. _gl.pixelStorei(37440, dstTexture.flipY);
  16023. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  16024. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  16025. var unpackRowLen = _gl.getParameter(3314);
  16026. var unpackImageHeight = _gl.getParameter(32878);
  16027. var unpackSkipPixels = _gl.getParameter(3316);
  16028. var unpackSkipRows = _gl.getParameter(3315);
  16029. var unpackSkipImages = _gl.getParameter(32877);
  16030. _gl.pixelStorei(3314, width);
  16031. _gl.pixelStorei(32878, height);
  16032. _gl.pixelStorei(3316, sourceBox.min.x);
  16033. _gl.pixelStorei(3315, sourceBox.min.y);
  16034. _gl.pixelStorei(32877, sourceBox.min.z);
  16035. _gl.texSubImage3D(glTarget, level, position.x, position.y, position.z, sourceBox.max.x - sourceBox.min.x + 1, sourceBox.max.y - sourceBox.min.y + 1, sourceBox.max.z - sourceBox.min.z + 1, glFormat, glType, data);
  16036. _gl.pixelStorei(3314, unpackRowLen);
  16037. _gl.pixelStorei(32878, unpackImageHeight);
  16038. _gl.pixelStorei(3316, unpackSkipPixels);
  16039. _gl.pixelStorei(3315, unpackSkipRows);
  16040. _gl.pixelStorei(32877, unpackSkipImages); // Generate mipmaps only when copying level 0
  16041. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(glTarget);
  16042. state.unbindTexture();
  16043. };
  16044. this.initTexture = function (texture) {
  16045. textures.setTexture2D(texture, 0);
  16046. state.unbindTexture();
  16047. };
  16048. this.resetState = function () {
  16049. state.reset();
  16050. bindingStates.reset();
  16051. };
  16052. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  16053. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  16054. detail: this
  16055. })); // eslint-disable-line no-undef
  16056. }
  16057. }
  16058. var WebGL1Renderer = /*#__PURE__*/function (_WebGLRenderer) {
  16059. _inheritsLoose(WebGL1Renderer, _WebGLRenderer);
  16060. function WebGL1Renderer() {
  16061. return _WebGLRenderer.apply(this, arguments) || this;
  16062. }
  16063. return WebGL1Renderer;
  16064. }(WebGLRenderer);
  16065. WebGL1Renderer.prototype.isWebGL1Renderer = true;
  16066. var FogExp2 = /*#__PURE__*/function () {
  16067. function FogExp2(color, density) {
  16068. this.name = '';
  16069. this.color = new Color(color);
  16070. this.density = density !== undefined ? density : 0.00025;
  16071. }
  16072. var _proto = FogExp2.prototype;
  16073. _proto.clone = function clone() {
  16074. return new FogExp2(this.color, this.density);
  16075. };
  16076. _proto.toJSON = function toJSON()
  16077. /* meta */
  16078. {
  16079. return {
  16080. type: 'FogExp2',
  16081. color: this.color.getHex(),
  16082. density: this.density
  16083. };
  16084. };
  16085. return FogExp2;
  16086. }();
  16087. FogExp2.prototype.isFogExp2 = true;
  16088. var Fog = /*#__PURE__*/function () {
  16089. function Fog(color, near, far) {
  16090. this.name = '';
  16091. this.color = new Color(color);
  16092. this.near = near !== undefined ? near : 1;
  16093. this.far = far !== undefined ? far : 1000;
  16094. }
  16095. var _proto = Fog.prototype;
  16096. _proto.clone = function clone() {
  16097. return new Fog(this.color, this.near, this.far);
  16098. };
  16099. _proto.toJSON = function toJSON()
  16100. /* meta */
  16101. {
  16102. return {
  16103. type: 'Fog',
  16104. color: this.color.getHex(),
  16105. near: this.near,
  16106. far: this.far
  16107. };
  16108. };
  16109. return Fog;
  16110. }();
  16111. Fog.prototype.isFog = true;
  16112. var Scene = /*#__PURE__*/function (_Object3D) {
  16113. _inheritsLoose(Scene, _Object3D);
  16114. function Scene() {
  16115. var _this;
  16116. _this = _Object3D.call(this) || this;
  16117. _this.type = 'Scene';
  16118. _this.background = null;
  16119. _this.environment = null;
  16120. _this.fog = null;
  16121. _this.overrideMaterial = null;
  16122. _this.autoUpdate = true; // checked by the renderer
  16123. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  16124. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  16125. detail: _assertThisInitialized(_this)
  16126. })); // eslint-disable-line no-undef
  16127. }
  16128. return _this;
  16129. }
  16130. var _proto = Scene.prototype;
  16131. _proto.copy = function copy(source, recursive) {
  16132. _Object3D.prototype.copy.call(this, source, recursive);
  16133. if (source.background !== null) this.background = source.background.clone();
  16134. if (source.environment !== null) this.environment = source.environment.clone();
  16135. if (source.fog !== null) this.fog = source.fog.clone();
  16136. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  16137. this.autoUpdate = source.autoUpdate;
  16138. this.matrixAutoUpdate = source.matrixAutoUpdate;
  16139. return this;
  16140. };
  16141. _proto.toJSON = function toJSON(meta) {
  16142. var data = _Object3D.prototype.toJSON.call(this, meta);
  16143. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  16144. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  16145. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  16146. return data;
  16147. };
  16148. return Scene;
  16149. }(Object3D);
  16150. Scene.prototype.isScene = true;
  16151. function InterleavedBuffer(array, stride) {
  16152. this.array = array;
  16153. this.stride = stride;
  16154. this.count = array !== undefined ? array.length / stride : 0;
  16155. this.usage = StaticDrawUsage;
  16156. this.updateRange = {
  16157. offset: 0,
  16158. count: -1
  16159. };
  16160. this.version = 0;
  16161. this.uuid = MathUtils.generateUUID();
  16162. }
  16163. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  16164. set: function set(value) {
  16165. if (value === true) this.version++;
  16166. }
  16167. });
  16168. Object.assign(InterleavedBuffer.prototype, {
  16169. isInterleavedBuffer: true,
  16170. onUploadCallback: function onUploadCallback() {},
  16171. setUsage: function setUsage(value) {
  16172. this.usage = value;
  16173. return this;
  16174. },
  16175. copy: function copy(source) {
  16176. this.array = new source.array.constructor(source.array);
  16177. this.count = source.count;
  16178. this.stride = source.stride;
  16179. this.usage = source.usage;
  16180. return this;
  16181. },
  16182. copyAt: function copyAt(index1, attribute, index2) {
  16183. index1 *= this.stride;
  16184. index2 *= attribute.stride;
  16185. for (var i = 0, l = this.stride; i < l; i++) {
  16186. this.array[index1 + i] = attribute.array[index2 + i];
  16187. }
  16188. return this;
  16189. },
  16190. set: function set(value, offset) {
  16191. if (offset === void 0) {
  16192. offset = 0;
  16193. }
  16194. this.array.set(value, offset);
  16195. return this;
  16196. },
  16197. clone: function clone(data) {
  16198. if (data.arrayBuffers === undefined) {
  16199. data.arrayBuffers = {};
  16200. }
  16201. if (this.array.buffer._uuid === undefined) {
  16202. this.array.buffer._uuid = MathUtils.generateUUID();
  16203. }
  16204. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16205. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  16206. }
  16207. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  16208. var ib = new InterleavedBuffer(array, this.stride);
  16209. ib.setUsage(this.usage);
  16210. return ib;
  16211. },
  16212. onUpload: function onUpload(callback) {
  16213. this.onUploadCallback = callback;
  16214. return this;
  16215. },
  16216. toJSON: function toJSON(data) {
  16217. if (data.arrayBuffers === undefined) {
  16218. data.arrayBuffers = {};
  16219. } // generate UUID for array buffer if necessary
  16220. if (this.array.buffer._uuid === undefined) {
  16221. this.array.buffer._uuid = MathUtils.generateUUID();
  16222. }
  16223. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16224. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  16225. } //
  16226. return {
  16227. uuid: this.uuid,
  16228. buffer: this.array.buffer._uuid,
  16229. type: this.array.constructor.name,
  16230. stride: this.stride
  16231. };
  16232. }
  16233. });
  16234. var _vector$6 = new Vector3();
  16235. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  16236. this.name = '';
  16237. this.data = interleavedBuffer;
  16238. this.itemSize = itemSize;
  16239. this.offset = offset;
  16240. this.normalized = normalized === true;
  16241. }
  16242. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  16243. count: {
  16244. get: function get() {
  16245. return this.data.count;
  16246. }
  16247. },
  16248. array: {
  16249. get: function get() {
  16250. return this.data.array;
  16251. }
  16252. },
  16253. needsUpdate: {
  16254. set: function set(value) {
  16255. this.data.needsUpdate = value;
  16256. }
  16257. }
  16258. });
  16259. Object.assign(InterleavedBufferAttribute.prototype, {
  16260. isInterleavedBufferAttribute: true,
  16261. applyMatrix4: function applyMatrix4(m) {
  16262. for (var i = 0, l = this.data.count; i < l; i++) {
  16263. _vector$6.x = this.getX(i);
  16264. _vector$6.y = this.getY(i);
  16265. _vector$6.z = this.getZ(i);
  16266. _vector$6.applyMatrix4(m);
  16267. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  16268. }
  16269. return this;
  16270. },
  16271. setX: function setX(index, x) {
  16272. this.data.array[index * this.data.stride + this.offset] = x;
  16273. return this;
  16274. },
  16275. setY: function setY(index, y) {
  16276. this.data.array[index * this.data.stride + this.offset + 1] = y;
  16277. return this;
  16278. },
  16279. setZ: function setZ(index, z) {
  16280. this.data.array[index * this.data.stride + this.offset + 2] = z;
  16281. return this;
  16282. },
  16283. setW: function setW(index, w) {
  16284. this.data.array[index * this.data.stride + this.offset + 3] = w;
  16285. return this;
  16286. },
  16287. getX: function getX(index) {
  16288. return this.data.array[index * this.data.stride + this.offset];
  16289. },
  16290. getY: function getY(index) {
  16291. return this.data.array[index * this.data.stride + this.offset + 1];
  16292. },
  16293. getZ: function getZ(index) {
  16294. return this.data.array[index * this.data.stride + this.offset + 2];
  16295. },
  16296. getW: function getW(index) {
  16297. return this.data.array[index * this.data.stride + this.offset + 3];
  16298. },
  16299. setXY: function setXY(index, x, y) {
  16300. index = index * this.data.stride + this.offset;
  16301. this.data.array[index + 0] = x;
  16302. this.data.array[index + 1] = y;
  16303. return this;
  16304. },
  16305. setXYZ: function setXYZ(index, x, y, z) {
  16306. index = index * this.data.stride + this.offset;
  16307. this.data.array[index + 0] = x;
  16308. this.data.array[index + 1] = y;
  16309. this.data.array[index + 2] = z;
  16310. return this;
  16311. },
  16312. setXYZW: function setXYZW(index, x, y, z, w) {
  16313. index = index * this.data.stride + this.offset;
  16314. this.data.array[index + 0] = x;
  16315. this.data.array[index + 1] = y;
  16316. this.data.array[index + 2] = z;
  16317. this.data.array[index + 3] = w;
  16318. return this;
  16319. },
  16320. clone: function clone(data) {
  16321. if (data === undefined) {
  16322. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  16323. var array = [];
  16324. for (var i = 0; i < this.count; i++) {
  16325. var index = i * this.data.stride + this.offset;
  16326. for (var j = 0; j < this.itemSize; j++) {
  16327. array.push(this.data.array[index + j]);
  16328. }
  16329. }
  16330. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  16331. } else {
  16332. if (data.interleavedBuffers === undefined) {
  16333. data.interleavedBuffers = {};
  16334. }
  16335. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16336. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  16337. }
  16338. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  16339. }
  16340. },
  16341. toJSON: function toJSON(data) {
  16342. if (data === undefined) {
  16343. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  16344. var array = [];
  16345. for (var i = 0; i < this.count; i++) {
  16346. var index = i * this.data.stride + this.offset;
  16347. for (var j = 0; j < this.itemSize; j++) {
  16348. array.push(this.data.array[index + j]);
  16349. }
  16350. } // deinterleave data and save it as an ordinary buffer attribute for now
  16351. return {
  16352. itemSize: this.itemSize,
  16353. type: this.array.constructor.name,
  16354. array: array,
  16355. normalized: this.normalized
  16356. };
  16357. } else {
  16358. // save as true interlaved attribtue
  16359. if (data.interleavedBuffers === undefined) {
  16360. data.interleavedBuffers = {};
  16361. }
  16362. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16363. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  16364. }
  16365. return {
  16366. isInterleavedBufferAttribute: true,
  16367. itemSize: this.itemSize,
  16368. data: this.data.uuid,
  16369. offset: this.offset,
  16370. normalized: this.normalized
  16371. };
  16372. }
  16373. }
  16374. });
  16375. /**
  16376. * parameters = {
  16377. * color: <hex>,
  16378. * map: new THREE.Texture( <Image> ),
  16379. * alphaMap: new THREE.Texture( <Image> ),
  16380. * rotation: <float>,
  16381. * sizeAttenuation: <bool>
  16382. * }
  16383. */
  16384. var SpriteMaterial = /*#__PURE__*/function (_Material) {
  16385. _inheritsLoose(SpriteMaterial, _Material);
  16386. function SpriteMaterial(parameters) {
  16387. var _this;
  16388. _this = _Material.call(this) || this;
  16389. _this.type = 'SpriteMaterial';
  16390. _this.color = new Color(0xffffff);
  16391. _this.map = null;
  16392. _this.alphaMap = null;
  16393. _this.rotation = 0;
  16394. _this.sizeAttenuation = true;
  16395. _this.transparent = true;
  16396. _this.setValues(parameters);
  16397. return _this;
  16398. }
  16399. var _proto = SpriteMaterial.prototype;
  16400. _proto.copy = function copy(source) {
  16401. _Material.prototype.copy.call(this, source);
  16402. this.color.copy(source.color);
  16403. this.map = source.map;
  16404. this.alphaMap = source.alphaMap;
  16405. this.rotation = source.rotation;
  16406. this.sizeAttenuation = source.sizeAttenuation;
  16407. return this;
  16408. };
  16409. return SpriteMaterial;
  16410. }(Material);
  16411. SpriteMaterial.prototype.isSpriteMaterial = true;
  16412. var _geometry;
  16413. var _intersectPoint = /*@__PURE__*/new Vector3();
  16414. var _worldScale = /*@__PURE__*/new Vector3();
  16415. var _mvPosition = /*@__PURE__*/new Vector3();
  16416. var _alignedPosition = /*@__PURE__*/new Vector2();
  16417. var _rotatedPosition = /*@__PURE__*/new Vector2();
  16418. var _viewWorldMatrix = /*@__PURE__*/new Matrix4();
  16419. var _vA$1 = /*@__PURE__*/new Vector3();
  16420. var _vB$1 = /*@__PURE__*/new Vector3();
  16421. var _vC$1 = /*@__PURE__*/new Vector3();
  16422. var _uvA$1 = /*@__PURE__*/new Vector2();
  16423. var _uvB$1 = /*@__PURE__*/new Vector2();
  16424. var _uvC$1 = /*@__PURE__*/new Vector2();
  16425. var Sprite = /*#__PURE__*/function (_Object3D) {
  16426. _inheritsLoose(Sprite, _Object3D);
  16427. function Sprite(material) {
  16428. var _this;
  16429. _this = _Object3D.call(this) || this;
  16430. _this.type = 'Sprite';
  16431. if (_geometry === undefined) {
  16432. _geometry = new BufferGeometry();
  16433. var float32Array = new Float32Array([-0.5, -0.5, 0, 0, 0, 0.5, -0.5, 0, 1, 0, 0.5, 0.5, 0, 1, 1, -0.5, 0.5, 0, 0, 1]);
  16434. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  16435. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  16436. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  16437. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  16438. }
  16439. _this.geometry = _geometry;
  16440. _this.material = material !== undefined ? material : new SpriteMaterial();
  16441. _this.center = new Vector2(0.5, 0.5);
  16442. return _this;
  16443. }
  16444. var _proto = Sprite.prototype;
  16445. _proto.raycast = function raycast(raycaster, intersects) {
  16446. if (raycaster.camera === null) {
  16447. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  16448. }
  16449. _worldScale.setFromMatrixScale(this.matrixWorld);
  16450. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  16451. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  16452. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  16453. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  16454. _worldScale.multiplyScalar(-_mvPosition.z);
  16455. }
  16456. var rotation = this.material.rotation;
  16457. var sin, cos;
  16458. if (rotation !== 0) {
  16459. cos = Math.cos(rotation);
  16460. sin = Math.sin(rotation);
  16461. }
  16462. var center = this.center;
  16463. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16464. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16465. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16466. _uvA$1.set(0, 0);
  16467. _uvB$1.set(1, 0);
  16468. _uvC$1.set(1, 1); // check first triangle
  16469. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  16470. if (intersect === null) {
  16471. // check second triangle
  16472. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16473. _uvB$1.set(0, 1);
  16474. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  16475. if (intersect === null) {
  16476. return;
  16477. }
  16478. }
  16479. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  16480. if (distance < raycaster.near || distance > raycaster.far) return;
  16481. intersects.push({
  16482. distance: distance,
  16483. point: _intersectPoint.clone(),
  16484. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  16485. face: null,
  16486. object: this
  16487. });
  16488. };
  16489. _proto.copy = function copy(source) {
  16490. _Object3D.prototype.copy.call(this, source);
  16491. if (source.center !== undefined) this.center.copy(source.center);
  16492. this.material = source.material;
  16493. return this;
  16494. };
  16495. return Sprite;
  16496. }(Object3D);
  16497. Sprite.prototype.isSprite = true;
  16498. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  16499. // compute position in camera space
  16500. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  16501. if (sin !== undefined) {
  16502. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  16503. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  16504. } else {
  16505. _rotatedPosition.copy(_alignedPosition);
  16506. }
  16507. vertexPosition.copy(mvPosition);
  16508. vertexPosition.x += _rotatedPosition.x;
  16509. vertexPosition.y += _rotatedPosition.y; // transform to world space
  16510. vertexPosition.applyMatrix4(_viewWorldMatrix);
  16511. }
  16512. var _v1$4 = /*@__PURE__*/new Vector3();
  16513. var _v2$2 = /*@__PURE__*/new Vector3();
  16514. var LOD = /*#__PURE__*/function (_Object3D) {
  16515. _inheritsLoose(LOD, _Object3D);
  16516. function LOD() {
  16517. var _this;
  16518. _this = _Object3D.call(this) || this;
  16519. _this._currentLevel = 0;
  16520. _this.type = 'LOD';
  16521. Object.defineProperties(_assertThisInitialized(_this), {
  16522. levels: {
  16523. enumerable: true,
  16524. value: []
  16525. },
  16526. isLOD: {
  16527. value: true
  16528. }
  16529. });
  16530. _this.autoUpdate = true;
  16531. return _this;
  16532. }
  16533. var _proto = LOD.prototype;
  16534. _proto.copy = function copy(source) {
  16535. _Object3D.prototype.copy.call(this, source, false);
  16536. var levels = source.levels;
  16537. for (var i = 0, l = levels.length; i < l; i++) {
  16538. var level = levels[i];
  16539. this.addLevel(level.object.clone(), level.distance);
  16540. }
  16541. this.autoUpdate = source.autoUpdate;
  16542. return this;
  16543. };
  16544. _proto.addLevel = function addLevel(object, distance) {
  16545. if (distance === void 0) {
  16546. distance = 0;
  16547. }
  16548. distance = Math.abs(distance);
  16549. var levels = this.levels;
  16550. var l;
  16551. for (l = 0; l < levels.length; l++) {
  16552. if (distance < levels[l].distance) {
  16553. break;
  16554. }
  16555. }
  16556. levels.splice(l, 0, {
  16557. distance: distance,
  16558. object: object
  16559. });
  16560. this.add(object);
  16561. return this;
  16562. };
  16563. _proto.getCurrentLevel = function getCurrentLevel() {
  16564. return this._currentLevel;
  16565. };
  16566. _proto.getObjectForDistance = function getObjectForDistance(distance) {
  16567. var levels = this.levels;
  16568. if (levels.length > 0) {
  16569. var i, l;
  16570. for (i = 1, l = levels.length; i < l; i++) {
  16571. if (distance < levels[i].distance) {
  16572. break;
  16573. }
  16574. }
  16575. return levels[i - 1].object;
  16576. }
  16577. return null;
  16578. };
  16579. _proto.raycast = function raycast(raycaster, intersects) {
  16580. var levels = this.levels;
  16581. if (levels.length > 0) {
  16582. _v1$4.setFromMatrixPosition(this.matrixWorld);
  16583. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  16584. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  16585. }
  16586. };
  16587. _proto.update = function update(camera) {
  16588. var levels = this.levels;
  16589. if (levels.length > 1) {
  16590. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  16591. _v2$2.setFromMatrixPosition(this.matrixWorld);
  16592. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  16593. levels[0].object.visible = true;
  16594. var i, l;
  16595. for (i = 1, l = levels.length; i < l; i++) {
  16596. if (distance >= levels[i].distance) {
  16597. levels[i - 1].object.visible = false;
  16598. levels[i].object.visible = true;
  16599. } else {
  16600. break;
  16601. }
  16602. }
  16603. this._currentLevel = i - 1;
  16604. for (; i < l; i++) {
  16605. levels[i].object.visible = false;
  16606. }
  16607. }
  16608. };
  16609. _proto.toJSON = function toJSON(meta) {
  16610. var data = _Object3D.prototype.toJSON.call(this, meta);
  16611. if (this.autoUpdate === false) data.object.autoUpdate = false;
  16612. data.object.levels = [];
  16613. var levels = this.levels;
  16614. for (var i = 0, l = levels.length; i < l; i++) {
  16615. var level = levels[i];
  16616. data.object.levels.push({
  16617. object: level.object.uuid,
  16618. distance: level.distance
  16619. });
  16620. }
  16621. return data;
  16622. };
  16623. return LOD;
  16624. }(Object3D);
  16625. var _basePosition = new Vector3();
  16626. var _skinIndex = new Vector4();
  16627. var _skinWeight = new Vector4();
  16628. var _vector$7 = new Vector3();
  16629. var _matrix$1 = new Matrix4();
  16630. function SkinnedMesh(geometry, material) {
  16631. Mesh.call(this, geometry, material);
  16632. this.type = 'SkinnedMesh';
  16633. this.bindMode = 'attached';
  16634. this.bindMatrix = new Matrix4();
  16635. this.bindMatrixInverse = new Matrix4();
  16636. }
  16637. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16638. constructor: SkinnedMesh,
  16639. isSkinnedMesh: true,
  16640. copy: function copy(source) {
  16641. Mesh.prototype.copy.call(this, source);
  16642. this.bindMode = source.bindMode;
  16643. this.bindMatrix.copy(source.bindMatrix);
  16644. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  16645. this.skeleton = source.skeleton;
  16646. return this;
  16647. },
  16648. bind: function bind(skeleton, bindMatrix) {
  16649. this.skeleton = skeleton;
  16650. if (bindMatrix === undefined) {
  16651. this.updateMatrixWorld(true);
  16652. this.skeleton.calculateInverses();
  16653. bindMatrix = this.matrixWorld;
  16654. }
  16655. this.bindMatrix.copy(bindMatrix);
  16656. this.bindMatrixInverse.copy(bindMatrix).invert();
  16657. },
  16658. pose: function pose() {
  16659. this.skeleton.pose();
  16660. },
  16661. normalizeSkinWeights: function normalizeSkinWeights() {
  16662. var vector = new Vector4();
  16663. var skinWeight = this.geometry.attributes.skinWeight;
  16664. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16665. vector.x = skinWeight.getX(i);
  16666. vector.y = skinWeight.getY(i);
  16667. vector.z = skinWeight.getZ(i);
  16668. vector.w = skinWeight.getW(i);
  16669. var scale = 1.0 / vector.manhattanLength();
  16670. if (scale !== Infinity) {
  16671. vector.multiplyScalar(scale);
  16672. } else {
  16673. vector.set(1, 0, 0, 0); // do something reasonable
  16674. }
  16675. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16676. }
  16677. },
  16678. updateMatrixWorld: function updateMatrixWorld(force) {
  16679. Mesh.prototype.updateMatrixWorld.call(this, force);
  16680. if (this.bindMode === 'attached') {
  16681. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16682. } else if (this.bindMode === 'detached') {
  16683. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16684. } else {
  16685. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16686. }
  16687. },
  16688. boneTransform: function boneTransform(index, target) {
  16689. var skeleton = this.skeleton;
  16690. var geometry = this.geometry;
  16691. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16692. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16693. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16694. target.set(0, 0, 0);
  16695. for (var i = 0; i < 4; i++) {
  16696. var weight = _skinWeight.getComponent(i);
  16697. if (weight !== 0) {
  16698. var boneIndex = _skinIndex.getComponent(i);
  16699. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16700. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16701. }
  16702. }
  16703. return target.applyMatrix4(this.bindMatrixInverse);
  16704. }
  16705. });
  16706. function Bone() {
  16707. Object3D.call(this);
  16708. this.type = 'Bone';
  16709. }
  16710. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16711. constructor: Bone,
  16712. isBone: true
  16713. });
  16714. var _offsetMatrix = /*@__PURE__*/new Matrix4();
  16715. var _identityMatrix = /*@__PURE__*/new Matrix4();
  16716. var Skeleton = /*#__PURE__*/function () {
  16717. function Skeleton(bones, boneInverses) {
  16718. if (bones === void 0) {
  16719. bones = [];
  16720. }
  16721. if (boneInverses === void 0) {
  16722. boneInverses = [];
  16723. }
  16724. this.uuid = MathUtils.generateUUID();
  16725. this.bones = bones.slice(0);
  16726. this.boneInverses = boneInverses;
  16727. this.boneMatrices = null;
  16728. this.boneTexture = null;
  16729. this.boneTextureSize = 0;
  16730. this.frame = -1;
  16731. this.init();
  16732. }
  16733. var _proto = Skeleton.prototype;
  16734. _proto.init = function init() {
  16735. var bones = this.bones;
  16736. var boneInverses = this.boneInverses;
  16737. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16738. if (boneInverses.length === 0) {
  16739. this.calculateInverses();
  16740. } else {
  16741. // handle special case
  16742. if (bones.length !== boneInverses.length) {
  16743. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16744. this.boneInverses = [];
  16745. for (var i = 0, il = this.bones.length; i < il; i++) {
  16746. this.boneInverses.push(new Matrix4());
  16747. }
  16748. }
  16749. }
  16750. };
  16751. _proto.calculateInverses = function calculateInverses() {
  16752. this.boneInverses.length = 0;
  16753. for (var i = 0, il = this.bones.length; i < il; i++) {
  16754. var inverse = new Matrix4();
  16755. if (this.bones[i]) {
  16756. inverse.copy(this.bones[i].matrixWorld).invert();
  16757. }
  16758. this.boneInverses.push(inverse);
  16759. }
  16760. };
  16761. _proto.pose = function pose() {
  16762. // recover the bind-time world matrices
  16763. for (var i = 0, il = this.bones.length; i < il; i++) {
  16764. var bone = this.bones[i];
  16765. if (bone) {
  16766. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16767. }
  16768. } // compute the local matrices, positions, rotations and scales
  16769. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16770. var _bone = this.bones[_i];
  16771. if (_bone) {
  16772. if (_bone.parent && _bone.parent.isBone) {
  16773. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16774. _bone.matrix.multiply(_bone.matrixWorld);
  16775. } else {
  16776. _bone.matrix.copy(_bone.matrixWorld);
  16777. }
  16778. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16779. }
  16780. }
  16781. };
  16782. _proto.update = function update() {
  16783. var bones = this.bones;
  16784. var boneInverses = this.boneInverses;
  16785. var boneMatrices = this.boneMatrices;
  16786. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16787. for (var i = 0, il = bones.length; i < il; i++) {
  16788. // compute the offset between the current and the original transform
  16789. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16790. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16791. _offsetMatrix.toArray(boneMatrices, i * 16);
  16792. }
  16793. if (boneTexture !== null) {
  16794. boneTexture.needsUpdate = true;
  16795. }
  16796. };
  16797. _proto.clone = function clone() {
  16798. return new Skeleton(this.bones, this.boneInverses);
  16799. };
  16800. _proto.getBoneByName = function getBoneByName(name) {
  16801. for (var i = 0, il = this.bones.length; i < il; i++) {
  16802. var bone = this.bones[i];
  16803. if (bone.name === name) {
  16804. return bone;
  16805. }
  16806. }
  16807. return undefined;
  16808. };
  16809. _proto.dispose = function dispose() {
  16810. if (this.boneTexture !== null) {
  16811. this.boneTexture.dispose();
  16812. this.boneTexture = null;
  16813. }
  16814. };
  16815. _proto.fromJSON = function fromJSON(json, bones) {
  16816. this.uuid = json.uuid;
  16817. for (var i = 0, l = json.bones.length; i < l; i++) {
  16818. var uuid = json.bones[i];
  16819. var bone = bones[uuid];
  16820. if (bone === undefined) {
  16821. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16822. bone = new Bone();
  16823. }
  16824. this.bones.push(bone);
  16825. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16826. }
  16827. this.init();
  16828. return this;
  16829. };
  16830. _proto.toJSON = function toJSON() {
  16831. var data = {
  16832. metadata: {
  16833. version: 4.5,
  16834. type: 'Skeleton',
  16835. generator: 'Skeleton.toJSON'
  16836. },
  16837. bones: [],
  16838. boneInverses: []
  16839. };
  16840. data.uuid = this.uuid;
  16841. var bones = this.bones;
  16842. var boneInverses = this.boneInverses;
  16843. for (var i = 0, l = bones.length; i < l; i++) {
  16844. var bone = bones[i];
  16845. data.bones.push(bone.uuid);
  16846. var boneInverse = boneInverses[i];
  16847. data.boneInverses.push(boneInverse.toArray());
  16848. }
  16849. return data;
  16850. };
  16851. return Skeleton;
  16852. }();
  16853. var _instanceLocalMatrix = new Matrix4();
  16854. var _instanceWorldMatrix = new Matrix4();
  16855. var _instanceIntersects = [];
  16856. var _mesh = new Mesh();
  16857. function InstancedMesh(geometry, material, count) {
  16858. Mesh.call(this, geometry, material);
  16859. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16860. this.instanceColor = null;
  16861. this.count = count;
  16862. this.frustumCulled = false;
  16863. }
  16864. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16865. constructor: InstancedMesh,
  16866. isInstancedMesh: true,
  16867. copy: function copy(source) {
  16868. Mesh.prototype.copy.call(this, source);
  16869. this.instanceMatrix.copy(source.instanceMatrix);
  16870. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16871. this.count = source.count;
  16872. return this;
  16873. },
  16874. getColorAt: function getColorAt(index, color) {
  16875. color.fromArray(this.instanceColor.array, index * 3);
  16876. },
  16877. getMatrixAt: function getMatrixAt(index, matrix) {
  16878. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16879. },
  16880. raycast: function raycast(raycaster, intersects) {
  16881. var matrixWorld = this.matrixWorld;
  16882. var raycastTimes = this.count;
  16883. _mesh.geometry = this.geometry;
  16884. _mesh.material = this.material;
  16885. if (_mesh.material === undefined) return;
  16886. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16887. // calculate the world matrix for each instance
  16888. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16889. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16890. _mesh.matrixWorld = _instanceWorldMatrix;
  16891. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16892. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16893. var intersect = _instanceIntersects[i];
  16894. intersect.instanceId = instanceId;
  16895. intersect.object = this;
  16896. intersects.push(intersect);
  16897. }
  16898. _instanceIntersects.length = 0;
  16899. }
  16900. },
  16901. setColorAt: function setColorAt(index, color) {
  16902. if (this.instanceColor === null) {
  16903. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16904. }
  16905. color.toArray(this.instanceColor.array, index * 3);
  16906. },
  16907. setMatrixAt: function setMatrixAt(index, matrix) {
  16908. matrix.toArray(this.instanceMatrix.array, index * 16);
  16909. },
  16910. updateMorphTargets: function updateMorphTargets() {},
  16911. dispose: function dispose() {
  16912. this.dispatchEvent({
  16913. type: 'dispose'
  16914. });
  16915. }
  16916. });
  16917. /**
  16918. * parameters = {
  16919. * color: <hex>,
  16920. * opacity: <float>,
  16921. *
  16922. * linewidth: <float>,
  16923. * linecap: "round",
  16924. * linejoin: "round"
  16925. * }
  16926. */
  16927. var LineBasicMaterial = /*#__PURE__*/function (_Material) {
  16928. _inheritsLoose(LineBasicMaterial, _Material);
  16929. function LineBasicMaterial(parameters) {
  16930. var _this;
  16931. _this = _Material.call(this) || this;
  16932. _this.type = 'LineBasicMaterial';
  16933. _this.color = new Color(0xffffff);
  16934. _this.linewidth = 1;
  16935. _this.linecap = 'round';
  16936. _this.linejoin = 'round';
  16937. _this.morphTargets = false;
  16938. _this.setValues(parameters);
  16939. return _this;
  16940. }
  16941. var _proto = LineBasicMaterial.prototype;
  16942. _proto.copy = function copy(source) {
  16943. _Material.prototype.copy.call(this, source);
  16944. this.color.copy(source.color);
  16945. this.linewidth = source.linewidth;
  16946. this.linecap = source.linecap;
  16947. this.linejoin = source.linejoin;
  16948. this.morphTargets = source.morphTargets;
  16949. return this;
  16950. };
  16951. return LineBasicMaterial;
  16952. }(Material);
  16953. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16954. var _start = new Vector3();
  16955. var _end = new Vector3();
  16956. var _inverseMatrix$1 = new Matrix4();
  16957. var _ray$1 = new Ray();
  16958. var _sphere$2 = new Sphere();
  16959. function Line(geometry, material) {
  16960. if (geometry === void 0) {
  16961. geometry = new BufferGeometry();
  16962. }
  16963. if (material === void 0) {
  16964. material = new LineBasicMaterial();
  16965. }
  16966. Object3D.call(this);
  16967. this.type = 'Line';
  16968. this.geometry = geometry;
  16969. this.material = material;
  16970. this.updateMorphTargets();
  16971. }
  16972. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16973. constructor: Line,
  16974. isLine: true,
  16975. copy: function copy(source) {
  16976. Object3D.prototype.copy.call(this, source);
  16977. this.material = source.material;
  16978. this.geometry = source.geometry;
  16979. return this;
  16980. },
  16981. computeLineDistances: function computeLineDistances() {
  16982. var geometry = this.geometry;
  16983. if (geometry.isBufferGeometry) {
  16984. // we assume non-indexed geometry
  16985. if (geometry.index === null) {
  16986. var positionAttribute = geometry.attributes.position;
  16987. var lineDistances = [0];
  16988. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16989. _start.fromBufferAttribute(positionAttribute, i - 1);
  16990. _end.fromBufferAttribute(positionAttribute, i);
  16991. lineDistances[i] = lineDistances[i - 1];
  16992. lineDistances[i] += _start.distanceTo(_end);
  16993. }
  16994. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16995. } else {
  16996. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16997. }
  16998. } else if (geometry.isGeometry) {
  16999. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17000. }
  17001. return this;
  17002. },
  17003. raycast: function raycast(raycaster, intersects) {
  17004. var geometry = this.geometry;
  17005. var matrixWorld = this.matrixWorld;
  17006. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  17007. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17008. _sphere$2.copy(geometry.boundingSphere);
  17009. _sphere$2.applyMatrix4(matrixWorld);
  17010. _sphere$2.radius += threshold;
  17011. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  17012. _inverseMatrix$1.copy(matrixWorld).invert();
  17013. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  17014. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17015. var localThresholdSq = localThreshold * localThreshold;
  17016. var vStart = new Vector3();
  17017. var vEnd = new Vector3();
  17018. var interSegment = new Vector3();
  17019. var interRay = new Vector3();
  17020. var step = this.isLineSegments ? 2 : 1;
  17021. if (geometry.isBufferGeometry) {
  17022. var index = geometry.index;
  17023. var attributes = geometry.attributes;
  17024. var positionAttribute = attributes.position;
  17025. if (index !== null) {
  17026. var indices = index.array;
  17027. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  17028. var a = indices[i];
  17029. var b = indices[i + 1];
  17030. vStart.fromBufferAttribute(positionAttribute, a);
  17031. vEnd.fromBufferAttribute(positionAttribute, b);
  17032. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  17033. if (distSq > localThresholdSq) continue;
  17034. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  17035. var distance = raycaster.ray.origin.distanceTo(interRay);
  17036. if (distance < raycaster.near || distance > raycaster.far) continue;
  17037. intersects.push({
  17038. distance: distance,
  17039. // What do we want? intersection point on the ray or on the segment??
  17040. // point: raycaster.ray.at( distance ),
  17041. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  17042. index: i,
  17043. face: null,
  17044. faceIndex: null,
  17045. object: this
  17046. });
  17047. }
  17048. } else {
  17049. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  17050. vStart.fromBufferAttribute(positionAttribute, _i);
  17051. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  17052. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  17053. if (_distSq > localThresholdSq) continue;
  17054. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  17055. var _distance = raycaster.ray.origin.distanceTo(interRay);
  17056. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  17057. intersects.push({
  17058. distance: _distance,
  17059. // What do we want? intersection point on the ray or on the segment??
  17060. // point: raycaster.ray.at( distance ),
  17061. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  17062. index: _i,
  17063. face: null,
  17064. faceIndex: null,
  17065. object: this
  17066. });
  17067. }
  17068. }
  17069. } else if (geometry.isGeometry) {
  17070. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17071. }
  17072. },
  17073. updateMorphTargets: function updateMorphTargets() {
  17074. var geometry = this.geometry;
  17075. if (geometry.isBufferGeometry) {
  17076. var morphAttributes = geometry.morphAttributes;
  17077. var keys = Object.keys(morphAttributes);
  17078. if (keys.length > 0) {
  17079. var morphAttribute = morphAttributes[keys[0]];
  17080. if (morphAttribute !== undefined) {
  17081. this.morphTargetInfluences = [];
  17082. this.morphTargetDictionary = {};
  17083. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17084. var name = morphAttribute[m].name || String(m);
  17085. this.morphTargetInfluences.push(0);
  17086. this.morphTargetDictionary[name] = m;
  17087. }
  17088. }
  17089. }
  17090. } else {
  17091. var morphTargets = geometry.morphTargets;
  17092. if (morphTargets !== undefined && morphTargets.length > 0) {
  17093. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17094. }
  17095. }
  17096. }
  17097. });
  17098. var _start$1 = new Vector3();
  17099. var _end$1 = new Vector3();
  17100. function LineSegments(geometry, material) {
  17101. Line.call(this, geometry, material);
  17102. this.type = 'LineSegments';
  17103. }
  17104. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  17105. constructor: LineSegments,
  17106. isLineSegments: true,
  17107. computeLineDistances: function computeLineDistances() {
  17108. var geometry = this.geometry;
  17109. if (geometry.isBufferGeometry) {
  17110. // we assume non-indexed geometry
  17111. if (geometry.index === null) {
  17112. var positionAttribute = geometry.attributes.position;
  17113. var lineDistances = [];
  17114. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  17115. _start$1.fromBufferAttribute(positionAttribute, i);
  17116. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  17117. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  17118. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  17119. }
  17120. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  17121. } else {
  17122. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  17123. }
  17124. } else if (geometry.isGeometry) {
  17125. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17126. }
  17127. return this;
  17128. }
  17129. });
  17130. var LineLoop = /*#__PURE__*/function (_Line) {
  17131. _inheritsLoose(LineLoop, _Line);
  17132. function LineLoop(geometry, material) {
  17133. var _this;
  17134. _this = _Line.call(this, geometry, material) || this;
  17135. _this.type = 'LineLoop';
  17136. return _this;
  17137. }
  17138. return LineLoop;
  17139. }(Line);
  17140. LineLoop.prototype.isLineLoop = true;
  17141. /**
  17142. * parameters = {
  17143. * color: <hex>,
  17144. * opacity: <float>,
  17145. * map: new THREE.Texture( <Image> ),
  17146. * alphaMap: new THREE.Texture( <Image> ),
  17147. *
  17148. * size: <float>,
  17149. * sizeAttenuation: <bool>
  17150. *
  17151. * morphTargets: <bool>
  17152. * }
  17153. */
  17154. var PointsMaterial = /*#__PURE__*/function (_Material) {
  17155. _inheritsLoose(PointsMaterial, _Material);
  17156. function PointsMaterial(parameters) {
  17157. var _this;
  17158. _this = _Material.call(this) || this;
  17159. _this.type = 'PointsMaterial';
  17160. _this.color = new Color(0xffffff);
  17161. _this.map = null;
  17162. _this.alphaMap = null;
  17163. _this.size = 1;
  17164. _this.sizeAttenuation = true;
  17165. _this.morphTargets = false;
  17166. _this.setValues(parameters);
  17167. return _this;
  17168. }
  17169. var _proto = PointsMaterial.prototype;
  17170. _proto.copy = function copy(source) {
  17171. _Material.prototype.copy.call(this, source);
  17172. this.color.copy(source.color);
  17173. this.map = source.map;
  17174. this.alphaMap = source.alphaMap;
  17175. this.size = source.size;
  17176. this.sizeAttenuation = source.sizeAttenuation;
  17177. this.morphTargets = source.morphTargets;
  17178. return this;
  17179. };
  17180. return PointsMaterial;
  17181. }(Material);
  17182. PointsMaterial.prototype.isPointsMaterial = true;
  17183. var _inverseMatrix$2 = new Matrix4();
  17184. var _ray$2 = new Ray();
  17185. var _sphere$3 = new Sphere();
  17186. var _position$1 = new Vector3();
  17187. function Points(geometry, material) {
  17188. if (geometry === void 0) {
  17189. geometry = new BufferGeometry();
  17190. }
  17191. if (material === void 0) {
  17192. material = new PointsMaterial();
  17193. }
  17194. Object3D.call(this);
  17195. this.type = 'Points';
  17196. this.geometry = geometry;
  17197. this.material = material;
  17198. this.updateMorphTargets();
  17199. }
  17200. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  17201. constructor: Points,
  17202. isPoints: true,
  17203. copy: function copy(source) {
  17204. Object3D.prototype.copy.call(this, source);
  17205. this.material = source.material;
  17206. this.geometry = source.geometry;
  17207. return this;
  17208. },
  17209. raycast: function raycast(raycaster, intersects) {
  17210. var geometry = this.geometry;
  17211. var matrixWorld = this.matrixWorld;
  17212. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  17213. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17214. _sphere$3.copy(geometry.boundingSphere);
  17215. _sphere$3.applyMatrix4(matrixWorld);
  17216. _sphere$3.radius += threshold;
  17217. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  17218. _inverseMatrix$2.copy(matrixWorld).invert();
  17219. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  17220. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17221. var localThresholdSq = localThreshold * localThreshold;
  17222. if (geometry.isBufferGeometry) {
  17223. var index = geometry.index;
  17224. var attributes = geometry.attributes;
  17225. var positionAttribute = attributes.position;
  17226. if (index !== null) {
  17227. var indices = index.array;
  17228. for (var i = 0, il = indices.length; i < il; i++) {
  17229. var a = indices[i];
  17230. _position$1.fromBufferAttribute(positionAttribute, a);
  17231. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17232. }
  17233. } else {
  17234. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  17235. _position$1.fromBufferAttribute(positionAttribute, _i);
  17236. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17237. }
  17238. }
  17239. } else {
  17240. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17241. }
  17242. },
  17243. updateMorphTargets: function updateMorphTargets() {
  17244. var geometry = this.geometry;
  17245. if (geometry.isBufferGeometry) {
  17246. var morphAttributes = geometry.morphAttributes;
  17247. var keys = Object.keys(morphAttributes);
  17248. if (keys.length > 0) {
  17249. var morphAttribute = morphAttributes[keys[0]];
  17250. if (morphAttribute !== undefined) {
  17251. this.morphTargetInfluences = [];
  17252. this.morphTargetDictionary = {};
  17253. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17254. var name = morphAttribute[m].name || String(m);
  17255. this.morphTargetInfluences.push(0);
  17256. this.morphTargetDictionary[name] = m;
  17257. }
  17258. }
  17259. }
  17260. } else {
  17261. var morphTargets = geometry.morphTargets;
  17262. if (morphTargets !== undefined && morphTargets.length > 0) {
  17263. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17264. }
  17265. }
  17266. }
  17267. });
  17268. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  17269. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  17270. if (rayPointDistanceSq < localThresholdSq) {
  17271. var intersectPoint = new Vector3();
  17272. _ray$2.closestPointToPoint(point, intersectPoint);
  17273. intersectPoint.applyMatrix4(matrixWorld);
  17274. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  17275. if (distance < raycaster.near || distance > raycaster.far) return;
  17276. intersects.push({
  17277. distance: distance,
  17278. distanceToRay: Math.sqrt(rayPointDistanceSq),
  17279. point: intersectPoint,
  17280. index: index,
  17281. face: null,
  17282. object: object
  17283. });
  17284. }
  17285. }
  17286. var VideoTexture = /*#__PURE__*/function (_Texture) {
  17287. _inheritsLoose(VideoTexture, _Texture);
  17288. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17289. var _this;
  17290. _this = _Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) || this;
  17291. _this.format = format !== undefined ? format : RGBFormat;
  17292. _this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17293. _this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17294. _this.generateMipmaps = false;
  17295. var scope = _assertThisInitialized(_this);
  17296. function updateVideo() {
  17297. scope.needsUpdate = true;
  17298. video.requestVideoFrameCallback(updateVideo);
  17299. }
  17300. if ('requestVideoFrameCallback' in video) {
  17301. video.requestVideoFrameCallback(updateVideo);
  17302. }
  17303. return _this;
  17304. }
  17305. var _proto = VideoTexture.prototype;
  17306. _proto.clone = function clone() {
  17307. return new this.constructor(this.image).copy(this);
  17308. };
  17309. _proto.update = function update() {
  17310. var video = this.image;
  17311. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  17312. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  17313. this.needsUpdate = true;
  17314. }
  17315. };
  17316. return VideoTexture;
  17317. }(Texture);
  17318. VideoTexture.prototype.isVideoTexture = true;
  17319. var CompressedTexture = /*#__PURE__*/function (_Texture) {
  17320. _inheritsLoose(CompressedTexture, _Texture);
  17321. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  17322. var _this;
  17323. _this = _Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) || this;
  17324. _this.image = {
  17325. width: width,
  17326. height: height
  17327. };
  17328. _this.mipmaps = mipmaps; // no flipping for cube textures
  17329. // (also flipping doesn't work for compressed textures )
  17330. _this.flipY = false; // can't generate mipmaps for compressed textures
  17331. // mips must be embedded in DDS files
  17332. _this.generateMipmaps = false;
  17333. return _this;
  17334. }
  17335. return CompressedTexture;
  17336. }(Texture);
  17337. CompressedTexture.prototype.isCompressedTexture = true;
  17338. var CanvasTexture = /*#__PURE__*/function (_Texture) {
  17339. _inheritsLoose(CanvasTexture, _Texture);
  17340. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17341. var _this;
  17342. _this = _Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) || this;
  17343. _this.needsUpdate = true;
  17344. return _this;
  17345. }
  17346. return CanvasTexture;
  17347. }(Texture);
  17348. CanvasTexture.prototype.isCanvasTexture = true;
  17349. var DepthTexture = /*#__PURE__*/function (_Texture) {
  17350. _inheritsLoose(DepthTexture, _Texture);
  17351. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  17352. var _this;
  17353. format = format !== undefined ? format : DepthFormat;
  17354. if (format !== DepthFormat && format !== DepthStencilFormat) {
  17355. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  17356. }
  17357. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  17358. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  17359. _this = _Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) || this;
  17360. _this.image = {
  17361. width: width,
  17362. height: height
  17363. };
  17364. _this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17365. _this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17366. _this.flipY = false;
  17367. _this.generateMipmaps = false;
  17368. return _this;
  17369. }
  17370. return DepthTexture;
  17371. }(Texture);
  17372. DepthTexture.prototype.isDepthTexture = true;
  17373. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17374. _inheritsLoose(CircleGeometry, _BufferGeometry);
  17375. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17376. var _this;
  17377. if (radius === void 0) {
  17378. radius = 1;
  17379. }
  17380. if (segments === void 0) {
  17381. segments = 8;
  17382. }
  17383. if (thetaStart === void 0) {
  17384. thetaStart = 0;
  17385. }
  17386. if (thetaLength === void 0) {
  17387. thetaLength = Math.PI * 2;
  17388. }
  17389. _this = _BufferGeometry.call(this) || this;
  17390. _this.type = 'CircleGeometry';
  17391. _this.parameters = {
  17392. radius: radius,
  17393. segments: segments,
  17394. thetaStart: thetaStart,
  17395. thetaLength: thetaLength
  17396. };
  17397. segments = Math.max(3, segments); // buffers
  17398. var indices = [];
  17399. var vertices = [];
  17400. var normals = [];
  17401. var uvs = []; // helper variables
  17402. var vertex = new Vector3();
  17403. var uv = new Vector2(); // center point
  17404. vertices.push(0, 0, 0);
  17405. normals.push(0, 0, 1);
  17406. uvs.push(0.5, 0.5);
  17407. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17408. var segment = thetaStart + s / segments * thetaLength; // vertex
  17409. vertex.x = radius * Math.cos(segment);
  17410. vertex.y = radius * Math.sin(segment);
  17411. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17412. normals.push(0, 0, 1); // uvs
  17413. uv.x = (vertices[i] / radius + 1) / 2;
  17414. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17415. uvs.push(uv.x, uv.y);
  17416. } // indices
  17417. for (var _i = 1; _i <= segments; _i++) {
  17418. indices.push(_i, _i + 1, 0);
  17419. } // build geometry
  17420. _this.setIndex(indices);
  17421. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17422. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17423. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17424. return _this;
  17425. }
  17426. return CircleGeometry;
  17427. }(BufferGeometry);
  17428. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17429. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  17430. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17431. var _this;
  17432. if (radiusTop === void 0) {
  17433. radiusTop = 1;
  17434. }
  17435. if (radiusBottom === void 0) {
  17436. radiusBottom = 1;
  17437. }
  17438. if (height === void 0) {
  17439. height = 1;
  17440. }
  17441. if (radialSegments === void 0) {
  17442. radialSegments = 8;
  17443. }
  17444. if (heightSegments === void 0) {
  17445. heightSegments = 1;
  17446. }
  17447. if (openEnded === void 0) {
  17448. openEnded = false;
  17449. }
  17450. if (thetaStart === void 0) {
  17451. thetaStart = 0;
  17452. }
  17453. if (thetaLength === void 0) {
  17454. thetaLength = Math.PI * 2;
  17455. }
  17456. _this = _BufferGeometry.call(this) || this;
  17457. _this.type = 'CylinderGeometry';
  17458. _this.parameters = {
  17459. radiusTop: radiusTop,
  17460. radiusBottom: radiusBottom,
  17461. height: height,
  17462. radialSegments: radialSegments,
  17463. heightSegments: heightSegments,
  17464. openEnded: openEnded,
  17465. thetaStart: thetaStart,
  17466. thetaLength: thetaLength
  17467. };
  17468. var scope = _assertThisInitialized(_this);
  17469. radialSegments = Math.floor(radialSegments);
  17470. heightSegments = Math.floor(heightSegments); // buffers
  17471. var indices = [];
  17472. var vertices = [];
  17473. var normals = [];
  17474. var uvs = []; // helper variables
  17475. var index = 0;
  17476. var indexArray = [];
  17477. var halfHeight = height / 2;
  17478. var groupStart = 0; // generate geometry
  17479. generateTorso();
  17480. if (openEnded === false) {
  17481. if (radiusTop > 0) generateCap(true);
  17482. if (radiusBottom > 0) generateCap(false);
  17483. } // build geometry
  17484. _this.setIndex(indices);
  17485. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17486. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17487. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17488. function generateTorso() {
  17489. var normal = new Vector3();
  17490. var vertex = new Vector3();
  17491. var groupCount = 0; // this will be used to calculate the normal
  17492. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17493. for (var y = 0; y <= heightSegments; y++) {
  17494. var indexRow = [];
  17495. var v = y / heightSegments; // calculate the radius of the current row
  17496. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17497. for (var x = 0; x <= radialSegments; x++) {
  17498. var u = x / radialSegments;
  17499. var theta = u * thetaLength + thetaStart;
  17500. var sinTheta = Math.sin(theta);
  17501. var cosTheta = Math.cos(theta); // vertex
  17502. vertex.x = radius * sinTheta;
  17503. vertex.y = -v * height + halfHeight;
  17504. vertex.z = radius * cosTheta;
  17505. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17506. normal.set(sinTheta, slope, cosTheta).normalize();
  17507. normals.push(normal.x, normal.y, normal.z); // uv
  17508. uvs.push(u, 1 - v); // save index of vertex in respective row
  17509. indexRow.push(index++);
  17510. } // now save vertices of the row in our index array
  17511. indexArray.push(indexRow);
  17512. } // generate indices
  17513. for (var _x = 0; _x < radialSegments; _x++) {
  17514. for (var _y = 0; _y < heightSegments; _y++) {
  17515. // we use the index array to access the correct indices
  17516. var a = indexArray[_y][_x];
  17517. var b = indexArray[_y + 1][_x];
  17518. var c = indexArray[_y + 1][_x + 1];
  17519. var d = indexArray[_y][_x + 1]; // faces
  17520. indices.push(a, b, d);
  17521. indices.push(b, c, d); // update group counter
  17522. groupCount += 6;
  17523. }
  17524. } // add a group to the geometry. this will ensure multi material support
  17525. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17526. groupStart += groupCount;
  17527. }
  17528. function generateCap(top) {
  17529. // save the index of the first center vertex
  17530. var centerIndexStart = index;
  17531. var uv = new Vector2();
  17532. var vertex = new Vector3();
  17533. var groupCount = 0;
  17534. var radius = top === true ? radiusTop : radiusBottom;
  17535. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17536. // because the geometry needs one set of uvs per face,
  17537. // we must generate a center vertex per face/segment
  17538. for (var x = 1; x <= radialSegments; x++) {
  17539. // vertex
  17540. vertices.push(0, halfHeight * sign, 0); // normal
  17541. normals.push(0, sign, 0); // uv
  17542. uvs.push(0.5, 0.5); // increase index
  17543. index++;
  17544. } // save the index of the last center vertex
  17545. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17546. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17547. var u = _x2 / radialSegments;
  17548. var theta = u * thetaLength + thetaStart;
  17549. var cosTheta = Math.cos(theta);
  17550. var sinTheta = Math.sin(theta); // vertex
  17551. vertex.x = radius * sinTheta;
  17552. vertex.y = halfHeight * sign;
  17553. vertex.z = radius * cosTheta;
  17554. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17555. normals.push(0, sign, 0); // uv
  17556. uv.x = cosTheta * 0.5 + 0.5;
  17557. uv.y = sinTheta * 0.5 * sign + 0.5;
  17558. uvs.push(uv.x, uv.y); // increase index
  17559. index++;
  17560. } // generate indices
  17561. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17562. var c = centerIndexStart + _x3;
  17563. var i = centerIndexEnd + _x3;
  17564. if (top === true) {
  17565. // face top
  17566. indices.push(i, i + 1, c);
  17567. } else {
  17568. // face bottom
  17569. indices.push(i + 1, i, c);
  17570. }
  17571. groupCount += 3;
  17572. } // add a group to the geometry. this will ensure multi material support
  17573. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17574. groupStart += groupCount;
  17575. }
  17576. return _this;
  17577. }
  17578. return CylinderGeometry;
  17579. }(BufferGeometry);
  17580. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17581. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17582. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17583. var _this;
  17584. if (radius === void 0) {
  17585. radius = 1;
  17586. }
  17587. if (height === void 0) {
  17588. height = 1;
  17589. }
  17590. if (radialSegments === void 0) {
  17591. radialSegments = 8;
  17592. }
  17593. if (heightSegments === void 0) {
  17594. heightSegments = 1;
  17595. }
  17596. if (openEnded === void 0) {
  17597. openEnded = false;
  17598. }
  17599. if (thetaStart === void 0) {
  17600. thetaStart = 0;
  17601. }
  17602. if (thetaLength === void 0) {
  17603. thetaLength = Math.PI * 2;
  17604. }
  17605. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17606. _this.type = 'ConeGeometry';
  17607. _this.parameters = {
  17608. radius: radius,
  17609. height: height,
  17610. radialSegments: radialSegments,
  17611. heightSegments: heightSegments,
  17612. openEnded: openEnded,
  17613. thetaStart: thetaStart,
  17614. thetaLength: thetaLength
  17615. };
  17616. return _this;
  17617. }
  17618. return ConeGeometry;
  17619. }(CylinderGeometry);
  17620. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17621. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  17622. function PolyhedronGeometry(vertices, indices, radius, detail) {
  17623. var _this;
  17624. if (radius === void 0) {
  17625. radius = 1;
  17626. }
  17627. if (detail === void 0) {
  17628. detail = 0;
  17629. }
  17630. _this = _BufferGeometry.call(this) || this;
  17631. _this.type = 'PolyhedronGeometry';
  17632. _this.parameters = {
  17633. vertices: vertices,
  17634. indices: indices,
  17635. radius: radius,
  17636. detail: detail
  17637. }; // default buffer data
  17638. var vertexBuffer = [];
  17639. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17640. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17641. applyRadius(radius); // finally, create the uv data
  17642. generateUVs(); // build non-indexed geometry
  17643. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17644. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17645. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17646. if (detail === 0) {
  17647. _this.computeVertexNormals(); // flat normals
  17648. } else {
  17649. _this.normalizeNormals(); // smooth normals
  17650. } // helper functions
  17651. function subdivide(detail) {
  17652. var a = new Vector3();
  17653. var b = new Vector3();
  17654. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17655. for (var i = 0; i < indices.length; i += 3) {
  17656. // get the vertices of the face
  17657. getVertexByIndex(indices[i + 0], a);
  17658. getVertexByIndex(indices[i + 1], b);
  17659. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17660. subdivideFace(a, b, c, detail);
  17661. }
  17662. }
  17663. function subdivideFace(a, b, c, detail) {
  17664. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17665. var v = []; // construct all of the vertices for this subdivision
  17666. for (var i = 0; i <= cols; i++) {
  17667. v[i] = [];
  17668. var aj = a.clone().lerp(c, i / cols);
  17669. var bj = b.clone().lerp(c, i / cols);
  17670. var rows = cols - i;
  17671. for (var j = 0; j <= rows; j++) {
  17672. if (j === 0 && i === cols) {
  17673. v[i][j] = aj;
  17674. } else {
  17675. v[i][j] = aj.clone().lerp(bj, j / rows);
  17676. }
  17677. }
  17678. } // construct all of the faces
  17679. for (var _i = 0; _i < cols; _i++) {
  17680. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17681. var k = Math.floor(_j / 2);
  17682. if (_j % 2 === 0) {
  17683. pushVertex(v[_i][k + 1]);
  17684. pushVertex(v[_i + 1][k]);
  17685. pushVertex(v[_i][k]);
  17686. } else {
  17687. pushVertex(v[_i][k + 1]);
  17688. pushVertex(v[_i + 1][k + 1]);
  17689. pushVertex(v[_i + 1][k]);
  17690. }
  17691. }
  17692. }
  17693. }
  17694. function applyRadius(radius) {
  17695. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17696. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17697. vertex.x = vertexBuffer[i + 0];
  17698. vertex.y = vertexBuffer[i + 1];
  17699. vertex.z = vertexBuffer[i + 2];
  17700. vertex.normalize().multiplyScalar(radius);
  17701. vertexBuffer[i + 0] = vertex.x;
  17702. vertexBuffer[i + 1] = vertex.y;
  17703. vertexBuffer[i + 2] = vertex.z;
  17704. }
  17705. }
  17706. function generateUVs() {
  17707. var vertex = new Vector3();
  17708. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17709. vertex.x = vertexBuffer[i + 0];
  17710. vertex.y = vertexBuffer[i + 1];
  17711. vertex.z = vertexBuffer[i + 2];
  17712. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17713. var v = inclination(vertex) / Math.PI + 0.5;
  17714. uvBuffer.push(u, 1 - v);
  17715. }
  17716. correctUVs();
  17717. correctSeam();
  17718. }
  17719. function correctSeam() {
  17720. // handle case when face straddles the seam, see #3269
  17721. for (var i = 0; i < uvBuffer.length; i += 6) {
  17722. // uv data of a single face
  17723. var x0 = uvBuffer[i + 0];
  17724. var x1 = uvBuffer[i + 2];
  17725. var x2 = uvBuffer[i + 4];
  17726. var max = Math.max(x0, x1, x2);
  17727. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17728. if (max > 0.9 && min < 0.1) {
  17729. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17730. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17731. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17732. }
  17733. }
  17734. }
  17735. function pushVertex(vertex) {
  17736. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17737. }
  17738. function getVertexByIndex(index, vertex) {
  17739. var stride = index * 3;
  17740. vertex.x = vertices[stride + 0];
  17741. vertex.y = vertices[stride + 1];
  17742. vertex.z = vertices[stride + 2];
  17743. }
  17744. function correctUVs() {
  17745. var a = new Vector3();
  17746. var b = new Vector3();
  17747. var c = new Vector3();
  17748. var centroid = new Vector3();
  17749. var uvA = new Vector2();
  17750. var uvB = new Vector2();
  17751. var uvC = new Vector2();
  17752. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17753. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17754. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17755. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17756. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17757. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17758. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17759. centroid.copy(a).add(b).add(c).divideScalar(3);
  17760. var azi = azimuth(centroid);
  17761. correctUV(uvA, j + 0, a, azi);
  17762. correctUV(uvB, j + 2, b, azi);
  17763. correctUV(uvC, j + 4, c, azi);
  17764. }
  17765. }
  17766. function correctUV(uv, stride, vector, azimuth) {
  17767. if (azimuth < 0 && uv.x === 1) {
  17768. uvBuffer[stride] = uv.x - 1;
  17769. }
  17770. if (vector.x === 0 && vector.z === 0) {
  17771. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17772. }
  17773. } // Angle around the Y axis, counter-clockwise when looking from above.
  17774. function azimuth(vector) {
  17775. return Math.atan2(vector.z, -vector.x);
  17776. } // Angle above the XZ plane.
  17777. function inclination(vector) {
  17778. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17779. }
  17780. return _this;
  17781. }
  17782. return PolyhedronGeometry;
  17783. }(BufferGeometry);
  17784. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17785. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17786. function DodecahedronGeometry(radius, detail) {
  17787. var _this;
  17788. if (radius === void 0) {
  17789. radius = 1;
  17790. }
  17791. if (detail === void 0) {
  17792. detail = 0;
  17793. }
  17794. var t = (1 + Math.sqrt(5)) / 2;
  17795. var r = 1 / t;
  17796. var vertices = [// (±1, ±1, ±1)
  17797. -1, -1, -1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, 1, 1, -1, 1, 1, 1, // (0, ±1/φ, ±φ)
  17798. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17799. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17800. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17801. var indices = [3, 11, 7, 3, 7, 15, 3, 15, 13, 7, 19, 17, 7, 17, 6, 7, 6, 15, 17, 4, 8, 17, 8, 10, 17, 10, 6, 8, 0, 16, 8, 16, 2, 8, 2, 10, 0, 12, 1, 0, 1, 18, 0, 18, 16, 6, 10, 2, 6, 2, 13, 6, 13, 15, 2, 16, 18, 2, 18, 3, 2, 3, 13, 18, 1, 9, 18, 9, 11, 18, 11, 3, 4, 14, 12, 4, 12, 0, 4, 0, 8, 11, 9, 5, 11, 5, 19, 11, 19, 7, 19, 5, 14, 19, 14, 4, 19, 4, 17, 1, 12, 14, 1, 14, 5, 1, 5, 9];
  17802. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17803. _this.type = 'DodecahedronGeometry';
  17804. _this.parameters = {
  17805. radius: radius,
  17806. detail: detail
  17807. };
  17808. return _this;
  17809. }
  17810. return DodecahedronGeometry;
  17811. }(PolyhedronGeometry);
  17812. var _v0$2 = new Vector3();
  17813. var _v1$5 = new Vector3();
  17814. var _normal$1 = new Vector3();
  17815. var _triangle = new Triangle();
  17816. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17817. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17818. function EdgesGeometry(geometry, thresholdAngle) {
  17819. var _this;
  17820. _this = _BufferGeometry.call(this) || this;
  17821. _this.type = 'EdgesGeometry';
  17822. _this.parameters = {
  17823. thresholdAngle: thresholdAngle
  17824. };
  17825. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17826. if (geometry.isGeometry === true) {
  17827. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17828. return _assertThisInitialized(_this);
  17829. }
  17830. var precisionPoints = 4;
  17831. var precision = Math.pow(10, precisionPoints);
  17832. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17833. var indexAttr = geometry.getIndex();
  17834. var positionAttr = geometry.getAttribute('position');
  17835. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17836. var indexArr = [0, 0, 0];
  17837. var vertKeys = ['a', 'b', 'c'];
  17838. var hashes = new Array(3);
  17839. var edgeData = {};
  17840. var vertices = [];
  17841. for (var i = 0; i < indexCount; i += 3) {
  17842. if (indexAttr) {
  17843. indexArr[0] = indexAttr.getX(i);
  17844. indexArr[1] = indexAttr.getX(i + 1);
  17845. indexArr[2] = indexAttr.getX(i + 2);
  17846. } else {
  17847. indexArr[0] = i;
  17848. indexArr[1] = i + 1;
  17849. indexArr[2] = i + 2;
  17850. }
  17851. var a = _triangle.a,
  17852. b = _triangle.b,
  17853. c = _triangle.c;
  17854. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17855. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17856. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17857. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17858. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17859. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17860. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17861. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17862. continue;
  17863. } // iterate over every edge
  17864. for (var j = 0; j < 3; j++) {
  17865. // get the first and next vertex making up the edge
  17866. var jNext = (j + 1) % 3;
  17867. var vecHash0 = hashes[j];
  17868. var vecHash1 = hashes[jNext];
  17869. var v0 = _triangle[vertKeys[j]];
  17870. var v1 = _triangle[vertKeys[jNext]];
  17871. var hash = vecHash0 + "_" + vecHash1;
  17872. var reverseHash = vecHash1 + "_" + vecHash0;
  17873. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17874. // if we found a sibling edge add it into the vertex array if
  17875. // it meets the angle threshold and delete the edge from the map.
  17876. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17877. vertices.push(v0.x, v0.y, v0.z);
  17878. vertices.push(v1.x, v1.y, v1.z);
  17879. }
  17880. edgeData[reverseHash] = null;
  17881. } else if (!(hash in edgeData)) {
  17882. // if we've already got an edge here then skip adding a new one
  17883. edgeData[hash] = {
  17884. index0: indexArr[j],
  17885. index1: indexArr[jNext],
  17886. normal: _normal$1.clone()
  17887. };
  17888. }
  17889. }
  17890. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17891. for (var key in edgeData) {
  17892. if (edgeData[key]) {
  17893. var _edgeData$key = edgeData[key],
  17894. index0 = _edgeData$key.index0,
  17895. index1 = _edgeData$key.index1;
  17896. _v0$2.fromBufferAttribute(positionAttr, index0);
  17897. _v1$5.fromBufferAttribute(positionAttr, index1);
  17898. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17899. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17900. }
  17901. }
  17902. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17903. return _this;
  17904. }
  17905. return EdgesGeometry;
  17906. }(BufferGeometry);
  17907. /**
  17908. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17909. */
  17910. var Earcut = {
  17911. triangulate: function triangulate(data, holeIndices, dim) {
  17912. dim = dim || 2;
  17913. var hasHoles = holeIndices && holeIndices.length;
  17914. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17915. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17916. var triangles = [];
  17917. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17918. var minX, minY, maxX, maxY, x, y, invSize;
  17919. if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim); // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  17920. if (data.length > 80 * dim) {
  17921. minX = maxX = data[0];
  17922. minY = maxY = data[1];
  17923. for (var i = dim; i < outerLen; i += dim) {
  17924. x = data[i];
  17925. y = data[i + 1];
  17926. if (x < minX) minX = x;
  17927. if (y < minY) minY = y;
  17928. if (x > maxX) maxX = x;
  17929. if (y > maxY) maxY = y;
  17930. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17931. invSize = Math.max(maxX - minX, maxY - minY);
  17932. invSize = invSize !== 0 ? 1 / invSize : 0;
  17933. }
  17934. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17935. return triangles;
  17936. }
  17937. }; // create a circular doubly linked list from polygon points in the specified winding order
  17938. function linkedList(data, start, end, dim, clockwise) {
  17939. var i, last;
  17940. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17941. for (i = start; i < end; i += dim) {
  17942. last = insertNode(i, data[i], data[i + 1], last);
  17943. }
  17944. } else {
  17945. for (i = end - dim; i >= start; i -= dim) {
  17946. last = insertNode(i, data[i], data[i + 1], last);
  17947. }
  17948. }
  17949. if (last && equals(last, last.next)) {
  17950. removeNode(last);
  17951. last = last.next;
  17952. }
  17953. return last;
  17954. } // eliminate colinear or duplicate points
  17955. function filterPoints(start, end) {
  17956. if (!start) return start;
  17957. if (!end) end = start;
  17958. var p = start,
  17959. again;
  17960. do {
  17961. again = false;
  17962. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17963. removeNode(p);
  17964. p = end = p.prev;
  17965. if (p === p.next) break;
  17966. again = true;
  17967. } else {
  17968. p = p.next;
  17969. }
  17970. } while (again || p !== end);
  17971. return end;
  17972. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17973. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17974. if (!ear) return; // interlink polygon nodes in z-order
  17975. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17976. var stop = ear,
  17977. prev,
  17978. next; // iterate through ears, slicing them one by one
  17979. while (ear.prev !== ear.next) {
  17980. prev = ear.prev;
  17981. next = ear.next;
  17982. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17983. // cut off the triangle
  17984. triangles.push(prev.i / dim);
  17985. triangles.push(ear.i / dim);
  17986. triangles.push(next.i / dim);
  17987. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17988. ear = next.next;
  17989. stop = next.next;
  17990. continue;
  17991. }
  17992. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17993. if (ear === stop) {
  17994. // try filtering points and slicing again
  17995. if (!pass) {
  17996. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17997. } else if (pass === 1) {
  17998. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17999. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  18000. } else if (pass === 2) {
  18001. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  18002. }
  18003. break;
  18004. }
  18005. }
  18006. } // check whether a polygon node forms a valid ear with adjacent nodes
  18007. function isEar(ear) {
  18008. var a = ear.prev,
  18009. b = ear,
  18010. c = ear.next;
  18011. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18012. // now make sure we don't have other points inside the potential ear
  18013. var p = ear.next.next;
  18014. while (p !== ear.prev) {
  18015. if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
  18016. p = p.next;
  18017. }
  18018. return true;
  18019. }
  18020. function isEarHashed(ear, minX, minY, invSize) {
  18021. var a = ear.prev,
  18022. b = ear,
  18023. c = ear.next;
  18024. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  18025. // triangle bbox; min & max are calculated like this for speed
  18026. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  18027. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  18028. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  18029. maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y; // z-order range for the current triangle bbox;
  18030. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  18031. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  18032. var p = ear.prevZ,
  18033. n = ear.nextZ; // look for points inside the triangle in both directions
  18034. while (p && p.z >= minZ && n && n.z <= maxZ) {
  18035. if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
  18036. p = p.prevZ;
  18037. if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
  18038. n = n.nextZ;
  18039. } // look for remaining points in decreasing z-order
  18040. while (p && p.z >= minZ) {
  18041. if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) return false;
  18042. p = p.prevZ;
  18043. } // look for remaining points in increasing z-order
  18044. while (n && n.z <= maxZ) {
  18045. if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0) return false;
  18046. n = n.nextZ;
  18047. }
  18048. return true;
  18049. } // go through all polygon nodes and cure small local self-intersections
  18050. function cureLocalIntersections(start, triangles, dim) {
  18051. var p = start;
  18052. do {
  18053. var a = p.prev,
  18054. b = p.next.next;
  18055. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  18056. triangles.push(a.i / dim);
  18057. triangles.push(p.i / dim);
  18058. triangles.push(b.i / dim); // remove two nodes involved
  18059. removeNode(p);
  18060. removeNode(p.next);
  18061. p = start = b;
  18062. }
  18063. p = p.next;
  18064. } while (p !== start);
  18065. return filterPoints(p);
  18066. } // try splitting polygon into two and triangulate them independently
  18067. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  18068. // look for a valid diagonal that divides the polygon into two
  18069. var a = start;
  18070. do {
  18071. var b = a.next.next;
  18072. while (b !== a.prev) {
  18073. if (a.i !== b.i && isValidDiagonal(a, b)) {
  18074. // split the polygon in two by the diagonal
  18075. var c = splitPolygon(a, b); // filter colinear points around the cuts
  18076. a = filterPoints(a, a.next);
  18077. c = filterPoints(c, c.next); // run earcut on each half
  18078. earcutLinked(a, triangles, dim, minX, minY, invSize);
  18079. earcutLinked(c, triangles, dim, minX, minY, invSize);
  18080. return;
  18081. }
  18082. b = b.next;
  18083. }
  18084. a = a.next;
  18085. } while (a !== start);
  18086. } // link every hole into the outer loop, producing a single-ring polygon without holes
  18087. function eliminateHoles(data, holeIndices, outerNode, dim) {
  18088. var queue = [];
  18089. var i, len, start, end, list;
  18090. for (i = 0, len = holeIndices.length; i < len; i++) {
  18091. start = holeIndices[i] * dim;
  18092. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  18093. list = linkedList(data, start, end, dim, false);
  18094. if (list === list.next) list.steiner = true;
  18095. queue.push(getLeftmost(list));
  18096. }
  18097. queue.sort(compareX); // process holes from left to right
  18098. for (i = 0; i < queue.length; i++) {
  18099. eliminateHole(queue[i], outerNode);
  18100. outerNode = filterPoints(outerNode, outerNode.next);
  18101. }
  18102. return outerNode;
  18103. }
  18104. function compareX(a, b) {
  18105. return a.x - b.x;
  18106. } // find a bridge between vertices that connects hole with an outer ring and and link it
  18107. function eliminateHole(hole, outerNode) {
  18108. outerNode = findHoleBridge(hole, outerNode);
  18109. if (outerNode) {
  18110. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  18111. filterPoints(outerNode, outerNode.next);
  18112. filterPoints(b, b.next);
  18113. }
  18114. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  18115. function findHoleBridge(hole, outerNode) {
  18116. var p = outerNode;
  18117. var hx = hole.x;
  18118. var hy = hole.y;
  18119. var qx = -Infinity,
  18120. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  18121. // segment's endpoint with lesser x will be potential connection point
  18122. do {
  18123. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  18124. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  18125. if (x <= hx && x > qx) {
  18126. qx = x;
  18127. if (x === hx) {
  18128. if (hy === p.y) return p;
  18129. if (hy === p.next.y) return p.next;
  18130. }
  18131. m = p.x < p.next.x ? p : p.next;
  18132. }
  18133. }
  18134. p = p.next;
  18135. } while (p !== outerNode);
  18136. if (!m) return null;
  18137. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  18138. // look for points inside the triangle of hole point, segment intersection and endpoint;
  18139. // if there are no points found, we have a valid connection;
  18140. // otherwise choose the point of the minimum angle with the ray as connection point
  18141. var stop = m,
  18142. mx = m.x,
  18143. my = m.y;
  18144. var tanMin = Infinity,
  18145. tan;
  18146. p = m;
  18147. do {
  18148. if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
  18149. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  18150. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  18151. m = p;
  18152. tanMin = tan;
  18153. }
  18154. }
  18155. p = p.next;
  18156. } while (p !== stop);
  18157. return m;
  18158. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18159. function sectorContainsSector(m, p) {
  18160. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18161. } // interlink polygon nodes in z-order
  18162. function indexCurve(start, minX, minY, invSize) {
  18163. var p = start;
  18164. do {
  18165. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18166. p.prevZ = p.prev;
  18167. p.nextZ = p.next;
  18168. p = p.next;
  18169. } while (p !== start);
  18170. p.prevZ.nextZ = null;
  18171. p.prevZ = null;
  18172. sortLinked(p);
  18173. } // Simon Tatham's linked list merge sort algorithm
  18174. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18175. function sortLinked(list) {
  18176. var i,
  18177. p,
  18178. q,
  18179. e,
  18180. tail,
  18181. numMerges,
  18182. pSize,
  18183. qSize,
  18184. inSize = 1;
  18185. do {
  18186. p = list;
  18187. list = null;
  18188. tail = null;
  18189. numMerges = 0;
  18190. while (p) {
  18191. numMerges++;
  18192. q = p;
  18193. pSize = 0;
  18194. for (i = 0; i < inSize; i++) {
  18195. pSize++;
  18196. q = q.nextZ;
  18197. if (!q) break;
  18198. }
  18199. qSize = inSize;
  18200. while (pSize > 0 || qSize > 0 && q) {
  18201. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18202. e = p;
  18203. p = p.nextZ;
  18204. pSize--;
  18205. } else {
  18206. e = q;
  18207. q = q.nextZ;
  18208. qSize--;
  18209. }
  18210. if (tail) tail.nextZ = e;else list = e;
  18211. e.prevZ = tail;
  18212. tail = e;
  18213. }
  18214. p = q;
  18215. }
  18216. tail.nextZ = null;
  18217. inSize *= 2;
  18218. } while (numMerges > 1);
  18219. return list;
  18220. } // z-order of a point given coords and inverse of the longer side of data bbox
  18221. function zOrder(x, y, minX, minY, invSize) {
  18222. // coords are transformed into non-negative 15-bit integer range
  18223. x = 32767 * (x - minX) * invSize;
  18224. y = 32767 * (y - minY) * invSize;
  18225. x = (x | x << 8) & 0x00FF00FF;
  18226. x = (x | x << 4) & 0x0F0F0F0F;
  18227. x = (x | x << 2) & 0x33333333;
  18228. x = (x | x << 1) & 0x55555555;
  18229. y = (y | y << 8) & 0x00FF00FF;
  18230. y = (y | y << 4) & 0x0F0F0F0F;
  18231. y = (y | y << 2) & 0x33333333;
  18232. y = (y | y << 1) & 0x55555555;
  18233. return x | y << 1;
  18234. } // find the leftmost node of a polygon ring
  18235. function getLeftmost(start) {
  18236. var p = start,
  18237. leftmost = start;
  18238. do {
  18239. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18240. p = p.next;
  18241. } while (p !== start);
  18242. return leftmost;
  18243. } // check if a point lies within a convex triangle
  18244. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18245. return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
  18246. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18247. function isValidDiagonal(a, b) {
  18248. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18249. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18250. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18251. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18252. } // signed area of a triangle
  18253. function area(p, q, r) {
  18254. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18255. } // check if two points are equal
  18256. function equals(p1, p2) {
  18257. return p1.x === p2.x && p1.y === p2.y;
  18258. } // check if two segments intersect
  18259. function intersects(p1, q1, p2, q2) {
  18260. var o1 = sign(area(p1, q1, p2));
  18261. var o2 = sign(area(p1, q1, q2));
  18262. var o3 = sign(area(p2, q2, p1));
  18263. var o4 = sign(area(p2, q2, q1));
  18264. if (o1 !== o2 && o3 !== o4) return true; // general case
  18265. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18266. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18267. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18268. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18269. return false;
  18270. } // for collinear points p, q, r, check if point q lies on segment pr
  18271. function onSegment(p, q, r) {
  18272. return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
  18273. }
  18274. function sign(num) {
  18275. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18276. } // check if a polygon diagonal intersects any polygon segments
  18277. function intersectsPolygon(a, b) {
  18278. var p = a;
  18279. do {
  18280. if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b)) return true;
  18281. p = p.next;
  18282. } while (p !== a);
  18283. return false;
  18284. } // check if a polygon diagonal is locally inside the polygon
  18285. function locallyInside(a, b) {
  18286. return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
  18287. } // check if the middle point of a polygon diagonal is inside the polygon
  18288. function middleInside(a, b) {
  18289. var p = a,
  18290. inside = false;
  18291. var px = (a.x + b.x) / 2,
  18292. py = (a.y + b.y) / 2;
  18293. do {
  18294. if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x) inside = !inside;
  18295. p = p.next;
  18296. } while (p !== a);
  18297. return inside;
  18298. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18299. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18300. function splitPolygon(a, b) {
  18301. var a2 = new Node(a.i, a.x, a.y),
  18302. b2 = new Node(b.i, b.x, b.y),
  18303. an = a.next,
  18304. bp = b.prev;
  18305. a.next = b;
  18306. b.prev = a;
  18307. a2.next = an;
  18308. an.prev = a2;
  18309. b2.next = a2;
  18310. a2.prev = b2;
  18311. bp.next = b2;
  18312. b2.prev = bp;
  18313. return b2;
  18314. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18315. function insertNode(i, x, y, last) {
  18316. var p = new Node(i, x, y);
  18317. if (!last) {
  18318. p.prev = p;
  18319. p.next = p;
  18320. } else {
  18321. p.next = last.next;
  18322. p.prev = last;
  18323. last.next.prev = p;
  18324. last.next = p;
  18325. }
  18326. return p;
  18327. }
  18328. function removeNode(p) {
  18329. p.next.prev = p.prev;
  18330. p.prev.next = p.next;
  18331. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18332. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18333. }
  18334. function Node(i, x, y) {
  18335. // vertex index in coordinates array
  18336. this.i = i; // vertex coordinates
  18337. this.x = x;
  18338. this.y = y; // previous and next vertex nodes in a polygon ring
  18339. this.prev = null;
  18340. this.next = null; // z-order curve value
  18341. this.z = null; // previous and next nodes in z-order
  18342. this.prevZ = null;
  18343. this.nextZ = null; // indicates whether this is a steiner point
  18344. this.steiner = false;
  18345. }
  18346. function signedArea(data, start, end, dim) {
  18347. var sum = 0;
  18348. for (var i = start, j = end - dim; i < end; i += dim) {
  18349. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18350. j = i;
  18351. }
  18352. return sum;
  18353. }
  18354. var ShapeUtils = {
  18355. // calculate area of the contour polygon
  18356. area: function area(contour) {
  18357. var n = contour.length;
  18358. var a = 0.0;
  18359. for (var p = n - 1, q = 0; q < n; p = q++) {
  18360. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18361. }
  18362. return a * 0.5;
  18363. },
  18364. isClockWise: function isClockWise(pts) {
  18365. return ShapeUtils.area(pts) < 0;
  18366. },
  18367. triangulateShape: function triangulateShape(contour, holes) {
  18368. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18369. var holeIndices = []; // array of hole indices
  18370. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18371. removeDupEndPts(contour);
  18372. addContour(vertices, contour); //
  18373. var holeIndex = contour.length;
  18374. holes.forEach(removeDupEndPts);
  18375. for (var i = 0; i < holes.length; i++) {
  18376. holeIndices.push(holeIndex);
  18377. holeIndex += holes[i].length;
  18378. addContour(vertices, holes[i]);
  18379. } //
  18380. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18381. for (var _i = 0; _i < triangles.length; _i += 3) {
  18382. faces.push(triangles.slice(_i, _i + 3));
  18383. }
  18384. return faces;
  18385. }
  18386. };
  18387. function removeDupEndPts(points) {
  18388. var l = points.length;
  18389. if (l > 2 && points[l - 1].equals(points[0])) {
  18390. points.pop();
  18391. }
  18392. }
  18393. function addContour(vertices, contour) {
  18394. for (var i = 0; i < contour.length; i++) {
  18395. vertices.push(contour[i].x);
  18396. vertices.push(contour[i].y);
  18397. }
  18398. }
  18399. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18400. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  18401. function ExtrudeGeometry(shapes, options) {
  18402. var _this;
  18403. _this = _BufferGeometry.call(this) || this;
  18404. _this.type = 'ExtrudeGeometry';
  18405. _this.parameters = {
  18406. shapes: shapes,
  18407. options: options
  18408. };
  18409. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18410. var scope = _assertThisInitialized(_this);
  18411. var verticesArray = [];
  18412. var uvArray = [];
  18413. for (var i = 0, l = shapes.length; i < l; i++) {
  18414. var shape = shapes[i];
  18415. addShape(shape);
  18416. } // build geometry
  18417. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18418. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18419. _this.computeVertexNormals(); // functions
  18420. function addShape(shape) {
  18421. var placeholder = []; // options
  18422. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18423. var steps = options.steps !== undefined ? options.steps : 1;
  18424. var depth = options.depth !== undefined ? options.depth : 100;
  18425. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18426. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18427. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18428. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18429. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18430. var extrudePath = options.extrudePath;
  18431. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18432. if (options.amount !== undefined) {
  18433. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18434. depth = options.amount;
  18435. } //
  18436. var extrudePts,
  18437. extrudeByPath = false;
  18438. var splineTube, binormal, normal, position2;
  18439. if (extrudePath) {
  18440. extrudePts = extrudePath.getSpacedPoints(steps);
  18441. extrudeByPath = true;
  18442. bevelEnabled = false; // bevels not supported for path extrusion
  18443. // SETUP TNB variables
  18444. // TODO1 - have a .isClosed in spline?
  18445. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18446. binormal = new Vector3();
  18447. normal = new Vector3();
  18448. position2 = new Vector3();
  18449. } // Safeguards if bevels are not enabled
  18450. if (!bevelEnabled) {
  18451. bevelSegments = 0;
  18452. bevelThickness = 0;
  18453. bevelSize = 0;
  18454. bevelOffset = 0;
  18455. } // Variables initialization
  18456. var shapePoints = shape.extractPoints(curveSegments);
  18457. var vertices = shapePoints.shape;
  18458. var holes = shapePoints.holes;
  18459. var reverse = !ShapeUtils.isClockWise(vertices);
  18460. if (reverse) {
  18461. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18462. for (var h = 0, hl = holes.length; h < hl; h++) {
  18463. var ahole = holes[h];
  18464. if (ShapeUtils.isClockWise(ahole)) {
  18465. holes[h] = ahole.reverse();
  18466. }
  18467. }
  18468. }
  18469. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18470. /* Vertices */
  18471. var contour = vertices; // vertices has all points but contour has only points of circumference
  18472. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18473. var _ahole = holes[_h];
  18474. vertices = vertices.concat(_ahole);
  18475. }
  18476. function scalePt2(pt, vec, size) {
  18477. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18478. return vec.clone().multiplyScalar(size).add(pt);
  18479. }
  18480. var vlen = vertices.length,
  18481. flen = faces.length; // Find directions for point movement
  18482. function getBevelVec(inPt, inPrev, inNext) {
  18483. // computes for inPt the corresponding point inPt' on a new contour
  18484. // shifted by 1 unit (length of normalized vector) to the left
  18485. // if we walk along contour clockwise, this new contour is outside the old one
  18486. //
  18487. // inPt' is the intersection of the two lines parallel to the two
  18488. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18489. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18490. // good reading for geometry algorithms (here: line-line intersection)
  18491. // http://geomalgorithms.com/a05-_intersect-1.html
  18492. var v_prev_x = inPt.x - inPrev.x,
  18493. v_prev_y = inPt.y - inPrev.y;
  18494. var v_next_x = inNext.x - inPt.x,
  18495. v_next_y = inNext.y - inPt.y;
  18496. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18497. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18498. if (Math.abs(collinear0) > Number.EPSILON) {
  18499. // not collinear
  18500. // length of vectors for normalizing
  18501. var v_prev_len = Math.sqrt(v_prev_lensq);
  18502. var v_next_len = Math.sqrt(v_next_x * v_next_x + v_next_y * v_next_y); // shift adjacent points by unit vectors to the left
  18503. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18504. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18505. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18506. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18507. var sf = ((ptNextShift_x - ptPrevShift_x) * v_next_y - (ptNextShift_y - ptPrevShift_y) * v_next_x) / (v_prev_x * v_next_y - v_prev_y * v_next_x); // vector from inPt to intersection point
  18508. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18509. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18510. // but prevent crazy spikes
  18511. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18512. if (v_trans_lensq <= 2) {
  18513. return new Vector2(v_trans_x, v_trans_y);
  18514. } else {
  18515. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18516. }
  18517. } else {
  18518. // handle special case of collinear edges
  18519. var direction_eq = false; // assumes: opposite
  18520. if (v_prev_x > Number.EPSILON) {
  18521. if (v_next_x > Number.EPSILON) {
  18522. direction_eq = true;
  18523. }
  18524. } else {
  18525. if (v_prev_x < -Number.EPSILON) {
  18526. if (v_next_x < -Number.EPSILON) {
  18527. direction_eq = true;
  18528. }
  18529. } else {
  18530. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18531. direction_eq = true;
  18532. }
  18533. }
  18534. }
  18535. if (direction_eq) {
  18536. // console.log("Warning: lines are a straight sequence");
  18537. v_trans_x = -v_prev_y;
  18538. v_trans_y = v_prev_x;
  18539. shrink_by = Math.sqrt(v_prev_lensq);
  18540. } else {
  18541. // console.log("Warning: lines are a straight spike");
  18542. v_trans_x = v_prev_x;
  18543. v_trans_y = v_prev_y;
  18544. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18545. }
  18546. }
  18547. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18548. }
  18549. var contourMovements = [];
  18550. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18551. if (j === il) j = 0;
  18552. if (k === il) k = 0; // (j)---(i)---(k)
  18553. // console.log('i,j,k', i, j , k)
  18554. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18555. }
  18556. var holesMovements = [];
  18557. var oneHoleMovements,
  18558. verticesMovements = contourMovements.concat();
  18559. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18560. var _ahole2 = holes[_h2];
  18561. oneHoleMovements = [];
  18562. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18563. if (_j === _il) _j = 0;
  18564. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18565. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18566. }
  18567. holesMovements.push(oneHoleMovements);
  18568. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18569. } // Loop bevelSegments, 1 for the front, 1 for the back
  18570. for (var b = 0; b < bevelSegments; b++) {
  18571. //for ( b = bevelSegments; b > 0; b -- ) {
  18572. var t = b / bevelSegments;
  18573. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18574. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18575. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18576. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18577. v(vert.x, vert.y, -z);
  18578. } // expand holes
  18579. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18580. var _ahole3 = holes[_h3];
  18581. oneHoleMovements = holesMovements[_h3];
  18582. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18583. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18584. v(_vert.x, _vert.y, -z);
  18585. }
  18586. }
  18587. }
  18588. var bs = bevelSize + bevelOffset; // Back facing vertices
  18589. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18590. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18591. if (!extrudeByPath) {
  18592. v(_vert2.x, _vert2.y, 0);
  18593. } else {
  18594. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18595. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18596. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18597. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18598. v(position2.x, position2.y, position2.z);
  18599. }
  18600. } // Add stepped vertices...
  18601. // Including front facing vertices
  18602. for (var s = 1; s <= steps; s++) {
  18603. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18604. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18605. if (!extrudeByPath) {
  18606. v(_vert3.x, _vert3.y, depth / steps * s);
  18607. } else {
  18608. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18609. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18610. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18611. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18612. v(position2.x, position2.y, position2.z);
  18613. }
  18614. }
  18615. } // Add bevel segments planes
  18616. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18617. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18618. var _t = _b / bevelSegments;
  18619. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18620. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18621. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18622. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18623. v(_vert4.x, _vert4.y, depth + _z);
  18624. } // expand holes
  18625. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18626. var _ahole4 = holes[_h4];
  18627. oneHoleMovements = holesMovements[_h4];
  18628. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18629. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18630. if (!extrudeByPath) {
  18631. v(_vert5.x, _vert5.y, depth + _z);
  18632. } else {
  18633. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18634. }
  18635. }
  18636. }
  18637. }
  18638. /* Faces */
  18639. // Top and bottom faces
  18640. buildLidFaces(); // Sides faces
  18641. buildSideFaces(); ///// Internal functions
  18642. function buildLidFaces() {
  18643. var start = verticesArray.length / 3;
  18644. if (bevelEnabled) {
  18645. var layer = 0; // steps + 1
  18646. var offset = vlen * layer; // Bottom faces
  18647. for (var _i9 = 0; _i9 < flen; _i9++) {
  18648. var face = faces[_i9];
  18649. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18650. }
  18651. layer = steps + bevelSegments * 2;
  18652. offset = vlen * layer; // Top faces
  18653. for (var _i10 = 0; _i10 < flen; _i10++) {
  18654. var _face = faces[_i10];
  18655. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18656. }
  18657. } else {
  18658. // Bottom faces
  18659. for (var _i11 = 0; _i11 < flen; _i11++) {
  18660. var _face2 = faces[_i11];
  18661. f3(_face2[2], _face2[1], _face2[0]);
  18662. } // Top faces
  18663. for (var _i12 = 0; _i12 < flen; _i12++) {
  18664. var _face3 = faces[_i12];
  18665. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18666. }
  18667. }
  18668. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18669. } // Create faces for the z-sides of the shape
  18670. function buildSideFaces() {
  18671. var start = verticesArray.length / 3;
  18672. var layeroffset = 0;
  18673. sidewalls(contour, layeroffset);
  18674. layeroffset += contour.length;
  18675. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18676. var _ahole5 = holes[_h5];
  18677. sidewalls(_ahole5, layeroffset); //, true
  18678. layeroffset += _ahole5.length;
  18679. }
  18680. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18681. }
  18682. function sidewalls(contour, layeroffset) {
  18683. var i = contour.length;
  18684. while (--i >= 0) {
  18685. var _j2 = i;
  18686. var _k2 = i - 1;
  18687. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18688. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18689. var slen1 = vlen * _s;
  18690. var slen2 = vlen * (_s + 1);
  18691. var a = layeroffset + _j2 + slen1,
  18692. _b2 = layeroffset + _k2 + slen1,
  18693. c = layeroffset + _k2 + slen2,
  18694. d = layeroffset + _j2 + slen2;
  18695. f4(a, _b2, c, d);
  18696. }
  18697. }
  18698. }
  18699. function v(x, y, z) {
  18700. placeholder.push(x);
  18701. placeholder.push(y);
  18702. placeholder.push(z);
  18703. }
  18704. function f3(a, b, c) {
  18705. addVertex(a);
  18706. addVertex(b);
  18707. addVertex(c);
  18708. var nextIndex = verticesArray.length / 3;
  18709. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18710. addUV(uvs[0]);
  18711. addUV(uvs[1]);
  18712. addUV(uvs[2]);
  18713. }
  18714. function f4(a, b, c, d) {
  18715. addVertex(a);
  18716. addVertex(b);
  18717. addVertex(d);
  18718. addVertex(b);
  18719. addVertex(c);
  18720. addVertex(d);
  18721. var nextIndex = verticesArray.length / 3;
  18722. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18723. addUV(uvs[0]);
  18724. addUV(uvs[1]);
  18725. addUV(uvs[3]);
  18726. addUV(uvs[1]);
  18727. addUV(uvs[2]);
  18728. addUV(uvs[3]);
  18729. }
  18730. function addVertex(index) {
  18731. verticesArray.push(placeholder[index * 3 + 0]);
  18732. verticesArray.push(placeholder[index * 3 + 1]);
  18733. verticesArray.push(placeholder[index * 3 + 2]);
  18734. }
  18735. function addUV(vector2) {
  18736. uvArray.push(vector2.x);
  18737. uvArray.push(vector2.y);
  18738. }
  18739. }
  18740. return _this;
  18741. }
  18742. var _proto = ExtrudeGeometry.prototype;
  18743. _proto.toJSON = function toJSON() {
  18744. var data = BufferGeometry.prototype.toJSON.call(this);
  18745. var shapes = this.parameters.shapes;
  18746. var options = this.parameters.options;
  18747. return _toJSON(shapes, options, data);
  18748. };
  18749. return ExtrudeGeometry;
  18750. }(BufferGeometry);
  18751. var WorldUVGenerator = {
  18752. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18753. var a_x = vertices[indexA * 3];
  18754. var a_y = vertices[indexA * 3 + 1];
  18755. var b_x = vertices[indexB * 3];
  18756. var b_y = vertices[indexB * 3 + 1];
  18757. var c_x = vertices[indexC * 3];
  18758. var c_y = vertices[indexC * 3 + 1];
  18759. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18760. },
  18761. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18762. var a_x = vertices[indexA * 3];
  18763. var a_y = vertices[indexA * 3 + 1];
  18764. var a_z = vertices[indexA * 3 + 2];
  18765. var b_x = vertices[indexB * 3];
  18766. var b_y = vertices[indexB * 3 + 1];
  18767. var b_z = vertices[indexB * 3 + 2];
  18768. var c_x = vertices[indexC * 3];
  18769. var c_y = vertices[indexC * 3 + 1];
  18770. var c_z = vertices[indexC * 3 + 2];
  18771. var d_x = vertices[indexD * 3];
  18772. var d_y = vertices[indexD * 3 + 1];
  18773. var d_z = vertices[indexD * 3 + 2];
  18774. if (Math.abs(a_y - b_y) < 0.01) {
  18775. return [new Vector2(a_x, 1 - a_z), new Vector2(b_x, 1 - b_z), new Vector2(c_x, 1 - c_z), new Vector2(d_x, 1 - d_z)];
  18776. } else {
  18777. return [new Vector2(a_y, 1 - a_z), new Vector2(b_y, 1 - b_z), new Vector2(c_y, 1 - c_z), new Vector2(d_y, 1 - d_z)];
  18778. }
  18779. }
  18780. };
  18781. function _toJSON(shapes, options, data) {
  18782. data.shapes = [];
  18783. if (Array.isArray(shapes)) {
  18784. for (var i = 0, l = shapes.length; i < l; i++) {
  18785. var shape = shapes[i];
  18786. data.shapes.push(shape.uuid);
  18787. }
  18788. } else {
  18789. data.shapes.push(shapes.uuid);
  18790. }
  18791. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18792. return data;
  18793. }
  18794. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18795. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18796. function IcosahedronGeometry(radius, detail) {
  18797. var _this;
  18798. if (radius === void 0) {
  18799. radius = 1;
  18800. }
  18801. if (detail === void 0) {
  18802. detail = 0;
  18803. }
  18804. var t = (1 + Math.sqrt(5)) / 2;
  18805. var vertices = [-1, t, 0, 1, t, 0, -1, -t, 0, 1, -t, 0, 0, -1, t, 0, 1, t, 0, -1, -t, 0, 1, -t, t, 0, -1, t, 0, 1, -t, 0, -1, -t, 0, 1];
  18806. var indices = [0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1];
  18807. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18808. _this.type = 'IcosahedronGeometry';
  18809. _this.parameters = {
  18810. radius: radius,
  18811. detail: detail
  18812. };
  18813. return _this;
  18814. }
  18815. return IcosahedronGeometry;
  18816. }(PolyhedronGeometry);
  18817. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18818. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18819. function LatheGeometry(points, segments, phiStart, phiLength) {
  18820. var _this;
  18821. if (segments === void 0) {
  18822. segments = 12;
  18823. }
  18824. if (phiStart === void 0) {
  18825. phiStart = 0;
  18826. }
  18827. if (phiLength === void 0) {
  18828. phiLength = Math.PI * 2;
  18829. }
  18830. _this = _BufferGeometry.call(this) || this;
  18831. _this.type = 'LatheGeometry';
  18832. _this.parameters = {
  18833. points: points,
  18834. segments: segments,
  18835. phiStart: phiStart,
  18836. phiLength: phiLength
  18837. };
  18838. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18839. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18840. var indices = [];
  18841. var vertices = [];
  18842. var uvs = []; // helper variables
  18843. var inverseSegments = 1.0 / segments;
  18844. var vertex = new Vector3();
  18845. var uv = new Vector2(); // generate vertices and uvs
  18846. for (var i = 0; i <= segments; i++) {
  18847. var phi = phiStart + i * inverseSegments * phiLength;
  18848. var sin = Math.sin(phi);
  18849. var cos = Math.cos(phi);
  18850. for (var j = 0; j <= points.length - 1; j++) {
  18851. // vertex
  18852. vertex.x = points[j].x * sin;
  18853. vertex.y = points[j].y;
  18854. vertex.z = points[j].x * cos;
  18855. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18856. uv.x = i / segments;
  18857. uv.y = j / (points.length - 1);
  18858. uvs.push(uv.x, uv.y);
  18859. }
  18860. } // indices
  18861. for (var _i = 0; _i < segments; _i++) {
  18862. for (var _j = 0; _j < points.length - 1; _j++) {
  18863. var base = _j + _i * points.length;
  18864. var a = base;
  18865. var b = base + points.length;
  18866. var c = base + points.length + 1;
  18867. var d = base + 1; // faces
  18868. indices.push(a, b, d);
  18869. indices.push(b, c, d);
  18870. }
  18871. } // build geometry
  18872. _this.setIndex(indices);
  18873. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18874. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18875. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18876. // because the corresponding vertices are identical (but still have different UVs).
  18877. if (phiLength === Math.PI * 2) {
  18878. var normals = _this.attributes.normal.array;
  18879. var n1 = new Vector3();
  18880. var n2 = new Vector3();
  18881. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18882. var _base = segments * points.length * 3;
  18883. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18884. // select the normal of the vertex in the first line
  18885. n1.x = normals[_j2 + 0];
  18886. n1.y = normals[_j2 + 1];
  18887. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18888. n2.x = normals[_base + _j2 + 0];
  18889. n2.y = normals[_base + _j2 + 1];
  18890. n2.z = normals[_base + _j2 + 2]; // average normals
  18891. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18892. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18893. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18894. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18895. }
  18896. }
  18897. return _this;
  18898. }
  18899. return LatheGeometry;
  18900. }(BufferGeometry);
  18901. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18902. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18903. function OctahedronGeometry(radius, detail) {
  18904. var _this;
  18905. if (radius === void 0) {
  18906. radius = 1;
  18907. }
  18908. if (detail === void 0) {
  18909. detail = 0;
  18910. }
  18911. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18912. var indices = [0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2];
  18913. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18914. _this.type = 'OctahedronGeometry';
  18915. _this.parameters = {
  18916. radius: radius,
  18917. detail: detail
  18918. };
  18919. return _this;
  18920. }
  18921. return OctahedronGeometry;
  18922. }(PolyhedronGeometry);
  18923. /**
  18924. * Parametric Surfaces Geometry
  18925. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18926. */
  18927. function ParametricGeometry(func, slices, stacks) {
  18928. BufferGeometry.call(this);
  18929. this.type = 'ParametricGeometry';
  18930. this.parameters = {
  18931. func: func,
  18932. slices: slices,
  18933. stacks: stacks
  18934. }; // buffers
  18935. var indices = [];
  18936. var vertices = [];
  18937. var normals = [];
  18938. var uvs = [];
  18939. var EPS = 0.00001;
  18940. var normal = new Vector3();
  18941. var p0 = new Vector3(),
  18942. p1 = new Vector3();
  18943. var pu = new Vector3(),
  18944. pv = new Vector3();
  18945. if (func.length < 3) {
  18946. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18947. } // generate vertices, normals and uvs
  18948. var sliceCount = slices + 1;
  18949. for (var i = 0; i <= stacks; i++) {
  18950. var v = i / stacks;
  18951. for (var j = 0; j <= slices; j++) {
  18952. var u = j / slices; // vertex
  18953. func(u, v, p0);
  18954. vertices.push(p0.x, p0.y, p0.z); // normal
  18955. // approximate tangent vectors via finite differences
  18956. if (u - EPS >= 0) {
  18957. func(u - EPS, v, p1);
  18958. pu.subVectors(p0, p1);
  18959. } else {
  18960. func(u + EPS, v, p1);
  18961. pu.subVectors(p1, p0);
  18962. }
  18963. if (v - EPS >= 0) {
  18964. func(u, v - EPS, p1);
  18965. pv.subVectors(p0, p1);
  18966. } else {
  18967. func(u, v + EPS, p1);
  18968. pv.subVectors(p1, p0);
  18969. } // cross product of tangent vectors returns surface normal
  18970. normal.crossVectors(pu, pv).normalize();
  18971. normals.push(normal.x, normal.y, normal.z); // uv
  18972. uvs.push(u, v);
  18973. }
  18974. } // generate indices
  18975. for (var _i = 0; _i < stacks; _i++) {
  18976. for (var _j = 0; _j < slices; _j++) {
  18977. var a = _i * sliceCount + _j;
  18978. var b = _i * sliceCount + _j + 1;
  18979. var c = (_i + 1) * sliceCount + _j + 1;
  18980. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18981. indices.push(a, b, d);
  18982. indices.push(b, c, d);
  18983. }
  18984. } // build geometry
  18985. this.setIndex(indices);
  18986. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18987. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18988. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18989. }
  18990. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18991. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18992. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18993. _inheritsLoose(RingGeometry, _BufferGeometry);
  18994. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18995. var _this;
  18996. if (innerRadius === void 0) {
  18997. innerRadius = 0.5;
  18998. }
  18999. if (outerRadius === void 0) {
  19000. outerRadius = 1;
  19001. }
  19002. if (thetaSegments === void 0) {
  19003. thetaSegments = 8;
  19004. }
  19005. if (phiSegments === void 0) {
  19006. phiSegments = 1;
  19007. }
  19008. if (thetaStart === void 0) {
  19009. thetaStart = 0;
  19010. }
  19011. if (thetaLength === void 0) {
  19012. thetaLength = Math.PI * 2;
  19013. }
  19014. _this = _BufferGeometry.call(this) || this;
  19015. _this.type = 'RingGeometry';
  19016. _this.parameters = {
  19017. innerRadius: innerRadius,
  19018. outerRadius: outerRadius,
  19019. thetaSegments: thetaSegments,
  19020. phiSegments: phiSegments,
  19021. thetaStart: thetaStart,
  19022. thetaLength: thetaLength
  19023. };
  19024. thetaSegments = Math.max(3, thetaSegments);
  19025. phiSegments = Math.max(1, phiSegments); // buffers
  19026. var indices = [];
  19027. var vertices = [];
  19028. var normals = [];
  19029. var uvs = []; // some helper variables
  19030. var radius = innerRadius;
  19031. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  19032. var vertex = new Vector3();
  19033. var uv = new Vector2(); // generate vertices, normals and uvs
  19034. for (var j = 0; j <= phiSegments; j++) {
  19035. for (var i = 0; i <= thetaSegments; i++) {
  19036. // values are generate from the inside of the ring to the outside
  19037. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  19038. vertex.x = radius * Math.cos(segment);
  19039. vertex.y = radius * Math.sin(segment);
  19040. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19041. normals.push(0, 0, 1); // uv
  19042. uv.x = (vertex.x / outerRadius + 1) / 2;
  19043. uv.y = (vertex.y / outerRadius + 1) / 2;
  19044. uvs.push(uv.x, uv.y);
  19045. } // increase the radius for next row of vertices
  19046. radius += radiusStep;
  19047. } // indices
  19048. for (var _j = 0; _j < phiSegments; _j++) {
  19049. var thetaSegmentLevel = _j * (thetaSegments + 1);
  19050. for (var _i = 0; _i < thetaSegments; _i++) {
  19051. var _segment = _i + thetaSegmentLevel;
  19052. var a = _segment;
  19053. var b = _segment + thetaSegments + 1;
  19054. var c = _segment + thetaSegments + 2;
  19055. var d = _segment + 1; // faces
  19056. indices.push(a, b, d);
  19057. indices.push(b, c, d);
  19058. }
  19059. } // build geometry
  19060. _this.setIndex(indices);
  19061. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19062. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19063. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19064. return _this;
  19065. }
  19066. return RingGeometry;
  19067. }(BufferGeometry);
  19068. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19069. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  19070. function ShapeGeometry(shapes, curveSegments) {
  19071. var _this;
  19072. if (curveSegments === void 0) {
  19073. curveSegments = 12;
  19074. }
  19075. _this = _BufferGeometry.call(this) || this;
  19076. _this.type = 'ShapeGeometry';
  19077. _this.parameters = {
  19078. shapes: shapes,
  19079. curveSegments: curveSegments
  19080. }; // buffers
  19081. var indices = [];
  19082. var vertices = [];
  19083. var normals = [];
  19084. var uvs = []; // helper variables
  19085. var groupStart = 0;
  19086. var groupCount = 0; // allow single and array values for "shapes" parameter
  19087. if (Array.isArray(shapes) === false) {
  19088. addShape(shapes);
  19089. } else {
  19090. for (var i = 0; i < shapes.length; i++) {
  19091. addShape(shapes[i]);
  19092. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  19093. groupStart += groupCount;
  19094. groupCount = 0;
  19095. }
  19096. } // build geometry
  19097. _this.setIndex(indices);
  19098. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19099. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19100. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  19101. function addShape(shape) {
  19102. var indexOffset = vertices.length / 3;
  19103. var points = shape.extractPoints(curveSegments);
  19104. var shapeVertices = points.shape;
  19105. var shapeHoles = points.holes; // check direction of vertices
  19106. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  19107. shapeVertices = shapeVertices.reverse();
  19108. }
  19109. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  19110. var shapeHole = shapeHoles[_i];
  19111. if (ShapeUtils.isClockWise(shapeHole) === true) {
  19112. shapeHoles[_i] = shapeHole.reverse();
  19113. }
  19114. }
  19115. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  19116. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  19117. var _shapeHole = shapeHoles[_i2];
  19118. shapeVertices = shapeVertices.concat(_shapeHole);
  19119. } // vertices, normals, uvs
  19120. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  19121. var vertex = shapeVertices[_i3];
  19122. vertices.push(vertex.x, vertex.y, 0);
  19123. normals.push(0, 0, 1);
  19124. uvs.push(vertex.x, vertex.y); // world uvs
  19125. } // incides
  19126. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  19127. var face = faces[_i4];
  19128. var a = face[0] + indexOffset;
  19129. var b = face[1] + indexOffset;
  19130. var c = face[2] + indexOffset;
  19131. indices.push(a, b, c);
  19132. groupCount += 3;
  19133. }
  19134. }
  19135. return _this;
  19136. }
  19137. var _proto = ShapeGeometry.prototype;
  19138. _proto.toJSON = function toJSON() {
  19139. var data = BufferGeometry.prototype.toJSON.call(this);
  19140. var shapes = this.parameters.shapes;
  19141. return _toJSON$1(shapes, data);
  19142. };
  19143. return ShapeGeometry;
  19144. }(BufferGeometry);
  19145. function _toJSON$1(shapes, data) {
  19146. data.shapes = [];
  19147. if (Array.isArray(shapes)) {
  19148. for (var i = 0, l = shapes.length; i < l; i++) {
  19149. var shape = shapes[i];
  19150. data.shapes.push(shape.uuid);
  19151. }
  19152. } else {
  19153. data.shapes.push(shapes.uuid);
  19154. }
  19155. return data;
  19156. }
  19157. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19158. _inheritsLoose(SphereGeometry, _BufferGeometry);
  19159. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19160. var _this;
  19161. if (radius === void 0) {
  19162. radius = 1;
  19163. }
  19164. if (widthSegments === void 0) {
  19165. widthSegments = 8;
  19166. }
  19167. if (heightSegments === void 0) {
  19168. heightSegments = 6;
  19169. }
  19170. if (phiStart === void 0) {
  19171. phiStart = 0;
  19172. }
  19173. if (phiLength === void 0) {
  19174. phiLength = Math.PI * 2;
  19175. }
  19176. if (thetaStart === void 0) {
  19177. thetaStart = 0;
  19178. }
  19179. if (thetaLength === void 0) {
  19180. thetaLength = Math.PI;
  19181. }
  19182. _this = _BufferGeometry.call(this) || this;
  19183. _this.type = 'SphereGeometry';
  19184. _this.parameters = {
  19185. radius: radius,
  19186. widthSegments: widthSegments,
  19187. heightSegments: heightSegments,
  19188. phiStart: phiStart,
  19189. phiLength: phiLength,
  19190. thetaStart: thetaStart,
  19191. thetaLength: thetaLength
  19192. };
  19193. widthSegments = Math.max(3, Math.floor(widthSegments));
  19194. heightSegments = Math.max(2, Math.floor(heightSegments));
  19195. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19196. var index = 0;
  19197. var grid = [];
  19198. var vertex = new Vector3();
  19199. var normal = new Vector3(); // buffers
  19200. var indices = [];
  19201. var vertices = [];
  19202. var normals = [];
  19203. var uvs = []; // generate vertices, normals and uvs
  19204. for (var iy = 0; iy <= heightSegments; iy++) {
  19205. var verticesRow = [];
  19206. var v = iy / heightSegments; // special case for the poles
  19207. var uOffset = 0;
  19208. if (iy == 0 && thetaStart == 0) {
  19209. uOffset = 0.5 / widthSegments;
  19210. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19211. uOffset = -0.5 / widthSegments;
  19212. }
  19213. for (var ix = 0; ix <= widthSegments; ix++) {
  19214. var u = ix / widthSegments; // vertex
  19215. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19216. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19217. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19218. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19219. normal.copy(vertex).normalize();
  19220. normals.push(normal.x, normal.y, normal.z); // uv
  19221. uvs.push(u + uOffset, 1 - v);
  19222. verticesRow.push(index++);
  19223. }
  19224. grid.push(verticesRow);
  19225. } // indices
  19226. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19227. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19228. var a = grid[_iy][_ix + 1];
  19229. var b = grid[_iy][_ix];
  19230. var c = grid[_iy + 1][_ix];
  19231. var d = grid[_iy + 1][_ix + 1];
  19232. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19233. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19234. }
  19235. } // build geometry
  19236. _this.setIndex(indices);
  19237. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19238. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19239. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19240. return _this;
  19241. }
  19242. return SphereGeometry;
  19243. }(BufferGeometry);
  19244. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  19245. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  19246. function TetrahedronGeometry(radius, detail) {
  19247. var _this;
  19248. if (radius === void 0) {
  19249. radius = 1;
  19250. }
  19251. if (detail === void 0) {
  19252. detail = 0;
  19253. }
  19254. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19255. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19256. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  19257. _this.type = 'TetrahedronGeometry';
  19258. _this.parameters = {
  19259. radius: radius,
  19260. detail: detail
  19261. };
  19262. return _this;
  19263. }
  19264. return TetrahedronGeometry;
  19265. }(PolyhedronGeometry);
  19266. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  19267. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  19268. function TextGeometry(text, parameters) {
  19269. var _this;
  19270. if (parameters === void 0) {
  19271. parameters = {};
  19272. }
  19273. var font = parameters.font;
  19274. if (!(font && font.isFont)) {
  19275. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19276. return new BufferGeometry() || _assertThisInitialized(_this);
  19277. }
  19278. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19279. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19280. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19281. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19282. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19283. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  19284. _this.type = 'TextGeometry';
  19285. return _this;
  19286. }
  19287. return TextGeometry;
  19288. }(ExtrudeGeometry);
  19289. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19290. _inheritsLoose(TorusGeometry, _BufferGeometry);
  19291. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19292. var _this;
  19293. if (radius === void 0) {
  19294. radius = 1;
  19295. }
  19296. if (tube === void 0) {
  19297. tube = 0.4;
  19298. }
  19299. if (radialSegments === void 0) {
  19300. radialSegments = 8;
  19301. }
  19302. if (tubularSegments === void 0) {
  19303. tubularSegments = 6;
  19304. }
  19305. if (arc === void 0) {
  19306. arc = Math.PI * 2;
  19307. }
  19308. _this = _BufferGeometry.call(this) || this;
  19309. _this.type = 'TorusGeometry';
  19310. _this.parameters = {
  19311. radius: radius,
  19312. tube: tube,
  19313. radialSegments: radialSegments,
  19314. tubularSegments: tubularSegments,
  19315. arc: arc
  19316. };
  19317. radialSegments = Math.floor(radialSegments);
  19318. tubularSegments = Math.floor(tubularSegments); // buffers
  19319. var indices = [];
  19320. var vertices = [];
  19321. var normals = [];
  19322. var uvs = []; // helper variables
  19323. var center = new Vector3();
  19324. var vertex = new Vector3();
  19325. var normal = new Vector3(); // generate vertices, normals and uvs
  19326. for (var j = 0; j <= radialSegments; j++) {
  19327. for (var i = 0; i <= tubularSegments; i++) {
  19328. var u = i / tubularSegments * arc;
  19329. var v = j / radialSegments * Math.PI * 2; // vertex
  19330. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19331. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19332. vertex.z = tube * Math.sin(v);
  19333. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19334. center.x = radius * Math.cos(u);
  19335. center.y = radius * Math.sin(u);
  19336. normal.subVectors(vertex, center).normalize();
  19337. normals.push(normal.x, normal.y, normal.z); // uv
  19338. uvs.push(i / tubularSegments);
  19339. uvs.push(j / radialSegments);
  19340. }
  19341. } // generate indices
  19342. for (var _j = 1; _j <= radialSegments; _j++) {
  19343. for (var _i = 1; _i <= tubularSegments; _i++) {
  19344. // indices
  19345. var a = (tubularSegments + 1) * _j + _i - 1;
  19346. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19347. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19348. var d = (tubularSegments + 1) * _j + _i; // faces
  19349. indices.push(a, b, d);
  19350. indices.push(b, c, d);
  19351. }
  19352. } // build geometry
  19353. _this.setIndex(indices);
  19354. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19355. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19356. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19357. return _this;
  19358. }
  19359. return TorusGeometry;
  19360. }(BufferGeometry);
  19361. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19362. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  19363. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19364. var _this;
  19365. if (radius === void 0) {
  19366. radius = 1;
  19367. }
  19368. if (tube === void 0) {
  19369. tube = 0.4;
  19370. }
  19371. if (tubularSegments === void 0) {
  19372. tubularSegments = 64;
  19373. }
  19374. if (radialSegments === void 0) {
  19375. radialSegments = 8;
  19376. }
  19377. if (p === void 0) {
  19378. p = 2;
  19379. }
  19380. if (q === void 0) {
  19381. q = 3;
  19382. }
  19383. _this = _BufferGeometry.call(this) || this;
  19384. _this.type = 'TorusKnotGeometry';
  19385. _this.parameters = {
  19386. radius: radius,
  19387. tube: tube,
  19388. tubularSegments: tubularSegments,
  19389. radialSegments: radialSegments,
  19390. p: p,
  19391. q: q
  19392. };
  19393. tubularSegments = Math.floor(tubularSegments);
  19394. radialSegments = Math.floor(radialSegments); // buffers
  19395. var indices = [];
  19396. var vertices = [];
  19397. var normals = [];
  19398. var uvs = []; // helper variables
  19399. var vertex = new Vector3();
  19400. var normal = new Vector3();
  19401. var P1 = new Vector3();
  19402. var P2 = new Vector3();
  19403. var B = new Vector3();
  19404. var T = new Vector3();
  19405. var N = new Vector3(); // generate vertices, normals and uvs
  19406. for (var i = 0; i <= tubularSegments; ++i) {
  19407. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19408. var u = i / tubularSegments * p * Math.PI * 2; // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  19409. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19410. calculatePositionOnCurve(u, p, q, radius, P1);
  19411. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19412. T.subVectors(P2, P1);
  19413. N.addVectors(P2, P1);
  19414. B.crossVectors(T, N);
  19415. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19416. B.normalize();
  19417. N.normalize();
  19418. for (var j = 0; j <= radialSegments; ++j) {
  19419. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19420. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19421. var v = j / radialSegments * Math.PI * 2;
  19422. var cx = -tube * Math.cos(v);
  19423. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19424. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19425. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19426. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19427. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19428. vertices.push(vertex.x, vertex.y, vertex.z); // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  19429. normal.subVectors(vertex, P1).normalize();
  19430. normals.push(normal.x, normal.y, normal.z); // uv
  19431. uvs.push(i / tubularSegments);
  19432. uvs.push(j / radialSegments);
  19433. }
  19434. } // generate indices
  19435. for (var _j = 1; _j <= tubularSegments; _j++) {
  19436. for (var _i = 1; _i <= radialSegments; _i++) {
  19437. // indices
  19438. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19439. var b = (radialSegments + 1) * _j + (_i - 1);
  19440. var c = (radialSegments + 1) * _j + _i;
  19441. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19442. indices.push(a, b, d);
  19443. indices.push(b, c, d);
  19444. }
  19445. } // build geometry
  19446. _this.setIndex(indices);
  19447. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19448. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19449. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19450. function calculatePositionOnCurve(u, p, q, radius, position) {
  19451. var cu = Math.cos(u);
  19452. var su = Math.sin(u);
  19453. var quOverP = q / p * u;
  19454. var cs = Math.cos(quOverP);
  19455. position.x = radius * (2 + cs) * 0.5 * cu;
  19456. position.y = radius * (2 + cs) * su * 0.5;
  19457. position.z = radius * Math.sin(quOverP) * 0.5;
  19458. }
  19459. return _this;
  19460. }
  19461. return TorusKnotGeometry;
  19462. }(BufferGeometry);
  19463. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19464. _inheritsLoose(TubeGeometry, _BufferGeometry);
  19465. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19466. var _this;
  19467. if (tubularSegments === void 0) {
  19468. tubularSegments = 64;
  19469. }
  19470. if (radius === void 0) {
  19471. radius = 1;
  19472. }
  19473. if (radialSegments === void 0) {
  19474. radialSegments = 8;
  19475. }
  19476. if (closed === void 0) {
  19477. closed = false;
  19478. }
  19479. _this = _BufferGeometry.call(this) || this;
  19480. _this.type = 'TubeGeometry';
  19481. _this.parameters = {
  19482. path: path,
  19483. tubularSegments: tubularSegments,
  19484. radius: radius,
  19485. radialSegments: radialSegments,
  19486. closed: closed
  19487. };
  19488. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19489. _this.tangents = frames.tangents;
  19490. _this.normals = frames.normals;
  19491. _this.binormals = frames.binormals; // helper variables
  19492. var vertex = new Vector3();
  19493. var normal = new Vector3();
  19494. var uv = new Vector2();
  19495. var P = new Vector3(); // buffer
  19496. var vertices = [];
  19497. var normals = [];
  19498. var uvs = [];
  19499. var indices = []; // create buffer data
  19500. generateBufferData(); // build geometry
  19501. _this.setIndex(indices);
  19502. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19503. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19504. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19505. function generateBufferData() {
  19506. for (var i = 0; i < tubularSegments; i++) {
  19507. generateSegment(i);
  19508. } // if the geometry is not closed, generate the last row of vertices and normals
  19509. // at the regular position on the given path
  19510. //
  19511. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19512. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19513. // this makes it easy compute correct values for closed geometries
  19514. generateUVs(); // finally create faces
  19515. generateIndices();
  19516. }
  19517. function generateSegment(i) {
  19518. // we use getPointAt to sample evenly distributed points from the given path
  19519. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19520. var N = frames.normals[i];
  19521. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19522. for (var j = 0; j <= radialSegments; j++) {
  19523. var v = j / radialSegments * Math.PI * 2;
  19524. var sin = Math.sin(v);
  19525. var cos = -Math.cos(v); // normal
  19526. normal.x = cos * N.x + sin * B.x;
  19527. normal.y = cos * N.y + sin * B.y;
  19528. normal.z = cos * N.z + sin * B.z;
  19529. normal.normalize();
  19530. normals.push(normal.x, normal.y, normal.z); // vertex
  19531. vertex.x = P.x + radius * normal.x;
  19532. vertex.y = P.y + radius * normal.y;
  19533. vertex.z = P.z + radius * normal.z;
  19534. vertices.push(vertex.x, vertex.y, vertex.z);
  19535. }
  19536. }
  19537. function generateIndices() {
  19538. for (var j = 1; j <= tubularSegments; j++) {
  19539. for (var i = 1; i <= radialSegments; i++) {
  19540. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19541. var b = (radialSegments + 1) * j + (i - 1);
  19542. var c = (radialSegments + 1) * j + i;
  19543. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19544. indices.push(a, b, d);
  19545. indices.push(b, c, d);
  19546. }
  19547. }
  19548. }
  19549. function generateUVs() {
  19550. for (var i = 0; i <= tubularSegments; i++) {
  19551. for (var j = 0; j <= radialSegments; j++) {
  19552. uv.x = i / tubularSegments;
  19553. uv.y = j / radialSegments;
  19554. uvs.push(uv.x, uv.y);
  19555. }
  19556. }
  19557. }
  19558. return _this;
  19559. }
  19560. var _proto = TubeGeometry.prototype;
  19561. _proto.toJSON = function toJSON() {
  19562. var data = BufferGeometry.prototype.toJSON.call(this);
  19563. data.path = this.parameters.path.toJSON();
  19564. return data;
  19565. };
  19566. return TubeGeometry;
  19567. }(BufferGeometry);
  19568. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19569. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19570. function WireframeGeometry(geometry) {
  19571. var _this;
  19572. _this = _BufferGeometry.call(this) || this;
  19573. _this.type = 'WireframeGeometry';
  19574. if (geometry.isGeometry === true) {
  19575. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  19576. return _assertThisInitialized(_this);
  19577. } // buffer
  19578. var vertices = []; // helper variables
  19579. var edge = [0, 0],
  19580. edges = {};
  19581. var vertex = new Vector3();
  19582. if (geometry.index !== null) {
  19583. // indexed BufferGeometry
  19584. var position = geometry.attributes.position;
  19585. var indices = geometry.index;
  19586. var groups = geometry.groups;
  19587. if (groups.length === 0) {
  19588. groups = [{
  19589. start: 0,
  19590. count: indices.count,
  19591. materialIndex: 0
  19592. }];
  19593. } // create a data structure that contains all eges without duplicates
  19594. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19595. var group = groups[o];
  19596. var start = group.start;
  19597. var count = group.count;
  19598. for (var i = start, l = start + count; i < l; i += 3) {
  19599. for (var j = 0; j < 3; j++) {
  19600. var edge1 = indices.getX(i + j);
  19601. var edge2 = indices.getX(i + (j + 1) % 3);
  19602. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19603. edge[1] = Math.max(edge1, edge2);
  19604. var key = edge[0] + ',' + edge[1];
  19605. if (edges[key] === undefined) {
  19606. edges[key] = {
  19607. index1: edge[0],
  19608. index2: edge[1]
  19609. };
  19610. }
  19611. }
  19612. }
  19613. } // generate vertices
  19614. for (var _key in edges) {
  19615. var e = edges[_key];
  19616. vertex.fromBufferAttribute(position, e.index1);
  19617. vertices.push(vertex.x, vertex.y, vertex.z);
  19618. vertex.fromBufferAttribute(position, e.index2);
  19619. vertices.push(vertex.x, vertex.y, vertex.z);
  19620. }
  19621. } else {
  19622. // non-indexed BufferGeometry
  19623. var _position = geometry.attributes.position;
  19624. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  19625. for (var _j = 0; _j < 3; _j++) {
  19626. // three edges per triangle, an edge is represented as (index1, index2)
  19627. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19628. var index1 = 3 * _i + _j;
  19629. vertex.fromBufferAttribute(_position, index1);
  19630. vertices.push(vertex.x, vertex.y, vertex.z);
  19631. var index2 = 3 * _i + (_j + 1) % 3;
  19632. vertex.fromBufferAttribute(_position, index2);
  19633. vertices.push(vertex.x, vertex.y, vertex.z);
  19634. }
  19635. }
  19636. } // build geometry
  19637. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19638. return _this;
  19639. }
  19640. return WireframeGeometry;
  19641. }(BufferGeometry);
  19642. var Geometries = /*#__PURE__*/Object.freeze({
  19643. __proto__: null,
  19644. BoxGeometry: BoxGeometry,
  19645. BoxBufferGeometry: BoxGeometry,
  19646. CircleGeometry: CircleGeometry,
  19647. CircleBufferGeometry: CircleGeometry,
  19648. ConeGeometry: ConeGeometry,
  19649. ConeBufferGeometry: ConeGeometry,
  19650. CylinderGeometry: CylinderGeometry,
  19651. CylinderBufferGeometry: CylinderGeometry,
  19652. DodecahedronGeometry: DodecahedronGeometry,
  19653. DodecahedronBufferGeometry: DodecahedronGeometry,
  19654. EdgesGeometry: EdgesGeometry,
  19655. ExtrudeGeometry: ExtrudeGeometry,
  19656. ExtrudeBufferGeometry: ExtrudeGeometry,
  19657. IcosahedronGeometry: IcosahedronGeometry,
  19658. IcosahedronBufferGeometry: IcosahedronGeometry,
  19659. LatheGeometry: LatheGeometry,
  19660. LatheBufferGeometry: LatheGeometry,
  19661. OctahedronGeometry: OctahedronGeometry,
  19662. OctahedronBufferGeometry: OctahedronGeometry,
  19663. ParametricGeometry: ParametricGeometry,
  19664. ParametricBufferGeometry: ParametricGeometry,
  19665. PlaneGeometry: PlaneGeometry,
  19666. PlaneBufferGeometry: PlaneGeometry,
  19667. PolyhedronGeometry: PolyhedronGeometry,
  19668. PolyhedronBufferGeometry: PolyhedronGeometry,
  19669. RingGeometry: RingGeometry,
  19670. RingBufferGeometry: RingGeometry,
  19671. ShapeGeometry: ShapeGeometry,
  19672. ShapeBufferGeometry: ShapeGeometry,
  19673. SphereGeometry: SphereGeometry,
  19674. SphereBufferGeometry: SphereGeometry,
  19675. TetrahedronGeometry: TetrahedronGeometry,
  19676. TetrahedronBufferGeometry: TetrahedronGeometry,
  19677. TextGeometry: TextGeometry,
  19678. TextBufferGeometry: TextGeometry,
  19679. TorusGeometry: TorusGeometry,
  19680. TorusBufferGeometry: TorusGeometry,
  19681. TorusKnotGeometry: TorusKnotGeometry,
  19682. TorusKnotBufferGeometry: TorusKnotGeometry,
  19683. TubeGeometry: TubeGeometry,
  19684. TubeBufferGeometry: TubeGeometry,
  19685. WireframeGeometry: WireframeGeometry
  19686. });
  19687. /**
  19688. * parameters = {
  19689. * color: <THREE.Color>
  19690. * }
  19691. */
  19692. var ShadowMaterial = /*#__PURE__*/function (_Material) {
  19693. _inheritsLoose(ShadowMaterial, _Material);
  19694. function ShadowMaterial(parameters) {
  19695. var _this;
  19696. _this = _Material.call(this) || this;
  19697. _this.type = 'ShadowMaterial';
  19698. _this.color = new Color(0x000000);
  19699. _this.transparent = true;
  19700. _this.setValues(parameters);
  19701. return _this;
  19702. }
  19703. var _proto = ShadowMaterial.prototype;
  19704. _proto.copy = function copy(source) {
  19705. _Material.prototype.copy.call(this, source);
  19706. this.color.copy(source.color);
  19707. return this;
  19708. };
  19709. return ShadowMaterial;
  19710. }(Material);
  19711. ShadowMaterial.prototype.isShadowMaterial = true;
  19712. var RawShaderMaterial = /*#__PURE__*/function (_ShaderMaterial) {
  19713. _inheritsLoose(RawShaderMaterial, _ShaderMaterial);
  19714. function RawShaderMaterial(parameters) {
  19715. var _this;
  19716. _this = _ShaderMaterial.call(this, parameters) || this;
  19717. _this.type = 'RawShaderMaterial';
  19718. return _this;
  19719. }
  19720. return RawShaderMaterial;
  19721. }(ShaderMaterial);
  19722. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19723. /**
  19724. * parameters = {
  19725. * color: <hex>,
  19726. * roughness: <float>,
  19727. * metalness: <float>,
  19728. * opacity: <float>,
  19729. *
  19730. * map: new THREE.Texture( <Image> ),
  19731. *
  19732. * lightMap: new THREE.Texture( <Image> ),
  19733. * lightMapIntensity: <float>
  19734. *
  19735. * aoMap: new THREE.Texture( <Image> ),
  19736. * aoMapIntensity: <float>
  19737. *
  19738. * emissive: <hex>,
  19739. * emissiveIntensity: <float>
  19740. * emissiveMap: new THREE.Texture( <Image> ),
  19741. *
  19742. * bumpMap: new THREE.Texture( <Image> ),
  19743. * bumpScale: <float>,
  19744. *
  19745. * normalMap: new THREE.Texture( <Image> ),
  19746. * normalMapType: THREE.TangentSpaceNormalMap,
  19747. * normalScale: <Vector2>,
  19748. *
  19749. * displacementMap: new THREE.Texture( <Image> ),
  19750. * displacementScale: <float>,
  19751. * displacementBias: <float>,
  19752. *
  19753. * roughnessMap: new THREE.Texture( <Image> ),
  19754. *
  19755. * metalnessMap: new THREE.Texture( <Image> ),
  19756. *
  19757. * alphaMap: new THREE.Texture( <Image> ),
  19758. *
  19759. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19760. * envMapIntensity: <float>
  19761. *
  19762. * refractionRatio: <float>,
  19763. *
  19764. * wireframe: <boolean>,
  19765. * wireframeLinewidth: <float>,
  19766. *
  19767. * skinning: <bool>,
  19768. * morphTargets: <bool>,
  19769. * morphNormals: <bool>,
  19770. *
  19771. * flatShading: <bool>
  19772. * }
  19773. */
  19774. function MeshStandardMaterial(parameters) {
  19775. Material.call(this);
  19776. this.defines = {
  19777. 'STANDARD': ''
  19778. };
  19779. this.type = 'MeshStandardMaterial';
  19780. this.color = new Color(0xffffff); // diffuse
  19781. this.roughness = 1.0;
  19782. this.metalness = 0.0;
  19783. this.map = null;
  19784. this.lightMap = null;
  19785. this.lightMapIntensity = 1.0;
  19786. this.aoMap = null;
  19787. this.aoMapIntensity = 1.0;
  19788. this.emissive = new Color(0x000000);
  19789. this.emissiveIntensity = 1.0;
  19790. this.emissiveMap = null;
  19791. this.bumpMap = null;
  19792. this.bumpScale = 1;
  19793. this.normalMap = null;
  19794. this.normalMapType = TangentSpaceNormalMap;
  19795. this.normalScale = new Vector2(1, 1);
  19796. this.displacementMap = null;
  19797. this.displacementScale = 1;
  19798. this.displacementBias = 0;
  19799. this.roughnessMap = null;
  19800. this.metalnessMap = null;
  19801. this.alphaMap = null;
  19802. this.envMap = null;
  19803. this.envMapIntensity = 1.0;
  19804. this.refractionRatio = 0.98;
  19805. this.wireframe = false;
  19806. this.wireframeLinewidth = 1;
  19807. this.wireframeLinecap = 'round';
  19808. this.wireframeLinejoin = 'round';
  19809. this.skinning = false;
  19810. this.morphTargets = false;
  19811. this.morphNormals = false;
  19812. this.flatShading = false;
  19813. this.vertexTangents = false;
  19814. this.setValues(parameters);
  19815. }
  19816. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19817. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19818. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19819. MeshStandardMaterial.prototype.copy = function (source) {
  19820. Material.prototype.copy.call(this, source);
  19821. this.defines = {
  19822. 'STANDARD': ''
  19823. };
  19824. this.color.copy(source.color);
  19825. this.roughness = source.roughness;
  19826. this.metalness = source.metalness;
  19827. this.map = source.map;
  19828. this.lightMap = source.lightMap;
  19829. this.lightMapIntensity = source.lightMapIntensity;
  19830. this.aoMap = source.aoMap;
  19831. this.aoMapIntensity = source.aoMapIntensity;
  19832. this.emissive.copy(source.emissive);
  19833. this.emissiveMap = source.emissiveMap;
  19834. this.emissiveIntensity = source.emissiveIntensity;
  19835. this.bumpMap = source.bumpMap;
  19836. this.bumpScale = source.bumpScale;
  19837. this.normalMap = source.normalMap;
  19838. this.normalMapType = source.normalMapType;
  19839. this.normalScale.copy(source.normalScale);
  19840. this.displacementMap = source.displacementMap;
  19841. this.displacementScale = source.displacementScale;
  19842. this.displacementBias = source.displacementBias;
  19843. this.roughnessMap = source.roughnessMap;
  19844. this.metalnessMap = source.metalnessMap;
  19845. this.alphaMap = source.alphaMap;
  19846. this.envMap = source.envMap;
  19847. this.envMapIntensity = source.envMapIntensity;
  19848. this.refractionRatio = source.refractionRatio;
  19849. this.wireframe = source.wireframe;
  19850. this.wireframeLinewidth = source.wireframeLinewidth;
  19851. this.wireframeLinecap = source.wireframeLinecap;
  19852. this.wireframeLinejoin = source.wireframeLinejoin;
  19853. this.skinning = source.skinning;
  19854. this.morphTargets = source.morphTargets;
  19855. this.morphNormals = source.morphNormals;
  19856. this.flatShading = source.flatShading;
  19857. this.vertexTangents = source.vertexTangents;
  19858. return this;
  19859. };
  19860. /**
  19861. * parameters = {
  19862. * clearcoat: <float>,
  19863. * clearcoatMap: new THREE.Texture( <Image> ),
  19864. * clearcoatRoughness: <float>,
  19865. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19866. * clearcoatNormalScale: <Vector2>,
  19867. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19868. *
  19869. * reflectivity: <float>,
  19870. * ior: <float>,
  19871. *
  19872. * sheen: <Color>,
  19873. *
  19874. * transmission: <float>,
  19875. * transmissionMap: new THREE.Texture( <Image> )
  19876. * }
  19877. */
  19878. function MeshPhysicalMaterial(parameters) {
  19879. MeshStandardMaterial.call(this);
  19880. this.defines = {
  19881. 'STANDARD': '',
  19882. 'PHYSICAL': ''
  19883. };
  19884. this.type = 'MeshPhysicalMaterial';
  19885. this.clearcoat = 0.0;
  19886. this.clearcoatMap = null;
  19887. this.clearcoatRoughness = 0.0;
  19888. this.clearcoatRoughnessMap = null;
  19889. this.clearcoatNormalScale = new Vector2(1, 1);
  19890. this.clearcoatNormalMap = null;
  19891. this.reflectivity = 0.5; // maps to F0 = 0.04
  19892. Object.defineProperty(this, 'ior', {
  19893. get: function get() {
  19894. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19895. },
  19896. set: function set(ior) {
  19897. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19898. }
  19899. });
  19900. this.sheen = null; // null will disable sheen bsdf
  19901. this.transmission = 0.0;
  19902. this.transmissionMap = null;
  19903. this.setValues(parameters);
  19904. }
  19905. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19906. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19907. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19908. MeshPhysicalMaterial.prototype.copy = function (source) {
  19909. MeshStandardMaterial.prototype.copy.call(this, source);
  19910. this.defines = {
  19911. 'STANDARD': '',
  19912. 'PHYSICAL': ''
  19913. };
  19914. this.clearcoat = source.clearcoat;
  19915. this.clearcoatMap = source.clearcoatMap;
  19916. this.clearcoatRoughness = source.clearcoatRoughness;
  19917. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19918. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19919. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19920. this.reflectivity = source.reflectivity;
  19921. if (source.sheen) {
  19922. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19923. } else {
  19924. this.sheen = null;
  19925. }
  19926. this.transmission = source.transmission;
  19927. this.transmissionMap = source.transmissionMap;
  19928. return this;
  19929. };
  19930. /**
  19931. * parameters = {
  19932. * color: <hex>,
  19933. * specular: <hex>,
  19934. * shininess: <float>,
  19935. * opacity: <float>,
  19936. *
  19937. * map: new THREE.Texture( <Image> ),
  19938. *
  19939. * lightMap: new THREE.Texture( <Image> ),
  19940. * lightMapIntensity: <float>
  19941. *
  19942. * aoMap: new THREE.Texture( <Image> ),
  19943. * aoMapIntensity: <float>
  19944. *
  19945. * emissive: <hex>,
  19946. * emissiveIntensity: <float>
  19947. * emissiveMap: new THREE.Texture( <Image> ),
  19948. *
  19949. * bumpMap: new THREE.Texture( <Image> ),
  19950. * bumpScale: <float>,
  19951. *
  19952. * normalMap: new THREE.Texture( <Image> ),
  19953. * normalMapType: THREE.TangentSpaceNormalMap,
  19954. * normalScale: <Vector2>,
  19955. *
  19956. * displacementMap: new THREE.Texture( <Image> ),
  19957. * displacementScale: <float>,
  19958. * displacementBias: <float>,
  19959. *
  19960. * specularMap: new THREE.Texture( <Image> ),
  19961. *
  19962. * alphaMap: new THREE.Texture( <Image> ),
  19963. *
  19964. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19965. * combine: THREE.MultiplyOperation,
  19966. * reflectivity: <float>,
  19967. * refractionRatio: <float>,
  19968. *
  19969. * wireframe: <boolean>,
  19970. * wireframeLinewidth: <float>,
  19971. *
  19972. * skinning: <bool>,
  19973. * morphTargets: <bool>,
  19974. * morphNormals: <bool>,
  19975. *
  19976. * flatShading: <bool>
  19977. * }
  19978. */
  19979. var MeshPhongMaterial = /*#__PURE__*/function (_Material) {
  19980. _inheritsLoose(MeshPhongMaterial, _Material);
  19981. function MeshPhongMaterial(parameters) {
  19982. var _this;
  19983. _this = _Material.call(this) || this;
  19984. _this.type = 'MeshPhongMaterial';
  19985. _this.color = new Color(0xffffff); // diffuse
  19986. _this.specular = new Color(0x111111);
  19987. _this.shininess = 30;
  19988. _this.map = null;
  19989. _this.lightMap = null;
  19990. _this.lightMapIntensity = 1.0;
  19991. _this.aoMap = null;
  19992. _this.aoMapIntensity = 1.0;
  19993. _this.emissive = new Color(0x000000);
  19994. _this.emissiveIntensity = 1.0;
  19995. _this.emissiveMap = null;
  19996. _this.bumpMap = null;
  19997. _this.bumpScale = 1;
  19998. _this.normalMap = null;
  19999. _this.normalMapType = TangentSpaceNormalMap;
  20000. _this.normalScale = new Vector2(1, 1);
  20001. _this.displacementMap = null;
  20002. _this.displacementScale = 1;
  20003. _this.displacementBias = 0;
  20004. _this.specularMap = null;
  20005. _this.alphaMap = null;
  20006. _this.envMap = null;
  20007. _this.combine = MultiplyOperation;
  20008. _this.reflectivity = 1;
  20009. _this.refractionRatio = 0.98;
  20010. _this.wireframe = false;
  20011. _this.wireframeLinewidth = 1;
  20012. _this.wireframeLinecap = 'round';
  20013. _this.wireframeLinejoin = 'round';
  20014. _this.skinning = false;
  20015. _this.morphTargets = false;
  20016. _this.morphNormals = false;
  20017. _this.flatShading = false;
  20018. _this.setValues(parameters);
  20019. return _this;
  20020. }
  20021. var _proto = MeshPhongMaterial.prototype;
  20022. _proto.copy = function copy(source) {
  20023. _Material.prototype.copy.call(this, source);
  20024. this.color.copy(source.color);
  20025. this.specular.copy(source.specular);
  20026. this.shininess = source.shininess;
  20027. this.map = source.map;
  20028. this.lightMap = source.lightMap;
  20029. this.lightMapIntensity = source.lightMapIntensity;
  20030. this.aoMap = source.aoMap;
  20031. this.aoMapIntensity = source.aoMapIntensity;
  20032. this.emissive.copy(source.emissive);
  20033. this.emissiveMap = source.emissiveMap;
  20034. this.emissiveIntensity = source.emissiveIntensity;
  20035. this.bumpMap = source.bumpMap;
  20036. this.bumpScale = source.bumpScale;
  20037. this.normalMap = source.normalMap;
  20038. this.normalMapType = source.normalMapType;
  20039. this.normalScale.copy(source.normalScale);
  20040. this.displacementMap = source.displacementMap;
  20041. this.displacementScale = source.displacementScale;
  20042. this.displacementBias = source.displacementBias;
  20043. this.specularMap = source.specularMap;
  20044. this.alphaMap = source.alphaMap;
  20045. this.envMap = source.envMap;
  20046. this.combine = source.combine;
  20047. this.reflectivity = source.reflectivity;
  20048. this.refractionRatio = source.refractionRatio;
  20049. this.wireframe = source.wireframe;
  20050. this.wireframeLinewidth = source.wireframeLinewidth;
  20051. this.wireframeLinecap = source.wireframeLinecap;
  20052. this.wireframeLinejoin = source.wireframeLinejoin;
  20053. this.skinning = source.skinning;
  20054. this.morphTargets = source.morphTargets;
  20055. this.morphNormals = source.morphNormals;
  20056. this.flatShading = source.flatShading;
  20057. return this;
  20058. };
  20059. return MeshPhongMaterial;
  20060. }(Material);
  20061. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20062. /**
  20063. * parameters = {
  20064. * color: <hex>,
  20065. *
  20066. * map: new THREE.Texture( <Image> ),
  20067. * gradientMap: new THREE.Texture( <Image> ),
  20068. *
  20069. * lightMap: new THREE.Texture( <Image> ),
  20070. * lightMapIntensity: <float>
  20071. *
  20072. * aoMap: new THREE.Texture( <Image> ),
  20073. * aoMapIntensity: <float>
  20074. *
  20075. * emissive: <hex>,
  20076. * emissiveIntensity: <float>
  20077. * emissiveMap: new THREE.Texture( <Image> ),
  20078. *
  20079. * bumpMap: new THREE.Texture( <Image> ),
  20080. * bumpScale: <float>,
  20081. *
  20082. * normalMap: new THREE.Texture( <Image> ),
  20083. * normalMapType: THREE.TangentSpaceNormalMap,
  20084. * normalScale: <Vector2>,
  20085. *
  20086. * displacementMap: new THREE.Texture( <Image> ),
  20087. * displacementScale: <float>,
  20088. * displacementBias: <float>,
  20089. *
  20090. * alphaMap: new THREE.Texture( <Image> ),
  20091. *
  20092. * wireframe: <boolean>,
  20093. * wireframeLinewidth: <float>,
  20094. *
  20095. * skinning: <bool>,
  20096. * morphTargets: <bool>,
  20097. * morphNormals: <bool>
  20098. * }
  20099. */
  20100. var MeshToonMaterial = /*#__PURE__*/function (_Material) {
  20101. _inheritsLoose(MeshToonMaterial, _Material);
  20102. function MeshToonMaterial(parameters) {
  20103. var _this;
  20104. _this = _Material.call(this) || this;
  20105. _this.defines = {
  20106. 'TOON': ''
  20107. };
  20108. _this.type = 'MeshToonMaterial';
  20109. _this.color = new Color(0xffffff);
  20110. _this.map = null;
  20111. _this.gradientMap = null;
  20112. _this.lightMap = null;
  20113. _this.lightMapIntensity = 1.0;
  20114. _this.aoMap = null;
  20115. _this.aoMapIntensity = 1.0;
  20116. _this.emissive = new Color(0x000000);
  20117. _this.emissiveIntensity = 1.0;
  20118. _this.emissiveMap = null;
  20119. _this.bumpMap = null;
  20120. _this.bumpScale = 1;
  20121. _this.normalMap = null;
  20122. _this.normalMapType = TangentSpaceNormalMap;
  20123. _this.normalScale = new Vector2(1, 1);
  20124. _this.displacementMap = null;
  20125. _this.displacementScale = 1;
  20126. _this.displacementBias = 0;
  20127. _this.alphaMap = null;
  20128. _this.wireframe = false;
  20129. _this.wireframeLinewidth = 1;
  20130. _this.wireframeLinecap = 'round';
  20131. _this.wireframeLinejoin = 'round';
  20132. _this.skinning = false;
  20133. _this.morphTargets = false;
  20134. _this.morphNormals = false;
  20135. _this.setValues(parameters);
  20136. return _this;
  20137. }
  20138. var _proto = MeshToonMaterial.prototype;
  20139. _proto.copy = function copy(source) {
  20140. _Material.prototype.copy.call(this, source);
  20141. this.color.copy(source.color);
  20142. this.map = source.map;
  20143. this.gradientMap = source.gradientMap;
  20144. this.lightMap = source.lightMap;
  20145. this.lightMapIntensity = source.lightMapIntensity;
  20146. this.aoMap = source.aoMap;
  20147. this.aoMapIntensity = source.aoMapIntensity;
  20148. this.emissive.copy(source.emissive);
  20149. this.emissiveMap = source.emissiveMap;
  20150. this.emissiveIntensity = source.emissiveIntensity;
  20151. this.bumpMap = source.bumpMap;
  20152. this.bumpScale = source.bumpScale;
  20153. this.normalMap = source.normalMap;
  20154. this.normalMapType = source.normalMapType;
  20155. this.normalScale.copy(source.normalScale);
  20156. this.displacementMap = source.displacementMap;
  20157. this.displacementScale = source.displacementScale;
  20158. this.displacementBias = source.displacementBias;
  20159. this.alphaMap = source.alphaMap;
  20160. this.wireframe = source.wireframe;
  20161. this.wireframeLinewidth = source.wireframeLinewidth;
  20162. this.wireframeLinecap = source.wireframeLinecap;
  20163. this.wireframeLinejoin = source.wireframeLinejoin;
  20164. this.skinning = source.skinning;
  20165. this.morphTargets = source.morphTargets;
  20166. this.morphNormals = source.morphNormals;
  20167. return this;
  20168. };
  20169. return MeshToonMaterial;
  20170. }(Material);
  20171. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20172. /**
  20173. * parameters = {
  20174. * opacity: <float>,
  20175. *
  20176. * bumpMap: new THREE.Texture( <Image> ),
  20177. * bumpScale: <float>,
  20178. *
  20179. * normalMap: new THREE.Texture( <Image> ),
  20180. * normalMapType: THREE.TangentSpaceNormalMap,
  20181. * normalScale: <Vector2>,
  20182. *
  20183. * displacementMap: new THREE.Texture( <Image> ),
  20184. * displacementScale: <float>,
  20185. * displacementBias: <float>,
  20186. *
  20187. * wireframe: <boolean>,
  20188. * wireframeLinewidth: <float>
  20189. *
  20190. * skinning: <bool>,
  20191. * morphTargets: <bool>,
  20192. * morphNormals: <bool>,
  20193. *
  20194. * flatShading: <bool>
  20195. * }
  20196. */
  20197. var MeshNormalMaterial = /*#__PURE__*/function (_Material) {
  20198. _inheritsLoose(MeshNormalMaterial, _Material);
  20199. function MeshNormalMaterial(parameters) {
  20200. var _this;
  20201. _this = _Material.call(this) || this;
  20202. _this.type = 'MeshNormalMaterial';
  20203. _this.bumpMap = null;
  20204. _this.bumpScale = 1;
  20205. _this.normalMap = null;
  20206. _this.normalMapType = TangentSpaceNormalMap;
  20207. _this.normalScale = new Vector2(1, 1);
  20208. _this.displacementMap = null;
  20209. _this.displacementScale = 1;
  20210. _this.displacementBias = 0;
  20211. _this.wireframe = false;
  20212. _this.wireframeLinewidth = 1;
  20213. _this.fog = false;
  20214. _this.skinning = false;
  20215. _this.morphTargets = false;
  20216. _this.morphNormals = false;
  20217. _this.flatShading = false;
  20218. _this.setValues(parameters);
  20219. return _this;
  20220. }
  20221. var _proto = MeshNormalMaterial.prototype;
  20222. _proto.copy = function copy(source) {
  20223. _Material.prototype.copy.call(this, source);
  20224. this.bumpMap = source.bumpMap;
  20225. this.bumpScale = source.bumpScale;
  20226. this.normalMap = source.normalMap;
  20227. this.normalMapType = source.normalMapType;
  20228. this.normalScale.copy(source.normalScale);
  20229. this.displacementMap = source.displacementMap;
  20230. this.displacementScale = source.displacementScale;
  20231. this.displacementBias = source.displacementBias;
  20232. this.wireframe = source.wireframe;
  20233. this.wireframeLinewidth = source.wireframeLinewidth;
  20234. this.skinning = source.skinning;
  20235. this.morphTargets = source.morphTargets;
  20236. this.morphNormals = source.morphNormals;
  20237. this.flatShading = source.flatShading;
  20238. return this;
  20239. };
  20240. return MeshNormalMaterial;
  20241. }(Material);
  20242. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20243. /**
  20244. * parameters = {
  20245. * color: <hex>,
  20246. * opacity: <float>,
  20247. *
  20248. * map: new THREE.Texture( <Image> ),
  20249. *
  20250. * lightMap: new THREE.Texture( <Image> ),
  20251. * lightMapIntensity: <float>
  20252. *
  20253. * aoMap: new THREE.Texture( <Image> ),
  20254. * aoMapIntensity: <float>
  20255. *
  20256. * emissive: <hex>,
  20257. * emissiveIntensity: <float>
  20258. * emissiveMap: new THREE.Texture( <Image> ),
  20259. *
  20260. * specularMap: new THREE.Texture( <Image> ),
  20261. *
  20262. * alphaMap: new THREE.Texture( <Image> ),
  20263. *
  20264. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20265. * combine: THREE.Multiply,
  20266. * reflectivity: <float>,
  20267. * refractionRatio: <float>,
  20268. *
  20269. * wireframe: <boolean>,
  20270. * wireframeLinewidth: <float>,
  20271. *
  20272. * skinning: <bool>,
  20273. * morphTargets: <bool>,
  20274. * morphNormals: <bool>
  20275. * }
  20276. */
  20277. var MeshLambertMaterial = /*#__PURE__*/function (_Material) {
  20278. _inheritsLoose(MeshLambertMaterial, _Material);
  20279. function MeshLambertMaterial(parameters) {
  20280. var _this;
  20281. _this = _Material.call(this) || this;
  20282. _this.type = 'MeshLambertMaterial';
  20283. _this.color = new Color(0xffffff); // diffuse
  20284. _this.map = null;
  20285. _this.lightMap = null;
  20286. _this.lightMapIntensity = 1.0;
  20287. _this.aoMap = null;
  20288. _this.aoMapIntensity = 1.0;
  20289. _this.emissive = new Color(0x000000);
  20290. _this.emissiveIntensity = 1.0;
  20291. _this.emissiveMap = null;
  20292. _this.specularMap = null;
  20293. _this.alphaMap = null;
  20294. _this.envMap = null;
  20295. _this.combine = MultiplyOperation;
  20296. _this.reflectivity = 1;
  20297. _this.refractionRatio = 0.98;
  20298. _this.wireframe = false;
  20299. _this.wireframeLinewidth = 1;
  20300. _this.wireframeLinecap = 'round';
  20301. _this.wireframeLinejoin = 'round';
  20302. _this.skinning = false;
  20303. _this.morphTargets = false;
  20304. _this.morphNormals = false;
  20305. _this.setValues(parameters);
  20306. return _this;
  20307. }
  20308. var _proto = MeshLambertMaterial.prototype;
  20309. _proto.copy = function copy(source) {
  20310. _Material.prototype.copy.call(this, source);
  20311. this.color.copy(source.color);
  20312. this.map = source.map;
  20313. this.lightMap = source.lightMap;
  20314. this.lightMapIntensity = source.lightMapIntensity;
  20315. this.aoMap = source.aoMap;
  20316. this.aoMapIntensity = source.aoMapIntensity;
  20317. this.emissive.copy(source.emissive);
  20318. this.emissiveMap = source.emissiveMap;
  20319. this.emissiveIntensity = source.emissiveIntensity;
  20320. this.specularMap = source.specularMap;
  20321. this.alphaMap = source.alphaMap;
  20322. this.envMap = source.envMap;
  20323. this.combine = source.combine;
  20324. this.reflectivity = source.reflectivity;
  20325. this.refractionRatio = source.refractionRatio;
  20326. this.wireframe = source.wireframe;
  20327. this.wireframeLinewidth = source.wireframeLinewidth;
  20328. this.wireframeLinecap = source.wireframeLinecap;
  20329. this.wireframeLinejoin = source.wireframeLinejoin;
  20330. this.skinning = source.skinning;
  20331. this.morphTargets = source.morphTargets;
  20332. this.morphNormals = source.morphNormals;
  20333. return this;
  20334. };
  20335. return MeshLambertMaterial;
  20336. }(Material);
  20337. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20338. /**
  20339. * parameters = {
  20340. * color: <hex>,
  20341. * opacity: <float>,
  20342. *
  20343. * matcap: new THREE.Texture( <Image> ),
  20344. *
  20345. * map: new THREE.Texture( <Image> ),
  20346. *
  20347. * bumpMap: new THREE.Texture( <Image> ),
  20348. * bumpScale: <float>,
  20349. *
  20350. * normalMap: new THREE.Texture( <Image> ),
  20351. * normalMapType: THREE.TangentSpaceNormalMap,
  20352. * normalScale: <Vector2>,
  20353. *
  20354. * displacementMap: new THREE.Texture( <Image> ),
  20355. * displacementScale: <float>,
  20356. * displacementBias: <float>,
  20357. *
  20358. * alphaMap: new THREE.Texture( <Image> ),
  20359. *
  20360. * skinning: <bool>,
  20361. * morphTargets: <bool>,
  20362. * morphNormals: <bool>
  20363. *
  20364. * flatShading: <bool>
  20365. * }
  20366. */
  20367. var MeshMatcapMaterial = /*#__PURE__*/function (_Material) {
  20368. _inheritsLoose(MeshMatcapMaterial, _Material);
  20369. function MeshMatcapMaterial(parameters) {
  20370. var _this;
  20371. _this = _Material.call(this) || this;
  20372. _this.defines = {
  20373. 'MATCAP': ''
  20374. };
  20375. _this.type = 'MeshMatcapMaterial';
  20376. _this.color = new Color(0xffffff); // diffuse
  20377. _this.matcap = null;
  20378. _this.map = null;
  20379. _this.bumpMap = null;
  20380. _this.bumpScale = 1;
  20381. _this.normalMap = null;
  20382. _this.normalMapType = TangentSpaceNormalMap;
  20383. _this.normalScale = new Vector2(1, 1);
  20384. _this.displacementMap = null;
  20385. _this.displacementScale = 1;
  20386. _this.displacementBias = 0;
  20387. _this.alphaMap = null;
  20388. _this.skinning = false;
  20389. _this.morphTargets = false;
  20390. _this.morphNormals = false;
  20391. _this.flatShading = false;
  20392. _this.setValues(parameters);
  20393. return _this;
  20394. }
  20395. var _proto = MeshMatcapMaterial.prototype;
  20396. _proto.copy = function copy(source) {
  20397. _Material.prototype.copy.call(this, source);
  20398. this.defines = {
  20399. 'MATCAP': ''
  20400. };
  20401. this.color.copy(source.color);
  20402. this.matcap = source.matcap;
  20403. this.map = source.map;
  20404. this.bumpMap = source.bumpMap;
  20405. this.bumpScale = source.bumpScale;
  20406. this.normalMap = source.normalMap;
  20407. this.normalMapType = source.normalMapType;
  20408. this.normalScale.copy(source.normalScale);
  20409. this.displacementMap = source.displacementMap;
  20410. this.displacementScale = source.displacementScale;
  20411. this.displacementBias = source.displacementBias;
  20412. this.alphaMap = source.alphaMap;
  20413. this.skinning = source.skinning;
  20414. this.morphTargets = source.morphTargets;
  20415. this.morphNormals = source.morphNormals;
  20416. this.flatShading = source.flatShading;
  20417. return this;
  20418. };
  20419. return MeshMatcapMaterial;
  20420. }(Material);
  20421. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20422. /**
  20423. * parameters = {
  20424. * color: <hex>,
  20425. * opacity: <float>,
  20426. *
  20427. * linewidth: <float>,
  20428. *
  20429. * scale: <float>,
  20430. * dashSize: <float>,
  20431. * gapSize: <float>
  20432. * }
  20433. */
  20434. var LineDashedMaterial = /*#__PURE__*/function (_LineBasicMaterial) {
  20435. _inheritsLoose(LineDashedMaterial, _LineBasicMaterial);
  20436. function LineDashedMaterial(parameters) {
  20437. var _this;
  20438. _this = _LineBasicMaterial.call(this) || this;
  20439. _this.type = 'LineDashedMaterial';
  20440. _this.scale = 1;
  20441. _this.dashSize = 3;
  20442. _this.gapSize = 1;
  20443. _this.setValues(parameters);
  20444. return _this;
  20445. }
  20446. var _proto = LineDashedMaterial.prototype;
  20447. _proto.copy = function copy(source) {
  20448. _LineBasicMaterial.prototype.copy.call(this, source);
  20449. this.scale = source.scale;
  20450. this.dashSize = source.dashSize;
  20451. this.gapSize = source.gapSize;
  20452. return this;
  20453. };
  20454. return LineDashedMaterial;
  20455. }(LineBasicMaterial);
  20456. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20457. var Materials = /*#__PURE__*/Object.freeze({
  20458. __proto__: null,
  20459. ShadowMaterial: ShadowMaterial,
  20460. SpriteMaterial: SpriteMaterial,
  20461. RawShaderMaterial: RawShaderMaterial,
  20462. ShaderMaterial: ShaderMaterial,
  20463. PointsMaterial: PointsMaterial,
  20464. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20465. MeshStandardMaterial: MeshStandardMaterial,
  20466. MeshPhongMaterial: MeshPhongMaterial,
  20467. MeshToonMaterial: MeshToonMaterial,
  20468. MeshNormalMaterial: MeshNormalMaterial,
  20469. MeshLambertMaterial: MeshLambertMaterial,
  20470. MeshDepthMaterial: MeshDepthMaterial,
  20471. MeshDistanceMaterial: MeshDistanceMaterial,
  20472. MeshBasicMaterial: MeshBasicMaterial,
  20473. MeshMatcapMaterial: MeshMatcapMaterial,
  20474. LineDashedMaterial: LineDashedMaterial,
  20475. LineBasicMaterial: LineBasicMaterial,
  20476. Material: Material
  20477. });
  20478. var AnimationUtils = {
  20479. // same as Array.prototype.slice, but also works on typed arrays
  20480. arraySlice: function arraySlice(array, from, to) {
  20481. if (AnimationUtils.isTypedArray(array)) {
  20482. // in ios9 array.subarray(from, undefined) will return empty array
  20483. // but array.subarray(from) or array.subarray(from, len) is correct
  20484. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20485. }
  20486. return array.slice(from, to);
  20487. },
  20488. // converts an array to a specific type
  20489. convertArray: function convertArray(array, type, forceClone) {
  20490. if (!array || // let 'undefined' and 'null' pass
  20491. !forceClone && array.constructor === type) return array;
  20492. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20493. return new type(array); // create typed array
  20494. }
  20495. return Array.prototype.slice.call(array); // create Array
  20496. },
  20497. isTypedArray: function isTypedArray(object) {
  20498. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20499. },
  20500. // returns an array by which times and values can be sorted
  20501. getKeyframeOrder: function getKeyframeOrder(times) {
  20502. function compareTime(i, j) {
  20503. return times[i] - times[j];
  20504. }
  20505. var n = times.length;
  20506. var result = new Array(n);
  20507. for (var i = 0; i !== n; ++i) {
  20508. result[i] = i;
  20509. }
  20510. result.sort(compareTime);
  20511. return result;
  20512. },
  20513. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20514. sortedArray: function sortedArray(values, stride, order) {
  20515. var nValues = values.length;
  20516. var result = new values.constructor(nValues);
  20517. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20518. var srcOffset = order[i] * stride;
  20519. for (var j = 0; j !== stride; ++j) {
  20520. result[dstOffset++] = values[srcOffset + j];
  20521. }
  20522. }
  20523. return result;
  20524. },
  20525. // function for parsing AOS keyframe formats
  20526. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20527. var i = 1,
  20528. key = jsonKeys[0];
  20529. while (key !== undefined && key[valuePropertyName] === undefined) {
  20530. key = jsonKeys[i++];
  20531. }
  20532. if (key === undefined) return; // no data
  20533. var value = key[valuePropertyName];
  20534. if (value === undefined) return; // no data
  20535. if (Array.isArray(value)) {
  20536. do {
  20537. value = key[valuePropertyName];
  20538. if (value !== undefined) {
  20539. times.push(key.time);
  20540. values.push.apply(values, value); // push all elements
  20541. }
  20542. key = jsonKeys[i++];
  20543. } while (key !== undefined);
  20544. } else if (value.toArray !== undefined) {
  20545. // ...assume THREE.Math-ish
  20546. do {
  20547. value = key[valuePropertyName];
  20548. if (value !== undefined) {
  20549. times.push(key.time);
  20550. value.toArray(values, values.length);
  20551. }
  20552. key = jsonKeys[i++];
  20553. } while (key !== undefined);
  20554. } else {
  20555. // otherwise push as-is
  20556. do {
  20557. value = key[valuePropertyName];
  20558. if (value !== undefined) {
  20559. times.push(key.time);
  20560. values.push(value);
  20561. }
  20562. key = jsonKeys[i++];
  20563. } while (key !== undefined);
  20564. }
  20565. },
  20566. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20567. if (fps === void 0) {
  20568. fps = 30;
  20569. }
  20570. var clip = sourceClip.clone();
  20571. clip.name = name;
  20572. var tracks = [];
  20573. for (var i = 0; i < clip.tracks.length; ++i) {
  20574. var track = clip.tracks[i];
  20575. var valueSize = track.getValueSize();
  20576. var times = [];
  20577. var values = [];
  20578. for (var j = 0; j < track.times.length; ++j) {
  20579. var frame = track.times[j] * fps;
  20580. if (frame < startFrame || frame >= endFrame) continue;
  20581. times.push(track.times[j]);
  20582. for (var k = 0; k < valueSize; ++k) {
  20583. values.push(track.values[j * valueSize + k]);
  20584. }
  20585. }
  20586. if (times.length === 0) continue;
  20587. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20588. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20589. tracks.push(track);
  20590. }
  20591. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20592. var minStartTime = Infinity;
  20593. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20594. if (minStartTime > clip.tracks[_i].times[0]) {
  20595. minStartTime = clip.tracks[_i].times[0];
  20596. }
  20597. } // shift all tracks such that clip begins at t=0
  20598. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20599. clip.tracks[_i2].shift(-1 * minStartTime);
  20600. }
  20601. clip.resetDuration();
  20602. return clip;
  20603. },
  20604. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20605. if (referenceFrame === void 0) {
  20606. referenceFrame = 0;
  20607. }
  20608. if (referenceClip === void 0) {
  20609. referenceClip = targetClip;
  20610. }
  20611. if (fps === void 0) {
  20612. fps = 30;
  20613. }
  20614. if (fps <= 0) fps = 30;
  20615. var numTracks = referenceClip.tracks.length;
  20616. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20617. var _loop = function _loop(i) {
  20618. var referenceTrack = referenceClip.tracks[i];
  20619. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20620. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20621. var targetTrack = targetClip.tracks.find(function (track) {
  20622. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20623. });
  20624. if (targetTrack === undefined) return "continue";
  20625. var referenceOffset = 0;
  20626. var referenceValueSize = referenceTrack.getValueSize();
  20627. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20628. referenceOffset = referenceValueSize / 3;
  20629. }
  20630. var targetOffset = 0;
  20631. var targetValueSize = targetTrack.getValueSize();
  20632. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20633. targetOffset = targetValueSize / 3;
  20634. }
  20635. var lastIndex = referenceTrack.times.length - 1;
  20636. var referenceValue = void 0; // Find the value to subtract out of the track
  20637. if (referenceTime <= referenceTrack.times[0]) {
  20638. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20639. var startIndex = referenceOffset;
  20640. var endIndex = referenceValueSize - referenceOffset;
  20641. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20642. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20643. // Reference frame is after the last keyframe, so just use the last keyframe
  20644. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20645. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20646. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20647. } else {
  20648. // Interpolate to the reference value
  20649. var interpolant = referenceTrack.createInterpolant();
  20650. var _startIndex2 = referenceOffset;
  20651. var _endIndex2 = referenceValueSize - referenceOffset;
  20652. interpolant.evaluate(referenceTime);
  20653. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20654. } // Conjugate the quaternion
  20655. if (referenceTrackType === 'quaternion') {
  20656. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20657. referenceQuat.toArray(referenceValue);
  20658. } // Subtract the reference value from all of the track values
  20659. var numTimes = targetTrack.times.length;
  20660. for (var j = 0; j < numTimes; ++j) {
  20661. var valueStart = j * targetValueSize + targetOffset;
  20662. if (referenceTrackType === 'quaternion') {
  20663. // Multiply the conjugate for quaternion track types
  20664. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20665. } else {
  20666. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20667. for (var k = 0; k < valueEnd; ++k) {
  20668. targetTrack.values[valueStart + k] -= referenceValue[k];
  20669. }
  20670. }
  20671. }
  20672. };
  20673. for (var i = 0; i < numTracks; ++i) {
  20674. var _ret = _loop(i);
  20675. if (_ret === "continue") continue;
  20676. }
  20677. targetClip.blendMode = AdditiveAnimationBlendMode;
  20678. return targetClip;
  20679. }
  20680. };
  20681. /**
  20682. * Abstract base class of interpolants over parametric samples.
  20683. *
  20684. * The parameter domain is one dimensional, typically the time or a path
  20685. * along a curve defined by the data.
  20686. *
  20687. * The sample values can have any dimensionality and derived classes may
  20688. * apply special interpretations to the data.
  20689. *
  20690. * This class provides the interval seek in a Template Method, deferring
  20691. * the actual interpolation to derived classes.
  20692. *
  20693. * Time complexity is O(1) for linear access crossing at most two points
  20694. * and O(log N) for random access, where N is the number of positions.
  20695. *
  20696. * References:
  20697. *
  20698. * http://www.oodesign.com/template-method-pattern.html
  20699. *
  20700. */
  20701. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20702. this.parameterPositions = parameterPositions;
  20703. this._cachedIndex = 0;
  20704. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20705. this.sampleValues = sampleValues;
  20706. this.valueSize = sampleSize;
  20707. }
  20708. Object.assign(Interpolant.prototype, {
  20709. evaluate: function evaluate(t) {
  20710. var pp = this.parameterPositions;
  20711. var i1 = this._cachedIndex,
  20712. t1 = pp[i1],
  20713. t0 = pp[i1 - 1];
  20714. validate_interval: {
  20715. seek: {
  20716. var right;
  20717. linear_scan: {
  20718. //- See http://jsperf.com/comparison-to-undefined/3
  20719. //- slower code:
  20720. //-
  20721. //- if ( t >= t1 || t1 === undefined ) {
  20722. forward_scan: if (!(t < t1)) {
  20723. for (var giveUpAt = i1 + 2;;) {
  20724. if (t1 === undefined) {
  20725. if (t < t0) break forward_scan; // after end
  20726. i1 = pp.length;
  20727. this._cachedIndex = i1;
  20728. return this.afterEnd_(i1 - 1, t, t0);
  20729. }
  20730. if (i1 === giveUpAt) break; // this loop
  20731. t0 = t1;
  20732. t1 = pp[++i1];
  20733. if (t < t1) {
  20734. // we have arrived at the sought interval
  20735. break seek;
  20736. }
  20737. } // prepare binary search on the right side of the index
  20738. right = pp.length;
  20739. break linear_scan;
  20740. } //- slower code:
  20741. //- if ( t < t0 || t0 === undefined ) {
  20742. if (!(t >= t0)) {
  20743. // looping?
  20744. var t1global = pp[1];
  20745. if (t < t1global) {
  20746. i1 = 2; // + 1, using the scan for the details
  20747. t0 = t1global;
  20748. } // linear reverse scan
  20749. for (var _giveUpAt = i1 - 2;;) {
  20750. if (t0 === undefined) {
  20751. // before start
  20752. this._cachedIndex = 0;
  20753. return this.beforeStart_(0, t, t1);
  20754. }
  20755. if (i1 === _giveUpAt) break; // this loop
  20756. t1 = t0;
  20757. t0 = pp[--i1 - 1];
  20758. if (t >= t0) {
  20759. // we have arrived at the sought interval
  20760. break seek;
  20761. }
  20762. } // prepare binary search on the left side of the index
  20763. right = i1;
  20764. i1 = 0;
  20765. break linear_scan;
  20766. } // the interval is valid
  20767. break validate_interval;
  20768. } // linear scan
  20769. // binary search
  20770. while (i1 < right) {
  20771. var mid = i1 + right >>> 1;
  20772. if (t < pp[mid]) {
  20773. right = mid;
  20774. } else {
  20775. i1 = mid + 1;
  20776. }
  20777. }
  20778. t1 = pp[i1];
  20779. t0 = pp[i1 - 1]; // check boundary cases, again
  20780. if (t0 === undefined) {
  20781. this._cachedIndex = 0;
  20782. return this.beforeStart_(0, t, t1);
  20783. }
  20784. if (t1 === undefined) {
  20785. i1 = pp.length;
  20786. this._cachedIndex = i1;
  20787. return this.afterEnd_(i1 - 1, t0, t);
  20788. }
  20789. } // seek
  20790. this._cachedIndex = i1;
  20791. this.intervalChanged_(i1, t0, t1);
  20792. } // validate_interval
  20793. return this.interpolate_(i1, t0, t, t1);
  20794. },
  20795. settings: null,
  20796. // optional, subclass-specific settings structure
  20797. // Note: The indirection allows central control of many interpolants.
  20798. // --- Protected interface
  20799. DefaultSettings_: {},
  20800. getSettings_: function getSettings_() {
  20801. return this.settings || this.DefaultSettings_;
  20802. },
  20803. copySampleValue_: function copySampleValue_(index) {
  20804. // copies a sample value to the result buffer
  20805. var result = this.resultBuffer,
  20806. values = this.sampleValues,
  20807. stride = this.valueSize,
  20808. offset = index * stride;
  20809. for (var i = 0; i !== stride; ++i) {
  20810. result[i] = values[offset + i];
  20811. }
  20812. return result;
  20813. },
  20814. // Template methods for derived classes:
  20815. interpolate_: function interpolate_()
  20816. /* i1, t0, t, t1 */
  20817. {
  20818. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20819. },
  20820. intervalChanged_: function intervalChanged_()
  20821. /* i1, t0, t1 */
  20822. {// empty
  20823. }
  20824. }); // DECLARE ALIAS AFTER assign prototype
  20825. Object.assign(Interpolant.prototype, {
  20826. //( 0, t, t0 ), returns this.resultBuffer
  20827. beforeStart_: Interpolant.prototype.copySampleValue_,
  20828. //( N-1, tN-1, t ), returns this.resultBuffer
  20829. afterEnd_: Interpolant.prototype.copySampleValue_
  20830. });
  20831. /**
  20832. * Fast and simple cubic spline interpolant.
  20833. *
  20834. * It was derived from a Hermitian construction setting the first derivative
  20835. * at each sample position to the linear slope between neighboring positions
  20836. * over their parameter interval.
  20837. */
  20838. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20839. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20840. this._weightPrev = -0;
  20841. this._offsetPrev = -0;
  20842. this._weightNext = -0;
  20843. this._offsetNext = -0;
  20844. }
  20845. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20846. constructor: CubicInterpolant,
  20847. DefaultSettings_: {
  20848. endingStart: ZeroCurvatureEnding,
  20849. endingEnd: ZeroCurvatureEnding
  20850. },
  20851. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20852. var pp = this.parameterPositions;
  20853. var iPrev = i1 - 2,
  20854. iNext = i1 + 1,
  20855. tPrev = pp[iPrev],
  20856. tNext = pp[iNext];
  20857. if (tPrev === undefined) {
  20858. switch (this.getSettings_().endingStart) {
  20859. case ZeroSlopeEnding:
  20860. // f'(t0) = 0
  20861. iPrev = i1;
  20862. tPrev = 2 * t0 - t1;
  20863. break;
  20864. case WrapAroundEnding:
  20865. // use the other end of the curve
  20866. iPrev = pp.length - 2;
  20867. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20868. break;
  20869. default:
  20870. // ZeroCurvatureEnding
  20871. // f''(t0) = 0 a.k.a. Natural Spline
  20872. iPrev = i1;
  20873. tPrev = t1;
  20874. }
  20875. }
  20876. if (tNext === undefined) {
  20877. switch (this.getSettings_().endingEnd) {
  20878. case ZeroSlopeEnding:
  20879. // f'(tN) = 0
  20880. iNext = i1;
  20881. tNext = 2 * t1 - t0;
  20882. break;
  20883. case WrapAroundEnding:
  20884. // use the other end of the curve
  20885. iNext = 1;
  20886. tNext = t1 + pp[1] - pp[0];
  20887. break;
  20888. default:
  20889. // ZeroCurvatureEnding
  20890. // f''(tN) = 0, a.k.a. Natural Spline
  20891. iNext = i1 - 1;
  20892. tNext = t0;
  20893. }
  20894. }
  20895. var halfDt = (t1 - t0) * 0.5,
  20896. stride = this.valueSize;
  20897. this._weightPrev = halfDt / (t0 - tPrev);
  20898. this._weightNext = halfDt / (tNext - t1);
  20899. this._offsetPrev = iPrev * stride;
  20900. this._offsetNext = iNext * stride;
  20901. },
  20902. interpolate_: function interpolate_(i1, t0, t, t1) {
  20903. var result = this.resultBuffer,
  20904. values = this.sampleValues,
  20905. stride = this.valueSize,
  20906. o1 = i1 * stride,
  20907. o0 = o1 - stride,
  20908. oP = this._offsetPrev,
  20909. oN = this._offsetNext,
  20910. wP = this._weightPrev,
  20911. wN = this._weightNext,
  20912. p = (t - t0) / (t1 - t0),
  20913. pp = p * p,
  20914. ppp = pp * p; // evaluate polynomials
  20915. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20916. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20917. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20918. var sN = wN * ppp - wN * pp; // combine data linearly
  20919. for (var i = 0; i !== stride; ++i) {
  20920. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20921. }
  20922. return result;
  20923. }
  20924. });
  20925. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20926. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20927. }
  20928. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20929. constructor: LinearInterpolant,
  20930. interpolate_: function interpolate_(i1, t0, t, t1) {
  20931. var result = this.resultBuffer,
  20932. values = this.sampleValues,
  20933. stride = this.valueSize,
  20934. offset1 = i1 * stride,
  20935. offset0 = offset1 - stride,
  20936. weight1 = (t - t0) / (t1 - t0),
  20937. weight0 = 1 - weight1;
  20938. for (var i = 0; i !== stride; ++i) {
  20939. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20940. }
  20941. return result;
  20942. }
  20943. });
  20944. /**
  20945. *
  20946. * Interpolant that evaluates to the sample value at the position preceeding
  20947. * the parameter.
  20948. */
  20949. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20950. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20951. }
  20952. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20953. constructor: DiscreteInterpolant,
  20954. interpolate_: function interpolate_(i1
  20955. /*, t0, t, t1 */
  20956. ) {
  20957. return this.copySampleValue_(i1 - 1);
  20958. }
  20959. });
  20960. var KeyframeTrack = /*#__PURE__*/function () {
  20961. function KeyframeTrack(name, times, values, interpolation) {
  20962. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20963. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20964. this.name = name;
  20965. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20966. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20967. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20968. } // Serialization (in static context, because of constructor invocation
  20969. // and automatic invocation of .toJSON):
  20970. KeyframeTrack.toJSON = function toJSON(track) {
  20971. var trackType = track.constructor;
  20972. var json; // derived classes can define a static toJSON method
  20973. if (trackType.toJSON !== this.toJSON) {
  20974. json = trackType.toJSON(track);
  20975. } else {
  20976. // by default, we assume the data can be serialized as-is
  20977. json = {
  20978. 'name': track.name,
  20979. 'times': AnimationUtils.convertArray(track.times, Array),
  20980. 'values': AnimationUtils.convertArray(track.values, Array)
  20981. };
  20982. var interpolation = track.getInterpolation();
  20983. if (interpolation !== track.DefaultInterpolation) {
  20984. json.interpolation = interpolation;
  20985. }
  20986. }
  20987. json.type = track.ValueTypeName; // mandatory
  20988. return json;
  20989. };
  20990. var _proto = KeyframeTrack.prototype;
  20991. _proto.InterpolantFactoryMethodDiscrete = function InterpolantFactoryMethodDiscrete(result) {
  20992. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20993. };
  20994. _proto.InterpolantFactoryMethodLinear = function InterpolantFactoryMethodLinear(result) {
  20995. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20996. };
  20997. _proto.InterpolantFactoryMethodSmooth = function InterpolantFactoryMethodSmooth(result) {
  20998. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20999. };
  21000. _proto.setInterpolation = function setInterpolation(interpolation) {
  21001. var factoryMethod;
  21002. switch (interpolation) {
  21003. case InterpolateDiscrete:
  21004. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21005. break;
  21006. case InterpolateLinear:
  21007. factoryMethod = this.InterpolantFactoryMethodLinear;
  21008. break;
  21009. case InterpolateSmooth:
  21010. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21011. break;
  21012. }
  21013. if (factoryMethod === undefined) {
  21014. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  21015. if (this.createInterpolant === undefined) {
  21016. // fall back to default, unless the default itself is messed up
  21017. if (interpolation !== this.DefaultInterpolation) {
  21018. this.setInterpolation(this.DefaultInterpolation);
  21019. } else {
  21020. throw new Error(message); // fatal, in this case
  21021. }
  21022. }
  21023. console.warn('THREE.KeyframeTrack:', message);
  21024. return this;
  21025. }
  21026. this.createInterpolant = factoryMethod;
  21027. return this;
  21028. };
  21029. _proto.getInterpolation = function getInterpolation() {
  21030. switch (this.createInterpolant) {
  21031. case this.InterpolantFactoryMethodDiscrete:
  21032. return InterpolateDiscrete;
  21033. case this.InterpolantFactoryMethodLinear:
  21034. return InterpolateLinear;
  21035. case this.InterpolantFactoryMethodSmooth:
  21036. return InterpolateSmooth;
  21037. }
  21038. };
  21039. _proto.getValueSize = function getValueSize() {
  21040. return this.values.length / this.times.length;
  21041. } // move all keyframes either forwards or backwards in time
  21042. ;
  21043. _proto.shift = function shift(timeOffset) {
  21044. if (timeOffset !== 0.0) {
  21045. var times = this.times;
  21046. for (var i = 0, n = times.length; i !== n; ++i) {
  21047. times[i] += timeOffset;
  21048. }
  21049. }
  21050. return this;
  21051. } // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21052. ;
  21053. _proto.scale = function scale(timeScale) {
  21054. if (timeScale !== 1.0) {
  21055. var times = this.times;
  21056. for (var i = 0, n = times.length; i !== n; ++i) {
  21057. times[i] *= timeScale;
  21058. }
  21059. }
  21060. return this;
  21061. } // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21062. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21063. ;
  21064. _proto.trim = function trim(startTime, endTime) {
  21065. var times = this.times,
  21066. nKeys = times.length;
  21067. var from = 0,
  21068. to = nKeys - 1;
  21069. while (from !== nKeys && times[from] < startTime) {
  21070. ++from;
  21071. }
  21072. while (to !== -1 && times[to] > endTime) {
  21073. --to;
  21074. }
  21075. ++to; // inclusive -> exclusive bound
  21076. if (from !== 0 || to !== nKeys) {
  21077. // empty tracks are forbidden, so keep at least one keyframe
  21078. if (from >= to) {
  21079. to = Math.max(to, 1);
  21080. from = to - 1;
  21081. }
  21082. var stride = this.getValueSize();
  21083. this.times = AnimationUtils.arraySlice(times, from, to);
  21084. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  21085. }
  21086. return this;
  21087. } // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21088. ;
  21089. _proto.validate = function validate() {
  21090. var valid = true;
  21091. var valueSize = this.getValueSize();
  21092. if (valueSize - Math.floor(valueSize) !== 0) {
  21093. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  21094. valid = false;
  21095. }
  21096. var times = this.times,
  21097. values = this.values,
  21098. nKeys = times.length;
  21099. if (nKeys === 0) {
  21100. console.error('THREE.KeyframeTrack: Track is empty.', this);
  21101. valid = false;
  21102. }
  21103. var prevTime = null;
  21104. for (var i = 0; i !== nKeys; i++) {
  21105. var currTime = times[i];
  21106. if (typeof currTime === 'number' && isNaN(currTime)) {
  21107. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  21108. valid = false;
  21109. break;
  21110. }
  21111. if (prevTime !== null && prevTime > currTime) {
  21112. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  21113. valid = false;
  21114. break;
  21115. }
  21116. prevTime = currTime;
  21117. }
  21118. if (values !== undefined) {
  21119. if (AnimationUtils.isTypedArray(values)) {
  21120. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  21121. var value = values[_i];
  21122. if (isNaN(value)) {
  21123. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  21124. valid = false;
  21125. break;
  21126. }
  21127. }
  21128. }
  21129. }
  21130. return valid;
  21131. } // removes equivalent sequential keys as common in morph target sequences
  21132. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21133. ;
  21134. _proto.optimize = function optimize() {
  21135. // times or values may be shared with other tracks, so overwriting is unsafe
  21136. var times = AnimationUtils.arraySlice(this.times),
  21137. values = AnimationUtils.arraySlice(this.values),
  21138. stride = this.getValueSize(),
  21139. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21140. lastIndex = times.length - 1;
  21141. var writeIndex = 1;
  21142. for (var i = 1; i < lastIndex; ++i) {
  21143. var keep = false;
  21144. var time = times[i];
  21145. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  21146. if (time !== timeNext && (i !== 1 || time !== times[0])) {
  21147. if (!smoothInterpolation) {
  21148. // remove unnecessary keyframes same as their neighbors
  21149. var offset = i * stride,
  21150. offsetP = offset - stride,
  21151. offsetN = offset + stride;
  21152. for (var j = 0; j !== stride; ++j) {
  21153. var value = values[offset + j];
  21154. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  21155. keep = true;
  21156. break;
  21157. }
  21158. }
  21159. } else {
  21160. keep = true;
  21161. }
  21162. } // in-place compaction
  21163. if (keep) {
  21164. if (i !== writeIndex) {
  21165. times[writeIndex] = times[i];
  21166. var readOffset = i * stride,
  21167. writeOffset = writeIndex * stride;
  21168. for (var _j = 0; _j !== stride; ++_j) {
  21169. values[writeOffset + _j] = values[readOffset + _j];
  21170. }
  21171. }
  21172. ++writeIndex;
  21173. }
  21174. } // flush last keyframe (compaction looks ahead)
  21175. if (lastIndex > 0) {
  21176. times[writeIndex] = times[lastIndex];
  21177. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  21178. values[_writeOffset + _j2] = values[_readOffset + _j2];
  21179. }
  21180. ++writeIndex;
  21181. }
  21182. if (writeIndex !== times.length) {
  21183. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  21184. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  21185. } else {
  21186. this.times = times;
  21187. this.values = values;
  21188. }
  21189. return this;
  21190. };
  21191. _proto.clone = function clone() {
  21192. var times = AnimationUtils.arraySlice(this.times, 0);
  21193. var values = AnimationUtils.arraySlice(this.values, 0);
  21194. var TypedKeyframeTrack = this.constructor;
  21195. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21196. track.createInterpolant = this.createInterpolant;
  21197. return track;
  21198. };
  21199. return KeyframeTrack;
  21200. }();
  21201. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  21202. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  21203. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  21204. /**
  21205. * A Track of Boolean keyframe values.
  21206. */
  21207. var BooleanKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21208. _inheritsLoose(BooleanKeyframeTrack, _KeyframeTrack);
  21209. function BooleanKeyframeTrack() {
  21210. return _KeyframeTrack.apply(this, arguments) || this;
  21211. }
  21212. return BooleanKeyframeTrack;
  21213. }(KeyframeTrack);
  21214. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  21215. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  21216. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  21217. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  21218. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined; // Note: Actually this track could have a optimized / compressed
  21219. /**
  21220. * A Track of keyframe values that represent color.
  21221. */
  21222. var ColorKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21223. _inheritsLoose(ColorKeyframeTrack, _KeyframeTrack);
  21224. function ColorKeyframeTrack() {
  21225. return _KeyframeTrack.apply(this, arguments) || this;
  21226. }
  21227. return ColorKeyframeTrack;
  21228. }(KeyframeTrack);
  21229. ColorKeyframeTrack.prototype.ValueTypeName = 'color'; // ValueBufferType is inherited
  21230. /**
  21231. * A Track of numeric keyframe values.
  21232. */
  21233. var NumberKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21234. _inheritsLoose(NumberKeyframeTrack, _KeyframeTrack);
  21235. function NumberKeyframeTrack() {
  21236. return _KeyframeTrack.apply(this, arguments) || this;
  21237. }
  21238. return NumberKeyframeTrack;
  21239. }(KeyframeTrack);
  21240. NumberKeyframeTrack.prototype.ValueTypeName = 'number'; // ValueBufferType is inherited
  21241. /**
  21242. * Spherical linear unit quaternion interpolant.
  21243. */
  21244. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21245. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21246. }
  21247. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21248. constructor: QuaternionLinearInterpolant,
  21249. interpolate_: function interpolate_(i1, t0, t, t1) {
  21250. var result = this.resultBuffer,
  21251. values = this.sampleValues,
  21252. stride = this.valueSize,
  21253. alpha = (t - t0) / (t1 - t0);
  21254. var offset = i1 * stride;
  21255. for (var end = offset + stride; offset !== end; offset += 4) {
  21256. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21257. }
  21258. return result;
  21259. }
  21260. });
  21261. /**
  21262. * A Track of quaternion keyframe values.
  21263. */
  21264. var QuaternionKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21265. _inheritsLoose(QuaternionKeyframeTrack, _KeyframeTrack);
  21266. function QuaternionKeyframeTrack() {
  21267. return _KeyframeTrack.apply(this, arguments) || this;
  21268. }
  21269. var _proto = QuaternionKeyframeTrack.prototype;
  21270. _proto.InterpolantFactoryMethodLinear = function InterpolantFactoryMethodLinear(result) {
  21271. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21272. };
  21273. return QuaternionKeyframeTrack;
  21274. }(KeyframeTrack);
  21275. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion'; // ValueBufferType is inherited
  21276. QuaternionKeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  21277. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  21278. /**
  21279. * A Track that interpolates Strings
  21280. */
  21281. var StringKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21282. _inheritsLoose(StringKeyframeTrack, _KeyframeTrack);
  21283. function StringKeyframeTrack() {
  21284. return _KeyframeTrack.apply(this, arguments) || this;
  21285. }
  21286. return StringKeyframeTrack;
  21287. }(KeyframeTrack);
  21288. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  21289. StringKeyframeTrack.prototype.ValueBufferType = Array;
  21290. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  21291. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  21292. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  21293. /**
  21294. * A Track of vectored keyframe values.
  21295. */
  21296. var VectorKeyframeTrack = /*#__PURE__*/function (_KeyframeTrack) {
  21297. _inheritsLoose(VectorKeyframeTrack, _KeyframeTrack);
  21298. function VectorKeyframeTrack() {
  21299. return _KeyframeTrack.apply(this, arguments) || this;
  21300. }
  21301. return VectorKeyframeTrack;
  21302. }(KeyframeTrack);
  21303. VectorKeyframeTrack.prototype.ValueTypeName = 'vector'; // ValueBufferType is inherited
  21304. var AnimationClip = /*#__PURE__*/function () {
  21305. function AnimationClip(name, duration, tracks, blendMode) {
  21306. if (duration === void 0) {
  21307. duration = -1;
  21308. }
  21309. if (blendMode === void 0) {
  21310. blendMode = NormalAnimationBlendMode;
  21311. }
  21312. this.name = name;
  21313. this.tracks = tracks;
  21314. this.duration = duration;
  21315. this.blendMode = blendMode;
  21316. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21317. if (this.duration < 0) {
  21318. this.resetDuration();
  21319. }
  21320. }
  21321. AnimationClip.parse = function parse(json) {
  21322. var tracks = [],
  21323. jsonTracks = json.tracks,
  21324. frameTime = 1.0 / (json.fps || 1.0);
  21325. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21326. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21327. }
  21328. var clip = new this(json.name, json.duration, tracks, json.blendMode);
  21329. clip.uuid = json.uuid;
  21330. return clip;
  21331. };
  21332. AnimationClip.toJSON = function toJSON(clip) {
  21333. var tracks = [],
  21334. clipTracks = clip.tracks;
  21335. var json = {
  21336. 'name': clip.name,
  21337. 'duration': clip.duration,
  21338. 'tracks': tracks,
  21339. 'uuid': clip.uuid,
  21340. 'blendMode': clip.blendMode
  21341. };
  21342. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21343. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21344. }
  21345. return json;
  21346. };
  21347. AnimationClip.CreateFromMorphTargetSequence = function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21348. var numMorphTargets = morphTargetSequence.length;
  21349. var tracks = [];
  21350. for (var i = 0; i < numMorphTargets; i++) {
  21351. var times = [];
  21352. var values = [];
  21353. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21354. values.push(0, 1, 0);
  21355. var order = AnimationUtils.getKeyframeOrder(times);
  21356. times = AnimationUtils.sortedArray(times, 1, order);
  21357. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21358. // last frame as well for perfect loop.
  21359. if (!noLoop && times[0] === 0) {
  21360. times.push(numMorphTargets);
  21361. values.push(values[0]);
  21362. }
  21363. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21364. }
  21365. return new this(name, -1, tracks);
  21366. };
  21367. AnimationClip.findByName = function findByName(objectOrClipArray, name) {
  21368. var clipArray = objectOrClipArray;
  21369. if (!Array.isArray(objectOrClipArray)) {
  21370. var o = objectOrClipArray;
  21371. clipArray = o.geometry && o.geometry.animations || o.animations;
  21372. }
  21373. for (var i = 0; i < clipArray.length; i++) {
  21374. if (clipArray[i].name === name) {
  21375. return clipArray[i];
  21376. }
  21377. }
  21378. return null;
  21379. };
  21380. AnimationClip.CreateClipsFromMorphTargetSequences = function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21381. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21382. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21383. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21384. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21385. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21386. var morphTarget = morphTargets[i];
  21387. var parts = morphTarget.name.match(pattern);
  21388. if (parts && parts.length > 1) {
  21389. var name = parts[1];
  21390. var animationMorphTargets = animationToMorphTargets[name];
  21391. if (!animationMorphTargets) {
  21392. animationToMorphTargets[name] = animationMorphTargets = [];
  21393. }
  21394. animationMorphTargets.push(morphTarget);
  21395. }
  21396. }
  21397. var clips = [];
  21398. for (var _name in animationToMorphTargets) {
  21399. clips.push(this.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21400. }
  21401. return clips;
  21402. } // parse the animation.hierarchy format
  21403. ;
  21404. AnimationClip.parseAnimation = function parseAnimation(animation, bones) {
  21405. if (!animation) {
  21406. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21407. return null;
  21408. }
  21409. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21410. // only return track if there are actually keys.
  21411. if (animationKeys.length !== 0) {
  21412. var times = [];
  21413. var values = [];
  21414. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21415. if (times.length !== 0) {
  21416. destTracks.push(new trackType(trackName, times, values));
  21417. }
  21418. }
  21419. };
  21420. var tracks = [];
  21421. var clipName = animation.name || 'default';
  21422. var fps = animation.fps || 30;
  21423. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21424. var duration = animation.length || -1;
  21425. var hierarchyTracks = animation.hierarchy || [];
  21426. for (var h = 0; h < hierarchyTracks.length; h++) {
  21427. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21428. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21429. if (animationKeys[0].morphTargets) {
  21430. // figure out all morph targets used in this track
  21431. var morphTargetNames = {};
  21432. var k = void 0;
  21433. for (k = 0; k < animationKeys.length; k++) {
  21434. if (animationKeys[k].morphTargets) {
  21435. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21436. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21437. }
  21438. }
  21439. } // create a track for each morph target with all zero
  21440. // morphTargetInfluences except for the keys in which
  21441. // the morphTarget is named.
  21442. for (var morphTargetName in morphTargetNames) {
  21443. var times = [];
  21444. var values = [];
  21445. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21446. var animationKey = animationKeys[k];
  21447. times.push(animationKey.time);
  21448. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21449. }
  21450. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21451. }
  21452. duration = morphTargetNames.length * (fps || 1.0);
  21453. } else {
  21454. // ...assume skeletal animation
  21455. var boneName = '.bones[' + bones[h].name + ']';
  21456. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21457. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21458. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21459. }
  21460. }
  21461. if (tracks.length === 0) {
  21462. return null;
  21463. }
  21464. var clip = new this(clipName, duration, tracks, blendMode);
  21465. return clip;
  21466. };
  21467. var _proto = AnimationClip.prototype;
  21468. _proto.resetDuration = function resetDuration() {
  21469. var tracks = this.tracks;
  21470. var duration = 0;
  21471. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21472. var track = this.tracks[i];
  21473. duration = Math.max(duration, track.times[track.times.length - 1]);
  21474. }
  21475. this.duration = duration;
  21476. return this;
  21477. };
  21478. _proto.trim = function trim() {
  21479. for (var i = 0; i < this.tracks.length; i++) {
  21480. this.tracks[i].trim(0, this.duration);
  21481. }
  21482. return this;
  21483. };
  21484. _proto.validate = function validate() {
  21485. var valid = true;
  21486. for (var i = 0; i < this.tracks.length; i++) {
  21487. valid = valid && this.tracks[i].validate();
  21488. }
  21489. return valid;
  21490. };
  21491. _proto.optimize = function optimize() {
  21492. for (var i = 0; i < this.tracks.length; i++) {
  21493. this.tracks[i].optimize();
  21494. }
  21495. return this;
  21496. };
  21497. _proto.clone = function clone() {
  21498. var tracks = [];
  21499. for (var i = 0; i < this.tracks.length; i++) {
  21500. tracks.push(this.tracks[i].clone());
  21501. }
  21502. return new this.constructor(this.name, this.duration, tracks, this.blendMode);
  21503. };
  21504. _proto.toJSON = function toJSON() {
  21505. return this.constructor.toJSON(this);
  21506. };
  21507. return AnimationClip;
  21508. }();
  21509. function getTrackTypeForValueTypeName(typeName) {
  21510. switch (typeName.toLowerCase()) {
  21511. case 'scalar':
  21512. case 'double':
  21513. case 'float':
  21514. case 'number':
  21515. case 'integer':
  21516. return NumberKeyframeTrack;
  21517. case 'vector':
  21518. case 'vector2':
  21519. case 'vector3':
  21520. case 'vector4':
  21521. return VectorKeyframeTrack;
  21522. case 'color':
  21523. return ColorKeyframeTrack;
  21524. case 'quaternion':
  21525. return QuaternionKeyframeTrack;
  21526. case 'bool':
  21527. case 'boolean':
  21528. return BooleanKeyframeTrack;
  21529. case 'string':
  21530. return StringKeyframeTrack;
  21531. }
  21532. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21533. }
  21534. function parseKeyframeTrack(json) {
  21535. if (json.type === undefined) {
  21536. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21537. }
  21538. var trackType = getTrackTypeForValueTypeName(json.type);
  21539. if (json.times === undefined) {
  21540. var times = [],
  21541. values = [];
  21542. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21543. json.times = times;
  21544. json.values = values;
  21545. } // derived classes can define a static parse method
  21546. if (trackType.parse !== undefined) {
  21547. return trackType.parse(json);
  21548. } else {
  21549. // by default, we assume a constructor compatible with the base
  21550. return new trackType(json.name, json.times, json.values, json.interpolation);
  21551. }
  21552. }
  21553. var Cache = {
  21554. enabled: false,
  21555. files: {},
  21556. add: function add(key, file) {
  21557. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21558. this.files[key] = file;
  21559. },
  21560. get: function get(key) {
  21561. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21562. return this.files[key];
  21563. },
  21564. remove: function remove(key) {
  21565. delete this.files[key];
  21566. },
  21567. clear: function clear() {
  21568. this.files = {};
  21569. }
  21570. };
  21571. function LoadingManager(onLoad, onProgress, onError) {
  21572. var scope = this;
  21573. var isLoading = false;
  21574. var itemsLoaded = 0;
  21575. var itemsTotal = 0;
  21576. var urlModifier = undefined;
  21577. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21578. // in the constructor
  21579. this.onStart = undefined;
  21580. this.onLoad = onLoad;
  21581. this.onProgress = onProgress;
  21582. this.onError = onError;
  21583. this.itemStart = function (url) {
  21584. itemsTotal++;
  21585. if (isLoading === false) {
  21586. if (scope.onStart !== undefined) {
  21587. scope.onStart(url, itemsLoaded, itemsTotal);
  21588. }
  21589. }
  21590. isLoading = true;
  21591. };
  21592. this.itemEnd = function (url) {
  21593. itemsLoaded++;
  21594. if (scope.onProgress !== undefined) {
  21595. scope.onProgress(url, itemsLoaded, itemsTotal);
  21596. }
  21597. if (itemsLoaded === itemsTotal) {
  21598. isLoading = false;
  21599. if (scope.onLoad !== undefined) {
  21600. scope.onLoad();
  21601. }
  21602. }
  21603. };
  21604. this.itemError = function (url) {
  21605. if (scope.onError !== undefined) {
  21606. scope.onError(url);
  21607. }
  21608. };
  21609. this.resolveURL = function (url) {
  21610. if (urlModifier) {
  21611. return urlModifier(url);
  21612. }
  21613. return url;
  21614. };
  21615. this.setURLModifier = function (transform) {
  21616. urlModifier = transform;
  21617. return this;
  21618. };
  21619. this.addHandler = function (regex, loader) {
  21620. handlers.push(regex, loader);
  21621. return this;
  21622. };
  21623. this.removeHandler = function (regex) {
  21624. var index = handlers.indexOf(regex);
  21625. if (index !== -1) {
  21626. handlers.splice(index, 2);
  21627. }
  21628. return this;
  21629. };
  21630. this.getHandler = function (file) {
  21631. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21632. var regex = handlers[i];
  21633. var loader = handlers[i + 1];
  21634. if (regex.global) regex.lastIndex = 0; // see #17920
  21635. if (regex.test(file)) {
  21636. return loader;
  21637. }
  21638. }
  21639. return null;
  21640. };
  21641. }
  21642. var DefaultLoadingManager = new LoadingManager();
  21643. function Loader(manager) {
  21644. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21645. this.crossOrigin = 'anonymous';
  21646. this.withCredentials = false;
  21647. this.path = '';
  21648. this.resourcePath = '';
  21649. this.requestHeader = {};
  21650. }
  21651. Object.assign(Loader.prototype, {
  21652. load: function load()
  21653. /* url, onLoad, onProgress, onError */
  21654. {},
  21655. loadAsync: function loadAsync(url, onProgress) {
  21656. var scope = this;
  21657. return new Promise(function (resolve, reject) {
  21658. scope.load(url, resolve, onProgress, reject);
  21659. });
  21660. },
  21661. parse: function parse()
  21662. /* data */
  21663. {},
  21664. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21665. this.crossOrigin = crossOrigin;
  21666. return this;
  21667. },
  21668. setWithCredentials: function setWithCredentials(value) {
  21669. this.withCredentials = value;
  21670. return this;
  21671. },
  21672. setPath: function setPath(path) {
  21673. this.path = path;
  21674. return this;
  21675. },
  21676. setResourcePath: function setResourcePath(resourcePath) {
  21677. this.resourcePath = resourcePath;
  21678. return this;
  21679. },
  21680. setRequestHeader: function setRequestHeader(requestHeader) {
  21681. this.requestHeader = requestHeader;
  21682. return this;
  21683. }
  21684. });
  21685. var loading = {};
  21686. function FileLoader(manager) {
  21687. Loader.call(this, manager);
  21688. }
  21689. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21690. constructor: FileLoader,
  21691. load: function load(url, onLoad, onProgress, onError) {
  21692. if (url === undefined) url = '';
  21693. if (this.path !== undefined) url = this.path + url;
  21694. url = this.manager.resolveURL(url);
  21695. var scope = this;
  21696. var cached = Cache.get(url);
  21697. if (cached !== undefined) {
  21698. scope.manager.itemStart(url);
  21699. setTimeout(function () {
  21700. if (onLoad) onLoad(cached);
  21701. scope.manager.itemEnd(url);
  21702. }, 0);
  21703. return cached;
  21704. } // Check if request is duplicate
  21705. if (loading[url] !== undefined) {
  21706. loading[url].push({
  21707. onLoad: onLoad,
  21708. onProgress: onProgress,
  21709. onError: onError
  21710. });
  21711. return;
  21712. } // Check for data: URI
  21713. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21714. var dataUriRegexResult = url.match(dataUriRegex);
  21715. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21716. if (dataUriRegexResult) {
  21717. var mimeType = dataUriRegexResult[1];
  21718. var isBase64 = !!dataUriRegexResult[2];
  21719. var data = dataUriRegexResult[3];
  21720. data = decodeURIComponent(data);
  21721. if (isBase64) data = atob(data);
  21722. try {
  21723. var response;
  21724. var responseType = (this.responseType || '').toLowerCase();
  21725. switch (responseType) {
  21726. case 'arraybuffer':
  21727. case 'blob':
  21728. var view = new Uint8Array(data.length);
  21729. for (var i = 0; i < data.length; i++) {
  21730. view[i] = data.charCodeAt(i);
  21731. }
  21732. if (responseType === 'blob') {
  21733. response = new Blob([view.buffer], {
  21734. type: mimeType
  21735. });
  21736. } else {
  21737. response = view.buffer;
  21738. }
  21739. break;
  21740. case 'document':
  21741. var parser = new DOMParser();
  21742. response = parser.parseFromString(data, mimeType);
  21743. break;
  21744. case 'json':
  21745. response = JSON.parse(data);
  21746. break;
  21747. default:
  21748. // 'text' or other
  21749. response = data;
  21750. break;
  21751. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21752. setTimeout(function () {
  21753. if (onLoad) onLoad(response);
  21754. scope.manager.itemEnd(url);
  21755. }, 0);
  21756. } catch (error) {
  21757. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21758. setTimeout(function () {
  21759. if (onError) onError(error);
  21760. scope.manager.itemError(url);
  21761. scope.manager.itemEnd(url);
  21762. }, 0);
  21763. }
  21764. } else {
  21765. // Initialise array for duplicate requests
  21766. loading[url] = [];
  21767. loading[url].push({
  21768. onLoad: onLoad,
  21769. onProgress: onProgress,
  21770. onError: onError
  21771. });
  21772. request = new XMLHttpRequest();
  21773. request.open('GET', url, true);
  21774. request.addEventListener('load', function (event) {
  21775. var response = this.response;
  21776. var callbacks = loading[url];
  21777. delete loading[url];
  21778. if (this.status === 200 || this.status === 0) {
  21779. // Some browsers return HTTP Status 0 when using non-http protocol
  21780. // e.g. 'file://' or 'data://'. Handle as success.
  21781. if (this.status === 0) console.warn('THREE.FileLoader: HTTP Status 0 received.'); // Add to cache only on HTTP success, so that we do not cache
  21782. // error response bodies as proper responses to requests.
  21783. Cache.add(url, response);
  21784. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21785. var callback = callbacks[_i];
  21786. if (callback.onLoad) callback.onLoad(response);
  21787. }
  21788. scope.manager.itemEnd(url);
  21789. } else {
  21790. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21791. var _callback = callbacks[_i2];
  21792. if (_callback.onError) _callback.onError(event);
  21793. }
  21794. scope.manager.itemError(url);
  21795. scope.manager.itemEnd(url);
  21796. }
  21797. }, false);
  21798. request.addEventListener('progress', function (event) {
  21799. var callbacks = loading[url];
  21800. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21801. var callback = callbacks[_i3];
  21802. if (callback.onProgress) callback.onProgress(event);
  21803. }
  21804. }, false);
  21805. request.addEventListener('error', function (event) {
  21806. var callbacks = loading[url];
  21807. delete loading[url];
  21808. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21809. var callback = callbacks[_i4];
  21810. if (callback.onError) callback.onError(event);
  21811. }
  21812. scope.manager.itemError(url);
  21813. scope.manager.itemEnd(url);
  21814. }, false);
  21815. request.addEventListener('abort', function (event) {
  21816. var callbacks = loading[url];
  21817. delete loading[url];
  21818. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21819. var callback = callbacks[_i5];
  21820. if (callback.onError) callback.onError(event);
  21821. }
  21822. scope.manager.itemError(url);
  21823. scope.manager.itemEnd(url);
  21824. }, false);
  21825. if (this.responseType !== undefined) request.responseType = this.responseType;
  21826. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21827. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21828. for (var header in this.requestHeader) {
  21829. request.setRequestHeader(header, this.requestHeader[header]);
  21830. }
  21831. request.send(null);
  21832. }
  21833. scope.manager.itemStart(url);
  21834. return request;
  21835. },
  21836. setResponseType: function setResponseType(value) {
  21837. this.responseType = value;
  21838. return this;
  21839. },
  21840. setMimeType: function setMimeType(value) {
  21841. this.mimeType = value;
  21842. return this;
  21843. }
  21844. });
  21845. var AnimationLoader = /*#__PURE__*/function (_Loader) {
  21846. _inheritsLoose(AnimationLoader, _Loader);
  21847. function AnimationLoader(manager) {
  21848. return _Loader.call(this, manager) || this;
  21849. }
  21850. var _proto = AnimationLoader.prototype;
  21851. _proto.load = function load(url, onLoad, onProgress, onError) {
  21852. var scope = this;
  21853. var loader = new FileLoader(this.manager);
  21854. loader.setPath(this.path);
  21855. loader.setRequestHeader(this.requestHeader);
  21856. loader.setWithCredentials(this.withCredentials);
  21857. loader.load(url, function (text) {
  21858. try {
  21859. onLoad(scope.parse(JSON.parse(text)));
  21860. } catch (e) {
  21861. if (onError) {
  21862. onError(e);
  21863. } else {
  21864. console.error(e);
  21865. }
  21866. scope.manager.itemError(url);
  21867. }
  21868. }, onProgress, onError);
  21869. };
  21870. _proto.parse = function parse(json) {
  21871. var animations = [];
  21872. for (var i = 0; i < json.length; i++) {
  21873. var clip = AnimationClip.parse(json[i]);
  21874. animations.push(clip);
  21875. }
  21876. return animations;
  21877. };
  21878. return AnimationLoader;
  21879. }(Loader);
  21880. /**
  21881. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21882. *
  21883. * Sub classes have to implement the parse() method which will be used in load().
  21884. */
  21885. function CompressedTextureLoader(manager) {
  21886. Loader.call(this, manager);
  21887. }
  21888. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21889. constructor: CompressedTextureLoader,
  21890. load: function load(url, onLoad, onProgress, onError) {
  21891. var scope = this;
  21892. var images = [];
  21893. var texture = new CompressedTexture();
  21894. var loader = new FileLoader(this.manager);
  21895. loader.setPath(this.path);
  21896. loader.setResponseType('arraybuffer');
  21897. loader.setRequestHeader(this.requestHeader);
  21898. loader.setWithCredentials(scope.withCredentials);
  21899. var loaded = 0;
  21900. function loadTexture(i) {
  21901. loader.load(url[i], function (buffer) {
  21902. var texDatas = scope.parse(buffer, true);
  21903. images[i] = {
  21904. width: texDatas.width,
  21905. height: texDatas.height,
  21906. format: texDatas.format,
  21907. mipmaps: texDatas.mipmaps
  21908. };
  21909. loaded += 1;
  21910. if (loaded === 6) {
  21911. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21912. texture.image = images;
  21913. texture.format = texDatas.format;
  21914. texture.needsUpdate = true;
  21915. if (onLoad) onLoad(texture);
  21916. }
  21917. }, onProgress, onError);
  21918. }
  21919. if (Array.isArray(url)) {
  21920. for (var i = 0, il = url.length; i < il; ++i) {
  21921. loadTexture(i);
  21922. }
  21923. } else {
  21924. // compressed cubemap texture stored in a single DDS file
  21925. loader.load(url, function (buffer) {
  21926. var texDatas = scope.parse(buffer, true);
  21927. if (texDatas.isCubemap) {
  21928. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21929. for (var f = 0; f < faces; f++) {
  21930. images[f] = {
  21931. mipmaps: []
  21932. };
  21933. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21934. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21935. images[f].format = texDatas.format;
  21936. images[f].width = texDatas.width;
  21937. images[f].height = texDatas.height;
  21938. }
  21939. }
  21940. texture.image = images;
  21941. } else {
  21942. texture.image.width = texDatas.width;
  21943. texture.image.height = texDatas.height;
  21944. texture.mipmaps = texDatas.mipmaps;
  21945. }
  21946. if (texDatas.mipmapCount === 1) {
  21947. texture.minFilter = LinearFilter;
  21948. }
  21949. texture.format = texDatas.format;
  21950. texture.needsUpdate = true;
  21951. if (onLoad) onLoad(texture);
  21952. }, onProgress, onError);
  21953. }
  21954. return texture;
  21955. }
  21956. });
  21957. var ImageLoader = /*#__PURE__*/function (_Loader) {
  21958. _inheritsLoose(ImageLoader, _Loader);
  21959. function ImageLoader(manager) {
  21960. return _Loader.call(this, manager) || this;
  21961. }
  21962. var _proto = ImageLoader.prototype;
  21963. _proto.load = function load(url, onLoad, onProgress, onError) {
  21964. if (this.path !== undefined) url = this.path + url;
  21965. url = this.manager.resolveURL(url);
  21966. var scope = this;
  21967. var cached = Cache.get(url);
  21968. if (cached !== undefined) {
  21969. scope.manager.itemStart(url);
  21970. setTimeout(function () {
  21971. if (onLoad) onLoad(cached);
  21972. scope.manager.itemEnd(url);
  21973. }, 0);
  21974. return cached;
  21975. }
  21976. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21977. function onImageLoad() {
  21978. image.removeEventListener('load', onImageLoad, false);
  21979. image.removeEventListener('error', onImageError, false);
  21980. Cache.add(url, this);
  21981. if (onLoad) onLoad(this);
  21982. scope.manager.itemEnd(url);
  21983. }
  21984. function onImageError(event) {
  21985. image.removeEventListener('load', onImageLoad, false);
  21986. image.removeEventListener('error', onImageError, false);
  21987. if (onError) onError(event);
  21988. scope.manager.itemError(url);
  21989. scope.manager.itemEnd(url);
  21990. }
  21991. image.addEventListener('load', onImageLoad, false);
  21992. image.addEventListener('error', onImageError, false);
  21993. if (url.substr(0, 5) !== 'data:') {
  21994. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21995. }
  21996. scope.manager.itemStart(url);
  21997. image.src = url;
  21998. return image;
  21999. };
  22000. return ImageLoader;
  22001. }(Loader);
  22002. var CubeTextureLoader = /*#__PURE__*/function (_Loader) {
  22003. _inheritsLoose(CubeTextureLoader, _Loader);
  22004. function CubeTextureLoader(manager) {
  22005. return _Loader.call(this, manager) || this;
  22006. }
  22007. var _proto = CubeTextureLoader.prototype;
  22008. _proto.load = function load(urls, onLoad, onProgress, onError) {
  22009. var texture = new CubeTexture();
  22010. var loader = new ImageLoader(this.manager);
  22011. loader.setCrossOrigin(this.crossOrigin);
  22012. loader.setPath(this.path);
  22013. var loaded = 0;
  22014. function loadTexture(i) {
  22015. loader.load(urls[i], function (image) {
  22016. texture.images[i] = image;
  22017. loaded++;
  22018. if (loaded === 6) {
  22019. texture.needsUpdate = true;
  22020. if (onLoad) onLoad(texture);
  22021. }
  22022. }, undefined, onError);
  22023. }
  22024. for (var i = 0; i < urls.length; ++i) {
  22025. loadTexture(i);
  22026. }
  22027. return texture;
  22028. };
  22029. return CubeTextureLoader;
  22030. }(Loader);
  22031. /**
  22032. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22033. *
  22034. * Sub classes have to implement the parse() method which will be used in load().
  22035. */
  22036. function DataTextureLoader(manager) {
  22037. Loader.call(this, manager);
  22038. }
  22039. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22040. constructor: DataTextureLoader,
  22041. load: function load(url, onLoad, onProgress, onError) {
  22042. var scope = this;
  22043. var texture = new DataTexture();
  22044. var loader = new FileLoader(this.manager);
  22045. loader.setResponseType('arraybuffer');
  22046. loader.setRequestHeader(this.requestHeader);
  22047. loader.setPath(this.path);
  22048. loader.setWithCredentials(scope.withCredentials);
  22049. loader.load(url, function (buffer) {
  22050. var texData = scope.parse(buffer);
  22051. if (!texData) return;
  22052. if (texData.image !== undefined) {
  22053. texture.image = texData.image;
  22054. } else if (texData.data !== undefined) {
  22055. texture.image.width = texData.width;
  22056. texture.image.height = texData.height;
  22057. texture.image.data = texData.data;
  22058. }
  22059. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22060. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22061. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22062. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22063. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22064. if (texData.encoding !== undefined) {
  22065. texture.encoding = texData.encoding;
  22066. }
  22067. if (texData.flipY !== undefined) {
  22068. texture.flipY = texData.flipY;
  22069. }
  22070. if (texData.format !== undefined) {
  22071. texture.format = texData.format;
  22072. }
  22073. if (texData.type !== undefined) {
  22074. texture.type = texData.type;
  22075. }
  22076. if (texData.mipmaps !== undefined) {
  22077. texture.mipmaps = texData.mipmaps;
  22078. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22079. }
  22080. if (texData.mipmapCount === 1) {
  22081. texture.minFilter = LinearFilter;
  22082. }
  22083. texture.needsUpdate = true;
  22084. if (onLoad) onLoad(texture, texData);
  22085. }, onProgress, onError);
  22086. return texture;
  22087. }
  22088. });
  22089. function TextureLoader(manager) {
  22090. Loader.call(this, manager);
  22091. }
  22092. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  22093. constructor: TextureLoader,
  22094. load: function load(url, onLoad, onProgress, onError) {
  22095. var texture = new Texture();
  22096. var loader = new ImageLoader(this.manager);
  22097. loader.setCrossOrigin(this.crossOrigin);
  22098. loader.setPath(this.path);
  22099. loader.load(url, function (image) {
  22100. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22101. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  22102. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22103. texture.needsUpdate = true;
  22104. if (onLoad !== undefined) {
  22105. onLoad(texture);
  22106. }
  22107. }, onProgress, onError);
  22108. return texture;
  22109. }
  22110. });
  22111. /**
  22112. * Extensible curve object.
  22113. *
  22114. * Some common of curve methods:
  22115. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22116. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22117. * .getPoints(), .getSpacedPoints()
  22118. * .getLength()
  22119. * .updateArcLengths()
  22120. *
  22121. * This following curves inherit from THREE.Curve:
  22122. *
  22123. * -- 2D curves --
  22124. * THREE.ArcCurve
  22125. * THREE.CubicBezierCurve
  22126. * THREE.EllipseCurve
  22127. * THREE.LineCurve
  22128. * THREE.QuadraticBezierCurve
  22129. * THREE.SplineCurve
  22130. *
  22131. * -- 3D curves --
  22132. * THREE.CatmullRomCurve3
  22133. * THREE.CubicBezierCurve3
  22134. * THREE.LineCurve3
  22135. * THREE.QuadraticBezierCurve3
  22136. *
  22137. * A series of curves can be represented as a THREE.CurvePath.
  22138. *
  22139. **/
  22140. function Curve() {
  22141. this.type = 'Curve';
  22142. this.arcLengthDivisions = 200;
  22143. }
  22144. Object.assign(Curve.prototype, {
  22145. // Virtual base class method to overwrite and implement in subclasses
  22146. // - t [0 .. 1]
  22147. getPoint: function getPoint()
  22148. /* t, optionalTarget */
  22149. {
  22150. console.warn('THREE.Curve: .getPoint() not implemented.');
  22151. return null;
  22152. },
  22153. // Get point at relative position in curve according to arc length
  22154. // - u [0 .. 1]
  22155. getPointAt: function getPointAt(u, optionalTarget) {
  22156. var t = this.getUtoTmapping(u);
  22157. return this.getPoint(t, optionalTarget);
  22158. },
  22159. // Get sequence of points using getPoint( t )
  22160. getPoints: function getPoints(divisions) {
  22161. if (divisions === void 0) {
  22162. divisions = 5;
  22163. }
  22164. var points = [];
  22165. for (var d = 0; d <= divisions; d++) {
  22166. points.push(this.getPoint(d / divisions));
  22167. }
  22168. return points;
  22169. },
  22170. // Get sequence of points using getPointAt( u )
  22171. getSpacedPoints: function getSpacedPoints(divisions) {
  22172. if (divisions === void 0) {
  22173. divisions = 5;
  22174. }
  22175. var points = [];
  22176. for (var d = 0; d <= divisions; d++) {
  22177. points.push(this.getPointAt(d / divisions));
  22178. }
  22179. return points;
  22180. },
  22181. // Get total curve arc length
  22182. getLength: function getLength() {
  22183. var lengths = this.getLengths();
  22184. return lengths[lengths.length - 1];
  22185. },
  22186. // Get list of cumulative segment lengths
  22187. getLengths: function getLengths(divisions) {
  22188. if (divisions === undefined) divisions = this.arcLengthDivisions;
  22189. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  22190. return this.cacheArcLengths;
  22191. }
  22192. this.needsUpdate = false;
  22193. var cache = [];
  22194. var current,
  22195. last = this.getPoint(0);
  22196. var sum = 0;
  22197. cache.push(0);
  22198. for (var p = 1; p <= divisions; p++) {
  22199. current = this.getPoint(p / divisions);
  22200. sum += current.distanceTo(last);
  22201. cache.push(sum);
  22202. last = current;
  22203. }
  22204. this.cacheArcLengths = cache;
  22205. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22206. },
  22207. updateArcLengths: function updateArcLengths() {
  22208. this.needsUpdate = true;
  22209. this.getLengths();
  22210. },
  22211. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22212. getUtoTmapping: function getUtoTmapping(u, distance) {
  22213. var arcLengths = this.getLengths();
  22214. var i = 0;
  22215. var il = arcLengths.length;
  22216. var targetArcLength; // The targeted u distance value to get
  22217. if (distance) {
  22218. targetArcLength = distance;
  22219. } else {
  22220. targetArcLength = u * arcLengths[il - 1];
  22221. } // binary search for the index with largest value smaller than target u distance
  22222. var low = 0,
  22223. high = il - 1,
  22224. comparison;
  22225. while (low <= high) {
  22226. i = Math.floor(low + (high - low) / 2); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
  22227. comparison = arcLengths[i] - targetArcLength;
  22228. if (comparison < 0) {
  22229. low = i + 1;
  22230. } else if (comparison > 0) {
  22231. high = i - 1;
  22232. } else {
  22233. high = i;
  22234. break; // DONE
  22235. }
  22236. }
  22237. i = high;
  22238. if (arcLengths[i] === targetArcLength) {
  22239. return i / (il - 1);
  22240. } // we could get finer grain at lengths, or use simple interpolation between two points
  22241. var lengthBefore = arcLengths[i];
  22242. var lengthAfter = arcLengths[i + 1];
  22243. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22244. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22245. var t = (i + segmentFraction) / (il - 1);
  22246. return t;
  22247. },
  22248. // Returns a unit vector tangent at t
  22249. // In case any sub curve does not implement its tangent derivation,
  22250. // 2 points a small delta apart will be used to find its gradient
  22251. // which seems to give a reasonable approximation
  22252. getTangent: function getTangent(t, optionalTarget) {
  22253. var delta = 0.0001;
  22254. var t1 = t - delta;
  22255. var t2 = t + delta; // Capping in case of danger
  22256. if (t1 < 0) t1 = 0;
  22257. if (t2 > 1) t2 = 1;
  22258. var pt1 = this.getPoint(t1);
  22259. var pt2 = this.getPoint(t2);
  22260. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22261. tangent.copy(pt2).sub(pt1).normalize();
  22262. return tangent;
  22263. },
  22264. getTangentAt: function getTangentAt(u, optionalTarget) {
  22265. var t = this.getUtoTmapping(u);
  22266. return this.getTangent(t, optionalTarget);
  22267. },
  22268. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22269. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22270. var normal = new Vector3();
  22271. var tangents = [];
  22272. var normals = [];
  22273. var binormals = [];
  22274. var vec = new Vector3();
  22275. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22276. for (var i = 0; i <= segments; i++) {
  22277. var u = i / segments;
  22278. tangents[i] = this.getTangentAt(u, new Vector3());
  22279. tangents[i].normalize();
  22280. } // select an initial normal vector perpendicular to the first tangent vector,
  22281. // and in the direction of the minimum tangent xyz component
  22282. normals[0] = new Vector3();
  22283. binormals[0] = new Vector3();
  22284. var min = Number.MAX_VALUE;
  22285. var tx = Math.abs(tangents[0].x);
  22286. var ty = Math.abs(tangents[0].y);
  22287. var tz = Math.abs(tangents[0].z);
  22288. if (tx <= min) {
  22289. min = tx;
  22290. normal.set(1, 0, 0);
  22291. }
  22292. if (ty <= min) {
  22293. min = ty;
  22294. normal.set(0, 1, 0);
  22295. }
  22296. if (tz <= min) {
  22297. normal.set(0, 0, 1);
  22298. }
  22299. vec.crossVectors(tangents[0], normal).normalize();
  22300. normals[0].crossVectors(tangents[0], vec);
  22301. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22302. for (var _i = 1; _i <= segments; _i++) {
  22303. normals[_i] = normals[_i - 1].clone();
  22304. binormals[_i] = binormals[_i - 1].clone();
  22305. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22306. if (vec.length() > Number.EPSILON) {
  22307. vec.normalize();
  22308. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22309. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22310. }
  22311. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22312. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22313. if (closed === true) {
  22314. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22315. _theta /= segments;
  22316. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22317. _theta = -_theta;
  22318. }
  22319. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22320. // twist a little...
  22321. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22322. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22323. }
  22324. }
  22325. return {
  22326. tangents: tangents,
  22327. normals: normals,
  22328. binormals: binormals
  22329. };
  22330. },
  22331. clone: function clone() {
  22332. return new this.constructor().copy(this);
  22333. },
  22334. copy: function copy(source) {
  22335. this.arcLengthDivisions = source.arcLengthDivisions;
  22336. return this;
  22337. },
  22338. toJSON: function toJSON() {
  22339. var data = {
  22340. metadata: {
  22341. version: 4.5,
  22342. type: 'Curve',
  22343. generator: 'Curve.toJSON'
  22344. }
  22345. };
  22346. data.arcLengthDivisions = this.arcLengthDivisions;
  22347. data.type = this.type;
  22348. return data;
  22349. },
  22350. fromJSON: function fromJSON(json) {
  22351. this.arcLengthDivisions = json.arcLengthDivisions;
  22352. return this;
  22353. }
  22354. });
  22355. var EllipseCurve = /*#__PURE__*/function (_Curve) {
  22356. _inheritsLoose(EllipseCurve, _Curve);
  22357. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22358. var _this;
  22359. if (aX === void 0) {
  22360. aX = 0;
  22361. }
  22362. if (aY === void 0) {
  22363. aY = 0;
  22364. }
  22365. if (xRadius === void 0) {
  22366. xRadius = 1;
  22367. }
  22368. if (yRadius === void 0) {
  22369. yRadius = 1;
  22370. }
  22371. if (aStartAngle === void 0) {
  22372. aStartAngle = 0;
  22373. }
  22374. if (aEndAngle === void 0) {
  22375. aEndAngle = Math.PI * 2;
  22376. }
  22377. if (aClockwise === void 0) {
  22378. aClockwise = false;
  22379. }
  22380. if (aRotation === void 0) {
  22381. aRotation = 0;
  22382. }
  22383. _this = _Curve.call(this) || this;
  22384. _this.type = 'EllipseCurve';
  22385. _this.aX = aX;
  22386. _this.aY = aY;
  22387. _this.xRadius = xRadius;
  22388. _this.yRadius = yRadius;
  22389. _this.aStartAngle = aStartAngle;
  22390. _this.aEndAngle = aEndAngle;
  22391. _this.aClockwise = aClockwise;
  22392. _this.aRotation = aRotation;
  22393. return _this;
  22394. }
  22395. var _proto = EllipseCurve.prototype;
  22396. _proto.getPoint = function getPoint(t, optionalTarget) {
  22397. var point = optionalTarget || new Vector2();
  22398. var twoPi = Math.PI * 2;
  22399. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22400. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22401. while (deltaAngle < 0) {
  22402. deltaAngle += twoPi;
  22403. }
  22404. while (deltaAngle > twoPi) {
  22405. deltaAngle -= twoPi;
  22406. }
  22407. if (deltaAngle < Number.EPSILON) {
  22408. if (samePoints) {
  22409. deltaAngle = 0;
  22410. } else {
  22411. deltaAngle = twoPi;
  22412. }
  22413. }
  22414. if (this.aClockwise === true && !samePoints) {
  22415. if (deltaAngle === twoPi) {
  22416. deltaAngle = -twoPi;
  22417. } else {
  22418. deltaAngle = deltaAngle - twoPi;
  22419. }
  22420. }
  22421. var angle = this.aStartAngle + t * deltaAngle;
  22422. var x = this.aX + this.xRadius * Math.cos(angle);
  22423. var y = this.aY + this.yRadius * Math.sin(angle);
  22424. if (this.aRotation !== 0) {
  22425. var cos = Math.cos(this.aRotation);
  22426. var sin = Math.sin(this.aRotation);
  22427. var tx = x - this.aX;
  22428. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22429. x = tx * cos - ty * sin + this.aX;
  22430. y = tx * sin + ty * cos + this.aY;
  22431. }
  22432. return point.set(x, y);
  22433. };
  22434. _proto.copy = function copy(source) {
  22435. _Curve.prototype.copy.call(this, source);
  22436. this.aX = source.aX;
  22437. this.aY = source.aY;
  22438. this.xRadius = source.xRadius;
  22439. this.yRadius = source.yRadius;
  22440. this.aStartAngle = source.aStartAngle;
  22441. this.aEndAngle = source.aEndAngle;
  22442. this.aClockwise = source.aClockwise;
  22443. this.aRotation = source.aRotation;
  22444. return this;
  22445. };
  22446. _proto.toJSON = function toJSON() {
  22447. var data = _Curve.prototype.toJSON.call(this);
  22448. data.aX = this.aX;
  22449. data.aY = this.aY;
  22450. data.xRadius = this.xRadius;
  22451. data.yRadius = this.yRadius;
  22452. data.aStartAngle = this.aStartAngle;
  22453. data.aEndAngle = this.aEndAngle;
  22454. data.aClockwise = this.aClockwise;
  22455. data.aRotation = this.aRotation;
  22456. return data;
  22457. };
  22458. _proto.fromJSON = function fromJSON(json) {
  22459. _Curve.prototype.fromJSON.call(this, json);
  22460. this.aX = json.aX;
  22461. this.aY = json.aY;
  22462. this.xRadius = json.xRadius;
  22463. this.yRadius = json.yRadius;
  22464. this.aStartAngle = json.aStartAngle;
  22465. this.aEndAngle = json.aEndAngle;
  22466. this.aClockwise = json.aClockwise;
  22467. this.aRotation = json.aRotation;
  22468. return this;
  22469. };
  22470. return EllipseCurve;
  22471. }(Curve);
  22472. EllipseCurve.prototype.isEllipseCurve = true;
  22473. var ArcCurve = /*#__PURE__*/function (_EllipseCurve) {
  22474. _inheritsLoose(ArcCurve, _EllipseCurve);
  22475. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22476. var _this;
  22477. _this = _EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise) || this;
  22478. _this.type = 'ArcCurve';
  22479. return _this;
  22480. }
  22481. return ArcCurve;
  22482. }(EllipseCurve);
  22483. ArcCurve.prototype.isArcCurve = true;
  22484. /**
  22485. * Centripetal CatmullRom Curve - which is useful for avoiding
  22486. * cusps and self-intersections in non-uniform catmull rom curves.
  22487. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22488. *
  22489. * curve.type accepts centripetal(default), chordal and catmullrom
  22490. * curve.tension is used for catmullrom which defaults to 0.5
  22491. */
  22492. /*
  22493. Based on an optimized c++ solution in
  22494. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22495. - http://ideone.com/NoEbVM
  22496. This CubicPoly class could be used for reusing some variables and calculations,
  22497. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22498. which can be placed in CurveUtils.
  22499. */
  22500. function CubicPoly() {
  22501. var c0 = 0,
  22502. c1 = 0,
  22503. c2 = 0,
  22504. c3 = 0;
  22505. /*
  22506. * Compute coefficients for a cubic polynomial
  22507. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22508. * such that
  22509. * p(0) = x0, p(1) = x1
  22510. * and
  22511. * p'(0) = t0, p'(1) = t1.
  22512. */
  22513. function init(x0, x1, t0, t1) {
  22514. c0 = x0;
  22515. c1 = t0;
  22516. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22517. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22518. }
  22519. return {
  22520. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22521. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22522. },
  22523. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22524. // compute tangents when parameterized in [t1,t2]
  22525. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22526. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22527. t1 *= dt1;
  22528. t2 *= dt1;
  22529. init(x1, x2, t1, t2);
  22530. },
  22531. calc: function calc(t) {
  22532. var t2 = t * t;
  22533. var t3 = t2 * t;
  22534. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22535. }
  22536. };
  22537. } //
  22538. var tmp = new Vector3();
  22539. var px = new CubicPoly(),
  22540. py = new CubicPoly(),
  22541. pz = new CubicPoly();
  22542. var CatmullRomCurve3 = /*#__PURE__*/function (_Curve) {
  22543. _inheritsLoose(CatmullRomCurve3, _Curve);
  22544. function CatmullRomCurve3(points, closed, curveType, tension) {
  22545. var _this;
  22546. if (points === void 0) {
  22547. points = [];
  22548. }
  22549. if (closed === void 0) {
  22550. closed = false;
  22551. }
  22552. if (curveType === void 0) {
  22553. curveType = 'centripetal';
  22554. }
  22555. if (tension === void 0) {
  22556. tension = 0.5;
  22557. }
  22558. _this = _Curve.call(this) || this;
  22559. _this.type = 'CatmullRomCurve3';
  22560. _this.points = points;
  22561. _this.closed = closed;
  22562. _this.curveType = curveType;
  22563. _this.tension = tension;
  22564. return _this;
  22565. }
  22566. var _proto = CatmullRomCurve3.prototype;
  22567. _proto.getPoint = function getPoint(t, optionalTarget) {
  22568. if (optionalTarget === void 0) {
  22569. optionalTarget = new Vector3();
  22570. }
  22571. var point = optionalTarget;
  22572. var points = this.points;
  22573. var l = points.length;
  22574. var p = (l - (this.closed ? 0 : 1)) * t;
  22575. var intPoint = Math.floor(p);
  22576. var weight = p - intPoint;
  22577. if (this.closed) {
  22578. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22579. } else if (weight === 0 && intPoint === l - 1) {
  22580. intPoint = l - 2;
  22581. weight = 1;
  22582. }
  22583. var p0, p3; // 4 points (p1 & p2 defined below)
  22584. if (this.closed || intPoint > 0) {
  22585. p0 = points[(intPoint - 1) % l];
  22586. } else {
  22587. // extrapolate first point
  22588. tmp.subVectors(points[0], points[1]).add(points[0]);
  22589. p0 = tmp;
  22590. }
  22591. var p1 = points[intPoint % l];
  22592. var p2 = points[(intPoint + 1) % l];
  22593. if (this.closed || intPoint + 2 < l) {
  22594. p3 = points[(intPoint + 2) % l];
  22595. } else {
  22596. // extrapolate last point
  22597. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22598. p3 = tmp;
  22599. }
  22600. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22601. // init Centripetal / Chordal Catmull-Rom
  22602. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22603. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22604. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22605. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22606. if (dt1 < 1e-4) dt1 = 1.0;
  22607. if (dt0 < 1e-4) dt0 = dt1;
  22608. if (dt2 < 1e-4) dt2 = dt1;
  22609. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22610. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22611. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22612. } else if (this.curveType === 'catmullrom') {
  22613. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22614. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22615. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22616. }
  22617. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22618. return point;
  22619. };
  22620. _proto.copy = function copy(source) {
  22621. _Curve.prototype.copy.call(this, source);
  22622. this.points = [];
  22623. for (var i = 0, l = source.points.length; i < l; i++) {
  22624. var point = source.points[i];
  22625. this.points.push(point.clone());
  22626. }
  22627. this.closed = source.closed;
  22628. this.curveType = source.curveType;
  22629. this.tension = source.tension;
  22630. return this;
  22631. };
  22632. _proto.toJSON = function toJSON() {
  22633. var data = _Curve.prototype.toJSON.call(this);
  22634. data.points = [];
  22635. for (var i = 0, l = this.points.length; i < l; i++) {
  22636. var point = this.points[i];
  22637. data.points.push(point.toArray());
  22638. }
  22639. data.closed = this.closed;
  22640. data.curveType = this.curveType;
  22641. data.tension = this.tension;
  22642. return data;
  22643. };
  22644. _proto.fromJSON = function fromJSON(json) {
  22645. _Curve.prototype.fromJSON.call(this, json);
  22646. this.points = [];
  22647. for (var i = 0, l = json.points.length; i < l; i++) {
  22648. var point = json.points[i];
  22649. this.points.push(new Vector3().fromArray(point));
  22650. }
  22651. this.closed = json.closed;
  22652. this.curveType = json.curveType;
  22653. this.tension = json.tension;
  22654. return this;
  22655. };
  22656. return CatmullRomCurve3;
  22657. }(Curve);
  22658. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22659. /**
  22660. * Bezier Curves formulas obtained from
  22661. * http://en.wikipedia.org/wiki/Bézier_curve
  22662. */
  22663. function CatmullRom(t, p0, p1, p2, p3) {
  22664. var v0 = (p2 - p0) * 0.5;
  22665. var v1 = (p3 - p1) * 0.5;
  22666. var t2 = t * t;
  22667. var t3 = t * t2;
  22668. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22669. } //
  22670. function QuadraticBezierP0(t, p) {
  22671. var k = 1 - t;
  22672. return k * k * p;
  22673. }
  22674. function QuadraticBezierP1(t, p) {
  22675. return 2 * (1 - t) * t * p;
  22676. }
  22677. function QuadraticBezierP2(t, p) {
  22678. return t * t * p;
  22679. }
  22680. function QuadraticBezier(t, p0, p1, p2) {
  22681. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22682. } //
  22683. function CubicBezierP0(t, p) {
  22684. var k = 1 - t;
  22685. return k * k * k * p;
  22686. }
  22687. function CubicBezierP1(t, p) {
  22688. var k = 1 - t;
  22689. return 3 * k * k * t * p;
  22690. }
  22691. function CubicBezierP2(t, p) {
  22692. return 3 * (1 - t) * t * t * p;
  22693. }
  22694. function CubicBezierP3(t, p) {
  22695. return t * t * t * p;
  22696. }
  22697. function CubicBezier(t, p0, p1, p2, p3) {
  22698. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22699. }
  22700. var CubicBezierCurve = /*#__PURE__*/function (_Curve) {
  22701. _inheritsLoose(CubicBezierCurve, _Curve);
  22702. function CubicBezierCurve(v0, v1, v2, v3) {
  22703. var _this;
  22704. if (v0 === void 0) {
  22705. v0 = new Vector2();
  22706. }
  22707. if (v1 === void 0) {
  22708. v1 = new Vector2();
  22709. }
  22710. if (v2 === void 0) {
  22711. v2 = new Vector2();
  22712. }
  22713. if (v3 === void 0) {
  22714. v3 = new Vector2();
  22715. }
  22716. _this = _Curve.call(this) || this;
  22717. _this.type = 'CubicBezierCurve';
  22718. _this.v0 = v0;
  22719. _this.v1 = v1;
  22720. _this.v2 = v2;
  22721. _this.v3 = v3;
  22722. return _this;
  22723. }
  22724. var _proto = CubicBezierCurve.prototype;
  22725. _proto.getPoint = function getPoint(t, optionalTarget) {
  22726. if (optionalTarget === void 0) {
  22727. optionalTarget = new Vector2();
  22728. }
  22729. var point = optionalTarget;
  22730. var v0 = this.v0,
  22731. v1 = this.v1,
  22732. v2 = this.v2,
  22733. v3 = this.v3;
  22734. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22735. return point;
  22736. };
  22737. _proto.copy = function copy(source) {
  22738. _Curve.prototype.copy.call(this, source);
  22739. this.v0.copy(source.v0);
  22740. this.v1.copy(source.v1);
  22741. this.v2.copy(source.v2);
  22742. this.v3.copy(source.v3);
  22743. return this;
  22744. };
  22745. _proto.toJSON = function toJSON() {
  22746. var data = _Curve.prototype.toJSON.call(this);
  22747. data.v0 = this.v0.toArray();
  22748. data.v1 = this.v1.toArray();
  22749. data.v2 = this.v2.toArray();
  22750. data.v3 = this.v3.toArray();
  22751. return data;
  22752. };
  22753. _proto.fromJSON = function fromJSON(json) {
  22754. _Curve.prototype.fromJSON.call(this, json);
  22755. this.v0.fromArray(json.v0);
  22756. this.v1.fromArray(json.v1);
  22757. this.v2.fromArray(json.v2);
  22758. this.v3.fromArray(json.v3);
  22759. return this;
  22760. };
  22761. return CubicBezierCurve;
  22762. }(Curve);
  22763. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22764. var CubicBezierCurve3 = /*#__PURE__*/function (_Curve) {
  22765. _inheritsLoose(CubicBezierCurve3, _Curve);
  22766. function CubicBezierCurve3(v0, v1, v2, v3) {
  22767. var _this;
  22768. if (v0 === void 0) {
  22769. v0 = new Vector3();
  22770. }
  22771. if (v1 === void 0) {
  22772. v1 = new Vector3();
  22773. }
  22774. if (v2 === void 0) {
  22775. v2 = new Vector3();
  22776. }
  22777. if (v3 === void 0) {
  22778. v3 = new Vector3();
  22779. }
  22780. _this = _Curve.call(this) || this;
  22781. _this.type = 'CubicBezierCurve3';
  22782. _this.v0 = v0;
  22783. _this.v1 = v1;
  22784. _this.v2 = v2;
  22785. _this.v3 = v3;
  22786. return _this;
  22787. }
  22788. var _proto = CubicBezierCurve3.prototype;
  22789. _proto.getPoint = function getPoint(t, optionalTarget) {
  22790. if (optionalTarget === void 0) {
  22791. optionalTarget = new Vector3();
  22792. }
  22793. var point = optionalTarget;
  22794. var v0 = this.v0,
  22795. v1 = this.v1,
  22796. v2 = this.v2,
  22797. v3 = this.v3;
  22798. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y), CubicBezier(t, v0.z, v1.z, v2.z, v3.z));
  22799. return point;
  22800. };
  22801. _proto.copy = function copy(source) {
  22802. _Curve.prototype.copy.call(this, source);
  22803. this.v0.copy(source.v0);
  22804. this.v1.copy(source.v1);
  22805. this.v2.copy(source.v2);
  22806. this.v3.copy(source.v3);
  22807. return this;
  22808. };
  22809. _proto.toJSON = function toJSON() {
  22810. var data = _Curve.prototype.toJSON.call(this);
  22811. data.v0 = this.v0.toArray();
  22812. data.v1 = this.v1.toArray();
  22813. data.v2 = this.v2.toArray();
  22814. data.v3 = this.v3.toArray();
  22815. return data;
  22816. };
  22817. _proto.fromJSON = function fromJSON(json) {
  22818. _Curve.prototype.fromJSON.call(this, json);
  22819. this.v0.fromArray(json.v0);
  22820. this.v1.fromArray(json.v1);
  22821. this.v2.fromArray(json.v2);
  22822. this.v3.fromArray(json.v3);
  22823. return this;
  22824. };
  22825. return CubicBezierCurve3;
  22826. }(Curve);
  22827. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22828. var LineCurve = /*#__PURE__*/function (_Curve) {
  22829. _inheritsLoose(LineCurve, _Curve);
  22830. function LineCurve(v1, v2) {
  22831. var _this;
  22832. if (v1 === void 0) {
  22833. v1 = new Vector2();
  22834. }
  22835. if (v2 === void 0) {
  22836. v2 = new Vector2();
  22837. }
  22838. _this = _Curve.call(this) || this;
  22839. _this.type = 'LineCurve';
  22840. _this.v1 = v1;
  22841. _this.v2 = v2;
  22842. return _this;
  22843. }
  22844. var _proto = LineCurve.prototype;
  22845. _proto.getPoint = function getPoint(t, optionalTarget) {
  22846. if (optionalTarget === void 0) {
  22847. optionalTarget = new Vector2();
  22848. }
  22849. var point = optionalTarget;
  22850. if (t === 1) {
  22851. point.copy(this.v2);
  22852. } else {
  22853. point.copy(this.v2).sub(this.v1);
  22854. point.multiplyScalar(t).add(this.v1);
  22855. }
  22856. return point;
  22857. } // Line curve is linear, so we can overwrite default getPointAt
  22858. ;
  22859. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22860. return this.getPoint(u, optionalTarget);
  22861. };
  22862. _proto.getTangent = function getTangent(t, optionalTarget) {
  22863. var tangent = optionalTarget || new Vector2();
  22864. tangent.copy(this.v2).sub(this.v1).normalize();
  22865. return tangent;
  22866. };
  22867. _proto.copy = function copy(source) {
  22868. _Curve.prototype.copy.call(this, source);
  22869. this.v1.copy(source.v1);
  22870. this.v2.copy(source.v2);
  22871. return this;
  22872. };
  22873. _proto.toJSON = function toJSON() {
  22874. var data = _Curve.prototype.toJSON.call(this);
  22875. data.v1 = this.v1.toArray();
  22876. data.v2 = this.v2.toArray();
  22877. return data;
  22878. };
  22879. _proto.fromJSON = function fromJSON(json) {
  22880. _Curve.prototype.fromJSON.call(this, json);
  22881. this.v1.fromArray(json.v1);
  22882. this.v2.fromArray(json.v2);
  22883. return this;
  22884. };
  22885. return LineCurve;
  22886. }(Curve);
  22887. LineCurve.prototype.isLineCurve = true;
  22888. var LineCurve3 = /*#__PURE__*/function (_Curve) {
  22889. _inheritsLoose(LineCurve3, _Curve);
  22890. function LineCurve3(v1, v2) {
  22891. var _this;
  22892. if (v1 === void 0) {
  22893. v1 = new Vector3();
  22894. }
  22895. if (v2 === void 0) {
  22896. v2 = new Vector3();
  22897. }
  22898. _this = _Curve.call(this) || this;
  22899. _this.type = 'LineCurve3';
  22900. _this.isLineCurve3 = true;
  22901. _this.v1 = v1;
  22902. _this.v2 = v2;
  22903. return _this;
  22904. }
  22905. var _proto = LineCurve3.prototype;
  22906. _proto.getPoint = function getPoint(t, optionalTarget) {
  22907. if (optionalTarget === void 0) {
  22908. optionalTarget = new Vector3();
  22909. }
  22910. var point = optionalTarget;
  22911. if (t === 1) {
  22912. point.copy(this.v2);
  22913. } else {
  22914. point.copy(this.v2).sub(this.v1);
  22915. point.multiplyScalar(t).add(this.v1);
  22916. }
  22917. return point;
  22918. } // Line curve is linear, so we can overwrite default getPointAt
  22919. ;
  22920. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22921. return this.getPoint(u, optionalTarget);
  22922. };
  22923. _proto.copy = function copy(source) {
  22924. _Curve.prototype.copy.call(this, source);
  22925. this.v1.copy(source.v1);
  22926. this.v2.copy(source.v2);
  22927. return this;
  22928. };
  22929. _proto.toJSON = function toJSON() {
  22930. var data = _Curve.prototype.toJSON.call(this);
  22931. data.v1 = this.v1.toArray();
  22932. data.v2 = this.v2.toArray();
  22933. return data;
  22934. };
  22935. _proto.fromJSON = function fromJSON(json) {
  22936. _Curve.prototype.fromJSON.call(this, json);
  22937. this.v1.fromArray(json.v1);
  22938. this.v2.fromArray(json.v2);
  22939. return this;
  22940. };
  22941. return LineCurve3;
  22942. }(Curve);
  22943. var QuadraticBezierCurve = /*#__PURE__*/function (_Curve) {
  22944. _inheritsLoose(QuadraticBezierCurve, _Curve);
  22945. function QuadraticBezierCurve(v0, v1, v2) {
  22946. var _this;
  22947. if (v0 === void 0) {
  22948. v0 = new Vector2();
  22949. }
  22950. if (v1 === void 0) {
  22951. v1 = new Vector2();
  22952. }
  22953. if (v2 === void 0) {
  22954. v2 = new Vector2();
  22955. }
  22956. _this = _Curve.call(this) || this;
  22957. _this.type = 'QuadraticBezierCurve';
  22958. _this.v0 = v0;
  22959. _this.v1 = v1;
  22960. _this.v2 = v2;
  22961. return _this;
  22962. }
  22963. var _proto = QuadraticBezierCurve.prototype;
  22964. _proto.getPoint = function getPoint(t, optionalTarget) {
  22965. if (optionalTarget === void 0) {
  22966. optionalTarget = new Vector2();
  22967. }
  22968. var point = optionalTarget;
  22969. var v0 = this.v0,
  22970. v1 = this.v1,
  22971. v2 = this.v2;
  22972. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22973. return point;
  22974. };
  22975. _proto.copy = function copy(source) {
  22976. _Curve.prototype.copy.call(this, source);
  22977. this.v0.copy(source.v0);
  22978. this.v1.copy(source.v1);
  22979. this.v2.copy(source.v2);
  22980. return this;
  22981. };
  22982. _proto.toJSON = function toJSON() {
  22983. var data = _Curve.prototype.toJSON.call(this);
  22984. data.v0 = this.v0.toArray();
  22985. data.v1 = this.v1.toArray();
  22986. data.v2 = this.v2.toArray();
  22987. return data;
  22988. };
  22989. _proto.fromJSON = function fromJSON(json) {
  22990. _Curve.prototype.fromJSON.call(this, json);
  22991. this.v0.fromArray(json.v0);
  22992. this.v1.fromArray(json.v1);
  22993. this.v2.fromArray(json.v2);
  22994. return this;
  22995. };
  22996. return QuadraticBezierCurve;
  22997. }(Curve);
  22998. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22999. var QuadraticBezierCurve3 = /*#__PURE__*/function (_Curve) {
  23000. _inheritsLoose(QuadraticBezierCurve3, _Curve);
  23001. function QuadraticBezierCurve3(v0, v1, v2) {
  23002. var _this;
  23003. if (v0 === void 0) {
  23004. v0 = new Vector3();
  23005. }
  23006. if (v1 === void 0) {
  23007. v1 = new Vector3();
  23008. }
  23009. if (v2 === void 0) {
  23010. v2 = new Vector3();
  23011. }
  23012. _this = _Curve.call(this) || this;
  23013. _this.type = 'QuadraticBezierCurve3';
  23014. _this.v0 = v0;
  23015. _this.v1 = v1;
  23016. _this.v2 = v2;
  23017. return _this;
  23018. }
  23019. var _proto = QuadraticBezierCurve3.prototype;
  23020. _proto.getPoint = function getPoint(t, optionalTarget) {
  23021. if (optionalTarget === void 0) {
  23022. optionalTarget = new Vector3();
  23023. }
  23024. var point = optionalTarget;
  23025. var v0 = this.v0,
  23026. v1 = this.v1,
  23027. v2 = this.v2;
  23028. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y), QuadraticBezier(t, v0.z, v1.z, v2.z));
  23029. return point;
  23030. };
  23031. _proto.copy = function copy(source) {
  23032. _Curve.prototype.copy.call(this, source);
  23033. this.v0.copy(source.v0);
  23034. this.v1.copy(source.v1);
  23035. this.v2.copy(source.v2);
  23036. return this;
  23037. };
  23038. _proto.toJSON = function toJSON() {
  23039. var data = _Curve.prototype.toJSON.call(this);
  23040. data.v0 = this.v0.toArray();
  23041. data.v1 = this.v1.toArray();
  23042. data.v2 = this.v2.toArray();
  23043. return data;
  23044. };
  23045. _proto.fromJSON = function fromJSON(json) {
  23046. _Curve.prototype.fromJSON.call(this, json);
  23047. this.v0.fromArray(json.v0);
  23048. this.v1.fromArray(json.v1);
  23049. this.v2.fromArray(json.v2);
  23050. return this;
  23051. };
  23052. return QuadraticBezierCurve3;
  23053. }(Curve);
  23054. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  23055. var SplineCurve = /*#__PURE__*/function (_Curve) {
  23056. _inheritsLoose(SplineCurve, _Curve);
  23057. function SplineCurve(points) {
  23058. var _this;
  23059. if (points === void 0) {
  23060. points = [];
  23061. }
  23062. _this = _Curve.call(this) || this;
  23063. _this.type = 'SplineCurve';
  23064. _this.points = points;
  23065. return _this;
  23066. }
  23067. var _proto = SplineCurve.prototype;
  23068. _proto.getPoint = function getPoint(t, optionalTarget) {
  23069. if (optionalTarget === void 0) {
  23070. optionalTarget = new Vector2();
  23071. }
  23072. var point = optionalTarget;
  23073. var points = this.points;
  23074. var p = (points.length - 1) * t;
  23075. var intPoint = Math.floor(p);
  23076. var weight = p - intPoint;
  23077. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  23078. var p1 = points[intPoint];
  23079. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  23080. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  23081. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  23082. return point;
  23083. };
  23084. _proto.copy = function copy(source) {
  23085. _Curve.prototype.copy.call(this, source);
  23086. this.points = [];
  23087. for (var i = 0, l = source.points.length; i < l; i++) {
  23088. var point = source.points[i];
  23089. this.points.push(point.clone());
  23090. }
  23091. return this;
  23092. };
  23093. _proto.toJSON = function toJSON() {
  23094. var data = _Curve.prototype.toJSON.call(this);
  23095. data.points = [];
  23096. for (var i = 0, l = this.points.length; i < l; i++) {
  23097. var point = this.points[i];
  23098. data.points.push(point.toArray());
  23099. }
  23100. return data;
  23101. };
  23102. _proto.fromJSON = function fromJSON(json) {
  23103. _Curve.prototype.fromJSON.call(this, json);
  23104. this.points = [];
  23105. for (var i = 0, l = json.points.length; i < l; i++) {
  23106. var point = json.points[i];
  23107. this.points.push(new Vector2().fromArray(point));
  23108. }
  23109. return this;
  23110. };
  23111. return SplineCurve;
  23112. }(Curve);
  23113. SplineCurve.prototype.isSplineCurve = true;
  23114. var Curves = /*#__PURE__*/Object.freeze({
  23115. __proto__: null,
  23116. ArcCurve: ArcCurve,
  23117. CatmullRomCurve3: CatmullRomCurve3,
  23118. CubicBezierCurve: CubicBezierCurve,
  23119. CubicBezierCurve3: CubicBezierCurve3,
  23120. EllipseCurve: EllipseCurve,
  23121. LineCurve: LineCurve,
  23122. LineCurve3: LineCurve3,
  23123. QuadraticBezierCurve: QuadraticBezierCurve,
  23124. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23125. SplineCurve: SplineCurve
  23126. });
  23127. /**************************************************************
  23128. * Curved Path - a curve path is simply a array of connected
  23129. * curves, but retains the api of a curve
  23130. **************************************************************/
  23131. var CurvePath = /*#__PURE__*/function (_Curve) {
  23132. _inheritsLoose(CurvePath, _Curve);
  23133. function CurvePath() {
  23134. var _this;
  23135. _this = _Curve.call(this) || this;
  23136. _this.type = 'CurvePath';
  23137. _this.curves = [];
  23138. _this.autoClose = false; // Automatically closes the path
  23139. return _this;
  23140. }
  23141. var _proto = CurvePath.prototype;
  23142. _proto.add = function add(curve) {
  23143. this.curves.push(curve);
  23144. };
  23145. _proto.closePath = function closePath() {
  23146. // Add a line curve if start and end of lines are not connected
  23147. var startPoint = this.curves[0].getPoint(0);
  23148. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  23149. if (!startPoint.equals(endPoint)) {
  23150. this.curves.push(new LineCurve(endPoint, startPoint));
  23151. }
  23152. } // To get accurate point with reference to
  23153. // entire path distance at time t,
  23154. // following has to be done:
  23155. // 1. Length of each sub path have to be known
  23156. // 2. Locate and identify type of curve
  23157. // 3. Get t for the curve
  23158. // 4. Return curve.getPointAt(t')
  23159. ;
  23160. _proto.getPoint = function getPoint(t) {
  23161. var d = t * this.getLength();
  23162. var curveLengths = this.getCurveLengths();
  23163. var i = 0; // To think about boundaries points.
  23164. while (i < curveLengths.length) {
  23165. if (curveLengths[i] >= d) {
  23166. var diff = curveLengths[i] - d;
  23167. var curve = this.curves[i];
  23168. var segmentLength = curve.getLength();
  23169. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23170. return curve.getPointAt(u);
  23171. }
  23172. i++;
  23173. }
  23174. return null; // loop where sum != 0, sum > d , sum+1 <d
  23175. } // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23176. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23177. // getPoint() depends on getLength
  23178. ;
  23179. _proto.getLength = function getLength() {
  23180. var lens = this.getCurveLengths();
  23181. return lens[lens.length - 1];
  23182. } // cacheLengths must be recalculated.
  23183. ;
  23184. _proto.updateArcLengths = function updateArcLengths() {
  23185. this.needsUpdate = true;
  23186. this.cacheLengths = null;
  23187. this.getCurveLengths();
  23188. } // Compute lengths and cache them
  23189. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23190. ;
  23191. _proto.getCurveLengths = function getCurveLengths() {
  23192. // We use cache values if curves and cache array are same length
  23193. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  23194. return this.cacheLengths;
  23195. } // Get length of sub-curve
  23196. // Push sums into cached array
  23197. var lengths = [];
  23198. var sums = 0;
  23199. for (var i = 0, l = this.curves.length; i < l; i++) {
  23200. sums += this.curves[i].getLength();
  23201. lengths.push(sums);
  23202. }
  23203. this.cacheLengths = lengths;
  23204. return lengths;
  23205. };
  23206. _proto.getSpacedPoints = function getSpacedPoints(divisions) {
  23207. if (divisions === void 0) {
  23208. divisions = 40;
  23209. }
  23210. var points = [];
  23211. for (var i = 0; i <= divisions; i++) {
  23212. points.push(this.getPoint(i / divisions));
  23213. }
  23214. if (this.autoClose) {
  23215. points.push(points[0]);
  23216. }
  23217. return points;
  23218. };
  23219. _proto.getPoints = function getPoints(divisions) {
  23220. if (divisions === void 0) {
  23221. divisions = 12;
  23222. }
  23223. var points = [];
  23224. var last;
  23225. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23226. var curve = curves[i];
  23227. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23228. var pts = curve.getPoints(resolution);
  23229. for (var j = 0; j < pts.length; j++) {
  23230. var point = pts[j];
  23231. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23232. points.push(point);
  23233. last = point;
  23234. }
  23235. }
  23236. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23237. points.push(points[0]);
  23238. }
  23239. return points;
  23240. };
  23241. _proto.copy = function copy(source) {
  23242. _Curve.prototype.copy.call(this, source);
  23243. this.curves = [];
  23244. for (var i = 0, l = source.curves.length; i < l; i++) {
  23245. var curve = source.curves[i];
  23246. this.curves.push(curve.clone());
  23247. }
  23248. this.autoClose = source.autoClose;
  23249. return this;
  23250. };
  23251. _proto.toJSON = function toJSON() {
  23252. var data = _Curve.prototype.toJSON.call(this);
  23253. data.autoClose = this.autoClose;
  23254. data.curves = [];
  23255. for (var i = 0, l = this.curves.length; i < l; i++) {
  23256. var curve = this.curves[i];
  23257. data.curves.push(curve.toJSON());
  23258. }
  23259. return data;
  23260. };
  23261. _proto.fromJSON = function fromJSON(json) {
  23262. _Curve.prototype.fromJSON.call(this, json);
  23263. this.autoClose = json.autoClose;
  23264. this.curves = [];
  23265. for (var i = 0, l = json.curves.length; i < l; i++) {
  23266. var curve = json.curves[i];
  23267. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23268. }
  23269. return this;
  23270. };
  23271. return CurvePath;
  23272. }(Curve);
  23273. var Path = /*#__PURE__*/function (_CurvePath) {
  23274. _inheritsLoose(Path, _CurvePath);
  23275. function Path(points) {
  23276. var _this;
  23277. _this = _CurvePath.call(this) || this;
  23278. _this.type = 'Path';
  23279. _this.currentPoint = new Vector2();
  23280. if (points) {
  23281. _this.setFromPoints(points);
  23282. }
  23283. return _this;
  23284. }
  23285. var _proto = Path.prototype;
  23286. _proto.setFromPoints = function setFromPoints(points) {
  23287. this.moveTo(points[0].x, points[0].y);
  23288. for (var i = 1, l = points.length; i < l; i++) {
  23289. this.lineTo(points[i].x, points[i].y);
  23290. }
  23291. return this;
  23292. };
  23293. _proto.moveTo = function moveTo(x, y) {
  23294. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23295. return this;
  23296. };
  23297. _proto.lineTo = function lineTo(x, y) {
  23298. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23299. this.curves.push(curve);
  23300. this.currentPoint.set(x, y);
  23301. return this;
  23302. };
  23303. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23304. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23305. this.curves.push(curve);
  23306. this.currentPoint.set(aX, aY);
  23307. return this;
  23308. };
  23309. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23310. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23311. this.curves.push(curve);
  23312. this.currentPoint.set(aX, aY);
  23313. return this;
  23314. };
  23315. _proto.splineThru = function splineThru(pts
  23316. /*Array of Vector*/
  23317. ) {
  23318. var npts = [this.currentPoint.clone()].concat(pts);
  23319. var curve = new SplineCurve(npts);
  23320. this.curves.push(curve);
  23321. this.currentPoint.copy(pts[pts.length - 1]);
  23322. return this;
  23323. };
  23324. _proto.arc = function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23325. var x0 = this.currentPoint.x;
  23326. var y0 = this.currentPoint.y;
  23327. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23328. return this;
  23329. };
  23330. _proto.absarc = function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23331. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23332. return this;
  23333. };
  23334. _proto.ellipse = function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23335. var x0 = this.currentPoint.x;
  23336. var y0 = this.currentPoint.y;
  23337. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23338. return this;
  23339. };
  23340. _proto.absellipse = function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23341. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23342. if (this.curves.length > 0) {
  23343. // if a previous curve is present, attempt to join
  23344. var firstPoint = curve.getPoint(0);
  23345. if (!firstPoint.equals(this.currentPoint)) {
  23346. this.lineTo(firstPoint.x, firstPoint.y);
  23347. }
  23348. }
  23349. this.curves.push(curve);
  23350. var lastPoint = curve.getPoint(1);
  23351. this.currentPoint.copy(lastPoint);
  23352. return this;
  23353. };
  23354. _proto.copy = function copy(source) {
  23355. _CurvePath.prototype.copy.call(this, source);
  23356. this.currentPoint.copy(source.currentPoint);
  23357. return this;
  23358. };
  23359. _proto.toJSON = function toJSON() {
  23360. var data = _CurvePath.prototype.toJSON.call(this);
  23361. data.currentPoint = this.currentPoint.toArray();
  23362. return data;
  23363. };
  23364. _proto.fromJSON = function fromJSON(json) {
  23365. _CurvePath.prototype.fromJSON.call(this, json);
  23366. this.currentPoint.fromArray(json.currentPoint);
  23367. return this;
  23368. };
  23369. return Path;
  23370. }(CurvePath);
  23371. var Shape = /*#__PURE__*/function (_Path) {
  23372. _inheritsLoose(Shape, _Path);
  23373. function Shape(points) {
  23374. var _this;
  23375. _this = _Path.call(this, points) || this;
  23376. _this.uuid = MathUtils.generateUUID();
  23377. _this.type = 'Shape';
  23378. _this.holes = [];
  23379. return _this;
  23380. }
  23381. var _proto = Shape.prototype;
  23382. _proto.getPointsHoles = function getPointsHoles(divisions) {
  23383. var holesPts = [];
  23384. for (var i = 0, l = this.holes.length; i < l; i++) {
  23385. holesPts[i] = this.holes[i].getPoints(divisions);
  23386. }
  23387. return holesPts;
  23388. } // get points of shape and holes (keypoints based on segments parameter)
  23389. ;
  23390. _proto.extractPoints = function extractPoints(divisions) {
  23391. return {
  23392. shape: this.getPoints(divisions),
  23393. holes: this.getPointsHoles(divisions)
  23394. };
  23395. };
  23396. _proto.copy = function copy(source) {
  23397. _Path.prototype.copy.call(this, source);
  23398. this.holes = [];
  23399. for (var i = 0, l = source.holes.length; i < l; i++) {
  23400. var hole = source.holes[i];
  23401. this.holes.push(hole.clone());
  23402. }
  23403. return this;
  23404. };
  23405. _proto.toJSON = function toJSON() {
  23406. var data = _Path.prototype.toJSON.call(this);
  23407. data.uuid = this.uuid;
  23408. data.holes = [];
  23409. for (var i = 0, l = this.holes.length; i < l; i++) {
  23410. var hole = this.holes[i];
  23411. data.holes.push(hole.toJSON());
  23412. }
  23413. return data;
  23414. };
  23415. _proto.fromJSON = function fromJSON(json) {
  23416. _Path.prototype.fromJSON.call(this, json);
  23417. this.uuid = json.uuid;
  23418. this.holes = [];
  23419. for (var i = 0, l = json.holes.length; i < l; i++) {
  23420. var hole = json.holes[i];
  23421. this.holes.push(new Path().fromJSON(hole));
  23422. }
  23423. return this;
  23424. };
  23425. return Shape;
  23426. }(Path);
  23427. var Light = /*#__PURE__*/function (_Object3D) {
  23428. _inheritsLoose(Light, _Object3D);
  23429. function Light(color, intensity) {
  23430. var _this;
  23431. if (intensity === void 0) {
  23432. intensity = 1;
  23433. }
  23434. _this = _Object3D.call(this) || this;
  23435. _this.type = 'Light';
  23436. _this.color = new Color(color);
  23437. _this.intensity = intensity;
  23438. return _this;
  23439. }
  23440. var _proto = Light.prototype;
  23441. _proto.copy = function copy(source) {
  23442. _Object3D.prototype.copy.call(this, source);
  23443. this.color.copy(source.color);
  23444. this.intensity = source.intensity;
  23445. return this;
  23446. };
  23447. _proto.toJSON = function toJSON(meta) {
  23448. var data = _Object3D.prototype.toJSON.call(this, meta);
  23449. data.object.color = this.color.getHex();
  23450. data.object.intensity = this.intensity;
  23451. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23452. if (this.distance !== undefined) data.object.distance = this.distance;
  23453. if (this.angle !== undefined) data.object.angle = this.angle;
  23454. if (this.decay !== undefined) data.object.decay = this.decay;
  23455. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23456. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23457. return data;
  23458. };
  23459. return Light;
  23460. }(Object3D);
  23461. Light.prototype.isLight = true;
  23462. var HemisphereLight = /*#__PURE__*/function (_Light) {
  23463. _inheritsLoose(HemisphereLight, _Light);
  23464. function HemisphereLight(skyColor, groundColor, intensity) {
  23465. var _this;
  23466. _this = _Light.call(this, skyColor, intensity) || this;
  23467. _this.type = 'HemisphereLight';
  23468. _this.position.copy(Object3D.DefaultUp);
  23469. _this.updateMatrix();
  23470. _this.groundColor = new Color(groundColor);
  23471. return _this;
  23472. }
  23473. var _proto = HemisphereLight.prototype;
  23474. _proto.copy = function copy(source) {
  23475. Light.prototype.copy.call(this, source);
  23476. this.groundColor.copy(source.groundColor);
  23477. return this;
  23478. };
  23479. return HemisphereLight;
  23480. }(Light);
  23481. HemisphereLight.prototype.isHemisphereLight = true;
  23482. var _projScreenMatrix = /*@__PURE__*/new Matrix4();
  23483. var _lightPositionWorld = /*@__PURE__*/new Vector3();
  23484. var _lookTarget = /*@__PURE__*/new Vector3();
  23485. var LightShadow = /*#__PURE__*/function () {
  23486. function LightShadow(camera) {
  23487. this.camera = camera;
  23488. this.bias = 0;
  23489. this.normalBias = 0;
  23490. this.radius = 1;
  23491. this.mapSize = new Vector2(512, 512);
  23492. this.map = null;
  23493. this.mapPass = null;
  23494. this.matrix = new Matrix4();
  23495. this.autoUpdate = true;
  23496. this.needsUpdate = false;
  23497. this._frustum = new Frustum();
  23498. this._frameExtents = new Vector2(1, 1);
  23499. this._viewportCount = 1;
  23500. this._viewports = [new Vector4(0, 0, 1, 1)];
  23501. }
  23502. var _proto = LightShadow.prototype;
  23503. _proto.getViewportCount = function getViewportCount() {
  23504. return this._viewportCount;
  23505. };
  23506. _proto.getFrustum = function getFrustum() {
  23507. return this._frustum;
  23508. };
  23509. _proto.updateMatrices = function updateMatrices(light) {
  23510. var shadowCamera = this.camera;
  23511. var shadowMatrix = this.matrix;
  23512. _lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23513. shadowCamera.position.copy(_lightPositionWorld);
  23514. _lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23515. shadowCamera.lookAt(_lookTarget);
  23516. shadowCamera.updateMatrixWorld();
  23517. _projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23518. this._frustum.setFromProjectionMatrix(_projScreenMatrix);
  23519. shadowMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
  23520. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23521. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23522. };
  23523. _proto.getViewport = function getViewport(viewportIndex) {
  23524. return this._viewports[viewportIndex];
  23525. };
  23526. _proto.getFrameExtents = function getFrameExtents() {
  23527. return this._frameExtents;
  23528. };
  23529. _proto.copy = function copy(source) {
  23530. this.camera = source.camera.clone();
  23531. this.bias = source.bias;
  23532. this.radius = source.radius;
  23533. this.mapSize.copy(source.mapSize);
  23534. return this;
  23535. };
  23536. _proto.clone = function clone() {
  23537. return new this.constructor().copy(this);
  23538. };
  23539. _proto.toJSON = function toJSON() {
  23540. var object = {};
  23541. if (this.bias !== 0) object.bias = this.bias;
  23542. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23543. if (this.radius !== 1) object.radius = this.radius;
  23544. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23545. object.camera = this.camera.toJSON(false).object;
  23546. delete object.camera.matrix;
  23547. return object;
  23548. };
  23549. return LightShadow;
  23550. }();
  23551. var SpotLightShadow = /*#__PURE__*/function (_LightShadow) {
  23552. _inheritsLoose(SpotLightShadow, _LightShadow);
  23553. function SpotLightShadow() {
  23554. var _this;
  23555. _this = _LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500)) || this;
  23556. _this.focus = 1;
  23557. return _this;
  23558. }
  23559. var _proto = SpotLightShadow.prototype;
  23560. _proto.updateMatrices = function updateMatrices(light) {
  23561. var camera = this.camera;
  23562. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23563. var aspect = this.mapSize.width / this.mapSize.height;
  23564. var far = light.distance || camera.far;
  23565. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23566. camera.fov = fov;
  23567. camera.aspect = aspect;
  23568. camera.far = far;
  23569. camera.updateProjectionMatrix();
  23570. }
  23571. _LightShadow.prototype.updateMatrices.call(this, light);
  23572. };
  23573. return SpotLightShadow;
  23574. }(LightShadow);
  23575. SpotLightShadow.prototype.isSpotLightShadow = true;
  23576. var SpotLight = /*#__PURE__*/function (_Light) {
  23577. _inheritsLoose(SpotLight, _Light);
  23578. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23579. var _this;
  23580. if (distance === void 0) {
  23581. distance = 0;
  23582. }
  23583. if (angle === void 0) {
  23584. angle = Math.PI / 3;
  23585. }
  23586. if (penumbra === void 0) {
  23587. penumbra = 0;
  23588. }
  23589. if (decay === void 0) {
  23590. decay = 1;
  23591. }
  23592. _this = _Light.call(this, color, intensity) || this;
  23593. _this.type = 'SpotLight';
  23594. _this.position.copy(Object3D.DefaultUp);
  23595. _this.updateMatrix();
  23596. _this.target = new Object3D();
  23597. _this.distance = distance;
  23598. _this.angle = angle;
  23599. _this.penumbra = penumbra;
  23600. _this.decay = decay; // for physically correct lights, should be 2.
  23601. _this.shadow = new SpotLightShadow();
  23602. return _this;
  23603. }
  23604. var _proto = SpotLight.prototype;
  23605. _proto.copy = function copy(source) {
  23606. _Light.prototype.copy.call(this, source);
  23607. this.distance = source.distance;
  23608. this.angle = source.angle;
  23609. this.penumbra = source.penumbra;
  23610. this.decay = source.decay;
  23611. this.target = source.target.clone();
  23612. this.shadow = source.shadow.clone();
  23613. return this;
  23614. };
  23615. _createClass(SpotLight, [{
  23616. key: "power",
  23617. get: function get() {
  23618. // intensity = power per solid angle.
  23619. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23620. return this.intensity * Math.PI;
  23621. },
  23622. set: function set(power) {
  23623. // intensity = power per solid angle.
  23624. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23625. this.intensity = power / Math.PI;
  23626. }
  23627. }]);
  23628. return SpotLight;
  23629. }(Light);
  23630. SpotLight.prototype.isSpotLight = true;
  23631. var _projScreenMatrix$1 = /*@__PURE__*/new Matrix4();
  23632. var _lightPositionWorld$1 = /*@__PURE__*/new Vector3();
  23633. var _lookTarget$1 = /*@__PURE__*/new Vector3();
  23634. var PointLightShadow = /*#__PURE__*/function (_LightShadow) {
  23635. _inheritsLoose(PointLightShadow, _LightShadow);
  23636. function PointLightShadow() {
  23637. var _this;
  23638. _this = _LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500)) || this;
  23639. _this._frameExtents = new Vector2(4, 2);
  23640. _this._viewportCount = 6;
  23641. _this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23642. // following orientation:
  23643. //
  23644. // xzXZ
  23645. // y Y
  23646. //
  23647. // X - Positive x direction
  23648. // x - Negative x direction
  23649. // Y - Positive y direction
  23650. // y - Negative y direction
  23651. // Z - Positive z direction
  23652. // z - Negative z direction
  23653. // positive X
  23654. new Vector4(2, 1, 1, 1), // negative X
  23655. new Vector4(0, 1, 1, 1), // positive Z
  23656. new Vector4(3, 1, 1, 1), // negative Z
  23657. new Vector4(1, 1, 1, 1), // positive Y
  23658. new Vector4(3, 0, 1, 1), // negative Y
  23659. new Vector4(1, 0, 1, 1)];
  23660. _this._cubeDirections = [new Vector3(1, 0, 0), new Vector3(-1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 0, -1), new Vector3(0, 1, 0), new Vector3(0, -1, 0)];
  23661. _this._cubeUps = [new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1), new Vector3(0, 0, -1)];
  23662. return _this;
  23663. }
  23664. var _proto = PointLightShadow.prototype;
  23665. _proto.updateMatrices = function updateMatrices(light, viewportIndex) {
  23666. if (viewportIndex === void 0) {
  23667. viewportIndex = 0;
  23668. }
  23669. var camera = this.camera;
  23670. var shadowMatrix = this.matrix;
  23671. _lightPositionWorld$1.setFromMatrixPosition(light.matrixWorld);
  23672. camera.position.copy(_lightPositionWorld$1);
  23673. _lookTarget$1.copy(camera.position);
  23674. _lookTarget$1.add(this._cubeDirections[viewportIndex]);
  23675. camera.up.copy(this._cubeUps[viewportIndex]);
  23676. camera.lookAt(_lookTarget$1);
  23677. camera.updateMatrixWorld();
  23678. shadowMatrix.makeTranslation(-_lightPositionWorld$1.x, -_lightPositionWorld$1.y, -_lightPositionWorld$1.z);
  23679. _projScreenMatrix$1.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23680. this._frustum.setFromProjectionMatrix(_projScreenMatrix$1);
  23681. };
  23682. return PointLightShadow;
  23683. }(LightShadow);
  23684. PointLightShadow.prototype.isPointLightShadow = true;
  23685. var PointLight = /*#__PURE__*/function (_Light) {
  23686. _inheritsLoose(PointLight, _Light);
  23687. function PointLight(color, intensity, distance, decay) {
  23688. var _this;
  23689. if (distance === void 0) {
  23690. distance = 0;
  23691. }
  23692. if (decay === void 0) {
  23693. decay = 1;
  23694. }
  23695. _this = _Light.call(this, color, intensity) || this;
  23696. _this.type = 'PointLight';
  23697. _this.distance = distance;
  23698. _this.decay = decay; // for physically correct lights, should be 2.
  23699. _this.shadow = new PointLightShadow();
  23700. return _this;
  23701. }
  23702. var _proto = PointLight.prototype;
  23703. _proto.copy = function copy(source) {
  23704. _Light.prototype.copy.call(this, source);
  23705. this.distance = source.distance;
  23706. this.decay = source.decay;
  23707. this.shadow = source.shadow.clone();
  23708. return this;
  23709. };
  23710. _createClass(PointLight, [{
  23711. key: "power",
  23712. get: function get() {
  23713. // intensity = power per solid angle.
  23714. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23715. return this.intensity * 4 * Math.PI;
  23716. },
  23717. set: function set(power) {
  23718. // intensity = power per solid angle.
  23719. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23720. this.intensity = power / (4 * Math.PI);
  23721. }
  23722. }]);
  23723. return PointLight;
  23724. }(Light);
  23725. PointLight.prototype.isPointLight = true;
  23726. var OrthographicCamera = /*#__PURE__*/function (_Camera) {
  23727. _inheritsLoose(OrthographicCamera, _Camera);
  23728. function OrthographicCamera(left, right, top, bottom, near, far) {
  23729. var _this;
  23730. if (left === void 0) {
  23731. left = -1;
  23732. }
  23733. if (right === void 0) {
  23734. right = 1;
  23735. }
  23736. if (top === void 0) {
  23737. top = 1;
  23738. }
  23739. if (bottom === void 0) {
  23740. bottom = -1;
  23741. }
  23742. if (near === void 0) {
  23743. near = 0.1;
  23744. }
  23745. if (far === void 0) {
  23746. far = 2000;
  23747. }
  23748. _this = _Camera.call(this) || this;
  23749. _this.type = 'OrthographicCamera';
  23750. _this.zoom = 1;
  23751. _this.view = null;
  23752. _this.left = left;
  23753. _this.right = right;
  23754. _this.top = top;
  23755. _this.bottom = bottom;
  23756. _this.near = near;
  23757. _this.far = far;
  23758. _this.updateProjectionMatrix();
  23759. return _this;
  23760. }
  23761. var _proto = OrthographicCamera.prototype;
  23762. _proto.copy = function copy(source, recursive) {
  23763. _Camera.prototype.copy.call(this, source, recursive);
  23764. this.left = source.left;
  23765. this.right = source.right;
  23766. this.top = source.top;
  23767. this.bottom = source.bottom;
  23768. this.near = source.near;
  23769. this.far = source.far;
  23770. this.zoom = source.zoom;
  23771. this.view = source.view === null ? null : Object.assign({}, source.view);
  23772. return this;
  23773. };
  23774. _proto.setViewOffset = function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23775. if (this.view === null) {
  23776. this.view = {
  23777. enabled: true,
  23778. fullWidth: 1,
  23779. fullHeight: 1,
  23780. offsetX: 0,
  23781. offsetY: 0,
  23782. width: 1,
  23783. height: 1
  23784. };
  23785. }
  23786. this.view.enabled = true;
  23787. this.view.fullWidth = fullWidth;
  23788. this.view.fullHeight = fullHeight;
  23789. this.view.offsetX = x;
  23790. this.view.offsetY = y;
  23791. this.view.width = width;
  23792. this.view.height = height;
  23793. this.updateProjectionMatrix();
  23794. };
  23795. _proto.clearViewOffset = function clearViewOffset() {
  23796. if (this.view !== null) {
  23797. this.view.enabled = false;
  23798. }
  23799. this.updateProjectionMatrix();
  23800. };
  23801. _proto.updateProjectionMatrix = function updateProjectionMatrix() {
  23802. var dx = (this.right - this.left) / (2 * this.zoom);
  23803. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23804. var cx = (this.right + this.left) / 2;
  23805. var cy = (this.top + this.bottom) / 2;
  23806. var left = cx - dx;
  23807. var right = cx + dx;
  23808. var top = cy + dy;
  23809. var bottom = cy - dy;
  23810. if (this.view !== null && this.view.enabled) {
  23811. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23812. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23813. left += scaleW * this.view.offsetX;
  23814. right = left + scaleW * this.view.width;
  23815. top -= scaleH * this.view.offsetY;
  23816. bottom = top - scaleH * this.view.height;
  23817. }
  23818. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23819. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23820. };
  23821. _proto.toJSON = function toJSON(meta) {
  23822. var data = Object3D.prototype.toJSON.call(this, meta);
  23823. data.object.zoom = this.zoom;
  23824. data.object.left = this.left;
  23825. data.object.right = this.right;
  23826. data.object.top = this.top;
  23827. data.object.bottom = this.bottom;
  23828. data.object.near = this.near;
  23829. data.object.far = this.far;
  23830. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23831. return data;
  23832. };
  23833. return OrthographicCamera;
  23834. }(Camera);
  23835. OrthographicCamera.prototype.isOrthographicCamera = true;
  23836. var DirectionalLightShadow = /*#__PURE__*/function (_LightShadow) {
  23837. _inheritsLoose(DirectionalLightShadow, _LightShadow);
  23838. function DirectionalLightShadow() {
  23839. return _LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500)) || this;
  23840. }
  23841. return DirectionalLightShadow;
  23842. }(LightShadow);
  23843. DirectionalLightShadow.prototype.isDirectionalLightShadow = true;
  23844. var DirectionalLight = /*#__PURE__*/function (_Light) {
  23845. _inheritsLoose(DirectionalLight, _Light);
  23846. function DirectionalLight(color, intensity) {
  23847. var _this;
  23848. _this = _Light.call(this, color, intensity) || this;
  23849. _this.type = 'DirectionalLight';
  23850. _this.position.copy(Object3D.DefaultUp);
  23851. _this.updateMatrix();
  23852. _this.target = new Object3D();
  23853. _this.shadow = new DirectionalLightShadow();
  23854. return _this;
  23855. }
  23856. var _proto = DirectionalLight.prototype;
  23857. _proto.copy = function copy(source) {
  23858. _Light.prototype.copy.call(this, source);
  23859. this.target = source.target.clone();
  23860. this.shadow = source.shadow.clone();
  23861. return this;
  23862. };
  23863. return DirectionalLight;
  23864. }(Light);
  23865. DirectionalLight.prototype.isDirectionalLight = true;
  23866. var AmbientLight = /*#__PURE__*/function (_Light) {
  23867. _inheritsLoose(AmbientLight, _Light);
  23868. function AmbientLight(color, intensity) {
  23869. var _this;
  23870. _this = _Light.call(this, color, intensity) || this;
  23871. _this.type = 'AmbientLight';
  23872. return _this;
  23873. }
  23874. return AmbientLight;
  23875. }(Light);
  23876. AmbientLight.prototype.isAmbientLight = true;
  23877. var RectAreaLight = /*#__PURE__*/function (_Light) {
  23878. _inheritsLoose(RectAreaLight, _Light);
  23879. function RectAreaLight(color, intensity, width, height) {
  23880. var _this;
  23881. if (width === void 0) {
  23882. width = 10;
  23883. }
  23884. if (height === void 0) {
  23885. height = 10;
  23886. }
  23887. _this = _Light.call(this, color, intensity) || this;
  23888. _this.type = 'RectAreaLight';
  23889. _this.width = width;
  23890. _this.height = height;
  23891. return _this;
  23892. }
  23893. var _proto = RectAreaLight.prototype;
  23894. _proto.copy = function copy(source) {
  23895. _Light.prototype.copy.call(this, source);
  23896. this.width = source.width;
  23897. this.height = source.height;
  23898. return this;
  23899. };
  23900. _proto.toJSON = function toJSON(meta) {
  23901. var data = _Light.prototype.toJSON.call(this, meta);
  23902. data.object.width = this.width;
  23903. data.object.height = this.height;
  23904. return data;
  23905. };
  23906. return RectAreaLight;
  23907. }(Light);
  23908. RectAreaLight.prototype.isRectAreaLight = true;
  23909. /**
  23910. * Primary reference:
  23911. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23912. *
  23913. * Secondary reference:
  23914. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23915. */
  23916. // 3-band SH defined by 9 coefficients
  23917. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23918. function SphericalHarmonics3() {
  23919. this.coefficients = [];
  23920. for (var i = 0; i < 9; i++) {
  23921. this.coefficients.push(new Vector3());
  23922. }
  23923. }
  23924. var _proto = SphericalHarmonics3.prototype;
  23925. _proto.set = function set(coefficients) {
  23926. for (var i = 0; i < 9; i++) {
  23927. this.coefficients[i].copy(coefficients[i]);
  23928. }
  23929. return this;
  23930. };
  23931. _proto.zero = function zero() {
  23932. for (var i = 0; i < 9; i++) {
  23933. this.coefficients[i].set(0, 0, 0);
  23934. }
  23935. return this;
  23936. } // get the radiance in the direction of the normal
  23937. // target is a Vector3
  23938. ;
  23939. _proto.getAt = function getAt(normal, target) {
  23940. // normal is assumed to be unit length
  23941. var x = normal.x,
  23942. y = normal.y,
  23943. z = normal.z;
  23944. var coeff = this.coefficients; // band 0
  23945. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23946. target.addScaledVector(coeff[1], 0.488603 * y);
  23947. target.addScaledVector(coeff[2], 0.488603 * z);
  23948. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23949. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23950. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23951. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23952. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23953. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23954. return target;
  23955. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23956. // target is a Vector3
  23957. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23958. ;
  23959. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23960. // normal is assumed to be unit length
  23961. var x = normal.x,
  23962. y = normal.y,
  23963. z = normal.z;
  23964. var coeff = this.coefficients; // band 0
  23965. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23966. // band 1
  23967. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23968. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23969. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23970. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23971. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23972. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23973. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23974. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23975. return target;
  23976. };
  23977. _proto.add = function add(sh) {
  23978. for (var i = 0; i < 9; i++) {
  23979. this.coefficients[i].add(sh.coefficients[i]);
  23980. }
  23981. return this;
  23982. };
  23983. _proto.addScaledSH = function addScaledSH(sh, s) {
  23984. for (var i = 0; i < 9; i++) {
  23985. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23986. }
  23987. return this;
  23988. };
  23989. _proto.scale = function scale(s) {
  23990. for (var i = 0; i < 9; i++) {
  23991. this.coefficients[i].multiplyScalar(s);
  23992. }
  23993. return this;
  23994. };
  23995. _proto.lerp = function lerp(sh, alpha) {
  23996. for (var i = 0; i < 9; i++) {
  23997. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23998. }
  23999. return this;
  24000. };
  24001. _proto.equals = function equals(sh) {
  24002. for (var i = 0; i < 9; i++) {
  24003. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  24004. return false;
  24005. }
  24006. }
  24007. return true;
  24008. };
  24009. _proto.copy = function copy(sh) {
  24010. return this.set(sh.coefficients);
  24011. };
  24012. _proto.clone = function clone() {
  24013. return new this.constructor().copy(this);
  24014. };
  24015. _proto.fromArray = function fromArray(array, offset) {
  24016. if (offset === void 0) {
  24017. offset = 0;
  24018. }
  24019. var coefficients = this.coefficients;
  24020. for (var i = 0; i < 9; i++) {
  24021. coefficients[i].fromArray(array, offset + i * 3);
  24022. }
  24023. return this;
  24024. };
  24025. _proto.toArray = function toArray(array, offset) {
  24026. if (array === void 0) {
  24027. array = [];
  24028. }
  24029. if (offset === void 0) {
  24030. offset = 0;
  24031. }
  24032. var coefficients = this.coefficients;
  24033. for (var i = 0; i < 9; i++) {
  24034. coefficients[i].toArray(array, offset + i * 3);
  24035. }
  24036. return array;
  24037. } // evaluate the basis functions
  24038. // shBasis is an Array[ 9 ]
  24039. ;
  24040. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  24041. // normal is assumed to be unit length
  24042. var x = normal.x,
  24043. y = normal.y,
  24044. z = normal.z; // band 0
  24045. shBasis[0] = 0.282095; // band 1
  24046. shBasis[1] = 0.488603 * y;
  24047. shBasis[2] = 0.488603 * z;
  24048. shBasis[3] = 0.488603 * x; // band 2
  24049. shBasis[4] = 1.092548 * x * y;
  24050. shBasis[5] = 1.092548 * y * z;
  24051. shBasis[6] = 0.315392 * (3 * z * z - 1);
  24052. shBasis[7] = 1.092548 * x * z;
  24053. shBasis[8] = 0.546274 * (x * x - y * y);
  24054. };
  24055. return SphericalHarmonics3;
  24056. }();
  24057. SphericalHarmonics3.prototype.isSphericalHarmonics3 = true;
  24058. var LightProbe = /*#__PURE__*/function (_Light) {
  24059. _inheritsLoose(LightProbe, _Light);
  24060. function LightProbe(sh, intensity) {
  24061. var _this;
  24062. if (sh === void 0) {
  24063. sh = new SphericalHarmonics3();
  24064. }
  24065. if (intensity === void 0) {
  24066. intensity = 1;
  24067. }
  24068. _this = _Light.call(this, undefined, intensity) || this;
  24069. _this.sh = sh;
  24070. return _this;
  24071. }
  24072. var _proto = LightProbe.prototype;
  24073. _proto.copy = function copy(source) {
  24074. _Light.prototype.copy.call(this, source);
  24075. this.sh.copy(source.sh);
  24076. return this;
  24077. };
  24078. _proto.fromJSON = function fromJSON(json) {
  24079. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  24080. this.sh.fromArray(json.sh);
  24081. return this;
  24082. };
  24083. _proto.toJSON = function toJSON(meta) {
  24084. var data = _Light.prototype.toJSON.call(this, meta);
  24085. data.object.sh = this.sh.toArray();
  24086. return data;
  24087. };
  24088. return LightProbe;
  24089. }(Light);
  24090. LightProbe.prototype.isLightProbe = true;
  24091. var MaterialLoader = /*#__PURE__*/function (_Loader) {
  24092. _inheritsLoose(MaterialLoader, _Loader);
  24093. function MaterialLoader(manager) {
  24094. var _this;
  24095. _this = _Loader.call(this, manager) || this;
  24096. _this.textures = {};
  24097. return _this;
  24098. }
  24099. var _proto = MaterialLoader.prototype;
  24100. _proto.load = function load(url, onLoad, onProgress, onError) {
  24101. var scope = this;
  24102. var loader = new FileLoader(scope.manager);
  24103. loader.setPath(scope.path);
  24104. loader.setRequestHeader(scope.requestHeader);
  24105. loader.setWithCredentials(scope.withCredentials);
  24106. loader.load(url, function (text) {
  24107. try {
  24108. onLoad(scope.parse(JSON.parse(text)));
  24109. } catch (e) {
  24110. if (onError) {
  24111. onError(e);
  24112. } else {
  24113. console.error(e);
  24114. }
  24115. scope.manager.itemError(url);
  24116. }
  24117. }, onProgress, onError);
  24118. };
  24119. _proto.parse = function parse(json) {
  24120. var textures = this.textures;
  24121. function getTexture(name) {
  24122. if (textures[name] === undefined) {
  24123. console.warn('THREE.MaterialLoader: Undefined texture', name);
  24124. }
  24125. return textures[name];
  24126. }
  24127. var material = new Materials[json.type]();
  24128. if (json.uuid !== undefined) material.uuid = json.uuid;
  24129. if (json.name !== undefined) material.name = json.name;
  24130. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  24131. if (json.roughness !== undefined) material.roughness = json.roughness;
  24132. if (json.metalness !== undefined) material.metalness = json.metalness;
  24133. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  24134. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  24135. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  24136. if (json.shininess !== undefined) material.shininess = json.shininess;
  24137. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  24138. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  24139. if (json.fog !== undefined) material.fog = json.fog;
  24140. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  24141. if (json.blending !== undefined) material.blending = json.blending;
  24142. if (json.combine !== undefined) material.combine = json.combine;
  24143. if (json.side !== undefined) material.side = json.side;
  24144. if (json.opacity !== undefined) material.opacity = json.opacity;
  24145. if (json.transparent !== undefined) material.transparent = json.transparent;
  24146. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  24147. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  24148. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  24149. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  24150. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  24151. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  24152. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  24153. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  24154. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  24155. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  24156. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  24157. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  24158. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  24159. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  24160. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  24161. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  24162. if (json.rotation !== undefined) material.rotation = json.rotation;
  24163. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  24164. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  24165. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  24166. if (json.scale !== undefined) material.scale = json.scale;
  24167. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  24168. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24169. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24170. if (json.skinning !== undefined) material.skinning = json.skinning;
  24171. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  24172. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  24173. if (json.dithering !== undefined) material.dithering = json.dithering;
  24174. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  24175. if (json.visible !== undefined) material.visible = json.visible;
  24176. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  24177. if (json.userData !== undefined) material.userData = json.userData;
  24178. if (json.vertexColors !== undefined) {
  24179. if (typeof json.vertexColors === 'number') {
  24180. material.vertexColors = json.vertexColors > 0 ? true : false;
  24181. } else {
  24182. material.vertexColors = json.vertexColors;
  24183. }
  24184. } // Shader Material
  24185. if (json.uniforms !== undefined) {
  24186. for (var name in json.uniforms) {
  24187. var uniform = json.uniforms[name];
  24188. material.uniforms[name] = {};
  24189. switch (uniform.type) {
  24190. case 't':
  24191. material.uniforms[name].value = getTexture(uniform.value);
  24192. break;
  24193. case 'c':
  24194. material.uniforms[name].value = new Color().setHex(uniform.value);
  24195. break;
  24196. case 'v2':
  24197. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  24198. break;
  24199. case 'v3':
  24200. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  24201. break;
  24202. case 'v4':
  24203. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  24204. break;
  24205. case 'm3':
  24206. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  24207. break;
  24208. case 'm4':
  24209. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  24210. break;
  24211. default:
  24212. material.uniforms[name].value = uniform.value;
  24213. }
  24214. }
  24215. }
  24216. if (json.defines !== undefined) material.defines = json.defines;
  24217. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  24218. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  24219. if (json.extensions !== undefined) {
  24220. for (var key in json.extensions) {
  24221. material.extensions[key] = json.extensions[key];
  24222. }
  24223. } // Deprecated
  24224. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  24225. // for PointsMaterial
  24226. if (json.size !== undefined) material.size = json.size;
  24227. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  24228. if (json.map !== undefined) material.map = getTexture(json.map);
  24229. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  24230. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  24231. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  24232. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  24233. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  24234. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  24235. if (json.normalScale !== undefined) {
  24236. var normalScale = json.normalScale;
  24237. if (Array.isArray(normalScale) === false) {
  24238. // Blender exporter used to export a scalar. See #7459
  24239. normalScale = [normalScale, normalScale];
  24240. }
  24241. material.normalScale = new Vector2().fromArray(normalScale);
  24242. }
  24243. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  24244. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  24245. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  24246. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  24247. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  24248. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  24249. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  24250. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  24251. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  24252. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  24253. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  24254. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  24255. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  24256. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  24257. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  24258. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  24259. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  24260. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  24261. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  24262. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  24263. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24264. if (json.transmission !== undefined) material.transmission = json.transmission;
  24265. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24266. return material;
  24267. };
  24268. _proto.setTextures = function setTextures(value) {
  24269. this.textures = value;
  24270. return this;
  24271. };
  24272. return MaterialLoader;
  24273. }(Loader);
  24274. var LoaderUtils = {
  24275. decodeText: function decodeText(array) {
  24276. if (typeof TextDecoder !== 'undefined') {
  24277. return new TextDecoder().decode(array);
  24278. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24279. // throws a "maximum call stack size exceeded" error for large arrays.
  24280. var s = '';
  24281. for (var i = 0, il = array.length; i < il; i++) {
  24282. // Implicitly assumes little-endian.
  24283. s += String.fromCharCode(array[i]);
  24284. }
  24285. try {
  24286. // merges multi-byte utf-8 characters.
  24287. return decodeURIComponent(escape(s));
  24288. } catch (e) {
  24289. // see #16358
  24290. return s;
  24291. }
  24292. },
  24293. extractUrlBase: function extractUrlBase(url) {
  24294. var index = url.lastIndexOf('/');
  24295. if (index === -1) return './';
  24296. return url.substr(0, index + 1);
  24297. }
  24298. };
  24299. function InstancedBufferGeometry() {
  24300. BufferGeometry.call(this);
  24301. this.type = 'InstancedBufferGeometry';
  24302. this.instanceCount = Infinity;
  24303. }
  24304. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24305. constructor: InstancedBufferGeometry,
  24306. isInstancedBufferGeometry: true,
  24307. copy: function copy(source) {
  24308. BufferGeometry.prototype.copy.call(this, source);
  24309. this.instanceCount = source.instanceCount;
  24310. return this;
  24311. },
  24312. clone: function clone() {
  24313. return new this.constructor().copy(this);
  24314. },
  24315. toJSON: function toJSON() {
  24316. var data = BufferGeometry.prototype.toJSON.call(this);
  24317. data.instanceCount = this.instanceCount;
  24318. data.isInstancedBufferGeometry = true;
  24319. return data;
  24320. }
  24321. });
  24322. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24323. if (typeof normalized === 'number') {
  24324. meshPerAttribute = normalized;
  24325. normalized = false;
  24326. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24327. }
  24328. BufferAttribute.call(this, array, itemSize, normalized);
  24329. this.meshPerAttribute = meshPerAttribute || 1;
  24330. }
  24331. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24332. constructor: InstancedBufferAttribute,
  24333. isInstancedBufferAttribute: true,
  24334. copy: function copy(source) {
  24335. BufferAttribute.prototype.copy.call(this, source);
  24336. this.meshPerAttribute = source.meshPerAttribute;
  24337. return this;
  24338. },
  24339. toJSON: function toJSON() {
  24340. var data = BufferAttribute.prototype.toJSON.call(this);
  24341. data.meshPerAttribute = this.meshPerAttribute;
  24342. data.isInstancedBufferAttribute = true;
  24343. return data;
  24344. }
  24345. });
  24346. var BufferGeometryLoader = /*#__PURE__*/function (_Loader) {
  24347. _inheritsLoose(BufferGeometryLoader, _Loader);
  24348. function BufferGeometryLoader(manager) {
  24349. return _Loader.call(this, manager) || this;
  24350. }
  24351. var _proto = BufferGeometryLoader.prototype;
  24352. _proto.load = function load(url, onLoad, onProgress, onError) {
  24353. var scope = this;
  24354. var loader = new FileLoader(scope.manager);
  24355. loader.setPath(scope.path);
  24356. loader.setRequestHeader(scope.requestHeader);
  24357. loader.setWithCredentials(scope.withCredentials);
  24358. loader.load(url, function (text) {
  24359. try {
  24360. onLoad(scope.parse(JSON.parse(text)));
  24361. } catch (e) {
  24362. if (onError) {
  24363. onError(e);
  24364. } else {
  24365. console.error(e);
  24366. }
  24367. scope.manager.itemError(url);
  24368. }
  24369. }, onProgress, onError);
  24370. };
  24371. _proto.parse = function parse(json) {
  24372. var interleavedBufferMap = {};
  24373. var arrayBufferMap = {};
  24374. function getInterleavedBuffer(json, uuid) {
  24375. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24376. var interleavedBuffers = json.interleavedBuffers;
  24377. var interleavedBuffer = interleavedBuffers[uuid];
  24378. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24379. var array = getTypedArray(interleavedBuffer.type, buffer);
  24380. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24381. ib.uuid = interleavedBuffer.uuid;
  24382. interleavedBufferMap[uuid] = ib;
  24383. return ib;
  24384. }
  24385. function getArrayBuffer(json, uuid) {
  24386. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24387. var arrayBuffers = json.arrayBuffers;
  24388. var arrayBuffer = arrayBuffers[uuid];
  24389. var ab = new Uint32Array(arrayBuffer).buffer;
  24390. arrayBufferMap[uuid] = ab;
  24391. return ab;
  24392. }
  24393. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24394. var index = json.data.index;
  24395. if (index !== undefined) {
  24396. var typedArray = getTypedArray(index.type, index.array);
  24397. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24398. }
  24399. var attributes = json.data.attributes;
  24400. for (var key in attributes) {
  24401. var attribute = attributes[key];
  24402. var bufferAttribute = void 0;
  24403. if (attribute.isInterleavedBufferAttribute) {
  24404. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24405. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24406. } else {
  24407. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24408. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24409. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24410. }
  24411. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24412. geometry.setAttribute(key, bufferAttribute);
  24413. }
  24414. var morphAttributes = json.data.morphAttributes;
  24415. if (morphAttributes) {
  24416. for (var _key in morphAttributes) {
  24417. var attributeArray = morphAttributes[_key];
  24418. var array = [];
  24419. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24420. var _attribute = attributeArray[i];
  24421. var _bufferAttribute = void 0;
  24422. if (_attribute.isInterleavedBufferAttribute) {
  24423. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24424. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24425. } else {
  24426. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24427. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24428. }
  24429. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24430. array.push(_bufferAttribute);
  24431. }
  24432. geometry.morphAttributes[_key] = array;
  24433. }
  24434. }
  24435. var morphTargetsRelative = json.data.morphTargetsRelative;
  24436. if (morphTargetsRelative) {
  24437. geometry.morphTargetsRelative = true;
  24438. }
  24439. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24440. if (groups !== undefined) {
  24441. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24442. var group = groups[_i];
  24443. geometry.addGroup(group.start, group.count, group.materialIndex);
  24444. }
  24445. }
  24446. var boundingSphere = json.data.boundingSphere;
  24447. if (boundingSphere !== undefined) {
  24448. var center = new Vector3();
  24449. if (boundingSphere.center !== undefined) {
  24450. center.fromArray(boundingSphere.center);
  24451. }
  24452. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24453. }
  24454. if (json.name) geometry.name = json.name;
  24455. if (json.userData) geometry.userData = json.userData;
  24456. return geometry;
  24457. };
  24458. return BufferGeometryLoader;
  24459. }(Loader);
  24460. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24461. _inheritsLoose(ObjectLoader, _Loader);
  24462. function ObjectLoader(manager) {
  24463. return _Loader.call(this, manager) || this;
  24464. }
  24465. var _proto = ObjectLoader.prototype;
  24466. _proto.load = function load(url, onLoad, onProgress, onError) {
  24467. var scope = this;
  24468. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24469. this.resourcePath = this.resourcePath || path;
  24470. var loader = new FileLoader(this.manager);
  24471. loader.setPath(this.path);
  24472. loader.setRequestHeader(this.requestHeader);
  24473. loader.setWithCredentials(this.withCredentials);
  24474. loader.load(url, function (text) {
  24475. var json = null;
  24476. try {
  24477. json = JSON.parse(text);
  24478. } catch (error) {
  24479. if (onError !== undefined) onError(error);
  24480. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24481. return;
  24482. }
  24483. var metadata = json.metadata;
  24484. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24485. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24486. return;
  24487. }
  24488. scope.parse(json, onLoad);
  24489. }, onProgress, onError);
  24490. };
  24491. _proto.parse = function parse(json, onLoad) {
  24492. var animations = this.parseAnimations(json.animations);
  24493. var shapes = this.parseShapes(json.shapes);
  24494. var geometries = this.parseGeometries(json.geometries, shapes);
  24495. var images = this.parseImages(json.images, function () {
  24496. if (onLoad !== undefined) onLoad(object);
  24497. });
  24498. var textures = this.parseTextures(json.textures, images);
  24499. var materials = this.parseMaterials(json.materials, textures);
  24500. var object = this.parseObject(json.object, geometries, materials, animations);
  24501. var skeletons = this.parseSkeletons(json.skeletons, object);
  24502. this.bindSkeletons(object, skeletons); //
  24503. if (onLoad !== undefined) {
  24504. var hasImages = false;
  24505. for (var uuid in images) {
  24506. if (images[uuid] instanceof HTMLImageElement) {
  24507. hasImages = true;
  24508. break;
  24509. }
  24510. }
  24511. if (hasImages === false) onLoad(object);
  24512. }
  24513. return object;
  24514. };
  24515. _proto.parseShapes = function parseShapes(json) {
  24516. var shapes = {};
  24517. if (json !== undefined) {
  24518. for (var i = 0, l = json.length; i < l; i++) {
  24519. var shape = new Shape().fromJSON(json[i]);
  24520. shapes[shape.uuid] = shape;
  24521. }
  24522. }
  24523. return shapes;
  24524. };
  24525. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24526. var skeletons = {};
  24527. var bones = {}; // generate bone lookup table
  24528. object.traverse(function (child) {
  24529. if (child.isBone) bones[child.uuid] = child;
  24530. }); // create skeletons
  24531. if (json !== undefined) {
  24532. for (var i = 0, l = json.length; i < l; i++) {
  24533. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24534. skeletons[skeleton.uuid] = skeleton;
  24535. }
  24536. }
  24537. return skeletons;
  24538. };
  24539. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24540. var geometries = {};
  24541. var geometryShapes;
  24542. if (json !== undefined) {
  24543. var bufferGeometryLoader = new BufferGeometryLoader();
  24544. for (var i = 0, l = json.length; i < l; i++) {
  24545. var geometry = void 0;
  24546. var data = json[i];
  24547. switch (data.type) {
  24548. case 'PlaneGeometry':
  24549. case 'PlaneBufferGeometry':
  24550. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24551. break;
  24552. case 'BoxGeometry':
  24553. case 'BoxBufferGeometry':
  24554. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24555. break;
  24556. case 'CircleGeometry':
  24557. case 'CircleBufferGeometry':
  24558. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24559. break;
  24560. case 'CylinderGeometry':
  24561. case 'CylinderBufferGeometry':
  24562. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24563. break;
  24564. case 'ConeGeometry':
  24565. case 'ConeBufferGeometry':
  24566. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24567. break;
  24568. case 'SphereGeometry':
  24569. case 'SphereBufferGeometry':
  24570. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24571. break;
  24572. case 'DodecahedronGeometry':
  24573. case 'DodecahedronBufferGeometry':
  24574. case 'IcosahedronGeometry':
  24575. case 'IcosahedronBufferGeometry':
  24576. case 'OctahedronGeometry':
  24577. case 'OctahedronBufferGeometry':
  24578. case 'TetrahedronGeometry':
  24579. case 'TetrahedronBufferGeometry':
  24580. geometry = new Geometries[data.type](data.radius, data.detail);
  24581. break;
  24582. case 'RingGeometry':
  24583. case 'RingBufferGeometry':
  24584. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24585. break;
  24586. case 'TorusGeometry':
  24587. case 'TorusBufferGeometry':
  24588. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24589. break;
  24590. case 'TorusKnotGeometry':
  24591. case 'TorusKnotBufferGeometry':
  24592. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24593. break;
  24594. case 'TubeGeometry':
  24595. case 'TubeBufferGeometry':
  24596. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24597. // User defined curves or instances of CurvePath will not be deserialized.
  24598. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24599. break;
  24600. case 'LatheGeometry':
  24601. case 'LatheBufferGeometry':
  24602. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24603. break;
  24604. case 'PolyhedronGeometry':
  24605. case 'PolyhedronBufferGeometry':
  24606. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24607. break;
  24608. case 'ShapeGeometry':
  24609. case 'ShapeBufferGeometry':
  24610. geometryShapes = [];
  24611. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24612. var shape = shapes[data.shapes[j]];
  24613. geometryShapes.push(shape);
  24614. }
  24615. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24616. break;
  24617. case 'ExtrudeGeometry':
  24618. case 'ExtrudeBufferGeometry':
  24619. geometryShapes = [];
  24620. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24621. var _shape = shapes[data.shapes[_j]];
  24622. geometryShapes.push(_shape);
  24623. }
  24624. var extrudePath = data.options.extrudePath;
  24625. if (extrudePath !== undefined) {
  24626. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24627. }
  24628. geometry = new Geometries[data.type](geometryShapes, data.options);
  24629. break;
  24630. case 'BufferGeometry':
  24631. case 'InstancedBufferGeometry':
  24632. geometry = bufferGeometryLoader.parse(data);
  24633. break;
  24634. case 'Geometry':
  24635. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24636. break;
  24637. default:
  24638. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24639. continue;
  24640. }
  24641. geometry.uuid = data.uuid;
  24642. if (data.name !== undefined) geometry.name = data.name;
  24643. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24644. geometries[data.uuid] = geometry;
  24645. }
  24646. }
  24647. return geometries;
  24648. };
  24649. _proto.parseMaterials = function parseMaterials(json, textures) {
  24650. var cache = {}; // MultiMaterial
  24651. var materials = {};
  24652. if (json !== undefined) {
  24653. var loader = new MaterialLoader();
  24654. loader.setTextures(textures);
  24655. for (var i = 0, l = json.length; i < l; i++) {
  24656. var data = json[i];
  24657. if (data.type === 'MultiMaterial') {
  24658. // Deprecated
  24659. var array = [];
  24660. for (var j = 0; j < data.materials.length; j++) {
  24661. var material = data.materials[j];
  24662. if (cache[material.uuid] === undefined) {
  24663. cache[material.uuid] = loader.parse(material);
  24664. }
  24665. array.push(cache[material.uuid]);
  24666. }
  24667. materials[data.uuid] = array;
  24668. } else {
  24669. if (cache[data.uuid] === undefined) {
  24670. cache[data.uuid] = loader.parse(data);
  24671. }
  24672. materials[data.uuid] = cache[data.uuid];
  24673. }
  24674. }
  24675. }
  24676. return materials;
  24677. };
  24678. _proto.parseAnimations = function parseAnimations(json) {
  24679. var animations = {};
  24680. if (json !== undefined) {
  24681. for (var i = 0; i < json.length; i++) {
  24682. var data = json[i];
  24683. var clip = AnimationClip.parse(data);
  24684. animations[clip.uuid] = clip;
  24685. }
  24686. }
  24687. return animations;
  24688. };
  24689. _proto.parseImages = function parseImages(json, onLoad) {
  24690. var scope = this;
  24691. var images = {};
  24692. var loader;
  24693. function loadImage(url) {
  24694. scope.manager.itemStart(url);
  24695. return loader.load(url, function () {
  24696. scope.manager.itemEnd(url);
  24697. }, undefined, function () {
  24698. scope.manager.itemError(url);
  24699. scope.manager.itemEnd(url);
  24700. });
  24701. }
  24702. function deserializeImage(image) {
  24703. if (typeof image === 'string') {
  24704. var url = image;
  24705. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24706. return loadImage(path);
  24707. } else {
  24708. if (image.data) {
  24709. return {
  24710. data: getTypedArray(image.type, image.data),
  24711. width: image.width,
  24712. height: image.height
  24713. };
  24714. } else {
  24715. return null;
  24716. }
  24717. }
  24718. }
  24719. if (json !== undefined && json.length > 0) {
  24720. var manager = new LoadingManager(onLoad);
  24721. loader = new ImageLoader(manager);
  24722. loader.setCrossOrigin(this.crossOrigin);
  24723. for (var i = 0, il = json.length; i < il; i++) {
  24724. var image = json[i];
  24725. var url = image.url;
  24726. if (Array.isArray(url)) {
  24727. // load array of images e.g CubeTexture
  24728. images[image.uuid] = [];
  24729. for (var j = 0, jl = url.length; j < jl; j++) {
  24730. var currentUrl = url[j];
  24731. var deserializedImage = deserializeImage(currentUrl);
  24732. if (deserializedImage !== null) {
  24733. if (deserializedImage instanceof HTMLImageElement) {
  24734. images[image.uuid].push(deserializedImage);
  24735. } else {
  24736. // special case: handle array of data textures for cube textures
  24737. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24738. }
  24739. }
  24740. }
  24741. } else {
  24742. // load single image
  24743. var _deserializedImage = deserializeImage(image.url);
  24744. if (_deserializedImage !== null) {
  24745. images[image.uuid] = _deserializedImage;
  24746. }
  24747. }
  24748. }
  24749. }
  24750. return images;
  24751. };
  24752. _proto.parseTextures = function parseTextures(json, images) {
  24753. function parseConstant(value, type) {
  24754. if (typeof value === 'number') return value;
  24755. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24756. return type[value];
  24757. }
  24758. var textures = {};
  24759. if (json !== undefined) {
  24760. for (var i = 0, l = json.length; i < l; i++) {
  24761. var data = json[i];
  24762. if (data.image === undefined) {
  24763. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24764. }
  24765. if (images[data.image] === undefined) {
  24766. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24767. }
  24768. var texture = void 0;
  24769. var image = images[data.image];
  24770. if (Array.isArray(image)) {
  24771. texture = new CubeTexture(image);
  24772. if (image.length === 6) texture.needsUpdate = true;
  24773. } else {
  24774. if (image && image.data) {
  24775. texture = new DataTexture(image.data, image.width, image.height);
  24776. } else {
  24777. texture = new Texture(image);
  24778. }
  24779. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24780. }
  24781. texture.uuid = data.uuid;
  24782. if (data.name !== undefined) texture.name = data.name;
  24783. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24784. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24785. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24786. if (data.center !== undefined) texture.center.fromArray(data.center);
  24787. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24788. if (data.wrap !== undefined) {
  24789. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24790. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24791. }
  24792. if (data.format !== undefined) texture.format = data.format;
  24793. if (data.type !== undefined) texture.type = data.type;
  24794. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24795. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24796. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24797. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24798. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24799. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24800. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24801. textures[data.uuid] = texture;
  24802. }
  24803. }
  24804. return textures;
  24805. };
  24806. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  24807. var object;
  24808. function getGeometry(name) {
  24809. if (geometries[name] === undefined) {
  24810. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24811. }
  24812. return geometries[name];
  24813. }
  24814. function getMaterial(name) {
  24815. if (name === undefined) return undefined;
  24816. if (Array.isArray(name)) {
  24817. var array = [];
  24818. for (var i = 0, l = name.length; i < l; i++) {
  24819. var uuid = name[i];
  24820. if (materials[uuid] === undefined) {
  24821. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24822. }
  24823. array.push(materials[uuid]);
  24824. }
  24825. return array;
  24826. }
  24827. if (materials[name] === undefined) {
  24828. console.warn('THREE.ObjectLoader: Undefined material', name);
  24829. }
  24830. return materials[name];
  24831. }
  24832. var geometry, material;
  24833. switch (data.type) {
  24834. case 'Scene':
  24835. object = new Scene();
  24836. if (data.background !== undefined) {
  24837. if (Number.isInteger(data.background)) {
  24838. object.background = new Color(data.background);
  24839. }
  24840. }
  24841. if (data.fog !== undefined) {
  24842. if (data.fog.type === 'Fog') {
  24843. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24844. } else if (data.fog.type === 'FogExp2') {
  24845. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24846. }
  24847. }
  24848. break;
  24849. case 'PerspectiveCamera':
  24850. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24851. if (data.focus !== undefined) object.focus = data.focus;
  24852. if (data.zoom !== undefined) object.zoom = data.zoom;
  24853. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24854. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24855. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24856. break;
  24857. case 'OrthographicCamera':
  24858. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24859. if (data.zoom !== undefined) object.zoom = data.zoom;
  24860. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24861. break;
  24862. case 'AmbientLight':
  24863. object = new AmbientLight(data.color, data.intensity);
  24864. break;
  24865. case 'DirectionalLight':
  24866. object = new DirectionalLight(data.color, data.intensity);
  24867. break;
  24868. case 'PointLight':
  24869. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24870. break;
  24871. case 'RectAreaLight':
  24872. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24873. break;
  24874. case 'SpotLight':
  24875. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24876. break;
  24877. case 'HemisphereLight':
  24878. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24879. break;
  24880. case 'LightProbe':
  24881. object = new LightProbe().fromJSON(data);
  24882. break;
  24883. case 'SkinnedMesh':
  24884. geometry = getGeometry(data.geometry);
  24885. material = getMaterial(data.material);
  24886. object = new SkinnedMesh(geometry, material);
  24887. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24888. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24889. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24890. break;
  24891. case 'Mesh':
  24892. geometry = getGeometry(data.geometry);
  24893. material = getMaterial(data.material);
  24894. object = new Mesh(geometry, material);
  24895. break;
  24896. case 'InstancedMesh':
  24897. geometry = getGeometry(data.geometry);
  24898. material = getMaterial(data.material);
  24899. var count = data.count;
  24900. var instanceMatrix = data.instanceMatrix;
  24901. object = new InstancedMesh(geometry, material, count);
  24902. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24903. break;
  24904. case 'LOD':
  24905. object = new LOD();
  24906. break;
  24907. case 'Line':
  24908. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  24909. break;
  24910. case 'LineLoop':
  24911. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24912. break;
  24913. case 'LineSegments':
  24914. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24915. break;
  24916. case 'PointCloud':
  24917. case 'Points':
  24918. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24919. break;
  24920. case 'Sprite':
  24921. object = new Sprite(getMaterial(data.material));
  24922. break;
  24923. case 'Group':
  24924. object = new Group();
  24925. break;
  24926. case 'Bone':
  24927. object = new Bone();
  24928. break;
  24929. default:
  24930. object = new Object3D();
  24931. }
  24932. object.uuid = data.uuid;
  24933. if (data.name !== undefined) object.name = data.name;
  24934. if (data.matrix !== undefined) {
  24935. object.matrix.fromArray(data.matrix);
  24936. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24937. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24938. } else {
  24939. if (data.position !== undefined) object.position.fromArray(data.position);
  24940. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24941. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24942. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24943. }
  24944. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24945. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24946. if (data.shadow) {
  24947. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24948. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24949. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24950. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24951. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24952. }
  24953. if (data.visible !== undefined) object.visible = data.visible;
  24954. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24955. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24956. if (data.userData !== undefined) object.userData = data.userData;
  24957. if (data.layers !== undefined) object.layers.mask = data.layers;
  24958. if (data.children !== undefined) {
  24959. var children = data.children;
  24960. for (var i = 0; i < children.length; i++) {
  24961. object.add(this.parseObject(children[i], geometries, materials, animations));
  24962. }
  24963. }
  24964. if (data.animations !== undefined) {
  24965. var objectAnimations = data.animations;
  24966. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24967. var uuid = objectAnimations[_i];
  24968. object.animations.push(animations[uuid]);
  24969. }
  24970. }
  24971. if (data.type === 'LOD') {
  24972. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24973. var levels = data.levels;
  24974. for (var l = 0; l < levels.length; l++) {
  24975. var level = levels[l];
  24976. var child = object.getObjectByProperty('uuid', level.object);
  24977. if (child !== undefined) {
  24978. object.addLevel(child, level.distance);
  24979. }
  24980. }
  24981. }
  24982. return object;
  24983. };
  24984. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24985. if (Object.keys(skeletons).length === 0) return;
  24986. object.traverse(function (child) {
  24987. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24988. var skeleton = skeletons[child.skeleton];
  24989. if (skeleton === undefined) {
  24990. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24991. } else {
  24992. child.bind(skeleton, child.bindMatrix);
  24993. }
  24994. }
  24995. });
  24996. }
  24997. /* DEPRECATED */
  24998. ;
  24999. _proto.setTexturePath = function setTexturePath(value) {
  25000. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  25001. return this.setResourcePath(value);
  25002. };
  25003. return ObjectLoader;
  25004. }(Loader);
  25005. var TEXTURE_MAPPING = {
  25006. UVMapping: UVMapping,
  25007. CubeReflectionMapping: CubeReflectionMapping,
  25008. CubeRefractionMapping: CubeRefractionMapping,
  25009. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  25010. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  25011. CubeUVReflectionMapping: CubeUVReflectionMapping,
  25012. CubeUVRefractionMapping: CubeUVRefractionMapping
  25013. };
  25014. var TEXTURE_WRAPPING = {
  25015. RepeatWrapping: RepeatWrapping,
  25016. ClampToEdgeWrapping: ClampToEdgeWrapping,
  25017. MirroredRepeatWrapping: MirroredRepeatWrapping
  25018. };
  25019. var TEXTURE_FILTER = {
  25020. NearestFilter: NearestFilter,
  25021. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  25022. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  25023. LinearFilter: LinearFilter,
  25024. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  25025. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  25026. };
  25027. function ImageBitmapLoader(manager) {
  25028. if (typeof createImageBitmap === 'undefined') {
  25029. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  25030. }
  25031. if (typeof fetch === 'undefined') {
  25032. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  25033. }
  25034. Loader.call(this, manager);
  25035. this.options = {
  25036. premultiplyAlpha: 'none'
  25037. };
  25038. }
  25039. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  25040. constructor: ImageBitmapLoader,
  25041. isImageBitmapLoader: true,
  25042. setOptions: function setOptions(options) {
  25043. this.options = options;
  25044. return this;
  25045. },
  25046. load: function load(url, onLoad, onProgress, onError) {
  25047. if (url === undefined) url = '';
  25048. if (this.path !== undefined) url = this.path + url;
  25049. url = this.manager.resolveURL(url);
  25050. var scope = this;
  25051. var cached = Cache.get(url);
  25052. if (cached !== undefined) {
  25053. scope.manager.itemStart(url);
  25054. setTimeout(function () {
  25055. if (onLoad) onLoad(cached);
  25056. scope.manager.itemEnd(url);
  25057. }, 0);
  25058. return cached;
  25059. }
  25060. var fetchOptions = {};
  25061. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  25062. fetchOptions.headers = this.requestHeader;
  25063. fetch(url, fetchOptions).then(function (res) {
  25064. return res.blob();
  25065. }).then(function (blob) {
  25066. return createImageBitmap(blob, Object.assign(scope.options, {
  25067. colorSpaceConversion: 'none'
  25068. }));
  25069. }).then(function (imageBitmap) {
  25070. Cache.add(url, imageBitmap);
  25071. if (onLoad) onLoad(imageBitmap);
  25072. scope.manager.itemEnd(url);
  25073. }).catch(function (e) {
  25074. if (onError) onError(e);
  25075. scope.manager.itemError(url);
  25076. scope.manager.itemEnd(url);
  25077. });
  25078. scope.manager.itemStart(url);
  25079. }
  25080. });
  25081. var ShapePath = /*#__PURE__*/function () {
  25082. function ShapePath() {
  25083. this.type = 'ShapePath';
  25084. this.color = new Color();
  25085. this.subPaths = [];
  25086. this.currentPath = null;
  25087. }
  25088. var _proto = ShapePath.prototype;
  25089. _proto.moveTo = function moveTo(x, y) {
  25090. this.currentPath = new Path();
  25091. this.subPaths.push(this.currentPath);
  25092. this.currentPath.moveTo(x, y);
  25093. return this;
  25094. };
  25095. _proto.lineTo = function lineTo(x, y) {
  25096. this.currentPath.lineTo(x, y);
  25097. return this;
  25098. };
  25099. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  25100. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  25101. return this;
  25102. };
  25103. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  25104. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  25105. return this;
  25106. };
  25107. _proto.splineThru = function splineThru(pts) {
  25108. this.currentPath.splineThru(pts);
  25109. return this;
  25110. };
  25111. _proto.toShapes = function toShapes(isCCW, noHoles) {
  25112. function toShapesNoHoles(inSubpaths) {
  25113. var shapes = [];
  25114. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  25115. var _tmpPath = inSubpaths[i];
  25116. var _tmpShape = new Shape();
  25117. _tmpShape.curves = _tmpPath.curves;
  25118. shapes.push(_tmpShape);
  25119. }
  25120. return shapes;
  25121. }
  25122. function isPointInsidePolygon(inPt, inPolygon) {
  25123. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  25124. // toggling of inside/outside at every single! intersection point of an edge
  25125. // with the horizontal line through inPt, left of inPt
  25126. // not counting lowerY endpoints of edges and whole edges on that line
  25127. var inside = false;
  25128. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  25129. var edgeLowPt = inPolygon[p];
  25130. var edgeHighPt = inPolygon[q];
  25131. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  25132. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  25133. if (Math.abs(edgeDy) > Number.EPSILON) {
  25134. // not parallel
  25135. if (edgeDy < 0) {
  25136. edgeLowPt = inPolygon[q];
  25137. edgeDx = -edgeDx;
  25138. edgeHighPt = inPolygon[p];
  25139. edgeDy = -edgeDy;
  25140. }
  25141. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  25142. if (inPt.y === edgeLowPt.y) {
  25143. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  25144. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25145. } else {
  25146. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  25147. if (perpEdge === 0) return true; // inPt is on contour ?
  25148. if (perpEdge < 0) continue;
  25149. inside = !inside; // true intersection left of inPt
  25150. }
  25151. } else {
  25152. // parallel or collinear
  25153. if (inPt.y !== edgeLowPt.y) continue; // parallel
  25154. // edge lies on the same horizontal line as inPt
  25155. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  25156. // continue;
  25157. }
  25158. }
  25159. return inside;
  25160. }
  25161. var isClockWise = ShapeUtils.isClockWise;
  25162. var subPaths = this.subPaths;
  25163. if (subPaths.length === 0) return [];
  25164. if (noHoles === true) return toShapesNoHoles(subPaths);
  25165. var solid, tmpPath, tmpShape;
  25166. var shapes = [];
  25167. if (subPaths.length === 1) {
  25168. tmpPath = subPaths[0];
  25169. tmpShape = new Shape();
  25170. tmpShape.curves = tmpPath.curves;
  25171. shapes.push(tmpShape);
  25172. return shapes;
  25173. }
  25174. var holesFirst = !isClockWise(subPaths[0].getPoints());
  25175. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  25176. var betterShapeHoles = [];
  25177. var newShapes = [];
  25178. var newShapeHoles = [];
  25179. var mainIdx = 0;
  25180. var tmpPoints;
  25181. newShapes[mainIdx] = undefined;
  25182. newShapeHoles[mainIdx] = [];
  25183. for (var i = 0, l = subPaths.length; i < l; i++) {
  25184. tmpPath = subPaths[i];
  25185. tmpPoints = tmpPath.getPoints();
  25186. solid = isClockWise(tmpPoints);
  25187. solid = isCCW ? !solid : solid;
  25188. if (solid) {
  25189. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  25190. newShapes[mainIdx] = {
  25191. s: new Shape(),
  25192. p: tmpPoints
  25193. };
  25194. newShapes[mainIdx].s.curves = tmpPath.curves;
  25195. if (holesFirst) mainIdx++;
  25196. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  25197. } else {
  25198. newShapeHoles[mainIdx].push({
  25199. h: tmpPath,
  25200. p: tmpPoints[0]
  25201. }); //console.log('ccw', i);
  25202. }
  25203. } // only Holes? -> probably all Shapes with wrong orientation
  25204. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  25205. if (newShapes.length > 1) {
  25206. var ambiguous = false;
  25207. var toChange = [];
  25208. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  25209. betterShapeHoles[sIdx] = [];
  25210. }
  25211. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  25212. var sho = newShapeHoles[_sIdx];
  25213. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  25214. var ho = sho[hIdx];
  25215. var hole_unassigned = true;
  25216. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  25217. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  25218. if (_sIdx !== s2Idx) toChange.push({
  25219. froms: _sIdx,
  25220. tos: s2Idx,
  25221. hole: hIdx
  25222. });
  25223. if (hole_unassigned) {
  25224. hole_unassigned = false;
  25225. betterShapeHoles[s2Idx].push(ho);
  25226. } else {
  25227. ambiguous = true;
  25228. }
  25229. }
  25230. }
  25231. if (hole_unassigned) {
  25232. betterShapeHoles[_sIdx].push(ho);
  25233. }
  25234. }
  25235. } // console.log("ambiguous: ", ambiguous);
  25236. if (toChange.length > 0) {
  25237. // console.log("to change: ", toChange);
  25238. if (!ambiguous) newShapeHoles = betterShapeHoles;
  25239. }
  25240. }
  25241. var tmpHoles;
  25242. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  25243. tmpShape = newShapes[_i].s;
  25244. shapes.push(tmpShape);
  25245. tmpHoles = newShapeHoles[_i];
  25246. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  25247. tmpShape.holes.push(tmpHoles[j].h);
  25248. }
  25249. } //console.log("shape", shapes);
  25250. return shapes;
  25251. };
  25252. return ShapePath;
  25253. }();
  25254. var Font = /*#__PURE__*/function () {
  25255. function Font(data) {
  25256. this.type = 'Font';
  25257. this.data = data;
  25258. }
  25259. var _proto = Font.prototype;
  25260. _proto.generateShapes = function generateShapes(text, size) {
  25261. if (size === void 0) {
  25262. size = 100;
  25263. }
  25264. var shapes = [];
  25265. var paths = createPaths(text, size, this.data);
  25266. for (var p = 0, pl = paths.length; p < pl; p++) {
  25267. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25268. }
  25269. return shapes;
  25270. };
  25271. return Font;
  25272. }();
  25273. function createPaths(text, size, data) {
  25274. var chars = Array.from(text);
  25275. var scale = size / data.resolution;
  25276. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25277. var paths = [];
  25278. var offsetX = 0,
  25279. offsetY = 0;
  25280. for (var i = 0; i < chars.length; i++) {
  25281. var char = chars[i];
  25282. if (char === '\n') {
  25283. offsetX = 0;
  25284. offsetY -= line_height;
  25285. } else {
  25286. var ret = createPath(char, scale, offsetX, offsetY, data);
  25287. offsetX += ret.offsetX;
  25288. paths.push(ret.path);
  25289. }
  25290. }
  25291. return paths;
  25292. }
  25293. function createPath(char, scale, offsetX, offsetY, data) {
  25294. var glyph = data.glyphs[char] || data.glyphs['?'];
  25295. if (!glyph) {
  25296. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25297. return;
  25298. }
  25299. var path = new ShapePath();
  25300. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25301. if (glyph.o) {
  25302. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25303. for (var i = 0, l = outline.length; i < l;) {
  25304. var action = outline[i++];
  25305. switch (action) {
  25306. case 'm':
  25307. // moveTo
  25308. x = outline[i++] * scale + offsetX;
  25309. y = outline[i++] * scale + offsetY;
  25310. path.moveTo(x, y);
  25311. break;
  25312. case 'l':
  25313. // lineTo
  25314. x = outline[i++] * scale + offsetX;
  25315. y = outline[i++] * scale + offsetY;
  25316. path.lineTo(x, y);
  25317. break;
  25318. case 'q':
  25319. // quadraticCurveTo
  25320. cpx = outline[i++] * scale + offsetX;
  25321. cpy = outline[i++] * scale + offsetY;
  25322. cpx1 = outline[i++] * scale + offsetX;
  25323. cpy1 = outline[i++] * scale + offsetY;
  25324. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25325. break;
  25326. case 'b':
  25327. // bezierCurveTo
  25328. cpx = outline[i++] * scale + offsetX;
  25329. cpy = outline[i++] * scale + offsetY;
  25330. cpx1 = outline[i++] * scale + offsetX;
  25331. cpy1 = outline[i++] * scale + offsetY;
  25332. cpx2 = outline[i++] * scale + offsetX;
  25333. cpy2 = outline[i++] * scale + offsetY;
  25334. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25335. break;
  25336. }
  25337. }
  25338. }
  25339. return {
  25340. offsetX: glyph.ha * scale,
  25341. path: path
  25342. };
  25343. }
  25344. Font.prototype.isFont = true;
  25345. var FontLoader = /*#__PURE__*/function (_Loader) {
  25346. _inheritsLoose(FontLoader, _Loader);
  25347. function FontLoader(manager) {
  25348. return _Loader.call(this, manager) || this;
  25349. }
  25350. var _proto = FontLoader.prototype;
  25351. _proto.load = function load(url, onLoad, onProgress, onError) {
  25352. var scope = this;
  25353. var loader = new FileLoader(this.manager);
  25354. loader.setPath(this.path);
  25355. loader.setRequestHeader(this.requestHeader);
  25356. loader.setWithCredentials(scope.withCredentials);
  25357. loader.load(url, function (text) {
  25358. var json;
  25359. try {
  25360. json = JSON.parse(text);
  25361. } catch (e) {
  25362. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25363. json = JSON.parse(text.substring(65, text.length - 2));
  25364. }
  25365. var font = scope.parse(json);
  25366. if (onLoad) onLoad(font);
  25367. }, onProgress, onError);
  25368. };
  25369. _proto.parse = function parse(json) {
  25370. return new Font(json);
  25371. };
  25372. return FontLoader;
  25373. }(Loader);
  25374. var _context;
  25375. var AudioContext = {
  25376. getContext: function getContext() {
  25377. if (_context === undefined) {
  25378. _context = new (window.AudioContext || window.webkitAudioContext)();
  25379. }
  25380. return _context;
  25381. },
  25382. setContext: function setContext(value) {
  25383. _context = value;
  25384. }
  25385. };
  25386. var AudioLoader = /*#__PURE__*/function (_Loader) {
  25387. _inheritsLoose(AudioLoader, _Loader);
  25388. function AudioLoader(manager) {
  25389. return _Loader.call(this, manager) || this;
  25390. }
  25391. var _proto = AudioLoader.prototype;
  25392. _proto.load = function load(url, onLoad, onProgress, onError) {
  25393. var scope = this;
  25394. var loader = new FileLoader(this.manager);
  25395. loader.setResponseType('arraybuffer');
  25396. loader.setPath(this.path);
  25397. loader.setRequestHeader(this.requestHeader);
  25398. loader.setWithCredentials(this.withCredentials);
  25399. loader.load(url, function (buffer) {
  25400. try {
  25401. // Create a copy of the buffer. The `decodeAudioData` method
  25402. // detaches the buffer when complete, preventing reuse.
  25403. var bufferCopy = buffer.slice(0);
  25404. var context = AudioContext.getContext();
  25405. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25406. onLoad(audioBuffer);
  25407. });
  25408. } catch (e) {
  25409. if (onError) {
  25410. onError(e);
  25411. } else {
  25412. console.error(e);
  25413. }
  25414. scope.manager.itemError(url);
  25415. }
  25416. }, onProgress, onError);
  25417. };
  25418. return AudioLoader;
  25419. }(Loader);
  25420. var HemisphereLightProbe = /*#__PURE__*/function (_LightProbe) {
  25421. _inheritsLoose(HemisphereLightProbe, _LightProbe);
  25422. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25423. var _this;
  25424. if (intensity === void 0) {
  25425. intensity = 1;
  25426. }
  25427. _this = _LightProbe.call(this, undefined, intensity) || this;
  25428. var color1 = new Color().set(skyColor);
  25429. var color2 = new Color().set(groundColor);
  25430. var sky = new Vector3(color1.r, color1.g, color1.b);
  25431. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25432. var c0 = Math.sqrt(Math.PI);
  25433. var c1 = c0 * Math.sqrt(0.75);
  25434. _this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25435. _this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25436. return _this;
  25437. }
  25438. return HemisphereLightProbe;
  25439. }(LightProbe);
  25440. HemisphereLightProbe.prototype.isHemisphereLightProbe = true;
  25441. var AmbientLightProbe = /*#__PURE__*/function (_LightProbe) {
  25442. _inheritsLoose(AmbientLightProbe, _LightProbe);
  25443. function AmbientLightProbe(color, intensity) {
  25444. var _this;
  25445. if (intensity === void 0) {
  25446. intensity = 1;
  25447. }
  25448. _this = _LightProbe.call(this, undefined, intensity) || this;
  25449. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25450. _this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25451. return _this;
  25452. }
  25453. return AmbientLightProbe;
  25454. }(LightProbe);
  25455. AmbientLightProbe.prototype.isAmbientLightProbe = true;
  25456. var _eyeRight = new Matrix4();
  25457. var _eyeLeft = new Matrix4();
  25458. var StereoCamera = /*#__PURE__*/function () {
  25459. function StereoCamera() {
  25460. this.type = 'StereoCamera';
  25461. this.aspect = 1;
  25462. this.eyeSep = 0.064;
  25463. this.cameraL = new PerspectiveCamera();
  25464. this.cameraL.layers.enable(1);
  25465. this.cameraL.matrixAutoUpdate = false;
  25466. this.cameraR = new PerspectiveCamera();
  25467. this.cameraR.layers.enable(2);
  25468. this.cameraR.matrixAutoUpdate = false;
  25469. this._cache = {
  25470. focus: null,
  25471. fov: null,
  25472. aspect: null,
  25473. near: null,
  25474. far: null,
  25475. zoom: null,
  25476. eyeSep: null
  25477. };
  25478. }
  25479. var _proto = StereoCamera.prototype;
  25480. _proto.update = function update(camera) {
  25481. var cache = this._cache;
  25482. var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov || cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near || cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  25483. if (needsUpdate) {
  25484. cache.focus = camera.focus;
  25485. cache.fov = camera.fov;
  25486. cache.aspect = camera.aspect * this.aspect;
  25487. cache.near = camera.near;
  25488. cache.far = camera.far;
  25489. cache.zoom = camera.zoom;
  25490. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25491. // http://paulbourke.net/stereographics/stereorender/
  25492. var projectionMatrix = camera.projectionMatrix.clone();
  25493. var eyeSepHalf = cache.eyeSep / 2;
  25494. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25495. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25496. var xmin, xmax; // translate xOffset
  25497. _eyeLeft.elements[12] = -eyeSepHalf;
  25498. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25499. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25500. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25501. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25502. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25503. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25504. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25505. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25506. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25507. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25508. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25509. }
  25510. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25511. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25512. };
  25513. return StereoCamera;
  25514. }();
  25515. var Clock = /*#__PURE__*/function () {
  25516. function Clock(autoStart) {
  25517. this.autoStart = autoStart !== undefined ? autoStart : true;
  25518. this.startTime = 0;
  25519. this.oldTime = 0;
  25520. this.elapsedTime = 0;
  25521. this.running = false;
  25522. }
  25523. var _proto = Clock.prototype;
  25524. _proto.start = function start() {
  25525. this.startTime = now();
  25526. this.oldTime = this.startTime;
  25527. this.elapsedTime = 0;
  25528. this.running = true;
  25529. };
  25530. _proto.stop = function stop() {
  25531. this.getElapsedTime();
  25532. this.running = false;
  25533. this.autoStart = false;
  25534. };
  25535. _proto.getElapsedTime = function getElapsedTime() {
  25536. this.getDelta();
  25537. return this.elapsedTime;
  25538. };
  25539. _proto.getDelta = function getDelta() {
  25540. var diff = 0;
  25541. if (this.autoStart && !this.running) {
  25542. this.start();
  25543. return 0;
  25544. }
  25545. if (this.running) {
  25546. var newTime = now();
  25547. diff = (newTime - this.oldTime) / 1000;
  25548. this.oldTime = newTime;
  25549. this.elapsedTime += diff;
  25550. }
  25551. return diff;
  25552. };
  25553. return Clock;
  25554. }();
  25555. function now() {
  25556. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25557. }
  25558. var _position$2 = /*@__PURE__*/new Vector3();
  25559. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25560. var _scale$1 = /*@__PURE__*/new Vector3();
  25561. var _orientation = /*@__PURE__*/new Vector3();
  25562. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25563. _inheritsLoose(AudioListener, _Object3D);
  25564. function AudioListener() {
  25565. var _this;
  25566. _this = _Object3D.call(this) || this;
  25567. _this.type = 'AudioListener';
  25568. _this.context = AudioContext.getContext();
  25569. _this.gain = _this.context.createGain();
  25570. _this.gain.connect(_this.context.destination);
  25571. _this.filter = null;
  25572. _this.timeDelta = 0; // private
  25573. _this._clock = new Clock();
  25574. return _this;
  25575. }
  25576. var _proto = AudioListener.prototype;
  25577. _proto.getInput = function getInput() {
  25578. return this.gain;
  25579. };
  25580. _proto.removeFilter = function removeFilter() {
  25581. if (this.filter !== null) {
  25582. this.gain.disconnect(this.filter);
  25583. this.filter.disconnect(this.context.destination);
  25584. this.gain.connect(this.context.destination);
  25585. this.filter = null;
  25586. }
  25587. return this;
  25588. };
  25589. _proto.getFilter = function getFilter() {
  25590. return this.filter;
  25591. };
  25592. _proto.setFilter = function setFilter(value) {
  25593. if (this.filter !== null) {
  25594. this.gain.disconnect(this.filter);
  25595. this.filter.disconnect(this.context.destination);
  25596. } else {
  25597. this.gain.disconnect(this.context.destination);
  25598. }
  25599. this.filter = value;
  25600. this.gain.connect(this.filter);
  25601. this.filter.connect(this.context.destination);
  25602. return this;
  25603. };
  25604. _proto.getMasterVolume = function getMasterVolume() {
  25605. return this.gain.gain.value;
  25606. };
  25607. _proto.setMasterVolume = function setMasterVolume(value) {
  25608. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25609. return this;
  25610. };
  25611. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25612. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25613. var listener = this.context.listener;
  25614. var up = this.up;
  25615. this.timeDelta = this._clock.getDelta();
  25616. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25617. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25618. if (listener.positionX) {
  25619. // code path for Chrome (see #14393)
  25620. var endTime = this.context.currentTime + this.timeDelta;
  25621. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25622. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25623. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25624. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25625. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25626. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25627. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25628. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25629. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25630. } else {
  25631. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25632. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25633. }
  25634. };
  25635. return AudioListener;
  25636. }(Object3D);
  25637. var Audio = /*#__PURE__*/function (_Object3D) {
  25638. _inheritsLoose(Audio, _Object3D);
  25639. function Audio(listener) {
  25640. var _this;
  25641. _this = _Object3D.call(this) || this;
  25642. _this.type = 'Audio';
  25643. _this.listener = listener;
  25644. _this.context = listener.context;
  25645. _this.gain = _this.context.createGain();
  25646. _this.gain.connect(listener.getInput());
  25647. _this.autoplay = false;
  25648. _this.buffer = null;
  25649. _this.detune = 0;
  25650. _this.loop = false;
  25651. _this.loopStart = 0;
  25652. _this.loopEnd = 0;
  25653. _this.offset = 0;
  25654. _this.duration = undefined;
  25655. _this.playbackRate = 1;
  25656. _this.isPlaying = false;
  25657. _this.hasPlaybackControl = true;
  25658. _this.source = null;
  25659. _this.sourceType = 'empty';
  25660. _this._startedAt = 0;
  25661. _this._progress = 0;
  25662. _this._connected = false;
  25663. _this.filters = [];
  25664. return _this;
  25665. }
  25666. var _proto = Audio.prototype;
  25667. _proto.getOutput = function getOutput() {
  25668. return this.gain;
  25669. };
  25670. _proto.setNodeSource = function setNodeSource(audioNode) {
  25671. this.hasPlaybackControl = false;
  25672. this.sourceType = 'audioNode';
  25673. this.source = audioNode;
  25674. this.connect();
  25675. return this;
  25676. };
  25677. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25678. this.hasPlaybackControl = false;
  25679. this.sourceType = 'mediaNode';
  25680. this.source = this.context.createMediaElementSource(mediaElement);
  25681. this.connect();
  25682. return this;
  25683. };
  25684. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25685. this.hasPlaybackControl = false;
  25686. this.sourceType = 'mediaStreamNode';
  25687. this.source = this.context.createMediaStreamSource(mediaStream);
  25688. this.connect();
  25689. return this;
  25690. };
  25691. _proto.setBuffer = function setBuffer(audioBuffer) {
  25692. this.buffer = audioBuffer;
  25693. this.sourceType = 'buffer';
  25694. if (this.autoplay) this.play();
  25695. return this;
  25696. };
  25697. _proto.play = function play(delay) {
  25698. if (delay === void 0) {
  25699. delay = 0;
  25700. }
  25701. if (this.isPlaying === true) {
  25702. console.warn('THREE.Audio: Audio is already playing.');
  25703. return;
  25704. }
  25705. if (this.hasPlaybackControl === false) {
  25706. console.warn('THREE.Audio: this Audio has no playback control.');
  25707. return;
  25708. }
  25709. this._startedAt = this.context.currentTime + delay;
  25710. var source = this.context.createBufferSource();
  25711. source.buffer = this.buffer;
  25712. source.loop = this.loop;
  25713. source.loopStart = this.loopStart;
  25714. source.loopEnd = this.loopEnd;
  25715. source.onended = this.onEnded.bind(this);
  25716. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25717. this.isPlaying = true;
  25718. this.source = source;
  25719. this.setDetune(this.detune);
  25720. this.setPlaybackRate(this.playbackRate);
  25721. return this.connect();
  25722. };
  25723. _proto.pause = function pause() {
  25724. if (this.hasPlaybackControl === false) {
  25725. console.warn('THREE.Audio: this Audio has no playback control.');
  25726. return;
  25727. }
  25728. if (this.isPlaying === true) {
  25729. // update current progress
  25730. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25731. if (this.loop === true) {
  25732. // ensure _progress does not exceed duration with looped audios
  25733. this._progress = this._progress % (this.duration || this.buffer.duration);
  25734. }
  25735. this.source.stop();
  25736. this.source.onended = null;
  25737. this.isPlaying = false;
  25738. }
  25739. return this;
  25740. };
  25741. _proto.stop = function stop() {
  25742. if (this.hasPlaybackControl === false) {
  25743. console.warn('THREE.Audio: this Audio has no playback control.');
  25744. return;
  25745. }
  25746. this._progress = 0;
  25747. this.source.stop();
  25748. this.source.onended = null;
  25749. this.isPlaying = false;
  25750. return this;
  25751. };
  25752. _proto.connect = function connect() {
  25753. if (this.filters.length > 0) {
  25754. this.source.connect(this.filters[0]);
  25755. for (var i = 1, l = this.filters.length; i < l; i++) {
  25756. this.filters[i - 1].connect(this.filters[i]);
  25757. }
  25758. this.filters[this.filters.length - 1].connect(this.getOutput());
  25759. } else {
  25760. this.source.connect(this.getOutput());
  25761. }
  25762. this._connected = true;
  25763. return this;
  25764. };
  25765. _proto.disconnect = function disconnect() {
  25766. if (this.filters.length > 0) {
  25767. this.source.disconnect(this.filters[0]);
  25768. for (var i = 1, l = this.filters.length; i < l; i++) {
  25769. this.filters[i - 1].disconnect(this.filters[i]);
  25770. }
  25771. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25772. } else {
  25773. this.source.disconnect(this.getOutput());
  25774. }
  25775. this._connected = false;
  25776. return this;
  25777. };
  25778. _proto.getFilters = function getFilters() {
  25779. return this.filters;
  25780. };
  25781. _proto.setFilters = function setFilters(value) {
  25782. if (!value) value = [];
  25783. if (this._connected === true) {
  25784. this.disconnect();
  25785. this.filters = value.slice();
  25786. this.connect();
  25787. } else {
  25788. this.filters = value.slice();
  25789. }
  25790. return this;
  25791. };
  25792. _proto.setDetune = function setDetune(value) {
  25793. this.detune = value;
  25794. if (this.source.detune === undefined) return; // only set detune when available
  25795. if (this.isPlaying === true) {
  25796. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25797. }
  25798. return this;
  25799. };
  25800. _proto.getDetune = function getDetune() {
  25801. return this.detune;
  25802. };
  25803. _proto.getFilter = function getFilter() {
  25804. return this.getFilters()[0];
  25805. };
  25806. _proto.setFilter = function setFilter(filter) {
  25807. return this.setFilters(filter ? [filter] : []);
  25808. };
  25809. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25810. if (this.hasPlaybackControl === false) {
  25811. console.warn('THREE.Audio: this Audio has no playback control.');
  25812. return;
  25813. }
  25814. this.playbackRate = value;
  25815. if (this.isPlaying === true) {
  25816. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25817. }
  25818. return this;
  25819. };
  25820. _proto.getPlaybackRate = function getPlaybackRate() {
  25821. return this.playbackRate;
  25822. };
  25823. _proto.onEnded = function onEnded() {
  25824. this.isPlaying = false;
  25825. };
  25826. _proto.getLoop = function getLoop() {
  25827. if (this.hasPlaybackControl === false) {
  25828. console.warn('THREE.Audio: this Audio has no playback control.');
  25829. return false;
  25830. }
  25831. return this.loop;
  25832. };
  25833. _proto.setLoop = function setLoop(value) {
  25834. if (this.hasPlaybackControl === false) {
  25835. console.warn('THREE.Audio: this Audio has no playback control.');
  25836. return;
  25837. }
  25838. this.loop = value;
  25839. if (this.isPlaying === true) {
  25840. this.source.loop = this.loop;
  25841. }
  25842. return this;
  25843. };
  25844. _proto.setLoopStart = function setLoopStart(value) {
  25845. this.loopStart = value;
  25846. return this;
  25847. };
  25848. _proto.setLoopEnd = function setLoopEnd(value) {
  25849. this.loopEnd = value;
  25850. return this;
  25851. };
  25852. _proto.getVolume = function getVolume() {
  25853. return this.gain.gain.value;
  25854. };
  25855. _proto.setVolume = function setVolume(value) {
  25856. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25857. return this;
  25858. };
  25859. return Audio;
  25860. }(Object3D);
  25861. var _position$3 = /*@__PURE__*/new Vector3();
  25862. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25863. var _scale$2 = /*@__PURE__*/new Vector3();
  25864. var _orientation$1 = /*@__PURE__*/new Vector3();
  25865. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25866. _inheritsLoose(PositionalAudio, _Audio);
  25867. function PositionalAudio(listener) {
  25868. var _this;
  25869. _this = _Audio.call(this, listener) || this;
  25870. _this.panner = _this.context.createPanner();
  25871. _this.panner.panningModel = 'HRTF';
  25872. _this.panner.connect(_this.gain);
  25873. return _this;
  25874. }
  25875. var _proto = PositionalAudio.prototype;
  25876. _proto.getOutput = function getOutput() {
  25877. return this.panner;
  25878. };
  25879. _proto.getRefDistance = function getRefDistance() {
  25880. return this.panner.refDistance;
  25881. };
  25882. _proto.setRefDistance = function setRefDistance(value) {
  25883. this.panner.refDistance = value;
  25884. return this;
  25885. };
  25886. _proto.getRolloffFactor = function getRolloffFactor() {
  25887. return this.panner.rolloffFactor;
  25888. };
  25889. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25890. this.panner.rolloffFactor = value;
  25891. return this;
  25892. };
  25893. _proto.getDistanceModel = function getDistanceModel() {
  25894. return this.panner.distanceModel;
  25895. };
  25896. _proto.setDistanceModel = function setDistanceModel(value) {
  25897. this.panner.distanceModel = value;
  25898. return this;
  25899. };
  25900. _proto.getMaxDistance = function getMaxDistance() {
  25901. return this.panner.maxDistance;
  25902. };
  25903. _proto.setMaxDistance = function setMaxDistance(value) {
  25904. this.panner.maxDistance = value;
  25905. return this;
  25906. };
  25907. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25908. this.panner.coneInnerAngle = coneInnerAngle;
  25909. this.panner.coneOuterAngle = coneOuterAngle;
  25910. this.panner.coneOuterGain = coneOuterGain;
  25911. return this;
  25912. };
  25913. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25914. _Audio.prototype.updateMatrixWorld.call(this, force);
  25915. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25916. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25917. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25918. var panner = this.panner;
  25919. if (panner.positionX) {
  25920. // code path for Chrome and Firefox (see #14393)
  25921. var endTime = this.context.currentTime + this.listener.timeDelta;
  25922. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25923. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25924. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25925. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25926. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25927. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25928. } else {
  25929. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25930. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25931. }
  25932. };
  25933. return PositionalAudio;
  25934. }(Audio);
  25935. var AudioAnalyser = /*#__PURE__*/function () {
  25936. function AudioAnalyser(audio, fftSize) {
  25937. if (fftSize === void 0) {
  25938. fftSize = 2048;
  25939. }
  25940. this.analyser = audio.context.createAnalyser();
  25941. this.analyser.fftSize = fftSize;
  25942. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25943. audio.getOutput().connect(this.analyser);
  25944. }
  25945. var _proto = AudioAnalyser.prototype;
  25946. _proto.getFrequencyData = function getFrequencyData() {
  25947. this.analyser.getByteFrequencyData(this.data);
  25948. return this.data;
  25949. };
  25950. _proto.getAverageFrequency = function getAverageFrequency() {
  25951. var value = 0;
  25952. var data = this.getFrequencyData();
  25953. for (var i = 0; i < data.length; i++) {
  25954. value += data[i];
  25955. }
  25956. return value / data.length;
  25957. };
  25958. return AudioAnalyser;
  25959. }();
  25960. var PropertyMixer = /*#__PURE__*/function () {
  25961. function PropertyMixer(binding, typeName, valueSize) {
  25962. this.binding = binding;
  25963. this.valueSize = valueSize;
  25964. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25965. //
  25966. // interpolators can use .buffer as their .result
  25967. // the data then goes to 'incoming'
  25968. //
  25969. // 'accu0' and 'accu1' are used frame-interleaved for
  25970. // the cumulative result and are compared to detect
  25971. // changes
  25972. //
  25973. // 'orig' stores the original state of the property
  25974. //
  25975. // 'add' is used for additive cumulative results
  25976. //
  25977. // 'work' is optional and is only present for quaternion types. It is used
  25978. // to store intermediate quaternion multiplication results
  25979. switch (typeName) {
  25980. case 'quaternion':
  25981. mixFunction = this._slerp;
  25982. mixFunctionAdditive = this._slerpAdditive;
  25983. setIdentity = this._setAdditiveIdentityQuaternion;
  25984. this.buffer = new Float64Array(valueSize * 6);
  25985. this._workIndex = 5;
  25986. break;
  25987. case 'string':
  25988. case 'bool':
  25989. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25990. // additive is not relevant for non-numeric types
  25991. mixFunctionAdditive = this._select;
  25992. setIdentity = this._setAdditiveIdentityOther;
  25993. this.buffer = new Array(valueSize * 5);
  25994. break;
  25995. default:
  25996. mixFunction = this._lerp;
  25997. mixFunctionAdditive = this._lerpAdditive;
  25998. setIdentity = this._setAdditiveIdentityNumeric;
  25999. this.buffer = new Float64Array(valueSize * 5);
  26000. }
  26001. this._mixBufferRegion = mixFunction;
  26002. this._mixBufferRegionAdditive = mixFunctionAdditive;
  26003. this._setIdentity = setIdentity;
  26004. this._origIndex = 3;
  26005. this._addIndex = 4;
  26006. this.cumulativeWeight = 0;
  26007. this.cumulativeWeightAdditive = 0;
  26008. this.useCount = 0;
  26009. this.referenceCount = 0;
  26010. } // accumulate data in the 'incoming' region into 'accu<i>'
  26011. var _proto = PropertyMixer.prototype;
  26012. _proto.accumulate = function accumulate(accuIndex, weight) {
  26013. // note: happily accumulating nothing when weight = 0, the caller knows
  26014. // the weight and shouldn't have made the call in the first place
  26015. var buffer = this.buffer,
  26016. stride = this.valueSize,
  26017. offset = accuIndex * stride + stride;
  26018. var currentWeight = this.cumulativeWeight;
  26019. if (currentWeight === 0) {
  26020. // accuN := incoming * weight
  26021. for (var i = 0; i !== stride; ++i) {
  26022. buffer[offset + i] = buffer[i];
  26023. }
  26024. currentWeight = weight;
  26025. } else {
  26026. // accuN := accuN + incoming * weight
  26027. currentWeight += weight;
  26028. var mix = weight / currentWeight;
  26029. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  26030. }
  26031. this.cumulativeWeight = currentWeight;
  26032. } // accumulate data in the 'incoming' region into 'add'
  26033. ;
  26034. _proto.accumulateAdditive = function accumulateAdditive(weight) {
  26035. var buffer = this.buffer,
  26036. stride = this.valueSize,
  26037. offset = stride * this._addIndex;
  26038. if (this.cumulativeWeightAdditive === 0) {
  26039. // add = identity
  26040. this._setIdentity();
  26041. } // add := add + incoming * weight
  26042. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  26043. this.cumulativeWeightAdditive += weight;
  26044. } // apply the state of 'accu<i>' to the binding when accus differ
  26045. ;
  26046. _proto.apply = function apply(accuIndex) {
  26047. var stride = this.valueSize,
  26048. buffer = this.buffer,
  26049. offset = accuIndex * stride + stride,
  26050. weight = this.cumulativeWeight,
  26051. weightAdditive = this.cumulativeWeightAdditive,
  26052. binding = this.binding;
  26053. this.cumulativeWeight = 0;
  26054. this.cumulativeWeightAdditive = 0;
  26055. if (weight < 1) {
  26056. // accuN := accuN + original * ( 1 - cumulativeWeight )
  26057. var originalValueOffset = stride * this._origIndex;
  26058. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  26059. }
  26060. if (weightAdditive > 0) {
  26061. // accuN := accuN + additive accuN
  26062. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  26063. }
  26064. for (var i = stride, e = stride + stride; i !== e; ++i) {
  26065. if (buffer[i] !== buffer[i + stride]) {
  26066. // value has changed -> update scene graph
  26067. binding.setValue(buffer, offset);
  26068. break;
  26069. }
  26070. }
  26071. } // remember the state of the bound property and copy it to both accus
  26072. ;
  26073. _proto.saveOriginalState = function saveOriginalState() {
  26074. var binding = this.binding;
  26075. var buffer = this.buffer,
  26076. stride = this.valueSize,
  26077. originalValueOffset = stride * this._origIndex;
  26078. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  26079. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  26080. buffer[i] = buffer[originalValueOffset + i % stride];
  26081. } // Add to identity for additive
  26082. this._setIdentity();
  26083. this.cumulativeWeight = 0;
  26084. this.cumulativeWeightAdditive = 0;
  26085. } // apply the state previously taken via 'saveOriginalState' to the binding
  26086. ;
  26087. _proto.restoreOriginalState = function restoreOriginalState() {
  26088. var originalValueOffset = this.valueSize * 3;
  26089. this.binding.setValue(this.buffer, originalValueOffset);
  26090. };
  26091. _proto._setAdditiveIdentityNumeric = function _setAdditiveIdentityNumeric() {
  26092. var startIndex = this._addIndex * this.valueSize;
  26093. var endIndex = startIndex + this.valueSize;
  26094. for (var i = startIndex; i < endIndex; i++) {
  26095. this.buffer[i] = 0;
  26096. }
  26097. };
  26098. _proto._setAdditiveIdentityQuaternion = function _setAdditiveIdentityQuaternion() {
  26099. this._setAdditiveIdentityNumeric();
  26100. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  26101. };
  26102. _proto._setAdditiveIdentityOther = function _setAdditiveIdentityOther() {
  26103. var startIndex = this._origIndex * this.valueSize;
  26104. var targetIndex = this._addIndex * this.valueSize;
  26105. for (var i = 0; i < this.valueSize; i++) {
  26106. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  26107. }
  26108. } // mix functions
  26109. ;
  26110. _proto._select = function _select(buffer, dstOffset, srcOffset, t, stride) {
  26111. if (t >= 0.5) {
  26112. for (var i = 0; i !== stride; ++i) {
  26113. buffer[dstOffset + i] = buffer[srcOffset + i];
  26114. }
  26115. }
  26116. };
  26117. _proto._slerp = function _slerp(buffer, dstOffset, srcOffset, t) {
  26118. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  26119. };
  26120. _proto._slerpAdditive = function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26121. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  26122. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  26123. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  26124. };
  26125. _proto._lerp = function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  26126. var s = 1 - t;
  26127. for (var i = 0; i !== stride; ++i) {
  26128. var j = dstOffset + i;
  26129. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  26130. }
  26131. };
  26132. _proto._lerpAdditive = function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  26133. for (var i = 0; i !== stride; ++i) {
  26134. var j = dstOffset + i;
  26135. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  26136. }
  26137. };
  26138. return PropertyMixer;
  26139. }();
  26140. // Characters [].:/ are reserved for track binding syntax.
  26141. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26142. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26143. // only latin characters, and the unicode \p{L} is not yet supported. So
  26144. // instead, we exclude reserved characters and match everything else.
  26145. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26146. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26147. // be matched to parse the rest of the track name.
  26148. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26149. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  26150. // characters. Accessor may contain any character except closing bracket.
  26151. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  26152. // contain any non-bracket characters.
  26153. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  26154. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  26155. var _supportedObjectNames = ['material', 'materials', 'bones'];
  26156. function Composite(targetGroup, path, optionalParsedPath) {
  26157. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  26158. this._targetGroup = targetGroup;
  26159. this._bindings = targetGroup.subscribe_(path, parsedPath);
  26160. }
  26161. Object.assign(Composite.prototype, {
  26162. getValue: function getValue(array, offset) {
  26163. this.bind(); // bind all binding
  26164. var firstValidIndex = this._targetGroup.nCachedObjects_,
  26165. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  26166. if (binding !== undefined) binding.getValue(array, offset);
  26167. },
  26168. setValue: function setValue(array, offset) {
  26169. var bindings = this._bindings;
  26170. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26171. bindings[i].setValue(array, offset);
  26172. }
  26173. },
  26174. bind: function bind() {
  26175. var bindings = this._bindings;
  26176. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26177. bindings[i].bind();
  26178. }
  26179. },
  26180. unbind: function unbind() {
  26181. var bindings = this._bindings;
  26182. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  26183. bindings[i].unbind();
  26184. }
  26185. }
  26186. });
  26187. function PropertyBinding(rootNode, path, parsedPath) {
  26188. this.path = path;
  26189. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  26190. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  26191. this.rootNode = rootNode;
  26192. }
  26193. Object.assign(PropertyBinding, {
  26194. Composite: Composite,
  26195. create: function create(root, path, parsedPath) {
  26196. if (!(root && root.isAnimationObjectGroup)) {
  26197. return new PropertyBinding(root, path, parsedPath);
  26198. } else {
  26199. return new PropertyBinding.Composite(root, path, parsedPath);
  26200. }
  26201. },
  26202. /**
  26203. * Replaces spaces with underscores and removes unsupported characters from
  26204. * node names, to ensure compatibility with parseTrackName().
  26205. *
  26206. * @param {string} name Node name to be sanitized.
  26207. * @return {string}
  26208. */
  26209. sanitizeNodeName: function sanitizeNodeName(name) {
  26210. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  26211. },
  26212. parseTrackName: function parseTrackName(trackName) {
  26213. var matches = _trackRe.exec(trackName);
  26214. if (!matches) {
  26215. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  26216. }
  26217. var results = {
  26218. // directoryName: matches[ 1 ], // (tschw) currently unused
  26219. nodeName: matches[2],
  26220. objectName: matches[3],
  26221. objectIndex: matches[4],
  26222. propertyName: matches[5],
  26223. // required
  26224. propertyIndex: matches[6]
  26225. };
  26226. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  26227. if (lastDot !== undefined && lastDot !== -1) {
  26228. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  26229. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26230. // 'bar' could be the objectName, or part of a nodeName (which can
  26231. // include '.' characters).
  26232. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  26233. results.nodeName = results.nodeName.substring(0, lastDot);
  26234. results.objectName = objectName;
  26235. }
  26236. }
  26237. if (results.propertyName === null || results.propertyName.length === 0) {
  26238. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  26239. }
  26240. return results;
  26241. },
  26242. findNode: function findNode(root, nodeName) {
  26243. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  26244. return root;
  26245. } // search into skeleton bones.
  26246. if (root.skeleton) {
  26247. var bone = root.skeleton.getBoneByName(nodeName);
  26248. if (bone !== undefined) {
  26249. return bone;
  26250. }
  26251. } // search into node subtree.
  26252. if (root.children) {
  26253. var searchNodeSubtree = function searchNodeSubtree(children) {
  26254. for (var i = 0; i < children.length; i++) {
  26255. var childNode = children[i];
  26256. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  26257. return childNode;
  26258. }
  26259. var result = searchNodeSubtree(childNode.children);
  26260. if (result) return result;
  26261. }
  26262. return null;
  26263. };
  26264. var subTreeNode = searchNodeSubtree(root.children);
  26265. if (subTreeNode) {
  26266. return subTreeNode;
  26267. }
  26268. }
  26269. return null;
  26270. }
  26271. });
  26272. Object.assign(PropertyBinding.prototype, {
  26273. // prototype, continued
  26274. // these are used to "bind" a nonexistent property
  26275. _getValue_unavailable: function _getValue_unavailable() {},
  26276. _setValue_unavailable: function _setValue_unavailable() {},
  26277. BindingType: {
  26278. Direct: 0,
  26279. EntireArray: 1,
  26280. ArrayElement: 2,
  26281. HasFromToArray: 3
  26282. },
  26283. Versioning: {
  26284. None: 0,
  26285. NeedsUpdate: 1,
  26286. MatrixWorldNeedsUpdate: 2
  26287. },
  26288. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26289. buffer[offset] = this.node[this.propertyName];
  26290. }, function getValue_array(buffer, offset) {
  26291. var source = this.resolvedProperty;
  26292. for (var i = 0, n = source.length; i !== n; ++i) {
  26293. buffer[offset++] = source[i];
  26294. }
  26295. }, function getValue_arrayElement(buffer, offset) {
  26296. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26297. }, function getValue_toArray(buffer, offset) {
  26298. this.resolvedProperty.toArray(buffer, offset);
  26299. }],
  26300. SetterByBindingTypeAndVersioning: [[// Direct
  26301. function setValue_direct(buffer, offset) {
  26302. this.targetObject[this.propertyName] = buffer[offset];
  26303. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26304. this.targetObject[this.propertyName] = buffer[offset];
  26305. this.targetObject.needsUpdate = true;
  26306. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26307. this.targetObject[this.propertyName] = buffer[offset];
  26308. this.targetObject.matrixWorldNeedsUpdate = true;
  26309. }], [// EntireArray
  26310. function setValue_array(buffer, offset) {
  26311. var dest = this.resolvedProperty;
  26312. for (var i = 0, n = dest.length; i !== n; ++i) {
  26313. dest[i] = buffer[offset++];
  26314. }
  26315. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26316. var dest = this.resolvedProperty;
  26317. for (var i = 0, n = dest.length; i !== n; ++i) {
  26318. dest[i] = buffer[offset++];
  26319. }
  26320. this.targetObject.needsUpdate = true;
  26321. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26322. var dest = this.resolvedProperty;
  26323. for (var i = 0, n = dest.length; i !== n; ++i) {
  26324. dest[i] = buffer[offset++];
  26325. }
  26326. this.targetObject.matrixWorldNeedsUpdate = true;
  26327. }], [// ArrayElement
  26328. function setValue_arrayElement(buffer, offset) {
  26329. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26330. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26331. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26332. this.targetObject.needsUpdate = true;
  26333. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26334. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26335. this.targetObject.matrixWorldNeedsUpdate = true;
  26336. }], [// HasToFromArray
  26337. function setValue_fromArray(buffer, offset) {
  26338. this.resolvedProperty.fromArray(buffer, offset);
  26339. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26340. this.resolvedProperty.fromArray(buffer, offset);
  26341. this.targetObject.needsUpdate = true;
  26342. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26343. this.resolvedProperty.fromArray(buffer, offset);
  26344. this.targetObject.matrixWorldNeedsUpdate = true;
  26345. }]],
  26346. getValue: function getValue_unbound(targetArray, offset) {
  26347. this.bind();
  26348. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26349. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26350. // prototype version of these methods with one that represents
  26351. // the bound state. When the property is not found, the methods
  26352. // become no-ops.
  26353. },
  26354. setValue: function getValue_unbound(sourceArray, offset) {
  26355. this.bind();
  26356. this.setValue(sourceArray, offset);
  26357. },
  26358. // create getter / setter pair for a property in the scene graph
  26359. bind: function bind() {
  26360. var targetObject = this.node;
  26361. var parsedPath = this.parsedPath;
  26362. var objectName = parsedPath.objectName;
  26363. var propertyName = parsedPath.propertyName;
  26364. var propertyIndex = parsedPath.propertyIndex;
  26365. if (!targetObject) {
  26366. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26367. this.node = targetObject;
  26368. } // set fail state so we can just 'return' on error
  26369. this.getValue = this._getValue_unavailable;
  26370. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26371. if (!targetObject) {
  26372. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26373. return;
  26374. }
  26375. if (objectName) {
  26376. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26377. switch (objectName) {
  26378. case 'materials':
  26379. if (!targetObject.material) {
  26380. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26381. return;
  26382. }
  26383. if (!targetObject.material.materials) {
  26384. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26385. return;
  26386. }
  26387. targetObject = targetObject.material.materials;
  26388. break;
  26389. case 'bones':
  26390. if (!targetObject.skeleton) {
  26391. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26392. return;
  26393. } // potential future optimization: skip this if propertyIndex is already an integer
  26394. // and convert the integer string to a true integer.
  26395. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26396. for (var i = 0; i < targetObject.length; i++) {
  26397. if (targetObject[i].name === objectIndex) {
  26398. objectIndex = i;
  26399. break;
  26400. }
  26401. }
  26402. break;
  26403. default:
  26404. if (targetObject[objectName] === undefined) {
  26405. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26406. return;
  26407. }
  26408. targetObject = targetObject[objectName];
  26409. }
  26410. if (objectIndex !== undefined) {
  26411. if (targetObject[objectIndex] === undefined) {
  26412. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26413. return;
  26414. }
  26415. targetObject = targetObject[objectIndex];
  26416. }
  26417. } // resolve property
  26418. var nodeProperty = targetObject[propertyName];
  26419. if (nodeProperty === undefined) {
  26420. var nodeName = parsedPath.nodeName;
  26421. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26422. return;
  26423. } // determine versioning scheme
  26424. var versioning = this.Versioning.None;
  26425. this.targetObject = targetObject;
  26426. if (targetObject.needsUpdate !== undefined) {
  26427. // material
  26428. versioning = this.Versioning.NeedsUpdate;
  26429. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26430. // node transform
  26431. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26432. } // determine how the property gets bound
  26433. var bindingType = this.BindingType.Direct;
  26434. if (propertyIndex !== undefined) {
  26435. // access a sub element of the property array (only primitives are supported right now)
  26436. if (propertyName === 'morphTargetInfluences') {
  26437. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26438. // support resolving morphTarget names into indices.
  26439. if (!targetObject.geometry) {
  26440. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26441. return;
  26442. }
  26443. if (targetObject.geometry.isBufferGeometry) {
  26444. if (!targetObject.geometry.morphAttributes) {
  26445. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26446. return;
  26447. }
  26448. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26449. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26450. }
  26451. } else {
  26452. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26453. return;
  26454. }
  26455. }
  26456. bindingType = this.BindingType.ArrayElement;
  26457. this.resolvedProperty = nodeProperty;
  26458. this.propertyIndex = propertyIndex;
  26459. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26460. // must use copy for Object3D.Euler/Quaternion
  26461. bindingType = this.BindingType.HasFromToArray;
  26462. this.resolvedProperty = nodeProperty;
  26463. } else if (Array.isArray(nodeProperty)) {
  26464. bindingType = this.BindingType.EntireArray;
  26465. this.resolvedProperty = nodeProperty;
  26466. } else {
  26467. this.propertyName = propertyName;
  26468. } // select getter / setter
  26469. this.getValue = this.GetterByBindingType[bindingType];
  26470. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26471. },
  26472. unbind: function unbind() {
  26473. this.node = null; // back to the prototype version of getValue / setValue
  26474. // note: avoiding to mutate the shape of 'this' via 'delete'
  26475. this.getValue = this._getValue_unbound;
  26476. this.setValue = this._setValue_unbound;
  26477. }
  26478. }); // DECLARE ALIAS AFTER assign prototype
  26479. Object.assign(PropertyBinding.prototype, {
  26480. // initial state of these methods that calls 'bind'
  26481. _getValue_unbound: PropertyBinding.prototype.getValue,
  26482. _setValue_unbound: PropertyBinding.prototype.setValue
  26483. });
  26484. /**
  26485. *
  26486. * A group of objects that receives a shared animation state.
  26487. *
  26488. * Usage:
  26489. *
  26490. * - Add objects you would otherwise pass as 'root' to the
  26491. * constructor or the .clipAction method of AnimationMixer.
  26492. *
  26493. * - Instead pass this object as 'root'.
  26494. *
  26495. * - You can also add and remove objects later when the mixer
  26496. * is running.
  26497. *
  26498. * Note:
  26499. *
  26500. * Objects of this class appear as one object to the mixer,
  26501. * so cache control of the individual objects must be done
  26502. * on the group.
  26503. *
  26504. * Limitation:
  26505. *
  26506. * - The animated properties must be compatible among the
  26507. * all objects in the group.
  26508. *
  26509. * - A single property can either be controlled through a
  26510. * target group or directly, but not both.
  26511. */
  26512. var AnimationObjectGroup = /*#__PURE__*/function () {
  26513. function AnimationObjectGroup() {
  26514. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26515. this._objects = Array.prototype.slice.call(arguments);
  26516. this.nCachedObjects_ = 0; // threshold
  26517. // note: read by PropertyBinding.Composite
  26518. var indices = {};
  26519. this._indicesByUUID = indices; // for bookkeeping
  26520. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26521. indices[arguments[i].uuid] = i;
  26522. }
  26523. this._paths = []; // inside: string
  26524. this._parsedPaths = []; // inside: { we don't care, here }
  26525. this._bindings = []; // inside: Array< PropertyBinding >
  26526. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26527. var scope = this;
  26528. this.stats = {
  26529. objects: {
  26530. get total() {
  26531. return scope._objects.length;
  26532. },
  26533. get inUse() {
  26534. return this.total - scope.nCachedObjects_;
  26535. }
  26536. },
  26537. get bindingsPerObject() {
  26538. return scope._bindings.length;
  26539. }
  26540. };
  26541. }
  26542. var _proto = AnimationObjectGroup.prototype;
  26543. _proto.add = function add() {
  26544. var objects = this._objects,
  26545. indicesByUUID = this._indicesByUUID,
  26546. paths = this._paths,
  26547. parsedPaths = this._parsedPaths,
  26548. bindings = this._bindings,
  26549. nBindings = bindings.length;
  26550. var knownObject = undefined,
  26551. nObjects = objects.length,
  26552. nCachedObjects = this.nCachedObjects_;
  26553. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26554. var object = arguments[i],
  26555. uuid = object.uuid;
  26556. var index = indicesByUUID[uuid];
  26557. if (index === undefined) {
  26558. // unknown object -> add it to the ACTIVE region
  26559. index = nObjects++;
  26560. indicesByUUID[uuid] = index;
  26561. objects.push(object); // accounting is done, now do the same for all bindings
  26562. for (var j = 0, m = nBindings; j !== m; ++j) {
  26563. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26564. }
  26565. } else if (index < nCachedObjects) {
  26566. knownObject = objects[index]; // move existing object to the ACTIVE region
  26567. var firstActiveIndex = --nCachedObjects,
  26568. lastCachedObject = objects[firstActiveIndex];
  26569. indicesByUUID[lastCachedObject.uuid] = index;
  26570. objects[index] = lastCachedObject;
  26571. indicesByUUID[uuid] = firstActiveIndex;
  26572. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26573. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26574. var bindingsForPath = bindings[_j],
  26575. lastCached = bindingsForPath[firstActiveIndex];
  26576. var binding = bindingsForPath[index];
  26577. bindingsForPath[index] = lastCached;
  26578. if (binding === undefined) {
  26579. // since we do not bother to create new bindings
  26580. // for objects that are cached, the binding may
  26581. // or may not exist
  26582. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26583. }
  26584. bindingsForPath[firstActiveIndex] = binding;
  26585. }
  26586. } else if (objects[index] !== knownObject) {
  26587. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26588. } // else the object is already where we want it to be
  26589. } // for arguments
  26590. this.nCachedObjects_ = nCachedObjects;
  26591. };
  26592. _proto.remove = function remove() {
  26593. var objects = this._objects,
  26594. indicesByUUID = this._indicesByUUID,
  26595. bindings = this._bindings,
  26596. nBindings = bindings.length;
  26597. var nCachedObjects = this.nCachedObjects_;
  26598. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26599. var object = arguments[i],
  26600. uuid = object.uuid,
  26601. index = indicesByUUID[uuid];
  26602. if (index !== undefined && index >= nCachedObjects) {
  26603. // move existing object into the CACHED region
  26604. var lastCachedIndex = nCachedObjects++,
  26605. firstActiveObject = objects[lastCachedIndex];
  26606. indicesByUUID[firstActiveObject.uuid] = index;
  26607. objects[index] = firstActiveObject;
  26608. indicesByUUID[uuid] = lastCachedIndex;
  26609. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26610. for (var j = 0, m = nBindings; j !== m; ++j) {
  26611. var bindingsForPath = bindings[j],
  26612. firstActive = bindingsForPath[lastCachedIndex],
  26613. binding = bindingsForPath[index];
  26614. bindingsForPath[index] = firstActive;
  26615. bindingsForPath[lastCachedIndex] = binding;
  26616. }
  26617. }
  26618. } // for arguments
  26619. this.nCachedObjects_ = nCachedObjects;
  26620. } // remove & forget
  26621. ;
  26622. _proto.uncache = function uncache() {
  26623. var objects = this._objects,
  26624. indicesByUUID = this._indicesByUUID,
  26625. bindings = this._bindings,
  26626. nBindings = bindings.length;
  26627. var nCachedObjects = this.nCachedObjects_,
  26628. nObjects = objects.length;
  26629. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26630. var object = arguments[i],
  26631. uuid = object.uuid,
  26632. index = indicesByUUID[uuid];
  26633. if (index !== undefined) {
  26634. delete indicesByUUID[uuid];
  26635. if (index < nCachedObjects) {
  26636. // object is cached, shrink the CACHED region
  26637. var firstActiveIndex = --nCachedObjects,
  26638. lastCachedObject = objects[firstActiveIndex],
  26639. lastIndex = --nObjects,
  26640. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26641. indicesByUUID[lastCachedObject.uuid] = index;
  26642. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26643. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26644. objects[firstActiveIndex] = lastObject;
  26645. objects.pop(); // accounting is done, now do the same for all bindings
  26646. for (var j = 0, m = nBindings; j !== m; ++j) {
  26647. var bindingsForPath = bindings[j],
  26648. lastCached = bindingsForPath[firstActiveIndex],
  26649. last = bindingsForPath[lastIndex];
  26650. bindingsForPath[index] = lastCached;
  26651. bindingsForPath[firstActiveIndex] = last;
  26652. bindingsForPath.pop();
  26653. }
  26654. } else {
  26655. // object is active, just swap with the last and pop
  26656. var _lastIndex = --nObjects,
  26657. _lastObject = objects[_lastIndex];
  26658. if (_lastIndex > 0) {
  26659. indicesByUUID[_lastObject.uuid] = index;
  26660. }
  26661. objects[index] = _lastObject;
  26662. objects.pop(); // accounting is done, now do the same for all bindings
  26663. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26664. var _bindingsForPath = bindings[_j2];
  26665. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26666. _bindingsForPath.pop();
  26667. }
  26668. } // cached or active
  26669. } // if object is known
  26670. } // for arguments
  26671. this.nCachedObjects_ = nCachedObjects;
  26672. } // Internal interface used by befriended PropertyBinding.Composite:
  26673. ;
  26674. _proto.subscribe_ = function subscribe_(path, parsedPath) {
  26675. // returns an array of bindings for the given path that is changed
  26676. // according to the contained objects in the group
  26677. var indicesByPath = this._bindingsIndicesByPath;
  26678. var index = indicesByPath[path];
  26679. var bindings = this._bindings;
  26680. if (index !== undefined) return bindings[index];
  26681. var paths = this._paths,
  26682. parsedPaths = this._parsedPaths,
  26683. objects = this._objects,
  26684. nObjects = objects.length,
  26685. nCachedObjects = this.nCachedObjects_,
  26686. bindingsForPath = new Array(nObjects);
  26687. index = bindings.length;
  26688. indicesByPath[path] = index;
  26689. paths.push(path);
  26690. parsedPaths.push(parsedPath);
  26691. bindings.push(bindingsForPath);
  26692. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26693. var object = objects[i];
  26694. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26695. }
  26696. return bindingsForPath;
  26697. };
  26698. _proto.unsubscribe_ = function unsubscribe_(path) {
  26699. // tells the group to forget about a property path and no longer
  26700. // update the array previously obtained with 'subscribe_'
  26701. var indicesByPath = this._bindingsIndicesByPath,
  26702. index = indicesByPath[path];
  26703. if (index !== undefined) {
  26704. var paths = this._paths,
  26705. parsedPaths = this._parsedPaths,
  26706. bindings = this._bindings,
  26707. lastBindingsIndex = bindings.length - 1,
  26708. lastBindings = bindings[lastBindingsIndex],
  26709. lastBindingsPath = path[lastBindingsIndex];
  26710. indicesByPath[lastBindingsPath] = index;
  26711. bindings[index] = lastBindings;
  26712. bindings.pop();
  26713. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26714. parsedPaths.pop();
  26715. paths[index] = paths[lastBindingsIndex];
  26716. paths.pop();
  26717. }
  26718. };
  26719. return AnimationObjectGroup;
  26720. }();
  26721. AnimationObjectGroup.prototype.isAnimationObjectGroup = true;
  26722. var AnimationAction = /*#__PURE__*/function () {
  26723. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26724. if (localRoot === void 0) {
  26725. localRoot = null;
  26726. }
  26727. if (blendMode === void 0) {
  26728. blendMode = clip.blendMode;
  26729. }
  26730. this._mixer = mixer;
  26731. this._clip = clip;
  26732. this._localRoot = localRoot;
  26733. this.blendMode = blendMode;
  26734. var tracks = clip.tracks,
  26735. nTracks = tracks.length,
  26736. interpolants = new Array(nTracks);
  26737. var interpolantSettings = {
  26738. endingStart: ZeroCurvatureEnding,
  26739. endingEnd: ZeroCurvatureEnding
  26740. };
  26741. for (var i = 0; i !== nTracks; ++i) {
  26742. var interpolant = tracks[i].createInterpolant(null);
  26743. interpolants[i] = interpolant;
  26744. interpolant.settings = interpolantSettings;
  26745. }
  26746. this._interpolantSettings = interpolantSettings;
  26747. this._interpolants = interpolants; // bound by the mixer
  26748. // inside: PropertyMixer (managed by the mixer)
  26749. this._propertyBindings = new Array(nTracks);
  26750. this._cacheIndex = null; // for the memory manager
  26751. this._byClipCacheIndex = null; // for the memory manager
  26752. this._timeScaleInterpolant = null;
  26753. this._weightInterpolant = null;
  26754. this.loop = LoopRepeat;
  26755. this._loopCount = -1; // global mixer time when the action is to be started
  26756. // it's set back to 'null' upon start of the action
  26757. this._startTime = null; // scaled local time of the action
  26758. // gets clamped or wrapped to 0..clip.duration according to loop
  26759. this.time = 0;
  26760. this.timeScale = 1;
  26761. this._effectiveTimeScale = 1;
  26762. this.weight = 1;
  26763. this._effectiveWeight = 1;
  26764. this.repetitions = Infinity; // no. of repetitions when looping
  26765. this.paused = false; // true -> zero effective time scale
  26766. this.enabled = true; // false -> zero effective weight
  26767. this.clampWhenFinished = false; // keep feeding the last frame?
  26768. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26769. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26770. } // State & Scheduling
  26771. var _proto = AnimationAction.prototype;
  26772. _proto.play = function play() {
  26773. this._mixer._activateAction(this);
  26774. return this;
  26775. };
  26776. _proto.stop = function stop() {
  26777. this._mixer._deactivateAction(this);
  26778. return this.reset();
  26779. };
  26780. _proto.reset = function reset() {
  26781. this.paused = false;
  26782. this.enabled = true;
  26783. this.time = 0; // restart clip
  26784. this._loopCount = -1; // forget previous loops
  26785. this._startTime = null; // forget scheduling
  26786. return this.stopFading().stopWarping();
  26787. };
  26788. _proto.isRunning = function isRunning() {
  26789. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26790. } // return true when play has been called
  26791. ;
  26792. _proto.isScheduled = function isScheduled() {
  26793. return this._mixer._isActiveAction(this);
  26794. };
  26795. _proto.startAt = function startAt(time) {
  26796. this._startTime = time;
  26797. return this;
  26798. };
  26799. _proto.setLoop = function setLoop(mode, repetitions) {
  26800. this.loop = mode;
  26801. this.repetitions = repetitions;
  26802. return this;
  26803. } // Weight
  26804. // set the weight stopping any scheduled fading
  26805. // although .enabled = false yields an effective weight of zero, this
  26806. // method does *not* change .enabled, because it would be confusing
  26807. ;
  26808. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26809. this.weight = weight; // note: same logic as when updated at runtime
  26810. this._effectiveWeight = this.enabled ? weight : 0;
  26811. return this.stopFading();
  26812. } // return the weight considering fading and .enabled
  26813. ;
  26814. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26815. return this._effectiveWeight;
  26816. };
  26817. _proto.fadeIn = function fadeIn(duration) {
  26818. return this._scheduleFading(duration, 0, 1);
  26819. };
  26820. _proto.fadeOut = function fadeOut(duration) {
  26821. return this._scheduleFading(duration, 1, 0);
  26822. };
  26823. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26824. fadeOutAction.fadeOut(duration);
  26825. this.fadeIn(duration);
  26826. if (warp) {
  26827. var fadeInDuration = this._clip.duration,
  26828. fadeOutDuration = fadeOutAction._clip.duration,
  26829. startEndRatio = fadeOutDuration / fadeInDuration,
  26830. endStartRatio = fadeInDuration / fadeOutDuration;
  26831. fadeOutAction.warp(1.0, startEndRatio, duration);
  26832. this.warp(endStartRatio, 1.0, duration);
  26833. }
  26834. return this;
  26835. };
  26836. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26837. return fadeInAction.crossFadeFrom(this, duration, warp);
  26838. };
  26839. _proto.stopFading = function stopFading() {
  26840. var weightInterpolant = this._weightInterpolant;
  26841. if (weightInterpolant !== null) {
  26842. this._weightInterpolant = null;
  26843. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26844. }
  26845. return this;
  26846. } // Time Scale Control
  26847. // set the time scale stopping any scheduled warping
  26848. // although .paused = true yields an effective time scale of zero, this
  26849. // method does *not* change .paused, because it would be confusing
  26850. ;
  26851. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26852. this.timeScale = timeScale;
  26853. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26854. return this.stopWarping();
  26855. } // return the time scale considering warping and .paused
  26856. ;
  26857. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26858. return this._effectiveTimeScale;
  26859. };
  26860. _proto.setDuration = function setDuration(duration) {
  26861. this.timeScale = this._clip.duration / duration;
  26862. return this.stopWarping();
  26863. };
  26864. _proto.syncWith = function syncWith(action) {
  26865. this.time = action.time;
  26866. this.timeScale = action.timeScale;
  26867. return this.stopWarping();
  26868. };
  26869. _proto.halt = function halt(duration) {
  26870. return this.warp(this._effectiveTimeScale, 0, duration);
  26871. };
  26872. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26873. var mixer = this._mixer,
  26874. now = mixer.time,
  26875. timeScale = this.timeScale;
  26876. var interpolant = this._timeScaleInterpolant;
  26877. if (interpolant === null) {
  26878. interpolant = mixer._lendControlInterpolant();
  26879. this._timeScaleInterpolant = interpolant;
  26880. }
  26881. var times = interpolant.parameterPositions,
  26882. values = interpolant.sampleValues;
  26883. times[0] = now;
  26884. times[1] = now + duration;
  26885. values[0] = startTimeScale / timeScale;
  26886. values[1] = endTimeScale / timeScale;
  26887. return this;
  26888. };
  26889. _proto.stopWarping = function stopWarping() {
  26890. var timeScaleInterpolant = this._timeScaleInterpolant;
  26891. if (timeScaleInterpolant !== null) {
  26892. this._timeScaleInterpolant = null;
  26893. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26894. }
  26895. return this;
  26896. } // Object Accessors
  26897. ;
  26898. _proto.getMixer = function getMixer() {
  26899. return this._mixer;
  26900. };
  26901. _proto.getClip = function getClip() {
  26902. return this._clip;
  26903. };
  26904. _proto.getRoot = function getRoot() {
  26905. return this._localRoot || this._mixer._root;
  26906. } // Interna
  26907. ;
  26908. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26909. // called by the mixer
  26910. if (!this.enabled) {
  26911. // call ._updateWeight() to update ._effectiveWeight
  26912. this._updateWeight(time);
  26913. return;
  26914. }
  26915. var startTime = this._startTime;
  26916. if (startTime !== null) {
  26917. // check for scheduled start of action
  26918. var timeRunning = (time - startTime) * timeDirection;
  26919. if (timeRunning < 0 || timeDirection === 0) {
  26920. return; // yet to come / don't decide when delta = 0
  26921. } // start
  26922. this._startTime = null; // unschedule
  26923. deltaTime = timeDirection * timeRunning;
  26924. } // apply time scale and advance time
  26925. deltaTime *= this._updateTimeScale(time);
  26926. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26927. // an effective weight of 0
  26928. var weight = this._updateWeight(time);
  26929. if (weight > 0) {
  26930. var _interpolants = this._interpolants;
  26931. var propertyMixers = this._propertyBindings;
  26932. switch (this.blendMode) {
  26933. case AdditiveAnimationBlendMode:
  26934. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26935. _interpolants[j].evaluate(clipTime);
  26936. propertyMixers[j].accumulateAdditive(weight);
  26937. }
  26938. break;
  26939. case NormalAnimationBlendMode:
  26940. default:
  26941. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26942. _interpolants[_j].evaluate(clipTime);
  26943. propertyMixers[_j].accumulate(accuIndex, weight);
  26944. }
  26945. }
  26946. }
  26947. };
  26948. _proto._updateWeight = function _updateWeight(time) {
  26949. var weight = 0;
  26950. if (this.enabled) {
  26951. weight = this.weight;
  26952. var interpolant = this._weightInterpolant;
  26953. if (interpolant !== null) {
  26954. var interpolantValue = interpolant.evaluate(time)[0];
  26955. weight *= interpolantValue;
  26956. if (time > interpolant.parameterPositions[1]) {
  26957. this.stopFading();
  26958. if (interpolantValue === 0) {
  26959. // faded out, disable
  26960. this.enabled = false;
  26961. }
  26962. }
  26963. }
  26964. }
  26965. this._effectiveWeight = weight;
  26966. return weight;
  26967. };
  26968. _proto._updateTimeScale = function _updateTimeScale(time) {
  26969. var timeScale = 0;
  26970. if (!this.paused) {
  26971. timeScale = this.timeScale;
  26972. var interpolant = this._timeScaleInterpolant;
  26973. if (interpolant !== null) {
  26974. var interpolantValue = interpolant.evaluate(time)[0];
  26975. timeScale *= interpolantValue;
  26976. if (time > interpolant.parameterPositions[1]) {
  26977. this.stopWarping();
  26978. if (timeScale === 0) {
  26979. // motion has halted, pause
  26980. this.paused = true;
  26981. } else {
  26982. // warp done - apply final time scale
  26983. this.timeScale = timeScale;
  26984. }
  26985. }
  26986. }
  26987. }
  26988. this._effectiveTimeScale = timeScale;
  26989. return timeScale;
  26990. };
  26991. _proto._updateTime = function _updateTime(deltaTime) {
  26992. var duration = this._clip.duration;
  26993. var loop = this.loop;
  26994. var time = this.time + deltaTime;
  26995. var loopCount = this._loopCount;
  26996. var pingPong = loop === LoopPingPong;
  26997. if (deltaTime === 0) {
  26998. if (loopCount === -1) return time;
  26999. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  27000. }
  27001. if (loop === LoopOnce) {
  27002. if (loopCount === -1) {
  27003. // just started
  27004. this._loopCount = 0;
  27005. this._setEndings(true, true, false);
  27006. }
  27007. handle_stop: {
  27008. if (time >= duration) {
  27009. time = duration;
  27010. } else if (time < 0) {
  27011. time = 0;
  27012. } else {
  27013. this.time = time;
  27014. break handle_stop;
  27015. }
  27016. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27017. this.time = time;
  27018. this._mixer.dispatchEvent({
  27019. type: 'finished',
  27020. action: this,
  27021. direction: deltaTime < 0 ? -1 : 1
  27022. });
  27023. }
  27024. } else {
  27025. // repetitive Repeat or PingPong
  27026. if (loopCount === -1) {
  27027. // just started
  27028. if (deltaTime >= 0) {
  27029. loopCount = 0;
  27030. this._setEndings(true, this.repetitions === 0, pingPong);
  27031. } else {
  27032. // when looping in reverse direction, the initial
  27033. // transition through zero counts as a repetition,
  27034. // so leave loopCount at -1
  27035. this._setEndings(this.repetitions === 0, true, pingPong);
  27036. }
  27037. }
  27038. if (time >= duration || time < 0) {
  27039. // wrap around
  27040. var loopDelta = Math.floor(time / duration); // signed
  27041. time -= duration * loopDelta;
  27042. loopCount += Math.abs(loopDelta);
  27043. var pending = this.repetitions - loopCount;
  27044. if (pending <= 0) {
  27045. // have to stop (switch state, clamp time, fire event)
  27046. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  27047. time = deltaTime > 0 ? duration : 0;
  27048. this.time = time;
  27049. this._mixer.dispatchEvent({
  27050. type: 'finished',
  27051. action: this,
  27052. direction: deltaTime > 0 ? 1 : -1
  27053. });
  27054. } else {
  27055. // keep running
  27056. if (pending === 1) {
  27057. // entering the last round
  27058. var atStart = deltaTime < 0;
  27059. this._setEndings(atStart, !atStart, pingPong);
  27060. } else {
  27061. this._setEndings(false, false, pingPong);
  27062. }
  27063. this._loopCount = loopCount;
  27064. this.time = time;
  27065. this._mixer.dispatchEvent({
  27066. type: 'loop',
  27067. action: this,
  27068. loopDelta: loopDelta
  27069. });
  27070. }
  27071. } else {
  27072. this.time = time;
  27073. }
  27074. if (pingPong && (loopCount & 1) === 1) {
  27075. // invert time for the "pong round"
  27076. return duration - time;
  27077. }
  27078. }
  27079. return time;
  27080. };
  27081. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  27082. var settings = this._interpolantSettings;
  27083. if (pingPong) {
  27084. settings.endingStart = ZeroSlopeEnding;
  27085. settings.endingEnd = ZeroSlopeEnding;
  27086. } else {
  27087. // assuming for LoopOnce atStart == atEnd == true
  27088. if (atStart) {
  27089. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27090. } else {
  27091. settings.endingStart = WrapAroundEnding;
  27092. }
  27093. if (atEnd) {
  27094. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27095. } else {
  27096. settings.endingEnd = WrapAroundEnding;
  27097. }
  27098. }
  27099. };
  27100. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  27101. var mixer = this._mixer,
  27102. now = mixer.time;
  27103. var interpolant = this._weightInterpolant;
  27104. if (interpolant === null) {
  27105. interpolant = mixer._lendControlInterpolant();
  27106. this._weightInterpolant = interpolant;
  27107. }
  27108. var times = interpolant.parameterPositions,
  27109. values = interpolant.sampleValues;
  27110. times[0] = now;
  27111. values[0] = weightNow;
  27112. times[1] = now + duration;
  27113. values[1] = weightThen;
  27114. return this;
  27115. };
  27116. return AnimationAction;
  27117. }();
  27118. var AnimationMixer = /*#__PURE__*/function (_EventDispatcher) {
  27119. _inheritsLoose(AnimationMixer, _EventDispatcher);
  27120. function AnimationMixer(root) {
  27121. var _this;
  27122. _this = _EventDispatcher.call(this) || this;
  27123. _this._root = root;
  27124. _this._initMemoryManager();
  27125. _this._accuIndex = 0;
  27126. _this.time = 0;
  27127. _this.timeScale = 1.0;
  27128. return _this;
  27129. }
  27130. var _proto = AnimationMixer.prototype;
  27131. _proto._bindAction = function _bindAction(action, prototypeAction) {
  27132. var root = action._localRoot || this._root,
  27133. tracks = action._clip.tracks,
  27134. nTracks = tracks.length,
  27135. bindings = action._propertyBindings,
  27136. interpolants = action._interpolants,
  27137. rootUuid = root.uuid,
  27138. bindingsByRoot = this._bindingsByRootAndName;
  27139. var bindingsByName = bindingsByRoot[rootUuid];
  27140. if (bindingsByName === undefined) {
  27141. bindingsByName = {};
  27142. bindingsByRoot[rootUuid] = bindingsByName;
  27143. }
  27144. for (var i = 0; i !== nTracks; ++i) {
  27145. var track = tracks[i],
  27146. trackName = track.name;
  27147. var binding = bindingsByName[trackName];
  27148. if (binding !== undefined) {
  27149. bindings[i] = binding;
  27150. } else {
  27151. binding = bindings[i];
  27152. if (binding !== undefined) {
  27153. // existing binding, make sure the cache knows
  27154. if (binding._cacheIndex === null) {
  27155. ++binding.referenceCount;
  27156. this._addInactiveBinding(binding, rootUuid, trackName);
  27157. }
  27158. continue;
  27159. }
  27160. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  27161. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  27162. ++binding.referenceCount;
  27163. this._addInactiveBinding(binding, rootUuid, trackName);
  27164. bindings[i] = binding;
  27165. }
  27166. interpolants[i].resultBuffer = binding.buffer;
  27167. }
  27168. };
  27169. _proto._activateAction = function _activateAction(action) {
  27170. if (!this._isActiveAction(action)) {
  27171. if (action._cacheIndex === null) {
  27172. // this action has been forgotten by the cache, but the user
  27173. // appears to be still using it -> rebind
  27174. var rootUuid = (action._localRoot || this._root).uuid,
  27175. clipUuid = action._clip.uuid,
  27176. actionsForClip = this._actionsByClip[clipUuid];
  27177. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  27178. this._addInactiveAction(action, clipUuid, rootUuid);
  27179. }
  27180. var bindings = action._propertyBindings; // increment reference counts / sort out state
  27181. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27182. var binding = bindings[i];
  27183. if (binding.useCount++ === 0) {
  27184. this._lendBinding(binding);
  27185. binding.saveOriginalState();
  27186. }
  27187. }
  27188. this._lendAction(action);
  27189. }
  27190. };
  27191. _proto._deactivateAction = function _deactivateAction(action) {
  27192. if (this._isActiveAction(action)) {
  27193. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  27194. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27195. var binding = bindings[i];
  27196. if (--binding.useCount === 0) {
  27197. binding.restoreOriginalState();
  27198. this._takeBackBinding(binding);
  27199. }
  27200. }
  27201. this._takeBackAction(action);
  27202. }
  27203. } // Memory manager
  27204. ;
  27205. _proto._initMemoryManager = function _initMemoryManager() {
  27206. this._actions = []; // 'nActiveActions' followed by inactive ones
  27207. this._nActiveActions = 0;
  27208. this._actionsByClip = {}; // inside:
  27209. // {
  27210. // knownActions: Array< AnimationAction > - used as prototypes
  27211. // actionByRoot: AnimationAction - lookup
  27212. // }
  27213. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27214. this._nActiveBindings = 0;
  27215. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27216. this._controlInterpolants = []; // same game as above
  27217. this._nActiveControlInterpolants = 0;
  27218. var scope = this;
  27219. this.stats = {
  27220. actions: {
  27221. get total() {
  27222. return scope._actions.length;
  27223. },
  27224. get inUse() {
  27225. return scope._nActiveActions;
  27226. }
  27227. },
  27228. bindings: {
  27229. get total() {
  27230. return scope._bindings.length;
  27231. },
  27232. get inUse() {
  27233. return scope._nActiveBindings;
  27234. }
  27235. },
  27236. controlInterpolants: {
  27237. get total() {
  27238. return scope._controlInterpolants.length;
  27239. },
  27240. get inUse() {
  27241. return scope._nActiveControlInterpolants;
  27242. }
  27243. }
  27244. };
  27245. } // Memory management for AnimationAction objects
  27246. ;
  27247. _proto._isActiveAction = function _isActiveAction(action) {
  27248. var index = action._cacheIndex;
  27249. return index !== null && index < this._nActiveActions;
  27250. };
  27251. _proto._addInactiveAction = function _addInactiveAction(action, clipUuid, rootUuid) {
  27252. var actions = this._actions,
  27253. actionsByClip = this._actionsByClip;
  27254. var actionsForClip = actionsByClip[clipUuid];
  27255. if (actionsForClip === undefined) {
  27256. actionsForClip = {
  27257. knownActions: [action],
  27258. actionByRoot: {}
  27259. };
  27260. action._byClipCacheIndex = 0;
  27261. actionsByClip[clipUuid] = actionsForClip;
  27262. } else {
  27263. var knownActions = actionsForClip.knownActions;
  27264. action._byClipCacheIndex = knownActions.length;
  27265. knownActions.push(action);
  27266. }
  27267. action._cacheIndex = actions.length;
  27268. actions.push(action);
  27269. actionsForClip.actionByRoot[rootUuid] = action;
  27270. };
  27271. _proto._removeInactiveAction = function _removeInactiveAction(action) {
  27272. var actions = this._actions,
  27273. lastInactiveAction = actions[actions.length - 1],
  27274. cacheIndex = action._cacheIndex;
  27275. lastInactiveAction._cacheIndex = cacheIndex;
  27276. actions[cacheIndex] = lastInactiveAction;
  27277. actions.pop();
  27278. action._cacheIndex = null;
  27279. var clipUuid = action._clip.uuid,
  27280. actionsByClip = this._actionsByClip,
  27281. actionsForClip = actionsByClip[clipUuid],
  27282. knownActionsForClip = actionsForClip.knownActions,
  27283. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27284. byClipCacheIndex = action._byClipCacheIndex;
  27285. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27286. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27287. knownActionsForClip.pop();
  27288. action._byClipCacheIndex = null;
  27289. var actionByRoot = actionsForClip.actionByRoot,
  27290. rootUuid = (action._localRoot || this._root).uuid;
  27291. delete actionByRoot[rootUuid];
  27292. if (knownActionsForClip.length === 0) {
  27293. delete actionsByClip[clipUuid];
  27294. }
  27295. this._removeInactiveBindingsForAction(action);
  27296. };
  27297. _proto._removeInactiveBindingsForAction = function _removeInactiveBindingsForAction(action) {
  27298. var bindings = action._propertyBindings;
  27299. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27300. var binding = bindings[i];
  27301. if (--binding.referenceCount === 0) {
  27302. this._removeInactiveBinding(binding);
  27303. }
  27304. }
  27305. };
  27306. _proto._lendAction = function _lendAction(action) {
  27307. // [ active actions | inactive actions ]
  27308. // [ active actions >| inactive actions ]
  27309. // s a
  27310. // <-swap->
  27311. // a s
  27312. var actions = this._actions,
  27313. prevIndex = action._cacheIndex,
  27314. lastActiveIndex = this._nActiveActions++,
  27315. firstInactiveAction = actions[lastActiveIndex];
  27316. action._cacheIndex = lastActiveIndex;
  27317. actions[lastActiveIndex] = action;
  27318. firstInactiveAction._cacheIndex = prevIndex;
  27319. actions[prevIndex] = firstInactiveAction;
  27320. };
  27321. _proto._takeBackAction = function _takeBackAction(action) {
  27322. // [ active actions | inactive actions ]
  27323. // [ active actions |< inactive actions ]
  27324. // a s
  27325. // <-swap->
  27326. // s a
  27327. var actions = this._actions,
  27328. prevIndex = action._cacheIndex,
  27329. firstInactiveIndex = --this._nActiveActions,
  27330. lastActiveAction = actions[firstInactiveIndex];
  27331. action._cacheIndex = firstInactiveIndex;
  27332. actions[firstInactiveIndex] = action;
  27333. lastActiveAction._cacheIndex = prevIndex;
  27334. actions[prevIndex] = lastActiveAction;
  27335. } // Memory management for PropertyMixer objects
  27336. ;
  27337. _proto._addInactiveBinding = function _addInactiveBinding(binding, rootUuid, trackName) {
  27338. var bindingsByRoot = this._bindingsByRootAndName,
  27339. bindings = this._bindings;
  27340. var bindingByName = bindingsByRoot[rootUuid];
  27341. if (bindingByName === undefined) {
  27342. bindingByName = {};
  27343. bindingsByRoot[rootUuid] = bindingByName;
  27344. }
  27345. bindingByName[trackName] = binding;
  27346. binding._cacheIndex = bindings.length;
  27347. bindings.push(binding);
  27348. };
  27349. _proto._removeInactiveBinding = function _removeInactiveBinding(binding) {
  27350. var bindings = this._bindings,
  27351. propBinding = binding.binding,
  27352. rootUuid = propBinding.rootNode.uuid,
  27353. trackName = propBinding.path,
  27354. bindingsByRoot = this._bindingsByRootAndName,
  27355. bindingByName = bindingsByRoot[rootUuid],
  27356. lastInactiveBinding = bindings[bindings.length - 1],
  27357. cacheIndex = binding._cacheIndex;
  27358. lastInactiveBinding._cacheIndex = cacheIndex;
  27359. bindings[cacheIndex] = lastInactiveBinding;
  27360. bindings.pop();
  27361. delete bindingByName[trackName];
  27362. if (Object.keys(bindingByName).length === 0) {
  27363. delete bindingsByRoot[rootUuid];
  27364. }
  27365. };
  27366. _proto._lendBinding = function _lendBinding(binding) {
  27367. var bindings = this._bindings,
  27368. prevIndex = binding._cacheIndex,
  27369. lastActiveIndex = this._nActiveBindings++,
  27370. firstInactiveBinding = bindings[lastActiveIndex];
  27371. binding._cacheIndex = lastActiveIndex;
  27372. bindings[lastActiveIndex] = binding;
  27373. firstInactiveBinding._cacheIndex = prevIndex;
  27374. bindings[prevIndex] = firstInactiveBinding;
  27375. };
  27376. _proto._takeBackBinding = function _takeBackBinding(binding) {
  27377. var bindings = this._bindings,
  27378. prevIndex = binding._cacheIndex,
  27379. firstInactiveIndex = --this._nActiveBindings,
  27380. lastActiveBinding = bindings[firstInactiveIndex];
  27381. binding._cacheIndex = firstInactiveIndex;
  27382. bindings[firstInactiveIndex] = binding;
  27383. lastActiveBinding._cacheIndex = prevIndex;
  27384. bindings[prevIndex] = lastActiveBinding;
  27385. } // Memory management of Interpolants for weight and time scale
  27386. ;
  27387. _proto._lendControlInterpolant = function _lendControlInterpolant() {
  27388. var interpolants = this._controlInterpolants,
  27389. lastActiveIndex = this._nActiveControlInterpolants++;
  27390. var interpolant = interpolants[lastActiveIndex];
  27391. if (interpolant === undefined) {
  27392. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27393. interpolant.__cacheIndex = lastActiveIndex;
  27394. interpolants[lastActiveIndex] = interpolant;
  27395. }
  27396. return interpolant;
  27397. };
  27398. _proto._takeBackControlInterpolant = function _takeBackControlInterpolant(interpolant) {
  27399. var interpolants = this._controlInterpolants,
  27400. prevIndex = interpolant.__cacheIndex,
  27401. firstInactiveIndex = --this._nActiveControlInterpolants,
  27402. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27403. interpolant.__cacheIndex = firstInactiveIndex;
  27404. interpolants[firstInactiveIndex] = interpolant;
  27405. lastActiveInterpolant.__cacheIndex = prevIndex;
  27406. interpolants[prevIndex] = lastActiveInterpolant;
  27407. } // return an action for a clip optionally using a custom root target
  27408. // object (this method allocates a lot of dynamic memory in case a
  27409. // previously unknown clip/root combination is specified)
  27410. ;
  27411. _proto.clipAction = function clipAction(clip, optionalRoot, blendMode) {
  27412. var root = optionalRoot || this._root,
  27413. rootUuid = root.uuid;
  27414. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27415. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27416. var actionsForClip = this._actionsByClip[clipUuid];
  27417. var prototypeAction = null;
  27418. if (blendMode === undefined) {
  27419. if (clipObject !== null) {
  27420. blendMode = clipObject.blendMode;
  27421. } else {
  27422. blendMode = NormalAnimationBlendMode;
  27423. }
  27424. }
  27425. if (actionsForClip !== undefined) {
  27426. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27427. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27428. return existingAction;
  27429. } // we know the clip, so we don't have to parse all
  27430. // the bindings again but can just copy
  27431. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27432. if (clipObject === null) clipObject = prototypeAction._clip;
  27433. } // clip must be known when specified via string
  27434. if (clipObject === null) return null; // allocate all resources required to run it
  27435. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27436. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27437. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27438. return newAction;
  27439. } // get an existing action
  27440. ;
  27441. _proto.existingAction = function existingAction(clip, optionalRoot) {
  27442. var root = optionalRoot || this._root,
  27443. rootUuid = root.uuid,
  27444. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27445. clipUuid = clipObject ? clipObject.uuid : clip,
  27446. actionsForClip = this._actionsByClip[clipUuid];
  27447. if (actionsForClip !== undefined) {
  27448. return actionsForClip.actionByRoot[rootUuid] || null;
  27449. }
  27450. return null;
  27451. } // deactivates all previously scheduled actions
  27452. ;
  27453. _proto.stopAllAction = function stopAllAction() {
  27454. var actions = this._actions,
  27455. nActions = this._nActiveActions;
  27456. for (var i = nActions - 1; i >= 0; --i) {
  27457. actions[i].stop();
  27458. }
  27459. return this;
  27460. } // advance the time and update apply the animation
  27461. ;
  27462. _proto.update = function update(deltaTime) {
  27463. deltaTime *= this.timeScale;
  27464. var actions = this._actions,
  27465. nActions = this._nActiveActions,
  27466. time = this.time += deltaTime,
  27467. timeDirection = Math.sign(deltaTime),
  27468. accuIndex = this._accuIndex ^= 1; // run active actions
  27469. for (var i = 0; i !== nActions; ++i) {
  27470. var action = actions[i];
  27471. action._update(time, deltaTime, timeDirection, accuIndex);
  27472. } // update scene graph
  27473. var bindings = this._bindings,
  27474. nBindings = this._nActiveBindings;
  27475. for (var _i = 0; _i !== nBindings; ++_i) {
  27476. bindings[_i].apply(accuIndex);
  27477. }
  27478. return this;
  27479. } // Allows you to seek to a specific time in an animation.
  27480. ;
  27481. _proto.setTime = function setTime(timeInSeconds) {
  27482. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27483. for (var i = 0; i < this._actions.length; i++) {
  27484. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27485. }
  27486. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27487. } // return this mixer's root target object
  27488. ;
  27489. _proto.getRoot = function getRoot() {
  27490. return this._root;
  27491. } // free all resources specific to a particular clip
  27492. ;
  27493. _proto.uncacheClip = function uncacheClip(clip) {
  27494. var actions = this._actions,
  27495. clipUuid = clip.uuid,
  27496. actionsByClip = this._actionsByClip,
  27497. actionsForClip = actionsByClip[clipUuid];
  27498. if (actionsForClip !== undefined) {
  27499. // note: just calling _removeInactiveAction would mess up the
  27500. // iteration state and also require updating the state we can
  27501. // just throw away
  27502. var actionsToRemove = actionsForClip.knownActions;
  27503. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27504. var action = actionsToRemove[i];
  27505. this._deactivateAction(action);
  27506. var cacheIndex = action._cacheIndex,
  27507. lastInactiveAction = actions[actions.length - 1];
  27508. action._cacheIndex = null;
  27509. action._byClipCacheIndex = null;
  27510. lastInactiveAction._cacheIndex = cacheIndex;
  27511. actions[cacheIndex] = lastInactiveAction;
  27512. actions.pop();
  27513. this._removeInactiveBindingsForAction(action);
  27514. }
  27515. delete actionsByClip[clipUuid];
  27516. }
  27517. } // free all resources specific to a particular root target object
  27518. ;
  27519. _proto.uncacheRoot = function uncacheRoot(root) {
  27520. var rootUuid = root.uuid,
  27521. actionsByClip = this._actionsByClip;
  27522. for (var clipUuid in actionsByClip) {
  27523. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27524. action = actionByRoot[rootUuid];
  27525. if (action !== undefined) {
  27526. this._deactivateAction(action);
  27527. this._removeInactiveAction(action);
  27528. }
  27529. }
  27530. var bindingsByRoot = this._bindingsByRootAndName,
  27531. bindingByName = bindingsByRoot[rootUuid];
  27532. if (bindingByName !== undefined) {
  27533. for (var trackName in bindingByName) {
  27534. var binding = bindingByName[trackName];
  27535. binding.restoreOriginalState();
  27536. this._removeInactiveBinding(binding);
  27537. }
  27538. }
  27539. } // remove a targeted clip from the cache
  27540. ;
  27541. _proto.uncacheAction = function uncacheAction(clip, optionalRoot) {
  27542. var action = this.existingAction(clip, optionalRoot);
  27543. if (action !== null) {
  27544. this._deactivateAction(action);
  27545. this._removeInactiveAction(action);
  27546. }
  27547. };
  27548. return AnimationMixer;
  27549. }(EventDispatcher);
  27550. AnimationMixer.prototype._controlInterpolantsResultBuffer = new Float32Array(1);
  27551. var Uniform = /*#__PURE__*/function () {
  27552. function Uniform(value) {
  27553. if (typeof value === 'string') {
  27554. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27555. value = arguments[1];
  27556. }
  27557. this.value = value;
  27558. }
  27559. var _proto = Uniform.prototype;
  27560. _proto.clone = function clone() {
  27561. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27562. };
  27563. return Uniform;
  27564. }();
  27565. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27566. InterleavedBuffer.call(this, array, stride);
  27567. this.meshPerAttribute = meshPerAttribute || 1;
  27568. }
  27569. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27570. constructor: InstancedInterleavedBuffer,
  27571. isInstancedInterleavedBuffer: true,
  27572. copy: function copy(source) {
  27573. InterleavedBuffer.prototype.copy.call(this, source);
  27574. this.meshPerAttribute = source.meshPerAttribute;
  27575. return this;
  27576. },
  27577. clone: function clone(data) {
  27578. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27579. ib.meshPerAttribute = this.meshPerAttribute;
  27580. return ib;
  27581. },
  27582. toJSON: function toJSON(data) {
  27583. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27584. json.isInstancedInterleavedBuffer = true;
  27585. json.meshPerAttribute = this.meshPerAttribute;
  27586. return json;
  27587. }
  27588. });
  27589. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27590. this.buffer = buffer;
  27591. this.type = type;
  27592. this.itemSize = itemSize;
  27593. this.elementSize = elementSize;
  27594. this.count = count;
  27595. this.version = 0;
  27596. }
  27597. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27598. set: function set(value) {
  27599. if (value === true) this.version++;
  27600. }
  27601. });
  27602. Object.assign(GLBufferAttribute.prototype, {
  27603. isGLBufferAttribute: true,
  27604. setBuffer: function setBuffer(buffer) {
  27605. this.buffer = buffer;
  27606. return this;
  27607. },
  27608. setType: function setType(type, elementSize) {
  27609. this.type = type;
  27610. this.elementSize = elementSize;
  27611. return this;
  27612. },
  27613. setItemSize: function setItemSize(itemSize) {
  27614. this.itemSize = itemSize;
  27615. return this;
  27616. },
  27617. setCount: function setCount(count) {
  27618. this.count = count;
  27619. return this;
  27620. }
  27621. });
  27622. function Raycaster(origin, direction, near, far) {
  27623. if (near === void 0) {
  27624. near = 0;
  27625. }
  27626. if (far === void 0) {
  27627. far = Infinity;
  27628. }
  27629. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27630. this.near = near;
  27631. this.far = far;
  27632. this.camera = null;
  27633. this.layers = new Layers();
  27634. this.params = {
  27635. Mesh: {},
  27636. Line: {
  27637. threshold: 1
  27638. },
  27639. LOD: {},
  27640. Points: {
  27641. threshold: 1
  27642. },
  27643. Sprite: {}
  27644. };
  27645. Object.defineProperties(this.params, {
  27646. PointCloud: {
  27647. get: function get() {
  27648. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27649. return this.Points;
  27650. }
  27651. }
  27652. });
  27653. }
  27654. function ascSort(a, b) {
  27655. return a.distance - b.distance;
  27656. }
  27657. function _intersectObject(object, raycaster, intersects, recursive) {
  27658. if (object.layers.test(raycaster.layers)) {
  27659. object.raycast(raycaster, intersects);
  27660. }
  27661. if (recursive === true) {
  27662. var children = object.children;
  27663. for (var i = 0, l = children.length; i < l; i++) {
  27664. _intersectObject(children[i], raycaster, intersects, true);
  27665. }
  27666. }
  27667. }
  27668. Object.assign(Raycaster.prototype, {
  27669. set: function set(origin, direction) {
  27670. // direction is assumed to be normalized (for accurate distance calculations)
  27671. this.ray.set(origin, direction);
  27672. },
  27673. setFromCamera: function setFromCamera(coords, camera) {
  27674. if (camera && camera.isPerspectiveCamera) {
  27675. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27676. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27677. this.camera = camera;
  27678. } else if (camera && camera.isOrthographicCamera) {
  27679. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27680. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27681. this.camera = camera;
  27682. } else {
  27683. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27684. }
  27685. },
  27686. intersectObject: function intersectObject(object, recursive, intersects) {
  27687. if (recursive === void 0) {
  27688. recursive = false;
  27689. }
  27690. if (intersects === void 0) {
  27691. intersects = [];
  27692. }
  27693. _intersectObject(object, this, intersects, recursive);
  27694. intersects.sort(ascSort);
  27695. return intersects;
  27696. },
  27697. intersectObjects: function intersectObjects(objects, recursive, intersects) {
  27698. if (recursive === void 0) {
  27699. recursive = false;
  27700. }
  27701. if (intersects === void 0) {
  27702. intersects = [];
  27703. }
  27704. for (var i = 0, l = objects.length; i < l; i++) {
  27705. _intersectObject(objects[i], this, intersects, recursive);
  27706. }
  27707. intersects.sort(ascSort);
  27708. return intersects;
  27709. }
  27710. });
  27711. /**
  27712. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27713. *
  27714. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27715. * The azimuthal angle (theta) is measured from the positive z-axis.
  27716. */
  27717. var Spherical = /*#__PURE__*/function () {
  27718. function Spherical(radius, phi, theta) {
  27719. if (radius === void 0) {
  27720. radius = 1;
  27721. }
  27722. if (phi === void 0) {
  27723. phi = 0;
  27724. }
  27725. if (theta === void 0) {
  27726. theta = 0;
  27727. }
  27728. this.radius = radius;
  27729. this.phi = phi; // polar angle
  27730. this.theta = theta; // azimuthal angle
  27731. return this;
  27732. }
  27733. var _proto = Spherical.prototype;
  27734. _proto.set = function set(radius, phi, theta) {
  27735. this.radius = radius;
  27736. this.phi = phi;
  27737. this.theta = theta;
  27738. return this;
  27739. };
  27740. _proto.copy = function copy(other) {
  27741. this.radius = other.radius;
  27742. this.phi = other.phi;
  27743. this.theta = other.theta;
  27744. return this;
  27745. } // restrict phi to be betwee EPS and PI-EPS
  27746. ;
  27747. _proto.makeSafe = function makeSafe() {
  27748. var EPS = 0.000001;
  27749. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27750. return this;
  27751. };
  27752. _proto.setFromVector3 = function setFromVector3(v) {
  27753. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27754. };
  27755. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27756. this.radius = Math.sqrt(x * x + y * y + z * z);
  27757. if (this.radius === 0) {
  27758. this.theta = 0;
  27759. this.phi = 0;
  27760. } else {
  27761. this.theta = Math.atan2(x, z);
  27762. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27763. }
  27764. return this;
  27765. };
  27766. _proto.clone = function clone() {
  27767. return new this.constructor().copy(this);
  27768. };
  27769. return Spherical;
  27770. }();
  27771. /**
  27772. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27773. */
  27774. var Cylindrical = /*#__PURE__*/function () {
  27775. function Cylindrical(radius, theta, y) {
  27776. if (radius === void 0) {
  27777. radius = 1;
  27778. }
  27779. if (theta === void 0) {
  27780. theta = 0;
  27781. }
  27782. if (y === void 0) {
  27783. y = 0;
  27784. }
  27785. this.radius = radius; // distance from the origin to a point in the x-z plane
  27786. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27787. this.y = y; // height above the x-z plane
  27788. return this;
  27789. }
  27790. var _proto = Cylindrical.prototype;
  27791. _proto.set = function set(radius, theta, y) {
  27792. this.radius = radius;
  27793. this.theta = theta;
  27794. this.y = y;
  27795. return this;
  27796. };
  27797. _proto.copy = function copy(other) {
  27798. this.radius = other.radius;
  27799. this.theta = other.theta;
  27800. this.y = other.y;
  27801. return this;
  27802. };
  27803. _proto.setFromVector3 = function setFromVector3(v) {
  27804. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27805. };
  27806. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27807. this.radius = Math.sqrt(x * x + z * z);
  27808. this.theta = Math.atan2(x, z);
  27809. this.y = y;
  27810. return this;
  27811. };
  27812. _proto.clone = function clone() {
  27813. return new this.constructor().copy(this);
  27814. };
  27815. return Cylindrical;
  27816. }();
  27817. var _vector$8 = /*@__PURE__*/new Vector2();
  27818. var Box2 = /*#__PURE__*/function () {
  27819. function Box2(min, max) {
  27820. if (min === void 0) {
  27821. min = new Vector2(+Infinity, +Infinity);
  27822. }
  27823. if (max === void 0) {
  27824. max = new Vector2(-Infinity, -Infinity);
  27825. }
  27826. this.min = min;
  27827. this.max = max;
  27828. }
  27829. var _proto = Box2.prototype;
  27830. _proto.set = function set(min, max) {
  27831. this.min.copy(min);
  27832. this.max.copy(max);
  27833. return this;
  27834. };
  27835. _proto.setFromPoints = function setFromPoints(points) {
  27836. this.makeEmpty();
  27837. for (var i = 0, il = points.length; i < il; i++) {
  27838. this.expandByPoint(points[i]);
  27839. }
  27840. return this;
  27841. };
  27842. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27843. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27844. this.min.copy(center).sub(halfSize);
  27845. this.max.copy(center).add(halfSize);
  27846. return this;
  27847. };
  27848. _proto.clone = function clone() {
  27849. return new this.constructor().copy(this);
  27850. };
  27851. _proto.copy = function copy(box) {
  27852. this.min.copy(box.min);
  27853. this.max.copy(box.max);
  27854. return this;
  27855. };
  27856. _proto.makeEmpty = function makeEmpty() {
  27857. this.min.x = this.min.y = +Infinity;
  27858. this.max.x = this.max.y = -Infinity;
  27859. return this;
  27860. };
  27861. _proto.isEmpty = function isEmpty() {
  27862. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27863. return this.max.x < this.min.x || this.max.y < this.min.y;
  27864. };
  27865. _proto.getCenter = function getCenter(target) {
  27866. if (target === undefined) {
  27867. console.warn('THREE.Box2: .getCenter() target is now required');
  27868. target = new Vector2();
  27869. }
  27870. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27871. };
  27872. _proto.getSize = function getSize(target) {
  27873. if (target === undefined) {
  27874. console.warn('THREE.Box2: .getSize() target is now required');
  27875. target = new Vector2();
  27876. }
  27877. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27878. };
  27879. _proto.expandByPoint = function expandByPoint(point) {
  27880. this.min.min(point);
  27881. this.max.max(point);
  27882. return this;
  27883. };
  27884. _proto.expandByVector = function expandByVector(vector) {
  27885. this.min.sub(vector);
  27886. this.max.add(vector);
  27887. return this;
  27888. };
  27889. _proto.expandByScalar = function expandByScalar(scalar) {
  27890. this.min.addScalar(-scalar);
  27891. this.max.addScalar(scalar);
  27892. return this;
  27893. };
  27894. _proto.containsPoint = function containsPoint(point) {
  27895. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27896. };
  27897. _proto.containsBox = function containsBox(box) {
  27898. return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y;
  27899. };
  27900. _proto.getParameter = function getParameter(point, target) {
  27901. // This can potentially have a divide by zero if the box
  27902. // has a size dimension of 0.
  27903. if (target === undefined) {
  27904. console.warn('THREE.Box2: .getParameter() target is now required');
  27905. target = new Vector2();
  27906. }
  27907. return target.set((point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y));
  27908. };
  27909. _proto.intersectsBox = function intersectsBox(box) {
  27910. // using 4 splitting planes to rule out intersections
  27911. return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  27912. };
  27913. _proto.clampPoint = function clampPoint(point, target) {
  27914. if (target === undefined) {
  27915. console.warn('THREE.Box2: .clampPoint() target is now required');
  27916. target = new Vector2();
  27917. }
  27918. return target.copy(point).clamp(this.min, this.max);
  27919. };
  27920. _proto.distanceToPoint = function distanceToPoint(point) {
  27921. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27922. return clampedPoint.sub(point).length();
  27923. };
  27924. _proto.intersect = function intersect(box) {
  27925. this.min.max(box.min);
  27926. this.max.min(box.max);
  27927. return this;
  27928. };
  27929. _proto.union = function union(box) {
  27930. this.min.min(box.min);
  27931. this.max.max(box.max);
  27932. return this;
  27933. };
  27934. _proto.translate = function translate(offset) {
  27935. this.min.add(offset);
  27936. this.max.add(offset);
  27937. return this;
  27938. };
  27939. _proto.equals = function equals(box) {
  27940. return box.min.equals(this.min) && box.max.equals(this.max);
  27941. };
  27942. return Box2;
  27943. }();
  27944. Box2.prototype.isBox2 = true;
  27945. var _startP = /*@__PURE__*/new Vector3();
  27946. var _startEnd = /*@__PURE__*/new Vector3();
  27947. var Line3 = /*#__PURE__*/function () {
  27948. function Line3(start, end) {
  27949. if (start === void 0) {
  27950. start = new Vector3();
  27951. }
  27952. if (end === void 0) {
  27953. end = new Vector3();
  27954. }
  27955. this.start = start;
  27956. this.end = end;
  27957. }
  27958. var _proto = Line3.prototype;
  27959. _proto.set = function set(start, end) {
  27960. this.start.copy(start);
  27961. this.end.copy(end);
  27962. return this;
  27963. };
  27964. _proto.copy = function copy(line) {
  27965. this.start.copy(line.start);
  27966. this.end.copy(line.end);
  27967. return this;
  27968. };
  27969. _proto.getCenter = function getCenter(target) {
  27970. if (target === undefined) {
  27971. console.warn('THREE.Line3: .getCenter() target is now required');
  27972. target = new Vector3();
  27973. }
  27974. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27975. };
  27976. _proto.delta = function delta(target) {
  27977. if (target === undefined) {
  27978. console.warn('THREE.Line3: .delta() target is now required');
  27979. target = new Vector3();
  27980. }
  27981. return target.subVectors(this.end, this.start);
  27982. };
  27983. _proto.distanceSq = function distanceSq() {
  27984. return this.start.distanceToSquared(this.end);
  27985. };
  27986. _proto.distance = function distance() {
  27987. return this.start.distanceTo(this.end);
  27988. };
  27989. _proto.at = function at(t, target) {
  27990. if (target === undefined) {
  27991. console.warn('THREE.Line3: .at() target is now required');
  27992. target = new Vector3();
  27993. }
  27994. return this.delta(target).multiplyScalar(t).add(this.start);
  27995. };
  27996. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27997. _startP.subVectors(point, this.start);
  27998. _startEnd.subVectors(this.end, this.start);
  27999. var startEnd2 = _startEnd.dot(_startEnd);
  28000. var startEnd_startP = _startEnd.dot(_startP);
  28001. var t = startEnd_startP / startEnd2;
  28002. if (clampToLine) {
  28003. t = MathUtils.clamp(t, 0, 1);
  28004. }
  28005. return t;
  28006. };
  28007. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  28008. var t = this.closestPointToPointParameter(point, clampToLine);
  28009. if (target === undefined) {
  28010. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  28011. target = new Vector3();
  28012. }
  28013. return this.delta(target).multiplyScalar(t).add(this.start);
  28014. };
  28015. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  28016. this.start.applyMatrix4(matrix);
  28017. this.end.applyMatrix4(matrix);
  28018. return this;
  28019. };
  28020. _proto.equals = function equals(line) {
  28021. return line.start.equals(this.start) && line.end.equals(this.end);
  28022. };
  28023. _proto.clone = function clone() {
  28024. return new this.constructor().copy(this);
  28025. };
  28026. return Line3;
  28027. }();
  28028. function ImmediateRenderObject(material) {
  28029. Object3D.call(this);
  28030. this.material = material;
  28031. this.render = function ()
  28032. /* renderCallback */
  28033. {};
  28034. this.hasPositions = false;
  28035. this.hasNormals = false;
  28036. this.hasColors = false;
  28037. this.hasUvs = false;
  28038. this.positionArray = null;
  28039. this.normalArray = null;
  28040. this.colorArray = null;
  28041. this.uvArray = null;
  28042. this.count = 0;
  28043. }
  28044. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  28045. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  28046. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  28047. var _vector$9 = /*@__PURE__*/new Vector3();
  28048. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  28049. _inheritsLoose(SpotLightHelper, _Object3D);
  28050. function SpotLightHelper(light, color) {
  28051. var _this;
  28052. _this = _Object3D.call(this) || this;
  28053. _this.light = light;
  28054. _this.light.updateMatrixWorld();
  28055. _this.matrix = light.matrixWorld;
  28056. _this.matrixAutoUpdate = false;
  28057. _this.color = color;
  28058. var geometry = new BufferGeometry();
  28059. var positions = [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, -1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, -1, 1];
  28060. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  28061. var p1 = i / l * Math.PI * 2;
  28062. var p2 = j / l * Math.PI * 2;
  28063. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  28064. }
  28065. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28066. var material = new LineBasicMaterial({
  28067. fog: false,
  28068. toneMapped: false
  28069. });
  28070. _this.cone = new LineSegments(geometry, material);
  28071. _this.add(_this.cone);
  28072. _this.update();
  28073. return _this;
  28074. }
  28075. var _proto = SpotLightHelper.prototype;
  28076. _proto.dispose = function dispose() {
  28077. this.cone.geometry.dispose();
  28078. this.cone.material.dispose();
  28079. };
  28080. _proto.update = function update() {
  28081. this.light.updateMatrixWorld();
  28082. var coneLength = this.light.distance ? this.light.distance : 1000;
  28083. var coneWidth = coneLength * Math.tan(this.light.angle);
  28084. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  28085. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  28086. this.cone.lookAt(_vector$9);
  28087. if (this.color !== undefined) {
  28088. this.cone.material.color.set(this.color);
  28089. } else {
  28090. this.cone.material.color.copy(this.light.color);
  28091. }
  28092. };
  28093. return SpotLightHelper;
  28094. }(Object3D);
  28095. var _vector$a = /*@__PURE__*/new Vector3();
  28096. var _boneMatrix = /*@__PURE__*/new Matrix4();
  28097. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  28098. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  28099. _inheritsLoose(SkeletonHelper, _LineSegments);
  28100. function SkeletonHelper(object) {
  28101. var _this;
  28102. var bones = getBoneList(object);
  28103. var geometry = new BufferGeometry();
  28104. var vertices = [];
  28105. var colors = [];
  28106. var color1 = new Color(0, 0, 1);
  28107. var color2 = new Color(0, 1, 0);
  28108. for (var i = 0; i < bones.length; i++) {
  28109. var bone = bones[i];
  28110. if (bone.parent && bone.parent.isBone) {
  28111. vertices.push(0, 0, 0);
  28112. vertices.push(0, 0, 0);
  28113. colors.push(color1.r, color1.g, color1.b);
  28114. colors.push(color2.r, color2.g, color2.b);
  28115. }
  28116. }
  28117. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28118. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28119. var material = new LineBasicMaterial({
  28120. vertexColors: true,
  28121. depthTest: false,
  28122. depthWrite: false,
  28123. toneMapped: false,
  28124. transparent: true
  28125. });
  28126. _this = _LineSegments.call(this, geometry, material) || this;
  28127. _this.type = 'SkeletonHelper';
  28128. _this.isSkeletonHelper = true;
  28129. _this.root = object;
  28130. _this.bones = bones;
  28131. _this.matrix = object.matrixWorld;
  28132. _this.matrixAutoUpdate = false;
  28133. return _this;
  28134. }
  28135. var _proto = SkeletonHelper.prototype;
  28136. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28137. var bones = this.bones;
  28138. var geometry = this.geometry;
  28139. var position = geometry.getAttribute('position');
  28140. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  28141. for (var i = 0, j = 0; i < bones.length; i++) {
  28142. var bone = bones[i];
  28143. if (bone.parent && bone.parent.isBone) {
  28144. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  28145. _vector$a.setFromMatrixPosition(_boneMatrix);
  28146. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  28147. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  28148. _vector$a.setFromMatrixPosition(_boneMatrix);
  28149. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  28150. j += 2;
  28151. }
  28152. }
  28153. geometry.getAttribute('position').needsUpdate = true;
  28154. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28155. };
  28156. return SkeletonHelper;
  28157. }(LineSegments);
  28158. function getBoneList(object) {
  28159. var boneList = [];
  28160. if (object && object.isBone) {
  28161. boneList.push(object);
  28162. }
  28163. for (var i = 0; i < object.children.length; i++) {
  28164. boneList.push.apply(boneList, getBoneList(object.children[i]));
  28165. }
  28166. return boneList;
  28167. }
  28168. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  28169. _inheritsLoose(PointLightHelper, _Mesh);
  28170. function PointLightHelper(light, sphereSize, color) {
  28171. var _this;
  28172. var geometry = new SphereGeometry(sphereSize, 4, 2);
  28173. var material = new MeshBasicMaterial({
  28174. wireframe: true,
  28175. fog: false,
  28176. toneMapped: false
  28177. });
  28178. _this = _Mesh.call(this, geometry, material) || this;
  28179. _this.light = light;
  28180. _this.light.updateMatrixWorld();
  28181. _this.color = color;
  28182. _this.type = 'PointLightHelper';
  28183. _this.matrix = _this.light.matrixWorld;
  28184. _this.matrixAutoUpdate = false;
  28185. _this.update();
  28186. /*
  28187. // TODO: delete this comment?
  28188. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28189. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28190. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28191. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28192. const d = light.distance;
  28193. if ( d === 0.0 ) {
  28194. this.lightDistance.visible = false;
  28195. } else {
  28196. this.lightDistance.scale.set( d, d, d );
  28197. }
  28198. this.add( this.lightDistance );
  28199. */
  28200. return _this;
  28201. }
  28202. var _proto = PointLightHelper.prototype;
  28203. _proto.dispose = function dispose() {
  28204. this.geometry.dispose();
  28205. this.material.dispose();
  28206. };
  28207. _proto.update = function update() {
  28208. if (this.color !== undefined) {
  28209. this.material.color.set(this.color);
  28210. } else {
  28211. this.material.color.copy(this.light.color);
  28212. }
  28213. /*
  28214. const d = this.light.distance;
  28215. if ( d === 0.0 ) {
  28216. this.lightDistance.visible = false;
  28217. } else {
  28218. this.lightDistance.visible = true;
  28219. this.lightDistance.scale.set( d, d, d );
  28220. }
  28221. */
  28222. };
  28223. return PointLightHelper;
  28224. }(Mesh);
  28225. var _vector$b = /*@__PURE__*/new Vector3();
  28226. var _color1 = /*@__PURE__*/new Color();
  28227. var _color2 = /*@__PURE__*/new Color();
  28228. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  28229. _inheritsLoose(HemisphereLightHelper, _Object3D);
  28230. function HemisphereLightHelper(light, size, color) {
  28231. var _this;
  28232. _this = _Object3D.call(this) || this;
  28233. _this.light = light;
  28234. _this.light.updateMatrixWorld();
  28235. _this.matrix = light.matrixWorld;
  28236. _this.matrixAutoUpdate = false;
  28237. _this.color = color;
  28238. var geometry = new OctahedronGeometry(size);
  28239. geometry.rotateY(Math.PI * 0.5);
  28240. _this.material = new MeshBasicMaterial({
  28241. wireframe: true,
  28242. fog: false,
  28243. toneMapped: false
  28244. });
  28245. if (_this.color === undefined) _this.material.vertexColors = true;
  28246. var position = geometry.getAttribute('position');
  28247. var colors = new Float32Array(position.count * 3);
  28248. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  28249. _this.add(new Mesh(geometry, _this.material));
  28250. _this.update();
  28251. return _this;
  28252. }
  28253. var _proto = HemisphereLightHelper.prototype;
  28254. _proto.dispose = function dispose() {
  28255. this.children[0].geometry.dispose();
  28256. this.children[0].material.dispose();
  28257. };
  28258. _proto.update = function update() {
  28259. var mesh = this.children[0];
  28260. if (this.color !== undefined) {
  28261. this.material.color.set(this.color);
  28262. } else {
  28263. var colors = mesh.geometry.getAttribute('color');
  28264. _color1.copy(this.light.color);
  28265. _color2.copy(this.light.groundColor);
  28266. for (var i = 0, l = colors.count; i < l; i++) {
  28267. var color = i < l / 2 ? _color1 : _color2;
  28268. colors.setXYZ(i, color.r, color.g, color.b);
  28269. }
  28270. colors.needsUpdate = true;
  28271. }
  28272. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  28273. };
  28274. return HemisphereLightHelper;
  28275. }(Object3D);
  28276. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  28277. _inheritsLoose(GridHelper, _LineSegments);
  28278. function GridHelper(size, divisions, color1, color2) {
  28279. var _this;
  28280. if (size === void 0) {
  28281. size = 10;
  28282. }
  28283. if (divisions === void 0) {
  28284. divisions = 10;
  28285. }
  28286. if (color1 === void 0) {
  28287. color1 = 0x444444;
  28288. }
  28289. if (color2 === void 0) {
  28290. color2 = 0x888888;
  28291. }
  28292. color1 = new Color(color1);
  28293. color2 = new Color(color2);
  28294. var center = divisions / 2;
  28295. var step = size / divisions;
  28296. var halfSize = size / 2;
  28297. var vertices = [],
  28298. colors = [];
  28299. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28300. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28301. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28302. var color = i === center ? color1 : color2;
  28303. color.toArray(colors, j);
  28304. j += 3;
  28305. color.toArray(colors, j);
  28306. j += 3;
  28307. color.toArray(colors, j);
  28308. j += 3;
  28309. color.toArray(colors, j);
  28310. j += 3;
  28311. }
  28312. var geometry = new BufferGeometry();
  28313. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28314. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28315. var material = new LineBasicMaterial({
  28316. vertexColors: true,
  28317. toneMapped: false
  28318. });
  28319. _this = _LineSegments.call(this, geometry, material) || this;
  28320. _this.type = 'GridHelper';
  28321. return _this;
  28322. }
  28323. return GridHelper;
  28324. }(LineSegments);
  28325. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28326. _inheritsLoose(PolarGridHelper, _LineSegments);
  28327. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28328. var _this;
  28329. if (radius === void 0) {
  28330. radius = 10;
  28331. }
  28332. if (radials === void 0) {
  28333. radials = 16;
  28334. }
  28335. if (circles === void 0) {
  28336. circles = 8;
  28337. }
  28338. if (divisions === void 0) {
  28339. divisions = 64;
  28340. }
  28341. if (color1 === void 0) {
  28342. color1 = 0x444444;
  28343. }
  28344. if (color2 === void 0) {
  28345. color2 = 0x888888;
  28346. }
  28347. color1 = new Color(color1);
  28348. color2 = new Color(color2);
  28349. var vertices = [];
  28350. var colors = []; // create the radials
  28351. for (var i = 0; i <= radials; i++) {
  28352. var v = i / radials * (Math.PI * 2);
  28353. var x = Math.sin(v) * radius;
  28354. var z = Math.cos(v) * radius;
  28355. vertices.push(0, 0, 0);
  28356. vertices.push(x, 0, z);
  28357. var color = i & 1 ? color1 : color2;
  28358. colors.push(color.r, color.g, color.b);
  28359. colors.push(color.r, color.g, color.b);
  28360. } // create the circles
  28361. for (var _i = 0; _i <= circles; _i++) {
  28362. var _color = _i & 1 ? color1 : color2;
  28363. var r = radius - radius / circles * _i;
  28364. for (var j = 0; j < divisions; j++) {
  28365. // first vertex
  28366. var _v = j / divisions * (Math.PI * 2);
  28367. var _x = Math.sin(_v) * r;
  28368. var _z = Math.cos(_v) * r;
  28369. vertices.push(_x, 0, _z);
  28370. colors.push(_color.r, _color.g, _color.b); // second vertex
  28371. _v = (j + 1) / divisions * (Math.PI * 2);
  28372. _x = Math.sin(_v) * r;
  28373. _z = Math.cos(_v) * r;
  28374. vertices.push(_x, 0, _z);
  28375. colors.push(_color.r, _color.g, _color.b);
  28376. }
  28377. }
  28378. var geometry = new BufferGeometry();
  28379. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28380. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28381. var material = new LineBasicMaterial({
  28382. vertexColors: true,
  28383. toneMapped: false
  28384. });
  28385. _this = _LineSegments.call(this, geometry, material) || this;
  28386. _this.type = 'PolarGridHelper';
  28387. return _this;
  28388. }
  28389. return PolarGridHelper;
  28390. }(LineSegments);
  28391. var _v1$6 = /*@__PURE__*/new Vector3();
  28392. var _v2$3 = /*@__PURE__*/new Vector3();
  28393. var _v3$1 = /*@__PURE__*/new Vector3();
  28394. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28395. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28396. function DirectionalLightHelper(light, size, color) {
  28397. var _this;
  28398. _this = _Object3D.call(this) || this;
  28399. _this.light = light;
  28400. _this.light.updateMatrixWorld();
  28401. _this.matrix = light.matrixWorld;
  28402. _this.matrixAutoUpdate = false;
  28403. _this.color = color;
  28404. if (size === undefined) size = 1;
  28405. var geometry = new BufferGeometry();
  28406. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28407. var material = new LineBasicMaterial({
  28408. fog: false,
  28409. toneMapped: false
  28410. });
  28411. _this.lightPlane = new Line(geometry, material);
  28412. _this.add(_this.lightPlane);
  28413. geometry = new BufferGeometry();
  28414. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28415. _this.targetLine = new Line(geometry, material);
  28416. _this.add(_this.targetLine);
  28417. _this.update();
  28418. return _this;
  28419. }
  28420. var _proto = DirectionalLightHelper.prototype;
  28421. _proto.dispose = function dispose() {
  28422. this.lightPlane.geometry.dispose();
  28423. this.lightPlane.material.dispose();
  28424. this.targetLine.geometry.dispose();
  28425. this.targetLine.material.dispose();
  28426. };
  28427. _proto.update = function update() {
  28428. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28429. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28430. _v3$1.subVectors(_v2$3, _v1$6);
  28431. this.lightPlane.lookAt(_v2$3);
  28432. if (this.color !== undefined) {
  28433. this.lightPlane.material.color.set(this.color);
  28434. this.targetLine.material.color.set(this.color);
  28435. } else {
  28436. this.lightPlane.material.color.copy(this.light.color);
  28437. this.targetLine.material.color.copy(this.light.color);
  28438. }
  28439. this.targetLine.lookAt(_v2$3);
  28440. this.targetLine.scale.z = _v3$1.length();
  28441. };
  28442. return DirectionalLightHelper;
  28443. }(Object3D);
  28444. var _vector$c = /*@__PURE__*/new Vector3();
  28445. var _camera = /*@__PURE__*/new Camera();
  28446. /**
  28447. * - shows frustum, line of sight and up of the camera
  28448. * - suitable for fast updates
  28449. * - based on frustum visualization in lightgl.js shadowmap example
  28450. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28451. */
  28452. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28453. _inheritsLoose(CameraHelper, _LineSegments);
  28454. function CameraHelper(camera) {
  28455. var _this;
  28456. var geometry = new BufferGeometry();
  28457. var material = new LineBasicMaterial({
  28458. color: 0xffffff,
  28459. vertexColors: true,
  28460. toneMapped: false
  28461. });
  28462. var vertices = [];
  28463. var colors = [];
  28464. var pointMap = {}; // colors
  28465. var colorFrustum = new Color(0xffaa00);
  28466. var colorCone = new Color(0xff0000);
  28467. var colorUp = new Color(0x00aaff);
  28468. var colorTarget = new Color(0xffffff);
  28469. var colorCross = new Color(0x333333); // near
  28470. addLine('n1', 'n2', colorFrustum);
  28471. addLine('n2', 'n4', colorFrustum);
  28472. addLine('n4', 'n3', colorFrustum);
  28473. addLine('n3', 'n1', colorFrustum); // far
  28474. addLine('f1', 'f2', colorFrustum);
  28475. addLine('f2', 'f4', colorFrustum);
  28476. addLine('f4', 'f3', colorFrustum);
  28477. addLine('f3', 'f1', colorFrustum); // sides
  28478. addLine('n1', 'f1', colorFrustum);
  28479. addLine('n2', 'f2', colorFrustum);
  28480. addLine('n3', 'f3', colorFrustum);
  28481. addLine('n4', 'f4', colorFrustum); // cone
  28482. addLine('p', 'n1', colorCone);
  28483. addLine('p', 'n2', colorCone);
  28484. addLine('p', 'n3', colorCone);
  28485. addLine('p', 'n4', colorCone); // up
  28486. addLine('u1', 'u2', colorUp);
  28487. addLine('u2', 'u3', colorUp);
  28488. addLine('u3', 'u1', colorUp); // target
  28489. addLine('c', 't', colorTarget);
  28490. addLine('p', 'c', colorCross); // cross
  28491. addLine('cn1', 'cn2', colorCross);
  28492. addLine('cn3', 'cn4', colorCross);
  28493. addLine('cf1', 'cf2', colorCross);
  28494. addLine('cf3', 'cf4', colorCross);
  28495. function addLine(a, b, color) {
  28496. addPoint(a, color);
  28497. addPoint(b, color);
  28498. }
  28499. function addPoint(id, color) {
  28500. vertices.push(0, 0, 0);
  28501. colors.push(color.r, color.g, color.b);
  28502. if (pointMap[id] === undefined) {
  28503. pointMap[id] = [];
  28504. }
  28505. pointMap[id].push(vertices.length / 3 - 1);
  28506. }
  28507. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28508. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28509. _this = _LineSegments.call(this, geometry, material) || this;
  28510. _this.type = 'CameraHelper';
  28511. _this.camera = camera;
  28512. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28513. _this.matrix = camera.matrixWorld;
  28514. _this.matrixAutoUpdate = false;
  28515. _this.pointMap = pointMap;
  28516. _this.update();
  28517. return _this;
  28518. }
  28519. var _proto = CameraHelper.prototype;
  28520. _proto.update = function update() {
  28521. var geometry = this.geometry;
  28522. var pointMap = this.pointMap;
  28523. var w = 1,
  28524. h = 1; // we need just camera projection matrix inverse
  28525. // world matrix must be identity
  28526. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28527. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28528. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28529. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28530. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28531. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28532. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28533. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28534. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28535. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28536. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28537. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28538. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28539. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28540. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28541. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28542. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28543. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28544. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28545. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28546. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28547. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28548. geometry.getAttribute('position').needsUpdate = true;
  28549. };
  28550. return CameraHelper;
  28551. }(LineSegments);
  28552. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28553. _vector$c.set(x, y, z).unproject(camera);
  28554. var points = pointMap[point];
  28555. if (points !== undefined) {
  28556. var position = geometry.getAttribute('position');
  28557. for (var i = 0, l = points.length; i < l; i++) {
  28558. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28559. }
  28560. }
  28561. }
  28562. var _box$3 = /*@__PURE__*/new Box3();
  28563. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28564. _inheritsLoose(BoxHelper, _LineSegments);
  28565. function BoxHelper(object, color) {
  28566. var _this;
  28567. if (color === void 0) {
  28568. color = 0xffff00;
  28569. }
  28570. var indices = new Uint16Array([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
  28571. var positions = new Float32Array(8 * 3);
  28572. var geometry = new BufferGeometry();
  28573. geometry.setIndex(new BufferAttribute(indices, 1));
  28574. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28575. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28576. color: color,
  28577. toneMapped: false
  28578. })) || this;
  28579. _this.object = object;
  28580. _this.type = 'BoxHelper';
  28581. _this.matrixAutoUpdate = false;
  28582. _this.update();
  28583. return _this;
  28584. }
  28585. var _proto = BoxHelper.prototype;
  28586. _proto.update = function update(object) {
  28587. if (object !== undefined) {
  28588. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28589. }
  28590. if (this.object !== undefined) {
  28591. _box$3.setFromObject(this.object);
  28592. }
  28593. if (_box$3.isEmpty()) return;
  28594. var min = _box$3.min;
  28595. var max = _box$3.max;
  28596. /*
  28597. 5____4
  28598. 1/___0/|
  28599. | 6__|_7
  28600. 2/___3/
  28601. 0: max.x, max.y, max.z
  28602. 1: min.x, max.y, max.z
  28603. 2: min.x, min.y, max.z
  28604. 3: max.x, min.y, max.z
  28605. 4: max.x, max.y, min.z
  28606. 5: min.x, max.y, min.z
  28607. 6: min.x, min.y, min.z
  28608. 7: max.x, min.y, min.z
  28609. */
  28610. var position = this.geometry.attributes.position;
  28611. var array = position.array;
  28612. array[0] = max.x;
  28613. array[1] = max.y;
  28614. array[2] = max.z;
  28615. array[3] = min.x;
  28616. array[4] = max.y;
  28617. array[5] = max.z;
  28618. array[6] = min.x;
  28619. array[7] = min.y;
  28620. array[8] = max.z;
  28621. array[9] = max.x;
  28622. array[10] = min.y;
  28623. array[11] = max.z;
  28624. array[12] = max.x;
  28625. array[13] = max.y;
  28626. array[14] = min.z;
  28627. array[15] = min.x;
  28628. array[16] = max.y;
  28629. array[17] = min.z;
  28630. array[18] = min.x;
  28631. array[19] = min.y;
  28632. array[20] = min.z;
  28633. array[21] = max.x;
  28634. array[22] = min.y;
  28635. array[23] = min.z;
  28636. position.needsUpdate = true;
  28637. this.geometry.computeBoundingSphere();
  28638. };
  28639. _proto.setFromObject = function setFromObject(object) {
  28640. this.object = object;
  28641. this.update();
  28642. return this;
  28643. };
  28644. _proto.copy = function copy(source) {
  28645. LineSegments.prototype.copy.call(this, source);
  28646. this.object = source.object;
  28647. return this;
  28648. };
  28649. return BoxHelper;
  28650. }(LineSegments);
  28651. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28652. _inheritsLoose(Box3Helper, _LineSegments);
  28653. function Box3Helper(box, color) {
  28654. var _this;
  28655. if (color === void 0) {
  28656. color = 0xffff00;
  28657. }
  28658. var indices = new Uint16Array([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7]);
  28659. var positions = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1];
  28660. var geometry = new BufferGeometry();
  28661. geometry.setIndex(new BufferAttribute(indices, 1));
  28662. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28663. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28664. color: color,
  28665. toneMapped: false
  28666. })) || this;
  28667. _this.box = box;
  28668. _this.type = 'Box3Helper';
  28669. _this.geometry.computeBoundingSphere();
  28670. return _this;
  28671. }
  28672. var _proto = Box3Helper.prototype;
  28673. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28674. var box = this.box;
  28675. if (box.isEmpty()) return;
  28676. box.getCenter(this.position);
  28677. box.getSize(this.scale);
  28678. this.scale.multiplyScalar(0.5);
  28679. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28680. };
  28681. return Box3Helper;
  28682. }(LineSegments);
  28683. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28684. _inheritsLoose(PlaneHelper, _Line);
  28685. function PlaneHelper(plane, size, hex) {
  28686. var _this;
  28687. if (size === void 0) {
  28688. size = 1;
  28689. }
  28690. if (hex === void 0) {
  28691. hex = 0xffff00;
  28692. }
  28693. var color = hex;
  28694. var positions = [1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0];
  28695. var geometry = new BufferGeometry();
  28696. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28697. geometry.computeBoundingSphere();
  28698. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28699. color: color,
  28700. toneMapped: false
  28701. })) || this;
  28702. _this.type = 'PlaneHelper';
  28703. _this.plane = plane;
  28704. _this.size = size;
  28705. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28706. var geometry2 = new BufferGeometry();
  28707. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28708. geometry2.computeBoundingSphere();
  28709. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28710. color: color,
  28711. opacity: 0.2,
  28712. transparent: true,
  28713. depthWrite: false,
  28714. toneMapped: false
  28715. })));
  28716. return _this;
  28717. }
  28718. var _proto = PlaneHelper.prototype;
  28719. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28720. var scale = -this.plane.constant;
  28721. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28722. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28723. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28724. this.lookAt(this.plane.normal);
  28725. _Line.prototype.updateMatrixWorld.call(this, force);
  28726. };
  28727. return PlaneHelper;
  28728. }(Line);
  28729. var _axis = /*@__PURE__*/new Vector3();
  28730. var _lineGeometry, _coneGeometry;
  28731. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28732. _inheritsLoose(ArrowHelper, _Object3D);
  28733. // dir is assumed to be normalized
  28734. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28735. var _this;
  28736. if (dir === void 0) {
  28737. dir = new Vector3(0, 0, 1);
  28738. }
  28739. if (origin === void 0) {
  28740. origin = new Vector3(0, 0, 0);
  28741. }
  28742. if (length === void 0) {
  28743. length = 1;
  28744. }
  28745. if (color === void 0) {
  28746. color = 0xffff00;
  28747. }
  28748. if (headLength === void 0) {
  28749. headLength = length * 0.2;
  28750. }
  28751. if (headWidth === void 0) {
  28752. headWidth = headLength * 0.2;
  28753. }
  28754. _this = _Object3D.call(this) || this;
  28755. _this.type = 'ArrowHelper';
  28756. if (_lineGeometry === undefined) {
  28757. _lineGeometry = new BufferGeometry();
  28758. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28759. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28760. _coneGeometry.translate(0, -0.5, 0);
  28761. }
  28762. _this.position.copy(origin);
  28763. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28764. color: color,
  28765. toneMapped: false
  28766. }));
  28767. _this.line.matrixAutoUpdate = false;
  28768. _this.add(_this.line);
  28769. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28770. color: color,
  28771. toneMapped: false
  28772. }));
  28773. _this.cone.matrixAutoUpdate = false;
  28774. _this.add(_this.cone);
  28775. _this.setDirection(dir);
  28776. _this.setLength(length, headLength, headWidth);
  28777. return _this;
  28778. }
  28779. var _proto = ArrowHelper.prototype;
  28780. _proto.setDirection = function setDirection(dir) {
  28781. // dir is assumed to be normalized
  28782. if (dir.y > 0.99999) {
  28783. this.quaternion.set(0, 0, 0, 1);
  28784. } else if (dir.y < -0.99999) {
  28785. this.quaternion.set(1, 0, 0, 0);
  28786. } else {
  28787. _axis.set(dir.z, 0, -dir.x).normalize();
  28788. var radians = Math.acos(dir.y);
  28789. this.quaternion.setFromAxisAngle(_axis, radians);
  28790. }
  28791. };
  28792. _proto.setLength = function setLength(length, headLength, headWidth) {
  28793. if (headLength === void 0) {
  28794. headLength = length * 0.2;
  28795. }
  28796. if (headWidth === void 0) {
  28797. headWidth = headLength * 0.2;
  28798. }
  28799. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28800. this.line.updateMatrix();
  28801. this.cone.scale.set(headWidth, headLength, headWidth);
  28802. this.cone.position.y = length;
  28803. this.cone.updateMatrix();
  28804. };
  28805. _proto.setColor = function setColor(color) {
  28806. this.line.material.color.set(color);
  28807. this.cone.material.color.set(color);
  28808. };
  28809. _proto.copy = function copy(source) {
  28810. _Object3D.prototype.copy.call(this, source, false);
  28811. this.line.copy(source.line);
  28812. this.cone.copy(source.cone);
  28813. return this;
  28814. };
  28815. return ArrowHelper;
  28816. }(Object3D);
  28817. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28818. _inheritsLoose(AxesHelper, _LineSegments);
  28819. function AxesHelper(size) {
  28820. var _this;
  28821. if (size === void 0) {
  28822. size = 1;
  28823. }
  28824. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28825. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28826. var geometry = new BufferGeometry();
  28827. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28828. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28829. var material = new LineBasicMaterial({
  28830. vertexColors: true,
  28831. toneMapped: false
  28832. });
  28833. _this = _LineSegments.call(this, geometry, material) || this;
  28834. _this.type = 'AxesHelper';
  28835. return _this;
  28836. }
  28837. return AxesHelper;
  28838. }(LineSegments);
  28839. var _floatView = new Float32Array(1);
  28840. var _int32View = new Int32Array(_floatView.buffer);
  28841. var DataUtils = {
  28842. // Converts float32 to float16 (stored as uint16 value).
  28843. toHalfFloat: function toHalfFloat(val) {
  28844. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28845. /* This method is faster than the OpenEXR implementation (very often
  28846. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28847. * by James Tursa?s half-precision code. */
  28848. _floatView[0] = val;
  28849. var x = _int32View[0];
  28850. var bits = x >> 16 & 0x8000;
  28851. /* Get the sign */
  28852. var m = x >> 12 & 0x07ff;
  28853. /* Keep one extra bit for rounding */
  28854. var e = x >> 23 & 0xff;
  28855. /* Using int is faster here */
  28856. /* If zero, or denormal, or exponent underflows too much for a denormal
  28857. * half, return signed zero. */
  28858. if (e < 103) return bits;
  28859. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28860. if (e > 142) {
  28861. bits |= 0x7c00;
  28862. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28863. * not Inf, so make sure we set one mantissa bit too. */
  28864. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28865. return bits;
  28866. }
  28867. /* If exponent underflows but not too much, return a denormal */
  28868. if (e < 113) {
  28869. m |= 0x0800;
  28870. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28871. * to 1, which is OK. */
  28872. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28873. return bits;
  28874. }
  28875. bits |= e - 112 << 10 | m >> 1;
  28876. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28877. * the exponent, which is OK. */
  28878. bits += m & 1;
  28879. return bits;
  28880. }
  28881. };
  28882. var _ENCODINGS;
  28883. var LOD_MIN = 4;
  28884. var LOD_MAX = 8;
  28885. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28886. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28887. // geometric shadowing function. These sigma values squared must match the
  28888. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28889. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28890. var TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length; // The maximum length of the blur for loop. Smaller sigmas will use fewer
  28891. // samples and exit early, but not recompile the shader.
  28892. var MAX_SAMPLES = 20;
  28893. var ENCODINGS = (_ENCODINGS = {}, _ENCODINGS[LinearEncoding] = 0, _ENCODINGS[sRGBEncoding] = 1, _ENCODINGS[RGBEEncoding] = 2, _ENCODINGS[RGBM7Encoding] = 3, _ENCODINGS[RGBM16Encoding] = 4, _ENCODINGS[RGBDEncoding] = 5, _ENCODINGS[GammaEncoding] = 6, _ENCODINGS);
  28894. var backgroundMaterial = new MeshBasicMaterial({
  28895. side: BackSide,
  28896. depthWrite: false,
  28897. depthTest: false
  28898. });
  28899. var backgroundBox = new Mesh(new BoxGeometry(), backgroundMaterial);
  28900. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28901. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28902. _lodPlanes = _createPlanes2._lodPlanes,
  28903. _sizeLods = _createPlanes2._sizeLods,
  28904. _sigmas = _createPlanes2._sigmas;
  28905. var _clearColor = /*@__PURE__*/new Color();
  28906. var _oldTarget = null; // Golden Ratio
  28907. var PHI = (1 + Math.sqrt(5)) / 2;
  28908. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28909. // same axis), used as axis directions evenly spread on a sphere.
  28910. var _axisDirections = [/*@__PURE__*/new Vector3(1, 1, 1), /*@__PURE__*/new Vector3(-1, 1, 1), /*@__PURE__*/new Vector3(1, 1, -1), /*@__PURE__*/new Vector3(-1, 1, -1), /*@__PURE__*/new Vector3(0, PHI, INV_PHI), /*@__PURE__*/new Vector3(0, PHI, -INV_PHI), /*@__PURE__*/new Vector3(INV_PHI, 0, PHI), /*@__PURE__*/new Vector3(-INV_PHI, 0, PHI), /*@__PURE__*/new Vector3(PHI, INV_PHI, 0), /*@__PURE__*/new Vector3(-PHI, INV_PHI, 0)];
  28911. /**
  28912. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28913. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28914. * blur to be quickly accessed based on material roughness. It is packed into a
  28915. * special CubeUV format that allows us to perform custom interpolation so that
  28916. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28917. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28918. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28919. * higher roughness levels. In this way we maintain resolution to smoothly
  28920. * interpolate diffuse lighting while limiting sampling computation.
  28921. */
  28922. function convertLinearToRGBE(color) {
  28923. var maxComponent = Math.max(color.r, color.g, color.b);
  28924. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28925. color.multiplyScalar(Math.pow(2.0, -fExp));
  28926. var alpha = (fExp + 128.0) / 255.0;
  28927. return alpha;
  28928. }
  28929. var PMREMGenerator = /*#__PURE__*/function () {
  28930. function PMREMGenerator(renderer) {
  28931. this._renderer = renderer;
  28932. this._pingPongRenderTarget = null;
  28933. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28934. this._equirectShader = null;
  28935. this._cubemapShader = null;
  28936. this._compileMaterial(this._blurMaterial);
  28937. }
  28938. /**
  28939. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28940. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28941. * in radians to be applied to the scene before PMREM generation. Optional near
  28942. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28943. * is placed at the origin).
  28944. */
  28945. var _proto = PMREMGenerator.prototype;
  28946. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28947. if (sigma === void 0) {
  28948. sigma = 0;
  28949. }
  28950. if (near === void 0) {
  28951. near = 0.1;
  28952. }
  28953. if (far === void 0) {
  28954. far = 100;
  28955. }
  28956. _oldTarget = this._renderer.getRenderTarget();
  28957. var cubeUVRenderTarget = this._allocateTargets();
  28958. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28959. if (sigma > 0) {
  28960. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28961. }
  28962. this._applyPMREM(cubeUVRenderTarget);
  28963. this._cleanup(cubeUVRenderTarget);
  28964. return cubeUVRenderTarget;
  28965. }
  28966. /**
  28967. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28968. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28969. * as this matches best with the 256 x 256 cubemap output.
  28970. */
  28971. ;
  28972. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28973. return this._fromTexture(equirectangular);
  28974. }
  28975. /**
  28976. * Generates a PMREM from an cubemap texture, which can be either LDR
  28977. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28978. * as this matches best with the 256 x 256 cubemap output.
  28979. */
  28980. ;
  28981. _proto.fromCubemap = function fromCubemap(cubemap) {
  28982. return this._fromTexture(cubemap);
  28983. }
  28984. /**
  28985. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28986. * your texture's network fetch for increased concurrency.
  28987. */
  28988. ;
  28989. _proto.compileCubemapShader = function compileCubemapShader() {
  28990. if (this._cubemapShader === null) {
  28991. this._cubemapShader = _getCubemapShader();
  28992. this._compileMaterial(this._cubemapShader);
  28993. }
  28994. }
  28995. /**
  28996. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28997. * your texture's network fetch for increased concurrency.
  28998. */
  28999. ;
  29000. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  29001. if (this._equirectShader === null) {
  29002. this._equirectShader = _getEquirectShader();
  29003. this._compileMaterial(this._equirectShader);
  29004. }
  29005. }
  29006. /**
  29007. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  29008. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  29009. * one of them will cause any others to also become unusable.
  29010. */
  29011. ;
  29012. _proto.dispose = function dispose() {
  29013. this._blurMaterial.dispose();
  29014. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  29015. if (this._equirectShader !== null) this._equirectShader.dispose();
  29016. for (var i = 0; i < _lodPlanes.length; i++) {
  29017. _lodPlanes[i].dispose();
  29018. }
  29019. } // private interface
  29020. ;
  29021. _proto._cleanup = function _cleanup(outputTarget) {
  29022. this._pingPongRenderTarget.dispose();
  29023. this._renderer.setRenderTarget(_oldTarget);
  29024. outputTarget.scissorTest = false;
  29025. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  29026. };
  29027. _proto._fromTexture = function _fromTexture(texture) {
  29028. _oldTarget = this._renderer.getRenderTarget();
  29029. var cubeUVRenderTarget = this._allocateTargets(texture);
  29030. this._textureToCubeUV(texture, cubeUVRenderTarget);
  29031. this._applyPMREM(cubeUVRenderTarget);
  29032. this._cleanup(cubeUVRenderTarget);
  29033. return cubeUVRenderTarget;
  29034. };
  29035. _proto._allocateTargets = function _allocateTargets(texture) {
  29036. // warning: null texture is valid
  29037. var params = {
  29038. magFilter: NearestFilter,
  29039. minFilter: NearestFilter,
  29040. generateMipmaps: false,
  29041. type: UnsignedByteType,
  29042. format: RGBEFormat,
  29043. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  29044. depthBuffer: false
  29045. };
  29046. var cubeUVRenderTarget = _createRenderTarget(params);
  29047. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  29048. this._pingPongRenderTarget = _createRenderTarget(params);
  29049. return cubeUVRenderTarget;
  29050. };
  29051. _proto._compileMaterial = function _compileMaterial(material) {
  29052. var tmpMesh = new Mesh(_lodPlanes[0], material);
  29053. this._renderer.compile(tmpMesh, _flatCamera);
  29054. };
  29055. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  29056. var fov = 90;
  29057. var aspect = 1;
  29058. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  29059. var upSign = [1, -1, 1, 1, 1, 1];
  29060. var forwardSign = [1, 1, 1, -1, -1, -1];
  29061. var renderer = this._renderer;
  29062. var originalAutoClear = renderer.autoClear;
  29063. var outputEncoding = renderer.outputEncoding;
  29064. var toneMapping = renderer.toneMapping;
  29065. renderer.getClearColor(_clearColor);
  29066. renderer.toneMapping = NoToneMapping;
  29067. renderer.outputEncoding = LinearEncoding;
  29068. renderer.autoClear = false;
  29069. var useSolidColor = false;
  29070. var background = scene.background;
  29071. if (background) {
  29072. if (background.isColor) {
  29073. backgroundMaterial.color.copy(background).convertSRGBToLinear();
  29074. scene.background = null;
  29075. var alpha = convertLinearToRGBE(backgroundMaterial.color);
  29076. backgroundMaterial.opacity = alpha;
  29077. useSolidColor = true;
  29078. }
  29079. } else {
  29080. backgroundMaterial.color.copy(_clearColor).convertSRGBToLinear();
  29081. var _alpha = convertLinearToRGBE(backgroundMaterial.color);
  29082. backgroundMaterial.opacity = _alpha;
  29083. useSolidColor = true;
  29084. }
  29085. for (var i = 0; i < 6; i++) {
  29086. var col = i % 3;
  29087. if (col == 0) {
  29088. cubeCamera.up.set(0, upSign[i], 0);
  29089. cubeCamera.lookAt(forwardSign[i], 0, 0);
  29090. } else if (col == 1) {
  29091. cubeCamera.up.set(0, 0, upSign[i]);
  29092. cubeCamera.lookAt(0, forwardSign[i], 0);
  29093. } else {
  29094. cubeCamera.up.set(0, upSign[i], 0);
  29095. cubeCamera.lookAt(0, 0, forwardSign[i]);
  29096. }
  29097. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  29098. renderer.setRenderTarget(cubeUVRenderTarget);
  29099. if (useSolidColor) {
  29100. renderer.render(backgroundBox, cubeCamera);
  29101. }
  29102. renderer.render(scene, cubeCamera);
  29103. }
  29104. renderer.toneMapping = toneMapping;
  29105. renderer.outputEncoding = outputEncoding;
  29106. renderer.autoClear = originalAutoClear;
  29107. };
  29108. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  29109. var renderer = this._renderer;
  29110. if (texture.isCubeTexture) {
  29111. if (this._cubemapShader == null) {
  29112. this._cubemapShader = _getCubemapShader();
  29113. }
  29114. } else {
  29115. if (this._equirectShader == null) {
  29116. this._equirectShader = _getEquirectShader();
  29117. }
  29118. }
  29119. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  29120. var mesh = new Mesh(_lodPlanes[0], material);
  29121. var uniforms = material.uniforms;
  29122. uniforms['envMap'].value = texture;
  29123. if (!texture.isCubeTexture) {
  29124. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  29125. }
  29126. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  29127. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  29128. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  29129. renderer.setRenderTarget(cubeUVRenderTarget);
  29130. renderer.render(mesh, _flatCamera);
  29131. };
  29132. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  29133. var renderer = this._renderer;
  29134. var autoClear = renderer.autoClear;
  29135. renderer.autoClear = false;
  29136. for (var i = 1; i < TOTAL_LODS; i++) {
  29137. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  29138. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  29139. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  29140. }
  29141. renderer.autoClear = autoClear;
  29142. }
  29143. /**
  29144. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  29145. * vertically and horizontally, but this breaks down on a cube. Here we apply
  29146. * the blur latitudinally (around the poles), and then longitudinally (towards
  29147. * the poles) to approximate the orthogonally-separable blur. It is least
  29148. * accurate at the poles, but still does a decent job.
  29149. */
  29150. ;
  29151. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  29152. var pingPongRenderTarget = this._pingPongRenderTarget;
  29153. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  29154. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  29155. };
  29156. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  29157. var renderer = this._renderer;
  29158. var blurMaterial = this._blurMaterial;
  29159. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  29160. console.error('blur direction must be either latitudinal or longitudinal!');
  29161. } // Number of standard deviations at which to cut off the discrete approximation.
  29162. var STANDARD_DEVIATIONS = 3;
  29163. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  29164. var blurUniforms = blurMaterial.uniforms;
  29165. var pixels = _sizeLods[lodIn] - 1;
  29166. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  29167. var sigmaPixels = sigmaRadians / radiansPerPixel;
  29168. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  29169. if (samples > MAX_SAMPLES) {
  29170. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  29171. }
  29172. var weights = [];
  29173. var sum = 0;
  29174. for (var i = 0; i < MAX_SAMPLES; ++i) {
  29175. var _x = i / sigmaPixels;
  29176. var weight = Math.exp(-_x * _x / 2);
  29177. weights.push(weight);
  29178. if (i == 0) {
  29179. sum += weight;
  29180. } else if (i < samples) {
  29181. sum += 2 * weight;
  29182. }
  29183. }
  29184. for (var _i = 0; _i < weights.length; _i++) {
  29185. weights[_i] = weights[_i] / sum;
  29186. }
  29187. blurUniforms['envMap'].value = targetIn.texture;
  29188. blurUniforms['samples'].value = samples;
  29189. blurUniforms['weights'].value = weights;
  29190. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  29191. if (poleAxis) {
  29192. blurUniforms['poleAxis'].value = poleAxis;
  29193. }
  29194. blurUniforms['dTheta'].value = radiansPerPixel;
  29195. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  29196. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29197. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  29198. var outputSize = _sizeLods[lodOut];
  29199. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  29200. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  29201. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  29202. renderer.setRenderTarget(targetOut);
  29203. renderer.render(blurMesh, _flatCamera);
  29204. };
  29205. return PMREMGenerator;
  29206. }();
  29207. function _isLDR(texture) {
  29208. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  29209. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  29210. }
  29211. function _createPlanes() {
  29212. var _lodPlanes = [];
  29213. var _sizeLods = [];
  29214. var _sigmas = [];
  29215. var lod = LOD_MAX;
  29216. for (var i = 0; i < TOTAL_LODS; i++) {
  29217. var sizeLod = Math.pow(2, lod);
  29218. _sizeLods.push(sizeLod);
  29219. var sigma = 1.0 / sizeLod;
  29220. if (i > LOD_MAX - LOD_MIN) {
  29221. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  29222. } else if (i == 0) {
  29223. sigma = 0;
  29224. }
  29225. _sigmas.push(sigma);
  29226. var texelSize = 1.0 / (sizeLod - 1);
  29227. var min = -texelSize / 2;
  29228. var max = 1 + texelSize / 2;
  29229. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  29230. var cubeFaces = 6;
  29231. var vertices = 6;
  29232. var positionSize = 3;
  29233. var uvSize = 2;
  29234. var faceIndexSize = 1;
  29235. var position = new Float32Array(positionSize * vertices * cubeFaces);
  29236. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  29237. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  29238. for (var face = 0; face < cubeFaces; face++) {
  29239. var x = face % 3 * 2 / 3 - 1;
  29240. var y = face > 2 ? 0 : -1;
  29241. var coordinates = [x, y, 0, x + 2 / 3, y, 0, x + 2 / 3, y + 1, 0, x, y, 0, x + 2 / 3, y + 1, 0, x, y + 1, 0];
  29242. position.set(coordinates, positionSize * vertices * face);
  29243. uv.set(uv1, uvSize * vertices * face);
  29244. var fill = [face, face, face, face, face, face];
  29245. faceIndex.set(fill, faceIndexSize * vertices * face);
  29246. }
  29247. var planes = new BufferGeometry();
  29248. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  29249. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  29250. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  29251. _lodPlanes.push(planes);
  29252. if (lod > LOD_MIN) {
  29253. lod--;
  29254. }
  29255. }
  29256. return {
  29257. _lodPlanes: _lodPlanes,
  29258. _sizeLods: _sizeLods,
  29259. _sigmas: _sigmas
  29260. };
  29261. }
  29262. function _createRenderTarget(params) {
  29263. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  29264. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29265. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29266. cubeUVRenderTarget.scissorTest = true;
  29267. return cubeUVRenderTarget;
  29268. }
  29269. function _setViewport(target, x, y, width, height) {
  29270. target.viewport.set(x, y, width, height);
  29271. target.scissor.set(x, y, width, height);
  29272. }
  29273. function _getBlurShader(maxSamples) {
  29274. var weights = new Float32Array(maxSamples);
  29275. var poleAxis = new Vector3(0, 1, 0);
  29276. var shaderMaterial = new RawShaderMaterial({
  29277. name: 'SphericalGaussianBlur',
  29278. defines: {
  29279. 'n': maxSamples
  29280. },
  29281. uniforms: {
  29282. 'envMap': {
  29283. value: null
  29284. },
  29285. 'samples': {
  29286. value: 1
  29287. },
  29288. 'weights': {
  29289. value: weights
  29290. },
  29291. 'latitudinal': {
  29292. value: false
  29293. },
  29294. 'dTheta': {
  29295. value: 0
  29296. },
  29297. 'mipInt': {
  29298. value: 0
  29299. },
  29300. 'poleAxis': {
  29301. value: poleAxis
  29302. },
  29303. 'inputEncoding': {
  29304. value: ENCODINGS[LinearEncoding]
  29305. },
  29306. 'outputEncoding': {
  29307. value: ENCODINGS[LinearEncoding]
  29308. }
  29309. },
  29310. vertexShader: _getCommonVertexShader(),
  29311. fragmentShader:
  29312. /* glsl */
  29313. "\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t" + _getEncodings() + "\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t",
  29314. blending: NoBlending,
  29315. depthTest: false,
  29316. depthWrite: false
  29317. });
  29318. return shaderMaterial;
  29319. }
  29320. function _getEquirectShader() {
  29321. var texelSize = new Vector2(1, 1);
  29322. var shaderMaterial = new RawShaderMaterial({
  29323. name: 'EquirectangularToCubeUV',
  29324. uniforms: {
  29325. 'envMap': {
  29326. value: null
  29327. },
  29328. 'texelSize': {
  29329. value: texelSize
  29330. },
  29331. 'inputEncoding': {
  29332. value: ENCODINGS[LinearEncoding]
  29333. },
  29334. 'outputEncoding': {
  29335. value: ENCODINGS[LinearEncoding]
  29336. }
  29337. },
  29338. vertexShader: _getCommonVertexShader(),
  29339. fragmentShader:
  29340. /* glsl */
  29341. "\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform vec2 texelSize;\n\n\t\t\t" + _getEncodings() + "\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tvec2 f = fract( uv / texelSize - 0.5 );\n\t\t\t\tuv -= f * texelSize;\n\t\t\t\tvec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x += texelSize.x;\n\t\t\t\tvec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.y += texelSize.y;\n\t\t\t\tvec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x -= texelSize.x;\n\t\t\t\tvec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\n\t\t\t\tvec3 tm = mix( tl, tr, f.x );\n\t\t\t\tvec3 bm = mix( bl, br, f.x );\n\t\t\t\tgl_FragColor.rgb = mix( tm, bm, f.y );\n\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t",
  29342. blending: NoBlending,
  29343. depthTest: false,
  29344. depthWrite: false
  29345. });
  29346. return shaderMaterial;
  29347. }
  29348. function _getCubemapShader() {
  29349. var shaderMaterial = new RawShaderMaterial({
  29350. name: 'CubemapToCubeUV',
  29351. uniforms: {
  29352. 'envMap': {
  29353. value: null
  29354. },
  29355. 'inputEncoding': {
  29356. value: ENCODINGS[LinearEncoding]
  29357. },
  29358. 'outputEncoding': {
  29359. value: ENCODINGS[LinearEncoding]
  29360. }
  29361. },
  29362. vertexShader: _getCommonVertexShader(),
  29363. fragmentShader:
  29364. /* glsl */
  29365. "\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\t" + _getEncodings() + "\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) ).rgb;\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t",
  29366. blending: NoBlending,
  29367. depthTest: false,
  29368. depthWrite: false
  29369. });
  29370. return shaderMaterial;
  29371. }
  29372. function _getCommonVertexShader() {
  29373. return (
  29374. /* glsl */
  29375. "\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t"
  29376. );
  29377. }
  29378. function _getEncodings() {
  29379. return (
  29380. /* glsl */
  29381. "\n\n\t\tuniform int inputEncoding;\n\t\tuniform int outputEncoding;\n\n\t\t#include <encodings_pars_fragment>\n\n\t\tvec4 inputTexelToLinear( vec4 value ) {\n\n\t\t\tif ( inputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( inputEncoding == 1 ) {\n\n\t\t\t\treturn sRGBToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 2 ) {\n\n\t\t\t\treturn RGBEToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 3 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 7.0 );\n\n\t\t\t} else if ( inputEncoding == 4 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 16.0 );\n\n\t\t\t} else if ( inputEncoding == 5 ) {\n\n\t\t\t\treturn RGBDToLinear( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn GammaToLinear( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 linearToOutputTexel( vec4 value ) {\n\n\t\t\tif ( outputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( outputEncoding == 1 ) {\n\n\t\t\t\treturn LinearTosRGB( value );\n\n\t\t\t} else if ( outputEncoding == 2 ) {\n\n\t\t\t\treturn LinearToRGBE( value );\n\n\t\t\t} else if ( outputEncoding == 3 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 7.0 );\n\n\t\t\t} else if ( outputEncoding == 4 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 16.0 );\n\n\t\t\t} else if ( outputEncoding == 5 ) {\n\n\t\t\t\treturn LinearToRGBD( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn LinearToGamma( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 envMapTexelToLinear( vec4 color ) {\n\n\t\t\treturn inputTexelToLinear( color );\n\n\t\t}\n\t"
  29382. );
  29383. }
  29384. var LineStrip = 0;
  29385. var LinePieces = 1;
  29386. var NoColors = 0;
  29387. var FaceColors = 1;
  29388. var VertexColors = 2;
  29389. function MeshFaceMaterial(materials) {
  29390. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29391. return materials;
  29392. }
  29393. function MultiMaterial(materials) {
  29394. if (materials === void 0) {
  29395. materials = [];
  29396. }
  29397. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29398. materials.isMultiMaterial = true;
  29399. materials.materials = materials;
  29400. materials.clone = function () {
  29401. return materials.slice();
  29402. };
  29403. return materials;
  29404. }
  29405. function PointCloud(geometry, material) {
  29406. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29407. return new Points(geometry, material);
  29408. }
  29409. function Particle(material) {
  29410. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29411. return new Sprite(material);
  29412. }
  29413. function ParticleSystem(geometry, material) {
  29414. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29415. return new Points(geometry, material);
  29416. }
  29417. function PointCloudMaterial(parameters) {
  29418. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29419. return new PointsMaterial(parameters);
  29420. }
  29421. function ParticleBasicMaterial(parameters) {
  29422. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29423. return new PointsMaterial(parameters);
  29424. }
  29425. function ParticleSystemMaterial(parameters) {
  29426. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29427. return new PointsMaterial(parameters);
  29428. }
  29429. function Vertex(x, y, z) {
  29430. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29431. return new Vector3(x, y, z);
  29432. } //
  29433. function DynamicBufferAttribute(array, itemSize) {
  29434. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29435. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29436. }
  29437. function Int8Attribute(array, itemSize) {
  29438. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29439. return new Int8BufferAttribute(array, itemSize);
  29440. }
  29441. function Uint8Attribute(array, itemSize) {
  29442. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29443. return new Uint8BufferAttribute(array, itemSize);
  29444. }
  29445. function Uint8ClampedAttribute(array, itemSize) {
  29446. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29447. return new Uint8ClampedBufferAttribute(array, itemSize);
  29448. }
  29449. function Int16Attribute(array, itemSize) {
  29450. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29451. return new Int16BufferAttribute(array, itemSize);
  29452. }
  29453. function Uint16Attribute(array, itemSize) {
  29454. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29455. return new Uint16BufferAttribute(array, itemSize);
  29456. }
  29457. function Int32Attribute(array, itemSize) {
  29458. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29459. return new Int32BufferAttribute(array, itemSize);
  29460. }
  29461. function Uint32Attribute(array, itemSize) {
  29462. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29463. return new Uint32BufferAttribute(array, itemSize);
  29464. }
  29465. function Float32Attribute(array, itemSize) {
  29466. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29467. return new Float32BufferAttribute(array, itemSize);
  29468. }
  29469. function Float64Attribute(array, itemSize) {
  29470. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29471. return new Float64BufferAttribute(array, itemSize);
  29472. } //
  29473. Curve.create = function (construct, getPoint) {
  29474. console.log('THREE.Curve.create() has been deprecated');
  29475. construct.prototype = Object.create(Curve.prototype);
  29476. construct.prototype.constructor = construct;
  29477. construct.prototype.getPoint = getPoint;
  29478. return construct;
  29479. }; //
  29480. Path.prototype.fromPoints = function (points) {
  29481. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29482. return this.setFromPoints(points);
  29483. }; //
  29484. function AxisHelper(size) {
  29485. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29486. return new AxesHelper(size);
  29487. }
  29488. function BoundingBoxHelper(object, color) {
  29489. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29490. return new BoxHelper(object, color);
  29491. }
  29492. function EdgesHelper(object, hex) {
  29493. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29494. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29495. color: hex !== undefined ? hex : 0xffffff
  29496. }));
  29497. }
  29498. GridHelper.prototype.setColors = function () {
  29499. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29500. };
  29501. SkeletonHelper.prototype.update = function () {
  29502. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29503. };
  29504. function WireframeHelper(object, hex) {
  29505. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29506. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29507. color: hex !== undefined ? hex : 0xffffff
  29508. }));
  29509. } //
  29510. Loader.prototype.extractUrlBase = function (url) {
  29511. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29512. return LoaderUtils.extractUrlBase(url);
  29513. };
  29514. Loader.Handlers = {
  29515. add: function add()
  29516. /* regex, loader */
  29517. {
  29518. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29519. },
  29520. get: function get()
  29521. /* file */
  29522. {
  29523. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29524. }
  29525. };
  29526. function XHRLoader(manager) {
  29527. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29528. return new FileLoader(manager);
  29529. }
  29530. function BinaryTextureLoader(manager) {
  29531. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29532. return new DataTextureLoader(manager);
  29533. } //
  29534. Box2.prototype.center = function (optionalTarget) {
  29535. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29536. return this.getCenter(optionalTarget);
  29537. };
  29538. Box2.prototype.empty = function () {
  29539. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29540. return this.isEmpty();
  29541. };
  29542. Box2.prototype.isIntersectionBox = function (box) {
  29543. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29544. return this.intersectsBox(box);
  29545. };
  29546. Box2.prototype.size = function (optionalTarget) {
  29547. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29548. return this.getSize(optionalTarget);
  29549. }; //
  29550. Box3.prototype.center = function (optionalTarget) {
  29551. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29552. return this.getCenter(optionalTarget);
  29553. };
  29554. Box3.prototype.empty = function () {
  29555. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29556. return this.isEmpty();
  29557. };
  29558. Box3.prototype.isIntersectionBox = function (box) {
  29559. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29560. return this.intersectsBox(box);
  29561. };
  29562. Box3.prototype.isIntersectionSphere = function (sphere) {
  29563. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29564. return this.intersectsSphere(sphere);
  29565. };
  29566. Box3.prototype.size = function (optionalTarget) {
  29567. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29568. return this.getSize(optionalTarget);
  29569. }; //
  29570. Sphere.prototype.empty = function () {
  29571. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29572. return this.isEmpty();
  29573. }; //
  29574. Frustum.prototype.setFromMatrix = function (m) {
  29575. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29576. return this.setFromProjectionMatrix(m);
  29577. }; //
  29578. Line3.prototype.center = function (optionalTarget) {
  29579. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29580. return this.getCenter(optionalTarget);
  29581. }; //
  29582. MathUtils.random16 = function () {
  29583. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29584. return Math.random();
  29585. };
  29586. MathUtils.nearestPowerOfTwo = function (value) {
  29587. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29588. return MathUtils.floorPowerOfTwo(value);
  29589. };
  29590. MathUtils.nextPowerOfTwo = function (value) {
  29591. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29592. return MathUtils.ceilPowerOfTwo(value);
  29593. }; //
  29594. Matrix3.prototype.flattenToArrayOffset = function (array, offset) {
  29595. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29596. return this.toArray(array, offset);
  29597. };
  29598. Matrix3.prototype.multiplyVector3 = function (vector) {
  29599. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29600. return vector.applyMatrix3(this);
  29601. };
  29602. Matrix3.prototype.multiplyVector3Array = function ()
  29603. /* a */
  29604. {
  29605. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29606. };
  29607. Matrix3.prototype.applyToBufferAttribute = function (attribute) {
  29608. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29609. return attribute.applyMatrix3(this);
  29610. };
  29611. Matrix3.prototype.applyToVector3Array = function ()
  29612. /* array, offset, length */
  29613. {
  29614. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29615. };
  29616. Matrix3.prototype.getInverse = function (matrix) {
  29617. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29618. return this.copy(matrix).invert();
  29619. }; //
  29620. Matrix4.prototype.extractPosition = function (m) {
  29621. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29622. return this.copyPosition(m);
  29623. };
  29624. Matrix4.prototype.flattenToArrayOffset = function (array, offset) {
  29625. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29626. return this.toArray(array, offset);
  29627. };
  29628. Matrix4.prototype.getPosition = function () {
  29629. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29630. return new Vector3().setFromMatrixColumn(this, 3);
  29631. };
  29632. Matrix4.prototype.setRotationFromQuaternion = function (q) {
  29633. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29634. return this.makeRotationFromQuaternion(q);
  29635. };
  29636. Matrix4.prototype.multiplyToArray = function () {
  29637. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29638. };
  29639. Matrix4.prototype.multiplyVector3 = function (vector) {
  29640. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29641. return vector.applyMatrix4(this);
  29642. };
  29643. Matrix4.prototype.multiplyVector4 = function (vector) {
  29644. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29645. return vector.applyMatrix4(this);
  29646. };
  29647. Matrix4.prototype.multiplyVector3Array = function ()
  29648. /* a */
  29649. {
  29650. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29651. };
  29652. Matrix4.prototype.rotateAxis = function (v) {
  29653. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29654. v.transformDirection(this);
  29655. };
  29656. Matrix4.prototype.crossVector = function (vector) {
  29657. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29658. return vector.applyMatrix4(this);
  29659. };
  29660. Matrix4.prototype.translate = function () {
  29661. console.error('THREE.Matrix4: .translate() has been removed.');
  29662. };
  29663. Matrix4.prototype.rotateX = function () {
  29664. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29665. };
  29666. Matrix4.prototype.rotateY = function () {
  29667. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29668. };
  29669. Matrix4.prototype.rotateZ = function () {
  29670. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29671. };
  29672. Matrix4.prototype.rotateByAxis = function () {
  29673. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29674. };
  29675. Matrix4.prototype.applyToBufferAttribute = function (attribute) {
  29676. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29677. return attribute.applyMatrix4(this);
  29678. };
  29679. Matrix4.prototype.applyToVector3Array = function ()
  29680. /* array, offset, length */
  29681. {
  29682. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29683. };
  29684. Matrix4.prototype.makeFrustum = function (left, right, bottom, top, near, far) {
  29685. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29686. return this.makePerspective(left, right, top, bottom, near, far);
  29687. };
  29688. Matrix4.prototype.getInverse = function (matrix) {
  29689. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29690. return this.copy(matrix).invert();
  29691. }; //
  29692. Plane.prototype.isIntersectionLine = function (line) {
  29693. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29694. return this.intersectsLine(line);
  29695. }; //
  29696. Quaternion.prototype.multiplyVector3 = function (vector) {
  29697. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29698. return vector.applyQuaternion(this);
  29699. };
  29700. Quaternion.prototype.inverse = function () {
  29701. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29702. return this.invert();
  29703. }; //
  29704. Ray.prototype.isIntersectionBox = function (box) {
  29705. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29706. return this.intersectsBox(box);
  29707. };
  29708. Ray.prototype.isIntersectionPlane = function (plane) {
  29709. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29710. return this.intersectsPlane(plane);
  29711. };
  29712. Ray.prototype.isIntersectionSphere = function (sphere) {
  29713. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29714. return this.intersectsSphere(sphere);
  29715. }; //
  29716. Triangle.prototype.area = function () {
  29717. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29718. return this.getArea();
  29719. };
  29720. Triangle.prototype.barycoordFromPoint = function (point, target) {
  29721. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29722. return this.getBarycoord(point, target);
  29723. };
  29724. Triangle.prototype.midpoint = function (target) {
  29725. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29726. return this.getMidpoint(target);
  29727. };
  29728. Triangle.prototypenormal = function (target) {
  29729. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29730. return this.getNormal(target);
  29731. };
  29732. Triangle.prototype.plane = function (target) {
  29733. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29734. return this.getPlane(target);
  29735. };
  29736. Triangle.barycoordFromPoint = function (point, a, b, c, target) {
  29737. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29738. return Triangle.getBarycoord(point, a, b, c, target);
  29739. };
  29740. Triangle.normal = function (a, b, c, target) {
  29741. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29742. return Triangle.getNormal(a, b, c, target);
  29743. }; //
  29744. Shape.prototype.extractAllPoints = function (divisions) {
  29745. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29746. return this.extractPoints(divisions);
  29747. };
  29748. Shape.prototype.extrude = function (options) {
  29749. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29750. return new ExtrudeGeometry(this, options);
  29751. };
  29752. Shape.prototype.makeGeometry = function (options) {
  29753. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29754. return new ShapeGeometry(this, options);
  29755. }; //
  29756. Vector2.prototype.fromAttribute = function (attribute, index, offset) {
  29757. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29758. return this.fromBufferAttribute(attribute, index, offset);
  29759. };
  29760. Vector2.prototype.distanceToManhattan = function (v) {
  29761. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29762. return this.manhattanDistanceTo(v);
  29763. };
  29764. Vector2.prototype.lengthManhattan = function () {
  29765. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29766. return this.manhattanLength();
  29767. }; //
  29768. Vector3.prototype.setEulerFromRotationMatrix = function () {
  29769. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29770. };
  29771. Vector3.prototype.setEulerFromQuaternion = function () {
  29772. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29773. };
  29774. Vector3.prototype.getPositionFromMatrix = function (m) {
  29775. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29776. return this.setFromMatrixPosition(m);
  29777. };
  29778. Vector3.prototype.getScaleFromMatrix = function (m) {
  29779. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29780. return this.setFromMatrixScale(m);
  29781. };
  29782. Vector3.prototype.getColumnFromMatrix = function (index, matrix) {
  29783. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29784. return this.setFromMatrixColumn(matrix, index);
  29785. };
  29786. Vector3.prototype.applyProjection = function (m) {
  29787. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29788. return this.applyMatrix4(m);
  29789. };
  29790. Vector3.prototype.fromAttribute = function (attribute, index, offset) {
  29791. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29792. return this.fromBufferAttribute(attribute, index, offset);
  29793. };
  29794. Vector3.prototype.distanceToManhattan = function (v) {
  29795. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29796. return this.manhattanDistanceTo(v);
  29797. };
  29798. Vector3.prototype.lengthManhattan = function () {
  29799. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29800. return this.manhattanLength();
  29801. }; //
  29802. Vector4.prototype.fromAttribute = function (attribute, index, offset) {
  29803. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29804. return this.fromBufferAttribute(attribute, index, offset);
  29805. };
  29806. Vector4.prototype.lengthManhattan = function () {
  29807. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29808. return this.manhattanLength();
  29809. }; //
  29810. Object3D.prototype.getChildByName = function (name) {
  29811. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29812. return this.getObjectByName(name);
  29813. };
  29814. Object3D.prototype.renderDepth = function () {
  29815. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29816. };
  29817. Object3D.prototype.translate = function (distance, axis) {
  29818. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29819. return this.translateOnAxis(axis, distance);
  29820. };
  29821. Object3D.prototype.getWorldRotation = function () {
  29822. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29823. };
  29824. Object3D.prototype.applyMatrix = function (matrix) {
  29825. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29826. return this.applyMatrix4(matrix);
  29827. };
  29828. Object.defineProperties(Object3D.prototype, {
  29829. eulerOrder: {
  29830. get: function get() {
  29831. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29832. return this.rotation.order;
  29833. },
  29834. set: function set(value) {
  29835. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29836. this.rotation.order = value;
  29837. }
  29838. },
  29839. useQuaternion: {
  29840. get: function get() {
  29841. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29842. },
  29843. set: function set() {
  29844. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29845. }
  29846. }
  29847. });
  29848. Mesh.prototype.setDrawMode = function () {
  29849. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29850. };
  29851. Object.defineProperties(Mesh.prototype, {
  29852. drawMode: {
  29853. get: function get() {
  29854. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29855. return TrianglesDrawMode;
  29856. },
  29857. set: function set() {
  29858. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29859. }
  29860. }
  29861. });
  29862. Object.defineProperties(LOD.prototype, {
  29863. objects: {
  29864. get: function get() {
  29865. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29866. return this.levels;
  29867. }
  29868. }
  29869. });
  29870. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29871. get: function get() {
  29872. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29873. },
  29874. set: function set() {
  29875. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29876. }
  29877. });
  29878. SkinnedMesh.prototype.initBones = function () {
  29879. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29880. };
  29881. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29882. get: function get() {
  29883. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29884. return this.arcLengthDivisions;
  29885. },
  29886. set: function set(value) {
  29887. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29888. this.arcLengthDivisions = value;
  29889. }
  29890. }); //
  29891. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29892. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29893. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29894. this.setFocalLength(focalLength);
  29895. }; //
  29896. Object.defineProperties(Light.prototype, {
  29897. onlyShadow: {
  29898. set: function set() {
  29899. console.warn('THREE.Light: .onlyShadow has been removed.');
  29900. }
  29901. },
  29902. shadowCameraFov: {
  29903. set: function set(value) {
  29904. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29905. this.shadow.camera.fov = value;
  29906. }
  29907. },
  29908. shadowCameraLeft: {
  29909. set: function set(value) {
  29910. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29911. this.shadow.camera.left = value;
  29912. }
  29913. },
  29914. shadowCameraRight: {
  29915. set: function set(value) {
  29916. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29917. this.shadow.camera.right = value;
  29918. }
  29919. },
  29920. shadowCameraTop: {
  29921. set: function set(value) {
  29922. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29923. this.shadow.camera.top = value;
  29924. }
  29925. },
  29926. shadowCameraBottom: {
  29927. set: function set(value) {
  29928. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29929. this.shadow.camera.bottom = value;
  29930. }
  29931. },
  29932. shadowCameraNear: {
  29933. set: function set(value) {
  29934. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29935. this.shadow.camera.near = value;
  29936. }
  29937. },
  29938. shadowCameraFar: {
  29939. set: function set(value) {
  29940. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29941. this.shadow.camera.far = value;
  29942. }
  29943. },
  29944. shadowCameraVisible: {
  29945. set: function set() {
  29946. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29947. }
  29948. },
  29949. shadowBias: {
  29950. set: function set(value) {
  29951. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29952. this.shadow.bias = value;
  29953. }
  29954. },
  29955. shadowDarkness: {
  29956. set: function set() {
  29957. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29958. }
  29959. },
  29960. shadowMapWidth: {
  29961. set: function set(value) {
  29962. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29963. this.shadow.mapSize.width = value;
  29964. }
  29965. },
  29966. shadowMapHeight: {
  29967. set: function set(value) {
  29968. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29969. this.shadow.mapSize.height = value;
  29970. }
  29971. }
  29972. }); //
  29973. Object.defineProperties(BufferAttribute.prototype, {
  29974. length: {
  29975. get: function get() {
  29976. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29977. return this.array.length;
  29978. }
  29979. },
  29980. dynamic: {
  29981. get: function get() {
  29982. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29983. return this.usage === DynamicDrawUsage;
  29984. },
  29985. set: function set()
  29986. /* value */
  29987. {
  29988. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29989. this.setUsage(DynamicDrawUsage);
  29990. }
  29991. }
  29992. });
  29993. BufferAttribute.prototype.setDynamic = function (value) {
  29994. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29995. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29996. return this;
  29997. };
  29998. BufferAttribute.prototype.copyIndicesArray = function ()
  29999. /* indices */
  30000. {
  30001. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  30002. }, BufferAttribute.prototype.setArray = function ()
  30003. /* array */
  30004. {
  30005. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30006. }; //
  30007. BufferGeometry.prototype.addIndex = function (index) {
  30008. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  30009. this.setIndex(index);
  30010. };
  30011. BufferGeometry.prototype.addAttribute = function (name, attribute) {
  30012. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  30013. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  30014. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  30015. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  30016. }
  30017. if (name === 'index') {
  30018. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  30019. this.setIndex(attribute);
  30020. return this;
  30021. }
  30022. return this.setAttribute(name, attribute);
  30023. };
  30024. BufferGeometry.prototype.addDrawCall = function (start, count, indexOffset) {
  30025. if (indexOffset !== undefined) {
  30026. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  30027. }
  30028. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  30029. this.addGroup(start, count);
  30030. };
  30031. BufferGeometry.prototype.clearDrawCalls = function () {
  30032. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  30033. this.clearGroups();
  30034. };
  30035. BufferGeometry.prototype.computeOffsets = function () {
  30036. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  30037. };
  30038. BufferGeometry.prototype.removeAttribute = function (name) {
  30039. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  30040. return this.deleteAttribute(name);
  30041. };
  30042. BufferGeometry.prototype.applyMatrix = function (matrix) {
  30043. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  30044. return this.applyMatrix4(matrix);
  30045. };
  30046. Object.defineProperties(BufferGeometry.prototype, {
  30047. drawcalls: {
  30048. get: function get() {
  30049. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  30050. return this.groups;
  30051. }
  30052. },
  30053. offsets: {
  30054. get: function get() {
  30055. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  30056. return this.groups;
  30057. }
  30058. }
  30059. });
  30060. Object.defineProperties(InstancedBufferGeometry.prototype, {
  30061. maxInstancedCount: {
  30062. get: function get() {
  30063. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30064. return this.instanceCount;
  30065. },
  30066. set: function set(value) {
  30067. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  30068. this.instanceCount = value;
  30069. }
  30070. }
  30071. });
  30072. Object.defineProperties(Raycaster.prototype, {
  30073. linePrecision: {
  30074. get: function get() {
  30075. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30076. return this.params.Line.threshold;
  30077. },
  30078. set: function set(value) {
  30079. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  30080. this.params.Line.threshold = value;
  30081. }
  30082. }
  30083. });
  30084. Object.defineProperties(InterleavedBuffer.prototype, {
  30085. dynamic: {
  30086. get: function get() {
  30087. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30088. return this.usage === DynamicDrawUsage;
  30089. },
  30090. set: function set(value) {
  30091. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  30092. this.setUsage(value);
  30093. }
  30094. }
  30095. });
  30096. InterleavedBuffer.prototype.setDynamic = function (value) {
  30097. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  30098. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  30099. return this;
  30100. };
  30101. InterleavedBuffer.prototype.setArray = function ()
  30102. /* array */
  30103. {
  30104. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  30105. }; //
  30106. ExtrudeGeometry.prototype.getArrays = function () {
  30107. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  30108. };
  30109. ExtrudeGeometry.prototype.addShapeList = function () {
  30110. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  30111. };
  30112. ExtrudeGeometry.prototype.addShape = function () {
  30113. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  30114. }; //
  30115. Scene.prototype.dispose = function () {
  30116. console.error('THREE.Scene: .dispose() has been removed.');
  30117. }; //
  30118. Object.defineProperties(Uniform.prototype, {
  30119. dynamic: {
  30120. set: function set() {
  30121. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  30122. }
  30123. },
  30124. onUpdate: {
  30125. value: function value() {
  30126. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  30127. return this;
  30128. }
  30129. }
  30130. }); //
  30131. Object.defineProperties(Material.prototype, {
  30132. wrapAround: {
  30133. get: function get() {
  30134. console.warn('THREE.Material: .wrapAround has been removed.');
  30135. },
  30136. set: function set() {
  30137. console.warn('THREE.Material: .wrapAround has been removed.');
  30138. }
  30139. },
  30140. overdraw: {
  30141. get: function get() {
  30142. console.warn('THREE.Material: .overdraw has been removed.');
  30143. },
  30144. set: function set() {
  30145. console.warn('THREE.Material: .overdraw has been removed.');
  30146. }
  30147. },
  30148. wrapRGB: {
  30149. get: function get() {
  30150. console.warn('THREE.Material: .wrapRGB has been removed.');
  30151. return new Color();
  30152. }
  30153. },
  30154. shading: {
  30155. get: function get() {
  30156. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30157. },
  30158. set: function set(value) {
  30159. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  30160. this.flatShading = value === FlatShading;
  30161. }
  30162. },
  30163. stencilMask: {
  30164. get: function get() {
  30165. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30166. return this.stencilFuncMask;
  30167. },
  30168. set: function set(value) {
  30169. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  30170. this.stencilFuncMask = value;
  30171. }
  30172. }
  30173. });
  30174. Object.defineProperties(MeshPhongMaterial.prototype, {
  30175. metal: {
  30176. get: function get() {
  30177. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  30178. return false;
  30179. },
  30180. set: function set() {
  30181. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  30182. }
  30183. }
  30184. });
  30185. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  30186. transparency: {
  30187. get: function get() {
  30188. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30189. return this.transmission;
  30190. },
  30191. set: function set(value) {
  30192. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  30193. this.transmission = value;
  30194. }
  30195. }
  30196. });
  30197. Object.defineProperties(ShaderMaterial.prototype, {
  30198. derivatives: {
  30199. get: function get() {
  30200. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30201. return this.extensions.derivatives;
  30202. },
  30203. set: function set(value) {
  30204. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  30205. this.extensions.derivatives = value;
  30206. }
  30207. }
  30208. }); //
  30209. WebGLRenderer.prototype.clearTarget = function (renderTarget, color, depth, stencil) {
  30210. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  30211. this.setRenderTarget(renderTarget);
  30212. this.clear(color, depth, stencil);
  30213. };
  30214. WebGLRenderer.prototype.animate = function (callback) {
  30215. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  30216. this.setAnimationLoop(callback);
  30217. };
  30218. WebGLRenderer.prototype.getCurrentRenderTarget = function () {
  30219. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  30220. return this.getRenderTarget();
  30221. };
  30222. WebGLRenderer.prototype.getMaxAnisotropy = function () {
  30223. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  30224. return this.capabilities.getMaxAnisotropy();
  30225. };
  30226. WebGLRenderer.prototype.getPrecision = function () {
  30227. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  30228. return this.capabilities.precision;
  30229. };
  30230. WebGLRenderer.prototype.resetGLState = function () {
  30231. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  30232. return this.state.reset();
  30233. };
  30234. WebGLRenderer.prototype.supportsFloatTextures = function () {
  30235. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30236. return this.extensions.get('OES_texture_float');
  30237. };
  30238. WebGLRenderer.prototype.supportsHalfFloatTextures = function () {
  30239. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30240. return this.extensions.get('OES_texture_half_float');
  30241. };
  30242. WebGLRenderer.prototype.supportsStandardDerivatives = function () {
  30243. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30244. return this.extensions.get('OES_standard_derivatives');
  30245. };
  30246. WebGLRenderer.prototype.supportsCompressedTextureS3TC = function () {
  30247. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30248. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30249. };
  30250. WebGLRenderer.prototype.supportsCompressedTexturePVRTC = function () {
  30251. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30252. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30253. };
  30254. WebGLRenderer.prototype.supportsBlendMinMax = function () {
  30255. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30256. return this.extensions.get('EXT_blend_minmax');
  30257. };
  30258. WebGLRenderer.prototype.supportsVertexTextures = function () {
  30259. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30260. return this.capabilities.vertexTextures;
  30261. };
  30262. WebGLRenderer.prototype.supportsInstancedArrays = function () {
  30263. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30264. return this.extensions.get('ANGLE_instanced_arrays');
  30265. };
  30266. WebGLRenderer.prototype.enableScissorTest = function (boolean) {
  30267. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30268. this.setScissorTest(boolean);
  30269. };
  30270. WebGLRenderer.prototype.initMaterial = function () {
  30271. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30272. };
  30273. WebGLRenderer.prototype.addPrePlugin = function () {
  30274. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30275. };
  30276. WebGLRenderer.prototype.addPostPlugin = function () {
  30277. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30278. };
  30279. WebGLRenderer.prototype.updateShadowMap = function () {
  30280. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30281. };
  30282. WebGLRenderer.prototype.setFaceCulling = function () {
  30283. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30284. };
  30285. WebGLRenderer.prototype.allocTextureUnit = function () {
  30286. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30287. };
  30288. WebGLRenderer.prototype.setTexture = function () {
  30289. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30290. };
  30291. WebGLRenderer.prototype.setTexture2D = function () {
  30292. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30293. };
  30294. WebGLRenderer.prototype.setTextureCube = function () {
  30295. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30296. };
  30297. WebGLRenderer.prototype.getActiveMipMapLevel = function () {
  30298. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30299. return this.getActiveMipmapLevel();
  30300. };
  30301. Object.defineProperties(WebGLRenderer.prototype, {
  30302. shadowMapEnabled: {
  30303. get: function get() {
  30304. return this.shadowMap.enabled;
  30305. },
  30306. set: function set(value) {
  30307. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30308. this.shadowMap.enabled = value;
  30309. }
  30310. },
  30311. shadowMapType: {
  30312. get: function get() {
  30313. return this.shadowMap.type;
  30314. },
  30315. set: function set(value) {
  30316. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30317. this.shadowMap.type = value;
  30318. }
  30319. },
  30320. shadowMapCullFace: {
  30321. get: function get() {
  30322. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30323. return undefined;
  30324. },
  30325. set: function set()
  30326. /* value */
  30327. {
  30328. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30329. }
  30330. },
  30331. context: {
  30332. get: function get() {
  30333. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30334. return this.getContext();
  30335. }
  30336. },
  30337. vr: {
  30338. get: function get() {
  30339. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30340. return this.xr;
  30341. }
  30342. },
  30343. gammaInput: {
  30344. get: function get() {
  30345. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30346. return false;
  30347. },
  30348. set: function set() {
  30349. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30350. }
  30351. },
  30352. gammaOutput: {
  30353. get: function get() {
  30354. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30355. return false;
  30356. },
  30357. set: function set(value) {
  30358. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30359. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30360. }
  30361. },
  30362. toneMappingWhitePoint: {
  30363. get: function get() {
  30364. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30365. return 1.0;
  30366. },
  30367. set: function set() {
  30368. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30369. }
  30370. }
  30371. });
  30372. Object.defineProperties(WebGLShadowMap.prototype, {
  30373. cullFace: {
  30374. get: function get() {
  30375. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30376. return undefined;
  30377. },
  30378. set: function set()
  30379. /* cullFace */
  30380. {
  30381. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30382. }
  30383. },
  30384. renderReverseSided: {
  30385. get: function get() {
  30386. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30387. return undefined;
  30388. },
  30389. set: function set() {
  30390. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30391. }
  30392. },
  30393. renderSingleSided: {
  30394. get: function get() {
  30395. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30396. return undefined;
  30397. },
  30398. set: function set() {
  30399. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30400. }
  30401. }
  30402. });
  30403. function WebGLRenderTargetCube(width, height, options) {
  30404. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30405. return new WebGLCubeRenderTarget(width, options);
  30406. } //
  30407. Object.defineProperties(WebGLRenderTarget.prototype, {
  30408. wrapS: {
  30409. get: function get() {
  30410. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30411. return this.texture.wrapS;
  30412. },
  30413. set: function set(value) {
  30414. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30415. this.texture.wrapS = value;
  30416. }
  30417. },
  30418. wrapT: {
  30419. get: function get() {
  30420. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30421. return this.texture.wrapT;
  30422. },
  30423. set: function set(value) {
  30424. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30425. this.texture.wrapT = value;
  30426. }
  30427. },
  30428. magFilter: {
  30429. get: function get() {
  30430. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30431. return this.texture.magFilter;
  30432. },
  30433. set: function set(value) {
  30434. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30435. this.texture.magFilter = value;
  30436. }
  30437. },
  30438. minFilter: {
  30439. get: function get() {
  30440. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30441. return this.texture.minFilter;
  30442. },
  30443. set: function set(value) {
  30444. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30445. this.texture.minFilter = value;
  30446. }
  30447. },
  30448. anisotropy: {
  30449. get: function get() {
  30450. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30451. return this.texture.anisotropy;
  30452. },
  30453. set: function set(value) {
  30454. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30455. this.texture.anisotropy = value;
  30456. }
  30457. },
  30458. offset: {
  30459. get: function get() {
  30460. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30461. return this.texture.offset;
  30462. },
  30463. set: function set(value) {
  30464. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30465. this.texture.offset = value;
  30466. }
  30467. },
  30468. repeat: {
  30469. get: function get() {
  30470. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30471. return this.texture.repeat;
  30472. },
  30473. set: function set(value) {
  30474. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30475. this.texture.repeat = value;
  30476. }
  30477. },
  30478. format: {
  30479. get: function get() {
  30480. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30481. return this.texture.format;
  30482. },
  30483. set: function set(value) {
  30484. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30485. this.texture.format = value;
  30486. }
  30487. },
  30488. type: {
  30489. get: function get() {
  30490. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30491. return this.texture.type;
  30492. },
  30493. set: function set(value) {
  30494. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30495. this.texture.type = value;
  30496. }
  30497. },
  30498. generateMipmaps: {
  30499. get: function get() {
  30500. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30501. return this.texture.generateMipmaps;
  30502. },
  30503. set: function set(value) {
  30504. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30505. this.texture.generateMipmaps = value;
  30506. }
  30507. }
  30508. }); //
  30509. Object.defineProperties(Audio.prototype, {
  30510. load: {
  30511. value: function value(file) {
  30512. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30513. var scope = this;
  30514. var audioLoader = new AudioLoader();
  30515. audioLoader.load(file, function (buffer) {
  30516. scope.setBuffer(buffer);
  30517. });
  30518. return this;
  30519. }
  30520. },
  30521. startTime: {
  30522. set: function set() {
  30523. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30524. }
  30525. }
  30526. });
  30527. AudioAnalyser.prototype.getData = function () {
  30528. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30529. return this.getFrequencyData();
  30530. }; //
  30531. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30532. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30533. return this.update(renderer, scene);
  30534. };
  30535. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30536. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30537. return this.renderTarget.clear(renderer, color, depth, stencil);
  30538. };
  30539. ImageUtils.crossOrigin = undefined;
  30540. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30541. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30542. var loader = new TextureLoader();
  30543. loader.setCrossOrigin(this.crossOrigin);
  30544. var texture = loader.load(url, onLoad, undefined, onError);
  30545. if (mapping) texture.mapping = mapping;
  30546. return texture;
  30547. };
  30548. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30549. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30550. var loader = new CubeTextureLoader();
  30551. loader.setCrossOrigin(this.crossOrigin);
  30552. var texture = loader.load(urls, onLoad, undefined, onError);
  30553. if (mapping) texture.mapping = mapping;
  30554. return texture;
  30555. };
  30556. ImageUtils.loadCompressedTexture = function () {
  30557. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30558. };
  30559. ImageUtils.loadCompressedTextureCube = function () {
  30560. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30561. }; //
  30562. function CanvasRenderer() {
  30563. console.error('THREE.CanvasRenderer has been removed');
  30564. } //
  30565. function JSONLoader() {
  30566. console.error('THREE.JSONLoader has been removed.');
  30567. } //
  30568. var SceneUtils = {
  30569. createMultiMaterialObject: function createMultiMaterialObject()
  30570. /* geometry, materials */
  30571. {
  30572. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30573. },
  30574. detach: function detach()
  30575. /* child, parent, scene */
  30576. {
  30577. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30578. },
  30579. attach: function attach()
  30580. /* child, scene, parent */
  30581. {
  30582. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30583. }
  30584. }; //
  30585. function LensFlare() {
  30586. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30587. }
  30588. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30589. /* eslint-disable no-undef */
  30590. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30591. detail: {
  30592. revision: REVISION
  30593. }
  30594. }));
  30595. /* eslint-enable no-undef */
  30596. }
  30597. if (typeof window !== 'undefined') {
  30598. if (window.__THREE__) {
  30599. console.warn('WARNING: Multiple instances of Three.js being imported.');
  30600. } else {
  30601. window.__THREE__ = REVISION;
  30602. }
  30603. }
  30604. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30605. exports.AddEquation = AddEquation;
  30606. exports.AddOperation = AddOperation;
  30607. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30608. exports.AdditiveBlending = AdditiveBlending;
  30609. exports.AlphaFormat = AlphaFormat;
  30610. exports.AlwaysDepth = AlwaysDepth;
  30611. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30612. exports.AmbientLight = AmbientLight;
  30613. exports.AmbientLightProbe = AmbientLightProbe;
  30614. exports.AnimationClip = AnimationClip;
  30615. exports.AnimationLoader = AnimationLoader;
  30616. exports.AnimationMixer = AnimationMixer;
  30617. exports.AnimationObjectGroup = AnimationObjectGroup;
  30618. exports.AnimationUtils = AnimationUtils;
  30619. exports.ArcCurve = ArcCurve;
  30620. exports.ArrayCamera = ArrayCamera;
  30621. exports.ArrowHelper = ArrowHelper;
  30622. exports.Audio = Audio;
  30623. exports.AudioAnalyser = AudioAnalyser;
  30624. exports.AudioContext = AudioContext;
  30625. exports.AudioListener = AudioListener;
  30626. exports.AudioLoader = AudioLoader;
  30627. exports.AxesHelper = AxesHelper;
  30628. exports.AxisHelper = AxisHelper;
  30629. exports.BackSide = BackSide;
  30630. exports.BasicDepthPacking = BasicDepthPacking;
  30631. exports.BasicShadowMap = BasicShadowMap;
  30632. exports.BinaryTextureLoader = BinaryTextureLoader;
  30633. exports.Bone = Bone;
  30634. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30635. exports.BoundingBoxHelper = BoundingBoxHelper;
  30636. exports.Box2 = Box2;
  30637. exports.Box3 = Box3;
  30638. exports.Box3Helper = Box3Helper;
  30639. exports.BoxBufferGeometry = BoxGeometry;
  30640. exports.BoxGeometry = BoxGeometry;
  30641. exports.BoxHelper = BoxHelper;
  30642. exports.BufferAttribute = BufferAttribute;
  30643. exports.BufferGeometry = BufferGeometry;
  30644. exports.BufferGeometryLoader = BufferGeometryLoader;
  30645. exports.ByteType = ByteType;
  30646. exports.Cache = Cache;
  30647. exports.Camera = Camera;
  30648. exports.CameraHelper = CameraHelper;
  30649. exports.CanvasRenderer = CanvasRenderer;
  30650. exports.CanvasTexture = CanvasTexture;
  30651. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30652. exports.CineonToneMapping = CineonToneMapping;
  30653. exports.CircleBufferGeometry = CircleGeometry;
  30654. exports.CircleGeometry = CircleGeometry;
  30655. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30656. exports.Clock = Clock;
  30657. exports.Color = Color;
  30658. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30659. exports.CompressedTexture = CompressedTexture;
  30660. exports.CompressedTextureLoader = CompressedTextureLoader;
  30661. exports.ConeBufferGeometry = ConeGeometry;
  30662. exports.ConeGeometry = ConeGeometry;
  30663. exports.CubeCamera = CubeCamera;
  30664. exports.CubeReflectionMapping = CubeReflectionMapping;
  30665. exports.CubeRefractionMapping = CubeRefractionMapping;
  30666. exports.CubeTexture = CubeTexture;
  30667. exports.CubeTextureLoader = CubeTextureLoader;
  30668. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30669. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30670. exports.CubicBezierCurve = CubicBezierCurve;
  30671. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30672. exports.CubicInterpolant = CubicInterpolant;
  30673. exports.CullFaceBack = CullFaceBack;
  30674. exports.CullFaceFront = CullFaceFront;
  30675. exports.CullFaceFrontBack = CullFaceFrontBack;
  30676. exports.CullFaceNone = CullFaceNone;
  30677. exports.Curve = Curve;
  30678. exports.CurvePath = CurvePath;
  30679. exports.CustomBlending = CustomBlending;
  30680. exports.CustomToneMapping = CustomToneMapping;
  30681. exports.CylinderBufferGeometry = CylinderGeometry;
  30682. exports.CylinderGeometry = CylinderGeometry;
  30683. exports.Cylindrical = Cylindrical;
  30684. exports.DataTexture = DataTexture;
  30685. exports.DataTexture2DArray = DataTexture2DArray;
  30686. exports.DataTexture3D = DataTexture3D;
  30687. exports.DataTextureLoader = DataTextureLoader;
  30688. exports.DataUtils = DataUtils;
  30689. exports.DecrementStencilOp = DecrementStencilOp;
  30690. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30691. exports.DefaultLoadingManager = DefaultLoadingManager;
  30692. exports.DepthFormat = DepthFormat;
  30693. exports.DepthStencilFormat = DepthStencilFormat;
  30694. exports.DepthTexture = DepthTexture;
  30695. exports.DirectionalLight = DirectionalLight;
  30696. exports.DirectionalLightHelper = DirectionalLightHelper;
  30697. exports.DiscreteInterpolant = DiscreteInterpolant;
  30698. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30699. exports.DodecahedronGeometry = DodecahedronGeometry;
  30700. exports.DoubleSide = DoubleSide;
  30701. exports.DstAlphaFactor = DstAlphaFactor;
  30702. exports.DstColorFactor = DstColorFactor;
  30703. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30704. exports.DynamicCopyUsage = DynamicCopyUsage;
  30705. exports.DynamicDrawUsage = DynamicDrawUsage;
  30706. exports.DynamicReadUsage = DynamicReadUsage;
  30707. exports.EdgesGeometry = EdgesGeometry;
  30708. exports.EdgesHelper = EdgesHelper;
  30709. exports.EllipseCurve = EllipseCurve;
  30710. exports.EqualDepth = EqualDepth;
  30711. exports.EqualStencilFunc = EqualStencilFunc;
  30712. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30713. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30714. exports.Euler = Euler;
  30715. exports.EventDispatcher = EventDispatcher;
  30716. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30717. exports.ExtrudeGeometry = ExtrudeGeometry;
  30718. exports.FaceColors = FaceColors;
  30719. exports.FileLoader = FileLoader;
  30720. exports.FlatShading = FlatShading;
  30721. exports.Float16BufferAttribute = Float16BufferAttribute;
  30722. exports.Float32Attribute = Float32Attribute;
  30723. exports.Float32BufferAttribute = Float32BufferAttribute;
  30724. exports.Float64Attribute = Float64Attribute;
  30725. exports.Float64BufferAttribute = Float64BufferAttribute;
  30726. exports.FloatType = FloatType;
  30727. exports.Fog = Fog;
  30728. exports.FogExp2 = FogExp2;
  30729. exports.Font = Font;
  30730. exports.FontLoader = FontLoader;
  30731. exports.FrontSide = FrontSide;
  30732. exports.Frustum = Frustum;
  30733. exports.GLBufferAttribute = GLBufferAttribute;
  30734. exports.GLSL1 = GLSL1;
  30735. exports.GLSL3 = GLSL3;
  30736. exports.GammaEncoding = GammaEncoding;
  30737. exports.GreaterDepth = GreaterDepth;
  30738. exports.GreaterEqualDepth = GreaterEqualDepth;
  30739. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30740. exports.GreaterStencilFunc = GreaterStencilFunc;
  30741. exports.GridHelper = GridHelper;
  30742. exports.Group = Group;
  30743. exports.HalfFloatType = HalfFloatType;
  30744. exports.HemisphereLight = HemisphereLight;
  30745. exports.HemisphereLightHelper = HemisphereLightHelper;
  30746. exports.HemisphereLightProbe = HemisphereLightProbe;
  30747. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30748. exports.IcosahedronGeometry = IcosahedronGeometry;
  30749. exports.ImageBitmapLoader = ImageBitmapLoader;
  30750. exports.ImageLoader = ImageLoader;
  30751. exports.ImageUtils = ImageUtils;
  30752. exports.ImmediateRenderObject = ImmediateRenderObject;
  30753. exports.IncrementStencilOp = IncrementStencilOp;
  30754. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30755. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30756. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30757. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30758. exports.InstancedMesh = InstancedMesh;
  30759. exports.Int16Attribute = Int16Attribute;
  30760. exports.Int16BufferAttribute = Int16BufferAttribute;
  30761. exports.Int32Attribute = Int32Attribute;
  30762. exports.Int32BufferAttribute = Int32BufferAttribute;
  30763. exports.Int8Attribute = Int8Attribute;
  30764. exports.Int8BufferAttribute = Int8BufferAttribute;
  30765. exports.IntType = IntType;
  30766. exports.InterleavedBuffer = InterleavedBuffer;
  30767. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30768. exports.Interpolant = Interpolant;
  30769. exports.InterpolateDiscrete = InterpolateDiscrete;
  30770. exports.InterpolateLinear = InterpolateLinear;
  30771. exports.InterpolateSmooth = InterpolateSmooth;
  30772. exports.InvertStencilOp = InvertStencilOp;
  30773. exports.JSONLoader = JSONLoader;
  30774. exports.KeepStencilOp = KeepStencilOp;
  30775. exports.KeyframeTrack = KeyframeTrack;
  30776. exports.LOD = LOD;
  30777. exports.LatheBufferGeometry = LatheGeometry;
  30778. exports.LatheGeometry = LatheGeometry;
  30779. exports.Layers = Layers;
  30780. exports.LensFlare = LensFlare;
  30781. exports.LessDepth = LessDepth;
  30782. exports.LessEqualDepth = LessEqualDepth;
  30783. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30784. exports.LessStencilFunc = LessStencilFunc;
  30785. exports.Light = Light;
  30786. exports.LightProbe = LightProbe;
  30787. exports.Line = Line;
  30788. exports.Line3 = Line3;
  30789. exports.LineBasicMaterial = LineBasicMaterial;
  30790. exports.LineCurve = LineCurve;
  30791. exports.LineCurve3 = LineCurve3;
  30792. exports.LineDashedMaterial = LineDashedMaterial;
  30793. exports.LineLoop = LineLoop;
  30794. exports.LinePieces = LinePieces;
  30795. exports.LineSegments = LineSegments;
  30796. exports.LineStrip = LineStrip;
  30797. exports.LinearEncoding = LinearEncoding;
  30798. exports.LinearFilter = LinearFilter;
  30799. exports.LinearInterpolant = LinearInterpolant;
  30800. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30801. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30802. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30803. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30804. exports.LinearToneMapping = LinearToneMapping;
  30805. exports.Loader = Loader;
  30806. exports.LoaderUtils = LoaderUtils;
  30807. exports.LoadingManager = LoadingManager;
  30808. exports.LogLuvEncoding = LogLuvEncoding;
  30809. exports.LoopOnce = LoopOnce;
  30810. exports.LoopPingPong = LoopPingPong;
  30811. exports.LoopRepeat = LoopRepeat;
  30812. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30813. exports.LuminanceFormat = LuminanceFormat;
  30814. exports.MOUSE = MOUSE;
  30815. exports.Material = Material;
  30816. exports.MaterialLoader = MaterialLoader;
  30817. exports.Math = MathUtils;
  30818. exports.MathUtils = MathUtils;
  30819. exports.Matrix3 = Matrix3;
  30820. exports.Matrix4 = Matrix4;
  30821. exports.MaxEquation = MaxEquation;
  30822. exports.Mesh = Mesh;
  30823. exports.MeshBasicMaterial = MeshBasicMaterial;
  30824. exports.MeshDepthMaterial = MeshDepthMaterial;
  30825. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30826. exports.MeshFaceMaterial = MeshFaceMaterial;
  30827. exports.MeshLambertMaterial = MeshLambertMaterial;
  30828. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30829. exports.MeshNormalMaterial = MeshNormalMaterial;
  30830. exports.MeshPhongMaterial = MeshPhongMaterial;
  30831. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30832. exports.MeshStandardMaterial = MeshStandardMaterial;
  30833. exports.MeshToonMaterial = MeshToonMaterial;
  30834. exports.MinEquation = MinEquation;
  30835. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30836. exports.MixOperation = MixOperation;
  30837. exports.MultiMaterial = MultiMaterial;
  30838. exports.MultiplyBlending = MultiplyBlending;
  30839. exports.MultiplyOperation = MultiplyOperation;
  30840. exports.NearestFilter = NearestFilter;
  30841. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30842. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30843. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30844. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30845. exports.NeverDepth = NeverDepth;
  30846. exports.NeverStencilFunc = NeverStencilFunc;
  30847. exports.NoBlending = NoBlending;
  30848. exports.NoColors = NoColors;
  30849. exports.NoToneMapping = NoToneMapping;
  30850. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30851. exports.NormalBlending = NormalBlending;
  30852. exports.NotEqualDepth = NotEqualDepth;
  30853. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30854. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30855. exports.Object3D = Object3D;
  30856. exports.ObjectLoader = ObjectLoader;
  30857. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30858. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30859. exports.OctahedronGeometry = OctahedronGeometry;
  30860. exports.OneFactor = OneFactor;
  30861. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30862. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30863. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30864. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30865. exports.OrthographicCamera = OrthographicCamera;
  30866. exports.PCFShadowMap = PCFShadowMap;
  30867. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30868. exports.PMREMGenerator = PMREMGenerator;
  30869. exports.ParametricBufferGeometry = ParametricGeometry;
  30870. exports.ParametricGeometry = ParametricGeometry;
  30871. exports.Particle = Particle;
  30872. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30873. exports.ParticleSystem = ParticleSystem;
  30874. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30875. exports.Path = Path;
  30876. exports.PerspectiveCamera = PerspectiveCamera;
  30877. exports.Plane = Plane;
  30878. exports.PlaneBufferGeometry = PlaneGeometry;
  30879. exports.PlaneGeometry = PlaneGeometry;
  30880. exports.PlaneHelper = PlaneHelper;
  30881. exports.PointCloud = PointCloud;
  30882. exports.PointCloudMaterial = PointCloudMaterial;
  30883. exports.PointLight = PointLight;
  30884. exports.PointLightHelper = PointLightHelper;
  30885. exports.Points = Points;
  30886. exports.PointsMaterial = PointsMaterial;
  30887. exports.PolarGridHelper = PolarGridHelper;
  30888. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30889. exports.PolyhedronGeometry = PolyhedronGeometry;
  30890. exports.PositionalAudio = PositionalAudio;
  30891. exports.PropertyBinding = PropertyBinding;
  30892. exports.PropertyMixer = PropertyMixer;
  30893. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30894. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30895. exports.Quaternion = Quaternion;
  30896. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30897. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30898. exports.REVISION = REVISION;
  30899. exports.RGBADepthPacking = RGBADepthPacking;
  30900. exports.RGBAFormat = RGBAFormat;
  30901. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30902. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30903. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30904. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30905. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30906. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30907. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30908. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30909. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30910. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30911. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30912. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30913. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30914. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30915. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30916. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30917. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30918. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30919. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30920. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30921. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30922. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30923. exports.RGBDEncoding = RGBDEncoding;
  30924. exports.RGBEEncoding = RGBEEncoding;
  30925. exports.RGBEFormat = RGBEFormat;
  30926. exports.RGBFormat = RGBFormat;
  30927. exports.RGBIntegerFormat = RGBIntegerFormat;
  30928. exports.RGBM16Encoding = RGBM16Encoding;
  30929. exports.RGBM7Encoding = RGBM7Encoding;
  30930. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30931. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30932. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30933. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30934. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30935. exports.RGFormat = RGFormat;
  30936. exports.RGIntegerFormat = RGIntegerFormat;
  30937. exports.RawShaderMaterial = RawShaderMaterial;
  30938. exports.Ray = Ray;
  30939. exports.Raycaster = Raycaster;
  30940. exports.RectAreaLight = RectAreaLight;
  30941. exports.RedFormat = RedFormat;
  30942. exports.RedIntegerFormat = RedIntegerFormat;
  30943. exports.ReinhardToneMapping = ReinhardToneMapping;
  30944. exports.RepeatWrapping = RepeatWrapping;
  30945. exports.ReplaceStencilOp = ReplaceStencilOp;
  30946. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30947. exports.RingBufferGeometry = RingGeometry;
  30948. exports.RingGeometry = RingGeometry;
  30949. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30950. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30951. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30952. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30953. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30954. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30955. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30956. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30957. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30958. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30959. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30960. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30961. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30962. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30963. exports.Scene = Scene;
  30964. exports.SceneUtils = SceneUtils;
  30965. exports.ShaderChunk = ShaderChunk;
  30966. exports.ShaderLib = ShaderLib;
  30967. exports.ShaderMaterial = ShaderMaterial;
  30968. exports.ShadowMaterial = ShadowMaterial;
  30969. exports.Shape = Shape;
  30970. exports.ShapeBufferGeometry = ShapeGeometry;
  30971. exports.ShapeGeometry = ShapeGeometry;
  30972. exports.ShapePath = ShapePath;
  30973. exports.ShapeUtils = ShapeUtils;
  30974. exports.ShortType = ShortType;
  30975. exports.Skeleton = Skeleton;
  30976. exports.SkeletonHelper = SkeletonHelper;
  30977. exports.SkinnedMesh = SkinnedMesh;
  30978. exports.SmoothShading = SmoothShading;
  30979. exports.Sphere = Sphere;
  30980. exports.SphereBufferGeometry = SphereGeometry;
  30981. exports.SphereGeometry = SphereGeometry;
  30982. exports.Spherical = Spherical;
  30983. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30984. exports.SplineCurve = SplineCurve;
  30985. exports.SpotLight = SpotLight;
  30986. exports.SpotLightHelper = SpotLightHelper;
  30987. exports.Sprite = Sprite;
  30988. exports.SpriteMaterial = SpriteMaterial;
  30989. exports.SrcAlphaFactor = SrcAlphaFactor;
  30990. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30991. exports.SrcColorFactor = SrcColorFactor;
  30992. exports.StaticCopyUsage = StaticCopyUsage;
  30993. exports.StaticDrawUsage = StaticDrawUsage;
  30994. exports.StaticReadUsage = StaticReadUsage;
  30995. exports.StereoCamera = StereoCamera;
  30996. exports.StreamCopyUsage = StreamCopyUsage;
  30997. exports.StreamDrawUsage = StreamDrawUsage;
  30998. exports.StreamReadUsage = StreamReadUsage;
  30999. exports.StringKeyframeTrack = StringKeyframeTrack;
  31000. exports.SubtractEquation = SubtractEquation;
  31001. exports.SubtractiveBlending = SubtractiveBlending;
  31002. exports.TOUCH = TOUCH;
  31003. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  31004. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  31005. exports.TetrahedronGeometry = TetrahedronGeometry;
  31006. exports.TextBufferGeometry = TextGeometry;
  31007. exports.TextGeometry = TextGeometry;
  31008. exports.Texture = Texture;
  31009. exports.TextureLoader = TextureLoader;
  31010. exports.TorusBufferGeometry = TorusGeometry;
  31011. exports.TorusGeometry = TorusGeometry;
  31012. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  31013. exports.TorusKnotGeometry = TorusKnotGeometry;
  31014. exports.Triangle = Triangle;
  31015. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  31016. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  31017. exports.TrianglesDrawMode = TrianglesDrawMode;
  31018. exports.TubeBufferGeometry = TubeGeometry;
  31019. exports.TubeGeometry = TubeGeometry;
  31020. exports.UVMapping = UVMapping;
  31021. exports.Uint16Attribute = Uint16Attribute;
  31022. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  31023. exports.Uint32Attribute = Uint32Attribute;
  31024. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  31025. exports.Uint8Attribute = Uint8Attribute;
  31026. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  31027. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  31028. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  31029. exports.Uniform = Uniform;
  31030. exports.UniformsLib = UniformsLib;
  31031. exports.UniformsUtils = UniformsUtils;
  31032. exports.UnsignedByteType = UnsignedByteType;
  31033. exports.UnsignedInt248Type = UnsignedInt248Type;
  31034. exports.UnsignedIntType = UnsignedIntType;
  31035. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  31036. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  31037. exports.UnsignedShort565Type = UnsignedShort565Type;
  31038. exports.UnsignedShortType = UnsignedShortType;
  31039. exports.VSMShadowMap = VSMShadowMap;
  31040. exports.Vector2 = Vector2;
  31041. exports.Vector3 = Vector3;
  31042. exports.Vector4 = Vector4;
  31043. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  31044. exports.Vertex = Vertex;
  31045. exports.VertexColors = VertexColors;
  31046. exports.VideoTexture = VideoTexture;
  31047. exports.WebGL1Renderer = WebGL1Renderer;
  31048. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  31049. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  31050. exports.WebGLRenderTarget = WebGLRenderTarget;
  31051. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  31052. exports.WebGLRenderer = WebGLRenderer;
  31053. exports.WebGLUtils = WebGLUtils;
  31054. exports.WireframeGeometry = WireframeGeometry;
  31055. exports.WireframeHelper = WireframeHelper;
  31056. exports.WrapAroundEnding = WrapAroundEnding;
  31057. exports.XHRLoader = XHRLoader;
  31058. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  31059. exports.ZeroFactor = ZeroFactor;
  31060. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  31061. exports.ZeroStencilOp = ZeroStencilOp;
  31062. exports.sRGBEncoding = sRGBEncoding;
  31063. Object.defineProperty(exports, '__esModule', { value: true });
  31064. })));
粤ICP备19079148号