three.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343
  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 = '125dev';
  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. // https://www.desmos.com/calculator/vcsjnyz7x4
  1022. pingpong: function pingpong(x, length) {
  1023. if (length === void 0) {
  1024. length = 1;
  1025. }
  1026. return length - Math.abs(MathUtils.euclideanModulo(x, length * 2) - length);
  1027. },
  1028. // http://en.wikipedia.org/wiki/Smoothstep
  1029. smoothstep: function smoothstep(x, min, max) {
  1030. if (x <= min) return 0;
  1031. if (x >= max) return 1;
  1032. x = (x - min) / (max - min);
  1033. return x * x * (3 - 2 * x);
  1034. },
  1035. smootherstep: function smootherstep(x, min, max) {
  1036. if (x <= min) return 0;
  1037. if (x >= max) return 1;
  1038. x = (x - min) / (max - min);
  1039. return x * x * x * (x * (x * 6 - 15) + 10);
  1040. },
  1041. // Random integer from <low, high> interval
  1042. randInt: function randInt(low, high) {
  1043. return low + Math.floor(Math.random() * (high - low + 1));
  1044. },
  1045. // Random float from <low, high> interval
  1046. randFloat: function randFloat(low, high) {
  1047. return low + Math.random() * (high - low);
  1048. },
  1049. // Random float from <-range/2, range/2> interval
  1050. randFloatSpread: function randFloatSpread(range) {
  1051. return range * (0.5 - Math.random());
  1052. },
  1053. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  1054. seededRandom: function seededRandom(s) {
  1055. if (s !== undefined) _seed = s % 2147483647; // Park-Miller algorithm
  1056. _seed = _seed * 16807 % 2147483647;
  1057. return (_seed - 1) / 2147483646;
  1058. },
  1059. degToRad: function degToRad(degrees) {
  1060. return degrees * MathUtils.DEG2RAD;
  1061. },
  1062. radToDeg: function radToDeg(radians) {
  1063. return radians * MathUtils.RAD2DEG;
  1064. },
  1065. isPowerOfTwo: function isPowerOfTwo(value) {
  1066. return (value & value - 1) === 0 && value !== 0;
  1067. },
  1068. ceilPowerOfTwo: function ceilPowerOfTwo(value) {
  1069. return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
  1070. },
  1071. floorPowerOfTwo: function floorPowerOfTwo(value) {
  1072. return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
  1073. },
  1074. setQuaternionFromProperEuler: function setQuaternionFromProperEuler(q, a, b, c, order) {
  1075. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  1076. // rotations are applied to the axes in the order specified by 'order'
  1077. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  1078. // angles are in radians
  1079. var cos = Math.cos;
  1080. var sin = Math.sin;
  1081. var c2 = cos(b / 2);
  1082. var s2 = sin(b / 2);
  1083. var c13 = cos((a + c) / 2);
  1084. var s13 = sin((a + c) / 2);
  1085. var c1_3 = cos((a - c) / 2);
  1086. var s1_3 = sin((a - c) / 2);
  1087. var c3_1 = cos((c - a) / 2);
  1088. var s3_1 = sin((c - a) / 2);
  1089. switch (order) {
  1090. case 'XYX':
  1091. q.set(c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13);
  1092. break;
  1093. case 'YZY':
  1094. q.set(s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13);
  1095. break;
  1096. case 'ZXZ':
  1097. q.set(s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13);
  1098. break;
  1099. case 'XZX':
  1100. q.set(c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13);
  1101. break;
  1102. case 'YXY':
  1103. q.set(s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13);
  1104. break;
  1105. case 'ZYZ':
  1106. q.set(s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13);
  1107. break;
  1108. default:
  1109. console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order);
  1110. }
  1111. }
  1112. };
  1113. var Vector2 = /*#__PURE__*/function () {
  1114. function Vector2(x, y) {
  1115. if (x === void 0) {
  1116. x = 0;
  1117. }
  1118. if (y === void 0) {
  1119. y = 0;
  1120. }
  1121. Object.defineProperty(this, 'isVector2', {
  1122. value: true
  1123. });
  1124. this.x = x;
  1125. this.y = y;
  1126. }
  1127. var _proto = Vector2.prototype;
  1128. _proto.set = function set(x, y) {
  1129. this.x = x;
  1130. this.y = y;
  1131. return this;
  1132. };
  1133. _proto.setScalar = function setScalar(scalar) {
  1134. this.x = scalar;
  1135. this.y = scalar;
  1136. return this;
  1137. };
  1138. _proto.setX = function setX(x) {
  1139. this.x = x;
  1140. return this;
  1141. };
  1142. _proto.setY = function setY(y) {
  1143. this.y = y;
  1144. return this;
  1145. };
  1146. _proto.setComponent = function setComponent(index, value) {
  1147. switch (index) {
  1148. case 0:
  1149. this.x = value;
  1150. break;
  1151. case 1:
  1152. this.y = value;
  1153. break;
  1154. default:
  1155. throw new Error('index is out of range: ' + index);
  1156. }
  1157. return this;
  1158. };
  1159. _proto.getComponent = function getComponent(index) {
  1160. switch (index) {
  1161. case 0:
  1162. return this.x;
  1163. case 1:
  1164. return this.y;
  1165. default:
  1166. throw new Error('index is out of range: ' + index);
  1167. }
  1168. };
  1169. _proto.clone = function clone() {
  1170. return new this.constructor(this.x, this.y);
  1171. };
  1172. _proto.copy = function copy(v) {
  1173. this.x = v.x;
  1174. this.y = v.y;
  1175. return this;
  1176. };
  1177. _proto.add = function add(v, w) {
  1178. if (w !== undefined) {
  1179. console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  1180. return this.addVectors(v, w);
  1181. }
  1182. this.x += v.x;
  1183. this.y += v.y;
  1184. return this;
  1185. };
  1186. _proto.addScalar = function addScalar(s) {
  1187. this.x += s;
  1188. this.y += s;
  1189. return this;
  1190. };
  1191. _proto.addVectors = function addVectors(a, b) {
  1192. this.x = a.x + b.x;
  1193. this.y = a.y + b.y;
  1194. return this;
  1195. };
  1196. _proto.addScaledVector = function addScaledVector(v, s) {
  1197. this.x += v.x * s;
  1198. this.y += v.y * s;
  1199. return this;
  1200. };
  1201. _proto.sub = function sub(v, w) {
  1202. if (w !== undefined) {
  1203. console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  1204. return this.subVectors(v, w);
  1205. }
  1206. this.x -= v.x;
  1207. this.y -= v.y;
  1208. return this;
  1209. };
  1210. _proto.subScalar = function subScalar(s) {
  1211. this.x -= s;
  1212. this.y -= s;
  1213. return this;
  1214. };
  1215. _proto.subVectors = function subVectors(a, b) {
  1216. this.x = a.x - b.x;
  1217. this.y = a.y - b.y;
  1218. return this;
  1219. };
  1220. _proto.multiply = function multiply(v) {
  1221. this.x *= v.x;
  1222. this.y *= v.y;
  1223. return this;
  1224. };
  1225. _proto.multiplyScalar = function multiplyScalar(scalar) {
  1226. this.x *= scalar;
  1227. this.y *= scalar;
  1228. return this;
  1229. };
  1230. _proto.divide = function divide(v) {
  1231. this.x /= v.x;
  1232. this.y /= v.y;
  1233. return this;
  1234. };
  1235. _proto.divideScalar = function divideScalar(scalar) {
  1236. return this.multiplyScalar(1 / scalar);
  1237. };
  1238. _proto.applyMatrix3 = function applyMatrix3(m) {
  1239. var x = this.x,
  1240. y = this.y;
  1241. var e = m.elements;
  1242. this.x = e[0] * x + e[3] * y + e[6];
  1243. this.y = e[1] * x + e[4] * y + e[7];
  1244. return this;
  1245. };
  1246. _proto.min = function min(v) {
  1247. this.x = Math.min(this.x, v.x);
  1248. this.y = Math.min(this.y, v.y);
  1249. return this;
  1250. };
  1251. _proto.max = function max(v) {
  1252. this.x = Math.max(this.x, v.x);
  1253. this.y = Math.max(this.y, v.y);
  1254. return this;
  1255. };
  1256. _proto.clamp = function clamp(min, max) {
  1257. // assumes min < max, componentwise
  1258. this.x = Math.max(min.x, Math.min(max.x, this.x));
  1259. this.y = Math.max(min.y, Math.min(max.y, this.y));
  1260. return this;
  1261. };
  1262. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  1263. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  1264. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  1265. return this;
  1266. };
  1267. _proto.clampLength = function clampLength(min, max) {
  1268. var length = this.length();
  1269. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  1270. };
  1271. _proto.floor = function floor() {
  1272. this.x = Math.floor(this.x);
  1273. this.y = Math.floor(this.y);
  1274. return this;
  1275. };
  1276. _proto.ceil = function ceil() {
  1277. this.x = Math.ceil(this.x);
  1278. this.y = Math.ceil(this.y);
  1279. return this;
  1280. };
  1281. _proto.round = function round() {
  1282. this.x = Math.round(this.x);
  1283. this.y = Math.round(this.y);
  1284. return this;
  1285. };
  1286. _proto.roundToZero = function roundToZero() {
  1287. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  1288. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  1289. return this;
  1290. };
  1291. _proto.negate = function negate() {
  1292. this.x = -this.x;
  1293. this.y = -this.y;
  1294. return this;
  1295. };
  1296. _proto.dot = function dot(v) {
  1297. return this.x * v.x + this.y * v.y;
  1298. };
  1299. _proto.cross = function cross(v) {
  1300. return this.x * v.y - this.y * v.x;
  1301. };
  1302. _proto.lengthSq = function lengthSq() {
  1303. return this.x * this.x + this.y * this.y;
  1304. };
  1305. _proto.length = function length() {
  1306. return Math.sqrt(this.x * this.x + this.y * this.y);
  1307. };
  1308. _proto.manhattanLength = function manhattanLength() {
  1309. return Math.abs(this.x) + Math.abs(this.y);
  1310. };
  1311. _proto.normalize = function normalize() {
  1312. return this.divideScalar(this.length() || 1);
  1313. };
  1314. _proto.angle = function angle() {
  1315. // computes the angle in radians with respect to the positive x-axis
  1316. var angle = Math.atan2(-this.y, -this.x) + Math.PI;
  1317. return angle;
  1318. };
  1319. _proto.distanceTo = function distanceTo(v) {
  1320. return Math.sqrt(this.distanceToSquared(v));
  1321. };
  1322. _proto.distanceToSquared = function distanceToSquared(v) {
  1323. var dx = this.x - v.x,
  1324. dy = this.y - v.y;
  1325. return dx * dx + dy * dy;
  1326. };
  1327. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  1328. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y);
  1329. };
  1330. _proto.setLength = function setLength(length) {
  1331. return this.normalize().multiplyScalar(length);
  1332. };
  1333. _proto.lerp = function lerp(v, alpha) {
  1334. this.x += (v.x - this.x) * alpha;
  1335. this.y += (v.y - this.y) * alpha;
  1336. return this;
  1337. };
  1338. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  1339. this.x = v1.x + (v2.x - v1.x) * alpha;
  1340. this.y = v1.y + (v2.y - v1.y) * alpha;
  1341. return this;
  1342. };
  1343. _proto.equals = function equals(v) {
  1344. return v.x === this.x && v.y === this.y;
  1345. };
  1346. _proto.fromArray = function fromArray(array, offset) {
  1347. if (offset === void 0) {
  1348. offset = 0;
  1349. }
  1350. this.x = array[offset];
  1351. this.y = array[offset + 1];
  1352. return this;
  1353. };
  1354. _proto.toArray = function toArray(array, offset) {
  1355. if (array === void 0) {
  1356. array = [];
  1357. }
  1358. if (offset === void 0) {
  1359. offset = 0;
  1360. }
  1361. array[offset] = this.x;
  1362. array[offset + 1] = this.y;
  1363. return array;
  1364. };
  1365. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  1366. if (offset !== undefined) {
  1367. console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');
  1368. }
  1369. this.x = attribute.getX(index);
  1370. this.y = attribute.getY(index);
  1371. return this;
  1372. };
  1373. _proto.rotateAround = function rotateAround(center, angle) {
  1374. var c = Math.cos(angle),
  1375. s = Math.sin(angle);
  1376. var x = this.x - center.x;
  1377. var y = this.y - center.y;
  1378. this.x = x * c - y * s + center.x;
  1379. this.y = x * s + y * c + center.y;
  1380. return this;
  1381. };
  1382. _proto.random = function random() {
  1383. this.x = Math.random();
  1384. this.y = Math.random();
  1385. return this;
  1386. };
  1387. _createClass(Vector2, [{
  1388. key: "width",
  1389. get: function get() {
  1390. return this.x;
  1391. },
  1392. set: function set(value) {
  1393. this.x = value;
  1394. }
  1395. }, {
  1396. key: "height",
  1397. get: function get() {
  1398. return this.y;
  1399. },
  1400. set: function set(value) {
  1401. this.y = value;
  1402. }
  1403. }]);
  1404. return Vector2;
  1405. }();
  1406. var Matrix3 = /*#__PURE__*/function () {
  1407. function Matrix3() {
  1408. Object.defineProperty(this, 'isMatrix3', {
  1409. value: true
  1410. });
  1411. this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  1412. if (arguments.length > 0) {
  1413. console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');
  1414. }
  1415. }
  1416. var _proto = Matrix3.prototype;
  1417. _proto.set = function set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
  1418. var te = this.elements;
  1419. te[0] = n11;
  1420. te[1] = n21;
  1421. te[2] = n31;
  1422. te[3] = n12;
  1423. te[4] = n22;
  1424. te[5] = n32;
  1425. te[6] = n13;
  1426. te[7] = n23;
  1427. te[8] = n33;
  1428. return this;
  1429. };
  1430. _proto.identity = function identity() {
  1431. this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);
  1432. return this;
  1433. };
  1434. _proto.clone = function clone() {
  1435. return new this.constructor().fromArray(this.elements);
  1436. };
  1437. _proto.copy = function copy(m) {
  1438. var te = this.elements;
  1439. var me = m.elements;
  1440. te[0] = me[0];
  1441. te[1] = me[1];
  1442. te[2] = me[2];
  1443. te[3] = me[3];
  1444. te[4] = me[4];
  1445. te[5] = me[5];
  1446. te[6] = me[6];
  1447. te[7] = me[7];
  1448. te[8] = me[8];
  1449. return this;
  1450. };
  1451. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  1452. xAxis.setFromMatrix3Column(this, 0);
  1453. yAxis.setFromMatrix3Column(this, 1);
  1454. zAxis.setFromMatrix3Column(this, 2);
  1455. return this;
  1456. };
  1457. _proto.setFromMatrix4 = function setFromMatrix4(m) {
  1458. var me = m.elements;
  1459. this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
  1460. return this;
  1461. };
  1462. _proto.multiply = function multiply(m) {
  1463. return this.multiplyMatrices(this, m);
  1464. };
  1465. _proto.premultiply = function premultiply(m) {
  1466. return this.multiplyMatrices(m, this);
  1467. };
  1468. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  1469. var ae = a.elements;
  1470. var be = b.elements;
  1471. var te = this.elements;
  1472. var a11 = ae[0],
  1473. a12 = ae[3],
  1474. a13 = ae[6];
  1475. var a21 = ae[1],
  1476. a22 = ae[4],
  1477. a23 = ae[7];
  1478. var a31 = ae[2],
  1479. a32 = ae[5],
  1480. a33 = ae[8];
  1481. var b11 = be[0],
  1482. b12 = be[3],
  1483. b13 = be[6];
  1484. var b21 = be[1],
  1485. b22 = be[4],
  1486. b23 = be[7];
  1487. var b31 = be[2],
  1488. b32 = be[5],
  1489. b33 = be[8];
  1490. te[0] = a11 * b11 + a12 * b21 + a13 * b31;
  1491. te[3] = a11 * b12 + a12 * b22 + a13 * b32;
  1492. te[6] = a11 * b13 + a12 * b23 + a13 * b33;
  1493. te[1] = a21 * b11 + a22 * b21 + a23 * b31;
  1494. te[4] = a21 * b12 + a22 * b22 + a23 * b32;
  1495. te[7] = a21 * b13 + a22 * b23 + a23 * b33;
  1496. te[2] = a31 * b11 + a32 * b21 + a33 * b31;
  1497. te[5] = a31 * b12 + a32 * b22 + a33 * b32;
  1498. te[8] = a31 * b13 + a32 * b23 + a33 * b33;
  1499. return this;
  1500. };
  1501. _proto.multiplyScalar = function multiplyScalar(s) {
  1502. var te = this.elements;
  1503. te[0] *= s;
  1504. te[3] *= s;
  1505. te[6] *= s;
  1506. te[1] *= s;
  1507. te[4] *= s;
  1508. te[7] *= s;
  1509. te[2] *= s;
  1510. te[5] *= s;
  1511. te[8] *= s;
  1512. return this;
  1513. };
  1514. _proto.determinant = function determinant() {
  1515. var te = this.elements;
  1516. var a = te[0],
  1517. b = te[1],
  1518. c = te[2],
  1519. d = te[3],
  1520. e = te[4],
  1521. f = te[5],
  1522. g = te[6],
  1523. h = te[7],
  1524. i = te[8];
  1525. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1526. };
  1527. _proto.invert = function invert() {
  1528. var te = this.elements,
  1529. n11 = te[0],
  1530. n21 = te[1],
  1531. n31 = te[2],
  1532. n12 = te[3],
  1533. n22 = te[4],
  1534. n32 = te[5],
  1535. n13 = te[6],
  1536. n23 = te[7],
  1537. n33 = te[8],
  1538. t11 = n33 * n22 - n32 * n23,
  1539. t12 = n32 * n13 - n33 * n12,
  1540. t13 = n23 * n12 - n22 * n13,
  1541. det = n11 * t11 + n21 * t12 + n31 * t13;
  1542. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0);
  1543. var detInv = 1 / det;
  1544. te[0] = t11 * detInv;
  1545. te[1] = (n31 * n23 - n33 * n21) * detInv;
  1546. te[2] = (n32 * n21 - n31 * n22) * detInv;
  1547. te[3] = t12 * detInv;
  1548. te[4] = (n33 * n11 - n31 * n13) * detInv;
  1549. te[5] = (n31 * n12 - n32 * n11) * detInv;
  1550. te[6] = t13 * detInv;
  1551. te[7] = (n21 * n13 - n23 * n11) * detInv;
  1552. te[8] = (n22 * n11 - n21 * n12) * detInv;
  1553. return this;
  1554. };
  1555. _proto.transpose = function transpose() {
  1556. var tmp;
  1557. var m = this.elements;
  1558. tmp = m[1];
  1559. m[1] = m[3];
  1560. m[3] = tmp;
  1561. tmp = m[2];
  1562. m[2] = m[6];
  1563. m[6] = tmp;
  1564. tmp = m[5];
  1565. m[5] = m[7];
  1566. m[7] = tmp;
  1567. return this;
  1568. };
  1569. _proto.getNormalMatrix = function getNormalMatrix(matrix4) {
  1570. return this.setFromMatrix4(matrix4).copy(this).invert().transpose();
  1571. };
  1572. _proto.transposeIntoArray = function transposeIntoArray(r) {
  1573. var m = this.elements;
  1574. r[0] = m[0];
  1575. r[1] = m[3];
  1576. r[2] = m[6];
  1577. r[3] = m[1];
  1578. r[4] = m[4];
  1579. r[5] = m[7];
  1580. r[6] = m[2];
  1581. r[7] = m[5];
  1582. r[8] = m[8];
  1583. return this;
  1584. };
  1585. _proto.setUvTransform = function setUvTransform(tx, ty, sx, sy, rotation, cx, cy) {
  1586. var c = Math.cos(rotation);
  1587. var s = Math.sin(rotation);
  1588. 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);
  1589. return this;
  1590. };
  1591. _proto.scale = function scale(sx, sy) {
  1592. var te = this.elements;
  1593. te[0] *= sx;
  1594. te[3] *= sx;
  1595. te[6] *= sx;
  1596. te[1] *= sy;
  1597. te[4] *= sy;
  1598. te[7] *= sy;
  1599. return this;
  1600. };
  1601. _proto.rotate = function rotate(theta) {
  1602. var c = Math.cos(theta);
  1603. var s = Math.sin(theta);
  1604. var te = this.elements;
  1605. var a11 = te[0],
  1606. a12 = te[3],
  1607. a13 = te[6];
  1608. var a21 = te[1],
  1609. a22 = te[4],
  1610. a23 = te[7];
  1611. te[0] = c * a11 + s * a21;
  1612. te[3] = c * a12 + s * a22;
  1613. te[6] = c * a13 + s * a23;
  1614. te[1] = -s * a11 + c * a21;
  1615. te[4] = -s * a12 + c * a22;
  1616. te[7] = -s * a13 + c * a23;
  1617. return this;
  1618. };
  1619. _proto.translate = function translate(tx, ty) {
  1620. var te = this.elements;
  1621. te[0] += tx * te[2];
  1622. te[3] += tx * te[5];
  1623. te[6] += tx * te[8];
  1624. te[1] += ty * te[2];
  1625. te[4] += ty * te[5];
  1626. te[7] += ty * te[8];
  1627. return this;
  1628. };
  1629. _proto.equals = function equals(matrix) {
  1630. var te = this.elements;
  1631. var me = matrix.elements;
  1632. for (var i = 0; i < 9; i++) {
  1633. if (te[i] !== me[i]) return false;
  1634. }
  1635. return true;
  1636. };
  1637. _proto.fromArray = function fromArray(array, offset) {
  1638. if (offset === void 0) {
  1639. offset = 0;
  1640. }
  1641. for (var i = 0; i < 9; i++) {
  1642. this.elements[i] = array[i + offset];
  1643. }
  1644. return this;
  1645. };
  1646. _proto.toArray = function toArray(array, offset) {
  1647. if (array === void 0) {
  1648. array = [];
  1649. }
  1650. if (offset === void 0) {
  1651. offset = 0;
  1652. }
  1653. var te = this.elements;
  1654. array[offset] = te[0];
  1655. array[offset + 1] = te[1];
  1656. array[offset + 2] = te[2];
  1657. array[offset + 3] = te[3];
  1658. array[offset + 4] = te[4];
  1659. array[offset + 5] = te[5];
  1660. array[offset + 6] = te[6];
  1661. array[offset + 7] = te[7];
  1662. array[offset + 8] = te[8];
  1663. return array;
  1664. };
  1665. return Matrix3;
  1666. }();
  1667. var _canvas;
  1668. var ImageUtils = {
  1669. getDataURL: function getDataURL(image) {
  1670. if (/^data:/i.test(image.src)) {
  1671. return image.src;
  1672. }
  1673. if (typeof HTMLCanvasElement == 'undefined') {
  1674. return image.src;
  1675. }
  1676. var canvas;
  1677. if (image instanceof HTMLCanvasElement) {
  1678. canvas = image;
  1679. } else {
  1680. if (_canvas === undefined) _canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  1681. _canvas.width = image.width;
  1682. _canvas.height = image.height;
  1683. var context = _canvas.getContext('2d');
  1684. if (image instanceof ImageData) {
  1685. context.putImageData(image, 0, 0);
  1686. } else {
  1687. context.drawImage(image, 0, 0, image.width, image.height);
  1688. }
  1689. canvas = _canvas;
  1690. }
  1691. if (canvas.width > 2048 || canvas.height > 2048) {
  1692. return canvas.toDataURL('image/jpeg', 0.6);
  1693. } else {
  1694. return canvas.toDataURL('image/png');
  1695. }
  1696. }
  1697. };
  1698. var textureId = 0;
  1699. function Texture(image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  1700. if (image === void 0) {
  1701. image = Texture.DEFAULT_IMAGE;
  1702. }
  1703. if (mapping === void 0) {
  1704. mapping = Texture.DEFAULT_MAPPING;
  1705. }
  1706. if (wrapS === void 0) {
  1707. wrapS = ClampToEdgeWrapping;
  1708. }
  1709. if (wrapT === void 0) {
  1710. wrapT = ClampToEdgeWrapping;
  1711. }
  1712. if (magFilter === void 0) {
  1713. magFilter = LinearFilter;
  1714. }
  1715. if (minFilter === void 0) {
  1716. minFilter = LinearMipmapLinearFilter;
  1717. }
  1718. if (format === void 0) {
  1719. format = RGBAFormat;
  1720. }
  1721. if (type === void 0) {
  1722. type = UnsignedByteType;
  1723. }
  1724. if (anisotropy === void 0) {
  1725. anisotropy = 1;
  1726. }
  1727. if (encoding === void 0) {
  1728. encoding = LinearEncoding;
  1729. }
  1730. Object.defineProperty(this, 'id', {
  1731. value: textureId++
  1732. });
  1733. this.uuid = MathUtils.generateUUID();
  1734. this.name = '';
  1735. this.image = image;
  1736. this.mipmaps = [];
  1737. this.mapping = mapping;
  1738. this.wrapS = wrapS;
  1739. this.wrapT = wrapT;
  1740. this.magFilter = magFilter;
  1741. this.minFilter = minFilter;
  1742. this.anisotropy = anisotropy;
  1743. this.format = format;
  1744. this.internalFormat = null;
  1745. this.type = type;
  1746. this.offset = new Vector2(0, 0);
  1747. this.repeat = new Vector2(1, 1);
  1748. this.center = new Vector2(0, 0);
  1749. this.rotation = 0;
  1750. this.matrixAutoUpdate = true;
  1751. this.matrix = new Matrix3();
  1752. this.generateMipmaps = true;
  1753. this.premultiplyAlpha = false;
  1754. this.flipY = true;
  1755. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1756. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1757. //
  1758. // Also changing the encoding after already used by a Material will not automatically make the Material
  1759. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1760. this.encoding = encoding;
  1761. this.version = 0;
  1762. this.onUpdate = null;
  1763. }
  1764. Texture.DEFAULT_IMAGE = undefined;
  1765. Texture.DEFAULT_MAPPING = UVMapping;
  1766. Texture.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  1767. constructor: Texture,
  1768. isTexture: true,
  1769. updateMatrix: function updateMatrix() {
  1770. this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y);
  1771. },
  1772. clone: function clone() {
  1773. return new this.constructor().copy(this);
  1774. },
  1775. copy: function copy(source) {
  1776. this.name = source.name;
  1777. this.image = source.image;
  1778. this.mipmaps = source.mipmaps.slice(0);
  1779. this.mapping = source.mapping;
  1780. this.wrapS = source.wrapS;
  1781. this.wrapT = source.wrapT;
  1782. this.magFilter = source.magFilter;
  1783. this.minFilter = source.minFilter;
  1784. this.anisotropy = source.anisotropy;
  1785. this.format = source.format;
  1786. this.internalFormat = source.internalFormat;
  1787. this.type = source.type;
  1788. this.offset.copy(source.offset);
  1789. this.repeat.copy(source.repeat);
  1790. this.center.copy(source.center);
  1791. this.rotation = source.rotation;
  1792. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1793. this.matrix.copy(source.matrix);
  1794. this.generateMipmaps = source.generateMipmaps;
  1795. this.premultiplyAlpha = source.premultiplyAlpha;
  1796. this.flipY = source.flipY;
  1797. this.unpackAlignment = source.unpackAlignment;
  1798. this.encoding = source.encoding;
  1799. return this;
  1800. },
  1801. toJSON: function toJSON(meta) {
  1802. var isRootObject = meta === undefined || typeof meta === 'string';
  1803. if (!isRootObject && meta.textures[this.uuid] !== undefined) {
  1804. return meta.textures[this.uuid];
  1805. }
  1806. var output = {
  1807. metadata: {
  1808. version: 4.5,
  1809. type: 'Texture',
  1810. generator: 'Texture.toJSON'
  1811. },
  1812. uuid: this.uuid,
  1813. name: this.name,
  1814. mapping: this.mapping,
  1815. repeat: [this.repeat.x, this.repeat.y],
  1816. offset: [this.offset.x, this.offset.y],
  1817. center: [this.center.x, this.center.y],
  1818. rotation: this.rotation,
  1819. wrap: [this.wrapS, this.wrapT],
  1820. format: this.format,
  1821. type: this.type,
  1822. encoding: this.encoding,
  1823. minFilter: this.minFilter,
  1824. magFilter: this.magFilter,
  1825. anisotropy: this.anisotropy,
  1826. flipY: this.flipY,
  1827. premultiplyAlpha: this.premultiplyAlpha,
  1828. unpackAlignment: this.unpackAlignment
  1829. };
  1830. if (this.image !== undefined) {
  1831. // TODO: Move to THREE.Image
  1832. var image = this.image;
  1833. if (image.uuid === undefined) {
  1834. image.uuid = MathUtils.generateUUID(); // UGH
  1835. }
  1836. if (!isRootObject && meta.images[image.uuid] === undefined) {
  1837. var url;
  1838. if (Array.isArray(image)) {
  1839. // process array of images e.g. CubeTexture
  1840. url = [];
  1841. for (var i = 0, l = image.length; i < l; i++) {
  1842. // check cube texture with data textures
  1843. if (image[i].isDataTexture) {
  1844. url.push(serializeImage(image[i].image));
  1845. } else {
  1846. url.push(serializeImage(image[i]));
  1847. }
  1848. }
  1849. } else {
  1850. // process single image
  1851. url = serializeImage(image);
  1852. }
  1853. meta.images[image.uuid] = {
  1854. uuid: image.uuid,
  1855. url: url
  1856. };
  1857. }
  1858. output.image = image.uuid;
  1859. }
  1860. if (!isRootObject) {
  1861. meta.textures[this.uuid] = output;
  1862. }
  1863. return output;
  1864. },
  1865. dispose: function dispose() {
  1866. this.dispatchEvent({
  1867. type: 'dispose'
  1868. });
  1869. },
  1870. transformUv: function transformUv(uv) {
  1871. if (this.mapping !== UVMapping) return uv;
  1872. uv.applyMatrix3(this.matrix);
  1873. if (uv.x < 0 || uv.x > 1) {
  1874. switch (this.wrapS) {
  1875. case RepeatWrapping:
  1876. uv.x = uv.x - Math.floor(uv.x);
  1877. break;
  1878. case ClampToEdgeWrapping:
  1879. uv.x = uv.x < 0 ? 0 : 1;
  1880. break;
  1881. case MirroredRepeatWrapping:
  1882. if (Math.abs(Math.floor(uv.x) % 2) === 1) {
  1883. uv.x = Math.ceil(uv.x) - uv.x;
  1884. } else {
  1885. uv.x = uv.x - Math.floor(uv.x);
  1886. }
  1887. break;
  1888. }
  1889. }
  1890. if (uv.y < 0 || uv.y > 1) {
  1891. switch (this.wrapT) {
  1892. case RepeatWrapping:
  1893. uv.y = uv.y - Math.floor(uv.y);
  1894. break;
  1895. case ClampToEdgeWrapping:
  1896. uv.y = uv.y < 0 ? 0 : 1;
  1897. break;
  1898. case MirroredRepeatWrapping:
  1899. if (Math.abs(Math.floor(uv.y) % 2) === 1) {
  1900. uv.y = Math.ceil(uv.y) - uv.y;
  1901. } else {
  1902. uv.y = uv.y - Math.floor(uv.y);
  1903. }
  1904. break;
  1905. }
  1906. }
  1907. if (this.flipY) {
  1908. uv.y = 1 - uv.y;
  1909. }
  1910. return uv;
  1911. }
  1912. });
  1913. Object.defineProperty(Texture.prototype, 'needsUpdate', {
  1914. set: function set(value) {
  1915. if (value === true) this.version++;
  1916. }
  1917. });
  1918. function serializeImage(image) {
  1919. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  1920. // default images
  1921. return ImageUtils.getDataURL(image);
  1922. } else {
  1923. if (image.data) {
  1924. // images of DataTexture
  1925. return {
  1926. data: Array.prototype.slice.call(image.data),
  1927. width: image.width,
  1928. height: image.height,
  1929. type: image.data.constructor.name
  1930. };
  1931. } else {
  1932. console.warn('THREE.Texture: Unable to serialize Texture.');
  1933. return {};
  1934. }
  1935. }
  1936. }
  1937. var Vector4 = /*#__PURE__*/function () {
  1938. function Vector4(x, y, z, w) {
  1939. if (x === void 0) {
  1940. x = 0;
  1941. }
  1942. if (y === void 0) {
  1943. y = 0;
  1944. }
  1945. if (z === void 0) {
  1946. z = 0;
  1947. }
  1948. if (w === void 0) {
  1949. w = 1;
  1950. }
  1951. Object.defineProperty(this, 'isVector4', {
  1952. value: true
  1953. });
  1954. this.x = x;
  1955. this.y = y;
  1956. this.z = z;
  1957. this.w = w;
  1958. }
  1959. var _proto = Vector4.prototype;
  1960. _proto.set = function set(x, y, z, w) {
  1961. this.x = x;
  1962. this.y = y;
  1963. this.z = z;
  1964. this.w = w;
  1965. return this;
  1966. };
  1967. _proto.setScalar = function setScalar(scalar) {
  1968. this.x = scalar;
  1969. this.y = scalar;
  1970. this.z = scalar;
  1971. this.w = scalar;
  1972. return this;
  1973. };
  1974. _proto.setX = function setX(x) {
  1975. this.x = x;
  1976. return this;
  1977. };
  1978. _proto.setY = function setY(y) {
  1979. this.y = y;
  1980. return this;
  1981. };
  1982. _proto.setZ = function setZ(z) {
  1983. this.z = z;
  1984. return this;
  1985. };
  1986. _proto.setW = function setW(w) {
  1987. this.w = w;
  1988. return this;
  1989. };
  1990. _proto.setComponent = function setComponent(index, value) {
  1991. switch (index) {
  1992. case 0:
  1993. this.x = value;
  1994. break;
  1995. case 1:
  1996. this.y = value;
  1997. break;
  1998. case 2:
  1999. this.z = value;
  2000. break;
  2001. case 3:
  2002. this.w = value;
  2003. break;
  2004. default:
  2005. throw new Error('index is out of range: ' + index);
  2006. }
  2007. return this;
  2008. };
  2009. _proto.getComponent = function getComponent(index) {
  2010. switch (index) {
  2011. case 0:
  2012. return this.x;
  2013. case 1:
  2014. return this.y;
  2015. case 2:
  2016. return this.z;
  2017. case 3:
  2018. return this.w;
  2019. default:
  2020. throw new Error('index is out of range: ' + index);
  2021. }
  2022. };
  2023. _proto.clone = function clone() {
  2024. return new this.constructor(this.x, this.y, this.z, this.w);
  2025. };
  2026. _proto.copy = function copy(v) {
  2027. this.x = v.x;
  2028. this.y = v.y;
  2029. this.z = v.z;
  2030. this.w = v.w !== undefined ? v.w : 1;
  2031. return this;
  2032. };
  2033. _proto.add = function add(v, w) {
  2034. if (w !== undefined) {
  2035. console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2036. return this.addVectors(v, w);
  2037. }
  2038. this.x += v.x;
  2039. this.y += v.y;
  2040. this.z += v.z;
  2041. this.w += v.w;
  2042. return this;
  2043. };
  2044. _proto.addScalar = function addScalar(s) {
  2045. this.x += s;
  2046. this.y += s;
  2047. this.z += s;
  2048. this.w += s;
  2049. return this;
  2050. };
  2051. _proto.addVectors = function addVectors(a, b) {
  2052. this.x = a.x + b.x;
  2053. this.y = a.y + b.y;
  2054. this.z = a.z + b.z;
  2055. this.w = a.w + b.w;
  2056. return this;
  2057. };
  2058. _proto.addScaledVector = function addScaledVector(v, s) {
  2059. this.x += v.x * s;
  2060. this.y += v.y * s;
  2061. this.z += v.z * s;
  2062. this.w += v.w * s;
  2063. return this;
  2064. };
  2065. _proto.sub = function sub(v, w) {
  2066. if (w !== undefined) {
  2067. console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  2068. return this.subVectors(v, w);
  2069. }
  2070. this.x -= v.x;
  2071. this.y -= v.y;
  2072. this.z -= v.z;
  2073. this.w -= v.w;
  2074. return this;
  2075. };
  2076. _proto.subScalar = function subScalar(s) {
  2077. this.x -= s;
  2078. this.y -= s;
  2079. this.z -= s;
  2080. this.w -= s;
  2081. return this;
  2082. };
  2083. _proto.subVectors = function subVectors(a, b) {
  2084. this.x = a.x - b.x;
  2085. this.y = a.y - b.y;
  2086. this.z = a.z - b.z;
  2087. this.w = a.w - b.w;
  2088. return this;
  2089. };
  2090. _proto.multiply = function multiply(v) {
  2091. this.x *= v.x;
  2092. this.y *= v.y;
  2093. this.z *= v.z;
  2094. this.w *= v.w;
  2095. return this;
  2096. };
  2097. _proto.multiplyScalar = function multiplyScalar(scalar) {
  2098. this.x *= scalar;
  2099. this.y *= scalar;
  2100. this.z *= scalar;
  2101. this.w *= scalar;
  2102. return this;
  2103. };
  2104. _proto.applyMatrix4 = function applyMatrix4(m) {
  2105. var x = this.x,
  2106. y = this.y,
  2107. z = this.z,
  2108. w = this.w;
  2109. var e = m.elements;
  2110. this.x = e[0] * x + e[4] * y + e[8] * z + e[12] * w;
  2111. this.y = e[1] * x + e[5] * y + e[9] * z + e[13] * w;
  2112. this.z = e[2] * x + e[6] * y + e[10] * z + e[14] * w;
  2113. this.w = e[3] * x + e[7] * y + e[11] * z + e[15] * w;
  2114. return this;
  2115. };
  2116. _proto.divideScalar = function divideScalar(scalar) {
  2117. return this.multiplyScalar(1 / scalar);
  2118. };
  2119. _proto.setAxisAngleFromQuaternion = function setAxisAngleFromQuaternion(q) {
  2120. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2121. // q is assumed to be normalized
  2122. this.w = 2 * Math.acos(q.w);
  2123. var s = Math.sqrt(1 - q.w * q.w);
  2124. if (s < 0.0001) {
  2125. this.x = 1;
  2126. this.y = 0;
  2127. this.z = 0;
  2128. } else {
  2129. this.x = q.x / s;
  2130. this.y = q.y / s;
  2131. this.z = q.z / s;
  2132. }
  2133. return this;
  2134. };
  2135. _proto.setAxisAngleFromRotationMatrix = function setAxisAngleFromRotationMatrix(m) {
  2136. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2137. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2138. var angle, x, y, z; // variables for result
  2139. var epsilon = 0.01,
  2140. // margin to allow for rounding errors
  2141. epsilon2 = 0.1,
  2142. // margin to distinguish between 0 and 180 degrees
  2143. te = m.elements,
  2144. m11 = te[0],
  2145. m12 = te[4],
  2146. m13 = te[8],
  2147. m21 = te[1],
  2148. m22 = te[5],
  2149. m23 = te[9],
  2150. m31 = te[2],
  2151. m32 = te[6],
  2152. m33 = te[10];
  2153. if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) {
  2154. // singularity found
  2155. // first check for identity matrix which must have +1 for all terms
  2156. // in leading diagonal and zero in other terms
  2157. if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) {
  2158. // this singularity is identity matrix so angle = 0
  2159. this.set(1, 0, 0, 0);
  2160. return this; // zero angle, arbitrary axis
  2161. } // otherwise this singularity is angle = 180
  2162. angle = Math.PI;
  2163. var xx = (m11 + 1) / 2;
  2164. var yy = (m22 + 1) / 2;
  2165. var zz = (m33 + 1) / 2;
  2166. var xy = (m12 + m21) / 4;
  2167. var xz = (m13 + m31) / 4;
  2168. var yz = (m23 + m32) / 4;
  2169. if (xx > yy && xx > zz) {
  2170. // m11 is the largest diagonal term
  2171. if (xx < epsilon) {
  2172. x = 0;
  2173. y = 0.707106781;
  2174. z = 0.707106781;
  2175. } else {
  2176. x = Math.sqrt(xx);
  2177. y = xy / x;
  2178. z = xz / x;
  2179. }
  2180. } else if (yy > zz) {
  2181. // m22 is the largest diagonal term
  2182. if (yy < epsilon) {
  2183. x = 0.707106781;
  2184. y = 0;
  2185. z = 0.707106781;
  2186. } else {
  2187. y = Math.sqrt(yy);
  2188. x = xy / y;
  2189. z = yz / y;
  2190. }
  2191. } else {
  2192. // m33 is the largest diagonal term so base result on this
  2193. if (zz < epsilon) {
  2194. x = 0.707106781;
  2195. y = 0.707106781;
  2196. z = 0;
  2197. } else {
  2198. z = Math.sqrt(zz);
  2199. x = xz / z;
  2200. y = yz / z;
  2201. }
  2202. }
  2203. this.set(x, y, z, angle);
  2204. return this; // return 180 deg rotation
  2205. } // as we have reached here there are no singularities so we can handle normally
  2206. var s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); // used to normalize
  2207. if (Math.abs(s) < 0.001) s = 1; // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2208. // caught by singularity test above, but I've left it in just in case
  2209. this.x = (m32 - m23) / s;
  2210. this.y = (m13 - m31) / s;
  2211. this.z = (m21 - m12) / s;
  2212. this.w = Math.acos((m11 + m22 + m33 - 1) / 2);
  2213. return this;
  2214. };
  2215. _proto.min = function min(v) {
  2216. this.x = Math.min(this.x, v.x);
  2217. this.y = Math.min(this.y, v.y);
  2218. this.z = Math.min(this.z, v.z);
  2219. this.w = Math.min(this.w, v.w);
  2220. return this;
  2221. };
  2222. _proto.max = function max(v) {
  2223. this.x = Math.max(this.x, v.x);
  2224. this.y = Math.max(this.y, v.y);
  2225. this.z = Math.max(this.z, v.z);
  2226. this.w = Math.max(this.w, v.w);
  2227. return this;
  2228. };
  2229. _proto.clamp = function clamp(min, max) {
  2230. // assumes min < max, componentwise
  2231. this.x = Math.max(min.x, Math.min(max.x, this.x));
  2232. this.y = Math.max(min.y, Math.min(max.y, this.y));
  2233. this.z = Math.max(min.z, Math.min(max.z, this.z));
  2234. this.w = Math.max(min.w, Math.min(max.w, this.w));
  2235. return this;
  2236. };
  2237. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  2238. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  2239. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  2240. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  2241. this.w = Math.max(minVal, Math.min(maxVal, this.w));
  2242. return this;
  2243. };
  2244. _proto.clampLength = function clampLength(min, max) {
  2245. var length = this.length();
  2246. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  2247. };
  2248. _proto.floor = function floor() {
  2249. this.x = Math.floor(this.x);
  2250. this.y = Math.floor(this.y);
  2251. this.z = Math.floor(this.z);
  2252. this.w = Math.floor(this.w);
  2253. return this;
  2254. };
  2255. _proto.ceil = function ceil() {
  2256. this.x = Math.ceil(this.x);
  2257. this.y = Math.ceil(this.y);
  2258. this.z = Math.ceil(this.z);
  2259. this.w = Math.ceil(this.w);
  2260. return this;
  2261. };
  2262. _proto.round = function round() {
  2263. this.x = Math.round(this.x);
  2264. this.y = Math.round(this.y);
  2265. this.z = Math.round(this.z);
  2266. this.w = Math.round(this.w);
  2267. return this;
  2268. };
  2269. _proto.roundToZero = function roundToZero() {
  2270. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  2271. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  2272. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  2273. this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(this.w);
  2274. return this;
  2275. };
  2276. _proto.negate = function negate() {
  2277. this.x = -this.x;
  2278. this.y = -this.y;
  2279. this.z = -this.z;
  2280. this.w = -this.w;
  2281. return this;
  2282. };
  2283. _proto.dot = function dot(v) {
  2284. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2285. };
  2286. _proto.lengthSq = function lengthSq() {
  2287. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2288. };
  2289. _proto.length = function length() {
  2290. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  2291. };
  2292. _proto.manhattanLength = function manhattanLength() {
  2293. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w);
  2294. };
  2295. _proto.normalize = function normalize() {
  2296. return this.divideScalar(this.length() || 1);
  2297. };
  2298. _proto.setLength = function setLength(length) {
  2299. return this.normalize().multiplyScalar(length);
  2300. };
  2301. _proto.lerp = function lerp(v, alpha) {
  2302. this.x += (v.x - this.x) * alpha;
  2303. this.y += (v.y - this.y) * alpha;
  2304. this.z += (v.z - this.z) * alpha;
  2305. this.w += (v.w - this.w) * alpha;
  2306. return this;
  2307. };
  2308. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  2309. this.x = v1.x + (v2.x - v1.x) * alpha;
  2310. this.y = v1.y + (v2.y - v1.y) * alpha;
  2311. this.z = v1.z + (v2.z - v1.z) * alpha;
  2312. this.w = v1.w + (v2.w - v1.w) * alpha;
  2313. return this;
  2314. };
  2315. _proto.equals = function equals(v) {
  2316. return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w;
  2317. };
  2318. _proto.fromArray = function fromArray(array, offset) {
  2319. if (offset === void 0) {
  2320. offset = 0;
  2321. }
  2322. this.x = array[offset];
  2323. this.y = array[offset + 1];
  2324. this.z = array[offset + 2];
  2325. this.w = array[offset + 3];
  2326. return this;
  2327. };
  2328. _proto.toArray = function toArray(array, offset) {
  2329. if (array === void 0) {
  2330. array = [];
  2331. }
  2332. if (offset === void 0) {
  2333. offset = 0;
  2334. }
  2335. array[offset] = this.x;
  2336. array[offset + 1] = this.y;
  2337. array[offset + 2] = this.z;
  2338. array[offset + 3] = this.w;
  2339. return array;
  2340. };
  2341. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  2342. if (offset !== undefined) {
  2343. console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');
  2344. }
  2345. this.x = attribute.getX(index);
  2346. this.y = attribute.getY(index);
  2347. this.z = attribute.getZ(index);
  2348. this.w = attribute.getW(index);
  2349. return this;
  2350. };
  2351. _proto.random = function random() {
  2352. this.x = Math.random();
  2353. this.y = Math.random();
  2354. this.z = Math.random();
  2355. this.w = Math.random();
  2356. return this;
  2357. };
  2358. _createClass(Vector4, [{
  2359. key: "width",
  2360. get: function get() {
  2361. return this.z;
  2362. },
  2363. set: function set(value) {
  2364. this.z = value;
  2365. }
  2366. }, {
  2367. key: "height",
  2368. get: function get() {
  2369. return this.w;
  2370. },
  2371. set: function set(value) {
  2372. this.w = value;
  2373. }
  2374. }]);
  2375. return Vector4;
  2376. }();
  2377. /*
  2378. In options, we can specify:
  2379. * Texture parameters for an auto-generated target texture
  2380. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2381. */
  2382. var WebGLRenderTarget = /*#__PURE__*/function (_EventDispatcher) {
  2383. _inheritsLoose(WebGLRenderTarget, _EventDispatcher);
  2384. function WebGLRenderTarget(width, height, options) {
  2385. var _this;
  2386. _this = _EventDispatcher.call(this) || this;
  2387. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLRenderTarget', {
  2388. value: true
  2389. });
  2390. _this.width = width;
  2391. _this.height = height;
  2392. _this.scissor = new Vector4(0, 0, width, height);
  2393. _this.scissorTest = false;
  2394. _this.viewport = new Vector4(0, 0, width, height);
  2395. options = options || {};
  2396. _this.texture = new Texture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  2397. _this.texture.image = {};
  2398. _this.texture.image.width = width;
  2399. _this.texture.image.height = height;
  2400. _this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2401. _this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2402. _this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2403. _this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  2404. _this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2405. return _this;
  2406. }
  2407. var _proto = WebGLRenderTarget.prototype;
  2408. _proto.setSize = function setSize(width, height) {
  2409. if (this.width !== width || this.height !== height) {
  2410. this.width = width;
  2411. this.height = height;
  2412. this.texture.image.width = width;
  2413. this.texture.image.height = height;
  2414. this.dispose();
  2415. }
  2416. this.viewport.set(0, 0, width, height);
  2417. this.scissor.set(0, 0, width, height);
  2418. };
  2419. _proto.clone = function clone() {
  2420. return new this.constructor().copy(this);
  2421. };
  2422. _proto.copy = function copy(source) {
  2423. this.width = source.width;
  2424. this.height = source.height;
  2425. this.viewport.copy(source.viewport);
  2426. this.texture = source.texture.clone();
  2427. this.depthBuffer = source.depthBuffer;
  2428. this.stencilBuffer = source.stencilBuffer;
  2429. this.depthTexture = source.depthTexture;
  2430. return this;
  2431. };
  2432. _proto.dispose = function dispose() {
  2433. this.dispatchEvent({
  2434. type: 'dispose'
  2435. });
  2436. };
  2437. return WebGLRenderTarget;
  2438. }(EventDispatcher);
  2439. var WebGLMultisampleRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  2440. _inheritsLoose(WebGLMultisampleRenderTarget, _WebGLRenderTarget);
  2441. function WebGLMultisampleRenderTarget(width, height, options) {
  2442. var _this;
  2443. _this = _WebGLRenderTarget.call(this, width, height, options) || this;
  2444. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLMultisampleRenderTarget', {
  2445. value: true
  2446. });
  2447. _this.samples = 4;
  2448. return _this;
  2449. }
  2450. var _proto = WebGLMultisampleRenderTarget.prototype;
  2451. _proto.copy = function copy(source) {
  2452. _WebGLRenderTarget.prototype.copy.call(this, source);
  2453. this.samples = source.samples;
  2454. return this;
  2455. };
  2456. return WebGLMultisampleRenderTarget;
  2457. }(WebGLRenderTarget);
  2458. var Quaternion = /*#__PURE__*/function () {
  2459. function Quaternion(x, y, z, w) {
  2460. if (x === void 0) {
  2461. x = 0;
  2462. }
  2463. if (y === void 0) {
  2464. y = 0;
  2465. }
  2466. if (z === void 0) {
  2467. z = 0;
  2468. }
  2469. if (w === void 0) {
  2470. w = 1;
  2471. }
  2472. Object.defineProperty(this, 'isQuaternion', {
  2473. value: true
  2474. });
  2475. this._x = x;
  2476. this._y = y;
  2477. this._z = z;
  2478. this._w = w;
  2479. }
  2480. Quaternion.slerp = function slerp(qa, qb, qm, t) {
  2481. return qm.copy(qa).slerp(qb, t);
  2482. };
  2483. Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
  2484. // fuzz-free, array-based Quaternion SLERP operation
  2485. var x0 = src0[srcOffset0 + 0],
  2486. y0 = src0[srcOffset0 + 1],
  2487. z0 = src0[srcOffset0 + 2],
  2488. w0 = src0[srcOffset0 + 3];
  2489. var x1 = src1[srcOffset1 + 0],
  2490. y1 = src1[srcOffset1 + 1],
  2491. z1 = src1[srcOffset1 + 2],
  2492. w1 = src1[srcOffset1 + 3];
  2493. if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
  2494. var s = 1 - t;
  2495. var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2496. dir = cos >= 0 ? 1 : -1,
  2497. sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
  2498. if (sqrSin > Number.EPSILON) {
  2499. var sin = Math.sqrt(sqrSin),
  2500. len = Math.atan2(sin, cos * dir);
  2501. s = Math.sin(s * len) / sin;
  2502. t = Math.sin(t * len) / sin;
  2503. }
  2504. var tDir = t * dir;
  2505. x0 = x0 * s + x1 * tDir;
  2506. y0 = y0 * s + y1 * tDir;
  2507. z0 = z0 * s + z1 * tDir;
  2508. w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
  2509. if (s === 1 - t) {
  2510. var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
  2511. x0 *= f;
  2512. y0 *= f;
  2513. z0 *= f;
  2514. w0 *= f;
  2515. }
  2516. }
  2517. dst[dstOffset] = x0;
  2518. dst[dstOffset + 1] = y0;
  2519. dst[dstOffset + 2] = z0;
  2520. dst[dstOffset + 3] = w0;
  2521. };
  2522. Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
  2523. var x0 = src0[srcOffset0];
  2524. var y0 = src0[srcOffset0 + 1];
  2525. var z0 = src0[srcOffset0 + 2];
  2526. var w0 = src0[srcOffset0 + 3];
  2527. var x1 = src1[srcOffset1];
  2528. var y1 = src1[srcOffset1 + 1];
  2529. var z1 = src1[srcOffset1 + 2];
  2530. var w1 = src1[srcOffset1 + 3];
  2531. dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2532. dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2533. dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2534. dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2535. return dst;
  2536. };
  2537. var _proto = Quaternion.prototype;
  2538. _proto.set = function set(x, y, z, w) {
  2539. this._x = x;
  2540. this._y = y;
  2541. this._z = z;
  2542. this._w = w;
  2543. this._onChangeCallback();
  2544. return this;
  2545. };
  2546. _proto.clone = function clone() {
  2547. return new this.constructor(this._x, this._y, this._z, this._w);
  2548. };
  2549. _proto.copy = function copy(quaternion) {
  2550. this._x = quaternion.x;
  2551. this._y = quaternion.y;
  2552. this._z = quaternion.z;
  2553. this._w = quaternion.w;
  2554. this._onChangeCallback();
  2555. return this;
  2556. };
  2557. _proto.setFromEuler = function setFromEuler(euler, update) {
  2558. if (!(euler && euler.isEuler)) {
  2559. throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');
  2560. }
  2561. var x = euler._x,
  2562. y = euler._y,
  2563. z = euler._z,
  2564. order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
  2565. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2566. // content/SpinCalc.m
  2567. var cos = Math.cos;
  2568. var sin = Math.sin;
  2569. var c1 = cos(x / 2);
  2570. var c2 = cos(y / 2);
  2571. var c3 = cos(z / 2);
  2572. var s1 = sin(x / 2);
  2573. var s2 = sin(y / 2);
  2574. var s3 = sin(z / 2);
  2575. switch (order) {
  2576. case 'XYZ':
  2577. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2578. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2579. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2580. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2581. break;
  2582. case 'YXZ':
  2583. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2584. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2585. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2586. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2587. break;
  2588. case 'ZXY':
  2589. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2590. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2591. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2592. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2593. break;
  2594. case 'ZYX':
  2595. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2596. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2597. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2598. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2599. break;
  2600. case 'YZX':
  2601. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2602. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2603. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2604. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2605. break;
  2606. case 'XZY':
  2607. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2608. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2609. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2610. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2611. break;
  2612. default:
  2613. console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
  2614. }
  2615. if (update !== false) this._onChangeCallback();
  2616. return this;
  2617. };
  2618. _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
  2619. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2620. // assumes axis is normalized
  2621. var halfAngle = angle / 2,
  2622. s = Math.sin(halfAngle);
  2623. this._x = axis.x * s;
  2624. this._y = axis.y * s;
  2625. this._z = axis.z * s;
  2626. this._w = Math.cos(halfAngle);
  2627. this._onChangeCallback();
  2628. return this;
  2629. };
  2630. _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
  2631. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2632. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2633. var te = m.elements,
  2634. m11 = te[0],
  2635. m12 = te[4],
  2636. m13 = te[8],
  2637. m21 = te[1],
  2638. m22 = te[5],
  2639. m23 = te[9],
  2640. m31 = te[2],
  2641. m32 = te[6],
  2642. m33 = te[10],
  2643. trace = m11 + m22 + m33;
  2644. if (trace > 0) {
  2645. var s = 0.5 / Math.sqrt(trace + 1.0);
  2646. this._w = 0.25 / s;
  2647. this._x = (m32 - m23) * s;
  2648. this._y = (m13 - m31) * s;
  2649. this._z = (m21 - m12) * s;
  2650. } else if (m11 > m22 && m11 > m33) {
  2651. var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
  2652. this._w = (m32 - m23) / _s;
  2653. this._x = 0.25 * _s;
  2654. this._y = (m12 + m21) / _s;
  2655. this._z = (m13 + m31) / _s;
  2656. } else if (m22 > m33) {
  2657. var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
  2658. this._w = (m13 - m31) / _s2;
  2659. this._x = (m12 + m21) / _s2;
  2660. this._y = 0.25 * _s2;
  2661. this._z = (m23 + m32) / _s2;
  2662. } else {
  2663. var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
  2664. this._w = (m21 - m12) / _s3;
  2665. this._x = (m13 + m31) / _s3;
  2666. this._y = (m23 + m32) / _s3;
  2667. this._z = 0.25 * _s3;
  2668. }
  2669. this._onChangeCallback();
  2670. return this;
  2671. };
  2672. _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
  2673. // assumes direction vectors vFrom and vTo are normalized
  2674. var EPS = 0.000001;
  2675. var r = vFrom.dot(vTo) + 1;
  2676. if (r < EPS) {
  2677. r = 0;
  2678. if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
  2679. this._x = -vFrom.y;
  2680. this._y = vFrom.x;
  2681. this._z = 0;
  2682. this._w = r;
  2683. } else {
  2684. this._x = 0;
  2685. this._y = -vFrom.z;
  2686. this._z = vFrom.y;
  2687. this._w = r;
  2688. }
  2689. } else {
  2690. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2691. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2692. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2693. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2694. this._w = r;
  2695. }
  2696. return this.normalize();
  2697. };
  2698. _proto.angleTo = function angleTo(q) {
  2699. return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), -1, 1)));
  2700. };
  2701. _proto.rotateTowards = function rotateTowards(q, step) {
  2702. var angle = this.angleTo(q);
  2703. if (angle === 0) return this;
  2704. var t = Math.min(1, step / angle);
  2705. this.slerp(q, t);
  2706. return this;
  2707. };
  2708. _proto.identity = function identity() {
  2709. return this.set(0, 0, 0, 1);
  2710. };
  2711. _proto.invert = function invert() {
  2712. // quaternion is assumed to have unit length
  2713. return this.conjugate();
  2714. };
  2715. _proto.conjugate = function conjugate() {
  2716. this._x *= -1;
  2717. this._y *= -1;
  2718. this._z *= -1;
  2719. this._onChangeCallback();
  2720. return this;
  2721. };
  2722. _proto.dot = function dot(v) {
  2723. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2724. };
  2725. _proto.lengthSq = function lengthSq() {
  2726. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2727. };
  2728. _proto.length = function length() {
  2729. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
  2730. };
  2731. _proto.normalize = function normalize() {
  2732. var l = this.length();
  2733. if (l === 0) {
  2734. this._x = 0;
  2735. this._y = 0;
  2736. this._z = 0;
  2737. this._w = 1;
  2738. } else {
  2739. l = 1 / l;
  2740. this._x = this._x * l;
  2741. this._y = this._y * l;
  2742. this._z = this._z * l;
  2743. this._w = this._w * l;
  2744. }
  2745. this._onChangeCallback();
  2746. return this;
  2747. };
  2748. _proto.multiply = function multiply(q, p) {
  2749. if (p !== undefined) {
  2750. console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');
  2751. return this.multiplyQuaternions(q, p);
  2752. }
  2753. return this.multiplyQuaternions(this, q);
  2754. };
  2755. _proto.premultiply = function premultiply(q) {
  2756. return this.multiplyQuaternions(q, this);
  2757. };
  2758. _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
  2759. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2760. var qax = a._x,
  2761. qay = a._y,
  2762. qaz = a._z,
  2763. qaw = a._w;
  2764. var qbx = b._x,
  2765. qby = b._y,
  2766. qbz = b._z,
  2767. qbw = b._w;
  2768. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2769. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2770. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2771. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2772. this._onChangeCallback();
  2773. return this;
  2774. };
  2775. _proto.slerp = function slerp(qb, t) {
  2776. if (t === 0) return this;
  2777. if (t === 1) return this.copy(qb);
  2778. var x = this._x,
  2779. y = this._y,
  2780. z = this._z,
  2781. w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2782. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2783. if (cosHalfTheta < 0) {
  2784. this._w = -qb._w;
  2785. this._x = -qb._x;
  2786. this._y = -qb._y;
  2787. this._z = -qb._z;
  2788. cosHalfTheta = -cosHalfTheta;
  2789. } else {
  2790. this.copy(qb);
  2791. }
  2792. if (cosHalfTheta >= 1.0) {
  2793. this._w = w;
  2794. this._x = x;
  2795. this._y = y;
  2796. this._z = z;
  2797. return this;
  2798. }
  2799. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2800. if (sqrSinHalfTheta <= Number.EPSILON) {
  2801. var s = 1 - t;
  2802. this._w = s * w + t * this._w;
  2803. this._x = s * x + t * this._x;
  2804. this._y = s * y + t * this._y;
  2805. this._z = s * z + t * this._z;
  2806. this.normalize();
  2807. this._onChangeCallback();
  2808. return this;
  2809. }
  2810. var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
  2811. var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
  2812. var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
  2813. ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
  2814. this._w = w * ratioA + this._w * ratioB;
  2815. this._x = x * ratioA + this._x * ratioB;
  2816. this._y = y * ratioA + this._y * ratioB;
  2817. this._z = z * ratioA + this._z * ratioB;
  2818. this._onChangeCallback();
  2819. return this;
  2820. };
  2821. _proto.equals = function equals(quaternion) {
  2822. return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
  2823. };
  2824. _proto.fromArray = function fromArray(array, offset) {
  2825. if (offset === void 0) {
  2826. offset = 0;
  2827. }
  2828. this._x = array[offset];
  2829. this._y = array[offset + 1];
  2830. this._z = array[offset + 2];
  2831. this._w = array[offset + 3];
  2832. this._onChangeCallback();
  2833. return this;
  2834. };
  2835. _proto.toArray = function toArray(array, offset) {
  2836. if (array === void 0) {
  2837. array = [];
  2838. }
  2839. if (offset === void 0) {
  2840. offset = 0;
  2841. }
  2842. array[offset] = this._x;
  2843. array[offset + 1] = this._y;
  2844. array[offset + 2] = this._z;
  2845. array[offset + 3] = this._w;
  2846. return array;
  2847. };
  2848. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  2849. this._x = attribute.getX(index);
  2850. this._y = attribute.getY(index);
  2851. this._z = attribute.getZ(index);
  2852. this._w = attribute.getW(index);
  2853. return this;
  2854. };
  2855. _proto._onChange = function _onChange(callback) {
  2856. this._onChangeCallback = callback;
  2857. return this;
  2858. };
  2859. _proto._onChangeCallback = function _onChangeCallback() {};
  2860. _createClass(Quaternion, [{
  2861. key: "x",
  2862. get: function get() {
  2863. return this._x;
  2864. },
  2865. set: function set(value) {
  2866. this._x = value;
  2867. this._onChangeCallback();
  2868. }
  2869. }, {
  2870. key: "y",
  2871. get: function get() {
  2872. return this._y;
  2873. },
  2874. set: function set(value) {
  2875. this._y = value;
  2876. this._onChangeCallback();
  2877. }
  2878. }, {
  2879. key: "z",
  2880. get: function get() {
  2881. return this._z;
  2882. },
  2883. set: function set(value) {
  2884. this._z = value;
  2885. this._onChangeCallback();
  2886. }
  2887. }, {
  2888. key: "w",
  2889. get: function get() {
  2890. return this._w;
  2891. },
  2892. set: function set(value) {
  2893. this._w = value;
  2894. this._onChangeCallback();
  2895. }
  2896. }]);
  2897. return Quaternion;
  2898. }();
  2899. var Vector3 = /*#__PURE__*/function () {
  2900. function Vector3(x, y, z) {
  2901. if (x === void 0) {
  2902. x = 0;
  2903. }
  2904. if (y === void 0) {
  2905. y = 0;
  2906. }
  2907. if (z === void 0) {
  2908. z = 0;
  2909. }
  2910. Object.defineProperty(this, 'isVector3', {
  2911. value: true
  2912. });
  2913. this.x = x;
  2914. this.y = y;
  2915. this.z = z;
  2916. }
  2917. var _proto = Vector3.prototype;
  2918. _proto.set = function set(x, y, z) {
  2919. if (z === undefined) z = this.z; // sprite.scale.set(x,y)
  2920. this.x = x;
  2921. this.y = y;
  2922. this.z = z;
  2923. return this;
  2924. };
  2925. _proto.setScalar = function setScalar(scalar) {
  2926. this.x = scalar;
  2927. this.y = scalar;
  2928. this.z = scalar;
  2929. return this;
  2930. };
  2931. _proto.setX = function setX(x) {
  2932. this.x = x;
  2933. return this;
  2934. };
  2935. _proto.setY = function setY(y) {
  2936. this.y = y;
  2937. return this;
  2938. };
  2939. _proto.setZ = function setZ(z) {
  2940. this.z = z;
  2941. return this;
  2942. };
  2943. _proto.setComponent = function setComponent(index, value) {
  2944. switch (index) {
  2945. case 0:
  2946. this.x = value;
  2947. break;
  2948. case 1:
  2949. this.y = value;
  2950. break;
  2951. case 2:
  2952. this.z = value;
  2953. break;
  2954. default:
  2955. throw new Error('index is out of range: ' + index);
  2956. }
  2957. return this;
  2958. };
  2959. _proto.getComponent = function getComponent(index) {
  2960. switch (index) {
  2961. case 0:
  2962. return this.x;
  2963. case 1:
  2964. return this.y;
  2965. case 2:
  2966. return this.z;
  2967. default:
  2968. throw new Error('index is out of range: ' + index);
  2969. }
  2970. };
  2971. _proto.clone = function clone() {
  2972. return new this.constructor(this.x, this.y, this.z);
  2973. };
  2974. _proto.copy = function copy(v) {
  2975. this.x = v.x;
  2976. this.y = v.y;
  2977. this.z = v.z;
  2978. return this;
  2979. };
  2980. _proto.add = function add(v, w) {
  2981. if (w !== undefined) {
  2982. console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');
  2983. return this.addVectors(v, w);
  2984. }
  2985. this.x += v.x;
  2986. this.y += v.y;
  2987. this.z += v.z;
  2988. return this;
  2989. };
  2990. _proto.addScalar = function addScalar(s) {
  2991. this.x += s;
  2992. this.y += s;
  2993. this.z += s;
  2994. return this;
  2995. };
  2996. _proto.addVectors = function addVectors(a, b) {
  2997. this.x = a.x + b.x;
  2998. this.y = a.y + b.y;
  2999. this.z = a.z + b.z;
  3000. return this;
  3001. };
  3002. _proto.addScaledVector = function addScaledVector(v, s) {
  3003. this.x += v.x * s;
  3004. this.y += v.y * s;
  3005. this.z += v.z * s;
  3006. return this;
  3007. };
  3008. _proto.sub = function sub(v, w) {
  3009. if (w !== undefined) {
  3010. console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');
  3011. return this.subVectors(v, w);
  3012. }
  3013. this.x -= v.x;
  3014. this.y -= v.y;
  3015. this.z -= v.z;
  3016. return this;
  3017. };
  3018. _proto.subScalar = function subScalar(s) {
  3019. this.x -= s;
  3020. this.y -= s;
  3021. this.z -= s;
  3022. return this;
  3023. };
  3024. _proto.subVectors = function subVectors(a, b) {
  3025. this.x = a.x - b.x;
  3026. this.y = a.y - b.y;
  3027. this.z = a.z - b.z;
  3028. return this;
  3029. };
  3030. _proto.multiply = function multiply(v, w) {
  3031. if (w !== undefined) {
  3032. console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');
  3033. return this.multiplyVectors(v, w);
  3034. }
  3035. this.x *= v.x;
  3036. this.y *= v.y;
  3037. this.z *= v.z;
  3038. return this;
  3039. };
  3040. _proto.multiplyScalar = function multiplyScalar(scalar) {
  3041. this.x *= scalar;
  3042. this.y *= scalar;
  3043. this.z *= scalar;
  3044. return this;
  3045. };
  3046. _proto.multiplyVectors = function multiplyVectors(a, b) {
  3047. this.x = a.x * b.x;
  3048. this.y = a.y * b.y;
  3049. this.z = a.z * b.z;
  3050. return this;
  3051. };
  3052. _proto.applyEuler = function applyEuler(euler) {
  3053. if (!(euler && euler.isEuler)) {
  3054. console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');
  3055. }
  3056. return this.applyQuaternion(_quaternion.setFromEuler(euler));
  3057. };
  3058. _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
  3059. return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
  3060. };
  3061. _proto.applyMatrix3 = function applyMatrix3(m) {
  3062. var x = this.x,
  3063. y = this.y,
  3064. z = this.z;
  3065. var e = m.elements;
  3066. this.x = e[0] * x + e[3] * y + e[6] * z;
  3067. this.y = e[1] * x + e[4] * y + e[7] * z;
  3068. this.z = e[2] * x + e[5] * y + e[8] * z;
  3069. return this;
  3070. };
  3071. _proto.applyNormalMatrix = function applyNormalMatrix(m) {
  3072. return this.applyMatrix3(m).normalize();
  3073. };
  3074. _proto.applyMatrix4 = function applyMatrix4(m) {
  3075. var x = this.x,
  3076. y = this.y,
  3077. z = this.z;
  3078. var e = m.elements;
  3079. var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
  3080. this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
  3081. this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
  3082. this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
  3083. return this;
  3084. };
  3085. _proto.applyQuaternion = function applyQuaternion(q) {
  3086. var x = this.x,
  3087. y = this.y,
  3088. z = this.z;
  3089. var qx = q.x,
  3090. qy = q.y,
  3091. qz = q.z,
  3092. qw = q.w; // calculate quat * vector
  3093. var ix = qw * x + qy * z - qz * y;
  3094. var iy = qw * y + qz * x - qx * z;
  3095. var iz = qw * z + qx * y - qy * x;
  3096. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  3097. this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  3098. this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  3099. this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  3100. return this;
  3101. };
  3102. _proto.project = function project(camera) {
  3103. return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
  3104. };
  3105. _proto.unproject = function unproject(camera) {
  3106. return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
  3107. };
  3108. _proto.transformDirection = function transformDirection(m) {
  3109. // input: THREE.Matrix4 affine matrix
  3110. // vector interpreted as a direction
  3111. var x = this.x,
  3112. y = this.y,
  3113. z = this.z;
  3114. var e = m.elements;
  3115. this.x = e[0] * x + e[4] * y + e[8] * z;
  3116. this.y = e[1] * x + e[5] * y + e[9] * z;
  3117. this.z = e[2] * x + e[6] * y + e[10] * z;
  3118. return this.normalize();
  3119. };
  3120. _proto.divide = function divide(v) {
  3121. this.x /= v.x;
  3122. this.y /= v.y;
  3123. this.z /= v.z;
  3124. return this;
  3125. };
  3126. _proto.divideScalar = function divideScalar(scalar) {
  3127. return this.multiplyScalar(1 / scalar);
  3128. };
  3129. _proto.min = function min(v) {
  3130. this.x = Math.min(this.x, v.x);
  3131. this.y = Math.min(this.y, v.y);
  3132. this.z = Math.min(this.z, v.z);
  3133. return this;
  3134. };
  3135. _proto.max = function max(v) {
  3136. this.x = Math.max(this.x, v.x);
  3137. this.y = Math.max(this.y, v.y);
  3138. this.z = Math.max(this.z, v.z);
  3139. return this;
  3140. };
  3141. _proto.clamp = function clamp(min, max) {
  3142. // assumes min < max, componentwise
  3143. this.x = Math.max(min.x, Math.min(max.x, this.x));
  3144. this.y = Math.max(min.y, Math.min(max.y, this.y));
  3145. this.z = Math.max(min.z, Math.min(max.z, this.z));
  3146. return this;
  3147. };
  3148. _proto.clampScalar = function clampScalar(minVal, maxVal) {
  3149. this.x = Math.max(minVal, Math.min(maxVal, this.x));
  3150. this.y = Math.max(minVal, Math.min(maxVal, this.y));
  3151. this.z = Math.max(minVal, Math.min(maxVal, this.z));
  3152. return this;
  3153. };
  3154. _proto.clampLength = function clampLength(min, max) {
  3155. var length = this.length();
  3156. return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
  3157. };
  3158. _proto.floor = function floor() {
  3159. this.x = Math.floor(this.x);
  3160. this.y = Math.floor(this.y);
  3161. this.z = Math.floor(this.z);
  3162. return this;
  3163. };
  3164. _proto.ceil = function ceil() {
  3165. this.x = Math.ceil(this.x);
  3166. this.y = Math.ceil(this.y);
  3167. this.z = Math.ceil(this.z);
  3168. return this;
  3169. };
  3170. _proto.round = function round() {
  3171. this.x = Math.round(this.x);
  3172. this.y = Math.round(this.y);
  3173. this.z = Math.round(this.z);
  3174. return this;
  3175. };
  3176. _proto.roundToZero = function roundToZero() {
  3177. this.x = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x);
  3178. this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y);
  3179. this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z);
  3180. return this;
  3181. };
  3182. _proto.negate = function negate() {
  3183. this.x = -this.x;
  3184. this.y = -this.y;
  3185. this.z = -this.z;
  3186. return this;
  3187. };
  3188. _proto.dot = function dot(v) {
  3189. return this.x * v.x + this.y * v.y + this.z * v.z;
  3190. } // TODO lengthSquared?
  3191. ;
  3192. _proto.lengthSq = function lengthSq() {
  3193. return this.x * this.x + this.y * this.y + this.z * this.z;
  3194. };
  3195. _proto.length = function length() {
  3196. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  3197. };
  3198. _proto.manhattanLength = function manhattanLength() {
  3199. return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
  3200. };
  3201. _proto.normalize = function normalize() {
  3202. return this.divideScalar(this.length() || 1);
  3203. };
  3204. _proto.setLength = function setLength(length) {
  3205. return this.normalize().multiplyScalar(length);
  3206. };
  3207. _proto.lerp = function lerp(v, alpha) {
  3208. this.x += (v.x - this.x) * alpha;
  3209. this.y += (v.y - this.y) * alpha;
  3210. this.z += (v.z - this.z) * alpha;
  3211. return this;
  3212. };
  3213. _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
  3214. this.x = v1.x + (v2.x - v1.x) * alpha;
  3215. this.y = v1.y + (v2.y - v1.y) * alpha;
  3216. this.z = v1.z + (v2.z - v1.z) * alpha;
  3217. return this;
  3218. };
  3219. _proto.cross = function cross(v, w) {
  3220. if (w !== undefined) {
  3221. console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');
  3222. return this.crossVectors(v, w);
  3223. }
  3224. return this.crossVectors(this, v);
  3225. };
  3226. _proto.crossVectors = function crossVectors(a, b) {
  3227. var ax = a.x,
  3228. ay = a.y,
  3229. az = a.z;
  3230. var bx = b.x,
  3231. by = b.y,
  3232. bz = b.z;
  3233. this.x = ay * bz - az * by;
  3234. this.y = az * bx - ax * bz;
  3235. this.z = ax * by - ay * bx;
  3236. return this;
  3237. };
  3238. _proto.projectOnVector = function projectOnVector(v) {
  3239. var denominator = v.lengthSq();
  3240. if (denominator === 0) return this.set(0, 0, 0);
  3241. var scalar = v.dot(this) / denominator;
  3242. return this.copy(v).multiplyScalar(scalar);
  3243. };
  3244. _proto.projectOnPlane = function projectOnPlane(planeNormal) {
  3245. _vector.copy(this).projectOnVector(planeNormal);
  3246. return this.sub(_vector);
  3247. };
  3248. _proto.reflect = function reflect(normal) {
  3249. // reflect incident vector off plane orthogonal to normal
  3250. // normal is assumed to have unit length
  3251. return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
  3252. };
  3253. _proto.angleTo = function angleTo(v) {
  3254. var denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
  3255. if (denominator === 0) return Math.PI / 2;
  3256. var theta = this.dot(v) / denominator; // clamp, to handle numerical problems
  3257. return Math.acos(MathUtils.clamp(theta, -1, 1));
  3258. };
  3259. _proto.distanceTo = function distanceTo(v) {
  3260. return Math.sqrt(this.distanceToSquared(v));
  3261. };
  3262. _proto.distanceToSquared = function distanceToSquared(v) {
  3263. var dx = this.x - v.x,
  3264. dy = this.y - v.y,
  3265. dz = this.z - v.z;
  3266. return dx * dx + dy * dy + dz * dz;
  3267. };
  3268. _proto.manhattanDistanceTo = function manhattanDistanceTo(v) {
  3269. return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
  3270. };
  3271. _proto.setFromSpherical = function setFromSpherical(s) {
  3272. return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
  3273. };
  3274. _proto.setFromSphericalCoords = function setFromSphericalCoords(radius, phi, theta) {
  3275. var sinPhiRadius = Math.sin(phi) * radius;
  3276. this.x = sinPhiRadius * Math.sin(theta);
  3277. this.y = Math.cos(phi) * radius;
  3278. this.z = sinPhiRadius * Math.cos(theta);
  3279. return this;
  3280. };
  3281. _proto.setFromCylindrical = function setFromCylindrical(c) {
  3282. return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
  3283. };
  3284. _proto.setFromCylindricalCoords = function setFromCylindricalCoords(radius, theta, y) {
  3285. this.x = radius * Math.sin(theta);
  3286. this.y = y;
  3287. this.z = radius * Math.cos(theta);
  3288. return this;
  3289. };
  3290. _proto.setFromMatrixPosition = function setFromMatrixPosition(m) {
  3291. var e = m.elements;
  3292. this.x = e[12];
  3293. this.y = e[13];
  3294. this.z = e[14];
  3295. return this;
  3296. };
  3297. _proto.setFromMatrixScale = function setFromMatrixScale(m) {
  3298. var sx = this.setFromMatrixColumn(m, 0).length();
  3299. var sy = this.setFromMatrixColumn(m, 1).length();
  3300. var sz = this.setFromMatrixColumn(m, 2).length();
  3301. this.x = sx;
  3302. this.y = sy;
  3303. this.z = sz;
  3304. return this;
  3305. };
  3306. _proto.setFromMatrixColumn = function setFromMatrixColumn(m, index) {
  3307. return this.fromArray(m.elements, index * 4);
  3308. };
  3309. _proto.setFromMatrix3Column = function setFromMatrix3Column(m, index) {
  3310. return this.fromArray(m.elements, index * 3);
  3311. };
  3312. _proto.equals = function equals(v) {
  3313. return v.x === this.x && v.y === this.y && v.z === this.z;
  3314. };
  3315. _proto.fromArray = function fromArray(array, offset) {
  3316. if (offset === void 0) {
  3317. offset = 0;
  3318. }
  3319. this.x = array[offset];
  3320. this.y = array[offset + 1];
  3321. this.z = array[offset + 2];
  3322. return this;
  3323. };
  3324. _proto.toArray = function toArray(array, offset) {
  3325. if (array === void 0) {
  3326. array = [];
  3327. }
  3328. if (offset === void 0) {
  3329. offset = 0;
  3330. }
  3331. array[offset] = this.x;
  3332. array[offset + 1] = this.y;
  3333. array[offset + 2] = this.z;
  3334. return array;
  3335. };
  3336. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index, offset) {
  3337. if (offset !== undefined) {
  3338. console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');
  3339. }
  3340. this.x = attribute.getX(index);
  3341. this.y = attribute.getY(index);
  3342. this.z = attribute.getZ(index);
  3343. return this;
  3344. };
  3345. _proto.random = function random() {
  3346. this.x = Math.random();
  3347. this.y = Math.random();
  3348. this.z = Math.random();
  3349. return this;
  3350. };
  3351. return Vector3;
  3352. }();
  3353. var _vector = /*@__PURE__*/new Vector3();
  3354. var _quaternion = /*@__PURE__*/new Quaternion();
  3355. var Box3 = /*#__PURE__*/function () {
  3356. function Box3(min, max) {
  3357. Object.defineProperty(this, 'isBox3', {
  3358. value: true
  3359. });
  3360. this.min = min !== undefined ? min : new Vector3(+Infinity, +Infinity, +Infinity);
  3361. this.max = max !== undefined ? max : new Vector3(-Infinity, -Infinity, -Infinity);
  3362. }
  3363. var _proto = Box3.prototype;
  3364. _proto.set = function set(min, max) {
  3365. this.min.copy(min);
  3366. this.max.copy(max);
  3367. return this;
  3368. };
  3369. _proto.setFromArray = function setFromArray(array) {
  3370. var minX = +Infinity;
  3371. var minY = +Infinity;
  3372. var minZ = +Infinity;
  3373. var maxX = -Infinity;
  3374. var maxY = -Infinity;
  3375. var maxZ = -Infinity;
  3376. for (var i = 0, l = array.length; i < l; i += 3) {
  3377. var x = array[i];
  3378. var y = array[i + 1];
  3379. var z = array[i + 2];
  3380. if (x < minX) minX = x;
  3381. if (y < minY) minY = y;
  3382. if (z < minZ) minZ = z;
  3383. if (x > maxX) maxX = x;
  3384. if (y > maxY) maxY = y;
  3385. if (z > maxZ) maxZ = z;
  3386. }
  3387. this.min.set(minX, minY, minZ);
  3388. this.max.set(maxX, maxY, maxZ);
  3389. return this;
  3390. };
  3391. _proto.setFromBufferAttribute = function setFromBufferAttribute(attribute) {
  3392. var minX = +Infinity;
  3393. var minY = +Infinity;
  3394. var minZ = +Infinity;
  3395. var maxX = -Infinity;
  3396. var maxY = -Infinity;
  3397. var maxZ = -Infinity;
  3398. for (var i = 0, l = attribute.count; i < l; i++) {
  3399. var x = attribute.getX(i);
  3400. var y = attribute.getY(i);
  3401. var z = attribute.getZ(i);
  3402. if (x < minX) minX = x;
  3403. if (y < minY) minY = y;
  3404. if (z < minZ) minZ = z;
  3405. if (x > maxX) maxX = x;
  3406. if (y > maxY) maxY = y;
  3407. if (z > maxZ) maxZ = z;
  3408. }
  3409. this.min.set(minX, minY, minZ);
  3410. this.max.set(maxX, maxY, maxZ);
  3411. return this;
  3412. };
  3413. _proto.setFromPoints = function setFromPoints(points) {
  3414. this.makeEmpty();
  3415. for (var i = 0, il = points.length; i < il; i++) {
  3416. this.expandByPoint(points[i]);
  3417. }
  3418. return this;
  3419. };
  3420. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  3421. var halfSize = _vector$1.copy(size).multiplyScalar(0.5);
  3422. this.min.copy(center).sub(halfSize);
  3423. this.max.copy(center).add(halfSize);
  3424. return this;
  3425. };
  3426. _proto.setFromObject = function setFromObject(object) {
  3427. this.makeEmpty();
  3428. return this.expandByObject(object);
  3429. };
  3430. _proto.clone = function clone() {
  3431. return new this.constructor().copy(this);
  3432. };
  3433. _proto.copy = function copy(box) {
  3434. this.min.copy(box.min);
  3435. this.max.copy(box.max);
  3436. return this;
  3437. };
  3438. _proto.makeEmpty = function makeEmpty() {
  3439. this.min.x = this.min.y = this.min.z = +Infinity;
  3440. this.max.x = this.max.y = this.max.z = -Infinity;
  3441. return this;
  3442. };
  3443. _proto.isEmpty = function isEmpty() {
  3444. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3445. return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
  3446. };
  3447. _proto.getCenter = function getCenter(target) {
  3448. if (target === undefined) {
  3449. console.warn('THREE.Box3: .getCenter() target is now required');
  3450. target = new Vector3();
  3451. }
  3452. return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  3453. };
  3454. _proto.getSize = function getSize(target) {
  3455. if (target === undefined) {
  3456. console.warn('THREE.Box3: .getSize() target is now required');
  3457. target = new Vector3();
  3458. }
  3459. return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min);
  3460. };
  3461. _proto.expandByPoint = function expandByPoint(point) {
  3462. this.min.min(point);
  3463. this.max.max(point);
  3464. return this;
  3465. };
  3466. _proto.expandByVector = function expandByVector(vector) {
  3467. this.min.sub(vector);
  3468. this.max.add(vector);
  3469. return this;
  3470. };
  3471. _proto.expandByScalar = function expandByScalar(scalar) {
  3472. this.min.addScalar(-scalar);
  3473. this.max.addScalar(scalar);
  3474. return this;
  3475. };
  3476. _proto.expandByObject = function expandByObject(object) {
  3477. // Computes the world-axis-aligned bounding box of an object (including its children),
  3478. // accounting for both the object's, and children's, world transforms
  3479. object.updateWorldMatrix(false, false);
  3480. var geometry = object.geometry;
  3481. if (geometry !== undefined) {
  3482. if (geometry.boundingBox === null) {
  3483. geometry.computeBoundingBox();
  3484. }
  3485. _box.copy(geometry.boundingBox);
  3486. _box.applyMatrix4(object.matrixWorld);
  3487. this.union(_box);
  3488. }
  3489. var children = object.children;
  3490. for (var i = 0, l = children.length; i < l; i++) {
  3491. this.expandByObject(children[i]);
  3492. }
  3493. return this;
  3494. };
  3495. _proto.containsPoint = function containsPoint(point) {
  3496. 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;
  3497. };
  3498. _proto.containsBox = function containsBox(box) {
  3499. 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;
  3500. };
  3501. _proto.getParameter = function getParameter(point, target) {
  3502. // This can potentially have a divide by zero if the box
  3503. // has a size dimension of 0.
  3504. if (target === undefined) {
  3505. console.warn('THREE.Box3: .getParameter() target is now required');
  3506. target = new Vector3();
  3507. }
  3508. 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));
  3509. };
  3510. _proto.intersectsBox = function intersectsBox(box) {
  3511. // using 6 splitting planes to rule out intersections.
  3512. 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;
  3513. };
  3514. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3515. // Find the point on the AABB closest to the sphere center.
  3516. this.clampPoint(sphere.center, _vector$1); // If that point is inside the sphere, the AABB and sphere intersect.
  3517. return _vector$1.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius;
  3518. };
  3519. _proto.intersectsPlane = function intersectsPlane(plane) {
  3520. // We compute the minimum and maximum dot product values. If those values
  3521. // are on the same side (back or front) of the plane, then there is no intersection.
  3522. var min, max;
  3523. if (plane.normal.x > 0) {
  3524. min = plane.normal.x * this.min.x;
  3525. max = plane.normal.x * this.max.x;
  3526. } else {
  3527. min = plane.normal.x * this.max.x;
  3528. max = plane.normal.x * this.min.x;
  3529. }
  3530. if (plane.normal.y > 0) {
  3531. min += plane.normal.y * this.min.y;
  3532. max += plane.normal.y * this.max.y;
  3533. } else {
  3534. min += plane.normal.y * this.max.y;
  3535. max += plane.normal.y * this.min.y;
  3536. }
  3537. if (plane.normal.z > 0) {
  3538. min += plane.normal.z * this.min.z;
  3539. max += plane.normal.z * this.max.z;
  3540. } else {
  3541. min += plane.normal.z * this.max.z;
  3542. max += plane.normal.z * this.min.z;
  3543. }
  3544. return min <= -plane.constant && max >= -plane.constant;
  3545. };
  3546. _proto.intersectsTriangle = function intersectsTriangle(triangle) {
  3547. if (this.isEmpty()) {
  3548. return false;
  3549. } // compute box center and extents
  3550. this.getCenter(_center);
  3551. _extents.subVectors(this.max, _center); // translate triangle to aabb origin
  3552. _v0.subVectors(triangle.a, _center);
  3553. _v1.subVectors(triangle.b, _center);
  3554. _v2.subVectors(triangle.c, _center); // compute edge vectors for triangle
  3555. _f0.subVectors(_v1, _v0);
  3556. _f1.subVectors(_v2, _v1);
  3557. _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
  3558. // 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
  3559. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3560. 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];
  3561. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3562. return false;
  3563. } // test 3 face normals from the aabb
  3564. axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
  3565. if (!satForAxes(axes, _v0, _v1, _v2, _extents)) {
  3566. return false;
  3567. } // finally testing the face normal of the triangle
  3568. // use already existing triangle edge vectors here
  3569. _triangleNormal.crossVectors(_f0, _f1);
  3570. axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
  3571. return satForAxes(axes, _v0, _v1, _v2, _extents);
  3572. };
  3573. _proto.clampPoint = function clampPoint(point, target) {
  3574. if (target === undefined) {
  3575. console.warn('THREE.Box3: .clampPoint() target is now required');
  3576. target = new Vector3();
  3577. }
  3578. return target.copy(point).clamp(this.min, this.max);
  3579. };
  3580. _proto.distanceToPoint = function distanceToPoint(point) {
  3581. var clampedPoint = _vector$1.copy(point).clamp(this.min, this.max);
  3582. return clampedPoint.sub(point).length();
  3583. };
  3584. _proto.getBoundingSphere = function getBoundingSphere(target) {
  3585. if (target === undefined) {
  3586. console.error('THREE.Box3: .getBoundingSphere() target is now required'); //target = new Sphere(); // removed to avoid cyclic dependency
  3587. }
  3588. this.getCenter(target.center);
  3589. target.radius = this.getSize(_vector$1).length() * 0.5;
  3590. return target;
  3591. };
  3592. _proto.intersect = function intersect(box) {
  3593. this.min.max(box.min);
  3594. 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.
  3595. if (this.isEmpty()) this.makeEmpty();
  3596. return this;
  3597. };
  3598. _proto.union = function union(box) {
  3599. this.min.min(box.min);
  3600. this.max.max(box.max);
  3601. return this;
  3602. };
  3603. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3604. // transform of empty box is an empty box.
  3605. if (this.isEmpty()) return this; // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3606. _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); // 000
  3607. _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); // 001
  3608. _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); // 010
  3609. _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); // 011
  3610. _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); // 100
  3611. _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); // 101
  3612. _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); // 110
  3613. _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); // 111
  3614. this.setFromPoints(_points);
  3615. return this;
  3616. };
  3617. _proto.translate = function translate(offset) {
  3618. this.min.add(offset);
  3619. this.max.add(offset);
  3620. return this;
  3621. };
  3622. _proto.equals = function equals(box) {
  3623. return box.min.equals(this.min) && box.max.equals(this.max);
  3624. };
  3625. return Box3;
  3626. }();
  3627. function satForAxes(axes, v0, v1, v2, extents) {
  3628. for (var i = 0, j = axes.length - 3; i <= j; i += 3) {
  3629. _testAxis.fromArray(axes, i); // project the aabb onto the seperating axis
  3630. 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
  3631. var p0 = v0.dot(_testAxis);
  3632. var p1 = v1.dot(_testAxis);
  3633. var p2 = v2.dot(_testAxis); // actual test, basically see if either of the most extreme of the triangle points intersects r
  3634. if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) {
  3635. // points of the projected triangle are outside the projected half-length of the aabb
  3636. // the axis is seperating and we can exit
  3637. return false;
  3638. }
  3639. }
  3640. return true;
  3641. }
  3642. 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()];
  3643. var _vector$1 = /*@__PURE__*/new Vector3();
  3644. var _box = /*@__PURE__*/new Box3(); // triangle centered vertices
  3645. var _v0 = /*@__PURE__*/new Vector3();
  3646. var _v1 = /*@__PURE__*/new Vector3();
  3647. var _v2 = /*@__PURE__*/new Vector3(); // triangle edge vectors
  3648. var _f0 = /*@__PURE__*/new Vector3();
  3649. var _f1 = /*@__PURE__*/new Vector3();
  3650. var _f2 = /*@__PURE__*/new Vector3();
  3651. var _center = /*@__PURE__*/new Vector3();
  3652. var _extents = /*@__PURE__*/new Vector3();
  3653. var _triangleNormal = /*@__PURE__*/new Vector3();
  3654. var _testAxis = /*@__PURE__*/new Vector3();
  3655. var _box$1 = /*@__PURE__*/new Box3();
  3656. var Sphere = /*#__PURE__*/function () {
  3657. function Sphere(center, radius) {
  3658. this.center = center !== undefined ? center : new Vector3();
  3659. this.radius = radius !== undefined ? radius : -1;
  3660. }
  3661. var _proto = Sphere.prototype;
  3662. _proto.set = function set(center, radius) {
  3663. this.center.copy(center);
  3664. this.radius = radius;
  3665. return this;
  3666. };
  3667. _proto.setFromPoints = function setFromPoints(points, optionalCenter) {
  3668. var center = this.center;
  3669. if (optionalCenter !== undefined) {
  3670. center.copy(optionalCenter);
  3671. } else {
  3672. _box$1.setFromPoints(points).getCenter(center);
  3673. }
  3674. var maxRadiusSq = 0;
  3675. for (var i = 0, il = points.length; i < il; i++) {
  3676. maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i]));
  3677. }
  3678. this.radius = Math.sqrt(maxRadiusSq);
  3679. return this;
  3680. };
  3681. _proto.clone = function clone() {
  3682. return new this.constructor().copy(this);
  3683. };
  3684. _proto.copy = function copy(sphere) {
  3685. this.center.copy(sphere.center);
  3686. this.radius = sphere.radius;
  3687. return this;
  3688. };
  3689. _proto.isEmpty = function isEmpty() {
  3690. return this.radius < 0;
  3691. };
  3692. _proto.makeEmpty = function makeEmpty() {
  3693. this.center.set(0, 0, 0);
  3694. this.radius = -1;
  3695. return this;
  3696. };
  3697. _proto.containsPoint = function containsPoint(point) {
  3698. return point.distanceToSquared(this.center) <= this.radius * this.radius;
  3699. };
  3700. _proto.distanceToPoint = function distanceToPoint(point) {
  3701. return point.distanceTo(this.center) - this.radius;
  3702. };
  3703. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3704. var radiusSum = this.radius + sphere.radius;
  3705. return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum;
  3706. };
  3707. _proto.intersectsBox = function intersectsBox(box) {
  3708. return box.intersectsSphere(this);
  3709. };
  3710. _proto.intersectsPlane = function intersectsPlane(plane) {
  3711. return Math.abs(plane.distanceToPoint(this.center)) <= this.radius;
  3712. };
  3713. _proto.clampPoint = function clampPoint(point, target) {
  3714. var deltaLengthSq = this.center.distanceToSquared(point);
  3715. if (target === undefined) {
  3716. console.warn('THREE.Sphere: .clampPoint() target is now required');
  3717. target = new Vector3();
  3718. }
  3719. target.copy(point);
  3720. if (deltaLengthSq > this.radius * this.radius) {
  3721. target.sub(this.center).normalize();
  3722. target.multiplyScalar(this.radius).add(this.center);
  3723. }
  3724. return target;
  3725. };
  3726. _proto.getBoundingBox = function getBoundingBox(target) {
  3727. if (target === undefined) {
  3728. console.warn('THREE.Sphere: .getBoundingBox() target is now required');
  3729. target = new Box3();
  3730. }
  3731. if (this.isEmpty()) {
  3732. // Empty sphere produces empty bounding box
  3733. target.makeEmpty();
  3734. return target;
  3735. }
  3736. target.set(this.center, this.center);
  3737. target.expandByScalar(this.radius);
  3738. return target;
  3739. };
  3740. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  3741. this.center.applyMatrix4(matrix);
  3742. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3743. return this;
  3744. };
  3745. _proto.translate = function translate(offset) {
  3746. this.center.add(offset);
  3747. return this;
  3748. };
  3749. _proto.equals = function equals(sphere) {
  3750. return sphere.center.equals(this.center) && sphere.radius === this.radius;
  3751. };
  3752. return Sphere;
  3753. }();
  3754. var _vector$2 = /*@__PURE__*/new Vector3();
  3755. var _segCenter = /*@__PURE__*/new Vector3();
  3756. var _segDir = /*@__PURE__*/new Vector3();
  3757. var _diff = /*@__PURE__*/new Vector3();
  3758. var _edge1 = /*@__PURE__*/new Vector3();
  3759. var _edge2 = /*@__PURE__*/new Vector3();
  3760. var _normal = /*@__PURE__*/new Vector3();
  3761. var Ray = /*#__PURE__*/function () {
  3762. function Ray(origin, direction) {
  3763. this.origin = origin !== undefined ? origin : new Vector3();
  3764. this.direction = direction !== undefined ? direction : new Vector3(0, 0, -1);
  3765. }
  3766. var _proto = Ray.prototype;
  3767. _proto.set = function set(origin, direction) {
  3768. this.origin.copy(origin);
  3769. this.direction.copy(direction);
  3770. return this;
  3771. };
  3772. _proto.clone = function clone() {
  3773. return new this.constructor().copy(this);
  3774. };
  3775. _proto.copy = function copy(ray) {
  3776. this.origin.copy(ray.origin);
  3777. this.direction.copy(ray.direction);
  3778. return this;
  3779. };
  3780. _proto.at = function at(t, target) {
  3781. if (target === undefined) {
  3782. console.warn('THREE.Ray: .at() target is now required');
  3783. target = new Vector3();
  3784. }
  3785. return target.copy(this.direction).multiplyScalar(t).add(this.origin);
  3786. };
  3787. _proto.lookAt = function lookAt(v) {
  3788. this.direction.copy(v).sub(this.origin).normalize();
  3789. return this;
  3790. };
  3791. _proto.recast = function recast(t) {
  3792. this.origin.copy(this.at(t, _vector$2));
  3793. return this;
  3794. };
  3795. _proto.closestPointToPoint = function closestPointToPoint(point, target) {
  3796. if (target === undefined) {
  3797. console.warn('THREE.Ray: .closestPointToPoint() target is now required');
  3798. target = new Vector3();
  3799. }
  3800. target.subVectors(point, this.origin);
  3801. var directionDistance = target.dot(this.direction);
  3802. if (directionDistance < 0) {
  3803. return target.copy(this.origin);
  3804. }
  3805. return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3806. };
  3807. _proto.distanceToPoint = function distanceToPoint(point) {
  3808. return Math.sqrt(this.distanceSqToPoint(point));
  3809. };
  3810. _proto.distanceSqToPoint = function distanceSqToPoint(point) {
  3811. var directionDistance = _vector$2.subVectors(point, this.origin).dot(this.direction); // point behind the ray
  3812. if (directionDistance < 0) {
  3813. return this.origin.distanceToSquared(point);
  3814. }
  3815. _vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);
  3816. return _vector$2.distanceToSquared(point);
  3817. };
  3818. _proto.distanceSqToSegment = function distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) {
  3819. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3820. // It returns the min distance between the ray and the segment
  3821. // defined by v0 and v1
  3822. // It can also set two optional targets :
  3823. // - The closest point on the ray
  3824. // - The closest point on the segment
  3825. _segCenter.copy(v0).add(v1).multiplyScalar(0.5);
  3826. _segDir.copy(v1).sub(v0).normalize();
  3827. _diff.copy(this.origin).sub(_segCenter);
  3828. var segExtent = v0.distanceTo(v1) * 0.5;
  3829. var a01 = -this.direction.dot(_segDir);
  3830. var b0 = _diff.dot(this.direction);
  3831. var b1 = -_diff.dot(_segDir);
  3832. var c = _diff.lengthSq();
  3833. var det = Math.abs(1 - a01 * a01);
  3834. var s0, s1, sqrDist, extDet;
  3835. if (det > 0) {
  3836. // The ray and segment are not parallel.
  3837. s0 = a01 * b1 - b0;
  3838. s1 = a01 * b0 - b1;
  3839. extDet = segExtent * det;
  3840. if (s0 >= 0) {
  3841. if (s1 >= -extDet) {
  3842. if (s1 <= extDet) {
  3843. // region 0
  3844. // Minimum at interior points of ray and segment.
  3845. var invDet = 1 / det;
  3846. s0 *= invDet;
  3847. s1 *= invDet;
  3848. sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c;
  3849. } else {
  3850. // region 1
  3851. s1 = segExtent;
  3852. s0 = Math.max(0, -(a01 * s1 + b0));
  3853. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3854. }
  3855. } else {
  3856. // region 5
  3857. s1 = -segExtent;
  3858. s0 = Math.max(0, -(a01 * s1 + b0));
  3859. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3860. }
  3861. } else {
  3862. if (s1 <= -extDet) {
  3863. // region 4
  3864. s0 = Math.max(0, -(-a01 * segExtent + b0));
  3865. s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3866. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3867. } else if (s1 <= extDet) {
  3868. // region 3
  3869. s0 = 0;
  3870. s1 = Math.min(Math.max(-segExtent, -b1), segExtent);
  3871. sqrDist = s1 * (s1 + 2 * b1) + c;
  3872. } else {
  3873. // region 2
  3874. s0 = Math.max(0, -(a01 * segExtent + b0));
  3875. s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent);
  3876. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3877. }
  3878. }
  3879. } else {
  3880. // Ray and segment are parallel.
  3881. s1 = a01 > 0 ? -segExtent : segExtent;
  3882. s0 = Math.max(0, -(a01 * s1 + b0));
  3883. sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c;
  3884. }
  3885. if (optionalPointOnRay) {
  3886. optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);
  3887. }
  3888. if (optionalPointOnSegment) {
  3889. optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);
  3890. }
  3891. return sqrDist;
  3892. };
  3893. _proto.intersectSphere = function intersectSphere(sphere, target) {
  3894. _vector$2.subVectors(sphere.center, this.origin);
  3895. var tca = _vector$2.dot(this.direction);
  3896. var d2 = _vector$2.dot(_vector$2) - tca * tca;
  3897. var radius2 = sphere.radius * sphere.radius;
  3898. if (d2 > radius2) return null;
  3899. var thc = Math.sqrt(radius2 - d2); // t0 = first intersect point - entrance on front of sphere
  3900. var t0 = tca - thc; // t1 = second intersect point - exit point on back of sphere
  3901. var t1 = tca + thc; // test to see if both t0 and t1 are behind the ray - if so, return null
  3902. if (t0 < 0 && t1 < 0) return null; // test to see if t0 is behind the ray:
  3903. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3904. // in order to always return an intersect point that is in front of the ray.
  3905. 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
  3906. return this.at(t0, target);
  3907. };
  3908. _proto.intersectsSphere = function intersectsSphere(sphere) {
  3909. return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius;
  3910. };
  3911. _proto.distanceToPlane = function distanceToPlane(plane) {
  3912. var denominator = plane.normal.dot(this.direction);
  3913. if (denominator === 0) {
  3914. // line is coplanar, return origin
  3915. if (plane.distanceToPoint(this.origin) === 0) {
  3916. return 0;
  3917. } // Null is preferable to undefined since undefined means.... it is undefined
  3918. return null;
  3919. }
  3920. var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; // Return if the ray never intersects the plane
  3921. return t >= 0 ? t : null;
  3922. };
  3923. _proto.intersectPlane = function intersectPlane(plane, target) {
  3924. var t = this.distanceToPlane(plane);
  3925. if (t === null) {
  3926. return null;
  3927. }
  3928. return this.at(t, target);
  3929. };
  3930. _proto.intersectsPlane = function intersectsPlane(plane) {
  3931. // check if the ray lies on the plane first
  3932. var distToPoint = plane.distanceToPoint(this.origin);
  3933. if (distToPoint === 0) {
  3934. return true;
  3935. }
  3936. var denominator = plane.normal.dot(this.direction);
  3937. if (denominator * distToPoint < 0) {
  3938. return true;
  3939. } // ray origin is behind the plane (and is pointing behind it)
  3940. return false;
  3941. };
  3942. _proto.intersectBox = function intersectBox(box, target) {
  3943. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3944. var invdirx = 1 / this.direction.x,
  3945. invdiry = 1 / this.direction.y,
  3946. invdirz = 1 / this.direction.z;
  3947. var origin = this.origin;
  3948. if (invdirx >= 0) {
  3949. tmin = (box.min.x - origin.x) * invdirx;
  3950. tmax = (box.max.x - origin.x) * invdirx;
  3951. } else {
  3952. tmin = (box.max.x - origin.x) * invdirx;
  3953. tmax = (box.min.x - origin.x) * invdirx;
  3954. }
  3955. if (invdiry >= 0) {
  3956. tymin = (box.min.y - origin.y) * invdiry;
  3957. tymax = (box.max.y - origin.y) * invdiry;
  3958. } else {
  3959. tymin = (box.max.y - origin.y) * invdiry;
  3960. tymax = (box.min.y - origin.y) * invdiry;
  3961. }
  3962. if (tmin > tymax || tymin > tmax) return null; // These lines also handle the case where tmin or tmax is NaN
  3963. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3964. if (tymin > tmin || tmin !== tmin) tmin = tymin;
  3965. if (tymax < tmax || tmax !== tmax) tmax = tymax;
  3966. if (invdirz >= 0) {
  3967. tzmin = (box.min.z - origin.z) * invdirz;
  3968. tzmax = (box.max.z - origin.z) * invdirz;
  3969. } else {
  3970. tzmin = (box.max.z - origin.z) * invdirz;
  3971. tzmax = (box.min.z - origin.z) * invdirz;
  3972. }
  3973. if (tmin > tzmax || tzmin > tmax) return null;
  3974. if (tzmin > tmin || tmin !== tmin) tmin = tzmin;
  3975. if (tzmax < tmax || tmax !== tmax) tmax = tzmax; //return point closest to the ray (positive side)
  3976. if (tmax < 0) return null;
  3977. return this.at(tmin >= 0 ? tmin : tmax, target);
  3978. };
  3979. _proto.intersectsBox = function intersectsBox(box) {
  3980. return this.intersectBox(box, _vector$2) !== null;
  3981. };
  3982. _proto.intersectTriangle = function intersectTriangle(a, b, c, backfaceCulling, target) {
  3983. // Compute the offset origin, edges, and normal.
  3984. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3985. _edge1.subVectors(b, a);
  3986. _edge2.subVectors(c, a);
  3987. _normal.crossVectors(_edge1, _edge2); // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3988. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3989. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3990. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3991. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3992. var DdN = this.direction.dot(_normal);
  3993. var sign;
  3994. if (DdN > 0) {
  3995. if (backfaceCulling) return null;
  3996. sign = 1;
  3997. } else if (DdN < 0) {
  3998. sign = -1;
  3999. DdN = -DdN;
  4000. } else {
  4001. return null;
  4002. }
  4003. _diff.subVectors(this.origin, a);
  4004. var DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); // b1 < 0, no intersection
  4005. if (DdQxE2 < 0) {
  4006. return null;
  4007. }
  4008. var DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); // b2 < 0, no intersection
  4009. if (DdE1xQ < 0) {
  4010. return null;
  4011. } // b1+b2 > 1, no intersection
  4012. if (DdQxE2 + DdE1xQ > DdN) {
  4013. return null;
  4014. } // Line intersects triangle, check if ray does.
  4015. var QdN = -sign * _diff.dot(_normal); // t < 0, no intersection
  4016. if (QdN < 0) {
  4017. return null;
  4018. } // Ray intersects triangle.
  4019. return this.at(QdN / DdN, target);
  4020. };
  4021. _proto.applyMatrix4 = function applyMatrix4(matrix4) {
  4022. this.origin.applyMatrix4(matrix4);
  4023. this.direction.transformDirection(matrix4);
  4024. return this;
  4025. };
  4026. _proto.equals = function equals(ray) {
  4027. return ray.origin.equals(this.origin) && ray.direction.equals(this.direction);
  4028. };
  4029. return Ray;
  4030. }();
  4031. var Matrix4 = /*#__PURE__*/function () {
  4032. function Matrix4() {
  4033. Object.defineProperty(this, 'isMatrix4', {
  4034. value: true
  4035. });
  4036. this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
  4037. if (arguments.length > 0) {
  4038. console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
  4039. }
  4040. }
  4041. var _proto = Matrix4.prototype;
  4042. _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
  4043. var te = this.elements;
  4044. te[0] = n11;
  4045. te[4] = n12;
  4046. te[8] = n13;
  4047. te[12] = n14;
  4048. te[1] = n21;
  4049. te[5] = n22;
  4050. te[9] = n23;
  4051. te[13] = n24;
  4052. te[2] = n31;
  4053. te[6] = n32;
  4054. te[10] = n33;
  4055. te[14] = n34;
  4056. te[3] = n41;
  4057. te[7] = n42;
  4058. te[11] = n43;
  4059. te[15] = n44;
  4060. return this;
  4061. };
  4062. _proto.identity = function identity() {
  4063. this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4064. return this;
  4065. };
  4066. _proto.clone = function clone() {
  4067. return new Matrix4().fromArray(this.elements);
  4068. };
  4069. _proto.copy = function copy(m) {
  4070. var te = this.elements;
  4071. var me = m.elements;
  4072. te[0] = me[0];
  4073. te[1] = me[1];
  4074. te[2] = me[2];
  4075. te[3] = me[3];
  4076. te[4] = me[4];
  4077. te[5] = me[5];
  4078. te[6] = me[6];
  4079. te[7] = me[7];
  4080. te[8] = me[8];
  4081. te[9] = me[9];
  4082. te[10] = me[10];
  4083. te[11] = me[11];
  4084. te[12] = me[12];
  4085. te[13] = me[13];
  4086. te[14] = me[14];
  4087. te[15] = me[15];
  4088. return this;
  4089. };
  4090. _proto.copyPosition = function copyPosition(m) {
  4091. var te = this.elements,
  4092. me = m.elements;
  4093. te[12] = me[12];
  4094. te[13] = me[13];
  4095. te[14] = me[14];
  4096. return this;
  4097. };
  4098. _proto.setFromMatrix3 = function setFromMatrix3(m) {
  4099. var me = m.elements;
  4100. 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);
  4101. return this;
  4102. };
  4103. _proto.extractBasis = function extractBasis(xAxis, yAxis, zAxis) {
  4104. xAxis.setFromMatrixColumn(this, 0);
  4105. yAxis.setFromMatrixColumn(this, 1);
  4106. zAxis.setFromMatrixColumn(this, 2);
  4107. return this;
  4108. };
  4109. _proto.makeBasis = function makeBasis(xAxis, yAxis, zAxis) {
  4110. 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);
  4111. return this;
  4112. };
  4113. _proto.extractRotation = function extractRotation(m) {
  4114. // this method does not support reflection matrices
  4115. var te = this.elements;
  4116. var me = m.elements;
  4117. var scaleX = 1 / _v1$1.setFromMatrixColumn(m, 0).length();
  4118. var scaleY = 1 / _v1$1.setFromMatrixColumn(m, 1).length();
  4119. var scaleZ = 1 / _v1$1.setFromMatrixColumn(m, 2).length();
  4120. te[0] = me[0] * scaleX;
  4121. te[1] = me[1] * scaleX;
  4122. te[2] = me[2] * scaleX;
  4123. te[3] = 0;
  4124. te[4] = me[4] * scaleY;
  4125. te[5] = me[5] * scaleY;
  4126. te[6] = me[6] * scaleY;
  4127. te[7] = 0;
  4128. te[8] = me[8] * scaleZ;
  4129. te[9] = me[9] * scaleZ;
  4130. te[10] = me[10] * scaleZ;
  4131. te[11] = 0;
  4132. te[12] = 0;
  4133. te[13] = 0;
  4134. te[14] = 0;
  4135. te[15] = 1;
  4136. return this;
  4137. };
  4138. _proto.makeRotationFromEuler = function makeRotationFromEuler(euler) {
  4139. if (!(euler && euler.isEuler)) {
  4140. console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
  4141. }
  4142. var te = this.elements;
  4143. var x = euler.x,
  4144. y = euler.y,
  4145. z = euler.z;
  4146. var a = Math.cos(x),
  4147. b = Math.sin(x);
  4148. var c = Math.cos(y),
  4149. d = Math.sin(y);
  4150. var e = Math.cos(z),
  4151. f = Math.sin(z);
  4152. if (euler.order === 'XYZ') {
  4153. var ae = a * e,
  4154. af = a * f,
  4155. be = b * e,
  4156. bf = b * f;
  4157. te[0] = c * e;
  4158. te[4] = -c * f;
  4159. te[8] = d;
  4160. te[1] = af + be * d;
  4161. te[5] = ae - bf * d;
  4162. te[9] = -b * c;
  4163. te[2] = bf - ae * d;
  4164. te[6] = be + af * d;
  4165. te[10] = a * c;
  4166. } else if (euler.order === 'YXZ') {
  4167. var ce = c * e,
  4168. cf = c * f,
  4169. de = d * e,
  4170. df = d * f;
  4171. te[0] = ce + df * b;
  4172. te[4] = de * b - cf;
  4173. te[8] = a * d;
  4174. te[1] = a * f;
  4175. te[5] = a * e;
  4176. te[9] = -b;
  4177. te[2] = cf * b - de;
  4178. te[6] = df + ce * b;
  4179. te[10] = a * c;
  4180. } else if (euler.order === 'ZXY') {
  4181. var _ce = c * e,
  4182. _cf = c * f,
  4183. _de = d * e,
  4184. _df = d * f;
  4185. te[0] = _ce - _df * b;
  4186. te[4] = -a * f;
  4187. te[8] = _de + _cf * b;
  4188. te[1] = _cf + _de * b;
  4189. te[5] = a * e;
  4190. te[9] = _df - _ce * b;
  4191. te[2] = -a * d;
  4192. te[6] = b;
  4193. te[10] = a * c;
  4194. } else if (euler.order === 'ZYX') {
  4195. var _ae = a * e,
  4196. _af = a * f,
  4197. _be = b * e,
  4198. _bf = b * f;
  4199. te[0] = c * e;
  4200. te[4] = _be * d - _af;
  4201. te[8] = _ae * d + _bf;
  4202. te[1] = c * f;
  4203. te[5] = _bf * d + _ae;
  4204. te[9] = _af * d - _be;
  4205. te[2] = -d;
  4206. te[6] = b * c;
  4207. te[10] = a * c;
  4208. } else if (euler.order === 'YZX') {
  4209. var ac = a * c,
  4210. ad = a * d,
  4211. bc = b * c,
  4212. bd = b * d;
  4213. te[0] = c * e;
  4214. te[4] = bd - ac * f;
  4215. te[8] = bc * f + ad;
  4216. te[1] = f;
  4217. te[5] = a * e;
  4218. te[9] = -b * e;
  4219. te[2] = -d * e;
  4220. te[6] = ad * f + bc;
  4221. te[10] = ac - bd * f;
  4222. } else if (euler.order === 'XZY') {
  4223. var _ac = a * c,
  4224. _ad = a * d,
  4225. _bc = b * c,
  4226. _bd = b * d;
  4227. te[0] = c * e;
  4228. te[4] = -f;
  4229. te[8] = d * e;
  4230. te[1] = _ac * f + _bd;
  4231. te[5] = a * e;
  4232. te[9] = _ad * f - _bc;
  4233. te[2] = _bc * f - _ad;
  4234. te[6] = b * e;
  4235. te[10] = _bd * f + _ac;
  4236. } // bottom row
  4237. te[3] = 0;
  4238. te[7] = 0;
  4239. te[11] = 0; // last column
  4240. te[12] = 0;
  4241. te[13] = 0;
  4242. te[14] = 0;
  4243. te[15] = 1;
  4244. return this;
  4245. };
  4246. _proto.makeRotationFromQuaternion = function makeRotationFromQuaternion(q) {
  4247. return this.compose(_zero, q, _one);
  4248. };
  4249. _proto.lookAt = function lookAt(eye, target, up) {
  4250. var te = this.elements;
  4251. _z.subVectors(eye, target);
  4252. if (_z.lengthSq() === 0) {
  4253. // eye and target are in the same position
  4254. _z.z = 1;
  4255. }
  4256. _z.normalize();
  4257. _x.crossVectors(up, _z);
  4258. if (_x.lengthSq() === 0) {
  4259. // up and z are parallel
  4260. if (Math.abs(up.z) === 1) {
  4261. _z.x += 0.0001;
  4262. } else {
  4263. _z.z += 0.0001;
  4264. }
  4265. _z.normalize();
  4266. _x.crossVectors(up, _z);
  4267. }
  4268. _x.normalize();
  4269. _y.crossVectors(_z, _x);
  4270. te[0] = _x.x;
  4271. te[4] = _y.x;
  4272. te[8] = _z.x;
  4273. te[1] = _x.y;
  4274. te[5] = _y.y;
  4275. te[9] = _z.y;
  4276. te[2] = _x.z;
  4277. te[6] = _y.z;
  4278. te[10] = _z.z;
  4279. return this;
  4280. };
  4281. _proto.multiply = function multiply(m, n) {
  4282. if (n !== undefined) {
  4283. console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
  4284. return this.multiplyMatrices(m, n);
  4285. }
  4286. return this.multiplyMatrices(this, m);
  4287. };
  4288. _proto.premultiply = function premultiply(m) {
  4289. return this.multiplyMatrices(m, this);
  4290. };
  4291. _proto.multiplyMatrices = function multiplyMatrices(a, b) {
  4292. var ae = a.elements;
  4293. var be = b.elements;
  4294. var te = this.elements;
  4295. var a11 = ae[0],
  4296. a12 = ae[4],
  4297. a13 = ae[8],
  4298. a14 = ae[12];
  4299. var a21 = ae[1],
  4300. a22 = ae[5],
  4301. a23 = ae[9],
  4302. a24 = ae[13];
  4303. var a31 = ae[2],
  4304. a32 = ae[6],
  4305. a33 = ae[10],
  4306. a34 = ae[14];
  4307. var a41 = ae[3],
  4308. a42 = ae[7],
  4309. a43 = ae[11],
  4310. a44 = ae[15];
  4311. var b11 = be[0],
  4312. b12 = be[4],
  4313. b13 = be[8],
  4314. b14 = be[12];
  4315. var b21 = be[1],
  4316. b22 = be[5],
  4317. b23 = be[9],
  4318. b24 = be[13];
  4319. var b31 = be[2],
  4320. b32 = be[6],
  4321. b33 = be[10],
  4322. b34 = be[14];
  4323. var b41 = be[3],
  4324. b42 = be[7],
  4325. b43 = be[11],
  4326. b44 = be[15];
  4327. te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  4328. te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  4329. te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  4330. te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  4331. te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  4332. te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  4333. te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  4334. te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  4335. te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  4336. te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  4337. te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  4338. te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  4339. te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  4340. te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  4341. te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  4342. te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  4343. return this;
  4344. };
  4345. _proto.multiplyScalar = function multiplyScalar(s) {
  4346. var te = this.elements;
  4347. te[0] *= s;
  4348. te[4] *= s;
  4349. te[8] *= s;
  4350. te[12] *= s;
  4351. te[1] *= s;
  4352. te[5] *= s;
  4353. te[9] *= s;
  4354. te[13] *= s;
  4355. te[2] *= s;
  4356. te[6] *= s;
  4357. te[10] *= s;
  4358. te[14] *= s;
  4359. te[3] *= s;
  4360. te[7] *= s;
  4361. te[11] *= s;
  4362. te[15] *= s;
  4363. return this;
  4364. };
  4365. _proto.determinant = function determinant() {
  4366. var te = this.elements;
  4367. var n11 = te[0],
  4368. n12 = te[4],
  4369. n13 = te[8],
  4370. n14 = te[12];
  4371. var n21 = te[1],
  4372. n22 = te[5],
  4373. n23 = te[9],
  4374. n24 = te[13];
  4375. var n31 = te[2],
  4376. n32 = te[6],
  4377. n33 = te[10],
  4378. n34 = te[14];
  4379. var n41 = te[3],
  4380. n42 = te[7],
  4381. n43 = te[11],
  4382. n44 = te[15]; //TODO: make this more efficient
  4383. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  4384. 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);
  4385. };
  4386. _proto.transpose = function transpose() {
  4387. var te = this.elements;
  4388. var tmp;
  4389. tmp = te[1];
  4390. te[1] = te[4];
  4391. te[4] = tmp;
  4392. tmp = te[2];
  4393. te[2] = te[8];
  4394. te[8] = tmp;
  4395. tmp = te[6];
  4396. te[6] = te[9];
  4397. te[9] = tmp;
  4398. tmp = te[3];
  4399. te[3] = te[12];
  4400. te[12] = tmp;
  4401. tmp = te[7];
  4402. te[7] = te[13];
  4403. te[13] = tmp;
  4404. tmp = te[11];
  4405. te[11] = te[14];
  4406. te[14] = tmp;
  4407. return this;
  4408. };
  4409. _proto.setPosition = function setPosition(x, y, z) {
  4410. var te = this.elements;
  4411. if (x.isVector3) {
  4412. te[12] = x.x;
  4413. te[13] = x.y;
  4414. te[14] = x.z;
  4415. } else {
  4416. te[12] = x;
  4417. te[13] = y;
  4418. te[14] = z;
  4419. }
  4420. return this;
  4421. };
  4422. _proto.invert = function invert() {
  4423. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  4424. var te = this.elements,
  4425. n11 = te[0],
  4426. n21 = te[1],
  4427. n31 = te[2],
  4428. n41 = te[3],
  4429. n12 = te[4],
  4430. n22 = te[5],
  4431. n32 = te[6],
  4432. n42 = te[7],
  4433. n13 = te[8],
  4434. n23 = te[9],
  4435. n33 = te[10],
  4436. n43 = te[11],
  4437. n14 = te[12],
  4438. n24 = te[13],
  4439. n34 = te[14],
  4440. n44 = te[15],
  4441. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  4442. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  4443. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  4444. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  4445. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  4446. if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  4447. var detInv = 1 / det;
  4448. te[0] = t11 * detInv;
  4449. te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
  4450. te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
  4451. te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
  4452. te[4] = t12 * detInv;
  4453. te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
  4454. te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
  4455. te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
  4456. te[8] = t13 * detInv;
  4457. te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
  4458. te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
  4459. te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
  4460. te[12] = t14 * detInv;
  4461. te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
  4462. te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
  4463. te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
  4464. return this;
  4465. };
  4466. _proto.scale = function scale(v) {
  4467. var te = this.elements;
  4468. var x = v.x,
  4469. y = v.y,
  4470. z = v.z;
  4471. te[0] *= x;
  4472. te[4] *= y;
  4473. te[8] *= z;
  4474. te[1] *= x;
  4475. te[5] *= y;
  4476. te[9] *= z;
  4477. te[2] *= x;
  4478. te[6] *= y;
  4479. te[10] *= z;
  4480. te[3] *= x;
  4481. te[7] *= y;
  4482. te[11] *= z;
  4483. return this;
  4484. };
  4485. _proto.getMaxScaleOnAxis = function getMaxScaleOnAxis() {
  4486. var te = this.elements;
  4487. var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
  4488. var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
  4489. var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
  4490. return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
  4491. };
  4492. _proto.makeTranslation = function makeTranslation(x, y, z) {
  4493. this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
  4494. return this;
  4495. };
  4496. _proto.makeRotationX = function makeRotationX(theta) {
  4497. var c = Math.cos(theta),
  4498. s = Math.sin(theta);
  4499. this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
  4500. return this;
  4501. };
  4502. _proto.makeRotationY = function makeRotationY(theta) {
  4503. var c = Math.cos(theta),
  4504. s = Math.sin(theta);
  4505. this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
  4506. return this;
  4507. };
  4508. _proto.makeRotationZ = function makeRotationZ(theta) {
  4509. var c = Math.cos(theta),
  4510. s = Math.sin(theta);
  4511. this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  4512. return this;
  4513. };
  4514. _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
  4515. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4516. var c = Math.cos(angle);
  4517. var s = Math.sin(angle);
  4518. var t = 1 - c;
  4519. var x = axis.x,
  4520. y = axis.y,
  4521. z = axis.z;
  4522. var tx = t * x,
  4523. ty = t * y;
  4524. 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);
  4525. return this;
  4526. };
  4527. _proto.makeScale = function makeScale(x, y, z) {
  4528. this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
  4529. return this;
  4530. };
  4531. _proto.makeShear = function makeShear(x, y, z) {
  4532. this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1);
  4533. return this;
  4534. };
  4535. _proto.compose = function compose(position, quaternion, scale) {
  4536. var te = this.elements;
  4537. var x = quaternion._x,
  4538. y = quaternion._y,
  4539. z = quaternion._z,
  4540. w = quaternion._w;
  4541. var x2 = x + x,
  4542. y2 = y + y,
  4543. z2 = z + z;
  4544. var xx = x * x2,
  4545. xy = x * y2,
  4546. xz = x * z2;
  4547. var yy = y * y2,
  4548. yz = y * z2,
  4549. zz = z * z2;
  4550. var wx = w * x2,
  4551. wy = w * y2,
  4552. wz = w * z2;
  4553. var sx = scale.x,
  4554. sy = scale.y,
  4555. sz = scale.z;
  4556. te[0] = (1 - (yy + zz)) * sx;
  4557. te[1] = (xy + wz) * sx;
  4558. te[2] = (xz - wy) * sx;
  4559. te[3] = 0;
  4560. te[4] = (xy - wz) * sy;
  4561. te[5] = (1 - (xx + zz)) * sy;
  4562. te[6] = (yz + wx) * sy;
  4563. te[7] = 0;
  4564. te[8] = (xz + wy) * sz;
  4565. te[9] = (yz - wx) * sz;
  4566. te[10] = (1 - (xx + yy)) * sz;
  4567. te[11] = 0;
  4568. te[12] = position.x;
  4569. te[13] = position.y;
  4570. te[14] = position.z;
  4571. te[15] = 1;
  4572. return this;
  4573. };
  4574. _proto.decompose = function decompose(position, quaternion, scale) {
  4575. var te = this.elements;
  4576. var sx = _v1$1.set(te[0], te[1], te[2]).length();
  4577. var sy = _v1$1.set(te[4], te[5], te[6]).length();
  4578. var sz = _v1$1.set(te[8], te[9], te[10]).length(); // if determine is negative, we need to invert one scale
  4579. var det = this.determinant();
  4580. if (det < 0) sx = -sx;
  4581. position.x = te[12];
  4582. position.y = te[13];
  4583. position.z = te[14]; // scale the rotation part
  4584. _m1.copy(this);
  4585. var invSX = 1 / sx;
  4586. var invSY = 1 / sy;
  4587. var invSZ = 1 / sz;
  4588. _m1.elements[0] *= invSX;
  4589. _m1.elements[1] *= invSX;
  4590. _m1.elements[2] *= invSX;
  4591. _m1.elements[4] *= invSY;
  4592. _m1.elements[5] *= invSY;
  4593. _m1.elements[6] *= invSY;
  4594. _m1.elements[8] *= invSZ;
  4595. _m1.elements[9] *= invSZ;
  4596. _m1.elements[10] *= invSZ;
  4597. quaternion.setFromRotationMatrix(_m1);
  4598. scale.x = sx;
  4599. scale.y = sy;
  4600. scale.z = sz;
  4601. return this;
  4602. };
  4603. _proto.makePerspective = function makePerspective(left, right, top, bottom, near, far) {
  4604. if (far === undefined) {
  4605. console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
  4606. }
  4607. var te = this.elements;
  4608. var x = 2 * near / (right - left);
  4609. var y = 2 * near / (top - bottom);
  4610. var a = (right + left) / (right - left);
  4611. var b = (top + bottom) / (top - bottom);
  4612. var c = -(far + near) / (far - near);
  4613. var d = -2 * far * near / (far - near);
  4614. te[0] = x;
  4615. te[4] = 0;
  4616. te[8] = a;
  4617. te[12] = 0;
  4618. te[1] = 0;
  4619. te[5] = y;
  4620. te[9] = b;
  4621. te[13] = 0;
  4622. te[2] = 0;
  4623. te[6] = 0;
  4624. te[10] = c;
  4625. te[14] = d;
  4626. te[3] = 0;
  4627. te[7] = 0;
  4628. te[11] = -1;
  4629. te[15] = 0;
  4630. return this;
  4631. };
  4632. _proto.makeOrthographic = function makeOrthographic(left, right, top, bottom, near, far) {
  4633. var te = this.elements;
  4634. var w = 1.0 / (right - left);
  4635. var h = 1.0 / (top - bottom);
  4636. var p = 1.0 / (far - near);
  4637. var x = (right + left) * w;
  4638. var y = (top + bottom) * h;
  4639. var z = (far + near) * p;
  4640. te[0] = 2 * w;
  4641. te[4] = 0;
  4642. te[8] = 0;
  4643. te[12] = -x;
  4644. te[1] = 0;
  4645. te[5] = 2 * h;
  4646. te[9] = 0;
  4647. te[13] = -y;
  4648. te[2] = 0;
  4649. te[6] = 0;
  4650. te[10] = -2 * p;
  4651. te[14] = -z;
  4652. te[3] = 0;
  4653. te[7] = 0;
  4654. te[11] = 0;
  4655. te[15] = 1;
  4656. return this;
  4657. };
  4658. _proto.equals = function equals(matrix) {
  4659. var te = this.elements;
  4660. var me = matrix.elements;
  4661. for (var i = 0; i < 16; i++) {
  4662. if (te[i] !== me[i]) return false;
  4663. }
  4664. return true;
  4665. };
  4666. _proto.fromArray = function fromArray(array, offset) {
  4667. if (offset === void 0) {
  4668. offset = 0;
  4669. }
  4670. for (var i = 0; i < 16; i++) {
  4671. this.elements[i] = array[i + offset];
  4672. }
  4673. return this;
  4674. };
  4675. _proto.toArray = function toArray(array, offset) {
  4676. if (array === void 0) {
  4677. array = [];
  4678. }
  4679. if (offset === void 0) {
  4680. offset = 0;
  4681. }
  4682. var te = this.elements;
  4683. array[offset] = te[0];
  4684. array[offset + 1] = te[1];
  4685. array[offset + 2] = te[2];
  4686. array[offset + 3] = te[3];
  4687. array[offset + 4] = te[4];
  4688. array[offset + 5] = te[5];
  4689. array[offset + 6] = te[6];
  4690. array[offset + 7] = te[7];
  4691. array[offset + 8] = te[8];
  4692. array[offset + 9] = te[9];
  4693. array[offset + 10] = te[10];
  4694. array[offset + 11] = te[11];
  4695. array[offset + 12] = te[12];
  4696. array[offset + 13] = te[13];
  4697. array[offset + 14] = te[14];
  4698. array[offset + 15] = te[15];
  4699. return array;
  4700. };
  4701. return Matrix4;
  4702. }();
  4703. var _v1$1 = /*@__PURE__*/new Vector3();
  4704. var _m1 = /*@__PURE__*/new Matrix4();
  4705. var _zero = /*@__PURE__*/new Vector3(0, 0, 0);
  4706. var _one = /*@__PURE__*/new Vector3(1, 1, 1);
  4707. var _x = /*@__PURE__*/new Vector3();
  4708. var _y = /*@__PURE__*/new Vector3();
  4709. var _z = /*@__PURE__*/new Vector3();
  4710. var Euler = /*#__PURE__*/function () {
  4711. function Euler(x, y, z, order) {
  4712. if (x === void 0) {
  4713. x = 0;
  4714. }
  4715. if (y === void 0) {
  4716. y = 0;
  4717. }
  4718. if (z === void 0) {
  4719. z = 0;
  4720. }
  4721. if (order === void 0) {
  4722. order = Euler.DefaultOrder;
  4723. }
  4724. Object.defineProperty(this, 'isEuler', {
  4725. value: true
  4726. });
  4727. this._x = x;
  4728. this._y = y;
  4729. this._z = z;
  4730. this._order = order;
  4731. }
  4732. var _proto = Euler.prototype;
  4733. _proto.set = function set(x, y, z, order) {
  4734. this._x = x;
  4735. this._y = y;
  4736. this._z = z;
  4737. this._order = order || this._order;
  4738. this._onChangeCallback();
  4739. return this;
  4740. };
  4741. _proto.clone = function clone() {
  4742. return new this.constructor(this._x, this._y, this._z, this._order);
  4743. };
  4744. _proto.copy = function copy(euler) {
  4745. this._x = euler._x;
  4746. this._y = euler._y;
  4747. this._z = euler._z;
  4748. this._order = euler._order;
  4749. this._onChangeCallback();
  4750. return this;
  4751. };
  4752. _proto.setFromRotationMatrix = function setFromRotationMatrix(m, order, update) {
  4753. var clamp = MathUtils.clamp; // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4754. var te = m.elements;
  4755. var m11 = te[0],
  4756. m12 = te[4],
  4757. m13 = te[8];
  4758. var m21 = te[1],
  4759. m22 = te[5],
  4760. m23 = te[9];
  4761. var m31 = te[2],
  4762. m32 = te[6],
  4763. m33 = te[10];
  4764. order = order || this._order;
  4765. switch (order) {
  4766. case 'XYZ':
  4767. this._y = Math.asin(clamp(m13, -1, 1));
  4768. if (Math.abs(m13) < 0.9999999) {
  4769. this._x = Math.atan2(-m23, m33);
  4770. this._z = Math.atan2(-m12, m11);
  4771. } else {
  4772. this._x = Math.atan2(m32, m22);
  4773. this._z = 0;
  4774. }
  4775. break;
  4776. case 'YXZ':
  4777. this._x = Math.asin(-clamp(m23, -1, 1));
  4778. if (Math.abs(m23) < 0.9999999) {
  4779. this._y = Math.atan2(m13, m33);
  4780. this._z = Math.atan2(m21, m22);
  4781. } else {
  4782. this._y = Math.atan2(-m31, m11);
  4783. this._z = 0;
  4784. }
  4785. break;
  4786. case 'ZXY':
  4787. this._x = Math.asin(clamp(m32, -1, 1));
  4788. if (Math.abs(m32) < 0.9999999) {
  4789. this._y = Math.atan2(-m31, m33);
  4790. this._z = Math.atan2(-m12, m22);
  4791. } else {
  4792. this._y = 0;
  4793. this._z = Math.atan2(m21, m11);
  4794. }
  4795. break;
  4796. case 'ZYX':
  4797. this._y = Math.asin(-clamp(m31, -1, 1));
  4798. if (Math.abs(m31) < 0.9999999) {
  4799. this._x = Math.atan2(m32, m33);
  4800. this._z = Math.atan2(m21, m11);
  4801. } else {
  4802. this._x = 0;
  4803. this._z = Math.atan2(-m12, m22);
  4804. }
  4805. break;
  4806. case 'YZX':
  4807. this._z = Math.asin(clamp(m21, -1, 1));
  4808. if (Math.abs(m21) < 0.9999999) {
  4809. this._x = Math.atan2(-m23, m22);
  4810. this._y = Math.atan2(-m31, m11);
  4811. } else {
  4812. this._x = 0;
  4813. this._y = Math.atan2(m13, m33);
  4814. }
  4815. break;
  4816. case 'XZY':
  4817. this._z = Math.asin(-clamp(m12, -1, 1));
  4818. if (Math.abs(m12) < 0.9999999) {
  4819. this._x = Math.atan2(m32, m22);
  4820. this._y = Math.atan2(m13, m11);
  4821. } else {
  4822. this._x = Math.atan2(-m23, m33);
  4823. this._y = 0;
  4824. }
  4825. break;
  4826. default:
  4827. console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order);
  4828. }
  4829. this._order = order;
  4830. if (update !== false) this._onChangeCallback();
  4831. return this;
  4832. };
  4833. _proto.setFromQuaternion = function setFromQuaternion(q, order, update) {
  4834. _matrix.makeRotationFromQuaternion(q);
  4835. return this.setFromRotationMatrix(_matrix, order, update);
  4836. };
  4837. _proto.setFromVector3 = function setFromVector3(v, order) {
  4838. return this.set(v.x, v.y, v.z, order || this._order);
  4839. };
  4840. _proto.reorder = function reorder(newOrder) {
  4841. // WARNING: this discards revolution information -bhouston
  4842. _quaternion$1.setFromEuler(this);
  4843. return this.setFromQuaternion(_quaternion$1, newOrder);
  4844. };
  4845. _proto.equals = function equals(euler) {
  4846. return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order;
  4847. };
  4848. _proto.fromArray = function fromArray(array) {
  4849. this._x = array[0];
  4850. this._y = array[1];
  4851. this._z = array[2];
  4852. if (array[3] !== undefined) this._order = array[3];
  4853. this._onChangeCallback();
  4854. return this;
  4855. };
  4856. _proto.toArray = function toArray(array, offset) {
  4857. if (array === void 0) {
  4858. array = [];
  4859. }
  4860. if (offset === void 0) {
  4861. offset = 0;
  4862. }
  4863. array[offset] = this._x;
  4864. array[offset + 1] = this._y;
  4865. array[offset + 2] = this._z;
  4866. array[offset + 3] = this._order;
  4867. return array;
  4868. };
  4869. _proto.toVector3 = function toVector3(optionalResult) {
  4870. if (optionalResult) {
  4871. return optionalResult.set(this._x, this._y, this._z);
  4872. } else {
  4873. return new Vector3(this._x, this._y, this._z);
  4874. }
  4875. };
  4876. _proto._onChange = function _onChange(callback) {
  4877. this._onChangeCallback = callback;
  4878. return this;
  4879. };
  4880. _proto._onChangeCallback = function _onChangeCallback() {};
  4881. _createClass(Euler, [{
  4882. key: "x",
  4883. get: function get() {
  4884. return this._x;
  4885. },
  4886. set: function set(value) {
  4887. this._x = value;
  4888. this._onChangeCallback();
  4889. }
  4890. }, {
  4891. key: "y",
  4892. get: function get() {
  4893. return this._y;
  4894. },
  4895. set: function set(value) {
  4896. this._y = value;
  4897. this._onChangeCallback();
  4898. }
  4899. }, {
  4900. key: "z",
  4901. get: function get() {
  4902. return this._z;
  4903. },
  4904. set: function set(value) {
  4905. this._z = value;
  4906. this._onChangeCallback();
  4907. }
  4908. }, {
  4909. key: "order",
  4910. get: function get() {
  4911. return this._order;
  4912. },
  4913. set: function set(value) {
  4914. this._order = value;
  4915. this._onChangeCallback();
  4916. }
  4917. }]);
  4918. return Euler;
  4919. }();
  4920. Euler.DefaultOrder = 'XYZ';
  4921. Euler.RotationOrders = ['XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX'];
  4922. var _matrix = /*@__PURE__*/new Matrix4();
  4923. var _quaternion$1 = /*@__PURE__*/new Quaternion();
  4924. var Layers = /*#__PURE__*/function () {
  4925. function Layers() {
  4926. this.mask = 1 | 0;
  4927. }
  4928. var _proto = Layers.prototype;
  4929. _proto.set = function set(channel) {
  4930. this.mask = 1 << channel | 0;
  4931. };
  4932. _proto.enable = function enable(channel) {
  4933. this.mask |= 1 << channel | 0;
  4934. };
  4935. _proto.enableAll = function enableAll() {
  4936. this.mask = 0xffffffff | 0;
  4937. };
  4938. _proto.toggle = function toggle(channel) {
  4939. this.mask ^= 1 << channel | 0;
  4940. };
  4941. _proto.disable = function disable(channel) {
  4942. this.mask &= ~(1 << channel | 0);
  4943. };
  4944. _proto.disableAll = function disableAll() {
  4945. this.mask = 0;
  4946. };
  4947. _proto.test = function test(layers) {
  4948. return (this.mask & layers.mask) !== 0;
  4949. };
  4950. return Layers;
  4951. }();
  4952. var _object3DId = 0;
  4953. var _v1$2 = new Vector3();
  4954. var _q1 = new Quaternion();
  4955. var _m1$1 = new Matrix4();
  4956. var _target = new Vector3();
  4957. var _position = new Vector3();
  4958. var _scale = new Vector3();
  4959. var _quaternion$2 = new Quaternion();
  4960. var _xAxis = new Vector3(1, 0, 0);
  4961. var _yAxis = new Vector3(0, 1, 0);
  4962. var _zAxis = new Vector3(0, 0, 1);
  4963. var _addedEvent = {
  4964. type: 'added'
  4965. };
  4966. var _removedEvent = {
  4967. type: 'removed'
  4968. };
  4969. function Object3D() {
  4970. Object.defineProperty(this, 'id', {
  4971. value: _object3DId++
  4972. });
  4973. this.uuid = MathUtils.generateUUID();
  4974. this.name = '';
  4975. this.type = 'Object3D';
  4976. this.parent = null;
  4977. this.children = [];
  4978. this.up = Object3D.DefaultUp.clone();
  4979. var position = new Vector3();
  4980. var rotation = new Euler();
  4981. var quaternion = new Quaternion();
  4982. var scale = new Vector3(1, 1, 1);
  4983. function onRotationChange() {
  4984. quaternion.setFromEuler(rotation, false);
  4985. }
  4986. function onQuaternionChange() {
  4987. rotation.setFromQuaternion(quaternion, undefined, false);
  4988. }
  4989. rotation._onChange(onRotationChange);
  4990. quaternion._onChange(onQuaternionChange);
  4991. Object.defineProperties(this, {
  4992. position: {
  4993. configurable: true,
  4994. enumerable: true,
  4995. value: position
  4996. },
  4997. rotation: {
  4998. configurable: true,
  4999. enumerable: true,
  5000. value: rotation
  5001. },
  5002. quaternion: {
  5003. configurable: true,
  5004. enumerable: true,
  5005. value: quaternion
  5006. },
  5007. scale: {
  5008. configurable: true,
  5009. enumerable: true,
  5010. value: scale
  5011. },
  5012. modelViewMatrix: {
  5013. value: new Matrix4()
  5014. },
  5015. normalMatrix: {
  5016. value: new Matrix3()
  5017. }
  5018. });
  5019. this.matrix = new Matrix4();
  5020. this.matrixWorld = new Matrix4();
  5021. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5022. this.matrixWorldNeedsUpdate = false;
  5023. this.layers = new Layers();
  5024. this.visible = true;
  5025. this.castShadow = false;
  5026. this.receiveShadow = false;
  5027. this.frustumCulled = true;
  5028. this.renderOrder = 0;
  5029. this.animations = [];
  5030. this.userData = {};
  5031. }
  5032. Object3D.DefaultUp = new Vector3(0, 1, 0);
  5033. Object3D.DefaultMatrixAutoUpdate = true;
  5034. Object3D.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  5035. constructor: Object3D,
  5036. isObject3D: true,
  5037. onBeforeRender: function onBeforeRender() {},
  5038. onAfterRender: function onAfterRender() {},
  5039. applyMatrix4: function applyMatrix4(matrix) {
  5040. if (this.matrixAutoUpdate) this.updateMatrix();
  5041. this.matrix.premultiply(matrix);
  5042. this.matrix.decompose(this.position, this.quaternion, this.scale);
  5043. },
  5044. applyQuaternion: function applyQuaternion(q) {
  5045. this.quaternion.premultiply(q);
  5046. return this;
  5047. },
  5048. setRotationFromAxisAngle: function setRotationFromAxisAngle(axis, angle) {
  5049. // assumes axis is normalized
  5050. this.quaternion.setFromAxisAngle(axis, angle);
  5051. },
  5052. setRotationFromEuler: function setRotationFromEuler(euler) {
  5053. this.quaternion.setFromEuler(euler, true);
  5054. },
  5055. setRotationFromMatrix: function setRotationFromMatrix(m) {
  5056. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5057. this.quaternion.setFromRotationMatrix(m);
  5058. },
  5059. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  5060. // assumes q is normalized
  5061. this.quaternion.copy(q);
  5062. },
  5063. rotateOnAxis: function rotateOnAxis(axis, angle) {
  5064. // rotate object on axis in object space
  5065. // axis is assumed to be normalized
  5066. _q1.setFromAxisAngle(axis, angle);
  5067. this.quaternion.multiply(_q1);
  5068. return this;
  5069. },
  5070. rotateOnWorldAxis: function rotateOnWorldAxis(axis, angle) {
  5071. // rotate object on axis in world space
  5072. // axis is assumed to be normalized
  5073. // method assumes no rotated parent
  5074. _q1.setFromAxisAngle(axis, angle);
  5075. this.quaternion.premultiply(_q1);
  5076. return this;
  5077. },
  5078. rotateX: function rotateX(angle) {
  5079. return this.rotateOnAxis(_xAxis, angle);
  5080. },
  5081. rotateY: function rotateY(angle) {
  5082. return this.rotateOnAxis(_yAxis, angle);
  5083. },
  5084. rotateZ: function rotateZ(angle) {
  5085. return this.rotateOnAxis(_zAxis, angle);
  5086. },
  5087. translateOnAxis: function translateOnAxis(axis, distance) {
  5088. // translate object by distance along axis in object space
  5089. // axis is assumed to be normalized
  5090. _v1$2.copy(axis).applyQuaternion(this.quaternion);
  5091. this.position.add(_v1$2.multiplyScalar(distance));
  5092. return this;
  5093. },
  5094. translateX: function translateX(distance) {
  5095. return this.translateOnAxis(_xAxis, distance);
  5096. },
  5097. translateY: function translateY(distance) {
  5098. return this.translateOnAxis(_yAxis, distance);
  5099. },
  5100. translateZ: function translateZ(distance) {
  5101. return this.translateOnAxis(_zAxis, distance);
  5102. },
  5103. localToWorld: function localToWorld(vector) {
  5104. return vector.applyMatrix4(this.matrixWorld);
  5105. },
  5106. worldToLocal: function worldToLocal(vector) {
  5107. return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert());
  5108. },
  5109. lookAt: function lookAt(x, y, z) {
  5110. // This method does not support objects having non-uniformly-scaled parent(s)
  5111. if (x.isVector3) {
  5112. _target.copy(x);
  5113. } else {
  5114. _target.set(x, y, z);
  5115. }
  5116. var parent = this.parent;
  5117. this.updateWorldMatrix(true, false);
  5118. _position.setFromMatrixPosition(this.matrixWorld);
  5119. if (this.isCamera || this.isLight) {
  5120. _m1$1.lookAt(_position, _target, this.up);
  5121. } else {
  5122. _m1$1.lookAt(_target, _position, this.up);
  5123. }
  5124. this.quaternion.setFromRotationMatrix(_m1$1);
  5125. if (parent) {
  5126. _m1$1.extractRotation(parent.matrixWorld);
  5127. _q1.setFromRotationMatrix(_m1$1);
  5128. this.quaternion.premultiply(_q1.invert());
  5129. }
  5130. },
  5131. add: function add(object) {
  5132. if (arguments.length > 1) {
  5133. for (var i = 0; i < arguments.length; i++) {
  5134. this.add(arguments[i]);
  5135. }
  5136. return this;
  5137. }
  5138. if (object === this) {
  5139. console.error('THREE.Object3D.add: object can\'t be added as a child of itself.', object);
  5140. return this;
  5141. }
  5142. if (object && object.isObject3D) {
  5143. if (object.parent !== null) {
  5144. object.parent.remove(object);
  5145. }
  5146. object.parent = this;
  5147. this.children.push(object);
  5148. object.dispatchEvent(_addedEvent);
  5149. } else {
  5150. console.error('THREE.Object3D.add: object not an instance of THREE.Object3D.', object);
  5151. }
  5152. return this;
  5153. },
  5154. remove: function remove(object) {
  5155. if (arguments.length > 1) {
  5156. for (var i = 0; i < arguments.length; i++) {
  5157. this.remove(arguments[i]);
  5158. }
  5159. return this;
  5160. }
  5161. var index = this.children.indexOf(object);
  5162. if (index !== -1) {
  5163. object.parent = null;
  5164. this.children.splice(index, 1);
  5165. object.dispatchEvent(_removedEvent);
  5166. }
  5167. return this;
  5168. },
  5169. clear: function clear() {
  5170. for (var i = 0; i < this.children.length; i++) {
  5171. var object = this.children[i];
  5172. object.parent = null;
  5173. object.dispatchEvent(_removedEvent);
  5174. }
  5175. this.children.length = 0;
  5176. return this;
  5177. },
  5178. attach: function attach(object) {
  5179. // adds object as a child of this, while maintaining the object's world transform
  5180. this.updateWorldMatrix(true, false);
  5181. _m1$1.copy(this.matrixWorld).invert();
  5182. if (object.parent !== null) {
  5183. object.parent.updateWorldMatrix(true, false);
  5184. _m1$1.multiply(object.parent.matrixWorld);
  5185. }
  5186. object.applyMatrix4(_m1$1);
  5187. object.updateWorldMatrix(false, false);
  5188. this.add(object);
  5189. return this;
  5190. },
  5191. getObjectById: function getObjectById(id) {
  5192. return this.getObjectByProperty('id', id);
  5193. },
  5194. getObjectByName: function getObjectByName(name) {
  5195. return this.getObjectByProperty('name', name);
  5196. },
  5197. getObjectByProperty: function getObjectByProperty(name, value) {
  5198. if (this[name] === value) return this;
  5199. for (var i = 0, l = this.children.length; i < l; i++) {
  5200. var child = this.children[i];
  5201. var object = child.getObjectByProperty(name, value);
  5202. if (object !== undefined) {
  5203. return object;
  5204. }
  5205. }
  5206. return undefined;
  5207. },
  5208. getWorldPosition: function getWorldPosition(target) {
  5209. if (target === undefined) {
  5210. console.warn('THREE.Object3D: .getWorldPosition() target is now required');
  5211. target = new Vector3();
  5212. }
  5213. this.updateWorldMatrix(true, false);
  5214. return target.setFromMatrixPosition(this.matrixWorld);
  5215. },
  5216. getWorldQuaternion: function getWorldQuaternion(target) {
  5217. if (target === undefined) {
  5218. console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');
  5219. target = new Quaternion();
  5220. }
  5221. this.updateWorldMatrix(true, false);
  5222. this.matrixWorld.decompose(_position, target, _scale);
  5223. return target;
  5224. },
  5225. getWorldScale: function getWorldScale(target) {
  5226. if (target === undefined) {
  5227. console.warn('THREE.Object3D: .getWorldScale() target is now required');
  5228. target = new Vector3();
  5229. }
  5230. this.updateWorldMatrix(true, false);
  5231. this.matrixWorld.decompose(_position, _quaternion$2, target);
  5232. return target;
  5233. },
  5234. getWorldDirection: function getWorldDirection(target) {
  5235. if (target === undefined) {
  5236. console.warn('THREE.Object3D: .getWorldDirection() target is now required');
  5237. target = new Vector3();
  5238. }
  5239. this.updateWorldMatrix(true, false);
  5240. var e = this.matrixWorld.elements;
  5241. return target.set(e[8], e[9], e[10]).normalize();
  5242. },
  5243. raycast: function raycast() {},
  5244. traverse: function traverse(callback) {
  5245. callback(this);
  5246. var children = this.children;
  5247. for (var i = 0, l = children.length; i < l; i++) {
  5248. children[i].traverse(callback);
  5249. }
  5250. },
  5251. traverseVisible: function traverseVisible(callback) {
  5252. if (this.visible === false) return;
  5253. callback(this);
  5254. var children = this.children;
  5255. for (var i = 0, l = children.length; i < l; i++) {
  5256. children[i].traverseVisible(callback);
  5257. }
  5258. },
  5259. traverseAncestors: function traverseAncestors(callback) {
  5260. var parent = this.parent;
  5261. if (parent !== null) {
  5262. callback(parent);
  5263. parent.traverseAncestors(callback);
  5264. }
  5265. },
  5266. updateMatrix: function updateMatrix() {
  5267. this.matrix.compose(this.position, this.quaternion, this.scale);
  5268. this.matrixWorldNeedsUpdate = true;
  5269. },
  5270. updateMatrixWorld: function updateMatrixWorld(force) {
  5271. if (this.matrixAutoUpdate) this.updateMatrix();
  5272. if (this.matrixWorldNeedsUpdate || force) {
  5273. if (this.parent === null) {
  5274. this.matrixWorld.copy(this.matrix);
  5275. } else {
  5276. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5277. }
  5278. this.matrixWorldNeedsUpdate = false;
  5279. force = true;
  5280. } // update children
  5281. var children = this.children;
  5282. for (var i = 0, l = children.length; i < l; i++) {
  5283. children[i].updateMatrixWorld(force);
  5284. }
  5285. },
  5286. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  5287. var parent = this.parent;
  5288. if (updateParents === true && parent !== null) {
  5289. parent.updateWorldMatrix(true, false);
  5290. }
  5291. if (this.matrixAutoUpdate) this.updateMatrix();
  5292. if (this.parent === null) {
  5293. this.matrixWorld.copy(this.matrix);
  5294. } else {
  5295. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  5296. } // update children
  5297. if (updateChildren === true) {
  5298. var children = this.children;
  5299. for (var i = 0, l = children.length; i < l; i++) {
  5300. children[i].updateWorldMatrix(false, true);
  5301. }
  5302. }
  5303. },
  5304. toJSON: function toJSON(meta) {
  5305. // meta is a string when called from JSON.stringify
  5306. var isRootObject = meta === undefined || typeof meta === 'string';
  5307. var output = {}; // meta is a hash used to collect geometries, materials.
  5308. // not providing it implies that this is the root object
  5309. // being serialized.
  5310. if (isRootObject) {
  5311. // initialize meta obj
  5312. meta = {
  5313. geometries: {},
  5314. materials: {},
  5315. textures: {},
  5316. images: {},
  5317. shapes: {},
  5318. skeletons: {},
  5319. animations: {}
  5320. };
  5321. output.metadata = {
  5322. version: 4.5,
  5323. type: 'Object',
  5324. generator: 'Object3D.toJSON'
  5325. };
  5326. } // standard Object3D serialization
  5327. var object = {};
  5328. object.uuid = this.uuid;
  5329. object.type = this.type;
  5330. if (this.name !== '') object.name = this.name;
  5331. if (this.castShadow === true) object.castShadow = true;
  5332. if (this.receiveShadow === true) object.receiveShadow = true;
  5333. if (this.visible === false) object.visible = false;
  5334. if (this.frustumCulled === false) object.frustumCulled = false;
  5335. if (this.renderOrder !== 0) object.renderOrder = this.renderOrder;
  5336. if (JSON.stringify(this.userData) !== '{}') object.userData = this.userData;
  5337. object.layers = this.layers.mask;
  5338. object.matrix = this.matrix.toArray();
  5339. if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; // object specific properties
  5340. if (this.isInstancedMesh) {
  5341. object.type = 'InstancedMesh';
  5342. object.count = this.count;
  5343. object.instanceMatrix = this.instanceMatrix.toJSON();
  5344. } //
  5345. function serialize(library, element) {
  5346. if (library[element.uuid] === undefined) {
  5347. library[element.uuid] = element.toJSON(meta);
  5348. }
  5349. return element.uuid;
  5350. }
  5351. if (this.isMesh || this.isLine || this.isPoints) {
  5352. object.geometry = serialize(meta.geometries, this.geometry);
  5353. var parameters = this.geometry.parameters;
  5354. if (parameters !== undefined && parameters.shapes !== undefined) {
  5355. var shapes = parameters.shapes;
  5356. if (Array.isArray(shapes)) {
  5357. for (var i = 0, l = shapes.length; i < l; i++) {
  5358. var shape = shapes[i];
  5359. serialize(meta.shapes, shape);
  5360. }
  5361. } else {
  5362. serialize(meta.shapes, shapes);
  5363. }
  5364. }
  5365. }
  5366. if (this.isSkinnedMesh) {
  5367. object.bindMode = this.bindMode;
  5368. object.bindMatrix = this.bindMatrix.toArray();
  5369. if (this.skeleton !== undefined) {
  5370. serialize(meta.skeletons, this.skeleton);
  5371. object.skeleton = this.skeleton.uuid;
  5372. }
  5373. }
  5374. if (this.material !== undefined) {
  5375. if (Array.isArray(this.material)) {
  5376. var uuids = [];
  5377. for (var _i = 0, _l = this.material.length; _i < _l; _i++) {
  5378. uuids.push(serialize(meta.materials, this.material[_i]));
  5379. }
  5380. object.material = uuids;
  5381. } else {
  5382. object.material = serialize(meta.materials, this.material);
  5383. }
  5384. } //
  5385. if (this.children.length > 0) {
  5386. object.children = [];
  5387. for (var _i2 = 0; _i2 < this.children.length; _i2++) {
  5388. object.children.push(this.children[_i2].toJSON(meta).object);
  5389. }
  5390. } //
  5391. if (this.animations.length > 0) {
  5392. object.animations = [];
  5393. for (var _i3 = 0; _i3 < this.animations.length; _i3++) {
  5394. var animation = this.animations[_i3];
  5395. object.animations.push(serialize(meta.animations, animation));
  5396. }
  5397. }
  5398. if (isRootObject) {
  5399. var geometries = extractFromCache(meta.geometries);
  5400. var materials = extractFromCache(meta.materials);
  5401. var textures = extractFromCache(meta.textures);
  5402. var images = extractFromCache(meta.images);
  5403. var _shapes = extractFromCache(meta.shapes);
  5404. var skeletons = extractFromCache(meta.skeletons);
  5405. var animations = extractFromCache(meta.animations);
  5406. if (geometries.length > 0) output.geometries = geometries;
  5407. if (materials.length > 0) output.materials = materials;
  5408. if (textures.length > 0) output.textures = textures;
  5409. if (images.length > 0) output.images = images;
  5410. if (_shapes.length > 0) output.shapes = _shapes;
  5411. if (skeletons.length > 0) output.skeletons = skeletons;
  5412. if (animations.length > 0) output.animations = animations;
  5413. }
  5414. output.object = object;
  5415. return output; // extract data from the cache hash
  5416. // remove metadata on each item
  5417. // and return as array
  5418. function extractFromCache(cache) {
  5419. var values = [];
  5420. for (var key in cache) {
  5421. var data = cache[key];
  5422. delete data.metadata;
  5423. values.push(data);
  5424. }
  5425. return values;
  5426. }
  5427. },
  5428. clone: function clone(recursive) {
  5429. return new this.constructor().copy(this, recursive);
  5430. },
  5431. copy: function copy(source, recursive) {
  5432. if (recursive === void 0) {
  5433. recursive = true;
  5434. }
  5435. this.name = source.name;
  5436. this.up.copy(source.up);
  5437. this.position.copy(source.position);
  5438. this.rotation.order = source.rotation.order;
  5439. this.quaternion.copy(source.quaternion);
  5440. this.scale.copy(source.scale);
  5441. this.matrix.copy(source.matrix);
  5442. this.matrixWorld.copy(source.matrixWorld);
  5443. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5444. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5445. this.layers.mask = source.layers.mask;
  5446. this.visible = source.visible;
  5447. this.castShadow = source.castShadow;
  5448. this.receiveShadow = source.receiveShadow;
  5449. this.frustumCulled = source.frustumCulled;
  5450. this.renderOrder = source.renderOrder;
  5451. this.userData = JSON.parse(JSON.stringify(source.userData));
  5452. if (recursive === true) {
  5453. for (var i = 0; i < source.children.length; i++) {
  5454. var child = source.children[i];
  5455. this.add(child.clone());
  5456. }
  5457. }
  5458. return this;
  5459. }
  5460. });
  5461. var _vector1 = /*@__PURE__*/new Vector3();
  5462. var _vector2 = /*@__PURE__*/new Vector3();
  5463. var _normalMatrix = /*@__PURE__*/new Matrix3();
  5464. var Plane = /*#__PURE__*/function () {
  5465. function Plane(normal, constant) {
  5466. Object.defineProperty(this, 'isPlane', {
  5467. value: true
  5468. }); // normal is assumed to be normalized
  5469. this.normal = normal !== undefined ? normal : new Vector3(1, 0, 0);
  5470. this.constant = constant !== undefined ? constant : 0;
  5471. }
  5472. var _proto = Plane.prototype;
  5473. _proto.set = function set(normal, constant) {
  5474. this.normal.copy(normal);
  5475. this.constant = constant;
  5476. return this;
  5477. };
  5478. _proto.setComponents = function setComponents(x, y, z, w) {
  5479. this.normal.set(x, y, z);
  5480. this.constant = w;
  5481. return this;
  5482. };
  5483. _proto.setFromNormalAndCoplanarPoint = function setFromNormalAndCoplanarPoint(normal, point) {
  5484. this.normal.copy(normal);
  5485. this.constant = -point.dot(this.normal);
  5486. return this;
  5487. };
  5488. _proto.setFromCoplanarPoints = function setFromCoplanarPoints(a, b, c) {
  5489. 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)?
  5490. this.setFromNormalAndCoplanarPoint(normal, a);
  5491. return this;
  5492. };
  5493. _proto.clone = function clone() {
  5494. return new this.constructor().copy(this);
  5495. };
  5496. _proto.copy = function copy(plane) {
  5497. this.normal.copy(plane.normal);
  5498. this.constant = plane.constant;
  5499. return this;
  5500. };
  5501. _proto.normalize = function normalize() {
  5502. // Note: will lead to a divide by zero if the plane is invalid.
  5503. var inverseNormalLength = 1.0 / this.normal.length();
  5504. this.normal.multiplyScalar(inverseNormalLength);
  5505. this.constant *= inverseNormalLength;
  5506. return this;
  5507. };
  5508. _proto.negate = function negate() {
  5509. this.constant *= -1;
  5510. this.normal.negate();
  5511. return this;
  5512. };
  5513. _proto.distanceToPoint = function distanceToPoint(point) {
  5514. return this.normal.dot(point) + this.constant;
  5515. };
  5516. _proto.distanceToSphere = function distanceToSphere(sphere) {
  5517. return this.distanceToPoint(sphere.center) - sphere.radius;
  5518. };
  5519. _proto.projectPoint = function projectPoint(point, target) {
  5520. if (target === undefined) {
  5521. console.warn('THREE.Plane: .projectPoint() target is now required');
  5522. target = new Vector3();
  5523. }
  5524. return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);
  5525. };
  5526. _proto.intersectLine = function intersectLine(line, target) {
  5527. if (target === undefined) {
  5528. console.warn('THREE.Plane: .intersectLine() target is now required');
  5529. target = new Vector3();
  5530. }
  5531. var direction = line.delta(_vector1);
  5532. var denominator = this.normal.dot(direction);
  5533. if (denominator === 0) {
  5534. // line is coplanar, return origin
  5535. if (this.distanceToPoint(line.start) === 0) {
  5536. return target.copy(line.start);
  5537. } // Unsure if this is the correct method to handle this case.
  5538. return undefined;
  5539. }
  5540. var t = -(line.start.dot(this.normal) + this.constant) / denominator;
  5541. if (t < 0 || t > 1) {
  5542. return undefined;
  5543. }
  5544. return target.copy(direction).multiplyScalar(t).add(line.start);
  5545. };
  5546. _proto.intersectsLine = function intersectsLine(line) {
  5547. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  5548. var startSign = this.distanceToPoint(line.start);
  5549. var endSign = this.distanceToPoint(line.end);
  5550. return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0;
  5551. };
  5552. _proto.intersectsBox = function intersectsBox(box) {
  5553. return box.intersectsPlane(this);
  5554. };
  5555. _proto.intersectsSphere = function intersectsSphere(sphere) {
  5556. return sphere.intersectsPlane(this);
  5557. };
  5558. _proto.coplanarPoint = function coplanarPoint(target) {
  5559. if (target === undefined) {
  5560. console.warn('THREE.Plane: .coplanarPoint() target is now required');
  5561. target = new Vector3();
  5562. }
  5563. return target.copy(this.normal).multiplyScalar(-this.constant);
  5564. };
  5565. _proto.applyMatrix4 = function applyMatrix4(matrix, optionalNormalMatrix) {
  5566. var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix);
  5567. var referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix);
  5568. var normal = this.normal.applyMatrix3(normalMatrix).normalize();
  5569. this.constant = -referencePoint.dot(normal);
  5570. return this;
  5571. };
  5572. _proto.translate = function translate(offset) {
  5573. this.constant -= offset.dot(this.normal);
  5574. return this;
  5575. };
  5576. _proto.equals = function equals(plane) {
  5577. return plane.normal.equals(this.normal) && plane.constant === this.constant;
  5578. };
  5579. return Plane;
  5580. }();
  5581. var _v0$1 = /*@__PURE__*/new Vector3();
  5582. var _v1$3 = /*@__PURE__*/new Vector3();
  5583. var _v2$1 = /*@__PURE__*/new Vector3();
  5584. var _v3 = /*@__PURE__*/new Vector3();
  5585. var _vab = /*@__PURE__*/new Vector3();
  5586. var _vac = /*@__PURE__*/new Vector3();
  5587. var _vbc = /*@__PURE__*/new Vector3();
  5588. var _vap = /*@__PURE__*/new Vector3();
  5589. var _vbp = /*@__PURE__*/new Vector3();
  5590. var _vcp = /*@__PURE__*/new Vector3();
  5591. var Triangle = /*#__PURE__*/function () {
  5592. function Triangle(a, b, c) {
  5593. this.a = a !== undefined ? a : new Vector3();
  5594. this.b = b !== undefined ? b : new Vector3();
  5595. this.c = c !== undefined ? c : new Vector3();
  5596. }
  5597. Triangle.getNormal = function getNormal(a, b, c, target) {
  5598. if (target === undefined) {
  5599. console.warn('THREE.Triangle: .getNormal() target is now required');
  5600. target = new Vector3();
  5601. }
  5602. target.subVectors(c, b);
  5603. _v0$1.subVectors(a, b);
  5604. target.cross(_v0$1);
  5605. var targetLengthSq = target.lengthSq();
  5606. if (targetLengthSq > 0) {
  5607. return target.multiplyScalar(1 / Math.sqrt(targetLengthSq));
  5608. }
  5609. return target.set(0, 0, 0);
  5610. } // static/instance method to calculate barycentric coordinates
  5611. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  5612. ;
  5613. Triangle.getBarycoord = function getBarycoord(point, a, b, c, target) {
  5614. _v0$1.subVectors(c, a);
  5615. _v1$3.subVectors(b, a);
  5616. _v2$1.subVectors(point, a);
  5617. var dot00 = _v0$1.dot(_v0$1);
  5618. var dot01 = _v0$1.dot(_v1$3);
  5619. var dot02 = _v0$1.dot(_v2$1);
  5620. var dot11 = _v1$3.dot(_v1$3);
  5621. var dot12 = _v1$3.dot(_v2$1);
  5622. var denom = dot00 * dot11 - dot01 * dot01;
  5623. if (target === undefined) {
  5624. console.warn('THREE.Triangle: .getBarycoord() target is now required');
  5625. target = new Vector3();
  5626. } // collinear or singular triangle
  5627. if (denom === 0) {
  5628. // arbitrary location outside of triangle?
  5629. // not sure if this is the best idea, maybe should be returning undefined
  5630. return target.set(-2, -1, -1);
  5631. }
  5632. var invDenom = 1 / denom;
  5633. var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  5634. var v = (dot00 * dot12 - dot01 * dot02) * invDenom; // barycentric coordinates must always sum to 1
  5635. return target.set(1 - u - v, v, u);
  5636. };
  5637. Triangle.containsPoint = function containsPoint(point, a, b, c) {
  5638. this.getBarycoord(point, a, b, c, _v3);
  5639. return _v3.x >= 0 && _v3.y >= 0 && _v3.x + _v3.y <= 1;
  5640. };
  5641. Triangle.getUV = function getUV(point, p1, p2, p3, uv1, uv2, uv3, target) {
  5642. this.getBarycoord(point, p1, p2, p3, _v3);
  5643. target.set(0, 0);
  5644. target.addScaledVector(uv1, _v3.x);
  5645. target.addScaledVector(uv2, _v3.y);
  5646. target.addScaledVector(uv3, _v3.z);
  5647. return target;
  5648. };
  5649. Triangle.isFrontFacing = function isFrontFacing(a, b, c, direction) {
  5650. _v0$1.subVectors(c, b);
  5651. _v1$3.subVectors(a, b); // strictly front facing
  5652. return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false;
  5653. };
  5654. var _proto = Triangle.prototype;
  5655. _proto.set = function set(a, b, c) {
  5656. this.a.copy(a);
  5657. this.b.copy(b);
  5658. this.c.copy(c);
  5659. return this;
  5660. };
  5661. _proto.setFromPointsAndIndices = function setFromPointsAndIndices(points, i0, i1, i2) {
  5662. this.a.copy(points[i0]);
  5663. this.b.copy(points[i1]);
  5664. this.c.copy(points[i2]);
  5665. return this;
  5666. };
  5667. _proto.clone = function clone() {
  5668. return new this.constructor().copy(this);
  5669. };
  5670. _proto.copy = function copy(triangle) {
  5671. this.a.copy(triangle.a);
  5672. this.b.copy(triangle.b);
  5673. this.c.copy(triangle.c);
  5674. return this;
  5675. };
  5676. _proto.getArea = function getArea() {
  5677. _v0$1.subVectors(this.c, this.b);
  5678. _v1$3.subVectors(this.a, this.b);
  5679. return _v0$1.cross(_v1$3).length() * 0.5;
  5680. };
  5681. _proto.getMidpoint = function getMidpoint(target) {
  5682. if (target === undefined) {
  5683. console.warn('THREE.Triangle: .getMidpoint() target is now required');
  5684. target = new Vector3();
  5685. }
  5686. return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3);
  5687. };
  5688. _proto.getNormal = function getNormal(target) {
  5689. return Triangle.getNormal(this.a, this.b, this.c, target);
  5690. };
  5691. _proto.getPlane = function getPlane(target) {
  5692. if (target === undefined) {
  5693. console.warn('THREE.Triangle: .getPlane() target is now required');
  5694. target = new Plane();
  5695. }
  5696. return target.setFromCoplanarPoints(this.a, this.b, this.c);
  5697. };
  5698. _proto.getBarycoord = function getBarycoord(point, target) {
  5699. return Triangle.getBarycoord(point, this.a, this.b, this.c, target);
  5700. };
  5701. _proto.getUV = function getUV(point, uv1, uv2, uv3, target) {
  5702. return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, target);
  5703. };
  5704. _proto.containsPoint = function containsPoint(point) {
  5705. return Triangle.containsPoint(point, this.a, this.b, this.c);
  5706. };
  5707. _proto.isFrontFacing = function isFrontFacing(direction) {
  5708. return Triangle.isFrontFacing(this.a, this.b, this.c, direction);
  5709. };
  5710. _proto.intersectsBox = function intersectsBox(box) {
  5711. return box.intersectsTriangle(this);
  5712. };
  5713. _proto.closestPointToPoint = function closestPointToPoint(p, target) {
  5714. if (target === undefined) {
  5715. console.warn('THREE.Triangle: .closestPointToPoint() target is now required');
  5716. target = new Vector3();
  5717. }
  5718. var a = this.a,
  5719. b = this.b,
  5720. c = this.c;
  5721. var v, w; // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5722. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5723. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5724. // basically, we're distinguishing which of the voronoi regions of the triangle
  5725. // the point lies in with the minimum amount of redundant computation.
  5726. _vab.subVectors(b, a);
  5727. _vac.subVectors(c, a);
  5728. _vap.subVectors(p, a);
  5729. var d1 = _vab.dot(_vap);
  5730. var d2 = _vac.dot(_vap);
  5731. if (d1 <= 0 && d2 <= 0) {
  5732. // vertex region of A; barycentric coords (1, 0, 0)
  5733. return target.copy(a);
  5734. }
  5735. _vbp.subVectors(p, b);
  5736. var d3 = _vab.dot(_vbp);
  5737. var d4 = _vac.dot(_vbp);
  5738. if (d3 >= 0 && d4 <= d3) {
  5739. // vertex region of B; barycentric coords (0, 1, 0)
  5740. return target.copy(b);
  5741. }
  5742. var vc = d1 * d4 - d3 * d2;
  5743. if (vc <= 0 && d1 >= 0 && d3 <= 0) {
  5744. v = d1 / (d1 - d3); // edge region of AB; barycentric coords (1-v, v, 0)
  5745. return target.copy(a).addScaledVector(_vab, v);
  5746. }
  5747. _vcp.subVectors(p, c);
  5748. var d5 = _vab.dot(_vcp);
  5749. var d6 = _vac.dot(_vcp);
  5750. if (d6 >= 0 && d5 <= d6) {
  5751. // vertex region of C; barycentric coords (0, 0, 1)
  5752. return target.copy(c);
  5753. }
  5754. var vb = d5 * d2 - d1 * d6;
  5755. if (vb <= 0 && d2 >= 0 && d6 <= 0) {
  5756. w = d2 / (d2 - d6); // edge region of AC; barycentric coords (1-w, 0, w)
  5757. return target.copy(a).addScaledVector(_vac, w);
  5758. }
  5759. var va = d3 * d6 - d5 * d4;
  5760. if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
  5761. _vbc.subVectors(c, b);
  5762. w = (d4 - d3) / (d4 - d3 + (d5 - d6)); // edge region of BC; barycentric coords (0, 1-w, w)
  5763. return target.copy(b).addScaledVector(_vbc, w); // edge region of BC
  5764. } // face region
  5765. var denom = 1 / (va + vb + vc); // u = va * denom
  5766. v = vb * denom;
  5767. w = vc * denom;
  5768. return target.copy(a).addScaledVector(_vab, v).addScaledVector(_vac, w);
  5769. };
  5770. _proto.equals = function equals(triangle) {
  5771. return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c);
  5772. };
  5773. return Triangle;
  5774. }();
  5775. var _colorKeywords = {
  5776. 'aliceblue': 0xF0F8FF,
  5777. 'antiquewhite': 0xFAEBD7,
  5778. 'aqua': 0x00FFFF,
  5779. 'aquamarine': 0x7FFFD4,
  5780. 'azure': 0xF0FFFF,
  5781. 'beige': 0xF5F5DC,
  5782. 'bisque': 0xFFE4C4,
  5783. 'black': 0x000000,
  5784. 'blanchedalmond': 0xFFEBCD,
  5785. 'blue': 0x0000FF,
  5786. 'blueviolet': 0x8A2BE2,
  5787. 'brown': 0xA52A2A,
  5788. 'burlywood': 0xDEB887,
  5789. 'cadetblue': 0x5F9EA0,
  5790. 'chartreuse': 0x7FFF00,
  5791. 'chocolate': 0xD2691E,
  5792. 'coral': 0xFF7F50,
  5793. 'cornflowerblue': 0x6495ED,
  5794. 'cornsilk': 0xFFF8DC,
  5795. 'crimson': 0xDC143C,
  5796. 'cyan': 0x00FFFF,
  5797. 'darkblue': 0x00008B,
  5798. 'darkcyan': 0x008B8B,
  5799. 'darkgoldenrod': 0xB8860B,
  5800. 'darkgray': 0xA9A9A9,
  5801. 'darkgreen': 0x006400,
  5802. 'darkgrey': 0xA9A9A9,
  5803. 'darkkhaki': 0xBDB76B,
  5804. 'darkmagenta': 0x8B008B,
  5805. 'darkolivegreen': 0x556B2F,
  5806. 'darkorange': 0xFF8C00,
  5807. 'darkorchid': 0x9932CC,
  5808. 'darkred': 0x8B0000,
  5809. 'darksalmon': 0xE9967A,
  5810. 'darkseagreen': 0x8FBC8F,
  5811. 'darkslateblue': 0x483D8B,
  5812. 'darkslategray': 0x2F4F4F,
  5813. 'darkslategrey': 0x2F4F4F,
  5814. 'darkturquoise': 0x00CED1,
  5815. 'darkviolet': 0x9400D3,
  5816. 'deeppink': 0xFF1493,
  5817. 'deepskyblue': 0x00BFFF,
  5818. 'dimgray': 0x696969,
  5819. 'dimgrey': 0x696969,
  5820. 'dodgerblue': 0x1E90FF,
  5821. 'firebrick': 0xB22222,
  5822. 'floralwhite': 0xFFFAF0,
  5823. 'forestgreen': 0x228B22,
  5824. 'fuchsia': 0xFF00FF,
  5825. 'gainsboro': 0xDCDCDC,
  5826. 'ghostwhite': 0xF8F8FF,
  5827. 'gold': 0xFFD700,
  5828. 'goldenrod': 0xDAA520,
  5829. 'gray': 0x808080,
  5830. 'green': 0x008000,
  5831. 'greenyellow': 0xADFF2F,
  5832. 'grey': 0x808080,
  5833. 'honeydew': 0xF0FFF0,
  5834. 'hotpink': 0xFF69B4,
  5835. 'indianred': 0xCD5C5C,
  5836. 'indigo': 0x4B0082,
  5837. 'ivory': 0xFFFFF0,
  5838. 'khaki': 0xF0E68C,
  5839. 'lavender': 0xE6E6FA,
  5840. 'lavenderblush': 0xFFF0F5,
  5841. 'lawngreen': 0x7CFC00,
  5842. 'lemonchiffon': 0xFFFACD,
  5843. 'lightblue': 0xADD8E6,
  5844. 'lightcoral': 0xF08080,
  5845. 'lightcyan': 0xE0FFFF,
  5846. 'lightgoldenrodyellow': 0xFAFAD2,
  5847. 'lightgray': 0xD3D3D3,
  5848. 'lightgreen': 0x90EE90,
  5849. 'lightgrey': 0xD3D3D3,
  5850. 'lightpink': 0xFFB6C1,
  5851. 'lightsalmon': 0xFFA07A,
  5852. 'lightseagreen': 0x20B2AA,
  5853. 'lightskyblue': 0x87CEFA,
  5854. 'lightslategray': 0x778899,
  5855. 'lightslategrey': 0x778899,
  5856. 'lightsteelblue': 0xB0C4DE,
  5857. 'lightyellow': 0xFFFFE0,
  5858. 'lime': 0x00FF00,
  5859. 'limegreen': 0x32CD32,
  5860. 'linen': 0xFAF0E6,
  5861. 'magenta': 0xFF00FF,
  5862. 'maroon': 0x800000,
  5863. 'mediumaquamarine': 0x66CDAA,
  5864. 'mediumblue': 0x0000CD,
  5865. 'mediumorchid': 0xBA55D3,
  5866. 'mediumpurple': 0x9370DB,
  5867. 'mediumseagreen': 0x3CB371,
  5868. 'mediumslateblue': 0x7B68EE,
  5869. 'mediumspringgreen': 0x00FA9A,
  5870. 'mediumturquoise': 0x48D1CC,
  5871. 'mediumvioletred': 0xC71585,
  5872. 'midnightblue': 0x191970,
  5873. 'mintcream': 0xF5FFFA,
  5874. 'mistyrose': 0xFFE4E1,
  5875. 'moccasin': 0xFFE4B5,
  5876. 'navajowhite': 0xFFDEAD,
  5877. 'navy': 0x000080,
  5878. 'oldlace': 0xFDF5E6,
  5879. 'olive': 0x808000,
  5880. 'olivedrab': 0x6B8E23,
  5881. 'orange': 0xFFA500,
  5882. 'orangered': 0xFF4500,
  5883. 'orchid': 0xDA70D6,
  5884. 'palegoldenrod': 0xEEE8AA,
  5885. 'palegreen': 0x98FB98,
  5886. 'paleturquoise': 0xAFEEEE,
  5887. 'palevioletred': 0xDB7093,
  5888. 'papayawhip': 0xFFEFD5,
  5889. 'peachpuff': 0xFFDAB9,
  5890. 'peru': 0xCD853F,
  5891. 'pink': 0xFFC0CB,
  5892. 'plum': 0xDDA0DD,
  5893. 'powderblue': 0xB0E0E6,
  5894. 'purple': 0x800080,
  5895. 'rebeccapurple': 0x663399,
  5896. 'red': 0xFF0000,
  5897. 'rosybrown': 0xBC8F8F,
  5898. 'royalblue': 0x4169E1,
  5899. 'saddlebrown': 0x8B4513,
  5900. 'salmon': 0xFA8072,
  5901. 'sandybrown': 0xF4A460,
  5902. 'seagreen': 0x2E8B57,
  5903. 'seashell': 0xFFF5EE,
  5904. 'sienna': 0xA0522D,
  5905. 'silver': 0xC0C0C0,
  5906. 'skyblue': 0x87CEEB,
  5907. 'slateblue': 0x6A5ACD,
  5908. 'slategray': 0x708090,
  5909. 'slategrey': 0x708090,
  5910. 'snow': 0xFFFAFA,
  5911. 'springgreen': 0x00FF7F,
  5912. 'steelblue': 0x4682B4,
  5913. 'tan': 0xD2B48C,
  5914. 'teal': 0x008080,
  5915. 'thistle': 0xD8BFD8,
  5916. 'tomato': 0xFF6347,
  5917. 'turquoise': 0x40E0D0,
  5918. 'violet': 0xEE82EE,
  5919. 'wheat': 0xF5DEB3,
  5920. 'white': 0xFFFFFF,
  5921. 'whitesmoke': 0xF5F5F5,
  5922. 'yellow': 0xFFFF00,
  5923. 'yellowgreen': 0x9ACD32
  5924. };
  5925. var _hslA = {
  5926. h: 0,
  5927. s: 0,
  5928. l: 0
  5929. };
  5930. var _hslB = {
  5931. h: 0,
  5932. s: 0,
  5933. l: 0
  5934. };
  5935. function hue2rgb(p, q, t) {
  5936. if (t < 0) t += 1;
  5937. if (t > 1) t -= 1;
  5938. if (t < 1 / 6) return p + (q - p) * 6 * t;
  5939. if (t < 1 / 2) return q;
  5940. if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
  5941. return p;
  5942. }
  5943. function SRGBToLinear(c) {
  5944. return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
  5945. }
  5946. function LinearToSRGB(c) {
  5947. return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
  5948. }
  5949. var Color = /*#__PURE__*/function () {
  5950. function Color(r, g, b) {
  5951. Object.defineProperty(this, 'isColor', {
  5952. value: true
  5953. });
  5954. if (g === undefined && b === undefined) {
  5955. // r is THREE.Color, hex or string
  5956. return this.set(r);
  5957. }
  5958. return this.setRGB(r, g, b);
  5959. }
  5960. var _proto = Color.prototype;
  5961. _proto.set = function set(value) {
  5962. if (value && value.isColor) {
  5963. this.copy(value);
  5964. } else if (typeof value === 'number') {
  5965. this.setHex(value);
  5966. } else if (typeof value === 'string') {
  5967. this.setStyle(value);
  5968. }
  5969. return this;
  5970. };
  5971. _proto.setScalar = function setScalar(scalar) {
  5972. this.r = scalar;
  5973. this.g = scalar;
  5974. this.b = scalar;
  5975. return this;
  5976. };
  5977. _proto.setHex = function setHex(hex) {
  5978. hex = Math.floor(hex);
  5979. this.r = (hex >> 16 & 255) / 255;
  5980. this.g = (hex >> 8 & 255) / 255;
  5981. this.b = (hex & 255) / 255;
  5982. return this;
  5983. };
  5984. _proto.setRGB = function setRGB(r, g, b) {
  5985. this.r = r;
  5986. this.g = g;
  5987. this.b = b;
  5988. return this;
  5989. };
  5990. _proto.setHSL = function setHSL(h, s, l) {
  5991. // h,s,l ranges are in 0.0 - 1.0
  5992. h = MathUtils.euclideanModulo(h, 1);
  5993. s = MathUtils.clamp(s, 0, 1);
  5994. l = MathUtils.clamp(l, 0, 1);
  5995. if (s === 0) {
  5996. this.r = this.g = this.b = l;
  5997. } else {
  5998. var p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
  5999. var q = 2 * l - p;
  6000. this.r = hue2rgb(q, p, h + 1 / 3);
  6001. this.g = hue2rgb(q, p, h);
  6002. this.b = hue2rgb(q, p, h - 1 / 3);
  6003. }
  6004. return this;
  6005. };
  6006. _proto.setStyle = function setStyle(style) {
  6007. function handleAlpha(string) {
  6008. if (string === undefined) return;
  6009. if (parseFloat(string) < 1) {
  6010. console.warn('THREE.Color: Alpha component of ' + style + ' will be ignored.');
  6011. }
  6012. }
  6013. var m;
  6014. if (m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)) {
  6015. // rgb / hsl
  6016. var color;
  6017. var name = m[1];
  6018. var components = m[2];
  6019. switch (name) {
  6020. case 'rgb':
  6021. case 'rgba':
  6022. if (color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6023. // rgb(255,0,0) rgba(255,0,0,0.5)
  6024. this.r = Math.min(255, parseInt(color[1], 10)) / 255;
  6025. this.g = Math.min(255, parseInt(color[2], 10)) / 255;
  6026. this.b = Math.min(255, parseInt(color[3], 10)) / 255;
  6027. handleAlpha(color[4]);
  6028. return this;
  6029. }
  6030. if (color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6031. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6032. this.r = Math.min(100, parseInt(color[1], 10)) / 100;
  6033. this.g = Math.min(100, parseInt(color[2], 10)) / 100;
  6034. this.b = Math.min(100, parseInt(color[3], 10)) / 100;
  6035. handleAlpha(color[4]);
  6036. return this;
  6037. }
  6038. break;
  6039. case 'hsl':
  6040. case 'hsla':
  6041. if (color = /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) {
  6042. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6043. var h = parseFloat(color[1]) / 360;
  6044. var s = parseInt(color[2], 10) / 100;
  6045. var l = parseInt(color[3], 10) / 100;
  6046. handleAlpha(color[4]);
  6047. return this.setHSL(h, s, l);
  6048. }
  6049. break;
  6050. }
  6051. } else if (m = /^\#([A-Fa-f\d]+)$/.exec(style)) {
  6052. // hex color
  6053. var hex = m[1];
  6054. var size = hex.length;
  6055. if (size === 3) {
  6056. // #ff0
  6057. this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
  6058. this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
  6059. this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
  6060. return this;
  6061. } else if (size === 6) {
  6062. // #ff0000
  6063. this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
  6064. this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
  6065. this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
  6066. return this;
  6067. }
  6068. }
  6069. if (style && style.length > 0) {
  6070. return this.setColorName(style);
  6071. }
  6072. return this;
  6073. };
  6074. _proto.setColorName = function setColorName(style) {
  6075. // color keywords
  6076. var hex = _colorKeywords[style];
  6077. if (hex !== undefined) {
  6078. // red
  6079. this.setHex(hex);
  6080. } else {
  6081. // unknown color
  6082. console.warn('THREE.Color: Unknown color ' + style);
  6083. }
  6084. return this;
  6085. };
  6086. _proto.clone = function clone() {
  6087. return new this.constructor(this.r, this.g, this.b);
  6088. };
  6089. _proto.copy = function copy(color) {
  6090. this.r = color.r;
  6091. this.g = color.g;
  6092. this.b = color.b;
  6093. return this;
  6094. };
  6095. _proto.copyGammaToLinear = function copyGammaToLinear(color, gammaFactor) {
  6096. if (gammaFactor === void 0) {
  6097. gammaFactor = 2.0;
  6098. }
  6099. this.r = Math.pow(color.r, gammaFactor);
  6100. this.g = Math.pow(color.g, gammaFactor);
  6101. this.b = Math.pow(color.b, gammaFactor);
  6102. return this;
  6103. };
  6104. _proto.copyLinearToGamma = function copyLinearToGamma(color, gammaFactor) {
  6105. if (gammaFactor === void 0) {
  6106. gammaFactor = 2.0;
  6107. }
  6108. var safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0;
  6109. this.r = Math.pow(color.r, safeInverse);
  6110. this.g = Math.pow(color.g, safeInverse);
  6111. this.b = Math.pow(color.b, safeInverse);
  6112. return this;
  6113. };
  6114. _proto.convertGammaToLinear = function convertGammaToLinear(gammaFactor) {
  6115. this.copyGammaToLinear(this, gammaFactor);
  6116. return this;
  6117. };
  6118. _proto.convertLinearToGamma = function convertLinearToGamma(gammaFactor) {
  6119. this.copyLinearToGamma(this, gammaFactor);
  6120. return this;
  6121. };
  6122. _proto.copySRGBToLinear = function copySRGBToLinear(color) {
  6123. this.r = SRGBToLinear(color.r);
  6124. this.g = SRGBToLinear(color.g);
  6125. this.b = SRGBToLinear(color.b);
  6126. return this;
  6127. };
  6128. _proto.copyLinearToSRGB = function copyLinearToSRGB(color) {
  6129. this.r = LinearToSRGB(color.r);
  6130. this.g = LinearToSRGB(color.g);
  6131. this.b = LinearToSRGB(color.b);
  6132. return this;
  6133. };
  6134. _proto.convertSRGBToLinear = function convertSRGBToLinear() {
  6135. this.copySRGBToLinear(this);
  6136. return this;
  6137. };
  6138. _proto.convertLinearToSRGB = function convertLinearToSRGB() {
  6139. this.copyLinearToSRGB(this);
  6140. return this;
  6141. };
  6142. _proto.getHex = function getHex() {
  6143. return this.r * 255 << 16 ^ this.g * 255 << 8 ^ this.b * 255 << 0;
  6144. };
  6145. _proto.getHexString = function getHexString() {
  6146. return ('000000' + this.getHex().toString(16)).slice(-6);
  6147. };
  6148. _proto.getHSL = function getHSL(target) {
  6149. // h,s,l ranges are in 0.0 - 1.0
  6150. if (target === undefined) {
  6151. console.warn('THREE.Color: .getHSL() target is now required');
  6152. target = {
  6153. h: 0,
  6154. s: 0,
  6155. l: 0
  6156. };
  6157. }
  6158. var r = this.r,
  6159. g = this.g,
  6160. b = this.b;
  6161. var max = Math.max(r, g, b);
  6162. var min = Math.min(r, g, b);
  6163. var hue, saturation;
  6164. var lightness = (min + max) / 2.0;
  6165. if (min === max) {
  6166. hue = 0;
  6167. saturation = 0;
  6168. } else {
  6169. var delta = max - min;
  6170. saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
  6171. switch (max) {
  6172. case r:
  6173. hue = (g - b) / delta + (g < b ? 6 : 0);
  6174. break;
  6175. case g:
  6176. hue = (b - r) / delta + 2;
  6177. break;
  6178. case b:
  6179. hue = (r - g) / delta + 4;
  6180. break;
  6181. }
  6182. hue /= 6;
  6183. }
  6184. target.h = hue;
  6185. target.s = saturation;
  6186. target.l = lightness;
  6187. return target;
  6188. };
  6189. _proto.getStyle = function getStyle() {
  6190. return 'rgb(' + (this.r * 255 | 0) + ',' + (this.g * 255 | 0) + ',' + (this.b * 255 | 0) + ')';
  6191. };
  6192. _proto.offsetHSL = function offsetHSL(h, s, l) {
  6193. this.getHSL(_hslA);
  6194. _hslA.h += h;
  6195. _hslA.s += s;
  6196. _hslA.l += l;
  6197. this.setHSL(_hslA.h, _hslA.s, _hslA.l);
  6198. return this;
  6199. };
  6200. _proto.add = function add(color) {
  6201. this.r += color.r;
  6202. this.g += color.g;
  6203. this.b += color.b;
  6204. return this;
  6205. };
  6206. _proto.addColors = function addColors(color1, color2) {
  6207. this.r = color1.r + color2.r;
  6208. this.g = color1.g + color2.g;
  6209. this.b = color1.b + color2.b;
  6210. return this;
  6211. };
  6212. _proto.addScalar = function addScalar(s) {
  6213. this.r += s;
  6214. this.g += s;
  6215. this.b += s;
  6216. return this;
  6217. };
  6218. _proto.sub = function sub(color) {
  6219. this.r = Math.max(0, this.r - color.r);
  6220. this.g = Math.max(0, this.g - color.g);
  6221. this.b = Math.max(0, this.b - color.b);
  6222. return this;
  6223. };
  6224. _proto.multiply = function multiply(color) {
  6225. this.r *= color.r;
  6226. this.g *= color.g;
  6227. this.b *= color.b;
  6228. return this;
  6229. };
  6230. _proto.multiplyScalar = function multiplyScalar(s) {
  6231. this.r *= s;
  6232. this.g *= s;
  6233. this.b *= s;
  6234. return this;
  6235. };
  6236. _proto.lerp = function lerp(color, alpha) {
  6237. this.r += (color.r - this.r) * alpha;
  6238. this.g += (color.g - this.g) * alpha;
  6239. this.b += (color.b - this.b) * alpha;
  6240. return this;
  6241. };
  6242. _proto.lerpColors = function lerpColors(color1, color2, alpha) {
  6243. this.r = color1.r + (color2.r - color1.r) * alpha;
  6244. this.g = color1.g + (color2.g - color1.g) * alpha;
  6245. this.b = color1.b + (color2.b - color1.b) * alpha;
  6246. return this;
  6247. };
  6248. _proto.lerpHSL = function lerpHSL(color, alpha) {
  6249. this.getHSL(_hslA);
  6250. color.getHSL(_hslB);
  6251. var h = MathUtils.lerp(_hslA.h, _hslB.h, alpha);
  6252. var s = MathUtils.lerp(_hslA.s, _hslB.s, alpha);
  6253. var l = MathUtils.lerp(_hslA.l, _hslB.l, alpha);
  6254. this.setHSL(h, s, l);
  6255. return this;
  6256. };
  6257. _proto.equals = function equals(c) {
  6258. return c.r === this.r && c.g === this.g && c.b === this.b;
  6259. };
  6260. _proto.fromArray = function fromArray(array, offset) {
  6261. if (offset === void 0) {
  6262. offset = 0;
  6263. }
  6264. this.r = array[offset];
  6265. this.g = array[offset + 1];
  6266. this.b = array[offset + 2];
  6267. return this;
  6268. };
  6269. _proto.toArray = function toArray(array, offset) {
  6270. if (array === void 0) {
  6271. array = [];
  6272. }
  6273. if (offset === void 0) {
  6274. offset = 0;
  6275. }
  6276. array[offset] = this.r;
  6277. array[offset + 1] = this.g;
  6278. array[offset + 2] = this.b;
  6279. return array;
  6280. };
  6281. _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
  6282. this.r = attribute.getX(index);
  6283. this.g = attribute.getY(index);
  6284. this.b = attribute.getZ(index);
  6285. if (attribute.normalized === true) {
  6286. // assuming Uint8Array
  6287. this.r /= 255;
  6288. this.g /= 255;
  6289. this.b /= 255;
  6290. }
  6291. return this;
  6292. };
  6293. _proto.toJSON = function toJSON() {
  6294. return this.getHex();
  6295. };
  6296. return Color;
  6297. }();
  6298. Color.NAMES = _colorKeywords;
  6299. Color.prototype.r = 1;
  6300. Color.prototype.g = 1;
  6301. Color.prototype.b = 1;
  6302. var Face3 = /*#__PURE__*/function () {
  6303. function Face3(a, b, c, normal, color, materialIndex) {
  6304. if (materialIndex === void 0) {
  6305. materialIndex = 0;
  6306. }
  6307. this.a = a;
  6308. this.b = b;
  6309. this.c = c;
  6310. this.normal = normal && normal.isVector3 ? normal : new Vector3();
  6311. this.vertexNormals = Array.isArray(normal) ? normal : [];
  6312. this.color = color && color.isColor ? color : new Color();
  6313. this.vertexColors = Array.isArray(color) ? color : [];
  6314. this.materialIndex = materialIndex;
  6315. }
  6316. var _proto = Face3.prototype;
  6317. _proto.clone = function clone() {
  6318. return new this.constructor().copy(this);
  6319. };
  6320. _proto.copy = function copy(source) {
  6321. this.a = source.a;
  6322. this.b = source.b;
  6323. this.c = source.c;
  6324. this.normal.copy(source.normal);
  6325. this.color.copy(source.color);
  6326. this.materialIndex = source.materialIndex;
  6327. for (var i = 0, il = source.vertexNormals.length; i < il; i++) {
  6328. this.vertexNormals[i] = source.vertexNormals[i].clone();
  6329. }
  6330. for (var _i = 0, _il = source.vertexColors.length; _i < _il; _i++) {
  6331. this.vertexColors[_i] = source.vertexColors[_i].clone();
  6332. }
  6333. return this;
  6334. };
  6335. return Face3;
  6336. }();
  6337. var materialId = 0;
  6338. function Material() {
  6339. Object.defineProperty(this, 'id', {
  6340. value: materialId++
  6341. });
  6342. this.uuid = MathUtils.generateUUID();
  6343. this.name = '';
  6344. this.type = 'Material';
  6345. this.fog = true;
  6346. this.blending = NormalBlending;
  6347. this.side = FrontSide;
  6348. this.flatShading = false;
  6349. this.vertexColors = false;
  6350. this.opacity = 1;
  6351. this.transparent = false;
  6352. this.blendSrc = SrcAlphaFactor;
  6353. this.blendDst = OneMinusSrcAlphaFactor;
  6354. this.blendEquation = AddEquation;
  6355. this.blendSrcAlpha = null;
  6356. this.blendDstAlpha = null;
  6357. this.blendEquationAlpha = null;
  6358. this.depthFunc = LessEqualDepth;
  6359. this.depthTest = true;
  6360. this.depthWrite = true;
  6361. this.stencilWriteMask = 0xff;
  6362. this.stencilFunc = AlwaysStencilFunc;
  6363. this.stencilRef = 0;
  6364. this.stencilFuncMask = 0xff;
  6365. this.stencilFail = KeepStencilOp;
  6366. this.stencilZFail = KeepStencilOp;
  6367. this.stencilZPass = KeepStencilOp;
  6368. this.stencilWrite = false;
  6369. this.clippingPlanes = null;
  6370. this.clipIntersection = false;
  6371. this.clipShadows = false;
  6372. this.shadowSide = null;
  6373. this.colorWrite = true;
  6374. this.precision = null; // override the renderer's default precision for this material
  6375. this.polygonOffset = false;
  6376. this.polygonOffsetFactor = 0;
  6377. this.polygonOffsetUnits = 0;
  6378. this.dithering = false;
  6379. this.alphaTest = 0;
  6380. this.premultipliedAlpha = false;
  6381. this.visible = true;
  6382. this.toneMapped = true;
  6383. this.userData = {};
  6384. this.version = 0;
  6385. }
  6386. Material.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  6387. constructor: Material,
  6388. isMaterial: true,
  6389. onBeforeCompile: function onBeforeCompile()
  6390. /* shaderobject, renderer */
  6391. {},
  6392. customProgramCacheKey: function customProgramCacheKey() {
  6393. return this.onBeforeCompile.toString();
  6394. },
  6395. setValues: function setValues(values) {
  6396. if (values === undefined) return;
  6397. for (var key in values) {
  6398. var newValue = values[key];
  6399. if (newValue === undefined) {
  6400. console.warn('THREE.Material: \'' + key + '\' parameter is undefined.');
  6401. continue;
  6402. } // for backward compatability if shading is set in the constructor
  6403. if (key === 'shading') {
  6404. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  6405. this.flatShading = newValue === FlatShading ? true : false;
  6406. continue;
  6407. }
  6408. var currentValue = this[key];
  6409. if (currentValue === undefined) {
  6410. console.warn('THREE.' + this.type + ': \'' + key + '\' is not a property of this material.');
  6411. continue;
  6412. }
  6413. if (currentValue && currentValue.isColor) {
  6414. currentValue.set(newValue);
  6415. } else if (currentValue && currentValue.isVector3 && newValue && newValue.isVector3) {
  6416. currentValue.copy(newValue);
  6417. } else {
  6418. this[key] = newValue;
  6419. }
  6420. }
  6421. },
  6422. toJSON: function toJSON(meta) {
  6423. var isRoot = meta === undefined || typeof meta === 'string';
  6424. if (isRoot) {
  6425. meta = {
  6426. textures: {},
  6427. images: {}
  6428. };
  6429. }
  6430. var data = {
  6431. metadata: {
  6432. version: 4.5,
  6433. type: 'Material',
  6434. generator: 'Material.toJSON'
  6435. }
  6436. }; // standard Material serialization
  6437. data.uuid = this.uuid;
  6438. data.type = this.type;
  6439. if (this.name !== '') data.name = this.name;
  6440. if (this.color && this.color.isColor) data.color = this.color.getHex();
  6441. if (this.roughness !== undefined) data.roughness = this.roughness;
  6442. if (this.metalness !== undefined) data.metalness = this.metalness;
  6443. if (this.sheen && this.sheen.isColor) data.sheen = this.sheen.getHex();
  6444. if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex();
  6445. if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity;
  6446. if (this.specular && this.specular.isColor) data.specular = this.specular.getHex();
  6447. if (this.shininess !== undefined) data.shininess = this.shininess;
  6448. if (this.clearcoat !== undefined) data.clearcoat = this.clearcoat;
  6449. if (this.clearcoatRoughness !== undefined) data.clearcoatRoughness = this.clearcoatRoughness;
  6450. if (this.clearcoatMap && this.clearcoatMap.isTexture) {
  6451. data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid;
  6452. }
  6453. if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) {
  6454. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid;
  6455. }
  6456. if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) {
  6457. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid;
  6458. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  6459. }
  6460. if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid;
  6461. if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid;
  6462. if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid;
  6463. if (this.lightMap && this.lightMap.isTexture) data.lightMap = this.lightMap.toJSON(meta).uuid;
  6464. if (this.aoMap && this.aoMap.isTexture) {
  6465. data.aoMap = this.aoMap.toJSON(meta).uuid;
  6466. data.aoMapIntensity = this.aoMapIntensity;
  6467. }
  6468. if (this.bumpMap && this.bumpMap.isTexture) {
  6469. data.bumpMap = this.bumpMap.toJSON(meta).uuid;
  6470. data.bumpScale = this.bumpScale;
  6471. }
  6472. if (this.normalMap && this.normalMap.isTexture) {
  6473. data.normalMap = this.normalMap.toJSON(meta).uuid;
  6474. data.normalMapType = this.normalMapType;
  6475. data.normalScale = this.normalScale.toArray();
  6476. }
  6477. if (this.displacementMap && this.displacementMap.isTexture) {
  6478. data.displacementMap = this.displacementMap.toJSON(meta).uuid;
  6479. data.displacementScale = this.displacementScale;
  6480. data.displacementBias = this.displacementBias;
  6481. }
  6482. if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid;
  6483. if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid;
  6484. if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid;
  6485. if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid;
  6486. if (this.envMap && this.envMap.isTexture) {
  6487. data.envMap = this.envMap.toJSON(meta).uuid;
  6488. data.reflectivity = this.reflectivity; // Scale behind envMap
  6489. data.refractionRatio = this.refractionRatio;
  6490. if (this.combine !== undefined) data.combine = this.combine;
  6491. if (this.envMapIntensity !== undefined) data.envMapIntensity = this.envMapIntensity;
  6492. }
  6493. if (this.gradientMap && this.gradientMap.isTexture) {
  6494. data.gradientMap = this.gradientMap.toJSON(meta).uuid;
  6495. }
  6496. if (this.size !== undefined) data.size = this.size;
  6497. if (this.sizeAttenuation !== undefined) data.sizeAttenuation = this.sizeAttenuation;
  6498. if (this.blending !== NormalBlending) data.blending = this.blending;
  6499. if (this.flatShading === true) data.flatShading = this.flatShading;
  6500. if (this.side !== FrontSide) data.side = this.side;
  6501. if (this.vertexColors) data.vertexColors = true;
  6502. if (this.opacity < 1) data.opacity = this.opacity;
  6503. if (this.transparent === true) data.transparent = this.transparent;
  6504. data.depthFunc = this.depthFunc;
  6505. data.depthTest = this.depthTest;
  6506. data.depthWrite = this.depthWrite;
  6507. data.stencilWrite = this.stencilWrite;
  6508. data.stencilWriteMask = this.stencilWriteMask;
  6509. data.stencilFunc = this.stencilFunc;
  6510. data.stencilRef = this.stencilRef;
  6511. data.stencilFuncMask = this.stencilFuncMask;
  6512. data.stencilFail = this.stencilFail;
  6513. data.stencilZFail = this.stencilZFail;
  6514. data.stencilZPass = this.stencilZPass; // rotation (SpriteMaterial)
  6515. if (this.rotation && this.rotation !== 0) data.rotation = this.rotation;
  6516. if (this.polygonOffset === true) data.polygonOffset = true;
  6517. if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor;
  6518. if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits;
  6519. if (this.linewidth && this.linewidth !== 1) data.linewidth = this.linewidth;
  6520. if (this.dashSize !== undefined) data.dashSize = this.dashSize;
  6521. if (this.gapSize !== undefined) data.gapSize = this.gapSize;
  6522. if (this.scale !== undefined) data.scale = this.scale;
  6523. if (this.dithering === true) data.dithering = true;
  6524. if (this.alphaTest > 0) data.alphaTest = this.alphaTest;
  6525. if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha;
  6526. if (this.wireframe === true) data.wireframe = this.wireframe;
  6527. if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth;
  6528. if (this.wireframeLinecap !== 'round') data.wireframeLinecap = this.wireframeLinecap;
  6529. if (this.wireframeLinejoin !== 'round') data.wireframeLinejoin = this.wireframeLinejoin;
  6530. if (this.morphTargets === true) data.morphTargets = true;
  6531. if (this.morphNormals === true) data.morphNormals = true;
  6532. if (this.skinning === true) data.skinning = true;
  6533. if (this.visible === false) data.visible = false;
  6534. if (this.toneMapped === false) data.toneMapped = false;
  6535. if (JSON.stringify(this.userData) !== '{}') data.userData = this.userData; // TODO: Copied from Object3D.toJSON
  6536. function extractFromCache(cache) {
  6537. var values = [];
  6538. for (var key in cache) {
  6539. var _data = cache[key];
  6540. delete _data.metadata;
  6541. values.push(_data);
  6542. }
  6543. return values;
  6544. }
  6545. if (isRoot) {
  6546. var textures = extractFromCache(meta.textures);
  6547. var images = extractFromCache(meta.images);
  6548. if (textures.length > 0) data.textures = textures;
  6549. if (images.length > 0) data.images = images;
  6550. }
  6551. return data;
  6552. },
  6553. clone: function clone() {
  6554. return new this.constructor().copy(this);
  6555. },
  6556. copy: function copy(source) {
  6557. this.name = source.name;
  6558. this.fog = source.fog;
  6559. this.blending = source.blending;
  6560. this.side = source.side;
  6561. this.flatShading = source.flatShading;
  6562. this.vertexColors = source.vertexColors;
  6563. this.opacity = source.opacity;
  6564. this.transparent = source.transparent;
  6565. this.blendSrc = source.blendSrc;
  6566. this.blendDst = source.blendDst;
  6567. this.blendEquation = source.blendEquation;
  6568. this.blendSrcAlpha = source.blendSrcAlpha;
  6569. this.blendDstAlpha = source.blendDstAlpha;
  6570. this.blendEquationAlpha = source.blendEquationAlpha;
  6571. this.depthFunc = source.depthFunc;
  6572. this.depthTest = source.depthTest;
  6573. this.depthWrite = source.depthWrite;
  6574. this.stencilWriteMask = source.stencilWriteMask;
  6575. this.stencilFunc = source.stencilFunc;
  6576. this.stencilRef = source.stencilRef;
  6577. this.stencilFuncMask = source.stencilFuncMask;
  6578. this.stencilFail = source.stencilFail;
  6579. this.stencilZFail = source.stencilZFail;
  6580. this.stencilZPass = source.stencilZPass;
  6581. this.stencilWrite = source.stencilWrite;
  6582. var srcPlanes = source.clippingPlanes;
  6583. var dstPlanes = null;
  6584. if (srcPlanes !== null) {
  6585. var n = srcPlanes.length;
  6586. dstPlanes = new Array(n);
  6587. for (var i = 0; i !== n; ++i) {
  6588. dstPlanes[i] = srcPlanes[i].clone();
  6589. }
  6590. }
  6591. this.clippingPlanes = dstPlanes;
  6592. this.clipIntersection = source.clipIntersection;
  6593. this.clipShadows = source.clipShadows;
  6594. this.shadowSide = source.shadowSide;
  6595. this.colorWrite = source.colorWrite;
  6596. this.precision = source.precision;
  6597. this.polygonOffset = source.polygonOffset;
  6598. this.polygonOffsetFactor = source.polygonOffsetFactor;
  6599. this.polygonOffsetUnits = source.polygonOffsetUnits;
  6600. this.dithering = source.dithering;
  6601. this.alphaTest = source.alphaTest;
  6602. this.premultipliedAlpha = source.premultipliedAlpha;
  6603. this.visible = source.visible;
  6604. this.toneMapped = source.toneMapped;
  6605. this.userData = JSON.parse(JSON.stringify(source.userData));
  6606. return this;
  6607. },
  6608. dispose: function dispose() {
  6609. this.dispatchEvent({
  6610. type: 'dispose'
  6611. });
  6612. }
  6613. });
  6614. Object.defineProperty(Material.prototype, 'needsUpdate', {
  6615. set: function set(value) {
  6616. if (value === true) this.version++;
  6617. }
  6618. });
  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 = new Face3(a, b, c);
  7854. Triangle.getNormal(_vA, _vB, _vC, face.normal);
  7855. intersection.face = face;
  7856. }
  7857. return intersection;
  7858. }
  7859. var BoxGeometry = /*#__PURE__*/function (_BufferGeometry) {
  7860. _inheritsLoose(BoxGeometry, _BufferGeometry);
  7861. function BoxGeometry(width, height, depth, widthSegments, heightSegments, depthSegments) {
  7862. var _this;
  7863. if (width === void 0) {
  7864. width = 1;
  7865. }
  7866. if (height === void 0) {
  7867. height = 1;
  7868. }
  7869. if (depth === void 0) {
  7870. depth = 1;
  7871. }
  7872. if (widthSegments === void 0) {
  7873. widthSegments = 1;
  7874. }
  7875. if (heightSegments === void 0) {
  7876. heightSegments = 1;
  7877. }
  7878. if (depthSegments === void 0) {
  7879. depthSegments = 1;
  7880. }
  7881. _this = _BufferGeometry.call(this) || this;
  7882. _this.type = 'BoxGeometry';
  7883. _this.parameters = {
  7884. width: width,
  7885. height: height,
  7886. depth: depth,
  7887. widthSegments: widthSegments,
  7888. heightSegments: heightSegments,
  7889. depthSegments: depthSegments
  7890. };
  7891. var scope = _assertThisInitialized(_this); // segments
  7892. widthSegments = Math.floor(widthSegments);
  7893. heightSegments = Math.floor(heightSegments);
  7894. depthSegments = Math.floor(depthSegments); // buffers
  7895. var indices = [];
  7896. var vertices = [];
  7897. var normals = [];
  7898. var uvs = []; // helper variables
  7899. var numberOfVertices = 0;
  7900. var groupStart = 0; // build each side of the box geometry
  7901. buildPlane('z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0); // px
  7902. buildPlane('z', 'y', 'x', 1, -1, depth, height, -width, depthSegments, heightSegments, 1); // nx
  7903. buildPlane('x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2); // py
  7904. buildPlane('x', 'z', 'y', 1, -1, width, depth, -height, widthSegments, depthSegments, 3); // ny
  7905. buildPlane('x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4); // pz
  7906. buildPlane('x', 'y', 'z', -1, -1, width, height, -depth, widthSegments, heightSegments, 5); // nz
  7907. // build geometry
  7908. _this.setIndex(indices);
  7909. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  7910. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  7911. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  7912. function buildPlane(u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex) {
  7913. var segmentWidth = width / gridX;
  7914. var segmentHeight = height / gridY;
  7915. var widthHalf = width / 2;
  7916. var heightHalf = height / 2;
  7917. var depthHalf = depth / 2;
  7918. var gridX1 = gridX + 1;
  7919. var gridY1 = gridY + 1;
  7920. var vertexCounter = 0;
  7921. var groupCount = 0;
  7922. var vector = new Vector3(); // generate vertices, normals and uvs
  7923. for (var iy = 0; iy < gridY1; iy++) {
  7924. var y = iy * segmentHeight - heightHalf;
  7925. for (var ix = 0; ix < gridX1; ix++) {
  7926. var x = ix * segmentWidth - widthHalf; // set values to correct vector component
  7927. vector[u] = x * udir;
  7928. vector[v] = y * vdir;
  7929. vector[w] = depthHalf; // now apply vector to vertex buffer
  7930. vertices.push(vector.x, vector.y, vector.z); // set values to correct vector component
  7931. vector[u] = 0;
  7932. vector[v] = 0;
  7933. vector[w] = depth > 0 ? 1 : -1; // now apply vector to normal buffer
  7934. normals.push(vector.x, vector.y, vector.z); // uvs
  7935. uvs.push(ix / gridX);
  7936. uvs.push(1 - iy / gridY); // counters
  7937. vertexCounter += 1;
  7938. }
  7939. } // indices
  7940. // 1. you need three indices to draw a single face
  7941. // 2. a single segment consists of two faces
  7942. // 3. so we need to generate six (2*3) indices per segment
  7943. for (var _iy = 0; _iy < gridY; _iy++) {
  7944. for (var _ix = 0; _ix < gridX; _ix++) {
  7945. var a = numberOfVertices + _ix + gridX1 * _iy;
  7946. var b = numberOfVertices + _ix + gridX1 * (_iy + 1);
  7947. var c = numberOfVertices + (_ix + 1) + gridX1 * (_iy + 1);
  7948. var d = numberOfVertices + (_ix + 1) + gridX1 * _iy; // faces
  7949. indices.push(a, b, d);
  7950. indices.push(b, c, d); // increase counter
  7951. groupCount += 6;
  7952. }
  7953. } // add a group to the geometry. this will ensure multi material support
  7954. scope.addGroup(groupStart, groupCount, materialIndex); // calculate new start value for groups
  7955. groupStart += groupCount; // update total number of vertices
  7956. numberOfVertices += vertexCounter;
  7957. }
  7958. return _this;
  7959. }
  7960. return BoxGeometry;
  7961. }(BufferGeometry);
  7962. /**
  7963. * Uniform Utilities
  7964. */
  7965. function cloneUniforms(src) {
  7966. var dst = {};
  7967. for (var u in src) {
  7968. dst[u] = {};
  7969. for (var p in src[u]) {
  7970. var property = src[u][p];
  7971. if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture)) {
  7972. dst[u][p] = property.clone();
  7973. } else if (Array.isArray(property)) {
  7974. dst[u][p] = property.slice();
  7975. } else {
  7976. dst[u][p] = property;
  7977. }
  7978. }
  7979. }
  7980. return dst;
  7981. }
  7982. function mergeUniforms(uniforms) {
  7983. var merged = {};
  7984. for (var u = 0; u < uniforms.length; u++) {
  7985. var tmp = cloneUniforms(uniforms[u]);
  7986. for (var p in tmp) {
  7987. merged[p] = tmp[p];
  7988. }
  7989. }
  7990. return merged;
  7991. } // Legacy
  7992. var UniformsUtils = {
  7993. clone: cloneUniforms,
  7994. merge: mergeUniforms
  7995. };
  7996. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7997. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7998. /**
  7999. * parameters = {
  8000. * defines: { "label" : "value" },
  8001. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  8002. *
  8003. * fragmentShader: <string>,
  8004. * vertexShader: <string>,
  8005. *
  8006. * wireframe: <boolean>,
  8007. * wireframeLinewidth: <float>,
  8008. *
  8009. * lights: <bool>,
  8010. *
  8011. * skinning: <bool>,
  8012. * morphTargets: <bool>,
  8013. * morphNormals: <bool>
  8014. * }
  8015. */
  8016. function ShaderMaterial(parameters) {
  8017. Material.call(this);
  8018. this.type = 'ShaderMaterial';
  8019. this.defines = {};
  8020. this.uniforms = {};
  8021. this.vertexShader = default_vertex;
  8022. this.fragmentShader = default_fragment;
  8023. this.linewidth = 1;
  8024. this.wireframe = false;
  8025. this.wireframeLinewidth = 1;
  8026. this.fog = false; // set to use scene fog
  8027. this.lights = false; // set to use scene lights
  8028. this.clipping = false; // set to use user-defined clipping planes
  8029. this.skinning = false; // set to use skinning attribute streams
  8030. this.morphTargets = false; // set to use morph targets
  8031. this.morphNormals = false; // set to use morph normals
  8032. this.extensions = {
  8033. derivatives: false,
  8034. // set to use derivatives
  8035. fragDepth: false,
  8036. // set to use fragment depth values
  8037. drawBuffers: false,
  8038. // set to use draw buffers
  8039. shaderTextureLOD: false // set to use shader texture LOD
  8040. }; // When rendered geometry doesn't include these attributes but the material does,
  8041. // use these default values in WebGL. This avoids errors when buffer data is missing.
  8042. this.defaultAttributeValues = {
  8043. 'color': [1, 1, 1],
  8044. 'uv': [0, 0],
  8045. 'uv2': [0, 0]
  8046. };
  8047. this.index0AttributeName = undefined;
  8048. this.uniformsNeedUpdate = false;
  8049. this.glslVersion = null;
  8050. if (parameters !== undefined) {
  8051. if (parameters.attributes !== undefined) {
  8052. console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');
  8053. }
  8054. this.setValues(parameters);
  8055. }
  8056. }
  8057. ShaderMaterial.prototype = Object.create(Material.prototype);
  8058. ShaderMaterial.prototype.constructor = ShaderMaterial;
  8059. ShaderMaterial.prototype.isShaderMaterial = true;
  8060. ShaderMaterial.prototype.copy = function (source) {
  8061. Material.prototype.copy.call(this, source);
  8062. this.fragmentShader = source.fragmentShader;
  8063. this.vertexShader = source.vertexShader;
  8064. this.uniforms = cloneUniforms(source.uniforms);
  8065. this.defines = Object.assign({}, source.defines);
  8066. this.wireframe = source.wireframe;
  8067. this.wireframeLinewidth = source.wireframeLinewidth;
  8068. this.lights = source.lights;
  8069. this.clipping = source.clipping;
  8070. this.skinning = source.skinning;
  8071. this.morphTargets = source.morphTargets;
  8072. this.morphNormals = source.morphNormals;
  8073. this.extensions = Object.assign({}, source.extensions);
  8074. this.glslVersion = source.glslVersion;
  8075. return this;
  8076. };
  8077. ShaderMaterial.prototype.toJSON = function (meta) {
  8078. var data = Material.prototype.toJSON.call(this, meta);
  8079. data.glslVersion = this.glslVersion;
  8080. data.uniforms = {};
  8081. for (var name in this.uniforms) {
  8082. var uniform = this.uniforms[name];
  8083. var value = uniform.value;
  8084. if (value && value.isTexture) {
  8085. data.uniforms[name] = {
  8086. type: 't',
  8087. value: value.toJSON(meta).uuid
  8088. };
  8089. } else if (value && value.isColor) {
  8090. data.uniforms[name] = {
  8091. type: 'c',
  8092. value: value.getHex()
  8093. };
  8094. } else if (value && value.isVector2) {
  8095. data.uniforms[name] = {
  8096. type: 'v2',
  8097. value: value.toArray()
  8098. };
  8099. } else if (value && value.isVector3) {
  8100. data.uniforms[name] = {
  8101. type: 'v3',
  8102. value: value.toArray()
  8103. };
  8104. } else if (value && value.isVector4) {
  8105. data.uniforms[name] = {
  8106. type: 'v4',
  8107. value: value.toArray()
  8108. };
  8109. } else if (value && value.isMatrix3) {
  8110. data.uniforms[name] = {
  8111. type: 'm3',
  8112. value: value.toArray()
  8113. };
  8114. } else if (value && value.isMatrix4) {
  8115. data.uniforms[name] = {
  8116. type: 'm4',
  8117. value: value.toArray()
  8118. };
  8119. } else {
  8120. data.uniforms[name] = {
  8121. value: value
  8122. }; // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  8123. }
  8124. }
  8125. if (Object.keys(this.defines).length > 0) data.defines = this.defines;
  8126. data.vertexShader = this.vertexShader;
  8127. data.fragmentShader = this.fragmentShader;
  8128. var extensions = {};
  8129. for (var key in this.extensions) {
  8130. if (this.extensions[key] === true) extensions[key] = true;
  8131. }
  8132. if (Object.keys(extensions).length > 0) data.extensions = extensions;
  8133. return data;
  8134. };
  8135. function Camera() {
  8136. Object3D.call(this);
  8137. this.type = 'Camera';
  8138. this.matrixWorldInverse = new Matrix4();
  8139. this.projectionMatrix = new Matrix4();
  8140. this.projectionMatrixInverse = new Matrix4();
  8141. }
  8142. Camera.prototype = Object.assign(Object.create(Object3D.prototype), {
  8143. constructor: Camera,
  8144. isCamera: true,
  8145. copy: function copy(source, recursive) {
  8146. Object3D.prototype.copy.call(this, source, recursive);
  8147. this.matrixWorldInverse.copy(source.matrixWorldInverse);
  8148. this.projectionMatrix.copy(source.projectionMatrix);
  8149. this.projectionMatrixInverse.copy(source.projectionMatrixInverse);
  8150. return this;
  8151. },
  8152. getWorldDirection: function getWorldDirection(target) {
  8153. if (target === undefined) {
  8154. console.warn('THREE.Camera: .getWorldDirection() target is now required');
  8155. target = new Vector3();
  8156. }
  8157. this.updateWorldMatrix(true, false);
  8158. var e = this.matrixWorld.elements;
  8159. return target.set(-e[8], -e[9], -e[10]).normalize();
  8160. },
  8161. updateMatrixWorld: function updateMatrixWorld(force) {
  8162. Object3D.prototype.updateMatrixWorld.call(this, force);
  8163. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8164. },
  8165. updateWorldMatrix: function updateWorldMatrix(updateParents, updateChildren) {
  8166. Object3D.prototype.updateWorldMatrix.call(this, updateParents, updateChildren);
  8167. this.matrixWorldInverse.copy(this.matrixWorld).invert();
  8168. },
  8169. clone: function clone() {
  8170. return new this.constructor().copy(this);
  8171. }
  8172. });
  8173. function PerspectiveCamera(fov, aspect, near, far) {
  8174. if (fov === void 0) {
  8175. fov = 50;
  8176. }
  8177. if (aspect === void 0) {
  8178. aspect = 1;
  8179. }
  8180. if (near === void 0) {
  8181. near = 0.1;
  8182. }
  8183. if (far === void 0) {
  8184. far = 2000;
  8185. }
  8186. Camera.call(this);
  8187. this.type = 'PerspectiveCamera';
  8188. this.fov = fov;
  8189. this.zoom = 1;
  8190. this.near = near;
  8191. this.far = far;
  8192. this.focus = 10;
  8193. this.aspect = aspect;
  8194. this.view = null;
  8195. this.filmGauge = 35; // width of the film (default in millimeters)
  8196. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  8197. this.updateProjectionMatrix();
  8198. }
  8199. PerspectiveCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  8200. constructor: PerspectiveCamera,
  8201. isPerspectiveCamera: true,
  8202. copy: function copy(source, recursive) {
  8203. Camera.prototype.copy.call(this, source, recursive);
  8204. this.fov = source.fov;
  8205. this.zoom = source.zoom;
  8206. this.near = source.near;
  8207. this.far = source.far;
  8208. this.focus = source.focus;
  8209. this.aspect = source.aspect;
  8210. this.view = source.view === null ? null : Object.assign({}, source.view);
  8211. this.filmGauge = source.filmGauge;
  8212. this.filmOffset = source.filmOffset;
  8213. return this;
  8214. },
  8215. /**
  8216. * Sets the FOV by focal length in respect to the current .filmGauge.
  8217. *
  8218. * The default film gauge is 35, so that the focal length can be specified for
  8219. * a 35mm (full frame) camera.
  8220. *
  8221. * Values for focal length and film gauge must have the same unit.
  8222. */
  8223. setFocalLength: function setFocalLength(focalLength) {
  8224. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  8225. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  8226. this.fov = MathUtils.RAD2DEG * 2 * Math.atan(vExtentSlope);
  8227. this.updateProjectionMatrix();
  8228. },
  8229. /**
  8230. * Calculates the focal length from the current .fov and .filmGauge.
  8231. */
  8232. getFocalLength: function getFocalLength() {
  8233. var vExtentSlope = Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov);
  8234. return 0.5 * this.getFilmHeight() / vExtentSlope;
  8235. },
  8236. getEffectiveFOV: function getEffectiveFOV() {
  8237. return MathUtils.RAD2DEG * 2 * Math.atan(Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom);
  8238. },
  8239. getFilmWidth: function getFilmWidth() {
  8240. // film not completely covered in portrait format (aspect < 1)
  8241. return this.filmGauge * Math.min(this.aspect, 1);
  8242. },
  8243. getFilmHeight: function getFilmHeight() {
  8244. // film not completely covered in landscape format (aspect > 1)
  8245. return this.filmGauge / Math.max(this.aspect, 1);
  8246. },
  8247. /**
  8248. * Sets an offset in a larger frustum. This is useful for multi-window or
  8249. * multi-monitor/multi-machine setups.
  8250. *
  8251. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8252. * the monitors are in grid like this
  8253. *
  8254. * +---+---+---+
  8255. * | A | B | C |
  8256. * +---+---+---+
  8257. * | D | E | F |
  8258. * +---+---+---+
  8259. *
  8260. * then for each monitor you would call it like this
  8261. *
  8262. * const w = 1920;
  8263. * const h = 1080;
  8264. * const fullWidth = w * 3;
  8265. * const fullHeight = h * 2;
  8266. *
  8267. * --A--
  8268. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8269. * --B--
  8270. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8271. * --C--
  8272. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8273. * --D--
  8274. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8275. * --E--
  8276. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8277. * --F--
  8278. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8279. *
  8280. * Note there is no reason monitors have to be the same size or in a grid.
  8281. */
  8282. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  8283. this.aspect = fullWidth / fullHeight;
  8284. if (this.view === null) {
  8285. this.view = {
  8286. enabled: true,
  8287. fullWidth: 1,
  8288. fullHeight: 1,
  8289. offsetX: 0,
  8290. offsetY: 0,
  8291. width: 1,
  8292. height: 1
  8293. };
  8294. }
  8295. this.view.enabled = true;
  8296. this.view.fullWidth = fullWidth;
  8297. this.view.fullHeight = fullHeight;
  8298. this.view.offsetX = x;
  8299. this.view.offsetY = y;
  8300. this.view.width = width;
  8301. this.view.height = height;
  8302. this.updateProjectionMatrix();
  8303. },
  8304. clearViewOffset: function clearViewOffset() {
  8305. if (this.view !== null) {
  8306. this.view.enabled = false;
  8307. }
  8308. this.updateProjectionMatrix();
  8309. },
  8310. updateProjectionMatrix: function updateProjectionMatrix() {
  8311. var near = this.near;
  8312. var top = near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov) / this.zoom;
  8313. var height = 2 * top;
  8314. var width = this.aspect * height;
  8315. var left = -0.5 * width;
  8316. var view = this.view;
  8317. if (this.view !== null && this.view.enabled) {
  8318. var fullWidth = view.fullWidth,
  8319. fullHeight = view.fullHeight;
  8320. left += view.offsetX * width / fullWidth;
  8321. top -= view.offsetY * height / fullHeight;
  8322. width *= view.width / fullWidth;
  8323. height *= view.height / fullHeight;
  8324. }
  8325. var skew = this.filmOffset;
  8326. if (skew !== 0) left += near * skew / this.getFilmWidth();
  8327. this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far);
  8328. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  8329. },
  8330. toJSON: function toJSON(meta) {
  8331. var data = Object3D.prototype.toJSON.call(this, meta);
  8332. data.object.fov = this.fov;
  8333. data.object.zoom = this.zoom;
  8334. data.object.near = this.near;
  8335. data.object.far = this.far;
  8336. data.object.focus = this.focus;
  8337. data.object.aspect = this.aspect;
  8338. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  8339. data.object.filmGauge = this.filmGauge;
  8340. data.object.filmOffset = this.filmOffset;
  8341. return data;
  8342. }
  8343. });
  8344. var fov = 90,
  8345. aspect = 1;
  8346. function CubeCamera(near, far, renderTarget) {
  8347. Object3D.call(this);
  8348. this.type = 'CubeCamera';
  8349. if (renderTarget.isWebGLCubeRenderTarget !== true) {
  8350. console.error('THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.');
  8351. return;
  8352. }
  8353. this.renderTarget = renderTarget;
  8354. var cameraPX = new PerspectiveCamera(fov, aspect, near, far);
  8355. cameraPX.layers = this.layers;
  8356. cameraPX.up.set(0, -1, 0);
  8357. cameraPX.lookAt(new Vector3(1, 0, 0));
  8358. this.add(cameraPX);
  8359. var cameraNX = new PerspectiveCamera(fov, aspect, near, far);
  8360. cameraNX.layers = this.layers;
  8361. cameraNX.up.set(0, -1, 0);
  8362. cameraNX.lookAt(new Vector3(-1, 0, 0));
  8363. this.add(cameraNX);
  8364. var cameraPY = new PerspectiveCamera(fov, aspect, near, far);
  8365. cameraPY.layers = this.layers;
  8366. cameraPY.up.set(0, 0, 1);
  8367. cameraPY.lookAt(new Vector3(0, 1, 0));
  8368. this.add(cameraPY);
  8369. var cameraNY = new PerspectiveCamera(fov, aspect, near, far);
  8370. cameraNY.layers = this.layers;
  8371. cameraNY.up.set(0, 0, -1);
  8372. cameraNY.lookAt(new Vector3(0, -1, 0));
  8373. this.add(cameraNY);
  8374. var cameraPZ = new PerspectiveCamera(fov, aspect, near, far);
  8375. cameraPZ.layers = this.layers;
  8376. cameraPZ.up.set(0, -1, 0);
  8377. cameraPZ.lookAt(new Vector3(0, 0, 1));
  8378. this.add(cameraPZ);
  8379. var cameraNZ = new PerspectiveCamera(fov, aspect, near, far);
  8380. cameraNZ.layers = this.layers;
  8381. cameraNZ.up.set(0, -1, 0);
  8382. cameraNZ.lookAt(new Vector3(0, 0, -1));
  8383. this.add(cameraNZ);
  8384. this.update = function (renderer, scene) {
  8385. if (this.parent === null) this.updateMatrixWorld();
  8386. var currentXrEnabled = renderer.xr.enabled;
  8387. var currentRenderTarget = renderer.getRenderTarget();
  8388. renderer.xr.enabled = false;
  8389. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8390. renderTarget.texture.generateMipmaps = false;
  8391. renderer.setRenderTarget(renderTarget, 0);
  8392. renderer.render(scene, cameraPX);
  8393. renderer.setRenderTarget(renderTarget, 1);
  8394. renderer.render(scene, cameraNX);
  8395. renderer.setRenderTarget(renderTarget, 2);
  8396. renderer.render(scene, cameraPY);
  8397. renderer.setRenderTarget(renderTarget, 3);
  8398. renderer.render(scene, cameraNY);
  8399. renderer.setRenderTarget(renderTarget, 4);
  8400. renderer.render(scene, cameraPZ);
  8401. renderTarget.texture.generateMipmaps = generateMipmaps;
  8402. renderer.setRenderTarget(renderTarget, 5);
  8403. renderer.render(scene, cameraNZ);
  8404. renderer.setRenderTarget(currentRenderTarget);
  8405. renderer.xr.enabled = currentXrEnabled;
  8406. };
  8407. }
  8408. CubeCamera.prototype = Object.create(Object3D.prototype);
  8409. CubeCamera.prototype.constructor = CubeCamera;
  8410. function CubeTexture(images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding) {
  8411. images = images !== undefined ? images : [];
  8412. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  8413. format = format !== undefined ? format : RGBFormat;
  8414. Texture.call(this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8415. this.flipY = false; // Why CubeTexture._needsFlipEnvMap is necessary:
  8416. //
  8417. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  8418. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  8419. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  8420. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  8421. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  8422. // when using WebGLCubeRenderTarget.texture as a cube texture.
  8423. this._needsFlipEnvMap = true;
  8424. }
  8425. CubeTexture.prototype = Object.create(Texture.prototype);
  8426. CubeTexture.prototype.constructor = CubeTexture;
  8427. CubeTexture.prototype.isCubeTexture = true;
  8428. Object.defineProperty(CubeTexture.prototype, 'images', {
  8429. get: function get() {
  8430. return this.image;
  8431. },
  8432. set: function set(value) {
  8433. this.image = value;
  8434. }
  8435. });
  8436. var WebGLCubeRenderTarget = /*#__PURE__*/function (_WebGLRenderTarget) {
  8437. _inheritsLoose(WebGLCubeRenderTarget, _WebGLRenderTarget);
  8438. function WebGLCubeRenderTarget(size, options, dummy) {
  8439. var _this;
  8440. if (Number.isInteger(options)) {
  8441. console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');
  8442. options = dummy;
  8443. }
  8444. _this = _WebGLRenderTarget.call(this, size, size, options) || this;
  8445. Object.defineProperty(_assertThisInitialized(_this), 'isWebGLCubeRenderTarget', {
  8446. value: true
  8447. });
  8448. options = options || {};
  8449. _this.texture = new CubeTexture(undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding);
  8450. _this.texture._needsFlipEnvMap = false;
  8451. return _this;
  8452. }
  8453. var _proto = WebGLCubeRenderTarget.prototype;
  8454. _proto.fromEquirectangularTexture = function fromEquirectangularTexture(renderer, texture) {
  8455. this.texture.type = texture.type;
  8456. this.texture.format = RGBAFormat; // see #18859
  8457. this.texture.encoding = texture.encoding;
  8458. this.texture.generateMipmaps = texture.generateMipmaps;
  8459. this.texture.minFilter = texture.minFilter;
  8460. this.texture.magFilter = texture.magFilter;
  8461. var shader = {
  8462. uniforms: {
  8463. tEquirect: {
  8464. value: null
  8465. }
  8466. },
  8467. vertexShader:
  8468. /* glsl */
  8469. "\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",
  8470. fragmentShader:
  8471. /* glsl */
  8472. "\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"
  8473. };
  8474. var geometry = new BoxGeometry(5, 5, 5);
  8475. var material = new ShaderMaterial({
  8476. name: 'CubemapFromEquirect',
  8477. uniforms: cloneUniforms(shader.uniforms),
  8478. vertexShader: shader.vertexShader,
  8479. fragmentShader: shader.fragmentShader,
  8480. side: BackSide,
  8481. blending: NoBlending
  8482. });
  8483. material.uniforms.tEquirect.value = texture;
  8484. var mesh = new Mesh(geometry, material);
  8485. var currentMinFilter = texture.minFilter; // Avoid blurred poles
  8486. if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter;
  8487. var camera = new CubeCamera(1, 10, this);
  8488. camera.update(renderer, mesh);
  8489. texture.minFilter = currentMinFilter;
  8490. mesh.geometry.dispose();
  8491. mesh.material.dispose();
  8492. return this;
  8493. };
  8494. _proto.clear = function clear(renderer, color, depth, stencil) {
  8495. var currentRenderTarget = renderer.getRenderTarget();
  8496. for (var i = 0; i < 6; i++) {
  8497. renderer.setRenderTarget(this, i);
  8498. renderer.clear(color, depth, stencil);
  8499. }
  8500. renderer.setRenderTarget(currentRenderTarget);
  8501. };
  8502. return WebGLCubeRenderTarget;
  8503. }(WebGLRenderTarget);
  8504. function DataTexture(data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  8505. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  8506. this.image = {
  8507. data: data || null,
  8508. width: width || 1,
  8509. height: height || 1
  8510. };
  8511. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8512. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8513. this.generateMipmaps = false;
  8514. this.flipY = false;
  8515. this.unpackAlignment = 1;
  8516. this.needsUpdate = true;
  8517. }
  8518. DataTexture.prototype = Object.create(Texture.prototype);
  8519. DataTexture.prototype.constructor = DataTexture;
  8520. DataTexture.prototype.isDataTexture = true;
  8521. var _sphere$1 = /*@__PURE__*/new Sphere();
  8522. var _vector$5 = /*@__PURE__*/new Vector3();
  8523. var Frustum = /*#__PURE__*/function () {
  8524. function Frustum(p0, p1, p2, p3, p4, p5) {
  8525. 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()];
  8526. }
  8527. var _proto = Frustum.prototype;
  8528. _proto.set = function set(p0, p1, p2, p3, p4, p5) {
  8529. var planes = this.planes;
  8530. planes[0].copy(p0);
  8531. planes[1].copy(p1);
  8532. planes[2].copy(p2);
  8533. planes[3].copy(p3);
  8534. planes[4].copy(p4);
  8535. planes[5].copy(p5);
  8536. return this;
  8537. };
  8538. _proto.clone = function clone() {
  8539. return new this.constructor().copy(this);
  8540. };
  8541. _proto.copy = function copy(frustum) {
  8542. var planes = this.planes;
  8543. for (var i = 0; i < 6; i++) {
  8544. planes[i].copy(frustum.planes[i]);
  8545. }
  8546. return this;
  8547. };
  8548. _proto.setFromProjectionMatrix = function setFromProjectionMatrix(m) {
  8549. var planes = this.planes;
  8550. var me = m.elements;
  8551. var me0 = me[0],
  8552. me1 = me[1],
  8553. me2 = me[2],
  8554. me3 = me[3];
  8555. var me4 = me[4],
  8556. me5 = me[5],
  8557. me6 = me[6],
  8558. me7 = me[7];
  8559. var me8 = me[8],
  8560. me9 = me[9],
  8561. me10 = me[10],
  8562. me11 = me[11];
  8563. var me12 = me[12],
  8564. me13 = me[13],
  8565. me14 = me[14],
  8566. me15 = me[15];
  8567. planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize();
  8568. planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize();
  8569. planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize();
  8570. planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize();
  8571. planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize();
  8572. planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize();
  8573. return this;
  8574. };
  8575. _proto.intersectsObject = function intersectsObject(object) {
  8576. var geometry = object.geometry;
  8577. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  8578. _sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);
  8579. return this.intersectsSphere(_sphere$1);
  8580. };
  8581. _proto.intersectsSprite = function intersectsSprite(sprite) {
  8582. _sphere$1.center.set(0, 0, 0);
  8583. _sphere$1.radius = 0.7071067811865476;
  8584. _sphere$1.applyMatrix4(sprite.matrixWorld);
  8585. return this.intersectsSphere(_sphere$1);
  8586. };
  8587. _proto.intersectsSphere = function intersectsSphere(sphere) {
  8588. var planes = this.planes;
  8589. var center = sphere.center;
  8590. var negRadius = -sphere.radius;
  8591. for (var i = 0; i < 6; i++) {
  8592. var distance = planes[i].distanceToPoint(center);
  8593. if (distance < negRadius) {
  8594. return false;
  8595. }
  8596. }
  8597. return true;
  8598. };
  8599. _proto.intersectsBox = function intersectsBox(box) {
  8600. var planes = this.planes;
  8601. for (var i = 0; i < 6; i++) {
  8602. var plane = planes[i]; // corner at max distance
  8603. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8604. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8605. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8606. if (plane.distanceToPoint(_vector$5) < 0) {
  8607. return false;
  8608. }
  8609. }
  8610. return true;
  8611. };
  8612. _proto.containsPoint = function containsPoint(point) {
  8613. var planes = this.planes;
  8614. for (var i = 0; i < 6; i++) {
  8615. if (planes[i].distanceToPoint(point) < 0) {
  8616. return false;
  8617. }
  8618. }
  8619. return true;
  8620. };
  8621. return Frustum;
  8622. }();
  8623. function WebGLAnimation() {
  8624. var context = null;
  8625. var isAnimating = false;
  8626. var animationLoop = null;
  8627. var requestId = null;
  8628. function onAnimationFrame(time, frame) {
  8629. animationLoop(time, frame);
  8630. requestId = context.requestAnimationFrame(onAnimationFrame);
  8631. }
  8632. return {
  8633. start: function start() {
  8634. if (isAnimating === true) return;
  8635. if (animationLoop === null) return;
  8636. requestId = context.requestAnimationFrame(onAnimationFrame);
  8637. isAnimating = true;
  8638. },
  8639. stop: function stop() {
  8640. context.cancelAnimationFrame(requestId);
  8641. isAnimating = false;
  8642. },
  8643. setAnimationLoop: function setAnimationLoop(callback) {
  8644. animationLoop = callback;
  8645. },
  8646. setContext: function setContext(value) {
  8647. context = value;
  8648. }
  8649. };
  8650. }
  8651. function WebGLAttributes(gl, capabilities) {
  8652. var isWebGL2 = capabilities.isWebGL2;
  8653. var buffers = new WeakMap();
  8654. function createBuffer(attribute, bufferType) {
  8655. var array = attribute.array;
  8656. var usage = attribute.usage;
  8657. var buffer = gl.createBuffer();
  8658. gl.bindBuffer(bufferType, buffer);
  8659. gl.bufferData(bufferType, array, usage);
  8660. attribute.onUploadCallback();
  8661. var type = 5126;
  8662. if (array instanceof Float32Array) {
  8663. type = 5126;
  8664. } else if (array instanceof Float64Array) {
  8665. console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
  8666. } else if (array instanceof Uint16Array) {
  8667. if (attribute.isFloat16BufferAttribute) {
  8668. if (isWebGL2) {
  8669. type = 5131;
  8670. } else {
  8671. console.warn('THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
  8672. }
  8673. } else {
  8674. type = 5123;
  8675. }
  8676. } else if (array instanceof Int16Array) {
  8677. type = 5122;
  8678. } else if (array instanceof Uint32Array) {
  8679. type = 5125;
  8680. } else if (array instanceof Int32Array) {
  8681. type = 5124;
  8682. } else if (array instanceof Int8Array) {
  8683. type = 5120;
  8684. } else if (array instanceof Uint8Array) {
  8685. type = 5121;
  8686. }
  8687. return {
  8688. buffer: buffer,
  8689. type: type,
  8690. bytesPerElement: array.BYTES_PER_ELEMENT,
  8691. version: attribute.version
  8692. };
  8693. }
  8694. function updateBuffer(buffer, attribute, bufferType) {
  8695. var array = attribute.array;
  8696. var updateRange = attribute.updateRange;
  8697. gl.bindBuffer(bufferType, buffer);
  8698. if (updateRange.count === -1) {
  8699. // Not using update ranges
  8700. gl.bufferSubData(bufferType, 0, array);
  8701. } else {
  8702. if (isWebGL2) {
  8703. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count);
  8704. } else {
  8705. gl.bufferSubData(bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count));
  8706. }
  8707. updateRange.count = -1; // reset range
  8708. }
  8709. } //
  8710. function get(attribute) {
  8711. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8712. return buffers.get(attribute);
  8713. }
  8714. function remove(attribute) {
  8715. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8716. var data = buffers.get(attribute);
  8717. if (data) {
  8718. gl.deleteBuffer(data.buffer);
  8719. buffers.delete(attribute);
  8720. }
  8721. }
  8722. function update(attribute, bufferType) {
  8723. if (attribute.isGLBufferAttribute) {
  8724. var cached = buffers.get(attribute);
  8725. if (!cached || cached.version < attribute.version) {
  8726. buffers.set(attribute, {
  8727. buffer: attribute.buffer,
  8728. type: attribute.type,
  8729. bytesPerElement: attribute.elementSize,
  8730. version: attribute.version
  8731. });
  8732. }
  8733. return;
  8734. }
  8735. if (attribute.isInterleavedBufferAttribute) attribute = attribute.data;
  8736. var data = buffers.get(attribute);
  8737. if (data === undefined) {
  8738. buffers.set(attribute, createBuffer(attribute, bufferType));
  8739. } else if (data.version < attribute.version) {
  8740. updateBuffer(data.buffer, attribute, bufferType);
  8741. data.version = attribute.version;
  8742. }
  8743. }
  8744. return {
  8745. get: get,
  8746. remove: remove,
  8747. update: update
  8748. };
  8749. }
  8750. var PlaneGeometry = /*#__PURE__*/function (_BufferGeometry) {
  8751. _inheritsLoose(PlaneGeometry, _BufferGeometry);
  8752. function PlaneGeometry(width, height, widthSegments, heightSegments) {
  8753. var _this;
  8754. if (width === void 0) {
  8755. width = 1;
  8756. }
  8757. if (height === void 0) {
  8758. height = 1;
  8759. }
  8760. if (widthSegments === void 0) {
  8761. widthSegments = 1;
  8762. }
  8763. if (heightSegments === void 0) {
  8764. heightSegments = 1;
  8765. }
  8766. _this = _BufferGeometry.call(this) || this;
  8767. _this.type = 'PlaneGeometry';
  8768. _this.parameters = {
  8769. width: width,
  8770. height: height,
  8771. widthSegments: widthSegments,
  8772. heightSegments: heightSegments
  8773. };
  8774. var width_half = width / 2;
  8775. var height_half = height / 2;
  8776. var gridX = Math.floor(widthSegments);
  8777. var gridY = Math.floor(heightSegments);
  8778. var gridX1 = gridX + 1;
  8779. var gridY1 = gridY + 1;
  8780. var segment_width = width / gridX;
  8781. var segment_height = height / gridY; //
  8782. var indices = [];
  8783. var vertices = [];
  8784. var normals = [];
  8785. var uvs = [];
  8786. for (var iy = 0; iy < gridY1; iy++) {
  8787. var y = iy * segment_height - height_half;
  8788. for (var ix = 0; ix < gridX1; ix++) {
  8789. var x = ix * segment_width - width_half;
  8790. vertices.push(x, -y, 0);
  8791. normals.push(0, 0, 1);
  8792. uvs.push(ix / gridX);
  8793. uvs.push(1 - iy / gridY);
  8794. }
  8795. }
  8796. for (var _iy = 0; _iy < gridY; _iy++) {
  8797. for (var _ix = 0; _ix < gridX; _ix++) {
  8798. var a = _ix + gridX1 * _iy;
  8799. var b = _ix + gridX1 * (_iy + 1);
  8800. var c = _ix + 1 + gridX1 * (_iy + 1);
  8801. var d = _ix + 1 + gridX1 * _iy;
  8802. indices.push(a, b, d);
  8803. indices.push(b, c, d);
  8804. }
  8805. }
  8806. _this.setIndex(indices);
  8807. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  8808. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  8809. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  8810. return _this;
  8811. }
  8812. return PlaneGeometry;
  8813. }(BufferGeometry);
  8814. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8815. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8816. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8817. 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";
  8818. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8819. var begin_vertex = "vec3 transformed = vec3( position );";
  8820. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8821. 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";
  8822. 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 ) {\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 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\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";
  8823. 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";
  8824. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  8825. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  8826. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  8827. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8828. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8829. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  8830. 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";
  8831. 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}";
  8832. 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";
  8833. 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";
  8834. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8835. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  8836. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8837. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8838. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8839. 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}";
  8840. 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";
  8841. 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";
  8842. 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";
  8843. 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";
  8844. 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";
  8845. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  8846. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8847. 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";
  8848. 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";
  8849. 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}";
  8850. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  8851. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8852. 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";
  8853. 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";
  8854. 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";
  8855. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  8856. 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)";
  8857. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8858. 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)";
  8859. 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";
  8860. 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}";
  8861. 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";
  8862. 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";
  8863. 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";
  8864. 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";
  8865. 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";
  8866. 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";
  8867. 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";
  8868. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8869. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8870. 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";
  8871. 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";
  8872. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8873. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8874. 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";
  8875. 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";
  8876. 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";
  8877. var normal_fragment_begin = "#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 * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\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 * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\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;";
  8878. 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 * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\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 );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  8879. 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 ) {\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 *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";
  8880. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  8881. 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 );\n\t#endif\n#endif";
  8882. 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";
  8883. 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}";
  8884. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8885. 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;";
  8886. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8887. 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";
  8888. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8889. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8890. 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";
  8891. 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";
  8892. 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";
  8893. 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}";
  8894. 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";
  8895. 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";
  8896. 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";
  8897. 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";
  8898. 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";
  8899. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8900. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8901. 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; }";
  8902. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  8903. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  8904. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  8905. 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";
  8906. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  8907. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8908. 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";
  8909. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  8910. 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";
  8911. 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}";
  8912. 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}";
  8913. 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}";
  8914. 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}";
  8915. 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}";
  8916. 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}";
  8917. 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}";
  8918. 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}";
  8919. 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}";
  8920. 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}";
  8921. 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}";
  8922. 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}";
  8923. 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}";
  8924. 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}";
  8925. 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}";
  8926. 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}";
  8927. 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}";
  8928. 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}";
  8929. 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}";
  8930. 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}";
  8931. 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}";
  8932. 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}";
  8933. 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}";
  8934. 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}";
  8935. 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}";
  8936. 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}";
  8937. 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}";
  8938. 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}";
  8939. 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}";
  8940. 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}";
  8941. 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}";
  8942. 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}";
  8943. var ShaderChunk = {
  8944. alphamap_fragment: alphamap_fragment,
  8945. alphamap_pars_fragment: alphamap_pars_fragment,
  8946. alphatest_fragment: alphatest_fragment,
  8947. aomap_fragment: aomap_fragment,
  8948. aomap_pars_fragment: aomap_pars_fragment,
  8949. begin_vertex: begin_vertex,
  8950. beginnormal_vertex: beginnormal_vertex,
  8951. bsdfs: bsdfs,
  8952. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8953. clipping_planes_fragment: clipping_planes_fragment,
  8954. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8955. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8956. clipping_planes_vertex: clipping_planes_vertex,
  8957. color_fragment: color_fragment,
  8958. color_pars_fragment: color_pars_fragment,
  8959. color_pars_vertex: color_pars_vertex,
  8960. color_vertex: color_vertex,
  8961. common: common,
  8962. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8963. defaultnormal_vertex: defaultnormal_vertex,
  8964. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8965. displacementmap_vertex: displacementmap_vertex,
  8966. emissivemap_fragment: emissivemap_fragment,
  8967. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8968. encodings_fragment: encodings_fragment,
  8969. encodings_pars_fragment: encodings_pars_fragment,
  8970. envmap_fragment: envmap_fragment,
  8971. envmap_common_pars_fragment: envmap_common_pars_fragment,
  8972. envmap_pars_fragment: envmap_pars_fragment,
  8973. envmap_pars_vertex: envmap_pars_vertex,
  8974. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8975. envmap_vertex: envmap_vertex,
  8976. fog_vertex: fog_vertex,
  8977. fog_pars_vertex: fog_pars_vertex,
  8978. fog_fragment: fog_fragment,
  8979. fog_pars_fragment: fog_pars_fragment,
  8980. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8981. lightmap_fragment: lightmap_fragment,
  8982. lightmap_pars_fragment: lightmap_pars_fragment,
  8983. lights_lambert_vertex: lights_lambert_vertex,
  8984. lights_pars_begin: lights_pars_begin,
  8985. lights_toon_fragment: lights_toon_fragment,
  8986. lights_toon_pars_fragment: lights_toon_pars_fragment,
  8987. lights_phong_fragment: lights_phong_fragment,
  8988. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8989. lights_physical_fragment: lights_physical_fragment,
  8990. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8991. lights_fragment_begin: lights_fragment_begin,
  8992. lights_fragment_maps: lights_fragment_maps,
  8993. lights_fragment_end: lights_fragment_end,
  8994. logdepthbuf_fragment: logdepthbuf_fragment,
  8995. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8996. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8997. logdepthbuf_vertex: logdepthbuf_vertex,
  8998. map_fragment: map_fragment,
  8999. map_pars_fragment: map_pars_fragment,
  9000. map_particle_fragment: map_particle_fragment,
  9001. map_particle_pars_fragment: map_particle_pars_fragment,
  9002. metalnessmap_fragment: metalnessmap_fragment,
  9003. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  9004. morphnormal_vertex: morphnormal_vertex,
  9005. morphtarget_pars_vertex: morphtarget_pars_vertex,
  9006. morphtarget_vertex: morphtarget_vertex,
  9007. normal_fragment_begin: normal_fragment_begin,
  9008. normal_fragment_maps: normal_fragment_maps,
  9009. normalmap_pars_fragment: normalmap_pars_fragment,
  9010. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  9011. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  9012. clearcoat_pars_fragment: clearcoat_pars_fragment,
  9013. packing: packing,
  9014. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  9015. project_vertex: project_vertex,
  9016. dithering_fragment: dithering_fragment,
  9017. dithering_pars_fragment: dithering_pars_fragment,
  9018. roughnessmap_fragment: roughnessmap_fragment,
  9019. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  9020. shadowmap_pars_fragment: shadowmap_pars_fragment,
  9021. shadowmap_pars_vertex: shadowmap_pars_vertex,
  9022. shadowmap_vertex: shadowmap_vertex,
  9023. shadowmask_pars_fragment: shadowmask_pars_fragment,
  9024. skinbase_vertex: skinbase_vertex,
  9025. skinning_pars_vertex: skinning_pars_vertex,
  9026. skinning_vertex: skinning_vertex,
  9027. skinnormal_vertex: skinnormal_vertex,
  9028. specularmap_fragment: specularmap_fragment,
  9029. specularmap_pars_fragment: specularmap_pars_fragment,
  9030. tonemapping_fragment: tonemapping_fragment,
  9031. tonemapping_pars_fragment: tonemapping_pars_fragment,
  9032. transmissionmap_fragment: transmissionmap_fragment,
  9033. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  9034. uv_pars_fragment: uv_pars_fragment,
  9035. uv_pars_vertex: uv_pars_vertex,
  9036. uv_vertex: uv_vertex,
  9037. uv2_pars_fragment: uv2_pars_fragment,
  9038. uv2_pars_vertex: uv2_pars_vertex,
  9039. uv2_vertex: uv2_vertex,
  9040. worldpos_vertex: worldpos_vertex,
  9041. background_frag: background_frag,
  9042. background_vert: background_vert,
  9043. cube_frag: cube_frag,
  9044. cube_vert: cube_vert,
  9045. depth_frag: depth_frag,
  9046. depth_vert: depth_vert,
  9047. distanceRGBA_frag: distanceRGBA_frag,
  9048. distanceRGBA_vert: distanceRGBA_vert,
  9049. equirect_frag: equirect_frag,
  9050. equirect_vert: equirect_vert,
  9051. linedashed_frag: linedashed_frag,
  9052. linedashed_vert: linedashed_vert,
  9053. meshbasic_frag: meshbasic_frag,
  9054. meshbasic_vert: meshbasic_vert,
  9055. meshlambert_frag: meshlambert_frag,
  9056. meshlambert_vert: meshlambert_vert,
  9057. meshmatcap_frag: meshmatcap_frag,
  9058. meshmatcap_vert: meshmatcap_vert,
  9059. meshtoon_frag: meshtoon_frag,
  9060. meshtoon_vert: meshtoon_vert,
  9061. meshphong_frag: meshphong_frag,
  9062. meshphong_vert: meshphong_vert,
  9063. meshphysical_frag: meshphysical_frag,
  9064. meshphysical_vert: meshphysical_vert,
  9065. normal_frag: normal_frag,
  9066. normal_vert: normal_vert,
  9067. points_frag: points_frag,
  9068. points_vert: points_vert,
  9069. shadow_frag: shadow_frag,
  9070. shadow_vert: shadow_vert,
  9071. sprite_frag: sprite_frag,
  9072. sprite_vert: sprite_vert
  9073. };
  9074. /**
  9075. * Uniforms library for shared webgl shaders
  9076. */
  9077. var UniformsLib = {
  9078. common: {
  9079. diffuse: {
  9080. value: new Color(0xeeeeee)
  9081. },
  9082. opacity: {
  9083. value: 1.0
  9084. },
  9085. map: {
  9086. value: null
  9087. },
  9088. uvTransform: {
  9089. value: new Matrix3()
  9090. },
  9091. uv2Transform: {
  9092. value: new Matrix3()
  9093. },
  9094. alphaMap: {
  9095. value: null
  9096. }
  9097. },
  9098. specularmap: {
  9099. specularMap: {
  9100. value: null
  9101. }
  9102. },
  9103. envmap: {
  9104. envMap: {
  9105. value: null
  9106. },
  9107. flipEnvMap: {
  9108. value: -1
  9109. },
  9110. reflectivity: {
  9111. value: 1.0
  9112. },
  9113. refractionRatio: {
  9114. value: 0.98
  9115. },
  9116. maxMipLevel: {
  9117. value: 0
  9118. }
  9119. },
  9120. aomap: {
  9121. aoMap: {
  9122. value: null
  9123. },
  9124. aoMapIntensity: {
  9125. value: 1
  9126. }
  9127. },
  9128. lightmap: {
  9129. lightMap: {
  9130. value: null
  9131. },
  9132. lightMapIntensity: {
  9133. value: 1
  9134. }
  9135. },
  9136. emissivemap: {
  9137. emissiveMap: {
  9138. value: null
  9139. }
  9140. },
  9141. bumpmap: {
  9142. bumpMap: {
  9143. value: null
  9144. },
  9145. bumpScale: {
  9146. value: 1
  9147. }
  9148. },
  9149. normalmap: {
  9150. normalMap: {
  9151. value: null
  9152. },
  9153. normalScale: {
  9154. value: new Vector2(1, 1)
  9155. }
  9156. },
  9157. displacementmap: {
  9158. displacementMap: {
  9159. value: null
  9160. },
  9161. displacementScale: {
  9162. value: 1
  9163. },
  9164. displacementBias: {
  9165. value: 0
  9166. }
  9167. },
  9168. roughnessmap: {
  9169. roughnessMap: {
  9170. value: null
  9171. }
  9172. },
  9173. metalnessmap: {
  9174. metalnessMap: {
  9175. value: null
  9176. }
  9177. },
  9178. gradientmap: {
  9179. gradientMap: {
  9180. value: null
  9181. }
  9182. },
  9183. fog: {
  9184. fogDensity: {
  9185. value: 0.00025
  9186. },
  9187. fogNear: {
  9188. value: 1
  9189. },
  9190. fogFar: {
  9191. value: 2000
  9192. },
  9193. fogColor: {
  9194. value: new Color(0xffffff)
  9195. }
  9196. },
  9197. lights: {
  9198. ambientLightColor: {
  9199. value: []
  9200. },
  9201. lightProbe: {
  9202. value: []
  9203. },
  9204. directionalLights: {
  9205. value: [],
  9206. properties: {
  9207. direction: {},
  9208. color: {}
  9209. }
  9210. },
  9211. directionalLightShadows: {
  9212. value: [],
  9213. properties: {
  9214. shadowBias: {},
  9215. shadowNormalBias: {},
  9216. shadowRadius: {},
  9217. shadowMapSize: {}
  9218. }
  9219. },
  9220. directionalShadowMap: {
  9221. value: []
  9222. },
  9223. directionalShadowMatrix: {
  9224. value: []
  9225. },
  9226. spotLights: {
  9227. value: [],
  9228. properties: {
  9229. color: {},
  9230. position: {},
  9231. direction: {},
  9232. distance: {},
  9233. coneCos: {},
  9234. penumbraCos: {},
  9235. decay: {}
  9236. }
  9237. },
  9238. spotLightShadows: {
  9239. value: [],
  9240. properties: {
  9241. shadowBias: {},
  9242. shadowNormalBias: {},
  9243. shadowRadius: {},
  9244. shadowMapSize: {}
  9245. }
  9246. },
  9247. spotShadowMap: {
  9248. value: []
  9249. },
  9250. spotShadowMatrix: {
  9251. value: []
  9252. },
  9253. pointLights: {
  9254. value: [],
  9255. properties: {
  9256. color: {},
  9257. position: {},
  9258. decay: {},
  9259. distance: {}
  9260. }
  9261. },
  9262. pointLightShadows: {
  9263. value: [],
  9264. properties: {
  9265. shadowBias: {},
  9266. shadowNormalBias: {},
  9267. shadowRadius: {},
  9268. shadowMapSize: {},
  9269. shadowCameraNear: {},
  9270. shadowCameraFar: {}
  9271. }
  9272. },
  9273. pointShadowMap: {
  9274. value: []
  9275. },
  9276. pointShadowMatrix: {
  9277. value: []
  9278. },
  9279. hemisphereLights: {
  9280. value: [],
  9281. properties: {
  9282. direction: {},
  9283. skyColor: {},
  9284. groundColor: {}
  9285. }
  9286. },
  9287. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  9288. rectAreaLights: {
  9289. value: [],
  9290. properties: {
  9291. color: {},
  9292. position: {},
  9293. width: {},
  9294. height: {}
  9295. }
  9296. },
  9297. ltc_1: {
  9298. value: null
  9299. },
  9300. ltc_2: {
  9301. value: null
  9302. }
  9303. },
  9304. points: {
  9305. diffuse: {
  9306. value: new Color(0xeeeeee)
  9307. },
  9308. opacity: {
  9309. value: 1.0
  9310. },
  9311. size: {
  9312. value: 1.0
  9313. },
  9314. scale: {
  9315. value: 1.0
  9316. },
  9317. map: {
  9318. value: null
  9319. },
  9320. alphaMap: {
  9321. value: null
  9322. },
  9323. uvTransform: {
  9324. value: new Matrix3()
  9325. }
  9326. },
  9327. sprite: {
  9328. diffuse: {
  9329. value: new Color(0xeeeeee)
  9330. },
  9331. opacity: {
  9332. value: 1.0
  9333. },
  9334. center: {
  9335. value: new Vector2(0.5, 0.5)
  9336. },
  9337. rotation: {
  9338. value: 0.0
  9339. },
  9340. map: {
  9341. value: null
  9342. },
  9343. alphaMap: {
  9344. value: null
  9345. },
  9346. uvTransform: {
  9347. value: new Matrix3()
  9348. }
  9349. }
  9350. };
  9351. var ShaderLib = {
  9352. basic: {
  9353. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog]),
  9354. vertexShader: ShaderChunk.meshbasic_vert,
  9355. fragmentShader: ShaderChunk.meshbasic_frag
  9356. },
  9357. lambert: {
  9358. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.fog, UniformsLib.lights, {
  9359. emissive: {
  9360. value: new Color(0x000000)
  9361. }
  9362. }]),
  9363. vertexShader: ShaderChunk.meshlambert_vert,
  9364. fragmentShader: ShaderChunk.meshlambert_frag
  9365. },
  9366. phong: {
  9367. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, {
  9368. emissive: {
  9369. value: new Color(0x000000)
  9370. },
  9371. specular: {
  9372. value: new Color(0x111111)
  9373. },
  9374. shininess: {
  9375. value: 30
  9376. }
  9377. }]),
  9378. vertexShader: ShaderChunk.meshphong_vert,
  9379. fragmentShader: ShaderChunk.meshphong_frag
  9380. },
  9381. standard: {
  9382. 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, {
  9383. emissive: {
  9384. value: new Color(0x000000)
  9385. },
  9386. roughness: {
  9387. value: 1.0
  9388. },
  9389. metalness: {
  9390. value: 0.0
  9391. },
  9392. envMapIntensity: {
  9393. value: 1
  9394. } // temporary
  9395. }]),
  9396. vertexShader: ShaderChunk.meshphysical_vert,
  9397. fragmentShader: ShaderChunk.meshphysical_frag
  9398. },
  9399. toon: {
  9400. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, {
  9401. emissive: {
  9402. value: new Color(0x000000)
  9403. }
  9404. }]),
  9405. vertexShader: ShaderChunk.meshtoon_vert,
  9406. fragmentShader: ShaderChunk.meshtoon_frag
  9407. },
  9408. matcap: {
  9409. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, {
  9410. matcap: {
  9411. value: null
  9412. }
  9413. }]),
  9414. vertexShader: ShaderChunk.meshmatcap_vert,
  9415. fragmentShader: ShaderChunk.meshmatcap_frag
  9416. },
  9417. points: {
  9418. uniforms: mergeUniforms([UniformsLib.points, UniformsLib.fog]),
  9419. vertexShader: ShaderChunk.points_vert,
  9420. fragmentShader: ShaderChunk.points_frag
  9421. },
  9422. dashed: {
  9423. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.fog, {
  9424. scale: {
  9425. value: 1
  9426. },
  9427. dashSize: {
  9428. value: 1
  9429. },
  9430. totalSize: {
  9431. value: 2
  9432. }
  9433. }]),
  9434. vertexShader: ShaderChunk.linedashed_vert,
  9435. fragmentShader: ShaderChunk.linedashed_frag
  9436. },
  9437. depth: {
  9438. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap]),
  9439. vertexShader: ShaderChunk.depth_vert,
  9440. fragmentShader: ShaderChunk.depth_frag
  9441. },
  9442. normal: {
  9443. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, {
  9444. opacity: {
  9445. value: 1.0
  9446. }
  9447. }]),
  9448. vertexShader: ShaderChunk.normal_vert,
  9449. fragmentShader: ShaderChunk.normal_frag
  9450. },
  9451. sprite: {
  9452. uniforms: mergeUniforms([UniformsLib.sprite, UniformsLib.fog]),
  9453. vertexShader: ShaderChunk.sprite_vert,
  9454. fragmentShader: ShaderChunk.sprite_frag
  9455. },
  9456. background: {
  9457. uniforms: {
  9458. uvTransform: {
  9459. value: new Matrix3()
  9460. },
  9461. t2D: {
  9462. value: null
  9463. }
  9464. },
  9465. vertexShader: ShaderChunk.background_vert,
  9466. fragmentShader: ShaderChunk.background_frag
  9467. },
  9468. /* -------------------------------------------------------------------------
  9469. // Cube map shader
  9470. ------------------------------------------------------------------------- */
  9471. cube: {
  9472. uniforms: mergeUniforms([UniformsLib.envmap, {
  9473. opacity: {
  9474. value: 1.0
  9475. }
  9476. }]),
  9477. vertexShader: ShaderChunk.cube_vert,
  9478. fragmentShader: ShaderChunk.cube_frag
  9479. },
  9480. equirect: {
  9481. uniforms: {
  9482. tEquirect: {
  9483. value: null
  9484. }
  9485. },
  9486. vertexShader: ShaderChunk.equirect_vert,
  9487. fragmentShader: ShaderChunk.equirect_frag
  9488. },
  9489. distanceRGBA: {
  9490. uniforms: mergeUniforms([UniformsLib.common, UniformsLib.displacementmap, {
  9491. referencePosition: {
  9492. value: new Vector3()
  9493. },
  9494. nearDistance: {
  9495. value: 1
  9496. },
  9497. farDistance: {
  9498. value: 1000
  9499. }
  9500. }]),
  9501. vertexShader: ShaderChunk.distanceRGBA_vert,
  9502. fragmentShader: ShaderChunk.distanceRGBA_frag
  9503. },
  9504. shadow: {
  9505. uniforms: mergeUniforms([UniformsLib.lights, UniformsLib.fog, {
  9506. color: {
  9507. value: new Color(0x00000)
  9508. },
  9509. opacity: {
  9510. value: 1.0
  9511. }
  9512. }]),
  9513. vertexShader: ShaderChunk.shadow_vert,
  9514. fragmentShader: ShaderChunk.shadow_frag
  9515. }
  9516. };
  9517. ShaderLib.physical = {
  9518. uniforms: mergeUniforms([ShaderLib.standard.uniforms, {
  9519. clearcoat: {
  9520. value: 0
  9521. },
  9522. clearcoatMap: {
  9523. value: null
  9524. },
  9525. clearcoatRoughness: {
  9526. value: 0
  9527. },
  9528. clearcoatRoughnessMap: {
  9529. value: null
  9530. },
  9531. clearcoatNormalScale: {
  9532. value: new Vector2(1, 1)
  9533. },
  9534. clearcoatNormalMap: {
  9535. value: null
  9536. },
  9537. sheen: {
  9538. value: new Color(0x000000)
  9539. },
  9540. transmission: {
  9541. value: 0
  9542. },
  9543. transmissionMap: {
  9544. value: null
  9545. }
  9546. }]),
  9547. vertexShader: ShaderChunk.meshphysical_vert,
  9548. fragmentShader: ShaderChunk.meshphysical_frag
  9549. };
  9550. function WebGLBackground(renderer, cubemaps, state, objects, premultipliedAlpha) {
  9551. var clearColor = new Color(0x000000);
  9552. var clearAlpha = 0;
  9553. var planeMesh;
  9554. var boxMesh;
  9555. var currentBackground = null;
  9556. var currentBackgroundVersion = 0;
  9557. var currentTonemapping = null;
  9558. function render(renderList, scene, camera, forceClear) {
  9559. var background = scene.isScene === true ? scene.background : null;
  9560. if (background && background.isTexture) {
  9561. background = cubemaps.get(background);
  9562. } // Ignore background in AR
  9563. // TODO: Reconsider this.
  9564. var xr = renderer.xr;
  9565. var session = xr.getSession && xr.getSession();
  9566. if (session && session.environmentBlendMode === 'additive') {
  9567. background = null;
  9568. }
  9569. if (background === null) {
  9570. setClear(clearColor, clearAlpha);
  9571. } else if (background && background.isColor) {
  9572. setClear(background, 1);
  9573. forceClear = true;
  9574. }
  9575. if (renderer.autoClear || forceClear) {
  9576. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  9577. }
  9578. if (background && (background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping)) {
  9579. if (boxMesh === undefined) {
  9580. boxMesh = new Mesh(new BoxGeometry(1, 1, 1), new ShaderMaterial({
  9581. name: 'BackgroundCubeMaterial',
  9582. uniforms: cloneUniforms(ShaderLib.cube.uniforms),
  9583. vertexShader: ShaderLib.cube.vertexShader,
  9584. fragmentShader: ShaderLib.cube.fragmentShader,
  9585. side: BackSide,
  9586. depthTest: false,
  9587. depthWrite: false,
  9588. fog: false
  9589. }));
  9590. boxMesh.geometry.deleteAttribute('normal');
  9591. boxMesh.geometry.deleteAttribute('uv');
  9592. boxMesh.onBeforeRender = function (renderer, scene, camera) {
  9593. this.matrixWorld.copyPosition(camera.matrixWorld);
  9594. }; // enable code injection for non-built-in material
  9595. Object.defineProperty(boxMesh.material, 'envMap', {
  9596. get: function get() {
  9597. return this.uniforms.envMap.value;
  9598. }
  9599. });
  9600. objects.update(boxMesh);
  9601. }
  9602. if (background.isWebGLCubeRenderTarget) {
  9603. // TODO Deprecate
  9604. background = background.texture;
  9605. }
  9606. boxMesh.material.uniforms.envMap.value = background;
  9607. boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background._needsFlipEnvMap ? -1 : 1;
  9608. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9609. boxMesh.material.needsUpdate = true;
  9610. currentBackground = background;
  9611. currentBackgroundVersion = background.version;
  9612. currentTonemapping = renderer.toneMapping;
  9613. } // push to the pre-sorted opaque render list
  9614. renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null);
  9615. } else if (background && background.isTexture) {
  9616. if (planeMesh === undefined) {
  9617. planeMesh = new Mesh(new PlaneGeometry(2, 2), new ShaderMaterial({
  9618. name: 'BackgroundMaterial',
  9619. uniforms: cloneUniforms(ShaderLib.background.uniforms),
  9620. vertexShader: ShaderLib.background.vertexShader,
  9621. fragmentShader: ShaderLib.background.fragmentShader,
  9622. side: FrontSide,
  9623. depthTest: false,
  9624. depthWrite: false,
  9625. fog: false
  9626. }));
  9627. planeMesh.geometry.deleteAttribute('normal'); // enable code injection for non-built-in material
  9628. Object.defineProperty(planeMesh.material, 'map', {
  9629. get: function get() {
  9630. return this.uniforms.t2D.value;
  9631. }
  9632. });
  9633. objects.update(planeMesh);
  9634. }
  9635. planeMesh.material.uniforms.t2D.value = background;
  9636. if (background.matrixAutoUpdate === true) {
  9637. background.updateMatrix();
  9638. }
  9639. planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);
  9640. if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer.toneMapping) {
  9641. planeMesh.material.needsUpdate = true;
  9642. currentBackground = background;
  9643. currentBackgroundVersion = background.version;
  9644. currentTonemapping = renderer.toneMapping;
  9645. } // push to the pre-sorted opaque render list
  9646. renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null);
  9647. }
  9648. }
  9649. function setClear(color, alpha) {
  9650. state.buffers.color.setClear(color.r, color.g, color.b, alpha, premultipliedAlpha);
  9651. }
  9652. return {
  9653. getClearColor: function getClearColor() {
  9654. return clearColor;
  9655. },
  9656. setClearColor: function setClearColor(color, alpha) {
  9657. if (alpha === void 0) {
  9658. alpha = 1;
  9659. }
  9660. clearColor.set(color);
  9661. clearAlpha = alpha;
  9662. setClear(clearColor, clearAlpha);
  9663. },
  9664. getClearAlpha: function getClearAlpha() {
  9665. return clearAlpha;
  9666. },
  9667. setClearAlpha: function setClearAlpha(alpha) {
  9668. clearAlpha = alpha;
  9669. setClear(clearColor, clearAlpha);
  9670. },
  9671. render: render
  9672. };
  9673. }
  9674. function WebGLBindingStates(gl, extensions, attributes, capabilities) {
  9675. var maxVertexAttributes = gl.getParameter(34921);
  9676. var extension = capabilities.isWebGL2 ? null : extensions.get('OES_vertex_array_object');
  9677. var vaoAvailable = capabilities.isWebGL2 || extension !== null;
  9678. var bindingStates = {};
  9679. var defaultState = createBindingState(null);
  9680. var currentState = defaultState;
  9681. function setup(object, material, program, geometry, index) {
  9682. var updateBuffers = false;
  9683. if (vaoAvailable) {
  9684. var state = getBindingState(geometry, program, material);
  9685. if (currentState !== state) {
  9686. currentState = state;
  9687. bindVertexArrayObject(currentState.object);
  9688. }
  9689. updateBuffers = needsUpdate(geometry, index);
  9690. if (updateBuffers) saveCache(geometry, index);
  9691. } else {
  9692. var wireframe = material.wireframe === true;
  9693. if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) {
  9694. currentState.geometry = geometry.id;
  9695. currentState.program = program.id;
  9696. currentState.wireframe = wireframe;
  9697. updateBuffers = true;
  9698. }
  9699. }
  9700. if (object.isInstancedMesh === true) {
  9701. updateBuffers = true;
  9702. }
  9703. if (index !== null) {
  9704. attributes.update(index, 34963);
  9705. }
  9706. if (updateBuffers) {
  9707. setupVertexAttributes(object, material, program, geometry);
  9708. if (index !== null) {
  9709. gl.bindBuffer(34963, attributes.get(index).buffer);
  9710. }
  9711. }
  9712. }
  9713. function createVertexArrayObject() {
  9714. if (capabilities.isWebGL2) return gl.createVertexArray();
  9715. return extension.createVertexArrayOES();
  9716. }
  9717. function bindVertexArrayObject(vao) {
  9718. if (capabilities.isWebGL2) return gl.bindVertexArray(vao);
  9719. return extension.bindVertexArrayOES(vao);
  9720. }
  9721. function deleteVertexArrayObject(vao) {
  9722. if (capabilities.isWebGL2) return gl.deleteVertexArray(vao);
  9723. return extension.deleteVertexArrayOES(vao);
  9724. }
  9725. function getBindingState(geometry, program, material) {
  9726. var wireframe = material.wireframe === true;
  9727. var programMap = bindingStates[geometry.id];
  9728. if (programMap === undefined) {
  9729. programMap = {};
  9730. bindingStates[geometry.id] = programMap;
  9731. }
  9732. var stateMap = programMap[program.id];
  9733. if (stateMap === undefined) {
  9734. stateMap = {};
  9735. programMap[program.id] = stateMap;
  9736. }
  9737. var state = stateMap[wireframe];
  9738. if (state === undefined) {
  9739. state = createBindingState(createVertexArrayObject());
  9740. stateMap[wireframe] = state;
  9741. }
  9742. return state;
  9743. }
  9744. function createBindingState(vao) {
  9745. var newAttributes = [];
  9746. var enabledAttributes = [];
  9747. var attributeDivisors = [];
  9748. for (var i = 0; i < maxVertexAttributes; i++) {
  9749. newAttributes[i] = 0;
  9750. enabledAttributes[i] = 0;
  9751. attributeDivisors[i] = 0;
  9752. }
  9753. return {
  9754. // for backward compatibility on non-VAO support browser
  9755. geometry: null,
  9756. program: null,
  9757. wireframe: false,
  9758. newAttributes: newAttributes,
  9759. enabledAttributes: enabledAttributes,
  9760. attributeDivisors: attributeDivisors,
  9761. object: vao,
  9762. attributes: {},
  9763. index: null
  9764. };
  9765. }
  9766. function needsUpdate(geometry, index) {
  9767. var cachedAttributes = currentState.attributes;
  9768. var geometryAttributes = geometry.attributes;
  9769. var attributesNum = 0;
  9770. for (var key in geometryAttributes) {
  9771. var cachedAttribute = cachedAttributes[key];
  9772. var geometryAttribute = geometryAttributes[key];
  9773. if (cachedAttribute === undefined) return true;
  9774. if (cachedAttribute.attribute !== geometryAttribute) return true;
  9775. if (cachedAttribute.data !== geometryAttribute.data) return true;
  9776. attributesNum++;
  9777. }
  9778. if (currentState.attributesNum !== attributesNum) return true;
  9779. if (currentState.index !== index) return true;
  9780. return false;
  9781. }
  9782. function saveCache(geometry, index) {
  9783. var cache = {};
  9784. var attributes = geometry.attributes;
  9785. var attributesNum = 0;
  9786. for (var key in attributes) {
  9787. var attribute = attributes[key];
  9788. var data = {};
  9789. data.attribute = attribute;
  9790. if (attribute.data) {
  9791. data.data = attribute.data;
  9792. }
  9793. cache[key] = data;
  9794. attributesNum++;
  9795. }
  9796. currentState.attributes = cache;
  9797. currentState.attributesNum = attributesNum;
  9798. currentState.index = index;
  9799. }
  9800. function initAttributes() {
  9801. var newAttributes = currentState.newAttributes;
  9802. for (var i = 0, il = newAttributes.length; i < il; i++) {
  9803. newAttributes[i] = 0;
  9804. }
  9805. }
  9806. function enableAttribute(attribute) {
  9807. enableAttributeAndDivisor(attribute, 0);
  9808. }
  9809. function enableAttributeAndDivisor(attribute, meshPerAttribute) {
  9810. var newAttributes = currentState.newAttributes;
  9811. var enabledAttributes = currentState.enabledAttributes;
  9812. var attributeDivisors = currentState.attributeDivisors;
  9813. newAttributes[attribute] = 1;
  9814. if (enabledAttributes[attribute] === 0) {
  9815. gl.enableVertexAttribArray(attribute);
  9816. enabledAttributes[attribute] = 1;
  9817. }
  9818. if (attributeDivisors[attribute] !== meshPerAttribute) {
  9819. var _extension = capabilities.isWebGL2 ? gl : extensions.get('ANGLE_instanced_arrays');
  9820. _extension[capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE'](attribute, meshPerAttribute);
  9821. attributeDivisors[attribute] = meshPerAttribute;
  9822. }
  9823. }
  9824. function disableUnusedAttributes() {
  9825. var newAttributes = currentState.newAttributes;
  9826. var enabledAttributes = currentState.enabledAttributes;
  9827. for (var i = 0, il = enabledAttributes.length; i < il; i++) {
  9828. if (enabledAttributes[i] !== newAttributes[i]) {
  9829. gl.disableVertexAttribArray(i);
  9830. enabledAttributes[i] = 0;
  9831. }
  9832. }
  9833. }
  9834. function vertexAttribPointer(index, size, type, normalized, stride, offset) {
  9835. if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) {
  9836. gl.vertexAttribIPointer(index, size, type, stride, offset);
  9837. } else {
  9838. gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
  9839. }
  9840. }
  9841. function setupVertexAttributes(object, material, program, geometry) {
  9842. if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) {
  9843. if (extensions.get('ANGLE_instanced_arrays') === null) return;
  9844. }
  9845. initAttributes();
  9846. var geometryAttributes = geometry.attributes;
  9847. var programAttributes = program.getAttributes();
  9848. var materialDefaultAttributeValues = material.defaultAttributeValues;
  9849. for (var name in programAttributes) {
  9850. var programAttribute = programAttributes[name];
  9851. if (programAttribute >= 0) {
  9852. var geometryAttribute = geometryAttributes[name];
  9853. if (geometryAttribute !== undefined) {
  9854. var normalized = geometryAttribute.normalized;
  9855. var size = geometryAttribute.itemSize;
  9856. var attribute = attributes.get(geometryAttribute); // TODO Attribute may not be available on context restore
  9857. if (attribute === undefined) continue;
  9858. var buffer = attribute.buffer;
  9859. var type = attribute.type;
  9860. var bytesPerElement = attribute.bytesPerElement;
  9861. if (geometryAttribute.isInterleavedBufferAttribute) {
  9862. var data = geometryAttribute.data;
  9863. var stride = data.stride;
  9864. var offset = geometryAttribute.offset;
  9865. if (data && data.isInstancedInterleavedBuffer) {
  9866. enableAttributeAndDivisor(programAttribute, data.meshPerAttribute);
  9867. if (geometry._maxInstanceCount === undefined) {
  9868. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  9869. }
  9870. } else {
  9871. enableAttribute(programAttribute);
  9872. }
  9873. gl.bindBuffer(34962, buffer);
  9874. vertexAttribPointer(programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement);
  9875. } else {
  9876. if (geometryAttribute.isInstancedBufferAttribute) {
  9877. enableAttributeAndDivisor(programAttribute, geometryAttribute.meshPerAttribute);
  9878. if (geometry._maxInstanceCount === undefined) {
  9879. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  9880. }
  9881. } else {
  9882. enableAttribute(programAttribute);
  9883. }
  9884. gl.bindBuffer(34962, buffer);
  9885. vertexAttribPointer(programAttribute, size, type, normalized, 0, 0);
  9886. }
  9887. } else if (name === 'instanceMatrix') {
  9888. var _attribute = attributes.get(object.instanceMatrix); // TODO Attribute may not be available on context restore
  9889. if (_attribute === undefined) continue;
  9890. var _buffer = _attribute.buffer;
  9891. var _type = _attribute.type;
  9892. enableAttributeAndDivisor(programAttribute + 0, 1);
  9893. enableAttributeAndDivisor(programAttribute + 1, 1);
  9894. enableAttributeAndDivisor(programAttribute + 2, 1);
  9895. enableAttributeAndDivisor(programAttribute + 3, 1);
  9896. gl.bindBuffer(34962, _buffer);
  9897. gl.vertexAttribPointer(programAttribute + 0, 4, _type, false, 64, 0);
  9898. gl.vertexAttribPointer(programAttribute + 1, 4, _type, false, 64, 16);
  9899. gl.vertexAttribPointer(programAttribute + 2, 4, _type, false, 64, 32);
  9900. gl.vertexAttribPointer(programAttribute + 3, 4, _type, false, 64, 48);
  9901. } else if (name === 'instanceColor') {
  9902. var _attribute2 = attributes.get(object.instanceColor); // TODO Attribute may not be available on context restore
  9903. if (_attribute2 === undefined) continue;
  9904. var _buffer2 = _attribute2.buffer;
  9905. var _type2 = _attribute2.type;
  9906. enableAttributeAndDivisor(programAttribute, 1);
  9907. gl.bindBuffer(34962, _buffer2);
  9908. gl.vertexAttribPointer(programAttribute, 3, _type2, false, 12, 0);
  9909. } else if (materialDefaultAttributeValues !== undefined) {
  9910. var value = materialDefaultAttributeValues[name];
  9911. if (value !== undefined) {
  9912. switch (value.length) {
  9913. case 2:
  9914. gl.vertexAttrib2fv(programAttribute, value);
  9915. break;
  9916. case 3:
  9917. gl.vertexAttrib3fv(programAttribute, value);
  9918. break;
  9919. case 4:
  9920. gl.vertexAttrib4fv(programAttribute, value);
  9921. break;
  9922. default:
  9923. gl.vertexAttrib1fv(programAttribute, value);
  9924. }
  9925. }
  9926. }
  9927. }
  9928. }
  9929. disableUnusedAttributes();
  9930. }
  9931. function dispose() {
  9932. reset();
  9933. for (var geometryId in bindingStates) {
  9934. var programMap = bindingStates[geometryId];
  9935. for (var programId in programMap) {
  9936. var stateMap = programMap[programId];
  9937. for (var wireframe in stateMap) {
  9938. deleteVertexArrayObject(stateMap[wireframe].object);
  9939. delete stateMap[wireframe];
  9940. }
  9941. delete programMap[programId];
  9942. }
  9943. delete bindingStates[geometryId];
  9944. }
  9945. }
  9946. function releaseStatesOfGeometry(geometry) {
  9947. if (bindingStates[geometry.id] === undefined) return;
  9948. var programMap = bindingStates[geometry.id];
  9949. for (var programId in programMap) {
  9950. var stateMap = programMap[programId];
  9951. for (var wireframe in stateMap) {
  9952. deleteVertexArrayObject(stateMap[wireframe].object);
  9953. delete stateMap[wireframe];
  9954. }
  9955. delete programMap[programId];
  9956. }
  9957. delete bindingStates[geometry.id];
  9958. }
  9959. function releaseStatesOfProgram(program) {
  9960. for (var geometryId in bindingStates) {
  9961. var programMap = bindingStates[geometryId];
  9962. if (programMap[program.id] === undefined) continue;
  9963. var stateMap = programMap[program.id];
  9964. for (var wireframe in stateMap) {
  9965. deleteVertexArrayObject(stateMap[wireframe].object);
  9966. delete stateMap[wireframe];
  9967. }
  9968. delete programMap[program.id];
  9969. }
  9970. }
  9971. function reset() {
  9972. resetDefaultState();
  9973. if (currentState === defaultState) return;
  9974. currentState = defaultState;
  9975. bindVertexArrayObject(currentState.object);
  9976. } // for backward-compatilibity
  9977. function resetDefaultState() {
  9978. defaultState.geometry = null;
  9979. defaultState.program = null;
  9980. defaultState.wireframe = false;
  9981. }
  9982. return {
  9983. setup: setup,
  9984. reset: reset,
  9985. resetDefaultState: resetDefaultState,
  9986. dispose: dispose,
  9987. releaseStatesOfGeometry: releaseStatesOfGeometry,
  9988. releaseStatesOfProgram: releaseStatesOfProgram,
  9989. initAttributes: initAttributes,
  9990. enableAttribute: enableAttribute,
  9991. disableUnusedAttributes: disableUnusedAttributes
  9992. };
  9993. }
  9994. function WebGLBufferRenderer(gl, extensions, info, capabilities) {
  9995. var isWebGL2 = capabilities.isWebGL2;
  9996. var mode;
  9997. function setMode(value) {
  9998. mode = value;
  9999. }
  10000. function render(start, count) {
  10001. gl.drawArrays(mode, start, count);
  10002. info.update(count, mode, 1);
  10003. }
  10004. function renderInstances(start, count, primcount) {
  10005. if (primcount === 0) return;
  10006. var extension, methodName;
  10007. if (isWebGL2) {
  10008. extension = gl;
  10009. methodName = 'drawArraysInstanced';
  10010. } else {
  10011. extension = extensions.get('ANGLE_instanced_arrays');
  10012. methodName = 'drawArraysInstancedANGLE';
  10013. if (extension === null) {
  10014. console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10015. return;
  10016. }
  10017. }
  10018. extension[methodName](mode, start, count, primcount);
  10019. info.update(count, mode, primcount);
  10020. } //
  10021. this.setMode = setMode;
  10022. this.render = render;
  10023. this.renderInstances = renderInstances;
  10024. }
  10025. function WebGLCapabilities(gl, extensions, parameters) {
  10026. var maxAnisotropy;
  10027. function getMaxAnisotropy() {
  10028. if (maxAnisotropy !== undefined) return maxAnisotropy;
  10029. var extension = extensions.get('EXT_texture_filter_anisotropic');
  10030. if (extension !== null) {
  10031. maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
  10032. } else {
  10033. maxAnisotropy = 0;
  10034. }
  10035. return maxAnisotropy;
  10036. }
  10037. function getMaxPrecision(precision) {
  10038. if (precision === 'highp') {
  10039. if (gl.getShaderPrecisionFormat(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) {
  10040. return 'highp';
  10041. }
  10042. precision = 'mediump';
  10043. }
  10044. if (precision === 'mediump') {
  10045. if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) {
  10046. return 'mediump';
  10047. }
  10048. }
  10049. return 'lowp';
  10050. }
  10051. /* eslint-disable no-undef */
  10052. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext;
  10053. /* eslint-enable no-undef */
  10054. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  10055. var maxPrecision = getMaxPrecision(precision);
  10056. if (maxPrecision !== precision) {
  10057. console.warn('THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.');
  10058. precision = maxPrecision;
  10059. }
  10060. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  10061. var maxTextures = gl.getParameter(34930);
  10062. var maxVertexTextures = gl.getParameter(35660);
  10063. var maxTextureSize = gl.getParameter(3379);
  10064. var maxCubemapSize = gl.getParameter(34076);
  10065. var maxAttributes = gl.getParameter(34921);
  10066. var maxVertexUniforms = gl.getParameter(36347);
  10067. var maxVaryings = gl.getParameter(36348);
  10068. var maxFragmentUniforms = gl.getParameter(36349);
  10069. var vertexTextures = maxVertexTextures > 0;
  10070. var floatFragmentTextures = isWebGL2 || !!extensions.get('OES_texture_float');
  10071. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  10072. var maxSamples = isWebGL2 ? gl.getParameter(36183) : 0;
  10073. return {
  10074. isWebGL2: isWebGL2,
  10075. getMaxAnisotropy: getMaxAnisotropy,
  10076. getMaxPrecision: getMaxPrecision,
  10077. precision: precision,
  10078. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10079. maxTextures: maxTextures,
  10080. maxVertexTextures: maxVertexTextures,
  10081. maxTextureSize: maxTextureSize,
  10082. maxCubemapSize: maxCubemapSize,
  10083. maxAttributes: maxAttributes,
  10084. maxVertexUniforms: maxVertexUniforms,
  10085. maxVaryings: maxVaryings,
  10086. maxFragmentUniforms: maxFragmentUniforms,
  10087. vertexTextures: vertexTextures,
  10088. floatFragmentTextures: floatFragmentTextures,
  10089. floatVertexTextures: floatVertexTextures,
  10090. maxSamples: maxSamples
  10091. };
  10092. }
  10093. function WebGLClipping(properties) {
  10094. var scope = this;
  10095. var globalState = null,
  10096. numGlobalPlanes = 0,
  10097. localClippingEnabled = false,
  10098. renderingShadows = false;
  10099. var plane = new Plane(),
  10100. viewNormalMatrix = new Matrix3(),
  10101. uniform = {
  10102. value: null,
  10103. needsUpdate: false
  10104. };
  10105. this.uniform = uniform;
  10106. this.numPlanes = 0;
  10107. this.numIntersection = 0;
  10108. this.init = function (planes, enableLocalClipping, camera) {
  10109. var enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to
  10110. // run another frame in order to reset the state:
  10111. numGlobalPlanes !== 0 || localClippingEnabled;
  10112. localClippingEnabled = enableLocalClipping;
  10113. globalState = projectPlanes(planes, camera, 0);
  10114. numGlobalPlanes = planes.length;
  10115. return enabled;
  10116. };
  10117. this.beginShadows = function () {
  10118. renderingShadows = true;
  10119. projectPlanes(null);
  10120. };
  10121. this.endShadows = function () {
  10122. renderingShadows = false;
  10123. resetGlobalState();
  10124. };
  10125. this.setState = function (material, camera, useCache) {
  10126. var planes = material.clippingPlanes,
  10127. clipIntersection = material.clipIntersection,
  10128. clipShadows = material.clipShadows;
  10129. var materialProperties = properties.get(material);
  10130. if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) {
  10131. // there's no local clipping
  10132. if (renderingShadows) {
  10133. // there's no global clipping
  10134. projectPlanes(null);
  10135. } else {
  10136. resetGlobalState();
  10137. }
  10138. } else {
  10139. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  10140. lGlobal = nGlobal * 4;
  10141. var dstArray = materialProperties.clippingState || null;
  10142. uniform.value = dstArray; // ensure unique state
  10143. dstArray = projectPlanes(planes, camera, lGlobal, useCache);
  10144. for (var i = 0; i !== lGlobal; ++i) {
  10145. dstArray[i] = globalState[i];
  10146. }
  10147. materialProperties.clippingState = dstArray;
  10148. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  10149. this.numPlanes += nGlobal;
  10150. }
  10151. };
  10152. function resetGlobalState() {
  10153. if (uniform.value !== globalState) {
  10154. uniform.value = globalState;
  10155. uniform.needsUpdate = numGlobalPlanes > 0;
  10156. }
  10157. scope.numPlanes = numGlobalPlanes;
  10158. scope.numIntersection = 0;
  10159. }
  10160. function projectPlanes(planes, camera, dstOffset, skipTransform) {
  10161. var nPlanes = planes !== null ? planes.length : 0;
  10162. var dstArray = null;
  10163. if (nPlanes !== 0) {
  10164. dstArray = uniform.value;
  10165. if (skipTransform !== true || dstArray === null) {
  10166. var flatSize = dstOffset + nPlanes * 4,
  10167. viewMatrix = camera.matrixWorldInverse;
  10168. viewNormalMatrix.getNormalMatrix(viewMatrix);
  10169. if (dstArray === null || dstArray.length < flatSize) {
  10170. dstArray = new Float32Array(flatSize);
  10171. }
  10172. for (var i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) {
  10173. plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix);
  10174. plane.normal.toArray(dstArray, i4);
  10175. dstArray[i4 + 3] = plane.constant;
  10176. }
  10177. }
  10178. uniform.value = dstArray;
  10179. uniform.needsUpdate = true;
  10180. }
  10181. scope.numPlanes = nPlanes;
  10182. scope.numIntersection = 0;
  10183. return dstArray;
  10184. }
  10185. }
  10186. function WebGLCubeMaps(renderer) {
  10187. var cubemaps = new WeakMap();
  10188. function mapTextureMapping(texture, mapping) {
  10189. if (mapping === EquirectangularReflectionMapping) {
  10190. texture.mapping = CubeReflectionMapping;
  10191. } else if (mapping === EquirectangularRefractionMapping) {
  10192. texture.mapping = CubeRefractionMapping;
  10193. }
  10194. return texture;
  10195. }
  10196. function get(texture) {
  10197. if (texture && texture.isTexture) {
  10198. var mapping = texture.mapping;
  10199. if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) {
  10200. if (cubemaps.has(texture)) {
  10201. var cubemap = cubemaps.get(texture).texture;
  10202. return mapTextureMapping(cubemap, texture.mapping);
  10203. } else {
  10204. var image = texture.image;
  10205. if (image && image.height > 0) {
  10206. var currentRenderList = renderer.getRenderList();
  10207. var currentRenderTarget = renderer.getRenderTarget();
  10208. var renderTarget = new WebGLCubeRenderTarget(image.height / 2);
  10209. renderTarget.fromEquirectangularTexture(renderer, texture);
  10210. cubemaps.set(texture, renderTarget);
  10211. renderer.setRenderTarget(currentRenderTarget);
  10212. renderer.setRenderList(currentRenderList);
  10213. texture.addEventListener('dispose', onTextureDispose);
  10214. return mapTextureMapping(renderTarget.texture, texture.mapping);
  10215. } else {
  10216. // image not yet ready. try the conversion next frame
  10217. return null;
  10218. }
  10219. }
  10220. }
  10221. }
  10222. return texture;
  10223. }
  10224. function onTextureDispose(event) {
  10225. var texture = event.target;
  10226. texture.removeEventListener('dispose', onTextureDispose);
  10227. var cubemap = cubemaps.get(texture);
  10228. if (cubemap !== undefined) {
  10229. cubemaps.delete(texture);
  10230. cubemap.dispose();
  10231. }
  10232. }
  10233. function dispose() {
  10234. cubemaps = new WeakMap();
  10235. }
  10236. return {
  10237. get: get,
  10238. dispose: dispose
  10239. };
  10240. }
  10241. function WebGLExtensions(gl) {
  10242. var extensions = {};
  10243. function getExtension(name) {
  10244. if (extensions[name] !== undefined) {
  10245. return extensions[name];
  10246. }
  10247. var extension;
  10248. switch (name) {
  10249. case 'WEBGL_depth_texture':
  10250. extension = gl.getExtension('WEBGL_depth_texture') || gl.getExtension('MOZ_WEBGL_depth_texture') || gl.getExtension('WEBKIT_WEBGL_depth_texture');
  10251. break;
  10252. case 'EXT_texture_filter_anisotropic':
  10253. extension = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
  10254. break;
  10255. case 'WEBGL_compressed_texture_s3tc':
  10256. extension = gl.getExtension('WEBGL_compressed_texture_s3tc') || gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');
  10257. break;
  10258. case 'WEBGL_compressed_texture_pvrtc':
  10259. extension = gl.getExtension('WEBGL_compressed_texture_pvrtc') || gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');
  10260. break;
  10261. default:
  10262. extension = gl.getExtension(name);
  10263. }
  10264. extensions[name] = extension;
  10265. return extension;
  10266. }
  10267. return {
  10268. has: function has(name) {
  10269. return getExtension(name) !== null;
  10270. },
  10271. init: function init(capabilities) {
  10272. if (capabilities.isWebGL2) {
  10273. getExtension('EXT_color_buffer_float');
  10274. } else {
  10275. getExtension('WEBGL_depth_texture');
  10276. getExtension('OES_texture_float');
  10277. getExtension('OES_texture_half_float');
  10278. getExtension('OES_texture_half_float_linear');
  10279. getExtension('OES_standard_derivatives');
  10280. getExtension('OES_element_index_uint');
  10281. getExtension('OES_vertex_array_object');
  10282. getExtension('ANGLE_instanced_arrays');
  10283. }
  10284. getExtension('OES_texture_float_linear');
  10285. getExtension('EXT_color_buffer_half_float');
  10286. },
  10287. get: function get(name) {
  10288. var extension = getExtension(name);
  10289. if (extension === null) {
  10290. console.warn('THREE.WebGLRenderer: ' + name + ' extension not supported.');
  10291. }
  10292. return extension;
  10293. }
  10294. };
  10295. }
  10296. function WebGLGeometries(gl, attributes, info, bindingStates) {
  10297. var geometries = {};
  10298. var wireframeAttributes = new WeakMap();
  10299. function onGeometryDispose(event) {
  10300. var geometry = event.target;
  10301. if (geometry.index !== null) {
  10302. attributes.remove(geometry.index);
  10303. }
  10304. for (var name in geometry.attributes) {
  10305. attributes.remove(geometry.attributes[name]);
  10306. }
  10307. geometry.removeEventListener('dispose', onGeometryDispose);
  10308. delete geometries[geometry.id];
  10309. var attribute = wireframeAttributes.get(geometry);
  10310. if (attribute) {
  10311. attributes.remove(attribute);
  10312. wireframeAttributes.delete(geometry);
  10313. }
  10314. bindingStates.releaseStatesOfGeometry(geometry);
  10315. if (geometry.isInstancedBufferGeometry === true) {
  10316. delete geometry._maxInstanceCount;
  10317. } //
  10318. info.memory.geometries--;
  10319. }
  10320. function get(object, geometry) {
  10321. if (geometries[geometry.id] === true) return geometry;
  10322. geometry.addEventListener('dispose', onGeometryDispose);
  10323. geometries[geometry.id] = true;
  10324. info.memory.geometries++;
  10325. return geometry;
  10326. }
  10327. function update(geometry) {
  10328. var geometryAttributes = geometry.attributes; // Updating index buffer in VAO now. See WebGLBindingStates.
  10329. for (var name in geometryAttributes) {
  10330. attributes.update(geometryAttributes[name], 34962);
  10331. } // morph targets
  10332. var morphAttributes = geometry.morphAttributes;
  10333. for (var _name in morphAttributes) {
  10334. var array = morphAttributes[_name];
  10335. for (var i = 0, l = array.length; i < l; i++) {
  10336. attributes.update(array[i], 34962);
  10337. }
  10338. }
  10339. }
  10340. function updateWireframeAttribute(geometry) {
  10341. var indices = [];
  10342. var geometryIndex = geometry.index;
  10343. var geometryPosition = geometry.attributes.position;
  10344. var version = 0;
  10345. if (geometryIndex !== null) {
  10346. var array = geometryIndex.array;
  10347. version = geometryIndex.version;
  10348. for (var i = 0, l = array.length; i < l; i += 3) {
  10349. var a = array[i + 0];
  10350. var b = array[i + 1];
  10351. var c = array[i + 2];
  10352. indices.push(a, b, b, c, c, a);
  10353. }
  10354. } else {
  10355. var _array = geometryPosition.array;
  10356. version = geometryPosition.version;
  10357. for (var _i = 0, _l = _array.length / 3 - 1; _i < _l; _i += 3) {
  10358. var _a = _i + 0;
  10359. var _b = _i + 1;
  10360. var _c = _i + 2;
  10361. indices.push(_a, _b, _b, _c, _c, _a);
  10362. }
  10363. }
  10364. var attribute = new (arrayMax(indices) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1);
  10365. attribute.version = version; // Updating index buffer in VAO now. See WebGLBindingStates
  10366. //
  10367. var previousAttribute = wireframeAttributes.get(geometry);
  10368. if (previousAttribute) attributes.remove(previousAttribute); //
  10369. wireframeAttributes.set(geometry, attribute);
  10370. }
  10371. function getWireframeAttribute(geometry) {
  10372. var currentAttribute = wireframeAttributes.get(geometry);
  10373. if (currentAttribute) {
  10374. var geometryIndex = geometry.index;
  10375. if (geometryIndex !== null) {
  10376. // if the attribute is obsolete, create a new one
  10377. if (currentAttribute.version < geometryIndex.version) {
  10378. updateWireframeAttribute(geometry);
  10379. }
  10380. }
  10381. } else {
  10382. updateWireframeAttribute(geometry);
  10383. }
  10384. return wireframeAttributes.get(geometry);
  10385. }
  10386. return {
  10387. get: get,
  10388. update: update,
  10389. getWireframeAttribute: getWireframeAttribute
  10390. };
  10391. }
  10392. function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) {
  10393. var isWebGL2 = capabilities.isWebGL2;
  10394. var mode;
  10395. function setMode(value) {
  10396. mode = value;
  10397. }
  10398. var type, bytesPerElement;
  10399. function setIndex(value) {
  10400. type = value.type;
  10401. bytesPerElement = value.bytesPerElement;
  10402. }
  10403. function render(start, count) {
  10404. gl.drawElements(mode, count, type, start * bytesPerElement);
  10405. info.update(count, mode, 1);
  10406. }
  10407. function renderInstances(start, count, primcount) {
  10408. if (primcount === 0) return;
  10409. var extension, methodName;
  10410. if (isWebGL2) {
  10411. extension = gl;
  10412. methodName = 'drawElementsInstanced';
  10413. } else {
  10414. extension = extensions.get('ANGLE_instanced_arrays');
  10415. methodName = 'drawElementsInstancedANGLE';
  10416. if (extension === null) {
  10417. console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');
  10418. return;
  10419. }
  10420. }
  10421. extension[methodName](mode, count, type, start * bytesPerElement, primcount);
  10422. info.update(count, mode, primcount);
  10423. } //
  10424. this.setMode = setMode;
  10425. this.setIndex = setIndex;
  10426. this.render = render;
  10427. this.renderInstances = renderInstances;
  10428. }
  10429. function WebGLInfo(gl) {
  10430. var memory = {
  10431. geometries: 0,
  10432. textures: 0
  10433. };
  10434. var render = {
  10435. frame: 0,
  10436. calls: 0,
  10437. triangles: 0,
  10438. points: 0,
  10439. lines: 0
  10440. };
  10441. function update(count, mode, instanceCount) {
  10442. render.calls++;
  10443. switch (mode) {
  10444. case 4:
  10445. render.triangles += instanceCount * (count / 3);
  10446. break;
  10447. case 1:
  10448. render.lines += instanceCount * (count / 2);
  10449. break;
  10450. case 3:
  10451. render.lines += instanceCount * (count - 1);
  10452. break;
  10453. case 2:
  10454. render.lines += instanceCount * count;
  10455. break;
  10456. case 0:
  10457. render.points += instanceCount * count;
  10458. break;
  10459. default:
  10460. console.error('THREE.WebGLInfo: Unknown draw mode:', mode);
  10461. break;
  10462. }
  10463. }
  10464. function reset() {
  10465. render.frame++;
  10466. render.calls = 0;
  10467. render.triangles = 0;
  10468. render.points = 0;
  10469. render.lines = 0;
  10470. }
  10471. return {
  10472. memory: memory,
  10473. render: render,
  10474. programs: null,
  10475. autoReset: true,
  10476. reset: reset,
  10477. update: update
  10478. };
  10479. }
  10480. function numericalSort(a, b) {
  10481. return a[0] - b[0];
  10482. }
  10483. function absNumericalSort(a, b) {
  10484. return Math.abs(b[1]) - Math.abs(a[1]);
  10485. }
  10486. function WebGLMorphtargets(gl) {
  10487. var influencesList = {};
  10488. var morphInfluences = new Float32Array(8);
  10489. var workInfluences = [];
  10490. for (var i = 0; i < 8; i++) {
  10491. workInfluences[i] = [i, 0];
  10492. }
  10493. function update(object, geometry, material, program) {
  10494. var objectInfluences = object.morphTargetInfluences; // When object doesn't have morph target influences defined, we treat it as a 0-length array
  10495. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  10496. var length = objectInfluences === undefined ? 0 : objectInfluences.length;
  10497. var influences = influencesList[geometry.id];
  10498. if (influences === undefined) {
  10499. // initialise list
  10500. influences = [];
  10501. for (var _i = 0; _i < length; _i++) {
  10502. influences[_i] = [_i, 0];
  10503. }
  10504. influencesList[geometry.id] = influences;
  10505. } // Collect influences
  10506. for (var _i2 = 0; _i2 < length; _i2++) {
  10507. var influence = influences[_i2];
  10508. influence[0] = _i2;
  10509. influence[1] = objectInfluences[_i2];
  10510. }
  10511. influences.sort(absNumericalSort);
  10512. for (var _i3 = 0; _i3 < 8; _i3++) {
  10513. if (_i3 < length && influences[_i3][1]) {
  10514. workInfluences[_i3][0] = influences[_i3][0];
  10515. workInfluences[_i3][1] = influences[_i3][1];
  10516. } else {
  10517. workInfluences[_i3][0] = Number.MAX_SAFE_INTEGER;
  10518. workInfluences[_i3][1] = 0;
  10519. }
  10520. }
  10521. workInfluences.sort(numericalSort);
  10522. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  10523. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  10524. var morphInfluencesSum = 0;
  10525. for (var _i4 = 0; _i4 < 8; _i4++) {
  10526. var _influence = workInfluences[_i4];
  10527. var index = _influence[0];
  10528. var value = _influence[1];
  10529. if (index !== Number.MAX_SAFE_INTEGER && value) {
  10530. if (morphTargets && geometry.getAttribute('morphTarget' + _i4) !== morphTargets[index]) {
  10531. geometry.setAttribute('morphTarget' + _i4, morphTargets[index]);
  10532. }
  10533. if (morphNormals && geometry.getAttribute('morphNormal' + _i4) !== morphNormals[index]) {
  10534. geometry.setAttribute('morphNormal' + _i4, morphNormals[index]);
  10535. }
  10536. morphInfluences[_i4] = value;
  10537. morphInfluencesSum += value;
  10538. } else {
  10539. if (morphTargets && geometry.hasAttribute('morphTarget' + _i4) === true) {
  10540. geometry.deleteAttribute('morphTarget' + _i4);
  10541. }
  10542. if (morphNormals && geometry.hasAttribute('morphNormal' + _i4) === true) {
  10543. geometry.deleteAttribute('morphNormal' + _i4);
  10544. }
  10545. morphInfluences[_i4] = 0;
  10546. }
  10547. } // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  10548. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  10549. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  10550. var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  10551. program.getUniforms().setValue(gl, 'morphTargetBaseInfluence', morphBaseInfluence);
  10552. program.getUniforms().setValue(gl, 'morphTargetInfluences', morphInfluences);
  10553. }
  10554. return {
  10555. update: update
  10556. };
  10557. }
  10558. function WebGLObjects(gl, geometries, attributes, info) {
  10559. var updateMap = new WeakMap();
  10560. function update(object) {
  10561. var frame = info.render.frame;
  10562. var geometry = object.geometry;
  10563. var buffergeometry = geometries.get(object, geometry); // Update once per frame
  10564. if (updateMap.get(buffergeometry) !== frame) {
  10565. geometries.update(buffergeometry);
  10566. updateMap.set(buffergeometry, frame);
  10567. }
  10568. if (object.isInstancedMesh) {
  10569. if (object.hasEventListener('dispose', onInstancedMeshDispose) === false) {
  10570. object.addEventListener('dispose', onInstancedMeshDispose);
  10571. }
  10572. attributes.update(object.instanceMatrix, 34962);
  10573. if (object.instanceColor !== null) {
  10574. attributes.update(object.instanceColor, 34962);
  10575. }
  10576. }
  10577. return buffergeometry;
  10578. }
  10579. function dispose() {
  10580. updateMap = new WeakMap();
  10581. }
  10582. function onInstancedMeshDispose(event) {
  10583. var instancedMesh = event.target;
  10584. instancedMesh.removeEventListener('dispose', onInstancedMeshDispose);
  10585. attributes.remove(instancedMesh.instanceMatrix);
  10586. if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor);
  10587. }
  10588. return {
  10589. update: update,
  10590. dispose: dispose
  10591. };
  10592. }
  10593. function DataTexture2DArray(data, width, height, depth) {
  10594. if (data === void 0) {
  10595. data = null;
  10596. }
  10597. if (width === void 0) {
  10598. width = 1;
  10599. }
  10600. if (height === void 0) {
  10601. height = 1;
  10602. }
  10603. if (depth === void 0) {
  10604. depth = 1;
  10605. }
  10606. Texture.call(this, null);
  10607. this.image = {
  10608. data: data,
  10609. width: width,
  10610. height: height,
  10611. depth: depth
  10612. };
  10613. this.magFilter = NearestFilter;
  10614. this.minFilter = NearestFilter;
  10615. this.wrapR = ClampToEdgeWrapping;
  10616. this.generateMipmaps = false;
  10617. this.flipY = false;
  10618. this.needsUpdate = true;
  10619. }
  10620. DataTexture2DArray.prototype = Object.create(Texture.prototype);
  10621. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  10622. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  10623. function DataTexture3D(data, width, height, depth) {
  10624. if (data === void 0) {
  10625. data = null;
  10626. }
  10627. if (width === void 0) {
  10628. width = 1;
  10629. }
  10630. if (height === void 0) {
  10631. height = 1;
  10632. }
  10633. if (depth === void 0) {
  10634. depth = 1;
  10635. }
  10636. // We're going to add .setXXX() methods for setting properties later.
  10637. // Users can still set in DataTexture3D directly.
  10638. //
  10639. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  10640. // texture.anisotropy = 16;
  10641. //
  10642. // See #14839
  10643. Texture.call(this, null);
  10644. this.image = {
  10645. data: data,
  10646. width: width,
  10647. height: height,
  10648. depth: depth
  10649. };
  10650. this.magFilter = NearestFilter;
  10651. this.minFilter = NearestFilter;
  10652. this.wrapR = ClampToEdgeWrapping;
  10653. this.generateMipmaps = false;
  10654. this.flipY = false;
  10655. this.needsUpdate = true;
  10656. }
  10657. DataTexture3D.prototype = Object.create(Texture.prototype);
  10658. DataTexture3D.prototype.constructor = DataTexture3D;
  10659. DataTexture3D.prototype.isDataTexture3D = true;
  10660. /**
  10661. * Uniforms of a program.
  10662. * Those form a tree structure with a special top-level container for the root,
  10663. * which you get by calling 'new WebGLUniforms( gl, program )'.
  10664. *
  10665. *
  10666. * Properties of inner nodes including the top-level container:
  10667. *
  10668. * .seq - array of nested uniforms
  10669. * .map - nested uniforms by name
  10670. *
  10671. *
  10672. * Methods of all nodes except the top-level container:
  10673. *
  10674. * .setValue( gl, value, [textures] )
  10675. *
  10676. * uploads a uniform value(s)
  10677. * the 'textures' parameter is needed for sampler uniforms
  10678. *
  10679. *
  10680. * Static methods of the top-level container (textures factorizations):
  10681. *
  10682. * .upload( gl, seq, values, textures )
  10683. *
  10684. * sets uniforms in 'seq' to 'values[id].value'
  10685. *
  10686. * .seqWithValue( seq, values ) : filteredSeq
  10687. *
  10688. * filters 'seq' entries with corresponding entry in values
  10689. *
  10690. *
  10691. * Methods of the top-level container (textures factorizations):
  10692. *
  10693. * .setValue( gl, name, value, textures )
  10694. *
  10695. * sets uniform with name 'name' to 'value'
  10696. *
  10697. * .setOptional( gl, obj, prop )
  10698. *
  10699. * like .set for an optional property of the object
  10700. *
  10701. */
  10702. var emptyTexture = new Texture();
  10703. var emptyTexture2dArray = new DataTexture2DArray();
  10704. var emptyTexture3d = new DataTexture3D();
  10705. var emptyCubeTexture = new CubeTexture(); // --- Utilities ---
  10706. // Array Caches (provide typed arrays for temporary by size)
  10707. var arrayCacheF32 = [];
  10708. var arrayCacheI32 = []; // Float32Array caches used for uploading Matrix uniforms
  10709. var mat4array = new Float32Array(16);
  10710. var mat3array = new Float32Array(9);
  10711. var mat2array = new Float32Array(4); // Flattening for arrays of vectors and matrices
  10712. function flatten(array, nBlocks, blockSize) {
  10713. var firstElem = array[0];
  10714. if (firstElem <= 0 || firstElem > 0) return array; // unoptimized: ! isNaN( firstElem )
  10715. // see http://jacksondunstan.com/articles/983
  10716. var n = nBlocks * blockSize;
  10717. var r = arrayCacheF32[n];
  10718. if (r === undefined) {
  10719. r = new Float32Array(n);
  10720. arrayCacheF32[n] = r;
  10721. }
  10722. if (nBlocks !== 0) {
  10723. firstElem.toArray(r, 0);
  10724. for (var i = 1, offset = 0; i !== nBlocks; ++i) {
  10725. offset += blockSize;
  10726. array[i].toArray(r, offset);
  10727. }
  10728. }
  10729. return r;
  10730. }
  10731. function arraysEqual(a, b) {
  10732. if (a.length !== b.length) return false;
  10733. for (var i = 0, l = a.length; i < l; i++) {
  10734. if (a[i] !== b[i]) return false;
  10735. }
  10736. return true;
  10737. }
  10738. function copyArray(a, b) {
  10739. for (var i = 0, l = b.length; i < l; i++) {
  10740. a[i] = b[i];
  10741. }
  10742. } // Texture unit allocation
  10743. function allocTexUnits(textures, n) {
  10744. var r = arrayCacheI32[n];
  10745. if (r === undefined) {
  10746. r = new Int32Array(n);
  10747. arrayCacheI32[n] = r;
  10748. }
  10749. for (var i = 0; i !== n; ++i) {
  10750. r[i] = textures.allocateTextureUnit();
  10751. }
  10752. return r;
  10753. } // --- Setters ---
  10754. // Note: Defining these methods externally, because they come in a bunch
  10755. // and this way their names minify.
  10756. // Single scalar
  10757. function setValueV1f(gl, v) {
  10758. var cache = this.cache;
  10759. if (cache[0] === v) return;
  10760. gl.uniform1f(this.addr, v);
  10761. cache[0] = v;
  10762. } // Single float vector (from flat array or THREE.VectorN)
  10763. function setValueV2f(gl, v) {
  10764. var cache = this.cache;
  10765. if (v.x !== undefined) {
  10766. if (cache[0] !== v.x || cache[1] !== v.y) {
  10767. gl.uniform2f(this.addr, v.x, v.y);
  10768. cache[0] = v.x;
  10769. cache[1] = v.y;
  10770. }
  10771. } else {
  10772. if (arraysEqual(cache, v)) return;
  10773. gl.uniform2fv(this.addr, v);
  10774. copyArray(cache, v);
  10775. }
  10776. }
  10777. function setValueV3f(gl, v) {
  10778. var cache = this.cache;
  10779. if (v.x !== undefined) {
  10780. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) {
  10781. gl.uniform3f(this.addr, v.x, v.y, v.z);
  10782. cache[0] = v.x;
  10783. cache[1] = v.y;
  10784. cache[2] = v.z;
  10785. }
  10786. } else if (v.r !== undefined) {
  10787. if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) {
  10788. gl.uniform3f(this.addr, v.r, v.g, v.b);
  10789. cache[0] = v.r;
  10790. cache[1] = v.g;
  10791. cache[2] = v.b;
  10792. }
  10793. } else {
  10794. if (arraysEqual(cache, v)) return;
  10795. gl.uniform3fv(this.addr, v);
  10796. copyArray(cache, v);
  10797. }
  10798. }
  10799. function setValueV4f(gl, v) {
  10800. var cache = this.cache;
  10801. if (v.x !== undefined) {
  10802. if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) {
  10803. gl.uniform4f(this.addr, v.x, v.y, v.z, v.w);
  10804. cache[0] = v.x;
  10805. cache[1] = v.y;
  10806. cache[2] = v.z;
  10807. cache[3] = v.w;
  10808. }
  10809. } else {
  10810. if (arraysEqual(cache, v)) return;
  10811. gl.uniform4fv(this.addr, v);
  10812. copyArray(cache, v);
  10813. }
  10814. } // Single matrix (from flat array or MatrixN)
  10815. function setValueM2(gl, v) {
  10816. var cache = this.cache;
  10817. var elements = v.elements;
  10818. if (elements === undefined) {
  10819. if (arraysEqual(cache, v)) return;
  10820. gl.uniformMatrix2fv(this.addr, false, v);
  10821. copyArray(cache, v);
  10822. } else {
  10823. if (arraysEqual(cache, elements)) return;
  10824. mat2array.set(elements);
  10825. gl.uniformMatrix2fv(this.addr, false, mat2array);
  10826. copyArray(cache, elements);
  10827. }
  10828. }
  10829. function setValueM3(gl, v) {
  10830. var cache = this.cache;
  10831. var elements = v.elements;
  10832. if (elements === undefined) {
  10833. if (arraysEqual(cache, v)) return;
  10834. gl.uniformMatrix3fv(this.addr, false, v);
  10835. copyArray(cache, v);
  10836. } else {
  10837. if (arraysEqual(cache, elements)) return;
  10838. mat3array.set(elements);
  10839. gl.uniformMatrix3fv(this.addr, false, mat3array);
  10840. copyArray(cache, elements);
  10841. }
  10842. }
  10843. function setValueM4(gl, v) {
  10844. var cache = this.cache;
  10845. var elements = v.elements;
  10846. if (elements === undefined) {
  10847. if (arraysEqual(cache, v)) return;
  10848. gl.uniformMatrix4fv(this.addr, false, v);
  10849. copyArray(cache, v);
  10850. } else {
  10851. if (arraysEqual(cache, elements)) return;
  10852. mat4array.set(elements);
  10853. gl.uniformMatrix4fv(this.addr, false, mat4array);
  10854. copyArray(cache, elements);
  10855. }
  10856. } // Single texture (2D / Cube)
  10857. function setValueT1(gl, v, textures) {
  10858. var cache = this.cache;
  10859. var unit = textures.allocateTextureUnit();
  10860. if (cache[0] !== unit) {
  10861. gl.uniform1i(this.addr, unit);
  10862. cache[0] = unit;
  10863. }
  10864. textures.safeSetTexture2D(v || emptyTexture, unit);
  10865. }
  10866. function setValueT2DArray1(gl, v, textures) {
  10867. var cache = this.cache;
  10868. var unit = textures.allocateTextureUnit();
  10869. if (cache[0] !== unit) {
  10870. gl.uniform1i(this.addr, unit);
  10871. cache[0] = unit;
  10872. }
  10873. textures.setTexture2DArray(v || emptyTexture2dArray, unit);
  10874. }
  10875. function setValueT3D1(gl, v, textures) {
  10876. var cache = this.cache;
  10877. var unit = textures.allocateTextureUnit();
  10878. if (cache[0] !== unit) {
  10879. gl.uniform1i(this.addr, unit);
  10880. cache[0] = unit;
  10881. }
  10882. textures.setTexture3D(v || emptyTexture3d, unit);
  10883. }
  10884. function setValueT6(gl, v, textures) {
  10885. var cache = this.cache;
  10886. var unit = textures.allocateTextureUnit();
  10887. if (cache[0] !== unit) {
  10888. gl.uniform1i(this.addr, unit);
  10889. cache[0] = unit;
  10890. }
  10891. textures.safeSetTextureCube(v || emptyCubeTexture, unit);
  10892. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10893. function setValueV1i(gl, v) {
  10894. var cache = this.cache;
  10895. if (cache[0] === v) return;
  10896. gl.uniform1i(this.addr, v);
  10897. cache[0] = v;
  10898. }
  10899. function setValueV2i(gl, v) {
  10900. var cache = this.cache;
  10901. if (arraysEqual(cache, v)) return;
  10902. gl.uniform2iv(this.addr, v);
  10903. copyArray(cache, v);
  10904. }
  10905. function setValueV3i(gl, v) {
  10906. var cache = this.cache;
  10907. if (arraysEqual(cache, v)) return;
  10908. gl.uniform3iv(this.addr, v);
  10909. copyArray(cache, v);
  10910. }
  10911. function setValueV4i(gl, v) {
  10912. var cache = this.cache;
  10913. if (arraysEqual(cache, v)) return;
  10914. gl.uniform4iv(this.addr, v);
  10915. copyArray(cache, v);
  10916. } // uint
  10917. function setValueV1ui(gl, v) {
  10918. var cache = this.cache;
  10919. if (cache[0] === v) return;
  10920. gl.uniform1ui(this.addr, v);
  10921. cache[0] = v;
  10922. } // Helper to pick the right setter for the singular case
  10923. function getSingularSetter(type) {
  10924. switch (type) {
  10925. case 0x1406:
  10926. return setValueV1f;
  10927. // FLOAT
  10928. case 0x8b50:
  10929. return setValueV2f;
  10930. // _VEC2
  10931. case 0x8b51:
  10932. return setValueV3f;
  10933. // _VEC3
  10934. case 0x8b52:
  10935. return setValueV4f;
  10936. // _VEC4
  10937. case 0x8b5a:
  10938. return setValueM2;
  10939. // _MAT2
  10940. case 0x8b5b:
  10941. return setValueM3;
  10942. // _MAT3
  10943. case 0x8b5c:
  10944. return setValueM4;
  10945. // _MAT4
  10946. case 0x1404:
  10947. case 0x8b56:
  10948. return setValueV1i;
  10949. // INT, BOOL
  10950. case 0x8b53:
  10951. case 0x8b57:
  10952. return setValueV2i;
  10953. // _VEC2
  10954. case 0x8b54:
  10955. case 0x8b58:
  10956. return setValueV3i;
  10957. // _VEC3
  10958. case 0x8b55:
  10959. case 0x8b59:
  10960. return setValueV4i;
  10961. // _VEC4
  10962. case 0x1405:
  10963. return setValueV1ui;
  10964. // UINT
  10965. case 0x8b5e: // SAMPLER_2D
  10966. case 0x8d66: // SAMPLER_EXTERNAL_OES
  10967. case 0x8dca: // INT_SAMPLER_2D
  10968. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  10969. case 0x8b62:
  10970. // SAMPLER_2D_SHADOW
  10971. return setValueT1;
  10972. case 0x8b5f: // SAMPLER_3D
  10973. case 0x8dcb: // INT_SAMPLER_3D
  10974. case 0x8dd3:
  10975. // UNSIGNED_INT_SAMPLER_3D
  10976. return setValueT3D1;
  10977. case 0x8b60: // SAMPLER_CUBE
  10978. case 0x8dcc: // INT_SAMPLER_CUBE
  10979. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  10980. case 0x8dc5:
  10981. // SAMPLER_CUBE_SHADOW
  10982. return setValueT6;
  10983. case 0x8dc1: // SAMPLER_2D_ARRAY
  10984. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  10985. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  10986. case 0x8dc4:
  10987. // SAMPLER_2D_ARRAY_SHADOW
  10988. return setValueT2DArray1;
  10989. }
  10990. } // Array of scalars
  10991. function setValueV1fArray(gl, v) {
  10992. gl.uniform1fv(this.addr, v);
  10993. } // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10994. function setValueV1iArray(gl, v) {
  10995. gl.uniform1iv(this.addr, v);
  10996. }
  10997. function setValueV2iArray(gl, v) {
  10998. gl.uniform2iv(this.addr, v);
  10999. }
  11000. function setValueV3iArray(gl, v) {
  11001. gl.uniform3iv(this.addr, v);
  11002. }
  11003. function setValueV4iArray(gl, v) {
  11004. gl.uniform4iv(this.addr, v);
  11005. } // Array of vectors (flat or from THREE classes)
  11006. function setValueV2fArray(gl, v) {
  11007. var data = flatten(v, this.size, 2);
  11008. gl.uniform2fv(this.addr, data);
  11009. }
  11010. function setValueV3fArray(gl, v) {
  11011. var data = flatten(v, this.size, 3);
  11012. gl.uniform3fv(this.addr, data);
  11013. }
  11014. function setValueV4fArray(gl, v) {
  11015. var data = flatten(v, this.size, 4);
  11016. gl.uniform4fv(this.addr, data);
  11017. } // Array of matrices (flat or from THREE clases)
  11018. function setValueM2Array(gl, v) {
  11019. var data = flatten(v, this.size, 4);
  11020. gl.uniformMatrix2fv(this.addr, false, data);
  11021. }
  11022. function setValueM3Array(gl, v) {
  11023. var data = flatten(v, this.size, 9);
  11024. gl.uniformMatrix3fv(this.addr, false, data);
  11025. }
  11026. function setValueM4Array(gl, v) {
  11027. var data = flatten(v, this.size, 16);
  11028. gl.uniformMatrix4fv(this.addr, false, data);
  11029. } // Array of textures (2D / Cube)
  11030. function setValueT1Array(gl, v, textures) {
  11031. var n = v.length;
  11032. var units = allocTexUnits(textures, n);
  11033. gl.uniform1iv(this.addr, units);
  11034. for (var i = 0; i !== n; ++i) {
  11035. textures.safeSetTexture2D(v[i] || emptyTexture, units[i]);
  11036. }
  11037. }
  11038. function setValueT6Array(gl, v, textures) {
  11039. var n = v.length;
  11040. var units = allocTexUnits(textures, n);
  11041. gl.uniform1iv(this.addr, units);
  11042. for (var i = 0; i !== n; ++i) {
  11043. textures.safeSetTextureCube(v[i] || emptyCubeTexture, units[i]);
  11044. }
  11045. } // Helper to pick the right setter for a pure (bottom-level) array
  11046. function getPureArraySetter(type) {
  11047. switch (type) {
  11048. case 0x1406:
  11049. return setValueV1fArray;
  11050. // FLOAT
  11051. case 0x8b50:
  11052. return setValueV2fArray;
  11053. // _VEC2
  11054. case 0x8b51:
  11055. return setValueV3fArray;
  11056. // _VEC3
  11057. case 0x8b52:
  11058. return setValueV4fArray;
  11059. // _VEC4
  11060. case 0x8b5a:
  11061. return setValueM2Array;
  11062. // _MAT2
  11063. case 0x8b5b:
  11064. return setValueM3Array;
  11065. // _MAT3
  11066. case 0x8b5c:
  11067. return setValueM4Array;
  11068. // _MAT4
  11069. case 0x1404:
  11070. case 0x8b56:
  11071. return setValueV1iArray;
  11072. // INT, BOOL
  11073. case 0x8b53:
  11074. case 0x8b57:
  11075. return setValueV2iArray;
  11076. // _VEC2
  11077. case 0x8b54:
  11078. case 0x8b58:
  11079. return setValueV3iArray;
  11080. // _VEC3
  11081. case 0x8b55:
  11082. case 0x8b59:
  11083. return setValueV4iArray;
  11084. // _VEC4
  11085. case 0x8b5e: // SAMPLER_2D
  11086. case 0x8d66: // SAMPLER_EXTERNAL_OES
  11087. case 0x8dca: // INT_SAMPLER_2D
  11088. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  11089. case 0x8b62:
  11090. // SAMPLER_2D_SHADOW
  11091. return setValueT1Array;
  11092. case 0x8b60: // SAMPLER_CUBE
  11093. case 0x8dcc: // INT_SAMPLER_CUBE
  11094. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  11095. case 0x8dc5:
  11096. // SAMPLER_CUBE_SHADOW
  11097. return setValueT6Array;
  11098. }
  11099. } // --- Uniform Classes ---
  11100. function SingleUniform(id, activeInfo, addr) {
  11101. this.id = id;
  11102. this.addr = addr;
  11103. this.cache = [];
  11104. this.setValue = getSingularSetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11105. }
  11106. function PureArrayUniform(id, activeInfo, addr) {
  11107. this.id = id;
  11108. this.addr = addr;
  11109. this.cache = [];
  11110. this.size = activeInfo.size;
  11111. this.setValue = getPureArraySetter(activeInfo.type); // this.path = activeInfo.name; // DEBUG
  11112. }
  11113. PureArrayUniform.prototype.updateCache = function (data) {
  11114. var cache = this.cache;
  11115. if (data instanceof Float32Array && cache.length !== data.length) {
  11116. this.cache = new Float32Array(data.length);
  11117. }
  11118. copyArray(cache, data);
  11119. };
  11120. function StructuredUniform(id) {
  11121. this.id = id;
  11122. this.seq = [];
  11123. this.map = {};
  11124. }
  11125. StructuredUniform.prototype.setValue = function (gl, value, textures) {
  11126. var seq = this.seq;
  11127. for (var i = 0, n = seq.length; i !== n; ++i) {
  11128. var u = seq[i];
  11129. u.setValue(gl, value[u.id], textures);
  11130. }
  11131. }; // --- Top-level ---
  11132. // Parser - builds up the property tree from the path strings
  11133. var RePathPart = /(\w+)(\])?(\[|\.)?/g; // extracts
  11134. // - the identifier (member name or array index)
  11135. // - followed by an optional right bracket (found when array index)
  11136. // - followed by an optional left bracket or dot (type of subscript)
  11137. //
  11138. // Note: These portions can be read in a non-overlapping fashion and
  11139. // allow straightforward parsing of the hierarchy that WebGL encodes
  11140. // in the uniform names.
  11141. function addUniform(container, uniformObject) {
  11142. container.seq.push(uniformObject);
  11143. container.map[uniformObject.id] = uniformObject;
  11144. }
  11145. function parseUniform(activeInfo, addr, container) {
  11146. var path = activeInfo.name,
  11147. pathLength = path.length; // reset RegExp object, because of the early exit of a previous run
  11148. RePathPart.lastIndex = 0;
  11149. while (true) {
  11150. var match = RePathPart.exec(path),
  11151. matchEnd = RePathPart.lastIndex;
  11152. var id = match[1];
  11153. var idIsIndex = match[2] === ']',
  11154. subscript = match[3];
  11155. if (idIsIndex) id = id | 0; // convert to integer
  11156. if (subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength) {
  11157. // bare name or "pure" bottom-level array "[0]" suffix
  11158. addUniform(container, subscript === undefined ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr));
  11159. break;
  11160. } else {
  11161. // step into inner node / create it in case it doesn't exist
  11162. var map = container.map;
  11163. var next = map[id];
  11164. if (next === undefined) {
  11165. next = new StructuredUniform(id);
  11166. addUniform(container, next);
  11167. }
  11168. container = next;
  11169. }
  11170. }
  11171. } // Root Container
  11172. function WebGLUniforms(gl, program) {
  11173. this.seq = [];
  11174. this.map = {};
  11175. var n = gl.getProgramParameter(program, 35718);
  11176. for (var i = 0; i < n; ++i) {
  11177. var info = gl.getActiveUniform(program, i),
  11178. addr = gl.getUniformLocation(program, info.name);
  11179. parseUniform(info, addr, this);
  11180. }
  11181. }
  11182. WebGLUniforms.prototype.setValue = function (gl, name, value, textures) {
  11183. var u = this.map[name];
  11184. if (u !== undefined) u.setValue(gl, value, textures);
  11185. };
  11186. WebGLUniforms.prototype.setOptional = function (gl, object, name) {
  11187. var v = object[name];
  11188. if (v !== undefined) this.setValue(gl, name, v);
  11189. }; // Static interface
  11190. WebGLUniforms.upload = function (gl, seq, values, textures) {
  11191. for (var i = 0, n = seq.length; i !== n; ++i) {
  11192. var u = seq[i],
  11193. v = values[u.id];
  11194. if (v.needsUpdate !== false) {
  11195. // note: always updating when .needsUpdate is undefined
  11196. u.setValue(gl, v.value, textures);
  11197. }
  11198. }
  11199. };
  11200. WebGLUniforms.seqWithValue = function (seq, values) {
  11201. var r = [];
  11202. for (var i = 0, n = seq.length; i !== n; ++i) {
  11203. var u = seq[i];
  11204. if (u.id in values) r.push(u);
  11205. }
  11206. return r;
  11207. };
  11208. function WebGLShader(gl, type, string) {
  11209. var shader = gl.createShader(type);
  11210. gl.shaderSource(shader, string);
  11211. gl.compileShader(shader);
  11212. return shader;
  11213. }
  11214. var programIdCount = 0;
  11215. function addLineNumbers(string) {
  11216. var lines = string.split('\n');
  11217. for (var i = 0; i < lines.length; i++) {
  11218. lines[i] = i + 1 + ': ' + lines[i];
  11219. }
  11220. return lines.join('\n');
  11221. }
  11222. function getEncodingComponents(encoding) {
  11223. switch (encoding) {
  11224. case LinearEncoding:
  11225. return ['Linear', '( value )'];
  11226. case sRGBEncoding:
  11227. return ['sRGB', '( value )'];
  11228. case RGBEEncoding:
  11229. return ['RGBE', '( value )'];
  11230. case RGBM7Encoding:
  11231. return ['RGBM', '( value, 7.0 )'];
  11232. case RGBM16Encoding:
  11233. return ['RGBM', '( value, 16.0 )'];
  11234. case RGBDEncoding:
  11235. return ['RGBD', '( value, 256.0 )'];
  11236. case GammaEncoding:
  11237. return ['Gamma', '( value, float( GAMMA_FACTOR ) )'];
  11238. case LogLuvEncoding:
  11239. return ['LogLuv', '( value )'];
  11240. default:
  11241. console.warn('THREE.WebGLProgram: Unsupported encoding:', encoding);
  11242. return ['Linear', '( value )'];
  11243. }
  11244. }
  11245. function getShaderErrors(gl, shader, type) {
  11246. var status = gl.getShaderParameter(shader, 35713);
  11247. var log = gl.getShaderInfoLog(shader).trim();
  11248. if (status && log === '') return ''; // --enable-privileged-webgl-extension
  11249. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  11250. var source = gl.getShaderSource(shader);
  11251. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers(source);
  11252. }
  11253. function getTexelDecodingFunction(functionName, encoding) {
  11254. var components = getEncodingComponents(encoding);
  11255. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[0] + 'ToLinear' + components[1] + '; }';
  11256. }
  11257. function getTexelEncodingFunction(functionName, encoding) {
  11258. var components = getEncodingComponents(encoding);
  11259. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[0] + components[1] + '; }';
  11260. }
  11261. function getToneMappingFunction(functionName, toneMapping) {
  11262. var toneMappingName;
  11263. switch (toneMapping) {
  11264. case LinearToneMapping:
  11265. toneMappingName = 'Linear';
  11266. break;
  11267. case ReinhardToneMapping:
  11268. toneMappingName = 'Reinhard';
  11269. break;
  11270. case CineonToneMapping:
  11271. toneMappingName = 'OptimizedCineon';
  11272. break;
  11273. case ACESFilmicToneMapping:
  11274. toneMappingName = 'ACESFilmic';
  11275. break;
  11276. case CustomToneMapping:
  11277. toneMappingName = 'Custom';
  11278. break;
  11279. default:
  11280. console.warn('THREE.WebGLProgram: Unsupported toneMapping:', toneMapping);
  11281. toneMappingName = 'Linear';
  11282. }
  11283. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  11284. }
  11285. function generateExtensions(parameters) {
  11286. 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' : ''];
  11287. return chunks.filter(filterEmptyLine).join('\n');
  11288. }
  11289. function generateDefines(defines) {
  11290. var chunks = [];
  11291. for (var name in defines) {
  11292. var value = defines[name];
  11293. if (value === false) continue;
  11294. chunks.push('#define ' + name + ' ' + value);
  11295. }
  11296. return chunks.join('\n');
  11297. }
  11298. function fetchAttributeLocations(gl, program) {
  11299. var attributes = {};
  11300. var n = gl.getProgramParameter(program, 35721);
  11301. for (var i = 0; i < n; i++) {
  11302. var info = gl.getActiveAttrib(program, i);
  11303. var name = info.name; // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  11304. attributes[name] = gl.getAttribLocation(program, name);
  11305. }
  11306. return attributes;
  11307. }
  11308. function filterEmptyLine(string) {
  11309. return string !== '';
  11310. }
  11311. function replaceLightNums(string, parameters) {
  11312. 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);
  11313. }
  11314. function replaceClippingPlaneNums(string, parameters) {
  11315. return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection);
  11316. } // Resolve Includes
  11317. var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  11318. function resolveIncludes(string) {
  11319. return string.replace(includePattern, includeReplacer);
  11320. }
  11321. function includeReplacer(match, include) {
  11322. var string = ShaderChunk[include];
  11323. if (string === undefined) {
  11324. throw new Error('Can not resolve #include <' + include + '>');
  11325. }
  11326. return resolveIncludes(string);
  11327. } // Unroll Loops
  11328. var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  11329. 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;
  11330. function unrollLoops(string) {
  11331. return string.replace(unrollLoopPattern, loopReplacer).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer);
  11332. }
  11333. function deprecatedLoopReplacer(match, start, end, snippet) {
  11334. console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');
  11335. return loopReplacer(match, start, end, snippet);
  11336. }
  11337. function loopReplacer(match, start, end, snippet) {
  11338. var string = '';
  11339. for (var i = parseInt(start); i < parseInt(end); i++) {
  11340. string += snippet.replace(/\[\s*i\s*\]/g, '[ ' + i + ' ]').replace(/UNROLLED_LOOP_INDEX/g, i);
  11341. }
  11342. return string;
  11343. } //
  11344. function generatePrecision(parameters) {
  11345. var precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  11346. if (parameters.precision === 'highp') {
  11347. precisionstring += '\n#define HIGH_PRECISION';
  11348. } else if (parameters.precision === 'mediump') {
  11349. precisionstring += '\n#define MEDIUM_PRECISION';
  11350. } else if (parameters.precision === 'lowp') {
  11351. precisionstring += '\n#define LOW_PRECISION';
  11352. }
  11353. return precisionstring;
  11354. }
  11355. function generateShadowMapTypeDefine(parameters) {
  11356. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  11357. if (parameters.shadowMapType === PCFShadowMap) {
  11358. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  11359. } else if (parameters.shadowMapType === PCFSoftShadowMap) {
  11360. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  11361. } else if (parameters.shadowMapType === VSMShadowMap) {
  11362. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  11363. }
  11364. return shadowMapTypeDefine;
  11365. }
  11366. function generateEnvMapTypeDefine(parameters) {
  11367. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11368. if (parameters.envMap) {
  11369. switch (parameters.envMapMode) {
  11370. case CubeReflectionMapping:
  11371. case CubeRefractionMapping:
  11372. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  11373. break;
  11374. case CubeUVReflectionMapping:
  11375. case CubeUVRefractionMapping:
  11376. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  11377. break;
  11378. }
  11379. }
  11380. return envMapTypeDefine;
  11381. }
  11382. function generateEnvMapModeDefine(parameters) {
  11383. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  11384. if (parameters.envMap) {
  11385. switch (parameters.envMapMode) {
  11386. case CubeRefractionMapping:
  11387. case CubeUVRefractionMapping:
  11388. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  11389. break;
  11390. }
  11391. }
  11392. return envMapModeDefine;
  11393. }
  11394. function generateEnvMapBlendingDefine(parameters) {
  11395. var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  11396. if (parameters.envMap) {
  11397. switch (parameters.combine) {
  11398. case MultiplyOperation:
  11399. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  11400. break;
  11401. case MixOperation:
  11402. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  11403. break;
  11404. case AddOperation:
  11405. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  11406. break;
  11407. }
  11408. }
  11409. return envMapBlendingDefine;
  11410. }
  11411. function WebGLProgram(renderer, cacheKey, parameters, bindingStates) {
  11412. var gl = renderer.getContext();
  11413. var defines = parameters.defines;
  11414. var vertexShader = parameters.vertexShader;
  11415. var fragmentShader = parameters.fragmentShader;
  11416. var shadowMapTypeDefine = generateShadowMapTypeDefine(parameters);
  11417. var envMapTypeDefine = generateEnvMapTypeDefine(parameters);
  11418. var envMapModeDefine = generateEnvMapModeDefine(parameters);
  11419. var envMapBlendingDefine = generateEnvMapBlendingDefine(parameters);
  11420. var gammaFactorDefine = renderer.gammaFactor > 0 ? renderer.gammaFactor : 1.0;
  11421. var customExtensions = parameters.isWebGL2 ? '' : generateExtensions(parameters);
  11422. var customDefines = generateDefines(defines);
  11423. var program = gl.createProgram();
  11424. var prefixVertex, prefixFragment;
  11425. var versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  11426. if (parameters.isRawShaderMaterial) {
  11427. prefixVertex = [customDefines].filter(filterEmptyLine).join('\n');
  11428. if (prefixVertex.length > 0) {
  11429. prefixVertex += '\n';
  11430. }
  11431. prefixFragment = [customExtensions, customDefines].filter(filterEmptyLine).join('\n');
  11432. if (prefixFragment.length > 0) {
  11433. prefixFragment += '\n';
  11434. }
  11435. } else {
  11436. 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');
  11437. prefixFragment = [customExtensions, generatePrecision(parameters), '#define SHADER_NAME ' + parameters.shaderName, customDefines, parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + (parameters.alphaTest % 1 ? '' : '.0') : '', // add '.0' if integer
  11438. '#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
  11439. 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
  11440. 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');
  11441. }
  11442. vertexShader = resolveIncludes(vertexShader);
  11443. vertexShader = replaceLightNums(vertexShader, parameters);
  11444. vertexShader = replaceClippingPlaneNums(vertexShader, parameters);
  11445. fragmentShader = resolveIncludes(fragmentShader);
  11446. fragmentShader = replaceLightNums(fragmentShader, parameters);
  11447. fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters);
  11448. vertexShader = unrollLoops(vertexShader);
  11449. fragmentShader = unrollLoops(fragmentShader);
  11450. if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) {
  11451. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  11452. versionString = '#version 300 es\n';
  11453. prefixVertex = ['#define attribute in', '#define varying out', '#define texture2D texture'].join('\n') + '\n' + prefixVertex;
  11454. 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;
  11455. }
  11456. var vertexGlsl = versionString + prefixVertex + vertexShader;
  11457. var fragmentGlsl = versionString + prefixFragment + fragmentShader; // console.log( '*VERTEX*', vertexGlsl );
  11458. // console.log( '*FRAGMENT*', fragmentGlsl );
  11459. var glVertexShader = WebGLShader(gl, 35633, vertexGlsl);
  11460. var glFragmentShader = WebGLShader(gl, 35632, fragmentGlsl);
  11461. gl.attachShader(program, glVertexShader);
  11462. gl.attachShader(program, glFragmentShader); // Force a particular attribute to index 0.
  11463. if (parameters.index0AttributeName !== undefined) {
  11464. gl.bindAttribLocation(program, 0, parameters.index0AttributeName);
  11465. } else if (parameters.morphTargets === true) {
  11466. // programs with morphTargets displace position out of attribute 0
  11467. gl.bindAttribLocation(program, 0, 'position');
  11468. }
  11469. gl.linkProgram(program); // check for link errors
  11470. if (renderer.debug.checkShaderErrors) {
  11471. var programLog = gl.getProgramInfoLog(program).trim();
  11472. var vertexLog = gl.getShaderInfoLog(glVertexShader).trim();
  11473. var fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim();
  11474. var runnable = true;
  11475. var haveDiagnostics = true;
  11476. if (gl.getProgramParameter(program, 35714) === false) {
  11477. runnable = false;
  11478. var vertexErrors = getShaderErrors(gl, glVertexShader, 'vertex');
  11479. var fragmentErrors = getShaderErrors(gl, glFragmentShader, 'fragment');
  11480. console.error('THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter(program, 35715), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors);
  11481. } else if (programLog !== '') {
  11482. console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()', programLog);
  11483. } else if (vertexLog === '' || fragmentLog === '') {
  11484. haveDiagnostics = false;
  11485. }
  11486. if (haveDiagnostics) {
  11487. this.diagnostics = {
  11488. runnable: runnable,
  11489. programLog: programLog,
  11490. vertexShader: {
  11491. log: vertexLog,
  11492. prefix: prefixVertex
  11493. },
  11494. fragmentShader: {
  11495. log: fragmentLog,
  11496. prefix: prefixFragment
  11497. }
  11498. };
  11499. }
  11500. } // Clean up
  11501. // Crashes in iOS9 and iOS10. #18402
  11502. // gl.detachShader( program, glVertexShader );
  11503. // gl.detachShader( program, glFragmentShader );
  11504. gl.deleteShader(glVertexShader);
  11505. gl.deleteShader(glFragmentShader); // set up caching for uniform locations
  11506. var cachedUniforms;
  11507. this.getUniforms = function () {
  11508. if (cachedUniforms === undefined) {
  11509. cachedUniforms = new WebGLUniforms(gl, program);
  11510. }
  11511. return cachedUniforms;
  11512. }; // set up caching for attribute locations
  11513. var cachedAttributes;
  11514. this.getAttributes = function () {
  11515. if (cachedAttributes === undefined) {
  11516. cachedAttributes = fetchAttributeLocations(gl, program);
  11517. }
  11518. return cachedAttributes;
  11519. }; // free resource
  11520. this.destroy = function () {
  11521. bindingStates.releaseStatesOfProgram(this);
  11522. gl.deleteProgram(program);
  11523. this.program = undefined;
  11524. }; //
  11525. this.name = parameters.shaderName;
  11526. this.id = programIdCount++;
  11527. this.cacheKey = cacheKey;
  11528. this.usedTimes = 1;
  11529. this.program = program;
  11530. this.vertexShader = glVertexShader;
  11531. this.fragmentShader = glFragmentShader;
  11532. return this;
  11533. }
  11534. function WebGLPrograms(renderer, cubemaps, extensions, capabilities, bindingStates, clipping) {
  11535. var programs = [];
  11536. var isWebGL2 = capabilities.isWebGL2;
  11537. var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  11538. var floatVertexTextures = capabilities.floatVertexTextures;
  11539. var maxVertexUniforms = capabilities.maxVertexUniforms;
  11540. var vertexTextures = capabilities.vertexTextures;
  11541. var precision = capabilities.precision;
  11542. var shaderIDs = {
  11543. MeshDepthMaterial: 'depth',
  11544. MeshDistanceMaterial: 'distanceRGBA',
  11545. MeshNormalMaterial: 'normal',
  11546. MeshBasicMaterial: 'basic',
  11547. MeshLambertMaterial: 'lambert',
  11548. MeshPhongMaterial: 'phong',
  11549. MeshToonMaterial: 'toon',
  11550. MeshStandardMaterial: 'physical',
  11551. MeshPhysicalMaterial: 'physical',
  11552. MeshMatcapMaterial: 'matcap',
  11553. LineBasicMaterial: 'basic',
  11554. LineDashedMaterial: 'dashed',
  11555. PointsMaterial: 'points',
  11556. ShadowMaterial: 'shadow',
  11557. SpriteMaterial: 'sprite'
  11558. };
  11559. 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'];
  11560. function getMaxBones(object) {
  11561. var skeleton = object.skeleton;
  11562. var bones = skeleton.bones;
  11563. if (floatVertexTextures) {
  11564. return 1024;
  11565. } else {
  11566. // default for when object is not specified
  11567. // ( for example when prebuilding shader to be used with multiple objects )
  11568. //
  11569. // - leave some extra space for other uniforms
  11570. // - limit here is ANGLE's 254 max uniform vectors
  11571. // (up to 54 should be safe)
  11572. var nVertexUniforms = maxVertexUniforms;
  11573. var nVertexMatrices = Math.floor((nVertexUniforms - 20) / 4);
  11574. var maxBones = Math.min(nVertexMatrices, bones.length);
  11575. if (maxBones < bones.length) {
  11576. console.warn('THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.');
  11577. return 0;
  11578. }
  11579. return maxBones;
  11580. }
  11581. }
  11582. function getTextureEncodingFromMap(map) {
  11583. var encoding;
  11584. if (map && map.isTexture) {
  11585. encoding = map.encoding;
  11586. } else if (map && map.isWebGLRenderTarget) {
  11587. console.warn('THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.');
  11588. encoding = map.texture.encoding;
  11589. } else {
  11590. encoding = LinearEncoding;
  11591. }
  11592. return encoding;
  11593. }
  11594. function getParameters(material, lights, shadows, scene, object) {
  11595. var fog = scene.fog;
  11596. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  11597. var envMap = cubemaps.get(material.envMap || environment);
  11598. var shaderID = shaderIDs[material.type]; // heuristics to create shader parameters according to lights in the scene
  11599. // (not to blow over maxLights budget)
  11600. var maxBones = object.isSkinnedMesh ? getMaxBones(object) : 0;
  11601. if (material.precision !== null) {
  11602. precision = capabilities.getMaxPrecision(material.precision);
  11603. if (precision !== material.precision) {
  11604. console.warn('THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.');
  11605. }
  11606. }
  11607. var vertexShader, fragmentShader;
  11608. if (shaderID) {
  11609. var shader = ShaderLib[shaderID];
  11610. vertexShader = shader.vertexShader;
  11611. fragmentShader = shader.fragmentShader;
  11612. } else {
  11613. vertexShader = material.vertexShader;
  11614. fragmentShader = material.fragmentShader;
  11615. }
  11616. var currentRenderTarget = renderer.getRenderTarget();
  11617. var parameters = {
  11618. isWebGL2: isWebGL2,
  11619. shaderID: shaderID,
  11620. shaderName: material.type,
  11621. vertexShader: vertexShader,
  11622. fragmentShader: fragmentShader,
  11623. defines: material.defines,
  11624. isRawShaderMaterial: material.isRawShaderMaterial === true,
  11625. glslVersion: material.glslVersion,
  11626. precision: precision,
  11627. instancing: object.isInstancedMesh === true,
  11628. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  11629. supportsVertexTextures: vertexTextures,
  11630. outputEncoding: currentRenderTarget !== null ? getTextureEncodingFromMap(currentRenderTarget.texture) : renderer.outputEncoding,
  11631. map: !!material.map,
  11632. mapEncoding: getTextureEncodingFromMap(material.map),
  11633. matcap: !!material.matcap,
  11634. matcapEncoding: getTextureEncodingFromMap(material.matcap),
  11635. envMap: !!envMap,
  11636. envMapMode: envMap && envMap.mapping,
  11637. envMapEncoding: getTextureEncodingFromMap(envMap),
  11638. envMapCubeUV: !!envMap && (envMap.mapping === CubeUVReflectionMapping || envMap.mapping === CubeUVRefractionMapping),
  11639. lightMap: !!material.lightMap,
  11640. lightMapEncoding: getTextureEncodingFromMap(material.lightMap),
  11641. aoMap: !!material.aoMap,
  11642. emissiveMap: !!material.emissiveMap,
  11643. emissiveMapEncoding: getTextureEncodingFromMap(material.emissiveMap),
  11644. bumpMap: !!material.bumpMap,
  11645. normalMap: !!material.normalMap,
  11646. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11647. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  11648. clearcoatMap: !!material.clearcoatMap,
  11649. clearcoatRoughnessMap: !!material.clearcoatRoughnessMap,
  11650. clearcoatNormalMap: !!material.clearcoatNormalMap,
  11651. displacementMap: !!material.displacementMap,
  11652. roughnessMap: !!material.roughnessMap,
  11653. metalnessMap: !!material.metalnessMap,
  11654. specularMap: !!material.specularMap,
  11655. alphaMap: !!material.alphaMap,
  11656. gradientMap: !!material.gradientMap,
  11657. sheen: !!material.sheen,
  11658. transmissionMap: !!material.transmissionMap,
  11659. combine: material.combine,
  11660. vertexTangents: material.normalMap && material.vertexTangents,
  11661. vertexColors: material.vertexColors,
  11662. 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,
  11663. uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.transmissionMap) && !!material.displacementMap,
  11664. fog: !!fog,
  11665. useFog: material.fog,
  11666. fogExp2: fog && fog.isFogExp2,
  11667. flatShading: material.flatShading,
  11668. sizeAttenuation: material.sizeAttenuation,
  11669. logarithmicDepthBuffer: logarithmicDepthBuffer,
  11670. skinning: material.skinning && maxBones > 0,
  11671. maxBones: maxBones,
  11672. useVertexTexture: floatVertexTextures,
  11673. morphTargets: material.morphTargets,
  11674. morphNormals: material.morphNormals,
  11675. maxMorphTargets: renderer.maxMorphTargets,
  11676. maxMorphNormals: renderer.maxMorphNormals,
  11677. numDirLights: lights.directional.length,
  11678. numPointLights: lights.point.length,
  11679. numSpotLights: lights.spot.length,
  11680. numRectAreaLights: lights.rectArea.length,
  11681. numHemiLights: lights.hemi.length,
  11682. numDirLightShadows: lights.directionalShadowMap.length,
  11683. numPointLightShadows: lights.pointShadowMap.length,
  11684. numSpotLightShadows: lights.spotShadowMap.length,
  11685. numClippingPlanes: clipping.numPlanes,
  11686. numClipIntersection: clipping.numIntersection,
  11687. dithering: material.dithering,
  11688. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  11689. shadowMapType: renderer.shadowMap.type,
  11690. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  11691. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11692. premultipliedAlpha: material.premultipliedAlpha,
  11693. alphaTest: material.alphaTest,
  11694. doubleSided: material.side === DoubleSide,
  11695. flipSided: material.side === BackSide,
  11696. depthPacking: material.depthPacking !== undefined ? material.depthPacking : false,
  11697. index0AttributeName: material.index0AttributeName,
  11698. extensionDerivatives: material.extensions && material.extensions.derivatives,
  11699. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  11700. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  11701. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  11702. rendererExtensionFragDepth: isWebGL2 || extensions.has('EXT_frag_depth'),
  11703. rendererExtensionDrawBuffers: isWebGL2 || extensions.has('WEBGL_draw_buffers'),
  11704. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has('EXT_shader_texture_lod'),
  11705. customProgramCacheKey: material.customProgramCacheKey()
  11706. };
  11707. return parameters;
  11708. }
  11709. function getProgramCacheKey(parameters) {
  11710. var array = [];
  11711. if (parameters.shaderID) {
  11712. array.push(parameters.shaderID);
  11713. } else {
  11714. array.push(parameters.fragmentShader);
  11715. array.push(parameters.vertexShader);
  11716. }
  11717. if (parameters.defines !== undefined) {
  11718. for (var name in parameters.defines) {
  11719. array.push(name);
  11720. array.push(parameters.defines[name]);
  11721. }
  11722. }
  11723. if (parameters.isRawShaderMaterial === false) {
  11724. for (var i = 0; i < parameterNames.length; i++) {
  11725. array.push(parameters[parameterNames[i]]);
  11726. }
  11727. array.push(renderer.outputEncoding);
  11728. array.push(renderer.gammaFactor);
  11729. }
  11730. array.push(parameters.customProgramCacheKey);
  11731. return array.join();
  11732. }
  11733. function getUniforms(material) {
  11734. var shaderID = shaderIDs[material.type];
  11735. var uniforms;
  11736. if (shaderID) {
  11737. var shader = ShaderLib[shaderID];
  11738. uniforms = UniformsUtils.clone(shader.uniforms);
  11739. } else {
  11740. uniforms = material.uniforms;
  11741. }
  11742. return uniforms;
  11743. }
  11744. function acquireProgram(parameters, cacheKey) {
  11745. var program; // Check if code has been already compiled
  11746. for (var p = 0, pl = programs.length; p < pl; p++) {
  11747. var preexistingProgram = programs[p];
  11748. if (preexistingProgram.cacheKey === cacheKey) {
  11749. program = preexistingProgram;
  11750. ++program.usedTimes;
  11751. break;
  11752. }
  11753. }
  11754. if (program === undefined) {
  11755. program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates);
  11756. programs.push(program);
  11757. }
  11758. return program;
  11759. }
  11760. function releaseProgram(program) {
  11761. if (--program.usedTimes === 0) {
  11762. // Remove from unordered set
  11763. var i = programs.indexOf(program);
  11764. programs[i] = programs[programs.length - 1];
  11765. programs.pop(); // Free WebGL resources
  11766. program.destroy();
  11767. }
  11768. }
  11769. return {
  11770. getParameters: getParameters,
  11771. getProgramCacheKey: getProgramCacheKey,
  11772. getUniforms: getUniforms,
  11773. acquireProgram: acquireProgram,
  11774. releaseProgram: releaseProgram,
  11775. // Exposed for resource monitoring & error feedback via renderer.info:
  11776. programs: programs
  11777. };
  11778. }
  11779. function WebGLProperties() {
  11780. var properties = new WeakMap();
  11781. function get(object) {
  11782. var map = properties.get(object);
  11783. if (map === undefined) {
  11784. map = {};
  11785. properties.set(object, map);
  11786. }
  11787. return map;
  11788. }
  11789. function remove(object) {
  11790. properties.delete(object);
  11791. }
  11792. function update(object, key, value) {
  11793. properties.get(object)[key] = value;
  11794. }
  11795. function dispose() {
  11796. properties = new WeakMap();
  11797. }
  11798. return {
  11799. get: get,
  11800. remove: remove,
  11801. update: update,
  11802. dispose: dispose
  11803. };
  11804. }
  11805. function painterSortStable(a, b) {
  11806. if (a.groupOrder !== b.groupOrder) {
  11807. return a.groupOrder - b.groupOrder;
  11808. } else if (a.renderOrder !== b.renderOrder) {
  11809. return a.renderOrder - b.renderOrder;
  11810. } else if (a.program !== b.program) {
  11811. return a.program.id - b.program.id;
  11812. } else if (a.material.id !== b.material.id) {
  11813. return a.material.id - b.material.id;
  11814. } else if (a.z !== b.z) {
  11815. return a.z - b.z;
  11816. } else {
  11817. return a.id - b.id;
  11818. }
  11819. }
  11820. function reversePainterSortStable(a, b) {
  11821. if (a.groupOrder !== b.groupOrder) {
  11822. return a.groupOrder - b.groupOrder;
  11823. } else if (a.renderOrder !== b.renderOrder) {
  11824. return a.renderOrder - b.renderOrder;
  11825. } else if (a.z !== b.z) {
  11826. return b.z - a.z;
  11827. } else {
  11828. return a.id - b.id;
  11829. }
  11830. }
  11831. function WebGLRenderList(properties) {
  11832. var renderItems = [];
  11833. var renderItemsIndex = 0;
  11834. var opaque = [];
  11835. var transparent = [];
  11836. var defaultProgram = {
  11837. id: -1
  11838. };
  11839. function init() {
  11840. renderItemsIndex = 0;
  11841. opaque.length = 0;
  11842. transparent.length = 0;
  11843. }
  11844. function getNextRenderItem(object, geometry, material, groupOrder, z, group) {
  11845. var renderItem = renderItems[renderItemsIndex];
  11846. var materialProperties = properties.get(material);
  11847. if (renderItem === undefined) {
  11848. renderItem = {
  11849. id: object.id,
  11850. object: object,
  11851. geometry: geometry,
  11852. material: material,
  11853. program: materialProperties.program || defaultProgram,
  11854. groupOrder: groupOrder,
  11855. renderOrder: object.renderOrder,
  11856. z: z,
  11857. group: group
  11858. };
  11859. renderItems[renderItemsIndex] = renderItem;
  11860. } else {
  11861. renderItem.id = object.id;
  11862. renderItem.object = object;
  11863. renderItem.geometry = geometry;
  11864. renderItem.material = material;
  11865. renderItem.program = materialProperties.program || defaultProgram;
  11866. renderItem.groupOrder = groupOrder;
  11867. renderItem.renderOrder = object.renderOrder;
  11868. renderItem.z = z;
  11869. renderItem.group = group;
  11870. }
  11871. renderItemsIndex++;
  11872. return renderItem;
  11873. }
  11874. function push(object, geometry, material, groupOrder, z, group) {
  11875. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11876. (material.transparent === true ? transparent : opaque).push(renderItem);
  11877. }
  11878. function unshift(object, geometry, material, groupOrder, z, group) {
  11879. var renderItem = getNextRenderItem(object, geometry, material, groupOrder, z, group);
  11880. (material.transparent === true ? transparent : opaque).unshift(renderItem);
  11881. }
  11882. function sort(customOpaqueSort, customTransparentSort) {
  11883. if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable);
  11884. if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable);
  11885. }
  11886. function finish() {
  11887. // Clear references from inactive renderItems in the list
  11888. for (var i = renderItemsIndex, il = renderItems.length; i < il; i++) {
  11889. var renderItem = renderItems[i];
  11890. if (renderItem.id === null) break;
  11891. renderItem.id = null;
  11892. renderItem.object = null;
  11893. renderItem.geometry = null;
  11894. renderItem.material = null;
  11895. renderItem.program = null;
  11896. renderItem.group = null;
  11897. }
  11898. }
  11899. return {
  11900. opaque: opaque,
  11901. transparent: transparent,
  11902. init: init,
  11903. push: push,
  11904. unshift: unshift,
  11905. finish: finish,
  11906. sort: sort
  11907. };
  11908. }
  11909. function WebGLRenderLists(properties) {
  11910. var lists = new WeakMap();
  11911. function get(scene, camera) {
  11912. var cameras = lists.get(scene);
  11913. var list;
  11914. if (cameras === undefined) {
  11915. list = new WebGLRenderList(properties);
  11916. lists.set(scene, new WeakMap());
  11917. lists.get(scene).set(camera, list);
  11918. } else {
  11919. list = cameras.get(camera);
  11920. if (list === undefined) {
  11921. list = new WebGLRenderList(properties);
  11922. cameras.set(camera, list);
  11923. }
  11924. }
  11925. return list;
  11926. }
  11927. function dispose() {
  11928. lists = new WeakMap();
  11929. }
  11930. return {
  11931. get: get,
  11932. dispose: dispose
  11933. };
  11934. }
  11935. function UniformsCache() {
  11936. var lights = {};
  11937. return {
  11938. get: function get(light) {
  11939. if (lights[light.id] !== undefined) {
  11940. return lights[light.id];
  11941. }
  11942. var uniforms;
  11943. switch (light.type) {
  11944. case 'DirectionalLight':
  11945. uniforms = {
  11946. direction: new Vector3(),
  11947. color: new Color()
  11948. };
  11949. break;
  11950. case 'SpotLight':
  11951. uniforms = {
  11952. position: new Vector3(),
  11953. direction: new Vector3(),
  11954. color: new Color(),
  11955. distance: 0,
  11956. coneCos: 0,
  11957. penumbraCos: 0,
  11958. decay: 0
  11959. };
  11960. break;
  11961. case 'PointLight':
  11962. uniforms = {
  11963. position: new Vector3(),
  11964. color: new Color(),
  11965. distance: 0,
  11966. decay: 0
  11967. };
  11968. break;
  11969. case 'HemisphereLight':
  11970. uniforms = {
  11971. direction: new Vector3(),
  11972. skyColor: new Color(),
  11973. groundColor: new Color()
  11974. };
  11975. break;
  11976. case 'RectAreaLight':
  11977. uniforms = {
  11978. color: new Color(),
  11979. position: new Vector3(),
  11980. halfWidth: new Vector3(),
  11981. halfHeight: new Vector3()
  11982. };
  11983. break;
  11984. }
  11985. lights[light.id] = uniforms;
  11986. return uniforms;
  11987. }
  11988. };
  11989. }
  11990. function ShadowUniformsCache() {
  11991. var lights = {};
  11992. return {
  11993. get: function get(light) {
  11994. if (lights[light.id] !== undefined) {
  11995. return lights[light.id];
  11996. }
  11997. var uniforms;
  11998. switch (light.type) {
  11999. case 'DirectionalLight':
  12000. uniforms = {
  12001. shadowBias: 0,
  12002. shadowNormalBias: 0,
  12003. shadowRadius: 1,
  12004. shadowMapSize: new Vector2()
  12005. };
  12006. break;
  12007. case 'SpotLight':
  12008. uniforms = {
  12009. shadowBias: 0,
  12010. shadowNormalBias: 0,
  12011. shadowRadius: 1,
  12012. shadowMapSize: new Vector2()
  12013. };
  12014. break;
  12015. case 'PointLight':
  12016. uniforms = {
  12017. shadowBias: 0,
  12018. shadowNormalBias: 0,
  12019. shadowRadius: 1,
  12020. shadowMapSize: new Vector2(),
  12021. shadowCameraNear: 1,
  12022. shadowCameraFar: 1000
  12023. };
  12024. break;
  12025. // TODO (abelnation): set RectAreaLight shadow uniforms
  12026. }
  12027. lights[light.id] = uniforms;
  12028. return uniforms;
  12029. }
  12030. };
  12031. }
  12032. var nextVersion = 0;
  12033. function shadowCastingLightsFirst(lightA, lightB) {
  12034. return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 1 : 0);
  12035. }
  12036. function WebGLLights(extensions, capabilities) {
  12037. var cache = new UniformsCache();
  12038. var shadowCache = ShadowUniformsCache();
  12039. var state = {
  12040. version: 0,
  12041. hash: {
  12042. directionalLength: -1,
  12043. pointLength: -1,
  12044. spotLength: -1,
  12045. rectAreaLength: -1,
  12046. hemiLength: -1,
  12047. numDirectionalShadows: -1,
  12048. numPointShadows: -1,
  12049. numSpotShadows: -1
  12050. },
  12051. ambient: [0, 0, 0],
  12052. probe: [],
  12053. directional: [],
  12054. directionalShadow: [],
  12055. directionalShadowMap: [],
  12056. directionalShadowMatrix: [],
  12057. spot: [],
  12058. spotShadow: [],
  12059. spotShadowMap: [],
  12060. spotShadowMatrix: [],
  12061. rectArea: [],
  12062. rectAreaLTC1: null,
  12063. rectAreaLTC2: null,
  12064. point: [],
  12065. pointShadow: [],
  12066. pointShadowMap: [],
  12067. pointShadowMatrix: [],
  12068. hemi: []
  12069. };
  12070. for (var i = 0; i < 9; i++) {
  12071. state.probe.push(new Vector3());
  12072. }
  12073. var vector3 = new Vector3();
  12074. var matrix4 = new Matrix4();
  12075. var matrix42 = new Matrix4();
  12076. function setup(lights) {
  12077. var r = 0,
  12078. g = 0,
  12079. b = 0;
  12080. for (var _i = 0; _i < 9; _i++) {
  12081. state.probe[_i].set(0, 0, 0);
  12082. }
  12083. var directionalLength = 0;
  12084. var pointLength = 0;
  12085. var spotLength = 0;
  12086. var rectAreaLength = 0;
  12087. var hemiLength = 0;
  12088. var numDirectionalShadows = 0;
  12089. var numPointShadows = 0;
  12090. var numSpotShadows = 0;
  12091. lights.sort(shadowCastingLightsFirst);
  12092. for (var _i2 = 0, l = lights.length; _i2 < l; _i2++) {
  12093. var light = lights[_i2];
  12094. var color = light.color;
  12095. var intensity = light.intensity;
  12096. var distance = light.distance;
  12097. var shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null;
  12098. if (light.isAmbientLight) {
  12099. r += color.r * intensity;
  12100. g += color.g * intensity;
  12101. b += color.b * intensity;
  12102. } else if (light.isLightProbe) {
  12103. for (var j = 0; j < 9; j++) {
  12104. state.probe[j].addScaledVector(light.sh.coefficients[j], intensity);
  12105. }
  12106. } else if (light.isDirectionalLight) {
  12107. var uniforms = cache.get(light);
  12108. uniforms.color.copy(light.color).multiplyScalar(light.intensity);
  12109. if (light.castShadow) {
  12110. var shadow = light.shadow;
  12111. var shadowUniforms = shadowCache.get(light);
  12112. shadowUniforms.shadowBias = shadow.bias;
  12113. shadowUniforms.shadowNormalBias = shadow.normalBias;
  12114. shadowUniforms.shadowRadius = shadow.radius;
  12115. shadowUniforms.shadowMapSize = shadow.mapSize;
  12116. state.directionalShadow[directionalLength] = shadowUniforms;
  12117. state.directionalShadowMap[directionalLength] = shadowMap;
  12118. state.directionalShadowMatrix[directionalLength] = light.shadow.matrix;
  12119. numDirectionalShadows++;
  12120. }
  12121. state.directional[directionalLength] = uniforms;
  12122. directionalLength++;
  12123. } else if (light.isSpotLight) {
  12124. var _uniforms = cache.get(light);
  12125. _uniforms.position.setFromMatrixPosition(light.matrixWorld);
  12126. _uniforms.color.copy(color).multiplyScalar(intensity);
  12127. _uniforms.distance = distance;
  12128. _uniforms.coneCos = Math.cos(light.angle);
  12129. _uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra));
  12130. _uniforms.decay = light.decay;
  12131. if (light.castShadow) {
  12132. var _shadow = light.shadow;
  12133. var _shadowUniforms = shadowCache.get(light);
  12134. _shadowUniforms.shadowBias = _shadow.bias;
  12135. _shadowUniforms.shadowNormalBias = _shadow.normalBias;
  12136. _shadowUniforms.shadowRadius = _shadow.radius;
  12137. _shadowUniforms.shadowMapSize = _shadow.mapSize;
  12138. state.spotShadow[spotLength] = _shadowUniforms;
  12139. state.spotShadowMap[spotLength] = shadowMap;
  12140. state.spotShadowMatrix[spotLength] = light.shadow.matrix;
  12141. numSpotShadows++;
  12142. }
  12143. state.spot[spotLength] = _uniforms;
  12144. spotLength++;
  12145. } else if (light.isRectAreaLight) {
  12146. var _uniforms2 = cache.get(light); // (a) intensity is the total visible light emitted
  12147. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  12148. // (b) intensity is the brightness of the light
  12149. _uniforms2.color.copy(color).multiplyScalar(intensity);
  12150. _uniforms2.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12151. _uniforms2.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12152. state.rectArea[rectAreaLength] = _uniforms2;
  12153. rectAreaLength++;
  12154. } else if (light.isPointLight) {
  12155. var _uniforms3 = cache.get(light);
  12156. _uniforms3.color.copy(light.color).multiplyScalar(light.intensity);
  12157. _uniforms3.distance = light.distance;
  12158. _uniforms3.decay = light.decay;
  12159. if (light.castShadow) {
  12160. var _shadow2 = light.shadow;
  12161. var _shadowUniforms2 = shadowCache.get(light);
  12162. _shadowUniforms2.shadowBias = _shadow2.bias;
  12163. _shadowUniforms2.shadowNormalBias = _shadow2.normalBias;
  12164. _shadowUniforms2.shadowRadius = _shadow2.radius;
  12165. _shadowUniforms2.shadowMapSize = _shadow2.mapSize;
  12166. _shadowUniforms2.shadowCameraNear = _shadow2.camera.near;
  12167. _shadowUniforms2.shadowCameraFar = _shadow2.camera.far;
  12168. state.pointShadow[pointLength] = _shadowUniforms2;
  12169. state.pointShadowMap[pointLength] = shadowMap;
  12170. state.pointShadowMatrix[pointLength] = light.shadow.matrix;
  12171. numPointShadows++;
  12172. }
  12173. state.point[pointLength] = _uniforms3;
  12174. pointLength++;
  12175. } else if (light.isHemisphereLight) {
  12176. var _uniforms4 = cache.get(light);
  12177. _uniforms4.skyColor.copy(light.color).multiplyScalar(intensity);
  12178. _uniforms4.groundColor.copy(light.groundColor).multiplyScalar(intensity);
  12179. state.hemi[hemiLength] = _uniforms4;
  12180. hemiLength++;
  12181. }
  12182. }
  12183. if (rectAreaLength > 0) {
  12184. if (capabilities.isWebGL2) {
  12185. // WebGL 2
  12186. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12187. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12188. } else {
  12189. // WebGL 1
  12190. if (extensions.has('OES_texture_float_linear') === true) {
  12191. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  12192. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  12193. } else if (extensions.has('OES_texture_half_float_linear') === true) {
  12194. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  12195. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  12196. } else {
  12197. console.error('THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.');
  12198. }
  12199. }
  12200. }
  12201. state.ambient[0] = r;
  12202. state.ambient[1] = g;
  12203. state.ambient[2] = b;
  12204. var hash = state.hash;
  12205. 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) {
  12206. state.directional.length = directionalLength;
  12207. state.spot.length = spotLength;
  12208. state.rectArea.length = rectAreaLength;
  12209. state.point.length = pointLength;
  12210. state.hemi.length = hemiLength;
  12211. state.directionalShadow.length = numDirectionalShadows;
  12212. state.directionalShadowMap.length = numDirectionalShadows;
  12213. state.pointShadow.length = numPointShadows;
  12214. state.pointShadowMap.length = numPointShadows;
  12215. state.spotShadow.length = numSpotShadows;
  12216. state.spotShadowMap.length = numSpotShadows;
  12217. state.directionalShadowMatrix.length = numDirectionalShadows;
  12218. state.pointShadowMatrix.length = numPointShadows;
  12219. state.spotShadowMatrix.length = numSpotShadows;
  12220. hash.directionalLength = directionalLength;
  12221. hash.pointLength = pointLength;
  12222. hash.spotLength = spotLength;
  12223. hash.rectAreaLength = rectAreaLength;
  12224. hash.hemiLength = hemiLength;
  12225. hash.numDirectionalShadows = numDirectionalShadows;
  12226. hash.numPointShadows = numPointShadows;
  12227. hash.numSpotShadows = numSpotShadows;
  12228. state.version = nextVersion++;
  12229. }
  12230. }
  12231. function setupView(lights, camera) {
  12232. var directionalLength = 0;
  12233. var pointLength = 0;
  12234. var spotLength = 0;
  12235. var rectAreaLength = 0;
  12236. var hemiLength = 0;
  12237. var viewMatrix = camera.matrixWorldInverse;
  12238. for (var _i3 = 0, l = lights.length; _i3 < l; _i3++) {
  12239. var light = lights[_i3];
  12240. if (light.isDirectionalLight) {
  12241. var uniforms = state.directional[directionalLength];
  12242. uniforms.direction.setFromMatrixPosition(light.matrixWorld);
  12243. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12244. uniforms.direction.sub(vector3);
  12245. uniforms.direction.transformDirection(viewMatrix);
  12246. directionalLength++;
  12247. } else if (light.isSpotLight) {
  12248. var _uniforms5 = state.spot[spotLength];
  12249. _uniforms5.position.setFromMatrixPosition(light.matrixWorld);
  12250. _uniforms5.position.applyMatrix4(viewMatrix);
  12251. _uniforms5.direction.setFromMatrixPosition(light.matrixWorld);
  12252. vector3.setFromMatrixPosition(light.target.matrixWorld);
  12253. _uniforms5.direction.sub(vector3);
  12254. _uniforms5.direction.transformDirection(viewMatrix);
  12255. spotLength++;
  12256. } else if (light.isRectAreaLight) {
  12257. var _uniforms6 = state.rectArea[rectAreaLength];
  12258. _uniforms6.position.setFromMatrixPosition(light.matrixWorld);
  12259. _uniforms6.position.applyMatrix4(viewMatrix); // extract local rotation of light to derive width/height half vectors
  12260. matrix42.identity();
  12261. matrix4.copy(light.matrixWorld);
  12262. matrix4.premultiply(viewMatrix);
  12263. matrix42.extractRotation(matrix4);
  12264. _uniforms6.halfWidth.set(light.width * 0.5, 0.0, 0.0);
  12265. _uniforms6.halfHeight.set(0.0, light.height * 0.5, 0.0);
  12266. _uniforms6.halfWidth.applyMatrix4(matrix42);
  12267. _uniforms6.halfHeight.applyMatrix4(matrix42);
  12268. rectAreaLength++;
  12269. } else if (light.isPointLight) {
  12270. var _uniforms7 = state.point[pointLength];
  12271. _uniforms7.position.setFromMatrixPosition(light.matrixWorld);
  12272. _uniforms7.position.applyMatrix4(viewMatrix);
  12273. pointLength++;
  12274. } else if (light.isHemisphereLight) {
  12275. var _uniforms8 = state.hemi[hemiLength];
  12276. _uniforms8.direction.setFromMatrixPosition(light.matrixWorld);
  12277. _uniforms8.direction.transformDirection(viewMatrix);
  12278. _uniforms8.direction.normalize();
  12279. hemiLength++;
  12280. }
  12281. }
  12282. }
  12283. return {
  12284. setup: setup,
  12285. setupView: setupView,
  12286. state: state
  12287. };
  12288. }
  12289. function WebGLRenderState(extensions, capabilities) {
  12290. var lights = new WebGLLights(extensions, capabilities);
  12291. var lightsArray = [];
  12292. var shadowsArray = [];
  12293. function init() {
  12294. lightsArray.length = 0;
  12295. shadowsArray.length = 0;
  12296. }
  12297. function pushLight(light) {
  12298. lightsArray.push(light);
  12299. }
  12300. function pushShadow(shadowLight) {
  12301. shadowsArray.push(shadowLight);
  12302. }
  12303. function setupLights() {
  12304. lights.setup(lightsArray);
  12305. }
  12306. function setupLightsView(camera) {
  12307. lights.setupView(lightsArray, camera);
  12308. }
  12309. var state = {
  12310. lightsArray: lightsArray,
  12311. shadowsArray: shadowsArray,
  12312. lights: lights
  12313. };
  12314. return {
  12315. init: init,
  12316. state: state,
  12317. setupLights: setupLights,
  12318. setupLightsView: setupLightsView,
  12319. pushLight: pushLight,
  12320. pushShadow: pushShadow
  12321. };
  12322. }
  12323. function WebGLRenderStates(extensions, capabilities) {
  12324. var renderStates = new WeakMap();
  12325. function get(scene, renderCallDepth) {
  12326. if (renderCallDepth === void 0) {
  12327. renderCallDepth = 0;
  12328. }
  12329. var renderState;
  12330. if (renderStates.has(scene) === false) {
  12331. renderState = new WebGLRenderState(extensions, capabilities);
  12332. renderStates.set(scene, []);
  12333. renderStates.get(scene).push(renderState);
  12334. } else {
  12335. if (renderCallDepth >= renderStates.get(scene).length) {
  12336. renderState = new WebGLRenderState(extensions, capabilities);
  12337. renderStates.get(scene).push(renderState);
  12338. } else {
  12339. renderState = renderStates.get(scene)[renderCallDepth];
  12340. }
  12341. }
  12342. return renderState;
  12343. }
  12344. function dispose() {
  12345. renderStates = new WeakMap();
  12346. }
  12347. return {
  12348. get: get,
  12349. dispose: dispose
  12350. };
  12351. }
  12352. /**
  12353. * parameters = {
  12354. *
  12355. * opacity: <float>,
  12356. *
  12357. * map: new THREE.Texture( <Image> ),
  12358. *
  12359. * alphaMap: new THREE.Texture( <Image> ),
  12360. *
  12361. * displacementMap: new THREE.Texture( <Image> ),
  12362. * displacementScale: <float>,
  12363. * displacementBias: <float>,
  12364. *
  12365. * wireframe: <boolean>,
  12366. * wireframeLinewidth: <float>
  12367. * }
  12368. */
  12369. function MeshDepthMaterial(parameters) {
  12370. Material.call(this);
  12371. this.type = 'MeshDepthMaterial';
  12372. this.depthPacking = BasicDepthPacking;
  12373. this.skinning = false;
  12374. this.morphTargets = false;
  12375. this.map = null;
  12376. this.alphaMap = null;
  12377. this.displacementMap = null;
  12378. this.displacementScale = 1;
  12379. this.displacementBias = 0;
  12380. this.wireframe = false;
  12381. this.wireframeLinewidth = 1;
  12382. this.fog = false;
  12383. this.setValues(parameters);
  12384. }
  12385. MeshDepthMaterial.prototype = Object.create(Material.prototype);
  12386. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12387. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12388. MeshDepthMaterial.prototype.copy = function (source) {
  12389. Material.prototype.copy.call(this, source);
  12390. this.depthPacking = source.depthPacking;
  12391. this.skinning = source.skinning;
  12392. this.morphTargets = source.morphTargets;
  12393. this.map = source.map;
  12394. this.alphaMap = source.alphaMap;
  12395. this.displacementMap = source.displacementMap;
  12396. this.displacementScale = source.displacementScale;
  12397. this.displacementBias = source.displacementBias;
  12398. this.wireframe = source.wireframe;
  12399. this.wireframeLinewidth = source.wireframeLinewidth;
  12400. return this;
  12401. };
  12402. /**
  12403. * parameters = {
  12404. *
  12405. * referencePosition: <float>,
  12406. * nearDistance: <float>,
  12407. * farDistance: <float>,
  12408. *
  12409. * skinning: <bool>,
  12410. * morphTargets: <bool>,
  12411. *
  12412. * map: new THREE.Texture( <Image> ),
  12413. *
  12414. * alphaMap: new THREE.Texture( <Image> ),
  12415. *
  12416. * displacementMap: new THREE.Texture( <Image> ),
  12417. * displacementScale: <float>,
  12418. * displacementBias: <float>
  12419. *
  12420. * }
  12421. */
  12422. function MeshDistanceMaterial(parameters) {
  12423. Material.call(this);
  12424. this.type = 'MeshDistanceMaterial';
  12425. this.referencePosition = new Vector3();
  12426. this.nearDistance = 1;
  12427. this.farDistance = 1000;
  12428. this.skinning = false;
  12429. this.morphTargets = false;
  12430. this.map = null;
  12431. this.alphaMap = null;
  12432. this.displacementMap = null;
  12433. this.displacementScale = 1;
  12434. this.displacementBias = 0;
  12435. this.fog = false;
  12436. this.setValues(parameters);
  12437. }
  12438. MeshDistanceMaterial.prototype = Object.create(Material.prototype);
  12439. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12440. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12441. MeshDistanceMaterial.prototype.copy = function (source) {
  12442. Material.prototype.copy.call(this, source);
  12443. this.referencePosition.copy(source.referencePosition);
  12444. this.nearDistance = source.nearDistance;
  12445. this.farDistance = source.farDistance;
  12446. this.skinning = source.skinning;
  12447. this.morphTargets = source.morphTargets;
  12448. this.map = source.map;
  12449. this.alphaMap = source.alphaMap;
  12450. this.displacementMap = source.displacementMap;
  12451. this.displacementScale = source.displacementScale;
  12452. this.displacementBias = source.displacementBias;
  12453. return this;
  12454. };
  12455. 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}";
  12456. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  12457. function WebGLShadowMap(_renderer, _objects, maxTextureSize) {
  12458. var _frustum = new Frustum();
  12459. var _shadowMapSize = new Vector2(),
  12460. _viewportSize = new Vector2(),
  12461. _viewport = new Vector4(),
  12462. _depthMaterials = [],
  12463. _distanceMaterials = [],
  12464. _materialCache = {};
  12465. var shadowSide = {
  12466. 0: BackSide,
  12467. 1: FrontSide,
  12468. 2: DoubleSide
  12469. };
  12470. var shadowMaterialVertical = new ShaderMaterial({
  12471. defines: {
  12472. SAMPLE_RATE: 2.0 / 8.0,
  12473. HALF_SAMPLE_RATE: 1.0 / 8.0
  12474. },
  12475. uniforms: {
  12476. shadow_pass: {
  12477. value: null
  12478. },
  12479. resolution: {
  12480. value: new Vector2()
  12481. },
  12482. radius: {
  12483. value: 4.0
  12484. }
  12485. },
  12486. vertexShader: vsm_vert,
  12487. fragmentShader: vsm_frag
  12488. });
  12489. var shadowMaterialHorizontal = shadowMaterialVertical.clone();
  12490. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  12491. var fullScreenTri = new BufferGeometry();
  12492. fullScreenTri.setAttribute('position', new BufferAttribute(new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3));
  12493. var fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical);
  12494. var scope = this;
  12495. this.enabled = false;
  12496. this.autoUpdate = true;
  12497. this.needsUpdate = false;
  12498. this.type = PCFShadowMap;
  12499. this.render = function (lights, scene, camera) {
  12500. if (scope.enabled === false) return;
  12501. if (scope.autoUpdate === false && scope.needsUpdate === false) return;
  12502. if (lights.length === 0) return;
  12503. var currentRenderTarget = _renderer.getRenderTarget();
  12504. var activeCubeFace = _renderer.getActiveCubeFace();
  12505. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  12506. var _state = _renderer.state; // Set GL state for depth map.
  12507. _state.setBlending(NoBlending);
  12508. _state.buffers.color.setClear(1, 1, 1, 1);
  12509. _state.buffers.depth.setTest(true);
  12510. _state.setScissorTest(false); // render depth map
  12511. for (var i = 0, il = lights.length; i < il; i++) {
  12512. var light = lights[i];
  12513. var shadow = light.shadow;
  12514. if (shadow === undefined) {
  12515. console.warn('THREE.WebGLShadowMap:', light, 'has no shadow.');
  12516. continue;
  12517. }
  12518. if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue;
  12519. _shadowMapSize.copy(shadow.mapSize);
  12520. var shadowFrameExtents = shadow.getFrameExtents();
  12521. _shadowMapSize.multiply(shadowFrameExtents);
  12522. _viewportSize.copy(shadow.mapSize);
  12523. if (_shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize) {
  12524. if (_shadowMapSize.x > maxTextureSize) {
  12525. _viewportSize.x = Math.floor(maxTextureSize / shadowFrameExtents.x);
  12526. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  12527. shadow.mapSize.x = _viewportSize.x;
  12528. }
  12529. if (_shadowMapSize.y > maxTextureSize) {
  12530. _viewportSize.y = Math.floor(maxTextureSize / shadowFrameExtents.y);
  12531. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  12532. shadow.mapSize.y = _viewportSize.y;
  12533. }
  12534. }
  12535. if (shadow.map === null && !shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12536. var pars = {
  12537. minFilter: LinearFilter,
  12538. magFilter: LinearFilter,
  12539. format: RGBAFormat
  12540. };
  12541. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12542. shadow.map.texture.name = light.name + '.shadowMap';
  12543. shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
  12544. shadow.camera.updateProjectionMatrix();
  12545. }
  12546. if (shadow.map === null) {
  12547. var _pars = {
  12548. minFilter: NearestFilter,
  12549. magFilter: NearestFilter,
  12550. format: RGBAFormat
  12551. };
  12552. shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, _pars);
  12553. shadow.map.texture.name = light.name + '.shadowMap';
  12554. shadow.camera.updateProjectionMatrix();
  12555. }
  12556. _renderer.setRenderTarget(shadow.map);
  12557. _renderer.clear();
  12558. var viewportCount = shadow.getViewportCount();
  12559. for (var vp = 0; vp < viewportCount; vp++) {
  12560. var viewport = shadow.getViewport(vp);
  12561. _viewport.set(_viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w);
  12562. _state.viewport(_viewport);
  12563. shadow.updateMatrices(light, vp);
  12564. _frustum = shadow.getFrustum();
  12565. renderObject(scene, camera, shadow.camera, light, this.type);
  12566. } // do blur pass for VSM
  12567. if (!shadow.isPointLightShadow && this.type === VSMShadowMap) {
  12568. VSMPass(shadow, camera);
  12569. }
  12570. shadow.needsUpdate = false;
  12571. }
  12572. scope.needsUpdate = false;
  12573. _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel);
  12574. };
  12575. function VSMPass(shadow, camera) {
  12576. var geometry = _objects.update(fullScreenMesh); // vertical pass
  12577. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  12578. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  12579. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  12580. _renderer.setRenderTarget(shadow.mapPass);
  12581. _renderer.clear();
  12582. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null); // horizontal pass
  12583. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  12584. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  12585. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  12586. _renderer.setRenderTarget(shadow.map);
  12587. _renderer.clear();
  12588. _renderer.renderBufferDirect(camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null);
  12589. }
  12590. function getDepthMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12591. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12592. var material = _depthMaterials[index];
  12593. if (material === undefined) {
  12594. material = new MeshDepthMaterial({
  12595. depthPacking: RGBADepthPacking,
  12596. morphTargets: useMorphing,
  12597. skinning: useSkinning
  12598. });
  12599. _depthMaterials[index] = material;
  12600. }
  12601. return material;
  12602. }
  12603. function getDistanceMaterialVariant(useMorphing, useSkinning, useInstancing) {
  12604. var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  12605. var material = _distanceMaterials[index];
  12606. if (material === undefined) {
  12607. material = new MeshDistanceMaterial({
  12608. morphTargets: useMorphing,
  12609. skinning: useSkinning
  12610. });
  12611. _distanceMaterials[index] = material;
  12612. }
  12613. return material;
  12614. }
  12615. function getDepthMaterial(object, geometry, material, light, shadowCameraNear, shadowCameraFar, type) {
  12616. var result = null;
  12617. var getMaterialVariant = getDepthMaterialVariant;
  12618. var customMaterial = object.customDepthMaterial;
  12619. if (light.isPointLight === true) {
  12620. getMaterialVariant = getDistanceMaterialVariant;
  12621. customMaterial = object.customDistanceMaterial;
  12622. }
  12623. if (customMaterial === undefined) {
  12624. var useMorphing = false;
  12625. if (material.morphTargets === true) {
  12626. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  12627. }
  12628. var useSkinning = false;
  12629. if (object.isSkinnedMesh === true) {
  12630. if (material.skinning === true) {
  12631. useSkinning = true;
  12632. } else {
  12633. console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object);
  12634. }
  12635. }
  12636. var useInstancing = object.isInstancedMesh === true;
  12637. result = getMaterialVariant(useMorphing, useSkinning, useInstancing);
  12638. } else {
  12639. result = customMaterial;
  12640. }
  12641. if (_renderer.localClippingEnabled && material.clipShadows === true && material.clippingPlanes.length !== 0) {
  12642. // in this case we need a unique material instance reflecting the
  12643. // appropriate state
  12644. var keyA = result.uuid,
  12645. keyB = material.uuid;
  12646. var materialsForVariant = _materialCache[keyA];
  12647. if (materialsForVariant === undefined) {
  12648. materialsForVariant = {};
  12649. _materialCache[keyA] = materialsForVariant;
  12650. }
  12651. var cachedMaterial = materialsForVariant[keyB];
  12652. if (cachedMaterial === undefined) {
  12653. cachedMaterial = result.clone();
  12654. materialsForVariant[keyB] = cachedMaterial;
  12655. }
  12656. result = cachedMaterial;
  12657. }
  12658. result.visible = material.visible;
  12659. result.wireframe = material.wireframe;
  12660. if (type === VSMShadowMap) {
  12661. result.side = material.shadowSide !== null ? material.shadowSide : material.side;
  12662. } else {
  12663. result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side];
  12664. }
  12665. result.clipShadows = material.clipShadows;
  12666. result.clippingPlanes = material.clippingPlanes;
  12667. result.clipIntersection = material.clipIntersection;
  12668. result.wireframeLinewidth = material.wireframeLinewidth;
  12669. result.linewidth = material.linewidth;
  12670. if (light.isPointLight === true && result.isMeshDistanceMaterial === true) {
  12671. result.referencePosition.setFromMatrixPosition(light.matrixWorld);
  12672. result.nearDistance = shadowCameraNear;
  12673. result.farDistance = shadowCameraFar;
  12674. }
  12675. return result;
  12676. }
  12677. function renderObject(object, camera, shadowCamera, light, type) {
  12678. if (object.visible === false) return;
  12679. var visible = object.layers.test(camera.layers);
  12680. if (visible && (object.isMesh || object.isLine || object.isPoints)) {
  12681. if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) {
  12682. object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld);
  12683. var geometry = _objects.update(object);
  12684. var material = object.material;
  12685. if (Array.isArray(material)) {
  12686. var groups = geometry.groups;
  12687. for (var k = 0, kl = groups.length; k < kl; k++) {
  12688. var group = groups[k];
  12689. var groupMaterial = material[group.materialIndex];
  12690. if (groupMaterial && groupMaterial.visible) {
  12691. var depthMaterial = getDepthMaterial(object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type);
  12692. _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group);
  12693. }
  12694. }
  12695. } else if (material.visible) {
  12696. var _depthMaterial = getDepthMaterial(object, geometry, material, light, shadowCamera.near, shadowCamera.far, type);
  12697. _renderer.renderBufferDirect(shadowCamera, null, geometry, _depthMaterial, object, null);
  12698. }
  12699. }
  12700. }
  12701. var children = object.children;
  12702. for (var i = 0, l = children.length; i < l; i++) {
  12703. renderObject(children[i], camera, shadowCamera, light, type);
  12704. }
  12705. }
  12706. }
  12707. function WebGLState(gl, extensions, capabilities) {
  12708. var _equationToGL, _factorToGL;
  12709. var isWebGL2 = capabilities.isWebGL2;
  12710. function ColorBuffer() {
  12711. var locked = false;
  12712. var color = new Vector4();
  12713. var currentColorMask = null;
  12714. var currentColorClear = new Vector4(0, 0, 0, 0);
  12715. return {
  12716. setMask: function setMask(colorMask) {
  12717. if (currentColorMask !== colorMask && !locked) {
  12718. gl.colorMask(colorMask, colorMask, colorMask, colorMask);
  12719. currentColorMask = colorMask;
  12720. }
  12721. },
  12722. setLocked: function setLocked(lock) {
  12723. locked = lock;
  12724. },
  12725. setClear: function setClear(r, g, b, a, premultipliedAlpha) {
  12726. if (premultipliedAlpha === true) {
  12727. r *= a;
  12728. g *= a;
  12729. b *= a;
  12730. }
  12731. color.set(r, g, b, a);
  12732. if (currentColorClear.equals(color) === false) {
  12733. gl.clearColor(r, g, b, a);
  12734. currentColorClear.copy(color);
  12735. }
  12736. },
  12737. reset: function reset() {
  12738. locked = false;
  12739. currentColorMask = null;
  12740. currentColorClear.set(-1, 0, 0, 0); // set to invalid state
  12741. }
  12742. };
  12743. }
  12744. function DepthBuffer() {
  12745. var locked = false;
  12746. var currentDepthMask = null;
  12747. var currentDepthFunc = null;
  12748. var currentDepthClear = null;
  12749. return {
  12750. setTest: function setTest(depthTest) {
  12751. if (depthTest) {
  12752. enable(2929);
  12753. } else {
  12754. disable(2929);
  12755. }
  12756. },
  12757. setMask: function setMask(depthMask) {
  12758. if (currentDepthMask !== depthMask && !locked) {
  12759. gl.depthMask(depthMask);
  12760. currentDepthMask = depthMask;
  12761. }
  12762. },
  12763. setFunc: function setFunc(depthFunc) {
  12764. if (currentDepthFunc !== depthFunc) {
  12765. if (depthFunc) {
  12766. switch (depthFunc) {
  12767. case NeverDepth:
  12768. gl.depthFunc(512);
  12769. break;
  12770. case AlwaysDepth:
  12771. gl.depthFunc(519);
  12772. break;
  12773. case LessDepth:
  12774. gl.depthFunc(513);
  12775. break;
  12776. case LessEqualDepth:
  12777. gl.depthFunc(515);
  12778. break;
  12779. case EqualDepth:
  12780. gl.depthFunc(514);
  12781. break;
  12782. case GreaterEqualDepth:
  12783. gl.depthFunc(518);
  12784. break;
  12785. case GreaterDepth:
  12786. gl.depthFunc(516);
  12787. break;
  12788. case NotEqualDepth:
  12789. gl.depthFunc(517);
  12790. break;
  12791. default:
  12792. gl.depthFunc(515);
  12793. }
  12794. } else {
  12795. gl.depthFunc(515);
  12796. }
  12797. currentDepthFunc = depthFunc;
  12798. }
  12799. },
  12800. setLocked: function setLocked(lock) {
  12801. locked = lock;
  12802. },
  12803. setClear: function setClear(depth) {
  12804. if (currentDepthClear !== depth) {
  12805. gl.clearDepth(depth);
  12806. currentDepthClear = depth;
  12807. }
  12808. },
  12809. reset: function reset() {
  12810. locked = false;
  12811. currentDepthMask = null;
  12812. currentDepthFunc = null;
  12813. currentDepthClear = null;
  12814. }
  12815. };
  12816. }
  12817. function StencilBuffer() {
  12818. var locked = false;
  12819. var currentStencilMask = null;
  12820. var currentStencilFunc = null;
  12821. var currentStencilRef = null;
  12822. var currentStencilFuncMask = null;
  12823. var currentStencilFail = null;
  12824. var currentStencilZFail = null;
  12825. var currentStencilZPass = null;
  12826. var currentStencilClear = null;
  12827. return {
  12828. setTest: function setTest(stencilTest) {
  12829. if (!locked) {
  12830. if (stencilTest) {
  12831. enable(2960);
  12832. } else {
  12833. disable(2960);
  12834. }
  12835. }
  12836. },
  12837. setMask: function setMask(stencilMask) {
  12838. if (currentStencilMask !== stencilMask && !locked) {
  12839. gl.stencilMask(stencilMask);
  12840. currentStencilMask = stencilMask;
  12841. }
  12842. },
  12843. setFunc: function setFunc(stencilFunc, stencilRef, stencilMask) {
  12844. if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) {
  12845. gl.stencilFunc(stencilFunc, stencilRef, stencilMask);
  12846. currentStencilFunc = stencilFunc;
  12847. currentStencilRef = stencilRef;
  12848. currentStencilFuncMask = stencilMask;
  12849. }
  12850. },
  12851. setOp: function setOp(stencilFail, stencilZFail, stencilZPass) {
  12852. if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) {
  12853. gl.stencilOp(stencilFail, stencilZFail, stencilZPass);
  12854. currentStencilFail = stencilFail;
  12855. currentStencilZFail = stencilZFail;
  12856. currentStencilZPass = stencilZPass;
  12857. }
  12858. },
  12859. setLocked: function setLocked(lock) {
  12860. locked = lock;
  12861. },
  12862. setClear: function setClear(stencil) {
  12863. if (currentStencilClear !== stencil) {
  12864. gl.clearStencil(stencil);
  12865. currentStencilClear = stencil;
  12866. }
  12867. },
  12868. reset: function reset() {
  12869. locked = false;
  12870. currentStencilMask = null;
  12871. currentStencilFunc = null;
  12872. currentStencilRef = null;
  12873. currentStencilFuncMask = null;
  12874. currentStencilFail = null;
  12875. currentStencilZFail = null;
  12876. currentStencilZPass = null;
  12877. currentStencilClear = null;
  12878. }
  12879. };
  12880. } //
  12881. var colorBuffer = new ColorBuffer();
  12882. var depthBuffer = new DepthBuffer();
  12883. var stencilBuffer = new StencilBuffer();
  12884. var enabledCapabilities = {};
  12885. var currentProgram = null;
  12886. var currentBlendingEnabled = null;
  12887. var currentBlending = null;
  12888. var currentBlendEquation = null;
  12889. var currentBlendSrc = null;
  12890. var currentBlendDst = null;
  12891. var currentBlendEquationAlpha = null;
  12892. var currentBlendSrcAlpha = null;
  12893. var currentBlendDstAlpha = null;
  12894. var currentPremultipledAlpha = false;
  12895. var currentFlipSided = null;
  12896. var currentCullFace = null;
  12897. var currentLineWidth = null;
  12898. var currentPolygonOffsetFactor = null;
  12899. var currentPolygonOffsetUnits = null;
  12900. var maxTextures = gl.getParameter(35661);
  12901. var lineWidthAvailable = false;
  12902. var version = 0;
  12903. var glVersion = gl.getParameter(7938);
  12904. if (glVersion.indexOf('WebGL') !== -1) {
  12905. version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]);
  12906. lineWidthAvailable = version >= 1.0;
  12907. } else if (glVersion.indexOf('OpenGL ES') !== -1) {
  12908. version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]);
  12909. lineWidthAvailable = version >= 2.0;
  12910. }
  12911. var currentTextureSlot = null;
  12912. var currentBoundTextures = {};
  12913. var currentScissor = new Vector4();
  12914. var currentViewport = new Vector4();
  12915. function createTexture(type, target, count) {
  12916. var data = new Uint8Array(4); // 4 is required to match default unpack alignment of 4.
  12917. var texture = gl.createTexture();
  12918. gl.bindTexture(type, texture);
  12919. gl.texParameteri(type, 10241, 9728);
  12920. gl.texParameteri(type, 10240, 9728);
  12921. for (var i = 0; i < count; i++) {
  12922. gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data);
  12923. }
  12924. return texture;
  12925. }
  12926. var emptyTextures = {};
  12927. emptyTextures[3553] = createTexture(3553, 3553, 1);
  12928. emptyTextures[34067] = createTexture(34067, 34069, 6); // init
  12929. colorBuffer.setClear(0, 0, 0, 1);
  12930. depthBuffer.setClear(1);
  12931. stencilBuffer.setClear(0);
  12932. enable(2929);
  12933. depthBuffer.setFunc(LessEqualDepth);
  12934. setFlipSided(false);
  12935. setCullFace(CullFaceBack);
  12936. enable(2884);
  12937. setBlending(NoBlending); //
  12938. function enable(id) {
  12939. if (enabledCapabilities[id] !== true) {
  12940. gl.enable(id);
  12941. enabledCapabilities[id] = true;
  12942. }
  12943. }
  12944. function disable(id) {
  12945. if (enabledCapabilities[id] !== false) {
  12946. gl.disable(id);
  12947. enabledCapabilities[id] = false;
  12948. }
  12949. }
  12950. function useProgram(program) {
  12951. if (currentProgram !== program) {
  12952. gl.useProgram(program);
  12953. currentProgram = program;
  12954. return true;
  12955. }
  12956. return false;
  12957. }
  12958. var equationToGL = (_equationToGL = {}, _equationToGL[AddEquation] = 32774, _equationToGL[SubtractEquation] = 32778, _equationToGL[ReverseSubtractEquation] = 32779, _equationToGL);
  12959. if (isWebGL2) {
  12960. equationToGL[MinEquation] = 32775;
  12961. equationToGL[MaxEquation] = 32776;
  12962. } else {
  12963. var extension = extensions.get('EXT_blend_minmax');
  12964. if (extension !== null) {
  12965. equationToGL[MinEquation] = extension.MIN_EXT;
  12966. equationToGL[MaxEquation] = extension.MAX_EXT;
  12967. }
  12968. }
  12969. 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);
  12970. function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) {
  12971. if (blending === NoBlending) {
  12972. if (currentBlendingEnabled) {
  12973. disable(3042);
  12974. currentBlendingEnabled = false;
  12975. }
  12976. return;
  12977. }
  12978. if (!currentBlendingEnabled) {
  12979. enable(3042);
  12980. currentBlendingEnabled = true;
  12981. }
  12982. if (blending !== CustomBlending) {
  12983. if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) {
  12984. if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) {
  12985. gl.blendEquation(32774);
  12986. currentBlendEquation = AddEquation;
  12987. currentBlendEquationAlpha = AddEquation;
  12988. }
  12989. if (premultipliedAlpha) {
  12990. switch (blending) {
  12991. case NormalBlending:
  12992. gl.blendFuncSeparate(1, 771, 1, 771);
  12993. break;
  12994. case AdditiveBlending:
  12995. gl.blendFunc(1, 1);
  12996. break;
  12997. case SubtractiveBlending:
  12998. gl.blendFuncSeparate(0, 0, 769, 771);
  12999. break;
  13000. case MultiplyBlending:
  13001. gl.blendFuncSeparate(0, 768, 0, 770);
  13002. break;
  13003. default:
  13004. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13005. break;
  13006. }
  13007. } else {
  13008. switch (blending) {
  13009. case NormalBlending:
  13010. gl.blendFuncSeparate(770, 771, 1, 771);
  13011. break;
  13012. case AdditiveBlending:
  13013. gl.blendFunc(770, 1);
  13014. break;
  13015. case SubtractiveBlending:
  13016. gl.blendFunc(0, 769);
  13017. break;
  13018. case MultiplyBlending:
  13019. gl.blendFunc(0, 768);
  13020. break;
  13021. default:
  13022. console.error('THREE.WebGLState: Invalid blending: ', blending);
  13023. break;
  13024. }
  13025. }
  13026. currentBlendSrc = null;
  13027. currentBlendDst = null;
  13028. currentBlendSrcAlpha = null;
  13029. currentBlendDstAlpha = null;
  13030. currentBlending = blending;
  13031. currentPremultipledAlpha = premultipliedAlpha;
  13032. }
  13033. return;
  13034. } // custom blending
  13035. blendEquationAlpha = blendEquationAlpha || blendEquation;
  13036. blendSrcAlpha = blendSrcAlpha || blendSrc;
  13037. blendDstAlpha = blendDstAlpha || blendDst;
  13038. if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) {
  13039. gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]);
  13040. currentBlendEquation = blendEquation;
  13041. currentBlendEquationAlpha = blendEquationAlpha;
  13042. }
  13043. if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) {
  13044. gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]);
  13045. currentBlendSrc = blendSrc;
  13046. currentBlendDst = blendDst;
  13047. currentBlendSrcAlpha = blendSrcAlpha;
  13048. currentBlendDstAlpha = blendDstAlpha;
  13049. }
  13050. currentBlending = blending;
  13051. currentPremultipledAlpha = null;
  13052. }
  13053. function setMaterial(material, frontFaceCW) {
  13054. material.side === DoubleSide ? disable(2884) : enable(2884);
  13055. var flipSided = material.side === BackSide;
  13056. if (frontFaceCW) flipSided = !flipSided;
  13057. setFlipSided(flipSided);
  13058. 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);
  13059. depthBuffer.setFunc(material.depthFunc);
  13060. depthBuffer.setTest(material.depthTest);
  13061. depthBuffer.setMask(material.depthWrite);
  13062. colorBuffer.setMask(material.colorWrite);
  13063. var stencilWrite = material.stencilWrite;
  13064. stencilBuffer.setTest(stencilWrite);
  13065. if (stencilWrite) {
  13066. stencilBuffer.setMask(material.stencilWriteMask);
  13067. stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask);
  13068. stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass);
  13069. }
  13070. setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits);
  13071. } //
  13072. function setFlipSided(flipSided) {
  13073. if (currentFlipSided !== flipSided) {
  13074. if (flipSided) {
  13075. gl.frontFace(2304);
  13076. } else {
  13077. gl.frontFace(2305);
  13078. }
  13079. currentFlipSided = flipSided;
  13080. }
  13081. }
  13082. function setCullFace(cullFace) {
  13083. if (cullFace !== CullFaceNone) {
  13084. enable(2884);
  13085. if (cullFace !== currentCullFace) {
  13086. if (cullFace === CullFaceBack) {
  13087. gl.cullFace(1029);
  13088. } else if (cullFace === CullFaceFront) {
  13089. gl.cullFace(1028);
  13090. } else {
  13091. gl.cullFace(1032);
  13092. }
  13093. }
  13094. } else {
  13095. disable(2884);
  13096. }
  13097. currentCullFace = cullFace;
  13098. }
  13099. function setLineWidth(width) {
  13100. if (width !== currentLineWidth) {
  13101. if (lineWidthAvailable) gl.lineWidth(width);
  13102. currentLineWidth = width;
  13103. }
  13104. }
  13105. function setPolygonOffset(polygonOffset, factor, units) {
  13106. if (polygonOffset) {
  13107. enable(32823);
  13108. if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) {
  13109. gl.polygonOffset(factor, units);
  13110. currentPolygonOffsetFactor = factor;
  13111. currentPolygonOffsetUnits = units;
  13112. }
  13113. } else {
  13114. disable(32823);
  13115. }
  13116. }
  13117. function setScissorTest(scissorTest) {
  13118. if (scissorTest) {
  13119. enable(3089);
  13120. } else {
  13121. disable(3089);
  13122. }
  13123. } // texture
  13124. function activeTexture(webglSlot) {
  13125. if (webglSlot === undefined) webglSlot = 33984 + maxTextures - 1;
  13126. if (currentTextureSlot !== webglSlot) {
  13127. gl.activeTexture(webglSlot);
  13128. currentTextureSlot = webglSlot;
  13129. }
  13130. }
  13131. function bindTexture(webglType, webglTexture) {
  13132. if (currentTextureSlot === null) {
  13133. activeTexture();
  13134. }
  13135. var boundTexture = currentBoundTextures[currentTextureSlot];
  13136. if (boundTexture === undefined) {
  13137. boundTexture = {
  13138. type: undefined,
  13139. texture: undefined
  13140. };
  13141. currentBoundTextures[currentTextureSlot] = boundTexture;
  13142. }
  13143. if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) {
  13144. gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]);
  13145. boundTexture.type = webglType;
  13146. boundTexture.texture = webglTexture;
  13147. }
  13148. }
  13149. function unbindTexture() {
  13150. var boundTexture = currentBoundTextures[currentTextureSlot];
  13151. if (boundTexture !== undefined && boundTexture.type !== undefined) {
  13152. gl.bindTexture(boundTexture.type, null);
  13153. boundTexture.type = undefined;
  13154. boundTexture.texture = undefined;
  13155. }
  13156. }
  13157. function compressedTexImage2D() {
  13158. try {
  13159. gl.compressedTexImage2D.apply(gl, arguments);
  13160. } catch (error) {
  13161. console.error('THREE.WebGLState:', error);
  13162. }
  13163. }
  13164. function texImage2D() {
  13165. try {
  13166. gl.texImage2D.apply(gl, arguments);
  13167. } catch (error) {
  13168. console.error('THREE.WebGLState:', error);
  13169. }
  13170. }
  13171. function texImage3D() {
  13172. try {
  13173. gl.texImage3D.apply(gl, arguments);
  13174. } catch (error) {
  13175. console.error('THREE.WebGLState:', error);
  13176. }
  13177. } //
  13178. function scissor(scissor) {
  13179. if (currentScissor.equals(scissor) === false) {
  13180. gl.scissor(scissor.x, scissor.y, scissor.z, scissor.w);
  13181. currentScissor.copy(scissor);
  13182. }
  13183. }
  13184. function viewport(viewport) {
  13185. if (currentViewport.equals(viewport) === false) {
  13186. gl.viewport(viewport.x, viewport.y, viewport.z, viewport.w);
  13187. currentViewport.copy(viewport);
  13188. }
  13189. } //
  13190. function reset() {
  13191. enabledCapabilities = {};
  13192. currentTextureSlot = null;
  13193. currentBoundTextures = {};
  13194. currentProgram = null;
  13195. currentBlendingEnabled = null;
  13196. currentBlending = null;
  13197. currentBlendEquation = null;
  13198. currentBlendSrc = null;
  13199. currentBlendDst = null;
  13200. currentBlendEquationAlpha = null;
  13201. currentBlendSrcAlpha = null;
  13202. currentBlendDstAlpha = null;
  13203. currentPremultipledAlpha = false;
  13204. currentFlipSided = null;
  13205. currentCullFace = null;
  13206. currentLineWidth = null;
  13207. currentPolygonOffsetFactor = null;
  13208. currentPolygonOffsetUnits = null;
  13209. colorBuffer.reset();
  13210. depthBuffer.reset();
  13211. stencilBuffer.reset();
  13212. }
  13213. return {
  13214. buffers: {
  13215. color: colorBuffer,
  13216. depth: depthBuffer,
  13217. stencil: stencilBuffer
  13218. },
  13219. enable: enable,
  13220. disable: disable,
  13221. useProgram: useProgram,
  13222. setBlending: setBlending,
  13223. setMaterial: setMaterial,
  13224. setFlipSided: setFlipSided,
  13225. setCullFace: setCullFace,
  13226. setLineWidth: setLineWidth,
  13227. setPolygonOffset: setPolygonOffset,
  13228. setScissorTest: setScissorTest,
  13229. activeTexture: activeTexture,
  13230. bindTexture: bindTexture,
  13231. unbindTexture: unbindTexture,
  13232. compressedTexImage2D: compressedTexImage2D,
  13233. texImage2D: texImage2D,
  13234. texImage3D: texImage3D,
  13235. scissor: scissor,
  13236. viewport: viewport,
  13237. reset: reset
  13238. };
  13239. }
  13240. function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) {
  13241. var _wrappingToGL, _filterToGL;
  13242. var isWebGL2 = capabilities.isWebGL2;
  13243. var maxTextures = capabilities.maxTextures;
  13244. var maxCubemapSize = capabilities.maxCubemapSize;
  13245. var maxTextureSize = capabilities.maxTextureSize;
  13246. var maxSamples = capabilities.maxSamples;
  13247. var _videoTextures = new WeakMap();
  13248. var _canvas; // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  13249. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  13250. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  13251. var useOffscreenCanvas = false;
  13252. try {
  13253. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' && new OffscreenCanvas(1, 1).getContext('2d') !== null;
  13254. } catch (err) {// Ignore any errors
  13255. }
  13256. function createCanvas(width, height) {
  13257. // Use OffscreenCanvas when available. Specially needed in web workers
  13258. return useOffscreenCanvas ? new OffscreenCanvas(width, height) : document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  13259. }
  13260. function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  13261. var scale = 1; // handle case if texture exceeds max size
  13262. if (image.width > maxSize || image.height > maxSize) {
  13263. scale = maxSize / Math.max(image.width, image.height);
  13264. } // only perform resize if necessary
  13265. if (scale < 1 || needsPowerOfTwo === true) {
  13266. // only perform resize for certain image types
  13267. if (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement || typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  13268. var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  13269. var width = floor(scale * image.width);
  13270. var height = floor(scale * image.height);
  13271. if (_canvas === undefined) _canvas = createCanvas(width, height); // cube textures can't reuse the same canvas
  13272. var canvas = needsNewCanvas ? createCanvas(width, height) : _canvas;
  13273. canvas.width = width;
  13274. canvas.height = height;
  13275. var context = canvas.getContext('2d');
  13276. context.drawImage(image, 0, 0, width, height);
  13277. console.warn('THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').');
  13278. return canvas;
  13279. } else {
  13280. if ('data' in image) {
  13281. console.warn('THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').');
  13282. }
  13283. return image;
  13284. }
  13285. }
  13286. return image;
  13287. }
  13288. function isPowerOfTwo(image) {
  13289. return MathUtils.isPowerOfTwo(image.width) && MathUtils.isPowerOfTwo(image.height);
  13290. }
  13291. function textureNeedsPowerOfTwo(texture) {
  13292. if (isWebGL2) return false;
  13293. return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13294. }
  13295. function textureNeedsGenerateMipmaps(texture, supportsMips) {
  13296. return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  13297. }
  13298. function generateMipmap(target, texture, width, height) {
  13299. _gl.generateMipmap(target);
  13300. var textureProperties = properties.get(texture); // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  13301. textureProperties.__maxMipLevel = Math.log(Math.max(width, height)) * Math.LOG2E;
  13302. }
  13303. function getInternalFormat(internalFormatName, glFormat, glType) {
  13304. if (isWebGL2 === false) return glFormat;
  13305. if (internalFormatName !== null) {
  13306. if (_gl[internalFormatName] !== undefined) return _gl[internalFormatName];
  13307. console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'');
  13308. }
  13309. var internalFormat = glFormat;
  13310. if (glFormat === 6403) {
  13311. if (glType === 5126) internalFormat = 33326;
  13312. if (glType === 5131) internalFormat = 33325;
  13313. if (glType === 5121) internalFormat = 33321;
  13314. }
  13315. if (glFormat === 6407) {
  13316. if (glType === 5126) internalFormat = 34837;
  13317. if (glType === 5131) internalFormat = 34843;
  13318. if (glType === 5121) internalFormat = 32849;
  13319. }
  13320. if (glFormat === 6408) {
  13321. if (glType === 5126) internalFormat = 34836;
  13322. if (glType === 5131) internalFormat = 34842;
  13323. if (glType === 5121) internalFormat = 32856;
  13324. }
  13325. if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 34842 || internalFormat === 34836) {
  13326. extensions.get('EXT_color_buffer_float');
  13327. }
  13328. return internalFormat;
  13329. } // Fallback filters for non-power-of-2 textures
  13330. function filterFallback(f) {
  13331. if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) {
  13332. return 9728;
  13333. }
  13334. return 9729;
  13335. } //
  13336. function onTextureDispose(event) {
  13337. var texture = event.target;
  13338. texture.removeEventListener('dispose', onTextureDispose);
  13339. deallocateTexture(texture);
  13340. if (texture.isVideoTexture) {
  13341. _videoTextures.delete(texture);
  13342. }
  13343. info.memory.textures--;
  13344. }
  13345. function onRenderTargetDispose(event) {
  13346. var renderTarget = event.target;
  13347. renderTarget.removeEventListener('dispose', onRenderTargetDispose);
  13348. deallocateRenderTarget(renderTarget);
  13349. info.memory.textures--;
  13350. } //
  13351. function deallocateTexture(texture) {
  13352. var textureProperties = properties.get(texture);
  13353. if (textureProperties.__webglInit === undefined) return;
  13354. _gl.deleteTexture(textureProperties.__webglTexture);
  13355. properties.remove(texture);
  13356. }
  13357. function deallocateRenderTarget(renderTarget) {
  13358. var renderTargetProperties = properties.get(renderTarget);
  13359. var textureProperties = properties.get(renderTarget.texture);
  13360. if (!renderTarget) return;
  13361. if (textureProperties.__webglTexture !== undefined) {
  13362. _gl.deleteTexture(textureProperties.__webglTexture);
  13363. }
  13364. if (renderTarget.depthTexture) {
  13365. renderTarget.depthTexture.dispose();
  13366. }
  13367. if (renderTarget.isWebGLCubeRenderTarget) {
  13368. for (var i = 0; i < 6; i++) {
  13369. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);
  13370. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);
  13371. }
  13372. } else {
  13373. _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);
  13374. if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);
  13375. if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);
  13376. if (renderTargetProperties.__webglColorRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);
  13377. if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);
  13378. }
  13379. properties.remove(renderTarget.texture);
  13380. properties.remove(renderTarget);
  13381. } //
  13382. var textureUnits = 0;
  13383. function resetTextureUnits() {
  13384. textureUnits = 0;
  13385. }
  13386. function allocateTextureUnit() {
  13387. var textureUnit = textureUnits;
  13388. if (textureUnit >= maxTextures) {
  13389. console.warn('THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures);
  13390. }
  13391. textureUnits += 1;
  13392. return textureUnit;
  13393. } //
  13394. function setTexture2D(texture, slot) {
  13395. var textureProperties = properties.get(texture);
  13396. if (texture.isVideoTexture) updateVideoTexture(texture);
  13397. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13398. var image = texture.image;
  13399. if (image === undefined) {
  13400. console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');
  13401. } else if (image.complete === false) {
  13402. console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');
  13403. } else {
  13404. uploadTexture(textureProperties, texture, slot);
  13405. return;
  13406. }
  13407. }
  13408. state.activeTexture(33984 + slot);
  13409. state.bindTexture(3553, textureProperties.__webglTexture);
  13410. }
  13411. function setTexture2DArray(texture, slot) {
  13412. var textureProperties = properties.get(texture);
  13413. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13414. uploadTexture(textureProperties, texture, slot);
  13415. return;
  13416. }
  13417. state.activeTexture(33984 + slot);
  13418. state.bindTexture(35866, textureProperties.__webglTexture);
  13419. }
  13420. function setTexture3D(texture, slot) {
  13421. var textureProperties = properties.get(texture);
  13422. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13423. uploadTexture(textureProperties, texture, slot);
  13424. return;
  13425. }
  13426. state.activeTexture(33984 + slot);
  13427. state.bindTexture(32879, textureProperties.__webglTexture);
  13428. }
  13429. function setTextureCube(texture, slot) {
  13430. var textureProperties = properties.get(texture);
  13431. if (texture.version > 0 && textureProperties.__version !== texture.version) {
  13432. uploadCubeTexture(textureProperties, texture, slot);
  13433. return;
  13434. }
  13435. state.activeTexture(33984 + slot);
  13436. state.bindTexture(34067, textureProperties.__webglTexture);
  13437. }
  13438. var wrappingToGL = (_wrappingToGL = {}, _wrappingToGL[RepeatWrapping] = 10497, _wrappingToGL[ClampToEdgeWrapping] = 33071, _wrappingToGL[MirroredRepeatWrapping] = 33648, _wrappingToGL);
  13439. var filterToGL = (_filterToGL = {}, _filterToGL[NearestFilter] = 9728, _filterToGL[NearestMipmapNearestFilter] = 9984, _filterToGL[NearestMipmapLinearFilter] = 9986, _filterToGL[LinearFilter] = 9729, _filterToGL[LinearMipmapNearestFilter] = 9985, _filterToGL[LinearMipmapLinearFilter] = 9987, _filterToGL);
  13440. function setTextureParameters(textureType, texture, supportsMips) {
  13441. if (supportsMips) {
  13442. _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]);
  13443. _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]);
  13444. if (textureType === 32879 || textureType === 35866) {
  13445. _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]);
  13446. }
  13447. _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]);
  13448. _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]);
  13449. } else {
  13450. _gl.texParameteri(textureType, 10242, 33071);
  13451. _gl.texParameteri(textureType, 10243, 33071);
  13452. if (textureType === 32879 || textureType === 35866) {
  13453. _gl.texParameteri(textureType, 32882, 33071);
  13454. }
  13455. if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) {
  13456. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');
  13457. }
  13458. _gl.texParameteri(textureType, 10240, filterFallback(texture.magFilter));
  13459. _gl.texParameteri(textureType, 10241, filterFallback(texture.minFilter));
  13460. if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) {
  13461. console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');
  13462. }
  13463. }
  13464. var extension = extensions.get('EXT_texture_filter_anisotropic');
  13465. if (extension) {
  13466. if (texture.type === FloatType && extensions.get('OES_texture_float_linear') === null) return;
  13467. if (texture.type === HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear')) === null) return;
  13468. if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) {
  13469. _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy()));
  13470. properties.get(texture).__currentAnisotropy = texture.anisotropy;
  13471. }
  13472. }
  13473. }
  13474. function initTexture(textureProperties, texture) {
  13475. if (textureProperties.__webglInit === undefined) {
  13476. textureProperties.__webglInit = true;
  13477. texture.addEventListener('dispose', onTextureDispose);
  13478. textureProperties.__webglTexture = _gl.createTexture();
  13479. info.memory.textures++;
  13480. }
  13481. }
  13482. function uploadTexture(textureProperties, texture, slot) {
  13483. var textureType = 3553;
  13484. if (texture.isDataTexture2DArray) textureType = 35866;
  13485. if (texture.isDataTexture3D) textureType = 32879;
  13486. initTexture(textureProperties, texture);
  13487. state.activeTexture(33984 + slot);
  13488. state.bindTexture(textureType, textureProperties.__webglTexture);
  13489. _gl.pixelStorei(37440, texture.flipY);
  13490. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13491. _gl.pixelStorei(3317, texture.unpackAlignment);
  13492. var needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo(texture.image) === false;
  13493. var image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize);
  13494. var supportsMips = isPowerOfTwo(image) || isWebGL2,
  13495. glFormat = utils.convert(texture.format);
  13496. var glType = utils.convert(texture.type),
  13497. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13498. setTextureParameters(textureType, texture, supportsMips);
  13499. var mipmap;
  13500. var mipmaps = texture.mipmaps;
  13501. if (texture.isDepthTexture) {
  13502. // populate depth texture with dummy data
  13503. glInternalFormat = 6402;
  13504. if (isWebGL2) {
  13505. if (texture.type === FloatType) {
  13506. glInternalFormat = 36012;
  13507. } else if (texture.type === UnsignedIntType) {
  13508. glInternalFormat = 33190;
  13509. } else if (texture.type === UnsignedInt248Type) {
  13510. glInternalFormat = 35056;
  13511. } else {
  13512. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  13513. }
  13514. } else {
  13515. if (texture.type === FloatType) {
  13516. console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');
  13517. }
  13518. } // validation checks for WebGL 1
  13519. if (texture.format === DepthFormat && glInternalFormat === 6402) {
  13520. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13521. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  13522. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13523. if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) {
  13524. console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');
  13525. texture.type = UnsignedShortType;
  13526. glType = utils.convert(texture.type);
  13527. }
  13528. }
  13529. if (texture.format === DepthStencilFormat && glInternalFormat === 6402) {
  13530. // Depth stencil textures need the DEPTH_STENCIL internal format
  13531. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13532. glInternalFormat = 34041; // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  13533. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  13534. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  13535. if (texture.type !== UnsignedInt248Type) {
  13536. console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');
  13537. texture.type = UnsignedInt248Type;
  13538. glType = utils.convert(texture.type);
  13539. }
  13540. } //
  13541. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null);
  13542. } else if (texture.isDataTexture) {
  13543. // use manually created mipmaps if available
  13544. // if there are no manual mipmaps
  13545. // set 0 level mipmap and then use GL to generate other mipmap levels
  13546. if (mipmaps.length > 0 && supportsMips) {
  13547. for (var i = 0, il = mipmaps.length; i < il; i++) {
  13548. mipmap = mipmaps[i];
  13549. state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13550. }
  13551. texture.generateMipmaps = false;
  13552. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13553. } else {
  13554. state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data);
  13555. textureProperties.__maxMipLevel = 0;
  13556. }
  13557. } else if (texture.isCompressedTexture) {
  13558. for (var _i = 0, _il = mipmaps.length; _i < _il; _i++) {
  13559. mipmap = mipmaps[_i];
  13560. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13561. if (glFormat !== null) {
  13562. state.compressedTexImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13563. } else {
  13564. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');
  13565. }
  13566. } else {
  13567. state.texImage2D(3553, _i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13568. }
  13569. }
  13570. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13571. } else if (texture.isDataTexture2DArray) {
  13572. state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13573. textureProperties.__maxMipLevel = 0;
  13574. } else if (texture.isDataTexture3D) {
  13575. state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data);
  13576. textureProperties.__maxMipLevel = 0;
  13577. } else {
  13578. // regular Texture (image, video, canvas)
  13579. // use manually created mipmaps if available
  13580. // if there are no manual mipmaps
  13581. // set 0 level mipmap and then use GL to generate other mipmap levels
  13582. if (mipmaps.length > 0 && supportsMips) {
  13583. for (var _i2 = 0, _il2 = mipmaps.length; _i2 < _il2; _i2++) {
  13584. mipmap = mipmaps[_i2];
  13585. state.texImage2D(3553, _i2, glInternalFormat, glFormat, glType, mipmap);
  13586. }
  13587. texture.generateMipmaps = false;
  13588. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13589. } else {
  13590. state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image);
  13591. textureProperties.__maxMipLevel = 0;
  13592. }
  13593. }
  13594. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13595. generateMipmap(textureType, texture, image.width, image.height);
  13596. }
  13597. textureProperties.__version = texture.version;
  13598. if (texture.onUpdate) texture.onUpdate(texture);
  13599. }
  13600. function uploadCubeTexture(textureProperties, texture, slot) {
  13601. if (texture.image.length !== 6) return;
  13602. initTexture(textureProperties, texture);
  13603. state.activeTexture(33984 + slot);
  13604. state.bindTexture(34067, textureProperties.__webglTexture);
  13605. _gl.pixelStorei(37440, texture.flipY);
  13606. _gl.pixelStorei(37441, texture.premultiplyAlpha);
  13607. _gl.pixelStorei(3317, texture.unpackAlignment);
  13608. var isCompressed = texture && (texture.isCompressedTexture || texture.image[0].isCompressedTexture);
  13609. var isDataTexture = texture.image[0] && texture.image[0].isDataTexture;
  13610. var cubeImage = [];
  13611. for (var i = 0; i < 6; i++) {
  13612. if (!isCompressed && !isDataTexture) {
  13613. cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize);
  13614. } else {
  13615. cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i];
  13616. }
  13617. }
  13618. var image = cubeImage[0],
  13619. supportsMips = isPowerOfTwo(image) || isWebGL2,
  13620. glFormat = utils.convert(texture.format),
  13621. glType = utils.convert(texture.type),
  13622. glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType);
  13623. setTextureParameters(34067, texture, supportsMips);
  13624. var mipmaps;
  13625. if (isCompressed) {
  13626. for (var _i3 = 0; _i3 < 6; _i3++) {
  13627. mipmaps = cubeImage[_i3].mipmaps;
  13628. for (var j = 0; j < mipmaps.length; j++) {
  13629. var mipmap = mipmaps[j];
  13630. if (texture.format !== RGBAFormat && texture.format !== RGBFormat) {
  13631. if (glFormat !== null) {
  13632. state.compressedTexImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data);
  13633. } else {
  13634. console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');
  13635. }
  13636. } else {
  13637. state.texImage2D(34069 + _i3, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data);
  13638. }
  13639. }
  13640. }
  13641. textureProperties.__maxMipLevel = mipmaps.length - 1;
  13642. } else {
  13643. mipmaps = texture.mipmaps;
  13644. for (var _i4 = 0; _i4 < 6; _i4++) {
  13645. if (isDataTexture) {
  13646. state.texImage2D(34069 + _i4, 0, glInternalFormat, cubeImage[_i4].width, cubeImage[_i4].height, 0, glFormat, glType, cubeImage[_i4].data);
  13647. for (var _j = 0; _j < mipmaps.length; _j++) {
  13648. var _mipmap = mipmaps[_j];
  13649. var mipmapImage = _mipmap.image[_i4].image;
  13650. state.texImage2D(34069 + _i4, _j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data);
  13651. }
  13652. } else {
  13653. state.texImage2D(34069 + _i4, 0, glInternalFormat, glFormat, glType, cubeImage[_i4]);
  13654. for (var _j2 = 0; _j2 < mipmaps.length; _j2++) {
  13655. var _mipmap2 = mipmaps[_j2];
  13656. state.texImage2D(34069 + _i4, _j2 + 1, glInternalFormat, glFormat, glType, _mipmap2.image[_i4]);
  13657. }
  13658. }
  13659. }
  13660. textureProperties.__maxMipLevel = mipmaps.length;
  13661. }
  13662. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13663. // We assume images for cube map have the same size.
  13664. generateMipmap(34067, texture, image.width, image.height);
  13665. }
  13666. textureProperties.__version = texture.version;
  13667. if (texture.onUpdate) texture.onUpdate(texture);
  13668. } // Render targets
  13669. // Setup storage for target texture and bind it to correct framebuffer
  13670. function setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget) {
  13671. var glFormat = utils.convert(renderTarget.texture.format);
  13672. var glType = utils.convert(renderTarget.texture.type);
  13673. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13674. state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null);
  13675. _gl.bindFramebuffer(36160, framebuffer);
  13676. _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(renderTarget.texture).__webglTexture, 0);
  13677. _gl.bindFramebuffer(36160, null);
  13678. } // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  13679. function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) {
  13680. _gl.bindRenderbuffer(36161, renderbuffer);
  13681. if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) {
  13682. var glInternalFormat = 33189;
  13683. if (isMultisample) {
  13684. var depthTexture = renderTarget.depthTexture;
  13685. if (depthTexture && depthTexture.isDepthTexture) {
  13686. if (depthTexture.type === FloatType) {
  13687. glInternalFormat = 36012;
  13688. } else if (depthTexture.type === UnsignedIntType) {
  13689. glInternalFormat = 33190;
  13690. }
  13691. }
  13692. var samples = getRenderTargetSamples(renderTarget);
  13693. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13694. } else {
  13695. _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height);
  13696. }
  13697. _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer);
  13698. } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) {
  13699. if (isMultisample) {
  13700. var _samples = getRenderTargetSamples(renderTarget);
  13701. _gl.renderbufferStorageMultisample(36161, _samples, 35056, renderTarget.width, renderTarget.height);
  13702. } else {
  13703. _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height);
  13704. }
  13705. _gl.framebufferRenderbuffer(36160, 33306, 36161, renderbuffer);
  13706. } else {
  13707. var glFormat = utils.convert(renderTarget.texture.format);
  13708. var glType = utils.convert(renderTarget.texture.type);
  13709. var _glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13710. if (isMultisample) {
  13711. var _samples2 = getRenderTargetSamples(renderTarget);
  13712. _gl.renderbufferStorageMultisample(36161, _samples2, _glInternalFormat, renderTarget.width, renderTarget.height);
  13713. } else {
  13714. _gl.renderbufferStorage(36161, _glInternalFormat, renderTarget.width, renderTarget.height);
  13715. }
  13716. }
  13717. _gl.bindRenderbuffer(36161, null);
  13718. } // Setup resources for a Depth Texture for a FBO (needs an extension)
  13719. function setupDepthTexture(framebuffer, renderTarget) {
  13720. var isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget;
  13721. if (isCube) throw new Error('Depth Texture with cube render targets is not supported');
  13722. _gl.bindFramebuffer(36160, framebuffer);
  13723. if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) {
  13724. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  13725. } // upload an empty depth texture with framebuffer size
  13726. if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) {
  13727. renderTarget.depthTexture.image.width = renderTarget.width;
  13728. renderTarget.depthTexture.image.height = renderTarget.height;
  13729. renderTarget.depthTexture.needsUpdate = true;
  13730. }
  13731. setTexture2D(renderTarget.depthTexture, 0);
  13732. var webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture;
  13733. if (renderTarget.depthTexture.format === DepthFormat) {
  13734. _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0);
  13735. } else if (renderTarget.depthTexture.format === DepthStencilFormat) {
  13736. _gl.framebufferTexture2D(36160, 33306, 3553, webglDepthTexture, 0);
  13737. } else {
  13738. throw new Error('Unknown depthTexture format');
  13739. }
  13740. } // Setup GL resources for a non-texture depth buffer
  13741. function setupDepthRenderbuffer(renderTarget) {
  13742. var renderTargetProperties = properties.get(renderTarget);
  13743. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13744. if (renderTarget.depthTexture) {
  13745. if (isCube) throw new Error('target.depthTexture not supported in Cube render targets');
  13746. setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget);
  13747. } else {
  13748. if (isCube) {
  13749. renderTargetProperties.__webglDepthbuffer = [];
  13750. for (var i = 0; i < 6; i++) {
  13751. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer[i]);
  13752. renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer();
  13753. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false);
  13754. }
  13755. } else {
  13756. _gl.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer);
  13757. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13758. setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false);
  13759. }
  13760. }
  13761. _gl.bindFramebuffer(36160, null);
  13762. } // Set up GL resources for the render target
  13763. function setupRenderTarget(renderTarget) {
  13764. var renderTargetProperties = properties.get(renderTarget);
  13765. var textureProperties = properties.get(renderTarget.texture);
  13766. renderTarget.addEventListener('dispose', onRenderTargetDispose);
  13767. textureProperties.__webglTexture = _gl.createTexture();
  13768. info.memory.textures++;
  13769. var isCube = renderTarget.isWebGLCubeRenderTarget === true;
  13770. var isMultisample = renderTarget.isWebGLMultisampleRenderTarget === true;
  13771. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2; // Handles WebGL2 RGBFormat fallback - #18858
  13772. if (isWebGL2 && renderTarget.texture.format === RGBFormat && (renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType)) {
  13773. renderTarget.texture.format = RGBAFormat;
  13774. console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');
  13775. } // Setup framebuffer
  13776. if (isCube) {
  13777. renderTargetProperties.__webglFramebuffer = [];
  13778. for (var i = 0; i < 6; i++) {
  13779. renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer();
  13780. }
  13781. } else {
  13782. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13783. if (isMultisample) {
  13784. if (isWebGL2) {
  13785. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13786. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13787. _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer);
  13788. var glFormat = utils.convert(renderTarget.texture.format);
  13789. var glType = utils.convert(renderTarget.texture.type);
  13790. var glInternalFormat = getInternalFormat(renderTarget.texture.internalFormat, glFormat, glType);
  13791. var samples = getRenderTargetSamples(renderTarget);
  13792. _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height);
  13793. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer);
  13794. _gl.framebufferRenderbuffer(36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer);
  13795. _gl.bindRenderbuffer(36161, null);
  13796. if (renderTarget.depthBuffer) {
  13797. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13798. setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true);
  13799. }
  13800. _gl.bindFramebuffer(36160, null);
  13801. } else {
  13802. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13803. }
  13804. }
  13805. } // Setup color buffer
  13806. if (isCube) {
  13807. state.bindTexture(34067, textureProperties.__webglTexture);
  13808. setTextureParameters(34067, renderTarget.texture, supportsMips);
  13809. for (var _i5 = 0; _i5 < 6; _i5++) {
  13810. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[_i5], renderTarget, 36064, 34069 + _i5);
  13811. }
  13812. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13813. generateMipmap(34067, renderTarget.texture, renderTarget.width, renderTarget.height);
  13814. }
  13815. state.bindTexture(34067, null);
  13816. } else {
  13817. state.bindTexture(3553, textureProperties.__webglTexture);
  13818. setTextureParameters(3553, renderTarget.texture, supportsMips);
  13819. setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553);
  13820. if (textureNeedsGenerateMipmaps(renderTarget.texture, supportsMips)) {
  13821. generateMipmap(3553, renderTarget.texture, renderTarget.width, renderTarget.height);
  13822. }
  13823. state.bindTexture(3553, null);
  13824. } // Setup depth and stencil buffers
  13825. if (renderTarget.depthBuffer) {
  13826. setupDepthRenderbuffer(renderTarget);
  13827. }
  13828. }
  13829. function updateRenderTargetMipmap(renderTarget) {
  13830. var texture = renderTarget.texture;
  13831. var supportsMips = isPowerOfTwo(renderTarget) || isWebGL2;
  13832. if (textureNeedsGenerateMipmaps(texture, supportsMips)) {
  13833. var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  13834. var webglTexture = properties.get(texture).__webglTexture;
  13835. state.bindTexture(target, webglTexture);
  13836. generateMipmap(target, texture, renderTarget.width, renderTarget.height);
  13837. state.bindTexture(target, null);
  13838. }
  13839. }
  13840. function updateMultisampleRenderTarget(renderTarget) {
  13841. if (renderTarget.isWebGLMultisampleRenderTarget) {
  13842. if (isWebGL2) {
  13843. var renderTargetProperties = properties.get(renderTarget);
  13844. _gl.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer);
  13845. _gl.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer);
  13846. var width = renderTarget.width;
  13847. var height = renderTarget.height;
  13848. var mask = 16384;
  13849. if (renderTarget.depthBuffer) mask |= 256;
  13850. if (renderTarget.stencilBuffer) mask |= 1024;
  13851. _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728);
  13852. _gl.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); // see #18905
  13853. } else {
  13854. console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');
  13855. }
  13856. }
  13857. }
  13858. function getRenderTargetSamples(renderTarget) {
  13859. return isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ? Math.min(maxSamples, renderTarget.samples) : 0;
  13860. }
  13861. function updateVideoTexture(texture) {
  13862. var frame = info.render.frame; // Check the last frame we updated the VideoTexture
  13863. if (_videoTextures.get(texture) !== frame) {
  13864. _videoTextures.set(texture, frame);
  13865. texture.update();
  13866. }
  13867. } // backwards compatibility
  13868. var warnedTexture2D = false;
  13869. var warnedTextureCube = false;
  13870. function safeSetTexture2D(texture, slot) {
  13871. if (texture && texture.isWebGLRenderTarget) {
  13872. if (warnedTexture2D === false) {
  13873. console.warn('THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.');
  13874. warnedTexture2D = true;
  13875. }
  13876. texture = texture.texture;
  13877. }
  13878. setTexture2D(texture, slot);
  13879. }
  13880. function safeSetTextureCube(texture, slot) {
  13881. if (texture && texture.isWebGLCubeRenderTarget) {
  13882. if (warnedTextureCube === false) {
  13883. console.warn('THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.');
  13884. warnedTextureCube = true;
  13885. }
  13886. texture = texture.texture;
  13887. }
  13888. setTextureCube(texture, slot);
  13889. } //
  13890. this.allocateTextureUnit = allocateTextureUnit;
  13891. this.resetTextureUnits = resetTextureUnits;
  13892. this.setTexture2D = setTexture2D;
  13893. this.setTexture2DArray = setTexture2DArray;
  13894. this.setTexture3D = setTexture3D;
  13895. this.setTextureCube = setTextureCube;
  13896. this.setupRenderTarget = setupRenderTarget;
  13897. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13898. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13899. this.safeSetTexture2D = safeSetTexture2D;
  13900. this.safeSetTextureCube = safeSetTextureCube;
  13901. }
  13902. function WebGLUtils(gl, extensions, capabilities) {
  13903. var isWebGL2 = capabilities.isWebGL2;
  13904. function convert(p) {
  13905. var extension;
  13906. if (p === UnsignedByteType) return 5121;
  13907. if (p === UnsignedShort4444Type) return 32819;
  13908. if (p === UnsignedShort5551Type) return 32820;
  13909. if (p === UnsignedShort565Type) return 33635;
  13910. if (p === ByteType) return 5120;
  13911. if (p === ShortType) return 5122;
  13912. if (p === UnsignedShortType) return 5123;
  13913. if (p === IntType) return 5124;
  13914. if (p === UnsignedIntType) return 5125;
  13915. if (p === FloatType) return 5126;
  13916. if (p === HalfFloatType) {
  13917. if (isWebGL2) return 5131;
  13918. extension = extensions.get('OES_texture_half_float');
  13919. if (extension !== null) {
  13920. return extension.HALF_FLOAT_OES;
  13921. } else {
  13922. return null;
  13923. }
  13924. }
  13925. if (p === AlphaFormat) return 6406;
  13926. if (p === RGBFormat) return 6407;
  13927. if (p === RGBAFormat) return 6408;
  13928. if (p === LuminanceFormat) return 6409;
  13929. if (p === LuminanceAlphaFormat) return 6410;
  13930. if (p === DepthFormat) return 6402;
  13931. if (p === DepthStencilFormat) return 34041;
  13932. if (p === RedFormat) return 6403; // WebGL2 formats.
  13933. if (p === RedIntegerFormat) return 36244;
  13934. if (p === RGFormat) return 33319;
  13935. if (p === RGIntegerFormat) return 33320;
  13936. if (p === RGBIntegerFormat) return 36248;
  13937. if (p === RGBAIntegerFormat) return 36249;
  13938. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  13939. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  13940. if (extension !== null) {
  13941. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13942. if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13943. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13944. if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13945. } else {
  13946. return null;
  13947. }
  13948. }
  13949. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  13950. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  13951. if (extension !== null) {
  13952. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13953. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13954. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13955. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13956. } else {
  13957. return null;
  13958. }
  13959. }
  13960. if (p === RGB_ETC1_Format) {
  13961. extension = extensions.get('WEBGL_compressed_texture_etc1');
  13962. if (extension !== null) {
  13963. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13964. } else {
  13965. return null;
  13966. }
  13967. }
  13968. if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) {
  13969. extension = extensions.get('WEBGL_compressed_texture_etc');
  13970. if (extension !== null) {
  13971. if (p === RGB_ETC2_Format) return extension.COMPRESSED_RGB8_ETC2;
  13972. if (p === RGBA_ETC2_EAC_Format) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13973. }
  13974. }
  13975. 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) {
  13976. extension = extensions.get('WEBGL_compressed_texture_astc');
  13977. if (extension !== null) {
  13978. // TODO Complete?
  13979. return p;
  13980. } else {
  13981. return null;
  13982. }
  13983. }
  13984. if (p === RGBA_BPTC_Format) {
  13985. extension = extensions.get('EXT_texture_compression_bptc');
  13986. if (extension !== null) {
  13987. // TODO Complete?
  13988. return p;
  13989. } else {
  13990. return null;
  13991. }
  13992. }
  13993. if (p === UnsignedInt248Type) {
  13994. if (isWebGL2) return 34042;
  13995. extension = extensions.get('WEBGL_depth_texture');
  13996. if (extension !== null) {
  13997. return extension.UNSIGNED_INT_24_8_WEBGL;
  13998. } else {
  13999. return null;
  14000. }
  14001. }
  14002. }
  14003. return {
  14004. convert: convert
  14005. };
  14006. }
  14007. function ArrayCamera(array) {
  14008. if (array === void 0) {
  14009. array = [];
  14010. }
  14011. PerspectiveCamera.call(this);
  14012. this.cameras = array;
  14013. }
  14014. ArrayCamera.prototype = Object.assign(Object.create(PerspectiveCamera.prototype), {
  14015. constructor: ArrayCamera,
  14016. isArrayCamera: true
  14017. });
  14018. function Group() {
  14019. Object3D.call(this);
  14020. this.type = 'Group';
  14021. }
  14022. Group.prototype = Object.assign(Object.create(Object3D.prototype), {
  14023. constructor: Group,
  14024. isGroup: true
  14025. });
  14026. function WebXRController() {
  14027. this._targetRay = null;
  14028. this._grip = null;
  14029. this._hand = null;
  14030. }
  14031. Object.assign(WebXRController.prototype, {
  14032. constructor: WebXRController,
  14033. getHandSpace: function getHandSpace() {
  14034. if (this._hand === null) {
  14035. this._hand = new Group();
  14036. this._hand.matrixAutoUpdate = false;
  14037. this._hand.visible = false;
  14038. this._hand.joints = {};
  14039. this._hand.inputState = {
  14040. pinching: false
  14041. };
  14042. }
  14043. return this._hand;
  14044. },
  14045. getTargetRaySpace: function getTargetRaySpace() {
  14046. if (this._targetRay === null) {
  14047. this._targetRay = new Group();
  14048. this._targetRay.matrixAutoUpdate = false;
  14049. this._targetRay.visible = false;
  14050. }
  14051. return this._targetRay;
  14052. },
  14053. getGripSpace: function getGripSpace() {
  14054. if (this._grip === null) {
  14055. this._grip = new Group();
  14056. this._grip.matrixAutoUpdate = false;
  14057. this._grip.visible = false;
  14058. }
  14059. return this._grip;
  14060. },
  14061. dispatchEvent: function dispatchEvent(event) {
  14062. if (this._targetRay !== null) {
  14063. this._targetRay.dispatchEvent(event);
  14064. }
  14065. if (this._grip !== null) {
  14066. this._grip.dispatchEvent(event);
  14067. }
  14068. if (this._hand !== null) {
  14069. this._hand.dispatchEvent(event);
  14070. }
  14071. return this;
  14072. },
  14073. disconnect: function disconnect(inputSource) {
  14074. this.dispatchEvent({
  14075. type: 'disconnected',
  14076. data: inputSource
  14077. });
  14078. if (this._targetRay !== null) {
  14079. this._targetRay.visible = false;
  14080. }
  14081. if (this._grip !== null) {
  14082. this._grip.visible = false;
  14083. }
  14084. if (this._hand !== null) {
  14085. this._hand.visible = false;
  14086. }
  14087. return this;
  14088. },
  14089. update: function update(inputSource, frame, referenceSpace) {
  14090. var inputPose = null;
  14091. var gripPose = null;
  14092. var handPose = null;
  14093. var targetRay = this._targetRay;
  14094. var grip = this._grip;
  14095. var hand = this._hand;
  14096. if (inputSource && frame.session.visibilityState !== 'visible-blurred') {
  14097. if (hand && inputSource.hand) {
  14098. handPose = true;
  14099. for (var _iterator = _createForOfIteratorHelperLoose(inputSource.hand.values()), _step; !(_step = _iterator()).done;) {
  14100. var inputjoint = _step.value;
  14101. // Update the joints groups with the XRJoint poses
  14102. var jointPose = frame.getJointPose(inputjoint, referenceSpace);
  14103. if (hand.joints[inputjoint.jointName] === undefined) {
  14104. // The transform of this joint will be updated with the joint pose on each frame
  14105. var _joint = new Group();
  14106. _joint.matrixAutoUpdate = false;
  14107. _joint.visible = false;
  14108. hand.joints[inputjoint.jointName] = _joint; // ??
  14109. hand.add(_joint);
  14110. }
  14111. var joint = hand.joints[inputjoint.jointName];
  14112. if (jointPose !== null) {
  14113. joint.matrix.fromArray(jointPose.transform.matrix);
  14114. joint.matrix.decompose(joint.position, joint.rotation, joint.scale);
  14115. joint.jointRadius = jointPose.radius;
  14116. }
  14117. joint.visible = jointPose !== null;
  14118. } // Custom events
  14119. // Check pinchz
  14120. var indexTip = hand.joints['index-finger-tip'];
  14121. var thumbTip = hand.joints['thumb-tip'];
  14122. var distance = indexTip.position.distanceTo(thumbTip.position);
  14123. var distanceToPinch = 0.02;
  14124. var threshold = 0.005;
  14125. if (hand.inputState.pinching && distance > distanceToPinch + threshold) {
  14126. hand.inputState.pinching = false;
  14127. this.dispatchEvent({
  14128. type: 'pinchend',
  14129. handedness: inputSource.handedness,
  14130. target: this
  14131. });
  14132. } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) {
  14133. hand.inputState.pinching = true;
  14134. this.dispatchEvent({
  14135. type: 'pinchstart',
  14136. handedness: inputSource.handedness,
  14137. target: this
  14138. });
  14139. }
  14140. } else {
  14141. if (targetRay !== null) {
  14142. inputPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
  14143. if (inputPose !== null) {
  14144. targetRay.matrix.fromArray(inputPose.transform.matrix);
  14145. targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale);
  14146. }
  14147. }
  14148. if (grip !== null && inputSource.gripSpace) {
  14149. gripPose = frame.getPose(inputSource.gripSpace, referenceSpace);
  14150. if (gripPose !== null) {
  14151. grip.matrix.fromArray(gripPose.transform.matrix);
  14152. grip.matrix.decompose(grip.position, grip.rotation, grip.scale);
  14153. }
  14154. }
  14155. }
  14156. }
  14157. if (targetRay !== null) {
  14158. targetRay.visible = inputPose !== null;
  14159. }
  14160. if (grip !== null) {
  14161. grip.visible = gripPose !== null;
  14162. }
  14163. if (hand !== null) {
  14164. hand.visible = handPose !== null;
  14165. }
  14166. return this;
  14167. }
  14168. });
  14169. function WebXRManager(renderer, gl) {
  14170. var scope = this;
  14171. var session = null;
  14172. var framebufferScaleFactor = 1.0;
  14173. var referenceSpace = null;
  14174. var referenceSpaceType = 'local-floor';
  14175. var pose = null;
  14176. var controllers = [];
  14177. var inputSourcesMap = new Map(); //
  14178. var cameraL = new PerspectiveCamera();
  14179. cameraL.layers.enable(1);
  14180. cameraL.viewport = new Vector4();
  14181. var cameraR = new PerspectiveCamera();
  14182. cameraR.layers.enable(2);
  14183. cameraR.viewport = new Vector4();
  14184. var cameras = [cameraL, cameraR];
  14185. var cameraVR = new ArrayCamera();
  14186. cameraVR.layers.enable(1);
  14187. cameraVR.layers.enable(2);
  14188. var _currentDepthNear = null;
  14189. var _currentDepthFar = null; //
  14190. this.enabled = false;
  14191. this.isPresenting = false;
  14192. this.getController = function (index) {
  14193. var controller = controllers[index];
  14194. if (controller === undefined) {
  14195. controller = new WebXRController();
  14196. controllers[index] = controller;
  14197. }
  14198. return controller.getTargetRaySpace();
  14199. };
  14200. this.getControllerGrip = function (index) {
  14201. var controller = controllers[index];
  14202. if (controller === undefined) {
  14203. controller = new WebXRController();
  14204. controllers[index] = controller;
  14205. }
  14206. return controller.getGripSpace();
  14207. };
  14208. this.getHand = function (index) {
  14209. var controller = controllers[index];
  14210. if (controller === undefined) {
  14211. controller = new WebXRController();
  14212. controllers[index] = controller;
  14213. }
  14214. return controller.getHandSpace();
  14215. }; //
  14216. function onSessionEvent(event) {
  14217. var controller = inputSourcesMap.get(event.inputSource);
  14218. if (controller) {
  14219. controller.dispatchEvent({
  14220. type: event.type,
  14221. data: event.inputSource
  14222. });
  14223. }
  14224. }
  14225. function onSessionEnd() {
  14226. inputSourcesMap.forEach(function (controller, inputSource) {
  14227. controller.disconnect(inputSource);
  14228. });
  14229. inputSourcesMap.clear(); //
  14230. renderer.setFramebuffer(null);
  14231. renderer.setRenderTarget(renderer.getRenderTarget()); // Hack #15830
  14232. animation.stop();
  14233. scope.isPresenting = false;
  14234. scope.dispatchEvent({
  14235. type: 'sessionend'
  14236. });
  14237. }
  14238. this.setFramebufferScaleFactor = function (value) {
  14239. framebufferScaleFactor = value;
  14240. if (scope.isPresenting === true) {
  14241. console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');
  14242. }
  14243. };
  14244. this.setReferenceSpaceType = function (value) {
  14245. referenceSpaceType = value;
  14246. if (scope.isPresenting === true) {
  14247. console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');
  14248. }
  14249. };
  14250. this.getReferenceSpace = function () {
  14251. return referenceSpace;
  14252. };
  14253. this.getSession = function () {
  14254. return session;
  14255. };
  14256. this.setSession = /*#__PURE__*/function () {
  14257. var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(value) {
  14258. var attributes, layerInit, baseLayer;
  14259. return regeneratorRuntime.wrap(function _callee$(_context) {
  14260. while (1) {
  14261. switch (_context.prev = _context.next) {
  14262. case 0:
  14263. session = value;
  14264. if (!(session !== null)) {
  14265. _context.next = 24;
  14266. break;
  14267. }
  14268. session.addEventListener('select', onSessionEvent);
  14269. session.addEventListener('selectstart', onSessionEvent);
  14270. session.addEventListener('selectend', onSessionEvent);
  14271. session.addEventListener('squeeze', onSessionEvent);
  14272. session.addEventListener('squeezestart', onSessionEvent);
  14273. session.addEventListener('squeezeend', onSessionEvent);
  14274. session.addEventListener('end', onSessionEnd);
  14275. session.addEventListener('inputsourceschange', onInputSourcesChange);
  14276. attributes = gl.getContextAttributes();
  14277. if (!(attributes.xrCompatible !== true)) {
  14278. _context.next = 14;
  14279. break;
  14280. }
  14281. _context.next = 14;
  14282. return gl.makeXRCompatible();
  14283. case 14:
  14284. layerInit = {
  14285. antialias: attributes.antialias,
  14286. alpha: attributes.alpha,
  14287. depth: attributes.depth,
  14288. stencil: attributes.stencil,
  14289. framebufferScaleFactor: framebufferScaleFactor
  14290. }; // eslint-disable-next-line no-undef
  14291. baseLayer = new XRWebGLLayer(session, gl, layerInit);
  14292. session.updateRenderState({
  14293. baseLayer: baseLayer
  14294. });
  14295. _context.next = 19;
  14296. return session.requestReferenceSpace(referenceSpaceType);
  14297. case 19:
  14298. referenceSpace = _context.sent;
  14299. animation.setContext(session);
  14300. animation.start();
  14301. scope.isPresenting = true;
  14302. scope.dispatchEvent({
  14303. type: 'sessionstart'
  14304. });
  14305. case 24:
  14306. case "end":
  14307. return _context.stop();
  14308. }
  14309. }
  14310. }, _callee);
  14311. }));
  14312. return function (_x) {
  14313. return _ref.apply(this, arguments);
  14314. };
  14315. }();
  14316. function onInputSourcesChange(event) {
  14317. var inputSources = session.inputSources; // Assign inputSources to available controllers
  14318. for (var i = 0; i < controllers.length; i++) {
  14319. inputSourcesMap.set(inputSources[i], controllers[i]);
  14320. } // Notify disconnected
  14321. for (var _i = 0; _i < event.removed.length; _i++) {
  14322. var inputSource = event.removed[_i];
  14323. var controller = inputSourcesMap.get(inputSource);
  14324. if (controller) {
  14325. controller.dispatchEvent({
  14326. type: 'disconnected',
  14327. data: inputSource
  14328. });
  14329. inputSourcesMap.delete(inputSource);
  14330. }
  14331. } // Notify connected
  14332. for (var _i2 = 0; _i2 < event.added.length; _i2++) {
  14333. var _inputSource = event.added[_i2];
  14334. var _controller = inputSourcesMap.get(_inputSource);
  14335. if (_controller) {
  14336. _controller.dispatchEvent({
  14337. type: 'connected',
  14338. data: _inputSource
  14339. });
  14340. }
  14341. }
  14342. } //
  14343. var cameraLPos = new Vector3();
  14344. var cameraRPos = new Vector3();
  14345. /**
  14346. * Assumes 2 cameras that are parallel and share an X-axis, and that
  14347. * the cameras' projection and world matrices have already been set.
  14348. * And that near and far planes are identical for both cameras.
  14349. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  14350. */
  14351. function setProjectionFromUnion(camera, cameraL, cameraR) {
  14352. cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);
  14353. cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);
  14354. var ipd = cameraLPos.distanceTo(cameraRPos);
  14355. var projL = cameraL.projectionMatrix.elements;
  14356. var projR = cameraR.projectionMatrix.elements; // VR systems will have identical far and near planes, and
  14357. // most likely identical top and bottom frustum extents.
  14358. // Use the left camera for these values.
  14359. var near = projL[14] / (projL[10] - 1);
  14360. var far = projL[14] / (projL[10] + 1);
  14361. var topFov = (projL[9] + 1) / projL[5];
  14362. var bottomFov = (projL[9] - 1) / projL[5];
  14363. var leftFov = (projL[8] - 1) / projL[0];
  14364. var rightFov = (projR[8] + 1) / projR[0];
  14365. var left = near * leftFov;
  14366. var right = near * rightFov; // Calculate the new camera's position offset from the
  14367. // left camera. xOffset should be roughly half `ipd`.
  14368. var zOffset = ipd / (-leftFov + rightFov);
  14369. var xOffset = zOffset * -leftFov; // TODO: Better way to apply this offset?
  14370. cameraL.matrixWorld.decompose(camera.position, camera.quaternion, camera.scale);
  14371. camera.translateX(xOffset);
  14372. camera.translateZ(zOffset);
  14373. camera.matrixWorld.compose(camera.position, camera.quaternion, camera.scale);
  14374. camera.matrixWorldInverse.copy(camera.matrixWorld).invert(); // Find the union of the frustum values of the cameras and scale
  14375. // the values so that the near plane's position does not change in world space,
  14376. // although must now be relative to the new union camera.
  14377. var near2 = near + zOffset;
  14378. var far2 = far + zOffset;
  14379. var left2 = left - xOffset;
  14380. var right2 = right + (ipd - xOffset);
  14381. var top2 = topFov * far / far2 * near2;
  14382. var bottom2 = bottomFov * far / far2 * near2;
  14383. camera.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2);
  14384. }
  14385. function updateCamera(camera, parent) {
  14386. if (parent === null) {
  14387. camera.matrixWorld.copy(camera.matrix);
  14388. } else {
  14389. camera.matrixWorld.multiplyMatrices(parent.matrixWorld, camera.matrix);
  14390. }
  14391. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  14392. }
  14393. this.getCamera = function (camera) {
  14394. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  14395. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  14396. if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) {
  14397. // Note that the new renderState won't apply until the next frame. See #18320
  14398. session.updateRenderState({
  14399. depthNear: cameraVR.near,
  14400. depthFar: cameraVR.far
  14401. });
  14402. _currentDepthNear = cameraVR.near;
  14403. _currentDepthFar = cameraVR.far;
  14404. }
  14405. var parent = camera.parent;
  14406. var cameras = cameraVR.cameras;
  14407. updateCamera(cameraVR, parent);
  14408. for (var i = 0; i < cameras.length; i++) {
  14409. updateCamera(cameras[i], parent);
  14410. } // update camera and its children
  14411. camera.matrixWorld.copy(cameraVR.matrixWorld);
  14412. var children = camera.children;
  14413. for (var _i3 = 0, l = children.length; _i3 < l; _i3++) {
  14414. children[_i3].updateMatrixWorld(true);
  14415. } // update projection matrix for proper view frustum culling
  14416. if (cameras.length === 2) {
  14417. setProjectionFromUnion(cameraVR, cameraL, cameraR);
  14418. } else {
  14419. // assume single camera setup (AR)
  14420. cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);
  14421. }
  14422. return cameraVR;
  14423. }; // Animation Loop
  14424. var onAnimationFrameCallback = null;
  14425. function onAnimationFrame(time, frame) {
  14426. pose = frame.getViewerPose(referenceSpace);
  14427. if (pose !== null) {
  14428. var views = pose.views;
  14429. var baseLayer = session.renderState.baseLayer;
  14430. renderer.setFramebuffer(baseLayer.framebuffer);
  14431. var cameraVRNeedsUpdate = false; // check if it's necessary to rebuild cameraVR's camera list
  14432. if (views.length !== cameraVR.cameras.length) {
  14433. cameraVR.cameras.length = 0;
  14434. cameraVRNeedsUpdate = true;
  14435. }
  14436. for (var i = 0; i < views.length; i++) {
  14437. var view = views[i];
  14438. var viewport = baseLayer.getViewport(view);
  14439. var camera = cameras[i];
  14440. camera.matrix.fromArray(view.transform.matrix);
  14441. camera.projectionMatrix.fromArray(view.projectionMatrix);
  14442. camera.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height);
  14443. if (i === 0) {
  14444. cameraVR.matrix.copy(camera.matrix);
  14445. }
  14446. if (cameraVRNeedsUpdate === true) {
  14447. cameraVR.cameras.push(camera);
  14448. }
  14449. }
  14450. } //
  14451. var inputSources = session.inputSources;
  14452. for (var _i4 = 0; _i4 < controllers.length; _i4++) {
  14453. var controller = controllers[_i4];
  14454. var inputSource = inputSources[_i4];
  14455. controller.update(inputSource, frame, referenceSpace);
  14456. }
  14457. if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame);
  14458. }
  14459. var animation = new WebGLAnimation();
  14460. animation.setAnimationLoop(onAnimationFrame);
  14461. this.setAnimationLoop = function (callback) {
  14462. onAnimationFrameCallback = callback;
  14463. };
  14464. this.dispose = function () {};
  14465. }
  14466. Object.assign(WebXRManager.prototype, EventDispatcher.prototype);
  14467. function WebGLMaterials(properties) {
  14468. function refreshFogUniforms(uniforms, fog) {
  14469. uniforms.fogColor.value.copy(fog.color);
  14470. if (fog.isFog) {
  14471. uniforms.fogNear.value = fog.near;
  14472. uniforms.fogFar.value = fog.far;
  14473. } else if (fog.isFogExp2) {
  14474. uniforms.fogDensity.value = fog.density;
  14475. }
  14476. }
  14477. function refreshMaterialUniforms(uniforms, material, pixelRatio, height) {
  14478. if (material.isMeshBasicMaterial) {
  14479. refreshUniformsCommon(uniforms, material);
  14480. } else if (material.isMeshLambertMaterial) {
  14481. refreshUniformsCommon(uniforms, material);
  14482. refreshUniformsLambert(uniforms, material);
  14483. } else if (material.isMeshToonMaterial) {
  14484. refreshUniformsCommon(uniforms, material);
  14485. refreshUniformsToon(uniforms, material);
  14486. } else if (material.isMeshPhongMaterial) {
  14487. refreshUniformsCommon(uniforms, material);
  14488. refreshUniformsPhong(uniforms, material);
  14489. } else if (material.isMeshStandardMaterial) {
  14490. refreshUniformsCommon(uniforms, material);
  14491. if (material.isMeshPhysicalMaterial) {
  14492. refreshUniformsPhysical(uniforms, material);
  14493. } else {
  14494. refreshUniformsStandard(uniforms, material);
  14495. }
  14496. } else if (material.isMeshMatcapMaterial) {
  14497. refreshUniformsCommon(uniforms, material);
  14498. refreshUniformsMatcap(uniforms, material);
  14499. } else if (material.isMeshDepthMaterial) {
  14500. refreshUniformsCommon(uniforms, material);
  14501. refreshUniformsDepth(uniforms, material);
  14502. } else if (material.isMeshDistanceMaterial) {
  14503. refreshUniformsCommon(uniforms, material);
  14504. refreshUniformsDistance(uniforms, material);
  14505. } else if (material.isMeshNormalMaterial) {
  14506. refreshUniformsCommon(uniforms, material);
  14507. refreshUniformsNormal(uniforms, material);
  14508. } else if (material.isLineBasicMaterial) {
  14509. refreshUniformsLine(uniforms, material);
  14510. if (material.isLineDashedMaterial) {
  14511. refreshUniformsDash(uniforms, material);
  14512. }
  14513. } else if (material.isPointsMaterial) {
  14514. refreshUniformsPoints(uniforms, material, pixelRatio, height);
  14515. } else if (material.isSpriteMaterial) {
  14516. refreshUniformsSprites(uniforms, material);
  14517. } else if (material.isShadowMaterial) {
  14518. uniforms.color.value.copy(material.color);
  14519. uniforms.opacity.value = material.opacity;
  14520. } else if (material.isShaderMaterial) {
  14521. material.uniformsNeedUpdate = false; // #15581
  14522. }
  14523. }
  14524. function refreshUniformsCommon(uniforms, material) {
  14525. uniforms.opacity.value = material.opacity;
  14526. if (material.color) {
  14527. uniforms.diffuse.value.copy(material.color);
  14528. }
  14529. if (material.emissive) {
  14530. uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);
  14531. }
  14532. if (material.map) {
  14533. uniforms.map.value = material.map;
  14534. }
  14535. if (material.alphaMap) {
  14536. uniforms.alphaMap.value = material.alphaMap;
  14537. }
  14538. if (material.specularMap) {
  14539. uniforms.specularMap.value = material.specularMap;
  14540. }
  14541. var envMap = properties.get(material).envMap;
  14542. if (envMap) {
  14543. uniforms.envMap.value = envMap;
  14544. uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap._needsFlipEnvMap ? -1 : 1;
  14545. uniforms.reflectivity.value = material.reflectivity;
  14546. uniforms.refractionRatio.value = material.refractionRatio;
  14547. var maxMipLevel = properties.get(envMap).__maxMipLevel;
  14548. if (maxMipLevel !== undefined) {
  14549. uniforms.maxMipLevel.value = maxMipLevel;
  14550. }
  14551. }
  14552. if (material.lightMap) {
  14553. uniforms.lightMap.value = material.lightMap;
  14554. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14555. }
  14556. if (material.aoMap) {
  14557. uniforms.aoMap.value = material.aoMap;
  14558. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14559. } // uv repeat and offset setting priorities
  14560. // 1. color map
  14561. // 2. specular map
  14562. // 3. displacementMap map
  14563. // 4. normal map
  14564. // 5. bump map
  14565. // 6. roughnessMap map
  14566. // 7. metalnessMap map
  14567. // 8. alphaMap map
  14568. // 9. emissiveMap map
  14569. // 10. clearcoat map
  14570. // 11. clearcoat normal map
  14571. // 12. clearcoat roughnessMap map
  14572. var uvScaleMap;
  14573. if (material.map) {
  14574. uvScaleMap = material.map;
  14575. } else if (material.specularMap) {
  14576. uvScaleMap = material.specularMap;
  14577. } else if (material.displacementMap) {
  14578. uvScaleMap = material.displacementMap;
  14579. } else if (material.normalMap) {
  14580. uvScaleMap = material.normalMap;
  14581. } else if (material.bumpMap) {
  14582. uvScaleMap = material.bumpMap;
  14583. } else if (material.roughnessMap) {
  14584. uvScaleMap = material.roughnessMap;
  14585. } else if (material.metalnessMap) {
  14586. uvScaleMap = material.metalnessMap;
  14587. } else if (material.alphaMap) {
  14588. uvScaleMap = material.alphaMap;
  14589. } else if (material.emissiveMap) {
  14590. uvScaleMap = material.emissiveMap;
  14591. } else if (material.clearcoatMap) {
  14592. uvScaleMap = material.clearcoatMap;
  14593. } else if (material.clearcoatNormalMap) {
  14594. uvScaleMap = material.clearcoatNormalMap;
  14595. } else if (material.clearcoatRoughnessMap) {
  14596. uvScaleMap = material.clearcoatRoughnessMap;
  14597. }
  14598. if (uvScaleMap !== undefined) {
  14599. // backwards compatibility
  14600. if (uvScaleMap.isWebGLRenderTarget) {
  14601. uvScaleMap = uvScaleMap.texture;
  14602. }
  14603. if (uvScaleMap.matrixAutoUpdate === true) {
  14604. uvScaleMap.updateMatrix();
  14605. }
  14606. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14607. } // uv repeat and offset setting priorities for uv2
  14608. // 1. ao map
  14609. // 2. light map
  14610. var uv2ScaleMap;
  14611. if (material.aoMap) {
  14612. uv2ScaleMap = material.aoMap;
  14613. } else if (material.lightMap) {
  14614. uv2ScaleMap = material.lightMap;
  14615. }
  14616. if (uv2ScaleMap !== undefined) {
  14617. // backwards compatibility
  14618. if (uv2ScaleMap.isWebGLRenderTarget) {
  14619. uv2ScaleMap = uv2ScaleMap.texture;
  14620. }
  14621. if (uv2ScaleMap.matrixAutoUpdate === true) {
  14622. uv2ScaleMap.updateMatrix();
  14623. }
  14624. uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);
  14625. }
  14626. }
  14627. function refreshUniformsLine(uniforms, material) {
  14628. uniforms.diffuse.value.copy(material.color);
  14629. uniforms.opacity.value = material.opacity;
  14630. }
  14631. function refreshUniformsDash(uniforms, material) {
  14632. uniforms.dashSize.value = material.dashSize;
  14633. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14634. uniforms.scale.value = material.scale;
  14635. }
  14636. function refreshUniformsPoints(uniforms, material, pixelRatio, height) {
  14637. uniforms.diffuse.value.copy(material.color);
  14638. uniforms.opacity.value = material.opacity;
  14639. uniforms.size.value = material.size * pixelRatio;
  14640. uniforms.scale.value = height * 0.5;
  14641. if (material.map) {
  14642. uniforms.map.value = material.map;
  14643. }
  14644. if (material.alphaMap) {
  14645. uniforms.alphaMap.value = material.alphaMap;
  14646. } // uv repeat and offset setting priorities
  14647. // 1. color map
  14648. // 2. alpha map
  14649. var uvScaleMap;
  14650. if (material.map) {
  14651. uvScaleMap = material.map;
  14652. } else if (material.alphaMap) {
  14653. uvScaleMap = material.alphaMap;
  14654. }
  14655. if (uvScaleMap !== undefined) {
  14656. if (uvScaleMap.matrixAutoUpdate === true) {
  14657. uvScaleMap.updateMatrix();
  14658. }
  14659. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14660. }
  14661. }
  14662. function refreshUniformsSprites(uniforms, material) {
  14663. uniforms.diffuse.value.copy(material.color);
  14664. uniforms.opacity.value = material.opacity;
  14665. uniforms.rotation.value = material.rotation;
  14666. if (material.map) {
  14667. uniforms.map.value = material.map;
  14668. }
  14669. if (material.alphaMap) {
  14670. uniforms.alphaMap.value = material.alphaMap;
  14671. } // uv repeat and offset setting priorities
  14672. // 1. color map
  14673. // 2. alpha map
  14674. var uvScaleMap;
  14675. if (material.map) {
  14676. uvScaleMap = material.map;
  14677. } else if (material.alphaMap) {
  14678. uvScaleMap = material.alphaMap;
  14679. }
  14680. if (uvScaleMap !== undefined) {
  14681. if (uvScaleMap.matrixAutoUpdate === true) {
  14682. uvScaleMap.updateMatrix();
  14683. }
  14684. uniforms.uvTransform.value.copy(uvScaleMap.matrix);
  14685. }
  14686. }
  14687. function refreshUniformsLambert(uniforms, material) {
  14688. if (material.emissiveMap) {
  14689. uniforms.emissiveMap.value = material.emissiveMap;
  14690. }
  14691. }
  14692. function refreshUniformsPhong(uniforms, material) {
  14693. uniforms.specular.value.copy(material.specular);
  14694. uniforms.shininess.value = Math.max(material.shininess, 1e-4); // to prevent pow( 0.0, 0.0 )
  14695. if (material.emissiveMap) {
  14696. uniforms.emissiveMap.value = material.emissiveMap;
  14697. }
  14698. if (material.bumpMap) {
  14699. uniforms.bumpMap.value = material.bumpMap;
  14700. uniforms.bumpScale.value = material.bumpScale;
  14701. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14702. }
  14703. if (material.normalMap) {
  14704. uniforms.normalMap.value = material.normalMap;
  14705. uniforms.normalScale.value.copy(material.normalScale);
  14706. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14707. }
  14708. if (material.displacementMap) {
  14709. uniforms.displacementMap.value = material.displacementMap;
  14710. uniforms.displacementScale.value = material.displacementScale;
  14711. uniforms.displacementBias.value = material.displacementBias;
  14712. }
  14713. }
  14714. function refreshUniformsToon(uniforms, material) {
  14715. if (material.gradientMap) {
  14716. uniforms.gradientMap.value = material.gradientMap;
  14717. }
  14718. if (material.emissiveMap) {
  14719. uniforms.emissiveMap.value = material.emissiveMap;
  14720. }
  14721. if (material.bumpMap) {
  14722. uniforms.bumpMap.value = material.bumpMap;
  14723. uniforms.bumpScale.value = material.bumpScale;
  14724. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14725. }
  14726. if (material.normalMap) {
  14727. uniforms.normalMap.value = material.normalMap;
  14728. uniforms.normalScale.value.copy(material.normalScale);
  14729. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14730. }
  14731. if (material.displacementMap) {
  14732. uniforms.displacementMap.value = material.displacementMap;
  14733. uniforms.displacementScale.value = material.displacementScale;
  14734. uniforms.displacementBias.value = material.displacementBias;
  14735. }
  14736. }
  14737. function refreshUniformsStandard(uniforms, material) {
  14738. uniforms.roughness.value = material.roughness;
  14739. uniforms.metalness.value = material.metalness;
  14740. if (material.roughnessMap) {
  14741. uniforms.roughnessMap.value = material.roughnessMap;
  14742. }
  14743. if (material.metalnessMap) {
  14744. uniforms.metalnessMap.value = material.metalnessMap;
  14745. }
  14746. if (material.emissiveMap) {
  14747. uniforms.emissiveMap.value = material.emissiveMap;
  14748. }
  14749. if (material.bumpMap) {
  14750. uniforms.bumpMap.value = material.bumpMap;
  14751. uniforms.bumpScale.value = material.bumpScale;
  14752. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14753. }
  14754. if (material.normalMap) {
  14755. uniforms.normalMap.value = material.normalMap;
  14756. uniforms.normalScale.value.copy(material.normalScale);
  14757. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14758. }
  14759. if (material.displacementMap) {
  14760. uniforms.displacementMap.value = material.displacementMap;
  14761. uniforms.displacementScale.value = material.displacementScale;
  14762. uniforms.displacementBias.value = material.displacementBias;
  14763. }
  14764. var envMap = properties.get(material).envMap;
  14765. if (envMap) {
  14766. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14767. uniforms.envMapIntensity.value = material.envMapIntensity;
  14768. }
  14769. }
  14770. function refreshUniformsPhysical(uniforms, material) {
  14771. refreshUniformsStandard(uniforms, material);
  14772. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14773. uniforms.clearcoat.value = material.clearcoat;
  14774. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  14775. if (material.sheen) uniforms.sheen.value.copy(material.sheen);
  14776. if (material.clearcoatMap) {
  14777. uniforms.clearcoatMap.value = material.clearcoatMap;
  14778. }
  14779. if (material.clearcoatRoughnessMap) {
  14780. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  14781. }
  14782. if (material.clearcoatNormalMap) {
  14783. uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);
  14784. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  14785. if (material.side === BackSide) {
  14786. uniforms.clearcoatNormalScale.value.negate();
  14787. }
  14788. }
  14789. uniforms.transmission.value = material.transmission;
  14790. if (material.transmissionMap) {
  14791. uniforms.transmissionMap.value = material.transmissionMap;
  14792. }
  14793. }
  14794. function refreshUniformsMatcap(uniforms, material) {
  14795. if (material.matcap) {
  14796. uniforms.matcap.value = material.matcap;
  14797. }
  14798. if (material.bumpMap) {
  14799. uniforms.bumpMap.value = material.bumpMap;
  14800. uniforms.bumpScale.value = material.bumpScale;
  14801. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14802. }
  14803. if (material.normalMap) {
  14804. uniforms.normalMap.value = material.normalMap;
  14805. uniforms.normalScale.value.copy(material.normalScale);
  14806. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14807. }
  14808. if (material.displacementMap) {
  14809. uniforms.displacementMap.value = material.displacementMap;
  14810. uniforms.displacementScale.value = material.displacementScale;
  14811. uniforms.displacementBias.value = material.displacementBias;
  14812. }
  14813. }
  14814. function refreshUniformsDepth(uniforms, material) {
  14815. if (material.displacementMap) {
  14816. uniforms.displacementMap.value = material.displacementMap;
  14817. uniforms.displacementScale.value = material.displacementScale;
  14818. uniforms.displacementBias.value = material.displacementBias;
  14819. }
  14820. }
  14821. function refreshUniformsDistance(uniforms, material) {
  14822. if (material.displacementMap) {
  14823. uniforms.displacementMap.value = material.displacementMap;
  14824. uniforms.displacementScale.value = material.displacementScale;
  14825. uniforms.displacementBias.value = material.displacementBias;
  14826. }
  14827. uniforms.referencePosition.value.copy(material.referencePosition);
  14828. uniforms.nearDistance.value = material.nearDistance;
  14829. uniforms.farDistance.value = material.farDistance;
  14830. }
  14831. function refreshUniformsNormal(uniforms, material) {
  14832. if (material.bumpMap) {
  14833. uniforms.bumpMap.value = material.bumpMap;
  14834. uniforms.bumpScale.value = material.bumpScale;
  14835. if (material.side === BackSide) uniforms.bumpScale.value *= -1;
  14836. }
  14837. if (material.normalMap) {
  14838. uniforms.normalMap.value = material.normalMap;
  14839. uniforms.normalScale.value.copy(material.normalScale);
  14840. if (material.side === BackSide) uniforms.normalScale.value.negate();
  14841. }
  14842. if (material.displacementMap) {
  14843. uniforms.displacementMap.value = material.displacementMap;
  14844. uniforms.displacementScale.value = material.displacementScale;
  14845. uniforms.displacementBias.value = material.displacementBias;
  14846. }
  14847. }
  14848. return {
  14849. refreshFogUniforms: refreshFogUniforms,
  14850. refreshMaterialUniforms: refreshMaterialUniforms
  14851. };
  14852. }
  14853. function createCanvasElement() {
  14854. var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
  14855. canvas.style.display = 'block';
  14856. return canvas;
  14857. }
  14858. function WebGLRenderer(parameters) {
  14859. parameters = parameters || {};
  14860. var _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  14861. _context = parameters.context !== undefined ? parameters.context : null,
  14862. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14863. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14864. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14865. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14866. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14867. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  14868. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  14869. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  14870. var currentRenderList = null;
  14871. var currentRenderState = null; // render() can be called from within a callback triggered by another render.
  14872. // We track this so that the nested render call gets its state isolated from the parent render call.
  14873. var renderStateStack = []; // public properties
  14874. this.domElement = _canvas; // Debug configuration container
  14875. this.debug = {
  14876. /**
  14877. * Enables error checking and reporting when shader programs are being compiled
  14878. * @type {boolean}
  14879. */
  14880. checkShaderErrors: true
  14881. }; // clearing
  14882. this.autoClear = true;
  14883. this.autoClearColor = true;
  14884. this.autoClearDepth = true;
  14885. this.autoClearStencil = true; // scene graph
  14886. this.sortObjects = true; // user-defined clipping
  14887. this.clippingPlanes = [];
  14888. this.localClippingEnabled = false; // physically based shading
  14889. this.gammaFactor = 2.0; // for backwards compatibility
  14890. this.outputEncoding = LinearEncoding; // physical lights
  14891. this.physicallyCorrectLights = false; // tone mapping
  14892. this.toneMapping = NoToneMapping;
  14893. this.toneMappingExposure = 1.0; // morphs
  14894. this.maxMorphTargets = 8;
  14895. this.maxMorphNormals = 4; // internal properties
  14896. var _this = this;
  14897. var _isContextLost = false; // internal state cache
  14898. var _framebuffer = null;
  14899. var _currentActiveCubeFace = 0;
  14900. var _currentActiveMipmapLevel = 0;
  14901. var _currentRenderTarget = null;
  14902. var _currentFramebuffer = null;
  14903. var _currentMaterialId = -1;
  14904. var _currentCamera = null;
  14905. var _currentViewport = new Vector4();
  14906. var _currentScissor = new Vector4();
  14907. var _currentScissorTest = null; //
  14908. var _width = _canvas.width;
  14909. var _height = _canvas.height;
  14910. var _pixelRatio = 1;
  14911. var _opaqueSort = null;
  14912. var _transparentSort = null;
  14913. var _viewport = new Vector4(0, 0, _width, _height);
  14914. var _scissor = new Vector4(0, 0, _width, _height);
  14915. var _scissorTest = false; // frustum
  14916. var _frustum = new Frustum(); // clipping
  14917. var _clippingEnabled = false;
  14918. var _localClippingEnabled = false; // camera matrices cache
  14919. var _projScreenMatrix = new Matrix4();
  14920. var _vector3 = new Vector3();
  14921. var _emptyScene = {
  14922. background: null,
  14923. fog: null,
  14924. environment: null,
  14925. overrideMaterial: null,
  14926. isScene: true
  14927. };
  14928. function getTargetPixelRatio() {
  14929. return _currentRenderTarget === null ? _pixelRatio : 1;
  14930. } // initialize
  14931. var _gl = _context;
  14932. function getContext(contextNames, contextAttributes) {
  14933. for (var i = 0; i < contextNames.length; i++) {
  14934. var contextName = contextNames[i];
  14935. var context = _canvas.getContext(contextName, contextAttributes);
  14936. if (context !== null) return context;
  14937. }
  14938. return null;
  14939. }
  14940. try {
  14941. var contextAttributes = {
  14942. alpha: _alpha,
  14943. depth: _depth,
  14944. stencil: _stencil,
  14945. antialias: _antialias,
  14946. premultipliedAlpha: _premultipliedAlpha,
  14947. preserveDrawingBuffer: _preserveDrawingBuffer,
  14948. powerPreference: _powerPreference,
  14949. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  14950. }; // event listeners must be registered before WebGL context is created, see #12753
  14951. _canvas.addEventListener('webglcontextlost', onContextLost, false);
  14952. _canvas.addEventListener('webglcontextrestored', onContextRestore, false);
  14953. if (_gl === null) {
  14954. var contextNames = ['webgl2', 'webgl', 'experimental-webgl'];
  14955. if (_this.isWebGL1Renderer === true) {
  14956. contextNames.shift();
  14957. }
  14958. _gl = getContext(contextNames, contextAttributes);
  14959. if (_gl === null) {
  14960. if (getContext(contextNames)) {
  14961. throw new Error('Error creating WebGL context with your selected attributes.');
  14962. } else {
  14963. throw new Error('Error creating WebGL context.');
  14964. }
  14965. }
  14966. } // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14967. if (_gl.getShaderPrecisionFormat === undefined) {
  14968. _gl.getShaderPrecisionFormat = function () {
  14969. return {
  14970. 'rangeMin': 1,
  14971. 'rangeMax': 1,
  14972. 'precision': 1
  14973. };
  14974. };
  14975. }
  14976. } catch (error) {
  14977. console.error('THREE.WebGLRenderer: ' + error.message);
  14978. throw error;
  14979. }
  14980. var extensions, capabilities, state, info;
  14981. var properties, textures, cubemaps, attributes, geometries, objects;
  14982. var programCache, materials, renderLists, renderStates, clipping;
  14983. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14984. var utils, bindingStates;
  14985. function initGLContext() {
  14986. extensions = new WebGLExtensions(_gl);
  14987. capabilities = new WebGLCapabilities(_gl, extensions, parameters);
  14988. extensions.init(capabilities);
  14989. utils = new WebGLUtils(_gl, extensions, capabilities);
  14990. state = new WebGLState(_gl, extensions, capabilities);
  14991. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  14992. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  14993. info = new WebGLInfo(_gl);
  14994. properties = new WebGLProperties();
  14995. textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info);
  14996. cubemaps = new WebGLCubeMaps(_this);
  14997. attributes = new WebGLAttributes(_gl, capabilities);
  14998. bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities);
  14999. geometries = new WebGLGeometries(_gl, attributes, info, bindingStates);
  15000. objects = new WebGLObjects(_gl, geometries, attributes, info);
  15001. morphtargets = new WebGLMorphtargets(_gl);
  15002. clipping = new WebGLClipping(properties);
  15003. programCache = new WebGLPrograms(_this, cubemaps, extensions, capabilities, bindingStates, clipping);
  15004. materials = new WebGLMaterials(properties);
  15005. renderLists = new WebGLRenderLists(properties);
  15006. renderStates = new WebGLRenderStates(extensions, capabilities);
  15007. background = new WebGLBackground(_this, cubemaps, state, objects, _premultipliedAlpha);
  15008. bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities);
  15009. indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities);
  15010. info.programs = programCache.programs;
  15011. _this.capabilities = capabilities;
  15012. _this.extensions = extensions;
  15013. _this.properties = properties;
  15014. _this.renderLists = renderLists;
  15015. _this.state = state;
  15016. _this.info = info;
  15017. }
  15018. initGLContext(); // xr
  15019. var xr = new WebXRManager(_this, _gl);
  15020. this.xr = xr; // shadow map
  15021. var shadowMap = new WebGLShadowMap(_this, objects, capabilities.maxTextureSize);
  15022. this.shadowMap = shadowMap; // API
  15023. this.getContext = function () {
  15024. return _gl;
  15025. };
  15026. this.getContextAttributes = function () {
  15027. return _gl.getContextAttributes();
  15028. };
  15029. this.forceContextLoss = function () {
  15030. var extension = extensions.get('WEBGL_lose_context');
  15031. if (extension) extension.loseContext();
  15032. };
  15033. this.forceContextRestore = function () {
  15034. var extension = extensions.get('WEBGL_lose_context');
  15035. if (extension) extension.restoreContext();
  15036. };
  15037. this.getPixelRatio = function () {
  15038. return _pixelRatio;
  15039. };
  15040. this.setPixelRatio = function (value) {
  15041. if (value === undefined) return;
  15042. _pixelRatio = value;
  15043. this.setSize(_width, _height, false);
  15044. };
  15045. this.getSize = function (target) {
  15046. if (target === undefined) {
  15047. console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');
  15048. target = new Vector2();
  15049. }
  15050. return target.set(_width, _height);
  15051. };
  15052. this.setSize = function (width, height, updateStyle) {
  15053. if (xr.isPresenting) {
  15054. console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');
  15055. return;
  15056. }
  15057. _width = width;
  15058. _height = height;
  15059. _canvas.width = Math.floor(width * _pixelRatio);
  15060. _canvas.height = Math.floor(height * _pixelRatio);
  15061. if (updateStyle !== false) {
  15062. _canvas.style.width = width + 'px';
  15063. _canvas.style.height = height + 'px';
  15064. }
  15065. this.setViewport(0, 0, width, height);
  15066. };
  15067. this.getDrawingBufferSize = function (target) {
  15068. if (target === undefined) {
  15069. console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');
  15070. target = new Vector2();
  15071. }
  15072. return target.set(_width * _pixelRatio, _height * _pixelRatio).floor();
  15073. };
  15074. this.setDrawingBufferSize = function (width, height, pixelRatio) {
  15075. _width = width;
  15076. _height = height;
  15077. _pixelRatio = pixelRatio;
  15078. _canvas.width = Math.floor(width * pixelRatio);
  15079. _canvas.height = Math.floor(height * pixelRatio);
  15080. this.setViewport(0, 0, width, height);
  15081. };
  15082. this.getCurrentViewport = function (target) {
  15083. if (target === undefined) {
  15084. console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');
  15085. target = new Vector4();
  15086. }
  15087. return target.copy(_currentViewport);
  15088. };
  15089. this.getViewport = function (target) {
  15090. return target.copy(_viewport);
  15091. };
  15092. this.setViewport = function (x, y, width, height) {
  15093. if (x.isVector4) {
  15094. _viewport.set(x.x, x.y, x.z, x.w);
  15095. } else {
  15096. _viewport.set(x, y, width, height);
  15097. }
  15098. state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());
  15099. };
  15100. this.getScissor = function (target) {
  15101. return target.copy(_scissor);
  15102. };
  15103. this.setScissor = function (x, y, width, height) {
  15104. if (x.isVector4) {
  15105. _scissor.set(x.x, x.y, x.z, x.w);
  15106. } else {
  15107. _scissor.set(x, y, width, height);
  15108. }
  15109. state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());
  15110. };
  15111. this.getScissorTest = function () {
  15112. return _scissorTest;
  15113. };
  15114. this.setScissorTest = function (boolean) {
  15115. state.setScissorTest(_scissorTest = boolean);
  15116. };
  15117. this.setOpaqueSort = function (method) {
  15118. _opaqueSort = method;
  15119. };
  15120. this.setTransparentSort = function (method) {
  15121. _transparentSort = method;
  15122. }; // Clearing
  15123. this.getClearColor = function (target) {
  15124. if (target === undefined) {
  15125. console.warn('WebGLRenderer: .getClearColor() now requires a Color as an argument');
  15126. target = new Color();
  15127. }
  15128. return target.copy(background.getClearColor());
  15129. };
  15130. this.setClearColor = function () {
  15131. background.setClearColor.apply(background, arguments);
  15132. };
  15133. this.getClearAlpha = function () {
  15134. return background.getClearAlpha();
  15135. };
  15136. this.setClearAlpha = function () {
  15137. background.setClearAlpha.apply(background, arguments);
  15138. };
  15139. this.clear = function (color, depth, stencil) {
  15140. var bits = 0;
  15141. if (color === undefined || color) bits |= 16384;
  15142. if (depth === undefined || depth) bits |= 256;
  15143. if (stencil === undefined || stencil) bits |= 1024;
  15144. _gl.clear(bits);
  15145. };
  15146. this.clearColor = function () {
  15147. this.clear(true, false, false);
  15148. };
  15149. this.clearDepth = function () {
  15150. this.clear(false, true, false);
  15151. };
  15152. this.clearStencil = function () {
  15153. this.clear(false, false, true);
  15154. }; //
  15155. this.dispose = function () {
  15156. _canvas.removeEventListener('webglcontextlost', onContextLost, false);
  15157. _canvas.removeEventListener('webglcontextrestored', onContextRestore, false);
  15158. renderLists.dispose();
  15159. renderStates.dispose();
  15160. properties.dispose();
  15161. cubemaps.dispose();
  15162. objects.dispose();
  15163. bindingStates.dispose();
  15164. xr.dispose();
  15165. animation.stop();
  15166. }; // Events
  15167. function onContextLost(event) {
  15168. event.preventDefault();
  15169. console.log('THREE.WebGLRenderer: Context Lost.');
  15170. _isContextLost = true;
  15171. }
  15172. function onContextRestore()
  15173. /* event */
  15174. {
  15175. console.log('THREE.WebGLRenderer: Context Restored.');
  15176. _isContextLost = false;
  15177. initGLContext();
  15178. }
  15179. function onMaterialDispose(event) {
  15180. var material = event.target;
  15181. material.removeEventListener('dispose', onMaterialDispose);
  15182. deallocateMaterial(material);
  15183. } // Buffer deallocation
  15184. function deallocateMaterial(material) {
  15185. releaseMaterialProgramReference(material);
  15186. properties.remove(material);
  15187. }
  15188. function releaseMaterialProgramReference(material) {
  15189. var programInfo = properties.get(material).program;
  15190. if (programInfo !== undefined) {
  15191. programCache.releaseProgram(programInfo);
  15192. }
  15193. } // Buffer rendering
  15194. function renderObjectImmediate(object, program) {
  15195. object.render(function (object) {
  15196. _this.renderBufferImmediate(object, program);
  15197. });
  15198. }
  15199. this.renderBufferImmediate = function (object, program) {
  15200. bindingStates.initAttributes();
  15201. var buffers = properties.get(object);
  15202. if (object.hasPositions && !buffers.position) buffers.position = _gl.createBuffer();
  15203. if (object.hasNormals && !buffers.normal) buffers.normal = _gl.createBuffer();
  15204. if (object.hasUvs && !buffers.uv) buffers.uv = _gl.createBuffer();
  15205. if (object.hasColors && !buffers.color) buffers.color = _gl.createBuffer();
  15206. var programAttributes = program.getAttributes();
  15207. if (object.hasPositions) {
  15208. _gl.bindBuffer(34962, buffers.position);
  15209. _gl.bufferData(34962, object.positionArray, 35048);
  15210. bindingStates.enableAttribute(programAttributes.position);
  15211. _gl.vertexAttribPointer(programAttributes.position, 3, 5126, false, 0, 0);
  15212. }
  15213. if (object.hasNormals) {
  15214. _gl.bindBuffer(34962, buffers.normal);
  15215. _gl.bufferData(34962, object.normalArray, 35048);
  15216. bindingStates.enableAttribute(programAttributes.normal);
  15217. _gl.vertexAttribPointer(programAttributes.normal, 3, 5126, false, 0, 0);
  15218. }
  15219. if (object.hasUvs) {
  15220. _gl.bindBuffer(34962, buffers.uv);
  15221. _gl.bufferData(34962, object.uvArray, 35048);
  15222. bindingStates.enableAttribute(programAttributes.uv);
  15223. _gl.vertexAttribPointer(programAttributes.uv, 2, 5126, false, 0, 0);
  15224. }
  15225. if (object.hasColors) {
  15226. _gl.bindBuffer(34962, buffers.color);
  15227. _gl.bufferData(34962, object.colorArray, 35048);
  15228. bindingStates.enableAttribute(programAttributes.color);
  15229. _gl.vertexAttribPointer(programAttributes.color, 3, 5126, false, 0, 0);
  15230. }
  15231. bindingStates.disableUnusedAttributes();
  15232. _gl.drawArrays(4, 0, object.count);
  15233. object.count = 0;
  15234. };
  15235. this.renderBufferDirect = function (camera, scene, geometry, material, object, group) {
  15236. if (scene === null) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  15237. var frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0;
  15238. var program = setProgram(camera, scene, material, object);
  15239. state.setMaterial(material, frontFaceCW); //
  15240. var index = geometry.index;
  15241. var position = geometry.attributes.position; //
  15242. if (index === null) {
  15243. if (position === undefined || position.count === 0) return;
  15244. } else if (index.count === 0) {
  15245. return;
  15246. } //
  15247. var rangeFactor = 1;
  15248. if (material.wireframe === true) {
  15249. index = geometries.getWireframeAttribute(geometry);
  15250. rangeFactor = 2;
  15251. }
  15252. if (material.morphTargets || material.morphNormals) {
  15253. morphtargets.update(object, geometry, material, program);
  15254. }
  15255. bindingStates.setup(object, material, program, geometry, index);
  15256. var attribute;
  15257. var renderer = bufferRenderer;
  15258. if (index !== null) {
  15259. attribute = attributes.get(index);
  15260. renderer = indexedBufferRenderer;
  15261. renderer.setIndex(attribute);
  15262. } //
  15263. var dataCount = index !== null ? index.count : position.count;
  15264. var rangeStart = geometry.drawRange.start * rangeFactor;
  15265. var rangeCount = geometry.drawRange.count * rangeFactor;
  15266. var groupStart = group !== null ? group.start * rangeFactor : 0;
  15267. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  15268. var drawStart = Math.max(rangeStart, groupStart);
  15269. var drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1;
  15270. var drawCount = Math.max(0, drawEnd - drawStart + 1);
  15271. if (drawCount === 0) return; //
  15272. if (object.isMesh) {
  15273. if (material.wireframe === true) {
  15274. state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio());
  15275. renderer.setMode(1);
  15276. } else {
  15277. renderer.setMode(4);
  15278. }
  15279. } else if (object.isLine) {
  15280. var lineWidth = material.linewidth;
  15281. if (lineWidth === undefined) lineWidth = 1; // Not using Line*Material
  15282. state.setLineWidth(lineWidth * getTargetPixelRatio());
  15283. if (object.isLineSegments) {
  15284. renderer.setMode(1);
  15285. } else if (object.isLineLoop) {
  15286. renderer.setMode(2);
  15287. } else {
  15288. renderer.setMode(3);
  15289. }
  15290. } else if (object.isPoints) {
  15291. renderer.setMode(0);
  15292. } else if (object.isSprite) {
  15293. renderer.setMode(4);
  15294. }
  15295. if (object.isInstancedMesh) {
  15296. renderer.renderInstances(drawStart, drawCount, object.count);
  15297. } else if (geometry.isInstancedBufferGeometry) {
  15298. var instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount);
  15299. renderer.renderInstances(drawStart, drawCount, instanceCount);
  15300. } else {
  15301. renderer.render(drawStart, drawCount);
  15302. }
  15303. }; // Compile
  15304. this.compile = function (scene, camera) {
  15305. currentRenderState = renderStates.get(scene);
  15306. currentRenderState.init();
  15307. scene.traverseVisible(function (object) {
  15308. if (object.isLight && object.layers.test(camera.layers)) {
  15309. currentRenderState.pushLight(object);
  15310. if (object.castShadow) {
  15311. currentRenderState.pushShadow(object);
  15312. }
  15313. }
  15314. });
  15315. currentRenderState.setupLights();
  15316. var compiled = new WeakMap();
  15317. scene.traverse(function (object) {
  15318. var material = object.material;
  15319. if (material) {
  15320. if (Array.isArray(material)) {
  15321. for (var i = 0; i < material.length; i++) {
  15322. var material2 = material[i];
  15323. if (compiled.has(material2) === false) {
  15324. initMaterial(material2, scene, object);
  15325. compiled.set(material2);
  15326. }
  15327. }
  15328. } else if (compiled.has(material) === false) {
  15329. initMaterial(material, scene, object);
  15330. compiled.set(material);
  15331. }
  15332. }
  15333. });
  15334. }; // Animation Loop
  15335. var onAnimationFrameCallback = null;
  15336. function onAnimationFrame(time) {
  15337. if (xr.isPresenting) return;
  15338. if (onAnimationFrameCallback) onAnimationFrameCallback(time);
  15339. }
  15340. var animation = new WebGLAnimation();
  15341. animation.setAnimationLoop(onAnimationFrame);
  15342. if (typeof window !== 'undefined') animation.setContext(window);
  15343. this.setAnimationLoop = function (callback) {
  15344. onAnimationFrameCallback = callback;
  15345. xr.setAnimationLoop(callback);
  15346. callback === null ? animation.stop() : animation.start();
  15347. }; // Rendering
  15348. this.render = function (scene, camera) {
  15349. var renderTarget, forceClear;
  15350. if (arguments[2] !== undefined) {
  15351. console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');
  15352. renderTarget = arguments[2];
  15353. }
  15354. if (arguments[3] !== undefined) {
  15355. console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');
  15356. forceClear = arguments[3];
  15357. }
  15358. if (camera !== undefined && camera.isCamera !== true) {
  15359. console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');
  15360. return;
  15361. }
  15362. if (_isContextLost === true) return; // reset caching for this frame
  15363. bindingStates.resetDefaultState();
  15364. _currentMaterialId = -1;
  15365. _currentCamera = null; // update scene graph
  15366. if (scene.autoUpdate === true) scene.updateMatrixWorld(); // update camera matrices and frustum
  15367. if (camera.parent === null) camera.updateMatrixWorld();
  15368. if (xr.enabled === true && xr.isPresenting === true) {
  15369. camera = xr.getCamera(camera);
  15370. } //
  15371. if (scene.isScene === true) scene.onBeforeRender(_this, scene, camera, renderTarget || _currentRenderTarget);
  15372. currentRenderState = renderStates.get(scene, renderStateStack.length);
  15373. currentRenderState.init();
  15374. renderStateStack.push(currentRenderState);
  15375. _projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  15376. _frustum.setFromProjectionMatrix(_projScreenMatrix);
  15377. _localClippingEnabled = this.localClippingEnabled;
  15378. _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled, camera);
  15379. currentRenderList = renderLists.get(scene, camera);
  15380. currentRenderList.init();
  15381. projectObject(scene, camera, 0, _this.sortObjects);
  15382. currentRenderList.finish();
  15383. if (_this.sortObjects === true) {
  15384. currentRenderList.sort(_opaqueSort, _transparentSort);
  15385. } //
  15386. if (_clippingEnabled === true) clipping.beginShadows();
  15387. var shadowsArray = currentRenderState.state.shadowsArray;
  15388. shadowMap.render(shadowsArray, scene, camera);
  15389. currentRenderState.setupLights();
  15390. currentRenderState.setupLightsView(camera);
  15391. if (_clippingEnabled === true) clipping.endShadows(); //
  15392. if (this.info.autoReset === true) this.info.reset();
  15393. if (renderTarget !== undefined) {
  15394. this.setRenderTarget(renderTarget);
  15395. } //
  15396. background.render(currentRenderList, scene, camera, forceClear); // render scene
  15397. var opaqueObjects = currentRenderList.opaque;
  15398. var transparentObjects = currentRenderList.transparent;
  15399. if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene, camera);
  15400. if (transparentObjects.length > 0) renderObjects(transparentObjects, scene, camera); //
  15401. if (scene.isScene === true) scene.onAfterRender(_this, scene, camera); //
  15402. if (_currentRenderTarget !== null) {
  15403. // Generate mipmap if we're using any kind of mipmap filtering
  15404. textures.updateRenderTargetMipmap(_currentRenderTarget); // resolve multisample renderbuffers to a single-sample texture if necessary
  15405. textures.updateMultisampleRenderTarget(_currentRenderTarget);
  15406. } // Ensure depth buffer writing is enabled so it can be cleared on next render
  15407. state.buffers.depth.setTest(true);
  15408. state.buffers.depth.setMask(true);
  15409. state.buffers.color.setMask(true);
  15410. state.setPolygonOffset(false); // _gl.finish();
  15411. renderStateStack.pop();
  15412. if (renderStateStack.length > 0) {
  15413. currentRenderState = renderStateStack[renderStateStack.length - 1];
  15414. } else {
  15415. currentRenderState = null;
  15416. }
  15417. currentRenderList = null;
  15418. };
  15419. function projectObject(object, camera, groupOrder, sortObjects) {
  15420. if (object.visible === false) return;
  15421. var visible = object.layers.test(camera.layers);
  15422. if (visible) {
  15423. if (object.isGroup) {
  15424. groupOrder = object.renderOrder;
  15425. } else if (object.isLOD) {
  15426. if (object.autoUpdate === true) object.update(camera);
  15427. } else if (object.isLight) {
  15428. currentRenderState.pushLight(object);
  15429. if (object.castShadow) {
  15430. currentRenderState.pushShadow(object);
  15431. }
  15432. } else if (object.isSprite) {
  15433. if (!object.frustumCulled || _frustum.intersectsSprite(object)) {
  15434. if (sortObjects) {
  15435. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15436. }
  15437. var geometry = objects.update(object);
  15438. var material = object.material;
  15439. if (material.visible) {
  15440. currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null);
  15441. }
  15442. }
  15443. } else if (object.isImmediateRenderObject) {
  15444. if (sortObjects) {
  15445. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15446. }
  15447. currentRenderList.push(object, null, object.material, groupOrder, _vector3.z, null);
  15448. } else if (object.isMesh || object.isLine || object.isPoints) {
  15449. if (object.isSkinnedMesh) {
  15450. // update skeleton only once in a frame
  15451. if (object.skeleton.frame !== info.render.frame) {
  15452. object.skeleton.update();
  15453. object.skeleton.frame = info.render.frame;
  15454. }
  15455. }
  15456. if (!object.frustumCulled || _frustum.intersectsObject(object)) {
  15457. if (sortObjects) {
  15458. _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);
  15459. }
  15460. var _geometry = objects.update(object);
  15461. var _material = object.material;
  15462. if (Array.isArray(_material)) {
  15463. var groups = _geometry.groups;
  15464. for (var i = 0, l = groups.length; i < l; i++) {
  15465. var group = groups[i];
  15466. var groupMaterial = _material[group.materialIndex];
  15467. if (groupMaterial && groupMaterial.visible) {
  15468. currentRenderList.push(object, _geometry, groupMaterial, groupOrder, _vector3.z, group);
  15469. }
  15470. }
  15471. } else if (_material.visible) {
  15472. currentRenderList.push(object, _geometry, _material, groupOrder, _vector3.z, null);
  15473. }
  15474. }
  15475. }
  15476. }
  15477. var children = object.children;
  15478. for (var _i = 0, _l = children.length; _i < _l; _i++) {
  15479. projectObject(children[_i], camera, groupOrder, sortObjects);
  15480. }
  15481. }
  15482. function renderObjects(renderList, scene, camera) {
  15483. var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  15484. for (var i = 0, l = renderList.length; i < l; i++) {
  15485. var renderItem = renderList[i];
  15486. var object = renderItem.object;
  15487. var geometry = renderItem.geometry;
  15488. var material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  15489. var group = renderItem.group;
  15490. if (camera.isArrayCamera) {
  15491. var cameras = camera.cameras;
  15492. for (var j = 0, jl = cameras.length; j < jl; j++) {
  15493. var camera2 = cameras[j];
  15494. if (object.layers.test(camera2.layers)) {
  15495. state.viewport(_currentViewport.copy(camera2.viewport));
  15496. currentRenderState.setupLightsView(camera2);
  15497. renderObject(object, scene, camera2, geometry, material, group);
  15498. }
  15499. }
  15500. } else {
  15501. renderObject(object, scene, camera, geometry, material, group);
  15502. }
  15503. }
  15504. }
  15505. function renderObject(object, scene, camera, geometry, material, group) {
  15506. object.onBeforeRender(_this, scene, camera, geometry, material, group);
  15507. object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse, object.matrixWorld);
  15508. object.normalMatrix.getNormalMatrix(object.modelViewMatrix);
  15509. if (object.isImmediateRenderObject) {
  15510. var program = setProgram(camera, scene, material, object);
  15511. state.setMaterial(material);
  15512. bindingStates.reset();
  15513. renderObjectImmediate(object, program);
  15514. } else {
  15515. _this.renderBufferDirect(camera, scene, geometry, material, object, group);
  15516. }
  15517. object.onAfterRender(_this, scene, camera, geometry, material, group);
  15518. }
  15519. function initMaterial(material, scene, object) {
  15520. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15521. var materialProperties = properties.get(material);
  15522. var lights = currentRenderState.state.lights;
  15523. var shadowsArray = currentRenderState.state.shadowsArray;
  15524. var lightsStateVersion = lights.state.version;
  15525. var parameters = programCache.getParameters(material, lights.state, shadowsArray, scene, object);
  15526. var programCacheKey = programCache.getProgramCacheKey(parameters);
  15527. var program = materialProperties.program;
  15528. var programChange = true; // always update environment and fog - changing these trigger an initMaterial call, but it's possible that the program doesn't change
  15529. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  15530. materialProperties.fog = scene.fog;
  15531. materialProperties.envMap = cubemaps.get(material.envMap || materialProperties.environment);
  15532. if (program === undefined) {
  15533. // new material
  15534. material.addEventListener('dispose', onMaterialDispose);
  15535. } else if (program.cacheKey !== programCacheKey) {
  15536. // changed glsl or parameters
  15537. releaseMaterialProgramReference(material);
  15538. } else if (materialProperties.lightsStateVersion !== lightsStateVersion) {
  15539. programChange = false;
  15540. } else if (parameters.shaderID !== undefined) {
  15541. // same glsl and uniform list
  15542. return;
  15543. } else {
  15544. // only rebuild uniform list
  15545. programChange = false;
  15546. }
  15547. if (programChange) {
  15548. parameters.uniforms = programCache.getUniforms(material);
  15549. material.onBeforeCompile(parameters, _this);
  15550. program = programCache.acquireProgram(parameters, programCacheKey);
  15551. materialProperties.program = program;
  15552. materialProperties.uniforms = parameters.uniforms;
  15553. materialProperties.outputEncoding = parameters.outputEncoding;
  15554. }
  15555. var uniforms = materialProperties.uniforms;
  15556. if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) {
  15557. materialProperties.numClippingPlanes = clipping.numPlanes;
  15558. materialProperties.numIntersection = clipping.numIntersection;
  15559. uniforms.clippingPlanes = clipping.uniform;
  15560. } // store the light setup it was created for
  15561. materialProperties.needsLights = materialNeedsLights(material);
  15562. materialProperties.lightsStateVersion = lightsStateVersion;
  15563. if (materialProperties.needsLights) {
  15564. // wire up the material to this renderer's lighting state
  15565. uniforms.ambientLightColor.value = lights.state.ambient;
  15566. uniforms.lightProbe.value = lights.state.probe;
  15567. uniforms.directionalLights.value = lights.state.directional;
  15568. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  15569. uniforms.spotLights.value = lights.state.spot;
  15570. uniforms.spotLightShadows.value = lights.state.spotShadow;
  15571. uniforms.rectAreaLights.value = lights.state.rectArea;
  15572. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  15573. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  15574. uniforms.pointLights.value = lights.state.point;
  15575. uniforms.pointLightShadows.value = lights.state.pointShadow;
  15576. uniforms.hemisphereLights.value = lights.state.hemi;
  15577. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  15578. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  15579. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  15580. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  15581. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  15582. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; // TODO (abelnation): add area lights shadow info to uniforms
  15583. }
  15584. var progUniforms = materialProperties.program.getUniforms();
  15585. var uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms);
  15586. materialProperties.uniformsList = uniformsList;
  15587. }
  15588. function setProgram(camera, scene, material, object) {
  15589. if (scene.isScene !== true) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  15590. textures.resetTextureUnits();
  15591. var fog = scene.fog;
  15592. var environment = material.isMeshStandardMaterial ? scene.environment : null;
  15593. var encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  15594. var envMap = cubemaps.get(material.envMap || environment);
  15595. var materialProperties = properties.get(material);
  15596. var lights = currentRenderState.state.lights;
  15597. if (_clippingEnabled === true) {
  15598. if (_localClippingEnabled === true || camera !== _currentCamera) {
  15599. var useCache = camera === _currentCamera && material.id === _currentMaterialId; // we might want to call this function with some ClippingGroup
  15600. // object instead of the material, once it becomes feasible
  15601. // (#8465, #8379)
  15602. clipping.setState(material, camera, useCache);
  15603. }
  15604. }
  15605. if (material.version === materialProperties.__version) {
  15606. if (material.fog && materialProperties.fog !== fog) {
  15607. initMaterial(material, scene, object);
  15608. } else if (materialProperties.environment !== environment) {
  15609. initMaterial(material, scene, object);
  15610. } else if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) {
  15611. initMaterial(material, scene, object);
  15612. } else if (materialProperties.numClippingPlanes !== undefined && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) {
  15613. initMaterial(material, scene, object);
  15614. } else if (materialProperties.outputEncoding !== encoding) {
  15615. initMaterial(material, scene, object);
  15616. } else if (materialProperties.envMap !== envMap) {
  15617. initMaterial(material, scene, object);
  15618. }
  15619. } else {
  15620. initMaterial(material, scene, object);
  15621. materialProperties.__version = material.version;
  15622. }
  15623. var refreshProgram = false;
  15624. var refreshMaterial = false;
  15625. var refreshLights = false;
  15626. var program = materialProperties.program,
  15627. p_uniforms = program.getUniforms(),
  15628. m_uniforms = materialProperties.uniforms;
  15629. if (state.useProgram(program.program)) {
  15630. refreshProgram = true;
  15631. refreshMaterial = true;
  15632. refreshLights = true;
  15633. }
  15634. if (material.id !== _currentMaterialId) {
  15635. _currentMaterialId = material.id;
  15636. refreshMaterial = true;
  15637. }
  15638. if (refreshProgram || _currentCamera !== camera) {
  15639. p_uniforms.setValue(_gl, 'projectionMatrix', camera.projectionMatrix);
  15640. if (capabilities.logarithmicDepthBuffer) {
  15641. p_uniforms.setValue(_gl, 'logDepthBufFC', 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
  15642. }
  15643. if (_currentCamera !== camera) {
  15644. _currentCamera = camera; // lighting uniforms depend on the camera so enforce an update
  15645. // now, in case this material supports lights - or later, when
  15646. // the next material that does gets activated:
  15647. refreshMaterial = true; // set to true on material change
  15648. refreshLights = true; // remains set until update done
  15649. } // load material specific uniforms
  15650. // (shader material also gets them for the sake of genericity)
  15651. if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) {
  15652. var uCamPos = p_uniforms.map.cameraPosition;
  15653. if (uCamPos !== undefined) {
  15654. uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera.matrixWorld));
  15655. }
  15656. }
  15657. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) {
  15658. p_uniforms.setValue(_gl, 'isOrthographic', camera.isOrthographicCamera === true);
  15659. }
  15660. if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || material.skinning) {
  15661. p_uniforms.setValue(_gl, 'viewMatrix', camera.matrixWorldInverse);
  15662. }
  15663. } // skinning uniforms must be set even if material didn't change
  15664. // auto-setting of texture unit for bone texture must go before other textures
  15665. // otherwise textures used for skinning can take over texture units reserved for other material textures
  15666. if (material.skinning) {
  15667. p_uniforms.setOptional(_gl, object, 'bindMatrix');
  15668. p_uniforms.setOptional(_gl, object, 'bindMatrixInverse');
  15669. var skeleton = object.skeleton;
  15670. if (skeleton) {
  15671. var bones = skeleton.bones;
  15672. if (capabilities.floatVertexTextures) {
  15673. if (skeleton.boneTexture === null) {
  15674. // layout (1 matrix = 4 pixels)
  15675. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  15676. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  15677. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  15678. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  15679. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  15680. var size = Math.sqrt(bones.length * 4); // 4 pixels needed for 1 matrix
  15681. size = MathUtils.ceilPowerOfTwo(size);
  15682. size = Math.max(size, 4);
  15683. var boneMatrices = new Float32Array(size * size * 4); // 4 floats per RGBA pixel
  15684. boneMatrices.set(skeleton.boneMatrices); // copy current values
  15685. var boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
  15686. skeleton.boneMatrices = boneMatrices;
  15687. skeleton.boneTexture = boneTexture;
  15688. skeleton.boneTextureSize = size;
  15689. }
  15690. p_uniforms.setValue(_gl, 'boneTexture', skeleton.boneTexture, textures);
  15691. p_uniforms.setValue(_gl, 'boneTextureSize', skeleton.boneTextureSize);
  15692. } else {
  15693. p_uniforms.setOptional(_gl, skeleton, 'boneMatrices');
  15694. }
  15695. }
  15696. }
  15697. if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) {
  15698. materialProperties.receiveShadow = object.receiveShadow;
  15699. p_uniforms.setValue(_gl, 'receiveShadow', object.receiveShadow);
  15700. }
  15701. if (refreshMaterial) {
  15702. p_uniforms.setValue(_gl, 'toneMappingExposure', _this.toneMappingExposure);
  15703. if (materialProperties.needsLights) {
  15704. // the current material requires lighting info
  15705. // note: all lighting uniforms are always set correctly
  15706. // they simply reference the renderer's state for their
  15707. // values
  15708. //
  15709. // use the current material's .needsUpdate flags to set
  15710. // the GL state when required
  15711. markUniformsLightsNeedsUpdate(m_uniforms, refreshLights);
  15712. } // refresh uniforms common to several materials
  15713. if (fog && material.fog) {
  15714. materials.refreshFogUniforms(m_uniforms, fog);
  15715. }
  15716. materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height);
  15717. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15718. }
  15719. if (material.isShaderMaterial && material.uniformsNeedUpdate === true) {
  15720. WebGLUniforms.upload(_gl, materialProperties.uniformsList, m_uniforms, textures);
  15721. material.uniformsNeedUpdate = false;
  15722. }
  15723. if (material.isSpriteMaterial) {
  15724. p_uniforms.setValue(_gl, 'center', object.center);
  15725. } // common matrices
  15726. p_uniforms.setValue(_gl, 'modelViewMatrix', object.modelViewMatrix);
  15727. p_uniforms.setValue(_gl, 'normalMatrix', object.normalMatrix);
  15728. p_uniforms.setValue(_gl, 'modelMatrix', object.matrixWorld);
  15729. return program;
  15730. } // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15731. function markUniformsLightsNeedsUpdate(uniforms, value) {
  15732. uniforms.ambientLightColor.needsUpdate = value;
  15733. uniforms.lightProbe.needsUpdate = value;
  15734. uniforms.directionalLights.needsUpdate = value;
  15735. uniforms.directionalLightShadows.needsUpdate = value;
  15736. uniforms.pointLights.needsUpdate = value;
  15737. uniforms.pointLightShadows.needsUpdate = value;
  15738. uniforms.spotLights.needsUpdate = value;
  15739. uniforms.spotLightShadows.needsUpdate = value;
  15740. uniforms.rectAreaLights.needsUpdate = value;
  15741. uniforms.hemisphereLights.needsUpdate = value;
  15742. }
  15743. function materialNeedsLights(material) {
  15744. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true;
  15745. } //
  15746. this.setFramebuffer = function (value) {
  15747. if (_framebuffer !== value && _currentRenderTarget === null) _gl.bindFramebuffer(36160, value);
  15748. _framebuffer = value;
  15749. };
  15750. this.getActiveCubeFace = function () {
  15751. return _currentActiveCubeFace;
  15752. };
  15753. this.getActiveMipmapLevel = function () {
  15754. return _currentActiveMipmapLevel;
  15755. };
  15756. this.getRenderList = function () {
  15757. return currentRenderList;
  15758. };
  15759. this.setRenderList = function (renderList) {
  15760. currentRenderList = renderList;
  15761. };
  15762. this.getRenderTarget = function () {
  15763. return _currentRenderTarget;
  15764. };
  15765. this.setRenderTarget = function (renderTarget, activeCubeFace, activeMipmapLevel) {
  15766. if (activeCubeFace === void 0) {
  15767. activeCubeFace = 0;
  15768. }
  15769. if (activeMipmapLevel === void 0) {
  15770. activeMipmapLevel = 0;
  15771. }
  15772. _currentRenderTarget = renderTarget;
  15773. _currentActiveCubeFace = activeCubeFace;
  15774. _currentActiveMipmapLevel = activeMipmapLevel;
  15775. if (renderTarget && properties.get(renderTarget).__webglFramebuffer === undefined) {
  15776. textures.setupRenderTarget(renderTarget);
  15777. }
  15778. var framebuffer = _framebuffer;
  15779. var isCube = false;
  15780. if (renderTarget) {
  15781. var __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer;
  15782. if (renderTarget.isWebGLCubeRenderTarget) {
  15783. framebuffer = __webglFramebuffer[activeCubeFace];
  15784. isCube = true;
  15785. } else if (renderTarget.isWebGLMultisampleRenderTarget) {
  15786. framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer;
  15787. } else {
  15788. framebuffer = __webglFramebuffer;
  15789. }
  15790. _currentViewport.copy(renderTarget.viewport);
  15791. _currentScissor.copy(renderTarget.scissor);
  15792. _currentScissorTest = renderTarget.scissorTest;
  15793. } else {
  15794. _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();
  15795. _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();
  15796. _currentScissorTest = _scissorTest;
  15797. }
  15798. if (_currentFramebuffer !== framebuffer) {
  15799. _gl.bindFramebuffer(36160, framebuffer);
  15800. _currentFramebuffer = framebuffer;
  15801. }
  15802. state.viewport(_currentViewport);
  15803. state.scissor(_currentScissor);
  15804. state.setScissorTest(_currentScissorTest);
  15805. if (isCube) {
  15806. var textureProperties = properties.get(renderTarget.texture);
  15807. _gl.framebufferTexture2D(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel);
  15808. }
  15809. };
  15810. this.readRenderTargetPixels = function (renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
  15811. if (!(renderTarget && renderTarget.isWebGLRenderTarget)) {
  15812. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');
  15813. return;
  15814. }
  15815. var framebuffer = properties.get(renderTarget).__webglFramebuffer;
  15816. if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined) {
  15817. framebuffer = framebuffer[activeCubeFaceIndex];
  15818. }
  15819. if (framebuffer) {
  15820. var restore = false;
  15821. if (framebuffer !== _currentFramebuffer) {
  15822. _gl.bindFramebuffer(36160, framebuffer);
  15823. restore = true;
  15824. }
  15825. try {
  15826. var texture = renderTarget.texture;
  15827. var textureFormat = texture.format;
  15828. var textureType = texture.type;
  15829. if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) {
  15830. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
  15831. return;
  15832. }
  15833. var halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has('EXT_color_buffer_half_float') || capabilities.isWebGL2 && extensions.has('EXT_color_buffer_float'));
  15834. if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(35738) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15835. !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has('OES_texture_float') || extensions.has('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
  15836. !halfFloatSupportedByExt) {
  15837. console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
  15838. return;
  15839. }
  15840. if (_gl.checkFramebufferStatus(36160) === 36053) {
  15841. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15842. if (x >= 0 && x <= renderTarget.width - width && y >= 0 && y <= renderTarget.height - height) {
  15843. _gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
  15844. }
  15845. } else {
  15846. console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');
  15847. }
  15848. } finally {
  15849. if (restore) {
  15850. _gl.bindFramebuffer(36160, _currentFramebuffer);
  15851. }
  15852. }
  15853. }
  15854. };
  15855. this.copyFramebufferToTexture = function (position, texture, level) {
  15856. if (level === void 0) {
  15857. level = 0;
  15858. }
  15859. var levelScale = Math.pow(2, -level);
  15860. var width = Math.floor(texture.image.width * levelScale);
  15861. var height = Math.floor(texture.image.height * levelScale);
  15862. var glFormat = utils.convert(texture.format);
  15863. textures.setTexture2D(texture, 0);
  15864. _gl.copyTexImage2D(3553, level, glFormat, position.x, position.y, width, height, 0);
  15865. state.unbindTexture();
  15866. };
  15867. this.copyTextureToTexture = function (position, srcTexture, dstTexture, level) {
  15868. if (level === void 0) {
  15869. level = 0;
  15870. }
  15871. var width = srcTexture.image.width;
  15872. var height = srcTexture.image.height;
  15873. var glFormat = utils.convert(dstTexture.format);
  15874. var glType = utils.convert(dstTexture.type);
  15875. textures.setTexture2D(dstTexture, 0); // As another texture upload may have changed pixelStorei
  15876. // parameters, make sure they are correct for the dstTexture
  15877. _gl.pixelStorei(37440, dstTexture.flipY);
  15878. _gl.pixelStorei(37441, dstTexture.premultiplyAlpha);
  15879. _gl.pixelStorei(3317, dstTexture.unpackAlignment);
  15880. if (srcTexture.isDataTexture) {
  15881. _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data);
  15882. } else {
  15883. if (srcTexture.isCompressedTexture) {
  15884. _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data);
  15885. } else {
  15886. _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image);
  15887. }
  15888. } // Generate mipmaps only when copying level 0
  15889. if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553);
  15890. state.unbindTexture();
  15891. };
  15892. this.initTexture = function (texture) {
  15893. textures.setTexture2D(texture, 0);
  15894. state.unbindTexture();
  15895. };
  15896. this.resetState = function () {
  15897. state.reset();
  15898. bindingStates.reset();
  15899. };
  15900. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15901. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15902. detail: this
  15903. })); // eslint-disable-line no-undef
  15904. }
  15905. }
  15906. function WebGL1Renderer(parameters) {
  15907. WebGLRenderer.call(this, parameters);
  15908. }
  15909. WebGL1Renderer.prototype = Object.assign(Object.create(WebGLRenderer.prototype), {
  15910. constructor: WebGL1Renderer,
  15911. isWebGL1Renderer: true
  15912. });
  15913. var FogExp2 = /*#__PURE__*/function () {
  15914. function FogExp2(color, density) {
  15915. Object.defineProperty(this, 'isFogExp2', {
  15916. value: true
  15917. });
  15918. this.name = '';
  15919. this.color = new Color(color);
  15920. this.density = density !== undefined ? density : 0.00025;
  15921. }
  15922. var _proto = FogExp2.prototype;
  15923. _proto.clone = function clone() {
  15924. return new FogExp2(this.color, this.density);
  15925. };
  15926. _proto.toJSON = function toJSON()
  15927. /* meta */
  15928. {
  15929. return {
  15930. type: 'FogExp2',
  15931. color: this.color.getHex(),
  15932. density: this.density
  15933. };
  15934. };
  15935. return FogExp2;
  15936. }();
  15937. var Fog = /*#__PURE__*/function () {
  15938. function Fog(color, near, far) {
  15939. Object.defineProperty(this, 'isFog', {
  15940. value: true
  15941. });
  15942. this.name = '';
  15943. this.color = new Color(color);
  15944. this.near = near !== undefined ? near : 1;
  15945. this.far = far !== undefined ? far : 1000;
  15946. }
  15947. var _proto = Fog.prototype;
  15948. _proto.clone = function clone() {
  15949. return new Fog(this.color, this.near, this.far);
  15950. };
  15951. _proto.toJSON = function toJSON()
  15952. /* meta */
  15953. {
  15954. return {
  15955. type: 'Fog',
  15956. color: this.color.getHex(),
  15957. near: this.near,
  15958. far: this.far
  15959. };
  15960. };
  15961. return Fog;
  15962. }();
  15963. var Scene = /*#__PURE__*/function (_Object3D) {
  15964. _inheritsLoose(Scene, _Object3D);
  15965. function Scene() {
  15966. var _this;
  15967. _this = _Object3D.call(this) || this;
  15968. Object.defineProperty(_assertThisInitialized(_this), 'isScene', {
  15969. value: true
  15970. });
  15971. _this.type = 'Scene';
  15972. _this.background = null;
  15973. _this.environment = null;
  15974. _this.fog = null;
  15975. _this.overrideMaterial = null;
  15976. _this.autoUpdate = true; // checked by the renderer
  15977. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  15978. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe', {
  15979. detail: _assertThisInitialized(_this)
  15980. })); // eslint-disable-line no-undef
  15981. }
  15982. return _this;
  15983. }
  15984. var _proto = Scene.prototype;
  15985. _proto.copy = function copy(source, recursive) {
  15986. _Object3D.prototype.copy.call(this, source, recursive);
  15987. if (source.background !== null) this.background = source.background.clone();
  15988. if (source.environment !== null) this.environment = source.environment.clone();
  15989. if (source.fog !== null) this.fog = source.fog.clone();
  15990. if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone();
  15991. this.autoUpdate = source.autoUpdate;
  15992. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15993. return this;
  15994. };
  15995. _proto.toJSON = function toJSON(meta) {
  15996. var data = _Object3D.prototype.toJSON.call(this, meta);
  15997. if (this.background !== null) data.object.background = this.background.toJSON(meta);
  15998. if (this.environment !== null) data.object.environment = this.environment.toJSON(meta);
  15999. if (this.fog !== null) data.object.fog = this.fog.toJSON();
  16000. return data;
  16001. };
  16002. return Scene;
  16003. }(Object3D);
  16004. function InterleavedBuffer(array, stride) {
  16005. this.array = array;
  16006. this.stride = stride;
  16007. this.count = array !== undefined ? array.length / stride : 0;
  16008. this.usage = StaticDrawUsage;
  16009. this.updateRange = {
  16010. offset: 0,
  16011. count: -1
  16012. };
  16013. this.version = 0;
  16014. this.uuid = MathUtils.generateUUID();
  16015. }
  16016. Object.defineProperty(InterleavedBuffer.prototype, 'needsUpdate', {
  16017. set: function set(value) {
  16018. if (value === true) this.version++;
  16019. }
  16020. });
  16021. Object.assign(InterleavedBuffer.prototype, {
  16022. isInterleavedBuffer: true,
  16023. onUploadCallback: function onUploadCallback() {},
  16024. setUsage: function setUsage(value) {
  16025. this.usage = value;
  16026. return this;
  16027. },
  16028. copy: function copy(source) {
  16029. this.array = new source.array.constructor(source.array);
  16030. this.count = source.count;
  16031. this.stride = source.stride;
  16032. this.usage = source.usage;
  16033. return this;
  16034. },
  16035. copyAt: function copyAt(index1, attribute, index2) {
  16036. index1 *= this.stride;
  16037. index2 *= attribute.stride;
  16038. for (var i = 0, l = this.stride; i < l; i++) {
  16039. this.array[index1 + i] = attribute.array[index2 + i];
  16040. }
  16041. return this;
  16042. },
  16043. set: function set(value, offset) {
  16044. if (offset === void 0) {
  16045. offset = 0;
  16046. }
  16047. this.array.set(value, offset);
  16048. return this;
  16049. },
  16050. clone: function clone(data) {
  16051. if (data.arrayBuffers === undefined) {
  16052. data.arrayBuffers = {};
  16053. }
  16054. if (this.array.buffer._uuid === undefined) {
  16055. this.array.buffer._uuid = MathUtils.generateUUID();
  16056. }
  16057. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16058. data.arrayBuffers[this.array.buffer._uuid] = this.array.slice(0).buffer;
  16059. }
  16060. var array = new this.array.constructor(data.arrayBuffers[this.array.buffer._uuid]);
  16061. var ib = new InterleavedBuffer(array, this.stride);
  16062. ib.setUsage(this.usage);
  16063. return ib;
  16064. },
  16065. onUpload: function onUpload(callback) {
  16066. this.onUploadCallback = callback;
  16067. return this;
  16068. },
  16069. toJSON: function toJSON(data) {
  16070. if (data.arrayBuffers === undefined) {
  16071. data.arrayBuffers = {};
  16072. } // generate UUID for array buffer if necessary
  16073. if (this.array.buffer._uuid === undefined) {
  16074. this.array.buffer._uuid = MathUtils.generateUUID();
  16075. }
  16076. if (data.arrayBuffers[this.array.buffer._uuid] === undefined) {
  16077. data.arrayBuffers[this.array.buffer._uuid] = Array.prototype.slice.call(new Uint32Array(this.array.buffer));
  16078. } //
  16079. return {
  16080. uuid: this.uuid,
  16081. buffer: this.array.buffer._uuid,
  16082. type: this.array.constructor.name,
  16083. stride: this.stride
  16084. };
  16085. }
  16086. });
  16087. var _vector$6 = new Vector3();
  16088. function InterleavedBufferAttribute(interleavedBuffer, itemSize, offset, normalized) {
  16089. this.name = '';
  16090. this.data = interleavedBuffer;
  16091. this.itemSize = itemSize;
  16092. this.offset = offset;
  16093. this.normalized = normalized === true;
  16094. }
  16095. Object.defineProperties(InterleavedBufferAttribute.prototype, {
  16096. count: {
  16097. get: function get() {
  16098. return this.data.count;
  16099. }
  16100. },
  16101. array: {
  16102. get: function get() {
  16103. return this.data.array;
  16104. }
  16105. },
  16106. needsUpdate: {
  16107. set: function set(value) {
  16108. this.data.needsUpdate = value;
  16109. }
  16110. }
  16111. });
  16112. Object.assign(InterleavedBufferAttribute.prototype, {
  16113. isInterleavedBufferAttribute: true,
  16114. applyMatrix4: function applyMatrix4(m) {
  16115. for (var i = 0, l = this.data.count; i < l; i++) {
  16116. _vector$6.x = this.getX(i);
  16117. _vector$6.y = this.getY(i);
  16118. _vector$6.z = this.getZ(i);
  16119. _vector$6.applyMatrix4(m);
  16120. this.setXYZ(i, _vector$6.x, _vector$6.y, _vector$6.z);
  16121. }
  16122. return this;
  16123. },
  16124. setX: function setX(index, x) {
  16125. this.data.array[index * this.data.stride + this.offset] = x;
  16126. return this;
  16127. },
  16128. setY: function setY(index, y) {
  16129. this.data.array[index * this.data.stride + this.offset + 1] = y;
  16130. return this;
  16131. },
  16132. setZ: function setZ(index, z) {
  16133. this.data.array[index * this.data.stride + this.offset + 2] = z;
  16134. return this;
  16135. },
  16136. setW: function setW(index, w) {
  16137. this.data.array[index * this.data.stride + this.offset + 3] = w;
  16138. return this;
  16139. },
  16140. getX: function getX(index) {
  16141. return this.data.array[index * this.data.stride + this.offset];
  16142. },
  16143. getY: function getY(index) {
  16144. return this.data.array[index * this.data.stride + this.offset + 1];
  16145. },
  16146. getZ: function getZ(index) {
  16147. return this.data.array[index * this.data.stride + this.offset + 2];
  16148. },
  16149. getW: function getW(index) {
  16150. return this.data.array[index * this.data.stride + this.offset + 3];
  16151. },
  16152. setXY: function setXY(index, x, y) {
  16153. index = index * this.data.stride + this.offset;
  16154. this.data.array[index + 0] = x;
  16155. this.data.array[index + 1] = y;
  16156. return this;
  16157. },
  16158. setXYZ: function setXYZ(index, x, y, z) {
  16159. index = index * this.data.stride + this.offset;
  16160. this.data.array[index + 0] = x;
  16161. this.data.array[index + 1] = y;
  16162. this.data.array[index + 2] = z;
  16163. return this;
  16164. },
  16165. setXYZW: function setXYZW(index, x, y, z, w) {
  16166. index = index * this.data.stride + this.offset;
  16167. this.data.array[index + 0] = x;
  16168. this.data.array[index + 1] = y;
  16169. this.data.array[index + 2] = z;
  16170. this.data.array[index + 3] = w;
  16171. return this;
  16172. },
  16173. clone: function clone(data) {
  16174. if (data === undefined) {
  16175. console.log('THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.');
  16176. var array = [];
  16177. for (var i = 0; i < this.count; i++) {
  16178. var index = i * this.data.stride + this.offset;
  16179. for (var j = 0; j < this.itemSize; j++) {
  16180. array.push(this.data.array[index + j]);
  16181. }
  16182. }
  16183. return new BufferAttribute(new this.array.constructor(array), this.itemSize, this.normalized);
  16184. } else {
  16185. if (data.interleavedBuffers === undefined) {
  16186. data.interleavedBuffers = {};
  16187. }
  16188. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16189. data.interleavedBuffers[this.data.uuid] = this.data.clone(data);
  16190. }
  16191. return new InterleavedBufferAttribute(data.interleavedBuffers[this.data.uuid], this.itemSize, this.offset, this.normalized);
  16192. }
  16193. },
  16194. toJSON: function toJSON(data) {
  16195. if (data === undefined) {
  16196. console.log('THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.');
  16197. var array = [];
  16198. for (var i = 0; i < this.count; i++) {
  16199. var index = i * this.data.stride + this.offset;
  16200. for (var j = 0; j < this.itemSize; j++) {
  16201. array.push(this.data.array[index + j]);
  16202. }
  16203. } // deinterleave data and save it as an ordinary buffer attribute for now
  16204. return {
  16205. itemSize: this.itemSize,
  16206. type: this.array.constructor.name,
  16207. array: array,
  16208. normalized: this.normalized
  16209. };
  16210. } else {
  16211. // save as true interlaved attribtue
  16212. if (data.interleavedBuffers === undefined) {
  16213. data.interleavedBuffers = {};
  16214. }
  16215. if (data.interleavedBuffers[this.data.uuid] === undefined) {
  16216. data.interleavedBuffers[this.data.uuid] = this.data.toJSON(data);
  16217. }
  16218. return {
  16219. isInterleavedBufferAttribute: true,
  16220. itemSize: this.itemSize,
  16221. data: this.data.uuid,
  16222. offset: this.offset,
  16223. normalized: this.normalized
  16224. };
  16225. }
  16226. }
  16227. });
  16228. /**
  16229. * parameters = {
  16230. * color: <hex>,
  16231. * map: new THREE.Texture( <Image> ),
  16232. * alphaMap: new THREE.Texture( <Image> ),
  16233. * rotation: <float>,
  16234. * sizeAttenuation: <bool>
  16235. * }
  16236. */
  16237. function SpriteMaterial(parameters) {
  16238. Material.call(this);
  16239. this.type = 'SpriteMaterial';
  16240. this.color = new Color(0xffffff);
  16241. this.map = null;
  16242. this.alphaMap = null;
  16243. this.rotation = 0;
  16244. this.sizeAttenuation = true;
  16245. this.transparent = true;
  16246. this.setValues(parameters);
  16247. }
  16248. SpriteMaterial.prototype = Object.create(Material.prototype);
  16249. SpriteMaterial.prototype.constructor = SpriteMaterial;
  16250. SpriteMaterial.prototype.isSpriteMaterial = true;
  16251. SpriteMaterial.prototype.copy = function (source) {
  16252. Material.prototype.copy.call(this, source);
  16253. this.color.copy(source.color);
  16254. this.map = source.map;
  16255. this.alphaMap = source.alphaMap;
  16256. this.rotation = source.rotation;
  16257. this.sizeAttenuation = source.sizeAttenuation;
  16258. return this;
  16259. };
  16260. var _geometry;
  16261. var _intersectPoint = new Vector3();
  16262. var _worldScale = new Vector3();
  16263. var _mvPosition = new Vector3();
  16264. var _alignedPosition = new Vector2();
  16265. var _rotatedPosition = new Vector2();
  16266. var _viewWorldMatrix = new Matrix4();
  16267. var _vA$1 = new Vector3();
  16268. var _vB$1 = new Vector3();
  16269. var _vC$1 = new Vector3();
  16270. var _uvA$1 = new Vector2();
  16271. var _uvB$1 = new Vector2();
  16272. var _uvC$1 = new Vector2();
  16273. function Sprite(material) {
  16274. Object3D.call(this);
  16275. this.type = 'Sprite';
  16276. if (_geometry === undefined) {
  16277. _geometry = new BufferGeometry();
  16278. 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]);
  16279. var interleavedBuffer = new InterleavedBuffer(float32Array, 5);
  16280. _geometry.setIndex([0, 1, 2, 0, 2, 3]);
  16281. _geometry.setAttribute('position', new InterleavedBufferAttribute(interleavedBuffer, 3, 0, false));
  16282. _geometry.setAttribute('uv', new InterleavedBufferAttribute(interleavedBuffer, 2, 3, false));
  16283. }
  16284. this.geometry = _geometry;
  16285. this.material = material !== undefined ? material : new SpriteMaterial();
  16286. this.center = new Vector2(0.5, 0.5);
  16287. }
  16288. Sprite.prototype = Object.assign(Object.create(Object3D.prototype), {
  16289. constructor: Sprite,
  16290. isSprite: true,
  16291. raycast: function raycast(raycaster, intersects) {
  16292. if (raycaster.camera === null) {
  16293. console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');
  16294. }
  16295. _worldScale.setFromMatrixScale(this.matrixWorld);
  16296. _viewWorldMatrix.copy(raycaster.camera.matrixWorld);
  16297. this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse, this.matrixWorld);
  16298. _mvPosition.setFromMatrixPosition(this.modelViewMatrix);
  16299. if (raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false) {
  16300. _worldScale.multiplyScalar(-_mvPosition.z);
  16301. }
  16302. var rotation = this.material.rotation;
  16303. var sin, cos;
  16304. if (rotation !== 0) {
  16305. cos = Math.cos(rotation);
  16306. sin = Math.sin(rotation);
  16307. }
  16308. var center = this.center;
  16309. transformVertex(_vA$1.set(-0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16310. transformVertex(_vB$1.set(0.5, -0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16311. transformVertex(_vC$1.set(0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16312. _uvA$1.set(0, 0);
  16313. _uvB$1.set(1, 0);
  16314. _uvC$1.set(1, 1); // check first triangle
  16315. var intersect = raycaster.ray.intersectTriangle(_vA$1, _vB$1, _vC$1, false, _intersectPoint);
  16316. if (intersect === null) {
  16317. // check second triangle
  16318. transformVertex(_vB$1.set(-0.5, 0.5, 0), _mvPosition, center, _worldScale, sin, cos);
  16319. _uvB$1.set(0, 1);
  16320. intersect = raycaster.ray.intersectTriangle(_vA$1, _vC$1, _vB$1, false, _intersectPoint);
  16321. if (intersect === null) {
  16322. return;
  16323. }
  16324. }
  16325. var distance = raycaster.ray.origin.distanceTo(_intersectPoint);
  16326. if (distance < raycaster.near || distance > raycaster.far) return;
  16327. intersects.push({
  16328. distance: distance,
  16329. point: _intersectPoint.clone(),
  16330. uv: Triangle.getUV(_intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()),
  16331. face: null,
  16332. object: this
  16333. });
  16334. },
  16335. copy: function copy(source) {
  16336. Object3D.prototype.copy.call(this, source);
  16337. if (source.center !== undefined) this.center.copy(source.center);
  16338. this.material = source.material;
  16339. return this;
  16340. }
  16341. });
  16342. function transformVertex(vertexPosition, mvPosition, center, scale, sin, cos) {
  16343. // compute position in camera space
  16344. _alignedPosition.subVectors(vertexPosition, center).addScalar(0.5).multiply(scale); // to check if rotation is not zero
  16345. if (sin !== undefined) {
  16346. _rotatedPosition.x = cos * _alignedPosition.x - sin * _alignedPosition.y;
  16347. _rotatedPosition.y = sin * _alignedPosition.x + cos * _alignedPosition.y;
  16348. } else {
  16349. _rotatedPosition.copy(_alignedPosition);
  16350. }
  16351. vertexPosition.copy(mvPosition);
  16352. vertexPosition.x += _rotatedPosition.x;
  16353. vertexPosition.y += _rotatedPosition.y; // transform to world space
  16354. vertexPosition.applyMatrix4(_viewWorldMatrix);
  16355. }
  16356. var _v1$4 = new Vector3();
  16357. var _v2$2 = new Vector3();
  16358. function LOD() {
  16359. Object3D.call(this);
  16360. this._currentLevel = 0;
  16361. this.type = 'LOD';
  16362. Object.defineProperties(this, {
  16363. levels: {
  16364. enumerable: true,
  16365. value: []
  16366. }
  16367. });
  16368. this.autoUpdate = true;
  16369. }
  16370. LOD.prototype = Object.assign(Object.create(Object3D.prototype), {
  16371. constructor: LOD,
  16372. isLOD: true,
  16373. copy: function copy(source) {
  16374. Object3D.prototype.copy.call(this, source, false);
  16375. var levels = source.levels;
  16376. for (var i = 0, l = levels.length; i < l; i++) {
  16377. var level = levels[i];
  16378. this.addLevel(level.object.clone(), level.distance);
  16379. }
  16380. this.autoUpdate = source.autoUpdate;
  16381. return this;
  16382. },
  16383. addLevel: function addLevel(object, distance) {
  16384. if (distance === void 0) {
  16385. distance = 0;
  16386. }
  16387. distance = Math.abs(distance);
  16388. var levels = this.levels;
  16389. var l;
  16390. for (l = 0; l < levels.length; l++) {
  16391. if (distance < levels[l].distance) {
  16392. break;
  16393. }
  16394. }
  16395. levels.splice(l, 0, {
  16396. distance: distance,
  16397. object: object
  16398. });
  16399. this.add(object);
  16400. return this;
  16401. },
  16402. getCurrentLevel: function getCurrentLevel() {
  16403. return this._currentLevel;
  16404. },
  16405. getObjectForDistance: function getObjectForDistance(distance) {
  16406. var levels = this.levels;
  16407. if (levels.length > 0) {
  16408. var i, l;
  16409. for (i = 1, l = levels.length; i < l; i++) {
  16410. if (distance < levels[i].distance) {
  16411. break;
  16412. }
  16413. }
  16414. return levels[i - 1].object;
  16415. }
  16416. return null;
  16417. },
  16418. raycast: function raycast(raycaster, intersects) {
  16419. var levels = this.levels;
  16420. if (levels.length > 0) {
  16421. _v1$4.setFromMatrixPosition(this.matrixWorld);
  16422. var distance = raycaster.ray.origin.distanceTo(_v1$4);
  16423. this.getObjectForDistance(distance).raycast(raycaster, intersects);
  16424. }
  16425. },
  16426. update: function update(camera) {
  16427. var levels = this.levels;
  16428. if (levels.length > 1) {
  16429. _v1$4.setFromMatrixPosition(camera.matrixWorld);
  16430. _v2$2.setFromMatrixPosition(this.matrixWorld);
  16431. var distance = _v1$4.distanceTo(_v2$2) / camera.zoom;
  16432. levels[0].object.visible = true;
  16433. var i, l;
  16434. for (i = 1, l = levels.length; i < l; i++) {
  16435. if (distance >= levels[i].distance) {
  16436. levels[i - 1].object.visible = false;
  16437. levels[i].object.visible = true;
  16438. } else {
  16439. break;
  16440. }
  16441. }
  16442. this._currentLevel = i - 1;
  16443. for (; i < l; i++) {
  16444. levels[i].object.visible = false;
  16445. }
  16446. }
  16447. },
  16448. toJSON: function toJSON(meta) {
  16449. var data = Object3D.prototype.toJSON.call(this, meta);
  16450. if (this.autoUpdate === false) data.object.autoUpdate = false;
  16451. data.object.levels = [];
  16452. var levels = this.levels;
  16453. for (var i = 0, l = levels.length; i < l; i++) {
  16454. var level = levels[i];
  16455. data.object.levels.push({
  16456. object: level.object.uuid,
  16457. distance: level.distance
  16458. });
  16459. }
  16460. return data;
  16461. }
  16462. });
  16463. var _basePosition = new Vector3();
  16464. var _skinIndex = new Vector4();
  16465. var _skinWeight = new Vector4();
  16466. var _vector$7 = new Vector3();
  16467. var _matrix$1 = new Matrix4();
  16468. function SkinnedMesh(geometry, material) {
  16469. if (geometry && geometry.isGeometry) {
  16470. console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16471. }
  16472. Mesh.call(this, geometry, material);
  16473. this.type = 'SkinnedMesh';
  16474. this.bindMode = 'attached';
  16475. this.bindMatrix = new Matrix4();
  16476. this.bindMatrixInverse = new Matrix4();
  16477. }
  16478. SkinnedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16479. constructor: SkinnedMesh,
  16480. isSkinnedMesh: true,
  16481. copy: function copy(source) {
  16482. Mesh.prototype.copy.call(this, source);
  16483. this.bindMode = source.bindMode;
  16484. this.bindMatrix.copy(source.bindMatrix);
  16485. this.bindMatrixInverse.copy(source.bindMatrixInverse);
  16486. this.skeleton = source.skeleton;
  16487. return this;
  16488. },
  16489. bind: function bind(skeleton, bindMatrix) {
  16490. this.skeleton = skeleton;
  16491. if (bindMatrix === undefined) {
  16492. this.updateMatrixWorld(true);
  16493. this.skeleton.calculateInverses();
  16494. bindMatrix = this.matrixWorld;
  16495. }
  16496. this.bindMatrix.copy(bindMatrix);
  16497. this.bindMatrixInverse.copy(bindMatrix).invert();
  16498. },
  16499. pose: function pose() {
  16500. this.skeleton.pose();
  16501. },
  16502. normalizeSkinWeights: function normalizeSkinWeights() {
  16503. var vector = new Vector4();
  16504. var skinWeight = this.geometry.attributes.skinWeight;
  16505. for (var i = 0, l = skinWeight.count; i < l; i++) {
  16506. vector.x = skinWeight.getX(i);
  16507. vector.y = skinWeight.getY(i);
  16508. vector.z = skinWeight.getZ(i);
  16509. vector.w = skinWeight.getW(i);
  16510. var scale = 1.0 / vector.manhattanLength();
  16511. if (scale !== Infinity) {
  16512. vector.multiplyScalar(scale);
  16513. } else {
  16514. vector.set(1, 0, 0, 0); // do something reasonable
  16515. }
  16516. skinWeight.setXYZW(i, vector.x, vector.y, vector.z, vector.w);
  16517. }
  16518. },
  16519. updateMatrixWorld: function updateMatrixWorld(force) {
  16520. Mesh.prototype.updateMatrixWorld.call(this, force);
  16521. if (this.bindMode === 'attached') {
  16522. this.bindMatrixInverse.copy(this.matrixWorld).invert();
  16523. } else if (this.bindMode === 'detached') {
  16524. this.bindMatrixInverse.copy(this.bindMatrix).invert();
  16525. } else {
  16526. console.warn('THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode);
  16527. }
  16528. },
  16529. boneTransform: function boneTransform(index, target) {
  16530. var skeleton = this.skeleton;
  16531. var geometry = this.geometry;
  16532. _skinIndex.fromBufferAttribute(geometry.attributes.skinIndex, index);
  16533. _skinWeight.fromBufferAttribute(geometry.attributes.skinWeight, index);
  16534. _basePosition.fromBufferAttribute(geometry.attributes.position, index).applyMatrix4(this.bindMatrix);
  16535. target.set(0, 0, 0);
  16536. for (var i = 0; i < 4; i++) {
  16537. var weight = _skinWeight.getComponent(i);
  16538. if (weight !== 0) {
  16539. var boneIndex = _skinIndex.getComponent(i);
  16540. _matrix$1.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld, skeleton.boneInverses[boneIndex]);
  16541. target.addScaledVector(_vector$7.copy(_basePosition).applyMatrix4(_matrix$1), weight);
  16542. }
  16543. }
  16544. return target.applyMatrix4(this.bindMatrixInverse);
  16545. }
  16546. });
  16547. function Bone() {
  16548. Object3D.call(this);
  16549. this.type = 'Bone';
  16550. }
  16551. Bone.prototype = Object.assign(Object.create(Object3D.prototype), {
  16552. constructor: Bone,
  16553. isBone: true
  16554. });
  16555. var _offsetMatrix = new Matrix4();
  16556. var _identityMatrix = new Matrix4();
  16557. function Skeleton(bones, boneInverses) {
  16558. if (bones === void 0) {
  16559. bones = [];
  16560. }
  16561. if (boneInverses === void 0) {
  16562. boneInverses = [];
  16563. }
  16564. this.uuid = MathUtils.generateUUID();
  16565. this.bones = bones.slice(0);
  16566. this.boneInverses = boneInverses;
  16567. this.boneMatrices = null;
  16568. this.boneTexture = null;
  16569. this.boneTextureSize = 0;
  16570. this.frame = -1;
  16571. this.init();
  16572. }
  16573. Object.assign(Skeleton.prototype, {
  16574. init: function init() {
  16575. var bones = this.bones;
  16576. var boneInverses = this.boneInverses;
  16577. this.boneMatrices = new Float32Array(bones.length * 16); // calculate inverse bone matrices if necessary
  16578. if (boneInverses.length === 0) {
  16579. this.calculateInverses();
  16580. } else {
  16581. // handle special case
  16582. if (bones.length !== boneInverses.length) {
  16583. console.warn('THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.');
  16584. this.boneInverses = [];
  16585. for (var i = 0, il = this.bones.length; i < il; i++) {
  16586. this.boneInverses.push(new Matrix4());
  16587. }
  16588. }
  16589. }
  16590. },
  16591. calculateInverses: function calculateInverses() {
  16592. this.boneInverses.length = 0;
  16593. for (var i = 0, il = this.bones.length; i < il; i++) {
  16594. var inverse = new Matrix4();
  16595. if (this.bones[i]) {
  16596. inverse.copy(this.bones[i].matrixWorld).invert();
  16597. }
  16598. this.boneInverses.push(inverse);
  16599. }
  16600. },
  16601. pose: function pose() {
  16602. // recover the bind-time world matrices
  16603. for (var i = 0, il = this.bones.length; i < il; i++) {
  16604. var bone = this.bones[i];
  16605. if (bone) {
  16606. bone.matrixWorld.copy(this.boneInverses[i]).invert();
  16607. }
  16608. } // compute the local matrices, positions, rotations and scales
  16609. for (var _i = 0, _il = this.bones.length; _i < _il; _i++) {
  16610. var _bone = this.bones[_i];
  16611. if (_bone) {
  16612. if (_bone.parent && _bone.parent.isBone) {
  16613. _bone.matrix.copy(_bone.parent.matrixWorld).invert();
  16614. _bone.matrix.multiply(_bone.matrixWorld);
  16615. } else {
  16616. _bone.matrix.copy(_bone.matrixWorld);
  16617. }
  16618. _bone.matrix.decompose(_bone.position, _bone.quaternion, _bone.scale);
  16619. }
  16620. }
  16621. },
  16622. update: function update() {
  16623. var bones = this.bones;
  16624. var boneInverses = this.boneInverses;
  16625. var boneMatrices = this.boneMatrices;
  16626. var boneTexture = this.boneTexture; // flatten bone matrices to array
  16627. for (var i = 0, il = bones.length; i < il; i++) {
  16628. // compute the offset between the current and the original transform
  16629. var matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
  16630. _offsetMatrix.multiplyMatrices(matrix, boneInverses[i]);
  16631. _offsetMatrix.toArray(boneMatrices, i * 16);
  16632. }
  16633. if (boneTexture !== null) {
  16634. boneTexture.needsUpdate = true;
  16635. }
  16636. },
  16637. clone: function clone() {
  16638. return new Skeleton(this.bones, this.boneInverses);
  16639. },
  16640. getBoneByName: function getBoneByName(name) {
  16641. for (var i = 0, il = this.bones.length; i < il; i++) {
  16642. var bone = this.bones[i];
  16643. if (bone.name === name) {
  16644. return bone;
  16645. }
  16646. }
  16647. return undefined;
  16648. },
  16649. dispose: function dispose() {
  16650. if (this.boneTexture !== null) {
  16651. this.boneTexture.dispose();
  16652. this.boneTexture = null;
  16653. }
  16654. },
  16655. fromJSON: function fromJSON(json, bones) {
  16656. this.uuid = json.uuid;
  16657. for (var i = 0, l = json.bones.length; i < l; i++) {
  16658. var uuid = json.bones[i];
  16659. var bone = bones[uuid];
  16660. if (bone === undefined) {
  16661. console.warn('THREE.Skeleton: No bone found with UUID:', uuid);
  16662. bone = new Bone();
  16663. }
  16664. this.bones.push(bone);
  16665. this.boneInverses.push(new Matrix4().fromArray(json.boneInverses[i]));
  16666. }
  16667. this.init();
  16668. return this;
  16669. },
  16670. toJSON: function toJSON() {
  16671. var data = {
  16672. metadata: {
  16673. version: 4.5,
  16674. type: 'Skeleton',
  16675. generator: 'Skeleton.toJSON'
  16676. },
  16677. bones: [],
  16678. boneInverses: []
  16679. };
  16680. data.uuid = this.uuid;
  16681. var bones = this.bones;
  16682. var boneInverses = this.boneInverses;
  16683. for (var i = 0, l = bones.length; i < l; i++) {
  16684. var bone = bones[i];
  16685. data.bones.push(bone.uuid);
  16686. var boneInverse = boneInverses[i];
  16687. data.boneInverses.push(boneInverse.toArray());
  16688. }
  16689. return data;
  16690. }
  16691. });
  16692. var _instanceLocalMatrix = new Matrix4();
  16693. var _instanceWorldMatrix = new Matrix4();
  16694. var _instanceIntersects = [];
  16695. var _mesh = new Mesh();
  16696. function InstancedMesh(geometry, material, count) {
  16697. Mesh.call(this, geometry, material);
  16698. this.instanceMatrix = new BufferAttribute(new Float32Array(count * 16), 16);
  16699. this.instanceColor = null;
  16700. this.count = count;
  16701. this.frustumCulled = false;
  16702. }
  16703. InstancedMesh.prototype = Object.assign(Object.create(Mesh.prototype), {
  16704. constructor: InstancedMesh,
  16705. isInstancedMesh: true,
  16706. copy: function copy(source) {
  16707. Mesh.prototype.copy.call(this, source);
  16708. this.instanceMatrix.copy(source.instanceMatrix);
  16709. if (source.instanceColor !== null) this.instanceColor = source.instanceColor.clone();
  16710. this.count = source.count;
  16711. return this;
  16712. },
  16713. getColorAt: function getColorAt(index, color) {
  16714. color.fromArray(this.instanceColor.array, index * 3);
  16715. },
  16716. getMatrixAt: function getMatrixAt(index, matrix) {
  16717. matrix.fromArray(this.instanceMatrix.array, index * 16);
  16718. },
  16719. raycast: function raycast(raycaster, intersects) {
  16720. var matrixWorld = this.matrixWorld;
  16721. var raycastTimes = this.count;
  16722. _mesh.geometry = this.geometry;
  16723. _mesh.material = this.material;
  16724. if (_mesh.material === undefined) return;
  16725. for (var instanceId = 0; instanceId < raycastTimes; instanceId++) {
  16726. // calculate the world matrix for each instance
  16727. this.getMatrixAt(instanceId, _instanceLocalMatrix);
  16728. _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix); // the mesh represents this single instance
  16729. _mesh.matrixWorld = _instanceWorldMatrix;
  16730. _mesh.raycast(raycaster, _instanceIntersects); // process the result of raycast
  16731. for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
  16732. var intersect = _instanceIntersects[i];
  16733. intersect.instanceId = instanceId;
  16734. intersect.object = this;
  16735. intersects.push(intersect);
  16736. }
  16737. _instanceIntersects.length = 0;
  16738. }
  16739. },
  16740. setColorAt: function setColorAt(index, color) {
  16741. if (this.instanceColor === null) {
  16742. this.instanceColor = new BufferAttribute(new Float32Array(this.count * 3), 3);
  16743. }
  16744. color.toArray(this.instanceColor.array, index * 3);
  16745. },
  16746. setMatrixAt: function setMatrixAt(index, matrix) {
  16747. matrix.toArray(this.instanceMatrix.array, index * 16);
  16748. },
  16749. updateMorphTargets: function updateMorphTargets() {},
  16750. dispose: function dispose() {
  16751. this.dispatchEvent({
  16752. type: 'dispose'
  16753. });
  16754. }
  16755. });
  16756. /**
  16757. * parameters = {
  16758. * color: <hex>,
  16759. * opacity: <float>,
  16760. *
  16761. * linewidth: <float>,
  16762. * linecap: "round",
  16763. * linejoin: "round"
  16764. * }
  16765. */
  16766. function LineBasicMaterial(parameters) {
  16767. Material.call(this);
  16768. this.type = 'LineBasicMaterial';
  16769. this.color = new Color(0xffffff);
  16770. this.linewidth = 1;
  16771. this.linecap = 'round';
  16772. this.linejoin = 'round';
  16773. this.morphTargets = false;
  16774. this.setValues(parameters);
  16775. }
  16776. LineBasicMaterial.prototype = Object.create(Material.prototype);
  16777. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  16778. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  16779. LineBasicMaterial.prototype.copy = function (source) {
  16780. Material.prototype.copy.call(this, source);
  16781. this.color.copy(source.color);
  16782. this.linewidth = source.linewidth;
  16783. this.linecap = source.linecap;
  16784. this.linejoin = source.linejoin;
  16785. this.morphTargets = source.morphTargets;
  16786. return this;
  16787. };
  16788. var _start = new Vector3();
  16789. var _end = new Vector3();
  16790. var _inverseMatrix$1 = new Matrix4();
  16791. var _ray$1 = new Ray();
  16792. var _sphere$2 = new Sphere();
  16793. function Line(geometry, material) {
  16794. if (geometry === void 0) {
  16795. geometry = new BufferGeometry();
  16796. }
  16797. if (material === void 0) {
  16798. material = new LineBasicMaterial();
  16799. }
  16800. Object3D.call(this);
  16801. this.type = 'Line';
  16802. this.geometry = geometry;
  16803. this.material = material;
  16804. this.updateMorphTargets();
  16805. }
  16806. Line.prototype = Object.assign(Object.create(Object3D.prototype), {
  16807. constructor: Line,
  16808. isLine: true,
  16809. copy: function copy(source) {
  16810. Object3D.prototype.copy.call(this, source);
  16811. this.material = source.material;
  16812. this.geometry = source.geometry;
  16813. return this;
  16814. },
  16815. computeLineDistances: function computeLineDistances() {
  16816. var geometry = this.geometry;
  16817. if (geometry.isBufferGeometry) {
  16818. // we assume non-indexed geometry
  16819. if (geometry.index === null) {
  16820. var positionAttribute = geometry.attributes.position;
  16821. var lineDistances = [0];
  16822. for (var i = 1, l = positionAttribute.count; i < l; i++) {
  16823. _start.fromBufferAttribute(positionAttribute, i - 1);
  16824. _end.fromBufferAttribute(positionAttribute, i);
  16825. lineDistances[i] = lineDistances[i - 1];
  16826. lineDistances[i] += _start.distanceTo(_end);
  16827. }
  16828. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16829. } else {
  16830. console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16831. }
  16832. } else if (geometry.isGeometry) {
  16833. console.error('THREE.Line.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16834. }
  16835. return this;
  16836. },
  16837. raycast: function raycast(raycaster, intersects) {
  16838. var geometry = this.geometry;
  16839. var matrixWorld = this.matrixWorld;
  16840. var threshold = raycaster.params.Line.threshold; // Checking boundingSphere distance to ray
  16841. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  16842. _sphere$2.copy(geometry.boundingSphere);
  16843. _sphere$2.applyMatrix4(matrixWorld);
  16844. _sphere$2.radius += threshold;
  16845. if (raycaster.ray.intersectsSphere(_sphere$2) === false) return; //
  16846. _inverseMatrix$1.copy(matrixWorld).invert();
  16847. _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);
  16848. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  16849. var localThresholdSq = localThreshold * localThreshold;
  16850. var vStart = new Vector3();
  16851. var vEnd = new Vector3();
  16852. var interSegment = new Vector3();
  16853. var interRay = new Vector3();
  16854. var step = this.isLineSegments ? 2 : 1;
  16855. if (geometry.isBufferGeometry) {
  16856. var index = geometry.index;
  16857. var attributes = geometry.attributes;
  16858. var positionAttribute = attributes.position;
  16859. if (index !== null) {
  16860. var indices = index.array;
  16861. for (var i = 0, l = indices.length - 1; i < l; i += step) {
  16862. var a = indices[i];
  16863. var b = indices[i + 1];
  16864. vStart.fromBufferAttribute(positionAttribute, a);
  16865. vEnd.fromBufferAttribute(positionAttribute, b);
  16866. var distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16867. if (distSq > localThresholdSq) continue;
  16868. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16869. var distance = raycaster.ray.origin.distanceTo(interRay);
  16870. if (distance < raycaster.near || distance > raycaster.far) continue;
  16871. intersects.push({
  16872. distance: distance,
  16873. // What do we want? intersection point on the ray or on the segment??
  16874. // point: raycaster.ray.at( distance ),
  16875. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16876. index: i,
  16877. face: null,
  16878. faceIndex: null,
  16879. object: this
  16880. });
  16881. }
  16882. } else {
  16883. for (var _i = 0, _l = positionAttribute.count - 1; _i < _l; _i += step) {
  16884. vStart.fromBufferAttribute(positionAttribute, _i);
  16885. vEnd.fromBufferAttribute(positionAttribute, _i + 1);
  16886. var _distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment);
  16887. if (_distSq > localThresholdSq) continue;
  16888. interRay.applyMatrix4(this.matrixWorld); //Move back to world space for distance calculation
  16889. var _distance = raycaster.ray.origin.distanceTo(interRay);
  16890. if (_distance < raycaster.near || _distance > raycaster.far) continue;
  16891. intersects.push({
  16892. distance: _distance,
  16893. // What do we want? intersection point on the ray or on the segment??
  16894. // point: raycaster.ray.at( distance ),
  16895. point: interSegment.clone().applyMatrix4(this.matrixWorld),
  16896. index: _i,
  16897. face: null,
  16898. faceIndex: null,
  16899. object: this
  16900. });
  16901. }
  16902. }
  16903. } else if (geometry.isGeometry) {
  16904. console.error('THREE.Line.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16905. }
  16906. },
  16907. updateMorphTargets: function updateMorphTargets() {
  16908. var geometry = this.geometry;
  16909. if (geometry.isBufferGeometry) {
  16910. var morphAttributes = geometry.morphAttributes;
  16911. var keys = Object.keys(morphAttributes);
  16912. if (keys.length > 0) {
  16913. var morphAttribute = morphAttributes[keys[0]];
  16914. if (morphAttribute !== undefined) {
  16915. this.morphTargetInfluences = [];
  16916. this.morphTargetDictionary = {};
  16917. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  16918. var name = morphAttribute[m].name || String(m);
  16919. this.morphTargetInfluences.push(0);
  16920. this.morphTargetDictionary[name] = m;
  16921. }
  16922. }
  16923. }
  16924. } else {
  16925. var morphTargets = geometry.morphTargets;
  16926. if (morphTargets !== undefined && morphTargets.length > 0) {
  16927. console.error('THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  16928. }
  16929. }
  16930. }
  16931. });
  16932. var _start$1 = new Vector3();
  16933. var _end$1 = new Vector3();
  16934. function LineSegments(geometry, material) {
  16935. Line.call(this, geometry, material);
  16936. this.type = 'LineSegments';
  16937. }
  16938. LineSegments.prototype = Object.assign(Object.create(Line.prototype), {
  16939. constructor: LineSegments,
  16940. isLineSegments: true,
  16941. computeLineDistances: function computeLineDistances() {
  16942. var geometry = this.geometry;
  16943. if (geometry.isBufferGeometry) {
  16944. // we assume non-indexed geometry
  16945. if (geometry.index === null) {
  16946. var positionAttribute = geometry.attributes.position;
  16947. var lineDistances = [];
  16948. for (var i = 0, l = positionAttribute.count; i < l; i += 2) {
  16949. _start$1.fromBufferAttribute(positionAttribute, i);
  16950. _end$1.fromBufferAttribute(positionAttribute, i + 1);
  16951. lineDistances[i] = i === 0 ? 0 : lineDistances[i - 1];
  16952. lineDistances[i + 1] = lineDistances[i] + _start$1.distanceTo(_end$1);
  16953. }
  16954. geometry.setAttribute('lineDistance', new Float32BufferAttribute(lineDistances, 1));
  16955. } else {
  16956. console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');
  16957. }
  16958. } else if (geometry.isGeometry) {
  16959. console.error('THREE.LineSegments.computeLineDistances() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  16960. }
  16961. return this;
  16962. }
  16963. });
  16964. function LineLoop(geometry, material) {
  16965. Line.call(this, geometry, material);
  16966. this.type = 'LineLoop';
  16967. }
  16968. LineLoop.prototype = Object.assign(Object.create(Line.prototype), {
  16969. constructor: LineLoop,
  16970. isLineLoop: true
  16971. });
  16972. /**
  16973. * parameters = {
  16974. * color: <hex>,
  16975. * opacity: <float>,
  16976. * map: new THREE.Texture( <Image> ),
  16977. * alphaMap: new THREE.Texture( <Image> ),
  16978. *
  16979. * size: <float>,
  16980. * sizeAttenuation: <bool>
  16981. *
  16982. * morphTargets: <bool>
  16983. * }
  16984. */
  16985. function PointsMaterial(parameters) {
  16986. Material.call(this);
  16987. this.type = 'PointsMaterial';
  16988. this.color = new Color(0xffffff);
  16989. this.map = null;
  16990. this.alphaMap = null;
  16991. this.size = 1;
  16992. this.sizeAttenuation = true;
  16993. this.morphTargets = false;
  16994. this.setValues(parameters);
  16995. }
  16996. PointsMaterial.prototype = Object.create(Material.prototype);
  16997. PointsMaterial.prototype.constructor = PointsMaterial;
  16998. PointsMaterial.prototype.isPointsMaterial = true;
  16999. PointsMaterial.prototype.copy = function (source) {
  17000. Material.prototype.copy.call(this, source);
  17001. this.color.copy(source.color);
  17002. this.map = source.map;
  17003. this.alphaMap = source.alphaMap;
  17004. this.size = source.size;
  17005. this.sizeAttenuation = source.sizeAttenuation;
  17006. this.morphTargets = source.morphTargets;
  17007. return this;
  17008. };
  17009. var _inverseMatrix$2 = new Matrix4();
  17010. var _ray$2 = new Ray();
  17011. var _sphere$3 = new Sphere();
  17012. var _position$1 = new Vector3();
  17013. function Points(geometry, material) {
  17014. if (geometry === void 0) {
  17015. geometry = new BufferGeometry();
  17016. }
  17017. if (material === void 0) {
  17018. material = new PointsMaterial();
  17019. }
  17020. Object3D.call(this);
  17021. this.type = 'Points';
  17022. this.geometry = geometry;
  17023. this.material = material;
  17024. this.updateMorphTargets();
  17025. }
  17026. Points.prototype = Object.assign(Object.create(Object3D.prototype), {
  17027. constructor: Points,
  17028. isPoints: true,
  17029. copy: function copy(source) {
  17030. Object3D.prototype.copy.call(this, source);
  17031. this.material = source.material;
  17032. this.geometry = source.geometry;
  17033. return this;
  17034. },
  17035. raycast: function raycast(raycaster, intersects) {
  17036. var geometry = this.geometry;
  17037. var matrixWorld = this.matrixWorld;
  17038. var threshold = raycaster.params.Points.threshold; // Checking boundingSphere distance to ray
  17039. if (geometry.boundingSphere === null) geometry.computeBoundingSphere();
  17040. _sphere$3.copy(geometry.boundingSphere);
  17041. _sphere$3.applyMatrix4(matrixWorld);
  17042. _sphere$3.radius += threshold;
  17043. if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; //
  17044. _inverseMatrix$2.copy(matrixWorld).invert();
  17045. _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);
  17046. var localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
  17047. var localThresholdSq = localThreshold * localThreshold;
  17048. if (geometry.isBufferGeometry) {
  17049. var index = geometry.index;
  17050. var attributes = geometry.attributes;
  17051. var positionAttribute = attributes.position;
  17052. if (index !== null) {
  17053. var indices = index.array;
  17054. for (var i = 0, il = indices.length; i < il; i++) {
  17055. var a = indices[i];
  17056. _position$1.fromBufferAttribute(positionAttribute, a);
  17057. testPoint(_position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17058. }
  17059. } else {
  17060. for (var _i = 0, l = positionAttribute.count; _i < l; _i++) {
  17061. _position$1.fromBufferAttribute(positionAttribute, _i);
  17062. testPoint(_position$1, _i, localThresholdSq, matrixWorld, raycaster, intersects, this);
  17063. }
  17064. }
  17065. } else {
  17066. console.error('THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17067. }
  17068. },
  17069. updateMorphTargets: function updateMorphTargets() {
  17070. var geometry = this.geometry;
  17071. if (geometry.isBufferGeometry) {
  17072. var morphAttributes = geometry.morphAttributes;
  17073. var keys = Object.keys(morphAttributes);
  17074. if (keys.length > 0) {
  17075. var morphAttribute = morphAttributes[keys[0]];
  17076. if (morphAttribute !== undefined) {
  17077. this.morphTargetInfluences = [];
  17078. this.morphTargetDictionary = {};
  17079. for (var m = 0, ml = morphAttribute.length; m < ml; m++) {
  17080. var name = morphAttribute[m].name || String(m);
  17081. this.morphTargetInfluences.push(0);
  17082. this.morphTargetDictionary[name] = m;
  17083. }
  17084. }
  17085. }
  17086. } else {
  17087. var morphTargets = geometry.morphTargets;
  17088. if (morphTargets !== undefined && morphTargets.length > 0) {
  17089. console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');
  17090. }
  17091. }
  17092. }
  17093. });
  17094. function testPoint(point, index, localThresholdSq, matrixWorld, raycaster, intersects, object) {
  17095. var rayPointDistanceSq = _ray$2.distanceSqToPoint(point);
  17096. if (rayPointDistanceSq < localThresholdSq) {
  17097. var intersectPoint = new Vector3();
  17098. _ray$2.closestPointToPoint(point, intersectPoint);
  17099. intersectPoint.applyMatrix4(matrixWorld);
  17100. var distance = raycaster.ray.origin.distanceTo(intersectPoint);
  17101. if (distance < raycaster.near || distance > raycaster.far) return;
  17102. intersects.push({
  17103. distance: distance,
  17104. distanceToRay: Math.sqrt(rayPointDistanceSq),
  17105. point: intersectPoint,
  17106. index: index,
  17107. face: null,
  17108. object: object
  17109. });
  17110. }
  17111. }
  17112. function VideoTexture(video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17113. Texture.call(this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17114. this.format = format !== undefined ? format : RGBFormat;
  17115. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  17116. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  17117. this.generateMipmaps = false;
  17118. var scope = this;
  17119. function updateVideo() {
  17120. scope.needsUpdate = true;
  17121. video.requestVideoFrameCallback(updateVideo);
  17122. }
  17123. if ('requestVideoFrameCallback' in video) {
  17124. video.requestVideoFrameCallback(updateVideo);
  17125. }
  17126. }
  17127. VideoTexture.prototype = Object.assign(Object.create(Texture.prototype), {
  17128. constructor: VideoTexture,
  17129. clone: function clone() {
  17130. return new this.constructor(this.image).copy(this);
  17131. },
  17132. isVideoTexture: true,
  17133. update: function update() {
  17134. var video = this.image;
  17135. var hasVideoFrameCallback = ('requestVideoFrameCallback' in video);
  17136. if (hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA) {
  17137. this.needsUpdate = true;
  17138. }
  17139. }
  17140. });
  17141. function CompressedTexture(mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding) {
  17142. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding);
  17143. this.image = {
  17144. width: width,
  17145. height: height
  17146. };
  17147. this.mipmaps = mipmaps; // no flipping for cube textures
  17148. // (also flipping doesn't work for compressed textures )
  17149. this.flipY = false; // can't generate mipmaps for compressed textures
  17150. // mips must be embedded in DDS files
  17151. this.generateMipmaps = false;
  17152. }
  17153. CompressedTexture.prototype = Object.create(Texture.prototype);
  17154. CompressedTexture.prototype.constructor = CompressedTexture;
  17155. CompressedTexture.prototype.isCompressedTexture = true;
  17156. function CanvasTexture(canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy) {
  17157. Texture.call(this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17158. this.needsUpdate = true;
  17159. }
  17160. CanvasTexture.prototype = Object.create(Texture.prototype);
  17161. CanvasTexture.prototype.constructor = CanvasTexture;
  17162. CanvasTexture.prototype.isCanvasTexture = true;
  17163. function DepthTexture(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format) {
  17164. format = format !== undefined ? format : DepthFormat;
  17165. if (format !== DepthFormat && format !== DepthStencilFormat) {
  17166. throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');
  17167. }
  17168. if (type === undefined && format === DepthFormat) type = UnsignedShortType;
  17169. if (type === undefined && format === DepthStencilFormat) type = UnsignedInt248Type;
  17170. Texture.call(this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy);
  17171. this.image = {
  17172. width: width,
  17173. height: height
  17174. };
  17175. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  17176. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  17177. this.flipY = false;
  17178. this.generateMipmaps = false;
  17179. }
  17180. DepthTexture.prototype = Object.create(Texture.prototype);
  17181. DepthTexture.prototype.constructor = DepthTexture;
  17182. DepthTexture.prototype.isDepthTexture = true;
  17183. var CircleGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17184. _inheritsLoose(CircleGeometry, _BufferGeometry);
  17185. function CircleGeometry(radius, segments, thetaStart, thetaLength) {
  17186. var _this;
  17187. if (radius === void 0) {
  17188. radius = 1;
  17189. }
  17190. if (segments === void 0) {
  17191. segments = 8;
  17192. }
  17193. if (thetaStart === void 0) {
  17194. thetaStart = 0;
  17195. }
  17196. if (thetaLength === void 0) {
  17197. thetaLength = Math.PI * 2;
  17198. }
  17199. _this = _BufferGeometry.call(this) || this;
  17200. _this.type = 'CircleGeometry';
  17201. _this.parameters = {
  17202. radius: radius,
  17203. segments: segments,
  17204. thetaStart: thetaStart,
  17205. thetaLength: thetaLength
  17206. };
  17207. segments = Math.max(3, segments); // buffers
  17208. var indices = [];
  17209. var vertices = [];
  17210. var normals = [];
  17211. var uvs = []; // helper variables
  17212. var vertex = new Vector3();
  17213. var uv = new Vector2(); // center point
  17214. vertices.push(0, 0, 0);
  17215. normals.push(0, 0, 1);
  17216. uvs.push(0.5, 0.5);
  17217. for (var s = 0, i = 3; s <= segments; s++, i += 3) {
  17218. var segment = thetaStart + s / segments * thetaLength; // vertex
  17219. vertex.x = radius * Math.cos(segment);
  17220. vertex.y = radius * Math.sin(segment);
  17221. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17222. normals.push(0, 0, 1); // uvs
  17223. uv.x = (vertices[i] / radius + 1) / 2;
  17224. uv.y = (vertices[i + 1] / radius + 1) / 2;
  17225. uvs.push(uv.x, uv.y);
  17226. } // indices
  17227. for (var _i = 1; _i <= segments; _i++) {
  17228. indices.push(_i, _i + 1, 0);
  17229. } // build geometry
  17230. _this.setIndex(indices);
  17231. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17232. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17233. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17234. return _this;
  17235. }
  17236. return CircleGeometry;
  17237. }(BufferGeometry);
  17238. var CylinderGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17239. _inheritsLoose(CylinderGeometry, _BufferGeometry);
  17240. function CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17241. var _this;
  17242. if (radiusTop === void 0) {
  17243. radiusTop = 1;
  17244. }
  17245. if (radiusBottom === void 0) {
  17246. radiusBottom = 1;
  17247. }
  17248. if (height === void 0) {
  17249. height = 1;
  17250. }
  17251. if (radialSegments === void 0) {
  17252. radialSegments = 8;
  17253. }
  17254. if (heightSegments === void 0) {
  17255. heightSegments = 1;
  17256. }
  17257. if (openEnded === void 0) {
  17258. openEnded = false;
  17259. }
  17260. if (thetaStart === void 0) {
  17261. thetaStart = 0;
  17262. }
  17263. if (thetaLength === void 0) {
  17264. thetaLength = Math.PI * 2;
  17265. }
  17266. _this = _BufferGeometry.call(this) || this;
  17267. _this.type = 'CylinderGeometry';
  17268. _this.parameters = {
  17269. radiusTop: radiusTop,
  17270. radiusBottom: radiusBottom,
  17271. height: height,
  17272. radialSegments: radialSegments,
  17273. heightSegments: heightSegments,
  17274. openEnded: openEnded,
  17275. thetaStart: thetaStart,
  17276. thetaLength: thetaLength
  17277. };
  17278. var scope = _assertThisInitialized(_this);
  17279. radialSegments = Math.floor(radialSegments);
  17280. heightSegments = Math.floor(heightSegments); // buffers
  17281. var indices = [];
  17282. var vertices = [];
  17283. var normals = [];
  17284. var uvs = []; // helper variables
  17285. var index = 0;
  17286. var indexArray = [];
  17287. var halfHeight = height / 2;
  17288. var groupStart = 0; // generate geometry
  17289. generateTorso();
  17290. if (openEnded === false) {
  17291. if (radiusTop > 0) generateCap(true);
  17292. if (radiusBottom > 0) generateCap(false);
  17293. } // build geometry
  17294. _this.setIndex(indices);
  17295. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17296. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  17297. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  17298. function generateTorso() {
  17299. var normal = new Vector3();
  17300. var vertex = new Vector3();
  17301. var groupCount = 0; // this will be used to calculate the normal
  17302. var slope = (radiusBottom - radiusTop) / height; // generate vertices, normals and uvs
  17303. for (var y = 0; y <= heightSegments; y++) {
  17304. var indexRow = [];
  17305. var v = y / heightSegments; // calculate the radius of the current row
  17306. var radius = v * (radiusBottom - radiusTop) + radiusTop;
  17307. for (var x = 0; x <= radialSegments; x++) {
  17308. var u = x / radialSegments;
  17309. var theta = u * thetaLength + thetaStart;
  17310. var sinTheta = Math.sin(theta);
  17311. var cosTheta = Math.cos(theta); // vertex
  17312. vertex.x = radius * sinTheta;
  17313. vertex.y = -v * height + halfHeight;
  17314. vertex.z = radius * cosTheta;
  17315. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17316. normal.set(sinTheta, slope, cosTheta).normalize();
  17317. normals.push(normal.x, normal.y, normal.z); // uv
  17318. uvs.push(u, 1 - v); // save index of vertex in respective row
  17319. indexRow.push(index++);
  17320. } // now save vertices of the row in our index array
  17321. indexArray.push(indexRow);
  17322. } // generate indices
  17323. for (var _x = 0; _x < radialSegments; _x++) {
  17324. for (var _y = 0; _y < heightSegments; _y++) {
  17325. // we use the index array to access the correct indices
  17326. var a = indexArray[_y][_x];
  17327. var b = indexArray[_y + 1][_x];
  17328. var c = indexArray[_y + 1][_x + 1];
  17329. var d = indexArray[_y][_x + 1]; // faces
  17330. indices.push(a, b, d);
  17331. indices.push(b, c, d); // update group counter
  17332. groupCount += 6;
  17333. }
  17334. } // add a group to the geometry. this will ensure multi material support
  17335. scope.addGroup(groupStart, groupCount, 0); // calculate new start value for groups
  17336. groupStart += groupCount;
  17337. }
  17338. function generateCap(top) {
  17339. // save the index of the first center vertex
  17340. var centerIndexStart = index;
  17341. var uv = new Vector2();
  17342. var vertex = new Vector3();
  17343. var groupCount = 0;
  17344. var radius = top === true ? radiusTop : radiusBottom;
  17345. var sign = top === true ? 1 : -1; // first we generate the center vertex data of the cap.
  17346. // because the geometry needs one set of uvs per face,
  17347. // we must generate a center vertex per face/segment
  17348. for (var x = 1; x <= radialSegments; x++) {
  17349. // vertex
  17350. vertices.push(0, halfHeight * sign, 0); // normal
  17351. normals.push(0, sign, 0); // uv
  17352. uvs.push(0.5, 0.5); // increase index
  17353. index++;
  17354. } // save the index of the last center vertex
  17355. var centerIndexEnd = index; // now we generate the surrounding vertices, normals and uvs
  17356. for (var _x2 = 0; _x2 <= radialSegments; _x2++) {
  17357. var u = _x2 / radialSegments;
  17358. var theta = u * thetaLength + thetaStart;
  17359. var cosTheta = Math.cos(theta);
  17360. var sinTheta = Math.sin(theta); // vertex
  17361. vertex.x = radius * sinTheta;
  17362. vertex.y = halfHeight * sign;
  17363. vertex.z = radius * cosTheta;
  17364. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  17365. normals.push(0, sign, 0); // uv
  17366. uv.x = cosTheta * 0.5 + 0.5;
  17367. uv.y = sinTheta * 0.5 * sign + 0.5;
  17368. uvs.push(uv.x, uv.y); // increase index
  17369. index++;
  17370. } // generate indices
  17371. for (var _x3 = 0; _x3 < radialSegments; _x3++) {
  17372. var c = centerIndexStart + _x3;
  17373. var i = centerIndexEnd + _x3;
  17374. if (top === true) {
  17375. // face top
  17376. indices.push(i, i + 1, c);
  17377. } else {
  17378. // face bottom
  17379. indices.push(i + 1, i, c);
  17380. }
  17381. groupCount += 3;
  17382. } // add a group to the geometry. this will ensure multi material support
  17383. scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); // calculate new start value for groups
  17384. groupStart += groupCount;
  17385. }
  17386. return _this;
  17387. }
  17388. return CylinderGeometry;
  17389. }(BufferGeometry);
  17390. var ConeGeometry = /*#__PURE__*/function (_CylinderGeometry) {
  17391. _inheritsLoose(ConeGeometry, _CylinderGeometry);
  17392. function ConeGeometry(radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) {
  17393. var _this;
  17394. if (radius === void 0) {
  17395. radius = 1;
  17396. }
  17397. if (height === void 0) {
  17398. height = 1;
  17399. }
  17400. if (radialSegments === void 0) {
  17401. radialSegments = 8;
  17402. }
  17403. if (heightSegments === void 0) {
  17404. heightSegments = 1;
  17405. }
  17406. if (openEnded === void 0) {
  17407. openEnded = false;
  17408. }
  17409. if (thetaStart === void 0) {
  17410. thetaStart = 0;
  17411. }
  17412. if (thetaLength === void 0) {
  17413. thetaLength = Math.PI * 2;
  17414. }
  17415. _this = _CylinderGeometry.call(this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength) || this;
  17416. _this.type = 'ConeGeometry';
  17417. _this.parameters = {
  17418. radius: radius,
  17419. height: height,
  17420. radialSegments: radialSegments,
  17421. heightSegments: heightSegments,
  17422. openEnded: openEnded,
  17423. thetaStart: thetaStart,
  17424. thetaLength: thetaLength
  17425. };
  17426. return _this;
  17427. }
  17428. return ConeGeometry;
  17429. }(CylinderGeometry);
  17430. var PolyhedronGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17431. _inheritsLoose(PolyhedronGeometry, _BufferGeometry);
  17432. function PolyhedronGeometry(vertices, indices, radius, detail) {
  17433. var _this;
  17434. if (radius === void 0) {
  17435. radius = 1;
  17436. }
  17437. if (detail === void 0) {
  17438. detail = 0;
  17439. }
  17440. _this = _BufferGeometry.call(this) || this;
  17441. _this.type = 'PolyhedronGeometry';
  17442. _this.parameters = {
  17443. vertices: vertices,
  17444. indices: indices,
  17445. radius: radius,
  17446. detail: detail
  17447. }; // default buffer data
  17448. var vertexBuffer = [];
  17449. var uvBuffer = []; // the subdivision creates the vertex buffer data
  17450. subdivide(detail); // all vertices should lie on a conceptual sphere with a given radius
  17451. applyRadius(radius); // finally, create the uv data
  17452. generateUVs(); // build non-indexed geometry
  17453. _this.setAttribute('position', new Float32BufferAttribute(vertexBuffer, 3));
  17454. _this.setAttribute('normal', new Float32BufferAttribute(vertexBuffer.slice(), 3));
  17455. _this.setAttribute('uv', new Float32BufferAttribute(uvBuffer, 2));
  17456. if (detail === 0) {
  17457. _this.computeVertexNormals(); // flat normals
  17458. } else {
  17459. _this.normalizeNormals(); // smooth normals
  17460. } // helper functions
  17461. function subdivide(detail) {
  17462. var a = new Vector3();
  17463. var b = new Vector3();
  17464. var c = new Vector3(); // iterate over all faces and apply a subdivison with the given detail value
  17465. for (var i = 0; i < indices.length; i += 3) {
  17466. // get the vertices of the face
  17467. getVertexByIndex(indices[i + 0], a);
  17468. getVertexByIndex(indices[i + 1], b);
  17469. getVertexByIndex(indices[i + 2], c); // perform subdivision
  17470. subdivideFace(a, b, c, detail);
  17471. }
  17472. }
  17473. function subdivideFace(a, b, c, detail) {
  17474. var cols = detail + 1; // we use this multidimensional array as a data structure for creating the subdivision
  17475. var v = []; // construct all of the vertices for this subdivision
  17476. for (var i = 0; i <= cols; i++) {
  17477. v[i] = [];
  17478. var aj = a.clone().lerp(c, i / cols);
  17479. var bj = b.clone().lerp(c, i / cols);
  17480. var rows = cols - i;
  17481. for (var j = 0; j <= rows; j++) {
  17482. if (j === 0 && i === cols) {
  17483. v[i][j] = aj;
  17484. } else {
  17485. v[i][j] = aj.clone().lerp(bj, j / rows);
  17486. }
  17487. }
  17488. } // construct all of the faces
  17489. for (var _i = 0; _i < cols; _i++) {
  17490. for (var _j = 0; _j < 2 * (cols - _i) - 1; _j++) {
  17491. var k = Math.floor(_j / 2);
  17492. if (_j % 2 === 0) {
  17493. pushVertex(v[_i][k + 1]);
  17494. pushVertex(v[_i + 1][k]);
  17495. pushVertex(v[_i][k]);
  17496. } else {
  17497. pushVertex(v[_i][k + 1]);
  17498. pushVertex(v[_i + 1][k + 1]);
  17499. pushVertex(v[_i + 1][k]);
  17500. }
  17501. }
  17502. }
  17503. }
  17504. function applyRadius(radius) {
  17505. var vertex = new Vector3(); // iterate over the entire buffer and apply the radius to each vertex
  17506. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17507. vertex.x = vertexBuffer[i + 0];
  17508. vertex.y = vertexBuffer[i + 1];
  17509. vertex.z = vertexBuffer[i + 2];
  17510. vertex.normalize().multiplyScalar(radius);
  17511. vertexBuffer[i + 0] = vertex.x;
  17512. vertexBuffer[i + 1] = vertex.y;
  17513. vertexBuffer[i + 2] = vertex.z;
  17514. }
  17515. }
  17516. function generateUVs() {
  17517. var vertex = new Vector3();
  17518. for (var i = 0; i < vertexBuffer.length; i += 3) {
  17519. vertex.x = vertexBuffer[i + 0];
  17520. vertex.y = vertexBuffer[i + 1];
  17521. vertex.z = vertexBuffer[i + 2];
  17522. var u = azimuth(vertex) / 2 / Math.PI + 0.5;
  17523. var v = inclination(vertex) / Math.PI + 0.5;
  17524. uvBuffer.push(u, 1 - v);
  17525. }
  17526. correctUVs();
  17527. correctSeam();
  17528. }
  17529. function correctSeam() {
  17530. // handle case when face straddles the seam, see #3269
  17531. for (var i = 0; i < uvBuffer.length; i += 6) {
  17532. // uv data of a single face
  17533. var x0 = uvBuffer[i + 0];
  17534. var x1 = uvBuffer[i + 2];
  17535. var x2 = uvBuffer[i + 4];
  17536. var max = Math.max(x0, x1, x2);
  17537. var min = Math.min(x0, x1, x2); // 0.9 is somewhat arbitrary
  17538. if (max > 0.9 && min < 0.1) {
  17539. if (x0 < 0.2) uvBuffer[i + 0] += 1;
  17540. if (x1 < 0.2) uvBuffer[i + 2] += 1;
  17541. if (x2 < 0.2) uvBuffer[i + 4] += 1;
  17542. }
  17543. }
  17544. }
  17545. function pushVertex(vertex) {
  17546. vertexBuffer.push(vertex.x, vertex.y, vertex.z);
  17547. }
  17548. function getVertexByIndex(index, vertex) {
  17549. var stride = index * 3;
  17550. vertex.x = vertices[stride + 0];
  17551. vertex.y = vertices[stride + 1];
  17552. vertex.z = vertices[stride + 2];
  17553. }
  17554. function correctUVs() {
  17555. var a = new Vector3();
  17556. var b = new Vector3();
  17557. var c = new Vector3();
  17558. var centroid = new Vector3();
  17559. var uvA = new Vector2();
  17560. var uvB = new Vector2();
  17561. var uvC = new Vector2();
  17562. for (var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6) {
  17563. a.set(vertexBuffer[i + 0], vertexBuffer[i + 1], vertexBuffer[i + 2]);
  17564. b.set(vertexBuffer[i + 3], vertexBuffer[i + 4], vertexBuffer[i + 5]);
  17565. c.set(vertexBuffer[i + 6], vertexBuffer[i + 7], vertexBuffer[i + 8]);
  17566. uvA.set(uvBuffer[j + 0], uvBuffer[j + 1]);
  17567. uvB.set(uvBuffer[j + 2], uvBuffer[j + 3]);
  17568. uvC.set(uvBuffer[j + 4], uvBuffer[j + 5]);
  17569. centroid.copy(a).add(b).add(c).divideScalar(3);
  17570. var azi = azimuth(centroid);
  17571. correctUV(uvA, j + 0, a, azi);
  17572. correctUV(uvB, j + 2, b, azi);
  17573. correctUV(uvC, j + 4, c, azi);
  17574. }
  17575. }
  17576. function correctUV(uv, stride, vector, azimuth) {
  17577. if (azimuth < 0 && uv.x === 1) {
  17578. uvBuffer[stride] = uv.x - 1;
  17579. }
  17580. if (vector.x === 0 && vector.z === 0) {
  17581. uvBuffer[stride] = azimuth / 2 / Math.PI + 0.5;
  17582. }
  17583. } // Angle around the Y axis, counter-clockwise when looking from above.
  17584. function azimuth(vector) {
  17585. return Math.atan2(vector.z, -vector.x);
  17586. } // Angle above the XZ plane.
  17587. function inclination(vector) {
  17588. return Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z));
  17589. }
  17590. return _this;
  17591. }
  17592. return PolyhedronGeometry;
  17593. }(BufferGeometry);
  17594. var DodecahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  17595. _inheritsLoose(DodecahedronGeometry, _PolyhedronGeometry);
  17596. function DodecahedronGeometry(radius, detail) {
  17597. var _this;
  17598. if (radius === void 0) {
  17599. radius = 1;
  17600. }
  17601. if (detail === void 0) {
  17602. detail = 0;
  17603. }
  17604. var t = (1 + Math.sqrt(5)) / 2;
  17605. var r = 1 / t;
  17606. var vertices = [// (±1, ±1, ±1)
  17607. -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/φ, ±φ)
  17608. 0, -r, -t, 0, -r, t, 0, r, -t, 0, r, t, // (±1/φ, ±φ, 0)
  17609. -r, -t, 0, -r, t, 0, r, -t, 0, r, t, 0, // (±φ, 0, ±1/φ)
  17610. -t, 0, -r, t, 0, -r, -t, 0, r, t, 0, r];
  17611. 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];
  17612. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  17613. _this.type = 'DodecahedronGeometry';
  17614. _this.parameters = {
  17615. radius: radius,
  17616. detail: detail
  17617. };
  17618. return _this;
  17619. }
  17620. return DodecahedronGeometry;
  17621. }(PolyhedronGeometry);
  17622. var _v0$2 = new Vector3();
  17623. var _v1$5 = new Vector3();
  17624. var _normal$1 = new Vector3();
  17625. var _triangle = new Triangle();
  17626. var EdgesGeometry = /*#__PURE__*/function (_BufferGeometry) {
  17627. _inheritsLoose(EdgesGeometry, _BufferGeometry);
  17628. function EdgesGeometry(geometry, thresholdAngle) {
  17629. var _this;
  17630. _this = _BufferGeometry.call(this) || this;
  17631. _this.type = 'EdgesGeometry';
  17632. _this.parameters = {
  17633. thresholdAngle: thresholdAngle
  17634. };
  17635. thresholdAngle = thresholdAngle !== undefined ? thresholdAngle : 1;
  17636. if (geometry.isGeometry === true) {
  17637. console.error('THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  17638. return _assertThisInitialized(_this);
  17639. }
  17640. var precisionPoints = 4;
  17641. var precision = Math.pow(10, precisionPoints);
  17642. var thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
  17643. var indexAttr = geometry.getIndex();
  17644. var positionAttr = geometry.getAttribute('position');
  17645. var indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17646. var indexArr = [0, 0, 0];
  17647. var vertKeys = ['a', 'b', 'c'];
  17648. var hashes = new Array(3);
  17649. var edgeData = {};
  17650. var vertices = [];
  17651. for (var i = 0; i < indexCount; i += 3) {
  17652. if (indexAttr) {
  17653. indexArr[0] = indexAttr.getX(i);
  17654. indexArr[1] = indexAttr.getX(i + 1);
  17655. indexArr[2] = indexAttr.getX(i + 2);
  17656. } else {
  17657. indexArr[0] = i;
  17658. indexArr[1] = i + 1;
  17659. indexArr[2] = i + 2;
  17660. }
  17661. var a = _triangle.a,
  17662. b = _triangle.b,
  17663. c = _triangle.c;
  17664. a.fromBufferAttribute(positionAttr, indexArr[0]);
  17665. b.fromBufferAttribute(positionAttr, indexArr[1]);
  17666. c.fromBufferAttribute(positionAttr, indexArr[2]);
  17667. _triangle.getNormal(_normal$1); // create hashes for the edge from the vertices
  17668. hashes[0] = Math.round(a.x * precision) + "," + Math.round(a.y * precision) + "," + Math.round(a.z * precision);
  17669. hashes[1] = Math.round(b.x * precision) + "," + Math.round(b.y * precision) + "," + Math.round(b.z * precision);
  17670. hashes[2] = Math.round(c.x * precision) + "," + Math.round(c.y * precision) + "," + Math.round(c.z * precision); // skip degenerate triangles
  17671. if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
  17672. continue;
  17673. } // iterate over every edge
  17674. for (var j = 0; j < 3; j++) {
  17675. // get the first and next vertex making up the edge
  17676. var jNext = (j + 1) % 3;
  17677. var vecHash0 = hashes[j];
  17678. var vecHash1 = hashes[jNext];
  17679. var v0 = _triangle[vertKeys[j]];
  17680. var v1 = _triangle[vertKeys[jNext]];
  17681. var hash = vecHash0 + "_" + vecHash1;
  17682. var reverseHash = vecHash1 + "_" + vecHash0;
  17683. if (reverseHash in edgeData && edgeData[reverseHash]) {
  17684. // if we found a sibling edge add it into the vertex array if
  17685. // it meets the angle threshold and delete the edge from the map.
  17686. if (_normal$1.dot(edgeData[reverseHash].normal) <= thresholdDot) {
  17687. vertices.push(v0.x, v0.y, v0.z);
  17688. vertices.push(v1.x, v1.y, v1.z);
  17689. }
  17690. edgeData[reverseHash] = null;
  17691. } else if (!(hash in edgeData)) {
  17692. // if we've already got an edge here then skip adding a new one
  17693. edgeData[hash] = {
  17694. index0: indexArr[j],
  17695. index1: indexArr[jNext],
  17696. normal: _normal$1.clone()
  17697. };
  17698. }
  17699. }
  17700. } // iterate over all remaining, unmatched edges and add them to the vertex array
  17701. for (var key in edgeData) {
  17702. if (edgeData[key]) {
  17703. var _edgeData$key = edgeData[key],
  17704. index0 = _edgeData$key.index0,
  17705. index1 = _edgeData$key.index1;
  17706. _v0$2.fromBufferAttribute(positionAttr, index0);
  17707. _v1$5.fromBufferAttribute(positionAttr, index1);
  17708. vertices.push(_v0$2.x, _v0$2.y, _v0$2.z);
  17709. vertices.push(_v1$5.x, _v1$5.y, _v1$5.z);
  17710. }
  17711. }
  17712. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  17713. return _this;
  17714. }
  17715. return EdgesGeometry;
  17716. }(BufferGeometry);
  17717. /**
  17718. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17719. */
  17720. var Earcut = {
  17721. triangulate: function triangulate(data, holeIndices, dim) {
  17722. dim = dim || 2;
  17723. var hasHoles = holeIndices && holeIndices.length;
  17724. var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
  17725. var outerNode = linkedList(data, 0, outerLen, dim, true);
  17726. var triangles = [];
  17727. if (!outerNode || outerNode.next === outerNode.prev) return triangles;
  17728. var minX, minY, maxX, maxY, x, y, invSize;
  17729. 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
  17730. if (data.length > 80 * dim) {
  17731. minX = maxX = data[0];
  17732. minY = maxY = data[1];
  17733. for (var i = dim; i < outerLen; i += dim) {
  17734. x = data[i];
  17735. y = data[i + 1];
  17736. if (x < minX) minX = x;
  17737. if (y < minY) minY = y;
  17738. if (x > maxX) maxX = x;
  17739. if (y > maxY) maxY = y;
  17740. } // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17741. invSize = Math.max(maxX - minX, maxY - minY);
  17742. invSize = invSize !== 0 ? 1 / invSize : 0;
  17743. }
  17744. earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
  17745. return triangles;
  17746. }
  17747. }; // create a circular doubly linked list from polygon points in the specified winding order
  17748. function linkedList(data, start, end, dim, clockwise) {
  17749. var i, last;
  17750. if (clockwise === signedArea(data, start, end, dim) > 0) {
  17751. for (i = start; i < end; i += dim) {
  17752. last = insertNode(i, data[i], data[i + 1], last);
  17753. }
  17754. } else {
  17755. for (i = end - dim; i >= start; i -= dim) {
  17756. last = insertNode(i, data[i], data[i + 1], last);
  17757. }
  17758. }
  17759. if (last && equals(last, last.next)) {
  17760. removeNode(last);
  17761. last = last.next;
  17762. }
  17763. return last;
  17764. } // eliminate colinear or duplicate points
  17765. function filterPoints(start, end) {
  17766. if (!start) return start;
  17767. if (!end) end = start;
  17768. var p = start,
  17769. again;
  17770. do {
  17771. again = false;
  17772. if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
  17773. removeNode(p);
  17774. p = end = p.prev;
  17775. if (p === p.next) break;
  17776. again = true;
  17777. } else {
  17778. p = p.next;
  17779. }
  17780. } while (again || p !== end);
  17781. return end;
  17782. } // main ear slicing loop which triangulates a polygon (given as a linked list)
  17783. function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
  17784. if (!ear) return; // interlink polygon nodes in z-order
  17785. if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
  17786. var stop = ear,
  17787. prev,
  17788. next; // iterate through ears, slicing them one by one
  17789. while (ear.prev !== ear.next) {
  17790. prev = ear.prev;
  17791. next = ear.next;
  17792. if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
  17793. // cut off the triangle
  17794. triangles.push(prev.i / dim);
  17795. triangles.push(ear.i / dim);
  17796. triangles.push(next.i / dim);
  17797. removeNode(ear); // skipping the next vertex leads to less sliver triangles
  17798. ear = next.next;
  17799. stop = next.next;
  17800. continue;
  17801. }
  17802. ear = next; // if we looped through the whole remaining polygon and can't find any more ears
  17803. if (ear === stop) {
  17804. // try filtering points and slicing again
  17805. if (!pass) {
  17806. earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1); // if this didn't work, try curing all small self-intersections locally
  17807. } else if (pass === 1) {
  17808. ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
  17809. earcutLinked(ear, triangles, dim, minX, minY, invSize, 2); // as a last resort, try splitting the remaining polygon into two
  17810. } else if (pass === 2) {
  17811. splitEarcut(ear, triangles, dim, minX, minY, invSize);
  17812. }
  17813. break;
  17814. }
  17815. }
  17816. } // check whether a polygon node forms a valid ear with adjacent nodes
  17817. function isEar(ear) {
  17818. var a = ear.prev,
  17819. b = ear,
  17820. c = ear.next;
  17821. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17822. // now make sure we don't have other points inside the potential ear
  17823. var p = ear.next.next;
  17824. while (p !== ear.prev) {
  17825. 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;
  17826. p = p.next;
  17827. }
  17828. return true;
  17829. }
  17830. function isEarHashed(ear, minX, minY, invSize) {
  17831. var a = ear.prev,
  17832. b = ear,
  17833. c = ear.next;
  17834. if (area(a, b, c) >= 0) return false; // reflex, can't be an ear
  17835. // triangle bbox; min & max are calculated like this for speed
  17836. var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x,
  17837. minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y,
  17838. maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x,
  17839. 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;
  17840. var minZ = zOrder(minTX, minTY, minX, minY, invSize),
  17841. maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
  17842. var p = ear.prevZ,
  17843. n = ear.nextZ; // look for points inside the triangle in both directions
  17844. while (p && p.z >= minZ && n && n.z <= maxZ) {
  17845. 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;
  17846. p = p.prevZ;
  17847. 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;
  17848. n = n.nextZ;
  17849. } // look for remaining points in decreasing z-order
  17850. while (p && p.z >= minZ) {
  17851. 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;
  17852. p = p.prevZ;
  17853. } // look for remaining points in increasing z-order
  17854. while (n && n.z <= maxZ) {
  17855. 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;
  17856. n = n.nextZ;
  17857. }
  17858. return true;
  17859. } // go through all polygon nodes and cure small local self-intersections
  17860. function cureLocalIntersections(start, triangles, dim) {
  17861. var p = start;
  17862. do {
  17863. var a = p.prev,
  17864. b = p.next.next;
  17865. if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
  17866. triangles.push(a.i / dim);
  17867. triangles.push(p.i / dim);
  17868. triangles.push(b.i / dim); // remove two nodes involved
  17869. removeNode(p);
  17870. removeNode(p.next);
  17871. p = start = b;
  17872. }
  17873. p = p.next;
  17874. } while (p !== start);
  17875. return filterPoints(p);
  17876. } // try splitting polygon into two and triangulate them independently
  17877. function splitEarcut(start, triangles, dim, minX, minY, invSize) {
  17878. // look for a valid diagonal that divides the polygon into two
  17879. var a = start;
  17880. do {
  17881. var b = a.next.next;
  17882. while (b !== a.prev) {
  17883. if (a.i !== b.i && isValidDiagonal(a, b)) {
  17884. // split the polygon in two by the diagonal
  17885. var c = splitPolygon(a, b); // filter colinear points around the cuts
  17886. a = filterPoints(a, a.next);
  17887. c = filterPoints(c, c.next); // run earcut on each half
  17888. earcutLinked(a, triangles, dim, minX, minY, invSize);
  17889. earcutLinked(c, triangles, dim, minX, minY, invSize);
  17890. return;
  17891. }
  17892. b = b.next;
  17893. }
  17894. a = a.next;
  17895. } while (a !== start);
  17896. } // link every hole into the outer loop, producing a single-ring polygon without holes
  17897. function eliminateHoles(data, holeIndices, outerNode, dim) {
  17898. var queue = [];
  17899. var i, len, start, end, list;
  17900. for (i = 0, len = holeIndices.length; i < len; i++) {
  17901. start = holeIndices[i] * dim;
  17902. end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
  17903. list = linkedList(data, start, end, dim, false);
  17904. if (list === list.next) list.steiner = true;
  17905. queue.push(getLeftmost(list));
  17906. }
  17907. queue.sort(compareX); // process holes from left to right
  17908. for (i = 0; i < queue.length; i++) {
  17909. eliminateHole(queue[i], outerNode);
  17910. outerNode = filterPoints(outerNode, outerNode.next);
  17911. }
  17912. return outerNode;
  17913. }
  17914. function compareX(a, b) {
  17915. return a.x - b.x;
  17916. } // find a bridge between vertices that connects hole with an outer ring and and link it
  17917. function eliminateHole(hole, outerNode) {
  17918. outerNode = findHoleBridge(hole, outerNode);
  17919. if (outerNode) {
  17920. var b = splitPolygon(outerNode, hole); // filter collinear points around the cuts
  17921. filterPoints(outerNode, outerNode.next);
  17922. filterPoints(b, b.next);
  17923. }
  17924. } // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17925. function findHoleBridge(hole, outerNode) {
  17926. var p = outerNode;
  17927. var hx = hole.x;
  17928. var hy = hole.y;
  17929. var qx = -Infinity,
  17930. m; // find a segment intersected by a ray from the hole's leftmost point to the left;
  17931. // segment's endpoint with lesser x will be potential connection point
  17932. do {
  17933. if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
  17934. var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
  17935. if (x <= hx && x > qx) {
  17936. qx = x;
  17937. if (x === hx) {
  17938. if (hy === p.y) return p;
  17939. if (hy === p.next.y) return p.next;
  17940. }
  17941. m = p.x < p.next.x ? p : p.next;
  17942. }
  17943. }
  17944. p = p.next;
  17945. } while (p !== outerNode);
  17946. if (!m) return null;
  17947. if (hx === qx) return m; // hole touches outer segment; pick leftmost endpoint
  17948. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17949. // if there are no points found, we have a valid connection;
  17950. // otherwise choose the point of the minimum angle with the ray as connection point
  17951. var stop = m,
  17952. mx = m.x,
  17953. my = m.y;
  17954. var tanMin = Infinity,
  17955. tan;
  17956. p = m;
  17957. do {
  17958. 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)) {
  17959. tan = Math.abs(hy - p.y) / (hx - p.x); // tangential
  17960. if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
  17961. m = p;
  17962. tanMin = tan;
  17963. }
  17964. }
  17965. p = p.next;
  17966. } while (p !== stop);
  17967. return m;
  17968. } // whether sector in vertex m contains sector in vertex p in the same coordinates
  17969. function sectorContainsSector(m, p) {
  17970. return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
  17971. } // interlink polygon nodes in z-order
  17972. function indexCurve(start, minX, minY, invSize) {
  17973. var p = start;
  17974. do {
  17975. if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
  17976. p.prevZ = p.prev;
  17977. p.nextZ = p.next;
  17978. p = p.next;
  17979. } while (p !== start);
  17980. p.prevZ.nextZ = null;
  17981. p.prevZ = null;
  17982. sortLinked(p);
  17983. } // Simon Tatham's linked list merge sort algorithm
  17984. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17985. function sortLinked(list) {
  17986. var i,
  17987. p,
  17988. q,
  17989. e,
  17990. tail,
  17991. numMerges,
  17992. pSize,
  17993. qSize,
  17994. inSize = 1;
  17995. do {
  17996. p = list;
  17997. list = null;
  17998. tail = null;
  17999. numMerges = 0;
  18000. while (p) {
  18001. numMerges++;
  18002. q = p;
  18003. pSize = 0;
  18004. for (i = 0; i < inSize; i++) {
  18005. pSize++;
  18006. q = q.nextZ;
  18007. if (!q) break;
  18008. }
  18009. qSize = inSize;
  18010. while (pSize > 0 || qSize > 0 && q) {
  18011. if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
  18012. e = p;
  18013. p = p.nextZ;
  18014. pSize--;
  18015. } else {
  18016. e = q;
  18017. q = q.nextZ;
  18018. qSize--;
  18019. }
  18020. if (tail) tail.nextZ = e;else list = e;
  18021. e.prevZ = tail;
  18022. tail = e;
  18023. }
  18024. p = q;
  18025. }
  18026. tail.nextZ = null;
  18027. inSize *= 2;
  18028. } while (numMerges > 1);
  18029. return list;
  18030. } // z-order of a point given coords and inverse of the longer side of data bbox
  18031. function zOrder(x, y, minX, minY, invSize) {
  18032. // coords are transformed into non-negative 15-bit integer range
  18033. x = 32767 * (x - minX) * invSize;
  18034. y = 32767 * (y - minY) * invSize;
  18035. x = (x | x << 8) & 0x00FF00FF;
  18036. x = (x | x << 4) & 0x0F0F0F0F;
  18037. x = (x | x << 2) & 0x33333333;
  18038. x = (x | x << 1) & 0x55555555;
  18039. y = (y | y << 8) & 0x00FF00FF;
  18040. y = (y | y << 4) & 0x0F0F0F0F;
  18041. y = (y | y << 2) & 0x33333333;
  18042. y = (y | y << 1) & 0x55555555;
  18043. return x | y << 1;
  18044. } // find the leftmost node of a polygon ring
  18045. function getLeftmost(start) {
  18046. var p = start,
  18047. leftmost = start;
  18048. do {
  18049. if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) leftmost = p;
  18050. p = p.next;
  18051. } while (p !== start);
  18052. return leftmost;
  18053. } // check if a point lies within a convex triangle
  18054. function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
  18055. 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;
  18056. } // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18057. function isValidDiagonal(a, b) {
  18058. return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && ( // dones't intersect other edges
  18059. locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && ( // locally visible
  18060. area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
  18061. equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
  18062. } // signed area of a triangle
  18063. function area(p, q, r) {
  18064. return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
  18065. } // check if two points are equal
  18066. function equals(p1, p2) {
  18067. return p1.x === p2.x && p1.y === p2.y;
  18068. } // check if two segments intersect
  18069. function intersects(p1, q1, p2, q2) {
  18070. var o1 = sign(area(p1, q1, p2));
  18071. var o2 = sign(area(p1, q1, q2));
  18072. var o3 = sign(area(p2, q2, p1));
  18073. var o4 = sign(area(p2, q2, q1));
  18074. if (o1 !== o2 && o3 !== o4) return true; // general case
  18075. if (o1 === 0 && onSegment(p1, p2, q1)) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18076. if (o2 === 0 && onSegment(p1, q2, q1)) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18077. if (o3 === 0 && onSegment(p2, p1, q2)) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18078. if (o4 === 0 && onSegment(p2, q1, q2)) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18079. return false;
  18080. } // for collinear points p, q, r, check if point q lies on segment pr
  18081. function onSegment(p, q, r) {
  18082. 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);
  18083. }
  18084. function sign(num) {
  18085. return num > 0 ? 1 : num < 0 ? -1 : 0;
  18086. } // check if a polygon diagonal intersects any polygon segments
  18087. function intersectsPolygon(a, b) {
  18088. var p = a;
  18089. do {
  18090. 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;
  18091. p = p.next;
  18092. } while (p !== a);
  18093. return false;
  18094. } // check if a polygon diagonal is locally inside the polygon
  18095. function locallyInside(a, b) {
  18096. 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;
  18097. } // check if the middle point of a polygon diagonal is inside the polygon
  18098. function middleInside(a, b) {
  18099. var p = a,
  18100. inside = false;
  18101. var px = (a.x + b.x) / 2,
  18102. py = (a.y + b.y) / 2;
  18103. do {
  18104. 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;
  18105. p = p.next;
  18106. } while (p !== a);
  18107. return inside;
  18108. } // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18109. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18110. function splitPolygon(a, b) {
  18111. var a2 = new Node(a.i, a.x, a.y),
  18112. b2 = new Node(b.i, b.x, b.y),
  18113. an = a.next,
  18114. bp = b.prev;
  18115. a.next = b;
  18116. b.prev = a;
  18117. a2.next = an;
  18118. an.prev = a2;
  18119. b2.next = a2;
  18120. a2.prev = b2;
  18121. bp.next = b2;
  18122. b2.prev = bp;
  18123. return b2;
  18124. } // create a node and optionally link it with previous one (in a circular doubly linked list)
  18125. function insertNode(i, x, y, last) {
  18126. var p = new Node(i, x, y);
  18127. if (!last) {
  18128. p.prev = p;
  18129. p.next = p;
  18130. } else {
  18131. p.next = last.next;
  18132. p.prev = last;
  18133. last.next.prev = p;
  18134. last.next = p;
  18135. }
  18136. return p;
  18137. }
  18138. function removeNode(p) {
  18139. p.next.prev = p.prev;
  18140. p.prev.next = p.next;
  18141. if (p.prevZ) p.prevZ.nextZ = p.nextZ;
  18142. if (p.nextZ) p.nextZ.prevZ = p.prevZ;
  18143. }
  18144. function Node(i, x, y) {
  18145. // vertex index in coordinates array
  18146. this.i = i; // vertex coordinates
  18147. this.x = x;
  18148. this.y = y; // previous and next vertex nodes in a polygon ring
  18149. this.prev = null;
  18150. this.next = null; // z-order curve value
  18151. this.z = null; // previous and next nodes in z-order
  18152. this.prevZ = null;
  18153. this.nextZ = null; // indicates whether this is a steiner point
  18154. this.steiner = false;
  18155. }
  18156. function signedArea(data, start, end, dim) {
  18157. var sum = 0;
  18158. for (var i = start, j = end - dim; i < end; i += dim) {
  18159. sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
  18160. j = i;
  18161. }
  18162. return sum;
  18163. }
  18164. var ShapeUtils = {
  18165. // calculate area of the contour polygon
  18166. area: function area(contour) {
  18167. var n = contour.length;
  18168. var a = 0.0;
  18169. for (var p = n - 1, q = 0; q < n; p = q++) {
  18170. a += contour[p].x * contour[q].y - contour[q].x * contour[p].y;
  18171. }
  18172. return a * 0.5;
  18173. },
  18174. isClockWise: function isClockWise(pts) {
  18175. return ShapeUtils.area(pts) < 0;
  18176. },
  18177. triangulateShape: function triangulateShape(contour, holes) {
  18178. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18179. var holeIndices = []; // array of hole indices
  18180. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18181. removeDupEndPts(contour);
  18182. addContour(vertices, contour); //
  18183. var holeIndex = contour.length;
  18184. holes.forEach(removeDupEndPts);
  18185. for (var i = 0; i < holes.length; i++) {
  18186. holeIndices.push(holeIndex);
  18187. holeIndex += holes[i].length;
  18188. addContour(vertices, holes[i]);
  18189. } //
  18190. var triangles = Earcut.triangulate(vertices, holeIndices); //
  18191. for (var _i = 0; _i < triangles.length; _i += 3) {
  18192. faces.push(triangles.slice(_i, _i + 3));
  18193. }
  18194. return faces;
  18195. }
  18196. };
  18197. function removeDupEndPts(points) {
  18198. var l = points.length;
  18199. if (l > 2 && points[l - 1].equals(points[0])) {
  18200. points.pop();
  18201. }
  18202. }
  18203. function addContour(vertices, contour) {
  18204. for (var i = 0; i < contour.length; i++) {
  18205. vertices.push(contour[i].x);
  18206. vertices.push(contour[i].y);
  18207. }
  18208. }
  18209. var ExtrudeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18210. _inheritsLoose(ExtrudeGeometry, _BufferGeometry);
  18211. function ExtrudeGeometry(shapes, options) {
  18212. var _this;
  18213. _this = _BufferGeometry.call(this) || this;
  18214. _this.type = 'ExtrudeGeometry';
  18215. _this.parameters = {
  18216. shapes: shapes,
  18217. options: options
  18218. };
  18219. shapes = Array.isArray(shapes) ? shapes : [shapes];
  18220. var scope = _assertThisInitialized(_this);
  18221. var verticesArray = [];
  18222. var uvArray = [];
  18223. for (var i = 0, l = shapes.length; i < l; i++) {
  18224. var shape = shapes[i];
  18225. addShape(shape);
  18226. } // build geometry
  18227. _this.setAttribute('position', new Float32BufferAttribute(verticesArray, 3));
  18228. _this.setAttribute('uv', new Float32BufferAttribute(uvArray, 2));
  18229. _this.computeVertexNormals(); // functions
  18230. function addShape(shape) {
  18231. var placeholder = []; // options
  18232. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18233. var steps = options.steps !== undefined ? options.steps : 1;
  18234. var depth = options.depth !== undefined ? options.depth : 100;
  18235. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18236. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18237. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18238. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18239. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18240. var extrudePath = options.extrudePath;
  18241. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; // deprecated options
  18242. if (options.amount !== undefined) {
  18243. console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');
  18244. depth = options.amount;
  18245. } //
  18246. var extrudePts,
  18247. extrudeByPath = false;
  18248. var splineTube, binormal, normal, position2;
  18249. if (extrudePath) {
  18250. extrudePts = extrudePath.getSpacedPoints(steps);
  18251. extrudeByPath = true;
  18252. bevelEnabled = false; // bevels not supported for path extrusion
  18253. // SETUP TNB variables
  18254. // TODO1 - have a .isClosed in spline?
  18255. splineTube = extrudePath.computeFrenetFrames(steps, false); // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18256. binormal = new Vector3();
  18257. normal = new Vector3();
  18258. position2 = new Vector3();
  18259. } // Safeguards if bevels are not enabled
  18260. if (!bevelEnabled) {
  18261. bevelSegments = 0;
  18262. bevelThickness = 0;
  18263. bevelSize = 0;
  18264. bevelOffset = 0;
  18265. } // Variables initialization
  18266. var shapePoints = shape.extractPoints(curveSegments);
  18267. var vertices = shapePoints.shape;
  18268. var holes = shapePoints.holes;
  18269. var reverse = !ShapeUtils.isClockWise(vertices);
  18270. if (reverse) {
  18271. vertices = vertices.reverse(); // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18272. for (var h = 0, hl = holes.length; h < hl; h++) {
  18273. var ahole = holes[h];
  18274. if (ShapeUtils.isClockWise(ahole)) {
  18275. holes[h] = ahole.reverse();
  18276. }
  18277. }
  18278. }
  18279. var faces = ShapeUtils.triangulateShape(vertices, holes);
  18280. /* Vertices */
  18281. var contour = vertices; // vertices has all points but contour has only points of circumference
  18282. for (var _h = 0, _hl = holes.length; _h < _hl; _h++) {
  18283. var _ahole = holes[_h];
  18284. vertices = vertices.concat(_ahole);
  18285. }
  18286. function scalePt2(pt, vec, size) {
  18287. if (!vec) console.error('THREE.ExtrudeGeometry: vec does not exist');
  18288. return vec.clone().multiplyScalar(size).add(pt);
  18289. }
  18290. var vlen = vertices.length,
  18291. flen = faces.length; // Find directions for point movement
  18292. function getBevelVec(inPt, inPrev, inNext) {
  18293. // computes for inPt the corresponding point inPt' on a new contour
  18294. // shifted by 1 unit (length of normalized vector) to the left
  18295. // if we walk along contour clockwise, this new contour is outside the old one
  18296. //
  18297. // inPt' is the intersection of the two lines parallel to the two
  18298. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18299. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18300. // good reading for geometry algorithms (here: line-line intersection)
  18301. // http://geomalgorithms.com/a05-_intersect-1.html
  18302. var v_prev_x = inPt.x - inPrev.x,
  18303. v_prev_y = inPt.y - inPrev.y;
  18304. var v_next_x = inNext.x - inPt.x,
  18305. v_next_y = inNext.y - inPt.y;
  18306. var v_prev_lensq = v_prev_x * v_prev_x + v_prev_y * v_prev_y; // check for collinear edges
  18307. var collinear0 = v_prev_x * v_next_y - v_prev_y * v_next_x;
  18308. if (Math.abs(collinear0) > Number.EPSILON) {
  18309. // not collinear
  18310. // length of vectors for normalizing
  18311. var v_prev_len = Math.sqrt(v_prev_lensq);
  18312. 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
  18313. var ptPrevShift_x = inPrev.x - v_prev_y / v_prev_len;
  18314. var ptPrevShift_y = inPrev.y + v_prev_x / v_prev_len;
  18315. var ptNextShift_x = inNext.x - v_next_y / v_next_len;
  18316. var ptNextShift_y = inNext.y + v_next_x / v_next_len; // scaling factor for v_prev to intersection point
  18317. 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
  18318. v_trans_x = ptPrevShift_x + v_prev_x * sf - inPt.x;
  18319. v_trans_y = ptPrevShift_y + v_prev_y * sf - inPt.y; // Don't normalize!, otherwise sharp corners become ugly
  18320. // but prevent crazy spikes
  18321. var v_trans_lensq = v_trans_x * v_trans_x + v_trans_y * v_trans_y;
  18322. if (v_trans_lensq <= 2) {
  18323. return new Vector2(v_trans_x, v_trans_y);
  18324. } else {
  18325. shrink_by = Math.sqrt(v_trans_lensq / 2);
  18326. }
  18327. } else {
  18328. // handle special case of collinear edges
  18329. var direction_eq = false; // assumes: opposite
  18330. if (v_prev_x > Number.EPSILON) {
  18331. if (v_next_x > Number.EPSILON) {
  18332. direction_eq = true;
  18333. }
  18334. } else {
  18335. if (v_prev_x < -Number.EPSILON) {
  18336. if (v_next_x < -Number.EPSILON) {
  18337. direction_eq = true;
  18338. }
  18339. } else {
  18340. if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
  18341. direction_eq = true;
  18342. }
  18343. }
  18344. }
  18345. if (direction_eq) {
  18346. // console.log("Warning: lines are a straight sequence");
  18347. v_trans_x = -v_prev_y;
  18348. v_trans_y = v_prev_x;
  18349. shrink_by = Math.sqrt(v_prev_lensq);
  18350. } else {
  18351. // console.log("Warning: lines are a straight spike");
  18352. v_trans_x = v_prev_x;
  18353. v_trans_y = v_prev_y;
  18354. shrink_by = Math.sqrt(v_prev_lensq / 2);
  18355. }
  18356. }
  18357. return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
  18358. }
  18359. var contourMovements = [];
  18360. for (var _i = 0, il = contour.length, j = il - 1, k = _i + 1; _i < il; _i++, j++, k++) {
  18361. if (j === il) j = 0;
  18362. if (k === il) k = 0; // (j)---(i)---(k)
  18363. // console.log('i,j,k', i, j , k)
  18364. contourMovements[_i] = getBevelVec(contour[_i], contour[j], contour[k]);
  18365. }
  18366. var holesMovements = [];
  18367. var oneHoleMovements,
  18368. verticesMovements = contourMovements.concat();
  18369. for (var _h2 = 0, _hl2 = holes.length; _h2 < _hl2; _h2++) {
  18370. var _ahole2 = holes[_h2];
  18371. oneHoleMovements = [];
  18372. for (var _i2 = 0, _il = _ahole2.length, _j = _il - 1, _k = _i2 + 1; _i2 < _il; _i2++, _j++, _k++) {
  18373. if (_j === _il) _j = 0;
  18374. if (_k === _il) _k = 0; // (j)---(i)---(k)
  18375. oneHoleMovements[_i2] = getBevelVec(_ahole2[_i2], _ahole2[_j], _ahole2[_k]);
  18376. }
  18377. holesMovements.push(oneHoleMovements);
  18378. verticesMovements = verticesMovements.concat(oneHoleMovements);
  18379. } // Loop bevelSegments, 1 for the front, 1 for the back
  18380. for (var b = 0; b < bevelSegments; b++) {
  18381. //for ( b = bevelSegments; b > 0; b -- ) {
  18382. var t = b / bevelSegments;
  18383. var z = bevelThickness * Math.cos(t * Math.PI / 2);
  18384. var _bs = bevelSize * Math.sin(t * Math.PI / 2) + bevelOffset; // contract shape
  18385. for (var _i3 = 0, _il2 = contour.length; _i3 < _il2; _i3++) {
  18386. var vert = scalePt2(contour[_i3], contourMovements[_i3], _bs);
  18387. v(vert.x, vert.y, -z);
  18388. } // expand holes
  18389. for (var _h3 = 0, _hl3 = holes.length; _h3 < _hl3; _h3++) {
  18390. var _ahole3 = holes[_h3];
  18391. oneHoleMovements = holesMovements[_h3];
  18392. for (var _i4 = 0, _il3 = _ahole3.length; _i4 < _il3; _i4++) {
  18393. var _vert = scalePt2(_ahole3[_i4], oneHoleMovements[_i4], _bs);
  18394. v(_vert.x, _vert.y, -z);
  18395. }
  18396. }
  18397. }
  18398. var bs = bevelSize + bevelOffset; // Back facing vertices
  18399. for (var _i5 = 0; _i5 < vlen; _i5++) {
  18400. var _vert2 = bevelEnabled ? scalePt2(vertices[_i5], verticesMovements[_i5], bs) : vertices[_i5];
  18401. if (!extrudeByPath) {
  18402. v(_vert2.x, _vert2.y, 0);
  18403. } else {
  18404. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18405. normal.copy(splineTube.normals[0]).multiplyScalar(_vert2.x);
  18406. binormal.copy(splineTube.binormals[0]).multiplyScalar(_vert2.y);
  18407. position2.copy(extrudePts[0]).add(normal).add(binormal);
  18408. v(position2.x, position2.y, position2.z);
  18409. }
  18410. } // Add stepped vertices...
  18411. // Including front facing vertices
  18412. for (var s = 1; s <= steps; s++) {
  18413. for (var _i6 = 0; _i6 < vlen; _i6++) {
  18414. var _vert3 = bevelEnabled ? scalePt2(vertices[_i6], verticesMovements[_i6], bs) : vertices[_i6];
  18415. if (!extrudeByPath) {
  18416. v(_vert3.x, _vert3.y, depth / steps * s);
  18417. } else {
  18418. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18419. normal.copy(splineTube.normals[s]).multiplyScalar(_vert3.x);
  18420. binormal.copy(splineTube.binormals[s]).multiplyScalar(_vert3.y);
  18421. position2.copy(extrudePts[s]).add(normal).add(binormal);
  18422. v(position2.x, position2.y, position2.z);
  18423. }
  18424. }
  18425. } // Add bevel segments planes
  18426. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18427. for (var _b = bevelSegments - 1; _b >= 0; _b--) {
  18428. var _t = _b / bevelSegments;
  18429. var _z = bevelThickness * Math.cos(_t * Math.PI / 2);
  18430. var _bs2 = bevelSize * Math.sin(_t * Math.PI / 2) + bevelOffset; // contract shape
  18431. for (var _i7 = 0, _il4 = contour.length; _i7 < _il4; _i7++) {
  18432. var _vert4 = scalePt2(contour[_i7], contourMovements[_i7], _bs2);
  18433. v(_vert4.x, _vert4.y, depth + _z);
  18434. } // expand holes
  18435. for (var _h4 = 0, _hl4 = holes.length; _h4 < _hl4; _h4++) {
  18436. var _ahole4 = holes[_h4];
  18437. oneHoleMovements = holesMovements[_h4];
  18438. for (var _i8 = 0, _il5 = _ahole4.length; _i8 < _il5; _i8++) {
  18439. var _vert5 = scalePt2(_ahole4[_i8], oneHoleMovements[_i8], _bs2);
  18440. if (!extrudeByPath) {
  18441. v(_vert5.x, _vert5.y, depth + _z);
  18442. } else {
  18443. v(_vert5.x, _vert5.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + _z);
  18444. }
  18445. }
  18446. }
  18447. }
  18448. /* Faces */
  18449. // Top and bottom faces
  18450. buildLidFaces(); // Sides faces
  18451. buildSideFaces(); ///// Internal functions
  18452. function buildLidFaces() {
  18453. var start = verticesArray.length / 3;
  18454. if (bevelEnabled) {
  18455. var layer = 0; // steps + 1
  18456. var offset = vlen * layer; // Bottom faces
  18457. for (var _i9 = 0; _i9 < flen; _i9++) {
  18458. var face = faces[_i9];
  18459. f3(face[2] + offset, face[1] + offset, face[0] + offset);
  18460. }
  18461. layer = steps + bevelSegments * 2;
  18462. offset = vlen * layer; // Top faces
  18463. for (var _i10 = 0; _i10 < flen; _i10++) {
  18464. var _face = faces[_i10];
  18465. f3(_face[0] + offset, _face[1] + offset, _face[2] + offset);
  18466. }
  18467. } else {
  18468. // Bottom faces
  18469. for (var _i11 = 0; _i11 < flen; _i11++) {
  18470. var _face2 = faces[_i11];
  18471. f3(_face2[2], _face2[1], _face2[0]);
  18472. } // Top faces
  18473. for (var _i12 = 0; _i12 < flen; _i12++) {
  18474. var _face3 = faces[_i12];
  18475. f3(_face3[0] + vlen * steps, _face3[1] + vlen * steps, _face3[2] + vlen * steps);
  18476. }
  18477. }
  18478. scope.addGroup(start, verticesArray.length / 3 - start, 0);
  18479. } // Create faces for the z-sides of the shape
  18480. function buildSideFaces() {
  18481. var start = verticesArray.length / 3;
  18482. var layeroffset = 0;
  18483. sidewalls(contour, layeroffset);
  18484. layeroffset += contour.length;
  18485. for (var _h5 = 0, _hl5 = holes.length; _h5 < _hl5; _h5++) {
  18486. var _ahole5 = holes[_h5];
  18487. sidewalls(_ahole5, layeroffset); //, true
  18488. layeroffset += _ahole5.length;
  18489. }
  18490. scope.addGroup(start, verticesArray.length / 3 - start, 1);
  18491. }
  18492. function sidewalls(contour, layeroffset) {
  18493. var i = contour.length;
  18494. while (--i >= 0) {
  18495. var _j2 = i;
  18496. var _k2 = i - 1;
  18497. if (_k2 < 0) _k2 = contour.length - 1; //console.log('b', i,j, i-1, k,vertices.length);
  18498. for (var _s = 0, sl = steps + bevelSegments * 2; _s < sl; _s++) {
  18499. var slen1 = vlen * _s;
  18500. var slen2 = vlen * (_s + 1);
  18501. var a = layeroffset + _j2 + slen1,
  18502. _b2 = layeroffset + _k2 + slen1,
  18503. c = layeroffset + _k2 + slen2,
  18504. d = layeroffset + _j2 + slen2;
  18505. f4(a, _b2, c, d);
  18506. }
  18507. }
  18508. }
  18509. function v(x, y, z) {
  18510. placeholder.push(x);
  18511. placeholder.push(y);
  18512. placeholder.push(z);
  18513. }
  18514. function f3(a, b, c) {
  18515. addVertex(a);
  18516. addVertex(b);
  18517. addVertex(c);
  18518. var nextIndex = verticesArray.length / 3;
  18519. var uvs = uvgen.generateTopUV(scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18520. addUV(uvs[0]);
  18521. addUV(uvs[1]);
  18522. addUV(uvs[2]);
  18523. }
  18524. function f4(a, b, c, d) {
  18525. addVertex(a);
  18526. addVertex(b);
  18527. addVertex(d);
  18528. addVertex(b);
  18529. addVertex(c);
  18530. addVertex(d);
  18531. var nextIndex = verticesArray.length / 3;
  18532. var uvs = uvgen.generateSideWallUV(scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1);
  18533. addUV(uvs[0]);
  18534. addUV(uvs[1]);
  18535. addUV(uvs[3]);
  18536. addUV(uvs[1]);
  18537. addUV(uvs[2]);
  18538. addUV(uvs[3]);
  18539. }
  18540. function addVertex(index) {
  18541. verticesArray.push(placeholder[index * 3 + 0]);
  18542. verticesArray.push(placeholder[index * 3 + 1]);
  18543. verticesArray.push(placeholder[index * 3 + 2]);
  18544. }
  18545. function addUV(vector2) {
  18546. uvArray.push(vector2.x);
  18547. uvArray.push(vector2.y);
  18548. }
  18549. }
  18550. return _this;
  18551. }
  18552. var _proto = ExtrudeGeometry.prototype;
  18553. _proto.toJSON = function toJSON() {
  18554. var data = BufferGeometry.prototype.toJSON.call(this);
  18555. var shapes = this.parameters.shapes;
  18556. var options = this.parameters.options;
  18557. return _toJSON(shapes, options, data);
  18558. };
  18559. return ExtrudeGeometry;
  18560. }(BufferGeometry);
  18561. var WorldUVGenerator = {
  18562. generateTopUV: function generateTopUV(geometry, vertices, indexA, indexB, indexC) {
  18563. var a_x = vertices[indexA * 3];
  18564. var a_y = vertices[indexA * 3 + 1];
  18565. var b_x = vertices[indexB * 3];
  18566. var b_y = vertices[indexB * 3 + 1];
  18567. var c_x = vertices[indexC * 3];
  18568. var c_y = vertices[indexC * 3 + 1];
  18569. return [new Vector2(a_x, a_y), new Vector2(b_x, b_y), new Vector2(c_x, c_y)];
  18570. },
  18571. generateSideWallUV: function generateSideWallUV(geometry, vertices, indexA, indexB, indexC, indexD) {
  18572. var a_x = vertices[indexA * 3];
  18573. var a_y = vertices[indexA * 3 + 1];
  18574. var a_z = vertices[indexA * 3 + 2];
  18575. var b_x = vertices[indexB * 3];
  18576. var b_y = vertices[indexB * 3 + 1];
  18577. var b_z = vertices[indexB * 3 + 2];
  18578. var c_x = vertices[indexC * 3];
  18579. var c_y = vertices[indexC * 3 + 1];
  18580. var c_z = vertices[indexC * 3 + 2];
  18581. var d_x = vertices[indexD * 3];
  18582. var d_y = vertices[indexD * 3 + 1];
  18583. var d_z = vertices[indexD * 3 + 2];
  18584. if (Math.abs(a_y - b_y) < 0.01) {
  18585. 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)];
  18586. } else {
  18587. 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)];
  18588. }
  18589. }
  18590. };
  18591. function _toJSON(shapes, options, data) {
  18592. data.shapes = [];
  18593. if (Array.isArray(shapes)) {
  18594. for (var i = 0, l = shapes.length; i < l; i++) {
  18595. var shape = shapes[i];
  18596. data.shapes.push(shape.uuid);
  18597. }
  18598. } else {
  18599. data.shapes.push(shapes.uuid);
  18600. }
  18601. if (options.extrudePath !== undefined) data.options.extrudePath = options.extrudePath.toJSON();
  18602. return data;
  18603. }
  18604. var IcosahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18605. _inheritsLoose(IcosahedronGeometry, _PolyhedronGeometry);
  18606. function IcosahedronGeometry(radius, detail) {
  18607. var _this;
  18608. if (radius === void 0) {
  18609. radius = 1;
  18610. }
  18611. if (detail === void 0) {
  18612. detail = 0;
  18613. }
  18614. var t = (1 + Math.sqrt(5)) / 2;
  18615. 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];
  18616. 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];
  18617. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18618. _this.type = 'IcosahedronGeometry';
  18619. _this.parameters = {
  18620. radius: radius,
  18621. detail: detail
  18622. };
  18623. return _this;
  18624. }
  18625. return IcosahedronGeometry;
  18626. }(PolyhedronGeometry);
  18627. var LatheGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18628. _inheritsLoose(LatheGeometry, _BufferGeometry);
  18629. function LatheGeometry(points, segments, phiStart, phiLength) {
  18630. var _this;
  18631. if (segments === void 0) {
  18632. segments = 12;
  18633. }
  18634. if (phiStart === void 0) {
  18635. phiStart = 0;
  18636. }
  18637. if (phiLength === void 0) {
  18638. phiLength = Math.PI * 2;
  18639. }
  18640. _this = _BufferGeometry.call(this) || this;
  18641. _this.type = 'LatheGeometry';
  18642. _this.parameters = {
  18643. points: points,
  18644. segments: segments,
  18645. phiStart: phiStart,
  18646. phiLength: phiLength
  18647. };
  18648. segments = Math.floor(segments); // clamp phiLength so it's in range of [ 0, 2PI ]
  18649. phiLength = MathUtils.clamp(phiLength, 0, Math.PI * 2); // buffers
  18650. var indices = [];
  18651. var vertices = [];
  18652. var uvs = []; // helper variables
  18653. var inverseSegments = 1.0 / segments;
  18654. var vertex = new Vector3();
  18655. var uv = new Vector2(); // generate vertices and uvs
  18656. for (var i = 0; i <= segments; i++) {
  18657. var phi = phiStart + i * inverseSegments * phiLength;
  18658. var sin = Math.sin(phi);
  18659. var cos = Math.cos(phi);
  18660. for (var j = 0; j <= points.length - 1; j++) {
  18661. // vertex
  18662. vertex.x = points[j].x * sin;
  18663. vertex.y = points[j].y;
  18664. vertex.z = points[j].x * cos;
  18665. vertices.push(vertex.x, vertex.y, vertex.z); // uv
  18666. uv.x = i / segments;
  18667. uv.y = j / (points.length - 1);
  18668. uvs.push(uv.x, uv.y);
  18669. }
  18670. } // indices
  18671. for (var _i = 0; _i < segments; _i++) {
  18672. for (var _j = 0; _j < points.length - 1; _j++) {
  18673. var base = _j + _i * points.length;
  18674. var a = base;
  18675. var b = base + points.length;
  18676. var c = base + points.length + 1;
  18677. var d = base + 1; // faces
  18678. indices.push(a, b, d);
  18679. indices.push(b, c, d);
  18680. }
  18681. } // build geometry
  18682. _this.setIndex(indices);
  18683. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18684. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // generate normals
  18685. _this.computeVertexNormals(); // if the geometry is closed, we need to average the normals along the seam.
  18686. // because the corresponding vertices are identical (but still have different UVs).
  18687. if (phiLength === Math.PI * 2) {
  18688. var normals = _this.attributes.normal.array;
  18689. var n1 = new Vector3();
  18690. var n2 = new Vector3();
  18691. var n = new Vector3(); // this is the buffer offset for the last line of vertices
  18692. var _base = segments * points.length * 3;
  18693. for (var _i2 = 0, _j2 = 0; _i2 < points.length; _i2++, _j2 += 3) {
  18694. // select the normal of the vertex in the first line
  18695. n1.x = normals[_j2 + 0];
  18696. n1.y = normals[_j2 + 1];
  18697. n1.z = normals[_j2 + 2]; // select the normal of the vertex in the last line
  18698. n2.x = normals[_base + _j2 + 0];
  18699. n2.y = normals[_base + _j2 + 1];
  18700. n2.z = normals[_base + _j2 + 2]; // average normals
  18701. n.addVectors(n1, n2).normalize(); // assign the new values to both normals
  18702. normals[_j2 + 0] = normals[_base + _j2 + 0] = n.x;
  18703. normals[_j2 + 1] = normals[_base + _j2 + 1] = n.y;
  18704. normals[_j2 + 2] = normals[_base + _j2 + 2] = n.z;
  18705. }
  18706. }
  18707. return _this;
  18708. }
  18709. return LatheGeometry;
  18710. }(BufferGeometry);
  18711. var OctahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  18712. _inheritsLoose(OctahedronGeometry, _PolyhedronGeometry);
  18713. function OctahedronGeometry(radius, detail) {
  18714. var _this;
  18715. if (radius === void 0) {
  18716. radius = 1;
  18717. }
  18718. if (detail === void 0) {
  18719. detail = 0;
  18720. }
  18721. var vertices = [1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1];
  18722. 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];
  18723. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  18724. _this.type = 'OctahedronGeometry';
  18725. _this.parameters = {
  18726. radius: radius,
  18727. detail: detail
  18728. };
  18729. return _this;
  18730. }
  18731. return OctahedronGeometry;
  18732. }(PolyhedronGeometry);
  18733. /**
  18734. * Parametric Surfaces Geometry
  18735. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18736. */
  18737. function ParametricGeometry(func, slices, stacks) {
  18738. BufferGeometry.call(this);
  18739. this.type = 'ParametricGeometry';
  18740. this.parameters = {
  18741. func: func,
  18742. slices: slices,
  18743. stacks: stacks
  18744. }; // buffers
  18745. var indices = [];
  18746. var vertices = [];
  18747. var normals = [];
  18748. var uvs = [];
  18749. var EPS = 0.00001;
  18750. var normal = new Vector3();
  18751. var p0 = new Vector3(),
  18752. p1 = new Vector3();
  18753. var pu = new Vector3(),
  18754. pv = new Vector3();
  18755. if (func.length < 3) {
  18756. console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');
  18757. } // generate vertices, normals and uvs
  18758. var sliceCount = slices + 1;
  18759. for (var i = 0; i <= stacks; i++) {
  18760. var v = i / stacks;
  18761. for (var j = 0; j <= slices; j++) {
  18762. var u = j / slices; // vertex
  18763. func(u, v, p0);
  18764. vertices.push(p0.x, p0.y, p0.z); // normal
  18765. // approximate tangent vectors via finite differences
  18766. if (u - EPS >= 0) {
  18767. func(u - EPS, v, p1);
  18768. pu.subVectors(p0, p1);
  18769. } else {
  18770. func(u + EPS, v, p1);
  18771. pu.subVectors(p1, p0);
  18772. }
  18773. if (v - EPS >= 0) {
  18774. func(u, v - EPS, p1);
  18775. pv.subVectors(p0, p1);
  18776. } else {
  18777. func(u, v + EPS, p1);
  18778. pv.subVectors(p1, p0);
  18779. } // cross product of tangent vectors returns surface normal
  18780. normal.crossVectors(pu, pv).normalize();
  18781. normals.push(normal.x, normal.y, normal.z); // uv
  18782. uvs.push(u, v);
  18783. }
  18784. } // generate indices
  18785. for (var _i = 0; _i < stacks; _i++) {
  18786. for (var _j = 0; _j < slices; _j++) {
  18787. var a = _i * sliceCount + _j;
  18788. var b = _i * sliceCount + _j + 1;
  18789. var c = (_i + 1) * sliceCount + _j + 1;
  18790. var d = (_i + 1) * sliceCount + _j; // faces one and two
  18791. indices.push(a, b, d);
  18792. indices.push(b, c, d);
  18793. }
  18794. } // build geometry
  18795. this.setIndex(indices);
  18796. this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18797. this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18798. this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18799. }
  18800. ParametricGeometry.prototype = Object.create(BufferGeometry.prototype);
  18801. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18802. var RingGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18803. _inheritsLoose(RingGeometry, _BufferGeometry);
  18804. function RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) {
  18805. var _this;
  18806. if (innerRadius === void 0) {
  18807. innerRadius = 0.5;
  18808. }
  18809. if (outerRadius === void 0) {
  18810. outerRadius = 1;
  18811. }
  18812. if (thetaSegments === void 0) {
  18813. thetaSegments = 8;
  18814. }
  18815. if (phiSegments === void 0) {
  18816. phiSegments = 1;
  18817. }
  18818. if (thetaStart === void 0) {
  18819. thetaStart = 0;
  18820. }
  18821. if (thetaLength === void 0) {
  18822. thetaLength = Math.PI * 2;
  18823. }
  18824. _this = _BufferGeometry.call(this) || this;
  18825. _this.type = 'RingGeometry';
  18826. _this.parameters = {
  18827. innerRadius: innerRadius,
  18828. outerRadius: outerRadius,
  18829. thetaSegments: thetaSegments,
  18830. phiSegments: phiSegments,
  18831. thetaStart: thetaStart,
  18832. thetaLength: thetaLength
  18833. };
  18834. thetaSegments = Math.max(3, thetaSegments);
  18835. phiSegments = Math.max(1, phiSegments); // buffers
  18836. var indices = [];
  18837. var vertices = [];
  18838. var normals = [];
  18839. var uvs = []; // some helper variables
  18840. var radius = innerRadius;
  18841. var radiusStep = (outerRadius - innerRadius) / phiSegments;
  18842. var vertex = new Vector3();
  18843. var uv = new Vector2(); // generate vertices, normals and uvs
  18844. for (var j = 0; j <= phiSegments; j++) {
  18845. for (var i = 0; i <= thetaSegments; i++) {
  18846. // values are generate from the inside of the ring to the outside
  18847. var segment = thetaStart + i / thetaSegments * thetaLength; // vertex
  18848. vertex.x = radius * Math.cos(segment);
  18849. vertex.y = radius * Math.sin(segment);
  18850. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  18851. normals.push(0, 0, 1); // uv
  18852. uv.x = (vertex.x / outerRadius + 1) / 2;
  18853. uv.y = (vertex.y / outerRadius + 1) / 2;
  18854. uvs.push(uv.x, uv.y);
  18855. } // increase the radius for next row of vertices
  18856. radius += radiusStep;
  18857. } // indices
  18858. for (var _j = 0; _j < phiSegments; _j++) {
  18859. var thetaSegmentLevel = _j * (thetaSegments + 1);
  18860. for (var _i = 0; _i < thetaSegments; _i++) {
  18861. var _segment = _i + thetaSegmentLevel;
  18862. var a = _segment;
  18863. var b = _segment + thetaSegments + 1;
  18864. var c = _segment + thetaSegments + 2;
  18865. var d = _segment + 1; // faces
  18866. indices.push(a, b, d);
  18867. indices.push(b, c, d);
  18868. }
  18869. } // build geometry
  18870. _this.setIndex(indices);
  18871. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18872. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18873. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  18874. return _this;
  18875. }
  18876. return RingGeometry;
  18877. }(BufferGeometry);
  18878. var ShapeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18879. _inheritsLoose(ShapeGeometry, _BufferGeometry);
  18880. function ShapeGeometry(shapes, curveSegments) {
  18881. var _this;
  18882. if (curveSegments === void 0) {
  18883. curveSegments = 12;
  18884. }
  18885. _this = _BufferGeometry.call(this) || this;
  18886. _this.type = 'ShapeGeometry';
  18887. _this.parameters = {
  18888. shapes: shapes,
  18889. curveSegments: curveSegments
  18890. }; // buffers
  18891. var indices = [];
  18892. var vertices = [];
  18893. var normals = [];
  18894. var uvs = []; // helper variables
  18895. var groupStart = 0;
  18896. var groupCount = 0; // allow single and array values for "shapes" parameter
  18897. if (Array.isArray(shapes) === false) {
  18898. addShape(shapes);
  18899. } else {
  18900. for (var i = 0; i < shapes.length; i++) {
  18901. addShape(shapes[i]);
  18902. _this.addGroup(groupStart, groupCount, i); // enables MultiMaterial support
  18903. groupStart += groupCount;
  18904. groupCount = 0;
  18905. }
  18906. } // build geometry
  18907. _this.setIndex(indices);
  18908. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  18909. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  18910. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // helper functions
  18911. function addShape(shape) {
  18912. var indexOffset = vertices.length / 3;
  18913. var points = shape.extractPoints(curveSegments);
  18914. var shapeVertices = points.shape;
  18915. var shapeHoles = points.holes; // check direction of vertices
  18916. if (ShapeUtils.isClockWise(shapeVertices) === false) {
  18917. shapeVertices = shapeVertices.reverse();
  18918. }
  18919. for (var _i = 0, l = shapeHoles.length; _i < l; _i++) {
  18920. var shapeHole = shapeHoles[_i];
  18921. if (ShapeUtils.isClockWise(shapeHole) === true) {
  18922. shapeHoles[_i] = shapeHole.reverse();
  18923. }
  18924. }
  18925. var faces = ShapeUtils.triangulateShape(shapeVertices, shapeHoles); // join vertices of inner and outer paths to a single array
  18926. for (var _i2 = 0, _l = shapeHoles.length; _i2 < _l; _i2++) {
  18927. var _shapeHole = shapeHoles[_i2];
  18928. shapeVertices = shapeVertices.concat(_shapeHole);
  18929. } // vertices, normals, uvs
  18930. for (var _i3 = 0, _l2 = shapeVertices.length; _i3 < _l2; _i3++) {
  18931. var vertex = shapeVertices[_i3];
  18932. vertices.push(vertex.x, vertex.y, 0);
  18933. normals.push(0, 0, 1);
  18934. uvs.push(vertex.x, vertex.y); // world uvs
  18935. } // incides
  18936. for (var _i4 = 0, _l3 = faces.length; _i4 < _l3; _i4++) {
  18937. var face = faces[_i4];
  18938. var a = face[0] + indexOffset;
  18939. var b = face[1] + indexOffset;
  18940. var c = face[2] + indexOffset;
  18941. indices.push(a, b, c);
  18942. groupCount += 3;
  18943. }
  18944. }
  18945. return _this;
  18946. }
  18947. var _proto = ShapeGeometry.prototype;
  18948. _proto.toJSON = function toJSON() {
  18949. var data = BufferGeometry.prototype.toJSON.call(this);
  18950. var shapes = this.parameters.shapes;
  18951. return _toJSON$1(shapes, data);
  18952. };
  18953. return ShapeGeometry;
  18954. }(BufferGeometry);
  18955. function _toJSON$1(shapes, data) {
  18956. data.shapes = [];
  18957. if (Array.isArray(shapes)) {
  18958. for (var i = 0, l = shapes.length; i < l; i++) {
  18959. var shape = shapes[i];
  18960. data.shapes.push(shape.uuid);
  18961. }
  18962. } else {
  18963. data.shapes.push(shapes.uuid);
  18964. }
  18965. return data;
  18966. }
  18967. var SphereGeometry = /*#__PURE__*/function (_BufferGeometry) {
  18968. _inheritsLoose(SphereGeometry, _BufferGeometry);
  18969. function SphereGeometry(radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength) {
  18970. var _this;
  18971. if (radius === void 0) {
  18972. radius = 1;
  18973. }
  18974. if (widthSegments === void 0) {
  18975. widthSegments = 8;
  18976. }
  18977. if (heightSegments === void 0) {
  18978. heightSegments = 6;
  18979. }
  18980. if (phiStart === void 0) {
  18981. phiStart = 0;
  18982. }
  18983. if (phiLength === void 0) {
  18984. phiLength = Math.PI * 2;
  18985. }
  18986. if (thetaStart === void 0) {
  18987. thetaStart = 0;
  18988. }
  18989. if (thetaLength === void 0) {
  18990. thetaLength = Math.PI;
  18991. }
  18992. _this = _BufferGeometry.call(this) || this;
  18993. _this.type = 'SphereGeometry';
  18994. _this.parameters = {
  18995. radius: radius,
  18996. widthSegments: widthSegments,
  18997. heightSegments: heightSegments,
  18998. phiStart: phiStart,
  18999. phiLength: phiLength,
  19000. thetaStart: thetaStart,
  19001. thetaLength: thetaLength
  19002. };
  19003. widthSegments = Math.max(3, Math.floor(widthSegments));
  19004. heightSegments = Math.max(2, Math.floor(heightSegments));
  19005. var thetaEnd = Math.min(thetaStart + thetaLength, Math.PI);
  19006. var index = 0;
  19007. var grid = [];
  19008. var vertex = new Vector3();
  19009. var normal = new Vector3(); // buffers
  19010. var indices = [];
  19011. var vertices = [];
  19012. var normals = [];
  19013. var uvs = []; // generate vertices, normals and uvs
  19014. for (var iy = 0; iy <= heightSegments; iy++) {
  19015. var verticesRow = [];
  19016. var v = iy / heightSegments; // special case for the poles
  19017. var uOffset = 0;
  19018. if (iy == 0 && thetaStart == 0) {
  19019. uOffset = 0.5 / widthSegments;
  19020. } else if (iy == heightSegments && thetaEnd == Math.PI) {
  19021. uOffset = -0.5 / widthSegments;
  19022. }
  19023. for (var ix = 0; ix <= widthSegments; ix++) {
  19024. var u = ix / widthSegments; // vertex
  19025. vertex.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19026. vertex.y = radius * Math.cos(thetaStart + v * thetaLength);
  19027. vertex.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength);
  19028. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19029. normal.copy(vertex).normalize();
  19030. normals.push(normal.x, normal.y, normal.z); // uv
  19031. uvs.push(u + uOffset, 1 - v);
  19032. verticesRow.push(index++);
  19033. }
  19034. grid.push(verticesRow);
  19035. } // indices
  19036. for (var _iy = 0; _iy < heightSegments; _iy++) {
  19037. for (var _ix = 0; _ix < widthSegments; _ix++) {
  19038. var a = grid[_iy][_ix + 1];
  19039. var b = grid[_iy][_ix];
  19040. var c = grid[_iy + 1][_ix];
  19041. var d = grid[_iy + 1][_ix + 1];
  19042. if (_iy !== 0 || thetaStart > 0) indices.push(a, b, d);
  19043. if (_iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c, d);
  19044. }
  19045. } // build geometry
  19046. _this.setIndex(indices);
  19047. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19048. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19049. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19050. return _this;
  19051. }
  19052. return SphereGeometry;
  19053. }(BufferGeometry);
  19054. var TetrahedronGeometry = /*#__PURE__*/function (_PolyhedronGeometry) {
  19055. _inheritsLoose(TetrahedronGeometry, _PolyhedronGeometry);
  19056. function TetrahedronGeometry(radius, detail) {
  19057. var _this;
  19058. if (radius === void 0) {
  19059. radius = 1;
  19060. }
  19061. if (detail === void 0) {
  19062. detail = 0;
  19063. }
  19064. var vertices = [1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1];
  19065. var indices = [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1];
  19066. _this = _PolyhedronGeometry.call(this, vertices, indices, radius, detail) || this;
  19067. _this.type = 'TetrahedronGeometry';
  19068. _this.parameters = {
  19069. radius: radius,
  19070. detail: detail
  19071. };
  19072. return _this;
  19073. }
  19074. return TetrahedronGeometry;
  19075. }(PolyhedronGeometry);
  19076. var TextGeometry = /*#__PURE__*/function (_ExtrudeGeometry) {
  19077. _inheritsLoose(TextGeometry, _ExtrudeGeometry);
  19078. function TextGeometry(text, parameters) {
  19079. var _this;
  19080. if (parameters === void 0) {
  19081. parameters = {};
  19082. }
  19083. var font = parameters.font;
  19084. if (!(font && font.isFont)) {
  19085. console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');
  19086. return new BufferGeometry() || _assertThisInitialized(_this);
  19087. }
  19088. var shapes = font.generateShapes(text, parameters.size); // translate parameters to ExtrudeGeometry API
  19089. parameters.depth = parameters.height !== undefined ? parameters.height : 50; // defaults
  19090. if (parameters.bevelThickness === undefined) parameters.bevelThickness = 10;
  19091. if (parameters.bevelSize === undefined) parameters.bevelSize = 8;
  19092. if (parameters.bevelEnabled === undefined) parameters.bevelEnabled = false;
  19093. _this = _ExtrudeGeometry.call(this, shapes, parameters) || this;
  19094. _this.type = 'TextGeometry';
  19095. return _this;
  19096. }
  19097. return TextGeometry;
  19098. }(ExtrudeGeometry);
  19099. var TorusGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19100. _inheritsLoose(TorusGeometry, _BufferGeometry);
  19101. function TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) {
  19102. var _this;
  19103. if (radius === void 0) {
  19104. radius = 1;
  19105. }
  19106. if (tube === void 0) {
  19107. tube = 0.4;
  19108. }
  19109. if (radialSegments === void 0) {
  19110. radialSegments = 8;
  19111. }
  19112. if (tubularSegments === void 0) {
  19113. tubularSegments = 6;
  19114. }
  19115. if (arc === void 0) {
  19116. arc = Math.PI * 2;
  19117. }
  19118. _this = _BufferGeometry.call(this) || this;
  19119. _this.type = 'TorusGeometry';
  19120. _this.parameters = {
  19121. radius: radius,
  19122. tube: tube,
  19123. radialSegments: radialSegments,
  19124. tubularSegments: tubularSegments,
  19125. arc: arc
  19126. };
  19127. radialSegments = Math.floor(radialSegments);
  19128. tubularSegments = Math.floor(tubularSegments); // buffers
  19129. var indices = [];
  19130. var vertices = [];
  19131. var normals = [];
  19132. var uvs = []; // helper variables
  19133. var center = new Vector3();
  19134. var vertex = new Vector3();
  19135. var normal = new Vector3(); // generate vertices, normals and uvs
  19136. for (var j = 0; j <= radialSegments; j++) {
  19137. for (var i = 0; i <= tubularSegments; i++) {
  19138. var u = i / tubularSegments * arc;
  19139. var v = j / radialSegments * Math.PI * 2; // vertex
  19140. vertex.x = (radius + tube * Math.cos(v)) * Math.cos(u);
  19141. vertex.y = (radius + tube * Math.cos(v)) * Math.sin(u);
  19142. vertex.z = tube * Math.sin(v);
  19143. vertices.push(vertex.x, vertex.y, vertex.z); // normal
  19144. center.x = radius * Math.cos(u);
  19145. center.y = radius * Math.sin(u);
  19146. normal.subVectors(vertex, center).normalize();
  19147. normals.push(normal.x, normal.y, normal.z); // uv
  19148. uvs.push(i / tubularSegments);
  19149. uvs.push(j / radialSegments);
  19150. }
  19151. } // generate indices
  19152. for (var _j = 1; _j <= radialSegments; _j++) {
  19153. for (var _i = 1; _i <= tubularSegments; _i++) {
  19154. // indices
  19155. var a = (tubularSegments + 1) * _j + _i - 1;
  19156. var b = (tubularSegments + 1) * (_j - 1) + _i - 1;
  19157. var c = (tubularSegments + 1) * (_j - 1) + _i;
  19158. var d = (tubularSegments + 1) * _j + _i; // faces
  19159. indices.push(a, b, d);
  19160. indices.push(b, c, d);
  19161. }
  19162. } // build geometry
  19163. _this.setIndex(indices);
  19164. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19165. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19166. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2));
  19167. return _this;
  19168. }
  19169. return TorusGeometry;
  19170. }(BufferGeometry);
  19171. var TorusKnotGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19172. _inheritsLoose(TorusKnotGeometry, _BufferGeometry);
  19173. function TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) {
  19174. var _this;
  19175. if (radius === void 0) {
  19176. radius = 1;
  19177. }
  19178. if (tube === void 0) {
  19179. tube = 0.4;
  19180. }
  19181. if (tubularSegments === void 0) {
  19182. tubularSegments = 64;
  19183. }
  19184. if (radialSegments === void 0) {
  19185. radialSegments = 8;
  19186. }
  19187. if (p === void 0) {
  19188. p = 2;
  19189. }
  19190. if (q === void 0) {
  19191. q = 3;
  19192. }
  19193. _this = _BufferGeometry.call(this) || this;
  19194. _this.type = 'TorusKnotGeometry';
  19195. _this.parameters = {
  19196. radius: radius,
  19197. tube: tube,
  19198. tubularSegments: tubularSegments,
  19199. radialSegments: radialSegments,
  19200. p: p,
  19201. q: q
  19202. };
  19203. tubularSegments = Math.floor(tubularSegments);
  19204. radialSegments = Math.floor(radialSegments); // buffers
  19205. var indices = [];
  19206. var vertices = [];
  19207. var normals = [];
  19208. var uvs = []; // helper variables
  19209. var vertex = new Vector3();
  19210. var normal = new Vector3();
  19211. var P1 = new Vector3();
  19212. var P2 = new Vector3();
  19213. var B = new Vector3();
  19214. var T = new Vector3();
  19215. var N = new Vector3(); // generate vertices, normals and uvs
  19216. for (var i = 0; i <= tubularSegments; ++i) {
  19217. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19218. 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.
  19219. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19220. calculatePositionOnCurve(u, p, q, radius, P1);
  19221. calculatePositionOnCurve(u + 0.01, p, q, radius, P2); // calculate orthonormal basis
  19222. T.subVectors(P2, P1);
  19223. N.addVectors(P2, P1);
  19224. B.crossVectors(T, N);
  19225. N.crossVectors(B, T); // normalize B, N. T can be ignored, we don't use it
  19226. B.normalize();
  19227. N.normalize();
  19228. for (var j = 0; j <= radialSegments; ++j) {
  19229. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19230. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19231. var v = j / radialSegments * Math.PI * 2;
  19232. var cx = -tube * Math.cos(v);
  19233. var cy = tube * Math.sin(v); // now calculate the final vertex position.
  19234. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19235. vertex.x = P1.x + (cx * N.x + cy * B.x);
  19236. vertex.y = P1.y + (cx * N.y + cy * B.y);
  19237. vertex.z = P1.z + (cx * N.z + cy * B.z);
  19238. 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)
  19239. normal.subVectors(vertex, P1).normalize();
  19240. normals.push(normal.x, normal.y, normal.z); // uv
  19241. uvs.push(i / tubularSegments);
  19242. uvs.push(j / radialSegments);
  19243. }
  19244. } // generate indices
  19245. for (var _j = 1; _j <= tubularSegments; _j++) {
  19246. for (var _i = 1; _i <= radialSegments; _i++) {
  19247. // indices
  19248. var a = (radialSegments + 1) * (_j - 1) + (_i - 1);
  19249. var b = (radialSegments + 1) * _j + (_i - 1);
  19250. var c = (radialSegments + 1) * _j + _i;
  19251. var d = (radialSegments + 1) * (_j - 1) + _i; // faces
  19252. indices.push(a, b, d);
  19253. indices.push(b, c, d);
  19254. }
  19255. } // build geometry
  19256. _this.setIndex(indices);
  19257. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19258. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19259. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // this function calculates the current position on the torus curve
  19260. function calculatePositionOnCurve(u, p, q, radius, position) {
  19261. var cu = Math.cos(u);
  19262. var su = Math.sin(u);
  19263. var quOverP = q / p * u;
  19264. var cs = Math.cos(quOverP);
  19265. position.x = radius * (2 + cs) * 0.5 * cu;
  19266. position.y = radius * (2 + cs) * su * 0.5;
  19267. position.z = radius * Math.sin(quOverP) * 0.5;
  19268. }
  19269. return _this;
  19270. }
  19271. return TorusKnotGeometry;
  19272. }(BufferGeometry);
  19273. var TubeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19274. _inheritsLoose(TubeGeometry, _BufferGeometry);
  19275. function TubeGeometry(path, tubularSegments, radius, radialSegments, closed) {
  19276. var _this;
  19277. if (tubularSegments === void 0) {
  19278. tubularSegments = 64;
  19279. }
  19280. if (radius === void 0) {
  19281. radius = 1;
  19282. }
  19283. if (radialSegments === void 0) {
  19284. radialSegments = 8;
  19285. }
  19286. if (closed === void 0) {
  19287. closed = false;
  19288. }
  19289. _this = _BufferGeometry.call(this) || this;
  19290. _this.type = 'TubeGeometry';
  19291. _this.parameters = {
  19292. path: path,
  19293. tubularSegments: tubularSegments,
  19294. radius: radius,
  19295. radialSegments: radialSegments,
  19296. closed: closed
  19297. };
  19298. var frames = path.computeFrenetFrames(tubularSegments, closed); // expose internals
  19299. _this.tangents = frames.tangents;
  19300. _this.normals = frames.normals;
  19301. _this.binormals = frames.binormals; // helper variables
  19302. var vertex = new Vector3();
  19303. var normal = new Vector3();
  19304. var uv = new Vector2();
  19305. var P = new Vector3(); // buffer
  19306. var vertices = [];
  19307. var normals = [];
  19308. var uvs = [];
  19309. var indices = []; // create buffer data
  19310. generateBufferData(); // build geometry
  19311. _this.setIndex(indices);
  19312. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19313. _this.setAttribute('normal', new Float32BufferAttribute(normals, 3));
  19314. _this.setAttribute('uv', new Float32BufferAttribute(uvs, 2)); // functions
  19315. function generateBufferData() {
  19316. for (var i = 0; i < tubularSegments; i++) {
  19317. generateSegment(i);
  19318. } // if the geometry is not closed, generate the last row of vertices and normals
  19319. // at the regular position on the given path
  19320. //
  19321. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19322. generateSegment(closed === false ? tubularSegments : 0); // uvs are generated in a separate function.
  19323. // this makes it easy compute correct values for closed geometries
  19324. generateUVs(); // finally create faces
  19325. generateIndices();
  19326. }
  19327. function generateSegment(i) {
  19328. // we use getPointAt to sample evenly distributed points from the given path
  19329. P = path.getPointAt(i / tubularSegments, P); // retrieve corresponding normal and binormal
  19330. var N = frames.normals[i];
  19331. var B = frames.binormals[i]; // generate normals and vertices for the current segment
  19332. for (var j = 0; j <= radialSegments; j++) {
  19333. var v = j / radialSegments * Math.PI * 2;
  19334. var sin = Math.sin(v);
  19335. var cos = -Math.cos(v); // normal
  19336. normal.x = cos * N.x + sin * B.x;
  19337. normal.y = cos * N.y + sin * B.y;
  19338. normal.z = cos * N.z + sin * B.z;
  19339. normal.normalize();
  19340. normals.push(normal.x, normal.y, normal.z); // vertex
  19341. vertex.x = P.x + radius * normal.x;
  19342. vertex.y = P.y + radius * normal.y;
  19343. vertex.z = P.z + radius * normal.z;
  19344. vertices.push(vertex.x, vertex.y, vertex.z);
  19345. }
  19346. }
  19347. function generateIndices() {
  19348. for (var j = 1; j <= tubularSegments; j++) {
  19349. for (var i = 1; i <= radialSegments; i++) {
  19350. var a = (radialSegments + 1) * (j - 1) + (i - 1);
  19351. var b = (radialSegments + 1) * j + (i - 1);
  19352. var c = (radialSegments + 1) * j + i;
  19353. var d = (radialSegments + 1) * (j - 1) + i; // faces
  19354. indices.push(a, b, d);
  19355. indices.push(b, c, d);
  19356. }
  19357. }
  19358. }
  19359. function generateUVs() {
  19360. for (var i = 0; i <= tubularSegments; i++) {
  19361. for (var j = 0; j <= radialSegments; j++) {
  19362. uv.x = i / tubularSegments;
  19363. uv.y = j / radialSegments;
  19364. uvs.push(uv.x, uv.y);
  19365. }
  19366. }
  19367. }
  19368. return _this;
  19369. }
  19370. var _proto = TubeGeometry.prototype;
  19371. _proto.toJSON = function toJSON() {
  19372. var data = BufferGeometry.prototype.toJSON.call(this);
  19373. data.path = this.parameters.path.toJSON();
  19374. return data;
  19375. };
  19376. return TubeGeometry;
  19377. }(BufferGeometry);
  19378. var WireframeGeometry = /*#__PURE__*/function (_BufferGeometry) {
  19379. _inheritsLoose(WireframeGeometry, _BufferGeometry);
  19380. function WireframeGeometry(geometry) {
  19381. var _this;
  19382. _this = _BufferGeometry.call(this) || this;
  19383. _this.type = 'WireframeGeometry';
  19384. if (geometry.isGeometry === true) {
  19385. console.error('THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');
  19386. return _assertThisInitialized(_this);
  19387. } // buffer
  19388. var vertices = []; // helper variables
  19389. var edge = [0, 0],
  19390. edges = {};
  19391. var vertex = new Vector3();
  19392. if (geometry.index !== null) {
  19393. // indexed BufferGeometry
  19394. var position = geometry.attributes.position;
  19395. var indices = geometry.index;
  19396. var groups = geometry.groups;
  19397. if (groups.length === 0) {
  19398. groups = [{
  19399. start: 0,
  19400. count: indices.count,
  19401. materialIndex: 0
  19402. }];
  19403. } // create a data structure that contains all eges without duplicates
  19404. for (var o = 0, ol = groups.length; o < ol; ++o) {
  19405. var group = groups[o];
  19406. var start = group.start;
  19407. var count = group.count;
  19408. for (var i = start, l = start + count; i < l; i += 3) {
  19409. for (var j = 0; j < 3; j++) {
  19410. var edge1 = indices.getX(i + j);
  19411. var edge2 = indices.getX(i + (j + 1) % 3);
  19412. edge[0] = Math.min(edge1, edge2); // sorting prevents duplicates
  19413. edge[1] = Math.max(edge1, edge2);
  19414. var key = edge[0] + ',' + edge[1];
  19415. if (edges[key] === undefined) {
  19416. edges[key] = {
  19417. index1: edge[0],
  19418. index2: edge[1]
  19419. };
  19420. }
  19421. }
  19422. }
  19423. } // generate vertices
  19424. for (var _key in edges) {
  19425. var e = edges[_key];
  19426. vertex.fromBufferAttribute(position, e.index1);
  19427. vertices.push(vertex.x, vertex.y, vertex.z);
  19428. vertex.fromBufferAttribute(position, e.index2);
  19429. vertices.push(vertex.x, vertex.y, vertex.z);
  19430. }
  19431. } else {
  19432. // non-indexed BufferGeometry
  19433. var _position = geometry.attributes.position;
  19434. for (var _i = 0, _l = _position.count / 3; _i < _l; _i++) {
  19435. for (var _j = 0; _j < 3; _j++) {
  19436. // three edges per triangle, an edge is represented as (index1, index2)
  19437. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19438. var index1 = 3 * _i + _j;
  19439. vertex.fromBufferAttribute(_position, index1);
  19440. vertices.push(vertex.x, vertex.y, vertex.z);
  19441. var index2 = 3 * _i + (_j + 1) % 3;
  19442. vertex.fromBufferAttribute(_position, index2);
  19443. vertices.push(vertex.x, vertex.y, vertex.z);
  19444. }
  19445. }
  19446. } // build geometry
  19447. _this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  19448. return _this;
  19449. }
  19450. return WireframeGeometry;
  19451. }(BufferGeometry);
  19452. var Geometries = /*#__PURE__*/Object.freeze({
  19453. __proto__: null,
  19454. BoxGeometry: BoxGeometry,
  19455. BoxBufferGeometry: BoxGeometry,
  19456. CircleGeometry: CircleGeometry,
  19457. CircleBufferGeometry: CircleGeometry,
  19458. ConeGeometry: ConeGeometry,
  19459. ConeBufferGeometry: ConeGeometry,
  19460. CylinderGeometry: CylinderGeometry,
  19461. CylinderBufferGeometry: CylinderGeometry,
  19462. DodecahedronGeometry: DodecahedronGeometry,
  19463. DodecahedronBufferGeometry: DodecahedronGeometry,
  19464. EdgesGeometry: EdgesGeometry,
  19465. ExtrudeGeometry: ExtrudeGeometry,
  19466. ExtrudeBufferGeometry: ExtrudeGeometry,
  19467. IcosahedronGeometry: IcosahedronGeometry,
  19468. IcosahedronBufferGeometry: IcosahedronGeometry,
  19469. LatheGeometry: LatheGeometry,
  19470. LatheBufferGeometry: LatheGeometry,
  19471. OctahedronGeometry: OctahedronGeometry,
  19472. OctahedronBufferGeometry: OctahedronGeometry,
  19473. ParametricGeometry: ParametricGeometry,
  19474. ParametricBufferGeometry: ParametricGeometry,
  19475. PlaneGeometry: PlaneGeometry,
  19476. PlaneBufferGeometry: PlaneGeometry,
  19477. PolyhedronGeometry: PolyhedronGeometry,
  19478. PolyhedronBufferGeometry: PolyhedronGeometry,
  19479. RingGeometry: RingGeometry,
  19480. RingBufferGeometry: RingGeometry,
  19481. ShapeGeometry: ShapeGeometry,
  19482. ShapeBufferGeometry: ShapeGeometry,
  19483. SphereGeometry: SphereGeometry,
  19484. SphereBufferGeometry: SphereGeometry,
  19485. TetrahedronGeometry: TetrahedronGeometry,
  19486. TetrahedronBufferGeometry: TetrahedronGeometry,
  19487. TextGeometry: TextGeometry,
  19488. TextBufferGeometry: TextGeometry,
  19489. TorusGeometry: TorusGeometry,
  19490. TorusBufferGeometry: TorusGeometry,
  19491. TorusKnotGeometry: TorusKnotGeometry,
  19492. TorusKnotBufferGeometry: TorusKnotGeometry,
  19493. TubeGeometry: TubeGeometry,
  19494. TubeBufferGeometry: TubeGeometry,
  19495. WireframeGeometry: WireframeGeometry
  19496. });
  19497. /**
  19498. * parameters = {
  19499. * color: <THREE.Color>
  19500. * }
  19501. */
  19502. function ShadowMaterial(parameters) {
  19503. Material.call(this);
  19504. this.type = 'ShadowMaterial';
  19505. this.color = new Color(0x000000);
  19506. this.transparent = true;
  19507. this.setValues(parameters);
  19508. }
  19509. ShadowMaterial.prototype = Object.create(Material.prototype);
  19510. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19511. ShadowMaterial.prototype.isShadowMaterial = true;
  19512. ShadowMaterial.prototype.copy = function (source) {
  19513. Material.prototype.copy.call(this, source);
  19514. this.color.copy(source.color);
  19515. return this;
  19516. };
  19517. function RawShaderMaterial(parameters) {
  19518. ShaderMaterial.call(this, parameters);
  19519. this.type = 'RawShaderMaterial';
  19520. }
  19521. RawShaderMaterial.prototype = Object.create(ShaderMaterial.prototype);
  19522. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19523. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19524. /**
  19525. * parameters = {
  19526. * color: <hex>,
  19527. * roughness: <float>,
  19528. * metalness: <float>,
  19529. * opacity: <float>,
  19530. *
  19531. * map: new THREE.Texture( <Image> ),
  19532. *
  19533. * lightMap: new THREE.Texture( <Image> ),
  19534. * lightMapIntensity: <float>
  19535. *
  19536. * aoMap: new THREE.Texture( <Image> ),
  19537. * aoMapIntensity: <float>
  19538. *
  19539. * emissive: <hex>,
  19540. * emissiveIntensity: <float>
  19541. * emissiveMap: new THREE.Texture( <Image> ),
  19542. *
  19543. * bumpMap: new THREE.Texture( <Image> ),
  19544. * bumpScale: <float>,
  19545. *
  19546. * normalMap: new THREE.Texture( <Image> ),
  19547. * normalMapType: THREE.TangentSpaceNormalMap,
  19548. * normalScale: <Vector2>,
  19549. *
  19550. * displacementMap: new THREE.Texture( <Image> ),
  19551. * displacementScale: <float>,
  19552. * displacementBias: <float>,
  19553. *
  19554. * roughnessMap: new THREE.Texture( <Image> ),
  19555. *
  19556. * metalnessMap: new THREE.Texture( <Image> ),
  19557. *
  19558. * alphaMap: new THREE.Texture( <Image> ),
  19559. *
  19560. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19561. * envMapIntensity: <float>
  19562. *
  19563. * refractionRatio: <float>,
  19564. *
  19565. * wireframe: <boolean>,
  19566. * wireframeLinewidth: <float>,
  19567. *
  19568. * skinning: <bool>,
  19569. * morphTargets: <bool>,
  19570. * morphNormals: <bool>
  19571. * }
  19572. */
  19573. function MeshStandardMaterial(parameters) {
  19574. Material.call(this);
  19575. this.defines = {
  19576. 'STANDARD': ''
  19577. };
  19578. this.type = 'MeshStandardMaterial';
  19579. this.color = new Color(0xffffff); // diffuse
  19580. this.roughness = 1.0;
  19581. this.metalness = 0.0;
  19582. this.map = null;
  19583. this.lightMap = null;
  19584. this.lightMapIntensity = 1.0;
  19585. this.aoMap = null;
  19586. this.aoMapIntensity = 1.0;
  19587. this.emissive = new Color(0x000000);
  19588. this.emissiveIntensity = 1.0;
  19589. this.emissiveMap = null;
  19590. this.bumpMap = null;
  19591. this.bumpScale = 1;
  19592. this.normalMap = null;
  19593. this.normalMapType = TangentSpaceNormalMap;
  19594. this.normalScale = new Vector2(1, 1);
  19595. this.displacementMap = null;
  19596. this.displacementScale = 1;
  19597. this.displacementBias = 0;
  19598. this.roughnessMap = null;
  19599. this.metalnessMap = null;
  19600. this.alphaMap = null;
  19601. this.envMap = null;
  19602. this.envMapIntensity = 1.0;
  19603. this.refractionRatio = 0.98;
  19604. this.wireframe = false;
  19605. this.wireframeLinewidth = 1;
  19606. this.wireframeLinecap = 'round';
  19607. this.wireframeLinejoin = 'round';
  19608. this.skinning = false;
  19609. this.morphTargets = false;
  19610. this.morphNormals = false;
  19611. this.vertexTangents = false;
  19612. this.setValues(parameters);
  19613. }
  19614. MeshStandardMaterial.prototype = Object.create(Material.prototype);
  19615. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19616. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19617. MeshStandardMaterial.prototype.copy = function (source) {
  19618. Material.prototype.copy.call(this, source);
  19619. this.defines = {
  19620. 'STANDARD': ''
  19621. };
  19622. this.color.copy(source.color);
  19623. this.roughness = source.roughness;
  19624. this.metalness = source.metalness;
  19625. this.map = source.map;
  19626. this.lightMap = source.lightMap;
  19627. this.lightMapIntensity = source.lightMapIntensity;
  19628. this.aoMap = source.aoMap;
  19629. this.aoMapIntensity = source.aoMapIntensity;
  19630. this.emissive.copy(source.emissive);
  19631. this.emissiveMap = source.emissiveMap;
  19632. this.emissiveIntensity = source.emissiveIntensity;
  19633. this.bumpMap = source.bumpMap;
  19634. this.bumpScale = source.bumpScale;
  19635. this.normalMap = source.normalMap;
  19636. this.normalMapType = source.normalMapType;
  19637. this.normalScale.copy(source.normalScale);
  19638. this.displacementMap = source.displacementMap;
  19639. this.displacementScale = source.displacementScale;
  19640. this.displacementBias = source.displacementBias;
  19641. this.roughnessMap = source.roughnessMap;
  19642. this.metalnessMap = source.metalnessMap;
  19643. this.alphaMap = source.alphaMap;
  19644. this.envMap = source.envMap;
  19645. this.envMapIntensity = source.envMapIntensity;
  19646. this.refractionRatio = source.refractionRatio;
  19647. this.wireframe = source.wireframe;
  19648. this.wireframeLinewidth = source.wireframeLinewidth;
  19649. this.wireframeLinecap = source.wireframeLinecap;
  19650. this.wireframeLinejoin = source.wireframeLinejoin;
  19651. this.skinning = source.skinning;
  19652. this.morphTargets = source.morphTargets;
  19653. this.morphNormals = source.morphNormals;
  19654. this.vertexTangents = source.vertexTangents;
  19655. return this;
  19656. };
  19657. /**
  19658. * parameters = {
  19659. * clearcoat: <float>,
  19660. * clearcoatMap: new THREE.Texture( <Image> ),
  19661. * clearcoatRoughness: <float>,
  19662. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19663. * clearcoatNormalScale: <Vector2>,
  19664. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19665. *
  19666. * reflectivity: <float>,
  19667. * ior: <float>,
  19668. *
  19669. * sheen: <Color>,
  19670. *
  19671. * transmission: <float>,
  19672. * transmissionMap: new THREE.Texture( <Image> )
  19673. * }
  19674. */
  19675. function MeshPhysicalMaterial(parameters) {
  19676. MeshStandardMaterial.call(this);
  19677. this.defines = {
  19678. 'STANDARD': '',
  19679. 'PHYSICAL': ''
  19680. };
  19681. this.type = 'MeshPhysicalMaterial';
  19682. this.clearcoat = 0.0;
  19683. this.clearcoatMap = null;
  19684. this.clearcoatRoughness = 0.0;
  19685. this.clearcoatRoughnessMap = null;
  19686. this.clearcoatNormalScale = new Vector2(1, 1);
  19687. this.clearcoatNormalMap = null;
  19688. this.reflectivity = 0.5; // maps to F0 = 0.04
  19689. Object.defineProperty(this, 'ior', {
  19690. get: function get() {
  19691. return (1 + 0.4 * this.reflectivity) / (1 - 0.4 * this.reflectivity);
  19692. },
  19693. set: function set(ior) {
  19694. this.reflectivity = MathUtils.clamp(2.5 * (ior - 1) / (ior + 1), 0, 1);
  19695. }
  19696. });
  19697. this.sheen = null; // null will disable sheen bsdf
  19698. this.transmission = 0.0;
  19699. this.transmissionMap = null;
  19700. this.setValues(parameters);
  19701. }
  19702. MeshPhysicalMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
  19703. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19704. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19705. MeshPhysicalMaterial.prototype.copy = function (source) {
  19706. MeshStandardMaterial.prototype.copy.call(this, source);
  19707. this.defines = {
  19708. 'STANDARD': '',
  19709. 'PHYSICAL': ''
  19710. };
  19711. this.clearcoat = source.clearcoat;
  19712. this.clearcoatMap = source.clearcoatMap;
  19713. this.clearcoatRoughness = source.clearcoatRoughness;
  19714. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  19715. this.clearcoatNormalMap = source.clearcoatNormalMap;
  19716. this.clearcoatNormalScale.copy(source.clearcoatNormalScale);
  19717. this.reflectivity = source.reflectivity;
  19718. if (source.sheen) {
  19719. this.sheen = (this.sheen || new Color()).copy(source.sheen);
  19720. } else {
  19721. this.sheen = null;
  19722. }
  19723. this.transmission = source.transmission;
  19724. this.transmissionMap = source.transmissionMap;
  19725. return this;
  19726. };
  19727. /**
  19728. * parameters = {
  19729. * color: <hex>,
  19730. * specular: <hex>,
  19731. * shininess: <float>,
  19732. * opacity: <float>,
  19733. *
  19734. * map: new THREE.Texture( <Image> ),
  19735. *
  19736. * lightMap: new THREE.Texture( <Image> ),
  19737. * lightMapIntensity: <float>
  19738. *
  19739. * aoMap: new THREE.Texture( <Image> ),
  19740. * aoMapIntensity: <float>
  19741. *
  19742. * emissive: <hex>,
  19743. * emissiveIntensity: <float>
  19744. * emissiveMap: new THREE.Texture( <Image> ),
  19745. *
  19746. * bumpMap: new THREE.Texture( <Image> ),
  19747. * bumpScale: <float>,
  19748. *
  19749. * normalMap: new THREE.Texture( <Image> ),
  19750. * normalMapType: THREE.TangentSpaceNormalMap,
  19751. * normalScale: <Vector2>,
  19752. *
  19753. * displacementMap: new THREE.Texture( <Image> ),
  19754. * displacementScale: <float>,
  19755. * displacementBias: <float>,
  19756. *
  19757. * specularMap: new THREE.Texture( <Image> ),
  19758. *
  19759. * alphaMap: new THREE.Texture( <Image> ),
  19760. *
  19761. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19762. * combine: THREE.MultiplyOperation,
  19763. * reflectivity: <float>,
  19764. * refractionRatio: <float>,
  19765. *
  19766. * wireframe: <boolean>,
  19767. * wireframeLinewidth: <float>,
  19768. *
  19769. * skinning: <bool>,
  19770. * morphTargets: <bool>,
  19771. * morphNormals: <bool>
  19772. * }
  19773. */
  19774. function MeshPhongMaterial(parameters) {
  19775. Material.call(this);
  19776. this.type = 'MeshPhongMaterial';
  19777. this.color = new Color(0xffffff); // diffuse
  19778. this.specular = new Color(0x111111);
  19779. this.shininess = 30;
  19780. this.map = null;
  19781. this.lightMap = null;
  19782. this.lightMapIntensity = 1.0;
  19783. this.aoMap = null;
  19784. this.aoMapIntensity = 1.0;
  19785. this.emissive = new Color(0x000000);
  19786. this.emissiveIntensity = 1.0;
  19787. this.emissiveMap = null;
  19788. this.bumpMap = null;
  19789. this.bumpScale = 1;
  19790. this.normalMap = null;
  19791. this.normalMapType = TangentSpaceNormalMap;
  19792. this.normalScale = new Vector2(1, 1);
  19793. this.displacementMap = null;
  19794. this.displacementScale = 1;
  19795. this.displacementBias = 0;
  19796. this.specularMap = null;
  19797. this.alphaMap = null;
  19798. this.envMap = null;
  19799. this.combine = MultiplyOperation;
  19800. this.reflectivity = 1;
  19801. this.refractionRatio = 0.98;
  19802. this.wireframe = false;
  19803. this.wireframeLinewidth = 1;
  19804. this.wireframeLinecap = 'round';
  19805. this.wireframeLinejoin = 'round';
  19806. this.skinning = false;
  19807. this.morphTargets = false;
  19808. this.morphNormals = false;
  19809. this.setValues(parameters);
  19810. }
  19811. MeshPhongMaterial.prototype = Object.create(Material.prototype);
  19812. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19813. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19814. MeshPhongMaterial.prototype.copy = function (source) {
  19815. Material.prototype.copy.call(this, source);
  19816. this.color.copy(source.color);
  19817. this.specular.copy(source.specular);
  19818. this.shininess = source.shininess;
  19819. this.map = source.map;
  19820. this.lightMap = source.lightMap;
  19821. this.lightMapIntensity = source.lightMapIntensity;
  19822. this.aoMap = source.aoMap;
  19823. this.aoMapIntensity = source.aoMapIntensity;
  19824. this.emissive.copy(source.emissive);
  19825. this.emissiveMap = source.emissiveMap;
  19826. this.emissiveIntensity = source.emissiveIntensity;
  19827. this.bumpMap = source.bumpMap;
  19828. this.bumpScale = source.bumpScale;
  19829. this.normalMap = source.normalMap;
  19830. this.normalMapType = source.normalMapType;
  19831. this.normalScale.copy(source.normalScale);
  19832. this.displacementMap = source.displacementMap;
  19833. this.displacementScale = source.displacementScale;
  19834. this.displacementBias = source.displacementBias;
  19835. this.specularMap = source.specularMap;
  19836. this.alphaMap = source.alphaMap;
  19837. this.envMap = source.envMap;
  19838. this.combine = source.combine;
  19839. this.reflectivity = source.reflectivity;
  19840. this.refractionRatio = source.refractionRatio;
  19841. this.wireframe = source.wireframe;
  19842. this.wireframeLinewidth = source.wireframeLinewidth;
  19843. this.wireframeLinecap = source.wireframeLinecap;
  19844. this.wireframeLinejoin = source.wireframeLinejoin;
  19845. this.skinning = source.skinning;
  19846. this.morphTargets = source.morphTargets;
  19847. this.morphNormals = source.morphNormals;
  19848. return this;
  19849. };
  19850. /**
  19851. * parameters = {
  19852. * color: <hex>,
  19853. *
  19854. * map: new THREE.Texture( <Image> ),
  19855. * gradientMap: new THREE.Texture( <Image> ),
  19856. *
  19857. * lightMap: new THREE.Texture( <Image> ),
  19858. * lightMapIntensity: <float>
  19859. *
  19860. * aoMap: new THREE.Texture( <Image> ),
  19861. * aoMapIntensity: <float>
  19862. *
  19863. * emissive: <hex>,
  19864. * emissiveIntensity: <float>
  19865. * emissiveMap: new THREE.Texture( <Image> ),
  19866. *
  19867. * bumpMap: new THREE.Texture( <Image> ),
  19868. * bumpScale: <float>,
  19869. *
  19870. * normalMap: new THREE.Texture( <Image> ),
  19871. * normalMapType: THREE.TangentSpaceNormalMap,
  19872. * normalScale: <Vector2>,
  19873. *
  19874. * displacementMap: new THREE.Texture( <Image> ),
  19875. * displacementScale: <float>,
  19876. * displacementBias: <float>,
  19877. *
  19878. * alphaMap: new THREE.Texture( <Image> ),
  19879. *
  19880. * wireframe: <boolean>,
  19881. * wireframeLinewidth: <float>,
  19882. *
  19883. * skinning: <bool>,
  19884. * morphTargets: <bool>,
  19885. * morphNormals: <bool>
  19886. * }
  19887. */
  19888. function MeshToonMaterial(parameters) {
  19889. Material.call(this);
  19890. this.defines = {
  19891. 'TOON': ''
  19892. };
  19893. this.type = 'MeshToonMaterial';
  19894. this.color = new Color(0xffffff);
  19895. this.map = null;
  19896. this.gradientMap = null;
  19897. this.lightMap = null;
  19898. this.lightMapIntensity = 1.0;
  19899. this.aoMap = null;
  19900. this.aoMapIntensity = 1.0;
  19901. this.emissive = new Color(0x000000);
  19902. this.emissiveIntensity = 1.0;
  19903. this.emissiveMap = null;
  19904. this.bumpMap = null;
  19905. this.bumpScale = 1;
  19906. this.normalMap = null;
  19907. this.normalMapType = TangentSpaceNormalMap;
  19908. this.normalScale = new Vector2(1, 1);
  19909. this.displacementMap = null;
  19910. this.displacementScale = 1;
  19911. this.displacementBias = 0;
  19912. this.alphaMap = null;
  19913. this.wireframe = false;
  19914. this.wireframeLinewidth = 1;
  19915. this.wireframeLinecap = 'round';
  19916. this.wireframeLinejoin = 'round';
  19917. this.skinning = false;
  19918. this.morphTargets = false;
  19919. this.morphNormals = false;
  19920. this.setValues(parameters);
  19921. }
  19922. MeshToonMaterial.prototype = Object.create(Material.prototype);
  19923. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19924. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19925. MeshToonMaterial.prototype.copy = function (source) {
  19926. Material.prototype.copy.call(this, source);
  19927. this.color.copy(source.color);
  19928. this.map = source.map;
  19929. this.gradientMap = source.gradientMap;
  19930. this.lightMap = source.lightMap;
  19931. this.lightMapIntensity = source.lightMapIntensity;
  19932. this.aoMap = source.aoMap;
  19933. this.aoMapIntensity = source.aoMapIntensity;
  19934. this.emissive.copy(source.emissive);
  19935. this.emissiveMap = source.emissiveMap;
  19936. this.emissiveIntensity = source.emissiveIntensity;
  19937. this.bumpMap = source.bumpMap;
  19938. this.bumpScale = source.bumpScale;
  19939. this.normalMap = source.normalMap;
  19940. this.normalMapType = source.normalMapType;
  19941. this.normalScale.copy(source.normalScale);
  19942. this.displacementMap = source.displacementMap;
  19943. this.displacementScale = source.displacementScale;
  19944. this.displacementBias = source.displacementBias;
  19945. this.alphaMap = source.alphaMap;
  19946. this.wireframe = source.wireframe;
  19947. this.wireframeLinewidth = source.wireframeLinewidth;
  19948. this.wireframeLinecap = source.wireframeLinecap;
  19949. this.wireframeLinejoin = source.wireframeLinejoin;
  19950. this.skinning = source.skinning;
  19951. this.morphTargets = source.morphTargets;
  19952. this.morphNormals = source.morphNormals;
  19953. return this;
  19954. };
  19955. /**
  19956. * parameters = {
  19957. * opacity: <float>,
  19958. *
  19959. * bumpMap: new THREE.Texture( <Image> ),
  19960. * bumpScale: <float>,
  19961. *
  19962. * normalMap: new THREE.Texture( <Image> ),
  19963. * normalMapType: THREE.TangentSpaceNormalMap,
  19964. * normalScale: <Vector2>,
  19965. *
  19966. * displacementMap: new THREE.Texture( <Image> ),
  19967. * displacementScale: <float>,
  19968. * displacementBias: <float>,
  19969. *
  19970. * wireframe: <boolean>,
  19971. * wireframeLinewidth: <float>
  19972. *
  19973. * skinning: <bool>,
  19974. * morphTargets: <bool>,
  19975. * morphNormals: <bool>
  19976. * }
  19977. */
  19978. function MeshNormalMaterial(parameters) {
  19979. Material.call(this);
  19980. this.type = 'MeshNormalMaterial';
  19981. this.bumpMap = null;
  19982. this.bumpScale = 1;
  19983. this.normalMap = null;
  19984. this.normalMapType = TangentSpaceNormalMap;
  19985. this.normalScale = new Vector2(1, 1);
  19986. this.displacementMap = null;
  19987. this.displacementScale = 1;
  19988. this.displacementBias = 0;
  19989. this.wireframe = false;
  19990. this.wireframeLinewidth = 1;
  19991. this.fog = false;
  19992. this.skinning = false;
  19993. this.morphTargets = false;
  19994. this.morphNormals = false;
  19995. this.setValues(parameters);
  19996. }
  19997. MeshNormalMaterial.prototype = Object.create(Material.prototype);
  19998. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19999. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20000. MeshNormalMaterial.prototype.copy = function (source) {
  20001. Material.prototype.copy.call(this, source);
  20002. this.bumpMap = source.bumpMap;
  20003. this.bumpScale = source.bumpScale;
  20004. this.normalMap = source.normalMap;
  20005. this.normalMapType = source.normalMapType;
  20006. this.normalScale.copy(source.normalScale);
  20007. this.displacementMap = source.displacementMap;
  20008. this.displacementScale = source.displacementScale;
  20009. this.displacementBias = source.displacementBias;
  20010. this.wireframe = source.wireframe;
  20011. this.wireframeLinewidth = source.wireframeLinewidth;
  20012. this.skinning = source.skinning;
  20013. this.morphTargets = source.morphTargets;
  20014. this.morphNormals = source.morphNormals;
  20015. return this;
  20016. };
  20017. /**
  20018. * parameters = {
  20019. * color: <hex>,
  20020. * opacity: <float>,
  20021. *
  20022. * map: new THREE.Texture( <Image> ),
  20023. *
  20024. * lightMap: new THREE.Texture( <Image> ),
  20025. * lightMapIntensity: <float>
  20026. *
  20027. * aoMap: new THREE.Texture( <Image> ),
  20028. * aoMapIntensity: <float>
  20029. *
  20030. * emissive: <hex>,
  20031. * emissiveIntensity: <float>
  20032. * emissiveMap: new THREE.Texture( <Image> ),
  20033. *
  20034. * specularMap: new THREE.Texture( <Image> ),
  20035. *
  20036. * alphaMap: new THREE.Texture( <Image> ),
  20037. *
  20038. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20039. * combine: THREE.Multiply,
  20040. * reflectivity: <float>,
  20041. * refractionRatio: <float>,
  20042. *
  20043. * wireframe: <boolean>,
  20044. * wireframeLinewidth: <float>,
  20045. *
  20046. * skinning: <bool>,
  20047. * morphTargets: <bool>,
  20048. * morphNormals: <bool>
  20049. * }
  20050. */
  20051. function MeshLambertMaterial(parameters) {
  20052. Material.call(this);
  20053. this.type = 'MeshLambertMaterial';
  20054. this.color = new Color(0xffffff); // diffuse
  20055. this.map = null;
  20056. this.lightMap = null;
  20057. this.lightMapIntensity = 1.0;
  20058. this.aoMap = null;
  20059. this.aoMapIntensity = 1.0;
  20060. this.emissive = new Color(0x000000);
  20061. this.emissiveIntensity = 1.0;
  20062. this.emissiveMap = null;
  20063. this.specularMap = null;
  20064. this.alphaMap = null;
  20065. this.envMap = null;
  20066. this.combine = MultiplyOperation;
  20067. this.reflectivity = 1;
  20068. this.refractionRatio = 0.98;
  20069. this.wireframe = false;
  20070. this.wireframeLinewidth = 1;
  20071. this.wireframeLinecap = 'round';
  20072. this.wireframeLinejoin = 'round';
  20073. this.skinning = false;
  20074. this.morphTargets = false;
  20075. this.morphNormals = false;
  20076. this.setValues(parameters);
  20077. }
  20078. MeshLambertMaterial.prototype = Object.create(Material.prototype);
  20079. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20080. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20081. MeshLambertMaterial.prototype.copy = function (source) {
  20082. Material.prototype.copy.call(this, source);
  20083. this.color.copy(source.color);
  20084. this.map = source.map;
  20085. this.lightMap = source.lightMap;
  20086. this.lightMapIntensity = source.lightMapIntensity;
  20087. this.aoMap = source.aoMap;
  20088. this.aoMapIntensity = source.aoMapIntensity;
  20089. this.emissive.copy(source.emissive);
  20090. this.emissiveMap = source.emissiveMap;
  20091. this.emissiveIntensity = source.emissiveIntensity;
  20092. this.specularMap = source.specularMap;
  20093. this.alphaMap = source.alphaMap;
  20094. this.envMap = source.envMap;
  20095. this.combine = source.combine;
  20096. this.reflectivity = source.reflectivity;
  20097. this.refractionRatio = source.refractionRatio;
  20098. this.wireframe = source.wireframe;
  20099. this.wireframeLinewidth = source.wireframeLinewidth;
  20100. this.wireframeLinecap = source.wireframeLinecap;
  20101. this.wireframeLinejoin = source.wireframeLinejoin;
  20102. this.skinning = source.skinning;
  20103. this.morphTargets = source.morphTargets;
  20104. this.morphNormals = source.morphNormals;
  20105. return this;
  20106. };
  20107. /**
  20108. * parameters = {
  20109. * color: <hex>,
  20110. * opacity: <float>,
  20111. *
  20112. * matcap: new THREE.Texture( <Image> ),
  20113. *
  20114. * map: new THREE.Texture( <Image> ),
  20115. *
  20116. * bumpMap: new THREE.Texture( <Image> ),
  20117. * bumpScale: <float>,
  20118. *
  20119. * normalMap: new THREE.Texture( <Image> ),
  20120. * normalMapType: THREE.TangentSpaceNormalMap,
  20121. * normalScale: <Vector2>,
  20122. *
  20123. * displacementMap: new THREE.Texture( <Image> ),
  20124. * displacementScale: <float>,
  20125. * displacementBias: <float>,
  20126. *
  20127. * alphaMap: new THREE.Texture( <Image> ),
  20128. *
  20129. * skinning: <bool>,
  20130. * morphTargets: <bool>,
  20131. * morphNormals: <bool>
  20132. * }
  20133. */
  20134. function MeshMatcapMaterial(parameters) {
  20135. Material.call(this);
  20136. this.defines = {
  20137. 'MATCAP': ''
  20138. };
  20139. this.type = 'MeshMatcapMaterial';
  20140. this.color = new Color(0xffffff); // diffuse
  20141. this.matcap = null;
  20142. this.map = null;
  20143. this.bumpMap = null;
  20144. this.bumpScale = 1;
  20145. this.normalMap = null;
  20146. this.normalMapType = TangentSpaceNormalMap;
  20147. this.normalScale = new Vector2(1, 1);
  20148. this.displacementMap = null;
  20149. this.displacementScale = 1;
  20150. this.displacementBias = 0;
  20151. this.alphaMap = null;
  20152. this.skinning = false;
  20153. this.morphTargets = false;
  20154. this.morphNormals = false;
  20155. this.setValues(parameters);
  20156. }
  20157. MeshMatcapMaterial.prototype = Object.create(Material.prototype);
  20158. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20159. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20160. MeshMatcapMaterial.prototype.copy = function (source) {
  20161. Material.prototype.copy.call(this, source);
  20162. this.defines = {
  20163. 'MATCAP': ''
  20164. };
  20165. this.color.copy(source.color);
  20166. this.matcap = source.matcap;
  20167. this.map = source.map;
  20168. this.bumpMap = source.bumpMap;
  20169. this.bumpScale = source.bumpScale;
  20170. this.normalMap = source.normalMap;
  20171. this.normalMapType = source.normalMapType;
  20172. this.normalScale.copy(source.normalScale);
  20173. this.displacementMap = source.displacementMap;
  20174. this.displacementScale = source.displacementScale;
  20175. this.displacementBias = source.displacementBias;
  20176. this.alphaMap = source.alphaMap;
  20177. this.skinning = source.skinning;
  20178. this.morphTargets = source.morphTargets;
  20179. this.morphNormals = source.morphNormals;
  20180. return this;
  20181. };
  20182. /**
  20183. * parameters = {
  20184. * color: <hex>,
  20185. * opacity: <float>,
  20186. *
  20187. * linewidth: <float>,
  20188. *
  20189. * scale: <float>,
  20190. * dashSize: <float>,
  20191. * gapSize: <float>
  20192. * }
  20193. */
  20194. function LineDashedMaterial(parameters) {
  20195. LineBasicMaterial.call(this);
  20196. this.type = 'LineDashedMaterial';
  20197. this.scale = 1;
  20198. this.dashSize = 3;
  20199. this.gapSize = 1;
  20200. this.setValues(parameters);
  20201. }
  20202. LineDashedMaterial.prototype = Object.create(LineBasicMaterial.prototype);
  20203. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20204. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20205. LineDashedMaterial.prototype.copy = function (source) {
  20206. LineBasicMaterial.prototype.copy.call(this, source);
  20207. this.scale = source.scale;
  20208. this.dashSize = source.dashSize;
  20209. this.gapSize = source.gapSize;
  20210. return this;
  20211. };
  20212. var Materials = /*#__PURE__*/Object.freeze({
  20213. __proto__: null,
  20214. ShadowMaterial: ShadowMaterial,
  20215. SpriteMaterial: SpriteMaterial,
  20216. RawShaderMaterial: RawShaderMaterial,
  20217. ShaderMaterial: ShaderMaterial,
  20218. PointsMaterial: PointsMaterial,
  20219. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20220. MeshStandardMaterial: MeshStandardMaterial,
  20221. MeshPhongMaterial: MeshPhongMaterial,
  20222. MeshToonMaterial: MeshToonMaterial,
  20223. MeshNormalMaterial: MeshNormalMaterial,
  20224. MeshLambertMaterial: MeshLambertMaterial,
  20225. MeshDepthMaterial: MeshDepthMaterial,
  20226. MeshDistanceMaterial: MeshDistanceMaterial,
  20227. MeshBasicMaterial: MeshBasicMaterial,
  20228. MeshMatcapMaterial: MeshMatcapMaterial,
  20229. LineDashedMaterial: LineDashedMaterial,
  20230. LineBasicMaterial: LineBasicMaterial,
  20231. Material: Material
  20232. });
  20233. var AnimationUtils = {
  20234. // same as Array.prototype.slice, but also works on typed arrays
  20235. arraySlice: function arraySlice(array, from, to) {
  20236. if (AnimationUtils.isTypedArray(array)) {
  20237. // in ios9 array.subarray(from, undefined) will return empty array
  20238. // but array.subarray(from) or array.subarray(from, len) is correct
  20239. return new array.constructor(array.subarray(from, to !== undefined ? to : array.length));
  20240. }
  20241. return array.slice(from, to);
  20242. },
  20243. // converts an array to a specific type
  20244. convertArray: function convertArray(array, type, forceClone) {
  20245. if (!array || // let 'undefined' and 'null' pass
  20246. !forceClone && array.constructor === type) return array;
  20247. if (typeof type.BYTES_PER_ELEMENT === 'number') {
  20248. return new type(array); // create typed array
  20249. }
  20250. return Array.prototype.slice.call(array); // create Array
  20251. },
  20252. isTypedArray: function isTypedArray(object) {
  20253. return ArrayBuffer.isView(object) && !(object instanceof DataView);
  20254. },
  20255. // returns an array by which times and values can be sorted
  20256. getKeyframeOrder: function getKeyframeOrder(times) {
  20257. function compareTime(i, j) {
  20258. return times[i] - times[j];
  20259. }
  20260. var n = times.length;
  20261. var result = new Array(n);
  20262. for (var i = 0; i !== n; ++i) {
  20263. result[i] = i;
  20264. }
  20265. result.sort(compareTime);
  20266. return result;
  20267. },
  20268. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20269. sortedArray: function sortedArray(values, stride, order) {
  20270. var nValues = values.length;
  20271. var result = new values.constructor(nValues);
  20272. for (var i = 0, dstOffset = 0; dstOffset !== nValues; ++i) {
  20273. var srcOffset = order[i] * stride;
  20274. for (var j = 0; j !== stride; ++j) {
  20275. result[dstOffset++] = values[srcOffset + j];
  20276. }
  20277. }
  20278. return result;
  20279. },
  20280. // function for parsing AOS keyframe formats
  20281. flattenJSON: function flattenJSON(jsonKeys, times, values, valuePropertyName) {
  20282. var i = 1,
  20283. key = jsonKeys[0];
  20284. while (key !== undefined && key[valuePropertyName] === undefined) {
  20285. key = jsonKeys[i++];
  20286. }
  20287. if (key === undefined) return; // no data
  20288. var value = key[valuePropertyName];
  20289. if (value === undefined) return; // no data
  20290. if (Array.isArray(value)) {
  20291. do {
  20292. value = key[valuePropertyName];
  20293. if (value !== undefined) {
  20294. times.push(key.time);
  20295. values.push.apply(values, value); // push all elements
  20296. }
  20297. key = jsonKeys[i++];
  20298. } while (key !== undefined);
  20299. } else if (value.toArray !== undefined) {
  20300. // ...assume THREE.Math-ish
  20301. do {
  20302. value = key[valuePropertyName];
  20303. if (value !== undefined) {
  20304. times.push(key.time);
  20305. value.toArray(values, values.length);
  20306. }
  20307. key = jsonKeys[i++];
  20308. } while (key !== undefined);
  20309. } else {
  20310. // otherwise push as-is
  20311. do {
  20312. value = key[valuePropertyName];
  20313. if (value !== undefined) {
  20314. times.push(key.time);
  20315. values.push(value);
  20316. }
  20317. key = jsonKeys[i++];
  20318. } while (key !== undefined);
  20319. }
  20320. },
  20321. subclip: function subclip(sourceClip, name, startFrame, endFrame, fps) {
  20322. if (fps === void 0) {
  20323. fps = 30;
  20324. }
  20325. var clip = sourceClip.clone();
  20326. clip.name = name;
  20327. var tracks = [];
  20328. for (var i = 0; i < clip.tracks.length; ++i) {
  20329. var track = clip.tracks[i];
  20330. var valueSize = track.getValueSize();
  20331. var times = [];
  20332. var values = [];
  20333. for (var j = 0; j < track.times.length; ++j) {
  20334. var frame = track.times[j] * fps;
  20335. if (frame < startFrame || frame >= endFrame) continue;
  20336. times.push(track.times[j]);
  20337. for (var k = 0; k < valueSize; ++k) {
  20338. values.push(track.values[j * valueSize + k]);
  20339. }
  20340. }
  20341. if (times.length === 0) continue;
  20342. track.times = AnimationUtils.convertArray(times, track.times.constructor);
  20343. track.values = AnimationUtils.convertArray(values, track.values.constructor);
  20344. tracks.push(track);
  20345. }
  20346. clip.tracks = tracks; // find minimum .times value across all tracks in the trimmed clip
  20347. var minStartTime = Infinity;
  20348. for (var _i = 0; _i < clip.tracks.length; ++_i) {
  20349. if (minStartTime > clip.tracks[_i].times[0]) {
  20350. minStartTime = clip.tracks[_i].times[0];
  20351. }
  20352. } // shift all tracks such that clip begins at t=0
  20353. for (var _i2 = 0; _i2 < clip.tracks.length; ++_i2) {
  20354. clip.tracks[_i2].shift(-1 * minStartTime);
  20355. }
  20356. clip.resetDuration();
  20357. return clip;
  20358. },
  20359. makeClipAdditive: function makeClipAdditive(targetClip, referenceFrame, referenceClip, fps) {
  20360. if (referenceFrame === void 0) {
  20361. referenceFrame = 0;
  20362. }
  20363. if (referenceClip === void 0) {
  20364. referenceClip = targetClip;
  20365. }
  20366. if (fps === void 0) {
  20367. fps = 30;
  20368. }
  20369. if (fps <= 0) fps = 30;
  20370. var numTracks = referenceClip.tracks.length;
  20371. var referenceTime = referenceFrame / fps; // Make each track's values relative to the values at the reference frame
  20372. var _loop = function _loop(i) {
  20373. var referenceTrack = referenceClip.tracks[i];
  20374. var referenceTrackType = referenceTrack.ValueTypeName; // Skip this track if it's non-numeric
  20375. if (referenceTrackType === 'bool' || referenceTrackType === 'string') return "continue"; // Find the track in the target clip whose name and type matches the reference track
  20376. var targetTrack = targetClip.tracks.find(function (track) {
  20377. return track.name === referenceTrack.name && track.ValueTypeName === referenceTrackType;
  20378. });
  20379. if (targetTrack === undefined) return "continue";
  20380. var referenceOffset = 0;
  20381. var referenceValueSize = referenceTrack.getValueSize();
  20382. if (referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20383. referenceOffset = referenceValueSize / 3;
  20384. }
  20385. var targetOffset = 0;
  20386. var targetValueSize = targetTrack.getValueSize();
  20387. if (targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline) {
  20388. targetOffset = targetValueSize / 3;
  20389. }
  20390. var lastIndex = referenceTrack.times.length - 1;
  20391. var referenceValue = void 0; // Find the value to subtract out of the track
  20392. if (referenceTime <= referenceTrack.times[0]) {
  20393. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20394. var startIndex = referenceOffset;
  20395. var endIndex = referenceValueSize - referenceOffset;
  20396. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, startIndex, endIndex);
  20397. } else if (referenceTime >= referenceTrack.times[lastIndex]) {
  20398. // Reference frame is after the last keyframe, so just use the last keyframe
  20399. var _startIndex = lastIndex * referenceValueSize + referenceOffset;
  20400. var _endIndex = _startIndex + referenceValueSize - referenceOffset;
  20401. referenceValue = AnimationUtils.arraySlice(referenceTrack.values, _startIndex, _endIndex);
  20402. } else {
  20403. // Interpolate to the reference value
  20404. var interpolant = referenceTrack.createInterpolant();
  20405. var _startIndex2 = referenceOffset;
  20406. var _endIndex2 = referenceValueSize - referenceOffset;
  20407. interpolant.evaluate(referenceTime);
  20408. referenceValue = AnimationUtils.arraySlice(interpolant.resultBuffer, _startIndex2, _endIndex2);
  20409. } // Conjugate the quaternion
  20410. if (referenceTrackType === 'quaternion') {
  20411. var referenceQuat = new Quaternion().fromArray(referenceValue).normalize().conjugate();
  20412. referenceQuat.toArray(referenceValue);
  20413. } // Subtract the reference value from all of the track values
  20414. var numTimes = targetTrack.times.length;
  20415. for (var j = 0; j < numTimes; ++j) {
  20416. var valueStart = j * targetValueSize + targetOffset;
  20417. if (referenceTrackType === 'quaternion') {
  20418. // Multiply the conjugate for quaternion track types
  20419. Quaternion.multiplyQuaternionsFlat(targetTrack.values, valueStart, referenceValue, 0, targetTrack.values, valueStart);
  20420. } else {
  20421. var valueEnd = targetValueSize - targetOffset * 2; // Subtract each value for all other numeric track types
  20422. for (var k = 0; k < valueEnd; ++k) {
  20423. targetTrack.values[valueStart + k] -= referenceValue[k];
  20424. }
  20425. }
  20426. }
  20427. };
  20428. for (var i = 0; i < numTracks; ++i) {
  20429. var _ret = _loop(i);
  20430. if (_ret === "continue") continue;
  20431. }
  20432. targetClip.blendMode = AdditiveAnimationBlendMode;
  20433. return targetClip;
  20434. }
  20435. };
  20436. /**
  20437. * Abstract base class of interpolants over parametric samples.
  20438. *
  20439. * The parameter domain is one dimensional, typically the time or a path
  20440. * along a curve defined by the data.
  20441. *
  20442. * The sample values can have any dimensionality and derived classes may
  20443. * apply special interpretations to the data.
  20444. *
  20445. * This class provides the interval seek in a Template Method, deferring
  20446. * the actual interpolation to derived classes.
  20447. *
  20448. * Time complexity is O(1) for linear access crossing at most two points
  20449. * and O(log N) for random access, where N is the number of positions.
  20450. *
  20451. * References:
  20452. *
  20453. * http://www.oodesign.com/template-method-pattern.html
  20454. *
  20455. */
  20456. function Interpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20457. this.parameterPositions = parameterPositions;
  20458. this._cachedIndex = 0;
  20459. this.resultBuffer = resultBuffer !== undefined ? resultBuffer : new sampleValues.constructor(sampleSize);
  20460. this.sampleValues = sampleValues;
  20461. this.valueSize = sampleSize;
  20462. }
  20463. Object.assign(Interpolant.prototype, {
  20464. evaluate: function evaluate(t) {
  20465. var pp = this.parameterPositions;
  20466. var i1 = this._cachedIndex,
  20467. t1 = pp[i1],
  20468. t0 = pp[i1 - 1];
  20469. validate_interval: {
  20470. seek: {
  20471. var right;
  20472. linear_scan: {
  20473. //- See http://jsperf.com/comparison-to-undefined/3
  20474. //- slower code:
  20475. //-
  20476. //- if ( t >= t1 || t1 === undefined ) {
  20477. forward_scan: if (!(t < t1)) {
  20478. for (var giveUpAt = i1 + 2;;) {
  20479. if (t1 === undefined) {
  20480. if (t < t0) break forward_scan; // after end
  20481. i1 = pp.length;
  20482. this._cachedIndex = i1;
  20483. return this.afterEnd_(i1 - 1, t, t0);
  20484. }
  20485. if (i1 === giveUpAt) break; // this loop
  20486. t0 = t1;
  20487. t1 = pp[++i1];
  20488. if (t < t1) {
  20489. // we have arrived at the sought interval
  20490. break seek;
  20491. }
  20492. } // prepare binary search on the right side of the index
  20493. right = pp.length;
  20494. break linear_scan;
  20495. } //- slower code:
  20496. //- if ( t < t0 || t0 === undefined ) {
  20497. if (!(t >= t0)) {
  20498. // looping?
  20499. var t1global = pp[1];
  20500. if (t < t1global) {
  20501. i1 = 2; // + 1, using the scan for the details
  20502. t0 = t1global;
  20503. } // linear reverse scan
  20504. for (var _giveUpAt = i1 - 2;;) {
  20505. if (t0 === undefined) {
  20506. // before start
  20507. this._cachedIndex = 0;
  20508. return this.beforeStart_(0, t, t1);
  20509. }
  20510. if (i1 === _giveUpAt) break; // this loop
  20511. t1 = t0;
  20512. t0 = pp[--i1 - 1];
  20513. if (t >= t0) {
  20514. // we have arrived at the sought interval
  20515. break seek;
  20516. }
  20517. } // prepare binary search on the left side of the index
  20518. right = i1;
  20519. i1 = 0;
  20520. break linear_scan;
  20521. } // the interval is valid
  20522. break validate_interval;
  20523. } // linear scan
  20524. // binary search
  20525. while (i1 < right) {
  20526. var mid = i1 + right >>> 1;
  20527. if (t < pp[mid]) {
  20528. right = mid;
  20529. } else {
  20530. i1 = mid + 1;
  20531. }
  20532. }
  20533. t1 = pp[i1];
  20534. t0 = pp[i1 - 1]; // check boundary cases, again
  20535. if (t0 === undefined) {
  20536. this._cachedIndex = 0;
  20537. return this.beforeStart_(0, t, t1);
  20538. }
  20539. if (t1 === undefined) {
  20540. i1 = pp.length;
  20541. this._cachedIndex = i1;
  20542. return this.afterEnd_(i1 - 1, t0, t);
  20543. }
  20544. } // seek
  20545. this._cachedIndex = i1;
  20546. this.intervalChanged_(i1, t0, t1);
  20547. } // validate_interval
  20548. return this.interpolate_(i1, t0, t, t1);
  20549. },
  20550. settings: null,
  20551. // optional, subclass-specific settings structure
  20552. // Note: The indirection allows central control of many interpolants.
  20553. // --- Protected interface
  20554. DefaultSettings_: {},
  20555. getSettings_: function getSettings_() {
  20556. return this.settings || this.DefaultSettings_;
  20557. },
  20558. copySampleValue_: function copySampleValue_(index) {
  20559. // copies a sample value to the result buffer
  20560. var result = this.resultBuffer,
  20561. values = this.sampleValues,
  20562. stride = this.valueSize,
  20563. offset = index * stride;
  20564. for (var i = 0; i !== stride; ++i) {
  20565. result[i] = values[offset + i];
  20566. }
  20567. return result;
  20568. },
  20569. // Template methods for derived classes:
  20570. interpolate_: function interpolate_()
  20571. /* i1, t0, t, t1 */
  20572. {
  20573. throw new Error('call to abstract method'); // implementations shall return this.resultBuffer
  20574. },
  20575. intervalChanged_: function intervalChanged_()
  20576. /* i1, t0, t1 */
  20577. {// empty
  20578. }
  20579. }); // DECLARE ALIAS AFTER assign prototype
  20580. Object.assign(Interpolant.prototype, {
  20581. //( 0, t, t0 ), returns this.resultBuffer
  20582. beforeStart_: Interpolant.prototype.copySampleValue_,
  20583. //( N-1, tN-1, t ), returns this.resultBuffer
  20584. afterEnd_: Interpolant.prototype.copySampleValue_
  20585. });
  20586. /**
  20587. * Fast and simple cubic spline interpolant.
  20588. *
  20589. * It was derived from a Hermitian construction setting the first derivative
  20590. * at each sample position to the linear slope between neighboring positions
  20591. * over their parameter interval.
  20592. */
  20593. function CubicInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20594. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20595. this._weightPrev = -0;
  20596. this._offsetPrev = -0;
  20597. this._weightNext = -0;
  20598. this._offsetNext = -0;
  20599. }
  20600. CubicInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20601. constructor: CubicInterpolant,
  20602. DefaultSettings_: {
  20603. endingStart: ZeroCurvatureEnding,
  20604. endingEnd: ZeroCurvatureEnding
  20605. },
  20606. intervalChanged_: function intervalChanged_(i1, t0, t1) {
  20607. var pp = this.parameterPositions;
  20608. var iPrev = i1 - 2,
  20609. iNext = i1 + 1,
  20610. tPrev = pp[iPrev],
  20611. tNext = pp[iNext];
  20612. if (tPrev === undefined) {
  20613. switch (this.getSettings_().endingStart) {
  20614. case ZeroSlopeEnding:
  20615. // f'(t0) = 0
  20616. iPrev = i1;
  20617. tPrev = 2 * t0 - t1;
  20618. break;
  20619. case WrapAroundEnding:
  20620. // use the other end of the curve
  20621. iPrev = pp.length - 2;
  20622. tPrev = t0 + pp[iPrev] - pp[iPrev + 1];
  20623. break;
  20624. default:
  20625. // ZeroCurvatureEnding
  20626. // f''(t0) = 0 a.k.a. Natural Spline
  20627. iPrev = i1;
  20628. tPrev = t1;
  20629. }
  20630. }
  20631. if (tNext === undefined) {
  20632. switch (this.getSettings_().endingEnd) {
  20633. case ZeroSlopeEnding:
  20634. // f'(tN) = 0
  20635. iNext = i1;
  20636. tNext = 2 * t1 - t0;
  20637. break;
  20638. case WrapAroundEnding:
  20639. // use the other end of the curve
  20640. iNext = 1;
  20641. tNext = t1 + pp[1] - pp[0];
  20642. break;
  20643. default:
  20644. // ZeroCurvatureEnding
  20645. // f''(tN) = 0, a.k.a. Natural Spline
  20646. iNext = i1 - 1;
  20647. tNext = t0;
  20648. }
  20649. }
  20650. var halfDt = (t1 - t0) * 0.5,
  20651. stride = this.valueSize;
  20652. this._weightPrev = halfDt / (t0 - tPrev);
  20653. this._weightNext = halfDt / (tNext - t1);
  20654. this._offsetPrev = iPrev * stride;
  20655. this._offsetNext = iNext * stride;
  20656. },
  20657. interpolate_: function interpolate_(i1, t0, t, t1) {
  20658. var result = this.resultBuffer,
  20659. values = this.sampleValues,
  20660. stride = this.valueSize,
  20661. o1 = i1 * stride,
  20662. o0 = o1 - stride,
  20663. oP = this._offsetPrev,
  20664. oN = this._offsetNext,
  20665. wP = this._weightPrev,
  20666. wN = this._weightNext,
  20667. p = (t - t0) / (t1 - t0),
  20668. pp = p * p,
  20669. ppp = pp * p; // evaluate polynomials
  20670. var sP = -wP * ppp + 2 * wP * pp - wP * p;
  20671. var s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1;
  20672. var s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p;
  20673. var sN = wN * ppp - wN * pp; // combine data linearly
  20674. for (var i = 0; i !== stride; ++i) {
  20675. result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i];
  20676. }
  20677. return result;
  20678. }
  20679. });
  20680. function LinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20681. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20682. }
  20683. LinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20684. constructor: LinearInterpolant,
  20685. interpolate_: function interpolate_(i1, t0, t, t1) {
  20686. var result = this.resultBuffer,
  20687. values = this.sampleValues,
  20688. stride = this.valueSize,
  20689. offset1 = i1 * stride,
  20690. offset0 = offset1 - stride,
  20691. weight1 = (t - t0) / (t1 - t0),
  20692. weight0 = 1 - weight1;
  20693. for (var i = 0; i !== stride; ++i) {
  20694. result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
  20695. }
  20696. return result;
  20697. }
  20698. });
  20699. /**
  20700. *
  20701. * Interpolant that evaluates to the sample value at the position preceeding
  20702. * the parameter.
  20703. */
  20704. function DiscreteInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  20705. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  20706. }
  20707. DiscreteInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  20708. constructor: DiscreteInterpolant,
  20709. interpolate_: function interpolate_(i1
  20710. /*, t0, t, t1 */
  20711. ) {
  20712. return this.copySampleValue_(i1 - 1);
  20713. }
  20714. });
  20715. function KeyframeTrack(name, times, values, interpolation) {
  20716. if (name === undefined) throw new Error('THREE.KeyframeTrack: track name is undefined');
  20717. if (times === undefined || times.length === 0) throw new Error('THREE.KeyframeTrack: no keyframes in track named ' + name);
  20718. this.name = name;
  20719. this.times = AnimationUtils.convertArray(times, this.TimeBufferType);
  20720. this.values = AnimationUtils.convertArray(values, this.ValueBufferType);
  20721. this.setInterpolation(interpolation || this.DefaultInterpolation);
  20722. } // Static methods
  20723. Object.assign(KeyframeTrack, {
  20724. // Serialization (in static context, because of constructor invocation
  20725. // and automatic invocation of .toJSON):
  20726. toJSON: function toJSON(track) {
  20727. var trackType = track.constructor;
  20728. var json; // derived classes can define a static toJSON method
  20729. if (trackType.toJSON !== undefined) {
  20730. json = trackType.toJSON(track);
  20731. } else {
  20732. // by default, we assume the data can be serialized as-is
  20733. json = {
  20734. 'name': track.name,
  20735. 'times': AnimationUtils.convertArray(track.times, Array),
  20736. 'values': AnimationUtils.convertArray(track.values, Array)
  20737. };
  20738. var interpolation = track.getInterpolation();
  20739. if (interpolation !== track.DefaultInterpolation) {
  20740. json.interpolation = interpolation;
  20741. }
  20742. }
  20743. json.type = track.ValueTypeName; // mandatory
  20744. return json;
  20745. }
  20746. });
  20747. Object.assign(KeyframeTrack.prototype, {
  20748. constructor: KeyframeTrack,
  20749. TimeBufferType: Float32Array,
  20750. ValueBufferType: Float32Array,
  20751. DefaultInterpolation: InterpolateLinear,
  20752. InterpolantFactoryMethodDiscrete: function InterpolantFactoryMethodDiscrete(result) {
  20753. return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result);
  20754. },
  20755. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  20756. return new LinearInterpolant(this.times, this.values, this.getValueSize(), result);
  20757. },
  20758. InterpolantFactoryMethodSmooth: function InterpolantFactoryMethodSmooth(result) {
  20759. return new CubicInterpolant(this.times, this.values, this.getValueSize(), result);
  20760. },
  20761. setInterpolation: function setInterpolation(interpolation) {
  20762. var factoryMethod;
  20763. switch (interpolation) {
  20764. case InterpolateDiscrete:
  20765. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20766. break;
  20767. case InterpolateLinear:
  20768. factoryMethod = this.InterpolantFactoryMethodLinear;
  20769. break;
  20770. case InterpolateSmooth:
  20771. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20772. break;
  20773. }
  20774. if (factoryMethod === undefined) {
  20775. var message = 'unsupported interpolation for ' + this.ValueTypeName + ' keyframe track named ' + this.name;
  20776. if (this.createInterpolant === undefined) {
  20777. // fall back to default, unless the default itself is messed up
  20778. if (interpolation !== this.DefaultInterpolation) {
  20779. this.setInterpolation(this.DefaultInterpolation);
  20780. } else {
  20781. throw new Error(message); // fatal, in this case
  20782. }
  20783. }
  20784. console.warn('THREE.KeyframeTrack:', message);
  20785. return this;
  20786. }
  20787. this.createInterpolant = factoryMethod;
  20788. return this;
  20789. },
  20790. getInterpolation: function getInterpolation() {
  20791. switch (this.createInterpolant) {
  20792. case this.InterpolantFactoryMethodDiscrete:
  20793. return InterpolateDiscrete;
  20794. case this.InterpolantFactoryMethodLinear:
  20795. return InterpolateLinear;
  20796. case this.InterpolantFactoryMethodSmooth:
  20797. return InterpolateSmooth;
  20798. }
  20799. },
  20800. getValueSize: function getValueSize() {
  20801. return this.values.length / this.times.length;
  20802. },
  20803. // move all keyframes either forwards or backwards in time
  20804. shift: function shift(timeOffset) {
  20805. if (timeOffset !== 0.0) {
  20806. var times = this.times;
  20807. for (var i = 0, n = times.length; i !== n; ++i) {
  20808. times[i] += timeOffset;
  20809. }
  20810. }
  20811. return this;
  20812. },
  20813. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20814. scale: function scale(timeScale) {
  20815. if (timeScale !== 1.0) {
  20816. var times = this.times;
  20817. for (var i = 0, n = times.length; i !== n; ++i) {
  20818. times[i] *= timeScale;
  20819. }
  20820. }
  20821. return this;
  20822. },
  20823. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20824. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20825. trim: function trim(startTime, endTime) {
  20826. var times = this.times,
  20827. nKeys = times.length;
  20828. var from = 0,
  20829. to = nKeys - 1;
  20830. while (from !== nKeys && times[from] < startTime) {
  20831. ++from;
  20832. }
  20833. while (to !== -1 && times[to] > endTime) {
  20834. --to;
  20835. }
  20836. ++to; // inclusive -> exclusive bound
  20837. if (from !== 0 || to !== nKeys) {
  20838. // empty tracks are forbidden, so keep at least one keyframe
  20839. if (from >= to) {
  20840. to = Math.max(to, 1);
  20841. from = to - 1;
  20842. }
  20843. var stride = this.getValueSize();
  20844. this.times = AnimationUtils.arraySlice(times, from, to);
  20845. this.values = AnimationUtils.arraySlice(this.values, from * stride, to * stride);
  20846. }
  20847. return this;
  20848. },
  20849. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20850. validate: function validate() {
  20851. var valid = true;
  20852. var valueSize = this.getValueSize();
  20853. if (valueSize - Math.floor(valueSize) !== 0) {
  20854. console.error('THREE.KeyframeTrack: Invalid value size in track.', this);
  20855. valid = false;
  20856. }
  20857. var times = this.times,
  20858. values = this.values,
  20859. nKeys = times.length;
  20860. if (nKeys === 0) {
  20861. console.error('THREE.KeyframeTrack: Track is empty.', this);
  20862. valid = false;
  20863. }
  20864. var prevTime = null;
  20865. for (var i = 0; i !== nKeys; i++) {
  20866. var currTime = times[i];
  20867. if (typeof currTime === 'number' && isNaN(currTime)) {
  20868. console.error('THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime);
  20869. valid = false;
  20870. break;
  20871. }
  20872. if (prevTime !== null && prevTime > currTime) {
  20873. console.error('THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime);
  20874. valid = false;
  20875. break;
  20876. }
  20877. prevTime = currTime;
  20878. }
  20879. if (values !== undefined) {
  20880. if (AnimationUtils.isTypedArray(values)) {
  20881. for (var _i = 0, n = values.length; _i !== n; ++_i) {
  20882. var value = values[_i];
  20883. if (isNaN(value)) {
  20884. console.error('THREE.KeyframeTrack: Value is not a valid number.', this, _i, value);
  20885. valid = false;
  20886. break;
  20887. }
  20888. }
  20889. }
  20890. }
  20891. return valid;
  20892. },
  20893. // removes equivalent sequential keys as common in morph target sequences
  20894. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20895. optimize: function optimize() {
  20896. // times or values may be shared with other tracks, so overwriting is unsafe
  20897. var times = AnimationUtils.arraySlice(this.times),
  20898. values = AnimationUtils.arraySlice(this.values),
  20899. stride = this.getValueSize(),
  20900. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20901. lastIndex = times.length - 1;
  20902. var writeIndex = 1;
  20903. for (var i = 1; i < lastIndex; ++i) {
  20904. var keep = false;
  20905. var time = times[i];
  20906. var timeNext = times[i + 1]; // remove adjacent keyframes scheduled at the same time
  20907. if (time !== timeNext && (i !== 1 || time !== times[0])) {
  20908. if (!smoothInterpolation) {
  20909. // remove unnecessary keyframes same as their neighbors
  20910. var offset = i * stride,
  20911. offsetP = offset - stride,
  20912. offsetN = offset + stride;
  20913. for (var j = 0; j !== stride; ++j) {
  20914. var value = values[offset + j];
  20915. if (value !== values[offsetP + j] || value !== values[offsetN + j]) {
  20916. keep = true;
  20917. break;
  20918. }
  20919. }
  20920. } else {
  20921. keep = true;
  20922. }
  20923. } // in-place compaction
  20924. if (keep) {
  20925. if (i !== writeIndex) {
  20926. times[writeIndex] = times[i];
  20927. var readOffset = i * stride,
  20928. writeOffset = writeIndex * stride;
  20929. for (var _j = 0; _j !== stride; ++_j) {
  20930. values[writeOffset + _j] = values[readOffset + _j];
  20931. }
  20932. }
  20933. ++writeIndex;
  20934. }
  20935. } // flush last keyframe (compaction looks ahead)
  20936. if (lastIndex > 0) {
  20937. times[writeIndex] = times[lastIndex];
  20938. for (var _readOffset = lastIndex * stride, _writeOffset = writeIndex * stride, _j2 = 0; _j2 !== stride; ++_j2) {
  20939. values[_writeOffset + _j2] = values[_readOffset + _j2];
  20940. }
  20941. ++writeIndex;
  20942. }
  20943. if (writeIndex !== times.length) {
  20944. this.times = AnimationUtils.arraySlice(times, 0, writeIndex);
  20945. this.values = AnimationUtils.arraySlice(values, 0, writeIndex * stride);
  20946. } else {
  20947. this.times = times;
  20948. this.values = values;
  20949. }
  20950. return this;
  20951. },
  20952. clone: function clone() {
  20953. var times = AnimationUtils.arraySlice(this.times, 0);
  20954. var values = AnimationUtils.arraySlice(this.values, 0);
  20955. var TypedKeyframeTrack = this.constructor;
  20956. var track = new TypedKeyframeTrack(this.name, times, values); // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20957. track.createInterpolant = this.createInterpolant;
  20958. return track;
  20959. }
  20960. });
  20961. /**
  20962. * A Track of Boolean keyframe values.
  20963. */
  20964. function BooleanKeyframeTrack(name, times, values) {
  20965. KeyframeTrack.call(this, name, times, values);
  20966. }
  20967. BooleanKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20968. constructor: BooleanKeyframeTrack,
  20969. ValueTypeName: 'bool',
  20970. ValueBufferType: Array,
  20971. DefaultInterpolation: InterpolateDiscrete,
  20972. InterpolantFactoryMethodLinear: undefined,
  20973. InterpolantFactoryMethodSmooth: undefined // Note: Actually this track could have a optimized / compressed
  20974. // representation of a single value and a custom interpolant that
  20975. // computes "firstValue ^ isOdd( index )".
  20976. });
  20977. /**
  20978. * A Track of keyframe values that represent color.
  20979. */
  20980. function ColorKeyframeTrack(name, times, values, interpolation) {
  20981. KeyframeTrack.call(this, name, times, values, interpolation);
  20982. }
  20983. ColorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20984. constructor: ColorKeyframeTrack,
  20985. ValueTypeName: 'color' // ValueBufferType is inherited
  20986. // DefaultInterpolation is inherited
  20987. // Note: Very basic implementation and nothing special yet.
  20988. // However, this is the place for color space parameterization.
  20989. });
  20990. /**
  20991. * A Track of numeric keyframe values.
  20992. */
  20993. function NumberKeyframeTrack(name, times, values, interpolation) {
  20994. KeyframeTrack.call(this, name, times, values, interpolation);
  20995. }
  20996. NumberKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  20997. constructor: NumberKeyframeTrack,
  20998. ValueTypeName: 'number' // ValueBufferType is inherited
  20999. // DefaultInterpolation is inherited
  21000. });
  21001. /**
  21002. * Spherical linear unit quaternion interpolant.
  21003. */
  21004. function QuaternionLinearInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
  21005. Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
  21006. }
  21007. QuaternionLinearInterpolant.prototype = Object.assign(Object.create(Interpolant.prototype), {
  21008. constructor: QuaternionLinearInterpolant,
  21009. interpolate_: function interpolate_(i1, t0, t, t1) {
  21010. var result = this.resultBuffer,
  21011. values = this.sampleValues,
  21012. stride = this.valueSize,
  21013. alpha = (t - t0) / (t1 - t0);
  21014. var offset = i1 * stride;
  21015. for (var end = offset + stride; offset !== end; offset += 4) {
  21016. Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha);
  21017. }
  21018. return result;
  21019. }
  21020. });
  21021. /**
  21022. * A Track of quaternion keyframe values.
  21023. */
  21024. function QuaternionKeyframeTrack(name, times, values, interpolation) {
  21025. KeyframeTrack.call(this, name, times, values, interpolation);
  21026. }
  21027. QuaternionKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21028. constructor: QuaternionKeyframeTrack,
  21029. ValueTypeName: 'quaternion',
  21030. // ValueBufferType is inherited
  21031. DefaultInterpolation: InterpolateLinear,
  21032. InterpolantFactoryMethodLinear: function InterpolantFactoryMethodLinear(result) {
  21033. return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result);
  21034. },
  21035. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21036. });
  21037. /**
  21038. * A Track that interpolates Strings
  21039. */
  21040. function StringKeyframeTrack(name, times, values, interpolation) {
  21041. KeyframeTrack.call(this, name, times, values, interpolation);
  21042. }
  21043. StringKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21044. constructor: StringKeyframeTrack,
  21045. ValueTypeName: 'string',
  21046. ValueBufferType: Array,
  21047. DefaultInterpolation: InterpolateDiscrete,
  21048. InterpolantFactoryMethodLinear: undefined,
  21049. InterpolantFactoryMethodSmooth: undefined
  21050. });
  21051. /**
  21052. * A Track of vectored keyframe values.
  21053. */
  21054. function VectorKeyframeTrack(name, times, values, interpolation) {
  21055. KeyframeTrack.call(this, name, times, values, interpolation);
  21056. }
  21057. VectorKeyframeTrack.prototype = Object.assign(Object.create(KeyframeTrack.prototype), {
  21058. constructor: VectorKeyframeTrack,
  21059. ValueTypeName: 'vector' // ValueBufferType is inherited
  21060. // DefaultInterpolation is inherited
  21061. });
  21062. function AnimationClip(name, duration, tracks, blendMode) {
  21063. if (duration === void 0) {
  21064. duration = -1;
  21065. }
  21066. if (blendMode === void 0) {
  21067. blendMode = NormalAnimationBlendMode;
  21068. }
  21069. this.name = name;
  21070. this.tracks = tracks;
  21071. this.duration = duration;
  21072. this.blendMode = blendMode;
  21073. this.uuid = MathUtils.generateUUID(); // this means it should figure out its duration by scanning the tracks
  21074. if (this.duration < 0) {
  21075. this.resetDuration();
  21076. }
  21077. }
  21078. function getTrackTypeForValueTypeName(typeName) {
  21079. switch (typeName.toLowerCase()) {
  21080. case 'scalar':
  21081. case 'double':
  21082. case 'float':
  21083. case 'number':
  21084. case 'integer':
  21085. return NumberKeyframeTrack;
  21086. case 'vector':
  21087. case 'vector2':
  21088. case 'vector3':
  21089. case 'vector4':
  21090. return VectorKeyframeTrack;
  21091. case 'color':
  21092. return ColorKeyframeTrack;
  21093. case 'quaternion':
  21094. return QuaternionKeyframeTrack;
  21095. case 'bool':
  21096. case 'boolean':
  21097. return BooleanKeyframeTrack;
  21098. case 'string':
  21099. return StringKeyframeTrack;
  21100. }
  21101. throw new Error('THREE.KeyframeTrack: Unsupported typeName: ' + typeName);
  21102. }
  21103. function parseKeyframeTrack(json) {
  21104. if (json.type === undefined) {
  21105. throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');
  21106. }
  21107. var trackType = getTrackTypeForValueTypeName(json.type);
  21108. if (json.times === undefined) {
  21109. var times = [],
  21110. values = [];
  21111. AnimationUtils.flattenJSON(json.keys, times, values, 'value');
  21112. json.times = times;
  21113. json.values = values;
  21114. } // derived classes can define a static parse method
  21115. if (trackType.parse !== undefined) {
  21116. return trackType.parse(json);
  21117. } else {
  21118. // by default, we assume a constructor compatible with the base
  21119. return new trackType(json.name, json.times, json.values, json.interpolation);
  21120. }
  21121. }
  21122. Object.assign(AnimationClip, {
  21123. parse: function parse(json) {
  21124. var tracks = [],
  21125. jsonTracks = json.tracks,
  21126. frameTime = 1.0 / (json.fps || 1.0);
  21127. for (var i = 0, n = jsonTracks.length; i !== n; ++i) {
  21128. tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));
  21129. }
  21130. var clip = new AnimationClip(json.name, json.duration, tracks, json.blendMode);
  21131. clip.uuid = json.uuid;
  21132. return clip;
  21133. },
  21134. toJSON: function toJSON(clip) {
  21135. var tracks = [],
  21136. clipTracks = clip.tracks;
  21137. var json = {
  21138. 'name': clip.name,
  21139. 'duration': clip.duration,
  21140. 'tracks': tracks,
  21141. 'uuid': clip.uuid,
  21142. 'blendMode': clip.blendMode
  21143. };
  21144. for (var i = 0, n = clipTracks.length; i !== n; ++i) {
  21145. tracks.push(KeyframeTrack.toJSON(clipTracks[i]));
  21146. }
  21147. return json;
  21148. },
  21149. CreateFromMorphTargetSequence: function CreateFromMorphTargetSequence(name, morphTargetSequence, fps, noLoop) {
  21150. var numMorphTargets = morphTargetSequence.length;
  21151. var tracks = [];
  21152. for (var i = 0; i < numMorphTargets; i++) {
  21153. var times = [];
  21154. var values = [];
  21155. times.push((i + numMorphTargets - 1) % numMorphTargets, i, (i + 1) % numMorphTargets);
  21156. values.push(0, 1, 0);
  21157. var order = AnimationUtils.getKeyframeOrder(times);
  21158. times = AnimationUtils.sortedArray(times, 1, order);
  21159. values = AnimationUtils.sortedArray(values, 1, order); // if there is a key at the first frame, duplicate it as the
  21160. // last frame as well for perfect loop.
  21161. if (!noLoop && times[0] === 0) {
  21162. times.push(numMorphTargets);
  21163. values.push(values[0]);
  21164. }
  21165. tracks.push(new NumberKeyframeTrack('.morphTargetInfluences[' + morphTargetSequence[i].name + ']', times, values).scale(1.0 / fps));
  21166. }
  21167. return new AnimationClip(name, -1, tracks);
  21168. },
  21169. findByName: function findByName(objectOrClipArray, name) {
  21170. var clipArray = objectOrClipArray;
  21171. if (!Array.isArray(objectOrClipArray)) {
  21172. var o = objectOrClipArray;
  21173. clipArray = o.geometry && o.geometry.animations || o.animations;
  21174. }
  21175. for (var i = 0; i < clipArray.length; i++) {
  21176. if (clipArray[i].name === name) {
  21177. return clipArray[i];
  21178. }
  21179. }
  21180. return null;
  21181. },
  21182. CreateClipsFromMorphTargetSequences: function CreateClipsFromMorphTargetSequences(morphTargets, fps, noLoop) {
  21183. var animationToMorphTargets = {}; // tested with https://regex101.com/ on trick sequences
  21184. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21185. var pattern = /^([\w-]*?)([\d]+)$/; // sort morph target names into animation groups based
  21186. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21187. for (var i = 0, il = morphTargets.length; i < il; i++) {
  21188. var morphTarget = morphTargets[i];
  21189. var parts = morphTarget.name.match(pattern);
  21190. if (parts && parts.length > 1) {
  21191. var name = parts[1];
  21192. var animationMorphTargets = animationToMorphTargets[name];
  21193. if (!animationMorphTargets) {
  21194. animationToMorphTargets[name] = animationMorphTargets = [];
  21195. }
  21196. animationMorphTargets.push(morphTarget);
  21197. }
  21198. }
  21199. var clips = [];
  21200. for (var _name in animationToMorphTargets) {
  21201. clips.push(AnimationClip.CreateFromMorphTargetSequence(_name, animationToMorphTargets[_name], fps, noLoop));
  21202. }
  21203. return clips;
  21204. },
  21205. // parse the animation.hierarchy format
  21206. parseAnimation: function parseAnimation(animation, bones) {
  21207. if (!animation) {
  21208. console.error('THREE.AnimationClip: No animation in JSONLoader data.');
  21209. return null;
  21210. }
  21211. var addNonemptyTrack = function addNonemptyTrack(trackType, trackName, animationKeys, propertyName, destTracks) {
  21212. // only return track if there are actually keys.
  21213. if (animationKeys.length !== 0) {
  21214. var times = [];
  21215. var values = [];
  21216. AnimationUtils.flattenJSON(animationKeys, times, values, propertyName); // empty keys are filtered out, so check again
  21217. if (times.length !== 0) {
  21218. destTracks.push(new trackType(trackName, times, values));
  21219. }
  21220. }
  21221. };
  21222. var tracks = [];
  21223. var clipName = animation.name || 'default';
  21224. var fps = animation.fps || 30;
  21225. var blendMode = animation.blendMode; // automatic length determination in AnimationClip.
  21226. var duration = animation.length || -1;
  21227. var hierarchyTracks = animation.hierarchy || [];
  21228. for (var h = 0; h < hierarchyTracks.length; h++) {
  21229. var animationKeys = hierarchyTracks[h].keys; // skip empty tracks
  21230. if (!animationKeys || animationKeys.length === 0) continue; // process morph targets
  21231. if (animationKeys[0].morphTargets) {
  21232. // figure out all morph targets used in this track
  21233. var morphTargetNames = {};
  21234. var k = void 0;
  21235. for (k = 0; k < animationKeys.length; k++) {
  21236. if (animationKeys[k].morphTargets) {
  21237. for (var m = 0; m < animationKeys[k].morphTargets.length; m++) {
  21238. morphTargetNames[animationKeys[k].morphTargets[m]] = -1;
  21239. }
  21240. }
  21241. } // create a track for each morph target with all zero
  21242. // morphTargetInfluences except for the keys in which
  21243. // the morphTarget is named.
  21244. for (var morphTargetName in morphTargetNames) {
  21245. var times = [];
  21246. var values = [];
  21247. for (var _m = 0; _m !== animationKeys[k].morphTargets.length; ++_m) {
  21248. var animationKey = animationKeys[k];
  21249. times.push(animationKey.time);
  21250. values.push(animationKey.morphTarget === morphTargetName ? 1 : 0);
  21251. }
  21252. tracks.push(new NumberKeyframeTrack('.morphTargetInfluence[' + morphTargetName + ']', times, values));
  21253. }
  21254. duration = morphTargetNames.length * (fps || 1.0);
  21255. } else {
  21256. // ...assume skeletal animation
  21257. var boneName = '.bones[' + bones[h].name + ']';
  21258. addNonemptyTrack(VectorKeyframeTrack, boneName + '.position', animationKeys, 'pos', tracks);
  21259. addNonemptyTrack(QuaternionKeyframeTrack, boneName + '.quaternion', animationKeys, 'rot', tracks);
  21260. addNonemptyTrack(VectorKeyframeTrack, boneName + '.scale', animationKeys, 'scl', tracks);
  21261. }
  21262. }
  21263. if (tracks.length === 0) {
  21264. return null;
  21265. }
  21266. var clip = new AnimationClip(clipName, duration, tracks, blendMode);
  21267. return clip;
  21268. }
  21269. });
  21270. Object.assign(AnimationClip.prototype, {
  21271. resetDuration: function resetDuration() {
  21272. var tracks = this.tracks;
  21273. var duration = 0;
  21274. for (var i = 0, n = tracks.length; i !== n; ++i) {
  21275. var track = this.tracks[i];
  21276. duration = Math.max(duration, track.times[track.times.length - 1]);
  21277. }
  21278. this.duration = duration;
  21279. return this;
  21280. },
  21281. trim: function trim() {
  21282. for (var i = 0; i < this.tracks.length; i++) {
  21283. this.tracks[i].trim(0, this.duration);
  21284. }
  21285. return this;
  21286. },
  21287. validate: function validate() {
  21288. var valid = true;
  21289. for (var i = 0; i < this.tracks.length; i++) {
  21290. valid = valid && this.tracks[i].validate();
  21291. }
  21292. return valid;
  21293. },
  21294. optimize: function optimize() {
  21295. for (var i = 0; i < this.tracks.length; i++) {
  21296. this.tracks[i].optimize();
  21297. }
  21298. return this;
  21299. },
  21300. clone: function clone() {
  21301. var tracks = [];
  21302. for (var i = 0; i < this.tracks.length; i++) {
  21303. tracks.push(this.tracks[i].clone());
  21304. }
  21305. return new AnimationClip(this.name, this.duration, tracks, this.blendMode);
  21306. },
  21307. toJSON: function toJSON() {
  21308. return AnimationClip.toJSON(this);
  21309. }
  21310. });
  21311. var Cache = {
  21312. enabled: false,
  21313. files: {},
  21314. add: function add(key, file) {
  21315. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Adding key:', key );
  21316. this.files[key] = file;
  21317. },
  21318. get: function get(key) {
  21319. if (this.enabled === false) return; // console.log( 'THREE.Cache', 'Checking key:', key );
  21320. return this.files[key];
  21321. },
  21322. remove: function remove(key) {
  21323. delete this.files[key];
  21324. },
  21325. clear: function clear() {
  21326. this.files = {};
  21327. }
  21328. };
  21329. function LoadingManager(onLoad, onProgress, onError) {
  21330. var scope = this;
  21331. var isLoading = false;
  21332. var itemsLoaded = 0;
  21333. var itemsTotal = 0;
  21334. var urlModifier = undefined;
  21335. var handlers = []; // Refer to #5689 for the reason why we don't set .onStart
  21336. // in the constructor
  21337. this.onStart = undefined;
  21338. this.onLoad = onLoad;
  21339. this.onProgress = onProgress;
  21340. this.onError = onError;
  21341. this.itemStart = function (url) {
  21342. itemsTotal++;
  21343. if (isLoading === false) {
  21344. if (scope.onStart !== undefined) {
  21345. scope.onStart(url, itemsLoaded, itemsTotal);
  21346. }
  21347. }
  21348. isLoading = true;
  21349. };
  21350. this.itemEnd = function (url) {
  21351. itemsLoaded++;
  21352. if (scope.onProgress !== undefined) {
  21353. scope.onProgress(url, itemsLoaded, itemsTotal);
  21354. }
  21355. if (itemsLoaded === itemsTotal) {
  21356. isLoading = false;
  21357. if (scope.onLoad !== undefined) {
  21358. scope.onLoad();
  21359. }
  21360. }
  21361. };
  21362. this.itemError = function (url) {
  21363. if (scope.onError !== undefined) {
  21364. scope.onError(url);
  21365. }
  21366. };
  21367. this.resolveURL = function (url) {
  21368. if (urlModifier) {
  21369. return urlModifier(url);
  21370. }
  21371. return url;
  21372. };
  21373. this.setURLModifier = function (transform) {
  21374. urlModifier = transform;
  21375. return this;
  21376. };
  21377. this.addHandler = function (regex, loader) {
  21378. handlers.push(regex, loader);
  21379. return this;
  21380. };
  21381. this.removeHandler = function (regex) {
  21382. var index = handlers.indexOf(regex);
  21383. if (index !== -1) {
  21384. handlers.splice(index, 2);
  21385. }
  21386. return this;
  21387. };
  21388. this.getHandler = function (file) {
  21389. for (var i = 0, l = handlers.length; i < l; i += 2) {
  21390. var regex = handlers[i];
  21391. var loader = handlers[i + 1];
  21392. if (regex.global) regex.lastIndex = 0; // see #17920
  21393. if (regex.test(file)) {
  21394. return loader;
  21395. }
  21396. }
  21397. return null;
  21398. };
  21399. }
  21400. var DefaultLoadingManager = new LoadingManager();
  21401. function Loader(manager) {
  21402. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  21403. this.crossOrigin = 'anonymous';
  21404. this.withCredentials = false;
  21405. this.path = '';
  21406. this.resourcePath = '';
  21407. this.requestHeader = {};
  21408. }
  21409. Object.assign(Loader.prototype, {
  21410. load: function load()
  21411. /* url, onLoad, onProgress, onError */
  21412. {},
  21413. loadAsync: function loadAsync(url, onProgress) {
  21414. var scope = this;
  21415. return new Promise(function (resolve, reject) {
  21416. scope.load(url, resolve, onProgress, reject);
  21417. });
  21418. },
  21419. parse: function parse()
  21420. /* data */
  21421. {},
  21422. setCrossOrigin: function setCrossOrigin(crossOrigin) {
  21423. this.crossOrigin = crossOrigin;
  21424. return this;
  21425. },
  21426. setWithCredentials: function setWithCredentials(value) {
  21427. this.withCredentials = value;
  21428. return this;
  21429. },
  21430. setPath: function setPath(path) {
  21431. this.path = path;
  21432. return this;
  21433. },
  21434. setResourcePath: function setResourcePath(resourcePath) {
  21435. this.resourcePath = resourcePath;
  21436. return this;
  21437. },
  21438. setRequestHeader: function setRequestHeader(requestHeader) {
  21439. this.requestHeader = requestHeader;
  21440. return this;
  21441. }
  21442. });
  21443. var loading = {};
  21444. function FileLoader(manager) {
  21445. Loader.call(this, manager);
  21446. }
  21447. FileLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21448. constructor: FileLoader,
  21449. load: function load(url, onLoad, onProgress, onError) {
  21450. if (url === undefined) url = '';
  21451. if (this.path !== undefined) url = this.path + url;
  21452. url = this.manager.resolveURL(url);
  21453. var scope = this;
  21454. var cached = Cache.get(url);
  21455. if (cached !== undefined) {
  21456. scope.manager.itemStart(url);
  21457. setTimeout(function () {
  21458. if (onLoad) onLoad(cached);
  21459. scope.manager.itemEnd(url);
  21460. }, 0);
  21461. return cached;
  21462. } // Check if request is duplicate
  21463. if (loading[url] !== undefined) {
  21464. loading[url].push({
  21465. onLoad: onLoad,
  21466. onProgress: onProgress,
  21467. onError: onError
  21468. });
  21469. return;
  21470. } // Check for data: URI
  21471. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21472. var dataUriRegexResult = url.match(dataUriRegex);
  21473. var request; // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21474. if (dataUriRegexResult) {
  21475. var mimeType = dataUriRegexResult[1];
  21476. var isBase64 = !!dataUriRegexResult[2];
  21477. var data = dataUriRegexResult[3];
  21478. data = decodeURIComponent(data);
  21479. if (isBase64) data = atob(data);
  21480. try {
  21481. var response;
  21482. var responseType = (this.responseType || '').toLowerCase();
  21483. switch (responseType) {
  21484. case 'arraybuffer':
  21485. case 'blob':
  21486. var view = new Uint8Array(data.length);
  21487. for (var i = 0; i < data.length; i++) {
  21488. view[i] = data.charCodeAt(i);
  21489. }
  21490. if (responseType === 'blob') {
  21491. response = new Blob([view.buffer], {
  21492. type: mimeType
  21493. });
  21494. } else {
  21495. response = view.buffer;
  21496. }
  21497. break;
  21498. case 'document':
  21499. var parser = new DOMParser();
  21500. response = parser.parseFromString(data, mimeType);
  21501. break;
  21502. case 'json':
  21503. response = JSON.parse(data);
  21504. break;
  21505. default:
  21506. // 'text' or other
  21507. response = data;
  21508. break;
  21509. } // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21510. setTimeout(function () {
  21511. if (onLoad) onLoad(response);
  21512. scope.manager.itemEnd(url);
  21513. }, 0);
  21514. } catch (error) {
  21515. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21516. setTimeout(function () {
  21517. if (onError) onError(error);
  21518. scope.manager.itemError(url);
  21519. scope.manager.itemEnd(url);
  21520. }, 0);
  21521. }
  21522. } else {
  21523. // Initialise array for duplicate requests
  21524. loading[url] = [];
  21525. loading[url].push({
  21526. onLoad: onLoad,
  21527. onProgress: onProgress,
  21528. onError: onError
  21529. });
  21530. request = new XMLHttpRequest();
  21531. request.open('GET', url, true);
  21532. request.addEventListener('load', function (event) {
  21533. var response = this.response;
  21534. var callbacks = loading[url];
  21535. delete loading[url];
  21536. if (this.status === 200 || this.status === 0) {
  21537. // Some browsers return HTTP Status 0 when using non-http protocol
  21538. // e.g. 'file://' or 'data://'. Handle as success.
  21539. 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
  21540. // error response bodies as proper responses to requests.
  21541. Cache.add(url, response);
  21542. for (var _i = 0, il = callbacks.length; _i < il; _i++) {
  21543. var callback = callbacks[_i];
  21544. if (callback.onLoad) callback.onLoad(response);
  21545. }
  21546. scope.manager.itemEnd(url);
  21547. } else {
  21548. for (var _i2 = 0, _il = callbacks.length; _i2 < _il; _i2++) {
  21549. var _callback = callbacks[_i2];
  21550. if (_callback.onError) _callback.onError(event);
  21551. }
  21552. scope.manager.itemError(url);
  21553. scope.manager.itemEnd(url);
  21554. }
  21555. }, false);
  21556. request.addEventListener('progress', function (event) {
  21557. var callbacks = loading[url];
  21558. for (var _i3 = 0, il = callbacks.length; _i3 < il; _i3++) {
  21559. var callback = callbacks[_i3];
  21560. if (callback.onProgress) callback.onProgress(event);
  21561. }
  21562. }, false);
  21563. request.addEventListener('error', function (event) {
  21564. var callbacks = loading[url];
  21565. delete loading[url];
  21566. for (var _i4 = 0, il = callbacks.length; _i4 < il; _i4++) {
  21567. var callback = callbacks[_i4];
  21568. if (callback.onError) callback.onError(event);
  21569. }
  21570. scope.manager.itemError(url);
  21571. scope.manager.itemEnd(url);
  21572. }, false);
  21573. request.addEventListener('abort', function (event) {
  21574. var callbacks = loading[url];
  21575. delete loading[url];
  21576. for (var _i5 = 0, il = callbacks.length; _i5 < il; _i5++) {
  21577. var callback = callbacks[_i5];
  21578. if (callback.onError) callback.onError(event);
  21579. }
  21580. scope.manager.itemError(url);
  21581. scope.manager.itemEnd(url);
  21582. }, false);
  21583. if (this.responseType !== undefined) request.responseType = this.responseType;
  21584. if (this.withCredentials !== undefined) request.withCredentials = this.withCredentials;
  21585. if (request.overrideMimeType) request.overrideMimeType(this.mimeType !== undefined ? this.mimeType : 'text/plain');
  21586. for (var header in this.requestHeader) {
  21587. request.setRequestHeader(header, this.requestHeader[header]);
  21588. }
  21589. request.send(null);
  21590. }
  21591. scope.manager.itemStart(url);
  21592. return request;
  21593. },
  21594. setResponseType: function setResponseType(value) {
  21595. this.responseType = value;
  21596. return this;
  21597. },
  21598. setMimeType: function setMimeType(value) {
  21599. this.mimeType = value;
  21600. return this;
  21601. }
  21602. });
  21603. function AnimationLoader(manager) {
  21604. Loader.call(this, manager);
  21605. }
  21606. AnimationLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21607. constructor: AnimationLoader,
  21608. load: function load(url, onLoad, onProgress, onError) {
  21609. var scope = this;
  21610. var loader = new FileLoader(scope.manager);
  21611. loader.setPath(scope.path);
  21612. loader.setRequestHeader(scope.requestHeader);
  21613. loader.setWithCredentials(scope.withCredentials);
  21614. loader.load(url, function (text) {
  21615. try {
  21616. onLoad(scope.parse(JSON.parse(text)));
  21617. } catch (e) {
  21618. if (onError) {
  21619. onError(e);
  21620. } else {
  21621. console.error(e);
  21622. }
  21623. scope.manager.itemError(url);
  21624. }
  21625. }, onProgress, onError);
  21626. },
  21627. parse: function parse(json) {
  21628. var animations = [];
  21629. for (var i = 0; i < json.length; i++) {
  21630. var clip = AnimationClip.parse(json[i]);
  21631. animations.push(clip);
  21632. }
  21633. return animations;
  21634. }
  21635. });
  21636. /**
  21637. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21638. *
  21639. * Sub classes have to implement the parse() method which will be used in load().
  21640. */
  21641. function CompressedTextureLoader(manager) {
  21642. Loader.call(this, manager);
  21643. }
  21644. CompressedTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21645. constructor: CompressedTextureLoader,
  21646. load: function load(url, onLoad, onProgress, onError) {
  21647. var scope = this;
  21648. var images = [];
  21649. var texture = new CompressedTexture();
  21650. var loader = new FileLoader(this.manager);
  21651. loader.setPath(this.path);
  21652. loader.setResponseType('arraybuffer');
  21653. loader.setRequestHeader(this.requestHeader);
  21654. loader.setWithCredentials(scope.withCredentials);
  21655. var loaded = 0;
  21656. function loadTexture(i) {
  21657. loader.load(url[i], function (buffer) {
  21658. var texDatas = scope.parse(buffer, true);
  21659. images[i] = {
  21660. width: texDatas.width,
  21661. height: texDatas.height,
  21662. format: texDatas.format,
  21663. mipmaps: texDatas.mipmaps
  21664. };
  21665. loaded += 1;
  21666. if (loaded === 6) {
  21667. if (texDatas.mipmapCount === 1) texture.minFilter = LinearFilter;
  21668. texture.image = images;
  21669. texture.format = texDatas.format;
  21670. texture.needsUpdate = true;
  21671. if (onLoad) onLoad(texture);
  21672. }
  21673. }, onProgress, onError);
  21674. }
  21675. if (Array.isArray(url)) {
  21676. for (var i = 0, il = url.length; i < il; ++i) {
  21677. loadTexture(i);
  21678. }
  21679. } else {
  21680. // compressed cubemap texture stored in a single DDS file
  21681. loader.load(url, function (buffer) {
  21682. var texDatas = scope.parse(buffer, true);
  21683. if (texDatas.isCubemap) {
  21684. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21685. for (var f = 0; f < faces; f++) {
  21686. images[f] = {
  21687. mipmaps: []
  21688. };
  21689. for (var _i = 0; _i < texDatas.mipmapCount; _i++) {
  21690. images[f].mipmaps.push(texDatas.mipmaps[f * texDatas.mipmapCount + _i]);
  21691. images[f].format = texDatas.format;
  21692. images[f].width = texDatas.width;
  21693. images[f].height = texDatas.height;
  21694. }
  21695. }
  21696. texture.image = images;
  21697. } else {
  21698. texture.image.width = texDatas.width;
  21699. texture.image.height = texDatas.height;
  21700. texture.mipmaps = texDatas.mipmaps;
  21701. }
  21702. if (texDatas.mipmapCount === 1) {
  21703. texture.minFilter = LinearFilter;
  21704. }
  21705. texture.format = texDatas.format;
  21706. texture.needsUpdate = true;
  21707. if (onLoad) onLoad(texture);
  21708. }, onProgress, onError);
  21709. }
  21710. return texture;
  21711. }
  21712. });
  21713. function ImageLoader(manager) {
  21714. Loader.call(this, manager);
  21715. }
  21716. ImageLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21717. constructor: ImageLoader,
  21718. load: function load(url, onLoad, onProgress, onError) {
  21719. if (this.path !== undefined) url = this.path + url;
  21720. url = this.manager.resolveURL(url);
  21721. var scope = this;
  21722. var cached = Cache.get(url);
  21723. if (cached !== undefined) {
  21724. scope.manager.itemStart(url);
  21725. setTimeout(function () {
  21726. if (onLoad) onLoad(cached);
  21727. scope.manager.itemEnd(url);
  21728. }, 0);
  21729. return cached;
  21730. }
  21731. var image = document.createElementNS('http://www.w3.org/1999/xhtml', 'img');
  21732. function onImageLoad() {
  21733. image.removeEventListener('load', onImageLoad, false);
  21734. image.removeEventListener('error', onImageError, false);
  21735. Cache.add(url, this);
  21736. if (onLoad) onLoad(this);
  21737. scope.manager.itemEnd(url);
  21738. }
  21739. function onImageError(event) {
  21740. image.removeEventListener('load', onImageLoad, false);
  21741. image.removeEventListener('error', onImageError, false);
  21742. if (onError) onError(event);
  21743. scope.manager.itemError(url);
  21744. scope.manager.itemEnd(url);
  21745. }
  21746. image.addEventListener('load', onImageLoad, false);
  21747. image.addEventListener('error', onImageError, false);
  21748. if (url.substr(0, 5) !== 'data:') {
  21749. if (this.crossOrigin !== undefined) image.crossOrigin = this.crossOrigin;
  21750. }
  21751. scope.manager.itemStart(url);
  21752. image.src = url;
  21753. return image;
  21754. }
  21755. });
  21756. function CubeTextureLoader(manager) {
  21757. Loader.call(this, manager);
  21758. }
  21759. CubeTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21760. constructor: CubeTextureLoader,
  21761. load: function load(urls, onLoad, onProgress, onError) {
  21762. var texture = new CubeTexture();
  21763. var loader = new ImageLoader(this.manager);
  21764. loader.setCrossOrigin(this.crossOrigin);
  21765. loader.setPath(this.path);
  21766. var loaded = 0;
  21767. function loadTexture(i) {
  21768. loader.load(urls[i], function (image) {
  21769. texture.images[i] = image;
  21770. loaded++;
  21771. if (loaded === 6) {
  21772. texture.needsUpdate = true;
  21773. if (onLoad) onLoad(texture);
  21774. }
  21775. }, undefined, onError);
  21776. }
  21777. for (var i = 0; i < urls.length; ++i) {
  21778. loadTexture(i);
  21779. }
  21780. return texture;
  21781. }
  21782. });
  21783. /**
  21784. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21785. *
  21786. * Sub classes have to implement the parse() method which will be used in load().
  21787. */
  21788. function DataTextureLoader(manager) {
  21789. Loader.call(this, manager);
  21790. }
  21791. DataTextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21792. constructor: DataTextureLoader,
  21793. load: function load(url, onLoad, onProgress, onError) {
  21794. var scope = this;
  21795. var texture = new DataTexture();
  21796. var loader = new FileLoader(this.manager);
  21797. loader.setResponseType('arraybuffer');
  21798. loader.setRequestHeader(this.requestHeader);
  21799. loader.setPath(this.path);
  21800. loader.setWithCredentials(scope.withCredentials);
  21801. loader.load(url, function (buffer) {
  21802. var texData = scope.parse(buffer);
  21803. if (!texData) return;
  21804. if (texData.image !== undefined) {
  21805. texture.image = texData.image;
  21806. } else if (texData.data !== undefined) {
  21807. texture.image.width = texData.width;
  21808. texture.image.height = texData.height;
  21809. texture.image.data = texData.data;
  21810. }
  21811. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21812. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21813. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21814. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  21815. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21816. if (texData.format !== undefined) {
  21817. texture.format = texData.format;
  21818. }
  21819. if (texData.type !== undefined) {
  21820. texture.type = texData.type;
  21821. }
  21822. if (texData.mipmaps !== undefined) {
  21823. texture.mipmaps = texData.mipmaps;
  21824. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  21825. }
  21826. if (texData.mipmapCount === 1) {
  21827. texture.minFilter = LinearFilter;
  21828. }
  21829. texture.needsUpdate = true;
  21830. if (onLoad) onLoad(texture, texData);
  21831. }, onProgress, onError);
  21832. return texture;
  21833. }
  21834. });
  21835. function TextureLoader(manager) {
  21836. Loader.call(this, manager);
  21837. }
  21838. TextureLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  21839. constructor: TextureLoader,
  21840. load: function load(url, onLoad, onProgress, onError) {
  21841. var texture = new Texture();
  21842. var loader = new ImageLoader(this.manager);
  21843. loader.setCrossOrigin(this.crossOrigin);
  21844. loader.setPath(this.path);
  21845. loader.load(url, function (image) {
  21846. texture.image = image; // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21847. var isJPEG = url.search(/\.jpe?g($|\?)/i) > 0 || url.search(/^data\:image\/jpeg/) === 0;
  21848. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21849. texture.needsUpdate = true;
  21850. if (onLoad !== undefined) {
  21851. onLoad(texture);
  21852. }
  21853. }, onProgress, onError);
  21854. return texture;
  21855. }
  21856. });
  21857. /**
  21858. * Extensible curve object.
  21859. *
  21860. * Some common of curve methods:
  21861. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  21862. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  21863. * .getPoints(), .getSpacedPoints()
  21864. * .getLength()
  21865. * .updateArcLengths()
  21866. *
  21867. * This following curves inherit from THREE.Curve:
  21868. *
  21869. * -- 2D curves --
  21870. * THREE.ArcCurve
  21871. * THREE.CubicBezierCurve
  21872. * THREE.EllipseCurve
  21873. * THREE.LineCurve
  21874. * THREE.QuadraticBezierCurve
  21875. * THREE.SplineCurve
  21876. *
  21877. * -- 3D curves --
  21878. * THREE.CatmullRomCurve3
  21879. * THREE.CubicBezierCurve3
  21880. * THREE.LineCurve3
  21881. * THREE.QuadraticBezierCurve3
  21882. *
  21883. * A series of curves can be represented as a THREE.CurvePath.
  21884. *
  21885. **/
  21886. function Curve() {
  21887. this.type = 'Curve';
  21888. this.arcLengthDivisions = 200;
  21889. }
  21890. Object.assign(Curve.prototype, {
  21891. // Virtual base class method to overwrite and implement in subclasses
  21892. // - t [0 .. 1]
  21893. getPoint: function getPoint()
  21894. /* t, optionalTarget */
  21895. {
  21896. console.warn('THREE.Curve: .getPoint() not implemented.');
  21897. return null;
  21898. },
  21899. // Get point at relative position in curve according to arc length
  21900. // - u [0 .. 1]
  21901. getPointAt: function getPointAt(u, optionalTarget) {
  21902. var t = this.getUtoTmapping(u);
  21903. return this.getPoint(t, optionalTarget);
  21904. },
  21905. // Get sequence of points using getPoint( t )
  21906. getPoints: function getPoints(divisions) {
  21907. if (divisions === void 0) {
  21908. divisions = 5;
  21909. }
  21910. var points = [];
  21911. for (var d = 0; d <= divisions; d++) {
  21912. points.push(this.getPoint(d / divisions));
  21913. }
  21914. return points;
  21915. },
  21916. // Get sequence of points using getPointAt( u )
  21917. getSpacedPoints: function getSpacedPoints(divisions) {
  21918. if (divisions === void 0) {
  21919. divisions = 5;
  21920. }
  21921. var points = [];
  21922. for (var d = 0; d <= divisions; d++) {
  21923. points.push(this.getPointAt(d / divisions));
  21924. }
  21925. return points;
  21926. },
  21927. // Get total curve arc length
  21928. getLength: function getLength() {
  21929. var lengths = this.getLengths();
  21930. return lengths[lengths.length - 1];
  21931. },
  21932. // Get list of cumulative segment lengths
  21933. getLengths: function getLengths(divisions) {
  21934. if (divisions === undefined) divisions = this.arcLengthDivisions;
  21935. if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
  21936. return this.cacheArcLengths;
  21937. }
  21938. this.needsUpdate = false;
  21939. var cache = [];
  21940. var current,
  21941. last = this.getPoint(0);
  21942. var sum = 0;
  21943. cache.push(0);
  21944. for (var p = 1; p <= divisions; p++) {
  21945. current = this.getPoint(p / divisions);
  21946. sum += current.distanceTo(last);
  21947. cache.push(sum);
  21948. last = current;
  21949. }
  21950. this.cacheArcLengths = cache;
  21951. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21952. },
  21953. updateArcLengths: function updateArcLengths() {
  21954. this.needsUpdate = true;
  21955. this.getLengths();
  21956. },
  21957. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21958. getUtoTmapping: function getUtoTmapping(u, distance) {
  21959. var arcLengths = this.getLengths();
  21960. var i = 0;
  21961. var il = arcLengths.length;
  21962. var targetArcLength; // The targeted u distance value to get
  21963. if (distance) {
  21964. targetArcLength = distance;
  21965. } else {
  21966. targetArcLength = u * arcLengths[il - 1];
  21967. } // binary search for the index with largest value smaller than target u distance
  21968. var low = 0,
  21969. high = il - 1,
  21970. comparison;
  21971. while (low <= high) {
  21972. 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
  21973. comparison = arcLengths[i] - targetArcLength;
  21974. if (comparison < 0) {
  21975. low = i + 1;
  21976. } else if (comparison > 0) {
  21977. high = i - 1;
  21978. } else {
  21979. high = i;
  21980. break; // DONE
  21981. }
  21982. }
  21983. i = high;
  21984. if (arcLengths[i] === targetArcLength) {
  21985. return i / (il - 1);
  21986. } // we could get finer grain at lengths, or use simple interpolation between two points
  21987. var lengthBefore = arcLengths[i];
  21988. var lengthAfter = arcLengths[i + 1];
  21989. var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
  21990. var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
  21991. var t = (i + segmentFraction) / (il - 1);
  21992. return t;
  21993. },
  21994. // Returns a unit vector tangent at t
  21995. // In case any sub curve does not implement its tangent derivation,
  21996. // 2 points a small delta apart will be used to find its gradient
  21997. // which seems to give a reasonable approximation
  21998. getTangent: function getTangent(t, optionalTarget) {
  21999. var delta = 0.0001;
  22000. var t1 = t - delta;
  22001. var t2 = t + delta; // Capping in case of danger
  22002. if (t1 < 0) t1 = 0;
  22003. if (t2 > 1) t2 = 1;
  22004. var pt1 = this.getPoint(t1);
  22005. var pt2 = this.getPoint(t2);
  22006. var tangent = optionalTarget || (pt1.isVector2 ? new Vector2() : new Vector3());
  22007. tangent.copy(pt2).sub(pt1).normalize();
  22008. return tangent;
  22009. },
  22010. getTangentAt: function getTangentAt(u, optionalTarget) {
  22011. var t = this.getUtoTmapping(u);
  22012. return this.getTangent(t, optionalTarget);
  22013. },
  22014. computeFrenetFrames: function computeFrenetFrames(segments, closed) {
  22015. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22016. var normal = new Vector3();
  22017. var tangents = [];
  22018. var normals = [];
  22019. var binormals = [];
  22020. var vec = new Vector3();
  22021. var mat = new Matrix4(); // compute the tangent vectors for each segment on the curve
  22022. for (var i = 0; i <= segments; i++) {
  22023. var u = i / segments;
  22024. tangents[i] = this.getTangentAt(u, new Vector3());
  22025. tangents[i].normalize();
  22026. } // select an initial normal vector perpendicular to the first tangent vector,
  22027. // and in the direction of the minimum tangent xyz component
  22028. normals[0] = new Vector3();
  22029. binormals[0] = new Vector3();
  22030. var min = Number.MAX_VALUE;
  22031. var tx = Math.abs(tangents[0].x);
  22032. var ty = Math.abs(tangents[0].y);
  22033. var tz = Math.abs(tangents[0].z);
  22034. if (tx <= min) {
  22035. min = tx;
  22036. normal.set(1, 0, 0);
  22037. }
  22038. if (ty <= min) {
  22039. min = ty;
  22040. normal.set(0, 1, 0);
  22041. }
  22042. if (tz <= min) {
  22043. normal.set(0, 0, 1);
  22044. }
  22045. vec.crossVectors(tangents[0], normal).normalize();
  22046. normals[0].crossVectors(tangents[0], vec);
  22047. binormals[0].crossVectors(tangents[0], normals[0]); // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22048. for (var _i = 1; _i <= segments; _i++) {
  22049. normals[_i] = normals[_i - 1].clone();
  22050. binormals[_i] = binormals[_i - 1].clone();
  22051. vec.crossVectors(tangents[_i - 1], tangents[_i]);
  22052. if (vec.length() > Number.EPSILON) {
  22053. vec.normalize();
  22054. var theta = Math.acos(MathUtils.clamp(tangents[_i - 1].dot(tangents[_i]), -1, 1)); // clamp for floating pt errors
  22055. normals[_i].applyMatrix4(mat.makeRotationAxis(vec, theta));
  22056. }
  22057. binormals[_i].crossVectors(tangents[_i], normals[_i]);
  22058. } // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22059. if (closed === true) {
  22060. var _theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), -1, 1));
  22061. _theta /= segments;
  22062. if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
  22063. _theta = -_theta;
  22064. }
  22065. for (var _i2 = 1; _i2 <= segments; _i2++) {
  22066. // twist a little...
  22067. normals[_i2].applyMatrix4(mat.makeRotationAxis(tangents[_i2], _theta * _i2));
  22068. binormals[_i2].crossVectors(tangents[_i2], normals[_i2]);
  22069. }
  22070. }
  22071. return {
  22072. tangents: tangents,
  22073. normals: normals,
  22074. binormals: binormals
  22075. };
  22076. },
  22077. clone: function clone() {
  22078. return new this.constructor().copy(this);
  22079. },
  22080. copy: function copy(source) {
  22081. this.arcLengthDivisions = source.arcLengthDivisions;
  22082. return this;
  22083. },
  22084. toJSON: function toJSON() {
  22085. var data = {
  22086. metadata: {
  22087. version: 4.5,
  22088. type: 'Curve',
  22089. generator: 'Curve.toJSON'
  22090. }
  22091. };
  22092. data.arcLengthDivisions = this.arcLengthDivisions;
  22093. data.type = this.type;
  22094. return data;
  22095. },
  22096. fromJSON: function fromJSON(json) {
  22097. this.arcLengthDivisions = json.arcLengthDivisions;
  22098. return this;
  22099. }
  22100. });
  22101. function EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22102. Curve.call(this);
  22103. this.type = 'EllipseCurve';
  22104. this.aX = aX || 0;
  22105. this.aY = aY || 0;
  22106. this.xRadius = xRadius || 1;
  22107. this.yRadius = yRadius || 1;
  22108. this.aStartAngle = aStartAngle || 0;
  22109. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22110. this.aClockwise = aClockwise || false;
  22111. this.aRotation = aRotation || 0;
  22112. }
  22113. EllipseCurve.prototype = Object.create(Curve.prototype);
  22114. EllipseCurve.prototype.constructor = EllipseCurve;
  22115. EllipseCurve.prototype.isEllipseCurve = true;
  22116. EllipseCurve.prototype.getPoint = function (t, optionalTarget) {
  22117. var point = optionalTarget || new Vector2();
  22118. var twoPi = Math.PI * 2;
  22119. var deltaAngle = this.aEndAngle - this.aStartAngle;
  22120. var samePoints = Math.abs(deltaAngle) < Number.EPSILON; // ensures that deltaAngle is 0 .. 2 PI
  22121. while (deltaAngle < 0) {
  22122. deltaAngle += twoPi;
  22123. }
  22124. while (deltaAngle > twoPi) {
  22125. deltaAngle -= twoPi;
  22126. }
  22127. if (deltaAngle < Number.EPSILON) {
  22128. if (samePoints) {
  22129. deltaAngle = 0;
  22130. } else {
  22131. deltaAngle = twoPi;
  22132. }
  22133. }
  22134. if (this.aClockwise === true && !samePoints) {
  22135. if (deltaAngle === twoPi) {
  22136. deltaAngle = -twoPi;
  22137. } else {
  22138. deltaAngle = deltaAngle - twoPi;
  22139. }
  22140. }
  22141. var angle = this.aStartAngle + t * deltaAngle;
  22142. var x = this.aX + this.xRadius * Math.cos(angle);
  22143. var y = this.aY + this.yRadius * Math.sin(angle);
  22144. if (this.aRotation !== 0) {
  22145. var cos = Math.cos(this.aRotation);
  22146. var sin = Math.sin(this.aRotation);
  22147. var tx = x - this.aX;
  22148. var ty = y - this.aY; // Rotate the point about the center of the ellipse.
  22149. x = tx * cos - ty * sin + this.aX;
  22150. y = tx * sin + ty * cos + this.aY;
  22151. }
  22152. return point.set(x, y);
  22153. };
  22154. EllipseCurve.prototype.copy = function (source) {
  22155. Curve.prototype.copy.call(this, source);
  22156. this.aX = source.aX;
  22157. this.aY = source.aY;
  22158. this.xRadius = source.xRadius;
  22159. this.yRadius = source.yRadius;
  22160. this.aStartAngle = source.aStartAngle;
  22161. this.aEndAngle = source.aEndAngle;
  22162. this.aClockwise = source.aClockwise;
  22163. this.aRotation = source.aRotation;
  22164. return this;
  22165. };
  22166. EllipseCurve.prototype.toJSON = function () {
  22167. var data = Curve.prototype.toJSON.call(this);
  22168. data.aX = this.aX;
  22169. data.aY = this.aY;
  22170. data.xRadius = this.xRadius;
  22171. data.yRadius = this.yRadius;
  22172. data.aStartAngle = this.aStartAngle;
  22173. data.aEndAngle = this.aEndAngle;
  22174. data.aClockwise = this.aClockwise;
  22175. data.aRotation = this.aRotation;
  22176. return data;
  22177. };
  22178. EllipseCurve.prototype.fromJSON = function (json) {
  22179. Curve.prototype.fromJSON.call(this, json);
  22180. this.aX = json.aX;
  22181. this.aY = json.aY;
  22182. this.xRadius = json.xRadius;
  22183. this.yRadius = json.yRadius;
  22184. this.aStartAngle = json.aStartAngle;
  22185. this.aEndAngle = json.aEndAngle;
  22186. this.aClockwise = json.aClockwise;
  22187. this.aRotation = json.aRotation;
  22188. return this;
  22189. };
  22190. function ArcCurve(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22191. EllipseCurve.call(this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22192. this.type = 'ArcCurve';
  22193. }
  22194. ArcCurve.prototype = Object.create(EllipseCurve.prototype);
  22195. ArcCurve.prototype.constructor = ArcCurve;
  22196. ArcCurve.prototype.isArcCurve = true;
  22197. /**
  22198. * Centripetal CatmullRom Curve - which is useful for avoiding
  22199. * cusps and self-intersections in non-uniform catmull rom curves.
  22200. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22201. *
  22202. * curve.type accepts centripetal(default), chordal and catmullrom
  22203. * curve.tension is used for catmullrom which defaults to 0.5
  22204. */
  22205. /*
  22206. Based on an optimized c++ solution in
  22207. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22208. - http://ideone.com/NoEbVM
  22209. This CubicPoly class could be used for reusing some variables and calculations,
  22210. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22211. which can be placed in CurveUtils.
  22212. */
  22213. function CubicPoly() {
  22214. var c0 = 0,
  22215. c1 = 0,
  22216. c2 = 0,
  22217. c3 = 0;
  22218. /*
  22219. * Compute coefficients for a cubic polynomial
  22220. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22221. * such that
  22222. * p(0) = x0, p(1) = x1
  22223. * and
  22224. * p'(0) = t0, p'(1) = t1.
  22225. */
  22226. function init(x0, x1, t0, t1) {
  22227. c0 = x0;
  22228. c1 = t0;
  22229. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  22230. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22231. }
  22232. return {
  22233. initCatmullRom: function initCatmullRom(x0, x1, x2, x3, tension) {
  22234. init(x1, x2, tension * (x2 - x0), tension * (x3 - x1));
  22235. },
  22236. initNonuniformCatmullRom: function initNonuniformCatmullRom(x0, x1, x2, x3, dt0, dt1, dt2) {
  22237. // compute tangents when parameterized in [t1,t2]
  22238. var t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1;
  22239. var t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; // rescale tangents for parametrization in [0,1]
  22240. t1 *= dt1;
  22241. t2 *= dt1;
  22242. init(x1, x2, t1, t2);
  22243. },
  22244. calc: function calc(t) {
  22245. var t2 = t * t;
  22246. var t3 = t2 * t;
  22247. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22248. }
  22249. };
  22250. } //
  22251. var tmp = new Vector3();
  22252. var px = new CubicPoly(),
  22253. py = new CubicPoly(),
  22254. pz = new CubicPoly();
  22255. function CatmullRomCurve3(points, closed, curveType, tension) {
  22256. if (points === void 0) {
  22257. points = [];
  22258. }
  22259. if (closed === void 0) {
  22260. closed = false;
  22261. }
  22262. if (curveType === void 0) {
  22263. curveType = 'centripetal';
  22264. }
  22265. if (tension === void 0) {
  22266. tension = 0.5;
  22267. }
  22268. Curve.call(this);
  22269. this.type = 'CatmullRomCurve3';
  22270. this.points = points;
  22271. this.closed = closed;
  22272. this.curveType = curveType;
  22273. this.tension = tension;
  22274. }
  22275. CatmullRomCurve3.prototype = Object.create(Curve.prototype);
  22276. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22277. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22278. CatmullRomCurve3.prototype.getPoint = function (t, optionalTarget) {
  22279. if (optionalTarget === void 0) {
  22280. optionalTarget = new Vector3();
  22281. }
  22282. var point = optionalTarget;
  22283. var points = this.points;
  22284. var l = points.length;
  22285. var p = (l - (this.closed ? 0 : 1)) * t;
  22286. var intPoint = Math.floor(p);
  22287. var weight = p - intPoint;
  22288. if (this.closed) {
  22289. intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l;
  22290. } else if (weight === 0 && intPoint === l - 1) {
  22291. intPoint = l - 2;
  22292. weight = 1;
  22293. }
  22294. var p0, p3; // 4 points (p1 & p2 defined below)
  22295. if (this.closed || intPoint > 0) {
  22296. p0 = points[(intPoint - 1) % l];
  22297. } else {
  22298. // extrapolate first point
  22299. tmp.subVectors(points[0], points[1]).add(points[0]);
  22300. p0 = tmp;
  22301. }
  22302. var p1 = points[intPoint % l];
  22303. var p2 = points[(intPoint + 1) % l];
  22304. if (this.closed || intPoint + 2 < l) {
  22305. p3 = points[(intPoint + 2) % l];
  22306. } else {
  22307. // extrapolate last point
  22308. tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]);
  22309. p3 = tmp;
  22310. }
  22311. if (this.curveType === 'centripetal' || this.curveType === 'chordal') {
  22312. // init Centripetal / Chordal Catmull-Rom
  22313. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22314. var dt0 = Math.pow(p0.distanceToSquared(p1), pow);
  22315. var dt1 = Math.pow(p1.distanceToSquared(p2), pow);
  22316. var dt2 = Math.pow(p2.distanceToSquared(p3), pow); // safety check for repeated points
  22317. if (dt1 < 1e-4) dt1 = 1.0;
  22318. if (dt0 < 1e-4) dt0 = dt1;
  22319. if (dt2 < 1e-4) dt2 = dt1;
  22320. px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2);
  22321. py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2);
  22322. pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2);
  22323. } else if (this.curveType === 'catmullrom') {
  22324. px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension);
  22325. py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension);
  22326. pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension);
  22327. }
  22328. point.set(px.calc(weight), py.calc(weight), pz.calc(weight));
  22329. return point;
  22330. };
  22331. CatmullRomCurve3.prototype.copy = function (source) {
  22332. Curve.prototype.copy.call(this, source);
  22333. this.points = [];
  22334. for (var i = 0, l = source.points.length; i < l; i++) {
  22335. var point = source.points[i];
  22336. this.points.push(point.clone());
  22337. }
  22338. this.closed = source.closed;
  22339. this.curveType = source.curveType;
  22340. this.tension = source.tension;
  22341. return this;
  22342. };
  22343. CatmullRomCurve3.prototype.toJSON = function () {
  22344. var data = Curve.prototype.toJSON.call(this);
  22345. data.points = [];
  22346. for (var i = 0, l = this.points.length; i < l; i++) {
  22347. var point = this.points[i];
  22348. data.points.push(point.toArray());
  22349. }
  22350. data.closed = this.closed;
  22351. data.curveType = this.curveType;
  22352. data.tension = this.tension;
  22353. return data;
  22354. };
  22355. CatmullRomCurve3.prototype.fromJSON = function (json) {
  22356. Curve.prototype.fromJSON.call(this, json);
  22357. this.points = [];
  22358. for (var i = 0, l = json.points.length; i < l; i++) {
  22359. var point = json.points[i];
  22360. this.points.push(new Vector3().fromArray(point));
  22361. }
  22362. this.closed = json.closed;
  22363. this.curveType = json.curveType;
  22364. this.tension = json.tension;
  22365. return this;
  22366. };
  22367. /**
  22368. * Bezier Curves formulas obtained from
  22369. * http://en.wikipedia.org/wiki/Bézier_curve
  22370. */
  22371. function CatmullRom(t, p0, p1, p2, p3) {
  22372. var v0 = (p2 - p0) * 0.5;
  22373. var v1 = (p3 - p1) * 0.5;
  22374. var t2 = t * t;
  22375. var t3 = t * t2;
  22376. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  22377. } //
  22378. function QuadraticBezierP0(t, p) {
  22379. var k = 1 - t;
  22380. return k * k * p;
  22381. }
  22382. function QuadraticBezierP1(t, p) {
  22383. return 2 * (1 - t) * t * p;
  22384. }
  22385. function QuadraticBezierP2(t, p) {
  22386. return t * t * p;
  22387. }
  22388. function QuadraticBezier(t, p0, p1, p2) {
  22389. return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
  22390. } //
  22391. function CubicBezierP0(t, p) {
  22392. var k = 1 - t;
  22393. return k * k * k * p;
  22394. }
  22395. function CubicBezierP1(t, p) {
  22396. var k = 1 - t;
  22397. return 3 * k * k * t * p;
  22398. }
  22399. function CubicBezierP2(t, p) {
  22400. return 3 * (1 - t) * t * t * p;
  22401. }
  22402. function CubicBezierP3(t, p) {
  22403. return t * t * t * p;
  22404. }
  22405. function CubicBezier(t, p0, p1, p2, p3) {
  22406. return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3);
  22407. }
  22408. function CubicBezierCurve(v0, v1, v2, v3) {
  22409. if (v0 === void 0) {
  22410. v0 = new Vector2();
  22411. }
  22412. if (v1 === void 0) {
  22413. v1 = new Vector2();
  22414. }
  22415. if (v2 === void 0) {
  22416. v2 = new Vector2();
  22417. }
  22418. if (v3 === void 0) {
  22419. v3 = new Vector2();
  22420. }
  22421. Curve.call(this);
  22422. this.type = 'CubicBezierCurve';
  22423. this.v0 = v0;
  22424. this.v1 = v1;
  22425. this.v2 = v2;
  22426. this.v3 = v3;
  22427. }
  22428. CubicBezierCurve.prototype = Object.create(Curve.prototype);
  22429. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22430. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22431. CubicBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22432. if (optionalTarget === void 0) {
  22433. optionalTarget = new Vector2();
  22434. }
  22435. var point = optionalTarget;
  22436. var v0 = this.v0,
  22437. v1 = this.v1,
  22438. v2 = this.v2,
  22439. v3 = this.v3;
  22440. point.set(CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y));
  22441. return point;
  22442. };
  22443. CubicBezierCurve.prototype.copy = function (source) {
  22444. Curve.prototype.copy.call(this, source);
  22445. this.v0.copy(source.v0);
  22446. this.v1.copy(source.v1);
  22447. this.v2.copy(source.v2);
  22448. this.v3.copy(source.v3);
  22449. return this;
  22450. };
  22451. CubicBezierCurve.prototype.toJSON = function () {
  22452. var data = Curve.prototype.toJSON.call(this);
  22453. data.v0 = this.v0.toArray();
  22454. data.v1 = this.v1.toArray();
  22455. data.v2 = this.v2.toArray();
  22456. data.v3 = this.v3.toArray();
  22457. return data;
  22458. };
  22459. CubicBezierCurve.prototype.fromJSON = function (json) {
  22460. Curve.prototype.fromJSON.call(this, json);
  22461. this.v0.fromArray(json.v0);
  22462. this.v1.fromArray(json.v1);
  22463. this.v2.fromArray(json.v2);
  22464. this.v3.fromArray(json.v3);
  22465. return this;
  22466. };
  22467. function CubicBezierCurve3(v0, v1, v2, v3) {
  22468. if (v0 === void 0) {
  22469. v0 = new Vector3();
  22470. }
  22471. if (v1 === void 0) {
  22472. v1 = new Vector3();
  22473. }
  22474. if (v2 === void 0) {
  22475. v2 = new Vector3();
  22476. }
  22477. if (v3 === void 0) {
  22478. v3 = new Vector3();
  22479. }
  22480. Curve.call(this);
  22481. this.type = 'CubicBezierCurve3';
  22482. this.v0 = v0;
  22483. this.v1 = v1;
  22484. this.v2 = v2;
  22485. this.v3 = v3;
  22486. }
  22487. CubicBezierCurve3.prototype = Object.create(Curve.prototype);
  22488. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22489. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22490. CubicBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22491. if (optionalTarget === void 0) {
  22492. optionalTarget = new Vector3();
  22493. }
  22494. var point = optionalTarget;
  22495. var v0 = this.v0,
  22496. v1 = this.v1,
  22497. v2 = this.v2,
  22498. v3 = this.v3;
  22499. 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));
  22500. return point;
  22501. };
  22502. CubicBezierCurve3.prototype.copy = function (source) {
  22503. Curve.prototype.copy.call(this, source);
  22504. this.v0.copy(source.v0);
  22505. this.v1.copy(source.v1);
  22506. this.v2.copy(source.v2);
  22507. this.v3.copy(source.v3);
  22508. return this;
  22509. };
  22510. CubicBezierCurve3.prototype.toJSON = function () {
  22511. var data = Curve.prototype.toJSON.call(this);
  22512. data.v0 = this.v0.toArray();
  22513. data.v1 = this.v1.toArray();
  22514. data.v2 = this.v2.toArray();
  22515. data.v3 = this.v3.toArray();
  22516. return data;
  22517. };
  22518. CubicBezierCurve3.prototype.fromJSON = function (json) {
  22519. Curve.prototype.fromJSON.call(this, json);
  22520. this.v0.fromArray(json.v0);
  22521. this.v1.fromArray(json.v1);
  22522. this.v2.fromArray(json.v2);
  22523. this.v3.fromArray(json.v3);
  22524. return this;
  22525. };
  22526. function LineCurve(v1, v2) {
  22527. if (v1 === void 0) {
  22528. v1 = new Vector2();
  22529. }
  22530. if (v2 === void 0) {
  22531. v2 = new Vector2();
  22532. }
  22533. Curve.call(this);
  22534. this.type = 'LineCurve';
  22535. this.v1 = v1;
  22536. this.v2 = v2;
  22537. }
  22538. LineCurve.prototype = Object.create(Curve.prototype);
  22539. LineCurve.prototype.constructor = LineCurve;
  22540. LineCurve.prototype.isLineCurve = true;
  22541. LineCurve.prototype.getPoint = function (t, optionalTarget) {
  22542. if (optionalTarget === void 0) {
  22543. optionalTarget = new Vector2();
  22544. }
  22545. var point = optionalTarget;
  22546. if (t === 1) {
  22547. point.copy(this.v2);
  22548. } else {
  22549. point.copy(this.v2).sub(this.v1);
  22550. point.multiplyScalar(t).add(this.v1);
  22551. }
  22552. return point;
  22553. }; // Line curve is linear, so we can overwrite default getPointAt
  22554. LineCurve.prototype.getPointAt = function (u, optionalTarget) {
  22555. return this.getPoint(u, optionalTarget);
  22556. };
  22557. LineCurve.prototype.getTangent = function (t, optionalTarget) {
  22558. var tangent = optionalTarget || new Vector2();
  22559. tangent.copy(this.v2).sub(this.v1).normalize();
  22560. return tangent;
  22561. };
  22562. LineCurve.prototype.copy = function (source) {
  22563. Curve.prototype.copy.call(this, source);
  22564. this.v1.copy(source.v1);
  22565. this.v2.copy(source.v2);
  22566. return this;
  22567. };
  22568. LineCurve.prototype.toJSON = function () {
  22569. var data = Curve.prototype.toJSON.call(this);
  22570. data.v1 = this.v1.toArray();
  22571. data.v2 = this.v2.toArray();
  22572. return data;
  22573. };
  22574. LineCurve.prototype.fromJSON = function (json) {
  22575. Curve.prototype.fromJSON.call(this, json);
  22576. this.v1.fromArray(json.v1);
  22577. this.v2.fromArray(json.v2);
  22578. return this;
  22579. };
  22580. function LineCurve3(v1, v2) {
  22581. if (v1 === void 0) {
  22582. v1 = new Vector3();
  22583. }
  22584. if (v2 === void 0) {
  22585. v2 = new Vector3();
  22586. }
  22587. Curve.call(this);
  22588. this.type = 'LineCurve3';
  22589. this.v1 = v1;
  22590. this.v2 = v2;
  22591. }
  22592. LineCurve3.prototype = Object.create(Curve.prototype);
  22593. LineCurve3.prototype.constructor = LineCurve3;
  22594. LineCurve3.prototype.isLineCurve3 = true;
  22595. LineCurve3.prototype.getPoint = function (t, optionalTarget) {
  22596. if (optionalTarget === void 0) {
  22597. optionalTarget = new Vector3();
  22598. }
  22599. var point = optionalTarget;
  22600. if (t === 1) {
  22601. point.copy(this.v2);
  22602. } else {
  22603. point.copy(this.v2).sub(this.v1);
  22604. point.multiplyScalar(t).add(this.v1);
  22605. }
  22606. return point;
  22607. }; // Line curve is linear, so we can overwrite default getPointAt
  22608. LineCurve3.prototype.getPointAt = function (u, optionalTarget) {
  22609. return this.getPoint(u, optionalTarget);
  22610. };
  22611. LineCurve3.prototype.copy = function (source) {
  22612. Curve.prototype.copy.call(this, source);
  22613. this.v1.copy(source.v1);
  22614. this.v2.copy(source.v2);
  22615. return this;
  22616. };
  22617. LineCurve3.prototype.toJSON = function () {
  22618. var data = Curve.prototype.toJSON.call(this);
  22619. data.v1 = this.v1.toArray();
  22620. data.v2 = this.v2.toArray();
  22621. return data;
  22622. };
  22623. LineCurve3.prototype.fromJSON = function (json) {
  22624. Curve.prototype.fromJSON.call(this, json);
  22625. this.v1.fromArray(json.v1);
  22626. this.v2.fromArray(json.v2);
  22627. return this;
  22628. };
  22629. function QuadraticBezierCurve(v0, v1, v2) {
  22630. if (v0 === void 0) {
  22631. v0 = new Vector2();
  22632. }
  22633. if (v1 === void 0) {
  22634. v1 = new Vector2();
  22635. }
  22636. if (v2 === void 0) {
  22637. v2 = new Vector2();
  22638. }
  22639. Curve.call(this);
  22640. this.type = 'QuadraticBezierCurve';
  22641. this.v0 = v0;
  22642. this.v1 = v1;
  22643. this.v2 = v2;
  22644. }
  22645. QuadraticBezierCurve.prototype = Object.create(Curve.prototype);
  22646. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22647. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22648. QuadraticBezierCurve.prototype.getPoint = function (t, optionalTarget) {
  22649. if (optionalTarget === void 0) {
  22650. optionalTarget = new Vector2();
  22651. }
  22652. var point = optionalTarget;
  22653. var v0 = this.v0,
  22654. v1 = this.v1,
  22655. v2 = this.v2;
  22656. point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y));
  22657. return point;
  22658. };
  22659. QuadraticBezierCurve.prototype.copy = function (source) {
  22660. Curve.prototype.copy.call(this, source);
  22661. this.v0.copy(source.v0);
  22662. this.v1.copy(source.v1);
  22663. this.v2.copy(source.v2);
  22664. return this;
  22665. };
  22666. QuadraticBezierCurve.prototype.toJSON = function () {
  22667. var data = Curve.prototype.toJSON.call(this);
  22668. data.v0 = this.v0.toArray();
  22669. data.v1 = this.v1.toArray();
  22670. data.v2 = this.v2.toArray();
  22671. return data;
  22672. };
  22673. QuadraticBezierCurve.prototype.fromJSON = function (json) {
  22674. Curve.prototype.fromJSON.call(this, json);
  22675. this.v0.fromArray(json.v0);
  22676. this.v1.fromArray(json.v1);
  22677. this.v2.fromArray(json.v2);
  22678. return this;
  22679. };
  22680. function QuadraticBezierCurve3(v0, v1, v2) {
  22681. if (v0 === void 0) {
  22682. v0 = new Vector3();
  22683. }
  22684. if (v1 === void 0) {
  22685. v1 = new Vector3();
  22686. }
  22687. if (v2 === void 0) {
  22688. v2 = new Vector3();
  22689. }
  22690. Curve.call(this);
  22691. this.type = 'QuadraticBezierCurve3';
  22692. this.v0 = v0;
  22693. this.v1 = v1;
  22694. this.v2 = v2;
  22695. }
  22696. QuadraticBezierCurve3.prototype = Object.create(Curve.prototype);
  22697. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22698. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22699. QuadraticBezierCurve3.prototype.getPoint = function (t, optionalTarget) {
  22700. if (optionalTarget === void 0) {
  22701. optionalTarget = new Vector3();
  22702. }
  22703. var point = optionalTarget;
  22704. var v0 = this.v0,
  22705. v1 = this.v1,
  22706. v2 = this.v2;
  22707. 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));
  22708. return point;
  22709. };
  22710. QuadraticBezierCurve3.prototype.copy = function (source) {
  22711. Curve.prototype.copy.call(this, source);
  22712. this.v0.copy(source.v0);
  22713. this.v1.copy(source.v1);
  22714. this.v2.copy(source.v2);
  22715. return this;
  22716. };
  22717. QuadraticBezierCurve3.prototype.toJSON = function () {
  22718. var data = Curve.prototype.toJSON.call(this);
  22719. data.v0 = this.v0.toArray();
  22720. data.v1 = this.v1.toArray();
  22721. data.v2 = this.v2.toArray();
  22722. return data;
  22723. };
  22724. QuadraticBezierCurve3.prototype.fromJSON = function (json) {
  22725. Curve.prototype.fromJSON.call(this, json);
  22726. this.v0.fromArray(json.v0);
  22727. this.v1.fromArray(json.v1);
  22728. this.v2.fromArray(json.v2);
  22729. return this;
  22730. };
  22731. function SplineCurve(points) {
  22732. if (points === void 0) {
  22733. points = [];
  22734. }
  22735. Curve.call(this);
  22736. this.type = 'SplineCurve';
  22737. this.points = points;
  22738. }
  22739. SplineCurve.prototype = Object.create(Curve.prototype);
  22740. SplineCurve.prototype.constructor = SplineCurve;
  22741. SplineCurve.prototype.isSplineCurve = true;
  22742. SplineCurve.prototype.getPoint = function (t, optionalTarget) {
  22743. if (optionalTarget === void 0) {
  22744. optionalTarget = new Vector2();
  22745. }
  22746. var point = optionalTarget;
  22747. var points = this.points;
  22748. var p = (points.length - 1) * t;
  22749. var intPoint = Math.floor(p);
  22750. var weight = p - intPoint;
  22751. var p0 = points[intPoint === 0 ? intPoint : intPoint - 1];
  22752. var p1 = points[intPoint];
  22753. var p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1];
  22754. var p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2];
  22755. point.set(CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y));
  22756. return point;
  22757. };
  22758. SplineCurve.prototype.copy = function (source) {
  22759. Curve.prototype.copy.call(this, source);
  22760. this.points = [];
  22761. for (var i = 0, l = source.points.length; i < l; i++) {
  22762. var point = source.points[i];
  22763. this.points.push(point.clone());
  22764. }
  22765. return this;
  22766. };
  22767. SplineCurve.prototype.toJSON = function () {
  22768. var data = Curve.prototype.toJSON.call(this);
  22769. data.points = [];
  22770. for (var i = 0, l = this.points.length; i < l; i++) {
  22771. var point = this.points[i];
  22772. data.points.push(point.toArray());
  22773. }
  22774. return data;
  22775. };
  22776. SplineCurve.prototype.fromJSON = function (json) {
  22777. Curve.prototype.fromJSON.call(this, json);
  22778. this.points = [];
  22779. for (var i = 0, l = json.points.length; i < l; i++) {
  22780. var point = json.points[i];
  22781. this.points.push(new Vector2().fromArray(point));
  22782. }
  22783. return this;
  22784. };
  22785. var Curves = /*#__PURE__*/Object.freeze({
  22786. __proto__: null,
  22787. ArcCurve: ArcCurve,
  22788. CatmullRomCurve3: CatmullRomCurve3,
  22789. CubicBezierCurve: CubicBezierCurve,
  22790. CubicBezierCurve3: CubicBezierCurve3,
  22791. EllipseCurve: EllipseCurve,
  22792. LineCurve: LineCurve,
  22793. LineCurve3: LineCurve3,
  22794. QuadraticBezierCurve: QuadraticBezierCurve,
  22795. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22796. SplineCurve: SplineCurve
  22797. });
  22798. /**************************************************************
  22799. * Curved Path - a curve path is simply a array of connected
  22800. * curves, but retains the api of a curve
  22801. **************************************************************/
  22802. function CurvePath() {
  22803. Curve.call(this);
  22804. this.type = 'CurvePath';
  22805. this.curves = [];
  22806. this.autoClose = false; // Automatically closes the path
  22807. }
  22808. CurvePath.prototype = Object.assign(Object.create(Curve.prototype), {
  22809. constructor: CurvePath,
  22810. add: function add(curve) {
  22811. this.curves.push(curve);
  22812. },
  22813. closePath: function closePath() {
  22814. // Add a line curve if start and end of lines are not connected
  22815. var startPoint = this.curves[0].getPoint(0);
  22816. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  22817. if (!startPoint.equals(endPoint)) {
  22818. this.curves.push(new LineCurve(endPoint, startPoint));
  22819. }
  22820. },
  22821. // To get accurate point with reference to
  22822. // entire path distance at time t,
  22823. // following has to be done:
  22824. // 1. Length of each sub path have to be known
  22825. // 2. Locate and identify type of curve
  22826. // 3. Get t for the curve
  22827. // 4. Return curve.getPointAt(t')
  22828. getPoint: function getPoint(t) {
  22829. var d = t * this.getLength();
  22830. var curveLengths = this.getCurveLengths();
  22831. var i = 0; // To think about boundaries points.
  22832. while (i < curveLengths.length) {
  22833. if (curveLengths[i] >= d) {
  22834. var diff = curveLengths[i] - d;
  22835. var curve = this.curves[i];
  22836. var segmentLength = curve.getLength();
  22837. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22838. return curve.getPointAt(u);
  22839. }
  22840. i++;
  22841. }
  22842. return null; // loop where sum != 0, sum > d , sum+1 <d
  22843. },
  22844. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22845. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22846. // getPoint() depends on getLength
  22847. getLength: function getLength() {
  22848. var lens = this.getCurveLengths();
  22849. return lens[lens.length - 1];
  22850. },
  22851. // cacheLengths must be recalculated.
  22852. updateArcLengths: function updateArcLengths() {
  22853. this.needsUpdate = true;
  22854. this.cacheLengths = null;
  22855. this.getCurveLengths();
  22856. },
  22857. // Compute lengths and cache them
  22858. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22859. getCurveLengths: function getCurveLengths() {
  22860. // We use cache values if curves and cache array are same length
  22861. if (this.cacheLengths && this.cacheLengths.length === this.curves.length) {
  22862. return this.cacheLengths;
  22863. } // Get length of sub-curve
  22864. // Push sums into cached array
  22865. var lengths = [];
  22866. var sums = 0;
  22867. for (var i = 0, l = this.curves.length; i < l; i++) {
  22868. sums += this.curves[i].getLength();
  22869. lengths.push(sums);
  22870. }
  22871. this.cacheLengths = lengths;
  22872. return lengths;
  22873. },
  22874. getSpacedPoints: function getSpacedPoints(divisions) {
  22875. if (divisions === void 0) {
  22876. divisions = 40;
  22877. }
  22878. var points = [];
  22879. for (var i = 0; i <= divisions; i++) {
  22880. points.push(this.getPoint(i / divisions));
  22881. }
  22882. if (this.autoClose) {
  22883. points.push(points[0]);
  22884. }
  22885. return points;
  22886. },
  22887. getPoints: function getPoints(divisions) {
  22888. if (divisions === void 0) {
  22889. divisions = 12;
  22890. }
  22891. var points = [];
  22892. var last;
  22893. for (var i = 0, curves = this.curves; i < curves.length; i++) {
  22894. var curve = curves[i];
  22895. var resolution = curve && curve.isEllipseCurve ? divisions * 2 : curve && (curve.isLineCurve || curve.isLineCurve3) ? 1 : curve && curve.isSplineCurve ? divisions * curve.points.length : divisions;
  22896. var pts = curve.getPoints(resolution);
  22897. for (var j = 0; j < pts.length; j++) {
  22898. var point = pts[j];
  22899. if (last && last.equals(point)) continue; // ensures no consecutive points are duplicates
  22900. points.push(point);
  22901. last = point;
  22902. }
  22903. }
  22904. if (this.autoClose && points.length > 1 && !points[points.length - 1].equals(points[0])) {
  22905. points.push(points[0]);
  22906. }
  22907. return points;
  22908. },
  22909. copy: function copy(source) {
  22910. Curve.prototype.copy.call(this, source);
  22911. this.curves = [];
  22912. for (var i = 0, l = source.curves.length; i < l; i++) {
  22913. var curve = source.curves[i];
  22914. this.curves.push(curve.clone());
  22915. }
  22916. this.autoClose = source.autoClose;
  22917. return this;
  22918. },
  22919. toJSON: function toJSON() {
  22920. var data = Curve.prototype.toJSON.call(this);
  22921. data.autoClose = this.autoClose;
  22922. data.curves = [];
  22923. for (var i = 0, l = this.curves.length; i < l; i++) {
  22924. var curve = this.curves[i];
  22925. data.curves.push(curve.toJSON());
  22926. }
  22927. return data;
  22928. },
  22929. fromJSON: function fromJSON(json) {
  22930. Curve.prototype.fromJSON.call(this, json);
  22931. this.autoClose = json.autoClose;
  22932. this.curves = [];
  22933. for (var i = 0, l = json.curves.length; i < l; i++) {
  22934. var curve = json.curves[i];
  22935. this.curves.push(new Curves[curve.type]().fromJSON(curve));
  22936. }
  22937. return this;
  22938. }
  22939. });
  22940. function Path(points) {
  22941. CurvePath.call(this);
  22942. this.type = 'Path';
  22943. this.currentPoint = new Vector2();
  22944. if (points) {
  22945. this.setFromPoints(points);
  22946. }
  22947. }
  22948. Path.prototype = Object.assign(Object.create(CurvePath.prototype), {
  22949. constructor: Path,
  22950. setFromPoints: function setFromPoints(points) {
  22951. this.moveTo(points[0].x, points[0].y);
  22952. for (var i = 1, l = points.length; i < l; i++) {
  22953. this.lineTo(points[i].x, points[i].y);
  22954. }
  22955. return this;
  22956. },
  22957. moveTo: function moveTo(x, y) {
  22958. this.currentPoint.set(x, y); // TODO consider referencing vectors instead of copying?
  22959. return this;
  22960. },
  22961. lineTo: function lineTo(x, y) {
  22962. var curve = new LineCurve(this.currentPoint.clone(), new Vector2(x, y));
  22963. this.curves.push(curve);
  22964. this.currentPoint.set(x, y);
  22965. return this;
  22966. },
  22967. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  22968. var curve = new QuadraticBezierCurve(this.currentPoint.clone(), new Vector2(aCPx, aCPy), new Vector2(aX, aY));
  22969. this.curves.push(curve);
  22970. this.currentPoint.set(aX, aY);
  22971. return this;
  22972. },
  22973. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  22974. var curve = new CubicBezierCurve(this.currentPoint.clone(), new Vector2(aCP1x, aCP1y), new Vector2(aCP2x, aCP2y), new Vector2(aX, aY));
  22975. this.curves.push(curve);
  22976. this.currentPoint.set(aX, aY);
  22977. return this;
  22978. },
  22979. splineThru: function splineThru(pts
  22980. /*Array of Vector*/
  22981. ) {
  22982. var npts = [this.currentPoint.clone()].concat(pts);
  22983. var curve = new SplineCurve(npts);
  22984. this.curves.push(curve);
  22985. this.currentPoint.copy(pts[pts.length - 1]);
  22986. return this;
  22987. },
  22988. arc: function arc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22989. var x0 = this.currentPoint.x;
  22990. var y0 = this.currentPoint.y;
  22991. this.absarc(aX + x0, aY + y0, aRadius, aStartAngle, aEndAngle, aClockwise);
  22992. return this;
  22993. },
  22994. absarc: function absarc(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) {
  22995. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  22996. return this;
  22997. },
  22998. ellipse: function ellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  22999. var x0 = this.currentPoint.x;
  23000. var y0 = this.currentPoint.y;
  23001. this.absellipse(aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23002. return this;
  23003. },
  23004. absellipse: function absellipse(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation) {
  23005. var curve = new EllipseCurve(aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation);
  23006. if (this.curves.length > 0) {
  23007. // if a previous curve is present, attempt to join
  23008. var firstPoint = curve.getPoint(0);
  23009. if (!firstPoint.equals(this.currentPoint)) {
  23010. this.lineTo(firstPoint.x, firstPoint.y);
  23011. }
  23012. }
  23013. this.curves.push(curve);
  23014. var lastPoint = curve.getPoint(1);
  23015. this.currentPoint.copy(lastPoint);
  23016. return this;
  23017. },
  23018. copy: function copy(source) {
  23019. CurvePath.prototype.copy.call(this, source);
  23020. this.currentPoint.copy(source.currentPoint);
  23021. return this;
  23022. },
  23023. toJSON: function toJSON() {
  23024. var data = CurvePath.prototype.toJSON.call(this);
  23025. data.currentPoint = this.currentPoint.toArray();
  23026. return data;
  23027. },
  23028. fromJSON: function fromJSON(json) {
  23029. CurvePath.prototype.fromJSON.call(this, json);
  23030. this.currentPoint.fromArray(json.currentPoint);
  23031. return this;
  23032. }
  23033. });
  23034. function Shape(points) {
  23035. Path.call(this, points);
  23036. this.uuid = MathUtils.generateUUID();
  23037. this.type = 'Shape';
  23038. this.holes = [];
  23039. }
  23040. Shape.prototype = Object.assign(Object.create(Path.prototype), {
  23041. constructor: Shape,
  23042. getPointsHoles: function getPointsHoles(divisions) {
  23043. var holesPts = [];
  23044. for (var i = 0, l = this.holes.length; i < l; i++) {
  23045. holesPts[i] = this.holes[i].getPoints(divisions);
  23046. }
  23047. return holesPts;
  23048. },
  23049. // get points of shape and holes (keypoints based on segments parameter)
  23050. extractPoints: function extractPoints(divisions) {
  23051. return {
  23052. shape: this.getPoints(divisions),
  23053. holes: this.getPointsHoles(divisions)
  23054. };
  23055. },
  23056. copy: function copy(source) {
  23057. Path.prototype.copy.call(this, source);
  23058. this.holes = [];
  23059. for (var i = 0, l = source.holes.length; i < l; i++) {
  23060. var hole = source.holes[i];
  23061. this.holes.push(hole.clone());
  23062. }
  23063. return this;
  23064. },
  23065. toJSON: function toJSON() {
  23066. var data = Path.prototype.toJSON.call(this);
  23067. data.uuid = this.uuid;
  23068. data.holes = [];
  23069. for (var i = 0, l = this.holes.length; i < l; i++) {
  23070. var hole = this.holes[i];
  23071. data.holes.push(hole.toJSON());
  23072. }
  23073. return data;
  23074. },
  23075. fromJSON: function fromJSON(json) {
  23076. Path.prototype.fromJSON.call(this, json);
  23077. this.uuid = json.uuid;
  23078. this.holes = [];
  23079. for (var i = 0, l = json.holes.length; i < l; i++) {
  23080. var hole = json.holes[i];
  23081. this.holes.push(new Path().fromJSON(hole));
  23082. }
  23083. return this;
  23084. }
  23085. });
  23086. function Light(color, intensity) {
  23087. if (intensity === void 0) {
  23088. intensity = 1;
  23089. }
  23090. Object3D.call(this);
  23091. this.type = 'Light';
  23092. this.color = new Color(color);
  23093. this.intensity = intensity;
  23094. }
  23095. Light.prototype = Object.assign(Object.create(Object3D.prototype), {
  23096. constructor: Light,
  23097. isLight: true,
  23098. copy: function copy(source) {
  23099. Object3D.prototype.copy.call(this, source);
  23100. this.color.copy(source.color);
  23101. this.intensity = source.intensity;
  23102. return this;
  23103. },
  23104. toJSON: function toJSON(meta) {
  23105. var data = Object3D.prototype.toJSON.call(this, meta);
  23106. data.object.color = this.color.getHex();
  23107. data.object.intensity = this.intensity;
  23108. if (this.groundColor !== undefined) data.object.groundColor = this.groundColor.getHex();
  23109. if (this.distance !== undefined) data.object.distance = this.distance;
  23110. if (this.angle !== undefined) data.object.angle = this.angle;
  23111. if (this.decay !== undefined) data.object.decay = this.decay;
  23112. if (this.penumbra !== undefined) data.object.penumbra = this.penumbra;
  23113. if (this.shadow !== undefined) data.object.shadow = this.shadow.toJSON();
  23114. return data;
  23115. }
  23116. });
  23117. function HemisphereLight(skyColor, groundColor, intensity) {
  23118. Light.call(this, skyColor, intensity);
  23119. this.type = 'HemisphereLight';
  23120. this.position.copy(Object3D.DefaultUp);
  23121. this.updateMatrix();
  23122. this.groundColor = new Color(groundColor);
  23123. }
  23124. HemisphereLight.prototype = Object.assign(Object.create(Light.prototype), {
  23125. constructor: HemisphereLight,
  23126. isHemisphereLight: true,
  23127. copy: function copy(source) {
  23128. Light.prototype.copy.call(this, source);
  23129. this.groundColor.copy(source.groundColor);
  23130. return this;
  23131. }
  23132. });
  23133. function LightShadow(camera) {
  23134. this.camera = camera;
  23135. this.bias = 0;
  23136. this.normalBias = 0;
  23137. this.radius = 1;
  23138. this.mapSize = new Vector2(512, 512);
  23139. this.map = null;
  23140. this.mapPass = null;
  23141. this.matrix = new Matrix4();
  23142. this.autoUpdate = true;
  23143. this.needsUpdate = false;
  23144. this._frustum = new Frustum();
  23145. this._frameExtents = new Vector2(1, 1);
  23146. this._viewportCount = 1;
  23147. this._viewports = [new Vector4(0, 0, 1, 1)];
  23148. }
  23149. Object.assign(LightShadow.prototype, {
  23150. _projScreenMatrix: new Matrix4(),
  23151. _lightPositionWorld: new Vector3(),
  23152. _lookTarget: new Vector3(),
  23153. getViewportCount: function getViewportCount() {
  23154. return this._viewportCount;
  23155. },
  23156. getFrustum: function getFrustum() {
  23157. return this._frustum;
  23158. },
  23159. updateMatrices: function updateMatrices(light) {
  23160. var shadowCamera = this.camera,
  23161. shadowMatrix = this.matrix,
  23162. projScreenMatrix = this._projScreenMatrix,
  23163. lookTarget = this._lookTarget,
  23164. lightPositionWorld = this._lightPositionWorld;
  23165. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23166. shadowCamera.position.copy(lightPositionWorld);
  23167. lookTarget.setFromMatrixPosition(light.target.matrixWorld);
  23168. shadowCamera.lookAt(lookTarget);
  23169. shadowCamera.updateMatrixWorld();
  23170. projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse);
  23171. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23172. 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);
  23173. shadowMatrix.multiply(shadowCamera.projectionMatrix);
  23174. shadowMatrix.multiply(shadowCamera.matrixWorldInverse);
  23175. },
  23176. getViewport: function getViewport(viewportIndex) {
  23177. return this._viewports[viewportIndex];
  23178. },
  23179. getFrameExtents: function getFrameExtents() {
  23180. return this._frameExtents;
  23181. },
  23182. copy: function copy(source) {
  23183. this.camera = source.camera.clone();
  23184. this.bias = source.bias;
  23185. this.radius = source.radius;
  23186. this.mapSize.copy(source.mapSize);
  23187. return this;
  23188. },
  23189. clone: function clone() {
  23190. return new this.constructor().copy(this);
  23191. },
  23192. toJSON: function toJSON() {
  23193. var object = {};
  23194. if (this.bias !== 0) object.bias = this.bias;
  23195. if (this.normalBias !== 0) object.normalBias = this.normalBias;
  23196. if (this.radius !== 1) object.radius = this.radius;
  23197. if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray();
  23198. object.camera = this.camera.toJSON(false).object;
  23199. delete object.camera.matrix;
  23200. return object;
  23201. }
  23202. });
  23203. function SpotLightShadow() {
  23204. LightShadow.call(this, new PerspectiveCamera(50, 1, 0.5, 500));
  23205. this.focus = 1;
  23206. }
  23207. SpotLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23208. constructor: SpotLightShadow,
  23209. isSpotLightShadow: true,
  23210. updateMatrices: function updateMatrices(light) {
  23211. var camera = this.camera;
  23212. var fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23213. var aspect = this.mapSize.width / this.mapSize.height;
  23214. var far = light.distance || camera.far;
  23215. if (fov !== camera.fov || aspect !== camera.aspect || far !== camera.far) {
  23216. camera.fov = fov;
  23217. camera.aspect = aspect;
  23218. camera.far = far;
  23219. camera.updateProjectionMatrix();
  23220. }
  23221. LightShadow.prototype.updateMatrices.call(this, light);
  23222. }
  23223. });
  23224. function SpotLight(color, intensity, distance, angle, penumbra, decay) {
  23225. Light.call(this, color, intensity);
  23226. this.type = 'SpotLight';
  23227. this.position.copy(Object3D.DefaultUp);
  23228. this.updateMatrix();
  23229. this.target = new Object3D();
  23230. Object.defineProperty(this, 'power', {
  23231. get: function get() {
  23232. // intensity = power per solid angle.
  23233. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23234. return this.intensity * Math.PI;
  23235. },
  23236. set: function set(power) {
  23237. // intensity = power per solid angle.
  23238. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23239. this.intensity = power / Math.PI;
  23240. }
  23241. });
  23242. this.distance = distance !== undefined ? distance : 0;
  23243. this.angle = angle !== undefined ? angle : Math.PI / 3;
  23244. this.penumbra = penumbra !== undefined ? penumbra : 0;
  23245. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23246. this.shadow = new SpotLightShadow();
  23247. }
  23248. SpotLight.prototype = Object.assign(Object.create(Light.prototype), {
  23249. constructor: SpotLight,
  23250. isSpotLight: true,
  23251. copy: function copy(source) {
  23252. Light.prototype.copy.call(this, source);
  23253. this.distance = source.distance;
  23254. this.angle = source.angle;
  23255. this.penumbra = source.penumbra;
  23256. this.decay = source.decay;
  23257. this.target = source.target.clone();
  23258. this.shadow = source.shadow.clone();
  23259. return this;
  23260. }
  23261. });
  23262. function PointLightShadow() {
  23263. LightShadow.call(this, new PerspectiveCamera(90, 1, 0.5, 500));
  23264. this._frameExtents = new Vector2(4, 2);
  23265. this._viewportCount = 6;
  23266. this._viewports = [// These viewports map a cube-map onto a 2D texture with the
  23267. // following orientation:
  23268. //
  23269. // xzXZ
  23270. // y Y
  23271. //
  23272. // X - Positive x direction
  23273. // x - Negative x direction
  23274. // Y - Positive y direction
  23275. // y - Negative y direction
  23276. // Z - Positive z direction
  23277. // z - Negative z direction
  23278. // positive X
  23279. new Vector4(2, 1, 1, 1), // negative X
  23280. new Vector4(0, 1, 1, 1), // positive Z
  23281. new Vector4(3, 1, 1, 1), // negative Z
  23282. new Vector4(1, 1, 1, 1), // positive Y
  23283. new Vector4(3, 0, 1, 1), // negative Y
  23284. new Vector4(1, 0, 1, 1)];
  23285. 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)];
  23286. 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)];
  23287. }
  23288. PointLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23289. constructor: PointLightShadow,
  23290. isPointLightShadow: true,
  23291. updateMatrices: function updateMatrices(light, viewportIndex) {
  23292. if (viewportIndex === void 0) {
  23293. viewportIndex = 0;
  23294. }
  23295. var camera = this.camera,
  23296. shadowMatrix = this.matrix,
  23297. lightPositionWorld = this._lightPositionWorld,
  23298. lookTarget = this._lookTarget,
  23299. projScreenMatrix = this._projScreenMatrix;
  23300. lightPositionWorld.setFromMatrixPosition(light.matrixWorld);
  23301. camera.position.copy(lightPositionWorld);
  23302. lookTarget.copy(camera.position);
  23303. lookTarget.add(this._cubeDirections[viewportIndex]);
  23304. camera.up.copy(this._cubeUps[viewportIndex]);
  23305. camera.lookAt(lookTarget);
  23306. camera.updateMatrixWorld();
  23307. shadowMatrix.makeTranslation(-lightPositionWorld.x, -lightPositionWorld.y, -lightPositionWorld.z);
  23308. projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  23309. this._frustum.setFromProjectionMatrix(projScreenMatrix);
  23310. }
  23311. });
  23312. function PointLight(color, intensity, distance, decay) {
  23313. Light.call(this, color, intensity);
  23314. this.type = 'PointLight';
  23315. Object.defineProperty(this, 'power', {
  23316. get: function get() {
  23317. // intensity = power per solid angle.
  23318. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23319. return this.intensity * 4 * Math.PI;
  23320. },
  23321. set: function set(power) {
  23322. // intensity = power per solid angle.
  23323. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23324. this.intensity = power / (4 * Math.PI);
  23325. }
  23326. });
  23327. this.distance = distance !== undefined ? distance : 0;
  23328. this.decay = decay !== undefined ? decay : 1; // for physically correct lights, should be 2.
  23329. this.shadow = new PointLightShadow();
  23330. }
  23331. PointLight.prototype = Object.assign(Object.create(Light.prototype), {
  23332. constructor: PointLight,
  23333. isPointLight: true,
  23334. copy: function copy(source) {
  23335. Light.prototype.copy.call(this, source);
  23336. this.distance = source.distance;
  23337. this.decay = source.decay;
  23338. this.shadow = source.shadow.clone();
  23339. return this;
  23340. }
  23341. });
  23342. function OrthographicCamera(left, right, top, bottom, near, far) {
  23343. if (left === void 0) {
  23344. left = -1;
  23345. }
  23346. if (right === void 0) {
  23347. right = 1;
  23348. }
  23349. if (top === void 0) {
  23350. top = 1;
  23351. }
  23352. if (bottom === void 0) {
  23353. bottom = -1;
  23354. }
  23355. if (near === void 0) {
  23356. near = 0.1;
  23357. }
  23358. if (far === void 0) {
  23359. far = 2000;
  23360. }
  23361. Camera.call(this);
  23362. this.type = 'OrthographicCamera';
  23363. this.zoom = 1;
  23364. this.view = null;
  23365. this.left = left;
  23366. this.right = right;
  23367. this.top = top;
  23368. this.bottom = bottom;
  23369. this.near = near;
  23370. this.far = far;
  23371. this.updateProjectionMatrix();
  23372. }
  23373. OrthographicCamera.prototype = Object.assign(Object.create(Camera.prototype), {
  23374. constructor: OrthographicCamera,
  23375. isOrthographicCamera: true,
  23376. copy: function copy(source, recursive) {
  23377. Camera.prototype.copy.call(this, source, recursive);
  23378. this.left = source.left;
  23379. this.right = source.right;
  23380. this.top = source.top;
  23381. this.bottom = source.bottom;
  23382. this.near = source.near;
  23383. this.far = source.far;
  23384. this.zoom = source.zoom;
  23385. this.view = source.view === null ? null : Object.assign({}, source.view);
  23386. return this;
  23387. },
  23388. setViewOffset: function setViewOffset(fullWidth, fullHeight, x, y, width, height) {
  23389. if (this.view === null) {
  23390. this.view = {
  23391. enabled: true,
  23392. fullWidth: 1,
  23393. fullHeight: 1,
  23394. offsetX: 0,
  23395. offsetY: 0,
  23396. width: 1,
  23397. height: 1
  23398. };
  23399. }
  23400. this.view.enabled = true;
  23401. this.view.fullWidth = fullWidth;
  23402. this.view.fullHeight = fullHeight;
  23403. this.view.offsetX = x;
  23404. this.view.offsetY = y;
  23405. this.view.width = width;
  23406. this.view.height = height;
  23407. this.updateProjectionMatrix();
  23408. },
  23409. clearViewOffset: function clearViewOffset() {
  23410. if (this.view !== null) {
  23411. this.view.enabled = false;
  23412. }
  23413. this.updateProjectionMatrix();
  23414. },
  23415. updateProjectionMatrix: function updateProjectionMatrix() {
  23416. var dx = (this.right - this.left) / (2 * this.zoom);
  23417. var dy = (this.top - this.bottom) / (2 * this.zoom);
  23418. var cx = (this.right + this.left) / 2;
  23419. var cy = (this.top + this.bottom) / 2;
  23420. var left = cx - dx;
  23421. var right = cx + dx;
  23422. var top = cy + dy;
  23423. var bottom = cy - dy;
  23424. if (this.view !== null && this.view.enabled) {
  23425. var scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom;
  23426. var scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom;
  23427. left += scaleW * this.view.offsetX;
  23428. right = left + scaleW * this.view.width;
  23429. top -= scaleH * this.view.offsetY;
  23430. bottom = top - scaleH * this.view.height;
  23431. }
  23432. this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far);
  23433. this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
  23434. },
  23435. toJSON: function toJSON(meta) {
  23436. var data = Object3D.prototype.toJSON.call(this, meta);
  23437. data.object.zoom = this.zoom;
  23438. data.object.left = this.left;
  23439. data.object.right = this.right;
  23440. data.object.top = this.top;
  23441. data.object.bottom = this.bottom;
  23442. data.object.near = this.near;
  23443. data.object.far = this.far;
  23444. if (this.view !== null) data.object.view = Object.assign({}, this.view);
  23445. return data;
  23446. }
  23447. });
  23448. function DirectionalLightShadow() {
  23449. LightShadow.call(this, new OrthographicCamera(-5, 5, 5, -5, 0.5, 500));
  23450. }
  23451. DirectionalLightShadow.prototype = Object.assign(Object.create(LightShadow.prototype), {
  23452. constructor: DirectionalLightShadow,
  23453. isDirectionalLightShadow: true,
  23454. updateMatrices: function updateMatrices(light) {
  23455. LightShadow.prototype.updateMatrices.call(this, light);
  23456. }
  23457. });
  23458. function DirectionalLight(color, intensity) {
  23459. Light.call(this, color, intensity);
  23460. this.type = 'DirectionalLight';
  23461. this.position.copy(Object3D.DefaultUp);
  23462. this.updateMatrix();
  23463. this.target = new Object3D();
  23464. this.shadow = new DirectionalLightShadow();
  23465. }
  23466. DirectionalLight.prototype = Object.assign(Object.create(Light.prototype), {
  23467. constructor: DirectionalLight,
  23468. isDirectionalLight: true,
  23469. copy: function copy(source) {
  23470. Light.prototype.copy.call(this, source);
  23471. this.target = source.target.clone();
  23472. this.shadow = source.shadow.clone();
  23473. return this;
  23474. }
  23475. });
  23476. function AmbientLight(color, intensity) {
  23477. Light.call(this, color, intensity);
  23478. this.type = 'AmbientLight';
  23479. }
  23480. AmbientLight.prototype = Object.assign(Object.create(Light.prototype), {
  23481. constructor: AmbientLight,
  23482. isAmbientLight: true
  23483. });
  23484. function RectAreaLight(color, intensity, width, height) {
  23485. Light.call(this, color, intensity);
  23486. this.type = 'RectAreaLight';
  23487. this.width = width !== undefined ? width : 10;
  23488. this.height = height !== undefined ? height : 10;
  23489. }
  23490. RectAreaLight.prototype = Object.assign(Object.create(Light.prototype), {
  23491. constructor: RectAreaLight,
  23492. isRectAreaLight: true,
  23493. copy: function copy(source) {
  23494. Light.prototype.copy.call(this, source);
  23495. this.width = source.width;
  23496. this.height = source.height;
  23497. return this;
  23498. },
  23499. toJSON: function toJSON(meta) {
  23500. var data = Light.prototype.toJSON.call(this, meta);
  23501. data.object.width = this.width;
  23502. data.object.height = this.height;
  23503. return data;
  23504. }
  23505. });
  23506. /**
  23507. * Primary reference:
  23508. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23509. *
  23510. * Secondary reference:
  23511. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23512. */
  23513. // 3-band SH defined by 9 coefficients
  23514. var SphericalHarmonics3 = /*#__PURE__*/function () {
  23515. function SphericalHarmonics3() {
  23516. Object.defineProperty(this, 'isSphericalHarmonics3', {
  23517. value: true
  23518. });
  23519. this.coefficients = [];
  23520. for (var i = 0; i < 9; i++) {
  23521. this.coefficients.push(new Vector3());
  23522. }
  23523. }
  23524. var _proto = SphericalHarmonics3.prototype;
  23525. _proto.set = function set(coefficients) {
  23526. for (var i = 0; i < 9; i++) {
  23527. this.coefficients[i].copy(coefficients[i]);
  23528. }
  23529. return this;
  23530. };
  23531. _proto.zero = function zero() {
  23532. for (var i = 0; i < 9; i++) {
  23533. this.coefficients[i].set(0, 0, 0);
  23534. }
  23535. return this;
  23536. } // get the radiance in the direction of the normal
  23537. // target is a Vector3
  23538. ;
  23539. _proto.getAt = function getAt(normal, target) {
  23540. // normal is assumed to be unit length
  23541. var x = normal.x,
  23542. y = normal.y,
  23543. z = normal.z;
  23544. var coeff = this.coefficients; // band 0
  23545. target.copy(coeff[0]).multiplyScalar(0.282095); // band 1
  23546. target.addScaledVector(coeff[1], 0.488603 * y);
  23547. target.addScaledVector(coeff[2], 0.488603 * z);
  23548. target.addScaledVector(coeff[3], 0.488603 * x); // band 2
  23549. target.addScaledVector(coeff[4], 1.092548 * (x * y));
  23550. target.addScaledVector(coeff[5], 1.092548 * (y * z));
  23551. target.addScaledVector(coeff[6], 0.315392 * (3.0 * z * z - 1.0));
  23552. target.addScaledVector(coeff[7], 1.092548 * (x * z));
  23553. target.addScaledVector(coeff[8], 0.546274 * (x * x - y * y));
  23554. return target;
  23555. } // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23556. // target is a Vector3
  23557. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23558. ;
  23559. _proto.getIrradianceAt = function getIrradianceAt(normal, target) {
  23560. // normal is assumed to be unit length
  23561. var x = normal.x,
  23562. y = normal.y,
  23563. z = normal.z;
  23564. var coeff = this.coefficients; // band 0
  23565. target.copy(coeff[0]).multiplyScalar(0.886227); // π * 0.282095
  23566. // band 1
  23567. target.addScaledVector(coeff[1], 2.0 * 0.511664 * y); // ( 2 * π / 3 ) * 0.488603
  23568. target.addScaledVector(coeff[2], 2.0 * 0.511664 * z);
  23569. target.addScaledVector(coeff[3], 2.0 * 0.511664 * x); // band 2
  23570. target.addScaledVector(coeff[4], 2.0 * 0.429043 * x * y); // ( π / 4 ) * 1.092548
  23571. target.addScaledVector(coeff[5], 2.0 * 0.429043 * y * z);
  23572. target.addScaledVector(coeff[6], 0.743125 * z * z - 0.247708); // ( π / 4 ) * 0.315392 * 3
  23573. target.addScaledVector(coeff[7], 2.0 * 0.429043 * x * z);
  23574. target.addScaledVector(coeff[8], 0.429043 * (x * x - y * y)); // ( π / 4 ) * 0.546274
  23575. return target;
  23576. };
  23577. _proto.add = function add(sh) {
  23578. for (var i = 0; i < 9; i++) {
  23579. this.coefficients[i].add(sh.coefficients[i]);
  23580. }
  23581. return this;
  23582. };
  23583. _proto.addScaledSH = function addScaledSH(sh, s) {
  23584. for (var i = 0; i < 9; i++) {
  23585. this.coefficients[i].addScaledVector(sh.coefficients[i], s);
  23586. }
  23587. return this;
  23588. };
  23589. _proto.scale = function scale(s) {
  23590. for (var i = 0; i < 9; i++) {
  23591. this.coefficients[i].multiplyScalar(s);
  23592. }
  23593. return this;
  23594. };
  23595. _proto.lerp = function lerp(sh, alpha) {
  23596. for (var i = 0; i < 9; i++) {
  23597. this.coefficients[i].lerp(sh.coefficients[i], alpha);
  23598. }
  23599. return this;
  23600. };
  23601. _proto.equals = function equals(sh) {
  23602. for (var i = 0; i < 9; i++) {
  23603. if (!this.coefficients[i].equals(sh.coefficients[i])) {
  23604. return false;
  23605. }
  23606. }
  23607. return true;
  23608. };
  23609. _proto.copy = function copy(sh) {
  23610. return this.set(sh.coefficients);
  23611. };
  23612. _proto.clone = function clone() {
  23613. return new this.constructor().copy(this);
  23614. };
  23615. _proto.fromArray = function fromArray(array, offset) {
  23616. if (offset === void 0) {
  23617. offset = 0;
  23618. }
  23619. var coefficients = this.coefficients;
  23620. for (var i = 0; i < 9; i++) {
  23621. coefficients[i].fromArray(array, offset + i * 3);
  23622. }
  23623. return this;
  23624. };
  23625. _proto.toArray = function toArray(array, offset) {
  23626. if (array === void 0) {
  23627. array = [];
  23628. }
  23629. if (offset === void 0) {
  23630. offset = 0;
  23631. }
  23632. var coefficients = this.coefficients;
  23633. for (var i = 0; i < 9; i++) {
  23634. coefficients[i].toArray(array, offset + i * 3);
  23635. }
  23636. return array;
  23637. } // evaluate the basis functions
  23638. // shBasis is an Array[ 9 ]
  23639. ;
  23640. SphericalHarmonics3.getBasisAt = function getBasisAt(normal, shBasis) {
  23641. // normal is assumed to be unit length
  23642. var x = normal.x,
  23643. y = normal.y,
  23644. z = normal.z; // band 0
  23645. shBasis[0] = 0.282095; // band 1
  23646. shBasis[1] = 0.488603 * y;
  23647. shBasis[2] = 0.488603 * z;
  23648. shBasis[3] = 0.488603 * x; // band 2
  23649. shBasis[4] = 1.092548 * x * y;
  23650. shBasis[5] = 1.092548 * y * z;
  23651. shBasis[6] = 0.315392 * (3 * z * z - 1);
  23652. shBasis[7] = 1.092548 * x * z;
  23653. shBasis[8] = 0.546274 * (x * x - y * y);
  23654. };
  23655. return SphericalHarmonics3;
  23656. }();
  23657. function LightProbe(sh, intensity) {
  23658. Light.call(this, undefined, intensity);
  23659. this.type = 'LightProbe';
  23660. this.sh = sh !== undefined ? sh : new SphericalHarmonics3();
  23661. }
  23662. LightProbe.prototype = Object.assign(Object.create(Light.prototype), {
  23663. constructor: LightProbe,
  23664. isLightProbe: true,
  23665. copy: function copy(source) {
  23666. Light.prototype.copy.call(this, source);
  23667. this.sh.copy(source.sh);
  23668. return this;
  23669. },
  23670. fromJSON: function fromJSON(json) {
  23671. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23672. this.sh.fromArray(json.sh);
  23673. return this;
  23674. },
  23675. toJSON: function toJSON(meta) {
  23676. var data = Light.prototype.toJSON.call(this, meta);
  23677. data.object.sh = this.sh.toArray();
  23678. return data;
  23679. }
  23680. });
  23681. function MaterialLoader(manager) {
  23682. Loader.call(this, manager);
  23683. this.textures = {};
  23684. }
  23685. MaterialLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23686. constructor: MaterialLoader,
  23687. load: function load(url, onLoad, onProgress, onError) {
  23688. var scope = this;
  23689. var loader = new FileLoader(scope.manager);
  23690. loader.setPath(scope.path);
  23691. loader.setRequestHeader(scope.requestHeader);
  23692. loader.setWithCredentials(scope.withCredentials);
  23693. loader.load(url, function (text) {
  23694. try {
  23695. onLoad(scope.parse(JSON.parse(text)));
  23696. } catch (e) {
  23697. if (onError) {
  23698. onError(e);
  23699. } else {
  23700. console.error(e);
  23701. }
  23702. scope.manager.itemError(url);
  23703. }
  23704. }, onProgress, onError);
  23705. },
  23706. parse: function parse(json) {
  23707. var textures = this.textures;
  23708. function getTexture(name) {
  23709. if (textures[name] === undefined) {
  23710. console.warn('THREE.MaterialLoader: Undefined texture', name);
  23711. }
  23712. return textures[name];
  23713. }
  23714. var material = new Materials[json.type]();
  23715. if (json.uuid !== undefined) material.uuid = json.uuid;
  23716. if (json.name !== undefined) material.name = json.name;
  23717. if (json.color !== undefined && material.color !== undefined) material.color.setHex(json.color);
  23718. if (json.roughness !== undefined) material.roughness = json.roughness;
  23719. if (json.metalness !== undefined) material.metalness = json.metalness;
  23720. if (json.sheen !== undefined) material.sheen = new Color().setHex(json.sheen);
  23721. if (json.emissive !== undefined && material.emissive !== undefined) material.emissive.setHex(json.emissive);
  23722. if (json.specular !== undefined && material.specular !== undefined) material.specular.setHex(json.specular);
  23723. if (json.shininess !== undefined) material.shininess = json.shininess;
  23724. if (json.clearcoat !== undefined) material.clearcoat = json.clearcoat;
  23725. if (json.clearcoatRoughness !== undefined) material.clearcoatRoughness = json.clearcoatRoughness;
  23726. if (json.fog !== undefined) material.fog = json.fog;
  23727. if (json.flatShading !== undefined) material.flatShading = json.flatShading;
  23728. if (json.blending !== undefined) material.blending = json.blending;
  23729. if (json.combine !== undefined) material.combine = json.combine;
  23730. if (json.side !== undefined) material.side = json.side;
  23731. if (json.opacity !== undefined) material.opacity = json.opacity;
  23732. if (json.transparent !== undefined) material.transparent = json.transparent;
  23733. if (json.alphaTest !== undefined) material.alphaTest = json.alphaTest;
  23734. if (json.depthTest !== undefined) material.depthTest = json.depthTest;
  23735. if (json.depthWrite !== undefined) material.depthWrite = json.depthWrite;
  23736. if (json.colorWrite !== undefined) material.colorWrite = json.colorWrite;
  23737. if (json.stencilWrite !== undefined) material.stencilWrite = json.stencilWrite;
  23738. if (json.stencilWriteMask !== undefined) material.stencilWriteMask = json.stencilWriteMask;
  23739. if (json.stencilFunc !== undefined) material.stencilFunc = json.stencilFunc;
  23740. if (json.stencilRef !== undefined) material.stencilRef = json.stencilRef;
  23741. if (json.stencilFuncMask !== undefined) material.stencilFuncMask = json.stencilFuncMask;
  23742. if (json.stencilFail !== undefined) material.stencilFail = json.stencilFail;
  23743. if (json.stencilZFail !== undefined) material.stencilZFail = json.stencilZFail;
  23744. if (json.stencilZPass !== undefined) material.stencilZPass = json.stencilZPass;
  23745. if (json.wireframe !== undefined) material.wireframe = json.wireframe;
  23746. if (json.wireframeLinewidth !== undefined) material.wireframeLinewidth = json.wireframeLinewidth;
  23747. if (json.wireframeLinecap !== undefined) material.wireframeLinecap = json.wireframeLinecap;
  23748. if (json.wireframeLinejoin !== undefined) material.wireframeLinejoin = json.wireframeLinejoin;
  23749. if (json.rotation !== undefined) material.rotation = json.rotation;
  23750. if (json.linewidth !== 1) material.linewidth = json.linewidth;
  23751. if (json.dashSize !== undefined) material.dashSize = json.dashSize;
  23752. if (json.gapSize !== undefined) material.gapSize = json.gapSize;
  23753. if (json.scale !== undefined) material.scale = json.scale;
  23754. if (json.polygonOffset !== undefined) material.polygonOffset = json.polygonOffset;
  23755. if (json.polygonOffsetFactor !== undefined) material.polygonOffsetFactor = json.polygonOffsetFactor;
  23756. if (json.polygonOffsetUnits !== undefined) material.polygonOffsetUnits = json.polygonOffsetUnits;
  23757. if (json.skinning !== undefined) material.skinning = json.skinning;
  23758. if (json.morphTargets !== undefined) material.morphTargets = json.morphTargets;
  23759. if (json.morphNormals !== undefined) material.morphNormals = json.morphNormals;
  23760. if (json.dithering !== undefined) material.dithering = json.dithering;
  23761. if (json.vertexTangents !== undefined) material.vertexTangents = json.vertexTangents;
  23762. if (json.visible !== undefined) material.visible = json.visible;
  23763. if (json.toneMapped !== undefined) material.toneMapped = json.toneMapped;
  23764. if (json.userData !== undefined) material.userData = json.userData;
  23765. if (json.vertexColors !== undefined) {
  23766. if (typeof json.vertexColors === 'number') {
  23767. material.vertexColors = json.vertexColors > 0 ? true : false;
  23768. } else {
  23769. material.vertexColors = json.vertexColors;
  23770. }
  23771. } // Shader Material
  23772. if (json.uniforms !== undefined) {
  23773. for (var name in json.uniforms) {
  23774. var uniform = json.uniforms[name];
  23775. material.uniforms[name] = {};
  23776. switch (uniform.type) {
  23777. case 't':
  23778. material.uniforms[name].value = getTexture(uniform.value);
  23779. break;
  23780. case 'c':
  23781. material.uniforms[name].value = new Color().setHex(uniform.value);
  23782. break;
  23783. case 'v2':
  23784. material.uniforms[name].value = new Vector2().fromArray(uniform.value);
  23785. break;
  23786. case 'v3':
  23787. material.uniforms[name].value = new Vector3().fromArray(uniform.value);
  23788. break;
  23789. case 'v4':
  23790. material.uniforms[name].value = new Vector4().fromArray(uniform.value);
  23791. break;
  23792. case 'm3':
  23793. material.uniforms[name].value = new Matrix3().fromArray(uniform.value);
  23794. break;
  23795. case 'm4':
  23796. material.uniforms[name].value = new Matrix4().fromArray(uniform.value);
  23797. break;
  23798. default:
  23799. material.uniforms[name].value = uniform.value;
  23800. }
  23801. }
  23802. }
  23803. if (json.defines !== undefined) material.defines = json.defines;
  23804. if (json.vertexShader !== undefined) material.vertexShader = json.vertexShader;
  23805. if (json.fragmentShader !== undefined) material.fragmentShader = json.fragmentShader;
  23806. if (json.extensions !== undefined) {
  23807. for (var key in json.extensions) {
  23808. material.extensions[key] = json.extensions[key];
  23809. }
  23810. } // Deprecated
  23811. if (json.shading !== undefined) material.flatShading = json.shading === 1; // THREE.FlatShading
  23812. // for PointsMaterial
  23813. if (json.size !== undefined) material.size = json.size;
  23814. if (json.sizeAttenuation !== undefined) material.sizeAttenuation = json.sizeAttenuation; // maps
  23815. if (json.map !== undefined) material.map = getTexture(json.map);
  23816. if (json.matcap !== undefined) material.matcap = getTexture(json.matcap);
  23817. if (json.alphaMap !== undefined) material.alphaMap = getTexture(json.alphaMap);
  23818. if (json.bumpMap !== undefined) material.bumpMap = getTexture(json.bumpMap);
  23819. if (json.bumpScale !== undefined) material.bumpScale = json.bumpScale;
  23820. if (json.normalMap !== undefined) material.normalMap = getTexture(json.normalMap);
  23821. if (json.normalMapType !== undefined) material.normalMapType = json.normalMapType;
  23822. if (json.normalScale !== undefined) {
  23823. var normalScale = json.normalScale;
  23824. if (Array.isArray(normalScale) === false) {
  23825. // Blender exporter used to export a scalar. See #7459
  23826. normalScale = [normalScale, normalScale];
  23827. }
  23828. material.normalScale = new Vector2().fromArray(normalScale);
  23829. }
  23830. if (json.displacementMap !== undefined) material.displacementMap = getTexture(json.displacementMap);
  23831. if (json.displacementScale !== undefined) material.displacementScale = json.displacementScale;
  23832. if (json.displacementBias !== undefined) material.displacementBias = json.displacementBias;
  23833. if (json.roughnessMap !== undefined) material.roughnessMap = getTexture(json.roughnessMap);
  23834. if (json.metalnessMap !== undefined) material.metalnessMap = getTexture(json.metalnessMap);
  23835. if (json.emissiveMap !== undefined) material.emissiveMap = getTexture(json.emissiveMap);
  23836. if (json.emissiveIntensity !== undefined) material.emissiveIntensity = json.emissiveIntensity;
  23837. if (json.specularMap !== undefined) material.specularMap = getTexture(json.specularMap);
  23838. if (json.envMap !== undefined) material.envMap = getTexture(json.envMap);
  23839. if (json.envMapIntensity !== undefined) material.envMapIntensity = json.envMapIntensity;
  23840. if (json.reflectivity !== undefined) material.reflectivity = json.reflectivity;
  23841. if (json.refractionRatio !== undefined) material.refractionRatio = json.refractionRatio;
  23842. if (json.lightMap !== undefined) material.lightMap = getTexture(json.lightMap);
  23843. if (json.lightMapIntensity !== undefined) material.lightMapIntensity = json.lightMapIntensity;
  23844. if (json.aoMap !== undefined) material.aoMap = getTexture(json.aoMap);
  23845. if (json.aoMapIntensity !== undefined) material.aoMapIntensity = json.aoMapIntensity;
  23846. if (json.gradientMap !== undefined) material.gradientMap = getTexture(json.gradientMap);
  23847. if (json.clearcoatMap !== undefined) material.clearcoatMap = getTexture(json.clearcoatMap);
  23848. if (json.clearcoatRoughnessMap !== undefined) material.clearcoatRoughnessMap = getTexture(json.clearcoatRoughnessMap);
  23849. if (json.clearcoatNormalMap !== undefined) material.clearcoatNormalMap = getTexture(json.clearcoatNormalMap);
  23850. if (json.clearcoatNormalScale !== undefined) material.clearcoatNormalScale = new Vector2().fromArray(json.clearcoatNormalScale);
  23851. if (json.transmission !== undefined) material.transmission = json.transmission;
  23852. if (json.transmissionMap !== undefined) material.transmissionMap = getTexture(json.transmissionMap);
  23853. return material;
  23854. },
  23855. setTextures: function setTextures(value) {
  23856. this.textures = value;
  23857. return this;
  23858. }
  23859. });
  23860. var LoaderUtils = {
  23861. decodeText: function decodeText(array) {
  23862. if (typeof TextDecoder !== 'undefined') {
  23863. return new TextDecoder().decode(array);
  23864. } // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  23865. // throws a "maximum call stack size exceeded" error for large arrays.
  23866. var s = '';
  23867. for (var i = 0, il = array.length; i < il; i++) {
  23868. // Implicitly assumes little-endian.
  23869. s += String.fromCharCode(array[i]);
  23870. }
  23871. try {
  23872. // merges multi-byte utf-8 characters.
  23873. return decodeURIComponent(escape(s));
  23874. } catch (e) {
  23875. // see #16358
  23876. return s;
  23877. }
  23878. },
  23879. extractUrlBase: function extractUrlBase(url) {
  23880. var index = url.lastIndexOf('/');
  23881. if (index === -1) return './';
  23882. return url.substr(0, index + 1);
  23883. }
  23884. };
  23885. function InstancedBufferGeometry() {
  23886. BufferGeometry.call(this);
  23887. this.type = 'InstancedBufferGeometry';
  23888. this.instanceCount = Infinity;
  23889. }
  23890. InstancedBufferGeometry.prototype = Object.assign(Object.create(BufferGeometry.prototype), {
  23891. constructor: InstancedBufferGeometry,
  23892. isInstancedBufferGeometry: true,
  23893. copy: function copy(source) {
  23894. BufferGeometry.prototype.copy.call(this, source);
  23895. this.instanceCount = source.instanceCount;
  23896. return this;
  23897. },
  23898. clone: function clone() {
  23899. return new this.constructor().copy(this);
  23900. },
  23901. toJSON: function toJSON() {
  23902. var data = BufferGeometry.prototype.toJSON.call(this);
  23903. data.instanceCount = this.instanceCount;
  23904. data.isInstancedBufferGeometry = true;
  23905. return data;
  23906. }
  23907. });
  23908. function InstancedBufferAttribute(array, itemSize, normalized, meshPerAttribute) {
  23909. if (typeof normalized === 'number') {
  23910. meshPerAttribute = normalized;
  23911. normalized = false;
  23912. console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');
  23913. }
  23914. BufferAttribute.call(this, array, itemSize, normalized);
  23915. this.meshPerAttribute = meshPerAttribute || 1;
  23916. }
  23917. InstancedBufferAttribute.prototype = Object.assign(Object.create(BufferAttribute.prototype), {
  23918. constructor: InstancedBufferAttribute,
  23919. isInstancedBufferAttribute: true,
  23920. copy: function copy(source) {
  23921. BufferAttribute.prototype.copy.call(this, source);
  23922. this.meshPerAttribute = source.meshPerAttribute;
  23923. return this;
  23924. },
  23925. toJSON: function toJSON() {
  23926. var data = BufferAttribute.prototype.toJSON.call(this);
  23927. data.meshPerAttribute = this.meshPerAttribute;
  23928. data.isInstancedBufferAttribute = true;
  23929. return data;
  23930. }
  23931. });
  23932. function BufferGeometryLoader(manager) {
  23933. Loader.call(this, manager);
  23934. }
  23935. BufferGeometryLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  23936. constructor: BufferGeometryLoader,
  23937. load: function load(url, onLoad, onProgress, onError) {
  23938. var scope = this;
  23939. var loader = new FileLoader(scope.manager);
  23940. loader.setPath(scope.path);
  23941. loader.setRequestHeader(scope.requestHeader);
  23942. loader.setWithCredentials(scope.withCredentials);
  23943. loader.load(url, function (text) {
  23944. try {
  23945. onLoad(scope.parse(JSON.parse(text)));
  23946. } catch (e) {
  23947. if (onError) {
  23948. onError(e);
  23949. } else {
  23950. console.error(e);
  23951. }
  23952. scope.manager.itemError(url);
  23953. }
  23954. }, onProgress, onError);
  23955. },
  23956. parse: function parse(json) {
  23957. var interleavedBufferMap = {};
  23958. var arrayBufferMap = {};
  23959. function getInterleavedBuffer(json, uuid) {
  23960. if (interleavedBufferMap[uuid] !== undefined) return interleavedBufferMap[uuid];
  23961. var interleavedBuffers = json.interleavedBuffers;
  23962. var interleavedBuffer = interleavedBuffers[uuid];
  23963. var buffer = getArrayBuffer(json, interleavedBuffer.buffer);
  23964. var array = getTypedArray(interleavedBuffer.type, buffer);
  23965. var ib = new InterleavedBuffer(array, interleavedBuffer.stride);
  23966. ib.uuid = interleavedBuffer.uuid;
  23967. interleavedBufferMap[uuid] = ib;
  23968. return ib;
  23969. }
  23970. function getArrayBuffer(json, uuid) {
  23971. if (arrayBufferMap[uuid] !== undefined) return arrayBufferMap[uuid];
  23972. var arrayBuffers = json.arrayBuffers;
  23973. var arrayBuffer = arrayBuffers[uuid];
  23974. var ab = new Uint32Array(arrayBuffer).buffer;
  23975. arrayBufferMap[uuid] = ab;
  23976. return ab;
  23977. }
  23978. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23979. var index = json.data.index;
  23980. if (index !== undefined) {
  23981. var typedArray = getTypedArray(index.type, index.array);
  23982. geometry.setIndex(new BufferAttribute(typedArray, 1));
  23983. }
  23984. var attributes = json.data.attributes;
  23985. for (var key in attributes) {
  23986. var attribute = attributes[key];
  23987. var bufferAttribute = void 0;
  23988. if (attribute.isInterleavedBufferAttribute) {
  23989. var interleavedBuffer = getInterleavedBuffer(json.data, attribute.data);
  23990. bufferAttribute = new InterleavedBufferAttribute(interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized);
  23991. } else {
  23992. var _typedArray = getTypedArray(attribute.type, attribute.array);
  23993. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23994. bufferAttribute = new bufferAttributeConstr(_typedArray, attribute.itemSize, attribute.normalized);
  23995. }
  23996. if (attribute.name !== undefined) bufferAttribute.name = attribute.name;
  23997. geometry.setAttribute(key, bufferAttribute);
  23998. }
  23999. var morphAttributes = json.data.morphAttributes;
  24000. if (morphAttributes) {
  24001. for (var _key in morphAttributes) {
  24002. var attributeArray = morphAttributes[_key];
  24003. var array = [];
  24004. for (var i = 0, il = attributeArray.length; i < il; i++) {
  24005. var _attribute = attributeArray[i];
  24006. var _bufferAttribute = void 0;
  24007. if (_attribute.isInterleavedBufferAttribute) {
  24008. var _interleavedBuffer = getInterleavedBuffer(json.data, _attribute.data);
  24009. _bufferAttribute = new InterleavedBufferAttribute(_interleavedBuffer, _attribute.itemSize, _attribute.offset, _attribute.normalized);
  24010. } else {
  24011. var _typedArray2 = getTypedArray(_attribute.type, _attribute.array);
  24012. _bufferAttribute = new BufferAttribute(_typedArray2, _attribute.itemSize, _attribute.normalized);
  24013. }
  24014. if (_attribute.name !== undefined) _bufferAttribute.name = _attribute.name;
  24015. array.push(_bufferAttribute);
  24016. }
  24017. geometry.morphAttributes[_key] = array;
  24018. }
  24019. }
  24020. var morphTargetsRelative = json.data.morphTargetsRelative;
  24021. if (morphTargetsRelative) {
  24022. geometry.morphTargetsRelative = true;
  24023. }
  24024. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24025. if (groups !== undefined) {
  24026. for (var _i = 0, n = groups.length; _i !== n; ++_i) {
  24027. var group = groups[_i];
  24028. geometry.addGroup(group.start, group.count, group.materialIndex);
  24029. }
  24030. }
  24031. var boundingSphere = json.data.boundingSphere;
  24032. if (boundingSphere !== undefined) {
  24033. var center = new Vector3();
  24034. if (boundingSphere.center !== undefined) {
  24035. center.fromArray(boundingSphere.center);
  24036. }
  24037. geometry.boundingSphere = new Sphere(center, boundingSphere.radius);
  24038. }
  24039. if (json.name) geometry.name = json.name;
  24040. if (json.userData) geometry.userData = json.userData;
  24041. return geometry;
  24042. }
  24043. });
  24044. var ObjectLoader = /*#__PURE__*/function (_Loader) {
  24045. _inheritsLoose(ObjectLoader, _Loader);
  24046. function ObjectLoader(manager) {
  24047. return _Loader.call(this, manager) || this;
  24048. }
  24049. var _proto = ObjectLoader.prototype;
  24050. _proto.load = function load(url, onLoad, onProgress, onError) {
  24051. var scope = this;
  24052. var path = this.path === '' ? LoaderUtils.extractUrlBase(url) : this.path;
  24053. this.resourcePath = this.resourcePath || path;
  24054. var loader = new FileLoader(this.manager);
  24055. loader.setPath(this.path);
  24056. loader.setRequestHeader(this.requestHeader);
  24057. loader.setWithCredentials(this.withCredentials);
  24058. loader.load(url, function (text) {
  24059. var json = null;
  24060. try {
  24061. json = JSON.parse(text);
  24062. } catch (error) {
  24063. if (onError !== undefined) onError(error);
  24064. console.error('THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message);
  24065. return;
  24066. }
  24067. var metadata = json.metadata;
  24068. if (metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry') {
  24069. console.error('THREE.ObjectLoader: Can\'t load ' + url);
  24070. return;
  24071. }
  24072. scope.parse(json, onLoad);
  24073. }, onProgress, onError);
  24074. };
  24075. _proto.parse = function parse(json, onLoad) {
  24076. var animations = this.parseAnimations(json.animations);
  24077. var shapes = this.parseShapes(json.shapes);
  24078. var geometries = this.parseGeometries(json.geometries, shapes);
  24079. var images = this.parseImages(json.images, function () {
  24080. if (onLoad !== undefined) onLoad(object);
  24081. });
  24082. var textures = this.parseTextures(json.textures, images);
  24083. var materials = this.parseMaterials(json.materials, textures);
  24084. var object = this.parseObject(json.object, geometries, materials, animations);
  24085. var skeletons = this.parseSkeletons(json.skeletons, object);
  24086. this.bindSkeletons(object, skeletons); //
  24087. if (onLoad !== undefined) {
  24088. var hasImages = false;
  24089. for (var uuid in images) {
  24090. if (images[uuid] instanceof HTMLImageElement) {
  24091. hasImages = true;
  24092. break;
  24093. }
  24094. }
  24095. if (hasImages === false) onLoad(object);
  24096. }
  24097. return object;
  24098. };
  24099. _proto.parseShapes = function parseShapes(json) {
  24100. var shapes = {};
  24101. if (json !== undefined) {
  24102. for (var i = 0, l = json.length; i < l; i++) {
  24103. var shape = new Shape().fromJSON(json[i]);
  24104. shapes[shape.uuid] = shape;
  24105. }
  24106. }
  24107. return shapes;
  24108. };
  24109. _proto.parseSkeletons = function parseSkeletons(json, object) {
  24110. var skeletons = {};
  24111. var bones = {}; // generate bone lookup table
  24112. object.traverse(function (child) {
  24113. if (child.isBone) bones[child.uuid] = child;
  24114. }); // create skeletons
  24115. if (json !== undefined) {
  24116. for (var i = 0, l = json.length; i < l; i++) {
  24117. var skeleton = new Skeleton().fromJSON(json[i], bones);
  24118. skeletons[skeleton.uuid] = skeleton;
  24119. }
  24120. }
  24121. return skeletons;
  24122. };
  24123. _proto.parseGeometries = function parseGeometries(json, shapes) {
  24124. var geometries = {};
  24125. var geometryShapes;
  24126. if (json !== undefined) {
  24127. var bufferGeometryLoader = new BufferGeometryLoader();
  24128. for (var i = 0, l = json.length; i < l; i++) {
  24129. var geometry = void 0;
  24130. var data = json[i];
  24131. switch (data.type) {
  24132. case 'PlaneGeometry':
  24133. case 'PlaneBufferGeometry':
  24134. geometry = new Geometries[data.type](data.width, data.height, data.widthSegments, data.heightSegments);
  24135. break;
  24136. case 'BoxGeometry':
  24137. case 'BoxBufferGeometry':
  24138. geometry = new Geometries[data.type](data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments);
  24139. break;
  24140. case 'CircleGeometry':
  24141. case 'CircleBufferGeometry':
  24142. geometry = new Geometries[data.type](data.radius, data.segments, data.thetaStart, data.thetaLength);
  24143. break;
  24144. case 'CylinderGeometry':
  24145. case 'CylinderBufferGeometry':
  24146. geometry = new Geometries[data.type](data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24147. break;
  24148. case 'ConeGeometry':
  24149. case 'ConeBufferGeometry':
  24150. geometry = new Geometries[data.type](data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength);
  24151. break;
  24152. case 'SphereGeometry':
  24153. case 'SphereBufferGeometry':
  24154. geometry = new Geometries[data.type](data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength);
  24155. break;
  24156. case 'DodecahedronGeometry':
  24157. case 'DodecahedronBufferGeometry':
  24158. case 'IcosahedronGeometry':
  24159. case 'IcosahedronBufferGeometry':
  24160. case 'OctahedronGeometry':
  24161. case 'OctahedronBufferGeometry':
  24162. case 'TetrahedronGeometry':
  24163. case 'TetrahedronBufferGeometry':
  24164. geometry = new Geometries[data.type](data.radius, data.detail);
  24165. break;
  24166. case 'RingGeometry':
  24167. case 'RingBufferGeometry':
  24168. geometry = new Geometries[data.type](data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength);
  24169. break;
  24170. case 'TorusGeometry':
  24171. case 'TorusBufferGeometry':
  24172. geometry = new Geometries[data.type](data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc);
  24173. break;
  24174. case 'TorusKnotGeometry':
  24175. case 'TorusKnotBufferGeometry':
  24176. geometry = new Geometries[data.type](data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q);
  24177. break;
  24178. case 'TubeGeometry':
  24179. case 'TubeBufferGeometry':
  24180. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24181. // User defined curves or instances of CurvePath will not be deserialized.
  24182. geometry = new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed);
  24183. break;
  24184. case 'LatheGeometry':
  24185. case 'LatheBufferGeometry':
  24186. geometry = new Geometries[data.type](data.points, data.segments, data.phiStart, data.phiLength);
  24187. break;
  24188. case 'PolyhedronGeometry':
  24189. case 'PolyhedronBufferGeometry':
  24190. geometry = new Geometries[data.type](data.vertices, data.indices, data.radius, data.details);
  24191. break;
  24192. case 'ShapeGeometry':
  24193. case 'ShapeBufferGeometry':
  24194. geometryShapes = [];
  24195. for (var j = 0, jl = data.shapes.length; j < jl; j++) {
  24196. var shape = shapes[data.shapes[j]];
  24197. geometryShapes.push(shape);
  24198. }
  24199. geometry = new Geometries[data.type](geometryShapes, data.curveSegments);
  24200. break;
  24201. case 'ExtrudeGeometry':
  24202. case 'ExtrudeBufferGeometry':
  24203. geometryShapes = [];
  24204. for (var _j = 0, _jl = data.shapes.length; _j < _jl; _j++) {
  24205. var _shape = shapes[data.shapes[_j]];
  24206. geometryShapes.push(_shape);
  24207. }
  24208. var extrudePath = data.options.extrudePath;
  24209. if (extrudePath !== undefined) {
  24210. data.options.extrudePath = new Curves[extrudePath.type]().fromJSON(extrudePath);
  24211. }
  24212. geometry = new Geometries[data.type](geometryShapes, data.options);
  24213. break;
  24214. case 'BufferGeometry':
  24215. case 'InstancedBufferGeometry':
  24216. geometry = bufferGeometryLoader.parse(data);
  24217. break;
  24218. case 'Geometry':
  24219. console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');
  24220. break;
  24221. default:
  24222. console.warn('THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"');
  24223. continue;
  24224. }
  24225. geometry.uuid = data.uuid;
  24226. if (data.name !== undefined) geometry.name = data.name;
  24227. if (geometry.isBufferGeometry === true && data.userData !== undefined) geometry.userData = data.userData;
  24228. geometries[data.uuid] = geometry;
  24229. }
  24230. }
  24231. return geometries;
  24232. };
  24233. _proto.parseMaterials = function parseMaterials(json, textures) {
  24234. var cache = {}; // MultiMaterial
  24235. var materials = {};
  24236. if (json !== undefined) {
  24237. var loader = new MaterialLoader();
  24238. loader.setTextures(textures);
  24239. for (var i = 0, l = json.length; i < l; i++) {
  24240. var data = json[i];
  24241. if (data.type === 'MultiMaterial') {
  24242. // Deprecated
  24243. var array = [];
  24244. for (var j = 0; j < data.materials.length; j++) {
  24245. var material = data.materials[j];
  24246. if (cache[material.uuid] === undefined) {
  24247. cache[material.uuid] = loader.parse(material);
  24248. }
  24249. array.push(cache[material.uuid]);
  24250. }
  24251. materials[data.uuid] = array;
  24252. } else {
  24253. if (cache[data.uuid] === undefined) {
  24254. cache[data.uuid] = loader.parse(data);
  24255. }
  24256. materials[data.uuid] = cache[data.uuid];
  24257. }
  24258. }
  24259. }
  24260. return materials;
  24261. };
  24262. _proto.parseAnimations = function parseAnimations(json) {
  24263. var animations = {};
  24264. if (json !== undefined) {
  24265. for (var i = 0; i < json.length; i++) {
  24266. var data = json[i];
  24267. var clip = AnimationClip.parse(data);
  24268. animations[clip.uuid] = clip;
  24269. }
  24270. }
  24271. return animations;
  24272. };
  24273. _proto.parseImages = function parseImages(json, onLoad) {
  24274. var scope = this;
  24275. var images = {};
  24276. var loader;
  24277. function loadImage(url) {
  24278. scope.manager.itemStart(url);
  24279. return loader.load(url, function () {
  24280. scope.manager.itemEnd(url);
  24281. }, undefined, function () {
  24282. scope.manager.itemError(url);
  24283. scope.manager.itemEnd(url);
  24284. });
  24285. }
  24286. function deserializeImage(image) {
  24287. if (typeof image === 'string') {
  24288. var url = image;
  24289. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test(url) ? url : scope.resourcePath + url;
  24290. return loadImage(path);
  24291. } else {
  24292. if (image.data) {
  24293. return {
  24294. data: getTypedArray(image.type, image.data),
  24295. width: image.width,
  24296. height: image.height
  24297. };
  24298. } else {
  24299. return null;
  24300. }
  24301. }
  24302. }
  24303. if (json !== undefined && json.length > 0) {
  24304. var manager = new LoadingManager(onLoad);
  24305. loader = new ImageLoader(manager);
  24306. loader.setCrossOrigin(this.crossOrigin);
  24307. for (var i = 0, il = json.length; i < il; i++) {
  24308. var image = json[i];
  24309. var url = image.url;
  24310. if (Array.isArray(url)) {
  24311. // load array of images e.g CubeTexture
  24312. images[image.uuid] = [];
  24313. for (var j = 0, jl = url.length; j < jl; j++) {
  24314. var currentUrl = url[j];
  24315. var deserializedImage = deserializeImage(currentUrl);
  24316. if (deserializedImage !== null) {
  24317. if (deserializedImage instanceof HTMLImageElement) {
  24318. images[image.uuid].push(deserializedImage);
  24319. } else {
  24320. // special case: handle array of data textures for cube textures
  24321. images[image.uuid].push(new DataTexture(deserializedImage.data, deserializedImage.width, deserializedImage.height));
  24322. }
  24323. }
  24324. }
  24325. } else {
  24326. // load single image
  24327. var _deserializedImage = deserializeImage(image.url);
  24328. if (_deserializedImage !== null) {
  24329. images[image.uuid] = _deserializedImage;
  24330. }
  24331. }
  24332. }
  24333. }
  24334. return images;
  24335. };
  24336. _proto.parseTextures = function parseTextures(json, images) {
  24337. function parseConstant(value, type) {
  24338. if (typeof value === 'number') return value;
  24339. console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value);
  24340. return type[value];
  24341. }
  24342. var textures = {};
  24343. if (json !== undefined) {
  24344. for (var i = 0, l = json.length; i < l; i++) {
  24345. var data = json[i];
  24346. if (data.image === undefined) {
  24347. console.warn('THREE.ObjectLoader: No "image" specified for', data.uuid);
  24348. }
  24349. if (images[data.image] === undefined) {
  24350. console.warn('THREE.ObjectLoader: Undefined image', data.image);
  24351. }
  24352. var texture = void 0;
  24353. var image = images[data.image];
  24354. if (Array.isArray(image)) {
  24355. texture = new CubeTexture(image);
  24356. if (image.length === 6) texture.needsUpdate = true;
  24357. } else {
  24358. if (image && image.data) {
  24359. texture = new DataTexture(image.data, image.width, image.height);
  24360. } else {
  24361. texture = new Texture(image);
  24362. }
  24363. if (image) texture.needsUpdate = true; // textures can have undefined image data
  24364. }
  24365. texture.uuid = data.uuid;
  24366. if (data.name !== undefined) texture.name = data.name;
  24367. if (data.mapping !== undefined) texture.mapping = parseConstant(data.mapping, TEXTURE_MAPPING);
  24368. if (data.offset !== undefined) texture.offset.fromArray(data.offset);
  24369. if (data.repeat !== undefined) texture.repeat.fromArray(data.repeat);
  24370. if (data.center !== undefined) texture.center.fromArray(data.center);
  24371. if (data.rotation !== undefined) texture.rotation = data.rotation;
  24372. if (data.wrap !== undefined) {
  24373. texture.wrapS = parseConstant(data.wrap[0], TEXTURE_WRAPPING);
  24374. texture.wrapT = parseConstant(data.wrap[1], TEXTURE_WRAPPING);
  24375. }
  24376. if (data.format !== undefined) texture.format = data.format;
  24377. if (data.type !== undefined) texture.type = data.type;
  24378. if (data.encoding !== undefined) texture.encoding = data.encoding;
  24379. if (data.minFilter !== undefined) texture.minFilter = parseConstant(data.minFilter, TEXTURE_FILTER);
  24380. if (data.magFilter !== undefined) texture.magFilter = parseConstant(data.magFilter, TEXTURE_FILTER);
  24381. if (data.anisotropy !== undefined) texture.anisotropy = data.anisotropy;
  24382. if (data.flipY !== undefined) texture.flipY = data.flipY;
  24383. if (data.premultiplyAlpha !== undefined) texture.premultiplyAlpha = data.premultiplyAlpha;
  24384. if (data.unpackAlignment !== undefined) texture.unpackAlignment = data.unpackAlignment;
  24385. textures[data.uuid] = texture;
  24386. }
  24387. }
  24388. return textures;
  24389. };
  24390. _proto.parseObject = function parseObject(data, geometries, materials, animations) {
  24391. var object;
  24392. function getGeometry(name) {
  24393. if (geometries[name] === undefined) {
  24394. console.warn('THREE.ObjectLoader: Undefined geometry', name);
  24395. }
  24396. return geometries[name];
  24397. }
  24398. function getMaterial(name) {
  24399. if (name === undefined) return undefined;
  24400. if (Array.isArray(name)) {
  24401. var array = [];
  24402. for (var i = 0, l = name.length; i < l; i++) {
  24403. var uuid = name[i];
  24404. if (materials[uuid] === undefined) {
  24405. console.warn('THREE.ObjectLoader: Undefined material', uuid);
  24406. }
  24407. array.push(materials[uuid]);
  24408. }
  24409. return array;
  24410. }
  24411. if (materials[name] === undefined) {
  24412. console.warn('THREE.ObjectLoader: Undefined material', name);
  24413. }
  24414. return materials[name];
  24415. }
  24416. var geometry, material;
  24417. switch (data.type) {
  24418. case 'Scene':
  24419. object = new Scene();
  24420. if (data.background !== undefined) {
  24421. if (Number.isInteger(data.background)) {
  24422. object.background = new Color(data.background);
  24423. }
  24424. }
  24425. if (data.fog !== undefined) {
  24426. if (data.fog.type === 'Fog') {
  24427. object.fog = new Fog(data.fog.color, data.fog.near, data.fog.far);
  24428. } else if (data.fog.type === 'FogExp2') {
  24429. object.fog = new FogExp2(data.fog.color, data.fog.density);
  24430. }
  24431. }
  24432. break;
  24433. case 'PerspectiveCamera':
  24434. object = new PerspectiveCamera(data.fov, data.aspect, data.near, data.far);
  24435. if (data.focus !== undefined) object.focus = data.focus;
  24436. if (data.zoom !== undefined) object.zoom = data.zoom;
  24437. if (data.filmGauge !== undefined) object.filmGauge = data.filmGauge;
  24438. if (data.filmOffset !== undefined) object.filmOffset = data.filmOffset;
  24439. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24440. break;
  24441. case 'OrthographicCamera':
  24442. object = new OrthographicCamera(data.left, data.right, data.top, data.bottom, data.near, data.far);
  24443. if (data.zoom !== undefined) object.zoom = data.zoom;
  24444. if (data.view !== undefined) object.view = Object.assign({}, data.view);
  24445. break;
  24446. case 'AmbientLight':
  24447. object = new AmbientLight(data.color, data.intensity);
  24448. break;
  24449. case 'DirectionalLight':
  24450. object = new DirectionalLight(data.color, data.intensity);
  24451. break;
  24452. case 'PointLight':
  24453. object = new PointLight(data.color, data.intensity, data.distance, data.decay);
  24454. break;
  24455. case 'RectAreaLight':
  24456. object = new RectAreaLight(data.color, data.intensity, data.width, data.height);
  24457. break;
  24458. case 'SpotLight':
  24459. object = new SpotLight(data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay);
  24460. break;
  24461. case 'HemisphereLight':
  24462. object = new HemisphereLight(data.color, data.groundColor, data.intensity);
  24463. break;
  24464. case 'LightProbe':
  24465. object = new LightProbe().fromJSON(data);
  24466. break;
  24467. case 'SkinnedMesh':
  24468. geometry = getGeometry(data.geometry);
  24469. material = getMaterial(data.material);
  24470. object = new SkinnedMesh(geometry, material);
  24471. if (data.bindMode !== undefined) object.bindMode = data.bindMode;
  24472. if (data.bindMatrix !== undefined) object.bindMatrix.fromArray(data.bindMatrix);
  24473. if (data.skeleton !== undefined) object.skeleton = data.skeleton;
  24474. break;
  24475. case 'Mesh':
  24476. geometry = getGeometry(data.geometry);
  24477. material = getMaterial(data.material);
  24478. object = new Mesh(geometry, material);
  24479. break;
  24480. case 'InstancedMesh':
  24481. geometry = getGeometry(data.geometry);
  24482. material = getMaterial(data.material);
  24483. var count = data.count;
  24484. var instanceMatrix = data.instanceMatrix;
  24485. object = new InstancedMesh(geometry, material, count);
  24486. object.instanceMatrix = new BufferAttribute(new Float32Array(instanceMatrix.array), 16);
  24487. break;
  24488. case 'LOD':
  24489. object = new LOD();
  24490. break;
  24491. case 'Line':
  24492. object = new Line(getGeometry(data.geometry), getMaterial(data.material));
  24493. break;
  24494. case 'LineLoop':
  24495. object = new LineLoop(getGeometry(data.geometry), getMaterial(data.material));
  24496. break;
  24497. case 'LineSegments':
  24498. object = new LineSegments(getGeometry(data.geometry), getMaterial(data.material));
  24499. break;
  24500. case 'PointCloud':
  24501. case 'Points':
  24502. object = new Points(getGeometry(data.geometry), getMaterial(data.material));
  24503. break;
  24504. case 'Sprite':
  24505. object = new Sprite(getMaterial(data.material));
  24506. break;
  24507. case 'Group':
  24508. object = new Group();
  24509. break;
  24510. case 'Bone':
  24511. object = new Bone();
  24512. break;
  24513. default:
  24514. object = new Object3D();
  24515. }
  24516. object.uuid = data.uuid;
  24517. if (data.name !== undefined) object.name = data.name;
  24518. if (data.matrix !== undefined) {
  24519. object.matrix.fromArray(data.matrix);
  24520. if (data.matrixAutoUpdate !== undefined) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24521. if (object.matrixAutoUpdate) object.matrix.decompose(object.position, object.quaternion, object.scale);
  24522. } else {
  24523. if (data.position !== undefined) object.position.fromArray(data.position);
  24524. if (data.rotation !== undefined) object.rotation.fromArray(data.rotation);
  24525. if (data.quaternion !== undefined) object.quaternion.fromArray(data.quaternion);
  24526. if (data.scale !== undefined) object.scale.fromArray(data.scale);
  24527. }
  24528. if (data.castShadow !== undefined) object.castShadow = data.castShadow;
  24529. if (data.receiveShadow !== undefined) object.receiveShadow = data.receiveShadow;
  24530. if (data.shadow) {
  24531. if (data.shadow.bias !== undefined) object.shadow.bias = data.shadow.bias;
  24532. if (data.shadow.normalBias !== undefined) object.shadow.normalBias = data.shadow.normalBias;
  24533. if (data.shadow.radius !== undefined) object.shadow.radius = data.shadow.radius;
  24534. if (data.shadow.mapSize !== undefined) object.shadow.mapSize.fromArray(data.shadow.mapSize);
  24535. if (data.shadow.camera !== undefined) object.shadow.camera = this.parseObject(data.shadow.camera);
  24536. }
  24537. if (data.visible !== undefined) object.visible = data.visible;
  24538. if (data.frustumCulled !== undefined) object.frustumCulled = data.frustumCulled;
  24539. if (data.renderOrder !== undefined) object.renderOrder = data.renderOrder;
  24540. if (data.userData !== undefined) object.userData = data.userData;
  24541. if (data.layers !== undefined) object.layers.mask = data.layers;
  24542. if (data.children !== undefined) {
  24543. var children = data.children;
  24544. for (var i = 0; i < children.length; i++) {
  24545. object.add(this.parseObject(children[i], geometries, materials, animations));
  24546. }
  24547. }
  24548. if (data.animations !== undefined) {
  24549. var objectAnimations = data.animations;
  24550. for (var _i = 0; _i < objectAnimations.length; _i++) {
  24551. var uuid = objectAnimations[_i];
  24552. object.animations.push(animations[uuid]);
  24553. }
  24554. }
  24555. if (data.type === 'LOD') {
  24556. if (data.autoUpdate !== undefined) object.autoUpdate = data.autoUpdate;
  24557. var levels = data.levels;
  24558. for (var l = 0; l < levels.length; l++) {
  24559. var level = levels[l];
  24560. var child = object.getObjectByProperty('uuid', level.object);
  24561. if (child !== undefined) {
  24562. object.addLevel(child, level.distance);
  24563. }
  24564. }
  24565. }
  24566. return object;
  24567. };
  24568. _proto.bindSkeletons = function bindSkeletons(object, skeletons) {
  24569. if (Object.keys(skeletons).length === 0) return;
  24570. object.traverse(function (child) {
  24571. if (child.isSkinnedMesh === true && child.skeleton !== undefined) {
  24572. var skeleton = skeletons[child.skeleton];
  24573. if (skeleton === undefined) {
  24574. console.warn('THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton);
  24575. } else {
  24576. child.bind(skeleton, child.bindMatrix);
  24577. }
  24578. }
  24579. });
  24580. }
  24581. /* DEPRECATED */
  24582. ;
  24583. _proto.setTexturePath = function setTexturePath(value) {
  24584. console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');
  24585. return this.setResourcePath(value);
  24586. };
  24587. return ObjectLoader;
  24588. }(Loader);
  24589. var TEXTURE_MAPPING = {
  24590. UVMapping: UVMapping,
  24591. CubeReflectionMapping: CubeReflectionMapping,
  24592. CubeRefractionMapping: CubeRefractionMapping,
  24593. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24594. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24595. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24596. CubeUVRefractionMapping: CubeUVRefractionMapping
  24597. };
  24598. var TEXTURE_WRAPPING = {
  24599. RepeatWrapping: RepeatWrapping,
  24600. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24601. MirroredRepeatWrapping: MirroredRepeatWrapping
  24602. };
  24603. var TEXTURE_FILTER = {
  24604. NearestFilter: NearestFilter,
  24605. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24606. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24607. LinearFilter: LinearFilter,
  24608. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24609. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24610. };
  24611. function ImageBitmapLoader(manager) {
  24612. if (typeof createImageBitmap === 'undefined') {
  24613. console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');
  24614. }
  24615. if (typeof fetch === 'undefined') {
  24616. console.warn('THREE.ImageBitmapLoader: fetch() not supported.');
  24617. }
  24618. Loader.call(this, manager);
  24619. this.options = {
  24620. premultiplyAlpha: 'none'
  24621. };
  24622. }
  24623. ImageBitmapLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24624. constructor: ImageBitmapLoader,
  24625. isImageBitmapLoader: true,
  24626. setOptions: function setOptions(options) {
  24627. this.options = options;
  24628. return this;
  24629. },
  24630. load: function load(url, onLoad, onProgress, onError) {
  24631. if (url === undefined) url = '';
  24632. if (this.path !== undefined) url = this.path + url;
  24633. url = this.manager.resolveURL(url);
  24634. var scope = this;
  24635. var cached = Cache.get(url);
  24636. if (cached !== undefined) {
  24637. scope.manager.itemStart(url);
  24638. setTimeout(function () {
  24639. if (onLoad) onLoad(cached);
  24640. scope.manager.itemEnd(url);
  24641. }, 0);
  24642. return cached;
  24643. }
  24644. var fetchOptions = {};
  24645. fetchOptions.credentials = this.crossOrigin === 'anonymous' ? 'same-origin' : 'include';
  24646. fetch(url, fetchOptions).then(function (res) {
  24647. return res.blob();
  24648. }).then(function (blob) {
  24649. return createImageBitmap(blob, scope.options);
  24650. }).then(function (imageBitmap) {
  24651. Cache.add(url, imageBitmap);
  24652. if (onLoad) onLoad(imageBitmap);
  24653. scope.manager.itemEnd(url);
  24654. }).catch(function (e) {
  24655. if (onError) onError(e);
  24656. scope.manager.itemError(url);
  24657. scope.manager.itemEnd(url);
  24658. });
  24659. scope.manager.itemStart(url);
  24660. }
  24661. });
  24662. function ShapePath() {
  24663. this.type = 'ShapePath';
  24664. this.color = new Color();
  24665. this.subPaths = [];
  24666. this.currentPath = null;
  24667. }
  24668. Object.assign(ShapePath.prototype, {
  24669. moveTo: function moveTo(x, y) {
  24670. this.currentPath = new Path();
  24671. this.subPaths.push(this.currentPath);
  24672. this.currentPath.moveTo(x, y);
  24673. return this;
  24674. },
  24675. lineTo: function lineTo(x, y) {
  24676. this.currentPath.lineTo(x, y);
  24677. return this;
  24678. },
  24679. quadraticCurveTo: function quadraticCurveTo(aCPx, aCPy, aX, aY) {
  24680. this.currentPath.quadraticCurveTo(aCPx, aCPy, aX, aY);
  24681. return this;
  24682. },
  24683. bezierCurveTo: function bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY) {
  24684. this.currentPath.bezierCurveTo(aCP1x, aCP1y, aCP2x, aCP2y, aX, aY);
  24685. return this;
  24686. },
  24687. splineThru: function splineThru(pts) {
  24688. this.currentPath.splineThru(pts);
  24689. return this;
  24690. },
  24691. toShapes: function toShapes(isCCW, noHoles) {
  24692. function toShapesNoHoles(inSubpaths) {
  24693. var shapes = [];
  24694. for (var i = 0, l = inSubpaths.length; i < l; i++) {
  24695. var _tmpPath = inSubpaths[i];
  24696. var _tmpShape = new Shape();
  24697. _tmpShape.curves = _tmpPath.curves;
  24698. shapes.push(_tmpShape);
  24699. }
  24700. return shapes;
  24701. }
  24702. function isPointInsidePolygon(inPt, inPolygon) {
  24703. var polyLen = inPolygon.length; // inPt on polygon contour => immediate success or
  24704. // toggling of inside/outside at every single! intersection point of an edge
  24705. // with the horizontal line through inPt, left of inPt
  24706. // not counting lowerY endpoints of edges and whole edges on that line
  24707. var inside = false;
  24708. for (var p = polyLen - 1, q = 0; q < polyLen; p = q++) {
  24709. var edgeLowPt = inPolygon[p];
  24710. var edgeHighPt = inPolygon[q];
  24711. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  24712. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  24713. if (Math.abs(edgeDy) > Number.EPSILON) {
  24714. // not parallel
  24715. if (edgeDy < 0) {
  24716. edgeLowPt = inPolygon[q];
  24717. edgeDx = -edgeDx;
  24718. edgeHighPt = inPolygon[p];
  24719. edgeDy = -edgeDy;
  24720. }
  24721. if (inPt.y < edgeLowPt.y || inPt.y > edgeHighPt.y) continue;
  24722. if (inPt.y === edgeLowPt.y) {
  24723. if (inPt.x === edgeLowPt.x) return true; // inPt is on contour ?
  24724. // continue; // no intersection or edgeLowPt => doesn't count !!!
  24725. } else {
  24726. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  24727. if (perpEdge === 0) return true; // inPt is on contour ?
  24728. if (perpEdge < 0) continue;
  24729. inside = !inside; // true intersection left of inPt
  24730. }
  24731. } else {
  24732. // parallel or collinear
  24733. if (inPt.y !== edgeLowPt.y) continue; // parallel
  24734. // edge lies on the same horizontal line as inPt
  24735. if (edgeHighPt.x <= inPt.x && inPt.x <= edgeLowPt.x || edgeLowPt.x <= inPt.x && inPt.x <= edgeHighPt.x) return true; // inPt: Point on contour !
  24736. // continue;
  24737. }
  24738. }
  24739. return inside;
  24740. }
  24741. var isClockWise = ShapeUtils.isClockWise;
  24742. var subPaths = this.subPaths;
  24743. if (subPaths.length === 0) return [];
  24744. if (noHoles === true) return toShapesNoHoles(subPaths);
  24745. var solid, tmpPath, tmpShape;
  24746. var shapes = [];
  24747. if (subPaths.length === 1) {
  24748. tmpPath = subPaths[0];
  24749. tmpShape = new Shape();
  24750. tmpShape.curves = tmpPath.curves;
  24751. shapes.push(tmpShape);
  24752. return shapes;
  24753. }
  24754. var holesFirst = !isClockWise(subPaths[0].getPoints());
  24755. holesFirst = isCCW ? !holesFirst : holesFirst; // console.log("Holes first", holesFirst);
  24756. var betterShapeHoles = [];
  24757. var newShapes = [];
  24758. var newShapeHoles = [];
  24759. var mainIdx = 0;
  24760. var tmpPoints;
  24761. newShapes[mainIdx] = undefined;
  24762. newShapeHoles[mainIdx] = [];
  24763. for (var i = 0, l = subPaths.length; i < l; i++) {
  24764. tmpPath = subPaths[i];
  24765. tmpPoints = tmpPath.getPoints();
  24766. solid = isClockWise(tmpPoints);
  24767. solid = isCCW ? !solid : solid;
  24768. if (solid) {
  24769. if (!holesFirst && newShapes[mainIdx]) mainIdx++;
  24770. newShapes[mainIdx] = {
  24771. s: new Shape(),
  24772. p: tmpPoints
  24773. };
  24774. newShapes[mainIdx].s.curves = tmpPath.curves;
  24775. if (holesFirst) mainIdx++;
  24776. newShapeHoles[mainIdx] = []; //console.log('cw', i);
  24777. } else {
  24778. newShapeHoles[mainIdx].push({
  24779. h: tmpPath,
  24780. p: tmpPoints[0]
  24781. }); //console.log('ccw', i);
  24782. }
  24783. } // only Holes? -> probably all Shapes with wrong orientation
  24784. if (!newShapes[0]) return toShapesNoHoles(subPaths);
  24785. if (newShapes.length > 1) {
  24786. var ambiguous = false;
  24787. var toChange = [];
  24788. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx++) {
  24789. betterShapeHoles[sIdx] = [];
  24790. }
  24791. for (var _sIdx = 0, _sLen = newShapes.length; _sIdx < _sLen; _sIdx++) {
  24792. var sho = newShapeHoles[_sIdx];
  24793. for (var hIdx = 0; hIdx < sho.length; hIdx++) {
  24794. var ho = sho[hIdx];
  24795. var hole_unassigned = true;
  24796. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx++) {
  24797. if (isPointInsidePolygon(ho.p, newShapes[s2Idx].p)) {
  24798. if (_sIdx !== s2Idx) toChange.push({
  24799. froms: _sIdx,
  24800. tos: s2Idx,
  24801. hole: hIdx
  24802. });
  24803. if (hole_unassigned) {
  24804. hole_unassigned = false;
  24805. betterShapeHoles[s2Idx].push(ho);
  24806. } else {
  24807. ambiguous = true;
  24808. }
  24809. }
  24810. }
  24811. if (hole_unassigned) {
  24812. betterShapeHoles[_sIdx].push(ho);
  24813. }
  24814. }
  24815. } // console.log("ambiguous: ", ambiguous);
  24816. if (toChange.length > 0) {
  24817. // console.log("to change: ", toChange);
  24818. if (!ambiguous) newShapeHoles = betterShapeHoles;
  24819. }
  24820. }
  24821. var tmpHoles;
  24822. for (var _i = 0, il = newShapes.length; _i < il; _i++) {
  24823. tmpShape = newShapes[_i].s;
  24824. shapes.push(tmpShape);
  24825. tmpHoles = newShapeHoles[_i];
  24826. for (var j = 0, jl = tmpHoles.length; j < jl; j++) {
  24827. tmpShape.holes.push(tmpHoles[j].h);
  24828. }
  24829. } //console.log("shape", shapes);
  24830. return shapes;
  24831. }
  24832. });
  24833. var Font = /*#__PURE__*/function () {
  24834. function Font(data) {
  24835. Object.defineProperty(this, 'isFont', {
  24836. value: true
  24837. });
  24838. this.type = 'Font';
  24839. this.data = data;
  24840. }
  24841. var _proto = Font.prototype;
  24842. _proto.generateShapes = function generateShapes(text, size) {
  24843. if (size === void 0) {
  24844. size = 100;
  24845. }
  24846. var shapes = [];
  24847. var paths = createPaths(text, size, this.data);
  24848. for (var p = 0, pl = paths.length; p < pl; p++) {
  24849. Array.prototype.push.apply(shapes, paths[p].toShapes());
  24850. }
  24851. return shapes;
  24852. };
  24853. return Font;
  24854. }();
  24855. function createPaths(text, size, data) {
  24856. var chars = Array.from ? Array.from(text) : String(text).split(''); // workaround for IE11, see #13988
  24857. var scale = size / data.resolution;
  24858. var line_height = (data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness) * scale;
  24859. var paths = [];
  24860. var offsetX = 0,
  24861. offsetY = 0;
  24862. for (var i = 0; i < chars.length; i++) {
  24863. var char = chars[i];
  24864. if (char === '\n') {
  24865. offsetX = 0;
  24866. offsetY -= line_height;
  24867. } else {
  24868. var ret = createPath(char, scale, offsetX, offsetY, data);
  24869. offsetX += ret.offsetX;
  24870. paths.push(ret.path);
  24871. }
  24872. }
  24873. return paths;
  24874. }
  24875. function createPath(char, scale, offsetX, offsetY, data) {
  24876. var glyph = data.glyphs[char] || data.glyphs['?'];
  24877. if (!glyph) {
  24878. console.error('THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.');
  24879. return;
  24880. }
  24881. var path = new ShapePath();
  24882. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  24883. if (glyph.o) {
  24884. var outline = glyph._cachedOutline || (glyph._cachedOutline = glyph.o.split(' '));
  24885. for (var i = 0, l = outline.length; i < l;) {
  24886. var action = outline[i++];
  24887. switch (action) {
  24888. case 'm':
  24889. // moveTo
  24890. x = outline[i++] * scale + offsetX;
  24891. y = outline[i++] * scale + offsetY;
  24892. path.moveTo(x, y);
  24893. break;
  24894. case 'l':
  24895. // lineTo
  24896. x = outline[i++] * scale + offsetX;
  24897. y = outline[i++] * scale + offsetY;
  24898. path.lineTo(x, y);
  24899. break;
  24900. case 'q':
  24901. // quadraticCurveTo
  24902. cpx = outline[i++] * scale + offsetX;
  24903. cpy = outline[i++] * scale + offsetY;
  24904. cpx1 = outline[i++] * scale + offsetX;
  24905. cpy1 = outline[i++] * scale + offsetY;
  24906. path.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
  24907. break;
  24908. case 'b':
  24909. // bezierCurveTo
  24910. cpx = outline[i++] * scale + offsetX;
  24911. cpy = outline[i++] * scale + offsetY;
  24912. cpx1 = outline[i++] * scale + offsetX;
  24913. cpy1 = outline[i++] * scale + offsetY;
  24914. cpx2 = outline[i++] * scale + offsetX;
  24915. cpy2 = outline[i++] * scale + offsetY;
  24916. path.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
  24917. break;
  24918. }
  24919. }
  24920. }
  24921. return {
  24922. offsetX: glyph.ha * scale,
  24923. path: path
  24924. };
  24925. }
  24926. function FontLoader(manager) {
  24927. Loader.call(this, manager);
  24928. }
  24929. FontLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24930. constructor: FontLoader,
  24931. load: function load(url, onLoad, onProgress, onError) {
  24932. var scope = this;
  24933. var loader = new FileLoader(this.manager);
  24934. loader.setPath(this.path);
  24935. loader.setRequestHeader(this.requestHeader);
  24936. loader.setWithCredentials(scope.withCredentials);
  24937. loader.load(url, function (text) {
  24938. var json;
  24939. try {
  24940. json = JSON.parse(text);
  24941. } catch (e) {
  24942. console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');
  24943. json = JSON.parse(text.substring(65, text.length - 2));
  24944. }
  24945. var font = scope.parse(json);
  24946. if (onLoad) onLoad(font);
  24947. }, onProgress, onError);
  24948. },
  24949. parse: function parse(json) {
  24950. return new Font(json);
  24951. }
  24952. });
  24953. var _context;
  24954. var AudioContext = {
  24955. getContext: function getContext() {
  24956. if (_context === undefined) {
  24957. _context = new (window.AudioContext || window.webkitAudioContext)();
  24958. }
  24959. return _context;
  24960. },
  24961. setContext: function setContext(value) {
  24962. _context = value;
  24963. }
  24964. };
  24965. function AudioLoader(manager) {
  24966. Loader.call(this, manager);
  24967. }
  24968. AudioLoader.prototype = Object.assign(Object.create(Loader.prototype), {
  24969. constructor: AudioLoader,
  24970. load: function load(url, onLoad, onProgress, onError) {
  24971. var scope = this;
  24972. var loader = new FileLoader(scope.manager);
  24973. loader.setResponseType('arraybuffer');
  24974. loader.setPath(scope.path);
  24975. loader.setRequestHeader(scope.requestHeader);
  24976. loader.setWithCredentials(scope.withCredentials);
  24977. loader.load(url, function (buffer) {
  24978. try {
  24979. // Create a copy of the buffer. The `decodeAudioData` method
  24980. // detaches the buffer when complete, preventing reuse.
  24981. var bufferCopy = buffer.slice(0);
  24982. var context = AudioContext.getContext();
  24983. context.decodeAudioData(bufferCopy, function (audioBuffer) {
  24984. onLoad(audioBuffer);
  24985. });
  24986. } catch (e) {
  24987. if (onError) {
  24988. onError(e);
  24989. } else {
  24990. console.error(e);
  24991. }
  24992. scope.manager.itemError(url);
  24993. }
  24994. }, onProgress, onError);
  24995. }
  24996. });
  24997. function HemisphereLightProbe(skyColor, groundColor, intensity) {
  24998. LightProbe.call(this, undefined, intensity);
  24999. var color1 = new Color().set(skyColor);
  25000. var color2 = new Color().set(groundColor);
  25001. var sky = new Vector3(color1.r, color1.g, color1.b);
  25002. var ground = new Vector3(color2.r, color2.g, color2.b); // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25003. var c0 = Math.sqrt(Math.PI);
  25004. var c1 = c0 * Math.sqrt(0.75);
  25005. this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);
  25006. this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);
  25007. }
  25008. HemisphereLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25009. constructor: HemisphereLightProbe,
  25010. isHemisphereLightProbe: true,
  25011. copy: function copy(source) {
  25012. // modifying colors not currently supported
  25013. LightProbe.prototype.copy.call(this, source);
  25014. return this;
  25015. },
  25016. toJSON: function toJSON(meta) {
  25017. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25018. return data;
  25019. }
  25020. });
  25021. function AmbientLightProbe(color, intensity) {
  25022. LightProbe.call(this, undefined, intensity);
  25023. var color1 = new Color().set(color); // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25024. this.sh.coefficients[0].set(color1.r, color1.g, color1.b).multiplyScalar(2 * Math.sqrt(Math.PI));
  25025. }
  25026. AmbientLightProbe.prototype = Object.assign(Object.create(LightProbe.prototype), {
  25027. constructor: AmbientLightProbe,
  25028. isAmbientLightProbe: true,
  25029. copy: function copy(source) {
  25030. // modifying color not currently supported
  25031. LightProbe.prototype.copy.call(this, source);
  25032. return this;
  25033. },
  25034. toJSON: function toJSON(meta) {
  25035. var data = LightProbe.prototype.toJSON.call(this, meta); // data.sh = this.sh.toArray(); // todo
  25036. return data;
  25037. }
  25038. });
  25039. var _eyeRight = new Matrix4();
  25040. var _eyeLeft = new Matrix4();
  25041. function StereoCamera() {
  25042. this.type = 'StereoCamera';
  25043. this.aspect = 1;
  25044. this.eyeSep = 0.064;
  25045. this.cameraL = new PerspectiveCamera();
  25046. this.cameraL.layers.enable(1);
  25047. this.cameraL.matrixAutoUpdate = false;
  25048. this.cameraR = new PerspectiveCamera();
  25049. this.cameraR.layers.enable(2);
  25050. this.cameraR.matrixAutoUpdate = false;
  25051. this._cache = {
  25052. focus: null,
  25053. fov: null,
  25054. aspect: null,
  25055. near: null,
  25056. far: null,
  25057. zoom: null,
  25058. eyeSep: null
  25059. };
  25060. }
  25061. Object.assign(StereoCamera.prototype, {
  25062. update: function update(camera) {
  25063. var cache = this._cache;
  25064. 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;
  25065. if (needsUpdate) {
  25066. cache.focus = camera.focus;
  25067. cache.fov = camera.fov;
  25068. cache.aspect = camera.aspect * this.aspect;
  25069. cache.near = camera.near;
  25070. cache.far = camera.far;
  25071. cache.zoom = camera.zoom;
  25072. cache.eyeSep = this.eyeSep; // Off-axis stereoscopic effect based on
  25073. // http://paulbourke.net/stereographics/stereorender/
  25074. var projectionMatrix = camera.projectionMatrix.clone();
  25075. var eyeSepHalf = cache.eyeSep / 2;
  25076. var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25077. var ymax = cache.near * Math.tan(MathUtils.DEG2RAD * cache.fov * 0.5) / cache.zoom;
  25078. var xmin, xmax; // translate xOffset
  25079. _eyeLeft.elements[12] = -eyeSepHalf;
  25080. _eyeRight.elements[12] = eyeSepHalf; // for left eye
  25081. xmin = -ymax * cache.aspect + eyeSepOnProjection;
  25082. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25083. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25084. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25085. this.cameraL.projectionMatrix.copy(projectionMatrix); // for right eye
  25086. xmin = -ymax * cache.aspect - eyeSepOnProjection;
  25087. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25088. projectionMatrix.elements[0] = 2 * cache.near / (xmax - xmin);
  25089. projectionMatrix.elements[8] = (xmax + xmin) / (xmax - xmin);
  25090. this.cameraR.projectionMatrix.copy(projectionMatrix);
  25091. }
  25092. this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);
  25093. this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);
  25094. }
  25095. });
  25096. var Clock = /*#__PURE__*/function () {
  25097. function Clock(autoStart) {
  25098. this.autoStart = autoStart !== undefined ? autoStart : true;
  25099. this.startTime = 0;
  25100. this.oldTime = 0;
  25101. this.elapsedTime = 0;
  25102. this.running = false;
  25103. }
  25104. var _proto = Clock.prototype;
  25105. _proto.start = function start() {
  25106. this.startTime = now();
  25107. this.oldTime = this.startTime;
  25108. this.elapsedTime = 0;
  25109. this.running = true;
  25110. };
  25111. _proto.stop = function stop() {
  25112. this.getElapsedTime();
  25113. this.running = false;
  25114. this.autoStart = false;
  25115. };
  25116. _proto.getElapsedTime = function getElapsedTime() {
  25117. this.getDelta();
  25118. return this.elapsedTime;
  25119. };
  25120. _proto.getDelta = function getDelta() {
  25121. var diff = 0;
  25122. if (this.autoStart && !this.running) {
  25123. this.start();
  25124. return 0;
  25125. }
  25126. if (this.running) {
  25127. var newTime = now();
  25128. diff = (newTime - this.oldTime) / 1000;
  25129. this.oldTime = newTime;
  25130. this.elapsedTime += diff;
  25131. }
  25132. return diff;
  25133. };
  25134. return Clock;
  25135. }();
  25136. function now() {
  25137. return (typeof performance === 'undefined' ? Date : performance).now(); // see #10732
  25138. }
  25139. var _position$2 = /*@__PURE__*/new Vector3();
  25140. var _quaternion$3 = /*@__PURE__*/new Quaternion();
  25141. var _scale$1 = /*@__PURE__*/new Vector3();
  25142. var _orientation = /*@__PURE__*/new Vector3();
  25143. var AudioListener = /*#__PURE__*/function (_Object3D) {
  25144. _inheritsLoose(AudioListener, _Object3D);
  25145. function AudioListener() {
  25146. var _this;
  25147. _this = _Object3D.call(this) || this;
  25148. _this.type = 'AudioListener';
  25149. _this.context = AudioContext.getContext();
  25150. _this.gain = _this.context.createGain();
  25151. _this.gain.connect(_this.context.destination);
  25152. _this.filter = null;
  25153. _this.timeDelta = 0; // private
  25154. _this._clock = new Clock();
  25155. return _this;
  25156. }
  25157. var _proto = AudioListener.prototype;
  25158. _proto.getInput = function getInput() {
  25159. return this.gain;
  25160. };
  25161. _proto.removeFilter = function removeFilter() {
  25162. if (this.filter !== null) {
  25163. this.gain.disconnect(this.filter);
  25164. this.filter.disconnect(this.context.destination);
  25165. this.gain.connect(this.context.destination);
  25166. this.filter = null;
  25167. }
  25168. return this;
  25169. };
  25170. _proto.getFilter = function getFilter() {
  25171. return this.filter;
  25172. };
  25173. _proto.setFilter = function setFilter(value) {
  25174. if (this.filter !== null) {
  25175. this.gain.disconnect(this.filter);
  25176. this.filter.disconnect(this.context.destination);
  25177. } else {
  25178. this.gain.disconnect(this.context.destination);
  25179. }
  25180. this.filter = value;
  25181. this.gain.connect(this.filter);
  25182. this.filter.connect(this.context.destination);
  25183. return this;
  25184. };
  25185. _proto.getMasterVolume = function getMasterVolume() {
  25186. return this.gain.gain.value;
  25187. };
  25188. _proto.setMasterVolume = function setMasterVolume(value) {
  25189. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25190. return this;
  25191. };
  25192. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25193. _Object3D.prototype.updateMatrixWorld.call(this, force);
  25194. var listener = this.context.listener;
  25195. var up = this.up;
  25196. this.timeDelta = this._clock.getDelta();
  25197. this.matrixWorld.decompose(_position$2, _quaternion$3, _scale$1);
  25198. _orientation.set(0, 0, -1).applyQuaternion(_quaternion$3);
  25199. if (listener.positionX) {
  25200. // code path for Chrome (see #14393)
  25201. var endTime = this.context.currentTime + this.timeDelta;
  25202. listener.positionX.linearRampToValueAtTime(_position$2.x, endTime);
  25203. listener.positionY.linearRampToValueAtTime(_position$2.y, endTime);
  25204. listener.positionZ.linearRampToValueAtTime(_position$2.z, endTime);
  25205. listener.forwardX.linearRampToValueAtTime(_orientation.x, endTime);
  25206. listener.forwardY.linearRampToValueAtTime(_orientation.y, endTime);
  25207. listener.forwardZ.linearRampToValueAtTime(_orientation.z, endTime);
  25208. listener.upX.linearRampToValueAtTime(up.x, endTime);
  25209. listener.upY.linearRampToValueAtTime(up.y, endTime);
  25210. listener.upZ.linearRampToValueAtTime(up.z, endTime);
  25211. } else {
  25212. listener.setPosition(_position$2.x, _position$2.y, _position$2.z);
  25213. listener.setOrientation(_orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z);
  25214. }
  25215. };
  25216. return AudioListener;
  25217. }(Object3D);
  25218. var Audio = /*#__PURE__*/function (_Object3D) {
  25219. _inheritsLoose(Audio, _Object3D);
  25220. function Audio(listener) {
  25221. var _this;
  25222. _this = _Object3D.call(this) || this;
  25223. _this.type = 'Audio';
  25224. _this.listener = listener;
  25225. _this.context = listener.context;
  25226. _this.gain = _this.context.createGain();
  25227. _this.gain.connect(listener.getInput());
  25228. _this.autoplay = false;
  25229. _this.buffer = null;
  25230. _this.detune = 0;
  25231. _this.loop = false;
  25232. _this.loopStart = 0;
  25233. _this.loopEnd = 0;
  25234. _this.offset = 0;
  25235. _this.duration = undefined;
  25236. _this.playbackRate = 1;
  25237. _this.isPlaying = false;
  25238. _this.hasPlaybackControl = true;
  25239. _this.source = null;
  25240. _this.sourceType = 'empty';
  25241. _this._startedAt = 0;
  25242. _this._progress = 0;
  25243. _this._connected = false;
  25244. _this.filters = [];
  25245. return _this;
  25246. }
  25247. var _proto = Audio.prototype;
  25248. _proto.getOutput = function getOutput() {
  25249. return this.gain;
  25250. };
  25251. _proto.setNodeSource = function setNodeSource(audioNode) {
  25252. this.hasPlaybackControl = false;
  25253. this.sourceType = 'audioNode';
  25254. this.source = audioNode;
  25255. this.connect();
  25256. return this;
  25257. };
  25258. _proto.setMediaElementSource = function setMediaElementSource(mediaElement) {
  25259. this.hasPlaybackControl = false;
  25260. this.sourceType = 'mediaNode';
  25261. this.source = this.context.createMediaElementSource(mediaElement);
  25262. this.connect();
  25263. return this;
  25264. };
  25265. _proto.setMediaStreamSource = function setMediaStreamSource(mediaStream) {
  25266. this.hasPlaybackControl = false;
  25267. this.sourceType = 'mediaStreamNode';
  25268. this.source = this.context.createMediaStreamSource(mediaStream);
  25269. this.connect();
  25270. return this;
  25271. };
  25272. _proto.setBuffer = function setBuffer(audioBuffer) {
  25273. this.buffer = audioBuffer;
  25274. this.sourceType = 'buffer';
  25275. if (this.autoplay) this.play();
  25276. return this;
  25277. };
  25278. _proto.play = function play(delay) {
  25279. if (delay === void 0) {
  25280. delay = 0;
  25281. }
  25282. if (this.isPlaying === true) {
  25283. console.warn('THREE.Audio: Audio is already playing.');
  25284. return;
  25285. }
  25286. if (this.hasPlaybackControl === false) {
  25287. console.warn('THREE.Audio: this Audio has no playback control.');
  25288. return;
  25289. }
  25290. this._startedAt = this.context.currentTime + delay;
  25291. var source = this.context.createBufferSource();
  25292. source.buffer = this.buffer;
  25293. source.loop = this.loop;
  25294. source.loopStart = this.loopStart;
  25295. source.loopEnd = this.loopEnd;
  25296. source.onended = this.onEnded.bind(this);
  25297. source.start(this._startedAt, this._progress + this.offset, this.duration);
  25298. this.isPlaying = true;
  25299. this.source = source;
  25300. this.setDetune(this.detune);
  25301. this.setPlaybackRate(this.playbackRate);
  25302. return this.connect();
  25303. };
  25304. _proto.pause = function pause() {
  25305. if (this.hasPlaybackControl === false) {
  25306. console.warn('THREE.Audio: this Audio has no playback control.');
  25307. return;
  25308. }
  25309. if (this.isPlaying === true) {
  25310. // update current progress
  25311. this._progress += Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
  25312. if (this.loop === true) {
  25313. // ensure _progress does not exceed duration with looped audios
  25314. this._progress = this._progress % (this.duration || this.buffer.duration);
  25315. }
  25316. this.source.stop();
  25317. this.source.onended = null;
  25318. this.isPlaying = false;
  25319. }
  25320. return this;
  25321. };
  25322. _proto.stop = function stop() {
  25323. if (this.hasPlaybackControl === false) {
  25324. console.warn('THREE.Audio: this Audio has no playback control.');
  25325. return;
  25326. }
  25327. this._progress = 0;
  25328. this.source.stop();
  25329. this.source.onended = null;
  25330. this.isPlaying = false;
  25331. return this;
  25332. };
  25333. _proto.connect = function connect() {
  25334. if (this.filters.length > 0) {
  25335. this.source.connect(this.filters[0]);
  25336. for (var i = 1, l = this.filters.length; i < l; i++) {
  25337. this.filters[i - 1].connect(this.filters[i]);
  25338. }
  25339. this.filters[this.filters.length - 1].connect(this.getOutput());
  25340. } else {
  25341. this.source.connect(this.getOutput());
  25342. }
  25343. this._connected = true;
  25344. return this;
  25345. };
  25346. _proto.disconnect = function disconnect() {
  25347. if (this.filters.length > 0) {
  25348. this.source.disconnect(this.filters[0]);
  25349. for (var i = 1, l = this.filters.length; i < l; i++) {
  25350. this.filters[i - 1].disconnect(this.filters[i]);
  25351. }
  25352. this.filters[this.filters.length - 1].disconnect(this.getOutput());
  25353. } else {
  25354. this.source.disconnect(this.getOutput());
  25355. }
  25356. this._connected = false;
  25357. return this;
  25358. };
  25359. _proto.getFilters = function getFilters() {
  25360. return this.filters;
  25361. };
  25362. _proto.setFilters = function setFilters(value) {
  25363. if (!value) value = [];
  25364. if (this._connected === true) {
  25365. this.disconnect();
  25366. this.filters = value.slice();
  25367. this.connect();
  25368. } else {
  25369. this.filters = value.slice();
  25370. }
  25371. return this;
  25372. };
  25373. _proto.setDetune = function setDetune(value) {
  25374. this.detune = value;
  25375. if (this.source.detune === undefined) return; // only set detune when available
  25376. if (this.isPlaying === true) {
  25377. this.source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
  25378. }
  25379. return this;
  25380. };
  25381. _proto.getDetune = function getDetune() {
  25382. return this.detune;
  25383. };
  25384. _proto.getFilter = function getFilter() {
  25385. return this.getFilters()[0];
  25386. };
  25387. _proto.setFilter = function setFilter(filter) {
  25388. return this.setFilters(filter ? [filter] : []);
  25389. };
  25390. _proto.setPlaybackRate = function setPlaybackRate(value) {
  25391. if (this.hasPlaybackControl === false) {
  25392. console.warn('THREE.Audio: this Audio has no playback control.');
  25393. return;
  25394. }
  25395. this.playbackRate = value;
  25396. if (this.isPlaying === true) {
  25397. this.source.playbackRate.setTargetAtTime(this.playbackRate, this.context.currentTime, 0.01);
  25398. }
  25399. return this;
  25400. };
  25401. _proto.getPlaybackRate = function getPlaybackRate() {
  25402. return this.playbackRate;
  25403. };
  25404. _proto.onEnded = function onEnded() {
  25405. this.isPlaying = false;
  25406. };
  25407. _proto.getLoop = function getLoop() {
  25408. if (this.hasPlaybackControl === false) {
  25409. console.warn('THREE.Audio: this Audio has no playback control.');
  25410. return false;
  25411. }
  25412. return this.loop;
  25413. };
  25414. _proto.setLoop = function setLoop(value) {
  25415. if (this.hasPlaybackControl === false) {
  25416. console.warn('THREE.Audio: this Audio has no playback control.');
  25417. return;
  25418. }
  25419. this.loop = value;
  25420. if (this.isPlaying === true) {
  25421. this.source.loop = this.loop;
  25422. }
  25423. return this;
  25424. };
  25425. _proto.setLoopStart = function setLoopStart(value) {
  25426. this.loopStart = value;
  25427. return this;
  25428. };
  25429. _proto.setLoopEnd = function setLoopEnd(value) {
  25430. this.loopEnd = value;
  25431. return this;
  25432. };
  25433. _proto.getVolume = function getVolume() {
  25434. return this.gain.gain.value;
  25435. };
  25436. _proto.setVolume = function setVolume(value) {
  25437. this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
  25438. return this;
  25439. };
  25440. return Audio;
  25441. }(Object3D);
  25442. var _position$3 = /*@__PURE__*/new Vector3();
  25443. var _quaternion$4 = /*@__PURE__*/new Quaternion();
  25444. var _scale$2 = /*@__PURE__*/new Vector3();
  25445. var _orientation$1 = /*@__PURE__*/new Vector3();
  25446. var PositionalAudio = /*#__PURE__*/function (_Audio) {
  25447. _inheritsLoose(PositionalAudio, _Audio);
  25448. function PositionalAudio(listener) {
  25449. var _this;
  25450. _this = _Audio.call(this, listener) || this;
  25451. _this.panner = _this.context.createPanner();
  25452. _this.panner.panningModel = 'HRTF';
  25453. _this.panner.connect(_this.gain);
  25454. return _this;
  25455. }
  25456. var _proto = PositionalAudio.prototype;
  25457. _proto.getOutput = function getOutput() {
  25458. return this.panner;
  25459. };
  25460. _proto.getRefDistance = function getRefDistance() {
  25461. return this.panner.refDistance;
  25462. };
  25463. _proto.setRefDistance = function setRefDistance(value) {
  25464. this.panner.refDistance = value;
  25465. return this;
  25466. };
  25467. _proto.getRolloffFactor = function getRolloffFactor() {
  25468. return this.panner.rolloffFactor;
  25469. };
  25470. _proto.setRolloffFactor = function setRolloffFactor(value) {
  25471. this.panner.rolloffFactor = value;
  25472. return this;
  25473. };
  25474. _proto.getDistanceModel = function getDistanceModel() {
  25475. return this.panner.distanceModel;
  25476. };
  25477. _proto.setDistanceModel = function setDistanceModel(value) {
  25478. this.panner.distanceModel = value;
  25479. return this;
  25480. };
  25481. _proto.getMaxDistance = function getMaxDistance() {
  25482. return this.panner.maxDistance;
  25483. };
  25484. _proto.setMaxDistance = function setMaxDistance(value) {
  25485. this.panner.maxDistance = value;
  25486. return this;
  25487. };
  25488. _proto.setDirectionalCone = function setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
  25489. this.panner.coneInnerAngle = coneInnerAngle;
  25490. this.panner.coneOuterAngle = coneOuterAngle;
  25491. this.panner.coneOuterGain = coneOuterGain;
  25492. return this;
  25493. };
  25494. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  25495. _Audio.prototype.updateMatrixWorld.call(this, force);
  25496. if (this.hasPlaybackControl === true && this.isPlaying === false) return;
  25497. this.matrixWorld.decompose(_position$3, _quaternion$4, _scale$2);
  25498. _orientation$1.set(0, 0, 1).applyQuaternion(_quaternion$4);
  25499. var panner = this.panner;
  25500. if (panner.positionX) {
  25501. // code path for Chrome and Firefox (see #14393)
  25502. var endTime = this.context.currentTime + this.listener.timeDelta;
  25503. panner.positionX.linearRampToValueAtTime(_position$3.x, endTime);
  25504. panner.positionY.linearRampToValueAtTime(_position$3.y, endTime);
  25505. panner.positionZ.linearRampToValueAtTime(_position$3.z, endTime);
  25506. panner.orientationX.linearRampToValueAtTime(_orientation$1.x, endTime);
  25507. panner.orientationY.linearRampToValueAtTime(_orientation$1.y, endTime);
  25508. panner.orientationZ.linearRampToValueAtTime(_orientation$1.z, endTime);
  25509. } else {
  25510. panner.setPosition(_position$3.x, _position$3.y, _position$3.z);
  25511. panner.setOrientation(_orientation$1.x, _orientation$1.y, _orientation$1.z);
  25512. }
  25513. };
  25514. return PositionalAudio;
  25515. }(Audio);
  25516. var AudioAnalyser = /*#__PURE__*/function () {
  25517. function AudioAnalyser(audio, fftSize) {
  25518. if (fftSize === void 0) {
  25519. fftSize = 2048;
  25520. }
  25521. this.analyser = audio.context.createAnalyser();
  25522. this.analyser.fftSize = fftSize;
  25523. this.data = new Uint8Array(this.analyser.frequencyBinCount);
  25524. audio.getOutput().connect(this.analyser);
  25525. }
  25526. var _proto = AudioAnalyser.prototype;
  25527. _proto.getFrequencyData = function getFrequencyData() {
  25528. this.analyser.getByteFrequencyData(this.data);
  25529. return this.data;
  25530. };
  25531. _proto.getAverageFrequency = function getAverageFrequency() {
  25532. var value = 0;
  25533. var data = this.getFrequencyData();
  25534. for (var i = 0; i < data.length; i++) {
  25535. value += data[i];
  25536. }
  25537. return value / data.length;
  25538. };
  25539. return AudioAnalyser;
  25540. }();
  25541. function PropertyMixer(binding, typeName, valueSize) {
  25542. this.binding = binding;
  25543. this.valueSize = valueSize;
  25544. var mixFunction, mixFunctionAdditive, setIdentity; // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25545. //
  25546. // interpolators can use .buffer as their .result
  25547. // the data then goes to 'incoming'
  25548. //
  25549. // 'accu0' and 'accu1' are used frame-interleaved for
  25550. // the cumulative result and are compared to detect
  25551. // changes
  25552. //
  25553. // 'orig' stores the original state of the property
  25554. //
  25555. // 'add' is used for additive cumulative results
  25556. //
  25557. // 'work' is optional and is only present for quaternion types. It is used
  25558. // to store intermediate quaternion multiplication results
  25559. switch (typeName) {
  25560. case 'quaternion':
  25561. mixFunction = this._slerp;
  25562. mixFunctionAdditive = this._slerpAdditive;
  25563. setIdentity = this._setAdditiveIdentityQuaternion;
  25564. this.buffer = new Float64Array(valueSize * 6);
  25565. this._workIndex = 5;
  25566. break;
  25567. case 'string':
  25568. case 'bool':
  25569. mixFunction = this._select; // Use the regular mix function and for additive on these types,
  25570. // additive is not relevant for non-numeric types
  25571. mixFunctionAdditive = this._select;
  25572. setIdentity = this._setAdditiveIdentityOther;
  25573. this.buffer = new Array(valueSize * 5);
  25574. break;
  25575. default:
  25576. mixFunction = this._lerp;
  25577. mixFunctionAdditive = this._lerpAdditive;
  25578. setIdentity = this._setAdditiveIdentityNumeric;
  25579. this.buffer = new Float64Array(valueSize * 5);
  25580. }
  25581. this._mixBufferRegion = mixFunction;
  25582. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25583. this._setIdentity = setIdentity;
  25584. this._origIndex = 3;
  25585. this._addIndex = 4;
  25586. this.cumulativeWeight = 0;
  25587. this.cumulativeWeightAdditive = 0;
  25588. this.useCount = 0;
  25589. this.referenceCount = 0;
  25590. }
  25591. Object.assign(PropertyMixer.prototype, {
  25592. // accumulate data in the 'incoming' region into 'accu<i>'
  25593. accumulate: function accumulate(accuIndex, weight) {
  25594. // note: happily accumulating nothing when weight = 0, the caller knows
  25595. // the weight and shouldn't have made the call in the first place
  25596. var buffer = this.buffer,
  25597. stride = this.valueSize,
  25598. offset = accuIndex * stride + stride;
  25599. var currentWeight = this.cumulativeWeight;
  25600. if (currentWeight === 0) {
  25601. // accuN := incoming * weight
  25602. for (var i = 0; i !== stride; ++i) {
  25603. buffer[offset + i] = buffer[i];
  25604. }
  25605. currentWeight = weight;
  25606. } else {
  25607. // accuN := accuN + incoming * weight
  25608. currentWeight += weight;
  25609. var mix = weight / currentWeight;
  25610. this._mixBufferRegion(buffer, offset, 0, mix, stride);
  25611. }
  25612. this.cumulativeWeight = currentWeight;
  25613. },
  25614. // accumulate data in the 'incoming' region into 'add'
  25615. accumulateAdditive: function accumulateAdditive(weight) {
  25616. var buffer = this.buffer,
  25617. stride = this.valueSize,
  25618. offset = stride * this._addIndex;
  25619. if (this.cumulativeWeightAdditive === 0) {
  25620. // add = identity
  25621. this._setIdentity();
  25622. } // add := add + incoming * weight
  25623. this._mixBufferRegionAdditive(buffer, offset, 0, weight, stride);
  25624. this.cumulativeWeightAdditive += weight;
  25625. },
  25626. // apply the state of 'accu<i>' to the binding when accus differ
  25627. apply: function apply(accuIndex) {
  25628. var stride = this.valueSize,
  25629. buffer = this.buffer,
  25630. offset = accuIndex * stride + stride,
  25631. weight = this.cumulativeWeight,
  25632. weightAdditive = this.cumulativeWeightAdditive,
  25633. binding = this.binding;
  25634. this.cumulativeWeight = 0;
  25635. this.cumulativeWeightAdditive = 0;
  25636. if (weight < 1) {
  25637. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25638. var originalValueOffset = stride * this._origIndex;
  25639. this._mixBufferRegion(buffer, offset, originalValueOffset, 1 - weight, stride);
  25640. }
  25641. if (weightAdditive > 0) {
  25642. // accuN := accuN + additive accuN
  25643. this._mixBufferRegionAdditive(buffer, offset, this._addIndex * stride, 1, stride);
  25644. }
  25645. for (var i = stride, e = stride + stride; i !== e; ++i) {
  25646. if (buffer[i] !== buffer[i + stride]) {
  25647. // value has changed -> update scene graph
  25648. binding.setValue(buffer, offset);
  25649. break;
  25650. }
  25651. }
  25652. },
  25653. // remember the state of the bound property and copy it to both accus
  25654. saveOriginalState: function saveOriginalState() {
  25655. var binding = this.binding;
  25656. var buffer = this.buffer,
  25657. stride = this.valueSize,
  25658. originalValueOffset = stride * this._origIndex;
  25659. binding.getValue(buffer, originalValueOffset); // accu[0..1] := orig -- initially detect changes against the original
  25660. for (var i = stride, e = originalValueOffset; i !== e; ++i) {
  25661. buffer[i] = buffer[originalValueOffset + i % stride];
  25662. } // Add to identity for additive
  25663. this._setIdentity();
  25664. this.cumulativeWeight = 0;
  25665. this.cumulativeWeightAdditive = 0;
  25666. },
  25667. // apply the state previously taken via 'saveOriginalState' to the binding
  25668. restoreOriginalState: function restoreOriginalState() {
  25669. var originalValueOffset = this.valueSize * 3;
  25670. this.binding.setValue(this.buffer, originalValueOffset);
  25671. },
  25672. _setAdditiveIdentityNumeric: function _setAdditiveIdentityNumeric() {
  25673. var startIndex = this._addIndex * this.valueSize;
  25674. var endIndex = startIndex + this.valueSize;
  25675. for (var i = startIndex; i < endIndex; i++) {
  25676. this.buffer[i] = 0;
  25677. }
  25678. },
  25679. _setAdditiveIdentityQuaternion: function _setAdditiveIdentityQuaternion() {
  25680. this._setAdditiveIdentityNumeric();
  25681. this.buffer[this._addIndex * this.valueSize + 3] = 1;
  25682. },
  25683. _setAdditiveIdentityOther: function _setAdditiveIdentityOther() {
  25684. var startIndex = this._origIndex * this.valueSize;
  25685. var targetIndex = this._addIndex * this.valueSize;
  25686. for (var i = 0; i < this.valueSize; i++) {
  25687. this.buffer[targetIndex + i] = this.buffer[startIndex + i];
  25688. }
  25689. },
  25690. // mix functions
  25691. _select: function _select(buffer, dstOffset, srcOffset, t, stride) {
  25692. if (t >= 0.5) {
  25693. for (var i = 0; i !== stride; ++i) {
  25694. buffer[dstOffset + i] = buffer[srcOffset + i];
  25695. }
  25696. }
  25697. },
  25698. _slerp: function _slerp(buffer, dstOffset, srcOffset, t) {
  25699. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t);
  25700. },
  25701. _slerpAdditive: function _slerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25702. var workOffset = this._workIndex * stride; // Store result in intermediate buffer offset
  25703. Quaternion.multiplyQuaternionsFlat(buffer, workOffset, buffer, dstOffset, buffer, srcOffset); // Slerp to the intermediate result
  25704. Quaternion.slerpFlat(buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t);
  25705. },
  25706. _lerp: function _lerp(buffer, dstOffset, srcOffset, t, stride) {
  25707. var s = 1 - t;
  25708. for (var i = 0; i !== stride; ++i) {
  25709. var j = dstOffset + i;
  25710. buffer[j] = buffer[j] * s + buffer[srcOffset + i] * t;
  25711. }
  25712. },
  25713. _lerpAdditive: function _lerpAdditive(buffer, dstOffset, srcOffset, t, stride) {
  25714. for (var i = 0; i !== stride; ++i) {
  25715. var j = dstOffset + i;
  25716. buffer[j] = buffer[j] + buffer[srcOffset + i] * t;
  25717. }
  25718. }
  25719. });
  25720. // Characters [].:/ are reserved for track binding syntax.
  25721. var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25722. var _reservedRe = new RegExp('[' + _RESERVED_CHARS_RE + ']', 'g'); // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25723. // only latin characters, and the unicode \p{L} is not yet supported. So
  25724. // instead, we exclude reserved characters and match everything else.
  25725. var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  25726. var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace('\\.', '') + ']'; // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25727. // be matched to parse the rest of the track name.
  25728. var _directoryRe = /((?:WC+[\/:])*)/.source.replace('WC', _wordChar); // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25729. var _nodeRe = /(WCOD+)?/.source.replace('WCOD', _wordCharOrDot); // Object on target node, and accessor. May not contain reserved
  25730. // characters. Accessor may contain any character except closing bracket.
  25731. var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC', _wordChar); // Property and accessor. May not contain reserved characters. Accessor may
  25732. // contain any non-bracket characters.
  25733. var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace('WC', _wordChar);
  25734. var _trackRe = new RegExp('' + '^' + _directoryRe + _nodeRe + _objectRe + _propertyRe + '$');
  25735. var _supportedObjectNames = ['material', 'materials', 'bones'];
  25736. function Composite(targetGroup, path, optionalParsedPath) {
  25737. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path);
  25738. this._targetGroup = targetGroup;
  25739. this._bindings = targetGroup.subscribe_(path, parsedPath);
  25740. }
  25741. Object.assign(Composite.prototype, {
  25742. getValue: function getValue(array, offset) {
  25743. this.bind(); // bind all binding
  25744. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25745. binding = this._bindings[firstValidIndex]; // and only call .getValue on the first
  25746. if (binding !== undefined) binding.getValue(array, offset);
  25747. },
  25748. setValue: function setValue(array, offset) {
  25749. var bindings = this._bindings;
  25750. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25751. bindings[i].setValue(array, offset);
  25752. }
  25753. },
  25754. bind: function bind() {
  25755. var bindings = this._bindings;
  25756. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25757. bindings[i].bind();
  25758. }
  25759. },
  25760. unbind: function unbind() {
  25761. var bindings = this._bindings;
  25762. for (var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) {
  25763. bindings[i].unbind();
  25764. }
  25765. }
  25766. });
  25767. function PropertyBinding(rootNode, path, parsedPath) {
  25768. this.path = path;
  25769. this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path);
  25770. this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName) || rootNode;
  25771. this.rootNode = rootNode;
  25772. }
  25773. Object.assign(PropertyBinding, {
  25774. Composite: Composite,
  25775. create: function create(root, path, parsedPath) {
  25776. if (!(root && root.isAnimationObjectGroup)) {
  25777. return new PropertyBinding(root, path, parsedPath);
  25778. } else {
  25779. return new PropertyBinding.Composite(root, path, parsedPath);
  25780. }
  25781. },
  25782. /**
  25783. * Replaces spaces with underscores and removes unsupported characters from
  25784. * node names, to ensure compatibility with parseTrackName().
  25785. *
  25786. * @param {string} name Node name to be sanitized.
  25787. * @return {string}
  25788. */
  25789. sanitizeNodeName: function sanitizeNodeName(name) {
  25790. return name.replace(/\s/g, '_').replace(_reservedRe, '');
  25791. },
  25792. parseTrackName: function parseTrackName(trackName) {
  25793. var matches = _trackRe.exec(trackName);
  25794. if (!matches) {
  25795. throw new Error('PropertyBinding: Cannot parse trackName: ' + trackName);
  25796. }
  25797. var results = {
  25798. // directoryName: matches[ 1 ], // (tschw) currently unused
  25799. nodeName: matches[2],
  25800. objectName: matches[3],
  25801. objectIndex: matches[4],
  25802. propertyName: matches[5],
  25803. // required
  25804. propertyIndex: matches[6]
  25805. };
  25806. var lastDot = results.nodeName && results.nodeName.lastIndexOf('.');
  25807. if (lastDot !== undefined && lastDot !== -1) {
  25808. var objectName = results.nodeName.substring(lastDot + 1); // Object names must be checked against an allowlist. Otherwise, there
  25809. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25810. // 'bar' could be the objectName, or part of a nodeName (which can
  25811. // include '.' characters).
  25812. if (_supportedObjectNames.indexOf(objectName) !== -1) {
  25813. results.nodeName = results.nodeName.substring(0, lastDot);
  25814. results.objectName = objectName;
  25815. }
  25816. }
  25817. if (results.propertyName === null || results.propertyName.length === 0) {
  25818. throw new Error('PropertyBinding: can not parse propertyName from trackName: ' + trackName);
  25819. }
  25820. return results;
  25821. },
  25822. findNode: function findNode(root, nodeName) {
  25823. if (!nodeName || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) {
  25824. return root;
  25825. } // search into skeleton bones.
  25826. if (root.skeleton) {
  25827. var bone = root.skeleton.getBoneByName(nodeName);
  25828. if (bone !== undefined) {
  25829. return bone;
  25830. }
  25831. } // search into node subtree.
  25832. if (root.children) {
  25833. var searchNodeSubtree = function searchNodeSubtree(children) {
  25834. for (var i = 0; i < children.length; i++) {
  25835. var childNode = children[i];
  25836. if (childNode.name === nodeName || childNode.uuid === nodeName) {
  25837. return childNode;
  25838. }
  25839. var result = searchNodeSubtree(childNode.children);
  25840. if (result) return result;
  25841. }
  25842. return null;
  25843. };
  25844. var subTreeNode = searchNodeSubtree(root.children);
  25845. if (subTreeNode) {
  25846. return subTreeNode;
  25847. }
  25848. }
  25849. return null;
  25850. }
  25851. });
  25852. Object.assign(PropertyBinding.prototype, {
  25853. // prototype, continued
  25854. // these are used to "bind" a nonexistent property
  25855. _getValue_unavailable: function _getValue_unavailable() {},
  25856. _setValue_unavailable: function _setValue_unavailable() {},
  25857. BindingType: {
  25858. Direct: 0,
  25859. EntireArray: 1,
  25860. ArrayElement: 2,
  25861. HasFromToArray: 3
  25862. },
  25863. Versioning: {
  25864. None: 0,
  25865. NeedsUpdate: 1,
  25866. MatrixWorldNeedsUpdate: 2
  25867. },
  25868. GetterByBindingType: [function getValue_direct(buffer, offset) {
  25869. buffer[offset] = this.node[this.propertyName];
  25870. }, function getValue_array(buffer, offset) {
  25871. var source = this.resolvedProperty;
  25872. for (var i = 0, n = source.length; i !== n; ++i) {
  25873. buffer[offset++] = source[i];
  25874. }
  25875. }, function getValue_arrayElement(buffer, offset) {
  25876. buffer[offset] = this.resolvedProperty[this.propertyIndex];
  25877. }, function getValue_toArray(buffer, offset) {
  25878. this.resolvedProperty.toArray(buffer, offset);
  25879. }],
  25880. SetterByBindingTypeAndVersioning: [[// Direct
  25881. function setValue_direct(buffer, offset) {
  25882. this.targetObject[this.propertyName] = buffer[offset];
  25883. }, function setValue_direct_setNeedsUpdate(buffer, offset) {
  25884. this.targetObject[this.propertyName] = buffer[offset];
  25885. this.targetObject.needsUpdate = true;
  25886. }, function setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) {
  25887. this.targetObject[this.propertyName] = buffer[offset];
  25888. this.targetObject.matrixWorldNeedsUpdate = true;
  25889. }], [// EntireArray
  25890. function setValue_array(buffer, offset) {
  25891. var dest = this.resolvedProperty;
  25892. for (var i = 0, n = dest.length; i !== n; ++i) {
  25893. dest[i] = buffer[offset++];
  25894. }
  25895. }, function setValue_array_setNeedsUpdate(buffer, offset) {
  25896. var dest = this.resolvedProperty;
  25897. for (var i = 0, n = dest.length; i !== n; ++i) {
  25898. dest[i] = buffer[offset++];
  25899. }
  25900. this.targetObject.needsUpdate = true;
  25901. }, function setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) {
  25902. var dest = this.resolvedProperty;
  25903. for (var i = 0, n = dest.length; i !== n; ++i) {
  25904. dest[i] = buffer[offset++];
  25905. }
  25906. this.targetObject.matrixWorldNeedsUpdate = true;
  25907. }], [// ArrayElement
  25908. function setValue_arrayElement(buffer, offset) {
  25909. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25910. }, function setValue_arrayElement_setNeedsUpdate(buffer, offset) {
  25911. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25912. this.targetObject.needsUpdate = true;
  25913. }, function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) {
  25914. this.resolvedProperty[this.propertyIndex] = buffer[offset];
  25915. this.targetObject.matrixWorldNeedsUpdate = true;
  25916. }], [// HasToFromArray
  25917. function setValue_fromArray(buffer, offset) {
  25918. this.resolvedProperty.fromArray(buffer, offset);
  25919. }, function setValue_fromArray_setNeedsUpdate(buffer, offset) {
  25920. this.resolvedProperty.fromArray(buffer, offset);
  25921. this.targetObject.needsUpdate = true;
  25922. }, function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) {
  25923. this.resolvedProperty.fromArray(buffer, offset);
  25924. this.targetObject.matrixWorldNeedsUpdate = true;
  25925. }]],
  25926. getValue: function getValue_unbound(targetArray, offset) {
  25927. this.bind();
  25928. this.getValue(targetArray, offset); // Note: This class uses a State pattern on a per-method basis:
  25929. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25930. // prototype version of these methods with one that represents
  25931. // the bound state. When the property is not found, the methods
  25932. // become no-ops.
  25933. },
  25934. setValue: function getValue_unbound(sourceArray, offset) {
  25935. this.bind();
  25936. this.setValue(sourceArray, offset);
  25937. },
  25938. // create getter / setter pair for a property in the scene graph
  25939. bind: function bind() {
  25940. var targetObject = this.node;
  25941. var parsedPath = this.parsedPath;
  25942. var objectName = parsedPath.objectName;
  25943. var propertyName = parsedPath.propertyName;
  25944. var propertyIndex = parsedPath.propertyIndex;
  25945. if (!targetObject) {
  25946. targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName) || this.rootNode;
  25947. this.node = targetObject;
  25948. } // set fail state so we can just 'return' on error
  25949. this.getValue = this._getValue_unavailable;
  25950. this.setValue = this._setValue_unavailable; // ensure there is a value node
  25951. if (!targetObject) {
  25952. console.error('THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.');
  25953. return;
  25954. }
  25955. if (objectName) {
  25956. var objectIndex = parsedPath.objectIndex; // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25957. switch (objectName) {
  25958. case 'materials':
  25959. if (!targetObject.material) {
  25960. console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.', this);
  25961. return;
  25962. }
  25963. if (!targetObject.material.materials) {
  25964. console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this);
  25965. return;
  25966. }
  25967. targetObject = targetObject.material.materials;
  25968. break;
  25969. case 'bones':
  25970. if (!targetObject.skeleton) {
  25971. console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this);
  25972. return;
  25973. } // potential future optimization: skip this if propertyIndex is already an integer
  25974. // and convert the integer string to a true integer.
  25975. targetObject = targetObject.skeleton.bones; // support resolving morphTarget names into indices.
  25976. for (var i = 0; i < targetObject.length; i++) {
  25977. if (targetObject[i].name === objectIndex) {
  25978. objectIndex = i;
  25979. break;
  25980. }
  25981. }
  25982. break;
  25983. default:
  25984. if (targetObject[objectName] === undefined) {
  25985. console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.', this);
  25986. return;
  25987. }
  25988. targetObject = targetObject[objectName];
  25989. }
  25990. if (objectIndex !== undefined) {
  25991. if (targetObject[objectIndex] === undefined) {
  25992. console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject);
  25993. return;
  25994. }
  25995. targetObject = targetObject[objectIndex];
  25996. }
  25997. } // resolve property
  25998. var nodeProperty = targetObject[propertyName];
  25999. if (nodeProperty === undefined) {
  26000. var nodeName = parsedPath.nodeName;
  26001. console.error('THREE.PropertyBinding: Trying to update property for track: ' + nodeName + '.' + propertyName + ' but it wasn\'t found.', targetObject);
  26002. return;
  26003. } // determine versioning scheme
  26004. var versioning = this.Versioning.None;
  26005. this.targetObject = targetObject;
  26006. if (targetObject.needsUpdate !== undefined) {
  26007. // material
  26008. versioning = this.Versioning.NeedsUpdate;
  26009. } else if (targetObject.matrixWorldNeedsUpdate !== undefined) {
  26010. // node transform
  26011. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26012. } // determine how the property gets bound
  26013. var bindingType = this.BindingType.Direct;
  26014. if (propertyIndex !== undefined) {
  26015. // access a sub element of the property array (only primitives are supported right now)
  26016. if (propertyName === 'morphTargetInfluences') {
  26017. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26018. // support resolving morphTarget names into indices.
  26019. if (!targetObject.geometry) {
  26020. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this);
  26021. return;
  26022. }
  26023. if (targetObject.geometry.isBufferGeometry) {
  26024. if (!targetObject.geometry.morphAttributes) {
  26025. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this);
  26026. return;
  26027. }
  26028. if (targetObject.morphTargetDictionary[propertyIndex] !== undefined) {
  26029. propertyIndex = targetObject.morphTargetDictionary[propertyIndex];
  26030. }
  26031. } else {
  26032. console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this);
  26033. return;
  26034. }
  26035. }
  26036. bindingType = this.BindingType.ArrayElement;
  26037. this.resolvedProperty = nodeProperty;
  26038. this.propertyIndex = propertyIndex;
  26039. } else if (nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined) {
  26040. // must use copy for Object3D.Euler/Quaternion
  26041. bindingType = this.BindingType.HasFromToArray;
  26042. this.resolvedProperty = nodeProperty;
  26043. } else if (Array.isArray(nodeProperty)) {
  26044. bindingType = this.BindingType.EntireArray;
  26045. this.resolvedProperty = nodeProperty;
  26046. } else {
  26047. this.propertyName = propertyName;
  26048. } // select getter / setter
  26049. this.getValue = this.GetterByBindingType[bindingType];
  26050. this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning];
  26051. },
  26052. unbind: function unbind() {
  26053. this.node = null; // back to the prototype version of getValue / setValue
  26054. // note: avoiding to mutate the shape of 'this' via 'delete'
  26055. this.getValue = this._getValue_unbound;
  26056. this.setValue = this._setValue_unbound;
  26057. }
  26058. }); // DECLARE ALIAS AFTER assign prototype
  26059. Object.assign(PropertyBinding.prototype, {
  26060. // initial state of these methods that calls 'bind'
  26061. _getValue_unbound: PropertyBinding.prototype.getValue,
  26062. _setValue_unbound: PropertyBinding.prototype.setValue
  26063. });
  26064. /**
  26065. *
  26066. * A group of objects that receives a shared animation state.
  26067. *
  26068. * Usage:
  26069. *
  26070. * - Add objects you would otherwise pass as 'root' to the
  26071. * constructor or the .clipAction method of AnimationMixer.
  26072. *
  26073. * - Instead pass this object as 'root'.
  26074. *
  26075. * - You can also add and remove objects later when the mixer
  26076. * is running.
  26077. *
  26078. * Note:
  26079. *
  26080. * Objects of this class appear as one object to the mixer,
  26081. * so cache control of the individual objects must be done
  26082. * on the group.
  26083. *
  26084. * Limitation:
  26085. *
  26086. * - The animated properties must be compatible among the
  26087. * all objects in the group.
  26088. *
  26089. * - A single property can either be controlled through a
  26090. * target group or directly, but not both.
  26091. */
  26092. function AnimationObjectGroup() {
  26093. this.uuid = MathUtils.generateUUID(); // cached objects followed by the active ones
  26094. this._objects = Array.prototype.slice.call(arguments);
  26095. this.nCachedObjects_ = 0; // threshold
  26096. // note: read by PropertyBinding.Composite
  26097. var indices = {};
  26098. this._indicesByUUID = indices; // for bookkeeping
  26099. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26100. indices[arguments[i].uuid] = i;
  26101. }
  26102. this._paths = []; // inside: string
  26103. this._parsedPaths = []; // inside: { we don't care, here }
  26104. this._bindings = []; // inside: Array< PropertyBinding >
  26105. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26106. var scope = this;
  26107. this.stats = {
  26108. objects: {
  26109. get total() {
  26110. return scope._objects.length;
  26111. },
  26112. get inUse() {
  26113. return this.total - scope.nCachedObjects_;
  26114. }
  26115. },
  26116. get bindingsPerObject() {
  26117. return scope._bindings.length;
  26118. }
  26119. };
  26120. }
  26121. Object.assign(AnimationObjectGroup.prototype, {
  26122. isAnimationObjectGroup: true,
  26123. add: function add() {
  26124. var objects = this._objects,
  26125. indicesByUUID = this._indicesByUUID,
  26126. paths = this._paths,
  26127. parsedPaths = this._parsedPaths,
  26128. bindings = this._bindings,
  26129. nBindings = bindings.length;
  26130. var knownObject = undefined,
  26131. nObjects = objects.length,
  26132. nCachedObjects = this.nCachedObjects_;
  26133. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26134. var object = arguments[i],
  26135. uuid = object.uuid;
  26136. var index = indicesByUUID[uuid];
  26137. if (index === undefined) {
  26138. // unknown object -> add it to the ACTIVE region
  26139. index = nObjects++;
  26140. indicesByUUID[uuid] = index;
  26141. objects.push(object); // accounting is done, now do the same for all bindings
  26142. for (var j = 0, m = nBindings; j !== m; ++j) {
  26143. bindings[j].push(new PropertyBinding(object, paths[j], parsedPaths[j]));
  26144. }
  26145. } else if (index < nCachedObjects) {
  26146. knownObject = objects[index]; // move existing object to the ACTIVE region
  26147. var firstActiveIndex = --nCachedObjects,
  26148. lastCachedObject = objects[firstActiveIndex];
  26149. indicesByUUID[lastCachedObject.uuid] = index;
  26150. objects[index] = lastCachedObject;
  26151. indicesByUUID[uuid] = firstActiveIndex;
  26152. objects[firstActiveIndex] = object; // accounting is done, now do the same for all bindings
  26153. for (var _j = 0, _m = nBindings; _j !== _m; ++_j) {
  26154. var bindingsForPath = bindings[_j],
  26155. lastCached = bindingsForPath[firstActiveIndex];
  26156. var binding = bindingsForPath[index];
  26157. bindingsForPath[index] = lastCached;
  26158. if (binding === undefined) {
  26159. // since we do not bother to create new bindings
  26160. // for objects that are cached, the binding may
  26161. // or may not exist
  26162. binding = new PropertyBinding(object, paths[_j], parsedPaths[_j]);
  26163. }
  26164. bindingsForPath[firstActiveIndex] = binding;
  26165. }
  26166. } else if (objects[index] !== knownObject) {
  26167. console.error('THREE.AnimationObjectGroup: Different objects with the same UUID ' + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.');
  26168. } // else the object is already where we want it to be
  26169. } // for arguments
  26170. this.nCachedObjects_ = nCachedObjects;
  26171. },
  26172. remove: function remove() {
  26173. var objects = this._objects,
  26174. indicesByUUID = this._indicesByUUID,
  26175. bindings = this._bindings,
  26176. nBindings = bindings.length;
  26177. var nCachedObjects = this.nCachedObjects_;
  26178. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26179. var object = arguments[i],
  26180. uuid = object.uuid,
  26181. index = indicesByUUID[uuid];
  26182. if (index !== undefined && index >= nCachedObjects) {
  26183. // move existing object into the CACHED region
  26184. var lastCachedIndex = nCachedObjects++,
  26185. firstActiveObject = objects[lastCachedIndex];
  26186. indicesByUUID[firstActiveObject.uuid] = index;
  26187. objects[index] = firstActiveObject;
  26188. indicesByUUID[uuid] = lastCachedIndex;
  26189. objects[lastCachedIndex] = object; // accounting is done, now do the same for all bindings
  26190. for (var j = 0, m = nBindings; j !== m; ++j) {
  26191. var bindingsForPath = bindings[j],
  26192. firstActive = bindingsForPath[lastCachedIndex],
  26193. binding = bindingsForPath[index];
  26194. bindingsForPath[index] = firstActive;
  26195. bindingsForPath[lastCachedIndex] = binding;
  26196. }
  26197. }
  26198. } // for arguments
  26199. this.nCachedObjects_ = nCachedObjects;
  26200. },
  26201. // remove & forget
  26202. uncache: function uncache() {
  26203. var objects = this._objects,
  26204. indicesByUUID = this._indicesByUUID,
  26205. bindings = this._bindings,
  26206. nBindings = bindings.length;
  26207. var nCachedObjects = this.nCachedObjects_,
  26208. nObjects = objects.length;
  26209. for (var i = 0, n = arguments.length; i !== n; ++i) {
  26210. var object = arguments[i],
  26211. uuid = object.uuid,
  26212. index = indicesByUUID[uuid];
  26213. if (index !== undefined) {
  26214. delete indicesByUUID[uuid];
  26215. if (index < nCachedObjects) {
  26216. // object is cached, shrink the CACHED region
  26217. var firstActiveIndex = --nCachedObjects,
  26218. lastCachedObject = objects[firstActiveIndex],
  26219. lastIndex = --nObjects,
  26220. lastObject = objects[lastIndex]; // last cached object takes this object's place
  26221. indicesByUUID[lastCachedObject.uuid] = index;
  26222. objects[index] = lastCachedObject; // last object goes to the activated slot and pop
  26223. indicesByUUID[lastObject.uuid] = firstActiveIndex;
  26224. objects[firstActiveIndex] = lastObject;
  26225. objects.pop(); // accounting is done, now do the same for all bindings
  26226. for (var j = 0, m = nBindings; j !== m; ++j) {
  26227. var bindingsForPath = bindings[j],
  26228. lastCached = bindingsForPath[firstActiveIndex],
  26229. last = bindingsForPath[lastIndex];
  26230. bindingsForPath[index] = lastCached;
  26231. bindingsForPath[firstActiveIndex] = last;
  26232. bindingsForPath.pop();
  26233. }
  26234. } else {
  26235. // object is active, just swap with the last and pop
  26236. var _lastIndex = --nObjects,
  26237. _lastObject = objects[_lastIndex];
  26238. if (_lastIndex > 0) {
  26239. indicesByUUID[_lastObject.uuid] = index;
  26240. }
  26241. objects[index] = _lastObject;
  26242. objects.pop(); // accounting is done, now do the same for all bindings
  26243. for (var _j2 = 0, _m2 = nBindings; _j2 !== _m2; ++_j2) {
  26244. var _bindingsForPath = bindings[_j2];
  26245. _bindingsForPath[index] = _bindingsForPath[_lastIndex];
  26246. _bindingsForPath.pop();
  26247. }
  26248. } // cached or active
  26249. } // if object is known
  26250. } // for arguments
  26251. this.nCachedObjects_ = nCachedObjects;
  26252. },
  26253. // Internal interface used by befriended PropertyBinding.Composite:
  26254. subscribe_: function subscribe_(path, parsedPath) {
  26255. // returns an array of bindings for the given path that is changed
  26256. // according to the contained objects in the group
  26257. var indicesByPath = this._bindingsIndicesByPath;
  26258. var index = indicesByPath[path];
  26259. var bindings = this._bindings;
  26260. if (index !== undefined) return bindings[index];
  26261. var paths = this._paths,
  26262. parsedPaths = this._parsedPaths,
  26263. objects = this._objects,
  26264. nObjects = objects.length,
  26265. nCachedObjects = this.nCachedObjects_,
  26266. bindingsForPath = new Array(nObjects);
  26267. index = bindings.length;
  26268. indicesByPath[path] = index;
  26269. paths.push(path);
  26270. parsedPaths.push(parsedPath);
  26271. bindings.push(bindingsForPath);
  26272. for (var i = nCachedObjects, n = objects.length; i !== n; ++i) {
  26273. var object = objects[i];
  26274. bindingsForPath[i] = new PropertyBinding(object, path, parsedPath);
  26275. }
  26276. return bindingsForPath;
  26277. },
  26278. unsubscribe_: function unsubscribe_(path) {
  26279. // tells the group to forget about a property path and no longer
  26280. // update the array previously obtained with 'subscribe_'
  26281. var indicesByPath = this._bindingsIndicesByPath,
  26282. index = indicesByPath[path];
  26283. if (index !== undefined) {
  26284. var paths = this._paths,
  26285. parsedPaths = this._parsedPaths,
  26286. bindings = this._bindings,
  26287. lastBindingsIndex = bindings.length - 1,
  26288. lastBindings = bindings[lastBindingsIndex],
  26289. lastBindingsPath = path[lastBindingsIndex];
  26290. indicesByPath[lastBindingsPath] = index;
  26291. bindings[index] = lastBindings;
  26292. bindings.pop();
  26293. parsedPaths[index] = parsedPaths[lastBindingsIndex];
  26294. parsedPaths.pop();
  26295. paths[index] = paths[lastBindingsIndex];
  26296. paths.pop();
  26297. }
  26298. }
  26299. });
  26300. var AnimationAction = /*#__PURE__*/function () {
  26301. function AnimationAction(mixer, clip, localRoot, blendMode) {
  26302. if (localRoot === void 0) {
  26303. localRoot = null;
  26304. }
  26305. if (blendMode === void 0) {
  26306. blendMode = clip.blendMode;
  26307. }
  26308. this._mixer = mixer;
  26309. this._clip = clip;
  26310. this._localRoot = localRoot;
  26311. this.blendMode = blendMode;
  26312. var tracks = clip.tracks,
  26313. nTracks = tracks.length,
  26314. interpolants = new Array(nTracks);
  26315. var interpolantSettings = {
  26316. endingStart: ZeroCurvatureEnding,
  26317. endingEnd: ZeroCurvatureEnding
  26318. };
  26319. for (var i = 0; i !== nTracks; ++i) {
  26320. var interpolant = tracks[i].createInterpolant(null);
  26321. interpolants[i] = interpolant;
  26322. interpolant.settings = interpolantSettings;
  26323. }
  26324. this._interpolantSettings = interpolantSettings;
  26325. this._interpolants = interpolants; // bound by the mixer
  26326. // inside: PropertyMixer (managed by the mixer)
  26327. this._propertyBindings = new Array(nTracks);
  26328. this._cacheIndex = null; // for the memory manager
  26329. this._byClipCacheIndex = null; // for the memory manager
  26330. this._timeScaleInterpolant = null;
  26331. this._weightInterpolant = null;
  26332. this.loop = LoopRepeat;
  26333. this._loopCount = -1; // global mixer time when the action is to be started
  26334. // it's set back to 'null' upon start of the action
  26335. this._startTime = null; // scaled local time of the action
  26336. // gets clamped or wrapped to 0..clip.duration according to loop
  26337. this.time = 0;
  26338. this.timeScale = 1;
  26339. this._effectiveTimeScale = 1;
  26340. this.weight = 1;
  26341. this._effectiveWeight = 1;
  26342. this.repetitions = Infinity; // no. of repetitions when looping
  26343. this.paused = false; // true -> zero effective time scale
  26344. this.enabled = true; // false -> zero effective weight
  26345. this.clampWhenFinished = false; // keep feeding the last frame?
  26346. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  26347. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  26348. } // State & Scheduling
  26349. var _proto = AnimationAction.prototype;
  26350. _proto.play = function play() {
  26351. this._mixer._activateAction(this);
  26352. return this;
  26353. };
  26354. _proto.stop = function stop() {
  26355. this._mixer._deactivateAction(this);
  26356. return this.reset();
  26357. };
  26358. _proto.reset = function reset() {
  26359. this.paused = false;
  26360. this.enabled = true;
  26361. this.time = 0; // restart clip
  26362. this._loopCount = -1; // forget previous loops
  26363. this._startTime = null; // forget scheduling
  26364. return this.stopFading().stopWarping();
  26365. };
  26366. _proto.isRunning = function isRunning() {
  26367. return this.enabled && !this.paused && this.timeScale !== 0 && this._startTime === null && this._mixer._isActiveAction(this);
  26368. } // return true when play has been called
  26369. ;
  26370. _proto.isScheduled = function isScheduled() {
  26371. return this._mixer._isActiveAction(this);
  26372. };
  26373. _proto.startAt = function startAt(time) {
  26374. this._startTime = time;
  26375. return this;
  26376. };
  26377. _proto.setLoop = function setLoop(mode, repetitions) {
  26378. this.loop = mode;
  26379. this.repetitions = repetitions;
  26380. return this;
  26381. } // Weight
  26382. // set the weight stopping any scheduled fading
  26383. // although .enabled = false yields an effective weight of zero, this
  26384. // method does *not* change .enabled, because it would be confusing
  26385. ;
  26386. _proto.setEffectiveWeight = function setEffectiveWeight(weight) {
  26387. this.weight = weight; // note: same logic as when updated at runtime
  26388. this._effectiveWeight = this.enabled ? weight : 0;
  26389. return this.stopFading();
  26390. } // return the weight considering fading and .enabled
  26391. ;
  26392. _proto.getEffectiveWeight = function getEffectiveWeight() {
  26393. return this._effectiveWeight;
  26394. };
  26395. _proto.fadeIn = function fadeIn(duration) {
  26396. return this._scheduleFading(duration, 0, 1);
  26397. };
  26398. _proto.fadeOut = function fadeOut(duration) {
  26399. return this._scheduleFading(duration, 1, 0);
  26400. };
  26401. _proto.crossFadeFrom = function crossFadeFrom(fadeOutAction, duration, warp) {
  26402. fadeOutAction.fadeOut(duration);
  26403. this.fadeIn(duration);
  26404. if (warp) {
  26405. var fadeInDuration = this._clip.duration,
  26406. fadeOutDuration = fadeOutAction._clip.duration,
  26407. startEndRatio = fadeOutDuration / fadeInDuration,
  26408. endStartRatio = fadeInDuration / fadeOutDuration;
  26409. fadeOutAction.warp(1.0, startEndRatio, duration);
  26410. this.warp(endStartRatio, 1.0, duration);
  26411. }
  26412. return this;
  26413. };
  26414. _proto.crossFadeTo = function crossFadeTo(fadeInAction, duration, warp) {
  26415. return fadeInAction.crossFadeFrom(this, duration, warp);
  26416. };
  26417. _proto.stopFading = function stopFading() {
  26418. var weightInterpolant = this._weightInterpolant;
  26419. if (weightInterpolant !== null) {
  26420. this._weightInterpolant = null;
  26421. this._mixer._takeBackControlInterpolant(weightInterpolant);
  26422. }
  26423. return this;
  26424. } // Time Scale Control
  26425. // set the time scale stopping any scheduled warping
  26426. // although .paused = true yields an effective time scale of zero, this
  26427. // method does *not* change .paused, because it would be confusing
  26428. ;
  26429. _proto.setEffectiveTimeScale = function setEffectiveTimeScale(timeScale) {
  26430. this.timeScale = timeScale;
  26431. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26432. return this.stopWarping();
  26433. } // return the time scale considering warping and .paused
  26434. ;
  26435. _proto.getEffectiveTimeScale = function getEffectiveTimeScale() {
  26436. return this._effectiveTimeScale;
  26437. };
  26438. _proto.setDuration = function setDuration(duration) {
  26439. this.timeScale = this._clip.duration / duration;
  26440. return this.stopWarping();
  26441. };
  26442. _proto.syncWith = function syncWith(action) {
  26443. this.time = action.time;
  26444. this.timeScale = action.timeScale;
  26445. return this.stopWarping();
  26446. };
  26447. _proto.halt = function halt(duration) {
  26448. return this.warp(this._effectiveTimeScale, 0, duration);
  26449. };
  26450. _proto.warp = function warp(startTimeScale, endTimeScale, duration) {
  26451. var mixer = this._mixer,
  26452. now = mixer.time,
  26453. timeScale = this.timeScale;
  26454. var interpolant = this._timeScaleInterpolant;
  26455. if (interpolant === null) {
  26456. interpolant = mixer._lendControlInterpolant();
  26457. this._timeScaleInterpolant = interpolant;
  26458. }
  26459. var times = interpolant.parameterPositions,
  26460. values = interpolant.sampleValues;
  26461. times[0] = now;
  26462. times[1] = now + duration;
  26463. values[0] = startTimeScale / timeScale;
  26464. values[1] = endTimeScale / timeScale;
  26465. return this;
  26466. };
  26467. _proto.stopWarping = function stopWarping() {
  26468. var timeScaleInterpolant = this._timeScaleInterpolant;
  26469. if (timeScaleInterpolant !== null) {
  26470. this._timeScaleInterpolant = null;
  26471. this._mixer._takeBackControlInterpolant(timeScaleInterpolant);
  26472. }
  26473. return this;
  26474. } // Object Accessors
  26475. ;
  26476. _proto.getMixer = function getMixer() {
  26477. return this._mixer;
  26478. };
  26479. _proto.getClip = function getClip() {
  26480. return this._clip;
  26481. };
  26482. _proto.getRoot = function getRoot() {
  26483. return this._localRoot || this._mixer._root;
  26484. } // Interna
  26485. ;
  26486. _proto._update = function _update(time, deltaTime, timeDirection, accuIndex) {
  26487. // called by the mixer
  26488. if (!this.enabled) {
  26489. // call ._updateWeight() to update ._effectiveWeight
  26490. this._updateWeight(time);
  26491. return;
  26492. }
  26493. var startTime = this._startTime;
  26494. if (startTime !== null) {
  26495. // check for scheduled start of action
  26496. var timeRunning = (time - startTime) * timeDirection;
  26497. if (timeRunning < 0 || timeDirection === 0) {
  26498. return; // yet to come / don't decide when delta = 0
  26499. } // start
  26500. this._startTime = null; // unschedule
  26501. deltaTime = timeDirection * timeRunning;
  26502. } // apply time scale and advance time
  26503. deltaTime *= this._updateTimeScale(time);
  26504. var clipTime = this._updateTime(deltaTime); // note: _updateTime may disable the action resulting in
  26505. // an effective weight of 0
  26506. var weight = this._updateWeight(time);
  26507. if (weight > 0) {
  26508. var _interpolants = this._interpolants;
  26509. var propertyMixers = this._propertyBindings;
  26510. switch (this.blendMode) {
  26511. case AdditiveAnimationBlendMode:
  26512. for (var j = 0, m = _interpolants.length; j !== m; ++j) {
  26513. _interpolants[j].evaluate(clipTime);
  26514. propertyMixers[j].accumulateAdditive(weight);
  26515. }
  26516. break;
  26517. case NormalAnimationBlendMode:
  26518. default:
  26519. for (var _j = 0, _m = _interpolants.length; _j !== _m; ++_j) {
  26520. _interpolants[_j].evaluate(clipTime);
  26521. propertyMixers[_j].accumulate(accuIndex, weight);
  26522. }
  26523. }
  26524. }
  26525. };
  26526. _proto._updateWeight = function _updateWeight(time) {
  26527. var weight = 0;
  26528. if (this.enabled) {
  26529. weight = this.weight;
  26530. var interpolant = this._weightInterpolant;
  26531. if (interpolant !== null) {
  26532. var interpolantValue = interpolant.evaluate(time)[0];
  26533. weight *= interpolantValue;
  26534. if (time > interpolant.parameterPositions[1]) {
  26535. this.stopFading();
  26536. if (interpolantValue === 0) {
  26537. // faded out, disable
  26538. this.enabled = false;
  26539. }
  26540. }
  26541. }
  26542. }
  26543. this._effectiveWeight = weight;
  26544. return weight;
  26545. };
  26546. _proto._updateTimeScale = function _updateTimeScale(time) {
  26547. var timeScale = 0;
  26548. if (!this.paused) {
  26549. timeScale = this.timeScale;
  26550. var interpolant = this._timeScaleInterpolant;
  26551. if (interpolant !== null) {
  26552. var interpolantValue = interpolant.evaluate(time)[0];
  26553. timeScale *= interpolantValue;
  26554. if (time > interpolant.parameterPositions[1]) {
  26555. this.stopWarping();
  26556. if (timeScale === 0) {
  26557. // motion has halted, pause
  26558. this.paused = true;
  26559. } else {
  26560. // warp done - apply final time scale
  26561. this.timeScale = timeScale;
  26562. }
  26563. }
  26564. }
  26565. }
  26566. this._effectiveTimeScale = timeScale;
  26567. return timeScale;
  26568. };
  26569. _proto._updateTime = function _updateTime(deltaTime) {
  26570. var duration = this._clip.duration;
  26571. var loop = this.loop;
  26572. var time = this.time + deltaTime;
  26573. var loopCount = this._loopCount;
  26574. var pingPong = loop === LoopPingPong;
  26575. if (deltaTime === 0) {
  26576. if (loopCount === -1) return time;
  26577. return pingPong && (loopCount & 1) === 1 ? duration - time : time;
  26578. }
  26579. if (loop === LoopOnce) {
  26580. if (loopCount === -1) {
  26581. // just started
  26582. this._loopCount = 0;
  26583. this._setEndings(true, true, false);
  26584. }
  26585. handle_stop: {
  26586. if (time >= duration) {
  26587. time = duration;
  26588. } else if (time < 0) {
  26589. time = 0;
  26590. } else {
  26591. this.time = time;
  26592. break handle_stop;
  26593. }
  26594. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26595. this.time = time;
  26596. this._mixer.dispatchEvent({
  26597. type: 'finished',
  26598. action: this,
  26599. direction: deltaTime < 0 ? -1 : 1
  26600. });
  26601. }
  26602. } else {
  26603. // repetitive Repeat or PingPong
  26604. if (loopCount === -1) {
  26605. // just started
  26606. if (deltaTime >= 0) {
  26607. loopCount = 0;
  26608. this._setEndings(true, this.repetitions === 0, pingPong);
  26609. } else {
  26610. // when looping in reverse direction, the initial
  26611. // transition through zero counts as a repetition,
  26612. // so leave loopCount at -1
  26613. this._setEndings(this.repetitions === 0, true, pingPong);
  26614. }
  26615. }
  26616. if (time >= duration || time < 0) {
  26617. // wrap around
  26618. var loopDelta = Math.floor(time / duration); // signed
  26619. time -= duration * loopDelta;
  26620. loopCount += Math.abs(loopDelta);
  26621. var pending = this.repetitions - loopCount;
  26622. if (pending <= 0) {
  26623. // have to stop (switch state, clamp time, fire event)
  26624. if (this.clampWhenFinished) this.paused = true;else this.enabled = false;
  26625. time = deltaTime > 0 ? duration : 0;
  26626. this.time = time;
  26627. this._mixer.dispatchEvent({
  26628. type: 'finished',
  26629. action: this,
  26630. direction: deltaTime > 0 ? 1 : -1
  26631. });
  26632. } else {
  26633. // keep running
  26634. if (pending === 1) {
  26635. // entering the last round
  26636. var atStart = deltaTime < 0;
  26637. this._setEndings(atStart, !atStart, pingPong);
  26638. } else {
  26639. this._setEndings(false, false, pingPong);
  26640. }
  26641. this._loopCount = loopCount;
  26642. this.time = time;
  26643. this._mixer.dispatchEvent({
  26644. type: 'loop',
  26645. action: this,
  26646. loopDelta: loopDelta
  26647. });
  26648. }
  26649. } else {
  26650. this.time = time;
  26651. }
  26652. if (pingPong && (loopCount & 1) === 1) {
  26653. // invert time for the "pong round"
  26654. return duration - time;
  26655. }
  26656. }
  26657. return time;
  26658. };
  26659. _proto._setEndings = function _setEndings(atStart, atEnd, pingPong) {
  26660. var settings = this._interpolantSettings;
  26661. if (pingPong) {
  26662. settings.endingStart = ZeroSlopeEnding;
  26663. settings.endingEnd = ZeroSlopeEnding;
  26664. } else {
  26665. // assuming for LoopOnce atStart == atEnd == true
  26666. if (atStart) {
  26667. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26668. } else {
  26669. settings.endingStart = WrapAroundEnding;
  26670. }
  26671. if (atEnd) {
  26672. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26673. } else {
  26674. settings.endingEnd = WrapAroundEnding;
  26675. }
  26676. }
  26677. };
  26678. _proto._scheduleFading = function _scheduleFading(duration, weightNow, weightThen) {
  26679. var mixer = this._mixer,
  26680. now = mixer.time;
  26681. var interpolant = this._weightInterpolant;
  26682. if (interpolant === null) {
  26683. interpolant = mixer._lendControlInterpolant();
  26684. this._weightInterpolant = interpolant;
  26685. }
  26686. var times = interpolant.parameterPositions,
  26687. values = interpolant.sampleValues;
  26688. times[0] = now;
  26689. values[0] = weightNow;
  26690. times[1] = now + duration;
  26691. values[1] = weightThen;
  26692. return this;
  26693. };
  26694. return AnimationAction;
  26695. }();
  26696. function AnimationMixer(root) {
  26697. this._root = root;
  26698. this._initMemoryManager();
  26699. this._accuIndex = 0;
  26700. this.time = 0;
  26701. this.timeScale = 1.0;
  26702. }
  26703. AnimationMixer.prototype = Object.assign(Object.create(EventDispatcher.prototype), {
  26704. constructor: AnimationMixer,
  26705. _bindAction: function _bindAction(action, prototypeAction) {
  26706. var root = action._localRoot || this._root,
  26707. tracks = action._clip.tracks,
  26708. nTracks = tracks.length,
  26709. bindings = action._propertyBindings,
  26710. interpolants = action._interpolants,
  26711. rootUuid = root.uuid,
  26712. bindingsByRoot = this._bindingsByRootAndName;
  26713. var bindingsByName = bindingsByRoot[rootUuid];
  26714. if (bindingsByName === undefined) {
  26715. bindingsByName = {};
  26716. bindingsByRoot[rootUuid] = bindingsByName;
  26717. }
  26718. for (var i = 0; i !== nTracks; ++i) {
  26719. var track = tracks[i],
  26720. trackName = track.name;
  26721. var binding = bindingsByName[trackName];
  26722. if (binding !== undefined) {
  26723. bindings[i] = binding;
  26724. } else {
  26725. binding = bindings[i];
  26726. if (binding !== undefined) {
  26727. // existing binding, make sure the cache knows
  26728. if (binding._cacheIndex === null) {
  26729. ++binding.referenceCount;
  26730. this._addInactiveBinding(binding, rootUuid, trackName);
  26731. }
  26732. continue;
  26733. }
  26734. var path = prototypeAction && prototypeAction._propertyBindings[i].binding.parsedPath;
  26735. binding = new PropertyMixer(PropertyBinding.create(root, trackName, path), track.ValueTypeName, track.getValueSize());
  26736. ++binding.referenceCount;
  26737. this._addInactiveBinding(binding, rootUuid, trackName);
  26738. bindings[i] = binding;
  26739. }
  26740. interpolants[i].resultBuffer = binding.buffer;
  26741. }
  26742. },
  26743. _activateAction: function _activateAction(action) {
  26744. if (!this._isActiveAction(action)) {
  26745. if (action._cacheIndex === null) {
  26746. // this action has been forgotten by the cache, but the user
  26747. // appears to be still using it -> rebind
  26748. var rootUuid = (action._localRoot || this._root).uuid,
  26749. clipUuid = action._clip.uuid,
  26750. actionsForClip = this._actionsByClip[clipUuid];
  26751. this._bindAction(action, actionsForClip && actionsForClip.knownActions[0]);
  26752. this._addInactiveAction(action, clipUuid, rootUuid);
  26753. }
  26754. var bindings = action._propertyBindings; // increment reference counts / sort out state
  26755. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26756. var binding = bindings[i];
  26757. if (binding.useCount++ === 0) {
  26758. this._lendBinding(binding);
  26759. binding.saveOriginalState();
  26760. }
  26761. }
  26762. this._lendAction(action);
  26763. }
  26764. },
  26765. _deactivateAction: function _deactivateAction(action) {
  26766. if (this._isActiveAction(action)) {
  26767. var bindings = action._propertyBindings; // decrement reference counts / sort out state
  26768. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26769. var binding = bindings[i];
  26770. if (--binding.useCount === 0) {
  26771. binding.restoreOriginalState();
  26772. this._takeBackBinding(binding);
  26773. }
  26774. }
  26775. this._takeBackAction(action);
  26776. }
  26777. },
  26778. // Memory manager
  26779. _initMemoryManager: function _initMemoryManager() {
  26780. this._actions = []; // 'nActiveActions' followed by inactive ones
  26781. this._nActiveActions = 0;
  26782. this._actionsByClip = {}; // inside:
  26783. // {
  26784. // knownActions: Array< AnimationAction > - used as prototypes
  26785. // actionByRoot: AnimationAction - lookup
  26786. // }
  26787. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26788. this._nActiveBindings = 0;
  26789. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26790. this._controlInterpolants = []; // same game as above
  26791. this._nActiveControlInterpolants = 0;
  26792. var scope = this;
  26793. this.stats = {
  26794. actions: {
  26795. get total() {
  26796. return scope._actions.length;
  26797. },
  26798. get inUse() {
  26799. return scope._nActiveActions;
  26800. }
  26801. },
  26802. bindings: {
  26803. get total() {
  26804. return scope._bindings.length;
  26805. },
  26806. get inUse() {
  26807. return scope._nActiveBindings;
  26808. }
  26809. },
  26810. controlInterpolants: {
  26811. get total() {
  26812. return scope._controlInterpolants.length;
  26813. },
  26814. get inUse() {
  26815. return scope._nActiveControlInterpolants;
  26816. }
  26817. }
  26818. };
  26819. },
  26820. // Memory management for AnimationAction objects
  26821. _isActiveAction: function _isActiveAction(action) {
  26822. var index = action._cacheIndex;
  26823. return index !== null && index < this._nActiveActions;
  26824. },
  26825. _addInactiveAction: function _addInactiveAction(action, clipUuid, rootUuid) {
  26826. var actions = this._actions,
  26827. actionsByClip = this._actionsByClip;
  26828. var actionsForClip = actionsByClip[clipUuid];
  26829. if (actionsForClip === undefined) {
  26830. actionsForClip = {
  26831. knownActions: [action],
  26832. actionByRoot: {}
  26833. };
  26834. action._byClipCacheIndex = 0;
  26835. actionsByClip[clipUuid] = actionsForClip;
  26836. } else {
  26837. var knownActions = actionsForClip.knownActions;
  26838. action._byClipCacheIndex = knownActions.length;
  26839. knownActions.push(action);
  26840. }
  26841. action._cacheIndex = actions.length;
  26842. actions.push(action);
  26843. actionsForClip.actionByRoot[rootUuid] = action;
  26844. },
  26845. _removeInactiveAction: function _removeInactiveAction(action) {
  26846. var actions = this._actions,
  26847. lastInactiveAction = actions[actions.length - 1],
  26848. cacheIndex = action._cacheIndex;
  26849. lastInactiveAction._cacheIndex = cacheIndex;
  26850. actions[cacheIndex] = lastInactiveAction;
  26851. actions.pop();
  26852. action._cacheIndex = null;
  26853. var clipUuid = action._clip.uuid,
  26854. actionsByClip = this._actionsByClip,
  26855. actionsForClip = actionsByClip[clipUuid],
  26856. knownActionsForClip = actionsForClip.knownActions,
  26857. lastKnownAction = knownActionsForClip[knownActionsForClip.length - 1],
  26858. byClipCacheIndex = action._byClipCacheIndex;
  26859. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26860. knownActionsForClip[byClipCacheIndex] = lastKnownAction;
  26861. knownActionsForClip.pop();
  26862. action._byClipCacheIndex = null;
  26863. var actionByRoot = actionsForClip.actionByRoot,
  26864. rootUuid = (action._localRoot || this._root).uuid;
  26865. delete actionByRoot[rootUuid];
  26866. if (knownActionsForClip.length === 0) {
  26867. delete actionsByClip[clipUuid];
  26868. }
  26869. this._removeInactiveBindingsForAction(action);
  26870. },
  26871. _removeInactiveBindingsForAction: function _removeInactiveBindingsForAction(action) {
  26872. var bindings = action._propertyBindings;
  26873. for (var i = 0, n = bindings.length; i !== n; ++i) {
  26874. var binding = bindings[i];
  26875. if (--binding.referenceCount === 0) {
  26876. this._removeInactiveBinding(binding);
  26877. }
  26878. }
  26879. },
  26880. _lendAction: function _lendAction(action) {
  26881. // [ active actions | inactive actions ]
  26882. // [ active actions >| inactive actions ]
  26883. // s a
  26884. // <-swap->
  26885. // a s
  26886. var actions = this._actions,
  26887. prevIndex = action._cacheIndex,
  26888. lastActiveIndex = this._nActiveActions++,
  26889. firstInactiveAction = actions[lastActiveIndex];
  26890. action._cacheIndex = lastActiveIndex;
  26891. actions[lastActiveIndex] = action;
  26892. firstInactiveAction._cacheIndex = prevIndex;
  26893. actions[prevIndex] = firstInactiveAction;
  26894. },
  26895. _takeBackAction: function _takeBackAction(action) {
  26896. // [ active actions | inactive actions ]
  26897. // [ active actions |< inactive actions ]
  26898. // a s
  26899. // <-swap->
  26900. // s a
  26901. var actions = this._actions,
  26902. prevIndex = action._cacheIndex,
  26903. firstInactiveIndex = --this._nActiveActions,
  26904. lastActiveAction = actions[firstInactiveIndex];
  26905. action._cacheIndex = firstInactiveIndex;
  26906. actions[firstInactiveIndex] = action;
  26907. lastActiveAction._cacheIndex = prevIndex;
  26908. actions[prevIndex] = lastActiveAction;
  26909. },
  26910. // Memory management for PropertyMixer objects
  26911. _addInactiveBinding: function _addInactiveBinding(binding, rootUuid, trackName) {
  26912. var bindingsByRoot = this._bindingsByRootAndName,
  26913. bindings = this._bindings;
  26914. var bindingByName = bindingsByRoot[rootUuid];
  26915. if (bindingByName === undefined) {
  26916. bindingByName = {};
  26917. bindingsByRoot[rootUuid] = bindingByName;
  26918. }
  26919. bindingByName[trackName] = binding;
  26920. binding._cacheIndex = bindings.length;
  26921. bindings.push(binding);
  26922. },
  26923. _removeInactiveBinding: function _removeInactiveBinding(binding) {
  26924. var bindings = this._bindings,
  26925. propBinding = binding.binding,
  26926. rootUuid = propBinding.rootNode.uuid,
  26927. trackName = propBinding.path,
  26928. bindingsByRoot = this._bindingsByRootAndName,
  26929. bindingByName = bindingsByRoot[rootUuid],
  26930. lastInactiveBinding = bindings[bindings.length - 1],
  26931. cacheIndex = binding._cacheIndex;
  26932. lastInactiveBinding._cacheIndex = cacheIndex;
  26933. bindings[cacheIndex] = lastInactiveBinding;
  26934. bindings.pop();
  26935. delete bindingByName[trackName];
  26936. if (Object.keys(bindingByName).length === 0) {
  26937. delete bindingsByRoot[rootUuid];
  26938. }
  26939. },
  26940. _lendBinding: function _lendBinding(binding) {
  26941. var bindings = this._bindings,
  26942. prevIndex = binding._cacheIndex,
  26943. lastActiveIndex = this._nActiveBindings++,
  26944. firstInactiveBinding = bindings[lastActiveIndex];
  26945. binding._cacheIndex = lastActiveIndex;
  26946. bindings[lastActiveIndex] = binding;
  26947. firstInactiveBinding._cacheIndex = prevIndex;
  26948. bindings[prevIndex] = firstInactiveBinding;
  26949. },
  26950. _takeBackBinding: function _takeBackBinding(binding) {
  26951. var bindings = this._bindings,
  26952. prevIndex = binding._cacheIndex,
  26953. firstInactiveIndex = --this._nActiveBindings,
  26954. lastActiveBinding = bindings[firstInactiveIndex];
  26955. binding._cacheIndex = firstInactiveIndex;
  26956. bindings[firstInactiveIndex] = binding;
  26957. lastActiveBinding._cacheIndex = prevIndex;
  26958. bindings[prevIndex] = lastActiveBinding;
  26959. },
  26960. // Memory management of Interpolants for weight and time scale
  26961. _lendControlInterpolant: function _lendControlInterpolant() {
  26962. var interpolants = this._controlInterpolants,
  26963. lastActiveIndex = this._nActiveControlInterpolants++;
  26964. var interpolant = interpolants[lastActiveIndex];
  26965. if (interpolant === undefined) {
  26966. interpolant = new LinearInterpolant(new Float32Array(2), new Float32Array(2), 1, this._controlInterpolantsResultBuffer);
  26967. interpolant.__cacheIndex = lastActiveIndex;
  26968. interpolants[lastActiveIndex] = interpolant;
  26969. }
  26970. return interpolant;
  26971. },
  26972. _takeBackControlInterpolant: function _takeBackControlInterpolant(interpolant) {
  26973. var interpolants = this._controlInterpolants,
  26974. prevIndex = interpolant.__cacheIndex,
  26975. firstInactiveIndex = --this._nActiveControlInterpolants,
  26976. lastActiveInterpolant = interpolants[firstInactiveIndex];
  26977. interpolant.__cacheIndex = firstInactiveIndex;
  26978. interpolants[firstInactiveIndex] = interpolant;
  26979. lastActiveInterpolant.__cacheIndex = prevIndex;
  26980. interpolants[prevIndex] = lastActiveInterpolant;
  26981. },
  26982. _controlInterpolantsResultBuffer: new Float32Array(1),
  26983. // return an action for a clip optionally using a custom root target
  26984. // object (this method allocates a lot of dynamic memory in case a
  26985. // previously unknown clip/root combination is specified)
  26986. clipAction: function clipAction(clip, optionalRoot, blendMode) {
  26987. var root = optionalRoot || this._root,
  26988. rootUuid = root.uuid;
  26989. var clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip;
  26990. var clipUuid = clipObject !== null ? clipObject.uuid : clip;
  26991. var actionsForClip = this._actionsByClip[clipUuid];
  26992. var prototypeAction = null;
  26993. if (blendMode === undefined) {
  26994. if (clipObject !== null) {
  26995. blendMode = clipObject.blendMode;
  26996. } else {
  26997. blendMode = NormalAnimationBlendMode;
  26998. }
  26999. }
  27000. if (actionsForClip !== undefined) {
  27001. var existingAction = actionsForClip.actionByRoot[rootUuid];
  27002. if (existingAction !== undefined && existingAction.blendMode === blendMode) {
  27003. return existingAction;
  27004. } // we know the clip, so we don't have to parse all
  27005. // the bindings again but can just copy
  27006. prototypeAction = actionsForClip.knownActions[0]; // also, take the clip from the prototype action
  27007. if (clipObject === null) clipObject = prototypeAction._clip;
  27008. } // clip must be known when specified via string
  27009. if (clipObject === null) return null; // allocate all resources required to run it
  27010. var newAction = new AnimationAction(this, clipObject, optionalRoot, blendMode);
  27011. this._bindAction(newAction, prototypeAction); // and make the action known to the memory manager
  27012. this._addInactiveAction(newAction, clipUuid, rootUuid);
  27013. return newAction;
  27014. },
  27015. // get an existing action
  27016. existingAction: function existingAction(clip, optionalRoot) {
  27017. var root = optionalRoot || this._root,
  27018. rootUuid = root.uuid,
  27019. clipObject = typeof clip === 'string' ? AnimationClip.findByName(root, clip) : clip,
  27020. clipUuid = clipObject ? clipObject.uuid : clip,
  27021. actionsForClip = this._actionsByClip[clipUuid];
  27022. if (actionsForClip !== undefined) {
  27023. return actionsForClip.actionByRoot[rootUuid] || null;
  27024. }
  27025. return null;
  27026. },
  27027. // deactivates all previously scheduled actions
  27028. stopAllAction: function stopAllAction() {
  27029. var actions = this._actions,
  27030. nActions = this._nActiveActions;
  27031. for (var i = nActions - 1; i >= 0; --i) {
  27032. actions[i].stop();
  27033. }
  27034. return this;
  27035. },
  27036. // advance the time and update apply the animation
  27037. update: function update(deltaTime) {
  27038. deltaTime *= this.timeScale;
  27039. var actions = this._actions,
  27040. nActions = this._nActiveActions,
  27041. time = this.time += deltaTime,
  27042. timeDirection = Math.sign(deltaTime),
  27043. accuIndex = this._accuIndex ^= 1; // run active actions
  27044. for (var i = 0; i !== nActions; ++i) {
  27045. var action = actions[i];
  27046. action._update(time, deltaTime, timeDirection, accuIndex);
  27047. } // update scene graph
  27048. var bindings = this._bindings,
  27049. nBindings = this._nActiveBindings;
  27050. for (var _i = 0; _i !== nBindings; ++_i) {
  27051. bindings[_i].apply(accuIndex);
  27052. }
  27053. return this;
  27054. },
  27055. // Allows you to seek to a specific time in an animation.
  27056. setTime: function setTime(timeInSeconds) {
  27057. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27058. for (var i = 0; i < this._actions.length; i++) {
  27059. this._actions[i].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27060. }
  27061. return this.update(timeInSeconds); // Update used to set exact time. Returns "this" AnimationMixer object.
  27062. },
  27063. // return this mixer's root target object
  27064. getRoot: function getRoot() {
  27065. return this._root;
  27066. },
  27067. // free all resources specific to a particular clip
  27068. uncacheClip: function uncacheClip(clip) {
  27069. var actions = this._actions,
  27070. clipUuid = clip.uuid,
  27071. actionsByClip = this._actionsByClip,
  27072. actionsForClip = actionsByClip[clipUuid];
  27073. if (actionsForClip !== undefined) {
  27074. // note: just calling _removeInactiveAction would mess up the
  27075. // iteration state and also require updating the state we can
  27076. // just throw away
  27077. var actionsToRemove = actionsForClip.knownActions;
  27078. for (var i = 0, n = actionsToRemove.length; i !== n; ++i) {
  27079. var action = actionsToRemove[i];
  27080. this._deactivateAction(action);
  27081. var cacheIndex = action._cacheIndex,
  27082. lastInactiveAction = actions[actions.length - 1];
  27083. action._cacheIndex = null;
  27084. action._byClipCacheIndex = null;
  27085. lastInactiveAction._cacheIndex = cacheIndex;
  27086. actions[cacheIndex] = lastInactiveAction;
  27087. actions.pop();
  27088. this._removeInactiveBindingsForAction(action);
  27089. }
  27090. delete actionsByClip[clipUuid];
  27091. }
  27092. },
  27093. // free all resources specific to a particular root target object
  27094. uncacheRoot: function uncacheRoot(root) {
  27095. var rootUuid = root.uuid,
  27096. actionsByClip = this._actionsByClip;
  27097. for (var clipUuid in actionsByClip) {
  27098. var actionByRoot = actionsByClip[clipUuid].actionByRoot,
  27099. action = actionByRoot[rootUuid];
  27100. if (action !== undefined) {
  27101. this._deactivateAction(action);
  27102. this._removeInactiveAction(action);
  27103. }
  27104. }
  27105. var bindingsByRoot = this._bindingsByRootAndName,
  27106. bindingByName = bindingsByRoot[rootUuid];
  27107. if (bindingByName !== undefined) {
  27108. for (var trackName in bindingByName) {
  27109. var binding = bindingByName[trackName];
  27110. binding.restoreOriginalState();
  27111. this._removeInactiveBinding(binding);
  27112. }
  27113. }
  27114. },
  27115. // remove a targeted clip from the cache
  27116. uncacheAction: function uncacheAction(clip, optionalRoot) {
  27117. var action = this.existingAction(clip, optionalRoot);
  27118. if (action !== null) {
  27119. this._deactivateAction(action);
  27120. this._removeInactiveAction(action);
  27121. }
  27122. }
  27123. });
  27124. var Uniform = /*#__PURE__*/function () {
  27125. function Uniform(value) {
  27126. if (typeof value === 'string') {
  27127. console.warn('THREE.Uniform: Type parameter is no longer needed.');
  27128. value = arguments[1];
  27129. }
  27130. this.value = value;
  27131. }
  27132. var _proto = Uniform.prototype;
  27133. _proto.clone = function clone() {
  27134. return new Uniform(this.value.clone === undefined ? this.value : this.value.clone());
  27135. };
  27136. return Uniform;
  27137. }();
  27138. function InstancedInterleavedBuffer(array, stride, meshPerAttribute) {
  27139. InterleavedBuffer.call(this, array, stride);
  27140. this.meshPerAttribute = meshPerAttribute || 1;
  27141. }
  27142. InstancedInterleavedBuffer.prototype = Object.assign(Object.create(InterleavedBuffer.prototype), {
  27143. constructor: InstancedInterleavedBuffer,
  27144. isInstancedInterleavedBuffer: true,
  27145. copy: function copy(source) {
  27146. InterleavedBuffer.prototype.copy.call(this, source);
  27147. this.meshPerAttribute = source.meshPerAttribute;
  27148. return this;
  27149. },
  27150. clone: function clone(data) {
  27151. var ib = InterleavedBuffer.prototype.clone.call(this, data);
  27152. ib.meshPerAttribute = this.meshPerAttribute;
  27153. return ib;
  27154. },
  27155. toJSON: function toJSON(data) {
  27156. var json = InterleavedBuffer.prototype.toJSON.call(this, data);
  27157. json.isInstancedInterleavedBuffer = true;
  27158. json.meshPerAttribute = this.meshPerAttribute;
  27159. return json;
  27160. }
  27161. });
  27162. function GLBufferAttribute(buffer, type, itemSize, elementSize, count) {
  27163. this.buffer = buffer;
  27164. this.type = type;
  27165. this.itemSize = itemSize;
  27166. this.elementSize = elementSize;
  27167. this.count = count;
  27168. this.version = 0;
  27169. }
  27170. Object.defineProperty(GLBufferAttribute.prototype, 'needsUpdate', {
  27171. set: function set(value) {
  27172. if (value === true) this.version++;
  27173. }
  27174. });
  27175. Object.assign(GLBufferAttribute.prototype, {
  27176. isGLBufferAttribute: true,
  27177. setBuffer: function setBuffer(buffer) {
  27178. this.buffer = buffer;
  27179. return this;
  27180. },
  27181. setType: function setType(type, elementSize) {
  27182. this.type = type;
  27183. this.elementSize = elementSize;
  27184. return this;
  27185. },
  27186. setItemSize: function setItemSize(itemSize) {
  27187. this.itemSize = itemSize;
  27188. return this;
  27189. },
  27190. setCount: function setCount(count) {
  27191. this.count = count;
  27192. return this;
  27193. }
  27194. });
  27195. function Raycaster(origin, direction, near, far) {
  27196. this.ray = new Ray(origin, direction); // direction is assumed to be normalized (for accurate distance calculations)
  27197. this.near = near || 0;
  27198. this.far = far || Infinity;
  27199. this.camera = null;
  27200. this.layers = new Layers();
  27201. this.params = {
  27202. Mesh: {},
  27203. Line: {
  27204. threshold: 1
  27205. },
  27206. LOD: {},
  27207. Points: {
  27208. threshold: 1
  27209. },
  27210. Sprite: {}
  27211. };
  27212. Object.defineProperties(this.params, {
  27213. PointCloud: {
  27214. get: function get() {
  27215. console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');
  27216. return this.Points;
  27217. }
  27218. }
  27219. });
  27220. }
  27221. function ascSort(a, b) {
  27222. return a.distance - b.distance;
  27223. }
  27224. function _intersectObject(object, raycaster, intersects, recursive) {
  27225. if (object.layers.test(raycaster.layers)) {
  27226. object.raycast(raycaster, intersects);
  27227. }
  27228. if (recursive === true) {
  27229. var children = object.children;
  27230. for (var i = 0, l = children.length; i < l; i++) {
  27231. _intersectObject(children[i], raycaster, intersects, true);
  27232. }
  27233. }
  27234. }
  27235. Object.assign(Raycaster.prototype, {
  27236. set: function set(origin, direction) {
  27237. // direction is assumed to be normalized (for accurate distance calculations)
  27238. this.ray.set(origin, direction);
  27239. },
  27240. setFromCamera: function setFromCamera(coords, camera) {
  27241. if (camera && camera.isPerspectiveCamera) {
  27242. this.ray.origin.setFromMatrixPosition(camera.matrixWorld);
  27243. this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(this.ray.origin).normalize();
  27244. this.camera = camera;
  27245. } else if (camera && camera.isOrthographicCamera) {
  27246. this.ray.origin.set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far)).unproject(camera); // set origin in plane of camera
  27247. this.ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
  27248. this.camera = camera;
  27249. } else {
  27250. console.error('THREE.Raycaster: Unsupported camera type: ' + camera.type);
  27251. }
  27252. },
  27253. intersectObject: function intersectObject(object, recursive, optionalTarget) {
  27254. var intersects = optionalTarget || [];
  27255. _intersectObject(object, this, intersects, recursive);
  27256. intersects.sort(ascSort);
  27257. return intersects;
  27258. },
  27259. intersectObjects: function intersectObjects(objects, recursive, optionalTarget) {
  27260. var intersects = optionalTarget || [];
  27261. if (Array.isArray(objects) === false) {
  27262. console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');
  27263. return intersects;
  27264. }
  27265. for (var i = 0, l = objects.length; i < l; i++) {
  27266. _intersectObject(objects[i], this, intersects, recursive);
  27267. }
  27268. intersects.sort(ascSort);
  27269. return intersects;
  27270. }
  27271. });
  27272. /**
  27273. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27274. *
  27275. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27276. * The azimuthal angle (theta) is measured from the positive z-axis.
  27277. */
  27278. var Spherical = /*#__PURE__*/function () {
  27279. function Spherical(radius, phi, theta) {
  27280. if (radius === void 0) {
  27281. radius = 1;
  27282. }
  27283. if (phi === void 0) {
  27284. phi = 0;
  27285. }
  27286. if (theta === void 0) {
  27287. theta = 0;
  27288. }
  27289. this.radius = radius;
  27290. this.phi = phi; // polar angle
  27291. this.theta = theta; // azimuthal angle
  27292. return this;
  27293. }
  27294. var _proto = Spherical.prototype;
  27295. _proto.set = function set(radius, phi, theta) {
  27296. this.radius = radius;
  27297. this.phi = phi;
  27298. this.theta = theta;
  27299. return this;
  27300. };
  27301. _proto.clone = function clone() {
  27302. return new this.constructor().copy(this);
  27303. };
  27304. _proto.copy = function copy(other) {
  27305. this.radius = other.radius;
  27306. this.phi = other.phi;
  27307. this.theta = other.theta;
  27308. return this;
  27309. } // restrict phi to be betwee EPS and PI-EPS
  27310. ;
  27311. _proto.makeSafe = function makeSafe() {
  27312. var EPS = 0.000001;
  27313. this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi));
  27314. return this;
  27315. };
  27316. _proto.setFromVector3 = function setFromVector3(v) {
  27317. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27318. };
  27319. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27320. this.radius = Math.sqrt(x * x + y * y + z * z);
  27321. if (this.radius === 0) {
  27322. this.theta = 0;
  27323. this.phi = 0;
  27324. } else {
  27325. this.theta = Math.atan2(x, z);
  27326. this.phi = Math.acos(MathUtils.clamp(y / this.radius, -1, 1));
  27327. }
  27328. return this;
  27329. };
  27330. return Spherical;
  27331. }();
  27332. /**
  27333. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27334. */
  27335. var Cylindrical = /*#__PURE__*/function () {
  27336. function Cylindrical(radius, theta, y) {
  27337. this.radius = radius !== undefined ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27338. this.theta = theta !== undefined ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27339. this.y = y !== undefined ? y : 0; // height above the x-z plane
  27340. return this;
  27341. }
  27342. var _proto = Cylindrical.prototype;
  27343. _proto.set = function set(radius, theta, y) {
  27344. this.radius = radius;
  27345. this.theta = theta;
  27346. this.y = y;
  27347. return this;
  27348. };
  27349. _proto.clone = function clone() {
  27350. return new this.constructor().copy(this);
  27351. };
  27352. _proto.copy = function copy(other) {
  27353. this.radius = other.radius;
  27354. this.theta = other.theta;
  27355. this.y = other.y;
  27356. return this;
  27357. };
  27358. _proto.setFromVector3 = function setFromVector3(v) {
  27359. return this.setFromCartesianCoords(v.x, v.y, v.z);
  27360. };
  27361. _proto.setFromCartesianCoords = function setFromCartesianCoords(x, y, z) {
  27362. this.radius = Math.sqrt(x * x + z * z);
  27363. this.theta = Math.atan2(x, z);
  27364. this.y = y;
  27365. return this;
  27366. };
  27367. return Cylindrical;
  27368. }();
  27369. var _vector$8 = /*@__PURE__*/new Vector2();
  27370. var Box2 = /*#__PURE__*/function () {
  27371. function Box2(min, max) {
  27372. Object.defineProperty(this, 'isBox2', {
  27373. value: true
  27374. });
  27375. this.min = min !== undefined ? min : new Vector2(+Infinity, +Infinity);
  27376. this.max = max !== undefined ? max : new Vector2(-Infinity, -Infinity);
  27377. }
  27378. var _proto = Box2.prototype;
  27379. _proto.set = function set(min, max) {
  27380. this.min.copy(min);
  27381. this.max.copy(max);
  27382. return this;
  27383. };
  27384. _proto.setFromPoints = function setFromPoints(points) {
  27385. this.makeEmpty();
  27386. for (var i = 0, il = points.length; i < il; i++) {
  27387. this.expandByPoint(points[i]);
  27388. }
  27389. return this;
  27390. };
  27391. _proto.setFromCenterAndSize = function setFromCenterAndSize(center, size) {
  27392. var halfSize = _vector$8.copy(size).multiplyScalar(0.5);
  27393. this.min.copy(center).sub(halfSize);
  27394. this.max.copy(center).add(halfSize);
  27395. return this;
  27396. };
  27397. _proto.clone = function clone() {
  27398. return new this.constructor().copy(this);
  27399. };
  27400. _proto.copy = function copy(box) {
  27401. this.min.copy(box.min);
  27402. this.max.copy(box.max);
  27403. return this;
  27404. };
  27405. _proto.makeEmpty = function makeEmpty() {
  27406. this.min.x = this.min.y = +Infinity;
  27407. this.max.x = this.max.y = -Infinity;
  27408. return this;
  27409. };
  27410. _proto.isEmpty = function isEmpty() {
  27411. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27412. return this.max.x < this.min.x || this.max.y < this.min.y;
  27413. };
  27414. _proto.getCenter = function getCenter(target) {
  27415. if (target === undefined) {
  27416. console.warn('THREE.Box2: .getCenter() target is now required');
  27417. target = new Vector2();
  27418. }
  27419. return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
  27420. };
  27421. _proto.getSize = function getSize(target) {
  27422. if (target === undefined) {
  27423. console.warn('THREE.Box2: .getSize() target is now required');
  27424. target = new Vector2();
  27425. }
  27426. return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
  27427. };
  27428. _proto.expandByPoint = function expandByPoint(point) {
  27429. this.min.min(point);
  27430. this.max.max(point);
  27431. return this;
  27432. };
  27433. _proto.expandByVector = function expandByVector(vector) {
  27434. this.min.sub(vector);
  27435. this.max.add(vector);
  27436. return this;
  27437. };
  27438. _proto.expandByScalar = function expandByScalar(scalar) {
  27439. this.min.addScalar(-scalar);
  27440. this.max.addScalar(scalar);
  27441. return this;
  27442. };
  27443. _proto.containsPoint = function containsPoint(point) {
  27444. return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
  27445. };
  27446. _proto.containsBox = function containsBox(box) {
  27447. 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;
  27448. };
  27449. _proto.getParameter = function getParameter(point, target) {
  27450. // This can potentially have a divide by zero if the box
  27451. // has a size dimension of 0.
  27452. if (target === undefined) {
  27453. console.warn('THREE.Box2: .getParameter() target is now required');
  27454. target = new Vector2();
  27455. }
  27456. 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));
  27457. };
  27458. _proto.intersectsBox = function intersectsBox(box) {
  27459. // using 4 splitting planes to rule out intersections
  27460. 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;
  27461. };
  27462. _proto.clampPoint = function clampPoint(point, target) {
  27463. if (target === undefined) {
  27464. console.warn('THREE.Box2: .clampPoint() target is now required');
  27465. target = new Vector2();
  27466. }
  27467. return target.copy(point).clamp(this.min, this.max);
  27468. };
  27469. _proto.distanceToPoint = function distanceToPoint(point) {
  27470. var clampedPoint = _vector$8.copy(point).clamp(this.min, this.max);
  27471. return clampedPoint.sub(point).length();
  27472. };
  27473. _proto.intersect = function intersect(box) {
  27474. this.min.max(box.min);
  27475. this.max.min(box.max);
  27476. return this;
  27477. };
  27478. _proto.union = function union(box) {
  27479. this.min.min(box.min);
  27480. this.max.max(box.max);
  27481. return this;
  27482. };
  27483. _proto.translate = function translate(offset) {
  27484. this.min.add(offset);
  27485. this.max.add(offset);
  27486. return this;
  27487. };
  27488. _proto.equals = function equals(box) {
  27489. return box.min.equals(this.min) && box.max.equals(this.max);
  27490. };
  27491. return Box2;
  27492. }();
  27493. var _startP = /*@__PURE__*/new Vector3();
  27494. var _startEnd = /*@__PURE__*/new Vector3();
  27495. var Line3 = /*#__PURE__*/function () {
  27496. function Line3(start, end) {
  27497. this.start = start !== undefined ? start : new Vector3();
  27498. this.end = end !== undefined ? end : new Vector3();
  27499. }
  27500. var _proto = Line3.prototype;
  27501. _proto.set = function set(start, end) {
  27502. this.start.copy(start);
  27503. this.end.copy(end);
  27504. return this;
  27505. };
  27506. _proto.clone = function clone() {
  27507. return new this.constructor().copy(this);
  27508. };
  27509. _proto.copy = function copy(line) {
  27510. this.start.copy(line.start);
  27511. this.end.copy(line.end);
  27512. return this;
  27513. };
  27514. _proto.getCenter = function getCenter(target) {
  27515. if (target === undefined) {
  27516. console.warn('THREE.Line3: .getCenter() target is now required');
  27517. target = new Vector3();
  27518. }
  27519. return target.addVectors(this.start, this.end).multiplyScalar(0.5);
  27520. };
  27521. _proto.delta = function delta(target) {
  27522. if (target === undefined) {
  27523. console.warn('THREE.Line3: .delta() target is now required');
  27524. target = new Vector3();
  27525. }
  27526. return target.subVectors(this.end, this.start);
  27527. };
  27528. _proto.distanceSq = function distanceSq() {
  27529. return this.start.distanceToSquared(this.end);
  27530. };
  27531. _proto.distance = function distance() {
  27532. return this.start.distanceTo(this.end);
  27533. };
  27534. _proto.at = function at(t, target) {
  27535. if (target === undefined) {
  27536. console.warn('THREE.Line3: .at() target is now required');
  27537. target = new Vector3();
  27538. }
  27539. return this.delta(target).multiplyScalar(t).add(this.start);
  27540. };
  27541. _proto.closestPointToPointParameter = function closestPointToPointParameter(point, clampToLine) {
  27542. _startP.subVectors(point, this.start);
  27543. _startEnd.subVectors(this.end, this.start);
  27544. var startEnd2 = _startEnd.dot(_startEnd);
  27545. var startEnd_startP = _startEnd.dot(_startP);
  27546. var t = startEnd_startP / startEnd2;
  27547. if (clampToLine) {
  27548. t = MathUtils.clamp(t, 0, 1);
  27549. }
  27550. return t;
  27551. };
  27552. _proto.closestPointToPoint = function closestPointToPoint(point, clampToLine, target) {
  27553. var t = this.closestPointToPointParameter(point, clampToLine);
  27554. if (target === undefined) {
  27555. console.warn('THREE.Line3: .closestPointToPoint() target is now required');
  27556. target = new Vector3();
  27557. }
  27558. return this.delta(target).multiplyScalar(t).add(this.start);
  27559. };
  27560. _proto.applyMatrix4 = function applyMatrix4(matrix) {
  27561. this.start.applyMatrix4(matrix);
  27562. this.end.applyMatrix4(matrix);
  27563. return this;
  27564. };
  27565. _proto.equals = function equals(line) {
  27566. return line.start.equals(this.start) && line.end.equals(this.end);
  27567. };
  27568. return Line3;
  27569. }();
  27570. function ImmediateRenderObject(material) {
  27571. Object3D.call(this);
  27572. this.material = material;
  27573. this.render = function ()
  27574. /* renderCallback */
  27575. {};
  27576. this.hasPositions = false;
  27577. this.hasNormals = false;
  27578. this.hasColors = false;
  27579. this.hasUvs = false;
  27580. this.positionArray = null;
  27581. this.normalArray = null;
  27582. this.colorArray = null;
  27583. this.uvArray = null;
  27584. this.count = 0;
  27585. }
  27586. ImmediateRenderObject.prototype = Object.create(Object3D.prototype);
  27587. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27588. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27589. var _vector$9 = /*@__PURE__*/new Vector3();
  27590. var SpotLightHelper = /*#__PURE__*/function (_Object3D) {
  27591. _inheritsLoose(SpotLightHelper, _Object3D);
  27592. function SpotLightHelper(light, color) {
  27593. var _this;
  27594. _this = _Object3D.call(this) || this;
  27595. _this.light = light;
  27596. _this.light.updateMatrixWorld();
  27597. _this.matrix = light.matrixWorld;
  27598. _this.matrixAutoUpdate = false;
  27599. _this.color = color;
  27600. var geometry = new BufferGeometry();
  27601. 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];
  27602. for (var i = 0, j = 1, l = 32; i < l; i++, j++) {
  27603. var p1 = i / l * Math.PI * 2;
  27604. var p2 = j / l * Math.PI * 2;
  27605. positions.push(Math.cos(p1), Math.sin(p1), 1, Math.cos(p2), Math.sin(p2), 1);
  27606. }
  27607. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  27608. var material = new LineBasicMaterial({
  27609. fog: false,
  27610. toneMapped: false
  27611. });
  27612. _this.cone = new LineSegments(geometry, material);
  27613. _this.add(_this.cone);
  27614. _this.update();
  27615. return _this;
  27616. }
  27617. var _proto = SpotLightHelper.prototype;
  27618. _proto.dispose = function dispose() {
  27619. this.cone.geometry.dispose();
  27620. this.cone.material.dispose();
  27621. };
  27622. _proto.update = function update() {
  27623. this.light.updateMatrixWorld();
  27624. var coneLength = this.light.distance ? this.light.distance : 1000;
  27625. var coneWidth = coneLength * Math.tan(this.light.angle);
  27626. this.cone.scale.set(coneWidth, coneWidth, coneLength);
  27627. _vector$9.setFromMatrixPosition(this.light.target.matrixWorld);
  27628. this.cone.lookAt(_vector$9);
  27629. if (this.color !== undefined) {
  27630. this.cone.material.color.set(this.color);
  27631. } else {
  27632. this.cone.material.color.copy(this.light.color);
  27633. }
  27634. };
  27635. return SpotLightHelper;
  27636. }(Object3D);
  27637. var _vector$a = /*@__PURE__*/new Vector3();
  27638. var _boneMatrix = /*@__PURE__*/new Matrix4();
  27639. var _matrixWorldInv = /*@__PURE__*/new Matrix4();
  27640. var SkeletonHelper = /*#__PURE__*/function (_LineSegments) {
  27641. _inheritsLoose(SkeletonHelper, _LineSegments);
  27642. function SkeletonHelper(object) {
  27643. var _this;
  27644. var bones = getBoneList(object);
  27645. var geometry = new BufferGeometry();
  27646. var vertices = [];
  27647. var colors = [];
  27648. var color1 = new Color(0, 0, 1);
  27649. var color2 = new Color(0, 1, 0);
  27650. for (var i = 0; i < bones.length; i++) {
  27651. var bone = bones[i];
  27652. if (bone.parent && bone.parent.isBone) {
  27653. vertices.push(0, 0, 0);
  27654. vertices.push(0, 0, 0);
  27655. colors.push(color1.r, color1.g, color1.b);
  27656. colors.push(color2.r, color2.g, color2.b);
  27657. }
  27658. }
  27659. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27660. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27661. var material = new LineBasicMaterial({
  27662. vertexColors: true,
  27663. depthTest: false,
  27664. depthWrite: false,
  27665. toneMapped: false,
  27666. transparent: true
  27667. });
  27668. _this = _LineSegments.call(this, geometry, material) || this;
  27669. _this.type = 'SkeletonHelper';
  27670. _this.isSkeletonHelper = true;
  27671. _this.root = object;
  27672. _this.bones = bones;
  27673. _this.matrix = object.matrixWorld;
  27674. _this.matrixAutoUpdate = false;
  27675. return _this;
  27676. }
  27677. var _proto = SkeletonHelper.prototype;
  27678. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  27679. var bones = this.bones;
  27680. var geometry = this.geometry;
  27681. var position = geometry.getAttribute('position');
  27682. _matrixWorldInv.copy(this.root.matrixWorld).invert();
  27683. for (var i = 0, j = 0; i < bones.length; i++) {
  27684. var bone = bones[i];
  27685. if (bone.parent && bone.parent.isBone) {
  27686. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.matrixWorld);
  27687. _vector$a.setFromMatrixPosition(_boneMatrix);
  27688. position.setXYZ(j, _vector$a.x, _vector$a.y, _vector$a.z);
  27689. _boneMatrix.multiplyMatrices(_matrixWorldInv, bone.parent.matrixWorld);
  27690. _vector$a.setFromMatrixPosition(_boneMatrix);
  27691. position.setXYZ(j + 1, _vector$a.x, _vector$a.y, _vector$a.z);
  27692. j += 2;
  27693. }
  27694. }
  27695. geometry.getAttribute('position').needsUpdate = true;
  27696. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  27697. };
  27698. return SkeletonHelper;
  27699. }(LineSegments);
  27700. function getBoneList(object) {
  27701. var boneList = [];
  27702. if (object && object.isBone) {
  27703. boneList.push(object);
  27704. }
  27705. for (var i = 0; i < object.children.length; i++) {
  27706. boneList.push.apply(boneList, getBoneList(object.children[i]));
  27707. }
  27708. return boneList;
  27709. }
  27710. var PointLightHelper = /*#__PURE__*/function (_Mesh) {
  27711. _inheritsLoose(PointLightHelper, _Mesh);
  27712. function PointLightHelper(light, sphereSize, color) {
  27713. var _this;
  27714. var geometry = new SphereGeometry(sphereSize, 4, 2);
  27715. var material = new MeshBasicMaterial({
  27716. wireframe: true,
  27717. fog: false,
  27718. toneMapped: false
  27719. });
  27720. _this = _Mesh.call(this, geometry, material) || this;
  27721. _this.light = light;
  27722. _this.light.updateMatrixWorld();
  27723. _this.color = color;
  27724. _this.type = 'PointLightHelper';
  27725. _this.matrix = _this.light.matrixWorld;
  27726. _this.matrixAutoUpdate = false;
  27727. _this.update();
  27728. /*
  27729. // TODO: delete this comment?
  27730. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27731. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27732. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27733. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27734. const d = light.distance;
  27735. if ( d === 0.0 ) {
  27736. this.lightDistance.visible = false;
  27737. } else {
  27738. this.lightDistance.scale.set( d, d, d );
  27739. }
  27740. this.add( this.lightDistance );
  27741. */
  27742. return _this;
  27743. }
  27744. var _proto = PointLightHelper.prototype;
  27745. _proto.dispose = function dispose() {
  27746. this.geometry.dispose();
  27747. this.material.dispose();
  27748. };
  27749. _proto.update = function update() {
  27750. if (this.color !== undefined) {
  27751. this.material.color.set(this.color);
  27752. } else {
  27753. this.material.color.copy(this.light.color);
  27754. }
  27755. /*
  27756. const d = this.light.distance;
  27757. if ( d === 0.0 ) {
  27758. this.lightDistance.visible = false;
  27759. } else {
  27760. this.lightDistance.visible = true;
  27761. this.lightDistance.scale.set( d, d, d );
  27762. }
  27763. */
  27764. };
  27765. return PointLightHelper;
  27766. }(Mesh);
  27767. var _vector$b = /*@__PURE__*/new Vector3();
  27768. var _color1 = /*@__PURE__*/new Color();
  27769. var _color2 = /*@__PURE__*/new Color();
  27770. var HemisphereLightHelper = /*#__PURE__*/function (_Object3D) {
  27771. _inheritsLoose(HemisphereLightHelper, _Object3D);
  27772. function HemisphereLightHelper(light, size, color) {
  27773. var _this;
  27774. _this = _Object3D.call(this) || this;
  27775. _this.light = light;
  27776. _this.light.updateMatrixWorld();
  27777. _this.matrix = light.matrixWorld;
  27778. _this.matrixAutoUpdate = false;
  27779. _this.color = color;
  27780. var geometry = new OctahedronGeometry(size);
  27781. geometry.rotateY(Math.PI * 0.5);
  27782. _this.material = new MeshBasicMaterial({
  27783. wireframe: true,
  27784. fog: false,
  27785. toneMapped: false
  27786. });
  27787. if (_this.color === undefined) _this.material.vertexColors = true;
  27788. var position = geometry.getAttribute('position');
  27789. var colors = new Float32Array(position.count * 3);
  27790. geometry.setAttribute('color', new BufferAttribute(colors, 3));
  27791. _this.add(new Mesh(geometry, _this.material));
  27792. _this.update();
  27793. return _this;
  27794. }
  27795. var _proto = HemisphereLightHelper.prototype;
  27796. _proto.dispose = function dispose() {
  27797. this.children[0].geometry.dispose();
  27798. this.children[0].material.dispose();
  27799. };
  27800. _proto.update = function update() {
  27801. var mesh = this.children[0];
  27802. if (this.color !== undefined) {
  27803. this.material.color.set(this.color);
  27804. } else {
  27805. var colors = mesh.geometry.getAttribute('color');
  27806. _color1.copy(this.light.color);
  27807. _color2.copy(this.light.groundColor);
  27808. for (var i = 0, l = colors.count; i < l; i++) {
  27809. var color = i < l / 2 ? _color1 : _color2;
  27810. colors.setXYZ(i, color.r, color.g, color.b);
  27811. }
  27812. colors.needsUpdate = true;
  27813. }
  27814. mesh.lookAt(_vector$b.setFromMatrixPosition(this.light.matrixWorld).negate());
  27815. };
  27816. return HemisphereLightHelper;
  27817. }(Object3D);
  27818. var GridHelper = /*#__PURE__*/function (_LineSegments) {
  27819. _inheritsLoose(GridHelper, _LineSegments);
  27820. function GridHelper(size, divisions, color1, color2) {
  27821. var _this;
  27822. if (size === void 0) {
  27823. size = 10;
  27824. }
  27825. if (divisions === void 0) {
  27826. divisions = 10;
  27827. }
  27828. if (color1 === void 0) {
  27829. color1 = 0x444444;
  27830. }
  27831. if (color2 === void 0) {
  27832. color2 = 0x888888;
  27833. }
  27834. color1 = new Color(color1);
  27835. color2 = new Color(color2);
  27836. var center = divisions / 2;
  27837. var step = size / divisions;
  27838. var halfSize = size / 2;
  27839. var vertices = [],
  27840. colors = [];
  27841. for (var i = 0, j = 0, k = -halfSize; i <= divisions; i++, k += step) {
  27842. vertices.push(-halfSize, 0, k, halfSize, 0, k);
  27843. vertices.push(k, 0, -halfSize, k, 0, halfSize);
  27844. var color = i === center ? color1 : color2;
  27845. color.toArray(colors, j);
  27846. j += 3;
  27847. color.toArray(colors, j);
  27848. j += 3;
  27849. color.toArray(colors, j);
  27850. j += 3;
  27851. color.toArray(colors, j);
  27852. j += 3;
  27853. }
  27854. var geometry = new BufferGeometry();
  27855. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27856. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27857. var material = new LineBasicMaterial({
  27858. vertexColors: true,
  27859. toneMapped: false
  27860. });
  27861. _this = _LineSegments.call(this, geometry, material) || this;
  27862. _this.type = 'GridHelper';
  27863. return _this;
  27864. }
  27865. return GridHelper;
  27866. }(LineSegments);
  27867. var PolarGridHelper = /*#__PURE__*/function (_LineSegments) {
  27868. _inheritsLoose(PolarGridHelper, _LineSegments);
  27869. function PolarGridHelper(radius, radials, circles, divisions, color1, color2) {
  27870. var _this;
  27871. if (radius === void 0) {
  27872. radius = 10;
  27873. }
  27874. if (radials === void 0) {
  27875. radials = 16;
  27876. }
  27877. if (circles === void 0) {
  27878. circles = 8;
  27879. }
  27880. if (divisions === void 0) {
  27881. divisions = 64;
  27882. }
  27883. if (color1 === void 0) {
  27884. color1 = 0x444444;
  27885. }
  27886. if (color2 === void 0) {
  27887. color2 = 0x888888;
  27888. }
  27889. color1 = new Color(color1);
  27890. color2 = new Color(color2);
  27891. var vertices = [];
  27892. var colors = []; // create the radials
  27893. for (var i = 0; i <= radials; i++) {
  27894. var v = i / radials * (Math.PI * 2);
  27895. var x = Math.sin(v) * radius;
  27896. var z = Math.cos(v) * radius;
  27897. vertices.push(0, 0, 0);
  27898. vertices.push(x, 0, z);
  27899. var color = i & 1 ? color1 : color2;
  27900. colors.push(color.r, color.g, color.b);
  27901. colors.push(color.r, color.g, color.b);
  27902. } // create the circles
  27903. for (var _i = 0; _i <= circles; _i++) {
  27904. var _color = _i & 1 ? color1 : color2;
  27905. var r = radius - radius / circles * _i;
  27906. for (var j = 0; j < divisions; j++) {
  27907. // first vertex
  27908. var _v = j / divisions * (Math.PI * 2);
  27909. var _x = Math.sin(_v) * r;
  27910. var _z = Math.cos(_v) * r;
  27911. vertices.push(_x, 0, _z);
  27912. colors.push(_color.r, _color.g, _color.b); // second vertex
  27913. _v = (j + 1) / divisions * (Math.PI * 2);
  27914. _x = Math.sin(_v) * r;
  27915. _z = Math.cos(_v) * r;
  27916. vertices.push(_x, 0, _z);
  27917. colors.push(_color.r, _color.g, _color.b);
  27918. }
  27919. }
  27920. var geometry = new BufferGeometry();
  27921. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  27922. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  27923. var material = new LineBasicMaterial({
  27924. vertexColors: true,
  27925. toneMapped: false
  27926. });
  27927. _this = _LineSegments.call(this, geometry, material) || this;
  27928. _this.type = 'PolarGridHelper';
  27929. return _this;
  27930. }
  27931. return PolarGridHelper;
  27932. }(LineSegments);
  27933. var _v1$6 = /*@__PURE__*/new Vector3();
  27934. var _v2$3 = /*@__PURE__*/new Vector3();
  27935. var _v3$1 = /*@__PURE__*/new Vector3();
  27936. var DirectionalLightHelper = /*#__PURE__*/function (_Object3D) {
  27937. _inheritsLoose(DirectionalLightHelper, _Object3D);
  27938. function DirectionalLightHelper(light, size, color) {
  27939. var _this;
  27940. _this = _Object3D.call(this) || this;
  27941. _this.light = light;
  27942. _this.light.updateMatrixWorld();
  27943. _this.matrix = light.matrixWorld;
  27944. _this.matrixAutoUpdate = false;
  27945. _this.color = color;
  27946. if (size === undefined) size = 1;
  27947. var geometry = new BufferGeometry();
  27948. geometry.setAttribute('position', new Float32BufferAttribute([-size, size, 0, size, size, 0, size, -size, 0, -size, -size, 0, -size, size, 0], 3));
  27949. var material = new LineBasicMaterial({
  27950. fog: false,
  27951. toneMapped: false
  27952. });
  27953. _this.lightPlane = new Line(geometry, material);
  27954. _this.add(_this.lightPlane);
  27955. geometry = new BufferGeometry();
  27956. geometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 0, 1], 3));
  27957. _this.targetLine = new Line(geometry, material);
  27958. _this.add(_this.targetLine);
  27959. _this.update();
  27960. return _this;
  27961. }
  27962. var _proto = DirectionalLightHelper.prototype;
  27963. _proto.dispose = function dispose() {
  27964. this.lightPlane.geometry.dispose();
  27965. this.lightPlane.material.dispose();
  27966. this.targetLine.geometry.dispose();
  27967. this.targetLine.material.dispose();
  27968. };
  27969. _proto.update = function update() {
  27970. _v1$6.setFromMatrixPosition(this.light.matrixWorld);
  27971. _v2$3.setFromMatrixPosition(this.light.target.matrixWorld);
  27972. _v3$1.subVectors(_v2$3, _v1$6);
  27973. this.lightPlane.lookAt(_v2$3);
  27974. if (this.color !== undefined) {
  27975. this.lightPlane.material.color.set(this.color);
  27976. this.targetLine.material.color.set(this.color);
  27977. } else {
  27978. this.lightPlane.material.color.copy(this.light.color);
  27979. this.targetLine.material.color.copy(this.light.color);
  27980. }
  27981. this.targetLine.lookAt(_v2$3);
  27982. this.targetLine.scale.z = _v3$1.length();
  27983. };
  27984. return DirectionalLightHelper;
  27985. }(Object3D);
  27986. var _vector$c = /*@__PURE__*/new Vector3();
  27987. var _camera = /*@__PURE__*/new Camera();
  27988. /**
  27989. * - shows frustum, line of sight and up of the camera
  27990. * - suitable for fast updates
  27991. * - based on frustum visualization in lightgl.js shadowmap example
  27992. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27993. */
  27994. var CameraHelper = /*#__PURE__*/function (_LineSegments) {
  27995. _inheritsLoose(CameraHelper, _LineSegments);
  27996. function CameraHelper(camera) {
  27997. var _this;
  27998. var geometry = new BufferGeometry();
  27999. var material = new LineBasicMaterial({
  28000. color: 0xffffff,
  28001. vertexColors: true,
  28002. toneMapped: false
  28003. });
  28004. var vertices = [];
  28005. var colors = [];
  28006. var pointMap = {}; // colors
  28007. var colorFrustum = new Color(0xffaa00);
  28008. var colorCone = new Color(0xff0000);
  28009. var colorUp = new Color(0x00aaff);
  28010. var colorTarget = new Color(0xffffff);
  28011. var colorCross = new Color(0x333333); // near
  28012. addLine('n1', 'n2', colorFrustum);
  28013. addLine('n2', 'n4', colorFrustum);
  28014. addLine('n4', 'n3', colorFrustum);
  28015. addLine('n3', 'n1', colorFrustum); // far
  28016. addLine('f1', 'f2', colorFrustum);
  28017. addLine('f2', 'f4', colorFrustum);
  28018. addLine('f4', 'f3', colorFrustum);
  28019. addLine('f3', 'f1', colorFrustum); // sides
  28020. addLine('n1', 'f1', colorFrustum);
  28021. addLine('n2', 'f2', colorFrustum);
  28022. addLine('n3', 'f3', colorFrustum);
  28023. addLine('n4', 'f4', colorFrustum); // cone
  28024. addLine('p', 'n1', colorCone);
  28025. addLine('p', 'n2', colorCone);
  28026. addLine('p', 'n3', colorCone);
  28027. addLine('p', 'n4', colorCone); // up
  28028. addLine('u1', 'u2', colorUp);
  28029. addLine('u2', 'u3', colorUp);
  28030. addLine('u3', 'u1', colorUp); // target
  28031. addLine('c', 't', colorTarget);
  28032. addLine('p', 'c', colorCross); // cross
  28033. addLine('cn1', 'cn2', colorCross);
  28034. addLine('cn3', 'cn4', colorCross);
  28035. addLine('cf1', 'cf2', colorCross);
  28036. addLine('cf3', 'cf4', colorCross);
  28037. function addLine(a, b, color) {
  28038. addPoint(a, color);
  28039. addPoint(b, color);
  28040. }
  28041. function addPoint(id, color) {
  28042. vertices.push(0, 0, 0);
  28043. colors.push(color.r, color.g, color.b);
  28044. if (pointMap[id] === undefined) {
  28045. pointMap[id] = [];
  28046. }
  28047. pointMap[id].push(vertices.length / 3 - 1);
  28048. }
  28049. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28050. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28051. _this = _LineSegments.call(this, geometry, material) || this;
  28052. _this.type = 'CameraHelper';
  28053. _this.camera = camera;
  28054. if (_this.camera.updateProjectionMatrix) _this.camera.updateProjectionMatrix();
  28055. _this.matrix = camera.matrixWorld;
  28056. _this.matrixAutoUpdate = false;
  28057. _this.pointMap = pointMap;
  28058. _this.update();
  28059. return _this;
  28060. }
  28061. var _proto = CameraHelper.prototype;
  28062. _proto.update = function update() {
  28063. var geometry = this.geometry;
  28064. var pointMap = this.pointMap;
  28065. var w = 1,
  28066. h = 1; // we need just camera projection matrix inverse
  28067. // world matrix must be identity
  28068. _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse); // center / target
  28069. setPoint('c', pointMap, geometry, _camera, 0, 0, -1);
  28070. setPoint('t', pointMap, geometry, _camera, 0, 0, 1); // near
  28071. setPoint('n1', pointMap, geometry, _camera, -w, -h, -1);
  28072. setPoint('n2', pointMap, geometry, _camera, w, -h, -1);
  28073. setPoint('n3', pointMap, geometry, _camera, -w, h, -1);
  28074. setPoint('n4', pointMap, geometry, _camera, w, h, -1); // far
  28075. setPoint('f1', pointMap, geometry, _camera, -w, -h, 1);
  28076. setPoint('f2', pointMap, geometry, _camera, w, -h, 1);
  28077. setPoint('f3', pointMap, geometry, _camera, -w, h, 1);
  28078. setPoint('f4', pointMap, geometry, _camera, w, h, 1); // up
  28079. setPoint('u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, -1);
  28080. setPoint('u2', pointMap, geometry, _camera, -w * 0.7, h * 1.1, -1);
  28081. setPoint('u3', pointMap, geometry, _camera, 0, h * 2, -1); // cross
  28082. setPoint('cf1', pointMap, geometry, _camera, -w, 0, 1);
  28083. setPoint('cf2', pointMap, geometry, _camera, w, 0, 1);
  28084. setPoint('cf3', pointMap, geometry, _camera, 0, -h, 1);
  28085. setPoint('cf4', pointMap, geometry, _camera, 0, h, 1);
  28086. setPoint('cn1', pointMap, geometry, _camera, -w, 0, -1);
  28087. setPoint('cn2', pointMap, geometry, _camera, w, 0, -1);
  28088. setPoint('cn3', pointMap, geometry, _camera, 0, -h, -1);
  28089. setPoint('cn4', pointMap, geometry, _camera, 0, h, -1);
  28090. geometry.getAttribute('position').needsUpdate = true;
  28091. };
  28092. return CameraHelper;
  28093. }(LineSegments);
  28094. function setPoint(point, pointMap, geometry, camera, x, y, z) {
  28095. _vector$c.set(x, y, z).unproject(camera);
  28096. var points = pointMap[point];
  28097. if (points !== undefined) {
  28098. var position = geometry.getAttribute('position');
  28099. for (var i = 0, l = points.length; i < l; i++) {
  28100. position.setXYZ(points[i], _vector$c.x, _vector$c.y, _vector$c.z);
  28101. }
  28102. }
  28103. }
  28104. var _box$3 = /*@__PURE__*/new Box3();
  28105. var BoxHelper = /*#__PURE__*/function (_LineSegments) {
  28106. _inheritsLoose(BoxHelper, _LineSegments);
  28107. function BoxHelper(object, color) {
  28108. var _this;
  28109. if (color === void 0) {
  28110. color = 0xffff00;
  28111. }
  28112. 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]);
  28113. var positions = new Float32Array(8 * 3);
  28114. var geometry = new BufferGeometry();
  28115. geometry.setIndex(new BufferAttribute(indices, 1));
  28116. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  28117. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28118. color: color,
  28119. toneMapped: false
  28120. })) || this;
  28121. _this.object = object;
  28122. _this.type = 'BoxHelper';
  28123. _this.matrixAutoUpdate = false;
  28124. _this.update();
  28125. return _this;
  28126. }
  28127. var _proto = BoxHelper.prototype;
  28128. _proto.update = function update(object) {
  28129. if (object !== undefined) {
  28130. console.warn('THREE.BoxHelper: .update() has no longer arguments.');
  28131. }
  28132. if (this.object !== undefined) {
  28133. _box$3.setFromObject(this.object);
  28134. }
  28135. if (_box$3.isEmpty()) return;
  28136. var min = _box$3.min;
  28137. var max = _box$3.max;
  28138. /*
  28139. 5____4
  28140. 1/___0/|
  28141. | 6__|_7
  28142. 2/___3/
  28143. 0: max.x, max.y, max.z
  28144. 1: min.x, max.y, max.z
  28145. 2: min.x, min.y, max.z
  28146. 3: max.x, min.y, max.z
  28147. 4: max.x, max.y, min.z
  28148. 5: min.x, max.y, min.z
  28149. 6: min.x, min.y, min.z
  28150. 7: max.x, min.y, min.z
  28151. */
  28152. var position = this.geometry.attributes.position;
  28153. var array = position.array;
  28154. array[0] = max.x;
  28155. array[1] = max.y;
  28156. array[2] = max.z;
  28157. array[3] = min.x;
  28158. array[4] = max.y;
  28159. array[5] = max.z;
  28160. array[6] = min.x;
  28161. array[7] = min.y;
  28162. array[8] = max.z;
  28163. array[9] = max.x;
  28164. array[10] = min.y;
  28165. array[11] = max.z;
  28166. array[12] = max.x;
  28167. array[13] = max.y;
  28168. array[14] = min.z;
  28169. array[15] = min.x;
  28170. array[16] = max.y;
  28171. array[17] = min.z;
  28172. array[18] = min.x;
  28173. array[19] = min.y;
  28174. array[20] = min.z;
  28175. array[21] = max.x;
  28176. array[22] = min.y;
  28177. array[23] = min.z;
  28178. position.needsUpdate = true;
  28179. this.geometry.computeBoundingSphere();
  28180. };
  28181. _proto.setFromObject = function setFromObject(object) {
  28182. this.object = object;
  28183. this.update();
  28184. return this;
  28185. };
  28186. _proto.copy = function copy(source) {
  28187. LineSegments.prototype.copy.call(this, source);
  28188. this.object = source.object;
  28189. return this;
  28190. };
  28191. return BoxHelper;
  28192. }(LineSegments);
  28193. var Box3Helper = /*#__PURE__*/function (_LineSegments) {
  28194. _inheritsLoose(Box3Helper, _LineSegments);
  28195. function Box3Helper(box, color) {
  28196. var _this;
  28197. if (color === void 0) {
  28198. color = 0xffff00;
  28199. }
  28200. 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]);
  28201. 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];
  28202. var geometry = new BufferGeometry();
  28203. geometry.setIndex(new BufferAttribute(indices, 1));
  28204. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28205. _this = _LineSegments.call(this, geometry, new LineBasicMaterial({
  28206. color: color,
  28207. toneMapped: false
  28208. })) || this;
  28209. _this.box = box;
  28210. _this.type = 'Box3Helper';
  28211. _this.geometry.computeBoundingSphere();
  28212. return _this;
  28213. }
  28214. var _proto = Box3Helper.prototype;
  28215. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28216. var box = this.box;
  28217. if (box.isEmpty()) return;
  28218. box.getCenter(this.position);
  28219. box.getSize(this.scale);
  28220. this.scale.multiplyScalar(0.5);
  28221. _LineSegments.prototype.updateMatrixWorld.call(this, force);
  28222. };
  28223. return Box3Helper;
  28224. }(LineSegments);
  28225. var PlaneHelper = /*#__PURE__*/function (_Line) {
  28226. _inheritsLoose(PlaneHelper, _Line);
  28227. function PlaneHelper(plane, size, hex) {
  28228. var _this;
  28229. if (size === void 0) {
  28230. size = 1;
  28231. }
  28232. if (hex === void 0) {
  28233. hex = 0xffff00;
  28234. }
  28235. var color = hex;
  28236. 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];
  28237. var geometry = new BufferGeometry();
  28238. geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
  28239. geometry.computeBoundingSphere();
  28240. _this = _Line.call(this, geometry, new LineBasicMaterial({
  28241. color: color,
  28242. toneMapped: false
  28243. })) || this;
  28244. _this.type = 'PlaneHelper';
  28245. _this.plane = plane;
  28246. _this.size = size;
  28247. var positions2 = [1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1];
  28248. var geometry2 = new BufferGeometry();
  28249. geometry2.setAttribute('position', new Float32BufferAttribute(positions2, 3));
  28250. geometry2.computeBoundingSphere();
  28251. _this.add(new Mesh(geometry2, new MeshBasicMaterial({
  28252. color: color,
  28253. opacity: 0.2,
  28254. transparent: true,
  28255. depthWrite: false,
  28256. toneMapped: false
  28257. })));
  28258. return _this;
  28259. }
  28260. var _proto = PlaneHelper.prototype;
  28261. _proto.updateMatrixWorld = function updateMatrixWorld(force) {
  28262. var scale = -this.plane.constant;
  28263. if (Math.abs(scale) < 1e-8) scale = 1e-8; // sign does not matter
  28264. this.scale.set(0.5 * this.size, 0.5 * this.size, scale);
  28265. this.children[0].material.side = scale < 0 ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28266. this.lookAt(this.plane.normal);
  28267. _Line.prototype.updateMatrixWorld.call(this, force);
  28268. };
  28269. return PlaneHelper;
  28270. }(Line);
  28271. var _axis = /*@__PURE__*/new Vector3();
  28272. var _lineGeometry, _coneGeometry;
  28273. var ArrowHelper = /*#__PURE__*/function (_Object3D) {
  28274. _inheritsLoose(ArrowHelper, _Object3D);
  28275. function ArrowHelper(dir, origin, length, color, headLength, headWidth) {
  28276. var _this;
  28277. _this = _Object3D.call(this) || this; // dir is assumed to be normalized
  28278. _this.type = 'ArrowHelper';
  28279. if (dir === undefined) dir = new Vector3(0, 0, 1);
  28280. if (origin === undefined) origin = new Vector3(0, 0, 0);
  28281. if (length === undefined) length = 1;
  28282. if (color === undefined) color = 0xffff00;
  28283. if (headLength === undefined) headLength = 0.2 * length;
  28284. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28285. if (_lineGeometry === undefined) {
  28286. _lineGeometry = new BufferGeometry();
  28287. _lineGeometry.setAttribute('position', new Float32BufferAttribute([0, 0, 0, 0, 1, 0], 3));
  28288. _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1);
  28289. _coneGeometry.translate(0, -0.5, 0);
  28290. }
  28291. _this.position.copy(origin);
  28292. _this.line = new Line(_lineGeometry, new LineBasicMaterial({
  28293. color: color,
  28294. toneMapped: false
  28295. }));
  28296. _this.line.matrixAutoUpdate = false;
  28297. _this.add(_this.line);
  28298. _this.cone = new Mesh(_coneGeometry, new MeshBasicMaterial({
  28299. color: color,
  28300. toneMapped: false
  28301. }));
  28302. _this.cone.matrixAutoUpdate = false;
  28303. _this.add(_this.cone);
  28304. _this.setDirection(dir);
  28305. _this.setLength(length, headLength, headWidth);
  28306. return _this;
  28307. }
  28308. var _proto = ArrowHelper.prototype;
  28309. _proto.setDirection = function setDirection(dir) {
  28310. // dir is assumed to be normalized
  28311. if (dir.y > 0.99999) {
  28312. this.quaternion.set(0, 0, 0, 1);
  28313. } else if (dir.y < -0.99999) {
  28314. this.quaternion.set(1, 0, 0, 0);
  28315. } else {
  28316. _axis.set(dir.z, 0, -dir.x).normalize();
  28317. var radians = Math.acos(dir.y);
  28318. this.quaternion.setFromAxisAngle(_axis, radians);
  28319. }
  28320. };
  28321. _proto.setLength = function setLength(length, headLength, headWidth) {
  28322. if (headLength === undefined) headLength = 0.2 * length;
  28323. if (headWidth === undefined) headWidth = 0.2 * headLength;
  28324. this.line.scale.set(1, Math.max(0.0001, length - headLength), 1); // see #17458
  28325. this.line.updateMatrix();
  28326. this.cone.scale.set(headWidth, headLength, headWidth);
  28327. this.cone.position.y = length;
  28328. this.cone.updateMatrix();
  28329. };
  28330. _proto.setColor = function setColor(color) {
  28331. this.line.material.color.set(color);
  28332. this.cone.material.color.set(color);
  28333. };
  28334. _proto.copy = function copy(source) {
  28335. _Object3D.prototype.copy.call(this, source, false);
  28336. this.line.copy(source.line);
  28337. this.cone.copy(source.cone);
  28338. return this;
  28339. };
  28340. return ArrowHelper;
  28341. }(Object3D);
  28342. var AxesHelper = /*#__PURE__*/function (_LineSegments) {
  28343. _inheritsLoose(AxesHelper, _LineSegments);
  28344. function AxesHelper(size) {
  28345. var _this;
  28346. if (size === void 0) {
  28347. size = 1;
  28348. }
  28349. var vertices = [0, 0, 0, size, 0, 0, 0, 0, 0, 0, size, 0, 0, 0, 0, 0, 0, size];
  28350. var colors = [1, 0, 0, 1, 0.6, 0, 0, 1, 0, 0.6, 1, 0, 0, 0, 1, 0, 0.6, 1];
  28351. var geometry = new BufferGeometry();
  28352. geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
  28353. geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
  28354. var material = new LineBasicMaterial({
  28355. vertexColors: true,
  28356. toneMapped: false
  28357. });
  28358. _this = _LineSegments.call(this, geometry, material) || this;
  28359. _this.type = 'AxesHelper';
  28360. return _this;
  28361. }
  28362. return AxesHelper;
  28363. }(LineSegments);
  28364. var _floatView = new Float32Array(1);
  28365. var _int32View = new Int32Array(_floatView.buffer);
  28366. var DataUtils = {
  28367. // Converts float32 to float16 (stored as uint16 value).
  28368. toHalfFloat: function toHalfFloat(val) {
  28369. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28370. /* This method is faster than the OpenEXR implementation (very often
  28371. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28372. * by James Tursa?s half-precision code. */
  28373. _floatView[0] = val;
  28374. var x = _int32View[0];
  28375. var bits = x >> 16 & 0x8000;
  28376. /* Get the sign */
  28377. var m = x >> 12 & 0x07ff;
  28378. /* Keep one extra bit for rounding */
  28379. var e = x >> 23 & 0xff;
  28380. /* Using int is faster here */
  28381. /* If zero, or denormal, or exponent underflows too much for a denormal
  28382. * half, return signed zero. */
  28383. if (e < 103) return bits;
  28384. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28385. if (e > 142) {
  28386. bits |= 0x7c00;
  28387. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28388. * not Inf, so make sure we set one mantissa bit too. */
  28389. bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
  28390. return bits;
  28391. }
  28392. /* If exponent underflows but not too much, return a denormal */
  28393. if (e < 113) {
  28394. m |= 0x0800;
  28395. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28396. * to 1, which is OK. */
  28397. bits |= (m >> 114 - e) + (m >> 113 - e & 1);
  28398. return bits;
  28399. }
  28400. bits |= e - 112 << 10 | m >> 1;
  28401. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28402. * the exponent, which is OK. */
  28403. bits += m & 1;
  28404. return bits;
  28405. }
  28406. };
  28407. var _ENCODINGS;
  28408. var LOD_MIN = 4;
  28409. var LOD_MAX = 8;
  28410. var SIZE_MAX = Math.pow(2, LOD_MAX); // The standard deviations (radians) associated with the extra mips. These are
  28411. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28412. // geometric shadowing function. These sigma values squared must match the
  28413. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28414. var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582];
  28415. 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
  28416. // samples and exit early, but not recompile the shader.
  28417. var MAX_SAMPLES = 20;
  28418. 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);
  28419. var backgroundMaterial = new MeshBasicMaterial({
  28420. side: BackSide,
  28421. depthWrite: false,
  28422. depthTest: false
  28423. });
  28424. var backgroundBox = new Mesh(new BoxGeometry(), backgroundMaterial);
  28425. var _flatCamera = /*@__PURE__*/new OrthographicCamera();
  28426. var _createPlanes2 = /*@__PURE__*/_createPlanes(),
  28427. _lodPlanes = _createPlanes2._lodPlanes,
  28428. _sizeLods = _createPlanes2._sizeLods,
  28429. _sigmas = _createPlanes2._sigmas;
  28430. var _clearColor = /*@__PURE__*/new Color();
  28431. var _oldTarget = null; // Golden Ratio
  28432. var PHI = (1 + Math.sqrt(5)) / 2;
  28433. var INV_PHI = 1 / PHI; // Vertices of a dodecahedron (except the opposites, which represent the
  28434. // same axis), used as axis directions evenly spread on a sphere.
  28435. 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)];
  28436. /**
  28437. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28438. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28439. * blur to be quickly accessed based on material roughness. It is packed into a
  28440. * special CubeUV format that allows us to perform custom interpolation so that
  28441. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28442. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28443. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28444. * higher roughness levels. In this way we maintain resolution to smoothly
  28445. * interpolate diffuse lighting while limiting sampling computation.
  28446. */
  28447. function convertLinearToRGBE(color) {
  28448. var maxComponent = Math.max(color.r, color.g, color.b);
  28449. var fExp = Math.min(Math.max(Math.ceil(Math.log2(maxComponent)), -128.0), 127.0);
  28450. color.multiplyScalar(Math.pow(2.0, -fExp));
  28451. var alpha = (fExp + 128.0) / 255.0;
  28452. return alpha;
  28453. }
  28454. var PMREMGenerator = /*#__PURE__*/function () {
  28455. function PMREMGenerator(renderer) {
  28456. this._renderer = renderer;
  28457. this._pingPongRenderTarget = null;
  28458. this._blurMaterial = _getBlurShader(MAX_SAMPLES);
  28459. this._equirectShader = null;
  28460. this._cubemapShader = null;
  28461. this._compileMaterial(this._blurMaterial);
  28462. }
  28463. /**
  28464. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28465. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28466. * in radians to be applied to the scene before PMREM generation. Optional near
  28467. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28468. * is placed at the origin).
  28469. */
  28470. var _proto = PMREMGenerator.prototype;
  28471. _proto.fromScene = function fromScene(scene, sigma, near, far) {
  28472. if (sigma === void 0) {
  28473. sigma = 0;
  28474. }
  28475. if (near === void 0) {
  28476. near = 0.1;
  28477. }
  28478. if (far === void 0) {
  28479. far = 100;
  28480. }
  28481. _oldTarget = this._renderer.getRenderTarget();
  28482. var cubeUVRenderTarget = this._allocateTargets();
  28483. this._sceneToCubeUV(scene, near, far, cubeUVRenderTarget);
  28484. if (sigma > 0) {
  28485. this._blur(cubeUVRenderTarget, 0, 0, sigma);
  28486. }
  28487. this._applyPMREM(cubeUVRenderTarget);
  28488. this._cleanup(cubeUVRenderTarget);
  28489. return cubeUVRenderTarget;
  28490. }
  28491. /**
  28492. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28493. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28494. * as this matches best with the 256 x 256 cubemap output.
  28495. */
  28496. ;
  28497. _proto.fromEquirectangular = function fromEquirectangular(equirectangular) {
  28498. return this._fromTexture(equirectangular);
  28499. }
  28500. /**
  28501. * Generates a PMREM from an cubemap texture, which can be either LDR
  28502. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28503. * as this matches best with the 256 x 256 cubemap output.
  28504. */
  28505. ;
  28506. _proto.fromCubemap = function fromCubemap(cubemap) {
  28507. return this._fromTexture(cubemap);
  28508. }
  28509. /**
  28510. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28511. * your texture's network fetch for increased concurrency.
  28512. */
  28513. ;
  28514. _proto.compileCubemapShader = function compileCubemapShader() {
  28515. if (this._cubemapShader === null) {
  28516. this._cubemapShader = _getCubemapShader();
  28517. this._compileMaterial(this._cubemapShader);
  28518. }
  28519. }
  28520. /**
  28521. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28522. * your texture's network fetch for increased concurrency.
  28523. */
  28524. ;
  28525. _proto.compileEquirectangularShader = function compileEquirectangularShader() {
  28526. if (this._equirectShader === null) {
  28527. this._equirectShader = _getEquirectShader();
  28528. this._compileMaterial(this._equirectShader);
  28529. }
  28530. }
  28531. /**
  28532. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28533. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28534. * one of them will cause any others to also become unusable.
  28535. */
  28536. ;
  28537. _proto.dispose = function dispose() {
  28538. this._blurMaterial.dispose();
  28539. if (this._cubemapShader !== null) this._cubemapShader.dispose();
  28540. if (this._equirectShader !== null) this._equirectShader.dispose();
  28541. for (var i = 0; i < _lodPlanes.length; i++) {
  28542. _lodPlanes[i].dispose();
  28543. }
  28544. } // private interface
  28545. ;
  28546. _proto._cleanup = function _cleanup(outputTarget) {
  28547. this._pingPongRenderTarget.dispose();
  28548. this._renderer.setRenderTarget(_oldTarget);
  28549. outputTarget.scissorTest = false;
  28550. _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height);
  28551. };
  28552. _proto._fromTexture = function _fromTexture(texture) {
  28553. _oldTarget = this._renderer.getRenderTarget();
  28554. var cubeUVRenderTarget = this._allocateTargets(texture);
  28555. this._textureToCubeUV(texture, cubeUVRenderTarget);
  28556. this._applyPMREM(cubeUVRenderTarget);
  28557. this._cleanup(cubeUVRenderTarget);
  28558. return cubeUVRenderTarget;
  28559. };
  28560. _proto._allocateTargets = function _allocateTargets(texture) {
  28561. // warning: null texture is valid
  28562. var params = {
  28563. magFilter: NearestFilter,
  28564. minFilter: NearestFilter,
  28565. generateMipmaps: false,
  28566. type: UnsignedByteType,
  28567. format: RGBEFormat,
  28568. encoding: _isLDR(texture) ? texture.encoding : RGBEEncoding,
  28569. depthBuffer: false
  28570. };
  28571. var cubeUVRenderTarget = _createRenderTarget(params);
  28572. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28573. this._pingPongRenderTarget = _createRenderTarget(params);
  28574. return cubeUVRenderTarget;
  28575. };
  28576. _proto._compileMaterial = function _compileMaterial(material) {
  28577. var tmpMesh = new Mesh(_lodPlanes[0], material);
  28578. this._renderer.compile(tmpMesh, _flatCamera);
  28579. };
  28580. _proto._sceneToCubeUV = function _sceneToCubeUV(scene, near, far, cubeUVRenderTarget) {
  28581. var fov = 90;
  28582. var aspect = 1;
  28583. var cubeCamera = new PerspectiveCamera(fov, aspect, near, far);
  28584. var upSign = [1, -1, 1, 1, 1, 1];
  28585. var forwardSign = [1, 1, 1, -1, -1, -1];
  28586. var renderer = this._renderer;
  28587. var originalAutoClear = renderer.autoClear;
  28588. var outputEncoding = renderer.outputEncoding;
  28589. var toneMapping = renderer.toneMapping;
  28590. renderer.getClearColor(_clearColor);
  28591. renderer.toneMapping = NoToneMapping;
  28592. renderer.outputEncoding = LinearEncoding;
  28593. renderer.autoClear = false;
  28594. var useSolidColor = false;
  28595. var background = scene.background;
  28596. if (background) {
  28597. if (background.isColor) {
  28598. backgroundMaterial.color.copy(background).convertSRGBToLinear();
  28599. scene.background = null;
  28600. var alpha = convertLinearToRGBE(backgroundMaterial.color);
  28601. backgroundMaterial.opacity = alpha;
  28602. useSolidColor = true;
  28603. }
  28604. } else {
  28605. backgroundMaterial.color.copy(_clearColor).convertSRGBToLinear();
  28606. var _alpha = convertLinearToRGBE(backgroundMaterial.color);
  28607. backgroundMaterial.opacity = _alpha;
  28608. useSolidColor = true;
  28609. }
  28610. for (var i = 0; i < 6; i++) {
  28611. var col = i % 3;
  28612. if (col == 0) {
  28613. cubeCamera.up.set(0, upSign[i], 0);
  28614. cubeCamera.lookAt(forwardSign[i], 0, 0);
  28615. } else if (col == 1) {
  28616. cubeCamera.up.set(0, 0, upSign[i]);
  28617. cubeCamera.lookAt(0, forwardSign[i], 0);
  28618. } else {
  28619. cubeCamera.up.set(0, upSign[i], 0);
  28620. cubeCamera.lookAt(0, 0, forwardSign[i]);
  28621. }
  28622. _setViewport(cubeUVRenderTarget, col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX);
  28623. renderer.setRenderTarget(cubeUVRenderTarget);
  28624. if (useSolidColor) {
  28625. renderer.render(backgroundBox, cubeCamera);
  28626. }
  28627. renderer.render(scene, cubeCamera);
  28628. }
  28629. renderer.toneMapping = toneMapping;
  28630. renderer.outputEncoding = outputEncoding;
  28631. renderer.autoClear = originalAutoClear;
  28632. };
  28633. _proto._textureToCubeUV = function _textureToCubeUV(texture, cubeUVRenderTarget) {
  28634. var renderer = this._renderer;
  28635. if (texture.isCubeTexture) {
  28636. if (this._cubemapShader == null) {
  28637. this._cubemapShader = _getCubemapShader();
  28638. }
  28639. } else {
  28640. if (this._equirectShader == null) {
  28641. this._equirectShader = _getEquirectShader();
  28642. }
  28643. }
  28644. var material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28645. var mesh = new Mesh(_lodPlanes[0], material);
  28646. var uniforms = material.uniforms;
  28647. uniforms['envMap'].value = texture;
  28648. if (!texture.isCubeTexture) {
  28649. uniforms['texelSize'].value.set(1.0 / texture.image.width, 1.0 / texture.image.height);
  28650. }
  28651. uniforms['inputEncoding'].value = ENCODINGS[texture.encoding];
  28652. uniforms['outputEncoding'].value = ENCODINGS[cubeUVRenderTarget.texture.encoding];
  28653. _setViewport(cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX);
  28654. renderer.setRenderTarget(cubeUVRenderTarget);
  28655. renderer.render(mesh, _flatCamera);
  28656. };
  28657. _proto._applyPMREM = function _applyPMREM(cubeUVRenderTarget) {
  28658. var renderer = this._renderer;
  28659. var autoClear = renderer.autoClear;
  28660. renderer.autoClear = false;
  28661. for (var i = 1; i < TOTAL_LODS; i++) {
  28662. var sigma = Math.sqrt(_sigmas[i] * _sigmas[i] - _sigmas[i - 1] * _sigmas[i - 1]);
  28663. var poleAxis = _axisDirections[(i - 1) % _axisDirections.length];
  28664. this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis);
  28665. }
  28666. renderer.autoClear = autoClear;
  28667. }
  28668. /**
  28669. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28670. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28671. * the blur latitudinally (around the poles), and then longitudinally (towards
  28672. * the poles) to approximate the orthogonally-separable blur. It is least
  28673. * accurate at the poles, but still does a decent job.
  28674. */
  28675. ;
  28676. _proto._blur = function _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) {
  28677. var pingPongRenderTarget = this._pingPongRenderTarget;
  28678. this._halfBlur(cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, 'latitudinal', poleAxis);
  28679. this._halfBlur(pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, 'longitudinal', poleAxis);
  28680. };
  28681. _proto._halfBlur = function _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) {
  28682. var renderer = this._renderer;
  28683. var blurMaterial = this._blurMaterial;
  28684. if (direction !== 'latitudinal' && direction !== 'longitudinal') {
  28685. console.error('blur direction must be either latitudinal or longitudinal!');
  28686. } // Number of standard deviations at which to cut off the discrete approximation.
  28687. var STANDARD_DEVIATIONS = 3;
  28688. var blurMesh = new Mesh(_lodPlanes[lodOut], blurMaterial);
  28689. var blurUniforms = blurMaterial.uniforms;
  28690. var pixels = _sizeLods[lodIn] - 1;
  28691. var radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1);
  28692. var sigmaPixels = sigmaRadians / radiansPerPixel;
  28693. var samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES;
  28694. if (samples > MAX_SAMPLES) {
  28695. console.warn("sigmaRadians, " + sigmaRadians + ", is too large and will clip, as it requested " + samples + " samples when the maximum is set to " + MAX_SAMPLES);
  28696. }
  28697. var weights = [];
  28698. var sum = 0;
  28699. for (var i = 0; i < MAX_SAMPLES; ++i) {
  28700. var _x = i / sigmaPixels;
  28701. var weight = Math.exp(-_x * _x / 2);
  28702. weights.push(weight);
  28703. if (i == 0) {
  28704. sum += weight;
  28705. } else if (i < samples) {
  28706. sum += 2 * weight;
  28707. }
  28708. }
  28709. for (var _i = 0; _i < weights.length; _i++) {
  28710. weights[_i] = weights[_i] / sum;
  28711. }
  28712. blurUniforms['envMap'].value = targetIn.texture;
  28713. blurUniforms['samples'].value = samples;
  28714. blurUniforms['weights'].value = weights;
  28715. blurUniforms['latitudinal'].value = direction === 'latitudinal';
  28716. if (poleAxis) {
  28717. blurUniforms['poleAxis'].value = poleAxis;
  28718. }
  28719. blurUniforms['dTheta'].value = radiansPerPixel;
  28720. blurUniforms['mipInt'].value = LOD_MAX - lodIn;
  28721. blurUniforms['inputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28722. blurUniforms['outputEncoding'].value = ENCODINGS[targetIn.texture.encoding];
  28723. var outputSize = _sizeLods[lodOut];
  28724. var x = 3 * Math.max(0, SIZE_MAX - 2 * outputSize);
  28725. var y = (lodOut === 0 ? 0 : 2 * SIZE_MAX) + 2 * outputSize * (lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0);
  28726. _setViewport(targetOut, x, y, 3 * outputSize, 2 * outputSize);
  28727. renderer.setRenderTarget(targetOut);
  28728. renderer.render(blurMesh, _flatCamera);
  28729. };
  28730. return PMREMGenerator;
  28731. }();
  28732. function _isLDR(texture) {
  28733. if (texture === undefined || texture.type !== UnsignedByteType) return false;
  28734. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28735. }
  28736. function _createPlanes() {
  28737. var _lodPlanes = [];
  28738. var _sizeLods = [];
  28739. var _sigmas = [];
  28740. var lod = LOD_MAX;
  28741. for (var i = 0; i < TOTAL_LODS; i++) {
  28742. var sizeLod = Math.pow(2, lod);
  28743. _sizeLods.push(sizeLod);
  28744. var sigma = 1.0 / sizeLod;
  28745. if (i > LOD_MAX - LOD_MIN) {
  28746. sigma = EXTRA_LOD_SIGMA[i - LOD_MAX + LOD_MIN - 1];
  28747. } else if (i == 0) {
  28748. sigma = 0;
  28749. }
  28750. _sigmas.push(sigma);
  28751. var texelSize = 1.0 / (sizeLod - 1);
  28752. var min = -texelSize / 2;
  28753. var max = 1 + texelSize / 2;
  28754. var uv1 = [min, min, max, min, max, max, min, min, max, max, min, max];
  28755. var cubeFaces = 6;
  28756. var vertices = 6;
  28757. var positionSize = 3;
  28758. var uvSize = 2;
  28759. var faceIndexSize = 1;
  28760. var position = new Float32Array(positionSize * vertices * cubeFaces);
  28761. var uv = new Float32Array(uvSize * vertices * cubeFaces);
  28762. var faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces);
  28763. for (var face = 0; face < cubeFaces; face++) {
  28764. var x = face % 3 * 2 / 3 - 1;
  28765. var y = face > 2 ? 0 : -1;
  28766. 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];
  28767. position.set(coordinates, positionSize * vertices * face);
  28768. uv.set(uv1, uvSize * vertices * face);
  28769. var fill = [face, face, face, face, face, face];
  28770. faceIndex.set(fill, faceIndexSize * vertices * face);
  28771. }
  28772. var planes = new BufferGeometry();
  28773. planes.setAttribute('position', new BufferAttribute(position, positionSize));
  28774. planes.setAttribute('uv', new BufferAttribute(uv, uvSize));
  28775. planes.setAttribute('faceIndex', new BufferAttribute(faceIndex, faceIndexSize));
  28776. _lodPlanes.push(planes);
  28777. if (lod > LOD_MIN) {
  28778. lod--;
  28779. }
  28780. }
  28781. return {
  28782. _lodPlanes: _lodPlanes,
  28783. _sizeLods: _sizeLods,
  28784. _sigmas: _sigmas
  28785. };
  28786. }
  28787. function _createRenderTarget(params) {
  28788. var cubeUVRenderTarget = new WebGLRenderTarget(3 * SIZE_MAX, 3 * SIZE_MAX, params);
  28789. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  28790. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  28791. cubeUVRenderTarget.scissorTest = true;
  28792. return cubeUVRenderTarget;
  28793. }
  28794. function _setViewport(target, x, y, width, height) {
  28795. target.viewport.set(x, y, width, height);
  28796. target.scissor.set(x, y, width, height);
  28797. }
  28798. function _getBlurShader(maxSamples) {
  28799. var weights = new Float32Array(maxSamples);
  28800. var poleAxis = new Vector3(0, 1, 0);
  28801. var shaderMaterial = new RawShaderMaterial({
  28802. name: 'SphericalGaussianBlur',
  28803. defines: {
  28804. 'n': maxSamples
  28805. },
  28806. uniforms: {
  28807. 'envMap': {
  28808. value: null
  28809. },
  28810. 'samples': {
  28811. value: 1
  28812. },
  28813. 'weights': {
  28814. value: weights
  28815. },
  28816. 'latitudinal': {
  28817. value: false
  28818. },
  28819. 'dTheta': {
  28820. value: 0
  28821. },
  28822. 'mipInt': {
  28823. value: 0
  28824. },
  28825. 'poleAxis': {
  28826. value: poleAxis
  28827. },
  28828. 'inputEncoding': {
  28829. value: ENCODINGS[LinearEncoding]
  28830. },
  28831. 'outputEncoding': {
  28832. value: ENCODINGS[LinearEncoding]
  28833. }
  28834. },
  28835. vertexShader: _getCommonVertexShader(),
  28836. fragmentShader:
  28837. /* glsl */
  28838. "\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",
  28839. blending: NoBlending,
  28840. depthTest: false,
  28841. depthWrite: false
  28842. });
  28843. return shaderMaterial;
  28844. }
  28845. function _getEquirectShader() {
  28846. var texelSize = new Vector2(1, 1);
  28847. var shaderMaterial = new RawShaderMaterial({
  28848. name: 'EquirectangularToCubeUV',
  28849. uniforms: {
  28850. 'envMap': {
  28851. value: null
  28852. },
  28853. 'texelSize': {
  28854. value: texelSize
  28855. },
  28856. 'inputEncoding': {
  28857. value: ENCODINGS[LinearEncoding]
  28858. },
  28859. 'outputEncoding': {
  28860. value: ENCODINGS[LinearEncoding]
  28861. }
  28862. },
  28863. vertexShader: _getCommonVertexShader(),
  28864. fragmentShader:
  28865. /* glsl */
  28866. "\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",
  28867. blending: NoBlending,
  28868. depthTest: false,
  28869. depthWrite: false
  28870. });
  28871. return shaderMaterial;
  28872. }
  28873. function _getCubemapShader() {
  28874. var shaderMaterial = new RawShaderMaterial({
  28875. name: 'CubemapToCubeUV',
  28876. uniforms: {
  28877. 'envMap': {
  28878. value: null
  28879. },
  28880. 'inputEncoding': {
  28881. value: ENCODINGS[LinearEncoding]
  28882. },
  28883. 'outputEncoding': {
  28884. value: ENCODINGS[LinearEncoding]
  28885. }
  28886. },
  28887. vertexShader: _getCommonVertexShader(),
  28888. fragmentShader:
  28889. /* glsl */
  28890. "\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",
  28891. blending: NoBlending,
  28892. depthTest: false,
  28893. depthWrite: false
  28894. });
  28895. return shaderMaterial;
  28896. }
  28897. function _getCommonVertexShader() {
  28898. return (
  28899. /* glsl */
  28900. "\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"
  28901. );
  28902. }
  28903. function _getEncodings() {
  28904. return (
  28905. /* glsl */
  28906. "\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"
  28907. );
  28908. }
  28909. function Face4(a, b, c, d, normal, color, materialIndex) {
  28910. console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');
  28911. return new Face3(a, b, c, normal, color, materialIndex);
  28912. }
  28913. var LineStrip = 0;
  28914. var LinePieces = 1;
  28915. var NoColors = 0;
  28916. var FaceColors = 1;
  28917. var VertexColors = 2;
  28918. function MeshFaceMaterial(materials) {
  28919. console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');
  28920. return materials;
  28921. }
  28922. function MultiMaterial(materials) {
  28923. if (materials === void 0) {
  28924. materials = [];
  28925. }
  28926. console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');
  28927. materials.isMultiMaterial = true;
  28928. materials.materials = materials;
  28929. materials.clone = function () {
  28930. return materials.slice();
  28931. };
  28932. return materials;
  28933. }
  28934. function PointCloud(geometry, material) {
  28935. console.warn('THREE.PointCloud has been renamed to THREE.Points.');
  28936. return new Points(geometry, material);
  28937. }
  28938. function Particle(material) {
  28939. console.warn('THREE.Particle has been renamed to THREE.Sprite.');
  28940. return new Sprite(material);
  28941. }
  28942. function ParticleSystem(geometry, material) {
  28943. console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');
  28944. return new Points(geometry, material);
  28945. }
  28946. function PointCloudMaterial(parameters) {
  28947. console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');
  28948. return new PointsMaterial(parameters);
  28949. }
  28950. function ParticleBasicMaterial(parameters) {
  28951. console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');
  28952. return new PointsMaterial(parameters);
  28953. }
  28954. function ParticleSystemMaterial(parameters) {
  28955. console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');
  28956. return new PointsMaterial(parameters);
  28957. }
  28958. function Vertex(x, y, z) {
  28959. console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');
  28960. return new Vector3(x, y, z);
  28961. } //
  28962. function DynamicBufferAttribute(array, itemSize) {
  28963. console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');
  28964. return new BufferAttribute(array, itemSize).setUsage(DynamicDrawUsage);
  28965. }
  28966. function Int8Attribute(array, itemSize) {
  28967. console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');
  28968. return new Int8BufferAttribute(array, itemSize);
  28969. }
  28970. function Uint8Attribute(array, itemSize) {
  28971. console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');
  28972. return new Uint8BufferAttribute(array, itemSize);
  28973. }
  28974. function Uint8ClampedAttribute(array, itemSize) {
  28975. console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');
  28976. return new Uint8ClampedBufferAttribute(array, itemSize);
  28977. }
  28978. function Int16Attribute(array, itemSize) {
  28979. console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');
  28980. return new Int16BufferAttribute(array, itemSize);
  28981. }
  28982. function Uint16Attribute(array, itemSize) {
  28983. console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');
  28984. return new Uint16BufferAttribute(array, itemSize);
  28985. }
  28986. function Int32Attribute(array, itemSize) {
  28987. console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');
  28988. return new Int32BufferAttribute(array, itemSize);
  28989. }
  28990. function Uint32Attribute(array, itemSize) {
  28991. console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');
  28992. return new Uint32BufferAttribute(array, itemSize);
  28993. }
  28994. function Float32Attribute(array, itemSize) {
  28995. console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');
  28996. return new Float32BufferAttribute(array, itemSize);
  28997. }
  28998. function Float64Attribute(array, itemSize) {
  28999. console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');
  29000. return new Float64BufferAttribute(array, itemSize);
  29001. } //
  29002. Curve.create = function (construct, getPoint) {
  29003. console.log('THREE.Curve.create() has been deprecated');
  29004. construct.prototype = Object.create(Curve.prototype);
  29005. construct.prototype.constructor = construct;
  29006. construct.prototype.getPoint = getPoint;
  29007. return construct;
  29008. }; //
  29009. Object.assign(Path.prototype, {
  29010. fromPoints: function fromPoints(points) {
  29011. console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');
  29012. return this.setFromPoints(points);
  29013. }
  29014. }); //
  29015. function ClosedSplineCurve3(points) {
  29016. console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29017. CatmullRomCurve3.call(this, points);
  29018. this.type = 'catmullrom';
  29019. this.closed = true;
  29020. }
  29021. ClosedSplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29022. function SplineCurve3(points) {
  29023. console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');
  29024. CatmullRomCurve3.call(this, points);
  29025. this.type = 'catmullrom';
  29026. }
  29027. SplineCurve3.prototype = Object.create(CatmullRomCurve3.prototype); //
  29028. function Spline(points) {
  29029. console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');
  29030. CatmullRomCurve3.call(this, points);
  29031. this.type = 'catmullrom';
  29032. }
  29033. Spline.prototype = Object.create(CatmullRomCurve3.prototype);
  29034. Object.assign(Spline.prototype, {
  29035. initFromArray: function initFromArray()
  29036. /* a */
  29037. {
  29038. console.error('THREE.Spline: .initFromArray() has been removed.');
  29039. },
  29040. getControlPointsArray: function getControlPointsArray()
  29041. /* optionalTarget */
  29042. {
  29043. console.error('THREE.Spline: .getControlPointsArray() has been removed.');
  29044. },
  29045. reparametrizeByArcLength: function reparametrizeByArcLength()
  29046. /* samplingCoef */
  29047. {
  29048. console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');
  29049. }
  29050. }); //
  29051. function AxisHelper(size) {
  29052. console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');
  29053. return new AxesHelper(size);
  29054. }
  29055. function BoundingBoxHelper(object, color) {
  29056. console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');
  29057. return new BoxHelper(object, color);
  29058. }
  29059. function EdgesHelper(object, hex) {
  29060. console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');
  29061. return new LineSegments(new EdgesGeometry(object.geometry), new LineBasicMaterial({
  29062. color: hex !== undefined ? hex : 0xffffff
  29063. }));
  29064. }
  29065. GridHelper.prototype.setColors = function () {
  29066. console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');
  29067. };
  29068. SkeletonHelper.prototype.update = function () {
  29069. console.error('THREE.SkeletonHelper: update() no longer needs to be called.');
  29070. };
  29071. function WireframeHelper(object, hex) {
  29072. console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');
  29073. return new LineSegments(new WireframeGeometry(object.geometry), new LineBasicMaterial({
  29074. color: hex !== undefined ? hex : 0xffffff
  29075. }));
  29076. } //
  29077. Object.assign(Loader.prototype, {
  29078. extractUrlBase: function extractUrlBase(url) {
  29079. console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');
  29080. return LoaderUtils.extractUrlBase(url);
  29081. }
  29082. });
  29083. Loader.Handlers = {
  29084. add: function add()
  29085. /* regex, loader */
  29086. {
  29087. console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');
  29088. },
  29089. get: function get()
  29090. /* file */
  29091. {
  29092. console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');
  29093. }
  29094. };
  29095. function XHRLoader(manager) {
  29096. console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');
  29097. return new FileLoader(manager);
  29098. }
  29099. function BinaryTextureLoader(manager) {
  29100. console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');
  29101. return new DataTextureLoader(manager);
  29102. } //
  29103. Object.assign(Box2.prototype, {
  29104. center: function center(optionalTarget) {
  29105. console.warn('THREE.Box2: .center() has been renamed to .getCenter().');
  29106. return this.getCenter(optionalTarget);
  29107. },
  29108. empty: function empty() {
  29109. console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');
  29110. return this.isEmpty();
  29111. },
  29112. isIntersectionBox: function isIntersectionBox(box) {
  29113. console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');
  29114. return this.intersectsBox(box);
  29115. },
  29116. size: function size(optionalTarget) {
  29117. console.warn('THREE.Box2: .size() has been renamed to .getSize().');
  29118. return this.getSize(optionalTarget);
  29119. }
  29120. });
  29121. Object.assign(Box3.prototype, {
  29122. center: function center(optionalTarget) {
  29123. console.warn('THREE.Box3: .center() has been renamed to .getCenter().');
  29124. return this.getCenter(optionalTarget);
  29125. },
  29126. empty: function empty() {
  29127. console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');
  29128. return this.isEmpty();
  29129. },
  29130. isIntersectionBox: function isIntersectionBox(box) {
  29131. console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');
  29132. return this.intersectsBox(box);
  29133. },
  29134. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29135. console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29136. return this.intersectsSphere(sphere);
  29137. },
  29138. size: function size(optionalTarget) {
  29139. console.warn('THREE.Box3: .size() has been renamed to .getSize().');
  29140. return this.getSize(optionalTarget);
  29141. }
  29142. });
  29143. Object.assign(Sphere.prototype, {
  29144. empty: function empty() {
  29145. console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');
  29146. return this.isEmpty();
  29147. }
  29148. });
  29149. Frustum.prototype.setFromMatrix = function (m) {
  29150. console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');
  29151. return this.setFromProjectionMatrix(m);
  29152. };
  29153. Line3.prototype.center = function (optionalTarget) {
  29154. console.warn('THREE.Line3: .center() has been renamed to .getCenter().');
  29155. return this.getCenter(optionalTarget);
  29156. };
  29157. Object.assign(MathUtils, {
  29158. random16: function random16() {
  29159. console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');
  29160. return Math.random();
  29161. },
  29162. nearestPowerOfTwo: function nearestPowerOfTwo(value) {
  29163. console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');
  29164. return MathUtils.floorPowerOfTwo(value);
  29165. },
  29166. nextPowerOfTwo: function nextPowerOfTwo(value) {
  29167. console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');
  29168. return MathUtils.ceilPowerOfTwo(value);
  29169. }
  29170. });
  29171. Object.assign(Matrix3.prototype, {
  29172. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29173. console.warn('THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29174. return this.toArray(array, offset);
  29175. },
  29176. multiplyVector3: function multiplyVector3(vector) {
  29177. console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');
  29178. return vector.applyMatrix3(this);
  29179. },
  29180. multiplyVector3Array: function multiplyVector3Array()
  29181. /* a */
  29182. {
  29183. console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');
  29184. },
  29185. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29186. console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');
  29187. return attribute.applyMatrix3(this);
  29188. },
  29189. applyToVector3Array: function applyToVector3Array()
  29190. /* array, offset, length */
  29191. {
  29192. console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');
  29193. },
  29194. getInverse: function getInverse(matrix) {
  29195. console.warn('THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29196. return this.copy(matrix).invert();
  29197. }
  29198. });
  29199. Object.assign(Matrix4.prototype, {
  29200. extractPosition: function extractPosition(m) {
  29201. console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');
  29202. return this.copyPosition(m);
  29203. },
  29204. flattenToArrayOffset: function flattenToArrayOffset(array, offset) {
  29205. console.warn('THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.');
  29206. return this.toArray(array, offset);
  29207. },
  29208. getPosition: function getPosition() {
  29209. console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');
  29210. return new Vector3().setFromMatrixColumn(this, 3);
  29211. },
  29212. setRotationFromQuaternion: function setRotationFromQuaternion(q) {
  29213. console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');
  29214. return this.makeRotationFromQuaternion(q);
  29215. },
  29216. multiplyToArray: function multiplyToArray() {
  29217. console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');
  29218. },
  29219. multiplyVector3: function multiplyVector3(vector) {
  29220. console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29221. return vector.applyMatrix4(this);
  29222. },
  29223. multiplyVector4: function multiplyVector4(vector) {
  29224. console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29225. return vector.applyMatrix4(this);
  29226. },
  29227. multiplyVector3Array: function multiplyVector3Array()
  29228. /* a */
  29229. {
  29230. console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');
  29231. },
  29232. rotateAxis: function rotateAxis(v) {
  29233. console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');
  29234. v.transformDirection(this);
  29235. },
  29236. crossVector: function crossVector(vector) {
  29237. console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');
  29238. return vector.applyMatrix4(this);
  29239. },
  29240. translate: function translate() {
  29241. console.error('THREE.Matrix4: .translate() has been removed.');
  29242. },
  29243. rotateX: function rotateX() {
  29244. console.error('THREE.Matrix4: .rotateX() has been removed.');
  29245. },
  29246. rotateY: function rotateY() {
  29247. console.error('THREE.Matrix4: .rotateY() has been removed.');
  29248. },
  29249. rotateZ: function rotateZ() {
  29250. console.error('THREE.Matrix4: .rotateZ() has been removed.');
  29251. },
  29252. rotateByAxis: function rotateByAxis() {
  29253. console.error('THREE.Matrix4: .rotateByAxis() has been removed.');
  29254. },
  29255. applyToBufferAttribute: function applyToBufferAttribute(attribute) {
  29256. console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');
  29257. return attribute.applyMatrix4(this);
  29258. },
  29259. applyToVector3Array: function applyToVector3Array()
  29260. /* array, offset, length */
  29261. {
  29262. console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');
  29263. },
  29264. makeFrustum: function makeFrustum(left, right, bottom, top, near, far) {
  29265. console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');
  29266. return this.makePerspective(left, right, top, bottom, near, far);
  29267. },
  29268. getInverse: function getInverse(matrix) {
  29269. console.warn('THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.');
  29270. return this.copy(matrix).invert();
  29271. }
  29272. });
  29273. Plane.prototype.isIntersectionLine = function (line) {
  29274. console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');
  29275. return this.intersectsLine(line);
  29276. };
  29277. Object.assign(Quaternion.prototype, {
  29278. multiplyVector3: function multiplyVector3(vector) {
  29279. console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');
  29280. return vector.applyQuaternion(this);
  29281. },
  29282. inverse: function inverse() {
  29283. console.warn('THREE.Quaternion: .inverse() has been renamed to invert().');
  29284. return this.invert();
  29285. }
  29286. });
  29287. Object.assign(Ray.prototype, {
  29288. isIntersectionBox: function isIntersectionBox(box) {
  29289. console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');
  29290. return this.intersectsBox(box);
  29291. },
  29292. isIntersectionPlane: function isIntersectionPlane(plane) {
  29293. console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');
  29294. return this.intersectsPlane(plane);
  29295. },
  29296. isIntersectionSphere: function isIntersectionSphere(sphere) {
  29297. console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');
  29298. return this.intersectsSphere(sphere);
  29299. }
  29300. });
  29301. Object.assign(Triangle.prototype, {
  29302. area: function area() {
  29303. console.warn('THREE.Triangle: .area() has been renamed to .getArea().');
  29304. return this.getArea();
  29305. },
  29306. barycoordFromPoint: function barycoordFromPoint(point, target) {
  29307. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29308. return this.getBarycoord(point, target);
  29309. },
  29310. midpoint: function midpoint(target) {
  29311. console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');
  29312. return this.getMidpoint(target);
  29313. },
  29314. normal: function normal(target) {
  29315. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29316. return this.getNormal(target);
  29317. },
  29318. plane: function plane(target) {
  29319. console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');
  29320. return this.getPlane(target);
  29321. }
  29322. });
  29323. Object.assign(Triangle, {
  29324. barycoordFromPoint: function barycoordFromPoint(point, a, b, c, target) {
  29325. console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');
  29326. return Triangle.getBarycoord(point, a, b, c, target);
  29327. },
  29328. normal: function normal(a, b, c, target) {
  29329. console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');
  29330. return Triangle.getNormal(a, b, c, target);
  29331. }
  29332. });
  29333. Object.assign(Shape.prototype, {
  29334. extractAllPoints: function extractAllPoints(divisions) {
  29335. console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');
  29336. return this.extractPoints(divisions);
  29337. },
  29338. extrude: function extrude(options) {
  29339. console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');
  29340. return new ExtrudeGeometry(this, options);
  29341. },
  29342. makeGeometry: function makeGeometry(options) {
  29343. console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');
  29344. return new ShapeGeometry(this, options);
  29345. }
  29346. });
  29347. Object.assign(Vector2.prototype, {
  29348. fromAttribute: function fromAttribute(attribute, index, offset) {
  29349. console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29350. return this.fromBufferAttribute(attribute, index, offset);
  29351. },
  29352. distanceToManhattan: function distanceToManhattan(v) {
  29353. console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29354. return this.manhattanDistanceTo(v);
  29355. },
  29356. lengthManhattan: function lengthManhattan() {
  29357. console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');
  29358. return this.manhattanLength();
  29359. }
  29360. });
  29361. Object.assign(Vector3.prototype, {
  29362. setEulerFromRotationMatrix: function setEulerFromRotationMatrix() {
  29363. console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');
  29364. },
  29365. setEulerFromQuaternion: function setEulerFromQuaternion() {
  29366. console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');
  29367. },
  29368. getPositionFromMatrix: function getPositionFromMatrix(m) {
  29369. console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');
  29370. return this.setFromMatrixPosition(m);
  29371. },
  29372. getScaleFromMatrix: function getScaleFromMatrix(m) {
  29373. console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');
  29374. return this.setFromMatrixScale(m);
  29375. },
  29376. getColumnFromMatrix: function getColumnFromMatrix(index, matrix) {
  29377. console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');
  29378. return this.setFromMatrixColumn(matrix, index);
  29379. },
  29380. applyProjection: function applyProjection(m) {
  29381. console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');
  29382. return this.applyMatrix4(m);
  29383. },
  29384. fromAttribute: function fromAttribute(attribute, index, offset) {
  29385. console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29386. return this.fromBufferAttribute(attribute, index, offset);
  29387. },
  29388. distanceToManhattan: function distanceToManhattan(v) {
  29389. console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');
  29390. return this.manhattanDistanceTo(v);
  29391. },
  29392. lengthManhattan: function lengthManhattan() {
  29393. console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');
  29394. return this.manhattanLength();
  29395. }
  29396. });
  29397. Object.assign(Vector4.prototype, {
  29398. fromAttribute: function fromAttribute(attribute, index, offset) {
  29399. console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');
  29400. return this.fromBufferAttribute(attribute, index, offset);
  29401. },
  29402. lengthManhattan: function lengthManhattan() {
  29403. console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');
  29404. return this.manhattanLength();
  29405. }
  29406. }); //
  29407. Object.assign(Object3D.prototype, {
  29408. getChildByName: function getChildByName(name) {
  29409. console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');
  29410. return this.getObjectByName(name);
  29411. },
  29412. renderDepth: function renderDepth() {
  29413. console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');
  29414. },
  29415. translate: function translate(distance, axis) {
  29416. console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');
  29417. return this.translateOnAxis(axis, distance);
  29418. },
  29419. getWorldRotation: function getWorldRotation() {
  29420. console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');
  29421. },
  29422. applyMatrix: function applyMatrix(matrix) {
  29423. console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');
  29424. return this.applyMatrix4(matrix);
  29425. }
  29426. });
  29427. Object.defineProperties(Object3D.prototype, {
  29428. eulerOrder: {
  29429. get: function get() {
  29430. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29431. return this.rotation.order;
  29432. },
  29433. set: function set(value) {
  29434. console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');
  29435. this.rotation.order = value;
  29436. }
  29437. },
  29438. useQuaternion: {
  29439. get: function get() {
  29440. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29441. },
  29442. set: function set() {
  29443. console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');
  29444. }
  29445. }
  29446. });
  29447. Object.assign(Mesh.prototype, {
  29448. setDrawMode: function setDrawMode() {
  29449. console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29450. }
  29451. });
  29452. Object.defineProperties(Mesh.prototype, {
  29453. drawMode: {
  29454. get: function get() {
  29455. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');
  29456. return TrianglesDrawMode;
  29457. },
  29458. set: function set() {
  29459. console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');
  29460. }
  29461. }
  29462. });
  29463. Object.defineProperties(LOD.prototype, {
  29464. objects: {
  29465. get: function get() {
  29466. console.warn('THREE.LOD: .objects has been renamed to .levels.');
  29467. return this.levels;
  29468. }
  29469. }
  29470. });
  29471. Object.defineProperty(Skeleton.prototype, 'useVertexTexture', {
  29472. get: function get() {
  29473. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29474. },
  29475. set: function set() {
  29476. console.warn('THREE.Skeleton: useVertexTexture has been removed.');
  29477. }
  29478. });
  29479. SkinnedMesh.prototype.initBones = function () {
  29480. console.error('THREE.SkinnedMesh: initBones() has been removed.');
  29481. };
  29482. Object.defineProperty(Curve.prototype, '__arcLengthDivisions', {
  29483. get: function get() {
  29484. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29485. return this.arcLengthDivisions;
  29486. },
  29487. set: function set(value) {
  29488. console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');
  29489. this.arcLengthDivisions = value;
  29490. }
  29491. }); //
  29492. PerspectiveCamera.prototype.setLens = function (focalLength, filmGauge) {
  29493. console.warn('THREE.PerspectiveCamera.setLens is deprecated. ' + 'Use .setFocalLength and .filmGauge for a photographic setup.');
  29494. if (filmGauge !== undefined) this.filmGauge = filmGauge;
  29495. this.setFocalLength(focalLength);
  29496. }; //
  29497. Object.defineProperties(Light.prototype, {
  29498. onlyShadow: {
  29499. set: function set() {
  29500. console.warn('THREE.Light: .onlyShadow has been removed.');
  29501. }
  29502. },
  29503. shadowCameraFov: {
  29504. set: function set(value) {
  29505. console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');
  29506. this.shadow.camera.fov = value;
  29507. }
  29508. },
  29509. shadowCameraLeft: {
  29510. set: function set(value) {
  29511. console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');
  29512. this.shadow.camera.left = value;
  29513. }
  29514. },
  29515. shadowCameraRight: {
  29516. set: function set(value) {
  29517. console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');
  29518. this.shadow.camera.right = value;
  29519. }
  29520. },
  29521. shadowCameraTop: {
  29522. set: function set(value) {
  29523. console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');
  29524. this.shadow.camera.top = value;
  29525. }
  29526. },
  29527. shadowCameraBottom: {
  29528. set: function set(value) {
  29529. console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');
  29530. this.shadow.camera.bottom = value;
  29531. }
  29532. },
  29533. shadowCameraNear: {
  29534. set: function set(value) {
  29535. console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');
  29536. this.shadow.camera.near = value;
  29537. }
  29538. },
  29539. shadowCameraFar: {
  29540. set: function set(value) {
  29541. console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');
  29542. this.shadow.camera.far = value;
  29543. }
  29544. },
  29545. shadowCameraVisible: {
  29546. set: function set() {
  29547. console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');
  29548. }
  29549. },
  29550. shadowBias: {
  29551. set: function set(value) {
  29552. console.warn('THREE.Light: .shadowBias is now .shadow.bias.');
  29553. this.shadow.bias = value;
  29554. }
  29555. },
  29556. shadowDarkness: {
  29557. set: function set() {
  29558. console.warn('THREE.Light: .shadowDarkness has been removed.');
  29559. }
  29560. },
  29561. shadowMapWidth: {
  29562. set: function set(value) {
  29563. console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');
  29564. this.shadow.mapSize.width = value;
  29565. }
  29566. },
  29567. shadowMapHeight: {
  29568. set: function set(value) {
  29569. console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');
  29570. this.shadow.mapSize.height = value;
  29571. }
  29572. }
  29573. }); //
  29574. Object.defineProperties(BufferAttribute.prototype, {
  29575. length: {
  29576. get: function get() {
  29577. console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');
  29578. return this.array.length;
  29579. }
  29580. },
  29581. dynamic: {
  29582. get: function get() {
  29583. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29584. return this.usage === DynamicDrawUsage;
  29585. },
  29586. set: function set()
  29587. /* value */
  29588. {
  29589. console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');
  29590. this.setUsage(DynamicDrawUsage);
  29591. }
  29592. }
  29593. });
  29594. Object.assign(BufferAttribute.prototype, {
  29595. setDynamic: function setDynamic(value) {
  29596. console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29597. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29598. return this;
  29599. },
  29600. copyIndicesArray: function copyIndicesArray()
  29601. /* indices */
  29602. {
  29603. console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');
  29604. },
  29605. setArray: function setArray()
  29606. /* array */
  29607. {
  29608. console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29609. }
  29610. });
  29611. Object.assign(BufferGeometry.prototype, {
  29612. addIndex: function addIndex(index) {
  29613. console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');
  29614. this.setIndex(index);
  29615. },
  29616. addAttribute: function addAttribute(name, attribute) {
  29617. console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');
  29618. if (!(attribute && attribute.isBufferAttribute) && !(attribute && attribute.isInterleavedBufferAttribute)) {
  29619. console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');
  29620. return this.setAttribute(name, new BufferAttribute(arguments[1], arguments[2]));
  29621. }
  29622. if (name === 'index') {
  29623. console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');
  29624. this.setIndex(attribute);
  29625. return this;
  29626. }
  29627. return this.setAttribute(name, attribute);
  29628. },
  29629. addDrawCall: function addDrawCall(start, count, indexOffset) {
  29630. if (indexOffset !== undefined) {
  29631. console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');
  29632. }
  29633. console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');
  29634. this.addGroup(start, count);
  29635. },
  29636. clearDrawCalls: function clearDrawCalls() {
  29637. console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');
  29638. this.clearGroups();
  29639. },
  29640. computeOffsets: function computeOffsets() {
  29641. console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');
  29642. },
  29643. removeAttribute: function removeAttribute(name) {
  29644. console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');
  29645. return this.deleteAttribute(name);
  29646. },
  29647. applyMatrix: function applyMatrix(matrix) {
  29648. console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');
  29649. return this.applyMatrix4(matrix);
  29650. }
  29651. });
  29652. Object.defineProperties(BufferGeometry.prototype, {
  29653. drawcalls: {
  29654. get: function get() {
  29655. console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');
  29656. return this.groups;
  29657. }
  29658. },
  29659. offsets: {
  29660. get: function get() {
  29661. console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');
  29662. return this.groups;
  29663. }
  29664. }
  29665. });
  29666. Object.defineProperties(InstancedBufferGeometry.prototype, {
  29667. maxInstancedCount: {
  29668. get: function get() {
  29669. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29670. return this.instanceCount;
  29671. },
  29672. set: function set(value) {
  29673. console.warn('THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.');
  29674. this.instanceCount = value;
  29675. }
  29676. }
  29677. });
  29678. Object.defineProperties(Raycaster.prototype, {
  29679. linePrecision: {
  29680. get: function get() {
  29681. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29682. return this.params.Line.threshold;
  29683. },
  29684. set: function set(value) {
  29685. console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');
  29686. this.params.Line.threshold = value;
  29687. }
  29688. }
  29689. });
  29690. Object.defineProperties(InterleavedBuffer.prototype, {
  29691. dynamic: {
  29692. get: function get() {
  29693. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29694. return this.usage === DynamicDrawUsage;
  29695. },
  29696. set: function set(value) {
  29697. console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');
  29698. this.setUsage(value);
  29699. }
  29700. }
  29701. });
  29702. Object.assign(InterleavedBuffer.prototype, {
  29703. setDynamic: function setDynamic(value) {
  29704. console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');
  29705. this.setUsage(value === true ? DynamicDrawUsage : StaticDrawUsage);
  29706. return this;
  29707. },
  29708. setArray: function setArray()
  29709. /* array */
  29710. {
  29711. console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');
  29712. }
  29713. }); //
  29714. Object.assign(ExtrudeGeometry.prototype, {
  29715. getArrays: function getArrays() {
  29716. console.error('THREE.ExtrudeGeometry: .getArrays() has been removed.');
  29717. },
  29718. addShapeList: function addShapeList() {
  29719. console.error('THREE.ExtrudeGeometry: .addShapeList() has been removed.');
  29720. },
  29721. addShape: function addShape() {
  29722. console.error('THREE.ExtrudeGeometry: .addShape() has been removed.');
  29723. }
  29724. }); //
  29725. Object.assign(Scene.prototype, {
  29726. dispose: function dispose() {
  29727. console.error('THREE.Scene: .dispose() has been removed.');
  29728. }
  29729. }); //
  29730. Object.defineProperties(Uniform.prototype, {
  29731. dynamic: {
  29732. set: function set() {
  29733. console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');
  29734. }
  29735. },
  29736. onUpdate: {
  29737. value: function value() {
  29738. console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');
  29739. return this;
  29740. }
  29741. }
  29742. }); //
  29743. Object.defineProperties(Material.prototype, {
  29744. wrapAround: {
  29745. get: function get() {
  29746. console.warn('THREE.Material: .wrapAround has been removed.');
  29747. },
  29748. set: function set() {
  29749. console.warn('THREE.Material: .wrapAround has been removed.');
  29750. }
  29751. },
  29752. overdraw: {
  29753. get: function get() {
  29754. console.warn('THREE.Material: .overdraw has been removed.');
  29755. },
  29756. set: function set() {
  29757. console.warn('THREE.Material: .overdraw has been removed.');
  29758. }
  29759. },
  29760. wrapRGB: {
  29761. get: function get() {
  29762. console.warn('THREE.Material: .wrapRGB has been removed.');
  29763. return new Color();
  29764. }
  29765. },
  29766. shading: {
  29767. get: function get() {
  29768. console.error('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29769. },
  29770. set: function set(value) {
  29771. console.warn('THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.');
  29772. this.flatShading = value === FlatShading;
  29773. }
  29774. },
  29775. stencilMask: {
  29776. get: function get() {
  29777. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29778. return this.stencilFuncMask;
  29779. },
  29780. set: function set(value) {
  29781. console.warn('THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.');
  29782. this.stencilFuncMask = value;
  29783. }
  29784. }
  29785. });
  29786. Object.defineProperties(MeshPhongMaterial.prototype, {
  29787. metal: {
  29788. get: function get() {
  29789. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');
  29790. return false;
  29791. },
  29792. set: function set() {
  29793. console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');
  29794. }
  29795. }
  29796. });
  29797. Object.defineProperties(MeshPhysicalMaterial.prototype, {
  29798. transparency: {
  29799. get: function get() {
  29800. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29801. return this.transmission;
  29802. },
  29803. set: function set(value) {
  29804. console.warn('THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.');
  29805. this.transmission = value;
  29806. }
  29807. }
  29808. });
  29809. Object.defineProperties(ShaderMaterial.prototype, {
  29810. derivatives: {
  29811. get: function get() {
  29812. console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29813. return this.extensions.derivatives;
  29814. },
  29815. set: function set(value) {
  29816. console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');
  29817. this.extensions.derivatives = value;
  29818. }
  29819. }
  29820. }); //
  29821. Object.assign(WebGLRenderer.prototype, {
  29822. clearTarget: function clearTarget(renderTarget, color, depth, stencil) {
  29823. console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');
  29824. this.setRenderTarget(renderTarget);
  29825. this.clear(color, depth, stencil);
  29826. },
  29827. animate: function animate(callback) {
  29828. console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');
  29829. this.setAnimationLoop(callback);
  29830. },
  29831. getCurrentRenderTarget: function getCurrentRenderTarget() {
  29832. console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');
  29833. return this.getRenderTarget();
  29834. },
  29835. getMaxAnisotropy: function getMaxAnisotropy() {
  29836. console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');
  29837. return this.capabilities.getMaxAnisotropy();
  29838. },
  29839. getPrecision: function getPrecision() {
  29840. console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');
  29841. return this.capabilities.precision;
  29842. },
  29843. resetGLState: function resetGLState() {
  29844. console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');
  29845. return this.state.reset();
  29846. },
  29847. supportsFloatTextures: function supportsFloatTextures() {
  29848. console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');
  29849. return this.extensions.get('OES_texture_float');
  29850. },
  29851. supportsHalfFloatTextures: function supportsHalfFloatTextures() {
  29852. console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');
  29853. return this.extensions.get('OES_texture_half_float');
  29854. },
  29855. supportsStandardDerivatives: function supportsStandardDerivatives() {
  29856. console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');
  29857. return this.extensions.get('OES_standard_derivatives');
  29858. },
  29859. supportsCompressedTextureS3TC: function supportsCompressedTextureS3TC() {
  29860. console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');
  29861. return this.extensions.get('WEBGL_compressed_texture_s3tc');
  29862. },
  29863. supportsCompressedTexturePVRTC: function supportsCompressedTexturePVRTC() {
  29864. console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');
  29865. return this.extensions.get('WEBGL_compressed_texture_pvrtc');
  29866. },
  29867. supportsBlendMinMax: function supportsBlendMinMax() {
  29868. console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');
  29869. return this.extensions.get('EXT_blend_minmax');
  29870. },
  29871. supportsVertexTextures: function supportsVertexTextures() {
  29872. console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');
  29873. return this.capabilities.vertexTextures;
  29874. },
  29875. supportsInstancedArrays: function supportsInstancedArrays() {
  29876. console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');
  29877. return this.extensions.get('ANGLE_instanced_arrays');
  29878. },
  29879. enableScissorTest: function enableScissorTest(boolean) {
  29880. console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');
  29881. this.setScissorTest(boolean);
  29882. },
  29883. initMaterial: function initMaterial() {
  29884. console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');
  29885. },
  29886. addPrePlugin: function addPrePlugin() {
  29887. console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');
  29888. },
  29889. addPostPlugin: function addPostPlugin() {
  29890. console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');
  29891. },
  29892. updateShadowMap: function updateShadowMap() {
  29893. console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');
  29894. },
  29895. setFaceCulling: function setFaceCulling() {
  29896. console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');
  29897. },
  29898. allocTextureUnit: function allocTextureUnit() {
  29899. console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');
  29900. },
  29901. setTexture: function setTexture() {
  29902. console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');
  29903. },
  29904. setTexture2D: function setTexture2D() {
  29905. console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');
  29906. },
  29907. setTextureCube: function setTextureCube() {
  29908. console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');
  29909. },
  29910. getActiveMipMapLevel: function getActiveMipMapLevel() {
  29911. console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');
  29912. return this.getActiveMipmapLevel();
  29913. }
  29914. });
  29915. Object.defineProperties(WebGLRenderer.prototype, {
  29916. shadowMapEnabled: {
  29917. get: function get() {
  29918. return this.shadowMap.enabled;
  29919. },
  29920. set: function set(value) {
  29921. console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');
  29922. this.shadowMap.enabled = value;
  29923. }
  29924. },
  29925. shadowMapType: {
  29926. get: function get() {
  29927. return this.shadowMap.type;
  29928. },
  29929. set: function set(value) {
  29930. console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');
  29931. this.shadowMap.type = value;
  29932. }
  29933. },
  29934. shadowMapCullFace: {
  29935. get: function get() {
  29936. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29937. return undefined;
  29938. },
  29939. set: function set()
  29940. /* value */
  29941. {
  29942. console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');
  29943. }
  29944. },
  29945. context: {
  29946. get: function get() {
  29947. console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');
  29948. return this.getContext();
  29949. }
  29950. },
  29951. vr: {
  29952. get: function get() {
  29953. console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');
  29954. return this.xr;
  29955. }
  29956. },
  29957. gammaInput: {
  29958. get: function get() {
  29959. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29960. return false;
  29961. },
  29962. set: function set() {
  29963. console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');
  29964. }
  29965. },
  29966. gammaOutput: {
  29967. get: function get() {
  29968. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29969. return false;
  29970. },
  29971. set: function set(value) {
  29972. console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');
  29973. this.outputEncoding = value === true ? sRGBEncoding : LinearEncoding;
  29974. }
  29975. },
  29976. toneMappingWhitePoint: {
  29977. get: function get() {
  29978. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29979. return 1.0;
  29980. },
  29981. set: function set() {
  29982. console.warn('THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.');
  29983. }
  29984. }
  29985. });
  29986. Object.defineProperties(WebGLShadowMap.prototype, {
  29987. cullFace: {
  29988. get: function get() {
  29989. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29990. return undefined;
  29991. },
  29992. set: function set()
  29993. /* cullFace */
  29994. {
  29995. console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');
  29996. }
  29997. },
  29998. renderReverseSided: {
  29999. get: function get() {
  30000. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30001. return undefined;
  30002. },
  30003. set: function set() {
  30004. console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');
  30005. }
  30006. },
  30007. renderSingleSided: {
  30008. get: function get() {
  30009. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30010. return undefined;
  30011. },
  30012. set: function set() {
  30013. console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');
  30014. }
  30015. }
  30016. });
  30017. function WebGLRenderTargetCube(width, height, options) {
  30018. console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');
  30019. return new WebGLCubeRenderTarget(width, options);
  30020. } //
  30021. Object.defineProperties(WebGLRenderTarget.prototype, {
  30022. wrapS: {
  30023. get: function get() {
  30024. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30025. return this.texture.wrapS;
  30026. },
  30027. set: function set(value) {
  30028. console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');
  30029. this.texture.wrapS = value;
  30030. }
  30031. },
  30032. wrapT: {
  30033. get: function get() {
  30034. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30035. return this.texture.wrapT;
  30036. },
  30037. set: function set(value) {
  30038. console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');
  30039. this.texture.wrapT = value;
  30040. }
  30041. },
  30042. magFilter: {
  30043. get: function get() {
  30044. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30045. return this.texture.magFilter;
  30046. },
  30047. set: function set(value) {
  30048. console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');
  30049. this.texture.magFilter = value;
  30050. }
  30051. },
  30052. minFilter: {
  30053. get: function get() {
  30054. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30055. return this.texture.minFilter;
  30056. },
  30057. set: function set(value) {
  30058. console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');
  30059. this.texture.minFilter = value;
  30060. }
  30061. },
  30062. anisotropy: {
  30063. get: function get() {
  30064. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30065. return this.texture.anisotropy;
  30066. },
  30067. set: function set(value) {
  30068. console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');
  30069. this.texture.anisotropy = value;
  30070. }
  30071. },
  30072. offset: {
  30073. get: function get() {
  30074. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30075. return this.texture.offset;
  30076. },
  30077. set: function set(value) {
  30078. console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');
  30079. this.texture.offset = value;
  30080. }
  30081. },
  30082. repeat: {
  30083. get: function get() {
  30084. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30085. return this.texture.repeat;
  30086. },
  30087. set: function set(value) {
  30088. console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');
  30089. this.texture.repeat = value;
  30090. }
  30091. },
  30092. format: {
  30093. get: function get() {
  30094. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30095. return this.texture.format;
  30096. },
  30097. set: function set(value) {
  30098. console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');
  30099. this.texture.format = value;
  30100. }
  30101. },
  30102. type: {
  30103. get: function get() {
  30104. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30105. return this.texture.type;
  30106. },
  30107. set: function set(value) {
  30108. console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');
  30109. this.texture.type = value;
  30110. }
  30111. },
  30112. generateMipmaps: {
  30113. get: function get() {
  30114. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30115. return this.texture.generateMipmaps;
  30116. },
  30117. set: function set(value) {
  30118. console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');
  30119. this.texture.generateMipmaps = value;
  30120. }
  30121. }
  30122. }); //
  30123. Object.defineProperties(Audio.prototype, {
  30124. load: {
  30125. value: function value(file) {
  30126. console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');
  30127. var scope = this;
  30128. var audioLoader = new AudioLoader();
  30129. audioLoader.load(file, function (buffer) {
  30130. scope.setBuffer(buffer);
  30131. });
  30132. return this;
  30133. }
  30134. },
  30135. startTime: {
  30136. set: function set() {
  30137. console.warn('THREE.Audio: .startTime is now .play( delay ).');
  30138. }
  30139. }
  30140. });
  30141. AudioAnalyser.prototype.getData = function () {
  30142. console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');
  30143. return this.getFrequencyData();
  30144. }; //
  30145. CubeCamera.prototype.updateCubeMap = function (renderer, scene) {
  30146. console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');
  30147. return this.update(renderer, scene);
  30148. };
  30149. CubeCamera.prototype.clear = function (renderer, color, depth, stencil) {
  30150. console.warn('THREE.CubeCamera: .clear() is now .renderTarget.clear().');
  30151. return this.renderTarget.clear(renderer, color, depth, stencil);
  30152. }; //
  30153. var GeometryUtils = {
  30154. merge: function merge(geometry1, geometry2, materialIndexOffset) {
  30155. console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');
  30156. var matrix;
  30157. if (geometry2.isMesh) {
  30158. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30159. matrix = geometry2.matrix;
  30160. geometry2 = geometry2.geometry;
  30161. }
  30162. geometry1.merge(geometry2, matrix, materialIndexOffset);
  30163. },
  30164. center: function center(geometry) {
  30165. console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');
  30166. return geometry.center();
  30167. }
  30168. };
  30169. ImageUtils.crossOrigin = undefined;
  30170. ImageUtils.loadTexture = function (url, mapping, onLoad, onError) {
  30171. console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');
  30172. var loader = new TextureLoader();
  30173. loader.setCrossOrigin(this.crossOrigin);
  30174. var texture = loader.load(url, onLoad, undefined, onError);
  30175. if (mapping) texture.mapping = mapping;
  30176. return texture;
  30177. };
  30178. ImageUtils.loadTextureCube = function (urls, mapping, onLoad, onError) {
  30179. console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');
  30180. var loader = new CubeTextureLoader();
  30181. loader.setCrossOrigin(this.crossOrigin);
  30182. var texture = loader.load(urls, onLoad, undefined, onError);
  30183. if (mapping) texture.mapping = mapping;
  30184. return texture;
  30185. };
  30186. ImageUtils.loadCompressedTexture = function () {
  30187. console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');
  30188. };
  30189. ImageUtils.loadCompressedTextureCube = function () {
  30190. console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');
  30191. }; //
  30192. function CanvasRenderer() {
  30193. console.error('THREE.CanvasRenderer has been removed');
  30194. } //
  30195. function JSONLoader() {
  30196. console.error('THREE.JSONLoader has been removed.');
  30197. } //
  30198. var SceneUtils = {
  30199. createMultiMaterialObject: function createMultiMaterialObject()
  30200. /* geometry, materials */
  30201. {
  30202. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30203. },
  30204. detach: function detach()
  30205. /* child, parent, scene */
  30206. {
  30207. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30208. },
  30209. attach: function attach()
  30210. /* child, scene, parent */
  30211. {
  30212. console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');
  30213. }
  30214. }; //
  30215. function LensFlare() {
  30216. console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');
  30217. }
  30218. if (typeof __THREE_DEVTOOLS__ !== 'undefined') {
  30219. /* eslint-disable no-undef */
  30220. __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register', {
  30221. detail: {
  30222. revision: REVISION
  30223. }
  30224. }));
  30225. /* eslint-enable no-undef */
  30226. }
  30227. if (typeof window !== 'undefined') {
  30228. if (window.__THREE__) {
  30229. console.warn('WARNING: Multiple instances of Three.js being imported.');
  30230. } else {
  30231. window.__THREE__ = REVISION;
  30232. }
  30233. }
  30234. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  30235. exports.AddEquation = AddEquation;
  30236. exports.AddOperation = AddOperation;
  30237. exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
  30238. exports.AdditiveBlending = AdditiveBlending;
  30239. exports.AlphaFormat = AlphaFormat;
  30240. exports.AlwaysDepth = AlwaysDepth;
  30241. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  30242. exports.AmbientLight = AmbientLight;
  30243. exports.AmbientLightProbe = AmbientLightProbe;
  30244. exports.AnimationClip = AnimationClip;
  30245. exports.AnimationLoader = AnimationLoader;
  30246. exports.AnimationMixer = AnimationMixer;
  30247. exports.AnimationObjectGroup = AnimationObjectGroup;
  30248. exports.AnimationUtils = AnimationUtils;
  30249. exports.ArcCurve = ArcCurve;
  30250. exports.ArrayCamera = ArrayCamera;
  30251. exports.ArrowHelper = ArrowHelper;
  30252. exports.Audio = Audio;
  30253. exports.AudioAnalyser = AudioAnalyser;
  30254. exports.AudioContext = AudioContext;
  30255. exports.AudioListener = AudioListener;
  30256. exports.AudioLoader = AudioLoader;
  30257. exports.AxesHelper = AxesHelper;
  30258. exports.AxisHelper = AxisHelper;
  30259. exports.BackSide = BackSide;
  30260. exports.BasicDepthPacking = BasicDepthPacking;
  30261. exports.BasicShadowMap = BasicShadowMap;
  30262. exports.BinaryTextureLoader = BinaryTextureLoader;
  30263. exports.Bone = Bone;
  30264. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  30265. exports.BoundingBoxHelper = BoundingBoxHelper;
  30266. exports.Box2 = Box2;
  30267. exports.Box3 = Box3;
  30268. exports.Box3Helper = Box3Helper;
  30269. exports.BoxBufferGeometry = BoxGeometry;
  30270. exports.BoxGeometry = BoxGeometry;
  30271. exports.BoxHelper = BoxHelper;
  30272. exports.BufferAttribute = BufferAttribute;
  30273. exports.BufferGeometry = BufferGeometry;
  30274. exports.BufferGeometryLoader = BufferGeometryLoader;
  30275. exports.ByteType = ByteType;
  30276. exports.Cache = Cache;
  30277. exports.Camera = Camera;
  30278. exports.CameraHelper = CameraHelper;
  30279. exports.CanvasRenderer = CanvasRenderer;
  30280. exports.CanvasTexture = CanvasTexture;
  30281. exports.CatmullRomCurve3 = CatmullRomCurve3;
  30282. exports.CineonToneMapping = CineonToneMapping;
  30283. exports.CircleBufferGeometry = CircleGeometry;
  30284. exports.CircleGeometry = CircleGeometry;
  30285. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  30286. exports.Clock = Clock;
  30287. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  30288. exports.Color = Color;
  30289. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  30290. exports.CompressedTexture = CompressedTexture;
  30291. exports.CompressedTextureLoader = CompressedTextureLoader;
  30292. exports.ConeBufferGeometry = ConeGeometry;
  30293. exports.ConeGeometry = ConeGeometry;
  30294. exports.CubeCamera = CubeCamera;
  30295. exports.CubeReflectionMapping = CubeReflectionMapping;
  30296. exports.CubeRefractionMapping = CubeRefractionMapping;
  30297. exports.CubeTexture = CubeTexture;
  30298. exports.CubeTextureLoader = CubeTextureLoader;
  30299. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  30300. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  30301. exports.CubicBezierCurve = CubicBezierCurve;
  30302. exports.CubicBezierCurve3 = CubicBezierCurve3;
  30303. exports.CubicInterpolant = CubicInterpolant;
  30304. exports.CullFaceBack = CullFaceBack;
  30305. exports.CullFaceFront = CullFaceFront;
  30306. exports.CullFaceFrontBack = CullFaceFrontBack;
  30307. exports.CullFaceNone = CullFaceNone;
  30308. exports.Curve = Curve;
  30309. exports.CurvePath = CurvePath;
  30310. exports.CustomBlending = CustomBlending;
  30311. exports.CustomToneMapping = CustomToneMapping;
  30312. exports.CylinderBufferGeometry = CylinderGeometry;
  30313. exports.CylinderGeometry = CylinderGeometry;
  30314. exports.Cylindrical = Cylindrical;
  30315. exports.DataTexture = DataTexture;
  30316. exports.DataTexture2DArray = DataTexture2DArray;
  30317. exports.DataTexture3D = DataTexture3D;
  30318. exports.DataTextureLoader = DataTextureLoader;
  30319. exports.DataUtils = DataUtils;
  30320. exports.DecrementStencilOp = DecrementStencilOp;
  30321. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  30322. exports.DefaultLoadingManager = DefaultLoadingManager;
  30323. exports.DepthFormat = DepthFormat;
  30324. exports.DepthStencilFormat = DepthStencilFormat;
  30325. exports.DepthTexture = DepthTexture;
  30326. exports.DirectionalLight = DirectionalLight;
  30327. exports.DirectionalLightHelper = DirectionalLightHelper;
  30328. exports.DiscreteInterpolant = DiscreteInterpolant;
  30329. exports.DodecahedronBufferGeometry = DodecahedronGeometry;
  30330. exports.DodecahedronGeometry = DodecahedronGeometry;
  30331. exports.DoubleSide = DoubleSide;
  30332. exports.DstAlphaFactor = DstAlphaFactor;
  30333. exports.DstColorFactor = DstColorFactor;
  30334. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  30335. exports.DynamicCopyUsage = DynamicCopyUsage;
  30336. exports.DynamicDrawUsage = DynamicDrawUsage;
  30337. exports.DynamicReadUsage = DynamicReadUsage;
  30338. exports.EdgesGeometry = EdgesGeometry;
  30339. exports.EdgesHelper = EdgesHelper;
  30340. exports.EllipseCurve = EllipseCurve;
  30341. exports.EqualDepth = EqualDepth;
  30342. exports.EqualStencilFunc = EqualStencilFunc;
  30343. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  30344. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  30345. exports.Euler = Euler;
  30346. exports.EventDispatcher = EventDispatcher;
  30347. exports.ExtrudeBufferGeometry = ExtrudeGeometry;
  30348. exports.ExtrudeGeometry = ExtrudeGeometry;
  30349. exports.Face3 = Face3;
  30350. exports.Face4 = Face4;
  30351. exports.FaceColors = FaceColors;
  30352. exports.FileLoader = FileLoader;
  30353. exports.FlatShading = FlatShading;
  30354. exports.Float16BufferAttribute = Float16BufferAttribute;
  30355. exports.Float32Attribute = Float32Attribute;
  30356. exports.Float32BufferAttribute = Float32BufferAttribute;
  30357. exports.Float64Attribute = Float64Attribute;
  30358. exports.Float64BufferAttribute = Float64BufferAttribute;
  30359. exports.FloatType = FloatType;
  30360. exports.Fog = Fog;
  30361. exports.FogExp2 = FogExp2;
  30362. exports.Font = Font;
  30363. exports.FontLoader = FontLoader;
  30364. exports.FrontSide = FrontSide;
  30365. exports.Frustum = Frustum;
  30366. exports.GLBufferAttribute = GLBufferAttribute;
  30367. exports.GLSL1 = GLSL1;
  30368. exports.GLSL3 = GLSL3;
  30369. exports.GammaEncoding = GammaEncoding;
  30370. exports.GeometryUtils = GeometryUtils;
  30371. exports.GreaterDepth = GreaterDepth;
  30372. exports.GreaterEqualDepth = GreaterEqualDepth;
  30373. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  30374. exports.GreaterStencilFunc = GreaterStencilFunc;
  30375. exports.GridHelper = GridHelper;
  30376. exports.Group = Group;
  30377. exports.HalfFloatType = HalfFloatType;
  30378. exports.HemisphereLight = HemisphereLight;
  30379. exports.HemisphereLightHelper = HemisphereLightHelper;
  30380. exports.HemisphereLightProbe = HemisphereLightProbe;
  30381. exports.IcosahedronBufferGeometry = IcosahedronGeometry;
  30382. exports.IcosahedronGeometry = IcosahedronGeometry;
  30383. exports.ImageBitmapLoader = ImageBitmapLoader;
  30384. exports.ImageLoader = ImageLoader;
  30385. exports.ImageUtils = ImageUtils;
  30386. exports.ImmediateRenderObject = ImmediateRenderObject;
  30387. exports.IncrementStencilOp = IncrementStencilOp;
  30388. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  30389. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  30390. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  30391. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  30392. exports.InstancedMesh = InstancedMesh;
  30393. exports.Int16Attribute = Int16Attribute;
  30394. exports.Int16BufferAttribute = Int16BufferAttribute;
  30395. exports.Int32Attribute = Int32Attribute;
  30396. exports.Int32BufferAttribute = Int32BufferAttribute;
  30397. exports.Int8Attribute = Int8Attribute;
  30398. exports.Int8BufferAttribute = Int8BufferAttribute;
  30399. exports.IntType = IntType;
  30400. exports.InterleavedBuffer = InterleavedBuffer;
  30401. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  30402. exports.Interpolant = Interpolant;
  30403. exports.InterpolateDiscrete = InterpolateDiscrete;
  30404. exports.InterpolateLinear = InterpolateLinear;
  30405. exports.InterpolateSmooth = InterpolateSmooth;
  30406. exports.InvertStencilOp = InvertStencilOp;
  30407. exports.JSONLoader = JSONLoader;
  30408. exports.KeepStencilOp = KeepStencilOp;
  30409. exports.KeyframeTrack = KeyframeTrack;
  30410. exports.LOD = LOD;
  30411. exports.LatheBufferGeometry = LatheGeometry;
  30412. exports.LatheGeometry = LatheGeometry;
  30413. exports.Layers = Layers;
  30414. exports.LensFlare = LensFlare;
  30415. exports.LessDepth = LessDepth;
  30416. exports.LessEqualDepth = LessEqualDepth;
  30417. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  30418. exports.LessStencilFunc = LessStencilFunc;
  30419. exports.Light = Light;
  30420. exports.LightProbe = LightProbe;
  30421. exports.Line = Line;
  30422. exports.Line3 = Line3;
  30423. exports.LineBasicMaterial = LineBasicMaterial;
  30424. exports.LineCurve = LineCurve;
  30425. exports.LineCurve3 = LineCurve3;
  30426. exports.LineDashedMaterial = LineDashedMaterial;
  30427. exports.LineLoop = LineLoop;
  30428. exports.LinePieces = LinePieces;
  30429. exports.LineSegments = LineSegments;
  30430. exports.LineStrip = LineStrip;
  30431. exports.LinearEncoding = LinearEncoding;
  30432. exports.LinearFilter = LinearFilter;
  30433. exports.LinearInterpolant = LinearInterpolant;
  30434. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  30435. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  30436. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  30437. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  30438. exports.LinearToneMapping = LinearToneMapping;
  30439. exports.Loader = Loader;
  30440. exports.LoaderUtils = LoaderUtils;
  30441. exports.LoadingManager = LoadingManager;
  30442. exports.LogLuvEncoding = LogLuvEncoding;
  30443. exports.LoopOnce = LoopOnce;
  30444. exports.LoopPingPong = LoopPingPong;
  30445. exports.LoopRepeat = LoopRepeat;
  30446. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  30447. exports.LuminanceFormat = LuminanceFormat;
  30448. exports.MOUSE = MOUSE;
  30449. exports.Material = Material;
  30450. exports.MaterialLoader = MaterialLoader;
  30451. exports.Math = MathUtils;
  30452. exports.MathUtils = MathUtils;
  30453. exports.Matrix3 = Matrix3;
  30454. exports.Matrix4 = Matrix4;
  30455. exports.MaxEquation = MaxEquation;
  30456. exports.Mesh = Mesh;
  30457. exports.MeshBasicMaterial = MeshBasicMaterial;
  30458. exports.MeshDepthMaterial = MeshDepthMaterial;
  30459. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  30460. exports.MeshFaceMaterial = MeshFaceMaterial;
  30461. exports.MeshLambertMaterial = MeshLambertMaterial;
  30462. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  30463. exports.MeshNormalMaterial = MeshNormalMaterial;
  30464. exports.MeshPhongMaterial = MeshPhongMaterial;
  30465. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  30466. exports.MeshStandardMaterial = MeshStandardMaterial;
  30467. exports.MeshToonMaterial = MeshToonMaterial;
  30468. exports.MinEquation = MinEquation;
  30469. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  30470. exports.MixOperation = MixOperation;
  30471. exports.MultiMaterial = MultiMaterial;
  30472. exports.MultiplyBlending = MultiplyBlending;
  30473. exports.MultiplyOperation = MultiplyOperation;
  30474. exports.NearestFilter = NearestFilter;
  30475. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  30476. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  30477. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  30478. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  30479. exports.NeverDepth = NeverDepth;
  30480. exports.NeverStencilFunc = NeverStencilFunc;
  30481. exports.NoBlending = NoBlending;
  30482. exports.NoColors = NoColors;
  30483. exports.NoToneMapping = NoToneMapping;
  30484. exports.NormalAnimationBlendMode = NormalAnimationBlendMode;
  30485. exports.NormalBlending = NormalBlending;
  30486. exports.NotEqualDepth = NotEqualDepth;
  30487. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  30488. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  30489. exports.Object3D = Object3D;
  30490. exports.ObjectLoader = ObjectLoader;
  30491. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  30492. exports.OctahedronBufferGeometry = OctahedronGeometry;
  30493. exports.OctahedronGeometry = OctahedronGeometry;
  30494. exports.OneFactor = OneFactor;
  30495. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  30496. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  30497. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  30498. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  30499. exports.OrthographicCamera = OrthographicCamera;
  30500. exports.PCFShadowMap = PCFShadowMap;
  30501. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  30502. exports.PMREMGenerator = PMREMGenerator;
  30503. exports.ParametricBufferGeometry = ParametricGeometry;
  30504. exports.ParametricGeometry = ParametricGeometry;
  30505. exports.Particle = Particle;
  30506. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  30507. exports.ParticleSystem = ParticleSystem;
  30508. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  30509. exports.Path = Path;
  30510. exports.PerspectiveCamera = PerspectiveCamera;
  30511. exports.Plane = Plane;
  30512. exports.PlaneBufferGeometry = PlaneGeometry;
  30513. exports.PlaneGeometry = PlaneGeometry;
  30514. exports.PlaneHelper = PlaneHelper;
  30515. exports.PointCloud = PointCloud;
  30516. exports.PointCloudMaterial = PointCloudMaterial;
  30517. exports.PointLight = PointLight;
  30518. exports.PointLightHelper = PointLightHelper;
  30519. exports.Points = Points;
  30520. exports.PointsMaterial = PointsMaterial;
  30521. exports.PolarGridHelper = PolarGridHelper;
  30522. exports.PolyhedronBufferGeometry = PolyhedronGeometry;
  30523. exports.PolyhedronGeometry = PolyhedronGeometry;
  30524. exports.PositionalAudio = PositionalAudio;
  30525. exports.PropertyBinding = PropertyBinding;
  30526. exports.PropertyMixer = PropertyMixer;
  30527. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  30528. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  30529. exports.Quaternion = Quaternion;
  30530. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  30531. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  30532. exports.REVISION = REVISION;
  30533. exports.RGBADepthPacking = RGBADepthPacking;
  30534. exports.RGBAFormat = RGBAFormat;
  30535. exports.RGBAIntegerFormat = RGBAIntegerFormat;
  30536. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  30537. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  30538. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  30539. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  30540. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  30541. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  30542. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  30543. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  30544. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  30545. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  30546. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  30547. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  30548. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  30549. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  30550. exports.RGBA_BPTC_Format = RGBA_BPTC_Format;
  30551. exports.RGBA_ETC2_EAC_Format = RGBA_ETC2_EAC_Format;
  30552. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  30553. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  30554. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  30555. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  30556. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  30557. exports.RGBDEncoding = RGBDEncoding;
  30558. exports.RGBEEncoding = RGBEEncoding;
  30559. exports.RGBEFormat = RGBEFormat;
  30560. exports.RGBFormat = RGBFormat;
  30561. exports.RGBIntegerFormat = RGBIntegerFormat;
  30562. exports.RGBM16Encoding = RGBM16Encoding;
  30563. exports.RGBM7Encoding = RGBM7Encoding;
  30564. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  30565. exports.RGB_ETC2_Format = RGB_ETC2_Format;
  30566. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  30567. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  30568. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  30569. exports.RGFormat = RGFormat;
  30570. exports.RGIntegerFormat = RGIntegerFormat;
  30571. exports.RawShaderMaterial = RawShaderMaterial;
  30572. exports.Ray = Ray;
  30573. exports.Raycaster = Raycaster;
  30574. exports.RectAreaLight = RectAreaLight;
  30575. exports.RedFormat = RedFormat;
  30576. exports.RedIntegerFormat = RedIntegerFormat;
  30577. exports.ReinhardToneMapping = ReinhardToneMapping;
  30578. exports.RepeatWrapping = RepeatWrapping;
  30579. exports.ReplaceStencilOp = ReplaceStencilOp;
  30580. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  30581. exports.RingBufferGeometry = RingGeometry;
  30582. exports.RingGeometry = RingGeometry;
  30583. exports.SRGB8_ALPHA8_ASTC_10x10_Format = SRGB8_ALPHA8_ASTC_10x10_Format;
  30584. exports.SRGB8_ALPHA8_ASTC_10x5_Format = SRGB8_ALPHA8_ASTC_10x5_Format;
  30585. exports.SRGB8_ALPHA8_ASTC_10x6_Format = SRGB8_ALPHA8_ASTC_10x6_Format;
  30586. exports.SRGB8_ALPHA8_ASTC_10x8_Format = SRGB8_ALPHA8_ASTC_10x8_Format;
  30587. exports.SRGB8_ALPHA8_ASTC_12x10_Format = SRGB8_ALPHA8_ASTC_12x10_Format;
  30588. exports.SRGB8_ALPHA8_ASTC_12x12_Format = SRGB8_ALPHA8_ASTC_12x12_Format;
  30589. exports.SRGB8_ALPHA8_ASTC_4x4_Format = SRGB8_ALPHA8_ASTC_4x4_Format;
  30590. exports.SRGB8_ALPHA8_ASTC_5x4_Format = SRGB8_ALPHA8_ASTC_5x4_Format;
  30591. exports.SRGB8_ALPHA8_ASTC_5x5_Format = SRGB8_ALPHA8_ASTC_5x5_Format;
  30592. exports.SRGB8_ALPHA8_ASTC_6x5_Format = SRGB8_ALPHA8_ASTC_6x5_Format;
  30593. exports.SRGB8_ALPHA8_ASTC_6x6_Format = SRGB8_ALPHA8_ASTC_6x6_Format;
  30594. exports.SRGB8_ALPHA8_ASTC_8x5_Format = SRGB8_ALPHA8_ASTC_8x5_Format;
  30595. exports.SRGB8_ALPHA8_ASTC_8x6_Format = SRGB8_ALPHA8_ASTC_8x6_Format;
  30596. exports.SRGB8_ALPHA8_ASTC_8x8_Format = SRGB8_ALPHA8_ASTC_8x8_Format;
  30597. exports.Scene = Scene;
  30598. exports.SceneUtils = SceneUtils;
  30599. exports.ShaderChunk = ShaderChunk;
  30600. exports.ShaderLib = ShaderLib;
  30601. exports.ShaderMaterial = ShaderMaterial;
  30602. exports.ShadowMaterial = ShadowMaterial;
  30603. exports.Shape = Shape;
  30604. exports.ShapeBufferGeometry = ShapeGeometry;
  30605. exports.ShapeGeometry = ShapeGeometry;
  30606. exports.ShapePath = ShapePath;
  30607. exports.ShapeUtils = ShapeUtils;
  30608. exports.ShortType = ShortType;
  30609. exports.Skeleton = Skeleton;
  30610. exports.SkeletonHelper = SkeletonHelper;
  30611. exports.SkinnedMesh = SkinnedMesh;
  30612. exports.SmoothShading = SmoothShading;
  30613. exports.Sphere = Sphere;
  30614. exports.SphereBufferGeometry = SphereGeometry;
  30615. exports.SphereGeometry = SphereGeometry;
  30616. exports.Spherical = Spherical;
  30617. exports.SphericalHarmonics3 = SphericalHarmonics3;
  30618. exports.Spline = Spline;
  30619. exports.SplineCurve = SplineCurve;
  30620. exports.SplineCurve3 = SplineCurve3;
  30621. exports.SpotLight = SpotLight;
  30622. exports.SpotLightHelper = SpotLightHelper;
  30623. exports.Sprite = Sprite;
  30624. exports.SpriteMaterial = SpriteMaterial;
  30625. exports.SrcAlphaFactor = SrcAlphaFactor;
  30626. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  30627. exports.SrcColorFactor = SrcColorFactor;
  30628. exports.StaticCopyUsage = StaticCopyUsage;
  30629. exports.StaticDrawUsage = StaticDrawUsage;
  30630. exports.StaticReadUsage = StaticReadUsage;
  30631. exports.StereoCamera = StereoCamera;
  30632. exports.StreamCopyUsage = StreamCopyUsage;
  30633. exports.StreamDrawUsage = StreamDrawUsage;
  30634. exports.StreamReadUsage = StreamReadUsage;
  30635. exports.StringKeyframeTrack = StringKeyframeTrack;
  30636. exports.SubtractEquation = SubtractEquation;
  30637. exports.SubtractiveBlending = SubtractiveBlending;
  30638. exports.TOUCH = TOUCH;
  30639. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  30640. exports.TetrahedronBufferGeometry = TetrahedronGeometry;
  30641. exports.TetrahedronGeometry = TetrahedronGeometry;
  30642. exports.TextBufferGeometry = TextGeometry;
  30643. exports.TextGeometry = TextGeometry;
  30644. exports.Texture = Texture;
  30645. exports.TextureLoader = TextureLoader;
  30646. exports.TorusBufferGeometry = TorusGeometry;
  30647. exports.TorusGeometry = TorusGeometry;
  30648. exports.TorusKnotBufferGeometry = TorusKnotGeometry;
  30649. exports.TorusKnotGeometry = TorusKnotGeometry;
  30650. exports.Triangle = Triangle;
  30651. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  30652. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  30653. exports.TrianglesDrawMode = TrianglesDrawMode;
  30654. exports.TubeBufferGeometry = TubeGeometry;
  30655. exports.TubeGeometry = TubeGeometry;
  30656. exports.UVMapping = UVMapping;
  30657. exports.Uint16Attribute = Uint16Attribute;
  30658. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  30659. exports.Uint32Attribute = Uint32Attribute;
  30660. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  30661. exports.Uint8Attribute = Uint8Attribute;
  30662. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  30663. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  30664. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  30665. exports.Uniform = Uniform;
  30666. exports.UniformsLib = UniformsLib;
  30667. exports.UniformsUtils = UniformsUtils;
  30668. exports.UnsignedByteType = UnsignedByteType;
  30669. exports.UnsignedInt248Type = UnsignedInt248Type;
  30670. exports.UnsignedIntType = UnsignedIntType;
  30671. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  30672. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  30673. exports.UnsignedShort565Type = UnsignedShort565Type;
  30674. exports.UnsignedShortType = UnsignedShortType;
  30675. exports.VSMShadowMap = VSMShadowMap;
  30676. exports.Vector2 = Vector2;
  30677. exports.Vector3 = Vector3;
  30678. exports.Vector4 = Vector4;
  30679. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  30680. exports.Vertex = Vertex;
  30681. exports.VertexColors = VertexColors;
  30682. exports.VideoTexture = VideoTexture;
  30683. exports.WebGL1Renderer = WebGL1Renderer;
  30684. exports.WebGLCubeRenderTarget = WebGLCubeRenderTarget;
  30685. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  30686. exports.WebGLRenderTarget = WebGLRenderTarget;
  30687. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  30688. exports.WebGLRenderer = WebGLRenderer;
  30689. exports.WebGLUtils = WebGLUtils;
  30690. exports.WireframeGeometry = WireframeGeometry;
  30691. exports.WireframeHelper = WireframeHelper;
  30692. exports.WrapAroundEnding = WrapAroundEnding;
  30693. exports.XHRLoader = XHRLoader;
  30694. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  30695. exports.ZeroFactor = ZeroFactor;
  30696. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  30697. exports.ZeroStencilOp = ZeroStencilOp;
  30698. exports.sRGBEncoding = sRGBEncoding;
  30699. Object.defineProperty(exports, '__esModule', { value: true });
  30700. })));