three.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613
  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. // Polyfills
  8. if (Number.EPSILON === undefined) {
  9. Number.EPSILON = Math.pow(2, -52);
  10. }
  11. if (Number.isInteger === undefined) {
  12. // Missing in IE
  13. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  14. Number.isInteger = function (value) {
  15. return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
  16. };
  17. } //
  18. if (Math.sign === undefined) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function (x) {
  21. return x < 0 ? -1 : x > 0 ? 1 : +x;
  22. };
  23. }
  24. if ('name' in Function.prototype === false) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty(Function.prototype, 'name', {
  28. get: function get() {
  29. return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];
  30. }
  31. });
  32. }
  33. if (Object.assign === undefined) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. Object.assign = function (target) {
  37. if (target === undefined || target === null) {
  38. throw new TypeError('Cannot convert undefined or null to object');
  39. }
  40. var output = Object(target);
  41. for (var index = 1; index < arguments.length; index++) {
  42. var source = arguments[index];
  43. if (source !== undefined && source !== null) {
  44. for (var nextKey in source) {
  45. if (Object.prototype.hasOwnProperty.call(source, nextKey)) {
  46. output[nextKey] = source[nextKey];
  47. }
  48. }
  49. }
  50. }
  51. return output;
  52. };
  53. }
  54. /**
  55. * Copyright (c) 2014-present, Facebook, Inc.
  56. *
  57. * This source code is licensed under the MIT license found in the
  58. * LICENSE file in the root directory of this source tree.
  59. */
  60. var runtime = function (exports) {
  61. var Op = Object.prototype;
  62. var hasOwn = Op.hasOwnProperty;
  63. var undefined$1; // More compressible than void 0.
  64. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  65. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  66. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  67. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  68. function define(obj, key, value) {
  69. Object.defineProperty(obj, key, {
  70. value: value,
  71. enumerable: true,
  72. configurable: true,
  73. writable: true
  74. });
  75. return obj[key];
  76. }
  77. try {
  78. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  79. define({}, "");
  80. } catch (err) {
  81. define = function define(obj, key, value) {
  82. return obj[key] = value;
  83. };
  84. }
  85. function wrap(innerFn, outerFn, self, tryLocsList) {
  86. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  87. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  88. var generator = Object.create(protoGenerator.prototype);
  89. var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
  90. // .throw, and .return methods.
  91. generator._invoke = makeInvokeMethod(innerFn, self, context);
  92. return generator;
  93. }
  94. exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
  95. // record like context.tryEntries[i].completion. This interface could
  96. // have been (and was previously) designed to take a closure to be
  97. // invoked without arguments, but in all the cases we care about we
  98. // already have an existing method we want to call, so there's no need
  99. // to create a new function object. We can even get away with assuming
  100. // the method takes exactly one argument, since that happens to be true
  101. // in every case, so we don't have to touch the arguments object. The
  102. // only additional allocation required is the completion record, which
  103. // has a stable shape and so hopefully should be cheap to allocate.
  104. function tryCatch(fn, obj, arg) {
  105. try {
  106. return {
  107. type: "normal",
  108. arg: fn.call(obj, arg)
  109. };
  110. } catch (err) {
  111. return {
  112. type: "throw",
  113. arg: err
  114. };
  115. }
  116. }
  117. var GenStateSuspendedStart = "suspendedStart";
  118. var GenStateSuspendedYield = "suspendedYield";
  119. var GenStateExecuting = "executing";
  120. var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
  121. // breaking out of the dispatch switch statement.
  122. var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
  123. // .constructor.prototype properties for functions that return Generator
  124. // objects. For full spec compliance, you may wish to configure your
  125. // minifier not to mangle the names of these two functions.
  126. function Generator() {}
  127. function GeneratorFunction() {}
  128. function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
  129. // don't natively support it.
  130. var IteratorPrototype = {};
  131. IteratorPrototype[iteratorSymbol] = function () {
  132. return this;
  133. };
  134. var getProto = Object.getPrototypeOf;
  135. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  136. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  137. // This environment has a native %IteratorPrototype%; use it instead
  138. // of the polyfill.
  139. IteratorPrototype = NativeIteratorPrototype;
  140. }
  141. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  142. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  143. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  144. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
  145. // Iterator interface in terms of a single ._invoke method.
  146. function defineIteratorMethods(prototype) {
  147. ["next", "throw", "return"].forEach(function (method) {
  148. define(prototype, method, function (arg) {
  149. return this._invoke(method, arg);
  150. });
  151. });
  152. }
  153. exports.isGeneratorFunction = function (genFun) {
  154. var ctor = typeof genFun === "function" && genFun.constructor;
  155. return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
  156. // do is to check its .name property.
  157. (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  158. };
  159. exports.mark = function (genFun) {
  160. if (Object.setPrototypeOf) {
  161. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  162. } else {
  163. genFun.__proto__ = GeneratorFunctionPrototype;
  164. define(genFun, toStringTagSymbol, "GeneratorFunction");
  165. }
  166. genFun.prototype = Object.create(Gp);
  167. return genFun;
  168. }; // Within the body of any async function, `await x` is transformed to
  169. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  170. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  171. // meant to be awaited.
  172. exports.awrap = function (arg) {
  173. return {
  174. __await: arg
  175. };
  176. };
  177. function AsyncIterator(generator, PromiseImpl) {
  178. function invoke(method, arg, resolve, reject) {
  179. var record = tryCatch(generator[method], generator, arg);
  180. if (record.type === "throw") {
  181. reject(record.arg);
  182. } else {
  183. var result = record.arg;
  184. var value = result.value;
  185. if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
  186. return PromiseImpl.resolve(value.__await).then(function (value) {
  187. invoke("next", value, resolve, reject);
  188. }, function (err) {
  189. invoke("throw", err, resolve, reject);
  190. });
  191. }
  192. return PromiseImpl.resolve(value).then(function (unwrapped) {
  193. // When a yielded Promise is resolved, its final value becomes
  194. // the .value of the Promise<{value,done}> result for the
  195. // current iteration.
  196. result.value = unwrapped;
  197. resolve(result);
  198. }, function (error) {
  199. // If a rejected Promise was yielded, throw the rejection back
  200. // into the async generator function so it can be handled there.
  201. return invoke("throw", error, resolve, reject);
  202. });
  203. }
  204. }
  205. var previousPromise;
  206. function enqueue(method, arg) {
  207. function callInvokeWithMethodAndArg() {
  208. return new PromiseImpl(function (resolve, reject) {
  209. invoke(method, arg, resolve, reject);
  210. });
  211. }
  212. return previousPromise = // If enqueue has been called before, then we want to wait until
  213. // all previous Promises have been resolved before calling invoke,
  214. // so that results are always delivered in the correct order. If
  215. // enqueue has not been called before, then it is important to
  216. // call invoke immediately, without waiting on a callback to fire,
  217. // so that the async generator function has the opportunity to do
  218. // any necessary setup in a predictable way. This predictability
  219. // is why the Promise constructor synchronously invokes its
  220. // executor callback, and why async functions synchronously
  221. // execute code before the first await. Since we implement simple
  222. // async functions in terms of async generators, it is especially
  223. // important to get this right, even though it requires care.
  224. previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
  225. // invocations of the iterator.
  226. callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  227. } // Define the unified helper method that is used to implement .next,
  228. // .throw, and .return (see defineIteratorMethods).
  229. this._invoke = enqueue;
  230. }
  231. defineIteratorMethods(AsyncIterator.prototype);
  232. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  233. return this;
  234. };
  235. exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
  236. // AsyncIterator objects; they just return a Promise for the value of
  237. // the final result produced by the iterator.
  238. exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  239. if (PromiseImpl === void 0) PromiseImpl = Promise;
  240. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  241. return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
  242. : iter.next().then(function (result) {
  243. return result.done ? result.value : iter.next();
  244. });
  245. };
  246. function makeInvokeMethod(innerFn, self, context) {
  247. var state = GenStateSuspendedStart;
  248. return function invoke(method, arg) {
  249. if (state === GenStateExecuting) {
  250. throw new Error("Generator is already running");
  251. }
  252. if (state === GenStateCompleted) {
  253. if (method === "throw") {
  254. throw arg;
  255. } // Be forgiving, per 25.3.3.3.3 of the spec:
  256. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  257. return doneResult();
  258. }
  259. context.method = method;
  260. context.arg = arg;
  261. while (true) {
  262. var delegate = context.delegate;
  263. if (delegate) {
  264. var delegateResult = maybeInvokeDelegate(delegate, context);
  265. if (delegateResult) {
  266. if (delegateResult === ContinueSentinel) continue;
  267. return delegateResult;
  268. }
  269. }
  270. if (context.method === "next") {
  271. // Setting context._sent for legacy support of Babel's
  272. // function.sent implementation.
  273. context.sent = context._sent = context.arg;
  274. } else if (context.method === "throw") {
  275. if (state === GenStateSuspendedStart) {
  276. state = GenStateCompleted;
  277. throw context.arg;
  278. }
  279. context.dispatchException(context.arg);
  280. } else if (context.method === "return") {
  281. context.abrupt("return", context.arg);
  282. }
  283. state = GenStateExecuting;
  284. var record = tryCatch(innerFn, self, context);
  285. if (record.type === "normal") {
  286. // If an exception is thrown from innerFn, we leave state ===
  287. // GenStateExecuting and loop back for another invocation.
  288. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  289. if (record.arg === ContinueSentinel) {
  290. continue;
  291. }
  292. return {
  293. value: record.arg,
  294. done: context.done
  295. };
  296. } else if (record.type === "throw") {
  297. state = GenStateCompleted; // Dispatch the exception by looping back around to the
  298. // context.dispatchException(context.arg) call above.
  299. context.method = "throw";
  300. context.arg = record.arg;
  301. }
  302. }
  303. };
  304. } // Call delegate.iterator[context.method](context.arg) and handle the
  305. // result, either by returning a { value, done } result from the
  306. // delegate iterator, or by modifying context.method and context.arg,
  307. // setting context.delegate to null, and returning the ContinueSentinel.
  308. function maybeInvokeDelegate(delegate, context) {
  309. var method = delegate.iterator[context.method];
  310. if (method === undefined$1) {
  311. // A .throw or .return when the delegate iterator has no .throw
  312. // method always terminates the yield* loop.
  313. context.delegate = null;
  314. if (context.method === "throw") {
  315. // Note: ["return"] must be used for ES3 parsing compatibility.
  316. if (delegate.iterator["return"]) {
  317. // If the delegate iterator has a return method, give it a
  318. // chance to clean up.
  319. context.method = "return";
  320. context.arg = undefined$1;
  321. maybeInvokeDelegate(delegate, context);
  322. if (context.method === "throw") {
  323. // If maybeInvokeDelegate(context) changed context.method from
  324. // "return" to "throw", let that override the TypeError below.
  325. return ContinueSentinel;
  326. }
  327. }
  328. context.method = "throw";
  329. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  330. }
  331. return ContinueSentinel;
  332. }
  333. var record = tryCatch(method, delegate.iterator, context.arg);
  334. if (record.type === "throw") {
  335. context.method = "throw";
  336. context.arg = record.arg;
  337. context.delegate = null;
  338. return ContinueSentinel;
  339. }
  340. var info = record.arg;
  341. if (!info) {
  342. context.method = "throw";
  343. context.arg = new TypeError("iterator result is not an object");
  344. context.delegate = null;
  345. return ContinueSentinel;
  346. }
  347. if (info.done) {
  348. // Assign the result of the finished delegate to the temporary
  349. // variable specified by delegate.resultName (see delegateYield).
  350. context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
  351. context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
  352. // exception, let the outer generator proceed normally. If
  353. // context.method was "next", forget context.arg since it has been
  354. // "consumed" by the delegate iterator. If context.method was
  355. // "return", allow the original .return call to continue in the
  356. // outer generator.
  357. if (context.method !== "return") {
  358. context.method = "next";
  359. context.arg = undefined$1;
  360. }
  361. } else {
  362. // Re-yield the result returned by the delegate method.
  363. return info;
  364. } // The delegate iterator is finished, so forget it and continue with
  365. // the outer generator.
  366. context.delegate = null;
  367. return ContinueSentinel;
  368. } // Define Generator.prototype.{next,throw,return} in terms of the
  369. // unified ._invoke helper method.
  370. defineIteratorMethods(Gp);
  371. define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
  372. // @@iterator function is called on it. Some browsers' implementations of the
  373. // iterator prototype chain incorrectly implement this, causing the Generator
  374. // object to not be returned from this call. This ensures that doesn't happen.
  375. // See https://github.com/facebook/regenerator/issues/274 for more details.
  376. Gp[iteratorSymbol] = function () {
  377. return this;
  378. };
  379. Gp.toString = function () {
  380. return "[object Generator]";
  381. };
  382. function pushTryEntry(locs) {
  383. var entry = {
  384. tryLoc: locs[0]
  385. };
  386. if (1 in locs) {
  387. entry.catchLoc = locs[1];
  388. }
  389. if (2 in locs) {
  390. entry.finallyLoc = locs[2];
  391. entry.afterLoc = locs[3];
  392. }
  393. this.tryEntries.push(entry);
  394. }
  395. function resetTryEntry(entry) {
  396. var record = entry.completion || {};
  397. record.type = "normal";
  398. delete record.arg;
  399. entry.completion = record;
  400. }
  401. function Context(tryLocsList) {
  402. // The root entry object (effectively a try statement without a catch
  403. // or a finally block) gives us a place to store values thrown from
  404. // locations where there is no enclosing try statement.
  405. this.tryEntries = [{
  406. tryLoc: "root"
  407. }];
  408. tryLocsList.forEach(pushTryEntry, this);
  409. this.reset(true);
  410. }
  411. exports.keys = function (object) {
  412. var keys = [];
  413. for (var key in object) {
  414. keys.push(key);
  415. }
  416. keys.reverse(); // Rather than returning an object with a next method, we keep
  417. // things simple and return the next function itself.
  418. return function next() {
  419. while (keys.length) {
  420. var key = keys.pop();
  421. if (key in object) {
  422. next.value = key;
  423. next.done = false;
  424. return next;
  425. }
  426. } // To avoid creating an additional object, we just hang the .value
  427. // and .done properties off the next function object itself. This
  428. // also ensures that the minifier will not anonymize the function.
  429. next.done = true;
  430. return next;
  431. };
  432. };
  433. function values(iterable) {
  434. if (iterable) {
  435. var iteratorMethod = iterable[iteratorSymbol];
  436. if (iteratorMethod) {
  437. return iteratorMethod.call(iterable);
  438. }
  439. if (typeof iterable.next === "function") {
  440. return iterable;
  441. }
  442. if (!isNaN(iterable.length)) {
  443. var i = -1,
  444. next = function next() {
  445. while (++i < iterable.length) {
  446. if (hasOwn.call(iterable, i)) {
  447. next.value = iterable[i];
  448. next.done = false;
  449. return next;
  450. }
  451. }
  452. next.value = undefined$1;
  453. next.done = true;
  454. return next;
  455. };
  456. return next.next = next;
  457. }
  458. } // Return an iterator with no values.
  459. return {
  460. next: doneResult
  461. };
  462. }
  463. exports.values = values;
  464. function doneResult() {
  465. return {
  466. value: undefined$1,
  467. done: true
  468. };
  469. }
  470. Context.prototype = {
  471. constructor: Context,
  472. reset: function reset(skipTempReset) {
  473. this.prev = 0;
  474. this.next = 0; // Resetting context._sent for legacy support of Babel's
  475. // function.sent implementation.
  476. this.sent = this._sent = undefined$1;
  477. this.done = false;
  478. this.delegate = null;
  479. this.method = "next";
  480. this.arg = undefined$1;
  481. this.tryEntries.forEach(resetTryEntry);
  482. if (!skipTempReset) {
  483. for (var name in this) {
  484. // Not sure about the optimal order of these conditions:
  485. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  486. this[name] = undefined$1;
  487. }
  488. }
  489. }
  490. },
  491. stop: function stop() {
  492. this.done = true;
  493. var rootEntry = this.tryEntries[0];
  494. var rootRecord = rootEntry.completion;
  495. if (rootRecord.type === "throw") {
  496. throw rootRecord.arg;
  497. }
  498. return this.rval;
  499. },
  500. dispatchException: function dispatchException(exception) {
  501. if (this.done) {
  502. throw exception;
  503. }
  504. var context = this;
  505. function handle(loc, caught) {
  506. record.type = "throw";
  507. record.arg = exception;
  508. context.next = loc;
  509. if (caught) {
  510. // If the dispatched exception was caught by a catch block,
  511. // then let that catch block handle the exception normally.
  512. context.method = "next";
  513. context.arg = undefined$1;
  514. }
  515. return !!caught;
  516. }
  517. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  518. var entry = this.tryEntries[i];
  519. var record = entry.completion;
  520. if (entry.tryLoc === "root") {
  521. // Exception thrown outside of any try block that could handle
  522. // it, so set the completion value of the entire function to
  523. // throw the exception.
  524. return handle("end");
  525. }
  526. if (entry.tryLoc <= this.prev) {
  527. var hasCatch = hasOwn.call(entry, "catchLoc");
  528. var hasFinally = hasOwn.call(entry, "finallyLoc");
  529. if (hasCatch && hasFinally) {
  530. if (this.prev < entry.catchLoc) {
  531. return handle(entry.catchLoc, true);
  532. } else if (this.prev < entry.finallyLoc) {
  533. return handle(entry.finallyLoc);
  534. }
  535. } else if (hasCatch) {
  536. if (this.prev < entry.catchLoc) {
  537. return handle(entry.catchLoc, true);
  538. }
  539. } else if (hasFinally) {
  540. if (this.prev < entry.finallyLoc) {
  541. return handle(entry.finallyLoc);
  542. }
  543. } else {
  544. throw new Error("try statement without catch or finally");
  545. }
  546. }
  547. }
  548. },
  549. abrupt: function abrupt(type, arg) {
  550. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  551. var entry = this.tryEntries[i];
  552. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  553. var finallyEntry = entry;
  554. break;
  555. }
  556. }
  557. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  558. // Ignore the finally entry if control is not jumping to a
  559. // location outside the try/catch block.
  560. finallyEntry = null;
  561. }
  562. var record = finallyEntry ? finallyEntry.completion : {};
  563. record.type = type;
  564. record.arg = arg;
  565. if (finallyEntry) {
  566. this.method = "next";
  567. this.next = finallyEntry.finallyLoc;
  568. return ContinueSentinel;
  569. }
  570. return this.complete(record);
  571. },
  572. complete: function complete(record, afterLoc) {
  573. if (record.type === "throw") {
  574. throw record.arg;
  575. }
  576. if (record.type === "break" || record.type === "continue") {
  577. this.next = record.arg;
  578. } else if (record.type === "return") {
  579. this.rval = this.arg = record.arg;
  580. this.method = "return";
  581. this.next = "end";
  582. } else if (record.type === "normal" && afterLoc) {
  583. this.next = afterLoc;
  584. }
  585. return ContinueSentinel;
  586. },
  587. finish: function finish(finallyLoc) {
  588. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  589. var entry = this.tryEntries[i];
  590. if (entry.finallyLoc === finallyLoc) {
  591. this.complete(entry.completion, entry.afterLoc);
  592. resetTryEntry(entry);
  593. return ContinueSentinel;
  594. }
  595. }
  596. },
  597. "catch": function _catch(tryLoc) {
  598. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  599. var entry = this.tryEntries[i];
  600. if (entry.tryLoc === tryLoc) {
  601. var record = entry.completion;
  602. if (record.type === "throw") {
  603. var thrown = record.arg;
  604. resetTryEntry(entry);
  605. }
  606. return thrown;
  607. }
  608. } // The context.catch method must only be called with a location
  609. // argument that corresponds to a known catch block.
  610. throw new Error("illegal catch attempt");
  611. },
  612. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  613. this.delegate = {
  614. iterator: values(iterable),
  615. resultName: resultName,
  616. nextLoc: nextLoc
  617. };
  618. if (this.method === "next") {
  619. // Deliberately forget the last sent value so that we don't
  620. // accidentally pass it on to the delegate.
  621. this.arg = undefined$1;
  622. }
  623. return ContinueSentinel;
  624. }
  625. }; // Regardless of whether this script is executing as a CommonJS module
  626. // or not, return the runtime object so that we can declare the variable
  627. // regeneratorRuntime in the outer scope, which allows this module to be
  628. // injected easily by `bin/regenerator --include-runtime script.js`.
  629. return exports;
  630. }( // If this script is executing as a CommonJS module, use module.exports
  631. // as the regeneratorRuntime namespace. Otherwise create a new empty
  632. // object. Either way, the resulting object will be used to initialize
  633. // the regeneratorRuntime variable at the top of this file.
  634. typeof module === "object" ? module.exports : {});
  635. try {
  636. regeneratorRuntime = runtime;
  637. } catch (accidentalStrictMode) {
  638. // This module should not be running in strict mode, so the above
  639. // assignment should always work unless something is misconfigured. Just
  640. // in case runtime.js accidentally runs in strict mode, we can escape
  641. // strict mode using a global Function call. This could conceivably fail
  642. // if a Content Security Policy forbids using Function, but in that case
  643. // the proper solution is to fix the accidental strict mode problem. If
  644. // you've misconfigured your bundler to force strict mode and applied a
  645. // CSP to forbid Function, and you're not willing to fix either of those
  646. // problems, please detail your unique predicament in a GitHub issue.
  647. Function("r", "regeneratorRuntime = r")(runtime);
  648. }
  649. var REVISION = '126dev';
  650. var MOUSE = {
  651. LEFT: 0,
  652. MIDDLE: 1,
  653. RIGHT: 2,
  654. ROTATE: 0,
  655. DOLLY: 1,
  656. PAN: 2
  657. };
  658. var TOUCH = {
  659. ROTATE: 0,
  660. PAN: 1,
  661. DOLLY_PAN: 2,
  662. DOLLY_ROTATE: 3
  663. };
  664. var CullFaceNone = 0;
  665. var CullFaceBack = 1;
  666. var CullFaceFront = 2;
  667. var CullFaceFrontBack = 3;
  668. var BasicShadowMap = 0;
  669. var PCFShadowMap = 1;
  670. var PCFSoftShadowMap = 2;
  671. var VSMShadowMap = 3;
  672. var FrontSide = 0;
  673. var BackSide = 1;
  674. var DoubleSide = 2;
  675. var FlatShading = 1;
  676. var SmoothShading = 2;
  677. var NoBlending = 0;
  678. var NormalBlending = 1;
  679. var AdditiveBlending = 2;
  680. var SubtractiveBlending = 3;
  681. var MultiplyBlending = 4;
  682. var CustomBlending = 5;
  683. var AddEquation = 100;
  684. var SubtractEquation = 101;
  685. var ReverseSubtractEquation = 102;
  686. var MinEquation = 103;
  687. var MaxEquation = 104;
  688. var ZeroFactor = 200;
  689. var OneFactor = 201;
  690. var SrcColorFactor = 202;
  691. var OneMinusSrcColorFactor = 203;
  692. var SrcAlphaFactor = 204;
  693. var OneMinusSrcAlphaFactor = 205;
  694. var DstAlphaFactor = 206;
  695. var OneMinusDstAlphaFactor = 207;
  696. var DstColorFactor = 208;
  697. var OneMinusDstColorFactor = 209;
  698. var SrcAlphaSaturateFactor = 210;
  699. var NeverDepth = 0;
  700. var AlwaysDepth = 1;
  701. var LessDepth = 2;
  702. var LessEqualDepth = 3;
  703. var EqualDepth = 4;
  704. var GreaterEqualDepth = 5;
  705. var GreaterDepth = 6;
  706. var NotEqualDepth = 7;
  707. var MultiplyOperation = 0;
  708. var MixOperation = 1;
  709. var AddOperation = 2;
  710. var NoToneMapping = 0;
  711. var LinearToneMapping = 1;
  712. var ReinhardToneMapping = 2;
  713. var CineonToneMapping = 3;
  714. var ACESFilmicToneMapping = 4;
  715. var CustomToneMapping = 5;
  716. var UVMapping = 300;
  717. var CubeReflectionMapping = 301;
  718. var CubeRefractionMapping = 302;
  719. var EquirectangularReflectionMapping = 303;
  720. var EquirectangularRefractionMapping = 304;
  721. var CubeUVReflectionMapping = 306;
  722. var CubeUVRefractionMapping = 307;
  723. var RepeatWrapping = 1000;
  724. var ClampToEdgeWrapping = 1001;
  725. var MirroredRepeatWrapping = 1002;
  726. var NearestFilter = 1003;
  727. var NearestMipmapNearestFilter = 1004;
  728. var NearestMipMapNearestFilter = 1004;
  729. var NearestMipmapLinearFilter = 1005;
  730. var NearestMipMapLinearFilter = 1005;
  731. var LinearFilter = 1006;
  732. var LinearMipmapNearestFilter = 1007;
  733. var LinearMipMapNearestFilter = 1007;
  734. var LinearMipmapLinearFilter = 1008;
  735. var LinearMipMapLinearFilter = 1008;
  736. var UnsignedByteType = 1009;
  737. var ByteType = 1010;
  738. var ShortType = 1011;
  739. var UnsignedShortType = 1012;
  740. var IntType = 1013;
  741. var UnsignedIntType = 1014;
  742. var FloatType = 1015;
  743. var HalfFloatType = 1016;
  744. var UnsignedShort4444Type = 1017;
  745. var UnsignedShort5551Type = 1018;
  746. var UnsignedShort565Type = 1019;
  747. var UnsignedInt248Type = 1020;
  748. var AlphaFormat = 1021;
  749. var RGBFormat = 1022;
  750. var RGBAFormat = 1023;
  751. var LuminanceFormat = 1024;
  752. var LuminanceAlphaFormat = 1025;
  753. var RGBEFormat = RGBAFormat;
  754. var DepthFormat = 1026;
  755. var DepthStencilFormat = 1027;
  756. var RedFormat = 1028;
  757. var RedIntegerFormat = 1029;
  758. var RGFormat = 1030;
  759. var RGIntegerFormat = 1031;
  760. var RGBIntegerFormat = 1032;
  761. var RGBAIntegerFormat = 1033;
  762. var RGB_S3TC_DXT1_Format = 33776;
  763. var RGBA_S3TC_DXT1_Format = 33777;
  764. var RGBA_S3TC_DXT3_Format = 33778;
  765. var RGBA_S3TC_DXT5_Format = 33779;
  766. var RGB_PVRTC_4BPPV1_Format = 35840;
  767. var RGB_PVRTC_2BPPV1_Format = 35841;
  768. var RGBA_PVRTC_4BPPV1_Format = 35842;
  769. var RGBA_PVRTC_2BPPV1_Format = 35843;
  770. var RGB_ETC1_Format = 36196;
  771. var RGB_ETC2_Format = 37492;
  772. var RGBA_ETC2_EAC_Format = 37496;
  773. var RGBA_ASTC_4x4_Format = 37808;
  774. var RGBA_ASTC_5x4_Format = 37809;
  775. var RGBA_ASTC_5x5_Format = 37810;
  776. var RGBA_ASTC_6x5_Format = 37811;
  777. var RGBA_ASTC_6x6_Format = 37812;
  778. var RGBA_ASTC_8x5_Format = 37813;
  779. var RGBA_ASTC_8x6_Format = 37814;
  780. var RGBA_ASTC_8x8_Format = 37815;
  781. var RGBA_ASTC_10x5_Format = 37816;
  782. var RGBA_ASTC_10x6_Format = 37817;
  783. var RGBA_ASTC_10x8_Format = 37818;
  784. var RGBA_ASTC_10x10_Format = 37819;
  785. var RGBA_ASTC_12x10_Format = 37820;
  786. var RGBA_ASTC_12x12_Format = 37821;
  787. var RGBA_BPTC_Format = 36492;
  788. var SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  789. var SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  790. var SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  791. var SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  792. var SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  793. var SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  794. var SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  795. var SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  796. var SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  797. var SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  798. var SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  799. var SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  800. var SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  801. var SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  802. var LoopOnce = 2200;
  803. var LoopRepeat = 2201;
  804. var LoopPingPong = 2202;
  805. var InterpolateDiscrete = 2300;
  806. var InterpolateLinear = 2301;
  807. var InterpolateSmooth = 2302;
  808. var ZeroCurvatureEnding = 2400;
  809. var ZeroSlopeEnding = 2401;
  810. var WrapAroundEnding = 2402;
  811. var NormalAnimationBlendMode = 2500;
  812. var AdditiveAnimationBlendMode = 2501;
  813. var TrianglesDrawMode = 0;
  814. var TriangleStripDrawMode = 1;
  815. var TriangleFanDrawMode = 2;
  816. var LinearEncoding = 3000;
  817. var sRGBEncoding = 3001;
  818. var GammaEncoding = 3007;
  819. var RGBEEncoding = 3002;
  820. var LogLuvEncoding = 3003;
  821. var RGBM7Encoding = 3004;
  822. var RGBM16Encoding = 3005;
  823. var RGBDEncoding = 3006;
  824. var BasicDepthPacking = 3200;
  825. var RGBADepthPacking = 3201;
  826. var TangentSpaceNormalMap = 0;
  827. var ObjectSpaceNormalMap = 1;
  828. var ZeroStencilOp = 0;
  829. var KeepStencilOp = 7680;
  830. var ReplaceStencilOp = 7681;
  831. var IncrementStencilOp = 7682;
  832. var DecrementStencilOp = 7683;
  833. var IncrementWrapStencilOp = 34055;
  834. var DecrementWrapStencilOp = 34056;
  835. var InvertStencilOp = 5386;
  836. var NeverStencilFunc = 512;
  837. var LessStencilFunc = 513;
  838. var EqualStencilFunc = 514;
  839. var LessEqualStencilFunc = 515;
  840. var GreaterStencilFunc = 516;
  841. var NotEqualStencilFunc = 517;
  842. var GreaterEqualStencilFunc = 518;
  843. var AlwaysStencilFunc = 519;
  844. var StaticDrawUsage = 35044;
  845. var DynamicDrawUsage = 35048;
  846. var StreamDrawUsage = 35040;
  847. var StaticReadUsage = 35045;
  848. var DynamicReadUsage = 35049;
  849. var StreamReadUsage = 35041;
  850. var StaticCopyUsage = 35046;
  851. var DynamicCopyUsage = 35050;
  852. var StreamCopyUsage = 35042;
  853. var GLSL1 = '100';
  854. var GLSL3 = '300 es';
  855. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  856. try {
  857. var info = gen[key](arg);
  858. var value = info.value;
  859. } catch (error) {
  860. reject(error);
  861. return;
  862. }
  863. if (info.done) {
  864. resolve(value);
  865. } else {
  866. Promise.resolve(value).then(_next, _throw);
  867. }
  868. }
  869. function _asyncToGenerator(fn) {
  870. return function () {
  871. var self = this,
  872. args = arguments;
  873. return new Promise(function (resolve, reject) {
  874. var gen = fn.apply(self, args);
  875. function _next(value) {
  876. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  877. }
  878. function _throw(err) {
  879. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  880. }
  881. _next(undefined);
  882. });
  883. };
  884. }
  885. function _defineProperties(target, props) {
  886. for (var i = 0; i < props.length; i++) {
  887. var descriptor = props[i];
  888. descriptor.enumerable = descriptor.enumerable || false;
  889. descriptor.configurable = true;
  890. if ("value" in descriptor) descriptor.writable = true;
  891. Object.defineProperty(target, descriptor.key, descriptor);
  892. }
  893. }
  894. function _createClass(Constructor, protoProps, staticProps) {
  895. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  896. if (staticProps) _defineProperties(Constructor, staticProps);
  897. return Constructor;
  898. }
  899. function _inheritsLoose(subClass, superClass) {
  900. subClass.prototype = Object.create(superClass.prototype);
  901. subClass.prototype.constructor = subClass;
  902. subClass.__proto__ = superClass;
  903. }
  904. function _assertThisInitialized(self) {
  905. if (self === void 0) {
  906. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  907. }
  908. return self;
  909. }
  910. function _unsupportedIterableToArray(o, minLen) {
  911. if (!o) return;
  912. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  913. var n = Object.prototype.toString.call(o).slice(8, -1);
  914. if (n === "Object" && o.constructor) n = o.constructor.name;
  915. if (n === "Map" || n === "Set") return Array.from(o);
  916. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  917. }
  918. function _arrayLikeToArray(arr, len) {
  919. if (len == null || len > arr.length) len = arr.length;
  920. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  921. return arr2;
  922. }
  923. function _createForOfIteratorHelperLoose(o, allowArrayLike) {
  924. var it;
  925. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  926. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  927. if (it) o = it;
  928. var i = 0;
  929. return function () {
  930. if (i >= o.length) return {
  931. done: true
  932. };
  933. return {
  934. done: false,
  935. value: o[i++]
  936. };
  937. };
  938. }
  939. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  940. }
  941. it = o[Symbol.iterator]();
  942. return it.next.bind(it);
  943. }
  944. /**
  945. * https://github.com/mrdoob/eventdispatcher.js/
  946. */
  947. function EventDispatcher() {}
  948. Object.assign(EventDispatcher.prototype, {
  949. addEventListener: function addEventListener(type, listener) {
  950. if (this._listeners === undefined) this._listeners = {};
  951. var listeners = this._listeners;
  952. if (listeners[type] === undefined) {
  953. listeners[type] = [];
  954. }
  955. if (listeners[type].indexOf(listener) === -1) {
  956. listeners[type].push(listener);
  957. }
  958. },
  959. hasEventListener: function hasEventListener(type, listener) {
  960. if (this._listeners === undefined) return false;
  961. var listeners = this._listeners;
  962. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1;
  963. },
  964. removeEventListener: function removeEventListener(type, listener) {
  965. if (this._listeners === undefined) return;
  966. var listeners = this._listeners;
  967. var listenerArray = listeners[type];
  968. if (listenerArray !== undefined) {
  969. var index = listenerArray.indexOf(listener);
  970. if (index !== -1) {
  971. listenerArray.splice(index, 1);
  972. }
  973. }
  974. },
  975. dispatchEvent: function dispatchEvent(event) {
  976. if (this._listeners === undefined) return;
  977. var listeners = this._listeners;
  978. var listenerArray = listeners[event.type];
  979. if (listenerArray !== undefined) {
  980. event.target = this; // Make a copy, in case listeners are removed while iterating.
  981. var array = listenerArray.slice(0);
  982. for (var i = 0, l = array.length; i < l; i++) {
  983. array[i].call(this, event);
  984. }
  985. }
  986. }
  987. });
  988. var _lut = [];
  989. for (var i = 0; i < 256; i++) {
  990. _lut[i] = (i < 16 ? '0' : '') + i.toString(16);
  991. }
  992. var _seed = 1234567;
  993. var MathUtils = {
  994. DEG2RAD: Math.PI / 180,
  995. RAD2DEG: 180 / Math.PI,
  996. generateUUID: function generateUUID() {
  997. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  998. var d0 = Math.random() * 0xffffffff | 0;
  999. var d1 = Math.random() * 0xffffffff | 0;
  1000. var d2 = Math.random() * 0xffffffff | 0;
  1001. var d3 = Math.random() * 0xffffffff | 0;
  1002. 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.
  1003. return uuid.toUpperCase();
  1004. },
  1005. clamp: function clamp(value, min, max) {
  1006. return Math.max(min, Math.min(max, value));
  1007. },
  1008. // compute euclidian modulo of m % n
  1009. // https://en.wikipedia.org/wiki/Modulo_operation
  1010. euclideanModulo: function euclideanModulo(n, m) {
  1011. return (n % m + m) % m;
  1012. },
  1013. // Linear mapping from range <a1, a2> to range <b1, b2>
  1014. mapLinear: function mapLinear(x, a1, a2, b1, b2) {
  1015. return b1 + (x - a1) * (b2 - b1) / (a2 - a1);
  1016. },
  1017. // https://en.wikipedia.org/wiki/Linear_interpolation
  1018. lerp: function lerp(x, y, t) {
  1019. return (1 - t) * x + t * y;
  1020. },
  1021. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  1022. damp: function damp(x, y, lambda, dt) {
  1023. return MathUtils.lerp(x, y, 1 - Math.exp(-lambda * dt));
  1024. },
  1025. // https://www.desmos.com/calculator/vcsjnyz7x4
  1026. pingpong: function pingpong(x, length) {
  1027. if (length === void 0) {
  1028. length = 1;
  1029. }
  1030. return length - Math.abs(MathUtils.euclideanModulo(x, length * 2) - length);
  1031. },
  1032. // http://en.wikipedia.org/wiki/Smoothstep
  1033. smoothstep: function smoothstep(x, min, max) {
  1034. if (x <= min) return 0;
  1035. if (x >= max) return 1;
  1036. x = (x - min) / (max - min);
  1037. return x * x * (3 - 2 * x);
  1038. },
  1039. smootherstep: function smootherstep(x, min, max) {
  1040. if (x <= min) return 0;
  1041. if (x >= max) return 1;
  1042. x = (x - min) / (max - min);
  1043. return x * x * x * (x * (x * 6 - 15) + 10);
  1044. },
  1045. // Random integer from <low, high> interval
  1046. randInt: function randInt(low, high) {
  1047. return low + Math.floor(Math.random() * (high - low + 1));
  1048. },
  1049. // Random float from <low, high> interval
  1050. randFloat: function randFloat(low, high) {
  1051. return low + Math.random() * (high - low);
  1052. },
  1053. // Random float from <-range/2, range/2> interval
  1054. randFloatSpread: function randFloatSpread(range) {
  1055. return range * (0.5 - Math.random());
  1056. },
  1057. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  1058. seededRandom: function seededRandom(s) {
  1059. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  1060. _seed = _seed * 16807 % 2147483647;
  1061. return (_seed - 1) / 2147483646;
  1062. },
  1063. degToRad: function degToRad(degrees) {
  1064. return degrees * MathUtils.DEG2RAD;
  1065. },
  1066. radToDeg: function radToDeg(radians) {
  1067. return radians * MathUtils.RAD2DEG;
  1068. },
  1069. isPowerOfTwo: function isPowerOfTwo(value) {
  1070. return (value & value - 1) === 0 && value !== 0;
  1071. },
  1072. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  1073. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  1074. },
  1075. floorPowerOfTwo: function floorPowerOfTwo(value) {
  1076. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  1077. },
  1078. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  1079. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  1080. // rotations are applied to the axes in the order specified by 'order'
  1081. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  1082. // angles are in radians
  1083. var cos = Math.cos;
  1084. var sin = Math.sin;
  1085. var c2 = cos(b / 2);
  1086. var s2 = sin(b / 2);
  1087. var c13 = cos((a + c) / 2);
  1088. var s13 = sin((a + c) / 2);
  1089. var c1_3 = cos((a - c) / 2);
  1090. var s1_3 = sin((a - c) / 2);
  1091. var c3_1 = cos((c - a) / 2);
  1092. var s3_1 = sin((c - a) / 2);
  1093. switch (order) {
  1094. case 'XYX':
  1095. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  1096. break;
  1097. case 'YZY':
  1098. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  1099. break;
  1100. case 'ZXZ':
  1101. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  1102. break;
  1103. case 'XZX':
  1104. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  1105. break;
  1106. case 'YXY':
  1107. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  1108. break;
  1109. case 'ZYZ':
  1110. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  1111. break;
  1112. default:
  1113. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  1114. }
  1115. }
  1116. };
  1117. var Vector2 = /*#__PURE__*/function () {
  1118. function Vector2(x, y) {
  1119. if (x === void 0) {
  1120. x = 0;
  1121. }
  1122. if (y === void 0) {
  1123. y = 0;
  1124. }
  1125. Object.defineProperty(this, 'isVector2', {
  1126. value: true
  1127. });
  1128. this.x = x;
  1129. this.y = y;
  1130. }
  1131. var _proto = Vector2.prototype;
  1132. _proto.set = function set(x, y) {
  1133. this.x = x;
  1134. this.y = y;
  1135. return this;
  1136. };
  1137. _proto.setScalar = function setScalar(scalar) {
  1138. this.x = scalar;
  1139. this.y = scalar;
  1140. return this;
  1141. };
  1142. _proto.setX = function setX(x) {
  1143. this.x = x;
  1144. return this;
  1145. };
  1146. _proto.setY = function setY(y) {
  1147. this.y = y;
  1148. return this;
  1149. };
  1150. _proto.setComponent = function setComponent(index, value) {
  1151. switch (index) {
  1152. case 0:
  1153. this.x = value;
  1154. break;
  1155. case 1:
  1156. this.y = value;
  1157. break;
  1158. default:
  1159. throw new Error('index is out of range: ' + index);
  1160. }
  1161. return this;
  1162. };
  1163. _proto.getComponent = function getComponent(index) {
  1164. switch (index) {
  1165. case 0:
  1166. return this.x;
  1167. case 1:
  1168. return this.y;
  1169. default:
  1170. throw new Error('index is out of range: ' + index);
  1171. }
  1172. };
  1173. _proto.clone = function clone() {
  1174. return new this.constructor(this.x, this.y);
  1175. };
  1176. _proto.copy = function copy(v) {
  1177. this.x = v.x;
  1178. this.y = v.y;
  1179. return this;
  1180. };
  1181. _proto.add = function add(v, w) {
  1182. if (w !== undefined) {
  1183. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1184. return this.addVectors(v, w);
  1185. }
  1186. this.x += v.x;
  1187. this.y += v.y;
  1188. return this;
  1189. };
  1190. _proto.addScalar = function addScalar(s) {
  1191. this.x += s;
  1192. this.y += s;
  1193. return this;
  1194. };
  1195. _proto.addVectors = function addVectors(a, b) {
  1196. this.x = a.x + b.x;
  1197. this.y = a.y + b.y;
  1198. return this;
  1199. };
  1200. _proto.addScaledVector = function addScaledVector(v, s) {
  1201. this.x += v.x * s;
  1202. this.y += v.y * s;
  1203. return this;
  1204. };
  1205. _proto.sub = function sub(v, w) {
  1206. if (w !== undefined) {
  1207. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1208. return this.subVectors(v, w);
  1209. }
  1210. this.x -= v.x;
  1211. this.y -= v.y;
  1212. return this;
  1213. };
  1214. _proto.subScalar = function subScalar(s) {
  1215. this.x -= s;
  1216. this.y -= s;
  1217. return this;
  1218. };
  1219. _proto.subVectors = function subVectors(a, b) {
  1220. this.x = a.x - b.x;
  1221. this.y = a.y - b.y;
  1222. return this;
  1223. };
  1224. _proto.multiply = function multiply(v) {
  1225. this.x *= v.x;
  1226. this.y *= v.y;
  1227. return this;
  1228. };
  1229. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1230. this.x *= scalar;
  1231. this.y *= scalar;
  1232. return this;
  1233. };
  1234. _proto.divide = function divide(v) {
  1235. this.x /= v.x;
  1236. this.y /= v.y;
  1237. return this;
  1238. };
  1239. _proto.divideScalar = function divideScalar(scalar) {
  1240. return this.multiplyScalar(1 / scalar);
  1241. };
  1242. _proto.applyMatrix3 = function applyMatrix3(m) {
  1243. var x = this.x,
  1244. y = this.y;
  1245. var e = m.elements;
  1246. this.x = e[0] * x + e[3] * y + e[6];
  1247. this.y = e[1] * x + e[4] * y + e[7];
  1248. return this;
  1249. };
  1250. _proto.min = function min(v) {
  1251. this.x = Math.min(this.x, v.x);
  1252. this.y = Math.min(this.y, v.y);
  1253. return this;
  1254. };
  1255. _proto.max = function max(v) {
  1256. this.x = Math.max(this.x, v.x);
  1257. this.y = Math.max(this.y, v.y);
  1258. return this;
  1259. };
  1260. _proto.clamp = function clamp(min, max) {
  1261. // assumes min < max, componentwise
  1262. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1263. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1264. return this;
  1265. };
  1266. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1267. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1268. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1269. return this;
  1270. };
  1271. _proto.clampLength = function clampLength(min, max) {
  1272. var length = this.length();
  1273. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1274. };
  1275. _proto.floor = function floor() {
  1276. this.x = Math.floor(this.x);
  1277. this.y = Math.floor(this.y);
  1278. return this;
  1279. };
  1280. _proto.ceil = function ceil() {
  1281. this.x = Math.ceil(this.x);
  1282. this.y = Math.ceil(this.y);
  1283. return this;
  1284. };
  1285. _proto.round = function round() {
  1286. this.x = Math.round(this.x);
  1287. this.y = Math.round(this.y);
  1288. return this;
  1289. };
  1290. _proto.roundToZero = function roundToZero() {
  1291. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1292. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1293. return this;
  1294. };
  1295. _proto.negate = function negate() {
  1296. this.x = -this.x;
  1297. this.y = -this.y;
  1298. return this;
  1299. };
  1300. _proto.dot = function dot(v) {
  1301. return this.x * v.x + this.y * v.y;
  1302. };
  1303. _proto.cross = function cross(v) {
  1304. return this.x * v.y - this.y * v.x;
  1305. };
  1306. _proto.lengthSq = function lengthSq() {
  1307. return this.x * this.x + this.y * this.y;
  1308. };
  1309. _proto.length = function length() {
  1310. return Math.sqrt(this.x * this.x + this.y * this.y);
  1311. };
  1312. _proto.manhattanLength = function manhattanLength() {
  1313. return Math.abs(this.x) + Math.abs(this.y);
  1314. };
  1315. _proto.normalize = function normalize() {
  1316. return this.divideScalar(this.length() || 1);
  1317. };
  1318. _proto.angle = function angle() {
  1319. // computes the angle in radians with respect to the positive x-axis
  1320. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  1321. return angle;
  1322. };
  1323. _proto.distanceTo = function distanceTo(v) {
  1324. return Math.sqrt(this.distanceToSquared(v));
  1325. };
  1326. _proto.distanceToSquared = function distanceToSquared(v) {
  1327. var dx = this.x - v.x,
  1328. dy = this.y - v.y;
  1329. return dx * dx + dy * dy;
  1330. };
  1331. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  1332. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  1333. };
  1334. _proto.setLength = function setLength(length) {
  1335. return this.normalize().multiplyScalar(length);
  1336. };
  1337. _proto.lerp = function lerp(v, alpha) {
  1338. this.x += (v.x - this.x) * alpha;
  1339. this.y += (v.y - this.y) * alpha;
  1340. return this;
  1341. };
  1342. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1343. this.x = v1.x + (v2.x - v1.x) * alpha;
  1344. this.y = v1.y + (v2.y - v1.y) * alpha;
  1345. return this;
  1346. };
  1347. _proto.equals = function equals(v) {
  1348. return v.x === this.x && v.y === this.y;
  1349. };
  1350. _proto.fromArray = function fromArray(array, offset) {
  1351. if (offset === void 0) {
  1352. offset = 0;
  1353. }
  1354. this.x = array[offset];
  1355. this.y = array[offset + 1];
  1356. return this;
  1357. };
  1358. _proto.toArray = function toArray(array, offset) {
  1359. if (array === void 0) {
  1360. array = [];
  1361. }
  1362. if (offset === void 0) {
  1363. offset = 0;
  1364. }
  1365. array[offset] = this.x;
  1366. array[offset + 1] = this.y;
  1367. return array;
  1368. };
  1369. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1370. if (offset !== undefined) {
  1371. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  1372. }
  1373. this.x = attribute.getX(index);
  1374. this.y = attribute.getY(index);
  1375. return this;
  1376. };
  1377. _proto.rotateAround = function rotateAround(center, angle) {
  1378. var c = Math.cos(angle),
  1379. s = Math.sin(angle);
  1380. var x = this.x - center.x;
  1381. var y = this.y - center.y;
  1382. this.x = x * c - y * s + center.x;
  1383. this.y = x * s + y * c + center.y;
  1384. return this;
  1385. };
  1386. _proto.random = function random() {
  1387. this.x = Math.random();
  1388. this.y = Math.random();
  1389. return this;
  1390. };
  1391. _createClass(Vector2, [{
  1392. key: "width",
  1393. get: function get() {
  1394. return this.x;
  1395. },
  1396. set: function set(value) {
  1397. this.x = value;
  1398. }
  1399. }, {
  1400. key: "height",
  1401. get: function get() {
  1402. return this.y;
  1403. },
  1404. set: function set(value) {
  1405. this.y = value;
  1406. }
  1407. }]);
  1408. return Vector2;
  1409. }();
  1410. var Matrix3 = /*#__PURE__*/function () {
  1411. function Matrix3() {
  1412. Object.defineProperty(this, 'isMatrix3', {
  1413. value: true
  1414. });
  1415. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  1416. if (arguments.length > 0) {
  1417. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  1418. }
  1419. }
  1420. var _proto = Matrix3.prototype;
  1421. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  1422. var te = this.elements;
  1423. te[0] = n11;
  1424. te[1] = n21;
  1425. te[2] = n31;
  1426. te[3] = n12;
  1427. te[4] = n22;
  1428. te[5] = n32;
  1429. te[6] = n13;
  1430. te[7] = n23;
  1431. te[8] = n33;
  1432. return this;
  1433. };
  1434. _proto.identity = function identity() {
  1435. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  1436. return this;
  1437. };
  1438. _proto.clone = function clone() {
  1439. return new this.constructor().fromArray(this.elements);
  1440. };
  1441. _proto.copy = function copy(m) {
  1442. var te = this.elements;
  1443. var me = m.elements;
  1444. te[0] = me[0];
  1445. te[1] = me[1];
  1446. te[2] = me[2];
  1447. te[3] = me[3];
  1448. te[4] = me[4];
  1449. te[5] = me[5];
  1450. te[6] = me[6];
  1451. te[7] = me[7];
  1452. te[8] = me[8];
  1453. return this;
  1454. };
  1455. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  1456. xAxis.setFromMatrix3Column(this, 0);
  1457. yAxis.setFromMatrix3Column(this, 1);
  1458. zAxis.setFromMatrix3Column(this, 2);
  1459. return this;
  1460. };
  1461. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  1462. var me = m.elements;
  1463. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  1464. return this;
  1465. };
  1466. _proto.multiply = function multiply(m) {
  1467. return this.multiplyMatrices(this, m);
  1468. };
  1469. _proto.premultiply = function premultiply(m) {
  1470. return this.multiplyMatrices(m, this);
  1471. };
  1472. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  1473. var ae = a.elements;
  1474. var be = b.elements;
  1475. var te = this.elements;
  1476. var a11 = ae[0],
  1477. a12 = ae[3],
  1478. a13 = ae[6];
  1479. var a21 = ae[1],
  1480. a22 = ae[4],
  1481. a23 = ae[7];
  1482. var a31 = ae[2],
  1483. a32 = ae[5],
  1484. a33 = ae[8];
  1485. var b11 = be[0],
  1486. b12 = be[3],
  1487. b13 = be[6];
  1488. var b21 = be[1],
  1489. b22 = be[4],
  1490. b23 = be[7];
  1491. var b31 = be[2],
  1492. b32 = be[5],
  1493. b33 = be[8];
  1494. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  1495. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  1496. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  1497. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  1498. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  1499. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  1500. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  1501. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  1502. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  1503. return this;
  1504. };
  1505. _proto.multiplyScalar = function multiplyScalar(s) {
  1506. var te = this.elements;
  1507. te[0] *= s;
  1508. te[3] *= s;
  1509. te[6] *= s;
  1510. te[1] *= s;
  1511. te[4] *= s;
  1512. te[7] *= s;
  1513. te[2] *= s;
  1514. te[5] *= s;
  1515. te[8] *= s;
  1516. return this;
  1517. };
  1518. _proto.determinant = function determinant() {
  1519. var te = this.elements;
  1520. var a = te[0],
  1521. b = te[1],
  1522. c = te[2],
  1523. d = te[3],
  1524. e = te[4],
  1525. f = te[5],
  1526. g = te[6],
  1527. h = te[7],
  1528. i = te[8];
  1529. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1530. };
  1531. _proto.invert = function invert() {
  1532. var te = this.elements,
  1533. n11 = te[0],
  1534. n21 = te[1],
  1535. n31 = te[2],
  1536. n12 = te[3],
  1537. n22 = te[4],
  1538. n32 = te[5],
  1539. n13 = te[6],
  1540. n23 = te[7],
  1541. n33 = te[8],
  1542. t11 = n33 * n22 - n32 * n23,
  1543. t12 = n32 * n13 - n33 * n12,
  1544. t13 = n23 * n12 - n22 * n13,
  1545. det = n11 * t11 + n21 * t12 + n31 * t13;
  1546. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  1547. var detInv = 1 / det;
  1548. te[0] = t11 * detInv;
  1549. te[1] = (n31 * n23 - n33 * n21) * detInv;
  1550. te[2] = (n32 * n21 - n31 * n22) * detInv;
  1551. te[3] = t12 * detInv;
  1552. te[4] = (n33 * n11 - n31 * n13) * detInv;
  1553. te[5] = (n31 * n12 - n32 * n11) * detInv;
  1554. te[6] = t13 * detInv;
  1555. te[7] = (n21 * n13 - n23 * n11) * detInv;
  1556. te[8] = (n22 * n11 - n21 * n12) * detInv;
  1557. return this;
  1558. };
  1559. _proto.transpose = function transpose() {
  1560. var tmp;
  1561. var m = this.elements;
  1562. tmp = m[1];
  1563. m[1] = m[3];
  1564. m[3] = tmp;
  1565. tmp = m[2];
  1566. m[2] = m[6];
  1567. m[6] = tmp;
  1568. tmp = m[5];
  1569. m[5] = m[7];
  1570. m[7] = tmp;
  1571. return this;
  1572. };
  1573. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  1574. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  1575. };
  1576. _proto.transposeIntoArray = function transposeIntoArray(r) {
  1577. var m = this.elements;
  1578. r[0] = m[0];
  1579. r[1] = m[3];
  1580. r[2] = m[6];
  1581. r[3] = m[1];
  1582. r[4] = m[4];
  1583. r[5] = m[7];
  1584. r[6] = m[2];
  1585. r[7] = m[5];
  1586. r[8] = m[8];
  1587. return this;
  1588. };
  1589. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  1590. var c = Math.cos(rotation);
  1591. var s = Math.sin(rotation);
  1592. 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);
  1593. return this;
  1594. };
  1595. _proto.scale = function scale(sx, sy) {
  1596. var te = this.elements;
  1597. te[0] *= sx;
  1598. te[3] *= sx;
  1599. te[6] *= sx;
  1600. te[1] *= sy;
  1601. te[4] *= sy;
  1602. te[7] *= sy;
  1603. return this;
  1604. };
  1605. _proto.rotate = function rotate(theta) {
  1606. var c = Math.cos(theta);
  1607. var s = Math.sin(theta);
  1608. var te = this.elements;
  1609. var a11 = te[0],
  1610. a12 = te[3],
  1611. a13 = te[6];
  1612. var a21 = te[1],
  1613. a22 = te[4],
  1614. a23 = te[7];
  1615. te[0] = c * a11 + s * a21;
  1616. te[3] = c * a12 + s * a22;
  1617. te[6] = c * a13 + s * a23;
  1618. te[1] = -s * a11 + c * a21;
  1619. te[4] = -s * a12 + c * a22;
  1620. te[7] = -s * a13 + c * a23;
  1621. return this;
  1622. };
  1623. _proto.translate = function translate(tx, ty) {
  1624. var te = this.elements;
  1625. te[0] += tx * te[2];
  1626. te[3] += tx * te[5];
  1627. te[6] += tx * te[8];
  1628. te[1] += ty * te[2];
  1629. te[4] += ty * te[5];
  1630. te[7] += ty * te[8];
  1631. return this;
  1632. };
  1633. _proto.equals = function equals(matrix) {
  1634. var te = this.elements;
  1635. var me = matrix.elements;
  1636. for (var i = 0; i < 9; i++) {
  1637. if (te[i] !== me[i]) return false;
  1638. }
  1639. return true;
  1640. };
  1641. _proto.fromArray = function fromArray(array, offset) {
  1642. if (offset === void 0) {
  1643. offset = 0;
  1644. }
  1645. for (var i = 0; i < 9; i++) {
  1646. this.elements[i] = array[i + offset];
  1647. }
  1648. return this;
  1649. };
  1650. _proto.toArray = function toArray(array, offset) {
  1651. if (array === void 0) {
  1652. array = [];
  1653. }
  1654. if (offset === void 0) {
  1655. offset = 0;
  1656. }
  1657. var te = this.elements;
  1658. array[offset] = te[0];
  1659. array[offset + 1] = te[1];
  1660. array[offset + 2] = te[2];
  1661. array[offset + 3] = te[3];
  1662. array[offset + 4] = te[4];
  1663. array[offset + 5] = te[5];
  1664. array[offset + 6] = te[6];
  1665. array[offset + 7] = te[7];
  1666. array[offset + 8] = te[8];
  1667. return array;
  1668. };
  1669. return Matrix3;
  1670. }();
  1671. var _canvas;
  1672. var ImageUtils = {
  1673. getDataURL: function getDataURL(image) {
  1674. if (/^data:/i.test(image.src)) {
  1675. return image.src;
  1676. }
  1677. if (typeof HTMLCanvasElement == 'undefined') {
  1678. return image.src;
  1679. }
  1680. var canvas;
  1681. if (image instanceof HTMLCanvasElement) {
  1682. canvas = image;
  1683. } else {
  1684. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1685. _canvas.width = image.width;
  1686. _canvas.height = image.height;
  1687. var context = _canvas.getContext('2d');
  1688. if (image instanceof ImageData) {
  1689. context.putImageData(image, 0, 0);
  1690. } else {
  1691. context.drawImage(image, 0, 0, image.width, image.height);
  1692. }
  1693. canvas = _canvas;
  1694. }
  1695. if (canvas.width > 2048 || canvas.height > 2048) {
  1696. return canvas.toDataURL('image/jpeg', 0.6);
  1697. } else {
  1698. return canvas.toDataURL('image/png');
  1699. }
  1700. }
  1701. };
  1702. var textureId = 0;
  1703. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1704. if (image === void 0) {
  1705. image = Texture.DEFAULT_IMAGE;
  1706. }
  1707. if (mapping === void 0) {
  1708. mapping = Texture.DEFAULT_MAPPING;
  1709. }
  1710. if (wrapS === void 0) {
  1711. wrapS = ClampToEdgeWrapping;
  1712. }
  1713. if (wrapT === void 0) {
  1714. wrapT = ClampToEdgeWrapping;
  1715. }
  1716. if (magFilter === void 0) {
  1717. magFilter = LinearFilter;
  1718. }
  1719. if (minFilter === void 0) {
  1720. minFilter = LinearMipmapLinearFilter;
  1721. }
  1722. if (format === void 0) {
  1723. format = RGBAFormat;
  1724. }
  1725. if (type === void 0) {
  1726. type = UnsignedByteType;
  1727. }
  1728. if (anisotropy === void 0) {
  1729. anisotropy = 1;
  1730. }
  1731. if (encoding === void 0) {
  1732. encoding = LinearEncoding;
  1733. }
  1734. Object.defineProperty(this, 'id', {
  1735. value: textureId++
  1736. });
  1737. this.uuid = MathUtils.generateUUID();
  1738. this.name = '';
  1739. this.image = image;
  1740. this.mipmaps = [];
  1741. this.mapping = mapping;
  1742. this.wrapS = wrapS;
  1743. this.wrapT = wrapT;
  1744. this.magFilter = magFilter;
  1745. this.minFilter = minFilter;
  1746. this.anisotropy = anisotropy;
  1747. this.format = format;
  1748. this.internalFormat = null;
  1749. this.type = type;
  1750. this.offset = new Vector2(0, 0);
  1751. this.repeat = new Vector2(1, 1);
  1752. this.center = new Vector2(0, 0);
  1753. this.rotation = 0;
  1754. this.matrixAutoUpdate = true;
  1755. this.matrix = new Matrix3();
  1756. this.generateMipmaps = true;
  1757. this.premultiplyAlpha = false;
  1758. this.flipY = true;
  1759. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1760. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1761. //
  1762. // Also changing the encoding after already used by a Material will not automatically make the Material
  1763. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1764. this.encoding = encoding;
  1765. this.version = 0;
  1766. this.onUpdate = null;
  1767. }
  1768. Texture.DEFAULT_IMAGE = undefined;
  1769. Texture.DEFAULT_MAPPING = UVMapping;
  1770. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1771. constructor: Texture,
  1772. isTexture: true,
  1773. updateMatrix: function updateMatrix() {
  1774. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1775. },
  1776. clone: function clone() {
  1777. return new this.constructor().copy(this);
  1778. },
  1779. copy: function copy(source) {
  1780. this.name = source.name;
  1781. this.image = source.image;
  1782. this.mipmaps = source.mipmaps.slice(0);
  1783. this.mapping = source.mapping;
  1784. this.wrapS = source.wrapS;
  1785. this.wrapT = source.wrapT;
  1786. this.magFilter = source.magFilter;
  1787. this.minFilter = source.minFilter;
  1788. this.anisotropy = source.anisotropy;
  1789. this.format = source.format;
  1790. this.internalFormat = source.internalFormat;
  1791. this.type = source.type;
  1792. this.offset.copy(source.offset);
  1793. this.repeat.copy(source.repeat);
  1794. this.center.copy(source.center);
  1795. this.rotation = source.rotation;
  1796. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1797. this.matrix.copy(source.matrix);
  1798. this.generateMipmaps = source.generateMipmaps;
  1799. this.premultiplyAlpha = source.premultiplyAlpha;
  1800. this.flipY = source.flipY;
  1801. this.unpackAlignment = source.unpackAlignment;
  1802. this.encoding = source.encoding;
  1803. return this;
  1804. },
  1805. toJSON: function toJSON(meta) {
  1806. var isRootObject = meta === undefined || typeof meta === 'string';
  1807. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1808. return meta.textures[this.uuid];
  1809. }
  1810. var output = {
  1811. metadata: {
  1812. version: 4.5,
  1813. type: 'Texture',
  1814. generator: 'Texture.toJSON'
  1815. },
  1816. uuid: this.uuid,
  1817. name: this.name,
  1818. mapping: this.mapping,
  1819. repeat: [this.repeat.x, this.repeat.y],
  1820. offset: [this.offset.x, this.offset.y],
  1821. center: [this.center.x, this.center.y],
  1822. rotation: this.rotation,
  1823. wrap: [this.wrapS, this.wrapT],
  1824. format: this.format,
  1825. type: this.type,
  1826. encoding: this.encoding,
  1827. minFilter: this.minFilter,
  1828. magFilter: this.magFilter,
  1829. anisotropy: this.anisotropy,
  1830. flipY: this.flipY,
  1831. premultiplyAlpha: this.premultiplyAlpha,
  1832. unpackAlignment: this.unpackAlignment
  1833. };
  1834. if (this.image !== undefined) {
  1835. // TODO: Move to THREE.Image
  1836. var image = this.image;
  1837. if (image.uuid === undefined) {
  1838. image.uuid = MathUtils.generateUUID(); // UGH
  1839. }
  1840. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1841. var url;
  1842. if (Array.isArray(image)) {
  1843. // process array of images e.g. CubeTexture
  1844. url = [];
  1845. for (var i = 0, l = image.length; i < l; i++) {
  1846. // check cube texture with data textures
  1847. if (image[i].isDataTexture) {
  1848. url.push(serializeImage(image[i].image));
  1849. } else {
  1850. url.push(serializeImage(image[i]));
  1851. }
  1852. }
  1853. } else {
  1854. // process single image
  1855. url = serializeImage(image);
  1856. }
  1857. meta.images[image.uuid] = {
  1858. uuid: image.uuid,
  1859. url: url
  1860. };
  1861. }
  1862. output.image = image.uuid;
  1863. }
  1864. if (!isRootObject) {
  1865. meta.textures[this.uuid] = output;
  1866. }
  1867. return output;
  1868. },
  1869. dispose: function dispose() {
  1870. this.dispatchEvent({
  1871. type: 'dispose'
  1872. });
  1873. },
  1874. transformUv: function transformUv(uv) {
  1875. if (this.mapping !== UVMapping) return uv;
  1876. uv.applyMatrix3(this.matrix);
  1877. if (uv.x < 0 || uv.x > 1) {
  1878. switch (this.wrapS) {
  1879. case RepeatWrapping:
  1880. uv.x = uv.x - Math.floor(uv.x);
  1881. break;
  1882. case ClampToEdgeWrapping:
  1883. uv.x = uv.x < 0 ? 0 : 1;
  1884. break;
  1885. case MirroredRepeatWrapping:
  1886. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1887. uv.x = Math.ceil(uv.x) - uv.x;
  1888. } else {
  1889. uv.x = uv.x - Math.floor(uv.x);
  1890. }
  1891. break;
  1892. }
  1893. }
  1894. if (uv.y < 0 || uv.y > 1) {
  1895. switch (this.wrapT) {
  1896. case RepeatWrapping:
  1897. uv.y = uv.y - Math.floor(uv.y);
  1898. break;
  1899. case ClampToEdgeWrapping:
  1900. uv.y = uv.y < 0 ? 0 : 1;
  1901. break;
  1902. case MirroredRepeatWrapping:
  1903. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1904. uv.y = Math.ceil(uv.y) - uv.y;
  1905. } else {
  1906. uv.y = uv.y - Math.floor(uv.y);
  1907. }
  1908. break;
  1909. }
  1910. }
  1911. if (this.flipY) {
  1912. uv.y = 1 - uv.y;
  1913. }
  1914. return uv;
  1915. }
  1916. });
  1917. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1918. set: function set(value) {
  1919. if (value === true) this.version++;
  1920. }
  1921. });
  1922. function serializeImage(image) {
  1923. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1924. // default images
  1925. return ImageUtils.getDataURL(image);
  1926. } else {
  1927. if (image.data) {
  1928. // images of DataTexture
  1929. return {
  1930. data: Array.prototype.slice.call(image.data),
  1931. width: image.width,
  1932. height: image.height,
  1933. type: image.data.constructor.name
  1934. };
  1935. } else {
  1936. console.warn('THREE.Texture: Unable to serialize Texture.');
  1937. return {};
  1938. }
  1939. }
  1940. }
  1941. var Vector4 = /*#__PURE__*/function () {
  1942. function Vector4(x, y, z, w) {
  1943. if (x === void 0) {
  1944. x = 0;
  1945. }
  1946. if (y === void 0) {
  1947. y = 0;
  1948. }
  1949. if (z === void 0) {
  1950. z = 0;
  1951. }
  1952. if (w === void 0) {
  1953. w = 1;
  1954. }
  1955. Object.defineProperty(this, 'isVector4', {
  1956. value: true
  1957. });
  1958. this.x = x;
  1959. this.y = y;
  1960. this.z = z;
  1961. this.w = w;
  1962. }
  1963. var _proto = Vector4.prototype;
  1964. _proto.set = function set(x, y, z, w) {
  1965. this.x = x;
  1966. this.y = y;
  1967. this.z = z;
  1968. this.w = w;
  1969. return this;
  1970. };
  1971. _proto.setScalar = function setScalar(scalar) {
  1972. this.x = scalar;
  1973. this.y = scalar;
  1974. this.z = scalar;
  1975. this.w = scalar;
  1976. return this;
  1977. };
  1978. _proto.setX = function setX(x) {
  1979. this.x = x;
  1980. return this;
  1981. };
  1982. _proto.setY = function setY(y) {
  1983. this.y = y;
  1984. return this;
  1985. };
  1986. _proto.setZ = function setZ(z) {
  1987. this.z = z;
  1988. return this;
  1989. };
  1990. _proto.setW = function setW(w) {
  1991. this.w = w;
  1992. return this;
  1993. };
  1994. _proto.setComponent = function setComponent(index, value) {
  1995. switch (index) {
  1996. case 0:
  1997. this.x = value;
  1998. break;
  1999. case 1:
  2000. this.y = value;
  2001. break;
  2002. case 2:
  2003. this.z = value;
  2004. break;
  2005. case 3:
  2006. this.w = value;
  2007. break;
  2008. default:
  2009. throw new Error('index is out of range: ' + index);
  2010. }
  2011. return this;
  2012. };
  2013. _proto.getComponent = function getComponent(index) {
  2014. switch (index) {
  2015. case 0:
  2016. return this.x;
  2017. case 1:
  2018. return this.y;
  2019. case 2:
  2020. return this.z;
  2021. case 3:
  2022. return this.w;
  2023. default:
  2024. throw new Error('index is out of range: ' + index);
  2025. }
  2026. };
  2027. _proto.clone = function clone() {
  2028. return new this.constructor(this.x, this.y, this.z, this.w);
  2029. };
  2030. _proto.copy = function copy(v) {
  2031. this.x = v.x;
  2032. this.y = v.y;
  2033. this.z = v.z;
  2034. this.w = v.w !== undefined ? v.w : 1;
  2035. return this;
  2036. };
  2037. _proto.add = function add(v, w) {
  2038. if (w !== undefined) {
  2039. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2040. return this.addVectors(v, w);
  2041. }
  2042. this.x += v.x;
  2043. this.y += v.y;
  2044. this.z += v.z;
  2045. this.w += v.w;
  2046. return this;
  2047. };
  2048. _proto.addScalar = function addScalar(s) {
  2049. this.x += s;
  2050. this.y += s;
  2051. this.z += s;
  2052. this.w += s;
  2053. return this;
  2054. };
  2055. _proto.addVectors = function addVectors(a, b) {
  2056. this.x = a.x + b.x;
  2057. this.y = a.y + b.y;
  2058. this.z = a.z + b.z;
  2059. this.w = a.w + b.w;
  2060. return this;
  2061. };
  2062. _proto.addScaledVector = function addScaledVector(v, s) {
  2063. this.x += v.x * s;
  2064. this.y += v.y * s;
  2065. this.z += v.z * s;
  2066. this.w += v.w * s;
  2067. return this;
  2068. };
  2069. _proto.sub = function sub(v, w) {
  2070. if (w !== undefined) {
  2071. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2072. return this.subVectors(v, w);
  2073. }
  2074. this.x -= v.x;
  2075. this.y -= v.y;
  2076. this.z -= v.z;
  2077. this.w -= v.w;
  2078. return this;
  2079. };
  2080. _proto.subScalar = function subScalar(s) {
  2081. this.x -= s;
  2082. this.y -= s;
  2083. this.z -= s;
  2084. this.w -= s;
  2085. return this;
  2086. };
  2087. _proto.subVectors = function subVectors(a, b) {
  2088. this.x = a.x - b.x;
  2089. this.y = a.y - b.y;
  2090. this.z = a.z - b.z;
  2091. this.w = a.w - b.w;
  2092. return this;
  2093. };
  2094. _proto.multiply = function multiply(v) {
  2095. this.x *= v.x;
  2096. this.y *= v.y;
  2097. this.z *= v.z;
  2098. this.w *= v.w;
  2099. return this;
  2100. };
  2101. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2102. this.x *= scalar;
  2103. this.y *= scalar;
  2104. this.z *= scalar;
  2105. this.w *= scalar;
  2106. return this;
  2107. };
  2108. _proto.applyMatrix4 = function applyMatrix4(m) {
  2109. var x = this.x,
  2110. y = this.y,
  2111. z = this.z,
  2112. w = this.w;
  2113. var e = m.elements;
  2114. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  2115. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  2116. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  2117. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  2118. return this;
  2119. };
  2120. _proto.divideScalar = function divideScalar(scalar) {
  2121. return this.multiplyScalar(1 / scalar);
  2122. };
  2123. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  2124. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2125. // q is assumed to be normalized
  2126. this.w = 2 * Math.acos(q.w);
  2127. var s = Math.sqrt(1 - q.w * q.w);
  2128. if (s < 0.0001) {
  2129. this.x = 1;
  2130. this.y = 0;
  2131. this.z = 0;
  2132. } else {
  2133. this.x = q.x / s;
  2134. this.y = q.y / s;
  2135. this.z = q.z / s;
  2136. }
  2137. return this;
  2138. };
  2139. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  2140. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2141. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2142. var angle, x, y, z; // variables for result
  2143. var epsilon = 0.01,
  2144. // margin to allow for rounding errors
  2145. epsilon2 = 0.1,
  2146. // margin to distinguish between 0 and 180 degrees
  2147. te = m.elements,
  2148. m11 = te[0],
  2149. m12 = te[4],
  2150. m13 = te[8],
  2151. m21 = te[1],
  2152. m22 = te[5],
  2153. m23 = te[9],
  2154. m31 = te[2],
  2155. m32 = te[6],
  2156. m33 = te[10];
  2157. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  2158. // singularity found
  2159. // first check for identity matrix which must have +1 for all terms
  2160. // in leading diagonal and zero in other terms
  2161. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  2162. // this singularity is identity matrix so angle = 0
  2163. this.set(1, 0, 0, 0);
  2164. return this; // zero angle, arbitrary axis
  2165. } // otherwise this singularity is angle = 180
  2166. angle = Math.PI;
  2167. var xx = (m11 + 1) / 2;
  2168. var yy = (m22 + 1) / 2;
  2169. var zz = (m33 + 1) / 2;
  2170. var xy = (m12 + m21) / 4;
  2171. var xz = (m13 + m31) / 4;
  2172. var yz = (m23 + m32) / 4;
  2173. if (xx > yy && xx > zz) {
  2174. // m11 is the largest diagonal term
  2175. if (xx < epsilon) {
  2176. x = 0;
  2177. y = 0.707106781;
  2178. z = 0.707106781;
  2179. } else {
  2180. x = Math.sqrt(xx);
  2181. y = xy / x;
  2182. z = xz / x;
  2183. }
  2184. } else if (yy > zz) {
  2185. // m22 is the largest diagonal term
  2186. if (yy < epsilon) {
  2187. x = 0.707106781;
  2188. y = 0;
  2189. z = 0.707106781;
  2190. } else {
  2191. y = Math.sqrt(yy);
  2192. x = xy / y;
  2193. z = yz / y;
  2194. }
  2195. } else {
  2196. // m33 is the largest diagonal term so base result on this
  2197. if (zz < epsilon) {
  2198. x = 0.707106781;
  2199. y = 0.707106781;
  2200. z = 0;
  2201. } else {
  2202. z = Math.sqrt(zz);
  2203. x = xz / z;
  2204. y = yz / z;
  2205. }
  2206. }
  2207. this.set(x, y, z, angle);
  2208. return this; // return 180 deg rotation
  2209. } // as we have reached here there are no singularities so we can handle normally
  2210. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  2211. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2212. // caught by singularity test above, but I've left it in just in case
  2213. this.x = (m32 - m23) / s;
  2214. this.y = (m13 - m31) / s;
  2215. this.z = (m21 - m12) / s;
  2216. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  2217. return this;
  2218. };
  2219. _proto.min = function min(v) {
  2220. this.x = Math.min(this.x, v.x);
  2221. this.y = Math.min(this.y, v.y);
  2222. this.z = Math.min(this.z, v.z);
  2223. this.w = Math.min(this.w, v.w);
  2224. return this;
  2225. };
  2226. _proto.max = function max(v) {
  2227. this.x = Math.max(this.x, v.x);
  2228. this.y = Math.max(this.y, v.y);
  2229. this.z = Math.max(this.z, v.z);
  2230. this.w = Math.max(this.w, v.w);
  2231. return this;
  2232. };
  2233. _proto.clamp = function clamp(min, max) {
  2234. // assumes min < max, componentwise
  2235. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2236. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2237. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2238. this.w = Math.max(min.w, Math.min(max.w, this.w));
  2239. return this;
  2240. };
  2241. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2242. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2243. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2244. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2245. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  2246. return this;
  2247. };
  2248. _proto.clampLength = function clampLength(min, max) {
  2249. var length = this.length();
  2250. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2251. };
  2252. _proto.floor = function floor() {
  2253. this.x = Math.floor(this.x);
  2254. this.y = Math.floor(this.y);
  2255. this.z = Math.floor(this.z);
  2256. this.w = Math.floor(this.w);
  2257. return this;
  2258. };
  2259. _proto.ceil = function ceil() {
  2260. this.x = Math.ceil(this.x);
  2261. this.y = Math.ceil(this.y);
  2262. this.z = Math.ceil(this.z);
  2263. this.w = Math.ceil(this.w);
  2264. return this;
  2265. };
  2266. _proto.round = function round() {
  2267. this.x = Math.round(this.x);
  2268. this.y = Math.round(this.y);
  2269. this.z = Math.round(this.z);
  2270. this.w = Math.round(this.w);
  2271. return this;
  2272. };
  2273. _proto.roundToZero = function roundToZero() {
  2274. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2275. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2276. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2277. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  2278. return this;
  2279. };
  2280. _proto.negate = function negate() {
  2281. this.x = -this.x;
  2282. this.y = -this.y;
  2283. this.z = -this.z;
  2284. this.w = -this.w;
  2285. return this;
  2286. };
  2287. _proto.dot = function dot(v) {
  2288. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2289. };
  2290. _proto.lengthSq = function lengthSq() {
  2291. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2292. };
  2293. _proto.length = function length() {
  2294. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  2295. };
  2296. _proto.manhattanLength = function manhattanLength() {
  2297. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  2298. };
  2299. _proto.normalize = function normalize() {
  2300. return this.divideScalar(this.length() || 1);
  2301. };
  2302. _proto.setLength = function setLength(length) {
  2303. return this.normalize().multiplyScalar(length);
  2304. };
  2305. _proto.lerp = function lerp(v, alpha) {
  2306. this.x += (v.x - this.x) * alpha;
  2307. this.y += (v.y - this.y) * alpha;
  2308. this.z += (v.z - this.z) * alpha;
  2309. this.w += (v.w - this.w) * alpha;
  2310. return this;
  2311. };
  2312. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2313. this.x = v1.x + (v2.x - v1.x) * alpha;
  2314. this.y = v1.y + (v2.y - v1.y) * alpha;
  2315. this.z = v1.z + (v2.z - v1.z) * alpha;
  2316. this.w = v1.w + (v2.w - v1.w) * alpha;
  2317. return this;
  2318. };
  2319. _proto.equals = function equals(v) {
  2320. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  2321. };
  2322. _proto.fromArray = function fromArray(array, offset) {
  2323. if (offset === void 0) {
  2324. offset = 0;
  2325. }
  2326. this.x = array[offset];
  2327. this.y = array[offset + 1];
  2328. this.z = array[offset + 2];
  2329. this.w = array[offset + 3];
  2330. return this;
  2331. };
  2332. _proto.toArray = function toArray(array, offset) {
  2333. if (array === void 0) {
  2334. array = [];
  2335. }
  2336. if (offset === void 0) {
  2337. offset = 0;
  2338. }
  2339. array[offset] = this.x;
  2340. array[offset + 1] = this.y;
  2341. array[offset + 2] = this.z;
  2342. array[offset + 3] = this.w;
  2343. return array;
  2344. };
  2345. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2346. if (offset !== undefined) {
  2347. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  2348. }
  2349. this.x = attribute.getX(index);
  2350. this.y = attribute.getY(index);
  2351. this.z = attribute.getZ(index);
  2352. this.w = attribute.getW(index);
  2353. return this;
  2354. };
  2355. _proto.random = function random() {
  2356. this.x = Math.random();
  2357. this.y = Math.random();
  2358. this.z = Math.random();
  2359. this.w = Math.random();
  2360. return this;
  2361. };
  2362. _createClass(Vector4, [{
  2363. key: "width",
  2364. get: function get() {
  2365. return this.z;
  2366. },
  2367. set: function set(value) {
  2368. this.z = value;
  2369. }
  2370. }, {
  2371. key: "height",
  2372. get: function get() {
  2373. return this.w;
  2374. },
  2375. set: function set(value) {
  2376. this.w = value;
  2377. }
  2378. }]);
  2379. return Vector4;
  2380. }();
  2381. /*
  2382. In options, we can specify:
  2383. * Texture parameters for an auto-generated target texture
  2384. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2385. */
  2386. var WebGLRenderTarget = /*#__PURE__*/function (_EventDispatcher) {
  2387. _inheritsLoose(WebGLRenderTarget, _EventDispatcher);
  2388. function WebGLRenderTarget(width, height, options) {
  2389. var _this;
  2390. _this = _EventDispatcher.call(this) || this;
  2391. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLRenderTarget', {
  2392. value: true
  2393. });
  2394. _this.width = width;
  2395. _this.height = height;
  2396. _this.depth = 1;
  2397. _this.scissor = new Vector4(0, 0, width, height);
  2398. _this.scissorTest = false;
  2399. _this.viewport = new Vector4(0, 0, width, height);
  2400. options = options || {};
  2401. _this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  2402. _this.texture.image = {};
  2403. _this.texture.image.width = width;
  2404. _this.texture.image.height = height;
  2405. _this.texture.image.depth = 1;
  2406. _this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2407. _this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2408. _this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2409. _this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  2410. _this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2411. return _this;
  2412. }
  2413. var _proto = WebGLRenderTarget.prototype;
  2414. _proto.setTexture = function setTexture(texture) {
  2415. texture.image = {
  2416. width: this.width,
  2417. height: this.height,
  2418. depth: this.depth
  2419. };
  2420. this.texture = texture;
  2421. };
  2422. _proto.setSize = function setSize(width, height, depth) {
  2423. if (depth === void 0) {
  2424. depth = 1;
  2425. }
  2426. if (this.width !== width || this.height !== height || this.depth !== depth) {
  2427. this.width = width;
  2428. this.height = height;
  2429. this.depth = depth;
  2430. this.texture.image.width = width;
  2431. this.texture.image.height = height;
  2432. this.texture.image.depth = depth;
  2433. this.dispose();
  2434. }
  2435. this.viewport.set(0, 0, width, height);
  2436. this.scissor.set(0, 0, width, height);
  2437. };
  2438. _proto.clone = function clone() {
  2439. return new this.constructor().copy(this);
  2440. };
  2441. _proto.copy = function copy(source) {
  2442. this.width = source.width;
  2443. this.height = source.height;
  2444. this.depth = source.depth;
  2445. this.viewport.copy(source.viewport);
  2446. this.texture = source.texture.clone();
  2447. this.depthBuffer = source.depthBuffer;
  2448. this.stencilBuffer = source.stencilBuffer;
  2449. this.depthTexture = source.depthTexture;
  2450. return this;
  2451. };
  2452. _proto.dispose = function dispose() {
  2453. this.dispatchEvent({
  2454. type: 'dispose'
  2455. });
  2456. };
  2457. return WebGLRenderTarget;
  2458. }(EventDispatcher);
  2459. var WebGLMultisampleRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  2460. _inheritsLoose(WebGLMultisampleRenderTarget, _WebGLRenderTarget);
  2461. function WebGLMultisampleRenderTarget(width, height, options) {
  2462. var _this;
  2463. _this = _WebGLRenderTarget.call(this, width, height, options) || this;
  2464. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLMultisampleRenderTarget', {
  2465. value: true
  2466. });
  2467. _this.samples = 4;
  2468. return _this;
  2469. }
  2470. var _proto = WebGLMultisampleRenderTarget.prototype;
  2471. _proto.copy = function copy(source) {
  2472. _WebGLRenderTarget.prototype.copy.call(this, source);
  2473. this.samples = source.samples;
  2474. return this;
  2475. };
  2476. return WebGLMultisampleRenderTarget;
  2477. }(WebGLRenderTarget);
  2478. var Quaternion = /*#__PURE__*/function () {
  2479. function Quaternion(x, y, z, w) {
  2480. if (x === void 0) {
  2481. x = 0;
  2482. }
  2483. if (y === void 0) {
  2484. y = 0;
  2485. }
  2486. if (z === void 0) {
  2487. z = 0;
  2488. }
  2489. if (w === void 0) {
  2490. w = 1;
  2491. }
  2492. Object.defineProperty(this, 'isQuaternion', {
  2493. value: true
  2494. });
  2495. this._x = x;
  2496. this._y = y;
  2497. this._z = z;
  2498. this._w = w;
  2499. }
  2500. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  2501. return qm.copy(qa).slerp(qb, t);
  2502. };
  2503. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  2504. // fuzz-free, array-based Quaternion SLERP operation
  2505. var x0 = src0[srcOffset0 + 0],
  2506. y0 = src0[srcOffset0 + 1],
  2507. z0 = src0[srcOffset0 + 2],
  2508. w0 = src0[srcOffset0 + 3];
  2509. var x1 = src1[srcOffset1 + 0],
  2510. y1 = src1[srcOffset1 + 1],
  2511. z1 = src1[srcOffset1 + 2],
  2512. w1 = src1[srcOffset1 + 3];
  2513. if (t === 0) {
  2514. dst[dstOffset + 0] = x0;
  2515. dst[dstOffset + 1] = y0;
  2516. dst[dstOffset + 2] = z0;
  2517. dst[dstOffset + 3] = w0;
  2518. return;
  2519. }
  2520. if (t === 1) {
  2521. dst[dstOffset + 0] = x1;
  2522. dst[dstOffset + 1] = y1;
  2523. dst[dstOffset + 2] = z1;
  2524. dst[dstOffset + 3] = w1;
  2525. return;
  2526. }
  2527. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  2528. var s = 1 - t;
  2529. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2530. dir = cos >= 0 ? 1 : -1,
  2531. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  2532. if (sqrSin > Number.EPSILON) {
  2533. var sin = Math.sqrt(sqrSin),
  2534. len = Math.atan2(sin, cos * dir);
  2535. s = Math.sin(s * len) / sin;
  2536. t = Math.sin(t * len) / sin;
  2537. }
  2538. var tDir = t * dir;
  2539. x0 = x0 * s + x1 * tDir;
  2540. y0 = y0 * s + y1 * tDir;
  2541. z0 = z0 * s + z1 * tDir;
  2542. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  2543. if (s === 1 - t) {
  2544. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  2545. x0 *= f;
  2546. y0 *= f;
  2547. z0 *= f;
  2548. w0 *= f;
  2549. }
  2550. }
  2551. dst[dstOffset] = x0;
  2552. dst[dstOffset + 1] = y0;
  2553. dst[dstOffset + 2] = z0;
  2554. dst[dstOffset + 3] = w0;
  2555. };
  2556. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  2557. var x0 = src0[srcOffset0];
  2558. var y0 = src0[srcOffset0 + 1];
  2559. var z0 = src0[srcOffset0 + 2];
  2560. var w0 = src0[srcOffset0 + 3];
  2561. var x1 = src1[srcOffset1];
  2562. var y1 = src1[srcOffset1 + 1];
  2563. var z1 = src1[srcOffset1 + 2];
  2564. var w1 = src1[srcOffset1 + 3];
  2565. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2566. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2567. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2568. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2569. return dst;
  2570. };
  2571. var _proto = Quaternion.prototype;
  2572. _proto.set = function set(x, y, z, w) {
  2573. this._x = x;
  2574. this._y = y;
  2575. this._z = z;
  2576. this._w = w;
  2577. this._onChangeCallback();
  2578. return this;
  2579. };
  2580. _proto.clone = function clone() {
  2581. return new this.constructor(this._x, this._y, this._z, this._w);
  2582. };
  2583. _proto.copy = function copy(quaternion) {
  2584. this._x = quaternion.x;
  2585. this._y = quaternion.y;
  2586. this._z = quaternion.z;
  2587. this._w = quaternion.w;
  2588. this._onChangeCallback();
  2589. return this;
  2590. };
  2591. _proto.setFromEuler = function setFromEuler(euler, update) {
  2592. if (!(euler && euler.isEuler)) {
  2593. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2594. }
  2595. var x = euler._x,
  2596. y = euler._y,
  2597. z = euler._z,
  2598. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  2599. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2600. // content/SpinCalc.m
  2601. var cos = Math.cos;
  2602. var sin = Math.sin;
  2603. var c1 = cos(x / 2);
  2604. var c2 = cos(y / 2);
  2605. var c3 = cos(z / 2);
  2606. var s1 = sin(x / 2);
  2607. var s2 = sin(y / 2);
  2608. var s3 = sin(z / 2);
  2609. switch (order) {
  2610. case 'XYZ':
  2611. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2612. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2613. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2614. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2615. break;
  2616. case 'YXZ':
  2617. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2618. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2619. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2620. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2621. break;
  2622. case 'ZXY':
  2623. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2624. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2625. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2626. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2627. break;
  2628. case 'ZYX':
  2629. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2630. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2631. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2632. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2633. break;
  2634. case 'YZX':
  2635. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2636. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2637. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2638. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2639. break;
  2640. case 'XZY':
  2641. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2642. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2643. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2644. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2645. break;
  2646. default:
  2647. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  2648. }
  2649. if (update !== false) this._onChangeCallback();
  2650. return this;
  2651. };
  2652. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  2653. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2654. // assumes axis is normalized
  2655. var halfAngle = angle / 2,
  2656. s = Math.sin(halfAngle);
  2657. this._x = axis.x * s;
  2658. this._y = axis.y * s;
  2659. this._z = axis.z * s;
  2660. this._w = Math.cos(halfAngle);
  2661. this._onChangeCallback();
  2662. return this;
  2663. };
  2664. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  2665. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2666. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2667. var te = m.elements,
  2668. m11 = te[0],
  2669. m12 = te[4],
  2670. m13 = te[8],
  2671. m21 = te[1],
  2672. m22 = te[5],
  2673. m23 = te[9],
  2674. m31 = te[2],
  2675. m32 = te[6],
  2676. m33 = te[10],
  2677. trace = m11 + m22 + m33;
  2678. if (trace > 0) {
  2679. var s = 0.5 / Math.sqrt(trace + 1.0);
  2680. this._w = 0.25 / s;
  2681. this._x = (m32 - m23) * s;
  2682. this._y = (m13 - m31) * s;
  2683. this._z = (m21 - m12) * s;
  2684. } else if (m11 > m22 && m11 > m33) {
  2685. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  2686. this._w = (m32 - m23) / _s;
  2687. this._x = 0.25 * _s;
  2688. this._y = (m12 + m21) / _s;
  2689. this._z = (m13 + m31) / _s;
  2690. } else if (m22 > m33) {
  2691. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  2692. this._w = (m13 - m31) / _s2;
  2693. this._x = (m12 + m21) / _s2;
  2694. this._y = 0.25 * _s2;
  2695. this._z = (m23 + m32) / _s2;
  2696. } else {
  2697. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  2698. this._w = (m21 - m12) / _s3;
  2699. this._x = (m13 + m31) / _s3;
  2700. this._y = (m23 + m32) / _s3;
  2701. this._z = 0.25 * _s3;
  2702. }
  2703. this._onChangeCallback();
  2704. return this;
  2705. };
  2706. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  2707. // assumes direction vectors vFrom and vTo are normalized
  2708. var EPS = 0.000001;
  2709. var r = vFrom.dot(vTo) + 1;
  2710. if (r < EPS) {
  2711. r = 0;
  2712. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  2713. this._x = -vFrom.y;
  2714. this._y = vFrom.x;
  2715. this._z = 0;
  2716. this._w = r;
  2717. } else {
  2718. this._x = 0;
  2719. this._y = -vFrom.z;
  2720. this._z = vFrom.y;
  2721. this._w = r;
  2722. }
  2723. } else {
  2724. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2725. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2726. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2727. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2728. this._w = r;
  2729. }
  2730. return this.normalize();
  2731. };
  2732. _proto.angleTo = function angleTo(q) {
  2733. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2734. };
  2735. _proto.rotateTowards = function rotateTowards(q, step) {
  2736. var angle = this.angleTo(q);
  2737. if (angle === 0) return this;
  2738. var t = Math.min(1, step / angle);
  2739. this.slerp(q, t);
  2740. return this;
  2741. };
  2742. _proto.identity = function identity() {
  2743. return this.set(0, 0, 0, 1);
  2744. };
  2745. _proto.invert = function invert() {
  2746. // quaternion is assumed to have unit length
  2747. return this.conjugate();
  2748. };
  2749. _proto.conjugate = function conjugate() {
  2750. this._x *= -1;
  2751. this._y *= -1;
  2752. this._z *= -1;
  2753. this._onChangeCallback();
  2754. return this;
  2755. };
  2756. _proto.dot = function dot(v) {
  2757. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2758. };
  2759. _proto.lengthSq = function lengthSq() {
  2760. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2761. };
  2762. _proto.length = function length() {
  2763. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2764. };
  2765. _proto.normalize = function normalize() {
  2766. var l = this.length();
  2767. if (l === 0) {
  2768. this._x = 0;
  2769. this._y = 0;
  2770. this._z = 0;
  2771. this._w = 1;
  2772. } else {
  2773. l = 1 / l;
  2774. this._x = this._x * l;
  2775. this._y = this._y * l;
  2776. this._z = this._z * l;
  2777. this._w = this._w * l;
  2778. }
  2779. this._onChangeCallback();
  2780. return this;
  2781. };
  2782. _proto.multiply = function multiply(q, p) {
  2783. if (p !== undefined) {
  2784. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2785. return this.multiplyQuaternions(q, p);
  2786. }
  2787. return this.multiplyQuaternions(this, q);
  2788. };
  2789. _proto.premultiply = function premultiply(q) {
  2790. return this.multiplyQuaternions(q, this);
  2791. };
  2792. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2793. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2794. var qax = a._x,
  2795. qay = a._y,
  2796. qaz = a._z,
  2797. qaw = a._w;
  2798. var qbx = b._x,
  2799. qby = b._y,
  2800. qbz = b._z,
  2801. qbw = b._w;
  2802. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2803. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2804. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2805. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2806. this._onChangeCallback();
  2807. return this;
  2808. };
  2809. _proto.slerp = function slerp(qb, t) {
  2810. if (t === 0) return this;
  2811. if (t === 1) return this.copy(qb);
  2812. var x = this._x,
  2813. y = this._y,
  2814. z = this._z,
  2815. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2816. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2817. if (cosHalfTheta < 0) {
  2818. this._w = -qb._w;
  2819. this._x = -qb._x;
  2820. this._y = -qb._y;
  2821. this._z = -qb._z;
  2822. cosHalfTheta = -cosHalfTheta;
  2823. } else {
  2824. this.copy(qb);
  2825. }
  2826. if (cosHalfTheta >= 1.0) {
  2827. this._w = w;
  2828. this._x = x;
  2829. this._y = y;
  2830. this._z = z;
  2831. return this;
  2832. }
  2833. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2834. if (sqrSinHalfTheta <= Number.EPSILON) {
  2835. var s = 1 - t;
  2836. this._w = s * w + t * this._w;
  2837. this._x = s * x + t * this._x;
  2838. this._y = s * y + t * this._y;
  2839. this._z = s * z + t * this._z;
  2840. this.normalize();
  2841. this._onChangeCallback();
  2842. return this;
  2843. }
  2844. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2845. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2846. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2847. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2848. this._w = w * ratioA + this._w * ratioB;
  2849. this._x = x * ratioA + this._x * ratioB;
  2850. this._y = y * ratioA + this._y * ratioB;
  2851. this._z = z * ratioA + this._z * ratioB;
  2852. this._onChangeCallback();
  2853. return this;
  2854. };
  2855. _proto.equals = function equals(quaternion) {
  2856. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2857. };
  2858. _proto.fromArray = function fromArray(array, offset) {
  2859. if (offset === void 0) {
  2860. offset = 0;
  2861. }
  2862. this._x = array[offset];
  2863. this._y = array[offset + 1];
  2864. this._z = array[offset + 2];
  2865. this._w = array[offset + 3];
  2866. this._onChangeCallback();
  2867. return this;
  2868. };
  2869. _proto.toArray = function toArray(array, offset) {
  2870. if (array === void 0) {
  2871. array = [];
  2872. }
  2873. if (offset === void 0) {
  2874. offset = 0;
  2875. }
  2876. array[offset] = this._x;
  2877. array[offset + 1] = this._y;
  2878. array[offset + 2] = this._z;
  2879. array[offset + 3] = this._w;
  2880. return array;
  2881. };
  2882. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2883. this._x = attribute.getX(index);
  2884. this._y = attribute.getY(index);
  2885. this._z = attribute.getZ(index);
  2886. this._w = attribute.getW(index);
  2887. return this;
  2888. };
  2889. _proto._onChange = function _onChange(callback) {
  2890. this._onChangeCallback = callback;
  2891. return this;
  2892. };
  2893. _proto._onChangeCallback = function _onChangeCallback() {};
  2894. _createClass(Quaternion, [{
  2895. key: "x",
  2896. get: function get() {
  2897. return this._x;
  2898. },
  2899. set: function set(value) {
  2900. this._x = value;
  2901. this._onChangeCallback();
  2902. }
  2903. }, {
  2904. key: "y",
  2905. get: function get() {
  2906. return this._y;
  2907. },
  2908. set: function set(value) {
  2909. this._y = value;
  2910. this._onChangeCallback();
  2911. }
  2912. }, {
  2913. key: "z",
  2914. get: function get() {
  2915. return this._z;
  2916. },
  2917. set: function set(value) {
  2918. this._z = value;
  2919. this._onChangeCallback();
  2920. }
  2921. }, {
  2922. key: "w",
  2923. get: function get() {
  2924. return this._w;
  2925. },
  2926. set: function set(value) {
  2927. this._w = value;
  2928. this._onChangeCallback();
  2929. }
  2930. }]);
  2931. return Quaternion;
  2932. }();
  2933. var Vector3 = /*#__PURE__*/function () {
  2934. function Vector3(x, y, z) {
  2935. if (x === void 0) {
  2936. x = 0;
  2937. }
  2938. if (y === void 0) {
  2939. y = 0;
  2940. }
  2941. if (z === void 0) {
  2942. z = 0;
  2943. }
  2944. Object.defineProperty(this, 'isVector3', {
  2945. value: true
  2946. });
  2947. this.x = x;
  2948. this.y = y;
  2949. this.z = z;
  2950. }
  2951. var _proto = Vector3.prototype;
  2952. _proto.set = function set(x, y, z) {
  2953. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2954. this.x = x;
  2955. this.y = y;
  2956. this.z = z;
  2957. return this;
  2958. };
  2959. _proto.setScalar = function setScalar(scalar) {
  2960. this.x = scalar;
  2961. this.y = scalar;
  2962. this.z = scalar;
  2963. return this;
  2964. };
  2965. _proto.setX = function setX(x) {
  2966. this.x = x;
  2967. return this;
  2968. };
  2969. _proto.setY = function setY(y) {
  2970. this.y = y;
  2971. return this;
  2972. };
  2973. _proto.setZ = function setZ(z) {
  2974. this.z = z;
  2975. return this;
  2976. };
  2977. _proto.setComponent = function setComponent(index, value) {
  2978. switch (index) {
  2979. case 0:
  2980. this.x = value;
  2981. break;
  2982. case 1:
  2983. this.y = value;
  2984. break;
  2985. case 2:
  2986. this.z = value;
  2987. break;
  2988. default:
  2989. throw new Error('index is out of range: ' + index);
  2990. }
  2991. return this;
  2992. };
  2993. _proto.getComponent = function getComponent(index) {
  2994. switch (index) {
  2995. case 0:
  2996. return this.x;
  2997. case 1:
  2998. return this.y;
  2999. case 2:
  3000. return this.z;
  3001. default:
  3002. throw new Error('index is out of range: ' + index);
  3003. }
  3004. };
  3005. _proto.clone = function clone() {
  3006. return new this.constructor(this.x, this.y, this.z);
  3007. };
  3008. _proto.copy = function copy(v) {
  3009. this.x = v.x;
  3010. this.y = v.y;
  3011. this.z = v.z;
  3012. return this;
  3013. };
  3014. _proto.add = function add(v, w) {
  3015. if (w !== undefined) {
  3016. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  3017. return this.addVectors(v, w);
  3018. }
  3019. this.x += v.x;
  3020. this.y += v.y;
  3021. this.z += v.z;
  3022. return this;
  3023. };
  3024. _proto.addScalar = function addScalar(s) {
  3025. this.x += s;
  3026. this.y += s;
  3027. this.z += s;
  3028. return this;
  3029. };
  3030. _proto.addVectors = function addVectors(a, b) {
  3031. this.x = a.x + b.x;
  3032. this.y = a.y + b.y;
  3033. this.z = a.z + b.z;
  3034. return this;
  3035. };
  3036. _proto.addScaledVector = function addScaledVector(v, s) {
  3037. this.x += v.x * s;
  3038. this.y += v.y * s;
  3039. this.z += v.z * s;
  3040. return this;
  3041. };
  3042. _proto.sub = function sub(v, w) {
  3043. if (w !== undefined) {
  3044. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  3045. return this.subVectors(v, w);
  3046. }
  3047. this.x -= v.x;
  3048. this.y -= v.y;
  3049. this.z -= v.z;
  3050. return this;
  3051. };
  3052. _proto.subScalar = function subScalar(s) {
  3053. this.x -= s;
  3054. this.y -= s;
  3055. this.z -= s;
  3056. return this;
  3057. };
  3058. _proto.subVectors = function subVectors(a, b) {
  3059. this.x = a.x - b.x;
  3060. this.y = a.y - b.y;
  3061. this.z = a.z - b.z;
  3062. return this;
  3063. };
  3064. _proto.multiply = function multiply(v, w) {
  3065. if (w !== undefined) {
  3066. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  3067. return this.multiplyVectors(v, w);
  3068. }
  3069. this.x *= v.x;
  3070. this.y *= v.y;
  3071. this.z *= v.z;
  3072. return this;
  3073. };
  3074. _proto.multiplyScalar = function multiplyScalar(scalar) {
  3075. this.x *= scalar;
  3076. this.y *= scalar;
  3077. this.z *= scalar;
  3078. return this;
  3079. };
  3080. _proto.multiplyVectors = function multiplyVectors(a, b) {
  3081. this.x = a.x * b.x;
  3082. this.y = a.y * b.y;
  3083. this.z = a.z * b.z;
  3084. return this;
  3085. };
  3086. _proto.applyEuler = function applyEuler(euler) {
  3087. if (!(euler && euler.isEuler)) {
  3088. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  3089. }
  3090. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  3091. };
  3092. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  3093. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  3094. };
  3095. _proto.applyMatrix3 = function applyMatrix3(m) {
  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[3] * y + e[6] * z;
  3101. this.y = e[1] * x + e[4] * y + e[7] * z;
  3102. this.z = e[2] * x + e[5] * y + e[8] * z;
  3103. return this;
  3104. };
  3105. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  3106. return this.applyMatrix3(m).normalize();
  3107. };
  3108. _proto.applyMatrix4 = function applyMatrix4(m) {
  3109. var x = this.x,
  3110. y = this.y,
  3111. z = this.z;
  3112. var e = m.elements;
  3113. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  3114. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  3115. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  3116. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  3117. return this;
  3118. };
  3119. _proto.applyQuaternion = function applyQuaternion(q) {
  3120. var x = this.x,
  3121. y = this.y,
  3122. z = this.z;
  3123. var qx = q.x,
  3124. qy = q.y,
  3125. qz = q.z,
  3126. qw = q.w; // calculate quat * vector
  3127. var ix = qw * x + qy * z - qz * y;
  3128. var iy = qw * y + qz * x - qx * z;
  3129. var iz = qw * z + qx * y - qy * x;
  3130. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  3131. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3132. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3133. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3134. return this;
  3135. };
  3136. _proto.project = function project(camera) {
  3137. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  3138. };
  3139. _proto.unproject = function unproject(camera) {
  3140. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  3141. };
  3142. _proto.transformDirection = function transformDirection(m) {
  3143. // input: THREE.Matrix4 affine matrix
  3144. // vector interpreted as a direction
  3145. var x = this.x,
  3146. y = this.y,
  3147. z = this.z;
  3148. var e = m.elements;
  3149. this.x = e[0] * x + e[4] * y + e[8] * z;
  3150. this.y = e[1] * x + e[5] * y + e[9] * z;
  3151. this.z = e[2] * x + e[6] * y + e[10] * z;
  3152. return this.normalize();
  3153. };
  3154. _proto.divide = function divide(v) {
  3155. this.x /= v.x;
  3156. this.y /= v.y;
  3157. this.z /= v.z;
  3158. return this;
  3159. };
  3160. _proto.divideScalar = function divideScalar(scalar) {
  3161. return this.multiplyScalar(1 / scalar);
  3162. };
  3163. _proto.min = function min(v) {
  3164. this.x = Math.min(this.x, v.x);
  3165. this.y = Math.min(this.y, v.y);
  3166. this.z = Math.min(this.z, v.z);
  3167. return this;
  3168. };
  3169. _proto.max = function max(v) {
  3170. this.x = Math.max(this.x, v.x);
  3171. this.y = Math.max(this.y, v.y);
  3172. this.z = Math.max(this.z, v.z);
  3173. return this;
  3174. };
  3175. _proto.clamp = function clamp(min, max) {
  3176. // assumes min < max, componentwise
  3177. this.x = Math.max(min.x, Math.min(max.x, this.x));
  3178. this.y = Math.max(min.y, Math.min(max.y, this.y));
  3179. this.z = Math.max(min.z, Math.min(max.z, this.z));
  3180. return this;
  3181. };
  3182. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  3183. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  3184. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  3185. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  3186. return this;
  3187. };
  3188. _proto.clampLength = function clampLength(min, max) {
  3189. var length = this.length();
  3190. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  3191. };
  3192. _proto.floor = function floor() {
  3193. this.x = Math.floor(this.x);
  3194. this.y = Math.floor(this.y);
  3195. this.z = Math.floor(this.z);
  3196. return this;
  3197. };
  3198. _proto.ceil = function ceil() {
  3199. this.x = Math.ceil(this.x);
  3200. this.y = Math.ceil(this.y);
  3201. this.z = Math.ceil(this.z);
  3202. return this;
  3203. };
  3204. _proto.round = function round() {
  3205. this.x = Math.round(this.x);
  3206. this.y = Math.round(this.y);
  3207. this.z = Math.round(this.z);
  3208. return this;
  3209. };
  3210. _proto.roundToZero = function roundToZero() {
  3211. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  3212. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  3213. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  3214. return this;
  3215. };
  3216. _proto.negate = function negate() {
  3217. this.x = -this.x;
  3218. this.y = -this.y;
  3219. this.z = -this.z;
  3220. return this;
  3221. };
  3222. _proto.dot = function dot(v) {
  3223. return this.x * v.x + this.y * v.y + this.z * v.z;
  3224. } // TODO lengthSquared?
  3225. ;
  3226. _proto.lengthSq = function lengthSq() {
  3227. return this.x * this.x + this.y * this.y + this.z * this.z;
  3228. };
  3229. _proto.length = function length() {
  3230. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3231. };
  3232. _proto.manhattanLength = function manhattanLength() {
  3233. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  3234. };
  3235. _proto.normalize = function normalize() {
  3236. return this.divideScalar(this.length() || 1);
  3237. };
  3238. _proto.setLength = function setLength(length) {
  3239. return this.normalize().multiplyScalar(length);
  3240. };
  3241. _proto.lerp = function lerp(v, alpha) {
  3242. this.x += (v.x - this.x) * alpha;
  3243. this.y += (v.y - this.y) * alpha;
  3244. this.z += (v.z - this.z) * alpha;
  3245. return this;
  3246. };
  3247. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  3248. this.x = v1.x + (v2.x - v1.x) * alpha;
  3249. this.y = v1.y + (v2.y - v1.y) * alpha;
  3250. this.z = v1.z + (v2.z - v1.z) * alpha;
  3251. return this;
  3252. };
  3253. _proto.cross = function cross(v, w) {
  3254. if (w !== undefined) {
  3255. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  3256. return this.crossVectors(v, w);
  3257. }
  3258. return this.crossVectors(this, v);
  3259. };
  3260. _proto.crossVectors = function crossVectors(a, b) {
  3261. var ax = a.x,
  3262. ay = a.y,
  3263. az = a.z;
  3264. var bx = b.x,
  3265. by = b.y,
  3266. bz = b.z;
  3267. this.x = ay * bz - az * by;
  3268. this.y = az * bx - ax * bz;
  3269. this.z = ax * by - ay * bx;
  3270. return this;
  3271. };
  3272. _proto.projectOnVector = function projectOnVector(v) {
  3273. var denominator = v.lengthSq();
  3274. if (denominator === 0) return this.set(0, 0, 0);
  3275. var scalar = v.dot(this) / denominator;
  3276. return this.copy(v).multiplyScalar(scalar);
  3277. };
  3278. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  3279. _vector.copy(this).projectOnVector(planeNormal);
  3280. return this.sub(_vector);
  3281. };
  3282. _proto.reflect = function reflect(normal) {
  3283. // reflect incident vector off plane orthogonal to normal
  3284. // normal is assumed to have unit length
  3285. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  3286. };
  3287. _proto.angleTo = function angleTo(v) {
  3288. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  3289. if (denominator === 0) return Math.PI / 2;
  3290. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  3291. return Math.acos(MathUtils.clamp(theta, -1, 1));
  3292. };
  3293. _proto.distanceTo = function distanceTo(v) {
  3294. return Math.sqrt(this.distanceToSquared(v));
  3295. };
  3296. _proto.distanceToSquared = function distanceToSquared(v) {
  3297. var dx = this.x - v.x,
  3298. dy = this.y - v.y,
  3299. dz = this.z - v.z;
  3300. return dx * dx + dy * dy + dz * dz;
  3301. };
  3302. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  3303. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  3304. };
  3305. _proto.setFromSpherical = function setFromSpherical(s) {
  3306. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  3307. };
  3308. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  3309. var sinPhiRadius = Math.sin(phi) * radius;
  3310. this.x = sinPhiRadius * Math.sin(theta);
  3311. this.y = Math.cos(phi) * radius;
  3312. this.z = sinPhiRadius * Math.cos(theta);
  3313. return this;
  3314. };
  3315. _proto.setFromCylindrical = function setFromCylindrical(c) {
  3316. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  3317. };
  3318. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  3319. this.x = radius * Math.sin(theta);
  3320. this.y = y;
  3321. this.z = radius * Math.cos(theta);
  3322. return this;
  3323. };
  3324. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  3325. var e = m.elements;
  3326. this.x = e[12];
  3327. this.y = e[13];
  3328. this.z = e[14];
  3329. return this;
  3330. };
  3331. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  3332. var sx = this.setFromMatrixColumn(m, 0).length();
  3333. var sy = this.setFromMatrixColumn(m, 1).length();
  3334. var sz = this.setFromMatrixColumn(m, 2).length();
  3335. this.x = sx;
  3336. this.y = sy;
  3337. this.z = sz;
  3338. return this;
  3339. };
  3340. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  3341. return this.fromArray(m.elements, index * 4);
  3342. };
  3343. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  3344. return this.fromArray(m.elements, index * 3);
  3345. };
  3346. _proto.equals = function equals(v) {
  3347. return v.x === this.x && v.y === this.y && v.z === this.z;
  3348. };
  3349. _proto.fromArray = function fromArray(array, offset) {
  3350. if (offset === void 0) {
  3351. offset = 0;
  3352. }
  3353. this.x = array[offset];
  3354. this.y = array[offset + 1];
  3355. this.z = array[offset + 2];
  3356. return this;
  3357. };
  3358. _proto.toArray = function toArray(array, offset) {
  3359. if (array === void 0) {
  3360. array = [];
  3361. }
  3362. if (offset === void 0) {
  3363. offset = 0;
  3364. }
  3365. array[offset] = this.x;
  3366. array[offset + 1] = this.y;
  3367. array[offset + 2] = this.z;
  3368. return array;
  3369. };
  3370. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  3371. if (offset !== undefined) {
  3372. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  3373. }
  3374. this.x = attribute.getX(index);
  3375. this.y = attribute.getY(index);
  3376. this.z = attribute.getZ(index);
  3377. return this;
  3378. };
  3379. _proto.random = function random() {
  3380. this.x = Math.random();
  3381. this.y = Math.random();
  3382. this.z = Math.random();
  3383. return this;
  3384. };
  3385. return Vector3;
  3386. }();
  3387. var _vector = /*@__PURE__*/new Vector3();
  3388. var _quaternion = /*@__PURE__*/new Quaternion();
  3389. var Box3 = /*#__PURE__*/function () {
  3390. function Box3(min, max) {
  3391. Object.defineProperty(this, 'isBox3', {
  3392. value: true
  3393. });
  3394. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  3395. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  3396. }
  3397. var _proto = Box3.prototype;
  3398. _proto.set = function set(min, max) {
  3399. this.min.copy(min);
  3400. this.max.copy(max);
  3401. return this;
  3402. };
  3403. _proto.setFromArray = function setFromArray(array) {
  3404. var minX = +Infinity;
  3405. var minY = +Infinity;
  3406. var minZ = +Infinity;
  3407. var maxX = -Infinity;
  3408. var maxY = -Infinity;
  3409. var maxZ = -Infinity;
  3410. for (var i = 0, l = array.length; i < l; i += 3) {
  3411. var x = array[i];
  3412. var y = array[i + 1];
  3413. var z = array[i + 2];
  3414. if (x < minX) minX = x;
  3415. if (y < minY) minY = y;
  3416. if (z < minZ) minZ = z;
  3417. if (x > maxX) maxX = x;
  3418. if (y > maxY) maxY = y;
  3419. if (z > maxZ) maxZ = z;
  3420. }
  3421. this.min.set(minX, minY, minZ);
  3422. this.max.set(maxX, maxY, maxZ);
  3423. return this;
  3424. };
  3425. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  3426. var minX = +Infinity;
  3427. var minY = +Infinity;
  3428. var minZ = +Infinity;
  3429. var maxX = -Infinity;
  3430. var maxY = -Infinity;
  3431. var maxZ = -Infinity;
  3432. for (var i = 0, l = attribute.count; i < l; i++) {
  3433. var x = attribute.getX(i);
  3434. var y = attribute.getY(i);
  3435. var z = attribute.getZ(i);
  3436. if (x < minX) minX = x;
  3437. if (y < minY) minY = y;
  3438. if (z < minZ) minZ = z;
  3439. if (x > maxX) maxX = x;
  3440. if (y > maxY) maxY = y;
  3441. if (z > maxZ) maxZ = z;
  3442. }
  3443. this.min.set(minX, minY, minZ);
  3444. this.max.set(maxX, maxY, maxZ);
  3445. return this;
  3446. };
  3447. _proto.setFromPoints = function setFromPoints(points) {
  3448. this.makeEmpty();
  3449. for (var i = 0, il = points.length; i < il; i++) {
  3450. this.expandByPoint(points[i]);
  3451. }
  3452. return this;
  3453. };
  3454. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  3455. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  3456. this.min.copy(center).sub(halfSize);
  3457. this.max.copy(center).add(halfSize);
  3458. return this;
  3459. };
  3460. _proto.setFromObject = function setFromObject(object) {
  3461. this.makeEmpty();
  3462. return this.expandByObject(object);
  3463. };
  3464. _proto.clone = function clone() {
  3465. return new this.constructor().copy(this);
  3466. };
  3467. _proto.copy = function copy(box) {
  3468. this.min.copy(box.min);
  3469. this.max.copy(box.max);
  3470. return this;
  3471. };
  3472. _proto.makeEmpty = function makeEmpty() {
  3473. this.min.x = this.min.y = this.min.z = +Infinity;
  3474. this.max.x = this.max.y = this.max.z = -Infinity;
  3475. return this;
  3476. };
  3477. _proto.isEmpty = function isEmpty() {
  3478. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3479. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  3480. };
  3481. _proto.getCenter = function getCenter(target) {
  3482. if (target === undefined) {
  3483. console.warn('THREE.Box3: .getCenter() target is now required');
  3484. target = new Vector3();
  3485. }
  3486. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  3487. };
  3488. _proto.getSize = function getSize(target) {
  3489. if (target === undefined) {
  3490. console.warn('THREE.Box3: .getSize() target is now required');
  3491. target = new Vector3();
  3492. }
  3493. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  3494. };
  3495. _proto.expandByPoint = function expandByPoint(point) {
  3496. this.min.min(point);
  3497. this.max.max(point);
  3498. return this;
  3499. };
  3500. _proto.expandByVector = function expandByVector(vector) {
  3501. this.min.sub(vector);
  3502. this.max.add(vector);
  3503. return this;
  3504. };
  3505. _proto.expandByScalar = function expandByScalar(scalar) {
  3506. this.min.addScalar(-scalar);
  3507. this.max.addScalar(scalar);
  3508. return this;
  3509. };
  3510. _proto.expandByObject = function expandByObject(object) {
  3511. // Computes the world-axis-aligned bounding box of an object (including its children),
  3512. // accounting for both the object's, and children's, world transforms
  3513. object.updateWorldMatrix(false, false);
  3514. var geometry = object.geometry;
  3515. if (geometry !== undefined) {
  3516. if (geometry.boundingBox === null) {
  3517. geometry.computeBoundingBox();
  3518. }
  3519. _box.copy(geometry.boundingBox);
  3520. _box.applyMatrix4(object.matrixWorld);
  3521. this.union(_box);
  3522. }
  3523. var children = object.children;
  3524. for (var i = 0, l = children.length; i < l; i++) {
  3525. this.expandByObject(children[i]);
  3526. }
  3527. return this;
  3528. };
  3529. _proto.containsPoint = function containsPoint(point) {
  3530. 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;
  3531. };
  3532. _proto.containsBox = function containsBox(box) {
  3533. 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;
  3534. };
  3535. _proto.getParameter = function getParameter(point, target) {
  3536. // This can potentially have a divide by zero if the box
  3537. // has a size dimension of 0.
  3538. if (target === undefined) {
  3539. console.warn('THREE.Box3: .getParameter() target is now required');
  3540. target = new Vector3();
  3541. }
  3542. 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));
  3543. };
  3544. _proto.intersectsBox = function intersectsBox(box) {
  3545. // using 6 splitting planes to rule out intersections.
  3546. 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;
  3547. };
  3548. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3549. // Find the point on the AABB closest to the sphere center.
  3550. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  3551. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  3552. };
  3553. _proto.intersectsPlane = function intersectsPlane(plane) {
  3554. // We compute the minimum and maximum dot product values. If those values
  3555. // are on the same side (back or front) of the plane, then there is no intersection.
  3556. var min, max;
  3557. if (plane.normal.x > 0) {
  3558. min = plane.normal.x * this.min.x;
  3559. max = plane.normal.x * this.max.x;
  3560. } else {
  3561. min = plane.normal.x * this.max.x;
  3562. max = plane.normal.x * this.min.x;
  3563. }
  3564. if (plane.normal.y > 0) {
  3565. min += plane.normal.y * this.min.y;
  3566. max += plane.normal.y * this.max.y;
  3567. } else {
  3568. min += plane.normal.y * this.max.y;
  3569. max += plane.normal.y * this.min.y;
  3570. }
  3571. if (plane.normal.z > 0) {
  3572. min += plane.normal.z * this.min.z;
  3573. max += plane.normal.z * this.max.z;
  3574. } else {
  3575. min += plane.normal.z * this.max.z;
  3576. max += plane.normal.z * this.min.z;
  3577. }
  3578. return min <= -plane.constant && max >= -plane.constant;
  3579. };
  3580. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  3581. if (this.isEmpty()) {
  3582. return false;
  3583. } // compute box center and extents
  3584. this.getCenter(_center);
  3585. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  3586. _v0.subVectors(triangle.a, _center);
  3587. _v1.subVectors(triangle.b, _center);
  3588. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  3589. _f0.subVectors(_v1, _v0);
  3590. _f1.subVectors(_v2, _v1);
  3591. _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
  3592. // 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
  3593. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3594. 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];
  3595. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3596. return false;
  3597. } // test 3 face normals from the aabb
  3598. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  3599. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3600. return false;
  3601. } // finally testing the face normal of the triangle
  3602. // use already existing triangle edge vectors here
  3603. _triangleNormal.crossVectors(_f0, _f1);
  3604. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  3605. return satForAxes(axes, _v0, _v1, _v2, _extents);
  3606. };
  3607. _proto.clampPoint = function clampPoint(point, target) {
  3608. if (target === undefined) {
  3609. console.warn('THREE.Box3: .clampPoint() target is now required');
  3610. target = new Vector3();
  3611. }
  3612. return target.copy(point).clamp(this.min, this.max);
  3613. };
  3614. _proto.distanceToPoint = function distanceToPoint(point) {
  3615. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  3616. return clampedPoint.sub(point).length();
  3617. };
  3618. _proto.getBoundingSphere = function getBoundingSphere(target) {
  3619. if (target === undefined) {
  3620. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  3621. }
  3622. this.getCenter(target.center);
  3623. target.radius = this.getSize(_vector$1).length() * 0.5;
  3624. return target;
  3625. };
  3626. _proto.intersect = function intersect(box) {
  3627. this.min.max(box.min);
  3628. 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.
  3629. if (this.isEmpty()) this.makeEmpty();
  3630. return this;
  3631. };
  3632. _proto.union = function union(box) {
  3633. this.min.min(box.min);
  3634. this.max.max(box.max);
  3635. return this;
  3636. };
  3637. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3638. // transform of empty box is an empty box.
  3639. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3640. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  3641. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  3642. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  3643. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  3644. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  3645. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  3646. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  3647. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  3648. this.setFromPoints(_points);
  3649. return this;
  3650. };
  3651. _proto.translate = function translate(offset) {
  3652. this.min.add(offset);
  3653. this.max.add(offset);
  3654. return this;
  3655. };
  3656. _proto.equals = function equals(box) {
  3657. return box.min.equals(this.min) && box.max.equals(this.max);
  3658. };
  3659. return Box3;
  3660. }();
  3661. function satForAxes(axes, v0, v1, v2, extents) {
  3662. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  3663. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  3664. 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
  3665. var p0 = v0.dot(_testAxis);
  3666. var p1 = v1.dot(_testAxis);
  3667. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  3668. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  3669. // points of the projected triangle are outside the projected half-length of the aabb
  3670. // the axis is seperating and we can exit
  3671. return false;
  3672. }
  3673. }
  3674. return true;
  3675. }
  3676. 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()];
  3677. var _vector$1 = /*@__PURE__*/new Vector3();
  3678. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  3679. var _v0 = /*@__PURE__*/new Vector3();
  3680. var _v1 = /*@__PURE__*/new Vector3();
  3681. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  3682. var _f0 = /*@__PURE__*/new Vector3();
  3683. var _f1 = /*@__PURE__*/new Vector3();
  3684. var _f2 = /*@__PURE__*/new Vector3();
  3685. var _center = /*@__PURE__*/new Vector3();
  3686. var _extents = /*@__PURE__*/new Vector3();
  3687. var _triangleNormal = /*@__PURE__*/new Vector3();
  3688. var _testAxis = /*@__PURE__*/new Vector3();
  3689. var _box$1 = /*@__PURE__*/new Box3();
  3690. var Sphere = /*#__PURE__*/function () {
  3691. function Sphere(center, radius) {
  3692. this.center = center !== undefined ? center : new Vector3();
  3693. this.radius = radius !== undefined ? radius : -1;
  3694. }
  3695. var _proto = Sphere.prototype;
  3696. _proto.set = function set(center, radius) {
  3697. this.center.copy(center);
  3698. this.radius = radius;
  3699. return this;
  3700. };
  3701. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  3702. var center = this.center;
  3703. if (optionalCenter !== undefined) {
  3704. center.copy(optionalCenter);
  3705. } else {
  3706. _box$1.setFromPoints(points).getCenter(center);
  3707. }
  3708. var maxRadiusSq = 0;
  3709. for (var i = 0, il = points.length; i < il; i++) {
  3710. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  3711. }
  3712. this.radius = Math.sqrt(maxRadiusSq);
  3713. return this;
  3714. };
  3715. _proto.clone = function clone() {
  3716. return new this.constructor().copy(this);
  3717. };
  3718. _proto.copy = function copy(sphere) {
  3719. this.center.copy(sphere.center);
  3720. this.radius = sphere.radius;
  3721. return this;
  3722. };
  3723. _proto.isEmpty = function isEmpty() {
  3724. return this.radius < 0;
  3725. };
  3726. _proto.makeEmpty = function makeEmpty() {
  3727. this.center.set(0, 0, 0);
  3728. this.radius = -1;
  3729. return this;
  3730. };
  3731. _proto.containsPoint = function containsPoint(point) {
  3732. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3733. };
  3734. _proto.distanceToPoint = function distanceToPoint(point) {
  3735. return point.distanceTo(this.center) - this.radius;
  3736. };
  3737. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3738. var radiusSum = this.radius + sphere.radius;
  3739. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3740. };
  3741. _proto.intersectsBox = function intersectsBox(box) {
  3742. return box.intersectsSphere(this);
  3743. };
  3744. _proto.intersectsPlane = function intersectsPlane(plane) {
  3745. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3746. };
  3747. _proto.clampPoint = function clampPoint(point, target) {
  3748. var deltaLengthSq = this.center.distanceToSquared(point);
  3749. if (target === undefined) {
  3750. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3751. target = new Vector3();
  3752. }
  3753. target.copy(point);
  3754. if (deltaLengthSq > this.radius * this.radius) {
  3755. target.sub(this.center).normalize();
  3756. target.multiplyScalar(this.radius).add(this.center);
  3757. }
  3758. return target;
  3759. };
  3760. _proto.getBoundingBox = function getBoundingBox(target) {
  3761. if (target === undefined) {
  3762. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3763. target = new Box3();
  3764. }
  3765. if (this.isEmpty()) {
  3766. // Empty sphere produces empty bounding box
  3767. target.makeEmpty();
  3768. return target;
  3769. }
  3770. target.set(this.center, this.center);
  3771. target.expandByScalar(this.radius);
  3772. return target;
  3773. };
  3774. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3775. this.center.applyMatrix4(matrix);
  3776. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3777. return this;
  3778. };
  3779. _proto.translate = function translate(offset) {
  3780. this.center.add(offset);
  3781. return this;
  3782. };
  3783. _proto.equals = function equals(sphere) {
  3784. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3785. };
  3786. return Sphere;
  3787. }();
  3788. var _vector$2 = /*@__PURE__*/new Vector3();
  3789. var _segCenter = /*@__PURE__*/new Vector3();
  3790. var _segDir = /*@__PURE__*/new Vector3();
  3791. var _diff = /*@__PURE__*/new Vector3();
  3792. var _edge1 = /*@__PURE__*/new Vector3();
  3793. var _edge2 = /*@__PURE__*/new Vector3();
  3794. var _normal = /*@__PURE__*/new Vector3();
  3795. var Ray = /*#__PURE__*/function () {
  3796. function Ray(origin, direction) {
  3797. this.origin = origin !== undefined ? origin : new Vector3();
  3798. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3799. }
  3800. var _proto = Ray.prototype;
  3801. _proto.set = function set(origin, direction) {
  3802. this.origin.copy(origin);
  3803. this.direction.copy(direction);
  3804. return this;
  3805. };
  3806. _proto.clone = function clone() {
  3807. return new this.constructor().copy(this);
  3808. };
  3809. _proto.copy = function copy(ray) {
  3810. this.origin.copy(ray.origin);
  3811. this.direction.copy(ray.direction);
  3812. return this;
  3813. };
  3814. _proto.at = function at(t, target) {
  3815. if (target === undefined) {
  3816. console.warn('THREE.Ray: .at() target is now required');
  3817. target = new Vector3();
  3818. }
  3819. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3820. };
  3821. _proto.lookAt = function lookAt(v) {
  3822. this.direction.copy(v).sub(this.origin).normalize();
  3823. return this;
  3824. };
  3825. _proto.recast = function recast(t) {
  3826. this.origin.copy(this.at(t, _vector$2));
  3827. return this;
  3828. };
  3829. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3830. if (target === undefined) {
  3831. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3832. target = new Vector3();
  3833. }
  3834. target.subVectors(point, this.origin);
  3835. var directionDistance = target.dot(this.direction);
  3836. if (directionDistance < 0) {
  3837. return target.copy(this.origin);
  3838. }
  3839. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3840. };
  3841. _proto.distanceToPoint = function distanceToPoint(point) {
  3842. return Math.sqrt(this.distanceSqToPoint(point));
  3843. };
  3844. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3845. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3846. if (directionDistance < 0) {
  3847. return this.origin.distanceToSquared(point);
  3848. }
  3849. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3850. return _vector$2.distanceToSquared(point);
  3851. };
  3852. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3853. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3854. // It returns the min distance between the ray and the segment
  3855. // defined by v0 and v1
  3856. // It can also set two optional targets :
  3857. // - The closest point on the ray
  3858. // - The closest point on the segment
  3859. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3860. _segDir.copy(v1).sub(v0).normalize();
  3861. _diff.copy(this.origin).sub(_segCenter);
  3862. var segExtent = v0.distanceTo(v1) * 0.5;
  3863. var a01 = -this.direction.dot(_segDir);
  3864. var b0 = _diff.dot(this.direction);
  3865. var b1 = -_diff.dot(_segDir);
  3866. var c = _diff.lengthSq();
  3867. var det = Math.abs(1 - a01 * a01);
  3868. var s0, s1, sqrDist, extDet;
  3869. if (det > 0) {
  3870. // The ray and segment are not parallel.
  3871. s0 = a01 * b1 - b0;
  3872. s1 = a01 * b0 - b1;
  3873. extDet = segExtent * det;
  3874. if (s0 >= 0) {
  3875. if (s1 >= -extDet) {
  3876. if (s1 <= extDet) {
  3877. // region 0
  3878. // Minimum at interior points of ray and segment.
  3879. var invDet = 1 / det;
  3880. s0 *= invDet;
  3881. s1 *= invDet;
  3882. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3883. } else {
  3884. // region 1
  3885. s1 = segExtent;
  3886. s0 = Math.max(0, -(a01 * s1 + b0));
  3887. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3888. }
  3889. } else {
  3890. // region 5
  3891. s1 = -segExtent;
  3892. s0 = Math.max(0, -(a01 * s1 + b0));
  3893. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3894. }
  3895. } else {
  3896. if (s1 <= -extDet) {
  3897. // region 4
  3898. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3899. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3900. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3901. } else if (s1 <= extDet) {
  3902. // region 3
  3903. s0 = 0;
  3904. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3905. sqrDist = s1 * (s1 + 2 * b1) + c;
  3906. } else {
  3907. // region 2
  3908. s0 = Math.max(0, -(a01 * segExtent + b0));
  3909. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3910. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3911. }
  3912. }
  3913. } else {
  3914. // Ray and segment are parallel.
  3915. s1 = a01 > 0 ? -segExtent : segExtent;
  3916. s0 = Math.max(0, -(a01 * s1 + b0));
  3917. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3918. }
  3919. if (optionalPointOnRay) {
  3920. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3921. }
  3922. if (optionalPointOnSegment) {
  3923. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3924. }
  3925. return sqrDist;
  3926. };
  3927. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3928. _vector$2.subVectors(sphere.center, this.origin);
  3929. var tca = _vector$2.dot(this.direction);
  3930. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3931. var radius2 = sphere.radius * sphere.radius;
  3932. if (d2 > radius2) return null;
  3933. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3934. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3935. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3936. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3937. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3938. // in order to always return an intersect point that is in front of the ray.
  3939. 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
  3940. return this.at(t0, target);
  3941. };
  3942. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3943. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3944. };
  3945. _proto.distanceToPlane = function distanceToPlane(plane) {
  3946. var denominator = plane.normal.dot(this.direction);
  3947. if (denominator === 0) {
  3948. // line is coplanar, return origin
  3949. if (plane.distanceToPoint(this.origin) === 0) {
  3950. return 0;
  3951. } // Null is preferable to undefined since undefined means.... it is undefined
  3952. return null;
  3953. }
  3954. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3955. return t >= 0 ? t : null;
  3956. };
  3957. _proto.intersectPlane = function intersectPlane(plane, target) {
  3958. var t = this.distanceToPlane(plane);
  3959. if (t === null) {
  3960. return null;
  3961. }
  3962. return this.at(t, target);
  3963. };
  3964. _proto.intersectsPlane = function intersectsPlane(plane) {
  3965. // check if the ray lies on the plane first
  3966. var distToPoint = plane.distanceToPoint(this.origin);
  3967. if (distToPoint === 0) {
  3968. return true;
  3969. }
  3970. var denominator = plane.normal.dot(this.direction);
  3971. if (denominator * distToPoint < 0) {
  3972. return true;
  3973. } // ray origin is behind the plane (and is pointing behind it)
  3974. return false;
  3975. };
  3976. _proto.intersectBox = function intersectBox(box, target) {
  3977. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3978. var invdirx = 1 / this.direction.x,
  3979. invdiry = 1 / this.direction.y,
  3980. invdirz = 1 / this.direction.z;
  3981. var origin = this.origin;
  3982. if (invdirx >= 0) {
  3983. tmin = (box.min.x - origin.x) * invdirx;
  3984. tmax = (box.max.x - origin.x) * invdirx;
  3985. } else {
  3986. tmin = (box.max.x - origin.x) * invdirx;
  3987. tmax = (box.min.x - origin.x) * invdirx;
  3988. }
  3989. if (invdiry >= 0) {
  3990. tymin = (box.min.y - origin.y) * invdiry;
  3991. tymax = (box.max.y - origin.y) * invdiry;
  3992. } else {
  3993. tymin = (box.max.y - origin.y) * invdiry;
  3994. tymax = (box.min.y - origin.y) * invdiry;
  3995. }
  3996. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3997. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3998. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3999. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  4000. if (invdirz >= 0) {
  4001. tzmin = (box.min.z - origin.z) * invdirz;
  4002. tzmax = (box.max.z - origin.z) * invdirz;
  4003. } else {
  4004. tzmin = (box.max.z - origin.z) * invdirz;
  4005. tzmax = (box.min.z - origin.z) * invdirz;
  4006. }
  4007. if (tmin > tzmax || tzmin > tmax) return null;
  4008. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  4009. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  4010. if (tmax < 0) return null;
  4011. return this.at(tmin >= 0 ? tmin : tmax, target);
  4012. };
  4013. _proto.intersectsBox = function intersectsBox(box) {
  4014. return this.intersectBox(box, _vector$2) !== null;
  4015. };
  4016. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  4017. // Compute the offset origin, edges, and normal.
  4018. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4019. _edge1.subVectors(b, a);
  4020. _edge2.subVectors(c, a);
  4021. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4022. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4023. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4024. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4025. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4026. var DdN = this.direction.dot(_normal);
  4027. var sign;
  4028. if (DdN > 0) {
  4029. if (backfaceCulling) return null;
  4030. sign = 1;
  4031. } else if (DdN < 0) {
  4032. sign = -1;
  4033. DdN = -DdN;
  4034. } else {
  4035. return null;
  4036. }
  4037. _diff.subVectors(this.origin, a);
  4038. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  4039. if (DdQxE2 < 0) {
  4040. return null;
  4041. }
  4042. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  4043. if (DdE1xQ < 0) {
  4044. return null;
  4045. } // b1+b2 > 1, no intersection
  4046. if (DdQxE2 + DdE1xQ > DdN) {
  4047. return null;
  4048. } // Line intersects triangle, check if ray does.
  4049. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  4050. if (QdN < 0) {
  4051. return null;
  4052. } // Ray intersects triangle.
  4053. return this.at(QdN / DdN, target);
  4054. };
  4055. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  4056. this.origin.applyMatrix4(matrix4);
  4057. this.direction.transformDirection(matrix4);
  4058. return this;
  4059. };
  4060. _proto.equals = function equals(ray) {
  4061. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  4062. };
  4063. return Ray;
  4064. }();
  4065. var Matrix4 = /*#__PURE__*/function () {
  4066. function Matrix4() {
  4067. Object.defineProperty(this, 'isMatrix4', {
  4068. value: true
  4069. });
  4070. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  4071. if (arguments.length > 0) {
  4072. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  4073. }
  4074. }
  4075. var _proto = Matrix4.prototype;
  4076. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  4077. var te = this.elements;
  4078. te[0] = n11;
  4079. te[4] = n12;
  4080. te[8] = n13;
  4081. te[12] = n14;
  4082. te[1] = n21;
  4083. te[5] = n22;
  4084. te[9] = n23;
  4085. te[13] = n24;
  4086. te[2] = n31;
  4087. te[6] = n32;
  4088. te[10] = n33;
  4089. te[14] = n34;
  4090. te[3] = n41;
  4091. te[7] = n42;
  4092. te[11] = n43;
  4093. te[15] = n44;
  4094. return this;
  4095. };
  4096. _proto.identity = function identity() {
  4097. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4098. return this;
  4099. };
  4100. _proto.clone = function clone() {
  4101. return new Matrix4().fromArray(this.elements);
  4102. };
  4103. _proto.copy = function copy(m) {
  4104. var te = this.elements;
  4105. var me = m.elements;
  4106. te[0] = me[0];
  4107. te[1] = me[1];
  4108. te[2] = me[2];
  4109. te[3] = me[3];
  4110. te[4] = me[4];
  4111. te[5] = me[5];
  4112. te[6] = me[6];
  4113. te[7] = me[7];
  4114. te[8] = me[8];
  4115. te[9] = me[9];
  4116. te[10] = me[10];
  4117. te[11] = me[11];
  4118. te[12] = me[12];
  4119. te[13] = me[13];
  4120. te[14] = me[14];
  4121. te[15] = me[15];
  4122. return this;
  4123. };
  4124. _proto.copyPosition = function copyPosition(m) {
  4125. var te = this.elements,
  4126. me = m.elements;
  4127. te[12] = me[12];
  4128. te[13] = me[13];
  4129. te[14] = me[14];
  4130. return this;
  4131. };
  4132. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  4133. var me = m.elements;
  4134. 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);
  4135. return this;
  4136. };
  4137. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  4138. xAxis.setFromMatrixColumn(this, 0);
  4139. yAxis.setFromMatrixColumn(this, 1);
  4140. zAxis.setFromMatrixColumn(this, 2);
  4141. return this;
  4142. };
  4143. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  4144. 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);
  4145. return this;
  4146. };
  4147. _proto.extractRotation = function extractRotation(m) {
  4148. // this method does not support reflection matrices
  4149. var te = this.elements;
  4150. var me = m.elements;
  4151. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  4152. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  4153. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  4154. te[0] = me[0] * scaleX;
  4155. te[1] = me[1] * scaleX;
  4156. te[2] = me[2] * scaleX;
  4157. te[3] = 0;
  4158. te[4] = me[4] * scaleY;
  4159. te[5] = me[5] * scaleY;
  4160. te[6] = me[6] * scaleY;
  4161. te[7] = 0;
  4162. te[8] = me[8] * scaleZ;
  4163. te[9] = me[9] * scaleZ;
  4164. te[10] = me[10] * scaleZ;
  4165. te[11] = 0;
  4166. te[12] = 0;
  4167. te[13] = 0;
  4168. te[14] = 0;
  4169. te[15] = 1;
  4170. return this;
  4171. };
  4172. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  4173. if (!(euler && euler.isEuler)) {
  4174. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  4175. }
  4176. var te = this.elements;
  4177. var x = euler.x,
  4178. y = euler.y,
  4179. z = euler.z;
  4180. var a = Math.cos(x),
  4181. b = Math.sin(x);
  4182. var c = Math.cos(y),
  4183. d = Math.sin(y);
  4184. var e = Math.cos(z),
  4185. f = Math.sin(z);
  4186. if (euler.order === 'XYZ') {
  4187. var ae = a * e,
  4188. af = a * f,
  4189. be = b * e,
  4190. bf = b * f;
  4191. te[0] = c * e;
  4192. te[4] = -c * f;
  4193. te[8] = d;
  4194. te[1] = af + be * d;
  4195. te[5] = ae - bf * d;
  4196. te[9] = -b * c;
  4197. te[2] = bf - ae * d;
  4198. te[6] = be + af * d;
  4199. te[10] = a * c;
  4200. } else if (euler.order === 'YXZ') {
  4201. var ce = c * e,
  4202. cf = c * f,
  4203. de = d * e,
  4204. df = d * f;
  4205. te[0] = ce + df * b;
  4206. te[4] = de * b - cf;
  4207. te[8] = a * d;
  4208. te[1] = a * f;
  4209. te[5] = a * e;
  4210. te[9] = -b;
  4211. te[2] = cf * b - de;
  4212. te[6] = df + ce * b;
  4213. te[10] = a * c;
  4214. } else if (euler.order === 'ZXY') {
  4215. var _ce = c * e,
  4216. _cf = c * f,
  4217. _de = d * e,
  4218. _df = d * f;
  4219. te[0] = _ce - _df * b;
  4220. te[4] = -a * f;
  4221. te[8] = _de + _cf * b;
  4222. te[1] = _cf + _de * b;
  4223. te[5] = a * e;
  4224. te[9] = _df - _ce * b;
  4225. te[2] = -a * d;
  4226. te[6] = b;
  4227. te[10] = a * c;
  4228. } else if (euler.order === 'ZYX') {
  4229. var _ae = a * e,
  4230. _af = a * f,
  4231. _be = b * e,
  4232. _bf = b * f;
  4233. te[0] = c * e;
  4234. te[4] = _be * d - _af;
  4235. te[8] = _ae * d + _bf;
  4236. te[1] = c * f;
  4237. te[5] = _bf * d + _ae;
  4238. te[9] = _af * d - _be;
  4239. te[2] = -d;
  4240. te[6] = b * c;
  4241. te[10] = a * c;
  4242. } else if (euler.order === 'YZX') {
  4243. var ac = a * c,
  4244. ad = a * d,
  4245. bc = b * c,
  4246. bd = b * d;
  4247. te[0] = c * e;
  4248. te[4] = bd - ac * f;
  4249. te[8] = bc * f + ad;
  4250. te[1] = f;
  4251. te[5] = a * e;
  4252. te[9] = -b * e;
  4253. te[2] = -d * e;
  4254. te[6] = ad * f + bc;
  4255. te[10] = ac - bd * f;
  4256. } else if (euler.order === 'XZY') {
  4257. var _ac = a * c,
  4258. _ad = a * d,
  4259. _bc = b * c,
  4260. _bd = b * d;
  4261. te[0] = c * e;
  4262. te[4] = -f;
  4263. te[8] = d * e;
  4264. te[1] = _ac * f + _bd;
  4265. te[5] = a * e;
  4266. te[9] = _ad * f - _bc;
  4267. te[2] = _bc * f - _ad;
  4268. te[6] = b * e;
  4269. te[10] = _bd * f + _ac;
  4270. } // bottom row
  4271. te[3] = 0;
  4272. te[7] = 0;
  4273. te[11] = 0; // last column
  4274. te[12] = 0;
  4275. te[13] = 0;
  4276. te[14] = 0;
  4277. te[15] = 1;
  4278. return this;
  4279. };
  4280. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  4281. return this.compose(_zero, q, _one);
  4282. };
  4283. _proto.lookAt = function lookAt(eye, target, up) {
  4284. var te = this.elements;
  4285. _z.subVectors(eye, target);
  4286. if (_z.lengthSq() === 0) {
  4287. // eye and target are in the same position
  4288. _z.z = 1;
  4289. }
  4290. _z.normalize();
  4291. _x.crossVectors(up, _z);
  4292. if (_x.lengthSq() === 0) {
  4293. // up and z are parallel
  4294. if (Math.abs(up.z) === 1) {
  4295. _z.x += 0.0001;
  4296. } else {
  4297. _z.z += 0.0001;
  4298. }
  4299. _z.normalize();
  4300. _x.crossVectors(up, _z);
  4301. }
  4302. _x.normalize();
  4303. _y.crossVectors(_z, _x);
  4304. te[0] = _x.x;
  4305. te[4] = _y.x;
  4306. te[8] = _z.x;
  4307. te[1] = _x.y;
  4308. te[5] = _y.y;
  4309. te[9] = _z.y;
  4310. te[2] = _x.z;
  4311. te[6] = _y.z;
  4312. te[10] = _z.z;
  4313. return this;
  4314. };
  4315. _proto.multiply = function multiply(m, n) {
  4316. if (n !== undefined) {
  4317. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  4318. return this.multiplyMatrices(m, n);
  4319. }
  4320. return this.multiplyMatrices(this, m);
  4321. };
  4322. _proto.premultiply = function premultiply(m) {
  4323. return this.multiplyMatrices(m, this);
  4324. };
  4325. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  4326. var ae = a.elements;
  4327. var be = b.elements;
  4328. var te = this.elements;
  4329. var a11 = ae[0],
  4330. a12 = ae[4],
  4331. a13 = ae[8],
  4332. a14 = ae[12];
  4333. var a21 = ae[1],
  4334. a22 = ae[5],
  4335. a23 = ae[9],
  4336. a24 = ae[13];
  4337. var a31 = ae[2],
  4338. a32 = ae[6],
  4339. a33 = ae[10],
  4340. a34 = ae[14];
  4341. var a41 = ae[3],
  4342. a42 = ae[7],
  4343. a43 = ae[11],
  4344. a44 = ae[15];
  4345. var b11 = be[0],
  4346. b12 = be[4],
  4347. b13 = be[8],
  4348. b14 = be[12];
  4349. var b21 = be[1],
  4350. b22 = be[5],
  4351. b23 = be[9],
  4352. b24 = be[13];
  4353. var b31 = be[2],
  4354. b32 = be[6],
  4355. b33 = be[10],
  4356. b34 = be[14];
  4357. var b41 = be[3],
  4358. b42 = be[7],
  4359. b43 = be[11],
  4360. b44 = be[15];
  4361. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  4362. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  4363. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  4364. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  4365. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  4366. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  4367. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  4368. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  4369. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  4370. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  4371. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  4372. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  4373. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  4374. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  4375. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  4376. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  4377. return this;
  4378. };
  4379. _proto.multiplyScalar = function multiplyScalar(s) {
  4380. var te = this.elements;
  4381. te[0] *= s;
  4382. te[4] *= s;
  4383. te[8] *= s;
  4384. te[12] *= s;
  4385. te[1] *= s;
  4386. te[5] *= s;
  4387. te[9] *= s;
  4388. te[13] *= s;
  4389. te[2] *= s;
  4390. te[6] *= s;
  4391. te[10] *= s;
  4392. te[14] *= s;
  4393. te[3] *= s;
  4394. te[7] *= s;
  4395. te[11] *= s;
  4396. te[15] *= s;
  4397. return this;
  4398. };
  4399. _proto.determinant = function determinant() {
  4400. var te = this.elements;
  4401. var n11 = te[0],
  4402. n12 = te[4],
  4403. n13 = te[8],
  4404. n14 = te[12];
  4405. var n21 = te[1],
  4406. n22 = te[5],
  4407. n23 = te[9],
  4408. n24 = te[13];
  4409. var n31 = te[2],
  4410. n32 = te[6],
  4411. n33 = te[10],
  4412. n34 = te[14];
  4413. var n41 = te[3],
  4414. n42 = te[7],
  4415. n43 = te[11],
  4416. n44 = te[15]; //TODO: make this more efficient
  4417. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  4418. 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);
  4419. };
  4420. _proto.transpose = function transpose() {
  4421. var te = this.elements;
  4422. var tmp;
  4423. tmp = te[1];
  4424. te[1] = te[4];
  4425. te[4] = tmp;
  4426. tmp = te[2];
  4427. te[2] = te[8];
  4428. te[8] = tmp;
  4429. tmp = te[6];
  4430. te[6] = te[9];
  4431. te[9] = tmp;
  4432. tmp = te[3];
  4433. te[3] = te[12];
  4434. te[12] = tmp;
  4435. tmp = te[7];
  4436. te[7] = te[13];
  4437. te[13] = tmp;
  4438. tmp = te[11];
  4439. te[11] = te[14];
  4440. te[14] = tmp;
  4441. return this;
  4442. };
  4443. _proto.setPosition = function setPosition(x, y, z) {
  4444. var te = this.elements;
  4445. if (x.isVector3) {
  4446. te[12] = x.x;
  4447. te[13] = x.y;
  4448. te[14] = x.z;
  4449. } else {
  4450. te[12] = x;
  4451. te[13] = y;
  4452. te[14] = z;
  4453. }
  4454. return this;
  4455. };
  4456. _proto.invert = function invert() {
  4457. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  4458. var te = this.elements,
  4459. n11 = te[0],
  4460. n21 = te[1],
  4461. n31 = te[2],
  4462. n41 = te[3],
  4463. n12 = te[4],
  4464. n22 = te[5],
  4465. n32 = te[6],
  4466. n42 = te[7],
  4467. n13 = te[8],
  4468. n23 = te[9],
  4469. n33 = te[10],
  4470. n43 = te[11],
  4471. n14 = te[12],
  4472. n24 = te[13],
  4473. n34 = te[14],
  4474. n44 = te[15],
  4475. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  4476. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  4477. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  4478. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  4479. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  4480. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  4481. var detInv = 1 / det;
  4482. te[0] = t11 * detInv;
  4483. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  4484. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  4485. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  4486. te[4] = t12 * detInv;
  4487. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  4488. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  4489. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  4490. te[8] = t13 * detInv;
  4491. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  4492. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  4493. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  4494. te[12] = t14 * detInv;
  4495. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  4496. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  4497. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  4498. return this;
  4499. };
  4500. _proto.scale = function scale(v) {
  4501. var te = this.elements;
  4502. var x = v.x,
  4503. y = v.y,
  4504. z = v.z;
  4505. te[0] *= x;
  4506. te[4] *= y;
  4507. te[8] *= z;
  4508. te[1] *= x;
  4509. te[5] *= y;
  4510. te[9] *= z;
  4511. te[2] *= x;
  4512. te[6] *= y;
  4513. te[10] *= z;
  4514. te[3] *= x;
  4515. te[7] *= y;
  4516. te[11] *= z;
  4517. return this;
  4518. };
  4519. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  4520. var te = this.elements;
  4521. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  4522. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  4523. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  4524. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  4525. };
  4526. _proto.makeTranslation = function makeTranslation(x, y, z) {
  4527. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  4528. return this;
  4529. };
  4530. _proto.makeRotationX = function makeRotationX(theta) {
  4531. var c = Math.cos(theta),
  4532. s = Math.sin(theta);
  4533. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  4534. return this;
  4535. };
  4536. _proto.makeRotationY = function makeRotationY(theta) {
  4537. var c = Math.cos(theta),
  4538. s = Math.sin(theta);
  4539. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  4540. return this;
  4541. };
  4542. _proto.makeRotationZ = function makeRotationZ(theta) {
  4543. var c = Math.cos(theta),
  4544. s = Math.sin(theta);
  4545. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4546. return this;
  4547. };
  4548. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  4549. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4550. var c = Math.cos(angle);
  4551. var s = Math.sin(angle);
  4552. var t = 1 - c;
  4553. var x = axis.x,
  4554. y = axis.y,
  4555. z = axis.z;
  4556. var tx = t * x,
  4557. ty = t * y;
  4558. 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);
  4559. return this;
  4560. };
  4561. _proto.makeScale = function makeScale(x, y, z) {
  4562. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  4563. return this;
  4564. };
  4565. _proto.makeShear = function makeShear(x, y, z) {
  4566. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  4567. return this;
  4568. };
  4569. _proto.compose = function compose(position, quaternion, scale) {
  4570. var te = this.elements;
  4571. var x = quaternion._x,
  4572. y = quaternion._y,
  4573. z = quaternion._z,
  4574. w = quaternion._w;
  4575. var x2 = x + x,
  4576. y2 = y + y,
  4577. z2 = z + z;
  4578. var xx = x * x2,
  4579. xy = x * y2,
  4580. xz = x * z2;
  4581. var yy = y * y2,
  4582. yz = y * z2,
  4583. zz = z * z2;
  4584. var wx = w * x2,
  4585. wy = w * y2,
  4586. wz = w * z2;
  4587. var sx = scale.x,
  4588. sy = scale.y,
  4589. sz = scale.z;
  4590. te[0] = (1 - (yy + zz)) * sx;
  4591. te[1] = (xy + wz) * sx;
  4592. te[2] = (xz - wy) * sx;
  4593. te[3] = 0;
  4594. te[4] = (xy - wz) * sy;
  4595. te[5] = (1 - (xx + zz)) * sy;
  4596. te[6] = (yz + wx) * sy;
  4597. te[7] = 0;
  4598. te[8] = (xz + wy) * sz;
  4599. te[9] = (yz - wx) * sz;
  4600. te[10] = (1 - (xx + yy)) * sz;
  4601. te[11] = 0;
  4602. te[12] = position.x;
  4603. te[13] = position.y;
  4604. te[14] = position.z;
  4605. te[15] = 1;
  4606. return this;
  4607. };
  4608. _proto.decompose = function decompose(position, quaternion, scale) {
  4609. var te = this.elements;
  4610. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  4611. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  4612. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  4613. var det = this.determinant();
  4614. if (det < 0) sx = -sx;
  4615. position.x = te[12];
  4616. position.y = te[13];
  4617. position.z = te[14]; // scale the rotation part
  4618. _m1.copy(this);
  4619. var invSX = 1 / sx;
  4620. var invSY = 1 / sy;
  4621. var invSZ = 1 / sz;
  4622. _m1.elements[0] *= invSX;
  4623. _m1.elements[1] *= invSX;
  4624. _m1.elements[2] *= invSX;
  4625. _m1.elements[4] *= invSY;
  4626. _m1.elements[5] *= invSY;
  4627. _m1.elements[6] *= invSY;
  4628. _m1.elements[8] *= invSZ;
  4629. _m1.elements[9] *= invSZ;
  4630. _m1.elements[10] *= invSZ;
  4631. quaternion.setFromRotationMatrix(_m1);
  4632. scale.x = sx;
  4633. scale.y = sy;
  4634. scale.z = sz;
  4635. return this;
  4636. };
  4637. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  4638. if (far === undefined) {
  4639. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  4640. }
  4641. var te = this.elements;
  4642. var x = 2 * near / (right - left);
  4643. var y = 2 * near / (top - bottom);
  4644. var a = (right + left) / (right - left);
  4645. var b = (top + bottom) / (top - bottom);
  4646. var c = -(far + near) / (far - near);
  4647. var d = -2 * far * near / (far - near);
  4648. te[0] = x;
  4649. te[4] = 0;
  4650. te[8] = a;
  4651. te[12] = 0;
  4652. te[1] = 0;
  4653. te[5] = y;
  4654. te[9] = b;
  4655. te[13] = 0;
  4656. te[2] = 0;
  4657. te[6] = 0;
  4658. te[10] = c;
  4659. te[14] = d;
  4660. te[3] = 0;
  4661. te[7] = 0;
  4662. te[11] = -1;
  4663. te[15] = 0;
  4664. return this;
  4665. };
  4666. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  4667. var te = this.elements;
  4668. var w = 1.0 / (right - left);
  4669. var h = 1.0 / (top - bottom);
  4670. var p = 1.0 / (far - near);
  4671. var x = (right + left) * w;
  4672. var y = (top + bottom) * h;
  4673. var z = (far + near) * p;
  4674. te[0] = 2 * w;
  4675. te[4] = 0;
  4676. te[8] = 0;
  4677. te[12] = -x;
  4678. te[1] = 0;
  4679. te[5] = 2 * h;
  4680. te[9] = 0;
  4681. te[13] = -y;
  4682. te[2] = 0;
  4683. te[6] = 0;
  4684. te[10] = -2 * p;
  4685. te[14] = -z;
  4686. te[3] = 0;
  4687. te[7] = 0;
  4688. te[11] = 0;
  4689. te[15] = 1;
  4690. return this;
  4691. };
  4692. _proto.equals = function equals(matrix) {
  4693. var te = this.elements;
  4694. var me = matrix.elements;
  4695. for (var i = 0; i < 16; i++) {
  4696. if (te[i] !== me[i]) return false;
  4697. }
  4698. return true;
  4699. };
  4700. _proto.fromArray = function fromArray(array, offset) {
  4701. if (offset === void 0) {
  4702. offset = 0;
  4703. }
  4704. for (var i = 0; i < 16; i++) {
  4705. this.elements[i] = array[i + offset];
  4706. }
  4707. return this;
  4708. };
  4709. _proto.toArray = function toArray(array, offset) {
  4710. if (array === void 0) {
  4711. array = [];
  4712. }
  4713. if (offset === void 0) {
  4714. offset = 0;
  4715. }
  4716. var te = this.elements;
  4717. array[offset] = te[0];
  4718. array[offset + 1] = te[1];
  4719. array[offset + 2] = te[2];
  4720. array[offset + 3] = te[3];
  4721. array[offset + 4] = te[4];
  4722. array[offset + 5] = te[5];
  4723. array[offset + 6] = te[6];
  4724. array[offset + 7] = te[7];
  4725. array[offset + 8] = te[8];
  4726. array[offset + 9] = te[9];
  4727. array[offset + 10] = te[10];
  4728. array[offset + 11] = te[11];
  4729. array[offset + 12] = te[12];
  4730. array[offset + 13] = te[13];
  4731. array[offset + 14] = te[14];
  4732. array[offset + 15] = te[15];
  4733. return array;
  4734. };
  4735. return Matrix4;
  4736. }();
  4737. var _v1$1 = /*@__PURE__*/new Vector3();
  4738. var _m1 = /*@__PURE__*/new Matrix4();
  4739. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4740. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4741. var _x = /*@__PURE__*/new Vector3();
  4742. var _y = /*@__PURE__*/new Vector3();
  4743. var _z = /*@__PURE__*/new Vector3();
  4744. var Euler = /*#__PURE__*/function () {
  4745. function Euler(x, y, z, order) {
  4746. if (x === void 0) {
  4747. x = 0;
  4748. }
  4749. if (y === void 0) {
  4750. y = 0;
  4751. }
  4752. if (z === void 0) {
  4753. z = 0;
  4754. }
  4755. if (order === void 0) {
  4756. order = Euler.DefaultOrder;
  4757. }
  4758. Object.defineProperty(this, 'isEuler', {
  4759. value: true
  4760. });
  4761. this._x = x;
  4762. this._y = y;
  4763. this._z = z;
  4764. this._order = order;
  4765. }
  4766. var _proto = Euler.prototype;
  4767. _proto.set = function set(x, y, z, order) {
  4768. this._x = x;
  4769. this._y = y;
  4770. this._z = z;
  4771. this._order = order || this._order;
  4772. this._onChangeCallback();
  4773. return this;
  4774. };
  4775. _proto.clone = function clone() {
  4776. return new this.constructor(this._x, this._y, this._z, this._order);
  4777. };
  4778. _proto.copy = function copy(euler) {
  4779. this._x = euler._x;
  4780. this._y = euler._y;
  4781. this._z = euler._z;
  4782. this._order = euler._order;
  4783. this._onChangeCallback();
  4784. return this;
  4785. };
  4786. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4787. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4788. var te = m.elements;
  4789. var m11 = te[0],
  4790. m12 = te[4],
  4791. m13 = te[8];
  4792. var m21 = te[1],
  4793. m22 = te[5],
  4794. m23 = te[9];
  4795. var m31 = te[2],
  4796. m32 = te[6],
  4797. m33 = te[10];
  4798. order = order || this._order;
  4799. switch (order) {
  4800. case 'XYZ':
  4801. this._y = Math.asin(clamp(m13, -1, 1));
  4802. if (Math.abs(m13) < 0.9999999) {
  4803. this._x = Math.atan2(-m23, m33);
  4804. this._z = Math.atan2(-m12, m11);
  4805. } else {
  4806. this._x = Math.atan2(m32, m22);
  4807. this._z = 0;
  4808. }
  4809. break;
  4810. case 'YXZ':
  4811. this._x = Math.asin(-clamp(m23, -1, 1));
  4812. if (Math.abs(m23) < 0.9999999) {
  4813. this._y = Math.atan2(m13, m33);
  4814. this._z = Math.atan2(m21, m22);
  4815. } else {
  4816. this._y = Math.atan2(-m31, m11);
  4817. this._z = 0;
  4818. }
  4819. break;
  4820. case 'ZXY':
  4821. this._x = Math.asin(clamp(m32, -1, 1));
  4822. if (Math.abs(m32) < 0.9999999) {
  4823. this._y = Math.atan2(-m31, m33);
  4824. this._z = Math.atan2(-m12, m22);
  4825. } else {
  4826. this._y = 0;
  4827. this._z = Math.atan2(m21, m11);
  4828. }
  4829. break;
  4830. case 'ZYX':
  4831. this._y = Math.asin(-clamp(m31, -1, 1));
  4832. if (Math.abs(m31) < 0.9999999) {
  4833. this._x = Math.atan2(m32, m33);
  4834. this._z = Math.atan2(m21, m11);
  4835. } else {
  4836. this._x = 0;
  4837. this._z = Math.atan2(-m12, m22);
  4838. }
  4839. break;
  4840. case 'YZX':
  4841. this._z = Math.asin(clamp(m21, -1, 1));
  4842. if (Math.abs(m21) < 0.9999999) {
  4843. this._x = Math.atan2(-m23, m22);
  4844. this._y = Math.atan2(-m31, m11);
  4845. } else {
  4846. this._x = 0;
  4847. this._y = Math.atan2(m13, m33);
  4848. }
  4849. break;
  4850. case 'XZY':
  4851. this._z = Math.asin(-clamp(m12, -1, 1));
  4852. if (Math.abs(m12) < 0.9999999) {
  4853. this._x = Math.atan2(m32, m22);
  4854. this._y = Math.atan2(m13, m11);
  4855. } else {
  4856. this._x = Math.atan2(-m23, m33);
  4857. this._y = 0;
  4858. }
  4859. break;
  4860. default:
  4861. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4862. }
  4863. this._order = order;
  4864. if (update !== false) this._onChangeCallback();
  4865. return this;
  4866. };
  4867. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4868. _matrix.makeRotationFromQuaternion(q);
  4869. return this.setFromRotationMatrix(_matrix, order, update);
  4870. };
  4871. _proto.setFromVector3 = function setFromVector3(v, order) {
  4872. return this.set(v.x, v.y, v.z, order || this._order);
  4873. };
  4874. _proto.reorder = function reorder(newOrder) {
  4875. // WARNING: this discards revolution information -bhouston
  4876. _quaternion$1.setFromEuler(this);
  4877. return this.setFromQuaternion(_quaternion$1, newOrder);
  4878. };
  4879. _proto.equals = function equals(euler) {
  4880. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4881. };
  4882. _proto.fromArray = function fromArray(array) {
  4883. this._x = array[0];
  4884. this._y = array[1];
  4885. this._z = array[2];
  4886. if (array[3] !== undefined) this._order = array[3];
  4887. this._onChangeCallback();
  4888. return this;
  4889. };
  4890. _proto.toArray = function toArray(array, offset) {
  4891. if (array === void 0) {
  4892. array = [];
  4893. }
  4894. if (offset === void 0) {
  4895. offset = 0;
  4896. }
  4897. array[offset] = this._x;
  4898. array[offset + 1] = this._y;
  4899. array[offset + 2] = this._z;
  4900. array[offset + 3] = this._order;
  4901. return array;
  4902. };
  4903. _proto.toVector3 = function toVector3(optionalResult) {
  4904. if (optionalResult) {
  4905. return optionalResult.set(this._x, this._y, this._z);
  4906. } else {
  4907. return new Vector3(this._x, this._y, this._z);
  4908. }
  4909. };
  4910. _proto._onChange = function _onChange(callback) {
  4911. this._onChangeCallback = callback;
  4912. return this;
  4913. };
  4914. _proto._onChangeCallback = function _onChangeCallback() {};
  4915. _createClass(Euler, [{
  4916. key: "x",
  4917. get: function get() {
  4918. return this._x;
  4919. },
  4920. set: function set(value) {
  4921. this._x = value;
  4922. this._onChangeCallback();
  4923. }
  4924. }, {
  4925. key: "y",
  4926. get: function get() {
  4927. return this._y;
  4928. },
  4929. set: function set(value) {
  4930. this._y = value;
  4931. this._onChangeCallback();
  4932. }
  4933. }, {
  4934. key: "z",
  4935. get: function get() {
  4936. return this._z;
  4937. },
  4938. set: function set(value) {
  4939. this._z = value;
  4940. this._onChangeCallback();
  4941. }
  4942. }, {
  4943. key: "order",
  4944. get: function get() {
  4945. return this._order;
  4946. },
  4947. set: function set(value) {
  4948. this._order = value;
  4949. this._onChangeCallback();
  4950. }
  4951. }]);
  4952. return Euler;
  4953. }();
  4954. Euler.DefaultOrder = 'XYZ';
  4955. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4956. var _matrix = /*@__PURE__*/new Matrix4();
  4957. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4958. var Layers = /*#__PURE__*/function () {
  4959. function Layers() {
  4960. this.mask = 1 | 0;
  4961. }
  4962. var _proto = Layers.prototype;
  4963. _proto.set = function set(channel) {
  4964. this.mask = 1 << channel | 0;
  4965. };
  4966. _proto.enable = function enable(channel) {
  4967. this.mask |= 1 << channel | 0;
  4968. };
  4969. _proto.enableAll = function enableAll() {
  4970. this.mask = 0xffffffff | 0;
  4971. };
  4972. _proto.toggle = function toggle(channel) {
  4973. this.mask ^= 1 << channel | 0;
  4974. };
  4975. _proto.disable = function disable(channel) {
  4976. this.mask &= ~(1 << channel | 0);
  4977. };
  4978. _proto.disableAll = function disableAll() {
  4979. this.mask = 0;
  4980. };
  4981. _proto.test = function test(layers) {
  4982. return (this.mask & layers.mask) !== 0;
  4983. };
  4984. return Layers;
  4985. }();
  4986. var _object3DId = 0;
  4987. var _v1$2 = new Vector3();
  4988. var _q1 = new Quaternion();
  4989. var _m1$1 = new Matrix4();
  4990. var _target = new Vector3();
  4991. var _position = new Vector3();
  4992. var _scale = new Vector3();
  4993. var _quaternion$2 = new Quaternion();
  4994. var _xAxis = new Vector3(1, 0, 0);
  4995. var _yAxis = new Vector3(0, 1, 0);
  4996. var _zAxis = new Vector3(0, 0, 1);
  4997. var _addedEvent = {
  4998. type: 'added'
  4999. };
  5000. var _removedEvent = {
  5001. type: 'removed'
  5002. };
  5003. function Object3D() {
  5004. Object.defineProperty(this, 'id', {
  5005. value: _object3DId++
  5006. });
  5007. this.uuid = MathUtils.generateUUID();
  5008. this.name = '';
  5009. this.type = 'Object3D';
  5010. this.parent = null;
  5011. this.children = [];
  5012. this.up = Object3D.DefaultUp.clone();
  5013. var position = new Vector3();
  5014. var rotation = new Euler();
  5015. var quaternion = new Quaternion();
  5016. var scale = new Vector3(1, 1, 1);
  5017. function onRotationChange() {
  5018. quaternion.setFromEuler(rotation, false);
  5019. }
  5020. function onQuaternionChange() {
  5021. rotation.setFromQuaternion(quaternion, undefined, false);
  5022. }
  5023. rotation._onChange(onRotationChange);
  5024. quaternion._onChange(onQuaternionChange);
  5025. Object.defineProperties(this, {
  5026. position: {
  5027. configurable: true,
  5028. enumerable: true,
  5029. value: position
  5030. },
  5031. rotation: {
  5032. configurable: true,
  5033. enumerable: true,
  5034. value: rotation
  5035. },
  5036. quaternion: {
  5037. configurable: true,
  5038. enumerable: true,
  5039. value: quaternion
  5040. },
  5041. scale: {
  5042. configurable: true,
  5043. enumerable: true,
  5044. value: scale
  5045. },
  5046. modelViewMatrix: {
  5047. value: new Matrix4()
  5048. },
  5049. normalMatrix: {
  5050. value: new Matrix3()
  5051. }
  5052. });
  5053. this.matrix = new Matrix4();
  5054. this.matrixWorld = new Matrix4();
  5055. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5056. this.matrixWorldNeedsUpdate = false;
  5057. this.layers = new Layers();
  5058. this.visible = true;
  5059. this.castShadow = false;
  5060. this.receiveShadow = false;
  5061. this.frustumCulled = true;
  5062. this.renderOrder = 0;
  5063. this.animations = [];
  5064. this.userData = {};
  5065. }
  5066. Object3D.DefaultUp = new Vector3(0, 1, 0);
  5067. Object3D.DefaultMatrixAutoUpdate = true;
  5068. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5069. constructor: Object3D,
  5070. isObject3D: true,
  5071. onBeforeRender: function onBeforeRender() {},
  5072. onAfterRender: function onAfterRender() {},
  5073. applyMatrix4: function applyMatrix4(matrix) {
  5074. if (this.matrixAutoUpdate) this.updateMatrix();
  5075. this.matrix.premultiply(matrix);
  5076. this.matrix.decompose(this.position, this.quaternion, this.scale);
  5077. },
  5078. applyQuaternion: function applyQuaternion(q) {
  5079. this.quaternion.premultiply(q);
  5080. return this;
  5081. },
  5082. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  5083. // assumes axis is normalized
  5084. this.quaternion.setFromAxisAngle(axis, angle);
  5085. },
  5086. setRotationFromEuler: function setRotationFromEuler(euler) {
  5087. this.quaternion.setFromEuler(euler, true);
  5088. },
  5089. setRotationFromMatrix: function setRotationFromMatrix(m) {
  5090. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5091. this.quaternion.setFromRotationMatrix(m);
  5092. },
  5093. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  5094. // assumes q is normalized
  5095. this.quaternion.copy(q);
  5096. },
  5097. rotateOnAxis: function rotateOnAxis(axis, angle) {
  5098. // rotate object on axis in object space
  5099. // axis is assumed to be normalized
  5100. _q1.setFromAxisAngle(axis, angle);
  5101. this.quaternion.multiply(_q1);
  5102. return this;
  5103. },
  5104. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  5105. // rotate object on axis in world space
  5106. // axis is assumed to be normalized
  5107. // method assumes no rotated parent
  5108. _q1.setFromAxisAngle(axis, angle);
  5109. this.quaternion.premultiply(_q1);
  5110. return this;
  5111. },
  5112. rotateX: function rotateX(angle) {
  5113. return this.rotateOnAxis(_xAxis, angle);
  5114. },
  5115. rotateY: function rotateY(angle) {
  5116. return this.rotateOnAxis(_yAxis, angle);
  5117. },
  5118. rotateZ: function rotateZ(angle) {
  5119. return this.rotateOnAxis(_zAxis, angle);
  5120. },
  5121. translateOnAxis: function translateOnAxis(axis, distance) {
  5122. // translate object by distance along axis in object space
  5123. // axis is assumed to be normalized
  5124. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  5125. this.position.add(_v1$2.multiplyScalar(distance));
  5126. return this;
  5127. },
  5128. translateX: function translateX(distance) {
  5129. return this.translateOnAxis(_xAxis, distance);
  5130. },
  5131. translateY: function translateY(distance) {
  5132. return this.translateOnAxis(_yAxis, distance);
  5133. },
  5134. translateZ: function translateZ(distance) {
  5135. return this.translateOnAxis(_zAxis, distance);
  5136. },
  5137. localToWorld: function localToWorld(vector) {
  5138. return vector.applyMatrix4(this.matrixWorld);
  5139. },
  5140. worldToLocal: function worldToLocal(vector) {
  5141. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  5142. },
  5143. lookAt: function lookAt(x, y, z) {
  5144. // This method does not support objects having non-uniformly-scaled parent(s)
  5145. if (x.isVector3) {
  5146. _target.copy(x);
  5147. } else {
  5148. _target.set(x, y, z);
  5149. }
  5150. var parent = this.parent;
  5151. this.updateWorldMatrix(true, false);
  5152. _position.setFromMatrixPosition(this.matrixWorld);
  5153. if (this.isCamera || this.isLight) {
  5154. _m1$1.lookAt(_position, _target, this.up);
  5155. } else {
  5156. _m1$1.lookAt(_target, _position, this.up);
  5157. }
  5158. this.quaternion.setFromRotationMatrix(_m1$1);
  5159. if (parent) {
  5160. _m1$1.extractRotation(parent.matrixWorld);
  5161. _q1.setFromRotationMatrix(_m1$1);
  5162. this.quaternion.premultiply(_q1.invert());
  5163. }
  5164. },
  5165. add: function add(object) {
  5166. if (arguments.length > 1) {
  5167. for (var i = 0; i < arguments.length; i++) {
  5168. this.add(arguments[i]);
  5169. }
  5170. return this;
  5171. }
  5172. if (object === this) {
  5173. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  5174. return this;
  5175. }
  5176. if (object && object.isObject3D) {
  5177. if (object.parent !== null) {
  5178. object.parent.remove(object);
  5179. }
  5180. object.parent = this;
  5181. this.children.push(object);
  5182. object.dispatchEvent(_addedEvent);
  5183. } else {
  5184. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  5185. }
  5186. return this;
  5187. },
  5188. remove: function remove(object) {
  5189. if (arguments.length > 1) {
  5190. for (var i = 0; i < arguments.length; i++) {
  5191. this.remove(arguments[i]);
  5192. }
  5193. return this;
  5194. }
  5195. var index = this.children.indexOf(object);
  5196. if (index !== -1) {
  5197. object.parent = null;
  5198. this.children.splice(index, 1);
  5199. object.dispatchEvent(_removedEvent);
  5200. }
  5201. return this;
  5202. },
  5203. clear: function clear() {
  5204. for (var i = 0; i < this.children.length; i++) {
  5205. var object = this.children[i];
  5206. object.parent = null;
  5207. object.dispatchEvent(_removedEvent);
  5208. }
  5209. this.children.length = 0;
  5210. return this;
  5211. },
  5212. attach: function attach(object) {
  5213. // adds object as a child of this, while maintaining the object's world transform
  5214. this.updateWorldMatrix(true, false);
  5215. _m1$1.copy(this.matrixWorld).invert();
  5216. if (object.parent !== null) {
  5217. object.parent.updateWorldMatrix(true, false);
  5218. _m1$1.multiply(object.parent.matrixWorld);
  5219. }
  5220. object.applyMatrix4(_m1$1);
  5221. object.updateWorldMatrix(false, false);
  5222. this.add(object);
  5223. return this;
  5224. },
  5225. getObjectById: function getObjectById(id) {
  5226. return this.getObjectByProperty('id', id);
  5227. },
  5228. getObjectByName: function getObjectByName(name) {
  5229. return this.getObjectByProperty('name', name);
  5230. },
  5231. getObjectByProperty: function getObjectByProperty(name, value) {
  5232. if (this[name] === value) return this;
  5233. for (var i = 0, l = this.children.length; i < l; i++) {
  5234. var child = this.children[i];
  5235. var object = child.getObjectByProperty(name, value);
  5236. if (object !== undefined) {
  5237. return object;
  5238. }
  5239. }
  5240. return undefined;
  5241. },
  5242. getWorldPosition: function getWorldPosition(target) {
  5243. if (target === undefined) {
  5244. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  5245. target = new Vector3();
  5246. }
  5247. this.updateWorldMatrix(true, false);
  5248. return target.setFromMatrixPosition(this.matrixWorld);
  5249. },
  5250. getWorldQuaternion: function getWorldQuaternion(target) {
  5251. if (target === undefined) {
  5252. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  5253. target = new Quaternion();
  5254. }
  5255. this.updateWorldMatrix(true, false);
  5256. this.matrixWorld.decompose(_position, target, _scale);
  5257. return target;
  5258. },
  5259. getWorldScale: function getWorldScale(target) {
  5260. if (target === undefined) {
  5261. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  5262. target = new Vector3();
  5263. }
  5264. this.updateWorldMatrix(true, false);
  5265. this.matrixWorld.decompose(_position, _quaternion$2, target);
  5266. return target;
  5267. },
  5268. getWorldDirection: function getWorldDirection(target) {
  5269. if (target === undefined) {
  5270. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  5271. target = new Vector3();
  5272. }
  5273. this.updateWorldMatrix(true, false);
  5274. var e = this.matrixWorld.elements;
  5275. return target.set(e[8], e[9], e[10]).normalize();
  5276. },
  5277. raycast: function raycast() {},
  5278. traverse: function traverse(callback) {
  5279. callback(this);
  5280. var children = this.children;
  5281. for (var i = 0, l = children.length; i < l; i++) {
  5282. children[i].traverse(callback);
  5283. }
  5284. },
  5285. traverseVisible: function traverseVisible(callback) {
  5286. if (this.visible === false) return;
  5287. callback(this);
  5288. var children = this.children;
  5289. for (var i = 0, l = children.length; i < l; i++) {
  5290. children[i].traverseVisible(callback);
  5291. }
  5292. },
  5293. traverseAncestors: function traverseAncestors(callback) {
  5294. var parent = this.parent;
  5295. if (parent !== null) {
  5296. callback(parent);
  5297. parent.traverseAncestors(callback);
  5298. }
  5299. },
  5300. updateMatrix: function updateMatrix() {
  5301. this.matrix.compose(this.position, this.quaternion, this.scale);
  5302. this.matrixWorldNeedsUpdate = true;
  5303. },
  5304. updateMatrixWorld: function updateMatrixWorld(force) {
  5305. if (this.matrixAutoUpdate) this.updateMatrix();
  5306. if (this.matrixWorldNeedsUpdate || force) {
  5307. if (this.parent === null) {
  5308. this.matrixWorld.copy(this.matrix);
  5309. } else {
  5310. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5311. }
  5312. this.matrixWorldNeedsUpdate = false;
  5313. force = true;
  5314. } // update children
  5315. var children = this.children;
  5316. for (var i = 0, l = children.length; i < l; i++) {
  5317. children[i].updateMatrixWorld(force);
  5318. }
  5319. },
  5320. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  5321. var parent = this.parent;
  5322. if (updateParents === true && parent !== null) {
  5323. parent.updateWorldMatrix(true, false);
  5324. }
  5325. if (this.matrixAutoUpdate) this.updateMatrix();
  5326. if (this.parent === null) {
  5327. this.matrixWorld.copy(this.matrix);
  5328. } else {
  5329. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5330. } // update children
  5331. if (updateChildren === true) {
  5332. var children = this.children;
  5333. for (var i = 0, l = children.length; i < l; i++) {
  5334. children[i].updateWorldMatrix(false, true);
  5335. }
  5336. }
  5337. },
  5338. toJSON: function toJSON(meta) {
  5339. // meta is a string when called from JSON.stringify
  5340. var isRootObject = meta === undefined || typeof meta === 'string';
  5341. var output = {}; // meta is a hash used to collect geometries, materials.
  5342. // not providing it implies that this is the root object
  5343. // being serialized.
  5344. if (isRootObject) {
  5345. // initialize meta obj
  5346. meta = {
  5347. geometries: {},
  5348. materials: {},
  5349. textures: {},
  5350. images: {},
  5351. shapes: {},
  5352. skeletons: {},
  5353. animations: {}
  5354. };
  5355. output.metadata = {
  5356. version: 4.5,
  5357. type: 'Object',
  5358. generator: 'Object3D.toJSON'
  5359. };
  5360. } // standard Object3D serialization
  5361. var object = {};
  5362. object.uuid = this.uuid;
  5363. object.type = this.type;
  5364. if (this.name !== '') object.name = this.name;
  5365. if (this.castShadow === true) object.castShadow = true;
  5366. if (this.receiveShadow === true) object.receiveShadow = true;
  5367. if (this.visible === false) object.visible = false;
  5368. if (this.frustumCulled === false) object.frustumCulled = false;
  5369. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  5370. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  5371. object.layers = this.layers.mask;
  5372. object.matrix = this.matrix.toArray();
  5373. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  5374. if (this.isInstancedMesh) {
  5375. object.type = 'InstancedMesh';
  5376. object.count = this.count;
  5377. object.instanceMatrix = this.instanceMatrix.toJSON();
  5378. } //
  5379. function serialize(library, element) {
  5380. if (library[element.uuid] === undefined) {
  5381. library[element.uuid] = element.toJSON(meta);
  5382. }
  5383. return element.uuid;
  5384. }
  5385. if (this.isMesh || this.isLine || this.isPoints) {
  5386. object.geometry = serialize(meta.geometries, this.geometry);
  5387. var parameters = this.geometry.parameters;
  5388. if (parameters !== undefined && parameters.shapes !== undefined) {
  5389. var shapes = parameters.shapes;
  5390. if (Array.isArray(shapes)) {
  5391. for (var i = 0, l = shapes.length; i < l; i++) {
  5392. var shape = shapes[i];
  5393. serialize(meta.shapes, shape);
  5394. }
  5395. } else {
  5396. serialize(meta.shapes, shapes);
  5397. }
  5398. }
  5399. }
  5400. if (this.isSkinnedMesh) {
  5401. object.bindMode = this.bindMode;
  5402. object.bindMatrix = this.bindMatrix.toArray();
  5403. if (this.skeleton !== undefined) {
  5404. serialize(meta.skeletons, this.skeleton);
  5405. object.skeleton = this.skeleton.uuid;
  5406. }
  5407. }
  5408. if (this.material !== undefined) {
  5409. if (Array.isArray(this.material)) {
  5410. var uuids = [];
  5411. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  5412. uuids.push(serialize(meta.materials, this.material[_i]));
  5413. }
  5414. object.material = uuids;
  5415. } else {
  5416. object.material = serialize(meta.materials, this.material);
  5417. }
  5418. } //
  5419. if (this.children.length > 0) {
  5420. object.children = [];
  5421. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  5422. object.children.push(this.children[_i2].toJSON(meta).object);
  5423. }
  5424. } //
  5425. if (this.animations.length > 0) {
  5426. object.animations = [];
  5427. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  5428. var animation = this.animations[_i3];
  5429. object.animations.push(serialize(meta.animations, animation));
  5430. }
  5431. }
  5432. if (isRootObject) {
  5433. var geometries = extractFromCache(meta.geometries);
  5434. var materials = extractFromCache(meta.materials);
  5435. var textures = extractFromCache(meta.textures);
  5436. var images = extractFromCache(meta.images);
  5437. var _shapes = extractFromCache(meta.shapes);
  5438. var skeletons = extractFromCache(meta.skeletons);
  5439. var animations = extractFromCache(meta.animations);
  5440. if (geometries.length > 0) output.geometries = geometries;
  5441. if (materials.length > 0) output.materials = materials;
  5442. if (textures.length > 0) output.textures = textures;
  5443. if (images.length > 0) output.images = images;
  5444. if (_shapes.length > 0) output.shapes = _shapes;
  5445. if (skeletons.length > 0) output.skeletons = skeletons;
  5446. if (animations.length > 0) output.animations = animations;
  5447. }
  5448. output.object = object;
  5449. return output; // extract data from the cache hash
  5450. // remove metadata on each item
  5451. // and return as array
  5452. function extractFromCache(cache) {
  5453. var values = [];
  5454. for (var key in cache) {
  5455. var data = cache[key];
  5456. delete data.metadata;
  5457. values.push(data);
  5458. }
  5459. return values;
  5460. }
  5461. },
  5462. clone: function clone(recursive) {
  5463. return new this.constructor().copy(this, recursive);
  5464. },
  5465. copy: function copy(source, recursive) {
  5466. if (recursive === void 0) {
  5467. recursive = true;
  5468. }
  5469. this.name = source.name;
  5470. this.up.copy(source.up);
  5471. this.position.copy(source.position);
  5472. this.rotation.order = source.rotation.order;
  5473. this.quaternion.copy(source.quaternion);
  5474. this.scale.copy(source.scale);
  5475. this.matrix.copy(source.matrix);
  5476. this.matrixWorld.copy(source.matrixWorld);
  5477. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5478. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5479. this.layers.mask = source.layers.mask;
  5480. this.visible = source.visible;
  5481. this.castShadow = source.castShadow;
  5482. this.receiveShadow = source.receiveShadow;
  5483. this.frustumCulled = source.frustumCulled;
  5484. this.renderOrder = source.renderOrder;
  5485. this.userData = JSON.parse(JSON.stringify(source.userData));
  5486. if (recursive === true) {
  5487. for (var i = 0; i < source.children.length; i++) {
  5488. var child = source.children[i];
  5489. this.add(child.clone());
  5490. }
  5491. }
  5492. return this;
  5493. }
  5494. });
  5495. var _vector1 = /*@__PURE__*/new Vector3();
  5496. var _vector2 = /*@__PURE__*/new Vector3();
  5497. var _normalMatrix = /*@__PURE__*/new Matrix3();
  5498. var Plane = /*#__PURE__*/function () {
  5499. function Plane(normal, constant) {
  5500. Object.defineProperty(this, 'isPlane', {
  5501. value: true
  5502. }); // normal is assumed to be normalized
  5503. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  5504. this.constant = constant !== undefined ? constant : 0;
  5505. }
  5506. var _proto = Plane.prototype;
  5507. _proto.set = function set(normal, constant) {
  5508. this.normal.copy(normal);
  5509. this.constant = constant;
  5510. return this;
  5511. };
  5512. _proto.setComponents = function setComponents(x, y, z, w) {
  5513. this.normal.set(x, y, z);
  5514. this.constant = w;
  5515. return this;
  5516. };
  5517. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  5518. this.normal.copy(normal);
  5519. this.constant = -point.dot(this.normal);
  5520. return this;
  5521. };
  5522. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  5523. 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)?
  5524. this.setFromNormalAndCoplanarPoint(normal, a);
  5525. return this;
  5526. };
  5527. _proto.clone = function clone() {
  5528. return new this.constructor().copy(this);
  5529. };
  5530. _proto.copy = function copy(plane) {
  5531. this.normal.copy(plane.normal);
  5532. this.constant = plane.constant;
  5533. return this;
  5534. };
  5535. _proto.normalize = function normalize() {
  5536. // Note: will lead to a divide by zero if the plane is invalid.
  5537. var inverseNormalLength = 1.0 / this.normal.length();
  5538. this.normal.multiplyScalar(inverseNormalLength);
  5539. this.constant *= inverseNormalLength;
  5540. return this;
  5541. };
  5542. _proto.negate = function negate() {
  5543. this.constant *= -1;
  5544. this.normal.negate();
  5545. return this;
  5546. };
  5547. _proto.distanceToPoint = function distanceToPoint(point) {
  5548. return this.normal.dot(point) + this.constant;
  5549. };
  5550. _proto.distanceToSphere = function distanceToSphere(sphere) {
  5551. return this.distanceToPoint(sphere.center) - sphere.radius;
  5552. };
  5553. _proto.projectPoint = function projectPoint(point, target) {
  5554. if (target === undefined) {
  5555. console.warn('THREE.Plane: .projectPoint() target is now required');
  5556. target = new Vector3();
  5557. }
  5558. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  5559. };
  5560. _proto.intersectLine = function intersectLine(line, target) {
  5561. if (target === undefined) {
  5562. console.warn('THREE.Plane: .intersectLine() target is now required');
  5563. target = new Vector3();
  5564. }
  5565. var direction = line.delta(_vector1);
  5566. var denominator = this.normal.dot(direction);
  5567. if (denominator === 0) {
  5568. // line is coplanar, return origin
  5569. if (this.distanceToPoint(line.start) === 0) {
  5570. return target.copy(line.start);
  5571. } // Unsure if this is the correct method to handle this case.
  5572. return undefined;
  5573. }
  5574. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  5575. if (t < 0 || t > 1) {
  5576. return undefined;
  5577. }
  5578. return target.copy(direction).multiplyScalar(t).add(line.start);
  5579. };
  5580. _proto.intersectsLine = function intersectsLine(line) {
  5581. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5582. var startSign = this.distanceToPoint(line.start);
  5583. var endSign = this.distanceToPoint(line.end);
  5584. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  5585. };
  5586. _proto.intersectsBox = function intersectsBox(box) {
  5587. return box.intersectsPlane(this);
  5588. };
  5589. _proto.intersectsSphere = function intersectsSphere(sphere) {
  5590. return sphere.intersectsPlane(this);
  5591. };
  5592. _proto.coplanarPoint = function coplanarPoint(target) {
  5593. if (target === undefined) {
  5594. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  5595. target = new Vector3();
  5596. }
  5597. return target.copy(this.normal).multiplyScalar(-this.constant);
  5598. };
  5599. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  5600. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  5601. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  5602. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  5603. this.constant = -referencePoint.dot(normal);
  5604. return this;
  5605. };
  5606. _proto.translate = function translate(offset) {
  5607. this.constant -= offset.dot(this.normal);
  5608. return this;
  5609. };
  5610. _proto.equals = function equals(plane) {
  5611. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  5612. };
  5613. return Plane;
  5614. }();
  5615. var _v0$1 = /*@__PURE__*/new Vector3();
  5616. var _v1$3 = /*@__PURE__*/new Vector3();
  5617. var _v2$1 = /*@__PURE__*/new Vector3();
  5618. var _v3 = /*@__PURE__*/new Vector3();
  5619. var _vab = /*@__PURE__*/new Vector3();
  5620. var _vac = /*@__PURE__*/new Vector3();
  5621. var _vbc = /*@__PURE__*/new Vector3();
  5622. var _vap = /*@__PURE__*/new Vector3();
  5623. var _vbp = /*@__PURE__*/new Vector3();
  5624. var _vcp = /*@__PURE__*/new Vector3();
  5625. var Triangle = /*#__PURE__*/function () {
  5626. function Triangle(a, b, c) {
  5627. this.a = a !== undefined ? a : new Vector3();
  5628. this.b = b !== undefined ? b : new Vector3();
  5629. this.c = c !== undefined ? c : new Vector3();
  5630. }
  5631. Triangle.getNormal = function getNormal(a, b, c, target) {
  5632. if (target === undefined) {
  5633. console.warn('THREE.Triangle: .getNormal() target is now required');
  5634. target = new Vector3();
  5635. }
  5636. target.subVectors(c, b);
  5637. _v0$1.subVectors(a, b);
  5638. target.cross(_v0$1);
  5639. var targetLengthSq = target.lengthSq();
  5640. if (targetLengthSq > 0) {
  5641. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  5642. }
  5643. return target.set(0, 0, 0);
  5644. } // static/instance method to calculate barycentric coordinates
  5645. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  5646. ;
  5647. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  5648. _v0$1.subVectors(c, a);
  5649. _v1$3.subVectors(b, a);
  5650. _v2$1.subVectors(point, a);
  5651. var dot00 = _v0$1.dot(_v0$1);
  5652. var dot01 = _v0$1.dot(_v1$3);
  5653. var dot02 = _v0$1.dot(_v2$1);
  5654. var dot11 = _v1$3.dot(_v1$3);
  5655. var dot12 = _v1$3.dot(_v2$1);
  5656. var denom = dot00 * dot11 - dot01 * dot01;
  5657. if (target === undefined) {
  5658. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  5659. target = new Vector3();
  5660. } // collinear or singular triangle
  5661. if (denom === 0) {
  5662. // arbitrary location outside of triangle?
  5663. // not sure if this is the best idea, maybe should be returning undefined
  5664. return target.set(-2, -1, -1);
  5665. }
  5666. var invDenom = 1 / denom;
  5667. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  5668. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  5669. return target.set(1 - u - v, v, u);
  5670. };
  5671. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  5672. this.getBarycoord(point, a, b, c, _v3);
  5673. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  5674. };
  5675. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  5676. this.getBarycoord(point, p1, p2, p3, _v3);
  5677. target.set(0, 0);
  5678. target.addScaledVector(uv1, _v3.x);
  5679. target.addScaledVector(uv2, _v3.y);
  5680. target.addScaledVector(uv3, _v3.z);
  5681. return target;
  5682. };
  5683. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  5684. _v0$1.subVectors(c, b);
  5685. _v1$3.subVectors(a, b); // strictly front facing
  5686. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  5687. };
  5688. var _proto = Triangle.prototype;
  5689. _proto.set = function set(a, b, c) {
  5690. this.a.copy(a);
  5691. this.b.copy(b);
  5692. this.c.copy(c);
  5693. return this;
  5694. };
  5695. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  5696. this.a.copy(points[i0]);
  5697. this.b.copy(points[i1]);
  5698. this.c.copy(points[i2]);
  5699. return this;
  5700. };
  5701. _proto.clone = function clone() {
  5702. return new this.constructor().copy(this);
  5703. };
  5704. _proto.copy = function copy(triangle) {
  5705. this.a.copy(triangle.a);
  5706. this.b.copy(triangle.b);
  5707. this.c.copy(triangle.c);
  5708. return this;
  5709. };
  5710. _proto.getArea = function getArea() {
  5711. _v0$1.subVectors(this.c, this.b);
  5712. _v1$3.subVectors(this.a, this.b);
  5713. return _v0$1.cross(_v1$3).length() * 0.5;
  5714. };
  5715. _proto.getMidpoint = function getMidpoint(target) {
  5716. if (target === undefined) {
  5717. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  5718. target = new Vector3();
  5719. }
  5720. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5721. };
  5722. _proto.getNormal = function getNormal(target) {
  5723. return Triangle.getNormal(this.a, this.b, this.c, target);
  5724. };
  5725. _proto.getPlane = function getPlane(target) {
  5726. if (target === undefined) {
  5727. console.warn('THREE.Triangle: .getPlane() target is now required');
  5728. target = new Plane();
  5729. }
  5730. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5731. };
  5732. _proto.getBarycoord = function getBarycoord(point, target) {
  5733. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5734. };
  5735. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5736. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5737. };
  5738. _proto.containsPoint = function containsPoint(point) {
  5739. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5740. };
  5741. _proto.isFrontFacing = function isFrontFacing(direction) {
  5742. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5743. };
  5744. _proto.intersectsBox = function intersectsBox(box) {
  5745. return box.intersectsTriangle(this);
  5746. };
  5747. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5748. if (target === undefined) {
  5749. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5750. target = new Vector3();
  5751. }
  5752. var a = this.a,
  5753. b = this.b,
  5754. c = this.c;
  5755. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5756. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5757. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5758. // basically, we're distinguishing which of the voronoi regions of the triangle
  5759. // the point lies in with the minimum amount of redundant computation.
  5760. _vab.subVectors(b, a);
  5761. _vac.subVectors(c, a);
  5762. _vap.subVectors(p, a);
  5763. var d1 = _vab.dot(_vap);
  5764. var d2 = _vac.dot(_vap);
  5765. if (d1 <= 0 && d2 <= 0) {
  5766. // vertex region of A; barycentric coords (1, 0, 0)
  5767. return target.copy(a);
  5768. }
  5769. _vbp.subVectors(p, b);
  5770. var d3 = _vab.dot(_vbp);
  5771. var d4 = _vac.dot(_vbp);
  5772. if (d3 >= 0 && d4 <= d3) {
  5773. // vertex region of B; barycentric coords (0, 1, 0)
  5774. return target.copy(b);
  5775. }
  5776. var vc = d1 * d4 - d3 * d2;
  5777. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5778. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5779. return target.copy(a).addScaledVector(_vab, v);
  5780. }
  5781. _vcp.subVectors(p, c);
  5782. var d5 = _vab.dot(_vcp);
  5783. var d6 = _vac.dot(_vcp);
  5784. if (d6 >= 0 && d5 <= d6) {
  5785. // vertex region of C; barycentric coords (0, 0, 1)
  5786. return target.copy(c);
  5787. }
  5788. var vb = d5 * d2 - d1 * d6;
  5789. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5790. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5791. return target.copy(a).addScaledVector(_vac, w);
  5792. }
  5793. var va = d3 * d6 - d5 * d4;
  5794. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5795. _vbc.subVectors(c, b);
  5796. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5797. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5798. } // face region
  5799. var denom = 1 / (va + vb + vc); // u = va * denom
  5800. v = vb * denom;
  5801. w = vc * denom;
  5802. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5803. };
  5804. _proto.equals = function equals(triangle) {
  5805. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5806. };
  5807. return Triangle;
  5808. }();
  5809. var materialId = 0;
  5810. function Material() {
  5811. Object.defineProperty(this, 'id', {
  5812. value: materialId++
  5813. });
  5814. this.uuid = MathUtils.generateUUID();
  5815. this.name = '';
  5816. this.type = 'Material';
  5817. this.fog = true;
  5818. this.blending = NormalBlending;
  5819. this.side = FrontSide;
  5820. this.vertexColors = false;
  5821. this.opacity = 1;
  5822. this.transparent = false;
  5823. this.blendSrc = SrcAlphaFactor;
  5824. this.blendDst = OneMinusSrcAlphaFactor;
  5825. this.blendEquation = AddEquation;
  5826. this.blendSrcAlpha = null;
  5827. this.blendDstAlpha = null;
  5828. this.blendEquationAlpha = null;
  5829. this.depthFunc = LessEqualDepth;
  5830. this.depthTest = true;
  5831. this.depthWrite = true;
  5832. this.stencilWriteMask = 0xff;
  5833. this.stencilFunc = AlwaysStencilFunc;
  5834. this.stencilRef = 0;
  5835. this.stencilFuncMask = 0xff;
  5836. this.stencilFail = KeepStencilOp;
  5837. this.stencilZFail = KeepStencilOp;
  5838. this.stencilZPass = KeepStencilOp;
  5839. this.stencilWrite = false;
  5840. this.clippingPlanes = null;
  5841. this.clipIntersection = false;
  5842. this.clipShadows = false;
  5843. this.shadowSide = null;
  5844. this.colorWrite = true;
  5845. this.precision = null; // override the renderer's default precision for this material
  5846. this.polygonOffset = false;
  5847. this.polygonOffsetFactor = 0;
  5848. this.polygonOffsetUnits = 0;
  5849. this.dithering = false;
  5850. this.alphaTest = 0;
  5851. this.premultipliedAlpha = false;
  5852. this.visible = true;
  5853. this.toneMapped = true;
  5854. this.userData = {};
  5855. this.version = 0;
  5856. }
  5857. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5858. constructor: Material,
  5859. isMaterial: true,
  5860. onBeforeCompile: function onBeforeCompile()
  5861. /* shaderobject, renderer */
  5862. {},
  5863. customProgramCacheKey: function customProgramCacheKey() {
  5864. return this.onBeforeCompile.toString();
  5865. },
  5866. setValues: function setValues(values) {
  5867. if (values === undefined) return;
  5868. for (var key in values) {
  5869. var newValue = values[key];
  5870. if (newValue === undefined) {
  5871. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  5872. continue;
  5873. } // for backward compatability if shading is set in the constructor
  5874. if (key === 'shading') {
  5875. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  5876. this.flatShading = newValue === FlatShading ? true : false;
  5877. continue;
  5878. }
  5879. var currentValue = this[key];
  5880. if (currentValue === undefined) {
  5881. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  5882. continue;
  5883. }
  5884. if (currentValue && currentValue.isColor) {
  5885. currentValue.set(newValue);
  5886. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  5887. currentValue.copy(newValue);
  5888. } else {
  5889. this[key] = newValue;
  5890. }
  5891. }
  5892. },
  5893. toJSON: function toJSON(meta) {
  5894. var isRoot = meta === undefined || typeof meta === 'string';
  5895. if (isRoot) {
  5896. meta = {
  5897. textures: {},
  5898. images: {}
  5899. };
  5900. }
  5901. var data = {
  5902. metadata: {
  5903. version: 4.5,
  5904. type: 'Material',
  5905. generator: 'Material.toJSON'
  5906. }
  5907. }; // standard Material serialization
  5908. data.uuid = this.uuid;
  5909. data.type = this.type;
  5910. if (this.name !== '') data.name = this.name;
  5911. if (this.color && this.color.isColor) data.color = this.color.getHex();
  5912. if (this.roughness !== undefined) data.roughness = this.roughness;
  5913. if (this.metalness !== undefined) data.metalness = this.metalness;
  5914. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  5915. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  5916. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  5917. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  5918. if (this.shininess !== undefined) data.shininess = this.shininess;
  5919. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  5920. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  5921. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  5922. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  5923. }
  5924. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  5925. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  5926. }
  5927. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  5928. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  5929. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5930. }
  5931. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  5932. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  5933. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  5934. if (this.lightMap && this.lightMap.isTexture) {
  5935. data.lightMap = this.lightMap.toJSON(meta).uuid;
  5936. data.lightMapIntensity = this.lightMapIntensity;
  5937. }
  5938. if (this.aoMap && this.aoMap.isTexture) {
  5939. data.aoMap = this.aoMap.toJSON(meta).uuid;
  5940. data.aoMapIntensity = this.aoMapIntensity;
  5941. }
  5942. if (this.bumpMap && this.bumpMap.isTexture) {
  5943. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  5944. data.bumpScale = this.bumpScale;
  5945. }
  5946. if (this.normalMap && this.normalMap.isTexture) {
  5947. data.normalMap = this.normalMap.toJSON(meta).uuid;
  5948. data.normalMapType = this.normalMapType;
  5949. data.normalScale = this.normalScale.toArray();
  5950. }
  5951. if (this.displacementMap && this.displacementMap.isTexture) {
  5952. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  5953. data.displacementScale = this.displacementScale;
  5954. data.displacementBias = this.displacementBias;
  5955. }
  5956. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  5957. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  5958. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  5959. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  5960. if (this.envMap && this.envMap.isTexture) {
  5961. data.envMap = this.envMap.toJSON(meta).uuid;
  5962. data.reflectivity = this.reflectivity; // Scale behind envMap
  5963. data.refractionRatio = this.refractionRatio;
  5964. if (this.combine !== undefined) data.combine = this.combine;
  5965. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  5966. }
  5967. if (this.gradientMap && this.gradientMap.isTexture) {
  5968. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  5969. }
  5970. if (this.size !== undefined) data.size = this.size;
  5971. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  5972. if (this.blending !== NormalBlending) data.blending = this.blending;
  5973. if (this.side !== FrontSide) data.side = this.side;
  5974. if (this.vertexColors) data.vertexColors = true;
  5975. if (this.opacity < 1) data.opacity = this.opacity;
  5976. if (this.transparent === true) data.transparent = this.transparent;
  5977. data.depthFunc = this.depthFunc;
  5978. data.depthTest = this.depthTest;
  5979. data.depthWrite = this.depthWrite;
  5980. data.stencilWrite = this.stencilWrite;
  5981. data.stencilWriteMask = this.stencilWriteMask;
  5982. data.stencilFunc = this.stencilFunc;
  5983. data.stencilRef = this.stencilRef;
  5984. data.stencilFuncMask = this.stencilFuncMask;
  5985. data.stencilFail = this.stencilFail;
  5986. data.stencilZFail = this.stencilZFail;
  5987. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  5988. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  5989. if (this.polygonOffset === true) data.polygonOffset = true;
  5990. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5991. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5992. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  5993. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  5994. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  5995. if (this.scale !== undefined) data.scale = this.scale;
  5996. if (this.dithering === true) data.dithering = true;
  5997. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  5998. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  5999. if (this.wireframe === true) data.wireframe = this.wireframe;
  6000. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  6001. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  6002. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  6003. if (this.morphTargets === true) data.morphTargets = true;
  6004. if (this.morphNormals === true) data.morphNormals = true;
  6005. if (this.skinning === true) data.skinning = true;
  6006. if (this.flatShading === true) data.flatShading = this.flatShading;
  6007. if (this.visible === false) data.visible = false;
  6008. if (this.toneMapped === false) data.toneMapped = false;
  6009. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  6010. function extractFromCache(cache) {
  6011. var values = [];
  6012. for (var key in cache) {
  6013. var _data = cache[key];
  6014. delete _data.metadata;
  6015. values.push(_data);
  6016. }
  6017. return values;
  6018. }
  6019. if (isRoot) {
  6020. var textures = extractFromCache(meta.textures);
  6021. var images = extractFromCache(meta.images);
  6022. if (textures.length > 0) data.textures = textures;
  6023. if (images.length > 0) data.images = images;
  6024. }
  6025. return data;
  6026. },
  6027. clone: function clone() {
  6028. return new this.constructor().copy(this);
  6029. },
  6030. copy: function copy(source) {
  6031. this.name = source.name;
  6032. this.fog = source.fog;
  6033. this.blending = source.blending;
  6034. this.side = source.side;
  6035. this.vertexColors = source.vertexColors;
  6036. this.opacity = source.opacity;
  6037. this.transparent = source.transparent;
  6038. this.blendSrc = source.blendSrc;
  6039. this.blendDst = source.blendDst;
  6040. this.blendEquation = source.blendEquation;
  6041. this.blendSrcAlpha = source.blendSrcAlpha;
  6042. this.blendDstAlpha = source.blendDstAlpha;
  6043. this.blendEquationAlpha = source.blendEquationAlpha;
  6044. this.depthFunc = source.depthFunc;
  6045. this.depthTest = source.depthTest;
  6046. this.depthWrite = source.depthWrite;
  6047. this.stencilWriteMask = source.stencilWriteMask;
  6048. this.stencilFunc = source.stencilFunc;
  6049. this.stencilRef = source.stencilRef;
  6050. this.stencilFuncMask = source.stencilFuncMask;
  6051. this.stencilFail = source.stencilFail;
  6052. this.stencilZFail = source.stencilZFail;
  6053. this.stencilZPass = source.stencilZPass;
  6054. this.stencilWrite = source.stencilWrite;
  6055. var srcPlanes = source.clippingPlanes;
  6056. var dstPlanes = null;
  6057. if (srcPlanes !== null) {
  6058. var n = srcPlanes.length;
  6059. dstPlanes = new Array(n);
  6060. for (var i = 0; i !== n; ++i) {
  6061. dstPlanes[i] = srcPlanes[i].clone();
  6062. }
  6063. }
  6064. this.clippingPlanes = dstPlanes;
  6065. this.clipIntersection = source.clipIntersection;
  6066. this.clipShadows = source.clipShadows;
  6067. this.shadowSide = source.shadowSide;
  6068. this.colorWrite = source.colorWrite;
  6069. this.precision = source.precision;
  6070. this.polygonOffset = source.polygonOffset;
  6071. this.polygonOffsetFactor = source.polygonOffsetFactor;
  6072. this.polygonOffsetUnits = source.polygonOffsetUnits;
  6073. this.dithering = source.dithering;
  6074. this.alphaTest = source.alphaTest;
  6075. this.premultipliedAlpha = source.premultipliedAlpha;
  6076. this.visible = source.visible;
  6077. this.toneMapped = source.toneMapped;
  6078. this.userData = JSON.parse(JSON.stringify(source.userData));
  6079. return this;
  6080. },
  6081. dispose: function dispose() {
  6082. this.dispatchEvent({
  6083. type: 'dispose'
  6084. });
  6085. }
  6086. });
  6087. Object.defineProperty(Material.prototype, 'needsUpdate', {
  6088. set: function set(value) {
  6089. if (value === true) this.version++;
  6090. }
  6091. });
  6092. var _colorKeywords = {
  6093. 'aliceblue': 0xF0F8FF,
  6094. 'antiquewhite': 0xFAEBD7,
  6095. 'aqua': 0x00FFFF,
  6096. 'aquamarine': 0x7FFFD4,
  6097. 'azure': 0xF0FFFF,
  6098. 'beige': 0xF5F5DC,
  6099. 'bisque': 0xFFE4C4,
  6100. 'black': 0x000000,
  6101. 'blanchedalmond': 0xFFEBCD,
  6102. 'blue': 0x0000FF,
  6103. 'blueviolet': 0x8A2BE2,
  6104. 'brown': 0xA52A2A,
  6105. 'burlywood': 0xDEB887,
  6106. 'cadetblue': 0x5F9EA0,
  6107. 'chartreuse': 0x7FFF00,
  6108. 'chocolate': 0xD2691E,
  6109. 'coral': 0xFF7F50,
  6110. 'cornflowerblue': 0x6495ED,
  6111. 'cornsilk': 0xFFF8DC,
  6112. 'crimson': 0xDC143C,
  6113. 'cyan': 0x00FFFF,
  6114. 'darkblue': 0x00008B,
  6115. 'darkcyan': 0x008B8B,
  6116. 'darkgoldenrod': 0xB8860B,
  6117. 'darkgray': 0xA9A9A9,
  6118. 'darkgreen': 0x006400,
  6119. 'darkgrey': 0xA9A9A9,
  6120. 'darkkhaki': 0xBDB76B,
  6121. 'darkmagenta': 0x8B008B,
  6122. 'darkolivegreen': 0x556B2F,
  6123. 'darkorange': 0xFF8C00,
  6124. 'darkorchid': 0x9932CC,
  6125. 'darkred': 0x8B0000,
  6126. 'darksalmon': 0xE9967A,
  6127. 'darkseagreen': 0x8FBC8F,
  6128. 'darkslateblue': 0x483D8B,
  6129. 'darkslategray': 0x2F4F4F,
  6130. 'darkslategrey': 0x2F4F4F,
  6131. 'darkturquoise': 0x00CED1,
  6132. 'darkviolet': 0x9400D3,
  6133. 'deeppink': 0xFF1493,
  6134. 'deepskyblue': 0x00BFFF,
  6135. 'dimgray': 0x696969,
  6136. 'dimgrey': 0x696969,
  6137. 'dodgerblue': 0x1E90FF,
  6138. 'firebrick': 0xB22222,
  6139. 'floralwhite': 0xFFFAF0,
  6140. 'forestgreen': 0x228B22,
  6141. 'fuchsia': 0xFF00FF,
  6142. 'gainsboro': 0xDCDCDC,
  6143. 'ghostwhite': 0xF8F8FF,
  6144. 'gold': 0xFFD700,
  6145. 'goldenrod': 0xDAA520,
  6146. 'gray': 0x808080,
  6147. 'green': 0x008000,
  6148. 'greenyellow': 0xADFF2F,
  6149. 'grey': 0x808080,
  6150. 'honeydew': 0xF0FFF0,
  6151. 'hotpink': 0xFF69B4,
  6152. 'indianred': 0xCD5C5C,
  6153. 'indigo': 0x4B0082,
  6154. 'ivory': 0xFFFFF0,
  6155. 'khaki': 0xF0E68C,
  6156. 'lavender': 0xE6E6FA,
  6157. 'lavenderblush': 0xFFF0F5,
  6158. 'lawngreen': 0x7CFC00,
  6159. 'lemonchiffon': 0xFFFACD,
  6160. 'lightblue': 0xADD8E6,
  6161. 'lightcoral': 0xF08080,
  6162. 'lightcyan': 0xE0FFFF,
  6163. 'lightgoldenrodyellow': 0xFAFAD2,
  6164. 'lightgray': 0xD3D3D3,
  6165. 'lightgreen': 0x90EE90,
  6166. 'lightgrey': 0xD3D3D3,
  6167. 'lightpink': 0xFFB6C1,
  6168. 'lightsalmon': 0xFFA07A,
  6169. 'lightseagreen': 0x20B2AA,
  6170. 'lightskyblue': 0x87CEFA,
  6171. 'lightslategray': 0x778899,
  6172. 'lightslategrey': 0x778899,
  6173. 'lightsteelblue': 0xB0C4DE,
  6174. 'lightyellow': 0xFFFFE0,
  6175. 'lime': 0x00FF00,
  6176. 'limegreen': 0x32CD32,
  6177. 'linen': 0xFAF0E6,
  6178. 'magenta': 0xFF00FF,
  6179. 'maroon': 0x800000,
  6180. 'mediumaquamarine': 0x66CDAA,
  6181. 'mediumblue': 0x0000CD,
  6182. 'mediumorchid': 0xBA55D3,
  6183. 'mediumpurple': 0x9370DB,
  6184. 'mediumseagreen': 0x3CB371,
  6185. 'mediumslateblue': 0x7B68EE,
  6186. 'mediumspringgreen': 0x00FA9A,
  6187. 'mediumturquoise': 0x48D1CC,
  6188. 'mediumvioletred': 0xC71585,
  6189. 'midnightblue': 0x191970,
  6190. 'mintcream': 0xF5FFFA,
  6191. 'mistyrose': 0xFFE4E1,
  6192. 'moccasin': 0xFFE4B5,
  6193. 'navajowhite': 0xFFDEAD,
  6194. 'navy': 0x000080,
  6195. 'oldlace': 0xFDF5E6,
  6196. 'olive': 0x808000,
  6197. 'olivedrab': 0x6B8E23,
  6198. 'orange': 0xFFA500,
  6199. 'orangered': 0xFF4500,
  6200. 'orchid': 0xDA70D6,
  6201. 'palegoldenrod': 0xEEE8AA,
  6202. 'palegreen': 0x98FB98,
  6203. 'paleturquoise': 0xAFEEEE,
  6204. 'palevioletred': 0xDB7093,
  6205. 'papayawhip': 0xFFEFD5,
  6206. 'peachpuff': 0xFFDAB9,
  6207. 'peru': 0xCD853F,
  6208. 'pink': 0xFFC0CB,
  6209. 'plum': 0xDDA0DD,
  6210. 'powderblue': 0xB0E0E6,
  6211. 'purple': 0x800080,
  6212. 'rebeccapurple': 0x663399,
  6213. 'red': 0xFF0000,
  6214. 'rosybrown': 0xBC8F8F,
  6215. 'royalblue': 0x4169E1,
  6216. 'saddlebrown': 0x8B4513,
  6217. 'salmon': 0xFA8072,
  6218. 'sandybrown': 0xF4A460,
  6219. 'seagreen': 0x2E8B57,
  6220. 'seashell': 0xFFF5EE,
  6221. 'sienna': 0xA0522D,
  6222. 'silver': 0xC0C0C0,
  6223. 'skyblue': 0x87CEEB,
  6224. 'slateblue': 0x6A5ACD,
  6225. 'slategray': 0x708090,
  6226. 'slategrey': 0x708090,
  6227. 'snow': 0xFFFAFA,
  6228. 'springgreen': 0x00FF7F,
  6229. 'steelblue': 0x4682B4,
  6230. 'tan': 0xD2B48C,
  6231. 'teal': 0x008080,
  6232. 'thistle': 0xD8BFD8,
  6233. 'tomato': 0xFF6347,
  6234. 'turquoise': 0x40E0D0,
  6235. 'violet': 0xEE82EE,
  6236. 'wheat': 0xF5DEB3,
  6237. 'white': 0xFFFFFF,
  6238. 'whitesmoke': 0xF5F5F5,
  6239. 'yellow': 0xFFFF00,
  6240. 'yellowgreen': 0x9ACD32
  6241. };
  6242. var _hslA = {
  6243. h: 0,
  6244. s: 0,
  6245. l: 0
  6246. };
  6247. var _hslB = {
  6248. h: 0,
  6249. s: 0,
  6250. l: 0
  6251. };
  6252. function hue2rgb(p, q, t) {
  6253. if (t < 0) t += 1;
  6254. if (t > 1) t -= 1;
  6255. if (t < 1 / 6) return p + (q - p) * 6 * t;
  6256. if (t < 1 / 2) return q;
  6257. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  6258. return p;
  6259. }
  6260. function SRGBToLinear(c) {
  6261. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  6262. }
  6263. function LinearToSRGB(c) {
  6264. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  6265. }
  6266. var Color = /*#__PURE__*/function () {
  6267. function Color(r, g, b) {
  6268. Object.defineProperty(this, 'isColor', {
  6269. value: true
  6270. });
  6271. if (g === undefined && b === undefined) {
  6272. // r is THREE.Color, hex or string
  6273. return this.set(r);
  6274. }
  6275. return this.setRGB(r, g, b);
  6276. }
  6277. var _proto = Color.prototype;
  6278. _proto.set = function set(value) {
  6279. if (value && value.isColor) {
  6280. this.copy(value);
  6281. } else if (typeof value === 'number') {
  6282. this.setHex(value);
  6283. } else if (typeof value === 'string') {
  6284. this.setStyle(value);
  6285. }
  6286. return this;
  6287. };
  6288. _proto.setScalar = function setScalar(scalar) {
  6289. this.r = scalar;
  6290. this.g = scalar;
  6291. this.b = scalar;
  6292. return this;
  6293. };
  6294. _proto.setHex = function setHex(hex) {
  6295. hex = Math.floor(hex);
  6296. this.r = (hex >> 16 & 255) / 255;
  6297. this.g = (hex >> 8 & 255) / 255;
  6298. this.b = (hex & 255) / 255;
  6299. return this;
  6300. };
  6301. _proto.setRGB = function setRGB(r, g, b) {
  6302. this.r = r;
  6303. this.g = g;
  6304. this.b = b;
  6305. return this;
  6306. };
  6307. _proto.setHSL = function setHSL(h, s, l) {
  6308. // h,s,l ranges are in 0.0 - 1.0
  6309. h = MathUtils.euclideanModulo(h, 1);
  6310. s = MathUtils.clamp(s, 0, 1);
  6311. l = MathUtils.clamp(l, 0, 1);
  6312. if (s === 0) {
  6313. this.r = this.g = this.b = l;
  6314. } else {
  6315. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  6316. var q = 2 * l - p;
  6317. this.r = hue2rgb(q, p, h + 1 / 3);
  6318. this.g = hue2rgb(q, p, h);
  6319. this.b = hue2rgb(q, p, h - 1 / 3);
  6320. }
  6321. return this;
  6322. };
  6323. _proto.setStyle = function setStyle(style) {
  6324. function handleAlpha(string) {
  6325. if (string === undefined) return;
  6326. if (parseFloat(string) < 1) {
  6327. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  6328. }
  6329. }
  6330. var m;
  6331. if (m = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(style)) {
  6332. // rgb / hsl
  6333. var color;
  6334. var name = m[1];
  6335. var components = m[2];
  6336. switch (name) {
  6337. case 'rgb':
  6338. case 'rgba':
  6339. if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6340. // rgb(255,0,0) rgba(255,0,0,0.5)
  6341. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  6342. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  6343. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  6344. handleAlpha(color[4]);
  6345. return this;
  6346. }
  6347. if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6348. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6349. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  6350. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  6351. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  6352. handleAlpha(color[4]);
  6353. return this;
  6354. }
  6355. break;
  6356. case 'hsl':
  6357. case 'hsla':
  6358. if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6359. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6360. var h = parseFloat(color[1]) / 360;
  6361. var s = parseInt(color[2], 10) / 100;
  6362. var l = parseInt(color[3], 10) / 100;
  6363. handleAlpha(color[4]);
  6364. return this.setHSL(h, s, l);
  6365. }
  6366. break;
  6367. }
  6368. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  6369. // hex color
  6370. var hex = m[1];
  6371. var size = hex.length;
  6372. if (size === 3) {
  6373. // #ff0
  6374. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  6375. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  6376. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  6377. return this;
  6378. } else if (size === 6) {
  6379. // #ff0000
  6380. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  6381. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  6382. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  6383. return this;
  6384. }
  6385. }
  6386. if (style && style.length > 0) {
  6387. return this.setColorName(style);
  6388. }
  6389. return this;
  6390. };
  6391. _proto.setColorName = function setColorName(style) {
  6392. // color keywords
  6393. var hex = _colorKeywords[style];
  6394. if (hex !== undefined) {
  6395. // red
  6396. this.setHex(hex);
  6397. } else {
  6398. // unknown color
  6399. console.warn('THREE.Color: Unknown color ' + style);
  6400. }
  6401. return this;
  6402. };
  6403. _proto.clone = function clone() {
  6404. return new this.constructor(this.r, this.g, this.b);
  6405. };
  6406. _proto.copy = function copy(color) {
  6407. this.r = color.r;
  6408. this.g = color.g;
  6409. this.b = color.b;
  6410. return this;
  6411. };
  6412. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  6413. if (gammaFactor === void 0) {
  6414. gammaFactor = 2.0;
  6415. }
  6416. this.r = Math.pow(color.r, gammaFactor);
  6417. this.g = Math.pow(color.g, gammaFactor);
  6418. this.b = Math.pow(color.b, gammaFactor);
  6419. return this;
  6420. };
  6421. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  6422. if (gammaFactor === void 0) {
  6423. gammaFactor = 2.0;
  6424. }
  6425. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  6426. this.r = Math.pow(color.r, safeInverse);
  6427. this.g = Math.pow(color.g, safeInverse);
  6428. this.b = Math.pow(color.b, safeInverse);
  6429. return this;
  6430. };
  6431. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  6432. this.copyGammaToLinear(this, gammaFactor);
  6433. return this;
  6434. };
  6435. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  6436. this.copyLinearToGamma(this, gammaFactor);
  6437. return this;
  6438. };
  6439. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  6440. this.r = SRGBToLinear(color.r);
  6441. this.g = SRGBToLinear(color.g);
  6442. this.b = SRGBToLinear(color.b);
  6443. return this;
  6444. };
  6445. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  6446. this.r = LinearToSRGB(color.r);
  6447. this.g = LinearToSRGB(color.g);
  6448. this.b = LinearToSRGB(color.b);
  6449. return this;
  6450. };
  6451. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  6452. this.copySRGBToLinear(this);
  6453. return this;
  6454. };
  6455. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  6456. this.copyLinearToSRGB(this);
  6457. return this;
  6458. };
  6459. _proto.getHex = function getHex() {
  6460. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  6461. };
  6462. _proto.getHexString = function getHexString() {
  6463. return ('000000' + this.getHex().toString(16)).slice(-6);
  6464. };
  6465. _proto.getHSL = function getHSL(target) {
  6466. // h,s,l ranges are in 0.0 - 1.0
  6467. if (target === undefined) {
  6468. console.warn('THREE.Color: .getHSL() target is now required');
  6469. target = {
  6470. h: 0,
  6471. s: 0,
  6472. l: 0
  6473. };
  6474. }
  6475. var r = this.r,
  6476. g = this.g,
  6477. b = this.b;
  6478. var max = Math.max(r, g, b);
  6479. var min = Math.min(r, g, b);
  6480. var hue, saturation;
  6481. var lightness = (min + max) / 2.0;
  6482. if (min === max) {
  6483. hue = 0;
  6484. saturation = 0;
  6485. } else {
  6486. var delta = max - min;
  6487. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  6488. switch (max) {
  6489. case r:
  6490. hue = (g - b) / delta + (g < b ? 6 : 0);
  6491. break;
  6492. case g:
  6493. hue = (b - r) / delta + 2;
  6494. break;
  6495. case b:
  6496. hue = (r - g) / delta + 4;
  6497. break;
  6498. }
  6499. hue /= 6;
  6500. }
  6501. target.h = hue;
  6502. target.s = saturation;
  6503. target.l = lightness;
  6504. return target;
  6505. };
  6506. _proto.getStyle = function getStyle() {
  6507. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  6508. };
  6509. _proto.offsetHSL = function offsetHSL(h, s, l) {
  6510. this.getHSL(_hslA);
  6511. _hslA.h += h;
  6512. _hslA.s += s;
  6513. _hslA.l += l;
  6514. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  6515. return this;
  6516. };
  6517. _proto.add = function add(color) {
  6518. this.r += color.r;
  6519. this.g += color.g;
  6520. this.b += color.b;
  6521. return this;
  6522. };
  6523. _proto.addColors = function addColors(color1, color2) {
  6524. this.r = color1.r + color2.r;
  6525. this.g = color1.g + color2.g;
  6526. this.b = color1.b + color2.b;
  6527. return this;
  6528. };
  6529. _proto.addScalar = function addScalar(s) {
  6530. this.r += s;
  6531. this.g += s;
  6532. this.b += s;
  6533. return this;
  6534. };
  6535. _proto.sub = function sub(color) {
  6536. this.r = Math.max(0, this.r - color.r);
  6537. this.g = Math.max(0, this.g - color.g);
  6538. this.b = Math.max(0, this.b - color.b);
  6539. return this;
  6540. };
  6541. _proto.multiply = function multiply(color) {
  6542. this.r *= color.r;
  6543. this.g *= color.g;
  6544. this.b *= color.b;
  6545. return this;
  6546. };
  6547. _proto.multiplyScalar = function multiplyScalar(s) {
  6548. this.r *= s;
  6549. this.g *= s;
  6550. this.b *= s;
  6551. return this;
  6552. };
  6553. _proto.lerp = function lerp(color, alpha) {
  6554. this.r += (color.r - this.r) * alpha;
  6555. this.g += (color.g - this.g) * alpha;
  6556. this.b += (color.b - this.b) * alpha;
  6557. return this;
  6558. };
  6559. _proto.lerpColors = function lerpColors(color1, color2, alpha) {
  6560. this.r = color1.r + (color2.r - color1.r) * alpha;
  6561. this.g = color1.g + (color2.g - color1.g) * alpha;
  6562. this.b = color1.b + (color2.b - color1.b) * alpha;
  6563. return this;
  6564. };
  6565. _proto.lerpHSL = function lerpHSL(color, alpha) {
  6566. this.getHSL(_hslA);
  6567. color.getHSL(_hslB);
  6568. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  6569. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  6570. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  6571. this.setHSL(h, s, l);
  6572. return this;
  6573. };
  6574. _proto.equals = function equals(c) {
  6575. return c.r === this.r && c.g === this.g && c.b === this.b;
  6576. };
  6577. _proto.fromArray = function fromArray(array, offset) {
  6578. if (offset === void 0) {
  6579. offset = 0;
  6580. }
  6581. this.r = array[offset];
  6582. this.g = array[offset + 1];
  6583. this.b = array[offset + 2];
  6584. return this;
  6585. };
  6586. _proto.toArray = function toArray(array, offset) {
  6587. if (array === void 0) {
  6588. array = [];
  6589. }
  6590. if (offset === void 0) {
  6591. offset = 0;
  6592. }
  6593. array[offset] = this.r;
  6594. array[offset + 1] = this.g;
  6595. array[offset + 2] = this.b;
  6596. return array;
  6597. };
  6598. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  6599. this.r = attribute.getX(index);
  6600. this.g = attribute.getY(index);
  6601. this.b = attribute.getZ(index);
  6602. if (attribute.normalized === true) {
  6603. // assuming Uint8Array
  6604. this.r /= 255;
  6605. this.g /= 255;
  6606. this.b /= 255;
  6607. }
  6608. return this;
  6609. };
  6610. _proto.toJSON = function toJSON() {
  6611. return this.getHex();
  6612. };
  6613. return Color;
  6614. }();
  6615. Color.NAMES = _colorKeywords;
  6616. Color.prototype.r = 1;
  6617. Color.prototype.g = 1;
  6618. Color.prototype.b = 1;
  6619. /**
  6620. * parameters = {
  6621. * color: <hex>,
  6622. * opacity: <float>,
  6623. * map: new THREE.Texture( <Image> ),
  6624. *
  6625. * lightMap: new THREE.Texture( <Image> ),
  6626. * lightMapIntensity: <float>
  6627. *
  6628. * aoMap: new THREE.Texture( <Image> ),
  6629. * aoMapIntensity: <float>
  6630. *
  6631. * specularMap: new THREE.Texture( <Image> ),
  6632. *
  6633. * alphaMap: new THREE.Texture( <Image> ),
  6634. *
  6635. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  6636. * combine: THREE.Multiply,
  6637. * reflectivity: <float>,
  6638. * refractionRatio: <float>,
  6639. *
  6640. * depthTest: <bool>,
  6641. * depthWrite: <bool>,
  6642. *
  6643. * wireframe: <boolean>,
  6644. * wireframeLinewidth: <float>,
  6645. *
  6646. * skinning: <bool>,
  6647. * morphTargets: <bool>
  6648. * }
  6649. */
  6650. function MeshBasicMaterial(parameters) {
  6651. Material.call(this);
  6652. this.type = 'MeshBasicMaterial';
  6653. this.color = new Color(0xffffff); // emissive
  6654. this.map = null;
  6655. this.lightMap = null;
  6656. this.lightMapIntensity = 1.0;
  6657. this.aoMap = null;
  6658. this.aoMapIntensity = 1.0;
  6659. this.specularMap = null;
  6660. this.alphaMap = null;
  6661. this.envMap = null;
  6662. this.combine = MultiplyOperation;
  6663. this.reflectivity = 1;
  6664. this.refractionRatio = 0.98;
  6665. this.wireframe = false;
  6666. this.wireframeLinewidth = 1;
  6667. this.wireframeLinecap = 'round';
  6668. this.wireframeLinejoin = 'round';
  6669. this.skinning = false;
  6670. this.morphTargets = false;
  6671. this.setValues(parameters);
  6672. }
  6673. MeshBasicMaterial.prototype = Object.create(Material.prototype);
  6674. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  6675. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  6676. MeshBasicMaterial.prototype.copy = function (source) {
  6677. Material.prototype.copy.call(this, source);
  6678. this.color.copy(source.color);
  6679. this.map = source.map;
  6680. this.lightMap = source.lightMap;
  6681. this.lightMapIntensity = source.lightMapIntensity;
  6682. this.aoMap = source.aoMap;
  6683. this.aoMapIntensity = source.aoMapIntensity;
  6684. this.specularMap = source.specularMap;
  6685. this.alphaMap = source.alphaMap;
  6686. this.envMap = source.envMap;
  6687. this.combine = source.combine;
  6688. this.reflectivity = source.reflectivity;
  6689. this.refractionRatio = source.refractionRatio;
  6690. this.wireframe = source.wireframe;
  6691. this.wireframeLinewidth = source.wireframeLinewidth;
  6692. this.wireframeLinecap = source.wireframeLinecap;
  6693. this.wireframeLinejoin = source.wireframeLinejoin;
  6694. this.skinning = source.skinning;
  6695. this.morphTargets = source.morphTargets;
  6696. return this;
  6697. };
  6698. var _vector$3 = new Vector3();
  6699. var _vector2$1 = new Vector2();
  6700. function BufferAttribute(array, itemSize, normalized) {
  6701. if (Array.isArray(array)) {
  6702. throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');
  6703. }
  6704. this.name = '';
  6705. this.array = array;
  6706. this.itemSize = itemSize;
  6707. this.count = array !== undefined ? array.length / itemSize : 0;
  6708. this.normalized = normalized === true;
  6709. this.usage = StaticDrawUsage;
  6710. this.updateRange = {
  6711. offset: 0,
  6712. count: -1
  6713. };
  6714. this.version = 0;
  6715. }
  6716. Object.defineProperty(BufferAttribute.prototype, 'needsUpdate', {
  6717. set: function set(value) {
  6718. if (value === true) this.version++;
  6719. }
  6720. });
  6721. Object.assign(BufferAttribute.prototype, {
  6722. isBufferAttribute: true,
  6723. onUploadCallback: function onUploadCallback() {},
  6724. setUsage: function setUsage(value) {
  6725. this.usage = value;
  6726. return this;
  6727. },
  6728. copy: function copy(source) {
  6729. this.name = source.name;
  6730. this.array = new source.array.constructor(source.array);
  6731. this.itemSize = source.itemSize;
  6732. this.count = source.count;
  6733. this.normalized = source.normalized;
  6734. this.usage = source.usage;
  6735. return this;
  6736. },
  6737. copyAt: function copyAt(index1, attribute, index2) {
  6738. index1 *= this.itemSize;
  6739. index2 *= attribute.itemSize;
  6740. for (var i = 0, l = this.itemSize; i < l; i++) {
  6741. this.array[index1 + i] = attribute.array[index2 + i];
  6742. }
  6743. return this;
  6744. },
  6745. copyArray: function copyArray(array) {
  6746. this.array.set(array);
  6747. return this;
  6748. },
  6749. copyColorsArray: function copyColorsArray(colors) {
  6750. var array = this.array;
  6751. var offset = 0;
  6752. for (var i = 0, l = colors.length; i < l; i++) {
  6753. var color = colors[i];
  6754. if (color === undefined) {
  6755. console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined', i);
  6756. color = new Color();
  6757. }
  6758. array[offset++] = color.r;
  6759. array[offset++] = color.g;
  6760. array[offset++] = color.b;
  6761. }
  6762. return this;
  6763. },
  6764. copyVector2sArray: function copyVector2sArray(vectors) {
  6765. var array = this.array;
  6766. var offset = 0;
  6767. for (var i = 0, l = vectors.length; i < l; i++) {
  6768. var vector = vectors[i];
  6769. if (vector === undefined) {
  6770. console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i);
  6771. vector = new Vector2();
  6772. }
  6773. array[offset++] = vector.x;
  6774. array[offset++] = vector.y;
  6775. }
  6776. return this;
  6777. },
  6778. copyVector3sArray: function copyVector3sArray(vectors) {
  6779. var array = this.array;
  6780. var offset = 0;
  6781. for (var i = 0, l = vectors.length; i < l; i++) {
  6782. var vector = vectors[i];
  6783. if (vector === undefined) {
  6784. console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i);
  6785. vector = new Vector3();
  6786. }
  6787. array[offset++] = vector.x;
  6788. array[offset++] = vector.y;
  6789. array[offset++] = vector.z;
  6790. }
  6791. return this;
  6792. },
  6793. copyVector4sArray: function copyVector4sArray(vectors) {
  6794. var array = this.array;
  6795. var offset = 0;
  6796. for (var i = 0, l = vectors.length; i < l; i++) {
  6797. var vector = vectors[i];
  6798. if (vector === undefined) {
  6799. console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i);
  6800. vector = new Vector4();
  6801. }
  6802. array[offset++] = vector.x;
  6803. array[offset++] = vector.y;
  6804. array[offset++] = vector.z;
  6805. array[offset++] = vector.w;
  6806. }
  6807. return this;
  6808. },
  6809. applyMatrix3: function applyMatrix3(m) {
  6810. if (this.itemSize === 2) {
  6811. for (var i = 0, l = this.count; i < l; i++) {
  6812. _vector2$1.fromBufferAttribute(this, i);
  6813. _vector2$1.applyMatrix3(m);
  6814. this.setXY(i, _vector2$1.x, _vector2$1.y);
  6815. }
  6816. } else if (this.itemSize === 3) {
  6817. for (var _i = 0, _l = this.count; _i < _l; _i++) {
  6818. _vector$3.fromBufferAttribute(this, _i);
  6819. _vector$3.applyMatrix3(m);
  6820. this.setXYZ(_i, _vector$3.x, _vector$3.y, _vector$3.z);
  6821. }
  6822. }
  6823. return this;
  6824. },
  6825. applyMatrix4: function applyMatrix4(m) {
  6826. for (var i = 0, l = this.count; i < l; i++) {
  6827. _vector$3.x = this.getX(i);
  6828. _vector$3.y = this.getY(i);
  6829. _vector$3.z = this.getZ(i);
  6830. _vector$3.applyMatrix4(m);
  6831. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6832. }
  6833. return this;
  6834. },
  6835. applyNormalMatrix: function applyNormalMatrix(m) {
  6836. for (var i = 0, l = this.count; i < l; i++) {
  6837. _vector$3.x = this.getX(i);
  6838. _vector$3.y = this.getY(i);
  6839. _vector$3.z = this.getZ(i);
  6840. _vector$3.applyNormalMatrix(m);
  6841. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6842. }
  6843. return this;
  6844. },
  6845. transformDirection: function transformDirection(m) {
  6846. for (var i = 0, l = this.count; i < l; i++) {
  6847. _vector$3.x = this.getX(i);
  6848. _vector$3.y = this.getY(i);
  6849. _vector$3.z = this.getZ(i);
  6850. _vector$3.transformDirection(m);
  6851. this.setXYZ(i, _vector$3.x, _vector$3.y, _vector$3.z);
  6852. }
  6853. return this;
  6854. },
  6855. set: function set(value, offset) {
  6856. if (offset === void 0) {
  6857. offset = 0;
  6858. }
  6859. this.array.set(value, offset);
  6860. return this;
  6861. },
  6862. getX: function getX(index) {
  6863. return this.array[index * this.itemSize];
  6864. },
  6865. setX: function setX(index, x) {
  6866. this.array[index * this.itemSize] = x;
  6867. return this;
  6868. },
  6869. getY: function getY(index) {
  6870. return this.array[index * this.itemSize + 1];
  6871. },
  6872. setY: function setY(index, y) {
  6873. this.array[index * this.itemSize + 1] = y;
  6874. return this;
  6875. },
  6876. getZ: function getZ(index) {
  6877. return this.array[index * this.itemSize + 2];
  6878. },
  6879. setZ: function setZ(index, z) {
  6880. this.array[index * this.itemSize + 2] = z;
  6881. return this;
  6882. },
  6883. getW: function getW(index) {
  6884. return this.array[index * this.itemSize + 3];
  6885. },
  6886. setW: function setW(index, w) {
  6887. this.array[index * this.itemSize + 3] = w;
  6888. return this;
  6889. },
  6890. setXY: function setXY(index, x, y) {
  6891. index *= this.itemSize;
  6892. this.array[index + 0] = x;
  6893. this.array[index + 1] = y;
  6894. return this;
  6895. },
  6896. setXYZ: function setXYZ(index, x, y, z) {
  6897. index *= this.itemSize;
  6898. this.array[index + 0] = x;
  6899. this.array[index + 1] = y;
  6900. this.array[index + 2] = z;
  6901. return this;
  6902. },
  6903. setXYZW: function setXYZW(index, x, y, z, w) {
  6904. index *= this.itemSize;
  6905. this.array[index + 0] = x;
  6906. this.array[index + 1] = y;
  6907. this.array[index + 2] = z;
  6908. this.array[index + 3] = w;
  6909. return this;
  6910. },
  6911. onUpload: function onUpload(callback) {
  6912. this.onUploadCallback = callback;
  6913. return this;
  6914. },
  6915. clone: function clone() {
  6916. return new this.constructor(this.array, this.itemSize).copy(this);
  6917. },
  6918. toJSON: function toJSON() {
  6919. return {
  6920. itemSize: this.itemSize,
  6921. type: this.array.constructor.name,
  6922. array: Array.prototype.slice.call(this.array),
  6923. normalized: this.normalized
  6924. };
  6925. }
  6926. }); //
  6927. function Int8BufferAttribute(array, itemSize, normalized) {
  6928. BufferAttribute.call(this, new Int8Array(array), itemSize, normalized);
  6929. }
  6930. Int8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6931. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6932. function Uint8BufferAttribute(array, itemSize, normalized) {
  6933. BufferAttribute.call(this, new Uint8Array(array), itemSize, normalized);
  6934. }
  6935. Uint8BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6936. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6937. function Uint8ClampedBufferAttribute(array, itemSize, normalized) {
  6938. BufferAttribute.call(this, new Uint8ClampedArray(array), itemSize, normalized);
  6939. }
  6940. Uint8ClampedBufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6941. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6942. function Int16BufferAttribute(array, itemSize, normalized) {
  6943. BufferAttribute.call(this, new Int16Array(array), itemSize, normalized);
  6944. }
  6945. Int16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6946. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6947. function Uint16BufferAttribute(array, itemSize, normalized) {
  6948. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6949. }
  6950. Uint16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6951. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6952. function Int32BufferAttribute(array, itemSize, normalized) {
  6953. BufferAttribute.call(this, new Int32Array(array), itemSize, normalized);
  6954. }
  6955. Int32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6956. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6957. function Uint32BufferAttribute(array, itemSize, normalized) {
  6958. BufferAttribute.call(this, new Uint32Array(array), itemSize, normalized);
  6959. }
  6960. Uint32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6961. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6962. function Float16BufferAttribute(array, itemSize, normalized) {
  6963. BufferAttribute.call(this, new Uint16Array(array), itemSize, normalized);
  6964. }
  6965. Float16BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6966. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  6967. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  6968. function Float32BufferAttribute(array, itemSize, normalized) {
  6969. BufferAttribute.call(this, new Float32Array(array), itemSize, normalized);
  6970. }
  6971. Float32BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6972. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6973. function Float64BufferAttribute(array, itemSize, normalized) {
  6974. BufferAttribute.call(this, new Float64Array(array), itemSize, normalized);
  6975. }
  6976. Float64BufferAttribute.prototype = Object.create(BufferAttribute.prototype);
  6977. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; //
  6978. function arrayMax(array) {
  6979. if (array.length === 0) return -Infinity;
  6980. var max = array[0];
  6981. for (var i = 1, l = array.length; i < l; ++i) {
  6982. if (array[i] > max) max = array[i];
  6983. }
  6984. return max;
  6985. }
  6986. var TYPED_ARRAYS = {
  6987. Int8Array: Int8Array,
  6988. Uint8Array: Uint8Array,
  6989. // Workaround for IE11 pre KB2929437. See #11440
  6990. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  6991. Int16Array: Int16Array,
  6992. Uint16Array: Uint16Array,
  6993. Int32Array: Int32Array,
  6994. Uint32Array: Uint32Array,
  6995. Float32Array: Float32Array,
  6996. Float64Array: Float64Array
  6997. };
  6998. function getTypedArray(type, buffer) {
  6999. return new TYPED_ARRAYS[type](buffer);
  7000. }
  7001. var _id = 0;
  7002. var _m1$2 = new Matrix4();
  7003. var _obj = new Object3D();
  7004. var _offset = new Vector3();
  7005. var _box$2 = new Box3();
  7006. var _boxMorphTargets = new Box3();
  7007. var _vector$4 = new Vector3();
  7008. function BufferGeometry() {
  7009. Object.defineProperty(this, 'id', {
  7010. value: _id++
  7011. });
  7012. this.uuid = MathUtils.generateUUID();
  7013. this.name = '';
  7014. this.type = 'BufferGeometry';
  7015. this.index = null;
  7016. this.attributes = {};
  7017. this.morphAttributes = {};
  7018. this.morphTargetsRelative = false;
  7019. this.groups = [];
  7020. this.boundingBox = null;
  7021. this.boundingSphere = null;
  7022. this.drawRange = {
  7023. start: 0,
  7024. count: Infinity
  7025. };
  7026. this.userData = {};
  7027. }
  7028. BufferGeometry.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  7029. constructor: BufferGeometry,
  7030. isBufferGeometry: true,
  7031. getIndex: function getIndex() {
  7032. return this.index;
  7033. },
  7034. setIndex: function setIndex(index) {
  7035. if (Array.isArray(index)) {
  7036. this.index = new (arrayMax(index) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
  7037. } else {
  7038. this.index = index;
  7039. }
  7040. return this;
  7041. },
  7042. getAttribute: function getAttribute(name) {
  7043. return this.attributes[name];
  7044. },
  7045. setAttribute: function setAttribute(name, attribute) {
  7046. this.attributes[name] = attribute;
  7047. return this;
  7048. },
  7049. deleteAttribute: function deleteAttribute(name) {
  7050. delete this.attributes[name];
  7051. return this;
  7052. },
  7053. hasAttribute: function hasAttribute(name) {
  7054. return this.attributes[name] !== undefined;
  7055. },
  7056. addGroup: function addGroup(start, count, materialIndex) {
  7057. if (materialIndex === void 0) {
  7058. materialIndex = 0;
  7059. }
  7060. this.groups.push({
  7061. start: start,
  7062. count: count,
  7063. materialIndex: materialIndex
  7064. });
  7065. },
  7066. clearGroups: function clearGroups() {
  7067. this.groups = [];
  7068. },
  7069. setDrawRange: function setDrawRange(start, count) {
  7070. this.drawRange.start = start;
  7071. this.drawRange.count = count;
  7072. },
  7073. applyMatrix4: function applyMatrix4(matrix) {
  7074. var position = this.attributes.position;
  7075. if (position !== undefined) {
  7076. position.applyMatrix4(matrix);
  7077. position.needsUpdate = true;
  7078. }
  7079. var normal = this.attributes.normal;
  7080. if (normal !== undefined) {
  7081. var normalMatrix = new Matrix3().getNormalMatrix(matrix);
  7082. normal.applyNormalMatrix(normalMatrix);
  7083. normal.needsUpdate = true;
  7084. }
  7085. var tangent = this.attributes.tangent;
  7086. if (tangent !== undefined) {
  7087. tangent.transformDirection(matrix);
  7088. tangent.needsUpdate = true;
  7089. }
  7090. if (this.boundingBox !== null) {
  7091. this.computeBoundingBox();
  7092. }
  7093. if (this.boundingSphere !== null) {
  7094. this.computeBoundingSphere();
  7095. }
  7096. return this;
  7097. },
  7098. rotateX: function rotateX(angle) {
  7099. // rotate geometry around world x-axis
  7100. _m1$2.makeRotationX(angle);
  7101. this.applyMatrix4(_m1$2);
  7102. return this;
  7103. },
  7104. rotateY: function rotateY(angle) {
  7105. // rotate geometry around world y-axis
  7106. _m1$2.makeRotationY(angle);
  7107. this.applyMatrix4(_m1$2);
  7108. return this;
  7109. },
  7110. rotateZ: function rotateZ(angle) {
  7111. // rotate geometry around world z-axis
  7112. _m1$2.makeRotationZ(angle);
  7113. this.applyMatrix4(_m1$2);
  7114. return this;
  7115. },
  7116. translate: function translate(x, y, z) {
  7117. // translate geometry
  7118. _m1$2.makeTranslation(x, y, z);
  7119. this.applyMatrix4(_m1$2);
  7120. return this;
  7121. },
  7122. scale: function scale(x, y, z) {
  7123. // scale geometry
  7124. _m1$2.makeScale(x, y, z);
  7125. this.applyMatrix4(_m1$2);
  7126. return this;
  7127. },
  7128. lookAt: function lookAt(vector) {
  7129. _obj.lookAt(vector);
  7130. _obj.updateMatrix();
  7131. this.applyMatrix4(_obj.matrix);
  7132. return this;
  7133. },
  7134. center: function center() {
  7135. this.computeBoundingBox();
  7136. this.boundingBox.getCenter(_offset).negate();
  7137. this.translate(_offset.x, _offset.y, _offset.z);
  7138. return this;
  7139. },
  7140. setFromPoints: function setFromPoints(points) {
  7141. var position = [];
  7142. for (var i = 0, l = points.length; i < l; i++) {
  7143. var point = points[i];
  7144. position.push(point.x, point.y, point.z || 0);
  7145. }
  7146. this.setAttribute('position', new Float32BufferAttribute(position, 3));
  7147. return this;
  7148. },
  7149. computeBoundingBox: function computeBoundingBox() {
  7150. if (this.boundingBox === null) {
  7151. this.boundingBox = new Box3();
  7152. }
  7153. var position = this.attributes.position;
  7154. var morphAttributesPosition = this.morphAttributes.position;
  7155. if (position && position.isGLBufferAttribute) {
  7156. console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this);
  7157. this.boundingBox.set(new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(+Infinity, +Infinity, +Infinity));
  7158. return;
  7159. }
  7160. if (position !== undefined) {
  7161. this.boundingBox.setFromBufferAttribute(position); // process morph attributes if present
  7162. if (morphAttributesPosition) {
  7163. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7164. var morphAttribute = morphAttributesPosition[i];
  7165. _box$2.setFromBufferAttribute(morphAttribute);
  7166. if (this.morphTargetsRelative) {
  7167. _vector$4.addVectors(this.boundingBox.min, _box$2.min);
  7168. this.boundingBox.expandByPoint(_vector$4);
  7169. _vector$4.addVectors(this.boundingBox.max, _box$2.max);
  7170. this.boundingBox.expandByPoint(_vector$4);
  7171. } else {
  7172. this.boundingBox.expandByPoint(_box$2.min);
  7173. this.boundingBox.expandByPoint(_box$2.max);
  7174. }
  7175. }
  7176. }
  7177. } else {
  7178. this.boundingBox.makeEmpty();
  7179. }
  7180. if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) {
  7181. console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this);
  7182. }
  7183. },
  7184. computeBoundingSphere: function computeBoundingSphere() {
  7185. if (this.boundingSphere === null) {
  7186. this.boundingSphere = new Sphere();
  7187. }
  7188. var position = this.attributes.position;
  7189. var morphAttributesPosition = this.morphAttributes.position;
  7190. if (position && position.isGLBufferAttribute) {
  7191. console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this);
  7192. this.boundingSphere.set(new Vector3(), Infinity);
  7193. return;
  7194. }
  7195. if (position) {
  7196. // first, find the center of the bounding sphere
  7197. var center = this.boundingSphere.center;
  7198. _box$2.setFromBufferAttribute(position); // process morph attributes if present
  7199. if (morphAttributesPosition) {
  7200. for (var i = 0, il = morphAttributesPosition.length; i < il; i++) {
  7201. var morphAttribute = morphAttributesPosition[i];
  7202. _boxMorphTargets.setFromBufferAttribute(morphAttribute);
  7203. if (this.morphTargetsRelative) {
  7204. _vector$4.addVectors(_box$2.min, _boxMorphTargets.min);
  7205. _box$2.expandByPoint(_vector$4);
  7206. _vector$4.addVectors(_box$2.max, _boxMorphTargets.max);
  7207. _box$2.expandByPoint(_vector$4);
  7208. } else {
  7209. _box$2.expandByPoint(_boxMorphTargets.min);
  7210. _box$2.expandByPoint(_boxMorphTargets.max);
  7211. }
  7212. }
  7213. }
  7214. _box$2.getCenter(center); // second, try to find a boundingSphere with a radius smaller than the
  7215. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7216. var maxRadiusSq = 0;
  7217. for (var _i = 0, _il = position.count; _i < _il; _i++) {
  7218. _vector$4.fromBufferAttribute(position, _i);
  7219. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7220. } // process morph attributes if present
  7221. if (morphAttributesPosition) {
  7222. for (var _i2 = 0, _il2 = morphAttributesPosition.length; _i2 < _il2; _i2++) {
  7223. var _morphAttribute = morphAttributesPosition[_i2];
  7224. var morphTargetsRelative = this.morphTargetsRelative;
  7225. for (var j = 0, jl = _morphAttribute.count; j < jl; j++) {
  7226. _vector$4.fromBufferAttribute(_morphAttribute, j);
  7227. if (morphTargetsRelative) {
  7228. _offset.fromBufferAttribute(position, j);
  7229. _vector$4.add(_offset);
  7230. }
  7231. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$4));
  7232. }
  7233. }
  7234. }
  7235. this.boundingSphere.radius = Math.sqrt(maxRadiusSq);
  7236. if (isNaN(this.boundingSphere.radius)) {
  7237. console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this);
  7238. }
  7239. }
  7240. },
  7241. computeFaceNormals: function computeFaceNormals() {// backwards compatibility
  7242. },
  7243. computeTangents: function computeTangents() {
  7244. var index = this.index;
  7245. var attributes = this.attributes; // based on http://www.terathon.com/code/tangent.html
  7246. // (per vertex tangents)
  7247. if (index === null || attributes.position === undefined || attributes.normal === undefined || attributes.uv === undefined) {
  7248. console.error('THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)');
  7249. return;
  7250. }
  7251. var indices = index.array;
  7252. var positions = attributes.position.array;
  7253. var normals = attributes.normal.array;
  7254. var uvs = attributes.uv.array;
  7255. var nVertices = positions.length / 3;
  7256. if (attributes.tangent === undefined) {
  7257. this.setAttribute('tangent', new BufferAttribute(new Float32Array(4 * nVertices), 4));
  7258. }
  7259. var tangents = attributes.tangent.array;
  7260. var tan1 = [],
  7261. tan2 = [];
  7262. for (var i = 0; i < nVertices; i++) {
  7263. tan1[i] = new Vector3();
  7264. tan2[i] = new Vector3();
  7265. }
  7266. var vA = new Vector3(),
  7267. vB = new Vector3(),
  7268. vC = new Vector3(),
  7269. uvA = new Vector2(),
  7270. uvB = new Vector2(),
  7271. uvC = new Vector2(),
  7272. sdir = new Vector3(),
  7273. tdir = new Vector3();
  7274. function handleTriangle(a, b, c) {
  7275. vA.fromArray(positions, a * 3);
  7276. vB.fromArray(positions, b * 3);
  7277. vC.fromArray(positions, c * 3);
  7278. uvA.fromArray(uvs, a * 2);
  7279. uvB.fromArray(uvs, b * 2);
  7280. uvC.fromArray(uvs, c * 2);
  7281. vB.sub(vA);
  7282. vC.sub(vA);
  7283. uvB.sub(uvA);
  7284. uvC.sub(uvA);
  7285. var r = 1.0 / (uvB.x * uvC.y - uvC.x * uvB.y); // silently ignore degenerate uv triangles having coincident or colinear vertices
  7286. if (!isFinite(r)) return;
  7287. sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r);
  7288. tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r);
  7289. tan1[a].add(sdir);
  7290. tan1[b].add(sdir);
  7291. tan1[c].add(sdir);
  7292. tan2[a].add(tdir);
  7293. tan2[b].add(tdir);
  7294. tan2[c].add(tdir);
  7295. }
  7296. var groups = this.groups;
  7297. if (groups.length === 0) {
  7298. groups = [{
  7299. start: 0,
  7300. count: indices.length
  7301. }];
  7302. }
  7303. for (var _i3 = 0, il = groups.length; _i3 < il; ++_i3) {
  7304. var group = groups[_i3];
  7305. var start = group.start;
  7306. var count = group.count;
  7307. for (var j = start, jl = start + count; j < jl; j += 3) {
  7308. handleTriangle(indices[j + 0], indices[j + 1], indices[j + 2]);
  7309. }
  7310. }
  7311. var tmp = new Vector3(),
  7312. tmp2 = new Vector3();
  7313. var n = new Vector3(),
  7314. n2 = new Vector3();
  7315. function handleVertex(v) {
  7316. n.fromArray(normals, v * 3);
  7317. n2.copy(n);
  7318. var t = tan1[v]; // Gram-Schmidt orthogonalize
  7319. tmp.copy(t);
  7320. tmp.sub(n.multiplyScalar(n.dot(t))).normalize(); // Calculate handedness
  7321. tmp2.crossVectors(n2, t);
  7322. var test = tmp2.dot(tan2[v]);
  7323. var w = test < 0.0 ? -1.0 : 1.0;
  7324. tangents[v * 4] = tmp.x;
  7325. tangents[v * 4 + 1] = tmp.y;
  7326. tangents[v * 4 + 2] = tmp.z;
  7327. tangents[v * 4 + 3] = w;
  7328. }
  7329. for (var _i4 = 0, _il3 = groups.length; _i4 < _il3; ++_i4) {
  7330. var _group = groups[_i4];
  7331. var _start = _group.start;
  7332. var _count = _group.count;
  7333. for (var _j = _start, _jl = _start + _count; _j < _jl; _j += 3) {
  7334. handleVertex(indices[_j + 0]);
  7335. handleVertex(indices[_j + 1]);
  7336. handleVertex(indices[_j + 2]);
  7337. }
  7338. }
  7339. },
  7340. computeVertexNormals: function computeVertexNormals() {
  7341. var index = this.index;
  7342. var positionAttribute = this.getAttribute('position');
  7343. if (positionAttribute !== undefined) {
  7344. var normalAttribute = this.getAttribute('normal');
  7345. if (normalAttribute === undefined) {
  7346. normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3);
  7347. this.setAttribute('normal', normalAttribute);
  7348. } else {
  7349. // reset existing normals to zero
  7350. for (var i = 0, il = normalAttribute.count; i < il; i++) {
  7351. normalAttribute.setXYZ(i, 0, 0, 0);
  7352. }
  7353. }
  7354. var pA = new Vector3(),
  7355. pB = new Vector3(),
  7356. pC = new Vector3();
  7357. var nA = new Vector3(),
  7358. nB = new Vector3(),
  7359. nC = new Vector3();
  7360. var cb = new Vector3(),
  7361. ab = new Vector3(); // indexed elements
  7362. if (index) {
  7363. for (var _i5 = 0, _il4 = index.count; _i5 < _il4; _i5 += 3) {
  7364. var vA = index.getX(_i5 + 0);
  7365. var vB = index.getX(_i5 + 1);
  7366. var vC = index.getX(_i5 + 2);
  7367. pA.fromBufferAttribute(positionAttribute, vA);
  7368. pB.fromBufferAttribute(positionAttribute, vB);
  7369. pC.fromBufferAttribute(positionAttribute, vC);
  7370. cb.subVectors(pC, pB);
  7371. ab.subVectors(pA, pB);
  7372. cb.cross(ab);
  7373. nA.fromBufferAttribute(normalAttribute, vA);
  7374. nB.fromBufferAttribute(normalAttribute, vB);
  7375. nC.fromBufferAttribute(normalAttribute, vC);
  7376. nA.add(cb);
  7377. nB.add(cb);
  7378. nC.add(cb);
  7379. normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z);
  7380. normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z);
  7381. normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z);
  7382. }
  7383. } else {
  7384. // non-indexed elements (unconnected triangle soup)
  7385. for (var _i6 = 0, _il5 = positionAttribute.count; _i6 < _il5; _i6 += 3) {
  7386. pA.fromBufferAttribute(positionAttribute, _i6 + 0);
  7387. pB.fromBufferAttribute(positionAttribute, _i6 + 1);
  7388. pC.fromBufferAttribute(positionAttribute, _i6 + 2);
  7389. cb.subVectors(pC, pB);
  7390. ab.subVectors(pA, pB);
  7391. cb.cross(ab);
  7392. normalAttribute.setXYZ(_i6 + 0, cb.x, cb.y, cb.z);
  7393. normalAttribute.setXYZ(_i6 + 1, cb.x, cb.y, cb.z);
  7394. normalAttribute.setXYZ(_i6 + 2, cb.x, cb.y, cb.z);
  7395. }
  7396. }
  7397. this.normalizeNormals();
  7398. normalAttribute.needsUpdate = true;
  7399. }
  7400. },
  7401. merge: function merge(geometry, offset) {
  7402. if (!(geometry && geometry.isBufferGeometry)) {
  7403. console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry);
  7404. return;
  7405. }
  7406. if (offset === undefined) {
  7407. offset = 0;
  7408. console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');
  7409. }
  7410. var attributes = this.attributes;
  7411. for (var key in attributes) {
  7412. if (geometry.attributes[key] === undefined) continue;
  7413. var attribute1 = attributes[key];
  7414. var attributeArray1 = attribute1.array;
  7415. var attribute2 = geometry.attributes[key];
  7416. var attributeArray2 = attribute2.array;
  7417. var attributeOffset = attribute2.itemSize * offset;
  7418. var length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset);
  7419. for (var i = 0, j = attributeOffset; i < length; i++, j++) {
  7420. attributeArray1[j] = attributeArray2[i];
  7421. }
  7422. }
  7423. return this;
  7424. },
  7425. normalizeNormals: function normalizeNormals() {
  7426. var normals = this.attributes.normal;
  7427. for (var i = 0, il = normals.count; i < il; i++) {
  7428. _vector$4.fromBufferAttribute(normals, i);
  7429. _vector$4.normalize();
  7430. normals.setXYZ(i, _vector$4.x, _vector$4.y, _vector$4.z);
  7431. }
  7432. },
  7433. toNonIndexed: function toNonIndexed() {
  7434. function convertBufferAttribute(attribute, indices) {
  7435. var array = attribute.array;
  7436. var itemSize = attribute.itemSize;
  7437. var normalized = attribute.normalized;
  7438. var array2 = new array.constructor(indices.length * itemSize);
  7439. var index = 0,
  7440. index2 = 0;
  7441. for (var i = 0, l = indices.length; i < l; i++) {
  7442. index = indices[i] * itemSize;
  7443. for (var j = 0; j < itemSize; j++) {
  7444. array2[index2++] = array[index++];
  7445. }
  7446. }
  7447. return new BufferAttribute(array2, itemSize, normalized);
  7448. } //
  7449. if (this.index === null) {
  7450. console.warn('THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.');
  7451. return this;
  7452. }
  7453. var geometry2 = new BufferGeometry();
  7454. var indices = this.index.array;
  7455. var attributes = this.attributes; // attributes
  7456. for (var name in attributes) {
  7457. var attribute = attributes[name];
  7458. var newAttribute = convertBufferAttribute(attribute, indices);
  7459. geometry2.setAttribute(name, newAttribute);
  7460. } // morph attributes
  7461. var morphAttributes = this.morphAttributes;
  7462. for (var _name in morphAttributes) {
  7463. var morphArray = [];
  7464. var morphAttribute = morphAttributes[_name]; // morphAttribute: array of Float32BufferAttributes
  7465. for (var i = 0, il = morphAttribute.length; i < il; i++) {
  7466. var _attribute = morphAttribute[i];
  7467. var _newAttribute = convertBufferAttribute(_attribute, indices);
  7468. morphArray.push(_newAttribute);
  7469. }
  7470. geometry2.morphAttributes[_name] = morphArray;
  7471. }
  7472. geometry2.morphTargetsRelative = this.morphTargetsRelative; // groups
  7473. var groups = this.groups;
  7474. for (var _i7 = 0, l = groups.length; _i7 < l; _i7++) {
  7475. var group = groups[_i7];
  7476. geometry2.addGroup(group.start, group.count, group.materialIndex);
  7477. }
  7478. return geometry2;
  7479. },
  7480. toJSON: function toJSON() {
  7481. var data = {
  7482. metadata: {
  7483. version: 4.5,
  7484. type: 'BufferGeometry',
  7485. generator: 'BufferGeometry.toJSON'
  7486. }
  7487. }; // standard BufferGeometry serialization
  7488. data.uuid = this.uuid;
  7489. data.type = this.type;
  7490. if (this.name !== '') data.name = this.name;
  7491. if (Object.keys(this.userData).length > 0) data.userData = this.userData;
  7492. if (this.parameters !== undefined) {
  7493. var parameters = this.parameters;
  7494. for (var key in parameters) {
  7495. if (parameters[key] !== undefined) data[key] = parameters[key];
  7496. }
  7497. return data;
  7498. }
  7499. data.data = {
  7500. attributes: {}
  7501. };
  7502. var index = this.index;
  7503. if (index !== null) {
  7504. data.data.index = {
  7505. type: index.array.constructor.name,
  7506. array: Array.prototype.slice.call(index.array)
  7507. };
  7508. }
  7509. var attributes = this.attributes;
  7510. for (var _key in attributes) {
  7511. var attribute = attributes[_key];
  7512. var attributeData = attribute.toJSON(data.data);
  7513. if (attribute.name !== '') attributeData.name = attribute.name;
  7514. data.data.attributes[_key] = attributeData;
  7515. }
  7516. var morphAttributes = {};
  7517. var hasMorphAttributes = false;
  7518. for (var _key2 in this.morphAttributes) {
  7519. var attributeArray = this.morphAttributes[_key2];
  7520. var array = [];
  7521. for (var i = 0, il = attributeArray.length; i < il; i++) {
  7522. var _attribute2 = attributeArray[i];
  7523. var _attributeData = _attribute2.toJSON(data.data);
  7524. if (_attribute2.name !== '') _attributeData.name = _attribute2.name;
  7525. array.push(_attributeData);
  7526. }
  7527. if (array.length > 0) {
  7528. morphAttributes[_key2] = array;
  7529. hasMorphAttributes = true;
  7530. }
  7531. }
  7532. if (hasMorphAttributes) {
  7533. data.data.morphAttributes = morphAttributes;
  7534. data.data.morphTargetsRelative = this.morphTargetsRelative;
  7535. }
  7536. var groups = this.groups;
  7537. if (groups.length > 0) {
  7538. data.data.groups = JSON.parse(JSON.stringify(groups));
  7539. }
  7540. var boundingSphere = this.boundingSphere;
  7541. if (boundingSphere !== null) {
  7542. data.data.boundingSphere = {
  7543. center: boundingSphere.center.toArray(),
  7544. radius: boundingSphere.radius
  7545. };
  7546. }
  7547. return data;
  7548. },
  7549. clone: function clone() {
  7550. /*
  7551. // Handle primitives
  7552. const parameters = this.parameters;
  7553. if ( parameters !== undefined ) {
  7554. const values = [];
  7555. for ( const key in parameters ) {
  7556. values.push( parameters[ key ] );
  7557. }
  7558. const geometry = Object.create( this.constructor.prototype );
  7559. this.constructor.apply( geometry, values );
  7560. return geometry;
  7561. }
  7562. return new this.constructor().copy( this );
  7563. */
  7564. return new BufferGeometry().copy(this);
  7565. },
  7566. copy: function copy(source) {
  7567. // reset
  7568. this.index = null;
  7569. this.attributes = {};
  7570. this.morphAttributes = {};
  7571. this.groups = [];
  7572. this.boundingBox = null;
  7573. this.boundingSphere = null; // used for storing cloned, shared data
  7574. var data = {}; // name
  7575. this.name = source.name; // index
  7576. var index = source.index;
  7577. if (index !== null) {
  7578. this.setIndex(index.clone(data));
  7579. } // attributes
  7580. var attributes = source.attributes;
  7581. for (var name in attributes) {
  7582. var attribute = attributes[name];
  7583. this.setAttribute(name, attribute.clone(data));
  7584. } // morph attributes
  7585. var morphAttributes = source.morphAttributes;
  7586. for (var _name2 in morphAttributes) {
  7587. var array = [];
  7588. var morphAttribute = morphAttributes[_name2]; // morphAttribute: array of Float32BufferAttributes
  7589. for (var i = 0, l = morphAttribute.length; i < l; i++) {
  7590. array.push(morphAttribute[i].clone(data));
  7591. }
  7592. this.morphAttributes[_name2] = array;
  7593. }
  7594. this.morphTargetsRelative = source.morphTargetsRelative; // groups
  7595. var groups = source.groups;
  7596. for (var _i8 = 0, _l = groups.length; _i8 < _l; _i8++) {
  7597. var group = groups[_i8];
  7598. this.addGroup(group.start, group.count, group.materialIndex);
  7599. } // bounding box
  7600. var boundingBox = source.boundingBox;
  7601. if (boundingBox !== null) {
  7602. this.boundingBox = boundingBox.clone();
  7603. } // bounding sphere
  7604. var boundingSphere = source.boundingSphere;
  7605. if (boundingSphere !== null) {
  7606. this.boundingSphere = boundingSphere.clone();
  7607. } // draw range
  7608. this.drawRange.start = source.drawRange.start;
  7609. this.drawRange.count = source.drawRange.count; // user data
  7610. this.userData = source.userData;
  7611. return this;
  7612. },
  7613. dispose: function dispose() {
  7614. this.dispatchEvent({
  7615. type: 'dispose'
  7616. });
  7617. }
  7618. });
  7619. var _inverseMatrix = new Matrix4();
  7620. var _ray = new Ray();
  7621. var _sphere = new Sphere();
  7622. var _vA = new Vector3();
  7623. var _vB = new Vector3();
  7624. var _vC = new Vector3();
  7625. var _tempA = new Vector3();
  7626. var _tempB = new Vector3();
  7627. var _tempC = new Vector3();
  7628. var _morphA = new Vector3();
  7629. var _morphB = new Vector3();
  7630. var _morphC = new Vector3();
  7631. var _uvA = new Vector2();
  7632. var _uvB = new Vector2();
  7633. var _uvC = new Vector2();
  7634. var _intersectionPoint = new Vector3();
  7635. var _intersectionPointWorld = new Vector3();
  7636. function Mesh(geometry, material) {
  7637. if (geometry === void 0) {
  7638. geometry = new BufferGeometry();
  7639. }
  7640. if (material === void 0) {
  7641. material = new MeshBasicMaterial();
  7642. }
  7643. Object3D.call(this);
  7644. this.type = 'Mesh';
  7645. this.geometry = geometry;
  7646. this.material = material;
  7647. this.updateMorphTargets();
  7648. }
  7649. Mesh.prototype = Object.assign(Object.create(Object3D.prototype), {
  7650. constructor: Mesh,
  7651. isMesh: true,
  7652. copy: function copy(source) {
  7653. Object3D.prototype.copy.call(this, source);
  7654. if (source.morphTargetInfluences !== undefined) {
  7655. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  7656. }
  7657. if (source.morphTargetDictionary !== undefined) {
  7658. this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary);
  7659. }
  7660. this.material = source.material;
  7661. this.geometry = source.geometry;
  7662. return this;
  7663. },
  7664. updateMorphTargets: function updateMorphTargets() {
  7665. var geometry = this.geometry;
  7666. if (geometry.isBufferGeometry) {
  7667. var morphAttributes = geometry.morphAttributes;
  7668. var keys = Object.keys(morphAttributes);
  7669. if (keys.length > 0) {
  7670. var morphAttribute = morphAttributes[keys[0]];
  7671. if (morphAttribute !== undefined) {
  7672. this.morphTargetInfluences = [];
  7673. this.morphTargetDictionary = {};
  7674. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  7675. var name = morphAttribute[m].name || String(m);
  7676. this.morphTargetInfluences.push(0);
  7677. this.morphTargetDictionary[name] = m;
  7678. }
  7679. }
  7680. }
  7681. } else {
  7682. var morphTargets = geometry.morphTargets;
  7683. if (morphTargets !== undefined && morphTargets.length > 0) {
  7684. console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7685. }
  7686. }
  7687. },
  7688. raycast: function raycast(raycaster, intersects) {
  7689. var geometry = this.geometry;
  7690. var material = this.material;
  7691. var matrixWorld = this.matrixWorld;
  7692. if (material === undefined) return; // Checking boundingSphere distance to ray
  7693. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  7694. _sphere.copy(geometry.boundingSphere);
  7695. _sphere.applyMatrix4(matrixWorld);
  7696. if (raycaster.ray.intersectsSphere(_sphere) === false) return; //
  7697. _inverseMatrix.copy(matrixWorld).invert();
  7698. _ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix); // Check boundingBox before continuing
  7699. if (geometry.boundingBox !== null) {
  7700. if (_ray.intersectsBox(geometry.boundingBox) === false) return;
  7701. }
  7702. var intersection;
  7703. if (geometry.isBufferGeometry) {
  7704. var index = geometry.index;
  7705. var position = geometry.attributes.position;
  7706. var morphPosition = geometry.morphAttributes.position;
  7707. var morphTargetsRelative = geometry.morphTargetsRelative;
  7708. var uv = geometry.attributes.uv;
  7709. var uv2 = geometry.attributes.uv2;
  7710. var groups = geometry.groups;
  7711. var drawRange = geometry.drawRange;
  7712. if (index !== null) {
  7713. // indexed buffer geometry
  7714. if (Array.isArray(material)) {
  7715. for (var i = 0, il = groups.length; i < il; i++) {
  7716. var group = groups[i];
  7717. var groupMaterial = material[group.materialIndex];
  7718. var start = Math.max(group.start, drawRange.start);
  7719. var end = Math.min(group.start + group.count, drawRange.start + drawRange.count);
  7720. for (var j = start, jl = end; j < jl; j += 3) {
  7721. var a = index.getX(j);
  7722. var b = index.getX(j + 1);
  7723. var c = index.getX(j + 2);
  7724. intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c);
  7725. if (intersection) {
  7726. intersection.faceIndex = Math.floor(j / 3); // triangle number in indexed buffer semantics
  7727. intersection.face.materialIndex = group.materialIndex;
  7728. intersects.push(intersection);
  7729. }
  7730. }
  7731. }
  7732. } else {
  7733. var _start = Math.max(0, drawRange.start);
  7734. var _end = Math.min(index.count, drawRange.start + drawRange.count);
  7735. for (var _i = _start, _il = _end; _i < _il; _i += 3) {
  7736. var _a = index.getX(_i);
  7737. var _b = index.getX(_i + 1);
  7738. var _c = index.getX(_i + 2);
  7739. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a, _b, _c);
  7740. if (intersection) {
  7741. intersection.faceIndex = Math.floor(_i / 3); // triangle number in indexed buffer semantics
  7742. intersects.push(intersection);
  7743. }
  7744. }
  7745. }
  7746. } else if (position !== undefined) {
  7747. // non-indexed buffer geometry
  7748. if (Array.isArray(material)) {
  7749. for (var _i2 = 0, _il2 = groups.length; _i2 < _il2; _i2++) {
  7750. var _group = groups[_i2];
  7751. var _groupMaterial = material[_group.materialIndex];
  7752. var _start2 = Math.max(_group.start, drawRange.start);
  7753. var _end2 = Math.min(_group.start + _group.count, drawRange.start + drawRange.count);
  7754. for (var _j = _start2, _jl = _end2; _j < _jl; _j += 3) {
  7755. var _a2 = _j;
  7756. var _b2 = _j + 1;
  7757. var _c2 = _j + 2;
  7758. intersection = checkBufferGeometryIntersection(this, _groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a2, _b2, _c2);
  7759. if (intersection) {
  7760. intersection.faceIndex = Math.floor(_j / 3); // triangle number in non-indexed buffer semantics
  7761. intersection.face.materialIndex = _group.materialIndex;
  7762. intersects.push(intersection);
  7763. }
  7764. }
  7765. }
  7766. } else {
  7767. var _start3 = Math.max(0, drawRange.start);
  7768. var _end3 = Math.min(position.count, drawRange.start + drawRange.count);
  7769. for (var _i3 = _start3, _il3 = _end3; _i3 < _il3; _i3 += 3) {
  7770. var _a3 = _i3;
  7771. var _b3 = _i3 + 1;
  7772. var _c3 = _i3 + 2;
  7773. intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, _a3, _b3, _c3);
  7774. if (intersection) {
  7775. intersection.faceIndex = Math.floor(_i3 / 3); // triangle number in non-indexed buffer semantics
  7776. intersects.push(intersection);
  7777. }
  7778. }
  7779. }
  7780. }
  7781. } else if (geometry.isGeometry) {
  7782. console.error('THREE.Mesh.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  7783. }
  7784. }
  7785. });
  7786. function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) {
  7787. var intersect;
  7788. if (material.side === BackSide) {
  7789. intersect = ray.intersectTriangle(pC, pB, pA, true, point);
  7790. } else {
  7791. intersect = ray.intersectTriangle(pA, pB, pC, material.side !== DoubleSide, point);
  7792. }
  7793. if (intersect === null) return null;
  7794. _intersectionPointWorld.copy(point);
  7795. _intersectionPointWorld.applyMatrix4(object.matrixWorld);
  7796. var distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld);
  7797. if (distance < raycaster.near || distance > raycaster.far) return null;
  7798. return {
  7799. distance: distance,
  7800. point: _intersectionPointWorld.clone(),
  7801. object: object
  7802. };
  7803. }
  7804. function checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c) {
  7805. _vA.fromBufferAttribute(position, a);
  7806. _vB.fromBufferAttribute(position, b);
  7807. _vC.fromBufferAttribute(position, c);
  7808. var morphInfluences = object.morphTargetInfluences;
  7809. if (material.morphTargets && morphPosition && morphInfluences) {
  7810. _morphA.set(0, 0, 0);
  7811. _morphB.set(0, 0, 0);
  7812. _morphC.set(0, 0, 0);
  7813. for (var i = 0, il = morphPosition.length; i < il; i++) {
  7814. var influence = morphInfluences[i];
  7815. var morphAttribute = morphPosition[i];
  7816. if (influence === 0) continue;
  7817. _tempA.fromBufferAttribute(morphAttribute, a);
  7818. _tempB.fromBufferAttribute(morphAttribute, b);
  7819. _tempC.fromBufferAttribute(morphAttribute, c);
  7820. if (morphTargetsRelative) {
  7821. _morphA.addScaledVector(_tempA, influence);
  7822. _morphB.addScaledVector(_tempB, influence);
  7823. _morphC.addScaledVector(_tempC, influence);
  7824. } else {
  7825. _morphA.addScaledVector(_tempA.sub(_vA), influence);
  7826. _morphB.addScaledVector(_tempB.sub(_vB), influence);
  7827. _morphC.addScaledVector(_tempC.sub(_vC), influence);
  7828. }
  7829. }
  7830. _vA.add(_morphA);
  7831. _vB.add(_morphB);
  7832. _vC.add(_morphC);
  7833. }
  7834. if (object.isSkinnedMesh) {
  7835. object.boneTransform(a, _vA);
  7836. object.boneTransform(b, _vB);
  7837. object.boneTransform(c, _vC);
  7838. }
  7839. var intersection = checkIntersection(object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
  7840. if (intersection) {
  7841. if (uv) {
  7842. _uvA.fromBufferAttribute(uv, a);
  7843. _uvB.fromBufferAttribute(uv, b);
  7844. _uvC.fromBufferAttribute(uv, c);
  7845. intersection.uv = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7846. }
  7847. if (uv2) {
  7848. _uvA.fromBufferAttribute(uv2, a);
  7849. _uvB.fromBufferAttribute(uv2, b);
  7850. _uvC.fromBufferAttribute(uv2, c);
  7851. intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2());
  7852. }
  7853. var face = {
  7854. a: a,
  7855. b: a,
  7856. c: c,
  7857. normal: new Vector3(),
  7858. materialIndex: 0
  7859. };
  7860. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7861. intersection.face = face;
  7862. }
  7863. return intersection;
  7864. }
  7865. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7866. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7867. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7868. var _this;
  7869. if (width === void 0) {
  7870. width = 1;
  7871. }
  7872. if (height === void 0) {
  7873. height = 1;
  7874. }
  7875. if (depth === void 0) {
  7876. depth = 1;
  7877. }
  7878. if (widthSegments === void 0) {
  7879. widthSegments = 1;
  7880. }
  7881. if (heightSegments === void 0) {
  7882. heightSegments = 1;
  7883. }
  7884. if (depthSegments === void 0) {
  7885. depthSegments = 1;
  7886. }
  7887. _this = _BufferGeometry.call(this) || this;
  7888. _this.type = 'BoxGeometry';
  7889. _this.parameters = {
  7890. width: width,
  7891. height: height,
  7892. depth: depth,
  7893. widthSegments: widthSegments,
  7894. heightSegments: heightSegments,
  7895. depthSegments: depthSegments
  7896. };
  7897. var scope = _assertThisInitialized(_this); // segments
  7898. widthSegments = Math.floor(widthSegments);
  7899. heightSegments = Math.floor(heightSegments);
  7900. depthSegments = Math.floor(depthSegments); // buffers
  7901. var indices = [];
  7902. var vertices = [];
  7903. var normals = [];
  7904. var uvs = []; // helper variables
  7905. var numberOfVertices = 0;
  7906. var groupStart = 0; // build each side of the box geometry
  7907. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7908. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7909. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7910. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7911. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7912. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7913. // build geometry
  7914. _this.setIndex(indices);
  7915. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7916. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7917. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7918. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7919. var segmentWidth = width / gridX;
  7920. var segmentHeight = height / gridY;
  7921. var widthHalf = width / 2;
  7922. var heightHalf = height / 2;
  7923. var depthHalf = depth / 2;
  7924. var gridX1 = gridX + 1;
  7925. var gridY1 = gridY + 1;
  7926. var vertexCounter = 0;
  7927. var groupCount = 0;
  7928. var vector = new Vector3(); // generate vertices, normals and uvs
  7929. for (var iy = 0; iy < gridY1; iy++) {
  7930. var y = iy * segmentHeight - heightHalf;
  7931. for (var ix = 0; ix < gridX1; ix++) {
  7932. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7933. vector[u] = x * udir;
  7934. vector[v] = y * vdir;
  7935. vector[w] = depthHalf; // now apply vector to vertex buffer
  7936. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7937. vector[u] = 0;
  7938. vector[v] = 0;
  7939. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7940. normals.push(vector.x, vector.y, vector.z); // uvs
  7941. uvs.push(ix / gridX);
  7942. uvs.push(1 - iy / gridY); // counters
  7943. vertexCounter += 1;
  7944. }
  7945. } // indices
  7946. // 1. you need three indices to draw a single face
  7947. // 2. a single segment consists of two faces
  7948. // 3. so we need to generate six (2*3) indices per segment
  7949. for (var _iy = 0; _iy < gridY; _iy++) {
  7950. for (var _ix = 0; _ix < gridX; _ix++) {
  7951. var a = numberOfVertices + _ix + gridX1 * _iy;
  7952. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7953. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7954. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7955. indices.push(a, b, d);
  7956. indices.push(b, c, d); // increase counter
  7957. groupCount += 6;
  7958. }
  7959. } // add a group to the geometry. this will ensure multi material support
  7960. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7961. groupStart += groupCount; // update total number of vertices
  7962. numberOfVertices += vertexCounter;
  7963. }
  7964. return _this;
  7965. }
  7966. return BoxGeometry;
  7967. }(BufferGeometry);
  7968. /**
  7969. * Uniform Utilities
  7970. */
  7971. function cloneUniforms(src) {
  7972. var dst = {};
  7973. for (var u in src) {
  7974. dst[u] = {};
  7975. for (var p in src[u]) {
  7976. var property = src[u][p];
  7977. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7978. dst[u][p] = property.clone();
  7979. } else if (Array.isArray(property)) {
  7980. dst[u][p] = property.slice();
  7981. } else {
  7982. dst[u][p] = property;
  7983. }
  7984. }
  7985. }
  7986. return dst;
  7987. }
  7988. function mergeUniforms(uniforms) {
  7989. var merged = {};
  7990. for (var u = 0; u < uniforms.length; u++) {
  7991. var tmp = cloneUniforms(uniforms[u]);
  7992. for (var p in tmp) {
  7993. merged[p] = tmp[p];
  7994. }
  7995. }
  7996. return merged;
  7997. } // Legacy
  7998. var UniformsUtils = {
  7999. clone: cloneUniforms,
  8000. merge: mergeUniforms
  8001. };
  8002. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  8003. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  8004. /**
  8005. * parameters = {
  8006. * defines: { "label" : "value" },
  8007. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  8008. *
  8009. * fragmentShader: <string>,
  8010. * vertexShader: <string>,
  8011. *
  8012. * wireframe: <boolean>,
  8013. * wireframeLinewidth: <float>,
  8014. *
  8015. * lights: <bool>,
  8016. *
  8017. * skinning: <bool>,
  8018. * morphTargets: <bool>,
  8019. * morphNormals: <bool>
  8020. * }
  8021. */
  8022. function ShaderMaterial(parameters) {
  8023. Material.call(this);
  8024. this.type = 'ShaderMaterial';
  8025. this.defines = {};
  8026. this.uniforms = {};
  8027. this.vertexShader = default_vertex;
  8028. this.fragmentShader = default_fragment;
  8029. this.linewidth = 1;
  8030. this.wireframe = false;
  8031. this.wireframeLinewidth = 1;
  8032. this.fog = false; // set to use scene fog
  8033. this.lights = false; // set to use scene lights
  8034. this.clipping = false; // set to use user-defined clipping planes
  8035. this.skinning = false; // set to use skinning attribute streams
  8036. this.morphTargets = false; // set to use morph targets
  8037. this.morphNormals = false; // set to use morph normals
  8038. this.extensions = {
  8039. derivatives: false,
  8040. // set to use derivatives
  8041. fragDepth: false,
  8042. // set to use fragment depth values
  8043. drawBuffers: false,
  8044. // set to use draw buffers
  8045. shaderTextureLOD: false // set to use shader texture LOD
  8046. }; // When rendered geometry doesn't include these attributes but the material does,
  8047. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8048. this.defaultAttributeValues = {
  8049. 'color': [1, 1, 1],
  8050. 'uv': [0, 0],
  8051. 'uv2': [0, 0]
  8052. };
  8053. this.index0AttributeName = undefined;
  8054. this.uniformsNeedUpdate = false;
  8055. this.glslVersion = null;
  8056. if (parameters !== undefined) {
  8057. if (parameters.attributes !== undefined) {
  8058. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  8059. }
  8060. this.setValues(parameters);
  8061. }
  8062. }
  8063. ShaderMaterial.prototype = Object.create(Material.prototype);
  8064. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8065. ShaderMaterial.prototype.isShaderMaterial = true;
  8066. ShaderMaterial.prototype.copy = function (source) {
  8067. Material.prototype.copy.call(this, source);
  8068. this.fragmentShader = source.fragmentShader;
  8069. this.vertexShader = source.vertexShader;
  8070. this.uniforms = cloneUniforms(source.uniforms);
  8071. this.defines = Object.assign({}, source.defines);
  8072. this.wireframe = source.wireframe;
  8073. this.wireframeLinewidth = source.wireframeLinewidth;
  8074. this.lights = source.lights;
  8075. this.clipping = source.clipping;
  8076. this.skinning = source.skinning;
  8077. this.morphTargets = source.morphTargets;
  8078. this.morphNormals = source.morphNormals;
  8079. this.extensions = Object.assign({}, source.extensions);
  8080. this.glslVersion = source.glslVersion;
  8081. return this;
  8082. };
  8083. ShaderMaterial.prototype.toJSON = function (meta) {
  8084. var data = Material.prototype.toJSON.call(this, meta);
  8085. data.glslVersion = this.glslVersion;
  8086. data.uniforms = {};
  8087. for (var name in this.uniforms) {
  8088. var uniform = this.uniforms[name];
  8089. var value = uniform.value;
  8090. if (value && value.isTexture) {
  8091. data.uniforms[name] = {
  8092. type: 't',
  8093. value: value.toJSON(meta).uuid
  8094. };
  8095. } else if (value && value.isColor) {
  8096. data.uniforms[name] = {
  8097. type: 'c',
  8098. value: value.getHex()
  8099. };
  8100. } else if (value && value.isVector2) {
  8101. data.uniforms[name] = {
  8102. type: 'v2',
  8103. value: value.toArray()
  8104. };
  8105. } else if (value && value.isVector3) {
  8106. data.uniforms[name] = {
  8107. type: 'v3',
  8108. value: value.toArray()
  8109. };
  8110. } else if (value && value.isVector4) {
  8111. data.uniforms[name] = {
  8112. type: 'v4',
  8113. value: value.toArray()
  8114. };
  8115. } else if (value && value.isMatrix3) {
  8116. data.uniforms[name] = {
  8117. type: 'm3',
  8118. value: value.toArray()
  8119. };
  8120. } else if (value && value.isMatrix4) {
  8121. data.uniforms[name] = {
  8122. type: 'm4',
  8123. value: value.toArray()
  8124. };
  8125. } else {
  8126. data.uniforms[name] = {
  8127. value: value
  8128. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8129. }
  8130. }
  8131. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  8132. data.vertexShader = this.vertexShader;
  8133. data.fragmentShader = this.fragmentShader;
  8134. var extensions = {};
  8135. for (var key in this.extensions) {
  8136. if (this.extensions[key] === true) extensions[key] = true;
  8137. }
  8138. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  8139. return data;
  8140. };
  8141. function Camera() {
  8142. Object3D.call(this);
  8143. this.type = 'Camera';
  8144. this.matrixWorldInverse = new Matrix4();
  8145. this.projectionMatrix = new Matrix4();
  8146. this.projectionMatrixInverse = new Matrix4();
  8147. }
  8148. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  8149. constructor: Camera,
  8150. isCamera: true,
  8151. copy: function copy(source, recursive) {
  8152. Object3D.prototype.copy.call(this, source, recursive);
  8153. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  8154. this.projectionMatrix.copy(source.projectionMatrix);
  8155. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  8156. return this;
  8157. },
  8158. getWorldDirection: function getWorldDirection(target) {
  8159. if (target === undefined) {
  8160. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  8161. target = new Vector3();
  8162. }
  8163. this.updateWorldMatrix(true, false);
  8164. var e = this.matrixWorld.elements;
  8165. return target.set(-e[8], -e[9], -e[10]).normalize();
  8166. },
  8167. updateMatrixWorld: function updateMatrixWorld(force) {
  8168. Object3D.prototype.updateMatrixWorld.call(this, force);
  8169. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8170. },
  8171. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  8172. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  8173. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8174. },
  8175. clone: function clone() {
  8176. return new this.constructor().copy(this);
  8177. }
  8178. });
  8179. function PerspectiveCamera(fov, aspect, near, far) {
  8180. if (fov === void 0) {
  8181. fov = 50;
  8182. }
  8183. if (aspect === void 0) {
  8184. aspect = 1;
  8185. }
  8186. if (near === void 0) {
  8187. near = 0.1;
  8188. }
  8189. if (far === void 0) {
  8190. far = 2000;
  8191. }
  8192. Camera.call(this);
  8193. this.type = 'PerspectiveCamera';
  8194. this.fov = fov;
  8195. this.zoom = 1;
  8196. this.near = near;
  8197. this.far = far;
  8198. this.focus = 10;
  8199. this.aspect = aspect;
  8200. this.view = null;
  8201. this.filmGauge = 35; // width of the film (default in millimeters)
  8202. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8203. this.updateProjectionMatrix();
  8204. }
  8205. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  8206. constructor: PerspectiveCamera,
  8207. isPerspectiveCamera: true,
  8208. copy: function copy(source, recursive) {
  8209. Camera.prototype.copy.call(this, source, recursive);
  8210. this.fov = source.fov;
  8211. this.zoom = source.zoom;
  8212. this.near = source.near;
  8213. this.far = source.far;
  8214. this.focus = source.focus;
  8215. this.aspect = source.aspect;
  8216. this.view = source.view === null ? null : Object.assign({}, source.view);
  8217. this.filmGauge = source.filmGauge;
  8218. this.filmOffset = source.filmOffset;
  8219. return this;
  8220. },
  8221. /**
  8222. * Sets the FOV by focal length in respect to the current .filmGauge.
  8223. *
  8224. * The default film gauge is 35, so that the focal length can be specified for
  8225. * a 35mm (full frame) camera.
  8226. *
  8227. * Values for focal length and film gauge must have the same unit.
  8228. */
  8229. setFocalLength: function setFocalLength(focalLength) {
  8230. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  8231. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8232. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  8233. this.updateProjectionMatrix();
  8234. },
  8235. /**
  8236. * Calculates the focal length from the current .fov and .filmGauge.
  8237. */
  8238. getFocalLength: function getFocalLength() {
  8239. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  8240. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8241. },
  8242. getEffectiveFOV: function getEffectiveFOV() {
  8243. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  8244. },
  8245. getFilmWidth: function getFilmWidth() {
  8246. // film not completely covered in portrait format (aspect < 1)
  8247. return this.filmGauge * Math.min(this.aspect, 1);
  8248. },
  8249. getFilmHeight: function getFilmHeight() {
  8250. // film not completely covered in landscape format (aspect > 1)
  8251. return this.filmGauge / Math.max(this.aspect, 1);
  8252. },
  8253. /**
  8254. * Sets an offset in a larger frustum. This is useful for multi-window or
  8255. * multi-monitor/multi-machine setups.
  8256. *
  8257. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8258. * the monitors are in grid like this
  8259. *
  8260. * +---+---+---+
  8261. * | A | B | C |
  8262. * +---+---+---+
  8263. * | D | E | F |
  8264. * +---+---+---+
  8265. *
  8266. * then for each monitor you would call it like this
  8267. *
  8268. * const w = 1920;
  8269. * const h = 1080;
  8270. * const fullWidth = w * 3;
  8271. * const fullHeight = h * 2;
  8272. *
  8273. * --A--
  8274. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8275. * --B--
  8276. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8277. * --C--
  8278. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8279. * --D--
  8280. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8281. * --E--
  8282. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8283. * --F--
  8284. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8285. *
  8286. * Note there is no reason monitors have to be the same size or in a grid.
  8287. */
  8288. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  8289. this.aspect = fullWidth / fullHeight;
  8290. if (this.view === null) {
  8291. this.view = {
  8292. enabled: true,
  8293. fullWidth: 1,
  8294. fullHeight: 1,
  8295. offsetX: 0,
  8296. offsetY: 0,
  8297. width: 1,
  8298. height: 1
  8299. };
  8300. }
  8301. this.view.enabled = true;
  8302. this.view.fullWidth = fullWidth;
  8303. this.view.fullHeight = fullHeight;
  8304. this.view.offsetX = x;
  8305. this.view.offsetY = y;
  8306. this.view.width = width;
  8307. this.view.height = height;
  8308. this.updateProjectionMatrix();
  8309. },
  8310. clearViewOffset: function clearViewOffset() {
  8311. if (this.view !== null) {
  8312. this.view.enabled = false;
  8313. }
  8314. this.updateProjectionMatrix();
  8315. },
  8316. updateProjectionMatrix: function updateProjectionMatrix() {
  8317. var near = this.near;
  8318. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  8319. var height = 2 * top;
  8320. var width = this.aspect * height;
  8321. var left = -0.5 * width;
  8322. var view = this.view;
  8323. if (this.view !== null && this.view.enabled) {
  8324. var fullWidth = view.fullWidth,
  8325. fullHeight = view.fullHeight;
  8326. left += view.offsetX * width / fullWidth;
  8327. top -= view.offsetY * height / fullHeight;
  8328. width *= view.width / fullWidth;
  8329. height *= view.height / fullHeight;
  8330. }
  8331. var skew = this.filmOffset;
  8332. if (skew !== 0) left += near * skew / this.getFilmWidth();
  8333. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  8334. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  8335. },
  8336. toJSON: function toJSON(meta) {
  8337. var data = Object3D.prototype.toJSON.call(this, meta);
  8338. data.object.fov = this.fov;
  8339. data.object.zoom = this.zoom;
  8340. data.object.near = this.near;
  8341. data.object.far = this.far;
  8342. data.object.focus = this.focus;
  8343. data.object.aspect = this.aspect;
  8344. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  8345. data.object.filmGauge = this.filmGauge;
  8346. data.object.filmOffset = this.filmOffset;
  8347. return data;
  8348. }
  8349. });
  8350. var fov = 90,
  8351. aspect = 1;
  8352. function CubeCamera(near, far, renderTarget) {
  8353. Object3D.call(this);
  8354. this.type = 'CubeCamera';
  8355. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  8356. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  8357. return;
  8358. }
  8359. this.renderTarget = renderTarget;
  8360. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  8361. cameraPX.layers = this.layers;
  8362. cameraPX.up.set(0, -1, 0);
  8363. cameraPX.lookAt(new Vector3(1, 0, 0));
  8364. this.add(cameraPX);
  8365. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  8366. cameraNX.layers = this.layers;
  8367. cameraNX.up.set(0, -1, 0);
  8368. cameraNX.lookAt(new Vector3(-1, 0, 0));
  8369. this.add(cameraNX);
  8370. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  8371. cameraPY.layers = this.layers;
  8372. cameraPY.up.set(0, 0, 1);
  8373. cameraPY.lookAt(new Vector3(0, 1, 0));
  8374. this.add(cameraPY);
  8375. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  8376. cameraNY.layers = this.layers;
  8377. cameraNY.up.set(0, 0, -1);
  8378. cameraNY.lookAt(new Vector3(0, -1, 0));
  8379. this.add(cameraNY);
  8380. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  8381. cameraPZ.layers = this.layers;
  8382. cameraPZ.up.set(0, -1, 0);
  8383. cameraPZ.lookAt(new Vector3(0, 0, 1));
  8384. this.add(cameraPZ);
  8385. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  8386. cameraNZ.layers = this.layers;
  8387. cameraNZ.up.set(0, -1, 0);
  8388. cameraNZ.lookAt(new Vector3(0, 0, -1));
  8389. this.add(cameraNZ);
  8390. this.update = function (renderer, scene) {
  8391. if (this.parent === null) this.updateMatrixWorld();
  8392. var currentXrEnabled = renderer.xr.enabled;
  8393. var currentRenderTarget = renderer.getRenderTarget();
  8394. renderer.xr.enabled = false;
  8395. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8396. renderTarget.texture.generateMipmaps = false;
  8397. renderer.setRenderTarget(renderTarget, 0);
  8398. renderer.render(scene, cameraPX);
  8399. renderer.setRenderTarget(renderTarget, 1);
  8400. renderer.render(scene, cameraNX);
  8401. renderer.setRenderTarget(renderTarget, 2);
  8402. renderer.render(scene, cameraPY);
  8403. renderer.setRenderTarget(renderTarget, 3);
  8404. renderer.render(scene, cameraNY);
  8405. renderer.setRenderTarget(renderTarget, 4);
  8406. renderer.render(scene, cameraPZ);
  8407. renderTarget.texture.generateMipmaps = generateMipmaps;
  8408. renderer.setRenderTarget(renderTarget, 5);
  8409. renderer.render(scene, cameraNZ);
  8410. renderer.setRenderTarget(currentRenderTarget);
  8411. renderer.xr.enabled = currentXrEnabled;
  8412. };
  8413. }
  8414. CubeCamera.prototype = Object.create(Object3D.prototype);
  8415. CubeCamera.prototype.constructor = CubeCamera;
  8416. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  8417. images = images !== undefined ? images : [];
  8418. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  8419. format = format !== undefined ? format : RGBFormat;
  8420. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8421. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  8422. //
  8423. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  8424. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  8425. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  8426. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  8427. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  8428. // when using WebGLCubeRenderTarget.texture as a cube texture.
  8429. this._needsFlipEnvMap = true;
  8430. }
  8431. CubeTexture.prototype = Object.create(Texture.prototype);
  8432. CubeTexture.prototype.constructor = CubeTexture;
  8433. CubeTexture.prototype.isCubeTexture = true;
  8434. Object.defineProperty(CubeTexture.prototype, 'images', {
  8435. get: function get() {
  8436. return this.image;
  8437. },
  8438. set: function set(value) {
  8439. this.image = value;
  8440. }
  8441. });
  8442. var WebGLCubeRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  8443. _inheritsLoose(WebGLCubeRenderTarget, _WebGLRenderTarget);
  8444. function WebGLCubeRenderTarget(size, options, dummy) {
  8445. var _this;
  8446. if (Number.isInteger(options)) {
  8447. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  8448. options = dummy;
  8449. }
  8450. _this = _WebGLRenderTarget.call(this, size, size, options) || this;
  8451. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLCubeRenderTarget', {
  8452. value: true
  8453. });
  8454. options = options || {};
  8455. _this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  8456. _this.texture._needsFlipEnvMap = false;
  8457. return _this;
  8458. }
  8459. var _proto = WebGLCubeRenderTarget.prototype;
  8460. _proto.fromEquirectangularTexture = function fromEquirectangularTexture(renderer, texture) {
  8461. this.texture.type = texture.type;
  8462. this.texture.format = RGBAFormat; // see #18859
  8463. this.texture.encoding = texture.encoding;
  8464. this.texture.generateMipmaps = texture.generateMipmaps;
  8465. this.texture.minFilter = texture.minFilter;
  8466. this.texture.magFilter = texture.magFilter;
  8467. var shader = {
  8468. uniforms: {
  8469. tEquirect: {
  8470. value: null
  8471. }
  8472. },
  8473. vertexShader:
  8474. /* glsl */
  8475. "\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",
  8476. fragmentShader:
  8477. /* glsl */
  8478. "\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"
  8479. };
  8480. var geometry = new BoxGeometry(5, 5, 5);
  8481. var material = new ShaderMaterial({
  8482. name: 'CubemapFromEquirect',
  8483. uniforms: cloneUniforms(shader.uniforms),
  8484. vertexShader: shader.vertexShader,
  8485. fragmentShader: shader.fragmentShader,
  8486. side: BackSide,
  8487. blending: NoBlending
  8488. });
  8489. material.uniforms.tEquirect.value = texture;
  8490. var mesh = new Mesh(geometry, material);
  8491. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8492. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8493. var camera = new CubeCamera(1, 10, this);
  8494. camera.update(renderer, mesh);
  8495. texture.minFilter = currentMinFilter;
  8496. mesh.geometry.dispose();
  8497. mesh.material.dispose();
  8498. return this;
  8499. };
  8500. _proto.clear = function clear(renderer, color, depth, stencil) {
  8501. var currentRenderTarget = renderer.getRenderTarget();
  8502. for (var i = 0; i < 6; i++) {
  8503. renderer.setRenderTarget(this, i);
  8504. renderer.clear(color, depth, stencil);
  8505. }
  8506. renderer.setRenderTarget(currentRenderTarget);
  8507. };
  8508. return WebGLCubeRenderTarget;
  8509. }(WebGLRenderTarget);
  8510. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8511. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8512. this.image = {
  8513. data: data || null,
  8514. width: width || 1,
  8515. height: height || 1
  8516. };
  8517. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8518. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8519. this.generateMipmaps = false;
  8520. this.flipY = false;
  8521. this.unpackAlignment = 1;
  8522. this.needsUpdate = true;
  8523. }
  8524. DataTexture.prototype = Object.create(Texture.prototype);
  8525. DataTexture.prototype.constructor = DataTexture;
  8526. DataTexture.prototype.isDataTexture = true;
  8527. var _sphere$1 = /*@__PURE__*/new Sphere();
  8528. var _vector$5 = /*@__PURE__*/new Vector3();
  8529. var Frustum = /*#__PURE__*/function () {
  8530. function Frustum(p0, p1, p2, p3, p4, p5) {
  8531. this.planes = [p0 !== undefined ? p0 : new Plane(), p1 !== undefined ? p1 : new Plane(), p2 !== undefined ? p2 : new Plane(), p3 !== undefined ? p3 : new Plane(), p4 !== undefined ? p4 : new Plane(), p5 !== undefined ? p5 : new Plane()];
  8532. }
  8533. var _proto = Frustum.prototype;
  8534. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8535. var planes = this.planes;
  8536. planes[0].copy(p0);
  8537. planes[1].copy(p1);
  8538. planes[2].copy(p2);
  8539. planes[3].copy(p3);
  8540. planes[4].copy(p4);
  8541. planes[5].copy(p5);
  8542. return this;
  8543. };
  8544. _proto.clone = function clone() {
  8545. return new this.constructor().copy(this);
  8546. };
  8547. _proto.copy = function copy(frustum) {
  8548. var planes = this.planes;
  8549. for (var i = 0; i < 6; i++) {
  8550. planes[i].copy(frustum.planes[i]);
  8551. }
  8552. return this;
  8553. };
  8554. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8555. var planes = this.planes;
  8556. var me = m.elements;
  8557. var me0 = me[0],
  8558. me1 = me[1],
  8559. me2 = me[2],
  8560. me3 = me[3];
  8561. var me4 = me[4],
  8562. me5 = me[5],
  8563. me6 = me[6],
  8564. me7 = me[7];
  8565. var me8 = me[8],
  8566. me9 = me[9],
  8567. me10 = me[10],
  8568. me11 = me[11];
  8569. var me12 = me[12],
  8570. me13 = me[13],
  8571. me14 = me[14],
  8572. me15 = me[15];
  8573. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8574. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8575. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8576. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8577. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8578. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8579. return this;
  8580. };
  8581. _proto.intersectsObject = function intersectsObject(object) {
  8582. var geometry = object.geometry;
  8583. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8584. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8585. return this.intersectsSphere(_sphere$1);
  8586. };
  8587. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8588. _sphere$1.center.set(0, 0, 0);
  8589. _sphere$1.radius = 0.7071067811865476;
  8590. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8591. return this.intersectsSphere(_sphere$1);
  8592. };
  8593. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8594. var planes = this.planes;
  8595. var center = sphere.center;
  8596. var negRadius = -sphere.radius;
  8597. for (var i = 0; i < 6; i++) {
  8598. var distance = planes[i].distanceToPoint(center);
  8599. if (distance < negRadius) {
  8600. return false;
  8601. }
  8602. }
  8603. return true;
  8604. };
  8605. _proto.intersectsBox = function intersectsBox(box) {
  8606. var planes = this.planes;
  8607. for (var i = 0; i < 6; i++) {
  8608. var plane = planes[i]; // corner at max distance
  8609. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8610. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8611. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8612. if (plane.distanceToPoint(_vector$5) < 0) {
  8613. return false;
  8614. }
  8615. }
  8616. return true;
  8617. };
  8618. _proto.containsPoint = function containsPoint(point) {
  8619. var planes = this.planes;
  8620. for (var i = 0; i < 6; i++) {
  8621. if (planes[i].distanceToPoint(point) < 0) {
  8622. return false;
  8623. }
  8624. }
  8625. return true;
  8626. };
  8627. return Frustum;
  8628. }();
  8629. function WebGLAnimation() {
  8630. var context = null;
  8631. var isAnimating = false;
  8632. var animationLoop = null;
  8633. var requestId = null;
  8634. function onAnimationFrame(time, frame) {
  8635. animationLoop(time, frame);
  8636. requestId = context.requestAnimationFrame(onAnimationFrame);
  8637. }
  8638. return {
  8639. start: function start() {
  8640. if (isAnimating === true) return;
  8641. if (animationLoop === null) return;
  8642. requestId = context.requestAnimationFrame(onAnimationFrame);
  8643. isAnimating = true;
  8644. },
  8645. stop: function stop() {
  8646. context.cancelAnimationFrame(requestId);
  8647. isAnimating = false;
  8648. },
  8649. setAnimationLoop: function setAnimationLoop(callback) {
  8650. animationLoop = callback;
  8651. },
  8652. setContext: function setContext(value) {
  8653. context = value;
  8654. }
  8655. };
  8656. }
  8657. function WebGLAttributes(gl, capabilities) {
  8658. var isWebGL2 = capabilities.isWebGL2;
  8659. var buffers = new WeakMap();
  8660. function createBuffer(attribute, bufferType) {
  8661. var array = attribute.array;
  8662. var usage = attribute.usage;
  8663. var buffer = gl.createBuffer();
  8664. gl.bindBuffer(bufferType, buffer);
  8665. gl.bufferData(bufferType, array, usage);
  8666. attribute.onUploadCallback();
  8667. var type = 5126;
  8668. if (array instanceof Float32Array) {
  8669. type = 5126;
  8670. } else if (array instanceof Float64Array) {
  8671. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8672. } else if (array instanceof Uint16Array) {
  8673. if (attribute.isFloat16BufferAttribute) {
  8674. if (isWebGL2) {
  8675. type = 5131;
  8676. } else {
  8677. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8678. }
  8679. } else {
  8680. type = 5123;
  8681. }
  8682. } else if (array instanceof Int16Array) {
  8683. type = 5122;
  8684. } else if (array instanceof Uint32Array) {
  8685. type = 5125;
  8686. } else if (array instanceof Int32Array) {
  8687. type = 5124;
  8688. } else if (array instanceof Int8Array) {
  8689. type = 5120;
  8690. } else if (array instanceof Uint8Array) {
  8691. type = 5121;
  8692. }
  8693. return {
  8694. buffer: buffer,
  8695. type: type,
  8696. bytesPerElement: array.BYTES_PER_ELEMENT,
  8697. version: attribute.version
  8698. };
  8699. }
  8700. function updateBuffer(buffer, attribute, bufferType) {
  8701. var array = attribute.array;
  8702. var updateRange = attribute.updateRange;
  8703. gl.bindBuffer(bufferType, buffer);
  8704. if (updateRange.count === -1) {
  8705. // Not using update ranges
  8706. gl.bufferSubData(bufferType, 0, array);
  8707. } else {
  8708. if (isWebGL2) {
  8709. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8710. } else {
  8711. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8712. }
  8713. updateRange.count = -1; // reset range
  8714. }
  8715. } //
  8716. function get(attribute) {
  8717. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8718. return buffers.get(attribute);
  8719. }
  8720. function remove(attribute) {
  8721. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8722. var data = buffers.get(attribute);
  8723. if (data) {
  8724. gl.deleteBuffer(data.buffer);
  8725. buffers.delete(attribute);
  8726. }
  8727. }
  8728. function update(attribute, bufferType) {
  8729. if (attribute.isGLBufferAttribute) {
  8730. var cached = buffers.get(attribute);
  8731. if (!cached || cached.version < attribute.version) {
  8732. buffers.set(attribute, {
  8733. buffer: attribute.buffer,
  8734. type: attribute.type,
  8735. bytesPerElement: attribute.elementSize,
  8736. version: attribute.version
  8737. });
  8738. }
  8739. return;
  8740. }
  8741. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8742. var data = buffers.get(attribute);
  8743. if (data === undefined) {
  8744. buffers.set(attribute, createBuffer(attribute, bufferType));
  8745. } else if (data.version < attribute.version) {
  8746. updateBuffer(data.buffer, attribute, bufferType);
  8747. data.version = attribute.version;
  8748. }
  8749. }
  8750. return {
  8751. get: get,
  8752. remove: remove,
  8753. update: update
  8754. };
  8755. }
  8756. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8757. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8758. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8759. var _this;
  8760. if (width === void 0) {
  8761. width = 1;
  8762. }
  8763. if (height === void 0) {
  8764. height = 1;
  8765. }
  8766. if (widthSegments === void 0) {
  8767. widthSegments = 1;
  8768. }
  8769. if (heightSegments === void 0) {
  8770. heightSegments = 1;
  8771. }
  8772. _this = _BufferGeometry.call(this) || this;
  8773. _this.type = 'PlaneGeometry';
  8774. _this.parameters = {
  8775. width: width,
  8776. height: height,
  8777. widthSegments: widthSegments,
  8778. heightSegments: heightSegments
  8779. };
  8780. var width_half = width / 2;
  8781. var height_half = height / 2;
  8782. var gridX = Math.floor(widthSegments);
  8783. var gridY = Math.floor(heightSegments);
  8784. var gridX1 = gridX + 1;
  8785. var gridY1 = gridY + 1;
  8786. var segment_width = width / gridX;
  8787. var segment_height = height / gridY; //
  8788. var indices = [];
  8789. var vertices = [];
  8790. var normals = [];
  8791. var uvs = [];
  8792. for (var iy = 0; iy < gridY1; iy++) {
  8793. var y = iy * segment_height - height_half;
  8794. for (var ix = 0; ix < gridX1; ix++) {
  8795. var x = ix * segment_width - width_half;
  8796. vertices.push(x, -y, 0);
  8797. normals.push(0, 0, 1);
  8798. uvs.push(ix / gridX);
  8799. uvs.push(1 - iy / gridY);
  8800. }
  8801. }
  8802. for (var _iy = 0; _iy < gridY; _iy++) {
  8803. for (var _ix = 0; _ix < gridX; _ix++) {
  8804. var a = _ix + gridX1 * _iy;
  8805. var b = _ix + gridX1 * (_iy + 1);
  8806. var c = _ix + 1 + gridX1 * (_iy + 1);
  8807. var d = _ix + 1 + gridX1 * _iy;
  8808. indices.push(a, b, d);
  8809. indices.push(b, c, d);
  8810. }
  8811. }
  8812. _this.setIndex(indices);
  8813. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8814. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8815. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8816. return _this;
  8817. }
  8818. return PlaneGeometry;
  8819. }(BufferGeometry);
  8820. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8821. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8822. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8823. 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";
  8824. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8825. var begin_vertex = "vec3 transformed = vec3( position );";
  8826. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8827. 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";
  8828. 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";
  8829. 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";
  8830. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8831. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8832. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8833. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8834. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8835. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8836. 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";
  8837. 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}";
  8838. 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";
  8839. 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";
  8840. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8841. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8842. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8843. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8844. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8845. 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}";
  8846. 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";
  8847. 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";
  8848. 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";
  8849. 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";
  8850. 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";
  8851. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8852. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8853. 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";
  8854. 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";
  8855. 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}";
  8856. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8857. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8858. 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";
  8859. 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";
  8860. 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";
  8861. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8862. 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)";
  8863. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8864. 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)";
  8865. 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";
  8866. 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}";
  8867. 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";
  8868. 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";
  8869. 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";
  8870. 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";
  8871. 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";
  8872. 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";
  8873. 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";
  8874. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8875. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8876. 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";
  8877. 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";
  8878. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8879. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8880. 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";
  8881. 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";
  8882. 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";
  8883. var normal_fragment_begin = "float faceDirection = float( gl_FrontFacing ) * 2.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;";
  8884. 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";
  8885. 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\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= faceDirection;\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8886. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8887. 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";
  8888. 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";
  8889. 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}";
  8890. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8891. 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;";
  8892. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8893. 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";
  8894. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8895. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8896. 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";
  8897. 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";
  8898. 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";
  8899. 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}";
  8900. 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";
  8901. 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";
  8902. 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";
  8903. 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";
  8904. 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";
  8905. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8906. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8907. 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; }";
  8908. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8909. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8910. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8911. 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";
  8912. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8913. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8914. 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";
  8915. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8916. 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";
  8917. 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}";
  8918. 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}";
  8919. 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}";
  8920. 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}";
  8921. 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}";
  8922. 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}";
  8923. 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}";
  8924. 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}";
  8925. 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}";
  8926. 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}";
  8927. 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}";
  8928. 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}";
  8929. 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}";
  8930. 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}";
  8931. 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}";
  8932. 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}";
  8933. 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}";
  8934. 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}";
  8935. 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}";
  8936. 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}";
  8937. 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}";
  8938. 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}";
  8939. 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}";
  8940. 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}";
  8941. 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}";
  8942. 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}";
  8943. 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}";
  8944. 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}";
  8945. 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}";
  8946. 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}";
  8947. 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}";
  8948. 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}";
  8949. var ShaderChunk = {
  8950. alphamap_fragment: alphamap_fragment,
  8951. alphamap_pars_fragment: alphamap_pars_fragment,
  8952. alphatest_fragment: alphatest_fragment,
  8953. aomap_fragment: aomap_fragment,
  8954. aomap_pars_fragment: aomap_pars_fragment,
  8955. begin_vertex: begin_vertex,
  8956. beginnormal_vertex: beginnormal_vertex,
  8957. bsdfs: bsdfs,
  8958. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8959. clipping_planes_fragment: clipping_planes_fragment,
  8960. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8961. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8962. clipping_planes_vertex: clipping_planes_vertex,
  8963. color_fragment: color_fragment,
  8964. color_pars_fragment: color_pars_fragment,
  8965. color_pars_vertex: color_pars_vertex,
  8966. color_vertex: color_vertex,
  8967. common: common,
  8968. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8969. defaultnormal_vertex: defaultnormal_vertex,
  8970. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8971. displacementmap_vertex: displacementmap_vertex,
  8972. emissivemap_fragment: emissivemap_fragment,
  8973. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8974. encodings_fragment: encodings_fragment,
  8975. encodings_pars_fragment: encodings_pars_fragment,
  8976. envmap_fragment: envmap_fragment,
  8977. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8978. envmap_pars_fragment: envmap_pars_fragment,
  8979. envmap_pars_vertex: envmap_pars_vertex,
  8980. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8981. envmap_vertex: envmap_vertex,
  8982. fog_vertex: fog_vertex,
  8983. fog_pars_vertex: fog_pars_vertex,
  8984. fog_fragment: fog_fragment,
  8985. fog_pars_fragment: fog_pars_fragment,
  8986. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8987. lightmap_fragment: lightmap_fragment,
  8988. lightmap_pars_fragment: lightmap_pars_fragment,
  8989. lights_lambert_vertex: lights_lambert_vertex,
  8990. lights_pars_begin: lights_pars_begin,
  8991. lights_toon_fragment: lights_toon_fragment,
  8992. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8993. lights_phong_fragment: lights_phong_fragment,
  8994. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8995. lights_physical_fragment: lights_physical_fragment,
  8996. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8997. lights_fragment_begin: lights_fragment_begin,
  8998. lights_fragment_maps: lights_fragment_maps,
  8999. lights_fragment_end: lights_fragment_end,
  9000. logdepthbuf_fragment: logdepthbuf_fragment,
  9001. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  9002. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  9003. logdepthbuf_vertex: logdepthbuf_vertex,
  9004. map_fragment: map_fragment,
  9005. map_pars_fragment: map_pars_fragment,
  9006. map_particle_fragment: map_particle_fragment,
  9007. map_particle_pars_fragment: map_particle_pars_fragment,
  9008. metalnessmap_fragment: metalnessmap_fragment,
  9009. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9010. morphnormal_vertex: morphnormal_vertex,
  9011. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9012. morphtarget_vertex: morphtarget_vertex,
  9013. normal_fragment_begin: normal_fragment_begin,
  9014. normal_fragment_maps: normal_fragment_maps,
  9015. normalmap_pars_fragment: normalmap_pars_fragment,
  9016. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9017. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9018. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9019. packing: packing,
  9020. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9021. project_vertex: project_vertex,
  9022. dithering_fragment: dithering_fragment,
  9023. dithering_pars_fragment: dithering_pars_fragment,
  9024. roughnessmap_fragment: roughnessmap_fragment,
  9025. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9026. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9027. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9028. shadowmap_vertex: shadowmap_vertex,
  9029. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9030. skinbase_vertex: skinbase_vertex,
  9031. skinning_pars_vertex: skinning_pars_vertex,
  9032. skinning_vertex: skinning_vertex,
  9033. skinnormal_vertex: skinnormal_vertex,
  9034. specularmap_fragment: specularmap_fragment,
  9035. specularmap_pars_fragment: specularmap_pars_fragment,
  9036. tonemapping_fragment: tonemapping_fragment,
  9037. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9038. transmissionmap_fragment: transmissionmap_fragment,
  9039. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  9040. uv_pars_fragment: uv_pars_fragment,
  9041. uv_pars_vertex: uv_pars_vertex,
  9042. uv_vertex: uv_vertex,
  9043. uv2_pars_fragment: uv2_pars_fragment,
  9044. uv2_pars_vertex: uv2_pars_vertex,
  9045. uv2_vertex: uv2_vertex,
  9046. worldpos_vertex: worldpos_vertex,
  9047. background_frag: background_frag,
  9048. background_vert: background_vert,
  9049. cube_frag: cube_frag,
  9050. cube_vert: cube_vert,
  9051. depth_frag: depth_frag,
  9052. depth_vert: depth_vert,
  9053. distanceRGBA_frag: distanceRGBA_frag,
  9054. distanceRGBA_vert: distanceRGBA_vert,
  9055. equirect_frag: equirect_frag,
  9056. equirect_vert: equirect_vert,
  9057. linedashed_frag: linedashed_frag,
  9058. linedashed_vert: linedashed_vert,
  9059. meshbasic_frag: meshbasic_frag,
  9060. meshbasic_vert: meshbasic_vert,
  9061. meshlambert_frag: meshlambert_frag,
  9062. meshlambert_vert: meshlambert_vert,
  9063. meshmatcap_frag: meshmatcap_frag,
  9064. meshmatcap_vert: meshmatcap_vert,
  9065. meshtoon_frag: meshtoon_frag,
  9066. meshtoon_vert: meshtoon_vert,
  9067. meshphong_frag: meshphong_frag,
  9068. meshphong_vert: meshphong_vert,
  9069. meshphysical_frag: meshphysical_frag,
  9070. meshphysical_vert: meshphysical_vert,
  9071. normal_frag: normal_frag,
  9072. normal_vert: normal_vert,
  9073. points_frag: points_frag,
  9074. points_vert: points_vert,
  9075. shadow_frag: shadow_frag,
  9076. shadow_vert: shadow_vert,
  9077. sprite_frag: sprite_frag,
  9078. sprite_vert: sprite_vert
  9079. };
  9080. /**
  9081. * Uniforms library for shared webgl shaders
  9082. */
  9083. var UniformsLib = {
  9084. common: {
  9085. diffuse: {
  9086. value: new Color(0xeeeeee)
  9087. },
  9088. opacity: {
  9089. value: 1.0
  9090. },
  9091. map: {
  9092. value: null
  9093. },
  9094. uvTransform: {
  9095. value: new Matrix3()
  9096. },
  9097. uv2Transform: {
  9098. value: new Matrix3()
  9099. },
  9100. alphaMap: {
  9101. value: null
  9102. }
  9103. },
  9104. specularmap: {
  9105. specularMap: {
  9106. value: null
  9107. }
  9108. },
  9109. envmap: {
  9110. envMap: {
  9111. value: null
  9112. },
  9113. flipEnvMap: {
  9114. value: -1
  9115. },
  9116. reflectivity: {
  9117. value: 1.0
  9118. },
  9119. refractionRatio: {
  9120. value: 0.98
  9121. },
  9122. maxMipLevel: {
  9123. value: 0
  9124. }
  9125. },
  9126. aomap: {
  9127. aoMap: {
  9128. value: null
  9129. },
  9130. aoMapIntensity: {
  9131. value: 1
  9132. }
  9133. },
  9134. lightmap: {
  9135. lightMap: {
  9136. value: null
  9137. },
  9138. lightMapIntensity: {
  9139. value: 1
  9140. }
  9141. },
  9142. emissivemap: {
  9143. emissiveMap: {
  9144. value: null
  9145. }
  9146. },
  9147. bumpmap: {
  9148. bumpMap: {
  9149. value: null
  9150. },
  9151. bumpScale: {
  9152. value: 1
  9153. }
  9154. },
  9155. normalmap: {
  9156. normalMap: {
  9157. value: null
  9158. },
  9159. normalScale: {
  9160. value: new Vector2(1, 1)
  9161. }
  9162. },
  9163. displacementmap: {
  9164. displacementMap: {
  9165. value: null
  9166. },
  9167. displacementScale: {
  9168. value: 1
  9169. },
  9170. displacementBias: {
  9171. value: 0
  9172. }
  9173. },
  9174. roughnessmap: {
  9175. roughnessMap: {
  9176. value: null
  9177. }
  9178. },
  9179. metalnessmap: {
  9180. metalnessMap: {
  9181. value: null
  9182. }
  9183. },
  9184. gradientmap: {
  9185. gradientMap: {
  9186. value: null
  9187. }
  9188. },
  9189. fog: {
  9190. fogDensity: {
  9191. value: 0.00025
  9192. },
  9193. fogNear: {
  9194. value: 1
  9195. },
  9196. fogFar: {
  9197. value: 2000
  9198. },
  9199. fogColor: {
  9200. value: new Color(0xffffff)
  9201. }
  9202. },
  9203. lights: {
  9204. ambientLightColor: {
  9205. value: []
  9206. },
  9207. lightProbe: {
  9208. value: []
  9209. },
  9210. directionalLights: {
  9211. value: [],
  9212. properties: {
  9213. direction: {},
  9214. color: {}
  9215. }
  9216. },
  9217. directionalLightShadows: {
  9218. value: [],
  9219. properties: {
  9220. shadowBias: {},
  9221. shadowNormalBias: {},
  9222. shadowRadius: {},
  9223. shadowMapSize: {}
  9224. }
  9225. },
  9226. directionalShadowMap: {
  9227. value: []
  9228. },
  9229. directionalShadowMatrix: {
  9230. value: []
  9231. },
  9232. spotLights: {
  9233. value: [],
  9234. properties: {
  9235. color: {},
  9236. position: {},
  9237. direction: {},
  9238. distance: {},
  9239. coneCos: {},
  9240. penumbraCos: {},
  9241. decay: {}
  9242. }
  9243. },
  9244. spotLightShadows: {
  9245. value: [],
  9246. properties: {
  9247. shadowBias: {},
  9248. shadowNormalBias: {},
  9249. shadowRadius: {},
  9250. shadowMapSize: {}
  9251. }
  9252. },
  9253. spotShadowMap: {
  9254. value: []
  9255. },
  9256. spotShadowMatrix: {
  9257. value: []
  9258. },
  9259. pointLights: {
  9260. value: [],
  9261. properties: {
  9262. color: {},
  9263. position: {},
  9264. decay: {},
  9265. distance: {}
  9266. }
  9267. },
  9268. pointLightShadows: {
  9269. value: [],
  9270. properties: {
  9271. shadowBias: {},
  9272. shadowNormalBias: {},
  9273. shadowRadius: {},
  9274. shadowMapSize: {},
  9275. shadowCameraNear: {},
  9276. shadowCameraFar: {}
  9277. }
  9278. },
  9279. pointShadowMap: {
  9280. value: []
  9281. },
  9282. pointShadowMatrix: {
  9283. value: []
  9284. },
  9285. hemisphereLights: {
  9286. value: [],
  9287. properties: {
  9288. direction: {},
  9289. skyColor: {},
  9290. groundColor: {}
  9291. }
  9292. },
  9293. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9294. rectAreaLights: {
  9295. value: [],
  9296. properties: {
  9297. color: {},
  9298. position: {},
  9299. width: {},
  9300. height: {}
  9301. }
  9302. },
  9303. ltc_1: {
  9304. value: null
  9305. },
  9306. ltc_2: {
  9307. value: null
  9308. }
  9309. },
  9310. points: {
  9311. diffuse: {
  9312. value: new Color(0xeeeeee)
  9313. },
  9314. opacity: {
  9315. value: 1.0
  9316. },
  9317. size: {
  9318. value: 1.0
  9319. },
  9320. scale: {
  9321. value: 1.0
  9322. },
  9323. map: {
  9324. value: null
  9325. },
  9326. alphaMap: {
  9327. value: null
  9328. },
  9329. uvTransform: {
  9330. value: new Matrix3()
  9331. }
  9332. },
  9333. sprite: {
  9334. diffuse: {
  9335. value: new Color(0xeeeeee)
  9336. },
  9337. opacity: {
  9338. value: 1.0
  9339. },
  9340. center: {
  9341. value: new Vector2(0.5, 0.5)
  9342. },
  9343. rotation: {
  9344. value: 0.0
  9345. },
  9346. map: {
  9347. value: null
  9348. },
  9349. alphaMap: {
  9350. value: null
  9351. },
  9352. uvTransform: {
  9353. value: new Matrix3()
  9354. }
  9355. }
  9356. };
  9357. var ShaderLib = {
  9358. basic: {
  9359. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  9360. vertexShader: ShaderChunk.meshbasic_vert,
  9361. fragmentShader: ShaderChunk.meshbasic_frag
  9362. },
  9363. lambert: {
  9364. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  9365. emissive: {
  9366. value: new Color(0x000000)
  9367. }
  9368. }]),
  9369. vertexShader: ShaderChunk.meshlambert_vert,
  9370. fragmentShader: ShaderChunk.meshlambert_frag
  9371. },
  9372. phong: {
  9373. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  9374. emissive: {
  9375. value: new Color(0x000000)
  9376. },
  9377. specular: {
  9378. value: new Color(0x111111)
  9379. },
  9380. shininess: {
  9381. value: 30
  9382. }
  9383. }]),
  9384. vertexShader: ShaderChunk.meshphong_vert,
  9385. fragmentShader: ShaderChunk.meshphong_frag
  9386. },
  9387. standard: {
  9388. 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, {
  9389. emissive: {
  9390. value: new Color(0x000000)
  9391. },
  9392. roughness: {
  9393. value: 1.0
  9394. },
  9395. metalness: {
  9396. value: 0.0
  9397. },
  9398. envMapIntensity: {
  9399. value: 1
  9400. } // temporary
  9401. }]),
  9402. vertexShader: ShaderChunk.meshphysical_vert,
  9403. fragmentShader: ShaderChunk.meshphysical_frag
  9404. },
  9405. toon: {
  9406. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  9407. emissive: {
  9408. value: new Color(0x000000)
  9409. }
  9410. }]),
  9411. vertexShader: ShaderChunk.meshtoon_vert,
  9412. fragmentShader: ShaderChunk.meshtoon_frag
  9413. },
  9414. matcap: {
  9415. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  9416. matcap: {
  9417. value: null
  9418. }
  9419. }]),
  9420. vertexShader: ShaderChunk.meshmatcap_vert,
  9421. fragmentShader: ShaderChunk.meshmatcap_frag
  9422. },
  9423. points: {
  9424. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  9425. vertexShader: ShaderChunk.points_vert,
  9426. fragmentShader: ShaderChunk.points_frag
  9427. },
  9428. dashed: {
  9429. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  9430. scale: {
  9431. value: 1
  9432. },
  9433. dashSize: {
  9434. value: 1
  9435. },
  9436. totalSize: {
  9437. value: 2
  9438. }
  9439. }]),
  9440. vertexShader: ShaderChunk.linedashed_vert,
  9441. fragmentShader: ShaderChunk.linedashed_frag
  9442. },
  9443. depth: {
  9444. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  9445. vertexShader: ShaderChunk.depth_vert,
  9446. fragmentShader: ShaderChunk.depth_frag
  9447. },
  9448. normal: {
  9449. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  9450. opacity: {
  9451. value: 1.0
  9452. }
  9453. }]),
  9454. vertexShader: ShaderChunk.normal_vert,
  9455. fragmentShader: ShaderChunk.normal_frag
  9456. },
  9457. sprite: {
  9458. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  9459. vertexShader: ShaderChunk.sprite_vert,
  9460. fragmentShader: ShaderChunk.sprite_frag
  9461. },
  9462. background: {
  9463. uniforms: {
  9464. uvTransform: {
  9465. value: new Matrix3()
  9466. },
  9467. t2D: {
  9468. value: null
  9469. }
  9470. },
  9471. vertexShader: ShaderChunk.background_vert,
  9472. fragmentShader: ShaderChunk.background_frag
  9473. },
  9474. /* -------------------------------------------------------------------------
  9475. // Cube map shader
  9476. ------------------------------------------------------------------------- */
  9477. cube: {
  9478. uniforms: mergeUniforms([UniformsLib.envmap, {
  9479. opacity: {
  9480. value: 1.0
  9481. }
  9482. }]),
  9483. vertexShader: ShaderChunk.cube_vert,
  9484. fragmentShader: ShaderChunk.cube_frag
  9485. },
  9486. equirect: {
  9487. uniforms: {
  9488. tEquirect: {
  9489. value: null
  9490. }
  9491. },
  9492. vertexShader: ShaderChunk.equirect_vert,
  9493. fragmentShader: ShaderChunk.equirect_frag
  9494. },
  9495. distanceRGBA: {
  9496. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9497. referencePosition: {
  9498. value: new Vector3()
  9499. },
  9500. nearDistance: {
  9501. value: 1
  9502. },
  9503. farDistance: {
  9504. value: 1000
  9505. }
  9506. }]),
  9507. vertexShader: ShaderChunk.distanceRGBA_vert,
  9508. fragmentShader: ShaderChunk.distanceRGBA_frag
  9509. },
  9510. shadow: {
  9511. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9512. color: {
  9513. value: new Color(0x00000)
  9514. },
  9515. opacity: {
  9516. value: 1.0
  9517. }
  9518. }]),
  9519. vertexShader: ShaderChunk.shadow_vert,
  9520. fragmentShader: ShaderChunk.shadow_frag
  9521. }
  9522. };
  9523. ShaderLib.physical = {
  9524. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9525. clearcoat: {
  9526. value: 0
  9527. },
  9528. clearcoatMap: {
  9529. value: null
  9530. },
  9531. clearcoatRoughness: {
  9532. value: 0
  9533. },
  9534. clearcoatRoughnessMap: {
  9535. value: null
  9536. },
  9537. clearcoatNormalScale: {
  9538. value: new Vector2(1, 1)
  9539. },
  9540. clearcoatNormalMap: {
  9541. value: null
  9542. },
  9543. sheen: {
  9544. value: new Color(0x000000)
  9545. },
  9546. transmission: {
  9547. value: 0
  9548. },
  9549. transmissionMap: {
  9550. value: null
  9551. }
  9552. }]),
  9553. vertexShader: ShaderChunk.meshphysical_vert,
  9554. fragmentShader: ShaderChunk.meshphysical_frag
  9555. };
  9556. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9557. var clearColor = new Color(0x000000);
  9558. var clearAlpha = 0;
  9559. var planeMesh;
  9560. var boxMesh;
  9561. var currentBackground = null;
  9562. var currentBackgroundVersion = 0;
  9563. var currentTonemapping = null;
  9564. function render(renderList, scene, camera, forceClear) {
  9565. var background = scene.isScene === true ? scene.background : null;
  9566. if (background && background.isTexture) {
  9567. background = cubemaps.get(background);
  9568. } // Ignore background in AR
  9569. // TODO: Reconsider this.
  9570. var xr = renderer.xr;
  9571. var session = xr.getSession && xr.getSession();
  9572. if (session && session.environmentBlendMode === 'additive') {
  9573. background = null;
  9574. }
  9575. if (background === null) {
  9576. setClear(clearColor, clearAlpha);
  9577. } else if (background && background.isColor) {
  9578. setClear(background, 1);
  9579. forceClear = true;
  9580. }
  9581. if (renderer.autoClear || forceClear) {
  9582. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9583. }
  9584. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9585. if (boxMesh === undefined) {
  9586. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9587. name: 'BackgroundCubeMaterial',
  9588. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9589. vertexShader: ShaderLib.cube.vertexShader,
  9590. fragmentShader: ShaderLib.cube.fragmentShader,
  9591. side: BackSide,
  9592. depthTest: false,
  9593. depthWrite: false,
  9594. fog: false
  9595. }));
  9596. boxMesh.geometry.deleteAttribute('normal');
  9597. boxMesh.geometry.deleteAttribute('uv');
  9598. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9599. this.matrixWorld.copyPosition(camera.matrixWorld);
  9600. }; // enable code injection for non-built-in material
  9601. Object.defineProperty(boxMesh.material, 'envMap', {
  9602. get: function get() {
  9603. return this.uniforms.envMap.value;
  9604. }
  9605. });
  9606. objects.update(boxMesh);
  9607. }
  9608. if (background.isWebGLCubeRenderTarget) {
  9609. // TODO Deprecate
  9610. background = background.texture;
  9611. }
  9612. boxMesh.material.uniforms.envMap.value = background;
  9613. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9614. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9615. boxMesh.material.needsUpdate = true;
  9616. currentBackground = background;
  9617. currentBackgroundVersion = background.version;
  9618. currentTonemapping = renderer.toneMapping;
  9619. } // push to the pre-sorted opaque render list
  9620. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9621. } else if (background && background.isTexture) {
  9622. if (planeMesh === undefined) {
  9623. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9624. name: 'BackgroundMaterial',
  9625. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9626. vertexShader: ShaderLib.background.vertexShader,
  9627. fragmentShader: ShaderLib.background.fragmentShader,
  9628. side: FrontSide,
  9629. depthTest: false,
  9630. depthWrite: false,
  9631. fog: false
  9632. }));
  9633. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9634. Object.defineProperty(planeMesh.material, 'map', {
  9635. get: function get() {
  9636. return this.uniforms.t2D.value;
  9637. }
  9638. });
  9639. objects.update(planeMesh);
  9640. }
  9641. planeMesh.material.uniforms.t2D.value = background;
  9642. if (background.matrixAutoUpdate === true) {
  9643. background.updateMatrix();
  9644. }
  9645. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9646. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9647. planeMesh.material.needsUpdate = true;
  9648. currentBackground = background;
  9649. currentBackgroundVersion = background.version;
  9650. currentTonemapping = renderer.toneMapping;
  9651. } // push to the pre-sorted opaque render list
  9652. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9653. }
  9654. }
  9655. function setClear(color, alpha) {
  9656. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9657. }
  9658. return {
  9659. getClearColor: function getClearColor() {
  9660. return clearColor;
  9661. },
  9662. setClearColor: function setClearColor(color, alpha) {
  9663. if (alpha === void 0) {
  9664. alpha = 1;
  9665. }
  9666. clearColor.set(color);
  9667. clearAlpha = alpha;
  9668. setClear(clearColor, clearAlpha);
  9669. },
  9670. getClearAlpha: function getClearAlpha() {
  9671. return clearAlpha;
  9672. },
  9673. setClearAlpha: function setClearAlpha(alpha) {
  9674. clearAlpha = alpha;
  9675. setClear(clearColor, clearAlpha);
  9676. },
  9677. render: render
  9678. };
  9679. }
  9680. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9681. var maxVertexAttributes = gl.getParameter(34921);
  9682. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9683. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9684. var bindingStates = {};
  9685. var defaultState = createBindingState(null);
  9686. var currentState = defaultState;
  9687. function setup(object, material, program, geometry, index) {
  9688. var updateBuffers = false;
  9689. if (vaoAvailable) {
  9690. var state = getBindingState(geometry, program, material);
  9691. if (currentState !== state) {
  9692. currentState = state;
  9693. bindVertexArrayObject(currentState.object);
  9694. }
  9695. updateBuffers = needsUpdate(geometry, index);
  9696. if (updateBuffers) saveCache(geometry, index);
  9697. } else {
  9698. var wireframe = material.wireframe === true;
  9699. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9700. currentState.geometry = geometry.id;
  9701. currentState.program = program.id;
  9702. currentState.wireframe = wireframe;
  9703. updateBuffers = true;
  9704. }
  9705. }
  9706. if (object.isInstancedMesh === true) {
  9707. updateBuffers = true;
  9708. }
  9709. if (index !== null) {
  9710. attributes.update(index, 34963);
  9711. }
  9712. if (updateBuffers) {
  9713. setupVertexAttributes(object, material, program, geometry);
  9714. if (index !== null) {
  9715. gl.bindBuffer(34963, attributes.get(index).buffer);
  9716. }
  9717. }
  9718. }
  9719. function createVertexArrayObject() {
  9720. if (capabilities.isWebGL2) return gl.createVertexArray();
  9721. return extension.createVertexArrayOES();
  9722. }
  9723. function bindVertexArrayObject(vao) {
  9724. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9725. return extension.bindVertexArrayOES(vao);
  9726. }
  9727. function deleteVertexArrayObject(vao) {
  9728. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9729. return extension.deleteVertexArrayOES(vao);
  9730. }
  9731. function getBindingState(geometry, program, material) {
  9732. var wireframe = material.wireframe === true;
  9733. var programMap = bindingStates[geometry.id];
  9734. if (programMap === undefined) {
  9735. programMap = {};
  9736. bindingStates[geometry.id] = programMap;
  9737. }
  9738. var stateMap = programMap[program.id];
  9739. if (stateMap === undefined) {
  9740. stateMap = {};
  9741. programMap[program.id] = stateMap;
  9742. }
  9743. var state = stateMap[wireframe];
  9744. if (state === undefined) {
  9745. state = createBindingState(createVertexArrayObject());
  9746. stateMap[wireframe] = state;
  9747. }
  9748. return state;
  9749. }
  9750. function createBindingState(vao) {
  9751. var newAttributes = [];
  9752. var enabledAttributes = [];
  9753. var attributeDivisors = [];
  9754. for (var i = 0; i < maxVertexAttributes; i++) {
  9755. newAttributes[i] = 0;
  9756. enabledAttributes[i] = 0;
  9757. attributeDivisors[i] = 0;
  9758. }
  9759. return {
  9760. // for backward compatibility on non-VAO support browser
  9761. geometry: null,
  9762. program: null,
  9763. wireframe: false,
  9764. newAttributes: newAttributes,
  9765. enabledAttributes: enabledAttributes,
  9766. attributeDivisors: attributeDivisors,
  9767. object: vao,
  9768. attributes: {},
  9769. index: null
  9770. };
  9771. }
  9772. function needsUpdate(geometry, index) {
  9773. var cachedAttributes = currentState.attributes;
  9774. var geometryAttributes = geometry.attributes;
  9775. var attributesNum = 0;
  9776. for (var key in geometryAttributes) {
  9777. var cachedAttribute = cachedAttributes[key];
  9778. var geometryAttribute = geometryAttributes[key];
  9779. if (cachedAttribute === undefined) return true;
  9780. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9781. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9782. attributesNum++;
  9783. }
  9784. if (currentState.attributesNum !== attributesNum) return true;
  9785. if (currentState.index !== index) return true;
  9786. return false;
  9787. }
  9788. function saveCache(geometry, index) {
  9789. var cache = {};
  9790. var attributes = geometry.attributes;
  9791. var attributesNum = 0;
  9792. for (var key in attributes) {
  9793. var attribute = attributes[key];
  9794. var data = {};
  9795. data.attribute = attribute;
  9796. if (attribute.data) {
  9797. data.data = attribute.data;
  9798. }
  9799. cache[key] = data;
  9800. attributesNum++;
  9801. }
  9802. currentState.attributes = cache;
  9803. currentState.attributesNum = attributesNum;
  9804. currentState.index = index;
  9805. }
  9806. function initAttributes() {
  9807. var newAttributes = currentState.newAttributes;
  9808. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9809. newAttributes[i] = 0;
  9810. }
  9811. }
  9812. function enableAttribute(attribute) {
  9813. enableAttributeAndDivisor(attribute, 0);
  9814. }
  9815. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9816. var newAttributes = currentState.newAttributes;
  9817. var enabledAttributes = currentState.enabledAttributes;
  9818. var attributeDivisors = currentState.attributeDivisors;
  9819. newAttributes[attribute] = 1;
  9820. if (enabledAttributes[attribute] === 0) {
  9821. gl.enableVertexAttribArray(attribute);
  9822. enabledAttributes[attribute] = 1;
  9823. }
  9824. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9825. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9826. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9827. attributeDivisors[attribute] = meshPerAttribute;
  9828. }
  9829. }
  9830. function disableUnusedAttributes() {
  9831. var newAttributes = currentState.newAttributes;
  9832. var enabledAttributes = currentState.enabledAttributes;
  9833. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9834. if (enabledAttributes[i] !== newAttributes[i]) {
  9835. gl.disableVertexAttribArray(i);
  9836. enabledAttributes[i] = 0;
  9837. }
  9838. }
  9839. }
  9840. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9841. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9842. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9843. } else {
  9844. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9845. }
  9846. }
  9847. function setupVertexAttributes(object, material, program, geometry) {
  9848. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9849. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9850. }
  9851. initAttributes();
  9852. var geometryAttributes = geometry.attributes;
  9853. var programAttributes = program.getAttributes();
  9854. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9855. for (var name in programAttributes) {
  9856. var programAttribute = programAttributes[name];
  9857. if (programAttribute >= 0) {
  9858. var geometryAttribute = geometryAttributes[name];
  9859. if (geometryAttribute !== undefined) {
  9860. var normalized = geometryAttribute.normalized;
  9861. var size = geometryAttribute.itemSize;
  9862. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9863. if (attribute === undefined) continue;
  9864. var buffer = attribute.buffer;
  9865. var type = attribute.type;
  9866. var bytesPerElement = attribute.bytesPerElement;
  9867. if (geometryAttribute.isInterleavedBufferAttribute) {
  9868. var data = geometryAttribute.data;
  9869. var stride = data.stride;
  9870. var offset = geometryAttribute.offset;
  9871. if (data && data.isInstancedInterleavedBuffer) {
  9872. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9873. if (geometry._maxInstanceCount === undefined) {
  9874. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9875. }
  9876. } else {
  9877. enableAttribute(programAttribute);
  9878. }
  9879. gl.bindBuffer(34962, buffer);
  9880. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9881. } else {
  9882. if (geometryAttribute.isInstancedBufferAttribute) {
  9883. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9884. if (geometry._maxInstanceCount === undefined) {
  9885. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9886. }
  9887. } else {
  9888. enableAttribute(programAttribute);
  9889. }
  9890. gl.bindBuffer(34962, buffer);
  9891. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9892. }
  9893. } else if (name === 'instanceMatrix') {
  9894. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9895. if (_attribute === undefined) continue;
  9896. var _buffer = _attribute.buffer;
  9897. var _type = _attribute.type;
  9898. enableAttributeAndDivisor(programAttribute + 0, 1);
  9899. enableAttributeAndDivisor(programAttribute + 1, 1);
  9900. enableAttributeAndDivisor(programAttribute + 2, 1);
  9901. enableAttributeAndDivisor(programAttribute + 3, 1);
  9902. gl.bindBuffer(34962, _buffer);
  9903. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9904. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9905. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9906. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9907. } else if (name === 'instanceColor') {
  9908. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9909. if (_attribute2 === undefined) continue;
  9910. var _buffer2 = _attribute2.buffer;
  9911. var _type2 = _attribute2.type;
  9912. enableAttributeAndDivisor(programAttribute, 1);
  9913. gl.bindBuffer(34962, _buffer2);
  9914. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9915. } else if (materialDefaultAttributeValues !== undefined) {
  9916. var value = materialDefaultAttributeValues[name];
  9917. if (value !== undefined) {
  9918. switch (value.length) {
  9919. case 2:
  9920. gl.vertexAttrib2fv(programAttribute, value);
  9921. break;
  9922. case 3:
  9923. gl.vertexAttrib3fv(programAttribute, value);
  9924. break;
  9925. case 4:
  9926. gl.vertexAttrib4fv(programAttribute, value);
  9927. break;
  9928. default:
  9929. gl.vertexAttrib1fv(programAttribute, value);
  9930. }
  9931. }
  9932. }
  9933. }
  9934. }
  9935. disableUnusedAttributes();
  9936. }
  9937. function dispose() {
  9938. reset();
  9939. for (var geometryId in bindingStates) {
  9940. var programMap = bindingStates[geometryId];
  9941. for (var programId in programMap) {
  9942. var stateMap = programMap[programId];
  9943. for (var wireframe in stateMap) {
  9944. deleteVertexArrayObject(stateMap[wireframe].object);
  9945. delete stateMap[wireframe];
  9946. }
  9947. delete programMap[programId];
  9948. }
  9949. delete bindingStates[geometryId];
  9950. }
  9951. }
  9952. function releaseStatesOfGeometry(geometry) {
  9953. if (bindingStates[geometry.id] === undefined) return;
  9954. var programMap = bindingStates[geometry.id];
  9955. for (var programId in programMap) {
  9956. var stateMap = programMap[programId];
  9957. for (var wireframe in stateMap) {
  9958. deleteVertexArrayObject(stateMap[wireframe].object);
  9959. delete stateMap[wireframe];
  9960. }
  9961. delete programMap[programId];
  9962. }
  9963. delete bindingStates[geometry.id];
  9964. }
  9965. function releaseStatesOfProgram(program) {
  9966. for (var geometryId in bindingStates) {
  9967. var programMap = bindingStates[geometryId];
  9968. if (programMap[program.id] === undefined) continue;
  9969. var stateMap = programMap[program.id];
  9970. for (var wireframe in stateMap) {
  9971. deleteVertexArrayObject(stateMap[wireframe].object);
  9972. delete stateMap[wireframe];
  9973. }
  9974. delete programMap[program.id];
  9975. }
  9976. }
  9977. function reset() {
  9978. resetDefaultState();
  9979. if (currentState === defaultState) return;
  9980. currentState = defaultState;
  9981. bindVertexArrayObject(currentState.object);
  9982. } // for backward-compatilibity
  9983. function resetDefaultState() {
  9984. defaultState.geometry = null;
  9985. defaultState.program = null;
  9986. defaultState.wireframe = false;
  9987. }
  9988. return {
  9989. setup: setup,
  9990. reset: reset,
  9991. resetDefaultState: resetDefaultState,
  9992. dispose: dispose,
  9993. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9994. releaseStatesOfProgram: releaseStatesOfProgram,
  9995. initAttributes: initAttributes,
  9996. enableAttribute: enableAttribute,
  9997. disableUnusedAttributes: disableUnusedAttributes
  9998. };
  9999. }
  10000. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  10001. var isWebGL2 = capabilities.isWebGL2;
  10002. var mode;
  10003. function setMode(value) {
  10004. mode = value;
  10005. }
  10006. function render(start, count) {
  10007. gl.drawArrays(mode, start, count);
  10008. info.update(count, mode, 1);
  10009. }
  10010. function renderInstances(start, count, primcount) {
  10011. if (primcount === 0) return;
  10012. var extension, methodName;
  10013. if (isWebGL2) {
  10014. extension = gl;
  10015. methodName = 'drawArraysInstanced';
  10016. } else {
  10017. extension = extensions.get('ANGLE_instanced_arrays');
  10018. methodName = 'drawArraysInstancedANGLE';
  10019. if (extension === null) {
  10020. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10021. return;
  10022. }
  10023. }
  10024. extension[methodName](mode, start, count, primcount);
  10025. info.update(count, mode, primcount);
  10026. } //
  10027. this.setMode = setMode;
  10028. this.render = render;
  10029. this.renderInstances = renderInstances;
  10030. }
  10031. function WebGLCapabilities(gl, extensions, parameters) {
  10032. var maxAnisotropy;
  10033. function getMaxAnisotropy() {
  10034. if (maxAnisotropy !== undefined) return maxAnisotropy;
  10035. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  10036. var extension = extensions.get('EXT_texture_filter_anisotropic');
  10037. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  10038. } else {
  10039. maxAnisotropy = 0;
  10040. }
  10041. return maxAnisotropy;
  10042. }
  10043. function getMaxPrecision(precision) {
  10044. if (precision === 'highp') {
  10045. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  10046. return 'highp';
  10047. }
  10048. precision = 'mediump';
  10049. }
  10050. if (precision === 'mediump') {
  10051. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  10052. return 'mediump';
  10053. }
  10054. }
  10055. return 'lowp';
  10056. }
  10057. /* eslint-disable no-undef */
  10058. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  10059. /* eslint-enable no-undef */
  10060. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10061. var maxPrecision = getMaxPrecision(precision);
  10062. if (maxPrecision !== precision) {
  10063. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  10064. precision = maxPrecision;
  10065. }
  10066. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10067. var maxTextures = gl.getParameter(34930);
  10068. var maxVertexTextures = gl.getParameter(35660);
  10069. var maxTextureSize = gl.getParameter(3379);
  10070. var maxCubemapSize = gl.getParameter(34076);
  10071. var maxAttributes = gl.getParameter(34921);
  10072. var maxVertexUniforms = gl.getParameter(36347);
  10073. var maxVaryings = gl.getParameter(36348);
  10074. var maxFragmentUniforms = gl.getParameter(36349);
  10075. var vertexTextures = maxVertexTextures > 0;
  10076. var floatFragmentTextures = isWebGL2 || extensions.has('OES_texture_float');
  10077. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10078. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  10079. return {
  10080. isWebGL2: isWebGL2,
  10081. getMaxAnisotropy: getMaxAnisotropy,
  10082. getMaxPrecision: getMaxPrecision,
  10083. precision: precision,
  10084. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10085. maxTextures: maxTextures,
  10086. maxVertexTextures: maxVertexTextures,
  10087. maxTextureSize: maxTextureSize,
  10088. maxCubemapSize: maxCubemapSize,
  10089. maxAttributes: maxAttributes,
  10090. maxVertexUniforms: maxVertexUniforms,
  10091. maxVaryings: maxVaryings,
  10092. maxFragmentUniforms: maxFragmentUniforms,
  10093. vertexTextures: vertexTextures,
  10094. floatFragmentTextures: floatFragmentTextures,
  10095. floatVertexTextures: floatVertexTextures,
  10096. maxSamples: maxSamples
  10097. };
  10098. }
  10099. function WebGLClipping(properties) {
  10100. var scope = this;
  10101. var globalState = null,
  10102. numGlobalPlanes = 0,
  10103. localClippingEnabled = false,
  10104. renderingShadows = false;
  10105. var plane = new Plane(),
  10106. viewNormalMatrix = new Matrix3(),
  10107. uniform = {
  10108. value: null,
  10109. needsUpdate: false
  10110. };
  10111. this.uniform = uniform;
  10112. this.numPlanes = 0;
  10113. this.numIntersection = 0;
  10114. this.init = function (planes, enableLocalClipping, camera) {
  10115. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  10116. // run another frame in order to reset the state:
  10117. numGlobalPlanes !== 0 || localClippingEnabled;
  10118. localClippingEnabled = enableLocalClipping;
  10119. globalState = projectPlanes(planes, camera, 0);
  10120. numGlobalPlanes = planes.length;
  10121. return enabled;
  10122. };
  10123. this.beginShadows = function () {
  10124. renderingShadows = true;
  10125. projectPlanes(null);
  10126. };
  10127. this.endShadows = function () {
  10128. renderingShadows = false;
  10129. resetGlobalState();
  10130. };
  10131. this.setState = function (material, camera, useCache) {
  10132. var planes = material.clippingPlanes,
  10133. clipIntersection = material.clipIntersection,
  10134. clipShadows = material.clipShadows;
  10135. var materialProperties = properties.get(material);
  10136. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  10137. // there's no local clipping
  10138. if (renderingShadows) {
  10139. // there's no global clipping
  10140. projectPlanes(null);
  10141. } else {
  10142. resetGlobalState();
  10143. }
  10144. } else {
  10145. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10146. lGlobal = nGlobal * 4;
  10147. var dstArray = materialProperties.clippingState || null;
  10148. uniform.value = dstArray; // ensure unique state
  10149. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  10150. for (var i = 0; i !== lGlobal; ++i) {
  10151. dstArray[i] = globalState[i];
  10152. }
  10153. materialProperties.clippingState = dstArray;
  10154. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10155. this.numPlanes += nGlobal;
  10156. }
  10157. };
  10158. function resetGlobalState() {
  10159. if (uniform.value !== globalState) {
  10160. uniform.value = globalState;
  10161. uniform.needsUpdate = numGlobalPlanes > 0;
  10162. }
  10163. scope.numPlanes = numGlobalPlanes;
  10164. scope.numIntersection = 0;
  10165. }
  10166. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  10167. var nPlanes = planes !== null ? planes.length : 0;
  10168. var dstArray = null;
  10169. if (nPlanes !== 0) {
  10170. dstArray = uniform.value;
  10171. if (skipTransform !== true || dstArray === null) {
  10172. var flatSize = dstOffset + nPlanes * 4,
  10173. viewMatrix = camera.matrixWorldInverse;
  10174. viewNormalMatrix.getNormalMatrix(viewMatrix);
  10175. if (dstArray === null || dstArray.length < flatSize) {
  10176. dstArray = new Float32Array(flatSize);
  10177. }
  10178. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  10179. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  10180. plane.normal.toArray(dstArray, i4);
  10181. dstArray[i4 + 3] = plane.constant;
  10182. }
  10183. }
  10184. uniform.value = dstArray;
  10185. uniform.needsUpdate = true;
  10186. }
  10187. scope.numPlanes = nPlanes;
  10188. scope.numIntersection = 0;
  10189. return dstArray;
  10190. }
  10191. }
  10192. function WebGLCubeMaps(renderer) {
  10193. var cubemaps = new WeakMap();
  10194. function mapTextureMapping(texture, mapping) {
  10195. if (mapping === EquirectangularReflectionMapping) {
  10196. texture.mapping = CubeReflectionMapping;
  10197. } else if (mapping === EquirectangularRefractionMapping) {
  10198. texture.mapping = CubeRefractionMapping;
  10199. }
  10200. return texture;
  10201. }
  10202. function get(texture) {
  10203. if (texture && texture.isTexture) {
  10204. var mapping = texture.mapping;
  10205. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  10206. if (cubemaps.has(texture)) {
  10207. var cubemap = cubemaps.get(texture).texture;
  10208. return mapTextureMapping(cubemap, texture.mapping);
  10209. } else {
  10210. var image = texture.image;
  10211. if (image && image.height > 0) {
  10212. var currentRenderList = renderer.getRenderList();
  10213. var currentRenderTarget = renderer.getRenderTarget();
  10214. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  10215. renderTarget.fromEquirectangularTexture(renderer, texture);
  10216. cubemaps.set(texture, renderTarget);
  10217. renderer.setRenderTarget(currentRenderTarget);
  10218. renderer.setRenderList(currentRenderList);
  10219. texture.addEventListener('dispose', onTextureDispose);
  10220. return mapTextureMapping(renderTarget.texture, texture.mapping);
  10221. } else {
  10222. // image not yet ready. try the conversion next frame
  10223. return null;
  10224. }
  10225. }
  10226. }
  10227. }
  10228. return texture;
  10229. }
  10230. function onTextureDispose(event) {
  10231. var texture = event.target;
  10232. texture.removeEventListener('dispose', onTextureDispose);
  10233. var cubemap = cubemaps.get(texture);
  10234. if (cubemap !== undefined) {
  10235. cubemaps.delete(texture);
  10236. cubemap.dispose();
  10237. }
  10238. }
  10239. function dispose() {
  10240. cubemaps = new WeakMap();
  10241. }
  10242. return {
  10243. get: get,
  10244. dispose: dispose
  10245. };
  10246. }
  10247. function WebGLExtensions(gl) {
  10248. var extensions = {};
  10249. function getExtension(name) {
  10250. if (extensions[name] !== undefined) {
  10251. return extensions[name];
  10252. }
  10253. var extension;
  10254. switch (name) {
  10255. case 'WEBGL_depth_texture':
  10256. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  10257. break;
  10258. case 'EXT_texture_filter_anisotropic':
  10259. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  10260. break;
  10261. case 'WEBGL_compressed_texture_s3tc':
  10262. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  10263. break;
  10264. case 'WEBGL_compressed_texture_pvrtc':
  10265. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  10266. break;
  10267. default:
  10268. extension = gl.getExtension(name);
  10269. }
  10270. extensions[name] = extension;
  10271. return extension;
  10272. }
  10273. return {
  10274. has: function has(name) {
  10275. return getExtension(name) !== null;
  10276. },
  10277. init: function init(capabilities) {
  10278. if (capabilities.isWebGL2) {
  10279. getExtension('EXT_color_buffer_float');
  10280. } else {
  10281. getExtension('WEBGL_depth_texture');
  10282. getExtension('OES_texture_float');
  10283. getExtension('OES_texture_half_float');
  10284. getExtension('OES_texture_half_float_linear');
  10285. getExtension('OES_standard_derivatives');
  10286. getExtension('OES_element_index_uint');
  10287. getExtension('OES_vertex_array_object');
  10288. getExtension('ANGLE_instanced_arrays');
  10289. }
  10290. getExtension('OES_texture_float_linear');
  10291. getExtension('EXT_color_buffer_half_float');
  10292. },
  10293. get: function get(name) {
  10294. var extension = getExtension(name);
  10295. if (extension === null) {
  10296. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  10297. }
  10298. return extension;
  10299. }
  10300. };
  10301. }
  10302. function WebGLGeometries(gl, attributes, info, bindingStates) {
  10303. var geometries = {};
  10304. var wireframeAttributes = new WeakMap();
  10305. function onGeometryDispose(event) {
  10306. var geometry = event.target;
  10307. if (geometry.index !== null) {
  10308. attributes.remove(geometry.index);
  10309. }
  10310. for (var name in geometry.attributes) {
  10311. attributes.remove(geometry.attributes[name]);
  10312. }
  10313. geometry.removeEventListener('dispose', onGeometryDispose);
  10314. delete geometries[geometry.id];
  10315. var attribute = wireframeAttributes.get(geometry);
  10316. if (attribute) {
  10317. attributes.remove(attribute);
  10318. wireframeAttributes.delete(geometry);
  10319. }
  10320. bindingStates.releaseStatesOfGeometry(geometry);
  10321. if (geometry.isInstancedBufferGeometry === true) {
  10322. delete geometry._maxInstanceCount;
  10323. } //
  10324. info.memory.geometries--;
  10325. }
  10326. function get(object, geometry) {
  10327. if (geometries[geometry.id] === true) return geometry;
  10328. geometry.addEventListener('dispose', onGeometryDispose);
  10329. geometries[geometry.id] = true;
  10330. info.memory.geometries++;
  10331. return geometry;
  10332. }
  10333. function update(geometry) {
  10334. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  10335. for (var name in geometryAttributes) {
  10336. attributes.update(geometryAttributes[name], 34962);
  10337. } // morph targets
  10338. var morphAttributes = geometry.morphAttributes;
  10339. for (var _name in morphAttributes) {
  10340. var array = morphAttributes[_name];
  10341. for (var i = 0, l = array.length; i < l; i++) {
  10342. attributes.update(array[i], 34962);
  10343. }
  10344. }
  10345. }
  10346. function updateWireframeAttribute(geometry) {
  10347. var indices = [];
  10348. var geometryIndex = geometry.index;
  10349. var geometryPosition = geometry.attributes.position;
  10350. var version = 0;
  10351. if (geometryIndex !== null) {
  10352. var array = geometryIndex.array;
  10353. version = geometryIndex.version;
  10354. for (var i = 0, l = array.length; i < l; i += 3) {
  10355. var a = array[i + 0];
  10356. var b = array[i + 1];
  10357. var c = array[i + 2];
  10358. indices.push(a, b, b, c, c, a);
  10359. }
  10360. } else {
  10361. var _array = geometryPosition.array;
  10362. version = geometryPosition.version;
  10363. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  10364. var _a = _i + 0;
  10365. var _b = _i + 1;
  10366. var _c = _i + 2;
  10367. indices.push(_a, _b, _b, _c, _c, _a);
  10368. }
  10369. }
  10370. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  10371. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  10372. //
  10373. var previousAttribute = wireframeAttributes.get(geometry);
  10374. if (previousAttribute) attributes.remove(previousAttribute); //
  10375. wireframeAttributes.set(geometry, attribute);
  10376. }
  10377. function getWireframeAttribute(geometry) {
  10378. var currentAttribute = wireframeAttributes.get(geometry);
  10379. if (currentAttribute) {
  10380. var geometryIndex = geometry.index;
  10381. if (geometryIndex !== null) {
  10382. // if the attribute is obsolete, create a new one
  10383. if (currentAttribute.version < geometryIndex.version) {
  10384. updateWireframeAttribute(geometry);
  10385. }
  10386. }
  10387. } else {
  10388. updateWireframeAttribute(geometry);
  10389. }
  10390. return wireframeAttributes.get(geometry);
  10391. }
  10392. return {
  10393. get: get,
  10394. update: update,
  10395. getWireframeAttribute: getWireframeAttribute
  10396. };
  10397. }
  10398. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  10399. var isWebGL2 = capabilities.isWebGL2;
  10400. var mode;
  10401. function setMode(value) {
  10402. mode = value;
  10403. }
  10404. var type, bytesPerElement;
  10405. function setIndex(value) {
  10406. type = value.type;
  10407. bytesPerElement = value.bytesPerElement;
  10408. }
  10409. function render(start, count) {
  10410. gl.drawElements(mode, count, type, start * bytesPerElement);
  10411. info.update(count, mode, 1);
  10412. }
  10413. function renderInstances(start, count, primcount) {
  10414. if (primcount === 0) return;
  10415. var extension, methodName;
  10416. if (isWebGL2) {
  10417. extension = gl;
  10418. methodName = 'drawElementsInstanced';
  10419. } else {
  10420. extension = extensions.get('ANGLE_instanced_arrays');
  10421. methodName = 'drawElementsInstancedANGLE';
  10422. if (extension === null) {
  10423. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10424. return;
  10425. }
  10426. }
  10427. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  10428. info.update(count, mode, primcount);
  10429. } //
  10430. this.setMode = setMode;
  10431. this.setIndex = setIndex;
  10432. this.render = render;
  10433. this.renderInstances = renderInstances;
  10434. }
  10435. function WebGLInfo(gl) {
  10436. var memory = {
  10437. geometries: 0,
  10438. textures: 0
  10439. };
  10440. var render = {
  10441. frame: 0,
  10442. calls: 0,
  10443. triangles: 0,
  10444. points: 0,
  10445. lines: 0
  10446. };
  10447. function update(count, mode, instanceCount) {
  10448. render.calls++;
  10449. switch (mode) {
  10450. case 4:
  10451. render.triangles += instanceCount * (count / 3);
  10452. break;
  10453. case 1:
  10454. render.lines += instanceCount * (count / 2);
  10455. break;
  10456. case 3:
  10457. render.lines += instanceCount * (count - 1);
  10458. break;
  10459. case 2:
  10460. render.lines += instanceCount * count;
  10461. break;
  10462. case 0:
  10463. render.points += instanceCount * count;
  10464. break;
  10465. default:
  10466. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  10467. break;
  10468. }
  10469. }
  10470. function reset() {
  10471. render.frame++;
  10472. render.calls = 0;
  10473. render.triangles = 0;
  10474. render.points = 0;
  10475. render.lines = 0;
  10476. }
  10477. return {
  10478. memory: memory,
  10479. render: render,
  10480. programs: null,
  10481. autoReset: true,
  10482. reset: reset,
  10483. update: update
  10484. };
  10485. }
  10486. function numericalSort(a, b) {
  10487. return a[0] - b[0];
  10488. }
  10489. function absNumericalSort(a, b) {
  10490. return Math.abs(b[1]) - Math.abs(a[1]);
  10491. }
  10492. function WebGLMorphtargets(gl) {
  10493. var influencesList = {};
  10494. var morphInfluences = new Float32Array(8);
  10495. var workInfluences = [];
  10496. for (var i = 0; i < 8; i++) {
  10497. workInfluences[i] = [i, 0];
  10498. }
  10499. function update(object, geometry, material, program) {
  10500. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10501. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10502. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10503. var influences = influencesList[geometry.id];
  10504. if (influences === undefined) {
  10505. // initialise list
  10506. influences = [];
  10507. for (var _i = 0; _i < length; _i++) {
  10508. influences[_i] = [_i, 0];
  10509. }
  10510. influencesList[geometry.id] = influences;
  10511. } // Collect influences
  10512. for (var _i2 = 0; _i2 < length; _i2++) {
  10513. var influence = influences[_i2];
  10514. influence[0] = _i2;
  10515. influence[1] = objectInfluences[_i2];
  10516. }
  10517. influences.sort(absNumericalSort);
  10518. for (var _i3 = 0; _i3 < 8; _i3++) {
  10519. if (_i3 < length && influences[_i3][1]) {
  10520. workInfluences[_i3][0] = influences[_i3][0];
  10521. workInfluences[_i3][1] = influences[_i3][1];
  10522. } else {
  10523. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10524. workInfluences[_i3][1] = 0;
  10525. }
  10526. }
  10527. workInfluences.sort(numericalSort);
  10528. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10529. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10530. var morphInfluencesSum = 0;
  10531. for (var _i4 = 0; _i4 < 8; _i4++) {
  10532. var _influence = workInfluences[_i4];
  10533. var index = _influence[0];
  10534. var value = _influence[1];
  10535. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10536. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10537. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10538. }
  10539. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10540. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10541. }
  10542. morphInfluences[_i4] = value;
  10543. morphInfluencesSum += value;
  10544. } else {
  10545. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10546. geometry.deleteAttribute('morphTarget' + _i4);
  10547. }
  10548. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10549. geometry.deleteAttribute('morphNormal' + _i4);
  10550. }
  10551. morphInfluences[_i4] = 0;
  10552. }
  10553. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10554. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10555. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10556. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10557. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10558. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10559. }
  10560. return {
  10561. update: update
  10562. };
  10563. }
  10564. function WebGLObjects(gl, geometries, attributes, info) {
  10565. var updateMap = new WeakMap();
  10566. function update(object) {
  10567. var frame = info.render.frame;
  10568. var geometry = object.geometry;
  10569. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10570. if (updateMap.get(buffergeometry) !== frame) {
  10571. geometries.update(buffergeometry);
  10572. updateMap.set(buffergeometry, frame);
  10573. }
  10574. if (object.isInstancedMesh) {
  10575. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10576. object.addEventListener('dispose', onInstancedMeshDispose);
  10577. }
  10578. attributes.update(object.instanceMatrix, 34962);
  10579. if (object.instanceColor !== null) {
  10580. attributes.update(object.instanceColor, 34962);
  10581. }
  10582. }
  10583. return buffergeometry;
  10584. }
  10585. function dispose() {
  10586. updateMap = new WeakMap();
  10587. }
  10588. function onInstancedMeshDispose(event) {
  10589. var instancedMesh = event.target;
  10590. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10591. attributes.remove(instancedMesh.instanceMatrix);
  10592. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10593. }
  10594. return {
  10595. update: update,
  10596. dispose: dispose
  10597. };
  10598. }
  10599. function DataTexture2DArray(data, width, height, depth) {
  10600. if (data === void 0) {
  10601. data = null;
  10602. }
  10603. if (width === void 0) {
  10604. width = 1;
  10605. }
  10606. if (height === void 0) {
  10607. height = 1;
  10608. }
  10609. if (depth === void 0) {
  10610. depth = 1;
  10611. }
  10612. Texture.call(this, null);
  10613. this.image = {
  10614. data: data,
  10615. width: width,
  10616. height: height,
  10617. depth: depth
  10618. };
  10619. this.magFilter = NearestFilter;
  10620. this.minFilter = NearestFilter;
  10621. this.wrapR = ClampToEdgeWrapping;
  10622. this.generateMipmaps = false;
  10623. this.flipY = false;
  10624. this.needsUpdate = true;
  10625. }
  10626. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10627. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10628. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10629. function DataTexture3D(data, width, height, depth) {
  10630. if (data === void 0) {
  10631. data = null;
  10632. }
  10633. if (width === void 0) {
  10634. width = 1;
  10635. }
  10636. if (height === void 0) {
  10637. height = 1;
  10638. }
  10639. if (depth === void 0) {
  10640. depth = 1;
  10641. }
  10642. // We're going to add .setXXX() methods for setting properties later.
  10643. // Users can still set in DataTexture3D directly.
  10644. //
  10645. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10646. // texture.anisotropy = 16;
  10647. //
  10648. // See #14839
  10649. Texture.call(this, null);
  10650. this.image = {
  10651. data: data,
  10652. width: width,
  10653. height: height,
  10654. depth: depth
  10655. };
  10656. this.magFilter = NearestFilter;
  10657. this.minFilter = NearestFilter;
  10658. this.wrapR = ClampToEdgeWrapping;
  10659. this.generateMipmaps = false;
  10660. this.flipY = false;
  10661. this.needsUpdate = true;
  10662. }
  10663. DataTexture3D.prototype = Object.create(Texture.prototype);
  10664. DataTexture3D.prototype.constructor = DataTexture3D;
  10665. DataTexture3D.prototype.isDataTexture3D = true;
  10666. /**
  10667. * Uniforms of a program.
  10668. * Those form a tree structure with a special top-level container for the root,
  10669. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10670. *
  10671. *
  10672. * Properties of inner nodes including the top-level container:
  10673. *
  10674. * .seq - array of nested uniforms
  10675. * .map - nested uniforms by name
  10676. *
  10677. *
  10678. * Methods of all nodes except the top-level container:
  10679. *
  10680. * .setValue( gl, value, [textures] )
  10681. *
  10682. * uploads a uniform value(s)
  10683. * the 'textures' parameter is needed for sampler uniforms
  10684. *
  10685. *
  10686. * Static methods of the top-level container (textures factorizations):
  10687. *
  10688. * .upload( gl, seq, values, textures )
  10689. *
  10690. * sets uniforms in 'seq' to 'values[id].value'
  10691. *
  10692. * .seqWithValue( seq, values ) : filteredSeq
  10693. *
  10694. * filters 'seq' entries with corresponding entry in values
  10695. *
  10696. *
  10697. * Methods of the top-level container (textures factorizations):
  10698. *
  10699. * .setValue( gl, name, value, textures )
  10700. *
  10701. * sets uniform with name 'name' to 'value'
  10702. *
  10703. * .setOptional( gl, obj, prop )
  10704. *
  10705. * like .set for an optional property of the object
  10706. *
  10707. */
  10708. var emptyTexture = new Texture();
  10709. var emptyTexture2dArray = new DataTexture2DArray();
  10710. var emptyTexture3d = new DataTexture3D();
  10711. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10712. // Array Caches (provide typed arrays for temporary by size)
  10713. var arrayCacheF32 = [];
  10714. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10715. var mat4array = new Float32Array(16);
  10716. var mat3array = new Float32Array(9);
  10717. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10718. function flatten(array, nBlocks, blockSize) {
  10719. var firstElem = array[0];
  10720. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10721. // see http://jacksondunstan.com/articles/983
  10722. var n = nBlocks * blockSize;
  10723. var r = arrayCacheF32[n];
  10724. if (r === undefined) {
  10725. r = new Float32Array(n);
  10726. arrayCacheF32[n] = r;
  10727. }
  10728. if (nBlocks !== 0) {
  10729. firstElem.toArray(r, 0);
  10730. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10731. offset += blockSize;
  10732. array[i].toArray(r, offset);
  10733. }
  10734. }
  10735. return r;
  10736. }
  10737. function arraysEqual(a, b) {
  10738. if (a.length !== b.length) return false;
  10739. for (var i = 0, l = a.length; i < l; i++) {
  10740. if (a[i] !== b[i]) return false;
  10741. }
  10742. return true;
  10743. }
  10744. function copyArray(a, b) {
  10745. for (var i = 0, l = b.length; i < l; i++) {
  10746. a[i] = b[i];
  10747. }
  10748. } // Texture unit allocation
  10749. function allocTexUnits(textures, n) {
  10750. var r = arrayCacheI32[n];
  10751. if (r === undefined) {
  10752. r = new Int32Array(n);
  10753. arrayCacheI32[n] = r;
  10754. }
  10755. for (var i = 0; i !== n; ++i) {
  10756. r[i] = textures.allocateTextureUnit();
  10757. }
  10758. return r;
  10759. } // --- Setters ---
  10760. // Note: Defining these methods externally, because they come in a bunch
  10761. // and this way their names minify.
  10762. // Single scalar
  10763. function setValueV1f(gl, v) {
  10764. var cache = this.cache;
  10765. if (cache[0] === v) return;
  10766. gl.uniform1f(this.addr, v);
  10767. cache[0] = v;
  10768. } // Single float vector (from flat array or THREE.VectorN)
  10769. function setValueV2f(gl, v) {
  10770. var cache = this.cache;
  10771. if (v.x !== undefined) {
  10772. if (cache[0] !== v.x || cache[1] !== v.y) {
  10773. gl.uniform2f(this.addr, v.x, v.y);
  10774. cache[0] = v.x;
  10775. cache[1] = v.y;
  10776. }
  10777. } else {
  10778. if (arraysEqual(cache, v)) return;
  10779. gl.uniform2fv(this.addr, v);
  10780. copyArray(cache, v);
  10781. }
  10782. }
  10783. function setValueV3f(gl, v) {
  10784. var cache = this.cache;
  10785. if (v.x !== undefined) {
  10786. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10787. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10788. cache[0] = v.x;
  10789. cache[1] = v.y;
  10790. cache[2] = v.z;
  10791. }
  10792. } else if (v.r !== undefined) {
  10793. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10794. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10795. cache[0] = v.r;
  10796. cache[1] = v.g;
  10797. cache[2] = v.b;
  10798. }
  10799. } else {
  10800. if (arraysEqual(cache, v)) return;
  10801. gl.uniform3fv(this.addr, v);
  10802. copyArray(cache, v);
  10803. }
  10804. }
  10805. function setValueV4f(gl, v) {
  10806. var cache = this.cache;
  10807. if (v.x !== undefined) {
  10808. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10809. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10810. cache[0] = v.x;
  10811. cache[1] = v.y;
  10812. cache[2] = v.z;
  10813. cache[3] = v.w;
  10814. }
  10815. } else {
  10816. if (arraysEqual(cache, v)) return;
  10817. gl.uniform4fv(this.addr, v);
  10818. copyArray(cache, v);
  10819. }
  10820. } // Single matrix (from flat array or MatrixN)
  10821. function setValueM2(gl, v) {
  10822. var cache = this.cache;
  10823. var elements = v.elements;
  10824. if (elements === undefined) {
  10825. if (arraysEqual(cache, v)) return;
  10826. gl.uniformMatrix2fv(this.addr, false, v);
  10827. copyArray(cache, v);
  10828. } else {
  10829. if (arraysEqual(cache, elements)) return;
  10830. mat2array.set(elements);
  10831. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10832. copyArray(cache, elements);
  10833. }
  10834. }
  10835. function setValueM3(gl, v) {
  10836. var cache = this.cache;
  10837. var elements = v.elements;
  10838. if (elements === undefined) {
  10839. if (arraysEqual(cache, v)) return;
  10840. gl.uniformMatrix3fv(this.addr, false, v);
  10841. copyArray(cache, v);
  10842. } else {
  10843. if (arraysEqual(cache, elements)) return;
  10844. mat3array.set(elements);
  10845. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10846. copyArray(cache, elements);
  10847. }
  10848. }
  10849. function setValueM4(gl, v) {
  10850. var cache = this.cache;
  10851. var elements = v.elements;
  10852. if (elements === undefined) {
  10853. if (arraysEqual(cache, v)) return;
  10854. gl.uniformMatrix4fv(this.addr, false, v);
  10855. copyArray(cache, v);
  10856. } else {
  10857. if (arraysEqual(cache, elements)) return;
  10858. mat4array.set(elements);
  10859. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10860. copyArray(cache, elements);
  10861. }
  10862. } // Single texture (2D / Cube)
  10863. function setValueT1(gl, v, textures) {
  10864. var cache = this.cache;
  10865. var unit = textures.allocateTextureUnit();
  10866. if (cache[0] !== unit) {
  10867. gl.uniform1i(this.addr, unit);
  10868. cache[0] = unit;
  10869. }
  10870. textures.safeSetTexture2D(v || emptyTexture, unit);
  10871. }
  10872. function setValueT2DArray1(gl, v, textures) {
  10873. var cache = this.cache;
  10874. var unit = textures.allocateTextureUnit();
  10875. if (cache[0] !== unit) {
  10876. gl.uniform1i(this.addr, unit);
  10877. cache[0] = unit;
  10878. }
  10879. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10880. }
  10881. function setValueT3D1(gl, v, textures) {
  10882. var cache = this.cache;
  10883. var unit = textures.allocateTextureUnit();
  10884. if (cache[0] !== unit) {
  10885. gl.uniform1i(this.addr, unit);
  10886. cache[0] = unit;
  10887. }
  10888. textures.setTexture3D(v || emptyTexture3d, unit);
  10889. }
  10890. function setValueT6(gl, v, textures) {
  10891. var cache = this.cache;
  10892. var unit = textures.allocateTextureUnit();
  10893. if (cache[0] !== unit) {
  10894. gl.uniform1i(this.addr, unit);
  10895. cache[0] = unit;
  10896. }
  10897. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10898. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10899. function setValueV1i(gl, v) {
  10900. var cache = this.cache;
  10901. if (cache[0] === v) return;
  10902. gl.uniform1i(this.addr, v);
  10903. cache[0] = v;
  10904. }
  10905. function setValueV2i(gl, v) {
  10906. var cache = this.cache;
  10907. if (arraysEqual(cache, v)) return;
  10908. gl.uniform2iv(this.addr, v);
  10909. copyArray(cache, v);
  10910. }
  10911. function setValueV3i(gl, v) {
  10912. var cache = this.cache;
  10913. if (arraysEqual(cache, v)) return;
  10914. gl.uniform3iv(this.addr, v);
  10915. copyArray(cache, v);
  10916. }
  10917. function setValueV4i(gl, v) {
  10918. var cache = this.cache;
  10919. if (arraysEqual(cache, v)) return;
  10920. gl.uniform4iv(this.addr, v);
  10921. copyArray(cache, v);
  10922. } // uint
  10923. function setValueV1ui(gl, v) {
  10924. var cache = this.cache;
  10925. if (cache[0] === v) return;
  10926. gl.uniform1ui(this.addr, v);
  10927. cache[0] = v;
  10928. } // Helper to pick the right setter for the singular case
  10929. function getSingularSetter(type) {
  10930. switch (type) {
  10931. case 0x1406:
  10932. return setValueV1f;
  10933. // FLOAT
  10934. case 0x8b50:
  10935. return setValueV2f;
  10936. // _VEC2
  10937. case 0x8b51:
  10938. return setValueV3f;
  10939. // _VEC3
  10940. case 0x8b52:
  10941. return setValueV4f;
  10942. // _VEC4
  10943. case 0x8b5a:
  10944. return setValueM2;
  10945. // _MAT2
  10946. case 0x8b5b:
  10947. return setValueM3;
  10948. // _MAT3
  10949. case 0x8b5c:
  10950. return setValueM4;
  10951. // _MAT4
  10952. case 0x1404:
  10953. case 0x8b56:
  10954. return setValueV1i;
  10955. // INT, BOOL
  10956. case 0x8b53:
  10957. case 0x8b57:
  10958. return setValueV2i;
  10959. // _VEC2
  10960. case 0x8b54:
  10961. case 0x8b58:
  10962. return setValueV3i;
  10963. // _VEC3
  10964. case 0x8b55:
  10965. case 0x8b59:
  10966. return setValueV4i;
  10967. // _VEC4
  10968. case 0x1405:
  10969. return setValueV1ui;
  10970. // UINT
  10971. case 0x8b5e: // SAMPLER_2D
  10972. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10973. case 0x8dca: // INT_SAMPLER_2D
  10974. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10975. case 0x8b62:
  10976. // SAMPLER_2D_SHADOW
  10977. return setValueT1;
  10978. case 0x8b5f: // SAMPLER_3D
  10979. case 0x8dcb: // INT_SAMPLER_3D
  10980. case 0x8dd3:
  10981. // UNSIGNED_INT_SAMPLER_3D
  10982. return setValueT3D1;
  10983. case 0x8b60: // SAMPLER_CUBE
  10984. case 0x8dcc: // INT_SAMPLER_CUBE
  10985. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10986. case 0x8dc5:
  10987. // SAMPLER_CUBE_SHADOW
  10988. return setValueT6;
  10989. case 0x8dc1: // SAMPLER_2D_ARRAY
  10990. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10991. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10992. case 0x8dc4:
  10993. // SAMPLER_2D_ARRAY_SHADOW
  10994. return setValueT2DArray1;
  10995. }
  10996. } // Array of scalars
  10997. function setValueV1fArray(gl, v) {
  10998. gl.uniform1fv(this.addr, v);
  10999. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  11000. function setValueV1iArray(gl, v) {
  11001. gl.uniform1iv(this.addr, v);
  11002. }
  11003. function setValueV2iArray(gl, v) {
  11004. gl.uniform2iv(this.addr, v);
  11005. }
  11006. function setValueV3iArray(gl, v) {
  11007. gl.uniform3iv(this.addr, v);
  11008. }
  11009. function setValueV4iArray(gl, v) {
  11010. gl.uniform4iv(this.addr, v);
  11011. } // Array of vectors (flat or from THREE classes)
  11012. function setValueV2fArray(gl, v) {
  11013. var data = flatten(v, this.size, 2);
  11014. gl.uniform2fv(this.addr, data);
  11015. }
  11016. function setValueV3fArray(gl, v) {
  11017. var data = flatten(v, this.size, 3);
  11018. gl.uniform3fv(this.addr, data);
  11019. }
  11020. function setValueV4fArray(gl, v) {
  11021. var data = flatten(v, this.size, 4);
  11022. gl.uniform4fv(this.addr, data);
  11023. } // Array of matrices (flat or from THREE clases)
  11024. function setValueM2Array(gl, v) {
  11025. var data = flatten(v, this.size, 4);
  11026. gl.uniformMatrix2fv(this.addr, false, data);
  11027. }
  11028. function setValueM3Array(gl, v) {
  11029. var data = flatten(v, this.size, 9);
  11030. gl.uniformMatrix3fv(this.addr, false, data);
  11031. }
  11032. function setValueM4Array(gl, v) {
  11033. var data = flatten(v, this.size, 16);
  11034. gl.uniformMatrix4fv(this.addr, false, data);
  11035. } // Array of textures (2D / Cube)
  11036. function setValueT1Array(gl, v, textures) {
  11037. var n = v.length;
  11038. var units = allocTexUnits(textures, n);
  11039. gl.uniform1iv(this.addr, units);
  11040. for (var i = 0; i !== n; ++i) {
  11041. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  11042. }
  11043. }
  11044. function setValueT6Array(gl, v, textures) {
  11045. var n = v.length;
  11046. var units = allocTexUnits(textures, n);
  11047. gl.uniform1iv(this.addr, units);
  11048. for (var i = 0; i !== n; ++i) {
  11049. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  11050. }
  11051. } // Helper to pick the right setter for a pure (bottom-level) array
  11052. function getPureArraySetter(type) {
  11053. switch (type) {
  11054. case 0x1406:
  11055. return setValueV1fArray;
  11056. // FLOAT
  11057. case 0x8b50:
  11058. return setValueV2fArray;
  11059. // _VEC2
  11060. case 0x8b51:
  11061. return setValueV3fArray;
  11062. // _VEC3
  11063. case 0x8b52:
  11064. return setValueV4fArray;
  11065. // _VEC4
  11066. case 0x8b5a:
  11067. return setValueM2Array;
  11068. // _MAT2
  11069. case 0x8b5b:
  11070. return setValueM3Array;
  11071. // _MAT3
  11072. case 0x8b5c:
  11073. return setValueM4Array;
  11074. // _MAT4
  11075. case 0x1404:
  11076. case 0x8b56:
  11077. return setValueV1iArray;
  11078. // INT, BOOL
  11079. case 0x8b53:
  11080. case 0x8b57:
  11081. return setValueV2iArray;
  11082. // _VEC2
  11083. case 0x8b54:
  11084. case 0x8b58:
  11085. return setValueV3iArray;
  11086. // _VEC3
  11087. case 0x8b55:
  11088. case 0x8b59:
  11089. return setValueV4iArray;
  11090. // _VEC4
  11091. case 0x8b5e: // SAMPLER_2D
  11092. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11093. case 0x8dca: // INT_SAMPLER_2D
  11094. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11095. case 0x8b62:
  11096. // SAMPLER_2D_SHADOW
  11097. return setValueT1Array;
  11098. case 0x8b60: // SAMPLER_CUBE
  11099. case 0x8dcc: // INT_SAMPLER_CUBE
  11100. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11101. case 0x8dc5:
  11102. // SAMPLER_CUBE_SHADOW
  11103. return setValueT6Array;
  11104. }
  11105. } // --- Uniform Classes ---
  11106. function SingleUniform(id, activeInfo, addr) {
  11107. this.id = id;
  11108. this.addr = addr;
  11109. this.cache = [];
  11110. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11111. }
  11112. function PureArrayUniform(id, activeInfo, addr) {
  11113. this.id = id;
  11114. this.addr = addr;
  11115. this.cache = [];
  11116. this.size = activeInfo.size;
  11117. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11118. }
  11119. PureArrayUniform.prototype.updateCache = function (data) {
  11120. var cache = this.cache;
  11121. if (data instanceof Float32Array && cache.length !== data.length) {
  11122. this.cache = new Float32Array(data.length);
  11123. }
  11124. copyArray(cache, data);
  11125. };
  11126. function StructuredUniform(id) {
  11127. this.id = id;
  11128. this.seq = [];
  11129. this.map = {};
  11130. }
  11131. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  11132. var seq = this.seq;
  11133. for (var i = 0, n = seq.length; i !== n; ++i) {
  11134. var u = seq[i];
  11135. u.setValue(gl, value[u.id], textures);
  11136. }
  11137. }; // --- Top-level ---
  11138. // Parser - builds up the property tree from the path strings
  11139. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  11140. // - the identifier (member name or array index)
  11141. // - followed by an optional right bracket (found when array index)
  11142. // - followed by an optional left bracket or dot (type of subscript)
  11143. //
  11144. // Note: These portions can be read in a non-overlapping fashion and
  11145. // allow straightforward parsing of the hierarchy that WebGL encodes
  11146. // in the uniform names.
  11147. function addUniform(container, uniformObject) {
  11148. container.seq.push(uniformObject);
  11149. container.map[uniformObject.id] = uniformObject;
  11150. }
  11151. function parseUniform(activeInfo, addr, container) {
  11152. var path = activeInfo.name,
  11153. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  11154. RePathPart.lastIndex = 0;
  11155. while (true) {
  11156. var match = RePathPart.exec(path),
  11157. matchEnd = RePathPart.lastIndex;
  11158. var id = match[1];
  11159. var idIsIndex = match[2] === ']',
  11160. subscript = match[3];
  11161. if (idIsIndex) id = id | 0; // convert to integer
  11162. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  11163. // bare name or "pure" bottom-level array "[0]" suffix
  11164. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  11165. break;
  11166. } else {
  11167. // step into inner node / create it in case it doesn't exist
  11168. var map = container.map;
  11169. var next = map[id];
  11170. if (next === undefined) {
  11171. next = new StructuredUniform(id);
  11172. addUniform(container, next);
  11173. }
  11174. container = next;
  11175. }
  11176. }
  11177. } // Root Container
  11178. function WebGLUniforms(gl, program) {
  11179. this.seq = [];
  11180. this.map = {};
  11181. var n = gl.getProgramParameter(program, 35718);
  11182. for (var i = 0; i < n; ++i) {
  11183. var info = gl.getActiveUniform(program, i),
  11184. addr = gl.getUniformLocation(program, info.name);
  11185. parseUniform(info, addr, this);
  11186. }
  11187. }
  11188. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  11189. var u = this.map[name];
  11190. if (u !== undefined) u.setValue(gl, value, textures);
  11191. };
  11192. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  11193. var v = object[name];
  11194. if (v !== undefined) this.setValue(gl, name, v);
  11195. }; // Static interface
  11196. WebGLUniforms.upload = function (gl, seq, values, textures) {
  11197. for (var i = 0, n = seq.length; i !== n; ++i) {
  11198. var u = seq[i],
  11199. v = values[u.id];
  11200. if (v.needsUpdate !== false) {
  11201. // note: always updating when .needsUpdate is undefined
  11202. u.setValue(gl, v.value, textures);
  11203. }
  11204. }
  11205. };
  11206. WebGLUniforms.seqWithValue = function (seq, values) {
  11207. var r = [];
  11208. for (var i = 0, n = seq.length; i !== n; ++i) {
  11209. var u = seq[i];
  11210. if (u.id in values) r.push(u);
  11211. }
  11212. return r;
  11213. };
  11214. function WebGLShader(gl, type, string) {
  11215. var shader = gl.createShader(type);
  11216. gl.shaderSource(shader, string);
  11217. gl.compileShader(shader);
  11218. return shader;
  11219. }
  11220. var programIdCount = 0;
  11221. function addLineNumbers(string) {
  11222. var lines = string.split('\n');
  11223. for (var i = 0; i < lines.length; i++) {
  11224. lines[i] = i + 1 + ': ' + lines[i];
  11225. }
  11226. return lines.join('\n');
  11227. }
  11228. function getEncodingComponents(encoding) {
  11229. switch (encoding) {
  11230. case LinearEncoding:
  11231. return ['Linear', '( value )'];
  11232. case sRGBEncoding:
  11233. return ['sRGB', '( value )'];
  11234. case RGBEEncoding:
  11235. return ['RGBE', '( value )'];
  11236. case RGBM7Encoding:
  11237. return ['RGBM', '( value, 7.0 )'];
  11238. case RGBM16Encoding:
  11239. return ['RGBM', '( value, 16.0 )'];
  11240. case RGBDEncoding:
  11241. return ['RGBD', '( value, 256.0 )'];
  11242. case GammaEncoding:
  11243. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  11244. case LogLuvEncoding:
  11245. return ['LogLuv', '( value )'];
  11246. default:
  11247. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  11248. return ['Linear', '( value )'];
  11249. }
  11250. }
  11251. function getShaderErrors(gl, shader, type) {
  11252. var status = gl.getShaderParameter(shader, 35713);
  11253. var log = gl.getShaderInfoLog(shader).trim();
  11254. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  11255. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11256. var source = gl.getShaderSource(shader);
  11257. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  11258. }
  11259. function getTexelDecodingFunction(functionName, encoding) {
  11260. var components = getEncodingComponents(encoding);
  11261. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  11262. }
  11263. function getTexelEncodingFunction(functionName, encoding) {
  11264. var components = getEncodingComponents(encoding);
  11265. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  11266. }
  11267. function getToneMappingFunction(functionName, toneMapping) {
  11268. var toneMappingName;
  11269. switch (toneMapping) {
  11270. case LinearToneMapping:
  11271. toneMappingName = 'Linear';
  11272. break;
  11273. case ReinhardToneMapping:
  11274. toneMappingName = 'Reinhard';
  11275. break;
  11276. case CineonToneMapping:
  11277. toneMappingName = 'OptimizedCineon';
  11278. break;
  11279. case ACESFilmicToneMapping:
  11280. toneMappingName = 'ACESFilmic';
  11281. break;
  11282. case CustomToneMapping:
  11283. toneMappingName = 'Custom';
  11284. break;
  11285. default:
  11286. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  11287. toneMappingName = 'Linear';
  11288. }
  11289. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11290. }
  11291. function generateExtensions(parameters) {
  11292. 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' : ''];
  11293. return chunks.filter(filterEmptyLine).join('\n');
  11294. }
  11295. function generateDefines(defines) {
  11296. var chunks = [];
  11297. for (var name in defines) {
  11298. var value = defines[name];
  11299. if (value === false) continue;
  11300. chunks.push('#define ' + name + ' ' + value);
  11301. }
  11302. return chunks.join('\n');
  11303. }
  11304. function fetchAttributeLocations(gl, program) {
  11305. var attributes = {};
  11306. var n = gl.getProgramParameter(program, 35721);
  11307. for (var i = 0; i < n; i++) {
  11308. var info = gl.getActiveAttrib(program, i);
  11309. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11310. attributes[name] = gl.getAttribLocation(program, name);
  11311. }
  11312. return attributes;
  11313. }
  11314. function filterEmptyLine(string) {
  11315. return string !== '';
  11316. }
  11317. function replaceLightNums(string, parameters) {
  11318. 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);
  11319. }
  11320. function replaceClippingPlaneNums(string, parameters) {
  11321. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  11322. } // Resolve Includes
  11323. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11324. function resolveIncludes(string) {
  11325. return string.replace(includePattern, includeReplacer);
  11326. }
  11327. function includeReplacer(match, include) {
  11328. var string = ShaderChunk[include];
  11329. if (string === undefined) {
  11330. throw new Error('Can not resolve #include <' + include + '>');
  11331. }
  11332. return resolveIncludes(string);
  11333. } // Unroll Loops
  11334. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11335. 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;
  11336. function unrollLoops(string) {
  11337. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  11338. }
  11339. function deprecatedLoopReplacer(match, start, end, snippet) {
  11340. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  11341. return loopReplacer(match, start, end, snippet);
  11342. }
  11343. function loopReplacer(match, start, end, snippet) {
  11344. var string = '';
  11345. for (var i = parseInt(start); i < parseInt(end); i++) {
  11346. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  11347. }
  11348. return string;
  11349. } //
  11350. function generatePrecision(parameters) {
  11351. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  11352. if (parameters.precision === 'highp') {
  11353. precisionstring += '\n#define HIGH_PRECISION';
  11354. } else if (parameters.precision === 'mediump') {
  11355. precisionstring += '\n#define MEDIUM_PRECISION';
  11356. } else if (parameters.precision === 'lowp') {
  11357. precisionstring += '\n#define LOW_PRECISION';
  11358. }
  11359. return precisionstring;
  11360. }
  11361. function generateShadowMapTypeDefine(parameters) {
  11362. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11363. if (parameters.shadowMapType === PCFShadowMap) {
  11364. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11365. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  11366. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11367. } else if (parameters.shadowMapType === VSMShadowMap) {
  11368. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11369. }
  11370. return shadowMapTypeDefine;
  11371. }
  11372. function generateEnvMapTypeDefine(parameters) {
  11373. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11374. if (parameters.envMap) {
  11375. switch (parameters.envMapMode) {
  11376. case CubeReflectionMapping:
  11377. case CubeRefractionMapping:
  11378. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11379. break;
  11380. case CubeUVReflectionMapping:
  11381. case CubeUVRefractionMapping:
  11382. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11383. break;
  11384. }
  11385. }
  11386. return envMapTypeDefine;
  11387. }
  11388. function generateEnvMapModeDefine(parameters) {
  11389. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11390. if (parameters.envMap) {
  11391. switch (parameters.envMapMode) {
  11392. case CubeRefractionMapping:
  11393. case CubeUVRefractionMapping:
  11394. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11395. break;
  11396. }
  11397. }
  11398. return envMapModeDefine;
  11399. }
  11400. function generateEnvMapBlendingDefine(parameters) {
  11401. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11402. if (parameters.envMap) {
  11403. switch (parameters.combine) {
  11404. case MultiplyOperation:
  11405. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11406. break;
  11407. case MixOperation:
  11408. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11409. break;
  11410. case AddOperation:
  11411. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11412. break;
  11413. }
  11414. }
  11415. return envMapBlendingDefine;
  11416. }
  11417. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  11418. var gl = renderer.getContext();
  11419. var defines = parameters.defines;
  11420. var vertexShader = parameters.vertexShader;
  11421. var fragmentShader = parameters.fragmentShader;
  11422. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  11423. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  11424. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  11425. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  11426. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  11427. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  11428. var customDefines = generateDefines(defines);
  11429. var program = gl.createProgram();
  11430. var prefixVertex, prefixFragment;
  11431. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11432. if (parameters.isRawShaderMaterial) {
  11433. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  11434. if (prefixVertex.length > 0) {
  11435. prefixVertex += '\n';
  11436. }
  11437. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  11438. if (prefixFragment.length > 0) {
  11439. prefixFragment += '\n';
  11440. }
  11441. } else {
  11442. 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');
  11443. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  11444. '#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
  11445. 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
  11446. 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');
  11447. }
  11448. vertexShader = resolveIncludes(vertexShader);
  11449. vertexShader = replaceLightNums(vertexShader, parameters);
  11450. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  11451. fragmentShader = resolveIncludes(fragmentShader);
  11452. fragmentShader = replaceLightNums(fragmentShader, parameters);
  11453. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  11454. vertexShader = unrollLoops(vertexShader);
  11455. fragmentShader = unrollLoops(fragmentShader);
  11456. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  11457. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11458. versionString = '#version 300 es\n';
  11459. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  11460. 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;
  11461. }
  11462. var vertexGlsl = versionString + prefixVertex + vertexShader;
  11463. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  11464. // console.log( '*FRAGMENT*', fragmentGlsl );
  11465. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  11466. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  11467. gl.attachShader(program, glVertexShader);
  11468. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  11469. if (parameters.index0AttributeName !== undefined) {
  11470. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  11471. } else if (parameters.morphTargets === true) {
  11472. // programs with morphTargets displace position out of attribute 0
  11473. gl.bindAttribLocation(program, 0, 'position');
  11474. }
  11475. gl.linkProgram(program); // check for link errors
  11476. if (renderer.debug.checkShaderErrors) {
  11477. var programLog = gl.getProgramInfoLog(program).trim();
  11478. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  11479. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  11480. var runnable = true;
  11481. var haveDiagnostics = true;
  11482. if (gl.getProgramParameter(program, 35714) === false) {
  11483. runnable = false;
  11484. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  11485. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  11486. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11487. } else if (programLog !== '') {
  11488. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11489. } else if (vertexLog === '' || fragmentLog === '') {
  11490. haveDiagnostics = false;
  11491. }
  11492. if (haveDiagnostics) {
  11493. this.diagnostics = {
  11494. runnable: runnable,
  11495. programLog: programLog,
  11496. vertexShader: {
  11497. log: vertexLog,
  11498. prefix: prefixVertex
  11499. },
  11500. fragmentShader: {
  11501. log: fragmentLog,
  11502. prefix: prefixFragment
  11503. }
  11504. };
  11505. }
  11506. } // Clean up
  11507. // Crashes in iOS9 and iOS10. #18402
  11508. // gl.detachShader( program, glVertexShader );
  11509. // gl.detachShader( program, glFragmentShader );
  11510. gl.deleteShader(glVertexShader);
  11511. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11512. var cachedUniforms;
  11513. this.getUniforms = function () {
  11514. if (cachedUniforms === undefined) {
  11515. cachedUniforms = new WebGLUniforms(gl, program);
  11516. }
  11517. return cachedUniforms;
  11518. }; // set up caching for attribute locations
  11519. var cachedAttributes;
  11520. this.getAttributes = function () {
  11521. if (cachedAttributes === undefined) {
  11522. cachedAttributes = fetchAttributeLocations(gl, program);
  11523. }
  11524. return cachedAttributes;
  11525. }; // free resource
  11526. this.destroy = function () {
  11527. bindingStates.releaseStatesOfProgram(this);
  11528. gl.deleteProgram(program);
  11529. this.program = undefined;
  11530. }; //
  11531. this.name = parameters.shaderName;
  11532. this.id = programIdCount++;
  11533. this.cacheKey = cacheKey;
  11534. this.usedTimes = 1;
  11535. this.program = program;
  11536. this.vertexShader = glVertexShader;
  11537. this.fragmentShader = glFragmentShader;
  11538. return this;
  11539. }
  11540. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11541. var programs = [];
  11542. var isWebGL2 = capabilities.isWebGL2;
  11543. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11544. var floatVertexTextures = capabilities.floatVertexTextures;
  11545. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11546. var vertexTextures = capabilities.vertexTextures;
  11547. var precision = capabilities.precision;
  11548. var shaderIDs = {
  11549. MeshDepthMaterial: 'depth',
  11550. MeshDistanceMaterial: 'distanceRGBA',
  11551. MeshNormalMaterial: 'normal',
  11552. MeshBasicMaterial: 'basic',
  11553. MeshLambertMaterial: 'lambert',
  11554. MeshPhongMaterial: 'phong',
  11555. MeshToonMaterial: 'toon',
  11556. MeshStandardMaterial: 'physical',
  11557. MeshPhysicalMaterial: 'physical',
  11558. MeshMatcapMaterial: 'matcap',
  11559. LineBasicMaterial: 'basic',
  11560. LineDashedMaterial: 'dashed',
  11561. PointsMaterial: 'points',
  11562. ShadowMaterial: 'shadow',
  11563. SpriteMaterial: 'sprite'
  11564. };
  11565. 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'];
  11566. function getMaxBones(object) {
  11567. var skeleton = object.skeleton;
  11568. var bones = skeleton.bones;
  11569. if (floatVertexTextures) {
  11570. return 1024;
  11571. } else {
  11572. // default for when object is not specified
  11573. // ( for example when prebuilding shader to be used with multiple objects )
  11574. //
  11575. // - leave some extra space for other uniforms
  11576. // - limit here is ANGLE's 254 max uniform vectors
  11577. // (up to 54 should be safe)
  11578. var nVertexUniforms = maxVertexUniforms;
  11579. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11580. var maxBones = Math.min(nVertexMatrices, bones.length);
  11581. if (maxBones < bones.length) {
  11582. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11583. return 0;
  11584. }
  11585. return maxBones;
  11586. }
  11587. }
  11588. function getTextureEncodingFromMap(map) {
  11589. var encoding;
  11590. if (map && map.isTexture) {
  11591. encoding = map.encoding;
  11592. } else if (map && map.isWebGLRenderTarget) {
  11593. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11594. encoding = map.texture.encoding;
  11595. } else {
  11596. encoding = LinearEncoding;
  11597. }
  11598. return encoding;
  11599. }
  11600. function getParameters(material, lights, shadows, scene, object) {
  11601. var fog = scene.fog;
  11602. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11603. var envMap = cubemaps.get(material.envMap || environment);
  11604. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11605. // (not to blow over maxLights budget)
  11606. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11607. if (material.precision !== null) {
  11608. precision = capabilities.getMaxPrecision(material.precision);
  11609. if (precision !== material.precision) {
  11610. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11611. }
  11612. }
  11613. var vertexShader, fragmentShader;
  11614. if (shaderID) {
  11615. var shader = ShaderLib[shaderID];
  11616. vertexShader = shader.vertexShader;
  11617. fragmentShader = shader.fragmentShader;
  11618. } else {
  11619. vertexShader = material.vertexShader;
  11620. fragmentShader = material.fragmentShader;
  11621. }
  11622. var currentRenderTarget = renderer.getRenderTarget();
  11623. var parameters = {
  11624. isWebGL2: isWebGL2,
  11625. shaderID: shaderID,
  11626. shaderName: material.type,
  11627. vertexShader: vertexShader,
  11628. fragmentShader: fragmentShader,
  11629. defines: material.defines,
  11630. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11631. glslVersion: material.glslVersion,
  11632. precision: precision,
  11633. instancing: object.isInstancedMesh === true,
  11634. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11635. supportsVertexTextures: vertexTextures,
  11636. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11637. map: !!material.map,
  11638. mapEncoding: getTextureEncodingFromMap(material.map),
  11639. matcap: !!material.matcap,
  11640. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11641. envMap: !!envMap,
  11642. envMapMode: envMap && envMap.mapping,
  11643. envMapEncoding: getTextureEncodingFromMap(envMap),
  11644. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11645. lightMap: !!material.lightMap,
  11646. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11647. aoMap: !!material.aoMap,
  11648. emissiveMap: !!material.emissiveMap,
  11649. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11650. bumpMap: !!material.bumpMap,
  11651. normalMap: !!material.normalMap,
  11652. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11653. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11654. clearcoatMap: !!material.clearcoatMap,
  11655. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11656. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11657. displacementMap: !!material.displacementMap,
  11658. roughnessMap: !!material.roughnessMap,
  11659. metalnessMap: !!material.metalnessMap,
  11660. specularMap: !!material.specularMap,
  11661. alphaMap: !!material.alphaMap,
  11662. gradientMap: !!material.gradientMap,
  11663. sheen: !!material.sheen,
  11664. transmissionMap: !!material.transmissionMap,
  11665. combine: material.combine,
  11666. vertexTangents: material.normalMap && material.vertexTangents,
  11667. vertexColors: material.vertexColors,
  11668. 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,
  11669. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11670. fog: !!fog,
  11671. useFog: material.fog,
  11672. fogExp2: fog && fog.isFogExp2,
  11673. flatShading: !!material.flatShading,
  11674. sizeAttenuation: material.sizeAttenuation,
  11675. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11676. skinning: material.skinning && maxBones > 0,
  11677. maxBones: maxBones,
  11678. useVertexTexture: floatVertexTextures,
  11679. morphTargets: material.morphTargets,
  11680. morphNormals: material.morphNormals,
  11681. maxMorphTargets: renderer.maxMorphTargets,
  11682. maxMorphNormals: renderer.maxMorphNormals,
  11683. numDirLights: lights.directional.length,
  11684. numPointLights: lights.point.length,
  11685. numSpotLights: lights.spot.length,
  11686. numRectAreaLights: lights.rectArea.length,
  11687. numHemiLights: lights.hemi.length,
  11688. numDirLightShadows: lights.directionalShadowMap.length,
  11689. numPointLightShadows: lights.pointShadowMap.length,
  11690. numSpotLightShadows: lights.spotShadowMap.length,
  11691. numClippingPlanes: clipping.numPlanes,
  11692. numClipIntersection: clipping.numIntersection,
  11693. dithering: material.dithering,
  11694. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11695. shadowMapType: renderer.shadowMap.type,
  11696. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11697. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11698. premultipliedAlpha: material.premultipliedAlpha,
  11699. alphaTest: material.alphaTest,
  11700. doubleSided: material.side === DoubleSide,
  11701. flipSided: material.side === BackSide,
  11702. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11703. index0AttributeName: material.index0AttributeName,
  11704. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11705. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11706. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11707. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11708. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11709. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11710. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11711. customProgramCacheKey: material.customProgramCacheKey()
  11712. };
  11713. return parameters;
  11714. }
  11715. function getProgramCacheKey(parameters) {
  11716. var array = [];
  11717. if (parameters.shaderID) {
  11718. array.push(parameters.shaderID);
  11719. } else {
  11720. array.push(parameters.fragmentShader);
  11721. array.push(parameters.vertexShader);
  11722. }
  11723. if (parameters.defines !== undefined) {
  11724. for (var name in parameters.defines) {
  11725. array.push(name);
  11726. array.push(parameters.defines[name]);
  11727. }
  11728. }
  11729. if (parameters.isRawShaderMaterial === false) {
  11730. for (var i = 0; i < parameterNames.length; i++) {
  11731. array.push(parameters[parameterNames[i]]);
  11732. }
  11733. array.push(renderer.outputEncoding);
  11734. array.push(renderer.gammaFactor);
  11735. }
  11736. array.push(parameters.customProgramCacheKey);
  11737. return array.join();
  11738. }
  11739. function getUniforms(material) {
  11740. var shaderID = shaderIDs[material.type];
  11741. var uniforms;
  11742. if (shaderID) {
  11743. var shader = ShaderLib[shaderID];
  11744. uniforms = UniformsUtils.clone(shader.uniforms);
  11745. } else {
  11746. uniforms = material.uniforms;
  11747. }
  11748. return uniforms;
  11749. }
  11750. function acquireProgram(parameters, cacheKey) {
  11751. var program; // Check if code has been already compiled
  11752. for (var p = 0, pl = programs.length; p < pl; p++) {
  11753. var preexistingProgram = programs[p];
  11754. if (preexistingProgram.cacheKey === cacheKey) {
  11755. program = preexistingProgram;
  11756. ++program.usedTimes;
  11757. break;
  11758. }
  11759. }
  11760. if (program === undefined) {
  11761. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11762. programs.push(program);
  11763. }
  11764. return program;
  11765. }
  11766. function releaseProgram(program) {
  11767. if (--program.usedTimes === 0) {
  11768. // Remove from unordered set
  11769. var i = programs.indexOf(program);
  11770. programs[i] = programs[programs.length - 1];
  11771. programs.pop(); // Free WebGL resources
  11772. program.destroy();
  11773. }
  11774. }
  11775. return {
  11776. getParameters: getParameters,
  11777. getProgramCacheKey: getProgramCacheKey,
  11778. getUniforms: getUniforms,
  11779. acquireProgram: acquireProgram,
  11780. releaseProgram: releaseProgram,
  11781. // Exposed for resource monitoring & error feedback via renderer.info:
  11782. programs: programs
  11783. };
  11784. }
  11785. function WebGLProperties() {
  11786. var properties = new WeakMap();
  11787. function get(object) {
  11788. var map = properties.get(object);
  11789. if (map === undefined) {
  11790. map = {};
  11791. properties.set(object, map);
  11792. }
  11793. return map;
  11794. }
  11795. function remove(object) {
  11796. properties.delete(object);
  11797. }
  11798. function update(object, key, value) {
  11799. properties.get(object)[key] = value;
  11800. }
  11801. function dispose() {
  11802. properties = new WeakMap();
  11803. }
  11804. return {
  11805. get: get,
  11806. remove: remove,
  11807. update: update,
  11808. dispose: dispose
  11809. };
  11810. }
  11811. function painterSortStable(a, b) {
  11812. if (a.groupOrder !== b.groupOrder) {
  11813. return a.groupOrder - b.groupOrder;
  11814. } else if (a.renderOrder !== b.renderOrder) {
  11815. return a.renderOrder - b.renderOrder;
  11816. } else if (a.program !== b.program) {
  11817. return a.program.id - b.program.id;
  11818. } else if (a.material.id !== b.material.id) {
  11819. return a.material.id - b.material.id;
  11820. } else if (a.z !== b.z) {
  11821. return a.z - b.z;
  11822. } else {
  11823. return a.id - b.id;
  11824. }
  11825. }
  11826. function reversePainterSortStable(a, b) {
  11827. if (a.groupOrder !== b.groupOrder) {
  11828. return a.groupOrder - b.groupOrder;
  11829. } else if (a.renderOrder !== b.renderOrder) {
  11830. return a.renderOrder - b.renderOrder;
  11831. } else if (a.z !== b.z) {
  11832. return b.z - a.z;
  11833. } else {
  11834. return a.id - b.id;
  11835. }
  11836. }
  11837. function WebGLRenderList(properties) {
  11838. var renderItems = [];
  11839. var renderItemsIndex = 0;
  11840. var opaque = [];
  11841. var transparent = [];
  11842. var defaultProgram = {
  11843. id: -1
  11844. };
  11845. function init() {
  11846. renderItemsIndex = 0;
  11847. opaque.length = 0;
  11848. transparent.length = 0;
  11849. }
  11850. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11851. var renderItem = renderItems[renderItemsIndex];
  11852. var materialProperties = properties.get(material);
  11853. if (renderItem === undefined) {
  11854. renderItem = {
  11855. id: object.id,
  11856. object: object,
  11857. geometry: geometry,
  11858. material: material,
  11859. program: materialProperties.program || defaultProgram,
  11860. groupOrder: groupOrder,
  11861. renderOrder: object.renderOrder,
  11862. z: z,
  11863. group: group
  11864. };
  11865. renderItems[renderItemsIndex] = renderItem;
  11866. } else {
  11867. renderItem.id = object.id;
  11868. renderItem.object = object;
  11869. renderItem.geometry = geometry;
  11870. renderItem.material = material;
  11871. renderItem.program = materialProperties.program || defaultProgram;
  11872. renderItem.groupOrder = groupOrder;
  11873. renderItem.renderOrder = object.renderOrder;
  11874. renderItem.z = z;
  11875. renderItem.group = group;
  11876. }
  11877. renderItemsIndex++;
  11878. return renderItem;
  11879. }
  11880. function push(object, geometry, material, groupOrder, z, group) {
  11881. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11882. (material.transparent === true ? transparent : opaque).push(renderItem);
  11883. }
  11884. function unshift(object, geometry, material, groupOrder, z, group) {
  11885. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11886. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11887. }
  11888. function sort(customOpaqueSort, customTransparentSort) {
  11889. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11890. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11891. }
  11892. function finish() {
  11893. // Clear references from inactive renderItems in the list
  11894. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11895. var renderItem = renderItems[i];
  11896. if (renderItem.id === null) break;
  11897. renderItem.id = null;
  11898. renderItem.object = null;
  11899. renderItem.geometry = null;
  11900. renderItem.material = null;
  11901. renderItem.program = null;
  11902. renderItem.group = null;
  11903. }
  11904. }
  11905. return {
  11906. opaque: opaque,
  11907. transparent: transparent,
  11908. init: init,
  11909. push: push,
  11910. unshift: unshift,
  11911. finish: finish,
  11912. sort: sort
  11913. };
  11914. }
  11915. function WebGLRenderLists(properties) {
  11916. var lists = new WeakMap();
  11917. function get(scene, camera) {
  11918. var cameras = lists.get(scene);
  11919. var list;
  11920. if (cameras === undefined) {
  11921. list = new WebGLRenderList(properties);
  11922. lists.set(scene, new WeakMap());
  11923. lists.get(scene).set(camera, list);
  11924. } else {
  11925. list = cameras.get(camera);
  11926. if (list === undefined) {
  11927. list = new WebGLRenderList(properties);
  11928. cameras.set(camera, list);
  11929. }
  11930. }
  11931. return list;
  11932. }
  11933. function dispose() {
  11934. lists = new WeakMap();
  11935. }
  11936. return {
  11937. get: get,
  11938. dispose: dispose
  11939. };
  11940. }
  11941. function UniformsCache() {
  11942. var lights = {};
  11943. return {
  11944. get: function get(light) {
  11945. if (lights[light.id] !== undefined) {
  11946. return lights[light.id];
  11947. }
  11948. var uniforms;
  11949. switch (light.type) {
  11950. case 'DirectionalLight':
  11951. uniforms = {
  11952. direction: new Vector3(),
  11953. color: new Color()
  11954. };
  11955. break;
  11956. case 'SpotLight':
  11957. uniforms = {
  11958. position: new Vector3(),
  11959. direction: new Vector3(),
  11960. color: new Color(),
  11961. distance: 0,
  11962. coneCos: 0,
  11963. penumbraCos: 0,
  11964. decay: 0
  11965. };
  11966. break;
  11967. case 'PointLight':
  11968. uniforms = {
  11969. position: new Vector3(),
  11970. color: new Color(),
  11971. distance: 0,
  11972. decay: 0
  11973. };
  11974. break;
  11975. case 'HemisphereLight':
  11976. uniforms = {
  11977. direction: new Vector3(),
  11978. skyColor: new Color(),
  11979. groundColor: new Color()
  11980. };
  11981. break;
  11982. case 'RectAreaLight':
  11983. uniforms = {
  11984. color: new Color(),
  11985. position: new Vector3(),
  11986. halfWidth: new Vector3(),
  11987. halfHeight: new Vector3()
  11988. };
  11989. break;
  11990. }
  11991. lights[light.id] = uniforms;
  11992. return uniforms;
  11993. }
  11994. };
  11995. }
  11996. function ShadowUniformsCache() {
  11997. var lights = {};
  11998. return {
  11999. get: function get(light) {
  12000. if (lights[light.id] !== undefined) {
  12001. return lights[light.id];
  12002. }
  12003. var uniforms;
  12004. switch (light.type) {
  12005. case 'DirectionalLight':
  12006. uniforms = {
  12007. shadowBias: 0,
  12008. shadowNormalBias: 0,
  12009. shadowRadius: 1,
  12010. shadowMapSize: new Vector2()
  12011. };
  12012. break;
  12013. case 'SpotLight':
  12014. uniforms = {
  12015. shadowBias: 0,
  12016. shadowNormalBias: 0,
  12017. shadowRadius: 1,
  12018. shadowMapSize: new Vector2()
  12019. };
  12020. break;
  12021. case 'PointLight':
  12022. uniforms = {
  12023. shadowBias: 0,
  12024. shadowNormalBias: 0,
  12025. shadowRadius: 1,
  12026. shadowMapSize: new Vector2(),
  12027. shadowCameraNear: 1,
  12028. shadowCameraFar: 1000
  12029. };
  12030. break;
  12031. // TODO (abelnation): set RectAreaLight shadow uniforms
  12032. }
  12033. lights[light.id] = uniforms;
  12034. return uniforms;
  12035. }
  12036. };
  12037. }
  12038. var nextVersion = 0;
  12039. function shadowCastingLightsFirst(lightA, lightB) {
  12040. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  12041. }
  12042. function WebGLLights(extensions, capabilities) {
  12043. var cache = new UniformsCache();
  12044. var shadowCache = ShadowUniformsCache();
  12045. var state = {
  12046. version: 0,
  12047. hash: {
  12048. directionalLength: -1,
  12049. pointLength: -1,
  12050. spotLength: -1,
  12051. rectAreaLength: -1,
  12052. hemiLength: -1,
  12053. numDirectionalShadows: -1,
  12054. numPointShadows: -1,
  12055. numSpotShadows: -1
  12056. },
  12057. ambient: [0, 0, 0],
  12058. probe: [],
  12059. directional: [],
  12060. directionalShadow: [],
  12061. directionalShadowMap: [],
  12062. directionalShadowMatrix: [],
  12063. spot: [],
  12064. spotShadow: [],
  12065. spotShadowMap: [],
  12066. spotShadowMatrix: [],
  12067. rectArea: [],
  12068. rectAreaLTC1: null,
  12069. rectAreaLTC2: null,
  12070. point: [],
  12071. pointShadow: [],
  12072. pointShadowMap: [],
  12073. pointShadowMatrix: [],
  12074. hemi: []
  12075. };
  12076. for (var i = 0; i < 9; i++) {
  12077. state.probe.push(new Vector3());
  12078. }
  12079. var vector3 = new Vector3();
  12080. var matrix4 = new Matrix4();
  12081. var matrix42 = new Matrix4();
  12082. function setup(lights) {
  12083. var r = 0,
  12084. g = 0,
  12085. b = 0;
  12086. for (var _i = 0; _i < 9; _i++) {
  12087. state.probe[_i].set(0, 0, 0);
  12088. }
  12089. var directionalLength = 0;
  12090. var pointLength = 0;
  12091. var spotLength = 0;
  12092. var rectAreaLength = 0;
  12093. var hemiLength = 0;
  12094. var numDirectionalShadows = 0;
  12095. var numPointShadows = 0;
  12096. var numSpotShadows = 0;
  12097. lights.sort(shadowCastingLightsFirst);
  12098. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  12099. var light = lights[_i2];
  12100. var color = light.color;
  12101. var intensity = light.intensity;
  12102. var distance = light.distance;
  12103. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  12104. if (light.isAmbientLight) {
  12105. r += color.r * intensity;
  12106. g += color.g * intensity;
  12107. b += color.b * intensity;
  12108. } else if (light.isLightProbe) {
  12109. for (var j = 0; j < 9; j++) {
  12110. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  12111. }
  12112. } else if (light.isDirectionalLight) {
  12113. var uniforms = cache.get(light);
  12114. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  12115. if (light.castShadow) {
  12116. var shadow = light.shadow;
  12117. var shadowUniforms = shadowCache.get(light);
  12118. shadowUniforms.shadowBias = shadow.bias;
  12119. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12120. shadowUniforms.shadowRadius = shadow.radius;
  12121. shadowUniforms.shadowMapSize = shadow.mapSize;
  12122. state.directionalShadow[directionalLength] = shadowUniforms;
  12123. state.directionalShadowMap[directionalLength] = shadowMap;
  12124. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  12125. numDirectionalShadows++;
  12126. }
  12127. state.directional[directionalLength] = uniforms;
  12128. directionalLength++;
  12129. } else if (light.isSpotLight) {
  12130. var _uniforms = cache.get(light);
  12131. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  12132. _uniforms.color.copy(color).multiplyScalar(intensity);
  12133. _uniforms.distance = distance;
  12134. _uniforms.coneCos = Math.cos(light.angle);
  12135. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  12136. _uniforms.decay = light.decay;
  12137. if (light.castShadow) {
  12138. var _shadow = light.shadow;
  12139. var _shadowUniforms = shadowCache.get(light);
  12140. _shadowUniforms.shadowBias = _shadow.bias;
  12141. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  12142. _shadowUniforms.shadowRadius = _shadow.radius;
  12143. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  12144. state.spotShadow[spotLength] = _shadowUniforms;
  12145. state.spotShadowMap[spotLength] = shadowMap;
  12146. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  12147. numSpotShadows++;
  12148. }
  12149. state.spot[spotLength] = _uniforms;
  12150. spotLength++;
  12151. } else if (light.isRectAreaLight) {
  12152. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  12153. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12154. // (b) intensity is the brightness of the light
  12155. _uniforms2.color.copy(color).multiplyScalar(intensity);
  12156. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12157. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12158. state.rectArea[rectAreaLength] = _uniforms2;
  12159. rectAreaLength++;
  12160. } else if (light.isPointLight) {
  12161. var _uniforms3 = cache.get(light);
  12162. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  12163. _uniforms3.distance = light.distance;
  12164. _uniforms3.decay = light.decay;
  12165. if (light.castShadow) {
  12166. var _shadow2 = light.shadow;
  12167. var _shadowUniforms2 = shadowCache.get(light);
  12168. _shadowUniforms2.shadowBias = _shadow2.bias;
  12169. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  12170. _shadowUniforms2.shadowRadius = _shadow2.radius;
  12171. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  12172. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  12173. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  12174. state.pointShadow[pointLength] = _shadowUniforms2;
  12175. state.pointShadowMap[pointLength] = shadowMap;
  12176. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  12177. numPointShadows++;
  12178. }
  12179. state.point[pointLength] = _uniforms3;
  12180. pointLength++;
  12181. } else if (light.isHemisphereLight) {
  12182. var _uniforms4 = cache.get(light);
  12183. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  12184. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  12185. state.hemi[hemiLength] = _uniforms4;
  12186. hemiLength++;
  12187. }
  12188. }
  12189. if (rectAreaLength > 0) {
  12190. if (capabilities.isWebGL2) {
  12191. // WebGL 2
  12192. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12193. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12194. } else {
  12195. // WebGL 1
  12196. if (extensions.has('OES_texture_float_linear') === true) {
  12197. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12198. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12199. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  12200. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12201. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12202. } else {
  12203. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  12204. }
  12205. }
  12206. }
  12207. state.ambient[0] = r;
  12208. state.ambient[1] = g;
  12209. state.ambient[2] = b;
  12210. var hash = state.hash;
  12211. 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) {
  12212. state.directional.length = directionalLength;
  12213. state.spot.length = spotLength;
  12214. state.rectArea.length = rectAreaLength;
  12215. state.point.length = pointLength;
  12216. state.hemi.length = hemiLength;
  12217. state.directionalShadow.length = numDirectionalShadows;
  12218. state.directionalShadowMap.length = numDirectionalShadows;
  12219. state.pointShadow.length = numPointShadows;
  12220. state.pointShadowMap.length = numPointShadows;
  12221. state.spotShadow.length = numSpotShadows;
  12222. state.spotShadowMap.length = numSpotShadows;
  12223. state.directionalShadowMatrix.length = numDirectionalShadows;
  12224. state.pointShadowMatrix.length = numPointShadows;
  12225. state.spotShadowMatrix.length = numSpotShadows;
  12226. hash.directionalLength = directionalLength;
  12227. hash.pointLength = pointLength;
  12228. hash.spotLength = spotLength;
  12229. hash.rectAreaLength = rectAreaLength;
  12230. hash.hemiLength = hemiLength;
  12231. hash.numDirectionalShadows = numDirectionalShadows;
  12232. hash.numPointShadows = numPointShadows;
  12233. hash.numSpotShadows = numSpotShadows;
  12234. state.version = nextVersion++;
  12235. }
  12236. }
  12237. function setupView(lights, camera) {
  12238. var directionalLength = 0;
  12239. var pointLength = 0;
  12240. var spotLength = 0;
  12241. var rectAreaLength = 0;
  12242. var hemiLength = 0;
  12243. var viewMatrix = camera.matrixWorldInverse;
  12244. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  12245. var light = lights[_i3];
  12246. if (light.isDirectionalLight) {
  12247. var uniforms = state.directional[directionalLength];
  12248. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  12249. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12250. uniforms.direction.sub(vector3);
  12251. uniforms.direction.transformDirection(viewMatrix);
  12252. directionalLength++;
  12253. } else if (light.isSpotLight) {
  12254. var _uniforms5 = state.spot[spotLength];
  12255. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  12256. _uniforms5.position.applyMatrix4(viewMatrix);
  12257. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  12258. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12259. _uniforms5.direction.sub(vector3);
  12260. _uniforms5.direction.transformDirection(viewMatrix);
  12261. spotLength++;
  12262. } else if (light.isRectAreaLight) {
  12263. var _uniforms6 = state.rectArea[rectAreaLength];
  12264. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  12265. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  12266. matrix42.identity();
  12267. matrix4.copy(light.matrixWorld);
  12268. matrix4.premultiply(viewMatrix);
  12269. matrix42.extractRotation(matrix4);
  12270. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12271. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12272. _uniforms6.halfWidth.applyMatrix4(matrix42);
  12273. _uniforms6.halfHeight.applyMatrix4(matrix42);
  12274. rectAreaLength++;
  12275. } else if (light.isPointLight) {
  12276. var _uniforms7 = state.point[pointLength];
  12277. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  12278. _uniforms7.position.applyMatrix4(viewMatrix);
  12279. pointLength++;
  12280. } else if (light.isHemisphereLight) {
  12281. var _uniforms8 = state.hemi[hemiLength];
  12282. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  12283. _uniforms8.direction.transformDirection(viewMatrix);
  12284. _uniforms8.direction.normalize();
  12285. hemiLength++;
  12286. }
  12287. }
  12288. }
  12289. return {
  12290. setup: setup,
  12291. setupView: setupView,
  12292. state: state
  12293. };
  12294. }
  12295. function WebGLRenderState(extensions, capabilities) {
  12296. var lights = new WebGLLights(extensions, capabilities);
  12297. var lightsArray = [];
  12298. var shadowsArray = [];
  12299. function init() {
  12300. lightsArray.length = 0;
  12301. shadowsArray.length = 0;
  12302. }
  12303. function pushLight(light) {
  12304. lightsArray.push(light);
  12305. }
  12306. function pushShadow(shadowLight) {
  12307. shadowsArray.push(shadowLight);
  12308. }
  12309. function setupLights() {
  12310. lights.setup(lightsArray);
  12311. }
  12312. function setupLightsView(camera) {
  12313. lights.setupView(lightsArray, camera);
  12314. }
  12315. var state = {
  12316. lightsArray: lightsArray,
  12317. shadowsArray: shadowsArray,
  12318. lights: lights
  12319. };
  12320. return {
  12321. init: init,
  12322. state: state,
  12323. setupLights: setupLights,
  12324. setupLightsView: setupLightsView,
  12325. pushLight: pushLight,
  12326. pushShadow: pushShadow
  12327. };
  12328. }
  12329. function WebGLRenderStates(extensions, capabilities) {
  12330. var renderStates = new WeakMap();
  12331. function get(scene, renderCallDepth) {
  12332. if (renderCallDepth === void 0) {
  12333. renderCallDepth = 0;
  12334. }
  12335. var renderState;
  12336. if (renderStates.has(scene) === false) {
  12337. renderState = new WebGLRenderState(extensions, capabilities);
  12338. renderStates.set(scene, []);
  12339. renderStates.get(scene).push(renderState);
  12340. } else {
  12341. if (renderCallDepth >= renderStates.get(scene).length) {
  12342. renderState = new WebGLRenderState(extensions, capabilities);
  12343. renderStates.get(scene).push(renderState);
  12344. } else {
  12345. renderState = renderStates.get(scene)[renderCallDepth];
  12346. }
  12347. }
  12348. return renderState;
  12349. }
  12350. function dispose() {
  12351. renderStates = new WeakMap();
  12352. }
  12353. return {
  12354. get: get,
  12355. dispose: dispose
  12356. };
  12357. }
  12358. /**
  12359. * parameters = {
  12360. *
  12361. * opacity: <float>,
  12362. *
  12363. * map: new THREE.Texture( <Image> ),
  12364. *
  12365. * alphaMap: new THREE.Texture( <Image> ),
  12366. *
  12367. * displacementMap: new THREE.Texture( <Image> ),
  12368. * displacementScale: <float>,
  12369. * displacementBias: <float>,
  12370. *
  12371. * wireframe: <boolean>,
  12372. * wireframeLinewidth: <float>
  12373. * }
  12374. */
  12375. function MeshDepthMaterial(parameters) {
  12376. Material.call(this);
  12377. this.type = 'MeshDepthMaterial';
  12378. this.depthPacking = BasicDepthPacking;
  12379. this.skinning = false;
  12380. this.morphTargets = false;
  12381. this.map = null;
  12382. this.alphaMap = null;
  12383. this.displacementMap = null;
  12384. this.displacementScale = 1;
  12385. this.displacementBias = 0;
  12386. this.wireframe = false;
  12387. this.wireframeLinewidth = 1;
  12388. this.fog = false;
  12389. this.setValues(parameters);
  12390. }
  12391. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  12392. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12393. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12394. MeshDepthMaterial.prototype.copy = function (source) {
  12395. Material.prototype.copy.call(this, source);
  12396. this.depthPacking = source.depthPacking;
  12397. this.skinning = source.skinning;
  12398. this.morphTargets = source.morphTargets;
  12399. this.map = source.map;
  12400. this.alphaMap = source.alphaMap;
  12401. this.displacementMap = source.displacementMap;
  12402. this.displacementScale = source.displacementScale;
  12403. this.displacementBias = source.displacementBias;
  12404. this.wireframe = source.wireframe;
  12405. this.wireframeLinewidth = source.wireframeLinewidth;
  12406. return this;
  12407. };
  12408. /**
  12409. * parameters = {
  12410. *
  12411. * referencePosition: <float>,
  12412. * nearDistance: <float>,
  12413. * farDistance: <float>,
  12414. *
  12415. * skinning: <bool>,
  12416. * morphTargets: <bool>,
  12417. *
  12418. * map: new THREE.Texture( <Image> ),
  12419. *
  12420. * alphaMap: new THREE.Texture( <Image> ),
  12421. *
  12422. * displacementMap: new THREE.Texture( <Image> ),
  12423. * displacementScale: <float>,
  12424. * displacementBias: <float>
  12425. *
  12426. * }
  12427. */
  12428. function MeshDistanceMaterial(parameters) {
  12429. Material.call(this);
  12430. this.type = 'MeshDistanceMaterial';
  12431. this.referencePosition = new Vector3();
  12432. this.nearDistance = 1;
  12433. this.farDistance = 1000;
  12434. this.skinning = false;
  12435. this.morphTargets = false;
  12436. this.map = null;
  12437. this.alphaMap = null;
  12438. this.displacementMap = null;
  12439. this.displacementScale = 1;
  12440. this.displacementBias = 0;
  12441. this.fog = false;
  12442. this.setValues(parameters);
  12443. }
  12444. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  12445. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12446. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12447. MeshDistanceMaterial.prototype.copy = function (source) {
  12448. Material.prototype.copy.call(this, source);
  12449. this.referencePosition.copy(source.referencePosition);
  12450. this.nearDistance = source.nearDistance;
  12451. this.farDistance = source.farDistance;
  12452. this.skinning = source.skinning;
  12453. this.morphTargets = source.morphTargets;
  12454. this.map = source.map;
  12455. this.alphaMap = source.alphaMap;
  12456. this.displacementMap = source.displacementMap;
  12457. this.displacementScale = source.displacementScale;
  12458. this.displacementBias = source.displacementBias;
  12459. return this;
  12460. };
  12461. 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}";
  12462. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12463. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  12464. var _frustum = new Frustum();
  12465. var _shadowMapSize = new Vector2(),
  12466. _viewportSize = new Vector2(),
  12467. _viewport = new Vector4(),
  12468. _depthMaterials = [],
  12469. _distanceMaterials = [],
  12470. _materialCache = {};
  12471. var shadowSide = {
  12472. 0: BackSide,
  12473. 1: FrontSide,
  12474. 2: DoubleSide
  12475. };
  12476. var shadowMaterialVertical = new ShaderMaterial({
  12477. defines: {
  12478. SAMPLE_RATE: 2.0 / 8.0,
  12479. HALF_SAMPLE_RATE: 1.0 / 8.0
  12480. },
  12481. uniforms: {
  12482. shadow_pass: {
  12483. value: null
  12484. },
  12485. resolution: {
  12486. value: new Vector2()
  12487. },
  12488. radius: {
  12489. value: 4.0
  12490. }
  12491. },
  12492. vertexShader: vsm_vert,
  12493. fragmentShader: vsm_frag
  12494. });
  12495. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12496. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12497. var fullScreenTri = new BufferGeometry();
  12498. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12499. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12500. var scope = this;
  12501. this.enabled = false;
  12502. this.autoUpdate = true;
  12503. this.needsUpdate = false;
  12504. this.type = PCFShadowMap;
  12505. this.render = function (lights, scene, camera) {
  12506. if (scope.enabled === false) return;
  12507. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12508. if (lights.length === 0) return;
  12509. var currentRenderTarget = _renderer.getRenderTarget();
  12510. var activeCubeFace = _renderer.getActiveCubeFace();
  12511. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12512. var _state = _renderer.state; // Set GL state for depth map.
  12513. _state.setBlending(NoBlending);
  12514. _state.buffers.color.setClear(1, 1, 1, 1);
  12515. _state.buffers.depth.setTest(true);
  12516. _state.setScissorTest(false); // render depth map
  12517. for (var i = 0, il = lights.length; i < il; i++) {
  12518. var light = lights[i];
  12519. var shadow = light.shadow;
  12520. if (shadow === undefined) {
  12521. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12522. continue;
  12523. }
  12524. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12525. _shadowMapSize.copy(shadow.mapSize);
  12526. var shadowFrameExtents = shadow.getFrameExtents();
  12527. _shadowMapSize.multiply(shadowFrameExtents);
  12528. _viewportSize.copy(shadow.mapSize);
  12529. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12530. if (_shadowMapSize.x > maxTextureSize) {
  12531. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12532. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12533. shadow.mapSize.x = _viewportSize.x;
  12534. }
  12535. if (_shadowMapSize.y > maxTextureSize) {
  12536. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12537. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12538. shadow.mapSize.y = _viewportSize.y;
  12539. }
  12540. }
  12541. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12542. var pars = {
  12543. minFilter: LinearFilter,
  12544. magFilter: LinearFilter,
  12545. format: RGBAFormat
  12546. };
  12547. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12548. shadow.map.texture.name = light.name + '.shadowMap';
  12549. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12550. shadow.camera.updateProjectionMatrix();
  12551. }
  12552. if (shadow.map === null) {
  12553. var _pars = {
  12554. minFilter: NearestFilter,
  12555. magFilter: NearestFilter,
  12556. format: RGBAFormat
  12557. };
  12558. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12559. shadow.map.texture.name = light.name + '.shadowMap';
  12560. shadow.camera.updateProjectionMatrix();
  12561. }
  12562. _renderer.setRenderTarget(shadow.map);
  12563. _renderer.clear();
  12564. var viewportCount = shadow.getViewportCount();
  12565. for (var vp = 0; vp < viewportCount; vp++) {
  12566. var viewport = shadow.getViewport(vp);
  12567. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12568. _state.viewport(_viewport);
  12569. shadow.updateMatrices(light, vp);
  12570. _frustum = shadow.getFrustum();
  12571. renderObject(scene, camera, shadow.camera, light, this.type);
  12572. } // do blur pass for VSM
  12573. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12574. VSMPass(shadow, camera);
  12575. }
  12576. shadow.needsUpdate = false;
  12577. }
  12578. scope.needsUpdate = false;
  12579. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12580. };
  12581. function VSMPass(shadow, camera) {
  12582. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12583. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12584. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12585. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12586. _renderer.setRenderTarget(shadow.mapPass);
  12587. _renderer.clear();
  12588. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12589. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12590. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12591. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12592. _renderer.setRenderTarget(shadow.map);
  12593. _renderer.clear();
  12594. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12595. }
  12596. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12597. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12598. var material = _depthMaterials[index];
  12599. if (material === undefined) {
  12600. material = new MeshDepthMaterial({
  12601. depthPacking: RGBADepthPacking,
  12602. morphTargets: useMorphing,
  12603. skinning: useSkinning
  12604. });
  12605. _depthMaterials[index] = material;
  12606. }
  12607. return material;
  12608. }
  12609. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12610. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12611. var material = _distanceMaterials[index];
  12612. if (material === undefined) {
  12613. material = new MeshDistanceMaterial({
  12614. morphTargets: useMorphing,
  12615. skinning: useSkinning
  12616. });
  12617. _distanceMaterials[index] = material;
  12618. }
  12619. return material;
  12620. }
  12621. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12622. var result = null;
  12623. var getMaterialVariant = getDepthMaterialVariant;
  12624. var customMaterial = object.customDepthMaterial;
  12625. if (light.isPointLight === true) {
  12626. getMaterialVariant = getDistanceMaterialVariant;
  12627. customMaterial = object.customDistanceMaterial;
  12628. }
  12629. if (customMaterial === undefined) {
  12630. var useMorphing = false;
  12631. if (material.morphTargets === true) {
  12632. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12633. }
  12634. var useSkinning = false;
  12635. if (object.isSkinnedMesh === true) {
  12636. if (material.skinning === true) {
  12637. useSkinning = true;
  12638. } else {
  12639. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12640. }
  12641. }
  12642. var useInstancing = object.isInstancedMesh === true;
  12643. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12644. } else {
  12645. result = customMaterial;
  12646. }
  12647. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12648. // in this case we need a unique material instance reflecting the
  12649. // appropriate state
  12650. var keyA = result.uuid,
  12651. keyB = material.uuid;
  12652. var materialsForVariant = _materialCache[keyA];
  12653. if (materialsForVariant === undefined) {
  12654. materialsForVariant = {};
  12655. _materialCache[keyA] = materialsForVariant;
  12656. }
  12657. var cachedMaterial = materialsForVariant[keyB];
  12658. if (cachedMaterial === undefined) {
  12659. cachedMaterial = result.clone();
  12660. materialsForVariant[keyB] = cachedMaterial;
  12661. }
  12662. result = cachedMaterial;
  12663. }
  12664. result.visible = material.visible;
  12665. result.wireframe = material.wireframe;
  12666. if (type === VSMShadowMap) {
  12667. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12668. } else {
  12669. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12670. }
  12671. result.clipShadows = material.clipShadows;
  12672. result.clippingPlanes = material.clippingPlanes;
  12673. result.clipIntersection = material.clipIntersection;
  12674. result.wireframeLinewidth = material.wireframeLinewidth;
  12675. result.linewidth = material.linewidth;
  12676. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12677. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12678. result.nearDistance = shadowCameraNear;
  12679. result.farDistance = shadowCameraFar;
  12680. }
  12681. return result;
  12682. }
  12683. function renderObject(object, camera, shadowCamera, light, type) {
  12684. if (object.visible === false) return;
  12685. var visible = object.layers.test(camera.layers);
  12686. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12687. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12688. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12689. var geometry = _objects.update(object);
  12690. var material = object.material;
  12691. if (Array.isArray(material)) {
  12692. var groups = geometry.groups;
  12693. for (var k = 0, kl = groups.length; k < kl; k++) {
  12694. var group = groups[k];
  12695. var groupMaterial = material[group.materialIndex];
  12696. if (groupMaterial && groupMaterial.visible) {
  12697. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12698. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12699. }
  12700. }
  12701. } else if (material.visible) {
  12702. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12703. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12704. }
  12705. }
  12706. }
  12707. var children = object.children;
  12708. for (var i = 0, l = children.length; i < l; i++) {
  12709. renderObject(children[i], camera, shadowCamera, light, type);
  12710. }
  12711. }
  12712. }
  12713. function WebGLState(gl, extensions, capabilities) {
  12714. var _equationToGL, _factorToGL;
  12715. var isWebGL2 = capabilities.isWebGL2;
  12716. function ColorBuffer() {
  12717. var locked = false;
  12718. var color = new Vector4();
  12719. var currentColorMask = null;
  12720. var currentColorClear = new Vector4(0, 0, 0, 0);
  12721. return {
  12722. setMask: function setMask(colorMask) {
  12723. if (currentColorMask !== colorMask && !locked) {
  12724. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12725. currentColorMask = colorMask;
  12726. }
  12727. },
  12728. setLocked: function setLocked(lock) {
  12729. locked = lock;
  12730. },
  12731. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12732. if (premultipliedAlpha === true) {
  12733. r *= a;
  12734. g *= a;
  12735. b *= a;
  12736. }
  12737. color.set(r, g, b, a);
  12738. if (currentColorClear.equals(color) === false) {
  12739. gl.clearColor(r, g, b, a);
  12740. currentColorClear.copy(color);
  12741. }
  12742. },
  12743. reset: function reset() {
  12744. locked = false;
  12745. currentColorMask = null;
  12746. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12747. }
  12748. };
  12749. }
  12750. function DepthBuffer() {
  12751. var locked = false;
  12752. var currentDepthMask = null;
  12753. var currentDepthFunc = null;
  12754. var currentDepthClear = null;
  12755. return {
  12756. setTest: function setTest(depthTest) {
  12757. if (depthTest) {
  12758. enable(2929);
  12759. } else {
  12760. disable(2929);
  12761. }
  12762. },
  12763. setMask: function setMask(depthMask) {
  12764. if (currentDepthMask !== depthMask && !locked) {
  12765. gl.depthMask(depthMask);
  12766. currentDepthMask = depthMask;
  12767. }
  12768. },
  12769. setFunc: function setFunc(depthFunc) {
  12770. if (currentDepthFunc !== depthFunc) {
  12771. if (depthFunc) {
  12772. switch (depthFunc) {
  12773. case NeverDepth:
  12774. gl.depthFunc(512);
  12775. break;
  12776. case AlwaysDepth:
  12777. gl.depthFunc(519);
  12778. break;
  12779. case LessDepth:
  12780. gl.depthFunc(513);
  12781. break;
  12782. case LessEqualDepth:
  12783. gl.depthFunc(515);
  12784. break;
  12785. case EqualDepth:
  12786. gl.depthFunc(514);
  12787. break;
  12788. case GreaterEqualDepth:
  12789. gl.depthFunc(518);
  12790. break;
  12791. case GreaterDepth:
  12792. gl.depthFunc(516);
  12793. break;
  12794. case NotEqualDepth:
  12795. gl.depthFunc(517);
  12796. break;
  12797. default:
  12798. gl.depthFunc(515);
  12799. }
  12800. } else {
  12801. gl.depthFunc(515);
  12802. }
  12803. currentDepthFunc = depthFunc;
  12804. }
  12805. },
  12806. setLocked: function setLocked(lock) {
  12807. locked = lock;
  12808. },
  12809. setClear: function setClear(depth) {
  12810. if (currentDepthClear !== depth) {
  12811. gl.clearDepth(depth);
  12812. currentDepthClear = depth;
  12813. }
  12814. },
  12815. reset: function reset() {
  12816. locked = false;
  12817. currentDepthMask = null;
  12818. currentDepthFunc = null;
  12819. currentDepthClear = null;
  12820. }
  12821. };
  12822. }
  12823. function StencilBuffer() {
  12824. var locked = false;
  12825. var currentStencilMask = null;
  12826. var currentStencilFunc = null;
  12827. var currentStencilRef = null;
  12828. var currentStencilFuncMask = null;
  12829. var currentStencilFail = null;
  12830. var currentStencilZFail = null;
  12831. var currentStencilZPass = null;
  12832. var currentStencilClear = null;
  12833. return {
  12834. setTest: function setTest(stencilTest) {
  12835. if (!locked) {
  12836. if (stencilTest) {
  12837. enable(2960);
  12838. } else {
  12839. disable(2960);
  12840. }
  12841. }
  12842. },
  12843. setMask: function setMask(stencilMask) {
  12844. if (currentStencilMask !== stencilMask && !locked) {
  12845. gl.stencilMask(stencilMask);
  12846. currentStencilMask = stencilMask;
  12847. }
  12848. },
  12849. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12850. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12851. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12852. currentStencilFunc = stencilFunc;
  12853. currentStencilRef = stencilRef;
  12854. currentStencilFuncMask = stencilMask;
  12855. }
  12856. },
  12857. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12858. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12859. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12860. currentStencilFail = stencilFail;
  12861. currentStencilZFail = stencilZFail;
  12862. currentStencilZPass = stencilZPass;
  12863. }
  12864. },
  12865. setLocked: function setLocked(lock) {
  12866. locked = lock;
  12867. },
  12868. setClear: function setClear(stencil) {
  12869. if (currentStencilClear !== stencil) {
  12870. gl.clearStencil(stencil);
  12871. currentStencilClear = stencil;
  12872. }
  12873. },
  12874. reset: function reset() {
  12875. locked = false;
  12876. currentStencilMask = null;
  12877. currentStencilFunc = null;
  12878. currentStencilRef = null;
  12879. currentStencilFuncMask = null;
  12880. currentStencilFail = null;
  12881. currentStencilZFail = null;
  12882. currentStencilZPass = null;
  12883. currentStencilClear = null;
  12884. }
  12885. };
  12886. } //
  12887. var colorBuffer = new ColorBuffer();
  12888. var depthBuffer = new DepthBuffer();
  12889. var stencilBuffer = new StencilBuffer();
  12890. var enabledCapabilities = {};
  12891. var currentProgram = null;
  12892. var currentBlendingEnabled = null;
  12893. var currentBlending = null;
  12894. var currentBlendEquation = null;
  12895. var currentBlendSrc = null;
  12896. var currentBlendDst = null;
  12897. var currentBlendEquationAlpha = null;
  12898. var currentBlendSrcAlpha = null;
  12899. var currentBlendDstAlpha = null;
  12900. var currentPremultipledAlpha = false;
  12901. var currentFlipSided = null;
  12902. var currentCullFace = null;
  12903. var currentLineWidth = null;
  12904. var currentPolygonOffsetFactor = null;
  12905. var currentPolygonOffsetUnits = null;
  12906. var maxTextures = gl.getParameter(35661);
  12907. var lineWidthAvailable = false;
  12908. var version = 0;
  12909. var glVersion = gl.getParameter(7938);
  12910. if (glVersion.indexOf('WebGL') !== -1) {
  12911. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12912. lineWidthAvailable = version >= 1.0;
  12913. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12914. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12915. lineWidthAvailable = version >= 2.0;
  12916. }
  12917. var currentTextureSlot = null;
  12918. var currentBoundTextures = {};
  12919. var currentScissor = new Vector4();
  12920. var currentViewport = new Vector4();
  12921. function createTexture(type, target, count) {
  12922. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12923. var texture = gl.createTexture();
  12924. gl.bindTexture(type, texture);
  12925. gl.texParameteri(type, 10241, 9728);
  12926. gl.texParameteri(type, 10240, 9728);
  12927. for (var i = 0; i < count; i++) {
  12928. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12929. }
  12930. return texture;
  12931. }
  12932. var emptyTextures = {};
  12933. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12934. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12935. colorBuffer.setClear(0, 0, 0, 1);
  12936. depthBuffer.setClear(1);
  12937. stencilBuffer.setClear(0);
  12938. enable(2929);
  12939. depthBuffer.setFunc(LessEqualDepth);
  12940. setFlipSided(false);
  12941. setCullFace(CullFaceBack);
  12942. enable(2884);
  12943. setBlending(NoBlending); //
  12944. function enable(id) {
  12945. if (enabledCapabilities[id] !== true) {
  12946. gl.enable(id);
  12947. enabledCapabilities[id] = true;
  12948. }
  12949. }
  12950. function disable(id) {
  12951. if (enabledCapabilities[id] !== false) {
  12952. gl.disable(id);
  12953. enabledCapabilities[id] = false;
  12954. }
  12955. }
  12956. function useProgram(program) {
  12957. if (currentProgram !== program) {
  12958. gl.useProgram(program);
  12959. currentProgram = program;
  12960. return true;
  12961. }
  12962. return false;
  12963. }
  12964. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12965. if (isWebGL2) {
  12966. equationToGL[MinEquation] = 32775;
  12967. equationToGL[MaxEquation] = 32776;
  12968. } else {
  12969. var extension = extensions.get('EXT_blend_minmax');
  12970. if (extension !== null) {
  12971. equationToGL[MinEquation] = extension.MIN_EXT;
  12972. equationToGL[MaxEquation] = extension.MAX_EXT;
  12973. }
  12974. }
  12975. 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);
  12976. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12977. if (blending === NoBlending) {
  12978. if (currentBlendingEnabled) {
  12979. disable(3042);
  12980. currentBlendingEnabled = false;
  12981. }
  12982. return;
  12983. }
  12984. if (!currentBlendingEnabled) {
  12985. enable(3042);
  12986. currentBlendingEnabled = true;
  12987. }
  12988. if (blending !== CustomBlending) {
  12989. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12990. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12991. gl.blendEquation(32774);
  12992. currentBlendEquation = AddEquation;
  12993. currentBlendEquationAlpha = AddEquation;
  12994. }
  12995. if (premultipliedAlpha) {
  12996. switch (blending) {
  12997. case NormalBlending:
  12998. gl.blendFuncSeparate(1, 771, 1, 771);
  12999. break;
  13000. case AdditiveBlending:
  13001. gl.blendFunc(1, 1);
  13002. break;
  13003. case SubtractiveBlending:
  13004. gl.blendFuncSeparate(0, 0, 769, 771);
  13005. break;
  13006. case MultiplyBlending:
  13007. gl.blendFuncSeparate(0, 768, 0, 770);
  13008. break;
  13009. default:
  13010. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13011. break;
  13012. }
  13013. } else {
  13014. switch (blending) {
  13015. case NormalBlending:
  13016. gl.blendFuncSeparate(770, 771, 1, 771);
  13017. break;
  13018. case AdditiveBlending:
  13019. gl.blendFunc(770, 1);
  13020. break;
  13021. case SubtractiveBlending:
  13022. gl.blendFunc(0, 769);
  13023. break;
  13024. case MultiplyBlending:
  13025. gl.blendFunc(0, 768);
  13026. break;
  13027. default:
  13028. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13029. break;
  13030. }
  13031. }
  13032. currentBlendSrc = null;
  13033. currentBlendDst = null;
  13034. currentBlendSrcAlpha = null;
  13035. currentBlendDstAlpha = null;
  13036. currentBlending = blending;
  13037. currentPremultipledAlpha = premultipliedAlpha;
  13038. }
  13039. return;
  13040. } // custom blending
  13041. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13042. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13043. blendDstAlpha = blendDstAlpha || blendDst;
  13044. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  13045. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  13046. currentBlendEquation = blendEquation;
  13047. currentBlendEquationAlpha = blendEquationAlpha;
  13048. }
  13049. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  13050. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  13051. currentBlendSrc = blendSrc;
  13052. currentBlendDst = blendDst;
  13053. currentBlendSrcAlpha = blendSrcAlpha;
  13054. currentBlendDstAlpha = blendDstAlpha;
  13055. }
  13056. currentBlending = blending;
  13057. currentPremultipledAlpha = null;
  13058. }
  13059. function setMaterial(material, frontFaceCW) {
  13060. material.side === DoubleSide ? disable(2884) : enable(2884);
  13061. var flipSided = material.side === BackSide;
  13062. if (frontFaceCW) flipSided = !flipSided;
  13063. setFlipSided(flipSided);
  13064. 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);
  13065. depthBuffer.setFunc(material.depthFunc);
  13066. depthBuffer.setTest(material.depthTest);
  13067. depthBuffer.setMask(material.depthWrite);
  13068. colorBuffer.setMask(material.colorWrite);
  13069. var stencilWrite = material.stencilWrite;
  13070. stencilBuffer.setTest(stencilWrite);
  13071. if (stencilWrite) {
  13072. stencilBuffer.setMask(material.stencilWriteMask);
  13073. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  13074. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  13075. }
  13076. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  13077. } //
  13078. function setFlipSided(flipSided) {
  13079. if (currentFlipSided !== flipSided) {
  13080. if (flipSided) {
  13081. gl.frontFace(2304);
  13082. } else {
  13083. gl.frontFace(2305);
  13084. }
  13085. currentFlipSided = flipSided;
  13086. }
  13087. }
  13088. function setCullFace(cullFace) {
  13089. if (cullFace !== CullFaceNone) {
  13090. enable(2884);
  13091. if (cullFace !== currentCullFace) {
  13092. if (cullFace === CullFaceBack) {
  13093. gl.cullFace(1029);
  13094. } else if (cullFace === CullFaceFront) {
  13095. gl.cullFace(1028);
  13096. } else {
  13097. gl.cullFace(1032);
  13098. }
  13099. }
  13100. } else {
  13101. disable(2884);
  13102. }
  13103. currentCullFace = cullFace;
  13104. }
  13105. function setLineWidth(width) {
  13106. if (width !== currentLineWidth) {
  13107. if (lineWidthAvailable) gl.lineWidth(width);
  13108. currentLineWidth = width;
  13109. }
  13110. }
  13111. function setPolygonOffset(polygonOffset, factor, units) {
  13112. if (polygonOffset) {
  13113. enable(32823);
  13114. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  13115. gl.polygonOffset(factor, units);
  13116. currentPolygonOffsetFactor = factor;
  13117. currentPolygonOffsetUnits = units;
  13118. }
  13119. } else {
  13120. disable(32823);
  13121. }
  13122. }
  13123. function setScissorTest(scissorTest) {
  13124. if (scissorTest) {
  13125. enable(3089);
  13126. } else {
  13127. disable(3089);
  13128. }
  13129. } // texture
  13130. function activeTexture(webglSlot) {
  13131. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  13132. if (currentTextureSlot !== webglSlot) {
  13133. gl.activeTexture(webglSlot);
  13134. currentTextureSlot = webglSlot;
  13135. }
  13136. }
  13137. function bindTexture(webglType, webglTexture) {
  13138. if (currentTextureSlot === null) {
  13139. activeTexture();
  13140. }
  13141. var boundTexture = currentBoundTextures[currentTextureSlot];
  13142. if (boundTexture === undefined) {
  13143. boundTexture = {
  13144. type: undefined,
  13145. texture: undefined
  13146. };
  13147. currentBoundTextures[currentTextureSlot] = boundTexture;
  13148. }
  13149. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  13150. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  13151. boundTexture.type = webglType;
  13152. boundTexture.texture = webglTexture;
  13153. }
  13154. }
  13155. function unbindTexture() {
  13156. var boundTexture = currentBoundTextures[currentTextureSlot];
  13157. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  13158. gl.bindTexture(boundTexture.type, null);
  13159. boundTexture.type = undefined;
  13160. boundTexture.texture = undefined;
  13161. }
  13162. }
  13163. function compressedTexImage2D() {
  13164. try {
  13165. gl.compressedTexImage2D.apply(gl, arguments);
  13166. } catch (error) {
  13167. console.error('THREE.WebGLState:', error);
  13168. }
  13169. }
  13170. function texImage2D() {
  13171. try {
  13172. gl.texImage2D.apply(gl, arguments);
  13173. } catch (error) {
  13174. console.error('THREE.WebGLState:', error);
  13175. }
  13176. }
  13177. function texImage3D() {
  13178. try {
  13179. gl.texImage3D.apply(gl, arguments);
  13180. } catch (error) {
  13181. console.error('THREE.WebGLState:', error);
  13182. }
  13183. } //
  13184. function scissor(scissor) {
  13185. if (currentScissor.equals(scissor) === false) {
  13186. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  13187. currentScissor.copy(scissor);
  13188. }
  13189. }
  13190. function viewport(viewport) {
  13191. if (currentViewport.equals(viewport) === false) {
  13192. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  13193. currentViewport.copy(viewport);
  13194. }
  13195. } //
  13196. function reset() {
  13197. enabledCapabilities = {};
  13198. currentTextureSlot = null;
  13199. currentBoundTextures = {};
  13200. currentProgram = null;
  13201. currentBlendingEnabled = null;
  13202. currentBlending = null;
  13203. currentBlendEquation = null;
  13204. currentBlendSrc = null;
  13205. currentBlendDst = null;
  13206. currentBlendEquationAlpha = null;
  13207. currentBlendSrcAlpha = null;
  13208. currentBlendDstAlpha = null;
  13209. currentPremultipledAlpha = false;
  13210. currentFlipSided = null;
  13211. currentCullFace = null;
  13212. currentLineWidth = null;
  13213. currentPolygonOffsetFactor = null;
  13214. currentPolygonOffsetUnits = null;
  13215. colorBuffer.reset();
  13216. depthBuffer.reset();
  13217. stencilBuffer.reset();
  13218. }
  13219. return {
  13220. buffers: {
  13221. color: colorBuffer,
  13222. depth: depthBuffer,
  13223. stencil: stencilBuffer
  13224. },
  13225. enable: enable,
  13226. disable: disable,
  13227. useProgram: useProgram,
  13228. setBlending: setBlending,
  13229. setMaterial: setMaterial,
  13230. setFlipSided: setFlipSided,
  13231. setCullFace: setCullFace,
  13232. setLineWidth: setLineWidth,
  13233. setPolygonOffset: setPolygonOffset,
  13234. setScissorTest: setScissorTest,
  13235. activeTexture: activeTexture,
  13236. bindTexture: bindTexture,
  13237. unbindTexture: unbindTexture,
  13238. compressedTexImage2D: compressedTexImage2D,
  13239. texImage2D: texImage2D,
  13240. texImage3D: texImage3D,
  13241. scissor: scissor,
  13242. viewport: viewport,
  13243. reset: reset
  13244. };
  13245. }
  13246. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  13247. var _wrappingToGL, _filterToGL;
  13248. var isWebGL2 = capabilities.isWebGL2;
  13249. var maxTextures = capabilities.maxTextures;
  13250. var maxCubemapSize = capabilities.maxCubemapSize;
  13251. var maxTextureSize = capabilities.maxTextureSize;
  13252. var maxSamples = capabilities.maxSamples;
  13253. var _videoTextures = new WeakMap();
  13254. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13255. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13256. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13257. var useOffscreenCanvas = false;
  13258. try {
  13259. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  13260. } catch (err) {// Ignore any errors
  13261. }
  13262. function createCanvas(width, height) {
  13263. // Use OffscreenCanvas when available. Specially needed in web workers
  13264. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  13265. }
  13266. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  13267. var scale = 1; // handle case if texture exceeds max size
  13268. if (image.width > maxSize || image.height > maxSize) {
  13269. scale = maxSize / Math.max(image.width, image.height);
  13270. } // only perform resize if necessary
  13271. if (scale < 1 || needsPowerOfTwo === true) {
  13272. // only perform resize for certain image types
  13273. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  13274. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13275. var width = floor(scale * image.width);
  13276. var height = floor(scale * image.height);
  13277. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  13278. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  13279. canvas.width = width;
  13280. canvas.height = height;
  13281. var context = canvas.getContext('2d');
  13282. context.drawImage(image, 0, 0, width, height);
  13283. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  13284. return canvas;
  13285. } else {
  13286. if ('data' in image) {
  13287. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  13288. }
  13289. return image;
  13290. }
  13291. }
  13292. return image;
  13293. }
  13294. function isPowerOfTwo(image) {
  13295. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  13296. }
  13297. function textureNeedsPowerOfTwo(texture) {
  13298. if (isWebGL2) return false;
  13299. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13300. }
  13301. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  13302. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13303. }
  13304. function generateMipmap(target, texture, width, height) {
  13305. _gl.generateMipmap(target);
  13306. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13307. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  13308. }
  13309. function getInternalFormat(internalFormatName, glFormat, glType) {
  13310. if (isWebGL2 === false) return glFormat;
  13311. if (internalFormatName !== null) {
  13312. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  13313. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  13314. }
  13315. var internalFormat = glFormat;
  13316. if (glFormat === 6403) {
  13317. if (glType === 5126) internalFormat = 33326;
  13318. if (glType === 5131) internalFormat = 33325;
  13319. if (glType === 5121) internalFormat = 33321;
  13320. }
  13321. if (glFormat === 6407) {
  13322. if (glType === 5126) internalFormat = 34837;
  13323. if (glType === 5131) internalFormat = 34843;
  13324. if (glType === 5121) internalFormat = 32849;
  13325. }
  13326. if (glFormat === 6408) {
  13327. if (glType === 5126) internalFormat = 34836;
  13328. if (glType === 5131) internalFormat = 34842;
  13329. if (glType === 5121) internalFormat = 32856;
  13330. }
  13331. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  13332. extensions.get('EXT_color_buffer_float');
  13333. }
  13334. return internalFormat;
  13335. } // Fallback filters for non-power-of-2 textures
  13336. function filterFallback(f) {
  13337. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  13338. return 9728;
  13339. }
  13340. return 9729;
  13341. } //
  13342. function onTextureDispose(event) {
  13343. var texture = event.target;
  13344. texture.removeEventListener('dispose', onTextureDispose);
  13345. deallocateTexture(texture);
  13346. if (texture.isVideoTexture) {
  13347. _videoTextures.delete(texture);
  13348. }
  13349. info.memory.textures--;
  13350. }
  13351. function onRenderTargetDispose(event) {
  13352. var renderTarget = event.target;
  13353. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  13354. deallocateRenderTarget(renderTarget);
  13355. info.memory.textures--;
  13356. } //
  13357. function deallocateTexture(texture) {
  13358. var textureProperties = properties.get(texture);
  13359. if (textureProperties.__webglInit === undefined) return;
  13360. _gl.deleteTexture(textureProperties.__webglTexture);
  13361. properties.remove(texture);
  13362. }
  13363. function deallocateRenderTarget(renderTarget) {
  13364. var texture = renderTarget.texture;
  13365. var renderTargetProperties = properties.get(renderTarget);
  13366. var textureProperties = properties.get(texture);
  13367. if (!renderTarget) return;
  13368. if (textureProperties.__webglTexture !== undefined) {
  13369. _gl.deleteTexture(textureProperties.__webglTexture);
  13370. }
  13371. if (renderTarget.depthTexture) {
  13372. renderTarget.depthTexture.dispose();
  13373. }
  13374. if (renderTarget.isWebGLCubeRenderTarget) {
  13375. for (var i = 0; i < 6; i++) {
  13376. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  13377. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  13378. }
  13379. } else {
  13380. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  13381. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  13382. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  13383. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  13384. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  13385. }
  13386. properties.remove(texture);
  13387. properties.remove(renderTarget);
  13388. } //
  13389. var textureUnits = 0;
  13390. function resetTextureUnits() {
  13391. textureUnits = 0;
  13392. }
  13393. function allocateTextureUnit() {
  13394. var textureUnit = textureUnits;
  13395. if (textureUnit >= maxTextures) {
  13396. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  13397. }
  13398. textureUnits += 1;
  13399. return textureUnit;
  13400. } //
  13401. function setTexture2D(texture, slot) {
  13402. var textureProperties = properties.get(texture);
  13403. if (texture.isVideoTexture) updateVideoTexture(texture);
  13404. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13405. var image = texture.image;
  13406. if (image === undefined) {
  13407. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  13408. } else if (image.complete === false) {
  13409. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  13410. } else {
  13411. uploadTexture(textureProperties, texture, slot);
  13412. return;
  13413. }
  13414. }
  13415. state.activeTexture(33984 + slot);
  13416. state.bindTexture(3553, textureProperties.__webglTexture);
  13417. }
  13418. function setTexture2DArray(texture, slot) {
  13419. var textureProperties = properties.get(texture);
  13420. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13421. uploadTexture(textureProperties, texture, slot);
  13422. return;
  13423. }
  13424. state.activeTexture(33984 + slot);
  13425. state.bindTexture(35866, textureProperties.__webglTexture);
  13426. }
  13427. function setTexture3D(texture, slot) {
  13428. var textureProperties = properties.get(texture);
  13429. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13430. uploadTexture(textureProperties, texture, slot);
  13431. return;
  13432. }
  13433. state.activeTexture(33984 + slot);
  13434. state.bindTexture(32879, textureProperties.__webglTexture);
  13435. }
  13436. function setTextureCube(texture, slot) {
  13437. var textureProperties = properties.get(texture);
  13438. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13439. uploadCubeTexture(textureProperties, texture, slot);
  13440. return;
  13441. }
  13442. state.activeTexture(33984 + slot);
  13443. state.bindTexture(34067, textureProperties.__webglTexture);
  13444. }
  13445. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  13446. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  13447. function setTextureParameters(textureType, texture, supportsMips) {
  13448. if (supportsMips) {
  13449. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  13450. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  13451. if (textureType === 32879 || textureType === 35866) {
  13452. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  13453. }
  13454. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  13455. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  13456. } else {
  13457. _gl.texParameteri(textureType, 10242, 33071);
  13458. _gl.texParameteri(textureType, 10243, 33071);
  13459. if (textureType === 32879 || textureType === 35866) {
  13460. _gl.texParameteri(textureType, 32882, 33071);
  13461. }
  13462. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  13463. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  13464. }
  13465. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  13466. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  13467. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  13468. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  13469. }
  13470. }
  13471. if (extensions.has('EXT_texture_filter_anisotropic') === true) {
  13472. var extension = extensions.get('EXT_texture_filter_anisotropic');
  13473. if (texture.type === FloatType && extensions.has('OES_texture_float_linear') === false) return; // verify extension for WebGL 1 and WebGL 2
  13474. if (isWebGL2 === false && texture.type === HalfFloatType && extensions.has('OES_texture_half_float_linear') === false) return; // verify extension for WebGL 1 only
  13475. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  13476. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  13477. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  13478. }
  13479. }
  13480. }
  13481. function initTexture(textureProperties, texture) {
  13482. if (textureProperties.__webglInit === undefined) {
  13483. textureProperties.__webglInit = true;
  13484. texture.addEventListener('dispose', onTextureDispose);
  13485. textureProperties.__webglTexture = _gl.createTexture();
  13486. info.memory.textures++;
  13487. }
  13488. }
  13489. function uploadTexture(textureProperties, texture, slot) {
  13490. var textureType = 3553;
  13491. if (texture.isDataTexture2DArray) textureType = 35866;
  13492. if (texture.isDataTexture3D) textureType = 32879;
  13493. initTexture(textureProperties, texture);
  13494. state.activeTexture(33984 + slot);
  13495. state.bindTexture(textureType, textureProperties.__webglTexture);
  13496. _gl.pixelStorei(37440, texture.flipY);
  13497. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13498. _gl.pixelStorei(3317, texture.unpackAlignment);
  13499. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13500. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13501. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13502. glFormat = utils.convert(texture.format);
  13503. var glType = utils.convert(texture.type),
  13504. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13505. setTextureParameters(textureType, texture, supportsMips);
  13506. var mipmap;
  13507. var mipmaps = texture.mipmaps;
  13508. if (texture.isDepthTexture) {
  13509. // populate depth texture with dummy data
  13510. glInternalFormat = 6402;
  13511. if (isWebGL2) {
  13512. if (texture.type === FloatType) {
  13513. glInternalFormat = 36012;
  13514. } else if (texture.type === UnsignedIntType) {
  13515. glInternalFormat = 33190;
  13516. } else if (texture.type === UnsignedInt248Type) {
  13517. glInternalFormat = 35056;
  13518. } else {
  13519. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13520. }
  13521. } else {
  13522. if (texture.type === FloatType) {
  13523. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13524. }
  13525. } // validation checks for WebGL 1
  13526. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13527. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13528. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13529. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13530. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13531. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13532. texture.type = UnsignedShortType;
  13533. glType = utils.convert(texture.type);
  13534. }
  13535. }
  13536. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13537. // Depth stencil textures need the DEPTH_STENCIL internal format
  13538. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13539. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13540. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13541. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13542. if (texture.type !== UnsignedInt248Type) {
  13543. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13544. texture.type = UnsignedInt248Type;
  13545. glType = utils.convert(texture.type);
  13546. }
  13547. } //
  13548. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13549. } else if (texture.isDataTexture) {
  13550. // use manually created mipmaps if available
  13551. // if there are no manual mipmaps
  13552. // set 0 level mipmap and then use GL to generate other mipmap levels
  13553. if (mipmaps.length > 0 && supportsMips) {
  13554. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13555. mipmap = mipmaps[i];
  13556. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13557. }
  13558. texture.generateMipmaps = false;
  13559. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13560. } else {
  13561. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13562. textureProperties.__maxMipLevel = 0;
  13563. }
  13564. } else if (texture.isCompressedTexture) {
  13565. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13566. mipmap = mipmaps[_i];
  13567. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13568. if (glFormat !== null) {
  13569. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13570. } else {
  13571. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13572. }
  13573. } else {
  13574. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13575. }
  13576. }
  13577. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13578. } else if (texture.isDataTexture2DArray) {
  13579. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13580. textureProperties.__maxMipLevel = 0;
  13581. } else if (texture.isDataTexture3D) {
  13582. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13583. textureProperties.__maxMipLevel = 0;
  13584. } else {
  13585. // regular Texture (image, video, canvas)
  13586. // use manually created mipmaps if available
  13587. // if there are no manual mipmaps
  13588. // set 0 level mipmap and then use GL to generate other mipmap levels
  13589. if (mipmaps.length > 0 && supportsMips) {
  13590. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13591. mipmap = mipmaps[_i2];
  13592. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13593. }
  13594. texture.generateMipmaps = false;
  13595. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13596. } else {
  13597. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13598. textureProperties.__maxMipLevel = 0;
  13599. }
  13600. }
  13601. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13602. generateMipmap(textureType, texture, image.width, image.height);
  13603. }
  13604. textureProperties.__version = texture.version;
  13605. if (texture.onUpdate) texture.onUpdate(texture);
  13606. }
  13607. function uploadCubeTexture(textureProperties, texture, slot) {
  13608. if (texture.image.length !== 6) return;
  13609. initTexture(textureProperties, texture);
  13610. state.activeTexture(33984 + slot);
  13611. state.bindTexture(34067, textureProperties.__webglTexture);
  13612. _gl.pixelStorei(37440, texture.flipY);
  13613. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13614. _gl.pixelStorei(3317, texture.unpackAlignment);
  13615. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13616. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13617. var cubeImage = [];
  13618. for (var i = 0; i < 6; i++) {
  13619. if (!isCompressed && !isDataTexture) {
  13620. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13621. } else {
  13622. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13623. }
  13624. }
  13625. var image = cubeImage[0],
  13626. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13627. glFormat = utils.convert(texture.format),
  13628. glType = utils.convert(texture.type),
  13629. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13630. setTextureParameters(34067, texture, supportsMips);
  13631. var mipmaps;
  13632. if (isCompressed) {
  13633. for (var _i3 = 0; _i3 < 6; _i3++) {
  13634. mipmaps = cubeImage[_i3].mipmaps;
  13635. for (var j = 0; j < mipmaps.length; j++) {
  13636. var mipmap = mipmaps[j];
  13637. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13638. if (glFormat !== null) {
  13639. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13640. } else {
  13641. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13642. }
  13643. } else {
  13644. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13645. }
  13646. }
  13647. }
  13648. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13649. } else {
  13650. mipmaps = texture.mipmaps;
  13651. for (var _i4 = 0; _i4 < 6; _i4++) {
  13652. if (isDataTexture) {
  13653. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13654. for (var _j = 0; _j < mipmaps.length; _j++) {
  13655. var _mipmap = mipmaps[_j];
  13656. var mipmapImage = _mipmap.image[_i4].image;
  13657. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13658. }
  13659. } else {
  13660. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13661. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13662. var _mipmap2 = mipmaps[_j2];
  13663. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13664. }
  13665. }
  13666. }
  13667. textureProperties.__maxMipLevel = mipmaps.length;
  13668. }
  13669. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13670. // We assume images for cube map have the same size.
  13671. generateMipmap(34067, texture, image.width, image.height);
  13672. }
  13673. textureProperties.__version = texture.version;
  13674. if (texture.onUpdate) texture.onUpdate(texture);
  13675. } // Render targets
  13676. // Setup storage for target texture and bind it to correct framebuffer
  13677. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13678. var texture = renderTarget.texture;
  13679. var glFormat = utils.convert(texture.format);
  13680. var glType = utils.convert(texture.type);
  13681. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13682. if (textureTarget === 32879 || textureTarget === 35866) {
  13683. state.texImage3D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null);
  13684. } else {
  13685. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13686. }
  13687. _gl.bindFramebuffer(36160, framebuffer);
  13688. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(texture).__webglTexture, 0);
  13689. _gl.bindFramebuffer(36160, null);
  13690. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13691. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13692. _gl.bindRenderbuffer(36161, renderbuffer);
  13693. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13694. var glInternalFormat = 33189;
  13695. if (isMultisample) {
  13696. var depthTexture = renderTarget.depthTexture;
  13697. if (depthTexture && depthTexture.isDepthTexture) {
  13698. if (depthTexture.type === FloatType) {
  13699. glInternalFormat = 36012;
  13700. } else if (depthTexture.type === UnsignedIntType) {
  13701. glInternalFormat = 33190;
  13702. }
  13703. }
  13704. var samples = getRenderTargetSamples(renderTarget);
  13705. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13706. } else {
  13707. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13708. }
  13709. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13710. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13711. if (isMultisample) {
  13712. var _samples = getRenderTargetSamples(renderTarget);
  13713. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13714. } else {
  13715. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13716. }
  13717. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13718. } else {
  13719. var texture = renderTarget.texture;
  13720. var glFormat = utils.convert(texture.format);
  13721. var glType = utils.convert(texture.type);
  13722. var _glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13723. if (isMultisample) {
  13724. var _samples2 = getRenderTargetSamples(renderTarget);
  13725. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13726. } else {
  13727. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13728. }
  13729. }
  13730. _gl.bindRenderbuffer(36161, null);
  13731. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13732. function setupDepthTexture(framebuffer, renderTarget) {
  13733. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13734. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13735. _gl.bindFramebuffer(36160, framebuffer);
  13736. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13737. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13738. } // upload an empty depth texture with framebuffer size
  13739. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13740. renderTarget.depthTexture.image.width = renderTarget.width;
  13741. renderTarget.depthTexture.image.height = renderTarget.height;
  13742. renderTarget.depthTexture.needsUpdate = true;
  13743. }
  13744. setTexture2D(renderTarget.depthTexture, 0);
  13745. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13746. if (renderTarget.depthTexture.format === DepthFormat) {
  13747. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13748. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13749. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13750. } else {
  13751. throw new Error('Unknown depthTexture format');
  13752. }
  13753. } // Setup GL resources for a non-texture depth buffer
  13754. function setupDepthRenderbuffer(renderTarget) {
  13755. var renderTargetProperties = properties.get(renderTarget);
  13756. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13757. if (renderTarget.depthTexture) {
  13758. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13759. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13760. } else {
  13761. if (isCube) {
  13762. renderTargetProperties.__webglDepthbuffer = [];
  13763. for (var i = 0; i < 6; i++) {
  13764. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13765. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13766. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13767. }
  13768. } else {
  13769. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13770. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13771. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13772. }
  13773. }
  13774. _gl.bindFramebuffer(36160, null);
  13775. } // Set up GL resources for the render target
  13776. function setupRenderTarget(renderTarget) {
  13777. var texture = renderTarget.texture;
  13778. var renderTargetProperties = properties.get(renderTarget);
  13779. var textureProperties = properties.get(texture);
  13780. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13781. textureProperties.__webglTexture = _gl.createTexture();
  13782. info.memory.textures++;
  13783. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13784. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13785. var isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
  13786. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13787. if (isWebGL2 && texture.format === RGBFormat && (texture.type === FloatType || texture.type === HalfFloatType)) {
  13788. texture.format = RGBAFormat;
  13789. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13790. } // Setup framebuffer
  13791. if (isCube) {
  13792. renderTargetProperties.__webglFramebuffer = [];
  13793. for (var i = 0; i < 6; i++) {
  13794. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13795. }
  13796. } else {
  13797. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13798. if (isMultisample) {
  13799. if (isWebGL2) {
  13800. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13801. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13802. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13803. var glFormat = utils.convert(texture.format);
  13804. var glType = utils.convert(texture.type);
  13805. var glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13806. var samples = getRenderTargetSamples(renderTarget);
  13807. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13808. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13809. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13810. _gl.bindRenderbuffer(36161, null);
  13811. if (renderTarget.depthBuffer) {
  13812. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13813. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13814. }
  13815. _gl.bindFramebuffer(36160, null);
  13816. } else {
  13817. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13818. }
  13819. }
  13820. } // Setup color buffer
  13821. if (isCube) {
  13822. state.bindTexture(34067, textureProperties.__webglTexture);
  13823. setTextureParameters(34067, texture, supportsMips);
  13824. for (var _i5 = 0; _i5 < 6; _i5++) {
  13825. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13826. }
  13827. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13828. generateMipmap(34067, texture, renderTarget.width, renderTarget.height);
  13829. }
  13830. state.bindTexture(34067, null);
  13831. } else {
  13832. var glTextureType = 3553;
  13833. if (isRenderTarget3D) {
  13834. // Render targets containing layers, i.e: Texture 3D and 2d arrays
  13835. if (isWebGL2) {
  13836. var isTexture3D = texture.isDataTexture3D;
  13837. glTextureType = isTexture3D ? 32879 : 35866;
  13838. } else {
  13839. console.warn('THREE.DataTexture3D and THREE.DataTexture2DArray only supported with WebGL2.');
  13840. }
  13841. }
  13842. state.bindTexture(glTextureType, textureProperties.__webglTexture);
  13843. setTextureParameters(glTextureType, texture, supportsMips);
  13844. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, glTextureType);
  13845. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13846. generateMipmap(3553, texture, renderTarget.width, renderTarget.height);
  13847. }
  13848. state.bindTexture(3553, null);
  13849. } // Setup depth and stencil buffers
  13850. if (renderTarget.depthBuffer) {
  13851. setupDepthRenderbuffer(renderTarget);
  13852. }
  13853. }
  13854. function updateRenderTargetMipmap(renderTarget) {
  13855. var texture = renderTarget.texture;
  13856. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13857. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13858. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13859. var webglTexture = properties.get(texture).__webglTexture;
  13860. state.bindTexture(target, webglTexture);
  13861. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13862. state.bindTexture(target, null);
  13863. }
  13864. }
  13865. function updateMultisampleRenderTarget(renderTarget) {
  13866. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13867. if (isWebGL2) {
  13868. var renderTargetProperties = properties.get(renderTarget);
  13869. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13870. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13871. var width = renderTarget.width;
  13872. var height = renderTarget.height;
  13873. var mask = 16384;
  13874. if (renderTarget.depthBuffer) mask |= 256;
  13875. if (renderTarget.stencilBuffer) mask |= 1024;
  13876. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13877. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13878. } else {
  13879. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13880. }
  13881. }
  13882. }
  13883. function getRenderTargetSamples(renderTarget) {
  13884. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13885. }
  13886. function updateVideoTexture(texture) {
  13887. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13888. if (_videoTextures.get(texture) !== frame) {
  13889. _videoTextures.set(texture, frame);
  13890. texture.update();
  13891. }
  13892. } // backwards compatibility
  13893. var warnedTexture2D = false;
  13894. var warnedTextureCube = false;
  13895. function safeSetTexture2D(texture, slot) {
  13896. if (texture && texture.isWebGLRenderTarget) {
  13897. if (warnedTexture2D === false) {
  13898. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13899. warnedTexture2D = true;
  13900. }
  13901. texture = texture.texture;
  13902. }
  13903. setTexture2D(texture, slot);
  13904. }
  13905. function safeSetTextureCube(texture, slot) {
  13906. if (texture && texture.isWebGLCubeRenderTarget) {
  13907. if (warnedTextureCube === false) {
  13908. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13909. warnedTextureCube = true;
  13910. }
  13911. texture = texture.texture;
  13912. }
  13913. setTextureCube(texture, slot);
  13914. } //
  13915. this.allocateTextureUnit = allocateTextureUnit;
  13916. this.resetTextureUnits = resetTextureUnits;
  13917. this.setTexture2D = setTexture2D;
  13918. this.setTexture2DArray = setTexture2DArray;
  13919. this.setTexture3D = setTexture3D;
  13920. this.setTextureCube = setTextureCube;
  13921. this.setupRenderTarget = setupRenderTarget;
  13922. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13923. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13924. this.safeSetTexture2D = safeSetTexture2D;
  13925. this.safeSetTextureCube = safeSetTextureCube;
  13926. }
  13927. function WebGLUtils(gl, extensions, capabilities) {
  13928. var isWebGL2 = capabilities.isWebGL2;
  13929. function convert(p) {
  13930. var extension;
  13931. if (p === UnsignedByteType) return 5121;
  13932. if (p === UnsignedShort4444Type) return 32819;
  13933. if (p === UnsignedShort5551Type) return 32820;
  13934. if (p === UnsignedShort565Type) return 33635;
  13935. if (p === ByteType) return 5120;
  13936. if (p === ShortType) return 5122;
  13937. if (p === UnsignedShortType) return 5123;
  13938. if (p === IntType) return 5124;
  13939. if (p === UnsignedIntType) return 5125;
  13940. if (p === FloatType) return 5126;
  13941. if (p === HalfFloatType) {
  13942. if (isWebGL2) return 5131;
  13943. extension = extensions.get('OES_texture_half_float');
  13944. if (extension !== null) {
  13945. return extension.HALF_FLOAT_OES;
  13946. } else {
  13947. return null;
  13948. }
  13949. }
  13950. if (p === AlphaFormat) return 6406;
  13951. if (p === RGBFormat) return 6407;
  13952. if (p === RGBAFormat) return 6408;
  13953. if (p === LuminanceFormat) return 6409;
  13954. if (p === LuminanceAlphaFormat) return 6410;
  13955. if (p === DepthFormat) return 6402;
  13956. if (p === DepthStencilFormat) return 34041;
  13957. if (p === RedFormat) return 6403; // WebGL2 formats.
  13958. if (p === RedIntegerFormat) return 36244;
  13959. if (p === RGFormat) return 33319;
  13960. if (p === RGIntegerFormat) return 33320;
  13961. if (p === RGBIntegerFormat) return 36248;
  13962. if (p === RGBAIntegerFormat) return 36249;
  13963. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13964. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13965. if (extension !== null) {
  13966. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13967. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13968. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13969. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13970. } else {
  13971. return null;
  13972. }
  13973. }
  13974. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13975. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13976. if (extension !== null) {
  13977. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13978. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13979. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13980. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13981. } else {
  13982. return null;
  13983. }
  13984. }
  13985. if (p === RGB_ETC1_Format) {
  13986. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13987. if (extension !== null) {
  13988. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13989. } else {
  13990. return null;
  13991. }
  13992. }
  13993. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13994. extension = extensions.get('WEBGL_compressed_texture_etc');
  13995. if (extension !== null) {
  13996. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13997. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13998. }
  13999. }
  14000. 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) {
  14001. extension = extensions.get('WEBGL_compressed_texture_astc');
  14002. if (extension !== null) {
  14003. // TODO Complete?
  14004. return p;
  14005. } else {
  14006. return null;
  14007. }
  14008. }
  14009. if (p === RGBA_BPTC_Format) {
  14010. extension = extensions.get('EXT_texture_compression_bptc');
  14011. if (extension !== null) {
  14012. // TODO Complete?
  14013. return p;
  14014. } else {
  14015. return null;
  14016. }
  14017. }
  14018. if (p === UnsignedInt248Type) {
  14019. if (isWebGL2) return 34042;
  14020. extension = extensions.get('WEBGL_depth_texture');
  14021. if (extension !== null) {
  14022. return extension.UNSIGNED_INT_24_8_WEBGL;
  14023. } else {
  14024. return null;
  14025. }
  14026. }
  14027. }
  14028. return {
  14029. convert: convert
  14030. };
  14031. }
  14032. function ArrayCamera(array) {
  14033. if (array === void 0) {
  14034. array = [];
  14035. }
  14036. PerspectiveCamera.call(this);
  14037. this.cameras = array;
  14038. }
  14039. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  14040. constructor: ArrayCamera,
  14041. isArrayCamera: true
  14042. });
  14043. function Group() {
  14044. Object3D.call(this);
  14045. this.type = 'Group';
  14046. }
  14047. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  14048. constructor: Group,
  14049. isGroup: true
  14050. });
  14051. function WebXRController() {
  14052. this._targetRay = null;
  14053. this._grip = null;
  14054. this._hand = null;
  14055. }
  14056. Object.assign(WebXRController.prototype, {
  14057. constructor: WebXRController,
  14058. getHandSpace: function getHandSpace() {
  14059. if (this._hand === null) {
  14060. this._hand = new Group();
  14061. this._hand.matrixAutoUpdate = false;
  14062. this._hand.visible = false;
  14063. this._hand.joints = {};
  14064. this._hand.inputState = {
  14065. pinching: false
  14066. };
  14067. }
  14068. return this._hand;
  14069. },
  14070. getTargetRaySpace: function getTargetRaySpace() {
  14071. if (this._targetRay === null) {
  14072. this._targetRay = new Group();
  14073. this._targetRay.matrixAutoUpdate = false;
  14074. this._targetRay.visible = false;
  14075. }
  14076. return this._targetRay;
  14077. },
  14078. getGripSpace: function getGripSpace() {
  14079. if (this._grip === null) {
  14080. this._grip = new Group();
  14081. this._grip.matrixAutoUpdate = false;
  14082. this._grip.visible = false;
  14083. }
  14084. return this._grip;
  14085. },
  14086. dispatchEvent: function dispatchEvent(event) {
  14087. if (this._targetRay !== null) {
  14088. this._targetRay.dispatchEvent(event);
  14089. }
  14090. if (this._grip !== null) {
  14091. this._grip.dispatchEvent(event);
  14092. }
  14093. if (this._hand !== null) {
  14094. this._hand.dispatchEvent(event);
  14095. }
  14096. return this;
  14097. },
  14098. disconnect: function disconnect(inputSource) {
  14099. this.dispatchEvent({
  14100. type: 'disconnected',
  14101. data: inputSource
  14102. });
  14103. if (this._targetRay !== null) {
  14104. this._targetRay.visible = false;
  14105. }
  14106. if (this._grip !== null) {
  14107. this._grip.visible = false;
  14108. }
  14109. if (this._hand !== null) {
  14110. this._hand.visible = false;
  14111. }
  14112. return this;
  14113. },
  14114. update: function update(inputSource, frame, referenceSpace) {
  14115. var inputPose = null;
  14116. var gripPose = null;
  14117. var handPose = null;
  14118. var targetRay = this._targetRay;
  14119. var grip = this._grip;
  14120. var hand = this._hand;
  14121. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  14122. if (hand && inputSource.hand) {
  14123. handPose = true;
  14124. for (var _iterator = _createForOfIteratorHelperLoose(inputSource.hand.values()), _step; !(_step = _iterator()).done;) {
  14125. var inputjoint = _step.value;
  14126. // Update the joints groups with the XRJoint poses
  14127. var jointPose = frame.getJointPose(inputjoint, referenceSpace);
  14128. if (hand.joints[inputjoint.jointName] === undefined) {
  14129. // The transform of this joint will be updated with the joint pose on each frame
  14130. var _joint = new Group();
  14131. _joint.matrixAutoUpdate = false;
  14132. _joint.visible = false;
  14133. hand.joints[inputjoint.jointName] = _joint; // ??
  14134. hand.add(_joint);
  14135. }
  14136. var joint = hand.joints[inputjoint.jointName];
  14137. if (jointPose !== null) {
  14138. joint.matrix.fromArray(jointPose.transform.matrix);
  14139. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  14140. joint.jointRadius = jointPose.radius;
  14141. }
  14142. joint.visible = jointPose !== null;
  14143. } // Custom events
  14144. // Check pinchz
  14145. var indexTip = hand.joints['index-finger-tip'];
  14146. var thumbTip = hand.joints['thumb-tip'];
  14147. var distance = indexTip.position.distanceTo(thumbTip.position);
  14148. var distanceToPinch = 0.02;
  14149. var threshold = 0.005;
  14150. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  14151. hand.inputState.pinching = false;
  14152. this.dispatchEvent({
  14153. type: 'pinchend',
  14154. handedness: inputSource.handedness,
  14155. target: this
  14156. });
  14157. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  14158. hand.inputState.pinching = true;
  14159. this.dispatchEvent({
  14160. type: 'pinchstart',
  14161. handedness: inputSource.handedness,
  14162. target: this
  14163. });
  14164. }
  14165. } else {
  14166. if (targetRay !== null) {
  14167. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  14168. if (inputPose !== null) {
  14169. targetRay.matrix.fromArray(inputPose.transform.matrix);
  14170. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  14171. }
  14172. }
  14173. if (grip !== null && inputSource.gripSpace) {
  14174. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  14175. if (gripPose !== null) {
  14176. grip.matrix.fromArray(gripPose.transform.matrix);
  14177. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  14178. }
  14179. }
  14180. }
  14181. }
  14182. if (targetRay !== null) {
  14183. targetRay.visible = inputPose !== null;
  14184. }
  14185. if (grip !== null) {
  14186. grip.visible = gripPose !== null;
  14187. }
  14188. if (hand !== null) {
  14189. hand.visible = handPose !== null;
  14190. }
  14191. return this;
  14192. }
  14193. });
  14194. function WebXRManager(renderer, gl) {
  14195. var scope = this;
  14196. var session = null;
  14197. var framebufferScaleFactor = 1.0;
  14198. var referenceSpace = null;
  14199. var referenceSpaceType = 'local-floor';
  14200. var pose = null;
  14201. var controllers = [];
  14202. var inputSourcesMap = new Map(); //
  14203. var cameraL = new PerspectiveCamera();
  14204. cameraL.layers.enable(1);
  14205. cameraL.viewport = new Vector4();
  14206. var cameraR = new PerspectiveCamera();
  14207. cameraR.layers.enable(2);
  14208. cameraR.viewport = new Vector4();
  14209. var cameras = [cameraL, cameraR];
  14210. var cameraVR = new ArrayCamera();
  14211. cameraVR.layers.enable(1);
  14212. cameraVR.layers.enable(2);
  14213. var _currentDepthNear = null;
  14214. var _currentDepthFar = null; //
  14215. this.enabled = false;
  14216. this.isPresenting = false;
  14217. this.getController = function (index) {
  14218. var controller = controllers[index];
  14219. if (controller === undefined) {
  14220. controller = new WebXRController();
  14221. controllers[index] = controller;
  14222. }
  14223. return controller.getTargetRaySpace();
  14224. };
  14225. this.getControllerGrip = function (index) {
  14226. var controller = controllers[index];
  14227. if (controller === undefined) {
  14228. controller = new WebXRController();
  14229. controllers[index] = controller;
  14230. }
  14231. return controller.getGripSpace();
  14232. };
  14233. this.getHand = function (index) {
  14234. var controller = controllers[index];
  14235. if (controller === undefined) {
  14236. controller = new WebXRController();
  14237. controllers[index] = controller;
  14238. }
  14239. return controller.getHandSpace();
  14240. }; //
  14241. function onSessionEvent(event) {
  14242. var controller = inputSourcesMap.get(event.inputSource);
  14243. if (controller) {
  14244. controller.dispatchEvent({
  14245. type: event.type,
  14246. data: event.inputSource
  14247. });
  14248. }
  14249. }
  14250. function onSessionEnd() {
  14251. inputSourcesMap.forEach(function (controller, inputSource) {
  14252. controller.disconnect(inputSource);
  14253. });
  14254. inputSourcesMap.clear();
  14255. _currentDepthNear = null;
  14256. _currentDepthFar = null; //
  14257. renderer.setFramebuffer(null);
  14258. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  14259. animation.stop();
  14260. scope.isPresenting = false;
  14261. scope.dispatchEvent({
  14262. type: 'sessionend'
  14263. });
  14264. }
  14265. this.setFramebufferScaleFactor = function (value) {
  14266. framebufferScaleFactor = value;
  14267. if (scope.isPresenting === true) {
  14268. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  14269. }
  14270. };
  14271. this.setReferenceSpaceType = function (value) {
  14272. referenceSpaceType = value;
  14273. if (scope.isPresenting === true) {
  14274. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  14275. }
  14276. };
  14277. this.getReferenceSpace = function () {
  14278. return referenceSpace;
  14279. };
  14280. this.getSession = function () {
  14281. return session;
  14282. };
  14283. this.setSession = /*#__PURE__*/function () {
  14284. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
  14285. var attributes, layerInit, baseLayer;
  14286. return regeneratorRuntime.wrap(function _callee$(_context) {
  14287. while (1) {
  14288. switch (_context.prev = _context.next) {
  14289. case 0:
  14290. session = value;
  14291. if (!(session !== null)) {
  14292. _context.next = 24;
  14293. break;
  14294. }
  14295. session.addEventListener('select', onSessionEvent);
  14296. session.addEventListener('selectstart', onSessionEvent);
  14297. session.addEventListener('selectend', onSessionEvent);
  14298. session.addEventListener('squeeze', onSessionEvent);
  14299. session.addEventListener('squeezestart', onSessionEvent);
  14300. session.addEventListener('squeezeend', onSessionEvent);
  14301. session.addEventListener('end', onSessionEnd);
  14302. session.addEventListener('inputsourceschange', onInputSourcesChange);
  14303. attributes = gl.getContextAttributes();
  14304. if (!(attributes.xrCompatible !== true)) {
  14305. _context.next = 14;
  14306. break;
  14307. }
  14308. _context.next = 14;
  14309. return gl.makeXRCompatible();
  14310. case 14:
  14311. layerInit = {
  14312. antialias: attributes.antialias,
  14313. alpha: attributes.alpha,
  14314. depth: attributes.depth,
  14315. stencil: attributes.stencil,
  14316. framebufferScaleFactor: framebufferScaleFactor
  14317. }; // eslint-disable-next-line no-undef
  14318. baseLayer = new XRWebGLLayer(session, gl, layerInit);
  14319. session.updateRenderState({
  14320. baseLayer: baseLayer
  14321. });
  14322. _context.next = 19;
  14323. return session.requestReferenceSpace(referenceSpaceType);
  14324. case 19:
  14325. referenceSpace = _context.sent;
  14326. animation.setContext(session);
  14327. animation.start();
  14328. scope.isPresenting = true;
  14329. scope.dispatchEvent({
  14330. type: 'sessionstart'
  14331. });
  14332. case 24:
  14333. case "end":
  14334. return _context.stop();
  14335. }
  14336. }
  14337. }, _callee);
  14338. }));
  14339. return function (_x) {
  14340. return _ref.apply(this, arguments);
  14341. };
  14342. }();
  14343. function onInputSourcesChange(event) {
  14344. var inputSources = session.inputSources; // Assign inputSources to available controllers
  14345. for (var i = 0; i < controllers.length; i++) {
  14346. inputSourcesMap.set(inputSources[i], controllers[i]);
  14347. } // Notify disconnected
  14348. for (var _i = 0; _i < event.removed.length; _i++) {
  14349. var inputSource = event.removed[_i];
  14350. var controller = inputSourcesMap.get(inputSource);
  14351. if (controller) {
  14352. controller.dispatchEvent({
  14353. type: 'disconnected',
  14354. data: inputSource
  14355. });
  14356. inputSourcesMap.delete(inputSource);
  14357. }
  14358. } // Notify connected
  14359. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  14360. var _inputSource = event.added[_i2];
  14361. var _controller = inputSourcesMap.get(_inputSource);
  14362. if (_controller) {
  14363. _controller.dispatchEvent({
  14364. type: 'connected',
  14365. data: _inputSource
  14366. });
  14367. }
  14368. }
  14369. } //
  14370. var cameraLPos = new Vector3();
  14371. var cameraRPos = new Vector3();
  14372. /**
  14373. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14374. * the cameras' projection and world matrices have already been set.
  14375. * And that near and far planes are identical for both cameras.
  14376. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14377. */
  14378. function setProjectionFromUnion(camera, cameraL, cameraR) {
  14379. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  14380. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  14381. var ipd = cameraLPos.distanceTo(cameraRPos);
  14382. var projL = cameraL.projectionMatrix.elements;
  14383. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  14384. // most likely identical top and bottom frustum extents.
  14385. // Use the left camera for these values.
  14386. var near = projL[14] / (projL[10] - 1);
  14387. var far = projL[14] / (projL[10] + 1);
  14388. var topFov = (projL[9] + 1) / projL[5];
  14389. var bottomFov = (projL[9] - 1) / projL[5];
  14390. var leftFov = (projL[8] - 1) / projL[0];
  14391. var rightFov = (projR[8] + 1) / projR[0];
  14392. var left = near * leftFov;
  14393. var right = near * rightFov; // Calculate the new camera's position offset from the
  14394. // left camera. xOffset should be roughly half `ipd`.
  14395. var zOffset = ipd / (-leftFov + rightFov);
  14396. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  14397. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  14398. camera.translateX(xOffset);
  14399. camera.translateZ(zOffset);
  14400. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  14401. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  14402. // the values so that the near plane's position does not change in world space,
  14403. // although must now be relative to the new union camera.
  14404. var near2 = near + zOffset;
  14405. var far2 = far + zOffset;
  14406. var left2 = left - xOffset;
  14407. var right2 = right + (ipd - xOffset);
  14408. var top2 = topFov * far / far2 * near2;
  14409. var bottom2 = bottomFov * far / far2 * near2;
  14410. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  14411. }
  14412. function updateCamera(camera, parent) {
  14413. if (parent === null) {
  14414. camera.matrixWorld.copy(camera.matrix);
  14415. } else {
  14416. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  14417. }
  14418. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  14419. }
  14420. this.getCamera = function (camera) {
  14421. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14422. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14423. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  14424. // Note that the new renderState won't apply until the next frame. See #18320
  14425. session.updateRenderState({
  14426. depthNear: cameraVR.near,
  14427. depthFar: cameraVR.far
  14428. });
  14429. _currentDepthNear = cameraVR.near;
  14430. _currentDepthFar = cameraVR.far;
  14431. }
  14432. var parent = camera.parent;
  14433. var cameras = cameraVR.cameras;
  14434. updateCamera(cameraVR, parent);
  14435. for (var i = 0; i < cameras.length; i++) {
  14436. updateCamera(cameras[i], parent);
  14437. } // update camera and its children
  14438. camera.matrixWorld.copy(cameraVR.matrixWorld);
  14439. camera.matrix.copy(cameraVR.matrix);
  14440. camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
  14441. var children = camera.children;
  14442. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  14443. children[_i3].updateMatrixWorld(true);
  14444. } // update projection matrix for proper view frustum culling
  14445. if (cameras.length === 2) {
  14446. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  14447. } else {
  14448. // assume single camera setup (AR)
  14449. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  14450. }
  14451. return cameraVR;
  14452. }; // Animation Loop
  14453. var onAnimationFrameCallback = null;
  14454. function onAnimationFrame(time, frame) {
  14455. pose = frame.getViewerPose(referenceSpace);
  14456. if (pose !== null) {
  14457. var views = pose.views;
  14458. var baseLayer = session.renderState.baseLayer;
  14459. renderer.setFramebuffer(baseLayer.framebuffer);
  14460. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  14461. if (views.length !== cameraVR.cameras.length) {
  14462. cameraVR.cameras.length = 0;
  14463. cameraVRNeedsUpdate = true;
  14464. }
  14465. for (var i = 0; i < views.length; i++) {
  14466. var view = views[i];
  14467. var viewport = baseLayer.getViewport(view);
  14468. var camera = cameras[i];
  14469. camera.matrix.fromArray(view.transform.matrix);
  14470. camera.projectionMatrix.fromArray(view.projectionMatrix);
  14471. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  14472. if (i === 0) {
  14473. cameraVR.matrix.copy(camera.matrix);
  14474. }
  14475. if (cameraVRNeedsUpdate === true) {
  14476. cameraVR.cameras.push(camera);
  14477. }
  14478. }
  14479. } //
  14480. var inputSources = session.inputSources;
  14481. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  14482. var controller = controllers[_i4];
  14483. var inputSource = inputSources[_i4];
  14484. controller.update(inputSource, frame, referenceSpace);
  14485. }
  14486. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  14487. }
  14488. var animation = new WebGLAnimation();
  14489. animation.setAnimationLoop(onAnimationFrame);
  14490. this.setAnimationLoop = function (callback) {
  14491. onAnimationFrameCallback = callback;
  14492. };
  14493. this.dispose = function () {};
  14494. }
  14495. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  14496. function WebGLMaterials(properties) {
  14497. function refreshFogUniforms(uniforms, fog) {
  14498. uniforms.fogColor.value.copy(fog.color);
  14499. if (fog.isFog) {
  14500. uniforms.fogNear.value = fog.near;
  14501. uniforms.fogFar.value = fog.far;
  14502. } else if (fog.isFogExp2) {
  14503. uniforms.fogDensity.value = fog.density;
  14504. }
  14505. }
  14506. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  14507. if (material.isMeshBasicMaterial) {
  14508. refreshUniformsCommon(uniforms, material);
  14509. } else if (material.isMeshLambertMaterial) {
  14510. refreshUniformsCommon(uniforms, material);
  14511. refreshUniformsLambert(uniforms, material);
  14512. } else if (material.isMeshToonMaterial) {
  14513. refreshUniformsCommon(uniforms, material);
  14514. refreshUniformsToon(uniforms, material);
  14515. } else if (material.isMeshPhongMaterial) {
  14516. refreshUniformsCommon(uniforms, material);
  14517. refreshUniformsPhong(uniforms, material);
  14518. } else if (material.isMeshStandardMaterial) {
  14519. refreshUniformsCommon(uniforms, material);
  14520. if (material.isMeshPhysicalMaterial) {
  14521. refreshUniformsPhysical(uniforms, material);
  14522. } else {
  14523. refreshUniformsStandard(uniforms, material);
  14524. }
  14525. } else if (material.isMeshMatcapMaterial) {
  14526. refreshUniformsCommon(uniforms, material);
  14527. refreshUniformsMatcap(uniforms, material);
  14528. } else if (material.isMeshDepthMaterial) {
  14529. refreshUniformsCommon(uniforms, material);
  14530. refreshUniformsDepth(uniforms, material);
  14531. } else if (material.isMeshDistanceMaterial) {
  14532. refreshUniformsCommon(uniforms, material);
  14533. refreshUniformsDistance(uniforms, material);
  14534. } else if (material.isMeshNormalMaterial) {
  14535. refreshUniformsCommon(uniforms, material);
  14536. refreshUniformsNormal(uniforms, material);
  14537. } else if (material.isLineBasicMaterial) {
  14538. refreshUniformsLine(uniforms, material);
  14539. if (material.isLineDashedMaterial) {
  14540. refreshUniformsDash(uniforms, material);
  14541. }
  14542. } else if (material.isPointsMaterial) {
  14543. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14544. } else if (material.isSpriteMaterial) {
  14545. refreshUniformsSprites(uniforms, material);
  14546. } else if (material.isShadowMaterial) {
  14547. uniforms.color.value.copy(material.color);
  14548. uniforms.opacity.value = material.opacity;
  14549. } else if (material.isShaderMaterial) {
  14550. material.uniformsNeedUpdate = false; // #15581
  14551. }
  14552. }
  14553. function refreshUniformsCommon(uniforms, material) {
  14554. uniforms.opacity.value = material.opacity;
  14555. if (material.color) {
  14556. uniforms.diffuse.value.copy(material.color);
  14557. }
  14558. if (material.emissive) {
  14559. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14560. }
  14561. if (material.map) {
  14562. uniforms.map.value = material.map;
  14563. }
  14564. if (material.alphaMap) {
  14565. uniforms.alphaMap.value = material.alphaMap;
  14566. }
  14567. if (material.specularMap) {
  14568. uniforms.specularMap.value = material.specularMap;
  14569. }
  14570. var envMap = properties.get(material).envMap;
  14571. if (envMap) {
  14572. uniforms.envMap.value = envMap;
  14573. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14574. uniforms.reflectivity.value = material.reflectivity;
  14575. uniforms.refractionRatio.value = material.refractionRatio;
  14576. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14577. if (maxMipLevel !== undefined) {
  14578. uniforms.maxMipLevel.value = maxMipLevel;
  14579. }
  14580. }
  14581. if (material.lightMap) {
  14582. uniforms.lightMap.value = material.lightMap;
  14583. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14584. }
  14585. if (material.aoMap) {
  14586. uniforms.aoMap.value = material.aoMap;
  14587. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14588. } // uv repeat and offset setting priorities
  14589. // 1. color map
  14590. // 2. specular map
  14591. // 3. displacementMap map
  14592. // 4. normal map
  14593. // 5. bump map
  14594. // 6. roughnessMap map
  14595. // 7. metalnessMap map
  14596. // 8. alphaMap map
  14597. // 9. emissiveMap map
  14598. // 10. clearcoat map
  14599. // 11. clearcoat normal map
  14600. // 12. clearcoat roughnessMap map
  14601. var uvScaleMap;
  14602. if (material.map) {
  14603. uvScaleMap = material.map;
  14604. } else if (material.specularMap) {
  14605. uvScaleMap = material.specularMap;
  14606. } else if (material.displacementMap) {
  14607. uvScaleMap = material.displacementMap;
  14608. } else if (material.normalMap) {
  14609. uvScaleMap = material.normalMap;
  14610. } else if (material.bumpMap) {
  14611. uvScaleMap = material.bumpMap;
  14612. } else if (material.roughnessMap) {
  14613. uvScaleMap = material.roughnessMap;
  14614. } else if (material.metalnessMap) {
  14615. uvScaleMap = material.metalnessMap;
  14616. } else if (material.alphaMap) {
  14617. uvScaleMap = material.alphaMap;
  14618. } else if (material.emissiveMap) {
  14619. uvScaleMap = material.emissiveMap;
  14620. } else if (material.clearcoatMap) {
  14621. uvScaleMap = material.clearcoatMap;
  14622. } else if (material.clearcoatNormalMap) {
  14623. uvScaleMap = material.clearcoatNormalMap;
  14624. } else if (material.clearcoatRoughnessMap) {
  14625. uvScaleMap = material.clearcoatRoughnessMap;
  14626. }
  14627. if (uvScaleMap !== undefined) {
  14628. // backwards compatibility
  14629. if (uvScaleMap.isWebGLRenderTarget) {
  14630. uvScaleMap = uvScaleMap.texture;
  14631. }
  14632. if (uvScaleMap.matrixAutoUpdate === true) {
  14633. uvScaleMap.updateMatrix();
  14634. }
  14635. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14636. } // uv repeat and offset setting priorities for uv2
  14637. // 1. ao map
  14638. // 2. light map
  14639. var uv2ScaleMap;
  14640. if (material.aoMap) {
  14641. uv2ScaleMap = material.aoMap;
  14642. } else if (material.lightMap) {
  14643. uv2ScaleMap = material.lightMap;
  14644. }
  14645. if (uv2ScaleMap !== undefined) {
  14646. // backwards compatibility
  14647. if (uv2ScaleMap.isWebGLRenderTarget) {
  14648. uv2ScaleMap = uv2ScaleMap.texture;
  14649. }
  14650. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14651. uv2ScaleMap.updateMatrix();
  14652. }
  14653. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14654. }
  14655. }
  14656. function refreshUniformsLine(uniforms, material) {
  14657. uniforms.diffuse.value.copy(material.color);
  14658. uniforms.opacity.value = material.opacity;
  14659. }
  14660. function refreshUniformsDash(uniforms, material) {
  14661. uniforms.dashSize.value = material.dashSize;
  14662. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14663. uniforms.scale.value = material.scale;
  14664. }
  14665. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14666. uniforms.diffuse.value.copy(material.color);
  14667. uniforms.opacity.value = material.opacity;
  14668. uniforms.size.value = material.size * pixelRatio;
  14669. uniforms.scale.value = height * 0.5;
  14670. if (material.map) {
  14671. uniforms.map.value = material.map;
  14672. }
  14673. if (material.alphaMap) {
  14674. uniforms.alphaMap.value = material.alphaMap;
  14675. } // uv repeat and offset setting priorities
  14676. // 1. color map
  14677. // 2. alpha map
  14678. var uvScaleMap;
  14679. if (material.map) {
  14680. uvScaleMap = material.map;
  14681. } else if (material.alphaMap) {
  14682. uvScaleMap = material.alphaMap;
  14683. }
  14684. if (uvScaleMap !== undefined) {
  14685. if (uvScaleMap.matrixAutoUpdate === true) {
  14686. uvScaleMap.updateMatrix();
  14687. }
  14688. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14689. }
  14690. }
  14691. function refreshUniformsSprites(uniforms, material) {
  14692. uniforms.diffuse.value.copy(material.color);
  14693. uniforms.opacity.value = material.opacity;
  14694. uniforms.rotation.value = material.rotation;
  14695. if (material.map) {
  14696. uniforms.map.value = material.map;
  14697. }
  14698. if (material.alphaMap) {
  14699. uniforms.alphaMap.value = material.alphaMap;
  14700. } // uv repeat and offset setting priorities
  14701. // 1. color map
  14702. // 2. alpha map
  14703. var uvScaleMap;
  14704. if (material.map) {
  14705. uvScaleMap = material.map;
  14706. } else if (material.alphaMap) {
  14707. uvScaleMap = material.alphaMap;
  14708. }
  14709. if (uvScaleMap !== undefined) {
  14710. if (uvScaleMap.matrixAutoUpdate === true) {
  14711. uvScaleMap.updateMatrix();
  14712. }
  14713. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14714. }
  14715. }
  14716. function refreshUniformsLambert(uniforms, material) {
  14717. if (material.emissiveMap) {
  14718. uniforms.emissiveMap.value = material.emissiveMap;
  14719. }
  14720. }
  14721. function refreshUniformsPhong(uniforms, material) {
  14722. uniforms.specular.value.copy(material.specular);
  14723. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14724. if (material.emissiveMap) {
  14725. uniforms.emissiveMap.value = material.emissiveMap;
  14726. }
  14727. if (material.bumpMap) {
  14728. uniforms.bumpMap.value = material.bumpMap;
  14729. uniforms.bumpScale.value = material.bumpScale;
  14730. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14731. }
  14732. if (material.normalMap) {
  14733. uniforms.normalMap.value = material.normalMap;
  14734. uniforms.normalScale.value.copy(material.normalScale);
  14735. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14736. }
  14737. if (material.displacementMap) {
  14738. uniforms.displacementMap.value = material.displacementMap;
  14739. uniforms.displacementScale.value = material.displacementScale;
  14740. uniforms.displacementBias.value = material.displacementBias;
  14741. }
  14742. }
  14743. function refreshUniformsToon(uniforms, material) {
  14744. if (material.gradientMap) {
  14745. uniforms.gradientMap.value = material.gradientMap;
  14746. }
  14747. if (material.emissiveMap) {
  14748. uniforms.emissiveMap.value = material.emissiveMap;
  14749. }
  14750. if (material.bumpMap) {
  14751. uniforms.bumpMap.value = material.bumpMap;
  14752. uniforms.bumpScale.value = material.bumpScale;
  14753. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14754. }
  14755. if (material.normalMap) {
  14756. uniforms.normalMap.value = material.normalMap;
  14757. uniforms.normalScale.value.copy(material.normalScale);
  14758. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14759. }
  14760. if (material.displacementMap) {
  14761. uniforms.displacementMap.value = material.displacementMap;
  14762. uniforms.displacementScale.value = material.displacementScale;
  14763. uniforms.displacementBias.value = material.displacementBias;
  14764. }
  14765. }
  14766. function refreshUniformsStandard(uniforms, material) {
  14767. uniforms.roughness.value = material.roughness;
  14768. uniforms.metalness.value = material.metalness;
  14769. if (material.roughnessMap) {
  14770. uniforms.roughnessMap.value = material.roughnessMap;
  14771. }
  14772. if (material.metalnessMap) {
  14773. uniforms.metalnessMap.value = material.metalnessMap;
  14774. }
  14775. if (material.emissiveMap) {
  14776. uniforms.emissiveMap.value = material.emissiveMap;
  14777. }
  14778. if (material.bumpMap) {
  14779. uniforms.bumpMap.value = material.bumpMap;
  14780. uniforms.bumpScale.value = material.bumpScale;
  14781. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14782. }
  14783. if (material.normalMap) {
  14784. uniforms.normalMap.value = material.normalMap;
  14785. uniforms.normalScale.value.copy(material.normalScale);
  14786. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14787. }
  14788. if (material.displacementMap) {
  14789. uniforms.displacementMap.value = material.displacementMap;
  14790. uniforms.displacementScale.value = material.displacementScale;
  14791. uniforms.displacementBias.value = material.displacementBias;
  14792. }
  14793. var envMap = properties.get(material).envMap;
  14794. if (envMap) {
  14795. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14796. uniforms.envMapIntensity.value = material.envMapIntensity;
  14797. }
  14798. }
  14799. function refreshUniformsPhysical(uniforms, material) {
  14800. refreshUniformsStandard(uniforms, material);
  14801. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14802. uniforms.clearcoat.value = material.clearcoat;
  14803. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14804. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14805. if (material.clearcoatMap) {
  14806. uniforms.clearcoatMap.value = material.clearcoatMap;
  14807. }
  14808. if (material.clearcoatRoughnessMap) {
  14809. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14810. }
  14811. if (material.clearcoatNormalMap) {
  14812. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14813. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14814. if (material.side === BackSide) {
  14815. uniforms.clearcoatNormalScale.value.negate();
  14816. }
  14817. }
  14818. uniforms.transmission.value = material.transmission;
  14819. if (material.transmissionMap) {
  14820. uniforms.transmissionMap.value = material.transmissionMap;
  14821. }
  14822. }
  14823. function refreshUniformsMatcap(uniforms, material) {
  14824. if (material.matcap) {
  14825. uniforms.matcap.value = material.matcap;
  14826. }
  14827. if (material.bumpMap) {
  14828. uniforms.bumpMap.value = material.bumpMap;
  14829. uniforms.bumpScale.value = material.bumpScale;
  14830. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14831. }
  14832. if (material.normalMap) {
  14833. uniforms.normalMap.value = material.normalMap;
  14834. uniforms.normalScale.value.copy(material.normalScale);
  14835. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14836. }
  14837. if (material.displacementMap) {
  14838. uniforms.displacementMap.value = material.displacementMap;
  14839. uniforms.displacementScale.value = material.displacementScale;
  14840. uniforms.displacementBias.value = material.displacementBias;
  14841. }
  14842. }
  14843. function refreshUniformsDepth(uniforms, material) {
  14844. if (material.displacementMap) {
  14845. uniforms.displacementMap.value = material.displacementMap;
  14846. uniforms.displacementScale.value = material.displacementScale;
  14847. uniforms.displacementBias.value = material.displacementBias;
  14848. }
  14849. }
  14850. function refreshUniformsDistance(uniforms, material) {
  14851. if (material.displacementMap) {
  14852. uniforms.displacementMap.value = material.displacementMap;
  14853. uniforms.displacementScale.value = material.displacementScale;
  14854. uniforms.displacementBias.value = material.displacementBias;
  14855. }
  14856. uniforms.referencePosition.value.copy(material.referencePosition);
  14857. uniforms.nearDistance.value = material.nearDistance;
  14858. uniforms.farDistance.value = material.farDistance;
  14859. }
  14860. function refreshUniformsNormal(uniforms, material) {
  14861. if (material.bumpMap) {
  14862. uniforms.bumpMap.value = material.bumpMap;
  14863. uniforms.bumpScale.value = material.bumpScale;
  14864. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14865. }
  14866. if (material.normalMap) {
  14867. uniforms.normalMap.value = material.normalMap;
  14868. uniforms.normalScale.value.copy(material.normalScale);
  14869. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14870. }
  14871. if (material.displacementMap) {
  14872. uniforms.displacementMap.value = material.displacementMap;
  14873. uniforms.displacementScale.value = material.displacementScale;
  14874. uniforms.displacementBias.value = material.displacementBias;
  14875. }
  14876. }
  14877. return {
  14878. refreshFogUniforms: refreshFogUniforms,
  14879. refreshMaterialUniforms: refreshMaterialUniforms
  14880. };
  14881. }
  14882. function createCanvasElement() {
  14883. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14884. canvas.style.display = 'block';
  14885. return canvas;
  14886. }
  14887. function WebGLRenderer(parameters) {
  14888. parameters = parameters || {};
  14889. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14890. _context = parameters.context !== undefined ? parameters.context : null,
  14891. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14892. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14893. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14894. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14895. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14896. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14897. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14898. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14899. var currentRenderList = null;
  14900. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14901. // We track this so that the nested render call gets its state isolated from the parent render call.
  14902. var renderStateStack = []; // public properties
  14903. this.domElement = _canvas; // Debug configuration container
  14904. this.debug = {
  14905. /**
  14906. * Enables error checking and reporting when shader programs are being compiled
  14907. * @type {boolean}
  14908. */
  14909. checkShaderErrors: true
  14910. }; // clearing
  14911. this.autoClear = true;
  14912. this.autoClearColor = true;
  14913. this.autoClearDepth = true;
  14914. this.autoClearStencil = true; // scene graph
  14915. this.sortObjects = true; // user-defined clipping
  14916. this.clippingPlanes = [];
  14917. this.localClippingEnabled = false; // physically based shading
  14918. this.gammaFactor = 2.0; // for backwards compatibility
  14919. this.outputEncoding = LinearEncoding; // physical lights
  14920. this.physicallyCorrectLights = false; // tone mapping
  14921. this.toneMapping = NoToneMapping;
  14922. this.toneMappingExposure = 1.0; // morphs
  14923. this.maxMorphTargets = 8;
  14924. this.maxMorphNormals = 4; // internal properties
  14925. var _this = this;
  14926. var _isContextLost = false; // internal state cache
  14927. var _framebuffer = null;
  14928. var _currentActiveCubeFace = 0;
  14929. var _currentActiveMipmapLevel = 0;
  14930. var _currentRenderTarget = null;
  14931. var _currentFramebuffer = null;
  14932. var _currentMaterialId = -1;
  14933. var _currentCamera = null;
  14934. var _currentViewport = new Vector4();
  14935. var _currentScissor = new Vector4();
  14936. var _currentScissorTest = null; //
  14937. var _width = _canvas.width;
  14938. var _height = _canvas.height;
  14939. var _pixelRatio = 1;
  14940. var _opaqueSort = null;
  14941. var _transparentSort = null;
  14942. var _viewport = new Vector4(0, 0, _width, _height);
  14943. var _scissor = new Vector4(0, 0, _width, _height);
  14944. var _scissorTest = false; // frustum
  14945. var _frustum = new Frustum(); // clipping
  14946. var _clippingEnabled = false;
  14947. var _localClippingEnabled = false; // camera matrices cache
  14948. var _projScreenMatrix = new Matrix4();
  14949. var _vector3 = new Vector3();
  14950. var _emptyScene = {
  14951. background: null,
  14952. fog: null,
  14953. environment: null,
  14954. overrideMaterial: null,
  14955. isScene: true
  14956. };
  14957. function getTargetPixelRatio() {
  14958. return _currentRenderTarget === null ? _pixelRatio : 1;
  14959. } // initialize
  14960. var _gl = _context;
  14961. function getContext(contextNames, contextAttributes) {
  14962. for (var i = 0; i < contextNames.length; i++) {
  14963. var contextName = contextNames[i];
  14964. var context = _canvas.getContext(contextName, contextAttributes);
  14965. if (context !== null) return context;
  14966. }
  14967. return null;
  14968. }
  14969. try {
  14970. var contextAttributes = {
  14971. alpha: _alpha,
  14972. depth: _depth,
  14973. stencil: _stencil,
  14974. antialias: _antialias,
  14975. premultipliedAlpha: _premultipliedAlpha,
  14976. preserveDrawingBuffer: _preserveDrawingBuffer,
  14977. powerPreference: _powerPreference,
  14978. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14979. }; // event listeners must be registered before WebGL context is created, see #12753
  14980. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14981. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14982. if (_gl === null) {
  14983. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14984. if (_this.isWebGL1Renderer === true) {
  14985. contextNames.shift();
  14986. }
  14987. _gl = getContext(contextNames, contextAttributes);
  14988. if (_gl === null) {
  14989. if (getContext(contextNames)) {
  14990. throw new Error('Error creating WebGL context with your selected attributes.');
  14991. } else {
  14992. throw new Error('Error creating WebGL context.');
  14993. }
  14994. }
  14995. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14996. if (_gl.getShaderPrecisionFormat === undefined) {
  14997. _gl.getShaderPrecisionFormat = function () {
  14998. return {
  14999. 'rangeMin': 1,
  15000. 'rangeMax': 1,
  15001. 'precision': 1
  15002. };
  15003. };
  15004. }
  15005. } catch (error) {
  15006. console.error('THREE.WebGLRenderer: ' + error.message);
  15007. throw error;
  15008. }
  15009. var extensions, capabilities, state, info;
  15010. var properties, textures, cubemaps, attributes, geometries, objects;
  15011. var programCache, materials, renderLists, renderStates, clipping;
  15012. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  15013. var utils, bindingStates;
  15014. function initGLContext() {
  15015. extensions = new WebGLExtensions(_gl);
  15016. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  15017. extensions.init(capabilities);
  15018. utils = new WebGLUtils(_gl, extensions, capabilities);
  15019. state = new WebGLState(_gl, extensions, capabilities);
  15020. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15021. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15022. info = new WebGLInfo(_gl);
  15023. properties = new WebGLProperties();
  15024. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  15025. cubemaps = new WebGLCubeMaps(_this);
  15026. attributes = new WebGLAttributes(_gl, capabilities);
  15027. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  15028. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  15029. objects = new WebGLObjects(_gl, geometries, attributes, info);
  15030. morphtargets = new WebGLMorphtargets(_gl);
  15031. clipping = new WebGLClipping(properties);
  15032. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  15033. materials = new WebGLMaterials(properties);
  15034. renderLists = new WebGLRenderLists(properties);
  15035. renderStates = new WebGLRenderStates(extensions, capabilities);
  15036. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  15037. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  15038. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  15039. info.programs = programCache.programs;
  15040. _this.capabilities = capabilities;
  15041. _this.extensions = extensions;
  15042. _this.properties = properties;
  15043. _this.renderLists = renderLists;
  15044. _this.state = state;
  15045. _this.info = info;
  15046. }
  15047. initGLContext(); // xr
  15048. var xr = new WebXRManager(_this, _gl);
  15049. this.xr = xr; // shadow map
  15050. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  15051. this.shadowMap = shadowMap; // API
  15052. this.getContext = function () {
  15053. return _gl;
  15054. };
  15055. this.getContextAttributes = function () {
  15056. return _gl.getContextAttributes();
  15057. };
  15058. this.forceContextLoss = function () {
  15059. var extension = extensions.get('WEBGL_lose_context');
  15060. if (extension) extension.loseContext();
  15061. };
  15062. this.forceContextRestore = function () {
  15063. var extension = extensions.get('WEBGL_lose_context');
  15064. if (extension) extension.restoreContext();
  15065. };
  15066. this.getPixelRatio = function () {
  15067. return _pixelRatio;
  15068. };
  15069. this.setPixelRatio = function (value) {
  15070. if (value === undefined) return;
  15071. _pixelRatio = value;
  15072. this.setSize(_width, _height, false);
  15073. };
  15074. this.getSize = function (target) {
  15075. if (target === undefined) {
  15076. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  15077. target = new Vector2();
  15078. }
  15079. return target.set(_width, _height);
  15080. };
  15081. this.setSize = function (width, height, updateStyle) {
  15082. if (xr.isPresenting) {
  15083. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  15084. return;
  15085. }
  15086. _width = width;
  15087. _height = height;
  15088. _canvas.width = Math.floor(width * _pixelRatio);
  15089. _canvas.height = Math.floor(height * _pixelRatio);
  15090. if (updateStyle !== false) {
  15091. _canvas.style.width = width + 'px';
  15092. _canvas.style.height = height + 'px';
  15093. }
  15094. this.setViewport(0, 0, width, height);
  15095. };
  15096. this.getDrawingBufferSize = function (target) {
  15097. if (target === undefined) {
  15098. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  15099. target = new Vector2();
  15100. }
  15101. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  15102. };
  15103. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  15104. _width = width;
  15105. _height = height;
  15106. _pixelRatio = pixelRatio;
  15107. _canvas.width = Math.floor(width * pixelRatio);
  15108. _canvas.height = Math.floor(height * pixelRatio);
  15109. this.setViewport(0, 0, width, height);
  15110. };
  15111. this.getCurrentViewport = function (target) {
  15112. if (target === undefined) {
  15113. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  15114. target = new Vector4();
  15115. }
  15116. return target.copy(_currentViewport);
  15117. };
  15118. this.getViewport = function (target) {
  15119. return target.copy(_viewport);
  15120. };
  15121. this.setViewport = function (x, y, width, height) {
  15122. if (x.isVector4) {
  15123. _viewport.set(x.x, x.y, x.z, x.w);
  15124. } else {
  15125. _viewport.set(x, y, width, height);
  15126. }
  15127. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15128. };
  15129. this.getScissor = function (target) {
  15130. return target.copy(_scissor);
  15131. };
  15132. this.setScissor = function (x, y, width, height) {
  15133. if (x.isVector4) {
  15134. _scissor.set(x.x, x.y, x.z, x.w);
  15135. } else {
  15136. _scissor.set(x, y, width, height);
  15137. }
  15138. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15139. };
  15140. this.getScissorTest = function () {
  15141. return _scissorTest;
  15142. };
  15143. this.setScissorTest = function (boolean) {
  15144. state.setScissorTest(_scissorTest = boolean);
  15145. };
  15146. this.setOpaqueSort = function (method) {
  15147. _opaqueSort = method;
  15148. };
  15149. this.setTransparentSort = function (method) {
  15150. _transparentSort = method;
  15151. }; // Clearing
  15152. this.getClearColor = function (target) {
  15153. if (target === undefined) {
  15154. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  15155. target = new Color();
  15156. }
  15157. return target.copy(background.getClearColor());
  15158. };
  15159. this.setClearColor = function () {
  15160. background.setClearColor.apply(background, arguments);
  15161. };
  15162. this.getClearAlpha = function () {
  15163. return background.getClearAlpha();
  15164. };
  15165. this.setClearAlpha = function () {
  15166. background.setClearAlpha.apply(background, arguments);
  15167. };
  15168. this.clear = function (color, depth, stencil) {
  15169. var bits = 0;
  15170. if (color === undefined || color) bits |= 16384;
  15171. if (depth === undefined || depth) bits |= 256;
  15172. if (stencil === undefined || stencil) bits |= 1024;
  15173. _gl.clear(bits);
  15174. };
  15175. this.clearColor = function () {
  15176. this.clear(true, false, false);
  15177. };
  15178. this.clearDepth = function () {
  15179. this.clear(false, true, false);
  15180. };
  15181. this.clearStencil = function () {
  15182. this.clear(false, false, true);
  15183. }; //
  15184. this.dispose = function () {
  15185. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  15186. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  15187. renderLists.dispose();
  15188. renderStates.dispose();
  15189. properties.dispose();
  15190. cubemaps.dispose();
  15191. objects.dispose();
  15192. bindingStates.dispose();
  15193. xr.dispose();
  15194. animation.stop();
  15195. }; // Events
  15196. function onContextLost(event) {
  15197. event.preventDefault();
  15198. console.log('THREE.WebGLRenderer: Context Lost.');
  15199. _isContextLost = true;
  15200. }
  15201. function onContextRestore()
  15202. /* event */
  15203. {
  15204. console.log('THREE.WebGLRenderer: Context Restored.');
  15205. _isContextLost = false;
  15206. initGLContext();
  15207. }
  15208. function onMaterialDispose(event) {
  15209. var material = event.target;
  15210. material.removeEventListener('dispose', onMaterialDispose);
  15211. deallocateMaterial(material);
  15212. } // Buffer deallocation
  15213. function deallocateMaterial(material) {
  15214. releaseMaterialProgramReference(material);
  15215. properties.remove(material);
  15216. }
  15217. function releaseMaterialProgramReference(material) {
  15218. var programInfo = properties.get(material).program;
  15219. if (programInfo !== undefined) {
  15220. programCache.releaseProgram(programInfo);
  15221. }
  15222. } // Buffer rendering
  15223. function renderObjectImmediate(object, program) {
  15224. object.render(function (object) {
  15225. _this.renderBufferImmediate(object, program);
  15226. });
  15227. }
  15228. this.renderBufferImmediate = function (object, program) {
  15229. bindingStates.initAttributes();
  15230. var buffers = properties.get(object);
  15231. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  15232. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  15233. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  15234. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  15235. var programAttributes = program.getAttributes();
  15236. if (object.hasPositions) {
  15237. _gl.bindBuffer(34962, buffers.position);
  15238. _gl.bufferData(34962, object.positionArray, 35048);
  15239. bindingStates.enableAttribute(programAttributes.position);
  15240. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  15241. }
  15242. if (object.hasNormals) {
  15243. _gl.bindBuffer(34962, buffers.normal);
  15244. _gl.bufferData(34962, object.normalArray, 35048);
  15245. bindingStates.enableAttribute(programAttributes.normal);
  15246. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  15247. }
  15248. if (object.hasUvs) {
  15249. _gl.bindBuffer(34962, buffers.uv);
  15250. _gl.bufferData(34962, object.uvArray, 35048);
  15251. bindingStates.enableAttribute(programAttributes.uv);
  15252. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  15253. }
  15254. if (object.hasColors) {
  15255. _gl.bindBuffer(34962, buffers.color);
  15256. _gl.bufferData(34962, object.colorArray, 35048);
  15257. bindingStates.enableAttribute(programAttributes.color);
  15258. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  15259. }
  15260. bindingStates.disableUnusedAttributes();
  15261. _gl.drawArrays(4, 0, object.count);
  15262. object.count = 0;
  15263. };
  15264. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  15265. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15266. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  15267. var program = setProgram(camera, scene, material, object);
  15268. state.setMaterial(material, frontFaceCW); //
  15269. var index = geometry.index;
  15270. var position = geometry.attributes.position; //
  15271. if (index === null) {
  15272. if (position === undefined || position.count === 0) return;
  15273. } else if (index.count === 0) {
  15274. return;
  15275. } //
  15276. var rangeFactor = 1;
  15277. if (material.wireframe === true) {
  15278. index = geometries.getWireframeAttribute(geometry);
  15279. rangeFactor = 2;
  15280. }
  15281. if (material.morphTargets || material.morphNormals) {
  15282. morphtargets.update(object, geometry, material, program);
  15283. }
  15284. bindingStates.setup(object, material, program, geometry, index);
  15285. var attribute;
  15286. var renderer = bufferRenderer;
  15287. if (index !== null) {
  15288. attribute = attributes.get(index);
  15289. renderer = indexedBufferRenderer;
  15290. renderer.setIndex(attribute);
  15291. } //
  15292. var dataCount = index !== null ? index.count : position.count;
  15293. var rangeStart = geometry.drawRange.start * rangeFactor;
  15294. var rangeCount = geometry.drawRange.count * rangeFactor;
  15295. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15296. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15297. var drawStart = Math.max(rangeStart, groupStart);
  15298. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  15299. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  15300. if (drawCount === 0) return; //
  15301. if (object.isMesh) {
  15302. if (material.wireframe === true) {
  15303. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  15304. renderer.setMode(1);
  15305. } else {
  15306. renderer.setMode(4);
  15307. }
  15308. } else if (object.isLine) {
  15309. var lineWidth = material.linewidth;
  15310. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  15311. state.setLineWidth(lineWidth * getTargetPixelRatio());
  15312. if (object.isLineSegments) {
  15313. renderer.setMode(1);
  15314. } else if (object.isLineLoop) {
  15315. renderer.setMode(2);
  15316. } else {
  15317. renderer.setMode(3);
  15318. }
  15319. } else if (object.isPoints) {
  15320. renderer.setMode(0);
  15321. } else if (object.isSprite) {
  15322. renderer.setMode(4);
  15323. }
  15324. if (object.isInstancedMesh) {
  15325. renderer.renderInstances(drawStart, drawCount, object.count);
  15326. } else if (geometry.isInstancedBufferGeometry) {
  15327. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  15328. renderer.renderInstances(drawStart, drawCount, instanceCount);
  15329. } else {
  15330. renderer.render(drawStart, drawCount);
  15331. }
  15332. }; // Compile
  15333. this.compile = function (scene, camera) {
  15334. currentRenderState = renderStates.get(scene);
  15335. currentRenderState.init();
  15336. scene.traverseVisible(function (object) {
  15337. if (object.isLight && object.layers.test(camera.layers)) {
  15338. currentRenderState.pushLight(object);
  15339. if (object.castShadow) {
  15340. currentRenderState.pushShadow(object);
  15341. }
  15342. }
  15343. });
  15344. currentRenderState.setupLights();
  15345. var compiled = new WeakMap();
  15346. scene.traverse(function (object) {
  15347. var material = object.material;
  15348. if (material) {
  15349. if (Array.isArray(material)) {
  15350. for (var i = 0; i < material.length; i++) {
  15351. var material2 = material[i];
  15352. if (compiled.has(material2) === false) {
  15353. initMaterial(material2, scene, object);
  15354. compiled.set(material2);
  15355. }
  15356. }
  15357. } else if (compiled.has(material) === false) {
  15358. initMaterial(material, scene, object);
  15359. compiled.set(material);
  15360. }
  15361. }
  15362. });
  15363. }; // Animation Loop
  15364. var onAnimationFrameCallback = null;
  15365. function onAnimationFrame(time) {
  15366. if (xr.isPresenting) return;
  15367. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  15368. }
  15369. var animation = new WebGLAnimation();
  15370. animation.setAnimationLoop(onAnimationFrame);
  15371. if (typeof window !== 'undefined') animation.setContext(window);
  15372. this.setAnimationLoop = function (callback) {
  15373. onAnimationFrameCallback = callback;
  15374. xr.setAnimationLoop(callback);
  15375. callback === null ? animation.stop() : animation.start();
  15376. }; // Rendering
  15377. this.render = function (scene, camera) {
  15378. var renderTarget, forceClear;
  15379. if (arguments[2] !== undefined) {
  15380. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  15381. renderTarget = arguments[2];
  15382. }
  15383. if (arguments[3] !== undefined) {
  15384. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  15385. forceClear = arguments[3];
  15386. }
  15387. if (camera !== undefined && camera.isCamera !== true) {
  15388. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  15389. return;
  15390. }
  15391. if (_isContextLost === true) return; // reset caching for this frame
  15392. bindingStates.resetDefaultState();
  15393. _currentMaterialId = -1;
  15394. _currentCamera = null; // update scene graph
  15395. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  15396. if (camera.parent === null) camera.updateMatrixWorld();
  15397. if (xr.enabled === true && xr.isPresenting === true) {
  15398. camera = xr.getCamera(camera);
  15399. } //
  15400. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  15401. currentRenderState = renderStates.get(scene, renderStateStack.length);
  15402. currentRenderState.init();
  15403. renderStateStack.push(currentRenderState);
  15404. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  15405. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  15406. _localClippingEnabled = this.localClippingEnabled;
  15407. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  15408. currentRenderList = renderLists.get(scene, camera);
  15409. currentRenderList.init();
  15410. projectObject(scene, camera, 0, _this.sortObjects);
  15411. currentRenderList.finish();
  15412. if (_this.sortObjects === true) {
  15413. currentRenderList.sort(_opaqueSort, _transparentSort);
  15414. } //
  15415. if (_clippingEnabled === true) clipping.beginShadows();
  15416. var shadowsArray = currentRenderState.state.shadowsArray;
  15417. shadowMap.render(shadowsArray, scene, camera);
  15418. currentRenderState.setupLights();
  15419. currentRenderState.setupLightsView(camera);
  15420. if (_clippingEnabled === true) clipping.endShadows(); //
  15421. if (this.info.autoReset === true) this.info.reset();
  15422. if (renderTarget !== undefined) {
  15423. this.setRenderTarget(renderTarget);
  15424. } //
  15425. background.render(currentRenderList, scene, camera, forceClear); // render scene
  15426. var opaqueObjects = currentRenderList.opaque;
  15427. var transparentObjects = currentRenderList.transparent;
  15428. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  15429. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  15430. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  15431. if (_currentRenderTarget !== null) {
  15432. // Generate mipmap if we're using any kind of mipmap filtering
  15433. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  15434. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  15435. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  15436. state.buffers.depth.setTest(true);
  15437. state.buffers.depth.setMask(true);
  15438. state.buffers.color.setMask(true);
  15439. state.setPolygonOffset(false); // _gl.finish();
  15440. renderStateStack.pop();
  15441. if (renderStateStack.length > 0) {
  15442. currentRenderState = renderStateStack[renderStateStack.length - 1];
  15443. } else {
  15444. currentRenderState = null;
  15445. }
  15446. currentRenderList = null;
  15447. };
  15448. function projectObject(object, camera, groupOrder, sortObjects) {
  15449. if (object.visible === false) return;
  15450. var visible = object.layers.test(camera.layers);
  15451. if (visible) {
  15452. if (object.isGroup) {
  15453. groupOrder = object.renderOrder;
  15454. } else if (object.isLOD) {
  15455. if (object.autoUpdate === true) object.update(camera);
  15456. } else if (object.isLight) {
  15457. currentRenderState.pushLight(object);
  15458. if (object.castShadow) {
  15459. currentRenderState.pushShadow(object);
  15460. }
  15461. } else if (object.isSprite) {
  15462. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  15463. if (sortObjects) {
  15464. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15465. }
  15466. var geometry = objects.update(object);
  15467. var material = object.material;
  15468. if (material.visible) {
  15469. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  15470. }
  15471. }
  15472. } else if (object.isImmediateRenderObject) {
  15473. if (sortObjects) {
  15474. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15475. }
  15476. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  15477. } else if (object.isMesh || object.isLine || object.isPoints) {
  15478. if (object.isSkinnedMesh) {
  15479. // update skeleton only once in a frame
  15480. if (object.skeleton.frame !== info.render.frame) {
  15481. object.skeleton.update();
  15482. object.skeleton.frame = info.render.frame;
  15483. }
  15484. }
  15485. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  15486. if (sortObjects) {
  15487. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15488. }
  15489. var _geometry = objects.update(object);
  15490. var _material = object.material;
  15491. if (Array.isArray(_material)) {
  15492. var groups = _geometry.groups;
  15493. for (var i = 0, l = groups.length; i < l; i++) {
  15494. var group = groups[i];
  15495. var groupMaterial = _material[group.materialIndex];
  15496. if (groupMaterial && groupMaterial.visible) {
  15497. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  15498. }
  15499. }
  15500. } else if (_material.visible) {
  15501. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  15502. }
  15503. }
  15504. }
  15505. }
  15506. var children = object.children;
  15507. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  15508. projectObject(children[_i], camera, groupOrder, sortObjects);
  15509. }
  15510. }
  15511. function renderObjects(renderList, scene, camera) {
  15512. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15513. for (var i = 0, l = renderList.length; i < l; i++) {
  15514. var renderItem = renderList[i];
  15515. var object = renderItem.object;
  15516. var geometry = renderItem.geometry;
  15517. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15518. var group = renderItem.group;
  15519. if (camera.isArrayCamera) {
  15520. var cameras = camera.cameras;
  15521. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15522. var camera2 = cameras[j];
  15523. if (object.layers.test(camera2.layers)) {
  15524. state.viewport(_currentViewport.copy(camera2.viewport));
  15525. currentRenderState.setupLightsView(camera2);
  15526. renderObject(object, scene, camera2, geometry, material, group);
  15527. }
  15528. }
  15529. } else {
  15530. renderObject(object, scene, camera, geometry, material, group);
  15531. }
  15532. }
  15533. }
  15534. function renderObject(object, scene, camera, geometry, material, group) {
  15535. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15536. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15537. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15538. if (object.isImmediateRenderObject) {
  15539. var program = setProgram(camera, scene, material, object);
  15540. state.setMaterial(material);
  15541. bindingStates.reset();
  15542. renderObjectImmediate(object, program);
  15543. } else {
  15544. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15545. }
  15546. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15547. }
  15548. function initMaterial(material, scene, object) {
  15549. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15550. var materialProperties = properties.get(material);
  15551. var lights = currentRenderState.state.lights;
  15552. var shadowsArray = currentRenderState.state.shadowsArray;
  15553. var lightsStateVersion = lights.state.version;
  15554. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15555. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15556. var program = materialProperties.program;
  15557. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15558. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15559. materialProperties.fog = scene.fog;
  15560. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15561. if (program === undefined) {
  15562. // new material
  15563. material.addEventListener('dispose', onMaterialDispose);
  15564. } else if (program.cacheKey !== programCacheKey) {
  15565. // changed glsl or parameters
  15566. releaseMaterialProgramReference(material);
  15567. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15568. programChange = false;
  15569. } else if (parameters.shaderID !== undefined) {
  15570. // same glsl and uniform list
  15571. return;
  15572. } else {
  15573. // only rebuild uniform list
  15574. programChange = false;
  15575. }
  15576. if (programChange) {
  15577. parameters.uniforms = programCache.getUniforms(material);
  15578. material.onBeforeCompile(parameters, _this);
  15579. program = programCache.acquireProgram(parameters, programCacheKey);
  15580. materialProperties.program = program;
  15581. materialProperties.uniforms = parameters.uniforms;
  15582. materialProperties.outputEncoding = parameters.outputEncoding;
  15583. }
  15584. var uniforms = materialProperties.uniforms;
  15585. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15586. materialProperties.numClippingPlanes = clipping.numPlanes;
  15587. materialProperties.numIntersection = clipping.numIntersection;
  15588. uniforms.clippingPlanes = clipping.uniform;
  15589. } // store the light setup it was created for
  15590. materialProperties.needsLights = materialNeedsLights(material);
  15591. materialProperties.lightsStateVersion = lightsStateVersion;
  15592. if (materialProperties.needsLights) {
  15593. // wire up the material to this renderer's lighting state
  15594. uniforms.ambientLightColor.value = lights.state.ambient;
  15595. uniforms.lightProbe.value = lights.state.probe;
  15596. uniforms.directionalLights.value = lights.state.directional;
  15597. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15598. uniforms.spotLights.value = lights.state.spot;
  15599. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15600. uniforms.rectAreaLights.value = lights.state.rectArea;
  15601. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15602. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15603. uniforms.pointLights.value = lights.state.point;
  15604. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15605. uniforms.hemisphereLights.value = lights.state.hemi;
  15606. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15607. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15608. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15609. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15610. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15611. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15612. }
  15613. var progUniforms = materialProperties.program.getUniforms();
  15614. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15615. materialProperties.uniformsList = uniformsList;
  15616. }
  15617. function setProgram(camera, scene, material, object) {
  15618. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15619. textures.resetTextureUnits();
  15620. var fog = scene.fog;
  15621. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15622. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15623. var envMap = cubemaps.get(material.envMap || environment);
  15624. var materialProperties = properties.get(material);
  15625. var lights = currentRenderState.state.lights;
  15626. if (_clippingEnabled === true) {
  15627. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15628. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15629. // object instead of the material, once it becomes feasible
  15630. // (#8465, #8379)
  15631. clipping.setState(material, camera, useCache);
  15632. }
  15633. }
  15634. if (material.version === materialProperties.__version) {
  15635. if (material.fog && materialProperties.fog !== fog) {
  15636. initMaterial(material, scene, object);
  15637. } else if (materialProperties.environment !== environment) {
  15638. initMaterial(material, scene, object);
  15639. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15640. initMaterial(material, scene, object);
  15641. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15642. initMaterial(material, scene, object);
  15643. } else if (materialProperties.outputEncoding !== encoding) {
  15644. initMaterial(material, scene, object);
  15645. } else if (materialProperties.envMap !== envMap) {
  15646. initMaterial(material, scene, object);
  15647. }
  15648. } else {
  15649. initMaterial(material, scene, object);
  15650. materialProperties.__version = material.version;
  15651. }
  15652. var refreshProgram = false;
  15653. var refreshMaterial = false;
  15654. var refreshLights = false;
  15655. var program = materialProperties.program,
  15656. p_uniforms = program.getUniforms(),
  15657. m_uniforms = materialProperties.uniforms;
  15658. if (state.useProgram(program.program)) {
  15659. refreshProgram = true;
  15660. refreshMaterial = true;
  15661. refreshLights = true;
  15662. }
  15663. if (material.id !== _currentMaterialId) {
  15664. _currentMaterialId = material.id;
  15665. refreshMaterial = true;
  15666. }
  15667. if (refreshProgram || _currentCamera !== camera) {
  15668. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15669. if (capabilities.logarithmicDepthBuffer) {
  15670. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15671. }
  15672. if (_currentCamera !== camera) {
  15673. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15674. // now, in case this material supports lights - or later, when
  15675. // the next material that does gets activated:
  15676. refreshMaterial = true; // set to true on material change
  15677. refreshLights = true; // remains set until update done
  15678. } // load material specific uniforms
  15679. // (shader material also gets them for the sake of genericity)
  15680. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15681. var uCamPos = p_uniforms.map.cameraPosition;
  15682. if (uCamPos !== undefined) {
  15683. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15684. }
  15685. }
  15686. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15687. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15688. }
  15689. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15690. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15691. }
  15692. } // skinning uniforms must be set even if material didn't change
  15693. // auto-setting of texture unit for bone texture must go before other textures
  15694. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15695. if (material.skinning) {
  15696. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15697. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15698. var skeleton = object.skeleton;
  15699. if (skeleton) {
  15700. var bones = skeleton.bones;
  15701. if (capabilities.floatVertexTextures) {
  15702. if (skeleton.boneTexture === null) {
  15703. // layout (1 matrix = 4 pixels)
  15704. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15705. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15706. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15707. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15708. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15709. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15710. size = MathUtils.ceilPowerOfTwo(size);
  15711. size = Math.max(size, 4);
  15712. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15713. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15714. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15715. skeleton.boneMatrices = boneMatrices;
  15716. skeleton.boneTexture = boneTexture;
  15717. skeleton.boneTextureSize = size;
  15718. }
  15719. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15720. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15721. } else {
  15722. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15723. }
  15724. }
  15725. }
  15726. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15727. materialProperties.receiveShadow = object.receiveShadow;
  15728. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15729. }
  15730. if (refreshMaterial) {
  15731. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15732. if (materialProperties.needsLights) {
  15733. // the current material requires lighting info
  15734. // note: all lighting uniforms are always set correctly
  15735. // they simply reference the renderer's state for their
  15736. // values
  15737. //
  15738. // use the current material's .needsUpdate flags to set
  15739. // the GL state when required
  15740. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15741. } // refresh uniforms common to several materials
  15742. if (fog && material.fog) {
  15743. materials.refreshFogUniforms(m_uniforms, fog);
  15744. }
  15745. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15746. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15747. }
  15748. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15749. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15750. material.uniformsNeedUpdate = false;
  15751. }
  15752. if (material.isSpriteMaterial) {
  15753. p_uniforms.setValue(_gl, 'center', object.center);
  15754. } // common matrices
  15755. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15756. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15757. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15758. return program;
  15759. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15760. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15761. uniforms.ambientLightColor.needsUpdate = value;
  15762. uniforms.lightProbe.needsUpdate = value;
  15763. uniforms.directionalLights.needsUpdate = value;
  15764. uniforms.directionalLightShadows.needsUpdate = value;
  15765. uniforms.pointLights.needsUpdate = value;
  15766. uniforms.pointLightShadows.needsUpdate = value;
  15767. uniforms.spotLights.needsUpdate = value;
  15768. uniforms.spotLightShadows.needsUpdate = value;
  15769. uniforms.rectAreaLights.needsUpdate = value;
  15770. uniforms.hemisphereLights.needsUpdate = value;
  15771. }
  15772. function materialNeedsLights(material) {
  15773. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15774. } //
  15775. this.setFramebuffer = function (value) {
  15776. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15777. _framebuffer = value;
  15778. };
  15779. this.getActiveCubeFace = function () {
  15780. return _currentActiveCubeFace;
  15781. };
  15782. this.getActiveMipmapLevel = function () {
  15783. return _currentActiveMipmapLevel;
  15784. };
  15785. this.getRenderList = function () {
  15786. return currentRenderList;
  15787. };
  15788. this.setRenderList = function (renderList) {
  15789. currentRenderList = renderList;
  15790. };
  15791. this.getRenderTarget = function () {
  15792. return _currentRenderTarget;
  15793. };
  15794. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15795. if (activeCubeFace === void 0) {
  15796. activeCubeFace = 0;
  15797. }
  15798. if (activeMipmapLevel === void 0) {
  15799. activeMipmapLevel = 0;
  15800. }
  15801. _currentRenderTarget = renderTarget;
  15802. _currentActiveCubeFace = activeCubeFace;
  15803. _currentActiveMipmapLevel = activeMipmapLevel;
  15804. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15805. textures.setupRenderTarget(renderTarget);
  15806. }
  15807. var framebuffer = _framebuffer;
  15808. var isCube = false;
  15809. var isRenderTarget3D = false;
  15810. if (renderTarget) {
  15811. var texture = renderTarget.texture;
  15812. if (texture.isDataTexture3D || texture.isDataTexture2DArray) {
  15813. isRenderTarget3D = true;
  15814. }
  15815. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15816. if (renderTarget.isWebGLCubeRenderTarget) {
  15817. framebuffer = __webglFramebuffer[activeCubeFace];
  15818. isCube = true;
  15819. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15820. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15821. } else {
  15822. framebuffer = __webglFramebuffer;
  15823. }
  15824. _currentViewport.copy(renderTarget.viewport);
  15825. _currentScissor.copy(renderTarget.scissor);
  15826. _currentScissorTest = renderTarget.scissorTest;
  15827. } else {
  15828. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15829. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15830. _currentScissorTest = _scissorTest;
  15831. }
  15832. if (_currentFramebuffer !== framebuffer) {
  15833. _gl.bindFramebuffer(36160, framebuffer);
  15834. _currentFramebuffer = framebuffer;
  15835. }
  15836. state.viewport(_currentViewport);
  15837. state.scissor(_currentScissor);
  15838. state.setScissorTest(_currentScissorTest);
  15839. if (isCube) {
  15840. var textureProperties = properties.get(renderTarget.texture);
  15841. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15842. } else if (isRenderTarget3D) {
  15843. var _textureProperties = properties.get(renderTarget.texture);
  15844. var layer = activeCubeFace || 0;
  15845. _gl.framebufferTextureLayer(36160, 36064, _textureProperties.__webglTexture, activeMipmapLevel || 0, layer);
  15846. }
  15847. };
  15848. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15849. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15850. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15851. return;
  15852. }
  15853. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15854. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15855. framebuffer = framebuffer[activeCubeFaceIndex];
  15856. }
  15857. if (framebuffer) {
  15858. var restore = false;
  15859. if (framebuffer !== _currentFramebuffer) {
  15860. _gl.bindFramebuffer(36160, framebuffer);
  15861. restore = true;
  15862. }
  15863. try {
  15864. var texture = renderTarget.texture;
  15865. var textureFormat = texture.format;
  15866. var textureType = texture.type;
  15867. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15868. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15869. return;
  15870. }
  15871. var halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has('EXT_color_buffer_half_float') || capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float'));
  15872. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15873. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has('OES_texture_float') || extensions.has('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15874. !halfFloatSupportedByExt) {
  15875. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15876. return;
  15877. }
  15878. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15879. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15880. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15881. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15882. }
  15883. } else {
  15884. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15885. }
  15886. } finally {
  15887. if (restore) {
  15888. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15889. }
  15890. }
  15891. }
  15892. };
  15893. this.copyFramebufferToTexture = function (position, texture, level) {
  15894. if (level === void 0) {
  15895. level = 0;
  15896. }
  15897. var levelScale = Math.pow(2, -level);
  15898. var width = Math.floor(texture.image.width * levelScale);
  15899. var height = Math.floor(texture.image.height * levelScale);
  15900. var glFormat = utils.convert(texture.format);
  15901. textures.setTexture2D(texture, 0);
  15902. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15903. state.unbindTexture();
  15904. };
  15905. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15906. if (level === void 0) {
  15907. level = 0;
  15908. }
  15909. var width = srcTexture.image.width;
  15910. var height = srcTexture.image.height;
  15911. var glFormat = utils.convert(dstTexture.format);
  15912. var glType = utils.convert(dstTexture.type);
  15913. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15914. // parameters, make sure they are correct for the dstTexture
  15915. _gl.pixelStorei(37440, dstTexture.flipY);
  15916. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15917. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15918. if (srcTexture.isDataTexture) {
  15919. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15920. } else {
  15921. if (srcTexture.isCompressedTexture) {
  15922. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15923. } else {
  15924. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15925. }
  15926. } // Generate mipmaps only when copying level 0
  15927. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15928. state.unbindTexture();
  15929. };
  15930. this.initTexture = function (texture) {
  15931. textures.setTexture2D(texture, 0);
  15932. state.unbindTexture();
  15933. };
  15934. this.resetState = function () {
  15935. state.reset();
  15936. bindingStates.reset();
  15937. };
  15938. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15939. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15940. detail: this
  15941. })); // eslint-disable-line no-undef
  15942. }
  15943. }
  15944. function WebGL1Renderer(parameters) {
  15945. WebGLRenderer.call(this, parameters);
  15946. }
  15947. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15948. constructor: WebGL1Renderer,
  15949. isWebGL1Renderer: true
  15950. });
  15951. var FogExp2 = /*#__PURE__*/function () {
  15952. function FogExp2(color, density) {
  15953. Object.defineProperty(this, 'isFogExp2', {
  15954. value: true
  15955. });
  15956. this.name = '';
  15957. this.color = new Color(color);
  15958. this.density = density !== undefined ? density : 0.00025;
  15959. }
  15960. var _proto = FogExp2.prototype;
  15961. _proto.clone = function clone() {
  15962. return new FogExp2(this.color, this.density);
  15963. };
  15964. _proto.toJSON = function toJSON()
  15965. /* meta */
  15966. {
  15967. return {
  15968. type: 'FogExp2',
  15969. color: this.color.getHex(),
  15970. density: this.density
  15971. };
  15972. };
  15973. return FogExp2;
  15974. }();
  15975. var Fog = /*#__PURE__*/function () {
  15976. function Fog(color, near, far) {
  15977. Object.defineProperty(this, 'isFog', {
  15978. value: true
  15979. });
  15980. this.name = '';
  15981. this.color = new Color(color);
  15982. this.near = near !== undefined ? near : 1;
  15983. this.far = far !== undefined ? far : 1000;
  15984. }
  15985. var _proto = Fog.prototype;
  15986. _proto.clone = function clone() {
  15987. return new Fog(this.color, this.near, this.far);
  15988. };
  15989. _proto.toJSON = function toJSON()
  15990. /* meta */
  15991. {
  15992. return {
  15993. type: 'Fog',
  15994. color: this.color.getHex(),
  15995. near: this.near,
  15996. far: this.far
  15997. };
  15998. };
  15999. return Fog;
  16000. }();
  16001. var Scene = /*#__PURE__*/function (_Object3D) {
  16002. _inheritsLoose(Scene, _Object3D);
  16003. function Scene() {
  16004. var _this;
  16005. _this = _Object3D.call(this) || this;
  16006. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  16007. value: true
  16008. });
  16009. _this.type = 'Scene';
  16010. _this.background = null;
  16011. _this.environment = null;
  16012. _this.fog = null;
  16013. _this.overrideMaterial = null;
  16014. _this.autoUpdate = true; // checked by the renderer
  16015. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  16016. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  16017. detail: _assertThisInitialized(_this)
  16018. })); // eslint-disable-line no-undef
  16019. }
  16020. return _this;
  16021. }
  16022. var _proto = Scene.prototype;
  16023. _proto.copy = function copy(source, recursive) {
  16024. _Object3D.prototype.copy.call(this, source, recursive);
  16025. if (source.background !== null) this.background = source.background.clone();
  16026. if (source.environment !== null) this.environment = source.environment.clone();
  16027. if (source.fog !== null) this.fog = source.fog.clone();
  16028. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  16029. this.autoUpdate = source.autoUpdate;
  16030. this.matrixAutoUpdate = source.matrixAutoUpdate;
  16031. return this;
  16032. };
  16033. _proto.toJSON = function toJSON(meta) {
  16034. var data = _Object3D.prototype.toJSON.call(this, meta);
  16035. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  16036. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  16037. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  16038. return data;
  16039. };
  16040. return Scene;
  16041. }(Object3D);
  16042. function InterleavedBuffer(array, stride) {
  16043. this.array = array;
  16044. this.stride = stride;
  16045. this.count = array !== undefined ? array.length / stride : 0;
  16046. this.usage = StaticDrawUsage;
  16047. this.updateRange = {
  16048. offset: 0,
  16049. count: -1
  16050. };
  16051. this.version = 0;
  16052. this.uuid = MathUtils.generateUUID();
  16053. }
  16054. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  16055. set: function set(value) {
  16056. if (value === true) this.version++;
  16057. }
  16058. });
  16059. Object.assign(InterleavedBuffer.prototype, {
  16060. isInterleavedBuffer: true,
  16061. onUploadCallback: function onUploadCallback() {},
  16062. setUsage: function setUsage(value) {
  16063. this.usage = value;
  16064. return this;
  16065. },
  16066. copy: function copy(source) {
  16067. this.array = new source.array.constructor(source.array);
  16068. this.count = source.count;
  16069. this.stride = source.stride;
  16070. this.usage = source.usage;
  16071. return this;
  16072. },
  16073. copyAt: function copyAt(index1, attribute, index2) {
  16074. index1 *= this.stride;
  16075. index2 *= attribute.stride;
  16076. for (var i = 0, l = this.stride; i < l; i++) {
  16077. this.array[index1 + i] = attribute.array[index2 + i];
  16078. }
  16079. return this;
  16080. },
  16081. set: function set(value, offset) {
  16082. if (offset === void 0) {
  16083. offset = 0;
  16084. }
  16085. this.array.set(value, offset);
  16086. return this;
  16087. },
  16088. clone: function clone(data) {
  16089. if (data.arrayBuffers === undefined) {
  16090. data.arrayBuffers = {};
  16091. }
  16092. if (this.array.buffer._uuid === undefined) {
  16093. this.array.buffer._uuid = MathUtils.generateUUID();
  16094. }
  16095. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16096. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  16097. }
  16098. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  16099. var ib = new InterleavedBuffer(array, this.stride);
  16100. ib.setUsage(this.usage);
  16101. return ib;
  16102. },
  16103. onUpload: function onUpload(callback) {
  16104. this.onUploadCallback = callback;
  16105. return this;
  16106. },
  16107. toJSON: function toJSON(data) {
  16108. if (data.arrayBuffers === undefined) {
  16109. data.arrayBuffers = {};
  16110. } // generate UUID for array buffer if necessary
  16111. if (this.array.buffer._uuid === undefined) {
  16112. this.array.buffer._uuid = MathUtils.generateUUID();
  16113. }
  16114. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16115. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  16116. } //
  16117. return {
  16118. uuid: this.uuid,
  16119. buffer: this.array.buffer._uuid,
  16120. type: this.array.constructor.name,
  16121. stride: this.stride
  16122. };
  16123. }
  16124. });
  16125. var _vector$6 = new Vector3();
  16126. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  16127. this.name = '';
  16128. this.data = interleavedBuffer;
  16129. this.itemSize = itemSize;
  16130. this.offset = offset;
  16131. this.normalized = normalized === true;
  16132. }
  16133. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  16134. count: {
  16135. get: function get() {
  16136. return this.data.count;
  16137. }
  16138. },
  16139. array: {
  16140. get: function get() {
  16141. return this.data.array;
  16142. }
  16143. },
  16144. needsUpdate: {
  16145. set: function set(value) {
  16146. this.data.needsUpdate = value;
  16147. }
  16148. }
  16149. });
  16150. Object.assign(InterleavedBufferAttribute.prototype, {
  16151. isInterleavedBufferAttribute: true,
  16152. applyMatrix4: function applyMatrix4(m) {
  16153. for (var i = 0, l = this.data.count; i < l; i++) {
  16154. _vector$6.x = this.getX(i);
  16155. _vector$6.y = this.getY(i);
  16156. _vector$6.z = this.getZ(i);
  16157. _vector$6.applyMatrix4(m);
  16158. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  16159. }
  16160. return this;
  16161. },
  16162. setX: function setX(index, x) {
  16163. this.data.array[index * this.data.stride + this.offset] = x;
  16164. return this;
  16165. },
  16166. setY: function setY(index, y) {
  16167. this.data.array[index * this.data.stride + this.offset + 1] = y;
  16168. return this;
  16169. },
  16170. setZ: function setZ(index, z) {
  16171. this.data.array[index * this.data.stride + this.offset + 2] = z;
  16172. return this;
  16173. },
  16174. setW: function setW(index, w) {
  16175. this.data.array[index * this.data.stride + this.offset + 3] = w;
  16176. return this;
  16177. },
  16178. getX: function getX(index) {
  16179. return this.data.array[index * this.data.stride + this.offset];
  16180. },
  16181. getY: function getY(index) {
  16182. return this.data.array[index * this.data.stride + this.offset + 1];
  16183. },
  16184. getZ: function getZ(index) {
  16185. return this.data.array[index * this.data.stride + this.offset + 2];
  16186. },
  16187. getW: function getW(index) {
  16188. return this.data.array[index * this.data.stride + this.offset + 3];
  16189. },
  16190. setXY: function setXY(index, x, y) {
  16191. index = index * this.data.stride + this.offset;
  16192. this.data.array[index + 0] = x;
  16193. this.data.array[index + 1] = y;
  16194. return this;
  16195. },
  16196. setXYZ: function setXYZ(index, x, y, z) {
  16197. index = index * this.data.stride + this.offset;
  16198. this.data.array[index + 0] = x;
  16199. this.data.array[index + 1] = y;
  16200. this.data.array[index + 2] = z;
  16201. return this;
  16202. },
  16203. setXYZW: function setXYZW(index, x, y, z, w) {
  16204. index = index * this.data.stride + this.offset;
  16205. this.data.array[index + 0] = x;
  16206. this.data.array[index + 1] = y;
  16207. this.data.array[index + 2] = z;
  16208. this.data.array[index + 3] = w;
  16209. return this;
  16210. },
  16211. clone: function clone(data) {
  16212. if (data === undefined) {
  16213. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  16214. var array = [];
  16215. for (var i = 0; i < this.count; i++) {
  16216. var index = i * this.data.stride + this.offset;
  16217. for (var j = 0; j < this.itemSize; j++) {
  16218. array.push(this.data.array[index + j]);
  16219. }
  16220. }
  16221. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  16222. } else {
  16223. if (data.interleavedBuffers === undefined) {
  16224. data.interleavedBuffers = {};
  16225. }
  16226. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16227. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  16228. }
  16229. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  16230. }
  16231. },
  16232. toJSON: function toJSON(data) {
  16233. if (data === undefined) {
  16234. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  16235. var array = [];
  16236. for (var i = 0; i < this.count; i++) {
  16237. var index = i * this.data.stride + this.offset;
  16238. for (var j = 0; j < this.itemSize; j++) {
  16239. array.push(this.data.array[index + j]);
  16240. }
  16241. } // deinterleave data and save it as an ordinary buffer attribute for now
  16242. return {
  16243. itemSize: this.itemSize,
  16244. type: this.array.constructor.name,
  16245. array: array,
  16246. normalized: this.normalized
  16247. };
  16248. } else {
  16249. // save as true interlaved attribtue
  16250. if (data.interleavedBuffers === undefined) {
  16251. data.interleavedBuffers = {};
  16252. }
  16253. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16254. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  16255. }
  16256. return {
  16257. isInterleavedBufferAttribute: true,
  16258. itemSize: this.itemSize,
  16259. data: this.data.uuid,
  16260. offset: this.offset,
  16261. normalized: this.normalized
  16262. };
  16263. }
  16264. }
  16265. });
  16266. /**
  16267. * parameters = {
  16268. * color: <hex>,
  16269. * map: new THREE.Texture( <Image> ),
  16270. * alphaMap: new THREE.Texture( <Image> ),
  16271. * rotation: <float>,
  16272. * sizeAttenuation: <bool>
  16273. * }
  16274. */
  16275. function SpriteMaterial(parameters) {
  16276. Material.call(this);
  16277. this.type = 'SpriteMaterial';
  16278. this.color = new Color(0xffffff);
  16279. this.map = null;
  16280. this.alphaMap = null;
  16281. this.rotation = 0;
  16282. this.sizeAttenuation = true;
  16283. this.transparent = true;
  16284. this.setValues(parameters);
  16285. }
  16286. SpriteMaterial.prototype = Object.create(Material.prototype);
  16287. SpriteMaterial.prototype.constructor = SpriteMaterial;
  16288. SpriteMaterial.prototype.isSpriteMaterial = true;
  16289. SpriteMaterial.prototype.copy = function (source) {
  16290. Material.prototype.copy.call(this, source);
  16291. this.color.copy(source.color);
  16292. this.map = source.map;
  16293. this.alphaMap = source.alphaMap;
  16294. this.rotation = source.rotation;
  16295. this.sizeAttenuation = source.sizeAttenuation;
  16296. return this;
  16297. };
  16298. var _geometry;
  16299. var _intersectPoint = new Vector3();
  16300. var _worldScale = new Vector3();
  16301. var _mvPosition = new Vector3();
  16302. var _alignedPosition = new Vector2();
  16303. var _rotatedPosition = new Vector2();
  16304. var _viewWorldMatrix = new Matrix4();
  16305. var _vA$1 = new Vector3();
  16306. var _vB$1 = new Vector3();
  16307. var _vC$1 = new Vector3();
  16308. var _uvA$1 = new Vector2();
  16309. var _uvB$1 = new Vector2();
  16310. var _uvC$1 = new Vector2();
  16311. function Sprite(material) {
  16312. Object3D.call(this);
  16313. this.type = 'Sprite';
  16314. if (_geometry === undefined) {
  16315. _geometry = new BufferGeometry();
  16316. 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]);
  16317. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  16318. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  16319. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  16320. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  16321. }
  16322. this.geometry = _geometry;
  16323. this.material = material !== undefined ? material : new SpriteMaterial();
  16324. this.center = new Vector2(0.5, 0.5);
  16325. }
  16326. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  16327. constructor: Sprite,
  16328. isSprite: true,
  16329. raycast: function raycast(raycaster, intersects) {
  16330. if (raycaster.camera === null) {
  16331. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  16332. }
  16333. _worldScale.setFromMatrixScale(this.matrixWorld);
  16334. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  16335. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  16336. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  16337. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  16338. _worldScale.multiplyScalar(-_mvPosition.z);
  16339. }
  16340. var rotation = this.material.rotation;
  16341. var sin, cos;
  16342. if (rotation !== 0) {
  16343. cos = Math.cos(rotation);
  16344. sin = Math.sin(rotation);
  16345. }
  16346. var center = this.center;
  16347. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16348. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16349. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16350. _uvA$1.set(0, 0);
  16351. _uvB$1.set(1, 0);
  16352. _uvC$1.set(1, 1); // check first triangle
  16353. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  16354. if (intersect === null) {
  16355. // check second triangle
  16356. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16357. _uvB$1.set(0, 1);
  16358. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  16359. if (intersect === null) {
  16360. return;
  16361. }
  16362. }
  16363. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  16364. if (distance < raycaster.near || distance > raycaster.far) return;
  16365. intersects.push({
  16366. distance: distance,
  16367. point: _intersectPoint.clone(),
  16368. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  16369. face: null,
  16370. object: this
  16371. });
  16372. },
  16373. copy: function copy(source) {
  16374. Object3D.prototype.copy.call(this, source);
  16375. if (source.center !== undefined) this.center.copy(source.center);
  16376. this.material = source.material;
  16377. return this;
  16378. }
  16379. });
  16380. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  16381. // compute position in camera space
  16382. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  16383. if (sin !== undefined) {
  16384. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  16385. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  16386. } else {
  16387. _rotatedPosition.copy(_alignedPosition);
  16388. }
  16389. vertexPosition.copy(mvPosition);
  16390. vertexPosition.x += _rotatedPosition.x;
  16391. vertexPosition.y += _rotatedPosition.y; // transform to world space
  16392. vertexPosition.applyMatrix4(_viewWorldMatrix);
  16393. }
  16394. var _v1$4 = new Vector3();
  16395. var _v2$2 = new Vector3();
  16396. function LOD() {
  16397. Object3D.call(this);
  16398. this._currentLevel = 0;
  16399. this.type = 'LOD';
  16400. Object.defineProperties(this, {
  16401. levels: {
  16402. enumerable: true,
  16403. value: []
  16404. }
  16405. });
  16406. this.autoUpdate = true;
  16407. }
  16408. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  16409. constructor: LOD,
  16410. isLOD: true,
  16411. copy: function copy(source) {
  16412. Object3D.prototype.copy.call(this, source, false);
  16413. var levels = source.levels;
  16414. for (var i = 0, l = levels.length; i < l; i++) {
  16415. var level = levels[i];
  16416. this.addLevel(level.object.clone(), level.distance);
  16417. }
  16418. this.autoUpdate = source.autoUpdate;
  16419. return this;
  16420. },
  16421. addLevel: function addLevel(object, distance) {
  16422. if (distance === void 0) {
  16423. distance = 0;
  16424. }
  16425. distance = Math.abs(distance);
  16426. var levels = this.levels;
  16427. var l;
  16428. for (l = 0; l < levels.length; l++) {
  16429. if (distance < levels[l].distance) {
  16430. break;
  16431. }
  16432. }
  16433. levels.splice(l, 0, {
  16434. distance: distance,
  16435. object: object
  16436. });
  16437. this.add(object);
  16438. return this;
  16439. },
  16440. getCurrentLevel: function getCurrentLevel() {
  16441. return this._currentLevel;
  16442. },
  16443. getObjectForDistance: function getObjectForDistance(distance) {
  16444. var levels = this.levels;
  16445. if (levels.length > 0) {
  16446. var i, l;
  16447. for (i = 1, l = levels.length; i < l; i++) {
  16448. if (distance < levels[i].distance) {
  16449. break;
  16450. }
  16451. }
  16452. return levels[i - 1].object;
  16453. }
  16454. return null;
  16455. },
  16456. raycast: function raycast(raycaster, intersects) {
  16457. var levels = this.levels;
  16458. if (levels.length > 0) {
  16459. _v1$4.setFromMatrixPosition(this.matrixWorld);
  16460. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  16461. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  16462. }
  16463. },
  16464. update: function update(camera) {
  16465. var levels = this.levels;
  16466. if (levels.length > 1) {
  16467. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  16468. _v2$2.setFromMatrixPosition(this.matrixWorld);
  16469. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  16470. levels[0].object.visible = true;
  16471. var i, l;
  16472. for (i = 1, l = levels.length; i < l; i++) {
  16473. if (distance >= levels[i].distance) {
  16474. levels[i - 1].object.visible = false;
  16475. levels[i].object.visible = true;
  16476. } else {
  16477. break;
  16478. }
  16479. }
  16480. this._currentLevel = i - 1;
  16481. for (; i < l; i++) {
  16482. levels[i].object.visible = false;
  16483. }
  16484. }
  16485. },
  16486. toJSON: function toJSON(meta) {
  16487. var data = Object3D.prototype.toJSON.call(this, meta);
  16488. if (this.autoUpdate === false) data.object.autoUpdate = false;
  16489. data.object.levels = [];
  16490. var levels = this.levels;
  16491. for (var i = 0, l = levels.length; i < l; i++) {
  16492. var level = levels[i];
  16493. data.object.levels.push({
  16494. object: level.object.uuid,
  16495. distance: level.distance
  16496. });
  16497. }
  16498. return data;
  16499. }
  16500. });
  16501. var _basePosition = new Vector3();
  16502. var _skinIndex = new Vector4();
  16503. var _skinWeight = new Vector4();
  16504. var _vector$7 = new Vector3();
  16505. var _matrix$1 = new Matrix4();
  16506. function SkinnedMesh(geometry, material) {
  16507. Mesh.call(this, geometry, material);
  16508. this.type = 'SkinnedMesh';
  16509. this.bindMode = 'attached';
  16510. this.bindMatrix = new Matrix4();
  16511. this.bindMatrixInverse = new Matrix4();
  16512. }
  16513. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16514. constructor: SkinnedMesh,
  16515. isSkinnedMesh: true,
  16516. copy: function copy(source) {
  16517. Mesh.prototype.copy.call(this, source);
  16518. this.bindMode = source.bindMode;
  16519. this.bindMatrix.copy(source.bindMatrix);
  16520. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  16521. this.skeleton = source.skeleton;
  16522. return this;
  16523. },
  16524. bind: function bind(skeleton, bindMatrix) {
  16525. this.skeleton = skeleton;
  16526. if (bindMatrix === undefined) {
  16527. this.updateMatrixWorld(true);
  16528. this.skeleton.calculateInverses();
  16529. bindMatrix = this.matrixWorld;
  16530. }
  16531. this.bindMatrix.copy(bindMatrix);
  16532. this.bindMatrixInverse.copy(bindMatrix).invert();
  16533. },
  16534. pose: function pose() {
  16535. this.skeleton.pose();
  16536. },
  16537. normalizeSkinWeights: function normalizeSkinWeights() {
  16538. var vector = new Vector4();
  16539. var skinWeight = this.geometry.attributes.skinWeight;
  16540. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16541. vector.x = skinWeight.getX(i);
  16542. vector.y = skinWeight.getY(i);
  16543. vector.z = skinWeight.getZ(i);
  16544. vector.w = skinWeight.getW(i);
  16545. var scale = 1.0 / vector.manhattanLength();
  16546. if (scale !== Infinity) {
  16547. vector.multiplyScalar(scale);
  16548. } else {
  16549. vector.set(1, 0, 0, 0); // do something reasonable
  16550. }
  16551. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16552. }
  16553. },
  16554. updateMatrixWorld: function updateMatrixWorld(force) {
  16555. Mesh.prototype.updateMatrixWorld.call(this, force);
  16556. if (this.bindMode === 'attached') {
  16557. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16558. } else if (this.bindMode === 'detached') {
  16559. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16560. } else {
  16561. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16562. }
  16563. },
  16564. boneTransform: function boneTransform(index, target) {
  16565. var skeleton = this.skeleton;
  16566. var geometry = this.geometry;
  16567. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16568. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16569. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16570. target.set(0, 0, 0);
  16571. for (var i = 0; i < 4; i++) {
  16572. var weight = _skinWeight.getComponent(i);
  16573. if (weight !== 0) {
  16574. var boneIndex = _skinIndex.getComponent(i);
  16575. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16576. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16577. }
  16578. }
  16579. return target.applyMatrix4(this.bindMatrixInverse);
  16580. }
  16581. });
  16582. function Bone() {
  16583. Object3D.call(this);
  16584. this.type = 'Bone';
  16585. }
  16586. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16587. constructor: Bone,
  16588. isBone: true
  16589. });
  16590. var _offsetMatrix = new Matrix4();
  16591. var _identityMatrix = new Matrix4();
  16592. function Skeleton(bones, boneInverses) {
  16593. if (bones === void 0) {
  16594. bones = [];
  16595. }
  16596. if (boneInverses === void 0) {
  16597. boneInverses = [];
  16598. }
  16599. this.uuid = MathUtils.generateUUID();
  16600. this.bones = bones.slice(0);
  16601. this.boneInverses = boneInverses;
  16602. this.boneMatrices = null;
  16603. this.boneTexture = null;
  16604. this.boneTextureSize = 0;
  16605. this.frame = -1;
  16606. this.init();
  16607. }
  16608. Object.assign(Skeleton.prototype, {
  16609. init: function init() {
  16610. var bones = this.bones;
  16611. var boneInverses = this.boneInverses;
  16612. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16613. if (boneInverses.length === 0) {
  16614. this.calculateInverses();
  16615. } else {
  16616. // handle special case
  16617. if (bones.length !== boneInverses.length) {
  16618. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16619. this.boneInverses = [];
  16620. for (var i = 0, il = this.bones.length; i < il; i++) {
  16621. this.boneInverses.push(new Matrix4());
  16622. }
  16623. }
  16624. }
  16625. },
  16626. calculateInverses: function calculateInverses() {
  16627. this.boneInverses.length = 0;
  16628. for (var i = 0, il = this.bones.length; i < il; i++) {
  16629. var inverse = new Matrix4();
  16630. if (this.bones[i]) {
  16631. inverse.copy(this.bones[i].matrixWorld).invert();
  16632. }
  16633. this.boneInverses.push(inverse);
  16634. }
  16635. },
  16636. pose: function pose() {
  16637. // recover the bind-time world matrices
  16638. for (var i = 0, il = this.bones.length; i < il; i++) {
  16639. var bone = this.bones[i];
  16640. if (bone) {
  16641. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16642. }
  16643. } // compute the local matrices, positions, rotations and scales
  16644. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16645. var _bone = this.bones[_i];
  16646. if (_bone) {
  16647. if (_bone.parent && _bone.parent.isBone) {
  16648. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16649. _bone.matrix.multiply(_bone.matrixWorld);
  16650. } else {
  16651. _bone.matrix.copy(_bone.matrixWorld);
  16652. }
  16653. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16654. }
  16655. }
  16656. },
  16657. update: function update() {
  16658. var bones = this.bones;
  16659. var boneInverses = this.boneInverses;
  16660. var boneMatrices = this.boneMatrices;
  16661. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16662. for (var i = 0, il = bones.length; i < il; i++) {
  16663. // compute the offset between the current and the original transform
  16664. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16665. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16666. _offsetMatrix.toArray(boneMatrices, i * 16);
  16667. }
  16668. if (boneTexture !== null) {
  16669. boneTexture.needsUpdate = true;
  16670. }
  16671. },
  16672. clone: function clone() {
  16673. return new Skeleton(this.bones, this.boneInverses);
  16674. },
  16675. getBoneByName: function getBoneByName(name) {
  16676. for (var i = 0, il = this.bones.length; i < il; i++) {
  16677. var bone = this.bones[i];
  16678. if (bone.name === name) {
  16679. return bone;
  16680. }
  16681. }
  16682. return undefined;
  16683. },
  16684. dispose: function dispose() {
  16685. if (this.boneTexture !== null) {
  16686. this.boneTexture.dispose();
  16687. this.boneTexture = null;
  16688. }
  16689. },
  16690. fromJSON: function fromJSON(json, bones) {
  16691. this.uuid = json.uuid;
  16692. for (var i = 0, l = json.bones.length; i < l; i++) {
  16693. var uuid = json.bones[i];
  16694. var bone = bones[uuid];
  16695. if (bone === undefined) {
  16696. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16697. bone = new Bone();
  16698. }
  16699. this.bones.push(bone);
  16700. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16701. }
  16702. this.init();
  16703. return this;
  16704. },
  16705. toJSON: function toJSON() {
  16706. var data = {
  16707. metadata: {
  16708. version: 4.5,
  16709. type: 'Skeleton',
  16710. generator: 'Skeleton.toJSON'
  16711. },
  16712. bones: [],
  16713. boneInverses: []
  16714. };
  16715. data.uuid = this.uuid;
  16716. var bones = this.bones;
  16717. var boneInverses = this.boneInverses;
  16718. for (var i = 0, l = bones.length; i < l; i++) {
  16719. var bone = bones[i];
  16720. data.bones.push(bone.uuid);
  16721. var boneInverse = boneInverses[i];
  16722. data.boneInverses.push(boneInverse.toArray());
  16723. }
  16724. return data;
  16725. }
  16726. });
  16727. var _instanceLocalMatrix = new Matrix4();
  16728. var _instanceWorldMatrix = new Matrix4();
  16729. var _instanceIntersects = [];
  16730. var _mesh = new Mesh();
  16731. function InstancedMesh(geometry, material, count) {
  16732. Mesh.call(this, geometry, material);
  16733. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16734. this.instanceColor = null;
  16735. this.count = count;
  16736. this.frustumCulled = false;
  16737. }
  16738. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16739. constructor: InstancedMesh,
  16740. isInstancedMesh: true,
  16741. copy: function copy(source) {
  16742. Mesh.prototype.copy.call(this, source);
  16743. this.instanceMatrix.copy(source.instanceMatrix);
  16744. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16745. this.count = source.count;
  16746. return this;
  16747. },
  16748. getColorAt: function getColorAt(index, color) {
  16749. color.fromArray(this.instanceColor.array, index * 3);
  16750. },
  16751. getMatrixAt: function getMatrixAt(index, matrix) {
  16752. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16753. },
  16754. raycast: function raycast(raycaster, intersects) {
  16755. var matrixWorld = this.matrixWorld;
  16756. var raycastTimes = this.count;
  16757. _mesh.geometry = this.geometry;
  16758. _mesh.material = this.material;
  16759. if (_mesh.material === undefined) return;
  16760. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16761. // calculate the world matrix for each instance
  16762. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16763. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16764. _mesh.matrixWorld = _instanceWorldMatrix;
  16765. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16766. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16767. var intersect = _instanceIntersects[i];
  16768. intersect.instanceId = instanceId;
  16769. intersect.object = this;
  16770. intersects.push(intersect);
  16771. }
  16772. _instanceIntersects.length = 0;
  16773. }
  16774. },
  16775. setColorAt: function setColorAt(index, color) {
  16776. if (this.instanceColor === null) {
  16777. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16778. }
  16779. color.toArray(this.instanceColor.array, index * 3);
  16780. },
  16781. setMatrixAt: function setMatrixAt(index, matrix) {
  16782. matrix.toArray(this.instanceMatrix.array, index * 16);
  16783. },
  16784. updateMorphTargets: function updateMorphTargets() {},
  16785. dispose: function dispose() {
  16786. this.dispatchEvent({
  16787. type: 'dispose'
  16788. });
  16789. }
  16790. });
  16791. /**
  16792. * parameters = {
  16793. * color: <hex>,
  16794. * opacity: <float>,
  16795. *
  16796. * linewidth: <float>,
  16797. * linecap: "round",
  16798. * linejoin: "round"
  16799. * }
  16800. */
  16801. function LineBasicMaterial(parameters) {
  16802. Material.call(this);
  16803. this.type = 'LineBasicMaterial';
  16804. this.color = new Color(0xffffff);
  16805. this.linewidth = 1;
  16806. this.linecap = 'round';
  16807. this.linejoin = 'round';
  16808. this.morphTargets = false;
  16809. this.setValues(parameters);
  16810. }
  16811. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16812. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16813. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16814. LineBasicMaterial.prototype.copy = function (source) {
  16815. Material.prototype.copy.call(this, source);
  16816. this.color.copy(source.color);
  16817. this.linewidth = source.linewidth;
  16818. this.linecap = source.linecap;
  16819. this.linejoin = source.linejoin;
  16820. this.morphTargets = source.morphTargets;
  16821. return this;
  16822. };
  16823. var _start = new Vector3();
  16824. var _end = new Vector3();
  16825. var _inverseMatrix$1 = new Matrix4();
  16826. var _ray$1 = new Ray();
  16827. var _sphere$2 = new Sphere();
  16828. function Line(geometry, material) {
  16829. if (geometry === void 0) {
  16830. geometry = new BufferGeometry();
  16831. }
  16832. if (material === void 0) {
  16833. material = new LineBasicMaterial();
  16834. }
  16835. Object3D.call(this);
  16836. this.type = 'Line';
  16837. this.geometry = geometry;
  16838. this.material = material;
  16839. this.updateMorphTargets();
  16840. }
  16841. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16842. constructor: Line,
  16843. isLine: true,
  16844. copy: function copy(source) {
  16845. Object3D.prototype.copy.call(this, source);
  16846. this.material = source.material;
  16847. this.geometry = source.geometry;
  16848. return this;
  16849. },
  16850. computeLineDistances: function computeLineDistances() {
  16851. var geometry = this.geometry;
  16852. if (geometry.isBufferGeometry) {
  16853. // we assume non-indexed geometry
  16854. if (geometry.index === null) {
  16855. var positionAttribute = geometry.attributes.position;
  16856. var lineDistances = [0];
  16857. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16858. _start.fromBufferAttribute(positionAttribute, i - 1);
  16859. _end.fromBufferAttribute(positionAttribute, i);
  16860. lineDistances[i] = lineDistances[i - 1];
  16861. lineDistances[i] += _start.distanceTo(_end);
  16862. }
  16863. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16864. } else {
  16865. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16866. }
  16867. } else if (geometry.isGeometry) {
  16868. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16869. }
  16870. return this;
  16871. },
  16872. raycast: function raycast(raycaster, intersects) {
  16873. var geometry = this.geometry;
  16874. var matrixWorld = this.matrixWorld;
  16875. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16876. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16877. _sphere$2.copy(geometry.boundingSphere);
  16878. _sphere$2.applyMatrix4(matrixWorld);
  16879. _sphere$2.radius += threshold;
  16880. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16881. _inverseMatrix$1.copy(matrixWorld).invert();
  16882. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16883. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16884. var localThresholdSq = localThreshold * localThreshold;
  16885. var vStart = new Vector3();
  16886. var vEnd = new Vector3();
  16887. var interSegment = new Vector3();
  16888. var interRay = new Vector3();
  16889. var step = this.isLineSegments ? 2 : 1;
  16890. if (geometry.isBufferGeometry) {
  16891. var index = geometry.index;
  16892. var attributes = geometry.attributes;
  16893. var positionAttribute = attributes.position;
  16894. if (index !== null) {
  16895. var indices = index.array;
  16896. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16897. var a = indices[i];
  16898. var b = indices[i + 1];
  16899. vStart.fromBufferAttribute(positionAttribute, a);
  16900. vEnd.fromBufferAttribute(positionAttribute, b);
  16901. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16902. if (distSq > localThresholdSq) continue;
  16903. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16904. var distance = raycaster.ray.origin.distanceTo(interRay);
  16905. if (distance < raycaster.near || distance > raycaster.far) continue;
  16906. intersects.push({
  16907. distance: distance,
  16908. // What do we want? intersection point on the ray or on the segment??
  16909. // point: raycaster.ray.at( distance ),
  16910. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16911. index: i,
  16912. face: null,
  16913. faceIndex: null,
  16914. object: this
  16915. });
  16916. }
  16917. } else {
  16918. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  16919. vStart.fromBufferAttribute(positionAttribute, _i);
  16920. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  16921. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16922. if (_distSq > localThresholdSq) continue;
  16923. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16924. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16925. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16926. intersects.push({
  16927. distance: _distance,
  16928. // What do we want? intersection point on the ray or on the segment??
  16929. // point: raycaster.ray.at( distance ),
  16930. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16931. index: _i,
  16932. face: null,
  16933. faceIndex: null,
  16934. object: this
  16935. });
  16936. }
  16937. }
  16938. } else if (geometry.isGeometry) {
  16939. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16940. }
  16941. },
  16942. updateMorphTargets: function updateMorphTargets() {
  16943. var geometry = this.geometry;
  16944. if (geometry.isBufferGeometry) {
  16945. var morphAttributes = geometry.morphAttributes;
  16946. var keys = Object.keys(morphAttributes);
  16947. if (keys.length > 0) {
  16948. var morphAttribute = morphAttributes[keys[0]];
  16949. if (morphAttribute !== undefined) {
  16950. this.morphTargetInfluences = [];
  16951. this.morphTargetDictionary = {};
  16952. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16953. var name = morphAttribute[m].name || String(m);
  16954. this.morphTargetInfluences.push(0);
  16955. this.morphTargetDictionary[name] = m;
  16956. }
  16957. }
  16958. }
  16959. } else {
  16960. var morphTargets = geometry.morphTargets;
  16961. if (morphTargets !== undefined && morphTargets.length > 0) {
  16962. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16963. }
  16964. }
  16965. }
  16966. });
  16967. var _start$1 = new Vector3();
  16968. var _end$1 = new Vector3();
  16969. function LineSegments(geometry, material) {
  16970. Line.call(this, geometry, material);
  16971. this.type = 'LineSegments';
  16972. }
  16973. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16974. constructor: LineSegments,
  16975. isLineSegments: true,
  16976. computeLineDistances: function computeLineDistances() {
  16977. var geometry = this.geometry;
  16978. if (geometry.isBufferGeometry) {
  16979. // we assume non-indexed geometry
  16980. if (geometry.index === null) {
  16981. var positionAttribute = geometry.attributes.position;
  16982. var lineDistances = [];
  16983. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16984. _start$1.fromBufferAttribute(positionAttribute, i);
  16985. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16986. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16987. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16988. }
  16989. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16990. } else {
  16991. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16992. }
  16993. } else if (geometry.isGeometry) {
  16994. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16995. }
  16996. return this;
  16997. }
  16998. });
  16999. function LineLoop(geometry, material) {
  17000. Line.call(this, geometry, material);
  17001. this.type = 'LineLoop';
  17002. }
  17003. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  17004. constructor: LineLoop,
  17005. isLineLoop: true
  17006. });
  17007. /**
  17008. * parameters = {
  17009. * color: <hex>,
  17010. * opacity: <float>,
  17011. * map: new THREE.Texture( <Image> ),
  17012. * alphaMap: new THREE.Texture( <Image> ),
  17013. *
  17014. * size: <float>,
  17015. * sizeAttenuation: <bool>
  17016. *
  17017. * morphTargets: <bool>
  17018. * }
  17019. */
  17020. function PointsMaterial(parameters) {
  17021. Material.call(this);
  17022. this.type = 'PointsMaterial';
  17023. this.color = new Color(0xffffff);
  17024. this.map = null;
  17025. this.alphaMap = null;
  17026. this.size = 1;
  17027. this.sizeAttenuation = true;
  17028. this.morphTargets = false;
  17029. this.setValues(parameters);
  17030. }
  17031. PointsMaterial.prototype = Object.create(Material.prototype);
  17032. PointsMaterial.prototype.constructor = PointsMaterial;
  17033. PointsMaterial.prototype.isPointsMaterial = true;
  17034. PointsMaterial.prototype.copy = function (source) {
  17035. Material.prototype.copy.call(this, source);
  17036. this.color.copy(source.color);
  17037. this.map = source.map;
  17038. this.alphaMap = source.alphaMap;
  17039. this.size = source.size;
  17040. this.sizeAttenuation = source.sizeAttenuation;
  17041. this.morphTargets = source.morphTargets;
  17042. return this;
  17043. };
  17044. var _inverseMatrix$2 = new Matrix4();
  17045. var _ray$2 = new Ray();
  17046. var _sphere$3 = new Sphere();
  17047. var _position$1 = new Vector3();
  17048. function Points(geometry, material) {
  17049. if (geometry === void 0) {
  17050. geometry = new BufferGeometry();
  17051. }
  17052. if (material === void 0) {
  17053. material = new PointsMaterial();
  17054. }
  17055. Object3D.call(this);
  17056. this.type = 'Points';
  17057. this.geometry = geometry;
  17058. this.material = material;
  17059. this.updateMorphTargets();
  17060. }
  17061. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  17062. constructor: Points,
  17063. isPoints: true,
  17064. copy: function copy(source) {
  17065. Object3D.prototype.copy.call(this, source);
  17066. this.material = source.material;
  17067. this.geometry = source.geometry;
  17068. return this;
  17069. },
  17070. raycast: function raycast(raycaster, intersects) {
  17071. var geometry = this.geometry;
  17072. var matrixWorld = this.matrixWorld;
  17073. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  17074. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17075. _sphere$3.copy(geometry.boundingSphere);
  17076. _sphere$3.applyMatrix4(matrixWorld);
  17077. _sphere$3.radius += threshold;
  17078. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  17079. _inverseMatrix$2.copy(matrixWorld).invert();
  17080. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  17081. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17082. var localThresholdSq = localThreshold * localThreshold;
  17083. if (geometry.isBufferGeometry) {
  17084. var index = geometry.index;
  17085. var attributes = geometry.attributes;
  17086. var positionAttribute = attributes.position;
  17087. if (index !== null) {
  17088. var indices = index.array;
  17089. for (var i = 0, il = indices.length; i < il; i++) {
  17090. var a = indices[i];
  17091. _position$1.fromBufferAttribute(positionAttribute, a);
  17092. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17093. }
  17094. } else {
  17095. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  17096. _position$1.fromBufferAttribute(positionAttribute, _i);
  17097. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17098. }
  17099. }
  17100. } else {
  17101. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17102. }
  17103. },
  17104. updateMorphTargets: function updateMorphTargets() {
  17105. var geometry = this.geometry;
  17106. if (geometry.isBufferGeometry) {
  17107. var morphAttributes = geometry.morphAttributes;
  17108. var keys = Object.keys(morphAttributes);
  17109. if (keys.length > 0) {
  17110. var morphAttribute = morphAttributes[keys[0]];
  17111. if (morphAttribute !== undefined) {
  17112. this.morphTargetInfluences = [];
  17113. this.morphTargetDictionary = {};
  17114. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17115. var name = morphAttribute[m].name || String(m);
  17116. this.morphTargetInfluences.push(0);
  17117. this.morphTargetDictionary[name] = m;
  17118. }
  17119. }
  17120. }
  17121. } else {
  17122. var morphTargets = geometry.morphTargets;
  17123. if (morphTargets !== undefined && morphTargets.length > 0) {
  17124. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17125. }
  17126. }
  17127. }
  17128. });
  17129. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  17130. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  17131. if (rayPointDistanceSq < localThresholdSq) {
  17132. var intersectPoint = new Vector3();
  17133. _ray$2.closestPointToPoint(point, intersectPoint);
  17134. intersectPoint.applyMatrix4(matrixWorld);
  17135. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  17136. if (distance < raycaster.near || distance > raycaster.far) return;
  17137. intersects.push({
  17138. distance: distance,
  17139. distanceToRay: Math.sqrt(rayPointDistanceSq),
  17140. point: intersectPoint,
  17141. index: index,
  17142. face: null,
  17143. object: object
  17144. });
  17145. }
  17146. }
  17147. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17148. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17149. this.format = format !== undefined ? format : RGBFormat;
  17150. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17151. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17152. this.generateMipmaps = false;
  17153. var scope = this;
  17154. function updateVideo() {
  17155. scope.needsUpdate = true;
  17156. video.requestVideoFrameCallback(updateVideo);
  17157. }
  17158. if ('requestVideoFrameCallback' in video) {
  17159. video.requestVideoFrameCallback(updateVideo);
  17160. }
  17161. }
  17162. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  17163. constructor: VideoTexture,
  17164. clone: function clone() {
  17165. return new this.constructor(this.image).copy(this);
  17166. },
  17167. isVideoTexture: true,
  17168. update: function update() {
  17169. var video = this.image;
  17170. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  17171. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  17172. this.needsUpdate = true;
  17173. }
  17174. }
  17175. });
  17176. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  17177. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  17178. this.image = {
  17179. width: width,
  17180. height: height
  17181. };
  17182. this.mipmaps = mipmaps; // no flipping for cube textures
  17183. // (also flipping doesn't work for compressed textures )
  17184. this.flipY = false; // can't generate mipmaps for compressed textures
  17185. // mips must be embedded in DDS files
  17186. this.generateMipmaps = false;
  17187. }
  17188. CompressedTexture.prototype = Object.create(Texture.prototype);
  17189. CompressedTexture.prototype.constructor = CompressedTexture;
  17190. CompressedTexture.prototype.isCompressedTexture = true;
  17191. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17192. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17193. this.needsUpdate = true;
  17194. }
  17195. CanvasTexture.prototype = Object.create(Texture.prototype);
  17196. CanvasTexture.prototype.constructor = CanvasTexture;
  17197. CanvasTexture.prototype.isCanvasTexture = true;
  17198. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  17199. format = format !== undefined ? format : DepthFormat;
  17200. if (format !== DepthFormat && format !== DepthStencilFormat) {
  17201. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  17202. }
  17203. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  17204. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  17205. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17206. this.image = {
  17207. width: width,
  17208. height: height
  17209. };
  17210. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17211. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17212. this.flipY = false;
  17213. this.generateMipmaps = false;
  17214. }
  17215. DepthTexture.prototype = Object.create(Texture.prototype);
  17216. DepthTexture.prototype.constructor = DepthTexture;
  17217. DepthTexture.prototype.isDepthTexture = true;
  17218. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17219. _inheritsLoose(CircleGeometry, _BufferGeometry);
  17220. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17221. var _this;
  17222. if (radius === void 0) {
  17223. radius = 1;
  17224. }
  17225. if (segments === void 0) {
  17226. segments = 8;
  17227. }
  17228. if (thetaStart === void 0) {
  17229. thetaStart = 0;
  17230. }
  17231. if (thetaLength === void 0) {
  17232. thetaLength = Math.PI * 2;
  17233. }
  17234. _this = _BufferGeometry.call(this) || this;
  17235. _this.type = 'CircleGeometry';
  17236. _this.parameters = {
  17237. radius: radius,
  17238. segments: segments,
  17239. thetaStart: thetaStart,
  17240. thetaLength: thetaLength
  17241. };
  17242. segments = Math.max(3, segments); // buffers
  17243. var indices = [];
  17244. var vertices = [];
  17245. var normals = [];
  17246. var uvs = []; // helper variables
  17247. var vertex = new Vector3();
  17248. var uv = new Vector2(); // center point
  17249. vertices.push(0, 0, 0);
  17250. normals.push(0, 0, 1);
  17251. uvs.push(0.5, 0.5);
  17252. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17253. var segment = thetaStart + s / segments * thetaLength; // vertex
  17254. vertex.x = radius * Math.cos(segment);
  17255. vertex.y = radius * Math.sin(segment);
  17256. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17257. normals.push(0, 0, 1); // uvs
  17258. uv.x = (vertices[i] / radius + 1) / 2;
  17259. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17260. uvs.push(uv.x, uv.y);
  17261. } // indices
  17262. for (var _i = 1; _i <= segments; _i++) {
  17263. indices.push(_i, _i + 1, 0);
  17264. } // build geometry
  17265. _this.setIndex(indices);
  17266. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17267. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17268. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17269. return _this;
  17270. }
  17271. return CircleGeometry;
  17272. }(BufferGeometry);
  17273. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17274. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  17275. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17276. var _this;
  17277. if (radiusTop === void 0) {
  17278. radiusTop = 1;
  17279. }
  17280. if (radiusBottom === void 0) {
  17281. radiusBottom = 1;
  17282. }
  17283. if (height === void 0) {
  17284. height = 1;
  17285. }
  17286. if (radialSegments === void 0) {
  17287. radialSegments = 8;
  17288. }
  17289. if (heightSegments === void 0) {
  17290. heightSegments = 1;
  17291. }
  17292. if (openEnded === void 0) {
  17293. openEnded = false;
  17294. }
  17295. if (thetaStart === void 0) {
  17296. thetaStart = 0;
  17297. }
  17298. if (thetaLength === void 0) {
  17299. thetaLength = Math.PI * 2;
  17300. }
  17301. _this = _BufferGeometry.call(this) || this;
  17302. _this.type = 'CylinderGeometry';
  17303. _this.parameters = {
  17304. radiusTop: radiusTop,
  17305. radiusBottom: radiusBottom,
  17306. height: height,
  17307. radialSegments: radialSegments,
  17308. heightSegments: heightSegments,
  17309. openEnded: openEnded,
  17310. thetaStart: thetaStart,
  17311. thetaLength: thetaLength
  17312. };
  17313. var scope = _assertThisInitialized(_this);
  17314. radialSegments = Math.floor(radialSegments);
  17315. heightSegments = Math.floor(heightSegments); // buffers
  17316. var indices = [];
  17317. var vertices = [];
  17318. var normals = [];
  17319. var uvs = []; // helper variables
  17320. var index = 0;
  17321. var indexArray = [];
  17322. var halfHeight = height / 2;
  17323. var groupStart = 0; // generate geometry
  17324. generateTorso();
  17325. if (openEnded === false) {
  17326. if (radiusTop > 0) generateCap(true);
  17327. if (radiusBottom > 0) generateCap(false);
  17328. } // build geometry
  17329. _this.setIndex(indices);
  17330. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17331. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17332. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17333. function generateTorso() {
  17334. var normal = new Vector3();
  17335. var vertex = new Vector3();
  17336. var groupCount = 0; // this will be used to calculate the normal
  17337. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17338. for (var y = 0; y <= heightSegments; y++) {
  17339. var indexRow = [];
  17340. var v = y / heightSegments; // calculate the radius of the current row
  17341. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17342. for (var x = 0; x <= radialSegments; x++) {
  17343. var u = x / radialSegments;
  17344. var theta = u * thetaLength + thetaStart;
  17345. var sinTheta = Math.sin(theta);
  17346. var cosTheta = Math.cos(theta); // vertex
  17347. vertex.x = radius * sinTheta;
  17348. vertex.y = -v * height + halfHeight;
  17349. vertex.z = radius * cosTheta;
  17350. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17351. normal.set(sinTheta, slope, cosTheta).normalize();
  17352. normals.push(normal.x, normal.y, normal.z); // uv
  17353. uvs.push(u, 1 - v); // save index of vertex in respective row
  17354. indexRow.push(index++);
  17355. } // now save vertices of the row in our index array
  17356. indexArray.push(indexRow);
  17357. } // generate indices
  17358. for (var _x = 0; _x < radialSegments; _x++) {
  17359. for (var _y = 0; _y < heightSegments; _y++) {
  17360. // we use the index array to access the correct indices
  17361. var a = indexArray[_y][_x];
  17362. var b = indexArray[_y + 1][_x];
  17363. var c = indexArray[_y + 1][_x + 1];
  17364. var d = indexArray[_y][_x + 1]; // faces
  17365. indices.push(a, b, d);
  17366. indices.push(b, c, d); // update group counter
  17367. groupCount += 6;
  17368. }
  17369. } // add a group to the geometry. this will ensure multi material support
  17370. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17371. groupStart += groupCount;
  17372. }
  17373. function generateCap(top) {
  17374. // save the index of the first center vertex
  17375. var centerIndexStart = index;
  17376. var uv = new Vector2();
  17377. var vertex = new Vector3();
  17378. var groupCount = 0;
  17379. var radius = top === true ? radiusTop : radiusBottom;
  17380. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17381. // because the geometry needs one set of uvs per face,
  17382. // we must generate a center vertex per face/segment
  17383. for (var x = 1; x <= radialSegments; x++) {
  17384. // vertex
  17385. vertices.push(0, halfHeight * sign, 0); // normal
  17386. normals.push(0, sign, 0); // uv
  17387. uvs.push(0.5, 0.5); // increase index
  17388. index++;
  17389. } // save the index of the last center vertex
  17390. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17391. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17392. var u = _x2 / radialSegments;
  17393. var theta = u * thetaLength + thetaStart;
  17394. var cosTheta = Math.cos(theta);
  17395. var sinTheta = Math.sin(theta); // vertex
  17396. vertex.x = radius * sinTheta;
  17397. vertex.y = halfHeight * sign;
  17398. vertex.z = radius * cosTheta;
  17399. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17400. normals.push(0, sign, 0); // uv
  17401. uv.x = cosTheta * 0.5 + 0.5;
  17402. uv.y = sinTheta * 0.5 * sign + 0.5;
  17403. uvs.push(uv.x, uv.y); // increase index
  17404. index++;
  17405. } // generate indices
  17406. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17407. var c = centerIndexStart + _x3;
  17408. var i = centerIndexEnd + _x3;
  17409. if (top === true) {
  17410. // face top
  17411. indices.push(i, i + 1, c);
  17412. } else {
  17413. // face bottom
  17414. indices.push(i + 1, i, c);
  17415. }
  17416. groupCount += 3;
  17417. } // add a group to the geometry. this will ensure multi material support
  17418. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17419. groupStart += groupCount;
  17420. }
  17421. return _this;
  17422. }
  17423. return CylinderGeometry;
  17424. }(BufferGeometry);
  17425. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17426. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17427. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17428. var _this;
  17429. if (radius === void 0) {
  17430. radius = 1;
  17431. }
  17432. if (height === void 0) {
  17433. height = 1;
  17434. }
  17435. if (radialSegments === void 0) {
  17436. radialSegments = 8;
  17437. }
  17438. if (heightSegments === void 0) {
  17439. heightSegments = 1;
  17440. }
  17441. if (openEnded === void 0) {
  17442. openEnded = false;
  17443. }
  17444. if (thetaStart === void 0) {
  17445. thetaStart = 0;
  17446. }
  17447. if (thetaLength === void 0) {
  17448. thetaLength = Math.PI * 2;
  17449. }
  17450. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17451. _this.type = 'ConeGeometry';
  17452. _this.parameters = {
  17453. radius: radius,
  17454. height: height,
  17455. radialSegments: radialSegments,
  17456. heightSegments: heightSegments,
  17457. openEnded: openEnded,
  17458. thetaStart: thetaStart,
  17459. thetaLength: thetaLength
  17460. };
  17461. return _this;
  17462. }
  17463. return ConeGeometry;
  17464. }(CylinderGeometry);
  17465. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17466. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  17467. function PolyhedronGeometry(vertices, indices, radius, detail) {
  17468. var _this;
  17469. if (radius === void 0) {
  17470. radius = 1;
  17471. }
  17472. if (detail === void 0) {
  17473. detail = 0;
  17474. }
  17475. _this = _BufferGeometry.call(this) || this;
  17476. _this.type = 'PolyhedronGeometry';
  17477. _this.parameters = {
  17478. vertices: vertices,
  17479. indices: indices,
  17480. radius: radius,
  17481. detail: detail
  17482. }; // default buffer data
  17483. var vertexBuffer = [];
  17484. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17485. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17486. applyRadius(radius); // finally, create the uv data
  17487. generateUVs(); // build non-indexed geometry
  17488. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17489. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17490. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17491. if (detail === 0) {
  17492. _this.computeVertexNormals(); // flat normals
  17493. } else {
  17494. _this.normalizeNormals(); // smooth normals
  17495. } // helper functions
  17496. function subdivide(detail) {
  17497. var a = new Vector3();
  17498. var b = new Vector3();
  17499. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17500. for (var i = 0; i < indices.length; i += 3) {
  17501. // get the vertices of the face
  17502. getVertexByIndex(indices[i + 0], a);
  17503. getVertexByIndex(indices[i + 1], b);
  17504. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17505. subdivideFace(a, b, c, detail);
  17506. }
  17507. }
  17508. function subdivideFace(a, b, c, detail) {
  17509. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17510. var v = []; // construct all of the vertices for this subdivision
  17511. for (var i = 0; i <= cols; i++) {
  17512. v[i] = [];
  17513. var aj = a.clone().lerp(c, i / cols);
  17514. var bj = b.clone().lerp(c, i / cols);
  17515. var rows = cols - i;
  17516. for (var j = 0; j <= rows; j++) {
  17517. if (j === 0 && i === cols) {
  17518. v[i][j] = aj;
  17519. } else {
  17520. v[i][j] = aj.clone().lerp(bj, j / rows);
  17521. }
  17522. }
  17523. } // construct all of the faces
  17524. for (var _i = 0; _i < cols; _i++) {
  17525. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17526. var k = Math.floor(_j / 2);
  17527. if (_j % 2 === 0) {
  17528. pushVertex(v[_i][k + 1]);
  17529. pushVertex(v[_i + 1][k]);
  17530. pushVertex(v[_i][k]);
  17531. } else {
  17532. pushVertex(v[_i][k + 1]);
  17533. pushVertex(v[_i + 1][k + 1]);
  17534. pushVertex(v[_i + 1][k]);
  17535. }
  17536. }
  17537. }
  17538. }
  17539. function applyRadius(radius) {
  17540. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17541. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17542. vertex.x = vertexBuffer[i + 0];
  17543. vertex.y = vertexBuffer[i + 1];
  17544. vertex.z = vertexBuffer[i + 2];
  17545. vertex.normalize().multiplyScalar(radius);
  17546. vertexBuffer[i + 0] = vertex.x;
  17547. vertexBuffer[i + 1] = vertex.y;
  17548. vertexBuffer[i + 2] = vertex.z;
  17549. }
  17550. }
  17551. function generateUVs() {
  17552. var vertex = new Vector3();
  17553. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17554. vertex.x = vertexBuffer[i + 0];
  17555. vertex.y = vertexBuffer[i + 1];
  17556. vertex.z = vertexBuffer[i + 2];
  17557. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17558. var v = inclination(vertex) / Math.PI + 0.5;
  17559. uvBuffer.push(u, 1 - v);
  17560. }
  17561. correctUVs();
  17562. correctSeam();
  17563. }
  17564. function correctSeam() {
  17565. // handle case when face straddles the seam, see #3269
  17566. for (var i = 0; i < uvBuffer.length; i += 6) {
  17567. // uv data of a single face
  17568. var x0 = uvBuffer[i + 0];
  17569. var x1 = uvBuffer[i + 2];
  17570. var x2 = uvBuffer[i + 4];
  17571. var max = Math.max(x0, x1, x2);
  17572. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17573. if (max > 0.9 && min < 0.1) {
  17574. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17575. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17576. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17577. }
  17578. }
  17579. }
  17580. function pushVertex(vertex) {
  17581. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17582. }
  17583. function getVertexByIndex(index, vertex) {
  17584. var stride = index * 3;
  17585. vertex.x = vertices[stride + 0];
  17586. vertex.y = vertices[stride + 1];
  17587. vertex.z = vertices[stride + 2];
  17588. }
  17589. function correctUVs() {
  17590. var a = new Vector3();
  17591. var b = new Vector3();
  17592. var c = new Vector3();
  17593. var centroid = new Vector3();
  17594. var uvA = new Vector2();
  17595. var uvB = new Vector2();
  17596. var uvC = new Vector2();
  17597. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17598. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17599. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17600. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17601. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17602. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17603. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17604. centroid.copy(a).add(b).add(c).divideScalar(3);
  17605. var azi = azimuth(centroid);
  17606. correctUV(uvA, j + 0, a, azi);
  17607. correctUV(uvB, j + 2, b, azi);
  17608. correctUV(uvC, j + 4, c, azi);
  17609. }
  17610. }
  17611. function correctUV(uv, stride, vector, azimuth) {
  17612. if (azimuth < 0 && uv.x === 1) {
  17613. uvBuffer[stride] = uv.x - 1;
  17614. }
  17615. if (vector.x === 0 && vector.z === 0) {
  17616. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17617. }
  17618. } // Angle around the Y axis, counter-clockwise when looking from above.
  17619. function azimuth(vector) {
  17620. return Math.atan2(vector.z, -vector.x);
  17621. } // Angle above the XZ plane.
  17622. function inclination(vector) {
  17623. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17624. }
  17625. return _this;
  17626. }
  17627. return PolyhedronGeometry;
  17628. }(BufferGeometry);
  17629. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17630. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17631. function DodecahedronGeometry(radius, detail) {
  17632. var _this;
  17633. if (radius === void 0) {
  17634. radius = 1;
  17635. }
  17636. if (detail === void 0) {
  17637. detail = 0;
  17638. }
  17639. var t = (1 + Math.sqrt(5)) / 2;
  17640. var r = 1 / t;
  17641. var vertices = [// (±1, ±1, ±1)
  17642. -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/φ, ±φ)
  17643. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17644. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17645. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17646. 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];
  17647. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17648. _this.type = 'DodecahedronGeometry';
  17649. _this.parameters = {
  17650. radius: radius,
  17651. detail: detail
  17652. };
  17653. return _this;
  17654. }
  17655. return DodecahedronGeometry;
  17656. }(PolyhedronGeometry);
  17657. var _v0$2 = new Vector3();
  17658. var _v1$5 = new Vector3();
  17659. var _normal$1 = new Vector3();
  17660. var _triangle = new Triangle();
  17661. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17662. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17663. function EdgesGeometry(geometry, thresholdAngle) {
  17664. var _this;
  17665. _this = _BufferGeometry.call(this) || this;
  17666. _this.type = 'EdgesGeometry';
  17667. _this.parameters = {
  17668. thresholdAngle: thresholdAngle
  17669. };
  17670. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17671. if (geometry.isGeometry === true) {
  17672. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17673. return _assertThisInitialized(_this);
  17674. }
  17675. var precisionPoints = 4;
  17676. var precision = Math.pow(10, precisionPoints);
  17677. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17678. var indexAttr = geometry.getIndex();
  17679. var positionAttr = geometry.getAttribute('position');
  17680. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17681. var indexArr = [0, 0, 0];
  17682. var vertKeys = ['a', 'b', 'c'];
  17683. var hashes = new Array(3);
  17684. var edgeData = {};
  17685. var vertices = [];
  17686. for (var i = 0; i < indexCount; i += 3) {
  17687. if (indexAttr) {
  17688. indexArr[0] = indexAttr.getX(i);
  17689. indexArr[1] = indexAttr.getX(i + 1);
  17690. indexArr[2] = indexAttr.getX(i + 2);
  17691. } else {
  17692. indexArr[0] = i;
  17693. indexArr[1] = i + 1;
  17694. indexArr[2] = i + 2;
  17695. }
  17696. var a = _triangle.a,
  17697. b = _triangle.b,
  17698. c = _triangle.c;
  17699. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17700. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17701. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17702. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17703. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17704. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17705. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17706. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17707. continue;
  17708. } // iterate over every edge
  17709. for (var j = 0; j < 3; j++) {
  17710. // get the first and next vertex making up the edge
  17711. var jNext = (j + 1) % 3;
  17712. var vecHash0 = hashes[j];
  17713. var vecHash1 = hashes[jNext];
  17714. var v0 = _triangle[vertKeys[j]];
  17715. var v1 = _triangle[vertKeys[jNext]];
  17716. var hash = vecHash0 + "_" + vecHash1;
  17717. var reverseHash = vecHash1 + "_" + vecHash0;
  17718. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17719. // if we found a sibling edge add it into the vertex array if
  17720. // it meets the angle threshold and delete the edge from the map.
  17721. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17722. vertices.push(v0.x, v0.y, v0.z);
  17723. vertices.push(v1.x, v1.y, v1.z);
  17724. }
  17725. edgeData[reverseHash] = null;
  17726. } else if (!(hash in edgeData)) {
  17727. // if we've already got an edge here then skip adding a new one
  17728. edgeData[hash] = {
  17729. index0: indexArr[j],
  17730. index1: indexArr[jNext],
  17731. normal: _normal$1.clone()
  17732. };
  17733. }
  17734. }
  17735. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17736. for (var key in edgeData) {
  17737. if (edgeData[key]) {
  17738. var _edgeData$key = edgeData[key],
  17739. index0 = _edgeData$key.index0,
  17740. index1 = _edgeData$key.index1;
  17741. _v0$2.fromBufferAttribute(positionAttr, index0);
  17742. _v1$5.fromBufferAttribute(positionAttr, index1);
  17743. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17744. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17745. }
  17746. }
  17747. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17748. return _this;
  17749. }
  17750. return EdgesGeometry;
  17751. }(BufferGeometry);
  17752. /**
  17753. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17754. */
  17755. var Earcut = {
  17756. triangulate: function triangulate(data, holeIndices, dim) {
  17757. dim = dim || 2;
  17758. var hasHoles = holeIndices && holeIndices.length;
  17759. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17760. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17761. var triangles = [];
  17762. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17763. var minX, minY, maxX, maxY, x, y, invSize;
  17764. 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
  17765. if (data.length > 80 * dim) {
  17766. minX = maxX = data[0];
  17767. minY = maxY = data[1];
  17768. for (var i = dim; i < outerLen; i += dim) {
  17769. x = data[i];
  17770. y = data[i + 1];
  17771. if (x < minX) minX = x;
  17772. if (y < minY) minY = y;
  17773. if (x > maxX) maxX = x;
  17774. if (y > maxY) maxY = y;
  17775. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17776. invSize = Math.max(maxX - minX, maxY - minY);
  17777. invSize = invSize !== 0 ? 1 / invSize : 0;
  17778. }
  17779. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17780. return triangles;
  17781. }
  17782. }; // create a circular doubly linked list from polygon points in the specified winding order
  17783. function linkedList(data, start, end, dim, clockwise) {
  17784. var i, last;
  17785. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17786. for (i = start; i < end; i += dim) {
  17787. last = insertNode(i, data[i], data[i + 1], last);
  17788. }
  17789. } else {
  17790. for (i = end - dim; i >= start; i -= dim) {
  17791. last = insertNode(i, data[i], data[i + 1], last);
  17792. }
  17793. }
  17794. if (last && equals(last, last.next)) {
  17795. removeNode(last);
  17796. last = last.next;
  17797. }
  17798. return last;
  17799. } // eliminate colinear or duplicate points
  17800. function filterPoints(start, end) {
  17801. if (!start) return start;
  17802. if (!end) end = start;
  17803. var p = start,
  17804. again;
  17805. do {
  17806. again = false;
  17807. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17808. removeNode(p);
  17809. p = end = p.prev;
  17810. if (p === p.next) break;
  17811. again = true;
  17812. } else {
  17813. p = p.next;
  17814. }
  17815. } while (again || p !== end);
  17816. return end;
  17817. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17818. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17819. if (!ear) return; // interlink polygon nodes in z-order
  17820. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17821. var stop = ear,
  17822. prev,
  17823. next; // iterate through ears, slicing them one by one
  17824. while (ear.prev !== ear.next) {
  17825. prev = ear.prev;
  17826. next = ear.next;
  17827. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17828. // cut off the triangle
  17829. triangles.push(prev.i / dim);
  17830. triangles.push(ear.i / dim);
  17831. triangles.push(next.i / dim);
  17832. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17833. ear = next.next;
  17834. stop = next.next;
  17835. continue;
  17836. }
  17837. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17838. if (ear === stop) {
  17839. // try filtering points and slicing again
  17840. if (!pass) {
  17841. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17842. } else if (pass === 1) {
  17843. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17844. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17845. } else if (pass === 2) {
  17846. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17847. }
  17848. break;
  17849. }
  17850. }
  17851. } // check whether a polygon node forms a valid ear with adjacent nodes
  17852. function isEar(ear) {
  17853. var a = ear.prev,
  17854. b = ear,
  17855. c = ear.next;
  17856. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17857. // now make sure we don't have other points inside the potential ear
  17858. var p = ear.next.next;
  17859. while (p !== ear.prev) {
  17860. 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;
  17861. p = p.next;
  17862. }
  17863. return true;
  17864. }
  17865. function isEarHashed(ear, minX, minY, invSize) {
  17866. var a = ear.prev,
  17867. b = ear,
  17868. c = ear.next;
  17869. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17870. // triangle bbox; min & max are calculated like this for speed
  17871. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17872. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17873. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17874. 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;
  17875. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17876. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17877. var p = ear.prevZ,
  17878. n = ear.nextZ; // look for points inside the triangle in both directions
  17879. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17880. 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;
  17881. p = p.prevZ;
  17882. 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;
  17883. n = n.nextZ;
  17884. } // look for remaining points in decreasing z-order
  17885. while (p && p.z >= minZ) {
  17886. 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;
  17887. p = p.prevZ;
  17888. } // look for remaining points in increasing z-order
  17889. while (n && n.z <= maxZ) {
  17890. 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;
  17891. n = n.nextZ;
  17892. }
  17893. return true;
  17894. } // go through all polygon nodes and cure small local self-intersections
  17895. function cureLocalIntersections(start, triangles, dim) {
  17896. var p = start;
  17897. do {
  17898. var a = p.prev,
  17899. b = p.next.next;
  17900. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17901. triangles.push(a.i / dim);
  17902. triangles.push(p.i / dim);
  17903. triangles.push(b.i / dim); // remove two nodes involved
  17904. removeNode(p);
  17905. removeNode(p.next);
  17906. p = start = b;
  17907. }
  17908. p = p.next;
  17909. } while (p !== start);
  17910. return filterPoints(p);
  17911. } // try splitting polygon into two and triangulate them independently
  17912. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17913. // look for a valid diagonal that divides the polygon into two
  17914. var a = start;
  17915. do {
  17916. var b = a.next.next;
  17917. while (b !== a.prev) {
  17918. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17919. // split the polygon in two by the diagonal
  17920. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17921. a = filterPoints(a, a.next);
  17922. c = filterPoints(c, c.next); // run earcut on each half
  17923. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17924. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17925. return;
  17926. }
  17927. b = b.next;
  17928. }
  17929. a = a.next;
  17930. } while (a !== start);
  17931. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17932. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17933. var queue = [];
  17934. var i, len, start, end, list;
  17935. for (i = 0, len = holeIndices.length; i < len; i++) {
  17936. start = holeIndices[i] * dim;
  17937. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17938. list = linkedList(data, start, end, dim, false);
  17939. if (list === list.next) list.steiner = true;
  17940. queue.push(getLeftmost(list));
  17941. }
  17942. queue.sort(compareX); // process holes from left to right
  17943. for (i = 0; i < queue.length; i++) {
  17944. eliminateHole(queue[i], outerNode);
  17945. outerNode = filterPoints(outerNode, outerNode.next);
  17946. }
  17947. return outerNode;
  17948. }
  17949. function compareX(a, b) {
  17950. return a.x - b.x;
  17951. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17952. function eliminateHole(hole, outerNode) {
  17953. outerNode = findHoleBridge(hole, outerNode);
  17954. if (outerNode) {
  17955. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17956. filterPoints(outerNode, outerNode.next);
  17957. filterPoints(b, b.next);
  17958. }
  17959. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17960. function findHoleBridge(hole, outerNode) {
  17961. var p = outerNode;
  17962. var hx = hole.x;
  17963. var hy = hole.y;
  17964. var qx = -Infinity,
  17965. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17966. // segment's endpoint with lesser x will be potential connection point
  17967. do {
  17968. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17969. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17970. if (x <= hx && x > qx) {
  17971. qx = x;
  17972. if (x === hx) {
  17973. if (hy === p.y) return p;
  17974. if (hy === p.next.y) return p.next;
  17975. }
  17976. m = p.x < p.next.x ? p : p.next;
  17977. }
  17978. }
  17979. p = p.next;
  17980. } while (p !== outerNode);
  17981. if (!m) return null;
  17982. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17983. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17984. // if there are no points found, we have a valid connection;
  17985. // otherwise choose the point of the minimum angle with the ray as connection point
  17986. var stop = m,
  17987. mx = m.x,
  17988. my = m.y;
  17989. var tanMin = Infinity,
  17990. tan;
  17991. p = m;
  17992. do {
  17993. 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)) {
  17994. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17995. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17996. m = p;
  17997. tanMin = tan;
  17998. }
  17999. }
  18000. p = p.next;
  18001. } while (p !== stop);
  18002. return m;
  18003. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  18004. function sectorContainsSector(m, p) {
  18005. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  18006. } // interlink polygon nodes in z-order
  18007. function indexCurve(start, minX, minY, invSize) {
  18008. var p = start;
  18009. do {
  18010. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  18011. p.prevZ = p.prev;
  18012. p.nextZ = p.next;
  18013. p = p.next;
  18014. } while (p !== start);
  18015. p.prevZ.nextZ = null;
  18016. p.prevZ = null;
  18017. sortLinked(p);
  18018. } // Simon Tatham's linked list merge sort algorithm
  18019. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  18020. function sortLinked(list) {
  18021. var i,
  18022. p,
  18023. q,
  18024. e,
  18025. tail,
  18026. numMerges,
  18027. pSize,
  18028. qSize,
  18029. inSize = 1;
  18030. do {
  18031. p = list;
  18032. list = null;
  18033. tail = null;
  18034. numMerges = 0;
  18035. while (p) {
  18036. numMerges++;
  18037. q = p;
  18038. pSize = 0;
  18039. for (i = 0; i < inSize; i++) {
  18040. pSize++;
  18041. q = q.nextZ;
  18042. if (!q) break;
  18043. }
  18044. qSize = inSize;
  18045. while (pSize > 0 || qSize > 0 && q) {
  18046. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18047. e = p;
  18048. p = p.nextZ;
  18049. pSize--;
  18050. } else {
  18051. e = q;
  18052. q = q.nextZ;
  18053. qSize--;
  18054. }
  18055. if (tail) tail.nextZ = e;else list = e;
  18056. e.prevZ = tail;
  18057. tail = e;
  18058. }
  18059. p = q;
  18060. }
  18061. tail.nextZ = null;
  18062. inSize *= 2;
  18063. } while (numMerges > 1);
  18064. return list;
  18065. } // z-order of a point given coords and inverse of the longer side of data bbox
  18066. function zOrder(x, y, minX, minY, invSize) {
  18067. // coords are transformed into non-negative 15-bit integer range
  18068. x = 32767 * (x - minX) * invSize;
  18069. y = 32767 * (y - minY) * invSize;
  18070. x = (x | x << 8) & 0x00FF00FF;
  18071. x = (x | x << 4) & 0x0F0F0F0F;
  18072. x = (x | x << 2) & 0x33333333;
  18073. x = (x | x << 1) & 0x55555555;
  18074. y = (y | y << 8) & 0x00FF00FF;
  18075. y = (y | y << 4) & 0x0F0F0F0F;
  18076. y = (y | y << 2) & 0x33333333;
  18077. y = (y | y << 1) & 0x55555555;
  18078. return x | y << 1;
  18079. } // find the leftmost node of a polygon ring
  18080. function getLeftmost(start) {
  18081. var p = start,
  18082. leftmost = start;
  18083. do {
  18084. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18085. p = p.next;
  18086. } while (p !== start);
  18087. return leftmost;
  18088. } // check if a point lies within a convex triangle
  18089. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18090. 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;
  18091. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18092. function isValidDiagonal(a, b) {
  18093. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18094. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18095. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18096. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18097. } // signed area of a triangle
  18098. function area(p, q, r) {
  18099. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18100. } // check if two points are equal
  18101. function equals(p1, p2) {
  18102. return p1.x === p2.x && p1.y === p2.y;
  18103. } // check if two segments intersect
  18104. function intersects(p1, q1, p2, q2) {
  18105. var o1 = sign(area(p1, q1, p2));
  18106. var o2 = sign(area(p1, q1, q2));
  18107. var o3 = sign(area(p2, q2, p1));
  18108. var o4 = sign(area(p2, q2, q1));
  18109. if (o1 !== o2 && o3 !== o4) return true; // general case
  18110. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18111. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18112. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18113. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18114. return false;
  18115. } // for collinear points p, q, r, check if point q lies on segment pr
  18116. function onSegment(p, q, r) {
  18117. 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);
  18118. }
  18119. function sign(num) {
  18120. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18121. } // check if a polygon diagonal intersects any polygon segments
  18122. function intersectsPolygon(a, b) {
  18123. var p = a;
  18124. do {
  18125. 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;
  18126. p = p.next;
  18127. } while (p !== a);
  18128. return false;
  18129. } // check if a polygon diagonal is locally inside the polygon
  18130. function locallyInside(a, b) {
  18131. 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;
  18132. } // check if the middle point of a polygon diagonal is inside the polygon
  18133. function middleInside(a, b) {
  18134. var p = a,
  18135. inside = false;
  18136. var px = (a.x + b.x) / 2,
  18137. py = (a.y + b.y) / 2;
  18138. do {
  18139. 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;
  18140. p = p.next;
  18141. } while (p !== a);
  18142. return inside;
  18143. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18144. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18145. function splitPolygon(a, b) {
  18146. var a2 = new Node(a.i, a.x, a.y),
  18147. b2 = new Node(b.i, b.x, b.y),
  18148. an = a.next,
  18149. bp = b.prev;
  18150. a.next = b;
  18151. b.prev = a;
  18152. a2.next = an;
  18153. an.prev = a2;
  18154. b2.next = a2;
  18155. a2.prev = b2;
  18156. bp.next = b2;
  18157. b2.prev = bp;
  18158. return b2;
  18159. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18160. function insertNode(i, x, y, last) {
  18161. var p = new Node(i, x, y);
  18162. if (!last) {
  18163. p.prev = p;
  18164. p.next = p;
  18165. } else {
  18166. p.next = last.next;
  18167. p.prev = last;
  18168. last.next.prev = p;
  18169. last.next = p;
  18170. }
  18171. return p;
  18172. }
  18173. function removeNode(p) {
  18174. p.next.prev = p.prev;
  18175. p.prev.next = p.next;
  18176. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18177. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18178. }
  18179. function Node(i, x, y) {
  18180. // vertex index in coordinates array
  18181. this.i = i; // vertex coordinates
  18182. this.x = x;
  18183. this.y = y; // previous and next vertex nodes in a polygon ring
  18184. this.prev = null;
  18185. this.next = null; // z-order curve value
  18186. this.z = null; // previous and next nodes in z-order
  18187. this.prevZ = null;
  18188. this.nextZ = null; // indicates whether this is a steiner point
  18189. this.steiner = false;
  18190. }
  18191. function signedArea(data, start, end, dim) {
  18192. var sum = 0;
  18193. for (var i = start, j = end - dim; i < end; i += dim) {
  18194. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18195. j = i;
  18196. }
  18197. return sum;
  18198. }
  18199. var ShapeUtils = {
  18200. // calculate area of the contour polygon
  18201. area: function area(contour) {
  18202. var n = contour.length;
  18203. var a = 0.0;
  18204. for (var p = n - 1, q = 0; q < n; p = q++) {
  18205. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18206. }
  18207. return a * 0.5;
  18208. },
  18209. isClockWise: function isClockWise(pts) {
  18210. return ShapeUtils.area(pts) < 0;
  18211. },
  18212. triangulateShape: function triangulateShape(contour, holes) {
  18213. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18214. var holeIndices = []; // array of hole indices
  18215. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18216. removeDupEndPts(contour);
  18217. addContour(vertices, contour); //
  18218. var holeIndex = contour.length;
  18219. holes.forEach(removeDupEndPts);
  18220. for (var i = 0; i < holes.length; i++) {
  18221. holeIndices.push(holeIndex);
  18222. holeIndex += holes[i].length;
  18223. addContour(vertices, holes[i]);
  18224. } //
  18225. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18226. for (var _i = 0; _i < triangles.length; _i += 3) {
  18227. faces.push(triangles.slice(_i, _i + 3));
  18228. }
  18229. return faces;
  18230. }
  18231. };
  18232. function removeDupEndPts(points) {
  18233. var l = points.length;
  18234. if (l > 2 && points[l - 1].equals(points[0])) {
  18235. points.pop();
  18236. }
  18237. }
  18238. function addContour(vertices, contour) {
  18239. for (var i = 0; i < contour.length; i++) {
  18240. vertices.push(contour[i].x);
  18241. vertices.push(contour[i].y);
  18242. }
  18243. }
  18244. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18245. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  18246. function ExtrudeGeometry(shapes, options) {
  18247. var _this;
  18248. _this = _BufferGeometry.call(this) || this;
  18249. _this.type = 'ExtrudeGeometry';
  18250. _this.parameters = {
  18251. shapes: shapes,
  18252. options: options
  18253. };
  18254. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18255. var scope = _assertThisInitialized(_this);
  18256. var verticesArray = [];
  18257. var uvArray = [];
  18258. for (var i = 0, l = shapes.length; i < l; i++) {
  18259. var shape = shapes[i];
  18260. addShape(shape);
  18261. } // build geometry
  18262. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18263. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18264. _this.computeVertexNormals(); // functions
  18265. function addShape(shape) {
  18266. var placeholder = []; // options
  18267. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18268. var steps = options.steps !== undefined ? options.steps : 1;
  18269. var depth = options.depth !== undefined ? options.depth : 100;
  18270. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18271. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18272. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18273. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18274. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18275. var extrudePath = options.extrudePath;
  18276. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18277. if (options.amount !== undefined) {
  18278. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18279. depth = options.amount;
  18280. } //
  18281. var extrudePts,
  18282. extrudeByPath = false;
  18283. var splineTube, binormal, normal, position2;
  18284. if (extrudePath) {
  18285. extrudePts = extrudePath.getSpacedPoints(steps);
  18286. extrudeByPath = true;
  18287. bevelEnabled = false; // bevels not supported for path extrusion
  18288. // SETUP TNB variables
  18289. // TODO1 - have a .isClosed in spline?
  18290. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18291. binormal = new Vector3();
  18292. normal = new Vector3();
  18293. position2 = new Vector3();
  18294. } // Safeguards if bevels are not enabled
  18295. if (!bevelEnabled) {
  18296. bevelSegments = 0;
  18297. bevelThickness = 0;
  18298. bevelSize = 0;
  18299. bevelOffset = 0;
  18300. } // Variables initialization
  18301. var shapePoints = shape.extractPoints(curveSegments);
  18302. var vertices = shapePoints.shape;
  18303. var holes = shapePoints.holes;
  18304. var reverse = !ShapeUtils.isClockWise(vertices);
  18305. if (reverse) {
  18306. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18307. for (var h = 0, hl = holes.length; h < hl; h++) {
  18308. var ahole = holes[h];
  18309. if (ShapeUtils.isClockWise(ahole)) {
  18310. holes[h] = ahole.reverse();
  18311. }
  18312. }
  18313. }
  18314. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18315. /* Vertices */
  18316. var contour = vertices; // vertices has all points but contour has only points of circumference
  18317. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18318. var _ahole = holes[_h];
  18319. vertices = vertices.concat(_ahole);
  18320. }
  18321. function scalePt2(pt, vec, size) {
  18322. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18323. return vec.clone().multiplyScalar(size).add(pt);
  18324. }
  18325. var vlen = vertices.length,
  18326. flen = faces.length; // Find directions for point movement
  18327. function getBevelVec(inPt, inPrev, inNext) {
  18328. // computes for inPt the corresponding point inPt' on a new contour
  18329. // shifted by 1 unit (length of normalized vector) to the left
  18330. // if we walk along contour clockwise, this new contour is outside the old one
  18331. //
  18332. // inPt' is the intersection of the two lines parallel to the two
  18333. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18334. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18335. // good reading for geometry algorithms (here: line-line intersection)
  18336. // http://geomalgorithms.com/a05-_intersect-1.html
  18337. var v_prev_x = inPt.x - inPrev.x,
  18338. v_prev_y = inPt.y - inPrev.y;
  18339. var v_next_x = inNext.x - inPt.x,
  18340. v_next_y = inNext.y - inPt.y;
  18341. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18342. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18343. if (Math.abs(collinear0) > Number.EPSILON) {
  18344. // not collinear
  18345. // length of vectors for normalizing
  18346. var v_prev_len = Math.sqrt(v_prev_lensq);
  18347. 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
  18348. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18349. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18350. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18351. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18352. 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
  18353. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18354. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18355. // but prevent crazy spikes
  18356. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18357. if (v_trans_lensq <= 2) {
  18358. return new Vector2(v_trans_x, v_trans_y);
  18359. } else {
  18360. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18361. }
  18362. } else {
  18363. // handle special case of collinear edges
  18364. var direction_eq = false; // assumes: opposite
  18365. if (v_prev_x > Number.EPSILON) {
  18366. if (v_next_x > Number.EPSILON) {
  18367. direction_eq = true;
  18368. }
  18369. } else {
  18370. if (v_prev_x < -Number.EPSILON) {
  18371. if (v_next_x < -Number.EPSILON) {
  18372. direction_eq = true;
  18373. }
  18374. } else {
  18375. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18376. direction_eq = true;
  18377. }
  18378. }
  18379. }
  18380. if (direction_eq) {
  18381. // console.log("Warning: lines are a straight sequence");
  18382. v_trans_x = -v_prev_y;
  18383. v_trans_y = v_prev_x;
  18384. shrink_by = Math.sqrt(v_prev_lensq);
  18385. } else {
  18386. // console.log("Warning: lines are a straight spike");
  18387. v_trans_x = v_prev_x;
  18388. v_trans_y = v_prev_y;
  18389. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18390. }
  18391. }
  18392. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18393. }
  18394. var contourMovements = [];
  18395. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18396. if (j === il) j = 0;
  18397. if (k === il) k = 0; // (j)---(i)---(k)
  18398. // console.log('i,j,k', i, j , k)
  18399. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18400. }
  18401. var holesMovements = [];
  18402. var oneHoleMovements,
  18403. verticesMovements = contourMovements.concat();
  18404. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18405. var _ahole2 = holes[_h2];
  18406. oneHoleMovements = [];
  18407. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18408. if (_j === _il) _j = 0;
  18409. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18410. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18411. }
  18412. holesMovements.push(oneHoleMovements);
  18413. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18414. } // Loop bevelSegments, 1 for the front, 1 for the back
  18415. for (var b = 0; b < bevelSegments; b++) {
  18416. //for ( b = bevelSegments; b > 0; b -- ) {
  18417. var t = b / bevelSegments;
  18418. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18419. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18420. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18421. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18422. v(vert.x, vert.y, -z);
  18423. } // expand holes
  18424. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18425. var _ahole3 = holes[_h3];
  18426. oneHoleMovements = holesMovements[_h3];
  18427. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18428. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18429. v(_vert.x, _vert.y, -z);
  18430. }
  18431. }
  18432. }
  18433. var bs = bevelSize + bevelOffset; // Back facing vertices
  18434. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18435. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18436. if (!extrudeByPath) {
  18437. v(_vert2.x, _vert2.y, 0);
  18438. } else {
  18439. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18440. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18441. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18442. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18443. v(position2.x, position2.y, position2.z);
  18444. }
  18445. } // Add stepped vertices...
  18446. // Including front facing vertices
  18447. for (var s = 1; s <= steps; s++) {
  18448. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18449. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18450. if (!extrudeByPath) {
  18451. v(_vert3.x, _vert3.y, depth / steps * s);
  18452. } else {
  18453. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18454. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18455. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18456. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18457. v(position2.x, position2.y, position2.z);
  18458. }
  18459. }
  18460. } // Add bevel segments planes
  18461. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18462. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18463. var _t = _b / bevelSegments;
  18464. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18465. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18466. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18467. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18468. v(_vert4.x, _vert4.y, depth + _z);
  18469. } // expand holes
  18470. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18471. var _ahole4 = holes[_h4];
  18472. oneHoleMovements = holesMovements[_h4];
  18473. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18474. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18475. if (!extrudeByPath) {
  18476. v(_vert5.x, _vert5.y, depth + _z);
  18477. } else {
  18478. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18479. }
  18480. }
  18481. }
  18482. }
  18483. /* Faces */
  18484. // Top and bottom faces
  18485. buildLidFaces(); // Sides faces
  18486. buildSideFaces(); ///// Internal functions
  18487. function buildLidFaces() {
  18488. var start = verticesArray.length / 3;
  18489. if (bevelEnabled) {
  18490. var layer = 0; // steps + 1
  18491. var offset = vlen * layer; // Bottom faces
  18492. for (var _i9 = 0; _i9 < flen; _i9++) {
  18493. var face = faces[_i9];
  18494. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18495. }
  18496. layer = steps + bevelSegments * 2;
  18497. offset = vlen * layer; // Top faces
  18498. for (var _i10 = 0; _i10 < flen; _i10++) {
  18499. var _face = faces[_i10];
  18500. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18501. }
  18502. } else {
  18503. // Bottom faces
  18504. for (var _i11 = 0; _i11 < flen; _i11++) {
  18505. var _face2 = faces[_i11];
  18506. f3(_face2[2], _face2[1], _face2[0]);
  18507. } // Top faces
  18508. for (var _i12 = 0; _i12 < flen; _i12++) {
  18509. var _face3 = faces[_i12];
  18510. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18511. }
  18512. }
  18513. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18514. } // Create faces for the z-sides of the shape
  18515. function buildSideFaces() {
  18516. var start = verticesArray.length / 3;
  18517. var layeroffset = 0;
  18518. sidewalls(contour, layeroffset);
  18519. layeroffset += contour.length;
  18520. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18521. var _ahole5 = holes[_h5];
  18522. sidewalls(_ahole5, layeroffset); //, true
  18523. layeroffset += _ahole5.length;
  18524. }
  18525. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18526. }
  18527. function sidewalls(contour, layeroffset) {
  18528. var i = contour.length;
  18529. while (--i >= 0) {
  18530. var _j2 = i;
  18531. var _k2 = i - 1;
  18532. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18533. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18534. var slen1 = vlen * _s;
  18535. var slen2 = vlen * (_s + 1);
  18536. var a = layeroffset + _j2 + slen1,
  18537. _b2 = layeroffset + _k2 + slen1,
  18538. c = layeroffset + _k2 + slen2,
  18539. d = layeroffset + _j2 + slen2;
  18540. f4(a, _b2, c, d);
  18541. }
  18542. }
  18543. }
  18544. function v(x, y, z) {
  18545. placeholder.push(x);
  18546. placeholder.push(y);
  18547. placeholder.push(z);
  18548. }
  18549. function f3(a, b, c) {
  18550. addVertex(a);
  18551. addVertex(b);
  18552. addVertex(c);
  18553. var nextIndex = verticesArray.length / 3;
  18554. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18555. addUV(uvs[0]);
  18556. addUV(uvs[1]);
  18557. addUV(uvs[2]);
  18558. }
  18559. function f4(a, b, c, d) {
  18560. addVertex(a);
  18561. addVertex(b);
  18562. addVertex(d);
  18563. addVertex(b);
  18564. addVertex(c);
  18565. addVertex(d);
  18566. var nextIndex = verticesArray.length / 3;
  18567. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18568. addUV(uvs[0]);
  18569. addUV(uvs[1]);
  18570. addUV(uvs[3]);
  18571. addUV(uvs[1]);
  18572. addUV(uvs[2]);
  18573. addUV(uvs[3]);
  18574. }
  18575. function addVertex(index) {
  18576. verticesArray.push(placeholder[index * 3 + 0]);
  18577. verticesArray.push(placeholder[index * 3 + 1]);
  18578. verticesArray.push(placeholder[index * 3 + 2]);
  18579. }
  18580. function addUV(vector2) {
  18581. uvArray.push(vector2.x);
  18582. uvArray.push(vector2.y);
  18583. }
  18584. }
  18585. return _this;
  18586. }
  18587. var _proto = ExtrudeGeometry.prototype;
  18588. _proto.toJSON = function toJSON() {
  18589. var data = BufferGeometry.prototype.toJSON.call(this);
  18590. var shapes = this.parameters.shapes;
  18591. var options = this.parameters.options;
  18592. return _toJSON(shapes, options, data);
  18593. };
  18594. return ExtrudeGeometry;
  18595. }(BufferGeometry);
  18596. var WorldUVGenerator = {
  18597. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18598. var a_x = vertices[indexA * 3];
  18599. var a_y = vertices[indexA * 3 + 1];
  18600. var b_x = vertices[indexB * 3];
  18601. var b_y = vertices[indexB * 3 + 1];
  18602. var c_x = vertices[indexC * 3];
  18603. var c_y = vertices[indexC * 3 + 1];
  18604. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18605. },
  18606. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18607. var a_x = vertices[indexA * 3];
  18608. var a_y = vertices[indexA * 3 + 1];
  18609. var a_z = vertices[indexA * 3 + 2];
  18610. var b_x = vertices[indexB * 3];
  18611. var b_y = vertices[indexB * 3 + 1];
  18612. var b_z = vertices[indexB * 3 + 2];
  18613. var c_x = vertices[indexC * 3];
  18614. var c_y = vertices[indexC * 3 + 1];
  18615. var c_z = vertices[indexC * 3 + 2];
  18616. var d_x = vertices[indexD * 3];
  18617. var d_y = vertices[indexD * 3 + 1];
  18618. var d_z = vertices[indexD * 3 + 2];
  18619. if (Math.abs(a_y - b_y) < 0.01) {
  18620. 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)];
  18621. } else {
  18622. 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)];
  18623. }
  18624. }
  18625. };
  18626. function _toJSON(shapes, options, data) {
  18627. data.shapes = [];
  18628. if (Array.isArray(shapes)) {
  18629. for (var i = 0, l = shapes.length; i < l; i++) {
  18630. var shape = shapes[i];
  18631. data.shapes.push(shape.uuid);
  18632. }
  18633. } else {
  18634. data.shapes.push(shapes.uuid);
  18635. }
  18636. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18637. return data;
  18638. }
  18639. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18640. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18641. function IcosahedronGeometry(radius, detail) {
  18642. var _this;
  18643. if (radius === void 0) {
  18644. radius = 1;
  18645. }
  18646. if (detail === void 0) {
  18647. detail = 0;
  18648. }
  18649. var t = (1 + Math.sqrt(5)) / 2;
  18650. 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];
  18651. 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];
  18652. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18653. _this.type = 'IcosahedronGeometry';
  18654. _this.parameters = {
  18655. radius: radius,
  18656. detail: detail
  18657. };
  18658. return _this;
  18659. }
  18660. return IcosahedronGeometry;
  18661. }(PolyhedronGeometry);
  18662. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18663. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18664. function LatheGeometry(points, segments, phiStart, phiLength) {
  18665. var _this;
  18666. if (segments === void 0) {
  18667. segments = 12;
  18668. }
  18669. if (phiStart === void 0) {
  18670. phiStart = 0;
  18671. }
  18672. if (phiLength === void 0) {
  18673. phiLength = Math.PI * 2;
  18674. }
  18675. _this = _BufferGeometry.call(this) || this;
  18676. _this.type = 'LatheGeometry';
  18677. _this.parameters = {
  18678. points: points,
  18679. segments: segments,
  18680. phiStart: phiStart,
  18681. phiLength: phiLength
  18682. };
  18683. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18684. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18685. var indices = [];
  18686. var vertices = [];
  18687. var uvs = []; // helper variables
  18688. var inverseSegments = 1.0 / segments;
  18689. var vertex = new Vector3();
  18690. var uv = new Vector2(); // generate vertices and uvs
  18691. for (var i = 0; i <= segments; i++) {
  18692. var phi = phiStart + i * inverseSegments * phiLength;
  18693. var sin = Math.sin(phi);
  18694. var cos = Math.cos(phi);
  18695. for (var j = 0; j <= points.length - 1; j++) {
  18696. // vertex
  18697. vertex.x = points[j].x * sin;
  18698. vertex.y = points[j].y;
  18699. vertex.z = points[j].x * cos;
  18700. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18701. uv.x = i / segments;
  18702. uv.y = j / (points.length - 1);
  18703. uvs.push(uv.x, uv.y);
  18704. }
  18705. } // indices
  18706. for (var _i = 0; _i < segments; _i++) {
  18707. for (var _j = 0; _j < points.length - 1; _j++) {
  18708. var base = _j + _i * points.length;
  18709. var a = base;
  18710. var b = base + points.length;
  18711. var c = base + points.length + 1;
  18712. var d = base + 1; // faces
  18713. indices.push(a, b, d);
  18714. indices.push(b, c, d);
  18715. }
  18716. } // build geometry
  18717. _this.setIndex(indices);
  18718. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18719. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18720. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18721. // because the corresponding vertices are identical (but still have different UVs).
  18722. if (phiLength === Math.PI * 2) {
  18723. var normals = _this.attributes.normal.array;
  18724. var n1 = new Vector3();
  18725. var n2 = new Vector3();
  18726. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18727. var _base = segments * points.length * 3;
  18728. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18729. // select the normal of the vertex in the first line
  18730. n1.x = normals[_j2 + 0];
  18731. n1.y = normals[_j2 + 1];
  18732. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18733. n2.x = normals[_base + _j2 + 0];
  18734. n2.y = normals[_base + _j2 + 1];
  18735. n2.z = normals[_base + _j2 + 2]; // average normals
  18736. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18737. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18738. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18739. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18740. }
  18741. }
  18742. return _this;
  18743. }
  18744. return LatheGeometry;
  18745. }(BufferGeometry);
  18746. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18747. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18748. function OctahedronGeometry(radius, detail) {
  18749. var _this;
  18750. if (radius === void 0) {
  18751. radius = 1;
  18752. }
  18753. if (detail === void 0) {
  18754. detail = 0;
  18755. }
  18756. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18757. 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];
  18758. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18759. _this.type = 'OctahedronGeometry';
  18760. _this.parameters = {
  18761. radius: radius,
  18762. detail: detail
  18763. };
  18764. return _this;
  18765. }
  18766. return OctahedronGeometry;
  18767. }(PolyhedronGeometry);
  18768. /**
  18769. * Parametric Surfaces Geometry
  18770. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18771. */
  18772. function ParametricGeometry(func, slices, stacks) {
  18773. BufferGeometry.call(this);
  18774. this.type = 'ParametricGeometry';
  18775. this.parameters = {
  18776. func: func,
  18777. slices: slices,
  18778. stacks: stacks
  18779. }; // buffers
  18780. var indices = [];
  18781. var vertices = [];
  18782. var normals = [];
  18783. var uvs = [];
  18784. var EPS = 0.00001;
  18785. var normal = new Vector3();
  18786. var p0 = new Vector3(),
  18787. p1 = new Vector3();
  18788. var pu = new Vector3(),
  18789. pv = new Vector3();
  18790. if (func.length < 3) {
  18791. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18792. } // generate vertices, normals and uvs
  18793. var sliceCount = slices + 1;
  18794. for (var i = 0; i <= stacks; i++) {
  18795. var v = i / stacks;
  18796. for (var j = 0; j <= slices; j++) {
  18797. var u = j / slices; // vertex
  18798. func(u, v, p0);
  18799. vertices.push(p0.x, p0.y, p0.z); // normal
  18800. // approximate tangent vectors via finite differences
  18801. if (u - EPS >= 0) {
  18802. func(u - EPS, v, p1);
  18803. pu.subVectors(p0, p1);
  18804. } else {
  18805. func(u + EPS, v, p1);
  18806. pu.subVectors(p1, p0);
  18807. }
  18808. if (v - EPS >= 0) {
  18809. func(u, v - EPS, p1);
  18810. pv.subVectors(p0, p1);
  18811. } else {
  18812. func(u, v + EPS, p1);
  18813. pv.subVectors(p1, p0);
  18814. } // cross product of tangent vectors returns surface normal
  18815. normal.crossVectors(pu, pv).normalize();
  18816. normals.push(normal.x, normal.y, normal.z); // uv
  18817. uvs.push(u, v);
  18818. }
  18819. } // generate indices
  18820. for (var _i = 0; _i < stacks; _i++) {
  18821. for (var _j = 0; _j < slices; _j++) {
  18822. var a = _i * sliceCount + _j;
  18823. var b = _i * sliceCount + _j + 1;
  18824. var c = (_i + 1) * sliceCount + _j + 1;
  18825. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18826. indices.push(a, b, d);
  18827. indices.push(b, c, d);
  18828. }
  18829. } // build geometry
  18830. this.setIndex(indices);
  18831. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18832. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18833. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18834. }
  18835. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18836. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18837. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18838. _inheritsLoose(RingGeometry, _BufferGeometry);
  18839. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18840. var _this;
  18841. if (innerRadius === void 0) {
  18842. innerRadius = 0.5;
  18843. }
  18844. if (outerRadius === void 0) {
  18845. outerRadius = 1;
  18846. }
  18847. if (thetaSegments === void 0) {
  18848. thetaSegments = 8;
  18849. }
  18850. if (phiSegments === void 0) {
  18851. phiSegments = 1;
  18852. }
  18853. if (thetaStart === void 0) {
  18854. thetaStart = 0;
  18855. }
  18856. if (thetaLength === void 0) {
  18857. thetaLength = Math.PI * 2;
  18858. }
  18859. _this = _BufferGeometry.call(this) || this;
  18860. _this.type = 'RingGeometry';
  18861. _this.parameters = {
  18862. innerRadius: innerRadius,
  18863. outerRadius: outerRadius,
  18864. thetaSegments: thetaSegments,
  18865. phiSegments: phiSegments,
  18866. thetaStart: thetaStart,
  18867. thetaLength: thetaLength
  18868. };
  18869. thetaSegments = Math.max(3, thetaSegments);
  18870. phiSegments = Math.max(1, phiSegments); // buffers
  18871. var indices = [];
  18872. var vertices = [];
  18873. var normals = [];
  18874. var uvs = []; // some helper variables
  18875. var radius = innerRadius;
  18876. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18877. var vertex = new Vector3();
  18878. var uv = new Vector2(); // generate vertices, normals and uvs
  18879. for (var j = 0; j <= phiSegments; j++) {
  18880. for (var i = 0; i <= thetaSegments; i++) {
  18881. // values are generate from the inside of the ring to the outside
  18882. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18883. vertex.x = radius * Math.cos(segment);
  18884. vertex.y = radius * Math.sin(segment);
  18885. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18886. normals.push(0, 0, 1); // uv
  18887. uv.x = (vertex.x / outerRadius + 1) / 2;
  18888. uv.y = (vertex.y / outerRadius + 1) / 2;
  18889. uvs.push(uv.x, uv.y);
  18890. } // increase the radius for next row of vertices
  18891. radius += radiusStep;
  18892. } // indices
  18893. for (var _j = 0; _j < phiSegments; _j++) {
  18894. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18895. for (var _i = 0; _i < thetaSegments; _i++) {
  18896. var _segment = _i + thetaSegmentLevel;
  18897. var a = _segment;
  18898. var b = _segment + thetaSegments + 1;
  18899. var c = _segment + thetaSegments + 2;
  18900. var d = _segment + 1; // faces
  18901. indices.push(a, b, d);
  18902. indices.push(b, c, d);
  18903. }
  18904. } // build geometry
  18905. _this.setIndex(indices);
  18906. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18907. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18908. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18909. return _this;
  18910. }
  18911. return RingGeometry;
  18912. }(BufferGeometry);
  18913. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18914. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  18915. function ShapeGeometry(shapes, curveSegments) {
  18916. var _this;
  18917. if (curveSegments === void 0) {
  18918. curveSegments = 12;
  18919. }
  18920. _this = _BufferGeometry.call(this) || this;
  18921. _this.type = 'ShapeGeometry';
  18922. _this.parameters = {
  18923. shapes: shapes,
  18924. curveSegments: curveSegments
  18925. }; // buffers
  18926. var indices = [];
  18927. var vertices = [];
  18928. var normals = [];
  18929. var uvs = []; // helper variables
  18930. var groupStart = 0;
  18931. var groupCount = 0; // allow single and array values for "shapes" parameter
  18932. if (Array.isArray(shapes) === false) {
  18933. addShape(shapes);
  18934. } else {
  18935. for (var i = 0; i < shapes.length; i++) {
  18936. addShape(shapes[i]);
  18937. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18938. groupStart += groupCount;
  18939. groupCount = 0;
  18940. }
  18941. } // build geometry
  18942. _this.setIndex(indices);
  18943. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18944. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18945. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  18946. function addShape(shape) {
  18947. var indexOffset = vertices.length / 3;
  18948. var points = shape.extractPoints(curveSegments);
  18949. var shapeVertices = points.shape;
  18950. var shapeHoles = points.holes; // check direction of vertices
  18951. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  18952. shapeVertices = shapeVertices.reverse();
  18953. }
  18954. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  18955. var shapeHole = shapeHoles[_i];
  18956. if (ShapeUtils.isClockWise(shapeHole) === true) {
  18957. shapeHoles[_i] = shapeHole.reverse();
  18958. }
  18959. }
  18960. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  18961. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  18962. var _shapeHole = shapeHoles[_i2];
  18963. shapeVertices = shapeVertices.concat(_shapeHole);
  18964. } // vertices, normals, uvs
  18965. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  18966. var vertex = shapeVertices[_i3];
  18967. vertices.push(vertex.x, vertex.y, 0);
  18968. normals.push(0, 0, 1);
  18969. uvs.push(vertex.x, vertex.y); // world uvs
  18970. } // incides
  18971. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  18972. var face = faces[_i4];
  18973. var a = face[0] + indexOffset;
  18974. var b = face[1] + indexOffset;
  18975. var c = face[2] + indexOffset;
  18976. indices.push(a, b, c);
  18977. groupCount += 3;
  18978. }
  18979. }
  18980. return _this;
  18981. }
  18982. var _proto = ShapeGeometry.prototype;
  18983. _proto.toJSON = function toJSON() {
  18984. var data = BufferGeometry.prototype.toJSON.call(this);
  18985. var shapes = this.parameters.shapes;
  18986. return _toJSON$1(shapes, data);
  18987. };
  18988. return ShapeGeometry;
  18989. }(BufferGeometry);
  18990. function _toJSON$1(shapes, data) {
  18991. data.shapes = [];
  18992. if (Array.isArray(shapes)) {
  18993. for (var i = 0, l = shapes.length; i < l; i++) {
  18994. var shape = shapes[i];
  18995. data.shapes.push(shape.uuid);
  18996. }
  18997. } else {
  18998. data.shapes.push(shapes.uuid);
  18999. }
  19000. return data;
  19001. }
  19002. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19003. _inheritsLoose(SphereGeometry, _BufferGeometry);
  19004. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  19005. var _this;
  19006. if (radius === void 0) {
  19007. radius = 1;
  19008. }
  19009. if (widthSegments === void 0) {
  19010. widthSegments = 8;
  19011. }
  19012. if (heightSegments === void 0) {
  19013. heightSegments = 6;
  19014. }
  19015. if (phiStart === void 0) {
  19016. phiStart = 0;
  19017. }
  19018. if (phiLength === void 0) {
  19019. phiLength = Math.PI * 2;
  19020. }
  19021. if (thetaStart === void 0) {
  19022. thetaStart = 0;
  19023. }
  19024. if (thetaLength === void 0) {
  19025. thetaLength = Math.PI;
  19026. }
  19027. _this = _BufferGeometry.call(this) || this;
  19028. _this.type = 'SphereGeometry';
  19029. _this.parameters = {
  19030. radius: radius,
  19031. widthSegments: widthSegments,
  19032. heightSegments: heightSegments,
  19033. phiStart: phiStart,
  19034. phiLength: phiLength,
  19035. thetaStart: thetaStart,
  19036. thetaLength: thetaLength
  19037. };
  19038. widthSegments = Math.max(3, Math.floor(widthSegments));
  19039. heightSegments = Math.max(2, Math.floor(heightSegments));
  19040. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19041. var index = 0;
  19042. var grid = [];
  19043. var vertex = new Vector3();
  19044. var normal = new Vector3(); // buffers
  19045. var indices = [];
  19046. var vertices = [];
  19047. var normals = [];
  19048. var uvs = []; // generate vertices, normals and uvs
  19049. for (var iy = 0; iy <= heightSegments; iy++) {
  19050. var verticesRow = [];
  19051. var v = iy / heightSegments; // special case for the poles
  19052. var uOffset = 0;
  19053. if (iy == 0 && thetaStart == 0) {
  19054. uOffset = 0.5 / widthSegments;
  19055. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19056. uOffset = -0.5 / widthSegments;
  19057. }
  19058. for (var ix = 0; ix <= widthSegments; ix++) {
  19059. var u = ix / widthSegments; // vertex
  19060. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19061. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19062. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19063. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19064. normal.copy(vertex).normalize();
  19065. normals.push(normal.x, normal.y, normal.z); // uv
  19066. uvs.push(u + uOffset, 1 - v);
  19067. verticesRow.push(index++);
  19068. }
  19069. grid.push(verticesRow);
  19070. } // indices
  19071. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19072. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19073. var a = grid[_iy][_ix + 1];
  19074. var b = grid[_iy][_ix];
  19075. var c = grid[_iy + 1][_ix];
  19076. var d = grid[_iy + 1][_ix + 1];
  19077. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19078. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19079. }
  19080. } // build geometry
  19081. _this.setIndex(indices);
  19082. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19083. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19084. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19085. return _this;
  19086. }
  19087. return SphereGeometry;
  19088. }(BufferGeometry);
  19089. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  19090. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  19091. function TetrahedronGeometry(radius, detail) {
  19092. var _this;
  19093. if (radius === void 0) {
  19094. radius = 1;
  19095. }
  19096. if (detail === void 0) {
  19097. detail = 0;
  19098. }
  19099. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19100. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19101. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  19102. _this.type = 'TetrahedronGeometry';
  19103. _this.parameters = {
  19104. radius: radius,
  19105. detail: detail
  19106. };
  19107. return _this;
  19108. }
  19109. return TetrahedronGeometry;
  19110. }(PolyhedronGeometry);
  19111. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  19112. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  19113. function TextGeometry(text, parameters) {
  19114. var _this;
  19115. if (parameters === void 0) {
  19116. parameters = {};
  19117. }
  19118. var font = parameters.font;
  19119. if (!(font && font.isFont)) {
  19120. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19121. return new BufferGeometry() || _assertThisInitialized(_this);
  19122. }
  19123. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19124. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19125. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19126. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19127. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19128. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  19129. _this.type = 'TextGeometry';
  19130. return _this;
  19131. }
  19132. return TextGeometry;
  19133. }(ExtrudeGeometry);
  19134. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19135. _inheritsLoose(TorusGeometry, _BufferGeometry);
  19136. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19137. var _this;
  19138. if (radius === void 0) {
  19139. radius = 1;
  19140. }
  19141. if (tube === void 0) {
  19142. tube = 0.4;
  19143. }
  19144. if (radialSegments === void 0) {
  19145. radialSegments = 8;
  19146. }
  19147. if (tubularSegments === void 0) {
  19148. tubularSegments = 6;
  19149. }
  19150. if (arc === void 0) {
  19151. arc = Math.PI * 2;
  19152. }
  19153. _this = _BufferGeometry.call(this) || this;
  19154. _this.type = 'TorusGeometry';
  19155. _this.parameters = {
  19156. radius: radius,
  19157. tube: tube,
  19158. radialSegments: radialSegments,
  19159. tubularSegments: tubularSegments,
  19160. arc: arc
  19161. };
  19162. radialSegments = Math.floor(radialSegments);
  19163. tubularSegments = Math.floor(tubularSegments); // buffers
  19164. var indices = [];
  19165. var vertices = [];
  19166. var normals = [];
  19167. var uvs = []; // helper variables
  19168. var center = new Vector3();
  19169. var vertex = new Vector3();
  19170. var normal = new Vector3(); // generate vertices, normals and uvs
  19171. for (var j = 0; j <= radialSegments; j++) {
  19172. for (var i = 0; i <= tubularSegments; i++) {
  19173. var u = i / tubularSegments * arc;
  19174. var v = j / radialSegments * Math.PI * 2; // vertex
  19175. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19176. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19177. vertex.z = tube * Math.sin(v);
  19178. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19179. center.x = radius * Math.cos(u);
  19180. center.y = radius * Math.sin(u);
  19181. normal.subVectors(vertex, center).normalize();
  19182. normals.push(normal.x, normal.y, normal.z); // uv
  19183. uvs.push(i / tubularSegments);
  19184. uvs.push(j / radialSegments);
  19185. }
  19186. } // generate indices
  19187. for (var _j = 1; _j <= radialSegments; _j++) {
  19188. for (var _i = 1; _i <= tubularSegments; _i++) {
  19189. // indices
  19190. var a = (tubularSegments + 1) * _j + _i - 1;
  19191. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19192. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19193. var d = (tubularSegments + 1) * _j + _i; // faces
  19194. indices.push(a, b, d);
  19195. indices.push(b, c, d);
  19196. }
  19197. } // build geometry
  19198. _this.setIndex(indices);
  19199. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19200. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19201. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19202. return _this;
  19203. }
  19204. return TorusGeometry;
  19205. }(BufferGeometry);
  19206. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19207. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  19208. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19209. var _this;
  19210. if (radius === void 0) {
  19211. radius = 1;
  19212. }
  19213. if (tube === void 0) {
  19214. tube = 0.4;
  19215. }
  19216. if (tubularSegments === void 0) {
  19217. tubularSegments = 64;
  19218. }
  19219. if (radialSegments === void 0) {
  19220. radialSegments = 8;
  19221. }
  19222. if (p === void 0) {
  19223. p = 2;
  19224. }
  19225. if (q === void 0) {
  19226. q = 3;
  19227. }
  19228. _this = _BufferGeometry.call(this) || this;
  19229. _this.type = 'TorusKnotGeometry';
  19230. _this.parameters = {
  19231. radius: radius,
  19232. tube: tube,
  19233. tubularSegments: tubularSegments,
  19234. radialSegments: radialSegments,
  19235. p: p,
  19236. q: q
  19237. };
  19238. tubularSegments = Math.floor(tubularSegments);
  19239. radialSegments = Math.floor(radialSegments); // buffers
  19240. var indices = [];
  19241. var vertices = [];
  19242. var normals = [];
  19243. var uvs = []; // helper variables
  19244. var vertex = new Vector3();
  19245. var normal = new Vector3();
  19246. var P1 = new Vector3();
  19247. var P2 = new Vector3();
  19248. var B = new Vector3();
  19249. var T = new Vector3();
  19250. var N = new Vector3(); // generate vertices, normals and uvs
  19251. for (var i = 0; i <= tubularSegments; ++i) {
  19252. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19253. 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.
  19254. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19255. calculatePositionOnCurve(u, p, q, radius, P1);
  19256. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19257. T.subVectors(P2, P1);
  19258. N.addVectors(P2, P1);
  19259. B.crossVectors(T, N);
  19260. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19261. B.normalize();
  19262. N.normalize();
  19263. for (var j = 0; j <= radialSegments; ++j) {
  19264. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19265. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19266. var v = j / radialSegments * Math.PI * 2;
  19267. var cx = -tube * Math.cos(v);
  19268. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19269. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19270. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19271. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19272. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19273. 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)
  19274. normal.subVectors(vertex, P1).normalize();
  19275. normals.push(normal.x, normal.y, normal.z); // uv
  19276. uvs.push(i / tubularSegments);
  19277. uvs.push(j / radialSegments);
  19278. }
  19279. } // generate indices
  19280. for (var _j = 1; _j <= tubularSegments; _j++) {
  19281. for (var _i = 1; _i <= radialSegments; _i++) {
  19282. // indices
  19283. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19284. var b = (radialSegments + 1) * _j + (_i - 1);
  19285. var c = (radialSegments + 1) * _j + _i;
  19286. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19287. indices.push(a, b, d);
  19288. indices.push(b, c, d);
  19289. }
  19290. } // build geometry
  19291. _this.setIndex(indices);
  19292. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19293. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19294. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19295. function calculatePositionOnCurve(u, p, q, radius, position) {
  19296. var cu = Math.cos(u);
  19297. var su = Math.sin(u);
  19298. var quOverP = q / p * u;
  19299. var cs = Math.cos(quOverP);
  19300. position.x = radius * (2 + cs) * 0.5 * cu;
  19301. position.y = radius * (2 + cs) * su * 0.5;
  19302. position.z = radius * Math.sin(quOverP) * 0.5;
  19303. }
  19304. return _this;
  19305. }
  19306. return TorusKnotGeometry;
  19307. }(BufferGeometry);
  19308. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19309. _inheritsLoose(TubeGeometry, _BufferGeometry);
  19310. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19311. var _this;
  19312. if (tubularSegments === void 0) {
  19313. tubularSegments = 64;
  19314. }
  19315. if (radius === void 0) {
  19316. radius = 1;
  19317. }
  19318. if (radialSegments === void 0) {
  19319. radialSegments = 8;
  19320. }
  19321. if (closed === void 0) {
  19322. closed = false;
  19323. }
  19324. _this = _BufferGeometry.call(this) || this;
  19325. _this.type = 'TubeGeometry';
  19326. _this.parameters = {
  19327. path: path,
  19328. tubularSegments: tubularSegments,
  19329. radius: radius,
  19330. radialSegments: radialSegments,
  19331. closed: closed
  19332. };
  19333. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19334. _this.tangents = frames.tangents;
  19335. _this.normals = frames.normals;
  19336. _this.binormals = frames.binormals; // helper variables
  19337. var vertex = new Vector3();
  19338. var normal = new Vector3();
  19339. var uv = new Vector2();
  19340. var P = new Vector3(); // buffer
  19341. var vertices = [];
  19342. var normals = [];
  19343. var uvs = [];
  19344. var indices = []; // create buffer data
  19345. generateBufferData(); // build geometry
  19346. _this.setIndex(indices);
  19347. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19348. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19349. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19350. function generateBufferData() {
  19351. for (var i = 0; i < tubularSegments; i++) {
  19352. generateSegment(i);
  19353. } // if the geometry is not closed, generate the last row of vertices and normals
  19354. // at the regular position on the given path
  19355. //
  19356. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19357. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19358. // this makes it easy compute correct values for closed geometries
  19359. generateUVs(); // finally create faces
  19360. generateIndices();
  19361. }
  19362. function generateSegment(i) {
  19363. // we use getPointAt to sample evenly distributed points from the given path
  19364. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19365. var N = frames.normals[i];
  19366. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19367. for (var j = 0; j <= radialSegments; j++) {
  19368. var v = j / radialSegments * Math.PI * 2;
  19369. var sin = Math.sin(v);
  19370. var cos = -Math.cos(v); // normal
  19371. normal.x = cos * N.x + sin * B.x;
  19372. normal.y = cos * N.y + sin * B.y;
  19373. normal.z = cos * N.z + sin * B.z;
  19374. normal.normalize();
  19375. normals.push(normal.x, normal.y, normal.z); // vertex
  19376. vertex.x = P.x + radius * normal.x;
  19377. vertex.y = P.y + radius * normal.y;
  19378. vertex.z = P.z + radius * normal.z;
  19379. vertices.push(vertex.x, vertex.y, vertex.z);
  19380. }
  19381. }
  19382. function generateIndices() {
  19383. for (var j = 1; j <= tubularSegments; j++) {
  19384. for (var i = 1; i <= radialSegments; i++) {
  19385. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19386. var b = (radialSegments + 1) * j + (i - 1);
  19387. var c = (radialSegments + 1) * j + i;
  19388. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19389. indices.push(a, b, d);
  19390. indices.push(b, c, d);
  19391. }
  19392. }
  19393. }
  19394. function generateUVs() {
  19395. for (var i = 0; i <= tubularSegments; i++) {
  19396. for (var j = 0; j <= radialSegments; j++) {
  19397. uv.x = i / tubularSegments;
  19398. uv.y = j / radialSegments;
  19399. uvs.push(uv.x, uv.y);
  19400. }
  19401. }
  19402. }
  19403. return _this;
  19404. }
  19405. var _proto = TubeGeometry.prototype;
  19406. _proto.toJSON = function toJSON() {
  19407. var data = BufferGeometry.prototype.toJSON.call(this);
  19408. data.path = this.parameters.path.toJSON();
  19409. return data;
  19410. };
  19411. return TubeGeometry;
  19412. }(BufferGeometry);
  19413. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19414. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19415. function WireframeGeometry(geometry) {
  19416. var _this;
  19417. _this = _BufferGeometry.call(this) || this;
  19418. _this.type = 'WireframeGeometry';
  19419. if (geometry.isGeometry === true) {
  19420. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  19421. return _assertThisInitialized(_this);
  19422. } // buffer
  19423. var vertices = []; // helper variables
  19424. var edge = [0, 0],
  19425. edges = {};
  19426. var vertex = new Vector3();
  19427. if (geometry.index !== null) {
  19428. // indexed BufferGeometry
  19429. var position = geometry.attributes.position;
  19430. var indices = geometry.index;
  19431. var groups = geometry.groups;
  19432. if (groups.length === 0) {
  19433. groups = [{
  19434. start: 0,
  19435. count: indices.count,
  19436. materialIndex: 0
  19437. }];
  19438. } // create a data structure that contains all eges without duplicates
  19439. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19440. var group = groups[o];
  19441. var start = group.start;
  19442. var count = group.count;
  19443. for (var i = start, l = start + count; i < l; i += 3) {
  19444. for (var j = 0; j < 3; j++) {
  19445. var edge1 = indices.getX(i + j);
  19446. var edge2 = indices.getX(i + (j + 1) % 3);
  19447. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19448. edge[1] = Math.max(edge1, edge2);
  19449. var key = edge[0] + ',' + edge[1];
  19450. if (edges[key] === undefined) {
  19451. edges[key] = {
  19452. index1: edge[0],
  19453. index2: edge[1]
  19454. };
  19455. }
  19456. }
  19457. }
  19458. } // generate vertices
  19459. for (var _key in edges) {
  19460. var e = edges[_key];
  19461. vertex.fromBufferAttribute(position, e.index1);
  19462. vertices.push(vertex.x, vertex.y, vertex.z);
  19463. vertex.fromBufferAttribute(position, e.index2);
  19464. vertices.push(vertex.x, vertex.y, vertex.z);
  19465. }
  19466. } else {
  19467. // non-indexed BufferGeometry
  19468. var _position = geometry.attributes.position;
  19469. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  19470. for (var _j = 0; _j < 3; _j++) {
  19471. // three edges per triangle, an edge is represented as (index1, index2)
  19472. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19473. var index1 = 3 * _i + _j;
  19474. vertex.fromBufferAttribute(_position, index1);
  19475. vertices.push(vertex.x, vertex.y, vertex.z);
  19476. var index2 = 3 * _i + (_j + 1) % 3;
  19477. vertex.fromBufferAttribute(_position, index2);
  19478. vertices.push(vertex.x, vertex.y, vertex.z);
  19479. }
  19480. }
  19481. } // build geometry
  19482. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19483. return _this;
  19484. }
  19485. return WireframeGeometry;
  19486. }(BufferGeometry);
  19487. var Geometries = /*#__PURE__*/Object.freeze({
  19488. __proto__: null,
  19489. BoxGeometry: BoxGeometry,
  19490. BoxBufferGeometry: BoxGeometry,
  19491. CircleGeometry: CircleGeometry,
  19492. CircleBufferGeometry: CircleGeometry,
  19493. ConeGeometry: ConeGeometry,
  19494. ConeBufferGeometry: ConeGeometry,
  19495. CylinderGeometry: CylinderGeometry,
  19496. CylinderBufferGeometry: CylinderGeometry,
  19497. DodecahedronGeometry: DodecahedronGeometry,
  19498. DodecahedronBufferGeometry: DodecahedronGeometry,
  19499. EdgesGeometry: EdgesGeometry,
  19500. ExtrudeGeometry: ExtrudeGeometry,
  19501. ExtrudeBufferGeometry: ExtrudeGeometry,
  19502. IcosahedronGeometry: IcosahedronGeometry,
  19503. IcosahedronBufferGeometry: IcosahedronGeometry,
  19504. LatheGeometry: LatheGeometry,
  19505. LatheBufferGeometry: LatheGeometry,
  19506. OctahedronGeometry: OctahedronGeometry,
  19507. OctahedronBufferGeometry: OctahedronGeometry,
  19508. ParametricGeometry: ParametricGeometry,
  19509. ParametricBufferGeometry: ParametricGeometry,
  19510. PlaneGeometry: PlaneGeometry,
  19511. PlaneBufferGeometry: PlaneGeometry,
  19512. PolyhedronGeometry: PolyhedronGeometry,
  19513. PolyhedronBufferGeometry: PolyhedronGeometry,
  19514. RingGeometry: RingGeometry,
  19515. RingBufferGeometry: RingGeometry,
  19516. ShapeGeometry: ShapeGeometry,
  19517. ShapeBufferGeometry: ShapeGeometry,
  19518. SphereGeometry: SphereGeometry,
  19519. SphereBufferGeometry: SphereGeometry,
  19520. TetrahedronGeometry: TetrahedronGeometry,
  19521. TetrahedronBufferGeometry: TetrahedronGeometry,
  19522. TextGeometry: TextGeometry,
  19523. TextBufferGeometry: TextGeometry,
  19524. TorusGeometry: TorusGeometry,
  19525. TorusBufferGeometry: TorusGeometry,
  19526. TorusKnotGeometry: TorusKnotGeometry,
  19527. TorusKnotBufferGeometry: TorusKnotGeometry,
  19528. TubeGeometry: TubeGeometry,
  19529. TubeBufferGeometry: TubeGeometry,
  19530. WireframeGeometry: WireframeGeometry
  19531. });
  19532. /**
  19533. * parameters = {
  19534. * color: <THREE.Color>
  19535. * }
  19536. */
  19537. function ShadowMaterial(parameters) {
  19538. Material.call(this);
  19539. this.type = 'ShadowMaterial';
  19540. this.color = new Color(0x000000);
  19541. this.transparent = true;
  19542. this.setValues(parameters);
  19543. }
  19544. ShadowMaterial.prototype = Object.create(Material.prototype);
  19545. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19546. ShadowMaterial.prototype.isShadowMaterial = true;
  19547. ShadowMaterial.prototype.copy = function (source) {
  19548. Material.prototype.copy.call(this, source);
  19549. this.color.copy(source.color);
  19550. return this;
  19551. };
  19552. function RawShaderMaterial(parameters) {
  19553. ShaderMaterial.call(this, parameters);
  19554. this.type = 'RawShaderMaterial';
  19555. }
  19556. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19557. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19558. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19559. /**
  19560. * parameters = {
  19561. * color: <hex>,
  19562. * roughness: <float>,
  19563. * metalness: <float>,
  19564. * opacity: <float>,
  19565. *
  19566. * map: new THREE.Texture( <Image> ),
  19567. *
  19568. * lightMap: new THREE.Texture( <Image> ),
  19569. * lightMapIntensity: <float>
  19570. *
  19571. * aoMap: new THREE.Texture( <Image> ),
  19572. * aoMapIntensity: <float>
  19573. *
  19574. * emissive: <hex>,
  19575. * emissiveIntensity: <float>
  19576. * emissiveMap: new THREE.Texture( <Image> ),
  19577. *
  19578. * bumpMap: new THREE.Texture( <Image> ),
  19579. * bumpScale: <float>,
  19580. *
  19581. * normalMap: new THREE.Texture( <Image> ),
  19582. * normalMapType: THREE.TangentSpaceNormalMap,
  19583. * normalScale: <Vector2>,
  19584. *
  19585. * displacementMap: new THREE.Texture( <Image> ),
  19586. * displacementScale: <float>,
  19587. * displacementBias: <float>,
  19588. *
  19589. * roughnessMap: new THREE.Texture( <Image> ),
  19590. *
  19591. * metalnessMap: new THREE.Texture( <Image> ),
  19592. *
  19593. * alphaMap: new THREE.Texture( <Image> ),
  19594. *
  19595. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19596. * envMapIntensity: <float>
  19597. *
  19598. * refractionRatio: <float>,
  19599. *
  19600. * wireframe: <boolean>,
  19601. * wireframeLinewidth: <float>,
  19602. *
  19603. * skinning: <bool>,
  19604. * morphTargets: <bool>,
  19605. * morphNormals: <bool>,
  19606. *
  19607. * flatShading: <bool>
  19608. * }
  19609. */
  19610. function MeshStandardMaterial(parameters) {
  19611. Material.call(this);
  19612. this.defines = {
  19613. 'STANDARD': ''
  19614. };
  19615. this.type = 'MeshStandardMaterial';
  19616. this.color = new Color(0xffffff); // diffuse
  19617. this.roughness = 1.0;
  19618. this.metalness = 0.0;
  19619. this.map = null;
  19620. this.lightMap = null;
  19621. this.lightMapIntensity = 1.0;
  19622. this.aoMap = null;
  19623. this.aoMapIntensity = 1.0;
  19624. this.emissive = new Color(0x000000);
  19625. this.emissiveIntensity = 1.0;
  19626. this.emissiveMap = null;
  19627. this.bumpMap = null;
  19628. this.bumpScale = 1;
  19629. this.normalMap = null;
  19630. this.normalMapType = TangentSpaceNormalMap;
  19631. this.normalScale = new Vector2(1, 1);
  19632. this.displacementMap = null;
  19633. this.displacementScale = 1;
  19634. this.displacementBias = 0;
  19635. this.roughnessMap = null;
  19636. this.metalnessMap = null;
  19637. this.alphaMap = null;
  19638. this.envMap = null;
  19639. this.envMapIntensity = 1.0;
  19640. this.refractionRatio = 0.98;
  19641. this.wireframe = false;
  19642. this.wireframeLinewidth = 1;
  19643. this.wireframeLinecap = 'round';
  19644. this.wireframeLinejoin = 'round';
  19645. this.skinning = false;
  19646. this.morphTargets = false;
  19647. this.morphNormals = false;
  19648. this.flatShading = false;
  19649. this.vertexTangents = false;
  19650. this.setValues(parameters);
  19651. }
  19652. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19653. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19654. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19655. MeshStandardMaterial.prototype.copy = function (source) {
  19656. Material.prototype.copy.call(this, source);
  19657. this.defines = {
  19658. 'STANDARD': ''
  19659. };
  19660. this.color.copy(source.color);
  19661. this.roughness = source.roughness;
  19662. this.metalness = source.metalness;
  19663. this.map = source.map;
  19664. this.lightMap = source.lightMap;
  19665. this.lightMapIntensity = source.lightMapIntensity;
  19666. this.aoMap = source.aoMap;
  19667. this.aoMapIntensity = source.aoMapIntensity;
  19668. this.emissive.copy(source.emissive);
  19669. this.emissiveMap = source.emissiveMap;
  19670. this.emissiveIntensity = source.emissiveIntensity;
  19671. this.bumpMap = source.bumpMap;
  19672. this.bumpScale = source.bumpScale;
  19673. this.normalMap = source.normalMap;
  19674. this.normalMapType = source.normalMapType;
  19675. this.normalScale.copy(source.normalScale);
  19676. this.displacementMap = source.displacementMap;
  19677. this.displacementScale = source.displacementScale;
  19678. this.displacementBias = source.displacementBias;
  19679. this.roughnessMap = source.roughnessMap;
  19680. this.metalnessMap = source.metalnessMap;
  19681. this.alphaMap = source.alphaMap;
  19682. this.envMap = source.envMap;
  19683. this.envMapIntensity = source.envMapIntensity;
  19684. this.refractionRatio = source.refractionRatio;
  19685. this.wireframe = source.wireframe;
  19686. this.wireframeLinewidth = source.wireframeLinewidth;
  19687. this.wireframeLinecap = source.wireframeLinecap;
  19688. this.wireframeLinejoin = source.wireframeLinejoin;
  19689. this.skinning = source.skinning;
  19690. this.morphTargets = source.morphTargets;
  19691. this.morphNormals = source.morphNormals;
  19692. this.flatShading = source.flatShading;
  19693. this.vertexTangents = source.vertexTangents;
  19694. return this;
  19695. };
  19696. /**
  19697. * parameters = {
  19698. * clearcoat: <float>,
  19699. * clearcoatMap: new THREE.Texture( <Image> ),
  19700. * clearcoatRoughness: <float>,
  19701. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19702. * clearcoatNormalScale: <Vector2>,
  19703. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19704. *
  19705. * reflectivity: <float>,
  19706. * ior: <float>,
  19707. *
  19708. * sheen: <Color>,
  19709. *
  19710. * transmission: <float>,
  19711. * transmissionMap: new THREE.Texture( <Image> )
  19712. * }
  19713. */
  19714. function MeshPhysicalMaterial(parameters) {
  19715. MeshStandardMaterial.call(this);
  19716. this.defines = {
  19717. 'STANDARD': '',
  19718. 'PHYSICAL': ''
  19719. };
  19720. this.type = 'MeshPhysicalMaterial';
  19721. this.clearcoat = 0.0;
  19722. this.clearcoatMap = null;
  19723. this.clearcoatRoughness = 0.0;
  19724. this.clearcoatRoughnessMap = null;
  19725. this.clearcoatNormalScale = new Vector2(1, 1);
  19726. this.clearcoatNormalMap = null;
  19727. this.reflectivity = 0.5; // maps to F0 = 0.04
  19728. Object.defineProperty(this, 'ior', {
  19729. get: function get() {
  19730. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19731. },
  19732. set: function set(ior) {
  19733. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19734. }
  19735. });
  19736. this.sheen = null; // null will disable sheen bsdf
  19737. this.transmission = 0.0;
  19738. this.transmissionMap = null;
  19739. this.setValues(parameters);
  19740. }
  19741. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19742. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19743. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19744. MeshPhysicalMaterial.prototype.copy = function (source) {
  19745. MeshStandardMaterial.prototype.copy.call(this, source);
  19746. this.defines = {
  19747. 'STANDARD': '',
  19748. 'PHYSICAL': ''
  19749. };
  19750. this.clearcoat = source.clearcoat;
  19751. this.clearcoatMap = source.clearcoatMap;
  19752. this.clearcoatRoughness = source.clearcoatRoughness;
  19753. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19754. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19755. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19756. this.reflectivity = source.reflectivity;
  19757. if (source.sheen) {
  19758. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19759. } else {
  19760. this.sheen = null;
  19761. }
  19762. this.transmission = source.transmission;
  19763. this.transmissionMap = source.transmissionMap;
  19764. return this;
  19765. };
  19766. /**
  19767. * parameters = {
  19768. * color: <hex>,
  19769. * specular: <hex>,
  19770. * shininess: <float>,
  19771. * opacity: <float>,
  19772. *
  19773. * map: new THREE.Texture( <Image> ),
  19774. *
  19775. * lightMap: new THREE.Texture( <Image> ),
  19776. * lightMapIntensity: <float>
  19777. *
  19778. * aoMap: new THREE.Texture( <Image> ),
  19779. * aoMapIntensity: <float>
  19780. *
  19781. * emissive: <hex>,
  19782. * emissiveIntensity: <float>
  19783. * emissiveMap: new THREE.Texture( <Image> ),
  19784. *
  19785. * bumpMap: new THREE.Texture( <Image> ),
  19786. * bumpScale: <float>,
  19787. *
  19788. * normalMap: new THREE.Texture( <Image> ),
  19789. * normalMapType: THREE.TangentSpaceNormalMap,
  19790. * normalScale: <Vector2>,
  19791. *
  19792. * displacementMap: new THREE.Texture( <Image> ),
  19793. * displacementScale: <float>,
  19794. * displacementBias: <float>,
  19795. *
  19796. * specularMap: new THREE.Texture( <Image> ),
  19797. *
  19798. * alphaMap: new THREE.Texture( <Image> ),
  19799. *
  19800. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19801. * combine: THREE.MultiplyOperation,
  19802. * reflectivity: <float>,
  19803. * refractionRatio: <float>,
  19804. *
  19805. * wireframe: <boolean>,
  19806. * wireframeLinewidth: <float>,
  19807. *
  19808. * skinning: <bool>,
  19809. * morphTargets: <bool>,
  19810. * morphNormals: <bool>,
  19811. *
  19812. * flatShading: <bool>
  19813. * }
  19814. */
  19815. function MeshPhongMaterial(parameters) {
  19816. Material.call(this);
  19817. this.type = 'MeshPhongMaterial';
  19818. this.color = new Color(0xffffff); // diffuse
  19819. this.specular = new Color(0x111111);
  19820. this.shininess = 30;
  19821. this.map = null;
  19822. this.lightMap = null;
  19823. this.lightMapIntensity = 1.0;
  19824. this.aoMap = null;
  19825. this.aoMapIntensity = 1.0;
  19826. this.emissive = new Color(0x000000);
  19827. this.emissiveIntensity = 1.0;
  19828. this.emissiveMap = null;
  19829. this.bumpMap = null;
  19830. this.bumpScale = 1;
  19831. this.normalMap = null;
  19832. this.normalMapType = TangentSpaceNormalMap;
  19833. this.normalScale = new Vector2(1, 1);
  19834. this.displacementMap = null;
  19835. this.displacementScale = 1;
  19836. this.displacementBias = 0;
  19837. this.specularMap = null;
  19838. this.alphaMap = null;
  19839. this.envMap = null;
  19840. this.combine = MultiplyOperation;
  19841. this.reflectivity = 1;
  19842. this.refractionRatio = 0.98;
  19843. this.wireframe = false;
  19844. this.wireframeLinewidth = 1;
  19845. this.wireframeLinecap = 'round';
  19846. this.wireframeLinejoin = 'round';
  19847. this.skinning = false;
  19848. this.morphTargets = false;
  19849. this.morphNormals = false;
  19850. this.flatShading = false;
  19851. this.setValues(parameters);
  19852. }
  19853. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  19854. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19855. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19856. MeshPhongMaterial.prototype.copy = function (source) {
  19857. Material.prototype.copy.call(this, source);
  19858. this.color.copy(source.color);
  19859. this.specular.copy(source.specular);
  19860. this.shininess = source.shininess;
  19861. this.map = source.map;
  19862. this.lightMap = source.lightMap;
  19863. this.lightMapIntensity = source.lightMapIntensity;
  19864. this.aoMap = source.aoMap;
  19865. this.aoMapIntensity = source.aoMapIntensity;
  19866. this.emissive.copy(source.emissive);
  19867. this.emissiveMap = source.emissiveMap;
  19868. this.emissiveIntensity = source.emissiveIntensity;
  19869. this.bumpMap = source.bumpMap;
  19870. this.bumpScale = source.bumpScale;
  19871. this.normalMap = source.normalMap;
  19872. this.normalMapType = source.normalMapType;
  19873. this.normalScale.copy(source.normalScale);
  19874. this.displacementMap = source.displacementMap;
  19875. this.displacementScale = source.displacementScale;
  19876. this.displacementBias = source.displacementBias;
  19877. this.specularMap = source.specularMap;
  19878. this.alphaMap = source.alphaMap;
  19879. this.envMap = source.envMap;
  19880. this.combine = source.combine;
  19881. this.reflectivity = source.reflectivity;
  19882. this.refractionRatio = source.refractionRatio;
  19883. this.wireframe = source.wireframe;
  19884. this.wireframeLinewidth = source.wireframeLinewidth;
  19885. this.wireframeLinecap = source.wireframeLinecap;
  19886. this.wireframeLinejoin = source.wireframeLinejoin;
  19887. this.skinning = source.skinning;
  19888. this.morphTargets = source.morphTargets;
  19889. this.morphNormals = source.morphNormals;
  19890. this.flatShading = source.flatShading;
  19891. return this;
  19892. };
  19893. /**
  19894. * parameters = {
  19895. * color: <hex>,
  19896. *
  19897. * map: new THREE.Texture( <Image> ),
  19898. * gradientMap: new THREE.Texture( <Image> ),
  19899. *
  19900. * lightMap: new THREE.Texture( <Image> ),
  19901. * lightMapIntensity: <float>
  19902. *
  19903. * aoMap: new THREE.Texture( <Image> ),
  19904. * aoMapIntensity: <float>
  19905. *
  19906. * emissive: <hex>,
  19907. * emissiveIntensity: <float>
  19908. * emissiveMap: new THREE.Texture( <Image> ),
  19909. *
  19910. * bumpMap: new THREE.Texture( <Image> ),
  19911. * bumpScale: <float>,
  19912. *
  19913. * normalMap: new THREE.Texture( <Image> ),
  19914. * normalMapType: THREE.TangentSpaceNormalMap,
  19915. * normalScale: <Vector2>,
  19916. *
  19917. * displacementMap: new THREE.Texture( <Image> ),
  19918. * displacementScale: <float>,
  19919. * displacementBias: <float>,
  19920. *
  19921. * alphaMap: new THREE.Texture( <Image> ),
  19922. *
  19923. * wireframe: <boolean>,
  19924. * wireframeLinewidth: <float>,
  19925. *
  19926. * skinning: <bool>,
  19927. * morphTargets: <bool>,
  19928. * morphNormals: <bool>
  19929. * }
  19930. */
  19931. function MeshToonMaterial(parameters) {
  19932. Material.call(this);
  19933. this.defines = {
  19934. 'TOON': ''
  19935. };
  19936. this.type = 'MeshToonMaterial';
  19937. this.color = new Color(0xffffff);
  19938. this.map = null;
  19939. this.gradientMap = null;
  19940. this.lightMap = null;
  19941. this.lightMapIntensity = 1.0;
  19942. this.aoMap = null;
  19943. this.aoMapIntensity = 1.0;
  19944. this.emissive = new Color(0x000000);
  19945. this.emissiveIntensity = 1.0;
  19946. this.emissiveMap = null;
  19947. this.bumpMap = null;
  19948. this.bumpScale = 1;
  19949. this.normalMap = null;
  19950. this.normalMapType = TangentSpaceNormalMap;
  19951. this.normalScale = new Vector2(1, 1);
  19952. this.displacementMap = null;
  19953. this.displacementScale = 1;
  19954. this.displacementBias = 0;
  19955. this.alphaMap = null;
  19956. this.wireframe = false;
  19957. this.wireframeLinewidth = 1;
  19958. this.wireframeLinecap = 'round';
  19959. this.wireframeLinejoin = 'round';
  19960. this.skinning = false;
  19961. this.morphTargets = false;
  19962. this.morphNormals = false;
  19963. this.setValues(parameters);
  19964. }
  19965. MeshToonMaterial.prototype = Object.create(Material.prototype);
  19966. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19967. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19968. MeshToonMaterial.prototype.copy = function (source) {
  19969. Material.prototype.copy.call(this, source);
  19970. this.color.copy(source.color);
  19971. this.map = source.map;
  19972. this.gradientMap = source.gradientMap;
  19973. this.lightMap = source.lightMap;
  19974. this.lightMapIntensity = source.lightMapIntensity;
  19975. this.aoMap = source.aoMap;
  19976. this.aoMapIntensity = source.aoMapIntensity;
  19977. this.emissive.copy(source.emissive);
  19978. this.emissiveMap = source.emissiveMap;
  19979. this.emissiveIntensity = source.emissiveIntensity;
  19980. this.bumpMap = source.bumpMap;
  19981. this.bumpScale = source.bumpScale;
  19982. this.normalMap = source.normalMap;
  19983. this.normalMapType = source.normalMapType;
  19984. this.normalScale.copy(source.normalScale);
  19985. this.displacementMap = source.displacementMap;
  19986. this.displacementScale = source.displacementScale;
  19987. this.displacementBias = source.displacementBias;
  19988. this.alphaMap = source.alphaMap;
  19989. this.wireframe = source.wireframe;
  19990. this.wireframeLinewidth = source.wireframeLinewidth;
  19991. this.wireframeLinecap = source.wireframeLinecap;
  19992. this.wireframeLinejoin = source.wireframeLinejoin;
  19993. this.skinning = source.skinning;
  19994. this.morphTargets = source.morphTargets;
  19995. this.morphNormals = source.morphNormals;
  19996. return this;
  19997. };
  19998. /**
  19999. * parameters = {
  20000. * opacity: <float>,
  20001. *
  20002. * bumpMap: new THREE.Texture( <Image> ),
  20003. * bumpScale: <float>,
  20004. *
  20005. * normalMap: new THREE.Texture( <Image> ),
  20006. * normalMapType: THREE.TangentSpaceNormalMap,
  20007. * normalScale: <Vector2>,
  20008. *
  20009. * displacementMap: new THREE.Texture( <Image> ),
  20010. * displacementScale: <float>,
  20011. * displacementBias: <float>,
  20012. *
  20013. * wireframe: <boolean>,
  20014. * wireframeLinewidth: <float>
  20015. *
  20016. * skinning: <bool>,
  20017. * morphTargets: <bool>,
  20018. * morphNormals: <bool>,
  20019. *
  20020. * flatShading: <bool>
  20021. * }
  20022. */
  20023. function MeshNormalMaterial(parameters) {
  20024. Material.call(this);
  20025. this.type = 'MeshNormalMaterial';
  20026. this.bumpMap = null;
  20027. this.bumpScale = 1;
  20028. this.normalMap = null;
  20029. this.normalMapType = TangentSpaceNormalMap;
  20030. this.normalScale = new Vector2(1, 1);
  20031. this.displacementMap = null;
  20032. this.displacementScale = 1;
  20033. this.displacementBias = 0;
  20034. this.wireframe = false;
  20035. this.wireframeLinewidth = 1;
  20036. this.fog = false;
  20037. this.skinning = false;
  20038. this.morphTargets = false;
  20039. this.morphNormals = false;
  20040. this.flatShading = false;
  20041. this.setValues(parameters);
  20042. }
  20043. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  20044. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20045. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20046. MeshNormalMaterial.prototype.copy = function (source) {
  20047. Material.prototype.copy.call(this, source);
  20048. this.bumpMap = source.bumpMap;
  20049. this.bumpScale = source.bumpScale;
  20050. this.normalMap = source.normalMap;
  20051. this.normalMapType = source.normalMapType;
  20052. this.normalScale.copy(source.normalScale);
  20053. this.displacementMap = source.displacementMap;
  20054. this.displacementScale = source.displacementScale;
  20055. this.displacementBias = source.displacementBias;
  20056. this.wireframe = source.wireframe;
  20057. this.wireframeLinewidth = source.wireframeLinewidth;
  20058. this.skinning = source.skinning;
  20059. this.morphTargets = source.morphTargets;
  20060. this.morphNormals = source.morphNormals;
  20061. this.flatShading = source.flatShading;
  20062. return this;
  20063. };
  20064. /**
  20065. * parameters = {
  20066. * color: <hex>,
  20067. * opacity: <float>,
  20068. *
  20069. * map: new THREE.Texture( <Image> ),
  20070. *
  20071. * lightMap: new THREE.Texture( <Image> ),
  20072. * lightMapIntensity: <float>
  20073. *
  20074. * aoMap: new THREE.Texture( <Image> ),
  20075. * aoMapIntensity: <float>
  20076. *
  20077. * emissive: <hex>,
  20078. * emissiveIntensity: <float>
  20079. * emissiveMap: new THREE.Texture( <Image> ),
  20080. *
  20081. * specularMap: new THREE.Texture( <Image> ),
  20082. *
  20083. * alphaMap: new THREE.Texture( <Image> ),
  20084. *
  20085. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20086. * combine: THREE.Multiply,
  20087. * reflectivity: <float>,
  20088. * refractionRatio: <float>,
  20089. *
  20090. * wireframe: <boolean>,
  20091. * wireframeLinewidth: <float>,
  20092. *
  20093. * skinning: <bool>,
  20094. * morphTargets: <bool>,
  20095. * morphNormals: <bool>
  20096. * }
  20097. */
  20098. function MeshLambertMaterial(parameters) {
  20099. Material.call(this);
  20100. this.type = 'MeshLambertMaterial';
  20101. this.color = new Color(0xffffff); // diffuse
  20102. this.map = null;
  20103. this.lightMap = null;
  20104. this.lightMapIntensity = 1.0;
  20105. this.aoMap = null;
  20106. this.aoMapIntensity = 1.0;
  20107. this.emissive = new Color(0x000000);
  20108. this.emissiveIntensity = 1.0;
  20109. this.emissiveMap = null;
  20110. this.specularMap = null;
  20111. this.alphaMap = null;
  20112. this.envMap = null;
  20113. this.combine = MultiplyOperation;
  20114. this.reflectivity = 1;
  20115. this.refractionRatio = 0.98;
  20116. this.wireframe = false;
  20117. this.wireframeLinewidth = 1;
  20118. this.wireframeLinecap = 'round';
  20119. this.wireframeLinejoin = 'round';
  20120. this.skinning = false;
  20121. this.morphTargets = false;
  20122. this.morphNormals = false;
  20123. this.setValues(parameters);
  20124. }
  20125. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20126. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20127. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20128. MeshLambertMaterial.prototype.copy = function (source) {
  20129. Material.prototype.copy.call(this, source);
  20130. this.color.copy(source.color);
  20131. this.map = source.map;
  20132. this.lightMap = source.lightMap;
  20133. this.lightMapIntensity = source.lightMapIntensity;
  20134. this.aoMap = source.aoMap;
  20135. this.aoMapIntensity = source.aoMapIntensity;
  20136. this.emissive.copy(source.emissive);
  20137. this.emissiveMap = source.emissiveMap;
  20138. this.emissiveIntensity = source.emissiveIntensity;
  20139. this.specularMap = source.specularMap;
  20140. this.alphaMap = source.alphaMap;
  20141. this.envMap = source.envMap;
  20142. this.combine = source.combine;
  20143. this.reflectivity = source.reflectivity;
  20144. this.refractionRatio = source.refractionRatio;
  20145. this.wireframe = source.wireframe;
  20146. this.wireframeLinewidth = source.wireframeLinewidth;
  20147. this.wireframeLinecap = source.wireframeLinecap;
  20148. this.wireframeLinejoin = source.wireframeLinejoin;
  20149. this.skinning = source.skinning;
  20150. this.morphTargets = source.morphTargets;
  20151. this.morphNormals = source.morphNormals;
  20152. return this;
  20153. };
  20154. /**
  20155. * parameters = {
  20156. * color: <hex>,
  20157. * opacity: <float>,
  20158. *
  20159. * matcap: new THREE.Texture( <Image> ),
  20160. *
  20161. * map: new THREE.Texture( <Image> ),
  20162. *
  20163. * bumpMap: new THREE.Texture( <Image> ),
  20164. * bumpScale: <float>,
  20165. *
  20166. * normalMap: new THREE.Texture( <Image> ),
  20167. * normalMapType: THREE.TangentSpaceNormalMap,
  20168. * normalScale: <Vector2>,
  20169. *
  20170. * displacementMap: new THREE.Texture( <Image> ),
  20171. * displacementScale: <float>,
  20172. * displacementBias: <float>,
  20173. *
  20174. * alphaMap: new THREE.Texture( <Image> ),
  20175. *
  20176. * skinning: <bool>,
  20177. * morphTargets: <bool>,
  20178. * morphNormals: <bool>
  20179. *
  20180. * flatShading: <bool>
  20181. * }
  20182. */
  20183. function MeshMatcapMaterial(parameters) {
  20184. Material.call(this);
  20185. this.defines = {
  20186. 'MATCAP': ''
  20187. };
  20188. this.type = 'MeshMatcapMaterial';
  20189. this.color = new Color(0xffffff); // diffuse
  20190. this.matcap = null;
  20191. this.map = null;
  20192. this.bumpMap = null;
  20193. this.bumpScale = 1;
  20194. this.normalMap = null;
  20195. this.normalMapType = TangentSpaceNormalMap;
  20196. this.normalScale = new Vector2(1, 1);
  20197. this.displacementMap = null;
  20198. this.displacementScale = 1;
  20199. this.displacementBias = 0;
  20200. this.alphaMap = null;
  20201. this.skinning = false;
  20202. this.morphTargets = false;
  20203. this.morphNormals = false;
  20204. this.flatShading = false;
  20205. this.setValues(parameters);
  20206. }
  20207. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20208. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20209. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20210. MeshMatcapMaterial.prototype.copy = function (source) {
  20211. Material.prototype.copy.call(this, source);
  20212. this.defines = {
  20213. 'MATCAP': ''
  20214. };
  20215. this.color.copy(source.color);
  20216. this.matcap = source.matcap;
  20217. this.map = source.map;
  20218. this.bumpMap = source.bumpMap;
  20219. this.bumpScale = source.bumpScale;
  20220. this.normalMap = source.normalMap;
  20221. this.normalMapType = source.normalMapType;
  20222. this.normalScale.copy(source.normalScale);
  20223. this.displacementMap = source.displacementMap;
  20224. this.displacementScale = source.displacementScale;
  20225. this.displacementBias = source.displacementBias;
  20226. this.alphaMap = source.alphaMap;
  20227. this.skinning = source.skinning;
  20228. this.morphTargets = source.morphTargets;
  20229. this.morphNormals = source.morphNormals;
  20230. this.flatShading = source.flatShading;
  20231. return this;
  20232. };
  20233. /**
  20234. * parameters = {
  20235. * color: <hex>,
  20236. * opacity: <float>,
  20237. *
  20238. * linewidth: <float>,
  20239. *
  20240. * scale: <float>,
  20241. * dashSize: <float>,
  20242. * gapSize: <float>
  20243. * }
  20244. */
  20245. function LineDashedMaterial(parameters) {
  20246. LineBasicMaterial.call(this);
  20247. this.type = 'LineDashedMaterial';
  20248. this.scale = 1;
  20249. this.dashSize = 3;
  20250. this.gapSize = 1;
  20251. this.setValues(parameters);
  20252. }
  20253. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20254. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20255. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20256. LineDashedMaterial.prototype.copy = function (source) {
  20257. LineBasicMaterial.prototype.copy.call(this, source);
  20258. this.scale = source.scale;
  20259. this.dashSize = source.dashSize;
  20260. this.gapSize = source.gapSize;
  20261. return this;
  20262. };
  20263. var Materials = /*#__PURE__*/Object.freeze({
  20264. __proto__: null,
  20265. ShadowMaterial: ShadowMaterial,
  20266. SpriteMaterial: SpriteMaterial,
  20267. RawShaderMaterial: RawShaderMaterial,
  20268. ShaderMaterial: ShaderMaterial,
  20269. PointsMaterial: PointsMaterial,
  20270. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20271. MeshStandardMaterial: MeshStandardMaterial,
  20272. MeshPhongMaterial: MeshPhongMaterial,
  20273. MeshToonMaterial: MeshToonMaterial,
  20274. MeshNormalMaterial: MeshNormalMaterial,
  20275. MeshLambertMaterial: MeshLambertMaterial,
  20276. MeshDepthMaterial: MeshDepthMaterial,
  20277. MeshDistanceMaterial: MeshDistanceMaterial,
  20278. MeshBasicMaterial: MeshBasicMaterial,
  20279. MeshMatcapMaterial: MeshMatcapMaterial,
  20280. LineDashedMaterial: LineDashedMaterial,
  20281. LineBasicMaterial: LineBasicMaterial,
  20282. Material: Material
  20283. });
  20284. var AnimationUtils = {
  20285. // same as Array.prototype.slice, but also works on typed arrays
  20286. arraySlice: function arraySlice(array, from, to) {
  20287. if (AnimationUtils.isTypedArray(array)) {
  20288. // in ios9 array.subarray(from, undefined) will return empty array
  20289. // but array.subarray(from) or array.subarray(from, len) is correct
  20290. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20291. }
  20292. return array.slice(from, to);
  20293. },
  20294. // converts an array to a specific type
  20295. convertArray: function convertArray(array, type, forceClone) {
  20296. if (!array || // let 'undefined' and 'null' pass
  20297. !forceClone && array.constructor === type) return array;
  20298. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20299. return new type(array); // create typed array
  20300. }
  20301. return Array.prototype.slice.call(array); // create Array
  20302. },
  20303. isTypedArray: function isTypedArray(object) {
  20304. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20305. },
  20306. // returns an array by which times and values can be sorted
  20307. getKeyframeOrder: function getKeyframeOrder(times) {
  20308. function compareTime(i, j) {
  20309. return times[i] - times[j];
  20310. }
  20311. var n = times.length;
  20312. var result = new Array(n);
  20313. for (var i = 0; i !== n; ++i) {
  20314. result[i] = i;
  20315. }
  20316. result.sort(compareTime);
  20317. return result;
  20318. },
  20319. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20320. sortedArray: function sortedArray(values, stride, order) {
  20321. var nValues = values.length;
  20322. var result = new values.constructor(nValues);
  20323. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20324. var srcOffset = order[i] * stride;
  20325. for (var j = 0; j !== stride; ++j) {
  20326. result[dstOffset++] = values[srcOffset + j];
  20327. }
  20328. }
  20329. return result;
  20330. },
  20331. // function for parsing AOS keyframe formats
  20332. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20333. var i = 1,
  20334. key = jsonKeys[0];
  20335. while (key !== undefined && key[valuePropertyName] === undefined) {
  20336. key = jsonKeys[i++];
  20337. }
  20338. if (key === undefined) return; // no data
  20339. var value = key[valuePropertyName];
  20340. if (value === undefined) return; // no data
  20341. if (Array.isArray(value)) {
  20342. do {
  20343. value = key[valuePropertyName];
  20344. if (value !== undefined) {
  20345. times.push(key.time);
  20346. values.push.apply(values, value); // push all elements
  20347. }
  20348. key = jsonKeys[i++];
  20349. } while (key !== undefined);
  20350. } else if (value.toArray !== undefined) {
  20351. // ...assume THREE.Math-ish
  20352. do {
  20353. value = key[valuePropertyName];
  20354. if (value !== undefined) {
  20355. times.push(key.time);
  20356. value.toArray(values, values.length);
  20357. }
  20358. key = jsonKeys[i++];
  20359. } while (key !== undefined);
  20360. } else {
  20361. // otherwise push as-is
  20362. do {
  20363. value = key[valuePropertyName];
  20364. if (value !== undefined) {
  20365. times.push(key.time);
  20366. values.push(value);
  20367. }
  20368. key = jsonKeys[i++];
  20369. } while (key !== undefined);
  20370. }
  20371. },
  20372. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20373. if (fps === void 0) {
  20374. fps = 30;
  20375. }
  20376. var clip = sourceClip.clone();
  20377. clip.name = name;
  20378. var tracks = [];
  20379. for (var i = 0; i < clip.tracks.length; ++i) {
  20380. var track = clip.tracks[i];
  20381. var valueSize = track.getValueSize();
  20382. var times = [];
  20383. var values = [];
  20384. for (var j = 0; j < track.times.length; ++j) {
  20385. var frame = track.times[j] * fps;
  20386. if (frame < startFrame || frame >= endFrame) continue;
  20387. times.push(track.times[j]);
  20388. for (var k = 0; k < valueSize; ++k) {
  20389. values.push(track.values[j * valueSize + k]);
  20390. }
  20391. }
  20392. if (times.length === 0) continue;
  20393. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20394. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20395. tracks.push(track);
  20396. }
  20397. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20398. var minStartTime = Infinity;
  20399. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20400. if (minStartTime > clip.tracks[_i].times[0]) {
  20401. minStartTime = clip.tracks[_i].times[0];
  20402. }
  20403. } // shift all tracks such that clip begins at t=0
  20404. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20405. clip.tracks[_i2].shift(-1 * minStartTime);
  20406. }
  20407. clip.resetDuration();
  20408. return clip;
  20409. },
  20410. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20411. if (referenceFrame === void 0) {
  20412. referenceFrame = 0;
  20413. }
  20414. if (referenceClip === void 0) {
  20415. referenceClip = targetClip;
  20416. }
  20417. if (fps === void 0) {
  20418. fps = 30;
  20419. }
  20420. if (fps <= 0) fps = 30;
  20421. var numTracks = referenceClip.tracks.length;
  20422. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20423. var _loop = function _loop(i) {
  20424. var referenceTrack = referenceClip.tracks[i];
  20425. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20426. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20427. var targetTrack = targetClip.tracks.find(function (track) {
  20428. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20429. });
  20430. if (targetTrack === undefined) return "continue";
  20431. var referenceOffset = 0;
  20432. var referenceValueSize = referenceTrack.getValueSize();
  20433. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20434. referenceOffset = referenceValueSize / 3;
  20435. }
  20436. var targetOffset = 0;
  20437. var targetValueSize = targetTrack.getValueSize();
  20438. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20439. targetOffset = targetValueSize / 3;
  20440. }
  20441. var lastIndex = referenceTrack.times.length - 1;
  20442. var referenceValue = void 0; // Find the value to subtract out of the track
  20443. if (referenceTime <= referenceTrack.times[0]) {
  20444. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20445. var startIndex = referenceOffset;
  20446. var endIndex = referenceValueSize - referenceOffset;
  20447. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20448. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20449. // Reference frame is after the last keyframe, so just use the last keyframe
  20450. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20451. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20452. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20453. } else {
  20454. // Interpolate to the reference value
  20455. var interpolant = referenceTrack.createInterpolant();
  20456. var _startIndex2 = referenceOffset;
  20457. var _endIndex2 = referenceValueSize - referenceOffset;
  20458. interpolant.evaluate(referenceTime);
  20459. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20460. } // Conjugate the quaternion
  20461. if (referenceTrackType === 'quaternion') {
  20462. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20463. referenceQuat.toArray(referenceValue);
  20464. } // Subtract the reference value from all of the track values
  20465. var numTimes = targetTrack.times.length;
  20466. for (var j = 0; j < numTimes; ++j) {
  20467. var valueStart = j * targetValueSize + targetOffset;
  20468. if (referenceTrackType === 'quaternion') {
  20469. // Multiply the conjugate for quaternion track types
  20470. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20471. } else {
  20472. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20473. for (var k = 0; k < valueEnd; ++k) {
  20474. targetTrack.values[valueStart + k] -= referenceValue[k];
  20475. }
  20476. }
  20477. }
  20478. };
  20479. for (var i = 0; i < numTracks; ++i) {
  20480. var _ret = _loop(i);
  20481. if (_ret === "continue") continue;
  20482. }
  20483. targetClip.blendMode = AdditiveAnimationBlendMode;
  20484. return targetClip;
  20485. }
  20486. };
  20487. /**
  20488. * Abstract base class of interpolants over parametric samples.
  20489. *
  20490. * The parameter domain is one dimensional, typically the time or a path
  20491. * along a curve defined by the data.
  20492. *
  20493. * The sample values can have any dimensionality and derived classes may
  20494. * apply special interpretations to the data.
  20495. *
  20496. * This class provides the interval seek in a Template Method, deferring
  20497. * the actual interpolation to derived classes.
  20498. *
  20499. * Time complexity is O(1) for linear access crossing at most two points
  20500. * and O(log N) for random access, where N is the number of positions.
  20501. *
  20502. * References:
  20503. *
  20504. * http://www.oodesign.com/template-method-pattern.html
  20505. *
  20506. */
  20507. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20508. this.parameterPositions = parameterPositions;
  20509. this._cachedIndex = 0;
  20510. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20511. this.sampleValues = sampleValues;
  20512. this.valueSize = sampleSize;
  20513. }
  20514. Object.assign(Interpolant.prototype, {
  20515. evaluate: function evaluate(t) {
  20516. var pp = this.parameterPositions;
  20517. var i1 = this._cachedIndex,
  20518. t1 = pp[i1],
  20519. t0 = pp[i1 - 1];
  20520. validate_interval: {
  20521. seek: {
  20522. var right;
  20523. linear_scan: {
  20524. //- See http://jsperf.com/comparison-to-undefined/3
  20525. //- slower code:
  20526. //-
  20527. //- if ( t >= t1 || t1 === undefined ) {
  20528. forward_scan: if (!(t < t1)) {
  20529. for (var giveUpAt = i1 + 2;;) {
  20530. if (t1 === undefined) {
  20531. if (t < t0) break forward_scan; // after end
  20532. i1 = pp.length;
  20533. this._cachedIndex = i1;
  20534. return this.afterEnd_(i1 - 1, t, t0);
  20535. }
  20536. if (i1 === giveUpAt) break; // this loop
  20537. t0 = t1;
  20538. t1 = pp[++i1];
  20539. if (t < t1) {
  20540. // we have arrived at the sought interval
  20541. break seek;
  20542. }
  20543. } // prepare binary search on the right side of the index
  20544. right = pp.length;
  20545. break linear_scan;
  20546. } //- slower code:
  20547. //- if ( t < t0 || t0 === undefined ) {
  20548. if (!(t >= t0)) {
  20549. // looping?
  20550. var t1global = pp[1];
  20551. if (t < t1global) {
  20552. i1 = 2; // + 1, using the scan for the details
  20553. t0 = t1global;
  20554. } // linear reverse scan
  20555. for (var _giveUpAt = i1 - 2;;) {
  20556. if (t0 === undefined) {
  20557. // before start
  20558. this._cachedIndex = 0;
  20559. return this.beforeStart_(0, t, t1);
  20560. }
  20561. if (i1 === _giveUpAt) break; // this loop
  20562. t1 = t0;
  20563. t0 = pp[--i1 - 1];
  20564. if (t >= t0) {
  20565. // we have arrived at the sought interval
  20566. break seek;
  20567. }
  20568. } // prepare binary search on the left side of the index
  20569. right = i1;
  20570. i1 = 0;
  20571. break linear_scan;
  20572. } // the interval is valid
  20573. break validate_interval;
  20574. } // linear scan
  20575. // binary search
  20576. while (i1 < right) {
  20577. var mid = i1 + right >>> 1;
  20578. if (t < pp[mid]) {
  20579. right = mid;
  20580. } else {
  20581. i1 = mid + 1;
  20582. }
  20583. }
  20584. t1 = pp[i1];
  20585. t0 = pp[i1 - 1]; // check boundary cases, again
  20586. if (t0 === undefined) {
  20587. this._cachedIndex = 0;
  20588. return this.beforeStart_(0, t, t1);
  20589. }
  20590. if (t1 === undefined) {
  20591. i1 = pp.length;
  20592. this._cachedIndex = i1;
  20593. return this.afterEnd_(i1 - 1, t0, t);
  20594. }
  20595. } // seek
  20596. this._cachedIndex = i1;
  20597. this.intervalChanged_(i1, t0, t1);
  20598. } // validate_interval
  20599. return this.interpolate_(i1, t0, t, t1);
  20600. },
  20601. settings: null,
  20602. // optional, subclass-specific settings structure
  20603. // Note: The indirection allows central control of many interpolants.
  20604. // --- Protected interface
  20605. DefaultSettings_: {},
  20606. getSettings_: function getSettings_() {
  20607. return this.settings || this.DefaultSettings_;
  20608. },
  20609. copySampleValue_: function copySampleValue_(index) {
  20610. // copies a sample value to the result buffer
  20611. var result = this.resultBuffer,
  20612. values = this.sampleValues,
  20613. stride = this.valueSize,
  20614. offset = index * stride;
  20615. for (var i = 0; i !== stride; ++i) {
  20616. result[i] = values[offset + i];
  20617. }
  20618. return result;
  20619. },
  20620. // Template methods for derived classes:
  20621. interpolate_: function interpolate_()
  20622. /* i1, t0, t, t1 */
  20623. {
  20624. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20625. },
  20626. intervalChanged_: function intervalChanged_()
  20627. /* i1, t0, t1 */
  20628. {// empty
  20629. }
  20630. }); // DECLARE ALIAS AFTER assign prototype
  20631. Object.assign(Interpolant.prototype, {
  20632. //( 0, t, t0 ), returns this.resultBuffer
  20633. beforeStart_: Interpolant.prototype.copySampleValue_,
  20634. //( N-1, tN-1, t ), returns this.resultBuffer
  20635. afterEnd_: Interpolant.prototype.copySampleValue_
  20636. });
  20637. /**
  20638. * Fast and simple cubic spline interpolant.
  20639. *
  20640. * It was derived from a Hermitian construction setting the first derivative
  20641. * at each sample position to the linear slope between neighboring positions
  20642. * over their parameter interval.
  20643. */
  20644. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20645. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20646. this._weightPrev = -0;
  20647. this._offsetPrev = -0;
  20648. this._weightNext = -0;
  20649. this._offsetNext = -0;
  20650. }
  20651. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20652. constructor: CubicInterpolant,
  20653. DefaultSettings_: {
  20654. endingStart: ZeroCurvatureEnding,
  20655. endingEnd: ZeroCurvatureEnding
  20656. },
  20657. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20658. var pp = this.parameterPositions;
  20659. var iPrev = i1 - 2,
  20660. iNext = i1 + 1,
  20661. tPrev = pp[iPrev],
  20662. tNext = pp[iNext];
  20663. if (tPrev === undefined) {
  20664. switch (this.getSettings_().endingStart) {
  20665. case ZeroSlopeEnding:
  20666. // f'(t0) = 0
  20667. iPrev = i1;
  20668. tPrev = 2 * t0 - t1;
  20669. break;
  20670. case WrapAroundEnding:
  20671. // use the other end of the curve
  20672. iPrev = pp.length - 2;
  20673. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20674. break;
  20675. default:
  20676. // ZeroCurvatureEnding
  20677. // f''(t0) = 0 a.k.a. Natural Spline
  20678. iPrev = i1;
  20679. tPrev = t1;
  20680. }
  20681. }
  20682. if (tNext === undefined) {
  20683. switch (this.getSettings_().endingEnd) {
  20684. case ZeroSlopeEnding:
  20685. // f'(tN) = 0
  20686. iNext = i1;
  20687. tNext = 2 * t1 - t0;
  20688. break;
  20689. case WrapAroundEnding:
  20690. // use the other end of the curve
  20691. iNext = 1;
  20692. tNext = t1 + pp[1] - pp[0];
  20693. break;
  20694. default:
  20695. // ZeroCurvatureEnding
  20696. // f''(tN) = 0, a.k.a. Natural Spline
  20697. iNext = i1 - 1;
  20698. tNext = t0;
  20699. }
  20700. }
  20701. var halfDt = (t1 - t0) * 0.5,
  20702. stride = this.valueSize;
  20703. this._weightPrev = halfDt / (t0 - tPrev);
  20704. this._weightNext = halfDt / (tNext - t1);
  20705. this._offsetPrev = iPrev * stride;
  20706. this._offsetNext = iNext * stride;
  20707. },
  20708. interpolate_: function interpolate_(i1, t0, t, t1) {
  20709. var result = this.resultBuffer,
  20710. values = this.sampleValues,
  20711. stride = this.valueSize,
  20712. o1 = i1 * stride,
  20713. o0 = o1 - stride,
  20714. oP = this._offsetPrev,
  20715. oN = this._offsetNext,
  20716. wP = this._weightPrev,
  20717. wN = this._weightNext,
  20718. p = (t - t0) / (t1 - t0),
  20719. pp = p * p,
  20720. ppp = pp * p; // evaluate polynomials
  20721. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20722. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20723. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20724. var sN = wN * ppp - wN * pp; // combine data linearly
  20725. for (var i = 0; i !== stride; ++i) {
  20726. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20727. }
  20728. return result;
  20729. }
  20730. });
  20731. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20732. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20733. }
  20734. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20735. constructor: LinearInterpolant,
  20736. interpolate_: function interpolate_(i1, t0, t, t1) {
  20737. var result = this.resultBuffer,
  20738. values = this.sampleValues,
  20739. stride = this.valueSize,
  20740. offset1 = i1 * stride,
  20741. offset0 = offset1 - stride,
  20742. weight1 = (t - t0) / (t1 - t0),
  20743. weight0 = 1 - weight1;
  20744. for (var i = 0; i !== stride; ++i) {
  20745. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20746. }
  20747. return result;
  20748. }
  20749. });
  20750. /**
  20751. *
  20752. * Interpolant that evaluates to the sample value at the position preceeding
  20753. * the parameter.
  20754. */
  20755. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20756. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20757. }
  20758. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20759. constructor: DiscreteInterpolant,
  20760. interpolate_: function interpolate_(i1
  20761. /*, t0, t, t1 */
  20762. ) {
  20763. return this.copySampleValue_(i1 - 1);
  20764. }
  20765. });
  20766. function KeyframeTrack(name, times, values, interpolation) {
  20767. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20768. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20769. this.name = name;
  20770. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20771. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20772. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20773. } // Static methods
  20774. Object.assign(KeyframeTrack, {
  20775. // Serialization (in static context, because of constructor invocation
  20776. // and automatic invocation of .toJSON):
  20777. toJSON: function toJSON(track) {
  20778. var trackType = track.constructor;
  20779. var json; // derived classes can define a static toJSON method
  20780. if (trackType.toJSON !== undefined) {
  20781. json = trackType.toJSON(track);
  20782. } else {
  20783. // by default, we assume the data can be serialized as-is
  20784. json = {
  20785. 'name': track.name,
  20786. 'times': AnimationUtils.convertArray(track.times, Array),
  20787. 'values': AnimationUtils.convertArray(track.values, Array)
  20788. };
  20789. var interpolation = track.getInterpolation();
  20790. if (interpolation !== track.DefaultInterpolation) {
  20791. json.interpolation = interpolation;
  20792. }
  20793. }
  20794. json.type = track.ValueTypeName; // mandatory
  20795. return json;
  20796. }
  20797. });
  20798. Object.assign(KeyframeTrack.prototype, {
  20799. constructor: KeyframeTrack,
  20800. TimeBufferType: Float32Array,
  20801. ValueBufferType: Float32Array,
  20802. DefaultInterpolation: InterpolateLinear,
  20803. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20804. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20805. },
  20806. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20807. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20808. },
  20809. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20810. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20811. },
  20812. setInterpolation: function setInterpolation(interpolation) {
  20813. var factoryMethod;
  20814. switch (interpolation) {
  20815. case InterpolateDiscrete:
  20816. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20817. break;
  20818. case InterpolateLinear:
  20819. factoryMethod = this.InterpolantFactoryMethodLinear;
  20820. break;
  20821. case InterpolateSmooth:
  20822. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20823. break;
  20824. }
  20825. if (factoryMethod === undefined) {
  20826. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  20827. if (this.createInterpolant === undefined) {
  20828. // fall back to default, unless the default itself is messed up
  20829. if (interpolation !== this.DefaultInterpolation) {
  20830. this.setInterpolation(this.DefaultInterpolation);
  20831. } else {
  20832. throw new Error(message); // fatal, in this case
  20833. }
  20834. }
  20835. console.warn('THREE.KeyframeTrack:', message);
  20836. return this;
  20837. }
  20838. this.createInterpolant = factoryMethod;
  20839. return this;
  20840. },
  20841. getInterpolation: function getInterpolation() {
  20842. switch (this.createInterpolant) {
  20843. case this.InterpolantFactoryMethodDiscrete:
  20844. return InterpolateDiscrete;
  20845. case this.InterpolantFactoryMethodLinear:
  20846. return InterpolateLinear;
  20847. case this.InterpolantFactoryMethodSmooth:
  20848. return InterpolateSmooth;
  20849. }
  20850. },
  20851. getValueSize: function getValueSize() {
  20852. return this.values.length / this.times.length;
  20853. },
  20854. // move all keyframes either forwards or backwards in time
  20855. shift: function shift(timeOffset) {
  20856. if (timeOffset !== 0.0) {
  20857. var times = this.times;
  20858. for (var i = 0, n = times.length; i !== n; ++i) {
  20859. times[i] += timeOffset;
  20860. }
  20861. }
  20862. return this;
  20863. },
  20864. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20865. scale: function scale(timeScale) {
  20866. if (timeScale !== 1.0) {
  20867. var times = this.times;
  20868. for (var i = 0, n = times.length; i !== n; ++i) {
  20869. times[i] *= timeScale;
  20870. }
  20871. }
  20872. return this;
  20873. },
  20874. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20875. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20876. trim: function trim(startTime, endTime) {
  20877. var times = this.times,
  20878. nKeys = times.length;
  20879. var from = 0,
  20880. to = nKeys - 1;
  20881. while (from !== nKeys && times[from] < startTime) {
  20882. ++from;
  20883. }
  20884. while (to !== -1 && times[to] > endTime) {
  20885. --to;
  20886. }
  20887. ++to; // inclusive -> exclusive bound
  20888. if (from !== 0 || to !== nKeys) {
  20889. // empty tracks are forbidden, so keep at least one keyframe
  20890. if (from >= to) {
  20891. to = Math.max(to, 1);
  20892. from = to - 1;
  20893. }
  20894. var stride = this.getValueSize();
  20895. this.times = AnimationUtils.arraySlice(times, from, to);
  20896. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  20897. }
  20898. return this;
  20899. },
  20900. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20901. validate: function validate() {
  20902. var valid = true;
  20903. var valueSize = this.getValueSize();
  20904. if (valueSize - Math.floor(valueSize) !== 0) {
  20905. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  20906. valid = false;
  20907. }
  20908. var times = this.times,
  20909. values = this.values,
  20910. nKeys = times.length;
  20911. if (nKeys === 0) {
  20912. console.error('THREE.KeyframeTrack: Track is empty.', this);
  20913. valid = false;
  20914. }
  20915. var prevTime = null;
  20916. for (var i = 0; i !== nKeys; i++) {
  20917. var currTime = times[i];
  20918. if (typeof currTime === 'number' && isNaN(currTime)) {
  20919. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  20920. valid = false;
  20921. break;
  20922. }
  20923. if (prevTime !== null && prevTime > currTime) {
  20924. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  20925. valid = false;
  20926. break;
  20927. }
  20928. prevTime = currTime;
  20929. }
  20930. if (values !== undefined) {
  20931. if (AnimationUtils.isTypedArray(values)) {
  20932. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  20933. var value = values[_i];
  20934. if (isNaN(value)) {
  20935. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  20936. valid = false;
  20937. break;
  20938. }
  20939. }
  20940. }
  20941. }
  20942. return valid;
  20943. },
  20944. // removes equivalent sequential keys as common in morph target sequences
  20945. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20946. optimize: function optimize() {
  20947. // times or values may be shared with other tracks, so overwriting is unsafe
  20948. var times = AnimationUtils.arraySlice(this.times),
  20949. values = AnimationUtils.arraySlice(this.values),
  20950. stride = this.getValueSize(),
  20951. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20952. lastIndex = times.length - 1;
  20953. var writeIndex = 1;
  20954. for (var i = 1; i < lastIndex; ++i) {
  20955. var keep = false;
  20956. var time = times[i];
  20957. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  20958. if (time !== timeNext && (i !== 1 || time !== times[0])) {
  20959. if (!smoothInterpolation) {
  20960. // remove unnecessary keyframes same as their neighbors
  20961. var offset = i * stride,
  20962. offsetP = offset - stride,
  20963. offsetN = offset + stride;
  20964. for (var j = 0; j !== stride; ++j) {
  20965. var value = values[offset + j];
  20966. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  20967. keep = true;
  20968. break;
  20969. }
  20970. }
  20971. } else {
  20972. keep = true;
  20973. }
  20974. } // in-place compaction
  20975. if (keep) {
  20976. if (i !== writeIndex) {
  20977. times[writeIndex] = times[i];
  20978. var readOffset = i * stride,
  20979. writeOffset = writeIndex * stride;
  20980. for (var _j = 0; _j !== stride; ++_j) {
  20981. values[writeOffset + _j] = values[readOffset + _j];
  20982. }
  20983. }
  20984. ++writeIndex;
  20985. }
  20986. } // flush last keyframe (compaction looks ahead)
  20987. if (lastIndex > 0) {
  20988. times[writeIndex] = times[lastIndex];
  20989. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  20990. values[_writeOffset + _j2] = values[_readOffset + _j2];
  20991. }
  20992. ++writeIndex;
  20993. }
  20994. if (writeIndex !== times.length) {
  20995. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  20996. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  20997. } else {
  20998. this.times = times;
  20999. this.values = values;
  21000. }
  21001. return this;
  21002. },
  21003. clone: function clone() {
  21004. var times = AnimationUtils.arraySlice(this.times, 0);
  21005. var values = AnimationUtils.arraySlice(this.values, 0);
  21006. var TypedKeyframeTrack = this.constructor;
  21007. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21008. track.createInterpolant = this.createInterpolant;
  21009. return track;
  21010. }
  21011. });
  21012. /**
  21013. * A Track of Boolean keyframe values.
  21014. */
  21015. function BooleanKeyframeTrack(name, times, values) {
  21016. KeyframeTrack.call(this, name, times, values);
  21017. }
  21018. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21019. constructor: BooleanKeyframeTrack,
  21020. ValueTypeName: 'bool',
  21021. ValueBufferType: Array,
  21022. DefaultInterpolation: InterpolateDiscrete,
  21023. InterpolantFactoryMethodLinear: undefined,
  21024. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  21025. // representation of a single value and a custom interpolant that
  21026. // computes "firstValue ^ isOdd( index )".
  21027. });
  21028. /**
  21029. * A Track of keyframe values that represent color.
  21030. */
  21031. function ColorKeyframeTrack(name, times, values, interpolation) {
  21032. KeyframeTrack.call(this, name, times, values, interpolation);
  21033. }
  21034. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21035. constructor: ColorKeyframeTrack,
  21036. ValueTypeName: 'color' // ValueBufferType is inherited
  21037. // DefaultInterpolation is inherited
  21038. // Note: Very basic implementation and nothing special yet.
  21039. // However, this is the place for color space parameterization.
  21040. });
  21041. /**
  21042. * A Track of numeric keyframe values.
  21043. */
  21044. function NumberKeyframeTrack(name, times, values, interpolation) {
  21045. KeyframeTrack.call(this, name, times, values, interpolation);
  21046. }
  21047. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21048. constructor: NumberKeyframeTrack,
  21049. ValueTypeName: 'number' // ValueBufferType is inherited
  21050. // DefaultInterpolation is inherited
  21051. });
  21052. /**
  21053. * Spherical linear unit quaternion interpolant.
  21054. */
  21055. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21056. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21057. }
  21058. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21059. constructor: QuaternionLinearInterpolant,
  21060. interpolate_: function interpolate_(i1, t0, t, t1) {
  21061. var result = this.resultBuffer,
  21062. values = this.sampleValues,
  21063. stride = this.valueSize,
  21064. alpha = (t - t0) / (t1 - t0);
  21065. var offset = i1 * stride;
  21066. for (var end = offset + stride; offset !== end; offset += 4) {
  21067. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21068. }
  21069. return result;
  21070. }
  21071. });
  21072. /**
  21073. * A Track of quaternion keyframe values.
  21074. */
  21075. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21076. KeyframeTrack.call(this, name, times, values, interpolation);
  21077. }
  21078. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21079. constructor: QuaternionKeyframeTrack,
  21080. ValueTypeName: 'quaternion',
  21081. // ValueBufferType is inherited
  21082. DefaultInterpolation: InterpolateLinear,
  21083. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21084. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21085. },
  21086. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21087. });
  21088. /**
  21089. * A Track that interpolates Strings
  21090. */
  21091. function StringKeyframeTrack(name, times, values, interpolation) {
  21092. KeyframeTrack.call(this, name, times, values, interpolation);
  21093. }
  21094. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21095. constructor: StringKeyframeTrack,
  21096. ValueTypeName: 'string',
  21097. ValueBufferType: Array,
  21098. DefaultInterpolation: InterpolateDiscrete,
  21099. InterpolantFactoryMethodLinear: undefined,
  21100. InterpolantFactoryMethodSmooth: undefined
  21101. });
  21102. /**
  21103. * A Track of vectored keyframe values.
  21104. */
  21105. function VectorKeyframeTrack(name, times, values, interpolation) {
  21106. KeyframeTrack.call(this, name, times, values, interpolation);
  21107. }
  21108. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21109. constructor: VectorKeyframeTrack,
  21110. ValueTypeName: 'vector' // ValueBufferType is inherited
  21111. // DefaultInterpolation is inherited
  21112. });
  21113. function AnimationClip(name, duration, tracks, blendMode) {
  21114. if (duration === void 0) {
  21115. duration = -1;
  21116. }
  21117. if (blendMode === void 0) {
  21118. blendMode = NormalAnimationBlendMode;
  21119. }
  21120. this.name = name;
  21121. this.tracks = tracks;
  21122. this.duration = duration;
  21123. this.blendMode = blendMode;
  21124. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21125. if (this.duration < 0) {
  21126. this.resetDuration();
  21127. }
  21128. }
  21129. function getTrackTypeForValueTypeName(typeName) {
  21130. switch (typeName.toLowerCase()) {
  21131. case 'scalar':
  21132. case 'double':
  21133. case 'float':
  21134. case 'number':
  21135. case 'integer':
  21136. return NumberKeyframeTrack;
  21137. case 'vector':
  21138. case 'vector2':
  21139. case 'vector3':
  21140. case 'vector4':
  21141. return VectorKeyframeTrack;
  21142. case 'color':
  21143. return ColorKeyframeTrack;
  21144. case 'quaternion':
  21145. return QuaternionKeyframeTrack;
  21146. case 'bool':
  21147. case 'boolean':
  21148. return BooleanKeyframeTrack;
  21149. case 'string':
  21150. return StringKeyframeTrack;
  21151. }
  21152. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21153. }
  21154. function parseKeyframeTrack(json) {
  21155. if (json.type === undefined) {
  21156. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21157. }
  21158. var trackType = getTrackTypeForValueTypeName(json.type);
  21159. if (json.times === undefined) {
  21160. var times = [],
  21161. values = [];
  21162. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21163. json.times = times;
  21164. json.values = values;
  21165. } // derived classes can define a static parse method
  21166. if (trackType.parse !== undefined) {
  21167. return trackType.parse(json);
  21168. } else {
  21169. // by default, we assume a constructor compatible with the base
  21170. return new trackType(json.name, json.times, json.values, json.interpolation);
  21171. }
  21172. }
  21173. Object.assign(AnimationClip, {
  21174. parse: function parse(json) {
  21175. var tracks = [],
  21176. jsonTracks = json.tracks,
  21177. frameTime = 1.0 / (json.fps || 1.0);
  21178. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21179. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21180. }
  21181. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21182. clip.uuid = json.uuid;
  21183. return clip;
  21184. },
  21185. toJSON: function toJSON(clip) {
  21186. var tracks = [],
  21187. clipTracks = clip.tracks;
  21188. var json = {
  21189. 'name': clip.name,
  21190. 'duration': clip.duration,
  21191. 'tracks': tracks,
  21192. 'uuid': clip.uuid,
  21193. 'blendMode': clip.blendMode
  21194. };
  21195. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21196. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21197. }
  21198. return json;
  21199. },
  21200. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21201. var numMorphTargets = morphTargetSequence.length;
  21202. var tracks = [];
  21203. for (var i = 0; i < numMorphTargets; i++) {
  21204. var times = [];
  21205. var values = [];
  21206. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21207. values.push(0, 1, 0);
  21208. var order = AnimationUtils.getKeyframeOrder(times);
  21209. times = AnimationUtils.sortedArray(times, 1, order);
  21210. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21211. // last frame as well for perfect loop.
  21212. if (!noLoop && times[0] === 0) {
  21213. times.push(numMorphTargets);
  21214. values.push(values[0]);
  21215. }
  21216. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21217. }
  21218. return new AnimationClip(name, -1, tracks);
  21219. },
  21220. findByName: function findByName(objectOrClipArray, name) {
  21221. var clipArray = objectOrClipArray;
  21222. if (!Array.isArray(objectOrClipArray)) {
  21223. var o = objectOrClipArray;
  21224. clipArray = o.geometry && o.geometry.animations || o.animations;
  21225. }
  21226. for (var i = 0; i < clipArray.length; i++) {
  21227. if (clipArray[i].name === name) {
  21228. return clipArray[i];
  21229. }
  21230. }
  21231. return null;
  21232. },
  21233. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21234. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21235. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21236. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21237. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21238. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21239. var morphTarget = morphTargets[i];
  21240. var parts = morphTarget.name.match(pattern);
  21241. if (parts && parts.length > 1) {
  21242. var name = parts[1];
  21243. var animationMorphTargets = animationToMorphTargets[name];
  21244. if (!animationMorphTargets) {
  21245. animationToMorphTargets[name] = animationMorphTargets = [];
  21246. }
  21247. animationMorphTargets.push(morphTarget);
  21248. }
  21249. }
  21250. var clips = [];
  21251. for (var _name in animationToMorphTargets) {
  21252. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21253. }
  21254. return clips;
  21255. },
  21256. // parse the animation.hierarchy format
  21257. parseAnimation: function parseAnimation(animation, bones) {
  21258. if (!animation) {
  21259. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21260. return null;
  21261. }
  21262. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21263. // only return track if there are actually keys.
  21264. if (animationKeys.length !== 0) {
  21265. var times = [];
  21266. var values = [];
  21267. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21268. if (times.length !== 0) {
  21269. destTracks.push(new trackType(trackName, times, values));
  21270. }
  21271. }
  21272. };
  21273. var tracks = [];
  21274. var clipName = animation.name || 'default';
  21275. var fps = animation.fps || 30;
  21276. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21277. var duration = animation.length || -1;
  21278. var hierarchyTracks = animation.hierarchy || [];
  21279. for (var h = 0; h < hierarchyTracks.length; h++) {
  21280. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21281. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21282. if (animationKeys[0].morphTargets) {
  21283. // figure out all morph targets used in this track
  21284. var morphTargetNames = {};
  21285. var k = void 0;
  21286. for (k = 0; k < animationKeys.length; k++) {
  21287. if (animationKeys[k].morphTargets) {
  21288. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21289. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21290. }
  21291. }
  21292. } // create a track for each morph target with all zero
  21293. // morphTargetInfluences except for the keys in which
  21294. // the morphTarget is named.
  21295. for (var morphTargetName in morphTargetNames) {
  21296. var times = [];
  21297. var values = [];
  21298. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21299. var animationKey = animationKeys[k];
  21300. times.push(animationKey.time);
  21301. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21302. }
  21303. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21304. }
  21305. duration = morphTargetNames.length * (fps || 1.0);
  21306. } else {
  21307. // ...assume skeletal animation
  21308. var boneName = '.bones[' + bones[h].name + ']';
  21309. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21310. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21311. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21312. }
  21313. }
  21314. if (tracks.length === 0) {
  21315. return null;
  21316. }
  21317. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21318. return clip;
  21319. }
  21320. });
  21321. Object.assign(AnimationClip.prototype, {
  21322. resetDuration: function resetDuration() {
  21323. var tracks = this.tracks;
  21324. var duration = 0;
  21325. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21326. var track = this.tracks[i];
  21327. duration = Math.max(duration, track.times[track.times.length - 1]);
  21328. }
  21329. this.duration = duration;
  21330. return this;
  21331. },
  21332. trim: function trim() {
  21333. for (var i = 0; i < this.tracks.length; i++) {
  21334. this.tracks[i].trim(0, this.duration);
  21335. }
  21336. return this;
  21337. },
  21338. validate: function validate() {
  21339. var valid = true;
  21340. for (var i = 0; i < this.tracks.length; i++) {
  21341. valid = valid && this.tracks[i].validate();
  21342. }
  21343. return valid;
  21344. },
  21345. optimize: function optimize() {
  21346. for (var i = 0; i < this.tracks.length; i++) {
  21347. this.tracks[i].optimize();
  21348. }
  21349. return this;
  21350. },
  21351. clone: function clone() {
  21352. var tracks = [];
  21353. for (var i = 0; i < this.tracks.length; i++) {
  21354. tracks.push(this.tracks[i].clone());
  21355. }
  21356. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21357. },
  21358. toJSON: function toJSON() {
  21359. return AnimationClip.toJSON(this);
  21360. }
  21361. });
  21362. var Cache = {
  21363. enabled: false,
  21364. files: {},
  21365. add: function add(key, file) {
  21366. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21367. this.files[key] = file;
  21368. },
  21369. get: function get(key) {
  21370. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21371. return this.files[key];
  21372. },
  21373. remove: function remove(key) {
  21374. delete this.files[key];
  21375. },
  21376. clear: function clear() {
  21377. this.files = {};
  21378. }
  21379. };
  21380. function LoadingManager(onLoad, onProgress, onError) {
  21381. var scope = this;
  21382. var isLoading = false;
  21383. var itemsLoaded = 0;
  21384. var itemsTotal = 0;
  21385. var urlModifier = undefined;
  21386. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21387. // in the constructor
  21388. this.onStart = undefined;
  21389. this.onLoad = onLoad;
  21390. this.onProgress = onProgress;
  21391. this.onError = onError;
  21392. this.itemStart = function (url) {
  21393. itemsTotal++;
  21394. if (isLoading === false) {
  21395. if (scope.onStart !== undefined) {
  21396. scope.onStart(url, itemsLoaded, itemsTotal);
  21397. }
  21398. }
  21399. isLoading = true;
  21400. };
  21401. this.itemEnd = function (url) {
  21402. itemsLoaded++;
  21403. if (scope.onProgress !== undefined) {
  21404. scope.onProgress(url, itemsLoaded, itemsTotal);
  21405. }
  21406. if (itemsLoaded === itemsTotal) {
  21407. isLoading = false;
  21408. if (scope.onLoad !== undefined) {
  21409. scope.onLoad();
  21410. }
  21411. }
  21412. };
  21413. this.itemError = function (url) {
  21414. if (scope.onError !== undefined) {
  21415. scope.onError(url);
  21416. }
  21417. };
  21418. this.resolveURL = function (url) {
  21419. if (urlModifier) {
  21420. return urlModifier(url);
  21421. }
  21422. return url;
  21423. };
  21424. this.setURLModifier = function (transform) {
  21425. urlModifier = transform;
  21426. return this;
  21427. };
  21428. this.addHandler = function (regex, loader) {
  21429. handlers.push(regex, loader);
  21430. return this;
  21431. };
  21432. this.removeHandler = function (regex) {
  21433. var index = handlers.indexOf(regex);
  21434. if (index !== -1) {
  21435. handlers.splice(index, 2);
  21436. }
  21437. return this;
  21438. };
  21439. this.getHandler = function (file) {
  21440. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21441. var regex = handlers[i];
  21442. var loader = handlers[i + 1];
  21443. if (regex.global) regex.lastIndex = 0; // see #17920
  21444. if (regex.test(file)) {
  21445. return loader;
  21446. }
  21447. }
  21448. return null;
  21449. };
  21450. }
  21451. var DefaultLoadingManager = new LoadingManager();
  21452. function Loader(manager) {
  21453. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21454. this.crossOrigin = 'anonymous';
  21455. this.withCredentials = false;
  21456. this.path = '';
  21457. this.resourcePath = '';
  21458. this.requestHeader = {};
  21459. }
  21460. Object.assign(Loader.prototype, {
  21461. load: function load()
  21462. /* url, onLoad, onProgress, onError */
  21463. {},
  21464. loadAsync: function loadAsync(url, onProgress) {
  21465. var scope = this;
  21466. return new Promise(function (resolve, reject) {
  21467. scope.load(url, resolve, onProgress, reject);
  21468. });
  21469. },
  21470. parse: function parse()
  21471. /* data */
  21472. {},
  21473. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21474. this.crossOrigin = crossOrigin;
  21475. return this;
  21476. },
  21477. setWithCredentials: function setWithCredentials(value) {
  21478. this.withCredentials = value;
  21479. return this;
  21480. },
  21481. setPath: function setPath(path) {
  21482. this.path = path;
  21483. return this;
  21484. },
  21485. setResourcePath: function setResourcePath(resourcePath) {
  21486. this.resourcePath = resourcePath;
  21487. return this;
  21488. },
  21489. setRequestHeader: function setRequestHeader(requestHeader) {
  21490. this.requestHeader = requestHeader;
  21491. return this;
  21492. }
  21493. });
  21494. var loading = {};
  21495. function FileLoader(manager) {
  21496. Loader.call(this, manager);
  21497. }
  21498. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21499. constructor: FileLoader,
  21500. load: function load(url, onLoad, onProgress, onError) {
  21501. if (url === undefined) url = '';
  21502. if (this.path !== undefined) url = this.path + url;
  21503. url = this.manager.resolveURL(url);
  21504. var scope = this;
  21505. var cached = Cache.get(url);
  21506. if (cached !== undefined) {
  21507. scope.manager.itemStart(url);
  21508. setTimeout(function () {
  21509. if (onLoad) onLoad(cached);
  21510. scope.manager.itemEnd(url);
  21511. }, 0);
  21512. return cached;
  21513. } // Check if request is duplicate
  21514. if (loading[url] !== undefined) {
  21515. loading[url].push({
  21516. onLoad: onLoad,
  21517. onProgress: onProgress,
  21518. onError: onError
  21519. });
  21520. return;
  21521. } // Check for data: URI
  21522. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21523. var dataUriRegexResult = url.match(dataUriRegex);
  21524. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21525. if (dataUriRegexResult) {
  21526. var mimeType = dataUriRegexResult[1];
  21527. var isBase64 = !!dataUriRegexResult[2];
  21528. var data = dataUriRegexResult[3];
  21529. data = decodeURIComponent(data);
  21530. if (isBase64) data = atob(data);
  21531. try {
  21532. var response;
  21533. var responseType = (this.responseType || '').toLowerCase();
  21534. switch (responseType) {
  21535. case 'arraybuffer':
  21536. case 'blob':
  21537. var view = new Uint8Array(data.length);
  21538. for (var i = 0; i < data.length; i++) {
  21539. view[i] = data.charCodeAt(i);
  21540. }
  21541. if (responseType === 'blob') {
  21542. response = new Blob([view.buffer], {
  21543. type: mimeType
  21544. });
  21545. } else {
  21546. response = view.buffer;
  21547. }
  21548. break;
  21549. case 'document':
  21550. var parser = new DOMParser();
  21551. response = parser.parseFromString(data, mimeType);
  21552. break;
  21553. case 'json':
  21554. response = JSON.parse(data);
  21555. break;
  21556. default:
  21557. // 'text' or other
  21558. response = data;
  21559. break;
  21560. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21561. setTimeout(function () {
  21562. if (onLoad) onLoad(response);
  21563. scope.manager.itemEnd(url);
  21564. }, 0);
  21565. } catch (error) {
  21566. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21567. setTimeout(function () {
  21568. if (onError) onError(error);
  21569. scope.manager.itemError(url);
  21570. scope.manager.itemEnd(url);
  21571. }, 0);
  21572. }
  21573. } else {
  21574. // Initialise array for duplicate requests
  21575. loading[url] = [];
  21576. loading[url].push({
  21577. onLoad: onLoad,
  21578. onProgress: onProgress,
  21579. onError: onError
  21580. });
  21581. request = new XMLHttpRequest();
  21582. request.open('GET', url, true);
  21583. request.addEventListener('load', function (event) {
  21584. var response = this.response;
  21585. var callbacks = loading[url];
  21586. delete loading[url];
  21587. if (this.status === 200 || this.status === 0) {
  21588. // Some browsers return HTTP Status 0 when using non-http protocol
  21589. // e.g. 'file://' or 'data://'. Handle as success.
  21590. 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
  21591. // error response bodies as proper responses to requests.
  21592. Cache.add(url, response);
  21593. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21594. var callback = callbacks[_i];
  21595. if (callback.onLoad) callback.onLoad(response);
  21596. }
  21597. scope.manager.itemEnd(url);
  21598. } else {
  21599. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21600. var _callback = callbacks[_i2];
  21601. if (_callback.onError) _callback.onError(event);
  21602. }
  21603. scope.manager.itemError(url);
  21604. scope.manager.itemEnd(url);
  21605. }
  21606. }, false);
  21607. request.addEventListener('progress', function (event) {
  21608. var callbacks = loading[url];
  21609. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21610. var callback = callbacks[_i3];
  21611. if (callback.onProgress) callback.onProgress(event);
  21612. }
  21613. }, false);
  21614. request.addEventListener('error', function (event) {
  21615. var callbacks = loading[url];
  21616. delete loading[url];
  21617. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21618. var callback = callbacks[_i4];
  21619. if (callback.onError) callback.onError(event);
  21620. }
  21621. scope.manager.itemError(url);
  21622. scope.manager.itemEnd(url);
  21623. }, false);
  21624. request.addEventListener('abort', function (event) {
  21625. var callbacks = loading[url];
  21626. delete loading[url];
  21627. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21628. var callback = callbacks[_i5];
  21629. if (callback.onError) callback.onError(event);
  21630. }
  21631. scope.manager.itemError(url);
  21632. scope.manager.itemEnd(url);
  21633. }, false);
  21634. if (this.responseType !== undefined) request.responseType = this.responseType;
  21635. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21636. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21637. for (var header in this.requestHeader) {
  21638. request.setRequestHeader(header, this.requestHeader[header]);
  21639. }
  21640. request.send(null);
  21641. }
  21642. scope.manager.itemStart(url);
  21643. return request;
  21644. },
  21645. setResponseType: function setResponseType(value) {
  21646. this.responseType = value;
  21647. return this;
  21648. },
  21649. setMimeType: function setMimeType(value) {
  21650. this.mimeType = value;
  21651. return this;
  21652. }
  21653. });
  21654. var AnimationLoader = /*#__PURE__*/function (_Loader) {
  21655. _inheritsLoose(AnimationLoader, _Loader);
  21656. function AnimationLoader(manager) {
  21657. return _Loader.call(this, manager) || this;
  21658. }
  21659. var _proto = AnimationLoader.prototype;
  21660. _proto.load = function load(url, onLoad, onProgress, onError) {
  21661. var scope = this;
  21662. var loader = new FileLoader(this.manager);
  21663. loader.setPath(this.path);
  21664. loader.setRequestHeader(this.requestHeader);
  21665. loader.setWithCredentials(this.withCredentials);
  21666. loader.load(url, function (text) {
  21667. try {
  21668. onLoad(scope.parse(JSON.parse(text)));
  21669. } catch (e) {
  21670. if (onError) {
  21671. onError(e);
  21672. } else {
  21673. console.error(e);
  21674. }
  21675. scope.manager.itemError(url);
  21676. }
  21677. }, onProgress, onError);
  21678. };
  21679. _proto.parse = function parse(json) {
  21680. var animations = [];
  21681. for (var i = 0; i < json.length; i++) {
  21682. var clip = AnimationClip.parse(json[i]);
  21683. animations.push(clip);
  21684. }
  21685. return animations;
  21686. };
  21687. return AnimationLoader;
  21688. }(Loader);
  21689. /**
  21690. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21691. *
  21692. * Sub classes have to implement the parse() method which will be used in load().
  21693. */
  21694. function CompressedTextureLoader(manager) {
  21695. Loader.call(this, manager);
  21696. }
  21697. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21698. constructor: CompressedTextureLoader,
  21699. load: function load(url, onLoad, onProgress, onError) {
  21700. var scope = this;
  21701. var images = [];
  21702. var texture = new CompressedTexture();
  21703. var loader = new FileLoader(this.manager);
  21704. loader.setPath(this.path);
  21705. loader.setResponseType('arraybuffer');
  21706. loader.setRequestHeader(this.requestHeader);
  21707. loader.setWithCredentials(scope.withCredentials);
  21708. var loaded = 0;
  21709. function loadTexture(i) {
  21710. loader.load(url[i], function (buffer) {
  21711. var texDatas = scope.parse(buffer, true);
  21712. images[i] = {
  21713. width: texDatas.width,
  21714. height: texDatas.height,
  21715. format: texDatas.format,
  21716. mipmaps: texDatas.mipmaps
  21717. };
  21718. loaded += 1;
  21719. if (loaded === 6) {
  21720. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21721. texture.image = images;
  21722. texture.format = texDatas.format;
  21723. texture.needsUpdate = true;
  21724. if (onLoad) onLoad(texture);
  21725. }
  21726. }, onProgress, onError);
  21727. }
  21728. if (Array.isArray(url)) {
  21729. for (var i = 0, il = url.length; i < il; ++i) {
  21730. loadTexture(i);
  21731. }
  21732. } else {
  21733. // compressed cubemap texture stored in a single DDS file
  21734. loader.load(url, function (buffer) {
  21735. var texDatas = scope.parse(buffer, true);
  21736. if (texDatas.isCubemap) {
  21737. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21738. for (var f = 0; f < faces; f++) {
  21739. images[f] = {
  21740. mipmaps: []
  21741. };
  21742. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21743. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21744. images[f].format = texDatas.format;
  21745. images[f].width = texDatas.width;
  21746. images[f].height = texDatas.height;
  21747. }
  21748. }
  21749. texture.image = images;
  21750. } else {
  21751. texture.image.width = texDatas.width;
  21752. texture.image.height = texDatas.height;
  21753. texture.mipmaps = texDatas.mipmaps;
  21754. }
  21755. if (texDatas.mipmapCount === 1) {
  21756. texture.minFilter = LinearFilter;
  21757. }
  21758. texture.format = texDatas.format;
  21759. texture.needsUpdate = true;
  21760. if (onLoad) onLoad(texture);
  21761. }, onProgress, onError);
  21762. }
  21763. return texture;
  21764. }
  21765. });
  21766. var ImageLoader = /*#__PURE__*/function (_Loader) {
  21767. _inheritsLoose(ImageLoader, _Loader);
  21768. function ImageLoader(manager) {
  21769. return _Loader.call(this, manager) || this;
  21770. }
  21771. var _proto = ImageLoader.prototype;
  21772. _proto.load = function load(url, onLoad, onProgress, onError) {
  21773. if (this.path !== undefined) url = this.path + url;
  21774. url = this.manager.resolveURL(url);
  21775. var scope = this;
  21776. var cached = Cache.get(url);
  21777. if (cached !== undefined) {
  21778. scope.manager.itemStart(url);
  21779. setTimeout(function () {
  21780. if (onLoad) onLoad(cached);
  21781. scope.manager.itemEnd(url);
  21782. }, 0);
  21783. return cached;
  21784. }
  21785. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21786. function onImageLoad() {
  21787. image.removeEventListener('load', onImageLoad, false);
  21788. image.removeEventListener('error', onImageError, false);
  21789. Cache.add(url, this);
  21790. if (onLoad) onLoad(this);
  21791. scope.manager.itemEnd(url);
  21792. }
  21793. function onImageError(event) {
  21794. image.removeEventListener('load', onImageLoad, false);
  21795. image.removeEventListener('error', onImageError, false);
  21796. if (onError) onError(event);
  21797. scope.manager.itemError(url);
  21798. scope.manager.itemEnd(url);
  21799. }
  21800. image.addEventListener('load', onImageLoad, false);
  21801. image.addEventListener('error', onImageError, false);
  21802. if (url.substr(0, 5) !== 'data:') {
  21803. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21804. }
  21805. scope.manager.itemStart(url);
  21806. image.src = url;
  21807. return image;
  21808. };
  21809. return ImageLoader;
  21810. }(Loader);
  21811. var CubeTextureLoader = /*#__PURE__*/function (_Loader) {
  21812. _inheritsLoose(CubeTextureLoader, _Loader);
  21813. function CubeTextureLoader(manager) {
  21814. return _Loader.call(this, manager) || this;
  21815. }
  21816. var _proto = CubeTextureLoader.prototype;
  21817. _proto.load = function load(urls, onLoad, onProgress, onError) {
  21818. var texture = new CubeTexture();
  21819. var loader = new ImageLoader(this.manager);
  21820. loader.setCrossOrigin(this.crossOrigin);
  21821. loader.setPath(this.path);
  21822. var loaded = 0;
  21823. function loadTexture(i) {
  21824. loader.load(urls[i], function (image) {
  21825. texture.images[i] = image;
  21826. loaded++;
  21827. if (loaded === 6) {
  21828. texture.needsUpdate = true;
  21829. if (onLoad) onLoad(texture);
  21830. }
  21831. }, undefined, onError);
  21832. }
  21833. for (var i = 0; i < urls.length; ++i) {
  21834. loadTexture(i);
  21835. }
  21836. return texture;
  21837. };
  21838. return CubeTextureLoader;
  21839. }(Loader);
  21840. /**
  21841. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21842. *
  21843. * Sub classes have to implement the parse() method which will be used in load().
  21844. */
  21845. function DataTextureLoader(manager) {
  21846. Loader.call(this, manager);
  21847. }
  21848. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21849. constructor: DataTextureLoader,
  21850. load: function load(url, onLoad, onProgress, onError) {
  21851. var scope = this;
  21852. var texture = new DataTexture();
  21853. var loader = new FileLoader(this.manager);
  21854. loader.setResponseType('arraybuffer');
  21855. loader.setRequestHeader(this.requestHeader);
  21856. loader.setPath(this.path);
  21857. loader.setWithCredentials(scope.withCredentials);
  21858. loader.load(url, function (buffer) {
  21859. var texData = scope.parse(buffer);
  21860. if (!texData) return;
  21861. if (texData.image !== undefined) {
  21862. texture.image = texData.image;
  21863. } else if (texData.data !== undefined) {
  21864. texture.image.width = texData.width;
  21865. texture.image.height = texData.height;
  21866. texture.image.data = texData.data;
  21867. }
  21868. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21869. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21870. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21871. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  21872. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21873. if (texData.encoding !== undefined) {
  21874. texture.encoding = texData.encoding;
  21875. }
  21876. if (texData.flipY !== undefined) {
  21877. texture.flipY = texData.flipY;
  21878. }
  21879. if (texData.format !== undefined) {
  21880. texture.format = texData.format;
  21881. }
  21882. if (texData.type !== undefined) {
  21883. texture.type = texData.type;
  21884. }
  21885. if (texData.mipmaps !== undefined) {
  21886. texture.mipmaps = texData.mipmaps;
  21887. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  21888. }
  21889. if (texData.mipmapCount === 1) {
  21890. texture.minFilter = LinearFilter;
  21891. }
  21892. texture.needsUpdate = true;
  21893. if (onLoad) onLoad(texture, texData);
  21894. }, onProgress, onError);
  21895. return texture;
  21896. }
  21897. });
  21898. function TextureLoader(manager) {
  21899. Loader.call(this, manager);
  21900. }
  21901. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21902. constructor: TextureLoader,
  21903. load: function load(url, onLoad, onProgress, onError) {
  21904. var texture = new Texture();
  21905. var loader = new ImageLoader(this.manager);
  21906. loader.setCrossOrigin(this.crossOrigin);
  21907. loader.setPath(this.path);
  21908. loader.load(url, function (image) {
  21909. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21910. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  21911. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21912. texture.needsUpdate = true;
  21913. if (onLoad !== undefined) {
  21914. onLoad(texture);
  21915. }
  21916. }, onProgress, onError);
  21917. return texture;
  21918. }
  21919. });
  21920. /**
  21921. * Extensible curve object.
  21922. *
  21923. * Some common of curve methods:
  21924. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  21925. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  21926. * .getPoints(), .getSpacedPoints()
  21927. * .getLength()
  21928. * .updateArcLengths()
  21929. *
  21930. * This following curves inherit from THREE.Curve:
  21931. *
  21932. * -- 2D curves --
  21933. * THREE.ArcCurve
  21934. * THREE.CubicBezierCurve
  21935. * THREE.EllipseCurve
  21936. * THREE.LineCurve
  21937. * THREE.QuadraticBezierCurve
  21938. * THREE.SplineCurve
  21939. *
  21940. * -- 3D curves --
  21941. * THREE.CatmullRomCurve3
  21942. * THREE.CubicBezierCurve3
  21943. * THREE.LineCurve3
  21944. * THREE.QuadraticBezierCurve3
  21945. *
  21946. * A series of curves can be represented as a THREE.CurvePath.
  21947. *
  21948. **/
  21949. function Curve() {
  21950. this.type = 'Curve';
  21951. this.arcLengthDivisions = 200;
  21952. }
  21953. Object.assign(Curve.prototype, {
  21954. // Virtual base class method to overwrite and implement in subclasses
  21955. // - t [0 .. 1]
  21956. getPoint: function getPoint()
  21957. /* t, optionalTarget */
  21958. {
  21959. console.warn('THREE.Curve: .getPoint() not implemented.');
  21960. return null;
  21961. },
  21962. // Get point at relative position in curve according to arc length
  21963. // - u [0 .. 1]
  21964. getPointAt: function getPointAt(u, optionalTarget) {
  21965. var t = this.getUtoTmapping(u);
  21966. return this.getPoint(t, optionalTarget);
  21967. },
  21968. // Get sequence of points using getPoint( t )
  21969. getPoints: function getPoints(divisions) {
  21970. if (divisions === void 0) {
  21971. divisions = 5;
  21972. }
  21973. var points = [];
  21974. for (var d = 0; d <= divisions; d++) {
  21975. points.push(this.getPoint(d / divisions));
  21976. }
  21977. return points;
  21978. },
  21979. // Get sequence of points using getPointAt( u )
  21980. getSpacedPoints: function getSpacedPoints(divisions) {
  21981. if (divisions === void 0) {
  21982. divisions = 5;
  21983. }
  21984. var points = [];
  21985. for (var d = 0; d <= divisions; d++) {
  21986. points.push(this.getPointAt(d / divisions));
  21987. }
  21988. return points;
  21989. },
  21990. // Get total curve arc length
  21991. getLength: function getLength() {
  21992. var lengths = this.getLengths();
  21993. return lengths[lengths.length - 1];
  21994. },
  21995. // Get list of cumulative segment lengths
  21996. getLengths: function getLengths(divisions) {
  21997. if (divisions === undefined) divisions = this.arcLengthDivisions;
  21998. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  21999. return this.cacheArcLengths;
  22000. }
  22001. this.needsUpdate = false;
  22002. var cache = [];
  22003. var current,
  22004. last = this.getPoint(0);
  22005. var sum = 0;
  22006. cache.push(0);
  22007. for (var p = 1; p <= divisions; p++) {
  22008. current = this.getPoint(p / divisions);
  22009. sum += current.distanceTo(last);
  22010. cache.push(sum);
  22011. last = current;
  22012. }
  22013. this.cacheArcLengths = cache;
  22014. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22015. },
  22016. updateArcLengths: function updateArcLengths() {
  22017. this.needsUpdate = true;
  22018. this.getLengths();
  22019. },
  22020. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22021. getUtoTmapping: function getUtoTmapping(u, distance) {
  22022. var arcLengths = this.getLengths();
  22023. var i = 0;
  22024. var il = arcLengths.length;
  22025. var targetArcLength; // The targeted u distance value to get
  22026. if (distance) {
  22027. targetArcLength = distance;
  22028. } else {
  22029. targetArcLength = u * arcLengths[il - 1];
  22030. } // binary search for the index with largest value smaller than target u distance
  22031. var low = 0,
  22032. high = il - 1,
  22033. comparison;
  22034. while (low <= high) {
  22035. 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
  22036. comparison = arcLengths[i] - targetArcLength;
  22037. if (comparison < 0) {
  22038. low = i + 1;
  22039. } else if (comparison > 0) {
  22040. high = i - 1;
  22041. } else {
  22042. high = i;
  22043. break; // DONE
  22044. }
  22045. }
  22046. i = high;
  22047. if (arcLengths[i] === targetArcLength) {
  22048. return i / (il - 1);
  22049. } // we could get finer grain at lengths, or use simple interpolation between two points
  22050. var lengthBefore = arcLengths[i];
  22051. var lengthAfter = arcLengths[i + 1];
  22052. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  22053. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  22054. var t = (i + segmentFraction) / (il - 1);
  22055. return t;
  22056. },
  22057. // Returns a unit vector tangent at t
  22058. // In case any sub curve does not implement its tangent derivation,
  22059. // 2 points a small delta apart will be used to find its gradient
  22060. // which seems to give a reasonable approximation
  22061. getTangent: function getTangent(t, optionalTarget) {
  22062. var delta = 0.0001;
  22063. var t1 = t - delta;
  22064. var t2 = t + delta; // Capping in case of danger
  22065. if (t1 < 0) t1 = 0;
  22066. if (t2 > 1) t2 = 1;
  22067. var pt1 = this.getPoint(t1);
  22068. var pt2 = this.getPoint(t2);
  22069. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22070. tangent.copy(pt2).sub(pt1).normalize();
  22071. return tangent;
  22072. },
  22073. getTangentAt: function getTangentAt(u, optionalTarget) {
  22074. var t = this.getUtoTmapping(u);
  22075. return this.getTangent(t, optionalTarget);
  22076. },
  22077. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22078. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22079. var normal = new Vector3();
  22080. var tangents = [];
  22081. var normals = [];
  22082. var binormals = [];
  22083. var vec = new Vector3();
  22084. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22085. for (var i = 0; i <= segments; i++) {
  22086. var u = i / segments;
  22087. tangents[i] = this.getTangentAt(u, new Vector3());
  22088. tangents[i].normalize();
  22089. } // select an initial normal vector perpendicular to the first tangent vector,
  22090. // and in the direction of the minimum tangent xyz component
  22091. normals[0] = new Vector3();
  22092. binormals[0] = new Vector3();
  22093. var min = Number.MAX_VALUE;
  22094. var tx = Math.abs(tangents[0].x);
  22095. var ty = Math.abs(tangents[0].y);
  22096. var tz = Math.abs(tangents[0].z);
  22097. if (tx <= min) {
  22098. min = tx;
  22099. normal.set(1, 0, 0);
  22100. }
  22101. if (ty <= min) {
  22102. min = ty;
  22103. normal.set(0, 1, 0);
  22104. }
  22105. if (tz <= min) {
  22106. normal.set(0, 0, 1);
  22107. }
  22108. vec.crossVectors(tangents[0], normal).normalize();
  22109. normals[0].crossVectors(tangents[0], vec);
  22110. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22111. for (var _i = 1; _i <= segments; _i++) {
  22112. normals[_i] = normals[_i - 1].clone();
  22113. binormals[_i] = binormals[_i - 1].clone();
  22114. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22115. if (vec.length() > Number.EPSILON) {
  22116. vec.normalize();
  22117. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22118. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22119. }
  22120. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22121. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22122. if (closed === true) {
  22123. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22124. _theta /= segments;
  22125. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22126. _theta = -_theta;
  22127. }
  22128. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22129. // twist a little...
  22130. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22131. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22132. }
  22133. }
  22134. return {
  22135. tangents: tangents,
  22136. normals: normals,
  22137. binormals: binormals
  22138. };
  22139. },
  22140. clone: function clone() {
  22141. return new this.constructor().copy(this);
  22142. },
  22143. copy: function copy(source) {
  22144. this.arcLengthDivisions = source.arcLengthDivisions;
  22145. return this;
  22146. },
  22147. toJSON: function toJSON() {
  22148. var data = {
  22149. metadata: {
  22150. version: 4.5,
  22151. type: 'Curve',
  22152. generator: 'Curve.toJSON'
  22153. }
  22154. };
  22155. data.arcLengthDivisions = this.arcLengthDivisions;
  22156. data.type = this.type;
  22157. return data;
  22158. },
  22159. fromJSON: function fromJSON(json) {
  22160. this.arcLengthDivisions = json.arcLengthDivisions;
  22161. return this;
  22162. }
  22163. });
  22164. var EllipseCurve = /*#__PURE__*/function (_Curve) {
  22165. _inheritsLoose(EllipseCurve, _Curve);
  22166. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22167. var _this;
  22168. _this = _Curve.call(this) || this;
  22169. _this.type = 'EllipseCurve';
  22170. Object.defineProperty(_assertThisInitialized(_this), 'isEllipseCurve', {
  22171. value: true
  22172. });
  22173. _this.aX = aX || 0;
  22174. _this.aY = aY || 0;
  22175. _this.xRadius = xRadius || 1;
  22176. _this.yRadius = yRadius || 1;
  22177. _this.aStartAngle = aStartAngle || 0;
  22178. _this.aEndAngle = aEndAngle || 2 * Math.PI;
  22179. _this.aClockwise = aClockwise || false;
  22180. _this.aRotation = aRotation || 0;
  22181. return _this;
  22182. }
  22183. var _proto = EllipseCurve.prototype;
  22184. _proto.getPoint = function getPoint(t, optionalTarget) {
  22185. var point = optionalTarget || new Vector2();
  22186. var twoPi = Math.PI * 2;
  22187. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22188. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22189. while (deltaAngle < 0) {
  22190. deltaAngle += twoPi;
  22191. }
  22192. while (deltaAngle > twoPi) {
  22193. deltaAngle -= twoPi;
  22194. }
  22195. if (deltaAngle < Number.EPSILON) {
  22196. if (samePoints) {
  22197. deltaAngle = 0;
  22198. } else {
  22199. deltaAngle = twoPi;
  22200. }
  22201. }
  22202. if (this.aClockwise === true && !samePoints) {
  22203. if (deltaAngle === twoPi) {
  22204. deltaAngle = -twoPi;
  22205. } else {
  22206. deltaAngle = deltaAngle - twoPi;
  22207. }
  22208. }
  22209. var angle = this.aStartAngle + t * deltaAngle;
  22210. var x = this.aX + this.xRadius * Math.cos(angle);
  22211. var y = this.aY + this.yRadius * Math.sin(angle);
  22212. if (this.aRotation !== 0) {
  22213. var cos = Math.cos(this.aRotation);
  22214. var sin = Math.sin(this.aRotation);
  22215. var tx = x - this.aX;
  22216. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22217. x = tx * cos - ty * sin + this.aX;
  22218. y = tx * sin + ty * cos + this.aY;
  22219. }
  22220. return point.set(x, y);
  22221. };
  22222. _proto.copy = function copy(source) {
  22223. _Curve.prototype.copy.call(this, source);
  22224. this.aX = source.aX;
  22225. this.aY = source.aY;
  22226. this.xRadius = source.xRadius;
  22227. this.yRadius = source.yRadius;
  22228. this.aStartAngle = source.aStartAngle;
  22229. this.aEndAngle = source.aEndAngle;
  22230. this.aClockwise = source.aClockwise;
  22231. this.aRotation = source.aRotation;
  22232. return this;
  22233. };
  22234. _proto.toJSON = function toJSON() {
  22235. var data = _Curve.prototype.toJSON.call(this);
  22236. data.aX = this.aX;
  22237. data.aY = this.aY;
  22238. data.xRadius = this.xRadius;
  22239. data.yRadius = this.yRadius;
  22240. data.aStartAngle = this.aStartAngle;
  22241. data.aEndAngle = this.aEndAngle;
  22242. data.aClockwise = this.aClockwise;
  22243. data.aRotation = this.aRotation;
  22244. return data;
  22245. };
  22246. _proto.fromJSON = function fromJSON(json) {
  22247. _Curve.prototype.fromJSON.call(this, json);
  22248. this.aX = json.aX;
  22249. this.aY = json.aY;
  22250. this.xRadius = json.xRadius;
  22251. this.yRadius = json.yRadius;
  22252. this.aStartAngle = json.aStartAngle;
  22253. this.aEndAngle = json.aEndAngle;
  22254. this.aClockwise = json.aClockwise;
  22255. this.aRotation = json.aRotation;
  22256. return this;
  22257. };
  22258. return EllipseCurve;
  22259. }(Curve);
  22260. var ArcCurve = /*#__PURE__*/function (_EllipseCurve) {
  22261. _inheritsLoose(ArcCurve, _EllipseCurve);
  22262. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22263. var _this;
  22264. _this = _EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise) || this;
  22265. _this.type = 'ArcCurve';
  22266. Object.defineProperty(_assertThisInitialized(_this), 'isArcCurve', {
  22267. value: true
  22268. });
  22269. return _this;
  22270. }
  22271. return ArcCurve;
  22272. }(EllipseCurve);
  22273. /**
  22274. * Centripetal CatmullRom Curve - which is useful for avoiding
  22275. * cusps and self-intersections in non-uniform catmull rom curves.
  22276. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22277. *
  22278. * curve.type accepts centripetal(default), chordal and catmullrom
  22279. * curve.tension is used for catmullrom which defaults to 0.5
  22280. */
  22281. /*
  22282. Based on an optimized c++ solution in
  22283. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22284. - http://ideone.com/NoEbVM
  22285. This CubicPoly class could be used for reusing some variables and calculations,
  22286. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22287. which can be placed in CurveUtils.
  22288. */
  22289. function CubicPoly() {
  22290. var c0 = 0,
  22291. c1 = 0,
  22292. c2 = 0,
  22293. c3 = 0;
  22294. /*
  22295. * Compute coefficients for a cubic polynomial
  22296. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22297. * such that
  22298. * p(0) = x0, p(1) = x1
  22299. * and
  22300. * p'(0) = t0, p'(1) = t1.
  22301. */
  22302. function init(x0, x1, t0, t1) {
  22303. c0 = x0;
  22304. c1 = t0;
  22305. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22306. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22307. }
  22308. return {
  22309. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22310. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22311. },
  22312. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22313. // compute tangents when parameterized in [t1,t2]
  22314. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22315. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22316. t1 *= dt1;
  22317. t2 *= dt1;
  22318. init(x1, x2, t1, t2);
  22319. },
  22320. calc: function calc(t) {
  22321. var t2 = t * t;
  22322. var t3 = t2 * t;
  22323. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22324. }
  22325. };
  22326. } //
  22327. var tmp = new Vector3();
  22328. var px = new CubicPoly(),
  22329. py = new CubicPoly(),
  22330. pz = new CubicPoly();
  22331. var CatmullRomCurve3 = /*#__PURE__*/function (_Curve) {
  22332. _inheritsLoose(CatmullRomCurve3, _Curve);
  22333. function CatmullRomCurve3(points, closed, curveType, tension) {
  22334. var _this;
  22335. if (points === void 0) {
  22336. points = [];
  22337. }
  22338. if (closed === void 0) {
  22339. closed = false;
  22340. }
  22341. if (curveType === void 0) {
  22342. curveType = 'centripetal';
  22343. }
  22344. if (tension === void 0) {
  22345. tension = 0.5;
  22346. }
  22347. _this = _Curve.call(this) || this;
  22348. _this.type = 'CatmullRomCurve3';
  22349. Object.defineProperty(_assertThisInitialized(_this), 'isCatmullRomCurve3', {
  22350. value: true
  22351. });
  22352. _this.points = points;
  22353. _this.closed = closed;
  22354. _this.curveType = curveType;
  22355. _this.tension = tension;
  22356. return _this;
  22357. }
  22358. var _proto = CatmullRomCurve3.prototype;
  22359. _proto.getPoint = function getPoint(t, optionalTarget) {
  22360. if (optionalTarget === void 0) {
  22361. optionalTarget = new Vector3();
  22362. }
  22363. var point = optionalTarget;
  22364. var points = this.points;
  22365. var l = points.length;
  22366. var p = (l - (this.closed ? 0 : 1)) * t;
  22367. var intPoint = Math.floor(p);
  22368. var weight = p - intPoint;
  22369. if (this.closed) {
  22370. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22371. } else if (weight === 0 && intPoint === l - 1) {
  22372. intPoint = l - 2;
  22373. weight = 1;
  22374. }
  22375. var p0, p3; // 4 points (p1 & p2 defined below)
  22376. if (this.closed || intPoint > 0) {
  22377. p0 = points[(intPoint - 1) % l];
  22378. } else {
  22379. // extrapolate first point
  22380. tmp.subVectors(points[0], points[1]).add(points[0]);
  22381. p0 = tmp;
  22382. }
  22383. var p1 = points[intPoint % l];
  22384. var p2 = points[(intPoint + 1) % l];
  22385. if (this.closed || intPoint + 2 < l) {
  22386. p3 = points[(intPoint + 2) % l];
  22387. } else {
  22388. // extrapolate last point
  22389. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22390. p3 = tmp;
  22391. }
  22392. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22393. // init Centripetal / Chordal Catmull-Rom
  22394. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22395. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22396. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22397. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22398. if (dt1 < 1e-4) dt1 = 1.0;
  22399. if (dt0 < 1e-4) dt0 = dt1;
  22400. if (dt2 < 1e-4) dt2 = dt1;
  22401. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22402. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22403. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22404. } else if (this.curveType === 'catmullrom') {
  22405. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22406. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22407. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22408. }
  22409. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22410. return point;
  22411. };
  22412. _proto.copy = function copy(source) {
  22413. _Curve.prototype.copy.call(this, source);
  22414. this.points = [];
  22415. for (var i = 0, l = source.points.length; i < l; i++) {
  22416. var point = source.points[i];
  22417. this.points.push(point.clone());
  22418. }
  22419. this.closed = source.closed;
  22420. this.curveType = source.curveType;
  22421. this.tension = source.tension;
  22422. return this;
  22423. };
  22424. _proto.toJSON = function toJSON() {
  22425. var data = _Curve.prototype.toJSON.call(this);
  22426. data.points = [];
  22427. for (var i = 0, l = this.points.length; i < l; i++) {
  22428. var point = this.points[i];
  22429. data.points.push(point.toArray());
  22430. }
  22431. data.closed = this.closed;
  22432. data.curveType = this.curveType;
  22433. data.tension = this.tension;
  22434. return data;
  22435. };
  22436. _proto.fromJSON = function fromJSON(json) {
  22437. _Curve.prototype.fromJSON.call(this, json);
  22438. this.points = [];
  22439. for (var i = 0, l = json.points.length; i < l; i++) {
  22440. var point = json.points[i];
  22441. this.points.push(new Vector3().fromArray(point));
  22442. }
  22443. this.closed = json.closed;
  22444. this.curveType = json.curveType;
  22445. this.tension = json.tension;
  22446. return this;
  22447. };
  22448. return CatmullRomCurve3;
  22449. }(Curve);
  22450. /**
  22451. * Bezier Curves formulas obtained from
  22452. * http://en.wikipedia.org/wiki/Bézier_curve
  22453. */
  22454. function CatmullRom(t, p0, p1, p2, p3) {
  22455. var v0 = (p2 - p0) * 0.5;
  22456. var v1 = (p3 - p1) * 0.5;
  22457. var t2 = t * t;
  22458. var t3 = t * t2;
  22459. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22460. } //
  22461. function QuadraticBezierP0(t, p) {
  22462. var k = 1 - t;
  22463. return k * k * p;
  22464. }
  22465. function QuadraticBezierP1(t, p) {
  22466. return 2 * (1 - t) * t * p;
  22467. }
  22468. function QuadraticBezierP2(t, p) {
  22469. return t * t * p;
  22470. }
  22471. function QuadraticBezier(t, p0, p1, p2) {
  22472. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22473. } //
  22474. function CubicBezierP0(t, p) {
  22475. var k = 1 - t;
  22476. return k * k * k * p;
  22477. }
  22478. function CubicBezierP1(t, p) {
  22479. var k = 1 - t;
  22480. return 3 * k * k * t * p;
  22481. }
  22482. function CubicBezierP2(t, p) {
  22483. return 3 * (1 - t) * t * t * p;
  22484. }
  22485. function CubicBezierP3(t, p) {
  22486. return t * t * t * p;
  22487. }
  22488. function CubicBezier(t, p0, p1, p2, p3) {
  22489. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22490. }
  22491. var CubicBezierCurve = /*#__PURE__*/function (_Curve) {
  22492. _inheritsLoose(CubicBezierCurve, _Curve);
  22493. function CubicBezierCurve(v0, v1, v2, v3) {
  22494. var _this;
  22495. if (v0 === void 0) {
  22496. v0 = new Vector2();
  22497. }
  22498. if (v1 === void 0) {
  22499. v1 = new Vector2();
  22500. }
  22501. if (v2 === void 0) {
  22502. v2 = new Vector2();
  22503. }
  22504. if (v3 === void 0) {
  22505. v3 = new Vector2();
  22506. }
  22507. _this = _Curve.call(this) || this;
  22508. _this.type = 'CubicBezierCurve';
  22509. Object.defineProperty(_assertThisInitialized(_this), 'isCubicBezierCurve', {
  22510. value: true
  22511. });
  22512. _this.v0 = v0;
  22513. _this.v1 = v1;
  22514. _this.v2 = v2;
  22515. _this.v3 = v3;
  22516. return _this;
  22517. }
  22518. var _proto = CubicBezierCurve.prototype;
  22519. _proto.getPoint = function getPoint(t, optionalTarget) {
  22520. if (optionalTarget === void 0) {
  22521. optionalTarget = new Vector2();
  22522. }
  22523. var point = optionalTarget;
  22524. var v0 = this.v0,
  22525. v1 = this.v1,
  22526. v2 = this.v2,
  22527. v3 = this.v3;
  22528. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22529. return point;
  22530. };
  22531. _proto.copy = function copy(source) {
  22532. _Curve.prototype.copy.call(this, source);
  22533. this.v0.copy(source.v0);
  22534. this.v1.copy(source.v1);
  22535. this.v2.copy(source.v2);
  22536. this.v3.copy(source.v3);
  22537. return this;
  22538. };
  22539. _proto.toJSON = function toJSON() {
  22540. var data = _Curve.prototype.toJSON.call(this);
  22541. data.v0 = this.v0.toArray();
  22542. data.v1 = this.v1.toArray();
  22543. data.v2 = this.v2.toArray();
  22544. data.v3 = this.v3.toArray();
  22545. return data;
  22546. };
  22547. _proto.fromJSON = function fromJSON(json) {
  22548. _Curve.prototype.fromJSON.call(this, json);
  22549. this.v0.fromArray(json.v0);
  22550. this.v1.fromArray(json.v1);
  22551. this.v2.fromArray(json.v2);
  22552. this.v3.fromArray(json.v3);
  22553. return this;
  22554. };
  22555. return CubicBezierCurve;
  22556. }(Curve);
  22557. var CubicBezierCurve3 = /*#__PURE__*/function (_Curve) {
  22558. _inheritsLoose(CubicBezierCurve3, _Curve);
  22559. function CubicBezierCurve3(v0, v1, v2, v3) {
  22560. var _this;
  22561. if (v0 === void 0) {
  22562. v0 = new Vector3();
  22563. }
  22564. if (v1 === void 0) {
  22565. v1 = new Vector3();
  22566. }
  22567. if (v2 === void 0) {
  22568. v2 = new Vector3();
  22569. }
  22570. if (v3 === void 0) {
  22571. v3 = new Vector3();
  22572. }
  22573. _this = _Curve.call(this) || this;
  22574. _this.type = 'CubicBezierCurve3';
  22575. Object.defineProperty(_assertThisInitialized(_this), 'isCubicBezierCurve3', {
  22576. value: true
  22577. });
  22578. _this.v0 = v0;
  22579. _this.v1 = v1;
  22580. _this.v2 = v2;
  22581. _this.v3 = v3;
  22582. return _this;
  22583. }
  22584. var _proto = CubicBezierCurve3.prototype;
  22585. _proto.getPoint = function getPoint(t, optionalTarget) {
  22586. if (optionalTarget === void 0) {
  22587. optionalTarget = new Vector3();
  22588. }
  22589. var point = optionalTarget;
  22590. var v0 = this.v0,
  22591. v1 = this.v1,
  22592. v2 = this.v2,
  22593. v3 = this.v3;
  22594. 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));
  22595. return point;
  22596. };
  22597. _proto.copy = function copy(source) {
  22598. _Curve.prototype.copy.call(this, source);
  22599. this.v0.copy(source.v0);
  22600. this.v1.copy(source.v1);
  22601. this.v2.copy(source.v2);
  22602. this.v3.copy(source.v3);
  22603. return this;
  22604. };
  22605. _proto.toJSON = function toJSON() {
  22606. var data = _Curve.prototype.toJSON.call(this);
  22607. data.v0 = this.v0.toArray();
  22608. data.v1 = this.v1.toArray();
  22609. data.v2 = this.v2.toArray();
  22610. data.v3 = this.v3.toArray();
  22611. return data;
  22612. };
  22613. _proto.fromJSON = function fromJSON(json) {
  22614. _Curve.prototype.fromJSON.call(this, json);
  22615. this.v0.fromArray(json.v0);
  22616. this.v1.fromArray(json.v1);
  22617. this.v2.fromArray(json.v2);
  22618. this.v3.fromArray(json.v3);
  22619. return this;
  22620. };
  22621. return CubicBezierCurve3;
  22622. }(Curve);
  22623. var LineCurve = /*#__PURE__*/function (_Curve) {
  22624. _inheritsLoose(LineCurve, _Curve);
  22625. function LineCurve(v1, v2) {
  22626. var _this;
  22627. if (v1 === void 0) {
  22628. v1 = new Vector2();
  22629. }
  22630. if (v2 === void 0) {
  22631. v2 = new Vector2();
  22632. }
  22633. _this = _Curve.call(this) || this;
  22634. _this.type = 'LineCurve';
  22635. Object.defineProperty(_assertThisInitialized(_this), 'isLineCurve', {
  22636. value: true
  22637. });
  22638. _this.v1 = v1;
  22639. _this.v2 = v2;
  22640. return _this;
  22641. }
  22642. var _proto = LineCurve.prototype;
  22643. _proto.getPoint = function getPoint(t, optionalTarget) {
  22644. if (optionalTarget === void 0) {
  22645. optionalTarget = new Vector2();
  22646. }
  22647. var point = optionalTarget;
  22648. if (t === 1) {
  22649. point.copy(this.v2);
  22650. } else {
  22651. point.copy(this.v2).sub(this.v1);
  22652. point.multiplyScalar(t).add(this.v1);
  22653. }
  22654. return point;
  22655. } // Line curve is linear, so we can overwrite default getPointAt
  22656. ;
  22657. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22658. return this.getPoint(u, optionalTarget);
  22659. };
  22660. _proto.getTangent = function getTangent(t, optionalTarget) {
  22661. var tangent = optionalTarget || new Vector2();
  22662. tangent.copy(this.v2).sub(this.v1).normalize();
  22663. return tangent;
  22664. };
  22665. _proto.copy = function copy(source) {
  22666. _Curve.prototype.copy.call(this, source);
  22667. this.v1.copy(source.v1);
  22668. this.v2.copy(source.v2);
  22669. return this;
  22670. };
  22671. _proto.toJSON = function toJSON() {
  22672. var data = _Curve.prototype.toJSON.call(this);
  22673. data.v1 = this.v1.toArray();
  22674. data.v2 = this.v2.toArray();
  22675. return data;
  22676. };
  22677. _proto.fromJSON = function fromJSON(json) {
  22678. _Curve.prototype.fromJSON.call(this, json);
  22679. this.v1.fromArray(json.v1);
  22680. this.v2.fromArray(json.v2);
  22681. return this;
  22682. };
  22683. return LineCurve;
  22684. }(Curve);
  22685. var LineCurve3 = /*#__PURE__*/function (_Curve) {
  22686. _inheritsLoose(LineCurve3, _Curve);
  22687. function LineCurve3(v1, v2) {
  22688. var _this;
  22689. if (v1 === void 0) {
  22690. v1 = new Vector3();
  22691. }
  22692. if (v2 === void 0) {
  22693. v2 = new Vector3();
  22694. }
  22695. _this = _Curve.call(this) || this;
  22696. _this.type = 'LineCurve3';
  22697. Object.defineProperty(_assertThisInitialized(_this), 'isLineCurve3', {
  22698. value: true
  22699. });
  22700. _this.v1 = v1;
  22701. _this.v2 = v2;
  22702. return _this;
  22703. }
  22704. var _proto = LineCurve3.prototype;
  22705. _proto.getPoint = function getPoint(t, optionalTarget) {
  22706. if (optionalTarget === void 0) {
  22707. optionalTarget = new Vector3();
  22708. }
  22709. var point = optionalTarget;
  22710. if (t === 1) {
  22711. point.copy(this.v2);
  22712. } else {
  22713. point.copy(this.v2).sub(this.v1);
  22714. point.multiplyScalar(t).add(this.v1);
  22715. }
  22716. return point;
  22717. } // Line curve is linear, so we can overwrite default getPointAt
  22718. ;
  22719. _proto.getPointAt = function getPointAt(u, optionalTarget) {
  22720. return this.getPoint(u, optionalTarget);
  22721. };
  22722. _proto.copy = function copy(source) {
  22723. _Curve.prototype.copy.call(this, source);
  22724. this.v1.copy(source.v1);
  22725. this.v2.copy(source.v2);
  22726. return this;
  22727. };
  22728. _proto.toJSON = function toJSON() {
  22729. var data = _Curve.prototype.toJSON.call(this);
  22730. data.v1 = this.v1.toArray();
  22731. data.v2 = this.v2.toArray();
  22732. return data;
  22733. };
  22734. _proto.fromJSON = function fromJSON(json) {
  22735. _Curve.prototype.fromJSON.call(this, json);
  22736. this.v1.fromArray(json.v1);
  22737. this.v2.fromArray(json.v2);
  22738. return this;
  22739. };
  22740. return LineCurve3;
  22741. }(Curve);
  22742. var QuadraticBezierCurve = /*#__PURE__*/function (_Curve) {
  22743. _inheritsLoose(QuadraticBezierCurve, _Curve);
  22744. function QuadraticBezierCurve(v0, v1, v2) {
  22745. var _this;
  22746. if (v0 === void 0) {
  22747. v0 = new Vector2();
  22748. }
  22749. if (v1 === void 0) {
  22750. v1 = new Vector2();
  22751. }
  22752. if (v2 === void 0) {
  22753. v2 = new Vector2();
  22754. }
  22755. _this = _Curve.call(this) || this;
  22756. _this.type = 'QuadraticBezierCurve';
  22757. Object.defineProperty(_assertThisInitialized(_this), 'isQuadraticBezierCurve', {
  22758. value: true
  22759. });
  22760. _this.v0 = v0;
  22761. _this.v1 = v1;
  22762. _this.v2 = v2;
  22763. return _this;
  22764. }
  22765. var _proto = QuadraticBezierCurve.prototype;
  22766. _proto.getPoint = function getPoint(t, optionalTarget) {
  22767. if (optionalTarget === void 0) {
  22768. optionalTarget = new Vector2();
  22769. }
  22770. var point = optionalTarget;
  22771. var v0 = this.v0,
  22772. v1 = this.v1,
  22773. v2 = this.v2;
  22774. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22775. return point;
  22776. };
  22777. _proto.copy = function copy(source) {
  22778. _Curve.prototype.copy.call(this, source);
  22779. this.v0.copy(source.v0);
  22780. this.v1.copy(source.v1);
  22781. this.v2.copy(source.v2);
  22782. return this;
  22783. };
  22784. _proto.toJSON = function toJSON() {
  22785. var data = _Curve.prototype.toJSON.call(this);
  22786. data.v0 = this.v0.toArray();
  22787. data.v1 = this.v1.toArray();
  22788. data.v2 = this.v2.toArray();
  22789. return data;
  22790. };
  22791. _proto.fromJSON = function fromJSON(json) {
  22792. _Curve.prototype.fromJSON.call(this, json);
  22793. this.v0.fromArray(json.v0);
  22794. this.v1.fromArray(json.v1);
  22795. this.v2.fromArray(json.v2);
  22796. return this;
  22797. };
  22798. return QuadraticBezierCurve;
  22799. }(Curve);
  22800. var QuadraticBezierCurve3 = /*#__PURE__*/function (_Curve) {
  22801. _inheritsLoose(QuadraticBezierCurve3, _Curve);
  22802. function QuadraticBezierCurve3(v0, v1, v2) {
  22803. var _this;
  22804. if (v0 === void 0) {
  22805. v0 = new Vector3();
  22806. }
  22807. if (v1 === void 0) {
  22808. v1 = new Vector3();
  22809. }
  22810. if (v2 === void 0) {
  22811. v2 = new Vector3();
  22812. }
  22813. _this = _Curve.call(this) || this;
  22814. _this.type = 'QuadraticBezierCurve3';
  22815. Object.defineProperty(_assertThisInitialized(_this), 'isQuadraticBezierCurve3', {
  22816. value: true
  22817. });
  22818. _this.v0 = v0;
  22819. _this.v1 = v1;
  22820. _this.v2 = v2;
  22821. return _this;
  22822. }
  22823. var _proto = QuadraticBezierCurve3.prototype;
  22824. _proto.getPoint = function getPoint(t, optionalTarget) {
  22825. if (optionalTarget === void 0) {
  22826. optionalTarget = new Vector3();
  22827. }
  22828. var point = optionalTarget;
  22829. var v0 = this.v0,
  22830. v1 = this.v1,
  22831. v2 = this.v2;
  22832. 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));
  22833. return point;
  22834. };
  22835. _proto.copy = function copy(source) {
  22836. _Curve.prototype.copy.call(this, source);
  22837. this.v0.copy(source.v0);
  22838. this.v1.copy(source.v1);
  22839. this.v2.copy(source.v2);
  22840. return this;
  22841. };
  22842. _proto.toJSON = function toJSON() {
  22843. var data = _Curve.prototype.toJSON.call(this);
  22844. data.v0 = this.v0.toArray();
  22845. data.v1 = this.v1.toArray();
  22846. data.v2 = this.v2.toArray();
  22847. return data;
  22848. };
  22849. _proto.fromJSON = function fromJSON(json) {
  22850. _Curve.prototype.fromJSON.call(this, json);
  22851. this.v0.fromArray(json.v0);
  22852. this.v1.fromArray(json.v1);
  22853. this.v2.fromArray(json.v2);
  22854. return this;
  22855. };
  22856. return QuadraticBezierCurve3;
  22857. }(Curve);
  22858. var SplineCurve = /*#__PURE__*/function (_Curve) {
  22859. _inheritsLoose(SplineCurve, _Curve);
  22860. function SplineCurve(points) {
  22861. var _this;
  22862. if (points === void 0) {
  22863. points = [];
  22864. }
  22865. _this = _Curve.call(this) || this;
  22866. _this.type = 'SplineCurve';
  22867. Object.defineProperty(_assertThisInitialized(_this), 'isSplineCurve', {
  22868. value: true
  22869. });
  22870. _this.points = points;
  22871. return _this;
  22872. }
  22873. var _proto = SplineCurve.prototype;
  22874. _proto.getPoint = function getPoint(t, optionalTarget) {
  22875. if (optionalTarget === void 0) {
  22876. optionalTarget = new Vector2();
  22877. }
  22878. var point = optionalTarget;
  22879. var points = this.points;
  22880. var p = (points.length - 1) * t;
  22881. var intPoint = Math.floor(p);
  22882. var weight = p - intPoint;
  22883. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22884. var p1 = points[intPoint];
  22885. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22886. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22887. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22888. return point;
  22889. };
  22890. _proto.copy = function copy(source) {
  22891. Curve.prototype.copy.call(this, source);
  22892. this.points = [];
  22893. for (var i = 0, l = source.points.length; i < l; i++) {
  22894. var point = source.points[i];
  22895. this.points.push(point.clone());
  22896. }
  22897. return this;
  22898. };
  22899. _proto.toJSON = function toJSON() {
  22900. var data = Curve.prototype.toJSON.call(this);
  22901. data.points = [];
  22902. for (var i = 0, l = this.points.length; i < l; i++) {
  22903. var point = this.points[i];
  22904. data.points.push(point.toArray());
  22905. }
  22906. return data;
  22907. };
  22908. _proto.fromJSON = function fromJSON(json) {
  22909. Curve.prototype.fromJSON.call(this, json);
  22910. this.points = [];
  22911. for (var i = 0, l = json.points.length; i < l; i++) {
  22912. var point = json.points[i];
  22913. this.points.push(new Vector2().fromArray(point));
  22914. }
  22915. return this;
  22916. };
  22917. return SplineCurve;
  22918. }(Curve);
  22919. var Curves = /*#__PURE__*/Object.freeze({
  22920. __proto__: null,
  22921. ArcCurve: ArcCurve,
  22922. CatmullRomCurve3: CatmullRomCurve3,
  22923. CubicBezierCurve: CubicBezierCurve,
  22924. CubicBezierCurve3: CubicBezierCurve3,
  22925. EllipseCurve: EllipseCurve,
  22926. LineCurve: LineCurve,
  22927. LineCurve3: LineCurve3,
  22928. QuadraticBezierCurve: QuadraticBezierCurve,
  22929. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22930. SplineCurve: SplineCurve
  22931. });
  22932. /**************************************************************
  22933. * Curved Path - a curve path is simply a array of connected
  22934. * curves, but retains the api of a curve
  22935. **************************************************************/
  22936. var CurvePath = /*#__PURE__*/function (_Curve) {
  22937. _inheritsLoose(CurvePath, _Curve);
  22938. function CurvePath() {
  22939. var _this;
  22940. _this = _Curve.call(this) || this;
  22941. _this.type = 'CurvePath';
  22942. _this.curves = [];
  22943. _this.autoClose = false; // Automatically closes the path
  22944. return _this;
  22945. }
  22946. var _proto = CurvePath.prototype;
  22947. _proto.add = function add(curve) {
  22948. this.curves.push(curve);
  22949. };
  22950. _proto.closePath = function closePath() {
  22951. // Add a line curve if start and end of lines are not connected
  22952. var startPoint = this.curves[0].getPoint(0);
  22953. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22954. if (!startPoint.equals(endPoint)) {
  22955. this.curves.push(new LineCurve(endPoint, startPoint));
  22956. }
  22957. } // To get accurate point with reference to
  22958. // entire path distance at time t,
  22959. // following has to be done:
  22960. // 1. Length of each sub path have to be known
  22961. // 2. Locate and identify type of curve
  22962. // 3. Get t for the curve
  22963. // 4. Return curve.getPointAt(t')
  22964. ;
  22965. _proto.getPoint = function getPoint(t) {
  22966. var d = t * this.getLength();
  22967. var curveLengths = this.getCurveLengths();
  22968. var i = 0; // To think about boundaries points.
  22969. while (i < curveLengths.length) {
  22970. if (curveLengths[i] >= d) {
  22971. var diff = curveLengths[i] - d;
  22972. var curve = this.curves[i];
  22973. var segmentLength = curve.getLength();
  22974. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22975. return curve.getPointAt(u);
  22976. }
  22977. i++;
  22978. }
  22979. return null; // loop where sum != 0, sum > d , sum+1 <d
  22980. } // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22981. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22982. // getPoint() depends on getLength
  22983. ;
  22984. _proto.getLength = function getLength() {
  22985. var lens = this.getCurveLengths();
  22986. return lens[lens.length - 1];
  22987. } // cacheLengths must be recalculated.
  22988. ;
  22989. _proto.updateArcLengths = function updateArcLengths() {
  22990. this.needsUpdate = true;
  22991. this.cacheLengths = null;
  22992. this.getCurveLengths();
  22993. } // Compute lengths and cache them
  22994. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22995. ;
  22996. _proto.getCurveLengths = function getCurveLengths() {
  22997. // We use cache values if curves and cache array are same length
  22998. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22999. return this.cacheLengths;
  23000. } // Get length of sub-curve
  23001. // Push sums into cached array
  23002. var lengths = [];
  23003. var sums = 0;
  23004. for (var i = 0, l = this.curves.length; i < l; i++) {
  23005. sums += this.curves[i].getLength();
  23006. lengths.push(sums);
  23007. }
  23008. this.cacheLengths = lengths;
  23009. return lengths;
  23010. };
  23011. _proto.getSpacedPoints = function getSpacedPoints(divisions) {
  23012. if (divisions === void 0) {
  23013. divisions = 40;
  23014. }
  23015. var points = [];
  23016. for (var i = 0; i <= divisions; i++) {
  23017. points.push(this.getPoint(i / divisions));
  23018. }
  23019. if (this.autoClose) {
  23020. points.push(points[0]);
  23021. }
  23022. return points;
  23023. };
  23024. _proto.getPoints = function getPoints(divisions) {
  23025. if (divisions === void 0) {
  23026. divisions = 12;
  23027. }
  23028. var points = [];
  23029. var last;
  23030. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  23031. var curve = curves[i];
  23032. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  23033. var pts = curve.getPoints(resolution);
  23034. for (var j = 0; j < pts.length; j++) {
  23035. var point = pts[j];
  23036. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  23037. points.push(point);
  23038. last = point;
  23039. }
  23040. }
  23041. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  23042. points.push(points[0]);
  23043. }
  23044. return points;
  23045. };
  23046. _proto.copy = function copy(source) {
  23047. _Curve.prototype.copy.call(this, source);
  23048. this.curves = [];
  23049. for (var i = 0, l = source.curves.length; i < l; i++) {
  23050. var curve = source.curves[i];
  23051. this.curves.push(curve.clone());
  23052. }
  23053. this.autoClose = source.autoClose;
  23054. return this;
  23055. };
  23056. _proto.toJSON = function toJSON() {
  23057. var data = _Curve.prototype.toJSON.call(this);
  23058. data.autoClose = this.autoClose;
  23059. data.curves = [];
  23060. for (var i = 0, l = this.curves.length; i < l; i++) {
  23061. var curve = this.curves[i];
  23062. data.curves.push(curve.toJSON());
  23063. }
  23064. return data;
  23065. };
  23066. _proto.fromJSON = function fromJSON(json) {
  23067. _Curve.prototype.fromJSON.call(this, json);
  23068. this.autoClose = json.autoClose;
  23069. this.curves = [];
  23070. for (var i = 0, l = json.curves.length; i < l; i++) {
  23071. var curve = json.curves[i];
  23072. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  23073. }
  23074. return this;
  23075. };
  23076. return CurvePath;
  23077. }(Curve);
  23078. var Path = /*#__PURE__*/function (_CurvePath) {
  23079. _inheritsLoose(Path, _CurvePath);
  23080. function Path(points) {
  23081. var _this;
  23082. _this = _CurvePath.call(this) || this;
  23083. _this.type = 'Path';
  23084. _this.currentPoint = new Vector2();
  23085. if (points) {
  23086. _this.setFromPoints(points);
  23087. }
  23088. return _this;
  23089. }
  23090. var _proto = Path.prototype;
  23091. _proto.setFromPoints = function setFromPoints(points) {
  23092. this.moveTo(points[0].x, points[0].y);
  23093. for (var i = 1, l = points.length; i < l; i++) {
  23094. this.lineTo(points[i].x, points[i].y);
  23095. }
  23096. return this;
  23097. };
  23098. _proto.moveTo = function moveTo(x, y) {
  23099. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  23100. return this;
  23101. };
  23102. _proto.lineTo = function lineTo(x, y) {
  23103. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  23104. this.curves.push(curve);
  23105. this.currentPoint.set(x, y);
  23106. return this;
  23107. };
  23108. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  23109. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  23110. this.curves.push(curve);
  23111. this.currentPoint.set(aX, aY);
  23112. return this;
  23113. };
  23114. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  23115. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  23116. this.curves.push(curve);
  23117. this.currentPoint.set(aX, aY);
  23118. return this;
  23119. };
  23120. _proto.splineThru = function splineThru(pts
  23121. /*Array of Vector*/
  23122. ) {
  23123. var npts = [this.currentPoint.clone()].concat(pts);
  23124. var curve = new SplineCurve(npts);
  23125. this.curves.push(curve);
  23126. this.currentPoint.copy(pts[pts.length - 1]);
  23127. return this;
  23128. };
  23129. _proto.arc = function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23130. var x0 = this.currentPoint.x;
  23131. var y0 = this.currentPoint.y;
  23132. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  23133. return this;
  23134. };
  23135. _proto.absarc = function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  23136. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  23137. return this;
  23138. };
  23139. _proto.ellipse = function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23140. var x0 = this.currentPoint.x;
  23141. var y0 = this.currentPoint.y;
  23142. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23143. return this;
  23144. };
  23145. _proto.absellipse = function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23146. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23147. if (this.curves.length > 0) {
  23148. // if a previous curve is present, attempt to join
  23149. var firstPoint = curve.getPoint(0);
  23150. if (!firstPoint.equals(this.currentPoint)) {
  23151. this.lineTo(firstPoint.x, firstPoint.y);
  23152. }
  23153. }
  23154. this.curves.push(curve);
  23155. var lastPoint = curve.getPoint(1);
  23156. this.currentPoint.copy(lastPoint);
  23157. return this;
  23158. };
  23159. _proto.copy = function copy(source) {
  23160. _CurvePath.prototype.copy.call(this, source);
  23161. this.currentPoint.copy(source.currentPoint);
  23162. return this;
  23163. };
  23164. _proto.toJSON = function toJSON() {
  23165. var data = _CurvePath.prototype.toJSON.call(this);
  23166. data.currentPoint = this.currentPoint.toArray();
  23167. return data;
  23168. };
  23169. _proto.fromJSON = function fromJSON(json) {
  23170. _CurvePath.prototype.fromJSON.call(this, json);
  23171. this.currentPoint.fromArray(json.currentPoint);
  23172. return this;
  23173. };
  23174. return Path;
  23175. }(CurvePath);
  23176. var Shape = /*#__PURE__*/function (_Path) {
  23177. _inheritsLoose(Shape, _Path);
  23178. function Shape(points) {
  23179. var _this;
  23180. _this = _Path.call(this, points) || this;
  23181. _this.uuid = MathUtils.generateUUID();
  23182. _this.type = 'Shape';
  23183. _this.holes = [];
  23184. return _this;
  23185. }
  23186. var _proto = Shape.prototype;
  23187. _proto.getPointsHoles = function getPointsHoles(divisions) {
  23188. var holesPts = [];
  23189. for (var i = 0, l = this.holes.length; i < l; i++) {
  23190. holesPts[i] = this.holes[i].getPoints(divisions);
  23191. }
  23192. return holesPts;
  23193. } // get points of shape and holes (keypoints based on segments parameter)
  23194. ;
  23195. _proto.extractPoints = function extractPoints(divisions) {
  23196. return {
  23197. shape: this.getPoints(divisions),
  23198. holes: this.getPointsHoles(divisions)
  23199. };
  23200. };
  23201. _proto.copy = function copy(source) {
  23202. _Path.prototype.copy.call(this, source);
  23203. this.holes = [];
  23204. for (var i = 0, l = source.holes.length; i < l; i++) {
  23205. var hole = source.holes[i];
  23206. this.holes.push(hole.clone());
  23207. }
  23208. return this;
  23209. };
  23210. _proto.toJSON = function toJSON() {
  23211. var data = _Path.prototype.toJSON.call(this);
  23212. data.uuid = this.uuid;
  23213. data.holes = [];
  23214. for (var i = 0, l = this.holes.length; i < l; i++) {
  23215. var hole = this.holes[i];
  23216. data.holes.push(hole.toJSON());
  23217. }
  23218. return data;
  23219. };
  23220. _proto.fromJSON = function fromJSON(json) {
  23221. _Path.prototype.fromJSON.call(this, json);
  23222. this.uuid = json.uuid;
  23223. this.holes = [];
  23224. for (var i = 0, l = json.holes.length; i < l; i++) {
  23225. var hole = json.holes[i];
  23226. this.holes.push(new Path().fromJSON(hole));
  23227. }
  23228. return this;
  23229. };
  23230. return Shape;
  23231. }(Path);
  23232. function Light(color, intensity) {
  23233. if (intensity === void 0) {
  23234. intensity = 1;
  23235. }
  23236. Object3D.call(this);
  23237. this.type = 'Light';
  23238. this.color = new Color(color);
  23239. this.intensity = intensity;
  23240. }
  23241. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23242. constructor: Light,
  23243. isLight: true,
  23244. copy: function copy(source) {
  23245. Object3D.prototype.copy.call(this, source);
  23246. this.color.copy(source.color);
  23247. this.intensity = source.intensity;
  23248. return this;
  23249. },
  23250. toJSON: function toJSON(meta) {
  23251. var data = Object3D.prototype.toJSON.call(this, meta);
  23252. data.object.color = this.color.getHex();
  23253. data.object.intensity = this.intensity;
  23254. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23255. if (this.distance !== undefined) data.object.distance = this.distance;
  23256. if (this.angle !== undefined) data.object.angle = this.angle;
  23257. if (this.decay !== undefined) data.object.decay = this.decay;
  23258. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23259. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23260. return data;
  23261. }
  23262. });
  23263. function HemisphereLight(skyColor, groundColor, intensity) {
  23264. Light.call(this, skyColor, intensity);
  23265. this.type = 'HemisphereLight';
  23266. this.position.copy(Object3D.DefaultUp);
  23267. this.updateMatrix();
  23268. this.groundColor = new Color(groundColor);
  23269. }
  23270. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23271. constructor: HemisphereLight,
  23272. isHemisphereLight: true,
  23273. copy: function copy(source) {
  23274. Light.prototype.copy.call(this, source);
  23275. this.groundColor.copy(source.groundColor);
  23276. return this;
  23277. }
  23278. });
  23279. function LightShadow(camera) {
  23280. this.camera = camera;
  23281. this.bias = 0;
  23282. this.normalBias = 0;
  23283. this.radius = 1;
  23284. this.mapSize = new Vector2(512, 512);
  23285. this.map = null;
  23286. this.mapPass = null;
  23287. this.matrix = new Matrix4();
  23288. this.autoUpdate = true;
  23289. this.needsUpdate = false;
  23290. this._frustum = new Frustum();
  23291. this._frameExtents = new Vector2(1, 1);
  23292. this._viewportCount = 1;
  23293. this._viewports = [new Vector4(0, 0, 1, 1)];
  23294. }
  23295. Object.assign(LightShadow.prototype, {
  23296. _projScreenMatrix: new Matrix4(),
  23297. _lightPositionWorld: new Vector3(),
  23298. _lookTarget: new Vector3(),
  23299. getViewportCount: function getViewportCount() {
  23300. return this._viewportCount;
  23301. },
  23302. getFrustum: function getFrustum() {
  23303. return this._frustum;
  23304. },
  23305. updateMatrices: function updateMatrices(light) {
  23306. var shadowCamera = this.camera,
  23307. shadowMatrix = this.matrix,
  23308. projScreenMatrix = this._projScreenMatrix,
  23309. lookTarget = this._lookTarget,
  23310. lightPositionWorld = this._lightPositionWorld;
  23311. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23312. shadowCamera.position.copy(lightPositionWorld);
  23313. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23314. shadowCamera.lookAt(lookTarget);
  23315. shadowCamera.updateMatrixWorld();
  23316. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23317. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23318. 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);
  23319. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23320. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23321. },
  23322. getViewport: function getViewport(viewportIndex) {
  23323. return this._viewports[viewportIndex];
  23324. },
  23325. getFrameExtents: function getFrameExtents() {
  23326. return this._frameExtents;
  23327. },
  23328. copy: function copy(source) {
  23329. this.camera = source.camera.clone();
  23330. this.bias = source.bias;
  23331. this.radius = source.radius;
  23332. this.mapSize.copy(source.mapSize);
  23333. return this;
  23334. },
  23335. clone: function clone() {
  23336. return new this.constructor().copy(this);
  23337. },
  23338. toJSON: function toJSON() {
  23339. var object = {};
  23340. if (this.bias !== 0) object.bias = this.bias;
  23341. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23342. if (this.radius !== 1) object.radius = this.radius;
  23343. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23344. object.camera = this.camera.toJSON(false).object;
  23345. delete object.camera.matrix;
  23346. return object;
  23347. }
  23348. });
  23349. function SpotLightShadow() {
  23350. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23351. this.focus = 1;
  23352. }
  23353. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23354. constructor: SpotLightShadow,
  23355. isSpotLightShadow: true,
  23356. updateMatrices: function updateMatrices(light) {
  23357. var camera = this.camera;
  23358. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23359. var aspect = this.mapSize.width / this.mapSize.height;
  23360. var far = light.distance || camera.far;
  23361. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23362. camera.fov = fov;
  23363. camera.aspect = aspect;
  23364. camera.far = far;
  23365. camera.updateProjectionMatrix();
  23366. }
  23367. LightShadow.prototype.updateMatrices.call(this, light);
  23368. }
  23369. });
  23370. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23371. Light.call(this, color, intensity);
  23372. this.type = 'SpotLight';
  23373. this.position.copy(Object3D.DefaultUp);
  23374. this.updateMatrix();
  23375. this.target = new Object3D();
  23376. Object.defineProperty(this, 'power', {
  23377. get: function get() {
  23378. // intensity = power per solid angle.
  23379. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23380. return this.intensity * Math.PI;
  23381. },
  23382. set: function set(power) {
  23383. // intensity = power per solid angle.
  23384. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23385. this.intensity = power / Math.PI;
  23386. }
  23387. });
  23388. this.distance = distance !== undefined ? distance : 0;
  23389. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23390. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23391. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23392. this.shadow = new SpotLightShadow();
  23393. }
  23394. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23395. constructor: SpotLight,
  23396. isSpotLight: true,
  23397. copy: function copy(source) {
  23398. Light.prototype.copy.call(this, source);
  23399. this.distance = source.distance;
  23400. this.angle = source.angle;
  23401. this.penumbra = source.penumbra;
  23402. this.decay = source.decay;
  23403. this.target = source.target.clone();
  23404. this.shadow = source.shadow.clone();
  23405. return this;
  23406. }
  23407. });
  23408. function PointLightShadow() {
  23409. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23410. this._frameExtents = new Vector2(4, 2);
  23411. this._viewportCount = 6;
  23412. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23413. // following orientation:
  23414. //
  23415. // xzXZ
  23416. // y Y
  23417. //
  23418. // X - Positive x direction
  23419. // x - Negative x direction
  23420. // Y - Positive y direction
  23421. // y - Negative y direction
  23422. // Z - Positive z direction
  23423. // z - Negative z direction
  23424. // positive X
  23425. new Vector4(2, 1, 1, 1), // negative X
  23426. new Vector4(0, 1, 1, 1), // positive Z
  23427. new Vector4(3, 1, 1, 1), // negative Z
  23428. new Vector4(1, 1, 1, 1), // positive Y
  23429. new Vector4(3, 0, 1, 1), // negative Y
  23430. new Vector4(1, 0, 1, 1)];
  23431. 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)];
  23432. 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)];
  23433. }
  23434. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23435. constructor: PointLightShadow,
  23436. isPointLightShadow: true,
  23437. updateMatrices: function updateMatrices(light, viewportIndex) {
  23438. if (viewportIndex === void 0) {
  23439. viewportIndex = 0;
  23440. }
  23441. var camera = this.camera,
  23442. shadowMatrix = this.matrix,
  23443. lightPositionWorld = this._lightPositionWorld,
  23444. lookTarget = this._lookTarget,
  23445. projScreenMatrix = this._projScreenMatrix;
  23446. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23447. camera.position.copy(lightPositionWorld);
  23448. lookTarget.copy(camera.position);
  23449. lookTarget.add(this._cubeDirections[viewportIndex]);
  23450. camera.up.copy(this._cubeUps[viewportIndex]);
  23451. camera.lookAt(lookTarget);
  23452. camera.updateMatrixWorld();
  23453. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23454. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23455. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23456. }
  23457. });
  23458. function PointLight(color, intensity, distance, decay) {
  23459. Light.call(this, color, intensity);
  23460. this.type = 'PointLight';
  23461. Object.defineProperty(this, 'power', {
  23462. get: function get() {
  23463. // intensity = power per solid angle.
  23464. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23465. return this.intensity * 4 * Math.PI;
  23466. },
  23467. set: function set(power) {
  23468. // intensity = power per solid angle.
  23469. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23470. this.intensity = power / (4 * Math.PI);
  23471. }
  23472. });
  23473. this.distance = distance !== undefined ? distance : 0;
  23474. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23475. this.shadow = new PointLightShadow();
  23476. }
  23477. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23478. constructor: PointLight,
  23479. isPointLight: true,
  23480. copy: function copy(source) {
  23481. Light.prototype.copy.call(this, source);
  23482. this.distance = source.distance;
  23483. this.decay = source.decay;
  23484. this.shadow = source.shadow.clone();
  23485. return this;
  23486. }
  23487. });
  23488. function OrthographicCamera(left, right, top, bottom, near, far) {
  23489. if (left === void 0) {
  23490. left = -1;
  23491. }
  23492. if (right === void 0) {
  23493. right = 1;
  23494. }
  23495. if (top === void 0) {
  23496. top = 1;
  23497. }
  23498. if (bottom === void 0) {
  23499. bottom = -1;
  23500. }
  23501. if (near === void 0) {
  23502. near = 0.1;
  23503. }
  23504. if (far === void 0) {
  23505. far = 2000;
  23506. }
  23507. Camera.call(this);
  23508. this.type = 'OrthographicCamera';
  23509. this.zoom = 1;
  23510. this.view = null;
  23511. this.left = left;
  23512. this.right = right;
  23513. this.top = top;
  23514. this.bottom = bottom;
  23515. this.near = near;
  23516. this.far = far;
  23517. this.updateProjectionMatrix();
  23518. }
  23519. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23520. constructor: OrthographicCamera,
  23521. isOrthographicCamera: true,
  23522. copy: function copy(source, recursive) {
  23523. Camera.prototype.copy.call(this, source, recursive);
  23524. this.left = source.left;
  23525. this.right = source.right;
  23526. this.top = source.top;
  23527. this.bottom = source.bottom;
  23528. this.near = source.near;
  23529. this.far = source.far;
  23530. this.zoom = source.zoom;
  23531. this.view = source.view === null ? null : Object.assign({}, source.view);
  23532. return this;
  23533. },
  23534. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23535. if (this.view === null) {
  23536. this.view = {
  23537. enabled: true,
  23538. fullWidth: 1,
  23539. fullHeight: 1,
  23540. offsetX: 0,
  23541. offsetY: 0,
  23542. width: 1,
  23543. height: 1
  23544. };
  23545. }
  23546. this.view.enabled = true;
  23547. this.view.fullWidth = fullWidth;
  23548. this.view.fullHeight = fullHeight;
  23549. this.view.offsetX = x;
  23550. this.view.offsetY = y;
  23551. this.view.width = width;
  23552. this.view.height = height;
  23553. this.updateProjectionMatrix();
  23554. },
  23555. clearViewOffset: function clearViewOffset() {
  23556. if (this.view !== null) {
  23557. this.view.enabled = false;
  23558. }
  23559. this.updateProjectionMatrix();
  23560. },
  23561. updateProjectionMatrix: function updateProjectionMatrix() {
  23562. var dx = (this.right - this.left) / (2 * this.zoom);
  23563. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23564. var cx = (this.right + this.left) / 2;
  23565. var cy = (this.top + this.bottom) / 2;
  23566. var left = cx - dx;
  23567. var right = cx + dx;
  23568. var top = cy + dy;
  23569. var bottom = cy - dy;
  23570. if (this.view !== null && this.view.enabled) {
  23571. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23572. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23573. left += scaleW * this.view.offsetX;
  23574. right = left + scaleW * this.view.width;
  23575. top -= scaleH * this.view.offsetY;
  23576. bottom = top - scaleH * this.view.height;
  23577. }
  23578. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23579. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23580. },
  23581. toJSON: function toJSON(meta) {
  23582. var data = Object3D.prototype.toJSON.call(this, meta);
  23583. data.object.zoom = this.zoom;
  23584. data.object.left = this.left;
  23585. data.object.right = this.right;
  23586. data.object.top = this.top;
  23587. data.object.bottom = this.bottom;
  23588. data.object.near = this.near;
  23589. data.object.far = this.far;
  23590. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23591. return data;
  23592. }
  23593. });
  23594. function DirectionalLightShadow() {
  23595. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23596. }
  23597. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23598. constructor: DirectionalLightShadow,
  23599. isDirectionalLightShadow: true,
  23600. updateMatrices: function updateMatrices(light) {
  23601. LightShadow.prototype.updateMatrices.call(this, light);
  23602. }
  23603. });
  23604. function DirectionalLight(color, intensity) {
  23605. Light.call(this, color, intensity);
  23606. this.type = 'DirectionalLight';
  23607. this.position.copy(Object3D.DefaultUp);
  23608. this.updateMatrix();
  23609. this.target = new Object3D();
  23610. this.shadow = new DirectionalLightShadow();
  23611. }
  23612. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23613. constructor: DirectionalLight,
  23614. isDirectionalLight: true,
  23615. copy: function copy(source) {
  23616. Light.prototype.copy.call(this, source);
  23617. this.target = source.target.clone();
  23618. this.shadow = source.shadow.clone();
  23619. return this;
  23620. }
  23621. });
  23622. function AmbientLight(color, intensity) {
  23623. Light.call(this, color, intensity);
  23624. this.type = 'AmbientLight';
  23625. }
  23626. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23627. constructor: AmbientLight,
  23628. isAmbientLight: true
  23629. });
  23630. function RectAreaLight(color, intensity, width, height) {
  23631. Light.call(this, color, intensity);
  23632. this.type = 'RectAreaLight';
  23633. this.width = width !== undefined ? width : 10;
  23634. this.height = height !== undefined ? height : 10;
  23635. }
  23636. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23637. constructor: RectAreaLight,
  23638. isRectAreaLight: true,
  23639. copy: function copy(source) {
  23640. Light.prototype.copy.call(this, source);
  23641. this.width = source.width;
  23642. this.height = source.height;
  23643. return this;
  23644. },
  23645. toJSON: function toJSON(meta) {
  23646. var data = Light.prototype.toJSON.call(this, meta);
  23647. data.object.width = this.width;
  23648. data.object.height = this.height;
  23649. return data;
  23650. }
  23651. });
  23652. /**
  23653. * Primary reference:
  23654. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23655. *
  23656. * Secondary reference:
  23657. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23658. */
  23659. // 3-band SH defined by 9 coefficients
  23660. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23661. function SphericalHarmonics3() {
  23662. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23663. value: true
  23664. });
  23665. this.coefficients = [];
  23666. for (var i = 0; i < 9; i++) {
  23667. this.coefficients.push(new Vector3());
  23668. }
  23669. }
  23670. var _proto = SphericalHarmonics3.prototype;
  23671. _proto.set = function set(coefficients) {
  23672. for (var i = 0; i < 9; i++) {
  23673. this.coefficients[i].copy(coefficients[i]);
  23674. }
  23675. return this;
  23676. };
  23677. _proto.zero = function zero() {
  23678. for (var i = 0; i < 9; i++) {
  23679. this.coefficients[i].set(0, 0, 0);
  23680. }
  23681. return this;
  23682. } // get the radiance in the direction of the normal
  23683. // target is a Vector3
  23684. ;
  23685. _proto.getAt = function getAt(normal, target) {
  23686. // normal is assumed to be unit length
  23687. var x = normal.x,
  23688. y = normal.y,
  23689. z = normal.z;
  23690. var coeff = this.coefficients; // band 0
  23691. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23692. target.addScaledVector(coeff[1], 0.488603 * y);
  23693. target.addScaledVector(coeff[2], 0.488603 * z);
  23694. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23695. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23696. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23697. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23698. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23699. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23700. return target;
  23701. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23702. // target is a Vector3
  23703. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23704. ;
  23705. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23706. // normal is assumed to be unit length
  23707. var x = normal.x,
  23708. y = normal.y,
  23709. z = normal.z;
  23710. var coeff = this.coefficients; // band 0
  23711. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23712. // band 1
  23713. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23714. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23715. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23716. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23717. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23718. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23719. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23720. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23721. return target;
  23722. };
  23723. _proto.add = function add(sh) {
  23724. for (var i = 0; i < 9; i++) {
  23725. this.coefficients[i].add(sh.coefficients[i]);
  23726. }
  23727. return this;
  23728. };
  23729. _proto.addScaledSH = function addScaledSH(sh, s) {
  23730. for (var i = 0; i < 9; i++) {
  23731. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23732. }
  23733. return this;
  23734. };
  23735. _proto.scale = function scale(s) {
  23736. for (var i = 0; i < 9; i++) {
  23737. this.coefficients[i].multiplyScalar(s);
  23738. }
  23739. return this;
  23740. };
  23741. _proto.lerp = function lerp(sh, alpha) {
  23742. for (var i = 0; i < 9; i++) {
  23743. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23744. }
  23745. return this;
  23746. };
  23747. _proto.equals = function equals(sh) {
  23748. for (var i = 0; i < 9; i++) {
  23749. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23750. return false;
  23751. }
  23752. }
  23753. return true;
  23754. };
  23755. _proto.copy = function copy(sh) {
  23756. return this.set(sh.coefficients);
  23757. };
  23758. _proto.clone = function clone() {
  23759. return new this.constructor().copy(this);
  23760. };
  23761. _proto.fromArray = function fromArray(array, offset) {
  23762. if (offset === void 0) {
  23763. offset = 0;
  23764. }
  23765. var coefficients = this.coefficients;
  23766. for (var i = 0; i < 9; i++) {
  23767. coefficients[i].fromArray(array, offset + i * 3);
  23768. }
  23769. return this;
  23770. };
  23771. _proto.toArray = function toArray(array, offset) {
  23772. if (array === void 0) {
  23773. array = [];
  23774. }
  23775. if (offset === void 0) {
  23776. offset = 0;
  23777. }
  23778. var coefficients = this.coefficients;
  23779. for (var i = 0; i < 9; i++) {
  23780. coefficients[i].toArray(array, offset + i * 3);
  23781. }
  23782. return array;
  23783. } // evaluate the basis functions
  23784. // shBasis is an Array[ 9 ]
  23785. ;
  23786. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23787. // normal is assumed to be unit length
  23788. var x = normal.x,
  23789. y = normal.y,
  23790. z = normal.z; // band 0
  23791. shBasis[0] = 0.282095; // band 1
  23792. shBasis[1] = 0.488603 * y;
  23793. shBasis[2] = 0.488603 * z;
  23794. shBasis[3] = 0.488603 * x; // band 2
  23795. shBasis[4] = 1.092548 * x * y;
  23796. shBasis[5] = 1.092548 * y * z;
  23797. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23798. shBasis[7] = 1.092548 * x * z;
  23799. shBasis[8] = 0.546274 * (x * x - y * y);
  23800. };
  23801. return SphericalHarmonics3;
  23802. }();
  23803. function LightProbe(sh, intensity) {
  23804. Light.call(this, undefined, intensity);
  23805. this.type = 'LightProbe';
  23806. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23807. }
  23808. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23809. constructor: LightProbe,
  23810. isLightProbe: true,
  23811. copy: function copy(source) {
  23812. Light.prototype.copy.call(this, source);
  23813. this.sh.copy(source.sh);
  23814. return this;
  23815. },
  23816. fromJSON: function fromJSON(json) {
  23817. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23818. this.sh.fromArray(json.sh);
  23819. return this;
  23820. },
  23821. toJSON: function toJSON(meta) {
  23822. var data = Light.prototype.toJSON.call(this, meta);
  23823. data.object.sh = this.sh.toArray();
  23824. return data;
  23825. }
  23826. });
  23827. var MaterialLoader = /*#__PURE__*/function (_Loader) {
  23828. _inheritsLoose(MaterialLoader, _Loader);
  23829. function MaterialLoader(manager) {
  23830. var _this;
  23831. _this = _Loader.call(this, manager) || this;
  23832. _this.textures = {};
  23833. return _this;
  23834. }
  23835. var _proto = MaterialLoader.prototype;
  23836. _proto.load = function load(url, onLoad, onProgress, onError) {
  23837. var scope = this;
  23838. var loader = new FileLoader(scope.manager);
  23839. loader.setPath(scope.path);
  23840. loader.setRequestHeader(scope.requestHeader);
  23841. loader.setWithCredentials(scope.withCredentials);
  23842. loader.load(url, function (text) {
  23843. try {
  23844. onLoad(scope.parse(JSON.parse(text)));
  23845. } catch (e) {
  23846. if (onError) {
  23847. onError(e);
  23848. } else {
  23849. console.error(e);
  23850. }
  23851. scope.manager.itemError(url);
  23852. }
  23853. }, onProgress, onError);
  23854. };
  23855. _proto.parse = function parse(json) {
  23856. var textures = this.textures;
  23857. function getTexture(name) {
  23858. if (textures[name] === undefined) {
  23859. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23860. }
  23861. return textures[name];
  23862. }
  23863. var material = new Materials[json.type]();
  23864. if (json.uuid !== undefined) material.uuid = json.uuid;
  23865. if (json.name !== undefined) material.name = json.name;
  23866. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  23867. if (json.roughness !== undefined) material.roughness = json.roughness;
  23868. if (json.metalness !== undefined) material.metalness = json.metalness;
  23869. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23870. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  23871. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  23872. if (json.shininess !== undefined) material.shininess = json.shininess;
  23873. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23874. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23875. if (json.fog !== undefined) material.fog = json.fog;
  23876. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23877. if (json.blending !== undefined) material.blending = json.blending;
  23878. if (json.combine !== undefined) material.combine = json.combine;
  23879. if (json.side !== undefined) material.side = json.side;
  23880. if (json.opacity !== undefined) material.opacity = json.opacity;
  23881. if (json.transparent !== undefined) material.transparent = json.transparent;
  23882. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23883. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23884. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23885. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23886. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23887. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23888. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23889. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23890. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23891. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23892. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23893. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23894. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23895. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23896. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23897. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23898. if (json.rotation !== undefined) material.rotation = json.rotation;
  23899. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23900. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23901. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23902. if (json.scale !== undefined) material.scale = json.scale;
  23903. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23904. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23905. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23906. if (json.skinning !== undefined) material.skinning = json.skinning;
  23907. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23908. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23909. if (json.dithering !== undefined) material.dithering = json.dithering;
  23910. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23911. if (json.visible !== undefined) material.visible = json.visible;
  23912. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23913. if (json.userData !== undefined) material.userData = json.userData;
  23914. if (json.vertexColors !== undefined) {
  23915. if (typeof json.vertexColors === 'number') {
  23916. material.vertexColors = json.vertexColors > 0 ? true : false;
  23917. } else {
  23918. material.vertexColors = json.vertexColors;
  23919. }
  23920. } // Shader Material
  23921. if (json.uniforms !== undefined) {
  23922. for (var name in json.uniforms) {
  23923. var uniform = json.uniforms[name];
  23924. material.uniforms[name] = {};
  23925. switch (uniform.type) {
  23926. case 't':
  23927. material.uniforms[name].value = getTexture(uniform.value);
  23928. break;
  23929. case 'c':
  23930. material.uniforms[name].value = new Color().setHex(uniform.value);
  23931. break;
  23932. case 'v2':
  23933. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23934. break;
  23935. case 'v3':
  23936. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23937. break;
  23938. case 'v4':
  23939. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23940. break;
  23941. case 'm3':
  23942. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23943. break;
  23944. case 'm4':
  23945. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23946. break;
  23947. default:
  23948. material.uniforms[name].value = uniform.value;
  23949. }
  23950. }
  23951. }
  23952. if (json.defines !== undefined) material.defines = json.defines;
  23953. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23954. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23955. if (json.extensions !== undefined) {
  23956. for (var key in json.extensions) {
  23957. material.extensions[key] = json.extensions[key];
  23958. }
  23959. } // Deprecated
  23960. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23961. // for PointsMaterial
  23962. if (json.size !== undefined) material.size = json.size;
  23963. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23964. if (json.map !== undefined) material.map = getTexture(json.map);
  23965. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23966. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23967. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23968. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23969. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23970. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23971. if (json.normalScale !== undefined) {
  23972. var normalScale = json.normalScale;
  23973. if (Array.isArray(normalScale) === false) {
  23974. // Blender exporter used to export a scalar. See #7459
  23975. normalScale = [normalScale, normalScale];
  23976. }
  23977. material.normalScale = new Vector2().fromArray(normalScale);
  23978. }
  23979. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23980. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23981. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23982. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23983. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23984. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23985. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23986. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23987. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23988. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23989. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23990. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23991. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23992. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23993. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23994. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23995. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23996. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23997. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23998. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23999. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  24000. if (json.transmission !== undefined) material.transmission = json.transmission;
  24001. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  24002. return material;
  24003. };
  24004. _proto.setTextures = function setTextures(value) {
  24005. this.textures = value;
  24006. return this;
  24007. };
  24008. return MaterialLoader;
  24009. }(Loader);
  24010. var LoaderUtils = {
  24011. decodeText: function decodeText(array) {
  24012. if (typeof TextDecoder !== 'undefined') {
  24013. return new TextDecoder().decode(array);
  24014. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24015. // throws a "maximum call stack size exceeded" error for large arrays.
  24016. var s = '';
  24017. for (var i = 0, il = array.length; i < il; i++) {
  24018. // Implicitly assumes little-endian.
  24019. s += String.fromCharCode(array[i]);
  24020. }
  24021. try {
  24022. // merges multi-byte utf-8 characters.
  24023. return decodeURIComponent(escape(s));
  24024. } catch (e) {
  24025. // see #16358
  24026. return s;
  24027. }
  24028. },
  24029. extractUrlBase: function extractUrlBase(url) {
  24030. var index = url.lastIndexOf('/');
  24031. if (index === -1) return './';
  24032. return url.substr(0, index + 1);
  24033. }
  24034. };
  24035. function InstancedBufferGeometry() {
  24036. BufferGeometry.call(this);
  24037. this.type = 'InstancedBufferGeometry';
  24038. this.instanceCount = Infinity;
  24039. }
  24040. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  24041. constructor: InstancedBufferGeometry,
  24042. isInstancedBufferGeometry: true,
  24043. copy: function copy(source) {
  24044. BufferGeometry.prototype.copy.call(this, source);
  24045. this.instanceCount = source.instanceCount;
  24046. return this;
  24047. },
  24048. clone: function clone() {
  24049. return new this.constructor().copy(this);
  24050. },
  24051. toJSON: function toJSON() {
  24052. var data = BufferGeometry.prototype.toJSON.call(this);
  24053. data.instanceCount = this.instanceCount;
  24054. data.isInstancedBufferGeometry = true;
  24055. return data;
  24056. }
  24057. });
  24058. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  24059. if (typeof normalized === 'number') {
  24060. meshPerAttribute = normalized;
  24061. normalized = false;
  24062. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  24063. }
  24064. BufferAttribute.call(this, array, itemSize, normalized);
  24065. this.meshPerAttribute = meshPerAttribute || 1;
  24066. }
  24067. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  24068. constructor: InstancedBufferAttribute,
  24069. isInstancedBufferAttribute: true,
  24070. copy: function copy(source) {
  24071. BufferAttribute.prototype.copy.call(this, source);
  24072. this.meshPerAttribute = source.meshPerAttribute;
  24073. return this;
  24074. },
  24075. toJSON: function toJSON() {
  24076. var data = BufferAttribute.prototype.toJSON.call(this);
  24077. data.meshPerAttribute = this.meshPerAttribute;
  24078. data.isInstancedBufferAttribute = true;
  24079. return data;
  24080. }
  24081. });
  24082. var BufferGeometryLoader = /*#__PURE__*/function (_Loader) {
  24083. _inheritsLoose(BufferGeometryLoader, _Loader);
  24084. function BufferGeometryLoader(manager) {
  24085. return _Loader.call(this, manager) || this;
  24086. }
  24087. var _proto = BufferGeometryLoader.prototype;
  24088. _proto.load = function load(url, onLoad, onProgress, onError) {
  24089. var scope = this;
  24090. var loader = new FileLoader(scope.manager);
  24091. loader.setPath(scope.path);
  24092. loader.setRequestHeader(scope.requestHeader);
  24093. loader.setWithCredentials(scope.withCredentials);
  24094. loader.load(url, function (text) {
  24095. try {
  24096. onLoad(scope.parse(JSON.parse(text)));
  24097. } catch (e) {
  24098. if (onError) {
  24099. onError(e);
  24100. } else {
  24101. console.error(e);
  24102. }
  24103. scope.manager.itemError(url);
  24104. }
  24105. }, onProgress, onError);
  24106. };
  24107. _proto.parse = function parse(json) {
  24108. var interleavedBufferMap = {};
  24109. var arrayBufferMap = {};
  24110. function getInterleavedBuffer(json, uuid) {
  24111. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  24112. var interleavedBuffers = json.interleavedBuffers;
  24113. var interleavedBuffer = interleavedBuffers[uuid];
  24114. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  24115. var array = getTypedArray(interleavedBuffer.type, buffer);
  24116. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  24117. ib.uuid = interleavedBuffer.uuid;
  24118. interleavedBufferMap[uuid] = ib;
  24119. return ib;
  24120. }
  24121. function getArrayBuffer(json, uuid) {
  24122. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  24123. var arrayBuffers = json.arrayBuffers;
  24124. var arrayBuffer = arrayBuffers[uuid];
  24125. var ab = new Uint32Array(arrayBuffer).buffer;
  24126. arrayBufferMap[uuid] = ab;
  24127. return ab;
  24128. }
  24129. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24130. var index = json.data.index;
  24131. if (index !== undefined) {
  24132. var typedArray = getTypedArray(index.type, index.array);
  24133. geometry.setIndex(new BufferAttribute(typedArray, 1));
  24134. }
  24135. var attributes = json.data.attributes;
  24136. for (var key in attributes) {
  24137. var attribute = attributes[key];
  24138. var bufferAttribute = void 0;
  24139. if (attribute.isInterleavedBufferAttribute) {
  24140. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  24141. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  24142. } else {
  24143. var _typedArray = getTypedArray(attribute.type, attribute.array);
  24144. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24145. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  24146. }
  24147. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  24148. geometry.setAttribute(key, bufferAttribute);
  24149. }
  24150. var morphAttributes = json.data.morphAttributes;
  24151. if (morphAttributes) {
  24152. for (var _key in morphAttributes) {
  24153. var attributeArray = morphAttributes[_key];
  24154. var array = [];
  24155. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24156. var _attribute = attributeArray[i];
  24157. var _bufferAttribute = void 0;
  24158. if (_attribute.isInterleavedBufferAttribute) {
  24159. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24160. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24161. } else {
  24162. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24163. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24164. }
  24165. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24166. array.push(_bufferAttribute);
  24167. }
  24168. geometry.morphAttributes[_key] = array;
  24169. }
  24170. }
  24171. var morphTargetsRelative = json.data.morphTargetsRelative;
  24172. if (morphTargetsRelative) {
  24173. geometry.morphTargetsRelative = true;
  24174. }
  24175. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24176. if (groups !== undefined) {
  24177. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24178. var group = groups[_i];
  24179. geometry.addGroup(group.start, group.count, group.materialIndex);
  24180. }
  24181. }
  24182. var boundingSphere = json.data.boundingSphere;
  24183. if (boundingSphere !== undefined) {
  24184. var center = new Vector3();
  24185. if (boundingSphere.center !== undefined) {
  24186. center.fromArray(boundingSphere.center);
  24187. }
  24188. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24189. }
  24190. if (json.name) geometry.name = json.name;
  24191. if (json.userData) geometry.userData = json.userData;
  24192. return geometry;
  24193. };
  24194. return BufferGeometryLoader;
  24195. }(Loader);
  24196. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24197. _inheritsLoose(ObjectLoader, _Loader);
  24198. function ObjectLoader(manager) {
  24199. return _Loader.call(this, manager) || this;
  24200. }
  24201. var _proto = ObjectLoader.prototype;
  24202. _proto.load = function load(url, onLoad, onProgress, onError) {
  24203. var scope = this;
  24204. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24205. this.resourcePath = this.resourcePath || path;
  24206. var loader = new FileLoader(this.manager);
  24207. loader.setPath(this.path);
  24208. loader.setRequestHeader(this.requestHeader);
  24209. loader.setWithCredentials(this.withCredentials);
  24210. loader.load(url, function (text) {
  24211. var json = null;
  24212. try {
  24213. json = JSON.parse(text);
  24214. } catch (error) {
  24215. if (onError !== undefined) onError(error);
  24216. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24217. return;
  24218. }
  24219. var metadata = json.metadata;
  24220. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24221. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24222. return;
  24223. }
  24224. scope.parse(json, onLoad);
  24225. }, onProgress, onError);
  24226. };
  24227. _proto.parse = function parse(json, onLoad) {
  24228. var animations = this.parseAnimations(json.animations);
  24229. var shapes = this.parseShapes(json.shapes);
  24230. var geometries = this.parseGeometries(json.geometries, shapes);
  24231. var images = this.parseImages(json.images, function () {
  24232. if (onLoad !== undefined) onLoad(object);
  24233. });
  24234. var textures = this.parseTextures(json.textures, images);
  24235. var materials = this.parseMaterials(json.materials, textures);
  24236. var object = this.parseObject(json.object, geometries, materials, animations);
  24237. var skeletons = this.parseSkeletons(json.skeletons, object);
  24238. this.bindSkeletons(object, skeletons); //
  24239. if (onLoad !== undefined) {
  24240. var hasImages = false;
  24241. for (var uuid in images) {
  24242. if (images[uuid] instanceof HTMLImageElement) {
  24243. hasImages = true;
  24244. break;
  24245. }
  24246. }
  24247. if (hasImages === false) onLoad(object);
  24248. }
  24249. return object;
  24250. };
  24251. _proto.parseShapes = function parseShapes(json) {
  24252. var shapes = {};
  24253. if (json !== undefined) {
  24254. for (var i = 0, l = json.length; i < l; i++) {
  24255. var shape = new Shape().fromJSON(json[i]);
  24256. shapes[shape.uuid] = shape;
  24257. }
  24258. }
  24259. return shapes;
  24260. };
  24261. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24262. var skeletons = {};
  24263. var bones = {}; // generate bone lookup table
  24264. object.traverse(function (child) {
  24265. if (child.isBone) bones[child.uuid] = child;
  24266. }); // create skeletons
  24267. if (json !== undefined) {
  24268. for (var i = 0, l = json.length; i < l; i++) {
  24269. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24270. skeletons[skeleton.uuid] = skeleton;
  24271. }
  24272. }
  24273. return skeletons;
  24274. };
  24275. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24276. var geometries = {};
  24277. var geometryShapes;
  24278. if (json !== undefined) {
  24279. var bufferGeometryLoader = new BufferGeometryLoader();
  24280. for (var i = 0, l = json.length; i < l; i++) {
  24281. var geometry = void 0;
  24282. var data = json[i];
  24283. switch (data.type) {
  24284. case 'PlaneGeometry':
  24285. case 'PlaneBufferGeometry':
  24286. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24287. break;
  24288. case 'BoxGeometry':
  24289. case 'BoxBufferGeometry':
  24290. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24291. break;
  24292. case 'CircleGeometry':
  24293. case 'CircleBufferGeometry':
  24294. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24295. break;
  24296. case 'CylinderGeometry':
  24297. case 'CylinderBufferGeometry':
  24298. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24299. break;
  24300. case 'ConeGeometry':
  24301. case 'ConeBufferGeometry':
  24302. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24303. break;
  24304. case 'SphereGeometry':
  24305. case 'SphereBufferGeometry':
  24306. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24307. break;
  24308. case 'DodecahedronGeometry':
  24309. case 'DodecahedronBufferGeometry':
  24310. case 'IcosahedronGeometry':
  24311. case 'IcosahedronBufferGeometry':
  24312. case 'OctahedronGeometry':
  24313. case 'OctahedronBufferGeometry':
  24314. case 'TetrahedronGeometry':
  24315. case 'TetrahedronBufferGeometry':
  24316. geometry = new Geometries[data.type](data.radius, data.detail);
  24317. break;
  24318. case 'RingGeometry':
  24319. case 'RingBufferGeometry':
  24320. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24321. break;
  24322. case 'TorusGeometry':
  24323. case 'TorusBufferGeometry':
  24324. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24325. break;
  24326. case 'TorusKnotGeometry':
  24327. case 'TorusKnotBufferGeometry':
  24328. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24329. break;
  24330. case 'TubeGeometry':
  24331. case 'TubeBufferGeometry':
  24332. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24333. // User defined curves or instances of CurvePath will not be deserialized.
  24334. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24335. break;
  24336. case 'LatheGeometry':
  24337. case 'LatheBufferGeometry':
  24338. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24339. break;
  24340. case 'PolyhedronGeometry':
  24341. case 'PolyhedronBufferGeometry':
  24342. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24343. break;
  24344. case 'ShapeGeometry':
  24345. case 'ShapeBufferGeometry':
  24346. geometryShapes = [];
  24347. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24348. var shape = shapes[data.shapes[j]];
  24349. geometryShapes.push(shape);
  24350. }
  24351. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24352. break;
  24353. case 'ExtrudeGeometry':
  24354. case 'ExtrudeBufferGeometry':
  24355. geometryShapes = [];
  24356. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24357. var _shape = shapes[data.shapes[_j]];
  24358. geometryShapes.push(_shape);
  24359. }
  24360. var extrudePath = data.options.extrudePath;
  24361. if (extrudePath !== undefined) {
  24362. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24363. }
  24364. geometry = new Geometries[data.type](geometryShapes, data.options);
  24365. break;
  24366. case 'BufferGeometry':
  24367. case 'InstancedBufferGeometry':
  24368. geometry = bufferGeometryLoader.parse(data);
  24369. break;
  24370. case 'Geometry':
  24371. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24372. break;
  24373. default:
  24374. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24375. continue;
  24376. }
  24377. geometry.uuid = data.uuid;
  24378. if (data.name !== undefined) geometry.name = data.name;
  24379. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24380. geometries[data.uuid] = geometry;
  24381. }
  24382. }
  24383. return geometries;
  24384. };
  24385. _proto.parseMaterials = function parseMaterials(json, textures) {
  24386. var cache = {}; // MultiMaterial
  24387. var materials = {};
  24388. if (json !== undefined) {
  24389. var loader = new MaterialLoader();
  24390. loader.setTextures(textures);
  24391. for (var i = 0, l = json.length; i < l; i++) {
  24392. var data = json[i];
  24393. if (data.type === 'MultiMaterial') {
  24394. // Deprecated
  24395. var array = [];
  24396. for (var j = 0; j < data.materials.length; j++) {
  24397. var material = data.materials[j];
  24398. if (cache[material.uuid] === undefined) {
  24399. cache[material.uuid] = loader.parse(material);
  24400. }
  24401. array.push(cache[material.uuid]);
  24402. }
  24403. materials[data.uuid] = array;
  24404. } else {
  24405. if (cache[data.uuid] === undefined) {
  24406. cache[data.uuid] = loader.parse(data);
  24407. }
  24408. materials[data.uuid] = cache[data.uuid];
  24409. }
  24410. }
  24411. }
  24412. return materials;
  24413. };
  24414. _proto.parseAnimations = function parseAnimations(json) {
  24415. var animations = {};
  24416. if (json !== undefined) {
  24417. for (var i = 0; i < json.length; i++) {
  24418. var data = json[i];
  24419. var clip = AnimationClip.parse(data);
  24420. animations[clip.uuid] = clip;
  24421. }
  24422. }
  24423. return animations;
  24424. };
  24425. _proto.parseImages = function parseImages(json, onLoad) {
  24426. var scope = this;
  24427. var images = {};
  24428. var loader;
  24429. function loadImage(url) {
  24430. scope.manager.itemStart(url);
  24431. return loader.load(url, function () {
  24432. scope.manager.itemEnd(url);
  24433. }, undefined, function () {
  24434. scope.manager.itemError(url);
  24435. scope.manager.itemEnd(url);
  24436. });
  24437. }
  24438. function deserializeImage(image) {
  24439. if (typeof image === 'string') {
  24440. var url = image;
  24441. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24442. return loadImage(path);
  24443. } else {
  24444. if (image.data) {
  24445. return {
  24446. data: getTypedArray(image.type, image.data),
  24447. width: image.width,
  24448. height: image.height
  24449. };
  24450. } else {
  24451. return null;
  24452. }
  24453. }
  24454. }
  24455. if (json !== undefined && json.length > 0) {
  24456. var manager = new LoadingManager(onLoad);
  24457. loader = new ImageLoader(manager);
  24458. loader.setCrossOrigin(this.crossOrigin);
  24459. for (var i = 0, il = json.length; i < il; i++) {
  24460. var image = json[i];
  24461. var url = image.url;
  24462. if (Array.isArray(url)) {
  24463. // load array of images e.g CubeTexture
  24464. images[image.uuid] = [];
  24465. for (var j = 0, jl = url.length; j < jl; j++) {
  24466. var currentUrl = url[j];
  24467. var deserializedImage = deserializeImage(currentUrl);
  24468. if (deserializedImage !== null) {
  24469. if (deserializedImage instanceof HTMLImageElement) {
  24470. images[image.uuid].push(deserializedImage);
  24471. } else {
  24472. // special case: handle array of data textures for cube textures
  24473. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24474. }
  24475. }
  24476. }
  24477. } else {
  24478. // load single image
  24479. var _deserializedImage = deserializeImage(image.url);
  24480. if (_deserializedImage !== null) {
  24481. images[image.uuid] = _deserializedImage;
  24482. }
  24483. }
  24484. }
  24485. }
  24486. return images;
  24487. };
  24488. _proto.parseTextures = function parseTextures(json, images) {
  24489. function parseConstant(value, type) {
  24490. if (typeof value === 'number') return value;
  24491. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24492. return type[value];
  24493. }
  24494. var textures = {};
  24495. if (json !== undefined) {
  24496. for (var i = 0, l = json.length; i < l; i++) {
  24497. var data = json[i];
  24498. if (data.image === undefined) {
  24499. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24500. }
  24501. if (images[data.image] === undefined) {
  24502. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24503. }
  24504. var texture = void 0;
  24505. var image = images[data.image];
  24506. if (Array.isArray(image)) {
  24507. texture = new CubeTexture(image);
  24508. if (image.length === 6) texture.needsUpdate = true;
  24509. } else {
  24510. if (image && image.data) {
  24511. texture = new DataTexture(image.data, image.width, image.height);
  24512. } else {
  24513. texture = new Texture(image);
  24514. }
  24515. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24516. }
  24517. texture.uuid = data.uuid;
  24518. if (data.name !== undefined) texture.name = data.name;
  24519. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24520. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24521. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24522. if (data.center !== undefined) texture.center.fromArray(data.center);
  24523. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24524. if (data.wrap !== undefined) {
  24525. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24526. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24527. }
  24528. if (data.format !== undefined) texture.format = data.format;
  24529. if (data.type !== undefined) texture.type = data.type;
  24530. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24531. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24532. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24533. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24534. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24535. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24536. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24537. textures[data.uuid] = texture;
  24538. }
  24539. }
  24540. return textures;
  24541. };
  24542. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  24543. var object;
  24544. function getGeometry(name) {
  24545. if (geometries[name] === undefined) {
  24546. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24547. }
  24548. return geometries[name];
  24549. }
  24550. function getMaterial(name) {
  24551. if (name === undefined) return undefined;
  24552. if (Array.isArray(name)) {
  24553. var array = [];
  24554. for (var i = 0, l = name.length; i < l; i++) {
  24555. var uuid = name[i];
  24556. if (materials[uuid] === undefined) {
  24557. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24558. }
  24559. array.push(materials[uuid]);
  24560. }
  24561. return array;
  24562. }
  24563. if (materials[name] === undefined) {
  24564. console.warn('THREE.ObjectLoader: Undefined material', name);
  24565. }
  24566. return materials[name];
  24567. }
  24568. var geometry, material;
  24569. switch (data.type) {
  24570. case 'Scene':
  24571. object = new Scene();
  24572. if (data.background !== undefined) {
  24573. if (Number.isInteger(data.background)) {
  24574. object.background = new Color(data.background);
  24575. }
  24576. }
  24577. if (data.fog !== undefined) {
  24578. if (data.fog.type === 'Fog') {
  24579. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24580. } else if (data.fog.type === 'FogExp2') {
  24581. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24582. }
  24583. }
  24584. break;
  24585. case 'PerspectiveCamera':
  24586. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24587. if (data.focus !== undefined) object.focus = data.focus;
  24588. if (data.zoom !== undefined) object.zoom = data.zoom;
  24589. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24590. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24591. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24592. break;
  24593. case 'OrthographicCamera':
  24594. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24595. if (data.zoom !== undefined) object.zoom = data.zoom;
  24596. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24597. break;
  24598. case 'AmbientLight':
  24599. object = new AmbientLight(data.color, data.intensity);
  24600. break;
  24601. case 'DirectionalLight':
  24602. object = new DirectionalLight(data.color, data.intensity);
  24603. break;
  24604. case 'PointLight':
  24605. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24606. break;
  24607. case 'RectAreaLight':
  24608. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24609. break;
  24610. case 'SpotLight':
  24611. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24612. break;
  24613. case 'HemisphereLight':
  24614. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24615. break;
  24616. case 'LightProbe':
  24617. object = new LightProbe().fromJSON(data);
  24618. break;
  24619. case 'SkinnedMesh':
  24620. geometry = getGeometry(data.geometry);
  24621. material = getMaterial(data.material);
  24622. object = new SkinnedMesh(geometry, material);
  24623. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24624. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24625. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24626. break;
  24627. case 'Mesh':
  24628. geometry = getGeometry(data.geometry);
  24629. material = getMaterial(data.material);
  24630. object = new Mesh(geometry, material);
  24631. break;
  24632. case 'InstancedMesh':
  24633. geometry = getGeometry(data.geometry);
  24634. material = getMaterial(data.material);
  24635. var count = data.count;
  24636. var instanceMatrix = data.instanceMatrix;
  24637. object = new InstancedMesh(geometry, material, count);
  24638. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24639. break;
  24640. case 'LOD':
  24641. object = new LOD();
  24642. break;
  24643. case 'Line':
  24644. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  24645. break;
  24646. case 'LineLoop':
  24647. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24648. break;
  24649. case 'LineSegments':
  24650. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24651. break;
  24652. case 'PointCloud':
  24653. case 'Points':
  24654. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24655. break;
  24656. case 'Sprite':
  24657. object = new Sprite(getMaterial(data.material));
  24658. break;
  24659. case 'Group':
  24660. object = new Group();
  24661. break;
  24662. case 'Bone':
  24663. object = new Bone();
  24664. break;
  24665. default:
  24666. object = new Object3D();
  24667. }
  24668. object.uuid = data.uuid;
  24669. if (data.name !== undefined) object.name = data.name;
  24670. if (data.matrix !== undefined) {
  24671. object.matrix.fromArray(data.matrix);
  24672. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24673. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24674. } else {
  24675. if (data.position !== undefined) object.position.fromArray(data.position);
  24676. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24677. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24678. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24679. }
  24680. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24681. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24682. if (data.shadow) {
  24683. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24684. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24685. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24686. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24687. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24688. }
  24689. if (data.visible !== undefined) object.visible = data.visible;
  24690. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24691. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24692. if (data.userData !== undefined) object.userData = data.userData;
  24693. if (data.layers !== undefined) object.layers.mask = data.layers;
  24694. if (data.children !== undefined) {
  24695. var children = data.children;
  24696. for (var i = 0; i < children.length; i++) {
  24697. object.add(this.parseObject(children[i], geometries, materials, animations));
  24698. }
  24699. }
  24700. if (data.animations !== undefined) {
  24701. var objectAnimations = data.animations;
  24702. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24703. var uuid = objectAnimations[_i];
  24704. object.animations.push(animations[uuid]);
  24705. }
  24706. }
  24707. if (data.type === 'LOD') {
  24708. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24709. var levels = data.levels;
  24710. for (var l = 0; l < levels.length; l++) {
  24711. var level = levels[l];
  24712. var child = object.getObjectByProperty('uuid', level.object);
  24713. if (child !== undefined) {
  24714. object.addLevel(child, level.distance);
  24715. }
  24716. }
  24717. }
  24718. return object;
  24719. };
  24720. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24721. if (Object.keys(skeletons).length === 0) return;
  24722. object.traverse(function (child) {
  24723. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24724. var skeleton = skeletons[child.skeleton];
  24725. if (skeleton === undefined) {
  24726. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24727. } else {
  24728. child.bind(skeleton, child.bindMatrix);
  24729. }
  24730. }
  24731. });
  24732. }
  24733. /* DEPRECATED */
  24734. ;
  24735. _proto.setTexturePath = function setTexturePath(value) {
  24736. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24737. return this.setResourcePath(value);
  24738. };
  24739. return ObjectLoader;
  24740. }(Loader);
  24741. var TEXTURE_MAPPING = {
  24742. UVMapping: UVMapping,
  24743. CubeReflectionMapping: CubeReflectionMapping,
  24744. CubeRefractionMapping: CubeRefractionMapping,
  24745. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24746. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24747. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24748. CubeUVRefractionMapping: CubeUVRefractionMapping
  24749. };
  24750. var TEXTURE_WRAPPING = {
  24751. RepeatWrapping: RepeatWrapping,
  24752. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24753. MirroredRepeatWrapping: MirroredRepeatWrapping
  24754. };
  24755. var TEXTURE_FILTER = {
  24756. NearestFilter: NearestFilter,
  24757. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24758. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24759. LinearFilter: LinearFilter,
  24760. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24761. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24762. };
  24763. function ImageBitmapLoader(manager) {
  24764. if (typeof createImageBitmap === 'undefined') {
  24765. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24766. }
  24767. if (typeof fetch === 'undefined') {
  24768. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24769. }
  24770. Loader.call(this, manager);
  24771. this.options = {
  24772. premultiplyAlpha: 'none'
  24773. };
  24774. }
  24775. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24776. constructor: ImageBitmapLoader,
  24777. isImageBitmapLoader: true,
  24778. setOptions: function setOptions(options) {
  24779. this.options = options;
  24780. return this;
  24781. },
  24782. load: function load(url, onLoad, onProgress, onError) {
  24783. if (url === undefined) url = '';
  24784. if (this.path !== undefined) url = this.path + url;
  24785. url = this.manager.resolveURL(url);
  24786. var scope = this;
  24787. var cached = Cache.get(url);
  24788. if (cached !== undefined) {
  24789. scope.manager.itemStart(url);
  24790. setTimeout(function () {
  24791. if (onLoad) onLoad(cached);
  24792. scope.manager.itemEnd(url);
  24793. }, 0);
  24794. return cached;
  24795. }
  24796. var fetchOptions = {};
  24797. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24798. fetch(url, fetchOptions).then(function (res) {
  24799. return res.blob();
  24800. }).then(function (blob) {
  24801. return createImageBitmap(blob, scope.options);
  24802. }).then(function (imageBitmap) {
  24803. Cache.add(url, imageBitmap);
  24804. if (onLoad) onLoad(imageBitmap);
  24805. scope.manager.itemEnd(url);
  24806. }).catch(function (e) {
  24807. if (onError) onError(e);
  24808. scope.manager.itemError(url);
  24809. scope.manager.itemEnd(url);
  24810. });
  24811. scope.manager.itemStart(url);
  24812. }
  24813. });
  24814. var ShapePath = /*#__PURE__*/function () {
  24815. function ShapePath() {
  24816. this.type = 'ShapePath';
  24817. this.color = new Color();
  24818. this.subPaths = [];
  24819. this.currentPath = null;
  24820. }
  24821. var _proto = ShapePath.prototype;
  24822. _proto.moveTo = function moveTo(x, y) {
  24823. this.currentPath = new Path();
  24824. this.subPaths.push(this.currentPath);
  24825. this.currentPath.moveTo(x, y);
  24826. return this;
  24827. };
  24828. _proto.lineTo = function lineTo(x, y) {
  24829. this.currentPath.lineTo(x, y);
  24830. return this;
  24831. };
  24832. _proto.quadraticCurveTo = function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24833. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24834. return this;
  24835. };
  24836. _proto.bezierCurveTo = function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24837. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24838. return this;
  24839. };
  24840. _proto.splineThru = function splineThru(pts) {
  24841. this.currentPath.splineThru(pts);
  24842. return this;
  24843. };
  24844. _proto.toShapes = function toShapes(isCCW, noHoles) {
  24845. function toShapesNoHoles(inSubpaths) {
  24846. var shapes = [];
  24847. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24848. var _tmpPath = inSubpaths[i];
  24849. var _tmpShape = new Shape();
  24850. _tmpShape.curves = _tmpPath.curves;
  24851. shapes.push(_tmpShape);
  24852. }
  24853. return shapes;
  24854. }
  24855. function isPointInsidePolygon(inPt, inPolygon) {
  24856. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24857. // toggling of inside/outside at every single! intersection point of an edge
  24858. // with the horizontal line through inPt, left of inPt
  24859. // not counting lowerY endpoints of edges and whole edges on that line
  24860. var inside = false;
  24861. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24862. var edgeLowPt = inPolygon[p];
  24863. var edgeHighPt = inPolygon[q];
  24864. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24865. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24866. if (Math.abs(edgeDy) > Number.EPSILON) {
  24867. // not parallel
  24868. if (edgeDy < 0) {
  24869. edgeLowPt = inPolygon[q];
  24870. edgeDx = -edgeDx;
  24871. edgeHighPt = inPolygon[p];
  24872. edgeDy = -edgeDy;
  24873. }
  24874. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24875. if (inPt.y === edgeLowPt.y) {
  24876. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24877. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24878. } else {
  24879. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24880. if (perpEdge === 0) return true; // inPt is on contour ?
  24881. if (perpEdge < 0) continue;
  24882. inside = !inside; // true intersection left of inPt
  24883. }
  24884. } else {
  24885. // parallel or collinear
  24886. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24887. // edge lies on the same horizontal line as inPt
  24888. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24889. // continue;
  24890. }
  24891. }
  24892. return inside;
  24893. }
  24894. var isClockWise = ShapeUtils.isClockWise;
  24895. var subPaths = this.subPaths;
  24896. if (subPaths.length === 0) return [];
  24897. if (noHoles === true) return toShapesNoHoles(subPaths);
  24898. var solid, tmpPath, tmpShape;
  24899. var shapes = [];
  24900. if (subPaths.length === 1) {
  24901. tmpPath = subPaths[0];
  24902. tmpShape = new Shape();
  24903. tmpShape.curves = tmpPath.curves;
  24904. shapes.push(tmpShape);
  24905. return shapes;
  24906. }
  24907. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24908. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24909. var betterShapeHoles = [];
  24910. var newShapes = [];
  24911. var newShapeHoles = [];
  24912. var mainIdx = 0;
  24913. var tmpPoints;
  24914. newShapes[mainIdx] = undefined;
  24915. newShapeHoles[mainIdx] = [];
  24916. for (var i = 0, l = subPaths.length; i < l; i++) {
  24917. tmpPath = subPaths[i];
  24918. tmpPoints = tmpPath.getPoints();
  24919. solid = isClockWise(tmpPoints);
  24920. solid = isCCW ? !solid : solid;
  24921. if (solid) {
  24922. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24923. newShapes[mainIdx] = {
  24924. s: new Shape(),
  24925. p: tmpPoints
  24926. };
  24927. newShapes[mainIdx].s.curves = tmpPath.curves;
  24928. if (holesFirst) mainIdx++;
  24929. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24930. } else {
  24931. newShapeHoles[mainIdx].push({
  24932. h: tmpPath,
  24933. p: tmpPoints[0]
  24934. }); //console.log('ccw', i);
  24935. }
  24936. } // only Holes? -> probably all Shapes with wrong orientation
  24937. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24938. if (newShapes.length > 1) {
  24939. var ambiguous = false;
  24940. var toChange = [];
  24941. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24942. betterShapeHoles[sIdx] = [];
  24943. }
  24944. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24945. var sho = newShapeHoles[_sIdx];
  24946. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24947. var ho = sho[hIdx];
  24948. var hole_unassigned = true;
  24949. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24950. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24951. if (_sIdx !== s2Idx) toChange.push({
  24952. froms: _sIdx,
  24953. tos: s2Idx,
  24954. hole: hIdx
  24955. });
  24956. if (hole_unassigned) {
  24957. hole_unassigned = false;
  24958. betterShapeHoles[s2Idx].push(ho);
  24959. } else {
  24960. ambiguous = true;
  24961. }
  24962. }
  24963. }
  24964. if (hole_unassigned) {
  24965. betterShapeHoles[_sIdx].push(ho);
  24966. }
  24967. }
  24968. } // console.log("ambiguous: ", ambiguous);
  24969. if (toChange.length > 0) {
  24970. // console.log("to change: ", toChange);
  24971. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24972. }
  24973. }
  24974. var tmpHoles;
  24975. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24976. tmpShape = newShapes[_i].s;
  24977. shapes.push(tmpShape);
  24978. tmpHoles = newShapeHoles[_i];
  24979. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24980. tmpShape.holes.push(tmpHoles[j].h);
  24981. }
  24982. } //console.log("shape", shapes);
  24983. return shapes;
  24984. };
  24985. return ShapePath;
  24986. }();
  24987. var Font = /*#__PURE__*/function () {
  24988. function Font(data) {
  24989. Object.defineProperty(this, 'isFont', {
  24990. value: true
  24991. });
  24992. this.type = 'Font';
  24993. this.data = data;
  24994. }
  24995. var _proto = Font.prototype;
  24996. _proto.generateShapes = function generateShapes(text, size) {
  24997. if (size === void 0) {
  24998. size = 100;
  24999. }
  25000. var shapes = [];
  25001. var paths = createPaths(text, size, this.data);
  25002. for (var p = 0, pl = paths.length; p < pl; p++) {
  25003. Array.prototype.push.apply(shapes, paths[p].toShapes());
  25004. }
  25005. return shapes;
  25006. };
  25007. return Font;
  25008. }();
  25009. function createPaths(text, size, data) {
  25010. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  25011. var scale = size / data.resolution;
  25012. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  25013. var paths = [];
  25014. var offsetX = 0,
  25015. offsetY = 0;
  25016. for (var i = 0; i < chars.length; i++) {
  25017. var char = chars[i];
  25018. if (char === '\n') {
  25019. offsetX = 0;
  25020. offsetY -= line_height;
  25021. } else {
  25022. var ret = createPath(char, scale, offsetX, offsetY, data);
  25023. offsetX += ret.offsetX;
  25024. paths.push(ret.path);
  25025. }
  25026. }
  25027. return paths;
  25028. }
  25029. function createPath(char, scale, offsetX, offsetY, data) {
  25030. var glyph = data.glyphs[char] || data.glyphs['?'];
  25031. if (!glyph) {
  25032. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  25033. return;
  25034. }
  25035. var path = new ShapePath();
  25036. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25037. if (glyph.o) {
  25038. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  25039. for (var i = 0, l = outline.length; i < l;) {
  25040. var action = outline[i++];
  25041. switch (action) {
  25042. case 'm':
  25043. // moveTo
  25044. x = outline[i++] * scale + offsetX;
  25045. y = outline[i++] * scale + offsetY;
  25046. path.moveTo(x, y);
  25047. break;
  25048. case 'l':
  25049. // lineTo
  25050. x = outline[i++] * scale + offsetX;
  25051. y = outline[i++] * scale + offsetY;
  25052. path.lineTo(x, y);
  25053. break;
  25054. case 'q':
  25055. // quadraticCurveTo
  25056. cpx = outline[i++] * scale + offsetX;
  25057. cpy = outline[i++] * scale + offsetY;
  25058. cpx1 = outline[i++] * scale + offsetX;
  25059. cpy1 = outline[i++] * scale + offsetY;
  25060. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  25061. break;
  25062. case 'b':
  25063. // bezierCurveTo
  25064. cpx = outline[i++] * scale + offsetX;
  25065. cpy = outline[i++] * scale + offsetY;
  25066. cpx1 = outline[i++] * scale + offsetX;
  25067. cpy1 = outline[i++] * scale + offsetY;
  25068. cpx2 = outline[i++] * scale + offsetX;
  25069. cpy2 = outline[i++] * scale + offsetY;
  25070. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  25071. break;
  25072. }
  25073. }
  25074. }
  25075. return {
  25076. offsetX: glyph.ha * scale,
  25077. path: path
  25078. };
  25079. }
  25080. var FontLoader = /*#__PURE__*/function (_Loader) {
  25081. _inheritsLoose(FontLoader, _Loader);
  25082. function FontLoader(manager) {
  25083. return _Loader.call(this, manager) || this;
  25084. }
  25085. var _proto = FontLoader.prototype;
  25086. _proto.load = function load(url, onLoad, onProgress, onError) {
  25087. var scope = this;
  25088. var loader = new FileLoader(this.manager);
  25089. loader.setPath(this.path);
  25090. loader.setRequestHeader(this.requestHeader);
  25091. loader.setWithCredentials(scope.withCredentials);
  25092. loader.load(url, function (text) {
  25093. var json;
  25094. try {
  25095. json = JSON.parse(text);
  25096. } catch (e) {
  25097. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  25098. json = JSON.parse(text.substring(65, text.length - 2));
  25099. }
  25100. var font = scope.parse(json);
  25101. if (onLoad) onLoad(font);
  25102. }, onProgress, onError);
  25103. };
  25104. _proto.parse = function parse(json) {
  25105. return new Font(json);
  25106. };
  25107. return FontLoader;
  25108. }(Loader);
  25109. var _context;
  25110. var AudioContext = {
  25111. getContext: function getContext() {
  25112. if (_context === undefined) {
  25113. _context = new (window.AudioContext || window.webkitAudioContext)();
  25114. }
  25115. return _context;
  25116. },
  25117. setContext: function setContext(value) {
  25118. _context = value;
  25119. }
  25120. };
  25121. var AudioLoader = /*#__PURE__*/function (_Loader) {
  25122. _inheritsLoose(AudioLoader, _Loader);
  25123. function AudioLoader(manager) {
  25124. return _Loader.call(this, manager) || this;
  25125. }
  25126. var _proto = AudioLoader.prototype;
  25127. _proto.load = function load(url, onLoad, onProgress, onError) {
  25128. var scope = this;
  25129. var loader = new FileLoader(this.manager);
  25130. loader.setResponseType('arraybuffer');
  25131. loader.setPath(this.path);
  25132. loader.setRequestHeader(this.requestHeader);
  25133. loader.setWithCredentials(this.withCredentials);
  25134. loader.load(url, function (buffer) {
  25135. try {
  25136. // Create a copy of the buffer. The `decodeAudioData` method
  25137. // detaches the buffer when complete, preventing reuse.
  25138. var bufferCopy = buffer.slice(0);
  25139. var context = AudioContext.getContext();
  25140. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  25141. onLoad(audioBuffer);
  25142. });
  25143. } catch (e) {
  25144. if (onError) {
  25145. onError(e);
  25146. } else {
  25147. console.error(e);
  25148. }
  25149. scope.manager.itemError(url);
  25150. }
  25151. }, onProgress, onError);
  25152. };
  25153. return AudioLoader;
  25154. }(Loader);
  25155. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  25156. LightProbe.call(this, undefined, intensity);
  25157. var color1 = new Color().set(skyColor);
  25158. var color2 = new Color().set(groundColor);
  25159. var sky = new Vector3(color1.r, color1.g, color1.b);
  25160. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25161. var c0 = Math.sqrt(Math.PI);
  25162. var c1 = c0 * Math.sqrt(0.75);
  25163. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25164. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25165. }
  25166. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25167. constructor: HemisphereLightProbe,
  25168. isHemisphereLightProbe: true,
  25169. copy: function copy(source) {
  25170. // modifying colors not currently supported
  25171. LightProbe.prototype.copy.call(this, source);
  25172. return this;
  25173. },
  25174. toJSON: function toJSON(meta) {
  25175. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25176. return data;
  25177. }
  25178. });
  25179. function AmbientLightProbe(color, intensity) {
  25180. LightProbe.call(this, undefined, intensity);
  25181. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25182. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25183. }
  25184. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25185. constructor: AmbientLightProbe,
  25186. isAmbientLightProbe: true,
  25187. copy: function copy(source) {
  25188. // modifying color not currently supported
  25189. LightProbe.prototype.copy.call(this, source);
  25190. return this;
  25191. },
  25192. toJSON: function toJSON(meta) {
  25193. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25194. return data;
  25195. }
  25196. });
  25197. var _eyeRight = new Matrix4();
  25198. var _eyeLeft = new Matrix4();
  25199. function StereoCamera() {
  25200. this.type = 'StereoCamera';
  25201. this.aspect = 1;
  25202. this.eyeSep = 0.064;
  25203. this.cameraL = new PerspectiveCamera();
  25204. this.cameraL.layers.enable(1);
  25205. this.cameraL.matrixAutoUpdate = false;
  25206. this.cameraR = new PerspectiveCamera();
  25207. this.cameraR.layers.enable(2);
  25208. this.cameraR.matrixAutoUpdate = false;
  25209. this._cache = {
  25210. focus: null,
  25211. fov: null,
  25212. aspect: null,
  25213. near: null,
  25214. far: null,
  25215. zoom: null,
  25216. eyeSep: null
  25217. };
  25218. }
  25219. Object.assign(StereoCamera.prototype, {
  25220. update: function update(camera) {
  25221. var cache = this._cache;
  25222. 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;
  25223. if (needsUpdate) {
  25224. cache.focus = camera.focus;
  25225. cache.fov = camera.fov;
  25226. cache.aspect = camera.aspect * this.aspect;
  25227. cache.near = camera.near;
  25228. cache.far = camera.far;
  25229. cache.zoom = camera.zoom;
  25230. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25231. // http://paulbourke.net/stereographics/stereorender/
  25232. var projectionMatrix = camera.projectionMatrix.clone();
  25233. var eyeSepHalf = cache.eyeSep / 2;
  25234. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25235. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25236. var xmin, xmax; // translate xOffset
  25237. _eyeLeft.elements[12] = -eyeSepHalf;
  25238. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25239. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25240. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25241. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25242. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25243. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25244. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25245. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25246. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25247. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25248. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25249. }
  25250. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25251. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25252. }
  25253. });
  25254. var Clock = /*#__PURE__*/function () {
  25255. function Clock(autoStart) {
  25256. this.autoStart = autoStart !== undefined ? autoStart : true;
  25257. this.startTime = 0;
  25258. this.oldTime = 0;
  25259. this.elapsedTime = 0;
  25260. this.running = false;
  25261. }
  25262. var _proto = Clock.prototype;
  25263. _proto.start = function start() {
  25264. this.startTime = now();
  25265. this.oldTime = this.startTime;
  25266. this.elapsedTime = 0;
  25267. this.running = true;
  25268. };
  25269. _proto.stop = function stop() {
  25270. this.getElapsedTime();
  25271. this.running = false;
  25272. this.autoStart = false;
  25273. };
  25274. _proto.getElapsedTime = function getElapsedTime() {
  25275. this.getDelta();
  25276. return this.elapsedTime;
  25277. };
  25278. _proto.getDelta = function getDelta() {
  25279. var diff = 0;
  25280. if (this.autoStart && !this.running) {
  25281. this.start();
  25282. return 0;
  25283. }
  25284. if (this.running) {
  25285. var newTime = now();
  25286. diff = (newTime - this.oldTime) / 1000;
  25287. this.oldTime = newTime;
  25288. this.elapsedTime += diff;
  25289. }
  25290. return diff;
  25291. };
  25292. return Clock;
  25293. }();
  25294. function now() {
  25295. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25296. }
  25297. var _position$2 = /*@__PURE__*/new Vector3();
  25298. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25299. var _scale$1 = /*@__PURE__*/new Vector3();
  25300. var _orientation = /*@__PURE__*/new Vector3();
  25301. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25302. _inheritsLoose(AudioListener, _Object3D);
  25303. function AudioListener() {
  25304. var _this;
  25305. _this = _Object3D.call(this) || this;
  25306. _this.type = 'AudioListener';
  25307. _this.context = AudioContext.getContext();
  25308. _this.gain = _this.context.createGain();
  25309. _this.gain.connect(_this.context.destination);
  25310. _this.filter = null;
  25311. _this.timeDelta = 0; // private
  25312. _this._clock = new Clock();
  25313. return _this;
  25314. }
  25315. var _proto = AudioListener.prototype;
  25316. _proto.getInput = function getInput() {
  25317. return this.gain;
  25318. };
  25319. _proto.removeFilter = function removeFilter() {
  25320. if (this.filter !== null) {
  25321. this.gain.disconnect(this.filter);
  25322. this.filter.disconnect(this.context.destination);
  25323. this.gain.connect(this.context.destination);
  25324. this.filter = null;
  25325. }
  25326. return this;
  25327. };
  25328. _proto.getFilter = function getFilter() {
  25329. return this.filter;
  25330. };
  25331. _proto.setFilter = function setFilter(value) {
  25332. if (this.filter !== null) {
  25333. this.gain.disconnect(this.filter);
  25334. this.filter.disconnect(this.context.destination);
  25335. } else {
  25336. this.gain.disconnect(this.context.destination);
  25337. }
  25338. this.filter = value;
  25339. this.gain.connect(this.filter);
  25340. this.filter.connect(this.context.destination);
  25341. return this;
  25342. };
  25343. _proto.getMasterVolume = function getMasterVolume() {
  25344. return this.gain.gain.value;
  25345. };
  25346. _proto.setMasterVolume = function setMasterVolume(value) {
  25347. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25348. return this;
  25349. };
  25350. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25351. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25352. var listener = this.context.listener;
  25353. var up = this.up;
  25354. this.timeDelta = this._clock.getDelta();
  25355. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25356. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25357. if (listener.positionX) {
  25358. // code path for Chrome (see #14393)
  25359. var endTime = this.context.currentTime + this.timeDelta;
  25360. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25361. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25362. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25363. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25364. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25365. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25366. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25367. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25368. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25369. } else {
  25370. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25371. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25372. }
  25373. };
  25374. return AudioListener;
  25375. }(Object3D);
  25376. var Audio = /*#__PURE__*/function (_Object3D) {
  25377. _inheritsLoose(Audio, _Object3D);
  25378. function Audio(listener) {
  25379. var _this;
  25380. _this = _Object3D.call(this) || this;
  25381. _this.type = 'Audio';
  25382. _this.listener = listener;
  25383. _this.context = listener.context;
  25384. _this.gain = _this.context.createGain();
  25385. _this.gain.connect(listener.getInput());
  25386. _this.autoplay = false;
  25387. _this.buffer = null;
  25388. _this.detune = 0;
  25389. _this.loop = false;
  25390. _this.loopStart = 0;
  25391. _this.loopEnd = 0;
  25392. _this.offset = 0;
  25393. _this.duration = undefined;
  25394. _this.playbackRate = 1;
  25395. _this.isPlaying = false;
  25396. _this.hasPlaybackControl = true;
  25397. _this.source = null;
  25398. _this.sourceType = 'empty';
  25399. _this._startedAt = 0;
  25400. _this._progress = 0;
  25401. _this._connected = false;
  25402. _this.filters = [];
  25403. return _this;
  25404. }
  25405. var _proto = Audio.prototype;
  25406. _proto.getOutput = function getOutput() {
  25407. return this.gain;
  25408. };
  25409. _proto.setNodeSource = function setNodeSource(audioNode) {
  25410. this.hasPlaybackControl = false;
  25411. this.sourceType = 'audioNode';
  25412. this.source = audioNode;
  25413. this.connect();
  25414. return this;
  25415. };
  25416. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25417. this.hasPlaybackControl = false;
  25418. this.sourceType = 'mediaNode';
  25419. this.source = this.context.createMediaElementSource(mediaElement);
  25420. this.connect();
  25421. return this;
  25422. };
  25423. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25424. this.hasPlaybackControl = false;
  25425. this.sourceType = 'mediaStreamNode';
  25426. this.source = this.context.createMediaStreamSource(mediaStream);
  25427. this.connect();
  25428. return this;
  25429. };
  25430. _proto.setBuffer = function setBuffer(audioBuffer) {
  25431. this.buffer = audioBuffer;
  25432. this.sourceType = 'buffer';
  25433. if (this.autoplay) this.play();
  25434. return this;
  25435. };
  25436. _proto.play = function play(delay) {
  25437. if (delay === void 0) {
  25438. delay = 0;
  25439. }
  25440. if (this.isPlaying === true) {
  25441. console.warn('THREE.Audio: Audio is already playing.');
  25442. return;
  25443. }
  25444. if (this.hasPlaybackControl === false) {
  25445. console.warn('THREE.Audio: this Audio has no playback control.');
  25446. return;
  25447. }
  25448. this._startedAt = this.context.currentTime + delay;
  25449. var source = this.context.createBufferSource();
  25450. source.buffer = this.buffer;
  25451. source.loop = this.loop;
  25452. source.loopStart = this.loopStart;
  25453. source.loopEnd = this.loopEnd;
  25454. source.onended = this.onEnded.bind(this);
  25455. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25456. this.isPlaying = true;
  25457. this.source = source;
  25458. this.setDetune(this.detune);
  25459. this.setPlaybackRate(this.playbackRate);
  25460. return this.connect();
  25461. };
  25462. _proto.pause = function pause() {
  25463. if (this.hasPlaybackControl === false) {
  25464. console.warn('THREE.Audio: this Audio has no playback control.');
  25465. return;
  25466. }
  25467. if (this.isPlaying === true) {
  25468. // update current progress
  25469. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25470. if (this.loop === true) {
  25471. // ensure _progress does not exceed duration with looped audios
  25472. this._progress = this._progress % (this.duration || this.buffer.duration);
  25473. }
  25474. this.source.stop();
  25475. this.source.onended = null;
  25476. this.isPlaying = false;
  25477. }
  25478. return this;
  25479. };
  25480. _proto.stop = function stop() {
  25481. if (this.hasPlaybackControl === false) {
  25482. console.warn('THREE.Audio: this Audio has no playback control.');
  25483. return;
  25484. }
  25485. this._progress = 0;
  25486. this.source.stop();
  25487. this.source.onended = null;
  25488. this.isPlaying = false;
  25489. return this;
  25490. };
  25491. _proto.connect = function connect() {
  25492. if (this.filters.length > 0) {
  25493. this.source.connect(this.filters[0]);
  25494. for (var i = 1, l = this.filters.length; i < l; i++) {
  25495. this.filters[i - 1].connect(this.filters[i]);
  25496. }
  25497. this.filters[this.filters.length - 1].connect(this.getOutput());
  25498. } else {
  25499. this.source.connect(this.getOutput());
  25500. }
  25501. this._connected = true;
  25502. return this;
  25503. };
  25504. _proto.disconnect = function disconnect() {
  25505. if (this.filters.length > 0) {
  25506. this.source.disconnect(this.filters[0]);
  25507. for (var i = 1, l = this.filters.length; i < l; i++) {
  25508. this.filters[i - 1].disconnect(this.filters[i]);
  25509. }
  25510. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25511. } else {
  25512. this.source.disconnect(this.getOutput());
  25513. }
  25514. this._connected = false;
  25515. return this;
  25516. };
  25517. _proto.getFilters = function getFilters() {
  25518. return this.filters;
  25519. };
  25520. _proto.setFilters = function setFilters(value) {
  25521. if (!value) value = [];
  25522. if (this._connected === true) {
  25523. this.disconnect();
  25524. this.filters = value.slice();
  25525. this.connect();
  25526. } else {
  25527. this.filters = value.slice();
  25528. }
  25529. return this;
  25530. };
  25531. _proto.setDetune = function setDetune(value) {
  25532. this.detune = value;
  25533. if (this.source.detune === undefined) return; // only set detune when available
  25534. if (this.isPlaying === true) {
  25535. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25536. }
  25537. return this;
  25538. };
  25539. _proto.getDetune = function getDetune() {
  25540. return this.detune;
  25541. };
  25542. _proto.getFilter = function getFilter() {
  25543. return this.getFilters()[0];
  25544. };
  25545. _proto.setFilter = function setFilter(filter) {
  25546. return this.setFilters(filter ? [filter] : []);
  25547. };
  25548. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25549. if (this.hasPlaybackControl === false) {
  25550. console.warn('THREE.Audio: this Audio has no playback control.');
  25551. return;
  25552. }
  25553. this.playbackRate = value;
  25554. if (this.isPlaying === true) {
  25555. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25556. }
  25557. return this;
  25558. };
  25559. _proto.getPlaybackRate = function getPlaybackRate() {
  25560. return this.playbackRate;
  25561. };
  25562. _proto.onEnded = function onEnded() {
  25563. this.isPlaying = false;
  25564. };
  25565. _proto.getLoop = function getLoop() {
  25566. if (this.hasPlaybackControl === false) {
  25567. console.warn('THREE.Audio: this Audio has no playback control.');
  25568. return false;
  25569. }
  25570. return this.loop;
  25571. };
  25572. _proto.setLoop = function setLoop(value) {
  25573. if (this.hasPlaybackControl === false) {
  25574. console.warn('THREE.Audio: this Audio has no playback control.');
  25575. return;
  25576. }
  25577. this.loop = value;
  25578. if (this.isPlaying === true) {
  25579. this.source.loop = this.loop;
  25580. }
  25581. return this;
  25582. };
  25583. _proto.setLoopStart = function setLoopStart(value) {
  25584. this.loopStart = value;
  25585. return this;
  25586. };
  25587. _proto.setLoopEnd = function setLoopEnd(value) {
  25588. this.loopEnd = value;
  25589. return this;
  25590. };
  25591. _proto.getVolume = function getVolume() {
  25592. return this.gain.gain.value;
  25593. };
  25594. _proto.setVolume = function setVolume(value) {
  25595. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25596. return this;
  25597. };
  25598. return Audio;
  25599. }(Object3D);
  25600. var _position$3 = /*@__PURE__*/new Vector3();
  25601. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25602. var _scale$2 = /*@__PURE__*/new Vector3();
  25603. var _orientation$1 = /*@__PURE__*/new Vector3();
  25604. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25605. _inheritsLoose(PositionalAudio, _Audio);
  25606. function PositionalAudio(listener) {
  25607. var _this;
  25608. _this = _Audio.call(this, listener) || this;
  25609. _this.panner = _this.context.createPanner();
  25610. _this.panner.panningModel = 'HRTF';
  25611. _this.panner.connect(_this.gain);
  25612. return _this;
  25613. }
  25614. var _proto = PositionalAudio.prototype;
  25615. _proto.getOutput = function getOutput() {
  25616. return this.panner;
  25617. };
  25618. _proto.getRefDistance = function getRefDistance() {
  25619. return this.panner.refDistance;
  25620. };
  25621. _proto.setRefDistance = function setRefDistance(value) {
  25622. this.panner.refDistance = value;
  25623. return this;
  25624. };
  25625. _proto.getRolloffFactor = function getRolloffFactor() {
  25626. return this.panner.rolloffFactor;
  25627. };
  25628. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25629. this.panner.rolloffFactor = value;
  25630. return this;
  25631. };
  25632. _proto.getDistanceModel = function getDistanceModel() {
  25633. return this.panner.distanceModel;
  25634. };
  25635. _proto.setDistanceModel = function setDistanceModel(value) {
  25636. this.panner.distanceModel = value;
  25637. return this;
  25638. };
  25639. _proto.getMaxDistance = function getMaxDistance() {
  25640. return this.panner.maxDistance;
  25641. };
  25642. _proto.setMaxDistance = function setMaxDistance(value) {
  25643. this.panner.maxDistance = value;
  25644. return this;
  25645. };
  25646. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25647. this.panner.coneInnerAngle = coneInnerAngle;
  25648. this.panner.coneOuterAngle = coneOuterAngle;
  25649. this.panner.coneOuterGain = coneOuterGain;
  25650. return this;
  25651. };
  25652. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25653. _Audio.prototype.updateMatrixWorld.call(this, force);
  25654. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25655. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25656. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25657. var panner = this.panner;
  25658. if (panner.positionX) {
  25659. // code path for Chrome and Firefox (see #14393)
  25660. var endTime = this.context.currentTime + this.listener.timeDelta;
  25661. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25662. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25663. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25664. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25665. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25666. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25667. } else {
  25668. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25669. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25670. }
  25671. };
  25672. return PositionalAudio;
  25673. }(Audio);
  25674. var AudioAnalyser = /*#__PURE__*/function () {
  25675. function AudioAnalyser(audio, fftSize) {
  25676. if (fftSize === void 0) {
  25677. fftSize = 2048;
  25678. }
  25679. this.analyser = audio.context.createAnalyser();
  25680. this.analyser.fftSize = fftSize;
  25681. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25682. audio.getOutput().connect(this.analyser);
  25683. }
  25684. var _proto = AudioAnalyser.prototype;
  25685. _proto.getFrequencyData = function getFrequencyData() {
  25686. this.analyser.getByteFrequencyData(this.data);
  25687. return this.data;
  25688. };
  25689. _proto.getAverageFrequency = function getAverageFrequency() {
  25690. var value = 0;
  25691. var data = this.getFrequencyData();
  25692. for (var i = 0; i < data.length; i++) {
  25693. value += data[i];
  25694. }
  25695. return value / data.length;
  25696. };
  25697. return AudioAnalyser;
  25698. }();
  25699. function PropertyMixer(binding, typeName, valueSize) {
  25700. this.binding = binding;
  25701. this.valueSize = valueSize;
  25702. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25703. //
  25704. // interpolators can use .buffer as their .result
  25705. // the data then goes to 'incoming'
  25706. //
  25707. // 'accu0' and 'accu1' are used frame-interleaved for
  25708. // the cumulative result and are compared to detect
  25709. // changes
  25710. //
  25711. // 'orig' stores the original state of the property
  25712. //
  25713. // 'add' is used for additive cumulative results
  25714. //
  25715. // 'work' is optional and is only present for quaternion types. It is used
  25716. // to store intermediate quaternion multiplication results
  25717. switch (typeName) {
  25718. case 'quaternion':
  25719. mixFunction = this._slerp;
  25720. mixFunctionAdditive = this._slerpAdditive;
  25721. setIdentity = this._setAdditiveIdentityQuaternion;
  25722. this.buffer = new Float64Array(valueSize * 6);
  25723. this._workIndex = 5;
  25724. break;
  25725. case 'string':
  25726. case 'bool':
  25727. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25728. // additive is not relevant for non-numeric types
  25729. mixFunctionAdditive = this._select;
  25730. setIdentity = this._setAdditiveIdentityOther;
  25731. this.buffer = new Array(valueSize * 5);
  25732. break;
  25733. default:
  25734. mixFunction = this._lerp;
  25735. mixFunctionAdditive = this._lerpAdditive;
  25736. setIdentity = this._setAdditiveIdentityNumeric;
  25737. this.buffer = new Float64Array(valueSize * 5);
  25738. }
  25739. this._mixBufferRegion = mixFunction;
  25740. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25741. this._setIdentity = setIdentity;
  25742. this._origIndex = 3;
  25743. this._addIndex = 4;
  25744. this.cumulativeWeight = 0;
  25745. this.cumulativeWeightAdditive = 0;
  25746. this.useCount = 0;
  25747. this.referenceCount = 0;
  25748. }
  25749. Object.assign(PropertyMixer.prototype, {
  25750. // accumulate data in the 'incoming' region into 'accu<i>'
  25751. accumulate: function accumulate(accuIndex, weight) {
  25752. // note: happily accumulating nothing when weight = 0, the caller knows
  25753. // the weight and shouldn't have made the call in the first place
  25754. var buffer = this.buffer,
  25755. stride = this.valueSize,
  25756. offset = accuIndex * stride + stride;
  25757. var currentWeight = this.cumulativeWeight;
  25758. if (currentWeight === 0) {
  25759. // accuN := incoming * weight
  25760. for (var i = 0; i !== stride; ++i) {
  25761. buffer[offset + i] = buffer[i];
  25762. }
  25763. currentWeight = weight;
  25764. } else {
  25765. // accuN := accuN + incoming * weight
  25766. currentWeight += weight;
  25767. var mix = weight / currentWeight;
  25768. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25769. }
  25770. this.cumulativeWeight = currentWeight;
  25771. },
  25772. // accumulate data in the 'incoming' region into 'add'
  25773. accumulateAdditive: function accumulateAdditive(weight) {
  25774. var buffer = this.buffer,
  25775. stride = this.valueSize,
  25776. offset = stride * this._addIndex;
  25777. if (this.cumulativeWeightAdditive === 0) {
  25778. // add = identity
  25779. this._setIdentity();
  25780. } // add := add + incoming * weight
  25781. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25782. this.cumulativeWeightAdditive += weight;
  25783. },
  25784. // apply the state of 'accu<i>' to the binding when accus differ
  25785. apply: function apply(accuIndex) {
  25786. var stride = this.valueSize,
  25787. buffer = this.buffer,
  25788. offset = accuIndex * stride + stride,
  25789. weight = this.cumulativeWeight,
  25790. weightAdditive = this.cumulativeWeightAdditive,
  25791. binding = this.binding;
  25792. this.cumulativeWeight = 0;
  25793. this.cumulativeWeightAdditive = 0;
  25794. if (weight < 1) {
  25795. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25796. var originalValueOffset = stride * this._origIndex;
  25797. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25798. }
  25799. if (weightAdditive > 0) {
  25800. // accuN := accuN + additive accuN
  25801. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25802. }
  25803. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25804. if (buffer[i] !== buffer[i + stride]) {
  25805. // value has changed -> update scene graph
  25806. binding.setValue(buffer, offset);
  25807. break;
  25808. }
  25809. }
  25810. },
  25811. // remember the state of the bound property and copy it to both accus
  25812. saveOriginalState: function saveOriginalState() {
  25813. var binding = this.binding;
  25814. var buffer = this.buffer,
  25815. stride = this.valueSize,
  25816. originalValueOffset = stride * this._origIndex;
  25817. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25818. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25819. buffer[i] = buffer[originalValueOffset + i % stride];
  25820. } // Add to identity for additive
  25821. this._setIdentity();
  25822. this.cumulativeWeight = 0;
  25823. this.cumulativeWeightAdditive = 0;
  25824. },
  25825. // apply the state previously taken via 'saveOriginalState' to the binding
  25826. restoreOriginalState: function restoreOriginalState() {
  25827. var originalValueOffset = this.valueSize * 3;
  25828. this.binding.setValue(this.buffer, originalValueOffset);
  25829. },
  25830. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25831. var startIndex = this._addIndex * this.valueSize;
  25832. var endIndex = startIndex + this.valueSize;
  25833. for (var i = startIndex; i < endIndex; i++) {
  25834. this.buffer[i] = 0;
  25835. }
  25836. },
  25837. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25838. this._setAdditiveIdentityNumeric();
  25839. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25840. },
  25841. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25842. var startIndex = this._origIndex * this.valueSize;
  25843. var targetIndex = this._addIndex * this.valueSize;
  25844. for (var i = 0; i < this.valueSize; i++) {
  25845. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25846. }
  25847. },
  25848. // mix functions
  25849. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25850. if (t >= 0.5) {
  25851. for (var i = 0; i !== stride; ++i) {
  25852. buffer[dstOffset + i] = buffer[srcOffset + i];
  25853. }
  25854. }
  25855. },
  25856. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25857. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25858. },
  25859. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25860. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25861. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25862. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25863. },
  25864. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25865. var s = 1 - t;
  25866. for (var i = 0; i !== stride; ++i) {
  25867. var j = dstOffset + i;
  25868. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25869. }
  25870. },
  25871. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25872. for (var i = 0; i !== stride; ++i) {
  25873. var j = dstOffset + i;
  25874. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25875. }
  25876. }
  25877. });
  25878. // Characters [].:/ are reserved for track binding syntax.
  25879. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25880. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25881. // only latin characters, and the unicode \p{L} is not yet supported. So
  25882. // instead, we exclude reserved characters and match everything else.
  25883. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25884. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25885. // be matched to parse the rest of the track name.
  25886. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25887. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25888. // characters. Accessor may contain any character except closing bracket.
  25889. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25890. // contain any non-bracket characters.
  25891. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25892. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25893. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25894. function Composite(targetGroup, path, optionalParsedPath) {
  25895. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25896. this._targetGroup = targetGroup;
  25897. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25898. }
  25899. Object.assign(Composite.prototype, {
  25900. getValue: function getValue(array, offset) {
  25901. this.bind(); // bind all binding
  25902. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25903. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25904. if (binding !== undefined) binding.getValue(array, offset);
  25905. },
  25906. setValue: function setValue(array, offset) {
  25907. var bindings = this._bindings;
  25908. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25909. bindings[i].setValue(array, offset);
  25910. }
  25911. },
  25912. bind: function bind() {
  25913. var bindings = this._bindings;
  25914. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25915. bindings[i].bind();
  25916. }
  25917. },
  25918. unbind: function unbind() {
  25919. var bindings = this._bindings;
  25920. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25921. bindings[i].unbind();
  25922. }
  25923. }
  25924. });
  25925. function PropertyBinding(rootNode, path, parsedPath) {
  25926. this.path = path;
  25927. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25928. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25929. this.rootNode = rootNode;
  25930. }
  25931. Object.assign(PropertyBinding, {
  25932. Composite: Composite,
  25933. create: function create(root, path, parsedPath) {
  25934. if (!(root && root.isAnimationObjectGroup)) {
  25935. return new PropertyBinding(root, path, parsedPath);
  25936. } else {
  25937. return new PropertyBinding.Composite(root, path, parsedPath);
  25938. }
  25939. },
  25940. /**
  25941. * Replaces spaces with underscores and removes unsupported characters from
  25942. * node names, to ensure compatibility with parseTrackName().
  25943. *
  25944. * @param {string} name Node name to be sanitized.
  25945. * @return {string}
  25946. */
  25947. sanitizeNodeName: function sanitizeNodeName(name) {
  25948. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25949. },
  25950. parseTrackName: function parseTrackName(trackName) {
  25951. var matches = _trackRe.exec(trackName);
  25952. if (!matches) {
  25953. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25954. }
  25955. var results = {
  25956. // directoryName: matches[ 1 ], // (tschw) currently unused
  25957. nodeName: matches[2],
  25958. objectName: matches[3],
  25959. objectIndex: matches[4],
  25960. propertyName: matches[5],
  25961. // required
  25962. propertyIndex: matches[6]
  25963. };
  25964. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25965. if (lastDot !== undefined && lastDot !== -1) {
  25966. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25967. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25968. // 'bar' could be the objectName, or part of a nodeName (which can
  25969. // include '.' characters).
  25970. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25971. results.nodeName = results.nodeName.substring(0, lastDot);
  25972. results.objectName = objectName;
  25973. }
  25974. }
  25975. if (results.propertyName === null || results.propertyName.length === 0) {
  25976. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25977. }
  25978. return results;
  25979. },
  25980. findNode: function findNode(root, nodeName) {
  25981. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25982. return root;
  25983. } // search into skeleton bones.
  25984. if (root.skeleton) {
  25985. var bone = root.skeleton.getBoneByName(nodeName);
  25986. if (bone !== undefined) {
  25987. return bone;
  25988. }
  25989. } // search into node subtree.
  25990. if (root.children) {
  25991. var searchNodeSubtree = function searchNodeSubtree(children) {
  25992. for (var i = 0; i < children.length; i++) {
  25993. var childNode = children[i];
  25994. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25995. return childNode;
  25996. }
  25997. var result = searchNodeSubtree(childNode.children);
  25998. if (result) return result;
  25999. }
  26000. return null;
  26001. };
  26002. var subTreeNode = searchNodeSubtree(root.children);
  26003. if (subTreeNode) {
  26004. return subTreeNode;
  26005. }
  26006. }
  26007. return null;
  26008. }
  26009. });
  26010. Object.assign(PropertyBinding.prototype, {
  26011. // prototype, continued
  26012. // these are used to "bind" a nonexistent property
  26013. _getValue_unavailable: function _getValue_unavailable() {},
  26014. _setValue_unavailable: function _setValue_unavailable() {},
  26015. BindingType: {
  26016. Direct: 0,
  26017. EntireArray: 1,
  26018. ArrayElement: 2,
  26019. HasFromToArray: 3
  26020. },
  26021. Versioning: {
  26022. None: 0,
  26023. NeedsUpdate: 1,
  26024. MatrixWorldNeedsUpdate: 2
  26025. },
  26026. GetterByBindingType: [function getValue_direct(buffer, offset) {
  26027. buffer[offset] = this.node[this.propertyName];
  26028. }, function getValue_array(buffer, offset) {
  26029. var source = this.resolvedProperty;
  26030. for (var i = 0, n = source.length; i !== n; ++i) {
  26031. buffer[offset++] = source[i];
  26032. }
  26033. }, function getValue_arrayElement(buffer, offset) {
  26034. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  26035. }, function getValue_toArray(buffer, offset) {
  26036. this.resolvedProperty.toArray(buffer, offset);
  26037. }],
  26038. SetterByBindingTypeAndVersioning: [[// Direct
  26039. function setValue_direct(buffer, offset) {
  26040. this.targetObject[this.propertyName] = buffer[offset];
  26041. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  26042. this.targetObject[this.propertyName] = buffer[offset];
  26043. this.targetObject.needsUpdate = true;
  26044. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  26045. this.targetObject[this.propertyName] = buffer[offset];
  26046. this.targetObject.matrixWorldNeedsUpdate = true;
  26047. }], [// EntireArray
  26048. function setValue_array(buffer, offset) {
  26049. var dest = this.resolvedProperty;
  26050. for (var i = 0, n = dest.length; i !== n; ++i) {
  26051. dest[i] = buffer[offset++];
  26052. }
  26053. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  26054. var dest = this.resolvedProperty;
  26055. for (var i = 0, n = dest.length; i !== n; ++i) {
  26056. dest[i] = buffer[offset++];
  26057. }
  26058. this.targetObject.needsUpdate = true;
  26059. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  26060. var dest = this.resolvedProperty;
  26061. for (var i = 0, n = dest.length; i !== n; ++i) {
  26062. dest[i] = buffer[offset++];
  26063. }
  26064. this.targetObject.matrixWorldNeedsUpdate = true;
  26065. }], [// ArrayElement
  26066. function setValue_arrayElement(buffer, offset) {
  26067. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26068. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  26069. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26070. this.targetObject.needsUpdate = true;
  26071. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  26072. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  26073. this.targetObject.matrixWorldNeedsUpdate = true;
  26074. }], [// HasToFromArray
  26075. function setValue_fromArray(buffer, offset) {
  26076. this.resolvedProperty.fromArray(buffer, offset);
  26077. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  26078. this.resolvedProperty.fromArray(buffer, offset);
  26079. this.targetObject.needsUpdate = true;
  26080. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  26081. this.resolvedProperty.fromArray(buffer, offset);
  26082. this.targetObject.matrixWorldNeedsUpdate = true;
  26083. }]],
  26084. getValue: function getValue_unbound(targetArray, offset) {
  26085. this.bind();
  26086. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  26087. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26088. // prototype version of these methods with one that represents
  26089. // the bound state. When the property is not found, the methods
  26090. // become no-ops.
  26091. },
  26092. setValue: function getValue_unbound(sourceArray, offset) {
  26093. this.bind();
  26094. this.setValue(sourceArray, offset);
  26095. },
  26096. // create getter / setter pair for a property in the scene graph
  26097. bind: function bind() {
  26098. var targetObject = this.node;
  26099. var parsedPath = this.parsedPath;
  26100. var objectName = parsedPath.objectName;
  26101. var propertyName = parsedPath.propertyName;
  26102. var propertyIndex = parsedPath.propertyIndex;
  26103. if (!targetObject) {
  26104. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  26105. this.node = targetObject;
  26106. } // set fail state so we can just 'return' on error
  26107. this.getValue = this._getValue_unavailable;
  26108. this.setValue = this._setValue_unavailable; // ensure there is a value node
  26109. if (!targetObject) {
  26110. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  26111. return;
  26112. }
  26113. if (objectName) {
  26114. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26115. switch (objectName) {
  26116. case 'materials':
  26117. if (!targetObject.material) {
  26118. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  26119. return;
  26120. }
  26121. if (!targetObject.material.materials) {
  26122. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  26123. return;
  26124. }
  26125. targetObject = targetObject.material.materials;
  26126. break;
  26127. case 'bones':
  26128. if (!targetObject.skeleton) {
  26129. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  26130. return;
  26131. } // potential future optimization: skip this if propertyIndex is already an integer
  26132. // and convert the integer string to a true integer.
  26133. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  26134. for (var i = 0; i < targetObject.length; i++) {
  26135. if (targetObject[i].name === objectIndex) {
  26136. objectIndex = i;
  26137. break;
  26138. }
  26139. }
  26140. break;
  26141. default:
  26142. if (targetObject[objectName] === undefined) {
  26143. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  26144. return;
  26145. }
  26146. targetObject = targetObject[objectName];
  26147. }
  26148. if (objectIndex !== undefined) {
  26149. if (targetObject[objectIndex] === undefined) {
  26150. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  26151. return;
  26152. }
  26153. targetObject = targetObject[objectIndex];
  26154. }
  26155. } // resolve property
  26156. var nodeProperty = targetObject[propertyName];
  26157. if (nodeProperty === undefined) {
  26158. var nodeName = parsedPath.nodeName;
  26159. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26160. return;
  26161. } // determine versioning scheme
  26162. var versioning = this.Versioning.None;
  26163. this.targetObject = targetObject;
  26164. if (targetObject.needsUpdate !== undefined) {
  26165. // material
  26166. versioning = this.Versioning.NeedsUpdate;
  26167. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26168. // node transform
  26169. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26170. } // determine how the property gets bound
  26171. var bindingType = this.BindingType.Direct;
  26172. if (propertyIndex !== undefined) {
  26173. // access a sub element of the property array (only primitives are supported right now)
  26174. if (propertyName === 'morphTargetInfluences') {
  26175. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26176. // support resolving morphTarget names into indices.
  26177. if (!targetObject.geometry) {
  26178. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26179. return;
  26180. }
  26181. if (targetObject.geometry.isBufferGeometry) {
  26182. if (!targetObject.geometry.morphAttributes) {
  26183. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26184. return;
  26185. }
  26186. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26187. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26188. }
  26189. } else {
  26190. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26191. return;
  26192. }
  26193. }
  26194. bindingType = this.BindingType.ArrayElement;
  26195. this.resolvedProperty = nodeProperty;
  26196. this.propertyIndex = propertyIndex;
  26197. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26198. // must use copy for Object3D.Euler/Quaternion
  26199. bindingType = this.BindingType.HasFromToArray;
  26200. this.resolvedProperty = nodeProperty;
  26201. } else if (Array.isArray(nodeProperty)) {
  26202. bindingType = this.BindingType.EntireArray;
  26203. this.resolvedProperty = nodeProperty;
  26204. } else {
  26205. this.propertyName = propertyName;
  26206. } // select getter / setter
  26207. this.getValue = this.GetterByBindingType[bindingType];
  26208. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26209. },
  26210. unbind: function unbind() {
  26211. this.node = null; // back to the prototype version of getValue / setValue
  26212. // note: avoiding to mutate the shape of 'this' via 'delete'
  26213. this.getValue = this._getValue_unbound;
  26214. this.setValue = this._setValue_unbound;
  26215. }
  26216. }); // DECLARE ALIAS AFTER assign prototype
  26217. Object.assign(PropertyBinding.prototype, {
  26218. // initial state of these methods that calls 'bind'
  26219. _getValue_unbound: PropertyBinding.prototype.getValue,
  26220. _setValue_unbound: PropertyBinding.prototype.setValue
  26221. });
  26222. /**
  26223. *
  26224. * A group of objects that receives a shared animation state.
  26225. *
  26226. * Usage:
  26227. *
  26228. * - Add objects you would otherwise pass as 'root' to the
  26229. * constructor or the .clipAction method of AnimationMixer.
  26230. *
  26231. * - Instead pass this object as 'root'.
  26232. *
  26233. * - You can also add and remove objects later when the mixer
  26234. * is running.
  26235. *
  26236. * Note:
  26237. *
  26238. * Objects of this class appear as one object to the mixer,
  26239. * so cache control of the individual objects must be done
  26240. * on the group.
  26241. *
  26242. * Limitation:
  26243. *
  26244. * - The animated properties must be compatible among the
  26245. * all objects in the group.
  26246. *
  26247. * - A single property can either be controlled through a
  26248. * target group or directly, but not both.
  26249. */
  26250. function AnimationObjectGroup() {
  26251. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26252. this._objects = Array.prototype.slice.call(arguments);
  26253. this.nCachedObjects_ = 0; // threshold
  26254. // note: read by PropertyBinding.Composite
  26255. var indices = {};
  26256. this._indicesByUUID = indices; // for bookkeeping
  26257. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26258. indices[arguments[i].uuid] = i;
  26259. }
  26260. this._paths = []; // inside: string
  26261. this._parsedPaths = []; // inside: { we don't care, here }
  26262. this._bindings = []; // inside: Array< PropertyBinding >
  26263. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26264. var scope = this;
  26265. this.stats = {
  26266. objects: {
  26267. get total() {
  26268. return scope._objects.length;
  26269. },
  26270. get inUse() {
  26271. return this.total - scope.nCachedObjects_;
  26272. }
  26273. },
  26274. get bindingsPerObject() {
  26275. return scope._bindings.length;
  26276. }
  26277. };
  26278. }
  26279. Object.assign(AnimationObjectGroup.prototype, {
  26280. isAnimationObjectGroup: true,
  26281. add: function add() {
  26282. var objects = this._objects,
  26283. indicesByUUID = this._indicesByUUID,
  26284. paths = this._paths,
  26285. parsedPaths = this._parsedPaths,
  26286. bindings = this._bindings,
  26287. nBindings = bindings.length;
  26288. var knownObject = undefined,
  26289. nObjects = objects.length,
  26290. nCachedObjects = this.nCachedObjects_;
  26291. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26292. var object = arguments[i],
  26293. uuid = object.uuid;
  26294. var index = indicesByUUID[uuid];
  26295. if (index === undefined) {
  26296. // unknown object -> add it to the ACTIVE region
  26297. index = nObjects++;
  26298. indicesByUUID[uuid] = index;
  26299. objects.push(object); // accounting is done, now do the same for all bindings
  26300. for (var j = 0, m = nBindings; j !== m; ++j) {
  26301. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26302. }
  26303. } else if (index < nCachedObjects) {
  26304. knownObject = objects[index]; // move existing object to the ACTIVE region
  26305. var firstActiveIndex = --nCachedObjects,
  26306. lastCachedObject = objects[firstActiveIndex];
  26307. indicesByUUID[lastCachedObject.uuid] = index;
  26308. objects[index] = lastCachedObject;
  26309. indicesByUUID[uuid] = firstActiveIndex;
  26310. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26311. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26312. var bindingsForPath = bindings[_j],
  26313. lastCached = bindingsForPath[firstActiveIndex];
  26314. var binding = bindingsForPath[index];
  26315. bindingsForPath[index] = lastCached;
  26316. if (binding === undefined) {
  26317. // since we do not bother to create new bindings
  26318. // for objects that are cached, the binding may
  26319. // or may not exist
  26320. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26321. }
  26322. bindingsForPath[firstActiveIndex] = binding;
  26323. }
  26324. } else if (objects[index] !== knownObject) {
  26325. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26326. } // else the object is already where we want it to be
  26327. } // for arguments
  26328. this.nCachedObjects_ = nCachedObjects;
  26329. },
  26330. remove: function remove() {
  26331. var objects = this._objects,
  26332. indicesByUUID = this._indicesByUUID,
  26333. bindings = this._bindings,
  26334. nBindings = bindings.length;
  26335. var nCachedObjects = this.nCachedObjects_;
  26336. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26337. var object = arguments[i],
  26338. uuid = object.uuid,
  26339. index = indicesByUUID[uuid];
  26340. if (index !== undefined && index >= nCachedObjects) {
  26341. // move existing object into the CACHED region
  26342. var lastCachedIndex = nCachedObjects++,
  26343. firstActiveObject = objects[lastCachedIndex];
  26344. indicesByUUID[firstActiveObject.uuid] = index;
  26345. objects[index] = firstActiveObject;
  26346. indicesByUUID[uuid] = lastCachedIndex;
  26347. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26348. for (var j = 0, m = nBindings; j !== m; ++j) {
  26349. var bindingsForPath = bindings[j],
  26350. firstActive = bindingsForPath[lastCachedIndex],
  26351. binding = bindingsForPath[index];
  26352. bindingsForPath[index] = firstActive;
  26353. bindingsForPath[lastCachedIndex] = binding;
  26354. }
  26355. }
  26356. } // for arguments
  26357. this.nCachedObjects_ = nCachedObjects;
  26358. },
  26359. // remove & forget
  26360. uncache: function uncache() {
  26361. var objects = this._objects,
  26362. indicesByUUID = this._indicesByUUID,
  26363. bindings = this._bindings,
  26364. nBindings = bindings.length;
  26365. var nCachedObjects = this.nCachedObjects_,
  26366. nObjects = objects.length;
  26367. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26368. var object = arguments[i],
  26369. uuid = object.uuid,
  26370. index = indicesByUUID[uuid];
  26371. if (index !== undefined) {
  26372. delete indicesByUUID[uuid];
  26373. if (index < nCachedObjects) {
  26374. // object is cached, shrink the CACHED region
  26375. var firstActiveIndex = --nCachedObjects,
  26376. lastCachedObject = objects[firstActiveIndex],
  26377. lastIndex = --nObjects,
  26378. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26379. indicesByUUID[lastCachedObject.uuid] = index;
  26380. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26381. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26382. objects[firstActiveIndex] = lastObject;
  26383. objects.pop(); // accounting is done, now do the same for all bindings
  26384. for (var j = 0, m = nBindings; j !== m; ++j) {
  26385. var bindingsForPath = bindings[j],
  26386. lastCached = bindingsForPath[firstActiveIndex],
  26387. last = bindingsForPath[lastIndex];
  26388. bindingsForPath[index] = lastCached;
  26389. bindingsForPath[firstActiveIndex] = last;
  26390. bindingsForPath.pop();
  26391. }
  26392. } else {
  26393. // object is active, just swap with the last and pop
  26394. var _lastIndex = --nObjects,
  26395. _lastObject = objects[_lastIndex];
  26396. if (_lastIndex > 0) {
  26397. indicesByUUID[_lastObject.uuid] = index;
  26398. }
  26399. objects[index] = _lastObject;
  26400. objects.pop(); // accounting is done, now do the same for all bindings
  26401. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26402. var _bindingsForPath = bindings[_j2];
  26403. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26404. _bindingsForPath.pop();
  26405. }
  26406. } // cached or active
  26407. } // if object is known
  26408. } // for arguments
  26409. this.nCachedObjects_ = nCachedObjects;
  26410. },
  26411. // Internal interface used by befriended PropertyBinding.Composite:
  26412. subscribe_: function subscribe_(path, parsedPath) {
  26413. // returns an array of bindings for the given path that is changed
  26414. // according to the contained objects in the group
  26415. var indicesByPath = this._bindingsIndicesByPath;
  26416. var index = indicesByPath[path];
  26417. var bindings = this._bindings;
  26418. if (index !== undefined) return bindings[index];
  26419. var paths = this._paths,
  26420. parsedPaths = this._parsedPaths,
  26421. objects = this._objects,
  26422. nObjects = objects.length,
  26423. nCachedObjects = this.nCachedObjects_,
  26424. bindingsForPath = new Array(nObjects);
  26425. index = bindings.length;
  26426. indicesByPath[path] = index;
  26427. paths.push(path);
  26428. parsedPaths.push(parsedPath);
  26429. bindings.push(bindingsForPath);
  26430. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26431. var object = objects[i];
  26432. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26433. }
  26434. return bindingsForPath;
  26435. },
  26436. unsubscribe_: function unsubscribe_(path) {
  26437. // tells the group to forget about a property path and no longer
  26438. // update the array previously obtained with 'subscribe_'
  26439. var indicesByPath = this._bindingsIndicesByPath,
  26440. index = indicesByPath[path];
  26441. if (index !== undefined) {
  26442. var paths = this._paths,
  26443. parsedPaths = this._parsedPaths,
  26444. bindings = this._bindings,
  26445. lastBindingsIndex = bindings.length - 1,
  26446. lastBindings = bindings[lastBindingsIndex],
  26447. lastBindingsPath = path[lastBindingsIndex];
  26448. indicesByPath[lastBindingsPath] = index;
  26449. bindings[index] = lastBindings;
  26450. bindings.pop();
  26451. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26452. parsedPaths.pop();
  26453. paths[index] = paths[lastBindingsIndex];
  26454. paths.pop();
  26455. }
  26456. }
  26457. });
  26458. var AnimationAction = /*#__PURE__*/function () {
  26459. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26460. if (localRoot === void 0) {
  26461. localRoot = null;
  26462. }
  26463. if (blendMode === void 0) {
  26464. blendMode = clip.blendMode;
  26465. }
  26466. this._mixer = mixer;
  26467. this._clip = clip;
  26468. this._localRoot = localRoot;
  26469. this.blendMode = blendMode;
  26470. var tracks = clip.tracks,
  26471. nTracks = tracks.length,
  26472. interpolants = new Array(nTracks);
  26473. var interpolantSettings = {
  26474. endingStart: ZeroCurvatureEnding,
  26475. endingEnd: ZeroCurvatureEnding
  26476. };
  26477. for (var i = 0; i !== nTracks; ++i) {
  26478. var interpolant = tracks[i].createInterpolant(null);
  26479. interpolants[i] = interpolant;
  26480. interpolant.settings = interpolantSettings;
  26481. }
  26482. this._interpolantSettings = interpolantSettings;
  26483. this._interpolants = interpolants; // bound by the mixer
  26484. // inside: PropertyMixer (managed by the mixer)
  26485. this._propertyBindings = new Array(nTracks);
  26486. this._cacheIndex = null; // for the memory manager
  26487. this._byClipCacheIndex = null; // for the memory manager
  26488. this._timeScaleInterpolant = null;
  26489. this._weightInterpolant = null;
  26490. this.loop = LoopRepeat;
  26491. this._loopCount = -1; // global mixer time when the action is to be started
  26492. // it's set back to 'null' upon start of the action
  26493. this._startTime = null; // scaled local time of the action
  26494. // gets clamped or wrapped to 0..clip.duration according to loop
  26495. this.time = 0;
  26496. this.timeScale = 1;
  26497. this._effectiveTimeScale = 1;
  26498. this.weight = 1;
  26499. this._effectiveWeight = 1;
  26500. this.repetitions = Infinity; // no. of repetitions when looping
  26501. this.paused = false; // true -> zero effective time scale
  26502. this.enabled = true; // false -> zero effective weight
  26503. this.clampWhenFinished = false; // keep feeding the last frame?
  26504. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26505. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26506. } // State & Scheduling
  26507. var _proto = AnimationAction.prototype;
  26508. _proto.play = function play() {
  26509. this._mixer._activateAction(this);
  26510. return this;
  26511. };
  26512. _proto.stop = function stop() {
  26513. this._mixer._deactivateAction(this);
  26514. return this.reset();
  26515. };
  26516. _proto.reset = function reset() {
  26517. this.paused = false;
  26518. this.enabled = true;
  26519. this.time = 0; // restart clip
  26520. this._loopCount = -1; // forget previous loops
  26521. this._startTime = null; // forget scheduling
  26522. return this.stopFading().stopWarping();
  26523. };
  26524. _proto.isRunning = function isRunning() {
  26525. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26526. } // return true when play has been called
  26527. ;
  26528. _proto.isScheduled = function isScheduled() {
  26529. return this._mixer._isActiveAction(this);
  26530. };
  26531. _proto.startAt = function startAt(time) {
  26532. this._startTime = time;
  26533. return this;
  26534. };
  26535. _proto.setLoop = function setLoop(mode, repetitions) {
  26536. this.loop = mode;
  26537. this.repetitions = repetitions;
  26538. return this;
  26539. } // Weight
  26540. // set the weight stopping any scheduled fading
  26541. // although .enabled = false yields an effective weight of zero, this
  26542. // method does *not* change .enabled, because it would be confusing
  26543. ;
  26544. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26545. this.weight = weight; // note: same logic as when updated at runtime
  26546. this._effectiveWeight = this.enabled ? weight : 0;
  26547. return this.stopFading();
  26548. } // return the weight considering fading and .enabled
  26549. ;
  26550. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26551. return this._effectiveWeight;
  26552. };
  26553. _proto.fadeIn = function fadeIn(duration) {
  26554. return this._scheduleFading(duration, 0, 1);
  26555. };
  26556. _proto.fadeOut = function fadeOut(duration) {
  26557. return this._scheduleFading(duration, 1, 0);
  26558. };
  26559. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26560. fadeOutAction.fadeOut(duration);
  26561. this.fadeIn(duration);
  26562. if (warp) {
  26563. var fadeInDuration = this._clip.duration,
  26564. fadeOutDuration = fadeOutAction._clip.duration,
  26565. startEndRatio = fadeOutDuration / fadeInDuration,
  26566. endStartRatio = fadeInDuration / fadeOutDuration;
  26567. fadeOutAction.warp(1.0, startEndRatio, duration);
  26568. this.warp(endStartRatio, 1.0, duration);
  26569. }
  26570. return this;
  26571. };
  26572. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26573. return fadeInAction.crossFadeFrom(this, duration, warp);
  26574. };
  26575. _proto.stopFading = function stopFading() {
  26576. var weightInterpolant = this._weightInterpolant;
  26577. if (weightInterpolant !== null) {
  26578. this._weightInterpolant = null;
  26579. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26580. }
  26581. return this;
  26582. } // Time Scale Control
  26583. // set the time scale stopping any scheduled warping
  26584. // although .paused = true yields an effective time scale of zero, this
  26585. // method does *not* change .paused, because it would be confusing
  26586. ;
  26587. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26588. this.timeScale = timeScale;
  26589. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26590. return this.stopWarping();
  26591. } // return the time scale considering warping and .paused
  26592. ;
  26593. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26594. return this._effectiveTimeScale;
  26595. };
  26596. _proto.setDuration = function setDuration(duration) {
  26597. this.timeScale = this._clip.duration / duration;
  26598. return this.stopWarping();
  26599. };
  26600. _proto.syncWith = function syncWith(action) {
  26601. this.time = action.time;
  26602. this.timeScale = action.timeScale;
  26603. return this.stopWarping();
  26604. };
  26605. _proto.halt = function halt(duration) {
  26606. return this.warp(this._effectiveTimeScale, 0, duration);
  26607. };
  26608. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26609. var mixer = this._mixer,
  26610. now = mixer.time,
  26611. timeScale = this.timeScale;
  26612. var interpolant = this._timeScaleInterpolant;
  26613. if (interpolant === null) {
  26614. interpolant = mixer._lendControlInterpolant();
  26615. this._timeScaleInterpolant = interpolant;
  26616. }
  26617. var times = interpolant.parameterPositions,
  26618. values = interpolant.sampleValues;
  26619. times[0] = now;
  26620. times[1] = now + duration;
  26621. values[0] = startTimeScale / timeScale;
  26622. values[1] = endTimeScale / timeScale;
  26623. return this;
  26624. };
  26625. _proto.stopWarping = function stopWarping() {
  26626. var timeScaleInterpolant = this._timeScaleInterpolant;
  26627. if (timeScaleInterpolant !== null) {
  26628. this._timeScaleInterpolant = null;
  26629. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26630. }
  26631. return this;
  26632. } // Object Accessors
  26633. ;
  26634. _proto.getMixer = function getMixer() {
  26635. return this._mixer;
  26636. };
  26637. _proto.getClip = function getClip() {
  26638. return this._clip;
  26639. };
  26640. _proto.getRoot = function getRoot() {
  26641. return this._localRoot || this._mixer._root;
  26642. } // Interna
  26643. ;
  26644. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26645. // called by the mixer
  26646. if (!this.enabled) {
  26647. // call ._updateWeight() to update ._effectiveWeight
  26648. this._updateWeight(time);
  26649. return;
  26650. }
  26651. var startTime = this._startTime;
  26652. if (startTime !== null) {
  26653. // check for scheduled start of action
  26654. var timeRunning = (time - startTime) * timeDirection;
  26655. if (timeRunning < 0 || timeDirection === 0) {
  26656. return; // yet to come / don't decide when delta = 0
  26657. } // start
  26658. this._startTime = null; // unschedule
  26659. deltaTime = timeDirection * timeRunning;
  26660. } // apply time scale and advance time
  26661. deltaTime *= this._updateTimeScale(time);
  26662. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26663. // an effective weight of 0
  26664. var weight = this._updateWeight(time);
  26665. if (weight > 0) {
  26666. var _interpolants = this._interpolants;
  26667. var propertyMixers = this._propertyBindings;
  26668. switch (this.blendMode) {
  26669. case AdditiveAnimationBlendMode:
  26670. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26671. _interpolants[j].evaluate(clipTime);
  26672. propertyMixers[j].accumulateAdditive(weight);
  26673. }
  26674. break;
  26675. case NormalAnimationBlendMode:
  26676. default:
  26677. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26678. _interpolants[_j].evaluate(clipTime);
  26679. propertyMixers[_j].accumulate(accuIndex, weight);
  26680. }
  26681. }
  26682. }
  26683. };
  26684. _proto._updateWeight = function _updateWeight(time) {
  26685. var weight = 0;
  26686. if (this.enabled) {
  26687. weight = this.weight;
  26688. var interpolant = this._weightInterpolant;
  26689. if (interpolant !== null) {
  26690. var interpolantValue = interpolant.evaluate(time)[0];
  26691. weight *= interpolantValue;
  26692. if (time > interpolant.parameterPositions[1]) {
  26693. this.stopFading();
  26694. if (interpolantValue === 0) {
  26695. // faded out, disable
  26696. this.enabled = false;
  26697. }
  26698. }
  26699. }
  26700. }
  26701. this._effectiveWeight = weight;
  26702. return weight;
  26703. };
  26704. _proto._updateTimeScale = function _updateTimeScale(time) {
  26705. var timeScale = 0;
  26706. if (!this.paused) {
  26707. timeScale = this.timeScale;
  26708. var interpolant = this._timeScaleInterpolant;
  26709. if (interpolant !== null) {
  26710. var interpolantValue = interpolant.evaluate(time)[0];
  26711. timeScale *= interpolantValue;
  26712. if (time > interpolant.parameterPositions[1]) {
  26713. this.stopWarping();
  26714. if (timeScale === 0) {
  26715. // motion has halted, pause
  26716. this.paused = true;
  26717. } else {
  26718. // warp done - apply final time scale
  26719. this.timeScale = timeScale;
  26720. }
  26721. }
  26722. }
  26723. }
  26724. this._effectiveTimeScale = timeScale;
  26725. return timeScale;
  26726. };
  26727. _proto._updateTime = function _updateTime(deltaTime) {
  26728. var duration = this._clip.duration;
  26729. var loop = this.loop;
  26730. var time = this.time + deltaTime;
  26731. var loopCount = this._loopCount;
  26732. var pingPong = loop === LoopPingPong;
  26733. if (deltaTime === 0) {
  26734. if (loopCount === -1) return time;
  26735. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26736. }
  26737. if (loop === LoopOnce) {
  26738. if (loopCount === -1) {
  26739. // just started
  26740. this._loopCount = 0;
  26741. this._setEndings(true, true, false);
  26742. }
  26743. handle_stop: {
  26744. if (time >= duration) {
  26745. time = duration;
  26746. } else if (time < 0) {
  26747. time = 0;
  26748. } else {
  26749. this.time = time;
  26750. break handle_stop;
  26751. }
  26752. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26753. this.time = time;
  26754. this._mixer.dispatchEvent({
  26755. type: 'finished',
  26756. action: this,
  26757. direction: deltaTime < 0 ? -1 : 1
  26758. });
  26759. }
  26760. } else {
  26761. // repetitive Repeat or PingPong
  26762. if (loopCount === -1) {
  26763. // just started
  26764. if (deltaTime >= 0) {
  26765. loopCount = 0;
  26766. this._setEndings(true, this.repetitions === 0, pingPong);
  26767. } else {
  26768. // when looping in reverse direction, the initial
  26769. // transition through zero counts as a repetition,
  26770. // so leave loopCount at -1
  26771. this._setEndings(this.repetitions === 0, true, pingPong);
  26772. }
  26773. }
  26774. if (time >= duration || time < 0) {
  26775. // wrap around
  26776. var loopDelta = Math.floor(time / duration); // signed
  26777. time -= duration * loopDelta;
  26778. loopCount += Math.abs(loopDelta);
  26779. var pending = this.repetitions - loopCount;
  26780. if (pending <= 0) {
  26781. // have to stop (switch state, clamp time, fire event)
  26782. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26783. time = deltaTime > 0 ? duration : 0;
  26784. this.time = time;
  26785. this._mixer.dispatchEvent({
  26786. type: 'finished',
  26787. action: this,
  26788. direction: deltaTime > 0 ? 1 : -1
  26789. });
  26790. } else {
  26791. // keep running
  26792. if (pending === 1) {
  26793. // entering the last round
  26794. var atStart = deltaTime < 0;
  26795. this._setEndings(atStart, !atStart, pingPong);
  26796. } else {
  26797. this._setEndings(false, false, pingPong);
  26798. }
  26799. this._loopCount = loopCount;
  26800. this.time = time;
  26801. this._mixer.dispatchEvent({
  26802. type: 'loop',
  26803. action: this,
  26804. loopDelta: loopDelta
  26805. });
  26806. }
  26807. } else {
  26808. this.time = time;
  26809. }
  26810. if (pingPong && (loopCount & 1) === 1) {
  26811. // invert time for the "pong round"
  26812. return duration - time;
  26813. }
  26814. }
  26815. return time;
  26816. };
  26817. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26818. var settings = this._interpolantSettings;
  26819. if (pingPong) {
  26820. settings.endingStart = ZeroSlopeEnding;
  26821. settings.endingEnd = ZeroSlopeEnding;
  26822. } else {
  26823. // assuming for LoopOnce atStart == atEnd == true
  26824. if (atStart) {
  26825. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26826. } else {
  26827. settings.endingStart = WrapAroundEnding;
  26828. }
  26829. if (atEnd) {
  26830. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26831. } else {
  26832. settings.endingEnd = WrapAroundEnding;
  26833. }
  26834. }
  26835. };
  26836. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26837. var mixer = this._mixer,
  26838. now = mixer.time;
  26839. var interpolant = this._weightInterpolant;
  26840. if (interpolant === null) {
  26841. interpolant = mixer._lendControlInterpolant();
  26842. this._weightInterpolant = interpolant;
  26843. }
  26844. var times = interpolant.parameterPositions,
  26845. values = interpolant.sampleValues;
  26846. times[0] = now;
  26847. values[0] = weightNow;
  26848. times[1] = now + duration;
  26849. values[1] = weightThen;
  26850. return this;
  26851. };
  26852. return AnimationAction;
  26853. }();
  26854. function AnimationMixer(root) {
  26855. this._root = root;
  26856. this._initMemoryManager();
  26857. this._accuIndex = 0;
  26858. this.time = 0;
  26859. this.timeScale = 1.0;
  26860. }
  26861. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26862. constructor: AnimationMixer,
  26863. _bindAction: function _bindAction(action, prototypeAction) {
  26864. var root = action._localRoot || this._root,
  26865. tracks = action._clip.tracks,
  26866. nTracks = tracks.length,
  26867. bindings = action._propertyBindings,
  26868. interpolants = action._interpolants,
  26869. rootUuid = root.uuid,
  26870. bindingsByRoot = this._bindingsByRootAndName;
  26871. var bindingsByName = bindingsByRoot[rootUuid];
  26872. if (bindingsByName === undefined) {
  26873. bindingsByName = {};
  26874. bindingsByRoot[rootUuid] = bindingsByName;
  26875. }
  26876. for (var i = 0; i !== nTracks; ++i) {
  26877. var track = tracks[i],
  26878. trackName = track.name;
  26879. var binding = bindingsByName[trackName];
  26880. if (binding !== undefined) {
  26881. bindings[i] = binding;
  26882. } else {
  26883. binding = bindings[i];
  26884. if (binding !== undefined) {
  26885. // existing binding, make sure the cache knows
  26886. if (binding._cacheIndex === null) {
  26887. ++binding.referenceCount;
  26888. this._addInactiveBinding(binding, rootUuid, trackName);
  26889. }
  26890. continue;
  26891. }
  26892. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26893. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26894. ++binding.referenceCount;
  26895. this._addInactiveBinding(binding, rootUuid, trackName);
  26896. bindings[i] = binding;
  26897. }
  26898. interpolants[i].resultBuffer = binding.buffer;
  26899. }
  26900. },
  26901. _activateAction: function _activateAction(action) {
  26902. if (!this._isActiveAction(action)) {
  26903. if (action._cacheIndex === null) {
  26904. // this action has been forgotten by the cache, but the user
  26905. // appears to be still using it -> rebind
  26906. var rootUuid = (action._localRoot || this._root).uuid,
  26907. clipUuid = action._clip.uuid,
  26908. actionsForClip = this._actionsByClip[clipUuid];
  26909. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26910. this._addInactiveAction(action, clipUuid, rootUuid);
  26911. }
  26912. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26913. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26914. var binding = bindings[i];
  26915. if (binding.useCount++ === 0) {
  26916. this._lendBinding(binding);
  26917. binding.saveOriginalState();
  26918. }
  26919. }
  26920. this._lendAction(action);
  26921. }
  26922. },
  26923. _deactivateAction: function _deactivateAction(action) {
  26924. if (this._isActiveAction(action)) {
  26925. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26926. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26927. var binding = bindings[i];
  26928. if (--binding.useCount === 0) {
  26929. binding.restoreOriginalState();
  26930. this._takeBackBinding(binding);
  26931. }
  26932. }
  26933. this._takeBackAction(action);
  26934. }
  26935. },
  26936. // Memory manager
  26937. _initMemoryManager: function _initMemoryManager() {
  26938. this._actions = []; // 'nActiveActions' followed by inactive ones
  26939. this._nActiveActions = 0;
  26940. this._actionsByClip = {}; // inside:
  26941. // {
  26942. // knownActions: Array< AnimationAction > - used as prototypes
  26943. // actionByRoot: AnimationAction - lookup
  26944. // }
  26945. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26946. this._nActiveBindings = 0;
  26947. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26948. this._controlInterpolants = []; // same game as above
  26949. this._nActiveControlInterpolants = 0;
  26950. var scope = this;
  26951. this.stats = {
  26952. actions: {
  26953. get total() {
  26954. return scope._actions.length;
  26955. },
  26956. get inUse() {
  26957. return scope._nActiveActions;
  26958. }
  26959. },
  26960. bindings: {
  26961. get total() {
  26962. return scope._bindings.length;
  26963. },
  26964. get inUse() {
  26965. return scope._nActiveBindings;
  26966. }
  26967. },
  26968. controlInterpolants: {
  26969. get total() {
  26970. return scope._controlInterpolants.length;
  26971. },
  26972. get inUse() {
  26973. return scope._nActiveControlInterpolants;
  26974. }
  26975. }
  26976. };
  26977. },
  26978. // Memory management for AnimationAction objects
  26979. _isActiveAction: function _isActiveAction(action) {
  26980. var index = action._cacheIndex;
  26981. return index !== null && index < this._nActiveActions;
  26982. },
  26983. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26984. var actions = this._actions,
  26985. actionsByClip = this._actionsByClip;
  26986. var actionsForClip = actionsByClip[clipUuid];
  26987. if (actionsForClip === undefined) {
  26988. actionsForClip = {
  26989. knownActions: [action],
  26990. actionByRoot: {}
  26991. };
  26992. action._byClipCacheIndex = 0;
  26993. actionsByClip[clipUuid] = actionsForClip;
  26994. } else {
  26995. var knownActions = actionsForClip.knownActions;
  26996. action._byClipCacheIndex = knownActions.length;
  26997. knownActions.push(action);
  26998. }
  26999. action._cacheIndex = actions.length;
  27000. actions.push(action);
  27001. actionsForClip.actionByRoot[rootUuid] = action;
  27002. },
  27003. _removeInactiveAction: function _removeInactiveAction(action) {
  27004. var actions = this._actions,
  27005. lastInactiveAction = actions[actions.length - 1],
  27006. cacheIndex = action._cacheIndex;
  27007. lastInactiveAction._cacheIndex = cacheIndex;
  27008. actions[cacheIndex] = lastInactiveAction;
  27009. actions.pop();
  27010. action._cacheIndex = null;
  27011. var clipUuid = action._clip.uuid,
  27012. actionsByClip = this._actionsByClip,
  27013. actionsForClip = actionsByClip[clipUuid],
  27014. knownActionsForClip = actionsForClip.knownActions,
  27015. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  27016. byClipCacheIndex = action._byClipCacheIndex;
  27017. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27018. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  27019. knownActionsForClip.pop();
  27020. action._byClipCacheIndex = null;
  27021. var actionByRoot = actionsForClip.actionByRoot,
  27022. rootUuid = (action._localRoot || this._root).uuid;
  27023. delete actionByRoot[rootUuid];
  27024. if (knownActionsForClip.length === 0) {
  27025. delete actionsByClip[clipUuid];
  27026. }
  27027. this._removeInactiveBindingsForAction(action);
  27028. },
  27029. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  27030. var bindings = action._propertyBindings;
  27031. for (var i = 0, n = bindings.length; i !== n; ++i) {
  27032. var binding = bindings[i];
  27033. if (--binding.referenceCount === 0) {
  27034. this._removeInactiveBinding(binding);
  27035. }
  27036. }
  27037. },
  27038. _lendAction: function _lendAction(action) {
  27039. // [ active actions | inactive actions ]
  27040. // [ active actions >| inactive actions ]
  27041. // s a
  27042. // <-swap->
  27043. // a s
  27044. var actions = this._actions,
  27045. prevIndex = action._cacheIndex,
  27046. lastActiveIndex = this._nActiveActions++,
  27047. firstInactiveAction = actions[lastActiveIndex];
  27048. action._cacheIndex = lastActiveIndex;
  27049. actions[lastActiveIndex] = action;
  27050. firstInactiveAction._cacheIndex = prevIndex;
  27051. actions[prevIndex] = firstInactiveAction;
  27052. },
  27053. _takeBackAction: function _takeBackAction(action) {
  27054. // [ active actions | inactive actions ]
  27055. // [ active actions |< inactive actions ]
  27056. // a s
  27057. // <-swap->
  27058. // s a
  27059. var actions = this._actions,
  27060. prevIndex = action._cacheIndex,
  27061. firstInactiveIndex = --this._nActiveActions,
  27062. lastActiveAction = actions[firstInactiveIndex];
  27063. action._cacheIndex = firstInactiveIndex;
  27064. actions[firstInactiveIndex] = action;
  27065. lastActiveAction._cacheIndex = prevIndex;
  27066. actions[prevIndex] = lastActiveAction;
  27067. },
  27068. // Memory management for PropertyMixer objects
  27069. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  27070. var bindingsByRoot = this._bindingsByRootAndName,
  27071. bindings = this._bindings;
  27072. var bindingByName = bindingsByRoot[rootUuid];
  27073. if (bindingByName === undefined) {
  27074. bindingByName = {};
  27075. bindingsByRoot[rootUuid] = bindingByName;
  27076. }
  27077. bindingByName[trackName] = binding;
  27078. binding._cacheIndex = bindings.length;
  27079. bindings.push(binding);
  27080. },
  27081. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  27082. var bindings = this._bindings,
  27083. propBinding = binding.binding,
  27084. rootUuid = propBinding.rootNode.uuid,
  27085. trackName = propBinding.path,
  27086. bindingsByRoot = this._bindingsByRootAndName,
  27087. bindingByName = bindingsByRoot[rootUuid],
  27088. lastInactiveBinding = bindings[bindings.length - 1],
  27089. cacheIndex = binding._cacheIndex;
  27090. lastInactiveBinding._cacheIndex = cacheIndex;
  27091. bindings[cacheIndex] = lastInactiveBinding;
  27092. bindings.pop();
  27093. delete bindingByName[trackName];
  27094. if (Object.keys(bindingByName).length === 0) {
  27095. delete bindingsByRoot[rootUuid];
  27096. }
  27097. },
  27098. _lendBinding: function _lendBinding(binding) {
  27099. var bindings = this._bindings,
  27100. prevIndex = binding._cacheIndex,
  27101. lastActiveIndex = this._nActiveBindings++,
  27102. firstInactiveBinding = bindings[lastActiveIndex];
  27103. binding._cacheIndex = lastActiveIndex;
  27104. bindings[lastActiveIndex] = binding;
  27105. firstInactiveBinding._cacheIndex = prevIndex;
  27106. bindings[prevIndex] = firstInactiveBinding;
  27107. },
  27108. _takeBackBinding: function _takeBackBinding(binding) {
  27109. var bindings = this._bindings,
  27110. prevIndex = binding._cacheIndex,
  27111. firstInactiveIndex = --this._nActiveBindings,
  27112. lastActiveBinding = bindings[firstInactiveIndex];
  27113. binding._cacheIndex = firstInactiveIndex;
  27114. bindings[firstInactiveIndex] = binding;
  27115. lastActiveBinding._cacheIndex = prevIndex;
  27116. bindings[prevIndex] = lastActiveBinding;
  27117. },
  27118. // Memory management of Interpolants for weight and time scale
  27119. _lendControlInterpolant: function _lendControlInterpolant() {
  27120. var interpolants = this._controlInterpolants,
  27121. lastActiveIndex = this._nActiveControlInterpolants++;
  27122. var interpolant = interpolants[lastActiveIndex];
  27123. if (interpolant === undefined) {
  27124. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  27125. interpolant.__cacheIndex = lastActiveIndex;
  27126. interpolants[lastActiveIndex] = interpolant;
  27127. }
  27128. return interpolant;
  27129. },
  27130. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  27131. var interpolants = this._controlInterpolants,
  27132. prevIndex = interpolant.__cacheIndex,
  27133. firstInactiveIndex = --this._nActiveControlInterpolants,
  27134. lastActiveInterpolant = interpolants[firstInactiveIndex];
  27135. interpolant.__cacheIndex = firstInactiveIndex;
  27136. interpolants[firstInactiveIndex] = interpolant;
  27137. lastActiveInterpolant.__cacheIndex = prevIndex;
  27138. interpolants[prevIndex] = lastActiveInterpolant;
  27139. },
  27140. _controlInterpolantsResultBuffer: new Float32Array(1),
  27141. // return an action for a clip optionally using a custom root target
  27142. // object (this method allocates a lot of dynamic memory in case a
  27143. // previously unknown clip/root combination is specified)
  27144. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  27145. var root = optionalRoot || this._root,
  27146. rootUuid = root.uuid;
  27147. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  27148. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27149. var actionsForClip = this._actionsByClip[clipUuid];
  27150. var prototypeAction = null;
  27151. if (blendMode === undefined) {
  27152. if (clipObject !== null) {
  27153. blendMode = clipObject.blendMode;
  27154. } else {
  27155. blendMode = NormalAnimationBlendMode;
  27156. }
  27157. }
  27158. if (actionsForClip !== undefined) {
  27159. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27160. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27161. return existingAction;
  27162. } // we know the clip, so we don't have to parse all
  27163. // the bindings again but can just copy
  27164. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27165. if (clipObject === null) clipObject = prototypeAction._clip;
  27166. } // clip must be known when specified via string
  27167. if (clipObject === null) return null; // allocate all resources required to run it
  27168. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27169. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27170. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27171. return newAction;
  27172. },
  27173. // get an existing action
  27174. existingAction: function existingAction(clip, optionalRoot) {
  27175. var root = optionalRoot || this._root,
  27176. rootUuid = root.uuid,
  27177. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27178. clipUuid = clipObject ? clipObject.uuid : clip,
  27179. actionsForClip = this._actionsByClip[clipUuid];
  27180. if (actionsForClip !== undefined) {
  27181. return actionsForClip.actionByRoot[rootUuid] || null;
  27182. }
  27183. return null;
  27184. },
  27185. // deactivates all previously scheduled actions
  27186. stopAllAction: function stopAllAction() {
  27187. var actions = this._actions,
  27188. nActions = this._nActiveActions;
  27189. for (var i = nActions - 1; i >= 0; --i) {
  27190. actions[i].stop();
  27191. }
  27192. return this;
  27193. },
  27194. // advance the time and update apply the animation
  27195. update: function update(deltaTime) {
  27196. deltaTime *= this.timeScale;
  27197. var actions = this._actions,
  27198. nActions = this._nActiveActions,
  27199. time = this.time += deltaTime,
  27200. timeDirection = Math.sign(deltaTime),
  27201. accuIndex = this._accuIndex ^= 1; // run active actions
  27202. for (var i = 0; i !== nActions; ++i) {
  27203. var action = actions[i];
  27204. action._update(time, deltaTime, timeDirection, accuIndex);
  27205. } // update scene graph
  27206. var bindings = this._bindings,
  27207. nBindings = this._nActiveBindings;
  27208. for (var _i = 0; _i !== nBindings; ++_i) {
  27209. bindings[_i].apply(accuIndex);
  27210. }
  27211. return this;
  27212. },
  27213. // Allows you to seek to a specific time in an animation.
  27214. setTime: function setTime(timeInSeconds) {
  27215. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27216. for (var i = 0; i < this._actions.length; i++) {
  27217. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27218. }
  27219. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27220. },
  27221. // return this mixer's root target object
  27222. getRoot: function getRoot() {
  27223. return this._root;
  27224. },
  27225. // free all resources specific to a particular clip
  27226. uncacheClip: function uncacheClip(clip) {
  27227. var actions = this._actions,
  27228. clipUuid = clip.uuid,
  27229. actionsByClip = this._actionsByClip,
  27230. actionsForClip = actionsByClip[clipUuid];
  27231. if (actionsForClip !== undefined) {
  27232. // note: just calling _removeInactiveAction would mess up the
  27233. // iteration state and also require updating the state we can
  27234. // just throw away
  27235. var actionsToRemove = actionsForClip.knownActions;
  27236. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27237. var action = actionsToRemove[i];
  27238. this._deactivateAction(action);
  27239. var cacheIndex = action._cacheIndex,
  27240. lastInactiveAction = actions[actions.length - 1];
  27241. action._cacheIndex = null;
  27242. action._byClipCacheIndex = null;
  27243. lastInactiveAction._cacheIndex = cacheIndex;
  27244. actions[cacheIndex] = lastInactiveAction;
  27245. actions.pop();
  27246. this._removeInactiveBindingsForAction(action);
  27247. }
  27248. delete actionsByClip[clipUuid];
  27249. }
  27250. },
  27251. // free all resources specific to a particular root target object
  27252. uncacheRoot: function uncacheRoot(root) {
  27253. var rootUuid = root.uuid,
  27254. actionsByClip = this._actionsByClip;
  27255. for (var clipUuid in actionsByClip) {
  27256. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27257. action = actionByRoot[rootUuid];
  27258. if (action !== undefined) {
  27259. this._deactivateAction(action);
  27260. this._removeInactiveAction(action);
  27261. }
  27262. }
  27263. var bindingsByRoot = this._bindingsByRootAndName,
  27264. bindingByName = bindingsByRoot[rootUuid];
  27265. if (bindingByName !== undefined) {
  27266. for (var trackName in bindingByName) {
  27267. var binding = bindingByName[trackName];
  27268. binding.restoreOriginalState();
  27269. this._removeInactiveBinding(binding);
  27270. }
  27271. }
  27272. },
  27273. // remove a targeted clip from the cache
  27274. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27275. var action = this.existingAction(clip, optionalRoot);
  27276. if (action !== null) {
  27277. this._deactivateAction(action);
  27278. this._removeInactiveAction(action);
  27279. }
  27280. }
  27281. });
  27282. var Uniform = /*#__PURE__*/function () {
  27283. function Uniform(value) {
  27284. if (typeof value === 'string') {
  27285. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27286. value = arguments[1];
  27287. }
  27288. this.value = value;
  27289. }
  27290. var _proto = Uniform.prototype;
  27291. _proto.clone = function clone() {
  27292. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27293. };
  27294. return Uniform;
  27295. }();
  27296. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27297. InterleavedBuffer.call(this, array, stride);
  27298. this.meshPerAttribute = meshPerAttribute || 1;
  27299. }
  27300. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27301. constructor: InstancedInterleavedBuffer,
  27302. isInstancedInterleavedBuffer: true,
  27303. copy: function copy(source) {
  27304. InterleavedBuffer.prototype.copy.call(this, source);
  27305. this.meshPerAttribute = source.meshPerAttribute;
  27306. return this;
  27307. },
  27308. clone: function clone(data) {
  27309. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27310. ib.meshPerAttribute = this.meshPerAttribute;
  27311. return ib;
  27312. },
  27313. toJSON: function toJSON(data) {
  27314. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27315. json.isInstancedInterleavedBuffer = true;
  27316. json.meshPerAttribute = this.meshPerAttribute;
  27317. return json;
  27318. }
  27319. });
  27320. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27321. this.buffer = buffer;
  27322. this.type = type;
  27323. this.itemSize = itemSize;
  27324. this.elementSize = elementSize;
  27325. this.count = count;
  27326. this.version = 0;
  27327. }
  27328. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27329. set: function set(value) {
  27330. if (value === true) this.version++;
  27331. }
  27332. });
  27333. Object.assign(GLBufferAttribute.prototype, {
  27334. isGLBufferAttribute: true,
  27335. setBuffer: function setBuffer(buffer) {
  27336. this.buffer = buffer;
  27337. return this;
  27338. },
  27339. setType: function setType(type, elementSize) {
  27340. this.type = type;
  27341. this.elementSize = elementSize;
  27342. return this;
  27343. },
  27344. setItemSize: function setItemSize(itemSize) {
  27345. this.itemSize = itemSize;
  27346. return this;
  27347. },
  27348. setCount: function setCount(count) {
  27349. this.count = count;
  27350. return this;
  27351. }
  27352. });
  27353. function Raycaster(origin, direction, near, far) {
  27354. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27355. this.near = near || 0;
  27356. this.far = far || Infinity;
  27357. this.camera = null;
  27358. this.layers = new Layers();
  27359. this.params = {
  27360. Mesh: {},
  27361. Line: {
  27362. threshold: 1
  27363. },
  27364. LOD: {},
  27365. Points: {
  27366. threshold: 1
  27367. },
  27368. Sprite: {}
  27369. };
  27370. Object.defineProperties(this.params, {
  27371. PointCloud: {
  27372. get: function get() {
  27373. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27374. return this.Points;
  27375. }
  27376. }
  27377. });
  27378. }
  27379. function ascSort(a, b) {
  27380. return a.distance - b.distance;
  27381. }
  27382. function _intersectObject(object, raycaster, intersects, recursive) {
  27383. if (object.layers.test(raycaster.layers)) {
  27384. object.raycast(raycaster, intersects);
  27385. }
  27386. if (recursive === true) {
  27387. var children = object.children;
  27388. for (var i = 0, l = children.length; i < l; i++) {
  27389. _intersectObject(children[i], raycaster, intersects, true);
  27390. }
  27391. }
  27392. }
  27393. Object.assign(Raycaster.prototype, {
  27394. set: function set(origin, direction) {
  27395. // direction is assumed to be normalized (for accurate distance calculations)
  27396. this.ray.set(origin, direction);
  27397. },
  27398. setFromCamera: function setFromCamera(coords, camera) {
  27399. if (camera && camera.isPerspectiveCamera) {
  27400. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27401. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27402. this.camera = camera;
  27403. } else if (camera && camera.isOrthographicCamera) {
  27404. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27405. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27406. this.camera = camera;
  27407. } else {
  27408. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27409. }
  27410. },
  27411. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27412. var intersects = optionalTarget || [];
  27413. _intersectObject(object, this, intersects, recursive);
  27414. intersects.sort(ascSort);
  27415. return intersects;
  27416. },
  27417. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27418. var intersects = optionalTarget || [];
  27419. if (Array.isArray(objects) === false) {
  27420. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27421. return intersects;
  27422. }
  27423. for (var i = 0, l = objects.length; i < l; i++) {
  27424. _intersectObject(objects[i], this, intersects, recursive);
  27425. }
  27426. intersects.sort(ascSort);
  27427. return intersects;
  27428. }
  27429. });
  27430. /**
  27431. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27432. *
  27433. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27434. * The azimuthal angle (theta) is measured from the positive z-axis.
  27435. */
  27436. var Spherical = /*#__PURE__*/function () {
  27437. function Spherical(radius, phi, theta) {
  27438. if (radius === void 0) {
  27439. radius = 1;
  27440. }
  27441. if (phi === void 0) {
  27442. phi = 0;
  27443. }
  27444. if (theta === void 0) {
  27445. theta = 0;
  27446. }
  27447. this.radius = radius;
  27448. this.phi = phi; // polar angle
  27449. this.theta = theta; // azimuthal angle
  27450. return this;
  27451. }
  27452. var _proto = Spherical.prototype;
  27453. _proto.set = function set(radius, phi, theta) {
  27454. this.radius = radius;
  27455. this.phi = phi;
  27456. this.theta = theta;
  27457. return this;
  27458. };
  27459. _proto.clone = function clone() {
  27460. return new this.constructor().copy(this);
  27461. };
  27462. _proto.copy = function copy(other) {
  27463. this.radius = other.radius;
  27464. this.phi = other.phi;
  27465. this.theta = other.theta;
  27466. return this;
  27467. } // restrict phi to be betwee EPS and PI-EPS
  27468. ;
  27469. _proto.makeSafe = function makeSafe() {
  27470. var EPS = 0.000001;
  27471. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27472. return this;
  27473. };
  27474. _proto.setFromVector3 = function setFromVector3(v) {
  27475. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27476. };
  27477. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27478. this.radius = Math.sqrt(x * x + y * y + z * z);
  27479. if (this.radius === 0) {
  27480. this.theta = 0;
  27481. this.phi = 0;
  27482. } else {
  27483. this.theta = Math.atan2(x, z);
  27484. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27485. }
  27486. return this;
  27487. };
  27488. return Spherical;
  27489. }();
  27490. /**
  27491. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27492. */
  27493. var Cylindrical = /*#__PURE__*/function () {
  27494. function Cylindrical(radius, theta, y) {
  27495. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27496. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27497. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27498. return this;
  27499. }
  27500. var _proto = Cylindrical.prototype;
  27501. _proto.set = function set(radius, theta, y) {
  27502. this.radius = radius;
  27503. this.theta = theta;
  27504. this.y = y;
  27505. return this;
  27506. };
  27507. _proto.clone = function clone() {
  27508. return new this.constructor().copy(this);
  27509. };
  27510. _proto.copy = function copy(other) {
  27511. this.radius = other.radius;
  27512. this.theta = other.theta;
  27513. this.y = other.y;
  27514. return this;
  27515. };
  27516. _proto.setFromVector3 = function setFromVector3(v) {
  27517. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27518. };
  27519. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27520. this.radius = Math.sqrt(x * x + z * z);
  27521. this.theta = Math.atan2(x, z);
  27522. this.y = y;
  27523. return this;
  27524. };
  27525. return Cylindrical;
  27526. }();
  27527. var _vector$8 = /*@__PURE__*/new Vector2();
  27528. var Box2 = /*#__PURE__*/function () {
  27529. function Box2(min, max) {
  27530. Object.defineProperty(this, 'isBox2', {
  27531. value: true
  27532. });
  27533. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27534. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27535. }
  27536. var _proto = Box2.prototype;
  27537. _proto.set = function set(min, max) {
  27538. this.min.copy(min);
  27539. this.max.copy(max);
  27540. return this;
  27541. };
  27542. _proto.setFromPoints = function setFromPoints(points) {
  27543. this.makeEmpty();
  27544. for (var i = 0, il = points.length; i < il; i++) {
  27545. this.expandByPoint(points[i]);
  27546. }
  27547. return this;
  27548. };
  27549. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27550. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27551. this.min.copy(center).sub(halfSize);
  27552. this.max.copy(center).add(halfSize);
  27553. return this;
  27554. };
  27555. _proto.clone = function clone() {
  27556. return new this.constructor().copy(this);
  27557. };
  27558. _proto.copy = function copy(box) {
  27559. this.min.copy(box.min);
  27560. this.max.copy(box.max);
  27561. return this;
  27562. };
  27563. _proto.makeEmpty = function makeEmpty() {
  27564. this.min.x = this.min.y = +Infinity;
  27565. this.max.x = this.max.y = -Infinity;
  27566. return this;
  27567. };
  27568. _proto.isEmpty = function isEmpty() {
  27569. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27570. return this.max.x < this.min.x || this.max.y < this.min.y;
  27571. };
  27572. _proto.getCenter = function getCenter(target) {
  27573. if (target === undefined) {
  27574. console.warn('THREE.Box2: .getCenter() target is now required');
  27575. target = new Vector2();
  27576. }
  27577. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27578. };
  27579. _proto.getSize = function getSize(target) {
  27580. if (target === undefined) {
  27581. console.warn('THREE.Box2: .getSize() target is now required');
  27582. target = new Vector2();
  27583. }
  27584. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27585. };
  27586. _proto.expandByPoint = function expandByPoint(point) {
  27587. this.min.min(point);
  27588. this.max.max(point);
  27589. return this;
  27590. };
  27591. _proto.expandByVector = function expandByVector(vector) {
  27592. this.min.sub(vector);
  27593. this.max.add(vector);
  27594. return this;
  27595. };
  27596. _proto.expandByScalar = function expandByScalar(scalar) {
  27597. this.min.addScalar(-scalar);
  27598. this.max.addScalar(scalar);
  27599. return this;
  27600. };
  27601. _proto.containsPoint = function containsPoint(point) {
  27602. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27603. };
  27604. _proto.containsBox = function containsBox(box) {
  27605. 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;
  27606. };
  27607. _proto.getParameter = function getParameter(point, target) {
  27608. // This can potentially have a divide by zero if the box
  27609. // has a size dimension of 0.
  27610. if (target === undefined) {
  27611. console.warn('THREE.Box2: .getParameter() target is now required');
  27612. target = new Vector2();
  27613. }
  27614. 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));
  27615. };
  27616. _proto.intersectsBox = function intersectsBox(box) {
  27617. // using 4 splitting planes to rule out intersections
  27618. 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;
  27619. };
  27620. _proto.clampPoint = function clampPoint(point, target) {
  27621. if (target === undefined) {
  27622. console.warn('THREE.Box2: .clampPoint() target is now required');
  27623. target = new Vector2();
  27624. }
  27625. return target.copy(point).clamp(this.min, this.max);
  27626. };
  27627. _proto.distanceToPoint = function distanceToPoint(point) {
  27628. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27629. return clampedPoint.sub(point).length();
  27630. };
  27631. _proto.intersect = function intersect(box) {
  27632. this.min.max(box.min);
  27633. this.max.min(box.max);
  27634. return this;
  27635. };
  27636. _proto.union = function union(box) {
  27637. this.min.min(box.min);
  27638. this.max.max(box.max);
  27639. return this;
  27640. };
  27641. _proto.translate = function translate(offset) {
  27642. this.min.add(offset);
  27643. this.max.add(offset);
  27644. return this;
  27645. };
  27646. _proto.equals = function equals(box) {
  27647. return box.min.equals(this.min) && box.max.equals(this.max);
  27648. };
  27649. return Box2;
  27650. }();
  27651. var _startP = /*@__PURE__*/new Vector3();
  27652. var _startEnd = /*@__PURE__*/new Vector3();
  27653. var Line3 = /*#__PURE__*/function () {
  27654. function Line3(start, end) {
  27655. this.start = start !== undefined ? start : new Vector3();
  27656. this.end = end !== undefined ? end : new Vector3();
  27657. }
  27658. var _proto = Line3.prototype;
  27659. _proto.set = function set(start, end) {
  27660. this.start.copy(start);
  27661. this.end.copy(end);
  27662. return this;
  27663. };
  27664. _proto.clone = function clone() {
  27665. return new this.constructor().copy(this);
  27666. };
  27667. _proto.copy = function copy(line) {
  27668. this.start.copy(line.start);
  27669. this.end.copy(line.end);
  27670. return this;
  27671. };
  27672. _proto.getCenter = function getCenter(target) {
  27673. if (target === undefined) {
  27674. console.warn('THREE.Line3: .getCenter() target is now required');
  27675. target = new Vector3();
  27676. }
  27677. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27678. };
  27679. _proto.delta = function delta(target) {
  27680. if (target === undefined) {
  27681. console.warn('THREE.Line3: .delta() target is now required');
  27682. target = new Vector3();
  27683. }
  27684. return target.subVectors(this.end, this.start);
  27685. };
  27686. _proto.distanceSq = function distanceSq() {
  27687. return this.start.distanceToSquared(this.end);
  27688. };
  27689. _proto.distance = function distance() {
  27690. return this.start.distanceTo(this.end);
  27691. };
  27692. _proto.at = function at(t, target) {
  27693. if (target === undefined) {
  27694. console.warn('THREE.Line3: .at() target is now required');
  27695. target = new Vector3();
  27696. }
  27697. return this.delta(target).multiplyScalar(t).add(this.start);
  27698. };
  27699. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27700. _startP.subVectors(point, this.start);
  27701. _startEnd.subVectors(this.end, this.start);
  27702. var startEnd2 = _startEnd.dot(_startEnd);
  27703. var startEnd_startP = _startEnd.dot(_startP);
  27704. var t = startEnd_startP / startEnd2;
  27705. if (clampToLine) {
  27706. t = MathUtils.clamp(t, 0, 1);
  27707. }
  27708. return t;
  27709. };
  27710. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27711. var t = this.closestPointToPointParameter(point, clampToLine);
  27712. if (target === undefined) {
  27713. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27714. target = new Vector3();
  27715. }
  27716. return this.delta(target).multiplyScalar(t).add(this.start);
  27717. };
  27718. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27719. this.start.applyMatrix4(matrix);
  27720. this.end.applyMatrix4(matrix);
  27721. return this;
  27722. };
  27723. _proto.equals = function equals(line) {
  27724. return line.start.equals(this.start) && line.end.equals(this.end);
  27725. };
  27726. return Line3;
  27727. }();
  27728. function ImmediateRenderObject(material) {
  27729. Object3D.call(this);
  27730. this.material = material;
  27731. this.render = function ()
  27732. /* renderCallback */
  27733. {};
  27734. this.hasPositions = false;
  27735. this.hasNormals = false;
  27736. this.hasColors = false;
  27737. this.hasUvs = false;
  27738. this.positionArray = null;
  27739. this.normalArray = null;
  27740. this.colorArray = null;
  27741. this.uvArray = null;
  27742. this.count = 0;
  27743. }
  27744. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27745. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27746. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27747. var _vector$9 = /*@__PURE__*/new Vector3();
  27748. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27749. _inheritsLoose(SpotLightHelper, _Object3D);
  27750. function SpotLightHelper(light, color) {
  27751. var _this;
  27752. _this = _Object3D.call(this) || this;
  27753. _this.light = light;
  27754. _this.light.updateMatrixWorld();
  27755. _this.matrix = light.matrixWorld;
  27756. _this.matrixAutoUpdate = false;
  27757. _this.color = color;
  27758. var geometry = new BufferGeometry();
  27759. 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];
  27760. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27761. var p1 = i / l * Math.PI * 2;
  27762. var p2 = j / l * Math.PI * 2;
  27763. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27764. }
  27765. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27766. var material = new LineBasicMaterial({
  27767. fog: false,
  27768. toneMapped: false
  27769. });
  27770. _this.cone = new LineSegments(geometry, material);
  27771. _this.add(_this.cone);
  27772. _this.update();
  27773. return _this;
  27774. }
  27775. var _proto = SpotLightHelper.prototype;
  27776. _proto.dispose = function dispose() {
  27777. this.cone.geometry.dispose();
  27778. this.cone.material.dispose();
  27779. };
  27780. _proto.update = function update() {
  27781. this.light.updateMatrixWorld();
  27782. var coneLength = this.light.distance ? this.light.distance : 1000;
  27783. var coneWidth = coneLength * Math.tan(this.light.angle);
  27784. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27785. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  27786. this.cone.lookAt(_vector$9);
  27787. if (this.color !== undefined) {
  27788. this.cone.material.color.set(this.color);
  27789. } else {
  27790. this.cone.material.color.copy(this.light.color);
  27791. }
  27792. };
  27793. return SpotLightHelper;
  27794. }(Object3D);
  27795. var _vector$a = /*@__PURE__*/new Vector3();
  27796. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27797. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27798. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27799. _inheritsLoose(SkeletonHelper, _LineSegments);
  27800. function SkeletonHelper(object) {
  27801. var _this;
  27802. var bones = getBoneList(object);
  27803. var geometry = new BufferGeometry();
  27804. var vertices = [];
  27805. var colors = [];
  27806. var color1 = new Color(0, 0, 1);
  27807. var color2 = new Color(0, 1, 0);
  27808. for (var i = 0; i < bones.length; i++) {
  27809. var bone = bones[i];
  27810. if (bone.parent && bone.parent.isBone) {
  27811. vertices.push(0, 0, 0);
  27812. vertices.push(0, 0, 0);
  27813. colors.push(color1.r, color1.g, color1.b);
  27814. colors.push(color2.r, color2.g, color2.b);
  27815. }
  27816. }
  27817. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27818. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27819. var material = new LineBasicMaterial({
  27820. vertexColors: true,
  27821. depthTest: false,
  27822. depthWrite: false,
  27823. toneMapped: false,
  27824. transparent: true
  27825. });
  27826. _this = _LineSegments.call(this, geometry, material) || this;
  27827. _this.type = 'SkeletonHelper';
  27828. _this.isSkeletonHelper = true;
  27829. _this.root = object;
  27830. _this.bones = bones;
  27831. _this.matrix = object.matrixWorld;
  27832. _this.matrixAutoUpdate = false;
  27833. return _this;
  27834. }
  27835. var _proto = SkeletonHelper.prototype;
  27836. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27837. var bones = this.bones;
  27838. var geometry = this.geometry;
  27839. var position = geometry.getAttribute('position');
  27840. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  27841. for (var i = 0, j = 0; i < bones.length; i++) {
  27842. var bone = bones[i];
  27843. if (bone.parent && bone.parent.isBone) {
  27844. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27845. _vector$a.setFromMatrixPosition(_boneMatrix);
  27846. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  27847. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27848. _vector$a.setFromMatrixPosition(_boneMatrix);
  27849. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  27850. j += 2;
  27851. }
  27852. }
  27853. geometry.getAttribute('position').needsUpdate = true;
  27854. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27855. };
  27856. return SkeletonHelper;
  27857. }(LineSegments);
  27858. function getBoneList(object) {
  27859. var boneList = [];
  27860. if (object && object.isBone) {
  27861. boneList.push(object);
  27862. }
  27863. for (var i = 0; i < object.children.length; i++) {
  27864. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27865. }
  27866. return boneList;
  27867. }
  27868. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27869. _inheritsLoose(PointLightHelper, _Mesh);
  27870. function PointLightHelper(light, sphereSize, color) {
  27871. var _this;
  27872. var geometry = new SphereGeometry(sphereSize, 4, 2);
  27873. var material = new MeshBasicMaterial({
  27874. wireframe: true,
  27875. fog: false,
  27876. toneMapped: false
  27877. });
  27878. _this = _Mesh.call(this, geometry, material) || this;
  27879. _this.light = light;
  27880. _this.light.updateMatrixWorld();
  27881. _this.color = color;
  27882. _this.type = 'PointLightHelper';
  27883. _this.matrix = _this.light.matrixWorld;
  27884. _this.matrixAutoUpdate = false;
  27885. _this.update();
  27886. /*
  27887. // TODO: delete this comment?
  27888. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27889. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27890. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27891. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27892. const d = light.distance;
  27893. if ( d === 0.0 ) {
  27894. this.lightDistance.visible = false;
  27895. } else {
  27896. this.lightDistance.scale.set( d, d, d );
  27897. }
  27898. this.add( this.lightDistance );
  27899. */
  27900. return _this;
  27901. }
  27902. var _proto = PointLightHelper.prototype;
  27903. _proto.dispose = function dispose() {
  27904. this.geometry.dispose();
  27905. this.material.dispose();
  27906. };
  27907. _proto.update = function update() {
  27908. if (this.color !== undefined) {
  27909. this.material.color.set(this.color);
  27910. } else {
  27911. this.material.color.copy(this.light.color);
  27912. }
  27913. /*
  27914. const d = this.light.distance;
  27915. if ( d === 0.0 ) {
  27916. this.lightDistance.visible = false;
  27917. } else {
  27918. this.lightDistance.visible = true;
  27919. this.lightDistance.scale.set( d, d, d );
  27920. }
  27921. */
  27922. };
  27923. return PointLightHelper;
  27924. }(Mesh);
  27925. var _vector$b = /*@__PURE__*/new Vector3();
  27926. var _color1 = /*@__PURE__*/new Color();
  27927. var _color2 = /*@__PURE__*/new Color();
  27928. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27929. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27930. function HemisphereLightHelper(light, size, color) {
  27931. var _this;
  27932. _this = _Object3D.call(this) || this;
  27933. _this.light = light;
  27934. _this.light.updateMatrixWorld();
  27935. _this.matrix = light.matrixWorld;
  27936. _this.matrixAutoUpdate = false;
  27937. _this.color = color;
  27938. var geometry = new OctahedronGeometry(size);
  27939. geometry.rotateY(Math.PI * 0.5);
  27940. _this.material = new MeshBasicMaterial({
  27941. wireframe: true,
  27942. fog: false,
  27943. toneMapped: false
  27944. });
  27945. if (_this.color === undefined) _this.material.vertexColors = true;
  27946. var position = geometry.getAttribute('position');
  27947. var colors = new Float32Array(position.count * 3);
  27948. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27949. _this.add(new Mesh(geometry, _this.material));
  27950. _this.update();
  27951. return _this;
  27952. }
  27953. var _proto = HemisphereLightHelper.prototype;
  27954. _proto.dispose = function dispose() {
  27955. this.children[0].geometry.dispose();
  27956. this.children[0].material.dispose();
  27957. };
  27958. _proto.update = function update() {
  27959. var mesh = this.children[0];
  27960. if (this.color !== undefined) {
  27961. this.material.color.set(this.color);
  27962. } else {
  27963. var colors = mesh.geometry.getAttribute('color');
  27964. _color1.copy(this.light.color);
  27965. _color2.copy(this.light.groundColor);
  27966. for (var i = 0, l = colors.count; i < l; i++) {
  27967. var color = i < l / 2 ? _color1 : _color2;
  27968. colors.setXYZ(i, color.r, color.g, color.b);
  27969. }
  27970. colors.needsUpdate = true;
  27971. }
  27972. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  27973. };
  27974. return HemisphereLightHelper;
  27975. }(Object3D);
  27976. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27977. _inheritsLoose(GridHelper, _LineSegments);
  27978. function GridHelper(size, divisions, color1, color2) {
  27979. var _this;
  27980. if (size === void 0) {
  27981. size = 10;
  27982. }
  27983. if (divisions === void 0) {
  27984. divisions = 10;
  27985. }
  27986. if (color1 === void 0) {
  27987. color1 = 0x444444;
  27988. }
  27989. if (color2 === void 0) {
  27990. color2 = 0x888888;
  27991. }
  27992. color1 = new Color(color1);
  27993. color2 = new Color(color2);
  27994. var center = divisions / 2;
  27995. var step = size / divisions;
  27996. var halfSize = size / 2;
  27997. var vertices = [],
  27998. colors = [];
  27999. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  28000. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  28001. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  28002. var color = i === center ? color1 : color2;
  28003. color.toArray(colors, j);
  28004. j += 3;
  28005. color.toArray(colors, j);
  28006. j += 3;
  28007. color.toArray(colors, j);
  28008. j += 3;
  28009. color.toArray(colors, j);
  28010. j += 3;
  28011. }
  28012. var geometry = new BufferGeometry();
  28013. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28014. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28015. var material = new LineBasicMaterial({
  28016. vertexColors: true,
  28017. toneMapped: false
  28018. });
  28019. _this = _LineSegments.call(this, geometry, material) || this;
  28020. _this.type = 'GridHelper';
  28021. return _this;
  28022. }
  28023. return GridHelper;
  28024. }(LineSegments);
  28025. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  28026. _inheritsLoose(PolarGridHelper, _LineSegments);
  28027. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  28028. var _this;
  28029. if (radius === void 0) {
  28030. radius = 10;
  28031. }
  28032. if (radials === void 0) {
  28033. radials = 16;
  28034. }
  28035. if (circles === void 0) {
  28036. circles = 8;
  28037. }
  28038. if (divisions === void 0) {
  28039. divisions = 64;
  28040. }
  28041. if (color1 === void 0) {
  28042. color1 = 0x444444;
  28043. }
  28044. if (color2 === void 0) {
  28045. color2 = 0x888888;
  28046. }
  28047. color1 = new Color(color1);
  28048. color2 = new Color(color2);
  28049. var vertices = [];
  28050. var colors = []; // create the radials
  28051. for (var i = 0; i <= radials; i++) {
  28052. var v = i / radials * (Math.PI * 2);
  28053. var x = Math.sin(v) * radius;
  28054. var z = Math.cos(v) * radius;
  28055. vertices.push(0, 0, 0);
  28056. vertices.push(x, 0, z);
  28057. var color = i & 1 ? color1 : color2;
  28058. colors.push(color.r, color.g, color.b);
  28059. colors.push(color.r, color.g, color.b);
  28060. } // create the circles
  28061. for (var _i = 0; _i <= circles; _i++) {
  28062. var _color = _i & 1 ? color1 : color2;
  28063. var r = radius - radius / circles * _i;
  28064. for (var j = 0; j < divisions; j++) {
  28065. // first vertex
  28066. var _v = j / divisions * (Math.PI * 2);
  28067. var _x = Math.sin(_v) * r;
  28068. var _z = Math.cos(_v) * r;
  28069. vertices.push(_x, 0, _z);
  28070. colors.push(_color.r, _color.g, _color.b); // second vertex
  28071. _v = (j + 1) / divisions * (Math.PI * 2);
  28072. _x = Math.sin(_v) * r;
  28073. _z = Math.cos(_v) * r;
  28074. vertices.push(_x, 0, _z);
  28075. colors.push(_color.r, _color.g, _color.b);
  28076. }
  28077. }
  28078. var geometry = new BufferGeometry();
  28079. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28080. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28081. var material = new LineBasicMaterial({
  28082. vertexColors: true,
  28083. toneMapped: false
  28084. });
  28085. _this = _LineSegments.call(this, geometry, material) || this;
  28086. _this.type = 'PolarGridHelper';
  28087. return _this;
  28088. }
  28089. return PolarGridHelper;
  28090. }(LineSegments);
  28091. var _v1$6 = /*@__PURE__*/new Vector3();
  28092. var _v2$3 = /*@__PURE__*/new Vector3();
  28093. var _v3$1 = /*@__PURE__*/new Vector3();
  28094. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  28095. _inheritsLoose(DirectionalLightHelper, _Object3D);
  28096. function DirectionalLightHelper(light, size, color) {
  28097. var _this;
  28098. _this = _Object3D.call(this) || this;
  28099. _this.light = light;
  28100. _this.light.updateMatrixWorld();
  28101. _this.matrix = light.matrixWorld;
  28102. _this.matrixAutoUpdate = false;
  28103. _this.color = color;
  28104. if (size === undefined) size = 1;
  28105. var geometry = new BufferGeometry();
  28106. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  28107. var material = new LineBasicMaterial({
  28108. fog: false,
  28109. toneMapped: false
  28110. });
  28111. _this.lightPlane = new Line(geometry, material);
  28112. _this.add(_this.lightPlane);
  28113. geometry = new BufferGeometry();
  28114. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  28115. _this.targetLine = new Line(geometry, material);
  28116. _this.add(_this.targetLine);
  28117. _this.update();
  28118. return _this;
  28119. }
  28120. var _proto = DirectionalLightHelper.prototype;
  28121. _proto.dispose = function dispose() {
  28122. this.lightPlane.geometry.dispose();
  28123. this.lightPlane.material.dispose();
  28124. this.targetLine.geometry.dispose();
  28125. this.targetLine.material.dispose();
  28126. };
  28127. _proto.update = function update() {
  28128. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  28129. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  28130. _v3$1.subVectors(_v2$3, _v1$6);
  28131. this.lightPlane.lookAt(_v2$3);
  28132. if (this.color !== undefined) {
  28133. this.lightPlane.material.color.set(this.color);
  28134. this.targetLine.material.color.set(this.color);
  28135. } else {
  28136. this.lightPlane.material.color.copy(this.light.color);
  28137. this.targetLine.material.color.copy(this.light.color);
  28138. }
  28139. this.targetLine.lookAt(_v2$3);
  28140. this.targetLine.scale.z = _v3$1.length();
  28141. };
  28142. return DirectionalLightHelper;
  28143. }(Object3D);
  28144. var _vector$c = /*@__PURE__*/new Vector3();
  28145. var _camera = /*@__PURE__*/new Camera();
  28146. /**
  28147. * - shows frustum, line of sight and up of the camera
  28148. * - suitable for fast updates
  28149. * - based on frustum visualization in lightgl.js shadowmap example
  28150. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28151. */
  28152. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  28153. _inheritsLoose(CameraHelper, _LineSegments);
  28154. function CameraHelper(camera) {
  28155. var _this;
  28156. var geometry = new BufferGeometry();
  28157. var material = new LineBasicMaterial({
  28158. color: 0xffffff,
  28159. vertexColors: true,
  28160. toneMapped: false
  28161. });
  28162. var vertices = [];
  28163. var colors = [];
  28164. var pointMap = {}; // colors
  28165. var colorFrustum = new Color(0xffaa00);
  28166. var colorCone = new Color(0xff0000);
  28167. var colorUp = new Color(0x00aaff);
  28168. var colorTarget = new Color(0xffffff);
  28169. var colorCross = new Color(0x333333); // near
  28170. addLine('n1', 'n2', colorFrustum);
  28171. addLine('n2', 'n4', colorFrustum);
  28172. addLine('n4', 'n3', colorFrustum);
  28173. addLine('n3', 'n1', colorFrustum); // far
  28174. addLine('f1', 'f2', colorFrustum);
  28175. addLine('f2', 'f4', colorFrustum);
  28176. addLine('f4', 'f3', colorFrustum);
  28177. addLine('f3', 'f1', colorFrustum); // sides
  28178. addLine('n1', 'f1', colorFrustum);
  28179. addLine('n2', 'f2', colorFrustum);
  28180. addLine('n3', 'f3', colorFrustum);
  28181. addLine('n4', 'f4', colorFrustum); // cone
  28182. addLine('p', 'n1', colorCone);
  28183. addLine('p', 'n2', colorCone);
  28184. addLine('p', 'n3', colorCone);
  28185. addLine('p', 'n4', colorCone); // up
  28186. addLine('u1', 'u2', colorUp);
  28187. addLine('u2', 'u3', colorUp);
  28188. addLine('u3', 'u1', colorUp); // target
  28189. addLine('c', 't', colorTarget);
  28190. addLine('p', 'c', colorCross); // cross
  28191. addLine('cn1', 'cn2', colorCross);
  28192. addLine('cn3', 'cn4', colorCross);
  28193. addLine('cf1', 'cf2', colorCross);
  28194. addLine('cf3', 'cf4', colorCross);
  28195. function addLine(a, b, color) {
  28196. addPoint(a, color);
  28197. addPoint(b, color);
  28198. }
  28199. function addPoint(id, color) {
  28200. vertices.push(0, 0, 0);
  28201. colors.push(color.r, color.g, color.b);
  28202. if (pointMap[id] === undefined) {
  28203. pointMap[id] = [];
  28204. }
  28205. pointMap[id].push(vertices.length / 3 - 1);
  28206. }
  28207. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28208. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28209. _this = _LineSegments.call(this, geometry, material) || this;
  28210. _this.type = 'CameraHelper';
  28211. _this.camera = camera;
  28212. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28213. _this.matrix = camera.matrixWorld;
  28214. _this.matrixAutoUpdate = false;
  28215. _this.pointMap = pointMap;
  28216. _this.update();
  28217. return _this;
  28218. }
  28219. var _proto = CameraHelper.prototype;
  28220. _proto.update = function update() {
  28221. var geometry = this.geometry;
  28222. var pointMap = this.pointMap;
  28223. var w = 1,
  28224. h = 1; // we need just camera projection matrix inverse
  28225. // world matrix must be identity
  28226. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28227. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28228. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28229. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28230. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28231. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28232. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28233. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28234. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28235. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28236. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28237. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28238. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28239. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28240. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28241. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28242. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28243. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28244. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28245. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28246. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28247. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28248. geometry.getAttribute('position').needsUpdate = true;
  28249. };
  28250. return CameraHelper;
  28251. }(LineSegments);
  28252. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28253. _vector$c.set(x, y, z).unproject(camera);
  28254. var points = pointMap[point];
  28255. if (points !== undefined) {
  28256. var position = geometry.getAttribute('position');
  28257. for (var i = 0, l = points.length; i < l; i++) {
  28258. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28259. }
  28260. }
  28261. }
  28262. var _box$3 = /*@__PURE__*/new Box3();
  28263. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28264. _inheritsLoose(BoxHelper, _LineSegments);
  28265. function BoxHelper(object, color) {
  28266. var _this;
  28267. if (color === void 0) {
  28268. color = 0xffff00;
  28269. }
  28270. 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]);
  28271. var positions = new Float32Array(8 * 3);
  28272. var geometry = new BufferGeometry();
  28273. geometry.setIndex(new BufferAttribute(indices, 1));
  28274. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28275. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28276. color: color,
  28277. toneMapped: false
  28278. })) || this;
  28279. _this.object = object;
  28280. _this.type = 'BoxHelper';
  28281. _this.matrixAutoUpdate = false;
  28282. _this.update();
  28283. return _this;
  28284. }
  28285. var _proto = BoxHelper.prototype;
  28286. _proto.update = function update(object) {
  28287. if (object !== undefined) {
  28288. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28289. }
  28290. if (this.object !== undefined) {
  28291. _box$3.setFromObject(this.object);
  28292. }
  28293. if (_box$3.isEmpty()) return;
  28294. var min = _box$3.min;
  28295. var max = _box$3.max;
  28296. /*
  28297. 5____4
  28298. 1/___0/|
  28299. | 6__|_7
  28300. 2/___3/
  28301. 0: max.x, max.y, max.z
  28302. 1: min.x, max.y, max.z
  28303. 2: min.x, min.y, max.z
  28304. 3: max.x, min.y, max.z
  28305. 4: max.x, max.y, min.z
  28306. 5: min.x, max.y, min.z
  28307. 6: min.x, min.y, min.z
  28308. 7: max.x, min.y, min.z
  28309. */
  28310. var position = this.geometry.attributes.position;
  28311. var array = position.array;
  28312. array[0] = max.x;
  28313. array[1] = max.y;
  28314. array[2] = max.z;
  28315. array[3] = min.x;
  28316. array[4] = max.y;
  28317. array[5] = max.z;
  28318. array[6] = min.x;
  28319. array[7] = min.y;
  28320. array[8] = max.z;
  28321. array[9] = max.x;
  28322. array[10] = min.y;
  28323. array[11] = max.z;
  28324. array[12] = max.x;
  28325. array[13] = max.y;
  28326. array[14] = min.z;
  28327. array[15] = min.x;
  28328. array[16] = max.y;
  28329. array[17] = min.z;
  28330. array[18] = min.x;
  28331. array[19] = min.y;
  28332. array[20] = min.z;
  28333. array[21] = max.x;
  28334. array[22] = min.y;
  28335. array[23] = min.z;
  28336. position.needsUpdate = true;
  28337. this.geometry.computeBoundingSphere();
  28338. };
  28339. _proto.setFromObject = function setFromObject(object) {
  28340. this.object = object;
  28341. this.update();
  28342. return this;
  28343. };
  28344. _proto.copy = function copy(source) {
  28345. LineSegments.prototype.copy.call(this, source);
  28346. this.object = source.object;
  28347. return this;
  28348. };
  28349. return BoxHelper;
  28350. }(LineSegments);
  28351. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28352. _inheritsLoose(Box3Helper, _LineSegments);
  28353. function Box3Helper(box, color) {
  28354. var _this;
  28355. if (color === void 0) {
  28356. color = 0xffff00;
  28357. }
  28358. 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]);
  28359. 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];
  28360. var geometry = new BufferGeometry();
  28361. geometry.setIndex(new BufferAttribute(indices, 1));
  28362. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28363. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28364. color: color,
  28365. toneMapped: false
  28366. })) || this;
  28367. _this.box = box;
  28368. _this.type = 'Box3Helper';
  28369. _this.geometry.computeBoundingSphere();
  28370. return _this;
  28371. }
  28372. var _proto = Box3Helper.prototype;
  28373. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28374. var box = this.box;
  28375. if (box.isEmpty()) return;
  28376. box.getCenter(this.position);
  28377. box.getSize(this.scale);
  28378. this.scale.multiplyScalar(0.5);
  28379. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28380. };
  28381. return Box3Helper;
  28382. }(LineSegments);
  28383. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28384. _inheritsLoose(PlaneHelper, _Line);
  28385. function PlaneHelper(plane, size, hex) {
  28386. var _this;
  28387. if (size === void 0) {
  28388. size = 1;
  28389. }
  28390. if (hex === void 0) {
  28391. hex = 0xffff00;
  28392. }
  28393. var color = hex;
  28394. 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];
  28395. var geometry = new BufferGeometry();
  28396. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28397. geometry.computeBoundingSphere();
  28398. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28399. color: color,
  28400. toneMapped: false
  28401. })) || this;
  28402. _this.type = 'PlaneHelper';
  28403. _this.plane = plane;
  28404. _this.size = size;
  28405. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28406. var geometry2 = new BufferGeometry();
  28407. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28408. geometry2.computeBoundingSphere();
  28409. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28410. color: color,
  28411. opacity: 0.2,
  28412. transparent: true,
  28413. depthWrite: false,
  28414. toneMapped: false
  28415. })));
  28416. return _this;
  28417. }
  28418. var _proto = PlaneHelper.prototype;
  28419. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28420. var scale = -this.plane.constant;
  28421. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28422. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28423. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28424. this.lookAt(this.plane.normal);
  28425. _Line.prototype.updateMatrixWorld.call(this, force);
  28426. };
  28427. return PlaneHelper;
  28428. }(Line);
  28429. var _axis = /*@__PURE__*/new Vector3();
  28430. var _lineGeometry, _coneGeometry;
  28431. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28432. _inheritsLoose(ArrowHelper, _Object3D);
  28433. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28434. var _this;
  28435. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28436. _this.type = 'ArrowHelper';
  28437. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28438. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28439. if (length === undefined) length = 1;
  28440. if (color === undefined) color = 0xffff00;
  28441. if (headLength === undefined) headLength = 0.2 * length;
  28442. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28443. if (_lineGeometry === undefined) {
  28444. _lineGeometry = new BufferGeometry();
  28445. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28446. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28447. _coneGeometry.translate(0, -0.5, 0);
  28448. }
  28449. _this.position.copy(origin);
  28450. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28451. color: color,
  28452. toneMapped: false
  28453. }));
  28454. _this.line.matrixAutoUpdate = false;
  28455. _this.add(_this.line);
  28456. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28457. color: color,
  28458. toneMapped: false
  28459. }));
  28460. _this.cone.matrixAutoUpdate = false;
  28461. _this.add(_this.cone);
  28462. _this.setDirection(dir);
  28463. _this.setLength(length, headLength, headWidth);
  28464. return _this;
  28465. }
  28466. var _proto = ArrowHelper.prototype;
  28467. _proto.setDirection = function setDirection(dir) {
  28468. // dir is assumed to be normalized
  28469. if (dir.y > 0.99999) {
  28470. this.quaternion.set(0, 0, 0, 1);
  28471. } else if (dir.y < -0.99999) {
  28472. this.quaternion.set(1, 0, 0, 0);
  28473. } else {
  28474. _axis.set(dir.z, 0, -dir.x).normalize();
  28475. var radians = Math.acos(dir.y);
  28476. this.quaternion.setFromAxisAngle(_axis, radians);
  28477. }
  28478. };
  28479. _proto.setLength = function setLength(length, headLength, headWidth) {
  28480. if (headLength === undefined) headLength = 0.2 * length;
  28481. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28482. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28483. this.line.updateMatrix();
  28484. this.cone.scale.set(headWidth, headLength, headWidth);
  28485. this.cone.position.y = length;
  28486. this.cone.updateMatrix();
  28487. };
  28488. _proto.setColor = function setColor(color) {
  28489. this.line.material.color.set(color);
  28490. this.cone.material.color.set(color);
  28491. };
  28492. _proto.copy = function copy(source) {
  28493. _Object3D.prototype.copy.call(this, source, false);
  28494. this.line.copy(source.line);
  28495. this.cone.copy(source.cone);
  28496. return this;
  28497. };
  28498. return ArrowHelper;
  28499. }(Object3D);
  28500. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28501. _inheritsLoose(AxesHelper, _LineSegments);
  28502. function AxesHelper(size) {
  28503. var _this;
  28504. if (size === void 0) {
  28505. size = 1;
  28506. }
  28507. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28508. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28509. var geometry = new BufferGeometry();
  28510. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28511. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28512. var material = new LineBasicMaterial({
  28513. vertexColors: true,
  28514. toneMapped: false
  28515. });
  28516. _this = _LineSegments.call(this, geometry, material) || this;
  28517. _this.type = 'AxesHelper';
  28518. return _this;
  28519. }
  28520. return AxesHelper;
  28521. }(LineSegments);
  28522. var _floatView = new Float32Array(1);
  28523. var _int32View = new Int32Array(_floatView.buffer);
  28524. var DataUtils = {
  28525. // Converts float32 to float16 (stored as uint16 value).
  28526. toHalfFloat: function toHalfFloat(val) {
  28527. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28528. /* This method is faster than the OpenEXR implementation (very often
  28529. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28530. * by James Tursa?s half-precision code. */
  28531. _floatView[0] = val;
  28532. var x = _int32View[0];
  28533. var bits = x >> 16 & 0x8000;
  28534. /* Get the sign */
  28535. var m = x >> 12 & 0x07ff;
  28536. /* Keep one extra bit for rounding */
  28537. var e = x >> 23 & 0xff;
  28538. /* Using int is faster here */
  28539. /* If zero, or denormal, or exponent underflows too much for a denormal
  28540. * half, return signed zero. */
  28541. if (e < 103) return bits;
  28542. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28543. if (e > 142) {
  28544. bits |= 0x7c00;
  28545. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28546. * not Inf, so make sure we set one mantissa bit too. */
  28547. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28548. return bits;
  28549. }
  28550. /* If exponent underflows but not too much, return a denormal */
  28551. if (e < 113) {
  28552. m |= 0x0800;
  28553. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28554. * to 1, which is OK. */
  28555. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28556. return bits;
  28557. }
  28558. bits |= e - 112 << 10 | m >> 1;
  28559. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28560. * the exponent, which is OK. */
  28561. bits += m & 1;
  28562. return bits;
  28563. }
  28564. };
  28565. var _ENCODINGS;
  28566. var LOD_MIN = 4;
  28567. var LOD_MAX = 8;
  28568. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28569. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28570. // geometric shadowing function. These sigma values squared must match the
  28571. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28572. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28573. 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
  28574. // samples and exit early, but not recompile the shader.
  28575. var MAX_SAMPLES = 20;
  28576. 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);
  28577. var backgroundMaterial = new MeshBasicMaterial({
  28578. side: BackSide,
  28579. depthWrite: false,
  28580. depthTest: false
  28581. });
  28582. var backgroundBox = new Mesh(new BoxGeometry(), backgroundMaterial);
  28583. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28584. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28585. _lodPlanes = _createPlanes2._lodPlanes,
  28586. _sizeLods = _createPlanes2._sizeLods,
  28587. _sigmas = _createPlanes2._sigmas;
  28588. var _clearColor = /*@__PURE__*/new Color();
  28589. var _oldTarget = null; // Golden Ratio
  28590. var PHI = (1 + Math.sqrt(5)) / 2;
  28591. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28592. // same axis), used as axis directions evenly spread on a sphere.
  28593. 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)];
  28594. /**
  28595. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28596. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28597. * blur to be quickly accessed based on material roughness. It is packed into a
  28598. * special CubeUV format that allows us to perform custom interpolation so that
  28599. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28600. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28601. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28602. * higher roughness levels. In this way we maintain resolution to smoothly
  28603. * interpolate diffuse lighting while limiting sampling computation.
  28604. */
  28605. function convertLinearToRGBE(color) {
  28606. var maxComponent = Math.max(color.r, color.g, color.b);
  28607. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28608. color.multiplyScalar(Math.pow(2.0, -fExp));
  28609. var alpha = (fExp + 128.0) / 255.0;
  28610. return alpha;
  28611. }
  28612. var PMREMGenerator = /*#__PURE__*/function () {
  28613. function PMREMGenerator(renderer) {
  28614. this._renderer = renderer;
  28615. this._pingPongRenderTarget = null;
  28616. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28617. this._equirectShader = null;
  28618. this._cubemapShader = null;
  28619. this._compileMaterial(this._blurMaterial);
  28620. }
  28621. /**
  28622. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28623. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28624. * in radians to be applied to the scene before PMREM generation. Optional near
  28625. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28626. * is placed at the origin).
  28627. */
  28628. var _proto = PMREMGenerator.prototype;
  28629. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28630. if (sigma === void 0) {
  28631. sigma = 0;
  28632. }
  28633. if (near === void 0) {
  28634. near = 0.1;
  28635. }
  28636. if (far === void 0) {
  28637. far = 100;
  28638. }
  28639. _oldTarget = this._renderer.getRenderTarget();
  28640. var cubeUVRenderTarget = this._allocateTargets();
  28641. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28642. if (sigma > 0) {
  28643. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28644. }
  28645. this._applyPMREM(cubeUVRenderTarget);
  28646. this._cleanup(cubeUVRenderTarget);
  28647. return cubeUVRenderTarget;
  28648. }
  28649. /**
  28650. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28651. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28652. * as this matches best with the 256 x 256 cubemap output.
  28653. */
  28654. ;
  28655. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28656. return this._fromTexture(equirectangular);
  28657. }
  28658. /**
  28659. * Generates a PMREM from an cubemap texture, which can be either LDR
  28660. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28661. * as this matches best with the 256 x 256 cubemap output.
  28662. */
  28663. ;
  28664. _proto.fromCubemap = function fromCubemap(cubemap) {
  28665. return this._fromTexture(cubemap);
  28666. }
  28667. /**
  28668. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28669. * your texture's network fetch for increased concurrency.
  28670. */
  28671. ;
  28672. _proto.compileCubemapShader = function compileCubemapShader() {
  28673. if (this._cubemapShader === null) {
  28674. this._cubemapShader = _getCubemapShader();
  28675. this._compileMaterial(this._cubemapShader);
  28676. }
  28677. }
  28678. /**
  28679. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28680. * your texture's network fetch for increased concurrency.
  28681. */
  28682. ;
  28683. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28684. if (this._equirectShader === null) {
  28685. this._equirectShader = _getEquirectShader();
  28686. this._compileMaterial(this._equirectShader);
  28687. }
  28688. }
  28689. /**
  28690. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28691. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28692. * one of them will cause any others to also become unusable.
  28693. */
  28694. ;
  28695. _proto.dispose = function dispose() {
  28696. this._blurMaterial.dispose();
  28697. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28698. if (this._equirectShader !== null) this._equirectShader.dispose();
  28699. for (var i = 0; i < _lodPlanes.length; i++) {
  28700. _lodPlanes[i].dispose();
  28701. }
  28702. } // private interface
  28703. ;
  28704. _proto._cleanup = function _cleanup(outputTarget) {
  28705. this._pingPongRenderTarget.dispose();
  28706. this._renderer.setRenderTarget(_oldTarget);
  28707. outputTarget.scissorTest = false;
  28708. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28709. };
  28710. _proto._fromTexture = function _fromTexture(texture) {
  28711. _oldTarget = this._renderer.getRenderTarget();
  28712. var cubeUVRenderTarget = this._allocateTargets(texture);
  28713. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28714. this._applyPMREM(cubeUVRenderTarget);
  28715. this._cleanup(cubeUVRenderTarget);
  28716. return cubeUVRenderTarget;
  28717. };
  28718. _proto._allocateTargets = function _allocateTargets(texture) {
  28719. // warning: null texture is valid
  28720. var params = {
  28721. magFilter: NearestFilter,
  28722. minFilter: NearestFilter,
  28723. generateMipmaps: false,
  28724. type: UnsignedByteType,
  28725. format: RGBEFormat,
  28726. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28727. depthBuffer: false
  28728. };
  28729. var cubeUVRenderTarget = _createRenderTarget(params);
  28730. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28731. this._pingPongRenderTarget = _createRenderTarget(params);
  28732. return cubeUVRenderTarget;
  28733. };
  28734. _proto._compileMaterial = function _compileMaterial(material) {
  28735. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28736. this._renderer.compile(tmpMesh, _flatCamera);
  28737. };
  28738. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28739. var fov = 90;
  28740. var aspect = 1;
  28741. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28742. var upSign = [1, -1, 1, 1, 1, 1];
  28743. var forwardSign = [1, 1, 1, -1, -1, -1];
  28744. var renderer = this._renderer;
  28745. var originalAutoClear = renderer.autoClear;
  28746. var outputEncoding = renderer.outputEncoding;
  28747. var toneMapping = renderer.toneMapping;
  28748. renderer.getClearColor(_clearColor);
  28749. renderer.toneMapping = NoToneMapping;
  28750. renderer.outputEncoding = LinearEncoding;
  28751. renderer.autoClear = false;
  28752. var useSolidColor = false;
  28753. var background = scene.background;
  28754. if (background) {
  28755. if (background.isColor) {
  28756. backgroundMaterial.color.copy(background).convertSRGBToLinear();
  28757. scene.background = null;
  28758. var alpha = convertLinearToRGBE(backgroundMaterial.color);
  28759. backgroundMaterial.opacity = alpha;
  28760. useSolidColor = true;
  28761. }
  28762. } else {
  28763. backgroundMaterial.color.copy(_clearColor).convertSRGBToLinear();
  28764. var _alpha = convertLinearToRGBE(backgroundMaterial.color);
  28765. backgroundMaterial.opacity = _alpha;
  28766. useSolidColor = true;
  28767. }
  28768. for (var i = 0; i < 6; i++) {
  28769. var col = i % 3;
  28770. if (col == 0) {
  28771. cubeCamera.up.set(0, upSign[i], 0);
  28772. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28773. } else if (col == 1) {
  28774. cubeCamera.up.set(0, 0, upSign[i]);
  28775. cubeCamera.lookAt(0, forwardSign[i], 0);
  28776. } else {
  28777. cubeCamera.up.set(0, upSign[i], 0);
  28778. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28779. }
  28780. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28781. renderer.setRenderTarget(cubeUVRenderTarget);
  28782. if (useSolidColor) {
  28783. renderer.render(backgroundBox, cubeCamera);
  28784. }
  28785. renderer.render(scene, cubeCamera);
  28786. }
  28787. renderer.toneMapping = toneMapping;
  28788. renderer.outputEncoding = outputEncoding;
  28789. renderer.autoClear = originalAutoClear;
  28790. };
  28791. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28792. var renderer = this._renderer;
  28793. if (texture.isCubeTexture) {
  28794. if (this._cubemapShader == null) {
  28795. this._cubemapShader = _getCubemapShader();
  28796. }
  28797. } else {
  28798. if (this._equirectShader == null) {
  28799. this._equirectShader = _getEquirectShader();
  28800. }
  28801. }
  28802. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28803. var mesh = new Mesh(_lodPlanes[0], material);
  28804. var uniforms = material.uniforms;
  28805. uniforms['envMap'].value = texture;
  28806. if (!texture.isCubeTexture) {
  28807. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28808. }
  28809. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28810. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28811. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28812. renderer.setRenderTarget(cubeUVRenderTarget);
  28813. renderer.render(mesh, _flatCamera);
  28814. };
  28815. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28816. var renderer = this._renderer;
  28817. var autoClear = renderer.autoClear;
  28818. renderer.autoClear = false;
  28819. for (var i = 1; i < TOTAL_LODS; i++) {
  28820. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28821. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28822. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28823. }
  28824. renderer.autoClear = autoClear;
  28825. }
  28826. /**
  28827. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28828. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28829. * the blur latitudinally (around the poles), and then longitudinally (towards
  28830. * the poles) to approximate the orthogonally-separable blur. It is least
  28831. * accurate at the poles, but still does a decent job.
  28832. */
  28833. ;
  28834. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28835. var pingPongRenderTarget = this._pingPongRenderTarget;
  28836. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28837. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28838. };
  28839. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28840. var renderer = this._renderer;
  28841. var blurMaterial = this._blurMaterial;
  28842. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28843. console.error('blur direction must be either latitudinal or longitudinal!');
  28844. } // Number of standard deviations at which to cut off the discrete approximation.
  28845. var STANDARD_DEVIATIONS = 3;
  28846. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28847. var blurUniforms = blurMaterial.uniforms;
  28848. var pixels = _sizeLods[lodIn] - 1;
  28849. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28850. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28851. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28852. if (samples > MAX_SAMPLES) {
  28853. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28854. }
  28855. var weights = [];
  28856. var sum = 0;
  28857. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28858. var _x = i / sigmaPixels;
  28859. var weight = Math.exp(-_x * _x / 2);
  28860. weights.push(weight);
  28861. if (i == 0) {
  28862. sum += weight;
  28863. } else if (i < samples) {
  28864. sum += 2 * weight;
  28865. }
  28866. }
  28867. for (var _i = 0; _i < weights.length; _i++) {
  28868. weights[_i] = weights[_i] / sum;
  28869. }
  28870. blurUniforms['envMap'].value = targetIn.texture;
  28871. blurUniforms['samples'].value = samples;
  28872. blurUniforms['weights'].value = weights;
  28873. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28874. if (poleAxis) {
  28875. blurUniforms['poleAxis'].value = poleAxis;
  28876. }
  28877. blurUniforms['dTheta'].value = radiansPerPixel;
  28878. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28879. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28880. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28881. var outputSize = _sizeLods[lodOut];
  28882. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28883. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28884. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28885. renderer.setRenderTarget(targetOut);
  28886. renderer.render(blurMesh, _flatCamera);
  28887. };
  28888. return PMREMGenerator;
  28889. }();
  28890. function _isLDR(texture) {
  28891. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28892. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28893. }
  28894. function _createPlanes() {
  28895. var _lodPlanes = [];
  28896. var _sizeLods = [];
  28897. var _sigmas = [];
  28898. var lod = LOD_MAX;
  28899. for (var i = 0; i < TOTAL_LODS; i++) {
  28900. var sizeLod = Math.pow(2, lod);
  28901. _sizeLods.push(sizeLod);
  28902. var sigma = 1.0 / sizeLod;
  28903. if (i > LOD_MAX - LOD_MIN) {
  28904. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28905. } else if (i == 0) {
  28906. sigma = 0;
  28907. }
  28908. _sigmas.push(sigma);
  28909. var texelSize = 1.0 / (sizeLod - 1);
  28910. var min = -texelSize / 2;
  28911. var max = 1 + texelSize / 2;
  28912. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28913. var cubeFaces = 6;
  28914. var vertices = 6;
  28915. var positionSize = 3;
  28916. var uvSize = 2;
  28917. var faceIndexSize = 1;
  28918. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28919. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28920. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28921. for (var face = 0; face < cubeFaces; face++) {
  28922. var x = face % 3 * 2 / 3 - 1;
  28923. var y = face > 2 ? 0 : -1;
  28924. 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];
  28925. position.set(coordinates, positionSize * vertices * face);
  28926. uv.set(uv1, uvSize * vertices * face);
  28927. var fill = [face, face, face, face, face, face];
  28928. faceIndex.set(fill, faceIndexSize * vertices * face);
  28929. }
  28930. var planes = new BufferGeometry();
  28931. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28932. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28933. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28934. _lodPlanes.push(planes);
  28935. if (lod > LOD_MIN) {
  28936. lod--;
  28937. }
  28938. }
  28939. return {
  28940. _lodPlanes: _lodPlanes,
  28941. _sizeLods: _sizeLods,
  28942. _sigmas: _sigmas
  28943. };
  28944. }
  28945. function _createRenderTarget(params) {
  28946. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28947. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28948. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28949. cubeUVRenderTarget.scissorTest = true;
  28950. return cubeUVRenderTarget;
  28951. }
  28952. function _setViewport(target, x, y, width, height) {
  28953. target.viewport.set(x, y, width, height);
  28954. target.scissor.set(x, y, width, height);
  28955. }
  28956. function _getBlurShader(maxSamples) {
  28957. var weights = new Float32Array(maxSamples);
  28958. var poleAxis = new Vector3(0, 1, 0);
  28959. var shaderMaterial = new RawShaderMaterial({
  28960. name: 'SphericalGaussianBlur',
  28961. defines: {
  28962. 'n': maxSamples
  28963. },
  28964. uniforms: {
  28965. 'envMap': {
  28966. value: null
  28967. },
  28968. 'samples': {
  28969. value: 1
  28970. },
  28971. 'weights': {
  28972. value: weights
  28973. },
  28974. 'latitudinal': {
  28975. value: false
  28976. },
  28977. 'dTheta': {
  28978. value: 0
  28979. },
  28980. 'mipInt': {
  28981. value: 0
  28982. },
  28983. 'poleAxis': {
  28984. value: poleAxis
  28985. },
  28986. 'inputEncoding': {
  28987. value: ENCODINGS[LinearEncoding]
  28988. },
  28989. 'outputEncoding': {
  28990. value: ENCODINGS[LinearEncoding]
  28991. }
  28992. },
  28993. vertexShader: _getCommonVertexShader(),
  28994. fragmentShader:
  28995. /* glsl */
  28996. "\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",
  28997. blending: NoBlending,
  28998. depthTest: false,
  28999. depthWrite: false
  29000. });
  29001. return shaderMaterial;
  29002. }
  29003. function _getEquirectShader() {
  29004. var texelSize = new Vector2(1, 1);
  29005. var shaderMaterial = new RawShaderMaterial({
  29006. name: 'EquirectangularToCubeUV',
  29007. uniforms: {
  29008. 'envMap': {
  29009. value: null
  29010. },
  29011. 'texelSize': {
  29012. value: texelSize
  29013. },
  29014. 'inputEncoding': {
  29015. value: ENCODINGS[LinearEncoding]
  29016. },
  29017. 'outputEncoding': {
  29018. value: ENCODINGS[LinearEncoding]
  29019. }
  29020. },
  29021. vertexShader: _getCommonVertexShader(),
  29022. fragmentShader:
  29023. /* glsl */
  29024. "\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",
  29025. blending: NoBlending,
  29026. depthTest: false,
  29027. depthWrite: false
  29028. });
  29029. return shaderMaterial;
  29030. }
  29031. function _getCubemapShader() {
  29032. var shaderMaterial = new RawShaderMaterial({
  29033. name: 'CubemapToCubeUV',
  29034. uniforms: {
  29035. 'envMap': {
  29036. value: null
  29037. },
  29038. 'inputEncoding': {
  29039. value: ENCODINGS[LinearEncoding]
  29040. },
  29041. 'outputEncoding': {
  29042. value: ENCODINGS[LinearEncoding]
  29043. }
  29044. },
  29045. vertexShader: _getCommonVertexShader(),
  29046. fragmentShader:
  29047. /* glsl */
  29048. "\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",
  29049. blending: NoBlending,
  29050. depthTest: false,
  29051. depthWrite: false
  29052. });
  29053. return shaderMaterial;
  29054. }
  29055. function _getCommonVertexShader() {
  29056. return (
  29057. /* glsl */
  29058. "\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"
  29059. );
  29060. }
  29061. function _getEncodings() {
  29062. return (
  29063. /* glsl */
  29064. "\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"
  29065. );
  29066. }
  29067. var LineStrip = 0;
  29068. var LinePieces = 1;
  29069. var NoColors = 0;
  29070. var FaceColors = 1;
  29071. var VertexColors = 2;
  29072. function MeshFaceMaterial(materials) {
  29073. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  29074. return materials;
  29075. }
  29076. function MultiMaterial(materials) {
  29077. if (materials === void 0) {
  29078. materials = [];
  29079. }
  29080. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  29081. materials.isMultiMaterial = true;
  29082. materials.materials = materials;
  29083. materials.clone = function () {
  29084. return materials.slice();
  29085. };
  29086. return materials;
  29087. }
  29088. function PointCloud(geometry, material) {
  29089. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  29090. return new Points(geometry, material);
  29091. }
  29092. function Particle(material) {
  29093. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  29094. return new Sprite(material);
  29095. }
  29096. function ParticleSystem(geometry, material) {
  29097. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  29098. return new Points(geometry, material);
  29099. }
  29100. function PointCloudMaterial(parameters) {
  29101. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  29102. return new PointsMaterial(parameters);
  29103. }
  29104. function ParticleBasicMaterial(parameters) {
  29105. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  29106. return new PointsMaterial(parameters);
  29107. }
  29108. function ParticleSystemMaterial(parameters) {
  29109. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  29110. return new PointsMaterial(parameters);
  29111. }
  29112. function Vertex(x, y, z) {
  29113. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  29114. return new Vector3(x, y, z);
  29115. } //
  29116. function DynamicBufferAttribute(array, itemSize) {
  29117. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  29118. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  29119. }
  29120. function Int8Attribute(array, itemSize) {
  29121. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  29122. return new Int8BufferAttribute(array, itemSize);
  29123. }
  29124. function Uint8Attribute(array, itemSize) {
  29125. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  29126. return new Uint8BufferAttribute(array, itemSize);
  29127. }
  29128. function Uint8ClampedAttribute(array, itemSize) {
  29129. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  29130. return new Uint8ClampedBufferAttribute(array, itemSize);
  29131. }
  29132. function Int16Attribute(array, itemSize) {
  29133. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  29134. return new Int16BufferAttribute(array, itemSize);
  29135. }
  29136. function Uint16Attribute(array, itemSize) {
  29137. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  29138. return new Uint16BufferAttribute(array, itemSize);
  29139. }
  29140. function Int32Attribute(array, itemSize) {
  29141. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  29142. return new Int32BufferAttribute(array, itemSize);
  29143. }
  29144. function Uint32Attribute(array, itemSize) {
  29145. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  29146. return new Uint32BufferAttribute(array, itemSize);
  29147. }
  29148. function Float32Attribute(array, itemSize) {
  29149. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  29150. return new Float32BufferAttribute(array, itemSize);
  29151. }
  29152. function Float64Attribute(array, itemSize) {
  29153. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29154. return new Float64BufferAttribute(array, itemSize);
  29155. } //
  29156. Curve.create = function (construct, getPoint) {
  29157. console.log('THREE.Curve.create() has been deprecated');
  29158. construct.prototype = Object.create(Curve.prototype);
  29159. construct.prototype.constructor = construct;
  29160. construct.prototype.getPoint = getPoint;
  29161. return construct;
  29162. }; //
  29163. Object.assign(Path.prototype, {
  29164. fromPoints: function fromPoints(points) {
  29165. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29166. return this.setFromPoints(points);
  29167. }
  29168. }); //
  29169. function ClosedSplineCurve3(points) {
  29170. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29171. CatmullRomCurve3.call(this, points);
  29172. this.type = 'catmullrom';
  29173. this.closed = true;
  29174. }
  29175. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29176. function SplineCurve3(points) {
  29177. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29178. CatmullRomCurve3.call(this, points);
  29179. this.type = 'catmullrom';
  29180. }
  29181. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29182. function Spline(points) {
  29183. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29184. CatmullRomCurve3.call(this, points);
  29185. this.type = 'catmullrom';
  29186. }
  29187. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29188. Object.assign(Spline.prototype, {
  29189. initFromArray: function initFromArray()
  29190. /* a */
  29191. {
  29192. console.error('THREE.Spline: .initFromArray() has been removed.');
  29193. },
  29194. getControlPointsArray: function getControlPointsArray()
  29195. /* optionalTarget */
  29196. {
  29197. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29198. },
  29199. reparametrizeByArcLength: function reparametrizeByArcLength()
  29200. /* samplingCoef */
  29201. {
  29202. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29203. }
  29204. }); //
  29205. function AxisHelper(size) {
  29206. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29207. return new AxesHelper(size);
  29208. }
  29209. function BoundingBoxHelper(object, color) {
  29210. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29211. return new BoxHelper(object, color);
  29212. }
  29213. function EdgesHelper(object, hex) {
  29214. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29215. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29216. color: hex !== undefined ? hex : 0xffffff
  29217. }));
  29218. }
  29219. GridHelper.prototype.setColors = function () {
  29220. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29221. };
  29222. SkeletonHelper.prototype.update = function () {
  29223. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29224. };
  29225. function WireframeHelper(object, hex) {
  29226. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29227. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29228. color: hex !== undefined ? hex : 0xffffff
  29229. }));
  29230. } //
  29231. Object.assign(Loader.prototype, {
  29232. extractUrlBase: function extractUrlBase(url) {
  29233. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29234. return LoaderUtils.extractUrlBase(url);
  29235. }
  29236. });
  29237. Loader.Handlers = {
  29238. add: function add()
  29239. /* regex, loader */
  29240. {
  29241. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29242. },
  29243. get: function get()
  29244. /* file */
  29245. {
  29246. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29247. }
  29248. };
  29249. function XHRLoader(manager) {
  29250. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29251. return new FileLoader(manager);
  29252. }
  29253. function BinaryTextureLoader(manager) {
  29254. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29255. return new DataTextureLoader(manager);
  29256. } //
  29257. Object.assign(Box2.prototype, {
  29258. center: function center(optionalTarget) {
  29259. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29260. return this.getCenter(optionalTarget);
  29261. },
  29262. empty: function empty() {
  29263. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29264. return this.isEmpty();
  29265. },
  29266. isIntersectionBox: function isIntersectionBox(box) {
  29267. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29268. return this.intersectsBox(box);
  29269. },
  29270. size: function size(optionalTarget) {
  29271. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29272. return this.getSize(optionalTarget);
  29273. }
  29274. });
  29275. Object.assign(Box3.prototype, {
  29276. center: function center(optionalTarget) {
  29277. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29278. return this.getCenter(optionalTarget);
  29279. },
  29280. empty: function empty() {
  29281. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29282. return this.isEmpty();
  29283. },
  29284. isIntersectionBox: function isIntersectionBox(box) {
  29285. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29286. return this.intersectsBox(box);
  29287. },
  29288. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29289. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29290. return this.intersectsSphere(sphere);
  29291. },
  29292. size: function size(optionalTarget) {
  29293. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29294. return this.getSize(optionalTarget);
  29295. }
  29296. });
  29297. Object.assign(Sphere.prototype, {
  29298. empty: function empty() {
  29299. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29300. return this.isEmpty();
  29301. }
  29302. });
  29303. Frustum.prototype.setFromMatrix = function (m) {
  29304. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29305. return this.setFromProjectionMatrix(m);
  29306. };
  29307. Line3.prototype.center = function (optionalTarget) {
  29308. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29309. return this.getCenter(optionalTarget);
  29310. };
  29311. Object.assign(MathUtils, {
  29312. random16: function random16() {
  29313. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29314. return Math.random();
  29315. },
  29316. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29317. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29318. return MathUtils.floorPowerOfTwo(value);
  29319. },
  29320. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29321. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29322. return MathUtils.ceilPowerOfTwo(value);
  29323. }
  29324. });
  29325. Object.assign(Matrix3.prototype, {
  29326. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29327. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29328. return this.toArray(array, offset);
  29329. },
  29330. multiplyVector3: function multiplyVector3(vector) {
  29331. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29332. return vector.applyMatrix3(this);
  29333. },
  29334. multiplyVector3Array: function multiplyVector3Array()
  29335. /* a */
  29336. {
  29337. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29338. },
  29339. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29340. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29341. return attribute.applyMatrix3(this);
  29342. },
  29343. applyToVector3Array: function applyToVector3Array()
  29344. /* array, offset, length */
  29345. {
  29346. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29347. },
  29348. getInverse: function getInverse(matrix) {
  29349. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29350. return this.copy(matrix).invert();
  29351. }
  29352. });
  29353. Object.assign(Matrix4.prototype, {
  29354. extractPosition: function extractPosition(m) {
  29355. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29356. return this.copyPosition(m);
  29357. },
  29358. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29359. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29360. return this.toArray(array, offset);
  29361. },
  29362. getPosition: function getPosition() {
  29363. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29364. return new Vector3().setFromMatrixColumn(this, 3);
  29365. },
  29366. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29367. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29368. return this.makeRotationFromQuaternion(q);
  29369. },
  29370. multiplyToArray: function multiplyToArray() {
  29371. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29372. },
  29373. multiplyVector3: function multiplyVector3(vector) {
  29374. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29375. return vector.applyMatrix4(this);
  29376. },
  29377. multiplyVector4: function multiplyVector4(vector) {
  29378. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29379. return vector.applyMatrix4(this);
  29380. },
  29381. multiplyVector3Array: function multiplyVector3Array()
  29382. /* a */
  29383. {
  29384. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29385. },
  29386. rotateAxis: function rotateAxis(v) {
  29387. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29388. v.transformDirection(this);
  29389. },
  29390. crossVector: function crossVector(vector) {
  29391. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29392. return vector.applyMatrix4(this);
  29393. },
  29394. translate: function translate() {
  29395. console.error('THREE.Matrix4: .translate() has been removed.');
  29396. },
  29397. rotateX: function rotateX() {
  29398. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29399. },
  29400. rotateY: function rotateY() {
  29401. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29402. },
  29403. rotateZ: function rotateZ() {
  29404. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29405. },
  29406. rotateByAxis: function rotateByAxis() {
  29407. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29408. },
  29409. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29410. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29411. return attribute.applyMatrix4(this);
  29412. },
  29413. applyToVector3Array: function applyToVector3Array()
  29414. /* array, offset, length */
  29415. {
  29416. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29417. },
  29418. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29419. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29420. return this.makePerspective(left, right, top, bottom, near, far);
  29421. },
  29422. getInverse: function getInverse(matrix) {
  29423. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29424. return this.copy(matrix).invert();
  29425. }
  29426. });
  29427. Plane.prototype.isIntersectionLine = function (line) {
  29428. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29429. return this.intersectsLine(line);
  29430. };
  29431. Object.assign(Quaternion.prototype, {
  29432. multiplyVector3: function multiplyVector3(vector) {
  29433. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29434. return vector.applyQuaternion(this);
  29435. },
  29436. inverse: function inverse() {
  29437. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29438. return this.invert();
  29439. }
  29440. });
  29441. Object.assign(Ray.prototype, {
  29442. isIntersectionBox: function isIntersectionBox(box) {
  29443. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29444. return this.intersectsBox(box);
  29445. },
  29446. isIntersectionPlane: function isIntersectionPlane(plane) {
  29447. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29448. return this.intersectsPlane(plane);
  29449. },
  29450. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29451. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29452. return this.intersectsSphere(sphere);
  29453. }
  29454. });
  29455. Object.assign(Triangle.prototype, {
  29456. area: function area() {
  29457. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29458. return this.getArea();
  29459. },
  29460. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29461. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29462. return this.getBarycoord(point, target);
  29463. },
  29464. midpoint: function midpoint(target) {
  29465. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29466. return this.getMidpoint(target);
  29467. },
  29468. normal: function normal(target) {
  29469. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29470. return this.getNormal(target);
  29471. },
  29472. plane: function plane(target) {
  29473. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29474. return this.getPlane(target);
  29475. }
  29476. });
  29477. Object.assign(Triangle, {
  29478. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29479. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29480. return Triangle.getBarycoord(point, a, b, c, target);
  29481. },
  29482. normal: function normal(a, b, c, target) {
  29483. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29484. return Triangle.getNormal(a, b, c, target);
  29485. }
  29486. });
  29487. Object.assign(Shape.prototype, {
  29488. extractAllPoints: function extractAllPoints(divisions) {
  29489. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29490. return this.extractPoints(divisions);
  29491. },
  29492. extrude: function extrude(options) {
  29493. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29494. return new ExtrudeGeometry(this, options);
  29495. },
  29496. makeGeometry: function makeGeometry(options) {
  29497. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29498. return new ShapeGeometry(this, options);
  29499. }
  29500. });
  29501. Object.assign(Vector2.prototype, {
  29502. fromAttribute: function fromAttribute(attribute, index, offset) {
  29503. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29504. return this.fromBufferAttribute(attribute, index, offset);
  29505. },
  29506. distanceToManhattan: function distanceToManhattan(v) {
  29507. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29508. return this.manhattanDistanceTo(v);
  29509. },
  29510. lengthManhattan: function lengthManhattan() {
  29511. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29512. return this.manhattanLength();
  29513. }
  29514. });
  29515. Object.assign(Vector3.prototype, {
  29516. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29517. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29518. },
  29519. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29520. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29521. },
  29522. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29523. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29524. return this.setFromMatrixPosition(m);
  29525. },
  29526. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29527. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29528. return this.setFromMatrixScale(m);
  29529. },
  29530. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29531. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29532. return this.setFromMatrixColumn(matrix, index);
  29533. },
  29534. applyProjection: function applyProjection(m) {
  29535. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29536. return this.applyMatrix4(m);
  29537. },
  29538. fromAttribute: function fromAttribute(attribute, index, offset) {
  29539. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29540. return this.fromBufferAttribute(attribute, index, offset);
  29541. },
  29542. distanceToManhattan: function distanceToManhattan(v) {
  29543. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29544. return this.manhattanDistanceTo(v);
  29545. },
  29546. lengthManhattan: function lengthManhattan() {
  29547. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29548. return this.manhattanLength();
  29549. }
  29550. });
  29551. Object.assign(Vector4.prototype, {
  29552. fromAttribute: function fromAttribute(attribute, index, offset) {
  29553. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29554. return this.fromBufferAttribute(attribute, index, offset);
  29555. },
  29556. lengthManhattan: function lengthManhattan() {
  29557. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29558. return this.manhattanLength();
  29559. }
  29560. }); //
  29561. Object.assign(Object3D.prototype, {
  29562. getChildByName: function getChildByName(name) {
  29563. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29564. return this.getObjectByName(name);
  29565. },
  29566. renderDepth: function renderDepth() {
  29567. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29568. },
  29569. translate: function translate(distance, axis) {
  29570. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29571. return this.translateOnAxis(axis, distance);
  29572. },
  29573. getWorldRotation: function getWorldRotation() {
  29574. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29575. },
  29576. applyMatrix: function applyMatrix(matrix) {
  29577. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29578. return this.applyMatrix4(matrix);
  29579. }
  29580. });
  29581. Object.defineProperties(Object3D.prototype, {
  29582. eulerOrder: {
  29583. get: function get() {
  29584. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29585. return this.rotation.order;
  29586. },
  29587. set: function set(value) {
  29588. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29589. this.rotation.order = value;
  29590. }
  29591. },
  29592. useQuaternion: {
  29593. get: function get() {
  29594. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29595. },
  29596. set: function set() {
  29597. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29598. }
  29599. }
  29600. });
  29601. Object.assign(Mesh.prototype, {
  29602. setDrawMode: function setDrawMode() {
  29603. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29604. }
  29605. });
  29606. Object.defineProperties(Mesh.prototype, {
  29607. drawMode: {
  29608. get: function get() {
  29609. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29610. return TrianglesDrawMode;
  29611. },
  29612. set: function set() {
  29613. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29614. }
  29615. }
  29616. });
  29617. Object.defineProperties(LOD.prototype, {
  29618. objects: {
  29619. get: function get() {
  29620. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29621. return this.levels;
  29622. }
  29623. }
  29624. });
  29625. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29626. get: function get() {
  29627. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29628. },
  29629. set: function set() {
  29630. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29631. }
  29632. });
  29633. SkinnedMesh.prototype.initBones = function () {
  29634. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29635. };
  29636. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29637. get: function get() {
  29638. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29639. return this.arcLengthDivisions;
  29640. },
  29641. set: function set(value) {
  29642. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29643. this.arcLengthDivisions = value;
  29644. }
  29645. }); //
  29646. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29647. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29648. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29649. this.setFocalLength(focalLength);
  29650. }; //
  29651. Object.defineProperties(Light.prototype, {
  29652. onlyShadow: {
  29653. set: function set() {
  29654. console.warn('THREE.Light: .onlyShadow has been removed.');
  29655. }
  29656. },
  29657. shadowCameraFov: {
  29658. set: function set(value) {
  29659. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29660. this.shadow.camera.fov = value;
  29661. }
  29662. },
  29663. shadowCameraLeft: {
  29664. set: function set(value) {
  29665. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29666. this.shadow.camera.left = value;
  29667. }
  29668. },
  29669. shadowCameraRight: {
  29670. set: function set(value) {
  29671. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29672. this.shadow.camera.right = value;
  29673. }
  29674. },
  29675. shadowCameraTop: {
  29676. set: function set(value) {
  29677. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29678. this.shadow.camera.top = value;
  29679. }
  29680. },
  29681. shadowCameraBottom: {
  29682. set: function set(value) {
  29683. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29684. this.shadow.camera.bottom = value;
  29685. }
  29686. },
  29687. shadowCameraNear: {
  29688. set: function set(value) {
  29689. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29690. this.shadow.camera.near = value;
  29691. }
  29692. },
  29693. shadowCameraFar: {
  29694. set: function set(value) {
  29695. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29696. this.shadow.camera.far = value;
  29697. }
  29698. },
  29699. shadowCameraVisible: {
  29700. set: function set() {
  29701. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29702. }
  29703. },
  29704. shadowBias: {
  29705. set: function set(value) {
  29706. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29707. this.shadow.bias = value;
  29708. }
  29709. },
  29710. shadowDarkness: {
  29711. set: function set() {
  29712. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29713. }
  29714. },
  29715. shadowMapWidth: {
  29716. set: function set(value) {
  29717. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29718. this.shadow.mapSize.width = value;
  29719. }
  29720. },
  29721. shadowMapHeight: {
  29722. set: function set(value) {
  29723. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29724. this.shadow.mapSize.height = value;
  29725. }
  29726. }
  29727. }); //
  29728. Object.defineProperties(BufferAttribute.prototype, {
  29729. length: {
  29730. get: function get() {
  29731. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29732. return this.array.length;
  29733. }
  29734. },
  29735. dynamic: {
  29736. get: function get() {
  29737. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29738. return this.usage === DynamicDrawUsage;
  29739. },
  29740. set: function set()
  29741. /* value */
  29742. {
  29743. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29744. this.setUsage(DynamicDrawUsage);
  29745. }
  29746. }
  29747. });
  29748. Object.assign(BufferAttribute.prototype, {
  29749. setDynamic: function setDynamic(value) {
  29750. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29751. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29752. return this;
  29753. },
  29754. copyIndicesArray: function copyIndicesArray()
  29755. /* indices */
  29756. {
  29757. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29758. },
  29759. setArray: function setArray()
  29760. /* array */
  29761. {
  29762. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29763. }
  29764. });
  29765. Object.assign(BufferGeometry.prototype, {
  29766. addIndex: function addIndex(index) {
  29767. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29768. this.setIndex(index);
  29769. },
  29770. addAttribute: function addAttribute(name, attribute) {
  29771. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29772. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29773. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29774. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29775. }
  29776. if (name === 'index') {
  29777. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29778. this.setIndex(attribute);
  29779. return this;
  29780. }
  29781. return this.setAttribute(name, attribute);
  29782. },
  29783. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29784. if (indexOffset !== undefined) {
  29785. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29786. }
  29787. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29788. this.addGroup(start, count);
  29789. },
  29790. clearDrawCalls: function clearDrawCalls() {
  29791. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29792. this.clearGroups();
  29793. },
  29794. computeOffsets: function computeOffsets() {
  29795. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29796. },
  29797. removeAttribute: function removeAttribute(name) {
  29798. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29799. return this.deleteAttribute(name);
  29800. },
  29801. applyMatrix: function applyMatrix(matrix) {
  29802. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29803. return this.applyMatrix4(matrix);
  29804. }
  29805. });
  29806. Object.defineProperties(BufferGeometry.prototype, {
  29807. drawcalls: {
  29808. get: function get() {
  29809. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29810. return this.groups;
  29811. }
  29812. },
  29813. offsets: {
  29814. get: function get() {
  29815. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29816. return this.groups;
  29817. }
  29818. }
  29819. });
  29820. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29821. maxInstancedCount: {
  29822. get: function get() {
  29823. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29824. return this.instanceCount;
  29825. },
  29826. set: function set(value) {
  29827. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29828. this.instanceCount = value;
  29829. }
  29830. }
  29831. });
  29832. Object.defineProperties(Raycaster.prototype, {
  29833. linePrecision: {
  29834. get: function get() {
  29835. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29836. return this.params.Line.threshold;
  29837. },
  29838. set: function set(value) {
  29839. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29840. this.params.Line.threshold = value;
  29841. }
  29842. }
  29843. });
  29844. Object.defineProperties(InterleavedBuffer.prototype, {
  29845. dynamic: {
  29846. get: function get() {
  29847. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29848. return this.usage === DynamicDrawUsage;
  29849. },
  29850. set: function set(value) {
  29851. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29852. this.setUsage(value);
  29853. }
  29854. }
  29855. });
  29856. Object.assign(InterleavedBuffer.prototype, {
  29857. setDynamic: function setDynamic(value) {
  29858. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29859. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29860. return this;
  29861. },
  29862. setArray: function setArray()
  29863. /* array */
  29864. {
  29865. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29866. }
  29867. }); //
  29868. Object.assign(ExtrudeGeometry.prototype, {
  29869. getArrays: function getArrays() {
  29870. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  29871. },
  29872. addShapeList: function addShapeList() {
  29873. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  29874. },
  29875. addShape: function addShape() {
  29876. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  29877. }
  29878. }); //
  29879. Object.assign(Scene.prototype, {
  29880. dispose: function dispose() {
  29881. console.error('THREE.Scene: .dispose() has been removed.');
  29882. }
  29883. }); //
  29884. Object.defineProperties(Uniform.prototype, {
  29885. dynamic: {
  29886. set: function set() {
  29887. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29888. }
  29889. },
  29890. onUpdate: {
  29891. value: function value() {
  29892. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29893. return this;
  29894. }
  29895. }
  29896. }); //
  29897. Object.defineProperties(Material.prototype, {
  29898. wrapAround: {
  29899. get: function get() {
  29900. console.warn('THREE.Material: .wrapAround has been removed.');
  29901. },
  29902. set: function set() {
  29903. console.warn('THREE.Material: .wrapAround has been removed.');
  29904. }
  29905. },
  29906. overdraw: {
  29907. get: function get() {
  29908. console.warn('THREE.Material: .overdraw has been removed.');
  29909. },
  29910. set: function set() {
  29911. console.warn('THREE.Material: .overdraw has been removed.');
  29912. }
  29913. },
  29914. wrapRGB: {
  29915. get: function get() {
  29916. console.warn('THREE.Material: .wrapRGB has been removed.');
  29917. return new Color();
  29918. }
  29919. },
  29920. shading: {
  29921. get: function get() {
  29922. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29923. },
  29924. set: function set(value) {
  29925. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29926. this.flatShading = value === FlatShading;
  29927. }
  29928. },
  29929. stencilMask: {
  29930. get: function get() {
  29931. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29932. return this.stencilFuncMask;
  29933. },
  29934. set: function set(value) {
  29935. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29936. this.stencilFuncMask = value;
  29937. }
  29938. }
  29939. });
  29940. Object.defineProperties(MeshPhongMaterial.prototype, {
  29941. metal: {
  29942. get: function get() {
  29943. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29944. return false;
  29945. },
  29946. set: function set() {
  29947. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29948. }
  29949. }
  29950. });
  29951. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29952. transparency: {
  29953. get: function get() {
  29954. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29955. return this.transmission;
  29956. },
  29957. set: function set(value) {
  29958. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29959. this.transmission = value;
  29960. }
  29961. }
  29962. });
  29963. Object.defineProperties(ShaderMaterial.prototype, {
  29964. derivatives: {
  29965. get: function get() {
  29966. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29967. return this.extensions.derivatives;
  29968. },
  29969. set: function set(value) {
  29970. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29971. this.extensions.derivatives = value;
  29972. }
  29973. }
  29974. }); //
  29975. Object.assign(WebGLRenderer.prototype, {
  29976. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29977. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29978. this.setRenderTarget(renderTarget);
  29979. this.clear(color, depth, stencil);
  29980. },
  29981. animate: function animate(callback) {
  29982. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29983. this.setAnimationLoop(callback);
  29984. },
  29985. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29986. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29987. return this.getRenderTarget();
  29988. },
  29989. getMaxAnisotropy: function getMaxAnisotropy() {
  29990. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29991. return this.capabilities.getMaxAnisotropy();
  29992. },
  29993. getPrecision: function getPrecision() {
  29994. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29995. return this.capabilities.precision;
  29996. },
  29997. resetGLState: function resetGLState() {
  29998. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29999. return this.state.reset();
  30000. },
  30001. supportsFloatTextures: function supportsFloatTextures() {
  30002. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  30003. return this.extensions.get('OES_texture_float');
  30004. },
  30005. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  30006. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  30007. return this.extensions.get('OES_texture_half_float');
  30008. },
  30009. supportsStandardDerivatives: function supportsStandardDerivatives() {
  30010. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  30011. return this.extensions.get('OES_standard_derivatives');
  30012. },
  30013. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  30014. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  30015. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  30016. },
  30017. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  30018. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  30019. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  30020. },
  30021. supportsBlendMinMax: function supportsBlendMinMax() {
  30022. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  30023. return this.extensions.get('EXT_blend_minmax');
  30024. },
  30025. supportsVertexTextures: function supportsVertexTextures() {
  30026. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  30027. return this.capabilities.vertexTextures;
  30028. },
  30029. supportsInstancedArrays: function supportsInstancedArrays() {
  30030. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  30031. return this.extensions.get('ANGLE_instanced_arrays');
  30032. },
  30033. enableScissorTest: function enableScissorTest(boolean) {
  30034. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  30035. this.setScissorTest(boolean);
  30036. },
  30037. initMaterial: function initMaterial() {
  30038. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  30039. },
  30040. addPrePlugin: function addPrePlugin() {
  30041. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  30042. },
  30043. addPostPlugin: function addPostPlugin() {
  30044. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  30045. },
  30046. updateShadowMap: function updateShadowMap() {
  30047. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  30048. },
  30049. setFaceCulling: function setFaceCulling() {
  30050. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  30051. },
  30052. allocTextureUnit: function allocTextureUnit() {
  30053. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  30054. },
  30055. setTexture: function setTexture() {
  30056. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  30057. },
  30058. setTexture2D: function setTexture2D() {
  30059. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  30060. },
  30061. setTextureCube: function setTextureCube() {
  30062. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  30063. },
  30064. getActiveMipMapLevel: function getActiveMipMapLevel() {
  30065. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  30066. return this.getActiveMipmapLevel();
  30067. }
  30068. });
  30069. Object.defineProperties(WebGLRenderer.prototype, {
  30070. shadowMapEnabled: {
  30071. get: function get() {
  30072. return this.shadowMap.enabled;
  30073. },
  30074. set: function set(value) {
  30075. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  30076. this.shadowMap.enabled = value;
  30077. }
  30078. },
  30079. shadowMapType: {
  30080. get: function get() {
  30081. return this.shadowMap.type;
  30082. },
  30083. set: function set(value) {
  30084. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  30085. this.shadowMap.type = value;
  30086. }
  30087. },
  30088. shadowMapCullFace: {
  30089. get: function get() {
  30090. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30091. return undefined;
  30092. },
  30093. set: function set()
  30094. /* value */
  30095. {
  30096. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  30097. }
  30098. },
  30099. context: {
  30100. get: function get() {
  30101. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  30102. return this.getContext();
  30103. }
  30104. },
  30105. vr: {
  30106. get: function get() {
  30107. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  30108. return this.xr;
  30109. }
  30110. },
  30111. gammaInput: {
  30112. get: function get() {
  30113. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30114. return false;
  30115. },
  30116. set: function set() {
  30117. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  30118. }
  30119. },
  30120. gammaOutput: {
  30121. get: function get() {
  30122. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30123. return false;
  30124. },
  30125. set: function set(value) {
  30126. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  30127. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  30128. }
  30129. },
  30130. toneMappingWhitePoint: {
  30131. get: function get() {
  30132. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30133. return 1.0;
  30134. },
  30135. set: function set() {
  30136. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  30137. }
  30138. }
  30139. });
  30140. Object.defineProperties(WebGLShadowMap.prototype, {
  30141. cullFace: {
  30142. get: function get() {
  30143. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30144. return undefined;
  30145. },
  30146. set: function set()
  30147. /* cullFace */
  30148. {
  30149. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  30150. }
  30151. },
  30152. renderReverseSided: {
  30153. get: function get() {
  30154. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30155. return undefined;
  30156. },
  30157. set: function set() {
  30158. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30159. }
  30160. },
  30161. renderSingleSided: {
  30162. get: function get() {
  30163. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30164. return undefined;
  30165. },
  30166. set: function set() {
  30167. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30168. }
  30169. }
  30170. });
  30171. function WebGLRenderTargetCube(width, height, options) {
  30172. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30173. return new WebGLCubeRenderTarget(width, options);
  30174. } //
  30175. Object.defineProperties(WebGLRenderTarget.prototype, {
  30176. wrapS: {
  30177. get: function get() {
  30178. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30179. return this.texture.wrapS;
  30180. },
  30181. set: function set(value) {
  30182. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30183. this.texture.wrapS = value;
  30184. }
  30185. },
  30186. wrapT: {
  30187. get: function get() {
  30188. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30189. return this.texture.wrapT;
  30190. },
  30191. set: function set(value) {
  30192. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30193. this.texture.wrapT = value;
  30194. }
  30195. },
  30196. magFilter: {
  30197. get: function get() {
  30198. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30199. return this.texture.magFilter;
  30200. },
  30201. set: function set(value) {
  30202. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30203. this.texture.magFilter = value;
  30204. }
  30205. },
  30206. minFilter: {
  30207. get: function get() {
  30208. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30209. return this.texture.minFilter;
  30210. },
  30211. set: function set(value) {
  30212. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30213. this.texture.minFilter = value;
  30214. }
  30215. },
  30216. anisotropy: {
  30217. get: function get() {
  30218. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30219. return this.texture.anisotropy;
  30220. },
  30221. set: function set(value) {
  30222. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30223. this.texture.anisotropy = value;
  30224. }
  30225. },
  30226. offset: {
  30227. get: function get() {
  30228. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30229. return this.texture.offset;
  30230. },
  30231. set: function set(value) {
  30232. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30233. this.texture.offset = value;
  30234. }
  30235. },
  30236. repeat: {
  30237. get: function get() {
  30238. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30239. return this.texture.repeat;
  30240. },
  30241. set: function set(value) {
  30242. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30243. this.texture.repeat = value;
  30244. }
  30245. },
  30246. format: {
  30247. get: function get() {
  30248. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30249. return this.texture.format;
  30250. },
  30251. set: function set(value) {
  30252. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30253. this.texture.format = value;
  30254. }
  30255. },
  30256. type: {
  30257. get: function get() {
  30258. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30259. return this.texture.type;
  30260. },
  30261. set: function set(value) {
  30262. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30263. this.texture.type = value;
  30264. }
  30265. },
  30266. generateMipmaps: {
  30267. get: function get() {
  30268. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30269. return this.texture.generateMipmaps;
  30270. },
  30271. set: function set(value) {
  30272. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30273. this.texture.generateMipmaps = value;
  30274. }
  30275. }
  30276. }); //
  30277. Object.defineProperties(Audio.prototype, {
  30278. load: {
  30279. value: function value(file) {
  30280. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30281. var scope = this;
  30282. var audioLoader = new AudioLoader();
  30283. audioLoader.load(file, function (buffer) {
  30284. scope.setBuffer(buffer);
  30285. });
  30286. return this;
  30287. }
  30288. },
  30289. startTime: {
  30290. set: function set() {
  30291. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30292. }
  30293. }
  30294. });
  30295. AudioAnalyser.prototype.getData = function () {
  30296. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30297. return this.getFrequencyData();
  30298. }; //
  30299. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30300. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30301. return this.update(renderer, scene);
  30302. };
  30303. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30304. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30305. return this.renderTarget.clear(renderer, color, depth, stencil);
  30306. };
  30307. ImageUtils.crossOrigin = undefined;
  30308. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30309. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30310. var loader = new TextureLoader();
  30311. loader.setCrossOrigin(this.crossOrigin);
  30312. var texture = loader.load(url, onLoad, undefined, onError);
  30313. if (mapping) texture.mapping = mapping;
  30314. return texture;
  30315. };
  30316. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30317. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30318. var loader = new CubeTextureLoader();
  30319. loader.setCrossOrigin(this.crossOrigin);
  30320. var texture = loader.load(urls, onLoad, undefined, onError);
  30321. if (mapping) texture.mapping = mapping;
  30322. return texture;
  30323. };
  30324. ImageUtils.loadCompressedTexture = function () {
  30325. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30326. };
  30327. ImageUtils.loadCompressedTextureCube = function () {
  30328. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30329. }; //
  30330. function CanvasRenderer() {
  30331. console.error('THREE.CanvasRenderer has been removed');
  30332. } //
  30333. function JSONLoader() {
  30334. console.error('THREE.JSONLoader has been removed.');
  30335. } //
  30336. var SceneUtils = {
  30337. createMultiMaterialObject: function createMultiMaterialObject()
  30338. /* geometry, materials */
  30339. {
  30340. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30341. },
  30342. detach: function detach()
  30343. /* child, parent, scene */
  30344. {
  30345. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30346. },
  30347. attach: function attach()
  30348. /* child, scene, parent */
  30349. {
  30350. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30351. }
  30352. }; //
  30353. function LensFlare() {
  30354. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30355. }
  30356. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30357. /* eslint-disable no-undef */
  30358. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30359. detail: {
  30360. revision: REVISION
  30361. }
  30362. }));
  30363. /* eslint-enable no-undef */
  30364. }
  30365. if (typeof window !== 'undefined') {
  30366. if (window.__THREE__) {
  30367. console.warn('WARNING: Multiple instances of Three.js being imported.');
  30368. } else {
  30369. window.__THREE__ = REVISION;
  30370. }
  30371. }
  30372. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30373. exports.AddEquation = AddEquation;
  30374. exports.AddOperation = AddOperation;
  30375. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30376. exports.AdditiveBlending = AdditiveBlending;
  30377. exports.AlphaFormat = AlphaFormat;
  30378. exports.AlwaysDepth = AlwaysDepth;
  30379. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30380. exports.AmbientLight = AmbientLight;
  30381. exports.AmbientLightProbe = AmbientLightProbe;
  30382. exports.AnimationClip = AnimationClip;
  30383. exports.AnimationLoader = AnimationLoader;
  30384. exports.AnimationMixer = AnimationMixer;
  30385. exports.AnimationObjectGroup = AnimationObjectGroup;
  30386. exports.AnimationUtils = AnimationUtils;
  30387. exports.ArcCurve = ArcCurve;
  30388. exports.ArrayCamera = ArrayCamera;
  30389. exports.ArrowHelper = ArrowHelper;
  30390. exports.Audio = Audio;
  30391. exports.AudioAnalyser = AudioAnalyser;
  30392. exports.AudioContext = AudioContext;
  30393. exports.AudioListener = AudioListener;
  30394. exports.AudioLoader = AudioLoader;
  30395. exports.AxesHelper = AxesHelper;
  30396. exports.AxisHelper = AxisHelper;
  30397. exports.BackSide = BackSide;
  30398. exports.BasicDepthPacking = BasicDepthPacking;
  30399. exports.BasicShadowMap = BasicShadowMap;
  30400. exports.BinaryTextureLoader = BinaryTextureLoader;
  30401. exports.Bone = Bone;
  30402. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30403. exports.BoundingBoxHelper = BoundingBoxHelper;
  30404. exports.Box2 = Box2;
  30405. exports.Box3 = Box3;
  30406. exports.Box3Helper = Box3Helper;
  30407. exports.BoxBufferGeometry = BoxGeometry;
  30408. exports.BoxGeometry = BoxGeometry;
  30409. exports.BoxHelper = BoxHelper;
  30410. exports.BufferAttribute = BufferAttribute;
  30411. exports.BufferGeometry = BufferGeometry;
  30412. exports.BufferGeometryLoader = BufferGeometryLoader;
  30413. exports.ByteType = ByteType;
  30414. exports.Cache = Cache;
  30415. exports.Camera = Camera;
  30416. exports.CameraHelper = CameraHelper;
  30417. exports.CanvasRenderer = CanvasRenderer;
  30418. exports.CanvasTexture = CanvasTexture;
  30419. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30420. exports.CineonToneMapping = CineonToneMapping;
  30421. exports.CircleBufferGeometry = CircleGeometry;
  30422. exports.CircleGeometry = CircleGeometry;
  30423. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30424. exports.Clock = Clock;
  30425. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30426. exports.Color = Color;
  30427. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30428. exports.CompressedTexture = CompressedTexture;
  30429. exports.CompressedTextureLoader = CompressedTextureLoader;
  30430. exports.ConeBufferGeometry = ConeGeometry;
  30431. exports.ConeGeometry = ConeGeometry;
  30432. exports.CubeCamera = CubeCamera;
  30433. exports.CubeReflectionMapping = CubeReflectionMapping;
  30434. exports.CubeRefractionMapping = CubeRefractionMapping;
  30435. exports.CubeTexture = CubeTexture;
  30436. exports.CubeTextureLoader = CubeTextureLoader;
  30437. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30438. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30439. exports.CubicBezierCurve = CubicBezierCurve;
  30440. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30441. exports.CubicInterpolant = CubicInterpolant;
  30442. exports.CullFaceBack = CullFaceBack;
  30443. exports.CullFaceFront = CullFaceFront;
  30444. exports.CullFaceFrontBack = CullFaceFrontBack;
  30445. exports.CullFaceNone = CullFaceNone;
  30446. exports.Curve = Curve;
  30447. exports.CurvePath = CurvePath;
  30448. exports.CustomBlending = CustomBlending;
  30449. exports.CustomToneMapping = CustomToneMapping;
  30450. exports.CylinderBufferGeometry = CylinderGeometry;
  30451. exports.CylinderGeometry = CylinderGeometry;
  30452. exports.Cylindrical = Cylindrical;
  30453. exports.DataTexture = DataTexture;
  30454. exports.DataTexture2DArray = DataTexture2DArray;
  30455. exports.DataTexture3D = DataTexture3D;
  30456. exports.DataTextureLoader = DataTextureLoader;
  30457. exports.DataUtils = DataUtils;
  30458. exports.DecrementStencilOp = DecrementStencilOp;
  30459. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30460. exports.DefaultLoadingManager = DefaultLoadingManager;
  30461. exports.DepthFormat = DepthFormat;
  30462. exports.DepthStencilFormat = DepthStencilFormat;
  30463. exports.DepthTexture = DepthTexture;
  30464. exports.DirectionalLight = DirectionalLight;
  30465. exports.DirectionalLightHelper = DirectionalLightHelper;
  30466. exports.DiscreteInterpolant = DiscreteInterpolant;
  30467. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30468. exports.DodecahedronGeometry = DodecahedronGeometry;
  30469. exports.DoubleSide = DoubleSide;
  30470. exports.DstAlphaFactor = DstAlphaFactor;
  30471. exports.DstColorFactor = DstColorFactor;
  30472. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30473. exports.DynamicCopyUsage = DynamicCopyUsage;
  30474. exports.DynamicDrawUsage = DynamicDrawUsage;
  30475. exports.DynamicReadUsage = DynamicReadUsage;
  30476. exports.EdgesGeometry = EdgesGeometry;
  30477. exports.EdgesHelper = EdgesHelper;
  30478. exports.EllipseCurve = EllipseCurve;
  30479. exports.EqualDepth = EqualDepth;
  30480. exports.EqualStencilFunc = EqualStencilFunc;
  30481. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30482. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30483. exports.Euler = Euler;
  30484. exports.EventDispatcher = EventDispatcher;
  30485. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30486. exports.ExtrudeGeometry = ExtrudeGeometry;
  30487. exports.FaceColors = FaceColors;
  30488. exports.FileLoader = FileLoader;
  30489. exports.FlatShading = FlatShading;
  30490. exports.Float16BufferAttribute = Float16BufferAttribute;
  30491. exports.Float32Attribute = Float32Attribute;
  30492. exports.Float32BufferAttribute = Float32BufferAttribute;
  30493. exports.Float64Attribute = Float64Attribute;
  30494. exports.Float64BufferAttribute = Float64BufferAttribute;
  30495. exports.FloatType = FloatType;
  30496. exports.Fog = Fog;
  30497. exports.FogExp2 = FogExp2;
  30498. exports.Font = Font;
  30499. exports.FontLoader = FontLoader;
  30500. exports.FrontSide = FrontSide;
  30501. exports.Frustum = Frustum;
  30502. exports.GLBufferAttribute = GLBufferAttribute;
  30503. exports.GLSL1 = GLSL1;
  30504. exports.GLSL3 = GLSL3;
  30505. exports.GammaEncoding = GammaEncoding;
  30506. exports.GreaterDepth = GreaterDepth;
  30507. exports.GreaterEqualDepth = GreaterEqualDepth;
  30508. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30509. exports.GreaterStencilFunc = GreaterStencilFunc;
  30510. exports.GridHelper = GridHelper;
  30511. exports.Group = Group;
  30512. exports.HalfFloatType = HalfFloatType;
  30513. exports.HemisphereLight = HemisphereLight;
  30514. exports.HemisphereLightHelper = HemisphereLightHelper;
  30515. exports.HemisphereLightProbe = HemisphereLightProbe;
  30516. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30517. exports.IcosahedronGeometry = IcosahedronGeometry;
  30518. exports.ImageBitmapLoader = ImageBitmapLoader;
  30519. exports.ImageLoader = ImageLoader;
  30520. exports.ImageUtils = ImageUtils;
  30521. exports.ImmediateRenderObject = ImmediateRenderObject;
  30522. exports.IncrementStencilOp = IncrementStencilOp;
  30523. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30524. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30525. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30526. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30527. exports.InstancedMesh = InstancedMesh;
  30528. exports.Int16Attribute = Int16Attribute;
  30529. exports.Int16BufferAttribute = Int16BufferAttribute;
  30530. exports.Int32Attribute = Int32Attribute;
  30531. exports.Int32BufferAttribute = Int32BufferAttribute;
  30532. exports.Int8Attribute = Int8Attribute;
  30533. exports.Int8BufferAttribute = Int8BufferAttribute;
  30534. exports.IntType = IntType;
  30535. exports.InterleavedBuffer = InterleavedBuffer;
  30536. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30537. exports.Interpolant = Interpolant;
  30538. exports.InterpolateDiscrete = InterpolateDiscrete;
  30539. exports.InterpolateLinear = InterpolateLinear;
  30540. exports.InterpolateSmooth = InterpolateSmooth;
  30541. exports.InvertStencilOp = InvertStencilOp;
  30542. exports.JSONLoader = JSONLoader;
  30543. exports.KeepStencilOp = KeepStencilOp;
  30544. exports.KeyframeTrack = KeyframeTrack;
  30545. exports.LOD = LOD;
  30546. exports.LatheBufferGeometry = LatheGeometry;
  30547. exports.LatheGeometry = LatheGeometry;
  30548. exports.Layers = Layers;
  30549. exports.LensFlare = LensFlare;
  30550. exports.LessDepth = LessDepth;
  30551. exports.LessEqualDepth = LessEqualDepth;
  30552. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30553. exports.LessStencilFunc = LessStencilFunc;
  30554. exports.Light = Light;
  30555. exports.LightProbe = LightProbe;
  30556. exports.Line = Line;
  30557. exports.Line3 = Line3;
  30558. exports.LineBasicMaterial = LineBasicMaterial;
  30559. exports.LineCurve = LineCurve;
  30560. exports.LineCurve3 = LineCurve3;
  30561. exports.LineDashedMaterial = LineDashedMaterial;
  30562. exports.LineLoop = LineLoop;
  30563. exports.LinePieces = LinePieces;
  30564. exports.LineSegments = LineSegments;
  30565. exports.LineStrip = LineStrip;
  30566. exports.LinearEncoding = LinearEncoding;
  30567. exports.LinearFilter = LinearFilter;
  30568. exports.LinearInterpolant = LinearInterpolant;
  30569. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30570. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30571. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30572. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30573. exports.LinearToneMapping = LinearToneMapping;
  30574. exports.Loader = Loader;
  30575. exports.LoaderUtils = LoaderUtils;
  30576. exports.LoadingManager = LoadingManager;
  30577. exports.LogLuvEncoding = LogLuvEncoding;
  30578. exports.LoopOnce = LoopOnce;
  30579. exports.LoopPingPong = LoopPingPong;
  30580. exports.LoopRepeat = LoopRepeat;
  30581. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30582. exports.LuminanceFormat = LuminanceFormat;
  30583. exports.MOUSE = MOUSE;
  30584. exports.Material = Material;
  30585. exports.MaterialLoader = MaterialLoader;
  30586. exports.Math = MathUtils;
  30587. exports.MathUtils = MathUtils;
  30588. exports.Matrix3 = Matrix3;
  30589. exports.Matrix4 = Matrix4;
  30590. exports.MaxEquation = MaxEquation;
  30591. exports.Mesh = Mesh;
  30592. exports.MeshBasicMaterial = MeshBasicMaterial;
  30593. exports.MeshDepthMaterial = MeshDepthMaterial;
  30594. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30595. exports.MeshFaceMaterial = MeshFaceMaterial;
  30596. exports.MeshLambertMaterial = MeshLambertMaterial;
  30597. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30598. exports.MeshNormalMaterial = MeshNormalMaterial;
  30599. exports.MeshPhongMaterial = MeshPhongMaterial;
  30600. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30601. exports.MeshStandardMaterial = MeshStandardMaterial;
  30602. exports.MeshToonMaterial = MeshToonMaterial;
  30603. exports.MinEquation = MinEquation;
  30604. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30605. exports.MixOperation = MixOperation;
  30606. exports.MultiMaterial = MultiMaterial;
  30607. exports.MultiplyBlending = MultiplyBlending;
  30608. exports.MultiplyOperation = MultiplyOperation;
  30609. exports.NearestFilter = NearestFilter;
  30610. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30611. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30612. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30613. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30614. exports.NeverDepth = NeverDepth;
  30615. exports.NeverStencilFunc = NeverStencilFunc;
  30616. exports.NoBlending = NoBlending;
  30617. exports.NoColors = NoColors;
  30618. exports.NoToneMapping = NoToneMapping;
  30619. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30620. exports.NormalBlending = NormalBlending;
  30621. exports.NotEqualDepth = NotEqualDepth;
  30622. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30623. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30624. exports.Object3D = Object3D;
  30625. exports.ObjectLoader = ObjectLoader;
  30626. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30627. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30628. exports.OctahedronGeometry = OctahedronGeometry;
  30629. exports.OneFactor = OneFactor;
  30630. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30631. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30632. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30633. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30634. exports.OrthographicCamera = OrthographicCamera;
  30635. exports.PCFShadowMap = PCFShadowMap;
  30636. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30637. exports.PMREMGenerator = PMREMGenerator;
  30638. exports.ParametricBufferGeometry = ParametricGeometry;
  30639. exports.ParametricGeometry = ParametricGeometry;
  30640. exports.Particle = Particle;
  30641. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30642. exports.ParticleSystem = ParticleSystem;
  30643. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30644. exports.Path = Path;
  30645. exports.PerspectiveCamera = PerspectiveCamera;
  30646. exports.Plane = Plane;
  30647. exports.PlaneBufferGeometry = PlaneGeometry;
  30648. exports.PlaneGeometry = PlaneGeometry;
  30649. exports.PlaneHelper = PlaneHelper;
  30650. exports.PointCloud = PointCloud;
  30651. exports.PointCloudMaterial = PointCloudMaterial;
  30652. exports.PointLight = PointLight;
  30653. exports.PointLightHelper = PointLightHelper;
  30654. exports.Points = Points;
  30655. exports.PointsMaterial = PointsMaterial;
  30656. exports.PolarGridHelper = PolarGridHelper;
  30657. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30658. exports.PolyhedronGeometry = PolyhedronGeometry;
  30659. exports.PositionalAudio = PositionalAudio;
  30660. exports.PropertyBinding = PropertyBinding;
  30661. exports.PropertyMixer = PropertyMixer;
  30662. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30663. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30664. exports.Quaternion = Quaternion;
  30665. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30666. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30667. exports.REVISION = REVISION;
  30668. exports.RGBADepthPacking = RGBADepthPacking;
  30669. exports.RGBAFormat = RGBAFormat;
  30670. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30671. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30672. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30673. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30674. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30675. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30676. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30677. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30678. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30679. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30680. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30681. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30682. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30683. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30684. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30685. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30686. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30687. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30688. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30689. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30690. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30691. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30692. exports.RGBDEncoding = RGBDEncoding;
  30693. exports.RGBEEncoding = RGBEEncoding;
  30694. exports.RGBEFormat = RGBEFormat;
  30695. exports.RGBFormat = RGBFormat;
  30696. exports.RGBIntegerFormat = RGBIntegerFormat;
  30697. exports.RGBM16Encoding = RGBM16Encoding;
  30698. exports.RGBM7Encoding = RGBM7Encoding;
  30699. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30700. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30701. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30702. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30703. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30704. exports.RGFormat = RGFormat;
  30705. exports.RGIntegerFormat = RGIntegerFormat;
  30706. exports.RawShaderMaterial = RawShaderMaterial;
  30707. exports.Ray = Ray;
  30708. exports.Raycaster = Raycaster;
  30709. exports.RectAreaLight = RectAreaLight;
  30710. exports.RedFormat = RedFormat;
  30711. exports.RedIntegerFormat = RedIntegerFormat;
  30712. exports.ReinhardToneMapping = ReinhardToneMapping;
  30713. exports.RepeatWrapping = RepeatWrapping;
  30714. exports.ReplaceStencilOp = ReplaceStencilOp;
  30715. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30716. exports.RingBufferGeometry = RingGeometry;
  30717. exports.RingGeometry = RingGeometry;
  30718. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30719. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30720. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30721. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30722. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30723. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30724. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30725. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30726. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30727. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30728. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30729. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30730. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30731. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30732. exports.Scene = Scene;
  30733. exports.SceneUtils = SceneUtils;
  30734. exports.ShaderChunk = ShaderChunk;
  30735. exports.ShaderLib = ShaderLib;
  30736. exports.ShaderMaterial = ShaderMaterial;
  30737. exports.ShadowMaterial = ShadowMaterial;
  30738. exports.Shape = Shape;
  30739. exports.ShapeBufferGeometry = ShapeGeometry;
  30740. exports.ShapeGeometry = ShapeGeometry;
  30741. exports.ShapePath = ShapePath;
  30742. exports.ShapeUtils = ShapeUtils;
  30743. exports.ShortType = ShortType;
  30744. exports.Skeleton = Skeleton;
  30745. exports.SkeletonHelper = SkeletonHelper;
  30746. exports.SkinnedMesh = SkinnedMesh;
  30747. exports.SmoothShading = SmoothShading;
  30748. exports.Sphere = Sphere;
  30749. exports.SphereBufferGeometry = SphereGeometry;
  30750. exports.SphereGeometry = SphereGeometry;
  30751. exports.Spherical = Spherical;
  30752. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30753. exports.Spline = Spline;
  30754. exports.SplineCurve = SplineCurve;
  30755. exports.SplineCurve3 = SplineCurve3;
  30756. exports.SpotLight = SpotLight;
  30757. exports.SpotLightHelper = SpotLightHelper;
  30758. exports.Sprite = Sprite;
  30759. exports.SpriteMaterial = SpriteMaterial;
  30760. exports.SrcAlphaFactor = SrcAlphaFactor;
  30761. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30762. exports.SrcColorFactor = SrcColorFactor;
  30763. exports.StaticCopyUsage = StaticCopyUsage;
  30764. exports.StaticDrawUsage = StaticDrawUsage;
  30765. exports.StaticReadUsage = StaticReadUsage;
  30766. exports.StereoCamera = StereoCamera;
  30767. exports.StreamCopyUsage = StreamCopyUsage;
  30768. exports.StreamDrawUsage = StreamDrawUsage;
  30769. exports.StreamReadUsage = StreamReadUsage;
  30770. exports.StringKeyframeTrack = StringKeyframeTrack;
  30771. exports.SubtractEquation = SubtractEquation;
  30772. exports.SubtractiveBlending = SubtractiveBlending;
  30773. exports.TOUCH = TOUCH;
  30774. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30775. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  30776. exports.TetrahedronGeometry = TetrahedronGeometry;
  30777. exports.TextBufferGeometry = TextGeometry;
  30778. exports.TextGeometry = TextGeometry;
  30779. exports.Texture = Texture;
  30780. exports.TextureLoader = TextureLoader;
  30781. exports.TorusBufferGeometry = TorusGeometry;
  30782. exports.TorusGeometry = TorusGeometry;
  30783. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  30784. exports.TorusKnotGeometry = TorusKnotGeometry;
  30785. exports.Triangle = Triangle;
  30786. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30787. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30788. exports.TrianglesDrawMode = TrianglesDrawMode;
  30789. exports.TubeBufferGeometry = TubeGeometry;
  30790. exports.TubeGeometry = TubeGeometry;
  30791. exports.UVMapping = UVMapping;
  30792. exports.Uint16Attribute = Uint16Attribute;
  30793. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30794. exports.Uint32Attribute = Uint32Attribute;
  30795. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30796. exports.Uint8Attribute = Uint8Attribute;
  30797. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30798. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30799. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30800. exports.Uniform = Uniform;
  30801. exports.UniformsLib = UniformsLib;
  30802. exports.UniformsUtils = UniformsUtils;
  30803. exports.UnsignedByteType = UnsignedByteType;
  30804. exports.UnsignedInt248Type = UnsignedInt248Type;
  30805. exports.UnsignedIntType = UnsignedIntType;
  30806. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30807. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30808. exports.UnsignedShort565Type = UnsignedShort565Type;
  30809. exports.UnsignedShortType = UnsignedShortType;
  30810. exports.VSMShadowMap = VSMShadowMap;
  30811. exports.Vector2 = Vector2;
  30812. exports.Vector3 = Vector3;
  30813. exports.Vector4 = Vector4;
  30814. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30815. exports.Vertex = Vertex;
  30816. exports.VertexColors = VertexColors;
  30817. exports.VideoTexture = VideoTexture;
  30818. exports.WebGL1Renderer = WebGL1Renderer;
  30819. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30820. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30821. exports.WebGLRenderTarget = WebGLRenderTarget;
  30822. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30823. exports.WebGLRenderer = WebGLRenderer;
  30824. exports.WebGLUtils = WebGLUtils;
  30825. exports.WireframeGeometry = WireframeGeometry;
  30826. exports.WireframeHelper = WireframeHelper;
  30827. exports.WrapAroundEnding = WrapAroundEnding;
  30828. exports.XHRLoader = XHRLoader;
  30829. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30830. exports.ZeroFactor = ZeroFactor;
  30831. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30832. exports.ZeroStencilOp = ZeroStencilOp;
  30833. exports.sRGBEncoding = sRGBEncoding;
  30834. Object.defineProperty(exports, '__esModule', { value: true });
  30835. })));